aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill Meier <wmeier@newsguy.com>2014-08-05 16:10:44 -0400
committerBill Meier <wmeier@newsguy.com>2014-08-05 20:42:21 +0000
commitf3dd7fe1eb5348922b079db2bdede700d4d28fbd (patch)
tree7382b5da9a3c1de3eba0e91aed54c087fcfea549
parentdfe331e35e0400942d3ad9e4b5f8c84369546b6d (diff)
Fix whitespace/indentation to match editor modelines.
Change-Id: I3445ae22f10584582d465bf632942e016f5f70ca Reviewed-on: https://code.wireshark.org/review/3452 Reviewed-by: Bill Meier <wmeier@newsguy.com>
-rw-r--r--capinfos.c2
-rw-r--r--captype.c2
-rw-r--r--dumpcap.c22
-rw-r--r--editcap.c2
-rw-r--r--epan/address.h62
-rw-r--r--epan/charsets.h4
-rw-r--r--epan/conversation_table.c12
-rw-r--r--epan/frame_data_sequence.c22
-rw-r--r--epan/oids.h2
-rw-r--r--epan/prefs.c2310
-rw-r--r--mergecap.c2
-rw-r--r--pcapio.c10
-rw-r--r--reordercap.c2
-rw-r--r--text2pcap.c2
-rw-r--r--tfshark.c20
-rw-r--r--tshark.c28
-rw-r--r--ui/gtk/addr_resolution_dlg.c310
-rw-r--r--ui/gtk/color_dlg.c28
-rw-r--r--ui/gtk/conversations_table.c4
-rw-r--r--ui/gtk/main.c2
-rw-r--r--ui/gtk/text_page_utils.c2
-rw-r--r--wiretap/pcapng.c5800
-rw-r--r--wiretap/vwr.c136
-rw-r--r--wiretap/wtap.h18
24 files changed, 4402 insertions, 4402 deletions
diff --git a/capinfos.c b/capinfos.c
index aec23f94a7..b3b58be8d7 100644
--- a/capinfos.c
+++ b/capinfos.c
@@ -78,7 +78,7 @@
#include <glib.h>
#ifdef HAVE_LIBZ
-#include <zlib.h> /* to get the libz version number */
+#include <zlib.h> /* to get the libz version number */
#endif
#include <wsutil/privileges.h>
diff --git a/captype.c b/captype.c
index f00c824b06..d37ee90d78 100644
--- a/captype.c
+++ b/captype.c
@@ -45,7 +45,7 @@
#endif
#ifdef HAVE_LIBZ
-#include <zlib.h> /* to get the libz version number */
+#include <zlib.h> /* to get the libz version number */
#endif
#include <glib.h>
diff --git a/dumpcap.c b/dumpcap.c
index cd329b4992..94aaca4394 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -68,7 +68,7 @@
#include <errno.h>
#ifdef HAVE_LIBZ
-#include <zlib.h> /* to get the libz version number */
+#include <zlib.h> /* to get the libz version number */
#endif
#include <wsutil/cmdarg_err.h>
@@ -4153,23 +4153,23 @@ out:
}
static void
-get_dumpcap_compiled_info(GString *str)
+ get_dumpcap_compiled_info(GString *str)
{
- /* Capture libraries */
- g_string_append(str, ", ");
- get_compiled_caplibs_version(str);
+ /* Capture libraries */
+ g_string_append(str, ", ");
+ get_compiled_caplibs_version(str);
- /* LIBZ */
- g_string_append(str, ", ");
+ /* LIBZ */
+ g_string_append(str, ", ");
#ifdef HAVE_LIBZ
- g_string_append(str, "with libz ");
+ g_string_append(str, "with libz ");
#ifdef ZLIB_VERSION
- g_string_append(str, ZLIB_VERSION);
+ g_string_append(str, ZLIB_VERSION);
#else /* ZLIB_VERSION */
- g_string_append(str, "(version unknown)");
+ g_string_append(str, "(version unknown)");
#endif /* ZLIB_VERSION */
#else /* HAVE_LIBZ */
- g_string_append(str, "without libz");
+ g_string_append(str, "without libz");
#endif /* HAVE_LIBZ */
}
diff --git a/editcap.c b/editcap.c
index a6d4720e3c..ebdab74d34 100644
--- a/editcap.c
+++ b/editcap.c
@@ -59,7 +59,7 @@
#endif
#ifdef HAVE_LIBZ
-#include <zlib.h> /* to get the libz version number */
+#include <zlib.h> /* to get the libz version number */
#endif
#include "wtap.h"
diff --git a/epan/address.h b/epan/address.h
index d64cf93b0a..f3ab362d37 100644
--- a/epan/address.h
+++ b/epan/address.h
@@ -62,10 +62,10 @@ typedef enum {
} address_type;
typedef struct _address {
- address_type type; /* type of address */
- int hf; /* the specific field that this addr is */
- int len; /* length of address, in bytes */
- const void *data; /* pointer to address data */
+ address_type type; /* type of address */
+ int hf; /* the specific field that this addr is */
+ int len; /* length of address, in bytes */
+ const void *data; /* pointer to address data */
} address;
/** Initialize an address with the given values.
@@ -83,7 +83,7 @@ set_address(address *addr, address_type addr_type, int addr_len, const void * ad
addr->hf = -1;
addr->len = addr_len;
}
-#define SET_ADDRESS(addr, addr_type, addr_len, addr_data) \
+#define SET_ADDRESS(addr, addr_type, addr_len, addr_data) \
set_address((addr), (addr_type), (addr_len), (addr_data))
/** Initialize an address from TVB data.
@@ -101,7 +101,7 @@ set_address(address *addr, address_type addr_type, int addr_len, const void * ad
* @param addr_len [in] The length in bytes of the address data. For example, 4 for
* AT_IPv4 or sizeof(struct e_in6_addr) for AT_IPv6.
*/
-#define TVB_SET_ADDRESS(addr, addr_type, tvb, offset, addr_len) \
+#define TVB_SET_ADDRESS(addr, addr_type, tvb, offset, addr_len) \
do { \
const void *TVB_SET_ADDRESS_data = (const void *)tvb_get_ptr(tvb, offset, addr_len); \
set_address((addr), (addr_type), (addr_len), TVB_SET_ADDRESS_data); \
@@ -123,7 +123,7 @@ set_address_hf(address *addr, address_type addr_type, int addr_len, const void *
addr->hf = addr_hf;
addr->len = addr_len;
}
-#define SET_ADDRESS_HF(addr, addr_type, addr_len, addr_data, addr_hf) \
+#define SET_ADDRESS_HF(addr, addr_type, addr_len, addr_data, addr_hf) \
set_address_hf((addr), (addr_type), (addr_len), (addr_data), (addr_hf))
/** Initialize an address from TVB data including an associated field.
@@ -142,7 +142,7 @@ set_address_hf(address *addr, address_type addr_type, int addr_len, const void *
* AT_IPv4 or sizeof(struct e_in6_addr) for AT_IPv6.
* @param addr_hf [in] The header field index to associate with the address.
*/
-#define TVB_SET_ADDRESS_HF(addr, addr_type, tvb, offset, addr_len, addr_hf) \
+#define TVB_SET_ADDRESS_HF(addr, addr_type, tvb, offset, addr_len, addr_hf) \
do { \
const void *TVB_SET_ADDRESS_data = (const void *) tvb_get_ptr(tvb, offset, addr_len); \
set_address_hf((addr), (addr_type), (addr_len), TVB_SET_ADDRESS_data, (addr_hf)); \
@@ -284,35 +284,35 @@ add_address_to_hash64(guint64 hash_val, const address *addr) {
/* Types of port numbers Wireshark knows about. */
typedef enum {
- PT_NONE, /* no port number */
- PT_SCTP, /* SCTP */
- PT_TCP, /* TCP */
- PT_UDP, /* UDP */
- PT_DCCP, /* DCCP */
- PT_IPX, /* IPX sockets */
- PT_NCP, /* NCP connection */
- PT_EXCHG, /* Fibre Channel exchange */
- PT_DDP, /* DDP AppleTalk connection */
- PT_SBCCS, /* FICON */
- PT_IDP, /* XNS IDP sockets */
- PT_TIPC, /* TIPC PORT */
- PT_USB, /* USB endpoint 0xffff means the host */
+ PT_NONE, /* no port number */
+ PT_SCTP, /* SCTP */
+ PT_TCP, /* TCP */
+ PT_UDP, /* UDP */
+ PT_DCCP, /* DCCP */
+ PT_IPX, /* IPX sockets */
+ PT_NCP, /* NCP connection */
+ PT_EXCHG, /* Fibre Channel exchange */
+ PT_DDP, /* DDP AppleTalk connection */
+ PT_SBCCS, /* FICON */
+ PT_IDP, /* XNS IDP sockets */
+ PT_TIPC, /* TIPC PORT */
+ PT_USB, /* USB endpoint 0xffff means the host */
PT_I2C,
- PT_IBQP, /* Infiniband QP number */
+ PT_IBQP, /* Infiniband QP number */
PT_BLUETOOTH
} port_type;
/* Types of circuit IDs Wireshark knows about. */
typedef enum {
- CT_NONE, /* no circuit type */
- CT_DLCI, /* Frame Relay DLCI */
- CT_ISDN, /* ISDN channel number */
- CT_X25, /* X.25 logical channel number */
- CT_ISUP, /* ISDN User Part CIC */
- CT_IAX2, /* IAX2 call id */
- CT_H223, /* H.223 logical channel number */
- CT_BICC, /* BICC Circuit identifier */
- CT_DVBCI /* DVB-CI session number|transport connection id */
+ CT_NONE, /* no circuit type */
+ CT_DLCI, /* Frame Relay DLCI */
+ CT_ISDN, /* ISDN channel number */
+ CT_X25, /* X.25 logical channel number */
+ CT_ISUP, /* ISDN User Part CIC */
+ CT_IAX2, /* IAX2 call id */
+ CT_H223, /* H.223 logical channel number */
+ CT_BICC, /* BICC Circuit identifier */
+ CT_DVBCI /* DVB-CI session number|transport connection id */
/* Could also have ATM VPI/VCI pairs */
} circuit_type;
diff --git a/epan/charsets.h b/epan/charsets.h
index ed0d275a53..07456fdac2 100644
--- a/epan/charsets.h
+++ b/epan/charsets.h
@@ -88,11 +88,11 @@ get_ucs_4_string(wmem_allocator_t *scope, const guint8 *ptr, gint length, const
WS_DLL_PUBLIC guint8 *
get_ts_23_038_7bits_string(wmem_allocator_t *scope, const guint8 *ptr,
- const gint bit_offset, gint no_of_chars);
+ const gint bit_offset, gint no_of_chars);
WS_DLL_PUBLIC guint8 *
get_ascii_7bits_string(wmem_allocator_t *scope, const guint8 *ptr,
- const gint bit_offset, gint no_of_chars);
+ const gint bit_offset, gint no_of_chars);
WS_DLL_PUBLIC guint8 *
get_ebcdic_string(wmem_allocator_t *scope, const guint8 *ptr, gint length);
diff --git a/epan/conversation_table.c b/epan/conversation_table.c
index 57bbb6f9d7..61ec310a19 100644
--- a/epan/conversation_table.c
+++ b/epan/conversation_table.c
@@ -88,14 +88,14 @@ dissector_conversation_init(const char *opt_arg, void* userdata)
*/
register_ct_t* get_conversation_by_proto_id(int proto_id)
{
- GSList *ct;
- register_ct_t *table;
+ GSList *ct;
+ register_ct_t *table;
- for(ct = registered_ct_tables; ct != NULL; ct = g_slist_next(ct)){
- table = (register_ct_t*)ct->data;
- if ((table) && (table->proto_id == proto_id))
+ for(ct = registered_ct_tables; ct != NULL; ct = g_slist_next(ct)){
+ table = (register_ct_t*)ct->data;
+ if ((table) && (table->proto_id == proto_id))
return table;
- }
+ }
return NULL;
}
diff --git a/epan/frame_data_sequence.c b/epan/frame_data_sequence.c
index 8f969dabe3..a2e56006f4 100644
--- a/epan/frame_data_sequence.c
+++ b/epan/frame_data_sequence.c
@@ -38,8 +38,8 @@
* As frame numbers are 32 bits, and as 1024 is 2^10, that gives us
* up to 4 levels of tree.
*/
-#define LOG2_NODES_PER_LEVEL 10
-#define NODES_PER_LEVEL (1<<LOG2_NODES_PER_LEVEL)
+#define LOG2_NODES_PER_LEVEL 10
+#define NODES_PER_LEVEL (1<<LOG2_NODES_PER_LEVEL)
struct _frame_data_sequence {
guint32 count; /* Total number of frames */
@@ -51,23 +51,23 @@ struct _frame_data_sequence {
* node, a level 2 node, a level 1 node, and a leaf node.
*/
#define LEVEL_3_INDEX(framenum) \
- ((framenum) >> (3*LOG2_NODES_PER_LEVEL))
+ ((framenum) >> (3*LOG2_NODES_PER_LEVEL))
#define LEVEL_2_INDEX(framenum) \
- (((framenum) >> (2*LOG2_NODES_PER_LEVEL)) & (NODES_PER_LEVEL - 1))
+ (((framenum) >> (2*LOG2_NODES_PER_LEVEL)) & (NODES_PER_LEVEL - 1))
#define LEVEL_1_INDEX(framenum) \
- (((framenum) >> (1*LOG2_NODES_PER_LEVEL)) & (NODES_PER_LEVEL - 1))
+ (((framenum) >> (1*LOG2_NODES_PER_LEVEL)) & (NODES_PER_LEVEL - 1))
#define LEAF_INDEX(framenum) \
- (((framenum) >> (0*LOG2_NODES_PER_LEVEL)) & (NODES_PER_LEVEL - 1))
+ (((framenum) >> (0*LOG2_NODES_PER_LEVEL)) & (NODES_PER_LEVEL - 1))
frame_data_sequence *
new_frame_data_sequence(void)
{
- frame_data_sequence *fds;
+ frame_data_sequence *fds;
- fds = (frame_data_sequence *)g_malloc(sizeof *fds);
- fds->count = 0;
- fds->ptree_root = NULL;
- return fds;
+ fds = (frame_data_sequence *)g_malloc(sizeof *fds);
+ fds->count = 0;
+ fds->ptree_root = NULL;
+ return fds;
}
/*
diff --git a/epan/oids.h b/epan/oids.h
index 4bbdc4989a..a0668a5272 100644
--- a/epan/oids.h
+++ b/epan/oids.h
@@ -145,7 +145,7 @@ WS_DLL_PUBLIC
guint oid_encoded2subid(const guint8 *oid, gint len, guint32** subids_p);
WS_DLL_PUBLIC
guint oid_encoded2subid_sub(const guint8 *oid_bytes, gint oid_len, guint32** subids_pi,
- gboolean is_first);
+ gboolean is_first);
WS_DLL_PUBLIC
guint oid_string2subid(wmem_allocator_t *scope, const gchar *oid_str, guint32** subids_p);
diff --git a/epan/prefs.c b/epan/prefs.c
index 0f3951982d..f8a889666a 100644
--- a/epan/prefs.c
+++ b/epan/prefs.c
@@ -2600,91 +2600,91 @@ prefs_register_modules(void)
GList *
prefs_get_string_list(const gchar *str)
{
- enum { PRE_STRING, IN_QUOT, NOT_IN_QUOT };
-
- gint state = PRE_STRING, i = 0, j = 0;
- gboolean backslash = FALSE;
- guchar cur_c;
- gchar *slstr = NULL;
- GList *sl = NULL;
-
- /* Allocate a buffer for the first string. */
- slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
- j = 0;
-
- for (;;) {
- cur_c = str[i];
- if (cur_c == '\0') {
- /* It's the end of the input, so it's the end of the string we
- were working on, and there's no more input. */
- if (state == IN_QUOT || backslash) {
- /* We were in the middle of a quoted string or backslash escape,
- and ran out of characters; that's an error. */
- g_free(slstr);
- prefs_clear_string_list(sl);
- return NULL;
- }
- slstr[j] = '\0';
- sl = g_list_append(sl, slstr);
- break;
- }
- if (cur_c == '"' && ! backslash) {
- switch (state) {
- case PRE_STRING:
- /* We hadn't yet started processing a string; this starts the
- string, and we're now quoting. */
- state = IN_QUOT;
- break;
- case IN_QUOT:
- /* We're in the middle of a quoted string, and we saw a quotation
- mark; we're no longer quoting. */
- state = NOT_IN_QUOT;
- break;
- case NOT_IN_QUOT:
- /* We're working on a string, but haven't seen a quote; we're
- now quoting. */
- state = IN_QUOT;
- break;
- default:
- break;
- }
- } else if (cur_c == '\\' && ! backslash) {
- /* We saw a backslash, and the previous character wasn't a
- backslash; escape the next character.
-
- This also means we've started a new string. */
- backslash = TRUE;
- if (state == PRE_STRING)
- state = NOT_IN_QUOT;
- } else if (cur_c == ',' && state != IN_QUOT && ! backslash) {
- /* We saw a comma, and we're not in the middle of a quoted string
- and it wasn't preceded by a backslash; it's the end of
- the string we were working on... */
- slstr[j] = '\0';
- sl = g_list_append(sl, slstr);
-
- /* ...and the beginning of a new string. */
- state = PRE_STRING;
- slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
- j = 0;
- } else if (!isspace(cur_c) || state != PRE_STRING) {
- /* Either this isn't a white-space character, or we've started a
- string (i.e., already seen a non-white-space character for that
- string and put it into the string).
-
- The character is to be put into the string; do so if there's
- room. */
- if (j < COL_MAX_LEN) {
- slstr[j] = cur_c;
- j++;
- }
+ enum { PRE_STRING, IN_QUOT, NOT_IN_QUOT };
+
+ gint state = PRE_STRING, i = 0, j = 0;
+ gboolean backslash = FALSE;
+ guchar cur_c;
+ gchar *slstr = NULL;
+ GList *sl = NULL;
+
+ /* Allocate a buffer for the first string. */
+ slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
+ j = 0;
+
+ for (;;) {
+ cur_c = str[i];
+ if (cur_c == '\0') {
+ /* It's the end of the input, so it's the end of the string we
+ were working on, and there's no more input. */
+ if (state == IN_QUOT || backslash) {
+ /* We were in the middle of a quoted string or backslash escape,
+ and ran out of characters; that's an error. */
+ g_free(slstr);
+ prefs_clear_string_list(sl);
+ return NULL;
+ }
+ slstr[j] = '\0';
+ sl = g_list_append(sl, slstr);
+ break;
+ }
+ if (cur_c == '"' && ! backslash) {
+ switch (state) {
+ case PRE_STRING:
+ /* We hadn't yet started processing a string; this starts the
+ string, and we're now quoting. */
+ state = IN_QUOT;
+ break;
+ case IN_QUOT:
+ /* We're in the middle of a quoted string, and we saw a quotation
+ mark; we're no longer quoting. */
+ state = NOT_IN_QUOT;
+ break;
+ case NOT_IN_QUOT:
+ /* We're working on a string, but haven't seen a quote; we're
+ now quoting. */
+ state = IN_QUOT;
+ break;
+ default:
+ break;
+ }
+ } else if (cur_c == '\\' && ! backslash) {
+ /* We saw a backslash, and the previous character wasn't a
+ backslash; escape the next character.
+
+ This also means we've started a new string. */
+ backslash = TRUE;
+ if (state == PRE_STRING)
+ state = NOT_IN_QUOT;
+ } else if (cur_c == ',' && state != IN_QUOT && ! backslash) {
+ /* We saw a comma, and we're not in the middle of a quoted string
+ and it wasn't preceded by a backslash; it's the end of
+ the string we were working on... */
+ slstr[j] = '\0';
+ sl = g_list_append(sl, slstr);
+
+ /* ...and the beginning of a new string. */
+ state = PRE_STRING;
+ slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
+ j = 0;
+ } else if (!isspace(cur_c) || state != PRE_STRING) {
+ /* Either this isn't a white-space character, or we've started a
+ string (i.e., already seen a non-white-space character for that
+ string and put it into the string).
+
+ The character is to be put into the string; do so if there's
+ room. */
+ if (j < COL_MAX_LEN) {
+ slstr[j] = cur_c;
+ j++;
+ }
- /* If it was backslash-escaped, we're done with the backslash escape. */
- backslash = FALSE;
+ /* If it was backslash-escaped, we're done with the backslash escape. */
+ backslash = FALSE;
+ }
+ i++;
}
- i++;
- }
- return(sl);
+ return(sl);
}
char *join_string_list(GList *sl)
@@ -2721,12 +2721,12 @@ char *join_string_list(GList *sl)
void
prefs_clear_string_list(GList *sl)
{
- GList *l = sl;
+ GList *l = sl;
- while (l) {
- g_free(l->data);
- l = g_list_remove_link(l, l);
- }
+ while (l) {
+ g_free(l->data);
+ l = g_list_remove_link(l, l);
+ }
}
/*
@@ -2789,55 +2789,55 @@ print.file: /a/very/long/path/
static gboolean
parse_column_format(fmt_data *cfmt, const char *fmt)
{
- const gchar *cust_format = col_format_to_string(COL_CUSTOM);
- size_t cust_format_len = strlen(cust_format);
- gchar **cust_format_info;
- char *p;
- int col_fmt;
- gchar *col_custom_field;
- long col_custom_occurrence;
- gboolean col_resolved;
-
- /*
- * Is this a custom column?
- */
- if ((strlen(fmt) > cust_format_len) && (fmt[cust_format_len] == ':') &&
- strncmp(fmt, cust_format, cust_format_len) == 0) {
- /* Yes. */
- col_fmt = COL_CUSTOM;
- cust_format_info = g_strsplit(&fmt[cust_format_len+1],":",3); /* add 1 for ':' */
- col_custom_field = g_strdup(cust_format_info[0]);
- if (col_custom_field && cust_format_info[1]) {
- col_custom_occurrence = strtol(cust_format_info[1], &p, 10);
- if (p == cust_format_info[1] || *p != '\0') {
- /* Not a valid number. */
- g_free(col_custom_field);
+ const gchar *cust_format = col_format_to_string(COL_CUSTOM);
+ size_t cust_format_len = strlen(cust_format);
+ gchar **cust_format_info;
+ char *p;
+ int col_fmt;
+ gchar *col_custom_field;
+ long col_custom_occurrence;
+ gboolean col_resolved;
+
+ /*
+ * Is this a custom column?
+ */
+ if ((strlen(fmt) > cust_format_len) && (fmt[cust_format_len] == ':') &&
+ strncmp(fmt, cust_format, cust_format_len) == 0) {
+ /* Yes. */
+ col_fmt = COL_CUSTOM;
+ cust_format_info = g_strsplit(&fmt[cust_format_len+1],":",3); /* add 1 for ':' */
+ col_custom_field = g_strdup(cust_format_info[0]);
+ if (col_custom_field && cust_format_info[1]) {
+ col_custom_occurrence = strtol(cust_format_info[1], &p, 10);
+ if (p == cust_format_info[1] || *p != '\0') {
+ /* Not a valid number. */
+ g_free(col_custom_field);
+ g_strfreev(cust_format_info);
+ return FALSE;
+ }
+ } else {
+ col_custom_occurrence = 0;
+ }
+ if (col_custom_field && cust_format_info[1] && cust_format_info[2]) {
+ col_resolved = (cust_format_info[2][0] == 'U') ? FALSE : TRUE;
+ } else {
+ col_resolved = TRUE;
+ }
g_strfreev(cust_format_info);
- return FALSE;
- }
- } else {
- col_custom_occurrence = 0;
- }
- if (col_custom_field && cust_format_info[1] && cust_format_info[2]) {
- col_resolved = (cust_format_info[2][0] == 'U') ? FALSE : TRUE;
} else {
- col_resolved = TRUE;
+ col_fmt = get_column_format_from_str(fmt);
+ if (col_fmt == -1)
+ return FALSE;
+ col_custom_field = NULL;
+ col_custom_occurrence = 0;
+ col_resolved = TRUE;
}
- g_strfreev(cust_format_info);
- } else {
- col_fmt = get_column_format_from_str(fmt);
- if (col_fmt == -1)
- return FALSE;
- col_custom_field = NULL;
- col_custom_occurrence = 0;
- col_resolved = TRUE;
- }
-
- cfmt->fmt = col_fmt;
- cfmt->custom_field = col_custom_field;
- cfmt->custom_occurrence = (int)col_custom_occurrence;
- cfmt->resolved = col_resolved;
- return TRUE;
+
+ cfmt->fmt = col_fmt;
+ cfmt->custom_field = col_custom_field;
+ cfmt->custom_occurrence = (int)col_custom_occurrence;
+ cfmt->resolved = col_resolved;
+ return TRUE;
}
/* Initialize non-dissector preferences to wired-in default values.
@@ -2849,16 +2849,16 @@ parse_column_format(fmt_data *cfmt, const char *fmt)
static void
init_prefs(void)
{
- if (prefs_initialized)
- return;
+ if (prefs_initialized)
+ return;
- uat_load_all();
+ uat_load_all();
- prefs_register_modules();
+ prefs_register_modules();
- filter_expression_init(TRUE);
+ filter_expression_init(TRUE);
- prefs_initialized = TRUE;
+ prefs_initialized = TRUE;
}
/* Initialize non-dissector preferences used by the "register preference" API
@@ -2867,168 +2867,168 @@ init_prefs(void)
static void
pre_init_prefs(void)
{
- int i;
- gchar *col_name;
- fmt_data *cfmt;
- static const gchar *col_fmt[DEF_NUM_COLS*2] = {
- "No.", "%m", "Time", "%t",
- "Source", "%s", "Destination", "%d",
- "Protocol", "%p", "Length", "%L",
- "Info", "%i"};
-
- if (prefs_pre_initialized)
- return;
-
- prefs.pr_format = PR_FMT_TEXT;
- prefs.pr_dest = PR_DEST_CMD;
- prefs.pr_file = "wireshark.out";
- prefs.pr_cmd = "lpr";
-
- prefs.gui_altern_colors = FALSE;
- prefs.gui_expert_composite_eyecandy = FALSE;
- prefs.gui_ptree_line_style = 0;
- prefs.gui_ptree_expander_style = 1;
- prefs.gui_hex_dump_highlight_style = 1;
- prefs.filter_toolbar_show_in_statusbar = FALSE;
- prefs.gui_toolbar_main_style = TB_STYLE_ICONS;
- prefs.gui_toolbar_filter_style = TB_STYLE_TEXT;
- /* These string prefs will be strduped shortly, so we can safely cast away
- * their constness in these assignments */
+ int i;
+ gchar *col_name;
+ fmt_data *cfmt;
+ static const gchar *col_fmt[DEF_NUM_COLS*2] = {
+ "No.", "%m", "Time", "%t",
+ "Source", "%s", "Destination", "%d",
+ "Protocol", "%p", "Length", "%L",
+ "Info", "%i"};
+
+ if (prefs_pre_initialized)
+ return;
+
+ prefs.pr_format = PR_FMT_TEXT;
+ prefs.pr_dest = PR_DEST_CMD;
+ prefs.pr_file = "wireshark.out";
+ prefs.pr_cmd = "lpr";
+
+ prefs.gui_altern_colors = FALSE;
+ prefs.gui_expert_composite_eyecandy = FALSE;
+ prefs.gui_ptree_line_style = 0;
+ prefs.gui_ptree_expander_style = 1;
+ prefs.gui_hex_dump_highlight_style = 1;
+ prefs.filter_toolbar_show_in_statusbar = FALSE;
+ prefs.gui_toolbar_main_style = TB_STYLE_ICONS;
+ prefs.gui_toolbar_filter_style = TB_STYLE_TEXT;
+ /* These string prefs will be strduped shortly, so we can safely cast away
+ * their constness in these assignments */
#ifdef _WIN32
- prefs.gui_gtk2_font_name = (char *) "Lucida Console 10";
+ prefs.gui_gtk2_font_name = (char *) "Lucida Console 10";
#else
- prefs.gui_gtk2_font_name = (char *) "Monospace 10";
+ prefs.gui_gtk2_font_name = (char *) "Monospace 10";
#endif
- /* We try to find the best font in the Qt code */
- prefs.gui_qt_font_name = (char *) "";
- prefs.gui_marked_fg.pixel = 65535;
- prefs.gui_marked_fg.red = 65535;
- prefs.gui_marked_fg.green = 65535;
- prefs.gui_marked_fg.blue = 65535;
- prefs.gui_marked_bg.pixel = 0;
- prefs.gui_marked_bg.red = 0;
- prefs.gui_marked_bg.green = 8224;
- prefs.gui_marked_bg.blue = 10794;
- prefs.gui_ignored_fg.pixel = 32767;
- prefs.gui_ignored_fg.red = 32767;
- prefs.gui_ignored_fg.green = 32767;
- prefs.gui_ignored_fg.blue = 32767;
- prefs.gui_ignored_bg.pixel = 65535;
- prefs.gui_ignored_bg.red = 65535;
- prefs.gui_ignored_bg.green = 65535;
- prefs.gui_ignored_bg.blue = 65535;
- prefs.gui_colorized_fg = "000000,000000,000000,000000,000000,000000,000000,000000,000000,000000";
- prefs.gui_colorized_bg = "ffc0c0,ffc0ff,e0c0e0,c0c0ff,c0e0e0,c0ffff,c0ffc0,ffffc0,e0e0c0,e0e0e0";
- prefs.st_client_fg.pixel = 0;
- prefs.st_client_fg.red = 32767;
- prefs.st_client_fg.green = 0;
- prefs.st_client_fg.blue = 0;
- prefs.st_client_bg.pixel = 0;
- prefs.st_client_bg.red = 64507;
- prefs.st_client_bg.green = 60909;
- prefs.st_client_bg.blue = 60909;
- prefs.st_server_fg.pixel = 0;
- prefs.st_server_fg.red = 0;
- prefs.st_server_fg.green = 0;
- prefs.st_server_fg.blue = 32767;
- prefs.st_server_bg.pixel = 0;
- prefs.st_server_bg.red = 60909;
- prefs.st_server_bg.green = 60909;
- prefs.st_server_bg.blue = 64507;
- prefs.gui_text_valid.pixel = 0; /* light green */
- prefs.gui_text_valid.red = 0xAFFF;
- prefs.gui_text_valid.green = 0xFFFF;
- prefs.gui_text_valid.blue = 0xAFFF;
- prefs.gui_text_invalid.pixel = 0; /* light red */
- prefs.gui_text_invalid.red = 0xFFFF;
- prefs.gui_text_invalid.green = 0xAFFF;
- prefs.gui_text_invalid.blue = 0xAFFF;
- prefs.gui_text_deprecated.pixel = 0; /* light yellow */
- prefs.gui_text_deprecated.red = 0xFFFF;
- prefs.gui_text_deprecated.green = 0xFFFF;
- prefs.gui_text_deprecated.blue = 0xAFFF;
- prefs.gui_geometry_save_position = TRUE;
- prefs.gui_geometry_save_size = TRUE;
- prefs.gui_geometry_save_maximized= TRUE;
- prefs.gui_macosx_style = TRUE;
- prefs.gui_console_open = console_open_never;
- prefs.gui_fileopen_style = FO_STYLE_LAST_OPENED;
- prefs.gui_recent_df_entries_max = 10;
- prefs.gui_recent_files_count_max = 10;
- prefs.gui_fileopen_dir = (char *) get_persdatafile_dir();
- prefs.gui_fileopen_preview = 3;
- prefs.gui_ask_unsaved = TRUE;
- prefs.gui_find_wrap = TRUE;
- prefs.gui_use_pref_save = FALSE;
- prefs.gui_update_enabled = TRUE;
- prefs.gui_update_channel = UPDATE_CHANNEL_STABLE;
- prefs.gui_update_interval = 60*60*24; /* Seconds */
+ /* We try to find the best font in the Qt code */
+ prefs.gui_qt_font_name = (char *) "";
+ prefs.gui_marked_fg.pixel = 65535;
+ prefs.gui_marked_fg.red = 65535;
+ prefs.gui_marked_fg.green = 65535;
+ prefs.gui_marked_fg.blue = 65535;
+ prefs.gui_marked_bg.pixel = 0;
+ prefs.gui_marked_bg.red = 0;
+ prefs.gui_marked_bg.green = 8224;
+ prefs.gui_marked_bg.blue = 10794;
+ prefs.gui_ignored_fg.pixel = 32767;
+ prefs.gui_ignored_fg.red = 32767;
+ prefs.gui_ignored_fg.green = 32767;
+ prefs.gui_ignored_fg.blue = 32767;
+ prefs.gui_ignored_bg.pixel = 65535;
+ prefs.gui_ignored_bg.red = 65535;
+ prefs.gui_ignored_bg.green = 65535;
+ prefs.gui_ignored_bg.blue = 65535;
+ prefs.gui_colorized_fg = "000000,000000,000000,000000,000000,000000,000000,000000,000000,000000";
+ prefs.gui_colorized_bg = "ffc0c0,ffc0ff,e0c0e0,c0c0ff,c0e0e0,c0ffff,c0ffc0,ffffc0,e0e0c0,e0e0e0";
+ prefs.st_client_fg.pixel = 0;
+ prefs.st_client_fg.red = 32767;
+ prefs.st_client_fg.green = 0;
+ prefs.st_client_fg.blue = 0;
+ prefs.st_client_bg.pixel = 0;
+ prefs.st_client_bg.red = 64507;
+ prefs.st_client_bg.green = 60909;
+ prefs.st_client_bg.blue = 60909;
+ prefs.st_server_fg.pixel = 0;
+ prefs.st_server_fg.red = 0;
+ prefs.st_server_fg.green = 0;
+ prefs.st_server_fg.blue = 32767;
+ prefs.st_server_bg.pixel = 0;
+ prefs.st_server_bg.red = 60909;
+ prefs.st_server_bg.green = 60909;
+ prefs.st_server_bg.blue = 64507;
+ prefs.gui_text_valid.pixel = 0; /* light green */
+ prefs.gui_text_valid.red = 0xAFFF;
+ prefs.gui_text_valid.green = 0xFFFF;
+ prefs.gui_text_valid.blue = 0xAFFF;
+ prefs.gui_text_invalid.pixel = 0; /* light red */
+ prefs.gui_text_invalid.red = 0xFFFF;
+ prefs.gui_text_invalid.green = 0xAFFF;
+ prefs.gui_text_invalid.blue = 0xAFFF;
+ prefs.gui_text_deprecated.pixel = 0; /* light yellow */
+ prefs.gui_text_deprecated.red = 0xFFFF;
+ prefs.gui_text_deprecated.green = 0xFFFF;
+ prefs.gui_text_deprecated.blue = 0xAFFF;
+ prefs.gui_geometry_save_position = TRUE;
+ prefs.gui_geometry_save_size = TRUE;
+ prefs.gui_geometry_save_maximized= TRUE;
+ prefs.gui_macosx_style = TRUE;
+ prefs.gui_console_open = console_open_never;
+ prefs.gui_fileopen_style = FO_STYLE_LAST_OPENED;
+ prefs.gui_recent_df_entries_max = 10;
+ prefs.gui_recent_files_count_max = 10;
+ prefs.gui_fileopen_dir = (char *) get_persdatafile_dir();
+ prefs.gui_fileopen_preview = 3;
+ prefs.gui_ask_unsaved = TRUE;
+ prefs.gui_find_wrap = TRUE;
+ prefs.gui_use_pref_save = FALSE;
+ prefs.gui_update_enabled = TRUE;
+ prefs.gui_update_channel = UPDATE_CHANNEL_STABLE;
+ prefs.gui_update_interval = 60*60*24; /* Seconds */
#ifdef HTML_VIEWER
- prefs.gui_webbrowser = (char *) HTML_VIEWER " %s";
+ prefs.gui_webbrowser = (char *) HTML_VIEWER " %s";
#else
- prefs.gui_webbrowser = (char *) "";
+ prefs.gui_webbrowser = (char *) "";
#endif
- prefs.gui_window_title = (char *) "";
- prefs.gui_start_title = "The World's Most Popular Network Protocol Analyzer";
- prefs.gui_version_placement = version_both;
- prefs.gui_auto_scroll_on_expand = FALSE;
- prefs.gui_auto_scroll_percentage = 0;
- prefs.gui_layout_type = layout_type_5;
- prefs.gui_layout_content_1 = layout_pane_content_plist;
- prefs.gui_layout_content_2 = layout_pane_content_pdetails;
- prefs.gui_layout_content_3 = layout_pane_content_pbytes;
- prefs.gui_qt_language = 0; /* (Auto-Detect) */
- prefs.gui_packet_editor = FALSE;
-
- prefs.col_list = NULL;
- for (i = 0; i < DEF_NUM_COLS; i++) {
- cfmt = g_new(fmt_data,1);
- cfmt->title = g_strdup(col_fmt[i * 2]);
- parse_column_format(cfmt, col_fmt[(i * 2) + 1]);
- cfmt->visible = TRUE;
- cfmt->resolved = TRUE;
- cfmt->custom_field = NULL;
- cfmt->custom_occurrence = 0;
- prefs.col_list = g_list_append(prefs.col_list, cfmt);
- }
- prefs.num_cols = DEF_NUM_COLS;
+ prefs.gui_window_title = (char *) "";
+ prefs.gui_start_title = "The World's Most Popular Network Protocol Analyzer";
+ prefs.gui_version_placement = version_both;
+ prefs.gui_auto_scroll_on_expand = FALSE;
+ prefs.gui_auto_scroll_percentage = 0;
+ prefs.gui_layout_type = layout_type_5;
+ prefs.gui_layout_content_1 = layout_pane_content_plist;
+ prefs.gui_layout_content_2 = layout_pane_content_pdetails;
+ prefs.gui_layout_content_3 = layout_pane_content_pbytes;
+ prefs.gui_qt_language = 0; /* (Auto-Detect) */
+ prefs.gui_packet_editor = FALSE;
+
+ prefs.col_list = NULL;
+ for (i = 0; i < DEF_NUM_COLS; i++) {
+ cfmt = g_new(fmt_data,1);
+ cfmt->title = g_strdup(col_fmt[i * 2]);
+ parse_column_format(cfmt, col_fmt[(i * 2) + 1]);
+ cfmt->visible = TRUE;
+ cfmt->resolved = TRUE;
+ cfmt->custom_field = NULL;
+ cfmt->custom_occurrence = 0;
+ prefs.col_list = g_list_append(prefs.col_list, cfmt);
+ }
+ prefs.num_cols = DEF_NUM_COLS;
/* set the default values for the capture dialog box */
- prefs.capture_prom_mode = TRUE;
+ prefs.capture_prom_mode = TRUE;
#ifdef PCAP_NG_DEFAULT
- prefs.capture_pcap_ng = TRUE;
+ prefs.capture_pcap_ng = TRUE;
#else
- prefs.capture_pcap_ng = FALSE;
+ prefs.capture_pcap_ng = FALSE;
#endif
- prefs.capture_real_time = TRUE;
- prefs.capture_auto_scroll = TRUE;
- prefs.capture_show_info = FALSE;
-
- prefs.capture_columns = NULL;
- for (i = 0; i < num_capture_cols; i++) {
- col_name = g_strdup(capture_cols[i]);
- prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
- }
+ prefs.capture_real_time = TRUE;
+ prefs.capture_auto_scroll = TRUE;
+ prefs.capture_show_info = FALSE;
+
+ prefs.capture_columns = NULL;
+ for (i = 0; i < num_capture_cols; i++) {
+ col_name = g_strdup(capture_cols[i]);
+ prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
+ }
- prefs.console_log_level =
- G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR;
+ prefs.console_log_level =
+ G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR;
/* set the default values for the tap/statistics dialog box */
- prefs.tap_update_interval = TAP_UPDATE_DEFAULT_INTERVAL;
- prefs.rtp_player_max_visible = RTP_PLAYER_DEFAULT_VISIBLE;
- prefs.st_enable_burstinfo = TRUE;
- prefs.st_burst_showcount = FALSE;
- prefs.st_burst_resolution = ST_DEF_BURSTRES;
- prefs.st_burst_windowlen = ST_DEF_BURSTLEN;
- prefs.st_sort_casesensitve = TRUE;
- prefs.st_sort_rng_fixorder = TRUE;
- prefs.st_sort_rng_nameonly = TRUE;
- prefs.st_sort_defcolflag = ST_SORT_COL_COUNT;
- prefs.st_sort_defdescending = TRUE;
- prefs.st_sort_showfullname = FALSE;
- prefs.display_hidden_proto_items = FALSE;
-
- prefs_pre_initialized = TRUE;
+ prefs.tap_update_interval = TAP_UPDATE_DEFAULT_INTERVAL;
+ prefs.rtp_player_max_visible = RTP_PLAYER_DEFAULT_VISIBLE;
+ prefs.st_enable_burstinfo = TRUE;
+ prefs.st_burst_showcount = FALSE;
+ prefs.st_burst_resolution = ST_DEF_BURSTRES;
+ prefs.st_burst_windowlen = ST_DEF_BURSTLEN;
+ prefs.st_sort_casesensitve = TRUE;
+ prefs.st_sort_rng_fixorder = TRUE;
+ prefs.st_sort_rng_nameonly = TRUE;
+ prefs.st_sort_defcolflag = ST_SORT_COL_COUNT;
+ prefs.st_sort_defdescending = TRUE;
+ prefs.st_sort_showfullname = FALSE;
+ prefs.display_hidden_proto_items = FALSE;
+
+ prefs_pre_initialized = TRUE;
}
/*
@@ -3124,29 +3124,29 @@ reset_module_prefs(void *value, void *data _U_)
void
prefs_reset(void)
{
- prefs_initialized = FALSE;
- g_free(prefs.saved_at_version);
- prefs.saved_at_version = NULL;
-
- /*
- * Unload all UAT preferences.
- */
- uat_unload_all();
-
- /*
- * Unload any loaded MIBs.
- */
- oids_cleanup();
-
- /*
- * Reset the non-dissector preferences.
- */
- init_prefs();
-
- /*
- * Reset the non-UAT dissector preferences.
- */
- wmem_tree_foreach(prefs_modules, reset_module_prefs, NULL);
+ prefs_initialized = FALSE;
+ g_free(prefs.saved_at_version);
+ prefs.saved_at_version = NULL;
+
+ /*
+ * Unload all UAT preferences.
+ */
+ uat_unload_all();
+
+ /*
+ * Unload any loaded MIBs.
+ */
+ oids_cleanup();
+
+ /*
+ * Reset the non-dissector preferences.
+ */
+ init_prefs();
+
+ /*
+ * Reset the non-UAT dissector preferences.
+ */
+ wmem_tree_foreach(prefs_modules, reset_module_prefs, NULL);
}
/* Read the preferences file, fill in "prefs", and return a pointer to it.
@@ -3166,115 +3166,115 @@ read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
char **gpf_path_return, int *pf_errno_return,
int *pf_read_errno_return, char **pf_path_return)
{
- int err;
- char *pf_path;
- FILE *pf;
+ int err;
+ char *pf_path;
+ FILE *pf;
- /* clean up libsmi structures before reading prefs */
- oids_cleanup();
+ /* clean up libsmi structures before reading prefs */
+ oids_cleanup();
- init_prefs();
+ init_prefs();
- /*
- * If we don't already have the pathname of the global preferences
- * file, construct it. Then, in either case, try to open the file.
- */
- if (gpf_path == NULL) {
/*
- * We don't have the path; try the new path first, and, if that
- * file doesn't exist, try the old path.
+ * If we don't already have the pathname of the global preferences
+ * file, construct it. Then, in either case, try to open the file.
*/
- gpf_path = get_datafile_path(PF_NAME);
- if ((pf = ws_fopen(gpf_path, "r")) == NULL && errno == ENOENT) {
- /*
- * It doesn't exist by the new name; try the old name.
- */
- g_free(gpf_path);
- gpf_path = get_datafile_path(OLD_GPF_NAME);
- pf = ws_fopen(gpf_path, "r");
+ if (gpf_path == NULL) {
+ /*
+ * We don't have the path; try the new path first, and, if that
+ * file doesn't exist, try the old path.
+ */
+ gpf_path = get_datafile_path(PF_NAME);
+ if ((pf = ws_fopen(gpf_path, "r")) == NULL && errno == ENOENT) {
+ /*
+ * It doesn't exist by the new name; try the old name.
+ */
+ g_free(gpf_path);
+ gpf_path = get_datafile_path(OLD_GPF_NAME);
+ pf = ws_fopen(gpf_path, "r");
+ }
+ } else {
+ /*
+ * We have the path; try it.
+ */
+ pf = ws_fopen(gpf_path, "r");
}
- } else {
- /*
- * We have the path; try it.
- */
- pf = ws_fopen(gpf_path, "r");
- }
-
- /*
- * If we were able to open the file, read it.
- * XXX - if it failed for a reason other than "it doesn't exist",
- * report the error.
- */
- *gpf_path_return = NULL;
- if (pf != NULL) {
+
/*
- * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
- * seen.
+ * If we were able to open the file, read it.
+ * XXX - if it failed for a reason other than "it doesn't exist",
+ * report the error.
*/
- mgcp_tcp_port_count = 0;
- mgcp_udp_port_count = 0;
-
- /* We succeeded in opening it; read it. */
- err = read_prefs_file(gpf_path, pf, set_pref, NULL);
- if (err != 0) {
- /* We had an error reading the file; return the errno and the
- pathname, so our caller can report the error. */
- *gpf_errno_return = 0;
- *gpf_read_errno_return = err;
- *gpf_path_return = gpf_path;
+ *gpf_path_return = NULL;
+ if (pf != NULL) {
+ /*
+ * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
+ * seen.
+ */
+ mgcp_tcp_port_count = 0;
+ mgcp_udp_port_count = 0;
+
+ /* We succeeded in opening it; read it. */
+ err = read_prefs_file(gpf_path, pf, set_pref, NULL);
+ if (err != 0) {
+ /* We had an error reading the file; return the errno and the
+ pathname, so our caller can report the error. */
+ *gpf_errno_return = 0;
+ *gpf_read_errno_return = err;
+ *gpf_path_return = gpf_path;
+ }
+ fclose(pf);
+ } else {
+ /* We failed to open it. If we failed for some reason other than
+ "it doesn't exist", return the errno and the pathname, so our
+ caller can report the error. */
+ if (errno != ENOENT) {
+ *gpf_errno_return = errno;
+ *gpf_read_errno_return = 0;
+ *gpf_path_return = gpf_path;
+ }
}
- fclose(pf);
- } else {
- /* We failed to open it. If we failed for some reason other than
- "it doesn't exist", return the errno and the pathname, so our
- caller can report the error. */
- if (errno != ENOENT) {
- *gpf_errno_return = errno;
- *gpf_read_errno_return = 0;
- *gpf_path_return = gpf_path;
+
+ /* Construct the pathname of the user's preferences file. */
+ pf_path = get_persconffile_path(PF_NAME, TRUE);
+
+ /* Read the user's preferences file, if it exists. */
+ *pf_path_return = NULL;
+ if ((pf = ws_fopen(pf_path, "r")) != NULL) {
+ /*
+ * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
+ * seen.
+ */
+ mgcp_tcp_port_count = 0;
+ mgcp_udp_port_count = 0;
+
+ /* We succeeded in opening it; read it. */
+ err = read_prefs_file(pf_path, pf, set_pref, NULL);
+ if (err != 0) {
+ /* We had an error reading the file; return the errno and the
+ pathname, so our caller can report the error. */
+ *pf_errno_return = 0;
+ *pf_read_errno_return = err;
+ *pf_path_return = pf_path;
+ } else
+ g_free(pf_path);
+ fclose(pf);
+ } else {
+ /* We failed to open it. If we failed for some reason other than
+ "it doesn't exist", return the errno and the pathname, so our
+ caller can report the error. */
+ if (errno != ENOENT) {
+ *pf_errno_return = errno;
+ *pf_read_errno_return = 0;
+ *pf_path_return = pf_path;
+ } else
+ g_free(pf_path);
}
- }
- /* Construct the pathname of the user's preferences file. */
- pf_path = get_persconffile_path(PF_NAME, TRUE);
+ /* load SMI modules if needed */
+ oids_init();
- /* Read the user's preferences file, if it exists. */
- *pf_path_return = NULL;
- if ((pf = ws_fopen(pf_path, "r")) != NULL) {
- /*
- * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
- * seen.
- */
- mgcp_tcp_port_count = 0;
- mgcp_udp_port_count = 0;
-
- /* We succeeded in opening it; read it. */
- err = read_prefs_file(pf_path, pf, set_pref, NULL);
- if (err != 0) {
- /* We had an error reading the file; return the errno and the
- pathname, so our caller can report the error. */
- *pf_errno_return = 0;
- *pf_read_errno_return = err;
- *pf_path_return = pf_path;
- } else
- g_free(pf_path);
- fclose(pf);
- } else {
- /* We failed to open it. If we failed for some reason other than
- "it doesn't exist", return the errno and the pathname, so our
- caller can report the error. */
- if (errno != ENOENT) {
- *pf_errno_return = errno;
- *pf_read_errno_return = 0;
- *pf_path_return = pf_path;
- } else
- g_free(pf_path);
- }
-
- /* load SMI modules if needed */
- oids_init();
-
- return &prefs;
+ return &prefs;
}
/* read the preferences file (or similiar) and call the callback
@@ -3283,192 +3283,192 @@ int
read_prefs_file(const char *pf_path, FILE *pf,
pref_set_pair_cb pref_set_pair_fct, void *private_data)
{
- enum {
- START, /* beginning of a line */
- IN_VAR, /* processing key name */
- PRE_VAL, /* finished processing key name, skipping white space befor evalue */
- IN_VAL, /* processing value */
- IN_SKIP /* skipping to the end of the line */
- } state = START;
- int got_c;
- GString *cur_val;
- GString *cur_var;
- gboolean got_val = FALSE;
- gint fline = 1, pline = 1;
- gchar hint[] = "(save preferences to remove this warning)";
- gchar ver[128];
-
- cur_val = g_string_new("");
- cur_var = g_string_new("");
-
- /* Try to read in the profile name in the first line of the preferences file. */
- if (fscanf(pf, "# Configuration file for %127[^\r\n]", ver) == 1) {
- /* Assume trailing period and remove it */
- prefs.saved_at_version = g_strndup(ver, strlen(ver) - 1);
- }
- rewind(pf);
-
- while ((got_c = getc(pf)) != EOF) {
- if (got_c == '\r') {
- /* Treat CR-LF at the end of a line like LF, so that if we're reading
- * a Windows-format file on UN*X, we handle it the same way we'd handle
- * a UN*X-format file. */
- got_c = getc(pf);
- if (got_c == EOF)
- break;
- if (got_c != '\n') {
- /* Put back the character after the CR, and process the CR normally. */
- ungetc(got_c, pf);
- got_c = '\r';
- }
- }
- if (got_c == '\n') {
- state = START;
- fline++;
- continue;
+ enum {
+ START, /* beginning of a line */
+ IN_VAR, /* processing key name */
+ PRE_VAL, /* finished processing key name, skipping white space befor evalue */
+ IN_VAL, /* processing value */
+ IN_SKIP /* skipping to the end of the line */
+ } state = START;
+ int got_c;
+ GString *cur_val;
+ GString *cur_var;
+ gboolean got_val = FALSE;
+ gint fline = 1, pline = 1;
+ gchar hint[] = "(save preferences to remove this warning)";
+ gchar ver[128];
+
+ cur_val = g_string_new("");
+ cur_var = g_string_new("");
+
+ /* Try to read in the profile name in the first line of the preferences file. */
+ if (fscanf(pf, "# Configuration file for %127[^\r\n]", ver) == 1) {
+ /* Assume trailing period and remove it */
+ prefs.saved_at_version = g_strndup(ver, strlen(ver) - 1);
}
+ rewind(pf);
+
+ while ((got_c = getc(pf)) != EOF) {
+ if (got_c == '\r') {
+ /* Treat CR-LF at the end of a line like LF, so that if we're reading
+ * a Windows-format file on UN*X, we handle it the same way we'd handle
+ * a UN*X-format file. */
+ got_c = getc(pf);
+ if (got_c == EOF)
+ break;
+ if (got_c != '\n') {
+ /* Put back the character after the CR, and process the CR normally. */
+ ungetc(got_c, pf);
+ got_c = '\r';
+ }
+ }
+ if (got_c == '\n') {
+ state = START;
+ fline++;
+ continue;
+ }
- switch (state) {
- case START:
- if (isalnum(got_c)) {
- if (cur_var->len > 0) {
- if (got_val) {
- if (cur_val->len > 0) {
- if (cur_val->str[cur_val->len-1] == ',') {
- /*
- * If the pref has a trailing comma, eliminate it.
- */
- cur_val->str[cur_val->len-1] = '\0';
- g_warning ("%s line %d: trailing comma in \"%s\" %s", pf_path, pline, cur_var->str, hint);
+ switch (state) {
+ case START:
+ if (isalnum(got_c)) {
+ if (cur_var->len > 0) {
+ if (got_val) {
+ if (cur_val->len > 0) {
+ if (cur_val->str[cur_val->len-1] == ',') {
+ /*
+ * If the pref has a trailing comma, eliminate it.
+ */
+ cur_val->str[cur_val->len-1] = '\0';
+ g_warning ("%s line %d: trailing comma in \"%s\" %s", pf_path, pline, cur_var->str, hint);
+ }
+ }
+ /* Call the routine to set the preference; it will parse
+ the value as appropriate.
+
+ Since we're reading a file, rather than processing
+ explicit user input, for range preferences, silently
+ lower values in excess of the range's maximum, rather
+ than reporting errors and failing. */
+ switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, FALSE)) {
+
+ case PREFS_SET_OK:
+ break;
+
+ case PREFS_SET_SYNTAX_ERR:
+ g_warning ("Syntax error in preference \"%s\" at line %d of\n%s %s",
+ cur_var->str, pline, pf_path, hint);
+ break;
+
+ case PREFS_SET_NO_SUCH_PREF:
+ /*
+ * If "print.command" silently ignore it because it's valid
+ * on non-Win32 platforms.
+ */
+ if (strcmp(cur_var->str, "print.command") != 0)
+ g_warning ("No such preference \"%s\" at line %d of\n%s %s",
+ cur_var->str, pline, pf_path, hint);
+ prefs.unknown_prefs = TRUE;
+ break;
+
+ case PREFS_SET_OBSOLETE:
+ if (strcmp(cur_var->str, "print.command") != 0)
+ /* If an attempt is made to save the preferences, a popup warning will be
+ displayed stating that obsolete prefs have been detected and the user will
+ be given the opportunity to save these prefs under a different profile name.
+ The prefs in question need to be listed in the console window so that the
+ user can make an informed choice.
+ */
+ g_warning ("Obsolete preference \"%s\" at line %d of\n%s %s",
+ cur_var->str, pline, pf_path, hint);
+ prefs.unknown_prefs = TRUE;
+ break;
+ }
+ } else {
+ g_warning ("Incomplete preference at line %d: of\n%s %s", pline, pf_path, hint);
+ }
}
- }
- /* Call the routine to set the preference; it will parse
- the value as appropriate.
-
- Since we're reading a file, rather than processing
- explicit user input, for range preferences, silently
- lower values in excess of the range's maximum, rather
- than reporting errors and failing. */
- switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, FALSE)) {
-
- case PREFS_SET_OK:
+ state = IN_VAR;
+ got_val = FALSE;
+ g_string_truncate(cur_var, 0);
+ g_string_append_c(cur_var, (gchar) got_c);
+ pline = fline;
+ } else if (isspace(got_c) && cur_var->len > 0 && got_val) {
+ state = PRE_VAL;
+ } else if (got_c == '#') {
+ state = IN_SKIP;
+ } else {
+ g_warning ("Malformed preference at line %d of\n%s %s", fline, pf_path, hint);
+ }
+ break;
+ case IN_VAR:
+ if (got_c != ':') {
+ g_string_append_c(cur_var, (gchar) got_c);
+ } else {
+ /* This is a colon (':') */
+ state = PRE_VAL;
+ g_string_truncate(cur_val, 0);
+ /*
+ * Set got_val to TRUE to accommodate prefs such as
+ * "gui.fileopen.dir" that do not require a value.
+ */
+ got_val = TRUE;
+ }
+ break;
+ case PRE_VAL:
+ if (!isspace(got_c)) {
+ state = IN_VAL;
+ g_string_append_c(cur_val, (gchar) got_c);
+ }
+ break;
+ case IN_VAL:
+ g_string_append_c(cur_val, (gchar) got_c);
+ break;
+ case IN_SKIP:
+ break;
+ }
+ }
+ if (cur_var->len > 0) {
+ if (got_val) {
+ /* Call the routine to set the preference; it will parse
+ the value as appropriate.
+
+ Since we're reading a file, rather than processing
+ explicit user input, for range preferences, silently
+ lower values in excess of the range's maximum, rather
+ than reporting errors and failing. */
+ switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, FALSE)) {
+
+ case PREFS_SET_OK:
break;
- case PREFS_SET_SYNTAX_ERR:
- g_warning ("Syntax error in preference \"%s\" at line %d of\n%s %s",
- cur_var->str, pline, pf_path, hint);
+ case PREFS_SET_SYNTAX_ERR:
+ g_warning ("Syntax error in preference %s at line %d of\n%s %s",
+ cur_var->str, pline, pf_path, hint);
break;
- case PREFS_SET_NO_SUCH_PREF:
- /*
- * If "print.command" silently ignore it because it's valid
- * on non-Win32 platforms.
- */
- if (strcmp(cur_var->str, "print.command") != 0)
- g_warning ("No such preference \"%s\" at line %d of\n%s %s",
- cur_var->str, pline, pf_path, hint);
+ case PREFS_SET_NO_SUCH_PREF:
+ g_warning ("No such preference \"%s\" at line %d of\n%s %s",
+ cur_var->str, pline, pf_path, hint);
prefs.unknown_prefs = TRUE;
break;
- case PREFS_SET_OBSOLETE:
- if (strcmp(cur_var->str, "print.command") != 0)
- /* If an attempt is made to save the preferences, a popup warning will be
- displayed stating that obsolete prefs have been detected and the user will
- be given the opportunity to save these prefs under a different profile name.
- The prefs in question need to be listed in the console window so that the
- user can make an informed choice.
- */
- g_warning ("Obsolete preference \"%s\" at line %d of\n%s %s",
- cur_var->str, pline, pf_path, hint);
+ case PREFS_SET_OBSOLETE:
prefs.unknown_prefs = TRUE;
break;
- }
- } else {
- g_warning ("Incomplete preference at line %d: of\n%s %s", pline, pf_path, hint);
}
- }
- state = IN_VAR;
- got_val = FALSE;
- g_string_truncate(cur_var, 0);
- g_string_append_c(cur_var, (gchar) got_c);
- pline = fline;
- } else if (isspace(got_c) && cur_var->len > 0 && got_val) {
- state = PRE_VAL;
- } else if (got_c == '#') {
- state = IN_SKIP;
- } else {
- g_warning ("Malformed preference at line %d of\n%s %s", fline, pf_path, hint);
- }
- break;
- case IN_VAR:
- if (got_c != ':') {
- g_string_append_c(cur_var, (gchar) got_c);
} else {
- /* This is a colon (':') */
- state = PRE_VAL;
- g_string_truncate(cur_val, 0);
- /*
- * Set got_val to TRUE to accommodate prefs such as
- * "gui.fileopen.dir" that do not require a value.
- */
- got_val = TRUE;
- }
- break;
- case PRE_VAL:
- if (!isspace(got_c)) {
- state = IN_VAL;
- g_string_append_c(cur_val, (gchar) got_c);
+ g_warning ("Incomplete preference at line %d of\n%s %s",
+ pline, pf_path, hint);
}
- break;
- case IN_VAL:
- g_string_append_c(cur_val, (gchar) got_c);
- break;
- case IN_SKIP:
- break;
}
- }
- if (cur_var->len > 0) {
- if (got_val) {
- /* Call the routine to set the preference; it will parse
- the value as appropriate.
-
- Since we're reading a file, rather than processing
- explicit user input, for range preferences, silently
- lower values in excess of the range's maximum, rather
- than reporting errors and failing. */
- switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, FALSE)) {
-
- case PREFS_SET_OK:
- break;
- case PREFS_SET_SYNTAX_ERR:
- g_warning ("Syntax error in preference %s at line %d of\n%s %s",
- cur_var->str, pline, pf_path, hint);
- break;
+ g_string_free(cur_val, TRUE);
+ g_string_free(cur_var, TRUE);
- case PREFS_SET_NO_SUCH_PREF:
- g_warning ("No such preference \"%s\" at line %d of\n%s %s",
- cur_var->str, pline, pf_path, hint);
- prefs.unknown_prefs = TRUE;
- break;
-
- case PREFS_SET_OBSOLETE:
- prefs.unknown_prefs = TRUE;
- break;
- }
- } else {
- g_warning ("Incomplete preference at line %d of\n%s %s",
- pline, pf_path, hint);
- }
- }
-
- g_string_free(cur_val, TRUE);
- g_string_free(cur_var, TRUE);
-
- if (ferror(pf))
- return errno;
- else
- return 0;
+ if (ferror(pf))
+ return errno;
+ else
+ return 0;
}
/*
@@ -3728,34 +3728,34 @@ prefs_capture_options_dialog_column_is_visible(const gchar *column)
char
string_to_name_resolve(const char *string, e_addr_resolve *name_resolve)
{
- char c;
+ char c;
- memset(name_resolve, 0, sizeof(e_addr_resolve));
- while ((c = *string++) != '\0') {
- switch (c) {
- case 'm':
- name_resolve->mac_name = TRUE;
- break;
- case 'n':
- name_resolve->network_name = TRUE;
- break;
- case 'N':
- name_resolve->use_external_net_name_resolver = TRUE;
- break;
- case 't':
- name_resolve->transport_name = TRUE;
- break;
- case 'C':
- name_resolve->concurrent_dns = TRUE;
- break;
- default:
- /*
- * Unrecognized letter.
- */
- return c;
- }
- }
- return '\0';
+ memset(name_resolve, 0, sizeof(e_addr_resolve));
+ while ((c = *string++) != '\0') {
+ switch (c) {
+ case 'm':
+ name_resolve->mac_name = TRUE;
+ break;
+ case 'n':
+ name_resolve->network_name = TRUE;
+ break;
+ case 'N':
+ name_resolve->use_external_net_name_resolver = TRUE;
+ break;
+ case 't':
+ name_resolve->transport_name = TRUE;
+ break;
+ case 'C':
+ name_resolve->concurrent_dns = TRUE;
+ break;
+ default:
+ /*
+ * Unrecognized letter.
+ */
+ return c;
+ }
+ }
+ return '\0';
}
@@ -3806,509 +3806,509 @@ static prefs_set_pref_e
set_pref(gchar *pref_name, const gchar *value, void *private_data _U_,
gboolean return_range_errors)
{
- unsigned long int cval;
- guint uval;
- gboolean bval;
- gint enum_val;
- char *p;
- gchar *dotp, *last_dotp;
- static gchar *filter_label = NULL;
- static gboolean filter_enabled = FALSE;
- gchar *filter_expr = NULL;
- module_t *module;
- pref_t *pref;
-
- if (strcmp(pref_name, PRS_GUI_FILTER_LABEL) == 0) {
- filter_label = g_strdup(value);
- } else if (strcmp(pref_name, PRS_GUI_FILTER_ENABLED) == 0) {
- filter_enabled = (strcmp(value, "TRUE") == 0) ? TRUE : FALSE;
- } else if (strcmp(pref_name, PRS_GUI_FILTER_EXPR) == 0) {
- filter_expr = g_strdup(value);
- filter_expression_new(filter_label, filter_expr, filter_enabled);
- g_free(filter_label);
- g_free(filter_expr);
- } else if (strcmp(pref_name, "gui.version_in_start_page") == 0) {
- /* Convert deprecated value to closest current equivalent */
- if (g_ascii_strcasecmp(value, "true") == 0) {
- prefs.gui_version_placement = version_both;
- } else {
- prefs.gui_version_placement = version_neither;
- }
- } else if (strcmp(pref_name, "name_resolve") == 0 ||
- strcmp(pref_name, "capture.name_resolve") == 0) {
- /*
- * Handle the deprecated name resolution options.
- *
- * "TRUE" and "FALSE", for backwards compatibility, are synonyms for
- * RESOLV_ALL and RESOLV_NONE.
- *
- * Otherwise, we treat it as a list of name types we want to resolve.
- */
- if (g_ascii_strcasecmp(value, "true") == 0) {
- gbl_resolv_flags.mac_name = TRUE;
- gbl_resolv_flags.network_name = TRUE;
- gbl_resolv_flags.transport_name = TRUE;
- gbl_resolv_flags.concurrent_dns = TRUE;
- }
- else if (g_ascii_strcasecmp(value, "false") == 0) {
- gbl_resolv_flags.mac_name = FALSE;
- gbl_resolv_flags.network_name = FALSE;
- gbl_resolv_flags.transport_name = FALSE;
- gbl_resolv_flags.concurrent_dns = FALSE;
- }
- else {
- /* start out with none set */
- gbl_resolv_flags.mac_name = FALSE;
- gbl_resolv_flags.network_name = FALSE;
- gbl_resolv_flags.transport_name = FALSE;
- gbl_resolv_flags.concurrent_dns = FALSE;
- if (string_to_name_resolve(value, &gbl_resolv_flags) != '\0')
- return PREFS_SET_SYNTAX_ERR;
- }
- } else {
- /* Handle deprecated "global" options that don't have a module
- * associated with them
- */
- if ((strcmp(pref_name, "name_resolve_concurrency") == 0) ||
- (strcmp(pref_name, "name_resolve_load_smi_modules") == 0) ||
- (strcmp(pref_name, "name_resolve_suppress_smi_errors") == 0)) {
- module = nameres_module;
- dotp = pref_name;
- } else {
- /* To which module does this preference belong? */
- module = NULL;
- last_dotp = pref_name;
- while (!module) {
- dotp = strchr(last_dotp, '.');
- if (dotp == NULL) {
- /* Either there's no such module, or no module was specified.
- In either case, that means there's no such preference. */
- return PREFS_SET_NO_SUCH_PREF;
+ unsigned long int cval;
+ guint uval;
+ gboolean bval;
+ gint enum_val;
+ char *p;
+ gchar *dotp, *last_dotp;
+ static gchar *filter_label = NULL;
+ static gboolean filter_enabled = FALSE;
+ gchar *filter_expr = NULL;
+ module_t *module;
+ pref_t *pref;
+
+ if (strcmp(pref_name, PRS_GUI_FILTER_LABEL) == 0) {
+ filter_label = g_strdup(value);
+ } else if (strcmp(pref_name, PRS_GUI_FILTER_ENABLED) == 0) {
+ filter_enabled = (strcmp(value, "TRUE") == 0) ? TRUE : FALSE;
+ } else if (strcmp(pref_name, PRS_GUI_FILTER_EXPR) == 0) {
+ filter_expr = g_strdup(value);
+ filter_expression_new(filter_label, filter_expr, filter_enabled);
+ g_free(filter_label);
+ g_free(filter_expr);
+ } else if (strcmp(pref_name, "gui.version_in_start_page") == 0) {
+ /* Convert deprecated value to closest current equivalent */
+ if (g_ascii_strcasecmp(value, "true") == 0) {
+ prefs.gui_version_placement = version_both;
+ } else {
+ prefs.gui_version_placement = version_neither;
}
- *dotp = '\0'; /* separate module and preference name */
- module = prefs_find_module(pref_name);
-
+ } else if (strcmp(pref_name, "name_resolve") == 0 ||
+ strcmp(pref_name, "capture.name_resolve") == 0) {
/*
- * XXX - "Diameter" rather than "diameter" was used in earlier
- * versions of Wireshark; if we didn't find the module, and its name
- * was "Diameter", look for "diameter" instead.
- *
- * In addition, the BEEP protocol used to be the BXXP protocol,
- * so if we didn't find the module, and its name was "bxxp",
- * look for "beep" instead.
- *
- * Also, the preferences for GTP v0 and v1 were combined under
- * a single "gtp" heading, and the preferences for SMPP were
- * moved to "smpp-gsm-sms" and then moved to "gsm-sms-ud".
- * However, SMPP now has its own preferences, so we just map
- * "smpp-gsm-sms" to "gsm-sms-ud", and then handle SMPP below.
+ * Handle the deprecated name resolution options.
*
- * We also renamed "dcp" to "dccp", "x.25" to "x25", "x411" to "p1"
- * and "nsip" to "gprs_ns".
- *
- * The SynOptics Network Management Protocol (SONMP) is now known by
- * its modern name, the Nortel Discovery Protocol (NDP).
- */
- if (module == NULL) {
- if (strcmp(pref_name, "column") == 0)
- module = gui_column_module;
- else if (strcmp(pref_name, "Diameter") == 0)
- module = prefs_find_module("diameter");
- else if (strcmp(pref_name, "bxxp") == 0)
- module = prefs_find_module("beep");
- else if (strcmp(pref_name, "gtpv0") == 0 ||
- strcmp(pref_name, "gtpv1") == 0)
- module = prefs_find_module("gtp");
- else if (strcmp(pref_name, "smpp-gsm-sms") == 0)
- module = prefs_find_module("gsm-sms-ud");
- else if (strcmp(pref_name, "dcp") == 0)
- module = prefs_find_module("dccp");
- else if (strcmp(pref_name, "x.25") == 0)
- module = prefs_find_module("x25");
- else if (strcmp(pref_name, "x411") == 0)
- module = prefs_find_module("p1");
- else if (strcmp(pref_name, "nsip") == 0)
- module = prefs_find_module("gprs-ns");
- else if (strcmp(pref_name, "sonmp") == 0)
- module = prefs_find_module("ndp");
- else if (strcmp(pref_name, "etheric") == 0 ||
- strcmp(pref_name, "isup_thin") == 0) {
- /* This protocol was removed 7. July 2009 */
- return PREFS_SET_OBSOLETE;
- }
- if (module) {
- g_warning ("Preference \"%s.%s\" has been converted to \"%s.%s.%s\"\n"
- "Save your preferences to make this change permanent.",
- pref_name, dotp+1, module->parent->name, pref_name, dotp+1);
- prefs.unknown_prefs = TRUE;
- }
- }
- *dotp = '.'; /* put the preference string back */
- dotp++; /* skip past separator to preference name */
- last_dotp = dotp;
- }
- }
-
- pref = prefs_find_preference(module, dotp);
-
- if (pref == NULL) {
- prefs.unknown_prefs = TRUE;
-
- /* "gui" prefix was added to column preferences for better organization
- * within the preferences file
- */
- if ((strcmp(pref_name, PRS_COL_HIDDEN) == 0) ||
- (strcmp(pref_name, PRS_COL_FMT) == 0)) {
- pref = prefs_find_preference(module, pref_name);
- }
- else if (strcmp(module->name, "mgcp") == 0) {
- /*
- * XXX - "mgcp.display raw text toggle" and "mgcp.display dissect tree"
- * rather than "mgcp.display_raw_text" and "mgcp.display_dissect_tree"
- * were used in earlier versions of Wireshark; if we didn't find the
- * preference, it was an MGCP preference, and its name was
- * "display raw text toggle" or "display dissect tree", look for
- * "display_raw_text" or "display_dissect_tree" instead.
+ * "TRUE" and "FALSE", for backwards compatibility, are synonyms for
+ * RESOLV_ALL and RESOLV_NONE.
*
- * "mgcp.tcp.port" and "mgcp.udp.port" are harder to handle, as both
- * the gateway and callagent ports were given those names; we interpret
- * the first as "mgcp.{tcp,udp}.gateway_port" and the second as
- * "mgcp.{tcp,udp}.callagent_port", as that's the order in which
- * they were registered by the MCCP dissector and thus that's the
- * order in which they were written to the preferences file. (If
- * we're not reading the preferences file, but are handling stuff
- * from a "-o" command-line option, we have no clue which the user
- * had in mind - they should have used "mgcp.{tcp,udp}.gateway_port"
- * or "mgcp.{tcp,udp}.callagent_port" instead.)
+ * Otherwise, we treat it as a list of name types we want to resolve.
*/
- if (strcmp(dotp, "display raw text toggle") == 0)
- pref = prefs_find_preference(module, "display_raw_text");
- else if (strcmp(dotp, "display dissect tree") == 0)
- pref = prefs_find_preference(module, "display_dissect_tree");
- else if (strcmp(dotp, "tcp.port") == 0) {
- mgcp_tcp_port_count++;
- if (mgcp_tcp_port_count == 1) {
- /* It's the first one */
- pref = prefs_find_preference(module, "tcp.gateway_port");
- } else if (mgcp_tcp_port_count == 2) {
- /* It's the second one */
- pref = prefs_find_preference(module, "tcp.callagent_port");
- }
- /* Otherwise it's from the command line, and we don't bother
- mapping it. */
- } else if (strcmp(dotp, "udp.port") == 0) {
- mgcp_udp_port_count++;
- if (mgcp_udp_port_count == 1) {
- /* It's the first one */
- pref = prefs_find_preference(module, "udp.gateway_port");
- } else if (mgcp_udp_port_count == 2) {
- /* It's the second one */
- pref = prefs_find_preference(module, "udp.callagent_port");
- }
- /* Otherwise it's from the command line, and we don't bother
- mapping it. */
+ if (g_ascii_strcasecmp(value, "true") == 0) {
+ gbl_resolv_flags.mac_name = TRUE;
+ gbl_resolv_flags.network_name = TRUE;
+ gbl_resolv_flags.transport_name = TRUE;
+ gbl_resolv_flags.concurrent_dns = TRUE;
}
- } else if (strcmp(module->name, "smb") == 0) {
- /* Handle old names for SMB preferences. */
- if (strcmp(dotp, "smb.trans.reassembly") == 0)
- pref = prefs_find_preference(module, "trans_reassembly");
- else if (strcmp(dotp, "smb.dcerpc.reassembly") == 0)
- pref = prefs_find_preference(module, "dcerpc_reassembly");
- } else if (strcmp(module->name, "ndmp") == 0) {
- /* Handle old names for NDMP preferences. */
- if (strcmp(dotp, "ndmp.desegment") == 0)
- pref = prefs_find_preference(module, "desegment");
- } else if (strcmp(module->name, "diameter") == 0) {
- /* Handle old names for Diameter preferences. */
- if (strcmp(dotp, "diameter.desegment") == 0)
- pref = prefs_find_preference(module, "desegment");
- } else if (strcmp(module->name, "pcli") == 0) {
- /* Handle old names for PCLI preferences. */
- if (strcmp(dotp, "pcli.udp_port") == 0)
- pref = prefs_find_preference(module, "udp_port");
- } else if (strcmp(module->name, "artnet") == 0) {
- /* Handle old names for ARTNET preferences. */
- if (strcmp(dotp, "artnet.udp_port") == 0)
- pref = prefs_find_preference(module, "udp_port");
- } else if (strcmp(module->name, "mapi") == 0) {
- /* Handle old names for MAPI preferences. */
- if (strcmp(dotp, "mapi_decrypt") == 0)
- pref = prefs_find_preference(module, "decrypt");
- } else if (strcmp(module->name, "fc") == 0) {
- /* Handle old names for Fibre Channel preferences. */
- if (strcmp(dotp, "reassemble_fc") == 0)
- pref = prefs_find_preference(module, "reassemble");
- else if (strcmp(dotp, "fc_max_frame_size") == 0)
- pref = prefs_find_preference(module, "max_frame_size");
- } else if (strcmp(module->name, "fcip") == 0) {
- /* Handle old names for Fibre Channel-over-IP preferences. */
- if (strcmp(dotp, "desegment_fcip_messages") == 0)
- pref = prefs_find_preference(module, "desegment");
- else if (strcmp(dotp, "fcip_port") == 0)
- pref = prefs_find_preference(module, "target_port");
- } else if (strcmp(module->name, "gtp") == 0) {
- /* Handle old names for GTP preferences. */
- if (strcmp(dotp, "gtpv0_port") == 0)
- pref = prefs_find_preference(module, "v0_port");
- else if (strcmp(dotp, "gtpv1c_port") == 0)
- pref = prefs_find_preference(module, "v1c_port");
- else if (strcmp(dotp, "gtpv1u_port") == 0)
- pref = prefs_find_preference(module, "v1u_port");
- else if (strcmp(dotp, "gtp_dissect_tpdu") == 0)
- pref = prefs_find_preference(module, "dissect_tpdu");
- else if (strcmp(dotp, "gtpv0_dissect_cdr_as") == 0)
- pref = prefs_find_preference(module, "v0_dissect_cdr_as");
- else if (strcmp(dotp, "gtpv0_check_etsi") == 0)
- pref = prefs_find_preference(module, "v0_check_etsi");
- else if (strcmp(dotp, "gtpv1_check_etsi") == 0)
- pref = prefs_find_preference(module, "v1_check_etsi");
- } else if (strcmp(module->name, "ip") == 0) {
- /* Handle old names for IP preferences. */
- if (strcmp(dotp, "ip_summary_in_tree") == 0)
- pref = prefs_find_preference(module, "summary_in_tree");
- } else if (strcmp(module->name, "iscsi") == 0) {
- /* Handle old names for iSCSI preferences. */
- if (strcmp(dotp, "iscsi_port") == 0)
- pref = prefs_find_preference(module, "target_port");
- } else if (strcmp(module->name, "lmp") == 0) {
- /* Handle old names for LMP preferences. */
- if (strcmp(dotp, "lmp_version") == 0)
- pref = prefs_find_preference(module, "version");
- } else if (strcmp(module->name, "mtp3") == 0) {
- /* Handle old names for MTP3 preferences. */
- if (strcmp(dotp, "mtp3_standard") == 0)
- pref = prefs_find_preference(module, "standard");
- else if (strcmp(dotp, "net_addr_format") == 0)
- pref = prefs_find_preference(module, "addr_format");
- } else if (strcmp(module->name, "nlm") == 0) {
- /* Handle old names for NLM preferences. */
- if (strcmp(dotp, "nlm_msg_res_matching") == 0)
- pref = prefs_find_preference(module, "msg_res_matching");
- } else if (strcmp(module->name, "ppp") == 0) {
- /* Handle old names for PPP preferences. */
- if (strcmp(dotp, "ppp_fcs") == 0)
- pref = prefs_find_preference(module, "fcs_type");
- else if (strcmp(dotp, "ppp_vj") == 0)
- pref = prefs_find_preference(module, "decompress_vj");
- } else if (strcmp(module->name, "rsvp") == 0) {
- /* Handle old names for RSVP preferences. */
- if (strcmp(dotp, "rsvp_process_bundle") == 0)
- pref = prefs_find_preference(module, "process_bundle");
- } else if (strcmp(module->name, "tcp") == 0) {
- /* Handle old names for TCP preferences. */
- if (strcmp(dotp, "tcp_summary_in_tree") == 0)
- pref = prefs_find_preference(module, "summary_in_tree");
- else if (strcmp(dotp, "tcp_analyze_sequence_numbers") == 0)
- pref = prefs_find_preference(module, "analyze_sequence_numbers");
- else if (strcmp(dotp, "tcp_relative_sequence_numbers") == 0)
- pref = prefs_find_preference(module, "relative_sequence_numbers");
- } else if (strcmp(module->name, "udp") == 0) {
- /* Handle old names for UDP preferences. */
- if (strcmp(dotp, "udp_summary_in_tree") == 0)
- pref = prefs_find_preference(module, "summary_in_tree");
- } else if (strcmp(module->name, "ndps") == 0) {
- /* Handle old names for NDPS preferences. */
- if (strcmp(dotp, "desegment_ndps") == 0)
- pref = prefs_find_preference(module, "desegment_tcp");
- } else if (strcmp(module->name, "http") == 0) {
- /* Handle old names for HTTP preferences. */
- if (strcmp(dotp, "desegment_http_headers") == 0)
- pref = prefs_find_preference(module, "desegment_headers");
- else if (strcmp(dotp, "desegment_http_body") == 0)
- pref = prefs_find_preference(module, "desegment_body");
- } else if (strcmp(module->name, "smpp") == 0) {
- /* Handle preferences that moved from SMPP. */
- module_t *new_module = prefs_find_module("gsm-sms-ud");
- if (new_module){
- if (strcmp(dotp, "port_number_udh_means_wsp") == 0)
- pref = prefs_find_preference(new_module, "port_number_udh_means_wsp");
- else if (strcmp(dotp, "try_dissect_1st_fragment") == 0)
- pref = prefs_find_preference(new_module, "try_dissect_1st_fragment");
+ else if (g_ascii_strcasecmp(value, "false") == 0) {
+ gbl_resolv_flags.mac_name = FALSE;
+ gbl_resolv_flags.network_name = FALSE;
+ gbl_resolv_flags.transport_name = FALSE;
+ gbl_resolv_flags.concurrent_dns = FALSE;
}
- } else if (strcmp(module->name, "asn1") == 0) {
- /* Handle old generic ASN.1 preferences (it's not really a
- rename, as the new preferences support multiple ports,
- but we might as well copy them over). */
- if (strcmp(dotp, "tcp_port") == 0)
- pref = prefs_find_preference(module, "tcp_ports");
- else if (strcmp(dotp, "udp_port") == 0)
- pref = prefs_find_preference(module, "udp_ports");
- else if (strcmp(dotp, "sctp_port") == 0)
- pref = prefs_find_preference(module, "sctp_ports");
- } else if (strcmp(module->name, "llcgprs") == 0) {
- if (strcmp(dotp, "ignore_cipher_bit") == 0)
- pref = prefs_find_preference(module, "autodetect_cipher_bit");
- } else if (strcmp(module->name, "erf") == 0) {
- if (strcmp(dotp, "erfeth") == 0) {
- /* Handle the old "erfeth" preference; map it to the new
- "ethfcs" preference, and map the values to those for
- the new preference. */
- pref = prefs_find_preference(module, "ethfcs");
- if (strcmp(value, "ethfcs") == 0 || strcmp(value, "Ethernet with FCS") == 0)
- value = "TRUE";
- else if (strcmp(value, "eth") == 0 || strcmp(value, "Ethernet") == 0)
- value = "FALSE";
- else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
- value = "TRUE";
- } else if (strcmp(dotp, "erfatm") == 0) {
- /* Handle the old "erfatm" preference; map it to the new
- "aal5_type" preference, and map the values to those for
- the new preference. */
- pref = prefs_find_preference(module, "aal5_type");
- if (strcmp(value, "atm") == 0 || strcmp(value, "ATM") == 0)
- value = "guess";
- else if (strcmp(value, "llc") == 0 || strcmp(value, "LLC") == 0)
- value = "llc";
- else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
- value = "guess";
- } else if (strcmp(dotp, "erfhdlc") == 0) {
- /* Handle the old "erfhdlc" preference; map it to the new
- "hdlc_type" preference, and map the values to those for
- the new preference. */
- pref = prefs_find_preference(module, "hdlc_type");
- if (strcmp(value, "chdlc") == 0 || strcmp(value, "Cisco HDLC") == 0)
- value = "chdlc";
- else if (strcmp(value, "ppp") == 0 || strcmp(value, "PPP serial") == 0)
- value = "ppp";
- else if (strcmp(value, "fr") == 0 || strcmp(value, "Frame Relay") == 0)
- value = "frelay";
- else if (strcmp(value, "mtp2") == 0 || strcmp(value, "SS7 MTP2") == 0)
- value = "mtp2";
- else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
- value = "guess";
+ else {
+ /* start out with none set */
+ gbl_resolv_flags.mac_name = FALSE;
+ gbl_resolv_flags.network_name = FALSE;
+ gbl_resolv_flags.transport_name = FALSE;
+ gbl_resolv_flags.concurrent_dns = FALSE;
+ if (string_to_name_resolve(value, &gbl_resolv_flags) != '\0')
+ return PREFS_SET_SYNTAX_ERR;
}
- } else if (strcmp(module->name, "eth") == 0) {
- /* "eth.qinq_ethertype" has been changed(restored) to "vlan.qinq.ethertype" */
- if (strcmp(dotp, "qinq_ethertype") == 0) {
- module_t *new_module = prefs_find_module("vlan");
- if (new_module) {
- pref = prefs_find_preference(new_module, "qinq_ethertype");
- module = new_module;
- }
+ } else {
+ /* Handle deprecated "global" options that don't have a module
+ * associated with them
+ */
+ if ((strcmp(pref_name, "name_resolve_concurrency") == 0) ||
+ (strcmp(pref_name, "name_resolve_load_smi_modules") == 0) ||
+ (strcmp(pref_name, "name_resolve_suppress_smi_errors") == 0)) {
+ module = nameres_module;
+ dotp = pref_name;
+ } else {
+ /* To which module does this preference belong? */
+ module = NULL;
+ last_dotp = pref_name;
+ while (!module) {
+ dotp = strchr(last_dotp, '.');
+ if (dotp == NULL) {
+ /* Either there's no such module, or no module was specified.
+ In either case, that means there's no such preference. */
+ return PREFS_SET_NO_SUCH_PREF;
+ }
+ *dotp = '\0'; /* separate module and preference name */
+ module = prefs_find_module(pref_name);
+
+ /*
+ * XXX - "Diameter" rather than "diameter" was used in earlier
+ * versions of Wireshark; if we didn't find the module, and its name
+ * was "Diameter", look for "diameter" instead.
+ *
+ * In addition, the BEEP protocol used to be the BXXP protocol,
+ * so if we didn't find the module, and its name was "bxxp",
+ * look for "beep" instead.
+ *
+ * Also, the preferences for GTP v0 and v1 were combined under
+ * a single "gtp" heading, and the preferences for SMPP were
+ * moved to "smpp-gsm-sms" and then moved to "gsm-sms-ud".
+ * However, SMPP now has its own preferences, so we just map
+ * "smpp-gsm-sms" to "gsm-sms-ud", and then handle SMPP below.
+ *
+ * We also renamed "dcp" to "dccp", "x.25" to "x25", "x411" to "p1"
+ * and "nsip" to "gprs_ns".
+ *
+ * The SynOptics Network Management Protocol (SONMP) is now known by
+ * its modern name, the Nortel Discovery Protocol (NDP).
+ */
+ if (module == NULL) {
+ if (strcmp(pref_name, "column") == 0)
+ module = gui_column_module;
+ else if (strcmp(pref_name, "Diameter") == 0)
+ module = prefs_find_module("diameter");
+ else if (strcmp(pref_name, "bxxp") == 0)
+ module = prefs_find_module("beep");
+ else if (strcmp(pref_name, "gtpv0") == 0 ||
+ strcmp(pref_name, "gtpv1") == 0)
+ module = prefs_find_module("gtp");
+ else if (strcmp(pref_name, "smpp-gsm-sms") == 0)
+ module = prefs_find_module("gsm-sms-ud");
+ else if (strcmp(pref_name, "dcp") == 0)
+ module = prefs_find_module("dccp");
+ else if (strcmp(pref_name, "x.25") == 0)
+ module = prefs_find_module("x25");
+ else if (strcmp(pref_name, "x411") == 0)
+ module = prefs_find_module("p1");
+ else if (strcmp(pref_name, "nsip") == 0)
+ module = prefs_find_module("gprs-ns");
+ else if (strcmp(pref_name, "sonmp") == 0)
+ module = prefs_find_module("ndp");
+ else if (strcmp(pref_name, "etheric") == 0 ||
+ strcmp(pref_name, "isup_thin") == 0) {
+ /* This protocol was removed 7. July 2009 */
+ return PREFS_SET_OBSOLETE;
+ }
+ if (module) {
+ g_warning ("Preference \"%s.%s\" has been converted to \"%s.%s.%s\"\n"
+ "Save your preferences to make this change permanent.",
+ pref_name, dotp+1, module->parent->name, pref_name, dotp+1);
+ prefs.unknown_prefs = TRUE;
+ }
+ }
+ *dotp = '.'; /* put the preference string back */
+ dotp++; /* skip past separator to preference name */
+ last_dotp = dotp;
+ }
}
- } else if (strcmp(module->name, "taps") == 0) {
- /* taps preferences moved to "statistics" module */
- if (strcmp(dotp, "update_interval") == 0 ||
- strcmp(dotp, "rtp_player_max_visible") == 0)
- pref = prefs_find_preference(stats_module, dotp);
- } else if (strcmp(module->name, "packet_list") == 0) {
- /* packet_list preferences moved to protocol module */
- if (strcmp(dotp, "display_hidden_proto_items") == 0)
- pref = prefs_find_preference(protocols_module, dotp);
- } else if (strcmp(module->name, "stream") == 0) {
- /* stream preferences moved to gui color module */
- if ((strcmp(dotp, "client.fg") == 0) ||
- (strcmp(dotp, "client.bg") == 0) ||
- (strcmp(dotp, "server.fg") == 0) ||
- (strcmp(dotp, "server.bg") == 0))
- pref = prefs_find_preference(gui_color_module, pref_name);
- } else if (strcmp(module->name, "nameres") == 0) {
- if (strcmp(pref_name, "name_resolve_concurrency") == 0) {
- pref = prefs_find_preference(nameres_module, pref_name);
- } else if (strcmp(pref_name, "name_resolve_load_smi_modules") == 0) {
- pref = prefs_find_preference(nameres_module, "load_smi_modules");
- } else if (strcmp(pref_name, "name_resolve_suppress_smi_errors") == 0) {
- pref = prefs_find_preference(nameres_module, "suppress_smi_errors");
- }
- }
- }
- if (pref == NULL)
- return PREFS_SET_NO_SUCH_PREF; /* no such preference */
- switch (pref->type) {
+ pref = prefs_find_preference(module, dotp);
- case PREF_UINT:
- /* XXX - give an error if it doesn't fit in a guint? */
- uval = (guint)strtoul(value, &p, pref->info.base);
- if (p == value || *p != '\0')
- return PREFS_SET_SYNTAX_ERR; /* number was bad */
- if (*pref->varp.uint != uval) {
- module->prefs_changed = TRUE;
- *pref->varp.uint = uval;
- }
- break;
+ if (pref == NULL) {
+ prefs.unknown_prefs = TRUE;
- case PREF_BOOL:
- /* XXX - give an error if it's neither "true" nor "false"? */
- if (g_ascii_strcasecmp(value, "true") == 0)
- bval = TRUE;
- else
- bval = FALSE;
- if (*pref->varp.boolp != bval) {
- module->prefs_changed = TRUE;
- *pref->varp.boolp = bval;
- }
- break;
+ /* "gui" prefix was added to column preferences for better organization
+ * within the preferences file
+ */
+ if ((strcmp(pref_name, PRS_COL_HIDDEN) == 0) ||
+ (strcmp(pref_name, PRS_COL_FMT) == 0)) {
+ pref = prefs_find_preference(module, pref_name);
+ }
+ else if (strcmp(module->name, "mgcp") == 0) {
+ /*
+ * XXX - "mgcp.display raw text toggle" and "mgcp.display dissect tree"
+ * rather than "mgcp.display_raw_text" and "mgcp.display_dissect_tree"
+ * were used in earlier versions of Wireshark; if we didn't find the
+ * preference, it was an MGCP preference, and its name was
+ * "display raw text toggle" or "display dissect tree", look for
+ * "display_raw_text" or "display_dissect_tree" instead.
+ *
+ * "mgcp.tcp.port" and "mgcp.udp.port" are harder to handle, as both
+ * the gateway and callagent ports were given those names; we interpret
+ * the first as "mgcp.{tcp,udp}.gateway_port" and the second as
+ * "mgcp.{tcp,udp}.callagent_port", as that's the order in which
+ * they were registered by the MCCP dissector and thus that's the
+ * order in which they were written to the preferences file. (If
+ * we're not reading the preferences file, but are handling stuff
+ * from a "-o" command-line option, we have no clue which the user
+ * had in mind - they should have used "mgcp.{tcp,udp}.gateway_port"
+ * or "mgcp.{tcp,udp}.callagent_port" instead.)
+ */
+ if (strcmp(dotp, "display raw text toggle") == 0)
+ pref = prefs_find_preference(module, "display_raw_text");
+ else if (strcmp(dotp, "display dissect tree") == 0)
+ pref = prefs_find_preference(module, "display_dissect_tree");
+ else if (strcmp(dotp, "tcp.port") == 0) {
+ mgcp_tcp_port_count++;
+ if (mgcp_tcp_port_count == 1) {
+ /* It's the first one */
+ pref = prefs_find_preference(module, "tcp.gateway_port");
+ } else if (mgcp_tcp_port_count == 2) {
+ /* It's the second one */
+ pref = prefs_find_preference(module, "tcp.callagent_port");
+ }
+ /* Otherwise it's from the command line, and we don't bother
+ mapping it. */
+ } else if (strcmp(dotp, "udp.port") == 0) {
+ mgcp_udp_port_count++;
+ if (mgcp_udp_port_count == 1) {
+ /* It's the first one */
+ pref = prefs_find_preference(module, "udp.gateway_port");
+ } else if (mgcp_udp_port_count == 2) {
+ /* It's the second one */
+ pref = prefs_find_preference(module, "udp.callagent_port");
+ }
+ /* Otherwise it's from the command line, and we don't bother
+ mapping it. */
+ }
+ } else if (strcmp(module->name, "smb") == 0) {
+ /* Handle old names for SMB preferences. */
+ if (strcmp(dotp, "smb.trans.reassembly") == 0)
+ pref = prefs_find_preference(module, "trans_reassembly");
+ else if (strcmp(dotp, "smb.dcerpc.reassembly") == 0)
+ pref = prefs_find_preference(module, "dcerpc_reassembly");
+ } else if (strcmp(module->name, "ndmp") == 0) {
+ /* Handle old names for NDMP preferences. */
+ if (strcmp(dotp, "ndmp.desegment") == 0)
+ pref = prefs_find_preference(module, "desegment");
+ } else if (strcmp(module->name, "diameter") == 0) {
+ /* Handle old names for Diameter preferences. */
+ if (strcmp(dotp, "diameter.desegment") == 0)
+ pref = prefs_find_preference(module, "desegment");
+ } else if (strcmp(module->name, "pcli") == 0) {
+ /* Handle old names for PCLI preferences. */
+ if (strcmp(dotp, "pcli.udp_port") == 0)
+ pref = prefs_find_preference(module, "udp_port");
+ } else if (strcmp(module->name, "artnet") == 0) {
+ /* Handle old names for ARTNET preferences. */
+ if (strcmp(dotp, "artnet.udp_port") == 0)
+ pref = prefs_find_preference(module, "udp_port");
+ } else if (strcmp(module->name, "mapi") == 0) {
+ /* Handle old names for MAPI preferences. */
+ if (strcmp(dotp, "mapi_decrypt") == 0)
+ pref = prefs_find_preference(module, "decrypt");
+ } else if (strcmp(module->name, "fc") == 0) {
+ /* Handle old names for Fibre Channel preferences. */
+ if (strcmp(dotp, "reassemble_fc") == 0)
+ pref = prefs_find_preference(module, "reassemble");
+ else if (strcmp(dotp, "fc_max_frame_size") == 0)
+ pref = prefs_find_preference(module, "max_frame_size");
+ } else if (strcmp(module->name, "fcip") == 0) {
+ /* Handle old names for Fibre Channel-over-IP preferences. */
+ if (strcmp(dotp, "desegment_fcip_messages") == 0)
+ pref = prefs_find_preference(module, "desegment");
+ else if (strcmp(dotp, "fcip_port") == 0)
+ pref = prefs_find_preference(module, "target_port");
+ } else if (strcmp(module->name, "gtp") == 0) {
+ /* Handle old names for GTP preferences. */
+ if (strcmp(dotp, "gtpv0_port") == 0)
+ pref = prefs_find_preference(module, "v0_port");
+ else if (strcmp(dotp, "gtpv1c_port") == 0)
+ pref = prefs_find_preference(module, "v1c_port");
+ else if (strcmp(dotp, "gtpv1u_port") == 0)
+ pref = prefs_find_preference(module, "v1u_port");
+ else if (strcmp(dotp, "gtp_dissect_tpdu") == 0)
+ pref = prefs_find_preference(module, "dissect_tpdu");
+ else if (strcmp(dotp, "gtpv0_dissect_cdr_as") == 0)
+ pref = prefs_find_preference(module, "v0_dissect_cdr_as");
+ else if (strcmp(dotp, "gtpv0_check_etsi") == 0)
+ pref = prefs_find_preference(module, "v0_check_etsi");
+ else if (strcmp(dotp, "gtpv1_check_etsi") == 0)
+ pref = prefs_find_preference(module, "v1_check_etsi");
+ } else if (strcmp(module->name, "ip") == 0) {
+ /* Handle old names for IP preferences. */
+ if (strcmp(dotp, "ip_summary_in_tree") == 0)
+ pref = prefs_find_preference(module, "summary_in_tree");
+ } else if (strcmp(module->name, "iscsi") == 0) {
+ /* Handle old names for iSCSI preferences. */
+ if (strcmp(dotp, "iscsi_port") == 0)
+ pref = prefs_find_preference(module, "target_port");
+ } else if (strcmp(module->name, "lmp") == 0) {
+ /* Handle old names for LMP preferences. */
+ if (strcmp(dotp, "lmp_version") == 0)
+ pref = prefs_find_preference(module, "version");
+ } else if (strcmp(module->name, "mtp3") == 0) {
+ /* Handle old names for MTP3 preferences. */
+ if (strcmp(dotp, "mtp3_standard") == 0)
+ pref = prefs_find_preference(module, "standard");
+ else if (strcmp(dotp, "net_addr_format") == 0)
+ pref = prefs_find_preference(module, "addr_format");
+ } else if (strcmp(module->name, "nlm") == 0) {
+ /* Handle old names for NLM preferences. */
+ if (strcmp(dotp, "nlm_msg_res_matching") == 0)
+ pref = prefs_find_preference(module, "msg_res_matching");
+ } else if (strcmp(module->name, "ppp") == 0) {
+ /* Handle old names for PPP preferences. */
+ if (strcmp(dotp, "ppp_fcs") == 0)
+ pref = prefs_find_preference(module, "fcs_type");
+ else if (strcmp(dotp, "ppp_vj") == 0)
+ pref = prefs_find_preference(module, "decompress_vj");
+ } else if (strcmp(module->name, "rsvp") == 0) {
+ /* Handle old names for RSVP preferences. */
+ if (strcmp(dotp, "rsvp_process_bundle") == 0)
+ pref = prefs_find_preference(module, "process_bundle");
+ } else if (strcmp(module->name, "tcp") == 0) {
+ /* Handle old names for TCP preferences. */
+ if (strcmp(dotp, "tcp_summary_in_tree") == 0)
+ pref = prefs_find_preference(module, "summary_in_tree");
+ else if (strcmp(dotp, "tcp_analyze_sequence_numbers") == 0)
+ pref = prefs_find_preference(module, "analyze_sequence_numbers");
+ else if (strcmp(dotp, "tcp_relative_sequence_numbers") == 0)
+ pref = prefs_find_preference(module, "relative_sequence_numbers");
+ } else if (strcmp(module->name, "udp") == 0) {
+ /* Handle old names for UDP preferences. */
+ if (strcmp(dotp, "udp_summary_in_tree") == 0)
+ pref = prefs_find_preference(module, "summary_in_tree");
+ } else if (strcmp(module->name, "ndps") == 0) {
+ /* Handle old names for NDPS preferences. */
+ if (strcmp(dotp, "desegment_ndps") == 0)
+ pref = prefs_find_preference(module, "desegment_tcp");
+ } else if (strcmp(module->name, "http") == 0) {
+ /* Handle old names for HTTP preferences. */
+ if (strcmp(dotp, "desegment_http_headers") == 0)
+ pref = prefs_find_preference(module, "desegment_headers");
+ else if (strcmp(dotp, "desegment_http_body") == 0)
+ pref = prefs_find_preference(module, "desegment_body");
+ } else if (strcmp(module->name, "smpp") == 0) {
+ /* Handle preferences that moved from SMPP. */
+ module_t *new_module = prefs_find_module("gsm-sms-ud");
+ if (new_module){
+ if (strcmp(dotp, "port_number_udh_means_wsp") == 0)
+ pref = prefs_find_preference(new_module, "port_number_udh_means_wsp");
+ else if (strcmp(dotp, "try_dissect_1st_fragment") == 0)
+ pref = prefs_find_preference(new_module, "try_dissect_1st_fragment");
+ }
+ } else if (strcmp(module->name, "asn1") == 0) {
+ /* Handle old generic ASN.1 preferences (it's not really a
+ rename, as the new preferences support multiple ports,
+ but we might as well copy them over). */
+ if (strcmp(dotp, "tcp_port") == 0)
+ pref = prefs_find_preference(module, "tcp_ports");
+ else if (strcmp(dotp, "udp_port") == 0)
+ pref = prefs_find_preference(module, "udp_ports");
+ else if (strcmp(dotp, "sctp_port") == 0)
+ pref = prefs_find_preference(module, "sctp_ports");
+ } else if (strcmp(module->name, "llcgprs") == 0) {
+ if (strcmp(dotp, "ignore_cipher_bit") == 0)
+ pref = prefs_find_preference(module, "autodetect_cipher_bit");
+ } else if (strcmp(module->name, "erf") == 0) {
+ if (strcmp(dotp, "erfeth") == 0) {
+ /* Handle the old "erfeth" preference; map it to the new
+ "ethfcs" preference, and map the values to those for
+ the new preference. */
+ pref = prefs_find_preference(module, "ethfcs");
+ if (strcmp(value, "ethfcs") == 0 || strcmp(value, "Ethernet with FCS") == 0)
+ value = "TRUE";
+ else if (strcmp(value, "eth") == 0 || strcmp(value, "Ethernet") == 0)
+ value = "FALSE";
+ else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
+ value = "TRUE";
+ } else if (strcmp(dotp, "erfatm") == 0) {
+ /* Handle the old "erfatm" preference; map it to the new
+ "aal5_type" preference, and map the values to those for
+ the new preference. */
+ pref = prefs_find_preference(module, "aal5_type");
+ if (strcmp(value, "atm") == 0 || strcmp(value, "ATM") == 0)
+ value = "guess";
+ else if (strcmp(value, "llc") == 0 || strcmp(value, "LLC") == 0)
+ value = "llc";
+ else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
+ value = "guess";
+ } else if (strcmp(dotp, "erfhdlc") == 0) {
+ /* Handle the old "erfhdlc" preference; map it to the new
+ "hdlc_type" preference, and map the values to those for
+ the new preference. */
+ pref = prefs_find_preference(module, "hdlc_type");
+ if (strcmp(value, "chdlc") == 0 || strcmp(value, "Cisco HDLC") == 0)
+ value = "chdlc";
+ else if (strcmp(value, "ppp") == 0 || strcmp(value, "PPP serial") == 0)
+ value = "ppp";
+ else if (strcmp(value, "fr") == 0 || strcmp(value, "Frame Relay") == 0)
+ value = "frelay";
+ else if (strcmp(value, "mtp2") == 0 || strcmp(value, "SS7 MTP2") == 0)
+ value = "mtp2";
+ else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
+ value = "guess";
+ }
+ } else if (strcmp(module->name, "eth") == 0) {
+ /* "eth.qinq_ethertype" has been changed(restored) to "vlan.qinq.ethertype" */
+ if (strcmp(dotp, "qinq_ethertype") == 0) {
+ module_t *new_module = prefs_find_module("vlan");
+ if (new_module) {
+ pref = prefs_find_preference(new_module, "qinq_ethertype");
+ module = new_module;
+ }
+ }
+ } else if (strcmp(module->name, "taps") == 0) {
+ /* taps preferences moved to "statistics" module */
+ if (strcmp(dotp, "update_interval") == 0 ||
+ strcmp(dotp, "rtp_player_max_visible") == 0)
+ pref = prefs_find_preference(stats_module, dotp);
+ } else if (strcmp(module->name, "packet_list") == 0) {
+ /* packet_list preferences moved to protocol module */
+ if (strcmp(dotp, "display_hidden_proto_items") == 0)
+ pref = prefs_find_preference(protocols_module, dotp);
+ } else if (strcmp(module->name, "stream") == 0) {
+ /* stream preferences moved to gui color module */
+ if ((strcmp(dotp, "client.fg") == 0) ||
+ (strcmp(dotp, "client.bg") == 0) ||
+ (strcmp(dotp, "server.fg") == 0) ||
+ (strcmp(dotp, "server.bg") == 0))
+ pref = prefs_find_preference(gui_color_module, pref_name);
+ } else if (strcmp(module->name, "nameres") == 0) {
+ if (strcmp(pref_name, "name_resolve_concurrency") == 0) {
+ pref = prefs_find_preference(nameres_module, pref_name);
+ } else if (strcmp(pref_name, "name_resolve_load_smi_modules") == 0) {
+ pref = prefs_find_preference(nameres_module, "load_smi_modules");
+ } else if (strcmp(pref_name, "name_resolve_suppress_smi_errors") == 0) {
+ pref = prefs_find_preference(nameres_module, "suppress_smi_errors");
+ }
+ }
+ }
+ if (pref == NULL)
+ return PREFS_SET_NO_SUCH_PREF; /* no such preference */
+
+ switch (pref->type) {
+
+ case PREF_UINT:
+ /* XXX - give an error if it doesn't fit in a guint? */
+ uval = (guint)strtoul(value, &p, pref->info.base);
+ if (p == value || *p != '\0')
+ return PREFS_SET_SYNTAX_ERR; /* number was bad */
+ if (*pref->varp.uint != uval) {
+ module->prefs_changed = TRUE;
+ *pref->varp.uint = uval;
+ }
+ break;
- case PREF_ENUM:
- /* XXX - give an error if it doesn't match? */
- enum_val = find_val_for_string(value, pref->info.enum_info.enumvals,
- *pref->varp.enump);
- if (*pref->varp.enump != enum_val) {
- module->prefs_changed = TRUE;
- *pref->varp.enump = enum_val;
- }
- break;
+ case PREF_BOOL:
+ /* XXX - give an error if it's neither "true" nor "false"? */
+ if (g_ascii_strcasecmp(value, "true") == 0)
+ bval = TRUE;
+ else
+ bval = FALSE;
+ if (*pref->varp.boolp != bval) {
+ module->prefs_changed = TRUE;
+ *pref->varp.boolp = bval;
+ }
+ break;
- case PREF_STRING:
- case PREF_FILENAME:
- case PREF_DIRNAME:
- if (strcmp(*pref->varp.string, value) != 0) {
- module->prefs_changed = TRUE;
- g_free((void *)*pref->varp.string);
- *pref->varp.string = g_strdup(value);
- }
- break;
+ case PREF_ENUM:
+ /* XXX - give an error if it doesn't match? */
+ enum_val = find_val_for_string(value, pref->info.enum_info.enumvals,
+ *pref->varp.enump);
+ if (*pref->varp.enump != enum_val) {
+ module->prefs_changed = TRUE;
+ *pref->varp.enump = enum_val;
+ }
+ break;
- case PREF_RANGE:
- {
- range_t *newrange;
+ case PREF_STRING:
+ case PREF_FILENAME:
+ case PREF_DIRNAME:
+ if (strcmp(*pref->varp.string, value) != 0) {
+ module->prefs_changed = TRUE;
+ g_free((void *)*pref->varp.string);
+ *pref->varp.string = g_strdup(value);
+ }
+ break;
- if (range_convert_str_work(&newrange, value, pref->info.max_value,
- return_range_errors) != CVT_NO_ERROR) {
- return PREFS_SET_SYNTAX_ERR; /* number was bad */
- }
+ case PREF_RANGE:
+ {
+ range_t *newrange;
- if (!ranges_are_equal(*pref->varp.range, newrange)) {
- module->prefs_changed = TRUE;
- g_free(*pref->varp.range);
- *pref->varp.range = newrange;
- } else {
- g_free (newrange);
- }
- break;
- }
+ if (range_convert_str_work(&newrange, value, pref->info.max_value,
+ return_range_errors) != CVT_NO_ERROR) {
+ return PREFS_SET_SYNTAX_ERR; /* number was bad */
+ }
- case PREF_COLOR:
- {
- cval = strtoul(value, NULL, 16);
- pref->varp.colorp->pixel = 0;
- if ((pref->varp.colorp->red != RED_COMPONENT(cval)) ||
- (pref->varp.colorp->green != GREEN_COMPONENT(cval)) ||
- (pref->varp.colorp->blue != BLUE_COMPONENT(cval))) {
- module->prefs_changed = TRUE;
- pref->varp.colorp->red = RED_COMPONENT(cval);
- pref->varp.colorp->green = GREEN_COMPONENT(cval);
- pref->varp.colorp->blue = BLUE_COMPONENT(cval);
- }
- break;
- }
+ if (!ranges_are_equal(*pref->varp.range, newrange)) {
+ module->prefs_changed = TRUE;
+ g_free(*pref->varp.range);
+ *pref->varp.range = newrange;
+ } else {
+ g_free (newrange);
+ }
+ break;
+ }
- case PREF_CUSTOM:
- return pref->custom_cbs.set_cb(pref, value, &module->prefs_changed);
+ case PREF_COLOR:
+ {
+ cval = strtoul(value, NULL, 16);
+ pref->varp.colorp->pixel = 0;
+ if ((pref->varp.colorp->red != RED_COMPONENT(cval)) ||
+ (pref->varp.colorp->green != GREEN_COMPONENT(cval)) ||
+ (pref->varp.colorp->blue != BLUE_COMPONENT(cval))) {
+ module->prefs_changed = TRUE;
+ pref->varp.colorp->red = RED_COMPONENT(cval);
+ pref->varp.colorp->green = GREEN_COMPONENT(cval);
+ pref->varp.colorp->blue = BLUE_COMPONENT(cval);
+ }
+ break;
+ }
- case PREF_STATIC_TEXT:
- case PREF_UAT:
- {
- break;
- }
+ case PREF_CUSTOM:
+ return pref->custom_cbs.set_cb(pref, value, &module->prefs_changed);
- case PREF_OBSOLETE:
- return PREFS_SET_OBSOLETE; /* no such preference any more */
+ case PREF_STATIC_TEXT:
+ case PREF_UAT:
+ {
+ break;
+ }
+
+ case PREF_OBSOLETE:
+ return PREFS_SET_OBSOLETE; /* no such preference any more */
+ }
}
- }
- return PREFS_SET_OK;
+ return PREFS_SET_OK;
}
typedef struct {
@@ -4782,74 +4782,74 @@ write_module_prefs(module_t *module, gpointer user_data)
int
write_prefs(char **pf_path_return)
{
- char *pf_path;
- FILE *pf;
- write_gui_pref_arg_t write_gui_pref_info;
+ char *pf_path;
+ FILE *pf;
+ write_gui_pref_arg_t write_gui_pref_info;
- /* Needed for "-G defaultprefs" */
- init_prefs();
+ /* Needed for "-G defaultprefs" */
+ init_prefs();
- /* To do:
- * - Split output lines longer than MAX_VAL_LEN
- * - Create a function for the preference directory check/creation
- * so that duplication can be avoided with filter.c
- */
+ /* To do:
+ * - Split output lines longer than MAX_VAL_LEN
+ * - Create a function for the preference directory check/creation
+ * so that duplication can be avoided with filter.c
+ */
- if (pf_path_return != NULL) {
- pf_path = get_persconffile_path(PF_NAME, TRUE);
- if ((pf = ws_fopen(pf_path, "w")) == NULL) {
- *pf_path_return = pf_path;
- return errno;
+ if (pf_path_return != NULL) {
+ pf_path = get_persconffile_path(PF_NAME, TRUE);
+ if ((pf = ws_fopen(pf_path, "w")) == NULL) {
+ *pf_path_return = pf_path;
+ return errno;
+ }
+ } else {
+ pf = stdout;
}
- } else {
- pf = stdout;
- }
-
- fputs("# Configuration file for Wireshark " VERSION ".\n"
- "#\n"
- "# This file is regenerated each time preferences are saved within\n"
- "# Wireshark. Making manual changes should be safe, however.\n"
- "# Preferences that have been commented out have not been\n"
- "# changed from their default value.\n", pf);
-
- /*
- * For "backwards compatibility" the GUI module is written first as it's
- * at the top of the file. This is followed by all modules that can't
- * fit into the preferences read/write API. Finally the remaining modules
- * are written in alphabetical order (including of course the protocol preferences)
- */
- write_gui_pref_info.pf = pf;
- write_gui_pref_info.is_gui_module = TRUE;
-
- write_module_prefs(gui_module, &write_gui_pref_info);
-
- {
- struct filter_expression *fe = *(struct filter_expression **)prefs.filter_expressions;
-
- if (fe != NULL)
- fprintf(pf, "\n####### Filter Expressions ########\n");
-
- while (fe != NULL) {
- if (fe->deleted == FALSE) {
- fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_LABEL, fe->label);
- fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_ENABLED,
- fe->enabled == TRUE ? "TRUE" : "FALSE");
- fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_EXPR, fe->expression);
- }
- fe = fe->next;
+
+ fputs("# Configuration file for Wireshark " VERSION ".\n"
+ "#\n"
+ "# This file is regenerated each time preferences are saved within\n"
+ "# Wireshark. Making manual changes should be safe, however.\n"
+ "# Preferences that have been commented out have not been\n"
+ "# changed from their default value.\n", pf);
+
+ /*
+ * For "backwards compatibility" the GUI module is written first as it's
+ * at the top of the file. This is followed by all modules that can't
+ * fit into the preferences read/write API. Finally the remaining modules
+ * are written in alphabetical order (including of course the protocol preferences)
+ */
+ write_gui_pref_info.pf = pf;
+ write_gui_pref_info.is_gui_module = TRUE;
+
+ write_module_prefs(gui_module, &write_gui_pref_info);
+
+ {
+ struct filter_expression *fe = *(struct filter_expression **)prefs.filter_expressions;
+
+ if (fe != NULL)
+ fprintf(pf, "\n####### Filter Expressions ########\n");
+
+ while (fe != NULL) {
+ if (fe->deleted == FALSE) {
+ fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_LABEL, fe->label);
+ fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_ENABLED,
+ fe->enabled == TRUE ? "TRUE" : "FALSE");
+ fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_EXPR, fe->expression);
+ }
+ fe = fe->next;
+ }
}
- }
- write_gui_pref_info.is_gui_module = FALSE;
- prefs_modules_foreach_submodules(NULL, write_module_prefs, &write_gui_pref_info);
+ write_gui_pref_info.is_gui_module = FALSE;
+ prefs_modules_foreach_submodules(NULL, write_module_prefs, &write_gui_pref_info);
- fclose(pf);
+ fclose(pf);
- /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
- an error indication, or maybe write to a new preferences file and
- rename that file on top of the old one only if there are not I/O
- errors. */
- return 0;
+ /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
+ an error indication, or maybe write to a new preferences file and
+ rename that file on top of the old one only if there are not I/O
+ errors. */
+ return 0;
}
/** The col_list is only partly managed by the custom preference API
@@ -4859,18 +4859,18 @@ write_prefs(char **pf_path_return)
static void
free_col_info(GList * list)
{
- fmt_data *cfmt;
-
- while (list != NULL) {
- cfmt = (fmt_data *)list->data;
-
- g_free(cfmt->title);
- g_free(cfmt->custom_field);
- g_free(cfmt);
- list = g_list_remove_link(list, list);
- }
- g_list_free(list);
- list = NULL;
+ fmt_data *cfmt;
+
+ while (list != NULL) {
+ cfmt = (fmt_data *)list->data;
+
+ g_free(cfmt->title);
+ g_free(cfmt->custom_field);
+ g_free(cfmt);
+ list = g_list_remove_link(list, list);
+ }
+ g_list_free(list);
+ list = NULL;
}
/*
diff --git a/mergecap.c b/mergecap.c
index 450e870e7b..748a317feb 100644
--- a/mergecap.c
+++ b/mergecap.c
@@ -43,7 +43,7 @@
#endif
#ifdef HAVE_LIBZ
-#include <zlib.h> /* to get the libz version number */
+#include <zlib.h> /* to get the libz version number */
#endif
#include <string.h>
diff --git a/pcapio.c b/pcapio.c
index 5393232509..91cec77f52 100644
--- a/pcapio.c
+++ b/pcapio.c
@@ -249,8 +249,8 @@ pcapng_count_string_option(const char *option_value)
/* There's a value to write; get its length */
return (guint32)(sizeof(struct option) +
(guint16)ADD_PADDING(strlen(option_value)));
- }
- return 0; /* nothing to write */
+ }
+ return 0; /* nothing to write */
}
static gboolean
@@ -734,11 +734,11 @@ pcapng_write_interface_statistics_block(FILE* pfile,
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
* Local variables:
- * c-basic-offset: 4
+ * c-basic-offset: 8
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
- * vi: set shiftwidth=4 tabstop=8 expandtab:
- * :indentSize=4:tabSize=8:noTabs=true:
+ * vi: set shiftwidth=8 tabstop=8 expandtab:
+ * :indentSize=8:tabSize=8:noTabs=true:
*/
diff --git a/reordercap.c b/reordercap.c
index c8e1fd53a4..fc610fab5a 100644
--- a/reordercap.c
+++ b/reordercap.c
@@ -37,7 +37,7 @@
#endif
#ifdef HAVE_LIBZ
-#include <zlib.h> /* to get the libz version number */
+#include <zlib.h> /* to get the libz version number */
#endif
#include "wtap.h"
diff --git a/text2pcap.c b/text2pcap.c
index 52ac53d584..3292902a8f 100644
--- a/text2pcap.c
+++ b/text2pcap.c
@@ -132,7 +132,7 @@
#include <assert.h>
#ifdef HAVE_LIBZ
-#include <zlib.h> /* to get the libz version number */
+#include <zlib.h> /* to get the libz version number */
#endif
#ifndef HAVE_GETOPT
diff --git a/tfshark.c b/tfshark.c
index 8a266b5c9a..4670d74af6 100644
--- a/tfshark.c
+++ b/tfshark.c
@@ -51,7 +51,7 @@
#endif
#ifdef HAVE_LIBZ
-#include <zlib.h> /* to get the libz version number */
+#include <zlib.h> /* to get the libz version number */
#endif
#ifndef HAVE_GETOPT
@@ -751,29 +751,29 @@ show_version(GString *comp_info_str, GString *runtime_info_str)
static void
get_tfshark_compiled_version_info(GString *str)
{
- /* LIBZ */
+ /* LIBZ */
#ifdef HAVE_LIBZ
- g_string_append(str, "with libz ");
+ g_string_append(str, "with libz ");
#ifdef ZLIB_VERSION
- g_string_append(str, ZLIB_VERSION);
+ g_string_append(str, ZLIB_VERSION);
#else /* ZLIB_VERSION */
- g_string_append(str, "(version unknown)");
+ g_string_append(str, "(version unknown)");
#endif /* ZLIB_VERSION */
#else /* HAVE_LIBZ */
- g_string_append(str, "without libz");
+ g_string_append(str, "without libz");
#endif /* HAVE_LIBZ */
}
static void
get_tfshark_runtime_version_info(GString *str)
{
- /* zlib */
+ /* zlib */
#if defined(HAVE_LIBZ) && !defined(_WIN32)
- g_string_append_printf(str, ", with libz %s", zlibVersion());
+ g_string_append_printf(str, ", with libz %s", zlibVersion());
#endif
- /* stuff used by libwireshark */
- epan_get_runtime_version_info(str);
+ /* stuff used by libwireshark */
+ epan_get_runtime_version_info(str);
}
int
diff --git a/tshark.c b/tshark.c
index 8e142b4631..d2bd31f288 100644
--- a/tshark.c
+++ b/tshark.c
@@ -52,7 +52,7 @@
#endif
#ifdef HAVE_LIBZ
-#include <zlib.h> /* to get the libz version number */
+#include <zlib.h> /* to get the libz version number */
#endif
#ifdef HAVE_LIBCAP
@@ -394,11 +394,11 @@ print_usage(FILE *output)
fprintf(output, " default report=\"fields\"\n");
fprintf(output, " use \"-G ?\" for more help\n");
#ifdef __linux__
- fprintf(output, "\n");
- fprintf(output, "WARNING: dumpcap will enable kernel BPF JIT compiler if available.\n");
- fprintf(output, "You might want to reset it\n");
- fprintf(output, "By doing \"echo 0 > /proc/sys/net/core/bpf_jit_enable\"\n");
- fprintf(output, "\n");
+ fprintf(output, "\n");
+ fprintf(output, "WARNING: dumpcap will enable kernel BPF JIT compiler if available.\n");
+ fprintf(output, "You might want to reset it\n");
+ fprintf(output, "By doing \"echo 0 > /proc/sys/net/core/bpf_jit_enable\"\n");
+ fprintf(output, "\n");
#endif
}
@@ -915,20 +915,20 @@ show_version(GString *comp_info_str, GString *runtime_info_str)
static void
get_tshark_compiled_version_info(GString *str)
{
- /* Capture libraries */
- get_compiled_caplibs_version(str);
+ /* Capture libraries */
+ get_compiled_caplibs_version(str);
- /* LIBZ */
- g_string_append(str, ", ");
+ /* LIBZ */
+ g_string_append(str, ", ");
#ifdef HAVE_LIBZ
- g_string_append(str, "with libz ");
+ g_string_append(str, "with libz ");
#ifdef ZLIB_VERSION
- g_string_append(str, ZLIB_VERSION);
+ g_string_append(str, ZLIB_VERSION);
#else /* ZLIB_VERSION */
- g_string_append(str, "(version unknown)");
+ g_string_append(str, "(version unknown)");
#endif /* ZLIB_VERSION */
#else /* HAVE_LIBZ */
- g_string_append(str, "without libz");
+ g_string_append(str, "without libz");
#endif /* HAVE_LIBZ */
}
diff --git a/ui/gtk/addr_resolution_dlg.c b/ui/gtk/addr_resolution_dlg.c
index 91b6e1817c..71129e1aaa 100644
--- a/ui/gtk/addr_resolution_dlg.c
+++ b/ui/gtk/addr_resolution_dlg.c
@@ -57,107 +57,107 @@ static GtkWidget *addr_resolution_dlg_w = NULL;
static void
eth_hash_to_texbuff(gpointer key, gpointer value, gpointer user_data)
{
- gchar string_buff[ADDRESS_STR_MAX];
- GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
- gint64 eth_as_gint64 = *(gint64*)key;
- hashether_t* tp = (hashether_t*)value;
-
- g_snprintf(string_buff, ADDRESS_STR_MAX, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X Status: %u %s %s\n",
- (guint8)(eth_as_gint64>>40&0xff),
- (guint8)(eth_as_gint64>>32&0xff),
- (guint8)((eth_as_gint64>>24)&0xff),
- (guint8)((eth_as_gint64>>16)&0xff),
- (guint8)((eth_as_gint64>>8)&0xff),
- (guint8)(eth_as_gint64&0xff),
- tp->status,
- tp->hexaddr,
- tp->resolved_name);
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+ gchar string_buff[ADDRESS_STR_MAX];
+ GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
+ gint64 eth_as_gint64 = *(gint64*)key;
+ hashether_t* tp = (hashether_t*)value;
+
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X Status: %u %s %s\n",
+ (guint8)(eth_as_gint64>>40&0xff),
+ (guint8)(eth_as_gint64>>32&0xff),
+ (guint8)((eth_as_gint64>>24)&0xff),
+ (guint8)((eth_as_gint64>>16)&0xff),
+ (guint8)((eth_as_gint64>>8)&0xff),
+ (guint8)(eth_as_gint64&0xff),
+ tp->status,
+ tp->hexaddr,
+ tp->resolved_name);
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
}
static void
manuf_hash_to_texbuff(gpointer key, gpointer value, gpointer user_data)
{
- gchar string_buff[ADDRESS_STR_MAX];
- GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
- gchar *name = (gchar *)value;
- int eth_as_gint = *(int*)key;
+ gchar string_buff[ADDRESS_STR_MAX];
+ GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
+ gchar *name = (gchar *)value;
+ int eth_as_gint = *(int*)key;
- g_snprintf(string_buff, ADDRESS_STR_MAX, "%.2X:%.2X:%.2X %s\n",eth_as_gint>>16, (eth_as_gint>>8)&0xff, eth_as_gint&0xff,name);
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "%.2X:%.2X:%.2X %s\n",eth_as_gint>>16, (eth_as_gint>>8)&0xff, eth_as_gint&0xff,name);
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
}
static void
wka_hash_to_texbuff(gpointer key, gpointer value, gpointer user_data)
{
- gchar string_buff[ADDRESS_STR_MAX];
- GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
- gchar *name = (gchar *)value;
- gint64 eth_as_gint64 = *(gint64*)key;
-
- g_snprintf(string_buff, ADDRESS_STR_MAX, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X %s\n",
- (guint8)(eth_as_gint64>>40&0xff),
- (guint8)(eth_as_gint64>>32&0xff),
- (guint8)((eth_as_gint64>>24)&0xff),
- (guint8)((eth_as_gint64>>16)&0xff),
- (guint8)((eth_as_gint64>>8)&0xff),
- (guint8)(eth_as_gint64&0xff),
- name);
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+ gchar string_buff[ADDRESS_STR_MAX];
+ GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
+ gchar *name = (gchar *)value;
+ gint64 eth_as_gint64 = *(gint64*)key;
+
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X %s\n",
+ (guint8)(eth_as_gint64>>40&0xff),
+ (guint8)(eth_as_gint64>>32&0xff),
+ (guint8)((eth_as_gint64>>24)&0xff),
+ (guint8)((eth_as_gint64>>16)&0xff),
+ (guint8)((eth_as_gint64>>8)&0xff),
+ (guint8)(eth_as_gint64&0xff),
+ name);
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
}
static void
serv_port_hash_to_texbuff(gpointer key, gpointer value, gpointer user_data)
{
- gchar string_buff[ADDRESS_STR_MAX];
- GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
- serv_port_t *serv_port_table = (serv_port_t *)value;
- int port = *(int*)key;
+ gchar string_buff[ADDRESS_STR_MAX];
+ GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
+ serv_port_t *serv_port_table = (serv_port_t *)value;
+ int port = *(int*)key;
- g_snprintf(string_buff, ADDRESS_STR_MAX, "Port %u \n"" TCP %s\n"" UDP %s\n"" SCTP %s\n"" DCCP %s\n",
- port,
- serv_port_table->tcp_name,
- serv_port_table->udp_name,
- serv_port_table->sctp_name,
- serv_port_table->dccp_name);
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "Port %u \n"" TCP %s\n"" UDP %s\n"" SCTP %s\n"" DCCP %s\n",
+ port,
+ serv_port_table->tcp_name,
+ serv_port_table->udp_name,
+ serv_port_table->sctp_name,
+ serv_port_table->dccp_name);
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
}
static void
ipv4_hash_table_to_texbuff(gpointer key, gpointer value, gpointer user_data)
{
- gchar string_buff[ADDRESS_STR_MAX];
- GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
- hashipv4_t *ipv4_hash_table_entry = (hashipv4_t *)value;
- int addr = GPOINTER_TO_UINT(key);
+ gchar string_buff[ADDRESS_STR_MAX];
+ GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
+ hashipv4_t *ipv4_hash_table_entry = (hashipv4_t *)value;
+ int addr = GPOINTER_TO_UINT(key);
- g_snprintf(string_buff, ADDRESS_STR_MAX, "Key:0x%x IP: %s, Name: %s\n",
- addr,
- ipv4_hash_table_entry->ip,
- ipv4_hash_table_entry->name);
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "Key:0x%x IP: %s, Name: %s\n",
+ addr,
+ ipv4_hash_table_entry->ip,
+ ipv4_hash_table_entry->name);
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
}
static void
ipv4_hash_table_resolved_to_texbuff(gpointer key _U_, gpointer value, gpointer user_data)
{
- gchar string_buff[ADDRESS_STR_MAX];
- GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
- hashipv4_t *ipv4_hash_table_entry = (hashipv4_t *)value;
+ gchar string_buff[ADDRESS_STR_MAX];
+ GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
+ hashipv4_t *ipv4_hash_table_entry = (hashipv4_t *)value;
- if((ipv4_hash_table_entry->flags & DUMMY_ADDRESS_ENTRY)== 0){
- g_snprintf(string_buff, ADDRESS_STR_MAX, "%s\t%s\n",
- ipv4_hash_table_entry->ip,
- ipv4_hash_table_entry->name);
+ if((ipv4_hash_table_entry->flags & DUMMY_ADDRESS_ENTRY)== 0){
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "%s\t%s\n",
+ ipv4_hash_table_entry->ip,
+ ipv4_hash_table_entry->name);
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
- }
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+ }
}
@@ -166,32 +166,32 @@ ipv4_hash_table_resolved_to_texbuff(gpointer key _U_, gpointer value, gpointer u
static void
ipv6_hash_table_to_texbuff(gpointer key _U_, gpointer value, gpointer user_data)
{
- gchar string_buff[ADDRESS_STR_MAX];
- GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
- hashipv6_t *ipv6_hash_table_entry = (hashipv6_t *)value;
+ gchar string_buff[ADDRESS_STR_MAX];
+ GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
+ hashipv6_t *ipv6_hash_table_entry = (hashipv6_t *)value;
- g_snprintf(string_buff, ADDRESS_STR_MAX, "IP: %s, Name: %s\n",
- ipv6_hash_table_entry->ip6,
- ipv6_hash_table_entry->name);
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "IP: %s, Name: %s\n",
+ ipv6_hash_table_entry->ip6,
+ ipv6_hash_table_entry->name);
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
}
static void
ipv6_hash_table_resolved_to_texbuff(gpointer key _U_, gpointer value, gpointer user_data)
{
- gchar string_buff[ADDRESS_STR_MAX];
- GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
- hashipv6_t *ipv6_hash_table_entry = (hashipv6_t *)value;
+ gchar string_buff[ADDRESS_STR_MAX];
+ GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
+ hashipv6_t *ipv6_hash_table_entry = (hashipv6_t *)value;
- if((ipv6_hash_table_entry->flags & DUMMY_ADDRESS_ENTRY)== 0){
- g_snprintf(string_buff, ADDRESS_STR_MAX, "%s\t%s\n",
- ipv6_hash_table_entry->ip6,
- ipv6_hash_table_entry->name);
+ if((ipv6_hash_table_entry->flags & DUMMY_ADDRESS_ENTRY)== 0){
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "%s\t%s\n",
+ ipv6_hash_table_entry->ip6,
+ ipv6_hash_table_entry->name);
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
- }
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+ }
}
@@ -199,12 +199,12 @@ static void
addres_resolution_to_texbuff(GtkTextBuffer *buffer)
{
gchar string_buff[ADDRESS_STR_MAX];
- GHashTable *manuf_hashtable;
- GHashTable *wka_hashtable;
- GHashTable *eth_hashtable;
- GHashTable *serv_port_hashtable;
- GHashTable *ipv4_hash_table;
- GHashTable *ipv6_hash_table;
+ GHashTable *manuf_hashtable;
+ GHashTable *wka_hashtable;
+ GHashTable *eth_hashtable;
+ GHashTable *serv_port_hashtable;
+ GHashTable *ipv4_hash_table;
+ GHashTable *ipv6_hash_table;
g_snprintf(string_buff, ADDRESS_STR_MAX, "# Hosts information in Wireshark \n#\n");
gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
@@ -212,74 +212,74 @@ addres_resolution_to_texbuff(GtkTextBuffer *buffer)
gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
/* Dump the v4 addresses first, then v6 */
- ipv4_hash_table = get_ipv4_hash_table();
- if(ipv4_hash_table){
- g_hash_table_foreach( ipv4_hash_table, ipv4_hash_table_resolved_to_texbuff, buffer);
- }
-
- ipv6_hash_table = get_ipv6_hash_table();
- if(ipv6_hash_table){
- g_hash_table_foreach( ipv6_hash_table, ipv6_hash_table_resolved_to_texbuff, buffer);
- }
-
- g_snprintf(string_buff, ADDRESS_STR_MAX, "\n\n# Address resolution IPv4 Hash table \n#\n");
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
-
- if(ipv4_hash_table){
- g_snprintf(string_buff, ADDRESS_STR_MAX, "# With %i entries\n#\n", g_hash_table_size(ipv4_hash_table));
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
- g_hash_table_foreach( ipv4_hash_table, ipv4_hash_table_to_texbuff, buffer);
- }
-
- g_snprintf(string_buff, ADDRESS_STR_MAX, "\n\n# Address resolution IPv6 Hash table \n#\n");
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
-
- if(ipv6_hash_table){
- g_snprintf(string_buff, ADDRESS_STR_MAX, "# With %i entries\n#\n", g_hash_table_size(ipv6_hash_table));
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
- g_hash_table_foreach( ipv6_hash_table, ipv6_hash_table_to_texbuff, buffer);
- }
-
-
- g_snprintf(string_buff, ADDRESS_STR_MAX, "\n\n# Port names information in Wireshark \n#\n");
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
-
- serv_port_hashtable = get_serv_port_hashtable();
- if(serv_port_hashtable){
- g_snprintf(string_buff, ADDRESS_STR_MAX, "# With %i entries\n#\n", g_hash_table_size(serv_port_hashtable));
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
- g_hash_table_foreach( serv_port_hashtable, serv_port_hash_to_texbuff, buffer);
- }
-
- g_snprintf(string_buff, ADDRESS_STR_MAX, "\n\n# Eth names information in Wireshark \n#\n");
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
-
- eth_hashtable = get_eth_hashtable();
- if(eth_hashtable){
- g_snprintf(string_buff, ADDRESS_STR_MAX, "# With %i entries\n#\n", g_hash_table_size(eth_hashtable));
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
- g_hash_table_foreach( eth_hashtable, eth_hash_to_texbuff, buffer);
- }
-
- g_snprintf(string_buff, ADDRESS_STR_MAX, "\n\n# Manuf information in Wireshark \n#\n");
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
-
- manuf_hashtable = get_manuf_hashtable();
- if(manuf_hashtable){
- g_snprintf(string_buff, ADDRESS_STR_MAX, "# With %i entries\n#\n", g_hash_table_size(manuf_hashtable));
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
- g_hash_table_foreach( manuf_hashtable, manuf_hash_to_texbuff, buffer);
- }
-
- g_snprintf(string_buff, ADDRESS_STR_MAX, "\n\n# wka information in Wireshark \n#\n");
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
-
- wka_hashtable = get_wka_hashtable();
- if(wka_hashtable){
- g_snprintf(string_buff, ADDRESS_STR_MAX, "# With %i entries\n#\n", g_hash_table_size(wka_hashtable));
- gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
- g_hash_table_foreach( wka_hashtable, wka_hash_to_texbuff, buffer);
- }
+ ipv4_hash_table = get_ipv4_hash_table();
+ if(ipv4_hash_table){
+ g_hash_table_foreach( ipv4_hash_table, ipv4_hash_table_resolved_to_texbuff, buffer);
+ }
+
+ ipv6_hash_table = get_ipv6_hash_table();
+ if(ipv6_hash_table){
+ g_hash_table_foreach( ipv6_hash_table, ipv6_hash_table_resolved_to_texbuff, buffer);
+ }
+
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "\n\n# Address resolution IPv4 Hash table \n#\n");
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+
+ if(ipv4_hash_table){
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "# With %i entries\n#\n", g_hash_table_size(ipv4_hash_table));
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+ g_hash_table_foreach( ipv4_hash_table, ipv4_hash_table_to_texbuff, buffer);
+ }
+
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "\n\n# Address resolution IPv6 Hash table \n#\n");
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+
+ if(ipv6_hash_table){
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "# With %i entries\n#\n", g_hash_table_size(ipv6_hash_table));
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+ g_hash_table_foreach( ipv6_hash_table, ipv6_hash_table_to_texbuff, buffer);
+ }
+
+
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "\n\n# Port names information in Wireshark \n#\n");
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+
+ serv_port_hashtable = get_serv_port_hashtable();
+ if(serv_port_hashtable){
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "# With %i entries\n#\n", g_hash_table_size(serv_port_hashtable));
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+ g_hash_table_foreach( serv_port_hashtable, serv_port_hash_to_texbuff, buffer);
+ }
+
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "\n\n# Eth names information in Wireshark \n#\n");
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+
+ eth_hashtable = get_eth_hashtable();
+ if(eth_hashtable){
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "# With %i entries\n#\n", g_hash_table_size(eth_hashtable));
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+ g_hash_table_foreach( eth_hashtable, eth_hash_to_texbuff, buffer);
+ }
+
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "\n\n# Manuf information in Wireshark \n#\n");
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+
+ manuf_hashtable = get_manuf_hashtable();
+ if(manuf_hashtable){
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "# With %i entries\n#\n", g_hash_table_size(manuf_hashtable));
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+ g_hash_table_foreach( manuf_hashtable, manuf_hash_to_texbuff, buffer);
+ }
+
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "\n\n# wka information in Wireshark \n#\n");
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+
+ wka_hashtable = get_wka_hashtable();
+ if(wka_hashtable){
+ g_snprintf(string_buff, ADDRESS_STR_MAX, "# With %i entries\n#\n", g_hash_table_size(wka_hashtable));
+ gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
+ g_hash_table_foreach( wka_hashtable, wka_hash_to_texbuff, buffer);
+ }
}
diff --git a/ui/gtk/color_dlg.c b/ui/gtk/color_dlg.c
index 77929fd137..aca38411ca 100644
--- a/ui/gtk/color_dlg.c
+++ b/ui/gtk/color_dlg.c
@@ -1020,20 +1020,20 @@ color_clear_cb(GtkWidget *widget, gpointer data _U_) {
static void
overwrite_existing_colorfilters_cb(gpointer dialog _U_, gint btn, gpointer data _U_)
{
- switch (btn) {
- case(ESD_BTN_SAVE):
- /* overwrite the file*/
- if (!color_filters_write(color_filter_edit_list))
- simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
- "Could not open colorfilter file: %s", g_strerror(errno));
- else
- prefs.unknown_colorfilters = FALSE;
- break;
- case(ESD_BTN_DONT_SAVE):
- break;
- default:
- g_assert_not_reached();
- }
+ switch (btn) {
+ case(ESD_BTN_SAVE):
+ /* overwrite the file*/
+ if (!color_filters_write(color_filter_edit_list))
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+ "Could not open colorfilter file: %s", g_strerror(errno));
+ else
+ prefs.unknown_colorfilters = FALSE;
+ break;
+ case(ESD_BTN_DONT_SAVE):
+ break;
+ default:
+ g_assert_not_reached();
+ }
}
static void
diff --git a/ui/gtk/conversations_table.c b/ui/gtk/conversations_table.c
index cdda16fa63..ec7fb717a3 100644
--- a/ui/gtk/conversations_table.c
+++ b/ui/gtk/conversations_table.c
@@ -95,7 +95,7 @@ reset_ct_table_data(conversations_table *ct)
}
if(ct->page_lb) {
- display_name = cf_get_display_name(&cfile);
+ display_name = cf_get_display_name(&cfile);
g_snprintf(title, sizeof(title), "Conversations: %s", display_name);
g_free(display_name);
gtk_window_set_title(GTK_WINDOW(ct->win), title);
@@ -114,7 +114,7 @@ reset_ct_table_data(conversations_table *ct)
}
gtk_label_set_text(GTK_LABEL(ct->name_lb), title);
} else {
- display_name = cf_get_display_name(&cfile);
+ display_name = cf_get_display_name(&cfile);
g_snprintf(title, sizeof(title), "%s Conversations: %s", ct->name, display_name);
g_free(display_name);
gtk_window_set_title(GTK_WINDOW(ct->win), title);
diff --git a/ui/gtk/main.c b/ui/gtk/main.c
index 8be126dd59..00facabdff 100644
--- a/ui/gtk/main.c
+++ b/ui/gtk/main.c
@@ -46,7 +46,7 @@
#endif
#ifdef HAVE_LIBZ
-#include <zlib.h> /* to get the libz version number */
+#include <zlib.h> /* to get the libz version number */
#endif
#ifdef _WIN32 /* Needed for console I/O */
diff --git a/ui/gtk/text_page_utils.c b/ui/gtk/text_page_utils.c
index 2a08838029..cc25c1bcf9 100644
--- a/ui/gtk/text_page_utils.c
+++ b/ui/gtk/text_page_utils.c
@@ -111,7 +111,7 @@ static void text_page_insert(GtkWidget *page, const char *buffer, int nchars)
static void text_page_set_text(GtkWidget *page, const char *absolute_path)
{
FILE *text_file;
- char line[4096+1]; /* XXX - size? */
+ char line[4096+1]; /* XXX - size? */
text_file = ws_fopen(absolute_path, "r");
if (text_file != NULL) {
diff --git a/wiretap/pcapng.c b/wiretap/pcapng.c
index 5e42797b68..b23c9c7e6f 100644
--- a/wiretap/pcapng.c
+++ b/wiretap/pcapng.c
@@ -58,20 +58,20 @@
static gboolean
pcapng_read(wtap *wth, int *err, gchar **err_info,
- gint64 *data_offset);
+ gint64 *data_offset);
static gboolean
pcapng_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
+ struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static void
pcapng_close(wtap *wth);
/* pcapng: common block header for every block type */
typedef struct pcapng_block_header_s {
- guint32 block_type;
- guint32 block_total_length;
- /* x bytes block_body */
- /* guint32 block_total_length */
+ guint32 block_type;
+ guint32 block_total_length;
+ /* x bytes block_body */
+ /* guint32 block_total_length */
} pcapng_block_header_t;
/*
@@ -89,16 +89,16 @@ typedef struct pcapng_block_header_s {
* For now, we pick an arbitrary limit of 16MB (OK, fine, 16MiB, but
* don't try saying that on Wikipedia :-) :-) :-)).
*/
-#define MAX_BLOCK_SIZE (16*1024*1024)
+#define MAX_BLOCK_SIZE (16*1024*1024)
/* pcapng: section header block */
typedef struct pcapng_section_header_block_s {
- /* pcapng_block_header_t */
- guint32 magic;
- guint16 version_major;
- guint16 version_minor;
- guint64 section_length; /* might be -1 for unknown */
- /* ... Options ... */
+ /* pcapng_block_header_t */
+ guint32 magic;
+ guint16 version_major;
+ guint16 version_minor;
+ guint64 section_length; /* might be -1 for unknown */
+ /* ... Options ... */
} pcapng_section_header_block_t;
/*
@@ -108,10 +108,10 @@ typedef struct pcapng_section_header_block_s {
/* pcapng: interface description block */
typedef struct pcapng_interface_description_block_s {
- guint16 linktype;
- guint16 reserved;
- guint32 snaplen;
- /* ... Options ... */
+ guint16 linktype;
+ guint16 reserved;
+ guint32 snaplen;
+ /* ... Options ... */
} pcapng_interface_description_block_t;
/*
@@ -121,15 +121,15 @@ typedef struct pcapng_interface_description_block_s {
/* pcapng: packet block (obsolete) */
typedef struct pcapng_packet_block_s {
- guint16 interface_id;
- guint16 drops_count;
- guint32 timestamp_high;
- guint32 timestamp_low;
- guint32 captured_len;
- guint32 packet_len;
- /* ... Packet Data ... */
- /* ... Padding ... */
- /* ... Options ... */
+ guint16 interface_id;
+ guint16 drops_count;
+ guint32 timestamp_high;
+ guint32 timestamp_low;
+ guint32 captured_len;
+ guint32 packet_len;
+ /* ... Packet Data ... */
+ /* ... Padding ... */
+ /* ... Options ... */
} pcapng_packet_block_t;
/*
@@ -139,14 +139,14 @@ typedef struct pcapng_packet_block_s {
/* pcapng: enhanced packet block */
typedef struct pcapng_enhanced_packet_block_s {
- guint32 interface_id;
- guint32 timestamp_high;
- guint32 timestamp_low;
- guint32 captured_len;
- guint32 packet_len;
- /* ... Packet Data ... */
- /* ... Padding ... */
- /* ... Options ... */
+ guint32 interface_id;
+ guint32 timestamp_high;
+ guint32 timestamp_low;
+ guint32 captured_len;
+ guint32 packet_len;
+ /* ... Packet Data ... */
+ /* ... Padding ... */
+ /* ... Options ... */
} pcapng_enhanced_packet_block_t;
/*
@@ -156,9 +156,9 @@ typedef struct pcapng_enhanced_packet_block_s {
/* pcapng: simple packet block */
typedef struct pcapng_simple_packet_block_s {
- guint32 packet_len;
- /* ... Packet Data ... */
- /* ... Padding ... */
+ guint32 packet_len;
+ /* ... Packet Data ... */
+ /* ... Padding ... */
} pcapng_simple_packet_block_t;
/*
@@ -168,9 +168,9 @@ typedef struct pcapng_simple_packet_block_s {
/* pcapng: name resolution block */
typedef struct pcapng_name_resolution_block_s {
- guint16 record_type;
- guint16 record_len;
- /* ... Record ... */
+ guint16 record_type;
+ guint16 record_len;
+ /* ... Record ... */
} pcapng_name_resolution_block_t;
/*
@@ -181,10 +181,10 @@ typedef struct pcapng_name_resolution_block_s {
/* pcapng: interface statistics block */
typedef struct pcapng_interface_statistics_block_s {
- guint32 interface_id;
- guint32 timestamp_high;
- guint32 timestamp_low;
- /* ... Options ... */
+ guint32 interface_id;
+ guint32 timestamp_high;
+ guint32 timestamp_low;
+ /* ... Options ... */
} pcapng_interface_statistics_block_t;
/*
@@ -194,15 +194,15 @@ typedef struct pcapng_interface_statistics_block_s {
/* pcapng: common option header for every option type */
typedef struct pcapng_option_header_s {
- guint16 option_code;
- guint16 option_length;
- /* ... x bytes Option Body ... */
- /* ... Padding ... */
+ guint16 option_code;
+ guint16 option_length;
+ /* ... x bytes Option Body ... */
+ /* ... Padding ... */
} pcapng_option_header_t;
struct option {
- guint16 type;
- guint16 value_length;
+ guint16 type;
+ guint16 value_length;
};
/* Block types */
@@ -228,13 +228,13 @@ struct option {
#if 0
/* Moved to wtap.h */
typedef struct wtapng_section_s {
- /* mandatory */
- guint64 section_length;
- /* options */
- gchar *opt_comment; /* NULL if not available */
- gchar *shb_hardware; /* NULL if not available */
- gchar *shb_os; /* NULL if not available */
- gchar *shb_user_appl; /* NULL if not available */
+ /* mandatory */
+ guint64 section_length;
+ /* options */
+ gchar *opt_comment; /* NULL if not available */
+ gchar *shb_hardware; /* NULL if not available */
+ gchar *shb_os; /* NULL if not available */
+ gchar *shb_user_appl; /* NULL if not available */
} wtapng_section_t;
#endif
@@ -260,120 +260,120 @@ typedef struct wtapng_section_s {
*/
typedef struct wtapng_if_descr_s {
- /* mandatory */
- guint16 link_type;
- guint encap;
- guint32 snap_len;
- /* options */
- gchar *opt_comment; /* NULL if not available */
- gchar *if_name; /* NULL if not available, opt 2 A UTF-8 string containing the name of the device used to capture data. */
- gchar *if_description;/* NULL if not available, opt 3 A UTF-8 string containing the description of the device used to capture data. */
- /* XXX: if_IPv4addr opt 4 Interface network address and netmask.*/
- /* XXX: if_IPv6addr opt 5 Interface network address and prefix length (stored in the last byte).*/
- /* XXX: if_MACaddr opt 6 Interface Hardware MAC address (48 bits).*/
- /* XXX: if_EUIaddr opt 7 Interface Hardware EUI address (64 bits)*/
- guint64 if_speed; /* 0 if unknown, opt 8 Interface speed (in bps). 100000000 for 100Mbps */
- guint8 if_tsresol; /* default is 6 for microsecond resolution, opt 9 Resolution of timestamps.
- * If the Most Significant Bit is equal to zero, the remaining bits indicates the resolution of the timestamp as as a negative power of 10
- */
- /* XXX: if_tzone 10 Time zone for GMT support (TODO: specify better). */
- gchar *if_filter; /* NULL if not available, opt 11 The filter (e.g. "capture only TCP traffic") used to capture traffic.
- * The first byte of the Option Data keeps a code of the filter used (e.g. if this is a libpcap string, or BPF bytecode, and more).
- */
- gchar *if_os; /* NULL if not available, 12 A UTF-8 string containing the name of the operating system of the machine in which this interface is installed. */
- gint8 if_fcslen; /* -1 if unknown or changes between packets, opt 13 An integer value that specified the length of the Frame Check Sequence (in bits) for this interface. */
- /* XXX: guint64 if_tsoffset; opt 14 A 64 bits integer value that specifies an offset (in seconds)...*/
+ /* mandatory */
+ guint16 link_type;
+ guint encap;
+ guint32 snap_len;
+ /* options */
+ gchar *opt_comment; /* NULL if not available */
+ gchar *if_name; /* NULL if not available, opt 2 A UTF-8 string containing the name of the device used to capture data. */
+ gchar *if_description; /* NULL if not available, opt 3 A UTF-8 string containing the description of the device used to capture data. */
+ /* XXX: if_IPv4addr opt 4 Interface network address and netmask.*/
+ /* XXX: if_IPv6addr opt 5 Interface network address and prefix length (stored in the last byte).*/
+ /* XXX: if_MACaddr opt 6 Interface Hardware MAC address (48 bits).*/
+ /* XXX: if_EUIaddr opt 7 Interface Hardware EUI address (64 bits)*/
+ guint64 if_speed; /* 0 if unknown, opt 8 Interface speed (in bps). 100000000 for 100Mbps */
+ guint8 if_tsresol; /* default is 6 for microsecond resolution, opt 9 Resolution of timestamps.
+ * If the Most Significant Bit is equal to zero, the remaining bits indicates the resolution of the timestamp as as a negative power of 10
+ */
+ /* XXX: if_tzone 10 Time zone for GMT support (TODO: specify better). */
+ gchar *if_filter; /* NULL if not available, opt 11 The filter (e.g. "capture only TCP traffic") used to capture traffic.
+ * The first byte of the Option Data keeps a code of the filter used (e.g. if this is a libpcap string, or BPF bytecode, and more).
+ */
+ gchar *if_os; /* NULL if not available, 12 A UTF-8 string containing the name of the operating system of the machine in which this interface is installed. */
+ gint8 if_fcslen; /* -1 if unknown or changes between packets, opt 13 An integer value that specified the length of the Frame Check Sequence (in bits) for this interface. */
+ /* XXX: guint64 if_tsoffset; opt 14 A 64 bits integer value that specifies an offset (in seconds)...*/
} wtapng_if_descr_t;
#endif
/* Packets */
typedef struct wtapng_packet_s {
- /* mandatory */
- guint32 ts_high; /* seconds since 1.1.1970 */
- guint32 ts_low; /* fraction of seconds, depends on if_tsresol */
- guint32 cap_len; /* data length in the file */
- guint32 packet_len; /* data length on the wire */
- guint32 interface_id; /* identifier of the interface. */
- guint16 drops_count; /* drops count, only valid for packet block */
- /* 0xffff if information no available */
- /* pack_hash */
- /* XXX - put the packet data / pseudo_header here as well? */
+ /* mandatory */
+ guint32 ts_high; /* seconds since 1.1.1970 */
+ guint32 ts_low; /* fraction of seconds, depends on if_tsresol */
+ guint32 cap_len; /* data length in the file */
+ guint32 packet_len; /* data length on the wire */
+ guint32 interface_id; /* identifier of the interface. */
+ guint16 drops_count; /* drops count, only valid for packet block */
+ /* 0xffff if information no available */
+ /* pack_hash */
+ /* XXX - put the packet data / pseudo_header here as well? */
} wtapng_packet_t;
/* Simple Packets */
typedef struct wtapng_simple_packet_s {
- /* mandatory */
- guint32 cap_len; /* data length in the file */
- guint32 packet_len; /* data length on the wire */
- guint32 pseudo_header_len;
- int wtap_encap;
- /* XXX - put the packet data / pseudo_header here as well? */
+ /* mandatory */
+ guint32 cap_len; /* data length in the file */
+ guint32 packet_len; /* data length on the wire */
+ guint32 pseudo_header_len;
+ int wtap_encap;
+ /* XXX - put the packet data / pseudo_header here as well? */
} wtapng_simple_packet_t;
/* Name Resolution */
typedef struct wtapng_name_res_s {
- /* options */
- gchar *opt_comment; /* NULL if not available */
- /* XXX */
+ /* options */
+ gchar *opt_comment; /* NULL if not available */
+ /* XXX */
} wtapng_name_res_t;
#if 0
/* Interface Statistics moved to wtap.h*/
typedef struct wtapng_if_stats_s {
- /* mandatory */
- guint32 interface_id;
- guint32 ts_high;
- guint32 ts_low;
- /* options */
- gchar *opt_comment; /* NULL if not available */
- guint64 isb_starttime;
- guint64 isb_endtime;
- guint64 isb_ifrecv;
- guint64 isb_ifdrop;
- guint64 isb_filteraccept;
- guint64 isb_osdrop;
- guint64 isb_usrdeliv;
+ /* mandatory */
+ guint32 interface_id;
+ guint32 ts_high;
+ guint32 ts_low;
+ /* options */
+ gchar *opt_comment; /* NULL if not available */
+ guint64 isb_starttime;
+ guint64 isb_endtime;
+ guint64 isb_ifrecv;
+ guint64 isb_ifdrop;
+ guint64 isb_filteraccept;
+ guint64 isb_osdrop;
+ guint64 isb_usrdeliv;
} wtapng_if_stats_t;
#endif
typedef struct wtapng_block_s {
- guint32 type; /* block_type as defined by pcapng */
- union {
- wtapng_section_t section;
- wtapng_if_descr_t if_descr;
- wtapng_name_res_t name_res;
- wtapng_if_stats_t if_stats;
- } data;
-
- /*
- * XXX - currently don't know how to handle these!
- *
- * For one thing, when we're reading a block, they must be
- * writable, i.e. not const, so that we can read into them,
- * but, when we're writing a block, they can be const, and,
- * in fact, they sometimes point to const values.
- */
- struct wtap_pkthdr *packet_header;
- Buffer *frame_buffer;
- int *file_encap;
+ guint32 type; /* block_type as defined by pcapng */
+ union {
+ wtapng_section_t section;
+ wtapng_if_descr_t if_descr;
+ wtapng_name_res_t name_res;
+ wtapng_if_stats_t if_stats;
+ } data;
+
+ /*
+ * XXX - currently don't know how to handle these!
+ *
+ * For one thing, when we're reading a block, they must be
+ * writable, i.e. not const, so that we can read into them,
+ * but, when we're writing a block, they can be const, and,
+ * in fact, they sometimes point to const values.
+ */
+ struct wtap_pkthdr *packet_header;
+ Buffer *frame_buffer;
+ int *file_encap;
} wtapng_block_t;
/* Interface data in private struct */
typedef struct interface_info_s {
- int wtap_encap;
- guint32 snap_len;
- guint64 time_units_per_second;
+ int wtap_encap;
+ guint32 snap_len;
+ guint64 time_units_per_second;
} interface_info_t;
typedef struct {
- gboolean shb_read; /**< Set when first SHB read, second read will fail */
- gboolean byte_swapped;
- guint16 version_major;
- guint16 version_minor;
- GArray *interfaces; /**< Interfaces found in the capture file. */
- gint8 if_fcslen;
- wtap_new_ipv4_callback_t add_new_ipv4;
- wtap_new_ipv6_callback_t add_new_ipv6;
+ gboolean shb_read; /**< Set when first SHB read, second read will fail */
+ gboolean byte_swapped;
+ guint16 version_major;
+ guint16 version_minor;
+ GArray *interfaces; /**< Interfaces found in the capture file. */
+ gint8 if_fcslen;
+ wtap_new_ipv4_callback_t add_new_ipv4;
+ wtap_new_ipv6_callback_t add_new_ipv6;
} pcapng_t;
#ifdef HAVE_PLUGINS
@@ -391,8 +391,8 @@ typedef struct {
* out a block.
*/
typedef struct {
- block_reader read;
- block_writer write;
+ block_reader read;
+ block_writer write;
} block_handler;
static GHashTable *block_handlers;
@@ -401,24 +401,24 @@ void
register_pcapng_block_type_handler(guint block_type, block_reader read,
block_writer write)
{
- block_handler *handler;
+ block_handler *handler;
- if (block_handlers == NULL) {
- /*
- * Create the table of block handlers.
- *
- * XXX - there's no "g_uint_hash()" or "g_uint_equal()",
- * so we use "g_direct_hash()" and "g_direct_equal()".
- */
- block_handlers = g_hash_table_new_full(g_direct_hash,
- g_direct_equal,
- NULL, g_free);
- }
- handler = (block_handler *)g_malloc(sizeof *handler);
- handler->read = read;
- handler->write = write;
- (void)g_hash_table_insert(block_handlers, GUINT_TO_POINTER(block_type),
- handler);
+ if (block_handlers == NULL) {
+ /*
+ * Create the table of block handlers.
+ *
+ * XXX - there's no "g_uint_hash()" or "g_uint_equal()",
+ * so we use "g_direct_hash()" and "g_direct_equal()".
+ */
+ block_handlers = g_hash_table_new_full(g_direct_hash,
+ g_direct_equal,
+ NULL, g_free);
+ }
+ handler = (block_handler *)g_malloc(sizeof *handler);
+ handler->read = read;
+ handler->write = write;
+ (void)g_hash_table_insert(block_handlers, GUINT_TO_POINTER(block_type),
+ handler);
}
#endif /* HAVE_PLUGINS */
@@ -427,71 +427,71 @@ pcapng_read_option(FILE_T fh, pcapng_t *pn, pcapng_option_header_t *oh,
char *content, guint len, guint to_read,
int *err, gchar **err_info)
{
- int bytes_read;
- int block_read;
- guint64 file_offset64;
-
- /* sanity check: don't run past the end of the block */
- if (to_read < sizeof (*oh)) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup("pcapng_read_option: option goes past the end of the block");
- return -1;
- }
+ int bytes_read;
+ int block_read;
+ guint64 file_offset64;
+
+ /* sanity check: don't run past the end of the block */
+ if (to_read < sizeof (*oh)) {
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup("pcapng_read_option: option goes past the end of the block");
+ return -1;
+ }
- /* read option header */
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(oh, sizeof (*oh), fh);
- if (bytes_read != sizeof (*oh)) {
- pcapng_debug0("pcapng_read_option: failed to read option");
- *err = file_error(fh, err_info);
- if (*err != 0)
- return -1;
- return 0;
- }
- block_read = sizeof (*oh);
- if (pn->byte_swapped) {
- oh->option_code = GUINT16_SWAP_LE_BE(oh->option_code);
- oh->option_length = GUINT16_SWAP_LE_BE(oh->option_length);
- }
+ /* read option header */
+ errno = WTAP_ERR_CANT_READ;
+ bytes_read = file_read(oh, sizeof (*oh), fh);
+ if (bytes_read != sizeof (*oh)) {
+ pcapng_debug0("pcapng_read_option: failed to read option");
+ *err = file_error(fh, err_info);
+ if (*err != 0)
+ return -1;
+ return 0;
+ }
+ block_read = sizeof (*oh);
+ if (pn->byte_swapped) {
+ oh->option_code = GUINT16_SWAP_LE_BE(oh->option_code);
+ oh->option_length = GUINT16_SWAP_LE_BE(oh->option_length);
+ }
- /* sanity check: don't run past the end of the block */
- if (to_read < sizeof (*oh) + oh->option_length) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup("pcapng_read_option: option goes past the end of the block");
- return -1;
- }
+ /* sanity check: don't run past the end of the block */
+ if (to_read < sizeof (*oh) + oh->option_length) {
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup("pcapng_read_option: option goes past the end of the block");
+ return -1;
+ }
- /* sanity check: option length */
- if (oh->option_length > len) {
- pcapng_debug2("pcapng_read_option: option_length %u larger than buffer (%u)",
- oh->option_length, len);
- return 0;
- }
+ /* sanity check: option length */
+ if (oh->option_length > len) {
+ pcapng_debug2("pcapng_read_option: option_length %u larger than buffer (%u)",
+ oh->option_length, len);
+ return 0;
+ }
- /* read option content */
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(content, oh->option_length, fh);
- if (bytes_read != oh->option_length) {
- pcapng_debug1("pcapng_read_option: failed to read content of option %u", oh->option_code);
- *err = file_error(fh, err_info);
- if (*err != 0)
- return -1;
- return 0;
- }
- block_read += oh->option_length;
+ /* read option content */
+ errno = WTAP_ERR_CANT_READ;
+ bytes_read = file_read(content, oh->option_length, fh);
+ if (bytes_read != oh->option_length) {
+ pcapng_debug1("pcapng_read_option: failed to read content of option %u", oh->option_code);
+ *err = file_error(fh, err_info);
+ if (*err != 0)
+ return -1;
+ return 0;
+ }
+ block_read += oh->option_length;
- /* jump over potential padding bytes at end of option */
- if ( (oh->option_length % 4) != 0) {
- file_offset64 = file_seek(fh, 4 - (oh->option_length % 4), SEEK_CUR, err);
- if (file_offset64 <= 0) {
- if (*err != 0)
- return -1;
- return 0;
- }
- block_read += 4 - (oh->option_length % 4);
+ /* jump over potential padding bytes at end of option */
+ if ( (oh->option_length % 4) != 0) {
+ file_offset64 = file_seek(fh, 4 - (oh->option_length % 4), SEEK_CUR, err);
+ if (file_offset64 <= 0) {
+ if (*err != 0)
+ return -1;
+ return 0;
}
+ block_read += 4 - (oh->option_length % 4);
+ }
- return block_read;
+ return block_read;
}
@@ -501,207 +501,207 @@ pcapng_read_section_header_block(FILE_T fh, gboolean first_block,
wtapng_block_t *wblock, int *err,
gchar **err_info)
{
- int bytes_read;
- guint block_read;
- guint to_read, opt_cont_buf_len;
- pcapng_section_header_block_t shb;
- pcapng_option_header_t oh;
- char *option_content = NULL; /* Allocate as large as the options block */
-
+ int bytes_read;
+ guint block_read;
+ guint to_read, opt_cont_buf_len;
+ pcapng_section_header_block_t shb;
+ pcapng_option_header_t oh;
+ char *option_content = NULL; /* Allocate as large as the options block */
+
+ /*
+ * Is this block long enough to be an SHB?
+ */
+ if (bh->block_total_length < MIN_SHB_SIZE) {
/*
- * Is this block long enough to be an SHB?
+ * No.
*/
- if (bh->block_total_length < MIN_SHB_SIZE) {
+ if (first_block)
+ return 0; /* probably not a pcap-ng file */
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_section_header_block: total block length %u of an SHB is less than the minimum SHB size %u",
+ bh->block_total_length, MIN_SHB_SIZE);
+ return -1;
+ }
+
+ /* read block content */
+ errno = WTAP_ERR_CANT_READ;
+ bytes_read = file_read(&shb, sizeof shb, fh);
+ if (bytes_read != sizeof shb) {
+ *err = file_error(fh, err_info);
+ if (*err == 0) {
+ if (first_block) {
/*
- * No.
+ * We're reading this as part of an open,
+ * and this block is too short to be
+ * an SHB, so the file is too short
+ * to be a pcap-ng file.
*/
- if (first_block)
- return 0; /* probably not a pcap-ng file */
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_section_header_block: total block length %u of an SHB is less than the minimum SHB size %u",
- bh->block_total_length, MIN_SHB_SIZE);
- return -1;
- }
-
- /* read block content */
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(&shb, sizeof shb, fh);
- if (bytes_read != sizeof shb) {
- *err = file_error(fh, err_info);
- if (*err == 0) {
- if (first_block) {
- /*
- * We're reading this as part of an open,
- * and this block is too short to be
- * an SHB, so the file is too short
- * to be a pcap-ng file.
- */
- return 0;
- }
+ return 0;
+ }
- /*
- * Otherwise, just report this as an error.
- */
- *err = WTAP_ERR_SHORT_READ;
- }
- return -1;
+ /*
+ * Otherwise, just report this as an error.
+ */
+ *err = WTAP_ERR_SHORT_READ;
}
- block_read = bytes_read;
-
- /* is the magic number one we expect? */
- switch (shb.magic) {
- case(0x1A2B3C4D):
- /* this seems pcapng with correct byte order */
- pn->byte_swapped = FALSE;
- pn->version_major = shb.version_major;
- pn->version_minor = shb.version_minor;
-
- pcapng_debug3("pcapng_read_section_header_block: SHB (little endian) V%u.%u, len %u",
- pn->version_major, pn->version_minor, bh->block_total_length);
- break;
- case(0x4D3C2B1A):
- /* this seems pcapng with swapped byte order */
- pn->byte_swapped = TRUE;
- pn->version_major = GUINT16_SWAP_LE_BE(shb.version_major);
- pn->version_minor = GUINT16_SWAP_LE_BE(shb.version_minor);
-
- /* tweak the block length to meet current swapping that we know now */
- bh->block_total_length = GUINT32_SWAP_LE_BE(bh->block_total_length);
-
- pcapng_debug3("pcapng_read_section_header_block: SHB (big endian) V%u.%u, len %u",
- pn->version_major, pn->version_minor, bh->block_total_length);
- break;
- default:
- /* Not a "pcapng" magic number we know about. */
- if (first_block) {
- /* Not a pcap-ng file. */
- return 0;
- }
-
- /* A bad block */
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_section_header_block: unknown byte-order magic number 0x%08x", shb.magic);
+ return -1;
+ }
+ block_read = bytes_read;
+
+ /* is the magic number one we expect? */
+ switch (shb.magic) {
+ case(0x1A2B3C4D):
+ /* this seems pcapng with correct byte order */
+ pn->byte_swapped = FALSE;
+ pn->version_major = shb.version_major;
+ pn->version_minor = shb.version_minor;
+
+ pcapng_debug3("pcapng_read_section_header_block: SHB (little endian) V%u.%u, len %u",
+ pn->version_major, pn->version_minor, bh->block_total_length);
+ break;
+ case(0x4D3C2B1A):
+ /* this seems pcapng with swapped byte order */
+ pn->byte_swapped = TRUE;
+ pn->version_major = GUINT16_SWAP_LE_BE(shb.version_major);
+ pn->version_minor = GUINT16_SWAP_LE_BE(shb.version_minor);
+
+ /* tweak the block length to meet current swapping that we know now */
+ bh->block_total_length = GUINT32_SWAP_LE_BE(bh->block_total_length);
+
+ pcapng_debug3("pcapng_read_section_header_block: SHB (big endian) V%u.%u, len %u",
+ pn->version_major, pn->version_minor, bh->block_total_length);
+ break;
+ default:
+ /* Not a "pcapng" magic number we know about. */
+ if (first_block) {
+ /* Not a pcap-ng file. */
return 0;
- }
+ }
- /* OK, at this point we assume it's a pcap-ng file.
+ /* A bad block */
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_section_header_block: unknown byte-order magic number 0x%08x", shb.magic);
+ return 0;
+ }
- Don't try to allocate memory for a huge number of options, as
- that might fail and, even if it succeeds, it might not leave
- any address space or memory+backing store for anything else.
+ /* OK, at this point we assume it's a pcap-ng file.
+
+ Don't try to allocate memory for a huge number of options, as
+ that might fail and, even if it succeeds, it might not leave
+ any address space or memory+backing store for anything else.
+
+ We do that by imposing a maximum block size of MAX_BLOCK_SIZE.
+ We check for this *after* checking the SHB for its byte
+ order magic number, so that non-pcap-ng files are less
+ likely to be treated as bad pcap-ng files. */
+ if (bh->block_total_length > MAX_BLOCK_SIZE) {
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng: total block length %u is too large (> %u)",
+ bh->block_total_length, MAX_BLOCK_SIZE);
+ return -1;
+ }
- We do that by imposing a maximum block size of MAX_BLOCK_SIZE.
- We check for this *after* checking the SHB for its byte
- order magic number, so that non-pcap-ng files are less
- likely to be treated as bad pcap-ng files. */
- if (bh->block_total_length > MAX_BLOCK_SIZE) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng: total block length %u is too large (> %u)",
- bh->block_total_length, MAX_BLOCK_SIZE);
- return -1;
- }
+ /* We currently only suport one SHB */
+ if (pn->shb_read == TRUE) {
+ *err = WTAP_ERR_UNSUPPORTED;
+ *err_info = g_strdup_printf("pcapng: multiple section header blocks not supported");
+ return 0;
+ }
- /* We currently only suport one SHB */
- if (pn->shb_read == TRUE) {
- *err = WTAP_ERR_UNSUPPORTED;
- *err_info = g_strdup_printf("pcapng: multiple section header blocks not supported");
- return 0;
- }
+ /* we currently only understand SHB V1.0 */
+ if (pn->version_major != 1 || pn->version_minor > 0) {
+ *err = WTAP_ERR_UNSUPPORTED;
+ *err_info = g_strdup_printf("pcapng_read_section_header_block: unknown SHB version %u.%u",
+ pn->version_major, pn->version_minor);
+ return -1;
+ }
- /* we currently only understand SHB V1.0 */
- if (pn->version_major != 1 || pn->version_minor > 0) {
- *err = WTAP_ERR_UNSUPPORTED;
- *err_info = g_strdup_printf("pcapng_read_section_header_block: unknown SHB version %u.%u",
- pn->version_major, pn->version_minor);
- return -1;
- }
+ /* 64bit section_length (currently unused) */
+ if (pn->byte_swapped) {
+ wblock->data.section.section_length = GUINT64_SWAP_LE_BE(shb.section_length);
+ } else {
+ wblock->data.section.section_length = shb.section_length;
+ }
- /* 64bit section_length (currently unused) */
- if (pn->byte_swapped) {
- wblock->data.section.section_length = GUINT64_SWAP_LE_BE(shb.section_length);
- } else {
- wblock->data.section.section_length = shb.section_length;
+ /* Option defaults */
+ wblock->data.section.opt_comment = NULL;
+ wblock->data.section.shb_hardware = NULL;
+ wblock->data.section.shb_os = NULL;
+ wblock->data.section.shb_user_appl = NULL;
+
+ /* Options */
+ errno = WTAP_ERR_CANT_READ;
+ to_read = bh->block_total_length - MIN_SHB_SIZE;
+
+ /* Allocate enough memory to hold all options */
+ opt_cont_buf_len = to_read;
+ option_content = (char *)g_try_malloc(opt_cont_buf_len);
+ if (opt_cont_buf_len != 0 && option_content == NULL) {
+ *err = ENOMEM; /* we assume we're out of memory */
+ return -1;
+ }
+ pcapng_debug1("pcapng_read_section_header_block: Options %u bytes", to_read);
+ while (to_read != 0) {
+ /* read option */
+ pcapng_debug1("pcapng_read_section_header_block: Options %u bytes remaining", to_read);
+ bytes_read = pcapng_read_option(fh, pn, &oh, option_content, opt_cont_buf_len, to_read, err, err_info);
+ if (bytes_read <= 0) {
+ pcapng_debug0("pcapng_read_section_header_block: failed to read option");
+ return bytes_read;
}
+ block_read += bytes_read;
+ to_read -= bytes_read;
- /* Option defaults */
- wblock->data.section.opt_comment = NULL;
- wblock->data.section.shb_hardware = NULL;
- wblock->data.section.shb_os = NULL;
- wblock->data.section.shb_user_appl = NULL;
-
- /* Options */
- errno = WTAP_ERR_CANT_READ;
- to_read = bh->block_total_length - MIN_SHB_SIZE;
-
- /* Allocate enough memory to hold all options */
- opt_cont_buf_len = to_read;
- option_content = (char *)g_try_malloc(opt_cont_buf_len);
- if (opt_cont_buf_len != 0 && option_content == NULL) {
- *err = ENOMEM; /* we assume we're out of memory */
- return -1;
- }
- pcapng_debug1("pcapng_read_section_header_block: Options %u bytes", to_read);
- while (to_read != 0) {
- /* read option */
- pcapng_debug1("pcapng_read_section_header_block: Options %u bytes remaining", to_read);
- bytes_read = pcapng_read_option(fh, pn, &oh, option_content, opt_cont_buf_len, to_read, err, err_info);
- if (bytes_read <= 0) {
- pcapng_debug0("pcapng_read_section_header_block: failed to read option");
- return bytes_read;
+ /* handle option content */
+ switch (oh.option_code) {
+ case(OPT_EOFOPT):
+ if (to_read != 0) {
+ pcapng_debug1("pcapng_read_section_header_block: %u bytes after opt_endofopt", to_read);
}
- block_read += bytes_read;
- to_read -= bytes_read;
-
- /* handle option content */
- switch (oh.option_code) {
- case(OPT_EOFOPT):
- if (to_read != 0) {
- pcapng_debug1("pcapng_read_section_header_block: %u bytes after opt_endofopt", to_read);
- }
- /* padding should be ok here, just get out of this */
- to_read = 0;
- break;
- case(OPT_COMMENT):
- if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
- wblock->data.section.opt_comment = g_strndup(option_content, oh.option_length);
- pcapng_debug1("pcapng_read_section_header_block: opt_comment %s", wblock->data.section.opt_comment);
- } else {
- pcapng_debug1("pcapng_read_section_header_block: opt_comment length %u seems strange", oh.option_length);
- }
- break;
- case(OPT_SHB_HARDWARE):
- if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
- wblock->data.section.shb_hardware = g_strndup(option_content, oh.option_length);
- pcapng_debug1("pcapng_read_section_header_block: shb_hardware %s", wblock->data.section.shb_hardware);
- } else {
- pcapng_debug1("pcapng_read_section_header_block: shb_hardware length %u seems strange", oh.option_length);
- }
- break;
- case(OPT_SHB_OS):
- if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
- wblock->data.section.shb_os = g_strndup(option_content, oh.option_length);
- pcapng_debug1("pcapng_read_section_header_block: shb_os %s", wblock->data.section.shb_os);
- } else {
- pcapng_debug2("pcapng_read_section_header_block: shb_os length %u seems strange, opt buffsize %u", oh.option_length,to_read);
- }
- break;
- case(OPT_SHB_USERAPPL):
- if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
- wblock->data.section.shb_user_appl = g_strndup(option_content, oh.option_length);
- pcapng_debug1("pcapng_read_section_header_block: shb_user_appl %s", wblock->data.section.shb_user_appl);
- } else {
- pcapng_debug1("pcapng_read_section_header_block: shb_user_appl length %u seems strange", oh.option_length);
- }
- break;
- default:
- pcapng_debug2("pcapng_read_section_header_block: unknown option %u - ignoring %u bytes",
- oh.option_code, oh.option_length);
+ /* padding should be ok here, just get out of this */
+ to_read = 0;
+ break;
+ case(OPT_COMMENT):
+ if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
+ wblock->data.section.opt_comment = g_strndup(option_content, oh.option_length);
+ pcapng_debug1("pcapng_read_section_header_block: opt_comment %s", wblock->data.section.opt_comment);
+ } else {
+ pcapng_debug1("pcapng_read_section_header_block: opt_comment length %u seems strange", oh.option_length);
}
+ break;
+ case(OPT_SHB_HARDWARE):
+ if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
+ wblock->data.section.shb_hardware = g_strndup(option_content, oh.option_length);
+ pcapng_debug1("pcapng_read_section_header_block: shb_hardware %s", wblock->data.section.shb_hardware);
+ } else {
+ pcapng_debug1("pcapng_read_section_header_block: shb_hardware length %u seems strange", oh.option_length);
+ }
+ break;
+ case(OPT_SHB_OS):
+ if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
+ wblock->data.section.shb_os = g_strndup(option_content, oh.option_length);
+ pcapng_debug1("pcapng_read_section_header_block: shb_os %s", wblock->data.section.shb_os);
+ } else {
+ pcapng_debug2("pcapng_read_section_header_block: shb_os length %u seems strange, opt buffsize %u", oh.option_length,to_read);
+ }
+ break;
+ case(OPT_SHB_USERAPPL):
+ if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
+ wblock->data.section.shb_user_appl = g_strndup(option_content, oh.option_length);
+ pcapng_debug1("pcapng_read_section_header_block: shb_user_appl %s", wblock->data.section.shb_user_appl);
+ } else {
+ pcapng_debug1("pcapng_read_section_header_block: shb_user_appl length %u seems strange", oh.option_length);
+ }
+ break;
+ default:
+ pcapng_debug2("pcapng_read_section_header_block: unknown option %u - ignoring %u bytes",
+ oh.option_code, oh.option_length);
}
- g_free(option_content);
+ }
+ g_free(option_content);
- return block_read;
+ return block_read;
}
@@ -710,787 +710,787 @@ static int
pcapng_read_if_descr_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn,
wtapng_block_t *wblock, int *err, gchar **err_info)
{
- guint64 time_units_per_second = 1000000; /* default */
- int bytes_read;
- guint block_read;
- guint to_read, opt_cont_buf_len;
- pcapng_interface_description_block_t idb;
- pcapng_option_header_t oh;
- char *option_content = NULL; /* Allocate as large as the options block */
-
+ guint64 time_units_per_second = 1000000; /* default */
+ int bytes_read;
+ guint block_read;
+ guint to_read, opt_cont_buf_len;
+ pcapng_interface_description_block_t idb;
+ pcapng_option_header_t oh;
+ char *option_content = NULL; /* Allocate as large as the options block */
+
+ /*
+ * Is this block long enough to be an IDB?
+ */
+ if (bh->block_total_length < MIN_IDB_SIZE) {
/*
- * Is this block long enough to be an IDB?
+ * No.
*/
- if (bh->block_total_length < MIN_IDB_SIZE) {
- /*
- * No.
- */
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_if_descr_block: total block length %u of an IDB is less than the minimum IDB size %u",
- bh->block_total_length, MIN_IDB_SIZE);
- return -1;
- }
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_if_descr_block: total block length %u of an IDB is less than the minimum IDB size %u",
+ bh->block_total_length, MIN_IDB_SIZE);
+ return -1;
+ }
- /* Don't try to allocate memory for a huge number of options, as
- that might fail and, even if it succeeds, it might not leave
- any address space or memory+backing store for anything else.
-
- We do that by imposing a maximum block size of MAX_BLOCK_SIZE.
- We check for this *after* checking the SHB for its byte
- order magic number, so that non-pcap-ng files are less
- likely to be treated as bad pcap-ng files. */
- if (bh->block_total_length > MAX_BLOCK_SIZE) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng: total block length %u is too large (> %u)",
- bh->block_total_length, MAX_BLOCK_SIZE);
- return -1;
- }
+ /* Don't try to allocate memory for a huge number of options, as
+ that might fail and, even if it succeeds, it might not leave
+ any address space or memory+backing store for anything else.
+
+ We do that by imposing a maximum block size of MAX_BLOCK_SIZE.
+ We check for this *after* checking the SHB for its byte
+ order magic number, so that non-pcap-ng files are less
+ likely to be treated as bad pcap-ng files. */
+ if (bh->block_total_length > MAX_BLOCK_SIZE) {
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng: total block length %u is too large (> %u)",
+ bh->block_total_length, MAX_BLOCK_SIZE);
+ return -1;
+ }
- /* read block content */
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(&idb, sizeof idb, fh);
- if (bytes_read != sizeof idb) {
- pcapng_debug0("pcapng_read_if_descr_block: failed to read IDB");
- *err = file_error(fh, err_info);
- if (*err != 0)
- return -1;
- return 0;
- }
- block_read = bytes_read;
+ /* read block content */
+ errno = WTAP_ERR_CANT_READ;
+ bytes_read = file_read(&idb, sizeof idb, fh);
+ if (bytes_read != sizeof idb) {
+ pcapng_debug0("pcapng_read_if_descr_block: failed to read IDB");
+ *err = file_error(fh, err_info);
+ if (*err != 0)
+ return -1;
+ return 0;
+ }
+ block_read = bytes_read;
+
+ /* mandatory values */
+ if (pn->byte_swapped) {
+ wblock->data.if_descr.link_type = GUINT16_SWAP_LE_BE(idb.linktype);
+ wblock->data.if_descr.snap_len = GUINT32_SWAP_LE_BE(idb.snaplen);
+ } else {
+ wblock->data.if_descr.link_type = idb.linktype;
+ wblock->data.if_descr.snap_len = idb.snaplen;
+ }
- /* mandatory values */
- if (pn->byte_swapped) {
- wblock->data.if_descr.link_type = GUINT16_SWAP_LE_BE(idb.linktype);
- wblock->data.if_descr.snap_len = GUINT32_SWAP_LE_BE(idb.snaplen);
- } else {
- wblock->data.if_descr.link_type = idb.linktype;
- wblock->data.if_descr.snap_len = idb.snaplen;
- }
+ wblock->data.if_descr.wtap_encap = wtap_pcap_encap_to_wtap_encap(wblock->data.if_descr.link_type);
+ wblock->data.if_descr.time_units_per_second = time_units_per_second;
- wblock->data.if_descr.wtap_encap = wtap_pcap_encap_to_wtap_encap(wblock->data.if_descr.link_type);
- wblock->data.if_descr.time_units_per_second = time_units_per_second;
+ pcapng_debug3("pcapng_read_if_descr_block: IDB link_type %u (%s), snap %u",
+ wblock->data.if_descr.link_type,
+ wtap_encap_string(wblock->data.if_descr.wtap_encap),
+ wblock->data.if_descr.snap_len);
- pcapng_debug3("pcapng_read_if_descr_block: IDB link_type %u (%s), snap %u",
- wblock->data.if_descr.link_type,
- wtap_encap_string(wblock->data.if_descr.wtap_encap),
+ if (wblock->data.if_descr.snap_len > WTAP_MAX_PACKET_SIZE) {
+ /* This is unrealistic, but text2pcap currently uses 102400.
+ * We do not use this value, maybe we should check the
+ * snap_len of the packets against it. For now, only warn.
+ */
+ pcapng_debug1("pcapng_read_if_descr_block: snapshot length %u unrealistic.",
wblock->data.if_descr.snap_len);
+ /*wblock->data.if_descr.snap_len = WTAP_MAX_PACKET_SIZE;*/
+ }
- if (wblock->data.if_descr.snap_len > WTAP_MAX_PACKET_SIZE) {
- /* This is unrealistic, but text2pcap currently uses 102400.
- * We do not use this value, maybe we should check the
- * snap_len of the packets against it. For now, only warn.
- */
- pcapng_debug1("pcapng_read_if_descr_block: snapshot length %u unrealistic.",
- wblock->data.if_descr.snap_len);
- /*wblock->data.if_descr.snap_len = WTAP_MAX_PACKET_SIZE;*/
+ /* Option defaults */
+ wblock->data.if_descr.opt_comment = NULL;
+ wblock->data.if_descr.if_name = NULL;
+ wblock->data.if_descr.if_description = NULL;
+ /* XXX: if_IPv4addr */
+ /* XXX: if_IPv6addr */
+ /* XXX: if_MACaddr */
+ /* XXX: if_EUIaddr */
+ wblock->data.if_descr.if_speed = 0; /* "unknown" */
+ wblock->data.if_descr.if_tsresol = 6; /* default is 6 for microsecond resolution */
+ wblock->data.if_descr.if_filter_str = NULL;
+ wblock->data.if_descr.bpf_filter_len = 0;
+ wblock->data.if_descr.if_filter_bpf_bytes = NULL;
+ wblock->data.if_descr.if_os = NULL;
+ wblock->data.if_descr.if_fcslen = -1; /* unknown or changes between packets */
+ /* XXX: guint64 if_tsoffset; */
+
+
+ /* Options */
+ errno = WTAP_ERR_CANT_READ;
+ to_read = bh->block_total_length - MIN_IDB_SIZE;
+
+ /* Allocate enough memory to hold all options */
+ opt_cont_buf_len = to_read;
+ option_content = (char *)g_try_malloc(opt_cont_buf_len);
+ if (opt_cont_buf_len != 0 && option_content == NULL) {
+ *err = ENOMEM; /* we assume we're out of memory */
+ return -1;
+ }
+
+ while (to_read != 0) {
+ /* read option */
+ bytes_read = pcapng_read_option(fh, pn, &oh, option_content, opt_cont_buf_len, to_read, err, err_info);
+ if (bytes_read <= 0) {
+ pcapng_debug0("pcapng_read_if_descr_block: failed to read option");
+ return bytes_read;
}
+ block_read += bytes_read;
+ to_read -= bytes_read;
- /* Option defaults */
- wblock->data.if_descr.opt_comment = NULL;
- wblock->data.if_descr.if_name = NULL;
- wblock->data.if_descr.if_description = NULL;
- /* XXX: if_IPv4addr */
- /* XXX: if_IPv6addr */
- /* XXX: if_MACaddr */
- /* XXX: if_EUIaddr */
- wblock->data.if_descr.if_speed = 0; /* "unknown" */
- wblock->data.if_descr.if_tsresol = 6; /* default is 6 for microsecond resolution */
- wblock->data.if_descr.if_filter_str = NULL;
- wblock->data.if_descr.bpf_filter_len = 0;
- wblock->data.if_descr.if_filter_bpf_bytes = NULL;
- wblock->data.if_descr.if_os = NULL;
- wblock->data.if_descr.if_fcslen = -1; /* unknown or changes between packets */
- /* XXX: guint64 if_tsoffset; */
-
-
- /* Options */
- errno = WTAP_ERR_CANT_READ;
- to_read = bh->block_total_length - MIN_IDB_SIZE;
-
- /* Allocate enough memory to hold all options */
- opt_cont_buf_len = to_read;
- option_content = (char *)g_try_malloc(opt_cont_buf_len);
- if (opt_cont_buf_len != 0 && option_content == NULL) {
- *err = ENOMEM; /* we assume we're out of memory */
- return -1;
- }
-
- while (to_read != 0) {
- /* read option */
- bytes_read = pcapng_read_option(fh, pn, &oh, option_content, opt_cont_buf_len, to_read, err, err_info);
- if (bytes_read <= 0) {
- pcapng_debug0("pcapng_read_if_descr_block: failed to read option");
- return bytes_read;
+ /* handle option content */
+ switch (oh.option_code) {
+ case(0): /* opt_endofopt */
+ if (to_read != 0) {
+ pcapng_debug1("pcapng_read_if_descr_block: %u bytes after opt_endofopt", to_read);
}
- block_read += bytes_read;
- to_read -= bytes_read;
-
- /* handle option content */
- switch (oh.option_code) {
- case(0): /* opt_endofopt */
- if (to_read != 0) {
- pcapng_debug1("pcapng_read_if_descr_block: %u bytes after opt_endofopt", to_read);
- }
- /* padding should be ok here, just get out of this */
- to_read = 0;
- break;
- case(1): /* opt_comment */
- if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
- wblock->data.if_descr.opt_comment = g_strndup(option_content, oh.option_length);
- pcapng_debug1("pcapng_read_if_descr_block: opt_comment %s", wblock->data.if_descr.opt_comment);
- } else {
- pcapng_debug1("pcapng_read_if_descr_block: opt_comment length %u seems strange", oh.option_length);
- }
- break;
- case(2): /* if_name */
- if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
- wblock->data.if_descr.if_name = g_strndup(option_content, oh.option_length);
- pcapng_debug1("pcapng_read_if_descr_block: if_name %s", wblock->data.if_descr.if_name);
- } else {
- pcapng_debug1("pcapng_read_if_descr_block: if_name length %u seems strange", oh.option_length);
- }
- break;
- case(3): /* if_description */
- if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
- wblock->data.if_descr.if_description = g_strndup(option_content, oh.option_length);
- pcapng_debug1("pcapng_read_if_descr_block: if_description %s", wblock->data.if_descr.if_description);
- } else {
- pcapng_debug1("pcapng_read_if_descr_block: if_description length %u seems strange", oh.option_length);
- }
- break;
- /*
- * if_IPv4addr 4 Interface network address and netmask. This option can be repeated multiple times within the same Interface Description Block when multiple IPv4 addresses are assigned to the interface. 192 168 1 1 255 255 255 0
- * if_IPv6addr 5 Interface network address and prefix length (stored in the last byte). This option can be repeated multiple times within the same Interface Description Block when multiple IPv6 addresses are assigned to the interface. 2001:0db8:85a3:08d3:1319:8a2e:0370:7344/64 is written (in hex) as "20 01 0d b8 85 a3 08 d3 13 19 8a 2e 03 70 73 44 40"
- * if_MACaddr 6 Interface Hardware MAC address (48 bits). 00 01 02 03 04 05
- * if_EUIaddr 7 Interface Hardware EUI address (64 bits), if available. TODO: give a good example
- */
- case(8): /* if_speed */
- if (oh.option_length == 8) {
- /* Don't cast a char[] into a guint64--the
- * char[] may not be aligned correctly.
- */
- memcpy(&wblock->data.if_descr.if_speed, option_content, sizeof(guint64));
- if (pn->byte_swapped)
- wblock->data.if_descr.if_speed = GUINT64_SWAP_LE_BE(wblock->data.if_descr.if_speed);
- pcapng_debug1("pcapng_read_if_descr_block: if_speed %" G_GINT64_MODIFIER "u (bps)", wblock->data.if_descr.if_speed);
- } else {
- pcapng_debug1("pcapng_read_if_descr_block: if_speed length %u not 8 as expected", oh.option_length);
- }
- break;
- case(9): /* if_tsresol */
- if (oh.option_length == 1) {
- guint64 base;
- guint64 result;
- guint8 i, exponent, if_tsresol;
-
- if_tsresol = option_content[0];
- if (if_tsresol & 0x80) {
- base = 2;
- } else {
- base = 10;
- }
- exponent = (guint8)(if_tsresol & 0x7f);
- if (((base == 2) && (exponent < 64)) || ((base == 10) && (exponent < 20))) {
- result = 1;
- for (i = 0; i < exponent; i++) {
- result *= base;
- }
- time_units_per_second = result;
- } else {
- time_units_per_second = G_MAXUINT64;
- }
- if (time_units_per_second > (((guint64)1) << 32)) {
- pcapng_debug0("pcapng_open: time conversion might be inaccurate");
- }
- wblock->data.if_descr.time_units_per_second = time_units_per_second;
- wblock->data.if_descr.if_tsresol = if_tsresol;
- pcapng_debug2("pcapng_read_if_descr_block: if_tsresol %u, units/s %" G_GINT64_MODIFIER "u", wblock->data.if_descr.if_tsresol, wblock->data.if_descr.time_units_per_second);
- } else {
- pcapng_debug1("pcapng_read_if_descr_block: if_tsresol length %u not 1 as expected", oh.option_length);
- }
- break;
- /*
- * if_tzone 10 Time zone for GMT support (TODO: specify better). TODO: give a good example
- */
- case(11): /* if_filter */
- if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
- /* The first byte of the Option Data keeps a code of the filter used (e.g. if this is a libpcap string,
- * or BPF bytecode.
- */
- if (option_content[0] == 0) {
- wblock->data.if_descr.if_filter_str = g_strndup(option_content+1, oh.option_length-1);
- pcapng_debug2("pcapng_read_if_descr_block: if_filter_str %s oh.option_length %u", wblock->data.if_descr.if_filter_str, oh.option_length);
- } else if (option_content[0] == 1) {
- wblock->data.if_descr.bpf_filter_len = oh.option_length-1;
- wblock->data.if_descr.if_filter_bpf_bytes = (gchar *)g_malloc(oh.option_length-1);
- memcpy(&wblock->data.if_descr.if_filter_bpf_bytes, option_content+1, oh.option_length-1);
- }
- } else {
- pcapng_debug1("pcapng_read_if_descr_block: if_filter length %u seems strange", oh.option_length);
- }
- break;
- case(12): /* if_os */
- /*
- * if_os 12 A UTF-8 string containing the name of the operating system of the machine in which this interface is installed.
- * This can be different from the same information that can be contained by the Section Header Block (Section 3.1 (Section Header Block (mandatory)))
- * because the capture can have been done on a remote machine. "Windows XP SP2" / "openSUSE 10.2" / ...
- */
- if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
- wblock->data.if_descr.if_os = g_strndup(option_content, oh.option_length);
- pcapng_debug1("pcapng_read_if_descr_block: if_os %s", wblock->data.if_descr.if_os);
- } else {
- pcapng_debug1("pcapng_read_if_descr_block: if_os length %u seems strange", oh.option_length);
- }
- break;
- case(13): /* if_fcslen */
- if (oh.option_length == 1) {
- wblock->data.if_descr.if_fcslen = option_content[0];
- pn->if_fcslen = wblock->data.if_descr.if_fcslen;
- pcapng_debug1("pcapng_read_if_descr_block: if_fcslen %u", wblock->data.if_descr.if_fcslen);
- /* XXX - add sanity check */
- } else {
- pcapng_debug1("pcapng_read_if_descr_block: if_fcslen length %u not 1 as expected", oh.option_length);
- }
- break;
- /*
- * if_tsoffset 14 A 64 bits integer value that specifies an offset (in seconds) that must be added to the timestamp of each packet
- * to obtain the absolute timestamp of a packet. If the option is missing, the timestamps stored in the packet must be considered absolute timestamps.
- * The time zone of the offset can be specified with the option if_tzone.
- * TODO: won't a if_tsoffset_low for fractional second offsets be useful for highly synchronized capture systems? 1234
- */
- default:
- pcapng_debug2("pcapng_read_if_descr_block: unknown option %u - ignoring %u bytes",
- oh.option_code, oh.option_length);
+ /* padding should be ok here, just get out of this */
+ to_read = 0;
+ break;
+ case(1): /* opt_comment */
+ if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
+ wblock->data.if_descr.opt_comment = g_strndup(option_content, oh.option_length);
+ pcapng_debug1("pcapng_read_if_descr_block: opt_comment %s", wblock->data.if_descr.opt_comment);
+ } else {
+ pcapng_debug1("pcapng_read_if_descr_block: opt_comment length %u seems strange", oh.option_length);
}
- }
-
- g_free(option_content);
-
- if (*wblock->file_encap == WTAP_ENCAP_UNKNOWN) {
- *wblock->file_encap = wblock->data.if_descr.wtap_encap;
- } else {
- if (*wblock->file_encap != wblock->data.if_descr.wtap_encap) {
- *wblock->file_encap = WTAP_ENCAP_PER_PACKET;
+ break;
+ case(2): /* if_name */
+ if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
+ wblock->data.if_descr.if_name = g_strndup(option_content, oh.option_length);
+ pcapng_debug1("pcapng_read_if_descr_block: if_name %s", wblock->data.if_descr.if_name);
+ } else {
+ pcapng_debug1("pcapng_read_if_descr_block: if_name length %u seems strange", oh.option_length);
}
- }
-
- return block_read;
-}
-
-
-static int
-pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wtapng_block_t *wblock, int *err, gchar **err_info, gboolean enhanced)
-{
- int bytes_read;
- guint block_read;
- guint to_read, opt_cont_buf_len;
- guint64 file_offset64;
- pcapng_enhanced_packet_block_t epb;
- pcapng_packet_block_t pb;
- wtapng_packet_t packet;
- guint32 block_total_length;
- guint32 padding;
- interface_info_t iface_info;
- guint64 ts;
- pcapng_option_header_t oh;
- int pseudo_header_len;
- char *option_content = NULL; /* Allocate as large as the options block */
- int fcslen;
-
- /* Don't try to allocate memory for a huge number of options, as
- that might fail and, even if it succeeds, it might not leave
- any address space or memory+backing store for anything else.
-
- We do that by imposing a maximum block size of MAX_BLOCK_SIZE.
- We check for this *after* checking the SHB for its byte
- order magic number, so that non-pcap-ng files are less
- likely to be treated as bad pcap-ng files. */
- if (bh->block_total_length > MAX_BLOCK_SIZE) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng: total block length %u is too large (> %u)",
- bh->block_total_length, MAX_BLOCK_SIZE);
- return -1;
- }
-
- /* "(Enhanced) Packet Block" read fixed part */
- errno = WTAP_ERR_CANT_READ;
- if (enhanced) {
+ break;
+ case(3): /* if_description */
+ if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
+ wblock->data.if_descr.if_description = g_strndup(option_content, oh.option_length);
+ pcapng_debug1("pcapng_read_if_descr_block: if_description %s", wblock->data.if_descr.if_description);
+ } else {
+ pcapng_debug1("pcapng_read_if_descr_block: if_description length %u seems strange", oh.option_length);
+ }
+ break;
/*
- * Is this block long enough to be an EPB?
+ * if_IPv4addr 4 Interface network address and netmask. This option can be repeated multiple times within the same Interface Description Block when multiple IPv4 addresses are assigned to the interface. 192 168 1 1 255 255 255 0
+ * if_IPv6addr 5 Interface network address and prefix length (stored in the last byte). This option can be repeated multiple times within the same Interface Description Block when multiple IPv6 addresses are assigned to the interface. 2001:0db8:85a3:08d3:1319:8a2e:0370:7344/64 is written (in hex) as "20 01 0d b8 85 a3 08 d3 13 19 8a 2e 03 70 73 44 40"
+ * if_MACaddr 6 Interface Hardware MAC address (48 bits). 00 01 02 03 04 05
+ * if_EUIaddr 7 Interface Hardware EUI address (64 bits), if available. TODO: give a good example
*/
- if (bh->block_total_length < MIN_EPB_SIZE) {
- /*
- * No.
- */
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_packet_block: total block length %u of an EPB is less than the minimum EPB size %u",
- bh->block_total_length, MIN_EPB_SIZE);
- return -1;
- }
- bytes_read = file_read(&epb, sizeof epb, fh);
- if (bytes_read != sizeof epb) {
- pcapng_debug0("pcapng_read_packet_block: failed to read packet data");
- *err = file_error(fh, err_info);
- return 0;
+ case(8): /* if_speed */
+ if (oh.option_length == 8) {
+ /* Don't cast a char[] into a guint64--the
+ * char[] may not be aligned correctly.
+ */
+ memcpy(&wblock->data.if_descr.if_speed, option_content, sizeof(guint64));
+ if (pn->byte_swapped)
+ wblock->data.if_descr.if_speed = GUINT64_SWAP_LE_BE(wblock->data.if_descr.if_speed);
+ pcapng_debug1("pcapng_read_if_descr_block: if_speed %" G_GINT64_MODIFIER "u (bps)", wblock->data.if_descr.if_speed);
+ } else {
+ pcapng_debug1("pcapng_read_if_descr_block: if_speed length %u not 8 as expected", oh.option_length);
}
- block_read = bytes_read;
-
- if (pn->byte_swapped) {
- packet.interface_id = GUINT32_SWAP_LE_BE(epb.interface_id);
- packet.drops_count = -1; /* invalid */
- packet.ts_high = GUINT32_SWAP_LE_BE(epb.timestamp_high);
- packet.ts_low = GUINT32_SWAP_LE_BE(epb.timestamp_low);
- packet.cap_len = GUINT32_SWAP_LE_BE(epb.captured_len);
- packet.packet_len = GUINT32_SWAP_LE_BE(epb.packet_len);
+ break;
+ case(9): /* if_tsresol */
+ if (oh.option_length == 1) {
+ guint64 base;
+ guint64 result;
+ guint8 i, exponent, if_tsresol;
+
+ if_tsresol = option_content[0];
+ if (if_tsresol & 0x80) {
+ base = 2;
+ } else {
+ base = 10;
+ }
+ exponent = (guint8)(if_tsresol & 0x7f);
+ if (((base == 2) && (exponent < 64)) || ((base == 10) && (exponent < 20))) {
+ result = 1;
+ for (i = 0; i < exponent; i++) {
+ result *= base;
+ }
+ time_units_per_second = result;
+ } else {
+ time_units_per_second = G_MAXUINT64;
+ }
+ if (time_units_per_second > (((guint64)1) << 32)) {
+ pcapng_debug0("pcapng_open: time conversion might be inaccurate");
+ }
+ wblock->data.if_descr.time_units_per_second = time_units_per_second;
+ wblock->data.if_descr.if_tsresol = if_tsresol;
+ pcapng_debug2("pcapng_read_if_descr_block: if_tsresol %u, units/s %" G_GINT64_MODIFIER "u", wblock->data.if_descr.if_tsresol, wblock->data.if_descr.time_units_per_second);
} else {
- packet.interface_id = epb.interface_id;
- packet.drops_count = -1; /* invalid */
- packet.ts_high = epb.timestamp_high;
- packet.ts_low = epb.timestamp_low;
- packet.cap_len = epb.captured_len;
- packet.packet_len = epb.packet_len;
+ pcapng_debug1("pcapng_read_if_descr_block: if_tsresol length %u not 1 as expected", oh.option_length);
}
- pcapng_debug3("pcapng_read_packet_block: EPB on interface_id %d, cap_len %d, packet_len %d",
- packet.interface_id, packet.cap_len, packet.packet_len);
- } else {
+ break;
/*
- * Is this block long enough to be a PB?
+ * if_tzone 10 Time zone for GMT support (TODO: specify better). TODO: give a good example
*/
- if (bh->block_total_length < MIN_PB_SIZE) {
- /*
- * No.
- */
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_packet_block: total block length %u of a PB is less than the minimum PB size %u",
- bh->block_total_length, MIN_PB_SIZE);
- return -1;
+ case(11): /* if_filter */
+ if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
+ /* The first byte of the Option Data keeps a code of the filter used (e.g. if this is a libpcap string,
+ * or BPF bytecode.
+ */
+ if (option_content[0] == 0) {
+ wblock->data.if_descr.if_filter_str = g_strndup(option_content+1, oh.option_length-1);
+ pcapng_debug2("pcapng_read_if_descr_block: if_filter_str %s oh.option_length %u", wblock->data.if_descr.if_filter_str, oh.option_length);
+ } else if (option_content[0] == 1) {
+ wblock->data.if_descr.bpf_filter_len = oh.option_length-1;
+ wblock->data.if_descr.if_filter_bpf_bytes = (gchar *)g_malloc(oh.option_length-1);
+ memcpy(&wblock->data.if_descr.if_filter_bpf_bytes, option_content+1, oh.option_length-1);
+ }
+ } else {
+ pcapng_debug1("pcapng_read_if_descr_block: if_filter length %u seems strange", oh.option_length);
}
- bytes_read = file_read(&pb, sizeof pb, fh);
- if (bytes_read != sizeof pb) {
- pcapng_debug0("pcapng_read_packet_block: failed to read packet data");
- *err = file_error(fh, err_info);
- return 0;
+ break;
+ case(12): /* if_os */
+ /*
+ * if_os 12 A UTF-8 string containing the name of the operating system of the machine in which this interface is installed.
+ * This can be different from the same information that can be contained by the Section Header Block (Section 3.1 (Section Header Block (mandatory)))
+ * because the capture can have been done on a remote machine. "Windows XP SP2" / "openSUSE 10.2" / ...
+ */
+ if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
+ wblock->data.if_descr.if_os = g_strndup(option_content, oh.option_length);
+ pcapng_debug1("pcapng_read_if_descr_block: if_os %s", wblock->data.if_descr.if_os);
+ } else {
+ pcapng_debug1("pcapng_read_if_descr_block: if_os length %u seems strange", oh.option_length);
}
- block_read = bytes_read;
-
- if (pn->byte_swapped) {
- packet.interface_id = GUINT16_SWAP_LE_BE(pb.interface_id);
- packet.drops_count = GUINT16_SWAP_LE_BE(pb.drops_count);
- packet.ts_high = GUINT32_SWAP_LE_BE(pb.timestamp_high);
- packet.ts_low = GUINT32_SWAP_LE_BE(pb.timestamp_low);
- packet.cap_len = GUINT32_SWAP_LE_BE(pb.captured_len);
- packet.packet_len = GUINT32_SWAP_LE_BE(pb.packet_len);
+ break;
+ case(13): /* if_fcslen */
+ if (oh.option_length == 1) {
+ wblock->data.if_descr.if_fcslen = option_content[0];
+ pn->if_fcslen = wblock->data.if_descr.if_fcslen;
+ pcapng_debug1("pcapng_read_if_descr_block: if_fcslen %u", wblock->data.if_descr.if_fcslen);
+ /* XXX - add sanity check */
} else {
- packet.interface_id = pb.interface_id;
- packet.drops_count = pb.drops_count;
- packet.ts_high = pb.timestamp_high;
- packet.ts_low = pb.timestamp_low;
- packet.cap_len = pb.captured_len;
- packet.packet_len = pb.packet_len;
+ pcapng_debug1("pcapng_read_if_descr_block: if_fcslen length %u not 1 as expected", oh.option_length);
}
- pcapng_debug3("pcapng_read_packet_block: PB on interface_id %d, cap_len %d, packet_len %d",
- packet.interface_id, packet.cap_len, packet.packet_len);
+ break;
+ /*
+ * if_tsoffset 14 A 64 bits integer value that specifies an offset (in seconds) that must be added to the timestamp of each packet
+ * to obtain the absolute timestamp of a packet. If the option is missing, the timestamps stored in the packet must be considered absolute timestamps.
+ * The time zone of the offset can be specified with the option if_tzone.
+ * TODO: won't a if_tsoffset_low for fractional second offsets be useful for highly synchronized capture systems? 1234
+ */
+ default:
+ pcapng_debug2("pcapng_read_if_descr_block: unknown option %u - ignoring %u bytes",
+ oh.option_code, oh.option_length);
}
+ }
+ g_free(option_content);
+
+ if (*wblock->file_encap == WTAP_ENCAP_UNKNOWN) {
+ *wblock->file_encap = wblock->data.if_descr.wtap_encap;
+ } else {
+ if (*wblock->file_encap != wblock->data.if_descr.wtap_encap) {
+ *wblock->file_encap = WTAP_ENCAP_PER_PACKET;
+ }
+ }
+
+ return block_read;
+}
+
+
+static int
+pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wtapng_block_t *wblock, int *err, gchar **err_info, gboolean enhanced)
+{
+ int bytes_read;
+ guint block_read;
+ guint to_read, opt_cont_buf_len;
+ guint64 file_offset64;
+ pcapng_enhanced_packet_block_t epb;
+ pcapng_packet_block_t pb;
+ wtapng_packet_t packet;
+ guint32 block_total_length;
+ guint32 padding;
+ interface_info_t iface_info;
+ guint64 ts;
+ pcapng_option_header_t oh;
+ int pseudo_header_len;
+ char *option_content = NULL; /* Allocate as large as the options block */
+ int fcslen;
+
+ /* Don't try to allocate memory for a huge number of options, as
+ that might fail and, even if it succeeds, it might not leave
+ any address space or memory+backing store for anything else.
+
+ We do that by imposing a maximum block size of MAX_BLOCK_SIZE.
+ We check for this *after* checking the SHB for its byte
+ order magic number, so that non-pcap-ng files are less
+ likely to be treated as bad pcap-ng files. */
+ if (bh->block_total_length > MAX_BLOCK_SIZE) {
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng: total block length %u is too large (> %u)",
+ bh->block_total_length, MAX_BLOCK_SIZE);
+ return -1;
+ }
+
+ /* "(Enhanced) Packet Block" read fixed part */
+ errno = WTAP_ERR_CANT_READ;
+ if (enhanced) {
/*
- * How much padding is there at the end of the packet data?
+ * Is this block long enough to be an EPB?
*/
- if ((packet.cap_len % 4) != 0)
- padding = 4 - (packet.cap_len % 4);
- else
- padding = 0;
-
- /* add padding bytes to "block total length" */
- /* (the "block total length" of some example files don't contain the packet data padding bytes!) */
- if (bh->block_total_length % 4) {
- block_total_length = bh->block_total_length + 4 - (bh->block_total_length % 4);
- } else {
- block_total_length = bh->block_total_length;
+ if (bh->block_total_length < MIN_EPB_SIZE) {
+ /*
+ * No.
+ */
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_packet_block: total block length %u of an EPB is less than the minimum EPB size %u",
+ bh->block_total_length, MIN_EPB_SIZE);
+ return -1;
+ }
+ bytes_read = file_read(&epb, sizeof epb, fh);
+ if (bytes_read != sizeof epb) {
+ pcapng_debug0("pcapng_read_packet_block: failed to read packet data");
+ *err = file_error(fh, err_info);
+ return 0;
}
- pcapng_debug1("pcapng_read_packet_block: block_total_length %d", block_total_length);
+ block_read = bytes_read;
+ if (pn->byte_swapped) {
+ packet.interface_id = GUINT32_SWAP_LE_BE(epb.interface_id);
+ packet.drops_count = -1; /* invalid */
+ packet.ts_high = GUINT32_SWAP_LE_BE(epb.timestamp_high);
+ packet.ts_low = GUINT32_SWAP_LE_BE(epb.timestamp_low);
+ packet.cap_len = GUINT32_SWAP_LE_BE(epb.captured_len);
+ packet.packet_len = GUINT32_SWAP_LE_BE(epb.packet_len);
+ } else {
+ packet.interface_id = epb.interface_id;
+ packet.drops_count = -1; /* invalid */
+ packet.ts_high = epb.timestamp_high;
+ packet.ts_low = epb.timestamp_low;
+ packet.cap_len = epb.captured_len;
+ packet.packet_len = epb.packet_len;
+ }
+ pcapng_debug3("pcapng_read_packet_block: EPB on interface_id %d, cap_len %d, packet_len %d",
+ packet.interface_id, packet.cap_len, packet.packet_len);
+ } else {
/*
- * Is this block long enough to hold the packet data?
+ * Is this block long enough to be a PB?
*/
- if (enhanced) {
- if (block_total_length <
- MIN_EPB_SIZE + packet.cap_len + padding) {
- /*
- * No.
- */
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_packet_block: total block length %u of EPB is too small for %u bytes of packet data",
- block_total_length, packet.cap_len);
- return -1;
- }
- } else {
- if (block_total_length <
- MIN_PB_SIZE + packet.cap_len + padding) {
- /*
- * No.
- */
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_packet_block: total block length %u of PB is too small for %u bytes of packet data",
- block_total_length, packet.cap_len);
- return -1;
- }
+ if (bh->block_total_length < MIN_PB_SIZE) {
+ /*
+ * No.
+ */
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_packet_block: total block length %u of a PB is less than the minimum PB size %u",
+ bh->block_total_length, MIN_PB_SIZE);
+ return -1;
+ }
+ bytes_read = file_read(&pb, sizeof pb, fh);
+ if (bytes_read != sizeof pb) {
+ pcapng_debug0("pcapng_read_packet_block: failed to read packet data");
+ *err = file_error(fh, err_info);
+ return 0;
}
+ block_read = bytes_read;
- if (packet.cap_len > WTAP_MAX_PACKET_SIZE) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_packet_block: cap_len %u is larger than WTAP_MAX_PACKET_SIZE %u",
- packet.cap_len, WTAP_MAX_PACKET_SIZE);
- return 0;
- }
- pcapng_debug3("pcapng_read_packet_block: packet data: packet_len %u captured_len %u interface_id %u",
- packet.packet_len,
- packet.cap_len,
- packet.interface_id);
-
- if (packet.interface_id >= pn->interfaces->len) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng: interface index %u is not less than interface count %u",
- packet.interface_id, pn->interfaces->len);
- return 0;
- }
- iface_info = g_array_index(pn->interfaces, interface_info_t,
- packet.interface_id);
-
- wblock->packet_header->rec_type = REC_TYPE_PACKET;
- wblock->packet_header->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID;
-
- pcapng_debug3("pcapng_read_packet_block: encapsulation = %d (%s), pseudo header size = %d.",
- iface_info.wtap_encap,
- wtap_encap_string(iface_info.wtap_encap),
- pcap_get_phdr_size(iface_info.wtap_encap, &wblock->packet_header->pseudo_header));
- wblock->packet_header->interface_id = packet.interface_id;
- wblock->packet_header->pkt_encap = iface_info.wtap_encap;
-
- memset((void *)&wblock->packet_header->pseudo_header, 0, sizeof(union wtap_pseudo_header));
- pseudo_header_len = pcap_process_pseudo_header(fh,
- WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
- iface_info.wtap_encap,
- packet.cap_len,
- TRUE,
- wblock->packet_header,
- err,
- err_info);
- if (pseudo_header_len < 0) {
- return 0;
- }
- block_read += pseudo_header_len;
- if (pseudo_header_len != pcap_get_phdr_size(iface_info.wtap_encap, &wblock->packet_header->pseudo_header)) {
- pcapng_debug1("pcapng_read_packet_block: Could only read %d bytes for pseudo header.",
- pseudo_header_len);
+ if (pn->byte_swapped) {
+ packet.interface_id = GUINT16_SWAP_LE_BE(pb.interface_id);
+ packet.drops_count = GUINT16_SWAP_LE_BE(pb.drops_count);
+ packet.ts_high = GUINT32_SWAP_LE_BE(pb.timestamp_high);
+ packet.ts_low = GUINT32_SWAP_LE_BE(pb.timestamp_low);
+ packet.cap_len = GUINT32_SWAP_LE_BE(pb.captured_len);
+ packet.packet_len = GUINT32_SWAP_LE_BE(pb.packet_len);
+ } else {
+ packet.interface_id = pb.interface_id;
+ packet.drops_count = pb.drops_count;
+ packet.ts_high = pb.timestamp_high;
+ packet.ts_low = pb.timestamp_low;
+ packet.cap_len = pb.captured_len;
+ packet.packet_len = pb.packet_len;
+ }
+ pcapng_debug3("pcapng_read_packet_block: PB on interface_id %d, cap_len %d, packet_len %d",
+ packet.interface_id, packet.cap_len, packet.packet_len);
+ }
+
+ /*
+ * How much padding is there at the end of the packet data?
+ */
+ if ((packet.cap_len % 4) != 0)
+ padding = 4 - (packet.cap_len % 4);
+ else
+ padding = 0;
+
+ /* add padding bytes to "block total length" */
+ /* (the "block total length" of some example files don't contain the packet data padding bytes!) */
+ if (bh->block_total_length % 4) {
+ block_total_length = bh->block_total_length + 4 - (bh->block_total_length % 4);
+ } else {
+ block_total_length = bh->block_total_length;
+ }
+ pcapng_debug1("pcapng_read_packet_block: block_total_length %d", block_total_length);
+
+ /*
+ * Is this block long enough to hold the packet data?
+ */
+ if (enhanced) {
+ if (block_total_length <
+ MIN_EPB_SIZE + packet.cap_len + padding) {
+ /*
+ * No.
+ */
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_packet_block: total block length %u of EPB is too small for %u bytes of packet data",
+ block_total_length, packet.cap_len);
+ return -1;
+ }
+ } else {
+ if (block_total_length <
+ MIN_PB_SIZE + packet.cap_len + padding) {
+ /*
+ * No.
+ */
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_packet_block: total block length %u of PB is too small for %u bytes of packet data",
+ block_total_length, packet.cap_len);
+ return -1;
}
- wblock->packet_header->caplen = packet.cap_len - pseudo_header_len;
- wblock->packet_header->len = packet.packet_len - pseudo_header_len;
+ }
- /* Combine the two 32-bit pieces of the timestamp into one 64-bit value */
- ts = (((guint64)packet.ts_high) << 32) | ((guint64)packet.ts_low);
- wblock->packet_header->ts.secs = (time_t)(ts / iface_info.time_units_per_second);
- wblock->packet_header->ts.nsecs = (int)(((ts % iface_info.time_units_per_second) * 1000000000) / iface_info.time_units_per_second);
+ if (packet.cap_len > WTAP_MAX_PACKET_SIZE) {
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_packet_block: cap_len %u is larger than WTAP_MAX_PACKET_SIZE %u",
+ packet.cap_len, WTAP_MAX_PACKET_SIZE);
+ return 0;
+ }
+ pcapng_debug3("pcapng_read_packet_block: packet data: packet_len %u captured_len %u interface_id %u",
+ packet.packet_len,
+ packet.cap_len,
+ packet.interface_id);
+
+ if (packet.interface_id >= pn->interfaces->len) {
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng: interface index %u is not less than interface count %u",
+ packet.interface_id, pn->interfaces->len);
+ return 0;
+ }
+ iface_info = g_array_index(pn->interfaces, interface_info_t,
+ packet.interface_id);
+
+ wblock->packet_header->rec_type = REC_TYPE_PACKET;
+ wblock->packet_header->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID;
+
+ pcapng_debug3("pcapng_read_packet_block: encapsulation = %d (%s), pseudo header size = %d.",
+ iface_info.wtap_encap,
+ wtap_encap_string(iface_info.wtap_encap),
+ pcap_get_phdr_size(iface_info.wtap_encap, &wblock->packet_header->pseudo_header));
+ wblock->packet_header->interface_id = packet.interface_id;
+ wblock->packet_header->pkt_encap = iface_info.wtap_encap;
+
+ memset((void *)&wblock->packet_header->pseudo_header, 0, sizeof(union wtap_pseudo_header));
+ pseudo_header_len = pcap_process_pseudo_header(fh,
+ WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
+ iface_info.wtap_encap,
+ packet.cap_len,
+ TRUE,
+ wblock->packet_header,
+ err,
+ err_info);
+ if (pseudo_header_len < 0) {
+ return 0;
+ }
+ block_read += pseudo_header_len;
+ if (pseudo_header_len != pcap_get_phdr_size(iface_info.wtap_encap, &wblock->packet_header->pseudo_header)) {
+ pcapng_debug1("pcapng_read_packet_block: Could only read %d bytes for pseudo header.",
+ pseudo_header_len);
+ }
+ wblock->packet_header->caplen = packet.cap_len - pseudo_header_len;
+ wblock->packet_header->len = packet.packet_len - pseudo_header_len;
+
+ /* Combine the two 32-bit pieces of the timestamp into one 64-bit value */
+ ts = (((guint64)packet.ts_high) << 32) | ((guint64)packet.ts_low);
+ wblock->packet_header->ts.secs = (time_t)(ts / iface_info.time_units_per_second);
+ wblock->packet_header->ts.nsecs = (int)(((ts % iface_info.time_units_per_second) * 1000000000) / iface_info.time_units_per_second);
+
+ /* "(Enhanced) Packet Block" read capture data */
+ errno = WTAP_ERR_CANT_READ;
+ if (!wtap_read_packet_bytes(fh, wblock->frame_buffer,
+ packet.cap_len - pseudo_header_len, err, err_info))
+ return 0;
+ block_read += packet.cap_len - pseudo_header_len;
- /* "(Enhanced) Packet Block" read capture data */
- errno = WTAP_ERR_CANT_READ;
- if (!wtap_read_packet_bytes(fh, wblock->frame_buffer,
- packet.cap_len - pseudo_header_len, err, err_info))
- return 0;
- block_read += packet.cap_len - pseudo_header_len;
-
- /* jump over potential padding bytes at end of the packet data */
- if (padding != 0) {
- file_offset64 = file_seek(fh, padding, SEEK_CUR, err);
- if (file_offset64 <= 0) {
- if (*err != 0)
- return -1;
- return 0;
- }
- block_read += padding;
+ /* jump over potential padding bytes at end of the packet data */
+ if (padding != 0) {
+ file_offset64 = file_seek(fh, padding, SEEK_CUR, err);
+ if (file_offset64 <= 0) {
+ if (*err != 0)
+ return -1;
+ return 0;
}
+ block_read += padding;
+ }
- /* Option defaults */
- wblock->packet_header->opt_comment = NULL;
- wblock->packet_header->drop_count = -1;
- wblock->packet_header->pack_flags = 0;
+ /* Option defaults */
+ wblock->packet_header->opt_comment = NULL;
+ wblock->packet_header->drop_count = -1;
+ wblock->packet_header->pack_flags = 0;
+
+ /* FCS length default */
+ fcslen = pn->if_fcslen;
+
+ /* Options
+ * opt_comment 1
+ * epb_flags 2
+ * epb_hash 3
+ * epb_dropcount 4
+ */
+ errno = WTAP_ERR_CANT_READ;
+ to_read = block_total_length -
+ (int)sizeof(pcapng_block_header_t) -
+ block_read - /* fixed and variable part, including padding */
+ (int)sizeof(bh->block_total_length);
+
+ /* Allocate enough memory to hold all options */
+ opt_cont_buf_len = to_read;
+ option_content = (char *)g_try_malloc(opt_cont_buf_len);
+ if (opt_cont_buf_len != 0 && option_content == NULL) {
+ *err = ENOMEM; /* we assume we're out of memory */
+ return -1;
+ }
- /* FCS length default */
- fcslen = pn->if_fcslen;
+ while (to_read != 0) {
+ /* read option */
+ bytes_read = pcapng_read_option(fh, pn, &oh, option_content, opt_cont_buf_len, to_read, err, err_info);
+ if (bytes_read <= 0) {
+ pcapng_debug0("pcapng_read_packet_block: failed to read option");
+ return bytes_read;
+ }
+ block_read += bytes_read;
+ to_read -= bytes_read;
- /* Options
- * opt_comment 1
- * epb_flags 2
- * epb_hash 3
- * epb_dropcount 4
- */
- errno = WTAP_ERR_CANT_READ;
- to_read = block_total_length -
- (int)sizeof(pcapng_block_header_t) -
- block_read - /* fixed and variable part, including padding */
- (int)sizeof(bh->block_total_length);
-
- /* Allocate enough memory to hold all options */
- opt_cont_buf_len = to_read;
- option_content = (char *)g_try_malloc(opt_cont_buf_len);
- if (opt_cont_buf_len != 0 && option_content == NULL) {
- *err = ENOMEM; /* we assume we're out of memory */
- return -1;
- }
-
- while (to_read != 0) {
- /* read option */
- bytes_read = pcapng_read_option(fh, pn, &oh, option_content, opt_cont_buf_len, to_read, err, err_info);
- if (bytes_read <= 0) {
- pcapng_debug0("pcapng_read_packet_block: failed to read option");
- return bytes_read;
+ /* handle option content */
+ switch (oh.option_code) {
+ case(OPT_EOFOPT):
+ if (to_read != 0) {
+ pcapng_debug1("pcapng_read_packet_block: %u bytes after opt_endofopt", to_read);
}
- block_read += bytes_read;
- to_read -= bytes_read;
-
- /* handle option content */
- switch (oh.option_code) {
- case(OPT_EOFOPT):
- if (to_read != 0) {
- pcapng_debug1("pcapng_read_packet_block: %u bytes after opt_endofopt", to_read);
- }
- /* padding should be ok here, just get out of this */
- to_read = 0;
- break;
- case(OPT_COMMENT):
- if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
- wblock->packet_header->presence_flags |= WTAP_HAS_COMMENTS;
- wblock->packet_header->opt_comment = g_strndup(option_content, oh.option_length);
- pcapng_debug2("pcapng_read_packet_block: length %u opt_comment '%s'", oh.option_length, wblock->packet_header->opt_comment);
- } else {
- pcapng_debug1("pcapng_read_packet_block: opt_comment length %u seems strange", oh.option_length);
- }
- break;
- case(OPT_EPB_FLAGS):
- if (oh.option_length == 4) {
- /* Don't cast a char[] into a guint32--the
- * char[] may not be aligned correctly.
- */
- wblock->packet_header->presence_flags |= WTAP_HAS_PACK_FLAGS;
- memcpy(&wblock->packet_header->pack_flags, option_content, sizeof(guint32));
- if (pn->byte_swapped)
- wblock->packet_header->pack_flags = GUINT32_SWAP_LE_BE(wblock->packet_header->pack_flags);
- if (wblock->packet_header->pack_flags & 0x000001E0) {
- /* The FCS length is present */
- fcslen = (wblock->packet_header->pack_flags & 0x000001E0) >> 5;
- }
- pcapng_debug1("pcapng_read_packet_block: pack_flags %u (ignored)", wblock->packet_header->pack_flags);
- } else {
- pcapng_debug1("pcapng_read_packet_block: pack_flags length %u not 4 as expected", oh.option_length);
- }
- break;
- case(OPT_EPB_HASH):
- pcapng_debug2("pcapng_read_packet_block: epb_hash %u currently not handled - ignoring %u bytes",
- oh.option_code, oh.option_length);
- break;
- case(OPT_EPB_DROPCOUNT):
- if (oh.option_length == 8) {
- /* Don't cast a char[] into a guint32--the
- * char[] may not be aligned correctly.
- */
- wblock->packet_header->presence_flags |= WTAP_HAS_DROP_COUNT;
- memcpy(&wblock->packet_header->drop_count, option_content, sizeof(guint64));
- if (pn->byte_swapped)
- wblock->packet_header->drop_count = GUINT64_SWAP_LE_BE(wblock->packet_header->drop_count);
-
- pcapng_debug1("pcapng_read_packet_block: drop_count %" G_GINT64_MODIFIER "u", wblock->packet_header->drop_count);
- } else {
- pcapng_debug1("pcapng_read_packet_block: drop_count length %u not 8 as expected", oh.option_length);
- }
- break;
- default:
- pcapng_debug2("pcapng_read_packet_block: unknown option %u - ignoring %u bytes",
- oh.option_code, oh.option_length);
+ /* padding should be ok here, just get out of this */
+ to_read = 0;
+ break;
+ case(OPT_COMMENT):
+ if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
+ wblock->packet_header->presence_flags |= WTAP_HAS_COMMENTS;
+ wblock->packet_header->opt_comment = g_strndup(option_content, oh.option_length);
+ pcapng_debug2("pcapng_read_packet_block: length %u opt_comment '%s'", oh.option_length, wblock->packet_header->opt_comment);
+ } else {
+ pcapng_debug1("pcapng_read_packet_block: opt_comment length %u seems strange", oh.option_length);
+ }
+ break;
+ case(OPT_EPB_FLAGS):
+ if (oh.option_length == 4) {
+ /* Don't cast a char[] into a guint32--the
+ * char[] may not be aligned correctly.
+ */
+ wblock->packet_header->presence_flags |= WTAP_HAS_PACK_FLAGS;
+ memcpy(&wblock->packet_header->pack_flags, option_content, sizeof(guint32));
+ if (pn->byte_swapped)
+ wblock->packet_header->pack_flags = GUINT32_SWAP_LE_BE(wblock->packet_header->pack_flags);
+ if (wblock->packet_header->pack_flags & 0x000001E0) {
+ /* The FCS length is present */
+ fcslen = (wblock->packet_header->pack_flags & 0x000001E0) >> 5;
+ }
+ pcapng_debug1("pcapng_read_packet_block: pack_flags %u (ignored)", wblock->packet_header->pack_flags);
+ } else {
+ pcapng_debug1("pcapng_read_packet_block: pack_flags length %u not 4 as expected", oh.option_length);
}
+ break;
+ case(OPT_EPB_HASH):
+ pcapng_debug2("pcapng_read_packet_block: epb_hash %u currently not handled - ignoring %u bytes",
+ oh.option_code, oh.option_length);
+ break;
+ case(OPT_EPB_DROPCOUNT):
+ if (oh.option_length == 8) {
+ /* Don't cast a char[] into a guint32--the
+ * char[] may not be aligned correctly.
+ */
+ wblock->packet_header->presence_flags |= WTAP_HAS_DROP_COUNT;
+ memcpy(&wblock->packet_header->drop_count, option_content, sizeof(guint64));
+ if (pn->byte_swapped)
+ wblock->packet_header->drop_count = GUINT64_SWAP_LE_BE(wblock->packet_header->drop_count);
+
+ pcapng_debug1("pcapng_read_packet_block: drop_count %" G_GINT64_MODIFIER "u", wblock->packet_header->drop_count);
+ } else {
+ pcapng_debug1("pcapng_read_packet_block: drop_count length %u not 8 as expected", oh.option_length);
+ }
+ break;
+ default:
+ pcapng_debug2("pcapng_read_packet_block: unknown option %u - ignoring %u bytes",
+ oh.option_code, oh.option_length);
}
+ }
- g_free(option_content);
+ g_free(option_content);
- pcap_read_post_process(WTAP_FILE_TYPE_SUBTYPE_PCAPNG, iface_info.wtap_encap,
- wblock->packet_header, ws_buffer_start_ptr(wblock->frame_buffer),
- pn->byte_swapped, fcslen);
- return block_read;
+ pcap_read_post_process(WTAP_FILE_TYPE_SUBTYPE_PCAPNG, iface_info.wtap_encap,
+ wblock->packet_header, ws_buffer_start_ptr(wblock->frame_buffer),
+ pn->byte_swapped, fcslen);
+ return block_read;
}
static int
pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wtapng_block_t *wblock, int *err, gchar **err_info)
{
- int bytes_read;
- guint block_read;
- guint64 file_offset64;
- interface_info_t iface_info;
- pcapng_simple_packet_block_t spb;
- wtapng_simple_packet_t simple_packet;
- guint32 block_total_length;
- guint32 padding;
- int pseudo_header_len;
-
+ int bytes_read;
+ guint block_read;
+ guint64 file_offset64;
+ interface_info_t iface_info;
+ pcapng_simple_packet_block_t spb;
+ wtapng_simple_packet_t simple_packet;
+ guint32 block_total_length;
+ guint32 padding;
+ int pseudo_header_len;
+
+ /*
+ * Is this block long enough to be an SPB?
+ */
+ if (bh->block_total_length < MIN_SPB_SIZE) {
/*
- * Is this block long enough to be an SPB?
+ * No.
*/
- if (bh->block_total_length < MIN_SPB_SIZE) {
- /*
- * No.
- */
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_simple_packet_block: total block length %u of an SPB is less than the minimum SPB size %u",
- bh->block_total_length, MIN_SPB_SIZE);
- return -1;
- }
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_simple_packet_block: total block length %u of an SPB is less than the minimum SPB size %u",
+ bh->block_total_length, MIN_SPB_SIZE);
+ return -1;
+ }
- /* Don't try to allocate memory for a huge number of options, as
- that might fail and, even if it succeeds, it might not leave
- any address space or memory+backing store for anything else.
-
- We do that by imposing a maximum block size of MAX_BLOCK_SIZE.
- We check for this *after* checking the SHB for its byte
- order magic number, so that non-pcap-ng files are less
- likely to be treated as bad pcap-ng files. */
- if (bh->block_total_length > MAX_BLOCK_SIZE) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng: total block length %u is too large (> %u)",
- bh->block_total_length, MAX_BLOCK_SIZE);
- return -1;
- }
+ /* Don't try to allocate memory for a huge number of options, as
+ that might fail and, even if it succeeds, it might not leave
+ any address space or memory+backing store for anything else.
+
+ We do that by imposing a maximum block size of MAX_BLOCK_SIZE.
+ We check for this *after* checking the SHB for its byte
+ order magic number, so that non-pcap-ng files are less
+ likely to be treated as bad pcap-ng files. */
+ if (bh->block_total_length > MAX_BLOCK_SIZE) {
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng: total block length %u is too large (> %u)",
+ bh->block_total_length, MAX_BLOCK_SIZE);
+ return -1;
+ }
- /* "Simple Packet Block" read fixed part */
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(&spb, sizeof spb, fh);
- if (bytes_read != sizeof spb) {
- pcapng_debug0("pcapng_read_simple_packet_block: failed to read packet data");
- *err = file_error(fh, err_info);
- return 0;
- }
- block_read = bytes_read;
+ /* "Simple Packet Block" read fixed part */
+ errno = WTAP_ERR_CANT_READ;
+ bytes_read = file_read(&spb, sizeof spb, fh);
+ if (bytes_read != sizeof spb) {
+ pcapng_debug0("pcapng_read_simple_packet_block: failed to read packet data");
+ *err = file_error(fh, err_info);
+ return 0;
+ }
+ block_read = bytes_read;
- if (0 >= pn->interfaces->len) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng: SPB appeared before any IDBs");
- return 0;
- }
- iface_info = g_array_index(pn->interfaces, interface_info_t, 0);
+ if (0 >= pn->interfaces->len) {
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng: SPB appeared before any IDBs");
+ return 0;
+ }
+ iface_info = g_array_index(pn->interfaces, interface_info_t, 0);
- if (pn->byte_swapped) {
- simple_packet.packet_len = GUINT32_SWAP_LE_BE(spb.packet_len);
- } else {
- simple_packet.packet_len = spb.packet_len;
- }
+ if (pn->byte_swapped) {
+ simple_packet.packet_len = GUINT32_SWAP_LE_BE(spb.packet_len);
+ } else {
+ simple_packet.packet_len = spb.packet_len;
+ }
- /*
- * The captured length is not a field in the SPB; it can be
- * calculated as the minimum of the snapshot length from the
- * IDB and the packet length, as per the pcap-ng spec.
- */
- simple_packet.cap_len = simple_packet.packet_len;
- if (simple_packet.cap_len > iface_info.snap_len)
- simple_packet.cap_len = iface_info.snap_len;
+ /*
+ * The captured length is not a field in the SPB; it can be
+ * calculated as the minimum of the snapshot length from the
+ * IDB and the packet length, as per the pcap-ng spec.
+ */
+ simple_packet.cap_len = simple_packet.packet_len;
+ if (simple_packet.cap_len > iface_info.snap_len)
+ simple_packet.cap_len = iface_info.snap_len;
+
+ /*
+ * How much padding is there at the end of the packet data?
+ */
+ if ((simple_packet.cap_len % 4) != 0)
+ padding = 4 - (simple_packet.cap_len % 4);
+ else
+ padding = 0;
+
+ /* add padding bytes to "block total length" */
+ /* (the "block total length" of some example files don't contain the packet data padding bytes!) */
+ if (bh->block_total_length % 4) {
+ block_total_length = bh->block_total_length + 4 - (bh->block_total_length % 4);
+ } else {
+ block_total_length = bh->block_total_length;
+ }
+ pcapng_debug1("pcapng_read_simple_packet_block: block_total_length %d", block_total_length);
+ /*
+ * Is this block long enough to hold the packet data?
+ */
+ if (block_total_length < MIN_SPB_SIZE + simple_packet.cap_len + padding) {
/*
- * How much padding is there at the end of the packet data?
+ * No. That means that the problem is with the packet
+ * length; the snapshot length can be bigger than the amount
+ * of packet data in the block, as it's a *maximum* length,
+ * not a *minimum* length.
*/
- if ((simple_packet.cap_len % 4) != 0)
- padding = 4 - (simple_packet.cap_len % 4);
- else
- padding = 0;
-
- /* add padding bytes to "block total length" */
- /* (the "block total length" of some example files don't contain the packet data padding bytes!) */
- if (bh->block_total_length % 4) {
- block_total_length = bh->block_total_length + 4 - (bh->block_total_length % 4);
- } else {
- block_total_length = bh->block_total_length;
- }
- pcapng_debug1("pcapng_read_simple_packet_block: block_total_length %d", block_total_length);
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_simple_packet_block: total block length %u of PB is too small for %u bytes of packet data",
+ block_total_length, simple_packet.packet_len);
+ return -1;
+ }
- /*
- * Is this block long enough to hold the packet data?
- */
- if (block_total_length < MIN_SPB_SIZE + simple_packet.cap_len + padding) {
- /*
- * No. That means that the problem is with the packet
- * length; the snapshot length can be bigger than the amount
- * of packet data in the block, as it's a *maximum* length,
- * not a *minimum* length.
- */
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_simple_packet_block: total block length %u of PB is too small for %u bytes of packet data",
- block_total_length, simple_packet.packet_len);
- return -1;
- }
+ if (simple_packet.cap_len > WTAP_MAX_PACKET_SIZE) {
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_simple_packet_block: cap_len %u is larger than WTAP_MAX_PACKET_SIZE %u",
+ simple_packet.cap_len, WTAP_MAX_PACKET_SIZE);
+ return 0;
+ }
+ pcapng_debug1("pcapng_read_simple_packet_block: packet data: packet_len %u",
+ simple_packet.packet_len);
+
+ pcapng_debug1("pcapng_read_simple_packet_block: Need to read pseudo header of size %d",
+ pcap_get_phdr_size(iface_info.wtap_encap, &wblock->packet_header->pseudo_header));
+
+ /* No time stamp in a simple packet block; no options, either */
+ wblock->packet_header->rec_type = REC_TYPE_PACKET;
+ wblock->packet_header->presence_flags = WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID;
+ wblock->packet_header->interface_id = 0;
+ wblock->packet_header->pkt_encap = iface_info.wtap_encap;
+ wblock->packet_header->ts.secs = 0;
+ wblock->packet_header->ts.nsecs = 0;
+ wblock->packet_header->interface_id = 0;
+ wblock->packet_header->opt_comment = NULL;
+ wblock->packet_header->drop_count = 0;
+ wblock->packet_header->pack_flags = 0;
+
+ memset((void *)&wblock->packet_header->pseudo_header, 0, sizeof(union wtap_pseudo_header));
+ pseudo_header_len = pcap_process_pseudo_header(fh,
+ WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
+ iface_info.wtap_encap,
+ simple_packet.cap_len,
+ TRUE,
+ wblock->packet_header,
+ err,
+ err_info);
+ if (pseudo_header_len < 0) {
+ return 0;
+ }
+ wblock->packet_header->caplen = simple_packet.cap_len - pseudo_header_len;
+ wblock->packet_header->len = simple_packet.packet_len - pseudo_header_len;
+ block_read += pseudo_header_len;
+ if (pseudo_header_len != pcap_get_phdr_size(iface_info.wtap_encap, &wblock->packet_header->pseudo_header)) {
+ pcapng_debug1("pcapng_read_simple_packet_block: Could only read %d bytes for pseudo header.",
+ pseudo_header_len);
+ }
- if (simple_packet.cap_len > WTAP_MAX_PACKET_SIZE) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_simple_packet_block: cap_len %u is larger than WTAP_MAX_PACKET_SIZE %u",
- simple_packet.cap_len, WTAP_MAX_PACKET_SIZE);
- return 0;
- }
- pcapng_debug1("pcapng_read_simple_packet_block: packet data: packet_len %u",
- simple_packet.packet_len);
-
- pcapng_debug1("pcapng_read_simple_packet_block: Need to read pseudo header of size %d",
- pcap_get_phdr_size(iface_info.wtap_encap, &wblock->packet_header->pseudo_header));
-
- /* No time stamp in a simple packet block; no options, either */
- wblock->packet_header->rec_type = REC_TYPE_PACKET;
- wblock->packet_header->presence_flags = WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID;
- wblock->packet_header->interface_id = 0;
- wblock->packet_header->pkt_encap = iface_info.wtap_encap;
- wblock->packet_header->ts.secs = 0;
- wblock->packet_header->ts.nsecs = 0;
- wblock->packet_header->interface_id = 0;
- wblock->packet_header->opt_comment = NULL;
- wblock->packet_header->drop_count = 0;
- wblock->packet_header->pack_flags = 0;
-
- memset((void *)&wblock->packet_header->pseudo_header, 0, sizeof(union wtap_pseudo_header));
- pseudo_header_len = pcap_process_pseudo_header(fh,
- WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
- iface_info.wtap_encap,
- simple_packet.cap_len,
- TRUE,
- wblock->packet_header,
- err,
- err_info);
- if (pseudo_header_len < 0) {
- return 0;
- }
- wblock->packet_header->caplen = simple_packet.cap_len - pseudo_header_len;
- wblock->packet_header->len = simple_packet.packet_len - pseudo_header_len;
- block_read += pseudo_header_len;
- if (pseudo_header_len != pcap_get_phdr_size(iface_info.wtap_encap, &wblock->packet_header->pseudo_header)) {
- pcapng_debug1("pcapng_read_simple_packet_block: Could only read %d bytes for pseudo header.",
- pseudo_header_len);
- }
+ memset((void *)&wblock->packet_header->pseudo_header, 0, sizeof(union wtap_pseudo_header));
- memset((void *)&wblock->packet_header->pseudo_header, 0, sizeof(union wtap_pseudo_header));
+ /* "Simple Packet Block" read capture data */
+ errno = WTAP_ERR_CANT_READ;
+ if (!wtap_read_packet_bytes(fh, wblock->frame_buffer,
+ simple_packet.cap_len, err, err_info))
+ return 0;
+ block_read += simple_packet.cap_len;
- /* "Simple Packet Block" read capture data */
- errno = WTAP_ERR_CANT_READ;
- if (!wtap_read_packet_bytes(fh, wblock->frame_buffer,
- simple_packet.cap_len, err, err_info))
- return 0;
- block_read += simple_packet.cap_len;
-
- /* jump over potential padding bytes at end of the packet data */
- if ((simple_packet.cap_len % 4) != 0) {
- file_offset64 = file_seek(fh, 4 - (simple_packet.cap_len % 4), SEEK_CUR, err);
- if (file_offset64 <= 0) {
- if (*err != 0)
- return -1;
- return 0;
- }
- block_read += 4 - (simple_packet.cap_len % 4);
+ /* jump over potential padding bytes at end of the packet data */
+ if ((simple_packet.cap_len % 4) != 0) {
+ file_offset64 = file_seek(fh, 4 - (simple_packet.cap_len % 4), SEEK_CUR, err);
+ if (file_offset64 <= 0) {
+ if (*err != 0)
+ return -1;
+ return 0;
}
+ block_read += 4 - (simple_packet.cap_len % 4);
+ }
- pcap_read_post_process(WTAP_FILE_TYPE_SUBTYPE_PCAPNG, iface_info.wtap_encap,
- wblock->packet_header, ws_buffer_start_ptr(wblock->frame_buffer),
- pn->byte_swapped, pn->if_fcslen);
- return block_read;
+ pcap_read_post_process(WTAP_FILE_TYPE_SUBTYPE_PCAPNG, iface_info.wtap_encap,
+ wblock->packet_header, ws_buffer_start_ptr(wblock->frame_buffer),
+ pn->byte_swapped, pn->if_fcslen);
+ return block_read;
}
#define NRES_ENDOFRECORD 0
@@ -1511,815 +1511,815 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *
*/
static int
name_resolution_block_find_name_end(const char *p, guint record_len, int *err,
- gchar **err_info)
+ gchar **err_info)
{
- int namelen;
-
- namelen = 0;
- for (;;) {
- if (record_len == 0) {
- /*
- * We ran out of bytes in the record without
- * finding a NUL.
- */
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup("pcapng_read_name_resolution_block: NRB record has non-null-terminated host name");
- return -1;
- }
- if (*p == '\0')
- break; /* that's the terminating NUL */
- p++;
- record_len--;
- namelen++; /* count this byte */
- }
+ int namelen;
+
+ namelen = 0;
+ for (;;) {
+ if (record_len == 0) {
+ /*
+ * We ran out of bytes in the record without
+ * finding a NUL.
+ */
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup("pcapng_read_name_resolution_block: NRB record has non-null-terminated host name");
+ return -1;
+ }
+ if (*p == '\0')
+ break; /* that's the terminating NUL */
+ p++;
+ record_len--;
+ namelen++; /* count this byte */
+ }
- /* Include the NUL in the name length. */
- return namelen + 1;
+ /* Include the NUL in the name length. */
+ return namelen + 1;
}
static int
pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wtapng_block_t *wblock _U_,int *err, gchar **err_info)
{
- int bytes_read = 0;
- int block_read = 0;
- int to_read;
- guint64 file_offset64;
- pcapng_name_resolution_block_t nrb;
- Buffer nrb_rec;
- guint32 v4_addr;
- guint record_len;
- char *namep;
- int namelen;
-
+ int bytes_read = 0;
+ int block_read = 0;
+ int to_read;
+ guint64 file_offset64;
+ pcapng_name_resolution_block_t nrb;
+ Buffer nrb_rec;
+ guint32 v4_addr;
+ guint record_len;
+ char *namep;
+ int namelen;
+
+ /*
+ * Is this block long enough to be an NRB?
+ */
+ if (bh->block_total_length < MIN_NRB_SIZE) {
/*
- * Is this block long enough to be an NRB?
+ * No.
*/
- if (bh->block_total_length < MIN_NRB_SIZE) {
- /*
- * No.
- */
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_name_resolution_block: total block length %u of an NRB is less than the minimum NRB size %u",
- bh->block_total_length, MIN_NRB_SIZE);
- return -1;
- }
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_name_resolution_block: total block length %u of an NRB is less than the minimum NRB size %u",
+ bh->block_total_length, MIN_NRB_SIZE);
+ return -1;
+ }
- /* Don't try to allocate memory for a huge number of options, as
- that might fail and, even if it succeeds, it might not leave
- any address space or memory+backing store for anything else.
-
- We do that by imposing a maximum block size of MAX_BLOCK_SIZE.
- We check for this *after* checking the SHB for its byte
- order magic number, so that non-pcap-ng files are less
- likely to be treated as bad pcap-ng files. */
- if (bh->block_total_length > MAX_BLOCK_SIZE) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng: total block length %u is too large (> %u)",
- bh->block_total_length, MAX_BLOCK_SIZE);
- return -1;
- }
+ /* Don't try to allocate memory for a huge number of options, as
+ that might fail and, even if it succeeds, it might not leave
+ any address space or memory+backing store for anything else.
+
+ We do that by imposing a maximum block size of MAX_BLOCK_SIZE.
+ We check for this *after* checking the SHB for its byte
+ order magic number, so that non-pcap-ng files are less
+ likely to be treated as bad pcap-ng files. */
+ if (bh->block_total_length > MAX_BLOCK_SIZE) {
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng: total block length %u is too large (> %u)",
+ bh->block_total_length, MAX_BLOCK_SIZE);
+ return -1;
+ }
- errno = WTAP_ERR_CANT_READ;
- to_read = bh->block_total_length - 8 - 4; /* We have read the header adn should not read the final block_total_length */
+ errno = WTAP_ERR_CANT_READ;
+ to_read = bh->block_total_length - 8 - 4; /* We have read the header adn should not read the final block_total_length */
- pcapng_debug1("pcapng_read_name_resolution_block, total %d bytes", bh->block_total_length);
+ pcapng_debug1("pcapng_read_name_resolution_block, total %d bytes", bh->block_total_length);
+ /*
+ * Start out with a buffer big enough for an IPv6 address and one
+ * 64-byte name; we'll make the buffer bigger if necessary.
+ */
+ ws_buffer_init(&nrb_rec, INITIAL_NRB_REC_SIZE);
+ while (block_read < to_read) {
/*
- * Start out with a buffer big enough for an IPv6 address and one
- * 64-byte name; we'll make the buffer bigger if necessary.
+ * There must be at least one record's worth of data
+ * here.
*/
- ws_buffer_init(&nrb_rec, INITIAL_NRB_REC_SIZE);
- while (block_read < to_read) {
+ if ((size_t)(to_read - block_read) < sizeof nrb) {
+ ws_buffer_free(&nrb_rec);
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_name_resolution_block: %d bytes left in the block < NRB record header size %u",
+ to_read - block_read,
+ (guint)sizeof nrb);
+ return -1;
+ }
+ bytes_read = file_read(&nrb, sizeof nrb, fh);
+ if (bytes_read != sizeof nrb) {
+ ws_buffer_free(&nrb_rec);
+ pcapng_debug0("pcapng_read_name_resolution_block: failed to read record header");
+ *err = file_error(fh, err_info);
+ return 0;
+ }
+ block_read += bytes_read;
+
+ if (pn->byte_swapped) {
+ nrb.record_type = GUINT16_SWAP_LE_BE(nrb.record_type);
+ nrb.record_len = GUINT16_SWAP_LE_BE(nrb.record_len);
+ }
+
+ if (to_read - block_read < nrb.record_len + PADDING4(nrb.record_len)) {
+ ws_buffer_free(&nrb_rec);
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_name_resolution_block: %d bytes left in the block < NRB record length + padding %u",
+ to_read - block_read,
+ nrb.record_len + PADDING4(nrb.record_len));
+ return -1;
+ }
+ switch (nrb.record_type) {
+ case NRES_ENDOFRECORD:
+ /* There shouldn't be any more data */
+ to_read = 0;
+ break;
+ case NRES_IP4RECORD:
/*
- * There must be at least one record's worth of data
- * here.
+ * The smallest possible record must have
+ * a 4-byte IPv4 address, hence a minimum
+ * of 4 bytes.
+ *
+ * (The pcap-NG spec really indicates
+ * that it must be at least 5 bytes,
+ * as there must be at least one name,
+ * and it really must be at least 6
+ * bytes, as the name mustn't be null,
+ * but there's no need to fail if there
+ * aren't any names at all, and we
+ * should report a null name as such.)
*/
- if ((size_t)(to_read - block_read) < sizeof nrb) {
- ws_buffer_free(&nrb_rec);
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_name_resolution_block: %d bytes left in the block < NRB record header size %u",
- to_read - block_read,
- (guint)sizeof nrb);
+ if (nrb.record_len < 4) {
+ ws_buffer_free(&nrb_rec);
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_name_resolution_block: NRB record length for IPv4 record %u < minimum length 4",
+ nrb.record_len);
+ return -1;
+ }
+ ws_buffer_assure_space(&nrb_rec, nrb.record_len);
+ bytes_read = file_read(ws_buffer_start_ptr(&nrb_rec),
+ nrb.record_len, fh);
+ if (bytes_read != nrb.record_len) {
+ ws_buffer_free(&nrb_rec);
+ pcapng_debug0("pcapng_read_name_resolution_block: failed to read IPv4 record data");
+ *err = file_error(fh, err_info);
+ return 0;
+ }
+ block_read += bytes_read;
+
+ if (pn->add_new_ipv4) {
+ /*
+ * Scan through all the names in
+ * the record and add them.
+ */
+ memcpy(&v4_addr,
+ ws_buffer_start_ptr(&nrb_rec), 4);
+ if (pn->byte_swapped)
+ v4_addr = GUINT32_SWAP_LE_BE(v4_addr);
+ for (namep = (char *)ws_buffer_start_ptr(&nrb_rec) + 4, record_len = nrb.record_len - 4;
+ record_len != 0;
+ namep += namelen, record_len -= namelen) {
+ /*
+ * Scan forward for a null
+ * byte.
+ */
+ namelen = name_resolution_block_find_name_end(namep, record_len, err, err_info);
+ if (namelen == -1) {
+ ws_buffer_free(&nrb_rec);
+ return -1; /* fail */
+ }
+ pn->add_new_ipv4(v4_addr, namep);
+ }
+ }
+
+ file_offset64 = file_seek(fh, PADDING4(nrb.record_len), SEEK_CUR, err);
+ if (file_offset64 <= 0) {
+ ws_buffer_free(&nrb_rec);
+ if (*err != 0)
return -1;
+ return 0;
}
- bytes_read = file_read(&nrb, sizeof nrb, fh);
- if (bytes_read != sizeof nrb) {
- ws_buffer_free(&nrb_rec);
- pcapng_debug0("pcapng_read_name_resolution_block: failed to read record header");
- *err = file_error(fh, err_info);
- return 0;
+ block_read += PADDING4(nrb.record_len);
+ break;
+ case NRES_IP6RECORD:
+ /*
+ * The smallest possible record must have
+ * a 16-byte IPv6 address, hence a minimum
+ * of 16 bytes.
+ *
+ * (The pcap-NG spec really indicates
+ * that it must be at least 17 bytes,
+ * as there must be at least one name,
+ * and it really must be at least 18
+ * bytes, as the name mustn't be null,
+ * but there's no need to fail if there
+ * aren't any names at all, and we
+ * should report a null name as such.)
+ */
+ if (nrb.record_len < 16) {
+ ws_buffer_free(&nrb_rec);
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_name_resolution_block: NRB record length for IPv6 record %u < minimum length 16",
+ nrb.record_len);
+ return -1;
+ }
+ if (to_read < nrb.record_len) {
+ ws_buffer_free(&nrb_rec);
+ pcapng_debug0("pcapng_read_name_resolution_block: insufficient data for IPv6 record");
+ return 0;
+ }
+ ws_buffer_assure_space(&nrb_rec, nrb.record_len);
+ bytes_read = file_read(ws_buffer_start_ptr(&nrb_rec),
+ nrb.record_len, fh);
+ if (bytes_read != nrb.record_len) {
+ ws_buffer_free(&nrb_rec);
+ pcapng_debug0("pcapng_read_name_resolution_block: failed to read IPv6 record data");
+ *err = file_error(fh, err_info);
+ return 0;
}
block_read += bytes_read;
- if (pn->byte_swapped) {
- nrb.record_type = GUINT16_SWAP_LE_BE(nrb.record_type);
- nrb.record_len = GUINT16_SWAP_LE_BE(nrb.record_len);
+ if (pn->add_new_ipv6) {
+ for (namep = (char *)ws_buffer_start_ptr(&nrb_rec) + 16, record_len = nrb.record_len - 16;
+ record_len != 0;
+ namep += namelen, record_len -= namelen) {
+ /*
+ * Scan forward for a null
+ * byte.
+ */
+ namelen = name_resolution_block_find_name_end(namep, record_len, err, err_info);
+ if (namelen == -1) {
+ ws_buffer_free(&nrb_rec);
+ return -1; /* fail */
+ }
+ pn->add_new_ipv6(ws_buffer_start_ptr(&nrb_rec),
+ namep);
+ }
}
- if (to_read - block_read < nrb.record_len + PADDING4(nrb.record_len)) {
- ws_buffer_free(&nrb_rec);
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_name_resolution_block: %d bytes left in the block < NRB record length + padding %u",
- to_read - block_read,
- nrb.record_len + PADDING4(nrb.record_len));
+ file_offset64 = file_seek(fh, PADDING4(nrb.record_len), SEEK_CUR, err);
+ if (file_offset64 <= 0) {
+ ws_buffer_free(&nrb_rec);
+ if (*err != 0)
return -1;
+ return 0;
}
- switch (nrb.record_type) {
- case NRES_ENDOFRECORD:
- /* There shouldn't be any more data */
- to_read = 0;
- break;
- case NRES_IP4RECORD:
- /*
- * The smallest possible record must have
- * a 4-byte IPv4 address, hence a minimum
- * of 4 bytes.
- *
- * (The pcap-NG spec really indicates
- * that it must be at least 5 bytes,
- * as there must be at least one name,
- * and it really must be at least 6
- * bytes, as the name mustn't be null,
- * but there's no need to fail if there
- * aren't any names at all, and we
- * should report a null name as such.)
- */
- if (nrb.record_len < 4) {
- ws_buffer_free(&nrb_rec);
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_name_resolution_block: NRB record length for IPv4 record %u < minimum length 4",
- nrb.record_len);
- return -1;
- }
- ws_buffer_assure_space(&nrb_rec, nrb.record_len);
- bytes_read = file_read(ws_buffer_start_ptr(&nrb_rec),
- nrb.record_len, fh);
- if (bytes_read != nrb.record_len) {
- ws_buffer_free(&nrb_rec);
- pcapng_debug0("pcapng_read_name_resolution_block: failed to read IPv4 record data");
- *err = file_error(fh, err_info);
- return 0;
- }
- block_read += bytes_read;
-
- if (pn->add_new_ipv4) {
- /*
- * Scan through all the names in
- * the record and add them.
- */
- memcpy(&v4_addr,
- ws_buffer_start_ptr(&nrb_rec), 4);
- if (pn->byte_swapped)
- v4_addr = GUINT32_SWAP_LE_BE(v4_addr);
- for (namep = (char *)ws_buffer_start_ptr(&nrb_rec) + 4, record_len = nrb.record_len - 4;
- record_len != 0;
- namep += namelen, record_len -= namelen) {
- /*
- * Scan forward for a null
- * byte.
- */
- namelen = name_resolution_block_find_name_end(namep, record_len, err, err_info);
- if (namelen == -1) {
- ws_buffer_free(&nrb_rec);
- return -1; /* fail */
- }
- pn->add_new_ipv4(v4_addr, namep);
- }
- }
-
- file_offset64 = file_seek(fh, PADDING4(nrb.record_len), SEEK_CUR, err);
- if (file_offset64 <= 0) {
- ws_buffer_free(&nrb_rec);
- if (*err != 0)
- return -1;
- return 0;
- }
- block_read += PADDING4(nrb.record_len);
- break;
- case NRES_IP6RECORD:
- /*
- * The smallest possible record must have
- * a 16-byte IPv6 address, hence a minimum
- * of 16 bytes.
- *
- * (The pcap-NG spec really indicates
- * that it must be at least 17 bytes,
- * as there must be at least one name,
- * and it really must be at least 18
- * bytes, as the name mustn't be null,
- * but there's no need to fail if there
- * aren't any names at all, and we
- * should report a null name as such.)
- */
- if (nrb.record_len < 16) {
- ws_buffer_free(&nrb_rec);
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_name_resolution_block: NRB record length for IPv6 record %u < minimum length 16",
- nrb.record_len);
- return -1;
- }
- if (to_read < nrb.record_len) {
- ws_buffer_free(&nrb_rec);
- pcapng_debug0("pcapng_read_name_resolution_block: insufficient data for IPv6 record");
- return 0;
- }
- ws_buffer_assure_space(&nrb_rec, nrb.record_len);
- bytes_read = file_read(ws_buffer_start_ptr(&nrb_rec),
- nrb.record_len, fh);
- if (bytes_read != nrb.record_len) {
- ws_buffer_free(&nrb_rec);
- pcapng_debug0("pcapng_read_name_resolution_block: failed to read IPv6 record data");
- *err = file_error(fh, err_info);
- return 0;
- }
- block_read += bytes_read;
-
- if (pn->add_new_ipv6) {
- for (namep = (char *)ws_buffer_start_ptr(&nrb_rec) + 16, record_len = nrb.record_len - 16;
- record_len != 0;
- namep += namelen, record_len -= namelen) {
- /*
- * Scan forward for a null
- * byte.
- */
- namelen = name_resolution_block_find_name_end(namep, record_len, err, err_info);
- if (namelen == -1) {
- ws_buffer_free(&nrb_rec);
- return -1; /* fail */
- }
- pn->add_new_ipv6(ws_buffer_start_ptr(&nrb_rec),
- namep);
- }
- }
-
- file_offset64 = file_seek(fh, PADDING4(nrb.record_len), SEEK_CUR, err);
- if (file_offset64 <= 0) {
- ws_buffer_free(&nrb_rec);
- if (*err != 0)
- return -1;
- return 0;
- }
- block_read += PADDING4(nrb.record_len);
- break;
- default:
- pcapng_debug1("pcapng_read_name_resolution_block: unknown record type 0x%x", nrb.record_type);
- file_offset64 = file_seek(fh, nrb.record_len + PADDING4(nrb.record_len), SEEK_CUR, err);
- if (file_offset64 <= 0) {
- ws_buffer_free(&nrb_rec);
- if (*err != 0)
- return -1;
- return 0;
- }
- block_read += nrb.record_len + PADDING4(nrb.record_len);
- break;
+ block_read += PADDING4(nrb.record_len);
+ break;
+ default:
+ pcapng_debug1("pcapng_read_name_resolution_block: unknown record type 0x%x", nrb.record_type);
+ file_offset64 = file_seek(fh, nrb.record_len + PADDING4(nrb.record_len), SEEK_CUR, err);
+ if (file_offset64 <= 0) {
+ ws_buffer_free(&nrb_rec);
+ if (*err != 0)
+ return -1;
+ return 0;
}
+ block_read += nrb.record_len + PADDING4(nrb.record_len);
+ break;
}
+ }
- ws_buffer_free(&nrb_rec);
- return block_read;
+ ws_buffer_free(&nrb_rec);
+ return block_read;
}
static int
pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wtapng_block_t *wblock,int *err, gchar **err_info)
{
- int bytes_read;
- guint block_read;
- guint to_read, opt_cont_buf_len;
- pcapng_interface_statistics_block_t isb;
- pcapng_option_header_t oh;
- char *option_content = NULL; /* Allocate as large as the options block */
-
+ int bytes_read;
+ guint block_read;
+ guint to_read, opt_cont_buf_len;
+ pcapng_interface_statistics_block_t isb;
+ pcapng_option_header_t oh;
+ char *option_content = NULL; /* Allocate as large as the options block */
+
+ /*
+ * Is this block long enough to be an ISB?
+ */
+ if (bh->block_total_length < MIN_ISB_SIZE) {
/*
- * Is this block long enough to be an ISB?
+ * No.
*/
- if (bh->block_total_length < MIN_ISB_SIZE) {
- /*
- * No.
- */
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_interface_statistics_block: total block length %u is too small (< %u)",
- bh->block_total_length, MIN_ISB_SIZE);
- return -1;
- }
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_interface_statistics_block: total block length %u is too small (< %u)",
+ bh->block_total_length, MIN_ISB_SIZE);
+ return -1;
+ }
- /* Don't try to allocate memory for a huge number of options, as
- that might fail and, even if it succeeds, it might not leave
- any address space or memory+backing store for anything else.
-
- We do that by imposing a maximum block size of MAX_BLOCK_SIZE.
- We check for this *after* checking the SHB for its byte
- order magic number, so that non-pcap-ng files are less
- likely to be treated as bad pcap-ng files. */
- if (bh->block_total_length > MAX_BLOCK_SIZE) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng: total block length %u is too large (> %u)",
- bh->block_total_length, MAX_BLOCK_SIZE);
- return -1;
- }
+ /* Don't try to allocate memory for a huge number of options, as
+ that might fail and, even if it succeeds, it might not leave
+ any address space or memory+backing store for anything else.
+
+ We do that by imposing a maximum block size of MAX_BLOCK_SIZE.
+ We check for this *after* checking the SHB for its byte
+ order magic number, so that non-pcap-ng files are less
+ likely to be treated as bad pcap-ng files. */
+ if (bh->block_total_length > MAX_BLOCK_SIZE) {
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng: total block length %u is too large (> %u)",
+ bh->block_total_length, MAX_BLOCK_SIZE);
+ return -1;
+ }
- /* "Interface Statistics Block" read fixed part */
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(&isb, sizeof isb, fh);
- if (bytes_read != sizeof isb) {
- pcapng_debug0("pcapng_read_interface_statistics_block: failed to read packet data");
- *err = file_error(fh, err_info);
- return 0;
- }
- block_read = bytes_read;
+ /* "Interface Statistics Block" read fixed part */
+ errno = WTAP_ERR_CANT_READ;
+ bytes_read = file_read(&isb, sizeof isb, fh);
+ if (bytes_read != sizeof isb) {
+ pcapng_debug0("pcapng_read_interface_statistics_block: failed to read packet data");
+ *err = file_error(fh, err_info);
+ return 0;
+ }
+ block_read = bytes_read;
+
+ if (pn->byte_swapped) {
+ wblock->data.if_stats.interface_id = GUINT32_SWAP_LE_BE(isb.interface_id);
+ wblock->data.if_stats.ts_high = GUINT32_SWAP_LE_BE(isb.timestamp_high);
+ wblock->data.if_stats.ts_low = GUINT32_SWAP_LE_BE(isb.timestamp_low);
+ } else {
+ wblock->data.if_stats.interface_id = isb.interface_id;
+ wblock->data.if_stats.ts_high = isb.timestamp_high;
+ wblock->data.if_stats.ts_low = isb.timestamp_low;
+ }
+ pcapng_debug1("pcapng_read_interface_statistics_block: interface_id %u", wblock->data.if_stats.interface_id);
+
+ /* Option defaults */
+ wblock->data.if_stats.opt_comment = NULL;
+ wblock->data.if_stats.isb_ifrecv = -1;
+ wblock->data.if_stats.isb_ifdrop = -1;
+ wblock->data.if_stats.isb_filteraccept = -1;
+ wblock->data.if_stats.isb_osdrop = -1;
+ wblock->data.if_stats.isb_usrdeliv = -1;
+
+ /* Options */
+ errno = WTAP_ERR_CANT_READ;
+ to_read = bh->block_total_length -
+ (MIN_BLOCK_SIZE + block_read); /* fixed and variable part, including padding */
+
+ /* Allocate enough memory to hold all options */
+ opt_cont_buf_len = to_read;
+ option_content = (char *)g_try_malloc(opt_cont_buf_len);
+ if (opt_cont_buf_len != 0 && option_content == NULL) {
+ *err = ENOMEM; /* we assume we're out of memory */
+ return -1;
+ }
- if (pn->byte_swapped) {
- wblock->data.if_stats.interface_id = GUINT32_SWAP_LE_BE(isb.interface_id);
- wblock->data.if_stats.ts_high = GUINT32_SWAP_LE_BE(isb.timestamp_high);
- wblock->data.if_stats.ts_low = GUINT32_SWAP_LE_BE(isb.timestamp_low);
- } else {
- wblock->data.if_stats.interface_id = isb.interface_id;
- wblock->data.if_stats.ts_high = isb.timestamp_high;
- wblock->data.if_stats.ts_low = isb.timestamp_low;
+ while (to_read != 0) {
+ /* read option */
+ bytes_read = pcapng_read_option(fh, pn, &oh, option_content, opt_cont_buf_len, to_read, err, err_info);
+ if (bytes_read <= 0) {
+ pcapng_debug0("pcapng_read_interface_statistics_block: failed to read option");
+ return bytes_read;
}
- pcapng_debug1("pcapng_read_interface_statistics_block: interface_id %u", wblock->data.if_stats.interface_id);
-
- /* Option defaults */
- wblock->data.if_stats.opt_comment = NULL;
- wblock->data.if_stats.isb_ifrecv = -1;
- wblock->data.if_stats.isb_ifdrop = -1;
- wblock->data.if_stats.isb_filteraccept = -1;
- wblock->data.if_stats.isb_osdrop = -1;
- wblock->data.if_stats.isb_usrdeliv = -1;
+ block_read += bytes_read;
+ to_read -= bytes_read;
- /* Options */
- errno = WTAP_ERR_CANT_READ;
- to_read = bh->block_total_length -
- (MIN_BLOCK_SIZE + block_read); /* fixed and variable part, including padding */
-
- /* Allocate enough memory to hold all options */
- opt_cont_buf_len = to_read;
- option_content = (char *)g_try_malloc(opt_cont_buf_len);
- if (opt_cont_buf_len != 0 && option_content == NULL) {
- *err = ENOMEM; /* we assume we're out of memory */
- return -1;
- }
-
- while (to_read != 0) {
- /* read option */
- bytes_read = pcapng_read_option(fh, pn, &oh, option_content, opt_cont_buf_len, to_read, err, err_info);
- if (bytes_read <= 0) {
- pcapng_debug0("pcapng_read_interface_statistics_block: failed to read option");
- return bytes_read;
+ /* handle option content */
+ switch (oh.option_code) {
+ case(0): /* opt_endofopt */
+ if (to_read != 0) {
+ pcapng_debug1("pcapng_read_interface_statistics_block: %u bytes after opt_endofopt", to_read);
}
- block_read += bytes_read;
- to_read -= bytes_read;
-
- /* handle option content */
- switch (oh.option_code) {
- case(0): /* opt_endofopt */
- if (to_read != 0) {
- pcapng_debug1("pcapng_read_interface_statistics_block: %u bytes after opt_endofopt", to_read);
- }
- /* padding should be ok here, just get out of this */
- to_read = 0;
- break;
- case(1): /* opt_comment */
- if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
- wblock->data.if_stats.opt_comment = g_strndup(option_content, oh.option_length);
- pcapng_debug1("pcapng_read_interface_statistics_block: opt_comment %s", wblock->data.if_stats.opt_comment);
- } else {
- pcapng_debug1("pcapng_read_interface_statistics_block: opt_comment length %u seems strange", oh.option_length);
- }
- break;
- case(2): /* isb_starttime */
- if (oh.option_length == 8) {
- guint32 high, low;
-
- /* Don't cast a char[] into a guint32--the
- * char[] may not be aligned correctly.
- */
- memcpy(&high, option_content, sizeof(guint32));
- memcpy(&low, option_content + sizeof(guint32), sizeof(guint32));
- if (pn->byte_swapped) {
- high = GUINT32_SWAP_LE_BE(high);
- low = GUINT32_SWAP_LE_BE(low);
- }
- wblock->data.if_stats.isb_starttime = (guint64)high;
- wblock->data.if_stats.isb_starttime <<= 32;
- wblock->data.if_stats.isb_starttime += (guint64)low;
- pcapng_debug1("pcapng_read_interface_statistics_block: isb_starttime %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_starttime);
- } else {
- pcapng_debug1("pcapng_read_interface_statistics_block: isb_starttime length %u not 8 as expected", oh.option_length);
- }
- break;
- case(3): /* isb_endtime */
- if (oh.option_length == 8) {
- guint32 high, low;
-
- /* Don't cast a char[] into a guint32--the
- * char[] may not be aligned correctly.
- */
- memcpy(&high, option_content, sizeof(guint32));
- memcpy(&low, option_content + sizeof(guint32), sizeof(guint32));
- if (pn->byte_swapped) {
- high = GUINT32_SWAP_LE_BE(high);
- low = GUINT32_SWAP_LE_BE(low);
- }
- wblock->data.if_stats.isb_endtime = (guint64)high;
- wblock->data.if_stats.isb_endtime <<= 32;
- wblock->data.if_stats.isb_endtime += (guint64)low;
- pcapng_debug1("pcapng_read_interface_statistics_block: isb_endtime %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_endtime);
- } else {
- pcapng_debug1("pcapng_read_interface_statistics_block: isb_starttime length %u not 8 as expected", oh.option_length);
- }
- break;
- case(4): /* isb_ifrecv */
- if (oh.option_length == 8) {
- /* Don't cast a char[] into a guint32--the
- * char[] may not be aligned correctly.
- */
- memcpy(&wblock->data.if_stats.isb_ifrecv, option_content, sizeof(guint64));
- if (pn->byte_swapped)
- wblock->data.if_stats.isb_ifrecv = GUINT64_SWAP_LE_BE(wblock->data.if_stats.isb_ifrecv);
- pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifrecv %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_ifrecv);
- } else {
- pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifrecv length %u not 8 as expected", oh.option_length);
- }
- break;
- case(5): /* isb_ifdrop */
- if (oh.option_length == 8) {
- /* Don't cast a char[] into a guint32--the
- * char[] may not be aligned correctly.
- */
- memcpy(&wblock->data.if_stats.isb_ifdrop, option_content, sizeof(guint64));
- if (pn->byte_swapped)
- wblock->data.if_stats.isb_ifdrop = GUINT64_SWAP_LE_BE(wblock->data.if_stats.isb_ifdrop);
- pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifdrop %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_ifdrop);
- } else {
- pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifdrop length %u not 8 as expected", oh.option_length);
- }
- break;
- case(6): /* isb_filteraccept 6 */
- if (oh.option_length == 8) {
- /* Don't cast a char[] into a guint32--the
- * char[] may not be aligned correctly.
- */
- memcpy(&wblock->data.if_stats.isb_filteraccept, option_content, sizeof(guint64));
- if (pn->byte_swapped)
- wblock->data.if_stats.isb_ifdrop = GUINT64_SWAP_LE_BE(wblock->data.if_stats.isb_filteraccept);
- pcapng_debug1("pcapng_read_interface_statistics_block: isb_filteraccept %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_filteraccept);
- } else {
- pcapng_debug1("pcapng_read_interface_statistics_block: isb_filteraccept length %u not 8 as expected", oh.option_length);
- }
- break;
- case(7): /* isb_osdrop 7 */
- if (oh.option_length == 8) {
- /* Don't cast a char[] into a guint32--the
- * char[] may not be aligned correctly.
- */
- memcpy(&wblock->data.if_stats.isb_osdrop, option_content, sizeof(guint64));
- if (pn->byte_swapped)
- wblock->data.if_stats.isb_osdrop = GUINT64_SWAP_LE_BE(wblock->data.if_stats.isb_osdrop);
- pcapng_debug1("pcapng_read_interface_statistics_block: isb_osdrop %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_osdrop);
- } else {
- pcapng_debug1("pcapng_read_interface_statistics_block: isb_osdrop length %u not 8 as expected", oh.option_length);
- }
- break;
- case(8): /* isb_usrdeliv 8 */
- if (oh.option_length == 8) {
- /* Don't cast a char[] into a guint32--the
- * char[] may not be aligned correctly.
- */
- memcpy(&wblock->data.if_stats.isb_usrdeliv, option_content, sizeof(guint64));
- if (pn->byte_swapped)
- wblock->data.if_stats.isb_usrdeliv = GUINT64_SWAP_LE_BE(wblock->data.if_stats.isb_osdrop);
- pcapng_debug1("pcapng_read_interface_statistics_block: isb_usrdeliv %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_usrdeliv);
- } else {
- pcapng_debug1("pcapng_read_interface_statistics_block: isb_usrdeliv length %u not 8 as expected", oh.option_length);
- }
- break;
- default:
- pcapng_debug2("pcapng_read_interface_statistics_block: unknown option %u - ignoring %u bytes",
- oh.option_code, oh.option_length);
+ /* padding should be ok here, just get out of this */
+ to_read = 0;
+ break;
+ case(1): /* opt_comment */
+ if (oh.option_length > 0 && oh.option_length < opt_cont_buf_len) {
+ wblock->data.if_stats.opt_comment = g_strndup(option_content, oh.option_length);
+ pcapng_debug1("pcapng_read_interface_statistics_block: opt_comment %s", wblock->data.if_stats.opt_comment);
+ } else {
+ pcapng_debug1("pcapng_read_interface_statistics_block: opt_comment length %u seems strange", oh.option_length);
+ }
+ break;
+ case(2): /* isb_starttime */
+ if (oh.option_length == 8) {
+ guint32 high, low;
+
+ /* Don't cast a char[] into a guint32--the
+ * char[] may not be aligned correctly.
+ */
+ memcpy(&high, option_content, sizeof(guint32));
+ memcpy(&low, option_content + sizeof(guint32), sizeof(guint32));
+ if (pn->byte_swapped) {
+ high = GUINT32_SWAP_LE_BE(high);
+ low = GUINT32_SWAP_LE_BE(low);
+ }
+ wblock->data.if_stats.isb_starttime = (guint64)high;
+ wblock->data.if_stats.isb_starttime <<= 32;
+ wblock->data.if_stats.isb_starttime += (guint64)low;
+ pcapng_debug1("pcapng_read_interface_statistics_block: isb_starttime %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_starttime);
+ } else {
+ pcapng_debug1("pcapng_read_interface_statistics_block: isb_starttime length %u not 8 as expected", oh.option_length);
+ }
+ break;
+ case(3): /* isb_endtime */
+ if (oh.option_length == 8) {
+ guint32 high, low;
+
+ /* Don't cast a char[] into a guint32--the
+ * char[] may not be aligned correctly.
+ */
+ memcpy(&high, option_content, sizeof(guint32));
+ memcpy(&low, option_content + sizeof(guint32), sizeof(guint32));
+ if (pn->byte_swapped) {
+ high = GUINT32_SWAP_LE_BE(high);
+ low = GUINT32_SWAP_LE_BE(low);
+ }
+ wblock->data.if_stats.isb_endtime = (guint64)high;
+ wblock->data.if_stats.isb_endtime <<= 32;
+ wblock->data.if_stats.isb_endtime += (guint64)low;
+ pcapng_debug1("pcapng_read_interface_statistics_block: isb_endtime %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_endtime);
+ } else {
+ pcapng_debug1("pcapng_read_interface_statistics_block: isb_starttime length %u not 8 as expected", oh.option_length);
+ }
+ break;
+ case(4): /* isb_ifrecv */
+ if (oh.option_length == 8) {
+ /* Don't cast a char[] into a guint32--the
+ * char[] may not be aligned correctly.
+ */
+ memcpy(&wblock->data.if_stats.isb_ifrecv, option_content, sizeof(guint64));
+ if (pn->byte_swapped)
+ wblock->data.if_stats.isb_ifrecv = GUINT64_SWAP_LE_BE(wblock->data.if_stats.isb_ifrecv);
+ pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifrecv %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_ifrecv);
+ } else {
+ pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifrecv length %u not 8 as expected", oh.option_length);
}
+ break;
+ case(5): /* isb_ifdrop */
+ if (oh.option_length == 8) {
+ /* Don't cast a char[] into a guint32--the
+ * char[] may not be aligned correctly.
+ */
+ memcpy(&wblock->data.if_stats.isb_ifdrop, option_content, sizeof(guint64));
+ if (pn->byte_swapped)
+ wblock->data.if_stats.isb_ifdrop = GUINT64_SWAP_LE_BE(wblock->data.if_stats.isb_ifdrop);
+ pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifdrop %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_ifdrop);
+ } else {
+ pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifdrop length %u not 8 as expected", oh.option_length);
+ }
+ break;
+ case(6): /* isb_filteraccept 6 */
+ if (oh.option_length == 8) {
+ /* Don't cast a char[] into a guint32--the
+ * char[] may not be aligned correctly.
+ */
+ memcpy(&wblock->data.if_stats.isb_filteraccept, option_content, sizeof(guint64));
+ if (pn->byte_swapped)
+ wblock->data.if_stats.isb_ifdrop = GUINT64_SWAP_LE_BE(wblock->data.if_stats.isb_filteraccept);
+ pcapng_debug1("pcapng_read_interface_statistics_block: isb_filteraccept %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_filteraccept);
+ } else {
+ pcapng_debug1("pcapng_read_interface_statistics_block: isb_filteraccept length %u not 8 as expected", oh.option_length);
+ }
+ break;
+ case(7): /* isb_osdrop 7 */
+ if (oh.option_length == 8) {
+ /* Don't cast a char[] into a guint32--the
+ * char[] may not be aligned correctly.
+ */
+ memcpy(&wblock->data.if_stats.isb_osdrop, option_content, sizeof(guint64));
+ if (pn->byte_swapped)
+ wblock->data.if_stats.isb_osdrop = GUINT64_SWAP_LE_BE(wblock->data.if_stats.isb_osdrop);
+ pcapng_debug1("pcapng_read_interface_statistics_block: isb_osdrop %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_osdrop);
+ } else {
+ pcapng_debug1("pcapng_read_interface_statistics_block: isb_osdrop length %u not 8 as expected", oh.option_length);
+ }
+ break;
+ case(8): /* isb_usrdeliv 8 */
+ if (oh.option_length == 8) {
+ /* Don't cast a char[] into a guint32--the
+ * char[] may not be aligned correctly.
+ */
+ memcpy(&wblock->data.if_stats.isb_usrdeliv, option_content, sizeof(guint64));
+ if (pn->byte_swapped)
+ wblock->data.if_stats.isb_usrdeliv = GUINT64_SWAP_LE_BE(wblock->data.if_stats.isb_osdrop);
+ pcapng_debug1("pcapng_read_interface_statistics_block: isb_usrdeliv %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_usrdeliv);
+ } else {
+ pcapng_debug1("pcapng_read_interface_statistics_block: isb_usrdeliv length %u not 8 as expected", oh.option_length);
+ }
+ break;
+ default:
+ pcapng_debug2("pcapng_read_interface_statistics_block: unknown option %u - ignoring %u bytes",
+ oh.option_code, oh.option_length);
}
+ }
- g_free(option_content);
+ g_free(option_content);
- return block_read;
+ return block_read;
}
static int
pcapng_read_unknown_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn _U_, wtapng_block_t *wblock _U_, int *err, gchar **err_info)
{
- int block_read;
- guint32 block_total_length;
+ int block_read;
+ guint32 block_total_length;
#ifdef HAVE_PLUGINS
- block_handler *handler;
+ block_handler *handler;
#endif
- if (bh->block_total_length < MIN_BLOCK_SIZE) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_unknown_block: total block length %u of an unknown block type is less than the minimum block size %u",
- bh->block_total_length, MIN_BLOCK_SIZE);
- return -1;
- }
+ if (bh->block_total_length < MIN_BLOCK_SIZE) {
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_unknown_block: total block length %u of an unknown block type is less than the minimum block size %u",
+ bh->block_total_length, MIN_BLOCK_SIZE);
+ return -1;
+ }
- /* add padding bytes to "block total length" */
- /* (the "block total length" of some example files don't contain any padding bytes!) */
- if (bh->block_total_length % 4) {
- block_total_length = bh->block_total_length + 4 - (bh->block_total_length % 4);
- } else {
- block_total_length = bh->block_total_length;
- }
+ /* add padding bytes to "block total length" */
+ /* (the "block total length" of some example files don't contain any padding bytes!) */
+ if (bh->block_total_length % 4) {
+ block_total_length = bh->block_total_length + 4 - (bh->block_total_length % 4);
+ } else {
+ block_total_length = bh->block_total_length;
+ }
- block_read = block_total_length - MIN_BLOCK_SIZE;
+ block_read = block_total_length - MIN_BLOCK_SIZE;
#ifdef HAVE_PLUGINS
- /*
- * Do we have a handler for this block type?
- */
- handler = (block_handler *)g_hash_table_lookup(block_handlers,
- GUINT_TO_POINTER(bh->block_type));
- if (handler != NULL) {
- /* Yes - call it to read this block type. */
- if (!handler->read(fh, block_read, pn->byte_swapped,
- wblock->packet_header, wblock->frame_buffer,
- err, err_info))
- return -1;
- } else
+ /*
+ * Do we have a handler for this block type?
+ */
+ handler = (block_handler *)g_hash_table_lookup(block_handlers,
+ GUINT_TO_POINTER(bh->block_type));
+ if (handler != NULL) {
+ /* Yes - call it to read this block type. */
+ if (!handler->read(fh, block_read, pn->byte_swapped,
+ wblock->packet_header, wblock->frame_buffer,
+ err, err_info))
+ return -1;
+ } else
#endif
- {
- /* No. Skip over this unknown block. */
- if (!file_skip(fh, block_read, err)) {
- if (*err != 0)
- return -1;
- return 0;
- }
+ {
+ /* No. Skip over this unknown block. */
+ if (!file_skip(fh, block_read, err)) {
+ if (*err != 0)
+ return -1;
+ return 0;
}
+ }
- return block_read;
+ return block_read;
}
static int
pcapng_read_block(FILE_T fh, gboolean first_block, pcapng_t *pn, wtapng_block_t *wblock, int *err, gchar **err_info)
{
- int block_read;
- int bytes_read;
- pcapng_block_header_t bh;
- guint32 block_total_length;
+ int block_read;
+ int bytes_read;
+ pcapng_block_header_t bh;
+ guint32 block_total_length;
- /* Try to read the (next) block header */
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(&bh, sizeof bh, fh);
- if (bytes_read != sizeof bh) {
- *err = file_error(fh, err_info);
- pcapng_debug3("pcapng_read_block: file_read() returned %d instead of %u, err = %d.", bytes_read, (unsigned int)sizeof bh, *err);
- if (*err != 0)
- return -1;
- return 0;
- }
+ /* Try to read the (next) block header */
+ errno = WTAP_ERR_CANT_READ;
+ bytes_read = file_read(&bh, sizeof bh, fh);
+ if (bytes_read != sizeof bh) {
+ *err = file_error(fh, err_info);
+ pcapng_debug3("pcapng_read_block: file_read() returned %d instead of %u, err = %d.", bytes_read, (unsigned int)sizeof bh, *err);
+ if (*err != 0)
+ return -1;
+ return 0;
+ }
- block_read = bytes_read;
- if (pn->byte_swapped) {
- bh.block_type = GUINT32_SWAP_LE_BE(bh.block_type);
- bh.block_total_length = GUINT32_SWAP_LE_BE(bh.block_total_length);
- }
+ block_read = bytes_read;
+ if (pn->byte_swapped) {
+ bh.block_type = GUINT32_SWAP_LE_BE(bh.block_type);
+ bh.block_total_length = GUINT32_SWAP_LE_BE(bh.block_total_length);
+ }
- wblock->type = bh.block_type;
+ wblock->type = bh.block_type;
- pcapng_debug1("pcapng_read_block: block_type 0x%x", bh.block_type);
+ pcapng_debug1("pcapng_read_block: block_type 0x%x", bh.block_type);
- if (first_block) {
- /*
- * This is being read in by pcapng_open(), so this block
- * must be an SHB. If it's not, this is not a pcap-ng
- * file.
- *
- * XXX - check for various forms of Windows <-> UN*X
- * mangling, and suggest that the file might be a
- * pcap-ng file that was damaged in transit?
- */
- if (bh.block_type != BLOCK_TYPE_SHB)
- return 0; /* not a pcap-ng file */
- }
-
- switch (bh.block_type) {
- case(BLOCK_TYPE_SHB):
- bytes_read = pcapng_read_section_header_block(fh, first_block, &bh, pn, wblock, err, err_info);
- break;
- case(BLOCK_TYPE_IDB):
- bytes_read = pcapng_read_if_descr_block(fh, &bh, pn, wblock, err, err_info);
- break;
- case(BLOCK_TYPE_PB):
- bytes_read = pcapng_read_packet_block(fh, &bh, pn, wblock, err, err_info, FALSE);
- break;
- case(BLOCK_TYPE_SPB):
- bytes_read = pcapng_read_simple_packet_block(fh, &bh, pn, wblock, err, err_info);
- break;
- case(BLOCK_TYPE_EPB):
- bytes_read = pcapng_read_packet_block(fh, &bh, pn, wblock, err, err_info, TRUE);
- break;
- case(BLOCK_TYPE_NRB):
- bytes_read = pcapng_read_name_resolution_block(fh, &bh, pn, wblock, err, err_info);
- break;
- case(BLOCK_TYPE_ISB):
- bytes_read = pcapng_read_interface_statistics_block(fh, &bh, pn, wblock, err, err_info);
- break;
- default:
- pcapng_debug2("pcapng_read_block: Unknown block_type: 0x%x (block ignored), block total length %d", bh.block_type, bh.block_total_length);
- bytes_read = pcapng_read_unknown_block(fh, &bh, pn, wblock, err, err_info);
- break;
- }
+ if (first_block) {
+ /*
+ * This is being read in by pcapng_open(), so this block
+ * must be an SHB. If it's not, this is not a pcap-ng
+ * file.
+ *
+ * XXX - check for various forms of Windows <-> UN*X
+ * mangling, and suggest that the file might be a
+ * pcap-ng file that was damaged in transit?
+ */
+ if (bh.block_type != BLOCK_TYPE_SHB)
+ return 0; /* not a pcap-ng file */
+ }
- if (bytes_read <= 0) {
- return bytes_read;
- }
- block_read += bytes_read;
+ switch (bh.block_type) {
+ case(BLOCK_TYPE_SHB):
+ bytes_read = pcapng_read_section_header_block(fh, first_block, &bh, pn, wblock, err, err_info);
+ break;
+ case(BLOCK_TYPE_IDB):
+ bytes_read = pcapng_read_if_descr_block(fh, &bh, pn, wblock, err, err_info);
+ break;
+ case(BLOCK_TYPE_PB):
+ bytes_read = pcapng_read_packet_block(fh, &bh, pn, wblock, err, err_info, FALSE);
+ break;
+ case(BLOCK_TYPE_SPB):
+ bytes_read = pcapng_read_simple_packet_block(fh, &bh, pn, wblock, err, err_info);
+ break;
+ case(BLOCK_TYPE_EPB):
+ bytes_read = pcapng_read_packet_block(fh, &bh, pn, wblock, err, err_info, TRUE);
+ break;
+ case(BLOCK_TYPE_NRB):
+ bytes_read = pcapng_read_name_resolution_block(fh, &bh, pn, wblock, err, err_info);
+ break;
+ case(BLOCK_TYPE_ISB):
+ bytes_read = pcapng_read_interface_statistics_block(fh, &bh, pn, wblock, err, err_info);
+ break;
+ default:
+ pcapng_debug2("pcapng_read_block: Unknown block_type: 0x%x (block ignored), block total length %d", bh.block_type, bh.block_total_length);
+ bytes_read = pcapng_read_unknown_block(fh, &bh, pn, wblock, err, err_info);
+ break;
+ }
- /* sanity check: first and second block lengths must match */
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(&block_total_length, sizeof block_total_length, fh);
- if (bytes_read != sizeof block_total_length) {
- pcapng_debug0("pcapng_read_block: couldn't read second block length");
- *err = file_error(fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return -1;
- }
- block_read += bytes_read;
+ if (bytes_read <= 0) {
+ return bytes_read;
+ }
+ block_read += bytes_read;
+
+ /* sanity check: first and second block lengths must match */
+ errno = WTAP_ERR_CANT_READ;
+ bytes_read = file_read(&block_total_length, sizeof block_total_length, fh);
+ if (bytes_read != sizeof block_total_length) {
+ pcapng_debug0("pcapng_read_block: couldn't read second block length");
+ *err = file_error(fh, err_info);
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
+ return -1;
+ }
+ block_read += bytes_read;
- if (pn->byte_swapped)
- block_total_length = GUINT32_SWAP_LE_BE(block_total_length);
+ if (pn->byte_swapped)
+ block_total_length = GUINT32_SWAP_LE_BE(block_total_length);
- if (!(block_total_length == bh.block_total_length)) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("pcapng_read_block: total block lengths (first %u and second %u) don't match",
- bh.block_total_length, block_total_length);
- return -1;
- }
+ if (!(block_total_length == bh.block_total_length)) {
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("pcapng_read_block: total block lengths (first %u and second %u) don't match",
+ bh.block_total_length, block_total_length);
+ return -1;
+ }
- return block_read;
+ return block_read;
}
/* Process an IDB that we've just read. */
static void
pcapng_process_idb(wtap *wth, pcapng_t *pcapng, wtapng_block_t *wblock)
{
- wtapng_if_descr_t int_data;
- interface_info_t iface_info;
-
- int_data.wtap_encap = wblock->data.if_descr.wtap_encap;
- int_data.time_units_per_second = wblock->data.if_descr.time_units_per_second;
- int_data.link_type = wblock->data.if_descr.link_type;
- int_data.snap_len = wblock->data.if_descr.snap_len;
- /* Options */
- int_data.opt_comment = wblock->data.if_descr.opt_comment;
- int_data.if_name = wblock->data.if_descr.if_name;
- int_data.if_description = wblock->data.if_descr.if_description;
- /* XXX: if_IPv4addr opt 4 Interface network address and netmask.*/
- /* XXX: if_IPv6addr opt 5 Interface network address and prefix length (stored in the last byte).*/
- /* XXX: if_MACaddr opt 6 Interface Hardware MAC address (48 bits).*/
- /* XXX: if_EUIaddr opt 7 Interface Hardware EUI address (64 bits)*/
- int_data.if_speed = wblock->data.if_descr.if_speed;
- int_data.if_tsresol = wblock->data.if_descr.if_tsresol;
- /* XXX: if_tzone 10 Time zone for GMT support (TODO: specify better). */
- int_data.if_filter_str = wblock->data.if_descr.if_filter_str;
- int_data.bpf_filter_len = wblock->data.if_descr.bpf_filter_len;
- int_data.if_filter_bpf_bytes = wblock->data.if_descr.if_filter_bpf_bytes;
- int_data.if_os = wblock->data.if_descr.if_os;
- int_data.if_fcslen = wblock->data.if_descr.if_fcslen;
- /* XXX if_tsoffset; opt 14 A 64 bits integer value that specifies an offset (in seconds)...*/
- /* Interface statistics */
- int_data.num_stat_entries = 0;
- int_data.interface_statistics = NULL;
-
- g_array_append_val(wth->interface_data, int_data);
-
- iface_info.wtap_encap = wblock->data.if_descr.wtap_encap;
- iface_info.snap_len = wblock->data.if_descr.snap_len;
- iface_info.time_units_per_second = wblock->data.if_descr.time_units_per_second;
-
- g_array_append_val(pcapng->interfaces, iface_info);
+ wtapng_if_descr_t int_data;
+ interface_info_t iface_info;
+
+ int_data.wtap_encap = wblock->data.if_descr.wtap_encap;
+ int_data.time_units_per_second = wblock->data.if_descr.time_units_per_second;
+ int_data.link_type = wblock->data.if_descr.link_type;
+ int_data.snap_len = wblock->data.if_descr.snap_len;
+ /* Options */
+ int_data.opt_comment = wblock->data.if_descr.opt_comment;
+ int_data.if_name = wblock->data.if_descr.if_name;
+ int_data.if_description = wblock->data.if_descr.if_description;
+ /* XXX: if_IPv4addr opt 4 Interface network address and netmask.*/
+ /* XXX: if_IPv6addr opt 5 Interface network address and prefix length (stored in the last byte).*/
+ /* XXX: if_MACaddr opt 6 Interface Hardware MAC address (48 bits).*/
+ /* XXX: if_EUIaddr opt 7 Interface Hardware EUI address (64 bits)*/
+ int_data.if_speed = wblock->data.if_descr.if_speed;
+ int_data.if_tsresol = wblock->data.if_descr.if_tsresol;
+ /* XXX: if_tzone 10 Time zone for GMT support (TODO: specify better). */
+ int_data.if_filter_str = wblock->data.if_descr.if_filter_str;
+ int_data.bpf_filter_len = wblock->data.if_descr.bpf_filter_len;
+ int_data.if_filter_bpf_bytes = wblock->data.if_descr.if_filter_bpf_bytes;
+ int_data.if_os = wblock->data.if_descr.if_os;
+ int_data.if_fcslen = wblock->data.if_descr.if_fcslen;
+ /* XXX if_tsoffset; opt 14 A 64 bits integer value that specifies an offset (in seconds)...*/
+ /* Interface statistics */
+ int_data.num_stat_entries = 0;
+ int_data.interface_statistics = NULL;
+
+ g_array_append_val(wth->interface_data, int_data);
+
+ iface_info.wtap_encap = wblock->data.if_descr.wtap_encap;
+ iface_info.snap_len = wblock->data.if_descr.snap_len;
+ iface_info.time_units_per_second = wblock->data.if_descr.time_units_per_second;
+
+ g_array_append_val(pcapng->interfaces, iface_info);
}
/* classic wtap: open capture file */
int
pcapng_open(wtap *wth, int *err, gchar **err_info)
{
- int bytes_read;
- pcapng_t pn;
- wtapng_block_t wblock;
- pcapng_t *pcapng;
- pcapng_block_header_t bh;
- gint64 saved_offset;
-
- pn.shb_read = FALSE;
- /* we don't know the byte swapping of the file yet */
- pn.byte_swapped = FALSE;
- pn.if_fcslen = -1;
- pn.version_major = -1;
- pn.version_minor = -1;
- pn.interfaces = g_array_new(FALSE, FALSE, sizeof(interface_info_t));
-
-
- /* we don't expect any packet blocks yet */
- wblock.frame_buffer = NULL;
- wblock.packet_header = NULL;
- wblock.file_encap = &wth->file_encap;
-
- pcapng_debug0("pcapng_open: opening file");
- /* read first block */
- bytes_read = pcapng_read_block(wth->fh, TRUE, &pn, &wblock, err, err_info);
- if (bytes_read <= 0) {
- pcapng_debug0("pcapng_open: couldn't read first SHB");
- *err = file_error(wth->fh, err_info);
- if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
- return -1;
- return 0;
- }
-
- /* first block must be a "Section Header Block" */
- if (wblock.type != BLOCK_TYPE_SHB) {
- /*
- * XXX - check for damage from transferring a file
- * between Windows and UN*X as text rather than
- * binary data?
- */
- pcapng_debug1("pcapng_open: first block type %u not SHB", wblock.type);
- return 0;
- }
- pn.shb_read = TRUE;
+ int bytes_read;
+ pcapng_t pn;
+ wtapng_block_t wblock;
+ pcapng_t *pcapng;
+ pcapng_block_header_t bh;
+ gint64 saved_offset;
+
+ pn.shb_read = FALSE;
+ /* we don't know the byte swapping of the file yet */
+ pn.byte_swapped = FALSE;
+ pn.if_fcslen = -1;
+ pn.version_major = -1;
+ pn.version_minor = -1;
+ pn.interfaces = g_array_new(FALSE, FALSE, sizeof(interface_info_t));
+
+
+ /* we don't expect any packet blocks yet */
+ wblock.frame_buffer = NULL;
+ wblock.packet_header = NULL;
+ wblock.file_encap = &wth->file_encap;
+
+ pcapng_debug0("pcapng_open: opening file");
+ /* read first block */
+ bytes_read = pcapng_read_block(wth->fh, TRUE, &pn, &wblock, err, err_info);
+ if (bytes_read <= 0) {
+ pcapng_debug0("pcapng_open: couldn't read first SHB");
+ *err = file_error(wth->fh, err_info);
+ if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
+ return -1;
+ return 0;
+ }
+ /* first block must be a "Section Header Block" */
+ if (wblock.type != BLOCK_TYPE_SHB) {
/*
- * At this point, we've decided this is a pcap-NG file, not
- * some other type of file, so we can't return 0, as that
- * means "this isn't a pcap-NG file, try some other file
- * type".
+ * XXX - check for damage from transferring a file
+ * between Windows and UN*X as text rather than
+ * binary data?
*/
- wth->shb_hdr.opt_comment = wblock.data.section.opt_comment;
- wth->shb_hdr.shb_hardware = wblock.data.section.shb_hardware;
- wth->shb_hdr.shb_os = wblock.data.section.shb_os;
- wth->shb_hdr.shb_user_appl = wblock.data.section.shb_user_appl;
-
- wth->file_encap = WTAP_ENCAP_UNKNOWN;
- wth->snapshot_length = 0;
- wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
- pcapng = (pcapng_t *)g_malloc(sizeof(pcapng_t));
- wth->priv = (void *)pcapng;
- *pcapng = pn;
-
- wth->subtype_read = pcapng_read;
- wth->subtype_seek_read = pcapng_seek_read;
- wth->subtype_close = pcapng_close;
- wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAPNG;
-
- /* Loop over all IDB:s that appear before any packets */
- while (1) {
- /* peek at next block */
- /* Try to read the (next) block header */
- saved_offset = file_tell(wth->fh);
- errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(&bh, sizeof bh, wth->fh);
- if (bytes_read == 0) {
- pcapng_debug0("No more IDBs available...");
- break;
- }
- if (bytes_read != sizeof bh) {
- *err = file_error(wth->fh, err_info);
- pcapng_debug3("pcapng_open: Check for more IDB:s, file_read() returned %d instead of %u, err = %d.", bytes_read, (unsigned int)sizeof bh, *err);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return -1;
- }
+ pcapng_debug1("pcapng_open: first block type %u not SHB", wblock.type);
+ return 0;
+ }
+ pn.shb_read = TRUE;
+
+ /*
+ * At this point, we've decided this is a pcap-NG file, not
+ * some other type of file, so we can't return 0, as that
+ * means "this isn't a pcap-NG file, try some other file
+ * type".
+ */
+ wth->shb_hdr.opt_comment = wblock.data.section.opt_comment;
+ wth->shb_hdr.shb_hardware = wblock.data.section.shb_hardware;
+ wth->shb_hdr.shb_os = wblock.data.section.shb_os;
+ wth->shb_hdr.shb_user_appl = wblock.data.section.shb_user_appl;
+
+ wth->file_encap = WTAP_ENCAP_UNKNOWN;
+ wth->snapshot_length = 0;
+ wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
+ pcapng = (pcapng_t *)g_malloc(sizeof(pcapng_t));
+ wth->priv = (void *)pcapng;
+ *pcapng = pn;
+
+ wth->subtype_read = pcapng_read;
+ wth->subtype_seek_read = pcapng_seek_read;
+ wth->subtype_close = pcapng_close;
+ wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PCAPNG;
+
+ /* Loop over all IDB:s that appear before any packets */
+ while (1) {
+ /* peek at next block */
+ /* Try to read the (next) block header */
+ saved_offset = file_tell(wth->fh);
+ errno = WTAP_ERR_CANT_READ;
+ bytes_read = file_read(&bh, sizeof bh, wth->fh);
+ if (bytes_read == 0) {
+ pcapng_debug0("No more IDBs available...");
+ break;
+ }
+ if (bytes_read != sizeof bh) {
+ *err = file_error(wth->fh, err_info);
+ pcapng_debug3("pcapng_open: Check for more IDB:s, file_read() returned %d instead of %u, err = %d.", bytes_read, (unsigned int)sizeof bh, *err);
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
+ return -1;
+ }
- /* go back to where we were */
- file_seek(wth->fh, saved_offset, SEEK_SET, err);
+ /* go back to where we were */
+ file_seek(wth->fh, saved_offset, SEEK_SET, err);
- if (pn.byte_swapped) {
- bh.block_type = GUINT32_SWAP_LE_BE(bh.block_type);
- }
+ if (pn.byte_swapped) {
+ bh.block_type = GUINT32_SWAP_LE_BE(bh.block_type);
+ }
- pcapng_debug1("pcapng_open: Check for more IDB:s block_type 0x%x", bh.block_type);
+ pcapng_debug1("pcapng_open: Check for more IDB:s block_type 0x%x", bh.block_type);
- if (bh.block_type != BLOCK_TYPE_IDB) {
- break; /* No more IDB:s */
- }
- bytes_read = pcapng_read_block(wth->fh, FALSE, &pn, &wblock, err, err_info);
- if (bytes_read == 0) {
- pcapng_debug0("No more IDBs available...");
- break;
- }
- if (bytes_read <= 0) {
- pcapng_debug0("pcapng_open: couldn't read IDB");
- *err = file_error(wth->fh, err_info);
- if (*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return -1;
- }
- pcapng_process_idb(wth, pcapng, &wblock);
- pcapng_debug2("pcapng_open: Read IDB number_of_interfaces %u, wtap_encap %i",
- wth->interface_data->len, *wblock.file_encap);
+ if (bh.block_type != BLOCK_TYPE_IDB) {
+ break; /* No more IDB:s */
+ }
+ bytes_read = pcapng_read_block(wth->fh, FALSE, &pn, &wblock, err, err_info);
+ if (bytes_read == 0) {
+ pcapng_debug0("No more IDBs available...");
+ break;
}
- return 1;
+ if (bytes_read <= 0) {
+ pcapng_debug0("pcapng_open: couldn't read IDB");
+ *err = file_error(wth->fh, err_info);
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
+ return -1;
+ }
+ pcapng_process_idb(wth, pcapng, &wblock);
+ pcapng_debug2("pcapng_open: Read IDB number_of_interfaces %u, wtap_encap %i",
+ wth->interface_data->len, *wblock.file_encap);
+ }
+ return 1;
}
@@ -2327,151 +2327,151 @@ pcapng_open(wtap *wth, int *err, gchar **err_info)
static gboolean
pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
- pcapng_t *pcapng = (pcapng_t *)wth->priv;
- int bytes_read;
- wtapng_block_t wblock;
- wtapng_if_descr_t *wtapng_if_descr;
- wtapng_if_stats_t if_stats;
-
- *data_offset = file_tell(wth->fh);
- pcapng_debug1("pcapng_read: data_offset is initially %" G_GINT64_MODIFIER "d", *data_offset);
-
- wblock.frame_buffer = wth->frame_buffer;
- wblock.packet_header = &wth->phdr;
- wblock.file_encap = &wth->file_encap;
-
- pcapng->add_new_ipv4 = wth->add_new_ipv4;
- pcapng->add_new_ipv6 = wth->add_new_ipv6;
-
- /* read next block */
- while (1) {
- bytes_read = pcapng_read_block(wth->fh, FALSE, pcapng, &wblock, err, err_info);
- if (bytes_read <= 0) {
- pcapng_debug1("pcapng_read: data_offset is finally %" G_GINT64_MODIFIER "d", *data_offset);
- pcapng_debug0("pcapng_read: couldn't read packet block");
- return FALSE;
- }
+ pcapng_t *pcapng = (pcapng_t *)wth->priv;
+ int bytes_read;
+ wtapng_block_t wblock;
+ wtapng_if_descr_t *wtapng_if_descr;
+ wtapng_if_stats_t if_stats;
- switch (wblock.type) {
-
- case(BLOCK_TYPE_SHB):
- /* We don't currently support multi-section files. */
- wth->phdr.pkt_encap = WTAP_ENCAP_UNKNOWN;
- *err = WTAP_ERR_UNSUPPORTED;
- *err_info = g_strdup_printf("pcapng: multi-section files not currently supported");
- return FALSE;
-
- case(BLOCK_TYPE_PB):
- case(BLOCK_TYPE_SPB):
- case(BLOCK_TYPE_EPB):
- /* packet block - we've found a packet */
- goto got_packet;
-
- case(BLOCK_TYPE_IDB):
- /* A new interface */
- pcapng_debug0("pcapng_read: block type BLOCK_TYPE_IDB");
- *data_offset += bytes_read;
- pcapng_process_idb(wth, pcapng, &wblock);
- break;
-
- case(BLOCK_TYPE_NRB):
- /* More name resolution entries */
- pcapng_debug0("pcapng_read: block type BLOCK_TYPE_NRB");
- *data_offset += bytes_read;
- break;
-
- case(BLOCK_TYPE_ISB):
- /* Another interface statistics report */
- pcapng_debug0("pcapng_read: block type BLOCK_TYPE_ISB");
- *data_offset += bytes_read;
- pcapng_debug1("pcapng_read: *data_offset is updated to %" G_GINT64_MODIFIER "d", *data_offset);
- if (wth->interface_data->len < wblock.data.if_stats.interface_id) {
- pcapng_debug1("pcapng_read: BLOCK_TYPE_ISB wblock.if_stats.interface_id %u > number_of_interfaces", wblock.data.if_stats.interface_id);
- } else {
- /* Get the interface description */
- wtapng_if_descr = &g_array_index(wth->interface_data, wtapng_if_descr_t, wblock.data.if_stats.interface_id);
- if (wtapng_if_descr->num_stat_entries == 0) {
- /* First ISB found, no previous entry */
- pcapng_debug0("pcapng_read: block type BLOCK_TYPE_ISB. First ISB found, no previous entry");
- wtapng_if_descr->interface_statistics = g_array_new(FALSE, FALSE, sizeof(wtapng_if_stats_t));
- }
-
- if_stats.interface_id = wblock.data.if_stats.interface_id;
- if_stats.ts_high = wblock.data.if_stats.ts_high;
- if_stats.ts_low = wblock.data.if_stats.ts_low;
- /* options */
- if_stats.opt_comment = wblock.data.if_stats.opt_comment; /* NULL if not available */
- if_stats.isb_starttime = wblock.data.if_stats.isb_starttime;
- if_stats.isb_endtime = wblock.data.if_stats.isb_endtime;
- if_stats.isb_ifrecv = wblock.data.if_stats.isb_ifrecv;
- if_stats.isb_ifdrop = wblock.data.if_stats.isb_ifdrop;
- if_stats.isb_filteraccept = wblock.data.if_stats.isb_filteraccept;
- if_stats.isb_osdrop = wblock.data.if_stats.isb_osdrop;
- if_stats.isb_usrdeliv = wblock.data.if_stats.isb_usrdeliv;
-
- g_array_append_val(wtapng_if_descr->interface_statistics, if_stats);
- wtapng_if_descr->num_stat_entries++;
- }
- break;
-
- default:
- /* XXX - improve handling of "unknown" blocks */
- pcapng_debug1("pcapng_read: Unknown block type 0x%08x", wblock.type);
- *data_offset += bytes_read;
- pcapng_debug1("pcapng_read: *data_offset is updated to %" G_GINT64_MODIFIER "d", *data_offset);
- break;
+ *data_offset = file_tell(wth->fh);
+ pcapng_debug1("pcapng_read: data_offset is initially %" G_GINT64_MODIFIER "d", *data_offset);
+
+ wblock.frame_buffer = wth->frame_buffer;
+ wblock.packet_header = &wth->phdr;
+ wblock.file_encap = &wth->file_encap;
+
+ pcapng->add_new_ipv4 = wth->add_new_ipv4;
+ pcapng->add_new_ipv6 = wth->add_new_ipv6;
+
+ /* read next block */
+ while (1) {
+ bytes_read = pcapng_read_block(wth->fh, FALSE, pcapng, &wblock, err, err_info);
+ if (bytes_read <= 0) {
+ pcapng_debug1("pcapng_read: data_offset is finally %" G_GINT64_MODIFIER "d", *data_offset);
+ pcapng_debug0("pcapng_read: couldn't read packet block");
+ return FALSE;
+ }
+
+ switch (wblock.type) {
+
+ case(BLOCK_TYPE_SHB):
+ /* We don't currently support multi-section files. */
+ wth->phdr.pkt_encap = WTAP_ENCAP_UNKNOWN;
+ *err = WTAP_ERR_UNSUPPORTED;
+ *err_info = g_strdup_printf("pcapng: multi-section files not currently supported");
+ return FALSE;
+
+ case(BLOCK_TYPE_PB):
+ case(BLOCK_TYPE_SPB):
+ case(BLOCK_TYPE_EPB):
+ /* packet block - we've found a packet */
+ goto got_packet;
+
+ case(BLOCK_TYPE_IDB):
+ /* A new interface */
+ pcapng_debug0("pcapng_read: block type BLOCK_TYPE_IDB");
+ *data_offset += bytes_read;
+ pcapng_process_idb(wth, pcapng, &wblock);
+ break;
+
+ case(BLOCK_TYPE_NRB):
+ /* More name resolution entries */
+ pcapng_debug0("pcapng_read: block type BLOCK_TYPE_NRB");
+ *data_offset += bytes_read;
+ break;
+
+ case(BLOCK_TYPE_ISB):
+ /* Another interface statistics report */
+ pcapng_debug0("pcapng_read: block type BLOCK_TYPE_ISB");
+ *data_offset += bytes_read;
+ pcapng_debug1("pcapng_read: *data_offset is updated to %" G_GINT64_MODIFIER "d", *data_offset);
+ if (wth->interface_data->len < wblock.data.if_stats.interface_id) {
+ pcapng_debug1("pcapng_read: BLOCK_TYPE_ISB wblock.if_stats.interface_id %u > number_of_interfaces", wblock.data.if_stats.interface_id);
+ } else {
+ /* Get the interface description */
+ wtapng_if_descr = &g_array_index(wth->interface_data, wtapng_if_descr_t, wblock.data.if_stats.interface_id);
+ if (wtapng_if_descr->num_stat_entries == 0) {
+ /* First ISB found, no previous entry */
+ pcapng_debug0("pcapng_read: block type BLOCK_TYPE_ISB. First ISB found, no previous entry");
+ wtapng_if_descr->interface_statistics = g_array_new(FALSE, FALSE, sizeof(wtapng_if_stats_t));
+ }
+
+ if_stats.interface_id = wblock.data.if_stats.interface_id;
+ if_stats.ts_high = wblock.data.if_stats.ts_high;
+ if_stats.ts_low = wblock.data.if_stats.ts_low;
+ /* options */
+ if_stats.opt_comment = wblock.data.if_stats.opt_comment; /* NULL if not available */
+ if_stats.isb_starttime = wblock.data.if_stats.isb_starttime;
+ if_stats.isb_endtime = wblock.data.if_stats.isb_endtime;
+ if_stats.isb_ifrecv = wblock.data.if_stats.isb_ifrecv;
+ if_stats.isb_ifdrop = wblock.data.if_stats.isb_ifdrop;
+ if_stats.isb_filteraccept = wblock.data.if_stats.isb_filteraccept;
+ if_stats.isb_osdrop = wblock.data.if_stats.isb_osdrop;
+ if_stats.isb_usrdeliv = wblock.data.if_stats.isb_usrdeliv;
+
+ g_array_append_val(wtapng_if_descr->interface_statistics, if_stats);
+ wtapng_if_descr->num_stat_entries++;
}
+ break;
+
+ default:
+ /* XXX - improve handling of "unknown" blocks */
+ pcapng_debug1("pcapng_read: Unknown block type 0x%08x", wblock.type);
+ *data_offset += bytes_read;
+ pcapng_debug1("pcapng_read: *data_offset is updated to %" G_GINT64_MODIFIER "d", *data_offset);
+ break;
}
+ }
got_packet:
- /*pcapng_debug2("Read length: %u Packet length: %u", bytes_read, wth->phdr.caplen);*/
- pcapng_debug1("pcapng_read: data_offset is finally %" G_GINT64_MODIFIER "d", *data_offset + bytes_read);
+ /*pcapng_debug2("Read length: %u Packet length: %u", bytes_read, wth->phdr.caplen);*/
+ pcapng_debug1("pcapng_read: data_offset is finally %" G_GINT64_MODIFIER "d", *data_offset + bytes_read);
- return TRUE;
+ return TRUE;
}
/* classic wtap: seek to file position and read packet */
static gboolean
pcapng_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf,
- int *err, gchar **err_info)
+ struct wtap_pkthdr *phdr, Buffer *buf,
+ int *err, gchar **err_info)
{
- pcapng_t *pcapng = (pcapng_t *)wth->priv;
- guint64 bytes_read64;
- int bytes_read;
- wtapng_block_t wblock;
+ pcapng_t *pcapng = (pcapng_t *)wth->priv;
+ guint64 bytes_read64;
+ int bytes_read;
+ wtapng_block_t wblock;
- /* seek to the right file position */
- bytes_read64 = file_seek(wth->random_fh, seek_off, SEEK_SET, err);
- if (bytes_read64 <= 0) {
- return FALSE; /* Seek error */
- }
- pcapng_debug1("pcapng_seek_read: reading at offset %" G_GINT64_MODIFIER "u", seek_off);
+ /* seek to the right file position */
+ bytes_read64 = file_seek(wth->random_fh, seek_off, SEEK_SET, err);
+ if (bytes_read64 <= 0) {
+ return FALSE; /* Seek error */
+ }
+ pcapng_debug1("pcapng_seek_read: reading at offset %" G_GINT64_MODIFIER "u", seek_off);
- wblock.frame_buffer = buf;
- wblock.packet_header = phdr;
- wblock.file_encap = &wth->file_encap;
+ wblock.frame_buffer = buf;
+ wblock.packet_header = phdr;
+ wblock.file_encap = &wth->file_encap;
- /* read the block */
- bytes_read = pcapng_read_block(wth->random_fh, FALSE, pcapng, &wblock, err, err_info);
- if (bytes_read <= 0) {
- pcapng_debug3("pcapng_seek_read: couldn't read packet block (err=%d, errno=%d, bytes_read=%d).",
- *err, errno, bytes_read);
- return FALSE;
- }
+ /* read the block */
+ bytes_read = pcapng_read_block(wth->random_fh, FALSE, pcapng, &wblock, err, err_info);
+ if (bytes_read <= 0) {
+ pcapng_debug3("pcapng_seek_read: couldn't read packet block (err=%d, errno=%d, bytes_read=%d).",
+ *err, errno, bytes_read);
+ return FALSE;
+ }
- /* block must be a "Packet Block", an "Enhanced Packet Block",
- or a "Simple Packet Block" */
- if (wblock.type != BLOCK_TYPE_PB && wblock.type != BLOCK_TYPE_EPB &&
- wblock.type != BLOCK_TYPE_SPB) {
- pcapng_debug1("pcapng_seek_read: block type %u not PB/EPB/SPB", wblock.type);
- return FALSE;
- }
+ /* block must be a "Packet Block", an "Enhanced Packet Block",
+ or a "Simple Packet Block" */
+ if (wblock.type != BLOCK_TYPE_PB && wblock.type != BLOCK_TYPE_EPB &&
+ wblock.type != BLOCK_TYPE_SPB) {
+ pcapng_debug1("pcapng_seek_read: block type %u not PB/EPB/SPB", wblock.type);
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
@@ -2479,207 +2479,207 @@ pcapng_seek_read(wtap *wth, gint64 seek_off,
static void
pcapng_close(wtap *wth)
{
- pcapng_t *pcapng = (pcapng_t *)wth->priv;
+ pcapng_t *pcapng = (pcapng_t *)wth->priv;
- pcapng_debug0("pcapng_close: closing file");
- g_array_free(pcapng->interfaces, TRUE);
+ pcapng_debug0("pcapng_close: closing file");
+ g_array_free(pcapng->interfaces, TRUE);
}
static gboolean
pcapng_write_section_header_block(wtap_dumper *wdh, int *err)
{
- pcapng_block_header_t bh;
- pcapng_section_header_block_t shb;
- const guint32 zero_pad = 0;
- gboolean have_options = FALSE;
- struct option option_hdr; /* guint16 type, guint16 value_length; */
- guint32 options_total_length = 0;
- guint32 comment_len = 0, shb_hardware_len = 0, shb_os_len = 0, shb_user_appl_len = 0;
- guint32 comment_pad_len = 0, shb_hardware_pad_len = 0, shb_os_pad_len = 0, shb_user_appl_pad_len = 0;
-
- if (wdh->shb_hdr) {
- pcapng_debug0("pcapng_write_section_header_block: Have shb_hdr");
- /* Check if we should write comment option */
- if (wdh->shb_hdr->opt_comment) {
- have_options = TRUE;
- comment_len = (guint32)strlen(wdh->shb_hdr->opt_comment) & 0xffff;
- if ((comment_len % 4)) {
- comment_pad_len = 4 - (comment_len % 4);
- } else {
- comment_pad_len = 0;
- }
- options_total_length = options_total_length + comment_len + comment_pad_len + 4 /* comment options tag */ ;
- }
+ pcapng_block_header_t bh;
+ pcapng_section_header_block_t shb;
+ const guint32 zero_pad = 0;
+ gboolean have_options = FALSE;
+ struct option option_hdr; /* guint16 type, guint16 value_length; */
+ guint32 options_total_length = 0;
+ guint32 comment_len = 0, shb_hardware_len = 0, shb_os_len = 0, shb_user_appl_len = 0;
+ guint32 comment_pad_len = 0, shb_hardware_pad_len = 0, shb_os_pad_len = 0, shb_user_appl_pad_len = 0;
+
+ if (wdh->shb_hdr) {
+ pcapng_debug0("pcapng_write_section_header_block: Have shb_hdr");
+ /* Check if we should write comment option */
+ if (wdh->shb_hdr->opt_comment) {
+ have_options = TRUE;
+ comment_len = (guint32)strlen(wdh->shb_hdr->opt_comment) & 0xffff;
+ if ((comment_len % 4)) {
+ comment_pad_len = 4 - (comment_len % 4);
+ } else {
+ comment_pad_len = 0;
+ }
+ options_total_length = options_total_length + comment_len + comment_pad_len + 4 /* comment options tag */ ;
+ }
- /* Check if we should write shb_hardware option */
- if (wdh->shb_hdr->shb_hardware) {
- have_options = TRUE;
- shb_hardware_len = (guint32)strlen(wdh->shb_hdr->shb_hardware) & 0xffff;
- if ((shb_hardware_len % 4)) {
- shb_hardware_pad_len = 4 - (shb_hardware_len % 4);
- } else {
- shb_hardware_pad_len = 0;
- }
- options_total_length = options_total_length + shb_hardware_len + shb_hardware_pad_len + 4 /* options tag */ ;
- }
+ /* Check if we should write shb_hardware option */
+ if (wdh->shb_hdr->shb_hardware) {
+ have_options = TRUE;
+ shb_hardware_len = (guint32)strlen(wdh->shb_hdr->shb_hardware) & 0xffff;
+ if ((shb_hardware_len % 4)) {
+ shb_hardware_pad_len = 4 - (shb_hardware_len % 4);
+ } else {
+ shb_hardware_pad_len = 0;
+ }
+ options_total_length = options_total_length + shb_hardware_len + shb_hardware_pad_len + 4 /* options tag */ ;
+ }
- /* Check if we should write shb_os option */
- if (wdh->shb_hdr->shb_os) {
- have_options = TRUE;
- shb_os_len = (guint32)strlen(wdh->shb_hdr->shb_os) & 0xffff;
- if ((shb_os_len % 4)) {
- shb_os_pad_len = 4 - (shb_os_len % 4);
- } else {
- shb_os_pad_len = 0;
- }
- options_total_length = options_total_length + shb_os_len + shb_os_pad_len + 4 /* options tag */ ;
- }
+ /* Check if we should write shb_os option */
+ if (wdh->shb_hdr->shb_os) {
+ have_options = TRUE;
+ shb_os_len = (guint32)strlen(wdh->shb_hdr->shb_os) & 0xffff;
+ if ((shb_os_len % 4)) {
+ shb_os_pad_len = 4 - (shb_os_len % 4);
+ } else {
+ shb_os_pad_len = 0;
+ }
+ options_total_length = options_total_length + shb_os_len + shb_os_pad_len + 4 /* options tag */ ;
+ }
- /* Check if we should write shb_user_appl option */
- if (wdh->shb_hdr->shb_user_appl) {
- have_options = TRUE;
- shb_user_appl_len = (guint32)strlen(wdh->shb_hdr->shb_user_appl) & 0xffff;
- if ((shb_user_appl_len % 4)) {
- shb_user_appl_pad_len = 4 - (shb_user_appl_len % 4);
- } else {
- shb_user_appl_pad_len = 0;
- }
- options_total_length = options_total_length + shb_user_appl_len + shb_user_appl_pad_len + 4 /* options tag */ ;
- }
- if (have_options) {
- /* End-of-options tag */
- options_total_length += 4;
- }
+ /* Check if we should write shb_user_appl option */
+ if (wdh->shb_hdr->shb_user_appl) {
+ have_options = TRUE;
+ shb_user_appl_len = (guint32)strlen(wdh->shb_hdr->shb_user_appl) & 0xffff;
+ if ((shb_user_appl_len % 4)) {
+ shb_user_appl_pad_len = 4 - (shb_user_appl_len % 4);
+ } else {
+ shb_user_appl_pad_len = 0;
+ }
+ options_total_length = options_total_length + shb_user_appl_len + shb_user_appl_pad_len + 4 /* options tag */ ;
}
+ if (have_options) {
+ /* End-of-options tag */
+ options_total_length += 4;
+ }
+ }
- /* write block header */
- bh.block_type = BLOCK_TYPE_SHB;
- bh.block_total_length = (guint32)(sizeof(bh) + sizeof(shb) + options_total_length + 4);
- pcapng_debug2("pcapng_write_section_header_block: Total len %u, Options total len %u",bh.block_total_length, options_total_length);
+ /* write block header */
+ bh.block_type = BLOCK_TYPE_SHB;
+ bh.block_total_length = (guint32)(sizeof(bh) + sizeof(shb) + options_total_length + 4);
+ pcapng_debug2("pcapng_write_section_header_block: Total len %u, Options total len %u",bh.block_total_length, options_total_length);
- if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err))
- return FALSE;
- wdh->bytes_dumped += sizeof bh;
+ if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err))
+ return FALSE;
+ wdh->bytes_dumped += sizeof bh;
- /* write block fixed content */
- /* XXX - get these values from wblock? */
- shb.magic = 0x1A2B3C4D;
- shb.version_major = 1;
- shb.version_minor = 0;
- shb.section_length = -1;
+ /* write block fixed content */
+ /* XXX - get these values from wblock? */
+ shb.magic = 0x1A2B3C4D;
+ shb.version_major = 1;
+ shb.version_minor = 0;
+ shb.section_length = -1;
+
+ if (!wtap_dump_file_write(wdh, &shb, sizeof shb, err))
+ return FALSE;
+ wdh->bytes_dumped += sizeof shb;
+
+ /* XXX - write (optional) block options
+ * opt_comment 1
+ * shb_hardware 2
+ * shb_os 3
+ * shb_user_appl 4
+ */
+
+ if (comment_len) {
+ option_hdr.type = OPT_COMMENT;
+ option_hdr.value_length = comment_len;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+
+ /* Write the comments string */
+ pcapng_debug3("pcapng_write_section_header_block, comment:'%s' comment_len %u comment_pad_len %u" , wdh->shb_hdr->opt_comment, comment_len, comment_pad_len);
+ if (!wtap_dump_file_write(wdh, wdh->shb_hdr->opt_comment, comment_len, err))
+ return FALSE;
+ wdh->bytes_dumped += comment_len;
- if (!wtap_dump_file_write(wdh, &shb, sizeof shb, err))
+ /* write padding (if any) */
+ if (comment_pad_len != 0) {
+ if (!wtap_dump_file_write(wdh, &zero_pad, comment_pad_len, err))
return FALSE;
- wdh->bytes_dumped += sizeof shb;
+ wdh->bytes_dumped += comment_pad_len;
+ }
+ }
- /* XXX - write (optional) block options
- * opt_comment 1
- * shb_hardware 2
- * shb_os 3
- * shb_user_appl 4
- */
+ if (shb_hardware_len) {
+ option_hdr.type = OPT_SHB_HARDWARE;
+ option_hdr.value_length = shb_hardware_len;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
- if (comment_len) {
- option_hdr.type = OPT_COMMENT;
- option_hdr.value_length = comment_len;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write the comments string */
- pcapng_debug3("pcapng_write_section_header_block, comment:'%s' comment_len %u comment_pad_len %u" , wdh->shb_hdr->opt_comment, comment_len, comment_pad_len);
- if (!wtap_dump_file_write(wdh, wdh->shb_hdr->opt_comment, comment_len, err))
- return FALSE;
- wdh->bytes_dumped += comment_len;
-
- /* write padding (if any) */
- if (comment_pad_len != 0) {
- if (!wtap_dump_file_write(wdh, &zero_pad, comment_pad_len, err))
- return FALSE;
- wdh->bytes_dumped += comment_pad_len;
- }
- }
+ /* Write the string */
+ pcapng_debug3("pcapng_write_section_header_block, shb_hardware:'%s' shb_hardware_len %u shb_hardware_pad_len %u" , wdh->shb_hdr->shb_hardware, shb_hardware_len, shb_hardware_pad_len);
+ if (!wtap_dump_file_write(wdh, wdh->shb_hdr->shb_hardware, shb_hardware_len, err))
+ return FALSE;
+ wdh->bytes_dumped += shb_hardware_len;
- if (shb_hardware_len) {
- option_hdr.type = OPT_SHB_HARDWARE;
- option_hdr.value_length = shb_hardware_len;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write the string */
- pcapng_debug3("pcapng_write_section_header_block, shb_hardware:'%s' shb_hardware_len %u shb_hardware_pad_len %u" , wdh->shb_hdr->shb_hardware, shb_hardware_len, shb_hardware_pad_len);
- if (!wtap_dump_file_write(wdh, wdh->shb_hdr->shb_hardware, shb_hardware_len, err))
- return FALSE;
- wdh->bytes_dumped += shb_hardware_len;
-
- /* write padding (if any) */
- if (shb_hardware_pad_len != 0) {
- if (!wtap_dump_file_write(wdh, &zero_pad, shb_hardware_pad_len, err))
- return FALSE;
- wdh->bytes_dumped += shb_hardware_pad_len;
- }
+ /* write padding (if any) */
+ if (shb_hardware_pad_len != 0) {
+ if (!wtap_dump_file_write(wdh, &zero_pad, shb_hardware_pad_len, err))
+ return FALSE;
+ wdh->bytes_dumped += shb_hardware_pad_len;
}
+ }
- if (shb_os_len) {
- option_hdr.type = OPT_SHB_OS;
- option_hdr.value_length = shb_os_len;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write the string */
- pcapng_debug3("pcapng_write_section_header_block, shb_os:'%s' shb_os_len %u shb_os_pad_len %u" , wdh->shb_hdr->shb_os, shb_os_len, shb_os_pad_len);
- if (!wtap_dump_file_write(wdh, wdh->shb_hdr->shb_os, shb_os_len, err))
- return FALSE;
- wdh->bytes_dumped += shb_os_len;
-
- /* write padding (if any) */
- if (shb_os_pad_len != 0) {
- if (!wtap_dump_file_write(wdh, &zero_pad, shb_os_pad_len, err))
- return FALSE;
- wdh->bytes_dumped += shb_os_pad_len;
- }
- }
+ if (shb_os_len) {
+ option_hdr.type = OPT_SHB_OS;
+ option_hdr.value_length = shb_os_len;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
- if (shb_user_appl_len) {
- option_hdr.type = OPT_SHB_USERAPPL;
- option_hdr.value_length = shb_user_appl_len;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write the comments string */
- pcapng_debug3("pcapng_write_section_header_block, shb_user_appl:'%s' shb_user_appl_len %u shb_user_appl_pad_len %u" , wdh->shb_hdr->shb_user_appl, shb_user_appl_len, shb_user_appl_pad_len);
- if (!wtap_dump_file_write(wdh, wdh->shb_hdr->shb_user_appl, shb_user_appl_len, err))
- return FALSE;
- wdh->bytes_dumped += shb_user_appl_len;
-
- /* write padding (if any) */
- if (shb_user_appl_pad_len != 0) {
- if (!wtap_dump_file_write(wdh, &zero_pad, shb_user_appl_pad_len, err))
- return FALSE;
- wdh->bytes_dumped += shb_user_appl_pad_len;
- }
- }
+ /* Write the string */
+ pcapng_debug3("pcapng_write_section_header_block, shb_os:'%s' shb_os_len %u shb_os_pad_len %u" , wdh->shb_hdr->shb_os, shb_os_len, shb_os_pad_len);
+ if (!wtap_dump_file_write(wdh, wdh->shb_hdr->shb_os, shb_os_len, err))
+ return FALSE;
+ wdh->bytes_dumped += shb_os_len;
- /* Write end of options if we have otions */
- if (have_options) {
- option_hdr.type = OPT_EOFOPT;
- option_hdr.value_length = 0;
- if (!wtap_dump_file_write(wdh, &zero_pad, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
+ /* write padding (if any) */
+ if (shb_os_pad_len != 0) {
+ if (!wtap_dump_file_write(wdh, &zero_pad, shb_os_pad_len, err))
+ return FALSE;
+ wdh->bytes_dumped += shb_os_pad_len;
}
+ }
+
+ if (shb_user_appl_len) {
+ option_hdr.type = OPT_SHB_USERAPPL;
+ option_hdr.value_length = shb_user_appl_len;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+
+ /* Write the comments string */
+ pcapng_debug3("pcapng_write_section_header_block, shb_user_appl:'%s' shb_user_appl_len %u shb_user_appl_pad_len %u" , wdh->shb_hdr->shb_user_appl, shb_user_appl_len, shb_user_appl_pad_len);
+ if (!wtap_dump_file_write(wdh, wdh->shb_hdr->shb_user_appl, shb_user_appl_len, err))
+ return FALSE;
+ wdh->bytes_dumped += shb_user_appl_len;
- /* write block footer */
- if (!wtap_dump_file_write(wdh, &bh.block_total_length,
- sizeof bh.block_total_length, err))
+ /* write padding (if any) */
+ if (shb_user_appl_pad_len != 0) {
+ if (!wtap_dump_file_write(wdh, &zero_pad, shb_user_appl_pad_len, err))
return FALSE;
- wdh->bytes_dumped += sizeof bh.block_total_length;
+ wdh->bytes_dumped += shb_user_appl_pad_len;
+ }
+ }
- return TRUE;
+ /* Write end of options if we have otions */
+ if (have_options) {
+ option_hdr.type = OPT_EOFOPT;
+ option_hdr.value_length = 0;
+ if (!wtap_dump_file_write(wdh, &zero_pad, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+ }
+
+ /* write block footer */
+ if (!wtap_dump_file_write(wdh, &bh.block_total_length,
+ sizeof bh.block_total_length, err))
+ return FALSE;
+ wdh->bytes_dumped += sizeof bh.block_total_length;
+
+ return TRUE;
}
#define IDB_OPT_IF_NAME 2
@@ -2692,340 +2692,340 @@ pcapng_write_section_header_block(wtap_dumper *wdh, int *err)
static gboolean
pcapng_write_if_descr_block(wtap_dumper *wdh, wtapng_if_descr_t *int_data, int *err)
{
- pcapng_block_header_t bh;
- pcapng_interface_description_block_t idb;
- const guint32 zero_pad = 0;
- gboolean have_options = FALSE;
- struct option option_hdr; /* guint16 type, guint16 value_length; */
- guint32 options_total_length = 0;
- guint32 comment_len = 0, if_name_len = 0, if_description_len = 0 , if_os_len = 0, if_filter_str_len = 0;
- guint32 comment_pad_len = 0, if_name_pad_len = 0, if_description_pad_len = 0, if_os_pad_len = 0, if_filter_str_pad_len = 0;
-
-
- pcapng_debug3("pcapng_write_if_descr_block: encap = %d (%s), snaplen = %d",
- int_data->link_type,
- wtap_encap_string(wtap_pcap_encap_to_wtap_encap(int_data->link_type)),
- int_data->snap_len);
-
- if (int_data->link_type == (guint16)-1) {
- *err = WTAP_ERR_UNSUPPORTED_ENCAP;
- return FALSE;
- }
+ pcapng_block_header_t bh;
+ pcapng_interface_description_block_t idb;
+ const guint32 zero_pad = 0;
+ gboolean have_options = FALSE;
+ struct option option_hdr; /* guint16 type, guint16 value_length; */
+ guint32 options_total_length = 0;
+ guint32 comment_len = 0, if_name_len = 0, if_description_len = 0 , if_os_len = 0, if_filter_str_len = 0;
+ guint32 comment_pad_len = 0, if_name_pad_len = 0, if_description_pad_len = 0, if_os_pad_len = 0, if_filter_str_pad_len = 0;
+
+
+ pcapng_debug3("pcapng_write_if_descr_block: encap = %d (%s), snaplen = %d",
+ int_data->link_type,
+ wtap_encap_string(wtap_pcap_encap_to_wtap_encap(int_data->link_type)),
+ int_data->snap_len);
+
+ if (int_data->link_type == (guint16)-1) {
+ *err = WTAP_ERR_UNSUPPORTED_ENCAP;
+ return FALSE;
+ }
- /* Calculate options length */
- if (int_data->opt_comment) {
- have_options = TRUE;
- comment_len = (guint32)strlen(int_data->opt_comment) & 0xffff;
- if ((comment_len % 4)) {
- comment_pad_len = 4 - (comment_len % 4);
- } else {
- comment_pad_len = 0;
- }
- options_total_length = options_total_length + comment_len + comment_pad_len + 4 /* comment options tag */ ;
+ /* Calculate options length */
+ if (int_data->opt_comment) {
+ have_options = TRUE;
+ comment_len = (guint32)strlen(int_data->opt_comment) & 0xffff;
+ if ((comment_len % 4)) {
+ comment_pad_len = 4 - (comment_len % 4);
+ } else {
+ comment_pad_len = 0;
}
+ options_total_length = options_total_length + comment_len + comment_pad_len + 4 /* comment options tag */ ;
+ }
- /*
- * if_name 2 A UTF-8 string containing the name of the device used to capture data.
- */
- if (int_data->if_name) {
- have_options = TRUE;
- if_name_len = (guint32)strlen(int_data->if_name) & 0xffff;
- if ((if_name_len % 4)) {
- if_name_pad_len = 4 - (if_name_len % 4);
- } else {
- if_name_pad_len = 0;
- }
- options_total_length = options_total_length + if_name_len + if_name_pad_len + 4 /* comment options tag */ ;
+ /*
+ * if_name 2 A UTF-8 string containing the name of the device used to capture data.
+ */
+ if (int_data->if_name) {
+ have_options = TRUE;
+ if_name_len = (guint32)strlen(int_data->if_name) & 0xffff;
+ if ((if_name_len % 4)) {
+ if_name_pad_len = 4 - (if_name_len % 4);
+ } else {
+ if_name_pad_len = 0;
}
+ options_total_length = options_total_length + if_name_len + if_name_pad_len + 4 /* comment options tag */ ;
+ }
- /*
- * if_description 3 A UTF-8 string containing the description of the device used to capture data.
- */
- if (int_data->if_description) {
- have_options = TRUE;
- if_description_len = (guint32)strlen(int_data->if_description) & 0xffff;
- if ((if_description_len % 4)) {
- if_description_pad_len = 4 - (if_description_len % 4);
- } else {
- if_description_pad_len = 0;
- }
- options_total_length = options_total_length + if_description_len + if_description_pad_len + 4 /* comment options tag */ ;
- }
- /* Currently not handled
- * if_IPv4addr 4 Interface network address and netmask.
- * if_IPv6addr 5 Interface network address and prefix length (stored in the last byte).
- * if_MACaddr 6 Interface Hardware MAC address (48 bits). 00 01 02 03 04 05
- * if_EUIaddr 7 Interface Hardware EUI address (64 bits), if available. TODO: give a good example
- */
- /*
- * if_speed 8 Interface speed (in bps). 100000000 for 100Mbps
- */
- if (int_data->if_speed != 0) {
- have_options = TRUE;
- options_total_length = options_total_length + 8 + 4;
- }
- /*
- * if_tsresol 9 Resolution of timestamps.
- */
- if (int_data->if_tsresol != 0) {
- have_options = TRUE;
- options_total_length = options_total_length + 4 + 4;
- }
- /* Not used
- * if_tzone 10 Time zone for GMT support (TODO: specify better). TODO: give a good example
- */
- /*
- * if_filter 11 The filter (e.g. "capture only TCP traffic") used to capture traffic.
- * The first byte of the Option Data keeps a code of the filter used (e.g. if this is a libpcap string, or BPF bytecode, and more).
- */
- if (int_data->if_filter_str) {
- have_options = TRUE;
- if_filter_str_len = (guint32)(strlen(int_data->if_filter_str) + 1) & 0xffff;
- if ((if_filter_str_len % 4)) {
- if_filter_str_pad_len = 4 - (if_filter_str_len % 4);
- } else {
- if_filter_str_pad_len = 0;
- }
- options_total_length = options_total_length + if_filter_str_len + if_filter_str_pad_len + 4 /* comment options tag */ ;
+ /*
+ * if_description 3 A UTF-8 string containing the description of the device used to capture data.
+ */
+ if (int_data->if_description) {
+ have_options = TRUE;
+ if_description_len = (guint32)strlen(int_data->if_description) & 0xffff;
+ if ((if_description_len % 4)) {
+ if_description_pad_len = 4 - (if_description_len % 4);
+ } else {
+ if_description_pad_len = 0;
}
- /*
- * if_os 12 A UTF-8 string containing the name of the operating system of the machine in which this interface is installed.
- */
- if (int_data->if_os) {
- have_options = TRUE;
- if_os_len = (guint32)strlen(int_data->if_os) & 0xffff;
- if ((if_os_len % 4)) {
- if_os_pad_len = 4 - (if_os_len % 4);
- } else {
- if_os_pad_len = 0;
- }
- options_total_length = options_total_length + if_os_len + if_os_pad_len + 4 /* comment options tag */ ;
+ options_total_length = options_total_length + if_description_len + if_description_pad_len + 4 /* comment options tag */ ;
+ }
+ /* Currently not handled
+ * if_IPv4addr 4 Interface network address and netmask.
+ * if_IPv6addr 5 Interface network address and prefix length (stored in the last byte).
+ * if_MACaddr 6 Interface Hardware MAC address (48 bits). 00 01 02 03 04 05
+ * if_EUIaddr 7 Interface Hardware EUI address (64 bits), if available. TODO: give a good example
+ */
+ /*
+ * if_speed 8 Interface speed (in bps). 100000000 for 100Mbps
+ */
+ if (int_data->if_speed != 0) {
+ have_options = TRUE;
+ options_total_length = options_total_length + 8 + 4;
+ }
+ /*
+ * if_tsresol 9 Resolution of timestamps.
+ */
+ if (int_data->if_tsresol != 0) {
+ have_options = TRUE;
+ options_total_length = options_total_length + 4 + 4;
+ }
+ /* Not used
+ * if_tzone 10 Time zone for GMT support (TODO: specify better). TODO: give a good example
+ */
+ /*
+ * if_filter 11 The filter (e.g. "capture only TCP traffic") used to capture traffic.
+ * The first byte of the Option Data keeps a code of the filter used (e.g. if this is a libpcap string, or BPF bytecode, and more).
+ */
+ if (int_data->if_filter_str) {
+ have_options = TRUE;
+ if_filter_str_len = (guint32)(strlen(int_data->if_filter_str) + 1) & 0xffff;
+ if ((if_filter_str_len % 4)) {
+ if_filter_str_pad_len = 4 - (if_filter_str_len % 4);
+ } else {
+ if_filter_str_pad_len = 0;
}
- /*
- * if_fcslen 13 An integer value that specified the length of the Frame Check Sequence (in bits) for this interface.
- * -1 if unknown or changes between packets, opt 13 An integer value that specified the length of the Frame Check Sequence (in bits) for this interface.
- */
- if (int_data->if_fcslen != 0) {
+ options_total_length = options_total_length + if_filter_str_len + if_filter_str_pad_len + 4 /* comment options tag */ ;
+ }
+ /*
+ * if_os 12 A UTF-8 string containing the name of the operating system of the machine in which this interface is installed.
+ */
+ if (int_data->if_os) {
+ have_options = TRUE;
+ if_os_len = (guint32)strlen(int_data->if_os) & 0xffff;
+ if ((if_os_len % 4)) {
+ if_os_pad_len = 4 - (if_os_len % 4);
+ } else {
+ if_os_pad_len = 0;
}
- /* Not used
- * if_tsoffset 14 A 64 bits integer value that specifies an offset (in seconds) that must be added to the timestamp of each packet
- * to obtain the absolute timestamp of a packet. If the option is missing, the timestamps stored in the packet must be considered absolute timestamps.
- */
+ options_total_length = options_total_length + if_os_len + if_os_pad_len + 4 /* comment options tag */ ;
+ }
+ /*
+ * if_fcslen 13 An integer value that specified the length of the Frame Check Sequence (in bits) for this interface.
+ * -1 if unknown or changes between packets, opt 13 An integer value that specified the length of the Frame Check Sequence (in bits) for this interface.
+ */
+ if (int_data->if_fcslen != 0) {
+ }
+ /* Not used
+ * if_tsoffset 14 A 64 bits integer value that specifies an offset (in seconds) that must be added to the timestamp of each packet
+ * to obtain the absolute timestamp of a packet. If the option is missing, the timestamps stored in the packet must be considered absolute timestamps.
+ */
+
+ if (have_options) {
+ /* End-of-options tag */
+ options_total_length += 4;
+ }
- if (have_options) {
- /* End-of-options tag */
- options_total_length += 4;
- }
+ /* write block header */
+ bh.block_type = BLOCK_TYPE_IDB;
+ bh.block_total_length = (guint32)(sizeof(bh) + sizeof(idb) + options_total_length + 4);
- /* write block header */
- bh.block_type = BLOCK_TYPE_IDB;
- bh.block_total_length = (guint32)(sizeof(bh) + sizeof(idb) + options_total_length + 4);
+ if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err))
+ return FALSE;
+ wdh->bytes_dumped += sizeof bh;
- if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err))
- return FALSE;
- wdh->bytes_dumped += sizeof bh;
+ /* write block fixed content */
+ idb.linktype = int_data->link_type;
+ idb.reserved = 0;
+ idb.snaplen = int_data->snap_len;
- /* write block fixed content */
- idb.linktype = int_data->link_type;
- idb.reserved = 0;
- idb.snaplen = int_data->snap_len;
+ if (!wtap_dump_file_write(wdh, &idb, sizeof idb, err))
+ return FALSE;
+ wdh->bytes_dumped += sizeof idb;
+
+ /* XXX - write (optional) block options */
+ if (comment_len != 0) {
+ option_hdr.type = OPT_COMMENT;
+ option_hdr.value_length = comment_len;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+
+ /* Write the comments string */
+ pcapng_debug3("pcapng_write_if_descr_block, comment:'%s' comment_len %u comment_pad_len %u" , int_data->opt_comment, comment_len, comment_pad_len);
+ if (!wtap_dump_file_write(wdh, int_data->opt_comment, comment_len, err))
+ return FALSE;
+ wdh->bytes_dumped += comment_len;
- if (!wtap_dump_file_write(wdh, &idb, sizeof idb, err))
+ /* write padding (if any) */
+ if (comment_pad_len != 0) {
+ if (!wtap_dump_file_write(wdh, &zero_pad, comment_pad_len, err))
return FALSE;
- wdh->bytes_dumped += sizeof idb;
-
- /* XXX - write (optional) block options */
- if (comment_len != 0) {
- option_hdr.type = OPT_COMMENT;
- option_hdr.value_length = comment_len;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write the comments string */
- pcapng_debug3("pcapng_write_if_descr_block, comment:'%s' comment_len %u comment_pad_len %u" , int_data->opt_comment, comment_len, comment_pad_len);
- if (!wtap_dump_file_write(wdh, int_data->opt_comment, comment_len, err))
- return FALSE;
- wdh->bytes_dumped += comment_len;
-
- /* write padding (if any) */
- if (comment_pad_len != 0) {
- if (!wtap_dump_file_write(wdh, &zero_pad, comment_pad_len, err))
- return FALSE;
- wdh->bytes_dumped += comment_pad_len;
- }
- }
- /*
- * if_name 2 A UTF-8 string containing the name of the device used to capture data.
- */
- if (if_name_len !=0) {
- option_hdr.type = IDB_OPT_IF_NAME;
- option_hdr.value_length = if_name_len;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write the comments string */
- pcapng_debug3("pcapng_write_if_descr_block, if_name:'%s' if_name_len %u if_name_pad_len %u" , int_data->if_name, if_name_len, if_name_pad_len);
- if (!wtap_dump_file_write(wdh, int_data->if_name, if_name_len, err))
- return FALSE;
- wdh->bytes_dumped += if_name_len;
-
- /* write padding (if any) */
- if (if_name_pad_len != 0) {
- if (!wtap_dump_file_write(wdh, &zero_pad, if_name_pad_len, err))
- return FALSE;
- wdh->bytes_dumped += if_name_pad_len;
- }
- }
- /*
- * if_description 3 A UTF-8 string containing the description of the device used to capture data.
- */
- if (if_description_len != 0) {
- option_hdr.type = IDB_OPT_IF_NAME;
- option_hdr.value_length = if_description_len;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write the comments string */
- pcapng_debug3("pcapng_write_if_descr_block, if_description:'%s' if_description_len %u if_description_pad_len %u" , int_data->if_description, if_description_len, if_description_pad_len);
- if (!wtap_dump_file_write(wdh, int_data->if_description, if_description_len, err))
- return FALSE;
- wdh->bytes_dumped += if_description_len;
-
- /* write padding (if any) */
- if (if_description_pad_len != 0) {
- if (!wtap_dump_file_write(wdh, &zero_pad, if_description_pad_len, err))
- return FALSE;
- wdh->bytes_dumped += if_description_pad_len;
- }
+ wdh->bytes_dumped += comment_pad_len;
}
- /* Currently not handled
- * if_IPv4addr 4 Interface network address and netmask.
- * if_IPv6addr 5 Interface network address and prefix length (stored in the last byte).
- * if_MACaddr 6 Interface Hardware MAC address (48 bits). 00 01 02 03 04 05
- * if_EUIaddr 7 Interface Hardware EUI address (64 bits), if available. TODO: give a good example
- */
- /*
- * if_speed 8 Interface speed (in bps). 100000000 for 100Mbps
- */
- if (int_data->if_speed != 0) {
- option_hdr.type = IDB_OPT_IF_SPEED;
- option_hdr.value_length = 8;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write the comments string */
- pcapng_debug1("pcapng_write_if_descr_block: if_speed %" G_GINT64_MODIFIER "u (bps)", int_data->if_speed);
- if (!wtap_dump_file_write(wdh, &int_data->if_speed, sizeof(guint64), err))
- return FALSE;
- wdh->bytes_dumped += 8;
- }
- /*
- * if_tsresol 9 Resolution of timestamps.
- * default is 6 for microsecond resolution, opt 9 Resolution of timestamps.
- * If the Most Significant Bit is equal to zero, the remaining bits indicates
- * the resolution of the timestamp as as a negative power of 10
- */
- if (int_data->if_tsresol != 0) {
- option_hdr.type = IDB_OPT_IF_TSRESOL;
- option_hdr.value_length = 1;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write the time stamp resolution */
- pcapng_debug1("pcapng_write_if_descr_block: if_tsresol %u", int_data->if_tsresol);
- if (!wtap_dump_file_write(wdh, &int_data->if_tsresol, 1, err))
- return FALSE;
- wdh->bytes_dumped += 1;
- if (!wtap_dump_file_write(wdh, &zero_pad, 3, err))
- return FALSE;
- wdh->bytes_dumped += 3;
+ }
+ /*
+ * if_name 2 A UTF-8 string containing the name of the device used to capture data.
+ */
+ if (if_name_len !=0) {
+ option_hdr.type = IDB_OPT_IF_NAME;
+ option_hdr.value_length = if_name_len;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+
+ /* Write the comments string */
+ pcapng_debug3("pcapng_write_if_descr_block, if_name:'%s' if_name_len %u if_name_pad_len %u" , int_data->if_name, if_name_len, if_name_pad_len);
+ if (!wtap_dump_file_write(wdh, int_data->if_name, if_name_len, err))
+ return FALSE;
+ wdh->bytes_dumped += if_name_len;
+
+ /* write padding (if any) */
+ if (if_name_pad_len != 0) {
+ if (!wtap_dump_file_write(wdh, &zero_pad, if_name_pad_len, err))
+ return FALSE;
+ wdh->bytes_dumped += if_name_pad_len;
}
- /* not used
- * if_tzone 10 Time zone for GMT support (TODO: specify better). TODO: give a good example
- */
- /*
- * if_filter 11 The filter (e.g. "capture only TCP traffic") used to capture traffic.
- */
- /* Libpcap string variant */
- if (if_filter_str_len !=0) {
- option_hdr.type = IDB_OPT_IF_FILTER;
- option_hdr.value_length = if_filter_str_len;
- /* if_filter_str_len includes the leading byte indicating filter type (libpcap str or BPF code) */
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write the zero indicating libpcap filter variant */
- if (!wtap_dump_file_write(wdh, &zero_pad, 1, err))
- return FALSE;
- wdh->bytes_dumped += 1;
-
- /* Write the comments string */
- pcapng_debug3("pcapng_write_if_descr_block, if_filter_str:'%s' if_filter_str_len %u if_filter_str_pad_len %u" , int_data->if_filter_str, if_filter_str_len, if_filter_str_pad_len);
- /* if_filter_str_len includes the leading byte indicating filter type (libpcap str or BPF code) */
- if (!wtap_dump_file_write(wdh, int_data->if_filter_str, if_filter_str_len-1, err))
- return FALSE;
- wdh->bytes_dumped += if_filter_str_len - 1;
-
- /* write padding (if any) */
- if (if_filter_str_pad_len != 0) {
- if (!wtap_dump_file_write(wdh, &zero_pad, if_filter_str_pad_len, err))
- return FALSE;
- wdh->bytes_dumped += if_filter_str_pad_len;
- }
+ }
+ /*
+ * if_description 3 A UTF-8 string containing the description of the device used to capture data.
+ */
+ if (if_description_len != 0) {
+ option_hdr.type = IDB_OPT_IF_NAME;
+ option_hdr.value_length = if_description_len;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+
+ /* Write the comments string */
+ pcapng_debug3("pcapng_write_if_descr_block, if_description:'%s' if_description_len %u if_description_pad_len %u" , int_data->if_description, if_description_len, if_description_pad_len);
+ if (!wtap_dump_file_write(wdh, int_data->if_description, if_description_len, err))
+ return FALSE;
+ wdh->bytes_dumped += if_description_len;
+
+ /* write padding (if any) */
+ if (if_description_pad_len != 0) {
+ if (!wtap_dump_file_write(wdh, &zero_pad, if_description_pad_len, err))
+ return FALSE;
+ wdh->bytes_dumped += if_description_pad_len;
}
- /*
- * if_os 12 A UTF-8 string containing the name of the operating system of the machine in which this interface is installed.
- */
- if (if_os_len != 0) {
- option_hdr.type = IDB_OPT_IF_OS;
- option_hdr.value_length = if_os_len;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write the comments string */
- pcapng_debug3("pcapng_write_if_descr_block, if_os:'%s' if_os_len %u if_os_pad_len %u" , int_data->if_os, if_os_len, if_os_pad_len);
- if (!wtap_dump_file_write(wdh, int_data->if_os, if_os_len, err))
- return FALSE;
- wdh->bytes_dumped += if_os_len;
-
- /* write padding (if any) */
- if (if_os_pad_len != 0) {
- if (!wtap_dump_file_write(wdh, &zero_pad, if_os_pad_len, err))
- return FALSE;
- wdh->bytes_dumped += if_os_pad_len;
- }
+ }
+ /* Currently not handled
+ * if_IPv4addr 4 Interface network address and netmask.
+ * if_IPv6addr 5 Interface network address and prefix length (stored in the last byte).
+ * if_MACaddr 6 Interface Hardware MAC address (48 bits). 00 01 02 03 04 05
+ * if_EUIaddr 7 Interface Hardware EUI address (64 bits), if available. TODO: give a good example
+ */
+ /*
+ * if_speed 8 Interface speed (in bps). 100000000 for 100Mbps
+ */
+ if (int_data->if_speed != 0) {
+ option_hdr.type = IDB_OPT_IF_SPEED;
+ option_hdr.value_length = 8;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+
+ /* Write the comments string */
+ pcapng_debug1("pcapng_write_if_descr_block: if_speed %" G_GINT64_MODIFIER "u (bps)", int_data->if_speed);
+ if (!wtap_dump_file_write(wdh, &int_data->if_speed, sizeof(guint64), err))
+ return FALSE;
+ wdh->bytes_dumped += 8;
+ }
+ /*
+ * if_tsresol 9 Resolution of timestamps.
+ * default is 6 for microsecond resolution, opt 9 Resolution of timestamps.
+ * If the Most Significant Bit is equal to zero, the remaining bits indicates
+ * the resolution of the timestamp as as a negative power of 10
+ */
+ if (int_data->if_tsresol != 0) {
+ option_hdr.type = IDB_OPT_IF_TSRESOL;
+ option_hdr.value_length = 1;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+
+ /* Write the time stamp resolution */
+ pcapng_debug1("pcapng_write_if_descr_block: if_tsresol %u", int_data->if_tsresol);
+ if (!wtap_dump_file_write(wdh, &int_data->if_tsresol, 1, err))
+ return FALSE;
+ wdh->bytes_dumped += 1;
+ if (!wtap_dump_file_write(wdh, &zero_pad, 3, err))
+ return FALSE;
+ wdh->bytes_dumped += 3;
+ }
+ /* not used
+ * if_tzone 10 Time zone for GMT support (TODO: specify better). TODO: give a good example
+ */
+ /*
+ * if_filter 11 The filter (e.g. "capture only TCP traffic") used to capture traffic.
+ */
+ /* Libpcap string variant */
+ if (if_filter_str_len !=0) {
+ option_hdr.type = IDB_OPT_IF_FILTER;
+ option_hdr.value_length = if_filter_str_len;
+ /* if_filter_str_len includes the leading byte indicating filter type (libpcap str or BPF code) */
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+
+ /* Write the zero indicating libpcap filter variant */
+ if (!wtap_dump_file_write(wdh, &zero_pad, 1, err))
+ return FALSE;
+ wdh->bytes_dumped += 1;
+
+ /* Write the comments string */
+ pcapng_debug3("pcapng_write_if_descr_block, if_filter_str:'%s' if_filter_str_len %u if_filter_str_pad_len %u" , int_data->if_filter_str, if_filter_str_len, if_filter_str_pad_len);
+ /* if_filter_str_len includes the leading byte indicating filter type (libpcap str or BPF code) */
+ if (!wtap_dump_file_write(wdh, int_data->if_filter_str, if_filter_str_len-1, err))
+ return FALSE;
+ wdh->bytes_dumped += if_filter_str_len - 1;
+
+ /* write padding (if any) */
+ if (if_filter_str_pad_len != 0) {
+ if (!wtap_dump_file_write(wdh, &zero_pad, if_filter_str_pad_len, err))
+ return FALSE;
+ wdh->bytes_dumped += if_filter_str_pad_len;
}
+ }
+ /*
+ * if_os 12 A UTF-8 string containing the name of the operating system of the machine in which this interface is installed.
+ */
+ if (if_os_len != 0) {
+ option_hdr.type = IDB_OPT_IF_OS;
+ option_hdr.value_length = if_os_len;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+
+ /* Write the comments string */
+ pcapng_debug3("pcapng_write_if_descr_block, if_os:'%s' if_os_len %u if_os_pad_len %u" , int_data->if_os, if_os_len, if_os_pad_len);
+ if (!wtap_dump_file_write(wdh, int_data->if_os, if_os_len, err))
+ return FALSE;
+ wdh->bytes_dumped += if_os_len;
- if (have_options) {
- option_hdr.type = OPT_EOFOPT;
- option_hdr.value_length = 0;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
+ /* write padding (if any) */
+ if (if_os_pad_len != 0) {
+ if (!wtap_dump_file_write(wdh, &zero_pad, if_os_pad_len, err))
+ return FALSE;
+ wdh->bytes_dumped += if_os_pad_len;
}
+ }
- /*
- * if_fcslen 13 An integer value that specified the length of the Frame Check Sequence (in bits) for this interface.
- */
- /*
- * if_tsoffset 14 A 64 bits integer value that specifies an offset (in seconds) that must be added to the timestamp of each packet
- * to obtain the absolute timestamp of a packet. If the option is missing, the timestamps stored in the packet must be considered absolute timestamps.
- */
+ if (have_options) {
+ option_hdr.type = OPT_EOFOPT;
+ option_hdr.value_length = 0;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+ }
- /* write block footer */
- if (!wtap_dump_file_write(wdh, &bh.block_total_length,
- sizeof bh.block_total_length, err))
- return FALSE;
- wdh->bytes_dumped += sizeof bh.block_total_length;
+ /*
+ * if_fcslen 13 An integer value that specified the length of the Frame Check Sequence (in bits) for this interface.
+ */
+ /*
+ * if_tsoffset 14 A 64 bits integer value that specifies an offset (in seconds) that must be added to the timestamp of each packet
+ * to obtain the absolute timestamp of a packet. If the option is missing, the timestamps stored in the packet must be considered absolute timestamps.
+ */
+
+ /* write block footer */
+ if (!wtap_dump_file_write(wdh, &bh.block_total_length,
+ sizeof bh.block_total_length, err))
+ return FALSE;
+ wdh->bytes_dumped += sizeof bh.block_total_length;
- return TRUE;
+ return TRUE;
}
#define ISB_STARTTIME 2
@@ -3040,423 +3040,423 @@ static gboolean
pcapng_write_interface_statistics_block(wtap_dumper *wdh, wtapng_if_stats_t *if_stats, int *err)
{
- pcapng_block_header_t bh;
- pcapng_interface_statistics_block_t isb;
- const guint32 zero_pad = 0;
- gboolean have_options = FALSE;
- struct option option_hdr; /* guint16 type, guint16 value_length; */
- guint32 options_total_length = 0;
- guint32 comment_len = 0;
- guint32 comment_pad_len = 0;
-
- pcapng_debug0("pcapng_write_interface_statistics_block");
-
-
- /* Calculate options length */
- if (if_stats->opt_comment) {
- have_options = TRUE;
- comment_len = (guint32)strlen(if_stats->opt_comment) & 0xffff;
- if ((comment_len % 4)) {
- comment_pad_len = 4 - (comment_len % 4);
- } else {
- comment_pad_len = 0;
- }
- options_total_length = options_total_length + comment_len + comment_pad_len + 4 /* comment options tag */ ;
- }
- /*guint64 isb_starttime */
- if (if_stats->isb_starttime != 0) {
- have_options = TRUE;
- options_total_length = options_total_length + 8 + 4 /* options tag */ ;
- }
- /*guint64 isb_endtime */
- if (if_stats->isb_endtime != 0) {
- have_options = TRUE;
- options_total_length = options_total_length + 8 + 4 /* options tag */ ;
- }
- /*guint64 isb_ifrecv */
- if (if_stats->isb_ifrecv != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
- have_options = TRUE;
- options_total_length = options_total_length + 8 + 4 /* options tag */ ;
- }
- /*guint64 isb_ifdrop */
- if (if_stats->isb_ifdrop != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
- have_options = TRUE;
- options_total_length = options_total_length + 8 + 4 /* options tag */ ;
- }
- /*guint64 isb_filteraccept */
- if (if_stats->isb_filteraccept != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
- have_options = TRUE;
- options_total_length = options_total_length + 8 + 4 /* options tag */ ;
- }
- /*guint64 isb_osdrop */
- if (if_stats->isb_osdrop != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
- have_options = TRUE;
- options_total_length = options_total_length + 8 + 4 /* options tag */ ;
- }
- /*guint64 isb_usrdeliv */
- if (if_stats->isb_usrdeliv != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
- have_options = TRUE;
- options_total_length = options_total_length + 8 + 4 /* options tag */ ;
+ pcapng_block_header_t bh;
+ pcapng_interface_statistics_block_t isb;
+ const guint32 zero_pad = 0;
+ gboolean have_options = FALSE;
+ struct option option_hdr; /* guint16 type, guint16 value_length; */
+ guint32 options_total_length = 0;
+ guint32 comment_len = 0;
+ guint32 comment_pad_len = 0;
+
+ pcapng_debug0("pcapng_write_interface_statistics_block");
+
+
+ /* Calculate options length */
+ if (if_stats->opt_comment) {
+ have_options = TRUE;
+ comment_len = (guint32)strlen(if_stats->opt_comment) & 0xffff;
+ if ((comment_len % 4)) {
+ comment_pad_len = 4 - (comment_len % 4);
+ } else {
+ comment_pad_len = 0;
}
+ options_total_length = options_total_length + comment_len + comment_pad_len + 4 /* comment options tag */ ;
+ }
+ /*guint64 isb_starttime */
+ if (if_stats->isb_starttime != 0) {
+ have_options = TRUE;
+ options_total_length = options_total_length + 8 + 4 /* options tag */ ;
+ }
+ /*guint64 isb_endtime */
+ if (if_stats->isb_endtime != 0) {
+ have_options = TRUE;
+ options_total_length = options_total_length + 8 + 4 /* options tag */ ;
+ }
+ /*guint64 isb_ifrecv */
+ if (if_stats->isb_ifrecv != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
+ have_options = TRUE;
+ options_total_length = options_total_length + 8 + 4 /* options tag */ ;
+ }
+ /*guint64 isb_ifdrop */
+ if (if_stats->isb_ifdrop != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
+ have_options = TRUE;
+ options_total_length = options_total_length + 8 + 4 /* options tag */ ;
+ }
+ /*guint64 isb_filteraccept */
+ if (if_stats->isb_filteraccept != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
+ have_options = TRUE;
+ options_total_length = options_total_length + 8 + 4 /* options tag */ ;
+ }
+ /*guint64 isb_osdrop */
+ if (if_stats->isb_osdrop != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
+ have_options = TRUE;
+ options_total_length = options_total_length + 8 + 4 /* options tag */ ;
+ }
+ /*guint64 isb_usrdeliv */
+ if (if_stats->isb_usrdeliv != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
+ have_options = TRUE;
+ options_total_length = options_total_length + 8 + 4 /* options tag */ ;
+ }
- /* write block header */
- if (have_options) {
- /* End-of-optios tag */
- options_total_length += 4;
- }
+ /* write block header */
+ if (have_options) {
+ /* End-of-optios tag */
+ options_total_length += 4;
+ }
- /* write block header */
- bh.block_type = BLOCK_TYPE_ISB;
- bh.block_total_length = (guint32)(sizeof(bh) + sizeof(isb) + options_total_length + 4);
+ /* write block header */
+ bh.block_type = BLOCK_TYPE_ISB;
+ bh.block_total_length = (guint32)(sizeof(bh) + sizeof(isb) + options_total_length + 4);
- if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err))
- return FALSE;
- wdh->bytes_dumped += sizeof bh;
+ if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err))
+ return FALSE;
+ wdh->bytes_dumped += sizeof bh;
- /* write block fixed content */
- isb.interface_id = if_stats->interface_id;
- isb.timestamp_high = if_stats->ts_high;
- isb.timestamp_low = if_stats->ts_low;
+ /* write block fixed content */
+ isb.interface_id = if_stats->interface_id;
+ isb.timestamp_high = if_stats->ts_high;
+ isb.timestamp_low = if_stats->ts_low;
- if (!wtap_dump_file_write(wdh, &isb, sizeof isb, err))
+ if (!wtap_dump_file_write(wdh, &isb, sizeof isb, err))
+ return FALSE;
+ wdh->bytes_dumped += sizeof isb;
+
+ /* write (optional) block options */
+ if (comment_len) {
+ option_hdr.type = OPT_COMMENT;
+ option_hdr.value_length = comment_len;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+
+ /* Write the comments string */
+ pcapng_debug3("pcapng_write_interface_statistics_block, comment:'%s' comment_len %u comment_pad_len %u" , if_stats->opt_comment, comment_len, comment_pad_len);
+ if (!wtap_dump_file_write(wdh, if_stats->opt_comment, comment_len, err))
+ return FALSE;
+ wdh->bytes_dumped += comment_len;
+
+ /* write padding (if any) */
+ if (comment_pad_len != 0) {
+ if (!wtap_dump_file_write(wdh, &zero_pad, comment_pad_len, err))
return FALSE;
- wdh->bytes_dumped += sizeof isb;
-
- /* write (optional) block options */
- if (comment_len) {
- option_hdr.type = OPT_COMMENT;
- option_hdr.value_length = comment_len;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write the comments string */
- pcapng_debug3("pcapng_write_interface_statistics_block, comment:'%s' comment_len %u comment_pad_len %u" , if_stats->opt_comment, comment_len, comment_pad_len);
- if (!wtap_dump_file_write(wdh, if_stats->opt_comment, comment_len, err))
- return FALSE;
- wdh->bytes_dumped += comment_len;
-
- /* write padding (if any) */
- if (comment_pad_len != 0) {
- if (!wtap_dump_file_write(wdh, &zero_pad, comment_pad_len, err))
- return FALSE;
- wdh->bytes_dumped += comment_pad_len;
- }
- }
- /*guint64 isb_starttime */
- if (if_stats->isb_starttime != 0) {
- guint32 high, low;
-
- option_hdr.type = ISB_STARTTIME;
- option_hdr.value_length = 8;
- high = (guint32)((if_stats->isb_starttime>>32) & 0xffffffff);
- low = (guint32)(if_stats->isb_starttime & 0xffffffff);
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write isb_starttime */
- pcapng_debug1("pcapng_write_interface_statistics_block, isb_starttime: %" G_GINT64_MODIFIER "u" , if_stats->isb_starttime);
- if (!wtap_dump_file_write(wdh, &high, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
- if (!wtap_dump_file_write(wdh, &low, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
- }
- /*guint64 isb_endtime */
- if (if_stats->isb_endtime != 0) {
- guint32 high, low;
-
- option_hdr.type = ISB_ENDTIME;
- option_hdr.value_length = 8;
- high = (guint32)((if_stats->isb_endtime>>32) & 0xffffffff);
- low = (guint32)(if_stats->isb_endtime & 0xffffffff);
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write isb_endtime */
- pcapng_debug1("pcapng_write_interface_statistics_block, isb_starttime: %" G_GINT64_MODIFIER "u" , if_stats->isb_endtime);
- if (!wtap_dump_file_write(wdh, &high, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
- if (!wtap_dump_file_write(wdh, &low, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
- }
- /*guint64 isb_ifrecv;*/
- if (if_stats->isb_ifrecv != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
- option_hdr.type = ISB_IFRECV;
- option_hdr.value_length = 8;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write isb_ifrecv */
- pcapng_debug1("pcapng_write_interface_statistics_block, isb_ifrecv: %" G_GINT64_MODIFIER "u" , if_stats->isb_ifrecv);
- if (!wtap_dump_file_write(wdh, &if_stats->isb_ifrecv, 8, err))
- return FALSE;
- wdh->bytes_dumped += 8;
- }
- /*guint64 isb_ifdrop;*/
- if (if_stats->isb_ifdrop != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
- option_hdr.type = ISB_IFDROP;
- option_hdr.value_length = 8;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write isb_ifdrop */
- pcapng_debug1("pcapng_write_interface_statistics_block, isb_ifdrop: %" G_GINT64_MODIFIER "u" , if_stats->isb_ifdrop);
- if (!wtap_dump_file_write(wdh, &if_stats->isb_ifdrop, 8, err))
- return FALSE;
- wdh->bytes_dumped += 8;
- }
- /*guint64 isb_filteraccept;*/
- if (if_stats->isb_filteraccept != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
- option_hdr.type = ISB_FILTERACCEPT;
- option_hdr.value_length = 8;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write isb_filteraccept */
- pcapng_debug1("pcapng_write_interface_statistics_block, isb_filteraccept: %" G_GINT64_MODIFIER "u" , if_stats->isb_filteraccept);
- if (!wtap_dump_file_write(wdh, &if_stats->isb_filteraccept, 8, err))
- return FALSE;
- wdh->bytes_dumped += 8;
- }
- /*guint64 isb_osdrop;*/
- if (if_stats->isb_osdrop != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
- option_hdr.type = ISB_OSDROP;
- option_hdr.value_length = 8;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write isb_osdrop */
- pcapng_debug1("pcapng_write_interface_statistics_block, isb_osdrop: %" G_GINT64_MODIFIER "u" , if_stats->isb_osdrop);
- if (!wtap_dump_file_write(wdh, &if_stats->isb_osdrop, 8, err))
- return FALSE;
- wdh->bytes_dumped += 8;
- }
- /*guint64 isb_usrdeliv;*/
- if (if_stats->isb_usrdeliv != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
- option_hdr.type = ISB_USRDELIV;
- option_hdr.value_length = 8;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write isb_usrdeliv */
- pcapng_debug1("pcapng_write_interface_statistics_block, isb_usrdeliv: %" G_GINT64_MODIFIER "u" , if_stats->isb_usrdeliv);
- if (!wtap_dump_file_write(wdh, &if_stats->isb_usrdeliv, 8, err))
- return FALSE;
- wdh->bytes_dumped += 8;
+ wdh->bytes_dumped += comment_pad_len;
}
+ }
+ /*guint64 isb_starttime */
+ if (if_stats->isb_starttime != 0) {
+ guint32 high, low;
+
+ option_hdr.type = ISB_STARTTIME;
+ option_hdr.value_length = 8;
+ high = (guint32)((if_stats->isb_starttime>>32) & 0xffffffff);
+ low = (guint32)(if_stats->isb_starttime & 0xffffffff);
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+
+ /* Write isb_starttime */
+ pcapng_debug1("pcapng_write_interface_statistics_block, isb_starttime: %" G_GINT64_MODIFIER "u" , if_stats->isb_starttime);
+ if (!wtap_dump_file_write(wdh, &high, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+ if (!wtap_dump_file_write(wdh, &low, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+ }
+ /*guint64 isb_endtime */
+ if (if_stats->isb_endtime != 0) {
+ guint32 high, low;
+
+ option_hdr.type = ISB_ENDTIME;
+ option_hdr.value_length = 8;
+ high = (guint32)((if_stats->isb_endtime>>32) & 0xffffffff);
+ low = (guint32)(if_stats->isb_endtime & 0xffffffff);
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+
+ /* Write isb_endtime */
+ pcapng_debug1("pcapng_write_interface_statistics_block, isb_starttime: %" G_GINT64_MODIFIER "u" , if_stats->isb_endtime);
+ if (!wtap_dump_file_write(wdh, &high, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+ if (!wtap_dump_file_write(wdh, &low, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+ }
+ /*guint64 isb_ifrecv;*/
+ if (if_stats->isb_ifrecv != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
+ option_hdr.type = ISB_IFRECV;
+ option_hdr.value_length = 8;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+
+ /* Write isb_ifrecv */
+ pcapng_debug1("pcapng_write_interface_statistics_block, isb_ifrecv: %" G_GINT64_MODIFIER "u" , if_stats->isb_ifrecv);
+ if (!wtap_dump_file_write(wdh, &if_stats->isb_ifrecv, 8, err))
+ return FALSE;
+ wdh->bytes_dumped += 8;
+ }
+ /*guint64 isb_ifdrop;*/
+ if (if_stats->isb_ifdrop != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
+ option_hdr.type = ISB_IFDROP;
+ option_hdr.value_length = 8;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+
+ /* Write isb_ifdrop */
+ pcapng_debug1("pcapng_write_interface_statistics_block, isb_ifdrop: %" G_GINT64_MODIFIER "u" , if_stats->isb_ifdrop);
+ if (!wtap_dump_file_write(wdh, &if_stats->isb_ifdrop, 8, err))
+ return FALSE;
+ wdh->bytes_dumped += 8;
+ }
+ /*guint64 isb_filteraccept;*/
+ if (if_stats->isb_filteraccept != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
+ option_hdr.type = ISB_FILTERACCEPT;
+ option_hdr.value_length = 8;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+
+ /* Write isb_filteraccept */
+ pcapng_debug1("pcapng_write_interface_statistics_block, isb_filteraccept: %" G_GINT64_MODIFIER "u" , if_stats->isb_filteraccept);
+ if (!wtap_dump_file_write(wdh, &if_stats->isb_filteraccept, 8, err))
+ return FALSE;
+ wdh->bytes_dumped += 8;
+ }
+ /*guint64 isb_osdrop;*/
+ if (if_stats->isb_osdrop != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
+ option_hdr.type = ISB_OSDROP;
+ option_hdr.value_length = 8;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+
+ /* Write isb_osdrop */
+ pcapng_debug1("pcapng_write_interface_statistics_block, isb_osdrop: %" G_GINT64_MODIFIER "u" , if_stats->isb_osdrop);
+ if (!wtap_dump_file_write(wdh, &if_stats->isb_osdrop, 8, err))
+ return FALSE;
+ wdh->bytes_dumped += 8;
+ }
+ /*guint64 isb_usrdeliv;*/
+ if (if_stats->isb_usrdeliv != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
+ option_hdr.type = ISB_USRDELIV;
+ option_hdr.value_length = 8;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+
+ /* Write isb_usrdeliv */
+ pcapng_debug1("pcapng_write_interface_statistics_block, isb_usrdeliv: %" G_GINT64_MODIFIER "u" , if_stats->isb_usrdeliv);
+ if (!wtap_dump_file_write(wdh, &if_stats->isb_usrdeliv, 8, err))
+ return FALSE;
+ wdh->bytes_dumped += 8;
+ }
- if (have_options) {
- option_hdr.type = OPT_EOFOPT;
- option_hdr.value_length = 0;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
- }
+ if (have_options) {
+ option_hdr.type = OPT_EOFOPT;
+ option_hdr.value_length = 0;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+ }
- /* write block footer */
- if (!wtap_dump_file_write(wdh, &bh.block_total_length,
- sizeof bh.block_total_length, err))
- return FALSE;
- wdh->bytes_dumped += sizeof bh.block_total_length;
+ /* write block footer */
+ if (!wtap_dump_file_write(wdh, &bh.block_total_length,
+ sizeof bh.block_total_length, err))
+ return FALSE;
+ wdh->bytes_dumped += sizeof bh.block_total_length;
- return TRUE;
+ return TRUE;
}
static gboolean
pcapng_write_enhanced_packet_block(wtap_dumper *wdh,
- const struct wtap_pkthdr *phdr,
- const union wtap_pseudo_header *pseudo_header, const guint8 *pd, int *err)
+ const struct wtap_pkthdr *phdr,
+ const union wtap_pseudo_header *pseudo_header, const guint8 *pd, int *err)
{
- pcapng_block_header_t bh;
- pcapng_enhanced_packet_block_t epb;
- guint64 ts;
- const guint32 zero_pad = 0;
- guint32 pad_len;
- guint32 phdr_len;
- gboolean have_options = FALSE;
- guint32 options_total_length = 0;
- struct option option_hdr;
- guint32 comment_len = 0, comment_pad_len = 0;
- wtapng_if_descr_t int_data;
+ pcapng_block_header_t bh;
+ pcapng_enhanced_packet_block_t epb;
+ guint64 ts;
+ const guint32 zero_pad = 0;
+ guint32 pad_len;
+ guint32 phdr_len;
+ gboolean have_options = FALSE;
+ guint32 options_total_length = 0;
+ struct option option_hdr;
+ guint32 comment_len = 0, comment_pad_len = 0;
+ wtapng_if_descr_t int_data;
+
+ /* Don't write anything we're not willing to read. */
+ if (phdr->caplen > WTAP_MAX_PACKET_SIZE) {
+ *err = WTAP_ERR_PACKET_TOO_LARGE;
+ return FALSE;
+ }
- /* Don't write anything we're not willing to read. */
- if (phdr->caplen > WTAP_MAX_PACKET_SIZE) {
- *err = WTAP_ERR_PACKET_TOO_LARGE;
- return FALSE;
- }
+ phdr_len = (guint32)pcap_get_phdr_size(phdr->pkt_encap, pseudo_header);
+ if ((phdr_len + phdr->caplen) % 4) {
+ pad_len = 4 - ((phdr_len + phdr->caplen) % 4);
+ } else {
+ pad_len = 0;
+ }
- phdr_len = (guint32)pcap_get_phdr_size(phdr->pkt_encap, pseudo_header);
- if ((phdr_len + phdr->caplen) % 4) {
- pad_len = 4 - ((phdr_len + phdr->caplen) % 4);
+ /* Check if we should write comment option */
+ if (phdr->opt_comment) {
+ have_options = TRUE;
+ comment_len = (guint32)strlen(phdr->opt_comment) & 0xffff;
+ if ((comment_len % 4)) {
+ comment_pad_len = 4 - (comment_len % 4);
} else {
- pad_len = 0;
- }
-
- /* Check if we should write comment option */
- if (phdr->opt_comment) {
- have_options = TRUE;
- comment_len = (guint32)strlen(phdr->opt_comment) & 0xffff;
- if ((comment_len % 4)) {
- comment_pad_len = 4 - (comment_len % 4);
- } else {
- comment_pad_len = 0;
- }
- options_total_length = options_total_length + comment_len + comment_pad_len + 4 /* comment options tag */ ;
- }
- if (phdr->presence_flags & WTAP_HAS_PACK_FLAGS) {
- have_options = TRUE;
- options_total_length = options_total_length + 8;
- }
- if (have_options) {
- /* End-of optios tag */
- options_total_length += 4;
+ comment_pad_len = 0;
}
+ options_total_length = options_total_length + comment_len + comment_pad_len + 4 /* comment options tag */ ;
+ }
+ if (phdr->presence_flags & WTAP_HAS_PACK_FLAGS) {
+ have_options = TRUE;
+ options_total_length = options_total_length + 8;
+ }
+ if (have_options) {
+ /* End-of optios tag */
+ options_total_length += 4;
+ }
- /* write (enhanced) packet block header */
- bh.block_type = BLOCK_TYPE_EPB;
- bh.block_total_length = (guint32)sizeof(bh) + (guint32)sizeof(epb) + phdr_len + phdr->caplen + pad_len + options_total_length + 4;
+ /* write (enhanced) packet block header */
+ bh.block_type = BLOCK_TYPE_EPB;
+ bh.block_total_length = (guint32)sizeof(bh) + (guint32)sizeof(epb) + phdr_len + phdr->caplen + pad_len + options_total_length + 4;
- if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err))
- return FALSE;
- wdh->bytes_dumped += sizeof bh;
+ if (!wtap_dump_file_write(wdh, &bh, sizeof bh, err))
+ return FALSE;
+ wdh->bytes_dumped += sizeof bh;
- /* write block fixed content */
- if (phdr->presence_flags & WTAP_HAS_INTERFACE_ID)
- epb.interface_id = phdr->interface_id;
- else {
- /*
- * XXX - we should support writing WTAP_ENCAP_PER_PACKET
- * data to pcap-NG files even if we *don't* have interface
- * IDs.
- */
- epb.interface_id = 0;
- }
+ /* write block fixed content */
+ if (phdr->presence_flags & WTAP_HAS_INTERFACE_ID)
+ epb.interface_id = phdr->interface_id;
+ else {
/*
- * Split the 64-bit timestamp into two 32-bit pieces, using
- * the time stamp resolution for the interface.
+ * XXX - we should support writing WTAP_ENCAP_PER_PACKET
+ * data to pcap-NG files even if we *don't* have interface
+ * IDs.
*/
- if (epb.interface_id >= wdh->interface_data->len) {
- /*
- * Our caller is doing something bad.
- */
- *err = WTAP_ERR_INTERNAL;
- return FALSE;
- }
- int_data = g_array_index(wdh->interface_data, wtapng_if_descr_t,
- epb.interface_id);
- ts = ((guint64)phdr->ts.secs) * int_data.time_units_per_second +
- (((guint64)phdr->ts.nsecs) * int_data.time_units_per_second) / 1000000000;
- epb.timestamp_high = (guint32)(ts >> 32);
- epb.timestamp_low = (guint32)ts;
- epb.captured_len = phdr->caplen + phdr_len;
- epb.packet_len = phdr->len + phdr_len;
-
- if (!wtap_dump_file_write(wdh, &epb, sizeof epb, err))
- return FALSE;
- wdh->bytes_dumped += sizeof epb;
+ epb.interface_id = 0;
+ }
+ /*
+ * Split the 64-bit timestamp into two 32-bit pieces, using
+ * the time stamp resolution for the interface.
+ */
+ if (epb.interface_id >= wdh->interface_data->len) {
+ /*
+ * Our caller is doing something bad.
+ */
+ *err = WTAP_ERR_INTERNAL;
+ return FALSE;
+ }
+ int_data = g_array_index(wdh->interface_data, wtapng_if_descr_t,
+ epb.interface_id);
+ ts = ((guint64)phdr->ts.secs) * int_data.time_units_per_second +
+ (((guint64)phdr->ts.nsecs) * int_data.time_units_per_second) / 1000000000;
+ epb.timestamp_high = (guint32)(ts >> 32);
+ epb.timestamp_low = (guint32)ts;
+ epb.captured_len = phdr->caplen + phdr_len;
+ epb.packet_len = phdr->len + phdr_len;
+
+ if (!wtap_dump_file_write(wdh, &epb, sizeof epb, err))
+ return FALSE;
+ wdh->bytes_dumped += sizeof epb;
- /* write pseudo header */
- if (!pcap_write_phdr(wdh, phdr->pkt_encap, pseudo_header, err)) {
- return FALSE;
- }
- wdh->bytes_dumped += phdr_len;
+ /* write pseudo header */
+ if (!pcap_write_phdr(wdh, phdr->pkt_encap, pseudo_header, err)) {
+ return FALSE;
+ }
+ wdh->bytes_dumped += phdr_len;
- /* write packet data */
- if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
- return FALSE;
- wdh->bytes_dumped += phdr->caplen;
+ /* write packet data */
+ if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
+ return FALSE;
+ wdh->bytes_dumped += phdr->caplen;
- /* write padding (if any) */
- if (pad_len != 0) {
- if (!wtap_dump_file_write(wdh, &zero_pad, pad_len, err))
- return FALSE;
- wdh->bytes_dumped += pad_len;
- }
+ /* write padding (if any) */
+ if (pad_len != 0) {
+ if (!wtap_dump_file_write(wdh, &zero_pad, pad_len, err))
+ return FALSE;
+ wdh->bytes_dumped += pad_len;
+ }
- /* XXX - write (optional) block options */
- /* options defined in Section 2.5 (Options)
- * Name Code Length Description
- * opt_comment 1 variable A UTF-8 string containing a comment that is associated to the current block.
- *
- * Enhanced Packet Block options
- * epb_flags 2 4 A flags word containing link-layer information. A complete specification of
- * the allowed flags can be found in Appendix A (Packet Block Flags Word).
- * epb_hash 3 variable This option contains a hash of the packet. The first byte specifies the hashing algorithm,
- * while the following bytes contain the actual hash, whose size depends on the hashing algorithm,
- * and hence from the value in the first bit. The hashing algorithm can be: 2s complement
- * (algorithm byte = 0, size=XXX), XOR (algorithm byte = 1, size=XXX), CRC32 (algorithm byte = 2, size = 4),
- * MD-5 (algorithm byte = 3, size=XXX), SHA-1 (algorithm byte = 4, size=XXX).
- * The hash covers only the packet, not the header added by the capture driver:
- * this gives the possibility to calculate it inside the network card.
- * The hash allows easier comparison/merging of different capture files, and reliable data transfer between the
- * data acquisition system and the capture library.
- * epb_dropcount 4 8 A 64bit integer value specifying the number of packets lost (by the interface and the operating system)
- * between this packet and the preceding one.
- * opt_endofopt 0 0 It delimits the end of the optional fields. This block cannot be repeated within a given list of options.
- */
- if (phdr->opt_comment) {
- option_hdr.type = OPT_COMMENT;
- option_hdr.value_length = comment_len;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
-
- /* Write the comments string */
- pcapng_debug3("pcapng_write_enhanced_packet_block, comment:'%s' comment_len %u comment_pad_len %u" , phdr->opt_comment, comment_len, comment_pad_len);
- if (!wtap_dump_file_write(wdh, phdr->opt_comment, comment_len, err))
- return FALSE;
- wdh->bytes_dumped += comment_len;
-
- /* write padding (if any) */
- if (comment_pad_len != 0) {
- if (!wtap_dump_file_write(wdh, &zero_pad, comment_pad_len, err))
- return FALSE;
- wdh->bytes_dumped += comment_pad_len;
- }
+ /* XXX - write (optional) block options */
+ /* options defined in Section 2.5 (Options)
+ * Name Code Length Description
+ * opt_comment 1 variable A UTF-8 string containing a comment that is associated to the current block.
+ *
+ * Enhanced Packet Block options
+ * epb_flags 2 4 A flags word containing link-layer information. A complete specification of
+ * the allowed flags can be found in Appendix A (Packet Block Flags Word).
+ * epb_hash 3 variable This option contains a hash of the packet. The first byte specifies the hashing algorithm,
+ * while the following bytes contain the actual hash, whose size depends on the hashing algorithm,
+ * and hence from the value in the first bit. The hashing algorithm can be: 2s complement
+ * (algorithm byte = 0, size=XXX), XOR (algorithm byte = 1, size=XXX), CRC32 (algorithm byte = 2, size = 4),
+ * MD-5 (algorithm byte = 3, size=XXX), SHA-1 (algorithm byte = 4, size=XXX).
+ * The hash covers only the packet, not the header added by the capture driver:
+ * this gives the possibility to calculate it inside the network card.
+ * The hash allows easier comparison/merging of different capture files, and reliable data transfer between the
+ * data acquisition system and the capture library.
+ * epb_dropcount 4 8 A 64bit integer value specifying the number of packets lost (by the interface and the operating system)
+ * between this packet and the preceding one.
+ * opt_endofopt 0 0 It delimits the end of the optional fields. This block cannot be repeated within a given list of options.
+ */
+ if (phdr->opt_comment) {
+ option_hdr.type = OPT_COMMENT;
+ option_hdr.value_length = comment_len;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+
+ /* Write the comments string */
+ pcapng_debug3("pcapng_write_enhanced_packet_block, comment:'%s' comment_len %u comment_pad_len %u" , phdr->opt_comment, comment_len, comment_pad_len);
+ if (!wtap_dump_file_write(wdh, phdr->opt_comment, comment_len, err))
+ return FALSE;
+ wdh->bytes_dumped += comment_len;
- pcapng_debug2("pcapng_write_enhanced_packet_block: Wrote Options comments: comment_len %u, comment_pad_len %u",
- comment_len,
- comment_pad_len);
- }
- if (phdr->presence_flags & WTAP_HAS_PACK_FLAGS) {
- option_hdr.type = OPT_EPB_FLAGS;
- option_hdr.value_length = 4;
- if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
- if (!wtap_dump_file_write(wdh, &phdr->pack_flags, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
- pcapng_debug1("pcapng_write_enhanced_packet_block: Wrote Options packet flags: %x", phdr->pack_flags);
- }
- /* Write end of options if we have otions */
- if (have_options) {
- if (!wtap_dump_file_write(wdh, &zero_pad, 4, err))
- return FALSE;
- wdh->bytes_dumped += 4;
+ /* write padding (if any) */
+ if (comment_pad_len != 0) {
+ if (!wtap_dump_file_write(wdh, &zero_pad, comment_pad_len, err))
+ return FALSE;
+ wdh->bytes_dumped += comment_pad_len;
}
- /* write block footer */
- if (!wtap_dump_file_write(wdh, &bh.block_total_length,
- sizeof bh.block_total_length, err))
- return FALSE;
- wdh->bytes_dumped += sizeof bh.block_total_length;
+ pcapng_debug2("pcapng_write_enhanced_packet_block: Wrote Options comments: comment_len %u, comment_pad_len %u",
+ comment_len,
+ comment_pad_len);
+ }
+ if (phdr->presence_flags & WTAP_HAS_PACK_FLAGS) {
+ option_hdr.type = OPT_EPB_FLAGS;
+ option_hdr.value_length = 4;
+ if (!wtap_dump_file_write(wdh, &option_hdr, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+ if (!wtap_dump_file_write(wdh, &phdr->pack_flags, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+ pcapng_debug1("pcapng_write_enhanced_packet_block: Wrote Options packet flags: %x", phdr->pack_flags);
+ }
+ /* Write end of options if we have otions */
+ if (have_options) {
+ if (!wtap_dump_file_write(wdh, &zero_pad, 4, err))
+ return FALSE;
+ wdh->bytes_dumped += 4;
+ }
- return TRUE;
+ /* write block footer */
+ if (!wtap_dump_file_write(wdh, &bh.block_total_length,
+ sizeof bh.block_total_length, err))
+ return FALSE;
+ wdh->bytes_dumped += sizeof bh.block_total_length;
+
+ return TRUE;
}
/* Arbitrary. */
@@ -3610,57 +3610,57 @@ pcapng_write_name_resolution_block(wtap_dumper *wdh, int *err)
}
static gboolean pcapng_dump(wtap_dumper *wdh,
- const struct wtap_pkthdr *phdr,
- const guint8 *pd, int *err)
+ const struct wtap_pkthdr *phdr,
+ const guint8 *pd, int *err)
{
- const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
+ const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
#ifdef HAVE_PLUGINS
- block_handler *handler;
+ block_handler *handler;
#endif
- pcapng_debug2("pcapng_dump: encap = %d (%s)",
- phdr->pkt_encap,
- wtap_encap_string(phdr->pkt_encap));
+ pcapng_debug2("pcapng_dump: encap = %d (%s)",
+ phdr->pkt_encap,
+ wtap_encap_string(phdr->pkt_encap));
- /* Flush any hostname resolution info we may have */
- pcapng_write_name_resolution_block(wdh, err);
+ /* Flush any hostname resolution info we may have */
+ pcapng_write_name_resolution_block(wdh, err);
- switch (phdr->rec_type) {
+ switch (phdr->rec_type) {
case REC_TYPE_PACKET:
- if (!pcapng_write_enhanced_packet_block(wdh, phdr, pseudo_header, pd, err)) {
- return FALSE;
- }
- break;
+ if (!pcapng_write_enhanced_packet_block(wdh, phdr, pseudo_header, pd, err)) {
+ return FALSE;
+ }
+ break;
case REC_TYPE_FT_SPECIFIC_EVENT:
case REC_TYPE_FT_SPECIFIC_REPORT:
#ifdef HAVE_PLUGINS
- /*
- * Do we have a handler for this block type?
- */
- handler = (block_handler *)g_hash_table_lookup(block_handlers,
- GUINT_TO_POINTER(pseudo_header->ftsrec.record_type));
- if (handler != NULL) {
- /* Yes. Call it to write out this record. */
- if (!handler->write(wdh, phdr, pd, err))
- return FALSE;
- } else
+ /*
+ * Do we have a handler for this block type?
+ */
+ handler = (block_handler *)g_hash_table_lookup(block_handlers,
+ GUINT_TO_POINTER(pseudo_header->ftsrec.record_type));
+ if (handler != NULL) {
+ /* Yes. Call it to write out this record. */
+ if (!handler->write(wdh, phdr, pd, err))
+ return FALSE;
+ } else
#endif
- {
- /* No. */
- *err = WTAP_ERR_REC_TYPE_UNSUPPORTED;
- return FALSE;
- }
- break;
-
- default:
- /* We don't support writing this record type. */
+ {
+ /* No. */
*err = WTAP_ERR_REC_TYPE_UNSUPPORTED;
return FALSE;
- }
+ }
+ break;
- return TRUE;
+ default:
+ /* We don't support writing this record type. */
+ *err = WTAP_ERR_REC_TYPE_UNSUPPORTED;
+ return FALSE;
+ }
+
+ return TRUE;
}
@@ -3668,27 +3668,27 @@ static gboolean pcapng_dump(wtap_dumper *wdh,
Returns TRUE on success, FALSE on failure. */
static gboolean pcapng_dump_close(wtap_dumper *wdh, int *err _U_)
{
- guint i, j;
+ guint i, j;
- for (i = 0; i < wdh->interface_data->len; i++) {
+ for (i = 0; i < wdh->interface_data->len; i++) {
- /* Get the interface description */
- wtapng_if_descr_t int_data;
+ /* Get the interface description */
+ wtapng_if_descr_t int_data;
- int_data = g_array_index(wdh->interface_data, wtapng_if_descr_t, i);
- for (j = 0; j < int_data.num_stat_entries; j++) {
- wtapng_if_stats_t if_stats;
+ int_data = g_array_index(wdh->interface_data, wtapng_if_descr_t, i);
+ for (j = 0; j < int_data.num_stat_entries; j++) {
+ wtapng_if_stats_t if_stats;
- if_stats = g_array_index(int_data.interface_statistics, wtapng_if_stats_t, j);
- pcapng_debug1("pcapng_dump_close: write ISB for interface %u",if_stats.interface_id);
- if (!pcapng_write_interface_statistics_block(wdh, &if_stats, err)) {
- return FALSE;
- }
- }
+ if_stats = g_array_index(int_data.interface_statistics, wtapng_if_stats_t, j);
+ pcapng_debug1("pcapng_dump_close: write ISB for interface %u",if_stats.interface_id);
+ if (!pcapng_write_interface_statistics_block(wdh, &if_stats, err)) {
+ return FALSE;
+ }
}
+ }
- pcapng_debug0("pcapng_dump_close");
- return TRUE;
+ pcapng_debug0("pcapng_dump_close");
+ return TRUE;
}
@@ -3697,43 +3697,43 @@ static gboolean pcapng_dump_close(wtap_dumper *wdh, int *err _U_)
gboolean
pcapng_dump_open(wtap_dumper *wdh, int *err)
{
- guint i;
+ guint i;
- pcapng_debug0("pcapng_dump_open");
- /* This is a pcapng file */
- wdh->subtype_write = pcapng_dump;
- wdh->subtype_close = pcapng_dump_close;
+ pcapng_debug0("pcapng_dump_open");
+ /* This is a pcapng file */
+ wdh->subtype_write = pcapng_dump;
+ wdh->subtype_close = pcapng_dump_close;
- if (wdh->interface_data->len == 0) {
- pcapng_debug0("There are no interfaces. Can't handle that...");
- *err = WTAP_ERR_INTERNAL;
- return FALSE;
- }
-
- /* write the section header block */
- if (!pcapng_write_section_header_block(wdh, err)) {
- return FALSE;
- }
- pcapng_debug0("pcapng_dump_open: wrote section header block.");
+ if (wdh->interface_data->len == 0) {
+ pcapng_debug0("There are no interfaces. Can't handle that...");
+ *err = WTAP_ERR_INTERNAL;
+ return FALSE;
+ }
- /* Write the Interface description blocks */
- pcapng_debug1("pcapng_dump_open: Number of IDB:s to write (number of interfaces) %u",
- wdh->interface_data->len);
+ /* write the section header block */
+ if (!pcapng_write_section_header_block(wdh, err)) {
+ return FALSE;
+ }
+ pcapng_debug0("pcapng_dump_open: wrote section header block.");
- for (i = 0; i < wdh->interface_data->len; i++) {
+ /* Write the Interface description blocks */
+ pcapng_debug1("pcapng_dump_open: Number of IDB:s to write (number of interfaces) %u",
+ wdh->interface_data->len);
- /* Get the interface description */
- wtapng_if_descr_t int_data;
+ for (i = 0; i < wdh->interface_data->len; i++) {
- int_data = g_array_index(wdh->interface_data, wtapng_if_descr_t, i);
+ /* Get the interface description */
+ wtapng_if_descr_t int_data;
- if (!pcapng_write_if_descr_block(wdh, &int_data, err)) {
- return FALSE;
- }
+ int_data = g_array_index(wdh->interface_data, wtapng_if_descr_t, i);
+ if (!pcapng_write_if_descr_block(wdh, &int_data, err)) {
+ return FALSE;
}
- return TRUE;
+ }
+
+ return TRUE;
}
@@ -3741,19 +3741,19 @@ pcapng_dump_open(wtap_dumper *wdh, int *err)
an error indication otherwise. */
int pcapng_dump_can_write_encap(int wtap_encap)
{
- pcapng_debug2("pcapng_dump_can_write_encap: encap = %d (%s)",
- wtap_encap,
- wtap_encap_string(wtap_encap));
+ pcapng_debug2("pcapng_dump_can_write_encap: encap = %d (%s)",
+ wtap_encap,
+ wtap_encap_string(wtap_encap));
- /* Per-packet encapsulation is supported. */
- if (wtap_encap == WTAP_ENCAP_PER_PACKET)
- return 0;
+ /* Per-packet encapsulation is supported. */
+ if (wtap_encap == WTAP_ENCAP_PER_PACKET)
+ return 0;
- /* Make sure we can figure out this DLT type */
- if (wtap_wtap_encap_to_pcap_encap(wtap_encap) == -1)
- return WTAP_ERR_UNSUPPORTED_ENCAP;
+ /* Make sure we can figure out this DLT type */
+ if (wtap_wtap_encap_to_pcap_encap(wtap_encap) == -1)
+ return WTAP_ERR_UNSUPPORTED_ENCAP;
- return 0;
+ return 0;
}
/*
diff --git a/wiretap/vwr.c b/wiretap/vwr.c
index a522531548..a48158e666 100644
--- a/wiretap/vwr.c
+++ b/wiretap/vwr.c
@@ -425,69 +425,69 @@
/* Per-capture file private data structure */
typedef struct {
- /* offsets in stats block; these are dependent on the frame type (Ethernet/WLAN) and */
- /* version number of .vwr file, and are set up by setup_defaults() */
- guint32 STATS_LEN; /* length of stats block trailer */
- guint32 STATS_START_OFF; /* STATS OFF AFTER HEADER */
- guint32 VALID_OFF; /* bit 6 (0x40) is flow-is-valid flag */
- guint32 MTYPE_OFF; /* offset of modulation type */
- guint32 VCID_OFF; /* offset of VC ID */
- guint32 FLOWSEQ_OFF; /* offset of signature sequence number */
- guint32 FLOWID_OFF; /* offset of flow ID */
- guint32 OCTET_OFF; /* offset of octets */
- guint32 ERRORS_OFF; /* offset of error vector */
- guint32 PATN_OFF; /* offset of pattern match vector */
- guint32 RSSI_OFF; /* RSSI (NOTE: RSSI must be negated!) */
- guint32 STARTT_OFF; /* offset of start time, 64 bits */
- guint32 ENDT_OFF; /* offset of end time, 64 bits */
- guint32 LATVAL_OFF; /* offset of latency, 32 bits */
- guint32 INFO_OFF; /* offset of INFO field, 16 bits */
- guint32 L1P_1_OFF; /* offset 1ST Byte of l1params */
- guint32 L1P_2_OFF; /* offset 2nd Byte of l1params */
- guint32 L4ID_OFF; /* LAYER 4 id offset*/
- guint32 IPLEN_OFF; /* */
- guint32 PLCP_LENGTH_OFF; /* plcp length offset*/
- guint32 FPGA_VERSION_OFF; /* offset of fpga version field, 16 bits */
- guint32 HEADER_VERSION_OFF; /* offset of header version, 16 bits */
- guint32 RXTX_OFF; /* offset of CMD bit, rx or tx */
- guint32 FRAME_TYPE_OFF;
-
- /* other information about the file in question */
- guint32 MT_10_HALF; /* 10 Mb/s half-duplex */
- guint32 MT_10_FULL; /* 10 Mb/s full-duplex */
- guint32 MT_100_HALF; /* 100 Mb/s half-duplex */
- guint32 MT_100_FULL; /* 100 Mb/s full-duplex */
- guint32 MT_1G_HALF; /* 1 Gb/s half-duplex */
- guint32 MT_1G_FULL; /* 1 Gb/s full-duplex */
- guint32 FCS_ERROR; /* FCS error in frame */
- guint32 CRYPTO_ERR; /* RX decrypt error flags */
- guint32 PAYCHK_ERR; /* payload checksum failure */
- guint32 RETRY_ERR; /* excessive retries on TX failure */
- guint8 IS_RX; /* TX/RX bit in STATS block */
- guint8 MT_MASK; /* modulation type mask */
- guint16 VCID_MASK; /* VC ID is only 9 bits */
- guint32 FLOW_VALID; /* flow-is-valid flag (else force to 0) */
- guint16 QOS_VALID;
- guint32 RX_DECRYPTS; /* RX-frame-was-decrypted bits */
- guint32 TX_DECRYPTS; /* TX-frame-was-decrypted bits */
- guint32 FC_PROT_BIT; /* Protected Frame bit in FC1 of frame */
- guint32 MT_CCKL; /* CCK modulation, long preamble */
- guint32 MT_CCKS; /* CCK modulation, short preamble */
- guint32 MT_OFDM; /* OFDM modulation */
- guint32 MCS_INDEX_MASK; /* mcs index type mask */
- guint32 FPGA_VERSION;
- guint32 HEADER_IS_RX;
- guint32 HEADER_IS_TX;
- guint32 WEPTYPE; /* frame is WEP */
- guint32 TKIPTYPE; /* frame is TKIP */
- guint32 CCMPTYPE; /* frame is CCMP */
- guint32 IS_TCP;
- guint32 IS_UDP;
- guint32 IS_ICMP;
- guint32 IS_IGMP;
- guint16 IS_QOS;
- guint32 IS_VLAN;
- guint32 MPDU_OFF;
+ /* offsets in stats block; these are dependent on the frame type (Ethernet/WLAN) and */
+ /* version number of .vwr file, and are set up by setup_defaults() */
+ guint32 STATS_LEN; /* length of stats block trailer */
+ guint32 STATS_START_OFF; /* STATS OFF AFTER HEADER */
+ guint32 VALID_OFF; /* bit 6 (0x40) is flow-is-valid flag */
+ guint32 MTYPE_OFF; /* offset of modulation type */
+ guint32 VCID_OFF; /* offset of VC ID */
+ guint32 FLOWSEQ_OFF; /* offset of signature sequence number */
+ guint32 FLOWID_OFF; /* offset of flow ID */
+ guint32 OCTET_OFF; /* offset of octets */
+ guint32 ERRORS_OFF; /* offset of error vector */
+ guint32 PATN_OFF; /* offset of pattern match vector */
+ guint32 RSSI_OFF; /* RSSI (NOTE: RSSI must be negated!) */
+ guint32 STARTT_OFF; /* offset of start time, 64 bits */
+ guint32 ENDT_OFF; /* offset of end time, 64 bits */
+ guint32 LATVAL_OFF; /* offset of latency, 32 bits */
+ guint32 INFO_OFF; /* offset of INFO field, 16 bits */
+ guint32 L1P_1_OFF; /* offset 1ST Byte of l1params */
+ guint32 L1P_2_OFF; /* offset 2nd Byte of l1params */
+ guint32 L4ID_OFF; /* LAYER 4 id offset*/
+ guint32 IPLEN_OFF; /* */
+ guint32 PLCP_LENGTH_OFF; /* plcp length offset*/
+ guint32 FPGA_VERSION_OFF; /* offset of fpga version field, 16 bits */
+ guint32 HEADER_VERSION_OFF; /* offset of header version, 16 bits */
+ guint32 RXTX_OFF; /* offset of CMD bit, rx or tx */
+ guint32 FRAME_TYPE_OFF;
+
+ /* other information about the file in question */
+ guint32 MT_10_HALF; /* 10 Mb/s half-duplex */
+ guint32 MT_10_FULL; /* 10 Mb/s full-duplex */
+ guint32 MT_100_HALF; /* 100 Mb/s half-duplex */
+ guint32 MT_100_FULL; /* 100 Mb/s full-duplex */
+ guint32 MT_1G_HALF; /* 1 Gb/s half-duplex */
+ guint32 MT_1G_FULL; /* 1 Gb/s full-duplex */
+ guint32 FCS_ERROR; /* FCS error in frame */
+ guint32 CRYPTO_ERR; /* RX decrypt error flags */
+ guint32 PAYCHK_ERR; /* payload checksum failure */
+ guint32 RETRY_ERR; /* excessive retries on TX failure */
+ guint8 IS_RX; /* TX/RX bit in STATS block */
+ guint8 MT_MASK; /* modulation type mask */
+ guint16 VCID_MASK; /* VC ID is only 9 bits */
+ guint32 FLOW_VALID; /* flow-is-valid flag (else force to 0) */
+ guint16 QOS_VALID;
+ guint32 RX_DECRYPTS; /* RX-frame-was-decrypted bits */
+ guint32 TX_DECRYPTS; /* TX-frame-was-decrypted bits */
+ guint32 FC_PROT_BIT; /* Protected Frame bit in FC1 of frame */
+ guint32 MT_CCKL; /* CCK modulation, long preamble */
+ guint32 MT_CCKS; /* CCK modulation, short preamble */
+ guint32 MT_OFDM; /* OFDM modulation */
+ guint32 MCS_INDEX_MASK; /* mcs index type mask */
+ guint32 FPGA_VERSION;
+ guint32 HEADER_IS_RX;
+ guint32 HEADER_IS_TX;
+ guint32 WEPTYPE; /* frame is WEP */
+ guint32 TKIPTYPE; /* frame is TKIP */
+ guint32 CCMPTYPE; /* frame is CCMP */
+ guint32 IS_TCP;
+ guint32 IS_UDP;
+ guint32 IS_ICMP;
+ guint32 IS_IGMP;
+ guint16 IS_QOS;
+ guint32 IS_VLAN;
+ guint32 MPDU_OFF;
} vwr_t;
/* internal utility functions */
@@ -1151,20 +1151,20 @@ static gboolean vwr_read_s2_W_rec(vwr_t *vwr, struct wtap_pkthdr *phdr,
/* we do the range checks at the end before copying the values
into the wtap header */
msdu_length = ((s_start_ptr[vVW510021_W_MSDU_LENGTH_OFF+1] & 0x1f) << 8)
- + s_start_ptr[vVW510021_W_MSDU_LENGTH_OFF];
+ + s_start_ptr[vVW510021_W_MSDU_LENGTH_OFF];
vc_id = pntoh16(&s_start_ptr[vVW510021_W_VCID_OFF]);
if (IS_TX)
{
rssi[0] = (s_start_ptr[vVW510021_W_RSSI_TXPOWER_OFF] & 0x80) ?
- -1 * (s_start_ptr[vVW510021_W_RSSI_TXPOWER_OFF] & 0x7f) :
- s_start_ptr[vVW510021_W_RSSI_TXPOWER_OFF] & 0x7f;
+ -1 * (s_start_ptr[vVW510021_W_RSSI_TXPOWER_OFF] & 0x7f) :
+ s_start_ptr[vVW510021_W_RSSI_TXPOWER_OFF] & 0x7f;
}
else
{
rssi[0] = (s_start_ptr[vVW510021_W_RSSI_TXPOWER_OFF] & 0x80) ?
- (s_start_ptr[vVW510021_W_RSSI_TXPOWER_OFF]- 256) :
- s_start_ptr[vVW510021_W_RSSI_TXPOWER_OFF];
+ (s_start_ptr[vVW510021_W_RSSI_TXPOWER_OFF]- 256) :
+ s_start_ptr[vVW510021_W_RSSI_TXPOWER_OFF];
}
rssi[1] = 100;
rssi[2] = 100;
diff --git a/wiretap/wtap.h b/wiretap/wtap.h
index f0716376c6..92297212df 100644
--- a/wiretap/wtap.h
+++ b/wiretap/wtap.h
@@ -1251,11 +1251,11 @@ struct file_extension_info {
*
* The open routine should return:
*
- * -1 on an I/O error;
+ * -1 on an I/O error;
*
- * 1 if the file it's reading is one of the types it handles;
+ * 1 if the file it's reading is one of the types it handles;
*
- * 0 if the file it's reading isn't the type it handles.
+ * 0 if the file it's reading isn't the type it handles.
*
* If the routine handles this type of file, it should set the "file_type"
* field in the "struct wtap" to the type of the file.
@@ -1291,8 +1291,8 @@ typedef int (*wtap_open_routine_t)(struct wtap*, int *, char **);
* might be recognized by the heuristics for a different file type.
*/
/*struct heuristic_open_info {
- wtap_open_routine_t open_routine;
- const char *extensions;
+ wtap_open_routine_t open_routine;
+ const char *extensions;
};
*/
#define OPEN_INFO_MAGIC 0
@@ -1313,9 +1313,9 @@ WS_DLL_PUBLIC struct open_info *open_routines;
/*
* Types of comments.
*/
-#define WTAP_COMMENT_PER_SECTION 0x00000001 /* per-file/per-file-section */
-#define WTAP_COMMENT_PER_INTERFACE 0x00000002 /* per-interface */
-#define WTAP_COMMENT_PER_PACKET 0x00000004 /* per-packet */
+#define WTAP_COMMENT_PER_SECTION 0x00000001 /* per-file/per-file-section */
+#define WTAP_COMMENT_PER_INTERFACE 0x00000002 /* per-interface */
+#define WTAP_COMMENT_PER_PACKET 0x00000004 /* per-packet */
struct file_type_subtype_info {
/* the file type name */
@@ -1406,7 +1406,7 @@ gboolean wtap_read(wtap *wth, int *err, gchar **err_info,
WS_DLL_PUBLIC
gboolean wtap_seek_read (wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
+ struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
/*** get various information snippets about the current packet ***/
WS_DLL_PUBLIC