From afbb1ce7227dc5edb291f242ed8d95cd3762fc51 Mon Sep 17 00:00:00 2001 From: guy Date: Sat, 29 Sep 2007 19:33:29 +0000 Subject: Based on work from Florent Drouin, split the 32-bit link-layer type field in a capture file into: a 16-bit link-layer type field (it's 16 bits in pcap-NG, and that'll probably be enough for the foreseeable future); a 10-bit "class" field, indicating the group of link-layer type values to which the link-layer type belongs - class 0 is for regular DLT_ values, and class 0x224 grandfathers in the NetBSD "raw address family" link-layer types; a 6-bit "extension" field, storing information about the capture, such an indication of whether the packets include an FCS and, if so, how many bytes of FCS are present. --- savefile.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'savefile.c') diff --git a/savefile.c b/savefile.c index 06804f7..d589a45 100644 --- a/savefile.c +++ b/savefile.c @@ -30,7 +30,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.166 2007-09-29 00:29:14 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.167 2007-09-29 19:33:29 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -834,6 +834,18 @@ static struct linktype_map { { -1, -1 } }; +/* + * Mechanism for storing information about a capture in the upper + * 6 bits of a linktype value in a capture file. + * + * LT_LINKTYPE_EXT(x) extracts the additional information. + * + * The rest of the bits are for a value describing the link-layer + * value. LT_LINKTYPE(x) extracts that value. + */ +#define LT_LINKTYPE(x) ((x) & 0x03FFFFFF) +#define LT_LINKTYPE_EXT(x) ((x) & 0xFC000000) + static int dlt_to_linktype(int dlt) { @@ -1064,7 +1076,8 @@ pcap_fopen_offline(FILE *fp, char *errbuf) } p->tzoff = hdr.thiszone; p->snapshot = hdr.snaplen; - p->linktype = linktype_to_dlt(hdr.linktype); + p->linktype = linktype_to_dlt(LT_LINKTYPE(hdr.linktype)); + p->linktype_ext = LT_LINKTYPE_EXT(hdr.linktype); if (magic == KUZNETZOV_TCPDUMP_MAGIC && p->linktype == DLT_EN10MB) { /* * This capture might have been done in raw mode or cooked @@ -1479,6 +1492,7 @@ pcap_dump_open(pcap_t *p, const char *fname) fname, linktype); return (NULL); } + linktype |= p->linktype_ext; if (fname[0] == '-' && fname[1] == '\0') { f = stdout; @@ -1513,6 +1527,7 @@ pcap_dump_fopen(pcap_t *p, FILE *f) linktype); return (NULL); } + linktype |= p->linktype_ext; return (pcap_setup_dump(p, linktype, f, "stream")); } -- cgit v1.2.3