Merge branch 'master' into macsec

This commit is contained in:
Guy Harris 2020-05-27 17:01:23 -07:00 committed by GitHub
commit 7885cfa165
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1314 changed files with 107002 additions and 36411 deletions

49
.appveyor.yml Normal file
View File

@ -0,0 +1,49 @@
version: '{build}'
clone_depth: 5
matrix:
fast_finish: true
install:
- appveyor DownloadFile https://www.winpcap.org/install/bin/WpdPack_4_1_2.zip
- 7z x .\WpdPack_4_1_2.zip -oc:\projects\libpcap\Win32
- appveyor DownloadFile https://nmap.org/npcap/dist/npcap-sdk-1.05.zip
- 7z x .\npcap-sdk-1.05.zip -oc:\projects\libpcap\Win32\npcap-sdk-1.05
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
GENERATOR: "Visual Studio 14 2015"
SDK: WpdPack
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
GENERATOR: "Visual Studio 14 2015 Win64"
SDK: WpdPack
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
GENERATOR: "Visual Studio 14 2015"
SDK: npcap-sdk-1.05
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
GENERATOR: "Visual Studio 14 2015 Win64"
SDK: npcap-sdk-1.05
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
GENERATOR: "Visual Studio 15 2017"
SDK: WpdPack
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
GENERATOR: "Visual Studio 15 2017 Win64"
SDK: WpdPack
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
GENERATOR: "Visual Studio 15 2017"
SDK: npcap-sdk-1.05
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
GENERATOR: "Visual Studio 15 2017 Win64"
SDK: npcap-sdk-1.05
build_script:
#
# Appveyor defaults to cmd.exe, so use cmd.exe syntax.
#
- type NUL >.devel
- md build
- cd build
- cmake -DPCAP_ROOT=c:\projects\libpcap\Win32\%SDK% -G"%GENERATOR%" ..
- msbuild /m /nologo /p:Configuration=Release tcpdump.sln

21
.cirrus.yml Normal file
View File

@ -0,0 +1,21 @@
# The internal git client reads CIRRUS_CLONE_DEPTH.
env:
CIRRUS_CLONE_DEPTH: 3
MAXJOBS: 2
IGNORE_OSVERSION: yes
task:
freebsd_instance:
matrix:
- image_family: freebsd-11-3-snap
- image_family: freebsd-12-1-snap
- image_family: freebsd-13-0-snap
script:
- freebsd-version
- pkg update -f
- pkg install -qy git autoconf
- (cd .. && git clone --depth ${CIRRUS_CLONE_DEPTH} --branch=master --quiet git://github.com/the-tcpdump-group/libpcap.git && cd libpcap && ./configure --prefix=/tmp && make -s -j${MAXJOBS})
- touch .devel
- ./configure
- make -s -j${MAXJOBS} CFLAGS=-Werror all
- make check

View File

@ -3,3 +3,6 @@ To report a security issue please send an e-mail to security@tcpdump.org.
To report bugs and other problems, contribute patches, request a
feature, provide generic feedback etc please see the file
CONTRIBUTING in the tcpdump source tree root.
When reporting bugs and other problems, give tcpdump and libpcap version
with 'tcpdump --version' or './tcpdump --version'

22
.gitignore vendored
View File

@ -18,3 +18,25 @@ tcpdump-*.tar.gz
version.c
failure-outputs.txt
autom4te.cache/
*.VC.db
*.VC.opendb
ALL_BUILD.vcxproj*
ZERO_CHECK.vcxproj*
check.vcxproj*
netdissect.vcxproj*
tcpdump.vcxproj*
uninstall.vcxproj*
CMakeCache.txt
CMakeFiles/
Debug/
Release/
MinSizeRel/
RelWithDebInfo/
cmake_install.cmake
cmake_uninstall.cmake
netdissect.dir/
tcpdump.dir/
tcpdump.sln
.vs/
.passed
.failed

View File

@ -1,26 +1,110 @@
sudo: false
language: c
#
# Try building on these 4 architectures; all are 64-bit, and all but
# "s390x", a/k/a z/Architecture, are little-endian. The crypto library
# on Litle-endian PowerPC/Power ISA does some things that require more
# careful adherence to the documentation, so it's useful for testing
# that.
#
arch:
- amd64
- ppc64le
- s390x
- arm64
os:
- linux
- osx
dist: bionic
compiler:
- gcc
- clang
#
# Linux runs on all of the architectures listed above; macOS currently
# runs only on 64-bit x86, although the Spaceshipologists are all in a
# tizzy about the possibility of Arm-based Macs. Suppress the macOS
# builds that don't work.
#
# In addition, with newer versions of macOS, Apple ships a "gcc" that's
# just another front end to Clang, presumably for backwards
# compatibility with build scripts etc. that expect the compiler to be
# "gcc", so don't bother doing "gcc" builds on macOS.
#
# Furthermore, the Coverity-branch builds seem to time out on the
# non-x86 platforms, so suppress them as well. (Are they supported
# at all?)
#
# XXX - what is the fast_finish clause there for? According to
#
# https://docs.travis-ci.com/user/build-matrix/#fast-finishing
#
# "If some rows in the build matrix are allowed to fail, the build
# won't be marked as finished until they have completed.
#
# To mark the build as finished as soon as possible, add fast_finish:
# true to the jobs section of your .travis.yml like this:
#
# jobs:
# fast_finish: true
#
# Now, the build result will be determined as soon as all the required
# jobs finish, based on these results, while the rest of the
# allow_failures jobs continue to run."
#
# but we *have* no allow_failures jobs.
#
jobs:
fast_finish: true
exclude:
- arch: ppc64le
os: osx
- arch: s390x
os: osx
- arch: arm64
os: osx
- compiler: gcc
os: osx
- if: branch = coverity_scan
arch: ppc64le
- if: branch = coverity_scan
arch: s390x
- if: branch = coverity_scan
arch: arm64
cache: ccache
env:
global:
- BUILD_LIBPCAP=true
# encrypted COVERITY_SCAN_TOKEN from
# https://scan.coverity.com/projects/<project_id>/submit_build?tab=travis_ci
- secure: "DwUeukcRGl1vXNZDDt2237zCA58ZzmzWpCkPcb/Hpeh8OvRw1eBZJiu4L8iD2qtY4A/dPDvOeBiml5MF6bVri9Dui1yPkvkvFqIXzbK5CWS6Ye+NgSBNMwqnAjhTMv/x8I4Bvy9IhDGwj/2JXVUvjBddRMLRyr/ag+MDRB1IVAI="
# Coverity run condition (avoid matrix multiple runs), need customized
# build script. Need an update if new matrix cases.
- coverity_scan_run_condition='"$TRAVIS_OS_NAME" = linux -a "$CC" = gcc'
- coverity_scan_run_condition='"$TRAVIS_CPU_ARCH" = amd64 -a "$TRAVIS_OS_NAME" = linux -a "$CC" = gcc -a "$REMOTE" = enable -a "$CMAKE" = no -a "$CRYPTO" = yes -a "$BUILD_LIBPCAP" = yes'
# Coverity script test mode (if true no uploading, avoid reaching the quota)
# usual processing: false.
- coverity_scan_script_test_mode=false
- MAKEFLAGS='-j 2' # Travis CI VMs come with 2 cores
matrix:
# NOTE: REMOTE= is for the libpcap build, which is done with autotools
# even if we're building tcpdump with CMake.
# It's irrelevant if we're building tcpdump with the system libpcap.
- BUILD_LIBPCAP=no CMAKE=no CRYPTO=no
- BUILD_LIBPCAP=no CMAKE=no CRYPTO=yes
- BUILD_LIBPCAP=no CMAKE=yes CRYPTO=no
- BUILD_LIBPCAP=no CMAKE=yes CRYPTO=yes
- BUILD_LIBPCAP=yes CMAKE=no REMOTE=disable CRYPTO=no
- BUILD_LIBPCAP=yes CMAKE=no REMOTE=disable CRYPTO=yes
- BUILD_LIBPCAP=yes CMAKE=no REMOTE=enable CRYPTO=no
- BUILD_LIBPCAP=yes CMAKE=no REMOTE=enable CRYPTO=yes
- BUILD_LIBPCAP=yes CMAKE=yes REMOTE=disable CRYPTO=no
- BUILD_LIBPCAP=yes CMAKE=yes REMOTE=disable CRYPTO=yes
- BUILD_LIBPCAP=yes CMAKE=yes REMOTE=enable CRYPTO=no
- BUILD_LIBPCAP=yes CMAKE=yes REMOTE=enable CRYPTO=yes
addons:
coverity_scan:
@ -42,10 +126,12 @@ addons:
branch_pattern: coverity_scan
apt:
packages:
- libdbus-1-dev
- libbluetooth-dev
- libnl-genl-3-dev
- libibverbs-dev
- libssl-dev
- libssl0.9.8
- libssl1.0.0
- libdnet-dev
- libsmi2-dev
- libcap-ng-dev
- libpcap-dev
@ -57,24 +143,48 @@ git:
before_install:
- uname -a
- date
- gem install travis-conditions
- if [ "$TRAVIS_OS_NAME" = osx ]; then brew update >/dev/null; fi
- if [ "$TRAVIS_OS_NAME" = linux ]; then apt list --installed 'lib*-dev'; fi
install:
- if [ "$TRAVIS_OS_NAME" = osx ]; then brew install libsmi | grep -v '%'; fi
before_script:
- if [ "$BUILD_LIBPCAP" = true ]; then (cd .. && echo '$ git clone [...] libpcap.git' && git clone --depth=50 --branch=master --quiet git://github.com/the-tcpdump-group/libpcap.git && cd libpcap && ./configure && make); fi
- if [ "$BUILD_LIBPCAP" = yes ]; then (cd .. && echo '$ git clone [...] libpcap.git' && git clone --depth 3 --branch=master --quiet git://github.com/the-tcpdump-group/libpcap.git && cd libpcap && ./configure "--${REMOTE}-remote" --prefix=/tmp && make && make install); fi
script:
- if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then touch .devel configure; fi
- if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then echo '$ ./configure [...]' && echo -n travis_fold:start:script.configure; fi
- if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then ./configure --prefix=/tmp; fi
- if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then echo -n travis_fold:end:script.configure; fi
- if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then make -s; fi
- if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then echo '$ make install [...]' && echo -n travis_fold:start:script.make_install; fi
- if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then PATH=$PATH make install; fi
- if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then echo -n travis_fold:end:script.make_install; fi
- if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then make check; fi
- if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then ./tcpdump -D; fi
- if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then ./tcpdump -J; fi
- if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then ./tcpdump --version; fi
- if [ "$COVERITY_SCAN_BRANCH" = 1 ]; then exit 0; fi
- if [ "$TRAVIS_OS_NAME" = osx ]; then OSX_SSL_DIR=$(ls /usr/local/Cellar/openssl); echo "OSX_SSL_DIR=$OSX_SSL_DIR"; fi
- touch .devel configure
- if [ "$CMAKE" = no ]; then echo '$ ./configure [...]' && echo travis_fold:start:script.configure; fi
- if [ "$CMAKE" = no ]; then ./configure --with-crypto=${CRYPTO} CPPFLAGS="-I/usr/local/Cellar/openssl/$OSX_SSL_DIR/include/" --prefix=/tmp; fi
- if [ "$CMAKE" = no ]; then echo -n travis_fold:end:script.configure; fi
- if [ "$CMAKE" = yes ]; then mkdir build; fi
- if [ "$CMAKE" = yes ]; then cd build; fi
- if [ "$CMAKE" = yes ]; then echo travis_fold:start:script.cmake; fi
- if [ "$CMAKE" = yes ]; then cmake -DWITH_CRYPTO="$CRYPTO" -DCMAKE_PREFIX_PATH=/tmp -DCMAKE_INSTALL_PREFIX=/tmp ..; fi
- if [ "$CMAKE" = yes ]; then echo -n travis_fold:end:script.cmake; fi
- make -s CFLAGS=-Werror
- echo '$ make install [...]' && echo travis_fold:start:script.make_install
- PATH=$PATH make install
- echo -n travis_fold:end:script.make_install
- if [ "$BUILD_LIBPCAP" = yes ]; then make check; fi
- ./tcpdump --version
- ./tcpdump -h
- ./tcpdump -D
- sudo ./tcpdump -J
- sudo ./tcpdump -L
- if [ "$TRAVIS_OS_NAME" = linux -a "$TRAVIS_CPU_ARCH" != ppc64le -a "$TRAVIS_CPU_ARCH" != s390x ]; then sudo ./tcpdump -#n -c 10; fi
- if [ "$CMAKE" = no ]; then make releasetar; fi
- echo '$ cat Makefile [...]'; echo travis_fold:start:script.cat_makefile
- if [ "$CMAKE" = no ]; then cat Makefile | sed -n '1,/DO NOT DELETE THIS LINE -- mkdep uses it/p'; fi
- if [ "$CMAKE" = yes ]; then cat Makefile; fi
- echo -n travis_fold:end:script.cat_makefile
- echo '$ cat config.h'; echo travis_fold:start:script.cat_config_h
- cat config.h
- echo -n travis_fold:end:script.cat_config_h
- if [ "$CMAKE" = no ]; then echo '$ cat config.log'; echo travis_fold:start:script.cat_config_log; fi
- if [ "$CMAKE" = no ]; then cat config.log; fi
- if [ "$CMAKE" = no ]; then echo -n travis_fold:end:script.cat_config_log; fi
- if [ "$TRAVIS_OS_NAME" = osx ]; then sleep 10; fi

117
CHANGES
View File

@ -1,3 +1,116 @@
print-arista.c : Print Arista Specific Protocol.
Sunday September 3, 2017 denis@ovsienko.info
Summary for 4.9.2 tcpdump release
Do not use getprotobynumber() for protocol name resolution. Do not do
any protocol name resolution if -n is specified.
Improve errors detection in the test scripts.
Fix a segfault with OpenSSL 1.1 and improve OpenSSL usage.
Clean up IS-IS printing.
Fix buffer overflow vulnerabilities:
CVE-2017-11543 (SLIP)
CVE-2017-13011 (bittok2str_internal)
Fix infinite loop vulnerabilities:
CVE-2017-12989 (RESP)
CVE-2017-12990 (ISAKMP)
CVE-2017-12995 (DNS)
CVE-2017-12997 (LLDP)
Fix buffer over-read vulnerabilities:
CVE-2017-11541 (safeputs)
CVE-2017-11542 (PIMv1)
CVE-2017-12893 (SMB/CIFS)
CVE-2017-12894 (lookup_bytestring)
CVE-2017-12895 (ICMP)
CVE-2017-12896 (ISAKMP)
CVE-2017-12897 (ISO CLNS)
CVE-2017-12898 (NFS)
CVE-2017-12899 (DECnet)
CVE-2017-12900 (tok2strbuf)
CVE-2017-12901 (EIGRP)
CVE-2017-12902 (Zephyr)
CVE-2017-12985 (IPv6)
CVE-2017-12986 (IPv6 routing headers)
CVE-2017-12987 (IEEE 802.11)
CVE-2017-12988 (telnet)
CVE-2017-12991 (BGP)
CVE-2017-12992 (RIPng)
CVE-2017-12993 (Juniper)
CVE-2017-12994 (BGP)
CVE-2017-12996 (PIMv2)
CVE-2017-12998 (ISO IS-IS)
CVE-2017-12999 (ISO IS-IS)
CVE-2017-13000 (IEEE 802.15.4)
CVE-2017-13001 (NFS)
CVE-2017-13002 (AODV)
CVE-2017-13003 (LMP)
CVE-2017-13004 (Juniper)
CVE-2017-13005 (NFS)
CVE-2017-13006 (L2TP)
CVE-2017-13007 (Apple PKTAP)
CVE-2017-13008 (IEEE 802.11)
CVE-2017-13009 (IPv6 mobility)
CVE-2017-13010 (BEEP)
CVE-2017-13012 (ICMP)
CVE-2017-13013 (ARP)
CVE-2017-13014 (White Board)
CVE-2017-13015 (EAP)
CVE-2017-11543 (SLIP)
CVE-2017-13016 (ISO ES-IS)
CVE-2017-13017 (DHCPv6)
CVE-2017-13018 (PGM)
CVE-2017-13019 (PGM)
CVE-2017-13020 (VTP)
CVE-2017-13021 (ICMPv6)
CVE-2017-13022 (IP)
CVE-2017-13023 (IPv6 mobility)
CVE-2017-13024 (IPv6 mobility)
CVE-2017-13025 (IPv6 mobility)
CVE-2017-13026 (ISO IS-IS)
CVE-2017-13027 (LLDP)
CVE-2017-13028 (BOOTP)
CVE-2017-13029 (PPP)
CVE-2017-13030 (PIM)
CVE-2017-13031 (IPv6 fragmentation header)
CVE-2017-13032 (RADIUS)
CVE-2017-13033 (VTP)
CVE-2017-13034 (PGM)
CVE-2017-13035 (ISO IS-IS)
CVE-2017-13036 (OSPFv3)
CVE-2017-13037 (IP)
CVE-2017-13038 (PPP)
CVE-2017-13039 (ISAKMP)
CVE-2017-13040 (MPTCP)
CVE-2017-13041 (ICMPv6)
CVE-2017-13042 (HNCP)
CVE-2017-13043 (BGP)
CVE-2017-13044 (HNCP)
CVE-2017-13045 (VQP)
CVE-2017-13046 (BGP)
CVE-2017-13047 (ISO ES-IS)
CVE-2017-13048 (RSVP)
CVE-2017-13049 (Rx)
CVE-2017-13050 (RPKI-Router)
CVE-2017-13051 (RSVP)
CVE-2017-13052 (CFM)
CVE-2017-13053 (BGP)
CVE-2017-13054 (LLDP)
CVE-2017-13055 (ISO IS-IS)
CVE-2017-13687 (Cisco HDLC)
CVE-2017-13688 (OLSR)
CVE-2017-13689 (IKEv1)
CVE-2017-13690 (IKEv2)
CVE-2017-13725 (IPv6 routing headers)
Sunday July 23, 2017 denis@ovsienko.info
Summary for 4.9.1 tcpdump release
CVE-2017-11108/Fix bounds checking for STP.
Make assorted documentation updates and fix a few typos in tcpdump output.
Fixup -C for file size >2GB (GH #488).
Show AddressSanitizer presence in version output.
Fix a bug in test scripts (exposed in GH #613).
On FreeBSD adjust Capsicum capabilities for netmap.
On Linux fix a use-after-free when the requested interface does not exist.
Wednesday January 18, 2017 devel.fx.lebail@orange.fr
Summary for 4.9.0 tcpdump release
General updates:
@ -502,7 +615,7 @@ Wed. April 25, 2007. ken@xelerance.com. Summary for 3.9.6 tcpdump release
Add support for CFM Link-trace msg, Link-trace-Reply msg,
Sender-ID tlv, private tlv, port, interface status
Add support for unidirectional link detection as per
http://www.ietf.org/internet-drafts/draft-foschiano-udld-02.txt
https://tools.ietf.org/id/draft-foschiano-udld-02.txt
Add support for the olsr protocol as per RFC 3626 plus the LQ
extensions from olsr.org
Add support for variable-length checksum in DCCP, as per section 9 of
@ -607,7 +720,7 @@ Tue. March 30, 2004. mcr@sandelman.ottawa.on.ca. Summary for 3.8.3 release
Mon. March 29, 2004. mcr@sandelman.ottawa.on.ca. Summary for 3.8.2 release
Fixes for print-isakmp.c CVE: CAN-2004-0183, CAN-2004-0184
http://www.rapid7.com/advisories/R7-0017.html
https://web.archive.org/web/20160328035955/https://www.rapid7.com/resources/advisories/R7-0017.jsp
IP-over-IEEE1394 printing.
some MINGW32 changes.
updates for autoconf 2.5

1218
CMakeLists.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -31,7 +31,7 @@ Please note that if you know exactly how to solve the problem and the solution
would not be too intrusive, it would be best to contribute some development time
and open a pull request instead as discussed below.
Still not sure how to do? Feel free to [subscribe](http://www.tcpdump.org/#mailing-lists)
Still not sure how to do? Feel free to [subscribe](https://www.tcpdump.org/#mailing-lists)
to the mailing list tcpdump-workers@lists.tcpdump.org and ask!
@ -45,10 +45,14 @@ How to add new code and to update existing code
https://github.com/the-tcpdump-group/tcpdump
(See https://help.github.com/articles/fork-a-repo/)
2) Setup an optional Travis-CI build
You can setup a travis build for your fork. So, you can test your changes
on Linux and OSX before sending pull requests.
(See http://docs.travis-ci.com/user/getting-started/)
2) Setup optional Travis CI build and AppVeyor builds
You can setup Travis CI and AppVeyor builds for your fork, so you can
test your changes on Linux, macOS, and Windows before sending pull
requests.
(See https://docs.travis-ci.com/user/tutorial/ for information
on setting up Travis CI; go to https://ci.appveyor.com/login and log
in with your GitHub account and select "NEW PROJECT" to set up an
AppVeyor build.)
3) Setup your git working copy
git clone https://github.com/<username>/tcpdump.git
@ -68,9 +72,14 @@ How to add new code and to update existing code
6) Add/update sample.pcap files
We use tests directory to do regression tests on the dissection of captured
packets, by running tcpdump against a savefile sample.pcap, created with -w
option and comparing the results with a text file sample.out giving the
expected results.
packets. Those captured packets were saved running tcpdump with option "-w
sample.pcap". Additional options, such as "-n", are used to create relevant
and reproducible output; "-#" is used to indicate which particular packets
have output that differs. The tests are run with the TZ environment
variable set to GMT0, so that UTC, rather than the local time where the
tests are being run, is used when "local time" values are printed. The
actual test compares the current text output with the expected result
(sample.out) saved from a previous version.
Any new/updated fields in a dissector must be present in a sample.pcap file
and the corresponding output file.
@ -79,8 +88,10 @@ How to add new code and to update existing code
Each line in this file has the following format:
test-name sample.pcap sample.out tcpdump-options
the sample.out file can be build by:
(cd tests && ../tcpdump -n -r sample.pcap tcpdump-options > sample.out)
The sample.out file can be build by:
(cd tests && TZ=GMT0 ../tcpdump -# -n -r sample.pcap tcpdump-options > sample.out)
Or, for convenience, use "./update-test.sh test-name"
It is often useful to have test outputs with different verbosity levels
(none, -v, -vv, -vvv, etc.) depending on the code.
@ -95,9 +106,13 @@ How to add new code and to update existing code
9) Once 100% happy, put your work into your forked repository.
git push
This will trigger both Travis CI and AppVeyor builds.
10) Initiate and send a pull request
(See https://help.github.com/articles/using-pull-requests/)
(See https://help.github.com/articles/using-pull-requests/)
Note that creating the pull request will cause your code to be
tested on Linux and macOS with Travis CI and on Windows with
AppVeyor.
Code style and generic remarks
@ -111,11 +126,20 @@ c) Put the format of packets/headers/options as comments if there is no
d) The printer may receive incomplete packet in the buffer, truncated at any
random position, for example by capturing with '-s size' option.
Thus use ND_TTEST, ND_TTEST2, ND_TCHECK or ND_TCHECK2 for bound checking.
For ND_TCHECK2:
Define : static const char tstr[] = " [|protocol]";
Thus use, for bounds checking, one of the following macros (defined in
netdissect.h or extract.h):
ND_TCHECK_n(p), n in { 1, 2, 3, 4, 5, 6, 7, 8, 16 }
ND_TCHECK_SIZE(p)
ND_TCHECK_LEN(p, l)
ND_TTEST_n(p), n in { 1, 2, 3, 4, 5, 6, 7, 8, 16 }
ND_TTEST_SIZE(p)
ND_TTEST_LEN(p, l)
For the ND_TCHECK_* macros (if not already done):
Assign: ndo->ndo_protocol = "protocol";
Define a label: trunc
Print with: ND_PRINT((ndo, "%s", tstr));
Print with: nd_print_trunc(ndo);
You can test the code via:
sudo ./tcpdump -s snaplen [-v][v][...] -i lo # in a terminal
sudo tcpreplay -i lo sample.pcap # in another terminal
@ -124,8 +148,8 @@ d) The printer may receive incomplete packet in the buffer, truncated at any
e) Do invalid packet checks in code: Think that your code can receive in input
not only a valid packet but any arbitrary random sequence of octets (packet
- built malformed originally by the sender or by a fuzz tester,
- became corrupted in transit).
Print with: ND_PRINT((ndo, "%s", istr)); /* to print " (invalid)" */
- became corrupted in transit or for some other reason).
Print with: nd_print_invalid(ndo); /* to print " (invalid)" */
f) Use 'struct tok' for indexed strings and print them with
tok2str() or bittok2str() (for flags).

25
CREDITS
View File

@ -1,16 +1,12 @@
This file lists people who have contributed to tcpdump:
This file lists people who have contributed to tcpdump.
The current maintainers:
Bill Fenner <fenner at research dot att dot com>
The current maintainers (in alphabetical order):
Denis Ovsienko <denis at ovsienko dot info>
Fulvio Risso <risso at polito dot it>
Francois-Xavier Le Bail <devel dot fx dot lebail at orange dot fr>
Guy Harris <guy at alum dot mit dot edu>
Hannes Gredler <hannes at juniper dot net>
Michael Richardson <mcr at sandelman dot ottawa dot on dot ca>
Francois-Xavier Le Bail <fx dot lebail at yahoo dot com>
Additional people who have contributed patches:
Additional people who have contributed patches (in alphabetical order):
Aaron Campbell <aaron at arbor dot net>
A Costa <agcosta at gis dot net>
Albert Chin <china at thewrittenword dot com>
@ -66,6 +62,7 @@ Additional people who have contributed patches:
Don Ebright <Don dot Ebright at compuware dot com>
Eddie Kohler <xexd at sourceforge dot net>
Elmar Kirchner <elmar at juniper dot net>
Etienne Marais <etienne at marais dot green>
Fang Wang <fangwang at sourceforge dot net>
Florent Drouin <Florent dot Drouin at alcatel-lucent dot fr>
Florian Forster <octo at verplant dot org>
@ -97,6 +94,7 @@ Additional people who have contributed patches:
Jacek Tobiasz <Jacek dot Tobiasz at atm dot com dot pl>
Jakob Schlyter <jakob at openbsd dot org>
Jamal Hadi Salim <hadi at cyberus dot ca>
James Ko <jck at exegin dot com>
Jan Oravec <wsx at wsx6 dot net>
Jason R. Thorpe <thorpej at netbsd dot org>
Jefferson Ogata <jogata at nodc dot noaa dot gov>
@ -126,7 +124,7 @@ Additional people who have contributed patches:
Krzysztof Halasa <khc at pm dot waw dot pl>
Larry Lile <lile at stdio dot com>
Lennert Buytenhek <buytenh at gnu dot org>
Loganaden Velvindron <logan at elandsys dot com>
Loganaden Velvindron <logan at cyberstorm dot mu>
Loris Degioanni <loris at netgroup-serv dot polito dot it>
Love Hörnquist-Åstrand <lha at stacken dot kth dot se>
Lucas C. Villa Real <lucasvr at us dot ibm dot com>
@ -161,6 +159,7 @@ Additional people who have contributed patches:
Nickolai Zeldovich <kolya at MIT dot EDU>
Nicolas Ferrero <toorop at babylo dot net>
Niels Provos <provos at openbsd dot org>
Nikhil AP <nikhilap at arista dot com>
Noritoshi Demizu <demizu at users dot sourceforge dot net>
Olaf Kirch <okir at caldera dot de>
Ola Martin Lykkja <ola dot lykkja at q-free dot com>
@ -195,6 +194,7 @@ Additional people who have contributed patches:
Ruben Kerkhof <ruben at rubenkerkhof dot com>
Sagun Shakya <sagun dot shakya at sun dot com>
Sami Farin <safari at iki dot fi>
Sawssen Hadded <saw.hadded at gmail dot com>
Scott Mcmillan <scott dot a dot mcmillan at intel dot com>
Scott Rose <syberpunk at users dot sourceforge dot net>
Sebastian Krahmer <krahmer at cs dot uni-potsdam dot de>
@ -234,5 +234,8 @@ The original LBL crew:
Craig Leres
Van Jacobson
Past maintainers:
Jun-ichiro itojun Hagino <itojun at iijlab dot net> Also see: http://www.wide.ad.jp/itojun-award/
Past maintainers (in alphabetical order):
Bill Fenner <fenner at research dot att dot com>
Fulvio Risso <risso at polito dot it>
Hannes Gredler <hannes at gredler dot at>
Jun-ichiro itojun Hagino <itojun at iijlab dot net> Also see: http://www.wide.ad.jp/itojun-award/

View File

@ -48,6 +48,8 @@ VERSION - version of this release
aclocal.m4 - autoconf macros
addrtoname.c - address to hostname routines
addrtoname.h - address to hostname definitions
addrtostr.c - address to printable string routines
addrtostr.h - address to printable string definitions
ah.h - IPSEC Authentication Header definitions
appletalk.h - AppleTalk definitions
ascii_strcasecmp.c - locale-independent case-independent string comparison
@ -63,14 +65,11 @@ config.guess - autoconf support
config.h.in - autoconf input
config.sub - autoconf support
configure - configure script (run this first)
configure.in - configure script source
ether.h - Ethernet definitions
configure.ac - configure script source
ethertype.h - Ethernet type value definitions
extract.h - alignment definitions
gmpls.c - GMPLS definitions
gmpls.h - GMPLS declarations
gmt2local.c - time conversion routines
gmt2local.h - time conversion prototypes
install-sh - BSD style install script
interface.h - globals, prototypes and definitions
ip.h - IP definitions
@ -86,6 +85,8 @@ machdep.h - machine dependent definitions
makemib - mib to header script
mib.h - mib definitions
missing/* - replacements for missing library functions
ntp.c - functions to handle ntp structs
ntp.h - declarations of functions to handle ntp structs
mkdep - construct Makefile dependency list
mpls.h - MPLS definitions
nameser.h - DNS definitions
@ -98,8 +99,6 @@ nlpid.h - OSI NLPID definitions
ospf.h - Open Shortest Path First definitions
packetdat.awk - TCP chunk summary awk script
parsenfsfh.c - Network File System file parser routines
pcap_dump_ftell.c - pcap_dump_ftell() implementation, in case libpcap
doesn't have it
pcap-missing.h - declarations of functions possibly missing from libpcap
ppp.h - Point to Point Protocol definitions
print.c - Top-level routines for protocol printing
@ -107,8 +106,6 @@ print-*.c - The netdissect printers
rpc_auth.h - definitions for ONC RPC authentication
rpc_msg.h - definitions for ONC RPC messages
send-ack.awk - unidirectional tcp send/ack awk script
setsignal.c - OS-independent signal routines
setsignal.h - OS-independent signal prototypes
slcompress.h - SLIP/PPP Van Jacobson compression (RFC1144) definitions
smb.h - SMB/CIFS definitions
smbutil.c - SMB/CIFS utility routines
@ -119,5 +116,4 @@ tcpdump.c - main program
timeval-operations.h - timeval operations macros
udp.h - UDP definitions
util-print.c - utility routines for protocol printers
vfprintf.c - emulation routine
win32 - headers and routines for building on Win32 systems

View File

@ -1,9 +1,9 @@
License: BSD
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
@ -13,7 +13,7 @@ are met:
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

View File

@ -2,12 +2,12 @@
# Auto-regenerate configure script or Makefile when things change.
# From autoconf.info . Works best with GNU Make.
#
${srcdir}/configure: configure.in aclocal.m4
${srcdir}/configure: configure.ac aclocal.m4
cd ${srcdir} && autoconf
# autoheader might not change config.h.in, so touch a stamp file.
${srcdir}/config.h.in: ${srcdir}/stamp-h.in
${srcdir}/stamp-h.in: configure.in aclocal.m4
${srcdir}/stamp-h.in: configure.ac aclocal.m4
cd ${srcdir} && autoheader
echo timestamp > ${srcdir}/stamp-h.in

View File

@ -32,6 +32,7 @@ mandir = @mandir@
# VPATH
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
#
@ -70,7 +71,7 @@ DEPENDENCY_CFLAG = @DEPENDENCY_CFLAG@
@rm -f $@
$(CC) $(FULL_CFLAGS) -c $(srcdir)/$*.c
CSRC = setsignal.c tcpdump.c
CSRC = fptype.c tcpdump.c
LIBNETDISSECT_SRC=\
addrtoname.c \
@ -80,12 +81,14 @@ LIBNETDISSECT_SRC=\
checksum.c \
cpack.c \
gmpls.c \
gmt2local.c \
in_cksum.c \
ipproto.c \
l2vpn.c \
machdep.c \
netdissect.c \
netdissect-alloc.c \
nlpid.c \
ntp.c \
oui.c \
parsenfsfh.c \
print.c \
@ -97,15 +100,18 @@ LIBNETDISSECT_SRC=\
print-aoe.c \
print-ap1394.c \
print-arcnet.c \
print-arista.c \
print-arp.c \
print-ascii.c \
print-atalk.c \
print-atm.c \
print-babel.c \
print-bcm-li.c \
print-beep.c \
print-bfd.c \
print-bgp.c \
print-bootp.c \
print-brcmtag.c \
print-bt.c \
print-calm-fast.c \
print-carp.c \
@ -118,6 +124,7 @@ LIBNETDISSECT_SRC=\
print-decnet.c \
print-dhcp6.c \
print-domain.c \
print-dsa.c \
print-dtp.c \
print-dvmrp.c \
print-eap.c \
@ -141,12 +148,14 @@ LIBNETDISSECT_SRC=\
print-icmp6.c \
print-igmp.c \
print-igrp.c \
print-ip-demux.c \
print-ip.c \
print-ip6.c \
print-ip6opts.c \
print-ipcomp.c \
print-ipfc.c \
print-ipnet.c \
print-ipoib.c \
print-ipx.c \
print-isakmp.c \
print-isoclns.c \
@ -165,7 +174,6 @@ LIBNETDISSECT_SRC=\
print-lwres.c \
print-m3ua.c \
print-macsec.c \
print-medsa.c \
print-mobile.c \
print-mobility.c \
print-mpcp.c \
@ -191,6 +199,7 @@ LIBNETDISSECT_SRC=\
print-ppp.c \
print-pppoe.c \
print-pptp.c \
print-ptp.c \
print-radius.c \
print-raw.c \
print-resp.c \
@ -210,6 +219,8 @@ LIBNETDISSECT_SRC=\
print-slow.c \
print-smtp.c \
print-snmp.c \
print-someip.c \
print-ssh.c \
print-stp.c \
print-sunatm.c \
print-sunrpc.c \
@ -223,34 +234,35 @@ LIBNETDISSECT_SRC=\
print-token.c \
print-udld.c \
print-udp.c \
print-unsupported.c \
print-usb.c \
print-vjc.c \
print-vqp.c \
print-vrrp.c \
print-vsock.c \
print-vtp.c \
print-vxlan.c \
print-vxlan-gpe.c \
print-vxlan.c \
print-wb.c \
print-zep.c \
print-zephyr.c \
print-zeromq.c \
netdissect.c \
signature.c \
strtoaddr.c \
util-print.c
LOCALSRC = @LOCALSRC@
GENSRC = version.c
LIBOBJS = @LIBOBJS@
LIBNETDISSECT_OBJ=$(LIBNETDISSECT_SRC:.c=.o) ${LOCALSRC:.c=.o} ${LIBOBJS}
LIBNETDISSECT=libnetdissect.a
SRC = $(CSRC) $(GENSRC) $(LOCALSRC) $(LIBNETDISSECT_SRC)
SRC = $(CSRC) $(GENSRC) $(LOCALSRC)
# We would like to say "OBJ = $(SRC:.c=.o)" but Ultrix's make cannot
# hack the extra indirection
OBJ = $(CSRC:.c=.o) $(GENSRC:.c=.o) $(LIBNETDISSECT_OBJ)
OBJ = $(CSRC:.c=.o) $(GENSRC:.c=.o)
HDR = \
addrtoname.h \
addrtostr.h \
@ -260,13 +272,14 @@ HDR = \
ascii_strcasecmp.h \
atm.h \
chdlc.h \
compiler-tests.h \
cpack.h \
ether.h \
ethertype.h \
extract.h \
getopt_long.h \
fptype.h \
funcattrs.h \
getservent.h \
gmpls.h \
gmt2local.h \
interface.h \
ip.h \
ip6.h \
@ -278,9 +291,13 @@ HDR = \
mpls.h \
nameser.h \
netdissect.h \
netdissect-alloc.h \
netdissect-ctype.h \
netdissect-stdinc.h \
nfs.h \
nfsfh.h \
nlpid.h \
ntp.h \
openflow.h \
ospf.h \
oui.h \
@ -289,16 +306,15 @@ HDR = \
print.h \
rpc_auth.h \
rpc_msg.h \
rpl.h \
setsignal.h \
signature.h \
slcompress.h \
smb.h \
status-exit-codes.h \
strtoaddr.h \
tcp.h \
netdissect-stdinc.h \
timeval-operations.h \
udp.h
udp.h \
varattrs.h
TAGHDR = \
/usr/include/arpa/tftp.h \
@ -310,14 +326,16 @@ TAGHDR = \
/usr/include/netinet/udp.h \
/usr/include/protocols/routed.h
TAGFILES = $(SRC) $(HDR) $(TAGHDR)
TAGFILES = $(SRC) $(HDR) $(TAGHDR) $(LIBNETDISSECT_SRC) \
print-pflog.c print-smb.c smbutil.c
CLEANFILES = $(PROG) $(OBJ) $(GENSRC)
CLEANFILES = $(PROG) $(OBJ) $(GENSRC) $(LIBNETDISSECT_OBJ)
EXTRA_DIST = \
CHANGES \
CONTRIBUTING \
CREDITS \
CMakeLists.txt \
INSTALL.txt \
LICENSE \
Makefile.in \
@ -330,11 +348,17 @@ EXTRA_DIST = \
aclocal.m4 \
atime.awk \
bpf_dump.c \
cmake_uninstall.cmake.in \
cmakeconfig.h.in \
cmake/Modules/FindCRYPTO.cmake \
cmake/Modules/FindPCAP.cmake \
cmake/Modules/FindSMI.cmake \
config.guess \
config.h.in \
config.sub \
configure \
configure.in \
configure.ac \
doc/README.Win32.md \
install-sh \
lbl/os-osf4.h \
lbl/os-solaris2.h \
@ -343,36 +367,37 @@ EXTRA_DIST = \
makemib \
missing/dlnames.c \
missing/datalinks.c \
missing/getopt_long.h \
missing/getopt_long.c \
missing/getservent.c \
missing/pcap_dump_ftell.c \
missing/snprintf.c \
missing/strdup.c \
missing/strlcat.c \
missing/strlcpy.c \
missing/strsep.c \
missing/win_ether_ntohost.c \
missing/win_ether_ntohost.h \
mkdep \
packetdat.awk \
pcap_dump_ftell.c \
print-pflog.c \
print-smb.c \
send-ack.awk \
smbutil.c \
stime.awk \
tcpdump.1.in \
vfprintf.c \
win32/prj/GNUmakefile \
win32/prj/WinDump.dsp \
win32/prj/WinDump.dsw \
win32/prj/WinDump.sln \
win32/prj/WinDump.vcproj \
win32/src/ether_ntohost.c
win32/prj/WinDump.vcproj
TEST_DIST= `find tests \( -name 'DIFF' -prune \) -o \( -name NEW -prune \) -o -type f \! -name '.*' \! -name '*~' -print`
TEST_DIST= `git ls-files tests | grep -v 'tests/\..*'`
all: $(PROG) $(LIBNETDISSECT)
all: $(PROG)
$(PROG): $(OBJ) @V_PCAPDEP@
$(PROG): $(OBJ) @V_PCAPDEP@ $(LIBNETDISSECT)
@rm -f $@
$(CC) $(FULL_CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
$(CC) $(FULL_CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBNETDISSECT) $(LIBS)
$(LIBNETDISSECT): $(LIBNETDISSECT_OBJ)
@rm -f $@
@ -383,6 +408,8 @@ datalinks.o: $(srcdir)/missing/datalinks.c
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/datalinks.c
dlnames.o: $(srcdir)/missing/dlnames.c
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/dlnames.c
getservent.o: $(srcdir)/missing/getservent.c
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/getservent.c
getopt_long.o: $(srcdir)/missing/getopt_long.c
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/getopt_long.c
snprintf.o: $(srcdir)/missing/snprintf.c
@ -395,19 +422,8 @@ strlcpy.o: $(srcdir)/missing/strlcpy.c
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strlcpy.c
strsep.o: $(srcdir)/missing/strsep.c
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strsep.c
version.o: version.c
$(CC) $(FULL_CFLAGS) -c version.c
version.c: $(srcdir)/VERSION
@rm -f $@
if grep GIT ${srcdir}/VERSION >/dev/null; then \
read ver <${srcdir}/VERSION; \
echo $$ver | tr -d '\012'; \
date +_%Y_%m_%d; \
else \
cat ${srcdir}/VERSION; \
fi | sed -e 's/.*/const char version[] = "&";/' > $@
pcap_dump_ftell.o: $(srcdir)/missing/pcap_dump_ftell.c
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/pcap_dump_ftell.c
install: all
[ -d $(DESTDIR)$(sbindir) ] || \
@ -423,7 +439,7 @@ uninstall:
rm -f $(DESTDIR)$(mandir)/man1/$(PROG).1
lint: $(GENSRC)
lint -hbxn $(SRC) | \
lint -hbxn $(SRC) $(LIBNETDISSECT_SRC) | \
grep -v 'struct/union .* never defined' | \
grep -v 'possible pointer alignment problem'
@ -438,7 +454,7 @@ distclean:
rm -rf autom4te.cache tests/DIFF tests/NEW
check: tcpdump
(cd tests && ./TESTrun.sh)
$(srcdir)/tests/TESTrun
extags: $(TAGFILES)
ctags $(TAGFILES)
@ -450,7 +466,7 @@ TAGS: $(TAGFILES)
etags $(TAGFILES)
releasetar:
@cwd=`pwd` ; dir=`basename $$cwd` ; name=$(PROG)-`cat VERSION` ; \
@name=$(PROG)-`cat VERSION` ; \
mkdir $$name; \
tar cf - $(CSRC) $(HDR) $(LIBNETDISSECT_SRC) $(EXTRA_DIST) $(TEST_DIST) | (cd $$name; tar xf -); \
tar -c -z -f $$name.tar.gz $$name; \
@ -460,4 +476,4 @@ testlist:
echo $(TEST_DIST)
depend: $(GENSRC)
$(MKDEP) -c $(CC) -m $(DEPENDENCY_CFLAG) $(DEFS) $(INCLS) $(SRC)
$(MKDEP) -c "$(CC)" -m "$(DEPENDENCY_CFLAG)" -s "$(srcdir)" $(DEFS) $(INCLS) $(SRC) $(LIBNETDISSECT_SRC)

View File

@ -6,11 +6,13 @@ recent snapshot it will take to compile tcpdump from the source code.
tcpdump compiles and works on at least the following platforms:
* AIX
* DragonFly BSD
* FreeBSD
* HP-UX 11i
* Linux (any) with glibc (usually just works)
* Linux (any) with musl libc (sometimes fails to compile, please report any bugs)
* Mac OS X / macOS
* {Mac} OS X / macOS
* NetBSD
* OpenBSD
* OpenWrt
* Solaris

View File

@ -1,7 +1,8 @@
# tcpdump
[![Build
Status](https://travis-ci.org/the-tcpdump-group/tcpdump.png)](https://travis-ci.org/the-tcpdump-group/tcpdump)
[![Build Status](https://travis-ci.org/the-tcpdump-group/tcpdump.svg?branch=master)](https://travis-ci.org/the-tcpdump-group/tcpdump)
[![Build Status](https://ci.appveyor.com/api/projects/status/github/the-tcpdump-group/tcpdump?branch=master&svg=true)](https://ci.appveyor.com/project/guyharris/tcpdump)
To report a security issue please send an e-mail to security@tcpdump.org.
@ -11,14 +12,14 @@ CONTRIBUTING in the tcpdump source tree root.
TCPDUMP 4.x.y
Now maintained by "The Tcpdump Group"
See www.tcpdump.org
See https://www.tcpdump.org
Anonymous Git is available via:
git clone git://bpf.tcpdump.org/tcpdump
formerly from Lawrence Berkeley National Laboratory
Network Research Group <tcpdump@ee.lbl.gov>
Network Research Group <tcpdump@ee.lbl.gov>
ftp://ftp.ee.lbl.gov/old/tcpdump.tar.Z (3.4)
This directory contains source code for tcpdump, a tool for network
@ -26,12 +27,12 @@ monitoring and data acquisition. This software was originally
developed by the Network Research Group at the Lawrence Berkeley
National Laboratory. The original distribution is available via
anonymous ftp to `ftp.ee.lbl.gov`, in `tcpdump.tar.Z`. More recent
development is performed at tcpdump.org, http://www.tcpdump.org/
development is performed at tcpdump.org, https://www.tcpdump.org/.
Tcpdump uses libpcap, a system-independent interface for user-level
packet capture. Before building tcpdump, you must first retrieve and
build libpcap, also originally from LBL and now being maintained by
tcpdump.org; see http://www.tcpdump.org/ .
tcpdump.org; see https://www.tcpdump.org/.
Once libpcap is built (either install it or make sure it's in
`../libpcap`), you can build tcpdump using the procedure in the `INSTALL.txt`
@ -57,7 +58,7 @@ about tcpdump and how to interpret its output, pick up this book.
Some tools for viewing and analyzing tcpdump trace files are available
from the Internet Traffic Archive:
* http://www.sigcomm.org/ITA/
* http://ita.ee.lbl.gov/
Another tool that tcpdump users might find useful is tcpslice:
@ -67,9 +68,9 @@ It is a program that can be used to extract portions of tcpdump binary
trace files. See the above distribution for further details and
documentation.
Current versions can be found at www.tcpdump.org.
Current versions can be found at https://www.tcpdump.org.
- The TCPdump team
- The TCPdump group
original text by: Steve McCanne, Craig Leres, Van Jacobson

View File

@ -1,24 +1,46 @@
To build tcpdump under Windows, you need:
- version 6 (or higher) of Microsoft Visual Studio or the Cygnus gnu
C compiler.
- The November 2001 (or later) edition of Microsoft Platform
Software Development Kit (SDK), that contains some necessary includes
for IPv6 support. You can download it from http://www.microsoft.com/sdk
- the WinPcap source code, that includes libpcap for win32. Download it
from http://winpcap.polito.it or download libpcap sources from
http://www.tcpdump.org and follow the instructions in the README.Win32
file.
- Microsoft Visual Studio 2015 or later
- the WinPcap or Npcap SDK, which includes libpcap for win32. The
WinPcap SDK can be doneloaded from
First, extract tcpdump and WinPcap in the same folder, and build WinPcap.
https://www.winpcap.org/devel.htm
The Visual Studio project and the cygwin makefile are in the Win32\prj
folder.
and the Npcap SDK can be downloaded from
From Visual Studio, open windump.dsw and build the program. The release
version of the WinDump.exe executable file will be created in the
windump\win32\prj\release directory . The debug version will be generated
in windump\win32\prj\debug.
https://nmap.org/npcap/
- CMake, which can be downloadd from
From cygnus, go to windump\win32\prj\ and type "make". WinDump.exe will be
created in the same directory.
https://cmake.org
First, make a build directory, either as a subdirectory of the tcpdump
source directory or as a separate directory.
Second, change to the build directory, and run CMake with the following
arguments:
-DCMAKE_PREFIX_PATH={pathname of the WinPcap/Npcap SDK}
-G {generator}
the pathname of the tcpdump source directory relative to the build
directory (".." if the build directory is a subdirectory of the
tcpdump source directory).
"{generator}" would be the string "Visual Studio N YYYY", where "N" is
the version of Visual Studio and "YYYY" is the year number for that
version; if you are building a 64-bit version of tcpdump, YYYY must be
followed by a space and "Win64". For example, to build a 32-bit version
of tcpdump with Visual Studio 2015, "{generator}" would be "Visual
Studio 14 2015" and to build a 64-bit version of tcpdump with Visual
Studio 2017, "{generator}" would be "Visual Studio 15 2017 Win64".
Third, from the build directory, run the command
msbuild /m /nologo /p:Configuration={configuration} tcpdump.sln
where {configuration} can be "Release", "Debug", or "RelWithDebInfo", or
build tcpdump from the Visual Studio application using the solution file
in question.
(XXX - rules for building with MinGW should be added.)

799
aclocal.m4 vendored
View File

@ -102,14 +102,6 @@ AC_DEFUN(AC_LBL_C_INIT,
# -Werror forces warnings to be errors.
#
ac_lbl_cc_force_warning_errors=-Werror
#
# Use -ffloat-store so that, on 32-bit x86, we don't
# do 80-bit arithmetic with the FPU; that way we should
# get the same results for floating-point calculations
# on x86-32 and x86-64.
#
AC_LBL_CHECK_COMPILER_OPT($1, -ffloat-store)
else
$2="$$2 -I/usr/local/include"
LDFLAGS="$LDFLAGS -L/usr/local/lib"
@ -169,7 +161,7 @@ AC_DEFUN(AC_LBL_C_INIT,
;;
osf*)
#
#
# Presumed to be DEC OSF/1, Digital UNIX, or
# Tru64 UNIX.
#
@ -371,11 +363,10 @@ AC_DEFUN(AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT,
if test ! -z "$ac_lbl_dependency_flag"; then
AC_LANG_CONFTEST(
[AC_LANG_SOURCE([[int main(void) { return 0; }]])])
echo "$CC" $ac_lbl_dependency_flag conftest.c >&5
if "$CC" $ac_lbl_dependency_flag conftest.c >/dev/null 2>&1; then
if AC_RUN_LOG([eval "$CC $ac_lbl_dependency_flag conftest.c >/dev/null 2>&1"]); then
AC_MSG_RESULT([yes, with $ac_lbl_dependency_flag])
DEPENDENCY_CFLAG="$ac_lbl_dependency_flag"
MKDEP='${srcdir}/mkdep'
MKDEP='${top_srcdir}/mkdep'
else
AC_MSG_RESULT([no])
#
@ -451,8 +442,9 @@ AC_DEFUN(AC_LBL_C_INLINE,
dnl
dnl Use pfopen.c if available and pfopen() not in standard libraries
dnl Require libpcap
dnl Look for libpcap in ..
dnl Use the installed libpcap if there is no local version
dnl Look for libpcap in directories under ..; those are local versions.
dnl Look for an installed libpcap if there is no local version or if
dnl the user said not to look for a local version.
dnl
dnl usage:
dnl
@ -473,176 +465,274 @@ AC_DEFUN(AC_LBL_LIBPCAP,
LBL_LIBS="$LIBS"
pfopen=/usr/examples/packetfilter/pfopen.c
if test -f $pfopen ; then
AC_CHECK_FUNCS(pfopen)
if test $ac_cv_func_pfopen = "no" ; then
AC_MSG_RESULT(Using $pfopen)
LIBS="$LIBS $pfopen"
fi
AC_CHECK_FUNCS(pfopen)
if test $ac_cv_func_pfopen = "no" ; then
AC_MSG_RESULT(Using $pfopen)
LIBS="$LIBS $pfopen"
fi
fi
libpcap=FAIL
AC_MSG_CHECKING(for local pcap library)
AC_ARG_WITH([system-libpcap],
[AS_HELP_STRING([--with-system-libpcap], [don't use local pcap library])])
if test "x$with_system_libpcap" != xyes ; then
lastdir=FAIL
places=`ls $srcdir/.. | sed -e 's,/$,,' -e "s,^,$srcdir/../," | \
egrep '/libpcap-[[0-9]]+\.[[0-9]]+(\.[[0-9]]*)?([[ab]][[0-9]]*|-PRE-GIT)?$'`
places2=`ls .. | sed -e 's,/$,,' -e "s,^,../," | \
egrep '/libpcap-[[0-9]]+\.[[0-9]]+(\.[[0-9]]*)?([[ab]][[0-9]]*|-PRE-GIT)?$'`
for dir in $places $srcdir/../libpcap ../libpcap $srcdir/libpcap $places2 ; do
basedir=`echo $dir | sed -e 's/[[ab]][[0-9]]*$//' | \
sed -e 's/-PRE-GIT$//' `
if test $lastdir = $basedir ; then
dnl skip alphas when an actual release is present
continue;
fi
lastdir=$dir
if test -r $dir/libpcap.a ; then
libpcap=$dir/libpcap.a
d=$dir
dnl continue and select the last one that exists
fi
done
fi
if test $libpcap = FAIL ; then
AC_MSG_RESULT(not found)
libpcap=FAIL
AC_ARG_WITH([system-libpcap],
[AS_HELP_STRING([--with-system-libpcap], [don't use local pcap library])],
[
#
# Don't look for a local libpcap.
#
using_local_libpcap=no
],
[
#
# Look for a local pcap library.
#
AC_MSG_CHECKING(for local pcap library)
lastdir=FAIL
places=`ls $srcdir/.. | sed -e 's,/$,,' -e "s,^,$srcdir/../," | \
egrep '/libpcap-[[0-9]]+\.[[0-9]]+(\.[[0-9]]*)?([[ab]][[0-9]]*|-PRE-GIT)?$'`
places2=`ls .. | sed -e 's,/$,,' -e "s,^,../," | \
egrep '/libpcap-[[0-9]]+\.[[0-9]]+(\.[[0-9]]*)?([[ab]][[0-9]]*|-PRE-GIT)?$'`
for dir in $places $srcdir/../libpcap ../libpcap $srcdir/libpcap $places2 ; do
basedir=`echo $dir | sed -e 's/[[ab]][[0-9]]*$//' | \
sed -e 's/-PRE-GIT$//' `
if test $lastdir = $basedir ; then
dnl skip alphas when an actual release is present
continue;
fi
lastdir=$dir
if test -r $dir/libpcap.a ; then
libpcap=$dir/libpcap.a
local_pcap_dir=$dir
dnl continue and select the last one that exists
fi
done
if test $libpcap = FAIL ; then
#
# We didn't find a local libpcap.
#
AC_MSG_RESULT(not found)
using_local_libpcap=no;
else
#
# We found a local libpcap.
#
AC_MSG_RESULT($libpcap)
using_local_libpcap=yes
fi
])
#
# Look for pcap-config.
#
AC_PATH_TOOL(PCAP_CONFIG, pcap-config)
if test -n "$PCAP_CONFIG" ; then
#
# Found - use it to get the include flags for
# libpcap and the flags to link with libpcap.
#
# Please read section 11.6 "Shell Substitutions"
# in the autoconf manual before doing anything
# to this that involves quoting. Especially note
# the statement "There is just no portable way to use
# double-quoted strings inside double-quoted back-quoted
# expressions (pfew!)."
#
cflags=`"$PCAP_CONFIG" --cflags`
$2="$cflags $$2"
libpcap=`"$PCAP_CONFIG" --libs`
else
#
# Not found; look for pcap.
#
AC_CHECK_LIB(pcap, main, libpcap="-lpcap")
if test $libpcap = FAIL ; then
AC_MSG_ERROR(see the INSTALL doc for more info)
fi
dnl
dnl Some versions of Red Hat Linux put "pcap.h" in
dnl "/usr/include/pcap"; had the LBL folks done so,
dnl that would have been a good idea, but for
dnl the Red Hat folks to do so just breaks source
dnl compatibility with other systems.
dnl
dnl We work around this by assuming that, as we didn't
dnl find a local libpcap, libpcap is in /usr/lib or
dnl /usr/local/lib and that the corresponding header
dnl file is under one of those directories; if we don't
dnl find it in either of those directories, we check to
dnl see if it's in a "pcap" subdirectory of them and,
dnl if so, add that subdirectory to the "-I" list.
dnl
dnl (We now also put pcap.h in /usr/include/pcap, but we
dnl leave behind a /usr/include/pcap.h that includes it,
dnl so you can still just include <pcap.h>.)
dnl
AC_MSG_CHECKING(for extraneous pcap header directories)
if test \( ! -r /usr/local/include/pcap.h \) -a \
\( ! -r /usr/include/pcap.h \); then
if test -r /usr/local/include/pcap/pcap.h; then
d="/usr/local/include/pcap"
elif test -r /usr/include/pcap/pcap.h; then
d="/usr/include/pcap"
fi
fi
if test -z "$d" ; then
AC_MSG_RESULT(not found)
else
$2="-I$d $$2"
AC_MSG_RESULT(found -- -I$d added)
fi
fi
if test $using_local_libpcap = no ; then
#
# We didn't find a local libpcap.
# Look for an installed pkg-config.
#
AC_PATH_TOOL(PKG_CONFIG, pkg-config)
if test -n "$PKG_CONFIG" ; then
#
# We have it. Are there .pc files for libpcap?
#
# --exists was introduced in pkg-config 0.4.0; that
# dates back to late 2000, so we won't worry about
# earlier releases that lack it.
#
AC_MSG_CHECKING(whether there are .pc files for libpcap)
if "$PKG_CONFIG" libpcap --exists ; then
#
# Yes, so we can use pkg-config to get configuration
# information for libpcap.
#
AC_MSG_RESULT(yes)
pkg_config_usable=yes
else
#
# No, so we can't use pkg-config to get configuration
# information for libpcap.
#
AC_MSG_RESULT(no)
pkg_config_usable=no
fi
else
#
# We don't have it, so we obviously can't use it.
#
pkg_config_usable=no
fi
if test "$pkg_config_usable" = "yes" ; then
#
# Found both - use pkg-config to get the include flags for
# libpcap and the flags to link with libpcap.
#
# Please read section 11.6 "Shell Substitutions"
# in the autoconf manual before doing anything
# to this that involves quoting. Especially note
# the statement "There is just no portable way to use
# double-quoted strings inside double-quoted back-quoted
# expressions (pfew!)."
#
cflags=`"$PKG_CONFIG" libpcap --cflags`
$2="$cflags $$2"
libpcap=`"$PKG_CONFIG" libpcap --libs`
else
#
# No pkg-config
# Look for an installed pcap-config.
#
AC_PATH_TOOL(PCAP_CONFIG, pcap-config)
if test -n "$PCAP_CONFIG" ; then
#
# Found - use it to get the include flags for
# libpcap and the flags to link with libpcap.
#
# Please read section 11.6 "Shell Substitutions"
# in the autoconf manual before doing anything
# to this that involves quoting. Especially note
# the statement "There is just no portable way to use
# double-quoted strings inside double-quoted back-quoted
# expressions (pfew!)."
#
cflags=`"$PCAP_CONFIG" --cflags`
$2="$cflags $$2"
libpcap=`"$PCAP_CONFIG" --libs`
else
#
# Not found; look for an installed pcap.
#
AC_CHECK_LIB(pcap, main, libpcap="-lpcap")
if test $libpcap = FAIL ; then
AC_MSG_ERROR(see the INSTALL doc for more info)
fi
dnl
dnl Some versions of Red Hat Linux put "pcap.h" in
dnl "/usr/include/pcap"; had the LBL folks done so,
dnl that would have been a good idea, but for
dnl the Red Hat folks to do so just breaks source
dnl compatibility with other systems.
dnl
dnl We work around this by assuming that, as we didn't
dnl find a local libpcap, libpcap is in /usr/lib or
dnl /usr/local/lib and that the corresponding header
dnl file is under one of those directories; if we don't
dnl find it in either of those directories, we check to
dnl see if it's in a "pcap" subdirectory of them and,
dnl if so, add that subdirectory to the "-I" list.
dnl
dnl (We now also put pcap.h in /usr/include/pcap, but we
dnl leave behind a /usr/include/pcap.h that includes it,
dnl so you can still just include <pcap.h>.)
dnl
AC_MSG_CHECKING(for extraneous pcap header directories)
if test \( ! -r /usr/local/include/pcap.h \) -a \
\( ! -r /usr/include/pcap.h \); then
if test -r /usr/local/include/pcap/pcap.h; then
d="/usr/local/include/pcap"
elif test -r /usr/include/pcap/pcap.h; then
d="/usr/include/pcap"
fi
fi
if test -z "$d" ; then
AC_MSG_RESULT(not found)
else
$2="-I$d $$2"
AC_MSG_RESULT(found -- -I$d added)
fi
fi
fi
else
$1=$libpcap
places=`ls $srcdir/.. | sed -e 's,/$,,' -e "s,^,$srcdir/../," | \
egrep '/libpcap-[[0-9]]*.[[0-9]]*(.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
places2=`ls .. | sed -e 's,/$,,' -e "s,^,../," | \
egrep '/libpcap-[[0-9]]*.[[0-9]]*(.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
#
# We found a local libpcap. Add it to the dependencies for
# tcpdump.
#
$1=$libpcap
#
# Look for its pcap-config script.
#
AC_PATH_PROG(PCAP_CONFIG, pcap-config,, $local_pcap_dir)
if test -n "$PCAP_CONFIG"; then
#
# We don't want its --cflags or --libs output, because
# those presume it's installed. For the C compiler flags,
# we add the source directory for the local libpcap, so
# we pick up its header files.
#
# We do, however, want its additional libraries, as required
# when linking statically, because it makes calls to
# routines in those libraries, so we'll need to link with
# them, because we'll be linking statically with it.
#
$2="-I$local_pcap_dir $$2"
additional_libs=`"$PCAP_CONFIG" --static --additional-libs`
libpcap="$libpcap $additional_libs"
else
#
# It doesn't have a pcap-config script.
# Make sure it has a pcap.h file.
#
places=`ls $srcdir/.. | sed -e 's,/$,,' -e "s,^,$srcdir/../," | \
egrep '/libpcap-[[0-9]]*.[[0-9]]*(.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
places2=`ls .. | sed -e 's,/$,,' -e "s,^,../," | \
egrep '/libpcap-[[0-9]]*.[[0-9]]*(.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
pcapH=FAIL
if test -r $d/pcap.h; then
pcapH=$d
else
if test -r $local_pcap_dir/pcap.h; then
pcapH=$local_pcap_dir
else
for dir in $places $srcdir/../libpcap ../libpcap $srcdir/libpcap $places2 ; do
if test -r $dir/pcap.h ; then
pcapH=$dir
fi
if test -r $dir/pcap.h ; then
pcapH=$dir
fi
done
fi
if test $pcapH = FAIL ; then
AC_MSG_ERROR(cannot find pcap.h: see INSTALL)
fi
AC_MSG_ERROR(cannot find pcap.h: see INSTALL)
fi
#
# Force the compiler to look for header files in the
# directory containing pcap.h.
#
$2="-I$pcapH $$2"
AC_MSG_RESULT($libpcap)
AC_PATH_PROG(PCAP_CONFIG, pcap-config,, $d)
if test -n "$PCAP_CONFIG"; then
#
# The libpcap directory has a pcap-config script.
# Use it to get any additioal libraries needed
# to link with the libpcap archive library in
# that directory.
#
# Please read section 11.6 "Shell Substitutions"
# in the autoconf manual before doing anything
# to this that involves quoting. Especially note
# the statement "There is just no portable way to use
# double-quoted strings inside double-quoted back-quoted
# expressions (pfew!)."
#
additional_libs=`"$PCAP_CONFIG" --additional-libs --static`
libpcap="$libpcap $additional_libs"
fi
fi
fi
if test -z "$PKG_CONFIG" -a -z "$PCAP_CONFIG"; then
#
# We don't have pkg-config or pcap-config; find out any additional
# link flags we need. (If we have pkg-config or pcap-config, we
# assume it tells us what we need.)
#
case "$host_os" in
aix*)
#
# If libpcap is DLPI-based, we have to use /lib/pse.exp if
# present, as we use the STREAMS routines.
#
# (XXX - true only if we're linking with a static libpcap?)
#
pseexe="/lib/pse.exp"
AC_MSG_CHECKING(for $pseexe)
if test -f $pseexe ; then
AC_MSG_RESULT(yes)
LIBS="$LIBS -I:$pseexe"
fi
#
# If libpcap is BPF-based, we need "-lodm" and "-lcfg", as
# we use them to load the BPF module.
#
# (XXX - true only if we're linking with a static libpcap?)
#
LIBS="$LIBS -lodm -lcfg"
;;
solaris*)
# libdlpi is needed for Solaris 11 and later.
AC_CHECK_LIB(dlpi, dlpi_walk, LIBS="$LIBS -ldlpi" LDFLAGS="-L/lib $LDFLAGS", ,-L/lib)
;;
esac
fi
LIBS="$libpcap $LIBS"
if ! test -n "$PCAP_CONFIG" ; then
#
# We don't have pcap-config; find out any additional link flags
# we need. (If we have pcap-config, we assume it tells us what
# we need.)
#
case "$host_os" in
aix*)
#
# If libpcap is DLPI-based, we have to use /lib/pse.exp if
# present, as we use the STREAMS routines.
#
# (XXX - true only if we're linking with a static libpcap?)
#
pseexe="/lib/pse.exp"
AC_MSG_CHECKING(for $pseexe)
if test -f $pseexe ; then
AC_MSG_RESULT(yes)
LIBS="$LIBS -I:$pseexe"
fi
#
# If libpcap is BPF-based, we need "-lodm" and "-lcfg", as
# we use them to load the BPF module.
#
# (XXX - true only if we're linking with a static libpcap?)
#
LIBS="$LIBS -lodm -lcfg"
;;
esac
fi
dnl
dnl Check for "pcap_loop()", to make sure we found a working
@ -653,8 +743,8 @@ AC_DEFUN(AC_LBL_LIBPCAP,
dnl that will cause confusing errors at build time.)
dnl
AC_CHECK_FUNC(pcap_loop,,
[
AC_MSG_ERROR(
[
AC_MSG_ERROR(
[This is a bug, please follow the guidelines in CONTRIBUTING and include the
config.log file in your report. If you have downloaded libpcap from
tcpdump.org, and built it yourself, please also include the config.log
@ -664,44 +754,9 @@ this could be a problem with the libpcap that was built, and we will
not be able to determine why this is happening, and thus will not be
able to fix it, without that information, as we have not been able to
reproduce this problem ourselves.])
])
])
])
dnl
dnl Define RETSIGTYPE and RETSIGVAL
dnl
dnl usage:
dnl
dnl AC_LBL_TYPE_SIGNAL
dnl
dnl results:
dnl
dnl RETSIGTYPE (defined)
dnl RETSIGVAL (defined)
dnl
AC_DEFUN(AC_LBL_TYPE_SIGNAL,
[AC_BEFORE([$0], [AC_LBL_LIBPCAP])
AC_TYPE_SIGNAL
if test "$ac_cv_type_signal" = void ; then
AC_DEFINE(RETSIGVAL,[],[return value of signal handlers])
else
AC_DEFINE(RETSIGVAL,(0),[return value of signal handlers])
fi
case "$host_os" in
irix*)
AC_DEFINE(_BSD_SIGNALS,1,[get BSD semantics on Irix])
;;
*)
dnl prefer sigaction() to sigset()
AC_CHECK_FUNCS(sigaction)
if test $ac_cv_func_sigaction = no ; then
AC_CHECK_FUNCS(sigset)
fi
;;
esac])
dnl
dnl If using gcc, make sure we have ANSI ioctl definitions
dnl
@ -767,31 +822,6 @@ AC_DEFUN(AC_LBL_UNION_WAIT,
AC_DEFINE(DECLWAITSTATUS,int,[type for wait])
fi])
dnl
dnl Checks to see if the sockaddr struct has the 4.4 BSD sa_len member
dnl
dnl usage:
dnl
dnl AC_LBL_SOCKADDR_SA_LEN
dnl
dnl results:
dnl
dnl HAVE_SOCKADDR_SA_LEN (defined)
dnl
AC_DEFUN(AC_LBL_SOCKADDR_SA_LEN,
[AC_MSG_CHECKING(if sockaddr struct has the sa_len member)
AC_CACHE_VAL(ac_cv_lbl_sockaddr_has_sa_len,
AC_TRY_COMPILE([
# include <sys/types.h>
# include <sys/socket.h>],
[u_int i = sizeof(((struct sockaddr *)0)->sa_len)],
ac_cv_lbl_sockaddr_has_sa_len=yes,
ac_cv_lbl_sockaddr_has_sa_len=no))
AC_MSG_RESULT($ac_cv_lbl_sockaddr_has_sa_len)
if test $ac_cv_lbl_sockaddr_has_sa_len = yes ; then
AC_DEFINE(HAVE_SOCKADDR_SA_LEN,1,[if struct sockaddr has the sa_len member])
fi])
dnl
dnl Checks to see if -R is used
dnl
@ -858,106 +888,6 @@ AC_DEFUN(AC_LBL_CHECK_64BIT_FORMAT,
])
])
dnl
dnl Checks to see if unaligned memory accesses fail
dnl
dnl usage:
dnl
dnl AC_LBL_UNALIGNED_ACCESS
dnl
dnl results:
dnl
dnl LBL_ALIGN (DEFINED)
dnl
AC_DEFUN(AC_LBL_UNALIGNED_ACCESS,
[AC_MSG_CHECKING(if unaligned accesses fail)
AC_CACHE_VAL(ac_cv_lbl_unaligned_fail,
[case "$host_cpu" in
#
# These are CPU types where:
#
# the CPU faults on an unaligned access, but at least some
# OSes that support that CPU catch the fault and simulate
# the unaligned access (e.g., Alpha/{Digital,Tru64} UNIX) -
# the simulation is slow, so we don't want to use it;
#
# the CPU, I infer (from the old
#
# XXX: should also check that they don't do weird things (like on arm)
#
# comment) doesn't fault on unaligned accesses, but doesn't
# do a normal unaligned fetch, either (e.g., presumably, ARM);
#
# for whatever reason, the test program doesn't work
# (this has been claimed to be the case for several of those
# CPUs - I don't know what the problem is; the problem
# was reported as "the test program dumps core" for SuperH,
# but that's what the test program is *supposed* to do -
# it dumps core before it writes anything, so the test
# for an empty output file should find an empty output
# file and conclude that unaligned accesses don't work).
#
# This run-time test won't work if you're cross-compiling, so
# in order to support cross-compiling for a particular CPU,
# we have to wire in the list of CPU types anyway, as far as
# I know, so perhaps we should just have a set of CPUs on
# which we know it doesn't work, a set of CPUs on which we
# know it does work, and have the script just fail on other
# cpu types and update it when such a failure occurs.
#
alpha*|arm*|bfin*|hp*|mips*|sh*|sparc*|ia64|nv1)
ac_cv_lbl_unaligned_fail=yes
;;
*)
cat >conftest.c <<EOF
# include <sys/types.h>
# include <sys/wait.h>
# include <stdio.h>
unsigned char a[[5]] = { 1, 2, 3, 4, 5 };
main() {
unsigned int i;
pid_t pid;
int status;
/* avoid "core dumped" message */
pid = fork();
if (pid < 0)
exit(2);
if (pid > 0) {
/* parent */
pid = waitpid(pid, &status, 0);
if (pid < 0)
exit(3);
exit(!WIFEXITED(status));
}
/* child */
i = *(unsigned int *)&a[[1]];
printf("%d\n", i);
exit(0);
}
EOF
${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \
conftest.c $LIBS >/dev/null 2>&1
if test ! -x conftest ; then
dnl failed to compile for some reason
ac_cv_lbl_unaligned_fail=yes
else
./conftest >conftest.out
if test ! -s conftest.out ; then
ac_cv_lbl_unaligned_fail=yes
else
ac_cv_lbl_unaligned_fail=no
fi
fi
rm -f -r conftest* core core.conftest
;;
esac])
AC_MSG_RESULT($ac_cv_lbl_unaligned_fail)
if test $ac_cv_lbl_unaligned_fail = yes ; then
AC_DEFINE(LBL_ALIGN,1,[if unaligned access fails])
fi])
dnl
dnl If the file .devel exists:
dnl Add some warning flags if the compiler supports them
@ -984,18 +914,21 @@ AC_DEFUN(AC_LBL_DEVEL,
#
if test "$ac_lbl_cc_dont_try_gcc_dashW" != yes; then
AC_LBL_CHECK_UNKNOWN_WARNING_OPTION_ERROR()
AC_LBL_CHECK_COMPILER_OPT($1, -Wall)
AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes)
AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes)
AC_LBL_CHECK_COMPILER_OPT($1, -Wwrite-strings)
AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-arith)
AC_LBL_CHECK_COMPILER_OPT($1, -Wcast-qual)
AC_LBL_CHECK_COMPILER_OPT($1, -Wshadow)
AC_LBL_CHECK_COMPILER_OPT($1, -Wdeclaration-after-statement)
AC_LBL_CHECK_COMPILER_OPT($1, -Wpedantic)
AC_LBL_CHECK_COMPILER_OPT($1, -Wold-style-definition)
AC_LBL_CHECK_COMPILER_OPT($1, -Wused-but-marked-unused)
AC_LBL_CHECK_COMPILER_OPT($1, -W)
AC_LBL_CHECK_COMPILER_OPT($1, -Wall)
AC_LBL_CHECK_COMPILER_OPT($1, -Wassign-enum)
AC_LBL_CHECK_COMPILER_OPT($1, -Wcast-qual)
AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes)
AC_LBL_CHECK_COMPILER_OPT($1, -Wold-style-definition)
AC_LBL_CHECK_COMPILER_OPT($1, -Wpedantic)
AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-arith)
AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-sign)
AC_LBL_CHECK_COMPILER_OPT($1, -Wshadow)
AC_LBL_CHECK_COMPILER_OPT($1, -Wsign-compare)
AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes)
AC_LBL_CHECK_COMPILER_OPT($1, -Wunreachable-code-return)
AC_LBL_CHECK_COMPILER_OPT($1, -Wused-but-marked-unused)
AC_LBL_CHECK_COMPILER_OPT($1, -Wwrite-strings)
fi
AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT()
#
@ -1102,11 +1035,11 @@ dnl This test exists so that every application developer does not test
dnl this in a different, and subtly broken fashion.
dnl It has been argued that this test should be broken up into two
dnl seperate tests, one for the resolver libraries, and one for the
dnl separate tests, one for the resolver libraries, and one for the
dnl libraries necessary for using Sockets API. Unfortunately, the two
dnl are carefully intertwined and allowing the autoconf user to use
dnl them independantly potentially results in unfortunate ordering
dnl dependancies -- as such, such component macros would have to
dnl them independently potentially results in unfortunate ordering
dnl dependencies -- as such, such component macros would have to
dnl carefully use indirection and be aware if the other components were
dnl executed. Since other autoconf macros do not go to this trouble,
dnl and almost no applications use sockets without the resolver, this
@ -1161,168 +1094,6 @@ dnl LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
dnl OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
dnl SUCH DAMAGE.
dnl
dnl Test for __attribute__
dnl
AC_DEFUN(AC_C___ATTRIBUTE__, [
AC_MSG_CHECKING(for __attribute__)
AC_CACHE_VAL(ac_cv___attribute__, [
AC_COMPILE_IFELSE([
AC_LANG_SOURCE([[
#include <stdlib.h>
static void foo(void) __attribute__ ((noreturn));
static void
foo(void)
{
exit(1);
}
int
main(int argc, char **argv)
{
foo();
}
]])],
ac_cv___attribute__=yes,
ac_cv___attribute__=no)])
if test "$ac_cv___attribute__" = "yes"; then
AC_DEFINE(HAVE___ATTRIBUTE__, 1, [define if your compiler has __attribute__])
else
#
# We can't use __attribute__, so we can't use __attribute__((unused)),
# so we define _U_ to an empty string.
#
V_DEFS="$V_DEFS -D_U_=\"\""
fi
AC_MSG_RESULT($ac_cv___attribute__)
])
dnl
dnl Test whether __attribute__((unused)) can be used without warnings
dnl
AC_DEFUN(AC_C___ATTRIBUTE___UNUSED, [
AC_MSG_CHECKING([whether __attribute__((unused)) can be used without warnings])
AC_CACHE_VAL(ac_cv___attribute___unused, [
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
AC_COMPILE_IFELSE([
AC_LANG_SOURCE([[
#include <stdlib.h>
#include <stdio.h>
int
main(int argc __attribute((unused)), char **argv __attribute((unused)))
{
printf("Hello, world!\n");
return 0;
}
]])],
ac_cv___attribute___unused=yes,
ac_cv___attribute___unused=no)])
CFLAGS="$save_CFLAGS"
if test "$ac_cv___attribute___unused" = "yes"; then
V_DEFS="$V_DEFS -D_U_=\"__attribute__((unused))\""
else
V_DEFS="$V_DEFS -D_U_=\"\""
fi
AC_MSG_RESULT($ac_cv___attribute___unused)
])
dnl
dnl Test whether __attribute__((format)) can be used without warnings
dnl
AC_DEFUN(AC_C___ATTRIBUTE___FORMAT, [
AC_MSG_CHECKING([whether __attribute__((format)) can be used without warnings])
AC_CACHE_VAL(ac_cv___attribute___format, [
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
AC_COMPILE_IFELSE([
AC_LANG_SOURCE([[
#include <stdlib.h>
extern int foo(const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
int
main(int argc, char **argv)
{
foo("%s", "test");
}
]])],
ac_cv___attribute___format=yes,
ac_cv___attribute___format=no)])
CFLAGS="$save_CFLAGS"
if test "$ac_cv___attribute___format" = "yes"; then
AC_DEFINE(__ATTRIBUTE___FORMAT_OK, 1,
[define if your compiler allows __attribute__((format)) without a warning])
fi
AC_MSG_RESULT($ac_cv___attribute___format)
])
dnl
dnl Test whether __attribute__((format)) can be applied to function
dnl pointers
dnl
AC_DEFUN(AC_C___ATTRIBUTE___FORMAT_FUNCTION_POINTER, [
AC_MSG_CHECKING([whether __attribute__((format)) can be applied to function pointers])
AC_CACHE_VAL(ac_cv___attribute___format_function_pointer, [
AC_COMPILE_IFELSE([
AC_LANG_SOURCE([[
#include <stdlib.h>
extern int (*foo)(const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
int
main(int argc, char **argv)
{
(*foo)("%s", "test");
}
]])],
ac_cv___attribute___format_function_pointer=yes,
ac_cv___attribute___format_function_pointer=no)])
if test "$ac_cv___attribute___format_function_pointer" = "yes"; then
AC_DEFINE(__ATTRIBUTE___FORMAT_OK_FOR_FUNCTION_POINTERS, 1,
[define if your compiler allows __attribute__((format)) to be applied to function pointers])
fi
AC_MSG_RESULT($ac_cv___attribute___format_function_pointer)
])
AC_DEFUN(AC_C___ATTRIBUTE___NORETURN_FUNCTION_POINTER, [
AC_MSG_CHECKING([whether __attribute__((noreturn)) can be applied to function pointers without warnings])
AC_CACHE_VAL(ac_cv___attribute___noreturn_function_pointer, [
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
AC_COMPILE_IFELSE([
AC_LANG_SOURCE([[
#include <stdlib.h>
extern int (*foo)(int i)
__attribute__ ((noreturn));
int
main(int argc, char **argv)
{
(*foo)(1);
}
]])],
ac_cv___attribute___noreturn_function_pointer=yes,
ac_cv___attribute___noreturn_function_pointer=no)])
CFLAGS="$save_CFLAGS"
if test "$ac_cv___attribute___noreturn_function_pointer" = "yes"; then
AC_DEFINE(__ATTRIBUTE___NORETURN_OK_FOR_FUNCTION_POINTERS, 1,
[define if your compiler allows __attribute__((noreturn)) to be applied to function pointers])
fi
AC_MSG_RESULT($ac_cv___attribute___noreturn_function_pointer)
])
AC_DEFUN(AC_LBL_SSLEAY,
[
#
@ -1346,9 +1117,9 @@ AC_DEFUN(AC_LBL_SSLEAY,
# Or should we just look for "libcrypto.*"?
#
if test -d "$1/$tmplib" -a \( -f "$1/$tmplib/libcrypto.a" -o \
-f "$1/$tmplib/libcrypto.so" -o \
-f "$1/$tmplib/libcrypto.sl" -o \
-f "$1/$tmplib/libcrypto.dylib" \); then
-f "$1/$tmplib/libcrypto.so" -o \
-f "$1/$tmplib/libcrypto.sl" -o \
-f "$1/$tmplib/libcrypto.dylib" \); then
ac_cv_ssleay_path="$1"
fi

View File

@ -23,7 +23,7 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#ifdef HAVE_CASPER
@ -31,32 +31,84 @@
#include <casper/cap_dns.h>
#endif /* HAVE_CASPER */
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#ifdef USE_ETHER_NTOHOST
#ifdef HAVE_NETINET_IF_ETHER_H
struct mbuf; /* Squelch compiler warnings on some platforms for */
struct rtentry; /* declarations in <net/if.h> */
#include <net/if.h> /* for "struct ifnet" in "struct arpcom" on Solaris */
#include <netinet/if_ether.h>
#endif /* HAVE_NETINET_IF_ETHER_H */
#ifdef NETINET_ETHER_H_DECLARES_ETHER_NTOHOST
#include <netinet/ether.h>
#endif /* NETINET_ETHER_H_DECLARES_ETHER_NTOHOST */
#if !defined(HAVE_DECL_ETHER_NTOHOST) || !HAVE_DECL_ETHER_NTOHOST
#ifndef HAVE_STRUCT_ETHER_ADDR
struct ether_addr {
unsigned char ether_addr_octet[6];
};
#endif
extern int ether_ntohost(char *, const struct ether_addr *);
#ifndef NTOHL
#define NTOHL(x) (x) = ntohl(x)
#define NTOHS(x) (x) = ntohs(x)
#define HTONL(x) (x) = htonl(x)
#define HTONS(x) (x) = htons(x)
#endif
#endif /* USE_ETHER_NTOHOST */
#ifdef _WIN32
/*
* We have our own ether_ntohost(), reading from the system's
* Ethernet address file.
*/
#include "missing/win_ether_ntohost.h"
#else
#ifdef USE_ETHER_NTOHOST
#if defined(NET_ETHERNET_H_DECLARES_ETHER_NTOHOST)
/*
* OK, just include <net/ethernet.h>.
*/
#include <net/ethernet.h>
#elif defined(NETINET_ETHER_H_DECLARES_ETHER_NTOHOST)
/*
* OK, just include <netinet/ether.h>
*/
#include <netinet/ether.h>
#elif defined(SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST)
/*
* OK, just include <sys/ethernet.h>
*/
#include <sys/ethernet.h>
#elif defined(ARPA_INET_H_DECLARES_ETHER_NTOHOST)
/*
* OK, just include <arpa/inet.h>
*/
#include <arpa/inet.h>
#elif defined(NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST)
/*
* OK, include <netinet/if_ether.h>, after all the other stuff we
* need to include or define for its benefit.
*/
#define NEED_NETINET_IF_ETHER_H
#else
/*
* We'll have to declare it ourselves.
* If <netinet/if_ether.h> defines struct ether_addr, include
* it. Otherwise, define it ourselves.
*/
#ifdef HAVE_STRUCT_ETHER_ADDR
#define NEED_NETINET_IF_ETHER_H
#else /* HAVE_STRUCT_ETHER_ADDR */
struct ether_addr {
unsigned char ether_addr_octet[6];
};
#endif /* HAVE_STRUCT_ETHER_ADDR */
#endif /* what declares ether_ntohost() */
#ifdef NEED_NETINET_IF_ETHER_H
#include <net/if.h> /* Needed on some platforms */
#include <netinet/in.h> /* Needed on some platforms */
#include <netinet/if_ether.h>
#endif /* NEED_NETINET_IF_ETHER_H */
#ifndef HAVE_DECL_ETHER_NTOHOST
/*
* No header declares it, so declare it ourselves.
*/
extern int ether_ntohost(char *, const struct ether_addr *);
#endif /* !defined(HAVE_DECL_ETHER_NTOHOST) */
#endif /* USE_ETHER_NTOHOST */
#endif /* _WIN32 */
#include <pcap.h>
#include <pcap-namedb.h>
#ifndef HAVE_GETSERVENT
#include <getservent.h>
#endif
#include <signal.h>
#include <stdio.h>
#include <string.h>
@ -67,18 +119,13 @@ extern int ether_ntohost(char *, const struct ether_addr *);
#include "addrtostr.h"
#include "ethertype.h"
#include "llc.h"
#include "setsignal.h"
#include "extract.h"
#include "oui.h"
#ifndef ETHER_ADDR_LEN
#define ETHER_ADDR_LEN 6
#endif
/*
* hash tables for whatever-to-name translations
*
* ndo_error() called on strdup(3) failure
* ndo_error() called on strdup(3) failure with S_ERR_ND_MEM_ALLOC status
*/
#define HASHNAMESIZE 4096
@ -125,7 +172,7 @@ win32_gethostbyaddr(const char *addr, int len, int type)
hname, sizeof(hname), NULL, 0, 0)) {
return NULL;
} else {
strcpy(host.h_name, hname);
strlcpy(host.h_name, hname, NI_MAXHOST);
return &host;
}
break;
@ -137,7 +184,7 @@ win32_gethostbyaddr(const char *addr, int len, int type)
#endif /* _WIN32 */
struct h6namemem {
struct in6_addr addr;
nd_ipv6 addr;
char *name;
struct h6namemem *nxt;
};
@ -150,13 +197,23 @@ struct enamemem {
u_short e_addr2;
const char *e_name;
u_char *e_nsap; /* used only for nsaptable[] */
#define e_bs e_nsap /* for bytestringtable */
struct enamemem *e_nxt;
};
static struct enamemem enametable[HASHNAMESIZE];
static struct enamemem nsaptable[HASHNAMESIZE];
static struct enamemem bytestringtable[HASHNAMESIZE];
struct bsnamemem {
u_short bs_addr0;
u_short bs_addr1;
u_short bs_addr2;
const char *bs_name;
u_char *bs_bytes;
unsigned int bs_nbytes;
struct bsnamemem *bs_nxt;
};
static struct bsnamemem bytestringtable[HASHNAMESIZE];
struct protoidmem {
uint32_t p_oui;
@ -173,9 +230,9 @@ static struct protoidmem protoidtable[HASHNAMESIZE];
const char *
intoa(uint32_t addr)
{
register char *cp;
register u_int byte;
register int n;
char *cp;
u_int byte;
int n;
static char buf[sizeof(".xxx.xxx.xxx.xxx")];
NTOHL(addr);
@ -185,13 +242,13 @@ intoa(uint32_t addr)
n = 4;
do {
byte = addr & 0xff;
*--cp = byte % 10 + '0';
*--cp = (char)(byte % 10) + '0';
byte /= 10;
if (byte > 0) {
*--cp = byte % 10 + '0';
*--cp = (char)(byte % 10) + '0';
byte /= 10;
if (byte > 0)
*--cp = byte + '0';
*--cp = (char)byte + '0';
}
*--cp = '.';
addr >>= 8;
@ -212,7 +269,7 @@ extern cap_channel_t *capdns;
*
* NOTE: ap is *NOT* necessarily part of the packet data (not even if
* this is being called with the "ipaddr_string()" macro), so you
* *CANNOT* use the ND_TCHECK{2}/ND_TTEST{2} macros on it. Furthermore,
* *CANNOT* use the ND_TCHECK_* or ND_TTEST_* macros on it. Furthermore,
* even in cases where it *is* part of the packet data, the caller
* would still have to check for a null return value, even if it's
* just printing the return value with "%s" - not all versions of
@ -226,9 +283,9 @@ extern cap_channel_t *capdns;
* also needs to check whether they're present in the packet buffer.
*/
const char *
getname(netdissect_options *ndo, const u_char *ap)
ipaddr_string(netdissect_options *ndo, const u_char *ap)
{
register struct hostent *hp;
struct hostent *hp;
uint32_t addr;
struct hnamemem *p;
@ -262,8 +319,8 @@ getname(netdissect_options *ndo, const u_char *ap)
p->name = strdup(hp->h_name);
if (p->name == NULL)
(*ndo->ndo_error)(ndo,
"getname: strdup(hp->h_name)");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"ipaddr_string: strdup(hp->h_name)");
if (ndo->ndo_Nflag) {
/* Remove domain qualifications */
dotp = strchr(p->name, '.');
@ -275,7 +332,8 @@ getname(netdissect_options *ndo, const u_char *ap)
}
p->name = strdup(intoa(addr));
if (p->name == NULL)
(*ndo->ndo_error)(ndo, "getname: strdup(intoa(addr))");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"ipaddr_string: strdup(intoa(addr))");
return (p->name);
}
@ -284,18 +342,18 @@ getname(netdissect_options *ndo, const u_char *ap)
* is assumed to be in network byte order.
*/
const char *
getname6(netdissect_options *ndo, const u_char *ap)
ip6addr_string(netdissect_options *ndo, const u_char *ap)
{
register struct hostent *hp;
struct hostent *hp;
union {
struct in6_addr addr;
nd_ipv6 addr;
struct for_hash_addr {
char fill[14];
uint16_t d;
} addra;
} addr;
struct h6namemem *p;
register const char *cp;
const char *cp;
char ntop_buf[INET6_ADDRSTRLEN];
memcpy(&addr, ap, sizeof(addr));
@ -304,7 +362,7 @@ getname6(netdissect_options *ndo, const u_char *ap)
if (memcmp(&p->addr, &addr, sizeof(addr)) == 0)
return (p->name);
}
p->addr = addr.addr;
memcpy(p->addr, addr.addr, sizeof(nd_ipv6));
p->nxt = newh6namemem(ndo);
/*
@ -324,8 +382,8 @@ getname6(netdissect_options *ndo, const u_char *ap)
p->name = strdup(hp->h_name);
if (p->name == NULL)
(*ndo->ndo_error)(ndo,
"getname6: strdup(hp->h_name)");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"ip6addr_string: strdup(hp->h_name)");
if (ndo->ndo_Nflag) {
/* Remove domain qualifications */
dotp = strchr(p->name, '.');
@ -338,19 +396,54 @@ getname6(netdissect_options *ndo, const u_char *ap)
cp = addrtostr6(ap, ntop_buf, sizeof(ntop_buf));
p->name = strdup(cp);
if (p->name == NULL)
(*ndo->ndo_error)(ndo, "getname6: strdup(cp)");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"ip6addr_string: strdup(cp)");
return (p->name);
}
static const char hex[] = "0123456789abcdef";
static const char hex[16] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
/*
* Convert an octet to two hex digits.
*
* Coverity appears either:
*
* not to believe the C standard when it asserts that a uint8_t is
* exactly 8 bits in size;
*
* not to believe that an unsigned type of exactly 8 bits has a value
* in the range of 0 to 255;
*
* not to believe that, for a range of unsigned values, if you shift
* one of those values right by 4 bits, the maximum result value is
* the maximum value shifted right by 4 bits, with no stray 1's shifted
* in;
*
* not to believe that 255 >> 4 is 15;
*
* so it gets upset that we're taking a "tainted" unsigned value, shifting
* it right 4 bits, and using it as an index into a 16-element array.
*
* So we do a stupid pointless masking of the result of the shift with
* 0xf, to hammer the point home to Coverity.
*/
static inline char *
octet_to_hex(char *cp, uint8_t octet)
{
*cp++ = hex[(octet >> 4) & 0xf];
*cp++ = hex[(octet >> 0) & 0xf];
return (cp);
}
/* Find the hash node that corresponds the ether address 'ep' */
static inline struct enamemem *
static struct enamemem *
lookup_emem(netdissect_options *ndo, const u_char *ep)
{
register u_int i, j, k;
u_int i, j, k;
struct enamemem *tp;
k = (ep[0] << 8) | ep[1];
@ -365,12 +458,12 @@ lookup_emem(netdissect_options *ndo, const u_char *ep)
return tp;
else
tp = tp->e_nxt;
tp->e_addr0 = i;
tp->e_addr1 = j;
tp->e_addr2 = k;
tp->e_addr0 = (u_short)i;
tp->e_addr1 = (u_short)j;
tp->e_addr2 = (u_short)k;
tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp));
if (tp->e_nxt == NULL)
(*ndo->ndo_error)(ndo, "lookup_emem: calloc");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC, "lookup_emem: calloc");
return tp;
}
@ -380,12 +473,12 @@ lookup_emem(netdissect_options *ndo, const u_char *ep)
* with length 'nlen'
*/
static inline struct enamemem *
lookup_bytestring(netdissect_options *ndo, register const u_char *bs,
static struct bsnamemem *
lookup_bytestring(netdissect_options *ndo, const u_char *bs,
const unsigned int nlen)
{
struct enamemem *tp;
register u_int i, j, k;
struct bsnamemem *tp;
u_int i, j, k;
if (nlen >= 6) {
k = (bs[0] << 8) | bs[1];
@ -399,38 +492,42 @@ lookup_bytestring(netdissect_options *ndo, register const u_char *bs,
i = j = k = 0;
tp = &bytestringtable[(i ^ j) & (HASHNAMESIZE-1)];
while (tp->e_nxt)
if (tp->e_addr0 == i &&
tp->e_addr1 == j &&
tp->e_addr2 == k &&
memcmp((const char *)bs, (const char *)(tp->e_bs), nlen) == 0)
while (tp->bs_nxt)
if (nlen == tp->bs_nbytes &&
tp->bs_addr0 == i &&
tp->bs_addr1 == j &&
tp->bs_addr2 == k &&
memcmp((const char *)bs, (const char *)(tp->bs_bytes), nlen) == 0)
return tp;
else
tp = tp->e_nxt;
tp = tp->bs_nxt;
tp->e_addr0 = i;
tp->e_addr1 = j;
tp->e_addr2 = k;
tp->bs_addr0 = (u_short)i;
tp->bs_addr1 = (u_short)j;
tp->bs_addr2 = (u_short)k;
tp->e_bs = (u_char *) calloc(1, nlen + 1);
if (tp->e_bs == NULL)
(*ndo->ndo_error)(ndo, "lookup_bytestring: calloc");
tp->bs_bytes = (u_char *) calloc(1, nlen);
if (tp->bs_bytes == NULL)
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"lookup_bytestring: calloc");
memcpy(tp->e_bs, bs, nlen);
tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp));
if (tp->e_nxt == NULL)
(*ndo->ndo_error)(ndo, "lookup_bytestring: calloc");
memcpy(tp->bs_bytes, bs, nlen);
tp->bs_nbytes = nlen;
tp->bs_nxt = (struct bsnamemem *)calloc(1, sizeof(*tp));
if (tp->bs_nxt == NULL)
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"lookup_bytestring: calloc");
return tp;
}
/* Find the hash node that corresponds the NSAP 'nsap' */
static inline struct enamemem *
lookup_nsap(netdissect_options *ndo, register const u_char *nsap,
register u_int nsap_length)
static struct enamemem *
lookup_nsap(netdissect_options *ndo, const u_char *nsap,
u_int nsap_length)
{
register u_int i, j, k;
u_int i, j, k;
struct enamemem *tp;
const u_char *ensap;
@ -445,36 +542,36 @@ lookup_nsap(netdissect_options *ndo, register const u_char *nsap,
tp = &nsaptable[(i ^ j) & (HASHNAMESIZE-1)];
while (tp->e_nxt)
if (tp->e_addr0 == i &&
if (nsap_length == tp->e_nsap[0] &&
tp->e_addr0 == i &&
tp->e_addr1 == j &&
tp->e_addr2 == k &&
tp->e_nsap[0] == nsap_length &&
memcmp((const char *)&(nsap[1]),
memcmp((const char *)nsap,
(char *)&(tp->e_nsap[1]), nsap_length) == 0)
return tp;
else
tp = tp->e_nxt;
tp->e_addr0 = i;
tp->e_addr1 = j;
tp->e_addr2 = k;
tp->e_addr0 = (u_short)i;
tp->e_addr1 = (u_short)j;
tp->e_addr2 = (u_short)k;
tp->e_nsap = (u_char *)malloc(nsap_length + 1);
if (tp->e_nsap == NULL)
(*ndo->ndo_error)(ndo, "lookup_nsap: malloc");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC, "lookup_nsap: malloc");
tp->e_nsap[0] = (u_char)nsap_length; /* guaranteed < ISONSAP_MAX_LENGTH */
memcpy((char *)&tp->e_nsap[1], (const char *)nsap, nsap_length);
tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp));
if (tp->e_nxt == NULL)
(*ndo->ndo_error)(ndo, "lookup_nsap: calloc");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC, "lookup_nsap: calloc");
return tp;
}
/* Find the hash node that corresponds the protoid 'pi'. */
static inline struct protoidmem *
static struct protoidmem *
lookup_protoid(netdissect_options *ndo, const u_char *pi)
{
register u_int i, j;
u_int i, j;
struct protoidmem *tp;
/* 5 octets won't be aligned */
@ -489,20 +586,20 @@ lookup_protoid(netdissect_options *ndo, const u_char *pi)
else
tp = tp->p_nxt;
tp->p_oui = i;
tp->p_proto = j;
tp->p_proto = (u_short)j;
tp->p_nxt = (struct protoidmem *)calloc(1, sizeof(*tp));
if (tp->p_nxt == NULL)
(*ndo->ndo_error)(ndo, "lookup_protoid: calloc");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC, "lookup_protoid: calloc");
return tp;
}
const char *
etheraddr_string(netdissect_options *ndo, register const u_char *ep)
etheraddr_string(netdissect_options *ndo, const uint8_t *ep)
{
register int i;
register char *cp;
register struct enamemem *tp;
int i;
char *cp;
struct enamemem *tp;
int oui;
char buf[BUFSIZE];
@ -516,20 +613,18 @@ etheraddr_string(netdissect_options *ndo, register const u_char *ep)
if (ether_ntohost(buf2, (const struct ether_addr *)ep) == 0) {
tp->e_name = strdup(buf2);
if (tp->e_name == NULL)
(*ndo->ndo_error)(ndo,
"etheraddr_string: strdup(buf2)");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"etheraddr_string: strdup(buf2)");
return (tp->e_name);
}
}
#endif
cp = buf;
oui = EXTRACT_24BITS(ep);
*cp++ = hex[*ep >> 4 ];
*cp++ = hex[*ep++ & 0xf];
oui = EXTRACT_BE_U_3(ep);
cp = octet_to_hex(cp, *ep++);
for (i = 5; --i >= 0;) {
*cp++ = ':';
*cp++ = hex[*ep >> 4 ];
*cp++ = hex[*ep++ & 0xf];
cp = octet_to_hex(cp, *ep++);
}
if (!ndo->ndo_nflag) {
@ -539,140 +634,83 @@ etheraddr_string(netdissect_options *ndo, register const u_char *ep)
*cp = '\0';
tp->e_name = strdup(buf);
if (tp->e_name == NULL)
(*ndo->ndo_error)(ndo, "etheraddr_string: strdup(buf)");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"etheraddr_string: strdup(buf)");
return (tp->e_name);
}
const char *
le64addr_string(netdissect_options *ndo, const u_char *ep)
le64addr_string(netdissect_options *ndo, const uint8_t *ep)
{
const unsigned int len = 8;
register u_int i;
register char *cp;
register struct enamemem *tp;
u_int i;
char *cp;
struct bsnamemem *tp;
char buf[BUFSIZE];
tp = lookup_bytestring(ndo, ep, len);
if (tp->e_name)
return (tp->e_name);
if (tp->bs_name)
return (tp->bs_name);
cp = buf;
for (i = len; i > 0 ; --i) {
*cp++ = hex[*(ep + i - 1) >> 4];
*cp++ = hex[*(ep + i - 1) & 0xf];
cp = octet_to_hex(cp, *(ep + i - 1));
*cp++ = ':';
}
cp --;
*cp = '\0';
tp->e_name = strdup(buf);
if (tp->e_name == NULL)
(*ndo->ndo_error)(ndo, "le64addr_string: strdup(buf)");
tp->bs_name = strdup(buf);
if (tp->bs_name == NULL)
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"le64addr_string: strdup(buf)");
return (tp->e_name);
return (tp->bs_name);
}
const char *
linkaddr_string(netdissect_options *ndo, const u_char *ep,
linkaddr_string(netdissect_options *ndo, const uint8_t *ep,
const unsigned int type, const unsigned int len)
{
register u_int i;
register char *cp;
register struct enamemem *tp;
u_int i;
char *cp;
struct bsnamemem *tp;
if (len == 0)
return ("<empty>");
if (type == LINKADDR_ETHER && len == ETHER_ADDR_LEN)
if (type == LINKADDR_ETHER && len == MAC_ADDR_LEN)
return (etheraddr_string(ndo, ep));
if (type == LINKADDR_FRELAY)
return (q922_string(ndo, ep, len));
tp = lookup_bytestring(ndo, ep, len);
if (tp->e_name)
return (tp->e_name);
if (tp->bs_name)
return (tp->bs_name);
tp->e_name = cp = (char *)malloc(len*3);
if (tp->e_name == NULL)
(*ndo->ndo_error)(ndo, "linkaddr_string: malloc");
*cp++ = hex[*ep >> 4];
*cp++ = hex[*ep++ & 0xf];
tp->bs_name = cp = (char *)malloc(len*3);
if (tp->bs_name == NULL)
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"linkaddr_string: malloc");
cp = octet_to_hex(cp, *ep++);
for (i = len-1; i > 0 ; --i) {
*cp++ = ':';
*cp++ = hex[*ep >> 4];
*cp++ = hex[*ep++ & 0xf];
cp = octet_to_hex(cp, *ep++);
}
*cp = '\0';
return (tp->e_name);
}
const char *
etherproto_string(netdissect_options *ndo, u_short port)
{
register char *cp;
register struct hnamemem *tp;
register uint32_t i = port;
char buf[sizeof("0000")];
for (tp = &eprototable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
if (tp->addr == i)
return (tp->name);
tp->addr = i;
tp->nxt = newhnamemem(ndo);
cp = buf;
NTOHS(port);
*cp++ = hex[port >> 12 & 0xf];
*cp++ = hex[port >> 8 & 0xf];
*cp++ = hex[port >> 4 & 0xf];
*cp++ = hex[port & 0xf];
*cp++ = '\0';
tp->name = strdup(buf);
if (tp->name == NULL)
(*ndo->ndo_error)(ndo, "etherproto_string: strdup(buf)");
return (tp->name);
}
const char *
protoid_string(netdissect_options *ndo, register const u_char *pi)
{
register u_int i, j;
register char *cp;
register struct protoidmem *tp;
char buf[sizeof("00:00:00:00:00")];
tp = lookup_protoid(ndo, pi);
if (tp->p_name)
return tp->p_name;
cp = buf;
if ((j = *pi >> 4) != 0)
*cp++ = hex[j];
*cp++ = hex[*pi++ & 0xf];
for (i = 4; (int)--i >= 0;) {
*cp++ = ':';
if ((j = *pi >> 4) != 0)
*cp++ = hex[j];
*cp++ = hex[*pi++ & 0xf];
}
*cp = '\0';
tp->p_name = strdup(buf);
if (tp->p_name == NULL)
(*ndo->ndo_error)(ndo, "protoid_string: strdup(buf)");
return (tp->p_name);
return (tp->bs_name);
}
#define ISONSAP_MAX_LENGTH 20
const char *
isonsap_string(netdissect_options *ndo, const u_char *nsap,
register u_int nsap_length)
isonsap_string(netdissect_options *ndo, const uint8_t *nsap,
u_int nsap_length)
{
register u_int nsap_idx;
register char *cp;
register struct enamemem *tp;
u_int nsap_idx;
char *cp;
struct enamemem *tp;
if (nsap_length < 1 || nsap_length > ISONSAP_MAX_LENGTH)
return ("isonsap_string: illegal length");
@ -683,14 +721,14 @@ isonsap_string(netdissect_options *ndo, const u_char *nsap,
tp->e_name = cp = (char *)malloc(sizeof("xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xx"));
if (cp == NULL)
(*ndo->ndo_error)(ndo, "isonsap_string: malloc");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"isonsap_string: malloc");
for (nsap_idx = 0; nsap_idx < nsap_length; nsap_idx++) {
*cp++ = hex[*nsap >> 4];
*cp++ = hex[*nsap++ & 0xf];
cp = octet_to_hex(cp, *nsap++);
if (((nsap_idx & 1) == 0) &&
(nsap_idx + 1 < nsap_length)) {
*cp++ = '.';
*cp++ = '.';
}
}
*cp = '\0';
@ -700,8 +738,8 @@ isonsap_string(netdissect_options *ndo, const u_char *nsap,
const char *
tcpport_string(netdissect_options *ndo, u_short port)
{
register struct hnamemem *tp;
register uint32_t i = port;
struct hnamemem *tp;
uint32_t i = port;
char buf[sizeof("00000")];
for (tp = &tporttable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
@ -714,15 +752,16 @@ tcpport_string(netdissect_options *ndo, u_short port)
(void)snprintf(buf, sizeof(buf), "%u", i);
tp->name = strdup(buf);
if (tp->name == NULL)
(*ndo->ndo_error)(ndo, "tcpport_string: strdup(buf)");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"tcpport_string: strdup(buf)");
return (tp->name);
}
const char *
udpport_string(netdissect_options *ndo, register u_short port)
udpport_string(netdissect_options *ndo, u_short port)
{
register struct hnamemem *tp;
register uint32_t i = port;
struct hnamemem *tp;
uint32_t i = port;
char buf[sizeof("00000")];
for (tp = &uporttable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
@ -735,16 +774,17 @@ udpport_string(netdissect_options *ndo, register u_short port)
(void)snprintf(buf, sizeof(buf), "%u", i);
tp->name = strdup(buf);
if (tp->name == NULL)
(*ndo->ndo_error)(ndo, "udpport_string: strdup(buf)");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"udpport_string: strdup(buf)");
return (tp->name);
}
const char *
ipxsap_string(netdissect_options *ndo, u_short port)
{
register char *cp;
register struct hnamemem *tp;
register uint32_t i = port;
char *cp;
struct hnamemem *tp;
uint32_t i = port;
char buf[sizeof("0000")];
for (tp = &ipxsaptable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
@ -763,7 +803,8 @@ ipxsap_string(netdissect_options *ndo, u_short port)
*cp++ = '\0';
tp->name = strdup(buf);
if (tp->name == NULL)
(*ndo->ndo_error)(ndo, "ipxsap_string: strdup(buf)");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"ipxsap_string: strdup(buf)");
return (tp->name);
}
@ -771,8 +812,8 @@ static void
init_servarray(netdissect_options *ndo)
{
struct servent *sv;
register struct hnamemem *table;
register int i;
struct hnamemem *table;
int i;
char buf[sizeof("0000000000")];
while ((sv = getservent()) != NULL) {
@ -793,7 +834,8 @@ init_servarray(netdissect_options *ndo)
} else
table->name = strdup(sv->s_name);
if (table->name == NULL)
(*ndo->ndo_error)(ndo, "init_servarray: strdup");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"init_servarray: strdup");
table->addr = port;
table->nxt = newhnamemem(ndo);
@ -805,34 +847,34 @@ static const struct eproto {
const char *s;
u_short p;
} eproto_db[] = {
{ "pup", ETHERTYPE_PUP },
{ "xns", ETHERTYPE_NS },
{ "ip", ETHERTYPE_IP },
{ "ip6", ETHERTYPE_IPV6 },
{ "arp", ETHERTYPE_ARP },
{ "rarp", ETHERTYPE_REVARP },
{ "sprite", ETHERTYPE_SPRITE },
{ "mopdl", ETHERTYPE_MOPDL },
{ "moprc", ETHERTYPE_MOPRC },
{ "decnet", ETHERTYPE_DN },
{ "lat", ETHERTYPE_LAT },
{ "sca", ETHERTYPE_SCA },
{ "lanbridge", ETHERTYPE_LANBRIDGE },
{ "vexp", ETHERTYPE_VEXP },
{ "vprod", ETHERTYPE_VPROD },
{ "atalk", ETHERTYPE_ATALK },
{ "atalkarp", ETHERTYPE_AARP },
{ "loopback", ETHERTYPE_LOOPBACK },
{ "decdts", ETHERTYPE_DECDTS },
{ "decdns", ETHERTYPE_DECDNS },
{ "decdts", ETHERTYPE_DECDTS },
{ "decnet", ETHERTYPE_DN },
{ "ip", ETHERTYPE_IP },
{ "ip6", ETHERTYPE_IPV6 },
{ "lanbridge", ETHERTYPE_LANBRIDGE },
{ "lat", ETHERTYPE_LAT },
{ "loopback", ETHERTYPE_LOOPBACK },
{ "mopdl", ETHERTYPE_MOPDL },
{ "moprc", ETHERTYPE_MOPRC },
{ "pup", ETHERTYPE_PUP },
{ "rarp", ETHERTYPE_REVARP },
{ "sca", ETHERTYPE_SCA },
{ "sprite", ETHERTYPE_SPRITE },
{ "vexp", ETHERTYPE_VEXP },
{ "vprod", ETHERTYPE_VPROD },
{ "xns", ETHERTYPE_NS },
{ (char *)0, 0 }
};
static void
init_eprotoarray(netdissect_options *ndo)
{
register int i;
register struct hnamemem *table;
int i;
struct hnamemem *table;
for (i = 0; eproto_db[i].s; i++) {
int j = htons(eproto_db[i].p) & (HASHNAMESIZE-1);
@ -864,8 +906,8 @@ static const struct protoidlist {
static void
init_protoidarray(netdissect_options *ndo)
{
register int i;
register struct protoidmem *tp;
int i;
struct protoidmem *tp;
const struct protoidlist *pl;
u_char protoid[5];
@ -879,8 +921,8 @@ init_protoidarray(netdissect_options *ndo)
tp = lookup_protoid(ndo, protoid);
tp->p_name = strdup(eproto_db[i].s);
if (tp->p_name == NULL)
(*ndo->ndo_error)(ndo,
"init_protoidarray: strdup(eproto_db[i].s)");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"init_protoidarray: strdup(eproto_db[i].s)");
}
/* Hardwire some SNAP proto ID names */
for (pl = protoidlist; pl->name != NULL; ++pl) {
@ -918,13 +960,13 @@ static const struct etherlist {
static void
init_etherarray(netdissect_options *ndo)
{
register const struct etherlist *el;
register struct enamemem *tp;
const struct etherlist *el;
struct enamemem *tp;
#ifdef USE_ETHER_NTOHOST
char name[256];
#else
register struct pcap_etherent *ep;
register FILE *fp;
struct pcap_etherent *ep;
FILE *fp;
/* Suck in entire ethers file */
fp = fopen(PCAP_ETHERS_FILE, "r");
@ -933,8 +975,8 @@ init_etherarray(netdissect_options *ndo)
tp = lookup_emem(ndo, ep->addr);
tp->e_name = strdup(ep->name);
if (tp->e_name == NULL)
(*ndo->ndo_error)(ndo,
"init_etherarray: strdup(ep->addr)");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"init_etherarray: strdup(ep->addr)");
}
(void)fclose(fp);
}
@ -954,8 +996,8 @@ init_etherarray(netdissect_options *ndo)
if (ether_ntohost(name, (const struct ether_addr *)el->addr) == 0) {
tp->e_name = strdup(name);
if (tp->e_name == NULL)
(*ndo->ndo_error)(ndo,
"init_etherarray: strdup(name)");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"init_etherarray: strdup(name)");
continue;
}
#endif
@ -963,7 +1005,10 @@ init_etherarray(netdissect_options *ndo)
}
}
static const struct tok ipxsap_db[] = {
static const struct ipxsap_ent {
uint16_t v;
const char *s;
} ipxsap_db[] = {
{ 0x0000, "Unknown" },
{ 0x0001, "User" },
{ 0x0002, "User Group" },
@ -1183,11 +1228,11 @@ static const struct tok ipxsap_db[] = {
static void
init_ipxsaparray(netdissect_options *ndo)
{
register int i;
register struct hnamemem *table;
int i;
struct hnamemem *table;
for (i = 0; ipxsap_db[i].s != NULL; i++) {
int j = htons(ipxsap_db[i].v) & (HASHNAMESIZE-1);
u_int j = htons(ipxsap_db[i].v) & (HASHNAMESIZE-1);
table = &ipxsaptable[j];
while (table->name)
table = table->nxt;
@ -1226,7 +1271,7 @@ init_addrtoname(netdissect_options *ndo, uint32_t localnet, uint32_t mask)
const char *
dnaddr_string(netdissect_options *ndo, u_short dnaddr)
{
register struct hnamemem *tp;
struct hnamemem *tp;
for (tp = &dnaddrtable[dnaddr & (HASHNAMESIZE-1)]; tp->nxt != NULL;
tp = tp->nxt)
@ -1235,10 +1280,7 @@ dnaddr_string(netdissect_options *ndo, u_short dnaddr)
tp->addr = dnaddr;
tp->nxt = newhnamemem(ndo);
if (ndo->ndo_nflag)
tp->name = dnnum_string(ndo, dnaddr);
else
tp->name = dnname_string(ndo, dnaddr);
tp->name = dnnum_string(ndo, dnaddr);
return(tp->name);
}
@ -1247,7 +1289,7 @@ dnaddr_string(netdissect_options *ndo, u_short dnaddr)
struct hnamemem *
newhnamemem(netdissect_options *ndo)
{
register struct hnamemem *p;
struct hnamemem *p;
static struct hnamemem *ptr = NULL;
static u_int num = 0;
@ -1255,7 +1297,8 @@ newhnamemem(netdissect_options *ndo)
num = 64;
ptr = (struct hnamemem *)calloc(num, sizeof (*ptr));
if (ptr == NULL)
(*ndo->ndo_error)(ndo, "newhnamemem: calloc");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"newhnamemem: calloc");
}
--num;
p = ptr++;
@ -1266,7 +1309,7 @@ newhnamemem(netdissect_options *ndo)
struct h6namemem *
newh6namemem(netdissect_options *ndo)
{
register struct h6namemem *p;
struct h6namemem *p;
static struct h6namemem *ptr = NULL;
static u_int num = 0;
@ -1274,7 +1317,8 @@ newh6namemem(netdissect_options *ndo)
num = 64;
ptr = (struct h6namemem *)calloc(num, sizeof (*ptr));
if (ptr == NULL)
(*ndo->ndo_error)(ndo, "newh6namemem: calloc");
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"newh6namemem: calloc");
}
--num;
p = ptr++;

View File

@ -19,8 +19,10 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "extract.h"
/*
* Definitions to let us compile most of the IPv6 code even on systems
* Definition to let us compile most of the IPv6 code even on systems
* without IPv6 support.
*/
#ifndef INET6_ADDRSTRLEN
@ -33,23 +35,22 @@ enum {
LINKADDR_ETHER,
LINKADDR_FRELAY,
LINKADDR_IEEE1394,
LINKADDR_ATM
LINKADDR_ATM,
LINKADDR_OTHER
};
#define BUFSIZE 128
extern const char *linkaddr_string(netdissect_options *, const u_char *, const unsigned int, const unsigned int);
extern const char *etheraddr_string(netdissect_options *, const u_char *);
extern const char *le64addr_string(netdissect_options *, const u_char *);
extern const char *etherproto_string(netdissect_options *, u_short);
extern const char *linkaddr_string(netdissect_options *, const uint8_t *, const unsigned int, const unsigned int);
extern const char *etheraddr_string(netdissect_options *, const uint8_t *);
extern const char *le64addr_string(netdissect_options *, const uint8_t *);
extern const char *tcpport_string(netdissect_options *, u_short);
extern const char *udpport_string(netdissect_options *, u_short);
extern const char *isonsap_string(netdissect_options *, const u_char *, register u_int);
extern const char *isonsap_string(netdissect_options *, const uint8_t *, u_int);
extern const char *dnaddr_string(netdissect_options *, u_short);
extern const char *protoid_string(netdissect_options *, const u_char *);
extern const char *ipxsap_string(netdissect_options *, u_short);
extern const char *getname(netdissect_options *, const u_char *);
extern const char *getname6(netdissect_options *, const u_char *);
extern const char *ipaddr_string(netdissect_options *, const u_char *);
extern const char *ip6addr_string(netdissect_options *, const u_char *);
extern const char *intoa(uint32_t);
extern void init_addrtoname(netdissect_options *, uint32_t, uint32_t);
@ -57,5 +58,64 @@ extern struct hnamemem *newhnamemem(netdissect_options *);
extern struct h6namemem *newh6namemem(netdissect_options *);
extern const char * ieee8021q_tci_string(const uint16_t);
#define ipaddr_string(ndo, p) getname(ndo, (const u_char *)(p))
#define ip6addr_string(ndo, p) getname6(ndo, (const u_char *)(p))
/* macro(s) and inline function(s) with setjmp/longjmp logic to call
* the X_string() function(s) after bounds checking.
* The macro(s) must be used on a packet buffer pointer.
*/
static inline const char *
get_linkaddr_string(netdissect_options *ndo, const uint8_t *p,
const unsigned int type, const unsigned int len)
{
if (!ND_TTEST_LEN(p, len))
longjmp(ndo->ndo_truncated, 1);
return linkaddr_string(ndo, p, type, len);
}
static inline const char *
get_etheraddr_string(netdissect_options *ndo, const uint8_t *p)
{
if (!ND_TTEST_LEN(p, MAC_ADDR_LEN))
longjmp(ndo->ndo_truncated, 1);
return etheraddr_string(ndo, p);
}
static inline const char *
get_le64addr_string(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_8(p))
longjmp(ndo->ndo_truncated, 1);
return le64addr_string(ndo, p);
}
static inline const char *
get_isonsap_string(netdissect_options *ndo, const uint8_t *nsap,
u_int nsap_length)
{
if (!ND_TTEST_LEN(nsap, nsap_length))
longjmp(ndo->ndo_truncated, 1);
return isonsap_string(ndo, nsap, nsap_length);
}
static inline const char *
get_ipaddr_string(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_4(p))
longjmp(ndo->ndo_truncated, 1);
return ipaddr_string(ndo, p);
}
static inline const char *
get_ip6addr_string(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_16(p))
longjmp(ndo->ndo_truncated, 1);
return ip6addr_string(ndo, p);
}
#define GET_LINKADDR_STRING(p, type, len) get_linkaddr_string(ndo, (const u_char *)(p), type, len)
#define GET_ETHERADDR_STRING(p) get_etheraddr_string(ndo, (const u_char *)(p))
#define GET_LE64ADDR_STRING(p) get_le64addr_string(ndo, (const u_char *)(p))
#define GET_ISONSAP_STRING(nsap, nsap_length) get_isonsap_string(ndo, (const u_char *)(nsap), nsap_length)
#define GET_IPADDR_STRING(p) get_ipaddr_string(ndo, (const u_char *)(p))
#define GET_IP6ADDR_STRING(p) get_ip6addr_string(ndo, (const u_char *)(p))

View File

@ -37,10 +37,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include "addrtostr.h"
#include <stdio.h>
@ -110,19 +110,18 @@ addrtostr6 (const void *src, char *dst, size_t size)
size_t space_left, added_space;
int snprintfed;
struct {
long base;
long len;
int base;
int len;
} best, cur;
u_long words [IN6ADDRSZ / INT16SZ];
u_int i;
uint16_t words [IN6ADDRSZ / INT16SZ];
int i;
/* Preprocess:
* Copy the input (bytewise) array into a wordwise array.
* Find the longest run of 0x00's in src[] for :: shorthanding.
*/
memset (words, 0, sizeof(words));
for (i = 0; i < IN6ADDRSZ; i++)
words[i/2] |= (srcaddr[i] << ((1 - (i % 2)) << 3));
for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++)
words[i] = (srcaddr[2*i] << 8) | srcaddr[2*i + 1];
best.len = 0;
best.base = -1;
@ -192,7 +191,7 @@ addrtostr6 (const void *src, char *dst, size_t size)
space_left -= added_space;
break;
}
snprintfed = snprintf (dp, space_left, "%lx", words[i]);
snprintfed = snprintf (dp, space_left, "%x", words[i]);
if (snprintfed < 0)
return (NULL);
if ((size_t) snprintfed >= space_left)

6
af.c
View File

@ -12,14 +12,14 @@
* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
* Original code by Hannes Gredler (hannes@juniper.net)
* Original code by Hannes Gredler (hannes@gredler.at)
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "af.h"

4
af.h
View File

@ -12,7 +12,7 @@
* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
* Original code by Hannes Gredler (hannes@juniper.net)
* Original code by Hannes Gredler (hannes@gredler.at)
*/
extern const struct tok af_values[];
@ -52,4 +52,4 @@ extern const struct tok bsd_af_values[];
#define BSD_AFNUM_IPX 23
#define BSD_AFNUM_INET6_BSD 24 /* NetBSD, OpenBSD, BSD/OS, Npcap */
#define BSD_AFNUM_INET6_FREEBSD 28 /* FreeBSD */
#define BSD_AFNUM_INET6_DARWIN 30 /* OS X, iOS, other Darwin-based OSes */
#define BSD_AFNUM_INET6_DARWIN 30 /* macOS, iOS, other Darwin-based OSes */

18
ah.h
View File

@ -38,19 +38,19 @@
#define _NETINET6_AH_H_
struct ah {
uint8_t ah_nxt; /* Next Header */
uint8_t ah_len; /* Length of data, in 32bit */
uint16_t ah_reserve; /* Reserved for future use */
uint32_t ah_spi; /* Security parameter index */
nd_uint8_t ah_nxt; /* Next Header */
nd_uint8_t ah_len; /* Length of data, in 32bit */
nd_uint16_t ah_reserve; /* Reserved for future use */
nd_uint32_t ah_spi; /* Security parameter index */
/* variable size, 32bit bound*/ /* Authentication data */
};
struct newah {
uint8_t ah_nxt; /* Next Header */
uint8_t ah_len; /* Length of data + 1, in 32bit */
uint16_t ah_reserve; /* Reserved for future use */
uint32_t ah_spi; /* Security parameter index */
uint32_t ah_seq; /* Sequence number field */
nd_uint8_t ah_nxt; /* Next Header */
nd_uint8_t ah_len; /* Length of data + 1, in 32bit */
nd_uint16_t ah_reserve; /* Reserved for future use */
nd_uint32_t ah_spi; /* Security parameter index */
nd_uint32_t ah_seq; /* Sequence number field */
/* variable size, 32bit bound*/ /* Authentication data */
};

View File

@ -22,9 +22,9 @@
*/
struct LAP {
uint8_t dst;
uint8_t src;
uint8_t type;
nd_uint8_t dst;
nd_uint8_t src;
nd_uint8_t type;
};
#define lapShortDDP 1 /* short DDP type */
#define lapDDP 2 /* DDP type */
@ -33,22 +33,22 @@ struct LAP {
/* Datagram Delivery Protocol */
struct atDDP {
uint16_t length;
uint16_t checksum;
uint16_t dstNet;
uint16_t srcNet;
uint8_t dstNode;
uint8_t srcNode;
uint8_t dstSkt;
uint8_t srcSkt;
uint8_t type;
nd_uint16_t length;
nd_uint16_t checksum;
nd_uint16_t dstNet;
nd_uint16_t srcNet;
nd_uint8_t dstNode;
nd_uint8_t srcNode;
nd_uint8_t dstSkt;
nd_uint8_t srcSkt;
nd_uint8_t type;
};
struct atShortDDP {
uint16_t length;
uint8_t dstSkt;
uint8_t srcSkt;
uint8_t type;
nd_uint16_t length;
nd_uint8_t dstSkt;
nd_uint8_t srcSkt;
nd_uint8_t type;
};
#define ddpMaxWKS 0x7F
@ -72,10 +72,10 @@ struct atShortDDP {
/* AppleTalk Transaction Protocol */
struct atATP {
uint8_t control;
uint8_t bitmap;
uint16_t transID;
int32_t userData;
nd_uint8_t control;
nd_uint8_t bitmap;
nd_uint16_t transID;
nd_uint32_t userData;
};
#define atpReqCode 0x40
@ -93,8 +93,8 @@ struct atATP {
/* AppleTalk Echo Protocol */
struct atEcho {
uint8_t echoFunction;
uint8_t *echoData;
nd_uint8_t echoFunction;
nd_uint8_t echoData[1]; /* Should be [], C99-style */
};
#define echoSkt 4 /* the echoer socket */
@ -106,15 +106,15 @@ struct atEcho {
/* Name Binding Protocol */
struct atNBP {
uint8_t control;
uint8_t id;
nd_uint8_t control;
nd_uint8_t id;
};
struct atNBPtuple {
uint16_t net;
uint8_t node;
uint8_t skt;
uint8_t enumerator;
nd_uint16_t net;
nd_uint8_t node;
nd_uint8_t skt;
nd_uint8_t enumerator;
};
#define nbpBrRq 0x10
@ -140,8 +140,8 @@ struct atNBPtuple {
/* Zone Information Protocol */
struct zipHeader {
uint8_t command;
uint8_t netcount;
nd_uint8_t command;
nd_uint8_t netcount;
};
#define zipHeaderSize 2

View File

@ -58,7 +58,7 @@ static const unsigned char charmap[] = {
int
ascii_strcasecmp(const char *s1, const char *s2)
{
register const unsigned char *cm = charmap,
const unsigned char *cm = charmap,
*us1 = (const unsigned char *)s1,
*us2 = (const unsigned char *)s2;
@ -69,9 +69,9 @@ ascii_strcasecmp(const char *s1, const char *s2)
}
int
ascii_strncasecmp(const char *s1, const char *s2, register size_t n)
ascii_strncasecmp(const char *s1, const char *s2, size_t n)
{
register const unsigned char *cm = charmap,
const unsigned char *cm = charmap,
*us1 = (const unsigned char *)s1,
*us2 = (const unsigned char *)s2;

View File

@ -20,10 +20,10 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include <stdio.h>

28
buildem Executable file
View File

@ -0,0 +1,28 @@
#!/bin/sh
# this script builds libpcap and tcpdump using the matrix of compilers and architectures
# that travis also buildsd.
if [ -f Makefile.in ]; then cd ..; fi
here=`pwd`
mkdir -p builds
cd builds
export CFLAGS='-fno-omit-frame-pointer -fsanitize=address -fno-optimize-sibling-calls -fPIC -Wextra -g3 -ggdb3 -O0 -Werror'
for arch in i386 x86_64
do
case $arch in
i386) CFLAGS="-m32 $CFLAGS"; export LDFLAGS="-m32"; export CXXFLAGS=-m32; target="i686-pc-linux-gnu" ;;
esac
(
for compiler in clang-6.0 gcc
do
mkdir -p $arch/$compiler
set -x
(cd $arch/$compiler && mkdir -p libpcap tcpdump &&
(cd libpcap && CC=$compiler $here/libpcap/configure --target=$target && make ) &&
(cd tcpdump && CC=$compiler $here/tcpdump/configure --target=$target && make && make check))
done
)
done

View File

@ -14,14 +14,14 @@
*
* miscellaneous checksumming routines
*
* Original code by Hannes Gredler (hannes@juniper.net)
* Original code by Hannes Gredler (hannes@gredler.at)
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include <stdio.h>
#include <stdlib.h>
@ -90,8 +90,8 @@ static void
init_crc10_table(void)
{
#define CRC10_POLYNOMIAL 0x633
register int i, j;
register uint16_t accum;
int i, j;
uint16_t accum;
uint16_t verify_crc10_table[256];
for ( i = 0; i < 256; i++ )
@ -112,7 +112,7 @@ init_crc10_table(void)
uint16_t
verify_crc10_cksum(uint16_t accum, const u_char *p, int length)
{
register int i;
int i;
for ( i = 0; i < length; i++ )
{

View File

@ -0,0 +1,24 @@
#
# Try to find libcrypto.
#
# Try to find the header
find_path(CRYPTO_INCLUDE_DIR openssl/crypto.h)
# Try to find the library
find_library(CRYPTO_LIBRARY crypto)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CRYPTO
DEFAULT_MSG
CRYPTO_INCLUDE_DIR
CRYPTO_LIBRARY
)
mark_as_advanced(
CRYPTO_INCLUDE_DIR
CRYPTO_LIBRARY
)
set(CRYPTO_INCLUDE_DIRS ${CRYPTO_INCLUDE_DIR})
set(CRYPTO_LIBRARIES ${CRYPTO_LIBRARY})

View File

@ -0,0 +1,325 @@
#
# Try to find libpcap.
#
# To tell this module where to look, a user may set the environment variable
# PCAP_ROOT to point cmake to the *root* of a directory with include and
# lib subdirectories for pcap.dll (e.g WpdPack or npcap-sdk).
# Alternatively, PCAP_ROOT may also be set from cmake command line or GUI
# (e.g cmake -DPCAP_ROOT=C:\path\to\pcap [...])
#
if(WIN32)
#
# Building for Windows.
#
# libpcap isn't set up to install .pc files or pcap-config on Windows,
# and it's not clear that either of them would work without a lot
# of additional effort. WinPcap doesn't supply them, and neither
# does Npcap.
#
# So just search for them directly. Look for both pcap and wpcap.
# Don't bother looking for static libraries; unlike most UN*Xes
# (with the exception of AIX), where different extensions are used
# for shared and static, Windows uses .lib both for import libraries
# for DLLs and for static libraries.
#
# We don't directly set PCAP_INCLUDE_DIRS or PCAP_LIBRARIES, as
# they're not supposed to be cache entries, and find_path() and
# find_library() set cache entries.
#
find_path(PCAP_INCLUDE_DIR pcap.h)
# The 64-bit Packet.lib is located under /x64
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
#
# For the WinPcap and Npcap SDKs, the Lib subdirectory of the top-level
# directory contains 32-bit libraries; the 64-bit libraries are in the
# Lib/x64 directory.
#
# The only way to *FORCE* CMake to look in the Lib/x64 directory
# without searching in the Lib directory first appears to be to set
# CMAKE_LIBRARY_ARCHITECTURE to "x64".
#
set(CMAKE_LIBRARY_ARCHITECTURE "x64")
endif()
find_library(PCAP_LIBRARY NAMES pcap wpcap)
#
# Do the standard arg processing, including failing if it's a
# required package.
#
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PCAP
DEFAULT_MSG
PCAP_INCLUDE_DIR
PCAP_LIBRARY
)
mark_as_advanced(
PCAP_INCLUDE_DIR
PCAP_LIBRARY
)
if(PCAP_FOUND)
set(PCAP_LIBRARIES ${PCAP_LIBRARY})
set(PCAP_INCLUDE_DIRS ${PCAP_INCLUDE_DIR})
endif()
else(WIN32)
#
# Building for UN*X.
#
# See whether we were handed a QUIET argument, so we can pass it on
# to pkg_search_module. Do *NOT* pass on the REQUIRED argument,
# because, if pkg-config isn't found, or it is but it has no .pc
# files for libpcap, that is *not* necessarily an indication that
# libpcap isn't available - not all systems ship pkg-config, and
# libpcap didn't have .pc files until libpcap 1.9.0.
#
if(PCAP_FIND_QUIETLY)
set(_quiet "QUIET")
endif()
#
# First, try pkg-config.
#
find_package(PkgConfig)
pkg_search_module(CONFIG_PCAP ${_quiet} libpcap)
if(NOT CONFIG_PCAP_FOUND)
#
# That didn't work. Try pcap-config.
#
find_program(PCAP_CONFIG pcap-config)
if(PCAP_CONFIG)
#
# We have pcap-config; use it.
#
if(NOT "${_quiet}" STREQUAL "QUIET")
message(STATUS "Found pcap-config")
endif()
#
# if this is macOS or some other Darwin-based OS, check whether
# it's the system-supplied one.
#
if(APPLE AND "${PCAP_CONFIG}" STREQUAL /usr/bin/pcap-config)
#
# It is - remember that, so that if it provides -I/usr/local/include
# with --cflags, or -L/usr/local/lib with --libs, we ignore it;
# the macOS pcap-config does that even though the headers aren't
# under /usr/local/include and the library isn't in /usr/local/lib.
#
set(_broken_apple_pcap_config TRUE)
endif()
#
# Now get the include directories.
#
execute_process(COMMAND "${PCAP_CONFIG}" "--cflags"
RESULT_VARIABLE PCAP_CONFIG_RESULT
OUTPUT_VARIABLE PCAP_CONFIG_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT PCAP_CONFIG_RESULT EQUAL 0)
message(FATAL_ERROR "pcap-config --cflags failed")
endif()
separate_arguments(CFLAGS_LIST UNIX_COMMAND ${PCAP_CONFIG_OUTPUT})
set(CONFIG_PCAP_INCLUDE_DIRS "")
foreach(_arg IN LISTS CFLAGS_LIST)
if(_arg MATCHES "^-I")
#
# Extract the directory by removing the -I.
#
string(REGEX REPLACE "-I" "" _dir ${_arg})
#
# Work around macOS (and probably other Darwin) brokenness,
# by not adding /usr/local/include if it's from the broken
# Apple pcap-config.
#
if(NOT _broken_apple_pcap_config OR
NOT "${_dir}" STREQUAL /usr/local/include)
# Add it to CONFIG_PCAP_INCLUDE_DIRS
list(APPEND CONFIG_PCAP_INCLUDE_DIRS ${_dir})
endif()
endif()
endforeach()
#
# Now, get the library directories and libraries for dynamic linking.
#
execute_process(COMMAND "${PCAP_CONFIG}" "--libs"
RESULT_VARIABLE PCAP_CONFIG_RESULT
OUTPUT_VARIABLE PCAP_CONFIG_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT PCAP_CONFIG_RESULT EQUAL 0)
message(FATAL_ERROR "pcap-config --libs failed")
endif()
separate_arguments(LIBS_LIST UNIX_COMMAND ${PCAP_CONFIG_OUTPUT})
set(CONFIG_PCAP_LIBRARY_DIRS "")
set(CONFIG_PCAP_LIBRARIES "")
foreach(_arg IN LISTS LIBS_LIST)
if(_arg MATCHES "^-L")
#
# Extract the directory by removing the -L.
#
string(REGEX REPLACE "-L" "" _dir ${_arg})
#
# Work around macOS (and probably other Darwin) brokenness,
# by not adding /usr/local/lib if it's from the broken
# Apple pcap-config.
#
if(NOT _broken_apple_pcap_config OR
NOT "${_dir}" STREQUAL /usr/local/lib)
# Add this directory to CONFIG_PCAP_LIBRARY_DIRS
list(APPEND CONFIG_PCAP_LIBRARY_DIRS ${_dir})
endif()
elseif(_arg MATCHES "^-l")
string(REGEX REPLACE "-l" "" _lib ${_arg})
list(APPEND CONFIG_PCAP_LIBRARIES ${_lib})
endif()
endforeach()
#
# Now, get the library directories and libraries for static linking.
#
execute_process(COMMAND "${PCAP_CONFIG}" "--libs" "--static"
RESULT_VARIABLE PCAP_CONFIG_RESULT
OUTPUT_VARIABLE PCAP_CONFIG_OUTPUT
)
if(NOT PCAP_CONFIG_RESULT EQUAL 0)
message(FATAL_ERROR "pcap-config --libs --static failed")
endif()
separate_arguments(LIBS_LIST UNIX_COMMAND ${PCAP_CONFIG_OUTPUT})
set(CONFIG_PCAP_STATIC_LIBRARY_DIRS "")
set(CONFIG_PCAP_STATIC_LIBRARIES "")
foreach(_arg IN LISTS LIBS_LIST)
if(_arg MATCHES "^-L")
#
# Extract the directory by removing the -L.
#
string(REGEX REPLACE "-L" "" _dir ${_arg})
#
# Work around macOS (and probably other Darwin) brokenness,
# by not adding /usr/local/lib if it's from the broken
# Apple pcap-config.
#
if(NOT _broken_apple_pcap_config OR
NOT "${_dir}" STREQUAL /usr/local/lib)
# Add this directory to CONFIG_PCAP_STATIC_LIBRARY_DIRS
list(APPEND CONFIG_PCAP_STATIC_LIBRARY_DIRS ${_dir})
endif()
elseif(_arg MATCHES "^-l")
string(REGEX REPLACE "-l" "" _lib ${_arg})
#
# Try to find that library, so we get its full path, as
# we do with dynamic libraries.
#
list(APPEND CONFIG_PCAP_STATIC_LIBRARIES ${_lib})
endif()
endforeach()
#
# We've set CONFIG_PCAP_INCLUDE_DIRS, CONFIG_PCAP_LIBRARIES, and
# CONFIG_PCAP_STATIC_LIBRARIES above; set CONFIG_PCAP_FOUND.
#
set(CONFIG_PCAP_FOUND YES)
endif()
endif()
#
# If CONFIG_PCAP_FOUND is set, we have information from pkg-config and
# pcap-config; we need to convert library names to library full paths.
#
# If it's not set, we have to look for the libpcap headers and library
# ourselves.
#
if(CONFIG_PCAP_FOUND)
#
# Use CONFIG_PCAP_INCLUDE_DIRS as the value for PCAP_INCLUDE_DIRS.
#
set(PCAP_INCLUDE_DIRS "${CONFIG_PCAP_INCLUDE_DIRS}")
#
# CMake *really* doesn't like the notion of specifying
# "here are the directories in which to look for libraries"
# except in find_library() calls; it *really* prefers using
# full paths to library files, rather than library names.
#
foreach(_lib IN LISTS CONFIG_PCAP_LIBRARIES)
find_library(_libfullpath ${_lib} HINTS ${CONFIG_PCAP_LIBRARY_DIRS})
list(APPEND PCAP_LIBRARIES ${_libfullpath})
#
# Remove that from the cache; we're using it as a local variable,
# but find_library insists on making it a cache variable.
#
unset(_libfullpath CACHE)
endforeach()
#
# Now do the same for the static libraries.
#
set(SAVED_CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
foreach(_lib IN LISTS CONFIG_PCAP_STATIC_LIBRARIES)
find_library(_libfullpath ${_lib} HINTS ${CONFIG_PCAP_LIBRARY_DIRS})
list(APPEND PCAP_STATIC_LIBRARIES ${_libfullpath})
#
# Remove that from the cache; we're using it as a local variable,
# but find_library insists on making it a cache variable.
#
unset(_libfullpath CACHE)
endforeach()
set(CMAKE_FIND_LIBRARY_SUFFIXES "${SAVED_CMAKE_FIND_LIBRARY_SUFFIXES}")
#
# We found libpcap using pkg-config or pcap-config.
#
set(PCAP_FOUND YES)
else(CONFIG_PCAP_FOUND)
#
# We didn't have pkg-config, or we did but it didn't have .pc files
# for libpcap, and we don't have pkg-config, so we have to look for
# the headers and libraries ourself.
#
# We don't directly set PCAP_INCLUDE_DIRS or PCAP_LIBRARIES, as
# they're not supposed to be cache entries, and find_path() and
# find_library() set cache entries.
#
# Try to find the header file.
#
find_path(PCAP_INCLUDE_DIR pcap.h)
#
# Try to find the library
#
find_library(PCAP_LIBRARY pcap)
# Try to find the static library (XXX - what about AIX?)
set(SAVED_CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
find_library(PCAP_STATIC_LIBRARY pcap)
set(CMAKE_FIND_LIBRARY_SUFFIXES "${SAVED_CMAKE_FIND_LIBRARY_SUFFIXES}")
#
# This will fail if REQUIRED is set and PCAP_INCLUDE_DIR or
# PCAP_LIBRARY aren't set.
#
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PCAP
DEFAULT_MSG
PCAP_INCLUDE_DIR
PCAP_LIBRARY
)
mark_as_advanced(
PCAP_INCLUDE_DIR
PCAP_LIBRARY
PCAP_STATIC_LIBRARY
)
if(PCAP_FOUND)
set(PCAP_INCLUDE_DIRS ${PCAP_INCLUDE_DIR})
set(PCAP_LIBRARIES ${PCAP_LIBRARY})
set(PCAP_STATIC_LIBRARIES ${PCAP_STATIC_LIBRARY})
endif(PCAP_FOUND)
endif(CONFIG_PCAP_FOUND)
endif(WIN32)

View File

@ -0,0 +1,24 @@
#
# Try to find libsmi.
#
# Try to find the header
find_path(SMI_INCLUDE_DIR smi.h)
# Try to find the library
find_library(SMI_LIBRARY smi)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SMI
DEFAULT_MSG
SMI_INCLUDE_DIR
SMI_LIBRARY
)
mark_as_advanced(
SMI_INCLUDE_DIR
SMI_LIBRARY
)
set(SMI_INCLUDE_DIRS ${SMI_INCLUDE_DIR})
set(SMI_LIBRARIES ${SMI_LIBRARY})

21
cmake_uninstall.cmake.in Normal file
View File

@ -0,0 +1,21 @@
if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
foreach(file ${files})
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
exec_program(
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
OUTPUT_VARIABLE rm_out
RETURN_VALUE rm_retval
)
if(NOT "${rm_retval}" STREQUAL 0)
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
endif(NOT "${rm_retval}" STREQUAL 0)
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
endforeach(file)

299
cmakeconfig.h.in Normal file
View File

@ -0,0 +1,299 @@
/* cmakeconfig.h.in */
/* Define to 1 if arpa/inet.h declares `ether_ntohost' */
#cmakedefine ARPA_INET_H_DECLARES_ETHER_NTOHOST 1
/* define if you want to build the possibly-buggy SMB printer */
#cmakedefine ENABLE_SMB 1
/* Define to 1 if you have the `bpf_dump' function. */
#cmakedefine HAVE_BPF_DUMP 1
/* capsicum support available */
#cmakedefine HAVE_CAPSICUM 1
/* Define to 1 if you have the `cap_enter' function. */
#cmakedefine HAVE_CAP_ENTER 1
/* Define to 1 if you have the `cap_ioctls_limit' function. */
#cmakedefine HAVE_CAP_IOCTLS_LIMIT 1
/* Define to 1 if you have the <cap-ng.h> header file. */
#cmakedefine HAVE_CAP_NG_H 1
/* Define to 1 if you have the `cap_rights_limit' function. */
#cmakedefine HAVE_CAP_RIGHTS_LIMIT 1
/* Casper support available */
#cmakedefine HAVE_CASPER 1
/* Define to 1 if you have the declaration of `ether_ntohost' */
#cmakedefine HAVE_DECL_ETHER_NTOHOST 1
/* Define to 1 if you have the `ether_ntohost' function. */
#cmakedefine HAVE_ETHER_NTOHOST 1
/* Define to 1 if you have the `EVP_CIPHER_CTX_new' function. */
#cmakedefine HAVE_EVP_CIPHER_CTX_NEW 1
/* Define to 1 if you have the `EVP_DecryptInit_ex' function. */
#cmakedefine HAVE_EVP_DECRYPTINIT_EX 1
/* Define to 1 if you have the <fcntl.h> header file. */
#cmakedefine HAVE_FCNTL_H 1
/* Define to 1 if you have the `fork' function. */
#cmakedefine HAVE_FORK 1
/* Define to 1 if you have the `getopt_long' function. */
#cmakedefine HAVE_GETOPT_LONG 1
/* define if you have getrpcbynumber() */
#cmakedefine HAVE_GETRPCBYNUMBER 1
/* Define to 1 if you have the `getservent' function. */
#cmakedefine HAVE_GETSERVENT 1
/* Define to 1 if you have the <inttypes.h> header file. */
#cmakedefine HAVE_INTTYPES_H 1
/* Define to 1 if you have the `cap-ng' library (-lcap-ng). */
#cmakedefine HAVE_LIBCAP_NG 1
/* Define to 1 if you have the `crypto' library (-lcrypto). */
#cmakedefine HAVE_LIBCRYPTO 1
/* Define to 1 if you have the `rpc' library (-lrpc). */
#cmakedefine HAVE_LIBRPC 1
/* Define to 1 if you have the <memory.h> header file. */
#cmakedefine HAVE_MEMORY_H 1
/* Define to 1 if you have the <net/if.h> header file. */
#cmakedefine HAVE_NET_IF_H 1
/* Define to 1 if you have the <net/if_pflog.h> header file. */
#cmakedefine HAVE_NET_IF_PFLOG_H 1
/* Define to 1 if you have the <net/pfvar.h> header file. */
#cmakedefine HAVE_NET_PFVAR_H 1
/* Define to 1 if you have the `openat' function. */
#cmakedefine HAVE_OPENAT 1
/* Define to 1 if you have the <openssl/evp.h> header file. */
#cmakedefine HAVE_OPENSSL_EVP_H 1
/* define if the OS provides AF_INET6 and struct in6_addr */
#cmakedefine HAVE_OS_IPV6_SUPPORT 1
/* if there's an os_proto.h for this platform, to use additional prototypes */
#cmakedefine HAVE_OS_PROTO_H 1
/* Define to 1 if you have the `pcap_breakloop' function. */
#cmakedefine HAVE_PCAP_BREAKLOOP 1
/* Define to 1 if you have the `pcap_create' function. */
#cmakedefine HAVE_PCAP_CREATE 1
/* define if libpcap has pcap_datalink_name_to_val() */
#cmakedefine HAVE_PCAP_DATALINK_NAME_TO_VAL 1
/* define if libpcap has pcap_datalink_val_to_description() */
#cmakedefine HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION 1
/* define if libpcap has pcap_debug */
#cmakedefine HAVE_PCAP_DEBUG 1
/* Define to 1 if you have the `pcap_dump_flush' function. */
#cmakedefine HAVE_PCAP_DUMP_FLUSH 1
/* define if libpcap has pcap_dump_ftell() */
#cmakedefine HAVE_PCAP_DUMP_FTELL 1
/* Define to 1 if you have the `pcap_dump_ftell64' function. */
#cmakedefine HAVE_PCAP_DUMP_FTELL64 1
/* Define to 1 if you have the `pcap_findalldevs' function. */
#cmakedefine HAVE_PCAP_FINDALLDEVS 1
/* Define to 1 if you have the `pcap_findalldevs_ex' function. */
#cmakedefine HAVE_PCAP_FINDALLDEVS_EX 1
/* Define to 1 if you have the `pcap_free_datalinks' function. */
#cmakedefine HAVE_PCAP_FREE_DATALINKS 1
/* Define to 1 if the system has the type `pcap_if_t'. */
#cmakedefine HAVE_PCAP_IF_T 1
/* Define to 1 if you have the `pcap_lib_version' function. */
#cmakedefine HAVE_PCAP_LIB_VERSION 1
/* define if libpcap has pcap_list_datalinks() */
#cmakedefine HAVE_PCAP_LIST_DATALINKS 1
/* Define to 1 if you have the `pcap_open' function. */
#cmakedefine HAVE_PCAP_OPEN 1
/* Define to 1 if you have the <pcap/pcap-inttypes.h> header file. */
#cmakedefine HAVE_PCAP_PCAP_INTTYPES_H 1
/* Define to 1 if you have the `pcap_setdirection' function. */
#cmakedefine HAVE_PCAP_SETDIRECTION 1
/* Define to 1 if you have the `pcap_set_datalink' function. */
#cmakedefine HAVE_PCAP_SET_DATALINK 1
/* Define to 1 if you have the `pcap_set_immediate_mode' function. */
#cmakedefine HAVE_PCAP_SET_IMMEDIATE_MODE 1
/* Define to 1 if you have the `pcap_set_optimizer_debug' function. */
#cmakedefine HAVE_PCAP_SET_OPTIMIZER_DEBUG 1
/* Define to 1 if you have the `pcap_set_parser_debug' function. */
#cmakedefine HAVE_PCAP_SET_PARSER_DEBUG 1
/* Define to 1 if you have the `pcap_set_tstamp_precision' function. */
#cmakedefine HAVE_PCAP_SET_TSTAMP_PRECISION 1
/* Define to 1 if you have the `pcap_set_tstamp_type' function. */
#cmakedefine HAVE_PCAP_SET_TSTAMP_TYPE 1
/* define if libpcap has pcap_version */
#cmakedefine HAVE_PCAP_VERSION 1
/* Define to 1 if you have the `pcap_wsockinit' function. */
#cmakedefine HAVE_PCAP_WSOCKINIT 1
/* Define to 1 if you have the `pfopen' function. */
#cmakedefine HAVE_PFOPEN 1
/* Define to 1 if you have the <rpc/rpcent.h> header file. */
#cmakedefine HAVE_RPC_RPCENT_H 1
/* Define to 1 if you have the <rpc/rpc.h> header file. */
#cmakedefine HAVE_RPC_RPC_H 1
/* Define to 1 if you have the `setlinebuf' function. */
#cmakedefine HAVE_SETLINEBUF 1
/* Define to 1 if you have the <stdint.h> header file. */
#cmakedefine HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#cmakedefine HAVE_STDLIB_H 1
/* Define to 1 if you have the `strdup' function. */
#cmakedefine HAVE_STRDUP 1
/* Define to 1 if you have the `strftime' function. */
#cmakedefine HAVE_STRFTIME 1
/* Define to 1 if you have the <strings.h> header file. */
#cmakedefine HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#cmakedefine HAVE_STRING_H 1
/* Define to 1 if you have the `strlcat' function. */
#cmakedefine HAVE_STRLCAT 1
/* Define to 1 if you have the `strlcpy' function. */
#cmakedefine HAVE_STRLCPY 1
/* Define to 1 if you have the `strsep' function. */
#cmakedefine HAVE_STRSEP 1
/* Define to 1 if the system has the type `struct ether_addr'. */
#cmakedefine HAVE_STRUCT_ETHER_ADDR 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#cmakedefine HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#cmakedefine HAVE_SYS_TYPES_H 1
/* Define to 1 if the system has the type `uintptr_t'. */
#cmakedefine HAVE_UINTPTR_T 1
/* Define to 1 if you have the <unistd.h> header file. */
#cmakedefine HAVE_UNISTD_H 1
/* Define to 1 if you have the `vfork' function. */
#cmakedefine HAVE_VFORK 1
/* Define to 1 if you have the `wsockinit' function. */
#cmakedefine HAVE_WSOCKINIT 1
/* define if libpcap has yydebug */
#cmakedefine HAVE_YYDEBUG 1
/* Define to 1 if netinet/ether.h declares `ether_ntohost' */
#cmakedefine NETINET_ETHER_H_DECLARES_ETHER_NTOHOST 1
/* Define to 1 if netinet/if_ether.h declares `ether_ntohost' */
#cmakedefine NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST 1
/* Define to 1 if net/ethernet.h declares `ether_ntohost' */
#cmakedefine NET_ETHERNET_H_DECLARES_ETHER_NTOHOST 1
/* Define to the address where bug reports for this package should be sent. */
#cmakedefine PACKAGE_BUGREPORT ""
/* Define to the full name of this package. */
#cmakedefine PACKAGE_NAME "@PACKAGE_NAME@"
/* Define to the full name and version of this package. */
#cmakedefine PACKAGE_STRING "@PACKAGE_STRING@"
/* Define to the one symbol short name of this package. */
#cmakedefine PACKAGE_TARNAME ""
/* Define to the home page for this package. */
#cmakedefine PACKAGE_URL ""
/* Define to the version of this package. */
#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@"
/* Define to 1 if you have the ANSI C header files. */
#cmakedefine STDC_HEADERS 1
/* Define to 1 if sys/ethernet.h declares `ether_ntohost' */
#cmakedefine SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST 1
/* define if you have ether_ntohost() and it works */
#cmakedefine USE_ETHER_NTOHOST 1
/* Define if you enable support for libsmi */
#cmakedefine USE_LIBSMI 1
/* define if should chroot when dropping privileges */
#cmakedefine WITH_CHROOT "@WITH_CHROOT@"
/* define if should drop privileges by default */
#cmakedefine WITH_USER "@WITH_USER@"
/* define on AIX to get certain functions */
#cmakedefine _SUN 1
/* to handle Ultrix compilers that don't support const in prototypes */
#cmakedefine const 1
/* Define as token for inline if inlining supported */
#cmakedefine inline 1
/* Define to `uint16_t' if u_int16_t not defined. */
#cmakedefine u_int16_t 1
/* Define to `uint32_t' if u_int32_t not defined. */
#cmakedefine u_int32_t 1
/* Define to `uint64_t' if u_int64_t not defined. */
#cmakedefine u_int64_t 1
/* Define to `uint8_t' if u_int8_t not defined. */
#cmakedefine u_int8_t 1
/* Define to the type of an unsigned integer type wide enough to hold a
pointer, if such a type exists, and if the system does not define it. */
#cmakedefine uintptr_t 1

151
compiler-tests.h Normal file
View File

@ -0,0 +1,151 @@
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Computer Systems
* Engineering Group at Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef nd_compiler_tests_h
#define nd_compiler_tests_h
/*
* This was introduced by Clang:
*
* https://clang.llvm.org/docs/LanguageExtensions.html#has-attribute
*
* in some version (which version?); it has been picked up by GCC 5.0.
*/
#ifndef __has_attribute
/*
* It's a macro, so you can check whether it's defined to check
* whether it's supported.
*
* If it's not, define it to always return 0, so that we move on to
* the fallback checks.
*/
#define __has_attribute(x) 0
#endif
/*
* Note that the C90 spec's "6.8.1 Conditional inclusion" and the
* C99 spec's and C11 spec's "6.10.1 Conditional inclusion" say:
*
* Prior to evaluation, macro invocations in the list of preprocessing
* tokens that will become the controlling constant expression are
* replaced (except for those macro names modified by the defined unary
* operator), just as in normal text. If the token "defined" is
* generated as a result of this replacement process or use of the
* "defined" unary operator does not match one of the two specified
* forms prior to macro replacement, the behavior is undefined.
*
* so you shouldn't use defined() in a #define that's used in #if or
* #elif. Some versions of Clang, for example, will warn about this.
*
* Instead, we check whether the pre-defined macros for particular
* compilers are defined and, if not, define the "is this version XXX
* or a later version of this compiler" macros as 0.
*/
/*
* Check whether this is GCC major.minor or a later release, or some
* compiler that claims to be "just like GCC" of that version or a
* later release.
*/
#if ! defined(__GNUC__)
#define ND_IS_AT_LEAST_GNUC_VERSION(major, minor) 0
#else
#define ND_IS_AT_LEAST_GNUC_VERSION(major, minor) \
(__GNUC__ > (major) || \
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
#endif
/*
* Check whether this is Sun C/SunPro C/Oracle Studio major.minor
* or a later release.
*
* The version number in __SUNPRO_C is encoded in hex BCD, with the
* uppermost hex digit being the major version number, the next
* one or two hex digits being the minor version number, and
* the last digit being the patch version.
*
* It represents the *compiler* version, not the product version;
* see
*
* https://sourceforge.net/p/predef/wiki/Compilers/
*
* for a partial mapping, which we assume continues for later
* 12.x product releases.
*/
#if ! defined(__SUNPRO_C)
#define ND_IS_AT_LEAST_SUNC_VERSION(major,minor) 0
#else
#define ND_SUNPRO_VERSION_TO_BCD(major, minor) \
(((minor) >= 10) ? \
(((major) << 12) | (((minor)/10) << 8) | (((minor)%10) << 4)) : \
(((major) << 8) | ((minor) << 4)))
#define ND_IS_AT_LEAST_SUNC_VERSION(major,minor) \
(__SUNPRO_C >= ND_SUNPRO_VERSION_TO_BCD((major), (minor)))
#endif
/*
* Check whether this is IBM XL C major.minor or a later release.
*
* The version number in __xlC__ has the major version in the
* upper 8 bits and the minor version in the lower 8 bits.
*/
#if ! defined(__xlC__)
#define ND_IS_AT_LEAST_XL_C_VERSION(major,minor) 0
#else
#define ND_IS_AT_LEAST_XL_C_VERSION(major, minor) \
(__xlC__ >= (((major) << 8) | (minor)))
#endif
/*
* Check whether this is HP aC++/HP C major.minor or a later release.
*
* The version number in __HP_aCC is encoded in zero-padded decimal BCD,
* with the "A." stripped off, the uppermost two decimal digits being
* the major version number, the next two decimal digits being the minor
* version number, and the last two decimal digits being the patch version.
* (Strip off the A., remove the . between the major and minor version
* number, and add two digits of patch.)
*/
#if ! defined(__HP_aCC)
#define ND_IS_AT_LEAST_HP_C_VERSION(major,minor) 0
#else
#define ND_IS_AT_LEAST_HP_C_VERSION(major,minor) \
(__HP_aCC >= ((major)*10000 + (minor)*100))
#endif
#endif /* nd_funcattrs_h */

685
config.guess vendored Normal file → Executable file

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
/* config.h.in. Generated from configure.in by autoheader. */
/* config.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if arpa/inet.h declares `ether_ntohost' */
#undef ARPA_INET_H_DECLARES_ETHER_NTOHOST
/* define if you want to build the possibly-buggy SMB printer */
#undef ENABLE_SMB
/* Define to 1 if you have the `alarm' function. */
#undef HAVE_ALARM
/* Define to 1 if you have the `bpf_dump' function. */
#undef HAVE_BPF_DUMP
@ -27,19 +27,18 @@
/* Casper support available */
#undef HAVE_CASPER
/* Define to 1 if you have the declaration of `ether_ntohost', and to 0 if you
don't. */
/* Define to 1 if you have the declaration of `ether_ntohost' */
#undef HAVE_DECL_ETHER_NTOHOST
/* define if you have the dnet_htoa function */
#undef HAVE_DNET_HTOA
/* Define to 1 if you have the `ether_ntohost' function. */
#undef HAVE_ETHER_NTOHOST
/* Define to 1 if you have the `EVP_CIPHER_CTX_new' function. */
#undef HAVE_EVP_CIPHER_CTX_NEW
/* Define to 1 if you have the `EVP_DecryptInit_ex' function. */
#undef HAVE_EVP_DECRYPTINIT_EX
/* Define to 1 if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
@ -52,6 +51,9 @@
/* define if you have getrpcbynumber() */
#undef HAVE_GETRPCBYNUMBER
/* Define to 1 if you have the `getservent' function. */
#undef HAVE_GETSERVENT
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
@ -67,17 +69,8 @@
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the <netdnet/dnetdb.h> header file. */
#undef HAVE_NETDNET_DNETDB_H
/* define if you have a dnet_htoa declaration in <netdnet/dnetdb.h> */
#undef HAVE_NETDNET_DNETDB_H_DNET_HTOA
/* Define to 1 if you have the <netinet/ether.h> header file. */
#undef HAVE_NETINET_ETHER_H
/* Define to 1 if you have the <netinet/if_ether.h> header file. */
#undef HAVE_NETINET_IF_ETHER_H
/* Define to 1 if you have the <net/if.h> header file. */
#undef HAVE_NET_IF_H
/* Define to 1 if you have the <net/if_pflog.h> header file. */
#undef HAVE_NET_IF_PFLOG_H
@ -97,9 +90,6 @@
/* if there's an os_proto.h for this platform, to use additional prototypes */
#undef HAVE_OS_PROTO_H
/* Define to 1 if you have the <pcap/bluetooth.h> header file. */
#undef HAVE_PCAP_BLUETOOTH_H
/* Define to 1 if you have the `pcap_breakloop' function. */
#undef HAVE_PCAP_BREAKLOOP
@ -118,12 +108,18 @@
/* Define to 1 if you have the `pcap_dump_flush' function. */
#undef HAVE_PCAP_DUMP_FLUSH
/* define if libpcap has pcap_dump_ftell() */
/* Define to 1 if you have the `pcap_dump_ftell' function. */
#undef HAVE_PCAP_DUMP_FTELL
/* Define to 1 if you have the `pcap_dump_ftell64' function. */
#undef HAVE_PCAP_DUMP_FTELL64
/* Define to 1 if you have the `pcap_findalldevs' function. */
#undef HAVE_PCAP_FINDALLDEVS
/* Define to 1 if you have the `pcap_findalldevs_ex' function. */
#undef HAVE_PCAP_FINDALLDEVS_EX
/* Define to 1 if you have the `pcap_free_datalinks' function. */
#undef HAVE_PCAP_FREE_DATALINKS
@ -136,8 +132,11 @@
/* define if libpcap has pcap_list_datalinks() */
#undef HAVE_PCAP_LIST_DATALINKS
/* Define to 1 if you have the <pcap/nflog.h> header file. */
#undef HAVE_PCAP_NFLOG_H
/* Define to 1 if you have the `pcap_open' function. */
#undef HAVE_PCAP_OPEN
/* Define to 1 if you have the <pcap/pcap-inttypes.h> header file. */
#undef HAVE_PCAP_PCAP_INTTYPES_H
/* Define to 1 if you have the `pcap_setdirection' function. */
#undef HAVE_PCAP_SETDIRECTION
@ -160,9 +159,6 @@
/* Define to 1 if you have the `pcap_set_tstamp_type' function. */
#undef HAVE_PCAP_SET_TSTAMP_TYPE
/* Define to 1 if you have the <pcap/usb.h> header file. */
#undef HAVE_PCAP_USB_H
/* define if libpcap has pcap_version */
#undef HAVE_PCAP_VERSION
@ -178,18 +174,6 @@
/* Define to 1 if you have the `setlinebuf' function. */
#undef HAVE_SETLINEBUF
/* Define to 1 if you have the `sigaction' function. */
#undef HAVE_SIGACTION
/* Define to 1 if you have the `sigset' function. */
#undef HAVE_SIGSET
/* Define to 1 if you have the `snprintf' function. */
#undef HAVE_SNPRINTF
/* if struct sockaddr has the sa_len member */
#undef HAVE_SOCKADDR_SA_LEN
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
@ -235,27 +219,18 @@
/* Define to 1 if you have the `vfork' function. */
#undef HAVE_VFORK
/* Define to 1 if you have the `vfprintf' function. */
#undef HAVE_VFPRINTF
/* Define to 1 if you have the `vsnprintf' function. */
#undef HAVE_VSNPRINTF
/* define if libpcap has yydebug */
#undef HAVE_YYDEBUG
/* define if your compiler has __attribute__ */
#undef HAVE___ATTRIBUTE__
/* if unaligned access fails */
#undef LBL_ALIGN
/* Define to 1 if netinet/ether.h declares `ether_ntohost' */
#undef NETINET_ETHER_H_DECLARES_ETHER_NTOHOST
/* Define to 1 if netinet/if_ether.h declares `ether_ntohost' */
#undef NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST
/* Define to 1 if net/ethernet.h declares `ether_ntohost' */
#undef NET_ETHERNET_H_DECLARES_ETHER_NTOHOST
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
@ -274,29 +249,11 @@
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* define if the platform doesn't define PRId64 */
#undef PRId64
/* define if the platform doesn't define PRIo64 */
#undef PRIo64
/* define if the platform doesn't define PRIx64 */
#undef PRIu64
/* define if the platform doesn't define PRIu64 */
#undef PRIx64
/* Define as the return type of signal handlers (`int' or `void'). */
#undef RETSIGTYPE
/* return value of signal handlers */
#undef RETSIGVAL
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#undef TIME_WITH_SYS_TIME
/* Define to 1 if sys/ethernet.h declares `ether_ntohost' */
#undef SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST
/* define if you have ether_ntohost() and it works */
#undef USE_ETHER_NTOHOST
@ -310,60 +267,15 @@
/* define if should drop privileges by default */
#undef WITH_USER
/* get BSD semantics on Irix */
#undef _BSD_SIGNALS
/* define on AIX to get certain functions */
#undef _SUN
/* Define for Solaris 2.5.1 so the uint32_t typedef from <sys/synch.h>,
<pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
#define below would cause a syntax error. */
#undef _UINT32_T
/* Define for Solaris 2.5.1 so the uint64_t typedef from <sys/synch.h>,
<pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
#define below would cause a syntax error. */
#undef _UINT64_T
/* Define for Solaris 2.5.1 so the uint8_t typedef from <sys/synch.h>,
<pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
#define below would cause a syntax error. */
#undef _UINT8_T
/* define if your compiler allows __attribute__((format)) without a warning */
#undef __ATTRIBUTE___FORMAT_OK
/* define if your compiler allows __attribute__((format)) to be applied to
function pointers */
#undef __ATTRIBUTE___FORMAT_OK_FOR_FUNCTION_POINTERS
/* define if your compiler allows __attribute__((noreturn)) to be applied to
function pointers */
#undef __ATTRIBUTE___NORETURN_OK_FOR_FUNCTION_POINTERS
/* to handle Ultrix compilers that don't support const in prototypes */
#undef const
/* Define as token for inline if inlining supported */
#undef inline
/* Define to the type of a signed integer type of width exactly 16 bits if
such a type exists and the standard includes do not define it. */
#undef int16_t
/* Define to the type of a signed integer type of width exactly 32 bits if
such a type exists and the standard includes do not define it. */
#undef int32_t
/* Define to the type of a signed integer type of width exactly 64 bits if
such a type exists and the standard includes do not define it. */
#undef int64_t
/* Define to the type of a signed integer type of width exactly 8 bits if such
a type exists and the standard includes do not define it. */
#undef int8_t
/* Define to `uint16_t' if u_int16_t not defined. */
#undef u_int16_t
@ -376,22 +288,6 @@
/* Define to `uint8_t' if u_int8_t not defined. */
#undef u_int8_t
/* Define to the type of an unsigned integer type of width exactly 16 bits if
such a type exists and the standard includes do not define it. */
#undef uint16_t
/* Define to the type of an unsigned integer type of width exactly 32 bits if
such a type exists and the standard includes do not define it. */
#undef uint32_t
/* Define to the type of an unsigned integer type of width exactly 64 bits if
such a type exists and the standard includes do not define it. */
#undef uint64_t
/* Define to the type of an unsigned integer type of width exactly 8 bits if
such a type exists and the standard includes do not define it. */
#undef uint8_t
/* Define to the type of an unsigned integer type wide enough to hold a
pointer, if such a type exists, and if the system does not define it. */
#undef uintptr_t

1695
config.sub vendored Normal file → Executable file

File diff suppressed because it is too large Load Diff

3098
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -7,32 +7,31 @@ dnl
#
# See
#
# http://ftp.gnu.org/gnu/config/README
# https://ftp.gnu.org/gnu/config/README
#
# for the URLs to use to fetch new versions of config.guess and
# config.sub.
#
AC_PREREQ(2.61)
AC_INIT(tcpdump.c)
AC_PREREQ(2.64)
AC_INIT(tcpdump, m4_esyscmd_s([cat VERSION]))
AC_CONFIG_SRCDIR(tcpdump.c)
AC_CANONICAL_HOST
AC_LBL_C_INIT_BEFORE_CC(V_INCLS)
AC_PROG_CC
#
# Try to enable as many C99 features as we can.
# At minimum, we want C++/C99-style // comments.
#
AC_PROG_CC_C99
if test "$ac_cv_prog_cc_c99" = "no"; then
AC_MSG_WARN([The C compiler does not support C99; there may be compiler errors])
fi
AC_LBL_C_INIT(V_CCOPT, V_INCLS)
AC_LBL_C_INLINE
AC_C___ATTRIBUTE__
if test "$ac_cv___attribute__" = "yes"; then
AC_C___ATTRIBUTE___UNUSED
AC_C___ATTRIBUTE___NORETURN_FUNCTION_POINTER
AC_C___ATTRIBUTE___FORMAT
if test "$ac_cv___attribute___format" = "yes"; then
AC_C___ATTRIBUTE___FORMAT_FUNCTION_POINTER
fi
fi
AC_CHECK_HEADERS(fcntl.h rpc/rpc.h rpc/rpcent.h netdnet/dnetdb.h)
AC_CHECK_HEADERS(fcntl.h rpc/rpc.h rpc/rpcent.h net/if.h)
AC_CHECK_HEADERS(net/pfvar.h, , , [#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>])
@ -45,33 +44,12 @@ if test "$ac_cv_header_net_pfvar_h" = yes; then
LOCALSRC="print-pflog.c $LOCALSRC"
fi
fi
AC_CHECK_HEADERS(netinet/if_ether.h, , , [#include <sys/types.h>
#include <sys/socket.h>])
if test "$ac_cv_header_netinet_if_ether_h" != yes; then
#
# The simple test didn't work.
# Do we need to include <net/if.h> first?
# Unset ac_cv_header_netinet_if_ether_h so we don't
# treat the previous failure as a cached value and
# suppress the next test.
#
AC_MSG_NOTICE([Rechecking with some additional includes])
unset ac_cv_header_netinet_if_ether_h
AC_CHECK_HEADERS(netinet/if_ether.h, , , [#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
struct mbuf;
struct rtentry;
#include <net/if.h>])
fi
AC_HEADER_TIME
case "$host_os" in
darwin*)
AC_ARG_ENABLE(universal,
AC_HELP_STRING([--disable-universal],[don't build universal on OS X]))
AC_HELP_STRING([--disable-universal],[don't build universal on macOS]))
if test "$enable_universal" != "no"; then
case "$host_os" in
@ -174,7 +152,6 @@ AC_ARG_ENABLE(smb,
enableval=yes)
case "$enableval" in
yes) AC_MSG_RESULT(yes)
AC_WARN([The SMB printer may have exploitable buffer overflows!!!])
AC_DEFINE(ENABLE_SMB, 1,
[define if you want to build the possibly-buggy SMB printer])
LOCALSRC="print-smb.c smbutil.c $LOCALSRC"
@ -221,10 +198,19 @@ AC_ARG_WITH(sandbox-capsicum,
# XXX - do we need to check for all of them, or are there some that, if
# present, imply others are present?
#
if test ! -z "$with_sandbox-capsicum" && test "$with_sandbox-capsicum" != "no" ; then
AC_CHECK_FUNCS(cap_enter cap_rights_limit cap_ioctls_limit openat,
ac_lbl_capsicum_function_seen=yes,
ac_lbl_capsicum_function_not_seen=yes)
if test ! -z "$with_sandbox_capsicum" && test "$with_sandbox_capsicum" != "no" ; then
#
# First, make sure we have the required header.
#
AC_CHECK_HEADER(sys/capsicum.h,
[
#
# We do; now make sure we have the required functions.
#
AC_CHECK_FUNCS(cap_enter cap_rights_limit cap_ioctls_limit openat,
ac_lbl_capsicum_function_seen=yes,
ac_lbl_capsicum_function_not_seen=yes)
])
AC_CHECK_LIB(casper, cap_init, LIBS="$LIBS -lcasper")
AC_CHECK_LIB(cap_dns, cap_gethostbyaddr, LIBS="$LIBS -lcap_dns")
fi
@ -263,8 +249,12 @@ AC_COMPILE_IFELSE(
[[
/* AF_INET6 available check */
#include <sys/types.h>
#ifdef _WIN32
#include <ws2tcpip.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#ifdef AF_INET6
void
foo(struct in6_addr *addr)
@ -395,31 +385,17 @@ if test "$ipv6" = "yes" -a "$ipv6lib" != "none"; then
fi
fi
AC_CACHE_CHECK([for dnet_htoa declaration in netdnet/dnetdb.h],
[td_cv_decl_netdnet_dnetdb_h_dnet_htoa],
[AC_EGREP_HEADER(dnet_htoa, netdnet/dnetdb.h,
td_cv_decl_netdnet_dnetdb_h_dnet_htoa=yes,
td_cv_decl_netdnet_dnetdb_h_dnet_htoa=no)])
if test "$td_cv_decl_netdnet_dnetdb_h_dnet_htoa" = yes; then
AC_DEFINE(HAVE_NETDNET_DNETDB_H_DNET_HTOA, 1,
[define if you have a dnet_htoa declaration in <netdnet/dnetdb.h>])
fi
AC_REPLACE_FUNCS(vfprintf strlcat strlcpy strdup strsep getopt_long)
AC_REPLACE_FUNCS(strlcat strlcpy strdup strsep getservent getopt_long)
AC_CHECK_FUNCS(fork vfork strftime)
AC_CHECK_FUNCS(setlinebuf alarm)
AC_CHECK_FUNCS(setlinebuf)
needsnprintf=no
AC_CHECK_FUNCS(vsnprintf snprintf,,
[needsnprintf=yes])
if test $needsnprintf = yes; then
AC_LIBOBJ(snprintf)
fi
AC_LBL_TYPE_SIGNAL
AC_SEARCH_LIBS(dnet_htoa, dnet,
AC_DEFINE(HAVE_DNET_HTOA, 1, [define if you have the dnet_htoa function]))
#
# Make sure we have vsnprintf() and snprintf(); we require them.
#
AC_CHECK_FUNC(vsnprintf,,
AC_MSG_ERROR([vsnprintf() is required but wasn't found]))
AC_CHECK_FUNC(snprintf,,
AC_MSG_ERROR([snprintf() is required but wasn't found]))
AC_CHECK_LIB(rpc, main) dnl It's unclear why we might need -lrpc
@ -435,11 +411,12 @@ AC_LBL_LIBPCAP(V_PCAPDEP, V_INCLS)
#
# You are in a twisty little maze of UN*Xes, all different.
# Some might not have ether_ntohost().
# Some might have it, but not declare it in any header file.
# Some might have it, but declare it in <netinet/if_ether.h>.
# Some might have it, but declare it in <netinet/ether.h>
# (And some might have it but document it as something declared in
# <netinet/ethernet.h>, although <netinet/if_ether.h> appears to work.)
# Some might have it and declare it in <net/ethernet.h>.
# Some might have it and declare it in <netinet/ether.h>
# Some might have it and declare it in <sys/ethernet.h>.
# Some might have it and declare it in <arpa/inet.h>.
# Some might have it and declare it in <netinet/if_ether.h>.
# Some might have it and not declare it in any header file.
#
# Before you is a C compiler.
#
@ -471,12 +448,114 @@ AC_CHECK_FUNCS(ether_ntohost, [
if test "$ac_cv_func_ether_ntohost" = yes -a \
"$ac_cv_buggy_ether_ntohost" = "no"; then
#
# OK, we have ether_ntohost(). Do we have <netinet/if_ether.h>?
# OK, we have ether_ntohost(). Is it declared in <net/ethernet.h>?
#
if test "$ac_cv_header_netinet_if_ether_h" = yes; then
# This test fails if we don't have <net/ethernet.h> or if we do
# but it doesn't declare ether_ntohost().
#
AC_CHECK_DECL(ether_ntohost,
[
AC_DEFINE(NET_ETHERNET_H_DECLARES_ETHER_NTOHOST,,
[Define to 1 if net/ethernet.h declares `ether_ntohost'])
],,
[
#include <net/ethernet.h>
])
#
# Did that succeed?
#
if test "$ac_cv_have_decl_ether_ntohost" != yes; then
#
# Yes. Does it declare ether_ntohost()?
# No, how about <netinet/ether.h>, as on Linux?
#
# This test fails if we don't have <netinet/ether.h>
# or if we do but it doesn't declare ether_ntohost().
#
# Unset ac_cv_have_decl_ether_ntohost so we don't
# treat the previous failure as a cached value and
# suppress the next test.
#
unset ac_cv_have_decl_ether_ntohost
AC_CHECK_DECL(ether_ntohost,
[
AC_DEFINE(NETINET_ETHER_H_DECLARES_ETHER_NTOHOST,,
[Define to 1 if netinet/ether.h declares `ether_ntohost'])
],,
[
#include <netinet/ether.h>
])
fi
#
# Did that succeed?
#
if test "$ac_cv_have_decl_ether_ntohost" != yes; then
#
# No, how about <sys/ethernet.h>, as on Solaris 10
# and later?
#
# This test fails if we don't have <sys/ethernet.h>
# or if we do but it doesn't declare ether_ntohost().
#
# Unset ac_cv_have_decl_ether_ntohost so we don't
# treat the previous failure as a cached value and
# suppress the next test.
#
unset ac_cv_have_decl_ether_ntohost
AC_CHECK_DECL(ether_ntohost,
[
AC_DEFINE(SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST,,
[Define to 1 if sys/ethernet.h declares `ether_ntohost'])
],,
[
#include <sys/ethernet.h>
])
fi
#
# Did that succeed?
#
if test "$ac_cv_have_decl_ether_ntohost" != yes; then
#
# No, how about <arpa/inet.h>, as in AIX?
#
# This test fails if we don't have <arpa/inet.h>
# (if we have ether_ntohost(), we should have
# networking, and if we have networking, we should
# have <arpa/inet.h>) or if we do but it doesn't
# declare ether_ntohost().
#
# Unset ac_cv_have_decl_ether_ntohost so we don't
# treat the previous failure as a cached value and
# suppress the next test.
#
unset ac_cv_have_decl_ether_ntohost
AC_CHECK_DECL(ether_ntohost,
[
AC_DEFINE(ARPA_INET_H_DECLARES_ETHER_NTOHOST,,
[Define to 1 if arpa/inet.h declares `ether_ntohost'])
],,
[
#include <arpa/inet.h>
])
fi
#
# Did that succeed?
#
if test "$ac_cv_have_decl_ether_ntohost" != yes; then
#
# No, how about <netinet/if_ether.h>?
# On some platforms, it requires <net/if.h> and
# <netinet/in.h>, and we always include it with
# both of them, so test it with both of them.
#
# This test fails if we don't have <netinet/if_ether.h>
# and the headers we include before it, or if we do but
# <netinet/if_ether.h> doesn't declare ether_hostton().
#
# Unset ac_cv_have_decl_ether_ntohost so we don't
# treat the previous failure as a cached value and
# suppress the next test.
#
unset ac_cv_have_decl_ether_ntohost
AC_CHECK_DECL(ether_ntohost,
[
AC_DEFINE(NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST,,
@ -485,76 +564,45 @@ if test "$ac_cv_func_ether_ntohost" = yes -a \
[
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
struct mbuf;
struct rtentry;
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
])
fi
#
# Did that succeed?
# After all that, is ether_ntohost() declared?
#
if test "$ac_cv_have_decl_ether_ntohost" != yes; then
if test "$ac_cv_have_decl_ether_ntohost" = yes; then
#
# No, how about <netinet/ether.h>, as on Linux?
# Yes.
#
AC_CHECK_HEADERS(netinet/ether.h)
if test "$ac_cv_header_netinet_ether_h" = yes; then
#
# We have it - does it declare ether_ntohost()?
# Unset ac_cv_have_decl_ether_ntohost so we don't
# treat the previous failure as a cached value and
# suppress the next test.
#
unset ac_cv_have_decl_ether_ntohost
AC_CHECK_DECL(ether_ntohost,
[
AC_DEFINE(NETINET_ETHER_H_DECLARES_ETHER_NTOHOST,,
[Define to 1 if netinet/ether.h declares `ether_ntohost'])
],,
[
#include <netinet/ether.h>
])
fi
fi
#
# Is ether_ntohost() declared?
#
if test "$ac_cv_have_decl_ether_ntohost" != yes; then
AC_DEFINE(HAVE_DECL_ETHER_NTOHOST, 1,
[Define to 1 if you have the declaration of `ether_ntohost'])
else
#
# No, we'll have to declare it ourselves.
# Do we have "struct ether_addr"?
# Do we have "struct ether_addr" if we include
# <netinet/if_ether.h>?
#
AC_CHECK_TYPES(struct ether_addr,,,
[
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
struct mbuf;
struct rtentry;
#include <net/if.h>
#include <netinet/if_ether.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
])
AC_DEFINE(HAVE_DECL_ETHER_NTOHOST, 0,
[Define to 1 if you have the declaration of `ether_ntohost', and to 0 if you
don't.])
else
AC_DEFINE(HAVE_DECL_ETHER_NTOHOST, 1,
[Define to 1 if you have the declaration of `ether_ntohost', and to 0 if you
don't.])
fi
fi
# libdlpi is needed for Solaris 11 and later.
AC_CHECK_LIB(dlpi, dlpi_walk, LIBS="$LIBS -ldlpi" LDFLAGS="-L/lib $LDFLAGS", ,-L/lib)
dnl
dnl Check for "pcap_list_datalinks()", "pcap_set_datalink()",
dnl and "pcap_datalink_name_to_val()", and use substitute versions
dnl if they're not present.
dnl Check for "pcap_list_datalinks()" and use a substitute version if
dnl it's not present. If it is present, check for "pcap_free_datalinks()";
dnl if it's not present, we don't replace it for now. (We could do so
dnl on UN*X, but not on Windows, where hilarity ensues if a program
dnl built with one version of the MSVC support library tries to free
dnl something allocated by a library built with another version of
dnl the MSVC support library.)
dnl
AC_CHECK_FUNC(pcap_list_datalinks,
[
@ -565,7 +613,13 @@ AC_CHECK_FUNC(pcap_list_datalinks,
[
AC_LIBOBJ(datalinks)
])
AC_CHECK_FUNCS(pcap_set_datalink)
dnl
dnl Check for "pcap_datalink_name_to_val()", and use a substitute
dnl version if it's not present. If it is present, check for
dnl "pcap_datalink_val_to_description()", and if we don't have it,
dnl use a substitute version.
dnl
AC_CHECK_FUNC(pcap_datalink_name_to_val,
[
AC_DEFINE(HAVE_PCAP_DATALINK_NAME_TO_VAL, 1,
@ -581,6 +635,13 @@ AC_CHECK_FUNC(pcap_datalink_name_to_val,
AC_LIBOBJ(dlnames)
])
dnl
dnl Check for "pcap_set_datalink()"; you can't substitute for it if
dnl it's absent (it has hooks into libpcap), so just define the
dnl HAVE_ value if it's there.
dnl
AC_CHECK_FUNCS(pcap_set_datalink)
dnl
dnl Check for "pcap_breakloop()"; you can't substitute for it if
dnl it's absent (it has hooks into the live capture routines),
@ -588,17 +649,6 @@ dnl so just define the HAVE_ value if it's there.
dnl
AC_CHECK_FUNCS(pcap_breakloop)
dnl
dnl Check for "pcap_dump_ftell()" and use a substitute version
dnl if it's not present.
dnl
AC_CHECK_FUNC(pcap_dump_ftell,
AC_DEFINE(HAVE_PCAP_DUMP_FTELL, 1,
[define if libpcap has pcap_dump_ftell()]),
[
AC_LIBOBJ(pcap_dump_ftell)
])
#
# Do we have the new open API? Check for pcap_create, and assume that,
# if we do, we also have pcap_activate() and the other new routines
@ -622,17 +672,18 @@ fi
# Check for a miscellaneous collection of functions which we use
# if we have them.
#
AC_CHECK_FUNCS(pcap_findalldevs pcap_dump_flush pcap_lib_version pcap_setdirection pcap_set_immediate_mode)
AC_CHECK_FUNCS(pcap_findalldevs)
if test $ac_cv_func_pcap_findalldevs = "yes" ; then
dnl Check for Mac OS X, which may ship pcap.h from 0.6 but libpcap may
dnl be 0.8; this means that lib has pcap_findalldevs but header doesn't
dnl have pcap_if_t.
dnl Check for libpcap having pcap_findalldevs() but the pcap.h header
dnl not having pcap_if_t; some versions of Mac OS X shipped with pcap.h
dnl from 0.6 and libpcap 0.8, so that libpcap had pcap_findalldevs but
dnl pcap.h didn't have pcap_if_t.
savedcppflags="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $V_INCLS"
AC_CHECK_TYPES(pcap_if_t, , , [#include <pcap.h>])
CPPFLAGS="$savedcppflags"
fi
AC_CHECK_FUNCS(pcap_dump_flush pcap_lib_version)
if test $ac_cv_func_pcap_lib_version = "no" ; then
AC_MSG_CHECKING(whether pcap_version is defined by libpcap)
AC_TRY_LINK([],
@ -650,6 +701,9 @@ if test $ac_cv_func_pcap_lib_version = "no" ; then
AC_MSG_RESULT(no)
fi
fi
AC_CHECK_FUNCS(pcap_setdirection pcap_set_immediate_mode pcap_dump_ftell64)
AC_CHECK_FUNCS(pcap_open pcap_findalldevs_ex)
AC_REPLACE_FUNCS(pcap_dump_ftell)
#
# Check for special debugging functions
@ -757,25 +811,21 @@ if test -f /dev/bpf0 ; then
V_GROUP=bpf
fi
#
# Make sure we have definitions for all the C99 specified-width types
# (regardless of whether the environment is a C99 environment or not).
#
AC_TYPE_INT8_T
AC_TYPE_INT16_T
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_TYPE_UINT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
#
# Make sure we have a definition for C99's uintptr_t (regardless of
# whether the environment is a C99 environment or not).
#
AC_TYPE_UINTPTR_T
#
# Check whether we have pcap/pcap-inttypes.h.
# If we do, we use that to get the C99 types defined.
#
savedcppflags="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $V_INCLS"
AC_CHECK_HEADERS(pcap/pcap-inttypes.h)
CPPFLAGS="$savedcppflags"
#
# Define the old BSD specified-width types in terms of the C99 types;
# we may need them with libpcap include files.
@ -805,88 +855,11 @@ AC_CHECK_TYPE([u_int64_t], ,
#include <sys/types.h>
])
#
# Check for <inttypes.h>
#
AC_CHECK_HEADERS(inttypes.h,
[
#
# OK, we have inttypes.h, but does it define all the PRI[doxu]64 macros?
# Some systems have an inttypes.h that doesn't define all of them.
#
AC_MSG_CHECKING([[whether inttypes.h defines the PRI[doxu]64 macros]])
AC_COMPILE_IFELSE(
[
AC_LANG_SOURCE(
[[
#include <inttypes.h>
#include <stdio.h>
#include <sys/types.h>
main()
{
printf("%" PRId64 "\n", (uint64_t)1);
printf("%" PRIo64 "\n", (uint64_t)1);
printf("%" PRIx64 "\n", (uint64_t)1);
printf("%" PRIu64 "\n", (uint64_t)1);
}
]])
],
[
AC_MSG_RESULT(yes)
ac_lbl_inttypes_h_defines_formats=yes
],
[
AC_MSG_RESULT(no)
ac_lbl_inttypes_h_defines_formats=no
])
],
[
#
# We don't have inttypes.h, so it obviously can't define those
# macros.
#
ac_lbl_inttypes_h_defines_formats=no
])
if test "$ac_lbl_inttypes_h_defines_formats" = no; then
AC_LBL_CHECK_64BIT_FORMAT(l,
[
AC_LBL_CHECK_64BIT_FORMAT(ll,
[
AC_LBL_CHECK_64BIT_FORMAT(L,
[
AC_LBL_CHECK_64BIT_FORMAT(q,
[
AC_MSG_ERROR([neither %llx nor %Lx nor %qx worked on a 64-bit integer])
])
])
])
])
fi
#
# Check for some headers introduced in later versions of libpcap
# and used by some printers.
#
# Those headers use the {u_}intN_t types, so we must do this after
# we check for what's needed to get them defined.
#
savedcppflags="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $V_INCLS"
AC_CHECK_HEADERS(pcap/bluetooth.h,,,[#include "netdissect-stdinc.h"])
AC_CHECK_HEADERS(pcap/nflog.h,,,[#include "netdissect-stdinc.h"])
AC_CHECK_HEADERS(pcap/usb.h,,,[#include "netdissect-stdinc.h"])
CPPFLAGS="$savedcppflags"
AC_PROG_RANLIB
AC_CHECK_TOOL([AR], [ar])
AC_LBL_DEVEL(V_CCOPT)
AC_LBL_SOCKADDR_SA_LEN
AC_LBL_UNALIGNED_ACCESS
# Check for OpenSSL/libressl libcrypto
AC_MSG_CHECKING(whether to use OpenSSL/libressl libcrypto)
# Specify location for both includes and libraries.
@ -936,7 +909,7 @@ if test "$want_libcrypto" != "no"; then
# El Capitan, probably because they don't want you writing
# nasty portable code that could run on other UN*Xes, they
# want you writing code that uses their Shiny New Crypto
# Library and that only runs on OS X.
# Library and that only runs on macOS.
#
AC_CHECK_HEADER(openssl/crypto.h,
[
@ -944,12 +917,26 @@ if test "$want_libcrypto" != "no"; then
if test "$ac_cv_lib_crypto_DES_cbc_encrypt" = "yes"; then
AC_CHECK_HEADERS(openssl/evp.h)
#
# OK, do we have EVP_CIPHER_CTX_new?
# OK, then:
#
# 1) do we have EVP_CIPHER_CTX_new?
# If so, we use it to allocate an
# EVP_CIPHER_CTX, as EVP_CIPHER_CTX may be
# opaque; otherwise, we allocate it ourselves.
#
AC_CHECK_FUNCS(EVP_CIPHER_CTX_new)
# 2) do we have EVP_DecryptInit_ex()?
# If so, we use it, because we need to be
# able to make two "initialize the cipher"
# calls, one with the cipher and key, and
# one with the IV, and, as of OpenSSL 1.1,
# You Can't Do That with EVP_DecryptInit(),
# because a call to EVP_DecryptInit() will
# unconditionally clear the context, and
# if you don't supply a cipher, it'll
# clear the cipher, rendering the context
# unusable and causing a crash.
#
AC_CHECK_FUNCS(EVP_CIPHER_CTX_new EVP_DecryptInit_ex)
fi
])
fi
@ -1005,7 +992,7 @@ AC_CONFIG_HEADER(config.h)
AC_OUTPUT_COMMANDS([if test -f .devel; then
echo timestamp > stamp-h
cat Makefile-devel-adds >> Makefile
cat $srcdir/Makefile-devel-adds >> Makefile
make depend
fi])
AC_OUTPUT(Makefile tcpdump.1)

91
cpack.c
View File

@ -28,15 +28,17 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "extract.h"
#include "cpack.h"
#include "extract.h"
const uint8_t *
cpack_next_boundary(const uint8_t *buf, const uint8_t *p, size_t alignment)
@ -93,63 +95,126 @@ cpack_init(struct cpack_state *cs, const uint8_t *buf, size_t buflen)
/* Unpack a 64-bit unsigned integer. */
int
cpack_uint64(struct cpack_state *cs, uint64_t *u)
cpack_uint64(netdissect_options *ndo, struct cpack_state *cs, uint64_t *u)
{
const uint8_t *next;
if ((next = cpack_align_and_reserve(cs, sizeof(*u))) == NULL)
return -1;
*u = EXTRACT_LE_64BITS(next);
*u = GET_LE_U_8(next);
/* Move pointer past the uint64_t. */
cs->c_next = next + sizeof(*u);
return 0;
}
/* Unpack a 32-bit unsigned integer. */
/* Unpack a 64-bit signed integer. */
int
cpack_uint32(struct cpack_state *cs, uint32_t *u)
cpack_int64(netdissect_options *ndo, struct cpack_state *cs, int64_t *u)
{
const uint8_t *next;
if ((next = cpack_align_and_reserve(cs, sizeof(*u))) == NULL)
return -1;
*u = EXTRACT_LE_32BITS(next);
*u = GET_LE_S_8(next);
/* Move pointer past the int64_t. */
cs->c_next = next + sizeof(*u);
return 0;
}
/* Unpack a 32-bit unsigned integer. */
int
cpack_uint32(netdissect_options *ndo, struct cpack_state *cs, uint32_t *u)
{
const uint8_t *next;
if ((next = cpack_align_and_reserve(cs, sizeof(*u))) == NULL)
return -1;
*u = GET_LE_U_4(next);
/* Move pointer past the uint32_t. */
cs->c_next = next + sizeof(*u);
return 0;
}
/* Unpack a 16-bit unsigned integer. */
/* Unpack a 32-bit signed integer. */
int
cpack_uint16(struct cpack_state *cs, uint16_t *u)
cpack_int32(netdissect_options *ndo, struct cpack_state *cs, int32_t *u)
{
const uint8_t *next;
if ((next = cpack_align_and_reserve(cs, sizeof(*u))) == NULL)
return -1;
*u = EXTRACT_LE_16BITS(next);
*u = GET_LE_S_4(next);
/* Move pointer past the int32_t. */
cs->c_next = next + sizeof(*u);
return 0;
}
/* Unpack a 16-bit unsigned integer. */
int
cpack_uint16(netdissect_options *ndo, struct cpack_state *cs, uint16_t *u)
{
const uint8_t *next;
if ((next = cpack_align_and_reserve(cs, sizeof(*u))) == NULL)
return -1;
*u = GET_LE_U_2(next);
/* Move pointer past the uint16_t. */
cs->c_next = next + sizeof(*u);
return 0;
}
/* Unpack a 16-bit signed integer. */
int
cpack_int16(netdissect_options *ndo, struct cpack_state *cs, int16_t *u)
{
const uint8_t *next;
if ((next = cpack_align_and_reserve(cs, sizeof(*u))) == NULL)
return -1;
*u = GET_LE_S_2(next);
/* Move pointer past the int16_t. */
cs->c_next = next + sizeof(*u);
return 0;
}
/* Unpack an 8-bit unsigned integer. */
int
cpack_uint8(struct cpack_state *cs, uint8_t *u)
cpack_uint8(netdissect_options *ndo, struct cpack_state *cs, uint8_t *u)
{
/* No space left? */
if ((size_t)(cs->c_next - cs->c_buf) >= cs->c_len)
return -1;
*u = *cs->c_next;
*u = GET_U_1(cs->c_next);
/* Move pointer past the uint8_t. */
cs->c_next++;
return 0;
}
/* Unpack an 8-bit signed integer. */
int
cpack_int8(netdissect_options *ndo, struct cpack_state *cs, int8_t *u)
{
/* No space left? */
if ((size_t)(cs->c_next - cs->c_buf) >= cs->c_len)
return -1;
*u = GET_S_1(cs->c_next);
/* Move pointer past the int8_t. */
cs->c_next++;
return 0;
}

19
cpack.h
View File

@ -30,6 +30,8 @@
#ifndef _CPACK_H
#define _CPACK_H
#include "netdissect.h"
struct cpack_state {
const uint8_t *c_buf;
const uint8_t *c_next;
@ -38,19 +40,18 @@ struct cpack_state {
int cpack_init(struct cpack_state *, const uint8_t *, size_t);
int cpack_uint8(struct cpack_state *, uint8_t *);
int cpack_uint16(struct cpack_state *, uint16_t *);
int cpack_uint32(struct cpack_state *, uint32_t *);
int cpack_uint64(struct cpack_state *, uint64_t *);
int cpack_uint8(netdissect_options *, struct cpack_state *, uint8_t *);
int cpack_int8(netdissect_options *, struct cpack_state *, int8_t *);
int cpack_uint16(netdissect_options *, struct cpack_state *, uint16_t *);
int cpack_int16(netdissect_options *, struct cpack_state *, int16_t *);
int cpack_uint32(netdissect_options *, struct cpack_state *, uint32_t *);
int cpack_int32(netdissect_options *, struct cpack_state *, int32_t *);
int cpack_uint64(netdissect_options *, struct cpack_state *, uint64_t *);
int cpack_int64(netdissect_options *, struct cpack_state *, int64_t *);
const uint8_t *cpack_next_boundary(const uint8_t *buf, const uint8_t *p, size_t alignment);
const uint8_t *cpack_align_and_reserve(struct cpack_state *cs, size_t wordsize);
#define cpack_int8(__s, __p) cpack_uint8((__s), (uint8_t*)(__p))
#define cpack_int16(__s, __p) cpack_uint16((__s), (uint16_t*)(__p))
#define cpack_int32(__s, __p) cpack_uint32((__s), (uint32_t*)(__p))
#define cpack_int64(__s, __p) cpack_uint64((__s), (uint64_t*)(__p))
extern int cpack_advance(struct cpack_state *, const size_t);
#endif /* _CPACK_H */

185
doc/README.Win32.md Normal file
View File

@ -0,0 +1,185 @@
Building tcpdump on Windows with Visual Studio
==============================================
Unlike the UN*Xes on which libpcap can capture network traffic, Windows
has no network traffic capture mechanism that libpcap can use.
Therefore, libpcap requires a driver, and a library to access the
driver, provided by the Npcap or WinPcap projects.
Those projects include versions of libpcap built to use that driver and
library; these instructions are for people who want to build libpcap
source releases, or libpcap from the Git repository, as a replacement
for the version provided with Npcap or WinPcap.
Npcap and WinPcap SDK
---------------------
In order to build tcpdump, you will need to download Npcap and its
software development kit (SDK) or WinPcap and its software development
kit.
Npcap is currently being developed and maintained, and offers many
additional capabilities that WinPcap does not.
WinPcap is no longer being developed or maintained; it should be used
only if there is some other requirement to use it rather than Npcap,
such as a requirement to support versions of Windows earlier than
Windows Vista, which is the earliest version supported by Npcap.
Npcap and its SDK can be downloaded from its home page:
https://npcap.org
The SDK is a ZIP archive; create a folder on your C: drive, e.g.
C:\npcap-sdk, and put the contents of the ZIP archive into that folder.
The WinPcap installer can be downloaded from
https://www.winpcap.org/install/default.htm
and the WinPcap Developer's Kit can be downloaded from
https://www.winpcap.org/devel.htm
Required build tools
--------------------
The Developer's Kit is a ZIP archive; it contains a folder named
WpdPack, which you should place on your C: drive, e.g. C:\WpdPack.
Building tcpdumpp on Windows requires Visual Studio 2015 or later. The
Community Edition of Visual Studio can be downloaded at no cost from
https://visualstudio.microsoft.com
Additional tools are also required. Chocolatey is a package manager for
Windows with which those tools, and other tools, can be installed; it
can be downloaded from
https://chocolatey.org
It is a command-line tool; a GUI tool, Chocolatey GUI, is provided as a
Chocolatey package, which can be installed from the command line:
choco install chocolateygui
For convenience, the "choco install" command can be run with the "-y"
flag, forcing it to automatically answer all questions asked of the user
with "yes":
choco install -y chocolateygui
The required tools are:
### CMake ###
libpcap does not provide supported project files for Visual Studio
(there are currently unsupported project files provided, but we do not
guarantee that they will work or that we will continue to provide them).
It does provide files for CMake, which is a cross-platform tool that
runs on UN*Xes and on Windows and that can generate project files for
UN*X Make, the Ninja build system, and Visual Studio, among other build
systems.
Visual Studio 2015 does not provide CMake; an installer can be
downloaded from
https://cmake.org/download/
When you run the installer, you should choose to add CMake to the system
PATH for all users and to create the desktop icon.
CMake can also be installed as the Chocolatey package "cmake":
choco install -y cmake
Visual Studio 2017 and later provide CMake, so you will not need to
install CMake if you have installed Visual Studio 2017 or later. They
include built-in support for CMake-based projects:
https://devblogs.microsoft.com/cppblog/cmake-support-in-visual-studio/
For Visual Studio 2017, make sure "Visual C++ tools for CMake" is
installed; for Visual Studio 2019, make sure "C++ CMake tools for
Windows" is intalled.
Git
---
An optional tool, required only if you will be building from a Git
repository rather than from a release source tarball, is Git. Git is
provided as an optional installation component, "Git for Windows", with
Visual Studio 2017 and later.
Building from the Visual Studio GUI
-----------------------------------
### Visual Studio 2017 ###
Open the folder containing the libpcap source with Open > Folder.
Visual Studio will run CMake; however, you will need to indicate where
the Npcap or WinPcap SDK is installed.
To do this, go to Project > "Change CMake Settings" > tcpdump and:
Choose which configuration type to build, if you don't want the default
Debug build.
In the CMakeSettings.json tab, change cmakeCommandArgs to include
-DPacket_ROOT={path-to-sdk}
where {path-to-sdk} is the path of the directory containing the Npcap or
WinPcap SDK. Note that backslashes in the path must be specified as two
backslashes.
Save the configuration changes with File > "Save CMakeSettings.json" or
with control-S.
Visual Studio will then re-run CMake. If that completes without errors,
you can build with CMake > "Build All".
### Visual Studio 2019 ###
Open the folder containing the libpcap source with Open > Folder.
Visual Studio will run CMake; however, you will need to indicate where
the Npcap or WinPcap SDK is installed.
To do this, go to Project > "CMake Settings for tcpdump" and:
Choose which configuration type to build, if you don't want the default
Debug build.
Scroll down to "Cmake variables and cache", scroll through the list
looking for the entry for Packet_ROOT, and either type in the path of
the directory containing the Npcap or WinPcap SDK or use the "Browse..."
button to browse for that directory.
Save the configuration changes with File > "Save CMakeSettings.json" or
with control-S.
Visual Studio will then re-run CMake. If that completes without errors,
you can build with Build > "Build All".
Building from the command line
------------------------------
Start the appropriate Native Tools command line prompt.
Change to the directory into which you want to build tcpdump, possibly
after creating it first. One choice is to create it as a subdirectory
of the tcpdump source directory.
Run the command
cmake "-DPacket_ROOT={path-to-sdk}" {path-to-tcpdump-source}
where {path-to-sdk} is the path of the directory containing the Npcap or
WinPcap SDK and {path-to-tcpdump-source} is the pathname of the
top-level source directory for tcpdump.
Run the command
msbuild/m tcpdump.sln
to compile tcpdump.

View File

@ -19,6 +19,13 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
* Maximum length of the length field in an Ethernet header; any value
* greater than this is not a length value, so it's either an Ethernet
* type or an invalid value.
*/
#define MAX_ETHERNET_LENGTH_VAL 1500
/*
* Ethernet types.
*
@ -106,8 +113,8 @@
#endif
/* see:
http://en.wikipedia.org/wiki/IEEE_802.1Q
and http://en.wikipedia.org/wiki/QinQ
https://en.wikipedia.org/wiki/IEEE_802.1Q
and https://en.wikipedia.org/wiki/QinQ
*/
#ifndef ETHERTYPE_8021Q9100
#define ETHERTYPE_8021Q9100 0x9100
@ -175,6 +182,9 @@
#ifndef ETHERTYPE_AOE
#define ETHERTYPE_AOE 0x88a2
#endif
#ifndef ETHERTYPE_PTP
#define ETHERTYPE_PTP 0x88f7
#endif
#ifndef ETHERTYPE_LOOPBACK
#define ETHERTYPE_LOOPBACK 0x9000
#endif
@ -202,8 +212,8 @@
#ifndef ETHERTYPE_GEONET
#define ETHERTYPE_GEONET 0x8947 /* ETSI GeoNetworking (Official IEEE registration from Jan 2013) */
#endif
#ifndef ETHERTYPE_MEDSA
#define ETHERTYPE_MEDSA 0xdada /* Marvel Distributed Switch Architecture */
#ifndef ETHERTYPE_ARISTA
#define ETHERTYPE_ARISTA 0xd28b /* Arista Networks vendor specific EtherType */
#endif
extern const struct tok ethertype_values[];

799
extract.h
View File

@ -19,22 +19,130 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
* Macros to extract possibly-unaligned big-endian integral values.
*/
#ifdef LBL_ALIGN
/*
* The processor doesn't natively handle unaligned loads.
*/
#if defined(__GNUC__) && defined(HAVE___ATTRIBUTE__) && \
(defined(__alpha) || defined(__alpha__) || \
defined(__mips) || defined(__mips__))
#ifndef EXTRACT_H
#define EXTRACT_H
#include <string.h>
/*
* This is a GCC-compatible compiler and we have __attribute__, which
* we assume that mean we have __attribute__((packed)), and this is
* MIPS or Alpha, which has instructions that can help when doing
* unaligned loads.
* For 8-bit values; needed to fetch a one-byte value. Byte order
* isn't relevant, and alignment isn't an issue.
*/
#define EXTRACT_U_1(p) ((uint8_t)(*(p)))
#define EXTRACT_S_1(p) ((int8_t)(*(p)))
/*
* Inline functions or macros to extract possibly-unaligned big-endian
* integral values.
*/
#include "funcattrs.h"
#include "netdissect.h"
/*
* If we have versions of GCC or Clang that support an __attribute__
* to say "if we're building with unsigned behavior sanitization,
* don't complain about undefined behavior in this function", we
* label these functions with that attribute - we *know* it's undefined
* in the C standard, but we *also* know it does what we want with
* the ISA we're targeting and the compiler we're using.
*
* For GCC 4.9.0 and later, we use __attribute__((no_sanitize_undefined));
* pre-5.0 GCC doesn't have __has_attribute, and I'm not sure whether
* GCC or Clang first had __attribute__((no_sanitize(XXX)).
*
* For Clang, we check for __attribute__((no_sanitize(XXX)) with
* __has_attribute, as there are versions of Clang that support
* __attribute__((no_sanitize("undefined")) but don't support
* __attribute__((no_sanitize_undefined)).
*
* We define this here, rather than in funcattrs.h, because we
* only want it used here, we don't want it to be broadly used.
* (Any printer will get this defined, but this should at least
* make it harder for people to find.)
*/
#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 409)
#define UNALIGNED_OK __attribute__((no_sanitize_undefined))
#elif __has_attribute(no_sanitize)
#define UNALIGNED_OK __attribute__((no_sanitize("undefined")))
#else
#define UNALIGNED_OK
#endif
#if (defined(__i386__) || defined(_M_IX86) || defined(__X86__) || defined(__x86_64__) || defined(_M_X64)) || \
(defined(__m68k__) && (!defined(__mc68000__) && !defined(__mc68010__))) || \
(defined(__ppc__) || defined(__ppc64__) || defined(_M_PPC) || defined(_ARCH_PPC) || defined(_ARCH_PPC64)) || \
(defined(__s390__) || defined(__s390x__) || defined(__zarch__))
/*
* The processor natively handles unaligned loads, so we can just
* cast the pointer and fetch through it.
*
* XXX - are those all the x86 tests we need?
* XXX - are those the only 68k tests we need not to generated
* unaligned accesses if the target is the 68000 or 68010?
* XXX - are there any tests we don't need, because some definitions are for
* compilers that also predefine the GCC symbols?
* XXX - do we need to test for both 32-bit and 64-bit versions of those
* architectures in all cases?
*/
UNALIGNED_OK static inline uint16_t
EXTRACT_BE_U_2(const void *p)
{
return ((uint16_t)ntohs(*(const uint16_t *)(p)));
}
UNALIGNED_OK static inline int16_t
EXTRACT_BE_S_2(const void *p)
{
return ((int16_t)ntohs(*(const int16_t *)(p)));
}
UNALIGNED_OK static inline uint32_t
EXTRACT_BE_U_4(const void *p)
{
return ((uint32_t)ntohl(*(const uint32_t *)(p)));
}
UNALIGNED_OK static inline int32_t
EXTRACT_BE_S_4(const void *p)
{
return ((int32_t)ntohl(*(const int32_t *)(p)));
}
UNALIGNED_OK static inline uint64_t
EXTRACT_BE_U_8(const void *p)
{
return ((uint64_t)(((uint64_t)ntohl(*((const uint32_t *)(p) + 0))) << 32 |
((uint64_t)ntohl(*((const uint32_t *)(p) + 1))) << 0));
}
UNALIGNED_OK static inline int64_t
EXTRACT_BE_S_8(const void *p)
{
return ((int64_t)(((int64_t)ntohl(*((const uint32_t *)(p) + 0))) << 32 |
((uint64_t)ntohl(*((const uint32_t *)(p) + 1))) << 0));
}
/*
* Extract an IPv4 address, which is in network byte order, and not
* necessarily aligned, and provide the result in host byte order.
*/
UNALIGNED_OK static inline uint32_t
EXTRACT_IPV4_TO_HOST_ORDER(const void *p)
{
return ((uint32_t)ntohl(*(const uint32_t *)(p)));
}
#elif ND_IS_AT_LEAST_GNUC_VERSION(2,0) && \
(defined(__alpha) || defined(__alpha__) || \
defined(__mips) || defined(__mips__))
/*
* This is MIPS or Alpha, which don't natively handle unaligned loads,
* but which have instructions that can help when doing unaligned
* loads, and this is GCC 2.0 or later or a compiler that claims to
* be GCC 2.0 or later, which we assume that mean we have
* __attribute__((packed)), which we can use to convince the compiler
* to generate those instructions.
*
* Declare packed structures containing a uint16_t and a uint32_t,
* cast the pointer to point to one of those, and fetch through it;
@ -44,7 +152,7 @@
*
* We do this in case the compiler can generate code using those
* instructions to do an unaligned load and pass stuff to "ntohs()" or
* "ntohl()", which might be better than than the code to fetch the
* "ntohl()", which might be better than the code to fetch the
* bytes one at a time and assemble them. (That might not be the
* case on a little-endian platform, such as DEC's MIPS machines and
* Alpha machines, where "ntohs()" and "ntohl()" might not be done
@ -84,46 +192,101 @@ typedef struct {
uint16_t val;
} __attribute__((packed)) unaligned_uint16_t;
typedef struct {
int16_t val;
} __attribute__((packed)) unaligned_int16_t;
typedef struct {
uint32_t val;
} __attribute__((packed)) unaligned_uint32_t;
static inline uint16_t
EXTRACT_16BITS(const void *p)
typedef struct {
int32_t val;
} __attribute__((packed)) unaligned_int32_t;
UNALIGNED_OK static inline uint16_t
EXTRACT_BE_U_2(const void *p)
{
return ((uint16_t)ntohs(((const unaligned_uint16_t *)(p))->val));
}
static inline uint32_t
EXTRACT_32BITS(const void *p)
UNALIGNED_OK static inline int16_t
EXTRACT_BE_S_2(const void *p)
{
return ((int16_t)ntohs(((const unaligned_int16_t *)(p))->val));
}
UNALIGNED_OK static inline uint32_t
EXTRACT_BE_U_4(const void *p)
{
return ((uint32_t)ntohl(((const unaligned_uint32_t *)(p))->val));
}
static inline uint64_t
EXTRACT_64BITS(const void *p)
UNALIGNED_OK static inline int32_t
EXTRACT_BE_S_4(const void *p)
{
return ((int32_t)ntohl(((const unaligned_int32_t *)(p))->val));
}
UNALIGNED_OK static inline uint64_t
EXTRACT_BE_U_8(const void *p)
{
return ((uint64_t)(((uint64_t)ntohl(((const unaligned_uint32_t *)(p) + 0)->val)) << 32 |
((uint64_t)ntohl(((const unaligned_uint32_t *)(p) + 1)->val)) << 0));
}
#else /* have to do it a byte at a time */
UNALIGNED_OK static inline int64_t
EXTRACT_BE_S_8(const void *p)
{
return ((int64_t)(((uint64_t)ntohl(((const unaligned_uint32_t *)(p) + 0)->val)) << 32 |
((uint64_t)ntohl(((const unaligned_uint32_t *)(p) + 1)->val)) << 0));
}
/*
* This isn't a GCC-compatible compiler, we don't have __attribute__,
* Extract an IPv4 address, which is in network byte order, and not
* necessarily aligned, and provide the result in host byte order.
*/
UNALIGNED_OK static inline uint32_t
EXTRACT_IPV4_TO_HOST_ORDER(const void *p)
{
return ((uint32_t)ntohl(((const unaligned_uint32_t *)(p))->val));
}
#else
/*
* This architecture doesn't natively support unaligned loads, and either
* this isn't a GCC-compatible compiler, we don't have __attribute__,
* or we do but we don't know of any better way with this instruction
* set to do unaligned loads, so do unaligned loads of big-endian
* quantities the hard way - fetch the bytes one at a time and
* assemble them.
*
* XXX - ARM is a special case. ARMv1 through ARMv5 didn't suppory
* unaligned loads; ARMv6 and later support it *but* have a bit in
* the system control register that the OS can set and that causes
* unaligned loads to fault rather than succeeding.
*
* At least some OSes may set that flag, so we do *not* treat ARM
* as supporting unaligned loads. If your OS supports them on ARM,
* and you want to use them, please update the tests in the #if above
* to check for ARM *and* for your OS.
*/
#define EXTRACT_16BITS(p) \
#define EXTRACT_BE_U_2(p) \
((uint16_t)(((uint16_t)(*((const uint8_t *)(p) + 0)) << 8) | \
((uint16_t)(*((const uint8_t *)(p) + 1)) << 0)))
#define EXTRACT_32BITS(p) \
#define EXTRACT_BE_S_2(p) \
((int16_t)(((uint16_t)(*((const uint8_t *)(p) + 0)) << 8) | \
((uint16_t)(*((const uint8_t *)(p) + 1)) << 0)))
#define EXTRACT_BE_U_4(p) \
((uint32_t)(((uint32_t)(*((const uint8_t *)(p) + 0)) << 24) | \
((uint32_t)(*((const uint8_t *)(p) + 1)) << 16) | \
((uint32_t)(*((const uint8_t *)(p) + 2)) << 8) | \
((uint32_t)(*((const uint8_t *)(p) + 3)) << 0)))
#define EXTRACT_64BITS(p) \
#define EXTRACT_BE_S_4(p) \
((int32_t)(((uint32_t)(*((const uint8_t *)(p) + 0)) << 24) | \
((uint32_t)(*((const uint8_t *)(p) + 1)) << 16) | \
((uint32_t)(*((const uint8_t *)(p) + 2)) << 8) | \
((uint32_t)(*((const uint8_t *)(p) + 3)) << 0)))
#define EXTRACT_BE_U_8(p) \
((uint64_t)(((uint64_t)(*((const uint8_t *)(p) + 0)) << 56) | \
((uint64_t)(*((const uint8_t *)(p) + 1)) << 48) | \
((uint64_t)(*((const uint8_t *)(p) + 2)) << 40) | \
@ -132,47 +295,133 @@ EXTRACT_64BITS(const void *p)
((uint64_t)(*((const uint8_t *)(p) + 5)) << 16) | \
((uint64_t)(*((const uint8_t *)(p) + 6)) << 8) | \
((uint64_t)(*((const uint8_t *)(p) + 7)) << 0)))
#endif /* must special-case unaligned accesses */
#else /* LBL_ALIGN */
#define EXTRACT_BE_S_8(p) \
((int64_t)(((uint64_t)(*((const uint8_t *)(p) + 0)) << 56) | \
((uint64_t)(*((const uint8_t *)(p) + 1)) << 48) | \
((uint64_t)(*((const uint8_t *)(p) + 2)) << 40) | \
((uint64_t)(*((const uint8_t *)(p) + 3)) << 32) | \
((uint64_t)(*((const uint8_t *)(p) + 4)) << 24) | \
((uint64_t)(*((const uint8_t *)(p) + 5)) << 16) | \
((uint64_t)(*((const uint8_t *)(p) + 6)) << 8) | \
((uint64_t)(*((const uint8_t *)(p) + 7)) << 0)))
/*
* The processor natively handles unaligned loads, so we can just
* cast the pointer and fetch through it.
* Extract an IPv4 address, which is in network byte order, and not
* necessarily aligned, and provide the result in host byte order.
*/
#define EXTRACT_IPV4_TO_HOST_ORDER(p) \
((uint32_t)(((uint32_t)(*((const uint8_t *)(p) + 0)) << 24) | \
((uint32_t)(*((const uint8_t *)(p) + 1)) << 16) | \
((uint32_t)(*((const uint8_t *)(p) + 2)) << 8) | \
((uint32_t)(*((const uint8_t *)(p) + 3)) << 0)))
#endif /* unaligned access checks */
/*
* Extract numerical values in *host* byte order. (Some metadata
* headers are in the byte order of the host that wrote the file,
* and libpcap translate them to the byte order of the host
* reading the file. This means that if a program on that host
* reads with libpcap and writes to a new file, the new file will
* be written in the byte order of the host writing the file. Thus,
* the magic number in pcap files and byte-order magic in pcapng
* files can be used to determine the byte order in those metadata
* headers.)
*
* XXX - on platforms that can do unaligned accesses, just cast and
* dereference the pointer.
*/
static inline uint16_t
EXTRACT_16BITS(const void *p)
EXTRACT_HE_U_2(const void *p)
{
return ((uint16_t)ntohs(*(const uint16_t *)(p)));
uint16_t val;
UNALIGNED_MEMCPY(&val, p, sizeof(uint16_t));
return val;
}
static inline int16_t
EXTRACT_HE_S_2(const void *p)
{
int16_t val;
UNALIGNED_MEMCPY(&val, p, sizeof(int16_t));
return val;
}
static inline uint32_t
EXTRACT_32BITS(const void *p)
EXTRACT_HE_U_4(const void *p)
{
return ((uint32_t)ntohl(*(const uint32_t *)(p)));
uint32_t val;
UNALIGNED_MEMCPY(&val, p, sizeof(uint32_t));
return val;
}
static inline uint64_t
EXTRACT_64BITS(const void *p)
static inline int32_t
EXTRACT_HE_S_4(const void *p)
{
return ((uint64_t)(((uint64_t)ntohl(*((const uint32_t *)(p) + 0))) << 32 |
((uint64_t)ntohl(*((const uint32_t *)(p) + 1))) << 0));
int32_t val;
UNALIGNED_MEMCPY(&val, p, sizeof(int32_t));
return val;
}
#endif /* LBL_ALIGN */
/*
* Extract an IPv4 address, which is in network byte order, and which
* is not necessarily aligned on a 4-byte boundary, and provide the
* result in network byte order.
*
* This works the same way regardless of the host's byte order.
*/
static inline uint32_t
EXTRACT_IPV4_TO_NETWORK_ORDER(const void *p)
{
uint32_t addr;
#define EXTRACT_24BITS(p) \
UNALIGNED_MEMCPY(&addr, p, sizeof(uint32_t));
return addr;
}
/*
* Non-power-of-2 sizes.
*/
#define EXTRACT_BE_U_3(p) \
((uint32_t)(((uint32_t)(*((const uint8_t *)(p) + 0)) << 16) | \
((uint32_t)(*((const uint8_t *)(p) + 1)) << 8) | \
((uint32_t)(*((const uint8_t *)(p) + 2)) << 0)))
#define EXTRACT_40BITS(p) \
#define EXTRACT_BE_S_3(p) \
(((*((const uint8_t *)(p) + 0)) & 0x80) ? \
((int32_t)(((uint32_t)(*((const uint8_t *)(p) + 0)) << 16) | \
((uint32_t)(*((const uint8_t *)(p) + 1)) << 8) | \
((uint32_t)(*((const uint8_t *)(p) + 2)) << 0))) : \
((int32_t)(0xFF000000U | \
((uint32_t)(*((const uint8_t *)(p) + 0)) << 16) | \
((uint32_t)(*((const uint8_t *)(p) + 1)) << 8) | \
((uint32_t)(*((const uint8_t *)(p) + 2)) << 0))))
#define EXTRACT_BE_U_5(p) \
((uint64_t)(((uint64_t)(*((const uint8_t *)(p) + 0)) << 32) | \
((uint64_t)(*((const uint8_t *)(p) + 1)) << 24) | \
((uint64_t)(*((const uint8_t *)(p) + 2)) << 16) | \
((uint64_t)(*((const uint8_t *)(p) + 3)) << 8) | \
((uint64_t)(*((const uint8_t *)(p) + 4)) << 0)))
#define EXTRACT_48BITS(p) \
#define EXTRACT_BE_S_5(p) \
(((*((const uint8_t *)(p) + 0)) & 0x80) ? \
((int64_t)(((uint64_t)(*((const uint8_t *)(p) + 0)) << 32) | \
((uint64_t)(*((const uint8_t *)(p) + 1)) << 24) | \
((uint64_t)(*((const uint8_t *)(p) + 2)) << 16) | \
((uint64_t)(*((const uint8_t *)(p) + 3)) << 8) | \
((uint64_t)(*((const uint8_t *)(p) + 4)) << 0))) : \
((int64_t)(INT64_T_CONSTANT(0xFFFFFF0000000000U) | \
((uint64_t)(*((const uint8_t *)(p) + 0)) << 32) | \
((uint64_t)(*((const uint8_t *)(p) + 1)) << 24) | \
((uint64_t)(*((const uint8_t *)(p) + 2)) << 16) | \
((uint64_t)(*((const uint8_t *)(p) + 3)) << 8) | \
((uint64_t)(*((const uint8_t *)(p) + 4)) << 0))))
#define EXTRACT_BE_U_6(p) \
((uint64_t)(((uint64_t)(*((const uint8_t *)(p) + 0)) << 40) | \
((uint64_t)(*((const uint8_t *)(p) + 1)) << 32) | \
((uint64_t)(*((const uint8_t *)(p) + 2)) << 24) | \
@ -180,7 +429,23 @@ EXTRACT_64BITS(const void *p)
((uint64_t)(*((const uint8_t *)(p) + 4)) << 8) | \
((uint64_t)(*((const uint8_t *)(p) + 5)) << 0)))
#define EXTRACT_56BITS(p) \
#define EXTRACT_BE_S_6(p) \
(((*((const uint8_t *)(p) + 0)) & 0x80) ? \
((int64_t)(((uint64_t)(*((const uint8_t *)(p) + 0)) << 40) | \
((uint64_t)(*((const uint8_t *)(p) + 1)) << 32) | \
((uint64_t)(*((const uint8_t *)(p) + 2)) << 24) | \
((uint64_t)(*((const uint8_t *)(p) + 3)) << 16) | \
((uint64_t)(*((const uint8_t *)(p) + 4)) << 8) | \
((uint64_t)(*((const uint8_t *)(p) + 5)) << 0))) : \
((int64_t)(INT64_T_CONSTANT(0xFFFFFFFF00000000U) | \
((uint64_t)(*((const uint8_t *)(p) + 0)) << 40) | \
((uint64_t)(*((const uint8_t *)(p) + 1)) << 32) | \
((uint64_t)(*((const uint8_t *)(p) + 2)) << 24) | \
((uint64_t)(*((const uint8_t *)(p) + 3)) << 16) | \
((uint64_t)(*((const uint8_t *)(p) + 4)) << 8) | \
((uint64_t)(*((const uint8_t *)(p) + 5)) << 0))))
#define EXTRACT_BE_U_7(p) \
((uint64_t)(((uint64_t)(*((const uint8_t *)(p) + 0)) << 48) | \
((uint64_t)(*((const uint8_t *)(p) + 1)) << 40) | \
((uint64_t)(*((const uint8_t *)(p) + 2)) << 32) | \
@ -189,24 +454,45 @@ EXTRACT_64BITS(const void *p)
((uint64_t)(*((const uint8_t *)(p) + 5)) << 8) | \
((uint64_t)(*((const uint8_t *)(p) + 6)) << 0)))
#define EXTRACT_BE_S_7(p) \
(((*((const uint8_t *)(p) + 0)) & 0x80) ? \
((int64_t)(((uint64_t)(*((const uint8_t *)(p) + 0)) << 48) | \
((uint64_t)(*((const uint8_t *)(p) + 1)) << 40) | \
((uint64_t)(*((const uint8_t *)(p) + 2)) << 32) | \
((uint64_t)(*((const uint8_t *)(p) + 3)) << 24) | \
((uint64_t)(*((const uint8_t *)(p) + 4)) << 16) | \
((uint64_t)(*((const uint8_t *)(p) + 5)) << 8) | \
((uint64_t)(*((const uint8_t *)(p) + 6)) << 0))) : \
((int64_t)(INT64_T_CONSTANT(0xFFFFFFFFFF000000U) | \
((uint64_t)(*((const uint8_t *)(p) + 0)) << 48) | \
((uint64_t)(*((const uint8_t *)(p) + 1)) << 40) | \
((uint64_t)(*((const uint8_t *)(p) + 2)) << 32) | \
((uint64_t)(*((const uint8_t *)(p) + 3)) << 24) | \
((uint64_t)(*((const uint8_t *)(p) + 4)) << 16) | \
((uint64_t)(*((const uint8_t *)(p) + 5)) << 8) | \
((uint64_t)(*((const uint8_t *)(p) + 6)) << 0))))
/*
* Macros to extract possibly-unaligned little-endian integral values.
* XXX - do loads on little-endian machines that support unaligned loads?
*/
#define EXTRACT_LE_8BITS(p) (*(p))
#define EXTRACT_LE_16BITS(p) \
#define EXTRACT_LE_U_2(p) \
((uint16_t)(((uint16_t)(*((const uint8_t *)(p) + 1)) << 8) | \
((uint16_t)(*((const uint8_t *)(p) + 0)) << 0)))
#define EXTRACT_LE_32BITS(p) \
#define EXTRACT_LE_S_2(p) \
((int16_t)(((uint16_t)(*((const uint8_t *)(p) + 1)) << 8) | \
((uint16_t)(*((const uint8_t *)(p) + 0)) << 0)))
#define EXTRACT_LE_U_4(p) \
((uint32_t)(((uint32_t)(*((const uint8_t *)(p) + 3)) << 24) | \
((uint32_t)(*((const uint8_t *)(p) + 2)) << 16) | \
((uint32_t)(*((const uint8_t *)(p) + 1)) << 8) | \
((uint32_t)(*((const uint8_t *)(p) + 0)) << 0)))
#define EXTRACT_LE_24BITS(p) \
((uint32_t)(((uint32_t)(*((const uint8_t *)(p) + 2)) << 16) | \
((uint32_t)(*((const uint8_t *)(p) + 1)) << 8) | \
((uint32_t)(*((const uint8_t *)(p) + 0)) << 0)))
#define EXTRACT_LE_64BITS(p) \
#define EXTRACT_LE_S_4(p) \
((int32_t)(((uint32_t)(*((const uint8_t *)(p) + 3)) << 24) | \
((uint32_t)(*((const uint8_t *)(p) + 2)) << 16) | \
((uint32_t)(*((const uint8_t *)(p) + 1)) << 8) | \
((uint32_t)(*((const uint8_t *)(p) + 0)) << 0)))
#define EXTRACT_LE_U_8(p) \
((uint64_t)(((uint64_t)(*((const uint8_t *)(p) + 7)) << 56) | \
((uint64_t)(*((const uint8_t *)(p) + 6)) << 48) | \
((uint64_t)(*((const uint8_t *)(p) + 5)) << 40) | \
@ -215,30 +501,409 @@ EXTRACT_64BITS(const void *p)
((uint64_t)(*((const uint8_t *)(p) + 2)) << 16) | \
((uint64_t)(*((const uint8_t *)(p) + 1)) << 8) | \
((uint64_t)(*((const uint8_t *)(p) + 0)) << 0)))
#define EXTRACT_LE_S_8(p) \
((int64_t)(((uint64_t)(*((const uint8_t *)(p) + 7)) << 56) | \
((uint64_t)(*((const uint8_t *)(p) + 6)) << 48) | \
((uint64_t)(*((const uint8_t *)(p) + 5)) << 40) | \
((uint64_t)(*((const uint8_t *)(p) + 4)) << 32) | \
((uint64_t)(*((const uint8_t *)(p) + 3)) << 24) | \
((uint64_t)(*((const uint8_t *)(p) + 2)) << 16) | \
((uint64_t)(*((const uint8_t *)(p) + 1)) << 8) | \
((uint64_t)(*((const uint8_t *)(p) + 0)) << 0)))
/*
* Non-power-of-2 sizes.
*/
#define EXTRACT_LE_U_3(p) \
((uint32_t)(((uint32_t)(*((const uint8_t *)(p) + 2)) << 16) | \
((uint32_t)(*((const uint8_t *)(p) + 1)) << 8) | \
((uint32_t)(*((const uint8_t *)(p) + 0)) << 0)))
#define EXTRACT_LE_S_3(p) \
((int32_t)(((uint32_t)(*((const uint8_t *)(p) + 2)) << 16) | \
((uint32_t)(*((const uint8_t *)(p) + 1)) << 8) | \
((uint32_t)(*((const uint8_t *)(p) + 0)) << 0)))
#define EXTRACT_LE_U_5(p) \
((uint64_t)(((uint64_t)(*((const uint8_t *)(p) + 4)) << 32) | \
((uint64_t)(*((const uint8_t *)(p) + 3)) << 24) | \
((uint64_t)(*((const uint8_t *)(p) + 2)) << 16) | \
((uint64_t)(*((const uint8_t *)(p) + 1)) << 8) | \
((uint64_t)(*((const uint8_t *)(p) + 0)) << 0)))
#define EXTRACT_LE_U_6(p) \
((uint64_t)(((uint64_t)(*((const uint8_t *)(p) + 5)) << 40) | \
((uint64_t)(*((const uint8_t *)(p) + 4)) << 32) | \
((uint64_t)(*((const uint8_t *)(p) + 3)) << 24) | \
((uint64_t)(*((const uint8_t *)(p) + 2)) << 16) | \
((uint64_t)(*((const uint8_t *)(p) + 1)) << 8) | \
((uint64_t)(*((const uint8_t *)(p) + 0)) << 0)))
#define EXTRACT_LE_U_7(p) \
((uint64_t)(((uint64_t)(*((const uint8_t *)(p) + 6)) << 48) | \
((uint64_t)(*((const uint8_t *)(p) + 5)) << 40) | \
((uint64_t)(*((const uint8_t *)(p) + 4)) << 32) | \
((uint64_t)(*((const uint8_t *)(p) + 3)) << 24) | \
((uint64_t)(*((const uint8_t *)(p) + 2)) << 16) | \
((uint64_t)(*((const uint8_t *)(p) + 1)) << 8) | \
((uint64_t)(*((const uint8_t *)(p) + 0)) << 0)))
/*
* Macros to check the presence of the values in question.
*/
#define ND_TTEST_8BITS(p) ND_TTEST2(*(p), 1)
#define ND_TCHECK_8BITS(p) ND_TCHECK2(*(p), 1)
#define ND_TTEST_1(p) ND_TTEST_LEN((p), 1)
#define ND_TCHECK_1(p) ND_TCHECK_LEN((p), 1)
#define ND_TTEST_16BITS(p) ND_TTEST2(*(p), 2)
#define ND_TCHECK_16BITS(p) ND_TCHECK2(*(p), 2)
#define ND_TTEST_2(p) ND_TTEST_LEN((p), 2)
#define ND_TCHECK_2(p) ND_TCHECK_LEN((p), 2)
#define ND_TTEST_24BITS(p) ND_TTEST2(*(p), 3)
#define ND_TCHECK_24BITS(p) ND_TCHECK2(*(p), 3)
#define ND_TTEST_3(p) ND_TTEST_LEN((p), 3)
#define ND_TCHECK_3(p) ND_TCHECK_LEN((p), 3)
#define ND_TTEST_32BITS(p) ND_TTEST2(*(p), 4)
#define ND_TCHECK_32BITS(p) ND_TCHECK2(*(p), 4)
#define ND_TTEST_4(p) ND_TTEST_LEN((p), 4)
#define ND_TCHECK_4(p) ND_TCHECK_LEN((p), 4)
#define ND_TTEST_40BITS(p) ND_TTEST2(*(p), 5)
#define ND_TCHECK_40BITS(p) ND_TCHECK2(*(p), 5)
#define ND_TTEST_5(p) ND_TTEST_LEN((p), 5)
#define ND_TCHECK_5(p) ND_TCHECK_LEN((p), 5)
#define ND_TTEST_48BITS(p) ND_TTEST2(*(p), 6)
#define ND_TCHECK_48BITS(p) ND_TCHECK2(*(p), 6)
#define ND_TTEST_6(p) ND_TTEST_LEN((p), 6)
#define ND_TCHECK_6(p) ND_TCHECK_LEN((p), 6)
#define ND_TTEST_56BITS(p) ND_TTEST2(*(p), 7)
#define ND_TCHECK_56BITS(p) ND_TCHECK2(*(p), 7)
#define ND_TTEST_7(p) ND_TTEST_LEN((p), 7)
#define ND_TCHECK_7(p) ND_TCHECK_LEN((p), 7)
#define ND_TTEST_64BITS(p) ND_TTEST2(*(p), 8)
#define ND_TCHECK_64BITS(p) ND_TCHECK2(*(p), 8)
#define ND_TTEST_8(p) ND_TTEST_LEN((p), 8)
#define ND_TCHECK_8(p) ND_TCHECK_LEN((p), 8)
#define ND_TTEST_16(p) ND_TTEST_LEN((p), 16)
#define ND_TCHECK_16(p) ND_TCHECK_LEN((p), 16)
/* get_u_1 and get_s_1 */
static inline uint8_t
get_u_1(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_1(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_U_1(p);
}
static inline int8_t
get_s_1(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_1(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_S_1(p);
}
/* get_be_u_N */
static inline uint16_t
get_be_u_2(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_2(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_BE_U_2(p);
}
static inline uint32_t
get_be_u_3(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_3(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_BE_U_3(p);
}
static inline uint32_t
get_be_u_4(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_4(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_BE_U_4(p);
}
static inline uint64_t
get_be_u_5(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_5(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_BE_U_5(p);
}
static inline uint64_t
get_be_u_6(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_6(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_BE_U_6(p);
}
static inline uint64_t
get_be_u_7(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_7(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_BE_U_7(p);
}
static inline uint64_t
get_be_u_8(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_8(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_BE_U_8(p);
}
/* get_be_s_N */
static inline int16_t
get_be_s_2(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_2(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_BE_S_2(p);
}
static inline int32_t
get_be_s_3(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_3(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_BE_S_3(p);
}
static inline int32_t
get_be_s_4(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_4(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_BE_S_4(p);
}
static inline int64_t
get_be_s_5(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_5(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_BE_S_5(p);
}
static inline int64_t
get_be_s_6(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_6(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_BE_S_6(p);
}
static inline int64_t
get_be_s_7(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_7(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_BE_S_7(p);
}
static inline int64_t
get_be_s_8(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_8(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_BE_S_8(p);
}
/* get_he_u_N */
static inline uint16_t
get_he_u_2(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_2(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_HE_U_2(p);
}
static inline uint32_t
get_he_u_4(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_4(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_HE_U_4(p);
}
/* get_he_s_N */
static inline int16_t
get_he_s_2(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_2(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_HE_S_2(p);
}
static inline int32_t
get_he_s_4(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_4(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_HE_S_4(p);
}
/* get_le_u_N */
static inline uint16_t
get_le_u_2(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_2(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_LE_U_2(p);
}
static inline uint32_t
get_le_u_3(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_3(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_LE_U_3(p);
}
static inline uint32_t
get_le_u_4(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_4(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_LE_U_4(p);
}
static inline uint64_t
get_le_u_5(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_5(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_LE_U_5(p);
}
static inline uint64_t
get_le_u_6(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_6(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_LE_U_6(p);
}
static inline uint64_t
get_le_u_7(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_7(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_LE_U_7(p);
}
static inline uint64_t
get_le_u_8(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_8(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_LE_U_8(p);
}
/* get_le_s_N */
static inline int16_t
get_le_s_2(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_2(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_LE_S_2(p);
}
static inline int32_t
get_le_s_3(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_3(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_LE_S_3(p);
}
static inline int32_t
get_le_s_4(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_4(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_LE_S_4(p);
}
static inline int64_t
get_le_s_8(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_8(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_LE_S_8(p);
}
/* get_ipv4_to_{host|network]_order */
static inline uint32_t
get_ipv4_to_host_order(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_4(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_IPV4_TO_HOST_ORDER(p);
}
static inline uint32_t
get_ipv4_to_network_order(netdissect_options *ndo, const u_char *p)
{
if (!ND_TTEST_4(p))
longjmp(ndo->ndo_truncated, 1);
return EXTRACT_IPV4_TO_NETWORK_ORDER(p);
}
static inline void
get_cpy_bytes(netdissect_options *ndo, u_char *dst, const u_char *p, size_t len)
{
if (!ND_TTEST_LEN(p, len))
longjmp(ndo->ndo_truncated, 1);
UNALIGNED_MEMCPY(dst, p, len);
}
#define GET_U_1(p) get_u_1(ndo, (const u_char *)(p))
#define GET_S_1(p) get_s_1(ndo, (const u_char *)(p))
#define GET_BE_U_2(p) get_be_u_2(ndo, (const u_char *)(p))
#define GET_BE_U_3(p) get_be_u_3(ndo, (const u_char *)(p))
#define GET_BE_U_4(p) get_be_u_4(ndo, (const u_char *)(p))
#define GET_BE_U_5(p) get_be_u_5(ndo, (const u_char *)(p))
#define GET_BE_U_6(p) get_be_u_6(ndo, (const u_char *)(p))
#define GET_BE_U_7(p) get_be_u_7(ndo, (const u_char *)(p))
#define GET_BE_U_8(p) get_be_u_8(ndo, (const u_char *)(p))
#define GET_BE_S_2(p) get_be_s_2(ndo, (const u_char *)(p))
#define GET_BE_S_3(p) get_be_s_3(ndo, (const u_char *)(p))
#define GET_BE_S_4(p) get_be_s_4(ndo, (const u_char *)(p))
#define GET_BE_S_5(p) get_be_s_5(ndo, (const u_char *)(p))
#define GET_BE_S_6(p) get_be_s_6(ndo, (const u_char *)(p))
#define GET_BE_S_7(p) get_be_s_7(ndo, (const u_char *)(p))
#define GET_BE_S_8(p) get_be_s_8(ndo, (const u_char *)(p))
#define GET_HE_U_2(p) get_he_u_2(ndo, (const u_char *)(p))
#define GET_HE_U_4(p) get_he_u_4(ndo, (const u_char *)(p))
#define GET_HE_S_2(p) get_he_s_2(ndo, (const u_char *)(p))
#define GET_HE_S_4(p) get_he_s_4(ndo, (const u_char *)(p))
#define GET_LE_U_2(p) get_le_u_2(ndo, (const u_char *)(p))
#define GET_LE_U_3(p) get_le_u_3(ndo, (const u_char *)(p))
#define GET_LE_U_4(p) get_le_u_4(ndo, (const u_char *)(p))
#define GET_LE_U_5(p) get_le_u_5(ndo, (const u_char *)(p))
#define GET_LE_U_6(p) get_le_u_6(ndo, (const u_char *)(p))
#define GET_LE_U_7(p) get_le_u_7(ndo, (const u_char *)(p))
#define GET_LE_U_8(p) get_le_u_8(ndo, (const u_char *)(p))
#define GET_LE_S_2(p) get_le_s_2(ndo, (const u_char *)(p))
#define GET_LE_S_3(p) get_le_s_3(ndo, (const u_char *)(p))
#define GET_LE_S_4(p) get_le_s_4(ndo, (const u_char *)(p))
#define GET_LE_S_8(p) get_le_s_8(ndo, (const u_char *)(p))
#define GET_IPV4_TO_HOST_ORDER(p) get_ipv4_to_host_order(ndo, (const u_char *)(p))
#define GET_IPV4_TO_NETWORK_ORDER(p) get_ipv4_to_network_order(ndo, (const u_char *)(p))
#define GET_CPY_BYTES(dst, p, len) get_cpy_bytes(ndo, (u_char *)(dst), (const u_char *)(p), len)
#endif /* EXTRACT_H */

View File

@ -29,29 +29,22 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)if_ether.h 8.3 (Berkeley) 5/2/95
*/
#define ETHERMTU 1500
#include <stdio.h>
/*
* The number of bytes in an ethernet (MAC) address.
*/
#define ETHER_ADDR_LEN 6
#include "netdissect-stdinc.h"
/*
* Structure of an Ethernet header.
*/
struct ether_header {
uint8_t ether_dhost[ETHER_ADDR_LEN];
uint8_t ether_shost[ETHER_ADDR_LEN];
uint16_t ether_length_type;
};
#include "fptype.h"
/*
* Length of an Ethernet header; note that some compilers may pad
* "struct ether_header" to a multiple of 4 bytes, for example, so
* "sizeof (struct ether_header)" may not give the right answer.
*/
#define ETHER_HDRLEN 14
void
float_type_check(uint32_t in)
{
union { /* int to float conversion buffer */
float f;
uint32_t i;
} f;
f.i = in;
printf("%.3f\n", f.f*8/1000000);
}

34
fptype.h Normal file
View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 1982, 1986, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
extern void float_type_check(uint32_t);

148
funcattrs.h Normal file
View File

@ -0,0 +1,148 @@
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Computer Systems
* Engineering Group at Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lib_funcattrs_h
#define lib_funcattrs_h
#include "compiler-tests.h"
/*
* Attributes to apply to functions and their arguments, using various
* compiler-specific extensions.
*/
/*
* This was introduced by Clang:
*
* https://clang.llvm.org/docs/LanguageExtensions.html#has-attribute
*
* in some version (which version?); it has been picked up by GCC 5.0.
*/
#ifndef __has_attribute
/*
* It's a macro, so you can check whether it's defined to check
* whether it's supported.
*
* If it's not, define it to always return 0, so that we move on to
* the fallback checks.
*/
#define __has_attribute(x) 0
#endif
/*
* NORETURN, before a function declaration, means "this function
* never returns". (It must go before the function declaration, e.g.
* "extern NORETURN func(...)" rather than after the function
* declaration, as the MSVC version has to go before the declaration.)
*/
#if __has_attribute(noreturn) \
|| ND_IS_AT_LEAST_GNUC_VERSION(2,5) \
|| ND_IS_AT_LEAST_SUNC_VERSION(5,9) \
|| ND_IS_AT_LEAST_XL_C_VERSION(10,1) \
|| ND_IS_AT_LEAST_HP_C_VERSION(6,10)
/*
* Compiler with support for __attribute((noreturn)), or GCC 2.5 and
* later, or Solaris Studio 12 (Sun C 5.9) and later, or IBM XL C 10.1
* and later (do any earlier versions of XL C support this?), or
* HP aCC A.06.10 and later.
*/
#define NORETURN __attribute((noreturn))
/*
* However, GCC didn't support that for function *pointers* until GCC
* 4.1.0; see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3481.
*
* Sun C/Oracle Studio C doesn't seem to support it, either.
*/
#if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) < 401)) \
|| (defined(__SUNPRO_C))
#define NORETURN_FUNCPTR
#else
#define NORETURN_FUNCPTR __attribute((noreturn))
#endif
#elif defined(_MSC_VER)
/*
* MSVC.
* It doesn't allow __declspec(noreturn) to be applied to function
* pointers.
*/
#define NORETURN __declspec(noreturn)
#define NORETURN_FUNCPTR
#else
#define NORETURN
#define NORETURN_FUNCPTR
#endif
/*
* PRINTFLIKE(x,y), after a function declaration, means "this function
* does printf-style formatting, with the xth argument being the format
* string and the yth argument being the first argument for the format
* string".
*/
#if __has_attribute(__format__) \
|| ND_IS_AT_LEAST_GNUC_VERSION(2,3) \
|| ND_IS_AT_LEAST_XL_C_VERSION(10,1) \
|| ND_IS_AT_LEAST_HP_C_VERSION(6,10)
/*
* Compiler with support for it, or GCC 2.3 and later, or IBM XL C 10.1
* and later (do any earlier versions of XL C support this?),
* or HP aCC A.06.10 and later.
*/
#define PRINTFLIKE(x,y) __attribute__((__format__(__printf__,x,y)))
/*
* However, GCC didn't support that for function *pointers* until GCC
* 4.1.0; see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3481.
*/
#if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) < 401))
#define PRINTFLIKE_FUNCPTR(x,y)
#else
#define PRINTFLIKE_FUNCPTR(x,y) __attribute__((__format__(__printf__,x,y)))
#endif
#else
#define PRINTFLIKE(x,y)
#define PRINTFLIKE_FUNCPTR(x,y)
#endif
/*
* For flagging arguments as format strings in MSVC.
*/
#ifdef _MSC_VER
#include <sal.h>
#define FORMAT_STRING(p) _Printf_format_string_ p
#else
#define FORMAT_STRING(p) p
#endif
#endif /* lib_funcattrs_h */

67
getservent.h Normal file
View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 1983, 1993 The Regents of the University of California.
* Copyright (c) 1993 Digital Equipment Corporation.
* Copyright (c) 2012 G. Vanem <gvanem@yahoo.no>.
* Copyright (c) 2017 Ali Abdulkadir <autostart.ini@gmail.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _GETSERVENT_H
#define _GETSERVENT_H
#ifdef _NETDB_H_
/* Just in case... */
#error netdb.h and getservent.h are incompatible
#else
#define _NETDB_H_
#endif
#ifdef _WIN32
#define __PATH_SYSROOT "SYSTEMROOT"
#define __PATH_ETC_INET "\\System32\\drivers\\etc\\"
#define __PATH_SERVICES "services"
#else
/*
* The idea here is to be able to replace "PREFIX" in __PATH_SYSROOT with a variable
* that could, for example, point to an alternative install location.
*/
#define __PATH_SYSROOT "PREFIX"
#define __PATH_ETC_INET "/etc/"
#define __PATH_SERVICES __PATH_ETC_INET"services"
#endif
#define MAXALIASES 35
void endservent (void);
struct servent *getservent(void);
void setservent (int f);
#endif /* !_GETSERVENT_H */

View File

@ -10,14 +10,14 @@
* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
* Original code by Hannes Gredler (hannes@juniper.net)
* Original code by Hannes Gredler (hannes@gredler.at)
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "gmpls.h"

View File

@ -10,7 +10,7 @@
* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
* Original code by Hannes Gredler (hannes@juniper.net)
* Original code by Hannes Gredler (hannes@gredler.at)
*/
#define GMPLS_PSC1 1

View File

@ -1,66 +0,0 @@
/*
* Copyright (c) 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University nor the names of its contributors may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <netdissect-stdinc.h>
#include <stdio.h>
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
#endif
#include "gmt2local.h"
/*
* Returns the difference between gmt and local time in seconds.
* Use gmtime() and localtime() to keep things simple.
*/
int32_t
gmt2local(time_t t)
{
register int dt, dir;
register struct tm *gmt, *loc;
struct tm sgmt;
if (t == 0)
t = time(NULL);
gmt = &sgmt;
*gmt = *gmtime(&t);
loc = localtime(&t);
dt = (loc->tm_hour - gmt->tm_hour) * 60 * 60 +
(loc->tm_min - gmt->tm_min) * 60;
/*
* If the year or julian day is different, we span 00:00 GMT
* and must add or subtract a day. Check the year first to
* avoid problems when the julian day wraps.
*/
dir = loc->tm_year - gmt->tm_year;
if (dir == 0)
dir = loc->tm_yday - gmt->tm_yday;
dt += dir * 24 * 60 * 60;
return (dt);
}

View File

@ -1,25 +0,0 @@
/*
* Copyright (c) 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University nor the names of its contributors may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef gmt2local_h
#define gmt2local_h
int32_t gmt2local(time_t);
#endif

View File

@ -36,10 +36,10 @@
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
# include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include "netdissect.h"
@ -56,9 +56,9 @@
uint16_t
in_cksum(const struct cksum_vec *vec, int veclen)
{
register const uint16_t *w;
register int sum = 0;
register int mlen = 0;
const uint16_t *w;
int sum = 0;
int mlen = 0;
int byte_swapped = 0;
union {
@ -196,5 +196,5 @@ in_cksum_shouldbe(uint16_t sum, uint16_t computed_sum)
shouldbe += ntohs(computed_sum);
shouldbe = (shouldbe & 0xFFFF) + (shouldbe >> 16);
shouldbe = (shouldbe & 0xFFFF) + (shouldbe >> 16);
return shouldbe;
return (uint16_t)shouldbe;
}

View File

@ -26,7 +26,7 @@
#include "os-proto.h"
#endif
/* snprintf et al */
#include "funcattrs.h"
#include <stdarg.h>
@ -34,22 +34,6 @@
#include <stdint.h>
#endif
#if !defined(HAVE_SNPRINTF)
int snprintf(char *, size_t, const char *, ...)
#ifdef __ATTRIBUTE___FORMAT_OK
__attribute__((format(printf, 3, 4)))
#endif /* __ATTRIBUTE___FORMAT_OK */
;
#endif /* !defined(HAVE_SNPRINTF) */
#if !defined(HAVE_VSNPRINTF)
int vsnprintf(char *, size_t, const char *, va_list)
#ifdef __ATTRIBUTE___FORMAT_OK
__attribute__((format(printf, 3, 0)))
#endif /* __ATTRIBUTE___FORMAT_OK */
;
#endif /* !defined(HAVE_VSNPRINTF) */
#ifndef HAVE_STRLCAT
extern size_t strlcat(char *, const char *, size_t);
#endif

4
ip.h
View File

@ -51,8 +51,8 @@
*/
struct ip {
nd_uint8_t ip_vhl; /* header length, version */
#define IP_V(ip) (((ip)->ip_vhl & 0xf0) >> 4)
#define IP_HL(ip) ((ip)->ip_vhl & 0x0f)
#define IP_V(ip) ((GET_U_1((ip)->ip_vhl) & 0xf0) >> 4)
#define IP_HL(ip) (GET_U_1((ip)->ip_vhl) & 0x0f)
nd_uint8_t ip_tos; /* type of service */
nd_uint16_t ip_len; /* total length */
nd_uint16_t ip_id; /* identification */

94
ip6.h
View File

@ -76,19 +76,19 @@
struct ip6_hdr {
union {
struct ip6_hdrctl {
uint32_t ip6_un1_flow; /* 20 bits of flow-ID */
uint16_t ip6_un1_plen; /* payload length */
uint8_t ip6_un1_nxt; /* next header */
uint8_t ip6_un1_hlim; /* hop limit */
nd_uint32_t ip6_un1_flow; /* 20 bits of flow-ID */
nd_uint16_t ip6_un1_plen; /* payload length */
nd_uint8_t ip6_un1_nxt; /* next header */
nd_uint8_t ip6_un1_hlim; /* hop limit */
} ip6_un1;
uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */
nd_uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */
} ip6_ctlun;
struct in6_addr ip6_src; /* source address */
struct in6_addr ip6_dst; /* destination address */
} UNALIGNED;
nd_ipv6 ip6_src; /* source address */
nd_ipv6 ip6_dst; /* destination address */
};
#define ip6_vfc ip6_ctlun.ip6_un2_vfc
#define IP6_VERSION(ip6_hdr) (((ip6_hdr)->ip6_vfc & 0xf0) >> 4)
#define IP6_VERSION(ip6_hdr) ((GET_U_1((ip6_hdr)->ip6_vfc) & 0xf0) >> 4)
#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
@ -98,36 +98,31 @@ struct ip6_hdr {
/* in network endian */
#define IPV6_FLOWINFO_MASK ((uint32_t)htonl(0x0fffffff)) /* flow info (28 bits) */
#define IPV6_FLOWLABEL_MASK ((uint32_t)htonl(0x000fffff)) /* flow label (20 bits) */
#if 1
/* ECN bits proposed by Sally Floyd */
#define IP6TOS_CE 0x01 /* congestion experienced */
#define IP6TOS_ECT 0x02 /* ECN-capable transport */
#endif
/*
* Extension Headers
*/
struct ip6_ext {
uint8_t ip6e_nxt;
uint8_t ip6e_len;
} UNALIGNED;
nd_uint8_t ip6e_nxt;
nd_uint8_t ip6e_len;
};
/* Hop-by-Hop options header */
struct ip6_hbh {
uint8_t ip6h_nxt; /* next header */
uint8_t ip6h_len; /* length in units of 8 octets */
nd_uint8_t ip6h_nxt; /* next header */
nd_uint8_t ip6h_len; /* length in units of 8 octets */
/* followed by options */
} UNALIGNED;
};
/* Destination options header */
struct ip6_dest {
uint8_t ip6d_nxt; /* next header */
uint8_t ip6d_len; /* length in units of 8 octets */
nd_uint8_t ip6d_nxt; /* next header */
nd_uint8_t ip6d_len; /* length in units of 8 octets */
/* followed by options */
} UNALIGNED;
};
/* http://www.iana.org/assignments/ipv6-parameters/ipv6-parameters.xhtml */
/* https://www.iana.org/assignments/ipv6-parameters/ipv6-parameters.xhtml */
/* Option types and related macros */
#define IP6OPT_PAD1 0x00 /* 00 0 00000 */
@ -165,35 +160,50 @@ struct ip6_dest {
/* Routing header */
struct ip6_rthdr {
uint8_t ip6r_nxt; /* next header */
uint8_t ip6r_len; /* length in units of 8 octets */
uint8_t ip6r_type; /* routing type */
uint8_t ip6r_segleft; /* segments left */
nd_uint8_t ip6r_nxt; /* next header */
nd_uint8_t ip6r_len; /* length in units of 8 octets */
nd_uint8_t ip6r_type; /* routing type */
nd_uint8_t ip6r_segleft; /* segments left */
/* followed by routing type specific data */
} UNALIGNED;
};
#define IPV6_RTHDR_TYPE_0 0
#define IPV6_RTHDR_TYPE_2 2
#define IPV6_RTHDR_TYPE_4 4
/* Type 0 Routing header */
/* Also used for Type 2 */
struct ip6_rthdr0 {
uint8_t ip6r0_nxt; /* next header */
uint8_t ip6r0_len; /* length in units of 8 octets */
uint8_t ip6r0_type; /* always zero */
uint8_t ip6r0_segleft; /* segments left */
uint8_t ip6r0_reserved; /* reserved field */
uint8_t ip6r0_slmap[3]; /* strict/loose bit map */
struct in6_addr ip6r0_addr[1]; /* up to 23 addresses */
} UNALIGNED;
nd_uint8_t ip6r0_nxt; /* next header */
nd_uint8_t ip6r0_len; /* length in units of 8 octets */
nd_uint8_t ip6r0_type; /* always zero */
nd_uint8_t ip6r0_segleft; /* segments left */
nd_uint32_t ip6r0_reserved; /* reserved field */
nd_ipv6 ip6r0_addr[1]; /* up to 23 addresses */
};
/**
* Type 4 Routing header
* known as Segment Routing Header 'SRH'
*/
struct ip6_srh {
nd_uint8_t srh_nxt; /* next header */
nd_uint8_t srh_len; /* length in units of 8 octets */
nd_uint8_t srh_type; /* Routing Type 4 */
nd_uint8_t srh_segleft; /* segments left */
nd_uint8_t srh_last_ent; /* Last Entry*/
nd_uint8_t srh_flags; /* Flags */
nd_uint16_t srh_tag; /* Tag */
nd_ipv6 srh_segments[1]; /* SRH segments list*/
};
/* Fragment header */
struct ip6_frag {
uint8_t ip6f_nxt; /* next header */
uint8_t ip6f_reserved; /* reserved field */
uint16_t ip6f_offlg; /* offset, reserved, and flag */
uint32_t ip6f_ident; /* identification */
} UNALIGNED;
nd_uint8_t ip6f_nxt; /* next header */
nd_uint8_t ip6f_reserved; /* reserved field */
nd_uint16_t ip6f_offlg; /* offset, reserved, and flag */
nd_uint32_t ip6f_ident; /* identification */
};
#define IP6F_OFF_MASK 0xfff8 /* mask out offset from ip6f_offlg */
#define IP6F_RESERVED_MASK 0x0006 /* reserved bits in ip6f_offlg */

315
ipproto.c
View File

@ -10,14 +10,14 @@
* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
* Original code by Hannes Gredler (hannes@juniper.net)
* Original code by Hannes Gredler (hannes@gredler.at)
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "ipproto.h"
@ -46,11 +46,316 @@ const struct tok ipproto_values[] = {
{ IPPROTO_OSPF, "OSPF" },
{ IPPROTO_PIM, "PIM" },
{ IPPROTO_IPCOMP, "Compressed IP" },
{ IPPROTO_VRRP, "VRRP" },
{ IPPROTO_VRRP, "VRRP" }, /* See also CARP. */
{ IPPROTO_PGM, "PGM" },
{ IPPROTO_SCTP, "SCTP" },
{ IPPROTO_MOBILITY, "Mobility" },
{ IPPROTO_CARP, "CARP" },
{ 0, NULL }
};
/*
* For completeness the number space in the array below comes from IANA:
* https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
* However, the spelling tries to match that of /etc/protocols to achieve as
* much consistency as possible with the previously implemented behaviour,
* which was based on getprotobynumber (3).
*/
static const char *netdb_protocol_names[256] = {
"hopopt", /* 0 (IPPROTO_HOPOPTS, IPv6 Hop-by-Hop Option) */
"icmp", /* 1 (IPPROTO_ICMP, Internet Control Message) */
"igmp", /* 2 (IPPROTO_IGMP, Internet Group Management) */
"ggp", /* 3 (Gateway-to-Gateway) */
"ipencap", /* 4 (IPPROTO_IPV4, IPv4 encapsulation) */
"st", /* 5 (Stream, ST datagram mode) */
"tcp", /* 6 (IPPROTO_TCP, Transmission Control) */
"cbt", /* 7 (CBT) */
"egp", /* 8 (IPPROTO_EGP, Exterior Gateway Protocol) */
"igp", /* 9 (IPPROTO_PIGP, "any private interior gateway
* (used by Cisco for their IGRP)")
*/
"bbn-rcc-mon", /* 10 (BBN RCC Monitoring) */
"nvp-ii", /* 11 (Network Voice Protocol) */
"pup", /* 12 (PARC universal packet protocol) */
"argus", /* 13 (ARGUS) */
"emcon", /* 14 (EMCON) */
"xnet", /* 15 (Cross Net Debugger) */
"chaos", /* 16 (Chaos) */
"udp", /* 17 (IPPROTO_UDP, User Datagram) */
"mux", /* 18 (Multiplexing) */
"dcn-meas", /* 19 (DCN Measurement Subsystems) */
"hmp", /* 20 (Host Monitoring) */
"prm", /* 21 (Packet Radio Measurement) */
"xns-idp", /* 22 (XEROX NS IDP) */
"trunk-1", /* 23 (Trunk-1) */
"trunk-2", /* 24 (Trunk-2) */
"leaf-1", /* 25 (Leaf-1) */
"leaf-2", /* 26 (Leaf-2) */
"rdp", /* 27 (Reliable Data Protocol) */
"irtp", /* 28 (Internet Reliable Transaction) */
"iso-tp4", /* 29 (ISO Transport Protocol Class 4) */
"netblt", /* 30 (Bulk Data Transfer Protocol) */
"mfe-nsp", /* 31 (MFE Network Services Protocol) */
"merit-inp", /* 32 (MERIT Internodal Protocol) */
"dccp", /* 33 (IPPROTO_DCCP, Datagram Congestion
* Control Protocol)
*/
"3pc", /* 34 (Third Party Connect Protocol) */
"idpr", /* 35 (Inter-Domain Policy Routing Protocol) */
"xtp", /* 36 (Xpress Transfer Protocol) */
"ddp", /* 37 (Datagram Delivery Protocol) */
"idpr-cmtp", /* 38 (IDPR Control Message Transport Proto) */
"tp++", /* 39 (TP++ Transport Protocol) */
"il", /* 40 (IL Transport Protocol) */
"ipv6", /* 41 (IPPROTO_IPV6, IPv6 encapsulation) */
"sdrp", /* 42 (Source Demand Routing Protocol) */
"ipv6-route", /* 43 (IPPROTO_ROUTING, Routing Header for IPv6) */
"ipv6-frag", /* 44 (IPPROTO_FRAGMENT, Fragment Header for
* IPv6)
*/
"idrp", /* 45 (Inter-Domain Routing Protocol) */
"rsvp", /* 46 (IPPROTO_RSVP, Reservation Protocol) */
"gre", /* 47 (IPPROTO_GRE, Generic Routing
* Encapsulation)
*/
"dsr", /* 48 (Dynamic Source Routing Protocol) */
"bna", /* 49 (BNA) */
"esp", /* 50 (IPPROTO_ESP, Encap Security Payload) */
"ah", /* 51 (IPPROTO_AH, Authentication Header) */
"i-nlsp", /* 52 (Integrated Net Layer Security TUBA) */
"swipe", /* 53 (IP with Encryption) */
"narp", /* 54 (NBMA Address Resolution Protocol) */
"mobile", /* 55 (IPPROTO_MOBILE, IP Mobility) */
"tlsp", /* 56 (Transport Layer Security Protocol using
* Kryptonet key management)
*/
"skip", /* 57 (SKIP) */
"ipv6-icmp", /* 58 (IPPROTO_ICMPV6, ICMP for IPv6) */
"ipv6-nonxt", /* 59 (IPPROTO_NONE, No Next Header for IPv6) */
"ipv6-opts", /* 60 (IPPROTO_DSTOPTS, Destination Options for
* IPv6)
*/
NULL, /* 61 (any host internal protocol) */
"cftp", /* 62 (IPPROTO_MOBILITY_OLD, CFTP, see the note
* in ipproto.h)
*/
NULL, /* 63 (any local network) */
"sat-expak", /* 64 (SATNET and Backroom EXPAK) */
"kryptolan", /* 65 (Kryptolan) */
"rvd", /* 66 (MIT Remote Virtual Disk Protocol) */
"ippc", /* 67 (Internet Pluribus Packet Core) */
NULL, /* 68 (any distributed file system) */
"sat-mon", /* 69 (SATNET Monitoring) */
"visa", /* 70 (VISA Protocol) */
"ipcv", /* 71 (Internet Packet Core Utility) */
"cpnx", /* 72 (Computer Protocol Network Executive) */
"rspf", /* 73 (Radio Shortest Path First, CPHB -- Computer
* Protocol Heart Beat -- in IANA)
*/
"wsn", /* 74 (Wang Span Network) */
"pvp", /* 75 (Packet Video Protocol) */
"br-sat-mon", /* 76 (Backroom SATNET Monitoring) */
"sun-nd", /* 77 (IPPROTO_ND, SUN ND PROTOCOL-Temporary) */
"wb-mon", /* 78 (WIDEBAND Monitoring) */
"wb-expak", /* 79 (WIDEBAND EXPAK) */
"iso-ip", /* 80 (ISO Internet Protocol) */
"vmtp", /* 81 (Versatile Message Transport) */
"secure-vmtp", /* 82 (Secure VMTP) */
"vines", /* 83 (VINES) */
"ttp", /* 84 (Transaction Transport Protocol, also IPTM --
* Internet Protocol Traffic Manager)
*/
"nsfnet-igp", /* 85 (NSFNET-IGP) */
"dgp", /* 86 (Dissimilar Gateway Protocol) */
"tcf", /* 87 (TCF) */
"eigrp", /* 88 (IPPROTO_EIGRP, Cisco EIGRP) */
"ospf", /* 89 (IPPROTO_OSPF, Open Shortest Path First
* IGP)
*/
"sprite-rpc", /* 90 (Sprite RPC Protocol) */
"larp", /* 91 (Locus Address Resolution Protocol) */
"mtp", /* 92 (Multicast Transport Protocol) */
"ax.25", /* 93 (AX.25 Frames) */
"ipip", /* 94 (IP-within-IP Encapsulation Protocol) */
"micp", /* 95 (Mobile Internetworking Control Pro.) */
"scc-sp", /* 96 (Semaphore Communications Sec. Pro.) */
"etherip", /* 97 (Ethernet-within-IP Encapsulation) */
"encap", /* 98 (Encapsulation Header) */
NULL, /* 99 (any private encryption scheme) */
"gmtp", /* 100 (GMTP) */
"ifmp", /* 101 (Ipsilon Flow Management Protocol) */
"pnni", /* 102 (PNNI over IP) */
"pim", /* 103 (IPPROTO_PIM, Protocol Independent
* Multicast)
*/
"aris", /* 104 (ARIS) */
"scps", /* 105 (SCPS) */
"qnx", /* 106 (QNX) */
"a/n", /* 107 (Active Networks) */
"ipcomp", /* 108 (IPPROTO_IPCOMP, IP Payload Compression
* Protocol)
*/
"snp", /* 109 (Sitara Networks Protocol) */
"compaq-peer", /* 110 (Compaq Peer Protocol) */
"ipx-in-ip", /* 111 (IPX in IP) */
"vrrp", /* 112 (IPPROTO_VRRP, Virtual Router Redundancy
* Protocol)
*/
"pgm", /* 113 (IPPROTO_PGM, PGM Reliable Transport
* Protocol)
*/
NULL, /* 114 (any 0-hop protocol) */
"l2tp", /* 115 (Layer Two Tunneling Protocol) */
"ddx", /* 116 (D-II Data Exchange (DDX)) */
"iatp", /* 117 (Interactive Agent Transfer Protocol) */
"stp", /* 118 (Schedule Transfer Protocol) */
"srp", /* 119 (SpectraLink Radio Protocol) */
"uti", /* 120 (UTI) */
"smp", /* 121 (Simple Message Protocol) */
"sm", /* 122 (Simple Multicast Protocol) */
"ptp", /* 123 (Performance Transparency Protocol) */
"isis", /* 124 (ISIS over IPv4) */
"fire", /* 125 (FIRE) */
"crtp", /* 126 (Combat Radio Transport Protocol) */
"crudp", /* 127 (Combat Radio User Datagram) */
"sscopmce", /* 128 (SSCOPMCE) */
"iplt", /* 129 (IPLT) */
"sps", /* 130 (Secure Packet Shield) */
"pipe", /* 131 (Private IP Encapsulation within IP) */
"sctp", /* 132 (IPPROTO_SCTP, Stream Control Transmission
* Protocol)
*/
"fc", /* 133 (Fibre Channel) */
"rsvp-e2e-ignore", /* 134 (RSVP-E2E-IGNORE) */
"mobility-header", /* 135 (IPPROTO_MOBILITY, Mobility Header) */
"udplite", /* 136 (UDPLite) */
"mpls-in-ip", /* 137 (MPLS-in-IP) */
"manet", /* 138 (MANET Protocols) */
"hip", /* 139 (Host Identity Protocol) */
"shim6", /* 140 (Shim6 Protocol) */
"wesp", /* 141 (Wrapped Encapsulating Security Payload) */
"rohc", /* 142 (Robust Header Compression) */
NULL, /* 143 (unassigned) */
NULL, /* 144 (unassigned) */
NULL, /* 145 (unassigned) */
NULL, /* 146 (unassigned) */
NULL, /* 147 (unassigned) */
NULL, /* 148 (unassigned) */
NULL, /* 149 (unassigned) */
NULL, /* 150 (unassigned) */
NULL, /* 151 (unassigned) */
NULL, /* 152 (unassigned) */
NULL, /* 153 (unassigned) */
NULL, /* 154 (unassigned) */
NULL, /* 155 (unassigned) */
NULL, /* 156 (unassigned) */
NULL, /* 157 (unassigned) */
NULL, /* 158 (unassigned) */
NULL, /* 159 (unassigned) */
NULL, /* 160 (unassigned) */
NULL, /* 161 (unassigned) */
NULL, /* 162 (unassigned) */
NULL, /* 163 (unassigned) */
NULL, /* 164 (unassigned) */
NULL, /* 165 (unassigned) */
NULL, /* 166 (unassigned) */
NULL, /* 167 (unassigned) */
NULL, /* 168 (unassigned) */
NULL, /* 169 (unassigned) */
NULL, /* 170 (unassigned) */
NULL, /* 171 (unassigned) */
NULL, /* 172 (unassigned) */
NULL, /* 173 (unassigned) */
NULL, /* 174 (unassigned) */
NULL, /* 175 (unassigned) */
NULL, /* 176 (unassigned) */
NULL, /* 177 (unassigned) */
NULL, /* 178 (unassigned) */
NULL, /* 179 (unassigned) */
NULL, /* 180 (unassigned) */
NULL, /* 181 (unassigned) */
NULL, /* 182 (unassigned) */
NULL, /* 183 (unassigned) */
NULL, /* 184 (unassigned) */
NULL, /* 185 (unassigned) */
NULL, /* 186 (unassigned) */
NULL, /* 187 (unassigned) */
NULL, /* 188 (unassigned) */
NULL, /* 189 (unassigned) */
NULL, /* 190 (unassigned) */
NULL, /* 191 (unassigned) */
NULL, /* 192 (unassigned) */
NULL, /* 193 (unassigned) */
NULL, /* 194 (unassigned) */
NULL, /* 195 (unassigned) */
NULL, /* 196 (unassigned) */
NULL, /* 197 (unassigned) */
NULL, /* 198 (unassigned) */
NULL, /* 199 (unassigned) */
NULL, /* 200 (unassigned) */
NULL, /* 201 (unassigned) */
NULL, /* 202 (unassigned) */
NULL, /* 203 (unassigned) */
NULL, /* 204 (unassigned) */
NULL, /* 205 (unassigned) */
NULL, /* 206 (unassigned) */
NULL, /* 207 (unassigned) */
NULL, /* 208 (unassigned) */
NULL, /* 209 (unassigned) */
NULL, /* 210 (unassigned) */
NULL, /* 211 (unassigned) */
NULL, /* 212 (unassigned) */
NULL, /* 213 (unassigned) */
NULL, /* 214 (unassigned) */
NULL, /* 215 (unassigned) */
NULL, /* 216 (unassigned) */
NULL, /* 217 (unassigned) */
NULL, /* 218 (unassigned) */
NULL, /* 219 (unassigned) */
NULL, /* 220 (unassigned) */
NULL, /* 221 (unassigned) */
NULL, /* 222 (unassigned) */
NULL, /* 223 (unassigned) */
NULL, /* 224 (unassigned) */
NULL, /* 225 (unassigned) */
NULL, /* 226 (unassigned) */
NULL, /* 227 (unassigned) */
NULL, /* 228 (unassigned) */
NULL, /* 229 (unassigned) */
NULL, /* 230 (unassigned) */
NULL, /* 231 (unassigned) */
NULL, /* 232 (unassigned) */
NULL, /* 233 (unassigned) */
NULL, /* 234 (unassigned) */
NULL, /* 235 (unassigned) */
NULL, /* 236 (unassigned) */
NULL, /* 237 (unassigned) */
NULL, /* 238 (unassigned) */
NULL, /* 239 (unassigned) */
NULL, /* 240 (unassigned) */
NULL, /* 241 (unassigned) */
NULL, /* 242 (unassigned) */
NULL, /* 243 (unassigned) */
NULL, /* 244 (unassigned) */
NULL, /* 245 (unassigned) */
NULL, /* 246 (unassigned) */
NULL, /* 247 (unassigned) */
NULL, /* 248 (unassigned) */
NULL, /* 249 (unassigned) */
NULL, /* 250 (unassigned) */
NULL, /* 251 (unassigned) */
NULL, /* 252 (unassigned) */
"exptest-253", /* 253 (Use for experimentation and testing,
* RFC 3692)
*/
"exptest-254", /* 254 (Use for experimentation and testing,
* RFC 3692)
*/
"reserved", /* 255 (reserved) */
};
/* The function enforces the array index to be 8-bit. */
const char *
netdb_protoname (const uint8_t protoid)
{
return netdb_protocol_names[protoid];
}

View File

@ -36,6 +36,7 @@
*/
extern const struct tok ipproto_values[];
extern const char *netdb_protoname (const uint8_t);
#ifndef IPPROTO_IP
#define IPPROTO_IP 0 /* dummy for IP */
@ -103,13 +104,12 @@ extern const struct tok ipproto_values[];
#ifndef IPPROTO_MOBILITY_OLD
/*
* The current Protocol Numbers list says that the IP protocol number for
* mobility headers is 135; it cites draft-ietf-mobileip-ipv6-24, but
* that draft doesn't actually give a number.
* mobility headers is 135; it cites RFC 6275 (obsoletes RFC 3775).
*
* 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
@ -129,10 +129,7 @@ extern const struct tok ipproto_values[];
#define IPPROTO_IPCOMP 108
#endif
#ifndef IPPROTO_VRRP
#define IPPROTO_VRRP 112
#endif
#ifndef IPPROTO_CARP
#define IPPROTO_CARP 112
#define IPPROTO_VRRP 112 /* See also CARP. */
#endif
#ifndef IPPROTO_PGM
#define IPPROTO_PGM 113

10
l2vpn.c
View File

@ -10,14 +10,14 @@
* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
* Original code by Hannes Gredler (hannes@juniper.net)
* Original code by Hannes Gredler (hannes@gredler.at)
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "l2vpn.h"
@ -26,7 +26,7 @@
*
* RFC 6624
*
* http://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml#bgp-l2-encapsulation-types-registry
* https://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml#bgp-l2-encapsulation-types-registry
*/
const struct tok l2vpn_encaps_values[] = {
{ 0, "Reserved"},
@ -61,7 +61,7 @@ const struct tok l2vpn_encaps_values[] = {
*
* RFC 4446
*
* http://www.iana.org/assignments/pwe3-parameters/pwe3-parameters.xhtml#pwe3-parameters-2
* https://www.iana.org/assignments/pwe3-parameters/pwe3-parameters.xhtml#pwe3-parameters-2
*/
const struct tok mpls_pw_types_values[] = {
{ 0x0000, "Reserved"},

View File

@ -10,7 +10,7 @@
* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
* Original code by Hannes Gredler (hannes@juniper.net)
* Original code by Hannes Gredler (hannes@gredler.at)
*/
extern const struct tok l2vpn_encaps_values[];

View File

@ -20,34 +20,18 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
/*
* XXX - all we need, on platforms other than DEC OSF/1 (a/k/a Digital UNIX,
* a/k/a Tru64 UNIX), is "size_t", which is a standard C type; what do we
* need to do to get it defined? This is clearly wrong, as we shouldn't
* have to include UNIX or Windows system header files to get it.
*/
#include <netdissect-stdinc.h>
#ifndef HAVE___ATTRIBUTE__
#define __attribute__(x)
#endif /* HAVE___ATTRIBUTE__ */
#include <stddef.h>
#ifdef __osf__
#include <stdio.h>
#include <sys/sysinfo.h>
#include <sys/proc.h>
#if !defined(HAVE_SNPRINTF)
int snprintf(char *, size_t, const char *, ...)
#ifdef __ATTRIBUTE___FORMAT_OK
__attribute__((format(printf, 3, 4)))
#endif /* __ATTRIBUTE___FORMAT_OK */
;
#endif /* !defined(HAVE_SNPRINTF) */
#endif /* __osf__ */
#include "varattrs.h"
#include "machdep.h"
/*

View File

@ -32,7 +32,7 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>

View File

@ -32,7 +32,7 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>

143
missing/getservent.c Normal file
View File

@ -0,0 +1,143 @@
/*
* Copyright (c) 1983, 1993 The Regents of the University of California.
* Copyright (c) 1993 Digital Equipment Corporation.
* Copyright (c) 2012 G. Vanem <gvanem@yahoo.no>.
* Copyright (c) 2017 Ali Abdulkadir <autostart.ini@gmail.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include <getservent.h>
static FILE *servf = NULL;
static char line[BUFSIZ+1];
static struct servent serv;
static char *serv_aliases[MAXALIASES];
int _serv_stayopen;
const char *etc_path(const char *file);
/*
* Check if <file> exists in the current directory and, if so, return it.
* Else return either "%SYSTEMROOT%\System32\drivers\etc\<file>"
* or $PREFIX/etc/<file>.
* "<file>" is aka __PATH_SERVICES (aka "services" on Windows and
* "/etc/services" on other platforms that would need this).
*/
const char *etc_path(const char *file)
{
const char *env = getenv(__PATH_SYSROOT);
static char path[_MAX_PATH];
/* see if "<file>" exists locally or whether __PATH_SYSROOT is valid */
if (fopen(file, "r") || !env)
return (file);
else
#ifdef _WIN32
snprintf(path, sizeof(path), "%s%s%s", env, __PATH_ETC_INET, file);
#else
snprintf(path, sizeof(path), "%s%s", env, file);
#endif
return (path);
}
void
setservent(int f)
{
if (servf == NULL)
servf = fopen(etc_path(__PATH_SERVICES), "r");
else
rewind(servf);
_serv_stayopen |= f;
}
void
endservent(void)
{
if (servf) {
fclose(servf);
servf = NULL;
}
_serv_stayopen = 0;
}
struct servent *
getservent(void)
{
char *p;
char *cp, **q;
if (servf == NULL && (servf = fopen(etc_path(__PATH_SERVICES), "r")) == NULL)
return (NULL);
again:
if ((p = fgets(line, BUFSIZ, servf)) == NULL)
return (NULL);
if (*p == '#')
goto again;
cp = strpbrk(p, "#\n");
if (cp == NULL)
goto again;
*cp = '\0';
serv.s_name = p;
p = strpbrk(p, " \t");
if (p == NULL)
goto again;
*p++ = '\0';
while (*p == ' ' || *p == '\t')
p++;
cp = strpbrk(p, ",/");
if (cp == NULL)
goto again;
*cp++ = '\0';
serv.s_port = htons((u_short)atoi(p));
serv.s_proto = cp;
q = serv.s_aliases = serv_aliases;
cp = strpbrk(cp, " \t");
if (cp != NULL)
*cp++ = '\0';
while (cp && *cp) {
if (*cp == ' ' || *cp == '\t') {
cp++;
continue;
}
if (q < &serv_aliases[MAXALIASES - 1])
*q++ = cp;
cp = strpbrk(cp, " \t");
if (cp != NULL)
*cp++ = '\0';
}
*q = NULL;
return (&serv);
}

46
missing/pcap_dump_ftell.c Normal file
View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Computer Systems
* Engineering Group at Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdio.h>
#include <pcap.h>
#include "pcap-missing.h"
long
pcap_dump_ftell(pcap_dumper_t *p)
{
/* FIXME: Using pcap_dump_file(p) would be a better style. That would
* require to test if pcap_dump_file() is available, and to substitute it,
* if it is not.
*/
return (ftell((FILE *)p));
}

View File

@ -67,25 +67,6 @@ struct state {
/* XXX - methods */
};
#ifndef HAVE_VSNPRINTF
static int
sn_reserve (struct state *state, size_t n)
{
return state->s + n > state->theend;
}
static int
sn_append_char (struct state *state, unsigned char c)
{
if (sn_reserve (state, 1)) {
return 1;
} else {
*state->s++ = c;
return 0;
}
}
#endif
#if 0
static int
as_reserve (struct state *state, size_t n)
@ -454,37 +435,6 @@ xyzprintf (struct state *state, const char *char_format, va_list ap)
return 0;
}
#ifndef HAVE_SNPRINTF
int
snprintf (char *str, size_t sz, const char *format, ...)
{
va_list args;
int ret;
va_start(args, format);
ret = vsnprintf (str, sz, format, args);
#ifdef PARANOIA
{
int ret2;
char *tmp;
tmp = malloc (sz);
if (tmp == NULL)
abort ();
ret2 = vsprintf (tmp, format, args);
if (ret != ret2 || strcmp(str, tmp))
abort ();
free (tmp);
}
#endif
va_end(args);
return ret;
}
#endif
#if 0
#ifndef HAVE_ASPRINTF
int
@ -516,48 +466,9 @@ asprintf (char **ret, const char *format, ...)
}
#endif
#ifndef HAVE_ASNPRINTF
int
asnprintf (char **ret, size_t max_sz, const char *format, ...)
{
va_list args;
int val;
va_start(args, format);
val = vasnprintf (ret, max_sz, format, args);
#ifdef PARANOIA
{
int ret2;
char *tmp;
tmp = malloc (val + 1);
if (tmp == NULL)
abort ();
ret2 = vsprintf (tmp, format, args);
if (val != ret2 || strcmp(*ret, tmp))
abort ();
free (tmp);
}
#endif
va_end(args);
return val;
}
#endif
#ifndef HAVE_VASPRINTF
int
vasprintf (char **ret, const char *format, va_list args)
{
return vasnprintf (ret, 0, format, args);
}
#endif
#ifndef HAVE_VASNPRINTF
int
vasnprintf (char **ret, size_t max_sz, const char *format, va_list args)
nd_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args)
{
int st;
size_t len;
@ -597,29 +508,3 @@ vasnprintf (char **ret, size_t max_sz, const char *format, va_list args)
}
#endif
#endif
#ifndef HAVE_VSNPRINTF
int
vsnprintf (char *str, size_t sz, const char *format, va_list args)
{
struct state state;
int ret;
unsigned char *ustr = (unsigned char *)str;
state.max_sz = 0;
state.sz = sz;
state.str = ustr;
state.s = ustr;
state.theend = ustr + sz - 1;
state.append_char = sn_append_char;
state.reserve = sn_reserve;
ret = xyzprintf (&state, format, args);
*state.s = '\0';
if (ret)
return sz;
else
return state.s - state.str;
}
#endif

View File

@ -47,9 +47,9 @@
size_t
strlcat(char *dst, const char *src, size_t siz)
{
register char *d = dst;
register const char *s = src;
register size_t n = siz;
char *d = dst;
const char *s = src;
size_t n = siz;
size_t dlen;
/* Find the end of dst and adjust bytes left but don't go past end */

View File

@ -46,9 +46,9 @@
size_t
strlcpy(char *dst, const char *src, size_t siz)
{
register char *d = dst;
register const char *s = src;
register size_t n = siz;
char *d = dst;
const char *s = src;
size_t n = siz;
/* Copy as many bytes as will fit */
if (n != 0 && --n != 0) {

View File

@ -55,9 +55,9 @@
char *
strsep(char **stringp, const char *delim)
{
register char *s;
register const char *spanp;
register int c, sc;
char *s;
const char *spanp;
int c, sc;
char *tok;
if ((s = *stringp) == NULL)

View File

@ -24,19 +24,16 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "ether.h"
#include "missing/win_ether_ntohost.h"
#include "netdissect.h"
#include "addrtoname.h"
typedef struct ether_addr {
unsigned char octet[ETHER_ADDR_LEN];
} ether_address;
typedef struct ether_entry {
ether_address eth_addr; /* MAC address */
char *name; /* name of MAC-address */
@ -125,7 +122,7 @@ int parse_ether_buf (const char *buf, char **result, struct ether_addr *e)
else
fmt = "%02x-%02x-%02x-%02x-%02x-%02x";
if (sscanf(str, fmt, &eth[0], &eth[1], &eth[2], &eth[3], &eth[4], &eth[5]) != ETHER_ADDR_LEN)
if (sscanf(str, fmt, &eth[0], &eth[1], &eth[2], &eth[3], &eth[4], &eth[5]) != MAC_ADDR_LEN)
return (0);
str = strtok (str, " \t");
@ -136,7 +133,7 @@ int parse_ether_buf (const char *buf, char **result, struct ether_addr *e)
*result = name;
for (i = 0; i < ETHER_ADDR_LEN; i++)
for (i = 0; i < MAC_ADDR_LEN; i++)
e->octet[i] = eth[i];
return (1);
@ -175,7 +172,7 @@ static int init_ethers (void)
if (!e)
break;
memcpy(&e->eth_addr, &eth, ETHER_ADDR_LEN);
memcpy(&e->eth_addr, &eth, MAC_ADDR_LEN);
e->name = strdup(name);
if (!e->name) {
free(e);
@ -210,7 +207,7 @@ int ether_ntohost (char *name, struct ether_addr *e)
}
for (cache = eth0; cache; cache = cache->next)
if (!memcmp(&e->octet, &cache->eth_addr, ETHER_ADDR_LEN)) {
if (!memcmp(&e->octet, &cache->eth_addr, MAC_ADDR_LEN)) {
strcpy (name,cache->name);
return (0);
}

View File

@ -1,7 +1,4 @@
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
@ -17,15 +14,20 @@
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* tcpdump/Win32 functions for reading and parsing system's Ethernet
* address file:
* '%SystemRoot%/drivers/etc/ethers' (Win-NT+)
* or '%Windir%/etc/ethers' (Win-9x/ME)
*
* G. Vanem <gvanem@yahoo.no> 2012.
*/
#include <stdio.h>
#include <pcap.h>
/*
* The number of bytes in an ethernet (MAC) address.
*/
#define ETHER_ADDR_LEN 6
#include "pcap-missing.h"
long
pcap_dump_ftell(pcap_dumper_t *p)
{
return (ftell((FILE *)p));
}
typedef struct ether_addr {
unsigned char octet[ETHER_ADDR_LEN];
} ether_address;

27
mkdep
View File

@ -16,7 +16,10 @@
MAKE=Makefile # default makefile name is "Makefile"
CC=cc # default C compiler is "cc"
DEPENDENCY_CFLAG=-M # default dependency-generation flag is -M
SOURCE_DIRECTORY=. # default source directory is the current directory
# No command-line flags seen yet.
flags=""
while :
do case "$1" in
# -c allows you to specify the C compiler
@ -39,13 +42,24 @@ while :
-p)
SED='s;\.o;;'
shift ;;
# -s allows you to specify the source directory
-s)
SOURCE_DIRECTORY=$2
shift; shift ;;
# other command-line flag
-*)
flags="$flags $1"
shift ;;
*)
break ;;
esac
done
if [ $# = 0 ] ; then
echo 'usage: mkdep [-p] [-c cc] [-f makefile] [-m dependency-cflag] [flags] file ...'
echo 'usage: mkdep [-p] [-c cc] [-f makefile] [-m dependency-cflag] [-s source-directory] [flags] file ...'
exit 1
fi
@ -76,8 +90,17 @@ _EOF_
# egrep '^#include[ ]*".*"' /dev/null $* |
# sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
#
# Construct a list of source files with paths relative to the source directory.
#
sources=""
for srcfile in $*
do
sources="$sources $SOURCE_DIRECTORY/$srcfile"
done
# XXX this doesn't work with things like "-DDECLWAITSTATUS=union\ wait"
$CC $DEPENDENCY_CFLAG $* |
$CC $DEPENDENCY_CFLAG $flags $sources |
sed "
s; \./; ;g
$SED" |

152
nameser.h
View File

@ -175,7 +175,7 @@
#define T_UID 101 /* user ID */
#define T_GID 102 /* group ID */
#define T_UNSPEC 103 /* Unspecified format (binary data) */
#define T_UNSPECA 104 /* "unspecified ascii". Ugly MIT hack */
#define T_UNSPECA 104 /* "unspecified ASCII". Ugly MIT hack */
/* Query type values which do not appear in resource records */
#define T_TKEY 249 /* Transaction Key [RFC2930] */
#define T_TSIG 250 /* Transaction Signature [RFC2845] */
@ -184,6 +184,7 @@
#define T_MAILB 253 /* transfer mailbox records */
#define T_MAILA 254 /* transfer mail agent records */
#define T_ANY 255 /* wildcard match */
#define T_URI 256 /* uri records [RFC7553] */
/*
* Values for class field
@ -197,6 +198,64 @@
#define C_QU 0x8000 /* mDNS QU flag in queries */
#define C_CACHE_FLUSH 0x8000 /* mDNS cache flush flag in replies */
/*
* Values for EDNS option types
*/
#define E_LLQ 1 /* long lived queries protocol */
#define E_UL 2 /* dynamic dns update leases */
#define E_NSID 3 /* name server identifier */
#define E_DAU 5 /* signal DNSSEC algorithm understood */
#define E_DHU 6 /* signal DS hash understood */
#define E_N3U 7 /* signal NSEC3 hash understood */
#define E_ECS 8 /* EDNS client subnet */
#define E_EXPIRE 9 /* zone expiration */
#define E_COOKIE 10 /* DNS cookies */
#define E_KEEPALIVE 11 /* TCP keepalive */
#define E_PADDING 12 /* pad DNS messages */
#define E_CHAIN 13 /* chain DNS queries */
#define E_KEYTAG 14 /* EDNS key tag */
#define E_CLIENTTAG 16 /* EDNS client tag */
#define E_SERVERTAG 17 /* EDNS server tag */
/*
* Values for DNSSEC Algorithms
* https://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml
*/
#define A_DELETE 0
#define A_RSAMD5 1
#define A_DH 2
#define A_DSA 3
#define A_RSASHA1 5
#define A_DSA_NSEC3_SHA1 6
#define A_RSASHA1_NSEC3_SHA1 7
#define A_RSASHA256 8
#define A_RSASHA512 10
#define A_ECC_GOST 12
#define A_ECDSAP256SHA256 13
#define A_ECDSAP384SHA384 14
#define A_ED25519 15
#define A_ED448 16
#define A_INDIRECT 252
#define A_PRIVATEDNS 253
#define A_PRIVATEOID 254
/*
* Values for NSEC3 algorithms
* https://www.iana.org/assignments/dnssec-nsec3-parameters/dnssec-nsec3-parameters.xhtml
*/
#define NSEC_SHA1 1
/*
* Values for delegation signer algorithms
* https://www.iana.org/assignments/ds-rr-types/ds-rr-types.xhtml
*/
#define DS_SHA1 1
#define DS_SHA256 2
#define DS_GOST 3
#define DS_SHA384 4
/*
* Status return codes for T_UNSPEC conversion routines
*/
@ -210,28 +269,26 @@
* Structure for query header.
*/
typedef struct {
uint16_t id; /* query identification number */
uint8_t flags1; /* first byte of flags */
uint8_t flags2; /* second byte of flags */
uint16_t qdcount; /* number of question entries */
uint16_t ancount; /* number of answer entries */
uint16_t nscount; /* number of authority entries */
uint16_t arcount; /* number of resource entries */
} HEADER;
nd_uint16_t id; /* query identification number */
nd_uint16_t flags; /* QR, Opcode, AA, TC, RD, RA, RCODE */
nd_uint16_t qdcount; /* number of question entries */
nd_uint16_t ancount; /* number of answer entries */
nd_uint16_t nscount; /* number of authority entries */
nd_uint16_t arcount; /* number of resource entries */
} dns_header_t;
/*
* Macros for subfields of flag fields.
*/
#define DNS_QR(np) ((np)->flags1 & 0x80) /* response flag */
#define DNS_OPCODE(np) ((((np)->flags1) >> 3) & 0xF) /* purpose of message */
#define DNS_AA(np) ((np)->flags1 & 0x04) /* authoritative answer */
#define DNS_TC(np) ((np)->flags1 & 0x02) /* truncated message */
#define DNS_RD(np) ((np)->flags1 & 0x01) /* recursion desired */
#define DNS_RA(np) ((np)->flags2 & 0x80) /* recursion available */
#define DNS_AD(np) ((np)->flags2 & 0x20) /* authentic data from named */
#define DNS_CD(np) ((np)->flags2 & 0x10) /* checking disabled by resolver */
#define DNS_RCODE(np) ((np)->flags2 & 0xF) /* response code */
#define DNS_QR(flags) ((flags) & 0x8000) /* response flag */
#define DNS_OPCODE(flags) (((flags) >> 11) & 0xF) /* purpose of message */
#define DNS_AA(flags) (flags & 0x0400) /* authoritative answer */
#define DNS_TC(flags) (flags & 0x0200) /* truncated message */
#define DNS_RD(flags) (flags & 0x0100) /* recursion desired */
#define DNS_RA(flags) (flags & 0x0080) /* recursion available */
#define DNS_AD(flags) (flags & 0x0020) /* authentic data from named */
#define DNS_CD(flags) (flags & 0x0010) /* checking disabled by resolver */
#define DNS_RCODE(flags) (flags & 0x000F) /* response code */
/*
* Defines for handling compressed domain names, EDNS0 labels, etc.
@ -240,61 +297,4 @@ typedef struct {
#define EDNS0_MASK 0x40 /* 01.... */
# define EDNS0_ELT_BITLABEL 0x01
/*
* Structure for passing resource records around.
*/
struct rrec {
int16_t r_zone; /* zone number */
int16_t r_class; /* class number */
int16_t r_type; /* type number */
uint32_t r_ttl; /* time to live */
int r_size; /* size of data area */
char *r_data; /* pointer to data */
};
/*
* Inline versions of get/put short/long. Pointer is advanced.
* We also assume that a "uint16_t" holds 2 "chars"
* and that a "uint32_t" holds 4 "chars".
*
* These macros demonstrate the property of C whereby it can be
* portable or it can be elegant but never both.
*/
#define GETSHORT(s, cp) { \
register u_char *t_cp = (u_char *)(cp); \
(s) = ((uint16_t)t_cp[0] << 8) | (uint16_t)t_cp[1]; \
(cp) += 2; \
}
#define GETLONG(l, cp) { \
register u_char *t_cp = (u_char *)(cp); \
(l) = (((uint32_t)t_cp[0]) << 24) \
| (((uint32_t)t_cp[1]) << 16) \
| (((uint32_t)t_cp[2]) << 8) \
| (((uint32_t)t_cp[3])); \
(cp) += 4; \
}
#define PUTSHORT(s, cp) { \
register uint16_t t_s = (uint16_t)(s); \
register u_char *t_cp = (u_char *)(cp); \
*t_cp++ = t_s >> 8; \
*t_cp = t_s; \
(cp) += 2; \
}
/*
* Warning: PUTLONG --no-longer-- destroys its first argument. if you
* were depending on this "feature", you will lose.
*/
#define PUTLONG(l, cp) { \
register uint32_t t_l = (uint32_t)(l); \
register u_char *t_cp = (u_char *)(cp); \
*t_cp++ = t_l >> 24; \
*t_cp++ = t_l >> 16; \
*t_cp++ = t_l >> 8; \
*t_cp = t_l; \
(cp) += 4; \
}
#endif /* !_NAMESER_H_ */

62
netdissect-alloc.c Normal file
View File

@ -0,0 +1,62 @@
/*
* Copyright (c) 2018 The TCPDUMP project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code
* distributions retain the above copyright notice and this paragraph
* in its entirety, and (2) distributions including binary code include
* the above copyright notice and this paragraph in its entirety in
* the documentation or other materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND
* WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include "netdissect-alloc.h"
/*
* nd_free_all() is intended to be used after a packet printing
*/
/* Add a memory chunk in allocation linked list */
void
nd_add_alloc_list(netdissect_options *ndo, nd_mem_chunk_t *chunkp)
{
if (ndo->ndo_last_mem_p == NULL) /* first memory allocation */
chunkp->prev_mem_p = NULL;
else /* previous memory allocation */
chunkp->prev_mem_p = ndo->ndo_last_mem_p;
ndo->ndo_last_mem_p = chunkp;
}
/* malloc replacement, with tracking in a linked list */
void *
nd_malloc(netdissect_options *ndo, size_t size)
{
nd_mem_chunk_t *chunkp = malloc(sizeof(nd_mem_chunk_t) + size);
if (chunkp == NULL)
return NULL;
nd_add_alloc_list(ndo, chunkp);
return chunkp + 1;
}
/* Free chunks in allocation linked list from last to first */
void
nd_free_all(netdissect_options *ndo)
{
nd_mem_chunk_t *current, *previous;
current = ndo->ndo_last_mem_p;
while (current != NULL) {
previous = current->prev_mem_p;
free(current);
current = previous;
}
ndo->ndo_last_mem_p = NULL;
}

33
netdissect-alloc.h Normal file
View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2018 The TCPDUMP project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code
* distributions retain the above copyright notice and this paragraph
* in its entirety, and (2) distributions including binary code include
* the above copyright notice and this paragraph in its entirety in
* the documentation or other materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND
* WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE.
*/
#ifndef netdissect_alloc_h
#define netdissect_alloc_h
#include <stdarg.h>
#include "netdissect-stdinc.h"
#include "netdissect.h"
typedef struct nd_mem_chunk {
void *prev_mem_p;
/* variable size data */
} nd_mem_chunk_t;
void nd_add_alloc_list(netdissect_options *, nd_mem_chunk_t *);
void * nd_malloc(netdissect_options *, size_t);
void nd_free_all(netdissect_options *);
#endif /* netdissect_alloc_h */

56
netdissect-ctype.h Normal file
View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 1988-1997
* The Regents of the University of California. All rights reserved.
*
* Copyright (c) 1998-2012 Michael Richardson <mcr@tcpdump.org>
* The TCPDUMP project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University nor the names of its contributors may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef netdissect_ctype_h
#define netdissect_ctype_h
/*
* Locale-independent macros for testing character properties and
* stripping the 8th bit from characters.
*
* Byte values outside the ASCII range are considered unprintable, so
* both ND_ASCII_ISPRINT() and ND_ASCII_ISGRAPH() return "false" for them.
*
* Assumed to be handed a value between 0 and 255, i.e. don't hand them
* a char, as those might be in the range -128 to 127.
*/
#define ND_ISASCII(c) (!((c) & 0x80)) /* value is an ASCII code point */
#define ND_ASCII_ISPRINT(c) ((c) >= 0x20 && (c) <= 0x7E)
#define ND_ASCII_ISGRAPH(c) ((c) > 0x20 && (c) <= 0x7E)
#define ND_ASCII_ISDIGIT(c) ((c) >= '0' && (c) <= '9')
#define ND_TOASCII(c) ((c) & 0x7F)
/*
* Locale-independent macros for coverting to upper or lower case.
*
* Byte values outside the ASCII range are not converted. Byte values
* *in* the ASCII range are converted to byte values in the ASCII range;
* in particular, 'i' is upper-cased to 'I" and 'I' is lower-cased to 'i',
* even in Turkish locales.
*/
#define ND_ASCII_TOLOWER(c) (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A' + 'a' : (c))
#define ND_ASCII_TOUPPER(c) (((c) >= 'a' && (c) <= 'z') ? (c) - 'a' + 'A' : (c))
#endif /* netdissect-ctype.h */

View File

@ -41,118 +41,150 @@
#include <errno.h>
#include "compiler-tests.h"
#include "varattrs.h"
/*
* If we're compiling with Visual Studio, make sure we have at least
* VS 2015 or later, so we have sufficient C99 support.
*
* XXX - verify that we have at least C99 support on UN*Xes?
*
* What about MinGW or various DOS toolchains? We're currently assuming
* sufficient C99 support there.
*/
#if defined(_MSC_VER)
/*
* Make sure we have VS 2015 or later.
*/
#if _MSC_VER < 1900
#error "Building tcpdump requires VS 2015 or later"
#endif
#endif
/*
* Get the C99 types, and the PRI[doux]64 format strings, defined.
*/
#ifdef HAVE_PCAP_PCAP_INTTYPES_H
/*
* We have pcap/pcap-inttypes.h; use that, as it'll do all the
* work, and won't cause problems if a file includes this file
* and later includes a pcap header file that also includes
* pcap/pcap-inttypes.h.
*/
#include <pcap/pcap-inttypes.h>
#else
/*
* OK, we don't have pcap/pcap-inttypes.h, so we'll have to
* do the work ourselves, but at least we don't have to
* worry about other headers including it and causing
* clashes.
*/
/*
* Include <inttypes.h> to get the integer types and PRi[doux]64 values
* defined.
*
* If the compiler is MSVC, we require VS 2015 or newer, so we
* have <inttypes.h> - and support for %zu in the formatted
* printing functions.
*
* If the compiler is MinGW, we assume we have <inttypes.h> - and
* support for %zu in the formatted printing functions.
*
* If the target is UN*X, we assume we have a C99-or-later development
* environment, and thus have <inttypes.h> - and support for %zu in
* the formatted printing functions.
*
* If the target is MS-DOS, we assume we have <inttypes.h> - and support
* for %zu in the formatted printing functions.
*/
#include <inttypes.h>
#if defined(_MSC_VER)
/*
* Suppress definition of intN_t in bittypes.h, which might be included
* by <pcap/pcap.h> in older versions of WinPcap.
* (Yes, HAVE_U_INTn_T, as the definition guards are UN*X-oriented.)
*/
#define HAVE_U_INT8_T
#define HAVE_U_INT16_T
#define HAVE_U_INT32_T
#define HAVE_U_INT64_T
#endif
#endif /* HAVE_PCAP_PCAP_INTTYPES_H */
#ifdef _WIN32
/*
* Includes and definitions for Windows.
*/
#include <stdint.h>
#include <stdio.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <ctype.h>
#include <time.h>
#include <io.h>
#include <fcntl.h>
#include <sys/types.h>
#ifndef uint8_t
#define uint8_t unsigned char
#ifdef _MSC_VER
/*
* Compiler is MSVC.
*
* We require VS 2015 or newer, so we have strtoll(). Use that for
* strtoint64_t().
*/
#define strtoint64_t strtoll
/*
* And we have LL as a suffix for constants, so use that.
*/
#define INT64_T_CONSTANT(constant) (constant##LL)
#else
/*
* Non-Microsoft compiler.
*
* XXX - should we use strtoll or should we use _strtoi64()?
*/
#define strtoint64_t strtoll
/*
* Assume LL works.
*/
#define INT64_T_CONSTANT(constant) (constant##LL)
#endif
#ifndef int8_t
#define int8_t signed char
#endif
#ifndef uint16_t
#define uint16_t unsigned short
#endif
#ifndef int16_t
#define int16_t signed short
#endif
#ifndef uint32_t
#define uint32_t unsigned int
#endif
#ifndef int32_t
#define int32_t signed int
#endif
#ifdef _MSC_EXTENSIONS
#ifndef uint64_t
#define uint64_t unsigned _int64
#endif
#ifndef int64_t
#define int64_t _int64
#endif
#ifndef PRId64
#define PRId64 "I64d"
#endif
#ifndef PRIo64
#define PRIo64 "I64o"
#endif
#ifndef PRIu64
#define PRIu64 "I64u"
#endif
#ifndef PRIx64
#define PRIx64 "I64x"
#endif
#else /* _MSC_EXTENSIONS */
#ifndef uint64_t
#define uint64_t unsigned long long
#endif
#ifndef int64_t
#define int64_t long long
#endif
#ifndef PRId64
#define PRId64 "lld"
#endif
#ifndef PRIo64
#define PRIo64 "llo"
#endif
#ifndef PRIu64
#define PRIu64 "llu"
#endif
#ifndef PRIx64
#define PRIx64 "llx"
#endif
#endif /* _MSC_EXTENSIONS */
/*
* Suppress definition of intN_t in bittypes.h, as included by <pcap/pcap.h>
* on Windows.
* (Yes, HAVE_U_INTn_T, as the definition guards are UN*X-oriented, and
* we check for u_intN_t in the UN*X configure script.)
*/
#define HAVE_U_INT8_T
#define HAVE_U_INT16_T
#define HAVE_U_INT32_T
#define HAVE_U_INT64_T
#ifdef _MSC_VER
#define stat _stat
#define open _open
#define fstat _fstat
#define read _read
#define close _close
#define O_RDONLY _O_RDONLY
/*
* Microsoft tries to avoid polluting the C namespace with UN*Xisms,
* by adding a preceding underscore; we *want* the UN*Xisms, so add
* #defines to let us use them.
*/
#define isatty _isatty
#define stat _stat
#define strdup _strdup
#define open _open
#define fstat _fstat
#define read _read
#define close _close
#define O_RDONLY _O_RDONLY
/*
* If <crtdbg.h> has been included, and _DEBUG is defined, and
* __STDC__ is zero, <crtdbg.h> will define strdup() to call
* _strdup_dbg(). So if it's already defined, don't redefine
* it.
*/
#ifndef strdup
#define strdup _strdup
#endif
/*
* Windows doesn't have ssize_t; routines such as _read() return int.
*/
typedef int ssize_t;
#endif /* _MSC_VER */
/*
@ -162,7 +194,7 @@
#define inline __inline
#endif
#ifdef AF_INET6
#if defined(AF_INET6) && !defined(HAVE_OS_IPV6_SUPPORT)
#define HAVE_OS_IPV6_SUPPORT
#endif
@ -181,9 +213,6 @@ typedef char* caddr_t;
#endif /* caddr_t */
#define MAXHOSTNAMELEN 64
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#define RETSIGTYPE void
#else /* _WIN32 */
@ -191,68 +220,34 @@ typedef char* caddr_t;
* Includes and definitions for various flavors of UN*X.
*/
#include <ctype.h>
#include <unistd.h>
#include <netdb.h>
#if HAVE_INTTYPES_H
#include <inttypes.h>
#elif HAVE_STDINT_H
#include <stdint.h>
#endif
#include <sys/param.h>
#include <sys/types.h> /* concession to AIX */
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#ifdef TIME_WITH_SYS_TIME
#include <time.h>
#endif
#include <arpa/inet.h>
#endif /* _WIN32 */
#ifndef HAVE___ATTRIBUTE__
#define __attribute__(x)
#endif
/*
* Assume all UN*Xes have strtoll(), and use it for strtoint64_t().
*/
#define strtoint64_t strtoll
/*
* Used to declare a structure unaligned, so that the C compiler,
* if necessary, generates code that doesn't assume alignment.
* This is required because there is no guarantee that the packet
* data we get from libpcap/WinPcap is properly aligned.
*
* This assumes that, for all compilers that support __attribute__:
*
* 1) they support __attribute__((packed));
*
* 2) for all instruction set architectures requiring strict
* alignment, declaring a structure with that attribute
* causes the compiler to generate code that handles
* misaligned 2-byte, 4-byte, and 8-byte integral
* quantities.
*
* It does not (yet) handle compilers where you can get the compiler
* to generate code of that sort by some other means.
*
* This is required in order to, for example, keep the compiler from
* generating, for
*
* if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) {
*
* in print-bootp.c, code that loads the first 4-byte word of a
* "struct bootp", masking out the bp_hops field, and comparing the result
* against 0x01010600.
*
* Note: this also requires that padding be put into the structure,
* at least for compilers where it's implemented as __attribute__((packed)).
* Assume LL works.
*/
#if !(defined(_MSC_VER) && defined(UNALIGNED))
/* MSVC may have its own macro defined with the same name and purpose. */
#undef UNALIGNED
#define UNALIGNED __attribute__((packed))
#endif
#define INT64_T_CONSTANT(constant) (constant##LL)
#endif /* _WIN32 */
/*
* Function attributes, for various compilers.
*/
#include "funcattrs.h"
/*
* fopen() read and write modes for text files and binary files.
@ -275,8 +270,8 @@ typedef char* caddr_t;
* an 80386, so, for example, it avoids the bswap instruction added in
* the 80486.
*
* (We don't use them on OS X; Apple provides their own, which *doesn't*
* avoid the bswap instruction, as OS X only supports machines that
* (We don't use them on macOS; Apple provides their own, which *doesn't*
* avoid the bswap instruction, as macOS only supports machines that
* have it.)
*/
#if defined(__GNUC__) && defined(__i386__) && !defined(__APPLE__) && !defined(__ntohl)
@ -361,7 +356,20 @@ struct in6_addr {
#define DIAG_JOINSTR(x,y) XSTRINGIFY(x ## y)
#define DIAG_DO_PRAGMA(x) _Pragma (#x)
#if defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
/*
* The current clang compilers also define __GNUC__ and __GNUC_MINOR__
* thus we need to test the clang case before the GCC one
*/
#if defined(__clang__)
# if (__clang_major__ * 100) + __clang_minor__ >= 208
# define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(clang diagnostic x)
# define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
# define DIAG_ON(x) DIAG_PRAGMA(pop)
# else
# define DIAG_OFF(x)
# define DIAG_ON(x)
# endif
#elif defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
# define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(GCC diagnostic x)
# if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406
# define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
@ -370,15 +378,20 @@ struct in6_addr {
# define DIAG_OFF(x) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
# define DIAG_ON(x) DIAG_PRAGMA(warning DIAG_JOINSTR(-W,x))
# endif
#elif defined(__clang__) && ((__clang_major__ * 100) + __clang_minor__ >= 208)
# define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(clang diagnostic x)
# define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
# define DIAG_ON(x) DIAG_PRAGMA(pop)
#else
# define DIAG_OFF(x)
# define DIAG_ON(x)
#endif
/* Use for clang specific warnings */
#ifdef __clang__
# define DIAG_OFF_CLANG(x) DIAG_OFF(x)
# define DIAG_ON_CLANG(x) DIAG_ON(x)
#else
# define DIAG_OFF_CLANG(x)
# define DIAG_ON_CLANG(x)
#endif
/*
* For dealing with APIs which are only deprecated in OSX (like the OpenSSL API)
*/
@ -394,11 +407,26 @@ struct in6_addr {
* end of Apple deprecation workaround macros
*/
#ifndef min
#define min(a,b) ((a)>(b)?(b):(a))
#endif
#ifndef max
#define max(a,b) ((b)>(a)?(b):(a))
#endif
/*
* Statement attributes, for various compilers.
*
* This was introduced sufficiently recently that compilers implementing
* it also implement __has_attribute() (for example, GCC 5.0 and later
* have __has_attribute(), and the "fallthrough" attribute was introduced
* in GCC 7).
*
* Unfortunately, Clang does this wrong - a statement
*
* __attribute__ ((fallthrough));
*
* produces bogus -Wmissing-declaration "declaration does not declare
* anything" warnings (dear Clang: that's not a declaration, it's an
* empty statement). GCC, however, has no trouble with this.
*/
#if __has_attribute(fallthrough) && !defined(__clang__)
# define ND_FALL_THROUGH __attribute__ ((fallthrough))
#else
# define ND_FALL_THROUGH
#endif /* __has_attribute(fallthrough) */
#endif /* netdissect_stdinc_h */

View File

@ -23,13 +23,14 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include "netdissect.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef USE_LIBSMI
#include <smi.h>
@ -144,3 +145,92 @@ nd_smi_version_string(void)
return (NULL);
#endif
}
int
nd_push_buffer(netdissect_options *ndo, u_char *new_buffer,
const u_char *new_packetp, const u_char *new_snapend)
{
struct netdissect_saved_packet_info *ndspi;
ndspi = (struct netdissect_saved_packet_info *)malloc(sizeof(struct netdissect_saved_packet_info));
if (ndspi == NULL)
return (0); /* fail */
ndspi->ndspi_buffer = new_buffer;
ndspi->ndspi_packetp = ndo->ndo_packetp;
ndspi->ndspi_snapend = ndo->ndo_snapend;
ndspi->ndspi_prev = ndo->ndo_packet_info_stack;
ndo->ndo_packetp = new_packetp;
ndo->ndo_snapend = new_snapend;
ndo->ndo_packet_info_stack = ndspi;
return (1); /* success */
}
/*
* Set a new snapshot end to the minimum of the existing snapshot end
* and the new snapshot end.
*/
int
nd_push_snapend(netdissect_options *ndo, const u_char *new_snapend)
{
struct netdissect_saved_packet_info *ndspi;
ndspi = (struct netdissect_saved_packet_info *)malloc(sizeof(struct netdissect_saved_packet_info));
if (ndspi == NULL)
return (0); /* fail */
ndspi->ndspi_buffer = NULL; /* no new buffer */
ndspi->ndspi_packetp = ndo->ndo_packetp;
ndspi->ndspi_snapend = ndo->ndo_snapend;
ndspi->ndspi_prev = ndo->ndo_packet_info_stack;
/* No new packet pointer, either */
if (new_snapend < ndo->ndo_snapend)
ndo->ndo_snapend = new_snapend;
ndo->ndo_packet_info_stack = ndspi;
return (1); /* success */
}
/*
* Change an already-pushed snapshot end. This may increase the
* snapshot end, as it may be used, for example, for a Jumbo Payload
* option in IPv6. It must not increase it past the snapshot length
* atop which the current one was pushed, however.
*/
void
nd_change_snapend(netdissect_options *ndo, const u_char *new_snapend)
{
struct netdissect_saved_packet_info *ndspi;
ndspi = ndo->ndo_packet_info_stack;
if (ndspi->ndspi_prev != NULL) {
if (new_snapend <= ndspi->ndspi_prev->ndspi_snapend)
ndo->ndo_snapend = new_snapend;
} else {
if (new_snapend < ndo->ndo_snapend)
ndo->ndo_snapend = new_snapend;
}
}
void
nd_pop_packet_info(netdissect_options *ndo)
{
struct netdissect_saved_packet_info *ndspi;
ndspi = ndo->ndo_packet_info_stack;
ndo->ndo_packetp = ndspi->ndspi_packetp;
ndo->ndo_snapend = ndspi->ndspi_snapend;
ndo->ndo_packet_info_stack = ndspi->ndspi_prev;
free(ndspi->ndspi_buffer);
free(ndspi);
}
void
nd_pop_all_packet_info(netdissect_options *ndo)
{
while (ndo->ndo_packet_info_stack != NULL)
nd_pop_packet_info(ndo);
}

View File

@ -29,10 +29,8 @@
#include "os-proto.h"
#endif
#include <sys/types.h>
#ifndef HAVE___ATTRIBUTE__
#define __attribute__(x)
#endif
#include <setjmp.h>
#include "status-exit-codes.h"
/*
* Data types corresponding to multi-byte integral values within data
@ -41,7 +39,11 @@
* use the EXTRACT_ macros to extract them (which you should be doing
* *anyway*, so as not to assume a particular byte order or alignment
* in your code).
*
* We even want EXTRACT_U_1 used for 8-bit integral values, so we
* define nd_uint8_t and nd_int8_t as arrays as well.
*/
typedef unsigned char nd_uint8_t[1];
typedef unsigned char nd_uint16_t[2];
typedef unsigned char nd_uint24_t[3];
typedef unsigned char nd_uint32_t[4];
@ -50,26 +52,65 @@ typedef unsigned char nd_uint48_t[6];
typedef unsigned char nd_uint56_t[7];
typedef unsigned char nd_uint64_t[8];
/*
* Use this for IPv4 addresses. It's defined as an array of octets, so
* that it's not aligned on its "natural" boundary, and it's defined as
* a structure in the hopes that this makes it harder to naively use
* EXTRACT_32BITS() to extract the value - in many cases you just want
* to use UNALIGNED_MEMCPY() to copy its value, so that it remains in
* network byte order.
*/
typedef struct {
unsigned char bytes[4];
} nd_ipv4;
typedef signed char nd_int8_t[1];
/*
* Data types corresponding to single-byte integral values, for
* completeness.
* "unsigned char" so that sign extension isn't done on the
* individual bytes while they're being assembled.
*/
typedef unsigned char nd_uint8_t;
typedef signed char nd_int8_t;
typedef unsigned char nd_int32_t[4];
typedef unsigned char nd_int64_t[8];
/* snprintf et al */
/*
* Use this for IPv4 addresses and netmasks.
*
* It's defined as an array of octets, so that it's not guaranteed to
* be aligned on its "natural" boundary (in some packet formats, it
* *isn't* so aligned). We have separate EXTRACT_ calls for them;
* sometimes you want the host-byte-order value, other times you want
* the network-byte-order value.
*
* Don't use EXTRACT_BE_U_4() on them, use EXTRACT_IPV4_TO_HOST_ORDER()
* if you want them in host byte order and EXTRACT_IPV4_TO_NETWORK_ORDER()
* if you want them in network byte order (which you want with system APIs
* that expect network-order IPv4 addresses, such as inet_ntop()).
*
* If, on your little-endian machine (e.g., an "IBM-compatible PC", no matter
* what the OS, or an Intel Mac, no matter what the OS), you get the wrong
* answer, and you've used EXTRACT_BE_U_4(), do *N*O*T* "fix" this by using
* EXTRACT_LE_U_4(), fix it by using EXTRACT_IPV4_TO_NETWORK_ORDER(),
* otherwise you're breaking the result on big-endian machines (e.g.,
* most PowerPC/Power ISA machines, System/390 and z/Architecture, SPARC,
* etc.).
*
* Yes, people do this; that's why Wireshark has tvb_get_ipv4(), to extract
* an IPv4 address from a packet data buffer; it was introduced in reaction
* to somebody who *had* done that.
*/
typedef unsigned char nd_ipv4[4];
/*
* Use this for IPv6 addresses and netmasks.
*/
typedef unsigned char nd_ipv6[16];
/*
* Use this for MAC addresses.
*/
#define MAC_ADDR_LEN 6 /* length of MAC addresses */
typedef unsigned char nd_mac_addr[MAC_ADDR_LEN];
/*
* Use this for blobs of bytes; make them arrays of nd_byte.
*/
typedef unsigned char nd_byte;
/*
* Round up x to a multiple of y; y must be a power of 2.
*/
#ifndef roundup2
#define roundup2(x, y) (((x)+((u_int)((y)-1)))&(~((u_int)((y)-1))))
#endif
#include <stdarg.h>
#include <pcap.h>
@ -77,26 +118,6 @@ typedef signed char nd_int8_t;
#include "ip.h" /* struct ip for nextproto4_cksum() */
#include "ip6.h" /* struct ip6 for nextproto6_cksum() */
extern int32_t thiszone; /* seconds offset from gmt to local time */
/* invalid string to print '(invalid)' for malformed or corrupted packets */
extern const char istr[];
#if !defined(HAVE_SNPRINTF)
int snprintf (char *str, size_t sz, const char *format, ...)
#ifdef __ATTRIBUTE___FORMAT_OK
__attribute__((format (printf, 3, 4)))
#endif /* __ATTRIBUTE___FORMAT_OK */
;
#endif /* !defined(HAVE_SNPRINTF) */
#if !defined(HAVE_VSNPRINTF)
int vsnprintf (char *str, size_t sz, const char *format, va_list ap)
#ifdef __ATTRIBUTE___FORMAT_OK
__attribute__((format (printf, 3, 0)))
#endif /* __ATTRIBUTE___FORMAT_OK */
;
#endif /* !defined(HAVE_VSNPRINTF) */
#ifndef HAVE_STRLCAT
extern size_t strlcat (char *, const char *, size_t);
#endif
@ -143,13 +164,47 @@ typedef struct netdissect_options netdissect_options;
#define IF_PRINTER_ARGS (netdissect_options *, const struct pcap_pkthdr *, const u_char *)
typedef u_int (*if_printer) IF_PRINTER_ARGS;
typedef u_int (*uint_if_printer) IF_PRINTER_ARGS;
typedef void (*void_if_printer) IF_PRINTER_ARGS;
/* pointer to the uint_if_printer or the void_if_printer function */
typedef union {
uint_if_printer uint_printer;
void_if_printer void_printer;
void* printer; /* generic when testing if NULL or not */
} if_printer_t;
/*
* In case the data in a buffer needs to be processed by being decrypted,
* decompressed, etc. before it's dissected, we can't process it in place,
* we have to allocate a new buffer for the processed data.
*
* We keep a stack of those buffers; when we allocate a new buffer, we
* push the current one onto a stack, and when we're done with the new
* buffer, we free the current buffer and pop the previous one off the
* stack.
*
* A buffer has a beginnning and end pointer, and a link to the previous
* buffer on the stack.
*
* In other cases, we temporarily adjust the snapshot end to reflect a
* packet-length field in the packet data and, when finished dissecting
* that part of the packet, restore the old snapshot end. We keep that
* on the stack with null buffer pointer, meaning there's nothing to
* free.
*/
struct netdissect_saved_packet_info {
u_char *ndspi_buffer; /* pointer to allocated buffer data */
const u_char *ndspi_packetp; /* saved beginning of data */
const u_char *ndspi_snapend; /* saved end of data */
struct netdissect_saved_packet_info *ndspi_prev; /* previous buffer on the stack */
};
struct netdissect_options {
int ndo_bflag; /* print 4 byte ASes in ASDOT notation */
int ndo_eflag; /* print ethernet header */
int ndo_fflag; /* don't translate "foreign" IP address */
int ndo_Kflag; /* don't check TCP checksums */
int ndo_Kflag; /* don't check IP, TCP or UDP checksums */
int ndo_nflag; /* leave addresses as numbers */
int ndo_Nflag; /* remove domains from printed host names */
int ndo_qflag; /* quick (shorter) output */
@ -158,11 +213,14 @@ struct netdissect_options {
int ndo_uflag; /* Print undecoded NFS handles */
int ndo_vflag; /* verbosity level */
int ndo_xflag; /* print packet in hex */
int ndo_Xflag; /* print packet in hex/ascii */
int ndo_Aflag; /* print packet only in ascii observing TAB,
int ndo_Xflag; /* print packet in hex/ASCII */
int ndo_Aflag; /* print packet only in ASCII observing TAB,
* LF, CR and SPACE as graphical chars
*/
int ndo_Hflag; /* dissect 802.11s draft mesh standard */
const char *ndo_protocol; /* protocol */
jmp_buf ndo_truncated; /* jmp_buf for setjmp()/longjmp() */
void *ndo_last_mem_p; /* pointer to the last allocated memory chunk */
int ndo_packet_number; /* print a packet number in the beginning of line */
int ndo_suppress_default_print; /* don't use default_print() for unknown packet types */
int ndo_tstamp_precision; /* requested time stamp precision */
@ -177,44 +235,45 @@ struct netdissect_options {
int ndo_packettype; /* as specified by -T */
int ndo_snaplen;
int ndo_ll_header_length; /* link-layer header length */
/*global pointers to beginning and end of current packet (during printing) */
const u_char *ndo_packetp;
const u_char *ndo_snapend;
/* pointer to the if_printer function */
if_printer ndo_if_printer;
/* stack of saved packet boundary and buffer information */
struct netdissect_saved_packet_info *ndo_packet_info_stack;
/* pointer to the uint_if_printer or the void_if_printer function */
if_printer_t ndo_if_printer;
int ndo_void_printer; /* void_if_printer ? (FALSE/TRUE) */
/* pointer to void function to output stuff */
void (*ndo_default_print)(netdissect_options *,
register const u_char *bp, register u_int length);
const u_char *bp, u_int length);
/* pointer to function to do regular output */
int (*ndo_printf)(netdissect_options *,
const char *fmt, ...)
#ifdef __ATTRIBUTE___FORMAT_OK_FOR_FUNCTION_POINTERS
__attribute__ ((format (printf, 2, 3)))
#endif
;
PRINTFLIKE_FUNCPTR(2, 3);
/* pointer to function to output errors */
void (*ndo_error)(netdissect_options *,
const char *fmt, ...)
#ifdef __ATTRIBUTE___NORETURN_OK_FOR_FUNCTION_POINTERS
__attribute__ ((noreturn))
#endif /* __ATTRIBUTE___NORETURN_OK_FOR_FUNCTION_POINTERS */
#ifdef __ATTRIBUTE___FORMAT_OK_FOR_FUNCTION_POINTERS
__attribute__ ((format (printf, 2, 3)))
#endif /* __ATTRIBUTE___FORMAT_OK_FOR_FUNCTION_POINTERS */
;
void NORETURN_FUNCPTR (*ndo_error)(netdissect_options *,
status_exit_codes_t status,
const char *fmt, ...)
PRINTFLIKE_FUNCPTR(3, 4);
/* pointer to function to output warnings */
void (*ndo_warning)(netdissect_options *,
const char *fmt, ...)
#ifdef __ATTRIBUTE___FORMAT_OK_FOR_FUNCTION_POINTERS
__attribute__ ((format (printf, 2, 3)))
#endif
;
PRINTFLIKE_FUNCPTR(2, 3);
};
extern int nd_push_buffer(netdissect_options *, u_char *, const u_char *,
const u_char *);
extern int nd_push_snapend(netdissect_options *, const u_char *);
extern void nd_change_snapend(netdissect_options *, const u_char *);
extern void nd_pop_packet_info(netdissect_options *);
extern void nd_pop_all_packet_info(netdissect_options *);
#define PT_VAT 1 /* Visual Audio Tool */
#define PT_WB 2 /* distributed White Board */
#define PT_RPC 3 /* Remote Procedure Call */
@ -232,6 +291,9 @@ struct netdissect_options {
#define PT_PGM_ZMTP1 15 /* ZMTP/1.0 inside PGM (native or UDP-encapsulated) */
#define PT_LMP 16 /* Link Management Protocol */
#define PT_RESP 17 /* RESP */
#define PT_PTP 18 /* PTP */
#define PT_SOMEIP 19 /* Autosar SOME/IP Protocol */
#define PT_DOMAIN 20 /* Domain Name System (DNS) */
#ifndef min
#define min(a,b) ((a)>(b)?(b):(a))
@ -253,7 +315,7 @@ struct netdissect_options {
* 1) big enough for maximum-size Linux loopback packets (65549)
* and some USB packets captured with USBPcap:
*
* http://desowin.org/usbpcap/
* https://desowin.org/usbpcap/
*
* (> 131072, < 262144)
*
@ -264,27 +326,16 @@ struct netdissect_options {
* savefile header to control the size of the buffer they allocate,
* so a size of, say, 2^31-1 might not work well.
*
* XXX - does it need to be bigger still?
* XXX - does it need to be bigger still? Note that, for versions of
* libpcap with pcap_create()/pcap_activate(), if no -s flag is specified
* or -s 0 is specified, we won't set the snapshot length at all, and will
* let libpcap choose a snapshot length; newer versions may choose a bigger
* value than 262144 for D-Bus, for example.
*/
#define MAXIMUM_SNAPLEN 262144
/*
* The default snapshot length is the maximum.
*/
#define DEFAULT_SNAPLEN MAXIMUM_SNAPLEN
#define ESRC(ep) ((ep)->ether_shost)
#define EDST(ep) ((ep)->ether_dhost)
#ifndef NTOHL
#define NTOHL(x) (x) = ntohl(x)
#define NTOHS(x) (x) = ntohs(x)
#define HTONL(x) (x) = htonl(x)
#define HTONS(x) (x) = htons(x)
#endif
/*
* True if "l" bytes of "var" were captured.
* True if "l" bytes from "p" were captured.
*
* The "ndo->ndo_snapend - (l) <= ndo->ndo_snapend" checks to make sure
* "l" isn't so large that "ndo->ndo_snapend - (l)" underflows.
@ -300,7 +351,7 @@ struct netdissect_options {
* you subtract a positive integer from a pointer, the result is
* guaranteed to be less than the original pointer value). See
*
* http://www.kb.cert.org/vuls/id/162289
* https://www.kb.cert.org/vuls/id/162289
*/
/*
@ -310,21 +361,32 @@ struct netdissect_options {
*/
#define IS_NOT_NEGATIVE(x) (((x) > 0) || ((x) == 0))
#define ND_TTEST2(var, l) \
#define ND_TTEST_LEN(p, l) \
(IS_NOT_NEGATIVE(l) && \
((uintptr_t)ndo->ndo_snapend - (l) <= (uintptr_t)ndo->ndo_snapend && \
(uintptr_t)&(var) <= (uintptr_t)ndo->ndo_snapend - (l)))
(uintptr_t)(p) <= (uintptr_t)ndo->ndo_snapend - (l)))
/* True if "var" was captured */
#define ND_TTEST(var) ND_TTEST2(var, sizeof(var))
/* True if "*(p)" was captured */
#define ND_TTEST_SIZE(p) ND_TTEST_LEN(p, sizeof(*(p)))
/* Bail if "l" bytes of "var" were not captured */
#define ND_TCHECK2(var, l) if (!ND_TTEST2(var, l)) goto trunc
/* Bail out if "l" bytes from "p" were not captured */
#define ND_TCHECK_LEN(p, l) if (!ND_TTEST_LEN(p, l)) goto trunc
/* Bail if "var" was not captured */
#define ND_TCHECK(var) ND_TCHECK2(var, sizeof(var))
/* Bail out if "*(p)" was not captured */
#define ND_TCHECK_SIZE(p) ND_TCHECK_LEN(p, sizeof(*(p)))
#define ND_PRINT(STUFF) (*ndo->ndo_printf)STUFF
/*
* Number of bytes between two pointers.
*/
#define ND_BYTES_BETWEEN(p1, p2) ((u_int)(((const uint8_t *)(p1)) - (const uint8_t *)(p2)))
/*
* Number of bytes remaining in the captured data, starting at the
* byte pointed to by the argument.
*/
#define ND_BYTES_AVAILABLE_AFTER(p) ND_BYTES_BETWEEN(ndo->ndo_snapend, (p))
#define ND_PRINT(...) (ndo->ndo_printf)(ndo, __VA_ARGS__)
#define ND_DEFAULTPRINT(ap, length) (*ndo->ndo_default_print)(ndo, ap, length)
extern void ts_print(netdissect_options *, const struct timeval *);
@ -332,10 +394,11 @@ extern void signed_relts_print(netdissect_options *, int32_t);
extern void unsigned_relts_print(netdissect_options *, uint32_t);
extern void fn_print_char(netdissect_options *, u_char);
extern int fn_print(netdissect_options *, const u_char *, const u_char *);
extern u_int fn_printztn(netdissect_options *ndo, const u_char *, u_int, const u_char *);
extern int fn_printn(netdissect_options *, const u_char *, u_int, const u_char *);
extern int fn_printzp(netdissect_options *, const u_char *, u_int, const u_char *);
extern void fn_print_str(netdissect_options *, const u_char *);
extern int nd_print(netdissect_options *, const u_char *, const u_char *);
extern u_int nd_printztn(netdissect_options *, const u_char *, u_int, const u_char *);
extern int nd_printn(netdissect_options *, const u_char *, u_int, const u_char *);
extern int nd_printzp(netdissect_options *, const u_char *, u_int, const u_char *);
/*
* Flags for txtproto_print().
@ -343,23 +406,32 @@ extern int fn_printzp(netdissect_options *, const u_char *, u_int, const u_char
#define RESP_CODE_SECOND_TOKEN 0x00000001 /* response code is second token in response line */
extern void txtproto_print(netdissect_options *, const u_char *, u_int,
const char *, const char **, u_int);
const char **, u_int);
#if (defined(__i386__) || defined(_M_IX86) || defined(__X86__) || defined(__x86_64__) || defined(_M_X64)) || \
(defined(__arm__) || defined(_M_ARM) || defined(__aarch64__)) || \
(defined(__m68k__) && (!defined(__mc68000__) && !defined(__mc68010__))) || \
(defined(__ppc__) || defined(__ppc64__) || defined(_M_PPC) || defined(_ARCH_PPC) || defined(_ARCH_PPC64)) || \
(defined(__s390__) || defined(__s390x__) || defined(__zarch__)) || \
defined(__vax__)
/*
* Locale-independent macros for testing character properties and
* stripping the 8th bit from characters. Assumed to be handed
* a value between 0 and 255, i.e. don't hand them a char, as
* those might be in the range -128 to 127.
* The procesor natively handles unaligned loads, so just use memcpy()
* and memcmp(), to enable those optimizations.
*
* XXX - are those all the x86 tests we need?
* XXX - do we need to worry about ARMv1 through ARMv5, which didn't
* support unaligned loads, and, if so, do we need to worry about all
* of them, or just some of them, e.g. ARMv5?
* XXX - are those the only 68k tests we need not to generated
* unaligned accesses if the target is the 68000 or 68010?
* XXX - are there any tests we don't need, because some definitions are for
* compilers that also predefine the GCC symbols?
* XXX - do we need to test for both 32-bit and 64-bit versions of those
* architectures in all cases?
*/
#define ND_ISASCII(c) (!((c) & 0x80)) /* value is an ASCII code point */
#define ND_ISPRINT(c) ((c) >= 0x20 && (c) <= 0x7E)
#define ND_ISGRAPH(c) ((c) > 0x20 && (c) <= 0x7E)
#define ND_TOASCII(c) ((c) & 0x7F)
extern void safeputchar(netdissect_options *, const u_char);
extern void safeputs(netdissect_options *, const u_char *, const u_int);
#ifdef LBL_ALIGN
#define UNALIGNED_MEMCPY(p, q, l) memcpy((p), (q), (l))
#define UNALIGNED_MEMCMP(p, q, l) memcmp((p), (q), (l))
#else
/*
* The processor doesn't natively handle unaligned loads,
* and the compiler might "helpfully" optimize memcpy()
@ -375,13 +447,6 @@ extern void unaligned_memcpy(void *, const void *, size_t);
extern int unaligned_memcmp(const void *, const void *, size_t);
#define UNALIGNED_MEMCPY(p, q, l) unaligned_memcpy((p), (q), (l))
#define UNALIGNED_MEMCMP(p, q, l) unaligned_memcmp((p), (q), (l))
#else
/*
* The procesor natively handles unaligned loads, so just use memcpy()
* and memcmp(), to enable those optimizations.
*/
#define UNALIGNED_MEMCPY(p, q, l) memcpy((p), (q), (l))
#define UNALIGNED_MEMCMP(p, q, l) memcmp((p), (q), (l))
#endif
#define PLURAL_SUFFIX(n) \
@ -390,18 +455,26 @@ extern int unaligned_memcmp(const void *, const void *, size_t);
extern const char *tok2strary_internal(const char **, int, const char *, int);
#define tok2strary(a,f,i) tok2strary_internal(a, sizeof(a)/sizeof(a[0]),f,i)
extern if_printer lookup_printer(int);
extern uint_if_printer lookup_uint_printer(int);
extern void_if_printer lookup_void_printer(int);
extern if_printer_t lookup_printer(netdissect_options *, int);
#define ND_DEBUG {printf(" [%s:%d %s] ", __FILE__, __LINE__, __FUNCTION__); fflush(stdout);}
/* The DLT printer routines */
extern u_int ap1394_if_print IF_PRINTER_ARGS;
extern u_int arcnet_if_print IF_PRINTER_ARGS;
extern u_int arcnet_linux_if_print IF_PRINTER_ARGS;
extern void ap1394_if_print IF_PRINTER_ARGS;
extern void arcnet_if_print IF_PRINTER_ARGS;
extern void arcnet_linux_if_print IF_PRINTER_ARGS;
extern u_int atm_if_print IF_PRINTER_ARGS;
extern u_int bt_if_print IF_PRINTER_ARGS;
extern void bt_if_print IF_PRINTER_ARGS;
extern u_int brcm_tag_if_print IF_PRINTER_ARGS;
extern u_int brcm_tag_prepend_if_print IF_PRINTER_ARGS;
extern u_int chdlc_if_print IF_PRINTER_ARGS;
extern u_int cip_if_print IF_PRINTER_ARGS;
extern u_int enc_if_print IF_PRINTER_ARGS;
extern u_int dsa_if_print IF_PRINTER_ARGS;
extern u_int edsa_if_print IF_PRINTER_ARGS;
extern void enc_if_print IF_PRINTER_ARGS;
extern u_int ether_if_print IF_PRINTER_ARGS;
extern u_int fddi_if_print IF_PRINTER_ARGS;
extern u_int fr_if_print IF_PRINTER_ARGS;
@ -409,47 +482,52 @@ extern u_int ieee802_11_if_print IF_PRINTER_ARGS;
extern u_int ieee802_11_radio_avs_if_print IF_PRINTER_ARGS;
extern u_int ieee802_11_radio_if_print IF_PRINTER_ARGS;
extern u_int ieee802_15_4_if_print IF_PRINTER_ARGS;
extern u_int ieee802_15_4_tap_if_print IF_PRINTER_ARGS;
extern u_int ipfc_if_print IF_PRINTER_ARGS;
extern u_int ipnet_if_print IF_PRINTER_ARGS;
extern u_int juniper_atm1_print IF_PRINTER_ARGS;
extern u_int juniper_atm2_print IF_PRINTER_ARGS;
extern u_int juniper_chdlc_print IF_PRINTER_ARGS;
extern u_int juniper_es_print IF_PRINTER_ARGS;
extern u_int juniper_ether_print IF_PRINTER_ARGS;
extern u_int juniper_frelay_print IF_PRINTER_ARGS;
extern u_int juniper_ggsn_print IF_PRINTER_ARGS;
extern u_int juniper_mfr_print IF_PRINTER_ARGS;
extern u_int juniper_mlfr_print IF_PRINTER_ARGS;
extern u_int juniper_mlppp_print IF_PRINTER_ARGS;
extern u_int juniper_monitor_print IF_PRINTER_ARGS;
extern u_int juniper_ppp_print IF_PRINTER_ARGS;
extern u_int juniper_pppoe_atm_print IF_PRINTER_ARGS;
extern u_int juniper_pppoe_print IF_PRINTER_ARGS;
extern u_int juniper_services_print IF_PRINTER_ARGS;
extern u_int ipoib_if_print IF_PRINTER_ARGS;
extern void ipnet_if_print IF_PRINTER_ARGS;
extern u_int juniper_atm1_if_print IF_PRINTER_ARGS;
extern u_int juniper_atm2_if_print IF_PRINTER_ARGS;
extern u_int juniper_chdlc_if_print IF_PRINTER_ARGS;
extern u_int juniper_es_if_print IF_PRINTER_ARGS;
extern u_int juniper_ether_if_print IF_PRINTER_ARGS;
extern u_int juniper_frelay_if_print IF_PRINTER_ARGS;
extern u_int juniper_ggsn_if_print IF_PRINTER_ARGS;
extern u_int juniper_mfr_if_print IF_PRINTER_ARGS;
extern u_int juniper_mlfr_if_print IF_PRINTER_ARGS;
extern u_int juniper_mlppp_if_print IF_PRINTER_ARGS;
extern u_int juniper_monitor_if_print IF_PRINTER_ARGS;
extern u_int juniper_ppp_if_print IF_PRINTER_ARGS;
extern u_int juniper_pppoe_atm_if_print IF_PRINTER_ARGS;
extern u_int juniper_pppoe_if_print IF_PRINTER_ARGS;
extern u_int juniper_services_if_print IF_PRINTER_ARGS;
extern u_int lane_if_print IF_PRINTER_ARGS;
extern u_int ltalk_if_print IF_PRINTER_ARGS;
extern u_int mfr_if_print IF_PRINTER_ARGS;
extern u_int netanalyzer_if_print IF_PRINTER_ARGS;
extern u_int netanalyzer_transparent_if_print IF_PRINTER_ARGS;
extern u_int nflog_if_print IF_PRINTER_ARGS;
extern u_int null_if_print IF_PRINTER_ARGS;
extern void nflog_if_print IF_PRINTER_ARGS;
extern void null_if_print IF_PRINTER_ARGS;
extern u_int pflog_if_print IF_PRINTER_ARGS;
extern u_int pktap_if_print IF_PRINTER_ARGS;
extern u_int ppi_if_print IF_PRINTER_ARGS;
extern void pktap_if_print IF_PRINTER_ARGS;
extern void ppi_if_print IF_PRINTER_ARGS;
extern u_int ppp_bsdos_if_print IF_PRINTER_ARGS;
extern u_int ppp_hdlc_if_print IF_PRINTER_ARGS;
extern u_int ppp_if_print IF_PRINTER_ARGS;
extern u_int pppoe_if_print IF_PRINTER_ARGS;
extern u_int prism_if_print IF_PRINTER_ARGS;
extern u_int raw_if_print IF_PRINTER_ARGS;
extern u_int sl_bsdos_if_print IF_PRINTER_ARGS;
extern u_int sl_if_print IF_PRINTER_ARGS;
extern void raw_if_print IF_PRINTER_ARGS;
extern void sl_bsdos_if_print IF_PRINTER_ARGS;
extern void sl_if_print IF_PRINTER_ARGS;
extern u_int sll_if_print IF_PRINTER_ARGS;
extern u_int sunatm_if_print IF_PRINTER_ARGS;
extern u_int symantec_if_print IF_PRINTER_ARGS;
extern u_int sll2_if_print IF_PRINTER_ARGS;
extern void sunatm_if_print IF_PRINTER_ARGS;
extern void symantec_if_print IF_PRINTER_ARGS;
extern u_int token_if_print IF_PRINTER_ARGS;
extern u_int usb_linux_48_byte_print IF_PRINTER_ARGS;
extern u_int usb_linux_64_byte_print IF_PRINTER_ARGS;
extern void unsupported_if_print IF_PRINTER_ARGS;
extern void usb_linux_48_byte_if_print IF_PRINTER_ARGS;
extern void usb_linux_64_byte_if_print IF_PRINTER_ARGS;
extern u_int vsock_if_print IF_PRINTER_ARGS;
/*
* Structure passed to some printers to allow them to print
@ -469,50 +547,52 @@ struct lladdr_info {
/* The printer routines. */
extern void aarp_print(netdissect_options *, const u_char *, u_int);
extern int ah_print(netdissect_options *, register const u_char *);
extern int ah_print(netdissect_options *, const u_char *);
extern void ahcp_print(netdissect_options *, const u_char *, const u_int);
extern void aodv_print(netdissect_options *, const u_char *, u_int, int);
extern void aoe_print(netdissect_options *, const u_char *, const u_int);
extern int arista_ethertype_print(netdissect_options *,const u_char *, u_int);
extern void arp_print(netdissect_options *, const u_char *, u_int, u_int);
extern void ascii_print(netdissect_options *, const u_char *, u_int);
extern void atalk_print(netdissect_options *, const u_char *, u_int);
extern void atm_print(netdissect_options *, u_int, u_int, u_int, const u_char *, u_int, u_int);
extern void babel_print(netdissect_options *, const u_char *, u_int);
extern void bcm_li_print(netdissect_options *, const u_char *, u_int);
extern void beep_print(netdissect_options *, const u_char *, u_int);
extern void bfd_print(netdissect_options *, const u_char *, u_int, u_int);
extern void bgp_print(netdissect_options *, const u_char *, int);
extern char *bgp_vpn_rd_print (netdissect_options *, const u_char *);
extern void bgp_print(netdissect_options *, const u_char *, u_int);
extern const char *bgp_vpn_rd_print(netdissect_options *, const u_char *);
extern void bootp_print(netdissect_options *, const u_char *, u_int);
extern void calm_fast_print(netdissect_options *, const u_char *, u_int, const struct lladdr_info *);
extern void carp_print(netdissect_options *, const u_char *, u_int, int);
extern void carp_print(netdissect_options *, const u_char *, u_int, u_int);
extern void cdp_print(netdissect_options *, const u_char *, u_int, u_int);
extern void cfm_print(netdissect_options *, const u_char *, u_int);
extern u_int chdlc_print(netdissect_options *, register const u_char *, u_int);
extern u_int chdlc_print(netdissect_options *, const u_char *, u_int);
extern void cisco_autorp_print(netdissect_options *, const u_char *, u_int);
extern void cnfp_print(netdissect_options *, const u_char *);
extern void dccp_print(netdissect_options *, const u_char *, const u_char *, u_int);
extern void decnet_print(netdissect_options *, const u_char *, u_int, u_int);
extern void dhcp6_print(netdissect_options *, const u_char *, u_int);
extern int dstopt_print(netdissect_options *, const u_char *);
extern int dstopt_process(netdissect_options *, const u_char *);
extern void dtp_print(netdissect_options *, const u_char *, u_int);
extern void dvmrp_print(netdissect_options *, const u_char *, u_int);
extern void eap_print(netdissect_options *, const u_char *, u_int);
extern void egp_print(netdissect_options *, const u_char *, u_int);
extern void eigrp_print(netdissect_options *, const u_char *, u_int);
extern int esp_print(netdissect_options *, const u_char *, const int, const u_char *, int *, int *);
extern void esp_print(netdissect_options *, const u_char *, u_int, const u_char *, u_int, int, u_int);
extern u_int ether_print(netdissect_options *, const u_char *, u_int, u_int, void (*)(netdissect_options *, const u_char *), const u_char *);
extern u_int ether_switch_tag_print(netdissect_options *, const u_char *, u_int, u_int, void (*)(netdissect_options *, const u_char *), u_int);
extern int ethertype_print(netdissect_options *, u_short, const u_char *, u_int, u_int, const struct lladdr_info *, const struct lladdr_info *);
extern u_int fddi_print(netdissect_options *, const u_char *, u_int, u_int);
extern void forces_print(netdissect_options *, const u_char *, u_int);
extern u_int fr_print(netdissect_options *, register const u_char *, u_int);
extern u_int fr_print(netdissect_options *, const u_char *, u_int);
extern int frag6_print(netdissect_options *, const u_char *, const u_char *);
extern void ftp_print(netdissect_options *, const u_char *, u_int);
extern void geneve_print(netdissect_options *, const u_char *, u_int);
extern void geonet_print(netdissect_options *, const u_char *, u_int, const struct lladdr_info *);
extern void gre_print(netdissect_options *, const u_char *, u_int);
extern int hbhopt_print(netdissect_options *, const u_char *);
extern int hbhopt_process(netdissect_options *, const u_char *, int *, uint32_t *);
extern void hex_and_ascii_print(netdissect_options *, const char *, const u_char *, u_int);
extern void hex_and_ascii_print_with_offset(netdissect_options *, const char *, const u_char *, u_int, u_int);
extern void hex_print(netdissect_options *, const char *ident, const u_char *cp, u_int);
extern void hex_print_with_offset(netdissect_options *, const char *ident, const u_char *cp, u_int, u_int);
extern void hncp_print(netdissect_options *, const u_char *, u_int);
@ -520,18 +600,19 @@ extern void hsrp_print(netdissect_options *, const u_char *, u_int);
extern void http_print(netdissect_options *, const u_char *, u_int);
extern void icmp6_print(netdissect_options *, const u_char *, u_int, const u_char *, int);
extern void icmp_print(netdissect_options *, const u_char *, u_int, const u_char *, int);
extern u_int ieee802_15_4_print(netdissect_options *, const u_char *, u_int);
extern u_int ieee802_11_radio_print(netdissect_options *, const u_char *, u_int, u_int);
extern void igmp_print(netdissect_options *, const u_char *, u_int);
extern void igrp_print(netdissect_options *, const u_char *, u_int);
extern void ip6_print(netdissect_options *, const u_char *, u_int);
extern void ipN_print(netdissect_options *, const u_char *, u_int);
extern void ip_print(netdissect_options *, const u_char *, u_int);
extern void ip_print_inner(netdissect_options *, const u_char *, u_int, u_int nh, const u_char *);
extern void ipcomp_print(netdissect_options *, register const u_char *);
extern void ipcomp_print(netdissect_options *, const u_char *);
extern void ipx_netbios_print(netdissect_options *, const u_char *, u_int);
extern void ipx_print(netdissect_options *, const u_char *, u_int);
extern void isakmp_print(netdissect_options *, const u_char *, u_int, const u_char *);
extern void isakmp_rfc3948_print(netdissect_options *, const u_char *, u_int, const u_char *);
extern void isoclns_print(netdissect_options *, const u_char *, u_int, u_int);
extern void isakmp_rfc3948_print(netdissect_options *, const u_char *, u_int, const u_char *, int, int, u_int);
extern void isoclns_print(netdissect_options *, const u_char *, u_int);
extern void krb_print(netdissect_options *, const u_char *);
extern void l2tp_print(netdissect_options *, const u_char *, u_int);
extern void lane_print(netdissect_options *, const u_char *, u_int, u_int);
@ -550,8 +631,7 @@ extern void m3ua_print(netdissect_options *, const u_char *, const u_int);
extern int macsec_print(netdissect_options *, const u_char **,
u_int *, u_int *, u_int *,
u_short *);
extern void medsa_print(netdissect_options *, const u_char *, u_int, u_int, const struct lladdr_info *, const struct lladdr_info *);
extern u_int mfr_print(netdissect_options *, register const u_char *, u_int);
extern u_int mfr_print(netdissect_options *, const u_char *, u_int);
extern void mobile_print(netdissect_options *, const u_char *, u_int);
extern int mobility_print(netdissect_options *, const u_char *, const u_char *);
extern void mpcp_print(netdissect_options *, const u_char *, u_int);
@ -559,33 +639,34 @@ extern void mpls_print(netdissect_options *, const u_char *, u_int);
extern int mptcp_print(netdissect_options *, const u_char *, u_int, u_char);
extern void msdp_print(netdissect_options *, const u_char *, u_int);
extern void msnlb_print(netdissect_options *, const u_char *);
extern void nbt_tcp_print(netdissect_options *, const u_char *, int);
extern void nbt_udp137_print(netdissect_options *, const u_char *, int);
extern void nbt_udp138_print(netdissect_options *, const u_char *, int);
extern void netbeui_print(netdissect_options *, u_short, const u_char *, int);
extern void nbt_tcp_print(netdissect_options *, const u_char *, u_int);
extern void nbt_udp137_print(netdissect_options *, const u_char *, u_int);
extern void nbt_udp138_print(netdissect_options *, const u_char *, u_int);
extern void netbeui_print(netdissect_options *, u_short, const u_char *, u_int);
extern void nfsreply_print(netdissect_options *, const u_char *, u_int, const u_char *);
extern void nfsreply_print_noaddr(netdissect_options *, const u_char *, u_int, const u_char *);
extern void nfsreq_print_noaddr(netdissect_options *, const u_char *, u_int, const u_char *);
extern const u_char * ns_nprint (netdissect_options *, register const u_char *, register const u_char *);
extern void ns_print(netdissect_options *, const u_char *, u_int, int);
extern void nsh_print(netdissect_options *ndo, const u_char *bp, u_int len);
extern void nfsreply_noaddr_print(netdissect_options *, const u_char *, u_int, const u_char *);
extern void nfsreq_noaddr_print(netdissect_options *, const u_char *, u_int, const u_char *);
extern const u_char *fqdn_print(netdissect_options *, const u_char *, const u_char *);
extern void domain_print(netdissect_options *, const u_char *, u_int, int);
extern void nsh_print(netdissect_options *, const u_char *, u_int);
extern void ntp_print(netdissect_options *, const u_char *, u_int);
extern void oam_print(netdissect_options *, const u_char *, u_int, u_int);
extern void olsr_print(netdissect_options *, const u_char *, u_int, int);
extern void openflow_print(netdissect_options *, const u_char *, const u_int);
extern void ospf6_print(netdissect_options *, const u_char *, u_int);
extern void ospf_print(netdissect_options *, const u_char *, u_int, const u_char *);
extern int ospf_print_grace_lsa(netdissect_options *, const uint8_t *, u_int);
extern int ospf_print_te_lsa(netdissect_options *, const uint8_t *, u_int);
extern int ospf_grace_lsa_print(netdissect_options *, const u_char *, u_int);
extern int ospf_te_lsa_print(netdissect_options *, const u_char *, u_int);
extern void otv_print(netdissect_options *, const u_char *, u_int);
extern void pgm_print(netdissect_options *, const u_char *, u_int, const u_char *);
extern void pim_print(netdissect_options *, const u_char *, u_int, const u_char *);
extern void pimv1_print(netdissect_options *, const u_char *, u_int);
extern u_int ppp_print(netdissect_options *, register const u_char *, u_int);
extern u_int ppp_print(netdissect_options *, const u_char *, u_int);
extern u_int pppoe_print(netdissect_options *, const u_char *, u_int);
extern void pptp_print(netdissect_options *, const u_char *);
extern int print_unknown_data(netdissect_options *, const u_char *, const char *, int);
extern char *q922_string(netdissect_options *, const u_char *, u_int);
extern void ptp_print(netdissect_options *, const u_char *, u_int);
extern int print_unknown_data(netdissect_options *, const u_char *, const char *, u_int);
extern const char *q922_string(netdissect_options *, const u_char *, u_int);
extern void q933_print(netdissect_options *, const u_char *, u_int);
extern void radius_print(netdissect_options *, const u_char *, u_int);
extern void resp_print(netdissect_options *, const u_char *, u_int);
@ -596,18 +677,18 @@ extern void rrcp_print(netdissect_options *, const u_char *, u_int, const struct
extern void rsvp_print(netdissect_options *, const u_char *, u_int);
extern int rt6_print(netdissect_options *, const u_char *, const u_char *);
extern void rtsp_print(netdissect_options *, const u_char *, u_int);
extern void rx_print(netdissect_options *, register const u_char *, int, int, int, const u_char *);
extern void rx_print(netdissect_options *, const u_char *, u_int, u_int, u_int, const u_char *);
extern void sctp_print(netdissect_options *, const u_char *, const u_char *, u_int);
extern void sflow_print(netdissect_options *, const u_char *, u_int);
extern void ssh_print(netdissect_options *, const u_char *, u_int);
extern void sip_print(netdissect_options *, const u_char *, u_int);
extern void slow_print(netdissect_options *, const u_char *, u_int);
extern void smb_print_data(netdissect_options *, const unsigned char *, int);
extern void smb_tcp_print(netdissect_options *, const u_char *, int);
extern void smb_tcp_print(netdissect_options *, const u_char *, u_int);
extern void smtp_print(netdissect_options *, const u_char *, u_int);
extern int snap_print(netdissect_options *, const u_char *, u_int, u_int, const struct lladdr_info *, const struct lladdr_info *, u_int);
extern void snmp_print(netdissect_options *, const u_char *, u_int);
extern void stp_print(netdissect_options *, const u_char *, u_int);
extern void sunrpcrequest_print(netdissect_options *, const u_char *, u_int, const u_char *);
extern void sunrpc_print(netdissect_options *, const u_char *, u_int, const u_char *);
extern void syslog_print(netdissect_options *, const u_char *, u_int);
extern void tcp_print(netdissect_options *, const u_char *, u_int, const u_char *, int);
extern void telnet_print(netdissect_options *, const u_char *, u_int);
@ -616,17 +697,19 @@ extern void timed_print(netdissect_options *, const u_char *);
extern void tipc_print(netdissect_options *, const u_char *, u_int, u_int);
extern u_int token_print(netdissect_options *, const u_char *, u_int, u_int);
extern void udld_print(netdissect_options *, const u_char *, u_int);
extern void udp_print(netdissect_options *, const u_char *, u_int, const u_char *, int);
extern int vjc_print(netdissect_options *, register const char *, u_short);
extern void vqp_print(netdissect_options *, register const u_char *, register u_int);
extern void udp_print(netdissect_options *, const u_char *, u_int, const u_char *, int, u_int);
extern int vjc_print(netdissect_options *, const u_char *, u_short);
extern void vqp_print(netdissect_options *, const u_char *, u_int);
extern void vrrp_print(netdissect_options *, const u_char *, u_int, const u_char *, int);
extern void vtp_print(netdissect_options *, const u_char *, u_int);
extern void vxlan_gpe_print(netdissect_options *ndo, const u_char *bp, u_int len);
extern void vxlan_gpe_print(netdissect_options *, const u_char *, u_int);
extern void vxlan_print(netdissect_options *, const u_char *, u_int);
extern void wb_print(netdissect_options *, const void *, u_int);
extern void wb_print(netdissect_options *, const u_char *, u_int);
extern void zep_print(netdissect_options *, const u_char *, u_int);
extern void zephyr_print(netdissect_options *, const u_char *, int);
extern void zmtp1_print(netdissect_options *, const u_char *, u_int);
extern void zmtp1_print_datagram(netdissect_options *, const u_char *, const u_int);
extern void zmtp1_datagram_print(netdissect_options *, const u_char *, const u_int);
extern void someip_print(netdissect_options *, const u_char *, const u_int);
/* checksum routines */
extern void init_checksum(void);
@ -640,27 +723,32 @@ struct cksum_vec {
extern uint16_t in_cksum(const struct cksum_vec *, int);
extern uint16_t in_cksum_shouldbe(uint16_t, uint16_t);
extern int nextproto4_cksum(netdissect_options *, const struct ip *, const uint8_t *, u_int, u_int, u_int);
/* IP protocol demuxing routines */
extern void ip_demux_print(netdissect_options *, const u_char *, u_int, u_int, int, u_int, uint8_t, const u_char *);
extern uint16_t nextproto4_cksum(netdissect_options *, const struct ip *, const uint8_t *, u_int, u_int, uint8_t);
/* in print-ip6.c */
extern int nextproto6_cksum(netdissect_options *, const struct ip6_hdr *, const uint8_t *, u_int, u_int, u_int);
extern uint16_t nextproto6_cksum(netdissect_options *, const struct ip6_hdr *, const uint8_t *, u_int, u_int, uint8_t);
/* Utilities */
extern void nd_print_trunc(netdissect_options *);
extern void nd_print_protocol(netdissect_options *);
extern void nd_print_protocol_caps(netdissect_options *);
extern void nd_print_invalid(netdissect_options *);
extern int mask2plen(uint32_t);
extern int mask62plen(const u_char *);
extern const char *dnname_string(netdissect_options *, u_short);
extern const char *dnnum_string(netdissect_options *, u_short);
extern char *smb_errstr(int, int);
extern const char *nt_errstr(uint32_t);
extern int decode_prefix4(netdissect_options *, const u_char *, u_int, char *, size_t);
extern int decode_prefix6(netdissect_options *, const u_char *, u_int, char *, size_t);
extern int decode_prefix4(netdissect_options *, const u_char *, u_int, char *, u_int);
extern int decode_prefix6(netdissect_options *, const u_char *, u_int, char *, u_int);
extern void esp_print_decodesecret(netdissect_options *);
extern int esp_print_decrypt_buffer_by_ikev2(netdissect_options *, int,
u_char spii[8], u_char spir[8],
extern void esp_decodesecret_print(netdissect_options *);
extern int esp_decrypt_buffer_by_ikev2_print(netdissect_options *, int,
const u_char spii[8],
const u_char spir[8],
const u_char *, const u_char *);
#endif /* netdissect_h */

163
nfs.h
View File

@ -118,7 +118,6 @@
#define NFSX_V3FHMAX 64 /* max. allowed by protocol */
#define NFSX_V3FATTR 84
#define NFSX_V3SATTR 60 /* max. all fields filled in */
#define NFSX_V3SRVSATTR (sizeof (struct nfsv3_sattr))
#define NFSX_V3POSTOPATTR (NFSX_V3FATTR + NFSX_UNSIGNED)
#define NFSX_V3WCCDATA (NFSX_V3POSTOPATTR + 8 * NFSX_UNSIGNED)
#define NFSX_V3COOKIEVERF 8
@ -139,7 +138,6 @@
NFSX_V2FATTR)
#define NFSX_WCCDATA(v3) ((v3) ? NFSX_V3WCCDATA : 0)
#define NFSX_WCCORFATTR(v3) ((v3) ? NFSX_V3WCCDATA : NFSX_V2FATTR)
#define NFSX_SATTR(v3) ((v3) ? NFSX_V3SATTR : NFSX_V2SATTR)
#define NFSX_COOKIEVERF(v3) ((v3) ? NFSX_V3COOKIEVERF : 0)
#define NFSX_WRITEVERF(v3) ((v3) ? NFSX_V3WRITEVERF : 0)
#define NFSX_READDIR(v3) ((v3) ? (5 * NFSX_UNSIGNED) : \
@ -248,7 +246,15 @@
typedef enum { NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5,
NFSOCK=6, NFFIFO=7 } nfs_type;
/* Structs for common parts of the rpc's */
/*
* Structs for common parts of the rpc's
*
* NOTE: these structures are not always overlaid directly on the
* packet data - sometimes we declare a local variable of that type,
* and fill it up with fields extracted using byte pointers - so we
* don't use nd_ types for their members.
*/
/*
* File Handle (32 bytes for version 2), variable up to 64 for version 3.
* File Handles of up to NFS_SMALLFH in size are stored directly in the
@ -266,32 +272,23 @@ union nfsfh {
typedef union nfsfh nfsfh_t;
struct nfsv2_time {
uint32_t nfsv2_sec;
uint32_t nfsv2_usec;
nd_uint32_t nfsv2_sec;
nd_uint32_t nfsv2_usec;
};
typedef struct nfsv2_time nfstime2;
struct nfsv3_time {
uint32_t nfsv3_sec;
uint32_t nfsv3_nsec;
nd_uint32_t nfsv3_sec;
nd_uint32_t nfsv3_nsec;
};
typedef struct nfsv3_time nfstime3;
/*
* Quads are defined as arrays of 2 longs to ensure dense packing for the
* protocol and to facilitate xdr conversion.
*/
struct nfs_uquad {
uint32_t nfsuquad[2];
};
typedef struct nfs_uquad nfsuint64;
/*
* NFS Version 3 special file number.
*/
struct nfsv3_spec {
uint32_t specdata1;
uint32_t specdata2;
nd_uint32_t specdata1;
nd_uint32_t specdata2;
};
typedef struct nfsv3_spec nfsv3spec;
@ -305,32 +302,32 @@ typedef struct nfsv3_spec nfsv3spec;
* NFSX_FATTR(v3) macro.
*/
struct nfs_fattr {
uint32_t fa_type;
uint32_t fa_mode;
uint32_t fa_nlink;
uint32_t fa_uid;
uint32_t fa_gid;
nd_uint32_t fa_type;
nd_uint32_t fa_mode;
nd_uint32_t fa_nlink;
nd_uint32_t fa_uid;
nd_uint32_t fa_gid;
union {
struct {
uint32_t nfsv2fa_size;
uint32_t nfsv2fa_blocksize;
uint32_t nfsv2fa_rdev;
uint32_t nfsv2fa_blocks;
uint32_t nfsv2fa_fsid;
uint32_t nfsv2fa_fileid;
nfstime2 nfsv2fa_atime;
nfstime2 nfsv2fa_mtime;
nfstime2 nfsv2fa_ctime;
nd_uint32_t nfsv2fa_size;
nd_uint32_t nfsv2fa_blocksize;
nd_uint32_t nfsv2fa_rdev;
nd_uint32_t nfsv2fa_blocks;
nd_uint32_t nfsv2fa_fsid;
nd_uint32_t nfsv2fa_fileid;
nfstime2 nfsv2fa_atime;
nfstime2 nfsv2fa_mtime;
nfstime2 nfsv2fa_ctime;
} fa_nfsv2;
struct {
nfsuint64 nfsv3fa_size;
nfsuint64 nfsv3fa_used;
nfsv3spec nfsv3fa_rdev;
nfsuint64 nfsv3fa_fsid;
nfsuint64 nfsv3fa_fileid;
nfstime3 nfsv3fa_atime;
nfstime3 nfsv3fa_mtime;
nfstime3 nfsv3fa_ctime;
nd_uint64_t nfsv3fa_size;
nd_uint64_t nfsv3fa_used;
nfsv3spec nfsv3fa_rdev;
nd_uint64_t nfsv3fa_fsid;
nd_uint64_t nfsv3fa_fileid;
nfstime3 nfsv3fa_atime;
nfstime3 nfsv3fa_mtime;
nfstime3 nfsv3fa_ctime;
} fa_nfsv3;
} fa_un;
};
@ -355,49 +352,31 @@ struct nfs_fattr {
#define fa3_ctime fa_un.fa_nfsv3.nfsv3fa_ctime
struct nfsv2_sattr {
uint32_t sa_mode;
uint32_t sa_uid;
uint32_t sa_gid;
uint32_t sa_size;
nfstime2 sa_atime;
nfstime2 sa_mtime;
};
/*
* NFS Version 3 sattr structure for the new node creation case.
*/
struct nfsv3_sattr {
uint32_t sa_modeset;
uint32_t sa_mode;
uint32_t sa_uidset;
uint32_t sa_uid;
uint32_t sa_gidset;
uint32_t sa_gid;
uint32_t sa_sizeset;
uint32_t sa_size;
uint32_t sa_atimetype;
nfstime3 sa_atime;
uint32_t sa_mtimetype;
nfstime3 sa_mtime;
nd_uint32_t sa_mode;
nd_uint32_t sa_uid;
nd_uint32_t sa_gid;
nd_uint32_t sa_size;
nfstime2 sa_atime;
nfstime2 sa_mtime;
};
struct nfs_statfs {
union {
struct {
uint32_t nfsv2sf_tsize;
uint32_t nfsv2sf_bsize;
uint32_t nfsv2sf_blocks;
uint32_t nfsv2sf_bfree;
uint32_t nfsv2sf_bavail;
nd_uint32_t nfsv2sf_tsize;
nd_uint32_t nfsv2sf_bsize;
nd_uint32_t nfsv2sf_blocks;
nd_uint32_t nfsv2sf_bfree;
nd_uint32_t nfsv2sf_bavail;
} sf_nfsv2;
struct {
nfsuint64 nfsv3sf_tbytes;
nfsuint64 nfsv3sf_fbytes;
nfsuint64 nfsv3sf_abytes;
nfsuint64 nfsv3sf_tfiles;
nfsuint64 nfsv3sf_ffiles;
nfsuint64 nfsv3sf_afiles;
uint32_t nfsv3sf_invarsec;
nd_uint64_t nfsv3sf_tbytes;
nd_uint64_t nfsv3sf_fbytes;
nd_uint64_t nfsv3sf_abytes;
nd_uint64_t nfsv3sf_tfiles;
nd_uint64_t nfsv3sf_ffiles;
nd_uint64_t nfsv3sf_afiles;
nd_uint32_t nfsv3sf_invarsec;
} sf_nfsv3;
} sf_un;
};
@ -416,23 +395,23 @@ struct nfs_statfs {
#define sf_invarsec sf_un.sf_nfsv3.nfsv3sf_invarsec
struct nfsv3_fsinfo {
uint32_t fs_rtmax;
uint32_t fs_rtpref;
uint32_t fs_rtmult;
uint32_t fs_wtmax;
uint32_t fs_wtpref;
uint32_t fs_wtmult;
uint32_t fs_dtpref;
nfsuint64 fs_maxfilesize;
nfstime3 fs_timedelta;
uint32_t fs_properties;
nd_uint32_t fs_rtmax;
nd_uint32_t fs_rtpref;
nd_uint32_t fs_rtmult;
nd_uint32_t fs_wtmax;
nd_uint32_t fs_wtpref;
nd_uint32_t fs_wtmult;
nd_uint32_t fs_dtpref;
nd_uint64_t fs_maxfilesize;
nfstime3 fs_timedelta;
nd_uint32_t fs_properties;
};
struct nfsv3_pathconf {
uint32_t pc_linkmax;
uint32_t pc_namemax;
uint32_t pc_notrunc;
uint32_t pc_chownrestricted;
uint32_t pc_caseinsensitive;
uint32_t pc_casepreserving;
nd_uint32_t pc_linkmax;
nd_uint32_t pc_namemax;
nd_uint32_t pc_notrunc;
nd_uint32_t pc_chownrestricted;
nd_uint32_t pc_caseinsensitive;
nd_uint32_t pc_casepreserving;
};

View File

@ -63,4 +63,4 @@ typedef struct {
#define fsid_eq(a,b) ((a.fsid_code == b.fsid_code) &&\
dev_eq(a.Fsid_dev, b.Fsid_dev))
extern void Parse_fh(const unsigned char *, u_int, my_fsid *, uint32_t *, const char **, const char **, int);
extern void Parse_fh(netdissect_options *, const unsigned char *, u_int, my_fsid *, uint32_t *, const char **, const char **, int);

View File

@ -10,14 +10,14 @@
* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
* Original code by Hannes Gredler (hannes@juniper.net)
* Original code by Hannes Gredler (hannes@gredler.at)
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "nlpid.h"

View File

@ -10,7 +10,7 @@
* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
* Original code by Hannes Gredler (hannes@juniper.net)
* Original code by Hannes Gredler (hannes@gredler.at)
*/
extern const struct tok nlpid_values[];

85
ntp.c Normal file
View File

@ -0,0 +1,85 @@
/*
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University nor the names of its contributors may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "ntp.h"
#include "extract.h"
#define JAN_1970 INT64_T_CONSTANT(2208988800) /* 1970 - 1900 in seconds */
void
p_ntp_time(netdissect_options *ndo,
const struct l_fixedpt *lfp)
{
uint32_t i;
uint32_t uf;
uint32_t f;
double ff;
i = GET_BE_U_4(lfp->int_part);
uf = GET_BE_U_4(lfp->fraction);
ff = uf;
if (ff < 0.0) /* some compilers are buggy */
ff += FMAXINT;
ff = ff / FMAXINT; /* shift radix point by 32 bits */
f = (uint32_t)(ff * 1000000000.0); /* treat fraction as parts per billion */
ND_PRINT("%u.%09u", i, f);
#ifdef HAVE_STRFTIME
/*
* print the UTC time in human-readable format.
*/
if (i) {
int64_t seconds_64bit = (int64_t)i - JAN_1970;
time_t seconds;
struct tm *tm;
char time_buf[128];
seconds = (time_t)seconds_64bit;
if (seconds != seconds_64bit) {
/*
* It doesn't fit into a time_t, so we can't hand it
* to gmtime.
*/
ND_PRINT(" (unrepresentable)");
} else {
tm = gmtime(&seconds);
if (tm == NULL) {
/*
* gmtime() can't handle it.
* (Yes, that might happen with some version of
* Microsoft's C library.)
*/
ND_PRINT(" (unrepresentable)");
} else {
/* use ISO 8601 (RFC3339) format */
strftime(time_buf, sizeof (time_buf), "%Y-%m-%dT%H:%M:%SZ", tm);
ND_PRINT(" (%s)", time_buf);
}
}
}
#endif
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1995
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -17,38 +17,40 @@
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include "netdissect-stdinc.h"
#include "netdissect.h"
/*
* Stock 4.3 doesn't have vfprintf.
* This routine is due to Chris Torek.
*/
vfprintf(f, fmt, args)
FILE *f;
char *fmt;
va_list args;
{
int ret;
* Structure definitions for NTP fixed point values
*
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Integer Part |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Fraction Part |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Integer Part | Fraction Part |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
struct l_fixedpt {
nd_uint32_t int_part;
nd_uint32_t fraction;
};
if ((f->_flag & _IOWRT) == 0) {
if (f->_flag & _IORW)
f->_flag |= _IOWRT;
else
return EOF;
}
ret = _doprnt(fmt, args, f);
return ferror(f) ? EOF : ret;
}
struct s_fixedpt {
nd_uint16_t int_part;
nd_uint16_t fraction;
};
#define FMAXINT (4294967296.0) /* floating point rep. of MAXINT */
void p_ntp_time(netdissect_options *, const struct l_fixedpt *);

142
ospf.h
View File

@ -147,14 +147,14 @@
* TOS metric struct (will be 0 or more in router links update)
*/
struct tos_metric {
uint8_t tos_type;
uint8_t reserved;
uint8_t tos_metric[2];
nd_uint8_t tos_type;
nd_uint8_t reserved;
nd_uint16_t tos_metric;
};
struct tos_link {
uint8_t link_type;
uint8_t link_tos_count;
uint8_t tos_metric[2];
nd_uint8_t link_type;
nd_uint8_t link_tos_count;
nd_uint16_t tos_metric;
};
union un_tos {
struct tos_link link;
@ -163,20 +163,20 @@ union un_tos {
/* link state advertisement header */
struct lsa_hdr {
uint16_t ls_age;
uint8_t ls_options;
uint8_t ls_type;
nd_uint16_t ls_age;
nd_uint8_t ls_options;
nd_uint8_t ls_type;
union {
struct in_addr lsa_id;
nd_ipv4 lsa_id;
struct { /* opaque LSAs change the LSA-ID field */
uint8_t opaque_type;
uint8_t opaque_id[3];
nd_uint8_t opaque_type;
nd_uint24_t opaque_id;
} opaque_field;
} un_lsa_id;
struct in_addr ls_router;
uint32_t ls_seq;
uint16_t ls_chksum;
uint16_t ls_length;
nd_ipv4 ls_router;
nd_uint32_t ls_seq;
nd_uint16_t ls_chksum;
nd_uint16_t ls_length;
};
/* link state advertisement */
@ -187,68 +187,68 @@ struct lsa {
union {
/* Router links advertisements */
struct {
uint8_t rla_flags;
uint8_t rla_zero[1];
uint16_t rla_count;
nd_uint8_t rla_flags;
nd_byte rla_zero;
nd_uint16_t rla_count;
struct rlalink {
struct in_addr link_id;
struct in_addr link_data;
nd_ipv4 link_id;
nd_ipv4 link_data;
union un_tos un_tos;
} rla_link[1]; /* may repeat */
} un_rla;
/* Network links advertisements */
struct {
struct in_addr nla_mask;
struct in_addr nla_router[1]; /* may repeat */
nd_ipv4 nla_mask;
nd_ipv4 nla_router[1]; /* may repeat */
} un_nla;
/* Summary links advertisements */
struct {
struct in_addr sla_mask;
uint32_t sla_tosmetric[1]; /* may repeat */
nd_ipv4 sla_mask;
nd_uint32_t sla_tosmetric[1]; /* may repeat */
} un_sla;
/* AS external links advertisements */
struct {
struct in_addr asla_mask;
nd_ipv4 asla_mask;
struct aslametric {
uint32_t asla_tosmetric;
struct in_addr asla_forward;
struct in_addr asla_tag;
nd_uint32_t asla_tosmetric;
nd_ipv4 asla_forward;
nd_ipv4 asla_tag;
} asla_metric[1]; /* may repeat */
} un_asla;
/* Multicast group membership */
struct mcla {
uint32_t mcla_vtype;
struct in_addr mcla_vid;
nd_uint32_t mcla_vtype;
nd_ipv4 mcla_vid;
} un_mcla[1];
/* Opaque TE LSA */
struct {
uint16_t type;
uint16_t length;
uint8_t data[1]; /* may repeat */
} un_te_lsa_tlv;
nd_uint16_t type;
nd_uint16_t length;
nd_byte data[1]; /* may repeat */
} un_te_lsa_tlv[1]; /* may repeat */
/* Opaque Grace LSA */
struct {
uint16_t type;
uint16_t length;
uint8_t data[1]; /* may repeat */
} un_grace_tlv;
nd_uint16_t type;
nd_uint16_t length;
nd_byte data[1]; /* may repeat */
} un_grace_tlv[1]; /* may repeat */
/* Opaque Router information LSA */
struct {
uint16_t type;
uint16_t length;
uint8_t data[1]; /* may repeat */
} un_ri_tlv;
nd_uint16_t type;
nd_uint16_t length;
nd_byte data[1]; /* may repeat */
} un_ri_tlv[1]; /* may repeat */
/* Unknown LSA */
struct unknown {
uint8_t data[1]; /* may repeat */
nd_byte data[1]; /* may repeat */
} un_unknown[1];
} lsa_un;
@ -260,54 +260,54 @@ struct lsa {
* the main header
*/
struct ospfhdr {
uint8_t ospf_version;
uint8_t ospf_type;
uint16_t ospf_len;
struct in_addr ospf_routerid;
struct in_addr ospf_areaid;
uint16_t ospf_chksum;
uint16_t ospf_authtype;
uint8_t ospf_authdata[OSPF_AUTH_SIZE];
nd_uint8_t ospf_version;
nd_uint8_t ospf_type;
nd_uint16_t ospf_len;
nd_ipv4 ospf_routerid;
nd_ipv4 ospf_areaid;
nd_uint16_t ospf_chksum;
nd_uint16_t ospf_authtype;
nd_byte ospf_authdata[OSPF_AUTH_SIZE];
union {
/* Hello packet */
struct {
struct in_addr hello_mask;
uint16_t hello_helloint;
uint8_t hello_options;
uint8_t hello_priority;
uint32_t hello_deadint;
struct in_addr hello_dr;
struct in_addr hello_bdr;
struct in_addr hello_neighbor[1]; /* may repeat */
nd_ipv4 hello_mask;
nd_uint16_t hello_helloint;
nd_uint8_t hello_options;
nd_uint8_t hello_priority;
nd_uint32_t hello_deadint;
nd_ipv4 hello_dr;
nd_ipv4 hello_bdr;
nd_ipv4 hello_neighbor[1]; /* may repeat */
} un_hello;
/* Database Description packet */
struct {
uint16_t db_ifmtu;
uint8_t db_options;
uint8_t db_flags;
uint32_t db_seq;
nd_uint16_t db_ifmtu;
nd_uint8_t db_options;
nd_uint8_t db_flags;
nd_uint32_t db_seq;
struct lsa_hdr db_lshdr[1]; /* may repeat */
} un_db;
/* Link State Request */
struct lsr {
uint8_t ls_type[4];
nd_uint32_t ls_type;
union {
struct in_addr ls_stateid;
nd_ipv4 ls_stateid;
struct { /* opaque LSAs change the LSA-ID field */
uint8_t opaque_type;
uint8_t opaque_id[3];
nd_uint8_t opaque_type;
nd_uint24_t opaque_id;
} opaque_field;
} un_ls_stateid;
struct in_addr ls_router;
nd_ipv4 ls_router;
} un_lsr[1]; /* may repeat */
/* Link State Update */
struct {
uint32_t lsu_count;
struct lsa lsu_lsa[1]; /* may repeat */
nd_uint32_t lsu_count;
struct lsa lsu_lsa[1]; /* may repeat */
} un_lsu;
/* Link State Acknowledgement */

32
oui.c
View File

@ -10,14 +10,14 @@
* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
* Original code by Hannes Gredler (hannes@juniper.net)
* Original code by Hannes Gredler (hannes@gredler.at)
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "oui.h"
@ -68,6 +68,8 @@ const struct tok smi_values[] = {
{ SMI_HEWLETT_PACKARD, "Hewlett Packard"},
{ SMI_SUN_MICROSYSTEMS, "Sun Microsystems"},
{ SMI_MERIT, "Merit"},
{ SMI_AT_AND_T, "AT&T"},
{ SMI_MOTOROLA, "Motorola"},
{ SMI_SHIVA, "Shiva"},
{ SMI_ERICSSON, "Ericsson AB"},
{ SMI_CISCO_VPN5000, "Cisco VPN 5000"},
@ -81,24 +83,46 @@ const struct tok smi_values[] = {
{ SMI_REDBACK, "Redback"},
{ SMI_JUNIPER, "Juniper Networks"},
{ SMI_APTIS, "Aptis"},
{ SMI_DT_AG, "Deutsche Telekom AG"},
{ SMI_IXIA, "Ixia Communications"},
{ SMI_CISCO_VPN3000, "Cisco VPN 3000"},
{ SMI_COSINE, "CoSine Communications"},
{ SMI_NETSCREEN, "Netscreen"},
{ SMI_SHASTA, "Shasta"},
{ SMI_NOMADIX, "Nomadix"},
{ SMI_T_MOBILE, "T-Mobile"},
{ SMI_BROADBAND_FORUM, "The Broadband Forum"},
{ SMI_ZTE, "ZTE"},
{ SMI_SIEMENS, "Siemens"},
{ SMI_CABLELABS, "CableLabs"},
{ SMI_UNISPHERE, "Unisphere Networks"},
{ SMI_CISCO_BBSM, "Cisco BBSM"},
{ SMI_THE3GPP2, "3rd Generation Partnership Project 2 (3GPP2)"},
{ SMI_SKT_TELECOM, "SK Telecom"},
{ SMI_IP_UNPLUGGED, "ipUnplugged"},
{ SMI_ISSANNI, "Issanni Communications"},
{ SMI_NETSCALER, "Netscaler"},
{ SMI_DE_TE_MOBIL, "T-Mobile"},
{ SMI_QUINTUM, "Quintum"},
{ SMI_INTERLINK, "Interlink"},
{ SMI_CNCTC, "CNCTC"},
{ SMI_STARENT_NETWORKS, "Starent Networks"},
{ SMI_COLUBRIS, "Colubris"},
{ SMI_COLUMBIA_UNIVERSITY, "Columbia University"},
{ SMI_THE3GPP, "3GPP"},
{ SMI_GEMTEK_SYSTEMS, "Gemtek-Systems"},
{ SMI_BARRACUDA, "Barracuda Networks"},
{ SMI_ERICSSON_PKT_CORE, "Ericsson AB - Packet Core Networks"},
{ SMI_DACOM, "dacom"},
{ SMI_COLUMBIA_UNIVERSITY, "Columbia University"},
{ SMI_FORTINET, "Fortinet"},
{ SMI_VERIZON, "Verizon Wireless"},
{ SMI_PLIXER, "Plixer"},
{ SMI_WIFI_ALLIANCE, "Wi-Fi Alliance"},
{ SMI_T_SYSTEMS_NOVA, "T-Systems Nova"},
{ SMI_CHINATELECOM_GUANZHOU, "China Telecom - Guangzhou Research Institute"},
{ SMI_GIGAMON, "Gigamon Systems"},
{ SMI_CACE, "CACE Technologies"},
{ SMI_NTOP, "ntop"},
{ SMI_ERICSSON_CANADA_INC, "Ericsson Canada"},
{ 0, NULL}
};

31
oui.h
View File

@ -10,7 +10,7 @@
* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
* Original code by Hannes Gredler (hannes@juniper.net)
* Original code by Hannes Gredler (hannes@gredler.at)
*/
extern const struct tok oui_values[];
@ -45,7 +45,7 @@ extern const struct tok smi_values[];
* These are SMI Network Management Private Enterprise Codes for
* organizations; see
*
* http://www.iana.org/assignments/enterprise-numbers
* https://www.iana.org/assignments/enterprise-numbers
*
* for a list.
*
@ -57,6 +57,8 @@ extern const struct tok smi_values[];
#define SMI_HEWLETT_PACKARD 11
#define SMI_SUN_MICROSYSTEMS 42
#define SMI_MERIT 61
#define SMI_AT_AND_T 74
#define SMI_MOTOROLA 161
#define SMI_SHIVA 166
#define SMI_ERICSSON 193
#define SMI_CISCO_VPN5000 255
@ -70,22 +72,45 @@ extern const struct tok smi_values[];
#define SMI_REDBACK 2352
#define SMI_JUNIPER 2636
#define SMI_APTIS 2637
#define SMI_DT_AG 2937
#define SMI_IXIA 3054
#define SMI_CISCO_VPN3000 3076
#define SMI_COSINE 3085
#define SMI_SHASTA 3199
#define SMI_NETSCREEN 3224
#define SMI_NOMADIX 3309
#define SMI_T_MOBILE 3414
#define SMI_BROADBAND_FORUM 3561
#define SMI_ZTE 3902
#define SMI_SIEMENS 4329
#define SMI_CABLELABS 4491
#define SMI_UNISPHERE 4874
#define SMI_CISCO_BBSM 5263
#define SMI_THE3GPP2 5535
#define SMI_SKT_TELECOM 5806
#define SMI_IP_UNPLUGGED 5925
#define SMI_ISSANNI 5948
#define SMI_NETSCALER 5951
#define SMI_DE_TE_MOBIL 6490
#define SMI_QUINTUM 6618
#define SMI_INTERLINK 6728
#define SMI_CNCTC 7951
#define SMI_STARENT_NETWORKS 8164
#define SMI_COLUBRIS 8744
#define SMI_COLUMBIA_UNIVERSITY 11862
#define SMI_THE3GPP 10415
#define SMI_GEMTEK_SYSTEMS 10529
#define SMI_BARRACUDA 10704
#define SMI_ERICSSON_PKT_CORE 10923
#define SMI_DACOM 11665
#define SMI_COLUMBIA_UNIVERSITY 11862
#define SMI_FORTINET 12356
#define SMI_VERIZON 12951
#define SMI_PLIXER 13745
#define SMI_WIFI_ALLIANCE 14122
#define SMI_T_SYSTEMS_NOVA 16787
#define SMI_CHINATELECOM_GUANZHOU 20942
#define SMI_GIGAMON 26866
#define SMI_CACE 32622
/* Greater than 32,767 need to be tagged unsigned. */
#define SMI_NTOP 35632u
#define SMI_ERICSSON_CANADA_INC 46098u

View File

@ -41,15 +41,18 @@
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include <stdio.h>
#include <string.h>
#include "netdissect-ctype.h"
#include "netdissect.h"
#include "extract.h"
#include "nfsfh.h"
/*
@ -76,42 +79,16 @@
#define FHT_HPUX9 11
#define FHT_BSD44 12
#ifdef ultrix
/* Nasty hack to keep the Ultrix C compiler from emitting bogus warnings */
#define XFF(x) ((uint32_t)(x))
#else
#define XFF(x) (x)
#endif
#define make_uint32(msb,b,c,lsb)\
(XFF(lsb) + (XFF(c)<<8) + (XFF(b)<<16) + (XFF(msb)<<24))
#define make_uint24(msb,b, lsb)\
(XFF(lsb) + (XFF(b)<<8) + (XFF(msb)<<16))
#define make_uint16(msb,lsb)\
(XFF(lsb) + (XFF(msb)<<8))
#ifdef __alpha
/* or other 64-bit systems */
#define make_uint48(msb,b,c,d,e,lsb)\
((lsb) + ((e)<<8) + ((d)<<16) + ((c)<<24) + ((b)<<32) + ((msb)<<40))
#else
/* on 32-bit systems ignore high-order bits */
#define make_uint48(msb,b,c,d,e,lsb)\
((lsb) + ((e)<<8) + ((d)<<16) + ((c)<<24))
#endif
static int is_UCX(const unsigned char *, u_int);
static int is_UCX(netdissect_options *, const unsigned char *, u_int);
void
Parse_fh(register const unsigned char *fh, u_int len, my_fsid *fsidp,
uint32_t *inop,
Parse_fh(netdissect_options *ndo, const unsigned char *fh, u_int len,
my_fsid *fsidp, uint32_t *inop,
const char **osnamep, /* if non-NULL, return OS name here */
const char **fsnamep, /* if non-NULL, return server fs name here (for VMS) */
int ourself) /* true if file handle was generated on this host */
{
register const unsigned char *fhp = fh;
const unsigned char *fhp = fh;
uint32_t temp;
int fhtype = FHT_UNKNOWN;
u_int i;
@ -154,10 +131,10 @@ Parse_fh(register const unsigned char *fh, u_int len, my_fsid *fsidp,
/*
* This is basically a big decision tree
*/
else if ((fhp[0] == 0) && (fhp[1] == 0)) {
else if ((GET_U_1(fhp) == 0) && (GET_U_1(fhp + 1) == 0)) {
/* bytes[0,1] == (0,0); rules out Ultrix, IRIX5, SUNOS5 */
/* probably rules out HP-UX, AIX unless they allow major=0 */
if ((fhp[2] == 0) && (fhp[3] == 0)) {
if ((GET_U_1(fhp + 2) == 0) && (GET_U_1(fhp + 3) == 0)) {
/* bytes[2,3] == (0,0); must be Auspex */
/* XXX or could be Ultrix+MASSBUS "hp" disk? */
fhtype = FHT_AUSPEX;
@ -167,16 +144,16 @@ Parse_fh(register const unsigned char *fh, u_int len, my_fsid *fsidp,
* bytes[2,3] != (0,0); rules out Auspex, could be
* DECOSF, SUNOS4, or IRIX4
*/
if ((fhp[4] != 0) && (fhp[5] == 0) &&
(fhp[8] == 12) && (fhp[9] == 0)) {
if ((GET_U_1(fhp + 4) != 0) && (GET_U_1(fhp + 5) == 0) &&
(GET_U_1(fhp + 8) == 12) && (GET_U_1(fhp + 9) == 0)) {
/* seems to be DECOSF, with minor == 0 */
fhtype = FHT_DECOSF;
}
else {
/* could be SUNOS4 or IRIX4 */
/* XXX the test of fhp[5] == 8 could be wrong */
if ((fhp[4] == 0) && (fhp[5] == 8) && (fhp[6] == 0) &&
(fhp[7] == 0)) {
if ((GET_U_1(fhp + 4) == 0) && (GET_U_1(fhp + 5) == 8) && (GET_U_1(fhp + 6) == 0) &&
(GET_U_1(fhp + 7) == 0)) {
/* looks like a length, not a file system typecode */
fhtype = FHT_IRIX4;
}
@ -193,24 +170,24 @@ Parse_fh(register const unsigned char *fh, u_int len, my_fsid *fsidp,
* could be IRIX5, DECOSF, UCX, Ultrix, SUNOS5
* could be AIX, HP-UX
*/
if ((fhp[2] == 0) && (fhp[3] == 0)) {
if ((GET_U_1(fhp + 2) == 0) && (GET_U_1(fhp + 3) == 0)) {
/*
* bytes[2,3] == (0,0); rules out OSF, probably not UCX
* (unless the exported device name is just one letter!),
* could be Ultrix, IRIX5, AIX, or SUNOS5
* might be HP-UX (depends on their values for minor devs)
*/
if ((fhp[6] == 0) && (fhp[7] == 0)) {
if ((GET_U_1(fhp + 6) == 0) && (GET_U_1(fhp + 7) == 0)) {
fhtype = FHT_BSD44;
}
/*XXX we probably only need to test of these two bytes */
else if ((len >= 24/4) && (fhp[21] == 0) && (fhp[23] == 0)) {
else if ((len >= 24/4) && (GET_U_1(fhp + 21) == 0) && (GET_U_1(fhp + 23) == 0)) {
fhtype = FHT_ULTRIX;
}
else {
/* Could be SUNOS5/IRIX5, maybe AIX */
/* XXX no obvious difference between SUNOS5 and IRIX5 */
if (fhp[9] == 10)
if (GET_U_1(fhp + 9) == 10)
fhtype = FHT_SUNOS5;
/* XXX what about AIX? */
}
@ -220,17 +197,17 @@ Parse_fh(register const unsigned char *fh, u_int len, my_fsid *fsidp,
* bytes[2,3] != (0,0); rules out Ultrix, could be
* DECOSF, SUNOS5, IRIX5, AIX, HP-UX, or UCX
*/
if ((fhp[8] == 12) && (fhp[9] == 0)) {
if ((GET_U_1(fhp + 8) == 12) && (GET_U_1(fhp + 9) == 0)) {
fhtype = FHT_DECOSF;
}
else if ((fhp[8] == 0) && (fhp[9] == 10)) {
else if ((GET_U_1(fhp + 8) == 0) && (GET_U_1(fhp + 9) == 10)) {
/* could be SUNOS5/IRIX5, AIX, HP-UX */
if ((fhp[7] == 0) && (fhp[6] == 0) &&
(fhp[5] == 0) && (fhp[4] == 0)) {
if ((GET_U_1(fhp + 7) == 0) && (GET_U_1(fhp + 6) == 0) &&
(GET_U_1(fhp + 5) == 0) && (GET_U_1(fhp + 4) == 0)) {
/* XXX is this always true of HP-UX? */
fhtype = FHT_HPUX9;
}
else if (fhp[7] == 2) {
else if (GET_U_1(fhp + 7) == 2) {
/* This would be MNT_NFS on AIX, which is impossible */
fhtype = FHT_SUNOS5; /* or maybe IRIX5 */
}
@ -245,7 +222,7 @@ Parse_fh(register const unsigned char *fh, u_int len, my_fsid *fsidp,
}
}
else {
if (is_UCX(fhp, len)) {
if (is_UCX(ndo, fhp, len)) {
fhtype = FHT_VMSUCX;
}
else {
@ -260,57 +237,57 @@ Parse_fh(register const unsigned char *fh, u_int len, my_fsid *fsidp,
switch (fhtype) {
case FHT_AUSPEX:
fsidp->Fsid_dev.Minor = fhp[7];
fsidp->Fsid_dev.Major = fhp[6];
fsidp->Fsid_dev.Minor = GET_U_1(fhp + 7);
fsidp->Fsid_dev.Major = GET_U_1(fhp + 6);
fsidp->fsid_code = 0;
*inop = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]);
*inop = GET_BE_U_4(fhp + 12);
if (osnamep)
*osnamep = "Auspex";
break;
case FHT_BSD44:
fsidp->Fsid_dev.Minor = fhp[0];
fsidp->Fsid_dev.Major = fhp[1];
fsidp->Fsid_dev.Minor = GET_U_1(fhp);
fsidp->Fsid_dev.Major = GET_U_1(fhp + 1);
fsidp->fsid_code = 0;
*inop = make_uint32(fhp[15], fhp[14], fhp[13], fhp[12]);
*inop = GET_LE_U_4(fhp + 12);
if (osnamep)
*osnamep = "BSD 4.4";
break;
case FHT_DECOSF:
fsidp->fsid_code = make_uint32(fhp[7], fhp[6], fhp[5], fhp[4]);
fsidp->fsid_code = GET_LE_U_4(fhp + 4);
/* XXX could ignore 3 high-order bytes */
temp = make_uint32(fhp[3], fhp[2], fhp[1], fhp[0]);
temp = GET_LE_U_4(fhp);
fsidp->Fsid_dev.Minor = temp & 0xFFFFF;
fsidp->Fsid_dev.Major = (temp>>20) & 0xFFF;
*inop = make_uint32(fhp[15], fhp[14], fhp[13], fhp[12]);
*inop = GET_LE_U_4(fhp + 12);
if (osnamep)
*osnamep = "OSF";
break;
case FHT_IRIX4:
fsidp->Fsid_dev.Minor = fhp[3];
fsidp->Fsid_dev.Major = fhp[2];
fsidp->Fsid_dev.Minor = GET_U_1(fhp + 3);
fsidp->Fsid_dev.Major = GET_U_1(fhp + 2);
fsidp->fsid_code = 0;
*inop = make_uint32(fhp[8], fhp[9], fhp[10], fhp[11]);
*inop = GET_BE_U_4(fhp + 8);
if (osnamep)
*osnamep = "IRIX4";
break;
case FHT_IRIX5:
fsidp->Fsid_dev.Minor = make_uint16(fhp[2], fhp[3]);
fsidp->Fsid_dev.Major = make_uint16(fhp[0], fhp[1]);
fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]);
fsidp->Fsid_dev.Minor = GET_BE_U_2(fhp + 2);
fsidp->Fsid_dev.Major = GET_BE_U_2(fhp);
fsidp->fsid_code = GET_BE_U_4(fhp + 4);
*inop = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]);
*inop = GET_BE_U_4(fhp + 12);
if (osnamep)
*osnamep = "IRIX5";
@ -328,24 +305,24 @@ Parse_fh(register const unsigned char *fh, u_int len, my_fsid *fsidp,
#endif
case FHT_SUNOS4:
fsidp->Fsid_dev.Minor = fhp[3];
fsidp->Fsid_dev.Major = fhp[2];
fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]);
fsidp->Fsid_dev.Minor = GET_U_1(fhp + 3);
fsidp->Fsid_dev.Major = GET_U_1(fhp + 2);
fsidp->fsid_code = GET_BE_U_4(fhp + 4);
*inop = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]);
*inop = GET_BE_U_4(fhp + 12);
if (osnamep)
*osnamep = "SUNOS4";
break;
case FHT_SUNOS5:
temp = make_uint16(fhp[0], fhp[1]);
temp = GET_BE_U_2(fhp);
fsidp->Fsid_dev.Major = (temp>>2) & 0x3FFF;
temp = make_uint24(fhp[1], fhp[2], fhp[3]);
temp = GET_BE_U_3(fhp + 1);
fsidp->Fsid_dev.Minor = temp & 0x3FFFF;
fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]);
fsidp->fsid_code = GET_BE_U_4(fhp + 4);
*inop = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]);
*inop = GET_BE_U_4(fhp + 12);
if (osnamep)
*osnamep = "SUNOS5";
@ -353,10 +330,10 @@ Parse_fh(register const unsigned char *fh, u_int len, my_fsid *fsidp,
case FHT_ULTRIX:
fsidp->fsid_code = 0;
fsidp->Fsid_dev.Minor = fhp[0];
fsidp->Fsid_dev.Major = fhp[1];
fsidp->Fsid_dev.Minor = GET_U_1(fhp);
fsidp->Fsid_dev.Major = GET_U_1(fhp + 1);
temp = make_uint32(fhp[7], fhp[6], fhp[5], fhp[4]);
temp = GET_LE_U_4(fhp + 4);
*inop = temp;
if (osnamep)
*osnamep = "Ultrix";
@ -381,34 +358,36 @@ Parse_fh(register const unsigned char *fh, u_int len, my_fsid *fsidp,
}
/* VMS file ID is: (RVN, FidHi, FidLo) */
*inop = make_uint32(fhp[26], fhp[27], fhp[23], fhp[22]);
*inop = (((uint32_t) GET_U_1(fhp + 26)) << 24) |
(((uint32_t) GET_U_1(fhp + 27)) << 16) |
(GET_LE_U_2(fhp + 22) << 0);
/* Caller must save (and null-terminate?) this value */
if (fsnamep)
*fsnamep = (const char *)&(fhp[1]);
*fsnamep = (const char *)(fhp + 1);
if (osnamep)
*osnamep = "VMS";
break;
case FHT_AIX32:
fsidp->Fsid_dev.Minor = make_uint16(fhp[2], fhp[3]);
fsidp->Fsid_dev.Major = make_uint16(fhp[0], fhp[1]);
fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]);
fsidp->Fsid_dev.Minor = GET_BE_U_2(fhp + 2);
fsidp->Fsid_dev.Major = GET_BE_U_2(fhp);
fsidp->fsid_code = GET_BE_U_4(fhp + 4);
*inop = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]);
*inop = GET_BE_U_4(fhp + 12);
if (osnamep)
*osnamep = "AIX32";
break;
case FHT_HPUX9:
fsidp->Fsid_dev.Major = fhp[0];
temp = make_uint24(fhp[1], fhp[2], fhp[3]);
fsidp->Fsid_dev.Major = GET_U_1(fhp);
temp = GET_BE_U_3(fhp + 1);
fsidp->Fsid_dev.Minor = temp;
fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]);
fsidp->fsid_code = GET_BE_U_4(fhp + 4);
*inop = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]);
*inop = GET_BE_U_4(fhp + 12);
if (osnamep)
*osnamep = "HPUX9";
@ -418,12 +397,13 @@ Parse_fh(register const unsigned char *fh, u_int len, my_fsid *fsidp,
#ifdef DEBUG
/* XXX debugging */
for (i = 0; i < len*4; i++)
(void)fprintf(stderr, "%x.", fhp[i]);
(void)fprintf(stderr, "%x.", GET_U_1(fhp + i));
(void)fprintf(stderr, "\n");
#endif
/* Save the actual handle, so it can be display with -u */
for (i = 0; i < len*4 && i*2 < sizeof(fsidp->Opaque_Handle) - 1; i++)
(void)snprintf(&(fsidp->Opaque_Handle[i*2]), 3, "%.2X", fhp[i]);
(void)snprintf(&(fsidp->Opaque_Handle[i*2]), 3, "%.2X",
GET_U_1(fhp + i));
fsidp->Opaque_Handle[i*2] = '\0';
/* XXX for now, give "bogus" values to aid debugging */
@ -451,9 +431,9 @@ Parse_fh(register const unsigned char *fh, u_int len, my_fsid *fsidp,
* (3) followed by string of nulls
*/
static int
is_UCX(const unsigned char *fhp, u_int len)
is_UCX(netdissect_options *ndo, const unsigned char *fhp, u_int len)
{
register u_int i;
u_int i;
int seen_null = 0;
/*
@ -464,13 +444,13 @@ is_UCX(const unsigned char *fhp, u_int len)
return(0);
for (i = 1; i < 14; i++) {
if (ND_ISPRINT(fhp[i])) {
if (ND_ASCII_ISPRINT(GET_U_1(fhp + i))) {
if (seen_null)
return(0);
else
continue;
}
else if (fhp[i] == 0) {
else if (GET_U_1(fhp + i) == 0) {
seen_null = 1;
continue;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -24,41 +24,39 @@
/* \summary: IPSEC Authentication Header printer */
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "ah.h"
#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "extract.h"
int
ah_print(netdissect_options *ndo, register const u_char *bp)
{
register const struct ah *ah;
int sumlen;
#include "ah.h"
int
ah_print(netdissect_options *ndo, const u_char *bp)
{
const struct ah *ah;
u_int sumlen;
ndo->ndo_protocol = "ah";
ah = (const struct ah *)bp;
ND_TCHECK(*ah);
ND_TCHECK_SIZE(ah);
sumlen = ah->ah_len << 2;
sumlen = GET_U_1(ah->ah_len) << 2;
ND_PRINT((ndo, "AH(spi=0x%08x", EXTRACT_32BITS(&ah->ah_spi)));
ND_PRINT("AH(spi=0x%08x", GET_BE_U_4(ah->ah_spi));
if (ndo->ndo_vflag)
ND_PRINT((ndo, ",sumlen=%d", sumlen));
ND_TCHECK_32BITS(ah + 1);
ND_PRINT((ndo, ",seq=0x%x", EXTRACT_32BITS(ah + 1)));
if (!ND_TTEST2(*bp, sizeof(struct ah) + sumlen)) {
ND_PRINT((ndo, "[truncated]):"));
return -1;
}
ND_PRINT((ndo, "): "));
ND_PRINT(",sumlen=%u", sumlen);
ND_TCHECK_4(ah + 1);
ND_PRINT(",seq=0x%x", GET_BE_U_4(ah + 1));
ND_TCHECK_LEN(bp, sizeof(struct ah) + sumlen);
ND_PRINT("): ");
return sizeof(struct ah) + sumlen;
trunc:
ND_PRINT((ndo, "[|AH]"));
nd_print_trunc(ndo);
return -1;
}

View File

@ -30,16 +30,15 @@
/* Based on draft-chroboczek-ahcp-00 and source code of ahcpd-0.53 */
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "extract.h"
#include "addrtoname.h"
static const char tstr[] = " [|ahcp]";
#define AHCP_MAGIC_NUMBER 43
#define AHCP_VERSION_1 1
@ -106,22 +105,22 @@ ahcp_time_print(netdissect_options *ndo, const u_char *cp, const u_char *ep)
if (cp + 4 != ep)
goto invalid;
ND_TCHECK2(*cp, 4);
t = EXTRACT_32BITS(cp);
ND_TCHECK_4(cp);
t = GET_BE_U_4(cp);
if (NULL == (tm = gmtime(&t)))
ND_PRINT((ndo, ": gmtime() error"));
ND_PRINT(": gmtime() error");
else if (0 == strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm))
ND_PRINT((ndo, ": strftime() error"));
ND_PRINT(": strftime() error");
else
ND_PRINT((ndo, ": %s UTC", buf));
ND_PRINT(": %s UTC", buf);
return 0;
invalid:
ND_PRINT((ndo, "%s", istr));
ND_TCHECK2(*cp, ep - cp);
nd_print_invalid(ndo);
ND_TCHECK_LEN(cp, ep - cp);
return 0;
trunc:
ND_PRINT((ndo, "%s", tstr));
nd_print_trunc(ndo);
return -1;
}
@ -130,16 +129,16 @@ ahcp_seconds_print(netdissect_options *ndo, const u_char *cp, const u_char *ep)
{
if (cp + 4 != ep)
goto invalid;
ND_TCHECK2(*cp, 4);
ND_PRINT((ndo, ": %us", EXTRACT_32BITS(cp)));
ND_TCHECK_4(cp);
ND_PRINT(": %us", GET_BE_U_4(cp));
return 0;
invalid:
ND_PRINT((ndo, "%s", istr));
ND_TCHECK2(*cp, ep - cp);
nd_print_invalid(ndo);
ND_TCHECK_LEN(cp, ep - cp);
return 0;
trunc:
ND_PRINT((ndo, "%s", tstr));
nd_print_trunc(ndo);
return -1;
}
@ -151,19 +150,19 @@ ahcp_ipv6_addresses_print(netdissect_options *ndo, const u_char *cp, const u_cha
while (cp < ep) {
if (cp + 16 > ep)
goto invalid;
ND_TCHECK2(*cp, 16);
ND_PRINT((ndo, "%s%s", sep, ip6addr_string(ndo, cp)));
ND_TCHECK_16(cp);
ND_PRINT("%s%s", sep, GET_IP6ADDR_STRING(cp));
cp += 16;
sep = ", ";
}
return 0;
invalid:
ND_PRINT((ndo, "%s", istr));
ND_TCHECK2(*cp, ep - cp);
nd_print_invalid(ndo);
ND_TCHECK_LEN(cp, ep - cp);
return 0;
trunc:
ND_PRINT((ndo, "%s", tstr));
nd_print_trunc(ndo);
return -1;
}
@ -175,19 +174,19 @@ ahcp_ipv4_addresses_print(netdissect_options *ndo, const u_char *cp, const u_cha
while (cp < ep) {
if (cp + 4 > ep)
goto invalid;
ND_TCHECK2(*cp, 4);
ND_PRINT((ndo, "%s%s", sep, ipaddr_string(ndo, cp)));
ND_TCHECK_4(cp);
ND_PRINT("%s%s", sep, GET_IPADDR_STRING(cp));
cp += 4;
sep = ", ";
}
return 0;
invalid:
ND_PRINT((ndo, "%s", istr));
ND_TCHECK2(*cp, ep - cp);
nd_print_invalid(ndo);
ND_TCHECK_LEN(cp, ep - cp);
return 0;
trunc:
ND_PRINT((ndo, "%s", tstr));
nd_print_trunc(ndo);
return -1;
}
@ -199,19 +198,20 @@ ahcp_ipv6_prefixes_print(netdissect_options *ndo, const u_char *cp, const u_char
while (cp < ep) {
if (cp + 17 > ep)
goto invalid;
ND_TCHECK2(*cp, 17);
ND_PRINT((ndo, "%s%s/%u", sep, ip6addr_string(ndo, cp), *(cp + 16)));
ND_TCHECK_LEN(cp, 17);
ND_PRINT("%s%s/%u", sep, GET_IP6ADDR_STRING(cp),
GET_U_1(cp + 16));
cp += 17;
sep = ", ";
}
return 0;
invalid:
ND_PRINT((ndo, "%s", istr));
ND_TCHECK2(*cp, ep - cp);
nd_print_invalid(ndo);
ND_TCHECK_LEN(cp, ep - cp);
return 0;
trunc:
ND_PRINT((ndo, "%s", tstr));
nd_print_trunc(ndo);
return -1;
}
@ -223,19 +223,20 @@ ahcp_ipv4_prefixes_print(netdissect_options *ndo, const u_char *cp, const u_char
while (cp < ep) {
if (cp + 5 > ep)
goto invalid;
ND_TCHECK2(*cp, 5);
ND_PRINT((ndo, "%s%s/%u", sep, ipaddr_string(ndo, cp), *(cp + 4)));
ND_TCHECK_5(cp);
ND_PRINT("%s%s/%u", sep, GET_IPADDR_STRING(cp),
GET_U_1(cp + 4));
cp += 5;
sep = ", ";
}
return 0;
invalid:
ND_PRINT((ndo, "%s", istr));
ND_TCHECK2(*cp, ep - cp);
nd_print_invalid(ndo);
ND_TCHECK_LEN(cp, ep - cp);
return 0;
trunc:
ND_PRINT((ndo, "%s", tstr));
nd_print_trunc(ndo);
return -1;
}
@ -265,17 +266,17 @@ ahcp1_options_print(netdissect_options *ndo, const u_char *cp, const u_char *ep)
while (cp < ep) {
/* Option no */
ND_TCHECK2(*cp, 1);
option_no = *cp;
ND_TCHECK_1(cp);
option_no = GET_U_1(cp);
cp += 1;
ND_PRINT((ndo, "\n\t %s", tok2str(ahcp1_opt_str, "Unknown-%u", option_no)));
ND_PRINT("\n\t %s", tok2str(ahcp1_opt_str, "Unknown-%u", option_no));
if (option_no == AHCP1_OPT_PAD || option_no == AHCP1_OPT_MANDATORY)
continue;
/* Length */
if (cp + 1 > ep)
goto invalid;
ND_TCHECK2(*cp, 1);
option_len = *cp;
ND_TCHECK_1(cp);
option_len = GET_U_1(cp);
cp += 1;
if (cp + option_len > ep)
goto invalid;
@ -284,19 +285,19 @@ ahcp1_options_print(netdissect_options *ndo, const u_char *cp, const u_char *ep)
if (data_decoders[option_no](ndo, cp, cp + option_len) < 0)
break; /* truncated and already marked up */
} else {
ND_PRINT((ndo, " (Length %u)", option_len));
ND_TCHECK2(*cp, option_len);
ND_PRINT(" (Length %u)", option_len);
ND_TCHECK_LEN(cp, option_len);
}
cp += option_len;
}
return;
invalid:
ND_PRINT((ndo, "%s", istr));
ND_TCHECK2(*cp, ep - cp);
nd_print_invalid(ndo);
ND_TCHECK_LEN(cp, ep - cp);
return;
trunc:
ND_PRINT((ndo, "%s", tstr));
nd_print_trunc(ndo);
}
static void
@ -308,23 +309,23 @@ ahcp1_body_print(netdissect_options *ndo, const u_char *cp, const u_char *ep)
if (cp + AHCP1_BODY_MIN_LEN > ep)
goto invalid;
/* Type */
ND_TCHECK2(*cp, 1);
type = *cp;
ND_TCHECK_1(cp);
type = GET_U_1(cp);
cp += 1;
/* MBZ */
ND_TCHECK2(*cp, 1);
mbz = *cp;
ND_TCHECK_1(cp);
mbz = GET_U_1(cp);
cp += 1;
/* Length */
ND_TCHECK2(*cp, 2);
body_len = EXTRACT_16BITS(cp);
ND_TCHECK_2(cp);
body_len = GET_BE_U_2(cp);
cp += 2;
if (ndo->ndo_vflag) {
ND_PRINT((ndo, "\n\t%s", tok2str(ahcp1_msg_str, "Unknown-%u", type)));
ND_PRINT("\n\t%s", tok2str(ahcp1_msg_str, "Unknown-%u", type));
if (mbz != 0)
ND_PRINT((ndo, ", MBZ %u", mbz));
ND_PRINT((ndo, ", Length %u", body_len));
ND_PRINT(", MBZ %u", mbz);
ND_PRINT(", Length %u", body_len);
}
if (cp + body_len > ep)
goto invalid;
@ -333,63 +334,65 @@ ahcp1_body_print(netdissect_options *ndo, const u_char *cp, const u_char *ep)
if (ndo->ndo_vflag >= 2)
ahcp1_options_print(ndo, cp, cp + body_len); /* not ep (ignore extra data) */
else
ND_TCHECK2(*cp, body_len);
ND_TCHECK_LEN(cp, body_len);
return;
invalid:
ND_PRINT((ndo, "%s", istr));
ND_TCHECK2(*cp, ep - cp);
nd_print_invalid(ndo);
ND_TCHECK_LEN(cp, ep - cp);
return;
trunc:
ND_PRINT((ndo, "%s", tstr));
nd_print_trunc(ndo);
}
void
ahcp_print(netdissect_options *ndo, const u_char *cp, const u_int len)
{
const u_char *ep = cp + len;
const u_char *ep = ndo->ndo_snapend;
uint8_t version;
ND_PRINT((ndo, "AHCP"));
ndo->ndo_protocol = "ahcp";
nd_print_protocol_caps(ndo);
if (len < 2)
goto invalid;
/* Magic */
ND_TCHECK2(*cp, 1);
if (*cp != AHCP_MAGIC_NUMBER)
ND_TCHECK_1(cp);
if (GET_U_1(cp) != AHCP_MAGIC_NUMBER)
goto invalid;
cp += 1;
/* Version */
ND_TCHECK2(*cp, 1);
version = *cp;
ND_TCHECK_1(cp);
version = GET_U_1(cp);
cp += 1;
switch (version) {
case AHCP_VERSION_1: {
ND_PRINT((ndo, " Version 1"));
ND_PRINT(" Version 1");
if (len < AHCP1_HEADER_FIX_LEN)
goto invalid;
if (!ndo->ndo_vflag) {
ND_TCHECK2(*cp, AHCP1_HEADER_FIX_LEN - 2);
ND_TCHECK_LEN(cp, AHCP1_HEADER_FIX_LEN - 2);
cp += AHCP1_HEADER_FIX_LEN - 2;
} else {
/* Hopcount */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, "\n\tHopcount %u", *cp));
ND_TCHECK_1(cp);
ND_PRINT("\n\tHopcount %u", GET_U_1(cp));
cp += 1;
/* Original Hopcount */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, ", Original Hopcount %u", *cp));
ND_TCHECK_1(cp);
ND_PRINT(", Original Hopcount %u",
GET_U_1(cp));
cp += 1;
/* Nonce */
ND_TCHECK2(*cp, 4);
ND_PRINT((ndo, ", Nonce 0x%08x", EXTRACT_32BITS(cp)));
ND_TCHECK_4(cp);
ND_PRINT(", Nonce 0x%08x", GET_BE_U_4(cp));
cp += 4;
/* Source Id */
ND_TCHECK2(*cp, 8);
ND_PRINT((ndo, ", Source Id %s", linkaddr_string(ndo, cp, 0, 8)));
ND_TCHECK_8(cp);
ND_PRINT(", Source Id %s", GET_LINKADDR_STRING(cp, LINKADDR_OTHER, 8));
cp += 8;
/* Destination Id */
ND_TCHECK2(*cp, 8);
ND_PRINT((ndo, ", Destination Id %s", linkaddr_string(ndo, cp, 0, 8)));
ND_TCHECK_8(cp);
ND_PRINT(", Destination Id %s", GET_LINKADDR_STRING(cp, LINKADDR_OTHER, 8));
cp += 8;
}
/* Body */
@ -397,15 +400,15 @@ ahcp_print(netdissect_options *ndo, const u_char *cp, const u_int len)
break;
}
default:
ND_PRINT((ndo, " Version %u (unknown)", version));
ND_PRINT(" Version %u (unknown)", version);
break;
}
return;
invalid:
ND_PRINT((ndo, "%s", istr));
ND_TCHECK2(*cp, ep - cp);
nd_print_invalid(ndo);
ND_TCHECK_LEN(cp, ep - cp);
return;
trunc:
ND_PRINT((ndo, "%s", tstr));
nd_print_trunc(ndo);
}

View File

@ -33,48 +33,50 @@
/* \summary: Ad hoc On-Demand Distance Vector (AODV) Routing printer */
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "addrtoname.h"
#include "extract.h"
/*
* RFC 3561
*/
struct aodv_rreq {
uint8_t rreq_type; /* AODV message type (1) */
uint8_t rreq_flags; /* various flags */
uint8_t rreq_zero0; /* reserved, set to zero */
uint8_t rreq_hops; /* number of hops from originator */
uint32_t rreq_id; /* request ID */
uint32_t rreq_da; /* destination IPv4 address */
uint32_t rreq_ds; /* destination sequence number */
uint32_t rreq_oa; /* originator IPv4 address */
uint32_t rreq_os; /* originator sequence number */
nd_uint8_t rreq_type; /* AODV message type (1) */
nd_uint8_t rreq_flags; /* various flags */
nd_uint8_t rreq_zero0; /* reserved, set to zero */
nd_uint8_t rreq_hops; /* number of hops from originator */
nd_uint32_t rreq_id; /* request ID */
nd_ipv4 rreq_da; /* destination IPv4 address */
nd_uint32_t rreq_ds; /* destination sequence number */
nd_ipv4 rreq_oa; /* originator IPv4 address */
nd_uint32_t rreq_os; /* originator sequence number */
};
struct aodv_rreq6 {
uint8_t rreq_type; /* AODV message type (1) */
uint8_t rreq_flags; /* various flags */
uint8_t rreq_zero0; /* reserved, set to zero */
uint8_t rreq_hops; /* number of hops from originator */
uint32_t rreq_id; /* request ID */
struct in6_addr rreq_da; /* destination IPv6 address */
uint32_t rreq_ds; /* destination sequence number */
struct in6_addr rreq_oa; /* originator IPv6 address */
uint32_t rreq_os; /* originator sequence number */
nd_uint8_t rreq_type; /* AODV message type (1) */
nd_uint8_t rreq_flags; /* various flags */
nd_uint8_t rreq_zero0; /* reserved, set to zero */
nd_uint8_t rreq_hops; /* number of hops from originator */
nd_uint32_t rreq_id; /* request ID */
nd_ipv6 rreq_da; /* destination IPv6 address */
nd_uint32_t rreq_ds; /* destination sequence number */
nd_ipv6 rreq_oa; /* originator IPv6 address */
nd_uint32_t rreq_os; /* originator sequence number */
};
struct aodv_rreq6_draft_01 {
uint8_t rreq_type; /* AODV message type (16) */
uint8_t rreq_flags; /* various flags */
uint8_t rreq_zero0; /* reserved, set to zero */
uint8_t rreq_hops; /* number of hops from originator */
uint32_t rreq_id; /* request ID */
uint32_t rreq_ds; /* destination sequence number */
uint32_t rreq_os; /* originator sequence number */
struct in6_addr rreq_da; /* destination IPv6 address */
struct in6_addr rreq_oa; /* originator IPv6 address */
nd_uint8_t rreq_type; /* AODV message type (16) */
nd_uint8_t rreq_flags; /* various flags */
nd_uint8_t rreq_zero0; /* reserved, set to zero */
nd_uint8_t rreq_hops; /* number of hops from originator */
nd_uint32_t rreq_id; /* request ID */
nd_uint32_t rreq_ds; /* destination sequence number */
nd_uint32_t rreq_os; /* originator sequence number */
nd_ipv6 rreq_da; /* destination IPv6 address */
nd_ipv6 rreq_oa; /* originator IPv6 address */
};
#define RREQ_JOIN 0x80 /* join (reserved for multicast */
@ -85,34 +87,34 @@ struct aodv_rreq6_draft_01 {
#define RREQ_FLAGS_MASK 0xF8 /* mask for rreq_flags */
struct aodv_rrep {
uint8_t rrep_type; /* AODV message type (2) */
uint8_t rrep_flags; /* various flags */
uint8_t rrep_ps; /* prefix size */
uint8_t rrep_hops; /* number of hops from o to d */
uint32_t rrep_da; /* destination IPv4 address */
uint32_t rrep_ds; /* destination sequence number */
uint32_t rrep_oa; /* originator IPv4 address */
uint32_t rrep_life; /* lifetime of this route */
nd_uint8_t rrep_type; /* AODV message type (2) */
nd_uint8_t rrep_flags; /* various flags */
nd_uint8_t rrep_ps; /* prefix size */
nd_uint8_t rrep_hops; /* number of hops from o to d */
nd_ipv4 rrep_da; /* destination IPv4 address */
nd_uint32_t rrep_ds; /* destination sequence number */
nd_ipv4 rrep_oa; /* originator IPv4 address */
nd_uint32_t rrep_life; /* lifetime of this route */
};
struct aodv_rrep6 {
uint8_t rrep_type; /* AODV message type (2) */
uint8_t rrep_flags; /* various flags */
uint8_t rrep_ps; /* prefix size */
uint8_t rrep_hops; /* number of hops from o to d */
struct in6_addr rrep_da; /* destination IPv6 address */
uint32_t rrep_ds; /* destination sequence number */
struct in6_addr rrep_oa; /* originator IPv6 address */
uint32_t rrep_life; /* lifetime of this route */
nd_uint8_t rrep_type; /* AODV message type (2) */
nd_uint8_t rrep_flags; /* various flags */
nd_uint8_t rrep_ps; /* prefix size */
nd_uint8_t rrep_hops; /* number of hops from o to d */
nd_ipv6 rrep_da; /* destination IPv6 address */
nd_uint32_t rrep_ds; /* destination sequence number */
nd_ipv6 rrep_oa; /* originator IPv6 address */
nd_uint32_t rrep_life; /* lifetime of this route */
};
struct aodv_rrep6_draft_01 {
uint8_t rrep_type; /* AODV message type (17) */
uint8_t rrep_flags; /* various flags */
uint8_t rrep_ps; /* prefix size */
uint8_t rrep_hops; /* number of hops from o to d */
uint32_t rrep_ds; /* destination sequence number */
struct in6_addr rrep_da; /* destination IPv6 address */
struct in6_addr rrep_oa; /* originator IPv6 address */
uint32_t rrep_life; /* lifetime of this route */
nd_uint8_t rrep_type; /* AODV message type (17) */
nd_uint8_t rrep_flags; /* various flags */
nd_uint8_t rrep_ps; /* prefix size */
nd_uint8_t rrep_hops; /* number of hops from o to d */
nd_uint32_t rrep_ds; /* destination sequence number */
nd_ipv6 rrep_da; /* destination IPv6 address */
nd_ipv6 rrep_oa; /* originator IPv6 address */
nd_uint32_t rrep_life; /* lifetime of this route */
};
#define RREP_REPAIR 0x80 /* repair (reserved for multicast */
@ -121,31 +123,31 @@ struct aodv_rrep6_draft_01 {
#define RREP_PREFIX_MASK 0x1F /* mask for prefix size */
struct rerr_unreach {
uint32_t u_da; /* IPv4 address */
uint32_t u_ds; /* sequence number */
nd_ipv4 u_da; /* IPv4 address */
nd_uint32_t u_ds; /* sequence number */
};
struct rerr_unreach6 {
struct in6_addr u_da; /* IPv6 address */
uint32_t u_ds; /* sequence number */
nd_ipv6 u_da; /* IPv6 address */
nd_uint32_t u_ds; /* sequence number */
};
struct rerr_unreach6_draft_01 {
struct in6_addr u_da; /* IPv6 address */
uint32_t u_ds; /* sequence number */
nd_ipv6 u_da; /* IPv6 address */
nd_uint32_t u_ds; /* sequence number */
};
struct aodv_rerr {
uint8_t rerr_type; /* AODV message type (3 or 18) */
uint8_t rerr_flags; /* various flags */
uint8_t rerr_zero0; /* reserved, set to zero */
uint8_t rerr_dc; /* destination count */
nd_uint8_t rerr_type; /* AODV message type (3 or 18) */
nd_uint8_t rerr_flags; /* various flags */
nd_uint8_t rerr_zero0; /* reserved, set to zero */
nd_uint8_t rerr_dc; /* destination count */
};
#define RERR_NODELETE 0x80 /* don't delete the link */
#define RERR_FLAGS_MASK 0x80 /* mask for rerr_flags */
struct aodv_rrep_ack {
uint8_t ra_type;
uint8_t ra_zero0;
nd_uint8_t ra_type;
nd_uint8_t ra_zero0;
};
#define AODV_RREQ 1 /* route request */
@ -159,13 +161,13 @@ struct aodv_rrep_ack {
#define AODV_V6_DRAFT_01_RREP_ACK 19 /* IPV6 route response acknowledgment */
struct aodv_ext {
uint8_t type; /* extension type */
uint8_t length; /* extension length */
nd_uint8_t type; /* extension type */
nd_uint8_t length; /* extension length */
};
struct aodv_hello {
struct aodv_ext eh; /* extension header */
uint8_t interval[4]; /* expect my next hello in
nd_uint32_t interval; /* expect my next hello in
* (n) ms
* NOTE: this is not aligned */
};
@ -178,24 +180,31 @@ aodv_extension(netdissect_options *ndo,
{
const struct aodv_hello *ah;
switch (ep->type) {
ND_TCHECK_SIZE(ep);
switch (GET_U_1(ep->type)) {
case AODV_EXT_HELLO:
ah = (const struct aodv_hello *)(const void *)ep;
ND_TCHECK(*ah);
ND_TCHECK_SIZE(ah);
if (length < sizeof(struct aodv_hello))
goto trunc;
ND_PRINT((ndo, "\n\text HELLO %ld ms",
(unsigned long)EXTRACT_32BITS(&ah->interval)));
if (GET_U_1(ep->length) < 4) {
ND_PRINT("\n\text HELLO - bad length %u",
GET_U_1(ep->length));
break;
}
ND_PRINT("\n\text HELLO %u ms",
GET_BE_U_4(ah->interval));
break;
default:
ND_PRINT((ndo, "\n\text %u %u", ep->type, ep->length));
ND_PRINT("\n\text %u %u", GET_U_1(ep->type),
GET_U_1(ep->length));
break;
}
return;
trunc:
ND_PRINT((ndo, " [|hello]"));
nd_print_trunc(ndo);
}
static void
@ -204,29 +213,29 @@ aodv_rreq(netdissect_options *ndo, const u_char *dat, u_int length)
u_int i;
const struct aodv_rreq *ap = (const struct aodv_rreq *)dat;
ND_TCHECK(*ap);
ND_TCHECK_SIZE(ap);
if (length < sizeof(*ap))
goto trunc;
ND_PRINT((ndo, " rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
"\tdst %s seq %lu src %s seq %lu", length,
ap->rreq_type & RREQ_JOIN ? "[J]" : "",
ap->rreq_type & RREQ_REPAIR ? "[R]" : "",
ap->rreq_type & RREQ_GRAT ? "[G]" : "",
ap->rreq_type & RREQ_DEST ? "[D]" : "",
ap->rreq_type & RREQ_UNKNOWN ? "[U] " : " ",
ap->rreq_hops,
(unsigned long)EXTRACT_32BITS(&ap->rreq_id),
ipaddr_string(ndo, &ap->rreq_da),
(unsigned long)EXTRACT_32BITS(&ap->rreq_ds),
ipaddr_string(ndo, &ap->rreq_oa),
(unsigned long)EXTRACT_32BITS(&ap->rreq_os)));
ND_PRINT(" rreq %u %s%s%s%s%shops %u id 0x%08x\n"
"\tdst %s seq %u src %s seq %u", length,
GET_U_1(ap->rreq_type) & RREQ_JOIN ? "[J]" : "",
GET_U_1(ap->rreq_type) & RREQ_REPAIR ? "[R]" : "",
GET_U_1(ap->rreq_type) & RREQ_GRAT ? "[G]" : "",
GET_U_1(ap->rreq_type) & RREQ_DEST ? "[D]" : "",
GET_U_1(ap->rreq_type) & RREQ_UNKNOWN ? "[U] " : " ",
GET_U_1(ap->rreq_hops),
GET_BE_U_4(ap->rreq_id),
GET_IPADDR_STRING(ap->rreq_da),
GET_BE_U_4(ap->rreq_ds),
GET_IPADDR_STRING(ap->rreq_oa),
GET_BE_U_4(ap->rreq_os));
i = length - sizeof(*ap);
if (i >= sizeof(struct aodv_ext))
aodv_extension(ndo, (const struct aodv_ext *)(dat + sizeof(*ap)), i);
return;
trunc:
ND_PRINT((ndo, " [|rreq"));
nd_print_trunc(ndo);
}
static void
@ -235,26 +244,26 @@ aodv_rrep(netdissect_options *ndo, const u_char *dat, u_int length)
u_int i;
const struct aodv_rrep *ap = (const struct aodv_rrep *)dat;
ND_TCHECK(*ap);
ND_TCHECK_SIZE(ap);
if (length < sizeof(*ap))
goto trunc;
ND_PRINT((ndo, " rrep %u %s%sprefix %u hops %u\n"
"\tdst %s dseq %lu src %s %lu ms", length,
ap->rrep_type & RREP_REPAIR ? "[R]" : "",
ap->rrep_type & RREP_ACK ? "[A] " : " ",
ap->rrep_ps & RREP_PREFIX_MASK,
ap->rrep_hops,
ipaddr_string(ndo, &ap->rrep_da),
(unsigned long)EXTRACT_32BITS(&ap->rrep_ds),
ipaddr_string(ndo, &ap->rrep_oa),
(unsigned long)EXTRACT_32BITS(&ap->rrep_life)));
ND_PRINT(" rrep %u %s%sprefix %u hops %u\n"
"\tdst %s dseq %u src %s %u ms", length,
GET_U_1(ap->rrep_type) & RREP_REPAIR ? "[R]" : "",
GET_U_1(ap->rrep_type) & RREP_ACK ? "[A] " : " ",
GET_U_1(ap->rrep_ps) & RREP_PREFIX_MASK,
GET_U_1(ap->rrep_hops),
GET_IPADDR_STRING(ap->rrep_da),
GET_BE_U_4(ap->rrep_ds),
GET_IPADDR_STRING(ap->rrep_oa),
GET_BE_U_4(ap->rrep_life));
i = length - sizeof(*ap);
if (i >= sizeof(struct aodv_ext))
aodv_extension(ndo, (const struct aodv_ext *)(dat + sizeof(*ap)), i);
return;
trunc:
ND_PRINT((ndo, " [|rreq"));
nd_print_trunc(ndo);
}
static void
@ -264,27 +273,27 @@ aodv_rerr(netdissect_options *ndo, const u_char *dat, u_int length)
const struct aodv_rerr *ap = (const struct aodv_rerr *)dat;
const struct rerr_unreach *dp;
ND_TCHECK(*ap);
ND_TCHECK_SIZE(ap);
if (length < sizeof(*ap))
goto trunc;
ND_PRINT((ndo, " rerr %s [items %u] [%u]:",
ap->rerr_flags & RERR_NODELETE ? "[D]" : "",
ap->rerr_dc, length));
ND_PRINT(" rerr %s [items %u] [%u]:",
GET_U_1(ap->rerr_flags) & RERR_NODELETE ? "[D]" : "",
GET_U_1(ap->rerr_dc), length);
dp = (const struct rerr_unreach *)(dat + sizeof(*ap));
i = length - sizeof(*ap);
for (dc = ap->rerr_dc; dc != 0; dc--) {
ND_TCHECK(*dp);
for (dc = GET_U_1(ap->rerr_dc); dc != 0; dc--) {
ND_TCHECK_SIZE(dp);
if (i < sizeof(*dp))
goto trunc;
ND_PRINT((ndo, " {%s}(%ld)", ipaddr_string(ndo, &dp->u_da),
(unsigned long)EXTRACT_32BITS(&dp->u_ds)));
ND_PRINT(" {%s}(%u)", GET_IPADDR_STRING(dp->u_da),
GET_BE_U_4(dp->u_ds));
dp++;
i -= sizeof(*dp);
}
return;
trunc:
ND_PRINT((ndo, "[|rerr]"));
nd_print_trunc(ndo);
}
static void
@ -293,29 +302,29 @@ aodv_v6_rreq(netdissect_options *ndo, const u_char *dat, u_int length)
u_int i;
const struct aodv_rreq6 *ap = (const struct aodv_rreq6 *)dat;
ND_TCHECK(*ap);
ND_TCHECK_SIZE(ap);
if (length < sizeof(*ap))
goto trunc;
ND_PRINT((ndo, " v6 rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
"\tdst %s seq %lu src %s seq %lu", length,
ap->rreq_type & RREQ_JOIN ? "[J]" : "",
ap->rreq_type & RREQ_REPAIR ? "[R]" : "",
ap->rreq_type & RREQ_GRAT ? "[G]" : "",
ap->rreq_type & RREQ_DEST ? "[D]" : "",
ap->rreq_type & RREQ_UNKNOWN ? "[U] " : " ",
ap->rreq_hops,
(unsigned long)EXTRACT_32BITS(&ap->rreq_id),
ip6addr_string(ndo, &ap->rreq_da),
(unsigned long)EXTRACT_32BITS(&ap->rreq_ds),
ip6addr_string(ndo, &ap->rreq_oa),
(unsigned long)EXTRACT_32BITS(&ap->rreq_os)));
ND_PRINT(" v6 rreq %u %s%s%s%s%shops %u id 0x%08x\n"
"\tdst %s seq %u src %s seq %u", length,
GET_U_1(ap->rreq_type) & RREQ_JOIN ? "[J]" : "",
GET_U_1(ap->rreq_type) & RREQ_REPAIR ? "[R]" : "",
GET_U_1(ap->rreq_type) & RREQ_GRAT ? "[G]" : "",
GET_U_1(ap->rreq_type) & RREQ_DEST ? "[D]" : "",
GET_U_1(ap->rreq_type) & RREQ_UNKNOWN ? "[U] " : " ",
GET_U_1(ap->rreq_hops),
GET_BE_U_4(ap->rreq_id),
GET_IP6ADDR_STRING(ap->rreq_da),
GET_BE_U_4(ap->rreq_ds),
GET_IP6ADDR_STRING(ap->rreq_oa),
GET_BE_U_4(ap->rreq_os));
i = length - sizeof(*ap);
if (i >= sizeof(struct aodv_ext))
aodv_extension(ndo, (const struct aodv_ext *)(dat + sizeof(*ap)), i);
return;
trunc:
ND_PRINT((ndo, " [|rreq"));
nd_print_trunc(ndo);
}
static void
@ -324,26 +333,26 @@ aodv_v6_rrep(netdissect_options *ndo, const u_char *dat, u_int length)
u_int i;
const struct aodv_rrep6 *ap = (const struct aodv_rrep6 *)dat;
ND_TCHECK(*ap);
ND_TCHECK_SIZE(ap);
if (length < sizeof(*ap))
goto trunc;
ND_PRINT((ndo, " rrep %u %s%sprefix %u hops %u\n"
"\tdst %s dseq %lu src %s %lu ms", length,
ap->rrep_type & RREP_REPAIR ? "[R]" : "",
ap->rrep_type & RREP_ACK ? "[A] " : " ",
ap->rrep_ps & RREP_PREFIX_MASK,
ap->rrep_hops,
ip6addr_string(ndo, &ap->rrep_da),
(unsigned long)EXTRACT_32BITS(&ap->rrep_ds),
ip6addr_string(ndo, &ap->rrep_oa),
(unsigned long)EXTRACT_32BITS(&ap->rrep_life)));
ND_PRINT(" rrep %u %s%sprefix %u hops %u\n"
"\tdst %s dseq %u src %s %u ms", length,
GET_U_1(ap->rrep_type) & RREP_REPAIR ? "[R]" : "",
GET_U_1(ap->rrep_type) & RREP_ACK ? "[A] " : " ",
GET_U_1(ap->rrep_ps) & RREP_PREFIX_MASK,
GET_U_1(ap->rrep_hops),
GET_IP6ADDR_STRING(ap->rrep_da),
GET_BE_U_4(ap->rrep_ds),
GET_IP6ADDR_STRING(ap->rrep_oa),
GET_BE_U_4(ap->rrep_life));
i = length - sizeof(*ap);
if (i >= sizeof(struct aodv_ext))
aodv_extension(ndo, (const struct aodv_ext *)(dat + sizeof(*ap)), i);
return;
trunc:
ND_PRINT((ndo, " [|rreq"));
nd_print_trunc(ndo);
}
static void
@ -353,27 +362,27 @@ aodv_v6_rerr(netdissect_options *ndo, const u_char *dat, u_int length)
const struct aodv_rerr *ap = (const struct aodv_rerr *)dat;
const struct rerr_unreach6 *dp6;
ND_TCHECK(*ap);
ND_TCHECK_SIZE(ap);
if (length < sizeof(*ap))
goto trunc;
ND_PRINT((ndo, " rerr %s [items %u] [%u]:",
ap->rerr_flags & RERR_NODELETE ? "[D]" : "",
ap->rerr_dc, length));
ND_PRINT(" rerr %s [items %u] [%u]:",
GET_U_1(ap->rerr_flags) & RERR_NODELETE ? "[D]" : "",
GET_U_1(ap->rerr_dc), length);
dp6 = (const struct rerr_unreach6 *)(const void *)(ap + 1);
i = length - sizeof(*ap);
for (dc = ap->rerr_dc; dc != 0; dc--) {
ND_TCHECK(*dp6);
for (dc = GET_U_1(ap->rerr_dc); dc != 0; dc--) {
ND_TCHECK_SIZE(dp6);
if (i < sizeof(*dp6))
goto trunc;
ND_PRINT((ndo, " {%s}(%ld)", ip6addr_string(ndo, &dp6->u_da),
(unsigned long)EXTRACT_32BITS(&dp6->u_ds)));
ND_PRINT(" {%s}(%u)", GET_IP6ADDR_STRING(dp6->u_da),
GET_BE_U_4(dp6->u_ds));
dp6++;
i -= sizeof(*dp6);
}
return;
trunc:
ND_PRINT((ndo, "[|rerr]"));
nd_print_trunc(ndo);
}
static void
@ -382,29 +391,29 @@ aodv_v6_draft_01_rreq(netdissect_options *ndo, const u_char *dat, u_int length)
u_int i;
const struct aodv_rreq6_draft_01 *ap = (const struct aodv_rreq6_draft_01 *)dat;
ND_TCHECK(*ap);
ND_TCHECK_SIZE(ap);
if (length < sizeof(*ap))
goto trunc;
ND_PRINT((ndo, " rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
"\tdst %s seq %lu src %s seq %lu", length,
ap->rreq_type & RREQ_JOIN ? "[J]" : "",
ap->rreq_type & RREQ_REPAIR ? "[R]" : "",
ap->rreq_type & RREQ_GRAT ? "[G]" : "",
ap->rreq_type & RREQ_DEST ? "[D]" : "",
ap->rreq_type & RREQ_UNKNOWN ? "[U] " : " ",
ap->rreq_hops,
(unsigned long)EXTRACT_32BITS(&ap->rreq_id),
ip6addr_string(ndo, &ap->rreq_da),
(unsigned long)EXTRACT_32BITS(&ap->rreq_ds),
ip6addr_string(ndo, &ap->rreq_oa),
(unsigned long)EXTRACT_32BITS(&ap->rreq_os)));
ND_PRINT(" rreq %u %s%s%s%s%shops %u id 0x%08x\n"
"\tdst %s seq %u src %s seq %u", length,
GET_U_1(ap->rreq_type) & RREQ_JOIN ? "[J]" : "",
GET_U_1(ap->rreq_type) & RREQ_REPAIR ? "[R]" : "",
GET_U_1(ap->rreq_type) & RREQ_GRAT ? "[G]" : "",
GET_U_1(ap->rreq_type) & RREQ_DEST ? "[D]" : "",
GET_U_1(ap->rreq_type) & RREQ_UNKNOWN ? "[U] " : " ",
GET_U_1(ap->rreq_hops),
GET_BE_U_4(ap->rreq_id),
GET_IP6ADDR_STRING(ap->rreq_da),
GET_BE_U_4(ap->rreq_ds),
GET_IP6ADDR_STRING(ap->rreq_oa),
GET_BE_U_4(ap->rreq_os));
i = length - sizeof(*ap);
if (i >= sizeof(struct aodv_ext))
aodv_extension(ndo, (const struct aodv_ext *)(dat + sizeof(*ap)), i);
return;
trunc:
ND_PRINT((ndo, " [|rreq"));
nd_print_trunc(ndo);
}
static void
@ -413,26 +422,26 @@ aodv_v6_draft_01_rrep(netdissect_options *ndo, const u_char *dat, u_int length)
u_int i;
const struct aodv_rrep6_draft_01 *ap = (const struct aodv_rrep6_draft_01 *)dat;
ND_TCHECK(*ap);
ND_TCHECK_SIZE(ap);
if (length < sizeof(*ap))
goto trunc;
ND_PRINT((ndo, " rrep %u %s%sprefix %u hops %u\n"
"\tdst %s dseq %lu src %s %lu ms", length,
ap->rrep_type & RREP_REPAIR ? "[R]" : "",
ap->rrep_type & RREP_ACK ? "[A] " : " ",
ap->rrep_ps & RREP_PREFIX_MASK,
ap->rrep_hops,
ip6addr_string(ndo, &ap->rrep_da),
(unsigned long)EXTRACT_32BITS(&ap->rrep_ds),
ip6addr_string(ndo, &ap->rrep_oa),
(unsigned long)EXTRACT_32BITS(&ap->rrep_life)));
ND_PRINT(" rrep %u %s%sprefix %u hops %u\n"
"\tdst %s dseq %u src %s %u ms", length,
GET_U_1(ap->rrep_type) & RREP_REPAIR ? "[R]" : "",
GET_U_1(ap->rrep_type) & RREP_ACK ? "[A] " : " ",
GET_U_1(ap->rrep_ps) & RREP_PREFIX_MASK,
GET_U_1(ap->rrep_hops),
GET_IP6ADDR_STRING(ap->rrep_da),
GET_BE_U_4(ap->rrep_ds),
GET_IP6ADDR_STRING(ap->rrep_oa),
GET_BE_U_4(ap->rrep_life));
i = length - sizeof(*ap);
if (i >= sizeof(struct aodv_ext))
aodv_extension(ndo, (const struct aodv_ext *)(dat + sizeof(*ap)), i);
return;
trunc:
ND_PRINT((ndo, " [|rreq"));
nd_print_trunc(ndo);
}
static void
@ -442,27 +451,27 @@ aodv_v6_draft_01_rerr(netdissect_options *ndo, const u_char *dat, u_int length)
const struct aodv_rerr *ap = (const struct aodv_rerr *)dat;
const struct rerr_unreach6_draft_01 *dp6;
ND_TCHECK(*ap);
ND_TCHECK_SIZE(ap);
if (length < sizeof(*ap))
goto trunc;
ND_PRINT((ndo, " rerr %s [items %u] [%u]:",
ap->rerr_flags & RERR_NODELETE ? "[D]" : "",
ap->rerr_dc, length));
ND_PRINT(" rerr %s [items %u] [%u]:",
GET_U_1(ap->rerr_flags) & RERR_NODELETE ? "[D]" : "",
GET_U_1(ap->rerr_dc), length);
dp6 = (const struct rerr_unreach6_draft_01 *)(const void *)(ap + 1);
i = length - sizeof(*ap);
for (dc = ap->rerr_dc; dc != 0; dc--) {
ND_TCHECK(*dp6);
for (dc = GET_U_1(ap->rerr_dc); dc != 0; dc--) {
ND_TCHECK_SIZE(dp6);
if (i < sizeof(*dp6))
goto trunc;
ND_PRINT((ndo, " {%s}(%ld)", ip6addr_string(ndo, &dp6->u_da),
(unsigned long)EXTRACT_32BITS(&dp6->u_ds)));
ND_PRINT(" {%s}(%u)", GET_IP6ADDR_STRING(dp6->u_da),
GET_BE_U_4(dp6->u_ds));
dp6++;
i -= sizeof(*dp6);
}
return;
trunc:
ND_PRINT((ndo, "[|rerr]"));
nd_print_trunc(ndo);
}
void
@ -471,13 +480,14 @@ aodv_print(netdissect_options *ndo,
{
uint8_t msg_type;
ndo->ndo_protocol = "aodv";
/*
* The message type is the first byte; make sure we have it
* and then fetch it.
*/
ND_TCHECK(*dat);
msg_type = *dat;
ND_PRINT((ndo, " aodv"));
ND_TCHECK_1(dat);
msg_type = GET_U_1(dat);
ND_PRINT(" aodv");
switch (msg_type) {
@ -503,7 +513,7 @@ aodv_print(netdissect_options *ndo,
break;
case AODV_RREP_ACK:
ND_PRINT((ndo, " rrep-ack %u", length));
ND_PRINT(" rrep-ack %u", length);
break;
case AODV_V6_DRAFT_01_RREQ:
@ -519,14 +529,14 @@ aodv_print(netdissect_options *ndo,
break;
case AODV_V6_DRAFT_01_RREP_ACK:
ND_PRINT((ndo, " rrep-ack %u", length));
ND_PRINT(" rrep-ack %u", length);
break;
default:
ND_PRINT((ndo, " type %u %u", msg_type, length));
ND_PRINT(" type %u %u", msg_type, length);
}
return;
trunc:
ND_PRINT((ndo, " [|aodv]"));
nd_print_trunc(ndo);
}

View File

@ -27,20 +27,20 @@
/* \summary: ATA over Ethernet (AoE) protocol printer */
/* specification: http://brantleycoilecompany.com/AoEr11.pdf */
/* specification:
* https://web.archive.org/web/20161025044402/http://brantleycoilecompany.com/AoEr11.pdf
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "extract.h"
#include "addrtoname.h"
#include "ether.h"
static const char tstr[] = " [|aoe]";
#define AOE_V1 1
#define ATA_SECTOR_SIZE 512
@ -143,199 +143,205 @@ static void
aoev1_issue_print(netdissect_options *ndo,
const u_char *cp, const u_int len)
{
const u_char *ep = cp + len;
const u_char *ep = ndo->ndo_snapend;
if (len < AOEV1_ISSUE_ARG_LEN)
goto invalid;
/* AFlags */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, "\n\tAFlags: [%s]", bittok2str(aoev1_aflag_str, "none", *cp)));
ND_TCHECK_1(cp);
ND_PRINT("\n\tAFlags: [%s]",
bittok2str(aoev1_aflag_str, "none", GET_U_1(cp)));
cp += 1;
/* Err/Feature */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, ", Err/Feature: %u", *cp));
ND_TCHECK_1(cp);
ND_PRINT(", Err/Feature: %u", GET_U_1(cp));
cp += 1;
/* Sector Count (not correlated with the length) */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, ", Sector Count: %u", *cp));
ND_TCHECK_1(cp);
ND_PRINT(", Sector Count: %u", GET_U_1(cp));
cp += 1;
/* Cmd/Status */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, ", Cmd/Status: %u", *cp));
ND_TCHECK_1(cp);
ND_PRINT(", Cmd/Status: %u", GET_U_1(cp));
cp += 1;
/* lba0 */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, "\n\tlba0: %u", *cp));
ND_TCHECK_1(cp);
ND_PRINT("\n\tlba0: %u", GET_U_1(cp));
cp += 1;
/* lba1 */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, ", lba1: %u", *cp));
ND_TCHECK_1(cp);
ND_PRINT(", lba1: %u", GET_U_1(cp));
cp += 1;
/* lba2 */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, ", lba2: %u", *cp));
ND_TCHECK_1(cp);
ND_PRINT(", lba2: %u", GET_U_1(cp));
cp += 1;
/* lba3 */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, ", lba3: %u", *cp));
ND_TCHECK_1(cp);
ND_PRINT(", lba3: %u", GET_U_1(cp));
cp += 1;
/* lba4 */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, ", lba4: %u", *cp));
ND_TCHECK_1(cp);
ND_PRINT(", lba4: %u", GET_U_1(cp));
cp += 1;
/* lba5 */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, ", lba5: %u", *cp));
ND_TCHECK_1(cp);
ND_PRINT(", lba5: %u", GET_U_1(cp));
cp += 1;
/* Reserved */
ND_TCHECK2(*cp, 2);
ND_TCHECK_2(cp);
cp += 2;
/* Data */
if (len > AOEV1_ISSUE_ARG_LEN)
ND_PRINT((ndo, "\n\tData: %u bytes", len - AOEV1_ISSUE_ARG_LEN));
ND_PRINT("\n\tData: %u bytes", len - AOEV1_ISSUE_ARG_LEN);
return;
invalid:
ND_PRINT((ndo, "%s", istr));
ND_TCHECK2(*cp, ep - cp);
nd_print_invalid(ndo);
ND_TCHECK_LEN(cp, ep - cp);
return;
trunc:
ND_PRINT((ndo, "%s", tstr));
nd_print_trunc(ndo);
}
static void
aoev1_query_print(netdissect_options *ndo,
const u_char *cp, const u_int len)
{
const u_char *ep = cp + len;
const u_char *ep = ndo->ndo_snapend;
uint16_t cslen;
if (len < AOEV1_QUERY_ARG_LEN)
goto invalid;
/* Buffer Count */
ND_TCHECK2(*cp, 2);
ND_PRINT((ndo, "\n\tBuffer Count: %u", EXTRACT_16BITS(cp)));
ND_TCHECK_2(cp);
ND_PRINT("\n\tBuffer Count: %u", GET_BE_U_2(cp));
cp += 2;
/* Firmware Version */
ND_TCHECK2(*cp, 2);
ND_PRINT((ndo, ", Firmware Version: %u", EXTRACT_16BITS(cp)));
ND_TCHECK_2(cp);
ND_PRINT(", Firmware Version: %u", GET_BE_U_2(cp));
cp += 2;
/* Sector Count */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, ", Sector Count: %u", *cp));
ND_TCHECK_1(cp);
ND_PRINT(", Sector Count: %u", GET_U_1(cp));
cp += 1;
/* AoE/CCmd */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, ", AoE: %u, CCmd: %s", (*cp & 0xF0) >> 4,
tok2str(aoev1_ccmd_str, "Unknown (0x02x)", *cp & 0x0F)));
ND_TCHECK_1(cp);
ND_PRINT(", AoE: %u, CCmd: %s", (GET_U_1(cp) & 0xF0) >> 4,
tok2str(aoev1_ccmd_str, "Unknown (0x02x)", GET_U_1(cp) & 0x0F));
cp += 1;
/* Config String Length */
ND_TCHECK2(*cp, 2);
cslen = EXTRACT_16BITS(cp);
ND_TCHECK_2(cp);
cslen = GET_BE_U_2(cp);
cp += 2;
if (cslen > AOEV1_MAX_CONFSTR_LEN || AOEV1_QUERY_ARG_LEN + cslen > len)
goto invalid;
/* Config String */
ND_TCHECK2(*cp, cslen);
if (cslen) {
ND_PRINT((ndo, "\n\tConfig String (length %u): ", cslen));
if (fn_printn(ndo, cp, cslen, ndo->ndo_snapend))
ND_TCHECK_LEN(cp, cslen);
ND_PRINT("\n\tConfig String (length %u): ", cslen);
if (nd_printn(ndo, cp, cslen, ndo->ndo_snapend))
goto trunc;
}
return;
invalid:
ND_PRINT((ndo, "%s", istr));
ND_TCHECK2(*cp, ep - cp);
nd_print_invalid(ndo);
ND_TCHECK_LEN(cp, ep - cp);
return;
trunc:
ND_PRINT((ndo, "%s", tstr));
nd_print_trunc(ndo);
}
static void
aoev1_mac_print(netdissect_options *ndo,
const u_char *cp, const u_int len)
{
const u_char *ep = cp + len;
const u_char *ep = ndo->ndo_snapend;
uint8_t dircount, i;
if (len < AOEV1_MAC_ARG_LEN)
goto invalid;
/* Reserved */
ND_TCHECK2(*cp, 1);
ND_TCHECK_1(cp);
cp += 1;
/* MCmd */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, "\n\tMCmd: %s", tok2str(aoev1_mcmd_str, "Unknown (0x%02x)", *cp)));
ND_TCHECK_1(cp);
ND_PRINT("\n\tMCmd: %s",
tok2str(aoev1_mcmd_str, "Unknown (0x%02x)", GET_U_1(cp)));
cp += 1;
/* MError */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, ", MError: %s", tok2str(aoev1_merror_str, "Unknown (0x%02x)", *cp)));
ND_TCHECK_1(cp);
ND_PRINT(", MError: %s",
tok2str(aoev1_merror_str, "Unknown (0x%02x)", GET_U_1(cp)));
cp += 1;
/* Dir Count */
ND_TCHECK2(*cp, 1);
dircount = *cp;
ND_TCHECK_1(cp);
dircount = GET_U_1(cp);
cp += 1;
ND_PRINT((ndo, ", Dir Count: %u", dircount));
ND_PRINT(", Dir Count: %u", dircount);
if (AOEV1_MAC_ARG_LEN + dircount * 8 > len)
goto invalid;
/* directives */
for (i = 0; i < dircount; i++) {
/* Reserved */
ND_TCHECK2(*cp, 1);
ND_TCHECK_1(cp);
cp += 1;
/* DCmd */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, "\n\t DCmd: %s", tok2str(aoev1_dcmd_str, "Unknown (0x%02x)", *cp)));
ND_TCHECK_1(cp);
ND_PRINT("\n\t DCmd: %s",
tok2str(aoev1_dcmd_str, "Unknown (0x%02x)", GET_U_1(cp)));
cp += 1;
/* Ethernet Address */
ND_TCHECK2(*cp, ETHER_ADDR_LEN);
ND_PRINT((ndo, ", Ethernet Address: %s", etheraddr_string(ndo, cp)));
cp += ETHER_ADDR_LEN;
ND_TCHECK_LEN(cp, MAC_ADDR_LEN);
ND_PRINT(", Ethernet Address: %s", GET_ETHERADDR_STRING(cp));
cp += MAC_ADDR_LEN;
}
return;
invalid:
ND_PRINT((ndo, "%s", istr));
ND_TCHECK2(*cp, ep - cp);
nd_print_invalid(ndo);
ND_TCHECK_LEN(cp, ep - cp);
return;
trunc:
ND_PRINT((ndo, "%s", tstr));
nd_print_trunc(ndo);
}
static void
aoev1_reserve_print(netdissect_options *ndo,
const u_char *cp, const u_int len)
{
const u_char *ep = cp + len;
const u_char *ep = ndo->ndo_snapend;
uint8_t nmacs, i;
if (len < AOEV1_RESERVE_ARG_LEN || (len - AOEV1_RESERVE_ARG_LEN) % ETHER_ADDR_LEN)
if (len < AOEV1_RESERVE_ARG_LEN || (len - AOEV1_RESERVE_ARG_LEN) % MAC_ADDR_LEN)
goto invalid;
/* RCmd */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, "\n\tRCmd: %s", tok2str(aoev1_rcmd_str, "Unknown (0x%02x)", *cp)));
ND_TCHECK_1(cp);
ND_PRINT("\n\tRCmd: %s",
tok2str(aoev1_rcmd_str, "Unknown (0x%02x)", GET_U_1(cp)));
cp += 1;
/* NMacs (correlated with the length) */
ND_TCHECK2(*cp, 1);
nmacs = *cp;
ND_TCHECK_1(cp);
nmacs = GET_U_1(cp);
cp += 1;
ND_PRINT((ndo, ", NMacs: %u", nmacs));
if (AOEV1_RESERVE_ARG_LEN + nmacs * ETHER_ADDR_LEN != len)
ND_PRINT(", NMacs: %u", nmacs);
if (AOEV1_RESERVE_ARG_LEN + nmacs * MAC_ADDR_LEN != len)
goto invalid;
/* addresses */
for (i = 0; i < nmacs; i++) {
ND_PRINT((ndo, "\n\tEthernet Address %u: %s", i, etheraddr_string(ndo, cp)));
cp += ETHER_ADDR_LEN;
ND_TCHECK_LEN(cp, MAC_ADDR_LEN);
ND_PRINT("\n\tEthernet Address %u: %s", i, GET_ETHERADDR_STRING(cp));
cp += MAC_ADDR_LEN;
}
return;
invalid:
ND_PRINT((ndo, "%s", istr));
ND_TCHECK2(*cp, ep - cp);
nd_print_invalid(ndo);
ND_TCHECK_LEN(cp, ep - cp);
return;
trunc:
ND_PRINT((ndo, "%s", tstr));
nd_print_trunc(ndo);
}
/* cp points to the Ver/Flags octet */
@ -343,39 +349,40 @@ static void
aoev1_print(netdissect_options *ndo,
const u_char *cp, const u_int len)
{
const u_char *ep = cp + len;
const u_char *ep = ndo->ndo_snapend;
uint8_t flags, command;
void (*cmd_decoder)(netdissect_options *, const u_char *, const u_int);
if (len < AOEV1_COMMON_HDR_LEN)
goto invalid;
/* Flags */
flags = *cp & 0x0F;
ND_PRINT((ndo, ", Flags: [%s]", bittok2str(aoev1_flag_str, "none", flags)));
flags = GET_U_1(cp) & 0x0F;
ND_PRINT(", Flags: [%s]", bittok2str(aoev1_flag_str, "none", flags));
cp += 1;
if (! ndo->ndo_vflag)
return;
/* Error */
ND_TCHECK2(*cp, 1);
ND_TCHECK_1(cp);
if (flags & AOEV1_FLAG_E)
ND_PRINT((ndo, "\n\tError: %s", tok2str(aoev1_errcode_str, "Invalid (%u)", *cp)));
ND_PRINT("\n\tError: %s",
tok2str(aoev1_errcode_str, "Invalid (%u)", GET_U_1(cp)));
cp += 1;
/* Major */
ND_TCHECK2(*cp, 2);
ND_PRINT((ndo, "\n\tMajor: 0x%04x", EXTRACT_16BITS(cp)));
ND_TCHECK_2(cp);
ND_PRINT("\n\tMajor: 0x%04x", GET_BE_U_2(cp));
cp += 2;
/* Minor */
ND_TCHECK2(*cp, 1);
ND_PRINT((ndo, ", Minor: 0x%02x", *cp));
ND_TCHECK_1(cp);
ND_PRINT(", Minor: 0x%02x", GET_U_1(cp));
cp += 1;
/* Command */
ND_TCHECK2(*cp, 1);
command = *cp;
ND_TCHECK_1(cp);
command = GET_U_1(cp);
cp += 1;
ND_PRINT((ndo, ", Command: %s", tok2str(cmdcode_str, "Unknown (0x%02x)", command)));
ND_PRINT(", Command: %s", tok2str(cmdcode_str, "Unknown (0x%02x)", command));
/* Tag */
ND_TCHECK2(*cp, 4);
ND_PRINT((ndo, ", Tag: 0x%08x", EXTRACT_32BITS(cp)));
ND_TCHECK_4(cp);
ND_PRINT(", Tag: 0x%08x", GET_BE_U_4(cp));
cp += 4;
/* Arg */
cmd_decoder =
@ -389,29 +396,30 @@ aoev1_print(netdissect_options *ndo,
return;
invalid:
ND_PRINT((ndo, "%s", istr));
ND_TCHECK2(*cp, ep - cp);
nd_print_invalid(ndo);
ND_TCHECK_LEN(cp, ep - cp);
return;
trunc:
ND_PRINT((ndo, "%s", tstr));
nd_print_trunc(ndo);
}
void
aoe_print(netdissect_options *ndo,
const u_char *cp, const u_int len)
{
const u_char *ep = cp + len;
const u_char *ep = ndo->ndo_snapend;
uint8_t ver;
ND_PRINT((ndo, "AoE length %u", len));
ndo->ndo_protocol = "aoe";
ND_PRINT("AoE length %u", len);
if (len < 1)
goto invalid;
/* Ver/Flags */
ND_TCHECK2(*cp, 1);
ver = (*cp & 0xF0) >> 4;
ND_TCHECK_1(cp);
ver = (GET_U_1(cp) & 0xF0) >> 4;
/* Don't advance cp yet: low order 4 bits are version-specific. */
ND_PRINT((ndo, ", Ver %u", ver));
ND_PRINT(", Ver %u", ver);
switch (ver) {
case AOE_V1:
@ -421,10 +429,10 @@ aoe_print(netdissect_options *ndo,
return;
invalid:
ND_PRINT((ndo, "%s", istr));
ND_TCHECK2(*cp, ep - cp);
nd_print_invalid(ndo);
ND_TCHECK_LEN(cp, ep - cp);
return;
trunc:
ND_PRINT((ndo, "%s", tstr));
nd_print_trunc(ndo);
}

View File

@ -22,10 +22,10 @@
/* \summary: Apple IP-over-IEEE 1394 printer */
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "extract.h"
@ -37,9 +37,9 @@
*/
#define FIREWIRE_EUI64_LEN 8
struct firewire_header {
u_char firewire_dhost[FIREWIRE_EUI64_LEN];
u_char firewire_shost[FIREWIRE_EUI64_LEN];
u_short firewire_type;
nd_byte firewire_dhost[FIREWIRE_EUI64_LEN];
nd_byte firewire_shost[FIREWIRE_EUI64_LEN];
nd_uint16_t firewire_type;
};
/*
@ -55,28 +55,28 @@ fwaddr_string(netdissect_options *ndo, const u_char *addr)
return (linkaddr_string(ndo, addr, LINKADDR_IEEE1394, FIREWIRE_EUI64_LEN));
}
static inline void
ap1394_hdr_print(netdissect_options *ndo, register const u_char *bp, u_int length)
static void
ap1394_hdr_print(netdissect_options *ndo, const u_char *bp, u_int length)
{
register const struct firewire_header *fp;
const struct firewire_header *fp;
uint16_t firewire_type;
fp = (const struct firewire_header *)bp;
ND_PRINT((ndo, "%s > %s",
ND_PRINT("%s > %s",
fwaddr_string(ndo, fp->firewire_shost),
fwaddr_string(ndo, fp->firewire_dhost)));
fwaddr_string(ndo, fp->firewire_dhost));
firewire_type = EXTRACT_16BITS(&fp->firewire_type);
firewire_type = GET_BE_U_2(fp->firewire_type);
if (!ndo->ndo_qflag) {
ND_PRINT((ndo, ", ethertype %s (0x%04x)",
ND_PRINT(", ethertype %s (0x%04x)",
tok2str(ethertype_values,"Unknown", firewire_type),
firewire_type));
firewire_type);
} else {
ND_PRINT((ndo, ", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", firewire_type)));
ND_PRINT(", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", firewire_type));
}
ND_PRINT((ndo, ", length %u: ", length));
ND_PRINT(", length %u: ", length);
}
/*
@ -85,7 +85,7 @@ ap1394_hdr_print(netdissect_options *ndo, register const u_char *bp, u_int lengt
* 'h->len' is the length of the packet off the wire, and 'h->caplen'
* is the number of bytes actually captured.
*/
u_int
void
ap1394_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
{
u_int length = h->len;
@ -94,10 +94,13 @@ ap1394_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_ch
u_short ether_type;
struct lladdr_info src, dst;
ndo->ndo_protocol = "ap1394";
if (caplen < FIREWIRE_HDRLEN) {
ND_PRINT((ndo, "[|ap1394]"));
return FIREWIRE_HDRLEN;
ndo->ndo_ll_header_length += caplen;
nd_print_trunc(ndo);
return;
}
ndo->ndo_ll_header_length += FIREWIRE_HDRLEN;
if (ndo->ndo_eflag)
ap1394_hdr_print(ndo, p, length);
@ -107,7 +110,7 @@ ap1394_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_ch
fp = (const struct firewire_header *)p;
p += FIREWIRE_HDRLEN;
ether_type = EXTRACT_16BITS(&fp->firewire_type);
ether_type = GET_BE_U_2(fp->firewire_type);
src.addr = fp->firewire_shost;
src.addr_string = fwaddr_string;
dst.addr = fp->firewire_dhost;
@ -121,5 +124,5 @@ ap1394_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_ch
ND_DEFAULTPRINT(p, caplen);
}
return FIREWIRE_HDRLEN;
return;
}

View File

@ -24,10 +24,10 @@
/* \summary: Attached Resource Computer NETwork (ARCNET) printer */
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "extract.h"
@ -41,22 +41,22 @@
* as given to interface code.
*/
struct arc_header {
uint8_t arc_shost;
uint8_t arc_dhost;
uint8_t arc_type;
nd_uint8_t arc_shost;
nd_uint8_t arc_dhost;
nd_uint8_t arc_type;
/*
* only present for newstyle encoding with LL fragmentation.
* Don't use sizeof(anything), use ARC_HDR{,NEW}LEN instead.
*/
uint8_t arc_flag;
uint16_t arc_seqid;
nd_uint8_t arc_flag;
nd_uint16_t arc_seqid;
/*
* only present in exception packets (arc_flag == 0xff)
*/
uint8_t arc_type2; /* same as arc_type */
uint8_t arc_flag2; /* real flag value */
uint16_t arc_seqid2; /* real seqid value */
nd_uint8_t arc_type2; /* same as arc_type */
nd_uint8_t arc_flag2; /* real flag value */
nd_uint16_t arc_seqid2; /* real seqid value */
};
#define ARC_HDRLEN 3
@ -85,17 +85,17 @@ struct arc_header {
* never presents packets that look like exception frames.
*/
struct arc_linux_header {
uint8_t arc_shost;
uint8_t arc_dhost;
uint16_t arc_offset;
uint8_t arc_type;
nd_uint8_t arc_shost;
nd_uint8_t arc_dhost;
nd_uint16_t arc_offset;
nd_uint8_t arc_type;
/*
* only present for newstyle encoding with LL fragmentation.
* Don't use sizeof(anything), use ARC_LINUX_HDR{,NEW}LEN
* instead.
*/
uint8_t arc_flag;
uint16_t arc_seqid;
nd_uint8_t arc_flag;
nd_uint16_t arc_seqid;
};
#define ARC_LINUX_HDRLEN 5
@ -115,54 +115,61 @@ static const struct tok arctypemap[] = {
{ ARCTYPE_IPX, "ipx" },
{ ARCTYPE_INET6, "ipv6" },
{ ARCTYPE_DIAGNOSE, "diag" },
{ 0, 0 }
{ 0, NULL }
};
static inline void
static void
arcnet_print(netdissect_options *ndo, const u_char *bp, u_int length, int phds,
int flag, u_int seqid)
u_int flag, u_int seqid)
{
const struct arc_header *ap;
const char *arctypename;
ndo->ndo_protocol = "arcnet";
ap = (const struct arc_header *)bp;
if (ndo->ndo_qflag) {
ND_PRINT((ndo, "%02x %02x %d: ",
ap->arc_shost,
ap->arc_dhost,
length));
ND_PRINT("%02x %02x %u: ",
GET_U_1(ap->arc_shost),
GET_U_1(ap->arc_dhost),
length);
return;
}
arctypename = tok2str(arctypemap, "%02x", ap->arc_type);
arctypename = tok2str(arctypemap, "%02x", GET_U_1(ap->arc_type));
if (!phds) {
ND_PRINT((ndo, "%02x %02x %s %d: ",
ap->arc_shost, ap->arc_dhost, arctypename,
length));
return;
ND_PRINT("%02x %02x %s %u: ",
GET_U_1(ap->arc_shost),
GET_U_1(ap->arc_dhost),
arctypename,
length);
return;
}
if (flag == 0) {
ND_PRINT((ndo, "%02x %02x %s seqid %04x %d: ",
ap->arc_shost, ap->arc_dhost, arctypename, seqid,
length));
return;
ND_PRINT("%02x %02x %s seqid %04x %u: ",
GET_U_1(ap->arc_shost),
GET_U_1(ap->arc_dhost),
arctypename, seqid,
length);
return;
}
if (flag & 1)
ND_PRINT((ndo, "%02x %02x %s seqid %04x "
"(first of %d fragments) %d: ",
ap->arc_shost, ap->arc_dhost, arctypename, seqid,
(flag + 3) / 2, length));
ND_PRINT("%02x %02x %s seqid %04x "
"(first of %u fragments) %u: ",
GET_U_1(ap->arc_shost),
GET_U_1(ap->arc_dhost),
arctypename, seqid,
(flag + 3) / 2, length);
else
ND_PRINT((ndo, "%02x %02x %s seqid %04x "
"(fragment %d) %d: ",
ap->arc_shost, ap->arc_dhost, arctypename, seqid,
flag/2 + 1, length));
ND_PRINT("%02x %02x %s seqid %04x "
"(fragment %u) %u: ",
GET_U_1(ap->arc_shost),
GET_U_1(ap->arc_dhost),
arctypename, seqid,
flag/2 + 1, length);
}
/*
@ -171,24 +178,27 @@ arcnet_print(netdissect_options *ndo, const u_char *bp, u_int length, int phds,
* 'h->len' is the length of the packet off the wire, and 'h->caplen'
* is the number of bytes actually captured.
*/
u_int
void
arcnet_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
{
u_int caplen = h->caplen;
u_int length = h->len;
const struct arc_header *ap;
int phds, flag = 0, archdrlen = 0;
int phds;
u_int flag = 0, archdrlen = 0;
u_int seqid = 0;
u_char arc_type;
if (caplen < ARC_HDRLEN || length < ARC_HDRLEN) {
ND_PRINT((ndo, "[|arcnet]"));
return (caplen);
ndo->ndo_protocol = "arcnet_if";
if (caplen < ARC_HDRLEN) {
nd_print_trunc(ndo);
ndo->ndo_ll_header_length += caplen;
return;
}
ap = (const struct arc_header *)p;
arc_type = ap->arc_type;
arc_type = GET_U_1(ap->arc_type);
switch (arc_type) {
default:
@ -203,24 +213,28 @@ arcnet_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_ch
}
if (phds) {
if (caplen < ARC_HDRNEWLEN || length < ARC_HDRNEWLEN) {
if (caplen < ARC_HDRNEWLEN) {
arcnet_print(ndo, p, length, 0, 0, 0);
ND_PRINT((ndo, "[|phds]"));
return (caplen);
ND_PRINT(" phds");
nd_print_trunc(ndo);
ndo->ndo_ll_header_length += caplen;
return;
}
if (ap->arc_flag == 0xff) {
if (caplen < ARC_HDRNEWLEN_EXC || length < ARC_HDRNEWLEN_EXC) {
flag = GET_U_1(ap->arc_flag);
if (flag == 0xff) {
if (caplen < ARC_HDRNEWLEN_EXC) {
arcnet_print(ndo, p, length, 0, 0, 0);
ND_PRINT((ndo, "[|phds extended]"));
return (caplen);
ND_PRINT(" phds extended");
nd_print_trunc(ndo);
ndo->ndo_ll_header_length += caplen;
return;
}
flag = ap->arc_flag2;
seqid = EXTRACT_16BITS(&ap->arc_seqid2);
flag = GET_U_1(ap->arc_flag2);
seqid = GET_BE_U_2(ap->arc_seqid2);
archdrlen = ARC_HDRNEWLEN_EXC;
} else {
flag = ap->arc_flag;
seqid = EXTRACT_16BITS(&ap->arc_seqid);
seqid = GET_BE_U_2(ap->arc_seqid);
archdrlen = ARC_HDRNEWLEN;
}
}
@ -240,13 +254,14 @@ arcnet_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_ch
/*
* This is a middle fragment.
*/
return (archdrlen);
ndo->ndo_ll_header_length += archdrlen;
return;
}
if (!arcnet_encap_print(ndo, arc_type, p, length, caplen))
ND_DEFAULTPRINT(p, caplen);
return (archdrlen);
ndo->ndo_ll_header_length += archdrlen;
}
/*
@ -259,7 +274,7 @@ arcnet_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_ch
* reassembled packets rather than raw frames, and headers have an
* extra "offset" field between the src/dest and packet type.
*/
u_int
void
arcnet_linux_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
{
u_int caplen = h->caplen;
@ -269,20 +284,23 @@ arcnet_linux_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, cons
int archdrlen = 0;
u_char arc_type;
if (caplen < ARC_LINUX_HDRLEN || length < ARC_LINUX_HDRLEN) {
ND_PRINT((ndo, "[|arcnet]"));
return (caplen);
ndo->ndo_protocol = "arcnet_linux_if";
if (caplen < ARC_LINUX_HDRLEN) {
nd_print_trunc(ndo);
ndo->ndo_ll_header_length += caplen;
return;
}
ap = (const struct arc_linux_header *)p;
arc_type = ap->arc_type;
arc_type = GET_U_1(ap->arc_type);
switch (arc_type) {
default:
archdrlen = ARC_LINUX_HDRNEWLEN;
if (caplen < ARC_LINUX_HDRNEWLEN || length < ARC_LINUX_HDRNEWLEN) {
ND_PRINT((ndo, "[|arcnet]"));
return (caplen);
if (caplen < ARC_LINUX_HDRNEWLEN) {
nd_print_trunc(ndo);
ndo->ndo_ll_header_length += caplen;
return;
}
break;
case ARCTYPE_IP_OLD:
@ -305,7 +323,7 @@ arcnet_linux_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, cons
if (!arcnet_encap_print(ndo, arc_type, p, length, caplen))
ND_DEFAULTPRINT(p, caplen);
return (archdrlen);
ndo->ndo_ll_header_length += archdrlen;
}
/*
@ -339,7 +357,7 @@ arcnet_encap_print(netdissect_options *ndo, u_char arctype, const u_char *p,
case ARCTYPE_ATALK: /* XXX was this ever used? */
if (ndo->ndo_vflag)
ND_PRINT((ndo, "et1 "));
ND_PRINT("et1 ");
atalk_print(ndo, p, length);
return (1);
@ -351,10 +369,3 @@ arcnet_encap_print(netdissect_options *ndo, u_char arctype, const u_char *p,
return (0);
}
}
/*
* Local Variables:
* c-style: bsd
* End:
*/

94
print-arista.c Normal file
View File

@ -0,0 +1,94 @@
// Copyright (c) 2018 Arista Networks, Inc. All rights reserved.
/* \summary: EtherType protocol for Arista Networks printer */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "netdissect-stdinc.h"
#include <string.h>
#include "netdissect.h"
#include "extract.h"
#include "addrtoname.h"
#define ARISTA_SUBTYPE_TIMESTAMP 0x01
#define ARISTA_TIMESTAMP_64_TAI 0x0010
#define ARISTA_TIMESTAMP_64_UTC 0x0110
#define ARISTA_TIMESTAMP_48_TAI 0x0020
#define ARISTA_TIMESTAMP_48_UTC 0x0120
static const struct tok ts_version_name[] = {
{ ARISTA_TIMESTAMP_64_TAI, "TAI(64-bit)" },
{ ARISTA_TIMESTAMP_64_UTC, "UTC(64-bit)" },
{ ARISTA_TIMESTAMP_48_TAI, "TAI(48-bit)" },
{ ARISTA_TIMESTAMP_48_UTC, "UTC(48-bit)" },
{ 0, NULL }
};
static inline void
arista_print_date_hms_time(netdissect_options *ndo, uint32_t seconds,
uint32_t nanoseconds)
{
time_t ts;
struct tm *tm;
char buf[BUFSIZE];
ts = seconds + (nanoseconds / 1000000000);
if (NULL == (tm = gmtime(&ts)))
ND_PRINT(": gmtime() error");
else if (0 == strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm))
ND_PRINT(": strftime() error");
else
ND_PRINT(": %s, %09u ns, ", buf, nanoseconds);
}
int
arista_ethertype_print(netdissect_options *ndo, const u_char *bp, u_int len _U_)
{
uint16_t subTypeId;
uint16_t version;
u_short bytesConsumed = 0;
u_short size = 0;
uint32_t seconds, nanoseconds;
ndo->ndo_protocol = "arista";
subTypeId = GET_BE_U_2(bp);
bp += 2;
version = GET_BE_U_2(bp);
bp += 2;
bytesConsumed += 4;
ND_PRINT("SubType: 0x%1x, Version: 0x%04x, ", subTypeId, version);
// TapAgg Header Timestamping
if (subTypeId == ARISTA_SUBTYPE_TIMESTAMP) {
// Timestamp has 32-bit lsb in nanosec and remaining msb in sec
ND_PRINT("Timestamp %s", tok2str(ts_version_name,
"Unknown timestamp Version 0x%04x ", version));
switch (version) {
case ARISTA_TIMESTAMP_64_TAI:
case ARISTA_TIMESTAMP_64_UTC:
seconds = GET_BE_U_4(bp);
nanoseconds = GET_BE_U_4(bp + 4);
arista_print_date_hms_time(ndo, seconds, nanoseconds);
bytesConsumed += size + 8;
break;
case ARISTA_TIMESTAMP_48_TAI:
case ARISTA_TIMESTAMP_48_UTC:
ND_PRINT(": Seconds %u,", GET_BE_U_2(bp));
ND_PRINT(" Nanoseconds %u, ", GET_BE_U_4(bp + 2));
bytesConsumed += size + 6;
break;
default:
return -1;
}
} else {
return -1;
}
return bytesConsumed;
}

View File

@ -22,20 +22,18 @@
/* \summary: Address Resolution Protocol (ARP) printer */
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <config.h>
#endif
#include <netdissect-stdinc.h>
#include "netdissect-stdinc.h"
#include <string.h>
#include "netdissect.h"
#include "addrtoname.h"
#include "ether.h"
#include "ethertype.h"
#include "extract.h"
static const char tstr[] = "[|ARP]";
/*
* Address Resolution Protocol.
@ -48,7 +46,7 @@ static const char tstr[] = "[|ARP]";
* specified. Field names used correspond to RFC 826.
*/
struct arp_pkthdr {
u_short ar_hrd; /* format of hardware address */
nd_uint16_t ar_hrd; /* format of hardware address */
#define ARPHRD_ETHER 1 /* ethernet hardware format */
#define ARPHRD_IEEE802 6 /* token-ring hardware format */
#define ARPHRD_ARCNET 7 /* arcnet hardware format */
@ -56,10 +54,11 @@ struct arp_pkthdr {
#define ARPHRD_ATM2225 19 /* ATM (RFC 2225) */
#define ARPHRD_STRIP 23 /* Ricochet Starmode Radio hardware format */
#define ARPHRD_IEEE1394 24 /* IEEE 1394 (FireWire) hardware format */
u_short ar_pro; /* format of protocol address */
u_char ar_hln; /* length of hardware address */
u_char ar_pln; /* length of protocol address */
u_short ar_op; /* one of: */
#define ARPHRD_INFINIBAND 32 /* InfiniBand RFC 4391 */
nd_uint16_t ar_pro; /* format of protocol address */
nd_uint8_t ar_hln; /* length of hardware address */
nd_uint8_t ar_pln; /* length of protocol address */
nd_uint16_t ar_op; /* one of: */
#define ARPOP_REQUEST 1 /* request to resolve address */
#define ARPOP_REPLY 2 /* response to previous request */
#define ARPOP_REVREQUEST 3 /* request protocol address given hardware */
@ -73,24 +72,24 @@ struct arp_pkthdr {
* according to the sizes above.
*/
#ifdef COMMENT_ONLY
u_char ar_sha[]; /* sender hardware address */
u_char ar_spa[]; /* sender protocol address */
u_char ar_tha[]; /* target hardware address */
u_char ar_tpa[]; /* target protocol address */
nd_byte ar_sha[]; /* sender hardware address */
nd_byte ar_spa[]; /* sender protocol address */
nd_byte ar_tha[]; /* target hardware address */
nd_byte ar_tpa[]; /* target protocol address */
#endif
#define ar_sha(ap) (((const u_char *)((ap)+1))+0)
#define ar_spa(ap) (((const u_char *)((ap)+1))+ (ap)->ar_hln)
#define ar_tha(ap) (((const u_char *)((ap)+1))+ (ap)->ar_hln+(ap)->ar_pln)
#define ar_tpa(ap) (((const u_char *)((ap)+1))+2*(ap)->ar_hln+(ap)->ar_pln)
#define ar_sha(ap) (((const u_char *)((ap)+1))+ 0)
#define ar_spa(ap) (((const u_char *)((ap)+1))+ GET_U_1((ap)->ar_hln))
#define ar_tha(ap) (((const u_char *)((ap)+1))+ GET_U_1((ap)->ar_hln)+GET_U_1((ap)->ar_pln))
#define ar_tpa(ap) (((const u_char *)((ap)+1))+2*GET_U_1((ap)->ar_hln)+GET_U_1((ap)->ar_pln))
};
#define ARP_HDRLEN 8
#define HRD(ap) EXTRACT_16BITS(&(ap)->ar_hrd)
#define HRD_LEN(ap) ((ap)->ar_hln)
#define PROTO_LEN(ap) ((ap)->ar_pln)
#define OP(ap) EXTRACT_16BITS(&(ap)->ar_op)
#define PRO(ap) EXTRACT_16BITS(&(ap)->ar_pro)
#define HRD(ap) GET_BE_U_2((ap)->ar_hrd)
#define HRD_LEN(ap) GET_U_1((ap)->ar_hln)
#define PROTO_LEN(ap) GET_U_1((ap)->ar_pln)
#define OP(ap) GET_BE_U_2((ap)->ar_op)
#define PRO(ap) GET_BE_U_2((ap)->ar_pro)
#define SHA(ap) (ar_sha(ap))
#define SPA(ap) (ar_spa(ap))
#define THA(ap) (ar_tha(ap))
@ -116,6 +115,7 @@ static const struct tok arphrd_values[] = {
{ ARPHRD_STRIP, "Strip" },
{ ARPHRD_IEEE1394, "IEEE 1394" },
{ ARPHRD_ATM2225, "ATM" },
{ ARPHRD_INFINIBAND, "InfiniBand" },
{ 0, NULL }
};
@ -129,39 +129,39 @@ static const struct tok arphrd_values[] = {
* of an ATM number and an ATM subaddress.
*/
struct atmarp_pkthdr {
u_short aar_hrd; /* format of hardware address */
u_short aar_pro; /* format of protocol address */
u_char aar_shtl; /* length of source ATM number */
u_char aar_sstl; /* length of source ATM subaddress */
nd_uint16_t aar_hrd; /* format of hardware address */
nd_uint16_t aar_pro; /* format of protocol address */
nd_uint8_t aar_shtl; /* length of source ATM number */
nd_uint8_t aar_sstl; /* length of source ATM subaddress */
#define ATMARP_IS_E164 0x40 /* bit in type/length for E.164 format */
#define ATMARP_LEN_MASK 0x3F /* length of {sub}address in type/length */
u_short aar_op; /* same as regular ARP */
u_char aar_spln; /* length of source protocol address */
u_char aar_thtl; /* length of target ATM number */
u_char aar_tstl; /* length of target ATM subaddress */
u_char aar_tpln; /* length of target protocol address */
nd_uint16_t aar_op; /* same as regular ARP */
nd_uint8_t aar_spln; /* length of source protocol address */
nd_uint8_t aar_thtl; /* length of target ATM number */
nd_uint8_t aar_tstl; /* length of target ATM subaddress */
nd_uint8_t aar_tpln; /* length of target protocol address */
/*
* The remaining fields are variable in size,
* according to the sizes above.
*/
#ifdef COMMENT_ONLY
u_char aar_sha[]; /* source ATM number */
u_char aar_ssa[]; /* source ATM subaddress */
u_char aar_spa[]; /* sender protocol address */
u_char aar_tha[]; /* target ATM number */
u_char aar_tsa[]; /* target ATM subaddress */
u_char aar_tpa[]; /* target protocol address */
nd_byte aar_sha[]; /* source ATM number */
nd_byte aar_ssa[]; /* source ATM subaddress */
nd_byte aar_spa[]; /* sender protocol address */
nd_byte aar_tha[]; /* target ATM number */
nd_byte aar_tsa[]; /* target ATM subaddress */
nd_byte aar_tpa[]; /* target protocol address */
#endif
#define ATMHRD(ap) EXTRACT_16BITS(&(ap)->aar_hrd)
#define ATMSHRD_LEN(ap) ((ap)->aar_shtl & ATMARP_LEN_MASK)
#define ATMSSLN(ap) ((ap)->aar_sstl & ATMARP_LEN_MASK)
#define ATMSPROTO_LEN(ap) ((ap)->aar_spln)
#define ATMOP(ap) EXTRACT_16BITS(&(ap)->aar_op)
#define ATMPRO(ap) EXTRACT_16BITS(&(ap)->aar_pro)
#define ATMTHRD_LEN(ap) ((ap)->aar_thtl & ATMARP_LEN_MASK)
#define ATMTSLN(ap) ((ap)->aar_tstl & ATMARP_LEN_MASK)
#define ATMTPROTO_LEN(ap) ((ap)->aar_tpln)
#define ATMHRD(ap) GET_BE_U_2((ap)->aar_hrd)
#define ATMSHRD_LEN(ap) (GET_U_1((ap)->aar_shtl) & ATMARP_LEN_MASK)
#define ATMSSLN(ap) (GET_U_1((ap)->aar_sstl) & ATMARP_LEN_MASK)
#define ATMSPROTO_LEN(ap) GET_U_1((ap)->aar_spln)
#define ATMOP(ap) GET_BE_U_2((ap)->aar_op)
#define ATMPRO(ap) GET_BE_U_2((ap)->aar_pro)
#define ATMTHRD_LEN(ap) (GET_U_1((ap)->aar_thtl) & ATMARP_LEN_MASK)
#define ATMTSLN(ap) (GET_U_1((ap)->aar_tstl) & ATMARP_LEN_MASK)
#define ATMTPROTO_LEN(ap) GET_U_1((ap)->aar_tpln)
#define aar_sha(ap) ((const u_char *)((ap)+1))
#define aar_ssa(ap) (aar_sha(ap) + ATMSHRD_LEN(ap))
#define aar_spa(ap) (aar_ssa(ap) + ATMSSLN(ap))
@ -178,10 +178,10 @@ struct atmarp_pkthdr {
#define ATMTPA(ap) (aar_tpa(ap))
static int
isnonzero(const u_char *a, size_t len)
isnonzero(netdissect_options *ndo, const u_char *a, size_t len)
{
while (len > 0) {
if (*a != 0)
if (GET_U_1(a) != 0)
return (1);
a++;
len--;
@ -189,21 +189,69 @@ isnonzero(const u_char *a, size_t len)
return (0);
}
static void
tpaddr_print_ip(netdissect_options *ndo,
const struct arp_pkthdr *ap, u_short pro)
{
if (pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL)
ND_PRINT("<wrong proto type>");
else if (PROTO_LEN(ap) != 4)
ND_PRINT("<wrong len>");
else
ND_PRINT("%s", GET_IPADDR_STRING(TPA(ap)));
}
static void
spaddr_print_ip(netdissect_options *ndo,
const struct arp_pkthdr *ap, u_short pro)
{
if (pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL)
ND_PRINT("<wrong proto type>");
else if (PROTO_LEN(ap) != 4)
ND_PRINT("<wrong len>");
else
ND_PRINT("%s", GET_IPADDR_STRING(SPA(ap)));
}
static void
atmarp_addr_print(netdissect_options *ndo,
const u_char *ha, u_int ha_len, const u_char *srca,
u_int srca_len)
{
if (ha_len == 0)
ND_PRINT((ndo, "<No address>"));
ND_PRINT("<No address>");
else {
ND_PRINT((ndo, "%s", linkaddr_string(ndo, ha, LINKADDR_ATM, ha_len)));
ND_PRINT("%s", GET_LINKADDR_STRING(ha, LINKADDR_ATM, ha_len));
if (srca_len != 0)
ND_PRINT((ndo, ",%s",
linkaddr_string(ndo, srca, LINKADDR_ATM, srca_len)));
ND_PRINT(",%s",
GET_LINKADDR_STRING(srca, LINKADDR_ATM, srca_len));
}
}
static void
atmarp_tpaddr_print(netdissect_options *ndo,
const struct atmarp_pkthdr *ap, u_short pro)
{
if (pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL)
ND_PRINT("<wrong proto type>");
else if (ATMTPROTO_LEN(ap) != 4)
ND_PRINT("<wrong tplen>");
else
ND_PRINT("%s", GET_IPADDR_STRING(ATMTPA(ap)));
}
static void
atmarp_spaddr_print(netdissect_options *ndo,
const struct atmarp_pkthdr *ap, u_short pro)
{
if (pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL)
ND_PRINT("<wrong proto type>");
else if (ATMSPROTO_LEN(ap) != 4)
ND_PRINT("<wrong splen>");
else
ND_PRINT("%s", GET_IPADDR_STRING(ATMSPA(ap)));
}
static void
atmarp_print(netdissect_options *ndo,
const u_char *bp, u_int length, u_int caplen)
@ -212,67 +260,70 @@ atmarp_print(netdissect_options *ndo,
u_short pro, hrd, op;
ap = (const struct atmarp_pkthdr *)bp;
ND_TCHECK(*ap);
ND_TCHECK_SIZE(ap);
hrd = ATMHRD(ap);
pro = ATMPRO(ap);
op = ATMOP(ap);
if (!ND_TTEST2(*aar_tpa(ap), ATMTPROTO_LEN(ap))) {
ND_PRINT((ndo, "%s", tstr));
if (!ND_TTEST_LEN(aar_tpa(ap), ATMTPROTO_LEN(ap))) {
nd_print_trunc(ndo);
ND_DEFAULTPRINT((const u_char *)ap, length);
return;
}
if (!ndo->ndo_eflag) {
ND_PRINT((ndo, "ARP, "));
ND_PRINT("ARP, ");
}
if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) ||
ATMSPROTO_LEN(ap) != 4 ||
ATMTPROTO_LEN(ap) != 4 ||
ndo->ndo_vflag) {
ND_PRINT((ndo, "%s, %s (len %u/%u)",
ND_PRINT("%s, %s (len %u/%u)",
tok2str(arphrd_values, "Unknown Hardware (%u)", hrd),
tok2str(ethertype_values, "Unknown Protocol (0x%04x)", pro),
ATMSPROTO_LEN(ap),
ATMTPROTO_LEN(ap)));
ATMTPROTO_LEN(ap));
/* don't know know about the address formats */
/* don't know about the address formats */
if (!ndo->ndo_vflag) {
goto out;
}
}
/* print operation */
ND_PRINT((ndo, "%s%s ",
ND_PRINT("%s%s ",
ndo->ndo_vflag ? ", " : "",
tok2str(arpop_values, "Unknown (%u)", op)));
tok2str(arpop_values, "Unknown (%u)", op));
switch (op) {
case ARPOP_REQUEST:
ND_PRINT((ndo, "who-has %s", ipaddr_string(ndo, ATMTPA(ap))));
ND_PRINT("who-has ");
atmarp_tpaddr_print(ndo, ap, pro);
if (ATMTHRD_LEN(ap) != 0) {
ND_PRINT((ndo, " ("));
ND_PRINT(" (");
atmarp_addr_print(ndo, ATMTHA(ap), ATMTHRD_LEN(ap),
ATMTSA(ap), ATMTSLN(ap));
ND_PRINT((ndo, ")"));
ND_PRINT(")");
}
ND_PRINT((ndo, "tell %s", ipaddr_string(ndo, ATMSPA(ap))));
ND_PRINT(" tell ");
atmarp_spaddr_print(ndo, ap, pro);
break;
case ARPOP_REPLY:
ND_PRINT((ndo, "%s is-at ", ipaddr_string(ndo, ATMSPA(ap))));
atmarp_spaddr_print(ndo, ap, pro);
ND_PRINT(" is-at ");
atmarp_addr_print(ndo, ATMSHA(ap), ATMSHRD_LEN(ap), ATMSSA(ap),
ATMSSLN(ap));
break;
case ARPOP_INVREQUEST:
ND_PRINT((ndo, "who-is "));
ND_PRINT("who-is ");
atmarp_addr_print(ndo, ATMTHA(ap), ATMTHRD_LEN(ap), ATMTSA(ap),
ATMTSLN(ap));
ND_PRINT((ndo, " tell "));
ND_PRINT(" tell ");
atmarp_addr_print(ndo, ATMSHA(ap), ATMSHRD_LEN(ap), ATMSSA(ap),
ATMSSLN(ap));
break;
@ -280,11 +331,13 @@ atmarp_print(netdissect_options *ndo,
case ARPOP_INVREPLY:
atmarp_addr_print(ndo, ATMSHA(ap), ATMSHRD_LEN(ap), ATMSSA(ap),
ATMSSLN(ap));
ND_PRINT((ndo, "at %s", ipaddr_string(ndo, ATMSPA(ap))));
ND_PRINT("at ");
atmarp_spaddr_print(ndo, ap, pro);
break;
case ARPOP_NAK:
ND_PRINT((ndo, "for %s", ipaddr_string(ndo, ATMSPA(ap))));
ND_PRINT("for ");
atmarp_spaddr_print(ndo, ap, pro);
break;
default:
@ -293,11 +346,11 @@ atmarp_print(netdissect_options *ndo,
}
out:
ND_PRINT((ndo, ", length %u", length));
ND_PRINT(", length %u", length);
return;
trunc:
ND_PRINT((ndo, "%s", tstr));
nd_print_trunc(ndo);
}
void
@ -307,8 +360,9 @@ arp_print(netdissect_options *ndo,
const struct arp_pkthdr *ap;
u_short pro, hrd, op, linkaddr;
ndo->ndo_protocol = "arp";
ap = (const struct arp_pkthdr *)bp;
ND_TCHECK(*ap);
ND_TCHECK_SIZE(ap);
hrd = HRD(ap);
pro = PRO(ap);
@ -318,7 +372,7 @@ arp_print(netdissect_options *ndo,
/* if its ATM then call the ATM ARP printer
for Frame-relay ARP most of the fields
are similar to Ethernet so overload the Ethernet Printer
and set the linkaddr type for linkaddr_string(ndo, ) accordingly */
and set the linkaddr type for GET_LINKADDR_STRING() accordingly */
switch(hrd) {
case ARPHRD_ATM2225:
@ -332,14 +386,14 @@ arp_print(netdissect_options *ndo,
break;
}
if (!ND_TTEST2(*ar_tpa(ap), PROTO_LEN(ap))) {
ND_PRINT((ndo, "%s", tstr));
if (!ND_TTEST_LEN(TPA(ap), PROTO_LEN(ap))) {
nd_print_trunc(ndo);
ND_DEFAULTPRINT((const u_char *)ap, length);
return;
}
if (!ndo->ndo_eflag) {
ND_PRINT((ndo, "ARP, "));
ND_PRINT("ARP, ");
}
/* print hardware type/len and proto type/len */
@ -347,61 +401,63 @@ arp_print(netdissect_options *ndo,
PROTO_LEN(ap) != 4 ||
HRD_LEN(ap) == 0 ||
ndo->ndo_vflag) {
ND_PRINT((ndo, "%s (len %u), %s (len %u)",
ND_PRINT("%s (len %u), %s (len %u)",
tok2str(arphrd_values, "Unknown Hardware (%u)", hrd),
HRD_LEN(ap),
tok2str(ethertype_values, "Unknown Protocol (0x%04x)", pro),
PROTO_LEN(ap)));
PROTO_LEN(ap));
/* don't know know about the address formats */
/* don't know about the address formats */
if (!ndo->ndo_vflag) {
goto out;
}
}
/* print operation */
ND_PRINT((ndo, "%s%s ",
ND_PRINT("%s%s ",
ndo->ndo_vflag ? ", " : "",
tok2str(arpop_values, "Unknown (%u)", op)));
tok2str(arpop_values, "Unknown (%u)", op));
switch (op) {
case ARPOP_REQUEST:
ND_PRINT((ndo, "who-has %s", ipaddr_string(ndo, TPA(ap))));
if (isnonzero((const u_char *)THA(ap), HRD_LEN(ap)))
ND_PRINT((ndo, " (%s)",
linkaddr_string(ndo, THA(ap), linkaddr, HRD_LEN(ap))));
ND_PRINT((ndo, " tell %s", ipaddr_string(ndo, SPA(ap))));
ND_PRINT("who-has ");
tpaddr_print_ip(ndo, ap, pro);
if (isnonzero(ndo, (const u_char *)THA(ap), HRD_LEN(ap)))
ND_PRINT(" (%s)",
GET_LINKADDR_STRING(THA(ap), linkaddr, HRD_LEN(ap)));
ND_PRINT(" tell ");
spaddr_print_ip(ndo, ap, pro);
break;
case ARPOP_REPLY:
ND_PRINT((ndo, "%s is-at %s",
ipaddr_string(ndo, SPA(ap)),
linkaddr_string(ndo, SHA(ap), linkaddr, HRD_LEN(ap))));
spaddr_print_ip(ndo, ap, pro);
ND_PRINT(" is-at %s",
GET_LINKADDR_STRING(SHA(ap), linkaddr, HRD_LEN(ap)));
break;
case ARPOP_REVREQUEST:
ND_PRINT((ndo, "who-is %s tell %s",
linkaddr_string(ndo, THA(ap), linkaddr, HRD_LEN(ap)),
linkaddr_string(ndo, SHA(ap), linkaddr, HRD_LEN(ap))));
ND_PRINT("who-is %s tell %s",
GET_LINKADDR_STRING(THA(ap), linkaddr, HRD_LEN(ap)),
GET_LINKADDR_STRING(SHA(ap), linkaddr, HRD_LEN(ap)));
break;
case ARPOP_REVREPLY:
ND_PRINT((ndo, "%s at %s",
linkaddr_string(ndo, THA(ap), linkaddr, HRD_LEN(ap)),
ipaddr_string(ndo, TPA(ap))));
ND_PRINT("%s at ",
GET_LINKADDR_STRING(THA(ap), linkaddr, HRD_LEN(ap)));
tpaddr_print_ip(ndo, ap, pro);
break;
case ARPOP_INVREQUEST:
ND_PRINT((ndo, "who-is %s tell %s",
linkaddr_string(ndo, THA(ap), linkaddr, HRD_LEN(ap)),
linkaddr_string(ndo, SHA(ap), linkaddr, HRD_LEN(ap))));
ND_PRINT("who-is %s tell %s",
GET_LINKADDR_STRING(THA(ap), linkaddr, HRD_LEN(ap)),
GET_LINKADDR_STRING(SHA(ap), linkaddr, HRD_LEN(ap)));
break;
case ARPOP_INVREPLY:
ND_PRINT((ndo,"%s at %s",
linkaddr_string(ndo, SHA(ap), linkaddr, HRD_LEN(ap)),
ipaddr_string(ndo, SPA(ap))));
ND_PRINT("%s at ",
GET_LINKADDR_STRING(SHA(ap), linkaddr, HRD_LEN(ap)));
spaddr_print_ip(ndo, ap, pro);
break;
default:
@ -410,16 +466,9 @@ arp_print(netdissect_options *ndo,
}
out:
ND_PRINT((ndo, ", length %u", length));
ND_PRINT(", length %u", length);
return;
trunc:
ND_PRINT((ndo, "%s", tstr));
nd_print_trunc(ndo);
}
/*
* Local Variables:
* c-style: bsd
* End:
*/

Some files were not shown because too many files have changed in this diff Show More