summaryrefslogtreecommitdiffstats
path: root/wiretap/wtap.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--wiretap/wtap.c291
1 files changed, 160 insertions, 131 deletions
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index 18432ef2..69056d98 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -7,6 +7,8 @@
*/
#include <config.h>
+#include "wtap.h"
+#include "wtap-int.h"
#define WS_LOG_DOMAIN LOG_DOMAIN_WIRETAP
@@ -14,26 +16,24 @@
#include <sys/types.h>
-#include "wtap-int.h"
#include "wtap_opttypes.h"
#include "file_wrappers.h"
#include <wsutil/file_util.h>
#include <wsutil/buffer.h>
#include <wsutil/ws_assert.h>
-#include <wsutil/wslog.h>
#include <wsutil/exported_pdu_tlvs.h>
#ifdef HAVE_PLUGINS
#include <wsutil/plugins.h>
#endif
#ifdef HAVE_PLUGINS
-static plugins_t *libwiretap_plugins = NULL;
+static plugins_t *libwiretap_plugins;
#endif
#define PADDING4(x) ((((x + 3) >> 2) << 2) - x)
-static GSList *wtap_plugins = NULL;
+static GSList *wtap_plugins;
#ifdef HAVE_PLUGINS
void
@@ -60,7 +60,7 @@ wtap_plugins_supported(void)
}
static void
-call_plugin_register_wtap_module(gpointer data, gpointer user_data _U_)
+call_plugin_register_wtap_module(void *data, void *user_data _U_)
{
wtap_plugin *plug = (wtap_plugin *)data;
@@ -71,9 +71,9 @@ call_plugin_register_wtap_module(gpointer data, gpointer user_data _U_)
/*
* Return the size of the file, as reported by the OS.
- * (gint64, in case that's 64 bits.)
+ * (int64_t, in case that's 64 bits.)
*/
-gint64
+int64_t
wtap_file_size(wtap *wth, int *err)
{
ws_statb64 statb;
@@ -102,7 +102,7 @@ wtap_file_type_subtype(wtap *wth)
return wth->file_type_subtype;
}
-guint
+unsigned
wtap_snapshot_length(wtap *wth)
{
return wth->snapshot_length;
@@ -120,14 +120,14 @@ wtap_file_tsprec(wtap *wth)
return wth->file_tsprec;
}
-guint
+unsigned
wtap_file_get_num_shbs(wtap *wth)
{
return wth->shb_hdrs->len;
}
wtap_block_t
-wtap_file_get_shb(wtap *wth, guint shb_num)
+wtap_file_get_shb(wtap *wth, unsigned shb_num)
{
if ((wth == NULL) || (wth->shb_hdrs == NULL) || (shb_num >= wth->shb_hdrs->len))
return NULL;
@@ -135,17 +135,28 @@ wtap_file_get_shb(wtap *wth, guint shb_num)
return g_array_index(wth->shb_hdrs, wtap_block_t, shb_num);
}
+unsigned
+wtap_file_get_shb_global_interface_id(wtap *wth, unsigned shb_num, uint32_t interface_id)
+{
+ if ((wth == NULL) || (wth->shb_hdrs == NULL) || (shb_num >= wth->shb_hdrs->len)) {
+ ws_warning("unexpected SHB %u and interface id %u", shb_num, interface_id);
+ return interface_id;
+ }
+
+ return interface_id + g_array_index(wth->shb_iface_to_global, unsigned, shb_num);
+}
+
GArray*
wtap_file_get_shb_for_new_file(wtap *wth)
{
- guint shb_count;
+ unsigned shb_count;
wtap_block_t shb_hdr_src, shb_hdr_dest;
GArray* shb_hdrs;
if ((wth == NULL) || (wth->shb_hdrs == NULL) || (wth->shb_hdrs->len == 0))
return NULL;
- shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
+ shb_hdrs = g_array_new(false, false, sizeof(wtap_block_t));
for (shb_count = 0; shb_count < wth->shb_hdrs->len; shb_count++) {
shb_hdr_src = g_array_index(wth->shb_hdrs, wtap_block_t, shb_count);
@@ -160,10 +171,10 @@ wtap_file_get_shb_for_new_file(wtap *wth)
* XXX - replace with APIs that let us handle multiple comments.
*/
void
-wtap_write_shb_comment(wtap *wth, gchar *comment)
+wtap_write_shb_comment(wtap *wth, char *comment)
{
if ((wth != NULL) && (wth->shb_hdrs != NULL) && (wth->shb_hdrs->len > 0)) {
- wtap_block_set_nth_string_option_value(g_array_index(wth->shb_hdrs, wtap_block_t, 0), OPT_COMMENT, 0, comment, (gsize)(comment ? strlen(comment) : 0));
+ wtap_block_set_nth_string_option_value(g_array_index(wth->shb_hdrs, wtap_block_t, 0), OPT_COMMENT, 0, comment, (size_t)(comment ? strlen(comment) : 0));
}
}
@@ -202,43 +213,61 @@ wtap_get_next_interface_description(wtap *wth)
return NULL;
}
+unsigned
+wtap_file_get_num_dsbs(wtap *wth)
+{
+ if (!wth->dsbs) {
+ return 0;
+ }
+ return wth->dsbs->len;
+}
+
+wtap_block_t
+wtap_file_get_dsb(wtap *wth, unsigned dsb_num)
+{
+ if ((wth == NULL) || (wth->dsbs == NULL) || (dsb_num >= wth->dsbs->len))
+ return NULL;
+
+ return g_array_index(wth->dsbs, wtap_block_t, dsb_num);
+}
+
void
wtap_file_add_decryption_secrets(wtap *wth, const wtap_block_t dsb)
{
if (!wth->dsbs) {
- wth->dsbs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
+ wth->dsbs = g_array_new(false, false, sizeof(wtap_block_t));
}
g_array_append_val(wth->dsbs, dsb);
}
-gboolean
+bool
wtap_file_discard_decryption_secrets(wtap *wth)
{
if (!wth->dsbs || wth->dsbs->len == 0)
- return FALSE;
+ return false;
wtap_block_array_free(wth->dsbs);
wth->dsbs = NULL;
- return TRUE;
+ return true;
}
void
-wtap_file_add_sysdig_meta_event(wtap *wth, const wtap_block_t mev)
+wtap_file_add_meta_event(wtap *wth, const wtap_block_t mev)
{
- if (!wth->sysdig_meta_events) {
- wth->sysdig_meta_events = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
+ if (!wth->meta_events) {
+ wth->meta_events = g_array_new(false, false, sizeof(wtap_block_t));
}
- g_array_append_val(wth->sysdig_meta_events, mev);
+ g_array_append_val(wth->meta_events, mev);
}
-gboolean
-wtap_file_discard_sysdig_meta_events(wtap *wth)
+bool
+wtap_file_discard_meta_events(wtap *wth)
{
- if (!wth->sysdig_meta_events || wth->sysdig_meta_events->len == 0)
+ if (!wth->meta_events || wth->meta_events->len == 0)
return false;
- wtap_block_array_free(wth->sysdig_meta_events);
- wth->sysdig_meta_events = NULL;
+ wtap_block_array_free(wth->meta_events);
+ wth->meta_events = NULL;
return true;
}
@@ -340,7 +369,7 @@ wtap_free_idb_info(wtapng_iface_descriptions_t *idb_info)
g_free(idb_info);
}
-gchar *
+char *
wtap_get_debug_if_descr(const wtap_block_t if_descr,
const int indent,
const char* line_end)
@@ -348,9 +377,9 @@ wtap_get_debug_if_descr(const wtap_block_t if_descr,
char* tmp_content;
wtapng_if_descr_mandatory_t* if_descr_mand;
GString *info = g_string_new("");
- gint64 itmp64;
- guint64 tmp64;
- guint8 tmp8;
+ int64_t itmp64;
+ uint64_t tmp64;
+ uint8_t tmp8;
if_filter_opt_t if_filter;
ws_assert(if_descr);
@@ -423,7 +452,7 @@ wtap_get_debug_if_descr(const wtap_block_t if_descr,
if (wtap_block_get_int64_option_value(if_descr, OPT_IDB_TSOFFSET, &itmp64) == WTAP_OPTTYPE_SUCCESS) {
g_string_append_printf(info,
- "%*cTimestamp offset = %" G_GINT64_FORMAT "%s", indent, ' ',
+ "%*cTimestamp offset = %" PRId64 "%s", indent, ' ',
itmp64,
line_end);
}
@@ -491,14 +520,14 @@ wtap_file_get_nrb(wtap *wth)
GArray*
wtap_file_get_nrb_for_new_file(wtap *wth)
{
- guint nrb_count;
+ unsigned nrb_count;
wtap_block_t nrb_src, nrb_dest;
GArray* nrbs;
if ((wth == NULL || wth->nrbs == NULL) || (wth->nrbs->len == 0))
return NULL;
- nrbs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
+ nrbs = g_array_new(false, false, sizeof(wtap_block_t));
for (nrb_count = 0; nrb_count < wth->nrbs->len; nrb_count++) {
nrb_src = g_array_index(wth->nrbs, wtap_block_t, nrb_count);
@@ -524,10 +553,11 @@ wtap_dump_params_init(wtap_dump_params *params, wtap *wth)
/* Assume that the input handle remains open until the dumper is closed.
* Refer to the DSBs from the input file, wtap_dump will then copy DSBs
* as they become available. */
+ params->shb_iface_to_global = wth->shb_iface_to_global;
params->nrbs_growing = wth->nrbs;
params->dsbs_growing = wth->dsbs;
- params->sysdig_mev_growing = wth->sysdig_meta_events;
- params->dont_copy_idbs = FALSE;
+ params->mevs_growing = wth->meta_events;
+ params->dont_copy_idbs = false;
}
/*
@@ -549,9 +579,10 @@ wtap_dump_params_init_no_idbs(wtap_dump_params *params, wtap *wth)
/* Assume that the input handle remains open until the dumper is closed.
* Refer to the DSBs from the input file, wtap_dump will then copy DSBs
* as they become available. */
+ params->shb_iface_to_global = wth->shb_iface_to_global;
params->nrbs_growing = wth->nrbs;
params->dsbs_growing = wth->dsbs;
- params->dont_copy_idbs = TRUE;
+ params->dont_copy_idbs = true;
}
void
@@ -568,9 +599,9 @@ wtap_dump_params_discard_decryption_secrets(wtap_dump_params *params)
}
void
-wtap_dump_params_discard_sysdig_meta_events(wtap_dump_params *params)
+wtap_dump_params_discard_meta_events(wtap_dump_params *params)
{
- params->sysdig_mev_growing = NULL;
+ params->mevs_growing = NULL;
}
void
@@ -1266,11 +1297,17 @@ static struct encap_type_info encap_table_base[] = {
/* WTAP_ENCAP_MDB */
{ "mdb", "MDB (Multi-Drop Bus)"},
+
+ /* WTAP_ENCAP_EMS */
+ { "ems", "EMS (EGNOS Message Server) file"},
+
+ /* WTAP_ENCAP_DECT_NR */
+ { "dect_nr", "DECT-2020 New Radio (NR) MAC layer" },
};
WS_DLL_LOCAL
-gint wtap_num_encap_types = sizeof(encap_table_base) / sizeof(struct encap_type_info);
-static GArray* encap_table_arr = NULL;
+int wtap_num_encap_types = array_length(encap_table_base);
+static GArray* encap_table_arr;
#define encap_table_entry(encap) \
g_array_index(encap_table_arr, struct encap_type_info, encap)
@@ -1279,14 +1316,14 @@ static void wtap_init_encap_types(void) {
if (encap_table_arr) return;
- encap_table_arr = g_array_new(FALSE,TRUE,sizeof(struct encap_type_info));
+ encap_table_arr = g_array_new(false,true,sizeof(struct encap_type_info));
g_array_append_vals(encap_table_arr,encap_table_base,wtap_num_encap_types);
}
static void wtap_cleanup_encap_types(void) {
if (encap_table_arr) {
- g_array_free(encap_table_arr, TRUE);
+ g_array_free(encap_table_arr, true);
encap_table_arr = NULL;
}
}
@@ -1464,7 +1501,7 @@ static const char *wtap_errlist[] = {
/* WTAP_ERR_TIME_STAMP_NOT_SUPPORTED */
"We don't support writing that record's time stamp to that file type",
};
-#define WTAP_ERRLIST_SIZE (sizeof wtap_errlist / sizeof wtap_errlist[0])
+#define WTAP_ERRLIST_SIZE array_length(wtap_errlist)
const char *
wtap_strerror(int err)
@@ -1506,7 +1543,7 @@ wtap_sequential_close(wtap *wth)
}
static void
-g_fast_seek_item_free(gpointer data, gpointer user_data _U_)
+g_fast_seek_item_free(void *data, void *user_data _U_)
{
g_free(data);
}
@@ -1543,14 +1580,15 @@ wtap_close(wtap *wth)
if (wth->fast_seek != NULL) {
g_ptr_array_foreach(wth->fast_seek, g_fast_seek_item_free, NULL);
- g_ptr_array_free(wth->fast_seek, TRUE);
+ g_ptr_array_free(wth->fast_seek, true);
}
wtap_block_array_free(wth->shb_hdrs);
wtap_block_array_free(wth->nrbs);
+ g_array_free(wth->shb_iface_to_global, true);
wtap_block_array_free(wth->interface_data);
wtap_block_array_free(wth->dsbs);
- wtap_block_array_free(wth->sysdig_meta_events);
+ wtap_block_array_free(wth->meta_events);
g_free(wth);
}
@@ -1569,7 +1607,7 @@ wtapng_process_nrb_ipv4(wtap *wth, wtap_block_t nrb)
if (wth->add_new_ipv4) {
for (GList *elem = nrb_mand->ipv4_addr_list; elem != NULL; elem = elem->next) {
hashipv4_t *tp = elem->data;
- wth->add_new_ipv4(tp->addr, tp->name, FALSE);
+ wth->add_new_ipv4(tp->addr, tp->name, false);
}
}
}
@@ -1582,7 +1620,7 @@ wtapng_process_nrb_ipv6(wtap *wth, wtap_block_t nrb)
if (wth->add_new_ipv6) {
for (GList *elem = nrb_mand->ipv6_addr_list; elem != NULL; elem = elem->next) {
hashipv6_t *tp = elem->data;
- wth->add_new_ipv6(tp->addr, tp->name, FALSE);
+ wth->add_new_ipv6(tp->addr, tp->name, false);
}
}
}
@@ -1601,7 +1639,7 @@ void wtap_set_cb_new_ipv4(wtap *wth, wtap_new_ipv4_callback_t add_new_ipv4) {
* relies on this to support redissection (during redissection, the
* previous name resolutions are lost and has to be resupplied).
*/
- for (guint i = 0; i < wth->nrbs->len; i++) {
+ for (unsigned i = 0; i < wth->nrbs->len; i++) {
wtap_block_t nrb = g_array_index(wth->nrbs, wtap_block_t, i);
wtapng_process_nrb_ipv4(wth, nrb);
}
@@ -1621,7 +1659,7 @@ void wtap_set_cb_new_ipv6(wtap *wth, wtap_new_ipv6_callback_t add_new_ipv6) {
* relies on this to support redissection (during redissection, the
* previous name resolutions are lost and has to be resupplied).
*/
- for (guint i = 0; i < wth->nrbs->len; i++) {
+ for (unsigned i = 0; i < wth->nrbs->len; i++) {
wtap_block_t nrb = g_array_index(wth->nrbs, wtap_block_t, i);
wtapng_process_nrb_ipv6(wth, nrb);
}
@@ -1645,7 +1683,7 @@ void wtap_set_cb_new_secrets(wtap *wth, wtap_new_secrets_callback_t add_new_secr
* relies on this to support redissection (during redissection, the
* previous secrets are lost and has to be resupplied).
*/
- for (guint i = 0; i < wth->dsbs->len; i++) {
+ for (unsigned i = 0; i < wth->dsbs->len; i++) {
wtap_block_t dsb = g_array_index(wth->dsbs, wtap_block_t, i);
wtapng_process_dsb(wth, dsb);
}
@@ -1660,15 +1698,6 @@ wtapng_process_dsb(wtap *wth, wtap_block_t dsb)
wth->add_new_secrets(dsb_mand->secrets_type, dsb_mand->secrets_data, dsb_mand->secrets_len);
}
-void
-wtapng_process_sysdig_meta_event(wtap *wth, wtap_block_t mev)
-{
- const wtapng_sysdig_mev_mandatory_t *mev_mand = (wtapng_sysdig_mev_mandatory_t*)wtap_block_get_mandatory_data(mev);
-
- if (wth->add_new_sysdig_meta_event)
- wth->add_new_sysdig_meta_event(mev_mand->mev_type, mev_mand->mev_data, mev_mand->mev_data_len);
-}
-
/* Perform per-packet initialization */
static void
wtap_init_rec(wtap *wth, wtap_rec *rec)
@@ -1686,7 +1715,7 @@ wtap_init_rec(wtap *wth, wtap_rec *rec)
rec->rec_header.packet_header.pkt_encap = wth->file_encap;
rec->tsprec = wth->file_tsprec;
rec->block = NULL;
- rec->block_was_modified = FALSE;
+ rec->block_was_modified = false;
/*
* Assume the file has only one section; the module for the
@@ -1696,9 +1725,9 @@ wtap_init_rec(wtap *wth, wtap_rec *rec)
rec->section_number = 0;
}
-gboolean
+bool
wtap_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err,
- gchar **err_info, gint64 *offset)
+ char **err_info, int64_t *offset)
{
/*
* Initialize the record to default values.
@@ -1727,7 +1756,7 @@ wtap_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err,
wtap_block_unref(rec->block);
rec->block = NULL;
}
- return FALSE; /* failure */
+ return false; /* failure */
}
/*
@@ -1744,68 +1773,68 @@ wtap_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err,
ws_assert(rec->rec_header.packet_header.pkt_encap != WTAP_ENCAP_NONE);
}
- return TRUE; /* success */
+ return true; /* success */
}
/*
* Read a given number of bytes from a file into a buffer or, if
* buf is NULL, just discard them.
*
- * If we succeed, return TRUE.
+ * If we succeed, return true.
*
- * If we get an EOF, return FALSE with *err set to 0, reporting this
+ * If we get an EOF, return false with *err set to 0, reporting this
* as an EOF.
*
- * If we get fewer bytes than the specified number, return FALSE with
+ * If we get fewer bytes than the specified number, return false with
* *err set to WTAP_ERR_SHORT_READ, reporting this as a short read
* error.
*
- * If we get a read error, return FALSE with *err and *err_info set
+ * If we get a read error, return false with *err and *err_info set
* appropriately.
*/
-gboolean
+bool
wtap_read_bytes_or_eof(FILE_T fh, void *buf, unsigned int count, int *err,
- gchar **err_info)
+ char **err_info)
{
int bytes_read;
bytes_read = file_read(buf, count, fh);
- if (bytes_read < 0 || (guint)bytes_read != count) {
+ if (bytes_read < 0 || (unsigned)bytes_read != count) {
*err = file_error(fh, err_info);
if (*err == 0 && bytes_read > 0)
*err = WTAP_ERR_SHORT_READ;
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
/*
* Read a given number of bytes from a file into a buffer or, if
* buf is NULL, just discard them.
*
- * If we succeed, return TRUE.
+ * If we succeed, return true.
*
* If we get fewer bytes than the specified number, including getting
- * an EOF, return FALSE with *err set to WTAP_ERR_SHORT_READ, reporting
+ * an EOF, return false with *err set to WTAP_ERR_SHORT_READ, reporting
* this as a short read error.
*
- * If we get a read error, return FALSE with *err and *err_info set
+ * If we get a read error, return false with *err and *err_info set
* appropriately.
*/
-gboolean
+bool
wtap_read_bytes(FILE_T fh, void *buf, unsigned int count, int *err,
- gchar **err_info)
+ char **err_info)
{
int bytes_read;
bytes_read = file_read(buf, count, fh);
- if (bytes_read < 0 || (guint)bytes_read != count) {
+ if (bytes_read < 0 || (unsigned)bytes_read != count) {
*err = file_error(fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
/*
@@ -1817,11 +1846,11 @@ wtap_read_bytes(FILE_T fh, void *buf, unsigned int count, int *err,
* header, so if we get an EOF trying to read the packet data, the file
* has been cut short, even if the read didn't read any data at all.)
*/
-gboolean
-wtap_read_packet_bytes(FILE_T fh, Buffer *buf, guint length, int *err,
- gchar **err_info)
+bool
+wtap_read_packet_bytes(FILE_T fh, Buffer *buf, unsigned length, int *err,
+ char **err_info)
{
- gboolean rv;
+ bool rv;
ws_buffer_assure_space(buf, length);
rv = wtap_read_bytes(fh, ws_buffer_end_ptr(buf), length, err,
err_info);
@@ -1833,9 +1862,9 @@ wtap_read_packet_bytes(FILE_T fh, Buffer *buf, guint length, int *err,
/*
* Return an approximation of the amount of data we've read sequentially
- * from the file so far. (gint64, in case that's 64 bits.)
+ * from the file so far. (int64_t, in case that's 64 bits.)
*/
-gint64
+int64_t
wtap_read_so_far(wtap *wth)
{
return file_tell_raw(wth->fh);
@@ -1859,7 +1888,7 @@ wtap_rec_reset(wtap_rec *rec)
{
wtap_block_unref(rec->block);
rec->block = NULL;
- rec->block_was_modified = FALSE;
+ rec->block_was_modified = false;
}
/* clean up record metadata */
@@ -1884,9 +1913,9 @@ wtap_rec_generate_idb(const wtap_rec *rec)
return wtap_generate_idb(rec->rec_header.packet_header.pkt_encap, tsprec, 0);
}
-gboolean
-wtap_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf,
- int *err, gchar **err_info)
+bool
+wtap_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf,
+ int *err, char **err_info)
{
/*
* Initialize the record to default values.
@@ -1904,7 +1933,7 @@ wtap_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf,
wtap_block_unref(rec->block);
rec->block = NULL;
}
- return FALSE;
+ return false;
}
/*
@@ -1921,27 +1950,27 @@ wtap_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf,
ws_assert(rec->rec_header.packet_header.pkt_encap != WTAP_ENCAP_NONE);
}
- return TRUE;
+ return true;
}
-static gboolean
-wtap_full_file_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info)
+static bool
+wtap_full_file_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *err, char **err_info)
{
- gint64 file_size;
+ int64_t file_size;
int packet_size = 0;
const int block_size = 1024 * 1024;
if ((file_size = wtap_file_size(wth, err)) == -1)
- return FALSE;
+ return false;
- if (file_size > G_MAXINT) {
+ if (file_size > INT_MAX) {
/*
* Avoid allocating space for an immensely-large file.
*/
*err = WTAP_ERR_BAD_FILE;
*err_info = ws_strdup_printf("%s: File has %" PRId64 "-byte packet, bigger than maximum of %u",
- wtap_encap_name(wth->file_encap), file_size, G_MAXINT);
- return FALSE;
+ wtap_encap_name(wth->file_encap), file_size, INT_MAX);
+ return false;
}
/*
@@ -1954,8 +1983,8 @@ wtap_full_file_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *
if (buffer_size <= 0) {
*err = WTAP_ERR_BAD_FILE;
*err_info = ws_strdup_printf("%s: Uncompressed file is bigger than maximum of %u",
- wtap_encap_name(wth->file_encap), G_MAXINT);
- return FALSE;
+ wtap_encap_name(wth->file_encap), INT_MAX);
+ return false;
}
ws_buffer_assure_space(buf, buffer_size);
int nread = file_read(ws_buffer_start_ptr(buf) + packet_size, buffer_size - packet_size, fh);
@@ -1963,7 +1992,7 @@ wtap_full_file_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *
*err = file_error(fh, err_info);
if (*err == 0)
*err = WTAP_ERR_BAD_FILE;
- return FALSE;
+ return false;
}
packet_size += nread;
if (packet_size != buffer_size) {
@@ -1980,46 +2009,46 @@ wtap_full_file_read_file(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf, int *
rec->rec_header.packet_header.caplen = packet_size;
rec->rec_header.packet_header.len = packet_size;
- return TRUE;
+ return true;
}
-gboolean
+bool
wtap_full_file_read(wtap *wth, wtap_rec *rec, Buffer *buf,
- int *err, gchar **err_info, gint64 *data_offset)
+ int *err, char **err_info, int64_t *data_offset)
{
- gint64 offset = file_tell(wth->fh);
+ int64_t offset = file_tell(wth->fh);
/* There is only one packet with the full file contents. */
if (offset != 0) {
*err = 0;
- return FALSE;
+ return false;
}
*data_offset = offset;
return wtap_full_file_read_file(wth, wth->fh, rec, buf, err, err_info);
}
-gboolean
-wtap_full_file_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info)
+bool
+wtap_full_file_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, int *err, char **err_info)
{
/* There is only one packet with the full file contents. */
if (seek_off > 0) {
*err = 0;
- return FALSE;
+ return false;
}
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
- return FALSE;
+ return false;
return wtap_full_file_read_file(wth, wth->random_fh, rec, buf, err, err_info);
}
void
-wtap_buffer_append_epdu_tag(Buffer *buf, guint16 epdu_tag, const guint8 *data, guint16 data_len)
+wtap_buffer_append_epdu_tag(Buffer *buf, uint16_t epdu_tag, const uint8_t *data, uint16_t data_len)
{
- guint8 pad_len = 0;
- guint space_needed = 4; /* 2 for tag field, 2 for length field */
- guint8 *buf_data;
+ uint8_t pad_len = 0;
+ unsigned space_needed = 4; /* 2 for tag field, 2 for length field */
+ uint8_t *buf_data;
if (epdu_tag != 0 && data != NULL && data_len != 0) {
pad_len += PADDING4(data_len);
@@ -2046,10 +2075,10 @@ wtap_buffer_append_epdu_tag(Buffer *buf, guint16 epdu_tag, const guint8 *data, g
}
void
-wtap_buffer_append_epdu_uint(Buffer *buf, guint16 epdu_tag, guint32 val)
+wtap_buffer_append_epdu_uint(Buffer *buf, uint16_t epdu_tag, uint32_t val)
{
- const guint space_needed = 8; /* 2 for tag field, 2 for length field, 4 for value */
- guint8 *buf_data;
+ const unsigned space_needed = 8; /* 2 for tag field, 2 for length field, 4 for value */
+ uint8_t *buf_data;
ws_assert(epdu_tag != 0);
ws_buffer_assure_space(buf, space_needed);
@@ -2062,41 +2091,41 @@ wtap_buffer_append_epdu_uint(Buffer *buf, guint16 epdu_tag, guint32 val)
}
void
-wtap_buffer_append_epdu_string(Buffer *buf, guint16 epdu_tag, const char *val)
+wtap_buffer_append_epdu_string(Buffer *buf, uint16_t epdu_tag, const char *val)
{
size_t string_len;
string_len = strlen(val);
/*
- * Cut off string length at G_MAXUINT16.
+ * Cut off string length at UINT16_MAX.
*
* XXX - make sure we don't leave an incomplete UTF-8
* sequence at the end.
*/
- if (string_len > G_MAXUINT16)
- string_len = G_MAXUINT16;
- wtap_buffer_append_epdu_tag(buf, epdu_tag, val, (guint16) string_len);
+ if (string_len > UINT16_MAX)
+ string_len = UINT16_MAX;
+ wtap_buffer_append_epdu_tag(buf, epdu_tag, val, (uint16_t) string_len);
}
-gint
+int
wtap_buffer_append_epdu_end(Buffer *buf)
{
- const guint space_needed = 4; /* 2 for tag (=0000), 2 for length field (=0) */
- guint8 *buf_data;
+ const unsigned space_needed = 4; /* 2 for tag (=0000), 2 for length field (=0) */
+ uint8_t *buf_data;
ws_buffer_assure_space(buf, space_needed);
buf_data = ws_buffer_end_ptr(buf);
memset(buf_data, 0, space_needed);
ws_buffer_increase_length(buf, space_needed);
- return (gint)ws_buffer_length(buf);
+ return (int)ws_buffer_length(buf);
}
/*
* Initialize the library.
*/
void
-wtap_init(gboolean load_wiretap_plugins)
+wtap_init(bool load_wiretap_plugins)
{
init_open_routines();
wtap_opttypes_initialize();