aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
diff options
context:
space:
mode:
authorAnthony Coddington <anthony.coddington@endace.com>2016-04-05 14:21:36 +1200
committerAnders Broman <a.broman58@gmail.com>2016-06-21 10:40:18 +0000
commit57b6bc158dfded711436232a14d8ab669fc59e7a (patch)
treed0e7ba5f0d2df37280ca4275e205fcd62cdd0383 /wiretap
parentd50b981d3839b212508523d02004ace41f1a731b (diff)
pcap: ERF per-Host ID/Source ID interface support
Add encap_priv pointer to libpcap_t. Initialize erf_priv when ENCAP_ERF. Use erf_populate_interface_from_header() to dynamically create interfaces. Free encap_priv on pcap_close. Ping-Bug: 12303 Change-Id: Ieda425ef3e50a124d9c38ee4538aa3644128ce60 Reviewed-on: https://code.wireshark.org/review/15362 Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/libpcap.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/wiretap/libpcap.c b/wiretap/libpcap.c
index 66572425e1..9b44b0db5c 100644
--- a/wiretap/libpcap.c
+++ b/wiretap/libpcap.c
@@ -47,6 +47,7 @@ typedef struct {
swapped_type_t lengths_swapped;
guint16 version_major;
guint16 version_minor;
+ void *encap_priv;
} libpcap_t;
/* On some systems, the FDDI MAC addresses are bit-swapped. */
@@ -69,6 +70,7 @@ static gboolean libpcap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err, gchar **err_info);
static int libpcap_read_header(wtap *wth, FILE_T fh, int *err, gchar **err_info,
struct pcaprec_ss990915_hdr *hdr);
+static void libpcap_close(wtap *wth);
wtap_open_return_val libpcap_open(wtap *wth, int *err, gchar **err_info)
{
@@ -263,9 +265,11 @@ wtap_open_return_val libpcap_open(wtap *wth, int *err, gchar **err_info)
libpcap->byte_swapped = byte_swapped;
libpcap->version_major = hdr.version_major;
libpcap->version_minor = hdr.version_minor;
+ libpcap->encap_priv = NULL;
wth->priv = (void *)libpcap;
wth->subtype_read = libpcap_read;
wth->subtype_seek_read = libpcap_seek_read;
+ wth->subtype_close = libpcap_close;
wth->file_encap = file_encap;
wth->snapshot_length = hdr.snaplen;
@@ -443,11 +447,8 @@ done:
wth->file_encap = WTAP_ENCAP_ATM_PDUS;
if (wth->file_encap == WTAP_ENCAP_ERF) {
- /*
- * Populate set of interface IDs for ERF format.
- * Currently, this *has* to be done at open time.
- */
- erf_populate_interfaces(wth);
+ /*Reset the ERF interface lookup table*/
+ libpcap->encap_priv = erf_priv_create();
}
return WTAP_OPEN_MINE;
}
@@ -646,6 +647,8 @@ libpcap_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
int phdr_len;
libpcap_t *libpcap;
+ libpcap = (libpcap_t *)wth->priv;
+
if (!libpcap_read_header(wth, fh, err, err_info, &hdr))
return FALSE;
@@ -709,9 +712,13 @@ libpcap_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
else
phdr->ts.nsecs = hdr.hdr.ts_usec * 1000;
} else {
+ int interface_id;
/* Set interface ID for ERF format */
phdr->presence_flags |= WTAP_HAS_INTERFACE_ID;
- phdr->interface_id = phdr->pseudo_header.erf.phdr.flags & 0x03;
+ if ((interface_id = erf_populate_interface_from_header((erf_t*) libpcap->encap_priv, wth, &phdr->pseudo_header)) < 0)
+ return FALSE;
+
+ phdr->interface_id = (guint) interface_id;
}
phdr->caplen = packet_size;
phdr->len = orig_size;
@@ -722,7 +729,6 @@ libpcap_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
if (!wtap_read_packet_bytes(fh, buf, packet_size, err, err_info))
return FALSE; /* failed */
- libpcap = (libpcap_t *)wth->priv;
pcap_read_post_process(wth->file_type_subtype, wth->file_encap,
phdr, ws_buffer_start_ptr(buf), libpcap->byte_swapped, -1);
return TRUE;
@@ -997,6 +1003,24 @@ static gboolean libpcap_dump(wtap_dumper *wdh,
return TRUE;
}
+static void libpcap_close(wtap *wth)
+{
+ libpcap_t *libpcap = (libpcap_t *)wth->priv;
+
+ if (libpcap->encap_priv) {
+ switch (wth->file_encap) {
+
+ case WTAP_ENCAP_ERF:
+ erf_priv_free((erf_t*) libpcap->encap_priv);
+ break;
+
+ default:
+ g_free(libpcap->encap_priv);
+ break;
+ }
+ }
+}
+
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*