diff options
author | Guy Harris <gharris@sonic.net> | 2023-08-01 02:02:56 -0700 |
---|---|---|
committer | Guy Harris <gharris@sonic.net> | 2023-08-01 02:02:56 -0700 |
commit | 5daaba1b5d45d111cbd4348d6d4e77fca12953a9 (patch) | |
tree | 9e62c45cd89393e8cfbbbaa82bc27cfc55deabe2 /pcap/dlt.h | |
parent | 193afa491f02dba76ba094b1a6045d548ee37441 (diff) |
Redo DLT_/LINKTYPE_ translation.
Do it with a bunch of ifs rather than with a translation table; that
lets the logic work differently for DLT_ -> LINKTYPE_ mapping and
LINKTYPE_ -> DLT_ mapping.
Have two "matching" ranges, so that the linktypes that preceded the BSDs
all going off in their own directions can be handled as a matching
range.
Avoid doing mapping if the corresponding LINKTYPE_ and DLT_ codes have
the same numerical value.
For LINKTYPE_ -> DLT_ mapping, don't map link-layer type values outside
either of the matching ranges if we don't have a specific mapping set up
for them, just treat the LINKTYPE_ value as if it's a DLT_ value. That
makes us handle some DLT_ codes outside the high mapping range to which
we assigned matching LINKTYPE_ codes, as well as attempting, as best we
can, files written with platform-dependent DLT_ codes (such as DLT_RAW)
as link-layer type codes (programs *on that platform* will handle them
correctly; programs will not do so on other platforms, but that's better
than not handling them correctly anywhere).
Update various comments.
Diffstat (limited to 'pcap/dlt.h')
-rw-r--r-- | pcap/dlt.h | 52 |
1 files changed, 38 insertions, 14 deletions
@@ -58,7 +58,12 @@ /* * These are the types that are the same on all platforms, and that * have been defined by <net/bpf.h> for ages. + * + * DLT_LOW_MATCHING_MIN is the lowest such value; DLT_LOW_MATCHING_MAX + * is the highest such value. */ +#define DLT_LOW_MATCHING_MIN 0 + #define DLT_NULL 0 /* BSD loopback encapsulation */ #define DLT_EN10MB 1 /* Ethernet (10Mb) */ #define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */ @@ -72,13 +77,34 @@ #define DLT_FDDI 10 /* FDDI */ /* + * In case the code that includes this file (directly or indirectly) + * has also included OS files that happen to define DLT_LOW_MATCHING_MAX, + * with a different value (perhaps because that OS hasn't picked up + * the latest version of our DLT definitions), we undefine the + * previous value of DLT_LOW_MATCHING_MAX. + * + * (They shouldn't, because only those 10 values were assigned in + * the Good Old Days, before DLT_ code assignment became a bit of + * a free-for-all. Perhaps 11 is DLT_ATM_RFC1483 everywhere 11 + * is used at all, but 12 is DLT_RAW on some platforms but not + * OpenBSD, and the fun continues for several other values.) + */ +#ifdef DLT_LOW_MATCHING_MAX +#undef DLT_LOW_MATCHING_MAX +#endif + +#define DLT_LOW_MATCHING_MAX DLT_FDDI /* highest value in this "matching" range */ + +/* * These are types that are different on some platforms, and that * have been defined by <net/bpf.h> for ages. We use #ifdefs to * detect the BSDs that define them differently from the traditional * libpcap <net/bpf.h> * * XXX - DLT_ATM_RFC1483 is 13 in BSD/OS, and DLT_RAW is 14 in BSD/OS, - * but I don't know what the right #define is for BSD/OS. + * but I don't know what the right #define is for BSD/OS. The last + * release was in October 2003; if anybody cares about making this + * work on BSD/OS, give us a pull request for a change to make it work. */ #define DLT_ATM_RFC1483 11 /* LLC-encapsulated ATM */ @@ -186,12 +212,10 @@ * anything and doesn't appear to have ever used it for anything.) * * We define it as 18 on those platforms; it is, unfortunately, used - * for DLT_CIP in SUSE 6.3, so we don't define it as DLT_PFSYNC - * in general. As the packet format for it, like that for - * DLT_PFLOG, is not only OS-dependent but OS-version-dependent, - * we don't support printing it in tcpdump except on OSes that - * have the relevant header files, so it's not that useful on - * other platforms. + * for DLT_CIP in SUSE 6.3, so we don't define it as 18 on all + * platforms. We define it as 121 on FreeBSD and as the same + * value that we assigned to LINKTYPE_PFSYNC on all remaining + * platforms. */ #if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__) #define DLT_PFSYNC 18 @@ -236,10 +260,10 @@ * and the LINKTYPE_ value that appears in capture files, are the * same. * - * DLT_MATCHING_MIN is the lowest such value; DLT_MATCHING_MAX is + * DLT_HIGH_MATCHING_MIN is the lowest such value; DLT_HIGH_MATCHING_MAX is * the highest such value. */ -#define DLT_MATCHING_MIN 104 +#define DLT_HIGH_MATCHING_MIN 104 /* * This value was defined by libpcap 0.5; platforms that have defined @@ -1616,15 +1640,15 @@ /* * In case the code that includes this file (directly or indirectly) - * has also included OS files that happen to define DLT_MATCHING_MAX, + * has also included OS files that happen to define DLT_HIGH_MATCHING_MAX, * with a different value (perhaps because that OS hasn't picked up * the latest version of our DLT definitions), we undefine the - * previous value of DLT_MATCHING_MAX. + * previous value of DLT_HIGH_MATCHING_MAX. */ -#ifdef DLT_MATCHING_MAX -#undef DLT_MATCHING_MAX +#ifdef DLT_HIGH_MATCHING_MAX +#undef DLT_HIGH_MATCHING_MAX #endif -#define DLT_MATCHING_MAX 299 /* highest value in the "matching" range */ +#define DLT_HIGH_MATCHING_MAX 299 /* highest value in the "matching" range */ #endif /* !defined(lib_pcap_dlt_h) */ |