diff options
author | Denis Ovsienko <denis@ovsienko.info> | 2017-08-27 14:15:17 +0100 |
---|---|---|
committer | Denis Ovsienko <denis@ovsienko.info> | 2017-08-27 14:19:25 +0100 |
commit | b3fb6a6c61e25ef8be56a2f1da7790a4e5ccd20b (patch) | |
tree | 0ce06ef12a7abd269a88240027d1e22e56b0a673 /ipproto.h | |
parent | 1b17a8cc5e2f73c17a11b07ada38e2cb173975a7 (diff) | |
download | tcpdump-b3fb6a6c61e25ef8be56a2f1da7790a4e5ccd20b.tar.gz |
Use a table instead of getprotobynumber().
On Linux getprotobynumber() returns different results for the same
argument depending on the contents of /etc/protocols at runtime
(expectedly but gets in the way of reproducible test cases). On FreeBSD
it returns results that are irrelevant of the contents of /etc/protocols
at runtime (unexpectedly). Other implementations exist and may expose
interesting properties too. And if the host uses LDAP instead of
/etc/protocols for name services, a call to that function may cause LDAP
handle the request. All of the above is not right for the specific task
of network protocols decoding, which needs to be fast and deterministic.
As the protocol number space is just 8-bit, add a 256-element array of
strings/NULLs for the translation and a wrapper function around it for
index range enforcement. Change the code to use the new function instead
of getprotobynumber().
Fix a typo while at it.
Diffstat (limited to 'ipproto.h')
-rw-r--r-- | ipproto.h | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -36,6 +36,7 @@ */ extern const struct tok ipproto_values[]; +extern const char *netdb_protoname (const nd_uint8_t); #ifndef IPPROTO_IP #define IPPROTO_IP 0 /* dummy for IP */ @@ -109,7 +110,7 @@ extern const struct tok ipproto_values[]; * It appears that 62 used to be used, even though that's assigned to * a protocol called CFTP; however, the only reference for CFTP is a * Network Message from BBN back in 1982, so, for now, we support 62, - * aas well as 135, as a protocol number for mobility headers. + * as well as 135, as a protocol number for mobility headers. */ #define IPPROTO_MOBILITY_OLD 62 #endif |