]> The Tcpdump Group git mirrors - tcpdump/commit
Use a table instead of getprotobynumber().
authorDenis Ovsienko <[email protected]>
Sun, 27 Aug 2017 13:15:17 +0000 (14:15 +0100)
committerDenis Ovsienko <[email protected]>
Sun, 27 Aug 2017 13:19:25 +0000 (14:19 +0100)
commitb3fb6a6c61e25ef8be56a2f1da7790a4e5ccd20b
tree0ce06ef12a7abd269a88240027d1e22e56b0a673
parent1b17a8cc5e2f73c17a11b07ada38e2cb173975a7
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.
ipproto.c
ipproto.h
print-cnfp.c
print-ip.c
print-isakmp.c