diff options
-rw-r--r-- | wiretap/erf.c | 84 | ||||
-rw-r--r-- | wiretap/erf.h | 2 | ||||
-rw-r--r-- | wiretap/libpcap.c | 9 |
3 files changed, 60 insertions, 35 deletions
diff --git a/wiretap/erf.c b/wiretap/erf.c index b3769643c5..d4064c2389 100644 --- a/wiretap/erf.c +++ b/wiretap/erf.c @@ -105,7 +105,6 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info) guint8 type; size_t r; gchar * buffer; - wtapng_if_descr_t int_data; memset(&prevts, 0, sizeof(prevts)); @@ -277,40 +276,7 @@ extern int erf_open(wtap *wth, int *err, gchar **err_info) wth->subtype_seek_read = erf_seek_read; wth->tsprecision = WTAP_FILE_TSPREC_NSEC; - /* Preemptively create interface entries for 4 interfaces, since this is the max number in ERF */ - wth->interface_data = g_array_new(FALSE, FALSE, sizeof(wtapng_if_descr_t)); - - memset(&int_data, 0, sizeof(int_data)); /* Zero all fields */ - - int_data.wtap_encap = WTAP_ENCAP_ERF; - int_data.time_units_per_second = (1LL<<32); /* ERF format resolution is 2^-32, capture resolution is unknown */ - int_data.link_type = wtap_wtap_encap_to_pcap_encap(WTAP_ENCAP_ERF); - int_data.snap_len = 65535; /* ERF max length */ - int_data.opt_comment = NULL; - /* 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 = 0; /* Unknown */ - int_data.if_tsresol = 0xa0; /* ERF format resolution is 2^-32 = 0xa0, capture resolution is unknown */ - /* XXX: if_tzone 10 Time zone for GMT support (TODO: specify better). */ - int_data.if_filter_str = NULL; - int_data.bpf_filter_len = 0; - int_data.if_filter_bpf_bytes = NULL; - int_data.if_os = NULL; - int_data.if_fcslen = 0; /* unknown! */ - /* 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; - - for (i=0; i<4; i++) { - int_data.if_name = g_strdup_printf("Port %c", 'A'+i); - int_data.if_description = g_strdup_printf("ERF Interface Id %d (Port %c)", i, 'A'+i); - - g_array_append_val(wth->interface_data, int_data); - wth->number_of_interfaces++; - } + erf_populate_interfaces(wth); return 1; } @@ -746,3 +712,51 @@ int erf_dump_open(wtap_dumper *wdh, int *err) return TRUE; } + +int erf_populate_interfaces(wtap *wth) +{ + wtapng_if_descr_t int_data; + int i; + + if (!wth) + return -1; + + if (!wth->interface_data) { + wth->interface_data = g_array_new(FALSE, FALSE, sizeof(wtapng_if_descr_t)); + } + + memset(&int_data, 0, sizeof(int_data)); /* Zero all fields */ + + int_data.wtap_encap = WTAP_ENCAP_ERF; + int_data.time_units_per_second = (1LL<<32); /* ERF format resolution is 2^-32, capture resolution is unknown */ + int_data.link_type = wtap_wtap_encap_to_pcap_encap(WTAP_ENCAP_ERF); + int_data.snap_len = 65535; /* ERF max length */ + int_data.opt_comment = NULL; + /* 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 = 0; /* Unknown */ + int_data.if_tsresol = 0xa0; /* ERF format resolution is 2^-32 = 0xa0, capture resolution is unknown */ + /* XXX: if_tzone 10 Time zone for GMT support (TODO: specify better). */ + int_data.if_filter_str = NULL; + int_data.bpf_filter_len = 0; + int_data.if_filter_bpf_bytes = NULL; + int_data.if_os = NULL; + int_data.if_fcslen = 0; /* unknown! */ + /* 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; + + /* Preemptively create interface entries for 4 interfaces, since this is the max number in ERF */ + for (i=0; i<4; i++) { + int_data.if_name = g_strdup_printf("Port %c", 'A'+i); + int_data.if_description = g_strdup_printf("ERF Interface Id %d (Port %c)", i, 'A'+i); + + g_array_append_val(wth->interface_data, int_data); + wth->number_of_interfaces++; + } + + return 0; +} diff --git a/wiretap/erf.h b/wiretap/erf.h index fde72e102a..012afba575 100644 --- a/wiretap/erf.h +++ b/wiretap/erf.h @@ -108,4 +108,6 @@ int erf_open(wtap *wth, int *err, gchar **err_info); int erf_dump_can_write_encap(int encap); int erf_dump_open(wtap_dumper *wdh, int *err); +int erf_populate_interfaces(wtap *wth); + #endif /* __W_ERF_H__ */ diff --git a/wiretap/libpcap.c b/wiretap/libpcap.c index c509643e7b..0e09e4026a 100644 --- a/wiretap/libpcap.c +++ b/wiretap/libpcap.c @@ -33,6 +33,7 @@ #include "pcap-common.h" #include "pcap-encap.h" #include "libpcap.h" +#include "erf.h" /* See source to the "libpcap" library for information on the "libpcap" file format. */ @@ -668,6 +669,14 @@ static gboolean libpcap_read(wtap *wth, int *err, gchar **err_info, } else { wth->phdr.ts.nsecs = hdr.hdr.ts_usec * 1000; } + } else { + /* update frame.interface_id for ERF format */ + wth->phdr.presence_flags |= WTAP_HAS_INTERFACE_ID; + wth->phdr.interface_id = wth->pseudo_header.erf.phdr.flags & 0x03; + + if(!wth->interface_data) { + erf_populate_interfaces(wth); + } } wth->phdr.caplen = packet_size; wth->phdr.len = orig_size; |