diff options
author | fenner <fenner@FreeBSD.org> | 2002-06-21 00:43:23 +0000 |
---|---|---|
committer | fenner <fenner@FreeBSD.org> | 2002-06-21 00:43:23 +0000 |
commit | 91fc581e384bca8ae8831d23b70ab73ab0dc1a21 (patch) | |
tree | 89431945035dbd4a9ce74e63c4a1f65ed4166a1a /contrib/tcpdump | |
parent | f815ae37f4671c581fdc1c6f99a8490a6dfbb4f6 (diff) | |
download | FreeBSD-src-91fc581e384bca8ae8831d23b70ab73ab0dc1a21.zip FreeBSD-src-91fc581e384bca8ae8831d23b70ab73ab0dc1a21.tar.gz |
Import tcpdump 3.7.1, from
http://www.tcpdump.org/release/tcpdump-3.7.1.tar.gz
Diffstat (limited to 'contrib/tcpdump')
116 files changed, 13491 insertions, 5624 deletions
diff --git a/contrib/tcpdump/CHANGES b/contrib/tcpdump/CHANGES index 4616fb3..d293a11 100644 --- a/contrib/tcpdump/CHANGES +++ b/contrib/tcpdump/CHANGES @@ -1,4 +1,62 @@ -$Header: /tcpdump/master/tcpdump/CHANGES,v 1.79 2001/01/10 20:13:58 mcr Exp $ +$Header: /tcpdump/master/tcpdump/CHANGES,v 1.81 2002/01/21 11:03:33 mcr Exp $ + +Monday, January 21, 2002. mcr@sandelman.ottawa.on.ca. Summary for 3.7 release +see http://www.tcpdump.org/cvs-log/2002-01-21.10:16:48.html for commit log. + keyword "ipx" added. + Better OSI/802.2 support on Linux. + IEEE 802.11 support, from clenahan@fortresstech.com, achirica@ttd.net. + LLC SAP support for FDDI/token ring/RFC-1483 style ATM + BXXP protocol was replaced by the BEEP protocol; + improvements to SNAP demux. + Changes to "any" interface documentation. + Documentation on pcap_stats() counters. + Fix a memory leak found by Miklos Szeredi - pcap_ether_aton(). + Added MPLS encapsulation decoding per RFC3032. + DNS dissector handles TKEY, TSIG and IXFR. + adaptive SLIP interface patch from Igor Khristophorov <igor@atdot.org> + SMB printing has much improved bounds checks + OUI 0x0000f8 decoded as encapsulated ethernet for Cisco-custom bridging + Zephyr support, from Nickolai Zeldovich <kolya@MIT.EDU>. + Solaris - devices with digits in them. Stefan Hudson <hudson@mbay.net> + IPX socket 0x85be is for Cisco EIGRP over IPX. + Improvements to fragmented ESP handling. + SCTP support from Armando L. Caro Jr. <acaro@mail.eecis.udel.edu> + Linux ARPHDR_ATM support fixed. + Added a "netbeui" keyword, which selects NetBEUI packets. + IPv6 ND improvements, MobileIP dissector, 2292bis-02 for RA option. + Handle ARPHDR_HDLC from Marcus Felipe Pereira <marcus@task.com.br>. + Handle IPX socket 0x553 -> NetBIOS-over-IPX socket, "nwlink-dgm" + Better Linux libc5 compat. + BIND9 lwres dissector added. + MIPS and SPARC get strict alignment macros (affects print-bgp.c) + Apple LocalTalk LINKTYPE_ reserved. + New time stamp formats documented. + DHCP6 updated to draft-22.txt spec. + ICMP types/codes now accept symbolic names. + Add SIGINFO handler from LBL + encrypted CIPE tunnels in IRIX, from Franz Schaefer <schaefer@mond.at>. + now we are -Wstrict-prototype clean. + NetBSD DLT_PPP_ETHER; adapted from Martin Husemann <martin@netbsd.org>. + PPPoE dissector cleaned up. + Support for LocalTalk hardware, from Uns Lider <unslider@miranda.org>. + In dissector, now the caller prints the IP addresses rather than proto. + cjclark@alum.mit.edu: print the IP proto for non-initial fragments. + LLC frames with a DSAP and LSAP of 0xe0 are IPX frames. + Linux cooked frames with a type value of LINUX_SLL_P_802_3 are IPX. + captures on the "any" device won't be done in promiscuous mode + Token Ring support on DLPI - Onno van der Linden <onno@simplex.nl> + ARCNet support, from NetBSD. + HSRP dissector, from Julian Cowley <julian@lava.net>. + Handle (GRE-encapsulated) PPTP + added -C option to rotate save file every optarg * 1,000,000 bytes. + support for "vrrp" name - NetBSD, by Klaus Klein <kleink@netbsd.org>. + PPTP support, from Motonori Shindo <mshindo@mshindo.net>. + IS-IS over PPP support, from Hannes Gredler <hannes@juniper.net>. + CNFP support for IPv6,format. Harry Raaymakers <harryr@connect.com.au>. + ESP printing updated to RFC2406. + HP-UX can now handle large number of PPAs. + MSDP printer added. + L2TP dissector improvements from Motonori Shindo. Tuesday January 9, 2001. mcr@sandelman.ottawa.on.ca. Summary for 3.6 release Cleaned up documentation. @@ -595,4 +653,4 @@ v2.0 Sun Jan 13 12:20:40 PST 1991 - Initial public release. -@(#) $Header: /tcpdump/master/tcpdump/CHANGES,v 1.79 2001/01/10 20:13:58 mcr Exp $ (LBL) +@(#) $Header: /tcpdump/master/tcpdump/CHANGES,v 1.81 2002/01/21 11:03:33 mcr Exp $ (LBL) diff --git a/contrib/tcpdump/CREDITS b/contrib/tcpdump/CREDITS index e53d689..e766e89 100644 --- a/contrib/tcpdump/CREDITS +++ b/contrib/tcpdump/CREDITS @@ -15,29 +15,55 @@ Additional people who have contributed patches: Alfredo Andres <aandres@s21sec.com> Andrew Tridgell <tridge@linuxcare.com> Arkadiusz Miskiewicz <misiek@pld.org.pl> + Armando L. Caro Jr. <acaro@mail.eecis.udel.edu> + Ben Smithurst <ben@scientia.demon.co.uk> + Brent L. Bates <blbates@vigyan.com> + Charlie Lenahan <clenahan@fortresstech.com> Chris G. Demetriou <cgd@netbsd.org> + Chris Jepeway <jepeway@blasted-heath.com> Craig Rodrigues <rodrigc@mediaone.net> + Crist J. Clark <cjclark@alum.mit.edu> Daniel Hagerty <hag@ai.mit.edu> Francisco Matias Cuenca-Acuna <mcuenca@george.rutgers.edu> Frank Volf <volf@oasis.IAEhv.nl> Gert Doering <gert@greenie.muc.de> Gilbert Ramirez Jr. <gram@xiexie.org> Gisle Vanem <gvanem@eunet.no> - JINMEI Tatuya <jinmei@kame.net> + Hannes Gredler <hannes@juniper.net> + Harry Raaymakers <harryr@connect.com.au> + Heinz-Ado Arnolds <Ado.Arnolds@dhm-systems.de> + Hendrik Scholz <hendrik@scholz.net> + Jakob Schlyter <jakob@openbsd.org> + Jan Oravec <wsx@wsx6.net> + Jason R. Thorpe <thorpej@zembu.com> Jefferson Ogata <jogata@nodc.noaa.gov> Jeffrey Hutzelman <jhutz@cmu.edu> Jim Hutchins <jim@ca.sandia.gov> + JINMEI Tatuya <jinmei@kame.net> Juergen Schoenwaelder <schoenw@ibr.cs.tu-bs.de> + Julian Cowley <julian@lava.net> + Kaarthik Sivakumar <kaarthik@torrentnet.com> + Kazushi Sugyo <sugyo@pb.jp.nec.com> + Kelly Carmichael <kcarmich@ipapp.com> Ken Hornstein <kenh@cmf.nrl.navy.mil> Kevin Steves <stevesk@sweden.hp.com> + Klaus Klein <kleink@reziprozitaet.de> + Kris Kennaway <kris@freebsd.org> Larry Lile <lile@stdio.com> Lennert Buytenhek <buytenh@gnu.org> Love Hörnquist-Åstrand <lha@stacken.kth.se> + Maciej W. Rozycki <macro@ds2.pg.gda.pl> Marko Kiiskila <carnil@cs.tut.fi> + Marshall Rose <mrose@dbc.mtview.ca.us> + Martin Husemann <martin@netbsd.org> + Michael Madore <mmadore@turbolinux.com> Michael Shalayeff <mickey@openbsd.org> Michael T. Stolarchuk <mts@off.to> Monroe Williams <monroe@pobox.com> Motonori Shindo <mshindo@mshindo.net> + Nathan J. Williams <nathanw@MIT.EDU> + Nathaniel Couper-Noles <Nathaniel@isi1.tccisi.com> + Nickolai Zeldovich <kolya@MIT.EDU> Olaf Kirch <okir@caldera.de> Onno van der Linden <onno@simplex.nl> Pascal Hennequin <pascal.hennequin@int-evry.fr> @@ -48,11 +74,11 @@ Additional people who have contributed patches: Rick Jones <raj@cup.hp.com> Roderick Schertler <roderick@argon.org> Sebastian Krahmer <krahmer@cs.uni-potsdam.de> + Seth Webster <swebster@sst.ll.mit.edu> Timo Koskiahde Tony Li <tli@jnx.com> + Uns Lider <unslider@miranda.org> Wilbert de Graaf <wilbertdg@hetnet.nl> - Kris Kennaway <kris@freebsd.org> - Ben Smithurst <ben@scientia.demon.co.uk> The original LBL crew: Steve McCanne diff --git a/contrib/tcpdump/FILES b/contrib/tcpdump/FILES index 987589e..3b4f3d4 100644 --- a/contrib/tcpdump/FILES +++ b/contrib/tcpdump/FILES @@ -12,8 +12,10 @@ addrtoname.c addrtoname.h ah.h appletalk.h +arcnet.h atime.awk bootp.h +bpf_dump.c chdlc.h config.guess config.h.in @@ -30,10 +32,13 @@ extract.h fddi.h gmt2local.c gmt2local.h +icmp6.h +ieee802_11.h igrp.h install-sh interface.h ip.h +ip6.h ipsec_doi.h ipx.h isakmp.h @@ -59,6 +64,7 @@ missing/resolv6.h missing/resolv_ext.h missing/snprintf.c missing/sockstorage.h +missing/strdup.c missing/strlcat.c missing/strlcpy.c mkdep @@ -73,14 +79,16 @@ ospf6.h packetdat.awk parsenfsfh.c ppp.h +print-802_11.c print-ah.c +print-arcnet.c print-arp.c print-ascii.c print-atalk.c print-atm.c print-bgp.c print-bootp.c -print-bxxp.c +print-beep.c print-cdp.c print-chdlc.c print-cip.c @@ -95,6 +103,7 @@ print-ether.c print-fddi.c print-frag6.c print-gre.c +print-hsrp.c print-icmp.c print-icmp6.c print-igmp.c @@ -111,7 +120,10 @@ print-l2tp.c print-lane.c print-lcp.c print-llc.c +print-lwres.c print-mobile.c +print-mpls.c +print-msdp.c print-netbios.c print-nfs.c print-ntp.c @@ -121,12 +133,14 @@ print-ospf6.c print-pim.c print-ppp.c print-pppoe.c +print-pptp.c print-radius.c print-raw.c print-rip.c print-ripng.c print-rt6.c print-rx.c +print-sctp.c print-sl.c print-sll.c print-smb.c @@ -142,15 +156,16 @@ print-udp.c print-vjc.c print-vrrp.c print-wb.c +print-zephyr.c route6d.h rx.h -savestr.c -savestr.h +sctpConstants.h +sctpHeader.h send-ack.awk setsignal.c setsignal.h -slip.h slcompress.h +slip.h sll.h smb.h smbutil.c @@ -159,6 +174,7 @@ strcasecmp.c tcp.h tcpdump.1 tcpdump.c +telnet.h timed.h token.h udp.h diff --git a/contrib/tcpdump/Makefile.in b/contrib/tcpdump/Makefile.in index 486e59f..ec8750e 100644 --- a/contrib/tcpdump/Makefile.in +++ b/contrib/tcpdump/Makefile.in @@ -17,7 +17,7 @@ # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. # -# @(#) $Header: /tcpdump/master/tcpdump/Makefile.in,v 1.244 2000/12/21 10:43:20 guy Exp $ (LBL) +# @(#) $Header: /tcpdump/master/tcpdump/Makefile.in,v 1.260 2001/12/10 08:21:23 guy Exp $ (LBL) # # Various configurable paths (remember to edit Makefile.in, not Makefile) @@ -65,22 +65,25 @@ INSTALL_DATA = @INSTALL_DATA@ @rm -f $@ $(CC) $(CFLAGS) -c $(srcdir)/$*.c -CSRC = tcpdump.c \ - print-arp.c print-atalk.c print-atm.c print-bootp.c \ - print-decnet.c print-domain.c print-dvmrp.c print-egp.c \ - print-ether.c print-fddi.c print-gre.c print-icmp.c print-igmp.c \ - print-igrp.c print-ip.c print-ipx.c print-isoclns.c print-krb.c \ - print-llc.c print-nfs.c print-ntp.c print-null.c print-ospf.c \ - print-pim.c print-ppp.c print-raw.c print-rip.c print-sl.c \ - print-snmp.c print-stp.c print-sunrpc.c print-tcp.c print-tftp.c \ - print-udp.c print-wb.c addrtoname.c gmt2local.c machdep.c \ - parsenfsfh.c util.c savestr.c setsignal.c \ - print-esp.c print-ah.c print-vjc.c print-isakmp.c print-chdlc.c \ - print-ipcomp.c print-mobile.c print-l2tp.c print-bgp.c print-rx.c \ - print-lane.c print-cip.c print-pppoe.c print-lcp.c \ - print-smb.c smbutil.c print-ascii.c print-telnet.c print-cnfp.c \ - print-vrrp.c print-cdp.c print-token.c print-bxxp.c print-timed.c \ - print-radius.c print-sll.c +CSRC = addrtoname.c gmt2local.c machdep.c parsenfsfh.c \ + print-802_11.c print-ah.c print-arcnet.c print-arp.c \ + print-ascii.c print-atalk.c print-atm.c print-bgp.c \ + print-bootp.c print-beep.c print-cdp.c print-chdlc.c \ + print-cip.c print-cnfp.c print-decnet.c print-domain.c \ + print-dvmrp.c print-egp.c print-esp.c print-ether.c \ + print-fddi.c print-gre.c print-hsrp.c print-icmp.c \ + print-igmp.c print-igrp.c print-ip.c print-ipcomp.c \ + print-ipx.c print-isakmp.c print-isoclns.c print-krb.c \ + print-l2tp.c print-lane.c print-lcp.c print-llc.c print-lwres.c \ + print-msdp.c print-mobile.c print-mpls.c print-nfs.c \ + print-ntp.c print-null.c print-ospf.c print-pim.c \ + print-ppp.c print-pppoe.c print-pptp.c print-radius.c \ + print-raw.c print-rip.c print-rx.c print-sctp.c \ + print-sl.c print-sll.c print-snmp.c \ + print-stp.c print-sunrpc.c print-tcp.c \ + print-telnet.c print-tftp.c print-timed.c print-token.c \ + print-udp.c print-vjc.c print-vrrp.c print-wb.c print-zephyr.c \ + setsignal.c tcpdump.c util.c LOCALSRC = @LOCALSRC@ GENSRC = version.c @@ -94,7 +97,7 @@ OBJ = $(CSRC:.c=.o) $(GENSRC:.c=.o) $(LOCALSRC:.c=.o) $(LIBOBJS) HDR = addrtoname.h appletalk.h bootp.h decnet.h \ ethertype.h extract.h fddi.h gmt2local.h igrp.h interface.h \ ipx.h llc.h machdep.h mib.h nfsfh.h nfsv2.h ntp.h ospf.h \ - savestr.c setsignal.h \ + setsignal.h \ gnuc.h ipsec_doi.h isakmp.h l2tp.h nameser.h \ netbios.h oakley.h ospf6.h ppp.h route6d.h diff --git a/contrib/tcpdump/PLATFORMS b/contrib/tcpdump/PLATFORMS index 49291176..2e1aedf 100644 --- a/contrib/tcpdump/PLATFORMS +++ b/contrib/tcpdump/PLATFORMS @@ -1,5 +1,6 @@ == Tested platforms == -NetBSD 1.5/i386 (mcr - 2000/12/8) +NetBSD 1.5/i386 (mcr - 2002/1/1) +Debian Linux (woody/i386) (mcr - 2002/1/1) --- RedHat Linux 6.1/i386 (assar) diff --git a/contrib/tcpdump/README b/contrib/tcpdump/README index 6d52e1f..bd6d184 100644 --- a/contrib/tcpdump/README +++ b/contrib/tcpdump/README @@ -1,6 +1,6 @@ -@(#) $Header: /tcpdump/master/tcpdump/README,v 1.58.2.1 2001/04/11 05:27:42 guy Exp $ (LBL) +@(#) $Header: /tcpdump/master/tcpdump/README,v 1.60 2002/01/21 11:16:33 mcr Exp $ (LBL) -TCPDUMP 3.6.2 +TCPDUMP 3.7.1 Now maintained by "The Tcpdump Group" See www.tcpdump.org @@ -11,8 +11,8 @@ Anonymous CVS is available via: (password "anoncvs") cvs -d cvs.tcpdump.org:/tcpdump/master checkout tcpdump -Version 3.6.2 of TCPDUMP can be retrived with the CVS tag "tcpdump_3_6rel2": - cvs -d cvs.tcpdump.org:/tcpdump/master checkout -r tcpdump_3_6rel2 tcpdump +Version 3.7.1 of TCPDUMP can be retrived with the CVS tag "tcpdump_3_7rel1": + cvs -d cvs.tcpdump.org:/tcpdump/master checkout -r tcpdump_3_7rel1 tcpdump Please send patches against the master copy to patches@tcpdump.org. diff --git a/contrib/tcpdump/VERSION b/contrib/tcpdump/VERSION index 4a788a0..a76ccff 100644 --- a/contrib/tcpdump/VERSION +++ b/contrib/tcpdump/VERSION @@ -1 +1 @@ -3.6.3 +3.7.1 diff --git a/contrib/tcpdump/acconfig.h b/contrib/tcpdump/acconfig.h index 6a03387..213b833 100644 --- a/contrib/tcpdump/acconfig.h +++ b/contrib/tcpdump/acconfig.h @@ -62,6 +62,9 @@ /* define if you have both getipnodebyname() and getipnodebyaddr() */ #undef USE_GETIPNODEBY +/* define if you have ether_ntohost() and it works */ +#undef USE_ETHER_NTOHOST + /* define if unaligned memory accesses fail */ #undef LBL_ALIGN @@ -84,3 +87,14 @@ #undef u_int16_t #undef u_int32_t #undef u_int8_t + +/* Whether or not to include the possibly-buggy SMB printer */ +#undef TCPDUMP_DO_SMB + +/* Long story short: aclocal.m4 depends on autoconf 2.13 + * implementation details wrt "const"; newer versions + * have different implementation details so for now we + * put "const" here. This may cause duplicate definitions + * in config.h but that should be OK since they're the same. + */ +#undef const diff --git a/contrib/tcpdump/aclocal.m4 b/contrib/tcpdump/aclocal.m4 index 06eca60..788fb22 100644 --- a/contrib/tcpdump/aclocal.m4 +++ b/contrib/tcpdump/aclocal.m4 @@ -1,4 +1,4 @@ -dnl @(#) $Header: /tcpdump/master/tcpdump/aclocal.m4,v 1.73 2001/01/02 22:18:27 guy Exp $ (LBL) +dnl @(#) $Header: /tcpdump/master/tcpdump/aclocal.m4,v 1.80 2001/12/10 08:41:15 guy Exp $ (LBL) dnl dnl Copyright (c) 1995, 1996, 1997, 1998 dnl The Regents of the University of California. All rights reserved. @@ -57,7 +57,7 @@ AC_DEFUN(AC_LBL_C_INIT, LBL_CFLAGS="$CFLAGS" fi if test -z "$CC" ; then - case "$target_os" in + case "$host_os" in bsdi*) AC_CHECK_PROG(SHLICC2, shlicc2, yes, no) @@ -100,7 +100,7 @@ AC_DEFUN(AC_LBL_C_INIT, ac_cv_lbl_cc_ansi_prototypes=no)) AC_MSG_RESULT($ac_cv_lbl_cc_ansi_prototypes) if test $ac_cv_lbl_cc_ansi_prototypes = no ; then - case "$target_os" in + case "$host_os" in hpux*) AC_MSG_CHECKING(for HP-UX ansi compiler ($CC -Aa -D_HPUX_SOURCE)) @@ -129,14 +129,14 @@ AC_DEFUN(AC_LBL_C_INIT, $2="$$2 -I/usr/local/include" LDFLAGS="$LDFLAGS -L/usr/local/lib" - case "$target_os" in + case "$host_os" in irix*) - V_CCOPT="$V_CCOPT -xansi -signed -g3" + V_CCOPT="$V_CCOPT -xansi -signed -O" ;; osf*) - V_CCOPT="$V_CCOPT -std1 -g3" + V_CCOPT="$V_CCOPT -std1 -O" ;; ultrix*) @@ -214,17 +214,19 @@ AC_DEFUN(AC_LBL_LIBPCAP, fi else $1=$libpcap + places=`ls $srcdir/.. | sed -e 's,/$,,' -e "s,^,$srcdir/../," | \ + egrep '/libpcap-[[0-9]]*.[[0-9]]*(.[[0-9]]*)?([[ab]][[0-9]]*)?$'` if test -r $d/pcap.h; then $2="-I$d $$2" - elif test -r $srcdir/../libpcap/pcap.h; then - $2="-I$d -I$srcdir/../libpcap $$2" + elif test -r $places/pcap.h; then + $2="-I$places $$2" else AC_MSG_ERROR(cannot find pcap.h, see INSTALL) fi AC_MSG_RESULT($libpcap) fi LIBS="$libpcap $LIBS" - case "$target_os" in + case "$host_os" in aix*) pseexe="/lib/pse.exp" @@ -256,7 +258,7 @@ AC_DEFUN(AC_LBL_TYPE_SIGNAL, else AC_DEFINE(RETSIGVAL,(0)) fi - case "$target_os" in + case "$host_os" in irix*) AC_DEFINE(_BSD_SIGNALS) @@ -489,10 +491,10 @@ dnl AC_DEFUN(AC_LBL_UNALIGNED_ACCESS, [AC_MSG_CHECKING(if unaligned accesses fail) AC_CACHE_VAL(ac_cv_lbl_unaligned_fail, - [case "$target_cpu" in + [case "$host_cpu" in # XXX: should also check that they don't do weird things (like on arm) - alpha*|arm*|hp*|mips|sparc) + alpha*|arm*|hp*|mips*|sparc*|ia64) ac_cv_lbl_unaligned_fail=yes ;; @@ -577,7 +579,7 @@ AC_DEFUN(AC_LBL_DEVEL, fi fi else - case "$target_os" in + case "$host_os" in irix6*) V_CCOPT="$V_CCOPT -n32" @@ -587,7 +589,7 @@ AC_DEFUN(AC_LBL_DEVEL, ;; esac fi - os=`echo $target_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'` + os=`echo $host_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'` name="lbl/os-$os.h" if test -f $name ; then ln -s $name os-proto.h @@ -614,10 +616,11 @@ dnl define(AC_LBL_CHECK_LIB, [AC_MSG_CHECKING([for $2 in -l$1]) -dnl Use a cache variable name containing both the library and function name, -dnl because the test really is for library $1 defining function $2, not -dnl just for library $1. Separate tests with the same $1 and different $2's -dnl may have different results. +dnl Use a cache variable name containing the library, function +dnl name, and extra libraries to link with, because the test really is +dnl for library $1 defining function $2, when linked with potinal +dnl library $5, not just for library $1. Separate tests with the same +dnl $1 and different $2's or $5's may have different results. ac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'` AC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var, [ac_save_LIBS="$LIBS" @@ -693,23 +696,20 @@ dnl AC_DEFUN(AC_LBL_LIBRARY_NET, [ # Most operating systems have gethostbyname() in the default searched # libraries (i.e. libc): - AC_CHECK_FUNC(gethostbyname, , - # Some OSes (eg. Solaris) place it in libnsl: - AC_LBL_CHECK_LIB(nsl, gethostbyname, , - # Some strange OSes (SINIX) have it in libsocket: - AC_LBL_CHECK_LIB(socket, gethostbyname, , - # Unfortunately libsocket sometimes depends on libnsl. - # AC_CHECK_LIB's API is essentially broken so the - # following ugliness is necessary: - AC_LBL_CHECK_LIB(socket, gethostbyname, - LIBS="-lsocket -lnsl $LIBS", - AC_CHECK_LIB(resolv, gethostbyname), - -lnsl)))) - AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, , - AC_LBL_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , - -lnsl))) + # Some OSes (eg. Solaris) place it in libnsl + # Some strange OSes (SINIX) have it in libsocket: + AC_SEARCH_LIBS(gethostbyname, nsl socket resolv) + # Unfortunately libsocket sometimes depends on libnsl and + # AC_SEARCH_LIBS isn't up to the task of handling dependencies like this. + if test "$ac_cv_search_gethostbyname" = "no" + then + AC_CHECK_LIB(socket, gethostbyname, + LIBS="-lsocket -lnsl $LIBS", , -lnsl) + fi + AC_SEARCH_LIBS(socket, socket, , + AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl)) # DLPI needs putmsg under HPUX so test for -lstr while we're at it - AC_CHECK_LIB(str, putmsg) + AC_SEARCH_LIBS(putmsg, str) ]) dnl Copyright (c) 1999 WIDE Project. All rights reserved. diff --git a/contrib/tcpdump/addrtoname.c b/contrib/tcpdump/addrtoname.c index 600b329..69008b9 100644 --- a/contrib/tcpdump/addrtoname.c +++ b/contrib/tcpdump/addrtoname.c @@ -23,7 +23,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/addrtoname.c,v 1.69.2.1 2001/01/17 18:29:58 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/addrtoname.c,v 1.83 2001/09/17 21:57:50 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -58,7 +58,6 @@ struct rtentry; #include "interface.h" #include "addrtoname.h" #include "llc.h" -#include "savestr.h" #include "setsignal.h" /* Forwards */ @@ -72,7 +71,7 @@ static RETSIGTYPE nohostname(int); struct hnamemem { u_int32_t addr; - char *name; + const char *name; struct hnamemem *nxt; }; @@ -97,18 +96,20 @@ struct enamemem { u_short e_addr0; u_short e_addr1; u_short e_addr2; - char *e_name; + const char *e_name; u_char *e_nsap; /* used only for nsaptable[] */ +#define e_bs e_nsap /* for bytestringtable */ struct enamemem *e_nxt; }; struct enamemem enametable[HASHNAMESIZE]; struct enamemem nsaptable[HASHNAMESIZE]; +struct enamemem bytestringtable[HASHNAMESIZE]; struct protoidmem { u_int32_t p_oui; u_short p_proto; - char *p_name; + const char *p_name; struct protoidmem *p_nxt; }; @@ -117,7 +118,7 @@ struct protoidmem protoidtable[HASHNAMESIZE]; /* * A faster replacement for inet_ntoa(). */ -char * +const char * intoa(u_int32_t addr) { register char *cp; @@ -169,18 +170,14 @@ nohostname(int signo) * Return a name for the IP address pointed to by ap. This address * is assumed to be in network byte order. */ -char * +const char * getname(const u_char *ap) { register struct hostent *hp; u_int32_t addr; static struct hnamemem *p; /* static for longjmp() */ -#ifndef LBL_ALIGN - addr = *(const u_int32_t *)ap; -#else memcpy(&addr, ap, sizeof(addr)); -#endif p = &hnametable[addr & (HASHNAMESIZE-1)]; for (; p->nxt; p = p->nxt) { if (p->addr == addr) @@ -210,7 +207,7 @@ getname(const u_char *ap) if (hp) { char *dotp; - p->name = savestr(hp->h_name); + p->name = strdup(hp->h_name); if (Nflag) { /* Remove domain qualifications */ dotp = strchr(p->name, '.'); @@ -221,7 +218,7 @@ getname(const u_char *ap) } } } - p->name = savestr(intoa(addr)); + p->name = strdup(intoa(addr)); return (p->name); } @@ -230,13 +227,13 @@ getname(const u_char *ap) * Return a name for the IP6 address pointed to by ap. This address * is assumed to be in network byte order. */ -char * +const char * getname6(const u_char *ap) { register struct hostent *hp; struct in6_addr addr; static struct h6namemem *p; /* static for longjmp() */ - register char *cp; + register const char *cp; char ntop_buf[INET6_ADDRSTRLEN]; memcpy(&addr, ap, sizeof(addr)); @@ -273,7 +270,7 @@ getname6(const u_char *ap) if (hp) { char *dotp; - p->name = savestr(hp->h_name); + p->name = strdup(hp->h_name); if (Nflag) { /* Remove domain qualifications */ dotp = strchr(p->name, '.'); @@ -284,8 +281,8 @@ getname6(const u_char *ap) } } } - cp = (char *)inet_ntop(AF_INET6, &addr, ntop_buf, sizeof(ntop_buf)); - p->name = savestr(cp); + cp = inet_ntop(AF_INET6, &addr, ntop_buf, sizeof(ntop_buf)); + p->name = strdup(cp); return (p->name); } #endif /* INET6 */ @@ -323,13 +320,58 @@ lookup_emem(const u_char *ep) return tp; } +/* + * Find the hash node that corresponds to the bytestring 'bs' + * with length 'nlen' + */ + +static inline struct enamemem * +lookup_bytestring(register const u_char *bs, const unsigned int nlen) +{ + struct enamemem *tp; + register u_int i, j, k; + + if (nlen >= 6) { + k = (bs[0] << 8) | bs[1]; + j = (bs[2] << 8) | bs[3]; + i = (bs[4] << 8) | bs[5]; + } else if (nlen >= 4) { + k = (bs[0] << 8) | bs[1]; + j = (bs[2] << 8) | bs[3]; + i = 0; + } else + 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) + return tp; + else + tp = tp->e_nxt; + + tp->e_addr0 = i; + tp->e_addr1 = j; + tp->e_addr2 = k; + + tp->e_bs = (u_char *) calloc(1, nlen + 1); + memcpy(tp->e_bs, bs, nlen); + tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp)); + if (tp->e_nxt == NULL) + error("lookup_bytestring: calloc"); + + return tp; +} + /* Find the hash node that corresponds the NSAP 'nsap' */ static inline struct enamemem * lookup_nsap(register const u_char *nsap) { register u_int i, j, k; - int nlen = *nsap; + unsigned int nlen = *nsap; struct enamemem *tp; const u_char *ensap = nsap + nlen - 6; @@ -347,7 +389,7 @@ lookup_nsap(register const u_char *nsap) tp->e_addr1 == j && tp->e_addr2 == k && tp->e_nsap[0] == nlen && - memcmp((char *)&(nsap[1]), + memcmp((const char *)&(nsap[1]), (char *)&(tp->e_nsap[1]), nlen) == 0) return tp; else @@ -358,7 +400,7 @@ lookup_nsap(register const u_char *nsap) tp->e_nsap = (u_char *)malloc(nlen + 1); if (tp->e_nsap == NULL) error("lookup_nsap: malloc"); - memcpy((char *)tp->e_nsap, (char *)nsap, nlen + 1); + memcpy((char *)tp->e_nsap, (const char *)nsap, nlen + 1); tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp)); if (tp->e_nxt == NULL) error("lookup_nsap: calloc"); @@ -394,7 +436,7 @@ lookup_protoid(const u_char *pi) return tp; } -char * +const char * etheraddr_string(register const u_char *ep) { register u_int i, j; @@ -405,11 +447,11 @@ etheraddr_string(register const u_char *ep) tp = lookup_emem(ep); if (tp->e_name) return (tp->e_name); -#ifdef HAVE_ETHER_NTOHOST +#ifdef USE_ETHER_NTOHOST if (!nflag) { char buf[128]; - if (ether_ntohost(buf, (struct ether_addr *)ep) == 0) { - tp->e_name = savestr(buf); + if (ether_ntohost(buf, (const struct ether_addr *)ep) == 0) { + tp->e_name = strdup(buf); return (tp->e_name); } } @@ -425,11 +467,41 @@ etheraddr_string(register const u_char *ep) *cp++ = hex[*ep++ & 0xf]; } *cp = '\0'; - tp->e_name = savestr(buf); + tp->e_name = strdup(buf); return (tp->e_name); } -char * +const char * +linkaddr_string(const u_char *ep, const unsigned int len) +{ + register u_int i, j; + register char *cp; + register struct enamemem *tp; + + if (len == 6) /* XXX not totally correct... */ + return etheraddr_string(ep); + + tp = lookup_bytestring(ep, len); + if (tp->e_name) + return (tp->e_name); + + tp->e_name = cp = (char *)malloc(len*3); + if (tp->e_name == NULL) + error("linkaddr_string: malloc"); + if ((j = *ep >> 4) != 0) + *cp++ = hex[j]; + *cp++ = hex[*ep++ & 0xf]; + for (i = len-1; i > 0 ; --i) { + *cp++ = ':'; + if ((j = *ep >> 4) != 0) + *cp++ = hex[j]; + *cp++ = hex[*ep++ & 0xf]; + } + *cp = '\0'; + return (tp->e_name); +} + +const char * etherproto_string(u_short port) { register char *cp; @@ -451,11 +523,11 @@ etherproto_string(u_short port) *cp++ = hex[port >> 4 & 0xf]; *cp++ = hex[port & 0xf]; *cp++ = '\0'; - tp->name = savestr(buf); + tp->name = strdup(buf); return (tp->name); } -char * +const char * protoid_string(register const u_char *pi) { register u_int i, j; @@ -478,11 +550,11 @@ protoid_string(register const u_char *pi) *cp++ = hex[*pi++ & 0xf]; } *cp = '\0'; - tp->p_name = savestr(buf); + tp->p_name = strdup(buf); return (tp->p_name); } -char * +const char * llcsap_string(u_char sap) { register struct hnamemem *tp; @@ -497,11 +569,11 @@ llcsap_string(u_char sap) tp->nxt = newhnamemem(); snprintf(buf, sizeof(buf), "sap %02x", sap & 0xff); - tp->name = savestr(buf); + tp->name = strdup(buf); return (tp->name); } -char * +const char * isonsap_string(const u_char *nsap) { register u_int i, nlen = nsap[0]; @@ -526,7 +598,7 @@ isonsap_string(const u_char *nsap) return (tp->e_name); } -char * +const char * tcpport_string(u_short port) { register struct hnamemem *tp; @@ -541,11 +613,11 @@ tcpport_string(u_short port) tp->nxt = newhnamemem(); (void)snprintf(buf, sizeof(buf), "%u", i); - tp->name = savestr(buf); + tp->name = strdup(buf); return (tp->name); } -char * +const char * udpport_string(register u_short port) { register struct hnamemem *tp; @@ -560,7 +632,7 @@ udpport_string(register u_short port) tp->nxt = newhnamemem(); (void)snprintf(buf, sizeof(buf), "%u", i); - tp->name = savestr(buf); + tp->name = strdup(buf); return (tp->name); } @@ -586,9 +658,9 @@ init_servarray(void) table = table->nxt; if (nflag) { (void)snprintf(buf, sizeof(buf), "%d", port); - table->name = savestr(buf); + table->name = strdup(buf); } else - table->name = savestr(sv->s_name); + table->name = strdup(sv->s_name); table->addr = port; table->nxt = newhnamemem(); } @@ -618,6 +690,18 @@ init_eprotoarray(void) } } +static struct protoidlist { + const u_char protoid[5]; + const char *name; +} protoidlist[] = { + {{ 0x00, 0x00, 0x0c, 0x01, 0x07 }, "CiscoMLS" }, + {{ 0x00, 0x00, 0x0c, 0x20, 0x00 }, "CiscoCDP" }, + {{ 0x00, 0x00, 0x0c, 0x20, 0x01 }, "CiscoCGMP" }, + {{ 0x00, 0x00, 0x0c, 0x20, 0x03 }, "CiscoVTP" }, + {{ 0x00, 0xe0, 0x2b, 0x00, 0xbb }, "ExtremeEDP" }, + {{ 0x00, 0x00, 0x00, 0x00, 0x00 }, NULL } +}; + /* * SNAP proto IDs with org code 0:0:0 are actually encapsulated Ethernet * types. @@ -627,6 +711,7 @@ init_protoidarray(void) { register int i; register struct protoidmem *tp; + struct protoidlist *pl; u_char protoid[5]; protoid[0] = 0; @@ -637,13 +722,22 @@ init_protoidarray(void) memcpy((char *)&protoid[3], (char *)&etype, 2); tp = lookup_protoid(protoid); - tp->p_name = savestr(eproto_db[i].s); + tp->p_name = strdup(eproto_db[i].s); + } + /* Hardwire some SNAP proto ID names */ + for (pl = protoidlist; pl->name != NULL; ++pl) { + tp = lookup_protoid(pl->protoid); + /* Don't override existing name */ + if (tp->p_name != NULL) + continue; + + tp->p_name = pl->name; } } static struct etherlist { - u_char addr[6]; - char *name; + const u_char addr[6]; + const char *name; } etherlist[] = { {{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, "Broadcast" }, {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, NULL } @@ -668,7 +762,7 @@ init_etherarray(void) { register struct etherlist *el; register struct enamemem *tp; -#ifdef HAVE_ETHER_NTOHOST +#ifdef USE_ETHER_NTOHOST char name[256]; #else register struct pcap_etherent *ep; @@ -679,7 +773,7 @@ init_etherarray(void) if (fp != NULL) { while ((ep = pcap_next_etherent(fp)) != NULL) { tp = lookup_emem(ep->addr); - tp->e_name = savestr(ep->name); + tp->e_name = strdup(ep->name); } (void)fclose(fp); } @@ -692,10 +786,10 @@ init_etherarray(void) if (tp->e_name != NULL) continue; -#ifdef HAVE_ETHER_NTOHOST +#ifdef USE_ETHER_NTOHOST /* Use yp/nis version of name if available */ - if (ether_ntohost(name, (struct ether_addr *)el->addr) == 0) { - tp->e_name = savestr(name); + if (ether_ntohost(name, (const struct ether_addr *)el->addr) == 0) { + tp->e_name = strdup(name); continue; } #endif @@ -713,6 +807,9 @@ static struct tok llcsap_db[] = { { LLCSAP_RS511, "eia-rs511" }, { LLCSAP_ISO8208, "x.25/llc2" }, { LLCSAP_PROWAY, "proway" }, + { LLCSAP_SNAP, "snap" }, + { LLCSAP_IPX, "IPX" }, + { LLCSAP_NETBEUI, "netbeui" }, { LLCSAP_ISONS, "iso-clns" }, { LLCSAP_GLOBAL, "global" }, { 0, NULL } @@ -761,7 +858,7 @@ init_addrtoname(u_int32_t localnet, u_int32_t mask) init_protoidarray(); } -char * +const char * dnaddr_string(u_short dnaddr) { register struct hnamemem *tp; diff --git a/contrib/tcpdump/addrtoname.h b/contrib/tcpdump/addrtoname.h index 72e79b8..67ded6e 100644 --- a/contrib/tcpdump/addrtoname.h +++ b/contrib/tcpdump/addrtoname.h @@ -18,20 +18,21 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: /tcpdump/master/tcpdump/addrtoname.h,v 1.16 1999/10/30 05:11:07 itojun Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/addrtoname.h,v 1.18 2001/09/17 21:57:51 fenner Exp $ (LBL) */ /* Name to address translation routines. */ -extern char *etheraddr_string(const u_char *); -extern char *etherproto_string(u_short); -extern char *tcpport_string(u_short); -extern char *udpport_string(u_short); -extern char *getname(const u_char *); +extern const char *linkaddr_string(const u_char *, const unsigned int); +extern const char *etheraddr_string(const u_char *); +extern const char *etherproto_string(u_short); +extern const char *tcpport_string(u_short); +extern const char *udpport_string(u_short); +extern const char *getname(const u_char *); #ifdef INET6 -extern char *getname6(const u_char *); +extern const char *getname6(const u_char *); #endif -extern char *intoa(u_int32_t); +extern const char *intoa(u_int32_t); extern void init_addrtoname(u_int32_t, u_int32_t); extern struct hnamemem *newhnamemem(void); diff --git a/contrib/tcpdump/arcnet.h b/contrib/tcpdump/arcnet.h new file mode 100644 index 0000000..89867e0 --- /dev/null +++ b/contrib/tcpdump/arcnet.h @@ -0,0 +1,79 @@ +/* + * 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. + * + * @(#) $Id: arcnet.h,v 1.1 2001/04/17 08:39:18 guy Exp $ (LBL) + * + * from: NetBSD: if_arc.h,v 1.13 1999/11/19 20:41:19 thorpej Exp + */ + +/* + * Structure of a 2.5MB/s Arcnet header. + * as given to interface code. + */ +struct arc_header { + u_int8_t arc_shost; + u_int8_t arc_dhost; + u_int8_t arc_type; + /* + * only present for newstyle encoding with LL fragmentation. + * Don't use sizeof(anything), use ARC_HDR{,NEW}LEN instead. + */ + u_int8_t arc_flag; + u_int16_t arc_seqid; + + /* + * only present in exception packets (arc_flag == 0xff) + */ + u_int8_t arc_type2; /* same as arc_type */ + u_int8_t arc_flag2; /* real flag value */ + u_int16_t arc_seqid2; /* real seqid value */ +} __attribute__((__packed__)); + +#define ARC_HDRLEN 3 +#define ARC_HDRNEWLEN 6 +#define ARC_HDRNEWLEN_EXC 10 + +/* RFC 1051 */ +#define ARCTYPE_IP_OLD 240 /* IP protocol */ +#define ARCTYPE_ARP_OLD 241 /* address resolution protocol */ + +/* RFC 1201 */ +#define ARCTYPE_IP 212 /* IP protocol */ +#define ARCTYPE_ARP 213 /* address resolution protocol */ +#define ARCTYPE_REVARP 214 /* reverse addr resolution protocol */ + +#define ARCTYPE_ATALK 221 /* Appletalk */ +#define ARCTYPE_BANIAN 247 /* Banyan Vines */ +#define ARCTYPE_IPX 250 /* Novell IPX */ + +#define ARCTYPE_INET6 0xc4 /* IPng */ +#define ARCTYPE_DIAGNOSE 0x80 /* as per ANSI/ATA 878.1 */ diff --git a/contrib/tcpdump/bootp.h b/contrib/tcpdump/bootp.h index 49899de..152d251 100644 --- a/contrib/tcpdump/bootp.h +++ b/contrib/tcpdump/bootp.h @@ -1,4 +1,4 @@ -/* @(#) $Header: /tcpdump/master/tcpdump/bootp.h,v 1.10 2000/12/03 23:42:23 fenner Exp $ (LBL) */ +/* @(#) $Header: /tcpdump/master/tcpdump/bootp.h,v 1.11 2001/01/09 07:39:13 fenner Exp $ (LBL) */ /* * Bootstrap Protocol (BOOTP). RFC951 and RFC1048. * @@ -148,6 +148,9 @@ struct bootp { #define TAG_NDS_SERVERS ((u_int8_t) 85) #define TAG_NDS_TREE_NAME ((u_int8_t) 86) #define TAG_NDS_CONTEXT ((u_int8_t) 87) +/* RFC 2242 */ +#define TAG_NDS_IPDOMAIN ((u_int8_t) 62) +#define TAG_NDS_IPINFO ((u_int8_t) 63) /* RFC 2485 */ #define TAG_OPEN_GROUP_UAP ((u_int8_t) 98) /* RFC 2563 */ diff --git a/contrib/tcpdump/config.guess b/contrib/tcpdump/config.guess index 980ea5b..ba66165 100755 --- a/contrib/tcpdump/config.guess +++ b/contrib/tcpdump/config.guess @@ -1,9 +1,9 @@ #! /bin/sh # Attempt to guess a canonical system name. -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 # Free Software Foundation, Inc. -timestamp='2000-12-15' +timestamp='2001-04-20' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -33,10 +33,6 @@ timestamp='2000-12-15' # # The plan is that this can be called by configure scripts if you # don't specify an explicit build system type. -# -# Only a few systems have been added to this list; please add others -# (but try to keep the structure clean). -# me=`echo "$0" | sed -e 's,.*/,,'` @@ -93,7 +89,7 @@ fi dummy=dummy-$$ -trap 'rm -f $dummy.c $dummy.o $dummy; exit 1' 1 2 15 +trap 'rm -f $dummy.c $dummy.o $dummy.rel $dummy; exit 1' 1 2 15 # CC_FOR_BUILD -- compiler used by this script. # Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still @@ -107,7 +103,7 @@ case $CC_FOR_BUILD,$HOST_CC,$CC in CC_FOR_BUILD="$c"; break fi done - rm -f $dummy.c $dummy.o + rm -f $dummy.c $dummy.o $dummy.rel if test x"$CC_FOR_BUILD" = x ; then CC_FOR_BUILD=no_compiler_found fi @@ -276,7 +272,7 @@ EOF arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) echo arm-acorn-riscix${UNAME_RELEASE} exit 0;; - SR2?01:HI-UX/MPP:*:*) + SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) echo hppa1.1-hitachi-hiuxmpp exit 0;; Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) @@ -412,10 +408,13 @@ EOF EOF $CC_FOR_BUILD $dummy.c -o $dummy \ && ./$dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \ - && rm $dummy.c $dummy && exit 0 + && rm -f $dummy.c $dummy && exit 0 rm -f $dummy.c $dummy echo mips-mips-riscos${UNAME_RELEASE} exit 0 ;; + Motorola:PowerMAX_OS:*:*) + echo powerpc-motorola-powermax + exit 0 ;; Night_Hawk:Power_UNIX:*:*) echo powerpc-harris-powerunix exit 0 ;; @@ -463,9 +462,17 @@ EOF ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX ' - i?86:AIX:*:*) + i*86:AIX:*:*) echo i386-ibm-aix exit 0 ;; + ia64:AIX:*:*) + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} + exit 0 ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then sed 's/^ //' << EOF >$dummy.c @@ -479,7 +486,7 @@ EOF exit(0); } EOF - $CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm $dummy.c $dummy && exit 0 + $CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm -f $dummy.c $dummy && exit 0 rm -f $dummy.c $dummy echo rs6000-ibm-aix3.2.5 elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then @@ -488,9 +495,9 @@ EOF echo rs6000-ibm-aix3.2 fi exit 0 ;; - *:AIX:*:4) + *:AIX:*:[45]) IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | head -1 | awk '{ print $1 }'` - if /usr/sbin/lsattr -EHl ${IBM_CPU_ID} | grep POWER >/dev/null 2>&1; then + if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then IBM_ARCH=rs6000 else IBM_ARCH=powerpc @@ -498,23 +505,10 @@ EOF if [ -x /usr/bin/oslevel ] ; then IBM_REV=`/usr/bin/oslevel` else - IBM_REV=4.${UNAME_RELEASE} + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi echo ${IBM_ARCH}-ibm-aix${IBM_REV} exit 0 ;; - *:AIX:*:5) - case "`lsattr -El proc0 -a type -F value`" in - PowerPC*) IBM_ARCH=powerpc - IBM_MANUF=ibm ;; - Itanium) IBM_ARCH=ia64 - IBM_MANUF=unknown ;; - POWER*) IBM_ARCH=power - IBM_MANUF=ibm ;; - *) IBM_ARCH=powerpc - IBM_MANUF=ibm ;; - esac - echo ${IBM_ARCH}-${IBM_MANUF}-aix${UNAME_VERSION}.${UNAME_RELEASE} - exit 0 ;; *:AIX:*:*) echo rs6000-ibm-aix exit 0 ;; @@ -599,6 +593,10 @@ EOF esac echo ${HP_ARCH}-hp-hpux${HPUX_REV} exit 0 ;; + ia64:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + echo ia64-hp-hpux${HPUX_REV} + exit 0 ;; 3050*:HI-UX:*:*) sed 's/^ //' << EOF >$dummy.c #include <unistd.h> @@ -625,7 +623,7 @@ EOF exit (0); } EOF - $CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm $dummy.c $dummy && exit 0 + $CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm -f $dummy.c $dummy && exit 0 rm -f $dummy.c $dummy echo unknown-hitachi-hiuxwe2 exit 0 ;; @@ -644,7 +642,7 @@ EOF hp8??:OSF1:*:*) echo hppa1.0-hp-osf exit 0 ;; - i?86:OSF1:*:*) + i*86:OSF1:*:*) if [ -x /usr/sbin/sysversion ] ; then echo ${UNAME_MACHINE}-unknown-osf1mk else @@ -701,18 +699,16 @@ EOF CRAY-2:*:*:*) echo cray2-cray-unicos exit 0 ;; - F300:UNIX_System_V:*:*) + F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) + FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` - echo "f300-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit 0 ;; - F301:UNIX_System_V:*:*) - echo f301-fujitsu-uxpv`echo $UNAME_RELEASE | sed 's/ .*//'` - exit 0 ;; hp300:OpenBSD:*:*) echo m68k-unknown-openbsd${UNAME_RELEASE} exit 0 ;; - i?86:BSD/386:*:* | i?86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) + i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} exit 0 ;; sparc*:BSD/OS:*:*) @@ -757,60 +753,38 @@ EOF i*86:Minix:*:*) echo ${UNAME_MACHINE}-pc-minix exit 0 ;; - *:Linux:*:*) - - # The BFD linker knows what the default object file format is, so - # first see if it will tell us. cd to the root directory to prevent - # problems with other programs or directories called `ld' in the path. - ld_supported_emulations=`cd /; ld --help 2>&1 \ - | sed -ne '/supported emulations:/!d - s/[ ][ ]*/ /g - s/.*supported emulations: *// - s/ .*// - p'` - case "$ld_supported_emulations" in - *ia64) - echo "${UNAME_MACHINE}-unknown-linux" - exit 0 - ;; - i?86linux) - echo "${UNAME_MACHINE}-pc-linux-gnuaout" - exit 0 - ;; - elf_i?86) - TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" - ;; - i?86coff) - echo "${UNAME_MACHINE}-pc-linux-gnucoff" - exit 0 - ;; - sparclinux) - echo "${UNAME_MACHINE}-unknown-linux-gnuaout" - exit 0 - ;; - elf32_sparc) - echo "${UNAME_MACHINE}-unknown-linux-gnu" - exit 0 - ;; - armlinux) - echo "${UNAME_MACHINE}-unknown-linux-gnuaout" - exit 0 - ;; - elf32arm*) - echo "${UNAME_MACHINE}-unknown-linux-gnuoldld" - exit 0 - ;; - armelf_linux*) - echo "${UNAME_MACHINE}-unknown-linux-gnu" - exit 0 - ;; - m68klinux) - echo "${UNAME_MACHINE}-unknown-linux-gnuaout" - exit 0 - ;; - elf32ppc | elf32ppclinux) - # Determine Lib Version - cat >$dummy.c <<EOF + arm*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + ia64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux + exit 0 ;; + m68*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + mips:Linux:*:*) + cat >$dummy.c <<EOF +#ifdef __cplusplus +#include <stdio.h> /* for printf() prototype */ +int main (int argc, char *argv[]) { +#else +int main (argc, argv) int argc; char *argv[]; { +#endif +#ifdef __MIPSEB__ + printf ("%s-unknown-linux-gnu\n", argv[1]); +#endif +#ifdef __MIPSEL__ + printf ("%sel-unknown-linux-gnu\n", argv[1]); +#endif + return 0; +} +EOF + $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy "${UNAME_MACHINE}" && rm -f $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy + ;; + ppc:Linux:*:*) + # Determine Lib Version + cat >$dummy.c <<EOF #include <features.h> #if defined(__GLIBC__) extern char __libc_version[]; @@ -823,143 +797,127 @@ main(argc, argv) #if defined(__GLIBC__) printf("%s %s\n", __libc_version, __libc_release); #else - printf("unkown\n"); + printf("unknown\n"); #endif return 0; } EOF - LIBC="" - $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null + LIBC="" + $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null + if test "$?" = 0 ; then + ./$dummy | grep 1\.99 > /dev/null + if test "$?" = 0 ; then LIBC="libc1" ; fi + fi + rm -f $dummy.c $dummy + echo powerpc-unknown-linux-gnu${LIBC} + exit 0 ;; + alpha:Linux:*:*) + cat <<EOF >$dummy.s + .data + \$Lformat: + .byte 37,100,45,37,120,10,0 # "%d-%x\n" + .text + .globl main + .align 4 + .ent main + main: + .frame \$30,16,\$26,0 + ldgp \$29,0(\$27) + .prologue 1 + .long 0x47e03d80 # implver \$0 + lda \$2,-1 + .long 0x47e20c21 # amask \$2,\$1 + lda \$16,\$Lformat + mov \$0,\$17 + not \$1,\$18 + jsr \$26,printf + ldgp \$29,0(\$26) + mov 0,\$16 + jsr \$26,exit + .end main +EOF + LIBC="" + $CC_FOR_BUILD $dummy.s -o $dummy 2>/dev/null + if test "$?" = 0 ; then + case `./$dummy` in + 0-0) UNAME_MACHINE="alpha" ;; + 1-0) UNAME_MACHINE="alphaev5" ;; + 1-1) UNAME_MACHINE="alphaev56" ;; + 1-101) UNAME_MACHINE="alphapca56" ;; + 2-303) UNAME_MACHINE="alphaev6" ;; + 2-307) UNAME_MACHINE="alphaev67" ;; + esac + objdump --private-headers $dummy | \ + grep ld.so.1 > /dev/null if test "$?" = 0 ; then - ./$dummy | grep 1\.99 > /dev/null - if test "$?" = 0 ; then - LIBC="libc1" - fi + LIBC="libc1" fi - rm -f $dummy.c $dummy - echo powerpc-unknown-linux-gnu${LIBC} + fi + rm -f $dummy.s $dummy + echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} + exit 0 ;; + parisc:Linux:*:* | hppa:Linux:*:*) + # Look for CPU level + case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in + PA7*) echo hppa1.1-unknown-linux-gnu ;; + PA8*) echo hppa2.0-unknown-linux-gnu ;; + *) echo hppa-unknown-linux-gnu ;; + esac + exit 0 ;; + parisc64:Linux:*:* | hppa64:Linux:*:*) + echo hppa64-unknown-linux-gnu + exit 0 ;; + s390:Linux:*:* | s390x:Linux:*:*) + echo ${UNAME_MACHINE}-ibm-linux + exit 0 ;; + sh*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + sparc:Linux:*:* | sparc64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + x86_64:Linux:*:*) + echo x86_64-unknown-linux-gnu + exit 0 ;; + i*86:Linux:*:*) + # The BFD linker knows what the default object file format is, so + # first see if it will tell us. cd to the root directory to prevent + # problems with other programs or directories called `ld' in the path. + ld_supported_emulations=`cd /; ld --help 2>&1 \ + | sed -ne '/supported emulations:/!d + s/[ ][ ]*/ /g + s/.*supported emulations: *// + s/ .*// + p'` + case "$ld_supported_emulations" in + i*86linux) + echo "${UNAME_MACHINE}-pc-linux-gnuaout" exit 0 ;; - shelf_linux) - echo "${UNAME_MACHINE}-unknown-linux-gnu" + elf_i*86) + TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" + ;; + i*86coff) + echo "${UNAME_MACHINE}-pc-linux-gnucoff" exit 0 ;; esac - - if test "${UNAME_MACHINE}" = "alpha" ; then - cat <<EOF >$dummy.s - .data - \$Lformat: - .byte 37,100,45,37,120,10,0 # "%d-%x\n" - - .text - .globl main - .align 4 - .ent main - main: - .frame \$30,16,\$26,0 - ldgp \$29,0(\$27) - .prologue 1 - .long 0x47e03d80 # implver \$0 - lda \$2,-1 - .long 0x47e20c21 # amask \$2,\$1 - lda \$16,\$Lformat - mov \$0,\$17 - not \$1,\$18 - jsr \$26,printf - ldgp \$29,0(\$26) - mov 0,\$16 - jsr \$26,exit - .end main -EOF - LIBC="" - $CC_FOR_BUILD $dummy.s -o $dummy 2>/dev/null - if test "$?" = 0 ; then - case `./$dummy` in - 0-0) - UNAME_MACHINE="alpha" - ;; - 1-0) - UNAME_MACHINE="alphaev5" - ;; - 1-1) - UNAME_MACHINE="alphaev56" - ;; - 1-101) - UNAME_MACHINE="alphapca56" - ;; - 2-303) - UNAME_MACHINE="alphaev6" - ;; - 2-307) - UNAME_MACHINE="alphaev67" - ;; - esac - - objdump --private-headers $dummy | \ - grep ld.so.1 > /dev/null - if test "$?" = 0 ; then - LIBC="libc1" - fi - fi - rm -f $dummy.s $dummy - echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} ; exit 0 - elif test "${UNAME_MACHINE}" = "mips" ; then - cat >$dummy.c <<EOF -#ifdef __cplusplus -#include <stdio.h> /* for printf() prototype */ - int main (int argc, char *argv[]) { -#else - int main (argc, argv) int argc; char *argv[]; { -#endif -#ifdef __MIPSEB__ - printf ("%s-unknown-linux-gnu\n", argv[1]); -#endif -#ifdef __MIPSEL__ - printf ("%sel-unknown-linux-gnu\n", argv[1]); -#endif - return 0; -} -EOF - $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy "${UNAME_MACHINE}" && rm $dummy.c $dummy && exit 0 - rm -f $dummy.c $dummy - elif test "${UNAME_MACHINE}" = "s390"; then - echo s390-ibm-linux && exit 0 - elif test "${UNAME_MACHINE}" = "x86_64"; then - echo x86_64-unknown-linux-gnu && exit 0 - elif test "${UNAME_MACHINE}" = "parisc" -o "${UNAME_MACHINE}" = "hppa"; then - # Look for CPU level - case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in - PA7*) - echo hppa1.1-unknown-linux-gnu - ;; - PA8*) - echo hppa2.0-unknown-linux-gnu - ;; - *) - echo hppa-unknown-linux-gnu - ;; - esac - exit 0 - else - # Either a pre-BFD a.out linker (linux-gnuoldld) - # or one that does not give us useful --help. - # GCC wants to distinguish between linux-gnuoldld and linux-gnuaout. - # If ld does not provide *any* "supported emulations:" - # that means it is gnuoldld. - test -z "$ld_supported_emulations" \ - && echo "${UNAME_MACHINE}-pc-linux-gnuoldld" && exit 0 - - case "${UNAME_MACHINE}" in - i?86) - VENDOR=pc; - ;; - *) - VENDOR=unknown; - ;; - esac - # Determine whether the default compiler is a.out or elf - cat >$dummy.c <<EOF + # Either a pre-BFD a.out linker (linux-gnuoldld) + # or one that does not give us useful --help. + # GCC wants to distinguish between linux-gnuoldld and linux-gnuaout. + # If ld does not provide *any* "supported emulations:" + # that means it is gnuoldld. + test -z "$ld_supported_emulations" && echo "${UNAME_MACHINE}-pc-linux-gnuoldld" && exit 0 + case "${UNAME_MACHINE}" in + i*86) + VENDOR=pc; + ;; + *) + VENDOR=unknown; + ;; + esac + # Determine whether the default compiler is a.out or elf + cat >$dummy.c <<EOF #include <features.h> #ifdef __cplusplus #include <stdio.h> /* for printf() prototype */ @@ -983,16 +941,16 @@ EOF return 0; } EOF - $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy "${UNAME_MACHINE}" && rm $dummy.c $dummy && exit 0 - rm -f $dummy.c $dummy - test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0 - fi ;; + $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy "${UNAME_MACHINE}" && rm -f $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy + test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0 + ;; # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. earlier versions # are messed up and put the nodename in both sysname and nodename. - i?86:DYNIX/ptx:4*:*) + i*86:DYNIX/ptx:4*:*) echo i386-sequent-sysv4 exit 0 ;; - i?86:UNIX_SV:4.2MP:2.*) + i*86:UNIX_SV:4.2MP:2.*) # Unixware is an offshoot of SVR4, but it has its own version # number series starting with 2... # I am not positive that other SVR4 systems won't match this, @@ -1000,7 +958,7 @@ EOF # Use sysv4.2uw... so that sysv4* matches it. echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} exit 0 ;; - i?86:*:4.*:* | i?86:SYSTEM_V:4.*:*) + i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} @@ -1008,7 +966,7 @@ EOF echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} fi exit 0 ;; - i?86:*:5:7*) + i*86:*:5:7*) # Fixed at (any) Pentium or better UNAME_MACHINE=i586 if [ ${UNAME_SYSTEM} = "UnixWare" ] ; then @@ -1017,7 +975,7 @@ EOF echo ${UNAME_MACHINE}-pc-sysv${UNAME_RELEASE} fi exit 0 ;; - i?86:*:3.2:*) + i*86:*:3.2:*) if test -f /usr/options/cb.name; then UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name` echo ${UNAME_MACHINE}-pc-isc$UNAME_REL @@ -1035,7 +993,7 @@ EOF echo ${UNAME_MACHINE}-pc-sysv32 fi exit 0 ;; - i?86:*DOS:*:*) + i*86:*DOS:*:*) echo ${UNAME_MACHINE}-pc-msdosdjgpp exit 0 ;; pc:*:*:*) @@ -1074,21 +1032,24 @@ EOF 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && echo i486-ncr-sysv4 && exit 0 ;; - m68*:LynxOS:2.*:*) + m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) echo m68k-unknown-lynxos${UNAME_RELEASE} exit 0 ;; mc68030:UNIX_System_V:4.*:*) echo m68k-atari-sysv4 exit 0 ;; - i?86:LynxOS:2.*:* | i?86:LynxOS:3.[01]*:*) + i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) echo i386-unknown-lynxos${UNAME_RELEASE} exit 0 ;; TSUNAMI:LynxOS:2.*:*) echo sparc-unknown-lynxos${UNAME_RELEASE} exit 0 ;; - rs6000:LynxOS:2.*:* | PowerPC:LynxOS:2.*:*) + rs6000:LynxOS:2.*:*) echo rs6000-unknown-lynxos${UNAME_RELEASE} exit 0 ;; + PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) + echo powerpc-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; SM[BE]S:UNIX_SV:*:*) echo mips-dde-sysv${UNAME_RELEASE} exit 0 ;; @@ -1188,11 +1149,29 @@ EOF fi echo ${UNAME_MACHINE}-unknown-plan9 exit 0 ;; - i?86:OS/2:*:*) + i*86:OS/2:*:*) # If we were able to find `uname', then EMX Unix compatibility # is probably installed. echo ${UNAME_MACHINE}-pc-os2-emx exit 0 ;; + *:TOPS-10:*:*) + echo pdp10-unknown-tops10 + exit 0 ;; + *:TENEX:*:*) + echo pdp10-unknown-tenex + exit 0 ;; + KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) + echo pdp10-dec-tops20 + exit 0 ;; + XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) + echo pdp10-xkl-tops20 + exit 0 ;; + *:TOPS-20:*:*) + echo pdp10-unknown-tops20 + exit 0 ;; + *:ITS:*:*) + echo pdp10-unknown-its + exit 0 ;; esac #echo '(No uname command or uname output not recognized.)' 1>&2 @@ -1284,11 +1263,24 @@ main () #endif #if defined (vax) -#if !defined (ultrix) - printf ("vax-dec-bsd\n"); exit (0); -#else - printf ("vax-dec-ultrix\n"); exit (0); -#endif +# if !defined (ultrix) +# include <sys/param.h> +# if defined (BSD) +# if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +# else +# if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# endif +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# else + printf ("vax-dec-ultrix\n"); exit (0); +# endif #endif #if defined (alliant) && defined (i860) @@ -1299,7 +1291,7 @@ main () } EOF -$CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy && rm $dummy.c $dummy && exit 0 +$CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy && rm -f $dummy.c $dummy && exit 0 rm -f $dummy.c $dummy # Apollos put the system type in the environment. @@ -1335,8 +1327,9 @@ fi cat >&2 <<EOF $0: unable to guess system type -The $version version of this script cannot recognize your system type. -Please download the most up to date version of the config scripts: +This script, last modified $timestamp, has failed to recognize +the operating system you are using. It is advised that you +download the most up to date version of the config scripts from ftp://ftp.gnu.org/pub/gnu/config/ @@ -1345,7 +1338,7 @@ send the following data and any information you think might be pertinent to <config-patches@gnu.org> in order to provide the needed information to handle your system. -config.guess version = $version +config.guess timestamp = $timestamp uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` diff --git a/contrib/tcpdump/config.h.in b/contrib/tcpdump/config.h.in index 3692681..87eced8 100644 --- a/contrib/tcpdump/config.h.in +++ b/contrib/tcpdump/config.h.in @@ -14,10 +14,6 @@ /* Define if you can safely include both <sys/time.h> and <time.h>. */ #undef TIME_WITH_SYS_TIME -/* Define if your processor stores words with the most significant - byte first (like Motorola and SPARC, unlike Intel and VAX). */ -#undef WORDS_BIGENDIAN - /* Define if you have SSLeay 0.9.0b with the buggy cast128. */ #undef HAVE_BUGGY_CAST128 @@ -60,8 +56,8 @@ /* define if you have struct sockaddr_storage */ #undef HAVE_SOCKADDR_STORAGE -/* define if you have both getipnodebyname() and getipnodebyaddr() */ -#undef USE_GETIPNODEBY +/* define if you have ether_ntohost() and it works */ +#undef USE_ETHER_NTOHOST /* define if unaligned memory accesses fail */ #undef LBL_ALIGN @@ -86,6 +82,17 @@ #undef u_int32_t #undef u_int8_t +/* Whether or not to include the possibly-buggy SMB printer */ +#undef TCPDUMP_DO_SMB + +/* Long story short: aclocal.m4 depends on autoconf 2.13 + * implementation details wrt "const"; newer versions + * have different implementation details so for now we + * put "const" here. This may cause duplicate definitions + * in config.h but that should be OK since they're the same. + */ +#undef const + /* The number of bytes in a char. */ #undef SIZEOF_CHAR @@ -104,18 +111,9 @@ /* Define if you have the ether_ntohost function. */ #undef HAVE_ETHER_NTOHOST -/* Define if you have the freeaddrinfo function. */ -#undef HAVE_FREEADDRINFO - /* Define if you have the getaddrinfo function. */ #undef HAVE_GETADDRINFO -/* Define if you have the getipnodebyaddr function. */ -#undef HAVE_GETIPNODEBYADDR - -/* Define if you have the getipnodebyname function. */ -#undef HAVE_GETIPNODEBYNAME - /* Define if you have the getnameinfo function. */ #undef HAVE_GETNAMEINFO @@ -146,6 +144,9 @@ /* Define if you have the strcasecmp function. */ #undef HAVE_STRCASECMP +/* Define if you have the strdup function. */ +#undef HAVE_STRDUP + /* Define if you have the strlcat function. */ #undef HAVE_STRLCAT @@ -182,24 +183,12 @@ /* Define if you have the dnet library (-ldnet). */ #undef HAVE_LIBDNET -/* Define if you have the nsl library (-lnsl). */ -#undef HAVE_LIBNSL - -/* Define if you have the resolv library (-lresolv). */ -#undef HAVE_LIBRESOLV - /* Define if you have the rpc library (-lrpc). */ #undef HAVE_LIBRPC /* Define if you have the smi library (-lsmi). */ #undef HAVE_LIBSMI -/* Define if you have the socket library (-lsocket). */ -#undef HAVE_LIBSOCKET - -/* Define if you have the str library (-lstr). */ -#undef HAVE_LIBSTR - /* define if your compiler has __attribute__ */ #undef HAVE___ATTRIBUTE__ diff --git a/contrib/tcpdump/config.sub b/contrib/tcpdump/config.sub index 4849dfd..a06a480 100755 --- a/contrib/tcpdump/config.sub +++ b/contrib/tcpdump/config.sub @@ -1,9 +1,9 @@ #! /bin/sh # Configuration validation subroutine script. -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 # Free Software Foundation, Inc. -timestamp='2000-12-15' +timestamp='2001-04-20' # This file is (in principle) common to ALL GNU software. # The presence of a machine in this file suggests that SOME GNU software @@ -69,7 +69,7 @@ Report bugs and patches to <config-patches@gnu.org>." version="\ GNU config.sub ($timestamp) -Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 99, 2000 +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO @@ -117,7 +117,7 @@ esac # Here we must recognize all the valid KERNEL-OS combinations. maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` case $maybe_os in - nto-qnx* | linux-gnu* | storm-chaos*) + nto-qnx* | linux-gnu* | storm-chaos* | os2-emx*) os=-$maybe_os basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` ;; @@ -226,12 +226,15 @@ case $basic_machine in | alphaev6[78] \ | we32k | ns16k | clipper | i370 | sh | sh[34] \ | powerpc | powerpcle \ - | 1750a | dsp16xx | pdp11 | mips16 | mips64 | mipsel | mips64el \ + | 1750a | dsp16xx | pdp10 | pdp11 \ + | mips16 | mips64 | mipsel | mips64el \ | mips64orion | mips64orionel | mipstx39 | mipstx39el \ | mips64vr4300 | mips64vr4300el | mips64vr4100 | mips64vr4100el \ - | mips64vr5000 | miprs64vr5000el | mcore \ - | sparc | sparclet | sparclite | sparc64 | sparcv9 | v850 | c4x \ - | thumb | d10v | d30v | fr30 | avr) + | mips64vr5000 | miprs64vr5000el | mcore | s390 | s390x \ + | sparc | sparclet | sparclite | sparc64 | sparcv9 | sparcv9b \ + | v850 | c4x \ + | thumb | d10v | d30v | fr30 | avr | openrisc | tic80 \ + | pj | pjl | h8500) basic_machine=$basic_machine-unknown ;; m6811 | m68hc11 | m6812 | m68hc12) @@ -239,13 +242,13 @@ case $basic_machine in basic_machine=$basic_machine-unknown os=-none ;; - m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | z8k | v70 | h8500 | w65 | pj | pjl) + m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | z8k | v70 | w65) ;; # We use `pc' rather than `unknown' # because (1) that's what they normally are, and # (2) the word "unknown" tends to confuse beginning users. - i[234567]86 | x86_64) + i*86 | x86_64) basic_machine=$basic_machine-pc ;; # Object if more than one company name word. @@ -255,7 +258,7 @@ case $basic_machine in ;; # Recognize the basic CPU types with company name. # FIXME: clean up the formatting here. - vax-* | tahoe-* | i[234567]86-* | i860-* | ia64-* | m32r-* | m68k-* | m68000-* \ + vax-* | tahoe-* | i*86-* | i860-* | ia64-* | m32r-* | m68k-* | m68000-* \ | m88k-* | sparc-* | ns32k-* | fx80-* | arc-* | c[123]* \ | arm-* | armbe-* | armle-* | armv*-* | strongarm-* | xscale-* \ | mips-* | pyramid-* | tron-* | a29k-* | romp-* | rs6000-* \ @@ -268,15 +271,17 @@ case $basic_machine in | alphaev6[78]-* \ | we32k-* | cydra-* | ns16k-* | pn-* | np1-* | xps100-* \ | clipper-* | orion-* \ - | sparclite-* | pdp11-* | sh-* | powerpc-* | powerpcle-* \ - | sparc64-* | sparcv9-* | sparc86x-* | mips16-* | mips64-* | mipsel-* \ + | sparclite-* | pdp10-* | pdp11-* | sh-* | powerpc-* | powerpcle-* \ + | sparc64-* | sparcv9-* | sparcv9b-* | sparc86x-* \ + | mips16-* | mips64-* | mipsel-* \ | mips64el-* | mips64orion-* | mips64orionel-* \ | mips64vr4100-* | mips64vr4100el-* | mips64vr4300-* | mips64vr4300el-* \ | mipstx39-* | mipstx39el-* | mcore-* \ - | f30[01]-* | s390-* | sv1-* | t3e-* \ + | f30[01]-* | f700-* | s390-* | s390x-* | sv1-* | t3e-* \ + | [cjt]90-* \ | m88110-* | m680[01234]0-* | m683?2-* | m68360-* | z8k-* | d10v-* \ - | thumb-* | v850-* | d30v-* | tic30-* | c30-* | fr30-* \ - | bs2000-* | tic54x-* | c54x-* | x86_64-*) + | thumb-* | v850-* | d30v-* | tic30-* | tic80-* | c30-* | fr30-* \ + | bs2000-* | tic54x-* | c54x-* | x86_64-* | pj-* | pjl-*) ;; # Recognize the various machine names and aliases which stand # for a CPU type and a company and sometimes even an OS. @@ -367,8 +372,8 @@ case $basic_machine in basic_machine=cray2-cray os=-unicos ;; - [ctj]90-cray) - basic_machine=c90-cray + [cjt]90) + basic_machine=${basic_machine}-cray os=-unicos ;; crds | unos) @@ -424,6 +429,10 @@ case $basic_machine in basic_machine=tron-gmicro os=-sysv ;; + go32) + basic_machine=i386-pc + os=-go32 + ;; h3050r* | hiux*) basic_machine=hppa1.1-hitachi os=-hiuxwe2 @@ -499,19 +508,19 @@ case $basic_machine in basic_machine=i370-ibm ;; # I'm not sure what "Sysv32" means. Should this be sysv3.2? - i[34567]86v32) + i*86v32) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv32 ;; - i[34567]86v4*) + i*86v4*) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv4 ;; - i[34567]86v) + i*86v) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv ;; - i[34567]86sol2) + i*86sol2) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-solaris2 ;; @@ -523,18 +532,6 @@ case $basic_machine in basic_machine=i386-unknown os=-vsta ;; - i386-go32 | go32) - basic_machine=i386-unknown - os=-go32 - ;; - i386-mingw32 | mingw32) - basic_machine=i386-unknown - os=-mingw32 - ;; - i[34567]86-pw32 | pw32) - basic_machine=i586-unknown - os=-pw32 - ;; iris | iris4d) basic_machine=mips-sgi case $os in @@ -560,6 +557,10 @@ case $basic_machine in basic_machine=ns32k-utek os=-sysv ;; + mingw32) + basic_machine=i386-pc + os=-mingw32 + ;; miniframe) basic_machine=m68000-convergent ;; @@ -590,7 +591,7 @@ case $basic_machine in os=-coff ;; msdos) - basic_machine=i386-unknown + basic_machine=i386-pc os=-msdos ;; mvs) @@ -729,6 +730,10 @@ case $basic_machine in ps2) basic_machine=i386-ibm ;; + pw32) + basic_machine=i586-unknown + os=-pw32 + ;; rom68k) basic_machine=m68k-rom68k os=-coff @@ -919,6 +924,10 @@ case $basic_machine in vax) basic_machine=vax-dec ;; + pdp10) + # there are many clones, so DEC is not a safe bet + basic_machine=pdp10-unknown + ;; pdp11) basic_machine=pdp11-dec ;; @@ -928,7 +937,7 @@ case $basic_machine in sh3 | sh4) basic_machine=sh-unknown ;; - sparc | sparcv9) + sparc | sparcv9 | sparcv9b) basic_machine=sparc-sun ;; cydra) @@ -950,6 +959,9 @@ case $basic_machine in basic_machine=c4x-none os=-coff ;; + *-unknown) + # Make sure to match an already-canonicalized machine name. + ;; *) echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 exit 1 @@ -1009,12 +1021,13 @@ case $os in | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \ | -interix* | -uwin* | -rhapsody* | -darwin* | -opened* \ - | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* | -storm-chaos*) + | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ + | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* | -os2*) # Remember, each alternative MUST END IN *, to match a version number. ;; -qnx*) case $basic_machine in - x86-* | i[34567]86-*) + x86-* | i*86-*) ;; *) os=-nto$os @@ -1107,7 +1120,7 @@ case $os in -xenix) os=-xenix ;; - -*mint | -*MiNT) + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) os=-mint ;; -none) @@ -1141,6 +1154,9 @@ case $basic_machine in arm*-semi) os=-aout ;; + pdp10-*) + os=-tops20 + ;; pdp11-*) os=-none ;; @@ -1249,7 +1265,7 @@ case $basic_machine in *-masscomp) os=-rtu ;; - f30[01]-fujitsu) + f30[01]-fujitsu | f700-fujitsu) os=-uxpv ;; *-rom68k) @@ -1327,7 +1343,7 @@ case $basic_machine in -mpw* | -macos*) vendor=apple ;; - -*mint | -*MiNT) + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) vendor=atari ;; esac diff --git a/contrib/tcpdump/configure b/contrib/tcpdump/configure index bb8eb99..5c4e84f 100755 --- a/contrib/tcpdump/configure +++ b/contrib/tcpdump/configure @@ -1,6 +1,6 @@ #! /bin/sh -# From configure.in Revision: 1.132.4.1 +# From configure.in Revision: 1.145 @@ -76,6 +76,9 @@ ac_default_prefix=/usr/local ac_help="$ac_help --without-gcc don't use gcc" ac_help="$ac_help + --enable-smb enable possibly-buggy SMB printer [default=yes] + --disable-smb disable possibly-buggy SMB printer" +ac_help="$ac_help --enable-ipv6 enable ipv6 (with ipv4) support --disable-ipv6 disable ipv6 support" ac_help="$ac_help @@ -611,34 +614,13 @@ ac_config_sub=$ac_aux_dir/config.sub ac_configure=$ac_aux_dir/configure # This should be Cygnus configure. -# Do some error checking and defaulting for the host and target type. -# The inputs are: -# configure --host=HOST --target=TARGET --build=BUILD NONOPT -# -# The rules are: -# 1. You are not allowed to specify --host, --target, and nonopt at the -# same time. -# 2. Host defaults to nonopt. -# 3. If nonopt is not specified, then host defaults to the current host, -# as determined by config.guess. -# 4. Target and build default to nonopt. -# 5. If nonopt is not specified, then target and build default to host. - -# The aliases save the names the user supplied, while $host etc. -# will get canonicalized. -case $host---$target---$nonopt in -NONE---*---* | *---NONE---* | *---*---NONE) ;; -*) { echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; } ;; -esac - - # Make sure we can run config.sub. if ${CONFIG_SHELL-/bin/sh} $ac_config_sub sun4 >/dev/null 2>&1; then : else { echo "configure: error: can not run $ac_config_sub" 1>&2; exit 1; } fi echo $ac_n "checking host system type""... $ac_c" 1>&6 -echo "configure:642: checking host system type" >&5 +echo "configure:624: checking host system type" >&5 host_alias=$host case "$host_alias" in @@ -658,47 +640,6 @@ host_vendor=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` host_os=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` echo "$ac_t""$host" 1>&6 -echo $ac_n "checking target system type""... $ac_c" 1>&6 -echo "configure:663: checking target system type" >&5 - -target_alias=$target -case "$target_alias" in -NONE) - case $nonopt in - NONE) target_alias=$host_alias ;; - *) target_alias=$nonopt ;; - esac ;; -esac - -target=`${CONFIG_SHELL-/bin/sh} $ac_config_sub $target_alias` -target_cpu=`echo $target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'` -target_vendor=`echo $target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` -target_os=`echo $target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` -echo "$ac_t""$target" 1>&6 - -echo $ac_n "checking build system type""... $ac_c" 1>&6 -echo "configure:681: checking build system type" >&5 - -build_alias=$build -case "$build_alias" in -NONE) - case $nonopt in - NONE) build_alias=$host_alias ;; - *) build_alias=$nonopt ;; - esac ;; -esac - -build=`${CONFIG_SHELL-/bin/sh} $ac_config_sub $build_alias` -build_cpu=`echo $build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'` -build_vendor=`echo $build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` -build_os=`echo $build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` -echo "$ac_t""$build" 1>&6 - -test "$host_alias" != "$target_alias" && - test "$program_prefix$program_suffix$program_transform_name" = \ - NONENONEs,x,x, && - program_prefix=${target_alias}- - @@ -719,13 +660,13 @@ fi LBL_CFLAGS="$CFLAGS" fi if test -z "$CC" ; then - case "$target_os" in + case "$host_os" in bsdi*) # Extract the first word of "shlicc2", so it can be a program name with args. set dummy shlicc2; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:729: checking for $ac_word" >&5 +echo "configure:670: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_SHLICC2'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -766,7 +707,7 @@ fi # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:770: checking for $ac_word" >&5 +echo "configure:711: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -796,7 +737,7 @@ if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:800: checking for $ac_word" >&5 +echo "configure:741: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -847,7 +788,7 @@ fi # Extract the first word of "cl", so it can be a program name with args. set dummy cl; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:851: checking for $ac_word" >&5 +echo "configure:792: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -879,7 +820,7 @@ fi fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:883: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 +echo "configure:824: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. @@ -890,12 +831,12 @@ cross_compiling=$ac_cv_prog_cc_cross cat > conftest.$ac_ext << EOF -#line 894 "configure" +#line 835 "configure" #include "confdefs.h" main(){return(0);} EOF -if { (eval echo configure:899: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:840: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then ac_cv_prog_cc_works=yes # If we can't run a trivial program, we are probably using a cross compiler. if (./conftest; exit) 2>/dev/null; then @@ -921,12 +862,12 @@ if test $ac_cv_prog_cc_works = no; then { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:925: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 +echo "configure:866: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 cross_compiling=$ac_cv_prog_cc_cross echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 -echo "configure:930: checking whether we are using GNU C" >&5 +echo "configure:871: checking whether we are using GNU C" >&5 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -935,7 +876,7 @@ else yes; #endif EOF -if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:939: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then +if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:880: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then ac_cv_prog_gcc=yes else ac_cv_prog_gcc=no @@ -954,7 +895,7 @@ ac_test_CFLAGS="${CFLAGS+set}" ac_save_CFLAGS="$CFLAGS" CFLAGS= echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 -echo "configure:958: checking whether ${CC-cc} accepts -g" >&5 +echo "configure:899: checking whether ${CC-cc} accepts -g" >&5 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -991,7 +932,7 @@ fi V_CCOPT="-O2" else echo $ac_n "checking gcc version""... $ac_c" 1>&6 -echo "configure:995: checking gcc version" >&5 +echo "configure:936: checking gcc version" >&5 if eval "test \"`echo '$''{'ac_cv_lbl_gcc_vers'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1009,19 +950,19 @@ fi fi else echo $ac_n "checking that $CC handles ansi prototypes""... $ac_c" 1>&6 -echo "configure:1013: checking that $CC handles ansi prototypes" >&5 +echo "configure:954: checking that $CC handles ansi prototypes" >&5 if eval "test \"`echo '$''{'ac_cv_lbl_cc_ansi_prototypes'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1018 "configure" +#line 959 "configure" #include "confdefs.h" #include <sys/types.h> int main() { int frob(int, char *) ; return 0; } EOF -if { (eval echo configure:1025: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:966: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_lbl_cc_ansi_prototypes=yes else @@ -1035,25 +976,25 @@ fi echo "$ac_t""$ac_cv_lbl_cc_ansi_prototypes" 1>&6 if test $ac_cv_lbl_cc_ansi_prototypes = no ; then - case "$target_os" in + case "$host_os" in hpux*) echo $ac_n "checking for HP-UX ansi compiler ($CC -Aa -D_HPUX_SOURCE)""... $ac_c" 1>&6 -echo "configure:1043: checking for HP-UX ansi compiler ($CC -Aa -D_HPUX_SOURCE)" >&5 +echo "configure:984: checking for HP-UX ansi compiler ($CC -Aa -D_HPUX_SOURCE)" >&5 savedcflags="$CFLAGS" CFLAGS="-Aa -D_HPUX_SOURCE $CFLAGS" if eval "test \"`echo '$''{'ac_cv_lbl_cc_hpux_cc_aa'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1050 "configure" +#line 991 "configure" #include "confdefs.h" #include <sys/types.h> int main() { int frob(int, char *) ; return 0; } EOF -if { (eval echo configure:1057: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:998: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_lbl_cc_hpux_cc_aa=yes else @@ -1085,24 +1026,24 @@ EOF V_INCLS="$V_INCLS -I/usr/local/include" LDFLAGS="$LDFLAGS -L/usr/local/lib" - case "$target_os" in + case "$host_os" in irix*) - V_CCOPT="$V_CCOPT -xansi -signed -g3" + V_CCOPT="$V_CCOPT -xansi -signed -O" ;; osf*) - V_CCOPT="$V_CCOPT -std1 -g3" + V_CCOPT="$V_CCOPT -std1 -O" ;; ultrix*) echo $ac_n "checking that Ultrix $CC hacks const in prototypes""... $ac_c" 1>&6 -echo "configure:1101: checking that Ultrix $CC hacks const in prototypes" >&5 +echo "configure:1042: checking that Ultrix $CC hacks const in prototypes" >&5 if eval "test \"`echo '$''{'ac_cv_lbl_cc_const_proto'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1106 "configure" +#line 1047 "configure" #include "confdefs.h" #include <sys/types.h> int main() { @@ -1110,7 +1051,7 @@ struct a { int b; }; void c(const struct a *) ; return 0; } EOF -if { (eval echo configure:1114: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1055: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_lbl_cc_const_proto=yes else @@ -1134,21 +1075,21 @@ EOF fi echo $ac_n "checking for inline""... $ac_c" 1>&6 -echo "configure:1138: checking for inline" >&5 +echo "configure:1079: checking for inline" >&5 if eval "test \"`echo '$''{'ac_cv_c_inline'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_cv_c_inline=no for ac_kw in inline __inline__ __inline; do cat > conftest.$ac_ext <<EOF -#line 1145 "configure" +#line 1086 "configure" #include "confdefs.h" int main() { } $ac_kw foo() { ; return 0; } EOF -if { (eval echo configure:1152: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1093: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_inline=$ac_kw; break else @@ -1175,13 +1116,13 @@ esac echo $ac_n "checking for __attribute__""... $ac_c" 1>&6 -echo "configure:1179: checking for __attribute__" >&5 +echo "configure:1120: checking for __attribute__" >&5 if eval "test \"`echo '$''{'ac_cv___attribute__'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1185 "configure" +#line 1126 "configure" #include "confdefs.h" #include <stdlib.h> @@ -1198,7 +1139,7 @@ foo(void) ; return 0; } EOF -if { (eval echo configure:1202: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1143: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv___attribute__=yes else @@ -1220,7 +1161,7 @@ echo "$ac_t""$ac_cv___attribute__" 1>&6 echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 -echo "configure:1224: checking how to run the C preprocessor" >&5 +echo "configure:1165: checking how to run the C preprocessor" >&5 # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= @@ -1235,13 +1176,13 @@ else # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. cat > conftest.$ac_ext <<EOF -#line 1239 "configure" +#line 1180 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1245: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1186: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1252,13 +1193,13 @@ else rm -rf conftest* CPP="${CC-cc} -E -traditional-cpp" cat > conftest.$ac_ext <<EOF -#line 1256 "configure" +#line 1197 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1262: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1203: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1269,13 +1210,13 @@ else rm -rf conftest* CPP="${CC-cc} -nologo -E" cat > conftest.$ac_ext <<EOF -#line 1273 "configure" +#line 1214 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1279: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1220: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1303,17 +1244,17 @@ for ac_hdr in fcntl.h rpc/rpcent.h netinet/if_ether.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1307: checking for $ac_hdr" >&5 +echo "configure:1248: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1312 "configure" +#line 1253 "configure" #include "confdefs.h" #include <$ac_hdr> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1317: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1258: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -1340,12 +1281,12 @@ fi done echo $ac_n "checking whether time.h and sys/time.h may both be included""... $ac_c" 1>&6 -echo "configure:1344: checking whether time.h and sys/time.h may both be included" >&5 +echo "configure:1285: checking whether time.h and sys/time.h may both be included" >&5 if eval "test \"`echo '$''{'ac_cv_header_time'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1349 "configure" +#line 1290 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/time.h> @@ -1354,7 +1295,7 @@ int main() { struct tm *tp; ; return 0; } EOF -if { (eval echo configure:1358: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1299: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_header_time=yes else @@ -1375,11 +1316,11 @@ EOF fi -case "$target_os" in +case "$host_os" in linux*) echo $ac_n "checking Linux kernel version""... $ac_c" 1>&6 -echo "configure:1383: checking Linux kernel version" >&5 +echo "configure:1324: checking Linux kernel version" >&5 if test "$cross_compiling" = yes; then if eval "test \"`echo '$''{'ac_cv_linux_vers'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1414,17 +1355,17 @@ for ac_hdr in smi.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1418: checking for $ac_hdr" >&5 +echo "configure:1359: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1423 "configure" +#line 1364 "configure" #include "confdefs.h" #include <$ac_hdr> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1428: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1369: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -1451,7 +1392,7 @@ fi done echo $ac_n "checking for smiInit in -lsmi""... $ac_c" 1>&6 -echo "configure:1455: checking for smiInit in -lsmi" >&5 +echo "configure:1396: checking for smiInit in -lsmi" >&5 ac_lib_var=`echo smi'_'smiInit | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1459,7 +1400,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lsmi $LIBS" cat > conftest.$ac_ext <<EOF -#line 1463 "configure" +#line 1404 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -1470,7 +1411,7 @@ int main() { smiInit() ; return 0; } EOF -if { (eval echo configure:1474: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1415: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1497,15 +1438,17 @@ else echo "$ac_t""no" 1>&6 fi +if test "$ac_cv_header_smi_h" = yes -a "$ac_cv_lib_smi_smiInit" = yes +then echo $ac_n "checking whether to enable libsmi""... $ac_c" 1>&6 -echo "configure:1502: checking whether to enable libsmi" >&5 +echo "configure:1445: checking whether to enable libsmi" >&5 if test "$cross_compiling" = yes; then echo "$ac_t""not when cross-compiling" 1>&6 libsmi=no else cat > conftest.$ac_ext <<EOF -#line 1509 "configure" +#line 1452 "configure" #include "confdefs.h" /* libsmi available check */ #include <smi.h> @@ -1526,7 +1469,7 @@ main() } EOF -if { (eval echo configure:1530: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1473: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then echo "$ac_t""yes" 1>&6 cat >> confdefs.h <<\EOF @@ -1538,17 +1481,46 @@ else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -fr conftest* - echo "$ac_t""no" 1>&6 + case $? in + 1) echo "$ac_t""no - smiInit failed" 1>&6 ;; + 2) echo "$ac_t""no - header/library version mismatch" 1>&6 ;; + 3) echo "$ac_t""no - can't determine library version" 1>&6 ;; + 4) echo "$ac_t""no - too old" 1>&6 ;; + *) echo "$ac_t""no" 1>&6 ;; + esac libsmi=no fi rm -fr conftest* fi +fi +echo $ac_n "checking whether to enable the possibly-buggy SMB printer""... $ac_c" 1>&6 +echo "configure:1500: checking whether to enable the possibly-buggy SMB printer" >&5 +# Check whether --enable-smb or --disable-smb was given. +if test "${enable_smb+set}" = set; then + enableval="$enable_smb" + : +else + enableval=yes +fi + +case "$enableval" in +yes) echo "$ac_t""yes" 1>&6 + echo "configure: warning: The SMB printer may have exploitable buffer overflows!!!" 1>&2 + cat >> confdefs.h <<\EOF +#define TCPDUMP_DO_SMB 1 +EOF + + LOCALSRC="print-smb.c smbutil.c $LOCALSRC" + ;; +*) echo "$ac_t""no" 1>&6 + ;; +esac CFLAGS="$CFLAGS -Dss_family=__ss_family -Dss_len=__ss_len" echo $ac_n "checking whether to enable ipv6""... $ac_c" 1>&6 -echo "configure:1552: checking whether to enable ipv6" >&5 +echo "configure:1524: checking whether to enable ipv6" >&5 # Check whether --enable-ipv6 or --disable-ipv6 was given. if test "${enable_ipv6+set}" = set; then enableval="$enable_ipv6" @@ -1573,7 +1545,7 @@ else else cat > conftest.$ac_ext <<EOF -#line 1577 "configure" +#line 1549 "configure" #include "confdefs.h" /* AF_INET6 available check */ #include <sys/types.h> @@ -1587,7 +1559,7 @@ main() } EOF -if { (eval echo configure:1591: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1563: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then echo "$ac_t""yes" 1>&6 LOCALSRC="print-ip6.c print-ip6opts.c print-ripng.c print-icmp6.c print-frag6.c print-rt6.c print-ospf6.c print-dhcp6.c $LOCALSRC" @@ -1615,12 +1587,12 @@ ipv6trylibc=no if test "$ipv6" = "yes"; then echo $ac_n "checking ipv6 stack type""... $ac_c" 1>&6 -echo "configure:1619: checking ipv6 stack type" >&5 +echo "configure:1591: checking ipv6 stack type" >&5 for i in inria kame linux-glibc linux-libinet6 toshiba v6d zeta; do case $i in inria) cat > conftest.$ac_ext <<EOF -#line 1624 "configure" +#line 1596 "configure" #include "confdefs.h" dnl #include <netinet/in.h> @@ -1639,7 +1611,7 @@ rm -f conftest* ;; kame) cat > conftest.$ac_ext <<EOF -#line 1643 "configure" +#line 1615 "configure" #include "confdefs.h" dnl #include <netinet/in.h> @@ -1661,7 +1633,7 @@ rm -f conftest* ;; linux-glibc) cat > conftest.$ac_ext <<EOF -#line 1665 "configure" +#line 1637 "configure" #include "confdefs.h" dnl #include <features.h> @@ -1689,7 +1661,7 @@ rm -f conftest* ;; toshiba) cat > conftest.$ac_ext <<EOF -#line 1693 "configure" +#line 1665 "configure" #include "confdefs.h" dnl #include <sys/param.h> @@ -1710,7 +1682,7 @@ rm -f conftest* ;; v6d) cat > conftest.$ac_ext <<EOF -#line 1714 "configure" +#line 1686 "configure" #include "confdefs.h" dnl #include </usr/local/v6/include/sys/v6config.h> @@ -1731,7 +1703,7 @@ rm -f conftest* ;; zeta) cat > conftest.$ac_ext <<EOF -#line 1735 "configure" +#line 1707 "configure" #include "confdefs.h" dnl #include <sys/param.h> @@ -1778,14 +1750,14 @@ fi if test "$ipv6" = "yes"; then echo $ac_n "checking for library containing getaddrinfo""... $ac_c" 1>&6 -echo "configure:1782: checking for library containing getaddrinfo" >&5 +echo "configure:1754: checking for library containing getaddrinfo" >&5 if eval "test \"`echo '$''{'ac_cv_search_getaddrinfo'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_func_search_save_LIBS="$LIBS" ac_cv_search_getaddrinfo="no" cat > conftest.$ac_ext <<EOF -#line 1789 "configure" +#line 1761 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -1796,7 +1768,7 @@ int main() { getaddrinfo() ; return 0; } EOF -if { (eval echo configure:1800: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1772: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* ac_cv_search_getaddrinfo="none required" else @@ -1807,7 +1779,7 @@ rm -f conftest* test "$ac_cv_search_getaddrinfo" = "no" && for i in socket; do LIBS="-l$i $ac_func_search_save_LIBS" cat > conftest.$ac_ext <<EOF -#line 1811 "configure" +#line 1783 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -1818,7 +1790,7 @@ int main() { getaddrinfo() ; return 0; } EOF -if { (eval echo configure:1822: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1794: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* ac_cv_search_getaddrinfo="-l$i" break @@ -1835,13 +1807,13 @@ echo "$ac_t""$ac_cv_search_getaddrinfo" 1>&6 if test "$ac_cv_search_getaddrinfo" != "no"; then test "$ac_cv_search_getaddrinfo" = "none required" || LIBS="$ac_cv_search_getaddrinfo $LIBS" echo $ac_n "checking getaddrinfo bug""... $ac_c" 1>&6 -echo "configure:1839: checking getaddrinfo bug" >&5 +echo "configure:1811: checking getaddrinfo bug" >&5 if test "$cross_compiling" = yes; then echo "$ac_t""buggy" 1>&6 buggygetaddrinfo=yes else cat > conftest.$ac_ext <<EOF -#line 1845 "configure" +#line 1817 "configure" #include "confdefs.h" #include <sys/types.h> @@ -1938,7 +1910,7 @@ main() } EOF -if { (eval echo configure:1942: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1914: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then echo "$ac_t""good" 1>&6 buggygetaddrinfo=no @@ -1970,12 +1942,12 @@ fi for ac_func in getaddrinfo getnameinfo do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1974: checking for $ac_func" >&5 +echo "configure:1946: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1979 "configure" +#line 1951 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -1998,7 +1970,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:2002: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1974: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -2026,9 +1998,9 @@ done fi echo $ac_n "checking for inet_ntop""... $ac_c" 1>&6 -echo "configure:2030: checking for inet_ntop" >&5 +echo "configure:2002: checking for inet_ntop" >&5 cat > conftest.$ac_ext <<EOF -#line 2032 "configure" +#line 2004 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/socket.h> @@ -2039,7 +2011,7 @@ char src[4], dst[128]; inet_ntop(AF_INET, src, dst, sizeof(dst)); ; return 0; } EOF -if { (eval echo configure:2043: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2015: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo "$ac_t""yes" 1>&6 else @@ -2050,12 +2022,12 @@ else for ac_func in inet_ntop do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:2054: checking for $ac_func" >&5 +echo "configure:2026: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2059 "configure" +#line 2031 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -2078,7 +2050,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:2082: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2054: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -2107,9 +2079,9 @@ done fi rm -f conftest* echo $ac_n "checking for inet_pton""... $ac_c" 1>&6 -echo "configure:2111: checking for inet_pton" >&5 +echo "configure:2083: checking for inet_pton" >&5 cat > conftest.$ac_ext <<EOF -#line 2113 "configure" +#line 2085 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/socket.h> @@ -2120,7 +2092,7 @@ char src[128], dst[4]; inet_pton(AF_INET, src, dst); ; return 0; } EOF -if { (eval echo configure:2124: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2096: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo "$ac_t""yes" 1>&6 else @@ -2131,12 +2103,12 @@ else for ac_func in inet_pton do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:2135: checking for $ac_func" >&5 +echo "configure:2107: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2140 "configure" +#line 2112 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -2159,7 +2131,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:2163: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2135: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -2188,9 +2160,9 @@ done fi rm -f conftest* echo $ac_n "checking for inet_aton""... $ac_c" 1>&6 -echo "configure:2192: checking for inet_aton" >&5 +echo "configure:2164: checking for inet_aton" >&5 cat > conftest.$ac_ext <<EOF -#line 2194 "configure" +#line 2166 "configure" #include "confdefs.h" #include <sys/types.h> #include <netinet/in.h> @@ -2201,7 +2173,7 @@ struct in_addr dst; inet_aton(src, &dst); ; return 0; } EOF -if { (eval echo configure:2205: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2177: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo "$ac_t""yes" 1>&6 else @@ -2212,12 +2184,12 @@ else for ac_func in inet_aton do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:2216: checking for $ac_func" >&5 +echo "configure:2188: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2221 "configure" +#line 2193 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -2240,7 +2212,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:2244: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2216: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -2271,12 +2243,12 @@ rm -f conftest* echo $ac_n "checking if sockaddr struct has sa_len member""... $ac_c" 1>&6 -echo "configure:2275: checking if sockaddr struct has sa_len member" >&5 +echo "configure:2247: checking if sockaddr struct has sa_len member" >&5 if eval "test \"`echo '$''{'ac_cv_sockaddr_has_sa_len'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2280 "configure" +#line 2252 "configure" #include "confdefs.h" # include <sys/types.h> @@ -2285,7 +2257,7 @@ int main() { u_int i = sizeof(((struct sockaddr *)0)->sa_len) ; return 0; } EOF -if { (eval echo configure:2289: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2261: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_sockaddr_has_sa_len=yes else @@ -2310,7 +2282,7 @@ if test "$ac_cv_sockaddr_has_sa_len" = no; then fi echo $ac_n "checking size of char""... $ac_c" 1>&6 -echo "configure:2314: checking size of char" >&5 +echo "configure:2286: checking size of char" >&5 if eval "test \"`echo '$''{'ac_cv_sizeof_char'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -2318,7 +2290,7 @@ else ac_cv_sizeof_char=1 else cat > conftest.$ac_ext <<EOF -#line 2322 "configure" +#line 2294 "configure" #include "confdefs.h" #include <stdio.h> main() @@ -2329,7 +2301,7 @@ main() exit(0); } EOF -if { (eval echo configure:2333: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:2305: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_char=`cat conftestval` else @@ -2349,7 +2321,7 @@ EOF echo $ac_n "checking size of short""... $ac_c" 1>&6 -echo "configure:2353: checking size of short" >&5 +echo "configure:2325: checking size of short" >&5 if eval "test \"`echo '$''{'ac_cv_sizeof_short'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -2357,7 +2329,7 @@ else ac_cv_sizeof_short=2 else cat > conftest.$ac_ext <<EOF -#line 2361 "configure" +#line 2333 "configure" #include "confdefs.h" #include <stdio.h> main() @@ -2368,7 +2340,7 @@ main() exit(0); } EOF -if { (eval echo configure:2372: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:2344: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_short=`cat conftestval` else @@ -2388,7 +2360,7 @@ EOF echo $ac_n "checking size of int""... $ac_c" 1>&6 -echo "configure:2392: checking size of int" >&5 +echo "configure:2364: checking size of int" >&5 if eval "test \"`echo '$''{'ac_cv_sizeof_int'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -2396,7 +2368,7 @@ else ac_cv_sizeof_int=4 else cat > conftest.$ac_ext <<EOF -#line 2400 "configure" +#line 2372 "configure" #include "confdefs.h" #include <stdio.h> main() @@ -2407,7 +2379,7 @@ main() exit(0); } EOF -if { (eval echo configure:2411: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:2383: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_int=`cat conftestval` else @@ -2427,7 +2399,7 @@ EOF echo $ac_n "checking size of long""... $ac_c" 1>&6 -echo "configure:2431: checking size of long" >&5 +echo "configure:2403: checking size of long" >&5 if eval "test \"`echo '$''{'ac_cv_sizeof_long'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -2435,7 +2407,7 @@ else ac_cv_sizeof_long=4 else cat > conftest.$ac_ext <<EOF -#line 2439 "configure" +#line 2411 "configure" #include "confdefs.h" #include <stdio.h> main() @@ -2446,7 +2418,7 @@ main() exit(0); } EOF -if { (eval echo configure:2450: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:2422: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_long=`cat conftestval` else @@ -2469,12 +2441,12 @@ EOF echo $ac_n "checking for addrinfo""... $ac_c" 1>&6 -echo "configure:2473: checking for addrinfo" >&5 +echo "configure:2445: checking for addrinfo" >&5 if eval "test \"`echo '$''{'ac_cv_addrinfo'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2478 "configure" +#line 2450 "configure" #include "confdefs.h" # include <netdb.h> @@ -2482,7 +2454,7 @@ int main() { struct addrinfo a ; return 0; } EOF -if { (eval echo configure:2486: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2458: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_addrinfo=yes else @@ -2513,12 +2485,12 @@ fi echo $ac_n "checking for NI_MAXSERV""... $ac_c" 1>&6 -echo "configure:2517: checking for NI_MAXSERV" >&5 +echo "configure:2489: checking for NI_MAXSERV" >&5 if eval "test \"`echo '$''{'ac_cv_maxserv'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2522 "configure" +#line 2494 "configure" #include "confdefs.h" #include <netdb.h> #ifdef NI_MAXSERV @@ -2551,12 +2523,12 @@ fi echo $ac_n "checking for NI_NAMEREQD""... $ac_c" 1>&6 -echo "configure:2555: checking for NI_NAMEREQD" >&5 +echo "configure:2527: checking for NI_NAMEREQD" >&5 if eval "test \"`echo '$''{'ac_cv_namereqd'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2560 "configure" +#line 2532 "configure" #include "confdefs.h" #include <netdb.h> #ifdef NI_NOFQDN @@ -2589,12 +2561,12 @@ fi echo $ac_n "checking for sockaddr_storage""... $ac_c" 1>&6 -echo "configure:2593: checking for sockaddr_storage" >&5 +echo "configure:2565: checking for sockaddr_storage" >&5 if eval "test \"`echo '$''{'ac_cv_sa_storage'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2598 "configure" +#line 2570 "configure" #include "confdefs.h" # include <sys/types.h> @@ -2603,7 +2575,7 @@ int main() { struct sockaddr_storage s ; return 0; } EOF -if { (eval echo configure:2607: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2579: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_sa_storage=yes else @@ -2630,12 +2602,12 @@ fi ac_cv_addrsz=yes echo $ac_n "checking for INADDRSZ""... $ac_c" 1>&6 -echo "configure:2634: checking for INADDRSZ" >&5 +echo "configure:2606: checking for INADDRSZ" >&5 if eval "test \"`echo '$''{'ac_cv_inaddrsz'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2639 "configure" +#line 2611 "configure" #include "confdefs.h" # include <arpa/nameser.h> @@ -2643,7 +2615,7 @@ int main() { int a = INADDRSZ ; return 0; } EOF -if { (eval echo configure:2647: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2619: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_inaddrsz=yes else @@ -2665,12 +2637,12 @@ EOF ac_cv_addrsz=no fi echo $ac_n "checking for IN6ADDRSZ""... $ac_c" 1>&6 -echo "configure:2669: checking for IN6ADDRSZ" >&5 +echo "configure:2641: checking for IN6ADDRSZ" >&5 if eval "test \"`echo '$''{'ac_cv_in6addrsz'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2674 "configure" +#line 2646 "configure" #include "confdefs.h" # include <arpa/nameser.h> @@ -2678,7 +2650,7 @@ int main() { int a = IN6ADDRSZ ; return 0; } EOF -if { (eval echo configure:2682: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2654: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_in6addrsz=yes else @@ -2706,12 +2678,12 @@ fi echo $ac_n "checking for RES_USE_INET6""... $ac_c" 1>&6 -echo "configure:2710: checking for RES_USE_INET6" >&5 +echo "configure:2682: checking for RES_USE_INET6" >&5 if eval "test \"`echo '$''{'ac_cv_res_inet6'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2715 "configure" +#line 2687 "configure" #include "confdefs.h" # include <sys/types.h> @@ -2721,7 +2693,7 @@ int main() { int a = RES_USE_INET6 ; return 0; } EOF -if { (eval echo configure:2725: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2697: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_res_inet6=yes else @@ -2747,12 +2719,12 @@ fi echo $ac_n "checking for res_state_ext""... $ac_c" 1>&6 -echo "configure:2751: checking for res_state_ext" >&5 +echo "configure:2723: checking for res_state_ext" >&5 if eval "test \"`echo '$''{'ac_cv_res_state_ext'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2756 "configure" +#line 2728 "configure" #include "confdefs.h" # include <sys/types.h> @@ -2763,7 +2735,7 @@ int main() { struct __res_state_ext e ; return 0; } EOF -if { (eval echo configure:2767: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2739: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_res_state_ext=yes else @@ -2789,12 +2761,12 @@ fi echo $ac_n "checking for nsort in res_state""... $ac_c" 1>&6 -echo "configure:2793: checking for nsort in res_state" >&5 +echo "configure:2765: checking for nsort in res_state" >&5 if eval "test \"`echo '$''{'ac_cv_res_state'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2798 "configure" +#line 2770 "configure" #include "confdefs.h" # include <sys/types.h> @@ -2805,7 +2777,7 @@ int main() { struct __res_state e; e.nsort = 0 ; return 0; } EOF -if { (eval echo configure:2809: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2781: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_res_state=yes else @@ -2832,15 +2804,15 @@ if test "$missing_includes" = "yes"; then fi -for ac_func in vfprintf strcasecmp strlcat strlcpy +for ac_func in vfprintf strcasecmp strlcat strlcpy strdup do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:2839: checking for $ac_func" >&5 +echo "configure:2811: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2844 "configure" +#line 2816 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -2863,7 +2835,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:2867: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2839: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -2889,15 +2861,15 @@ fi done -for ac_func in ether_ntohost setlinebuf +for ac_func in ether_ntohost do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:2896: checking for $ac_func" >&5 +echo "configure:2868: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2901 "configure" +#line 2873 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -2920,7 +2892,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:2924: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2896: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -2939,22 +2911,71 @@ if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then #define $ac_tr_func 1 EOF + echo $ac_n "checking for buggy ether_ntohost""... $ac_c" 1>&6 +echo "configure:2916: checking for buggy ether_ntohost" >&5 +if eval "test \"`echo '$''{'ac_cv_buggy_ether_ntohost'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + + if test "$cross_compiling" = yes; then + ac_cv_buggy_ether_ntohost=not while cross-compiling +else + cat > conftest.$ac_ext <<EOF +#line 2925 "configure" +#include "confdefs.h" + + #include <netdb.h> + #include <sys/types.h> + #include <sys/param.h> + #include <sys/socket.h> + + int + main(int argc, char **argv) + { + u_char ea[6] = { 0xff, 0xff, 0xff, 0xff, 0xff }; + char name[MAXHOSTNAMELEN]; + + ether_ntohost(name, (struct ether_addr *)ea); + exit(0); + } + +EOF +if { (eval echo configure:2944: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +then + ac_cv_buggy_ether_ntohost=no +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -fr conftest* + ac_cv_buggy_ether_ntohost=yes +fi +rm -fr conftest* +fi + +fi + +echo "$ac_t""$ac_cv_buggy_ether_ntohost" 1>&6 + if test "$ac_cv_buggy_ether_ntohost" = "no"; then + cat >> confdefs.h <<\EOF +#define USE_ETHER_NTOHOST 1 +EOF + + fi + else echo "$ac_t""no" 1>&6 fi done - -usegetipnodeby=yes -for ac_func in getipnodebyname getipnodebyaddr freeaddrinfo +for ac_func in setlinebuf do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:2953: checking for $ac_func" >&5 +echo "configure:2974: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2958 "configure" +#line 2979 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -2977,7 +2998,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:2981: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:3002: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -2998,27 +3019,20 @@ EOF else echo "$ac_t""no" 1>&6 -usegetipnodeby=no fi done -if test $usegetipnodeby = yes; then - cat >> confdefs.h <<\EOF -#define USE_GETIPNODEBY 1 -EOF - -fi needsnprintf=no for ac_func in vsnprintf snprintf do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:3017: checking for $ac_func" >&5 +echo "configure:3031: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 3022 "configure" +#line 3036 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -3041,7 +3055,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:3045: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:3059: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -3070,239 +3084,14 @@ if test $needsnprintf = yes; then LIBOBJS="$LIBOBJS snprintf.o" fi -echo $ac_n "checking whether byte ordering is bigendian""... $ac_c" 1>&6 -echo "configure:3075: checking whether byte ordering is bigendian" >&5 -if eval "test \"`echo '$''{'ac_cv_c_bigendian'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - ac_cv_c_bigendian=unknown -# See if sys/param.h defines the BYTE_ORDER macro. -cat > conftest.$ac_ext <<EOF -#line 3082 "configure" -#include "confdefs.h" -#include <sys/types.h> -#include <sys/param.h> -int main() { - -#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN - bogus endian macros -#endif -; return 0; } -EOF -if { (eval echo configure:3093: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then - rm -rf conftest* - # It does; now see whether it defined to BIG_ENDIAN or not. -cat > conftest.$ac_ext <<EOF -#line 3097 "configure" -#include "confdefs.h" -#include <sys/types.h> -#include <sys/param.h> -int main() { - -#if BYTE_ORDER != BIG_ENDIAN - not big endian -#endif -; return 0; } -EOF -if { (eval echo configure:3108: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then - rm -rf conftest* - ac_cv_c_bigendian=yes -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - ac_cv_c_bigendian=no -fi -rm -f conftest* -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 -fi -rm -f conftest* -if test $ac_cv_c_bigendian = unknown; then -if test "$cross_compiling" = yes; then - { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } -else - cat > conftest.$ac_ext <<EOF -#line 3128 "configure" -#include "confdefs.h" -main () { - /* Are we little or big endian? From Harbison&Steele. */ - union - { - long l; - char c[sizeof (long)]; - } u; - u.l = 1; - exit (u.c[sizeof (long) - 1] == 1); -} -EOF -if { (eval echo configure:3141: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null -then - ac_cv_c_bigendian=no -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -fr conftest* - ac_cv_c_bigendian=yes -fi -rm -fr conftest* -fi - -fi -fi - -echo "$ac_t""$ac_cv_c_bigendian" 1>&6 -if test $ac_cv_c_bigendian = yes; then - cat >> confdefs.h <<\EOF -#define WORDS_BIGENDIAN 1 -EOF - -fi - - -echo $ac_n "checking for main in -ldnet""... $ac_c" 1>&6 -echo "configure:3166: checking for main in -ldnet" >&5 -ac_lib_var=`echo dnet'_'main | sed 'y%./+-%__p_%'` -if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - ac_save_LIBS="$LIBS" -LIBS="-ldnet $LIBS" -cat > conftest.$ac_ext <<EOF -#line 3174 "configure" -#include "confdefs.h" - -int main() { -main() -; return 0; } -EOF -if { (eval echo configure:3181: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then - rm -rf conftest* - eval "ac_cv_lib_$ac_lib_var=yes" -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_lib_$ac_lib_var=no" -fi -rm -f conftest* -LIBS="$ac_save_LIBS" - -fi -if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_lib=HAVE_LIB`echo dnet | sed -e 's/[^a-zA-Z0-9_]/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` - cat >> confdefs.h <<EOF -#define $ac_tr_lib 1 -EOF - - LIBS="-ldnet $LIBS" - -else - echo "$ac_t""no" 1>&6 -fi - -echo $ac_n "checking for main in -lrpc""... $ac_c" 1>&6 -echo "configure:3209: checking for main in -lrpc" >&5 -ac_lib_var=`echo rpc'_'main | sed 'y%./+-%__p_%'` -if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - ac_save_LIBS="$LIBS" -LIBS="-lrpc $LIBS" -cat > conftest.$ac_ext <<EOF -#line 3217 "configure" -#include "confdefs.h" - -int main() { -main() -; return 0; } -EOF -if { (eval echo configure:3224: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then - rm -rf conftest* - eval "ac_cv_lib_$ac_lib_var=yes" -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_lib_$ac_lib_var=no" -fi -rm -f conftest* -LIBS="$ac_save_LIBS" - -fi -if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_lib=HAVE_LIB`echo rpc | sed -e 's/[^a-zA-Z0-9_]/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` - cat >> confdefs.h <<EOF -#define $ac_tr_lib 1 -EOF - - LIBS="-lrpc $LIBS" - -else - echo "$ac_t""no" 1>&6 -fi - -echo $ac_n "checking for getrpcbynumber in -lnsl""... $ac_c" 1>&6 -echo "configure:3252: checking for getrpcbynumber in -lnsl" >&5 -ac_lib_var=`echo nsl'_'getrpcbynumber | sed 'y%./+-%__p_%'` -if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - ac_save_LIBS="$LIBS" -LIBS="-lnsl $LIBS" -cat > conftest.$ac_ext <<EOF -#line 3260 "configure" -#include "confdefs.h" -/* Override any gcc2 internal prototype to avoid an error. */ -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char getrpcbynumber(); - -int main() { -getrpcbynumber() -; return 0; } -EOF -if { (eval echo configure:3271: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then - rm -rf conftest* - eval "ac_cv_lib_$ac_lib_var=yes" -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_lib_$ac_lib_var=no" -fi -rm -f conftest* -LIBS="$ac_save_LIBS" - -fi -if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_lib=HAVE_LIB`echo nsl | sed -e 's/[^a-zA-Z0-9_]/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` - cat >> confdefs.h <<EOF -#define $ac_tr_lib 1 -EOF - - LIBS="-lnsl $LIBS" - -else - echo "$ac_t""no" 1>&6 -fi - - echo $ac_n "checking return type of signal handlers""... $ac_c" 1>&6 -echo "configure:3301: checking return type of signal handlers" >&5 +echo "configure:3090: checking return type of signal handlers" >&5 if eval "test \"`echo '$''{'ac_cv_type_signal'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 3306 "configure" +#line 3095 "configure" #include "confdefs.h" #include <sys/types.h> #include <signal.h> @@ -3319,7 +3108,7 @@ int main() { int i; ; return 0; } EOF -if { (eval echo configure:3323: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:3112: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_type_signal=void else @@ -3348,7 +3137,7 @@ EOF EOF fi - case "$target_os" in + case "$host_os" in irix*) cat >> confdefs.h <<\EOF @@ -3361,12 +3150,12 @@ EOF for ac_func in sigset do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:3365: checking for $ac_func" >&5 +echo "configure:3154: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 3370 "configure" +#line 3159 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -3389,7 +3178,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:3393: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:3182: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -3417,12 +3206,12 @@ done for ac_func in sigaction do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:3421: checking for $ac_func" >&5 +echo "configure:3210: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 3426 "configure" +#line 3215 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -3445,7 +3234,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:3449: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:3238: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -3473,160 +3262,176 @@ done ;; esac - - # Most operating systems have gethostbyname() in the default searched - # libraries (i.e. libc): - echo $ac_n "checking for gethostbyname""... $ac_c" 1>&6 -echo "configure:3481: checking for gethostbyname" >&5 -if eval "test \"`echo '$''{'ac_cv_func_gethostbyname'+set}'`\" = set"; then +echo $ac_n "checking for dnet_htoa in -ldnet""... $ac_c" 1>&6 +echo "configure:3267: checking for dnet_htoa in -ldnet" >&5 +ac_lib_var=`echo dnet'_'dnet_htoa | sed 'y%./+-%__p_%'` +if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else - cat > conftest.$ac_ext <<EOF -#line 3486 "configure" + ac_save_LIBS="$LIBS" +LIBS="-ldnet $LIBS" +cat > conftest.$ac_ext <<EOF +#line 3275 "configure" #include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char gethostbyname(); below. */ -#include <assert.h> /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 builtin and then its argument prototype would still apply. */ -char gethostbyname(); +char dnet_htoa(); int main() { - -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_gethostbyname) || defined (__stub___gethostbyname) -choke me -#else -gethostbyname(); -#endif - +dnet_htoa() ; return 0; } EOF -if { (eval echo configure:3509: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:3286: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* - eval "ac_cv_func_gethostbyname=yes" + eval "ac_cv_lib_$ac_lib_var=yes" else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* - eval "ac_cv_func_gethostbyname=no" + eval "ac_cv_lib_$ac_lib_var=no" fi rm -f conftest* -fi +LIBS="$ac_save_LIBS" -if eval "test \"`echo '$ac_cv_func_'gethostbyname`\" = yes"; then +fi +if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then echo "$ac_t""yes" 1>&6 - : + ac_tr_lib=HAVE_LIB`echo dnet | sed -e 's/[^a-zA-Z0-9_]/_/g' \ + -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` + cat >> confdefs.h <<EOF +#define $ac_tr_lib 1 +EOF + + LIBS="-ldnet $LIBS" + else echo "$ac_t""no" 1>&6 -# Some OSes (eg. Solaris) place it in libnsl: - echo $ac_n "checking for gethostbyname in -lnsl""... $ac_c" 1>&6 -echo "configure:3528: checking for gethostbyname in -lnsl" >&5 -ac_lib_var=`echo nsl'_'gethostbyname'_' | sed 'y%./+- %__p__%'` -if eval "test \"`echo '$''{'ac_cv_lbl_lib_$ac_lib_var'+set}'`\" = set"; then +fi + + +echo $ac_n "checking for main in -lrpc""... $ac_c" 1>&6 +echo "configure:3315: checking for main in -lrpc" >&5 +ac_lib_var=`echo rpc'_'main | sed 'y%./+-%__p_%'` +if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_save_LIBS="$LIBS" -LIBS="-lnsl $LIBS" +LIBS="-lrpc $LIBS" cat > conftest.$ac_ext <<EOF -#line 3536 "configure" +#line 3323 "configure" #include "confdefs.h" -/* Override any gcc2 internal prototype to avoid an error. */ -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char gethostbyname(); int main() { -gethostbyname() +main() ; return 0; } EOF -if { (eval echo configure:3547: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:3330: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* - eval "ac_cv_lbl_lib_$ac_lib_var=yes" + eval "ac_cv_lib_$ac_lib_var=yes" else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* - eval "ac_cv_lbl_lib_$ac_lib_var=no" + eval "ac_cv_lib_$ac_lib_var=no" fi rm -f conftest* LIBS="$ac_save_LIBS" fi -if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then +if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then echo "$ac_t""yes" 1>&6 - ac_tr_lib=HAVE_LIB`echo nsl | sed -e 's/^a-zA-Z0-9_/_/g' \ + ac_tr_lib=HAVE_LIB`echo rpc | sed -e 's/[^a-zA-Z0-9_]/_/g' \ -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` cat >> confdefs.h <<EOF #define $ac_tr_lib 1 EOF - LIBS="-lnsl $LIBS" + LIBS="-lrpc $LIBS" else echo "$ac_t""no" 1>&6 -# Some strange OSes (SINIX) have it in libsocket: - echo $ac_n "checking for gethostbyname in -lsocket""... $ac_c" 1>&6 -echo "configure:3574: checking for gethostbyname in -lsocket" >&5 -ac_lib_var=`echo socket'_'gethostbyname'_' | sed 'y%./+- %__p__%'` -if eval "test \"`echo '$''{'ac_cv_lbl_lib_$ac_lib_var'+set}'`\" = set"; then +fi + + +echo $ac_n "checking for library containing getrpcbynumber""... $ac_c" 1>&6 +echo "configure:3359: checking for library containing getrpcbynumber" >&5 +if eval "test \"`echo '$''{'ac_cv_search_getrpcbynumber'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else - ac_save_LIBS="$LIBS" -LIBS="-lsocket $LIBS" + ac_func_search_save_LIBS="$LIBS" +ac_cv_search_getrpcbynumber="no" cat > conftest.$ac_ext <<EOF -#line 3582 "configure" +#line 3366 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 builtin and then its argument prototype would still apply. */ -char gethostbyname(); +char getrpcbynumber(); int main() { -gethostbyname() +getrpcbynumber() ; return 0; } EOF -if { (eval echo configure:3593: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:3377: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* - eval "ac_cv_lbl_lib_$ac_lib_var=yes" + ac_cv_search_getrpcbynumber="none required" else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 +fi +rm -f conftest* +test "$ac_cv_search_getrpcbynumber" = "no" && for i in nsl; do +LIBS="-l$i $ac_func_search_save_LIBS" +cat > conftest.$ac_ext <<EOF +#line 3388 "configure" +#include "confdefs.h" +/* Override any gcc2 internal prototype to avoid an error. */ +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char getrpcbynumber(); + +int main() { +getrpcbynumber() +; return 0; } +EOF +if { (eval echo configure:3399: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* - eval "ac_cv_lbl_lib_$ac_lib_var=no" + ac_cv_search_getrpcbynumber="-l$i" +break +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 fi rm -f conftest* -LIBS="$ac_save_LIBS" +done +LIBS="$ac_func_search_save_LIBS" +fi +echo "$ac_t""$ac_cv_search_getrpcbynumber" 1>&6 +if test "$ac_cv_search_getrpcbynumber" != "no"; then + test "$ac_cv_search_getrpcbynumber" = "none required" || LIBS="$ac_cv_search_getrpcbynumber $LIBS" + +else : + fi -if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_lib=HAVE_LIB`echo socket | sed -e 's/^a-zA-Z0-9_/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` - cat >> confdefs.h <<EOF -#define $ac_tr_lib 1 -EOF - LIBS="-lsocket $LIBS" -else - echo "$ac_t""no" 1>&6 -# Unfortunately libsocket sometimes depends on libnsl. - # AC_CHECK_LIB's API is essentially broken so the - # following ugliness is necessary: - echo $ac_n "checking for gethostbyname in -lsocket""... $ac_c" 1>&6 -echo "configure:3622: checking for gethostbyname in -lsocket" >&5 -ac_lib_var=`echo socket'_'gethostbyname'_'-lnsl | sed 'y%./+- %__p__%'` -if eval "test \"`echo '$''{'ac_cv_lbl_lib_$ac_lib_var'+set}'`\" = set"; then + + # Most operating systems have gethostbyname() in the default searched + # libraries (i.e. libc): + # Some OSes (eg. Solaris) place it in libnsl + # Some strange OSes (SINIX) have it in libsocket: + +echo $ac_n "checking for library containing gethostbyname""... $ac_c" 1>&6 +echo "configure:3428: checking for library containing gethostbyname" >&5 +if eval "test \"`echo '$''{'ac_cv_search_gethostbyname'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else - ac_save_LIBS="$LIBS" -LIBS="-lsocket -lnsl $LIBS" + ac_func_search_save_LIBS="$LIBS" +ac_cv_search_gethostbyname="no" cat > conftest.$ac_ext <<EOF -#line 3630 "configure" +#line 3435 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -3637,34 +3442,62 @@ int main() { gethostbyname() ; return 0; } EOF -if { (eval echo configure:3641: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:3446: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* - eval "ac_cv_lbl_lib_$ac_lib_var=yes" + ac_cv_search_gethostbyname="none required" else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 +fi +rm -f conftest* +test "$ac_cv_search_gethostbyname" = "no" && for i in nsl socket resolv; do +LIBS="-l$i $ac_func_search_save_LIBS" +cat > conftest.$ac_ext <<EOF +#line 3457 "configure" +#include "confdefs.h" +/* Override any gcc2 internal prototype to avoid an error. */ +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char gethostbyname(); + +int main() { +gethostbyname() +; return 0; } +EOF +if { (eval echo configure:3468: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* - eval "ac_cv_lbl_lib_$ac_lib_var=no" + ac_cv_search_gethostbyname="-l$i" +break +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 fi rm -f conftest* -LIBS="$ac_save_LIBS" +done +LIBS="$ac_func_search_save_LIBS" +fi +echo "$ac_t""$ac_cv_search_gethostbyname" 1>&6 +if test "$ac_cv_search_gethostbyname" != "no"; then + test "$ac_cv_search_gethostbyname" = "none required" || LIBS="$ac_cv_search_gethostbyname $LIBS" + +else : + fi -if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then - echo "$ac_t""yes" 1>&6 - LIBS="-lsocket -lnsl $LIBS" -else - echo "$ac_t""no" 1>&6 -echo $ac_n "checking for gethostbyname in -lresolv""... $ac_c" 1>&6 -echo "configure:3660: checking for gethostbyname in -lresolv" >&5 -ac_lib_var=`echo resolv'_'gethostbyname | sed 'y%./+-%__p_%'` + # Unfortunately libsocket sometimes depends on libnsl and + # AC_SEARCH_LIBS isn't up to the task of handling dependencies like this. + if test "$ac_cv_search_gethostbyname" = "no" + then + echo $ac_n "checking for gethostbyname in -lsocket""... $ac_c" 1>&6 +echo "configure:3493: checking for gethostbyname in -lsocket" >&5 +ac_lib_var=`echo socket'_'gethostbyname | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_save_LIBS="$LIBS" -LIBS="-lresolv $LIBS" +LIBS="-lsocket -lnsl $LIBS" cat > conftest.$ac_ext <<EOF -#line 3668 "configure" +#line 3501 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -3675,7 +3508,7 @@ int main() { gethostbyname() ; return 0; } EOF -if { (eval echo configure:3679: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:3512: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -3690,82 +3523,44 @@ LIBS="$ac_save_LIBS" fi if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then echo "$ac_t""yes" 1>&6 - ac_tr_lib=HAVE_LIB`echo resolv | sed -e 's/^a-zA-Z0-9_/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` - cat >> confdefs.h <<EOF -#define $ac_tr_lib 1 -EOF - - LIBS="-lresolv $LIBS" - + LIBS="-lsocket -lnsl $LIBS" else echo "$ac_t""no" 1>&6 fi -fi - -fi - -fi - -fi - - echo $ac_n "checking for socket""... $ac_c" 1>&6 -echo "configure:3715: checking for socket" >&5 -if eval "test \"`echo '$''{'ac_cv_func_socket'+set}'`\" = set"; then + fi + +echo $ac_n "checking for library containing socket""... $ac_c" 1>&6 +echo "configure:3535: checking for library containing socket" >&5 +if eval "test \"`echo '$''{'ac_cv_search_socket'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else - cat > conftest.$ac_ext <<EOF -#line 3720 "configure" + ac_func_search_save_LIBS="$LIBS" +ac_cv_search_socket="no" +cat > conftest.$ac_ext <<EOF +#line 3542 "configure" #include "confdefs.h" -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char socket(); below. */ -#include <assert.h> /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 builtin and then its argument prototype would still apply. */ char socket(); int main() { - -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_socket) || defined (__stub___socket) -choke me -#else -socket(); -#endif - +socket() ; return 0; } EOF -if { (eval echo configure:3743: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:3553: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* - eval "ac_cv_func_socket=yes" + ac_cv_search_socket="none required" else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_func_socket=no" fi rm -f conftest* -fi - -if eval "test \"`echo '$ac_cv_func_'socket`\" = yes"; then - echo "$ac_t""yes" 1>&6 - : -else - echo "$ac_t""no" 1>&6 -echo $ac_n "checking for socket in -lsocket""... $ac_c" 1>&6 -echo "configure:3761: checking for socket in -lsocket" >&5 -ac_lib_var=`echo socket'_'socket | sed 'y%./+-%__p_%'` -if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - ac_save_LIBS="$LIBS" -LIBS="-lsocket $LIBS" +test "$ac_cv_search_socket" = "no" && for i in socket; do +LIBS="-l$i $ac_func_search_save_LIBS" cat > conftest.$ac_ext <<EOF -#line 3769 "configure" +#line 3564 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -3776,41 +3571,34 @@ int main() { socket() ; return 0; } EOF -if { (eval echo configure:3780: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:3575: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* - eval "ac_cv_lib_$ac_lib_var=yes" + ac_cv_search_socket="-l$i" +break else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_lib_$ac_lib_var=no" fi rm -f conftest* -LIBS="$ac_save_LIBS" - +done +LIBS="$ac_func_search_save_LIBS" fi -if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_lib=HAVE_LIB`echo socket | sed -e 's/^a-zA-Z0-9_/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` - cat >> confdefs.h <<EOF -#define $ac_tr_lib 1 -EOF - LIBS="-lsocket $LIBS" - -else - echo "$ac_t""no" 1>&6 -echo $ac_n "checking for socket in -lsocket""... $ac_c" 1>&6 -echo "configure:3806: checking for socket in -lsocket" >&5 -ac_lib_var=`echo socket'_'socket'_'-lnsl | sed 'y%./+- %__p__%'` -if eval "test \"`echo '$''{'ac_cv_lbl_lib_$ac_lib_var'+set}'`\" = set"; then +echo "$ac_t""$ac_cv_search_socket" 1>&6 +if test "$ac_cv_search_socket" != "no"; then + test "$ac_cv_search_socket" = "none required" || LIBS="$ac_cv_search_socket $LIBS" + +else : + echo $ac_n "checking for socket in -lsocket""... $ac_c" 1>&6 +echo "configure:3594: checking for socket in -lsocket" >&5 +ac_lib_var=`echo socket'_'socket | sed 'y%./+-%__p_%'` +if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_save_LIBS="$LIBS" LIBS="-lsocket -lnsl $LIBS" cat > conftest.$ac_ext <<EOF -#line 3814 "configure" +#line 3602 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -3821,20 +3609,20 @@ int main() { socket() ; return 0; } EOF -if { (eval echo configure:3825: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:3613: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* - eval "ac_cv_lbl_lib_$ac_lib_var=yes" + eval "ac_cv_lib_$ac_lib_var=yes" else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* - eval "ac_cv_lbl_lib_$ac_lib_var=no" + eval "ac_cv_lib_$ac_lib_var=no" fi rm -f conftest* LIBS="$ac_save_LIBS" fi -if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then +if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then echo "$ac_t""yes" 1>&6 LIBS="-lsocket -lnsl $LIBS" else @@ -3842,20 +3630,17 @@ else fi fi - -fi - # DLPI needs putmsg under HPUX so test for -lstr while we're at it - echo $ac_n "checking for putmsg in -lstr""... $ac_c" 1>&6 -echo "configure:3851: checking for putmsg in -lstr" >&5 -ac_lib_var=`echo str'_'putmsg | sed 'y%./+-%__p_%'` -if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then + +echo $ac_n "checking for library containing putmsg""... $ac_c" 1>&6 +echo "configure:3637: checking for library containing putmsg" >&5 +if eval "test \"`echo '$''{'ac_cv_search_putmsg'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else - ac_save_LIBS="$LIBS" -LIBS="-lstr $LIBS" + ac_func_search_save_LIBS="$LIBS" +ac_cv_search_putmsg="no" cat > conftest.$ac_ext <<EOF -#line 3859 "configure" +#line 3644 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -3866,33 +3651,48 @@ int main() { putmsg() ; return 0; } EOF -if { (eval echo configure:3870: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:3655: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* - eval "ac_cv_lib_$ac_lib_var=yes" + ac_cv_search_putmsg="none required" else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_lib_$ac_lib_var=no" fi rm -f conftest* -LIBS="$ac_save_LIBS" +test "$ac_cv_search_putmsg" = "no" && for i in str; do +LIBS="-l$i $ac_func_search_save_LIBS" +cat > conftest.$ac_ext <<EOF +#line 3666 "configure" +#include "confdefs.h" +/* Override any gcc2 internal prototype to avoid an error. */ +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char putmsg(); -fi -if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_lib=HAVE_LIB`echo str | sed -e 's/[^a-zA-Z0-9_]/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` - cat >> confdefs.h <<EOF -#define $ac_tr_lib 1 +int main() { +putmsg() +; return 0; } EOF - - LIBS="-lstr $LIBS" - +if { (eval echo configure:3677: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then + rm -rf conftest* + ac_cv_search_putmsg="-l$i" +break else - echo "$ac_t""no" 1>&6 + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 +fi +rm -f conftest* +done +LIBS="$ac_func_search_save_LIBS" fi +echo "$ac_t""$ac_cv_search_putmsg" 1>&6 +if test "$ac_cv_search_putmsg" != "no"; then + test "$ac_cv_search_putmsg" = "none required" || LIBS="$ac_cv_search_putmsg $LIBS" + +else : + +fi LBL_LIBS="$LIBS" @@ -3901,12 +3701,12 @@ fi for ac_func in pfopen do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:3905: checking for $ac_func" >&5 +echo "configure:3705: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 3910 "configure" +#line 3710 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -3929,7 +3729,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:3933: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:3733: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -3959,7 +3759,7 @@ done fi fi echo $ac_n "checking for local pcap library""... $ac_c" 1>&6 -echo "configure:3963: checking for local pcap library" >&5 +echo "configure:3763: checking for local pcap library" >&5 libpcap=FAIL lastdir=FAIL places=`ls .. | sed -e 's,/$,,' -e 's,^,../,' | \ @@ -3978,7 +3778,7 @@ echo "configure:3963: checking for local pcap library" >&5 if test $libpcap = FAIL ; then echo "$ac_t""not found" 1>&6 echo $ac_n "checking for main in -lpcap""... $ac_c" 1>&6 -echo "configure:3982: checking for main in -lpcap" >&5 +echo "configure:3782: checking for main in -lpcap" >&5 ac_lib_var=`echo pcap'_'main | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -3986,14 +3786,14 @@ else ac_save_LIBS="$LIBS" LIBS="-lpcap $LIBS" cat > conftest.$ac_ext <<EOF -#line 3990 "configure" +#line 3790 "configure" #include "confdefs.h" int main() { main() ; return 0; } EOF -if { (eval echo configure:3997: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:3797: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -4018,22 +3818,24 @@ fi fi else V_PCAPDEP=$libpcap + places=`ls $srcdir/.. | sed -e 's,/$,,' -e "s,^,$srcdir/../," | \ + egrep '/libpcap-[0-9]*.[0-9]*(.[0-9]*)?([ab][0-9]*)?$'` if test -r $d/pcap.h; then V_INCLS="-I$d $V_INCLS" - elif test -r $srcdir/../libpcap/pcap.h; then - V_INCLS="-I$d -I$srcdir/../libpcap $V_INCLS" + elif test -r $places/pcap.h; then + V_INCLS="-I$places $V_INCLS" else { echo "configure: error: cannot find pcap.h" 1>&2; exit 1; } fi echo "$ac_t""$libpcap" 1>&6 fi LIBS="$libpcap $LIBS" - case "$target_os" in + case "$host_os" in aix*) pseexe="/lib/pse.exp" echo $ac_n "checking for $pseexe""... $ac_c" 1>&6 -echo "configure:4037: checking for $pseexe" >&5 +echo "configure:3839: checking for $pseexe" >&5 if test -f $pseexe ; then echo "$ac_t""yes" 1>&6 LIBS="$LIBS -I:$pseexe" @@ -4044,12 +3846,12 @@ echo "configure:4037: checking for $pseexe" >&5 for ac_func in bpf_dump do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:4048: checking for $ac_func" >&5 +echo "configure:3850: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 4053 "configure" +#line 3855 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -4072,7 +3874,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:4076: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:3878: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -4102,7 +3904,7 @@ V_GROUP=0 if test -f /etc/group -a ! -z "`grep '^wheel:' /etc/group`" ; then V_GROUP=wheel fi -case "$target_os" in +case "$host_os" in aix*) cat >> confdefs.h <<\EOF @@ -4129,12 +3931,12 @@ if test -f /dev/bpf0 ; then fi echo $ac_n "checking for u_int8_t using $CC""... $ac_c" 1>&6 -echo "configure:4133: checking for u_int8_t using $CC" >&5 +echo "configure:3935: checking for u_int8_t using $CC" >&5 if eval "test \"`echo '$''{'ac_cv_lbl_have_u_int8_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 4138 "configure" +#line 3940 "configure" #include "confdefs.h" # include "confdefs.h" @@ -4147,7 +3949,7 @@ int main() { u_int8_t i ; return 0; } EOF -if { (eval echo configure:4151: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:3953: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_lbl_have_u_int8_t=yes else @@ -4167,12 +3969,12 @@ EOF fi echo $ac_n "checking for int16_t using $CC""... $ac_c" 1>&6 -echo "configure:4171: checking for int16_t using $CC" >&5 +echo "configure:3973: checking for int16_t using $CC" >&5 if eval "test \"`echo '$''{'ac_cv_lbl_have_int16_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 4176 "configure" +#line 3978 "configure" #include "confdefs.h" # include "confdefs.h" @@ -4185,7 +3987,7 @@ int main() { int16_t i ; return 0; } EOF -if { (eval echo configure:4189: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:3991: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_lbl_have_int16_t=yes else @@ -4205,12 +4007,12 @@ EOF fi echo $ac_n "checking for u_int16_t using $CC""... $ac_c" 1>&6 -echo "configure:4209: checking for u_int16_t using $CC" >&5 +echo "configure:4011: checking for u_int16_t using $CC" >&5 if eval "test \"`echo '$''{'ac_cv_lbl_have_u_int16_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 4214 "configure" +#line 4016 "configure" #include "confdefs.h" # include "confdefs.h" @@ -4223,7 +4025,7 @@ int main() { u_int16_t i ; return 0; } EOF -if { (eval echo configure:4227: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:4029: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_lbl_have_u_int16_t=yes else @@ -4243,12 +4045,12 @@ EOF fi echo $ac_n "checking for int32_t using $CC""... $ac_c" 1>&6 -echo "configure:4247: checking for int32_t using $CC" >&5 +echo "configure:4049: checking for int32_t using $CC" >&5 if eval "test \"`echo '$''{'ac_cv_lbl_have_int32_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 4252 "configure" +#line 4054 "configure" #include "confdefs.h" # include "confdefs.h" @@ -4261,7 +4063,7 @@ int main() { int32_t i ; return 0; } EOF -if { (eval echo configure:4265: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:4067: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_lbl_have_int32_t=yes else @@ -4281,12 +4083,12 @@ EOF fi echo $ac_n "checking for u_int32_t using $CC""... $ac_c" 1>&6 -echo "configure:4285: checking for u_int32_t using $CC" >&5 +echo "configure:4087: checking for u_int32_t using $CC" >&5 if eval "test \"`echo '$''{'ac_cv_lbl_have_u_int32_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 4290 "configure" +#line 4092 "configure" #include "confdefs.h" # include "confdefs.h" @@ -4299,7 +4101,7 @@ int main() { u_int32_t i ; return 0; } EOF -if { (eval echo configure:4303: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:4105: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_lbl_have_u_int32_t=yes else @@ -4335,7 +4137,7 @@ rm -f os-proto.h fi fi else - case "$target_os" in + case "$host_os" in irix6*) V_CCOPT="$V_CCOPT -n32" @@ -4345,7 +4147,7 @@ rm -f os-proto.h ;; esac fi - os=`echo $target_os | sed -e 's/\([0-9][0-9]*\)[^0-9].*$/\1/'` + os=`echo $host_os | sed -e 's/\([0-9][0-9]*\)[^0-9].*$/\1/'` name="lbl/os-$os.h" if test -f $name ; then ln -s $name os-proto.h @@ -4359,12 +4161,12 @@ EOF fi echo $ac_n "checking if sockaddr struct has sa_len member""... $ac_c" 1>&6 -echo "configure:4363: checking if sockaddr struct has sa_len member" >&5 +echo "configure:4165: checking if sockaddr struct has sa_len member" >&5 if eval "test \"`echo '$''{'ac_cv_lbl_sockaddr_has_sa_len'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 4368 "configure" +#line 4170 "configure" #include "confdefs.h" # include <sys/types.h> @@ -4373,7 +4175,7 @@ int main() { u_int i = sizeof(((struct sockaddr *)0)->sa_len) ; return 0; } EOF -if { (eval echo configure:4377: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:4179: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_lbl_sockaddr_has_sa_len=yes else @@ -4394,14 +4196,14 @@ EOF fi echo $ac_n "checking if unaligned accesses fail""... $ac_c" 1>&6 -echo "configure:4398: checking if unaligned accesses fail" >&5 +echo "configure:4200: checking if unaligned accesses fail" >&5 if eval "test \"`echo '$''{'ac_cv_lbl_unaligned_fail'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else - case "$target_cpu" in + case "$host_cpu" in # XXX: should also check that they don't do weird things (like on arm) - alpha*|arm*|hp*|mips|sparc) + alpha*|arm*|hp*|mips*|sparc*|ia64) ac_cv_lbl_unaligned_fail=yes ;; @@ -4459,12 +4261,12 @@ EOF echo $ac_n "checking for h_errno""... $ac_c" 1>&6 -echo "configure:4463: checking for h_errno" >&5 +echo "configure:4265: checking for h_errno" >&5 if eval "test \"`echo '$''{'ac_cv_var_h_errno'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 4468 "configure" +#line 4270 "configure" #include "confdefs.h" # include <sys/types.h> @@ -4473,7 +4275,7 @@ int main() { int foo = h_errno; ; return 0; } EOF -if { (eval echo configure:4477: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:4279: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_var_h_errno=yes else @@ -4501,18 +4303,14 @@ if test "${with_crypto+set}" = set; then else echo $ac_n "checking for SSLeay""... $ac_c" 1>&6 -echo "configure:4505: checking for SSLeay" >&5 +echo "configure:4307: checking for SSLeay" >&5 ac_cv_ssleay_path=no incdir=no for dir in /usr /usr/local /usr/local/ssl /usr/pkg; do if test -d $dir/lib -a -f $dir/lib/libcrypto.a; then ac_cv_ssleay_path=$dir fi - if test -d $dir/include/ssleay -a -f $dir/include/ssleay/des.h; then - incdir="-I$dir/include/ssleay" - elif test -d $dir/include/openssl -a -f $dir/include/openssl/des.h; then - incdir="-I$dir/include -I$dir/include/openssl" - elif test -d $dir/include -a -f $dir/include/des.h; then + if test -d $dir/include/openssl -a -f $dir/include/openssl/des.h; then incdir="-I$dir/include" fi if test "$ac_cv_ssleay_path" != "no" -a "$incdir" != "no"; then @@ -4533,7 +4331,7 @@ if test "$ac_cv_ssleay_path" != no; then LIBS="$LIBS -lrsaref" fi echo $ac_n "checking for des_cbc_encrypt in -lcrypto""... $ac_c" 1>&6 -echo "configure:4537: checking for des_cbc_encrypt in -lcrypto" >&5 +echo "configure:4335: checking for des_cbc_encrypt in -lcrypto" >&5 ac_lib_var=`echo crypto'_'des_cbc_encrypt | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -4541,7 +4339,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lcrypto $LIBS" cat > conftest.$ac_ext <<EOF -#line 4545 "configure" +#line 4343 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -4552,7 +4350,7 @@ int main() { des_cbc_encrypt() ; return 0; } EOF -if { (eval echo configure:4556: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:4354: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -4586,17 +4384,17 @@ fi do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:4590: checking for $ac_hdr" >&5 +echo "configure:4388: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 4595 "configure" +#line 4393 "configure" #include "confdefs.h" #include <$ac_hdr> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:4600: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:4398: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -4625,12 +4423,12 @@ done if test "$ac_cv_header_cast_h" = "yes"; then echo $ac_n "checking for buggy CAST128""... $ac_c" 1>&6 -echo "configure:4629: checking for buggy CAST128" >&5 +echo "configure:4427: checking for buggy CAST128" >&5 if test "$cross_compiling" = yes; then buggy_cast128="cross-compiling, assume yes" else cat > conftest.$ac_ext <<EOF -#line 4634 "configure" +#line 4432 "configure" #include "confdefs.h" #include <cast.h> @@ -4649,7 +4447,7 @@ main() return 1; } EOF -if { (eval echo configure:4653: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:4451: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then buggy_cast128=yes else @@ -4681,17 +4479,17 @@ for ac_hdr in rc5.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:4685: checking for $ac_hdr" >&5 +echo "configure:4483: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 4690 "configure" +#line 4488 "configure" #include "confdefs.h" #include <$ac_hdr> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:4695: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:4493: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -4736,7 +4534,7 @@ done # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # ./install, which can be erroneously created by make from ./install.sh. echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6 -echo "configure:4740: checking for a BSD compatible install" >&5 +echo "configure:4538: checking for a BSD compatible install" >&5 if test -z "$INSTALL"; then if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -4930,16 +4728,6 @@ s%@host_alias@%$host_alias%g s%@host_cpu@%$host_cpu%g s%@host_vendor@%$host_vendor%g s%@host_os@%$host_os%g -s%@target@%$target%g -s%@target_alias@%$target_alias%g -s%@target_cpu@%$target_cpu%g -s%@target_vendor@%$target_vendor%g -s%@target_os@%$target_os%g -s%@build@%$build%g -s%@build_alias@%$build_alias%g -s%@build_cpu@%$build_cpu%g -s%@build_vendor@%$build_vendor%g -s%@build_os@%$build_os%g s%@SHLICC2@%$SHLICC2%g s%@CC@%$CC%g s%@CPP@%$CPP%g diff --git a/contrib/tcpdump/configure.in b/contrib/tcpdump/configure.in index 43f6777..361fba0 100755 --- a/contrib/tcpdump/configure.in +++ b/contrib/tcpdump/configure.in @@ -1,4 +1,4 @@ -dnl @(#) $Header: /tcpdump/master/tcpdump/configure.in,v 1.132.4.1 2001/01/17 18:29:58 guy Exp $ (LBL) +dnl @(#) $Header: /tcpdump/master/tcpdump/configure.in,v 1.145 2002/01/17 05:00:16 guy Exp $ (LBL) dnl dnl Copyright (c) 1994, 1995, 1996, 1997 dnl The Regents of the University of California. All rights reserved. @@ -6,11 +6,11 @@ dnl dnl Process this file with autoconf to produce a configure script. dnl -AC_REVISION($Revision: 1.132.4.1 $) +AC_REVISION($Revision: 1.145 $) AC_PREREQ(2.13) AC_INIT(tcpdump.c) -AC_CANONICAL_SYSTEM +AC_CANONICAL_HOST AC_LBL_C_INIT(V_CCOPT, V_INCLS) AC_C_INLINE @@ -19,7 +19,7 @@ AC_C___ATTRIBUTE__ AC_CHECK_HEADERS(fcntl.h rpc/rpcent.h netinet/if_ether.h) AC_HEADER_TIME -case "$target_os" in +case "$host_os" in linux*) AC_MSG_CHECKING(Linux kernel version) @@ -47,6 +47,8 @@ esac AC_CHECK_HEADERS(smi.h) AC_CHECK_LIB(smi, smiInit) +if test "$ac_cv_header_smi_h" = yes -a "$ac_cv_lib_smi_smiInit" = yes +then AC_MSG_CHECKING([whether to enable libsmi]) AC_TRY_RUN([ /* libsmi available check */ #include <smi.h> @@ -69,12 +71,36 @@ main() [ AC_MSG_RESULT(yes) AC_DEFINE(LIBSMI) libsmi=yes], -[ AC_MSG_RESULT(no) +dnl autoconf documentation says that $? contains the exit value. +dnl reality is that it does not. We leave this in just in case +dnl autoconf ever comes back to match the documentation. +[ case $? in + 1) AC_MSG_RESULT(no - smiInit failed) ;; + 2) AC_MSG_RESULT(no - header/library version mismatch) ;; + 3) AC_MSG_RESULT(no - can't determine library version) ;; + 4) AC_MSG_RESULT(no - too old) ;; + *) AC_MSG_RESULT(no) ;; + esac libsmi=no], [ AC_MSG_RESULT(not when cross-compiling) libsmi=no] ) +fi +AC_MSG_CHECKING([whether to enable the possibly-buggy SMB printer]) +AC_ARG_ENABLE(smb, +[ --enable-smb enable possibly-buggy SMB printer [default=yes] + --disable-smb disable possibly-buggy SMB printer],, + enableval=yes) +case "$enableval" in +yes) AC_MSG_RESULT(yes) + AC_WARN([The SMB printer may have exploitable buffer overflows!!!]) + AC_DEFINE(TCPDUMP_DO_SMB) + LOCALSRC="print-smb.c smbutil.c $LOCALSRC" + ;; +*) AC_MSG_RESULT(no) + ;; +esac CFLAGS="$CFLAGS -Dss_family=__ss_family -Dss_len=__ss_len" AC_MSG_CHECKING([whether to enable ipv6]) @@ -450,15 +476,32 @@ if test "$missing_includes" = "yes"; then fi -AC_REPLACE_FUNCS(vfprintf strcasecmp strlcat strlcpy) -AC_CHECK_FUNCS(ether_ntohost setlinebuf) - -usegetipnodeby=yes -AC_CHECK_FUNCS(getipnodebyname getipnodebyaddr freeaddrinfo, - [], [usegetipnodeby=no]) -if test $usegetipnodeby = yes; then - AC_DEFINE(USE_GETIPNODEBY) -fi +AC_REPLACE_FUNCS(vfprintf strcasecmp strlcat strlcpy strdup) +AC_CHECK_FUNCS(ether_ntohost, [ + AC_CACHE_CHECK(for buggy ether_ntohost, ac_cv_buggy_ether_ntohost, [ + AC_TRY_RUN([ + #include <netdb.h> + #include <sys/types.h> + #include <sys/param.h> + #include <sys/socket.h> + + int + main(int argc, char **argv) + { + u_char ea[6] = { 0xff, 0xff, 0xff, 0xff, 0xff }; + char name[MAXHOSTNAMELEN]; + + ether_ntohost(name, (struct ether_addr *)ea); + exit(0); + } + ], [ac_cv_buggy_ether_ntohost=no], + [ac_cv_buggy_ether_ntohost=yes], + [ac_cv_buggy_ether_ntohost=not while cross-compiling])]) + if test "$ac_cv_buggy_ether_ntohost" = "no"; then + AC_DEFINE(USE_ETHER_NTOHOST) + fi +]) +AC_CHECK_FUNCS(setlinebuf) needsnprintf=no AC_CHECK_FUNCS(vsnprintf snprintf,, @@ -467,19 +510,18 @@ if test $needsnprintf = yes; then LIBOBJS="$LIBOBJS snprintf.o" fi -dnl The following generates a warning from autoconf... -errprint(__file__:__line__: please ignore the next warning: -)dnl -AC_C_BIGENDIAN +AC_LBL_TYPE_SIGNAL + +AC_CHECK_LIB(dnet, dnet_htoa) + +AC_CHECK_LIB(rpc, main) dnl It's unclear why we might need -lrpc + +dnl HP/UX may need -lnsl for getrpcbynumber. +AC_SEARCH_LIBS(getrpcbynumber, nsl) -AC_CHECK_LIB(dnet, main) -AC_CHECK_LIB(rpc, main) -AC_CHECK_LIB(nsl, getrpcbynumber) dnl AC_CHECK_LIB(z, uncompress) dnl AC_CHECK_HEADERS(zlib.h) -AC_LBL_TYPE_SIGNAL - AC_LBL_LIBPCAP(V_PCAPDEP, V_INCLS) AC_REPLACE_FUNCS(bpf_dump) dnl moved to libpcap in 0.6 @@ -488,7 +530,7 @@ V_GROUP=0 if test -f /etc/group -a ! -z "`grep '^wheel:' /etc/group`" ; then V_GROUP=wheel fi -case "$target_os" in +case "$host_os" in aix*) dnl Workaround to enable certain features @@ -535,11 +577,7 @@ for dir in /usr /usr/local /usr/local/ssl /usr/pkg; do if test -d $dir/lib -a -f $dir/lib/libcrypto.a; then ac_cv_ssleay_path=$dir fi - if test -d $dir/include/ssleay -a -f $dir/include/ssleay/des.h; then - incdir="-I$dir/include/ssleay" - elif test -d $dir/include/openssl -a -f $dir/include/openssl/des.h; then - incdir="-I$dir/include -I$dir/include/openssl" - elif test -d $dir/include -a -f $dir/include/des.h; then + if test -d $dir/include/openssl -a -f $dir/include/openssl/des.h; then incdir="-I$dir/include" fi if test "$ac_cv_ssleay_path" != "no" -a "$incdir" != "no"; then diff --git a/contrib/tcpdump/dhcp6.h b/contrib/tcpdump/dhcp6.h index a451bbf..8381b11 100644 --- a/contrib/tcpdump/dhcp6.h +++ b/contrib/tcpdump/dhcp6.h @@ -1,4 +1,4 @@ -/* @(#) $Header: /tcpdump/master/tcpdump/dhcp6.h,v 1.4 2000/12/17 23:07:48 guy Exp $ (LBL) */ +/* @(#) $Header: /tcpdump/master/tcpdump/Attic/dhcp6.h,v 1.4 2000/12/17 23:07:48 guy Exp $ (LBL) */ /* * Copyright (C) 1998 and 1999 WIDE Project. * All rights reserved. diff --git a/contrib/tcpdump/dhcp6opt.h b/contrib/tcpdump/dhcp6opt.h index b4ec2e4..fc6534d 100644 --- a/contrib/tcpdump/dhcp6opt.h +++ b/contrib/tcpdump/dhcp6opt.h @@ -1,4 +1,4 @@ -/* @(#) $Header: /tcpdump/master/tcpdump/dhcp6opt.h,v 1.3 2000/12/17 23:07:49 guy Exp $ (LBL) */ +/* @(#) $Header: /tcpdump/master/tcpdump/Attic/dhcp6opt.h,v 1.4 2001/09/17 21:57:51 fenner Exp $ (LBL) */ /* * Copyright (C) 1998 and 1999 WIDE Project. * All rights reserved. @@ -47,7 +47,7 @@ struct dhcp6_opt { u_int code; int len; - char *name; + const char *name; int type; }; diff --git a/contrib/tcpdump/ethertype.h b/contrib/tcpdump/ethertype.h index d1a653b..fe5e617 100644 --- a/contrib/tcpdump/ethertype.h +++ b/contrib/tcpdump/ethertype.h @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: /tcpdump/master/tcpdump/ethertype.h,v 1.12 2000/09/23 08:03:30 guy Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/ethertype.h,v 1.16 2001/06/21 17:56:02 itojun Exp $ (LBL) */ /* @@ -97,11 +97,20 @@ #define ETHERTYPE_8021Q 0x8100 #endif #ifndef ETHERTYPE_IPX -#define ETHERTYPE_IPX 0x8137 +#define ETHERTYPE_IPX 0x8137 #endif #ifndef ETHERTYPE_IPV6 #define ETHERTYPE_IPV6 0x86dd #endif +#ifndef ETHERTYPE_PPP +#define ETHERTYPE_PPP 0x880b +#endif +#ifndef ETHERTYPE_MPLS +#define ETHERTYPE_MPLS 0x8847 +#endif +#ifndef ETHERTYPE_MPLS_MULTI +#define ETHERTYPE_MPLS_MULTI 0x8848 +#endif #ifndef ETHERTYPE_PPPOED #define ETHERTYPE_PPPOED 0x8863 #endif diff --git a/contrib/tcpdump/extract.h b/contrib/tcpdump/extract.h index 9e5bb9b..861f06f 100644 --- a/contrib/tcpdump/extract.h +++ b/contrib/tcpdump/extract.h @@ -18,40 +18,40 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: /tcpdump/master/tcpdump/extract.h,v 1.16 2000/10/03 02:54:55 itojun Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/extract.h,v 1.17 2001/09/17 21:57:52 fenner Exp $ (LBL) */ /* Network to host order macros */ #ifdef LBL_ALIGN #define EXTRACT_16BITS(p) \ - ((u_int16_t)*((u_int8_t *)(p) + 0) << 8 | \ - (u_int16_t)*((u_int8_t *)(p) + 1)) + ((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ + (u_int16_t)*((const u_int8_t *)(p) + 1)) #define EXTRACT_32BITS(p) \ - ((u_int32_t)*((u_int8_t *)(p) + 0) << 24 | \ - (u_int32_t)*((u_int8_t *)(p) + 1) << 16 | \ - (u_int32_t)*((u_int8_t *)(p) + 2) << 8 | \ - (u_int32_t)*((u_int8_t *)(p) + 3)) + ((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \ + (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \ + (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \ + (u_int32_t)*((const u_int8_t *)(p) + 3)) #else #define EXTRACT_16BITS(p) \ - ((u_int16_t)ntohs(*(u_int16_t *)(p))) + ((u_int16_t)ntohs(*(const u_int16_t *)(p))) #define EXTRACT_32BITS(p) \ - ((u_int32_t)ntohl(*(u_int32_t *)(p))) + ((u_int32_t)ntohl(*(const u_int32_t *)(p))) #endif #define EXTRACT_24BITS(p) \ - ((u_int32_t)*((u_int8_t *)(p) + 0) << 16 | \ - (u_int32_t)*((u_int8_t *)(p) + 1) << 8 | \ - (u_int32_t)*((u_int8_t *)(p) + 2)) + ((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \ + (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ + (u_int32_t)*((const u_int8_t *)(p) + 2)) /* Little endian protocol host order macros */ #define EXTRACT_LE_8BITS(p) (*(p)) #define EXTRACT_LE_16BITS(p) \ - ((u_int16_t)*((u_int8_t *)(p) + 1) << 8 | \ - (u_int16_t)*((u_int8_t *)(p) + 0)) + ((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \ + (u_int16_t)*((const u_int8_t *)(p) + 0)) #define EXTRACT_LE_32BITS(p) \ - ((u_int32_t)*((u_int8_t *)(p) + 3) << 24 | \ - (u_int32_t)*((u_int8_t *)(p) + 2) << 16 | \ - (u_int32_t)*((u_int8_t *)(p) + 1) << 8 | \ - (u_int32_t)*((u_int8_t *)(p) + 0)) + ((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \ + (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \ + (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ + (u_int32_t)*((const u_int8_t *)(p) + 0)) diff --git a/contrib/tcpdump/icmp6.h b/contrib/tcpdump/icmp6.h index 7f66c2e..49b8cfa 100644 --- a/contrib/tcpdump/icmp6.h +++ b/contrib/tcpdump/icmp6.h @@ -1,4 +1,4 @@ -/* @(#) $Header: /tcpdump/master/tcpdump/icmp6.h,v 1.4 2000/12/17 23:13:32 guy Exp $ (LBL) */ +/* @(#) $Header: /tcpdump/master/tcpdump/icmp6.h,v 1.11 2001/06/01 23:01:04 itojun Exp $ (LBL) */ /* $NetBSD: icmp6.h,v 1.13 2000/08/03 16:30:37 itojun Exp $ */ /* $KAME: icmp6.h,v 1.22 2000/08/03 15:25:16 jinmei Exp $ */ @@ -198,6 +198,19 @@ struct nd_router_advert { /* router advertisement */ #define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1] #define ND_RA_FLAG_MANAGED 0x80 #define ND_RA_FLAG_OTHER 0x40 +#define ND_RA_FLAG_HOME_AGENT 0x20 + +/* + * Router preference values based on draft-draves-ipngwg-router-selection-01. + * These are non-standard definitions. + */ +#define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */ + +#define ND_RA_FLAG_RTPREF_HIGH 0x08 /* 00001000 */ +#define ND_RA_FLAG_RTPREF_MEDIUM 0x00 /* 00000000 */ +#define ND_RA_FLAG_RTPREF_LOW 0x18 /* 00011000 */ +#define ND_RA_FLAG_RTPREF_RSV 0x10 /* 00010000 */ + #define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1] struct nd_neighbor_solicit { /* neighbor solicitation */ @@ -249,7 +262,10 @@ struct nd_opt_hdr { /* Neighbor discovery option header */ #define ND_OPT_PREFIX_INFORMATION 3 #define ND_OPT_REDIRECTED_HEADER 4 #define ND_OPT_MTU 5 -#define ND_OPT_ADVINT 7 +#define ND_OPT_ADVINTERVAL 7 +#define ND_OPT_HOMEAGENT_INFO 8 +#define ND_OPT_ROUTE_INFO 9 /* draft-ietf-ipngwg-router-preference, not officially assigned yet */ + struct nd_opt_prefix_info { /* prefix information */ u_int8_t nd_opt_pi_type; @@ -281,11 +297,28 @@ struct nd_opt_mtu { /* MTU option */ u_int32_t nd_opt_mtu_mtu; }; -struct nd_opt_advint { /* Advertisement interval option */ - u_int8_t nd_opt_advint_type; - u_int8_t nd_opt_advint_len; - u_int16_t nd_opt_advint_reserved; - u_int32_t nd_opt_advint_advint; +struct nd_opt_advinterval { /* Advertisement interval option */ + u_int8_t nd_opt_adv_type; + u_int8_t nd_opt_adv_len; + u_int16_t nd_opt_adv_reserved; + u_int32_t nd_opt_adv_interval; +}; + +struct nd_opt_homeagent_info { /* Home Agent info */ + u_int8_t nd_opt_hai_type; + u_int8_t nd_opt_hai_len; + u_int16_t nd_opt_hai_reserved; + int16_t nd_opt_hai_preference; + u_int16_t nd_opt_hai_lifetime; +}; + +struct nd_opt_route_info { /* route info */ + u_int8_t nd_opt_rti_type; + u_int8_t nd_opt_rti_len; + u_int8_t nd_opt_rti_prefixlen; + u_int8_t nd_opt_rti_flags; + u_int32_t nd_opt_rti_lifetime; + /* prefix follows */ }; /* @@ -356,7 +389,7 @@ struct icmp6_router_renum { /* router renumbering header */ }; #define ICMP6_RR_FLAGS_TEST 0x80 #define ICMP6_RR_FLAGS_REQRESULT 0x40 -#define ICMP6_RR_FLAGS_ALLIF 0x20 +#define ICMP6_RR_FLAGS_FORCEAPPLY 0x20 #define ICMP6_RR_FLAGS_SPECSITE 0x10 #define ICMP6_RR_FLAGS_PREVDONE 0x08 diff --git a/contrib/tcpdump/ieee802_11.h b/contrib/tcpdump/ieee802_11.h new file mode 100644 index 0000000..cecd0d7 --- /dev/null +++ b/contrib/tcpdump/ieee802_11.h @@ -0,0 +1,244 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/ieee802_11.h,v 1.3 2001/06/14 09:50:01 guy Exp $ (LBL) */ +/* + * Copyright (c) 2001 + * Fortress Technologies + * Charlie Lenahan ( clenahan@fortresstech.com ) + * + * 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. + */ + +#define IEEE802_11_FC_LEN 2 + +#define T_MGMT 0x0 /* management */ +#define T_CTRL 0x1 /* control */ +#define T_DATA 0x2 /* data */ +#define T_RESV 0x3 /* reserved */ + +#define ST_ASSOC_REQUEST 0x0 +#define ST_ASSOC_RESPONSE 0x1 +#define ST_REASSOC_REQUEST 0x2 +#define ST_REASSOC_RESPONSE 0x3 +#define ST_PROBE_REQUEST 0x4 +#define ST_PROBE_RESPONSE 0x5 +/* RESERVED 0x6 */ +/* RESERVED 0x7 */ +#define ST_BEACON 0x8 +#define ST_ATIM 0x9 +#define ST_DISASSOC 0xA +#define ST_AUTH 0xB +#define ST_DEAUTH 0xC +/* RESERVED 0xD */ +/* RESERVED 0xE */ +/* RESERVED 0xF */ + + +#define CTRL_PS_POLL 0xA +#define CTRL_RTS 0xB +#define CTRL_CTS 0xC +#define CTRL_ACK 0xD +#define CTRL_CF_END 0xE +#define CTRL_END_ACK 0xF + +/* + * Bits in the frame control field. + */ +#define FC_VERSION(fc) ((fc) & 0x3) +#define FC_TYPE(fc) (((fc) >> 2) & 0x3) +#define FC_SUBTYPE(fc) (((fc) >> 4) & 0xF) +#define FC_TO_DS(fc) ((fc) & 0x0100) +#define FC_FROM_DS(fc) ((fc) & 0x0200) +#define FC_MORE_FLAG(fc) ((fc) & 0x0400) +#define FC_RETRY(fc) ((fc) & 0x0800) +#define FC_POWER_MGMT(fc) ((fc) & 0x1000) +#define FC_MORE_DATA(fc) ((fc) & 0x2000) +#define FC_WEP(fc) ((fc) & 0x4000) +#define FC_ORDER(fc) ((fc) & 0x8000) + +struct mgmt_header_t { + u_int16_t fc; + u_int16_t duration; + u_int8_t da[6]; + u_int8_t sa[6]; + u_int8_t bssid[6]; + u_int16_t seq_ctrl; +}; + +#define MGMT_HEADER_LEN (2+2+6+6+6+2) + +#define CAPABILITY_ESS(cap) ((cap) & 0x0001) +#define CAPABILITY_IBSS(cap) ((cap) & 0x0002) +#define CAPABILITY_CFP(cap) ((cap) & 0x0004) +#define CAPABILITY_CFP_REQ(cap) ((cap) & 0x0008) +#define CAPABILITY_PRIVACY(cap) ((cap) & 0x0010) + +struct ssid_t { + u_int8_t element_id; + u_int8_t length; + u_char ssid[33]; /* 32 + 1 for null */ +} ; + +struct rates_t { + u_int8_t element_id; + u_int8_t length; + u_int8_t rate[8]; +}; + +struct challenge_t { + u_int8_t element_id; + u_int8_t length; + u_int8_t text[254]; /* 1-253 + 1 for null */ +}; +struct fh_t { + u_int8_t element_id; + u_int8_t length; + u_int16_t dwell_time; + u_int8_t hop_set; + u_int8_t hop_pattern; + u_int8_t hop_index; +}; + +struct ds_t { + u_int8_t element_id; + u_int8_t length; + u_int8_t channel; +}; + +struct cf_t { + u_int8_t element_id; + u_int8_t length; + u_int8_t count; + u_int8_t period; + u_int16_t max_duration; + u_int16_t dur_remaing; +}; + +struct tim_t { + u_int8_t element_id; + u_int8_t length; + u_int8_t count; + u_int8_t period; + u_int8_t bitmap_control; + u_int8_t bitmap[251]; +}; + +#define E_SSID 0 +#define E_RATES 1 +#define E_FH 2 +#define E_DS 3 +#define E_CF 4 +#define E_TIM 5 +#define E_IBSS 6 +/* reserved 7 */ +/* reserved 8 */ +/* reserved 9 */ +/* reserved 10 */ +/* reserved 11 */ +/* reserved 12 */ +/* reserved 13 */ +/* reserved 14 */ +/* reserved 15 */ +/* reserved 16 */ + +#define E_CHALLENGE 16 +/* reserved 17 */ +/* reserved 18 */ +/* reserved 19 */ +/* reserved 16 */ +/* reserved 16 */ + + +struct mgmt_body_t { + u_int8_t timestamp[8]; + u_int16_t beacon_interval; + u_int16_t listen_interval; + u_int16_t status_code; + u_int16_t aid; + u_char ap[6]; + u_int16_t reason_code; + u_int16_t auth_alg; + u_int16_t auth_trans_seq_num; + struct challenge_t challenge; + u_int16_t capability_info; + struct ssid_t ssid; + struct rates_t rates; + struct ds_t ds; + struct cf_t cf; + struct fh_t fh; + struct tim_t tim; +}; + +struct ctrl_rts_t { + u_int16_t fc; + u_int16_t duration; + u_int8_t ra[6]; + u_int8_t ta[6]; + u_int8_t fcs[4]; +}; + +#define CTRL_RTS_LEN (2+2+6+6+4) + +struct ctrl_cts_t { + u_int16_t fc; + u_int16_t duration; + u_int8_t ra[6]; + u_int8_t fcs[4]; +}; + +#define CTRL_CTS_LEN (2+2+6+4) + +struct ctrl_ack_t { + u_int16_t fc; + u_int16_t duration; + u_int8_t ra[6]; + u_int8_t fcs[4]; +}; + +#define CTRL_ACK_LEN (2+2+6+4) + +struct ctrl_ps_poll_t { + u_int16_t fc; + u_int16_t aid; + u_int8_t bssid[6]; + u_int8_t ta[6]; + u_int8_t fcs[4]; +}; + +#define CTRL_PS_POLL_LEN (2+2+6+6+4) + +struct ctrl_end_t { + u_int16_t fc; + u_int16_t duration; + u_int8_t ra[6]; + u_int8_t bssid[6]; + u_int8_t fcs[4]; +}; + +#define CTRL_END_LEN (2+2+6+6+4) + +struct ctrl_end_ack_t { + u_int16_t fc; + u_int16_t duration; + u_int8_t ra[6]; + u_int8_t bssid[6]; + u_int8_t fcs[4]; +}; + +#define CTRL_END_ACK_LEN (2+2+6+6+4) + +#define IV_IV(iv) ((iv) & 0xFFFFFF) +#define IV_PAD(iv) (((iv) >> 24) & 0x3F) +#define IV_KEYID(iv) (((iv) >> 30) & 0x03) diff --git a/contrib/tcpdump/interface.h b/contrib/tcpdump/interface.h index 89b05d5..8e19062 100644 --- a/contrib/tcpdump/interface.h +++ b/contrib/tcpdump/interface.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 + * Copyright (c) 1988-2002 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.149 2001/01/02 22:47:06 guy Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.178 2002/01/21 11:39:58 mcr Exp $ (LBL) */ #ifndef tcpdump_interface_h @@ -39,25 +39,29 @@ #include <stdarg.h> #if !defined(HAVE_SNPRINTF) -int snprintf (char *str, size_t sz, const char *format, ...) - __attribute__ ((format (printf, 3, 4))); +int snprintf(char *, size_t, const char *, ...) + __attribute__((format(printf, 3, 4))); #endif #if !defined(HAVE_VSNPRINTF) -int vsnprintf (char *str, size_t sz, const char *format, va_list ap) - __attribute__((format (printf, 3, 0))); +int vsnprintf(char *, size_t, const char *, va_list) + __attribute__((format(printf, 3, 0))); #endif #ifndef HAVE_STRLCAT -extern size_t strlcat (char *, const char *, size_t); +extern size_t strlcat(char *, const char *, size_t); #endif #ifndef HAVE_STRLCPY -extern size_t strlcpy (char *, const char *, size_t); +extern size_t strlcpy(char *, const char *, size_t); +#endif + +#ifndef HAVE_STRDUP +extern char *strdup(const char *); #endif struct tok { int v; /* value */ - char *s; /* string */ + const char *s; /* string */ }; extern int aflag; /* translate network and broadcast addresses */ @@ -77,6 +81,8 @@ extern int xflag; /* print packet in hex */ extern int Xflag; /* print packet in hex/ascii */ extern char *espsecret; +extern struct esp_algorithm *espsecret_xform; /* cache of decoded alg. */ +extern char *espsecret_key; extern int packettype; /* as specified by -T */ #define PT_VAT 1 /* Visual Audio Tool */ @@ -94,16 +100,14 @@ extern int packettype; /* as specified by -T */ #define max(a,b) ((b)>(a)?(b):(a)) #endif -#ifndef INET6 /* * The default snapshot length. This value allows most printers to print * useful information while keeping the amount of unwanted data down. - * In particular, it allows for an ethernet header, tcp/ip header, and - * 14 bytes of data (assuming no ip options). */ -#define DEFAULT_SNAPLEN 68 +#ifndef INET6 +#define DEFAULT_SNAPLEN 68 /* ether + IPv4 + TCP + 14 */ #else -#define DEFAULT_SNAPLEN 96 +#define DEFAULT_SNAPLEN 96 /* ether + IPv6 + TCP + 22 */ #endif #ifndef BIG_ENDIAN @@ -132,7 +136,7 @@ extern const u_char *packetp; extern const u_char *snapend; /* True if "l" bytes of "var" were captured */ -#define TTEST2(var, l) ((u_char *)&(var) <= snapend - (l)) +#define TTEST2(var, l) ((const u_char *)&(var) <= snapend - (l)) /* True if "var" was captured */ #define TTEST(var) TTEST2(var, sizeof(var)) @@ -143,17 +147,20 @@ extern const u_char *snapend; /* Bail if "var" was not captured */ #define TCHECK(var) TCHECK2(var, sizeof(var)) -struct timeval; - extern void ts_print(const struct timeval *); extern void relts_print(int); extern int fn_print(const u_char *, const u_char *); extern int fn_printn(const u_char *, u_int, const u_char *); extern const char *tok2str(const struct tok *, const char *, int); -extern char *dnaddr_string(u_short); +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 const char *dnaddr_string(u_short); -extern void wrapup(int); +extern void info(int); +extern int infodelay; +extern int infoprint; extern void error(const char *, ...) __attribute__((noreturn, format (printf, 1, 2))); @@ -165,15 +172,16 @@ extern char *copy_argv(char **); extern void safeputchar(int); extern void safeputs(const char *); -extern char *isonsap_string(const u_char *); -extern char *llcsap_string(u_char); -extern char *protoid_string(const u_char *); -extern char *dnname_string(u_short); -extern char *dnnum_string(u_short); +extern const char *isonsap_string(const u_char *); +extern const char *llcsap_string(u_char); +extern const char *protoid_string(const u_char *); +extern const char *ipxsap_string(u_short); +extern const char *dnname_string(u_short); +extern const char *dnnum_string(u_short); /* The printer routines. */ -struct pcap_pkthdr; +#include <pcap.h> extern void ascii_print_with_offset(const u_char *, u_int, u_int); extern void ascii_print(const u_char *, u_int); @@ -189,21 +197,25 @@ extern void atalk_print(const u_char *, u_int); extern void atm_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); extern void bootp_print(const u_char *, u_int, u_short, u_short); extern void bgp_print(const u_char *, int); -extern void bxxp_print(const u_char *, u_int); -extern void cnfp_print(const u_char *cp, u_int len, const u_char *bp); +extern void beep_print(const u_char *, u_int); +extern void cnfp_print(const u_char *, u_int, const u_char *); extern void decnet_print(const u_char *, u_int, u_int); extern void default_print(const u_char *, u_int); extern void default_print_unaligned(const u_char *, u_int); extern void dvmrp_print(const u_char *, u_int); extern void egp_print(const u_char *, u_int, const u_char *); +extern void arcnet_if_print(u_char *, const struct pcap_pkthdr *, + const u_char *); extern void ether_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); extern void token_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); extern void fddi_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); +extern void ieee802_11_if_print(u_char *, const struct pcap_pkthdr *, + const u_char *); extern void gre_print(const u_char *, u_int); extern void icmp_print(const u_char *, u_int, const u_char *); -extern void igmp_print(const u_char *, u_int, const u_char *); +extern void igmp_print(const u_char *, u_int); extern void igrp_print(const u_char *, u_int, const u_char *); extern void ip_print(const u_char *, u_int); extern void ipN_print(const u_char *, u_int); @@ -212,6 +224,9 @@ extern void isoclns_print(const u_char *, u_int, u_int, const u_char *, const u_char *); extern void krb_print(const u_char *, u_int); extern void llap_print(const u_char *, u_int); +extern void ltalk_if_print(u_char *, const struct pcap_pkthdr *, + const u_char *); +extern void msdp_print(const unsigned char *, u_int); extern void nfsreply_print(const u_char *, u_int, const u_char *); extern void nfsreq_print(const u_char *, u_int, const u_char *); extern void ns_print(const u_char *, u_int); @@ -229,6 +244,8 @@ extern void ppp_hdlc_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); extern void ppp_bsdos_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); +extern void pppoe_if_print(u_char *, const struct pcap_pkthdr *, + const u_char *); extern int vjc_print(register const char *, register u_int, u_short); extern void raw_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); extern void rip_print(const u_char *, u_int); @@ -239,6 +256,7 @@ extern void sl_bsdos_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); extern void chdlc_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); +extern void chdlc_print(register const u_char *, u_int, u_int); extern void sll_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); extern void snmp_print(const u_char *, u_int); extern void sunrpcrequest_print(const u_char *, u_int, const u_char *); @@ -248,35 +266,47 @@ extern void timed_print(const u_char *, u_int); extern void udp_print(const u_char *, u_int, const u_char *, int); extern void wb_print(const void *, u_int); extern int ah_print(register const u_char *, register const u_char *); -extern int esp_print(register const u_char *, register const u_char *, int *); +extern int esp_print(register const u_char *, register const u_char *, int *, int *); extern void isakmp_print(const u_char *, u_int, const u_char *); extern int ipcomp_print(register const u_char *, register const u_char *, int *); extern void rx_print(register const u_char *, int, int, int, u_char *); -extern void netbeui_print(u_short, const u_char *, const u_char *); -extern void ipx_netbios_print(const u_char *, const u_char *); +extern void netbeui_print(u_short, const u_char *, int); +extern void ipx_netbios_print(const u_char *, u_int); extern void nbt_tcp_print(const u_char *, int); -extern void nbt_udp137_print(const u_char *data, int); -extern void nbt_udp138_print(const u_char *data, int); +extern void nbt_udp137_print(const u_char *, int); +extern void nbt_udp138_print(const u_char *, int); extern char *smb_errstr(int, int); extern void print_data(const unsigned char *, int); extern void l2tp_print(const u_char *, u_int); extern void lcp_print(const u_char *, u_int); -extern void vrrp_print(const u_char *bp, u_int len, int ttl); -extern void cdp_print(const u_char *p, u_int length, u_int caplen, - const u_char *esrc, const u_char *edst); -extern void stp_print(const u_char *p, u_int length); +extern void vrrp_print(const u_char *, u_int, int); +extern void cdp_print(const u_char *, u_int, u_int, const u_char *, + const u_char *); +extern void stp_print(const u_char *, u_int); extern void radius_print(const u_char *, u_int); +extern void lwres_print(const u_char *, u_int); +extern void pptp_print(const u_char *, u_int); +extern void sctp_print(const u_char *, const u_char *, u_int); +extern void mpls_print(const u_char *, u_int); +extern void zephyr_print(const u_char *, int); +extern void hsrp_print(const u_char *, u_int); #ifdef INET6 -extern void ip6_print(const u_char *, int); +extern void ip6_print(const u_char *, u_int); extern void ip6_opt_print(const u_char *, int); extern int hbhopt_print(const u_char *); extern int dstopt_print(const u_char *); extern int frag6_print(const u_char *, const u_char *); extern void icmp6_print(const u_char *, const u_char *); -extern void ripng_print(const u_char *, int); +extern void ripng_print(const u_char *, unsigned int); extern int rt6_print(const u_char *, const u_char *); extern void ospf6_print(const u_char *, u_int); extern void dhcp6_print(const u_char *, u_int, u_int16_t, u_int16_t); #endif /*INET6*/ -extern u_short in_cksum(const u_short *addr, register int len, u_short csum); +extern u_short in_cksum(const u_short *, register u_int, int); + +#ifndef HAVE_BPF_DUMP +struct bpf_program; + +extern void bpf_dump(struct bpf_program *, int); +#endif diff --git a/contrib/tcpdump/ipx.h b/contrib/tcpdump/ipx.h index c65582a..a0dca0c 100644 --- a/contrib/tcpdump/ipx.h +++ b/contrib/tcpdump/ipx.h @@ -1,7 +1,7 @@ /* * IPX protocol formats * - * @(#) $Header: /tcpdump/master/tcpdump/ipx.h,v 1.2 2000/10/03 02:54:56 itojun Exp $ + * @(#) $Header: /tcpdump/master/tcpdump/ipx.h,v 1.4 2001/01/15 03:23:59 guy Exp $ */ /* well-known sockets */ @@ -10,6 +10,8 @@ #define IPX_SKT_RIP 0x0453 #define IPX_SKT_NETBIOS 0x0455 #define IPX_SKT_DIAGNOSTICS 0x0456 +#define IPX_SKT_NWLINK_DGM 0x0553 /* NWLink datagram, may contain SMB */ +#define IPX_SKT_EIGRP 0x85be /* Cisco EIGRP over IPX */ /* IPX transport header */ struct ipxHdr { diff --git a/contrib/tcpdump/l2tp.h b/contrib/tcpdump/l2tp.h index 5c8f98d..1568883 100644 --- a/contrib/tcpdump/l2tp.h +++ b/contrib/tcpdump/l2tp.h @@ -1,4 +1,4 @@ -/* @(#) $Header: /tcpdump/master/tcpdump/l2tp.h,v 1.4 2000/12/17 23:07:49 guy Exp $ (LBL) */ +/* @(#) $Header: /tcpdump/master/tcpdump/l2tp.h,v 1.5 2001/11/05 10:03:27 guy Exp $ (LBL) */ /* * Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997 * The Regents of the University of California. All rights reserved. @@ -55,29 +55,8 @@ #define L2TP_AUTHEN_TYPE_CHAP 0x0002 /* PPP CHAP */ #define L2TP_AUTHEN_TYPE_PAP 0x0003 /* PPP PAP */ #define L2TP_AUTHEN_TYPE_NO_AUTH 0x0004 /* No Authentication */ -#define L2TP_AUTHEN_TYPE_MSCHAP 0x0005 /* MSCHAPv1 */ +#define L2TP_AUTHEN_TYPE_MSCHAPv1 0x0005 /* MSCHAPv1 */ #define L2TP_PROXY_AUTH_ID_MASK 0x00ff -struct l2tp_avp_vec { - const char *name; - void (*print)(const u_char *, u_int32_t); -}; - -struct l2tp_call_errors { - u_int16_t reserved; - u_int32_t crc_errs; - u_int32_t framing_errs; - u_int32_t hardware_overruns; - u_int32_t buffer_overruns; - u_int32_t timeout_errs; - u_int32_t alignment_errs; -}; - -struct l2tp_accm { - u_int16_t reserved; - u_int32_t send_accm; - u_int32_t recv_accm; -}; - diff --git a/contrib/tcpdump/llc.h b/contrib/tcpdump/llc.h index 5f0b981..6485d77 100644 --- a/contrib/tcpdump/llc.h +++ b/contrib/tcpdump/llc.h @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: /tcpdump/master/tcpdump/llc.h,v 1.8 2000/12/18 07:55:36 guy Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/llc.h,v 1.13 2001/06/04 05:47:13 guy Exp $ (LBL) */ /* @@ -51,8 +51,8 @@ struct llc { #define llcui ctl.snap.snap_ui #define llcpi ctl.snap.snap_pi -#define orgcode ctl.snap_ether.snap_orgcode -#define ethertype ctl.snap_ether.snap_ethertype +#define llc_orgcode ctl.snap_ether.snap_orgcode +#define llc_ethertype ctl.snap_ether.snap_ethertype #define llcis ctl.is_ctl #define llcu ctl.u_ctl @@ -88,10 +88,10 @@ struct llc { #ifndef LLCSAP_GLOBAL #define LLCSAP_GLOBAL 0xff #endif -#ifndef LLCSAP_8021B +#ifndef LLCSAP_8021B_I #define LLCSAP_8021B_I 0x02 #endif -#ifndef LLCSAP_8021B +#ifndef LLCSAP_8021B_G #define LLCSAP_8021B_G 0x03 #endif #ifndef LLCSAP_IP @@ -115,6 +115,18 @@ struct llc { #ifndef LLCSAP_SNAP #define LLCSAP_SNAP 0xaa #endif +#ifndef LLCSAP_IPX +#define LLCSAP_IPX 0xe0 +#endif +#ifndef LLCSAP_NETBEUI +#define LLCSAP_NETBEUI 0xf0 +#endif #ifndef LLCSAP_ISONS #define LLCSAP_ISONS 0xfe #endif + +#define OUI_ENCAP_ETHER 0x000000 /* encapsulated Ethernet */ +#define OUI_CISCO 0x00000c /* Cisco protocols */ +#define ETHERTYPE_CISCO_CDP 0x2000 /* Cisco Discovery Protocol */ +#define OUI_CISCO_90 0x0000f8 /* Cisco bridging */ +#define OUI_APPLETALK 0x080007 /* Appletalk */ diff --git a/contrib/tcpdump/machdep.c b/contrib/tcpdump/machdep.c index 3080f85..e86a84d 100644 --- a/contrib/tcpdump/machdep.c +++ b/contrib/tcpdump/machdep.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/machdep.c,v 1.6 2000/01/17 06:24:23 itojun Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/machdep.c,v 1.7 2001/06/27 05:42:04 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -32,7 +32,16 @@ static const char rcsid[] = #ifdef __osf__ #include <sys/sysinfo.h> #include <sys/proc.h> -#endif + +#if !defined(HAVE_SNPRINTF) +#ifndef HAVE___ATTRIBUTE__ +#define __attribute__(x) +#endif /* HAVE___ATTRIBUTE__ */ + +int snprintf(char *, size_t, const char *, ...) + __attribute__((format(printf, 3, 4))); +#endif /* !defined(HAVE_SNPRINTF) */ +#endif /* __osf__ */ #include "machdep.h" diff --git a/contrib/tcpdump/makemib b/contrib/tcpdump/makemib index 8516263..2c80bef 100755 --- a/contrib/tcpdump/makemib +++ b/contrib/tcpdump/makemib @@ -1,20 +1,33 @@ #!/bin/sh # -# Copyright (c) 1990, 1996, by John Robert LoVerso. -# All rights reserved. -# SMIv2 parsing copyright (c) 1999 by William C. Fenner. -# -# Redistribution and use in source and binary forms are permitted -# provided that the above copyright notice and this paragraph are -# duplicated in all such forms and that any documentation, -# advertising materials, and other materials related to such -# distribution and use acknowledge that the software was developed -# by John Robert LoVerso. -# 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. -# -# @(#) $Id: makemib,v 1.2 1999/11/21 17:24:15 fenner Exp $ (jlv) +# Copyright (c) 1990, 1996 +# John Robert LoVerso. All rights reserved. +# SMIv2 parsing copyright (c) 1999 +# William C. Fenner. +# +# 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 +# notices, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notices, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 AUTHORS 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. +# +# @(#) $Id: makemib,v 1.3 2001/09/17 22:16:52 fenner Exp $ (jlv) # # This script will read either ASN.1-style MIB files or the ".defs" files diff --git a/contrib/tcpdump/missing/snprintf.c b/contrib/tcpdump/missing/snprintf.c index 176636f..1d4ab71 100644 --- a/contrib/tcpdump/missing/snprintf.c +++ b/contrib/tcpdump/missing/snprintf.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. */ -/* $Id: snprintf.c,v 1.4 2001/01/02 22:33:04 guy Exp $ */ +/* $Id: snprintf.c,v 1.5 2001/01/12 10:14:40 guy Exp $ */ #ifdef HAVE_CONFIG_H #include <config.h> @@ -39,7 +39,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/missing/snprintf.c,v 1.4 2001/01/02 22:33:04 guy Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/missing/snprintf.c,v 1.5 2001/01/12 10:14:40 guy Exp $"; #endif #include <stdio.h> @@ -93,6 +93,7 @@ sn_append_char (struct state *state, unsigned char c) } #endif +#if 0 static int as_reserve (struct state *state, size_t n) { @@ -126,6 +127,7 @@ as_append_char (struct state *state, unsigned char c) return 0; } } +#endif static int append_number(struct state *state, @@ -490,6 +492,7 @@ snprintf (char *str, size_t sz, const char *format, ...) } #endif +#if 0 #ifndef HAVE_ASPRINTF int asprintf (char **ret, const char *format, ...) @@ -600,6 +603,7 @@ vasnprintf (char **ret, size_t max_sz, const char *format, va_list args) } } #endif +#endif #ifndef HAVE_VSNPRINTF int diff --git a/contrib/tcpdump/missing/strdup.c b/contrib/tcpdump/missing/strdup.c new file mode 100644 index 0000000..103c3b2 --- /dev/null +++ b/contrib/tcpdump/missing/strdup.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 1988, 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/missing/strdup.c,v 1.1 2001/01/20 07:26:08 guy Exp $ (LBL)"; +#endif /* LIBC_SCCS and not lint */ + +#include <stddef.h> +#include <stdlib.h> +#include <string.h> + +#include "interface.h" + +char * +strdup(str) + const char *str; +{ + size_t len; + char *copy; + + len = strlen(str) + 1; + if ((copy = malloc(len)) == NULL) + return (NULL); + memcpy(copy, str, len); + return (copy); +} diff --git a/contrib/tcpdump/nameser.h b/contrib/tcpdump/nameser.h index 9963dd0..b8e157d 100644 --- a/contrib/tcpdump/nameser.h +++ b/contrib/tcpdump/nameser.h @@ -1,4 +1,4 @@ -/* @(#) $Header: /tcpdump/master/tcpdump/nameser.h,v 1.5 2000/12/28 20:30:41 itojun Exp $ (LBL) */ +/* @(#) $Header: /tcpdump/master/tcpdump/nameser.h,v 1.9 2001/06/27 05:40:16 guy Exp $ (LBL) */ /* * Copyright (c) 1983, 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -96,6 +96,23 @@ #define ZONEREF 0xf /* incremental zone referesh */ /* + * Undefine various #defines from various System V-flavored OSes (Solaris, + * SINIX, HP-UX) so the compiler doesn't whine that we redefine them. + */ +#ifdef T_NULL +#undef T_NULL +#endif +#ifdef T_OPT +#undef T_OPT +#endif +#ifdef T_UNSPEC +#undef T_UNSPEC +#endif +#ifdef NOERROR +#undef NOERROR +#endif + +/* * Currently defined response codes */ #define NOERROR 0 /* no error */ @@ -128,14 +145,36 @@ #define T_TXT 16 /* text strings */ #define T_RP 17 /* responsible person */ #define T_AFSDB 18 /* AFS cell database */ +#define T_X25 19 /* X_25 calling address */ +#define T_ISDN 20 /* ISDN calling address */ +#define T_RT 21 /* router */ #define T_NSAP 22 /* NSAP address */ #define T_NSAP_PTR 23 /* reverse lookup for NSAP */ +#define T_SIG 24 /* security signature */ +#define T_KEY 25 /* security key */ +#define T_PX 26 /* X.400 mail mapping */ +#define T_GPOS 27 /* geographical position (withdrawn) */ +#define T_AAAA 28 /* IP6 Address */ +#define T_LOC 29 /* Location Information */ +#define T_NXT 30 /* Next Valid Name in Zone */ +#define T_EID 31 /* Endpoint identifier */ +#define T_NIMLOC 32 /* Nimrod locator */ +#define T_SRV 33 /* Server selection */ +#define T_ATMA 34 /* ATM Address */ +#define T_NAPTR 35 /* Naming Authority PoinTeR */ +#define T_A6 38 /* IP6 address */ +#define T_DNAME 39 /* non-terminal redirection */ +#define T_OPT 41 /* EDNS0 option (meta-RR) */ /* non standard */ #define T_UINFO 100 /* user (finger) information */ #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 */ /* Query type values which do not appear in resource records */ +#define T_TKEY 249 /* Transaction Key [RFC2930] */ +#define T_TSIG 250 /* Transaction Signature [RFC2845] */ +#define T_IXFR 251 /* incremental transfer [RFC1995] */ #define T_AXFR 252 /* transfer zone of authority */ #define T_MAILB 253 /* transfer mailbox records */ #define T_MAILA 254 /* transfer mail agent records */ diff --git a/contrib/tcpdump/nfsfh.h b/contrib/tcpdump/nfsfh.h index 8160d0f..0d58fe6 100644 --- a/contrib/tcpdump/nfsfh.h +++ b/contrib/tcpdump/nfsfh.h @@ -1,12 +1,45 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/nfsfh.h,v 1.12 2001/09/17 21:57:52 fenner Exp $ (LBL) */ + /* - * $Header: /tcpdump/master/tcpdump/nfsfh.h,v 1.9 2000/06/01 01:16:36 assar Exp $ + * Copyright (c) 1993, 1994 Jeffrey C. Mogul, Digital Equipment Corporation, + * Western Research Laboratory. All rights reserved. + * Copyright (c) 2001 Compaq Computer Corporation. All rights reserved. + * + * Permission to use, copy, and modify this software and its + * documentation is hereby granted only under the following terms and + * conditions. Both the above copyright notice and this permission + * notice must appear in all copies of the software, derivative works + * or modified versions, and any portions thereof, and both notices + * must appear in supporting documentation. * + * 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. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND COMPAQ COMPUTER CORPORATION + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO + * EVENT SHALL COMPAQ COMPUTER CORPORATION BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +/* * nfsfh.h - NFS file handle definitions (for portable use) * * Jeffrey C. Mogul * Digital Equipment Corporation * Western Research Laboratory - * $NetBSD: nfsfh.h,v 1.1.1.2 1997/10/03 17:25:13 christos Exp $ */ + */ /* * Internal representation of dev_t, because different NFS servers @@ -32,4 +65,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(caddr_t *, int, my_fsid *, ino_t *, char **, char **, int); +extern void Parse_fh(caddr_t *, int, my_fsid *, ino_t *, const char **, const char **, int); diff --git a/contrib/tcpdump/parsenfsfh.c b/contrib/tcpdump/parsenfsfh.c index 0f4c3a5..086ad5f 100644 --- a/contrib/tcpdump/parsenfsfh.c +++ b/contrib/tcpdump/parsenfsfh.c @@ -1,4 +1,37 @@ /* + * Copyright (c) 1993, 1994 Jeffrey C. Mogul, Digital Equipment Corporation, + * Western Research Laboratory. All rights reserved. + * Copyright (c) 2001 Compaq Computer Corporation. All rights reserved. + * + * Permission to use, copy, and modify this software and its + * documentation is hereby granted only under the following terms and + * conditions. Both the above copyright notice and this permission + * notice must appear in all copies of the software, derivative works + * or modified versions, and any portions thereof, and both notices + * must appear in supporting documentation. + * + * 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. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND COMPAQ COMPUTER CORPORATION + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO + * EVENT SHALL COMPAQ COMPUTER CORPORATION BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +/* * parsenfsfh.c - portable parser for NFS file handles * uses all sorts of heuristics * @@ -9,7 +42,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/parsenfsfh.c,v 1.18 2000/07/01 03:39:00 assar Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/parsenfsfh.c,v 1.23 2001/09/17 21:57:53 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -83,8 +116,8 @@ register caddr_t *fh; int len; my_fsid *fsidp; ino_t *inop; -char **osnamep; /* if non-NULL, return OS name here */ -char **fsnamep; /* if non-NULL, return server fs name here (for VMS) */ +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 unsigned char *fhp = (unsigned char *)fh; @@ -369,17 +402,15 @@ int ourself; /* true if file handle was generated on this host */ case FHT_UNKNOWN: #ifdef DEBUG /* XXX debugging */ - int i; for (i = 0; i < 32; i++) (void)fprintf(stderr, "%x.", fhp[i]); (void)fprintf(stderr, "\n"); #endif - /* XXX for now, give "bogus" values to aid debugging */ - /* Save the actual handle, so it can be display with -u */ for (i = 0; i < 32; i++) - (void)sprintf(&(fsidp->Opaque_Handle[i*2]), "%.2X", fhp[i]); + (void)snprintf(&(fsidp->Opaque_Handle[i*2]), 3, "%.2X", fhp[i]); + /* XXX for now, give "bogus" values to aid debugging */ fsidp->fsid_code = 0; fsidp->Fsid_dev.Minor = 257; fsidp->Fsid_dev.Major = 257; diff --git a/contrib/tcpdump/ppp.h b/contrib/tcpdump/ppp.h index 00d3548..7ad4cb0 100644 --- a/contrib/tcpdump/ppp.h +++ b/contrib/tcpdump/ppp.h @@ -1,4 +1,4 @@ -/* @(#) $Header: /tcpdump/master/tcpdump/ppp.h,v 1.11 2000/10/09 01:53:19 guy Exp $ (LBL) */ +/* @(#) $Header: /tcpdump/master/tcpdump/ppp.h,v 1.12 2001/02/04 02:17:55 fenner Exp $ (LBL) */ /* * Point to Point Protocol (PPP) RFC1331 * @@ -33,6 +33,7 @@ #define PPP_STII 0x0033 /* Stream Protocol (ST-II) */ #define PPP_VINES 0x0035 /* Banyan Vines */ #define PPP_IPV6 0x0057 /* IPv6 */ +#define PPP_COMP 0x00fd /* Compressed Datagram */ #define PPP_HELLO 0x0201 /* 802.1d Hello Packets */ #define PPP_LUXCOM 0x0231 /* Luxcom */ diff --git a/contrib/tcpdump/print-802_11.c b/contrib/tcpdump/print-802_11.c new file mode 100644 index 0000000..b9c2bb8 --- /dev/null +++ b/contrib/tcpdump/print-802_11.c @@ -0,0 +1,858 @@ +/* + * Copyright (c) 2001 + * Fortress Technologies, Inc. All rights reserved. + * Charlie Lenahan (clenahan@fortresstech.com) + * + * 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 lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-802_11.c,v 1.6 2001/09/17 21:57:53 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/socket.h> + +#include <netinet/in.h> + +#include <stdio.h> +#include <pcap.h> +#include <string.h> + +#include "interface.h" +#include "addrtoname.h" +#include "ethertype.h" + +#include "extract.h" + +#include "ieee802_11.h" + +#define RATEStoBUF(p, buf) \ +do { \ + int z = 0; \ + for (z = 0 ; z < p.rates.length ; z++) \ + snprintf(buf, sizeof(buf), "%s %2.1f", buf, (.5 * (p.rates.rate[z] & 0x7f))); \ +} while (0) + +static const char *auth_alg_text[]={"Open System","Shared Key","EAP"}; +static const char *subtype_text[]={ + "Assoc Request", + "Assoc Response", + "ReAssoc Request", + "ReAssoc Response", + "Probe Request", + "Probe Response", + "RESERVED", + "RESERVED", + "Beacon", + "ATIM", + "Disassociation", + "Authentication", + "DeAuthentication", + "RESERVED", + "RESERVED" +}; + +static const char *status_text[] = { + "Succesful", /* 0 */ + "Unspecified failure", /* 1 */ + "Reserved", /* 2 */ + "Reserved", /* 3 */ + "Reserved", /* 4 */ + "Reserved", /* 5 */ + "Reserved", /* 6 */ + "Reserved", /* 7 */ + "Reserved", /* 8 */ + "Reserved", /* 9 */ + "Cannot Support all requested capabilities in the Capability Information field", /* 10 */ + "Reassociation denied due to inability to confirm that association exists", /* 11 */ + "Association denied due to reason outside the scope of the standard", /* 12 */ + "Responding station does not support the specified authentication algorithm ", /* 13 */ + "Received an Authentication frame with authentication transaction " \ + "sequence number out of expected sequence", /* 14 */ + "Authentication rejected because of challenge failure", /* 15 */ + "Authentication rejected due to timeout waiting for next frame in sequence", /* 16 */ + "Association denied because AP is unable to handle additional associated stations", /* 17 */ + "Association denied due to requesting station not supporting all of the " \ + "data rates in BSSBasicRateSet parameter", /* 18 */ + NULL +}; + +static const char *reason_text[] = { + "Reserved", /* 0 */ + "Unspecified reason", /* 1 */ + "Previous authentication no longer valid", /* 2 */ + "Deauthenticated because sending station is leaving (or has left) IBSS or ESS", /* 3 */ + "Disassociated due to inactivity", /* 4 */ + "Disassociated because AP is unable to handle all currently associated stations", /* 5 */ + "Class 2 frame receivedfrom nonauthenticated station", /* 6 */ + "Class 3 frame received from nonassociated station", /* 7 */ + "Disassociated because sending station is leaving (or has left) BSS", /* 8 */ + "Station requesting (re)association is not authenticated with responding station", /* 9 */ + NULL +}; + +static int wep_print(const u_char *p,u_int length) +{ + u_int32_t iv; + + if (!TTEST2(*p, 4)) + return 0; + iv = EXTRACT_LE_32BITS(p); + + printf("Data IV:%3x Pad %x KeyID %x", IV_IV(iv), IV_PAD(iv), + IV_KEYID(iv)); + + return 1; +} + + +static int parse_elements(struct mgmt_body_t *pbody,const u_char *p,int offset) +{ + for (;;) { + if (!TTEST2(*(p + offset), 1)) + return 0; + if (*(p + offset) == 0xff) + break; + switch (*(p + offset)) { + case E_SSID: + if (!TTEST2(*(p+offset), 2)) + return 0; + memcpy(&(pbody->ssid),p+offset,2); offset += 2; + if (pbody->ssid.length > 0) + { + if (!TTEST2(*(p+offset), pbody->ssid.length)) + return 0; + memcpy(&(pbody->ssid.ssid),p+offset,pbody->ssid.length); offset += pbody->ssid.length; + pbody->ssid.ssid[pbody->ssid.length]='\0'; + } + break; + case E_CHALLENGE: + if (!TTEST2(*(p+offset), 2)) + return 0; + memcpy(&(pbody->challenge),p+offset,2); offset += 2; + if (pbody->challenge.length > 0) + { + if (!TTEST2(*(p+offset), pbody->challenge.length)) + return 0; + memcpy(&(pbody->challenge.text),p+offset,pbody->challenge.length); offset += pbody->challenge.length; + pbody->challenge.text[pbody->challenge.length]='\0'; + } + break; + case E_RATES: + if (!TTEST2(*(p+offset), 2)) + return 0; + memcpy(&(pbody->rates),p+offset,2); offset += 2; + if (pbody->rates.length > 0) { + if (!TTEST2(*(p+offset), pbody->rates.length)) + return 0; + memcpy(&(pbody->rates.rate),p+offset,pbody->rates.length); offset += pbody->rates.length; + } + break; + case E_DS: + if (!TTEST2(*(p+offset), 3)) + return 0; + memcpy(&(pbody->ds),p+offset,3); offset +=3; + break; + case E_CF: + if (!TTEST2(*(p+offset), 8)) + return 0; + memcpy(&(pbody->cf),p+offset,8); offset +=8; + break; + case E_TIM: + if (!TTEST2(*(p+offset), 2)) + return 0; + memcpy(&(pbody->tim),p+offset,2); offset +=2; + if (!TTEST2(*(p+offset), 3)) + return 0; + memcpy(&(pbody->tim.count),p+offset,3); offset +=3; + + if ((pbody->tim.length -3) > 0) + { + if (!TTEST2(*(p+offset), pbody->tim.length -3)) + return 0; + memcpy((pbody->tim.bitmap),p+(pbody->tim.length -3),(pbody->tim.length -3)); + offset += pbody->tim.length -3; + } + + break; + default: +#if 0 + printf("(1) unhandled element_id (%d) ", *(p+offset) ); +#endif + offset+= *(p+offset+1) + 2; + break; + } + } + return 1; +} + +/********************************************************************************* + * Print Handle functions for the management frame types + *********************************************************************************/ + +static int handle_beacon(u_int16_t fc, const struct mgmt_header_t *pmh, + const u_char *p) +{ + struct mgmt_body_t pbody; + int offset = 0; + char buf[128]; + + memset(buf, 0, sizeof(buf)); + memset(&pbody, 0, sizeof(pbody)); + + if (!TTEST2(*p, 12)) + return 0; + memcpy(&pbody.timestamp, p, 8); + offset += 8; + pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); + offset += 2; + pbody.capability_info = EXTRACT_LE_16BITS(p+offset); + offset += 2; + + if (!parse_elements(&pbody,p,offset)) + return 0; + + RATEStoBUF(pbody, buf); + + printf("%s (%s) [%s Mbit] %s CH: %x %s", + subtype_text[FC_SUBTYPE(fc)], pbody.ssid.ssid, buf, + CAPABILITY_ESS(pbody.capability_info) ? "ESS" : "IBSS", + pbody.ds.channel, + CAPABILITY_PRIVACY(pbody.capability_info) ? ", PRIVACY" : "" ); + + return 1; +} + +static int handle_assoc_request(u_int16_t fc, const struct mgmt_header_t *pmh, + const u_char *p) +{ + struct mgmt_body_t pbody; + int offset = 0; + char buf[128]; + + memset(buf, 0, sizeof(buf)); + memset(&pbody, 0, sizeof(pbody)); + + if (!TTEST2(*p, 4)) + return 0; + pbody.capability_info = EXTRACT_LE_16BITS(p); + offset += 2; + pbody.listen_interval = EXTRACT_LE_16BITS(p+offset); + offset += 2; + + if (!parse_elements(&pbody,p,offset)) + return 0; + + RATEStoBUF(pbody,buf); + + printf("%s (%s) [%s Mbit] ", + subtype_text[FC_SUBTYPE(fc)], pbody.ssid.ssid,buf); + return 1; +} + +static int handle_assoc_response(u_int16_t fc, const struct mgmt_header_t *pmh, + const u_char *p) +{ + struct mgmt_body_t pbody; + int offset = 0; + + memset(&pbody, 0, sizeof(pbody)); + + if (!TTEST2(*p, 6)) + return 0; + pbody.capability_info = EXTRACT_LE_16BITS(p); + offset += 2; + pbody.status_code = EXTRACT_LE_16BITS(p+offset); + offset += 2; + pbody.aid = EXTRACT_LE_16BITS(p+offset); + offset += 2; + + if (!parse_elements(&pbody,p,offset)) + return 0; + + printf("%s AID(%x) :%s: %s ", subtype_text[FC_SUBTYPE(fc)], + ((u_int16_t)(pbody.aid << 2 )) >> 2 , + CAPABILITY_PRIVACY(pbody.capability_info) ? " PRIVACY " : "", + (pbody.status_code < 19 ? status_text[pbody.status_code] : "n/a")); + + return 1; +} + + +static int handle_reassoc_request(u_int16_t fc, const struct mgmt_header_t *pmh, + const u_char *p) +{ + struct mgmt_body_t pbody; + int offset = 0; + + memset(&pbody, 0, sizeof(pbody)); + + if (!TTEST2(*p, 10)) + return 0; + pbody.capability_info = EXTRACT_LE_16BITS(p); + offset += 2; + pbody.listen_interval = EXTRACT_LE_16BITS(p+offset); + offset += 2; + memcpy(&pbody.ap,p+offset,6); + offset += 6; + + if (!parse_elements(&pbody,p,offset)) + return 0; + + printf("%s (%s) AP : %s",subtype_text[FC_SUBTYPE(fc)], pbody.ssid.ssid, etheraddr_string( pbody.ap )); + + return 1; +} + +static int handle_reassoc_response(u_int16_t fc, const struct mgmt_header_t *pmh, + const u_char *p) +{ + /* Same as a Association Reponse */ + return handle_assoc_response(fc,pmh,p); +} + +static int handle_probe_request(u_int16_t fc, const struct mgmt_header_t *pmh, + const u_char *p) +{ + struct mgmt_body_t pbody; + int offset = 0; + char buf[128]; + + memset(buf, 0, sizeof(buf)); + + memset(&pbody, 0, sizeof(pbody)); + + if (!parse_elements(&pbody, p, offset)) + return 0; + + RATEStoBUF(pbody, buf); + + printf("%s (%s) [%s Mbit] ", subtype_text[FC_SUBTYPE(fc)], + pbody.ssid.ssid,buf); + + return 1; +} + +static int handle_probe_response(u_int16_t fc, const struct mgmt_header_t *pmh, + const u_char *p) +{ + struct mgmt_body_t pbody; + int offset = 0; + char buf[128]; + + memset(buf, 0, sizeof(buf)); + + memset(&pbody, 0, sizeof(pbody)); + + if (!TTEST2(*p, 12)) + return 0; + memcpy(&pbody.timestamp,p,8); + offset += 8; + pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); + offset += 2; + pbody.capability_info = EXTRACT_LE_16BITS(p+offset); + offset += 2; + + if (!parse_elements(&pbody, p, offset)) + return 0; + + printf("%s (%s) CH: %x %s", subtype_text[FC_SUBTYPE(fc)], pbody.ssid.ssid,pbody.ds.channel, + CAPABILITY_PRIVACY(pbody.capability_info) ? ",PRIVACY " : "" ); + + return 1; +} + +static int handle_atim(u_int16_t fc, const struct mgmt_header_t *pmh, + const u_char *p) +{ + /* the frame body for ATIM is null. */ + printf("ATIM"); + return 1; +} + +static int handle_disassoc(u_int16_t fc, const struct mgmt_header_t *pmh, + const u_char *p) +{ + struct mgmt_body_t pbody; + int offset = 0; + + memset(&pbody, 0, sizeof(pbody)); + + if (!TTEST2(*p, 2)) + return 0; + pbody.reason_code = EXTRACT_LE_16BITS(p); + offset += 2; + + printf("%s: %s ", subtype_text[FC_SUBTYPE(fc)], + pbody.reason_code < 10 ? reason_text[pbody.reason_code] : "Reserved" ); + + return 1; +} + +static int handle_auth(u_int16_t fc, const struct mgmt_header_t *pmh, + const u_char *p) +{ + struct mgmt_body_t pbody; + int offset = 0; + + memset(&pbody, 0, sizeof(pbody)); + + if (!TTEST2(*p, 6)) + return 0; + pbody.auth_alg = EXTRACT_LE_16BITS(p); + offset += 2; + pbody.auth_trans_seq_num = EXTRACT_LE_16BITS(p + offset); + offset += 2; + pbody.status_code = EXTRACT_LE_16BITS(p + offset); + offset += 2; + + if (!parse_elements(&pbody,p,offset)) + return 0; + + if ((pbody.auth_alg == 1) && + ((pbody.auth_trans_seq_num == 2) || (pbody.auth_trans_seq_num == 3))) { + printf("%s (%s)-%x [Challenge Text] %s", + subtype_text[FC_SUBTYPE(fc)], + pbody.auth_alg < 4 ? auth_alg_text[pbody.auth_alg] : "Reserved" , + pbody.auth_trans_seq_num, + ((pbody.auth_trans_seq_num % 2) ? + (pbody.status_code < 19 ? status_text[pbody.status_code] : "n/a") : "" )); + } else { + printf("%s (%s)-%x: %s", + subtype_text[FC_SUBTYPE(fc)], + pbody.auth_alg < 4 ? auth_alg_text[pbody.auth_alg] : "Reserved" , + pbody.auth_trans_seq_num, + ((pbody.auth_trans_seq_num % 2) ? (pbody.status_code < 19 ? status_text[pbody.status_code] : "n/a") : "")); + } + + return 1; +} + +static int handle_deauth(u_int16_t fc, const struct mgmt_header_t *pmh, + const u_char *p) +{ + struct mgmt_body_t pbody; + int offset = 0; + + memset(&pbody, 0, sizeof(pbody)); + + if (!TTEST2(*p, 2)) + return 0; + pbody.reason_code = EXTRACT_LE_16BITS(p); + offset += 2; + + if (eflag) { + printf("%s: %s", + subtype_text[FC_SUBTYPE(fc)], + pbody.reason_code < 10 ? reason_text[pbody.reason_code] : "Reserved" ); + } else { + printf("%s (%s): %s", + subtype_text[FC_SUBTYPE(fc)], etheraddr_string(pmh->sa), + pbody.reason_code < 10 ? reason_text[pbody.reason_code] : "Reserved" ); + } + + return 1; +} + + +/********************************************************************************* + * Print Body funcs + *********************************************************************************/ + + +static int mgmt_body_print(u_int16_t fc, const struct mgmt_header_t *pmh, + const u_char *p, u_int length) +{ + switch (FC_SUBTYPE(fc)) { + case ST_ASSOC_REQUEST: + return (handle_assoc_request(fc, pmh, p)); + case ST_ASSOC_RESPONSE: + return (handle_assoc_response(fc, pmh, p)); + case ST_REASSOC_REQUEST: + return (handle_reassoc_request(fc, pmh, p)); + case ST_REASSOC_RESPONSE: + return (handle_reassoc_response(fc, pmh, p)); + case ST_PROBE_REQUEST: + return (handle_probe_request(fc, pmh, p)); + case ST_PROBE_RESPONSE: + return (handle_probe_response(fc, pmh, p)); + case ST_BEACON: + return (handle_beacon(fc, pmh, p)); + case ST_ATIM: + return (handle_atim(fc, pmh, p)); + case ST_DISASSOC: + return (handle_disassoc(fc, pmh, p)); + case ST_AUTH: + if (!TTEST2(*p, 3)) + return 0; + if ((p[0] == 0 ) && (p[1] == 0) && (p[2] == 0)) { + printf("Authentication (Shared-Key)-3 "); + return (wep_print(p, length)); + } + else + return (handle_auth(fc, pmh, p)); + case ST_DEAUTH: + return (handle_deauth(fc, pmh, p)); + break; + default: + printf("Unhandled Managment subtype(%x)", + FC_SUBTYPE(fc)); + return 1; + } +} + + +/********************************************************************************* + * Handles printing all the control frame types + *********************************************************************************/ + +static int ctrl_body_print(u_int16_t fc,const u_char *p, u_int length) +{ + switch (FC_SUBTYPE(fc)) { + case CTRL_PS_POLL: + if (!TTEST2(*p, CTRL_PS_POLL_LEN)) + return 0; + printf("Power Save-Poll AID(%x)", + EXTRACT_LE_16BITS(&(((const struct ctrl_ps_poll_t *)p)->aid))); + break; + case CTRL_RTS: + if (!TTEST2(*p, CTRL_RTS_LEN)) + return 0; + if (eflag) + printf("Request-To-Send"); + else + printf("Request-To-Send TA:%s ", + etheraddr_string(((const struct ctrl_rts_t *)p)->ta)); + break; + case CTRL_CTS: + if (!TTEST2(*p, CTRL_CTS_LEN)) + return 0; + if (eflag) + printf("Clear-To-Send"); + else + printf("Clear-To-Send RA:%s ", + etheraddr_string(((const struct ctrl_cts_t *)p)->ra)); + break; + case CTRL_ACK: + if (!TTEST2(*p, CTRL_ACK_LEN)) + return 0; + if (eflag) + printf("Acknowledgment"); + else + printf("Acknowledgment RA:%s ", + etheraddr_string(((const struct ctrl_ack_t *)p)->ra)); + break; + case CTRL_CF_END: + if (!TTEST2(*p, CTRL_END_LEN)) + return 0; + if (eflag) + printf("CF-End"); + else + printf("CF-End RA:%s ", + etheraddr_string(((const struct ctrl_end_t *)p)->ra)); + break; + case CTRL_END_ACK: + if (!TTEST2(*p, CTRL_END_ACK_LEN)) + return 0; + if (eflag) + printf("CF-End+CF-Ack"); + else + printf("CF-End+CF-Ack RA:%s ", + etheraddr_string(((const struct ctrl_end_ack_t *)p)->ra)); + break; + default: + printf("(B) Unknown Ctrl Subtype"); + } + return 1; +} + + + +/* + * Print Header funcs + */ + +/* + * Data Frame - Address field contents + * + * To Ds | From DS | Addr 1 | Addr 2 | Addr 3 | Addr 4 + * 0 | 0 | DA | SA | BSSID | n/a + * 0 | 1 | DA | BSSID | SA | n/a + * 1 | 0 | BSSID | SA | DA | n/a + * 1 | 1 | RA | TA | DA | SA + */ + +static void data_header_print(u_int16_t fc,const u_char *p, u_int length) +{ +#define ADDR1 (p + 4) +#define ADDR2 (p + 10) +#define ADDR3 (p + 16) +#define ADDR4 (p + 24) + + if (!FC_TO_DS(fc)) { + if (!FC_FROM_DS(fc)) + printf("DA:%s SA:%s BSSID:%s ", + etheraddr_string(ADDR1), etheraddr_string(ADDR2), + etheraddr_string(ADDR3)); + else + printf("DA:%s BSSID:%s SA:%s ", + etheraddr_string(ADDR1), etheraddr_string(ADDR2), + etheraddr_string(ADDR3)); + } else { + if (!FC_FROM_DS(fc)) + printf("BSSID:%s SA:%s DA:%s ", + etheraddr_string(ADDR1), etheraddr_string(ADDR2), + etheraddr_string(ADDR3)); + else + printf("RA:%s TA:%s DA:%s SA:%s ", + etheraddr_string(ADDR1), etheraddr_string(ADDR2), + etheraddr_string(ADDR3), etheraddr_string(ADDR4)); + } + +#undef ADDR1 +#undef ADDR2 +#undef ADDR3 +#undef ADDR4 +} + + +static void mgmt_header_print(const u_char *p, u_int length) +{ + const struct mgmt_header_t *hp = (const struct mgmt_header_t *) p; + + printf("BSSID:%s DA:%s SA:%s ", + etheraddr_string((hp)->bssid), etheraddr_string((hp)->da), + etheraddr_string((hp)->sa)); +} + +static void ctrl_header_print(u_int16_t fc,const u_char *p, u_int length) +{ + switch (FC_SUBTYPE(fc)) { + case CTRL_PS_POLL: + printf("BSSID:%s TA:%s ", + etheraddr_string(((const struct ctrl_ps_poll_t *)p)->bssid), + etheraddr_string(((const struct ctrl_ps_poll_t *)p)->ta)); + break; + case CTRL_RTS: + printf("RA:%s TA:%s ", + etheraddr_string(((const struct ctrl_rts_t *)p)->ra), + etheraddr_string(((const struct ctrl_rts_t *)p)->ta)); + break; + case CTRL_CTS: + printf("RA:%s ", + etheraddr_string(((const struct ctrl_cts_t *)p)->ra)); + break; + case CTRL_ACK: + printf("RA:%s ", + etheraddr_string(((const struct ctrl_ack_t *)p)->ra)); + break; + case CTRL_CF_END: + printf("RA:%s BSSID:%s ", + etheraddr_string(((const struct ctrl_end_t *)p)->ra), + etheraddr_string(((const struct ctrl_end_t *)p)->bssid)); + break; + case CTRL_END_ACK: + printf("RA:%s BSSID:%s ", + etheraddr_string(((const struct ctrl_end_ack_t *)p)->ra), + etheraddr_string(((const struct ctrl_end_ack_t *)p)->bssid)); + break; + default: + printf("(H) Unknown Ctrl Subtype"); + } +} + +static int GetHeaderLength(u_int16_t fc) +{ + int iLength=0; + + switch (FC_TYPE(fc)) { + case T_MGMT: + iLength = MGMT_HEADER_LEN; + break; + case T_CTRL: + switch (FC_SUBTYPE(fc)) { + case CTRL_PS_POLL: + iLength = CTRL_PS_POLL_LEN; + break; + case CTRL_RTS: + iLength = CTRL_RTS_LEN; + break; + case CTRL_CTS: + iLength = CTRL_CTS_LEN; + break; + case CTRL_ACK: + iLength = CTRL_ACK_LEN; + break; + case CTRL_CF_END: + iLength = CTRL_END_LEN; + break; + case CTRL_END_ACK: + iLength = CTRL_END_ACK_LEN; + break; + default: + iLength = 0; + break; + } + break; + case T_DATA: + if (FC_TO_DS(fc) && FC_FROM_DS(fc)) + iLength = 30; + else + iLength = 24; + break; + default: + printf("unknown IEEE802.11 frame type (%d)", + FC_TYPE(fc)); + break; + } + + return iLength; +} + +/* + * Print the 802.11 MAC header + */ +static inline void +ieee_802_11_print(u_int16_t fc, const u_char *p, u_int length) +{ + switch (FC_TYPE(fc)) { + case T_MGMT: + mgmt_header_print(p, length); + break; + + case T_CTRL: + ctrl_header_print(fc, p, length); + break; + + case T_DATA: + data_header_print(fc, p, length); + break; + + default: + printf("(header) unknown IEEE802.11 frame type (%d)", + FC_TYPE(fc)); + break; + } +} + +/* + * This is the top level routine of the printer. 'p' is the points + * to the ether header of the packet, 'h->tv' is the timestamp, + * 'h->length' is the length of the packet off the wire, and 'h->caplen' + * is the number of bytes actually captured. + */ +void +ieee802_11_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) +{ + u_int caplen = h->caplen; + u_int length = h->len; + u_int16_t fc; + u_int HEADER_LENGTH; + u_short extracted_ethertype; + + ++infodelay; + ts_print(&h->ts); + + if (caplen < IEEE802_11_FC_LEN) { + printf("[|802.11]"); + goto out; + } + + fc=EXTRACT_LE_16BITS(p); + + if (eflag) + ieee_802_11_print(fc, p, length); + + /* + * Some printers want to get back at the ethernet addresses, + * and/or check that they're not walking off the end of the packet. + * Rather than pass them all the way down, we set these globals. + */ + packetp = p; + snapend = p + caplen; + + HEADER_LENGTH=GetHeaderLength(fc); + + length -= HEADER_LENGTH; + caplen -= HEADER_LENGTH; + p += HEADER_LENGTH; + + switch (FC_TYPE(fc)) { + case T_MGMT: + if (!mgmt_body_print(fc, (const struct mgmt_header_t *)packetp, + p, length)) { + printf("[|802.11]"); + goto out; + } + break; + + case T_CTRL: + if (!ctrl_body_print(fc, p - HEADER_LENGTH, + length + HEADER_LENGTH)) { + printf("[|802.11]"); + goto out; + } + break; + + case T_DATA: + /* There may be a problem w/ AP not having this bit set */ + if (FC_WEP(fc)) { + if (!wep_print(p,length)) { + printf("[|802.11]"); + goto out; + } + } else { + if (llc_print(p, length, caplen, packetp + 10, + packetp + 4, &extracted_ethertype) == 0) { + /* + * Some kinds of LLC packet we cannot + * handle intelligently + */ + if (!eflag) + ieee_802_11_print(fc, p - HEADER_LENGTH, + length + HEADER_LENGTH); + if (extracted_ethertype) { + printf("(LLC %s) ", + etherproto_string(htons(extracted_ethertype))); + } + if (!xflag && !qflag) + default_print(p, caplen); + } + } + break; + + default: + printf("(body) unhandled IEEE802.11 frame type (%d)", + FC_TYPE(fc)); + break; + } + + if (xflag) + default_print(p, caplen); + out: + putchar('\n'); + --infodelay; + if (infoprint) + info(0); +} diff --git a/contrib/tcpdump/print-ah.c b/contrib/tcpdump/print-ah.c index c7a4fab..50af4d4 100644 --- a/contrib/tcpdump/print-ah.c +++ b/contrib/tcpdump/print-ah.c @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ah.c,v 1.14 2000/12/12 09:58:40 itojun Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ah.c,v 1.15 2001/09/17 21:57:54 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -52,11 +52,10 @@ ah_print(register const u_char *bp, register const u_char *bp2) int sumlen; u_int32_t spi; - ah = (struct ah *)bp; + ah = (const struct ah *)bp; ep = snapend; /* 'ep' points to the end of available data. */ - if ((u_char *)(ah + 1) >= ep - sizeof(struct ah)) - goto trunc; + TCHECK(*ah); sumlen = ah->ah_len << 2; spi = (u_int32_t)ntohl(ah->ah_spi); @@ -64,7 +63,7 @@ ah_print(register const u_char *bp, register const u_char *bp2) printf("AH(spi=0x%08x", spi); if (vflag) printf(",sumlen=%d", sumlen); - printf(",seq=0x%x", (u_int32_t)ntohl(*(u_int32_t *)(ah + 1))); + printf(",seq=0x%x", (u_int32_t)ntohl(*(const u_int32_t *)(ah + 1))); if (bp + sizeof(struct ah) + sumlen > ep) fputs("[truncated]", stdout); fputs("): ", stdout); diff --git a/contrib/tcpdump/print-arcnet.c b/contrib/tcpdump/print-arcnet.c new file mode 100644 index 0000000..3b6ea90 --- /dev/null +++ b/contrib/tcpdump/print-arcnet.c @@ -0,0 +1,248 @@ +/* + * Copyright (c) 1988, 1989, 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. + * + * From: NetBSD: print-arcnet.c,v 1.2 2000/04/24 13:02:28 itojun Exp + */ +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-arcnet.c,v 1.6 2001/09/17 21:57:54 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/socket.h> + +struct mbuf; +struct rtentry; + +#include <netinet/in.h> + +#include <stdio.h> +#include <pcap.h> + +#include "interface.h" +#include "arcnet.h" + +int arcnet_encap_print(u_char arctype, const u_char *p, + u_int length, u_int caplen); + +struct tok arctypemap[] = { + { ARCTYPE_IP_OLD, "oldip" }, + { ARCTYPE_ARP_OLD, "oldarp" }, + { ARCTYPE_IP, "ip" }, + { ARCTYPE_ARP, "arp" }, + { ARCTYPE_REVARP, "rarp" }, + { ARCTYPE_ATALK, "atalk" }, + { ARCTYPE_BANIAN, "banyan" }, + { ARCTYPE_IPX, "ipx" }, + { ARCTYPE_INET6, "ipv6" }, + { ARCTYPE_DIAGNOSE, "diag" }, + { 0, 0 } +}; + +static inline void +arcnet_print(const u_char *bp, u_int length, int phds, int flag, u_int seqid) +{ + const struct arc_header *ap; + const char *arctypename; + + + ap = (const struct arc_header *)bp; + + + if (qflag) { + (void)printf("%02x %02x %d: ", + ap->arc_shost, + ap->arc_dhost, + length); + return; + } + + arctypename = tok2str(arctypemap, "%02x", ap->arc_type); + + if (!phds) { + (void)printf("%02x %02x %s %d: ", + ap->arc_shost, ap->arc_dhost, arctypename, + length); + return; + } + + if (flag == 0) { + (void)printf("%02x %02x %s seqid %04x %d: ", + ap->arc_shost, ap->arc_dhost, arctypename, seqid, + length); + return; + } + + if (flag & 1) + (void)printf("%02x %02x %s seqid %04x " + "(first of %d fragments) %d: ", + ap->arc_shost, ap->arc_dhost, arctypename, seqid, + (flag + 3) / 2, length); + else + (void)printf("%02x %02x %s seqid %04x " + "(fragment %d) %d: ", + ap->arc_shost, ap->arc_dhost, arctypename, seqid, + flag/2 + 1, length); +} + +/* + * This is the top level routine of the printer. 'p' is the points + * to the ether header of the packet, 'tvp' is the timestamp, + * 'length' is the length of the packet off the wire, and 'caplen' + * is the number of bytes actually captured. + */ +void +arcnet_if_print(u_char *user, 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; + u_int seqid = 0; + u_char arc_type; + + ++infodelay; + ts_print(&h->ts); + + if (caplen < ARC_HDRLEN) { + printf("[|arcnet]"); + goto out; + } + + ap = (const struct arc_header *)p; + arc_type = ap->arc_type; + + switch (arc_type) { + default: + phds = 1; + break; + case ARCTYPE_IP_OLD: + case ARCTYPE_ARP_OLD: + case ARCTYPE_DIAGNOSE: + phds = 0; + archdrlen = ARC_HDRLEN; + break; + } + + if (phds) { + if (caplen < ARC_HDRNEWLEN) { + arcnet_print(p, length, 0, 0, 0); + printf("[|phds]"); + goto out; + } + + if (ap->arc_flag == 0xff) { + if (caplen < ARC_HDRNEWLEN_EXC) { + arcnet_print(p, length, 0, 0, 0); + printf("[|phds extended]"); + goto out; + } + flag = ap->arc_flag2; + seqid = ap->arc_seqid2; + archdrlen = ARC_HDRNEWLEN_EXC; + } else { + flag = ap->arc_flag; + seqid = ap->arc_seqid; + archdrlen = ARC_HDRNEWLEN; + } + } + + + if (eflag) + arcnet_print(p, length, phds, flag, seqid); + + /* + * Some printers want to get back at the ethernet addresses, + * and/or check that they're not walking off the end of the packet. + * Rather than pass them all the way down, we set these globals. + */ + packetp = p; + snapend = p + caplen; + + length -= archdrlen; + caplen -= archdrlen; + p += archdrlen; + + if (phds && flag && (flag & 1) == 0) + goto out2; + + if (!arcnet_encap_print(arc_type, p, length, caplen)) { + default_print(p, caplen); + goto out; + } + + out2: + if (xflag) + default_print(p, caplen); + + out: + putchar('\n'); + --infodelay; + if (infoprint) + info(0); +} + +/* + * Prints the packet encapsulated in an ARCnet data field, + * given the ARCnet system code. + * + * Returns non-zero if it can do so, zero if the system code is unknown. + */ + + +int +arcnet_encap_print(u_char arctype, const u_char *p, + u_int length, u_int caplen) +{ + switch (arctype) { + + case ARCTYPE_IP_OLD: + case ARCTYPE_IP: + ip_print(p, length); + return (1); + +#ifdef INET6 + case ARCTYPE_INET6: + ip6_print(p, length); + return (1); +#endif /*INET6*/ + + case ARCTYPE_ARP_OLD: + case ARCTYPE_ARP: + case ARCTYPE_REVARP: + arp_print(p, length, caplen); + return (1); + + case ARCTYPE_ATALK: /* XXX was this ever used? */ + if (vflag) + fputs("et1 ", stdout); + atalk_print(p, length); + return (1); + + default: + return (0); + } +} diff --git a/contrib/tcpdump/print-arp.c b/contrib/tcpdump/print-arp.c index 7b693a2..160c7a8 100644 --- a/contrib/tcpdump/print-arp.c +++ b/contrib/tcpdump/print-arp.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-arp.c,v 1.49 2000/10/10 05:05:07 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-arp.c,v 1.51 2001/09/17 21:57:54 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -56,7 +56,10 @@ struct arphdr { u_short 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 */ #define ARPHRD_FRELAY 15 /* frame relay hardware format */ +#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 */ @@ -77,117 +80,86 @@ struct arphdr { u_char ar_tha[]; /* target hardware address */ u_char ar_tpa[]; /* target protocol address */ #endif +#define ar_sha(ap) (((const caddr_t)((ap)+1))+0) +#define ar_spa(ap) (((const caddr_t)((ap)+1))+ (ap)->ar_hln) +#define ar_tha(ap) (((const caddr_t)((ap)+1))+ (ap)->ar_hln+(ap)->ar_pln) +#define ar_tpa(ap) (((const caddr_t)((ap)+1))+2*(ap)->ar_hln+(ap)->ar_pln) }; #define ARP_HDRLEN 8 -/* - * Ethernet Address Resolution Protocol. - * - * See RFC 826 for protocol description. Structure below is adapted - * to resolving internet addresses. Field names used correspond to - * RFC 826. - */ -struct ether_arp { - struct arphdr ea_hdr; /* fixed-size header */ - u_char arp_sha[6]; /* sender hardware address */ - u_char arp_spa[4]; /* sender protocol address */ - u_char arp_tha[6]; /* target hardware address */ - u_char arp_tpa[4]; /* target protocol address */ -}; -#define arp_hrd ea_hdr.ar_hrd -#define arp_pro ea_hdr.ar_pro -#define arp_hln ea_hdr.ar_hln -#define arp_pln ea_hdr.ar_pln -#define arp_op ea_hdr.ar_op - -#define ETHER_ARP_HDRLEN (ARP_HDRLEN + 6 + 4 + 6 + 4) - -#define SHA(ap) ((ap)->arp_sha) -#define THA(ap) ((ap)->arp_tha) -#define SPA(ap) ((ap)->arp_spa) -#define TPA(ap) ((ap)->arp_tpa) - -/* Compatibility */ -#ifndef REVARP_REQUEST -#define REVARP_REQUEST 3 -#endif -#ifndef REVARP_REPLY -#define REVARP_REPLY 4 -#endif +#define HRD(ap) ((ap)->ar_hrd) +#define HLN(ap) ((ap)->ar_hln) +#define PLN(ap) ((ap)->ar_pln) +#define OP(ap) ((ap)->ar_op) +#define PRO(ap) ((ap)->ar_pro) +#define SHA(ap) (ar_sha(ap)) +#define SPA(ap) (ar_spa(ap)) +#define THA(ap) (ar_tha(ap)) +#define TPA(ap) (ar_tpa(ap)) static u_char ezero[6]; void -arp_print(register const u_char *bp, u_int length, u_int caplen) +arp_print(const u_char *bp, u_int length, u_int caplen) { - register const struct ether_arp *ap; - register const struct ether_header *eh; - register u_short pro, hrd, op; + const struct arphdr *ap; + u_short pro, hrd, op; - ap = (struct ether_arp *)bp; - if ((u_char *)(ap + 1) > snapend) { - printf("[|arp]"); - return; - } - if (length < ETHER_ARP_HDRLEN) { + ap = (const struct arphdr *)bp; + TCHECK(*ap); + if ((const u_char *)(ar_tpa(ap) + PLN(ap)) > snapend) { (void)printf("truncated-arp"); - default_print((u_char *)ap, length); + default_print((const u_char *)ap, length); return; } - pro = EXTRACT_16BITS(&ap->arp_pro); - hrd = EXTRACT_16BITS(&ap->arp_hrd); - op = EXTRACT_16BITS(&ap->arp_op); + pro = EXTRACT_16BITS(&PRO(ap)); + hrd = EXTRACT_16BITS(&HRD(ap)); + op = EXTRACT_16BITS(&OP(ap)); - if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) - || ap->arp_hln != sizeof(SHA(ap)) - || ap->arp_pln != sizeof(SPA(ap))) { + if (pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) { (void)printf("arp-#%d for proto #%d (%d) hardware #%d (%d)", - op, pro, ap->arp_pln, - hrd, ap->arp_hln); + op, pro, PLN(ap), hrd, HLN(ap)); return; } if (pro == ETHERTYPE_TRAIL) (void)printf("trailer-"); - eh = (struct ether_header *)packetp; switch (op) { case ARPOP_REQUEST: (void)printf("arp who-has %s", ipaddr_string(TPA(ap))); - if (memcmp((char *)ezero, (char *)THA(ap), 6) != 0) - (void)printf(" (%s)", etheraddr_string(THA(ap))); + if (memcmp((const char *)ezero, (const char *)THA(ap), HLN(ap)) != 0) + (void)printf(" (%s)", + linkaddr_string(THA(ap), HLN(ap))); (void)printf(" tell %s", ipaddr_string(SPA(ap))); - if (memcmp((char *)ESRC(eh), (char *)SHA(ap), 6) != 0) - (void)printf(" (%s)", etheraddr_string(SHA(ap))); break; case ARPOP_REPLY: (void)printf("arp reply %s", ipaddr_string(SPA(ap))); - if (memcmp((char *)ESRC(eh), (char *)SHA(ap), 6) != 0) - (void)printf(" (%s)", etheraddr_string(SHA(ap))); - (void)printf(" is-at %s", etheraddr_string(SHA(ap))); - if (memcmp((char *)EDST(eh), (char *)THA(ap), 6) != 0) - (void)printf(" (%s)", etheraddr_string(THA(ap))); + (void)printf(" is-at %s", linkaddr_string(SHA(ap), HLN(ap))); break; - case REVARP_REQUEST: + case ARPOP_REVREQUEST: (void)printf("rarp who-is %s tell %s", - etheraddr_string(THA(ap)), - etheraddr_string(SHA(ap))); + linkaddr_string(THA(ap), HLN(ap)), + linkaddr_string(SHA(ap), HLN(ap))); break; - case REVARP_REPLY: + case ARPOP_REVREPLY: (void)printf("rarp reply %s at %s", - etheraddr_string(THA(ap)), + linkaddr_string(THA(ap), HLN(ap)), ipaddr_string(TPA(ap))); break; default: (void)printf("arp-#%d", op); - default_print((u_char *)ap, caplen); + default_print((const u_char *)ap, caplen); return; } if (hrd != ARPHRD_ETHER) printf(" hardware #%d", hrd); + return; +trunc: + (void)printf("[|arp]"); } diff --git a/contrib/tcpdump/print-atalk.c b/contrib/tcpdump/print-atalk.c index 820b7db..5446521 100644 --- a/contrib/tcpdump/print-atalk.c +++ b/contrib/tcpdump/print-atalk.c @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-atalk.c,v 1.64 2000/10/30 06:22:14 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-atalk.c,v 1.70 2001/11/15 08:23:12 itojun Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -40,13 +40,13 @@ static const char rcsid[] = #include <stdlib.h> #include <string.h> #include <netdb.h> /* for MAXHOSTNAMELEN on some platforms */ +#include <pcap.h> #include "interface.h" #include "addrtoname.h" #include "ethertype.h" #include "extract.h" /* must come after interface.h */ #include "appletalk.h" -#include "savestr.h" static struct tok type2str[] = { { ddpRTMP, "rtmp" }, @@ -84,6 +84,24 @@ static void ddp_print(const u_char *, u_int, int, u_short, u_char, u_char); static const char *ddpskt_string(int); /* + * Print LLAP packets received on a physical LocalTalk interface. + */ +void +ltalk_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) +{ + snapend = p + h->caplen; + ++infodelay; + ts_print(&h->ts); + llap_print(p, h->caplen); + if(xflag) + default_print(p, h->caplen); + putchar('\n'); + --infodelay; + if (infoprint) + info(0); +} + +/* * Print AppleTalk LLAP packets. */ void @@ -94,7 +112,7 @@ llap_print(register const u_char *bp, u_int length) register const struct atShortDDP *sdp; u_short snet; - lp = (struct LAP *)bp; + lp = (const struct LAP *)bp; bp += sizeof(*lp); length -= sizeof(*lp); switch (lp->type) { @@ -156,8 +174,8 @@ atalk_print(register const u_char *bp, u_int length) u_short snet; if (length < ddpSize) { - (void)printf(" [|ddp %d]", length); - return; + (void)printf(" [|ddp %d]", length); + return; } dp = (const struct atDDP *)bp; snet = EXTRACT_16BITS(&dp->srcNet); @@ -168,6 +186,21 @@ atalk_print(register const u_char *bp, u_int length) ddpskt_string(dp->dstSkt)); bp += ddpSize; length -= ddpSize; +#ifdef LBL_ALIGN + if ((long)bp & 3) { + static u_char *abuf = NULL; + + if (abuf == NULL) { + abuf = (u_char *)malloc(snaplen); + if (abuf == NULL) + error("atalk_print: malloc"); + } + memcpy((char *)abuf, (char *)bp, min(length, snaplen)); + snapend += abuf - (u_char *)bp; + packetp = abuf; + bp = abuf; + } +#endif ddp_print(bp, length, dp->type, snet, dp->srcNode, dp->srcSkt); } @@ -357,7 +390,7 @@ nbp_print(register const struct atNBP *np, u_int length, register u_short snet, register u_char snode, register u_char skt) { register const struct atNBPtuple *tp = - (struct atNBPtuple *)((u_char *)np + nbpHeaderSize); + (const struct atNBPtuple *)((u_char *)np + nbpHeaderSize); int i; const u_char *ep; @@ -433,7 +466,7 @@ print_cstring(register const char *cp, register const u_char *ep) return (0); } while ((int)--length >= 0) { - if (cp >= (char *)ep) { + if (cp >= (const char *)ep) { fputs(tstr, stdout); return (0); } @@ -542,7 +575,7 @@ ataddr_string(u_short atnet, u_char athost) ; tp->addr = i3; tp->nxt = newhnamemem(); - tp->name = savestr(nambuf); + tp->name = strdup(nambuf); } fclose(fp); } @@ -559,7 +592,7 @@ ataddr_string(u_short atnet, u_char athost) tp->nxt = newhnamemem(); (void)snprintf(nambuf, sizeof(nambuf), "%s.%d", tp2->name, athost); - tp->name = savestr(nambuf); + tp->name = strdup(nambuf); return (tp->name); } @@ -571,7 +604,7 @@ ataddr_string(u_short atnet, u_char athost) else (void)snprintf(nambuf, sizeof(nambuf), "%d.%d", atnet >> 8, atnet & 0xff); - tp->name = savestr(nambuf); + tp->name = strdup(nambuf); return (tp->name); } diff --git a/contrib/tcpdump/print-atm.c b/contrib/tcpdump/print-atm.c index d978086..ced9c46 100644 --- a/contrib/tcpdump/print-atm.c +++ b/contrib/tcpdump/print-atm.c @@ -20,7 +20,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-atm.c,v 1.20 2000/12/22 22:45:09 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-atm.c,v 1.21 2001/07/05 18:54:14 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -53,6 +53,7 @@ atm_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) u_int length = h->len; u_short ethertype; + ++infodelay; ts_print(&h->ts); if (caplen < 8) { @@ -141,4 +142,7 @@ atm_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) default_print(p, caplen); out: putchar('\n'); + --infodelay; + if (infoprint) + info(0); } diff --git a/contrib/tcpdump/print-beep.c b/contrib/tcpdump/print-beep.c new file mode 100644 index 0000000..51c1295 --- /dev/null +++ b/contrib/tcpdump/print-beep.c @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2000, Richard Sharpe + * + * This software may be distributed either under the terms of the + * BSD-style licence that accompanies tcpdump or under the GNU GPL + * version 2 or later. + * + * print-beep.c + * + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-beep.c,v 1.1 2001/12/10 08:21:24 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/param.h> +#include <sys/time.h> + +#ifdef HAVE_MEMORY_H +#include <memory.h> +#endif +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "interface.h" +#include "extract.h" + +/* Check for a string but not go beyond length + * Return TRUE on match, FALSE otherwise + * + * Looks at the first few chars up to tl1 ... + */ + +static int l_strnstart(const char *, u_int, const char *, u_int); + +static int +l_strnstart(const char *tstr1, u_int tl1, const char *str2, u_int l2) +{ + + if (tl1 > l2) + return 0; + + return (strncmp(tstr1, str2, tl1) == 0 ? 1 : 0); +} + +void +beep_print(const u_char *bp, u_int length) +{ + + if (l_strnstart("MSG", 4, bp, length)) /* A REQuest */ + printf(" BEEP MSG"); + else if (l_strnstart("RPY ", 4, bp, length)) + printf(" BEEP RPY"); + else if (l_strnstart("ERR ", 4, bp, length)) + printf(" BEEP ERR"); + else if (l_strnstart("ANS ", 4, bp, length)) + printf(" BEEP ANS"); + else if (l_strnstart("NUL ", 4, bp, length)) + printf(" BEEP NUL"); + else if (l_strnstart("SEQ ", 4, bp, length)) + printf(" BEEP SEQ"); + else if (l_strnstart("END", 4, bp, length)) + printf(" BEEP END"); + else + printf(" BEEP (payload or undecoded)"); +} diff --git a/contrib/tcpdump/print-bgp.c b/contrib/tcpdump/print-bgp.c index 71f20c3..342292b 100644 --- a/contrib/tcpdump/print-bgp.c +++ b/contrib/tcpdump/print-bgp.c @@ -33,7 +33,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.21 2000/12/05 05:48:35 guy Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.27 2001/10/18 09:52:17 itojun Exp $"; #endif #include <sys/param.h> @@ -75,12 +75,14 @@ struct bgp_open { u_int8_t bgpo_optlen; /* options should follow */ }; +#define BGP_OPEN_SIZE 29 /* unaligned */ struct bgp_opt { u_int8_t bgpopt_type; u_int8_t bgpopt_len; /* variable length */ }; +#define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */ struct bgp_notification { u_int8_t bgpn_marker[16]; @@ -90,6 +92,7 @@ struct bgp_notification { u_int8_t bgpn_minor; /* data should follow */ }; +#define BGP_NOTIFICATION_SIZE 21 /* unaligned */ struct bgp_attr { u_int8_t bgpa_flags; @@ -128,7 +131,7 @@ static const char *bgptype[] = { #define bgp_type(x) num_or_str(bgptype, sizeof(bgptype)/sizeof(bgptype[0]), (x)) static const char *bgpopt_type[] = { - NULL, "Authentication Information", + NULL, "Authentication Information", "Capabilities Advertisement", }; #define bgp_opttype(x) \ num_or_str(bgpopt_type, sizeof(bgpopt_type)/sizeof(bgpopt_type[0]), (x)) @@ -192,7 +195,7 @@ static const char *bgpattr_type[] = { /* Subsequent address family identifier, RFC2283 section 7 */ static const char *bgpattr_nlri_safi[] = { - "Reserved", "Unicast", "Multicast", "Unicast+Multicast", + "Reserved", "Unicast", "Multicast", "Unicast+Multicast", }; #define bgp_attr_nlri_safi(x) \ num_or_str(bgpattr_nlri_safi, \ @@ -270,10 +273,10 @@ bgp_notify_minor(int major, int minor) } static int -decode_prefix4(const u_char *pd, char *buf, int buflen) +decode_prefix4(const u_char *pd, char *buf, u_int buflen) { struct in_addr addr; - int plen; + u_int plen; plen = pd[0]; if (plen < 0 || 32 < plen) @@ -291,10 +294,10 @@ decode_prefix4(const u_char *pd, char *buf, int buflen) #ifdef INET6 static int -decode_prefix6(const u_char *pd, char *buf, int buflen) +decode_prefix6(const u_char *pd, char *buf, u_int buflen) { struct in6_addr addr; - int plen; + u_int plen; plen = pd[0]; if (plen < 0 || 128 < plen) @@ -306,7 +309,7 @@ decode_prefix6(const u_char *pd, char *buf, int buflen) addr.s6_addr[(plen + 7) / 8 - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } - snprintf(buf, buflen, "%s/%d", getname6((char *)&addr), plen); + snprintf(buf, buflen, "%s/%d", getname6((u_char *)&addr), plen); return 1 + (plen + 7) / 8; } #endif @@ -346,9 +349,9 @@ bgp_attr_print(const struct bgp_attr *attr, const u_char *dat, int len) if (p[0] == 3 || p[0] == 4) printf("confed"); printf("%s", (p[0] & 1) ? "{" : ""); - for (i = 0; i < p[1]; i += 2) { + for (i = 0; i < p[1] * 2; i += 2) { printf("%s%u", i == 0 ? "" : " ", - ntohs(*(u_int16_t *)&p[2 + i])); + EXTRACT_16BITS(&p[2 + i])); } printf("%s", (p[0] & 1) ? "}" : ""); p += 2 + p[1] * 2; @@ -365,7 +368,7 @@ bgp_attr_print(const struct bgp_attr *attr, const u_char *dat, int len) if (len != 4) printf(" invalid len"); else - printf(" %u", (u_int32_t)ntohl(*(u_int32_t *)p)); + printf(" %u", EXTRACT_32BITS(p)); break; case BGPTYPE_ATOMIC_AGGREGATE: if (len != 0) @@ -376,7 +379,7 @@ bgp_attr_print(const struct bgp_attr *attr, const u_char *dat, int len) printf(" invalid len"); break; } - printf(" AS #%u, origin %s", ntohs(*(u_int16_t *)p), + printf(" AS #%u, origin %s", EXTRACT_16BITS(p), getname(p + 2)); break; case BGPTYPE_COMMUNITIES: @@ -386,7 +389,7 @@ bgp_attr_print(const struct bgp_attr *attr, const u_char *dat, int len) } for (i = 0; i < len; i += 4) { u_int32_t comm; - comm = (u_int32_t)ntohl(*(u_int32_t *)&p[i]); + comm = EXTRACT_32BITS(&p[i]); switch (comm) { case BGP_COMMUNITY_NO_EXPORT: printf(" NO_EXPORT"); @@ -405,7 +408,7 @@ bgp_attr_print(const struct bgp_attr *attr, const u_char *dat, int len) } break; case BGPTYPE_MP_REACH_NLRI: - af = ntohs(*(u_int16_t *)p); + af = EXTRACT_16BITS(p); safi = p[2]; if (safi >= 128) printf(" %s vendor specific,", af_name(af)); @@ -487,7 +490,7 @@ bgp_attr_print(const struct bgp_attr *attr, const u_char *dat, int len) break; case BGPTYPE_MP_UNREACH_NLRI: - af = ntohs(*(u_int16_t *)p); + af = EXTRACT_16BITS(p); safi = p[2]; if (safi >= 128) printf(" %s vendor specific,", af_name(af)); @@ -534,8 +537,8 @@ bgp_open_print(const u_char *dat, int length) const u_char *opt; int i; - TCHECK2(dat[0], sizeof(bgpo)); - memcpy(&bgpo, dat, sizeof(bgpo)); + TCHECK2(dat[0], BGP_OPEN_SIZE); + memcpy(&bgpo, dat, BGP_OPEN_SIZE); hlen = ntohs(bgpo.bgpo_len); printf(": Version %d,", bgpo.bgpo_version); @@ -545,11 +548,13 @@ bgp_open_print(const u_char *dat, int length) printf(" Option length %u", bgpo.bgpo_optlen); /* ugly! */ - opt = &((struct bgp_open *)dat)->bgpo_optlen; + opt = &((const struct bgp_open *)dat)->bgpo_optlen; opt++; - for (i = 0; i < bgpo.bgpo_optlen; i++) { - memcpy(&bgpopt, &opt[i], sizeof(bgpopt)); + i = 0; + while (i < bgpo.bgpo_optlen) { + TCHECK2(opt[i], BGP_OPT_SIZE); + memcpy(&bgpopt, &opt[i], BGP_OPT_SIZE); if (i + 2 + bgpopt.bgpopt_len > bgpo.bgpo_optlen) { printf(" [|opt %d %d]", bgpopt.bgpopt_len, bgpopt.bgpopt_type); break; @@ -557,7 +562,7 @@ bgp_open_print(const u_char *dat, int length) printf(" (option %s, len=%d)", bgp_opttype(bgpopt.bgpopt_type), bgpopt.bgpopt_len); - i += sizeof(bgpopt) + bgpopt.bgpopt_len; + i += BGP_OPT_SIZE + bgpopt.bgpopt_len; } return; trunc: @@ -575,8 +580,8 @@ bgp_update_print(const u_char *dat, int length) int i; int newline; - TCHECK2(dat[0], sizeof(bgp)); - memcpy(&bgp, dat, sizeof(bgp)); + TCHECK2(dat[0], BGP_SIZE); + memcpy(&bgp, dat, BGP_SIZE); hlen = ntohs(bgp.bgp_len); p = dat + BGP_SIZE; /*XXX*/ printf(":"); @@ -584,9 +589,10 @@ bgp_update_print(const u_char *dat, int length) /* Unfeasible routes */ len = EXTRACT_16BITS(p); if (len) { - /* Without keeping state from the original NLRI message, - * it's not possible to tell if this a v4 or v6 route, - * so only try to decode it if we're not v6 enabled. + /* + * Without keeping state from the original NLRI message, + * it's not possible to tell if this a v4 or v6 route, + * so only try to decode it if we're not v6 enabled. */ #ifdef INET6 printf(" (Withdrawn routes: %d bytes)", len); @@ -680,8 +686,8 @@ bgp_notification_print(const u_char *dat, int length) struct bgp_notification bgpn; int hlen; - TCHECK2(dat[0], sizeof(bgpn)); - memcpy(&bgpn, dat, sizeof(bgpn)); + TCHECK2(dat[0], BGP_NOTIFICATION_SIZE); + memcpy(&bgpn, dat, BGP_NOTIFICATION_SIZE); hlen = ntohs(bgpn.bgpn_len); printf(": error %s,", bgp_notify_major(bgpn.bgpn_major)); @@ -697,8 +703,8 @@ bgp_header_print(const u_char *dat, int length) { struct bgp bgp; - TCHECK2(dat[0], sizeof(bgp)); - memcpy(&bgp, dat, sizeof(bgp)); + TCHECK2(dat[0], BGP_SIZE); + memcpy(&bgp, dat, BGP_SIZE); printf("(%s", bgp_type(bgp.bgp_type)); /* ) */ switch (bgp.bgp_type) { @@ -759,8 +765,8 @@ bgp_print(const u_char *dat, int length) } /* found BGP header */ - TCHECK2(p[0], sizeof(bgp)); /*XXX*/ - memcpy(&bgp, p, sizeof(bgp)); + TCHECK2(p[0], BGP_SIZE); /*XXX*/ + memcpy(&bgp, p, BGP_SIZE); if (start != p) printf(" [|BGP]"); diff --git a/contrib/tcpdump/print-bootp.c b/contrib/tcpdump/print-bootp.c index e564a29..fd8754a 100644 --- a/contrib/tcpdump/print-bootp.c +++ b/contrib/tcpdump/print-bootp.c @@ -22,7 +22,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.56 2000/12/04 00:00:08 fenner Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.60 2001/09/17 21:57:56 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -48,8 +48,8 @@ struct rtentry; #include "ether.h" #include "bootp.h" -static void rfc1048_print(const u_char *, u_int); -static void cmu_print(const u_char *, u_int); +static void rfc1048_print(const u_char *); +static void cmu_print(const u_char *); static char tstr[] = " [|bootp]"; @@ -61,10 +61,10 @@ bootp_print(register const u_char *cp, u_int length, u_short sport, u_short dport) { register const struct bootp *bp; - static u_char vm_cmu[4] = VM_CMU; - static u_char vm_rfc1048[4] = VM_RFC1048; + static const u_char vm_cmu[4] = VM_CMU; + static const u_char vm_rfc1048[4] = VM_RFC1048; - bp = (struct bootp *)cp; + bp = (const struct bootp *)cp; TCHECK(bp->bp_op); switch (bp->bp_op) { @@ -130,14 +130,14 @@ bootp_print(register const u_char *cp, u_int length, register const char *e; TCHECK2(bp->bp_chaddr[0], 6); - eh = (struct ether_header *)packetp; + eh = (const struct ether_header *)packetp; if (bp->bp_op == BOOTREQUEST) e = (const char *)ESRC(eh); else if (bp->bp_op == BOOTREPLY) e = (const char *)EDST(eh); else e = 0; - if (e == 0 || memcmp((char *)bp->bp_chaddr, e, 6) != 0) + if (e == 0 || memcmp((const char *)bp->bp_chaddr, e, 6) != 0) printf(" ether %s", etheraddr_string(bp->bp_chaddr)); } @@ -164,13 +164,12 @@ bootp_print(register const u_char *cp, u_int length, /* Decode the vendor buffer */ TCHECK(bp->bp_vend[0]); - length -= sizeof(*bp) - sizeof(bp->bp_vend); - if (memcmp((char *)bp->bp_vend, (char *)vm_rfc1048, + if (memcmp((const char *)bp->bp_vend, vm_rfc1048, sizeof(u_int32_t)) == 0) - rfc1048_print(bp->bp_vend, length); - else if (memcmp((char *)bp->bp_vend, (char *)vm_cmu, + rfc1048_print(bp->bp_vend); + else if (memcmp((const char *)bp->bp_vend, vm_cmu, sizeof(u_int32_t)) == 0) - cmu_print(bp->bp_vend, length); + cmu_print(bp->bp_vend); else { u_int32_t ul; @@ -184,7 +183,19 @@ trunc: fputs(tstr, stdout); } -/* The first character specifies the format to print */ +/* + * The first character specifies the format to print: + * i - ip address (32 bits) + * p - ip address pairs (32 bits + 32 bits) + * l - long (32 bits) + * L - unsigned long (32 bits) + * s - short (16 bits) + * b - period-seperated decimal bytes (variable length) + * x - colon-seperated hex bytes (variable length) + * a - ascii string (variable length) + * B - on/off (8 bits) + * $ - special (explicit code to handle) + */ static struct tok tag2str[] = { /* RFC1048 tags */ { TAG_PAD, " PAD" }, @@ -236,7 +247,7 @@ static struct tok tag2str[] = { { TAG_VENDOR_OPTS, "bVO" }, { TAG_NETBIOS_NS, "iWNS" }, { TAG_NETBIOS_DDS, "iWDD" }, - { TAG_NETBIOS_NODE, "bWNT" }, + { TAG_NETBIOS_NODE, "$WNT" }, { TAG_NETBIOS_SCOPE, "aWSC" }, { TAG_XWIN_FS, "iXFS" }, { TAG_XWIN_DM, "iXDM" }, @@ -253,7 +264,7 @@ static struct tok tag2str[] = { { TAG_STREETTALK_STDA, "iSTDA" }, { TAG_REQUESTED_IP, "iRQ" }, { TAG_IP_LEASE, "lLT" }, - { TAG_OPT_OVERLOAD, "bOO" }, + { TAG_OPT_OVERLOAD, "$OO" }, { TAG_TFTP_SERVER, "aTFTP" }, { TAG_BOOTFILENAME, "aBF" }, { TAG_DHCP_MESSAGE, " DHCP" }, @@ -263,8 +274,8 @@ static struct tok tag2str[] = { { TAG_MAX_MSG_SIZE, "sMSZ" }, { TAG_RENEWAL_TIME, "lRN" }, { TAG_REBIND_TIME, "lRB" }, - { TAG_VENDOR_CLASS, "bVC" }, - { TAG_CLIENT_ID, "xCID" }, + { TAG_VENDOR_CLASS, "aVC" }, + { TAG_CLIENT_ID, "$CID" }, /* RFC 2485 */ { TAG_OPEN_GROUP_UAP, "aUAP" }, /* RFC 2563 */ @@ -279,7 +290,7 @@ static struct tok tag2str[] = { /* ftp://ftp.isi.edu/.../assignments/bootp-dhcp-extensions */ { TAG_USER_CLASS, "aCLASS" }, { TAG_SLP_NAMING_AUTH, "aSLP-NA" }, - { TAG_CLIENT_FQDN, "bFQDN" }, /* XXX 'b' */ + { TAG_CLIENT_FQDN, "$FQDN" }, { TAG_AGENT_CIRCUIT, "bACKT" }, { TAG_AGENT_REMOTE, "bARMT" }, { TAG_AGENT_MASK, "bAMSK" }, @@ -307,8 +318,36 @@ static struct tok xtag2str[] = { { 0, NULL } }; +/* DHCP "options overload" types */ +static struct tok oo2str[] = { + { 1, "file" }, + { 2, "sname" }, + { 3, "file+sname" }, + { 0, NULL } +}; + +/* NETBIOS over TCP/IP node type options */ +static struct tok nbo2str[] = { + { 0x1, "b-node" }, + { 0x2, "p-node" }, + { 0x4, "m-node" }, + { 0x8, "h-node" }, + { 0, NULL } +}; + +/* ARP Hardware types, for Client-ID option */ +static struct tok arp2str[] = { + { 0x1, "ether" }, + { 0x6, "ieee802" }, + { 0x7, "arcnet" }, + { 0xf, "frelay" }, + { 0x17, "strip" }, + { 0x18, "ieee1394" }, + { 0, NULL } +}; + static void -rfc1048_print(register const u_char *bp, register u_int length) +rfc1048_print(register const u_char *bp) { register u_char tag; register u_int len, size; @@ -446,10 +485,10 @@ rfc1048_print(register const u_char *bp, register u_int length) while (size >= 2*sizeof(ul)) { if (!first) putchar(','); - memcpy((char *)&ul, (char *)bp, sizeof(ul)); + memcpy((char *)&ul, (const char *)bp, sizeof(ul)); printf("(%s:", ipaddr_string(&ul)); bp += sizeof(ul); - memcpy((char *)&ul, (char *)bp, sizeof(ul)); + memcpy((char *)&ul, (const char *)bp, sizeof(ul)); printf("%s)", ipaddr_string(&ul)); bp += sizeof(ul); size -= 2*sizeof(ul); @@ -498,13 +537,76 @@ rfc1048_print(register const u_char *bp, register u_int length) /* Bytes */ while (size > 0) { if (!first) - putchar (c == 'x' ? ':' : '.'); - printf (c == 'x' ? "%02x" : "%d", *bp); + putchar(c == 'x' ? ':' : '.'); + if (c == 'x') + printf("%02x", *bp); + else + printf("%d", *bp); ++bp; --size; first = 0; } break; + + case '$': + /* Guys we can't handle with one of the usual cases */ + switch (tag) { + + case TAG_NETBIOS_NODE: + tag = *bp++; + --size; + fputs(tok2str(nbo2str, NULL, tag), stdout); + break; + + case TAG_OPT_OVERLOAD: + tag = *bp++; + --size; + fputs(tok2str(oo2str, NULL, tag), stdout); + break; + + case TAG_CLIENT_FQDN: + if (*bp++) + printf("[svrreg]"); + if (*bp) + printf("%d/%d/", *bp, *(bp+1)); + bp += 2; + putchar('"'); + (void)fn_printn(bp, size - 3, NULL); + putchar('"'); + bp += size - 3; + size = 0; + break; + + case TAG_CLIENT_ID: + { int type = *bp++; + size--; + if (type == 0) { + putchar('"'); + (void)fn_printn(bp, size, NULL); + putchar('"'); + break; + } else { + printf("[%s]", tok2str(arp2str, "type-%d", type)); + } + while (size > 0) { + if (!first) + putchar(':'); + printf("%02x", *bp); + ++bp; + --size; + first = 0; + } + break; + } + + default: + printf("[unknown special tag %d, size %d]", + tag, size); + bp += size; + size = 0; + break; + } + break; } /* Data left over? */ if (size) @@ -516,17 +618,16 @@ trunc: } static void -cmu_print(register const u_char *bp, register u_int length) +cmu_print(register const u_char *bp) { register const struct cmu_vend *cmu; - char *fmt = " %s:%s"; #define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \ if (cmu->m.s_addr != 0) \ - printf(fmt, s, ipaddr_string(&cmu->m.s_addr)); } + printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); } printf(" vend-cmu"); - cmu = (struct cmu_vend *)bp; + cmu = (const struct cmu_vend *)bp; /* Only print if there are unknown bits */ TCHECK(cmu->v_flags); diff --git a/contrib/tcpdump/print-cdp.c b/contrib/tcpdump/print-cdp.c index 53eff98..a73fc3f 100644 --- a/contrib/tcpdump/print-cdp.c +++ b/contrib/tcpdump/print-cdp.c @@ -26,7 +26,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-cdp.c,v 1.4 2000/07/29 07:27:54 assar Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-cdp.c,v 1.11 2001/09/17 21:57:56 fenner Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -47,141 +47,216 @@ static const char rcsid[] = #include "addrtoname.h" #include "extract.h" /* must come after interface.h */ -static void cdp_print_addr( const u_char * p, int l ); -static void cdp_print_prefixes( const u_char * p, int l ); +static int cdp_print_addr(const u_char *, int); +static int cdp_print_prefixes(const u_char *, int); -/* - * Returns non-zero IFF it succeeds in printing the header - */ void cdp_print(const u_char *p, u_int length, u_int caplen, const u_char *esrc, const u_char *edst) { - int i; + u_int i; int type, len; /* Cisco Discovery Protocol */ - - if ( caplen < 12 ) { + if (caplen < 4) { (void)printf("[|cdp]"); return; } - i=8; /* CDP data starts at offset 8 */ - printf ("CDP v%d, ttl=%ds", p[i], p[i+1] ); - i+=4; /* skip version, TTL and chksum */ + i = 0; /* CDP data starts at offset 0 */ + printf("CDP v%u, ttl=%us", p[i], p[i + 1]); + i += 4; /* skip version, TTL and chksum */ while (i < length) { - if ( i+4 > caplen ) { - printf("[!cdp]"); - return; - } - type = (p[i]<<8) + p[i+1]; - len = (p[i+2]<<8) + p[i+3]; + if (i + 4 > caplen) + goto trunc; + type = (p[i] << 8) + p[i + 1]; + len = (p[i + 2] << 8) + p[i + 3]; - if ( vflag ) - printf( "\n\t%02x/%02x", type, len ); - else - printf( "\n\t" ); + if (vflag > 1) + printf("\n\t"); - if ( i+len > caplen ) { - printf("[!cdp]"); - return; - } - - switch( type ) - { - case 0x01: - printf( " DevID '%.*s'", len-4, p+i+4 ); - break; - case 0x02: - printf( " Addr" ); - cdp_print_addr( p+i+4, len-4 ); - break; - case 0x03: - printf( " PortID '%.*s'", len-4, p+i+4 ); - break; - case 0x04: - printf( " CAP 0x%02x", (unsigned) p[i+7] ); - break; - case 0x05: - if ( vflag ) - printf( " Version:\n%.*s", len-4, p+i+4 ); - else - printf( " Version: (suppressed)" ); - break; - case 0x06: - printf( " Platform: '%.*s'", len-4, p+i+4 ); - break; - case 0x07: - cdp_print_prefixes( p+i+4, len-4 ); - break; - case 0x09: /* guess - not documented */ - printf( " VTP Management Domain: '%.*s'", len-4, p+i+4 ); - break; - case 0x0a: /* guess - not documented */ - printf( " Native VLAN ID: %d", (p[i+4]<<8) + p[i+4+1] - 1 ); - break; - case 0x0b: /* guess - not documented */ - printf( " Duplex: %s", p[i+4] ? "full": "half" ); - break; - default: - printf( " unknown field type %02x, len %d", type, len ); - } - - /* avoid infinite loop */ - if (len == 0) - break; - i+=len; + if (vflag) + printf(" %02x/%02x", type, len); + + if (i + len > caplen) + goto trunc; + + switch (type) { + case 0x00: + printf(" Goodbye"); + break; + case 0x01: + printf(" DevID '%.*s'", len - 4, p + i + 4); + break; + case 0x02: + printf(" Addr"); + if (cdp_print_addr(p + i + 4, len - 4) < 0) + goto trunc; + break; + case 0x03: + printf(" PortID '%.*s'", len - 4, p + i + 4); + break; + case 0x04: + printf(" CAP 0x%02x", (unsigned) p[i + 7]); + break; + case 0x05: + if (vflag > 1) + printf(" Version:\n%.*s", len - 4, p + i + 4); + else + printf(" Version: (suppressed)"); + break; + case 0x06: + printf(" Platform: '%.*s'", len - 4, p + i + 4); + break; + case 0x07: + if (cdp_print_prefixes(p + i + 4, len - 4) < 0) + goto trunc; + break; + case 0x09: /* guess - not documented */ + printf(" VTP Management Domain: '%.*s'", len - 4, + p + i + 4); + break; + case 0x0a: /* guess - not documented */ + printf(" Native VLAN ID: %d", + (p[i + 4] << 8) + p[i + 4 + 1] - 1); + break; + case 0x0b: /* guess - not documented */ + printf(" Duplex: %s", p[i + 4] ? "full": "half"); + break; + default: + printf(" unknown field type %02x, len %d", type, len); + break; + } + + /* avoid infinite loop */ + if (len == 0) + break; + i += len; } + + return; + +trunc: + printf("[|cdp]"); } -static void -cdp_print_addr( const u_char * p, int l ) +/* + * Protocol type values. + * + * PT_NLPID means that the protocol type field contains an OSI NLPID. + * + * PT_IEEE_802_2 means that the protocol type field contains an IEEE 802.2 + * LLC header that specifies that the payload is for that protocol. + */ +#define PT_NLPID 1 /* OSI NLPID */ +#define PT_IEEE_802_2 2 /* IEEE 802.2 LLC header */ + +static int +cdp_print_addr(const u_char * p, int l) { - int pl, al, num; - const u_char * endp = p+l; - - num = (p[0] << 24) + (p[1]<<16) + (p[2]<<8)+ p[3]; - p+=4; - - printf(" (%d): ", num ); - - while( p < endp && num >= 0) { - pl=*(p+1); - p+=2; - - /* special case: IPv4, protocol type=0xcc, addr. length=4 */ - if ( pl == 1 && *p == 0xcc && - p[1] == 0 && p[2] == 4 ) { - p+=3; - - printf( "IPv4 %d.%d.%d.%d ", p[0], p[1], p[2], p[3] ); - p+=4; - } else { /* generic case: just print raw data */ - printf("pt=0x%02x, pl=%d, pb=", *(p-2), pl); - while( pl-- > 0 ) - printf( " %02x", *p++); - al=(*p << 8) + *(p+1); - printf( ", al=%d, a=", al ); - p+=2; - while( al-- > 0 ) - printf( " %02x", *p++); + int pt, pl, al, num; + const u_char *endp = p + l; +#ifdef INET6 + static u_char prot_ipv6[] = { + 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x86, 0xdd + }; +#endif + + num = EXTRACT_32BITS(p); + p += 4; + + printf(" (%d): ", num); + + while (p < endp && num >= 0) { + if (p + 2 > endp) + goto trunc; + pt = p[0]; /* type of "protocol" field */ + pl = p[1]; /* length of "protocol" field */ + p += 2; + + if (p + pl + 2 > endp) + goto trunc; + al = EXTRACT_16BITS(&p[pl]); /* address length */ + + if (pt == PT_NLPID && pl == 1 && *p == 0xcc && al == 4) { + /* + * IPv4: protocol type = NLPID, protocol length = 1 + * (1-byte NLPID), protocol = 0xcc (NLPID for IPv4), + * address length = 4 + */ + p += 3; + + if (p + 4 > endp) + goto trunc; + printf("IPv4 %u.%u.%u.%u", p[0], p[1], p[2], p[3]); + p += 4; + } +#ifdef INET6 + else if (pt == PT_IEEE_802_2 && pl == 8 && + memcmp(p, prot_ipv6, 8) == 0 && al == 16) { + /* + * IPv6: protocol type = IEEE 802.2 header, + * protocol length = 8 (size of LLC+SNAP header), + * protocol = LLC+SNAP header with the IPv6 + * Ethertype, address length = 16 + */ + p += 10; + if (p + al > endp) + goto trunc; + + printf("IPv6 %s", ip6addr_string(p)); + p += al; + } +#endif + else { + /* + * Generic case: just print raw data + */ + if (p + pl > endp) + goto trunc; + printf("pt=0x%02x, pl=%d, pb=", *(p - 2), pl); + while (pl-- > 0) + printf(" %02x", *p++); + if (p + 2 > endp) + goto trunc; + al = (*p << 8) + *(p + 1); + printf(", al=%d, a=", al); + p += 2; + if (p + al > endp) + goto trunc; + while (al-- > 0) + printf(" %02x", *p++); } - printf(" "); num--; + if (num) + printf(" "); } + + return 0; + +trunc: + return -1; } -static void -cdp_print_prefixes( const u_char * p, int l ) +static int +cdp_print_prefixes(const u_char * p, int l) { - printf( " IPv4 Prefixes (%d):", l/5 ); + if (l % 5) + goto trunc; + + printf(" IPv4 Prefixes (%d):", l / 5); + + while (l > 0) { + printf(" %u.%u.%u.%u/%u", p[0], p[1], p[2], p[3], p[4]); + l -= 5; + p += 5; + } + + return 0; - while(l > 0) { - printf( " %d.%d.%d.%d/%d", p[0], p[1], p[2], p[3], p[4] ); - l-=5; p+=5; - } +trunc: + return -1; } diff --git a/contrib/tcpdump/print-chdlc.c b/contrib/tcpdump/print-chdlc.c index 09c58ab..f6ff533 100644 --- a/contrib/tcpdump/print-chdlc.c +++ b/contrib/tcpdump/print-chdlc.c @@ -22,7 +22,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-chdlc.c,v 1.11 2000/10/09 01:53:19 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-chdlc.c,v 1.13 2001/09/17 21:57:57 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -42,6 +42,7 @@ static const char rcsid[] = #include "interface.h" #include "addrtoname.h" #include "ethertype.h" +#include "extract.h" #include "ppp.h" #include "chdlc.h" @@ -54,25 +55,38 @@ chdlc_if_print(u_char *user, const struct pcap_pkthdr *h, { register u_int length = h->len; register u_int caplen = h->caplen; - const struct ip *ip; - u_int proto; + ++infodelay; ts_print(&h->ts); - if (caplen < CHDLC_HDRLEN) { - printf("[|chdlc]"); - goto out; - } - /* * Some printers want to get back at the link level addresses, * and/or check that they're not walking off the end of the packet. * Rather than pass them all the way down, we set these globals. */ - proto = ntohs(*(u_short *)&p[2]); packetp = p; snapend = p + caplen; + chdlc_print(p, length, caplen); + + putchar('\n'); + --infodelay; + if (infoprint) + info(0); +} + +void +chdlc_print(register const u_char *p, u_int length, u_int caplen) +{ + const struct ip *ip; + u_int proto; + + if (caplen < CHDLC_HDRLEN) { + printf("[|chdlc]"); + return; + } + + proto = EXTRACT_16BITS(&p[2]); if (eflag) { switch (p[0]) { case CHDLC_UNICAST: @@ -89,7 +103,7 @@ chdlc_if_print(u_char *user, const struct pcap_pkthdr *h, } length -= CHDLC_HDRLEN; - ip = (struct ip *)(p + CHDLC_HDRLEN); + ip = (const struct ip *)(p + CHDLC_HDRLEN); switch (proto) { case ETHERTYPE_IP: ip_print((const u_char *)ip, length); @@ -110,8 +124,6 @@ chdlc_if_print(u_char *user, const struct pcap_pkthdr *h, } if (xflag) default_print((const u_char *)ip, caplen - CHDLC_HDRLEN); -out: - putchar('\n'); } struct cisco_slarp { @@ -140,14 +152,14 @@ struct cisco_slarp { static void chdlc_slarp_print(const u_char *cp, u_int length) { - struct cisco_slarp *slarp; + const struct cisco_slarp *slarp; if (length < SLARP_LEN) { printf("[|slarp]"); return; } - slarp = (struct cisco_slarp *)cp; + slarp = (const struct cisco_slarp *)cp; switch (ntohl(slarp->code)) { case SLARP_REQUEST: printf("slarp-request"); diff --git a/contrib/tcpdump/print-cip.c b/contrib/tcpdump/print-cip.c index 1d244c2..40228cd 100644 --- a/contrib/tcpdump/print-cip.c +++ b/contrib/tcpdump/print-cip.c @@ -22,13 +22,15 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-cip.c,v 1.11 2000/12/22 22:45:10 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-cip.c,v 1.16 2001/09/23 21:52:38 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include <string.h> + #include <sys/param.h> #include <sys/time.h> #include <sys/types.h> @@ -45,9 +47,6 @@ static const char rcsid[] = #include "ethertype.h" #include "ether.h" -const u_char *packetp; -const u_char *snapend; - #define RFC1483LLC_LEN 8 static unsigned char rfcllc[] = { @@ -61,25 +60,10 @@ static unsigned char rfcllc[] = { static inline void cip_print(register const u_char *bp, int length) { - int i; - - if (memcmp(rfcllc, bp, sizeof(rfcllc))) { - if (qflag) { - for (i = 0;i < RFC1483LLC_LEN; i++) - (void)printf("%2.2x ",bp[i]); - } else { - for (i = 0;i < RFC1483LLC_LEN - 2; i++) - (void)printf("%2.2x ",bp[i]); - etherproto_string(((u_short*)bp)[3]); - } - } else { - if (qflag) - (void)printf("(null encapsulation)"); - else { - (void)printf("(null encap)"); - etherproto_string(ETHERTYPE_IP); - } - } + /* + * There is no MAC-layer header, so just print the length. + */ + printf("%d: ", length); } /* @@ -91,12 +75,11 @@ cip_print(register const u_char *bp, int length) void cip_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) { - int caplen = h->caplen; - int length = h->len; - u_short ether_type; + u_int caplen = h->caplen; + u_int length = h->len; u_short extracted_ethertype; - u_short *bp; + ++infodelay; ts_print(&h->ts); if (memcmp(rfcllc, p, sizeof(rfcllc))==0 && caplen < RFC1483LLC_LEN) { @@ -115,28 +98,15 @@ cip_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) packetp = p; snapend = p + caplen; - if (memcmp(rfcllc, p, sizeof(rfcllc))==0) { - length -= RFC1483LLC_LEN; - caplen -= RFC1483LLC_LEN; - bp = (u_short *)p; - p += RFC1483LLC_LEN; - ether_type = ntohs(bp[3]); - } else { - ether_type = ETHERTYPE_IP; - bp = (u_short *)p; - } - - /* - * Is it (gag) an 802.3 encapsulation? - */ - extracted_ethertype = 0; - if (ether_type < ETHERMTU) { - /* Try to print the LLC-layer header & higher layers */ + if (memcmp(rfcllc, p, sizeof(rfcllc)) == 0) { + /* + * LLC header is present. Try to print it & higher layers. + */ if (llc_print(p, length, caplen, NULL, NULL, - &extracted_ethertype)==0) { + &extracted_ethertype) == 0) { /* ether_type not known, print raw packet */ if (!eflag) - cip_print((u_char *)bp, length + RFC1483LLC_LEN); + cip_print(p, length); if (extracted_ethertype) { printf("(LLC %s) ", etherproto_string(htons(extracted_ethertype))); @@ -144,16 +114,18 @@ cip_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) if (!xflag && !qflag) default_print(p, caplen); } - } else if (ether_encap_print(ether_type, p, length, caplen, - &extracted_ethertype) == 0) { - /* ether_type not known, print raw packet */ - if (!eflag) - cip_print((u_char *)bp, length + RFC1483LLC_LEN); - if (!xflag && !qflag) - default_print(p, caplen); + } else { + /* + * LLC header is absent; treat it as just IP. + */ + ip_print(p, length); } + if (xflag) default_print(p, caplen); out: putchar('\n'); + --infodelay; + if (infoprint) + info(0); } diff --git a/contrib/tcpdump/print-cnfp.c b/contrib/tcpdump/print-cnfp.c index 265599c..206438e 100644 --- a/contrib/tcpdump/print-cnfp.c +++ b/contrib/tcpdump/print-cnfp.c @@ -34,7 +34,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-cnfp.c,v 1.6 2000/09/23 08:26:32 guy Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-cnfp.c,v 1.8 2001/09/17 21:57:58 fenner Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -78,8 +78,8 @@ struct nfrec { u_int32_t ports; /* src,dst ports */ u_int32_t proto_tos; /* proto, tos, pad, flags(v5) */ u_int32_t asses; /* v1: flags; v5: src,dst AS */ - u_int32_t masks; /* src,dst addr prefix */ - + u_int32_t masks; /* src,dst addr prefix; v6: encaps */ + struct in_addr peer_nexthop; /* v6: IP address of the nexthop within the peer (FIB)*/ }; void @@ -92,10 +92,10 @@ cnfp_print(const u_char *cp, u_int len, const u_char *bp) int nrecs, ver; time_t t; - ip = (struct ip *)bp; - nh = (struct nfhdr *)cp; + ip = (const struct ip *)bp; + nh = (const struct nfhdr *)cp; - if ((u_char *)(nh + 1) > snapend) + if ((const u_char *)(nh + 1) > snapend) return; nrecs = ntohl(nh->ver_cnt) & 0xffff; @@ -108,18 +108,18 @@ cnfp_print(const u_char *cp, u_int len, const u_char *bp) (unsigned)ntohl(nh->msys_uptime)%1000, (unsigned)ntohl(nh->utc_sec), (unsigned)ntohl(nh->utc_nsec)); - if (ver == 5) { + if (ver == 5 || ver == 6) { printf("#%u, ", (unsigned)htonl(nh->sequence)); - nr = (struct nfrec *)&nh[1]; + nr = (const struct nfrec *)&nh[1]; snaplen -= 24; } else { - nr = (struct nfrec *)&nh->sequence; + nr = (const struct nfrec *)&nh->sequence; snaplen -= 16; } printf("%2u recs", nrecs); - for (; nrecs-- && (u_char *)(nr + 1) <= snapend; nr++) { + for (; nrecs-- && (const u_char *)(nr + 1) <= snapend; nr++) { char buf[20]; char asbuf[20]; @@ -130,19 +130,19 @@ cnfp_print(const u_char *cp, u_int len, const u_char *bp) (unsigned)ntohl(nr->last_time)%1000); asbuf[0] = buf[0] = '\0'; - if (ver == 5) { + if (ver == 5 || ver == 6) { snprintf(buf, sizeof(buf), "/%u", (unsigned)(ntohl(nr->masks) >> 24) & 0xff); - snprintf(asbuf, sizeof(asbuf), "%u:", + snprintf(asbuf, sizeof(asbuf), ":%u", (unsigned)(ntohl(nr->asses) >> 16) & 0xffff); } printf("\n %s%s%s:%u ", inet_ntoa(nr->src_ina), buf, asbuf, (unsigned)ntohl(nr->ports) >> 16); - if (ver == 5) { + if (ver == 5 || ver ==6) { snprintf(buf, sizeof(buf), "/%d", (unsigned)(ntohl(nr->masks) >> 16) & 0xff); - snprintf(asbuf, sizeof(asbuf), "%u:", + snprintf(asbuf, sizeof(asbuf), ":%u", (unsigned)ntohl(nr->asses) & 0xffff); } printf("> %s%s%s:%u ", inet_ntoa(nr->dst_ina), buf, asbuf, @@ -173,9 +173,16 @@ cnfp_print(const u_char *cp, u_int len, const u_char *bp) if (flags) putchar(' '); } - printf("tos %u, %u (%u octets)", + + buf[0]='\0'; + if (ver == 6) { + snprintf(buf, sizeof(buf), "(%u<>%u encaps)", + (unsigned)(ntohl(nr->masks) >> 8) & 0xff, + (unsigned)(ntohl(nr->masks)) & 0xff); + } + printf("tos %u, %u (%u octets) %s", (unsigned)ntohl(nr->proto_tos) & 0xff, (unsigned)ntohl(nr->packets), - (unsigned)ntohl(nr->octets)); + (unsigned)ntohl(nr->octets), buf); } } diff --git a/contrib/tcpdump/print-decnet.c b/contrib/tcpdump/print-decnet.c index d589bc9..8c51a67 100644 --- a/contrib/tcpdump/print-decnet.c +++ b/contrib/tcpdump/print-decnet.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-decnet.c,v 1.30 2000/09/28 06:42:57 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-decnet.c,v 1.33 2001/09/17 21:57:59 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -730,7 +730,7 @@ print_reason(register int reason) printf("%s ", tok2str(reason2str, "reason-%d", reason)); } -char * +const char * dnnum_string(u_short dnaddr) { char *str; @@ -745,7 +745,7 @@ dnnum_string(u_short dnaddr) return(str); } -char * +const char * dnname_string(u_short dnaddr) { #ifdef HAVE_LIBDNET @@ -753,7 +753,7 @@ dnname_string(u_short dnaddr) dna.a_len = sizeof(short); memcpy((char *)dna.a_addr, (char *)&dnaddr, sizeof(short)); - return (savestr(dnet_htoa(&dna))); + return (strdup(dnet_htoa(&dna))); #else return(dnnum_string(dnaddr)); /* punt */ #endif @@ -768,10 +768,7 @@ pdata(u_char *dp, u_int maxlen) while (x-- > 0) { c = *dp++; - if (isprint(c)) - putchar(c); - else - printf("\\%o", c & 0xFF); + safeputchar(c); } } #endif diff --git a/contrib/tcpdump/print-dhcp6.c b/contrib/tcpdump/print-dhcp6.c index c9848f0..e42febf 100644 --- a/contrib/tcpdump/print-dhcp6.c +++ b/contrib/tcpdump/print-dhcp6.c @@ -29,7 +29,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-dhcp6.c,v 1.12 2000/10/24 00:56:50 fenner Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-dhcp6.c,v 1.14 2001/09/17 21:57:59 fenner Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -56,12 +56,12 @@ struct rtentry; #include "dhcp6opt.h" #if 0 -static void dhcp6opttab_init (void); -static struct dhcp6_opt *dhcp6opttab_byname (char *); +static void dhcp6opttab_init(void); +static struct dhcp6_opt *dhcp6opttab_byname(char *); #endif -static struct dhcp6_opt *dhcp6opttab_bycode (u_int); +static struct dhcp6_opt *dhcp6opttab_bycode(u_int); -static char tstr[] = " [|dhcp6]"; +static const char tstr[] = " [|dhcp6]"; static struct dhcp6_opt dh6opttab[] = { /* IP Address Extension */ diff --git a/contrib/tcpdump/print-domain.c b/contrib/tcpdump/print-domain.c index 77140c4..ee785f2 100644 --- a/contrib/tcpdump/print-domain.c +++ b/contrib/tcpdump/print-domain.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.64.2.1 2001/02/21 09:01:20 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.78 2001/10/19 09:00:48 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -33,12 +33,6 @@ static const char rcsid[] = #include <netinet/in.h> -#ifdef NOERROR -#undef NOERROR /* Solaris sucks */ -#endif -#ifdef NOERROR -#undef T_UNSPEC /* SINIX does too */ -#endif #include "nameser.h" #include <stdio.h> @@ -48,102 +42,16 @@ static const char rcsid[] = #include "addrtoname.h" #include "extract.h" /* must come after interface.h */ -/* Compatibility */ -#ifndef T_TXT -#define T_TXT 16 /* text strings */ -#endif -#ifndef T_RP -#define T_RP 17 /* responsible person */ -#endif -#ifndef T_AFSDB -#define T_AFSDB 18 /* AFS cell database */ -#endif -#ifndef T_X25 -#define T_X25 19 /* X_25 calling address */ -#endif -#ifndef T_ISDN -#define T_ISDN 20 /* ISDN calling address */ -#endif -#ifndef T_RT -#define T_RT 21 /* router */ -#endif -#ifndef T_NSAP -#define T_NSAP 22 /* NSAP address */ -#endif -#ifndef T_NSAP_PTR -#define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */ -#endif -#ifndef T_SIG -#define T_SIG 24 /* security signature */ -#endif -#ifndef T_KEY -#define T_KEY 25 /* security key */ -#endif -#ifndef T_PX -#define T_PX 26 /* X.400 mail mapping */ -#endif -#ifndef T_GPOS -#define T_GPOS 27 /* geographical position (withdrawn) */ -#endif -#ifndef T_AAAA -#define T_AAAA 28 /* IP6 Address */ -#endif -#ifndef T_LOC -#define T_LOC 29 /* Location Information */ -#endif -#ifndef T_NXT -#define T_NXT 30 /* Next Valid Name in Zone */ -#endif -#ifndef T_EID -#define T_EID 31 /* Endpoint identifier */ -#endif -#ifndef T_NIMLOC -#define T_NIMLOC 32 /* Nimrod locator */ -#endif -#ifndef T_SRV -#define T_SRV 33 /* Server selection */ -#endif -#ifndef T_ATMA -#define T_ATMA 34 /* ATM Address */ -#endif -#ifndef T_NAPTR -#define T_NAPTR 35 /* Naming Authority PoinTeR */ -#endif -#ifndef T_A6 -#define T_A6 38 /* IP6 address */ -#endif -#ifndef T_DNAME -#define T_DNAME 39 /* non-terminal redirection */ -#endif - -#ifndef T_OPT -#define T_OPT 41 /* EDNS0 option (meta-RR) */ -#endif - -#ifndef T_UNSPEC -#define T_UNSPEC 103 /* Unspecified format (binary data) */ -#endif -#ifndef T_UNSPECA -#define T_UNSPECA 104 /* "unspecified ascii". Ugly MIT hack */ -#endif - -#ifndef C_CHAOS -#define C_CHAOS 3 /* for chaos net (MIT) */ -#endif -#ifndef C_HS -#define C_HS 4 /* for Hesiod name server (MIT) (XXX) */ -#endif - -static char *ns_ops[] = { - "", " inv_q", " stat", " op3", " notify", " op5", " op6", " op7", +static const char *ns_ops[] = { + "", " inv_q", " stat", " op3", " notify", " update", " op6", " op7", " op8", " updataA", " updateD", " updateDA", " updateM", " updateMA", " zoneInit", " zoneRef", }; -static char *ns_resp[] = { +static const char *ns_resp[] = { "", " FormErr", " ServFail", " NXDomain", - " NotImp", " Refused", " Resp6", " Resp7", - " Resp8", " Resp9", " Resp10", " Resp11", + " NotImp", " Refused", " YXDomain", " YXRRSet", + " NXRRSet", " NotAuth", " NotZone", " Resp11", " Resp12", " Resp13", " Resp14", " NoChange", }; @@ -153,24 +61,26 @@ ns_nskip(register const u_char *cp, register const u_char *bp) { register u_char i; + if (!TTEST2(*cp, 1)) + return (NULL); if (((i = *cp++) & INDIR_MASK) == INDIR_MASK) return (cp + 1); - if (cp >= snapend) - return(NULL); - while (i && cp < snapend) { + while (i) { if ((i & INDIR_MASK) == EDNS0_MASK) { int bitlen, bytelen; if ((i & ~INDIR_MASK) != EDNS0_ELT_BITLABEL) return(NULL); /* unknown ELT */ + if (!TTEST2(*cp, 1)) + return (NULL); if ((bitlen = *cp++) == 0) bitlen = 256; bytelen = (bitlen + 7) / 8; cp += bytelen; } else cp += i; - if (cp >= snapend) - return(NULL); + if (!TTEST2(*cp, 1)) + return (NULL); i = *cp++; } return (cp); @@ -185,7 +95,7 @@ blabel_print(const u_char *cp) const u_char *bitp, *lim; char tc; - if (cp >= snapend) + if (!TTEST2(*cp, 1)) return(NULL); if ((bitlen = *cp) == 0) bitlen = 256; @@ -218,7 +128,7 @@ labellen(const u_char *cp) { register u_int i; - if (cp >= snapend) + if (!TTEST2(*cp, 1)) return(-1); i = *cp; if ((i & INDIR_MASK) == EDNS0_MASK) { @@ -226,7 +136,7 @@ labellen(const u_char *cp) if ((elt = (i & ~INDIR_MASK)) != EDNS0_ELT_BITLABEL) return(-1); - if (cp + 1 >= snapend) + if (!TTEST2(*(cp + 1), 1)) return(-1); if ((bitlen = *(cp + 1)) == 0) bitlen = 256; @@ -247,7 +157,7 @@ ns_nprint(register const u_char *cp, register const u_char *bp) if ((l = labellen(cp)) < 0) return(NULL); - if (cp >= snapend) + if (!TTEST2(*cp, 1)) return(NULL); chars_processed = 1; if (((i = *cp++) & INDIR_MASK) != INDIR_MASK) { @@ -262,11 +172,13 @@ ns_nprint(register const u_char *cp, register const u_char *bp) rp = cp + 1; compress = 1; } - cp = bp + (((i << 8) | *cp) & 0x3fff); - if (cp >= snapend) + if (!TTEST2(*cp, 1)) return(NULL); + cp = bp + (((i << 8) | *cp) & 0x3fff); if ((l = labellen(cp)) < 0) return(NULL); + if (!TTEST2(*cp, 1)) + return(NULL); i = *cp++; chars_processed++; @@ -286,7 +198,8 @@ ns_nprint(register const u_char *cp, register const u_char *bp) elt = (i & ~INDIR_MASK); switch(elt) { case EDNS0_ELT_BITLABEL: - blabel_print(cp); + if (blabel_print(cp) == NULL) + return (NULL); break; default: /* unknown ELT */ @@ -295,13 +208,15 @@ ns_nprint(register const u_char *cp, register const u_char *bp) } } else { if (fn_printn(cp, l, snapend)) - break; + return(NULL); } cp += l; chars_processed += l; putchar('.'); - if (cp >= snapend || (l = labellen(cp)) < 0) + if ((l = labellen(cp)) < 0) + return(NULL); + if (!TTEST2(*cp, 1)) return(NULL); i = *cp++; chars_processed++; @@ -319,14 +234,15 @@ ns_cprint(register const u_char *cp, register const u_char *bp) { register u_int i; - if (cp >= snapend) - return NULL; + if (!TTEST2(*cp, 1)) + return (NULL); i = *cp++; - (void)fn_printn(cp, i, snapend); + if (fn_printn(cp, i, snapend)) + return (NULL); return (cp + i); } -static struct tok type2str[] = { +struct tok ns_type2str[] = { { T_A, "A" }, { T_NS, "NS" }, { T_MD, "MD" }, @@ -355,21 +271,24 @@ static struct tok type2str[] = { { T_PX, "PX" }, { T_GPOS, "GPOS" }, { T_AAAA, "AAAA" }, - { T_LOC, "LOC " }, - { T_NXT, "NXT " }, - { T_EID, "EID " }, - { T_NIMLOC, "NIMLOC " }, - { T_SRV, "SRV " }, - { T_ATMA, "ATMA " }, - { T_NAPTR, "NAPTR " }, - { T_A6, "A6 " }, - { T_DNAME, "DNAME " }, - { T_OPT, "OPT " }, + { T_LOC, "LOC" }, + { T_NXT, "NXT" }, + { T_EID, "EID" }, + { T_NIMLOC, "NIMLOC" }, + { T_SRV, "SRV" }, + { T_ATMA, "ATMA" }, + { T_NAPTR, "NAPTR" }, + { T_A6, "A6" }, + { T_DNAME, "DNAME" }, + { T_OPT, "OPT" }, { T_UINFO, "UINFO" }, { T_UID, "UID" }, { T_GID, "GID" }, { T_UNSPEC, "UNSPEC" }, { T_UNSPECA, "UNSPECA" }, + { T_TKEY, "TKEY" }, + { T_TSIG, "TSIG" }, + { T_IXFR, "IXFR" }, { T_AXFR, "AXFR" }, { T_MAILB, "MAILB" }, { T_MAILA, "MAILA" }, @@ -377,9 +296,9 @@ static struct tok type2str[] = { { 0, NULL } }; -static struct tok class2str[] = { +struct tok ns_class2str[] = { { C_IN, "IN" }, /* Not used */ - { C_CHAOS, "CHAOS)" }, + { C_CHAOS, "CHAOS" }, { C_HS, "HS" }, { C_ANY, "ANY" }, { 0, NULL } @@ -394,17 +313,17 @@ ns_qprint(register const u_char *cp, register const u_char *bp) cp = ns_nskip(cp, bp); - if (cp + 4 > snapend || cp == NULL) + if (cp == NULL || !TTEST2(*cp, 4)) return(NULL); /* print the qtype and qclass (if it's not IN) */ i = *cp++ << 8; i |= *cp++; - printf(" %s", tok2str(type2str, "Type%d", i)); + printf(" %s", tok2str(ns_type2str, "Type%d", i)); i = *cp++ << 8; i |= *cp++; if (i != C_IN) - printf(" %s", tok2str(class2str, "(Class %d)", i)); + printf(" %s", tok2str(ns_class2str, "(Class %d)", i)); fputs("? ", stdout); cp = ns_nprint(np, bp); @@ -426,7 +345,7 @@ ns_rprint(register const u_char *cp, register const u_char *bp) } else cp = ns_nskip(cp, bp); - if (cp + 10 > snapend || cp == NULL) + if (cp == NULL || !TTEST2(*cp, 10)) return (snapend); /* print the type/qtype and class (if it's not IN) */ @@ -435,7 +354,7 @@ ns_rprint(register const u_char *cp, register const u_char *bp) class = *cp++ << 8; class |= *cp++; if (class != C_IN && typ != T_OPT) - printf(" %s", tok2str(class2str, "(Class %d)", class)); + printf(" %s", tok2str(ns_class2str, "(Class %d)", class)); /* ignore ttl */ cp += 4; @@ -445,13 +364,13 @@ ns_rprint(register const u_char *cp, register const u_char *bp) rp = cp + len; - printf(" %s", tok2str(type2str, "Type%d", typ)); + printf(" %s", tok2str(ns_type2str, "Type%d", typ)); if (rp > snapend) return(NULL); switch (typ) { case T_A: - if (cp + sizeof(struct in_addr) > snapend) + if (!TTEST2(*cp, sizeof(struct in_addr))) return(NULL); printf(" %s", ipaddr_string(cp)); break; @@ -476,7 +395,7 @@ ns_rprint(register const u_char *cp, register const u_char *bp) putchar(' '); if ((cp = ns_nprint(cp, bp)) == NULL) return(NULL); - if (cp + 5 * 4 > snapend) + if (!TTEST2(*cp, 5 * 4)) return(NULL); printf(" %u", EXTRACT_32BITS(cp)); cp += 4; @@ -491,7 +410,7 @@ ns_rprint(register const u_char *cp, register const u_char *bp) break; case T_MX: putchar(' '); - if (cp + 2 > snapend) + if (!TTEST2(*cp, 2)) return(NULL); if (ns_nprint(cp + 2, bp) == NULL) return(NULL); @@ -505,7 +424,7 @@ ns_rprint(register const u_char *cp, register const u_char *bp) #ifdef INET6 case T_AAAA: - if (cp + sizeof(struct in6_addr) > snapend) + if (!TTEST2(*cp, sizeof(struct in6_addr))) return(NULL); printf(" %s", ip6addr_string(cp)); break; @@ -515,12 +434,16 @@ ns_rprint(register const u_char *cp, register const u_char *bp) struct in6_addr a; int pbit, pbyte; + if (!TTEST2(*cp, 1)) + return(NULL); pbit = *cp; pbyte = (pbit & ~7) / 8; if (pbit > 128) { printf(" %u(bad plen)", pbit); break; } else if (pbit < 128) { + if (!TTEST2(*(cp + 1), sizeof(a) - pbyte)) + return(NULL); memset(&a, 0, sizeof(a)); memcpy(&a.s6_addr[pbyte], cp + 1, sizeof(a) - pbyte); printf(" %u %s", pbit, ip6addr_string(&a)); @@ -539,10 +462,43 @@ ns_rprint(register const u_char *cp, register const u_char *bp) break; case T_UNSPECA: /* One long string */ - if (cp + len > snapend) + if (!TTEST2(*cp, len)) + return(NULL); + if (fn_printn(cp, len, snapend)) return(NULL); - fn_printn(cp, len, snapend); break; + + case T_TSIG: + { + if (cp + len > snapend) + return(NULL); + if (!vflag) + break; + putchar(' '); + if ((cp = ns_nprint(cp, bp)) == NULL) + return(NULL); + cp += 6; + if (!TTEST2(*cp, 2)) + return(NULL); + printf(" fudge=%u", EXTRACT_16BITS(cp)); + cp += 2; + if (!TTEST2(*cp, 2)) + return(NULL); + printf(" maclen=%u", EXTRACT_16BITS(cp)); + cp += 2 + EXTRACT_16BITS(cp); + if (!TTEST2(*cp, 2)) + return(NULL); + printf(" origid=%u", EXTRACT_16BITS(cp)); + cp += 2; + if (!TTEST2(*cp, 2)) + return(NULL); + printf(" error=%u", EXTRACT_16BITS(cp)); + cp += 2; + if (!TTEST2(*cp, 2)) + return(NULL); + printf(" otherlen=%u", EXTRACT_16BITS(cp)); + cp += 2; + } } return (rp); /* XXX This isn't always right */ } @@ -552,7 +508,7 @@ ns_print(register const u_char *bp, u_int length) { register const HEADER *np; register int qdcount, ancount, nscount, arcount; - register const u_char *cp = NULL; + register const u_char *cp; np = (const HEADER *)bp; TCHECK(*np); @@ -576,49 +532,58 @@ ns_print(register const u_char *bp, u_int length) if (qdcount != 1) printf(" [%dq]", qdcount); /* Print QUESTION section on -vv */ - if (vflag > 1) { - fputs(" q:", stdout); - if ((cp = ns_qprint((const u_char *)(np + 1), bp)) - == NULL) - goto trunc; - } else { - if ((cp = ns_nskip((const u_char *)(np + 1), bp)) - == NULL) - goto trunc; - cp += 4; + cp = (const u_char *)(np + 1); + while (qdcount--) { + if (qdcount < ntohs(np->qdcount) - 1) + putchar(','); + if (vflag > 1) { + fputs(" q:", stdout); + if ((cp = ns_qprint(cp, bp)) == NULL) + goto trunc; + } else { + if ((cp = ns_nskip(cp, bp)) == NULL) + goto trunc; + cp += 4; /* skip QTYPE and QCLASS */ + } } printf(" %d/%d/%d", ancount, nscount, arcount); if (ancount--) { if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; - while (ancount-- && cp < snapend) { + while (cp < snapend && ancount--) { putchar(','); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; } } + if (ancount > 0) + goto trunc; /* Print NS and AR sections on -vv */ if (vflag > 1) { - if (nscount-- && cp < snapend) { + if (cp < snapend && nscount--) { fputs(" ns:", stdout); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; - while (nscount-- && cp < snapend) { + while (cp < snapend && nscount--) { putchar(','); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; } } - if (arcount-- && cp < snapend) { + if (nscount > 0) + goto trunc; + if (cp < snapend && arcount--) { fputs(" ar:", stdout); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; - while (arcount-- && cp < snapend) { + while (cp < snapend && arcount--) { putchar(','); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; } } + if (arcount > 0) + goto trunc; } } else { @@ -648,35 +613,35 @@ ns_print(register const u_char *bp, u_int length) if (arcount) printf(" [%dau]", arcount); + cp = (const u_char *)(np + 1); if (qdcount--) { - cp = ns_qprint((const u_char *)(np + 1), - (const u_char *)np); + cp = ns_qprint(cp, (const u_char *)np); if (!cp) goto trunc; - if ((cp = ns_rprint(cp, bp)) == NULL) - goto trunc; - while (qdcount-- && cp < snapend) { + while (cp < snapend && qdcount--) { cp = ns_qprint((const u_char *)cp, (const u_char *)np); if (!cp) goto trunc; - if ((cp = ns_rprint(cp, bp)) == NULL) - goto trunc; } } + if (qdcount > 0) + goto trunc; /* Print remaining sections on -vv */ if (vflag > 1) { if (ancount--) { if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; - while (ancount-- && cp < snapend) { + while (cp < snapend && ancount--) { putchar(','); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; } } - if (nscount-- && cp < snapend) { + if (ancount > 0) + goto trunc; + if (cp < snapend && nscount--) { fputs(" ns:", stdout); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; @@ -686,16 +651,20 @@ ns_print(register const u_char *bp, u_int length) goto trunc; } } - if (arcount-- && cp < snapend) { + if (nscount > 0) + goto trunc; + if (cp < snapend && arcount--) { fputs(" ar:", stdout); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; - while (arcount-- && cp < snapend) { + while (cp < snapend && arcount--) { putchar(','); if ((cp = ns_rprint(cp, bp)) == NULL) goto trunc; } } + if (arcount > 0) + goto trunc; } } printf(" (%d)", length); diff --git a/contrib/tcpdump/print-dvmrp.c b/contrib/tcpdump/print-dvmrp.c index 04abc2c..273c7d6 100644 --- a/contrib/tcpdump/print-dvmrp.c +++ b/contrib/tcpdump/print-dvmrp.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-dvmrp.c,v 1.20 2000/09/29 04:58:36 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-dvmrp.c,v 1.21 2001/05/10 05:30:20 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -50,9 +50,7 @@ static const char rcsid[] = #define DVMRP_PROBE 1 /* for finding neighbors */ #define DVMRP_REPORT 2 /* for reporting some or all routes */ #define DVMRP_ASK_NEIGHBORS 3 /* sent by mapper, asking for a list */ - /* - * of this router's neighbors - */ + /* of this router's neighbors */ #define DVMRP_NEIGHBORS 4 /* response to such a request */ #define DVMRP_ASK_NEIGHBORS2 5 /* as above, want new format reply */ #define DVMRP_NEIGHBORS2 6 @@ -90,11 +88,9 @@ dvmrp_print(register const u_char *bp, register u_int len) return; type = bp[1]; - bp += 8; - /* - * Skip IGMP header - */ + /* Skip IGMP header */ + bp += 8; len -= 8; switch (type) { @@ -107,7 +103,7 @@ dvmrp_print(register const u_char *bp, register u_int len) case DVMRP_REPORT: printf(" Report"); - if (vflag) + if (vflag > 1) print_report(bp, ep, len); break; @@ -222,7 +218,13 @@ print_probe(register const u_char *bp, register const u_char *ep, genid = (bp[0] << 24) | (bp[1] << 16) | (bp[2] << 8) | bp[3]; bp += 4; len -= 4; - printf("\n\tgenid %u", genid); + if (vflag > 1) + printf("\n\t"); + else + printf(" "); + printf("genid %u", genid); + if (vflag < 2) + return; while ((len > 0) && (bp < ep)) { TCHECK2(bp[0], 4); diff --git a/contrib/tcpdump/print-egp.c b/contrib/tcpdump/print-egp.c index 5adb9ee..56dfb26 100644 --- a/contrib/tcpdump/print-egp.c +++ b/contrib/tcpdump/print-egp.c @@ -20,7 +20,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-egp.c,v 1.26 2000/09/29 04:58:36 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-egp.c,v 1.28 2001/09/17 21:58:01 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -99,7 +99,7 @@ struct egp_packet { #define egp_sourcenet egp_pands.egpu_sourcenet }; -char *egp_acquire_codes[] = { +const char *egp_acquire_codes[] = { "request", "confirm", "refuse", @@ -107,7 +107,7 @@ char *egp_acquire_codes[] = { "cease_ack" }; -char *egp_acquire_status[] = { +const char *egp_acquire_status[] = { "unspecified", "active_mode", "passive_mode", @@ -118,18 +118,18 @@ char *egp_acquire_status[] = { "protocol_violation" }; -char *egp_reach_codes[] = { +const char *egp_reach_codes[] = { "hello", "i-h-u" }; -char *egp_status_updown[] = { +const char *egp_status_updown[] = { "indeterminate", "up", "down" }; -char *egp_reasons[] = { +const char *egp_reasons[] = { "unspecified", "bad_EGP_header_format", "bad_EGP_data_field_format", @@ -230,9 +230,7 @@ egp_print(register const u_char *bp, register u_int length, egp = (struct egp_packet *)bp; ip = (struct ip *)bp2; - (void)printf("%s > %s: egp: ", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); + (void)printf("egp: "); if (egp->egp_version != EGP_VERSION) { printf("[version %d]", egp->egp_version); diff --git a/contrib/tcpdump/print-esp.c b/contrib/tcpdump/print-esp.c index 7ebad59..1bdf76a 100644 --- a/contrib/tcpdump/print-esp.c +++ b/contrib/tcpdump/print-esp.c @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-esp.c,v 1.17 2000/12/12 09:58:41 itojun Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-esp.c,v 1.20 2002/01/21 11:39:59 mcr Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -39,13 +39,13 @@ static const char rcsid[] = #include <netinet/in.h> #ifdef HAVE_LIBCRYPTO -#include <des.h> -#include <blowfish.h> +#include <openssl/des.h> +#include <openssl/blowfish.h> #ifdef HAVE_RC5_H -#include <rc5.h> +#include <openssl/rc5.h> #endif #ifdef HAVE_CAST_H -#include <cast.h> +#include <openssl/cast.h> #endif #endif @@ -57,28 +57,153 @@ static const char rcsid[] = #include "ip6.h" #endif +#define AVOID_CHURN 1 #include "interface.h" #include "addrtoname.h" +static struct esp_algorithm *espsecret_xform=NULL; /* cache of decoded alg. */ +static char *espsecret_key=NULL; + + +enum cipher { NONE, + DESCBC, + BLOWFISH, + RC5, + CAST128, + DES3CBC}; + + + +struct esp_algorithm { + char *name; + enum cipher algo; + int ivlen; + int authlen; + int replaysize; +}; + +struct esp_algorithm esp_xforms[]={ + {"none", NONE, 0, 0, 0}, + {"des-cbc", DESCBC, 8, 0, 0}, + {"des-cbc-hmac96", DESCBC, 8, 12, 4}, + {"blowfish-cbc", BLOWFISH,8, 0, 0}, + {"blowfish-cbc-hmac96", BLOWFISH,8, 12, 4}, + {"rc5-cbc", RC5, 8, 0, 0}, + {"rc5-cbc-hmac96", RC5, 8, 12, 4}, + {"cast128-cbc", CAST128, 8, 0, 0}, + {"cast128-cbc-hmac96", CAST128, 8, 12, 4}, + {"3des-cbc-hmac96", DES3CBC, 8, 12, 4}, +}; + +static int hexdigit(char hex) +{ + if(hex >= '0' && hex <= '9') { + return (hex - '0'); + } else if(hex >= 'A' && hex <= 'F') { + return (hex - 'A' + 10); + } else if(hex >= 'a' && hex <= 'f') { + return (hex - 'a' + 10); + } else { + printf("invalid hex digit %c in espsecret\n", hex); + return 0; + } +} + +static int hex2byte(char *hexstring) +{ + int byte; + + byte = (hexdigit(hexstring[0]) << 4) + + hexdigit(hexstring[1]); + return byte; +} + + +void esp_print_decodesecret() +{ + char *colon; + int len, i; + struct esp_algorithm *xf; + + if(espsecret == NULL) { + /* set to NONE transform */ + espsecret_xform = esp_xforms; + return; + } + + if(espsecret_key != NULL) { + return; + } + + colon = strchr(espsecret, ':'); + if(colon == NULL) { + printf("failed to decode espsecret: %s\n", + espsecret); + /* set to NONE transform */ + espsecret_xform = esp_xforms; + } + + len = colon - espsecret; + xf = esp_xforms; + while(xf->name && strncasecmp(espsecret, xf->name, len)!=0) { + xf++; + } + if(xf->name == NULL) { + printf("failed to find cipher algo %s\n", + espsecret); + espsecret_xform = esp_xforms; + return; + } + espsecret_xform = xf; + + colon++; + if(colon[0]=='0' && colon[1]=='x') { + /* decode some hex! */ + colon+=2; + len = strlen(colon) / 2; + espsecret_key = (char *)malloc(len); + if(espsecret_key == NULL) { + fprintf(stderr, "%s: ran out of memory (%d) to allocate secret key\n", + program_name, len); + exit(2); + } + i = 0; + while(colon[0] != '\0' && colon[1]!='\0') { + espsecret_key[i]=hex2byte(colon); + colon+=2; + i++; + } + } else { + espsecret_key = colon; + } +} + int -esp_print(register const u_char *bp, register const u_char *bp2, int *nhdr) +esp_print(register const u_char *bp, register const u_char *bp2, + int *nhdr, int *padlen) { register const struct esp *esp; register const u_char *ep; u_int32_t spi; - enum { NONE, DESCBC, BLOWFISH, RC5, CAST128, DES3CBC } algo = NONE; struct ip *ip = NULL; #ifdef INET6 struct ip6_hdr *ip6 = NULL; #endif int advance; int len; - char *secret = NULL; + char *secret; int ivlen = 0; u_char *ivoff; - + u_char *p; + esp = (struct esp *)bp; spi = (u_int32_t)ntohl(esp->esp_spi); + secret = NULL; + +#if 0 + /* keep secret out of a register */ + p = (u_char *)&secret; +#endif /* 'ep' points to the end of available data. */ ep = snapend; @@ -95,40 +220,11 @@ esp_print(register const u_char *bp, register const u_char *bp2, int *nhdr) if (!espsecret) goto fail; - if (strncmp(espsecret, "des-cbc:", 8) == 0 - && strlen(espsecret + 8) == 8) { - algo = DESCBC; - ivlen = 8; - secret = espsecret + 8; - } else if (strncmp(espsecret, "blowfish-cbc:", 13) == 0) { - algo = BLOWFISH; - ivlen = 8; - secret = espsecret + 13; - } else if (strncmp(espsecret, "rc5-cbc:", 8) == 0) { - algo = RC5; - ivlen = 8; - secret = espsecret + 8; - } else if (strncmp(espsecret, "cast128-cbc:", 12) == 0) { - algo = CAST128; - ivlen = 8; - secret = espsecret + 12; - } else if (strncmp(espsecret, "3des-cbc:", 9) == 0 - && strlen(espsecret + 9) == 24) { - algo = DES3CBC; - ivlen = 8; - secret = espsecret + 9; - } else if (strncmp(espsecret, "none:", 5) == 0) { - algo = NONE; - ivlen = 0; - secret = espsecret + 5; - } else if (strlen(espsecret) == 8) { - algo = DESCBC; - ivlen = 8; - secret = espsecret; - } else { - algo = NONE; - ivlen = 0; - secret = espsecret; + if(!espsecret_xform) { + esp_print_decodesecret(); + } + if(espsecret_xform->algo == NONE) { + goto fail; } ip = (struct ip *)bp2; @@ -145,6 +241,9 @@ esp_print(register const u_char *bp, register const u_char *bp2, int *nhdr) break; #endif /*INET6*/ case 4: + /* nexthdr & padding are in the last fragment */ + if (ntohs(ip->ip_off) & IP_MF) + goto fail; #ifdef INET6 ip6 = NULL; #endif @@ -158,18 +257,16 @@ esp_print(register const u_char *bp, register const u_char *bp2, int *nhdr) if (ep - bp2 < len) goto fail; - if (Rflag) - ivoff = (u_char *)(esp + 1) + sizeof(u_int32_t); - else - ivoff = (u_char *)(esp + 1); + ivoff = (u_char *)(esp + 1) + espsecret_xform->replaysize; + ivlen = espsecret_xform->ivlen; + secret = espsecret_key; - switch (algo) { + switch (espsecret_xform->algo) { case DESCBC: #ifdef HAVE_LIBCRYPTO { u_char iv[8]; des_key_schedule schedule; - u_char *p; switch (ivlen) { case 4: @@ -206,7 +303,6 @@ esp_print(register const u_char *bp, register const u_char *bp2, int *nhdr) #ifdef HAVE_LIBCRYPTO { BF_KEY schedule; - u_char *p; BF_set_key(&schedule, strlen(secret), secret); @@ -224,7 +320,6 @@ esp_print(register const u_char *bp, register const u_char *bp2, int *nhdr) #if defined(HAVE_LIBCRYPTO) && defined(HAVE_RC5_H) { RC5_32_KEY schedule; - u_char *p; RC5_32_set_key(&schedule, strlen(secret), secret, RC5_16_ROUNDS); @@ -243,7 +338,6 @@ esp_print(register const u_char *bp, register const u_char *bp2, int *nhdr) #if defined(HAVE_LIBCRYPTO) && defined(HAVE_CAST_H) && !defined(HAVE_BUGGY_CAST128) { CAST_KEY schedule; - u_char *p; CAST_set_key(&schedule, strlen(secret), secret); @@ -261,16 +355,26 @@ esp_print(register const u_char *bp, register const u_char *bp2, int *nhdr) #if defined(HAVE_LIBCRYPTO) { des_key_schedule s1, s2, s3; - u_char *p; - des_check_key = 0; - des_set_key((void *)secret, s1); - des_set_key((void *)(secret + 8), s2); - des_set_key((void *)(secret + 16), s3); + des_check_key = 1; + des_set_odd_parity((void *)secret); + des_set_odd_parity((void *)secret+8); + des_set_odd_parity((void *)secret+16); + if(des_set_key((void *)secret, s1) != 0) { + printf("failed to schedule key 1\n"); + } + if(des_set_key((void *)(secret + 8), s2)!=0) { + printf("failed to schedule key 2\n"); + } + if(des_set_key((void *)(secret + 16), s3)!=0) { + printf("failed to schedule key 3\n"); + } p = ivoff + ivlen; des_ede3_cbc_encrypt((void *)p, (void *)p, - (long)(ep - p), s1, s2, s3, (void *)ivoff, DES_DECRYPT); + (long)(ep - p), + s1, s2, s3, + (void *)ivoff, DES_DECRYPT); advance = ivoff - (u_char *)esp + ivlen; break; } @@ -280,17 +384,18 @@ esp_print(register const u_char *bp, register const u_char *bp2, int *nhdr) case NONE: default: - if (Rflag) - advance = sizeof(struct esp) + sizeof(u_int32_t); - else - advance = sizeof(struct esp); + advance = sizeof(struct esp) + espsecret_xform->replaysize; break; } + ep = ep - espsecret_xform->authlen; /* sanity check for pad length */ if (ep - bp < *(ep - 2)) goto fail; + if (padlen) + *padlen = *(ep - 2) + 2; + if (nhdr) *nhdr = *(ep - 1); diff --git a/contrib/tcpdump/print-ether.c b/contrib/tcpdump/print-ether.c index d10a86e..dc68f86 100644 --- a/contrib/tcpdump/print-ether.c +++ b/contrib/tcpdump/print-ether.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -20,7 +20,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.61 2000/12/22 22:45:10 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.65 2001/07/04 22:03:14 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -82,6 +82,7 @@ ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) u_short ether_type; u_short extracted_ethertype; + ++infodelay; ts_print(&h->ts); if (caplen < ETHER_HDRLEN) { @@ -137,6 +138,9 @@ ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) default_print(p, caplen); out: putchar('\n'); + --infodelay; + if (infoprint) + info(0); } /* @@ -226,6 +230,19 @@ ether_encap_print(u_short ethertype, const u_char *p, pppoe_print(p, length); return (1); + case ETHERTYPE_PPP: + printf("ppp"); + if (length) { + printf(": "); + ppp_print(p, length); + } + return (1); + + case ETHERTYPE_MPLS: + case ETHERTYPE_MPLS_MULTI: + mpls_print(p, length); + return (1); + case ETHERTYPE_LAT: case ETHERTYPE_SCA: case ETHERTYPE_MOPRC: diff --git a/contrib/tcpdump/print-fddi.c b/contrib/tcpdump/print-fddi.c index d0286de..a178f15 100644 --- a/contrib/tcpdump/print-fddi.c +++ b/contrib/tcpdump/print-fddi.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-fddi.c,v 1.50 2000/12/23 20:48:13 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-fddi.c,v 1.53 2001/11/14 16:46:34 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -52,7 +52,7 @@ static const char rcsid[] = /* * Some FDDI interfaces use bit-swapped addresses. */ -#if defined(ultrix) || defined(__alpha) || defined(__bsdi) || defined(__NetBSD__) +#if defined(ultrix) || defined(__alpha) || defined(__bsdi) || defined(__NetBSD__) || defined(__linux__) int fddi_bitswap = 0; #else int fddi_bitswap = 1; @@ -210,8 +210,8 @@ extract_fddi_addrs(const struct fddi_header *fddip, char *fsrc, char *fdst) fsrc[i] = fddi_bit_swap[fddip->fddi_shost[i]]; } else { - memcpy(fdst, (char *)fddip->fddi_dhost, 6); - memcpy(fsrc, (char *)fddip->fddi_shost, 6); + memcpy(fdst, (const char *)fddip->fddi_dhost, 6); + memcpy(fsrc, (const char *)fddip->fddi_shost, 6); } } @@ -222,7 +222,7 @@ static inline void fddi_print(register const struct fddi_header *fddip, register u_int length, register const u_char *fsrc, register const u_char *fdst) { - char *srcname, *dstname; + const char *srcname, *dstname; srcname = etheraddr_string(fsrc); dstname = etheraddr_string(fdst); @@ -258,10 +258,11 @@ fddi_if_print(u_char *pcap, const struct pcap_pkthdr *h, { u_int caplen = h->caplen; u_int length = h->len; - const struct fddi_header *fddip = (struct fddi_header *)p; + const struct fddi_header *fddip = (const struct fddi_header *)p; struct ether_header ehdr; u_short extracted_ethertype; + ++infodelay; ts_print(&h->ts); if (caplen < FDDI_HDRLEN) { @@ -328,4 +329,7 @@ fddi_if_print(u_char *pcap, const struct pcap_pkthdr *h, default_print(p, caplen); out: putchar('\n'); + --infodelay; + if (infoprint) + info(0); } diff --git a/contrib/tcpdump/print-frag6.c b/contrib/tcpdump/print-frag6.c index abf0cc6..4553505 100644 --- a/contrib/tcpdump/print-frag6.c +++ b/contrib/tcpdump/print-frag6.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-frag6.c,v 1.12 2000/10/07 05:53:10 itojun Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-frag6.c,v 1.13 2001/09/17 21:58:02 fenner Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -52,12 +52,8 @@ frag6_print(register const u_char *bp, register const u_char *bp2) register const struct ip6_hdr *ip6; register const u_char *ep; -#if 0 -#define TCHECK(var) if ((u_char *)&(var) >= ep - sizeof(var)) goto trunc -#endif - - dp = (struct ip6_frag *)bp; - ip6 = (struct ip6_hdr *)bp2; + dp = (const struct ip6_frag *)bp; + ip6 = (const struct ip6_hdr *)bp2; /* 'ep' points to the end of available data. */ ep = snapend; diff --git a/contrib/tcpdump/print-gre.c b/contrib/tcpdump/print-gre.c index e79d300..ebadb0e 100644 --- a/contrib/tcpdump/print-gre.c +++ b/contrib/tcpdump/print-gre.c @@ -24,7 +24,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-gre.c,v 1.9 2000/12/18 05:41:59 guy Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-gre.c,v 1.13 2001/06/15 22:17:31 fenner Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -45,38 +45,31 @@ static const char rcsid[] = #include "addrtoname.h" #include "extract.h" /* must come after interface.h */ -#define GRE_SIZE (20) - struct gre { - u_short flags; - u_short proto; - union { - struct gre_ckof { - u_short cksum; - u_short offset; - } gre_ckof; - u_int32_t key; - u_int32_t seq; - } gre_void1; - union { - u_int32_t key; - u_int32_t seq; - u_int32_t routing; - } gre_void2; - union { - u_int32_t seq; - u_int32_t routing; - } gre_void3; - union { - u_int32_t routing; - } gre_void4; + u_int16_t flags; + u_int16_t proto; }; +/* RFC 2784 - GRE */ #define GRE_CP 0x8000 /* Checksum Present */ -#define GRE_RP 0x4000 /* Routing Present */ +#define GRE_VER_MASK 0x0007 /* Version */ + +/* RFC 2890 - Key and Sequence extensions to GRE */ #define GRE_KP 0x2000 /* Key Present */ #define GRE_SP 0x1000 /* Sequence Present */ +/* Legacy from RFC 1700 */ +#define GRE_RP 0x4000 /* Routing Present */ +#define GRE_sP 0x0800 /* strict source route present */ +#define GRE_RECUR_MASK 0x0700 /* Recursion Control */ +#define GRE_RECUR_SHIFT 8 + +#define GRE_COP (GRE_RP|GRE_CP) /* Checksum & Offset Present */ + +/* "Enhanced GRE" from RFC2637 - PPTP */ +#define GRE_AP 0x0080 /* Ack present */ + +#define GRE_MBZ_MASK 0x0078 /* not defined */ /* * Deencapsulate and print a GRE-tunneled IP datagram @@ -86,17 +79,18 @@ gre_print(const u_char *bp, u_int length) { const u_char *cp = bp + 4; const struct gre *gre; - u_short flags, proto, extracted_ethertype; + u_int16_t flags, proto; + u_short ver=0; + u_short extracted_ethertype; gre = (const struct gre *)bp; - if (length < GRE_SIZE) { - goto trunc; - } + TCHECK(gre->proto); flags = EXTRACT_16BITS(&gre->flags); proto = EXTRACT_16BITS(&gre->proto); + (void)printf("gre "); - if (vflag) { + if (flags) { /* Decode the flags */ putchar('['); if (flags & GRE_CP) @@ -107,20 +101,68 @@ gre_print(const u_char *bp, u_int length) putchar('K'); if (flags & GRE_SP) putchar('S'); + if (flags & GRE_sP) + putchar('s'); + if (flags & GRE_AP) + putchar('A'); + if (flags & GRE_RECUR_MASK) + printf("R%x", (flags & GRE_RECUR_MASK) >> GRE_RECUR_SHIFT); + ver = flags & GRE_VER_MASK; + printf("v%u", ver); + + if (flags & GRE_MBZ_MASK) + printf("!%x", flags & GRE_MBZ_MASK); fputs("] ", stdout); } - /* Checksum & Offset are present */ - if ((flags & GRE_CP) | (flags & GRE_RP)) - cp += 4; + if (flags & GRE_COP) { + int checksum, offset; + + TCHECK2(*cp, 4); + checksum = EXTRACT_16BITS(cp); + offset = EXTRACT_16BITS(cp + 2); + + if (flags & GRE_CP) { + /* Checksum present */ + + /* todo: check checksum */ + if (vflag > 1) + printf("C:%04x ", checksum); + } + if (flags & GRE_RP) { + /* Offset present */ + + if (vflag > 1) + printf("O:%04x ", offset); + } + cp += 4; /* skip checksum and offset */ + } + if (flags & GRE_KP) { + TCHECK2(*cp, 4); + if (ver == 1) { /* PPTP */ + if (vflag > 1) + printf("PL:%u ", EXTRACT_16BITS(cp)); + printf("ID:%04x ", EXTRACT_16BITS(cp+2)); + } + else + printf("K:%08x ", EXTRACT_32BITS(cp)); + cp += 4; /* skip key */ + } + if (flags & GRE_SP) { + TCHECK2(*cp, 4); + printf("S:%u ", EXTRACT_32BITS(cp)); + cp += 4; /* skip seq */ + } + if (flags & GRE_AP && ver >= 1) { + TCHECK2(*cp, 4); + printf("A:%u ", EXTRACT_32BITS(cp)); + cp += 4; /* skip ack */ + } /* We don't support routing fields (variable length) now. Punt. */ if (flags & GRE_RP) return; - if (flags & GRE_KP) - cp += 4; - if (flags & GRE_SP) - cp += 4; + TCHECK(cp[0]); length -= cp - bp; if (ether_encap_print(proto, cp, length, length, diff --git a/contrib/tcpdump/print-hsrp.c b/contrib/tcpdump/print-hsrp.c new file mode 100644 index 0000000..a7a1c82 --- /dev/null +++ b/contrib/tcpdump/print-hsrp.c @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2001 Julian Cowley + * 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. Neither the name of the project 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 PROJECT 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 PROJECT 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. + */ + +/* Cisco Hot Standby Router Protocol (HSRP). */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-hsrp.c,v 1.2 2001/10/08 16:12:37 fenner Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/types.h> + +#include <stdio.h> +#include <netinet/in.h> + +#include "interface.h" +#include "addrtoname.h" + +/* HSRP op code types. */ +static const char *op_code_str[] = { + "hello", + "coup", + "resign" +}; + +/* HSRP states and associated names. */ +static struct tok states[] = { + { 0, "initial" }, + { 1, "learn" }, + { 2, "listen" }, + { 4, "speak" }, + { 8, "standby" }, + { 16, "active" }, + { 0, NULL } +}; + +/* + * RFC 2281: + * + * 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 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Version | Op Code | State | Hellotime | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Holdtime | Priority | Group | Reserved | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Authentication Data | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Authentication Data | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Virtual IP Address | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +#define HSRP_AUTH_SIZE 8 + +/* HSRP protocol header. */ +struct hsrp { + u_char hsrp_version; + u_char hsrp_op_code; + u_char hsrp_state; + u_char hsrp_hellotime; + u_char hsrp_holdtime; + u_char hsrp_priority; + u_char hsrp_group; + u_char hsrp_reserved; + u_char hsrp_authdata[HSRP_AUTH_SIZE]; + struct in_addr hsrp_virtaddr; +}; + +void +hsrp_print(register const u_char *bp, register u_int len) +{ + struct hsrp *hp = (struct hsrp *) bp; + + TCHECK(hp->hsrp_version); + printf("HSRPv%d", hp->hsrp_version); + if (hp->hsrp_version != 0) + return; + TCHECK(hp->hsrp_op_code); + printf("-"); + printf("%s ", tok2strary(op_code_str, "unknown (%d)", hp->hsrp_op_code)); + printf("%d: ", len); + TCHECK(hp->hsrp_state); + printf("state=%s ", tok2str(states, "Unknown (%d)", hp->hsrp_state)); + TCHECK(hp->hsrp_group); + printf("group=%d ", hp->hsrp_group); + TCHECK(hp->hsrp_reserved); + if (hp->hsrp_reserved != 0) { + printf("[reserved=%d!] ", hp->hsrp_reserved); + } + TCHECK2(hp->hsrp_virtaddr, sizeof(hp->hsrp_virtaddr)); + printf("addr=%s", ipaddr_string(&hp->hsrp_virtaddr)); + if (vflag) { + printf(" hellotime="); + relts_print(hp->hsrp_hellotime); + printf(" holdtime="); + relts_print(hp->hsrp_holdtime); + printf(" priority=%d", hp->hsrp_priority); + printf(" auth=\""); + fn_printn(hp->hsrp_authdata, sizeof(hp->hsrp_authdata), NULL); + printf("\""); + } + return; +trunc: + printf("[|hsrp]"); +} diff --git a/contrib/tcpdump/print-icmp.c b/contrib/tcpdump/print-icmp.c index 59f6465..71f9649 100644 --- a/contrib/tcpdump/print-icmp.c +++ b/contrib/tcpdump/print-icmp.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-icmp.c,v 1.57 2000/10/10 05:03:32 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-icmp.c,v 1.62 2001/07/24 16:56:11 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -245,7 +245,7 @@ static struct tok type2str[] = { { ICMP_REDIRECT_NET, "redirect %s to net %s" }, { ICMP_REDIRECT_HOST, "redirect %s to host %s" }, { ICMP_REDIRECT_TOSNET, "redirect-tos %s to net %s" }, - { ICMP_REDIRECT_TOSHOST, "redirect-tos %s to net %s" }, + { ICMP_REDIRECT_TOSHOST, "redirect-tos %s to host %s" }, { 0, NULL } }; @@ -268,27 +268,21 @@ struct id_rdiscovery { }; void -icmp_print(register const u_char *bp, u_int plen, register const u_char *bp2) +icmp_print(const u_char *bp, u_int plen, const u_char *bp2) { - register char *cp; - register const struct icmp *dp; - register const struct ip *ip; - register const char *str, *fmt; - register const struct ip *oip; - register const struct udphdr *ouh; - register u_int hlen, dport, mtu; + char *cp; + const struct icmp *dp; + const struct ip *ip; + const char *str, *fmt; + const struct ip *oip; + const struct udphdr *ouh; + u_int hlen, dport, mtu; char buf[MAXHOSTNAMELEN + 100]; dp = (struct icmp *)bp; ip = (struct ip *)bp2; str = buf; -#if 0 - (void)printf("%s > %s: ", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); -#endif - TCHECK(dp->icmp_code); switch (dp->icmp_type) { @@ -339,12 +333,12 @@ icmp_print(register const u_char *bp, u_int plen, register const u_char *bp2) { register const struct mtu_discovery *mp; mp = (struct mtu_discovery *)&dp->icmp_void; - mtu = EXTRACT_16BITS(&mp->nexthopmtu); - if (mtu) { + mtu = EXTRACT_16BITS(&mp->nexthopmtu); + if (mtu) { (void)snprintf(buf, sizeof(buf), "%s unreachable - need to frag (mtu %d)", ipaddr_string(&dp->icmp_ip.ip_dst), mtu); - } else { + } else { (void)snprintf(buf, sizeof(buf), "%s unreachable - need to frag", ipaddr_string(&dp->icmp_ip.ip_dst)); @@ -480,7 +474,7 @@ icmp_print(register const u_char *bp, u_int plen, register const u_char *bp2) str = tok2str(icmp2str, "type-#%d", dp->icmp_type); break; } - (void)printf("icmp: %s", str); + (void)printf("icmp: %s", str); if (vflag) { if (TTEST2(*bp, plen)) { if (in_cksum((u_short*)dp, plen, 0)) diff --git a/contrib/tcpdump/print-icmp6.c b/contrib/tcpdump/print-icmp6.c index a983bbb..73e78a3 100644 --- a/contrib/tcpdump/print-icmp6.c +++ b/contrib/tcpdump/print-icmp6.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-icmp6.c,v 1.42 2000/12/13 07:57:05 itojun Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-icmp6.c,v 1.56 2001/06/27 02:48:43 itojun Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -43,6 +43,7 @@ static const char rcsid[] = #include <arpa/inet.h> #include <stdio.h> +#include <string.h> #include <netdb.h> #include "ip6.h" @@ -54,6 +55,9 @@ static const char rcsid[] = #include "udp.h" #include "ah.h" +static const char *get_rtpref(u_int); +static const char *get_lifetime(u_int32_t); +static void print_lladdr(const u_char *, size_t); void icmp6_opt_print(const u_char *, int); void mld6_print(const u_char *); static struct udphdr *get_upperlayer(u_char *, int *); @@ -65,23 +69,60 @@ void icmp6_rrenum_print(int, const u_char *, const u_char *); #define abs(a) ((0 < (a)) ? (a) : -(a)) #endif +static const char * +get_rtpref(u_int v) +{ + static const char *rtpref_str[] = { + "medium", /* 00 */ + "high", /* 01 */ + "rsv", /* 10 */ + "low" /* 11 */ + }; + + return rtpref_str[((v & ND_RA_FLAG_RTPREF_MASK) >> 3) & 0xff]; +} + +static const char * +get_lifetime(u_int32_t v) +{ + static char buf[20]; + + if (v == (u_int32_t)~0UL) + return "infinity"; + else { + snprintf(buf, sizeof(buf), "%u", v); + return buf; + } +} + +static void +print_lladdr(const u_int8_t *p, size_t l) +{ + const u_int8_t *ep, *q; + + q = p; + ep = p + l; + while (l > 0 && q < ep) { + if (q > p) + printf(":"); + printf("%02x", *q++); + l--; + } +} + void -icmp6_print(register const u_char *bp, register const u_char *bp2) +icmp6_print(const u_char *bp, const u_char *bp2) { const struct icmp6_hdr *dp; - register const struct ip6_hdr *ip; - register const char *str; - register const struct ip6_hdr *oip; - register const struct udphdr *ouh; - register int dport; - register const u_char *ep; + const struct ip6_hdr *ip; + const char *str; + const struct ip6_hdr *oip; + const struct udphdr *ouh; + int dport; + const u_char *ep; char buf[256]; int icmp6len, prot; -#if 0 -#define TCHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) goto trunc -#endif - dp = (struct icmp6_hdr *)bp; ip = (struct ip6_hdr *)bp2; oip = (struct ip6_hdr *)(dp + 1); @@ -94,12 +135,6 @@ icmp6_print(register const u_char *bp, register const u_char *bp2) else /* XXX: jumbo payload case... */ icmp6len = snapend - bp; -#if 0 - (void)printf("%s > %s: ", - ip6addr_string(&ip->ip6_src), - ip6addr_string(&ip->ip6_dst)); -#endif - TCHECK(dp->icmp6_code); switch (dp->icmp6_type) { case ICMP6_DST_UNREACH: @@ -155,7 +190,7 @@ icmp6_print(register const u_char *bp, register const u_char *bp2) break; case ICMP6_PACKET_TOO_BIG: TCHECK(dp->icmp6_mtu); - printf("icmp6: too big %u\n", (u_int32_t)ntohl(dp->icmp6_mtu)); + printf("icmp6: too big %u", (u_int32_t)ntohl(dp->icmp6_mtu)); break; case ICMP6_TIME_EXCEEDED: TCHECK(oip->ip6_dst); @@ -177,15 +212,15 @@ icmp6_print(register const u_char *bp, register const u_char *bp2) TCHECK(oip->ip6_dst); switch (dp->icmp6_code) { case ICMP6_PARAMPROB_HEADER: - printf("icmp6: parameter problem errorneous - octet %u\n", + printf("icmp6: parameter problem errorneous - octet %u", (u_int32_t)ntohl(dp->icmp6_pptr)); break; case ICMP6_PARAMPROB_NEXTHEADER: - printf("icmp6: parameter problem next header - octet %u\n", + printf("icmp6: parameter problem next header - octet %u", (u_int32_t)ntohl(dp->icmp6_pptr)); break; case ICMP6_PARAMPROB_OPTION: - printf("icmp6: parameter problem option - octet %u\n", + printf("icmp6: parameter problem option - octet %u", (u_int32_t)ntohl(dp->icmp6_pptr)); break; default: @@ -232,13 +267,16 @@ icmp6_print(register const u_char *bp, register const u_char *bp2) printf("M"); if (p->nd_ra_flags_reserved & ND_RA_FLAG_OTHER) printf("O"); -#ifndef ND_RA_FLAG_HA -#define ND_RA_FLAG_HA 0x20 -#endif - if (p->nd_ra_flags_reserved & ND_RA_FLAG_HA) + if (p->nd_ra_flags_reserved & ND_RA_FLAG_HOME_AGENT) printf("H"); - if (p->nd_ra_flags_reserved != 0) + + if ((p->nd_ra_flags_reserved & ~ND_RA_FLAG_RTPREF_MASK) + != 0) printf(" "); + + printf("pref=%s, ", + get_rtpref(p->nd_ra_flags_reserved)); + printf("router_ltime=%d, ", ntohs(p->nd_ra_router_lifetime)); printf("reachable_time=%u, ", (u_int32_t)ntohl(p->nd_ra_reachable)); @@ -325,15 +363,12 @@ icmp6_print(register const u_char *bp, register const u_char *bp2) return; trunc: fputs("[|icmp6]", stdout); -#if 0 -#undef TCHECK -#endif } static struct udphdr * -get_upperlayer(register u_char *bp, int *prot) +get_upperlayer(u_char *bp, int *prot) { - register const u_char *ep; + const u_char *ep; struct ip6_hdr *ip6 = (struct ip6_hdr *)bp; struct udphdr *uh; struct ip6_hbh *hbh; @@ -404,149 +439,151 @@ get_upperlayer(register u_char *bp, int *prot) } void -icmp6_opt_print(register const u_char *bp, int resid) +icmp6_opt_print(const u_char *bp, int resid) { - register const struct nd_opt_hdr *op; - register const struct nd_opt_hdr *opl; /* why there's no struct? */ - register const struct nd_opt_prefix_info *opp; - register const struct icmp6_opts_redirect *opr; - register const struct nd_opt_mtu *opm; - register const struct nd_opt_advint *opa; - register const u_char *ep; - int opts_len; -#if 0 - register const struct ip6_hdr *ip; - register const char *str; - register const struct ip6_hdr *oip; - register const struct udphdr *ouh; - register int hlen, dport; - char buf[256]; -#endif + const struct nd_opt_hdr *op; + const struct nd_opt_hdr *opl; /* why there's no struct? */ + const struct nd_opt_prefix_info *opp; + const struct icmp6_opts_redirect *opr; + const struct nd_opt_mtu *opm; + const struct nd_opt_advinterval *opa; + const struct nd_opt_route_info *opri; + const u_char *cp, *ep; + struct in6_addr in6, *in6p; + size_t l; #define ECHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) return - op = (struct nd_opt_hdr *)bp; -#if 0 - ip = (struct ip6_hdr *)bp2; - oip = &dp->icmp6_ip6; - str = buf; -#endif + cp = bp; /* 'ep' points to the end of available data. */ ep = snapend; - ECHECK(op->nd_opt_len); - if (resid <= 0) - return; - switch (op->nd_opt_type) { - case ND_OPT_SOURCE_LINKADDR: - opl = (struct nd_opt_hdr *)op; -#if 1 - if ((u_char *)opl + (opl->nd_opt_len << 3) > ep) + while (cp < ep) { + op = (struct nd_opt_hdr *)cp; + + ECHECK(op->nd_opt_len); + if (resid <= 0) + return; + if (op->nd_opt_len == 0) goto trunc; -#else - TCHECK((u_char *)opl + (opl->nd_opt_len << 3) - 1); -#endif - printf("(src lladdr: %s", /*)*/ - etheraddr_string((u_char *)(opl + 1))); - if (opl->nd_opt_len != 1) - printf("!"); - /*(*/ - printf(")"); - icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3), - resid - (op->nd_opt_len << 3)); - break; - case ND_OPT_TARGET_LINKADDR: - opl = (struct nd_opt_hdr *)op; -#if 1 - if ((u_char *)opl + (opl->nd_opt_len << 3) > ep) + if (cp + (op->nd_opt_len << 3) > ep) goto trunc; -#else - TCHECK((u_char *)opl + (opl->nd_opt_len << 3) - 1); -#endif - printf("(tgt lladdr: %s", /*)*/ - etheraddr_string((u_char *)(opl + 1))); - if (opl->nd_opt_len != 1) - printf("!"); - /*(*/ - printf(")"); - icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3), - resid - (op->nd_opt_len << 3)); - break; - case ND_OPT_PREFIX_INFORMATION: - opp = (struct nd_opt_prefix_info *)op; - TCHECK(opp->nd_opt_pi_prefix); - printf("(prefix info: "); /*)*/ - if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK) - printf("L"); - if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO) - printf("A"); - if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ROUTER) - printf("R"); - if (opp->nd_opt_pi_flags_reserved) - printf(" "); - printf("valid_ltime="); - if ((u_int32_t)ntohl(opp->nd_opt_pi_valid_time) == ~0U) - printf("infinity"); - else { - printf("%u", (u_int32_t)ntohl(opp->nd_opt_pi_valid_time)); - } - printf(", "); - printf("preffered_ltime="); - if ((u_int32_t)ntohl(opp->nd_opt_pi_preferred_time) == ~0U) - printf("infinity"); - else { - printf("%u", (u_int32_t)ntohl(opp->nd_opt_pi_preferred_time)); + + switch (op->nd_opt_type) { + case ND_OPT_SOURCE_LINKADDR: + opl = (struct nd_opt_hdr *)op; + printf("(src lladdr: "); + l = (op->nd_opt_len << 3) - 2; + print_lladdr(cp + 2, l); + /*(*/ + printf(")"); + break; + case ND_OPT_TARGET_LINKADDR: + opl = (struct nd_opt_hdr *)op; + printf("(tgt lladdr: "); + l = (op->nd_opt_len << 3) - 2; + print_lladdr(cp + 2, l); + /*(*/ + printf(")"); + break; + case ND_OPT_PREFIX_INFORMATION: + opp = (struct nd_opt_prefix_info *)op; + TCHECK(opp->nd_opt_pi_prefix); + printf("(prefix info: "); /*)*/ + if (op->nd_opt_len != 4) { + printf("badlen"); + /*(*/ + printf(")"); + break; + } + if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK) + printf("L"); + if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO) + printf("A"); + if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ROUTER) + printf("R"); + if (opp->nd_opt_pi_flags_reserved) + printf(" "); + printf("valid_ltime=%s,", + get_lifetime((u_int32_t)ntohl(opp->nd_opt_pi_valid_time))); + printf("preferred_ltime=%s,", + get_lifetime((u_int32_t)ntohl(opp->nd_opt_pi_preferred_time))); + printf("prefix=%s/%d", + ip6addr_string(&opp->nd_opt_pi_prefix), + opp->nd_opt_pi_prefix_len); + if (opp->nd_opt_pi_len != 4) + printf("!"); + /*(*/ + printf(")"); + break; + case ND_OPT_REDIRECTED_HEADER: + opr = (struct icmp6_opts_redirect *)op; + printf("(redirect)"); + /* xxx */ + break; + case ND_OPT_MTU: + opm = (struct nd_opt_mtu *)op; + TCHECK(opm->nd_opt_mtu_mtu); + printf("(mtu:"); /*)*/ + if (op->nd_opt_len != 1) { + printf("badlen"); + /*(*/ + printf(")"); + break; + } + printf(" mtu=%u", (u_int32_t)ntohl(opm->nd_opt_mtu_mtu)); + if (opm->nd_opt_mtu_len != 1) + printf("!"); + printf(")"); + break; + case ND_OPT_ADVINTERVAL: + opa = (struct nd_opt_advinterval *)op; + TCHECK(opa->nd_opt_adv_interval); + printf("(advint:"); /*)*/ + printf(" advint=%u", + (u_int32_t)ntohl(opa->nd_opt_adv_interval)); + /*(*/ + printf(")"); + break; + case ND_OPT_ROUTE_INFO: + opri = (struct nd_opt_route_info *)op; + TCHECK(opri->nd_opt_rti_lifetime); + memset(&in6, 0, sizeof(in6)); + in6p = (struct in6_addr *)(opri + 1); + switch (op->nd_opt_len) { + case 1: + break; + case 2: + TCHECK2(*in6p, 8); + memcpy(&in6, opri + 1, 8); + break; + case 3: + TCHECK(*in6p); + memcpy(&in6, opri + 1, sizeof(in6)); + break; + default: + goto trunc; + } + printf("(rtinfo:"); /*)*/ + printf(" %s/%u", ip6addr_string(&in6), + opri->nd_opt_rti_prefixlen); + printf(", pref=%s", get_rtpref(opri->nd_opt_rti_flags)); + printf(", lifetime=%s", + get_lifetime((u_int32_t)ntohl(opri->nd_opt_rti_lifetime))); + /*(*/ + printf(")"); + break; + default: + printf("(unknwon opt_type=%d, opt_len=%d)", + op->nd_opt_type, op->nd_opt_len); + break; } - printf(", "); - printf("prefix=%s/%d", ip6addr_string(&opp->nd_opt_pi_prefix), - opp->nd_opt_pi_prefix_len); - if (opp->nd_opt_pi_len != 4) - printf("!"); - /*(*/ - printf(")"); - icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3), - resid - (op->nd_opt_len << 3)); - break; - case ND_OPT_REDIRECTED_HEADER: - opr = (struct icmp6_opts_redirect *)op; - printf("(redirect)"); - /* xxx */ - icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3), - resid - (op->nd_opt_len << 3)); - break; - case ND_OPT_MTU: - opm = (struct nd_opt_mtu *)op; - TCHECK(opm->nd_opt_mtu_mtu); - printf("(mtu: "); /*)*/ - printf("mtu=%u", (u_int32_t)ntohl(opm->nd_opt_mtu_mtu)); - if (opm->nd_opt_mtu_len != 1) - printf("!"); - printf(")"); - icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3), - resid - (op->nd_opt_len << 3)); - break; - case ND_OPT_ADVINT: - opa = (struct nd_opt_advint *)op; - TCHECK(opa->nd_opt_advint_advint); - printf("(advint: "); /*)*/ - printf("advint=%u", - (u_int32_t)ntohl(opa->nd_opt_advint_advint)); - /*(*/ - printf(")"); - icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3), - resid - (op->nd_opt_len << 3)); - break; - default: - opts_len = op->nd_opt_len; - printf("(unknwon opt_type=%d, opt_len=%d)", - op->nd_opt_type, opts_len); - if (opts_len == 0) - opts_len = 1; /* XXX */ - icmp6_opt_print((const u_char *)op + (opts_len << 3), - resid - (opts_len << 3)); - break; + + cp += op->nd_opt_len << 3; + resid -= op->nd_opt_len << 3; } return; + trunc: fputs("[ndp opt]", stdout); return; @@ -554,10 +591,10 @@ icmp6_opt_print(register const u_char *bp, int resid) } void -mld6_print(register const u_char *bp) +mld6_print(const u_char *bp) { - register struct mld6_hdr *mp = (struct mld6_hdr *)bp; - register const u_char *ep; + struct mld6_hdr *mp = (struct mld6_hdr *)bp; + const u_char *ep; /* 'ep' points to the end of available data. */ ep = snapend; @@ -820,7 +857,7 @@ icmp6_nodeinfo_print(int icmp6len, const u_char *bp, const u_char *ep) break; printf(" %s", getname6(bp + i)); i += sizeof(struct in6_addr); - printf("(%d)", ntohl(*(int32_t *)(bp + i))); + printf("(%d)", (int32_t)ntohl(*(int32_t *)(bp + i))); i += sizeof(int32_t); } i = ni6->ni_flags; @@ -893,7 +930,7 @@ icmp6_rrenum_print(int icmp6len, const u_char *bp, const u_char *ep) if (rr6->rr_flags) { printf("%s%s%s%s%s,", F(ICMP6_RR_FLAGS_TEST, "T"), F(ICMP6_RR_FLAGS_REQRESULT, "R"), - F(ICMP6_RR_FLAGS_ALLIF, "A"), + F(ICMP6_RR_FLAGS_FORCEAPPLY, "A"), F(ICMP6_RR_FLAGS_SPECSITE, "S"), F(ICMP6_RR_FLAGS_PREVDONE, "P")); } @@ -912,7 +949,7 @@ icmp6_rrenum_print(int icmp6len, const u_char *bp, const u_char *ep) TCHECK(match->rpm_prefix); - if (vflag) + if (vflag > 1) printf("\n\t"); else printf(" "); @@ -946,7 +983,7 @@ icmp6_rrenum_print(int icmp6len, const u_char *bp, const u_char *ep) TCHECK(use->rpu_prefix); - if (vflag) + if (vflag > 1) printf("\n\t"); else printf(" "); diff --git a/contrib/tcpdump/print-igmp.c b/contrib/tcpdump/print-igmp.c index c79244e..07ace7d 100644 --- a/contrib/tcpdump/print-igmp.c +++ b/contrib/tcpdump/print-igmp.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-igmp.c,v 1.3 2001/01/09 08:01:18 fenner Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-igmp.c,v 1.5 2001/09/17 21:58:02 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -114,7 +114,7 @@ static struct tok igmpv3report2str[] = { static void print_mtrace(register const u_char *bp, register u_int len) { - register struct tr_query *tr = (struct tr_query *)(bp + 8); + register const struct tr_query *tr = (const struct tr_query *)(bp + 8); printf("mtrace %lu: %s to %s reply-to %s", (u_long)TR_GETQID(ntohl(tr->tr_rttlqid)), @@ -127,7 +127,7 @@ print_mtrace(register const u_char *bp, register u_int len) static void print_mresp(register const u_char *bp, register u_int len) { - register struct tr_query *tr = (struct tr_query *)(bp + 8); + register const struct tr_query *tr = (const struct tr_query *)(bp + 8); printf("mresp %lu: %s to %s reply-to %s", (u_long)TR_GETQID(ntohl(tr->tr_rttlqid)), @@ -138,11 +138,10 @@ print_mresp(register const u_char *bp, register u_int len) } static void -print_igmpv3_report(register const u_char *bp, register u_int len, - register const u_char *bp2) +print_igmpv3_report(register const u_char *bp, register u_int len) { - int group, nsrcs, ngroups; - register int i, j; + u_int group, nsrcs, ngroups; + register u_int i, j; /* Minimum len is 16, and should be a multiple of 4 */ if (len < 16 || len & 0x03) { @@ -193,11 +192,12 @@ trunc: } static void -print_igmpv3_query(register const u_char *bp, register u_int len, - register const u_char *bp2) +print_igmpv3_query(register const u_char *bp, register u_int len) { - int nsrcs; - register int i; + u_int mrc; + int mrt; + u_int nsrcs; + register u_int i; (void)printf(" v3"); /* Minimum len is 12, and should be a multiple of 4 */ @@ -205,6 +205,17 @@ print_igmpv3_query(register const u_char *bp, register u_int len, (void)printf(" [invalid len %d]", len); return; } + mrc = bp[1]; + if (mrc < 128) { + mrt = mrc; + } else { + mrt = ((mrc & 0x0f) | 0x10) << (((mrc & 0x70) >> 4) + 3); + } + if (mrc != 100) { + (void)printf(" [max resp time "); + relts_print(mrt); + (void)printf("]"); + } TCHECK2(bp[4], 4); if (EXTRACT_32BITS(&bp[4]) == 0) return; @@ -232,8 +243,7 @@ trunc: } void -igmp_print(register const u_char *bp, register u_int len, - register const u_char *bp2) +igmp_print(register const u_char *bp, register u_int len) { if (qflag) { (void)printf("igmp"); @@ -245,7 +255,7 @@ igmp_print(register const u_char *bp, register u_int len, case 0x11: (void)printf("igmp query"); if (len >= 12) - print_igmpv3_query(bp, len, bp2); + print_igmpv3_query(bp, len); else { if (bp[1]) { (void)printf(" v2"); @@ -269,7 +279,7 @@ igmp_print(register const u_char *bp, register u_int len, break; case 0x22: (void)printf("igmp v3 report"); - print_igmpv3_report(bp, len, bp2); + print_igmpv3_report(bp, len); break; case 0x17: (void)printf("igmp leave %s", ipaddr_string(&bp[4])); diff --git a/contrib/tcpdump/print-igrp.c b/contrib/tcpdump/print-igrp.c index cecee14..19f4c83 100644 --- a/contrib/tcpdump/print-igrp.c +++ b/contrib/tcpdump/print-igrp.c @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-igrp.c,v 1.15 2000/09/29 04:58:40 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-igrp.c,v 1.16 2001/06/15 22:17:32 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -92,9 +92,7 @@ igrp_print(register const u_char *bp, u_int length, register const u_char *bp2) hdr = (struct igrphdr *)bp; ip = (struct ip *)bp2; cp = (u_char *)(hdr + 1); - (void)printf("%s > %s: igrp: ", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); + (void)printf("igrp:"); /* Header */ TCHECK(*hdr); @@ -126,7 +124,7 @@ igrp_print(register const u_char *bp, u_int length, register const u_char *bp2) igrp_entry_print((struct igrprte *)cp, 0, 1); --next; } else { - (void)printf("[extra bytes %d]", length); + (void)printf(" [extra bytes %d]", length); break; } cp += IGRP_RTE_SIZE; @@ -135,5 +133,5 @@ igrp_print(register const u_char *bp, u_int length, register const u_char *bp2) if (nint == 0 && nsys == 0 && next == 0) return; trunc: - fputs("[|igrp]", stdout); + fputs(" [|igrp]", stdout); } diff --git a/contrib/tcpdump/print-ip.c b/contrib/tcpdump/print-ip.c index 869c9da..e3e35ea 100644 --- a/contrib/tcpdump/print-ip.c +++ b/contrib/tcpdump/print-ip.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.92 2001/01/02 23:00:01 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.100 2001/09/17 21:58:03 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -203,7 +203,7 @@ ip_optprint(register const u_char *cp, u_int length) printf("{%d}", len); else if (cp[2] || cp[3]) printf("%d.%d", cp[2], cp[3]); - break; + break; default: printf(" IPOPT-%d{%d}", cp[0], len); @@ -217,7 +217,7 @@ ip_optprint(register const u_char *cp, u_int length) * don't modifiy the packet. */ u_short -in_cksum(const u_short *addr, register int len, u_short csum) +in_cksum(const u_short *addr, register u_int len, int csum) { int nleft = len; const u_short *w = addr; @@ -301,7 +301,7 @@ ip_print(register const u_char *bp, register u_int length) len = ntohs(ip->ip_len); if (length < len) - (void)printf("truncated-ip - %d bytes missing!", + (void)printf("truncated-ip - %d bytes missing! ", len - length); len -= hlen; len0 = len; @@ -315,7 +315,11 @@ ip_print(register const u_char *bp, register u_int length) cp = (const u_char *)ip + hlen; nh = ip->ip_p; - if (nh != IPPROTO_TCP && nh != IPPROTO_UDP) { +#ifndef IPPROTO_SCTP +#define IPPROTO_SCTP 132 +#endif + if (nh != IPPROTO_TCP && nh != IPPROTO_UDP && + nh != IPPROTO_SCTP) { (void)printf("%s > %s: ", ipaddr_string(&ip->ip_src), ipaddr_string(&ip->ip_dst)); } @@ -337,10 +341,10 @@ again: #endif case IPPROTO_ESP: { - int enh; - advance = esp_print(cp, (const u_char *)ip, &enh); + int enh, padlen; + advance = esp_print(cp, (const u_char *)ip, &enh, &padlen); cp += advance; - len -= advance; + len -= advance + padlen; if (enh < 0) break; nh = enh & 0xff; @@ -362,6 +366,10 @@ again: goto again; } + case IPPROTO_SCTP: + sctp_print(cp, (const u_char *)ip, len); + break; + case IPPROTO_TCP: tcp_print(cp, len, (const u_char *)ip, (off &~ 0x6000)); break; @@ -382,10 +390,6 @@ again: break; case IPPROTO_ND: -#if 0 - (void)printf("%s > %s:", ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); -#endif (void)printf(" nd %d", len); break; @@ -404,20 +408,14 @@ again: #define IPPROTO_IGMP 2 #endif case IPPROTO_IGMP: - igmp_print(cp, len, (const u_char *)ip); + igmp_print(cp, len); break; case 4: /* DVMRP multicast tunnel (ip-in-ip encapsulation) */ -#if 0 - if (vflag) - (void)printf("%s > %s: ", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); -#endif ip_print(cp, len); if (! vflag) { - printf(" (ipip)"); + printf(" (ipip-proto-4)"); return; } break; @@ -428,17 +426,7 @@ again: #endif case IP6PROTO_ENCAP: /* ip6-in-ip encapsulation */ -#if 0 - if (vflag) - (void)printf("%s > %s: ", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); -#endif ip6_print(cp, len); - if (! vflag) { - printf(" (encap)"); - return; - } break; #endif /*INET6*/ @@ -447,31 +435,15 @@ again: #define IPPROTO_GRE 47 #endif case IPPROTO_GRE: - if (vflag) - (void)printf("gre %s > %s: ", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); /* do it */ gre_print(cp, len); - if (! vflag) { - printf(" (gre encap)"); - return; - } - break; + break; #ifndef IPPROTO_MOBILE #define IPPROTO_MOBILE 55 #endif case IPPROTO_MOBILE: - if (vflag) - (void)printf("mobile %s > %s: ", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); mobile_print(cp, len); - if (! vflag) { - printf(" (mobile encap)"); - return; - } break; #ifndef IPPROTO_PIM @@ -485,18 +457,10 @@ again: #define IPPROTO_VRRP 112 #endif case IPPROTO_VRRP: - if (vflag) - (void)printf("vrrp %s > %s: ", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); vrrp_print(cp, len, ip->ip_ttl); break; default: -#if 0 - (void)printf("%s > %s:", ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); -#endif (void)printf(" ip-proto-%d %d", nh, len); break; } @@ -537,10 +501,17 @@ again: if (ip->ip_tos) { (void)printf(" [tos 0x%x", (int)ip->ip_tos); /* ECN bits */ - if (ip->ip_tos&0x02) { - (void)printf(",ECT"); - if (ip->ip_tos&0x01) + if (ip->ip_tos & 0x03) { + switch (ip->ip_tos & 0x03) { + case 1: + (void)printf(",ECT(1)"); + break; + case 2: + (void)printf(",ECT(0)"); + break; + case 3: (void)printf(",CE"); + } } (void)printf("] "); } @@ -592,15 +563,15 @@ ipN_print(register const u_char *bp, register u_int length) memcpy (&hdr, (char *)ip, 4); switch (IP_V(&hdr)) { case 4: - ip_print (bp, length); - return; + ip_print (bp, length); + return; #ifdef INET6 case 6: - ip6_print (bp, length); - return; + ip6_print (bp, length); + return; #endif default: - (void)printf("unknown ip %d", IP_V(&hdr)); - return; + (void)printf("unknown ip %d", IP_V(&hdr)); + return; } } diff --git a/contrib/tcpdump/print-ip6.c b/contrib/tcpdump/print-ip6.c index 71cd41c..7c98ad3 100644 --- a/contrib/tcpdump/print-ip6.c +++ b/contrib/tcpdump/print-ip6.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ip6.c,v 1.16 2000/11/17 19:08:15 itojun Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ip6.c,v 1.21 2001/11/16 02:17:36 itojun Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -51,11 +51,11 @@ static const char rcsid[] = * print an IP6 datagram. */ void -ip6_print(register const u_char *bp, register int length) +ip6_print(register const u_char *bp, register u_int length) { register const struct ip6_hdr *ip6; register int advance; - register int len; + register u_int len; register const u_char *cp; int nh; int fragmented = 0; @@ -66,24 +66,23 @@ ip6_print(register const u_char *bp, register int length) #ifdef LBL_ALIGN /* * The IP6 header is not 16-byte aligned, so copy into abuf. - * This will never happen with BPF. It does happen raw packet - * dumps from -r. */ if ((u_long)ip6 & 15) { static u_char *abuf; - if (abuf == NULL) + if (abuf == NULL) { abuf = malloc(snaplen); + if (abuf == NULL) + error("ip6_print: malloc"); + } memcpy(abuf, ip6, min(length, snaplen)); snapend += abuf - (u_char *)ip6; packetp = abuf; ip6 = (struct ip6_hdr *)abuf; + bp = abuf; } #endif - if ((u_char *)(ip6 + 1) > snapend) { - printf("[|ip6]"); - return; - } + TCHECK(*ip6); if (length < sizeof (struct ip6_hdr)) { (void)printf("truncated-ip6 %d", length); return; @@ -100,7 +99,7 @@ ip6_print(register const u_char *bp, register int length) while (cp < snapend) { cp += advance; - if (cp == (u_char *)(ip6 + 1) + if (cp == (const u_char *)(ip6 + 1) && nh != IPPROTO_TCP && nh != IPPROTO_UDP) { (void)printf("%s > %s: ", ip6addr_string(&ip6->ip6_src), ip6addr_string(&ip6->ip6_dst)); @@ -143,11 +142,12 @@ ip6_print(register const u_char *bp, register int length) break; case IPPROTO_ESP: { - int enh; - advance = esp_print(cp, (const u_char *)ip6, &enh); + int enh, padlen; + advance = esp_print(cp, (const u_char *)ip6, &enh, &padlen); if (enh < 0) goto end; nh = enh & 0xff; + len -= padlen; break; } #ifndef IPPROTO_IPCOMP @@ -221,6 +221,9 @@ ip6_print(register const u_char *bp, register int length) (void)printf(", hlim %d", (int)ip6->ip6_hlim); printf(")"); } + return; +trunc: + (void)printf("[|ip6]"); } #endif /* INET6 */ diff --git a/contrib/tcpdump/print-ip6opts.c b/contrib/tcpdump/print-ip6opts.c index 22d017e..3d78a08 100644 --- a/contrib/tcpdump/print-ip6opts.c +++ b/contrib/tcpdump/print-ip6opts.c @@ -33,7 +33,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ip6opts.c,v 1.8 2000/12/13 07:57:05 itojun Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ip6opts.c,v 1.9 2001/05/09 02:47:26 itojun Exp $"; #endif #ifdef INET6 @@ -78,10 +78,20 @@ ip6_sopt_print(const u_char *bp, int len) int optlen; for (i = 0; i < len; i += optlen) { + if (bp[i] == IP6OPT_PAD1) + optlen = 1; + else { + if (i + 1 < len) + optlen = bp[i + 1] + 2; + else + goto trunc; + } + if (i + optlen > len) + goto trunc; + switch (bp[i]) { case IP6OPT_PAD1: printf(", pad1"); - optlen = 1; break; case IP6OPT_PADN: if (len - i < IP6OPT_MINLEN) { @@ -89,7 +99,6 @@ ip6_sopt_print(const u_char *bp, int len) goto trunc; } printf(", padn"); - optlen = bp[i + 1] + 2; break; case IP6SOPT_ALTCOA: if (len - i < IP6SOPT_ALTCOA_MINLEN) { @@ -97,7 +106,6 @@ ip6_sopt_print(const u_char *bp, int len) goto trunc; } printf(", alt-CoA: %s", ip6addr_string(&bp[i+2])); - optlen = bp[i + 1] + 2; break; case IP6SOPT_UI: if (len - i < IP6SOPT_UI_MINLEN) { @@ -105,7 +113,6 @@ ip6_sopt_print(const u_char *bp, int len) goto trunc; } printf("(ui: 0x%04x) ", ntohs(*(u_int16_t *)&bp[i + 2])); - optlen = bp[i + 1] + 2; break; default: if (len - i < IP6OPT_MINLEN) { @@ -113,7 +120,6 @@ ip6_sopt_print(const u_char *bp, int len) goto trunc; } printf(", sopt_type 0x%02x: len=%d", bp[i], bp[i + 1]); - optlen = bp[i + 1] + 2; break; } } @@ -130,10 +136,20 @@ ip6_opt_print(const u_char *bp, int len) int optlen; for (i = 0; i < len; i += optlen) { + if (bp[i] == IP6OPT_PAD1) + optlen = 1; + else { + if (i + 1 < len) + optlen = bp[i + 1] + 2; + else + goto trunc; + } + if (i + optlen > len) + goto trunc; + switch (bp[i]) { case IP6OPT_PAD1: printf("(pad1)"); - optlen = 1; break; case IP6OPT_PADN: if (len - i < IP6OPT_MINLEN) { @@ -141,7 +157,6 @@ ip6_opt_print(const u_char *bp, int len) goto trunc; } printf("(padn)"); - optlen = bp[i + 1] + 2; break; case IP6OPT_ROUTER_ALERT: if (len - i < IP6OPT_RTALERT_LEN) { @@ -153,7 +168,6 @@ ip6_opt_print(const u_char *bp, int len) goto trunc; } printf("(rtalert: 0x%04x) ", ntohs(*(u_int16_t *)&bp[i + 2])); - optlen = IP6OPT_RTALERT_LEN; break; case IP6OPT_JUMBO: if (len - i < IP6OPT_JUMBO_LEN) { @@ -165,7 +179,6 @@ ip6_opt_print(const u_char *bp, int len) goto trunc; } printf("(jumbo: %u) ", (u_int32_t)ntohl(*(u_int32_t *)&bp[i + 2])); - optlen = IP6OPT_JUMBO_LEN; break; case IP6OPT_HOME_ADDRESS: if (len - i < IP6OPT_HOMEADDR_MINLEN) { @@ -179,10 +192,9 @@ ip6_opt_print(const u_char *bp, int len) printf("(homeaddr: %s", ip6addr_string(&bp[i + 2])); if (bp[i + 1] > IP6OPT_HOMEADDR_MINLEN - 2) { ip6_sopt_print(&bp[i + IP6OPT_HOMEADDR_MINLEN], - (optlen-IP6OPT_HOMEADDR_MINLEN)); + (optlen - IP6OPT_HOMEADDR_MINLEN)); } printf(")"); - optlen = bp[i + 1] + 2; break; case IP6OPT_BINDING_UPDATE: if (len - i < IP6OPT_BU_MINLEN) { @@ -210,7 +222,6 @@ ip6_opt_print(const u_char *bp, int len) printf(", lifetime: %u", (u_int32_t)ntohs(*(u_int32_t *)&bp[i + 8])); - optlen = bp[i + 1] + 2; if (bp[i + 1] > IP6OPT_BU_MINLEN - 2) { ip6_sopt_print(&bp[i + IP6OPT_BU_MINLEN], (optlen - IP6OPT_BU_MINLEN)); @@ -237,10 +248,9 @@ ip6_opt_print(const u_char *bp, int len) if (bp[i + 1] > IP6OPT_BA_MINLEN - 2) { ip6_sopt_print(&bp[i + IP6OPT_BA_MINLEN], - (optlen-IP6OPT_BA_MINLEN)); + (optlen - IP6OPT_BA_MINLEN)); } printf(")"); - optlen = bp[i + 1] + 2; break; case IP6OPT_BINDING_REQ: if (len - i < IP6OPT_BR_MINLEN) { @@ -250,10 +260,9 @@ ip6_opt_print(const u_char *bp, int len) printf("(br"); if (bp[i + 1] > IP6OPT_BR_MINLEN - 2) { ip6_sopt_print(&bp[i + IP6OPT_BR_MINLEN], - (optlen-IP6OPT_BR_MINLEN)); + (optlen - IP6OPT_BR_MINLEN)); } printf(")"); - optlen = bp[i + 1] + 2; break; default: if (len - i < IP6OPT_MINLEN) { @@ -261,7 +270,6 @@ ip6_opt_print(const u_char *bp, int len) goto trunc; } printf("(opt_type 0x%02x: len=%d) ", bp[i], bp[i + 1]); - optlen = bp[i + 1] + 2; break; } } diff --git a/contrib/tcpdump/print-ipx.c b/contrib/tcpdump/print-ipx.c index 4925719..be1befd 100644 --- a/contrib/tcpdump/print-ipx.c +++ b/contrib/tcpdump/print-ipx.c @@ -24,7 +24,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ipx.c,v 1.27 2000/09/29 04:58:41 guy Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ipx.c,v 1.32 2001/10/08 21:25:20 fenner Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -108,10 +108,22 @@ ipx_decode(const struct ipxHdr *ipx, const u_char *datap, u_int length) break; case IPX_SKT_NETBIOS: (void)printf(" ipx-netbios %d", length); +#ifdef TCPDUMP_DO_SMB + ipx_netbios_print(datap, length); +#endif break; case IPX_SKT_DIAGNOSTICS: (void)printf(" ipx-diags %d", length); break; + case IPX_SKT_NWLINK_DGM: + (void)printf(" ipx-nwlink-dgm %d", length); +#ifdef TCPDUMP_DO_SMB + ipx_netbios_print(datap, length); +#endif + break; + case IPX_SKT_EIGRP: + (void)printf(" ipx-eigrp %d", length); + break; default: (void)printf(" ipx-#%x %d", dstSkt, length); break; @@ -136,12 +148,8 @@ ipx_sap_print(const u_short *ipx, u_int length) else (void)printf("ipx-sap-nearest-req"); - if (length > 0) { - TCHECK(ipx[1]); - (void)printf(" %x '", EXTRACT_16BITS(&ipx[0])); - fn_print((u_char *)&ipx[1], (u_char *)&ipx[1] + 48); - putchar('\''); - } + TCHECK(ipx[0]); + (void)printf(" %x", EXTRACT_16BITS(&ipx[0])); break; case 2: @@ -152,7 +160,7 @@ ipx_sap_print(const u_short *ipx, u_int length) (void)printf("ipx-sap-nearest-resp"); for (i = 0; i < 8 && length > 0; i++) { - TCHECK2(ipx[27], 1); + TCHECK2(ipx[25], 10); (void)printf(" %x '", EXTRACT_16BITS(&ipx[0])); fn_print((u_char *)&ipx[1], (u_char *)&ipx[1] + 48); printf("' addr %s", @@ -162,12 +170,12 @@ ipx_sap_print(const u_short *ipx, u_int length) } break; default: - (void)printf("ipx-sap-?%x", command); + (void)printf("ipx-sap-?%x", command); break; } - return; + return; trunc: - printf("[|ipx %d]", length); + printf("[|ipx %d]", length); } void @@ -201,10 +209,11 @@ ipx_rip_print(const u_short *ipx, u_int length) } break; default: - (void)printf("ipx-rip-?%x", command); + (void)printf("ipx-rip-?%x", command); + break; } - return; + return; trunc: - printf("[|ipx %d]", length); + printf("[|ipx %d]", length); } diff --git a/contrib/tcpdump/print-isakmp.c b/contrib/tcpdump/print-isakmp.c index 66df93a..909f0b95 100644 --- a/contrib/tcpdump/print-isakmp.c +++ b/contrib/tcpdump/print-isakmp.c @@ -30,7 +30,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-isakmp.c,v 1.26 2000/12/12 09:20:26 itojun Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-isakmp.c,v 1.29 2001/10/26 03:41:29 itojun Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -702,12 +702,8 @@ isakmp_id_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, { int i; printf(" len=%d ", len); - for (i = 0; i < len; i++) { - if (isprint(data[i])) - printf("%c", data[i]); - else - printf("\\%03o", data[i]); - } + for (i = 0; i < len; i++) + safeputchar(data[i]); len = 0; break; } @@ -759,7 +755,6 @@ isakmp_id_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, } } if (data && len) { - len -= sizeof(*p); printf(" len=%d", len); if (2 < vflag) { printf(" "); @@ -1188,7 +1183,7 @@ isakmp_print(const u_char *bp, u_int length, const u_char *bp2) * encrypted, nothing we can do right now. * we hope to decrypt the packet in the future... */ - printf(" [|%s]", NPSTR(base.np)); + printf(" [encrypted %s]", NPSTR(base.np)); goto done; } diff --git a/contrib/tcpdump/print-isoclns.c b/contrib/tcpdump/print-isoclns.c index aaf360a..636de33 100644 --- a/contrib/tcpdump/print-isoclns.c +++ b/contrib/tcpdump/print-isoclns.c @@ -19,11 +19,14 @@ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * Original code by Matt Thomas, Digital Equipment Corporation + * + * Extensively modified by Hannes Gredler (hannes@juniper.net) for more + * complete IS-IS support. */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-isoclns.c,v 1.22 2000/10/11 04:04:33 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-isoclns.c,v 1.36 2002/01/10 09:33:23 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -37,6 +40,7 @@ static const char rcsid[] = #include <netinet/in.h> #include <stdio.h> +#include <string.h> #include "interface.h" #include "addrtoname.h" @@ -47,9 +51,10 @@ static const char rcsid[] = #define NLPID_CLNS 129 /* 0x81 */ #define NLPID_ESIS 130 /* 0x82 */ #define NLPID_ISIS 131 /* 0x83 */ +#define NLPID_IP6 0x8e +#define NLPID_IP 0xcc #define NLPID_NULLNS 0 - /* * IS-IS is defined in ISO 10589. Look there for protocol definitions. */ @@ -62,10 +67,13 @@ static const char rcsid[] = #define L1_LAN_IIH 15 #define L2_LAN_IIH 16 #define PTP_IIH 17 -#define L1_LS_PDU 18 -#define L2_LS_PDU 19 -#define L1_COMPLETE_SEQ_PDU 24 -#define L2_COMPLETE_SEQ_PDU 25 +#define L1_LSP 18 +#define L2_LSP 20 +#define L1_CSNP 24 +#define L2_CSNP 25 +#define L1_PSNP 26 +#define L2_PSNP 27 + /* * A TLV is a tuple of a type, length and a value and is normally used for @@ -73,21 +81,89 @@ static const char rcsid[] = * the well known types. */ -#define TLV_AREA_ADDR 1 -#define TLV_IS_REACH 2 -#define TLV_ES_REACH 3 -#define TLV_SUMMARY 5 -#define TLV_ISNEIGH 6 -#define TLV_PADDING 8 -#define TLV_LSP 9 -#define TLV_AUTHENT 10 -#define TLV_IP_REACH 128 -#define TLV_PROTOCOLS 129 -#define TLV_IP_EXTERN 130 -#define TLV_IDRP_INFO 131 -#define TLV_IPADDR 132 -#define TLV_IPAUTH 133 -#define TLV_PTP_ADJ 240 +#define TLV_AREA_ADDR 1 +#define TLV_IS_REACH 2 +#define TLV_ES_REACH 3 +#define TLV_SUMMARY 5 +#define TLV_ISNEIGH 6 +#define TLV_PADDING 8 +#define TLV_LSP 9 +#define TLV_AUTH 10 +#define TLV_CHECKSUM 12 +#define TLV_EXT_IS_REACH 22 +#define TLV_IP_REACH 128 +#define TLV_PROTOCOLS 129 +#define TLV_IP_REACH_EXT 130 +#define TLV_IDRP_INFO 131 +#define TLV_IPADDR 132 +#define TLV_IPAUTH 133 +#define TLV_TE_ROUTER_ID 134 +#define TLV_EXT_IP_REACH 135 +#define TLV_HOSTNAME 137 +#define TLV_RESTART_SIGNALING 211 +#define TLV_MT_IS_REACH 222 +#define TLV_MT_SUPPORTED 229 +#define TLV_IP6ADDR 232 +#define TLV_MT_REACH 235 +#define TLV_IP6_REACH 236 +#define TLV_PTP_ADJ 240 + +#define SUBTLV_EXT_IS_REACH_ADMIN_GROUP 3 +#define SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR 6 +#define SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR 8 +#define SUBTLV_EXT_IS_REACH_MAX_LINK_BW 9 +#define SUBTLV_EXT_IS_REACH_RESERVABLE_BW 10 +#define SUBTLV_EXT_IS_REACH_UNRESERVED_BW 11 +#define SUBTLV_EXT_IS_REACH_TE_METRIC 18 + +#define SUBTLV_AUTH_SIMPLE 1 +#define SUBTLV_AUTH_MD5 54 + +#define ISIS_MASK_LEVEL_BITS(x) ((x)&0x1) + +#define ISIS_MASK_LSP_OL_BIT(x) ((x)&0x4) +#define ISIS_MASK_LSP_ISTYPE_BITS(x) ((x)&0x3) +#define ISIS_MASK_LSP_PARTITION_BIT(x) ((x)&0x80) +#define ISIS_MASK_LSP_ATT_BITS(x) ((x)&0x78) +#define ISIS_MASK_LSP_ATT_ERROR_BIT(x) ((x)&0x40) +#define ISIS_MASK_LSP_ATT_EXPENSE_BIT(x) ((x)&0x20) +#define ISIS_MASK_LSP_ATT_DELAY_BIT(x) ((x)&0x10) +#define ISIS_MASK_LSP_ATT_DEFAULT_BIT(x) ((x)&0x8) + +#define ISIS_MASK_TLV_EXT_IP_UPDOWN(x) ((x)&0x80) +#define ISIS_MASK_TLV_EXT_IP_SUBTLV(x) ((x)&0x40) + +#define ISIS_MASK_TLV_IP6_UPDOWN(x) ((x)&0x80) +#define ISIS_MASK_TLV_IP6_IE(x) ((x)&0x40) +#define ISIS_MASK_TLV_IP6_SUBTLV(x) ((x)&0x20) + +#define ISIS_MASK_RESTART_RR(x) ((x)&0x1) +#define ISIS_MASK_RESTART_RA(x) ((x)&0x2) + +#define ISIS_LSP_TLV_METRIC_SUPPORTED(x) ((x)&0x80) +#define ISIS_LSP_TLV_METRIC_IE(x) ((x)&0x40) +#define ISIS_LSP_TLV_METRIC_UPDOWN(x) ((x)&0x80) +#define ISIS_LSP_TLV_METRIC_VALUE(x) ((x)&0x3f) + +#define ISIS_LSP_TYPE_UNUSED0 0 +#define ISIS_LSP_TYPE_LEVEL_1 1 +#define ISIS_LSP_TYPE_UNUSED2 2 +#define ISIS_LSP_TYPE_LEVEL_2 3 + +static struct tok isis_lsp_istype_values[] = { + { ISIS_LSP_TYPE_UNUSED0, "Unused 0x0 (invalid)"}, + { ISIS_LSP_TYPE_LEVEL_1, "L1 IS"}, + { ISIS_LSP_TYPE_UNUSED2, "Unused 0x2 (invalid)"}, + { ISIS_LSP_TYPE_LEVEL_2, "L1L2 IS"}, + { 0, NULL } +}; + +static struct tok isis_nlpid_values[] = { + { NLPID_CLNS, "CLNS"}, + { NLPID_IP, "IPv4"}, + { NLPID_IP6, "IPv6"}, + { 0, "unknown" } +}; /* * Katz's point to point adjacency TLV uses codes to tell us the state of @@ -98,89 +174,117 @@ static const char rcsid[] = #define ISIS_PTP_ADJ_INIT 1 #define ISIS_PTP_ADJ_DOWN 2 -static int osi_cksum(const u_char *, int, u_char *); +static int osi_cksum(const u_char *, u_int, u_char *); static void esis_print(const u_char *, u_int); static int isis_print(const u_char *, u_int); -struct isis_ptp_adjancey_values { - u_char id; - char *name; +static struct tok isis_ptp_adjancey_values[] = { + { ISIS_PTP_ADJ_UP, "Up" }, + { ISIS_PTP_ADJ_INIT, "Initializing" }, + { ISIS_PTP_ADJ_DOWN, "Down" } }; -static struct isis_ptp_adjancey_values isis_ptp_adjancey_values[] = { - { ISIS_PTP_ADJ_UP, "UP" }, - { ISIS_PTP_ADJ_INIT, "INIT" }, - { ISIS_PTP_ADJ_DOWN, "DOWN" } +struct isis_tlv_ptp_adj { + u_char adjacency_state; + u_char ext_local_circuit_id[4]; + u_char neighbor_sysid[SYSTEM_ID_LEN]; + u_char neighbor_ext_local_circuit_id[4]; }; +struct isis_tlv_ip_reach { + u_char metric_default; + u_char metric_delay; + u_char metric_expense; + u_char metric_error; + u_char prefix[4]; + u_char mask[4]; +}; + +struct isis_tlv_is_reach { + u_char metric_default; + u_char metric_delay; + u_char metric_expense; + u_char metric_error; + u_char neighbor_nodeid[SYSTEM_ID_LEN+1]; +}; + + struct isis_common_header { u_char nlpid; u_char fixed_len; u_char version; /* Protocol version? */ u_char id_length; - u_char enc_pdu_type; /* 3 MSbs are reserved */ + u_char pdu_type; /* 3 MSbs are reserved */ u_char pkt_version; /* Packet format version? */ u_char reserved; - u_char enc_max_area; + u_char max_area; }; -struct isis_header { - u_char nlpid; - u_char fixed_len; - u_char version; /* Protocol version? */ - u_char id_length; - u_char enc_pdu_type; /* 3 MSbs are reserved */ - u_char pkt_version; /* Packet format version? */ - u_char reserved; - u_char enc_max_area; - u_char circuit; - u_char enc_source_id[SYSTEM_ID_LEN]; - u_char enc_holding_time[2]; - u_char enc_packet_len[2]; - u_char enc_priority; - u_char enc_lan_id[SYSTEM_ID_LEN+1]; +struct isis_iih_lan_header { + u_char circuit_type; + u_char source_id[SYSTEM_ID_LEN]; + u_char holding_time[2]; + u_char pdu_len[2]; + u_char priority; + u_char lan_id[SYSTEM_ID_LEN+1]; }; -struct isis_lan_header { - u_char circuit; - u_char enc_source_id[SYSTEM_ID_LEN]; - u_char enc_holding_time[2]; - u_char enc_packet_len[2]; - u_char enc_priority; - u_char enc_lan_id[SYSTEM_ID_LEN+1]; + +struct isis_iih_ptp_header { + u_char circuit_type; + u_char source_id[SYSTEM_ID_LEN]; + u_char holding_time[2]; + u_char pdu_len[2]; + u_char circuit_id; }; -struct isis_ptp_header { - u_char circuit; - u_char enc_source_id[SYSTEM_ID_LEN]; - u_char enc_holding_time[2]; - u_char enc_packet_len[2]; - u_char loc_circuit_id; +struct isis_lsp_header { + u_char pdu_len[2]; + u_char remaining_lifetime[2]; + u_char lsp_id[SYSTEM_ID_LEN+2]; + u_char sequence_number[4]; + u_char checksum[2]; + u_char typeblock; }; -#define ISIS_COMMON_HEADER_SIZE (sizeof(struct isis_common_header)) -#define ISIS_HEADER_SIZE (15+(SYSTEM_ID_LEN<<1)) -#define ISIS_PTP_HEADER_SIZE (14+SYSTEM_ID_LEN) -#define L1_LS_PDU_HEADER_SIZE (21+SYSTEM_ID_LEN) -#define L2_LS_PDU_HEADER_SIZE L1_LS_PDU_HEADER_SIZE -#define L1_COMPLETE_SEQ_PDU_HEADER_SIZE 33 -#define L2_COMPLETE_SEQ_PDU_HEADER_SIZE L1_COMPLETE_SEQ_PDU_HEADER_SIZE +struct isis_csnp_header { + u_char pdu_len[2]; + u_char source_id[SYSTEM_ID_LEN+1]; + u_char start_lsp_id[SYSTEM_ID_LEN+2]; + u_char end_lsp_id[SYSTEM_ID_LEN+2]; +}; +struct isis_psnp_header { + u_char pdu_len[2]; + u_char source_id[SYSTEM_ID_LEN+1]; +}; +struct isis_tlv_lsp { + u_char remaining_lifetime[2]; + u_char lsp_id[SYSTEM_ID_LEN+2]; + u_char sequence_number[4]; + u_char checksum[2]; +}; + +#define ISIS_COMMON_HEADER_SIZE (sizeof(struct isis_common_header)) +#define ISIS_IIH_LAN_HEADER_SIZE (sizeof(struct isis_iih_lan_header)) +#define ISIS_IIH_PTP_HEADER_SIZE (sizeof(struct isis_iih_ptp_header)) +#define ISIS_LSP_HEADER_SIZE (sizeof(struct isis_lsp_header)) +#define ISIS_CSNP_HEADER_SIZE (sizeof(struct isis_csnp_header)) +#define ISIS_PSNP_HEADER_SIZE (sizeof(struct isis_psnp_header)) -void -isoclns_print(const u_char *p, u_int length, u_int caplen, +void isoclns_print(const u_char *p, u_int length, u_int caplen, const u_char *esrc, const u_char *edst) { u_char pdu_type; - struct isis_header *header; + const struct isis_common_header *header; - header = (struct isis_header *)p; - pdu_type = header->enc_pdu_type & PDU_TYPE_MASK; + header = (const struct isis_common_header *)p; + pdu_type = header->pdu_type & PDU_TYPE_MASK; if (caplen < 1) { printf("[|iso-clns] "); - if (!eflag) + if (!eflag && esrc != NULL && edst != NULL) printf("%s > %s", etheraddr_string(esrc), etheraddr_string(edst)); @@ -190,50 +294,46 @@ isoclns_print(const u_char *p, u_int length, u_int caplen, switch (*p) { case NLPID_CLNS: - printf("iso clns"); - if (!eflag) - (void)printf(" %s > %s", + (void)printf("CLNS(%d)", length); + if (!eflag && esrc != NULL && edst != NULL) + (void)printf(", %s > %s", etheraddr_string(esrc), etheraddr_string(edst)); break; case NLPID_ESIS: - printf("iso esis"); - if (!eflag) - (void)printf(" %s > %s", + (void)printf("ESIS"); + if (!eflag && esrc != NULL && edst != NULL) + (void)printf(", %s > %s", etheraddr_string(esrc), etheraddr_string(edst)); esis_print(p, length); return; case NLPID_ISIS: - printf("iso isis"); - if (!eflag) { - if(pdu_type != PTP_IIH) - (void)printf(" %s > %s", - etheraddr_string(esrc), - etheraddr_string(edst)); - } - (void)printf(" len=%d ", length); + (void)printf("ISIS(%d)", length); + if (!eflag && esrc != NULL && edst != NULL) + (void)printf(", %s > %s", + etheraddr_string(esrc), + etheraddr_string(edst)); if (!isis_print(p, length)) - default_print_unaligned(p, caplen); + default_print_unaligned(p, caplen); break; case NLPID_NULLNS: - printf("iso nullns"); - if (!eflag) - (void)printf(" %s > %s", + (void)printf("ISO NULLNS(%d)", length); + if (!eflag && esrc != NULL && edst != NULL) + (void)printf(", %s > %s", etheraddr_string(esrc), etheraddr_string(edst)); break; default: - printf("iso clns %02x", p[0]); - if (!eflag) - (void)printf(" %s > %s", + (void)printf("CLNS %02x(%d)", p[0], length); + if (!eflag && esrc != NULL && edst != NULL) + (void)printf(", %s > %s", etheraddr_string(esrc), etheraddr_string(edst)); - (void)printf(" len=%d ", length); if (caplen > 1) default_print_unaligned(p, caplen); break; @@ -256,17 +356,19 @@ static void esis_print(const u_char *p, u_int length) { const u_char *ep; - int li = p[1]; - const struct esis_hdr *eh = (const struct esis_hdr *) &p[2]; + u_int li; + const struct esis_hdr *eh; u_char off[2]; - if (length == 2) { + if (length <= 2) { if (qflag) printf(" bad pkt!"); else printf(" no header at all!"); return; } + li = p[1]; + eh = (const struct esis_hdr *) &p[2]; ep = p + li; if (li > length) { if (qflag) @@ -372,7 +474,7 @@ esis_print(const u_char *p, u_int length) } if (vflag) while (p < ep && li) { - int op, opli; + u_int op, opli; const u_char *q; if (snapend - p < 2) @@ -398,7 +500,7 @@ esis_print(const u_char *p, u_int length) continue; } printf (" %d:<", op); - while (--opli >= 0) + while (opli-- > 0) printf("%02x", *q++); printf (">"); } @@ -408,181 +510,438 @@ esis_print(const u_char *p, u_int length) * print_nsap * Print out an NSAP. */ +static int +print_nsap(register const u_char *cp, register int length) +{ + int i; + + for (i = 0; i < length; i++) { + if (!TTEST2(*cp, 1)) + return (0); + printf("%02x", *cp++); + if (((i & 1) == 0) && (i + 1 < length)) { + printf("."); + } + } + return (1); +} + +static int +isis_print_sysid(const u_char *cp) +{ + int i; + + for (i = 1; i <= 6; i++) { + if (!TTEST2(*cp, 1)) + return (0); + printf("%02x", *cp++); + if ((i==2)^(i==4)) { + printf("."); + } + } + return (1); +} + +static int +isis_print_nodeid(const u_char *cp) +{ + int i; + + for (i = 1; i <= 7; i++) { + if (!TTEST2(*cp, 1)) + return (0); + printf("%02x", *cp++); + if ((i & 1) == 0) { + printf("."); + } + } + return (1); +} static void -print_nsap (register const u_char *cp, register int length) +isis_print_lspid(const u_char *cp) { - int i; - - for (i = 0; i < length; i++) { - printf("%02x", *cp++); - if (((i & 1) == 0) && (i + 1 < length)) { - printf("."); + int i; + + for (i = 1; i <= 7; i++) { + printf("%02x", *cp++); + if ((i & 1) == 0) + printf("."); } + printf("-%02x", *cp); +} - } +static int +isis_print_tlv_ip_reach (const u_char *cp, int length) +{ + int bitmasks[33] = { + 0x00000000, + 0x80000000, 0xc0000000, 0xe0000000, 0xf0000000, + 0xf8000000, 0xfc000000, 0xfe000000, 0xff000000, + 0xff800000, 0xffc00000, 0xffe00000, 0xfff00000, + 0xfff80000, 0xfffc0000, 0xfffe0000, 0xffff0000, + 0xffff8000, 0xffffc000, 0xffffe000, 0xfffff000, + 0xfffff800, 0xfffffc00, 0xfffffe00, 0xffffff00, + 0xffffff80, 0xffffffc0, 0xffffffe0, 0xfffffff0, + 0xfffffff8, 0xfffffffc, 0xfffffffe, 0xffffffff + }; + int mask, prefix_len; + const struct isis_tlv_ip_reach *tlv_ip_reach; + + tlv_ip_reach = (const struct isis_tlv_ip_reach *)cp; + + while (length > 0) { + if (length < sizeof(*tlv_ip_reach)) { + printf("short IP reachability (%d vs %lu)", length, + (unsigned long)sizeof(*tlv_ip_reach)); + return (0); + } + + if (!TTEST(*tlv_ip_reach)) + return (0); + + mask = EXTRACT_32BITS(tlv_ip_reach->mask); + prefix_len = 0; + + while (prefix_len <= 33) { + if (bitmasks[prefix_len++] == mask) { + prefix_len--; + break; + } + } + + /* + * 34 indicates no match -> must be a discontiguous netmask + * lets dump the mask, otherwise print the prefix_len + */ + if (prefix_len == 34) + printf("\n\t\t\tIPv4 prefix: %u.%u.%u.%u mask %u.%u.%u.%u", + (tlv_ip_reach->prefix)[0], + (tlv_ip_reach->prefix)[1], + (tlv_ip_reach->prefix)[2], + (tlv_ip_reach->prefix)[3], + (tlv_ip_reach->mask)[0], (tlv_ip_reach->mask)[1], + (tlv_ip_reach->mask)[2], (tlv_ip_reach->mask)[3]); + else + printf("\n\t\t\tIPv4 prefix: %u.%u.%u.%u/%u", + (tlv_ip_reach->prefix)[0], + (tlv_ip_reach->prefix)[1], + (tlv_ip_reach->prefix)[2], + (tlv_ip_reach->prefix)[3], prefix_len); + + printf("\n\t\t\t Default Metric: %02d, %s, Distribution: %s", + ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->metric_default), + ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->metric_default) ? "External" : "Internal", + ISIS_LSP_TLV_METRIC_UPDOWN(tlv_ip_reach->metric_default) ? "down" : "up"); + + if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->metric_delay)) + printf("\n\t\t\t Delay Metric: %02d, %s", + ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->metric_delay), + ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->metric_delay) ? "External" : "Internal"); + + if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->metric_expense)) + printf("\n\t\t\t Expense Metric: %02d, %s", + ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->metric_expense), + ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->metric_expense) ? "External" : "Internal"); + + if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->metric_error)) + printf("\n\t\t\t Error Metric: %02d, %s", + ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->metric_error), + ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->metric_error) ? "External" : "Internal"); + + length -= sizeof(struct isis_tlv_ip_reach); + tlv_ip_reach++; + } + return (1); } /* * isis_print * Decode IS-IS packets. Return 0 on error. - * - * So far, this is only smart enough to print IIH's. Someday... */ -static int -isis_print (const u_char *p, u_int length) +static int isis_print (const u_char *p, u_int length) { - struct isis_header *header; - struct isis_ptp_header *header_ptp; - u_char pdu_type, max_area, priority, type, len, tmp, alen; - const u_char *pptr, *tptr; - u_short packet_len, holding_time; - int i; - - header = (struct isis_header *)p; - header_ptp = (struct isis_ptp_header *)header; - printf("\n\t\t\t"); - + const struct isis_common_header *header; + + const struct isis_iih_lan_header *header_iih_lan; + const struct isis_iih_ptp_header *header_iih_ptp; + const struct isis_lsp_header *header_lsp; + const struct isis_csnp_header *header_csnp; + const struct isis_psnp_header *header_psnp; + + const struct isis_tlv_lsp *tlv_lsp; + const struct isis_tlv_ptp_adj *tlv_ptp_adj; + const struct isis_tlv_is_reach *tlv_is_reach; + + u_char pdu_type, max_area, type, len, tmp, alen, subl, subt, tslen, ttslen; + const u_char *optr, *pptr, *tptr; + u_short packet_len,pdu_len; + u_int i,j,bit_length,byte_length,metric; + u_char prefix[4]; /* copy buffer for ipv4 prefixes */ +#ifdef INET6 + u_char prefix6[16]; /* copy buffer for ipv6 prefixes */ +#endif + u_char off[2]; + float bw; /* copy buffer for several subTLVs of the extended IS reachability TLV */ + + packet_len=length; + optr = p; /* initialize the _o_riginal pointer - need it for parsing the checksum TLV */ + header = (const struct isis_common_header *)p; + TCHECK(*header); + pptr = p+(ISIS_COMMON_HEADER_SIZE); + header_iih_lan = (const struct isis_iih_lan_header *)pptr; + header_iih_ptp = (const struct isis_iih_ptp_header *)pptr; + header_lsp = (const struct isis_lsp_header *)pptr; + header_csnp = (const struct isis_csnp_header *)pptr; + header_psnp = (const struct isis_psnp_header *)pptr; + /* * Sanity checking of the header. */ if (header->nlpid != NLPID_ISIS) { - printf(" coding error!"); - return(0); + printf(", coding error!"); + return (0); } if (header->version != ISIS_VERSION) { - printf(" version %d packet not supported", header->version); - return(0); + printf(", version %d packet not supported", header->version); + return (0); } if ((header->id_length != SYSTEM_ID_LEN) && (header->id_length != 0)) { - printf(" system ID length of %d is not supported", + printf(", system ID length of %d is not supported", header->id_length); - return(0); - } - - if ((header->fixed_len != ISIS_HEADER_SIZE) && - (header->fixed_len != ISIS_PTP_HEADER_SIZE) && - (header->fixed_len != L1_LS_PDU_HEADER_SIZE) && - (header-> fixed_len != L1_COMPLETE_SEQ_PDU_HEADER_SIZE) ) { - printf(" bogus fixed header length %u", - header->fixed_len); - return(0); - } - - pdu_type = header->enc_pdu_type & PDU_TYPE_MASK; - if ((pdu_type != L1_LAN_IIH) && (pdu_type != L2_LAN_IIH) && - (pdu_type != PTP_IIH) && - (pdu_type != L1_COMPLETE_SEQ_PDU) && - (pdu_type != L2_COMPLETE_SEQ_PDU) ) { - printf(" PDU type (%d) not supported", pdu_type); - return(0); + return (0); } if (header->pkt_version != ISIS_VERSION) { - printf(" version %d packet not supported", header->pkt_version); - return(0); + printf(", version %d packet not supported", header->pkt_version); + return (0); } - max_area = header->enc_max_area; + max_area = header->max_area; switch(max_area) { case 0: max_area = 3; /* silly shit */ break; case 255: - printf(" bad packet -- 255 areas"); - return(0); + printf(", bad packet -- 255 areas"); + return (0); default: break; } - switch (header->circuit) { - case 0: - printf(" PDU with circuit type 0"); - return(0); - case 1: - if (pdu_type == L2_LAN_IIH) { - printf(" L2 IIH on an L1 only circuit"); - return(0); + printf(", hlen: %u, v: %u, sys-id-len: 6 (0), max-area: %u (%u)", + header->fixed_len, + header->pkt_version, + max_area, + header->max_area); + + pdu_type=header->pdu_type; + + switch (pdu_type) { + + case L1_LAN_IIH: + case L2_LAN_IIH: + if (header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE)) { + printf(", bogus fixed header length %u should be %lu", + header->fixed_len, (unsigned long)ISIS_IIH_LAN_HEADER_SIZE); + return (0); } - break; - case 2: - if (pdu_type == L1_LAN_IIH) { - printf(" L1 IIH on an L2 only circuit"); - return(0); + + pdu_len=EXTRACT_16BITS(header_iih_lan->pdu_len); + if (packet_len>pdu_len) { + packet_len=pdu_len; /* do TLV decoding as long as it makes sense */ + length=pdu_len; } - break; - case 3: - break; - default: - printf(" unknown circuit type"); - return(0); - } - - holding_time = EXTRACT_16BITS(header->enc_holding_time); - - packet_len = EXTRACT_16BITS(header->enc_packet_len); - if ((packet_len < ISIS_HEADER_SIZE) || - (packet_len > length)) { - printf(" bogus packet length %d, real length %d", packet_len, - length); - return(0); - } - if(pdu_type != PTP_IIH) - priority = header->enc_priority & PRIORITY_MASK; + printf(", L%s Lan IIH (%u)", + ISIS_MASK_LEVEL_BITS(pdu_type) ? "1" : "2", + pdu_len); + + TCHECK(*header_iih_lan); + printf("\n\t\t source-id: "); + isis_print_sysid(header_iih_lan->source_id); + printf(", holding time: %us",EXTRACT_16BITS(header_iih_lan->holding_time)); + switch(header_iih_lan->circuit_type) { + + case 1: + printf(", Level 1 only"); + break; - /* - * Now print the fixed header. - */ - switch (pdu_type) { - case L1_LAN_IIH: - printf(" L1 lan iih, "); - break; - case L2_LAN_IIH: - printf(" L2 lan iih, "); + case 2: + printf(", Level 2 only"); + break; + + case 3: + printf(", Level 1, Level 2"); + break; + + default: + printf(", unknown 0x%02x", header_iih_lan->circuit_type); + break; + } + printf("\n\t\t lan-id: "); + isis_print_nodeid(header_iih_lan->lan_id); + printf(", Priority: %u",(header_iih_lan->priority) & PRIORITY_MASK); + + packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE); + pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE); break; + case PTP_IIH: - printf(" PTP iih, "); - break; - } + if (header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE)) { + printf(", bogus fixed header length %u should be %lu", + header->fixed_len, (unsigned long)ISIS_IIH_PTP_HEADER_SIZE); + return (0); + } + + pdu_len=EXTRACT_16BITS(header_iih_ptp->pdu_len); + if (packet_len>pdu_len) { + packet_len=pdu_len; /* do TLV decoding as long as it makes sense */ + length=pdu_len; + } + + printf(", PTP IIH (%u)",pdu_len); + TCHECK(*header_iih_ptp); + printf("\n\t\t source-id: "); + isis_print_sysid(header_iih_ptp->source_id); + printf(", holding time: %us",EXTRACT_16BITS(header_iih_ptp->holding_time)); + printf(", circuit-id: 0x%02x", header_iih_ptp->circuit_id); + switch(header_iih_ptp->circuit_type) { + + case 1: + printf(", Level 1 only"); + break; + + case 2: + printf(", Level 2 only"); + break; + + case 3: + printf(", Level 1, Level 2"); + break; - printf("circuit "); - switch (header->circuit) { - case 1: - printf("l1 only, "); + default: + printf(", unknown 0x%02x", header_iih_ptp->circuit_type); + break; + } + + packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE); + pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE); break; - case 2: - printf("l2 only, "); + + case L1_LSP: + case L2_LSP: + if (header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE)) { + printf(", bogus fixed header length %u should be %lu", + header->fixed_len, (unsigned long)ISIS_LSP_HEADER_SIZE); + return (0); + } + + pdu_len=EXTRACT_16BITS(header_lsp->pdu_len); + if (packet_len>pdu_len) { + packet_len=pdu_len; /* do TLV decoding as long as it makes sense */ + length=pdu_len; + } + + if (pdu_type == L1_LSP) + printf(", L1 LSP (%u)",pdu_len); + else if (pdu_type == L2_LSP) + printf(", L2 LSP (%u)",pdu_len); + + TCHECK(*header_lsp); + printf("\n\t\t lsp-id: "); + isis_print_lspid(header_lsp->lsp_id); + printf(", sequence number: 0x%08x",EXTRACT_32BITS(header_lsp->sequence_number)); + printf(", lifetime: %5us",EXTRACT_16BITS(header_lsp->remaining_lifetime)); + printf("\n\t\t checksum: 0x%04x",EXTRACT_16BITS(header_lsp->checksum)); + + printf(", %s", ISIS_MASK_LSP_OL_BIT(header_lsp->typeblock) ? "Overload bit set, " : ""); + + if (ISIS_MASK_LSP_ATT_BITS(header_lsp->typeblock)) { + printf("%s", ISIS_MASK_LSP_ATT_DEFAULT_BIT(header_lsp->typeblock) ? "default " : ""); + printf("%s", ISIS_MASK_LSP_ATT_DELAY_BIT(header_lsp->typeblock) ? "delay " : ""); + printf("%s", ISIS_MASK_LSP_ATT_EXPENSE_BIT(header_lsp->typeblock) ? "expense " : ""); + printf("%s", ISIS_MASK_LSP_ATT_ERROR_BIT(header_lsp->typeblock) ? "error " : ""); + printf("ATT bit set, "); + } + printf("%s", ISIS_MASK_LSP_PARTITION_BIT(header_lsp->typeblock) ? "P bit set, " : ""); + printf("%s", tok2str(isis_lsp_istype_values,"Unknown(0x%x)",ISIS_MASK_LSP_ISTYPE_BITS(header_lsp->typeblock))); + + packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE); + pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE); break; - case 3: - printf("l1-l2, "); + + case L1_CSNP: + case L2_CSNP: + if (header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE)) { + printf(", bogus fixed header length %u should be %lu", + header->fixed_len, (unsigned long)ISIS_CSNP_HEADER_SIZE); + return (0); + } + + pdu_len=EXTRACT_16BITS(header_csnp->pdu_len); + if (packet_len>pdu_len) { + packet_len=pdu_len; /* do TLV decoding as long as it makes sense */ + length=pdu_len; + } + + printf(", L%s CSNP (%u)", ISIS_MASK_LEVEL_BITS(pdu_type) ? "2" : "1", pdu_len); + TCHECK(*header_csnp); + printf("\n\t\t source-id: "); + isis_print_nodeid(header_csnp->source_id); + printf("\n\t\t start lsp-id: "); + isis_print_lspid(header_csnp->start_lsp_id); + printf("\n\t\t end lsp-id: "); + isis_print_lspid(header_csnp->end_lsp_id); + + packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE); + pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE); + break; + + case L1_PSNP: + case L2_PSNP: + if (header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE)) { + printf("- bogus fixed header length %u should be %lu", + header->fixed_len, (unsigned long)ISIS_PSNP_HEADER_SIZE); + return (0); + } + + pdu_len=EXTRACT_16BITS(header_psnp->pdu_len); + if (packet_len>pdu_len) { + packet_len=pdu_len; /* do TLV decoding as long as it makes sense */ + length=pdu_len; + } + + printf(", L%s PSNP (%u)", ISIS_MASK_LEVEL_BITS(pdu_type) ? "2" : "1", pdu_len); + TCHECK(*header_psnp); + printf("\n\t\t source-id: "); + isis_print_nodeid(header_psnp->source_id); + + packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE); + pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE); break; - } - printf ("holding time %d ", holding_time); - printf ("\n\t\t\t source %s, length %d", - etheraddr_string(header->enc_source_id), packet_len); - if((pdu_type==L1_LAN_IIH)||(pdu_type==L2_LAN_IIH)) - printf ("\n\t\t\t lan id %s(%d)", etheraddr_string(header->enc_lan_id), - header->enc_lan_id[SYSTEM_ID_LEN]); + default: + printf(", PDU type (0x%02x) not supported", pdu_type); + return (1); + } /* * Now print the TLV's. */ - if(pdu_type==PTP_IIH) { - packet_len -= ISIS_PTP_HEADER_SIZE; - pptr = p + ISIS_PTP_HEADER_SIZE; - } else { - packet_len -= ISIS_HEADER_SIZE; - pptr = p + ISIS_HEADER_SIZE; - } + while (packet_len >= 2) { - if (pptr >= snapend) { - printf("\n\t\t\t packet exceeded snapshot"); - return(1); + if (pptr == snapend) { + return (1); + } + + if (!TTEST2(*pptr, 2)) { + printf("\n\t\t\t packet exceeded snapshot (%ld) bytes", + (long)(pptr-snapend)); + return (1); } type = *pptr++; len = *pptr++; @@ -590,53 +949,593 @@ isis_print (const u_char *p, u_int length) if (len > packet_len) { break; } + printf("\n\t\t "); switch (type) { case TLV_AREA_ADDR: - printf("\n\t\t\t area addresses"); + printf("Area address(es) (%u)",len); tmp = len; tptr = pptr; + if (!TTEST2(*tptr, 1)) + goto trunctlv; alen = *tptr++; while (tmp && alen < tmp) { - printf("\n\t\t\t "); - print_nsap(tptr, alen); - printf(" (%d)", alen); + printf("\n\t\t\tArea address (%u): ",alen); + if (!print_nsap(tptr, alen)) + return (1); tptr += alen; tmp -= alen + 1; + if (tmp==0) /* if this is the last area address do not attemt a boundary check */ + break; + if (!TTEST2(*tptr, 1)) + goto trunctlv; alen = *tptr++; } break; case TLV_ISNEIGH: - printf("\n\t\t\t neighbor addresses"); + printf("IS Neighbor(s) (%u)",len); tmp = len; tptr = pptr; while (tmp >= ETHER_ADDR_LEN) { - printf("\n\t\t\t %s", etheraddr_string(tptr)); + printf("\n\t\t\tIS Neighbor: "); + if (!isis_print_sysid(tptr)) + return (1); tmp -= ETHER_ADDR_LEN; tptr += ETHER_ADDR_LEN; } break; + case TLV_PADDING: - printf("\n\t\t\t padding for %d bytes", len); + printf("Padding (%u)", len); + break; + + case TLV_MT_IS_REACH: + printf("Multi Topology IS Reachability (%u)",len); + tptr=pptr; + tmp=len; + while (tmp>0) { + printf("\n\t\t\t"); + if (!TTEST2(*tptr, 2)) + goto trunctlv; + switch(EXTRACT_16BITS(tptr)&0x0fff) { + + case 0: + printf("IPv4 unicast"); + break; + + case 1: + printf("In-Band Management"); + break; + + case 2: + printf("IPv6 unicast"); + break; + + case 3: + printf("Multicast"); + break; + + case 4095: + printf("Development, Experimental or Proprietary"); + break; + + default: + printf("Reserved for IETF Consensus"); + break; + } + printf(" Topology (0x%03x)",EXTRACT_16BITS(tptr)&0x0fff); + tptr+=2; + printf("\n\t\t\t IS Neighbor: "); + if (!isis_print_nodeid(tptr)) + return (1); + tptr+=(SYSTEM_ID_LEN+1); + if (!TTEST2(*tptr, 3)) + goto trunctlv; + printf(", Metric: %d",EXTRACT_24BITS(tptr)); + tptr+=3; + if (!TTEST2(*tptr, 1)) + goto trunctlv; + tslen=*(tptr++); + printf(", %ssub-TLVs present",tslen ? "" : "no "); + + tptr+=tslen; + tmp-=(13+tslen); + } + break; + + case TLV_EXT_IS_REACH: + printf("Extended IS Reachability (%u)",len); + tptr=pptr; + tmp=len; + while (tmp>0) { + printf("\n\t\t\tIS Neighbor: "); + if (!isis_print_nodeid(tptr)) + return (1); + tptr+=(SYSTEM_ID_LEN+1); + if (!TTEST2(*tptr, 3)) + goto trunctlv; + printf(", Metric: %d",EXTRACT_24BITS(tptr)); + tptr+=3; + if (!TTEST2(*tptr, 1)) + goto trunctlv; + tslen=*(tptr++); + printf(", %ssub-TLVs present",tslen ? "" : "no "); + if (tslen) { + printf(" (%u)",tslen); + ttslen=tslen; + while (ttslen>0) { + if (!TTEST2(*tptr,2)) + goto trunctlv; + printf("\n\t\t\t "); + subt=*(tptr++); + subl=*(tptr++); + switch(subt) { + case SUBTLV_EXT_IS_REACH_ADMIN_GROUP: + printf("Administrative groups: 0x%08x", EXTRACT_32BITS(tptr)); + break; + case SUBTLV_EXT_IS_REACH_MAX_LINK_BW : + if (!TTEST2(*tptr,4)) + goto trunctlv; + j = EXTRACT_32BITS(tptr); + memcpy (&bw, &j, 4); + printf("Maximum link bandwidth : %.3f Mbps", + bw*8/1000000 ); + break; + case SUBTLV_EXT_IS_REACH_RESERVABLE_BW : + if (!TTEST2(*tptr,4)) + goto trunctlv; + j = EXTRACT_32BITS(tptr); + memcpy (&bw, &j, 4); + printf("Reservable link bandwidth: %.3f Mbps", + bw*8/1000000 ); + break; + case SUBTLV_EXT_IS_REACH_UNRESERVED_BW : + printf("Unreserved bandwidth:"); + for (i = 0; i < 8; i++) { + if (!TTEST2(*tptr,4)) + goto trunctlv; + j = EXTRACT_32BITS(tptr); + memcpy (&bw, &j, 4); + printf("\n\t\t\t priority level %d: %.3f Mbps", + i, bw*8/1000000 ); + tptr+=4; + } + tptr-=32; + break; + case SUBTLV_EXT_IS_REACH_TE_METRIC: + if (!TTEST2(*tptr,3)) + goto trunctlv; + printf("Traffic Engineering Metric: %d", EXTRACT_24BITS(tptr)); + break; + case SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR: + if (!TTEST2(*tptr,4)) + goto trunctlv; + printf("IPv4 interface address: %s", ipaddr_string(tptr)); + break; + case SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR: + if (!TTEST2(*tptr,4)) + goto trunctlv; + printf("IPv4 neighbor address: %s", ipaddr_string(tptr)); + break; + case 250: + case 251: + case 252: + case 253: + case 254: + printf("Reserved for cisco specific extensions, type %d, length %d", subt, subl); + break; + case 255: + printf("Reserved for future expansion, type %d, length %d", subt, subl); + break; + default: + printf("unknown subTLV, type %d, length %d", subt, subl); + } + tptr+=subl; + ttslen-=(subl+2); + } + } + tptr+=tslen; + tmp-=(11+tslen); + } + break; + case TLV_IS_REACH: + printf("IS Reachability (%u)",len); + + tptr=pptr; + + if (!TTEST2(*tptr,1)) /* check if there is one byte left to read out the virtual flag */ + goto trunctlv; + + switch (*tptr) { + case 0: + printf("\n\t\t\tIsNotVirtual"); + break; + case 1: + printf("\n\t\t\tIsVirtual"); + break; + default: + printf("\n\t\t\tbogus virtual flag 0x%02x",(*tptr)); + break; + } + + tptr++; + + tlv_is_reach = (const struct isis_tlv_is_reach *)tptr; + + tmp = len; + while (tmp >= sizeof(struct isis_tlv_is_reach)) { + if (!TTEST(*tlv_is_reach)) + goto trunctlv; + + printf("\n\t\t\tIS Neighbor: "); + isis_print_nodeid(tlv_is_reach->neighbor_nodeid); + + printf(", Default Metric: %d, %s", + ISIS_LSP_TLV_METRIC_VALUE(tlv_is_reach->metric_default), + ISIS_LSP_TLV_METRIC_IE(tlv_is_reach->metric_default) ? "External" : "Internal"); + + if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_is_reach->metric_delay)) + printf("\n\t\t\t Delay Metric: %d, %s", + ISIS_LSP_TLV_METRIC_VALUE(tlv_is_reach->metric_delay), + ISIS_LSP_TLV_METRIC_IE(tlv_is_reach->metric_delay) ? "External" : "Internal"); + + if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_is_reach->metric_expense)) + printf("\n\t\t\t Expense Metric: %d, %s", + ISIS_LSP_TLV_METRIC_VALUE(tlv_is_reach->metric_expense), + ISIS_LSP_TLV_METRIC_IE(tlv_is_reach->metric_expense) ? "External" : "Internal"); + + if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_is_reach->metric_error)) + printf("\n\t\t\t Error Metric: %d, %s", + ISIS_LSP_TLV_METRIC_VALUE(tlv_is_reach->metric_error), + ISIS_LSP_TLV_METRIC_IE(tlv_is_reach->metric_error) ? "External" : "Internal"); + + tmp -= sizeof(struct isis_tlv_is_reach); + tlv_is_reach++; + } + break; + + case TLV_IP_REACH: + printf("IP Internal reachability (%u)",len); + if (!isis_print_tlv_ip_reach(pptr, len)) + return (1); + break; + + case TLV_IP_REACH_EXT: + printf("IP External reachability (%u)",len); + if (!isis_print_tlv_ip_reach(pptr, len)) + return (1); + break; + + case TLV_EXT_IP_REACH: + printf("Extended IP reachability (%u)",len); + i=len; + tptr=pptr; + + while (i>0) { + memset (prefix, 0, 4); + if (!TTEST2(*tptr, 4)) + return (1); + metric = EXTRACT_32BITS(tptr); + tptr+=4; + + if (!TTEST2(*tptr, 1)) + return (1); + j=*(tptr); + bit_length = (*(tptr)++&0x3f); + byte_length = (bit_length + 7) / 8; + if (!TTEST2(*tptr, byte_length)) + return (1); + + memcpy(prefix,tptr,byte_length); + + printf("\n\t\t\tIPv4 prefix: %u.%u.%u.%u/%d", + prefix[0], + prefix[1], + prefix[2], + prefix[3], + bit_length); + + printf("\n\t\t\t Metric: %u, Distribution: %s", + metric, + ISIS_MASK_TLV_EXT_IP_UPDOWN(j) ? "down" : "up"); + + printf(", %ssub-TLVs present", + ISIS_MASK_TLV_EXT_IP_SUBTLV(j) ? "" : "no "); + + if (ISIS_MASK_TLV_EXT_IP_SUBTLV(j)) { + if (!TTEST2(*tptr, 1)) + return (1); + printf(" (%u)",*tptr); /* no subTLV decoder supported - just print out subTLV length */ + i-=*tptr; + tptr+=*tptr++; + } + + i-=(5+byte_length); + tptr+=byte_length; + } break; - case TLV_AUTHENT: - printf("\n\t\t\t authentication data"); - default_print(pptr, len); + +#ifdef INET6 + + case TLV_IP6_REACH: + printf("IP6 reachability (%u)",len); + i=len; + tptr=pptr; + + while (i>0) { + if (!TTEST2(*tptr, 4)) + return (1); + metric = EXTRACT_32BITS(tptr); + tptr+=4; + + if (!TTEST2(*tptr, 2)) + return (1); + j=*(tptr++); + bit_length = (*(tptr)++); + byte_length = (bit_length + 7) / 8; + if (!TTEST2(*tptr, byte_length)) + return (1); + + memset(prefix6, 0, 16); + memcpy(prefix6,tptr,byte_length); + + printf("\n\t\t\tIPv6 prefix: %s/%u", + ip6addr_string(prefix6), + bit_length); + + printf("\n\t\t\t Metric: %u, %s, Distribution: %s, %ssub-TLVs present", + metric, + ISIS_MASK_TLV_IP6_IE(j) ? "External" : "Internal", + ISIS_MASK_TLV_IP6_UPDOWN(j) ? "down" : "up", + ISIS_MASK_TLV_IP6_SUBTLV(j) ? "" : "no "); + + if (ISIS_MASK_TLV_IP6_SUBTLV(j)) { + if (!TTEST2(*tptr, 1)) + return (1); + printf(" (%u)",*tptr); /* no subTLV decoder supported - just print out subTLV length */ + i-=*tptr; + tptr+=*tptr++; + } + + i-=(6+byte_length); + tptr+=byte_length; + } + break; +#endif + +#ifdef INET6 + case TLV_IP6ADDR: + printf("IPv6 Interface address(es) (%u)",len); + i=len; + tptr=pptr; + while (i>0) { + if (!TTEST2(*tptr, 16)) + goto trunctlv; + + printf("\n\t\t\tIPv6 interface address: %s", + ip6addr_string(tptr)); + + tptr += 16; + i -= 16; + } + break; +#endif + case TLV_AUTH: + if (!TTEST2(*pptr, 1)) + goto trunctlv; + printf("Authentication (%u)",len); + if (*pptr==SUBTLV_AUTH_SIMPLE) { + printf("\n\t\t\tsimple text password: "); + for(i=1;i<len;i++) { + if (!TTEST2(*(pptr+i), 1)) + goto trunctlv; + printf("%c",*(pptr+i)); + } + } + if (!TTEST2(*pptr, 1)) + goto trunctlv; + if (*pptr==SUBTLV_AUTH_MD5) { + printf("\n\t\t\tMD5 password: "); + for(i=1;i<len;i++) { + if (!TTEST2(*(pptr+i), 1)) + goto trunctlv; + printf("%02x",*(pptr+i)); + } + } + break; + case TLV_PTP_ADJ: - printf("\n\t\t\t PTP adjacency status %s", - isis_ptp_adjancey_values[*pptr].name); + printf("Point-to-point Adjacency State (%u)",len); + tlv_ptp_adj = (const struct isis_tlv_ptp_adj *)pptr; + i=len; + if(i>=1) { + if (!TTEST2(*pptr, 1)) + goto trunctlv; + printf("\n\t\t\tAdjacency State: %s", + tok2str(isis_ptp_adjancey_values, "#0x%x", *pptr)); + i--; + } + if(i>=4) { + if (!TTEST2(tlv_ptp_adj->ext_local_circuit_id, 4)) + goto trunctlv; + printf("\n\t\t\tExtended Local circuit ID: 0x%08x", + EXTRACT_32BITS(tlv_ptp_adj->ext_local_circuit_id)); + i-=4; + } + if(i>=6) { + if (!TTEST2(tlv_ptp_adj->neighbor_sysid, 6)) + goto trunctlv; + printf("\n\t\t\tNeighbor SystemID: "); + isis_print_sysid(tlv_ptp_adj->neighbor_sysid); + i-=6; + } + if(i>=4) { + if (!TTEST2(tlv_ptp_adj->neighbor_ext_local_circuit_id, 4)) + goto trunctlv; + printf("\n\t\t\tNeighbor Extended Local circuit ID: 0x%08x", + EXTRACT_32BITS(tlv_ptp_adj->neighbor_ext_local_circuit_id)); + } break; + case TLV_PROTOCOLS: - printf("\n\t\t\t Supports protocols %s", (len>1)? "are":"is"); - for(i=0;i<len;i++) - printf(" %02X", (u_char)*(pptr+i)); + printf("Protocols supported (%u)", len); + printf("\n\t\t\tNLPID(s): "); + for (i = 0; i < len; i++) { + if (!TTEST2(*(pptr+i), 1)) + goto trunctlv; + printf("%s (0x%02x)",tok2str(isis_nlpid_values, "Unknown", *(pptr+i)),*(pptr+i)); + if (i<len-1) + printf(", "); + } break; + + case TLV_TE_ROUTER_ID: + printf("Traffic Engineering Router ID (%u)",len); + if (!TTEST2(*pptr, 4)) + goto trunctlv; + printf("\n\t\t\tTraffic Engineering Router ID: %s", ipaddr_string(pptr)); + break; + case TLV_IPADDR: - printf("\n\t\t\t IP address: %s", ipaddr_string(pptr)); + printf("IPv4 Interface address(es) (%u)",len); + i=len; + tptr=pptr; + while (i>0) { + if (!TTEST2(*tptr, 4)) + goto trunctlv; + printf("\n\t\t\tIPv4 interface address: %s", ipaddr_string(tptr)); + tptr += 4; + i -= 4; + } + break; + + case TLV_HOSTNAME: + printf("Hostname (%u)", len); + printf("\n\t\t\tHostname: "); + for(i = 0; i < len; i++) { + if (!TTEST2(*(pptr+i), 1)) + goto trunctlv; + printf("%c",*(pptr+i)); + } + break; + + case TLV_LSP: + tlv_lsp = (const struct isis_tlv_lsp *)pptr; + printf("LSP entries (%u)", len); + i=0; + while(i<len) { + printf("\n\t\t\tlsp-id: "); + if (!isis_print_nodeid(tlv_lsp->lsp_id)) + return (1); + if (!TTEST((tlv_lsp->lsp_id)[SYSTEM_ID_LEN+1])) + goto trunctlv; + printf("-%02x",(tlv_lsp->lsp_id)[SYSTEM_ID_LEN+1]); + if (!TTEST2(tlv_lsp->sequence_number, 4)) + goto trunctlv; + printf("\n\t\t\t sequence number: 0x%08x",EXTRACT_32BITS(tlv_lsp->sequence_number)); + if (!TTEST2(tlv_lsp->remaining_lifetime, 2)) + goto trunctlv; + printf("\n\t\t\t Remaining lifetime: %5ds",EXTRACT_16BITS(tlv_lsp->remaining_lifetime)); + if (!TTEST2(tlv_lsp->checksum, 2)) + goto trunctlv; + printf("\n\t\t\t checksum: 0x%04x",EXTRACT_16BITS(tlv_lsp->checksum)); + i+=sizeof(struct isis_tlv_lsp); + tlv_lsp++; + } + break; + + case TLV_CHECKSUM: + if (!TTEST2(*pptr, 2)) + goto trunctlv; + printf("Checksum (%u)", len); + printf("\n\t\t\tchecksum: 0x%04x", + EXTRACT_16BITS(pptr)); + + if (osi_cksum(optr, length, off)) + printf(" (incorrect)"); + else + printf(" (correct)"); + break; + + case TLV_MT_SUPPORTED: + printf("Multi Topology (%u)",len); + i=len; + tptr=pptr; + while (i>1) { + /* length can only be a multiple of 2, otherwise there is + something broken -> so decode down until length is 1 */ + if (i!=1) { + if (!TTEST2(*tptr, 2)) + goto trunctlv; + printf("\n\t\t\t"); + switch(EXTRACT_16BITS(tptr)&0x0fff) { + + case 0: + printf("IPv4 unicast"); + break; + + case 1: + printf("In-Band Management"); + break; + + case 2: + printf("IPv6 unicast"); + break; + + case 3: + printf("Multicast"); + break; + + case 4095: + printf("Development, Experimental or Proprietary"); + break; + + default: + printf("Reserved for IETF Consensus"); + break; + } + printf(" Topology (0x%03x)%s%s", + EXTRACT_16BITS(tptr)&0xfff, + (EXTRACT_16BITS(tptr)&0x8000) ? "" : ", no sub-TLVs present", + (EXTRACT_16BITS(tptr)&0x4000) ? ", ATT bit set" : "" ); + } else { + printf("\n\t\t\tmalformed MT-ID"); + break; + } + i-=2; + tptr+=2; + } + break; + + case TLV_RESTART_SIGNALING: + tptr=pptr; + printf("Restart Signaling (%u)",len); + if (!TTEST2(*tptr, 3)) + goto trunctlv; + + printf("\n\t\t\tRestart Request bit %s, Restart Acknowledgement bit %s\n\t\t\tRemaining holding time: %us", + ISIS_MASK_RESTART_RR(*tptr) ? "set" : "clear", + ISIS_MASK_RESTART_RA(*tptr++) ? "set" : "clear", + EXTRACT_16BITS(tptr)); + break; + default: - printf("\n\t\t\t unknown TLV, type %d, length %d", type, len); + printf("unknown TLV, type %d, length %d\n\t\t\t", type, len); + tptr=pptr; + + for(i=0;i<len;i++) { + if (!TTEST2(*(tptr+i), 1)) + goto trunctlv; + printf("%02x",*(tptr+i)); /* formatted hex output of unknown TLV data */ + if (i%2) + printf(" "); + if (i/16!=(i+1)/16) { + if (i<(len-1)) + printf("\n\t\t\t"); + } + } break; } @@ -647,6 +1546,14 @@ isis_print (const u_char *p, u_int length) if (packet_len != 0) { printf("\n\t\t\t %d straggler bytes", packet_len); } + return (1); + +trunc: + fputs("[|isis]", stdout); + return (1); + +trunctlv: + printf("\n\t\t\t packet exceeded snapshot"); return(1); } @@ -655,7 +1562,7 @@ isis_print (const u_char *p, u_int length) */ static int -osi_cksum(register const u_char *p, register int len, u_char *off) +osi_cksum(register const u_char *p, register u_int len, u_char *off) { int32_t c0 = 0, c1 = 0; @@ -671,3 +1578,4 @@ osi_cksum(register const u_char *p, register int len, u_char *off) } return (c0 | c1); } + diff --git a/contrib/tcpdump/print-l2tp.c b/contrib/tcpdump/print-l2tp.c index d054308..973c942 100644 --- a/contrib/tcpdump/print-l2tp.c +++ b/contrib/tcpdump/print-l2tp.c @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-l2tp.c,v 1.8 2000/08/18 07:44:46 itojun Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-l2tp.c,v 1.10 2001/11/10 21:37:58 guy Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -49,111 +49,145 @@ static char tstr[] = " [|l2tp]"; #define FALSE 0 #endif -static char *l2tp_message_type_string[] = { - "RESERVED_0", /* 0 Reserved */ - "SCCRQ", /* 1 Start-Control-Connection-Request */ - "SCCRP", /* 2 Start-Control-Connection-Reply */ - "SCCCN", /* 3 Start-Control-Connection-Connected */ - "StopCCN", /* 4 Stop-Control-Connection-Notification */ - "RESERVED_5", /* 5 Reserved */ - "HELLO", /* 6 Hello */ - "OCRQ", /* 7 Outgoing-Call-Request */ - "OCRP", /* 8 Outgoing-Call-Reply */ - "OCCN", /* 9 Outgoing-Call-Connected */ - "ICRQ", /* 10 Incoming-Call-Request */ - "ICRP", /* 11 Incoming-Call-Reply */ - "ICCN", /* 12 Incoming-Call-Connected */ - "RESERVED_13", /* 13 Reserved */ - "CDN", /* 14 Call-Disconnect-Notify */ - "WEN", /* 15 WAN-Error-Notify */ - "SLI" /* 16 Set-Link-Info */ -#define L2TP_MAX_MSGTYPE_INDEX 17 +#define L2TP_MSGTYPE_SCCRQ 1 /* Start-Control-Connection-Request */ +#define L2TP_MSGTYPE_SCCRP 2 /* Start-Control-Connection-Reply */ +#define L2TP_MSGTYPE_SCCCN 3 /* Start-Control-Connection-Connected */ +#define L2TP_MSGTYPE_STOPCCN 4 /* Stop-Control-Connection-Notification */ +#define L2TP_MSGTYPE_HELLO 6 /* Hello */ +#define L2TP_MSGTYPE_OCRQ 7 /* Outgoing-Call-Request */ +#define L2TP_MSGTYPE_OCRP 8 /* Outgoing-Call-Reply */ +#define L2TP_MSGTYPE_OCCN 9 /* Outgoing-Call-Connected */ +#define L2TP_MSGTYPE_ICRQ 10 /* Incoming-Call-Request */ +#define L2TP_MSGTYPE_ICRP 11 /* Incoming-Call-Reply */ +#define L2TP_MSGTYPE_ICCN 12 /* Incoming-Call-Connected */ +#define L2TP_MSGTYPE_CDN 14 /* Call-Disconnect-Notify */ +#define L2TP_MSGTYPE_WEN 15 /* WAN-Error-Notify */ +#define L2TP_MSGTYPE_SLI 16 /* Set-Link-Info */ + +static struct tok l2tp_msgtype2str[] = { + { L2TP_MSGTYPE_SCCRQ, "SCCRQ" }, + { L2TP_MSGTYPE_SCCRP, "SCCRP" }, + { L2TP_MSGTYPE_SCCCN, "SCCCN" }, + { L2TP_MSGTYPE_STOPCCN, "StopCCN" }, + { L2TP_MSGTYPE_HELLO, "HELLO" }, + { L2TP_MSGTYPE_OCRQ, "OCRQ" }, + { L2TP_MSGTYPE_OCRP, "OCRP" }, + { L2TP_MSGTYPE_OCCN, "OCCN" }, + { L2TP_MSGTYPE_ICRQ, "ICRQ" }, + { L2TP_MSGTYPE_ICRP, "ICRP" }, + { L2TP_MSGTYPE_ICCN, "ICCN" }, + { L2TP_MSGTYPE_CDN, "CDN" }, + { L2TP_MSGTYPE_WEN, "WEN" }, + { L2TP_MSGTYPE_SLI, "SLI" }, + { 0, NULL } }; -static void l2tp_msgtype_print(const u_char *dat, u_int length); -static void l2tp_result_code_print(const u_char *dat, u_int length); -static void l2tp_proto_ver_print(const u_char *dat, u_int length); -static void l2tp_framing_cap_print(const u_char *dat, u_int length); -static void l2tp_bearer_cap_print(const u_char *dat, u_int length); -static void l2tp_tie_breaker_print(const u_char *dat, u_int length); -static void l2tp_firm_ver_print(const u_char *dat, u_int length); -static void l2tp_host_name_print(const u_char *dat, u_int length); -static void l2tp_vendor_name_print(const u_char *dat, u_int length); -static void l2tp_assnd_tun_id_print(const u_char *dat, u_int length); -static void l2tp_recv_win_size_print(const u_char *dat, u_int length); -static void l2tp_challenge_print(const u_char *dat, u_int length); -static void l2tp_q931_cc_print(const u_char *dat, u_int length); -static void l2tp_challenge_resp_print(const u_char *dat, u_int length); -static void l2tp_assnd_sess_id_print(const u_char *dat, u_int length); -static void l2tp_call_ser_num_print(const u_char *dat, u_int length); -static void l2tp_minimum_bps_print(const u_char *dat, u_int length); -static void l2tp_maximum_bps_print(const u_char *dat, u_int length); -static void l2tp_bearer_type_print(const u_char *dat, u_int length); -static void l2tp_framing_type_print(const u_char *dat, u_int length); -static void l2tp_packet_proc_delay_print(const u_char *dat, u_int length); -static void l2tp_called_number_print(const u_char *dat, u_int length); -static void l2tp_calling_number_print(const u_char *dat, u_int length); -static void l2tp_sub_address_print(const u_char *dat, u_int length); -static void l2tp_tx_conn_speed_print(const u_char *dat, u_int length); -static void l2tp_phy_channel_id_print(const u_char *dat, u_int length); -static void l2tp_ini_recv_lcp_print(const u_char *dat, u_int length); -static void l2tp_last_sent_lcp_print(const u_char *dat, u_int length); -static void l2tp_last_recv_lcp_print(const u_char *dat, u_int length); -static void l2tp_proxy_auth_type_print(const u_char *dat, u_int length); -static void l2tp_proxy_auth_name_print(const u_char *dat, u_int length); -static void l2tp_proxy_auth_chal_print(const u_char *dat, u_int length); -static void l2tp_proxy_auth_id_print(const u_char *dat, u_int length); -static void l2tp_proxy_auth_resp_print(const u_char *dat, u_int length); -static void l2tp_call_errors_print(const u_char *dat, u_int length); -static void l2tp_accm_print(const u_char *dat, u_int length); -static void l2tp_random_vector_print(const u_char *dat, u_int length); -static void l2tp_private_grp_id_print(const u_char *dat, u_int length); -static void l2tp_rx_conn_speed_print(const u_char *dat, u_int length); -static void l2tp_seq_required_print(const u_char *dat, u_int length); -static void l2tp_avp_print(const u_char *dat, u_int length); - -static struct l2tp_avp_vec l2tp_avp[] = { - {"MSGTYPE", l2tp_msgtype_print}, /* 0 Message Type */ - {"RESULT_CODE", l2tp_result_code_print}, /* 1 Result Code */ - {"PROTO_VER", l2tp_proto_ver_print}, /* 2 Protocol Version */ - {"FRAMING_CAP", l2tp_framing_cap_print}, /* 3 Framing Capabilities */ - {"BEARER_CAP", l2tp_bearer_cap_print}, /* 4 Bearer Capabilities */ - {"TIE_BREAKER", l2tp_tie_breaker_print}, /* 5 Tie Breaker */ - {"FIRM_VER", l2tp_firm_ver_print}, /* 6 Firmware Revision */ - {"HOST_NAME", l2tp_host_name_print}, /* 7 Host Name */ - {"VENDOR_NAME", l2tp_vendor_name_print}, /* 8 Vendor Name */ - {"ASSND_TUN_ID", l2tp_assnd_tun_id_print}, /* 9 Assigned Tunnel ID */ - {"RECV_WIN_SIZE", l2tp_recv_win_size_print}, /* 10 Receive Window Size */ - {"CHALLENGE", l2tp_challenge_print}, /* 11 Challenge */ - {"Q931_CC", l2tp_q931_cc_print}, /* 12 Q.931 Cause Code */ - {"CHALLENGE_RESP", l2tp_challenge_resp_print},/* 13 Challenge Response */ - {"ASSND_SESS_ID", l2tp_assnd_sess_id_print}, /* 14 Assigned Session ID */ - {"CALL_SER_NUM", l2tp_call_ser_num_print}, /* 15 Call Serial Number */ - {"MINIMUM_BPS", l2tp_minimum_bps_print},/* 16 Minimum BPS */ - {"MAXIMUM_BPS", l2tp_maximum_bps_print}, /* 17 Maximum BPS */ - {"BEARER_TYPE", l2tp_bearer_type_print},/* 18 Bearer Type */ - {"FRAMING_TYPE", l2tp_framing_type_print}, /* 19 Framing Type */ - {"PACKET_PROC_DELAY", l2tp_packet_proc_delay_print}, /* 20 Packet Processing Delay (OBSOLETE) */ - {"CALLED_NUMBER", l2tp_called_number_print}, /* 21 Called Number */ - {"CALLING_NUMBER", l2tp_calling_number_print},/* 22 Calling Number */ - {"SUB_ADDRESS", l2tp_sub_address_print},/* 23 Sub-Address */ - {"TX_CONN_SPEED", l2tp_tx_conn_speed_print}, /* 24 (Tx) Connect Speed */ - {"PHY_CHANNEL_ID", l2tp_phy_channel_id_print},/* 25 Physical Channel ID */ - {"INI_RECV_LCP", l2tp_ini_recv_lcp_print}, /* 26 Initial Received LCP CONFREQ */ - {"LAST_SENT_LCP", l2tp_last_sent_lcp_print}, /* 27 Last Sent LCP CONFREQ */ - {"LAST_RECV_LCP", l2tp_last_recv_lcp_print}, /* 28 Last Received LCP CONFREQ */ - {"PROXY_AUTH_TYPE", l2tp_proxy_auth_type_print},/* 29 Proxy Authen Type */ - {"PROXY_AUTH_NAME", l2tp_proxy_auth_name_print},/* 30 Proxy Authen Name */ - {"PROXY_AUTH_CHAL", l2tp_proxy_auth_chal_print},/* 31 Proxy Authen Challenge */ - {"PROXY_AUTH_ID", l2tp_proxy_auth_id_print}, /* 32 Proxy Authen ID */ - {"PROXY_AUTH_RESP", l2tp_proxy_auth_resp_print},/* 33 Proxy Authen Response */ - {"CALL_ERRORS", l2tp_call_errors_print}, /* 34 Call Errors */ - {"ACCM", l2tp_accm_print}, /* 35 ACCM */ - {"RANDOM_VECTOR", l2tp_random_vector_print}, /* 36 Random Vector */ - {"PRIVATE_GRP_ID", l2tp_private_grp_id_print},/* 37 Private Group ID */ - {"RX_CONN_SPEED", l2tp_rx_conn_speed_print}, /* 38 (Rx) Connect Speed */ - {"SEQ_REQUIRED", l2tp_seq_required_print}, /* 39 Sequencing Required */ -#define L2TP_MAX_AVP_INDEX 40 +#define L2TP_AVP_MSGTYPE 0 /* Message Type */ +#define L2TP_AVP_RESULT_CODE 1 /* Result Code */ +#define L2TP_AVP_PROTO_VER 2 /* Protocol Version */ +#define L2TP_AVP_FRAMING_CAP 3 /* Framing Capabilities */ +#define L2TP_AVP_BEARER_CAP 4 /* Bearer Capabilities */ +#define L2TP_AVP_TIE_BREAKER 5 /* Tie Breaker */ +#define L2TP_AVP_FIRM_VER 6 /* Firmware Revision */ +#define L2TP_AVP_HOST_NAME 7 /* Host Name */ +#define L2TP_AVP_VENDOR_NAME 8 /* Vendor Name */ +#define L2TP_AVP_ASSND_TUN_ID 9 /* Assigned Tunnel ID */ +#define L2TP_AVP_RECV_WIN_SIZE 10 /* Receive Window Size */ +#define L2TP_AVP_CHALLENGE 11 /* Challenge */ +#define L2TP_AVP_Q931_CC 12 /* Q.931 Cause Code */ +#define L2TP_AVP_CHALLENGE_RESP 13 /* Challenge Response */ +#define L2TP_AVP_ASSND_SESS_ID 14 /* Assigned Session ID */ +#define L2TP_AVP_CALL_SER_NUM 15 /* Call Serial Number */ +#define L2TP_AVP_MINIMUM_BPS 16 /* Minimum BPS */ +#define L2TP_AVP_MAXIMUM_BPS 17 /* Maximum BPS */ +#define L2TP_AVP_BEARER_TYPE 18 /* Bearer Type */ +#define L2TP_AVP_FRAMING_TYPE 19 /* Framing Type */ +#define L2TP_AVP_PACKET_PROC_DELAY 20 /* Packet Processing Delay (OBSOLETE) */ +#define L2TP_AVP_CALLED_NUMBER 21 /* Called Number */ +#define L2TP_AVP_CALLING_NUMBER 22 /* Calling Number */ +#define L2TP_AVP_SUB_ADDRESS 23 /* Sub-Address */ +#define L2TP_AVP_TX_CONN_SPEED 24 /* (Tx) Connect Speed */ +#define L2TP_AVP_PHY_CHANNEL_ID 25 /* Physical Channel ID */ +#define L2TP_AVP_INI_RECV_LCP 26 /* Initial Received LCP CONFREQ */ +#define L2TP_AVP_LAST_SENT_LCP 27 /* Last Sent LCP CONFREQ */ +#define L2TP_AVP_LAST_RECV_LCP 28 /* Last Received LCP CONFREQ */ +#define L2TP_AVP_PROXY_AUTH_TYPE 29 /* Proxy Authen Type */ +#define L2TP_AVP_PROXY_AUTH_NAME 30 /* Proxy Authen Name */ +#define L2TP_AVP_PROXY_AUTH_CHAL 31 /* Proxy Authen Challenge */ +#define L2TP_AVP_PROXY_AUTH_ID 32 /* Proxy Authen ID */ +#define L2TP_AVP_PROXY_AUTH_RESP 33 /* Proxy Authen Response */ +#define L2TP_AVP_CALL_ERRORS 34 /* Call Errors */ +#define L2TP_AVP_ACCM 35 /* ACCM */ +#define L2TP_AVP_RANDOM_VECTOR 36 /* Random Vector */ +#define L2TP_AVP_PRIVATE_GRP_ID 37 /* Private Group ID */ +#define L2TP_AVP_RX_CONN_SPEED 38 /* (Rx) Connect Speed */ +#define L2TP_AVP_SEQ_REQUIRED 39 /* Sequencing Required */ +#define L2TP_AVP_PPP_DISCON_CC 46 /* PPP Disconnect Cause Code */ + +static struct tok l2tp_avp2str[] = { + { L2TP_AVP_MSGTYPE, "MSGTYPE" }, + { L2TP_AVP_RESULT_CODE, "RESULT_CODE" }, + { L2TP_AVP_PROTO_VER, "PROTO_VER" }, + { L2TP_AVP_FRAMING_CAP, "FRAMING_CAP" }, + { L2TP_AVP_BEARER_CAP, "BEARER_CAP" }, + { L2TP_AVP_TIE_BREAKER, "TIE_BREAKER" }, + { L2TP_AVP_FIRM_VER, "FIRM_VER" }, + { L2TP_AVP_HOST_NAME, "HOST_NAME" }, + { L2TP_AVP_VENDOR_NAME, "VENDOR_NAME" }, + { L2TP_AVP_ASSND_TUN_ID, "ASSND_TUN_ID" }, + { L2TP_AVP_RECV_WIN_SIZE, "RECV_WIN_SIZE" }, + { L2TP_AVP_CHALLENGE, "CHALLENGE" }, + { L2TP_AVP_Q931_CC, "Q931_CC", }, + { L2TP_AVP_CHALLENGE_RESP, "CHALLENGE_RESP" }, + { L2TP_AVP_ASSND_SESS_ID, "ASSND_SESS_ID" }, + { L2TP_AVP_CALL_SER_NUM, "CALL_SER_NUM" }, + { L2TP_AVP_MINIMUM_BPS, "MINIMUM_BPS" }, + { L2TP_AVP_MAXIMUM_BPS, "MAXIMUM_BPS" }, + { L2TP_AVP_BEARER_TYPE, "BEARER_TYPE" }, + { L2TP_AVP_FRAMING_TYPE, "FRAMING_TYPE" }, + { L2TP_AVP_PACKET_PROC_DELAY, "PACKET_PROC_DELAY" }, + { L2TP_AVP_CALLED_NUMBER, "CALLED_NUMBER" }, + { L2TP_AVP_CALLING_NUMBER, "CALLING_NUMBER" }, + { L2TP_AVP_SUB_ADDRESS, "SUB_ADDRESS" }, + { L2TP_AVP_TX_CONN_SPEED, "TX_CONN_SPEED" }, + { L2TP_AVP_PHY_CHANNEL_ID, "PHY_CHANNEL_ID" }, + { L2TP_AVP_INI_RECV_LCP, "INI_RECV_LCP" }, + { L2TP_AVP_LAST_SENT_LCP, "LAST_SENT_LCP" }, + { L2TP_AVP_LAST_RECV_LCP, "LAST_RECV_LCP" }, + { L2TP_AVP_PROXY_AUTH_TYPE, "PROXY_AUTH_TYPE" }, + { L2TP_AVP_PROXY_AUTH_NAME, "PROXY_AUTH_NAME" }, + { L2TP_AVP_PROXY_AUTH_CHAL, "PROXY_AUTH_CHAL" }, + { L2TP_AVP_PROXY_AUTH_ID, "PROXY_AUTH_ID" }, + { L2TP_AVP_PROXY_AUTH_RESP, "PROXY_AUTH_RESP" }, + { L2TP_AVP_CALL_ERRORS, "CALL_ERRORS" }, + { L2TP_AVP_ACCM, "ACCM" }, + { L2TP_AVP_RANDOM_VECTOR, "RANDOM_VECTOR" }, + { L2TP_AVP_PRIVATE_GRP_ID, "PRIVATE_GRP_ID" }, + { L2TP_AVP_RX_CONN_SPEED, "RX_CONN_SPEED" }, + { L2TP_AVP_SEQ_REQUIRED, "SEQ_REQUIRED" }, + { L2TP_AVP_PPP_DISCON_CC, "PPP_DISCON_CC" }, + { 0, NULL } +}; + +static struct tok l2tp_authentype2str[] = { + { L2TP_AUTHEN_TYPE_RESERVED, "Reserved" }, + { L2TP_AUTHEN_TYPE_TEXTUAL, "Textual" }, + { L2TP_AUTHEN_TYPE_CHAP, "CHAP" }, + { L2TP_AUTHEN_TYPE_PAP, "PAP" }, + { L2TP_AUTHEN_TYPE_NO_AUTH, "No Auth" }, + { L2TP_AUTHEN_TYPE_MSCHAPv1, "MS-CHAPv1" }, + { 0, NULL } +}; + +#define L2TP_PPP_DISCON_CC_DIRECTION_GLOBAL 0 +#define L2TP_PPP_DISCON_CC_DIRECTION_AT_PEER 1 +#define L2TP_PPP_DISCON_CC_DIRECTION_AT_LOCAL 2 + +static struct tok l2tp_cc_direction2str[] = { + { L2TP_PPP_DISCON_CC_DIRECTION_GLOBAL, "global error" }, + { L2TP_PPP_DISCON_CC_DIRECTION_AT_PEER, "at peer" }, + { L2TP_PPP_DISCON_CC_DIRECTION_AT_LOCAL,"at local" }, + { 0, NULL } }; #if 0 @@ -227,57 +261,53 @@ print_octets(const u_char *dat, u_int length) } static void -print_short(const u_short *dat) +print_16bits_val(const u_int16_t *dat) { printf("%u", ntohs(*dat)); } static void -print_int(const u_int *dat) +print_32bits_val(const u_int32_t *dat) { printf("%lu", (u_long)ntohl(*dat)); } -/**********************************/ -/* AVP-specific print out routines*/ -/**********************************/ +/***********************************/ +/* AVP-specific print out routines */ +/***********************************/ static void -l2tp_msgtype_print(const u_char *dat, u_int length) +l2tp_msgtype_print(const u_char *dat) { - u_short *ptr = (u_short *)dat; + u_int16_t *ptr = (u_int16_t*)dat; - if (ntohs(*ptr) < L2TP_MAX_MSGTYPE_INDEX) { - printf("%s", l2tp_message_type_string[ntohs(*ptr)]); - } + printf("%s", tok2str(l2tp_msgtype2str, "MSGTYPE-#%u", ntohs(*ptr))); } static void l2tp_result_code_print(const u_char *dat, u_int length) { - /* we just print out the result and error code number */ - u_short *ptr = (u_short *)dat; + u_int16_t *ptr = (u_int16_t *)dat; - if (length == 2) { /* result code */ - printf("%u", ntohs(*ptr)); - } else if (length == 4) { /* result & error code */ - printf("%u/%u", ntohs(*ptr), ntohs(*(ptr+1))); - } else if (length > 4) { /* result & error code & msg */ - printf("%u/%u ", ntohs(*ptr), ntohs(*(ptr+1))); - print_string((u_char *)(ptr+2), length - 4); + printf("%u", ntohs(*ptr++)); /* Result Code */ + if (length > 2) { /* Error Code (opt) */ + printf("/%u", ntohs(*ptr++)); + } + if (length > 4) { /* Error Message (opt) */ + printf(" "); + print_string((u_char *)ptr, length - 4); } } static void -l2tp_proto_ver_print(const u_char *dat, u_int length) +l2tp_proto_ver_print(const u_int16_t *dat) { - printf("%d.%d", *dat, *(dat+1)); + printf("%u.%u", (ntohs(*dat) >> 8), (ntohs(*dat) & 0xff)); } - static void -l2tp_framing_cap_print(const u_char *dat, u_int length) +l2tp_framing_cap_print(const u_char *dat) { - u_int *ptr = (u_int *)dat; + u_int32_t *ptr = (u_int32_t *)dat; if (ntohl(*ptr) & L2TP_FRAMING_CAP_ASYNC_MASK) { printf("A"); @@ -288,9 +318,9 @@ l2tp_framing_cap_print(const u_char *dat, u_int length) } static void -l2tp_bearer_cap_print(const u_char *dat, u_int length) +l2tp_bearer_cap_print(const u_char *dat) { - u_int *ptr = (u_int *)dat; + u_int32_t *ptr = (u_int32_t *)dat; if (ntohl(*ptr) & L2TP_BEARER_CAP_ANALOG_MASK) { printf("A"); @@ -301,51 +331,9 @@ l2tp_bearer_cap_print(const u_char *dat, u_int length) } static void -l2tp_tie_breaker_print(const u_char *dat, u_int length) -{ - print_octets(dat, 8); /* Tie Break Value is 64bits long */ -} - -static void -l2tp_firm_ver_print(const u_char *dat, u_int length) -{ - print_short((u_short *)dat); -} - -static void -l2tp_host_name_print(const u_char *dat, u_int length) -{ - print_string(dat, length); -} - -static void -l2tp_vendor_name_print(const u_char *dat, u_int length) -{ - print_string(dat, length); -} - -static void -l2tp_assnd_tun_id_print(const u_char *dat, u_int length) -{ - print_short((u_short *)dat); -} - -static void -l2tp_recv_win_size_print(const u_char *dat, u_int length) -{ - print_short((u_short *)dat); -} - -static void -l2tp_challenge_print(const u_char *dat, u_int length) -{ - print_octets(dat, length); -} - -static void l2tp_q931_cc_print(const u_char *dat, u_int length) { - print_short((u_short *)dat); + print_16bits_val((u_int16_t *)dat); printf(", %02x", dat[2]); if (length > 3) { printf(" "); @@ -354,39 +342,9 @@ l2tp_q931_cc_print(const u_char *dat, u_int length) } static void -l2tp_challenge_resp_print(const u_char *dat, u_int length) -{ - print_octets(dat, 16); /* XXX length should be 16? */ -} - -static void -l2tp_assnd_sess_id_print(const u_char *dat, u_int length) -{ - print_short((u_short *)dat); -} - -static void -l2tp_call_ser_num_print(const u_char *dat, u_int length) -{ - print_int((u_int *)dat); -} - -static void -l2tp_minimum_bps_print(const u_char *dat, u_int length) -{ - print_int((u_int *)dat); -} - -static void -l2tp_maximum_bps_print(const u_char *dat, u_int length) -{ - print_int((u_int *)dat); -} - -static void -l2tp_bearer_type_print(const u_char *dat, u_int length) +l2tp_bearer_type_print(const u_char *dat) { - u_int *ptr = (u_int *)dat; + u_int32_t *ptr = (u_int32_t *)dat; if (ntohl(*ptr) & L2TP_BEARER_TYPE_ANALOG_MASK) { printf("A"); @@ -397,9 +355,9 @@ l2tp_bearer_type_print(const u_char *dat, u_int length) } static void -l2tp_framing_type_print(const u_char *dat, u_int length) +l2tp_framing_type_print(const u_char *dat) { - u_int *ptr = (u_int *)dat; + u_int32_t *ptr = (u_int32_t *)dat; if (ntohl(*ptr) & L2TP_FRAMING_TYPE_ASYNC_MASK) { printf("A"); @@ -410,241 +368,251 @@ l2tp_framing_type_print(const u_char *dat, u_int length) } static void -l2tp_packet_proc_delay_print(const u_char *dat, u_int length) +l2tp_packet_proc_delay_print(void) { printf("obsolete"); } static void -l2tp_called_number_print(const u_char *dat, u_int length) +l2tp_proxy_auth_type_print(const u_char *dat) { - print_string(dat, length); -} + u_int16_t *ptr = (u_int16_t *)dat; -static void -l2tp_calling_number_print(const u_char *dat, u_int length) -{ - print_string(dat, length); + printf("%s", tok2str(l2tp_authentype2str, + "AuthType-#%u", ntohs(*ptr))); } static void -l2tp_sub_address_print(const u_char *dat, u_int length) +l2tp_proxy_auth_id_print(const u_char *dat) { - print_string(dat, length); -} + u_int16_t *ptr = (u_int16_t *)dat; -static void -l2tp_tx_conn_speed_print(const u_char *dat, u_int length) -{ - print_int((u_int *)dat); + printf("%u", ntohs(*ptr) & L2TP_PROXY_AUTH_ID_MASK); } static void -l2tp_phy_channel_id_print(const u_char *dat, u_int length) +l2tp_call_errors_print(const u_char *dat) { - print_int((u_int *)dat); -} + u_int16_t *ptr = (u_int16_t *)dat; + u_int16_t val_h, val_l; + + ptr++; /* skip "Reserved" */ -static void -l2tp_ini_recv_lcp_print(const u_char *dat, u_int length) -{ - print_octets(dat, length); -} + val_h = ntohs(*ptr++); + val_l = ntohs(*ptr++); + printf("CRCErr=%u ", (val_h<<16) + val_l); -static void -l2tp_last_sent_lcp_print(const u_char *dat, u_int length) -{ - print_octets(dat, length); -} + val_h = ntohs(*ptr++); + val_l = ntohs(*ptr++); + printf("FrameErr=%u ", (val_h<<16) + val_l); -static void -l2tp_last_recv_lcp_print(const u_char *dat, u_int length) -{ - print_octets(dat, length); -} + val_h = ntohs(*ptr++); + val_l = ntohs(*ptr++); + printf("HardOver=%u ", (val_h<<16) + val_l); -static void -l2tp_proxy_auth_type_print(const u_char *dat, u_int length) -{ - u_short *ptr = (u_short *)dat; - - switch (ntohs(*ptr)) { - case L2TP_AUTHEN_TYPE_RESERVED: - printf("Reserved"); - break; - case L2TP_AUTHEN_TYPE_TEXTUAL: - printf("Textual"); - break; - case L2TP_AUTHEN_TYPE_CHAP: - printf("CHAP"); - break; - case L2TP_AUTHEN_TYPE_PAP: - printf("PAP"); - break; - case L2TP_AUTHEN_TYPE_NO_AUTH: - printf("No Auth"); - break; - case L2TP_AUTHEN_TYPE_MSCHAP: - printf("MS-CHAP"); - break; - default: - printf("unknown"); - } -} + val_h = ntohs(*ptr++); + val_l = ntohs(*ptr++); + printf("BufOver=%u ", (val_h<<16) + val_l); -static void -l2tp_proxy_auth_name_print(const u_char *dat, u_int length) -{ - print_octets(dat, length); -} + val_h = ntohs(*ptr++); + val_l = ntohs(*ptr++); + printf("Timeout=%u ", (val_h<<16) + val_l); -static void -l2tp_proxy_auth_chal_print(const u_char *dat, u_int length) -{ - print_octets(dat, length); + val_h = ntohs(*ptr++); + val_l = ntohs(*ptr++); + printf("AlignErr=%u ", (val_h<<16) + val_l); } static void -l2tp_proxy_auth_id_print(const u_char *dat, u_int length) +l2tp_accm_print(const u_char *dat) { - u_short *ptr = (u_short *)dat; + u_int16_t *ptr = (u_int16_t *)dat; + u_int16_t val_h, val_l; - printf("%u", ntohs(*ptr) & L2TP_PROXY_AUTH_ID_MASK); -} - -static void -l2tp_proxy_auth_resp_print(const u_char *dat, u_int length) -{ - print_octets(dat, length); -} + ptr++; /* skip "Reserved" */ -static void -l2tp_call_errors_print(const u_char *dat, u_int length) -{ - struct l2tp_call_errors *ptr = (struct l2tp_call_errors *)dat; - - printf("CRCErr=%d FrameErr=%d HardOver=%d BufOver=%d ", - ptr->crc_errs, - ptr->framing_errs, - ptr->hardware_overruns, - ptr->buffer_overruns); - printf("Timeout=%d AlingErr=%d", - ptr->timeout_errs, - ptr->alignment_errs); + val_h = ntohs(*ptr++); + val_l = ntohs(*ptr++); + printf("send=%08x ", (val_h<<16) + val_l); + + val_h = ntohs(*ptr++); + val_l = ntohs(*ptr++); + printf("recv=%08x ", (val_h<<16) + val_l); } static void -l2tp_accm_print(const u_char *dat, u_int length) +l2tp_ppp_discon_cc_print(const u_char *dat, u_int length) { - struct l2tp_accm *ptr = (struct l2tp_accm *)dat; + u_int16_t *ptr = (u_int16_t *)dat; + + printf("%04x, ", ntohs(*ptr++)); /* Disconnect Code */ + printf("%04x ", ntohs(*ptr++)); /* Control Protocol Number */ + printf("%s", tok2str(l2tp_cc_direction2str, + "Direction-#%u", *((u_char *)ptr++))); - printf("send=%x recv=%x", ptr->send_accm, ptr->recv_accm); + if (length > 5) { + printf(" "); + print_string((const u_char *)ptr, length-5); + } } static void -l2tp_random_vector_print(const u_char *dat, u_int length) +l2tp_avp_print(const u_char *dat, int length) { - print_octets(dat, length); -} + u_int len; + const u_int16_t *ptr = (u_int16_t *)dat; + u_int16_t attr_type; + int hidden = FALSE; -static void -l2tp_private_grp_id_print(const u_char *dat, u_int length) -{ - print_string(dat, length); - /* XXX print_octets is more appropriate?? */ -} + if (length <= 0) { + return; + } -static void -l2tp_rx_conn_speed_print(const u_char *dat, u_int length) -{ - print_int((u_int *)dat); -} + printf(" "); -static void -l2tp_seq_required_print(const u_char *dat, u_int length) -{ - return; -} + TCHECK(*ptr); /* Flags & Length */ + len = ntohs(*ptr) & L2TP_AVP_HDR_LEN_MASK; -static void -l2tp_avp_print(const u_char *dat, u_int length) -{ - u_int len; - const u_short *ptr = (u_short *)dat; - int hidden = FALSE; + /* If it is not long enough to decode the entire AVP, we'll + abandon. */ + TCHECK2(*ptr, len); + /* After this point, no need to worry about truncation */ - printf(" "); - if (length > 0 && (snapend - dat) >= 2) { - /* there must be at least two octets for the length - to be decoded */ - if ((len = (ntohs(*ptr) & L2TP_AVP_HDR_LEN_MASK)) <= - (snapend - dat)) { - if (ntohs(*ptr) & L2TP_AVP_HDR_FLAG_MANDATORY) { - printf("*"); - } - if (ntohs(*ptr) & L2TP_AVP_HDR_FLAG_HIDDEN) { - hidden = TRUE; - printf("?"); - } - } else { - printf("|..."); - return; - } - ptr++; + if (ntohs(*ptr) & L2TP_AVP_HDR_FLAG_MANDATORY) { + printf("*"); + } + if (ntohs(*ptr) & L2TP_AVP_HDR_FLAG_HIDDEN) { + hidden = TRUE; + printf("?"); + } + ptr++; - if (ntohs(*ptr)) { - /* Vendor Specific Attribute */ - printf("VENDOR%04x:", ntohs(*ptr)); - ptr++; - printf("ATTR%04x", ntohs(*ptr)); - printf("("); - print_octets((u_char *)ptr+2, len-6); - printf(")"); + if (ntohs(*ptr)) { + /* Vendor Specific Attribute */ + printf("VENDOR%04x:", ntohs(*ptr++)); + printf("ATTR%04x", ntohs(*ptr++)); + printf("("); + print_octets((u_char *)ptr, len-6); + printf(")"); + } else { + /* IETF-defined Attributes */ + ptr++; + attr_type = ntohs(*ptr++); + printf("%s", tok2str(l2tp_avp2str, "AVP-#%u", attr_type)); + printf("("); + if (hidden) { + printf("???"); } else { - /* IETF-defined Attribute */ - ptr++; - if (ntohs(*ptr) < L2TP_MAX_AVP_INDEX) { - printf("%s", l2tp_avp[ntohs(*ptr)].name); - printf("("); - if (!hidden) { - (l2tp_avp[ntohs(*ptr)].print) - ((u_char *)ptr+2, len-6); - } else { - printf("???"); - } - printf(")"); - } else { - printf(" invalid AVP %u", ntohs(*ptr)); + switch (attr_type) { + case L2TP_AVP_MSGTYPE: + l2tp_msgtype_print((u_char *)ptr); + break; + case L2TP_AVP_RESULT_CODE: + l2tp_result_code_print((u_char *)ptr, len-6); + break; + case L2TP_AVP_PROTO_VER: + l2tp_proto_ver_print(ptr); + break; + case L2TP_AVP_FRAMING_CAP: + l2tp_framing_cap_print((u_char *)ptr); + break; + case L2TP_AVP_BEARER_CAP: + l2tp_bearer_cap_print((u_char *)ptr); + break; + case L2TP_AVP_TIE_BREAKER: + print_octets((u_char *)ptr, 8); + break; + case L2TP_AVP_FIRM_VER: + case L2TP_AVP_ASSND_TUN_ID: + case L2TP_AVP_RECV_WIN_SIZE: + case L2TP_AVP_ASSND_SESS_ID: + print_16bits_val(ptr); + break; + case L2TP_AVP_HOST_NAME: + case L2TP_AVP_VENDOR_NAME: + case L2TP_AVP_CALLING_NUMBER: + case L2TP_AVP_CALLED_NUMBER: + case L2TP_AVP_SUB_ADDRESS: + case L2TP_AVP_PROXY_AUTH_NAME: + case L2TP_AVP_PRIVATE_GRP_ID: + print_string((u_char *)ptr, len-6); + break; + case L2TP_AVP_CHALLENGE: + case L2TP_AVP_INI_RECV_LCP: + case L2TP_AVP_LAST_SENT_LCP: + case L2TP_AVP_LAST_RECV_LCP: + case L2TP_AVP_PROXY_AUTH_CHAL: + case L2TP_AVP_PROXY_AUTH_RESP: + case L2TP_AVP_RANDOM_VECTOR: + print_octets((u_char *)ptr, len-6); + break; + case L2TP_AVP_Q931_CC: + l2tp_q931_cc_print((u_char *)ptr, len-6); + break; + case L2TP_AVP_CHALLENGE_RESP: + print_octets((u_char *)ptr, 16); + break; + case L2TP_AVP_CALL_SER_NUM: + case L2TP_AVP_MINIMUM_BPS: + case L2TP_AVP_MAXIMUM_BPS: + case L2TP_AVP_TX_CONN_SPEED: + case L2TP_AVP_PHY_CHANNEL_ID: + case L2TP_AVP_RX_CONN_SPEED: + print_32bits_val((u_int32_t *)ptr); + break; + case L2TP_AVP_BEARER_TYPE: + l2tp_bearer_type_print((u_char *)ptr); + break; + case L2TP_AVP_FRAMING_TYPE: + l2tp_framing_type_print((u_char *)ptr); + break; + case L2TP_AVP_PACKET_PROC_DELAY: + l2tp_packet_proc_delay_print(); + break; + case L2TP_AVP_PROXY_AUTH_TYPE: + l2tp_proxy_auth_type_print((u_char *)ptr); + break; + case L2TP_AVP_PROXY_AUTH_ID: + l2tp_proxy_auth_id_print((u_char *)ptr); + break; + case L2TP_AVP_CALL_ERRORS: + l2tp_call_errors_print((u_char *)ptr); + break; + case L2TP_AVP_ACCM: + l2tp_accm_print((u_char *)ptr); + break; + case L2TP_AVP_SEQ_REQUIRED: + break; /* No Attribute Value */ + case L2TP_AVP_PPP_DISCON_CC: + l2tp_ppp_discon_cc_print((u_char *)ptr, len-6); + break; + default: + break; } } - - l2tp_avp_print(dat + len, length - len); - } else if (length == 0) { - return; - } else { - printf("|..."); + printf(")"); } + + l2tp_avp_print(dat+len, length-len); + return; + + trunc: + printf("|..."); } void l2tp_print(const u_char *dat, u_int length) { - const u_short *ptr = (u_short *)dat; + const u_int16_t *ptr = (u_int16_t *)dat; u_int cnt = 0; /* total octets consumed */ - u_short pad; + u_int16_t pad; int flag_t, flag_l, flag_s, flag_o, flag_p; - u_short l2tp_len; + u_int16_t l2tp_len; flag_t = flag_l = flag_s = flag_o = flag_p = FALSE; - if (min(length, snapend - dat) - 6 < 0) { - /* flag/ver, tunnel_id, session_id must be present for - this packet to be properly decoded */ - printf("%s", tstr); - return; - } - + TCHECK(*ptr); /* Flags & Version */ if ((ntohs(*ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2TP) { printf(" l2tp:"); } else if ((ntohs(*ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2F) { @@ -682,24 +650,31 @@ l2tp_print(const u_char *dat, u_int length) cnt += 2; if (flag_l) { - l2tp_len = ntohs(*ptr++); /* XXX need to consider - truncation ?? */ + TCHECK(*ptr); /* Length */ + l2tp_len = ntohs(*ptr++); cnt += 2; } else { l2tp_len = 0; } - printf("(%u/", ntohs(*ptr++)); /* Tunnel ID */ - printf("%u)", ntohs(*ptr++)); /* Session ID */ - cnt += 4; + TCHECK(*ptr); /* Tunnel ID */ + printf("(%u/", ntohs(*ptr++)); + cnt += 2; + TCHECK(*ptr); /* Session ID */ + printf("%u)", ntohs(*ptr++)); + cnt += 2; if (flag_s) { + TCHECK(*ptr); /* Ns */ printf("Ns=%u,", ntohs(*ptr++)); + cnt += 2; + TCHECK(*ptr); /* Nr */ printf("Nr=%u", ntohs(*ptr++)); - cnt += 4; + cnt += 2; } if (flag_o) { + TCHECK(*ptr); /* Offset Size */ pad = ntohs(*ptr++); ptr += pad / sizeof(*ptr); cnt += (2 + pad); @@ -716,4 +691,9 @@ l2tp_print(const u_char *dat, u_int length) ppp_print((u_char *)ptr, length - cnt); printf("}"); } + + return; + + trunc: + printf("%s", tstr); } diff --git a/contrib/tcpdump/print-lane.c b/contrib/tcpdump/print-lane.c index db38ef7..e697dba 100644 --- a/contrib/tcpdump/print-lane.c +++ b/contrib/tcpdump/print-lane.c @@ -22,7 +22,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-lane.c,v 1.11 2000/12/22 22:45:11 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-lane.c,v 1.12 2001/07/05 18:54:15 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -81,6 +81,7 @@ lane_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) u_short ether_type; u_short extracted_ethertype; + ++infodelay; ts_print(&h->ts); if (caplen < sizeof(struct lecdatahdr_8023)) { @@ -136,4 +137,7 @@ lane_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) default_print(p, caplen); out: putchar('\n'); + --infodelay; + if (infoprint) + info(0); } diff --git a/contrib/tcpdump/print-llc.c b/contrib/tcpdump/print-llc.c index 988fdfe..0aa9819 100644 --- a/contrib/tcpdump/print-llc.c +++ b/contrib/tcpdump/print-llc.c @@ -24,7 +24,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-llc.c,v 1.32 2000/12/18 07:55:36 guy Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-llc.c,v 1.43 2001/10/08 21:25:22 fenner Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -46,6 +46,7 @@ static const char rcsid[] = #include "extract.h" /* must come after interface.h */ #include "llc.h" +#include "ethertype.h" static struct tok cmd2str[] = { { LLC_UI, "ui" }, @@ -81,23 +82,47 @@ llc_print(const u_char *p, u_int length, u_int caplen, memcpy((char *)&llc, (char *)p, min(caplen, sizeof(llc))); if (llc.ssap == LLCSAP_GLOBAL && llc.dsap == LLCSAP_GLOBAL) { + /* + * This is an Ethernet_802.3 IPX frame; it has an + * 802.3 header (i.e., an Ethernet header where the + * type/length field is <= ETHERMTU, i.e. it's a length + * field, not a type field), but has no 802.2 header - + * the IPX packet starts right after the Ethernet header, + * with a signature of two bytes of 0xFF (which is + * LLCSAP_GLOBAL). + * + * (It might also have been an Ethernet_802.3 IPX at + * one time, but got bridged onto another network, + * such as an 802.11 network; this has appeared in at + * least one capture file.) + */ ipx_print(p, length); return (1); } - /* Cisco Discovery Protocol - SNAP & ether type 0x2000 */ - if(llc.ssap == LLCSAP_SNAP && llc.dsap == LLCSAP_SNAP && - llc.llcui == LLC_UI && - llc.ethertype[0] == 0x20 && llc.ethertype[1] == 0x00 ) { - cdp_print( p, length, caplen, esrc, edst); - return (1); - } - if (llc.ssap == LLCSAP_8021D && llc.dsap == LLCSAP_8021D) { stp_print(p, length); return (1); } - if (llc.ssap == 0xf0 && llc.dsap == 0xf0 + + if (llc.ssap == LLCSAP_IPX && llc.dsap == LLCSAP_IPX && + llc.llcui == LLC_UI) { + /* + * This is an Ethernet_802.2 IPX frame, with an 802.3 + * header and an 802.2 LLC header with the source and + * destination SAPs being the IPX SAP. + * + * Skip DSAP, LSAP, and control field. + */ + p += 3; + length -= 3; + caplen -= 3; + ipx_print(p, length); + return (1); + } + +#ifdef TCPDUMP_DO_SMB + if (llc.ssap == LLCSAP_NETBEUI && llc.dsap == LLCSAP_NETBEUI && (!(llc.llcu & LLC_S_FMT) || llc.llcu == LLC_U_FMT)) { /* * we don't actually have a full netbeui parser yet, but the @@ -138,9 +163,10 @@ llc_print(const u_char *p, u_int length, u_int caplen, length -= 2; caplen -= 2; } - netbeui_print(control, p, p + min(caplen, length)); + netbeui_print(control, p, length); return (1); } +#endif if (llc.ssap == LLCSAP_ISONS && llc.dsap == LLCSAP_ISONS && llc.llcui == LLC_UI) { isoclns_print(p + 3, length - 3, caplen - 3, esrc, edst); @@ -149,6 +175,8 @@ llc_print(const u_char *p, u_int length, u_int caplen, if (llc.ssap == LLCSAP_SNAP && llc.dsap == LLCSAP_SNAP && llc.llcui == LLC_UI) { + u_int32_t orgcode; + if (caplen < sizeof(llc)) { (void)printf("[|llc-snap]"); default_print((u_char *)p, caplen); @@ -161,16 +189,51 @@ llc_print(const u_char *p, u_int length, u_int caplen, length -= sizeof(llc); p += sizeof(llc); - /* This is an encapsulated Ethernet packet */ - et = EXTRACT_16BITS(&llc.ethertype[0]); - ret = ether_encap_print(et, p, length, caplen, - extracted_ethertype); - if (ret) - return (ret); + orgcode = EXTRACT_24BITS(&llc.llc_orgcode[0]); + et = EXTRACT_16BITS(&llc.llc_ethertype[0]); + switch (orgcode) { + case OUI_ENCAP_ETHER: + case OUI_CISCO_90: + /* + * This is an encapsulated Ethernet packet, + * or a packet bridged by some piece of + * Cisco hardware; the protocol ID is + * an Ethernet protocol type. + */ + ret = ether_encap_print(et, p, length, caplen, + extracted_ethertype); + if (ret) + return (ret); + break; + + case OUI_APPLETALK: + if (et == ETHERTYPE_ATALK) { + /* + * No, I have no idea why Apple used one + * of their own OUIs, rather than + * 0x000000, and an Ethernet packet + * type, for Appletalk data packets, + * but used 0x000000 and an Ethernet + * packet type for AARP packets. + */ + ret = ether_encap_print(et, p, length, caplen, + extracted_ethertype); + if (ret) + return (ret); + } + break; + + case OUI_CISCO: + if (et == ETHERTYPE_CISCO_CDP) { + cdp_print(p, length, caplen, esrc, edst); + return 1; + } + break; + } } if ((llc.ssap & ~LLC_GSAP) == llc.dsap) { - if (eflag) + if (eflag || esrc == NULL || edst == NULL) (void)printf("%s ", llcsap_string(llc.dsap)); else (void)printf("%s > %s %s ", @@ -178,7 +241,7 @@ llc_print(const u_char *p, u_int length, u_int caplen, etheraddr_string(edst), llcsap_string(llc.dsap)); } else { - if (eflag) + if (eflag || esrc == NULL || edst == NULL) (void)printf("%s > %s ", llcsap_string(llc.ssap & ~LLC_GSAP), llcsap_string(llc.dsap)); @@ -219,14 +282,6 @@ llc_print(const u_char *p, u_int length, u_int caplen, caplen -= 3; } } - - if (cmd == LLC_UI && f == 'C') { - /* - * we don't have a proper ipx decoder yet, but there - * is a partial one in the smb code - */ - ipx_netbios_print(p,p+min(caplen,length)); - } } else { char f; diff --git a/contrib/tcpdump/print-lwres.c b/contrib/tcpdump/print-lwres.c new file mode 100644 index 0000000..82ec5ae --- /dev/null +++ b/contrib/tcpdump/print-lwres.c @@ -0,0 +1,599 @@ +/* + * Copyright (C) 2001 WIDE Project. + * 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. Neither the name of the project 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 PROJECT 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 PROJECT 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 lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-lwres.c,v 1.5 2001/06/26 06:19:05 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/param.h> +#include <sys/time.h> + +#include <netinet/in.h> + +#include "nameser.h" + +#include <stdio.h> +#include <string.h> + +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" /* must come after interface.h */ + +/* BIND9 lib/lwres/include/lwres */ +typedef u_int32_t lwres_uint32_t; +typedef u_int16_t lwres_uint16_t; +typedef u_int8_t lwres_uint8_t; + +struct lwres_lwpacket { + lwres_uint32_t length; + lwres_uint16_t version; + lwres_uint16_t pktflags; + lwres_uint32_t serial; + lwres_uint32_t opcode; + lwres_uint32_t result; + lwres_uint32_t recvlength; + lwres_uint16_t authtype; + lwres_uint16_t authlength; +}; + +#define LWRES_LWPACKETFLAG_RESPONSE 0x0001U /* if set, pkt is a response */ + +#define LWRES_LWPACKETVERSION_0 0 + +#define LWRES_FLAG_TRUSTNOTREQUIRED 0x00000001U +#define LWRES_FLAG_SECUREDATA 0x00000002U + +/* + * no-op + */ +#define LWRES_OPCODE_NOOP 0x00000000U + +typedef struct { + /* public */ + lwres_uint16_t datalength; + /* data follows */ +} lwres_nooprequest_t; + +typedef struct { + /* public */ + lwres_uint16_t datalength; + /* data follows */ +} lwres_noopresponse_t; + +/* + * get addresses by name + */ +#define LWRES_OPCODE_GETADDRSBYNAME 0x00010001U + +typedef struct lwres_addr lwres_addr_t; + +struct lwres_addr { + lwres_uint32_t family; + lwres_uint16_t length; + /* address folows */ +}; + +typedef struct { + /* public */ + lwres_uint32_t flags; + lwres_uint32_t addrtypes; + lwres_uint16_t namelen; + /* name follows */ +} lwres_gabnrequest_t; + +typedef struct { + /* public */ + lwres_uint32_t flags; + lwres_uint16_t naliases; + lwres_uint16_t naddrs; + lwres_uint16_t realnamelen; + /* aliases follows */ + /* addrs follows */ + /* realname follows */ +} lwres_gabnresponse_t; + +/* + * get name by address + */ +#define LWRES_OPCODE_GETNAMEBYADDR 0x00010002U +typedef struct { + /* public */ + lwres_uint32_t flags; + lwres_addr_t addr; + /* addr body follows */ +} lwres_gnbarequest_t; + +typedef struct { + /* public */ + lwres_uint32_t flags; + lwres_uint16_t naliases; + lwres_uint16_t realnamelen; + /* aliases follows */ + /* realname follows */ +} lwres_gnbaresponse_t; + +/* + * get rdata by name + */ +#define LWRES_OPCODE_GETRDATABYNAME 0x00010003U + +typedef struct { + /* public */ + lwres_uint32_t flags; + lwres_uint16_t rdclass; + lwres_uint16_t rdtype; + lwres_uint16_t namelen; + /* name follows */ +} lwres_grbnrequest_t; + +typedef struct { + /* public */ + lwres_uint32_t flags; + lwres_uint16_t rdclass; + lwres_uint16_t rdtype; + lwres_uint32_t ttl; + lwres_uint16_t nrdatas; + lwres_uint16_t nsigs; + /* realname here (len + name) */ + /* rdata here (len + name) */ + /* signatures here (len + name) */ +} lwres_grbnresponse_t; + +#define LWRDATA_VALIDATED 0x00000001 + +#define LWRES_ADDRTYPE_V4 0x00000001U /* ipv4 */ +#define LWRES_ADDRTYPE_V6 0x00000002U /* ipv6 */ + +#define LWRES_MAX_ALIASES 16 /* max # of aliases */ +#define LWRES_MAX_ADDRS 64 /* max # of addrs */ + +struct tok opcode[] = { + { LWRES_OPCODE_NOOP, "noop", }, + { LWRES_OPCODE_GETADDRSBYNAME, "getaddrsbyname", }, + { LWRES_OPCODE_GETNAMEBYADDR, "getnamebyaddr", }, + { LWRES_OPCODE_GETRDATABYNAME, "getrdatabyname", }, + { 0, NULL, }, +}; + +/* print-domain.c */ +extern struct tok ns_type2str[]; +extern struct tok ns_class2str[]; + +static int lwres_printname(size_t, const char *); +static int lwres_printnamelen(const char *); +static int lwres_printbinlen(const char *); +static int lwres_printaddr(lwres_addr_t *); + +static int +lwres_printname(size_t l, const char *p0) +{ + const char *p; + int i; + + p = p0; + /* + 1 for terminating \0 */ + if (p + l + 1 > (const char *)snapend) + goto trunc; + + printf(" "); + for (i = 0; i < l; i++) + safeputchar(*p++); + p++; /* skip terminating \0 */ + + return p - p0; + + trunc: + return -1; +} + +static int +lwres_printnamelen(const char *p) +{ + u_int16_t l; + int advance; + + if (p + 2 > (const char *)snapend) + goto trunc; + l = EXTRACT_16BITS(p); + advance = lwres_printname(l, p + 2); + if (advance < 0) + goto trunc; + return 2 + advance; + + trunc: + return -1; +} + +static int +lwres_printbinlen(const char *p0) +{ + const char *p; + u_int16_t l; + int i; + + p = p0; + if (p + 2 > (const char *)snapend) + goto trunc; + l = EXTRACT_16BITS(p); + if (p + 2 + l > (const char *)snapend) + goto trunc; + p += 2; + for (i = 0; i < l; i++) + printf("%02x", *p++); + return p - p0; + + trunc: + return -1; +} + +static int +lwres_printaddr(lwres_addr_t *ap) +{ + u_int16_t l; + const char *p; + int i; + + TCHECK(ap->length); + l = ntohs(ap->length); + /* XXX ap points to packed struct */ + p = (const char *)&ap->length + sizeof(ap->length); + if (p + l > (const char *)snapend) + goto trunc; + + switch (ntohl(ap->family)) { + case 1: /* IPv4 */ + printf(" %s", ipaddr_string(p)); + p += sizeof(struct in_addr); + break; +#ifdef INET6 + case 2: /* IPv6 */ + printf(" %s", ip6addr_string(p)); + p += sizeof(struct in6_addr); + break; +#endif + default: + printf(" %lu/", (unsigned long)ntohl(ap->family)); + for (i = 0; i < l; i++) + printf("%02x", *p++); + } + + return p - (const char *)ap; + + trunc: + return -1; +} + +void +lwres_print(register const u_char *bp, u_int length) +{ + const struct lwres_lwpacket *np; + u_int32_t v; + const char *s; + int response; + int advance; + int unsupported = 0; + + np = (const struct lwres_lwpacket *)bp; + TCHECK(np->authlength); + + printf(" lwres"); + v = ntohs(np->version); + if (vflag || v != LWRES_LWPACKETVERSION_0) + printf(" v%u", v); + if (v != LWRES_LWPACKETVERSION_0) { + s = (const char *)np + ntohl(np->length); + goto tail; + } + + response = ntohs(np->pktflags) & LWRES_LWPACKETFLAG_RESPONSE; + + /* opcode and pktflags */ + v = (u_int32_t)ntohl(np->opcode); + s = tok2str(opcode, "#0x%x", v); + printf(" %s%s", s, response ? "" : "?"); + + /* pktflags */ + v = ntohs(np->pktflags); + if (v & ~LWRES_LWPACKETFLAG_RESPONSE) + printf("[0x%x]", v); + + if (vflag > 1) { + printf(" ("); /*)*/ + printf("serial:0x%lx", (unsigned long)ntohl(np->serial)); + printf(" result:0x%lx", (unsigned long)ntohl(np->result)); + printf(" recvlen:%lu", (unsigned long)ntohl(np->recvlength)); + /* BIND910: not used */ + if (vflag > 2) { + printf(" authtype:0x%x", ntohs(np->authtype)); + printf(" authlen:%u", ntohs(np->authlength)); + } + /*(*/ + printf(")"); + } + + /* per-opcode content */ + if (!response) { + /* + * queries + */ + lwres_gabnrequest_t *gabn; + lwres_gnbarequest_t *gnba; + lwres_grbnrequest_t *grbn; + u_int32_t l; + + gabn = NULL; + gnba = NULL; + grbn = NULL; + + switch (ntohl(np->opcode)) { + case LWRES_OPCODE_NOOP: + break; + case LWRES_OPCODE_GETADDRSBYNAME: + gabn = (lwres_gabnrequest_t *)(np + 1); + TCHECK(gabn->namelen); + /* XXX gabn points to packed struct */ + s = (const char *)&gabn->namelen + + sizeof(gabn->namelen); + l = ntohs(gabn->namelen); + + /* BIND910: not used */ + if (vflag > 2) { + printf(" flags:0x%lx", + (unsigned long)ntohl(gabn->flags)); + } + + v = (u_int32_t)ntohl(gabn->addrtypes); + switch (v & (LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6)) { + case LWRES_ADDRTYPE_V4: + printf(" IPv4"); + break; + case LWRES_ADDRTYPE_V6: + printf(" IPv6"); + break; + case LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6: + printf(" IPv4/6"); + break; + } + if (v & ~(LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6)) + printf("[0x%x]", v); + + advance = lwres_printname(l, s); + if (advance < 0) + goto trunc; + s += advance; + break; + case LWRES_OPCODE_GETNAMEBYADDR: + gnba = (lwres_gnbarequest_t *)(np + 1); + TCHECK(gnba->addr); + + /* BIND910: not used */ + if (vflag > 2) { + printf(" flags:0x%lx", + (unsigned long)ntohl(gnba->flags)); + } + + s = (const char *)&gnba->addr; + + advance = lwres_printaddr(&gnba->addr); + if (advance < 0) + goto trunc; + s += advance; + break; + case LWRES_OPCODE_GETRDATABYNAME: + /* XXX no trace, not tested */ + grbn = (lwres_grbnrequest_t *)(np + 1); + TCHECK(grbn->namelen); + + /* BIND910: not used */ + if (vflag > 2) { + printf(" flags:0x%lx", + (unsigned long)ntohl(grbn->flags)); + } + + printf(" %s", tok2str(ns_type2str, "Type%d", + ntohs(grbn->rdtype))); + if (ntohs(grbn->rdclass) != C_IN); + printf(" %s", tok2str(ns_class2str, "Class%d", + ntohs(grbn->rdclass))); + + /* XXX grbn points to packed struct */ + s = (const char *)&grbn->namelen + + sizeof(grbn->namelen); + l = ntohs(gabn->namelen); + + advance = lwres_printname(l, s); + if (advance < 0) + goto trunc; + s += advance; + break; + default: + unsupported++; + break; + } + } else { + /* + * responses + */ + lwres_gabnresponse_t *gabn; + lwres_gnbaresponse_t *gnba; + lwres_grbnresponse_t *grbn; + u_int32_t l, na; + int i; + + gabn = NULL; + gnba = NULL; + grbn = NULL; + + switch (ntohl(np->opcode)) { + case LWRES_OPCODE_NOOP: + break; + case LWRES_OPCODE_GETADDRSBYNAME: + gabn = (lwres_gabnresponse_t *)(np + 1); + TCHECK(gabn->realnamelen); + /* XXX gabn points to packed struct */ + s = (const char *)&gabn->realnamelen + + sizeof(gabn->realnamelen); + l = ntohs(gabn->realnamelen); + + /* BIND910: not used */ + if (vflag > 2) { + printf(" flags:0x%lx", + (unsigned long)ntohl(gabn->flags)); + } + + printf(" %u/%u", ntohs(gabn->naliases), + ntohs(gabn->naddrs)); + + advance = lwres_printname(l, s); + if (advance < 0) + goto trunc; + s += advance; + + /* aliases */ + na = ntohs(gabn->naliases); + for (i = 0; i < na; i++) { + advance = lwres_printnamelen(s); + if (advance < 0) + goto trunc; + s += advance; + } + + /* addrs */ + na = ntohs(gabn->naddrs); + for (i = 0; i < na; i++) { + advance = lwres_printaddr((lwres_addr_t *)s); + if (advance < 0) + goto trunc; + s += advance; + } + break; + case LWRES_OPCODE_GETNAMEBYADDR: + gnba = (lwres_gnbaresponse_t *)(np + 1); + TCHECK(gnba->realnamelen); + /* XXX gnba points to packed struct */ + s = (const char *)&gnba->realnamelen + + sizeof(gnba->realnamelen); + l = ntohs(gnba->realnamelen); + + /* BIND910: not used */ + if (vflag > 2) { + printf(" flags:0x%lx", + (unsigned long)ntohl(gnba->flags)); + } + + printf(" %u", ntohs(gnba->naliases)); + + advance = lwres_printname(l, s); + if (advance < 0) + goto trunc; + s += advance; + + /* aliases */ + na = ntohs(gnba->naliases); + for (i = 0; i < na; i++) { + advance = lwres_printnamelen(s); + if (advance < 0) + goto trunc; + s += advance; + } + break; + case LWRES_OPCODE_GETRDATABYNAME: + /* XXX no trace, not tested */ + grbn = (lwres_grbnresponse_t *)(np + 1); + TCHECK(grbn->nsigs); + + /* BIND910: not used */ + if (vflag > 2) { + printf(" flags:0x%lx", + (unsigned long)ntohl(grbn->flags)); + } + + printf(" %s", tok2str(ns_type2str, "Type%d", + ntohs(grbn->rdtype))); + if (ntohs(grbn->rdclass) != C_IN); + printf(" %s", tok2str(ns_class2str, "Class%d", + ntohs(grbn->rdclass))); + printf(" TTL "); + relts_print(ntohl(grbn->ttl)); + printf(" %u/%u", ntohs(grbn->nrdatas), + ntohs(grbn->nsigs)); + + /* XXX grbn points to packed struct */ + s = (const char *)&grbn->nsigs+ sizeof(grbn->nsigs); + + advance = lwres_printnamelen(s); + if (advance < 0) + goto trunc; + s += advance; + + /* rdatas */ + na = ntohs(grbn->nrdatas); + for (i = 0; i < na; i++) { + /* XXX should decode resource data */ + advance = lwres_printbinlen(s); + if (advance < 0) + goto trunc; + s += advance; + } + + /* sigs */ + na = ntohs(grbn->nsigs); + for (i = 0; i < na; i++) { + /* XXX how should we print it? */ + advance = lwres_printbinlen(s); + if (advance < 0) + goto trunc; + s += advance; + } + break; + default: + unsupported++; + break; + } + } + + tail: + /* length mismatch */ + if (ntohl(np->length) != length) { + printf(" [len: %lu != %u]", (unsigned long)ntohl(np->length), + length); + } + if (!unsupported && s < (const char *)np + ntohl(np->length)) + printf("[extra]"); + return; + + trunc: + printf("[|lwres]"); + return; +} diff --git a/contrib/tcpdump/print-mobile.c b/contrib/tcpdump/print-mobile.c index a6116f6..bc4f3cb 100644 --- a/contrib/tcpdump/print-mobile.c +++ b/contrib/tcpdump/print-mobile.c @@ -42,7 +42,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-mobile.c,v 1.5 2000/09/29 04:58:43 guy Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-mobile.c,v 1.7 2001/08/20 17:53:54 fenner Exp $"; #endif #include <sys/param.h> @@ -70,8 +70,6 @@ struct mobile_ip { #define OSRC_PRES 0x0080 /* old source is present */ -static u_int16_t mob_in_cksum(u_short *p, int len); - /* * Deencapsulate and print a mobile-tunneled IP datagram */ @@ -89,6 +87,7 @@ mobile_print(const u_char *bp, u_int length) fputs("[|mobile]", stdout); return; } + fputs("mobile: ", stdout); proto = EXTRACT_16BITS(&mob->proto); crc = EXTRACT_16BITS(&mob->hcheck); @@ -108,34 +107,9 @@ mobile_print(const u_char *bp, u_int length) (void)printf("> %s ",ipaddr_string(&mob->odst)); (void)printf("(oproto=%d)",proto>>8); } - if (mob_in_cksum((u_short *)mob, osp ? 12 : 8)!=0) { + if (in_cksum((u_short *)mob, osp ? 12 : 8, 0)!=0) { (void)printf(" (bad checksum %d)",crc); } return; } - -static u_int16_t mob_in_cksum(u_short *p, int len) -{ - u_int32_t sum = 0; - int nwords = len >> 1; - - while (nwords-- != 0) - sum += *p++; - - if (len & 1) { - union { - u_int16_t w; - u_int8_t c[2]; - } u; - u.c[0] = *(u_char *)p; - u.c[1] = 0; - sum += u.w; - } - - /* end-around-carry */ - sum = (sum >> 16) + (sum & 0xffff); - sum += (sum >> 16); - return (~sum); -} - diff --git a/contrib/tcpdump/print-mpls.c b/contrib/tcpdump/print-mpls.c new file mode 100644 index 0000000..eb03705 --- /dev/null +++ b/contrib/tcpdump/print-mpls.c @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2001 WIDE Project. 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. Neither the name of the project 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 PROJECT 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 PROJECT 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 lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-mpls.c,v 1.2 2001/06/26 06:24:57 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/socket.h> + +#include <netinet/in.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "addrtoname.h" +#include "interface.h" +#include "extract.h" /* must come after interface.h */ + +#define LABEL_MASK 0xfffff000 +#define LABEL_SHIFT 12 +#define EXP_MASK 0x00000e00 +#define EXP_SHIFT 9 +#define STACK_MASK 0x00000100 +#define STACK_SHIFT 8 +#define TTL_MASK 0x000000ff +#define TTL_SHIFT 0 + +#define MPLS_LABEL(x) (((x) & LABEL_MASK) >> LABEL_SHIFT) +#define MPLS_EXP(x) (((x) & EXP_MASK) >> EXP_SHIFT) +#define MPLS_STACK(x) (((x) & STACK_MASK) >> STACK_SHIFT) +#define MPLS_TTL(x) (((x) & TTL_MASK) >> TTL_SHIFT) + +static const char *mpls_labelname[] = { +/*0*/ "IPv4 explicit NULL", "router alert", "IPv6 explicit NULL", + "implicit NULL", "rsvd", +/*5*/ "rsvd", "rsvd", "rsvd", "rsvd", "rsvd", +/*10*/ "rsvd", "rsvd", "rsvd", "rsvd", "rsvd", +/*15*/ "rsvd", +}; + +/* + * RFC3032: MPLS label stack encoding + */ +void +mpls_print(const u_char *bp, u_int length) +{ + const u_char *p; + u_int32_t v; + + p = bp; + printf("MPLS"); + TCHECK2(*p, sizeof(v)); + memcpy(&v, p, sizeof(v)); + v = (u_int32_t)ntohl(v); + printf(" ("); /*)*/ + printf("label 0x%x", MPLS_LABEL(v)); + if (vflag && + MPLS_LABEL(v) < sizeof(mpls_labelname) / sizeof(mpls_labelname[0])) + printf("(%s)", mpls_labelname[MPLS_LABEL(v)]); + if (MPLS_EXP(v)) + printf(" exp 0x%x", MPLS_EXP(v)); + if (MPLS_STACK(v)) + printf("[S]"); + printf(" TTL %u", MPLS_TTL(v)); + /*(*/ + printf(")"); + + p += sizeof(v); + + switch (MPLS_LABEL(v)) { + case 0: /* IPv4 explicit NULL label */ + ip_print(p, length - (p - bp)); + break; +#ifdef INET6 + case 2: /* IPv6 explicit NULL label */ + ip6_print(p, length - (p - bp)); + break; +#endif + default: + /* + * Since there's no indication of protocol in MPLS label + * encoding, we can print nothing further. + */ + return; + } + +trunc: + printf("[|MPLS]"); +} diff --git a/contrib/tcpdump/print-msdp.c b/contrib/tcpdump/print-msdp.c new file mode 100644 index 0000000..2ffc34f --- /dev/null +++ b/contrib/tcpdump/print-msdp.c @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2001 William C. Fenner. + * 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. + * The name of William C. Fenner 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. + */ +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-msdp.c,v 1.2 2001/12/10 08:06:40 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include <netinet/in.h> + +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" + +#define MSDP_TYPE_MAX 7 + +void +msdp_print(const unsigned char *sp, u_int length) +{ + unsigned int type, len; + + TCHECK2(*sp, 3); + /* See if we think we're at the beginning of a compound packet */ + type = *sp; + len = EXTRACT_16BITS(sp + 1); + if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX) + goto trunc; /* not really truncated, but still not decodable */ + (void)printf(" msdp:"); + while (length > 0) { + TCHECK2(*sp, 3); + type = *sp; + len = EXTRACT_16BITS(sp + 1); + if (len > 1400 || vflag) + printf(" [len %d]", len); + if (len < 3) + goto trunc; + sp += 3; + length -= 3; + switch (type) { + case 1: /* IPv4 Source-Active */ + case 3: /* IPv4 Source-Active Response */ + if (type == 1) + (void)printf(" SA"); + else + (void)printf(" SA-Response"); + TCHECK(*sp); + (void)printf(" %d entries", *sp); + if (*sp * 12 + 8 < len) { + (void)printf(" [w/data]"); + if (vflag > 1) { + (void)printf(" "); + ip_print(sp + *sp * 12 + 8 - 3, + len - (*sp * 12 + 8)); + } + } + break; + case 2: + (void)printf(" SA-Request"); + TCHECK2(*sp, 5); + (void)printf(" for %s", ipaddr_string(sp + 1)); + break; + case 4: + (void)printf(" Keepalive"); + if (len != 3) + (void)printf("[len=%d] ", len); + break; + case 5: + (void)printf(" Notification"); + break; + default: + (void)printf(" [type=%d len=%d]", type, len); + break; + } + sp += (len - 3); + length -= (len - 3); + } + return; +trunc: + (void)printf(" [|msdp]"); +} diff --git a/contrib/tcpdump/print-nfs.c b/contrib/tcpdump/print-nfs.c index b520160..5c2cc6d 100644 --- a/contrib/tcpdump/print-nfs.c +++ b/contrib/tcpdump/print-nfs.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.87 2000/10/07 05:53:12 itojun Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.89 2001/07/08 08:01:43 itojun Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -1205,7 +1205,7 @@ parserddires(const u_int32_t *dp) int er; dp = parsestatus(dp, &er); - if (dp == 0 || er) + if (dp == NULL || er) return (0); if (qflag) return (1); @@ -1487,7 +1487,8 @@ interp_reply(const struct rpc_msg *rp, u_int32_t proc, u_int32_t vers, int lengt case NFSPROC_ACCESS: printf(" access"); - dp = parserep(rp, length); + if (!(dp = parserep(rp, length))) + break; if (!(dp = parsestatus(dp, &er))) break; if (vflag) diff --git a/contrib/tcpdump/print-ntp.c b/contrib/tcpdump/print-ntp.c index fd2712e..57a0b7a 100644 --- a/contrib/tcpdump/print-ntp.c +++ b/contrib/tcpdump/print-ntp.c @@ -25,7 +25,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ntp.c,v 1.31 2000/10/06 04:23:13 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ntp.c,v 1.32 2001/08/20 15:36:57 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -61,7 +61,6 @@ ntp_print(register const u_char *cp, u_int length) { register const struct ntpdata *bp; int mode, version, leapind; - static char rclock[5]; bp = (struct ntpdata *)cp; /* Note funny sized packets */ @@ -156,9 +155,7 @@ ntp_print(register const u_char *cp, u_int length) break; case PRIM_REF: - strncpy(rclock, (char *)&(bp->refid), 4); - rclock[4] = '\0'; - fputs(rclock, stdout); + fn_printn((char *)&(bp->refid), 4, NULL); break; case INFO_QUERY: diff --git a/contrib/tcpdump/print-null.c b/contrib/tcpdump/print-null.c index 55602a4..e02d298 100644 --- a/contrib/tcpdump/print-null.c +++ b/contrib/tcpdump/print-null.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-null.c,v 1.40 2000/12/16 22:00:50 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-null.c,v 1.41 2001/07/05 18:54:15 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -113,6 +113,7 @@ null_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) const struct ip *ip; u_int family; + ++infodelay; ts_print(&h->ts); memcpy((char *)&family, (char *)p, sizeof(family)); @@ -160,5 +161,8 @@ null_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) if (xflag) default_print((const u_char *)ip, caplen - NULL_HDRLEN); putchar('\n'); + --infodelay; + if (infoprint) + info(0); } diff --git a/contrib/tcpdump/print-ospf.c b/contrib/tcpdump/print-ospf.c index f5e452f..800a44d 100644 --- a/contrib/tcpdump/print-ospf.c +++ b/contrib/tcpdump/print-ospf.c @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ospf.c,v 1.29 2000/09/29 04:58:45 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ospf.c,v 1.31 2001/06/28 04:34:51 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -403,8 +403,9 @@ ospf_decode_v2(register const struct ospfhdr *op, printf(" bdr %s", ipaddr_string(&op->ospf_hello.hello_bdr)); if (vflag) { - printf(" nbrs"); ap = op->ospf_hello.hello_neighbor; + if ((u_char *)ap < dataend) + printf(" nbrs"); while ((u_char *)ap < dataend) { TCHECK(*ap); printf(" %s", ipaddr_string(ap)); @@ -509,12 +510,6 @@ ospf_print(register const u_char *bp, register u_int length, op = (struct ospfhdr *)bp; ip = (struct ip *)bp2; - /* Print the source and destination address */ -#if 0 - (void) printf("%s > %s:", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); -#endif /* XXX Before we do anything else, strip off the MD5 trailer */ TCHECK(op->ospf_authtype); @@ -527,7 +522,7 @@ ospf_print(register const u_char *bp, register u_int length, /* value. If it's not valid, say so and return */ TCHECK(op->ospf_type); cp = tok2str(type2str, "type%d", op->ospf_type); - printf(" OSPFv%d-%s %d:", op->ospf_version, cp, length); + printf("OSPFv%d-%s %d:", op->ospf_version, cp, length); if (*cp == 't') return; diff --git a/contrib/tcpdump/print-ospf6.c b/contrib/tcpdump/print-ospf6.c index f52b462..5f6deb1 100644 --- a/contrib/tcpdump/print-ospf6.c +++ b/contrib/tcpdump/print-ospf6.c @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ospf6.c,v 1.6 2000/09/29 04:58:45 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ospf6.c,v 1.7 2001/05/09 01:08:03 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -359,7 +359,7 @@ ospf6_print_lsa(register const struct lsa *lsap) flags32 = ntohl(lsap->lsa_un.un_asla.asla_metric); ospf6_print_bits(ospf6_asla_flag_bits, flags32); printf(" metric %u", - ntohl(lsap->lsa_un.un_asla.asla_metric) & + (u_int32_t)ntohl(lsap->lsa_un.un_asla.asla_metric) & ASLA_MASK_METRIC); lsapp = lsap->lsa_un.un_asla.asla_prefix; k = ospf6_print_lsaprefix(lsapp); diff --git a/contrib/tcpdump/print-pim.c b/contrib/tcpdump/print-pim.c index 06ba458..63ccb14 100644 --- a/contrib/tcpdump/print-pim.c +++ b/contrib/tcpdump/print-pim.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-pim.c,v 1.23 2000/10/03 02:55:00 itojun Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-pim.c,v 1.29 2001/07/04 21:36:15 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -69,280 +69,287 @@ static void pimv2_print(register const u_char *bp, register u_int len); static void pimv1_join_prune_print(register const u_char *bp, register u_int len) { - int maddrlen, addrlen, ngroups, njoin, nprune; - int njp; - - /* If it's a single group and a single source, use 1-line output. */ - if (TTEST2(bp[0], 30) && bp[11] == 1 && - ((njoin = EXTRACT_16BITS(&bp[20])) + EXTRACT_16BITS(&bp[22])) == 1) { - int hold; - - (void)printf(" RPF %s ", ipaddr_string(bp)); - hold = EXTRACT_16BITS(&bp[6]); - if (hold != 180) { - (void)printf("Hold "); - relts_print(hold); - } - (void)printf("%s (%s/%d, %s", njoin ? "Join" : "Prune", - ipaddr_string(&bp[26]), bp[25] & 0x3f, - ipaddr_string(&bp[12])); - if (EXTRACT_32BITS(&bp[16]) != 0xffffffff) - (void)printf("/%s", ipaddr_string(&bp[16])); - (void)printf(") %s%s %s", + int maddrlen, addrlen, ngroups, njoin, nprune; + int njp; + + /* If it's a single group and a single source, use 1-line output. */ + if (TTEST2(bp[0], 30) && bp[11] == 1 && + ((njoin = EXTRACT_16BITS(&bp[20])) + EXTRACT_16BITS(&bp[22])) == 1) { + int hold; + + (void)printf(" RPF %s ", ipaddr_string(bp)); + hold = EXTRACT_16BITS(&bp[6]); + if (hold != 180) { + (void)printf("Hold "); + relts_print(hold); + } + (void)printf("%s (%s/%d, %s", njoin ? "Join" : "Prune", + ipaddr_string(&bp[26]), bp[25] & 0x3f, + ipaddr_string(&bp[12])); + if (EXTRACT_32BITS(&bp[16]) != 0xffffffff) + (void)printf("/%s", ipaddr_string(&bp[16])); + (void)printf(") %s%s %s", (bp[24] & 0x01) ? "Sparse" : "Dense", (bp[25] & 0x80) ? " WC" : "", (bp[25] & 0x40) ? "RP" : "SPT"); - return; - } - - TCHECK2(bp[0], 4); - (void)printf("\n Upstream Nbr: %s", ipaddr_string(bp)); - TCHECK2(bp[6], 2); - (void)printf("\n Hold time: "); - relts_print(EXTRACT_16BITS(&bp[6])); - bp += 8; len -= 8; - - TCHECK2(bp[0], 4); - maddrlen = bp[1]; - addrlen = bp[2]; - ngroups = bp[3]; - bp += 4; len -= 4; - while (ngroups--) { + return; + } + TCHECK2(bp[0], 4); - (void)printf("\n\tGroup: %s", ipaddr_string(bp)); - if (EXTRACT_32BITS(&bp[4]) != 0xffffffff) - (void)printf("/%s", ipaddr_string(&bp[4])); - TCHECK2(bp[8], 4); - njoin = EXTRACT_16BITS(&bp[8]); - nprune = EXTRACT_16BITS(&bp[10]); - (void)printf(" joined: %d pruned: %d", njoin, nprune); - bp += 12; len -= 12; - for (njp = 0; njp < (njoin + nprune); njp++) { - char *type; - - if (njp < njoin) { - type = "Join "; - } else { - type = "Prune"; - } - TCHECK2(bp[0], 6); - (void)printf("\n\t%s %s%s%s%s/%d", type, + if (vflag > 1) + (void)printf("\n"); + (void)printf(" Upstream Nbr: %s", ipaddr_string(bp)); + TCHECK2(bp[6], 2); + if (vflag > 1) + (void)printf("\n"); + (void)printf(" Hold time: "); + relts_print(EXTRACT_16BITS(&bp[6])); + if (vflag < 2) + return; + bp += 8; + len -= 8; + + TCHECK2(bp[0], 4); + maddrlen = bp[1]; + addrlen = bp[2]; + ngroups = bp[3]; + bp += 4; + len -= 4; + while (ngroups--) { + TCHECK2(bp[0], 4); + (void)printf("\n\tGroup: %s", ipaddr_string(bp)); + if (EXTRACT_32BITS(&bp[4]) != 0xffffffff) + (void)printf("/%s", ipaddr_string(&bp[4])); + TCHECK2(bp[8], 4); + njoin = EXTRACT_16BITS(&bp[8]); + nprune = EXTRACT_16BITS(&bp[10]); + (void)printf(" joined: %d pruned: %d", njoin, nprune); + bp += 12; + len -= 12; + for (njp = 0; njp < (njoin + nprune); njp++) { + char *type; + + if (njp < njoin) + type = "Join "; + else + type = "Prune"; + TCHECK2(bp[0], 6); + (void)printf("\n\t%s %s%s%s%s/%d", type, (bp[0] & 0x01) ? "Sparse " : "Dense ", (bp[1] & 0x80) ? "WC " : "", (bp[1] & 0x40) ? "RP " : "SPT ", - ipaddr_string(&bp[2]), bp[1] & 0x3f); - bp += 6; len -= 6; + ipaddr_string(&bp[2]), bp[1] & 0x3f); + bp += 6; + len -= 6; + } } - } - return; + return; trunc: - (void)printf("[|pim]"); - return; + (void)printf("[|pim]"); + return; } void pimv1_print(register const u_char *bp, register u_int len) { - register const u_char *ep; - register u_char type; + register const u_char *ep; + register u_char type; - ep = (const u_char *)snapend; - if (bp >= ep) - return; + ep = (const u_char *)snapend; + if (bp >= ep) + return; - type = bp[1]; + type = bp[1]; - switch (type) { - case 0: - (void)printf(" Query"); - if (TTEST(bp[8])) { - switch (bp[8] >> 4) { - case 0: (void)printf(" Dense-mode"); + switch (type) { + case 0: + (void)printf(" Query"); + if (TTEST(bp[8])) { + switch (bp[8] >> 4) { + case 0: + (void)printf(" Dense-mode"); break; - case 1: (void)printf(" Sparse-mode"); + case 1: + (void)printf(" Sparse-mode"); break; - case 2: (void)printf(" Sparse-Dense-mode"); + case 2: + (void)printf(" Sparse-Dense-mode"); break; - default: (void)printf(" mode-%d", bp[8] >> 4); + default: + (void)printf(" mode-%d", bp[8] >> 4); break; + } } - } - if (vflag) { - TCHECK2(bp[10],2); - (void)printf(" (Hold-time "); - relts_print(EXTRACT_16BITS(&bp[10])); - (void)printf(")"); - } - break; - - case 1: - (void)printf(" Register"); - TCHECK2(bp[8], 20); /* ip header */ - (void)printf(" for %s > %s", ipaddr_string(&bp[20]), - ipaddr_string(&bp[24])); - break; - - case 2: - (void)printf(" Register-Stop"); - TCHECK2(bp[12], 4); - (void)printf(" for %s > %s", ipaddr_string(&bp[8]), - ipaddr_string(&bp[12])); - break; - - case 3: - (void)printf(" Join/Prune"); - if (vflag) { - pimv1_join_prune_print(&bp[8], len - 8); - } - break; + if (vflag) { + TCHECK2(bp[10],2); + (void)printf(" (Hold-time "); + relts_print(EXTRACT_16BITS(&bp[10])); + (void)printf(")"); + } + break; - case 4: - (void)printf(" RP-reachable"); - if (vflag) { - TCHECK2(bp[22], 2); - (void)printf(" group %s", + case 1: + (void)printf(" Register"); + TCHECK2(bp[8], 20); /* ip header */ + (void)printf(" for %s > %s", ipaddr_string(&bp[20]), + ipaddr_string(&bp[24])); + break; + case 2: + (void)printf(" Register-Stop"); + TCHECK2(bp[12], 4); + (void)printf(" for %s > %s", ipaddr_string(&bp[8]), + ipaddr_string(&bp[12])); + break; + case 3: + (void)printf(" Join/Prune"); + if (vflag) + pimv1_join_prune_print(&bp[8], len - 8); + break; + case 4: + (void)printf(" RP-reachable"); + if (vflag) { + TCHECK2(bp[22], 2); + (void)printf(" group %s", ipaddr_string(&bp[8])); + if (EXTRACT_32BITS(&bp[12]) != 0xffffffff) + (void)printf("/%s", ipaddr_string(&bp[12])); + (void)printf(" RP %s hold ", ipaddr_string(&bp[16])); + relts_print(EXTRACT_16BITS(&bp[22])); + } + break; + case 5: + (void)printf(" Assert"); + TCHECK2(bp[16], 4); + (void)printf(" for %s > %s", ipaddr_string(&bp[16]), + ipaddr_string(&bp[8])); if (EXTRACT_32BITS(&bp[12]) != 0xffffffff) (void)printf("/%s", ipaddr_string(&bp[12])); - (void)printf(" RP %s hold ", - ipaddr_string(&bp[16])); - relts_print(EXTRACT_16BITS(&bp[22])); - } - break; - - case 5: - (void)printf(" Assert"); - TCHECK2(bp[16], 4); - (void)printf(" for %s > %s", ipaddr_string(&bp[16]), - ipaddr_string(&bp[8])); - if (EXTRACT_32BITS(&bp[12]) != 0xffffffff) - (void)printf("/%s", ipaddr_string(&bp[12])); - TCHECK2(bp[24], 4); - (void)printf(" %s pref %d metric %d", - (bp[20] & 0x80) ? "RP-tree" : "SPT", + TCHECK2(bp[24], 4); + (void)printf(" %s pref %d metric %d", + (bp[20] & 0x80) ? "RP-tree" : "SPT", EXTRACT_32BITS(&bp[20]) & 0x7fffffff, EXTRACT_32BITS(&bp[24])); - break; - - case 6: - (void)printf(" Graft"); - if (vflag) { - pimv1_join_prune_print(&bp[8], len - 8); - } - break; - - case 7: - (void)printf(" Graft-ACK"); - if (vflag) { - pimv1_join_prune_print(&bp[8], len - 8); + break; + case 6: + (void)printf(" Graft"); + if (vflag) + pimv1_join_prune_print(&bp[8], len - 8); + break; + case 7: + (void)printf(" Graft-ACK"); + if (vflag) + pimv1_join_prune_print(&bp[8], len - 8); + break; + case 8: + (void)printf(" Mode"); + break; + default: + (void)printf(" [type %d]", type); + break; } - break; - - case 8: - (void)printf(" Mode"); - break; - - default: - (void)printf(" [type %d]", type); - break; - } - if ((bp[4] >> 4) != 1) - (void)printf(" [v%d]", bp[4] >> 4); - return; + if ((bp[4] >> 4) != 1) + (void)printf(" [v%d]", bp[4] >> 4); + return; trunc: - (void)printf("[|pim]"); - return; + (void)printf("[|pim]"); + return; } /* * auto-RP is a cisco protocol, documented at - * ftp://ftpeng.cisco.com/ipmulticast/pim-autorp-spec01.txt + * ftp://ftpeng.cisco.com/ipmulticast/specs/pim-autorp-spec01.txt + * + * This implements version 1+, dated Sept 9, 1998. */ void cisco_autorp_print(register const u_char *bp, register u_int len) { - int type; - int numrps; - int hold; - - TCHECK(bp[0]); - (void)printf(" auto-rp "); - type = bp[0]; - switch (type) { - case 0x11: - (void)printf("candidate-advert"); - break; - case 0x12: - (void)printf("mapping"); - break; - default: - (void)printf("type-0x%02x", type); - break; - } - - TCHECK(bp[1]); - numrps = bp[1]; - - TCHECK2(bp[2], 2); - (void)printf(" Hold "); - hold = EXTRACT_16BITS(&bp[2]); - if (hold) - relts_print(EXTRACT_16BITS(&bp[2])); - else - printf("FOREVER"); - - /* Next 4 bytes are reserved. */ - - bp += 8; len -= 8; - - /*XXX skip unless -v? */ - - /* - * Rest of packet: - * numrps entries of the form: - * 32 bits: RP - * 6 bits: reserved - * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2". - * 8 bits: # of entries for this RP - * each entry: 7 bits: reserved, 1 bit: negative, - * 8 bits: mask 32 bits: source - * lather, rinse, repeat. - */ - while (numrps--) { - int nentries; - char s; + int type; + int numrps; + int hold; - TCHECK2(bp[0], 4); - (void)printf(" RP %s", ipaddr_string(bp)); - TCHECK(bp[4]); - switch (bp[4] & 0x3) { - case 0: printf(" PIMv?"); - break; - case 1: printf(" PIMv1"); + TCHECK(bp[0]); + (void)printf(" auto-rp "); + type = bp[0]; + switch (type) { + case 0x11: + (void)printf("candidate-advert"); break; - case 2: printf(" PIMv2"); + case 0x12: + (void)printf("mapping"); break; - case 3: printf(" PIMv1+2"); + default: + (void)printf("type-0x%02x", type); break; } - TCHECK(bp[5]); - nentries = bp[5]; - bp += 6; len -= 6; - s = ' '; - for (; nentries; nentries--) { - TCHECK2(bp[0], 6); - (void)printf("%c%s%s/%d", s, bp[0] & 1 ? "!" : "", - ipaddr_string(&bp[2]), bp[1]); - s = ','; - bp += 6; len -= 6; + + TCHECK(bp[1]); + numrps = bp[1]; + + TCHECK2(bp[2], 2); + (void)printf(" Hold "); + hold = EXTRACT_16BITS(&bp[2]); + if (hold) + relts_print(EXTRACT_16BITS(&bp[2])); + else + printf("FOREVER"); + + /* Next 4 bytes are reserved. */ + + bp += 8; len -= 8; + + /*XXX skip unless -v? */ + + /* + * Rest of packet: + * numrps entries of the form: + * 32 bits: RP + * 6 bits: reserved + * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2". + * 8 bits: # of entries for this RP + * each entry: 7 bits: reserved, 1 bit: negative, + * 8 bits: mask 32 bits: source + * lather, rinse, repeat. + */ + while (numrps--) { + int nentries; + char s; + + TCHECK2(bp[0], 4); + (void)printf(" RP %s", ipaddr_string(bp)); + TCHECK(bp[4]); + switch (bp[4] & 0x3) { + case 0: printf(" PIMv?"); + break; + case 1: printf(" PIMv1"); + break; + case 2: printf(" PIMv2"); + break; + case 3: printf(" PIMv1+2"); + break; + } + if (bp[4] & 0xfc) + (void)printf(" [rsvd=0x%02x]", bp[4] & 0xfc); + TCHECK(bp[5]); + nentries = bp[5]; + bp += 6; len -= 6; + s = ' '; + for (; nentries; nentries--) { + TCHECK2(bp[0], 6); + (void)printf("%c%s%s/%d", s, bp[0] & 1 ? "!" : "", + ipaddr_string(&bp[2]), bp[1]); + if (bp[0] & 0xfe) + (void)printf("[rsvd=0x%02x]", bp[0] & 0xfe); + s = ','; + bp += 6; len -= 6; + } } - } - return; + return; trunc: - (void)printf("[|autorp]"); - return; + (void)printf("[|autorp]"); + return; } void @@ -359,11 +366,11 @@ pim_print(register const u_char *bp, register u_int len) #endif switch (PIM_VER(pim->pim_typever)) { - case 2: /* avoid hardcoding? */ + case 2: /* avoid hardcoding? */ (void)printf("pim v2"); pimv2_print(bp, len); break; - default: + default: (void)printf("pim v%d", PIM_VER(pim->pim_typever)); break; } @@ -415,11 +422,6 @@ static int pimv2_addr_len; enum pimv2_addrtype { pimv2_unicast, pimv2_group, pimv2_source }; -#if 0 -static char *addrtypestr[] = { - "unicast", "group", "source" -}; -#endif /* 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 @@ -453,19 +455,19 @@ pimv2_addr_print(const u_char *bp, enum pimv2_addrtype at, int silent) if (pimv2_addr_len == 0) { TCHECK(bp[1]); switch (bp[0]) { - case 1: + case 1: af = AF_INET; afstr = "IPv4"; len = 4; break; #ifdef INET6 - case 2: + case 2: af = AF_INET6; afstr = "IPv6"; len = 16; break; #endif - default: + default: return -1; } if (bp[1] != 0) @@ -473,17 +475,17 @@ pimv2_addr_print(const u_char *bp, enum pimv2_addrtype at, int silent) hdrlen = 2; } else { switch (pimv2_addr_len) { - case 4: + case 4: af = AF_INET; afstr = "IPv4"; break; #ifdef INET6 - case 16: + case 16: af = AF_INET6; afstr = "IPv6"; break; #endif - default: + default: return -1; break; } @@ -493,7 +495,7 @@ pimv2_addr_print(const u_char *bp, enum pimv2_addrtype at, int silent) bp += hdrlen; switch (at) { - case pimv2_unicast: + case pimv2_unicast: TCHECK2(bp[0], len); if (af == AF_INET) { if (!silent) @@ -506,8 +508,8 @@ pimv2_addr_print(const u_char *bp, enum pimv2_addrtype at, int silent) } #endif return hdrlen + len; - case pimv2_group: - case pimv2_source: + case pimv2_group: + case pimv2_source: TCHECK2(bp[0], len + 2); if (af == AF_INET) { if (!silent) { @@ -565,7 +567,7 @@ pimv2_print(register const u_char *bp, register u_int len) (void)printf("[RFC2117-encoding] "); switch (PIM_TYPE(pim->pim_typever)) { - case 0: + case 0: { u_int16_t otype, olen; (void)printf(" Hello"); @@ -582,20 +584,13 @@ pimv2_print(register const u_char *bp, register u_int len) (void)printf(")"); break; - /* XXX - * draft-ietf-idmr-pimv2-dr-priority-00.txt - * says that DR-Priority is option 19. - * draft-ietf-pim-v2-sm-00.txt says it's 18. - */ - case 18: /* DR-Priority */ - (void)printf(" (DR-Priority: %d)", EXTRACT_32BITS(&bp[4])); - break; - - case 19: /* Bidir-Capable */ - if (olen == 4) - (void)printf(" (OLD-DR-Priority: %d)", EXTRACT_32BITS(&bp[4])); - else - (void)printf(" (bidir-capable)"); + case 19: /* DR-Priority */ + (void)printf(" (DR-Priority: "); + if (olen != 4) { + (void)printf("!olen=%d!)", olen); + } else { + (void)printf("%d)", EXTRACT_32BITS(&bp[4])); + } break; case 20: @@ -603,13 +598,21 @@ pimv2_print(register const u_char *bp, register u_int len) break; case 21: - (void)printf(" (State Refresh Capable"); - if (EXTRACT_32BITS(&bp[4]) != 1) { - (void)printf(" ?0x%x?", EXTRACT_32BITS(&bp[4])); + (void)printf(" (State Refresh Capable; v%d", bp[4]); + if (bp[5] != 0) { + (void)printf(" interval "); + relts_print(bp[5]); + } + if (EXTRACT_16BITS(&bp[6]) != 0) { + (void)printf(" ?0x%04x?", EXTRACT_16BITS(&bp[6])); } (void)printf(")"); break; + case 22: /* Bidir-Capable */ + (void)printf(" (bidir-capable)"); + break; + default: if (vflag) (void)printf(" [Hello option %d]", otype); @@ -619,8 +622,8 @@ pimv2_print(register const u_char *bp, register u_int len) break; } - case 1: - { + case 1: + { struct ip *ip; (void)printf(" Register"); @@ -635,24 +638,24 @@ pimv2_print(register const u_char *bp, register u_int len) break; ip = (struct ip *)bp; switch (IP_V(ip)) { - case 4: /* IPv4 */ + case 4: /* IPv4 */ printf(" "); ip_print(bp, len); break; #ifdef INET6 - case 6: /* IPv6 */ + case 6: /* IPv6 */ printf(" "); ip6_print(bp, len); break; #endif - default: + default: (void)printf(" IP ver %d", IP_V(ip)); break; } break; - } + } - case 2: + case 2: (void)printf(" Register-Stop"); bp += 4; len -= 4; if (bp >= ep) @@ -673,9 +676,9 @@ pimv2_print(register const u_char *bp, register u_int len) bp += advance; len -= advance; break; - case 3: - case 6: - case 7: + case 3: + case 6: + case 7: { u_int8_t ngroup; u_int16_t holdtime; @@ -684,13 +687,13 @@ pimv2_print(register const u_char *bp, register u_int len) int i, j; switch (PIM_TYPE(pim->pim_typever)) { - case 3: + case 3: (void)printf(" Join/Prune"); break; - case 6: + case 6: (void)printf(" Graft"); break; - case 7: + case 7: (void)printf(" Graft-ACK"); break; } @@ -758,8 +761,8 @@ pimv2_print(register const u_char *bp, register u_int len) break; } - case 4: - { + case 4: + { int i, j, frpcnt; (void)printf(" Bootstrap"); @@ -835,8 +838,8 @@ pimv2_print(register const u_char *bp, register u_int len) } bs_done: break; - } - case 5: + } + case 5: (void)printf(" Assert"); bp += 4; len -= 4; if (bp >= ep) @@ -863,8 +866,8 @@ pimv2_print(register const u_char *bp, register u_int len) (void)printf(" metric=%u", EXTRACT_32BITS(&bp[4])); break; - case 8: - { + case 8: + { int i, pfxcnt; (void)printf(" Candidate-RP-Advertisement"); @@ -901,9 +904,9 @@ pimv2_print(register const u_char *bp, register u_int len) bp += advance; } break; - } + } - case 9: + case 9: (void)printf(" Prune-Refresh"); (void)printf(" src="); if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) { diff --git a/contrib/tcpdump/print-ppp.c b/contrib/tcpdump/print-ppp.c index 5dc1b83..dc2950f 100644 --- a/contrib/tcpdump/print-ppp.c +++ b/contrib/tcpdump/print-ppp.c @@ -31,7 +31,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.58 2000/12/27 11:09:08 itojun Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.64 2001/09/09 02:04:19 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -352,14 +352,14 @@ ppp_protoname(u_int proto) case PPP_XNS: return "XNS"; #endif case PPP_IPX: return "IPX"; + case PPP_OSI: return "OSI"; case PPP_VJC: return "VJC"; case PPP_VJNC: return "VJNC"; -#ifdef PPP_COMP case PPP_COMP: return "COMP"; -#endif case PPP_IPCP: return "IPCP"; case PPP_IPV6CP: return "IPv6CP"; case PPP_IPXCP: return "IPXCP"; + case PPP_OSICP: return "OSICP"; case PPP_CCP: return "CCP"; case PPP_LCP: return "LCP"; case PPP_PAP: return "PAP"; @@ -981,6 +981,11 @@ handle_ppp(u_int proto, const u_char *p, int length) case PPP_IPX: ipx_print(p, length); break; + case PPP_OSI: + isoclns_print(p, length, length, NULL, NULL); + break; + default: + break; } } @@ -1014,7 +1019,8 @@ ppp_print(register const u_char *p, u_int length) length -= 2; } - printf("%s %d: ", ppp_protoname(proto), full_length); + if (eflag) + printf("%s %d: ", ppp_protoname(proto), full_length); handle_ppp(proto, p, length); return; @@ -1031,6 +1037,7 @@ ppp_if_print(u_char *user, const struct pcap_pkthdr *h, register u_int length = h->len; register u_int caplen = h->caplen; + ++infodelay; ts_print(&h->ts); if (caplen < PPP_HDRLEN) { @@ -1093,6 +1100,9 @@ ppp_if_print(u_char *user, const struct pcap_pkthdr *h, default_print(p, caplen); out: putchar('\n'); + --infodelay; + if (infoprint) + info(0); } /* @@ -1112,6 +1122,9 @@ ppp_hdlc_if_print(u_char *user, const struct pcap_pkthdr *h, register u_int caplen = h->caplen; u_int proto; + ++infodelay; + ts_print(&h->ts); + if (caplen < 2) { printf("[|ppp]"); goto out; @@ -1133,7 +1146,6 @@ ppp_hdlc_if_print(u_char *user, const struct pcap_pkthdr *h, goto out; } - ts_print(&h->ts); if (eflag) printf("%02x %02x %d ", p[0], p[1], length); p += 2; @@ -1142,21 +1154,18 @@ ppp_hdlc_if_print(u_char *user, const struct pcap_pkthdr *h, proto = EXTRACT_16BITS(p); p += 2; length -= 2; - printf("%s: ", ppp_protoname(proto)); + if (eflag) + printf("%s: ", ppp_protoname(proto)); handle_ppp(proto, p, length); break; case CHDLC_UNICAST: case CHDLC_BCAST: - /* - * Have the Cisco HDLC print routine do all the work. - */ - chdlc_if_print(user, h, p); - return; + chdlc_print(p, length, caplen); + goto out; default: - ts_print(&h->ts); if (eflag) printf("%02x %02x %d ", p[0], p[1], length); p += 2; @@ -1175,6 +1184,9 @@ ppp_hdlc_if_print(u_char *user, const struct pcap_pkthdr *h, default_print(p, caplen); out: putchar('\n'); + --infodelay; + if (infoprint) + info(0); } @@ -1229,6 +1241,7 @@ ppp_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *q; int i; + ++infodelay; ts_print(&h->ts); if (caplen < PPP_BSDI_HDRLEN) { @@ -1370,5 +1383,8 @@ printx: default_print((const u_char *)p, caplen - hdrlength); out: putchar('\n'); + --infodelay; + if (infoprint) + info(0); #endif /* __bsdi__ */ } diff --git a/contrib/tcpdump/print-pppoe.c b/contrib/tcpdump/print-pppoe.c index 81475cd..0cb9453 100644 --- a/contrib/tcpdump/print-pppoe.c +++ b/contrib/tcpdump/print-pppoe.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = -"@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.12 2000/10/09 02:59:40 guy Exp $ (LBL)"; +"@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.15 2001/07/05 18:54:17 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -45,178 +45,175 @@ static const char rcsid[] = #include "extract.h" /* must come after interface.h */ /* Codes */ -enum { - PPPOE_PADI = 0x09, - PPPOE_PADO = 0x07, - PPPOE_PADR = 0x19, - PPPOE_PADS = 0x65, - PPPOE_PADT = 0xa7 +enum { + PPPOE_PADI = 0x09, + PPPOE_PADO = 0x07, + PPPOE_PADR = 0x19, + PPPOE_PADS = 0x65, + PPPOE_PADT = 0xa7 }; static struct tok pppoecode2str[] = { - { PPPOE_PADI, "PADI"}, - { PPPOE_PADO, "PADO"}, - { PPPOE_PADR, "PADR"}, - { PPPOE_PADS, "PADS"}, - { PPPOE_PADT, "PADT"}, - { 0, ""}, /* PPP Data */ - { 0, NULL } + { PPPOE_PADI, "PADI" }, + { PPPOE_PADO, "PADO" }, + { PPPOE_PADR, "PADR" }, + { PPPOE_PADS, "PADS" }, + { PPPOE_PADT, "PADT" }, + { 0, "" }, /* PPP Data */ + { 0, NULL } }; /* Tags */ enum { - PPPOE_EOL = 0, - PPPOE_SERVICE_NAME = 0x0101, - PPPOE_AC_NAME = 0x0102, - PPPOE_HOST_UNIQ = 0x0103, - PPPOE_AC_COOKIE = 0x0104, - PPPOE_VENDOR = 0x0105, - PPPOE_RELAY_SID = 0x0110, - PPPOE_SERVICE_NAME_ERROR = 0x0201, - PPPOE_AC_SYSTEM_ERROR = 0x0202, - PPPOE_GENERIC_ERROR = 0x0203 + PPPOE_EOL = 0, + PPPOE_SERVICE_NAME = 0x0101, + PPPOE_AC_NAME = 0x0102, + PPPOE_HOST_UNIQ = 0x0103, + PPPOE_AC_COOKIE = 0x0104, + PPPOE_VENDOR = 0x0105, + PPPOE_RELAY_SID = 0x0110, + PPPOE_SERVICE_NAME_ERROR = 0x0201, + PPPOE_AC_SYSTEM_ERROR = 0x0202, + PPPOE_GENERIC_ERROR = 0x0203 }; static struct tok pppoetag2str[] = { - { PPPOE_EOL, "EOL"}, - { PPPOE_SERVICE_NAME, "Service-Name" }, - { PPPOE_AC_NAME, "AC-Name" }, - { PPPOE_HOST_UNIQ, "Host-Uniq" }, - { PPPOE_AC_COOKIE, "AC-Cookie" }, - { PPPOE_VENDOR, "Vendor-Specific" }, - { PPPOE_RELAY_SID, "Relay-Session-ID" }, - { PPPOE_SERVICE_NAME_ERROR, "Service-Name-Error" }, - { PPPOE_AC_SYSTEM_ERROR, "AC-System-Error" }, - { PPPOE_GENERIC_ERROR, "Generic-Error" }, - { 0, NULL} + { PPPOE_EOL, "EOL" }, + { PPPOE_SERVICE_NAME, "Service-Name" }, + { PPPOE_AC_NAME, "AC-Name" }, + { PPPOE_HOST_UNIQ, "Host-Uniq" }, + { PPPOE_AC_COOKIE, "AC-Cookie" }, + { PPPOE_VENDOR, "Vendor-Specific" }, + { PPPOE_RELAY_SID, "Relay-Session-ID" }, + { PPPOE_SERVICE_NAME_ERROR, "Service-Name-Error" }, + { PPPOE_AC_SYSTEM_ERROR, "AC-System-Error" }, + { PPPOE_GENERIC_ERROR, "Generic-Error" }, + { 0, NULL } }; #define PPPOE_HDRLEN 6 void +pppoe_if_print(u_char *user, const struct pcap_pkthdr *h, + register const u_char *p) +{ + register u_int length = h->len; + register u_int caplen = h->caplen; + + ++infodelay; + ts_print(&h->ts); + + /* + * Some printers want to get back at the link level addresses, + * and/or check that they're not walking off the end of the packet. + * Rather than pass them all the way down, we set these globals. + */ + packetp = p; + snapend = p + caplen; + + pppoe_print(p, length); + putchar('\n'); + --infodelay; + if (infoprint) + info(0); +} + +void pppoe_print(register const u_char *bp, u_int length) { - register const struct ether_header *eh; - register u_short pppoe_ver, pppoe_type, pppoe_code, pppoe_sessionid, pppoe_length; - const u_char *pppoe_packet, *pppoe_payload; - - eh = (struct ether_header *)packetp; - pppoe_packet = packetp+ETHER_HDRLEN; - if (pppoe_packet > snapend) { - printf("[|pppoe]"); - return; - } - - pppoe_ver = (pppoe_packet[0]&0xF0)>>4; - pppoe_type = (pppoe_packet[0]&0x0F); - pppoe_code = (pppoe_packet[1]); - pppoe_sessionid = (EXTRACT_16BITS(pppoe_packet+2)); - pppoe_length = (EXTRACT_16BITS(pppoe_packet+4)); - pppoe_payload = pppoe_packet+6; - - if (snapend < pppoe_payload) { - printf(" truncated PPPoE"); - return; - } - - if (pppoe_ver != 1) { - printf(" [ver %d]",pppoe_ver); - } - if (pppoe_type != 1) { - printf(" [type %d]",pppoe_type); - } - - printf("PPPoE %s", tok2str(pppoecode2str, "PAD-%x", pppoe_code)); - if (pppoe_code == PPPOE_PADI && pppoe_length > 1484-PPPOE_HDRLEN) { - printf(" [len %d!]",pppoe_length); - } - if (pppoe_sessionid) { - printf(" [ses 0x%x]",pppoe_sessionid); - } - - if (pppoe_payload + pppoe_length < snapend) { - /* - printf(" [length %d (%d extra bytes)]", pppoe_length, snapend-pppoe_payload-pppoe_length); - { - const u_char *x = pppoe_payload+pppoe_length; - default_print(x, snapend - x); - } - */ - snapend = pppoe_payload+pppoe_length; - } - - - if (pppoe_code) { - /* PPP session packets don't contain tags */ - u_short tag_type = 0xffff, tag_len; - const u_char *p = pppoe_payload; - - /* loop invariant: - p points to next tag, - tag_type is previous tag or 0xffff for first iteration - */ - while (tag_type && - p+4 < pppoe_payload + length && - p+4 < snapend) { - tag_type = EXTRACT_16BITS(p); - tag_len = EXTRACT_16BITS(p+2); - p += 4; - /* p points to tag_value */ - - if (tag_len) { - int isascii = 1; - const u_char *v = p; - - for (v=p; v<p+tag_len; v++) - if (*v >= 127 || *v < 32) { - isascii = 0; - break; - } - - /* TODO print UTF8 decoded text */ - if (isascii) - printf(" [%s \"%*.*s\"]", - tok2str(pppoetag2str, "TAG-0x%x", tag_type), - tag_len < 80 ? tag_len : 80, - tag_len < 80 ? tag_len : 80, - p - ); - else - printf(" [%s UTF8]", tok2str(pppoetag2str, "TAG-0x%x", tag_type)); - } else - printf(" [%s]", tok2str(pppoetag2str, "TAG-0x%x", tag_type)); - - p += tag_len; - /* p points to next tag */ - } - } else { + u_short pppoe_ver, pppoe_type, pppoe_code, pppoe_sessionid, pppoe_length; + const u_char *pppoe_packet, *pppoe_payload; + + pppoe_packet = bp; + if (pppoe_packet > snapend) { + printf("[|pppoe]"); + return; + } + + pppoe_ver = (pppoe_packet[0] & 0xF0) >> 4; + pppoe_type = (pppoe_packet[0] & 0x0F); + pppoe_code = pppoe_packet[1]; + pppoe_sessionid = EXTRACT_16BITS(pppoe_packet + 2); + pppoe_length = EXTRACT_16BITS(pppoe_packet + 4); + pppoe_payload = pppoe_packet + PPPOE_HDRLEN; + + if (snapend < pppoe_payload) { + printf(" truncated PPPoE"); + return; + } + + if (pppoe_ver != 1) { + printf(" [ver %d]",pppoe_ver); + } + if (pppoe_type != 1) { + printf(" [type %d]",pppoe_type); + } + + printf("PPPoE %s", tok2str(pppoecode2str, "PAD-%x", pppoe_code)); + if (pppoe_code == PPPOE_PADI && pppoe_length > 1484 - PPPOE_HDRLEN) { + printf(" [len %d!]",pppoe_length); + } + if (pppoe_sessionid) { + printf(" [ses 0x%x]", pppoe_sessionid); + } + + if (pppoe_payload + pppoe_length < snapend) { #if 0 - /* We now make use of ppp_print() instead, because it has more - comprehensive support for PPP. It also gives us a consistent - output with other protocols like L2TP. */ - u_short ptype; - if (pppoe_payload[0] & 0x1) { - ptype = pppoe_payload[0]; - pppoe_payload +=1; - pppoe_length -=1; - } else if (pppoe_payload[1] & 0x1) { - ptype = ntohs(*(u_short *)pppoe_payload); - pppoe_payload +=2; - pppoe_length -=2; - } else { - printf(" Invalid PPP protocol ID: %x %x", pppoe_payload[0],pppoe_payload[1]); - return; - } - printf(" "); - if (ptype == PPP_IP) - ip_print(pppoe_payload, pppoe_length); - else if (ptype == PPP_LCP) - lcp_print(pppoe_payload, pppoe_length); - else - printf("%s ", tok2str(ppptype2str, "proto-0x%x", ptype)); + const u_char *x = pppoe_payload + pppoe_length; + printf(" [length %d (%d extra bytes)]", + pppoe_length, snapend - pppoe_payload - pppoe_length); + default_print(x, snapend - x); #endif - printf(" "); - ppp_print(pppoe_payload, pppoe_length); - } - return; + snapend = pppoe_payload+pppoe_length; + } + + if (pppoe_code) { + /* PPP session packets don't contain tags */ + u_short tag_type = 0xffff, tag_len; + const u_char *p = pppoe_payload; + + /* + * loop invariant: + * p points to next tag, + * tag_type is previous tag or 0xffff for first iteration + */ + while (tag_type && p + 4 < pppoe_payload + length && + p + 4 < snapend) { + tag_type = EXTRACT_16BITS(p); + tag_len = EXTRACT_16BITS(p + 2); + p += 4; + /* p points to tag_value */ + + if (tag_len) { + int isascii = 1; + const u_char *v = p; + u_short l; + + for (v = p; v < p + tag_len; v++) + if (*v >= 127 || *v < 32) { + isascii = 0; + break; + } + + /* TODO print UTF8 decoded text */ + if (isascii) { + l = (tag_len < 80 ? tag_len : 80); + printf(" [%s \"%*.*s\"]", + tok2str(pppoetag2str, "TAG-0x%x", tag_type), + l, l, p); + } else + printf(" [%s UTF8]", + tok2str(pppoetag2str, "TAG-0x%x", tag_type)); + } else + printf(" [%s]", tok2str(pppoetag2str, + "TAG-0x%x", tag_type)); + + p += tag_len; + /* p points to next tag */ + } + } else { + printf(" "); + ppp_print(pppoe_payload, pppoe_length); + } + return; } diff --git a/contrib/tcpdump/print-pptp.c b/contrib/tcpdump/print-pptp.c new file mode 100644 index 0000000..1798fd3 --- /dev/null +++ b/contrib/tcpdump/print-pptp.c @@ -0,0 +1,1070 @@ +/* + * Copyright (c) 1991, 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. + * + * PPTP support contributed by Motonori Shindo (mshindo@mshindo.net) + */ + + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-pptp.c,v 1.3 2001/10/31 08:54:31 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdio.h> +#include <sys/types.h> +#include <sys/param.h> +#include <netinet/in.h> +#include <arpa/inet.h> + +#include "interface.h" + +static char tstr[] = " [|pptp]"; + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#define PPTP_MSG_TYPE_CTRL 1 /* Control Message */ +#define PPTP_MSG_TYPE_MGMT 2 /* Management Message (currently not used */ +#define PPTP_MAGIC_COOKIE 0x1a2b3c4d /* for sanity check */ + +#define PPTP_CTRL_MSG_TYPE_SCCRQ 1 +#define PPTP_CTRL_MSG_TYPE_SCCRP 2 +#define PPTP_CTRL_MSG_TYPE_StopCCRQ 3 +#define PPTP_CTRL_MSG_TYPE_StopCCRP 4 +#define PPTP_CTRL_MSG_TYPE_ECHORQ 5 +#define PPTP_CTRL_MSG_TYPE_ECHORP 6 +#define PPTP_CTRL_MSG_TYPE_OCRQ 7 +#define PPTP_CTRL_MSG_TYPE_OCRP 8 +#define PPTP_CTRL_MSG_TYPE_ICRQ 9 +#define PPTP_CTRL_MSG_TYPE_ICRP 10 +#define PPTP_CTRL_MSG_TYPE_ICCN 11 +#define PPTP_CTRL_MSG_TYPE_CCRQ 12 +#define PPTP_CTRL_MSG_TYPE_CDN 13 +#define PPTP_CTRL_MSG_TYPE_WEN 14 +#define PPTP_CTRL_MSG_TYPE_SLI 15 + +#define PPTP_FRAMING_CAP_ASYNC_MASK 0x00000001 /* Aynchronous */ +#define PPTP_FRAMING_CAP_SYNC_MASK 0x00000002 /* Synchronous */ + +#define PPTP_BEARER_CAP_ANALOG_MASK 0x00000001 /* Analog */ +#define PPTP_BEARER_CAP_DIGITAL_MASK 0x00000002 /* Digital */ + +static char *pptp_message_type_string[] = { + "NOT_DEFINED", /* 0 Not defined in the RFC2637 */ + "SCCRQ", /* 1 Start-Control-Connection-Request */ + "SCCRP", /* 2 Start-Control-Connection-Reply */ + "StopCCRQ", /* 3 Stop-Control-Connection-Request */ + "StopCCRP", /* 4 Stop-Control-Connection-Reply */ + "ECHORQ", /* 5 Echo Request */ + "ECHORP", /* 6 Echo Reply */ + + "OCRQ", /* 7 Outgoing-Call-Request */ + "OCRP", /* 8 Outgoing-Call-Reply */ + "ICRQ", /* 9 Incoming-Call-Request */ + "ICRP", /* 10 Incoming-Call-Reply */ + "ICCN", /* 11 Incoming-Call-Connected */ + "CCRQ", /* 12 Call-Clear-Request */ + "CDN", /* 13 Call-Disconnect-Notify */ + + "WEN", /* 14 WAN-Error-Notify */ + + "SLI" /* 15 Set-Link-Info */ +#define PPTP_MAX_MSGTYPE_INDEX 16 +}; + +/* common for all PPTP control messages */ +struct pptp_hdr { + u_int16_t length; + u_int16_t msg_type; + u_int32_t magic_cookie; + u_int16_t ctrl_msg_type; + u_int16_t reserved0; +}; + +struct pptp_msg_sccrq { + u_int16_t proto_ver; + u_int16_t reserved1; + u_int32_t framing_cap; + u_int32_t bearer_cap; + u_int16_t max_channel; + u_int16_t firm_rev; + u_char hostname[64]; + u_char vendor[64]; +}; + +struct pptp_msg_sccrp { + u_int16_t proto_ver; + u_int8_t result_code; + u_int8_t err_code; + u_int32_t framing_cap; + u_int32_t bearer_cap; + u_int16_t max_channel; + u_int16_t firm_rev; + u_char hostname[64]; + u_char vendor[64]; +}; + +struct pptp_msg_stopccrq { + u_int8_t reason; + u_int8_t reserved1; + u_int16_t reserved2; +}; + +struct pptp_msg_stopccrp { + u_int8_t result_code; + u_int8_t err_code; + u_int16_t reserved1; +}; + +struct pptp_msg_echorq { + u_int32_t id; +}; + +struct pptp_msg_echorp { + u_int32_t id; + u_int8_t result_code; + u_int8_t err_code; + u_int16_t reserved1; +}; + +struct pptp_msg_ocrq { + u_int16_t call_id; + u_int16_t call_ser; + u_int32_t min_bps; + u_int32_t max_bps; + u_int32_t bearer_type; + u_int32_t framing_type; + u_int16_t recv_winsiz; + u_int16_t pkt_proc_delay; + u_int16_t phone_no_len; + u_int16_t reserved1; + u_char phone_no[64]; + u_char subaddr[64]; +}; + +struct pptp_msg_ocrp { + u_int16_t call_id; + u_int16_t peer_call_id; + u_int8_t result_code; + u_int8_t err_code; + u_int16_t cause_code; + u_int32_t conn_speed; + u_int16_t recv_winsiz; + u_int16_t pkt_proc_delay; + u_int32_t phy_chan_id; +}; + +struct pptp_msg_icrq { + u_int16_t call_id; + u_int16_t call_ser; + u_int32_t bearer_type; + u_int32_t phy_chan_id; + u_int16_t dialed_no_len; + u_int16_t dialing_no_len; + u_char dialed_no[64]; /* DNIS */ + u_char dialing_no[64]; /* CLID */ + u_char subaddr[64]; +}; + +struct pptp_msg_icrp { + u_int16_t call_id; + u_int16_t peer_call_id; + u_int8_t result_code; + u_int8_t err_code; + u_int16_t recv_winsiz; + u_int16_t pkt_proc_delay; + u_int16_t reserved1; +}; + +struct pptp_msg_iccn { + u_int16_t peer_call_id; + u_int16_t reserved1; + u_int32_t conn_speed; + u_int16_t recv_winsiz; + u_int16_t pkt_proc_delay; + u_int32_t framing_type; +}; + +struct pptp_msg_ccrq { + u_int16_t call_id; + u_int16_t reserved1; +}; + +struct pptp_msg_cdn { + u_int16_t call_id; + u_int8_t result_code; + u_int8_t err_code; + u_int16_t cause_code; + u_int16_t reserved1; + u_char call_stats[128]; +}; + +struct pptp_msg_wen { + u_int16_t peer_call_id; + u_int16_t reserved1; + u_int32_t crc_err; + u_int32_t framing_err; + u_int32_t hardware_overrun; + u_int32_t buffer_overrun; + u_int32_t timeout_err; + u_int32_t align_err; +}; + +struct pptp_msg_sli { + u_int16_t peer_call_id; + u_int16_t reserved1; + u_int32_t send_accm; + u_int32_t recv_accm; +}; + +/* attributes that appear more than once in above messages: + + Number of + occurence attributes + -------------------------------------- + 2 u_int32_t bearer_cap; + 2 u_int32_t bearer_type; + 6 u_int16_t call_id; + 2 u_int16_t call_ser; + 2 u_int16_t cause_code; + 2 u_int32_t conn_speed; + 6 u_int8_t err_code; + 2 u_int16_t firm_rev; + 2 u_int32_t framing_cap; + 2 u_int32_t framing_type; + 2 u_char hostname[64]; + 2 u_int32_t id; + 2 u_int16_t max_channel; + 5 u_int16_t peer_call_id; + 2 u_int32_t phy_chan_id; + 4 u_int16_t pkt_proc_delay; + 2 u_int16_t proto_ver; + 4 u_int16_t recv_winsiz; + 2 u_int8_t reserved1; + 9 u_int16_t reserved1; + 6 u_int8_t result_code; + 2 u_char subaddr[64]; + 2 u_char vendor[64]; + + so I will prepare print out functions for these attributes (except for + reserved*). +*/ + +/******************************************/ +/* Attribute-specific print out functions */ +/******************************************/ + +/* In these attribute-specific print-out functions, it't not necessary + to do TCHECK because they are already checked in the caller of + these functions. */ + +static void +pptp_bearer_cap_print(const u_int32_t *bearer_cap) +{ + printf(" BEARER_CAP("); + if (ntohl(*bearer_cap) & PPTP_BEARER_CAP_DIGITAL_MASK) { + printf("D"); + } + if (ntohl(*bearer_cap) & PPTP_BEARER_CAP_ANALOG_MASK) { + printf("A"); + } + printf(")"); +} + +static void +pptp_bearer_type_print(const u_int32_t *bearer_type) +{ + printf(" BEARER_TYPE("); + switch (ntohl(*bearer_type)) { + case 1: + printf("A"); /* Analog */ + break; + case 2: + printf("D"); /* Digital */ + break; + case 3: + printf("Any"); + break; + default: + printf("?"); + break; + } + printf(")"); +} + +static void +pptp_call_id_print(const u_int16_t *call_id) +{ + printf(" CALL_ID(%u)", ntohs(*call_id)); +} + +static void +pptp_call_ser_print(const u_int16_t *call_ser) +{ + printf(" CALL_SER_NUM(%u)", ntohs(*call_ser)); +} + +static void +pptp_cause_code_print(const u_int16_t *cause_code) +{ + printf(" CAUSE_CODE(%u)", ntohs(*cause_code)); +} + +static void +pptp_conn_speed_print(const u_int32_t *conn_speed) +{ + printf(" CONN_SPEED(%lu)", (unsigned long)ntohl(*conn_speed)); +} + +static void +pptp_err_code_print(const u_int8_t *err_code) +{ + printf(" ERR_CODE(%u", *err_code); + if (vflag) { + switch (*err_code) { + case 0: + printf(":None"); + break; + case 1: + printf(":Not-Connected"); + break; + case 2: + printf(":Bad-Format"); + break; + case 3: + printf(":Bad-Valude"); + break; + case 4: + printf(":No-Resource"); + break; + case 5: + printf(":Bad-Call-ID"); + break; + case 6: + printf(":PAC-Error"); + break; + default: + printf(":?"); + break; + } + } + printf(")"); +} + +static void +pptp_firm_rev_print(const u_int16_t *firm_rev) +{ + printf(" FIRM_REV(%u)", ntohs(*firm_rev)); +} + +static void +pptp_framing_cap_print(const u_int32_t *framing_cap) +{ + printf(" FRAME_CAP("); + if (ntohl(*framing_cap) & PPTP_FRAMING_CAP_ASYNC_MASK) { + printf("A"); /* Async */ + } + if (ntohl(*framing_cap) & PPTP_FRAMING_CAP_SYNC_MASK) { + printf("S"); /* Sync */ + } + printf(")"); +} + +static void +pptp_framing_type_print(const u_int32_t *framing_type) +{ + printf(" FRAME_TYPE("); + switch (ntohl(*framing_type)) { + case 1: + printf("A"); /* Async */ + break; + case 2: + printf("S"); /* Sync */ + break; + case 3: + printf("E"); /* Either */ + break; + default: + printf("?"); + break; + } + printf(")"); +} + +static void +pptp_hostname_print(const u_char *hostname) +{ + printf(" HOSTNAME(%.64s)", hostname); +} + +static void +pptp_id_print(const u_int32_t *id) +{ + printf(" ID(%lu)", (unsigned long)ntohl(*id)); +} + +static void +pptp_max_channel_print(const u_int16_t *max_channel) +{ + printf(" MAX_CHAN(%u)", ntohs(*max_channel)); +} + +static void +pptp_peer_call_id_print(const u_int16_t *peer_call_id) +{ + printf(" PEER_CALL_ID(%u)", ntohs(*peer_call_id)); +} + +static void +pptp_phy_chan_id_print(const u_int32_t *phy_chan_id) +{ + printf(" PHY_CHAN_ID(%lu)", (unsigned long)ntohl(*phy_chan_id)); +} + +static void +pptp_pkt_proc_delay_print(const u_int16_t *pkt_proc_delay) +{ + printf(" PROC_DELAY(%u)", ntohs(*pkt_proc_delay)); +} + +static void +pptp_proto_ver_print(const u_int16_t *proto_ver) +{ + printf(" PROTO_VER(%u.%u)", /* Version.Revision */ + ntohs(*proto_ver) >> 8, ntohs(*proto_ver) & 0xff); +} + +static void +pptp_recv_winsiz_print(const u_int16_t *recv_winsiz) +{ + printf(" RECV_WIN(%u)", ntohs(*recv_winsiz)); +} + +static void +pptp_result_code_print(const u_int8_t *result_code, int ctrl_msg_type) +{ + printf(" RESULT_CODE(%u", *result_code); + if (vflag) { + switch (ctrl_msg_type) { + case PPTP_CTRL_MSG_TYPE_SCCRP: + switch (*result_code) { + case 1: + printf(":Successful channel establishment"); + break; + case 2: + printf(":General error"); + break; + case 3: + printf(":Command channel already exists"); + break; + case 4: + printf(":Requester is not authorized to establish a command channel"); + break; + case 5: + printf(":The protocol version of the requester is not supported"); + break; + default: + printf(":?"); + break; + } + break; + case PPTP_CTRL_MSG_TYPE_StopCCRP: + case PPTP_CTRL_MSG_TYPE_ECHORP: + switch (*result_code) { + case 1: + printf(":OK"); + break; + case 2: + printf(":General Error"); + break; + default: + printf(":?"); + break; + } + break; + case PPTP_CTRL_MSG_TYPE_OCRP: + switch (*result_code) { + case 1: + printf(":Connected"); + break; + case 2: + printf(":General Error"); + break; + case 3: + printf(":No Carrier"); + break; + case 4: + printf(":Busy"); + break; + case 5: + printf(":No Dial Tone"); + break; + case 6: + printf(":Time-out"); + break; + case 7: + printf(":Do Not Accept"); + break; + default: + printf(":?"); + break; + } + break; + case PPTP_CTRL_MSG_TYPE_ICRP: + switch (*result_code) { + case 1: + printf(":Connect"); + break; + case 2: + printf(":General Error"); + break; + case 3: + printf(":Do Not Accept"); + break; + default: + printf(":?"); + break; + } + break; + case PPTP_CTRL_MSG_TYPE_CDN: + switch (*result_code) { + case 1: + printf(":Lost Carrier"); + break; + case 2: + printf(":General Error"); + break; + case 3: + printf(":Admin Shutdown"); + break; + case 4: + printf(":Request"); + default: + printf(":?"); + break; + break; + } + default: + /* assertion error */ + break; + } + } + printf(")"); +} + +static void +pptp_subaddr_print(const u_char *subaddr) +{ + printf(" SUB_ADDR(%.64s)", subaddr); +} + +static void +pptp_vendor_print(const u_char *vendor) +{ + printf(" VENDOR(%.64s)", vendor); +} + +/************************************/ +/* PPTP message print out functions */ +/************************************/ +static void +pptp_sccrq_print(const u_char *dat) +{ + struct pptp_msg_sccrq *ptr = (struct pptp_msg_sccrq *)dat; + + TCHECK(ptr->proto_ver); + pptp_proto_ver_print(&ptr->proto_ver); + TCHECK(ptr->reserved1); + TCHECK(ptr->framing_cap); + pptp_framing_cap_print(&ptr->framing_cap); + TCHECK(ptr->bearer_cap); + pptp_bearer_cap_print(&ptr->bearer_cap); + TCHECK(ptr->max_channel); + pptp_max_channel_print(&ptr->max_channel); + TCHECK(ptr->firm_rev); + pptp_firm_rev_print(&ptr->firm_rev); + TCHECK(ptr->hostname); + pptp_hostname_print(&ptr->hostname[0]); + TCHECK(ptr->vendor); + pptp_vendor_print(&ptr->vendor[0]); + + return; + +trunc: + printf("%s", tstr); +} + +static void +pptp_sccrp_print(const u_char *dat) +{ + struct pptp_msg_sccrp *ptr = (struct pptp_msg_sccrp *)dat; + + TCHECK(ptr->proto_ver); + pptp_proto_ver_print(&ptr->proto_ver); + TCHECK(ptr->result_code); + pptp_result_code_print(&ptr->result_code, PPTP_CTRL_MSG_TYPE_SCCRP); + TCHECK(ptr->err_code); + pptp_err_code_print(&ptr->err_code); + TCHECK(ptr->framing_cap); + pptp_framing_cap_print(&ptr->framing_cap); + TCHECK(ptr->bearer_cap); + pptp_bearer_cap_print(&ptr->bearer_cap); + TCHECK(ptr->max_channel); + pptp_max_channel_print(&ptr->max_channel); + TCHECK(ptr->firm_rev); + pptp_firm_rev_print(&ptr->firm_rev); + TCHECK(ptr->hostname); + pptp_hostname_print(&ptr->hostname[0]); + TCHECK(ptr->vendor); + pptp_vendor_print(&ptr->vendor[0]); + + return; + +trunc: + printf("%s", tstr); +} + +static void +pptp_stopccrq_print(const u_char *dat) +{ + struct pptp_msg_stopccrq *ptr = (struct pptp_msg_stopccrq *)dat; + + TCHECK(ptr->reason); + printf(" REASON(%u", ptr->reason); + if (vflag) { + switch (ptr->reason) { + case 1: + printf(":None"); + break; + case 2: + printf(":Stop-Protocol"); + break; + case 3: + printf(":Stop-Local-Shutdown"); + break; + default: + printf(":?"); + break; + } + } + printf(")"); + TCHECK(ptr->reserved1); + TCHECK(ptr->reserved2); + + return; + +trunc: + printf("%s", tstr); +} + +static void +pptp_stopccrp_print(const u_char *dat) +{ + struct pptp_msg_stopccrp *ptr = (struct pptp_msg_stopccrp *)dat; + + TCHECK(ptr->result_code); + pptp_result_code_print(&ptr->result_code, PPTP_CTRL_MSG_TYPE_StopCCRP); + TCHECK(ptr->err_code); + pptp_err_code_print(&ptr->err_code); + TCHECK(ptr->reserved1); + + return; + +trunc: + printf("%s", tstr); +} + +static void +pptp_echorq_print(const u_char *dat) +{ + struct pptp_msg_echorq *ptr = (struct pptp_msg_echorq *)dat; + + TCHECK(ptr->id); + pptp_id_print(&ptr->id); + + return; + +trunc: + printf("%s", tstr); +} + +static void +pptp_echorp_print(const u_char *dat) +{ + struct pptp_msg_echorp *ptr = (struct pptp_msg_echorp *)dat; + + TCHECK(ptr->id); + pptp_id_print(&ptr->id); + TCHECK(ptr->result_code); + pptp_result_code_print(&ptr->result_code, PPTP_CTRL_MSG_TYPE_ECHORP); + TCHECK(ptr->err_code); + pptp_err_code_print(&ptr->err_code); + TCHECK(ptr->reserved1); + + return; + +trunc: + printf("%s", tstr); +} + +static void +pptp_ocrq_print(const u_char *dat) +{ + struct pptp_msg_ocrq *ptr = (struct pptp_msg_ocrq *)dat; + + TCHECK(ptr->call_id); + pptp_call_id_print(&ptr->call_id); + TCHECK(ptr->call_ser); + pptp_call_ser_print(&ptr->call_ser); + TCHECK(ptr->min_bps); + printf(" MIN_BPS(%lu)", (unsigned long)ntohl(ptr->min_bps)); + TCHECK(ptr->max_bps); + printf(" MAX_BPS(%lu)", (unsigned long)ntohl(ptr->max_bps)); + TCHECK(ptr->bearer_type); + pptp_bearer_type_print(&ptr->bearer_type); + TCHECK(ptr->framing_type); + pptp_framing_type_print(&ptr->framing_type); + TCHECK(ptr->recv_winsiz); + pptp_recv_winsiz_print(&ptr->recv_winsiz); + TCHECK(ptr->pkt_proc_delay); + pptp_pkt_proc_delay_print(&ptr->pkt_proc_delay); + TCHECK(ptr->phone_no_len); + printf(" PHONE_NO_LEN(%u)", ntohs(ptr->phone_no_len)); + TCHECK(ptr->reserved1); + TCHECK(ptr->phone_no); + printf(" PHONE_NO(%.64s)", ptr->phone_no); + TCHECK(ptr->subaddr); + pptp_subaddr_print(&ptr->subaddr[0]); + + return; + +trunc: + printf("%s", tstr); +} + +static void +pptp_ocrp_print(const u_char *dat) +{ + struct pptp_msg_ocrp *ptr = (struct pptp_msg_ocrp *)dat; + + TCHECK(ptr->call_id); + pptp_call_id_print(&ptr->call_id); + TCHECK(ptr->peer_call_id); + pptp_peer_call_id_print(&ptr->peer_call_id); + TCHECK(ptr->result_code); + pptp_result_code_print(&ptr->result_code, PPTP_CTRL_MSG_TYPE_OCRP); + TCHECK(ptr->err_code); + pptp_err_code_print(&ptr->err_code); + TCHECK(ptr->cause_code); + pptp_cause_code_print(&ptr->cause_code); + TCHECK(ptr->conn_speed); + pptp_conn_speed_print(&ptr->conn_speed); + TCHECK(ptr->recv_winsiz); + pptp_recv_winsiz_print(&ptr->recv_winsiz); + TCHECK(ptr->pkt_proc_delay); + pptp_pkt_proc_delay_print(&ptr->pkt_proc_delay); + TCHECK(ptr->phy_chan_id); + pptp_phy_chan_id_print(&ptr->phy_chan_id); + + return; + +trunc: + printf("%s", tstr); +} + +static void +pptp_icrq_print(const u_char *dat) +{ + struct pptp_msg_icrq *ptr = (struct pptp_msg_icrq *)dat; + + TCHECK(ptr->call_id); + pptp_call_id_print(&ptr->call_id); + TCHECK(ptr->call_ser); + pptp_call_ser_print(&ptr->call_ser); + TCHECK(ptr->bearer_type); + pptp_bearer_type_print(&ptr->bearer_type); + TCHECK(ptr->phy_chan_id); + pptp_phy_chan_id_print(&ptr->phy_chan_id); + TCHECK(ptr->dialed_no_len); + printf(" DIALED_NO_LEN(%u)", ntohs(ptr->dialed_no_len)); + TCHECK(ptr->dialing_no_len); + printf(" DIALING_NO_LEN(%u)", ntohs(ptr->dialing_no_len)); + TCHECK(ptr->dialed_no); + printf(" DIALED_NO(%.64s)", ptr->dialed_no); + TCHECK(ptr->dialing_no); + printf(" DIALING_NO(%.64s)", ptr->dialing_no); + TCHECK(ptr->subaddr); + pptp_subaddr_print(&ptr->subaddr[0]); + + return; + +trunc: + printf("%s", tstr); +} + +static void +pptp_icrp_print(const u_char *dat) +{ + struct pptp_msg_icrp *ptr = (struct pptp_msg_icrp *)dat; + + TCHECK(ptr->call_id); + pptp_call_id_print(&ptr->call_id); + TCHECK(ptr->peer_call_id); + pptp_peer_call_id_print(&ptr->peer_call_id); + TCHECK(ptr->result_code); + pptp_result_code_print(&ptr->result_code, PPTP_CTRL_MSG_TYPE_ICRP); + TCHECK(ptr->err_code); + pptp_err_code_print(&ptr->err_code); + TCHECK(ptr->recv_winsiz); + pptp_recv_winsiz_print(&ptr->recv_winsiz); + TCHECK(ptr->pkt_proc_delay); + pptp_pkt_proc_delay_print(&ptr->pkt_proc_delay); + TCHECK(ptr->reserved1); + + return; + +trunc: + printf("%s", tstr); +} + +static void +pptp_iccn_print(const u_char *dat) +{ + struct pptp_msg_iccn *ptr = (struct pptp_msg_iccn *)dat; + + TCHECK(ptr->peer_call_id); + pptp_peer_call_id_print(&ptr->peer_call_id); + TCHECK(ptr->reserved1); + TCHECK(ptr->conn_speed); + pptp_conn_speed_print(&ptr->conn_speed); + TCHECK(ptr->recv_winsiz); + pptp_recv_winsiz_print(&ptr->recv_winsiz); + TCHECK(ptr->pkt_proc_delay); + pptp_pkt_proc_delay_print(&ptr->pkt_proc_delay); + TCHECK(ptr->framing_type); + pptp_framing_type_print(&ptr->framing_type); + + return; + +trunc: + printf("%s", tstr); +} + +static void +pptp_ccrq_print(const u_char *dat) +{ + struct pptp_msg_ccrq *ptr = (struct pptp_msg_ccrq *)dat; + + TCHECK(ptr->call_id); + pptp_call_id_print(&ptr->call_id); + TCHECK(ptr->reserved1); + + return; + +trunc: + printf("%s", tstr); +} + +static void +pptp_cdn_print(const u_char *dat) +{ + struct pptp_msg_cdn *ptr = (struct pptp_msg_cdn *)dat; + + TCHECK(ptr->call_id); + pptp_call_id_print(&ptr->call_id); + TCHECK(ptr->result_code); + pptp_result_code_print(&ptr->result_code, PPTP_CTRL_MSG_TYPE_CDN); + TCHECK(ptr->err_code); + pptp_err_code_print(&ptr->err_code); + TCHECK(ptr->cause_code); + pptp_cause_code_print(&ptr->cause_code); + TCHECK(ptr->reserved1); + TCHECK(ptr->call_stats); + printf(" CALL_STATS(%.128s)", ptr->call_stats); + + return; + +trunc: + printf("%s", tstr); +} + +static void +pptp_wen_print(const u_char *dat) +{ + struct pptp_msg_wen *ptr = (struct pptp_msg_wen *)dat; + + TCHECK(ptr->peer_call_id); + pptp_peer_call_id_print(&ptr->peer_call_id); + TCHECK(ptr->reserved1); + TCHECK(ptr->crc_err); + printf(" CRC_ERR(%lu)", (unsigned long)ntohl(ptr->crc_err)); + TCHECK(ptr->framing_err); + printf(" FRAMING_ERR(%lu)", (unsigned long)ntohl(ptr->framing_err)); + TCHECK(ptr->hardware_overrun); + printf(" HARDWARE_OVERRUN(%lu)", + (unsigned long)ntohl(ptr->hardware_overrun)); + TCHECK(ptr->buffer_overrun); + printf(" BUFFER_OVERRUN(%lu)", + (unsigned long)ntohl(ptr->buffer_overrun)); + TCHECK(ptr->timeout_err); + printf(" TIMEOUT_ERR(%lu)", (unsigned long)ntohl(ptr->timeout_err)); + TCHECK(ptr->align_err); + printf(" ALIGN_ERR(%lu)", (unsigned long)ntohl(ptr->align_err)); + + return; + +trunc: + printf("%s", tstr); +} + +static void +pptp_sli_print(const u_char *dat) +{ + struct pptp_msg_sli *ptr = (struct pptp_msg_sli *)dat; + + TCHECK(ptr->peer_call_id); + pptp_peer_call_id_print(&ptr->peer_call_id); + TCHECK(ptr->reserved1); + TCHECK(ptr->send_accm); + printf(" SEND_ACCM(0x%08lx)", (unsigned long)ntohl(ptr->send_accm)); + TCHECK(ptr->recv_accm); + printf(" RECV_ACCM(0x%08lx)", (unsigned long)ntohl(ptr->recv_accm)); + + return; + +trunc: + printf("%s", tstr); +} + +void +pptp_print(const u_char *dat, u_int length) +{ + const struct pptp_hdr *hdr; + u_int32_t mc; + u_int16_t ctrl_msg_type; + + printf(": pptp"); + + hdr = (struct pptp_hdr *)dat; + + TCHECK(hdr->length); + if (vflag) { + printf(" Length=%u", ntohs(hdr->length)); + } + TCHECK(hdr->msg_type); + if (vflag) { + switch(ntohs(hdr->msg_type)) { + case PPTP_MSG_TYPE_CTRL: + printf(" CTRL-MSG"); + break; + case PPTP_MSG_TYPE_MGMT: + printf(" MGMT-MSG"); + break; + default: + printf(" UNKNOWN-MSG-TYPE"); + break; + } + } + + TCHECK(hdr->magic_cookie); + mc = ntohl(hdr->magic_cookie); + if (mc != PPTP_MAGIC_COOKIE) { + printf(" UNEXPECTED Magic-Cookie!!(%08x)", mc); + } + if (vflag || mc != PPTP_MAGIC_COOKIE) { + printf(" Magic-Cookie=%08x", mc); + } + TCHECK(hdr->ctrl_msg_type); + ctrl_msg_type = ntohs(hdr->ctrl_msg_type); + if (ctrl_msg_type < PPTP_MAX_MSGTYPE_INDEX) { + printf(" CTRL_MSGTYPE=%s", + pptp_message_type_string[ctrl_msg_type]); + } else { + printf(" UNKNOWN_CTRL_MSGTYPE(%u)", ctrl_msg_type); + } + TCHECK(hdr->reserved0); + + dat += 12; + + switch(ctrl_msg_type) { + case PPTP_CTRL_MSG_TYPE_SCCRQ: + pptp_sccrq_print(dat); + break; + case PPTP_CTRL_MSG_TYPE_SCCRP: + pptp_sccrp_print(dat); + break; + case PPTP_CTRL_MSG_TYPE_StopCCRQ: + pptp_stopccrq_print(dat); + break; + case PPTP_CTRL_MSG_TYPE_StopCCRP: + pptp_stopccrp_print(dat); + break; + case PPTP_CTRL_MSG_TYPE_ECHORQ: + pptp_echorq_print(dat); + break; + case PPTP_CTRL_MSG_TYPE_ECHORP: + pptp_echorp_print(dat); + break; + case PPTP_CTRL_MSG_TYPE_OCRQ: + pptp_ocrq_print(dat); + break; + case PPTP_CTRL_MSG_TYPE_OCRP: + pptp_ocrp_print(dat); + break; + case PPTP_CTRL_MSG_TYPE_ICRQ: + pptp_icrq_print(dat); + break; + case PPTP_CTRL_MSG_TYPE_ICRP: + pptp_icrp_print(dat); + break; + case PPTP_CTRL_MSG_TYPE_ICCN: + pptp_iccn_print(dat); + break; + case PPTP_CTRL_MSG_TYPE_CCRQ: + pptp_ccrq_print(dat); + break; + case PPTP_CTRL_MSG_TYPE_CDN: + pptp_cdn_print(dat); + break; + case PPTP_CTRL_MSG_TYPE_WEN: + pptp_wen_print(dat); + break; + case PPTP_CTRL_MSG_TYPE_SLI: + pptp_sli_print(dat); + break; + default: + /* do nothing */ + break; + } + + return; + +trunc: + printf("%s", tstr); +} diff --git a/contrib/tcpdump/print-radius.c b/contrib/tcpdump/print-radius.c index 32c8575..a3c8403 100644 --- a/contrib/tcpdump/print-radius.c +++ b/contrib/tcpdump/print-radius.c @@ -1,4 +1,25 @@ /* + * Copyright (C) 2000 Alfredo Andres Omella. 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. 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. + */ +/* * Radius printer routines as specified on: * * RFC 2865: @@ -23,13 +44,15 @@ #ifndef lint static const char rcsid[] = - "$Id: print-radius.c,v 1.5 2000/12/18 08:16:58 guy Exp $"; + "$Id: print-radius.c,v 1.10 2001/10/22 06:58:33 itojun Exp $"; #endif #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include <string.h> + #include <sys/param.h> #include <netinet/in.h> @@ -115,6 +138,7 @@ struct radius_hdr { u_int8_t code; /* Radius packet code */ u_int8_t auth[16]; /* Authenticator */ }; +#define MIN_RADIUS_LEN 20 struct radius_attr { u_int8_t type; /* Attribute type */ u_int8_t len; /* Attribute length */ @@ -495,7 +519,6 @@ print_attr_num(register u_char *data, u_int length, u_short attr_code ) } else { - data++; data_value = EXTRACT_32BITS(data); } if ( data_value <= (attr_type[attr_code].siz_subtypes - 1 + @@ -638,7 +661,7 @@ static void print_attr_time(register u_char *data, u_int length, u_short attr_co TCHECK2(data[0],4); attr_time = EXTRACT_32BITS(data); - strcpy(string, ctime(&attr_time)); + strlcpy(string, ctime(&attr_time), sizeof(string)); /* Get rid of the newline */ string[24] = '\0'; printf("{%.24s}", string); @@ -730,7 +753,7 @@ static void print_attr_strange(register u_char *data, u_int length, u_short attr static void -radius_attr_print(register u_char *attr, u_int length) +radius_attr_print(register const u_char *attr, u_int length) { register const struct radius_attr *rad_attr = (struct radius_attr *)attr; @@ -743,6 +766,11 @@ radius_attr_print(register u_char *attr, u_int length) printf(" Attr[ "); while (length > 0) { + if (rad_attr->len == 0) + { + printf("(zero-length attribute)"); + return; + } if ( rad_attr->len <= length ) { if ( !rad_attr->type || (rad_attr->type > (TAM_SIZE(attr_type)-1)) ) @@ -778,17 +806,30 @@ radius_print(const u_char *dat, u_int length) { register const struct radius_hdr *rad; register int i; + int len; - i = min(length, snapend - dat) - sizeof(*rad); + i = min(length, snapend - dat); - if (i < 0) + if (i < MIN_RADIUS_LEN) { printf(" [|radius]"); return; } rad = (struct radius_hdr *)dat; - + len = ntohs(rad->len); + + if (len < MIN_RADIUS_LEN) + { + printf(" [|radius]"); + return; + } + + if (len < i) + i = len; + + i -= MIN_RADIUS_LEN; + switch (rad->code) { case RADCMD_ACCESS_REQ: @@ -834,5 +875,5 @@ radius_print(const u_char *dat, u_int length) printf(" [id %d]", rad->id); if (i) - radius_attr_print( ((u_char *)(rad+1)), i); + radius_attr_print( dat + MIN_RADIUS_LEN, i); } diff --git a/contrib/tcpdump/print-raw.c b/contrib/tcpdump/print-raw.c index b6e421c..f6ffc41 100644 --- a/contrib/tcpdump/print-raw.c +++ b/contrib/tcpdump/print-raw.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-raw.c,v 1.33 2000/10/06 04:23:13 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-raw.c,v 1.34 2001/07/05 18:54:17 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -53,6 +53,7 @@ raw_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) u_int length = h->len; u_int caplen = h->caplen; + ++infodelay; ts_print(&h->ts); /* @@ -71,4 +72,7 @@ raw_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) if (xflag) default_print(p, caplen); putchar('\n'); + --infodelay; + if (infoprint) + info(0); } diff --git a/contrib/tcpdump/print-rip.c b/contrib/tcpdump/print-rip.c index 1f02c23..bb3d53a 100644 --- a/contrib/tcpdump/print-rip.c +++ b/contrib/tcpdump/print-rip.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-rip.c,v 1.47 2000/10/03 04:19:07 itojun Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-rip.c,v 1.49 2001/05/10 05:30:22 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -181,7 +181,7 @@ rip_print(const u_char *dat, u_int length) * * so perhaps we should just dump the first few words of * the packet, in hex. - */ + */ printf(" RIPv0: "); ni = (struct rip_netinfo *)(rp + 1); rip_printblk((u_char *)&ni->rip_family, @@ -215,7 +215,7 @@ rip_print(const u_char *dat, u_int length) case RIPCMD_TRACEON: printf(" RIPv%d-traceon %d: \"", rp->rip_vers, length); (void)fn_print((const u_char *)(rp + 1), snapend); - fputs("\"\n", stdout); + fputs("\"", stdout); break; case RIPCMD_TRACEOFF: printf(" RIPv%d-traceoff %d", rp->rip_vers, length); @@ -231,5 +231,5 @@ rip_print(const u_char *dat, u_int length) length); break; } - } + } } diff --git a/contrib/tcpdump/print-ripng.c b/contrib/tcpdump/print-ripng.c index e4d11a4..ad6d3f8 100644 --- a/contrib/tcpdump/print-ripng.c +++ b/contrib/tcpdump/print-ripng.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ripng.c,v 1.7 2000/10/07 05:46:21 itojun Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ripng.c,v 1.10 2001/11/16 08:59:22 itojun Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -57,7 +57,7 @@ rip6_entry_print(register const struct netinfo6 *ni, int metric) } void -ripng_print(const u_char *dat, int length) +ripng_print(const u_char *dat, unsigned int length) { register const struct rip6 *rp = (struct rip6 *)dat; register const struct netinfo6 *ni; @@ -81,12 +81,12 @@ ripng_print(const u_char *dat, int length) break; } if (j * sizeof(*ni) != length - 4) - printf(" ripng-req %d[%d]:", j, length); + printf(" ripng-req %d[%u]:", j, length); else printf(" ripng-req %d:", j); trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) { - if (vflag) + if (vflag > 1) printf("\n\t"); else printf(" "); @@ -96,22 +96,22 @@ ripng_print(const u_char *dat, int length) case RIP6_RESPONSE: j = length / sizeof(*ni); if (j * sizeof(*ni) != length - 4) - printf(" ripng-resp %d[%d]:", j, length); + printf(" ripng-resp %d[%u]:", j, length); else printf(" ripng-resp %d:", j); trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) { - if (vflag) + if (vflag > 1) printf("\n\t"); else printf(" "); rip6_entry_print(ni, ni->rip6_metric); } if (trunc) - printf("[|rip]"); + printf("[|ripng]"); break; default: - printf(" ripng-%d ?? %d", rp->rip6_cmd, length); + printf(" ripng-%d ?? %u", rp->rip6_cmd, length); break; } if (rp->rip6_vers != RIP6_VERSION) diff --git a/contrib/tcpdump/print-rt6.c b/contrib/tcpdump/print-rt6.c index ea464e2..dc5f0f3 100644 --- a/contrib/tcpdump/print-rt6.c +++ b/contrib/tcpdump/print-rt6.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-rt6.c,v 1.17 2000/12/13 07:57:05 itojun Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-rt6.c,v 1.18 2001/06/15 22:17:34 fenner Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -62,12 +62,6 @@ rt6_print(register const u_char *bp, register const u_char *bp2) /* 'ep' points to the end of available data. */ ep = snapend; -#if 0 - printf("%s > %s: ", - ip6addr_string(&ip->ip6_src), - ip6addr_string(&ip->ip6_dst)); -#endif - TCHECK(dp->ip6r_segleft); printf("srcrt (len=%d", dp->ip6r_len); /*)*/ diff --git a/contrib/tcpdump/print-rx.c b/contrib/tcpdump/print-rx.c index af3cf1b..530965d 100644 --- a/contrib/tcpdump/print-rx.c +++ b/contrib/tcpdump/print-rx.c @@ -1,4 +1,26 @@ /* + * Copyright: (c) 2000 United States Government as represented by the + * Secretary of the Navy. 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. 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. + */ +/* * This code unmangles RX packets. RX is the mutant form of RPC that AFS * uses to communicate between clients and servers. * @@ -8,12 +30,11 @@ * Bah. If I never look at rx_packet.h again, it will be too soon. * * Ken Hornstein <kenh@cmf.nrl.navy.mil> - * */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-rx.c,v 1.20.2.1 2001/07/09 01:40:59 fenner Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-rx.c,v 1.27 2001/10/20 07:41:55 itojun Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -35,9 +56,6 @@ static const char rcsid[] = #include "addrtoname.h" #include "extract.h" -#undef NOERROR /* Solaris sucks */ -#include <arpa/nameser.h> - #include "rx.h" #include "ip.h" @@ -56,12 +74,18 @@ static struct tok rx_types[] = { { 0, NULL }, }; -static struct tok rx_flags[] = { - { RX_CLIENT_INITIATED, "client-init" }, - { RX_REQUEST_ACK, "req-ack" }, - { RX_LAST_PACKET, "last-pckt" }, - { RX_MORE_PACKETS, "more-pckts" }, - { RX_FREE_PACKET, "free-pckt" } +static struct double_tok { + int flag; /* Rx flag */ + int packetType; /* Packet type */ + char *s; /* Flag string */ +} rx_flags[] = { + { RX_CLIENT_INITIATED, 0, "client-init" }, + { RX_REQUEST_ACK, 0, "req-ack" }, + { RX_LAST_PACKET, 0, "last-pckt" }, + { RX_MORE_PACKETS, 0, "more-pckts" }, + { RX_FREE_PACKET, 0, "free-pckt" }, + { RX_SLOW_START_OK, RX_PACKET_TYPE_ACK, "slow-start" }, + { RX_JUMBO_PACKET, RX_PACKET_TYPE_DATA, "jumbogram" } }; static struct tok fs_req[] = { @@ -99,6 +123,7 @@ static struct tok fs_req[] = { { 161, "dfs-lookup" }, { 162, "dfs-flushcps" }, { 163, "dfs-symlink" }, + { 220, "residency" }, { 0, NULL }, }; @@ -114,6 +139,10 @@ static struct tok cb_req[] = { { 212, "whoareyou" }, { 213, "initcb3" }, { 214, "probeuuid" }, + { 215, "getsrvprefs" }, + { 216, "getcellservdb" }, + { 217, "getlocalcell" }, + { 218, "getcacheconf" }, { 0, NULL }, }; @@ -139,6 +168,7 @@ static struct tok pt_req[] = { { 518, "get-cps2" }, { 519, "get-host-cps" }, { 520, "update-entry" }, + { 521, "list-entries" }, { 0, NULL }, }; @@ -176,6 +206,7 @@ static struct tok vldb_req[] = { { 531, "linked-list-u" }, { 532, "regaddr" }, { 533, "get-addrs-u" }, + { 534, "list-attrib-n2" }, { 0, NULL }, }; @@ -270,6 +301,8 @@ static struct tok bos_req[] = { { 112, "start-bozo-log" }, { 113, "wait-all" }, { 114, "get-instance-strings" }, + { 115, "get-restricted" }, + { 116, "set-restricted" }, { 0, NULL }, }; @@ -439,7 +472,9 @@ rx_print(register const u_char *bp, int length, int sport, int dport, if (vflag > 1) for (i = 0; i < NUM_RX_FLAGS; i++) { - if (rxh->flags & rx_flags[i].v) { + if (rxh->flags & rx_flags[i].flag && + (!rx_flags[i].packetType || + rxh->type == rx_flags[i].packetType)) { if (!firstflag) { firstflag = 1; printf(" "); @@ -638,7 +673,7 @@ rx_cache_find(const struct rx_header *rxh, const struct ip *ip, int sport, #define STROUT(MAX) { unsigned int i; \ TCHECK2(bp[0], sizeof(int32_t)); \ i = EXTRACT_32BITS(bp); \ - if (i > MAX) \ + if (i > (MAX)) \ goto trunc; \ bp += sizeof(int32_t); \ printf(" \""); \ @@ -721,14 +756,17 @@ rx_cache_find(const struct rx_header *rxh, const struct ip *ip, int sport, */ #define VECOUT(MAX) { char *sp; \ + char s[AFSNAMEMAX]; \ int k; \ - TCHECK2(bp[0], MAX * sizeof(int32_t)); \ + if ((MAX) + 1 > sizeof(s)) \ + goto trunc; \ + TCHECK2(bp[0], (MAX) * sizeof(int32_t)); \ sp = s; \ - for (k = 0; k < MAX; k++) { \ + for (k = 0; k < (MAX); k++) { \ *sp++ = (char) EXTRACT_32BITS(bp); \ bp += sizeof(int32_t); \ } \ - s[MAX] = '\0'; \ + s[(MAX)] = '\0'; \ printf(" \""); \ fn_print(s, NULL); \ printf("\""); \ @@ -812,7 +850,6 @@ fs_print(register const u_char *bp, int length) { int fs_op; unsigned long i; - char s[AFSNAMEMAX]; if (length <= sizeof(struct rx_header)) return; @@ -963,7 +1000,6 @@ static void fs_reply_print(register const u_char *bp, int length, int32_t opcode) { unsigned long i; - char s[AFSNAMEMAX]; struct rx_header *rxh; if (length <= sizeof(struct rx_header)) @@ -1259,7 +1295,6 @@ static void prot_print(register const u_char *bp, int length) { unsigned long i; - char s[AFSNAMEMAX]; int pt_op; if (length <= sizeof(struct rx_header)) @@ -1403,7 +1438,6 @@ prot_reply_print(register const u_char *bp, int length, int32_t opcode) { struct rx_header *rxh; unsigned long i; - char s[AFSNAMEMAX]; if (length < sizeof(struct rx_header)) return; @@ -1516,7 +1550,6 @@ vldb_print(register const u_char *bp, int length) { int vldb_op; unsigned long i; - char s[AFSNAMEMAX]; if (length <= sizeof(struct rx_header)) return; @@ -1610,7 +1643,6 @@ vldb_reply_print(register const u_char *bp, int length, int32_t opcode) { struct rx_header *rxh; unsigned long i; - char s[AFSNAMEMAX]; if (length < sizeof(struct rx_header)) return; @@ -1797,7 +1829,6 @@ static void kauth_print(register const u_char *bp, int length) { int kauth_op; - char s[AFSNAMEMAX]; if (length <= sizeof(struct rx_header)) return; @@ -2024,7 +2055,6 @@ static void bos_print(register const u_char *bp, int length) { int bos_op; - char s[BOSNAMEMAX]; if (length <= sizeof(struct rx_header)) return; diff --git a/contrib/tcpdump/print-sctp.c b/contrib/tcpdump/print-sctp.c new file mode 100644 index 0000000..8bf45ca --- /dev/null +++ b/contrib/tcpdump/print-sctp.c @@ -0,0 +1,351 @@ +/* Copyright (c) 2001 NETLAB, Temple University + * Copyright (c) 2001 Protocol Engineering Lab, University of Delaware + * + * Jerry Heinz <gheinz@astro.temple.edu> + * John Fiore <jfiore@joda.cis.temple.edu> + * Armando L. Caro Jr. <acaro@cis.udel.edu> + * + * 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. 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 lint +static const char rcsid[] = +"@(#) $Header: /tcpdump/master/tcpdump/print-sctp.c,v 1.7 2001/12/12 07:16:40 guy Exp $ (NETLAB/PEL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/socket.h> + +#include <unistd.h> +#include "sctpHeader.h" +#include "sctpConstants.h" +#include <assert.h> + +#include <netinet/in.h> + +#include <stdio.h> +#include <string.h> + +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" /* must come after interface.h */ +#include "ip.h" +#ifdef INET6 +#include "ip6.h" +#endif + +void sctp_print(const u_char *bp, /* beginning of sctp packet */ + const u_char *bp2, /* beginning of enclosing */ + u_int sctpPacketLength) /* ip packet */ +{ + const struct sctpHeader *sctpPktHdr; + const struct ip *ip; +#ifdef INET6 + const struct ip6_hdr *ip6; +#endif + const u_char *cp; + void *endPacketPtr; + u_short sourcePort, destPort; + int chunkCount; + struct sctpChunkDesc *chunkDescPtr; + void *nextChunk; + + sctpPktHdr = (struct sctpHeader*) bp; + endPacketPtr = ((u_char*)((u_char*)sctpPktHdr+sctpPacketLength)); + + if( (u_long) endPacketPtr > (u_long) snapend) + endPacketPtr = (void *) snapend; + ip = (struct ip *)bp2; +#ifdef INET6 + if (IP_V(ip) == 6) + ip6 = (struct ip6_hdr *)bp2; + else + ip6 = NULL; +#endif /*INET6*/ + cp = (u_char *)(sctpPktHdr + 1); + if (cp > snapend) + { + printf("[|sctp]"); + return; + } + + if (sctpPacketLength < sizeof(struct sctpHeader)) + { + (void)printf("truncated-sctp - %ld bytes missing!", + (long)sctpPacketLength-sizeof(struct sctpHeader)); + return; + } + + /* sctpPacketLength -= sizeof(struct sctpHeader); packet length */ + /* is now only as long as the payload */ + + sourcePort = ntohs(sctpPktHdr->source); + destPort = ntohs(sctpPktHdr->destination); + +#ifdef INET6 + if (ip6) { + if (ip6->ip6_nxt == IPPROTO_SCTP) { + (void)printf("%s.%d > %s.%d: sctp", + ip6addr_string(&ip6->ip6_src), + sourcePort, + ip6addr_string(&ip6->ip6_dst), + destPort); + } else { + (void)printf("%d > %d: sctp", + sourcePort, destPort); + } + } else +#endif /*INET6*/ + { + if (ip->ip_p == IPPROTO_SCTP) { + (void)printf("%s.%d > %s.%d: sctp", + ipaddr_string(&ip->ip_src), + sourcePort, + ipaddr_string(&ip->ip_dst), + destPort); + } else { + (void)printf("%d > %d: sctp", + sourcePort, destPort); + } + } + fflush(stdout); + + if (vflag < 2) + return; + + /* cycle through all chunks, printing information on each one */ + for (chunkCount = 0, + chunkDescPtr = (struct sctpChunkDesc *) ( (u_char*) sctpPktHdr + + sizeof(struct sctpHeader)); + chunkDescPtr != NULL && + ( (void *) ((u_char *) chunkDescPtr + sizeof(struct sctpChunkDesc)) + <= endPacketPtr); + + chunkDescPtr = (struct sctpChunkDesc *) nextChunk, chunkCount++) + { + u_short align; + u_char *chunkEnd; + + chunkEnd = ((u_char*)chunkDescPtr + ntohs(chunkDescPtr->chunkLength)); + + align=ntohs(chunkDescPtr->chunkLength) % 4; + if (align != 0) + align = 4 - align; + + nextChunk = (void *) (chunkEnd + align); + + printf("\n\t%d) ", chunkCount+1); + switch (chunkDescPtr->chunkID) + { + case SCTP_DATA : + { + struct sctpDataPart *dataHdrPtr; + + printf("[DATA] "); + + if ((chunkDescPtr->chunkFlg & SCTP_DATA_UNORDERED) + == SCTP_DATA_UNORDERED) + printf("(U)"); + + if ((chunkDescPtr->chunkFlg & SCTP_DATA_FIRST_FRAG) + == SCTP_DATA_FIRST_FRAG) + printf("(B)"); + + if ((chunkDescPtr->chunkFlg & SCTP_DATA_LAST_FRAG) + == SCTP_DATA_LAST_FRAG) + printf("(E)"); + + if( ((chunkDescPtr->chunkFlg & SCTP_DATA_UNORDERED) + == SCTP_DATA_UNORDERED) + || + ((chunkDescPtr->chunkFlg & SCTP_DATA_FIRST_FRAG) + == SCTP_DATA_FIRST_FRAG) + || + ((chunkDescPtr->chunkFlg & SCTP_DATA_LAST_FRAG) + == SCTP_DATA_LAST_FRAG) ) + printf(" "); + + dataHdrPtr=(struct sctpDataPart*)(chunkDescPtr+1); + + printf("[TSN: %u] ", (u_int32_t)ntohl(dataHdrPtr->TSN)); + printf("[SID: %u] ", ntohs(dataHdrPtr->streamId)); + printf("[SSEQ %u] ", ntohs(dataHdrPtr->sequence)); + printf("[PPID 0x%x] ", (u_int32_t)ntohl(dataHdrPtr->payloadtype)); + fflush(stdout); + + if (vflag) /* if verbose output is specified */ + { /* at the command line */ + char *payloadPtr; + + printf("[Payload"); + + if (!xflag && !qflag) { + payloadPtr = (char *) (++dataHdrPtr); + printf(":"); + default_print(payloadPtr, + htons(chunkDescPtr->chunkLength)-1 - + sizeof(struct sctpDataPart)-sizeof(struct sctpChunkDesc)); + } else + printf("]"); + } + break; + } + case SCTP_INITIATION : + { + struct sctpInitiation *init; + + printf("[INIT] "); + init=(struct sctpInitiation*)(chunkDescPtr+1); + printf("[init tag: %u] ", (u_int32_t)ntohl(init->initTag)); + printf("[rwnd: %u] ", (u_int32_t)ntohl(init->rcvWindowCredit)); + printf("[OS: %u] ", ntohs(init->NumPreopenStreams)); + printf("[MIS: %u] ", ntohs(init->MaxInboundStreams)); + printf("[init TSN: %u] ", (u_int32_t)ntohl(init->initialTSN)); + +#if(0) /* ALC you can add code for optional params here */ + if( (init+1) < chunkEnd ) + printf(" @@@@@ UNFINISHED @@@@@@%s\n", + "Optional params present, but not printed."); +#endif + break; + } + case SCTP_INITIATION_ACK : + { + struct sctpInitiation *init; + + printf("[INIT ACK] "); + init=(struct sctpInitiation*)(chunkDescPtr+1); + printf("[init tag: %u] ", (u_int32_t)ntohl(init->initTag)); + printf("[rwnd: %u] ", (u_int32_t)ntohl(init->rcvWindowCredit)); + printf("[OS: %u] ", ntohs(init->NumPreopenStreams)); + printf("[MIS: %u] ", ntohs(init->MaxInboundStreams)); + printf("[init TSN: %u] ", (u_int32_t)ntohl(init->initialTSN)); + +#if(0) /* ALC you can add code for optional params here */ + if( (init+1) < chunkEnd ) + printf(" @@@@@ UNFINISHED @@@@@@%s\n", + "Optional params present, but not printed."); +#endif + break; + } + case SCTP_SELECTIVE_ACK: + { + struct sctpSelectiveAck *sack; + struct sctpSelectiveFrag *frag; + int fragNo, tsnNo; + u_long *dupTSN; + + printf("[SACK] "); + sack=(struct sctpSelectiveAck*)(chunkDescPtr+1); + printf("[cum ack %u] ", (u_int32_t)ntohl(sack->highestConseqTSN)); + printf("[a_rwnd %u] ", (u_int32_t)ntohl(sack->updatedRwnd)); + printf("[#gap acks %u] ", ntohs(sack->numberOfdesc)); + printf("[#dup tsns %u] ", ntohs(sack->numDupTsns)); + + + /* print gaps */ + for (frag = ( (struct sctpSelectiveFrag *) + ((struct sctpSelectiveAck *) sack+1)), + fragNo=0; + (void *)frag < nextChunk && fragNo < ntohs(sack->numberOfdesc); + frag++, fragNo++) + printf("\n\t\t[gap ack block #%d: start = %u, end = %u] ", + fragNo+1, + (u_int32_t)(ntohl(sack->highestConseqTSN) + ntohs(frag->fragmentStart)), + (u_int32_t)(ntohl(sack->highestConseqTSN) + ntohs(frag->fragmentEnd))); + + + /* print duplicate TSNs */ + for (dupTSN = (u_long*)frag, tsnNo=0; + (void *) dupTSN < nextChunk && tsnNo<ntohs(sack->numDupTsns); + dupTSN++, tsnNo++) + printf("\n\t\t[dup TSN #%u: %u] ", tsnNo+1, + (u_int32_t)ntohl(*dupTSN)); + + break; + } + case SCTP_HEARTBEAT_REQUEST : + { + struct sctpHBsender *hb; + + hb=(struct sctpHBsender*)chunkDescPtr; + + printf("[HB REQ] "); + + break; + } + case SCTP_HEARTBEAT_ACK : + printf("[HB ACK] "); + break; + case SCTP_ABORT_ASSOCIATION : + printf("[ABORT] "); + break; + case SCTP_SHUTDOWN : + printf("[SHUTDOWN] "); + break; + case SCTP_SHUTDOWN_ACK : + printf("[SHUTDOWN ACK] "); + break; + case SCTP_OPERATION_ERR : + printf("[OP ERR] "); + break; + case SCTP_COOKIE_ECHO : + printf("[COOKIE ECHO] "); + break; + case SCTP_COOKIE_ACK : + printf("[COOKIE ACK] "); + break; + case SCTP_ECN_ECHO : + printf("[ECN ECHO] "); + break; + case SCTP_ECN_CWR : + printf("[ECN CWR] "); + break; + case SCTP_SHUTDOWN_COMPLETE : + printf("[SHUTDOWN COMPLETE] "); + break; + case SCTP_FORWARD_CUM_TSN : + printf("[FOR CUM TSN] "); + break; + case SCTP_RELIABLE_CNTL : + printf("[REL CTRL] "); + break; + case SCTP_RELIABLE_CNTL_ACK : + printf("[REL CTRL ACK] "); + break; + default : + printf("[Unknown chunk type: 0x%x]", chunkDescPtr->chunkID); + return; + } + } +} diff --git a/contrib/tcpdump/print-sl.c b/contrib/tcpdump/print-sl.c index c89a9a3..3448287 100644 --- a/contrib/tcpdump/print-sl.c +++ b/contrib/tcpdump/print-sl.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-sl.c,v 1.56 2000/10/10 05:06:10 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-sl.c,v 1.57 2001/07/05 18:54:17 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -60,6 +60,7 @@ sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) register u_int length = h->len; register const struct ip *ip; + ++infodelay; ts_print(&h->ts); if (caplen < SLIP_HDRLEN) { @@ -98,6 +99,9 @@ sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) default_print((u_char *)ip, caplen - SLIP_HDRLEN); out: putchar('\n'); + --infodelay; + if (infoprint) + info(0); } @@ -108,6 +112,7 @@ sl_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) register u_int length = h->len; register const struct ip *ip; + ++infodelay; ts_print(&h->ts); if (caplen < SLIP_HDRLEN) { @@ -137,6 +142,9 @@ sl_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) default_print((u_char *)ip, caplen - SLIP_HDRLEN); out: putchar('\n'); + --infodelay; + if (infoprint) + info(0); } static void diff --git a/contrib/tcpdump/print-sll.c b/contrib/tcpdump/print-sll.c index 8f2803a..0b284c8 100644 --- a/contrib/tcpdump/print-sll.c +++ b/contrib/tcpdump/print-sll.c @@ -20,7 +20,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-sll.c,v 1.3 2000/12/23 20:49:34 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-sll.c,v 1.6 2001/07/05 18:54:18 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -47,9 +47,6 @@ struct rtentry; #include "ether.h" #include "sll.h" -const u_char *packetp; -const u_char *snapend; - static inline void sll_print(register const struct sll_header *sllp, u_int length) { @@ -113,6 +110,7 @@ sll_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) u_short ether_type; u_short extracted_ethertype; + ++infodelay; ts_print(&h->ts); if (caplen < SLL_HDR_LEN) { @@ -200,6 +198,13 @@ sll_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) */ switch (ether_type) { + case LINUX_SLL_P_802_3: + /* + * Ethernet_802.3 IPX frame. + */ + ipx_print(p, length); + break; + case LINUX_SLL_P_802_2: /* * 802.2. @@ -235,4 +240,7 @@ sll_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) default_print(p, caplen); out: putchar('\n'); + --infodelay; + if (infoprint) + info(0); } diff --git a/contrib/tcpdump/print-smb.c b/contrib/tcpdump/print-smb.c index e5a3da5..eb7df57 100644 --- a/contrib/tcpdump/print-smb.c +++ b/contrib/tcpdump/print-smb.c @@ -1,9 +1,10 @@ -/* - Copyright (C) Andrew Tridgell 1995-1999 - - This software may be distributed either under the terms of the - BSD-style license that accompanies tcpdump or the GNU GPL version 2 - or later */ +/* + * Copyright (C) Andrew Tridgell 1995-1999 + * + * This software may be distributed either under the terms of the + * BSD-style license that accompanies tcpdump or the GNU GPL version 2 + * or later + */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -11,7 +12,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-smb.c,v 1.7 2000/12/05 06:42:47 guy Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-smb.c,v 1.20 2002/01/17 04:38:29 guy Exp $"; #endif #include <stdio.h> @@ -19,1027 +20,1277 @@ static const char rcsid[] = #include <sys/types.h> #include "interface.h" +#include "extract.h" #include "smb.h" -static int request=0; +static int request = 0; -const uchar *startbuf=NULL; +const u_char *startbuf = NULL; -struct smbdescript -{ - char *req_f1; - char *req_f2; - char *rep_f1; - char *rep_f2; - void (*fn)(); /* sometimes (u_char *, u_char *, u_char *, u_char *) - and sometimes (u_char *, u_char *, int, int) */ +struct smbdescript { + const char *req_f1; + const char *req_f2; + const char *rep_f1; + const char *rep_f2; + void (*fn)(const u_char *, const u_char *, const u_char *, const u_char *); +}; + +struct smbdescriptint { + const char *req_f1; + const char *req_f2; + const char *rep_f1; + const char *rep_f2; + void (*fn)(const u_char *, const u_char *, int, int); }; struct smbfns { - int id; - char *name; - int flags; - struct smbdescript descript; + int id; + const char *name; + int flags; + struct smbdescript descript; }; -#define DEFDESCRIPT {NULL,NULL,NULL,NULL,NULL} - -#define FLG_CHAIN (1<<0) - -static struct smbfns *smbfind(int id,struct smbfns *list) +struct smbfnsint { - int sindex; - - for (sindex=0;list[sindex].name;sindex++) - if (list[sindex].id == id) return(&list[sindex]); + int id; + const char *name; + int flags; + struct smbdescriptint descript; +}; - return(&list[0]); -} +#define DEFDESCRIPT { NULL, NULL, NULL, NULL, NULL } -static void trans2_findfirst(uchar *param,uchar *data,int pcnt,int dcnt) -{ - char *fmt; - - if (request) { - fmt = "Attribute=[A]\nSearchCount=[d]\nFlags=[w]\nLevel=[dP5]\nFile=[S]\n"; - } else { - fmt = "Handle=[w]\nCount=[d]\nEOS=[w]\nEoffset=[d]\nLastNameOfs=[w]\n"; - } - - fdata(param,fmt,param+pcnt); - if (dcnt) { - printf("data:\n"); - print_data(data,dcnt); - } -} +#define FLG_CHAIN (1 << 0) -static void trans2_qfsinfo(uchar *param,uchar *data,int pcnt,int dcnt) +static struct smbfns * +smbfind(int id, struct smbfns *list) { - static int level=0; - char *fmt=""; - - if (request) { - level = SVAL(param,0); - fmt = "InfoLevel=[d]\n"; - fdata(param,fmt,param+pcnt); - } else { - switch (level) { - case 1: - fmt = "idFileSystem=[W]\nSectorUnit=[D]\nUnit=[D]\nAvail=[D]\nSectorSize=[d]\n"; - break; - case 2: - fmt = "CreationTime=[T2]VolNameLength=[B]\nVolumeLabel=[s12]\n"; - break; - case 0x105: - fmt = "Capabilities=[W]\nMaxFileLen=[D]\nVolNameLen=[D]\nVolume=[S]\n"; - break; - default: - fmt = "UnknownLevel\n"; - } - fdata(data,fmt,data+dcnt); - } - if (dcnt) { - printf("data:\n"); - print_data(data,dcnt); - } -} - -struct smbfns trans2_fns[] = { -{0,"TRANSACT2_OPEN",0, - {"Flags2=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]\nOFun=[w]\nSize=[D]\nRes=([w,w,w,w,w])\nPath=[S]",NULL, - "Handle=[d]\nAttrib=[A]\nTime=[T2]\nSize=[D]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nInode=[W]\nOffErr=[d]\n|EALength=[d]\n",NULL,NULL}}, + int sindex; -{1,"TRANSACT2_FINDFIRST",0, - {NULL,NULL,NULL,NULL,trans2_findfirst}}, + for (sindex = 0; list[sindex].name; sindex++) + if (list[sindex].id == id) + return(&list[sindex]); -{2,"TRANSACT2_FINDNEXT",0,DEFDESCRIPT}, - -{3,"TRANSACT2_QFSINFO",0, - {NULL,NULL,NULL,NULL,trans2_qfsinfo}}, + return(&list[0]); +} -{4,"TRANSACT2_SETFSINFO",0,DEFDESCRIPT}, -{5,"TRANSACT2_QPATHINFO",0,DEFDESCRIPT}, -{6,"TRANSACT2_SETPATHINFO",0,DEFDESCRIPT}, -{7,"TRANSACT2_QFILEINFO",0,DEFDESCRIPT}, -{8,"TRANSACT2_SETFILEINFO",0,DEFDESCRIPT}, -{9,"TRANSACT2_FSCTL",0,DEFDESCRIPT}, -{10,"TRANSACT2_IOCTL",0,DEFDESCRIPT}, -{11,"TRANSACT2_FINDNOTIFYFIRST",0,DEFDESCRIPT}, -{12,"TRANSACT2_FINDNOTIFYNEXT",0,DEFDESCRIPT}, -{13,"TRANSACT2_MKDIR",0,DEFDESCRIPT}, -{-1,NULL,0,DEFDESCRIPT}}; +static struct smbfnsint * +smbfindint(int id, struct smbfnsint *list) +{ + int sindex; + for (sindex = 0; list[sindex].name; sindex++) + if (list[sindex].id == id) + return(&list[sindex]); -static void print_trans2(uchar *words,uchar *dat,uchar *buf,uchar *maxbuf) -{ - static struct smbfns *fn = &trans2_fns[0]; - uchar *data,*param; - uchar *f1=NULL,*f2=NULL; - int pcnt,dcnt; - - if (request) { - fn = smbfind(SVAL(words+1,14*2),trans2_fns); - data = buf+SVAL(words+1,12*2); - param = buf+SVAL(words+1,10*2); - pcnt = SVAL(words+1,9*2); - dcnt = SVAL(words+1,11*2); - } else { - data = buf+SVAL(words+1,7*2); - param = buf+SVAL(words+1,4*2); - pcnt = SVAL(words+1,3*2); - dcnt = SVAL(words+1,6*2); - } - - printf("%s param_length=%d data_length=%d\n", - fn->name,pcnt,dcnt); - - if (request) { - if (CVAL(words,0) == 8) { - fdata(words+1,"Trans2Secondary\nTotParam=[d]\nTotData=[d]\nParamCnt=[d]\nParamOff=[d]\nParamDisp=[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nHandle=[d]\n",maxbuf); - return; - } else { - fdata(words+1,"TotParam=[d]\nTotData=[d]\nMaxParam=[d]\nMaxData=[d]\nMaxSetup=[d]\nFlags=[w]\nTimeOut=[D]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nDataCnt=[d]\nDataOff=[d]\nSetupCnt=[d]\n",words+1+14*2); - fdata(data+1,"TransactionName=[S]\n%",maxbuf); - } - f1 = fn->descript.req_f1; - f2 = fn->descript.req_f2; - } else { - if (CVAL(words,0) == 0) { - printf("Trans2Interim\n"); - return; - } else { - fdata(words+1,"TotParam=[d]\nTotData=[d]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nParamDisp[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nSetupCnt=[d]\n",words+1+10*2); - } - f1 = fn->descript.rep_f1; - f2 = fn->descript.rep_f2; - } - - if (fn->descript.fn) { - fn->descript.fn(param,data,pcnt,dcnt); - } else { - fdata(param,f1?f1:(uchar*)"Paramaters=\n",param+pcnt); - fdata(data,f2?f2:(uchar*)"Data=\n",data+dcnt); - } + return(&list[0]); } - -static void print_browse(uchar *param,int paramlen,const uchar *data,int datalen) +static void +trans2_findfirst(const u_char *param, const u_char *data, int pcnt, int dcnt) { - const uchar *maxbuf = data + datalen; - int command = CVAL(data,0); - - fdata(param,"BROWSE PACKET\n|Param ",param+paramlen); - - switch (command) { - case 0xF: - data = fdata(data,"BROWSE PACKET:\nType=[B] (LocalMasterAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",maxbuf); - break; - - case 0x1: - data = fdata(data,"BROWSE PACKET:\nType=[B] (HostAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",maxbuf); - break; - - case 0x2: - data = fdata(data,"BROWSE PACKET:\nType=[B] (AnnouncementRequest)\nFlags=[B]\nReplySystemName=[S]\n",maxbuf); - break; - - case 0xc: - data = fdata(data,"BROWSE PACKET:\nType=[B] (WorkgroupAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nCommentPointer=[W]\nServerName=[S]\n",maxbuf); - break; - - case 0x8: - data = fdata(data,"BROWSE PACKET:\nType=[B] (ElectionFrame)\nElectionVersion=[B]\nOSSummary=[W]\nUptime=[(W,W)]\nServerName=[S]\n",maxbuf); - break; - - case 0xb: - data = fdata(data,"BROWSE PACKET:\nType=[B] (BecomeBackupBrowser)\nName=[S]\n",maxbuf); - break; - - case 0x9: - data = fdata(data,"BROWSE PACKET:\nType=[B] (GetBackupList)\nListCount?=[B]\nToken?=[B]\n",maxbuf); - break; - - case 0xa: - data = fdata(data,"BROWSE PACKET:\nType=[B] (BackupListResponse)\nServerCount?=[B]\nToken?=[B]*Name=[S]\n",maxbuf); - break; - - case 0xd: - data = fdata(data,"BROWSE PACKET:\nType=[B] (MasterAnnouncement)\nMasterName=[S]\n",maxbuf); - break; - - case 0xe: - data = fdata(data,"BROWSE PACKET:\nType=[B] (ResetBrowser)\nOptions=[B]\n",maxbuf); - break; - - default: - data = fdata(data,"Unknown Browser Frame ",maxbuf); - break; - } -} + const char *fmt; + if (request) + fmt = "Attribute=[A]\nSearchCount=[d]\nFlags=[w]\nLevel=[dP5]\nFile=[S]\n"; + else + fmt = "Handle=[w]\nCount=[d]\nEOS=[w]\nEoffset=[d]\nLastNameOfs=[w]\n"; -static void print_ipc(uchar *param,int paramlen,uchar *data,int datalen) -{ - if (paramlen) - fdata(param,"Command=[w]\nStr1=[S]\nStr2=[S]\n",param+paramlen); - if (datalen) - fdata(data,"IPC ",data+datalen); + smb_fdata(param, fmt, param + pcnt); + if (dcnt) { + printf("data:\n"); + print_data(data, dcnt); + } } - -static void print_trans(uchar *words,uchar *data1,uchar *buf,uchar *maxbuf) +static void +trans2_qfsinfo(const u_char *param, const u_char *data, int pcnt, int dcnt) { - uchar *f1,*f2,*f3,*f4; - uchar *data,*param; - int datalen,paramlen; - - if (request) { - paramlen = SVAL(words+1,9*2); - param = buf + SVAL(words+1,10*2); - datalen = SVAL(words+1,11*2); - data = buf + SVAL(words+1,12*2); - f1 = "TotParamCnt=[d] \nTotDataCnt=[d] \nMaxParmCnt=[d] \nMaxDataCnt=[d]\nMaxSCnt=[d] \nTransFlags=[w] \nRes1=[w] \nRes2=[w] \nRes3=[w]\nParamCnt=[d] \nParamOff=[d] \nDataCnt=[d] \nDataOff=[d] \nSUCnt=[d]\n"; - f2 = "|Name=[S]\n"; - f3 = "|Param "; - f4 = "|Data "; - } else { - paramlen = SVAL(words+1,3*2); - param = buf + SVAL(words+1,4*2); - datalen = SVAL(words+1,6*2); - data = buf + SVAL(words+1,7*2); - f1 = "TotParamCnt=[d] \nTotDataCnt=[d] \nRes1=[d]\nParamCnt=[d] \nParamOff=[d] \nRes2=[d] \nDataCnt=[d] \nDataOff=[d] \nRes3=[d]\nLsetup=[d]\n"; - f2 = "|Unknown "; - f3 = "|Param "; - f4 = "|Data "; - } - - fdata(words+1,f1,MIN(words+1+2*CVAL(words,0),maxbuf)); - fdata(data1+2,f2,maxbuf - (paramlen + datalen)); - - if (!strcmp(data1+2,"\\MAILSLOT\\BROWSE")) { - print_browse(param,paramlen,data,datalen); + static int level = 0; + const char *fmt=""; + + if (request) { + TCHECK2(*param, 2); + level = EXTRACT_LE_16BITS(param); + fmt = "InfoLevel=[d]\n"; + smb_fdata(param, fmt, param + pcnt); + } else { + switch (level) { + case 1: + fmt = "idFileSystem=[W]\nSectorUnit=[D]\nUnit=[D]\nAvail=[D]\nSectorSize=[d]\n"; + break; + case 2: + fmt = "CreationTime=[T2]VolNameLength=[B]\nVolumeLabel=[s12]\n"; + break; + case 0x105: + fmt = "Capabilities=[W]\nMaxFileLen=[D]\nVolNameLen=[D]\nVolume=[S]\n"; + break; + default: + fmt = "UnknownLevel\n"; + break; + } + smb_fdata(data, fmt, data + dcnt); + } + if (dcnt) { + printf("data:\n"); + print_data(data, dcnt); + } return; - } - - if (!strcmp(data1+2,"\\PIPE\\LANMAN")) { - print_ipc(param,paramlen,data,datalen); +trunc: + printf("[|SMB]"); return; - } - - if (paramlen) fdata(param,f3,MIN(param+paramlen,maxbuf)); - if (datalen) fdata(data,f4,MIN(data+datalen,maxbuf)); } +struct smbfnsint trans2_fns[] = { + { 0, "TRANSACT2_OPEN", 0, + { "Flags2=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]\nOFun=[w]\nSize=[D]\nRes=([w, w, w, w, w])\nPath=[S]", + NULL, + "Handle=[d]\nAttrib=[A]\nTime=[T2]\nSize=[D]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nInode=[W]\nOffErr=[d]\n|EALength=[d]\n", + NULL, NULL }}, + { 1, "TRANSACT2_FINDFIRST", 0, + { NULL, NULL, NULL, NULL, trans2_findfirst }}, + { 2, "TRANSACT2_FINDNEXT", 0, DEFDESCRIPT }, + { 3, "TRANSACT2_QFSINFO", 0, + { NULL, NULL, NULL, NULL, trans2_qfsinfo }}, + { 4, "TRANSACT2_SETFSINFO", 0, DEFDESCRIPT }, + { 5, "TRANSACT2_QPATHINFO", 0, DEFDESCRIPT }, + { 6, "TRANSACT2_SETPATHINFO", 0, DEFDESCRIPT }, + { 7, "TRANSACT2_QFILEINFO", 0, DEFDESCRIPT }, + { 8, "TRANSACT2_SETFILEINFO", 0, DEFDESCRIPT }, + { 9, "TRANSACT2_FSCTL", 0, DEFDESCRIPT }, + { 10, "TRANSACT2_IOCTL", 0, DEFDESCRIPT }, + { 11, "TRANSACT2_FINDNOTIFYFIRST", 0, DEFDESCRIPT }, + { 12, "TRANSACT2_FINDNOTIFYNEXT", 0, DEFDESCRIPT }, + { 13, "TRANSACT2_MKDIR", 0, DEFDESCRIPT }, + { -1, NULL, 0, DEFDESCRIPT } +}; -static void print_negprot(uchar *words,uchar *data,uchar *buf,uchar *maxbuf) +static void +print_trans2(const u_char *words, const u_char *dat, const u_char *buf, const u_char *maxbuf) { - uchar *f1=NULL,*f2=NULL; - - if (request) { - f2 = "*|Dialect=[Z]\n"; - } else { - if (CVAL(words,0) == 1) { - f1 = "Core Protocol\nDialectIndex=[d]"; - } else if (CVAL(words,0) == 17) { - f1 = "NT1 Protocol\nDialectIndex=[d]\nSecMode=[B]\nMaxMux=[d]\nNumVcs=[d]\nMaxBuffer=[D]\nRawSize=[D]\nSessionKey=[W]\nCapabilities=[W]\nServerTime=[T3]TimeZone=[d]\nCryptKey="; - } else if (CVAL(words,0) == 13) { - f1 = "Coreplus/Lanman1/Lanman2 Protocol\nDialectIndex=[d]\nSecMode=[w]\nMaxXMit=[d]\nMaxMux=[d]\nMaxVcs=[d]\nBlkMode=[w]\nSessionKey=[W]\nServerTime=[T1]TimeZone=[d]\nRes=[W]\nCryptKey="; + static struct smbfnsint *fn = &trans2_fns[0]; + const u_char *data, *param; + const u_char *w = words + 1; + const u_char *f1 = NULL, *f2 = NULL; + int pcnt, dcnt; + + TCHECK(words[0]); + if (request) { + TCHECK2(w[14 * 2], 2); + pcnt = EXTRACT_LE_16BITS(w + 9 * 2); + param = buf + EXTRACT_LE_16BITS(w + 10 * 2); + dcnt = EXTRACT_LE_16BITS(w + 11 * 2); + data = buf + EXTRACT_LE_16BITS(w + 12 * 2); + fn = smbfindint(EXTRACT_LE_16BITS(w + 14 * 2), trans2_fns); + } else { + if (words[0] == 0) { + printf("%s\n", fn->name); + printf("Trans2Interim\n"); + return; + } + TCHECK2(w[7 * 2], 2); + pcnt = EXTRACT_LE_16BITS(w + 3 * 2); + param = buf + EXTRACT_LE_16BITS(w + 4 * 2); + dcnt = EXTRACT_LE_16BITS(w + 6 * 2); + data = buf + EXTRACT_LE_16BITS(w + 7 * 2); } - } - - if (f1) - fdata(words+1,f1,MIN(words + 1 + CVAL(words,0)*2,maxbuf)); - else - print_data(words+1,MIN(CVAL(words,0)*2,PTR_DIFF(maxbuf,words+1))); - - if (f2) - fdata(data+2,f2,MIN(data + 2 + SVAL(data,0),maxbuf)); - else - print_data(data+2,MIN(SVAL(data,0),PTR_DIFF(maxbuf,data+2))); - -} -static void print_sesssetup(uchar *words,uchar *data,uchar *buf,uchar *maxbuf) -{ - int wcnt = CVAL(words,0); - uchar *f1=NULL,*f2=NULL; + printf("%s param_length=%d data_length=%d\n", fn->name, pcnt, dcnt); - if (request) { - if (wcnt==10) { - f1 = "Com2=[w]\nOff2=[d]\nBufSize=[d]\nMpxMax=[d]\nVcNum=[d]\nSessionKey=[W]\nPassLen=[d]\nCryptLen=[d]\nCryptOff=[d]\nPass&Name=\n"; + if (request) { + if (words[0] == 8) { + smb_fdata(words + 1, + "Trans2Secondary\nTotParam=[d]\nTotData=[d]\nParamCnt=[d]\nParamOff=[d]\nParamDisp=[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nHandle=[d]\n", + maxbuf); + return; + } else { + smb_fdata(words + 1, + "TotParam=[d]\nTotData=[d]\nMaxParam=[d]\nMaxData=[d]\nMaxSetup=[d]\nFlags=[w]\nTimeOut=[D]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nDataCnt=[d]\nDataOff=[d]\nSetupCnt=[d]\n", + words + 1 + 14 * 2); + smb_fdata(data + 1, "TransactionName=[S]\n%", maxbuf); + } + f1 = fn->descript.req_f1; + f2 = fn->descript.req_f2; } else { - f1 = "Com2=[B]\nRes1=[B]\nOff2=[d]\nMaxBuffer=[d]\nMaxMpx=[d]\nVcNumber=[d]\nSessionKey=[W]\nCaseInsensitivePasswordLength=[d]\nCaseSensitivePasswordLength=[d]\nRes=[W]\nCapabilities=[W]\nPass1&Pass2&Account&Domain&OS&LanMan=\n"; + smb_fdata(words + 1, + "TotParam=[d]\nTotData=[d]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nParamDisp[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nSetupCnt=[d]\n", + words + 1 + 10 * 2); + f1 = fn->descript.rep_f1; + f2 = fn->descript.rep_f2; } - } else { - if (CVAL(words,0) == 3) { - f1 = "Com2=[w]\nOff2=[d]\nAction=[w]\n"; - } else if (CVAL(words,0) == 13) { - f1 = "Com2=[B]\nRes=[B]\nOff2=[d]\nAction=[w]\n"; - f2 = "NativeOS=[S]\nNativeLanMan=[S]\nPrimaryDomain=[S]\n"; + + if (fn->descript.fn) + (*fn->descript.fn)(param, data, pcnt, dcnt); + else { + smb_fdata(param, f1 ? f1 : (u_char *)"Paramaters=\n", param + pcnt); + smb_fdata(data, f2 ? f2 : (u_char *)"Data=\n", data + dcnt); } - } - - if (f1) - fdata(words+1,f1,MIN(words + 1 + CVAL(words,0)*2,maxbuf)); - else - print_data(words+1,MIN(CVAL(words,0)*2,PTR_DIFF(maxbuf,words+1))); - - if (f2) - fdata(data+2,f2,MIN(data + 2 + SVAL(data,0),maxbuf)); - else - print_data(data+2,MIN(SVAL(data,0),PTR_DIFF(maxbuf,data+2))); + return; +trunc: + printf("[|SMB]"); + return; } -static struct smbfns smb_fns[] = +static void +print_browse(const u_char *param, int paramlen, const u_char *data, int datalen) { -{-1,"SMBunknown",0,DEFDESCRIPT}, + const u_char *maxbuf = data + datalen; + int command; -{SMBtcon,"SMBtcon",0, - {NULL,"Path=[Z]\nPassword=[Z]\nDevice=[Z]\n", - "MaxXmit=[d]\nTreeId=[d]\n",NULL, - NULL}}, + TCHECK(data[0]); + command = data[0]; + smb_fdata(param, "BROWSE PACKET\n|Param ", param+paramlen); -{SMBtdis,"SMBtdis",0,DEFDESCRIPT}, -{SMBexit,"SMBexit",0,DEFDESCRIPT}, -{SMBioctl,"SMBioctl",0,DEFDESCRIPT}, + switch (command) { + case 0xF: + data = smb_fdata(data, + "BROWSE PACKET:\nType=[B] (LocalMasterAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n", + maxbuf); + break; -{SMBecho,"SMBecho",0, - {"ReverbCount=[d]\n",NULL, - "SequenceNum=[d]\n",NULL, - NULL}}, + case 0x1: + data = smb_fdata(data, + "BROWSE PACKET:\nType=[B] (HostAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n", + maxbuf); + break; -{SMBulogoffX, "SMBulogoffX",FLG_CHAIN,DEFDESCRIPT}, + case 0x2: + data = smb_fdata(data, + "BROWSE PACKET:\nType=[B] (AnnouncementRequest)\nFlags=[B]\nReplySystemName=[S]\n", + maxbuf); + break; -{SMBgetatr,"SMBgetatr",0, - {NULL,"Path=[Z]\n", - "Attribute=[A]\nTime=[T2]Size=[D]\nRes=([w,w,w,w,w])\n",NULL, - NULL}}, + case 0xc: + data = smb_fdata(data, + "BROWSE PACKET:\nType=[B] (WorkgroupAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nCommentPointer=[W]\nServerName=[S]\n", + maxbuf); + break; -{SMBsetatr,"SMBsetatr",0, - {"Attribute=[A]\nTime=[T2]Res=([w,w,w,w,w])\n","Path=[Z]\n", - NULL,NULL,NULL}}, + case 0x8: + data = smb_fdata(data, + "BROWSE PACKET:\nType=[B] (ElectionFrame)\nElectionVersion=[B]\nOSSummary=[W]\nUptime=[(W, W)]\nServerName=[S]\n", + maxbuf); + break; -{SMBchkpth,"SMBchkpth",0, - {NULL,"Path=[Z]\n",NULL,NULL,NULL}}, + case 0xb: + data = smb_fdata(data, + "BROWSE PACKET:\nType=[B] (BecomeBackupBrowser)\nName=[S]\n", + maxbuf); + break; -{SMBsearch,"SMBsearch",0, -{"Count=[d]\nAttrib=[A]\n","Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\n", -"Count=[d]\n","BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",NULL}}, + case 0x9: + data = smb_fdata(data, + "BROWSE PACKET:\nType=[B] (GetBackupList)\nListCount?=[B]\nToken?=[B]\n", + maxbuf); + break; + case 0xa: + data = smb_fdata(data, + "BROWSE PACKET:\nType=[B] (BackupListResponse)\nServerCount?=[B]\nToken?=[B]*Name=[S]\n", + maxbuf); + break; -{SMBopen,"SMBopen",0, - {"Mode=[w]\nAttribute=[A]\n","Path=[Z]\n", - "Handle=[d]\nOAttrib=[A]\nTime=[T2]Size=[D]\nAccess=[w]\n",NULL, - NULL}}, + case 0xd: + data = smb_fdata(data, + "BROWSE PACKET:\nType=[B] (MasterAnnouncement)\nMasterName=[S]\n", + maxbuf); + break; -{SMBcreate,"SMBcreate",0, - {"Attrib=[A]\nTime=[T2]","Path=[Z]\n", - "Handle=[d]\n",NULL, - NULL}}, + case 0xe: + data = smb_fdata(data, + "BROWSE PACKET:\nType=[B] (ResetBrowser)\nOptions=[B]\n", maxbuf); + break; -{SMBmknew,"SMBmknew",0, - {"Attrib=[A]\nTime=[T2]","Path=[Z]\n", - "Handle=[d]\n",NULL, - NULL}}, + default: + data = smb_fdata(data, "Unknown Browser Frame ", maxbuf); + break; + } + return; +trunc: + printf("[|SMB]"); + return; +} -{SMBunlink,"SMBunlink",0, - {"Attrib=[A]\n","Path=[Z]\n",NULL,NULL,NULL}}, -{SMBread,"SMBread",0, - {"Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n",NULL, - "Count=[d]\nRes=([w,w,w,w])\n",NULL,NULL}}, +static void +print_ipc(const u_char *param, int paramlen, const u_char *data, int datalen) +{ + if (paramlen) + smb_fdata(param, "Command=[w]\nStr1=[S]\nStr2=[S]\n", param + paramlen); + if (datalen) + smb_fdata(data, "IPC ", data + datalen); +} -{SMBwrite,"SMBwrite",0, - {"Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n",NULL, - "Count=[d]\n",NULL,NULL}}, -{SMBclose,"SMBclose",0, - {"Handle=[d]\nTime=[T2]",NULL,NULL,NULL,NULL}}, +static void +print_trans(const u_char *words, const u_char *data1, const u_char *buf, const u_char *maxbuf) +{ + const u_char *f1, *f2, *f3, *f4; + const u_char *data, *param; + const u_char *w = words + 1; + int datalen, paramlen; + + if (request) { + TCHECK2(w[12 * 2], 2); + paramlen = EXTRACT_LE_16BITS(w + 9 * 2); + param = buf + EXTRACT_LE_16BITS(w + 10 * 2); + datalen = EXTRACT_LE_16BITS(w + 11 * 2); + data = buf + EXTRACT_LE_16BITS(w + 12 * 2); + f1 = "TotParamCnt=[d] \nTotDataCnt=[d] \nMaxParmCnt=[d] \nMaxDataCnt=[d]\nMaxSCnt=[d] \nTransFlags=[w] \nRes1=[w] \nRes2=[w] \nRes3=[w]\nParamCnt=[d] \nParamOff=[d] \nDataCnt=[d] \nDataOff=[d] \nSUCnt=[d]\n"; + f2 = "|Name=[S]\n"; + f3 = "|Param "; + f4 = "|Data "; + } else { + TCHECK2(w[7 * 2], 2); + paramlen = EXTRACT_LE_16BITS(w + 3 * 2); + param = buf + EXTRACT_LE_16BITS(w + 4 * 2); + datalen = EXTRACT_LE_16BITS(w + 6 * 2); + data = buf + EXTRACT_LE_16BITS(w + 7 * 2); + f1 = "TotParamCnt=[d] \nTotDataCnt=[d] \nRes1=[d]\nParamCnt=[d] \nParamOff=[d] \nRes2=[d] \nDataCnt=[d] \nDataOff=[d] \nRes3=[d]\nLsetup=[d]\n"; + f2 = "|Unknown "; + f3 = "|Param "; + f4 = "|Data "; + } -{SMBmkdir,"SMBmkdir",0, - {NULL,"Path=[Z]\n",NULL,NULL,NULL}}, + smb_fdata(words + 1, f1, SMBMIN(words + 1 + 2 * words[0], maxbuf)); + smb_fdata(data1 + 2, f2, maxbuf - (paramlen + datalen)); -{SMBrmdir,"SMBrmdir",0, - {NULL,"Path=[Z]\n",NULL,NULL,NULL}}, + if (!strcmp(data1 + 2, "\\MAILSLOT\\BROWSE")) { + print_browse(param, paramlen, data, datalen); + return; + } -{SMBdskattr,"SMBdskattr",0, -{NULL,NULL, -"TotalUnits=[d]\nBlocksPerUnit=[d]\nBlockSize=[d]\nFreeUnits=[d]\nMedia=[w]\n", -NULL,NULL}}, + if (!strcmp(data1 + 2, "\\PIPE\\LANMAN")) { + print_ipc(param, paramlen, data, datalen); + return; + } -{SMBmv,"SMBmv",0, - {"Attrib=[A]\n","OldPath=[Z]\nNewPath=[Z]\n",NULL,NULL,NULL}}, + if (paramlen) + smb_fdata(param, f3, SMBMIN(param + paramlen, maxbuf)); + if (datalen) + smb_fdata(data, f4, SMBMIN(data + datalen, maxbuf)); + return; +trunc: + printf("[|SMB]"); + return; +} -/* this is a Pathworks specific call, allowing the - changing of the root path */ -{pSETDIR,"SMBsetdir",0, - {NULL,"Path=[Z]\n",NULL,NULL,NULL}}, -{SMBlseek,"SMBlseek",0, - {"Handle=[d]\nMode=[w]\nOffset=[D]\n","Offset=[D]\n",NULL,NULL}}, +static void +print_negprot(const u_char *words, const u_char *data, const u_char *buf, const u_char *maxbuf) +{ + u_char *f1 = NULL, *f2 = NULL; + + TCHECK(words[0]); + if (request) + f2 = "*|Dialect=[Z]\n"; + else { + if (words[0] == 1) + f1 = "Core Protocol\nDialectIndex=[d]"; + else if (words[0] == 17) + f1 = "NT1 Protocol\nDialectIndex=[d]\nSecMode=[B]\nMaxMux=[d]\nNumVcs=[d]\nMaxBuffer=[D]\nRawSize=[D]\nSessionKey=[W]\nCapabilities=[W]\nServerTime=[T3]TimeZone=[d]\nCryptKey="; + else if (words[0] == 13) + f1 = "Coreplus/Lanman1/Lanman2 Protocol\nDialectIndex=[d]\nSecMode=[w]\nMaxXMit=[d]\nMaxMux=[d]\nMaxVcs=[d]\nBlkMode=[w]\nSessionKey=[W]\nServerTime=[T1]TimeZone=[d]\nRes=[W]\nCryptKey="; + } -{SMBflush,"SMBflush",0, - {"Handle=[d]\n",NULL,NULL,NULL,NULL}}, + if (f1) + smb_fdata(words + 1, f1, SMBMIN(words + 1 + words[0] * 2, maxbuf)); + else + print_data(words + 1, SMBMIN(words[0] * 2, + PTR_DIFF(maxbuf, words + 1))); -{SMBsplopen,"SMBsplopen",0, - {"SetupLen=[d]\nMode=[w]\n","Ident=[Z]\n","Handle=[d]\n",NULL,NULL}}, + TCHECK2(*data, 2); + if (f2) + smb_fdata(data + 2, f2, SMBMIN(data + 2 + EXTRACT_LE_16BITS(data), maxbuf)); + else + print_data(data + 2, SMBMIN(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2))); + return; +trunc: + printf("[|SMB]"); + return; +} -{SMBsplclose,"SMBsplclose",0, - {"Handle=[d]\n",NULL,NULL,NULL,NULL}}, +static void +print_sesssetup(const u_char *words, const u_char *data, const u_char *buf, const u_char *maxbuf) +{ + int wcnt; + u_char *f1 = NULL, *f2 = NULL; + + TCHECK(words[0]); + wcnt = words[0]; + if (request) { + if (wcnt == 10) + f1 = "Com2=[w]\nOff2=[d]\nBufSize=[d]\nMpxMax=[d]\nVcNum=[d]\nSessionKey=[W]\nPassLen=[d]\nCryptLen=[d]\nCryptOff=[d]\nPass&Name=\n"; + else + f1 = "Com2=[B]\nRes1=[B]\nOff2=[d]\nMaxBuffer=[d]\nMaxMpx=[d]\nVcNumber=[d]\nSessionKey=[W]\nCaseInsensitivePasswordLength=[d]\nCaseSensitivePasswordLength=[d]\nRes=[W]\nCapabilities=[W]\nPass1&Pass2&Account&Domain&OS&LanMan=\n"; + } else { + if (words[0] == 3) { + f1 = "Com2=[w]\nOff2=[d]\nAction=[w]\n"; + } else if (words[0] == 13) { + f1 = "Com2=[B]\nRes=[B]\nOff2=[d]\nAction=[w]\n"; + f2 = "NativeOS=[S]\nNativeLanMan=[S]\nPrimaryDomain=[S]\n"; + } + } -{SMBsplretq,"SMBsplretq",0, - {"MaxCount=[d]\nStartIndex=[d]\n",NULL, - "Count=[d]\nIndex=[d]\n", - "*Time=[T2]Status=[B]\nJobID=[d]\nSize=[D]\nRes=[B]Name=[s16]\n", - NULL}}, + if (f1) + smb_fdata(words + 1, f1, SMBMIN(words + 1 + words[0] * 2, maxbuf)); + else + print_data(words + 1, SMBMIN(words[0] * 2, + PTR_DIFF(maxbuf, words + 1))); -{SMBsplwr,"SMBsplwr",0, - {"Handle=[d]\n",NULL,NULL,NULL,NULL}}, + TCHECK2(*data, 2); + if (f2) + smb_fdata(data + 2, f2, SMBMIN(data + 2 + EXTRACT_LE_16BITS(data), maxbuf)); + else + print_data(data + 2, SMBMIN(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2))); + return; +trunc: + printf("[|SMB]"); + return; +} + + +static struct smbfns smb_fns[] = { + { -1, "SMBunknown", 0, DEFDESCRIPT }, + + { SMBtcon, "SMBtcon", 0, + { NULL, "Path=[Z]\nPassword=[Z]\nDevice=[Z]\n", + "MaxXmit=[d]\nTreeId=[d]\n", NULL, + NULL } }, -{SMBlock,"SMBlock",0, - {"Handle=[d]\nCount=[D]\nOffset=[D]\n",NULL,NULL,NULL,NULL}}, + { SMBtdis, "SMBtdis", 0, DEFDESCRIPT }, + { SMBexit, "SMBexit", 0, DEFDESCRIPT }, + { SMBioctl, "SMBioctl", 0, DEFDESCRIPT }, -{SMBunlock,"SMBunlock",0, - {"Handle=[d]\nCount=[D]\nOffset=[D]\n",NULL,NULL,NULL,NULL}}, + { SMBecho, "SMBecho", 0, + { "ReverbCount=[d]\n", NULL, + "SequenceNum=[d]\n", NULL, + NULL } }, -/* CORE+ PROTOCOL FOLLOWS */ + { SMBulogoffX, "SMBulogoffX", FLG_CHAIN, DEFDESCRIPT }, -{SMBreadbraw,"SMBreadbraw",0, -{"Handle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nRes=[d]\n", - NULL,NULL,NULL,NULL}}, + { SMBgetatr, "SMBgetatr", 0, + { NULL, "Path=[Z]\n", + "Attribute=[A]\nTime=[T2]Size=[D]\nRes=([w,w,w,w,w])\n", NULL, + NULL } }, -{SMBwritebraw,"SMBwritebraw",0, -{"Handle=[d]\nTotalCount=[d]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\n|DataSize=[d]\nDataOff=[d]\n", -NULL,"WriteRawAck",NULL,NULL}}, + { SMBsetatr, "SMBsetatr", 0, + { "Attribute=[A]\nTime=[T2]Res=([w,w,w,w,w])\n", "Path=[Z]\n", + NULL, NULL, NULL } }, -{SMBwritec,"SMBwritec",0, - {NULL,NULL,"Count=[d]\n",NULL,NULL}}, + { SMBchkpth, "SMBchkpth", 0, + { NULL, "Path=[Z]\n", NULL, NULL, NULL } }, -{SMBwriteclose,"SMBwriteclose",0, - {"Handle=[d]\nCount=[d]\nOffset=[D]\nTime=[T2]Res=([w,w,w,w,w,w])",NULL, - "Count=[d]\n",NULL,NULL}}, + { SMBsearch, "SMBsearch", 0, + { "Count=[d]\nAttrib=[A]\n", + "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\n", + "Count=[d]\n", + "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n", + NULL } }, -{SMBlockread,"SMBlockread",0, - {"Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n",NULL, - "Count=[d]\nRes=([w,w,w,w])\n",NULL,NULL}}, + { SMBopen, "SMBopen", 0, + { "Mode=[w]\nAttribute=[A]\n", "Path=[Z]\n", + "Handle=[d]\nOAttrib=[A]\nTime=[T2]Size=[D]\nAccess=[w]\n", + NULL, NULL } }, -{SMBwriteunlock,"SMBwriteunlock",0, - {"Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n",NULL, - "Count=[d]\n",NULL,NULL}}, + { SMBcreate, "SMBcreate", 0, + { "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[d]\n", NULL, NULL } }, -{SMBreadBmpx,"SMBreadBmpx",0, -{"Handle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nRes=[w]\n", -NULL, -"Offset=[D]\nTotCount=[d]\nRemaining=[d]\nRes=([w,w])\nDataSize=[d]\nDataOff=[d]\n", -NULL,NULL}}, + { SMBmknew, "SMBmknew", 0, + { "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[d]\n", NULL, NULL } }, -{SMBwriteBmpx,"SMBwriteBmpx",0, -{"Handle=[d]\nTotCount=[d]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\nDataSize=[d]\nDataOff=[d]\n",NULL, -"Remaining=[d]\n",NULL,NULL}}, + { SMBunlink, "SMBunlink", 0, + { "Attrib=[A]\n", "Path=[Z]\n", NULL, NULL, NULL } }, -{SMBwriteBs,"SMBwriteBs",0, - {"Handle=[d]\nTotCount=[d]\nOffset=[D]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\n",NULL, - "Count=[d]\n",NULL,NULL}}, + { SMBread, "SMBread", 0, + { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL, + "Count=[d]\nRes=([w,w,w,w])\n", NULL, NULL } }, -{SMBsetattrE,"SMBsetattrE",0, - {"Handle=[d]\nCreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]",NULL, - NULL,NULL,NULL}}, + { SMBwrite, "SMBwrite", 0, + { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL, + "Count=[d]\n", NULL, NULL } }, -{SMBgetattrE,"SMBgetattrE",0, -{"Handle=[d]\n",NULL, - "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[D]\nAllocSize=[D]\nAttribute=[A]\n",NULL,NULL}}, + { SMBclose, "SMBclose", 0, + { "Handle=[d]\nTime=[T2]", NULL, NULL, NULL, NULL } }, -{SMBtranss,"SMBtranss",0,DEFDESCRIPT}, -{SMBioctls,"SMBioctls",0,DEFDESCRIPT}, + { SMBmkdir, "SMBmkdir", 0, + { NULL, "Path=[Z]\n", NULL, NULL, NULL } }, -{SMBcopy,"SMBcopy",0, - {"TreeID2=[d]\nOFun=[w]\nFlags=[w]\n","Path=[S]\nNewPath=[S]\n", - "CopyCount=[d]\n","|ErrStr=[S]\n",NULL}}, + { SMBrmdir, "SMBrmdir", 0, + { NULL, "Path=[Z]\n", NULL, NULL, NULL } }, -{SMBmove,"SMBmove",0, - {"TreeID2=[d]\nOFun=[w]\nFlags=[w]\n","Path=[S]\nNewPath=[S]\n", - "MoveCount=[d]\n","|ErrStr=[S]\n",NULL}}, + { SMBdskattr, "SMBdskattr", 0, + { NULL, NULL, + "TotalUnits=[d]\nBlocksPerUnit=[d]\nBlockSize=[d]\nFreeUnits=[d]\nMedia=[w]\n", + NULL, NULL } }, -{SMBopenX,"SMBopenX",FLG_CHAIN, -{"Com2=[w]\nOff2=[d]\nFlags=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]OFun=[w]\nSize=[D]\nTimeOut=[D]\nRes=[W]\n","Path=[S]\n", -"Com2=[w]\nOff2=[d]\nHandle=[d]\nAttrib=[A]\nTime=[T2]Size=[D]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nFileID=[W]\nRes=[w]\n",NULL,NULL}}, + { SMBmv, "SMBmv", 0, + { "Attrib=[A]\n", "OldPath=[Z]\nNewPath=[Z]\n", NULL, NULL, NULL } }, -{SMBreadX,"SMBreadX",FLG_CHAIN, -{"Com2=[w]\nOff2=[d]\nHandle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nCountLeft=[d]\n",NULL, -"Com2=[w]\nOff2=[d]\nRemaining=[d]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\nRes=([w,w,w,w])\n",NULL,NULL}}, + /* + * this is a Pathworks specific call, allowing the + * changing of the root path + */ + { pSETDIR, "SMBsetdir", 0, { NULL, "Path=[Z]\n", NULL, NULL, NULL } }, -{SMBwriteX,"SMBwriteX",FLG_CHAIN, -{"Com2=[w]\nOff2=[d]\nHandle=[d]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nCountLeft=[d]\nRes=[w]\nDataSize=[d]\nDataOff=[d]\n",NULL, -"Com2=[w]\nOff2=[d]\nCount=[d]\nRemaining=[d]\nRes=[W]\n",NULL,NULL}}, + { SMBlseek, "SMBlseek", 0, + { "Handle=[d]\nMode=[w]\nOffset=[D]\n", "Offset=[D]\n", NULL, NULL } }, -{SMBlockingX,"SMBlockingX",FLG_CHAIN, -{"Com2=[w]\nOff2=[d]\nHandle=[d]\nLockType=[w]\nTimeOut=[D]\nUnlockCount=[d]\nLockCount=[d]\n", -"*Process=[d]\nOffset=[D]\nLength=[D]\n", -"Com2=[w]\nOff2=[d]\n"}}, + { SMBflush, "SMBflush", 0, { "Handle=[d]\n", NULL, NULL, NULL, NULL } }, -{SMBffirst,"SMBffirst",0, -{"Count=[d]\nAttrib=[A]\n","Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n", -"Count=[d]\n","BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",NULL}}, + { SMBsplopen, "SMBsplopen", 0, + { "SetupLen=[d]\nMode=[w]\n", "Ident=[Z]\n", "Handle=[d]\n", + NULL, NULL } }, -{SMBfunique,"SMBfunique",0, -{"Count=[d]\nAttrib=[A]\n","Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n", -"Count=[d]\n","BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",NULL}}, + { SMBsplclose, "SMBsplclose", 0, + { "Handle=[d]\n", NULL, NULL, NULL, NULL } }, -{SMBfclose,"SMBfclose",0, -{"Count=[d]\nAttrib=[A]\n","Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n", -"Count=[d]\n","BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",NULL}}, + { SMBsplretq, "SMBsplretq", 0, + { "MaxCount=[d]\nStartIndex=[d]\n", NULL, + "Count=[d]\nIndex=[d]\n", + "*Time=[T2]Status=[B]\nJobID=[d]\nSize=[D]\nRes=[B]Name=[s16]\n", + NULL } }, + + { SMBsplwr, "SMBsplwr", 0, + { "Handle=[d]\n", NULL, NULL, NULL, NULL } }, + + { SMBlock, "SMBlock", 0, + { "Handle=[d]\nCount=[D]\nOffset=[D]\n", NULL, NULL, NULL, NULL } }, + + { SMBunlock, "SMBunlock", 0, + { "Handle=[d]\nCount=[D]\nOffset=[D]\n", NULL, NULL, NULL, NULL } }, + + /* CORE+ PROTOCOL FOLLOWS */ + + { SMBreadbraw, "SMBreadbraw", 0, + { "Handle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nRes=[d]\n", + NULL, NULL, NULL, NULL } }, + + { SMBwritebraw, "SMBwritebraw", 0, + { "Handle=[d]\nTotalCount=[d]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\n|DataSize=[d]\nDataOff=[d]\n", + NULL, "WriteRawAck", NULL, NULL } }, + + { SMBwritec, "SMBwritec", 0, + { NULL, NULL, "Count=[d]\n", NULL, NULL } }, + + { SMBwriteclose, "SMBwriteclose", 0, + { "Handle=[d]\nCount=[d]\nOffset=[D]\nTime=[T2]Res=([w,w,w,w,w,w])", + NULL, "Count=[d]\n", NULL, NULL } }, + + { SMBlockread, "SMBlockread", 0, + { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL, + "Count=[d]\nRes=([w,w,w,w])\n", NULL, NULL } }, -{SMBfindnclose, "SMBfindnclose", 0, - {"Handle=[d]\n",NULL,NULL,NULL,NULL}}, + { SMBwriteunlock, "SMBwriteunlock", 0, + { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL, + "Count=[d]\n", NULL, NULL } }, -{SMBfindclose, "SMBfindclose", 0, - {"Handle=[d]\n",NULL,NULL,NULL,NULL}}, + { SMBreadBmpx, "SMBreadBmpx", 0, + { "Handle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nRes=[w]\n", + NULL, + "Offset=[D]\nTotCount=[d]\nRemaining=[d]\nRes=([w,w])\nDataSize=[d]\nDataOff=[d]\n", + NULL, NULL } }, -{SMBsends,"SMBsends",0, - {NULL,"Source=[Z]\nDest=[Z]\n",NULL,NULL,NULL}}, + { SMBwriteBmpx, "SMBwriteBmpx", 0, + { "Handle=[d]\nTotCount=[d]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\nDataSize=[d]\nDataOff=[d]\n", NULL, + "Remaining=[d]\n", NULL, NULL } }, -{SMBsendstrt,"SMBsendstrt",0, - {NULL,"Source=[Z]\nDest=[Z]\n","GroupID=[d]\n",NULL,NULL}}, - -{SMBsendend,"SMBsendend",0, - {"GroupID=[d]\n",NULL,NULL,NULL,NULL}}, + { SMBwriteBs, "SMBwriteBs", 0, + { "Handle=[d]\nTotCount=[d]\nOffset=[D]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\n", + NULL, "Count=[d]\n", NULL, NULL } }, -{SMBsendtxt,"SMBsendtxt",0, - {"GroupID=[d]\n",NULL,NULL,NULL,NULL}}, + { SMBsetattrE, "SMBsetattrE", 0, + { "Handle=[d]\nCreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]", NULL, + NULL, NULL, NULL } }, -{SMBsendb,"SMBsendb",0, - {NULL,"Source=[Z]\nDest=[Z]\n",NULL,NULL,NULL}}, + { SMBgetattrE, "SMBgetattrE", 0, + { "Handle=[d]\n", NULL, + "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[D]\nAllocSize=[D]\nAttribute=[A]\n", + NULL, NULL } }, -{SMBfwdname,"SMBfwdname",0,DEFDESCRIPT}, -{SMBcancelf,"SMBcancelf",0,DEFDESCRIPT}, -{SMBgetmac,"SMBgetmac",0,DEFDESCRIPT}, + { SMBtranss, "SMBtranss", 0, DEFDESCRIPT }, + { SMBioctls, "SMBioctls", 0, DEFDESCRIPT }, -{SMBnegprot,"SMBnegprot",0, - {NULL,NULL,NULL,NULL,print_negprot}}, + { SMBcopy, "SMBcopy", 0, + { "TreeID2=[d]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n", + "CopyCount=[d]\n", "|ErrStr=[S]\n", NULL } }, -{SMBsesssetupX,"SMBsesssetupX",FLG_CHAIN, - {NULL,NULL,NULL,NULL,print_sesssetup}}, + { SMBmove, "SMBmove", 0, + { "TreeID2=[d]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n", + "MoveCount=[d]\n", "|ErrStr=[S]\n", NULL } }, -{SMBtconX,"SMBtconX",FLG_CHAIN, -{"Com2=[w]\nOff2=[d]\nFlags=[w]\nPassLen=[d]\nPasswd&Path&Device=\n",NULL, - "Com2=[w]\nOff2=[d]\n","ServiceType=[S]\n",NULL}}, + { SMBopenX, "SMBopenX", FLG_CHAIN, + { "Com2=[w]\nOff2=[d]\nFlags=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]OFun=[w]\nSize=[D]\nTimeOut=[D]\nRes=[W]\n", + "Path=[S]\n", + "Com2=[w]\nOff2=[d]\nHandle=[d]\nAttrib=[A]\nTime=[T2]Size=[D]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nFileID=[W]\nRes=[w]\n", + NULL, NULL } }, -{SMBtrans2, "SMBtrans2",0,{NULL,NULL,NULL,NULL,print_trans2}}, + { SMBreadX, "SMBreadX", FLG_CHAIN, + { "Com2=[w]\nOff2=[d]\nHandle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nCountLeft=[d]\n", + NULL, + "Com2=[w]\nOff2=[d]\nRemaining=[d]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\nRes=([w,w,w,w])\n", + NULL, NULL } }, -{SMBtranss2, "SMBtranss2", 0,DEFDESCRIPT}, -{SMBctemp,"SMBctemp",0,DEFDESCRIPT}, -{SMBreadBs,"SMBreadBs",0,DEFDESCRIPT}, -{SMBtrans,"SMBtrans",0,{NULL,NULL,NULL,NULL,print_trans}}, + { SMBwriteX, "SMBwriteX", FLG_CHAIN, + { "Com2=[w]\nOff2=[d]\nHandle=[d]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nCountLeft=[d]\nRes=[w]\nDataSize=[d]\nDataOff=[d]\n", + NULL, + "Com2=[w]\nOff2=[d]\nCount=[d]\nRemaining=[d]\nRes=[W]\n", + NULL, NULL } }, -{SMBnttrans,"SMBnttrans", 0, DEFDESCRIPT}, -{SMBnttranss,"SMBnttranss", 0, DEFDESCRIPT}, + { SMBlockingX, "SMBlockingX", FLG_CHAIN, + { "Com2=[w]\nOff2=[d]\nHandle=[d]\nLockType=[w]\nTimeOut=[D]\nUnlockCount=[d]\nLockCount=[d]\n", + "*Process=[d]\nOffset=[D]\nLength=[D]\n", + "Com2=[w]\nOff2=[d]\n", NULL, NULL } }, -{SMBntcreateX,"SMBntcreateX", FLG_CHAIN, -{"Com2=[w]\nOff2=[d]\nRes=[b]\nNameLen=[d]\nFlags=[W]\nRootDirectoryFid=[D]\nAccessMask=[W]\nAllocationSize=[L]\nExtFileAttributes=[W]\nShareAccess=[W]\nCreateDisposition=[W]\nCreateOptions=[W]\nImpersonationLevel=[W]\nSecurityFlags=[b]\n","Path=[S]\n", - "Com2=[w]\nOff2=[d]\nOplockLevel=[b]\nFid=[d]\nCreateAction=[W]\nCreateTime=[T3]LastAccessTime=[T3]LastWriteTime=[T3]ChangeTime=[T3]ExtFileAttributes=[W]\nAllocationSize=[L]\nEndOfFile=[L]\nFileType=[w]\nDeviceState=[w]\nDirectory=[b]\n", NULL}}, + { SMBffirst, "SMBffirst", 0, + { "Count=[d]\nAttrib=[A]\n", + "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n", + "Count=[d]\n", + "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n", + NULL } }, -{SMBntcancel,"SMBntcancel", 0, DEFDESCRIPT}, + { SMBfunique, "SMBfunique", 0, + { "Count=[d]\nAttrib=[A]\n", + "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n", + "Count=[d]\n", + "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n", + NULL } }, -{-1,NULL,0,DEFDESCRIPT}}; + { SMBfclose, "SMBfclose", 0, + { "Count=[d]\nAttrib=[A]\n", + "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n", + "Count=[d]\n", + "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n", + NULL } }, + + { SMBfindnclose, "SMBfindnclose", 0, + { "Handle=[d]\n", NULL, NULL, NULL, NULL } }, + + { SMBfindclose, "SMBfindclose", 0, + { "Handle=[d]\n", NULL, NULL, NULL, NULL } }, + + { SMBsends, "SMBsends", 0, + { NULL, "Source=[Z]\nDest=[Z]\n", NULL, NULL, NULL } }, + + { SMBsendstrt, "SMBsendstrt", 0, + { NULL, "Source=[Z]\nDest=[Z]\n", "GroupID=[d]\n", NULL, NULL } }, + + { SMBsendend, "SMBsendend", 0, + { "GroupID=[d]\n", NULL, NULL, NULL, NULL } }, + + { SMBsendtxt, "SMBsendtxt", 0, + { "GroupID=[d]\n", NULL, NULL, NULL, NULL } }, + + { SMBsendb, "SMBsendb", 0, + { NULL, "Source=[Z]\nDest=[Z]\n", NULL, NULL, NULL } }, + + { SMBfwdname, "SMBfwdname", 0, DEFDESCRIPT }, + { SMBcancelf, "SMBcancelf", 0, DEFDESCRIPT }, + { SMBgetmac, "SMBgetmac", 0, DEFDESCRIPT }, + + { SMBnegprot, "SMBnegprot", 0, + { NULL, NULL, NULL, NULL, print_negprot } }, + { SMBsesssetupX, "SMBsesssetupX", FLG_CHAIN, + { NULL, NULL, NULL, NULL, print_sesssetup } }, + + { SMBtconX, "SMBtconX", FLG_CHAIN, + { "Com2=[w]\nOff2=[d]\nFlags=[w]\nPassLen=[d]\nPasswd&Path&Device=\n", + NULL, "Com2=[w]\nOff2=[d]\n", "ServiceType=[S]\n", NULL } }, + + { SMBtrans2, "SMBtrans2", 0, { NULL, NULL, NULL, NULL, print_trans2 } }, + + { SMBtranss2, "SMBtranss2", 0, DEFDESCRIPT }, + { SMBctemp, "SMBctemp", 0, DEFDESCRIPT }, + { SMBreadBs, "SMBreadBs", 0, DEFDESCRIPT }, + { SMBtrans, "SMBtrans", 0, { NULL, NULL, NULL, NULL, print_trans } }, + + { SMBnttrans, "SMBnttrans", 0, DEFDESCRIPT }, + { SMBnttranss, "SMBnttranss", 0, DEFDESCRIPT }, -/******************************************************************* -print a SMB message -********************************************************************/ -static void print_smb(const uchar *buf, const uchar *maxbuf) + { SMBntcreateX, "SMBntcreateX", FLG_CHAIN, + { "Com2=[w]\nOff2=[d]\nRes=[b]\nNameLen=[d]\nFlags=[W]\nRootDirectoryFid=[D]\nAccessMask=[W]\nAllocationSize=[L]\nExtFileAttributes=[W]\nShareAccess=[W]\nCreateDisposition=[W]\nCreateOptions=[W]\nImpersonationLevel=[W]\nSecurityFlags=[b]\n", + "Path=[S]\n", + "Com2=[w]\nOff2=[d]\nOplockLevel=[b]\nFid=[d]\nCreateAction=[W]\nCreateTime=[T3]LastAccessTime=[T3]LastWriteTime=[T3]ChangeTime=[T3]ExtFileAttributes=[W]\nAllocationSize=[L]\nEndOfFile=[L]\nFileType=[w]\nDeviceState=[w]\nDirectory=[b]\n", + NULL } }, + + { SMBntcancel, "SMBntcancel", 0, DEFDESCRIPT }, + + { -1, NULL, 0, DEFDESCRIPT } +}; + + +/* + * print a SMB message + */ +static void +print_smb(const u_char *buf, const u_char *maxbuf) { - int command; - const uchar *words, *data; - struct smbfns *fn; - char *fmt_smbheader = -"[P4]SMB Command = [B]\nError class = [BP1]\nError code = [d]\nFlags1 = [B]\nFlags2 = [B][P13]\nTree ID = [d]\nProc ID = [d]\nUID = [d]\nMID = [d]\nWord Count = [b]\n"; + int command; + const u_char *words, *data; + struct smbfns *fn; + char *fmt_smbheader = + "[P4]SMB Command = [B]\nError class = [BP1]\nError code = [d]\nFlags1 = [B]\nFlags2 = [B][P13]\nTree ID = [d]\nProc ID = [d]\nUID = [d]\nMID = [d]\nWord Count = [b]\n"; - request = (CVAL(buf,9)&0x80)?0:1; - command = CVAL(buf,4); + TCHECK(buf[9]); + request = (buf[9] & 0x80) ? 0 : 1; - fn = smbfind(command,smb_fns); + command = buf[4]; - printf("\nSMB PACKET: %s (%s)\n",fn->name,request?"REQUEST":"REPLY"); + fn = smbfind(command, smb_fns); - if (vflag == 0) return; + if (vflag > 1) + printf("\n"); - /* print out the header */ - fdata(buf,fmt_smbheader,buf+33); + printf("SMB PACKET: %s (%s)\n", fn->name, request ? "REQUEST" : "REPLY"); - if (CVAL(buf,5)) { - int class = CVAL(buf,5); - int num = SVAL(buf,7); - printf("SMBError = %s\n",smb_errstr(class,num)); - } + if (vflag < 2) + return; - words = buf+32; - data = words + 1 + CVAL(words,0)*2; + /* print out the header */ + smb_fdata(buf, fmt_smbheader, buf + 33); + if (buf[5]) + printf("SMBError = %s\n", smb_errstr(buf[5], EXTRACT_LE_16BITS(&buf[7]))); - while (words && data) - { - char *f1,*f2; - int wct = CVAL(words,0); + words = buf + 32; + TCHECK(words[0]); - if (request) { - f1 = fn->descript.req_f1; - f2 = fn->descript.req_f2; - } else { - f1 = fn->descript.rep_f1; - f2 = fn->descript.rep_f2; - } - - if (fn->descript.fn) { - fn->descript.fn(words,data,buf,maxbuf); - } else { - if (f1) { - printf("smbvwv[]=\n"); - fdata(words+1,f1,words + 1 + wct*2); - } else if (wct) { - int i; - int v; - printf("smbvwv[]=\n"); - for (i=0;i<wct;i++) { - v = SVAL(words+1,2*i); - printf("smb_vwv[%d]=%d (0x%X)\n",i,v,v); - } - } - - if (f2) { - printf("smbbuf[]=\n"); - fdata(data+2,f2,maxbuf); + for (;;) { + const u_char *f1, *f2; + int wct; + int bcc; + + TCHECK(words[0]); + wct = words[0]; + data = words + 1 + wct * 2; + + if (request) { + f1 = fn->descript.req_f1; + f2 = fn->descript.req_f2; } else { - int bcc = SVAL(data,0); - printf("smb_bcc=%d\n",bcc); - if (bcc>0) { - printf("smb_buf[]=\n"); - print_data(data + 2, MIN(bcc,PTR_DIFF(maxbuf,data+2))); - } + f1 = fn->descript.rep_f1; + f2 = fn->descript.rep_f2; } - } - if ((fn->flags & FLG_CHAIN) && CVAL(words,0) && SVAL(words,1)!=0xFF) { - command = SVAL(words,1); - words = buf + SVAL(words,3); - data = words + 1 + CVAL(words,0)*2; + if (fn->descript.fn) + (*fn->descript.fn)(words, data, buf, maxbuf); + else { + if (wct) { + printf("smbvwv[]=\n"); + if (f1) + smb_fdata(words + 1, f1, words + 1 + wct * 2); + else { + int i; + int v; + + for (i = 0; i < wct; i++) { + TCHECK2(words[1 + 2 * i], 2); + v = EXTRACT_LE_16BITS(words + 1 + 2 * i); + printf("smb_vwv[%d]=%d (0x%X)\n", i, v, v); + } + } + } - fn = smbfind(command,smb_fns); + TCHECK2(*data, 2); + bcc = EXTRACT_LE_16BITS(data); + if (f2) { + if (bcc > 0) { + printf("smbbuf[]=\n"); + smb_fdata(data + 2, f2, data + 2 + bcc); + } + } else { + printf("smb_bcc=%d\n", bcc); + if (bcc > 0) { + printf("smb_buf[]=\n"); + print_data(data + 2, SMBMIN(bcc, PTR_DIFF(maxbuf, data + 2))); + } + } + } - printf("\nSMB PACKET: %s (%s) (CHAINED)\n",fn->name,request?"REQUEST":"REPLY"); - } else { - words = data = NULL; - } + if ((fn->flags & FLG_CHAIN) == 0) + break; + if (wct == 0) + break; + TCHECK(words[1]); + command = EXTRACT_LE_16BITS(words + 1); + if (command == 0xFF) + break; + TCHECK2(words[3], 2); + words = buf + EXTRACT_LE_16BITS(words + 3); + + fn = smbfind(command, smb_fns); + + printf("\nSMB PACKET: %s (%s) (CHAINED)\n", + fn->name, request ? "REQUEST" : "REPLY"); } - printf("\n"); + printf("\n"); + return; +trunc: + printf("[|SMB]"); + return; } /* - print a NBT packet received across tcp on port 139 -*/ -void nbt_tcp_print(const uchar *data,int length) + * print a NBT packet received across tcp on port 139 + */ +void +nbt_tcp_print(const u_char *data, int length) { - const uchar *maxbuf = data + length; - int flags = CVAL(data,0); - int nbt_len = RSVAL(data,2); + const u_char *maxbuf = data + length; + int flags; + int nbt_len; - startbuf = data; - if (maxbuf <= data) return; + TCHECK2(data[2], 2); + flags = data[0]; + nbt_len = EXTRACT_16BITS(data + 2); - printf("\n>>> NBT Packet\n"); + startbuf = data; + if (maxbuf <= data) + return; - switch (flags) { - case 1: - printf("flags=0x%x\n", flags); - case 0: - data = fdata(data,"NBT Session Packet\nFlags=[rw]\nLength=[rd]\n",data+4); - if (data == NULL) - break; - if (memcmp(data,"\377SMB",4)==0) { - if (nbt_len>PTR_DIFF(maxbuf,data)) - printf("WARNING: Short packet. Try increasing the snap length (%ld)\n", - PTR_DIFF(maxbuf,data)); - print_smb(data,maxbuf>data+nbt_len?data+nbt_len:maxbuf); - } else { + if (vflag > 1) + printf ("\n>>> "); + + printf("NBT Packet"); + + if (vflag < 2) + return; + + printf("\n"); + + switch (flags) { + case 1: + printf("flags=0x%x\n", flags); + case 0: + data = smb_fdata(data, "NBT Session Packet\nFlags=[rw]\nLength=[rd]\n", + data + 4); + if (data == NULL) + break; + if (memcmp(data,"\377SMB",4) == 0) { + if (nbt_len > PTR_DIFF(maxbuf, data)) + printf("WARNING: Short packet. Try increasing the snap length (%lu)\n", + (unsigned long)PTR_DIFF(maxbuf, data)); + print_smb(data, maxbuf > data + nbt_len ? data + nbt_len : maxbuf); + } else printf("Session packet:(raw data?)\n"); - } - break; - - case 0x81: - data = fdata(data,"NBT Session Request\nFlags=[rW]\nDestination=[n1]\nSource=[n1]\n",maxbuf); - break; - - case 0x82: - data = fdata(data,"NBT Session Granted\nFlags=[rW]\n",maxbuf); - break; - - case 0x83: - { - int ecode = CVAL(data,4); - data = fdata(data,"NBT SessionReject\nFlags=[rW]\nReason=[B]\n",maxbuf); - switch (ecode) { - case 0x80: - printf("Not listening on called name\n"); - break; - case 0x81: - printf("Not listening for calling name\n"); - break; - case 0x82: - printf("Called name not present\n"); break; - case 0x83: - printf("Called name present, but insufficient resources\n"); - break; - default: - printf("Unspecified error 0x%X\n",ecode); - break; - } + + case 0x81: + data = smb_fdata(data, + "NBT Session Request\nFlags=[rW]\nDestination=[n1]\nSource=[n1]\n", + maxbuf); + break; + + case 0x82: + data = smb_fdata(data, "NBT Session Granted\nFlags=[rW]\n", maxbuf); + break; + + case 0x83: + { + int ecode; + + TCHECK(data[4]); + ecode = data[4]; + + data = smb_fdata(data, "NBT SessionReject\nFlags=[rW]\nReason=[B]\n", + maxbuf); + switch (ecode) { + case 0x80: + printf("Not listening on called name\n"); + break; + case 0x81: + printf("Not listening for calling name\n"); + break; + case 0x82: + printf("Called name not present\n"); + break; + case 0x83: + printf("Called name present, but insufficient resources\n"); + break; + default: + printf("Unspecified error 0x%X\n", ecode); + break; + } + } + break; + + case 0x85: + data = smb_fdata(data, "NBT Session Keepalive\nFlags=[rW]\n", maxbuf); + break; + + default: + printf("flags=0x%x\n", flags); + data = smb_fdata(data, "NBT - Unknown packet type\nType=[rW]\n", maxbuf); } - break; - - case 0x85: - data = fdata(data,"NBT Session Keepalive\nFlags=[rW]\n",maxbuf); - break; - - default: - printf("flags=0x%x\n", flags); - data = fdata(data,"NBT - Unknown packet type\nType=[rW]\n",maxbuf); - } - printf("\n"); - fflush(stdout); + printf("\n"); + fflush(stdout); + return; +trunc: + printf("[|SMB]"); + return; } /* - print a NBT packet received across udp on port 137 -*/ -void nbt_udp137_print(const uchar *data, int length) + * print a NBT packet received across udp on port 137 + */ +void +nbt_udp137_print(const u_char *data, int length) { - const uchar *maxbuf = data + length; - int name_trn_id = RSVAL(data,0); - int response = (CVAL(data,2)>>7); - int opcode = (CVAL(data,2) >> 3) & 0xF; - int nm_flags = ((CVAL(data,2) & 0x7) << 4) + (CVAL(data,3)>>4); - int rcode = CVAL(data,3) & 0xF; - int qdcount = RSVAL(data,4); - int ancount = RSVAL(data,6); - int nscount = RSVAL(data,8); - int arcount = RSVAL(data,10); - char *opcodestr; - const char *p; - - startbuf = data; - - if (maxbuf <= data) return; - - printf("\n>>> NBT UDP PACKET(137): "); - - switch (opcode) { - case 0: opcodestr = "QUERY"; break; - case 5: opcodestr = "REGISTRATION"; break; - case 6: opcodestr = "RELEASE"; break; - case 7: opcodestr = "WACK"; break; - case 8: opcodestr = "REFRESH(8)"; break; - case 9: opcodestr = "REFRESH"; break; - default: opcodestr = "OPUNKNOWN"; break; - } - printf("%s", opcodestr); - if (response) { - if (rcode) - printf("; NEGATIVE"); + const u_char *maxbuf = data + length; + int name_trn_id, response, opcode, nm_flags, rcode; + int qdcount, ancount, nscount, arcount; + char *opcodestr; + const char *p; + int total, i; + + TCHECK2(data[10], 2); + name_trn_id = EXTRACT_16BITS(data); + response = (data[2] >> 7); + opcode = (data[2] >> 3) & 0xF; + nm_flags = ((data[2] & 0x7) << 4) + (data[3] >> 4); + rcode = data[3] & 0xF; + qdcount = EXTRACT_16BITS(data + 4); + ancount = EXTRACT_16BITS(data + 6); + nscount = EXTRACT_16BITS(data + 8); + arcount = EXTRACT_16BITS(data + 10); + startbuf = data; + + if (maxbuf <= data) + return; + + if (vflag > 1) + printf("\n>>> "); + + printf("NBT UDP PACKET(137): "); + + switch (opcode) { + case 0: opcodestr = "QUERY"; break; + case 5: opcodestr = "REGISTRATION"; break; + case 6: opcodestr = "RELEASE"; break; + case 7: opcodestr = "WACK"; break; + case 8: opcodestr = "REFRESH(8)"; break; + case 9: opcodestr = "REFRESH"; break; + case 15: opcodestr = "MULTIHOMED REGISTRATION"; break; + default: opcodestr = "OPUNKNOWN"; break; + } + printf("%s", opcodestr); + if (response) { + if (rcode) + printf("; NEGATIVE"); + else + printf("; POSITIVE"); + } + + if (response) + printf("; RESPONSE"); else - printf("; POSITIVE"); - } - - if (response) - printf("; RESPONSE"); - else - printf("; REQUEST"); - - if (nm_flags&1) - printf("; BROADCAST"); - else - printf("; UNICAST"); - - if (vflag == 0) return; - - printf("\nTrnID=0x%X\nOpCode=%d\nNmFlags=0x%X\nRcode=%d\nQueryCount=%d\nAnswerCount=%d\nAuthorityCount=%d\nAddressRecCount=%d\n", - name_trn_id,opcode,nm_flags,rcode,qdcount,ancount,nscount,arcount); - - p = data + 12; - - { - int total = ancount+nscount+arcount; - int i; + printf("; REQUEST"); + + if (nm_flags & 1) + printf("; BROADCAST"); + else + printf("; UNICAST"); + + if (vflag < 2) + return; - if (qdcount>100 || total>100) { - printf("Corrupt packet??\n"); - return; + printf("\nTrnID=0x%X\nOpCode=%d\nNmFlags=0x%X\nRcode=%d\nQueryCount=%d\nAnswerCount=%d\nAuthorityCount=%d\nAddressRecCount=%d\n", + name_trn_id, opcode, nm_flags, rcode, qdcount, ancount, nscount, + arcount); + + p = data + 12; + + total = ancount + nscount + arcount; + + if (qdcount > 100 || total > 100) { + printf("Corrupt packet??\n"); + return; } if (qdcount) { - printf("QuestionRecords:\n"); - for (i=0;i<qdcount;i++) - p = fdata(p,"|Name=[n1]\nQuestionType=[rw]\nQuestionClass=[rw]\n#",maxbuf); + printf("QuestionRecords:\n"); + for (i = 0; i < qdcount; i++) + p = smb_fdata(p, + "|Name=[n1]\nQuestionType=[rw]\nQuestionClass=[rw]\n#", + maxbuf); if (p == NULL) - goto out; + goto out; } if (total) { - printf("\nResourceRecords:\n"); - for (i=0;i<total;i++) { - int rdlen; - int restype; - p = fdata(p,"Name=[n1]\n#",maxbuf); - if (p == NULL) - goto out; - restype = RSVAL(p,0); - p = fdata(p,"ResType=[rw]\nResClass=[rw]\nTTL=[rD]\n",p+8); - if (p == NULL) - goto out; - rdlen = RSVAL(p,0); - printf("ResourceLength=%d\nResourceData=\n",rdlen); - p += 2; - if (rdlen == 6) { - p = fdata(p,"AddrType=[rw]\nAddress=[b.b.b.b]\n",p+rdlen); - if (p == NULL) - goto out; - } else { - if (restype == 0x21) { - int numnames = CVAL(p,0); - p = fdata(p,"NumNames=[B]\n",p+1); + printf("\nResourceRecords:\n"); + for (i = 0; i < total; i++) { + int rdlen; + int restype; + + p = smb_fdata(p, "Name=[n1]\n#", maxbuf); if (p == NULL) - goto out; - while (numnames--) { - p = fdata(p,"Name=[n2]\t#",maxbuf); - if (p[0] & 0x80) printf("<GROUP> "); - switch (p[0] & 0x60) { - case 0x00: printf("B "); break; - case 0x20: printf("P "); break; - case 0x40: printf("M "); break; - case 0x60: printf("_ "); break; - } - if (p[0] & 0x10) printf("<DEREGISTERING> "); - if (p[0] & 0x08) printf("<CONFLICT> "); - if (p[0] & 0x04) printf("<ACTIVE> "); - if (p[0] & 0x02) printf("<PERMANENT> "); - printf("\n"); - p += 2; + goto out; + restype = EXTRACT_16BITS(p); + p = smb_fdata(p, "ResType=[rw]\nResClass=[rw]\nTTL=[rD]\n", p + 8); + if (p == NULL) + goto out; + rdlen = EXTRACT_16BITS(p); + printf("ResourceLength=%d\nResourceData=\n", rdlen); + p += 2; + if (rdlen == 6) { + p = smb_fdata(p, "AddrType=[rw]\nAddress=[b.b.b.b]\n", p + rdlen); + if (p == NULL) + goto out; + } else { + if (restype == 0x21) { + int numnames; + + TCHECK(*p); + numnames = p[0]; + p = smb_fdata(p, "NumNames=[B]\n", p + 1); + if (p == NULL) + goto out; + while (numnames--) { + p = smb_fdata(p, "Name=[n2]\t#", maxbuf); + TCHECK(*p); + if (p[0] & 0x80) + printf("<GROUP> "); + switch (p[0] & 0x60) { + case 0x00: printf("B "); break; + case 0x20: printf("P "); break; + case 0x40: printf("M "); break; + case 0x60: printf("_ "); break; + } + if (p[0] & 0x10) + printf("<DEREGISTERING> "); + if (p[0] & 0x08) + printf("<CONFLICT> "); + if (p[0] & 0x04) + printf("<ACTIVE> "); + if (p[0] & 0x02) + printf("<PERMANENT> "); + printf("\n"); + p += 2; + } + } else { + print_data(p, min(rdlen, length - ((const u_char *)p - data))); + p += rdlen; + } } - } else { - print_data(p,rdlen); - p += rdlen; - } } - } } - } - if ((uchar*)p < maxbuf) { - fdata(p,"AdditionalData:\n",maxbuf); - } - + if ((u_char*)p < maxbuf) + smb_fdata(p, "AdditionalData:\n", maxbuf); + out: - printf("\n"); - fflush(stdout); + printf("\n"); + fflush(stdout); + return; +trunc: + printf("[|SMB]"); + return; } /* - print a NBT packet received across udp on port 138 -*/ -void nbt_udp138_print(const uchar *data, int length) + * print a NBT packet received across udp on port 138 + */ +void +nbt_udp138_print(const u_char *data, int length) { - const uchar *maxbuf = data + length; - startbuf = data; - if (maxbuf <= data) return; + const u_char *maxbuf = data + length; - data = fdata(data,"\n>>> NBT UDP PACKET(138) Res=[rw] ID=[rw] IP=[b.b.b.b] Port=[rd] Length=[rd] Res2=[rw]\nSourceName=[n1]\nDestName=[n1]\n#",maxbuf); + if (maxbuf > snapend) + maxbuf = snapend; + if (maxbuf <= data) + return; + startbuf = data; - if (data != NULL) - print_smb(data,maxbuf); - - printf("\n"); - fflush(stdout); -} + if (vflag < 2) { + printf("NBT UDP PACKET(138)"); + return; + } + data = smb_fdata(data, + "\n>>> NBT UDP PACKET(138) Res=[rw] ID=[rw] IP=[b.b.b.b] Port=[rd] Length=[rd] Res2=[rw]\nSourceName=[n1]\nDestName=[n1]\n#", + maxbuf); + + if (data != NULL) { + /* If there isn't enough data for "\377SMB", don't check for it. */ + if (&data[3] >= maxbuf) + goto out; + + if (memcmp(data, "\377SMB",4) == 0) + print_smb(data, maxbuf); + } +out: + printf("\n"); + fflush(stdout); +} /* - print netbeui frames + print netbeui frames */ -void netbeui_print(u_short control, const uchar *data, const uchar *maxbuf) +void +netbeui_print(u_short control, const u_char *data, int length) { - int len = SVAL(data,0); - int command = CVAL(data,4); - const uchar *data2 = data + len; - int is_truncated = 0; - - if (data2 >= maxbuf) { - data2 = maxbuf; - is_truncated = 1; - } - - startbuf = data; - - printf("\n>>> NetBeui Packet\nType=0x%X ", control); - data = fdata(data,"Length=[d] Signature=[w] Command=[B]\n#",maxbuf); - if (data == NULL) - goto out; - - switch (command) { - case 0xA: - data = fdata(data,"NameQuery:[P1]\nSessionNumber=[B]\nNameType=[B][P2]\nResponseCorrelator=[w]\nDestination=[n2]\nSource=[n2]\n",data2); - break; - - case 0x8: - data = fdata(data,"NetbiosDataGram:[P7]\nDestination=[n2]\nSource=[n2]\n",data2); - break; - - case 0xE: - data = fdata(data,"NameRecognise:\n[P1]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nDestination=[n2]\nSource=[n2]\n",data2); - break; - - case 0x19: - data = fdata(data,"SessionInitialise:\nData1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n",data2); - break; - - case 0x17: - data = fdata(data,"SessionConfirm:\nData1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n",data2); - break; - - case 0x16: - data = fdata(data,"NetbiosDataOnlyLast:\nFlags=[{|NO_ACK|PIGGYBACK_ACK_ALLOWED|PIGGYBACK_ACK_INCLUDED|}]\nResyncIndicator=[w][P2]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n",data2); - break; - - case 0x14: - data = fdata(data,"NetbiosDataAck:\n[P3]TransmitCorrelator=[w][P2]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n",data2); - break; - - case 0x18: - data = fdata(data,"SessionEnd:\n[P1]Data2=[w][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n",data2); - break; - - case 0x1f: - data = fdata(data,"SessionAlive\n",data2); - break; - - default: - data = fdata(data,"Unknown Netbios Command ",data2); - break; - } - if (data == NULL) - goto out; - - if (is_truncated) { - /* data2 was past the end of the buffer */ - goto out; - } - - if (memcmp(data2,"\377SMB",4)==0) { - print_smb(data2,maxbuf); - } else { - int i; - for (i=0;i<128;i++) { - if (&data2[i] >= maxbuf) - break; - if (memcmp(&data2[i],"\377SMB",4)==0) { - printf("found SMB packet at %d\n", i); - print_smb(&data2[i],maxbuf); + const u_char *maxbuf = data + length; + int len; + int command; + const u_char *data2; + int is_truncated = 0; + + if (maxbuf > snapend) + maxbuf = snapend; + TCHECK(data[4]); + len = EXTRACT_LE_16BITS(data); + command = data[4]; + data2 = data + len; + if (data2 >= maxbuf) { + data2 = maxbuf; + is_truncated = 1; + } + + startbuf = data; + + if (vflag < 2) { + printf("NetBeui Packet"); + return; + } + + printf("\n>>> NetBeui Packet\nType=0x%X ", control); + data = smb_fdata(data, "Length=[d] Signature=[w] Command=[B]\n#", maxbuf); + if (data == NULL) + goto out; + + switch (command) { + case 0xA: + data = smb_fdata(data, "NameQuery:[P1]\nSessionNumber=[B]\nNameType=[B][P2]\nResponseCorrelator=[w]\nDestination=[n2]\nSource=[n2]\n", data2); + break; + + case 0x8: + data = smb_fdata(data, + "NetbiosDataGram:[P7]\nDestination=[n2]\nSource=[n2]\n", data2); + break; + + case 0xE: + data = smb_fdata(data, + "NameRecognise:\n[P1]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nDestination=[n2]\nSource=[n2]\n", + data2); + break; + + case 0x19: + data = smb_fdata(data, + "SessionInitialise:\nData1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n", + data2); + break; + + case 0x17: + data = smb_fdata(data, + "SessionConfirm:\nData1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n", + data2); + break; + + case 0x16: + data = smb_fdata(data, + "NetbiosDataOnlyLast:\nFlags=[{|NO_ACK|PIGGYBACK_ACK_ALLOWED|PIGGYBACK_ACK_INCLUDED|}]\nResyncIndicator=[w][P2]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n", + data2); + break; + + case 0x14: + data = smb_fdata(data, + "NetbiosDataAck:\n[P3]TransmitCorrelator=[w][P2]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n", + data2); + break; + + case 0x18: + data = smb_fdata(data, + "SessionEnd:\n[P1]Data2=[w][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n", + data2); + break; + + case 0x1f: + data = smb_fdata(data, "SessionAlive\n", data2); + break; + + default: + data = smb_fdata(data, "Unknown Netbios Command ", data2); break; - } } - } + if (data == NULL) + goto out; + + if (is_truncated) { + /* data2 was past the end of the buffer */ + goto out; + } + + /* If there isn't enough data for "\377SMB", don't look for it. */ + if (&data2[3] >= maxbuf) + goto out; + + if (memcmp(data2, "\377SMB",4) == 0) + print_smb(data2, maxbuf); + else { + int i; + for (i = 0; i < 128; i++) { + if (&data2[i + 3] >= maxbuf) + break; + if (memcmp(&data2[i], "\377SMB", 4) == 0) { + printf("found SMB packet at %d\n", i); + print_smb(&data2[i], maxbuf); + break; + } + } + } out: - printf("\n"); + printf("\n"); + return; +trunc: + printf("[|SMB]"); + return; } /* - print IPX-Netbios frames -*/ -void ipx_netbios_print(const uchar *data, const uchar *maxbuf) + * print IPX-Netbios frames + */ +void +ipx_netbios_print(const u_char *data, u_int length) { - /* this is a hack till I work out how to parse the rest of the IPX stuff */ - int i; - startbuf = data; - for (i=0;i<128;i++) - if (memcmp(&data[i],"\377SMB",4)==0) { - fdata(data,"\n>>> IPX transport ",&data[i]); - if (data != NULL) - print_smb(&data[i],maxbuf); - printf("\n"); - fflush(stdout); - break; + /* + * this is a hack till I work out how to parse the rest of the + * NetBIOS-over-IPX stuff + */ + int i; + const u_char *maxbuf; + + maxbuf = data + length; + /* Don't go past the end of the captured data in the packet. */ + if (maxbuf > snapend) + maxbuf = snapend; + startbuf = data; + for (i = 0; i < 128; i++) { + if (&data[i + 4] > maxbuf) + break; + if (memcmp(&data[i], "\377SMB", 4) == 0) { + smb_fdata(data, "\n>>> IPX transport ", &data[i]); + if (data != NULL) + print_smb(&data[i], maxbuf); + printf("\n"); + fflush(stdout); + break; + } } - if (i==128) - fdata(data,"\n>>> Unknown IPX ",maxbuf); + if (i == 128) + smb_fdata(data, "\n>>> Unknown IPX ", maxbuf); } diff --git a/contrib/tcpdump/print-snmp.c b/contrib/tcpdump/print-snmp.c index 2e2a276..a2638ce 100644 --- a/contrib/tcpdump/print-snmp.c +++ b/contrib/tcpdump/print-snmp.c @@ -1,16 +1,29 @@ /* * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997 - * The Regents of the University of California. All rights reserved. + * John Robert LoVerso. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by John Robert LoVerso. - * 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. * * This implementation has been influenced by the CMU SNMP release, * by Steve Waldbusser. However, this shares no code with that system. @@ -45,7 +58,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.44 2000/11/10 17:34:10 fenner Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.50 2001/09/17 22:16:53 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -428,16 +441,11 @@ asn1_parse(register const u_char *p, u_int len, struct be *elem) elem->form = form; elem->class = class; elem->id = id; - if (vflag > 1) - printf("|%.2x", *p); p++; len--; hdr = 1; /* extended tag field */ if (id == ASN_ID_EXT) { - for (id = 0; *p & ASN_BIT8 && len > 0; len--, hdr++, p++) { - if (vflag > 1) - printf("|%.2x", *p); + for (id = 0; *p & ASN_BIT8 && len > 0; len--, hdr++, p++) id = (id << 7) | (*p & ~ASN_BIT8); - } if (len == 0 && *p & ASN_BIT8) { ifNotTruncated fputs("[Xtagfield?]", stdout); return -1; @@ -452,8 +460,6 @@ asn1_parse(register const u_char *p, u_int len, struct be *elem) return -1; } elem->asnlen = *p; - if (vflag > 1) - printf("|%.2x", *p); p++; len--; hdr++; if (elem->asnlen & ASN_BIT8) { int noct = elem->asnlen % ASN_BIT8; @@ -462,11 +468,8 @@ asn1_parse(register const u_char *p, u_int len, struct be *elem) ifNotTruncated printf("[asnlen? %d<%d]", len, noct); return -1; } - for (; noct-- > 0; len--, hdr++) { - if (vflag > 1) - printf("|%.2x", *p); + for (; noct-- > 0; len--, hdr++) elem->asnlen = (elem->asnlen << ASN_SHIFT8) | *p++; - } } if (len < elem->asnlen) { if (!truncated) { @@ -720,7 +723,7 @@ asn1_print(struct be *elem) d = elem->data.uns64.high * 4294967296.0; /* 2^32 */ if (elem->data.uns64.high <= 0x1fffff) { d += elem->data.uns64.low; -#if 0 /*is looks illegal, but what is the intention???*/ +#if 0 /*is looks illegal, but what is the intention?*/ printf("%.f", d); #else printf("%f", d); @@ -728,7 +731,7 @@ asn1_print(struct be *elem) break; } d += (elem->data.uns64.low & 0xfffff000); -#if 0 /*is looks illegal, but what is the intention???*/ +#if 0 /*is looks illegal, but what is the intention?*/ snprintf(first, sizeof(first), "%.f", d); #else snprintf(first, sizeof(first), "%f", d); @@ -837,25 +840,6 @@ asn1_decode(u_char *p, u_int length) #ifdef LIBSMI -#if (SMI_VERSION_MAJOR == 0 && SMI_VERSION_MINOR >= 2) || (SMI_VERSION_MAJOR > 0) -#define LIBSMI_API_V2 -#else -#define LIBSMI_API_V1 -#endif - -#ifdef LIBSMI_API_V1 -/* Some of the API revisions introduced new calls that can be - * represented by macros. - */ -#define smiGetNodeType(n) smiGetType((n)->typemodule, (n)->typename) - -#else -/* These calls in the V1 API were removed in V2. */ -#define smiFreeRange(r) -#define smiFreeType(r) -#define smiFreeNode(r) -#endif - struct smi2be { SmiBasetype basetype; int be; @@ -878,7 +862,7 @@ static struct smi2be smi2betab[] = { }; static void smi_decode_oid(struct be *elem, unsigned int *oid, - unsigned int *oidlen) + unsigned int oidsize, unsigned int *oidlen) { u_char *p = (u_char *)elem->data.raw; u_int32_t asnlen = elem->asnlen; @@ -894,10 +878,14 @@ static void smi_decode_oid(struct be *elem, unsigned int *oid, */ if (first < 0) { first = 0; - oid[(*oidlen)++] = o/OIDMUX; + if (*oidlen < oidsize) { + oid[(*oidlen)++] = o/OIDMUX; + } o %= OIDMUX; } - oid[(*oidlen)++] = o; + if (*oidlen < oidsize) { + oid[(*oidlen)++] = o; + } o = 0; } } @@ -966,37 +954,22 @@ static int smi_check_range(SmiType *smiType, struct be *elem) SmiRange *smiRange; int ok = 1; -#ifdef LIBSMI_API_V1 - for (smiRange = smiGetFirstRange(smiType->module, smiType->name); -#else for (smiRange = smiGetFirstRange(smiType); -#endif smiRange; smiRange = smiGetNextRange(smiRange)) { ok = smi_check_a_range(smiType, smiRange, elem); if (ok) { - smiFreeRange(smiRange); break; } } - if (ok -#ifdef LIBSMI_API_V1 - && smiType->parentmodule && smiType->parentname -#endif - ) { + if (ok) { SmiType *parentType; -#ifdef LIBSMI_API_V1 - parentType = smiGetType(smiType->parentmodule, - smiType->parentname); -#else parentType = smiGetParentType(smiType); -#endif if (parentType) { ok = smi_check_range(parentType, elem); - smiFreeType(parentType); } } @@ -1009,18 +982,14 @@ static SmiNode *smi_print_variable(struct be *elem) SmiNode *smiNode = NULL; int i; - smi_decode_oid(elem, oid, &oidlen); + smi_decode_oid(elem, oid, sizeof(oid)/sizeof(unsigned int), &oidlen); smiNode = smiGetNodeByOID(oidlen, oid); if (! smiNode) { asn1_print(elem); return NULL; } if (vflag) { -#ifdef LIBSMI_API_V1 - fputs(smiNode->module, stdout); -#else fputs(smiGetNodeModule(smiNode)->name, stdout); -#endif fputs("::", stdout); } fputs(smiNode->name, stdout); @@ -1069,26 +1038,18 @@ static void smi_print_value(SmiNode *smiNode, u_char pduid, struct be *elem) fputs("[noAccess]", stdout); } -#ifdef LIBSMI_API_V1 - smiType = smiGetType(smiNode->typemodule, smiNode->typename); -#else smiType = smiGetNodeType(smiNode); -#endif if (! smiType) { asn1_print(elem); return; } -#ifdef LIBSMI_API_V1 - if (! smi_check_type(smiNode->basetype, elem->type)) { -#else if (! smi_check_type(smiType->basetype, elem->type)) { -#endif fputs("[wrongType]", stdout); } if (! smi_check_range(smiType, elem)) { - fputs("[wrongLength]", stdout); + fputs("[outOfRange]", stdout); } /* resolve bits to named bits */ @@ -1104,15 +1065,13 @@ static void smi_print_value(SmiNode *smiNode, u_char pduid, struct be *elem) if (smiType->basetype == SMI_BASETYPE_BITS) { /* print bit labels */ } else { - smi_decode_oid(elem, oid, &oidlen); + smi_decode_oid(elem, oid, + sizeof(oid)/sizeof(unsigned int), + &oidlen); smiNode = smiGetNodeByOID(oidlen, oid); if (smiNode) { if (vflag) { -#ifdef LIBSMI_API_V1 - fputs(smiNode->module, stdout); -#else fputs(smiGetNodeModule(smiNode)->name, stdout); -#endif fputs("::", stdout); } fputs(smiNode->name, stdout); @@ -1128,15 +1087,8 @@ static void smi_print_value(SmiNode *smiNode, u_char pduid, struct be *elem) break; case BE_INT: -#ifdef LIBSMI_API_V1 - if (smiNode->basetype == SMI_BASETYPE_ENUM - && smiNode->typemodule && smiNode->typename) { - for (nn = smiGetFirstNamedNumber(smiNode->typemodule, - smiNode->typename); -#else if (smiType->basetype == SMI_BASETYPE_ENUM) { for (nn = smiGetFirstNamedNumber(smiType); -#endif nn; nn = smiGetNextNamedNumber(nn)) { if (nn->value.value.integer32 @@ -1154,10 +1106,6 @@ static void smi_print_value(SmiNode *smiNode, u_char pduid, struct be *elem) if (! done) { asn1_print(elem); } - - if (smiType) { - smiFreeType(smiType); - } } #endif @@ -1273,7 +1221,6 @@ varbind_print(u_char pduid, const u_char *np, u_int length) if (elem.type != BE_NULL) { #ifdef LIBSMI smi_print_value(smiNode, pduid, &elem); - smiFreeNode(smiNode); #else asn1_print(&elem); #endif diff --git a/contrib/tcpdump/print-tcp.c b/contrib/tcpdump/print-tcp.c index 40d3f49..a5f69fe 100644 --- a/contrib/tcpdump/print-tcp.c +++ b/contrib/tcpdump/print-tcp.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.81 2000/12/23 20:55:22 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.95 2001/12/10 08:21:24 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -52,49 +52,12 @@ static const char rcsid[] = #include "ip6.h" #endif +#include "nameser.h" + static void print_tcp_rst_data(register const u_char *sp, u_int length); #define MAX_RST_DATA_LEN 30 -/* Compatibility */ -#ifndef TCPOPT_WSCALE -#define TCPOPT_WSCALE 3 /* window scale factor (rfc1072) */ -#endif -#ifndef TCPOPT_SACKOK -#define TCPOPT_SACKOK 4 /* selective ack ok (rfc1072) */ -#endif -#ifndef TCPOPT_SACK -#define TCPOPT_SACK 5 /* selective ack (rfc1072) */ -#endif -#ifndef TCPOPT_ECHO -#define TCPOPT_ECHO 6 /* echo (rfc1072) */ -#endif -#ifndef TCPOPT_ECHOREPLY -#define TCPOPT_ECHOREPLY 7 /* echo (rfc1072) */ -#endif -#ifndef TCPOPT_TIMESTAMP -#define TCPOPT_TIMESTAMP 8 /* timestamps (rfc1323) */ -#endif -#ifndef TCPOPT_CC -#define TCPOPT_CC 11 /* T/TCP CC options (rfc1644) */ -#endif -#ifndef TCPOPT_CCNEW -#define TCPOPT_CCNEW 12 /* T/TCP CC options (rfc1644) */ -#endif -#ifndef TCPOPT_CCECHO -#define TCPOPT_CCECHO 13 /* T/TCP CC options (rfc1644) */ -#endif - -/* - * Definitions required for ECN - * for use if the OS running tcpdump does not have ECN - */ -#ifndef TH_ECNECHO -#define TH_ECNECHO 0x40 /* ECN Echo in tcp header */ -#endif -#ifndef TH_CWR -#define TH_CWR 0x80 /* ECN Cwnd Reduced in tcp header*/ -#endif struct tha { #ifndef INET6 @@ -129,16 +92,19 @@ static struct tcp_seq_hash tcp_seq_hash[TSEQ_HASHSIZE]; #define BGP_PORT 179 #endif #define NETBIOS_SSN_PORT 139 -#define BXXP_PORT 10288 +#ifndef PPTP_PORT +#define PPTP_PORT 1723 +#endif +#define BEEP_PORT 10288 #ifndef NFS_PORT #define NFS_PORT 2049 #endif +#define MSDP_PORT 639 static int tcp_cksum(register const struct ip *ip, register const struct tcphdr *tp, register int len) { - int i, tlen; union phu { struct phdr { u_int32_t src; @@ -149,34 +115,18 @@ static int tcp_cksum(register const struct ip *ip, } ph; u_int16_t pa[6]; } phu; - register const u_int16_t *sp; - u_int32_t sum; - tlen = ntohs(ip->ip_len) - ((const char *)tp-(const char*)ip); + const u_int16_t *sp; /* pseudo-header.. */ - phu.ph.len = htons(tlen); + phu.ph.len = htons(len); /* XXX */ phu.ph.mbz = 0; phu.ph.proto = IPPROTO_TCP; memcpy(&phu.ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t)); memcpy(&phu.ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t)); sp = &phu.pa[0]; - sum = sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5]; - - sp = (const u_int16_t *)tp; - - for (i=0; i<(tlen&~1); i+= 2) - sum += *sp++; - - if (tlen & 1) { - sum += htons( (*(const u_int8_t *)sp) << 8); - } - - while (sum > 0xffff) - sum = (sum & 0xffff) + (sum >> 16); - sum = ~sum & 0xffff; - - return (sum); + return in_cksum((u_short *)tp, len, + sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5]); } #ifdef INET6 @@ -262,7 +212,6 @@ tcp_print(register const u_char *bp, register u_int length, sport = ntohs(tp->th_sport); dport = ntohs(tp->th_dport); - hlen = TH_OFF(tp) * 4; /* @@ -273,13 +222,13 @@ tcp_print(register const u_char *bp, register u_int length, if (!qflag) { if ((u_char *)tp + 4 + sizeof(struct rpc_msg) <= snapend && dport == NFS_PORT) { - nfsreq_print((u_char *)tp + hlen + 4, length-hlen, + nfsreq_print((u_char *)tp + hlen + 4, length - hlen, (u_char *)ip); return; } else if ((u_char *)tp + 4 + sizeof(struct rpc_msg) <= snapend && sport == NFS_PORT) { - nfsreply_print((u_char *)tp + hlen + 4,length-hlen, + nfsreply_print((u_char *)tp + hlen + 4, length - hlen, (u_char *)ip); return; } @@ -353,18 +302,18 @@ tcp_print(register const u_char *bp, register u_int length, memset(&tha, 0, sizeof(tha)); rev = 0; if (ip6) { - if (sport > dport) { + if (sport > dport) rev = 1; - } else if (sport == dport) { - int i; - - for (i = 0; i < 4; i++) { - if (((u_int32_t *)(&ip6->ip6_src))[i] > - ((u_int32_t *)(&ip6->ip6_dst))[i]) { - rev = 1; - break; + else if (sport == dport) { + int i; + + for (i = 0; i < 4; i++) { + if (((u_int32_t *)(&ip6->ip6_src))[i] > + ((u_int32_t *)(&ip6->ip6_dst))[i]) { + rev = 1; + break; + } } - } } if (rev) { tha.src = ip6->ip6_dst; @@ -425,7 +374,6 @@ tcp_print(register const u_char *bp, register u_int length, th->ack = seq, th->seq = ack - 1; else th->seq = seq, th->ack = ack - 1; - } else { if (rev) seq -= th->ack, ack -= th->seq; @@ -469,7 +417,7 @@ tcp_print(register const u_char *bp, register u_int length, length -= hlen; if (vflag > 1 || length > 0 || flags & (TH_SYN | TH_FIN | TH_RST)) - (void)printf(" %u:%u(%d)", seq, seq + length, length); + (void)printf(" %u:%u(%u)", seq, seq + length, length); if (flags & TH_ACK) (void)printf(" ack %u", ack); @@ -649,10 +597,24 @@ tcp_print(register const u_char *bp, register u_int length, telnet_print(bp, length); } else if (sport == BGP_PORT || dport == BGP_PORT) bgp_print(bp, length); + else if (sport == PPTP_PORT || dport == PPTP_PORT) + pptp_print(bp, length); +#ifdef TCPDUMP_DO_SMB else if (sport == NETBIOS_SSN_PORT || dport == NETBIOS_SSN_PORT) nbt_tcp_print(bp, length); - else if (sport == BXXP_PORT || dport == BXXP_PORT) - bxxp_print(bp, length); +#endif + else if (sport == BEEP_PORT || dport == BEEP_PORT) + beep_print(bp, length); + else if (length > 2 && + (sport == NAMESERVER_PORT || dport == NAMESERVER_PORT)) { + /* + * TCP DNS query has 2byte length at the head. + * XXX packet could be unaligned, it can go strange + */ + ns_print(bp + 2, length - 2); + } else if (sport == MSDP_PORT || dport == MSDP_PORT) { + msdp_print(bp, length); + } } return; bad: @@ -697,10 +659,7 @@ print_tcp_rst_data(register const u_char *sp, u_int length) putchar(' '); while (length-- && sp <= snapend) { c = *sp++; - if (isprint(c)) - putchar(c); - else - putchar('.'); + safeputchar(c); } putchar(']'); } diff --git a/contrib/tcpdump/print-telnet.c b/contrib/tcpdump/print-telnet.c index bad4e7d..c070c44 100644 --- a/contrib/tcpdump/print-telnet.c +++ b/contrib/tcpdump/print-telnet.c @@ -51,7 +51,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-telnet.c,v 1.12 2000/09/29 04:58:51 guy Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-telnet.c,v 1.18 2001/09/10 06:40:08 fenner Exp $"; #endif #include <sys/param.h> @@ -61,10 +61,6 @@ static const char rcsid[] = #include <netinet/in.h> -#define TELCMDS -#define TELOPTS -#include <arpa/telnet.h> - #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -73,110 +69,199 @@ static const char rcsid[] = #include "interface.h" #include "addrtoname.h" -#ifndef TELCMD_FIRST -# define TELCMD_FIRST SE -#endif +#define TELCMDS +#define TELOPTS +#include "telnet.h" -void -telnet_print(register const u_char *sp, u_int length) +/* normal */ +static const char *cmds[] = { + "IS", "SEND", "INFO", +}; + +/* 37: Authentication */ +static const char *authcmd[] = { + "IS", "SEND", "REPLY", "NAME", +}; +static const char *authtype[] = { + "NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", + "SRP", "RSA", "SSL", NULL, NULL, + "LOKI", "SSA", "KEA_SJ", "KEA_SJ_INTEG", "DSS", + "NTLM", +}; + +/* 38: Encryption */ +static const char *enccmd[] = { + "IS", "SUPPORT", "REPLY", "START", "END", + "REQUEST-START", "REQUEST-END", "END_KEYID", "DEC_KEYID", +}; +static const char *enctype[] = { + "NULL", "DES_CFB64", "DES_OFB64", "DES3_CFB64", "DES3_OFB64", + NULL, "CAST5_40_CFB64", "CAST5_40_OFB64", "CAST128_CFB64", "CAST128_OFB64", +}; + +#define STR_OR_ID(x, tab) \ + (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x)) + +static char * +numstr(int x) { - static char tnet[128]; - register int i, c, x; - register u_char *rcp; - int off, first = 1; - u_char *osp; - - off = 0; - x = 0; - - while (length > 0 && *sp == IAC) { - osp = (u_char *) sp; - tnet[0] = '\0'; - - c = *sp++; - length--; - switch (*sp) { - case IAC: /* <IAC><IAC>! */ - if (length > 1 && sp[1] == IAC) { - (void)strcpy(tnet, "IAC IAC"); - } else { - length = 0; - continue; - } + static char buf[20]; + + snprintf(buf, sizeof(buf), "%#x", x); + return buf; +} + +/* sp points to IAC byte */ +static int +telnet_parse(const u_char *sp, u_int length, int print) +{ + int i, c, x; + const u_char *osp, *p; +#define FETCH(c, sp, length) \ + do { \ + if (length < 1) \ + goto pktend; \ + TCHECK(*sp); \ + c = *sp++; \ + length--; \ + } while (0) + + osp = sp; + + FETCH(c, sp, length); + if (c != IAC) + goto pktend; + FETCH(c, sp, length); + if (c == IAC) { /* <IAC><IAC>! */ + if (print) + printf("IAC IAC"); + goto done; + } + + i = c - TELCMD_FIRST; + if (i < 0 || i > IAC - TELCMD_FIRST) + goto pktend; + + switch (c) { + case DONT: + case DO: + case WONT: + case WILL: + case SB: + /* DONT/DO/WONT/WILL x */ + FETCH(x, sp, length); + if (x >= 0 && x < NTELOPTS) { + if (print) + (void)printf("%s %s", telcmds[i], telopts[x]); + } else { + if (print) + (void)printf("%s %#x", telcmds[i], x); + } + if (c != SB) + break; + /* IAC SB .... IAC SE */ + p = sp; + while (length > p + 1 - sp) { + if (p[0] == IAC && p[1] == SE) + break; + p++; + } + if (*p != IAC) + goto pktend; + + switch (x) { + case TELOPT_AUTHENTICATION: + if (p <= sp) + break; + FETCH(c, sp, length); + if (print) + (void)printf(" %s", STR_OR_ID(c, authcmd)); + if (p <= sp) + break; + FETCH(c, sp, length); + if (print) + (void)printf(" %s", STR_OR_ID(c, authtype)); + break; + case TELOPT_ENCRYPT: + if (p <= sp) + break; + FETCH(c, sp, length); + if (print) + (void)printf(" %s", STR_OR_ID(c, enccmd)); + if (p <= sp) + break; + FETCH(c, sp, length); + if (print) + (void)printf(" %s", STR_OR_ID(c, enctype)); break; default: - c = *sp++; - length--; - if ((i = c - TELCMD_FIRST) < 0 - || i > IAC - TELCMD_FIRST) { - (void)printf("unknown: ff%02x\n", c); - return; - } - switch (c) { - case DONT: - case DO: - case WONT: - case WILL: - case SB: - x = *sp++; /* option */ - length--; - if (x >= 0 && x < NTELOPTS) { - (void)snprintf(tnet, sizeof(tnet), - "%s %s", telcmds[i], telopts[x]); - } else { - (void)snprintf(tnet, sizeof(tnet), - "%s %#x", telcmds[i], x); - } + if (p <= sp) break; - default: - (void)snprintf(tnet, sizeof(tnet), "%s", - telcmds[i]); - } - if (c == SB) { - c = *sp++; - length--; - (void)strcat(tnet, c ? " SEND" : " IS '"); - rcp = (u_char *) sp; - i = strlen(tnet); - while (length > 0 && (x = *sp++) != IAC) - --length; - if (x == IAC) { - if (2 < vflag - && i + 16 + sp - rcp < sizeof(tnet)) { - (void)strncpy(&tnet[i], rcp, sp - rcp); - i += (sp - rcp) - 1; - tnet[i] = '\0'; - } else if (i + 8 < sizeof(tnet)) { - (void)strcat(&tnet[i], "..."); - } - if (*sp++ == SE - && i + 4 < sizeof(tnet)) - (void)strcat(tnet, c ? " SE" : "' SE"); - } else if (i + 16 < sizeof(tnet)) { - (void)strcat(tnet, " truncated!"); - } - } + FETCH(c, sp, length); + if (print) + (void)printf(" %s", STR_OR_ID(c, cmds)); break; } + while (p > sp) { + FETCH(x, sp, length); + if (print) + (void)printf(" %#x", x); + } + /* terminating IAC SE */ + if (print) + (void)printf(" SE"); + sp += 2; + length -= 2; + break; + default: + if (print) + (void)printf("%s", telcmds[i]); + goto done; + } + +done: + return sp - osp; + +trunc: + (void)printf("[|telnet]"); +pktend: + return -1; +#undef FETCH +} + +void +telnet_print(const u_char *sp, u_int length) +{ + int first = 1; + const u_char *osp; + int l; + + osp = sp; + + while (length > 0 && *sp == IAC) { + l = telnet_parse(sp, length, 0); + if (l < 0) + break; + /* * now print it */ if (Xflag && 2 < vflag) { if (first) - printf("\nTelnet:\n"); - i = sp - osp; - hex_print_with_offset(osp, i, off); - off += i; - if (i > 8) + printf("\nTelnet:"); + hex_print_with_offset(sp, l, sp - osp); + if (l > 8) printf("\n\t\t\t\t"); else - printf("%*s\t", (8 - i) * 3, ""); - safeputs(tnet); - } else { + printf("%*s\t", (8 - l) * 3, ""); + } else printf("%s", (first) ? " [telnet " : ", "); - safeputs(tnet); - } + + (void)telnet_parse(sp, length, 1); first = 0; + + sp += l; + length -= l; } if (!first) { if (Xflag && 2 < vflag) diff --git a/contrib/tcpdump/print-timed.c b/contrib/tcpdump/print-timed.c index d683c40..af73ddb 100644 --- a/contrib/tcpdump/print-timed.c +++ b/contrib/tcpdump/print-timed.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-timed.c,v 1.1 2000/10/06 05:35:37 guy Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-timed.c,v 1.3 2001/05/17 18:33:23 fenner Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -30,20 +30,12 @@ static const char rcsid[] = #include <sys/param.h> #include <sys/time.h> - #include <netinet/in.h> -#include "ip.h" -#include "udp.h" -#include "tcp.h" - -#include "timed.h" - #include <stdio.h> #include <string.h> +#include "timed.h" #include "interface.h" -#include "addrtoname.h" -#include "extract.h" /* must come after interface.h */ static char *tsptype[TSPTYPENUMBER] = { "ANY", "ADJTIME", "ACK", "MASTERREQ", "MASTERACK", "SETTIME", "MASTERUP", diff --git a/contrib/tcpdump/print-token.c b/contrib/tcpdump/print-token.c index aff3607..d2de92d 100644 --- a/contrib/tcpdump/print-token.c +++ b/contrib/tcpdump/print-token.c @@ -25,7 +25,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-token.c,v 1.11 2000/12/23 20:48:13 guy Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-token.c,v 1.13 2001/09/18 15:46:37 fenner Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -53,8 +53,8 @@ static const char rcsid[] = static inline void extract_token_addrs(const struct token_header *trp, char *fsrc, char *fdst) { - memcpy(fdst, (char *)trp->token_dhost, 6); - memcpy(fsrc, (char *)trp->token_shost, 6); + memcpy(fdst, (const char *)trp->token_dhost, 6); + memcpy(fsrc, (const char *)trp->token_shost, 6); } /* @@ -64,7 +64,7 @@ static inline void token_print(register const struct token_header *trp, register u_int length, register const u_char *fsrc, register const u_char *fdst) { - char *srcname, *dstname; + const char *srcname, *dstname; srcname = etheraddr_string(fsrc); dstname = etheraddr_string(fdst); @@ -79,18 +79,18 @@ token_print(register const struct token_header *trp, register u_int length, printf("%s %s %d: ", srcname, dstname, length); } -static char *broadcast_indicator[] = { +static const char *broadcast_indicator[] = { "Non-Broadcast", "Non-Broadcast", "Non-Broadcast", "Non-Broadcast", "All-routes", "All-routes", "Single-route", "Single-route" }; -static char *direction[] = { +static const char *direction[] = { "Forward", "Backward" }; -static char *largest_frame[] = { +static const char *largest_frame[] = { "516", "1500", "2052", @@ -112,13 +112,14 @@ token_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) { u_int caplen = h->caplen; u_int length = h->len; - struct token_header *trp; + const struct token_header *trp; u_short extracted_ethertype; struct ether_header ehdr; u_int route_len = 0, seg; - trp = (struct token_header *)p; + trp = (const struct token_header *)p; + ++infodelay; ts_print(&h->ts); if (caplen < TOKEN_HDRLEN) { @@ -207,4 +208,7 @@ token_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) default_print(p, caplen); out: putchar('\n'); + --infodelay; + if (infoprint) + info(0); } diff --git a/contrib/tcpdump/print-udp.c b/contrib/tcpdump/print-udp.c index 70daef1..c787384 100644 --- a/contrib/tcpdump/print-udp.c +++ b/contrib/tcpdump/print-udp.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.90 2000/12/23 20:55:22 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.101 2001/10/08 21:25:24 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -54,12 +54,6 @@ static const char rcsid[] = #include "ip6.h" #endif -#ifdef NOERROR -#undef NOERROR /* Solaris sucks */ -#endif -#ifdef T_UNSPEC -#undef T_UNSPEC /* SINIX does too */ -#endif #include "nameser.h" #include "nfs.h" #include "bootp.h" @@ -120,14 +114,14 @@ vat_print(const void *hdr, u_int len, register const struct udphdr *up) u_int ts = *(u_int16_t *)hdr; if ((ts & 0xf060) != 0) { /* probably vt */ - (void)printf(" udp/vt %u %d / %d", + (void)printf("udp/vt %u %d / %d", (u_int32_t)(ntohs(up->uh_ulen) - sizeof(*up)), ts & 0x3ff, ts >> 10); } else { /* probably vat */ u_int32_t i0 = (u_int32_t)ntohl(((u_int *)hdr)[0]); u_int32_t i1 = (u_int32_t)ntohl(((u_int *)hdr)[1]); - printf(" udp/vat %u c%d %u%s", + printf("udp/vat %u c%d %u%s", (u_int32_t)(ntohs(up->uh_ulen) - sizeof(*up) - 8), i0 & 0xffff, i1, i0 & 0x800000? "*" : ""); @@ -171,7 +165,7 @@ rtp_print(const void *hdr, u_int len, register const struct udphdr *up) ip += 1; len -= 1; } - printf(" udp/%s %d c%d %s%s %d %u", + printf("udp/%s %d c%d %s%s %d %u", ptype, dlen, contype, @@ -294,7 +288,6 @@ static int udp_cksum(register const struct ip *ip, register const struct udphdr *up, register int len) { - int i, tlen; union phu { struct phdr { u_int32_t src; @@ -306,33 +299,17 @@ static int udp_cksum(register const struct ip *ip, u_int16_t pa[6]; } phu; register const u_int16_t *sp; - u_int32_t sum; - tlen = ntohs(ip->ip_len) - ((const char *)up-(const char*)ip); /* pseudo-header.. */ - phu.ph.len = htons(tlen); + phu.ph.len = htons(len); phu.ph.mbz = 0; phu.ph.proto = IPPROTO_UDP; memcpy(&phu.ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t)); memcpy(&phu.ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t)); sp = &phu.pa[0]; - sum = sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5]; - - sp = (const u_int16_t *)up; - - for (i=0; i<(tlen&~1); i+= 2) - sum += *sp++; - - if (tlen & 1) { - sum += htons( (*(const u_int8_t *)sp) << 8); - } - - while (sum > 0xffff) - sum = (sum & 0xffff) + (sum >> 16); - sum = ~sum & 0xffff; - - return (sum); + return in_cksum((u_short *)up, len, + sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5]); } #ifdef INET6 @@ -396,8 +373,8 @@ static int udp6_cksum(const struct ip6_hdr *ip6, const struct udphdr *up, #define RIP_PORT 520 /*XXX*/ #define KERBEROS_SEC_PORT 750 /*XXX*/ #define L2TP_PORT 1701 /*XXX*/ -#define ISAKMP_PORT_USER1 7500 /*??? - nonstandard*/ -#define ISAKMP_PORT_USER2 8500 /*??? - nonstandard*/ +#define ISAKMP_PORT_USER1 7500 /*XXX - nonstandard*/ +#define ISAKMP_PORT_USER2 8500 /*XXX - nonstandard*/ #define RX_PORT_LOW 7000 /*XXX*/ #define RX_PORT_HIGH 7009 /*XXX*/ #define NETBIOS_NS_PORT 137 @@ -407,6 +384,10 @@ static int udp6_cksum(const struct ip6_hdr *ip6, const struct udphdr *up, #define RADIUS_NEW_PORT 1812 #define RADIUS_ACCOUNTING_PORT 1646 #define RADIUS_NEW_ACCOUNTING_PORT 1813 +#define HSRP_PORT 1985 /*XXX*/ +#define LWRES_PORT 921 +#define ZEPHYR_SRV_PORT 2103 +#define ZEPHYR_CLT_PORT 2104 #ifdef INET6 #define RIPNG_PORT 521 /*XXX*/ @@ -468,7 +449,7 @@ udp_print(register const u_char *bp, u_int length, switch (packettype) { case PT_VAT: - (void)printf("%s.%s > %s.%s:", + (void)printf("%s.%s > %s.%s: ", ipaddr_string(&ip->ip_src), udpport_string(sport), ipaddr_string(&ip->ip_dst), @@ -477,7 +458,7 @@ udp_print(register const u_char *bp, u_int length, break; case PT_WB: - (void)printf("%s.%s > %s.%s:", + (void)printf("%s.%s > %s.%s: ", ipaddr_string(&ip->ip_src), udpport_string(sport), ipaddr_string(&ip->ip_dst), @@ -497,7 +478,7 @@ udp_print(register const u_char *bp, u_int length, break; case PT_RTP: - (void)printf("%s.%s > %s.%s:", + (void)printf("%s.%s > %s.%s: ", ipaddr_string(&ip->ip_src), udpport_string(sport), ipaddr_string(&ip->ip_dst), @@ -569,11 +550,6 @@ udp_print(register const u_char *bp, u_int length, return; } } -#if 0 - (void)printf("%s.%s > %s.%s:", - ipaddr_string(&ip->ip_src), udpport_string(sport), - ipaddr_string(&ip->ip_dst), udpport_string(dport)); -#else #ifdef INET6 if (ip6) { if (ip6->ip6_nxt == IPPROTO_UDP) { @@ -600,18 +576,17 @@ udp_print(register const u_char *bp, u_int length, udpport_string(sport), udpport_string(dport)); } } -#endif if (IP_V(ip) == 4 && vflag && !fragmented) { int sum = up->uh_sum; if (sum == 0) { - (void)printf(" [no cksum]"); + (void)printf("[no cksum] "); } else if (TTEST2(cp[0], length)) { - sum = udp_cksum(ip, up, length); + sum = udp_cksum(ip, up, length + sizeof(struct udphdr)); if (sum != 0) - (void)printf(" [bad udp cksum %x!]", sum); + (void)printf("[bad udp cksum %x!] ", sum); else - (void)printf(" [udp sum ok]"); + (void)printf("[udp sum ok] "); } } #ifdef INET6 @@ -621,9 +596,9 @@ udp_print(register const u_char *bp, u_int length, if (TTEST2(cp[0], length)) { sum = udp6_cksum(ip6, up, length); if (sum != 0) - (void)printf(" [bad udp cksum %x!]", sum); + (void)printf("[bad udp cksum %x!] ", sum); else - (void)printf(" [udp sum ok]"); + (void)printf("[udp sum ok] "); } } #endif @@ -655,14 +630,16 @@ udp_print(register const u_char *bp, u_int length, krb_print((const void *)(up + 1), length); else if (ISPORT(L2TP_PORT)) l2tp_print((const u_char *)(up + 1), length); - else if (ISPORT(NETBIOS_NS_PORT)) { +#ifdef TCPDUMP_DO_SMB + else if (ISPORT(NETBIOS_NS_PORT)) nbt_udp137_print((const u_char *)(up + 1), length); - } - else if (ISPORT(NETBIOS_DGRAM_PORT)) { + else if (ISPORT(NETBIOS_DGRAM_PORT)) nbt_udp138_print((const u_char *)(up + 1), length); - } +#endif else if (dport == 3456) vat_print((const void *)(up + 1), length, up); + else if (ISPORT(ZEPHYR_SRV_PORT) || ISPORT(ZEPHYR_CLT_PORT)) + zephyr_print((const void *)(up + 1), length); /* * Since there are 10 possible ports to check, I think * a <> test would be more efficient @@ -687,14 +664,18 @@ udp_print(register const u_char *bp, u_int length, else if (ISPORT(CISCO_AUTORP_PORT)) cisco_autorp_print((const void *)(up + 1), length); else if (ISPORT(RADIUS_PORT) || - ISPORT(RADIUS_NEW_PORT) || - ISPORT(RADIUS_ACCOUNTING_PORT) || - ISPORT(RADIUS_NEW_ACCOUNTING_PORT) ) - radius_print((const u_char *)(up+1), length); + ISPORT(RADIUS_NEW_PORT) || + ISPORT(RADIUS_ACCOUNTING_PORT) || + ISPORT(RADIUS_NEW_ACCOUNTING_PORT) ) + radius_print((const u_char *)(up+1), length); + else if (dport == HSRP_PORT) + hsrp_print((const u_char *)(up + 1), length); + else if (ISPORT(LWRES_PORT)) + lwres_print((const u_char *)(up + 1), length); else - (void)printf(" udp %u", + (void)printf("udp %u", (u_int32_t)(ulen - sizeof(*up))); #undef ISPORT } else - (void)printf(" udp %u", (u_int32_t)(ulen - sizeof(*up))); + (void)printf("udp %u", (u_int32_t)(ulen - sizeof(*up))); } diff --git a/contrib/tcpdump/print-vrrp.c b/contrib/tcpdump/print-vrrp.c index 6b7ac94..9bc29d1 100644 --- a/contrib/tcpdump/print-vrrp.c +++ b/contrib/tcpdump/print-vrrp.c @@ -25,7 +25,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-vrrp.c,v 1.3 2000/10/10 05:05:08 guy Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-vrrp.c,v 1.5 2001/07/23 22:27:30 fenner Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -64,30 +64,47 @@ static const char rcsid[] = * | Authentication Data (2) | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ + +/* Type */ +#define VRRP_TYPE_ADVERTISEMENT 1 + +static const struct tok type2str[] = { + { VRRP_TYPE_ADVERTISEMENT, "advertisement" }, + { 0, NULL } +}; + +/* Auth Type */ +#define VRRP_AUTH_NONE 0 +#define VRRP_AUTH_SIMPLE 1 +#define VRRP_AUTH_AH 2 + +static const struct tok auth2str[] = { + { VRRP_AUTH_NONE, "none" }, + { VRRP_AUTH_SIMPLE, "simple" }, + { VRRP_AUTH_AH, "ah" }, + { 0, NULL } +}; + void vrrp_print(register const u_char *bp, register u_int len, int ttl) { int version, type, auth_type; - char *type_s; + const char *type_s; TCHECK(bp[0]); version = (bp[0] & 0xf0) >> 4; type = bp[0] & 0x0f; - if (type == 1) - type_s = "advertise"; - else - type_s = "unknown"; + type_s = tok2str(type2str, "type#%d", type); printf("VRRPv%d-%s %d: ", version, type_s, len); if (ttl != 255) printf("[ttl=%d!] ", ttl); - if (version != 2 || type != 1) + if (version != 2 || type != VRRP_TYPE_ADVERTISEMENT) return; TCHECK(bp[2]); printf("vrid=%d prio=%d", bp[1], bp[2]); TCHECK(bp[5]); auth_type = bp[4]; - if (auth_type != 0) - printf(" authtype=%d", auth_type); + printf(" authtype=%s", tok2str(auth2str, NULL, auth_type)); printf(" intvl=%d", bp[5]); if (vflag) { int naddrs = bp[3]; @@ -109,9 +126,11 @@ vrrp_print(register const u_char *bp, register u_int len, int ttl) c = ','; bp += 4; } - if (auth_type == 1) { /* simple text password */ + if (auth_type == VRRP_AUTH_SIMPLE) { /* simple text password */ TCHECK(bp[7]); - printf(" auth %.8s", bp); + printf(" auth \""); + fn_printn(bp, 8, NULL); + printf("\""); } } return; diff --git a/contrib/tcpdump/print-wb.c b/contrib/tcpdump/print-wb.c index fa10541..7b0281b 100644 --- a/contrib/tcpdump/print-wb.c +++ b/contrib/tcpdump/print-wb.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-wb.c,v 1.25 1999/11/21 09:37:03 fenner Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-wb.c,v 1.26 2001/06/27 05:37:19 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -77,6 +77,10 @@ struct pkt_hdr { #define PT_PREQ 5 /* page vector request */ #define PT_PREP 7 /* page vector reply */ +#ifdef PF_USER +#undef PF_USER /* {Digital,Tru64} UNIX define this, alas */ +#endif + /* flags */ #define PF_USER 0x01 /* hint that packet has interactive data */ #define PF_VIS 0x02 /* only visible ops wanted */ diff --git a/contrib/tcpdump/print-zephyr.c b/contrib/tcpdump/print-zephyr.c new file mode 100644 index 0000000..5792e60 --- /dev/null +++ b/contrib/tcpdump/print-zephyr.c @@ -0,0 +1,311 @@ +/* + * Decode and print Zephyr packets. + * + * Copyright (c) 2001 Nickolai Zeldovich <kolya@MIT.EDU> + * 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. + * The name of the author(s) 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. + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-zephyr.c,v 1.2 2001/09/11 02:37:12 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdio.h> +#include <ctype.h> +#include <string.h> +#include <stdlib.h> +#include <sys/types.h> + +#include "interface.h" + +struct z_packet { + char *version; + int numfields; + int kind; + char *uid; + int port; + int auth; + int authlen; + char *authdata; + char *class; + char *inst; + char *opcode; + char *sender; + char *recipient; + char *format; + int cksum; + int multi; + char *multi_uid; + /* Other fields follow here.. */ +}; + +enum { + Z_PACKET_UNSAFE = 0, + Z_PACKET_UNACKED, + Z_PACKET_ACKED, + Z_PACKET_HMACK, + Z_PACKET_HMCTL, + Z_PACKET_SERVACK, + Z_PACKET_SERVNAK, + Z_PACKET_CLIENTACK, + Z_PACKET_STAT +} z_packet_type; + +static struct tok z_types[] = { + { Z_PACKET_UNSAFE, "unsafe" }, + { Z_PACKET_UNACKED, "unacked" }, + { Z_PACKET_ACKED, "acked" }, + { Z_PACKET_HMACK, "hm-ack" }, + { Z_PACKET_HMCTL, "hm-ctl" }, + { Z_PACKET_SERVACK, "serv-ack" }, + { Z_PACKET_SERVNAK, "serv-nak" }, + { Z_PACKET_CLIENTACK, "client-ack" }, + { Z_PACKET_STAT, "stat" } +}; + +char z_buf[256]; + +static char * +parse_field(char **pptr, int *len) +{ + char *s; + + if (*len <= 0 || !pptr || !*pptr) + return NULL; + if (*pptr > (char *) snapend) + return NULL; + + s = *pptr; + while (*pptr <= (char *) snapend && *len >= 0 && **pptr) { + (*pptr)++; + (*len)--; + } + (*pptr)++; + (*len)--; + if (*len < 0 || *pptr > (char *) snapend) + return NULL; + return s; +} + +static const char * +z_triple(char *class, char *inst, char *recipient) +{ + if (!*recipient) + recipient = "*"; + snprintf(z_buf, sizeof(z_buf), "<%s,%s,%s>", class, inst, recipient); + z_buf[sizeof(z_buf)-1] = '\0'; + return z_buf; +} + +static const char * +str_to_lower(char *string) +{ + strncpy(z_buf, string, sizeof(z_buf)); + z_buf[sizeof(z_buf)-1] = '\0'; + + string = z_buf; + while (*string) { + *string = tolower(*string); + string++; + } + + return z_buf; +} + +void +zephyr_print(const u_char *cp, int length) +{ + struct z_packet z; + char *parse = (char *) cp; + int parselen = length; + char *s; + int lose = 0; + +#define PARSE_STRING \ + s = parse_field(&parse, &parselen); \ + if (!s) lose = 1; + +#define PARSE_FIELD_INT(field) \ + PARSE_STRING \ + if (!lose) field = strtol(s, 0, 16); + +#define PARSE_FIELD_STR(field) \ + PARSE_STRING \ + if (!lose) field = s; + + PARSE_FIELD_STR(z.version); + if (lose) return; + if (strncmp(z.version, "ZEPH", 4)) + return; + + PARSE_FIELD_INT(z.numfields); + PARSE_FIELD_INT(z.kind); + PARSE_FIELD_STR(z.uid); + PARSE_FIELD_INT(z.port); + PARSE_FIELD_INT(z.auth); + PARSE_FIELD_INT(z.authlen); + PARSE_FIELD_STR(z.authdata); + PARSE_FIELD_STR(z.class); + PARSE_FIELD_STR(z.inst); + PARSE_FIELD_STR(z.opcode); + PARSE_FIELD_STR(z.sender); + PARSE_FIELD_STR(z.recipient); + PARSE_FIELD_STR(z.format); + PARSE_FIELD_INT(z.cksum); + PARSE_FIELD_INT(z.multi); + PARSE_FIELD_STR(z.multi_uid); + + if (lose) { + printf(" [|zephyr] (%d)", length); + return; + } + + printf(" zephyr"); + if (strncmp(z.version+4, "0.2", 3)) { + printf(" v%s", z.version+4); + return; + } + + printf(" %s", tok2str(z_types, "type %d", z.kind)); + if (z.kind == Z_PACKET_SERVACK) { + /* Initialization to silence warnings */ + char *ackdata = NULL; + PARSE_FIELD_STR(ackdata); + if (!lose && strcmp(ackdata, "SENT")) + printf("/%s", str_to_lower(ackdata)); + } + if (*z.sender) printf(" %s", z.sender); + + if (!strcmp(z.class, "USER_LOCATE")) { + if (!strcmp(z.opcode, "USER_HIDE")) + printf(" hide"); + else if (!strcmp(z.opcode, "USER_UNHIDE")) + printf(" unhide"); + else + printf(" locate %s", z.inst); + return; + } + + if (!strcmp(z.class, "ZEPHYR_ADMIN")) { + printf(" zephyr-admin %s", str_to_lower(z.opcode)); + return; + } + + if (!strcmp(z.class, "ZEPHYR_CTL")) { + if (!strcmp(z.inst, "CLIENT")) { + if (!strcmp(z.opcode, "SUBSCRIBE") || + !strcmp(z.opcode, "SUBSCRIBE_NODEFS") || + !strcmp(z.opcode, "UNSUBSCRIBE")) { + + printf(" %ssub%s", strcmp(z.opcode, "SUBSCRIBE") ? "un" : "", + strcmp(z.opcode, "SUBSCRIBE_NODEFS") ? "" : + "-nodefs"); + if (z.kind != Z_PACKET_SERVACK) { + /* Initialization to silence warnings */ + char *c = NULL, *i = NULL, *r = NULL; + PARSE_FIELD_STR(c); + PARSE_FIELD_STR(i); + PARSE_FIELD_STR(r); + if (!lose) printf(" %s", z_triple(c, i, r)); + } + return; + } + + if (!strcmp(z.opcode, "GIMME")) { + printf(" ret"); + return; + } + + if (!strcmp(z.opcode, "GIMMEDEFS")) { + printf(" gimme-defs"); + return; + } + + if (!strcmp(z.opcode, "CLEARSUB")) { + printf(" clear-subs"); + return; + } + + printf(" %s", str_to_lower(z.opcode)); + return; + } + + if (!strcmp(z.inst, "HM")) { + printf(" %s", str_to_lower(z.opcode)); + return; + } + + if (!strcmp(z.inst, "REALM")) { + if (!strcmp(z.opcode, "ADD_SUBSCRIBE")) + printf(" realm add-subs"); + if (!strcmp(z.opcode, "REQ_SUBSCRIBE")) + printf(" realm req-subs"); + if (!strcmp(z.opcode, "RLM_SUBSCRIBE")) + printf(" realm rlm-sub"); + if (!strcmp(z.opcode, "RLM_UNSUBSCRIBE")) + printf(" realm rlm-unsub"); + return; + } + } + + if (!strcmp(z.class, "HM_CTL")) { + printf(" hm_ctl %s", str_to_lower(z.inst)); + printf(" %s", str_to_lower(z.opcode)); + return; + } + + if (!strcmp(z.class, "HM_STAT")) { + if (!strcmp(z.inst, "HMST_CLIENT") && !strcmp(z.opcode, "GIMMESTATS")) { + printf(" get-client-stats"); + return; + } + } + + if (!strcmp(z.class, "WG_CTL")) { + printf(" wg_ctl %s", str_to_lower(z.inst)); + printf(" %s", str_to_lower(z.opcode)); + return; + } + + if (!strcmp(z.class, "LOGIN")) { + if (!strcmp(z.opcode, "USER_FLUSH")) { + printf(" flush_locs"); + return; + } + + if (!strcmp(z.opcode, "NONE") || + !strcmp(z.opcode, "OPSTAFF") || + !strcmp(z.opcode, "REALM-VISIBLE") || + !strcmp(z.opcode, "REALM-ANNOUNCED") || + !strcmp(z.opcode, "NET-VISIBLE") || + !strcmp(z.opcode, "NET-ANNOUNCED")) { + printf(" set-exposure %s", str_to_lower(z.opcode)); + return; + } + } + + if (!*z.recipient) + z.recipient = "*"; + + printf(" to %s", z_triple(z.class, z.inst, z.recipient)); + if (*z.opcode) + printf(" op %s", z.opcode); + return; +} diff --git a/contrib/tcpdump/route6d.h b/contrib/tcpdump/route6d.h index dba49fb..2adf409 100644 --- a/contrib/tcpdump/route6d.h +++ b/contrib/tcpdump/route6d.h @@ -1,5 +1,33 @@ /* - * $Header: /tcpdump/master/tcpdump/route6d.h,v 1.2 2000/04/28 11:14:49 itojun Exp $ + * Copyright (C) 1995, 1996, 1997 and 1998 WIDE Project. + * 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. Neither the name of the project 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 PROJECT 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 PROJECT 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. + */ +/* + * $Header: /tcpdump/master/tcpdump/route6d.h,v 1.3 2001/10/22 04:27:47 itojun Exp $ */ #define RIP6_VERSION 1 diff --git a/contrib/tcpdump/rx.h b/contrib/tcpdump/rx.h index fe6f963..247be99 100644 --- a/contrib/tcpdump/rx.h +++ b/contrib/tcpdump/rx.h @@ -1,7 +1,29 @@ /* + * Copyright: (c) 2000 United States Government as represented by the + * Secretary of the Navy. 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. 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. + */ +/* * Rx protocol format * - * $Id: rx.h,v 1.3 2000/10/03 02:55:02 itojun Exp $ + * $Id: rx.h,v 1.5 2001/10/22 04:23:37 itojun Exp $ */ #define FS_RX_PORT 7000 @@ -57,6 +79,8 @@ struct rx_header { #define RX_LAST_PACKET 4 #define RX_MORE_PACKETS 8 #define RX_FREE_PACKET 16 +#define RX_SLOW_START_OK 32 +#define RX_JUMBO_PACKET 32 u_int8_t userStatus; u_int8_t securityIndex; u_int16_t spare; /* How clever: even though the AFS */ @@ -65,7 +89,7 @@ struct rx_header { /* encoded _after_ the spare field */ /* I wasted a day figuring that out! */ -#define NUM_RX_FLAGS 5 +#define NUM_RX_FLAGS 7 #define RX_MAXACKS 255 diff --git a/contrib/tcpdump/sctpConstants.h b/contrib/tcpdump/sctpConstants.h new file mode 100644 index 0000000..3267e83 --- /dev/null +++ b/contrib/tcpdump/sctpConstants.h @@ -0,0 +1,576 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/sctpConstants.h,v 1.2 2001/06/28 10:17:22 guy Exp $ (LBL) */ + +/* SCTP reference Implementation Copyright (C) 1999 Cisco And Motorola + * + * 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. Neither the name of Cisco nor of Motorola 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. + * + * This file is part of the SCTP reference Implementation + * + * + * Please send any bug reports or fixes you make to one of the following email + * addresses: + * + * rstewar1@email.mot.com + * kmorneau@cisco.com + * qxie1@email.mot.com + * + * Any bugs reported given to us we will try to fix... any fixes shared will + * be incorperated into the next SCTP release. + */ + + +#ifndef __sctpConstants_h__ +#define __sctpConstants_h__ + + + /* If you wish to use MD5 instead of SLA uncomment the line + * below. Why you would like to do this: + * a) There may be IPR on SHA-1, or so the FIP-180-1 page says, + * b) MD5 is 3 times faster (has coded here). + * + * The disadvantage is, it is thought that MD5 has been + * cracked... see RFC2104. + */ +/*#define USE_MD5 1*/ + +/* the SCTP protocol signature + * this includes the version number + * encoded in the last 4 bits of the + * signature. + */ +#define PROTO_SIGNATURE_A 0x30000000 + +#define SCTP_VERSION_NUMBER 0x3 + +#define MAX_TSN 0xffffffff +#define MAX_SEQ 0xffff + +/* option: + * If you comment out the following you will + * receive the old behavior of obeying cwnd for + * the fast retransmit algorithm. With this defined + * a FR happens right away with-out waiting for the + * flightsize to drop below the cwnd value (which + * is reduced by the FR to 1/2 the inflight packets). + */ +#define SCTP_IGNORE_CWND_ON_FR 1 +/* default max I can burst out after a fast retransmit */ +#define SCTP_DEF_MAX_BURST 4 + +/* Packet transmit states in the sent + * field in the SCTP_transmitOnQueue struct + */ +#define SCTP_DATAGRAM_UNSENT 0 +#define SCTP_DATAGRAM_SENT 1 +#define SCTP_DATAGRAM_RESEND1 2 /* not used */ +#define SCTP_DATAGRAM_RESEND2 3 /* not used */ +#define SCTP_DATAGRAM_RESEND3 4 /* not used */ +#define SCTP_DATAGRAM_RESEND 5 +#define SCTP_DATAGRAM_ACKED 10010 +#define SCTP_DATAGRAM_INBOUND 10011 +#define SCTP_READY_TO_TRANSMIT 10012 +#define SCTP_DATAGRAM_MARKED 20010 + +#define MAX_FSID 64 /* debug 5 ints used for cc dynamic tracking */ + +/* The valid defines for all message + * types know to SCTP. 0 is reserved + */ +#define SCTP_MSGTYPE_MASK 0xff + +#define SCTP_DATA 0x00 +#define SCTP_INITIATION 0x01 +#define SCTP_INITIATION_ACK 0x02 +#define SCTP_SELECTIVE_ACK 0x03 +#define SCTP_HEARTBEAT_REQUEST 0x04 +#define SCTP_HEARTBEAT_ACK 0x05 +#define SCTP_ABORT_ASSOCIATION 0x06 +#define SCTP_SHUTDOWN 0x07 +#define SCTP_SHUTDOWN_ACK 0x08 +#define SCTP_OPERATION_ERR 0x09 +#define SCTP_COOKIE_ECHO 0x0a +#define SCTP_COOKIE_ACK 0x0b +#define SCTP_ECN_ECHO 0x0c +#define SCTP_ECN_CWR 0x0d +#define SCTP_SHUTDOWN_COMPLETE 0x0e +#define SCTP_FORWARD_CUM_TSN 0xc0 +#define SCTP_RELIABLE_CNTL 0xc1 +#define SCTP_RELIABLE_CNTL_ACK 0xc2 + +/* ABORT and SHUTDOWN COMPLETE FLAG */ +#define SCTP_HAD_NO_TCB 0x01 + +/* Data Chuck Specific Flags */ +#define SCTP_DATA_FRAG_MASK 0x03 +#define SCTP_DATA_MIDDLE_FRAG 0x00 +#define SCTP_DATA_LAST_FRAG 0x01 +#define SCTP_DATA_FIRST_FRAG 0x02 +#define SCTP_DATA_NOT_FRAG 0x03 +#define SCTP_DATA_UNORDERED 0x04 + +#define SCTP_CRC_ENABLE_BIT 0x01 /* lower bit of reserved */ + +#define isSCTPControl(a) (a->chunkID != SCTP_DATA) +#define isSCTPData(a) (a->chunkID == SCTP_DATA) + +/* sctp parameter types for init/init-ack */ + +#define SCTP_IPV4_PARAM_TYPE 0x0005 +#define SCTP_IPV6_PARAM_TYPE 0x0006 +#define SCTP_RESPONDER_COOKIE 0x0007 +#define SCTP_UNRECOG_PARAM 0x0008 +#define SCTP_COOKIE_PRESERVE 0x0009 +#define SCTP_HOSTNAME_VIA_DNS 0x000b +#define SCTP_RESTRICT_ADDR_TO 0x000c + +#define SCTP_ECN_I_CAN_DO_ECN 0x8000 +#define SCTP_OPERATION_SUCCEED 0x4001 +#define SCTP_ERROR_NOT_EXECUTED 0x4002 + +#define SCTP_UNRELIABLE_STRM 0xc000 +#define SCTP_ADD_IP_ADDRESS 0xc001 +#define SCTP_DEL_IP_ADDRESS 0xc002 +#define SCTP_STRM_FLOW_LIMIT 0xc003 +#define SCTP_PARTIAL_CSUM 0xc004 +#define SCTP_ERROR_CAUSE_TLV 0xc005 +#define SCTP_MIT_STACK_NAME 0xc006 +#define SCTP_SETADDRESS_PRIMARY 0xc007 + +/* bits for TOS field */ +#define SCTP_ECT_BIT 0x02 +#define SCTP_CE_BIT 0x01 + +/* error codes */ +#define SCTP_OP_ERROR_NO_ERROR 0x0000 +#define SCTP_OP_ERROR_INV_STRM 0x0001 +#define SCTP_OP_ERROR_MISS_PARAM 0x0002 +#define SCTP_OP_ERROR_STALE_COOKIE 0x0003 +#define SCTP_OP_ERROR_NO_RESOURCE 0x0004 +#define SCTP_OP_ERROR_DNS_FAILED 0x0005 +#define SCTP_OP_ERROR_UNK_CHUNK 0x0006 +#define SCTP_OP_ERROR_INV_PARAM 0x0007 +#define SCTP_OP_ERROR_UNK_PARAM 0x0008 +#define SCTP_OP_ERROR_NO_USERD 0x0009 +#define SCTP_OP_ERROR_COOKIE_SHUT 0x000a +#define SCTP_OP_ERROR_DELETE_LAST 0x000b +#define SCTP_OP_ERROR_RESOURCE_SHORT 0x000c + +#define SCTP_MAX_ERROR_CAUSE 12 + +/* empty error causes i.e. nothing but the cause + * are SCTP_OP_ERROR_NO_RESOURCE, SCTP_OP_ERROR_INV_PARAM, + * SCTP_OP_ERROR_COOKIE_SHUT. + */ + +/* parameter for Heart Beat */ +#define HEART_BEAT_PARAM 0x0001 + + + +/* send options for SCTP + */ +#define SCTP_ORDERED_DELIVERY 0x01 +#define SCTP_NON_ORDERED_DELIVERY 0x02 +#define SCTP_DO_CRC16 0x08 +#define SCTP_MY_ADDRESS_ONLY 0x10 + +/* below turns off above */ +#define SCTP_FLEXIBLE_ADDRESS 0x20 +#define SCTP_NO_HEARTBEAT 0x40 + +/* mask to get sticky */ +#define SCTP_STICKY_OPTIONS_MASK 0x0c + +/* MTU discovery flags */ +#define SCTP_DONT_FRAGMENT 0x0100 +#define SCTP_FRAGMENT_OK 0x0200 + + +/* SCTP state defines for internal state machine */ +#define SCTP_STATE_EMPTY 0x0000 +#define SCTP_STATE_INUSE 0x0001 +#define SCTP_STATE_COOKIE_WAIT 0x0002 +#define SCTP_STATE_COOKIE_SENT 0x0004 +#define SCTP_STATE_OPEN 0x0008 +#define SCTP_STATE_SHUTDOWN 0x0010 +#define SCTP_STATE_SHUTDOWN_RECV 0x0020 +#define SCTP_STATE_SHUTDOWN_ACK_SENT 0x0040 +#define SCTP_STATE_SHUTDOWN_PEND 0x0080 +#define SCTP_STATE_MASK 0x007f +/* SCTP reachability state for each address */ +#define SCTP_ADDR_NOT_REACHABLE 1 +#define SCTP_ADDR_REACHABLE 2 +#define SCTP_ADDR_NOHB 4 +#define SCTP_ADDR_BEING_DELETED 8 + +/* How long a cookie lives */ +#define SCTP_DEFAULT_COOKIE_LIFE 60 /* seconds */ + +/* resource limit of streams */ +#define MAX_SCTP_STREAMS 2048 + + +/* guess at how big to make the TSN mapping array */ +#define SCTP_STARTING_MAPARRAY 10000 + +/* Here we define the timer types used + * by the implementation has + * arguments in the set/get timer type calls. + */ +#define SCTP_TIMER_INIT 0 +#define SCTP_TIMER_RECV 1 +#define SCTP_TIMER_SEND 2 +#define SCTP_TIMER_SHUTDOWN 3 +#define SCTP_TIMER_HEARTBEAT 4 +#define SCTP_TIMER_PMTU 5 +/* number of timer types in the base SCTP + * structure used in the set/get and has + * the base default. + */ +#define SCTP_NUM_TMRS 6 + + + +#define SCTP_IPV4_ADDRESS 2 +#define SCTP_IPV6_ADDRESS 4 + +/* timer types */ +#define SctpTimerTypeNone 0 +#define SctpTimerTypeSend 1 +#define SctpTimerTypeInit 2 +#define SctpTimerTypeRecv 3 +#define SctpTimerTypeShutdown 4 +#define SctpTimerTypeHeartbeat 5 +#define SctpTimerTypeCookie 6 +#define SctpTimerTypeNewCookie 7 +#define SctpTimerTypePathMtuRaise 8 +#define SctpTimerTypeShutdownAck 9 +#define SctpTimerTypeRelReq 10 + +/* Here are the timer directives given to the + * user provided function + */ +#define SCTP_TIMER_START 1 +#define SCTP_TIMER_STOP 2 + +/* running flag states in timer structure */ +#define SCTP_TIMER_IDLE 0x0 +#define SCTP_TIMER_EXPIRED 0x1 +#define SCTP_TIMER_RUNNING 0x2 + + +/* number of simultaneous timers running */ +#define SCTP_MAX_NET_TIMERS 6 /* base of where net timers start */ +#define SCTP_NUMBER_TIMERS 12 /* allows up to 6 destinations */ + + +/* Of course we really don't collect stale cookies, being + * folks of decerning taste. However we do count them, if + * we get to many before the association comes up.. we + * give up. Below is the constant that dictates when + * we give it up...this is a implemenation dependant + * treatment. In ours we do not ask for a extension of + * time, but just retry this many times... + */ +#define SCTP_MAX_STALE_COOKIES_I_COLLECT 10 + +/* max number of TSN's dup'd that I will hold */ +#define SCTP_MAX_DUP_TSNS 20 + +/* Here we define the types used when + * setting the retry ammounts. + */ +/* constants for type of set */ +#define SCTP_MAXATTEMPT_INIT 2 +#define SCTP_MAXATTEMPT_SEND 3 + +/* Here we define the default timers and the + * default number of attemts we make for + * each respective side (send/init). + */ + +/* init timer def = 3sec */ +#define SCTP_INIT_SEC 3 +#define SCTP_INIT_NSEC 0 + +/* send timer def = 3 seconds */ +#define SCTP_SEND_SEC 1 +#define SCTP_SEND_NSEC 0 + +/* recv timer def = 200ms (in nsec) */ +#define SCTP_RECV_SEC 0 +#define SCTP_RECV_NSEC 200000000 + +/* 30 seconds + RTO */ +#define SCTP_HB_SEC 30 +#define SCTP_HB_NSEC 0 + + +/* 300 ms */ +#define SCTP_SHUTDOWN_SEC 0 +#define SCTP_SHUTDOWN_NSEC 300000000 + +#define SCTP_RTO_UPPER_BOUND 60000000 /* 60 sec in micro-second's */ +#define SCTP_RTO_UPPER_BOUND_SEC 60 /* for the init timer */ +#define SCTP_RTO_LOWER_BOUND 1000000 /* 1 sec in micro-sec's */ + +#define SCTP_DEF_MAX_INIT 8 +#define SCTP_DEF_MAX_SEND 10 + +#define SCTP_DEF_PMTU_RAISE 600 /* 10 Minutes between raise attempts */ +#define SCTP_DEF_PMTU_MIN 600 + +#define SCTP_MSEC_IN_A_SEC 1000 +#define SCTP_USEC_IN_A_SEC 1000000 +#define SCTP_NSEC_IN_A_SEC 1000000000 + + +/* Events that SCTP will look for, these + * are or'd together to declare what SCTP + * wants. Each select mask/poll list should be + * set for the fd, if the bit is on. + */ +#define SCTP_EVENT_READ 0x000001 +#define SCTP_EVENT_WRITE 0x000002 +#define SCTP_EVENT_EXCEPT 0x000004 + +/* The following constant is a value for this + * particular implemenation. It is quite arbitrary and + * is used to limit how much data will be queued up to + * a sender, waiting for cwnd to be larger than flightSize. + * All implementations will need this protection is some + * way due to buffer size constraints. + */ + +#define SCTP_MAX_OUTSTANDING_DG 10000 + + + +/* This constant (SCTP_MAX_READBUFFER) define + * how big the read/write buffer is + * when we enter the fd event notification + * the buffer is put on the stack, so the bigger + * it is the more stack you chew up, however it + * has got to be big enough to handle the bigest + * message this O/S will send you. In solaris + * with sockets (not TLI) we end up at a value + * of 64k. In TLI we could do partial reads to + * get it all in with less hassel.. but we + * write to sockets for generality. + */ +#define SCTP_MAX_READBUFFER 65536 +#define SCTP_ADDRMAX 60 + +/* amount peer is obligated to have in rwnd or + * I will abort + */ +#define SCTP_MIN_RWND 1500 + +#define SCTP_WINDOW_MIN 1500 /* smallest rwnd can be */ +#define SCTP_WINDOW_MAX 1048576 /* biggest I can grow rwnd to + * My playing around suggests a + * value greater than 64k does not + * do much, I guess via the kernel + * limitations on the stream/socket. + */ + +#define SCTP_MAX_BUNDLE_UP 256 /* max number of chunks I can bundle */ + +/* I can handle a 1meg re-assembly */ +#define SCTP_DEFAULT_MAXMSGREASM 1048576 + + +#define SCTP_DEFAULT_MAXWINDOW 32768 /* default rwnd size */ +#define SCTP_DEFAULT_MAXSEGMENT 1500 /* MTU size, this is the default + * to which we set the smallestMTU + * size to. This governs what is the + * largest size we will use, of course + * PMTU will raise this up to + * the largest interface MTU or the + * ceiling below if there is no + * SIOCGIFMTU. + */ +#ifdef LYNX +#define DEFAULT_MTU_CEILING 1500 /* Since Lynx O/S is brain dead + * in the way it handles the + * raw IP socket, insisting + * on makeing its own IP + * header, we limit the growth + * to that of the e-net size + */ +#else +#define DEFAULT_MTU_CEILING 2048 /* If no SIOCGIFMTU, highest value + * to raise the PMTU to, i.e. + * don't try to raise above this + * value. Tune this per your + * largest MTU interface if your + * system does not support the + * SIOCGIFMTU ioctl. + */ +#endif +#define SCTP_DEFAULT_MINSEGMENT 512 /* MTU size ... if no mtu disc */ +#define SCTP_HOW_MANY_SECRETS 2 /* how many secrets I keep */ +/* This is how long a secret lives, NOT how long a cookie lives */ +#define SCTP_HOW_LONG_COOKIE_LIVE 3600 /* how many seconds the current secret will live */ + +#define SCTP_NUMBER_OF_SECRETS 8 /* or 8 * 4 = 32 octets */ +#define SCTP_SECRET_SIZE 32 /* number of octets in a 256 bits */ + +#ifdef USE_MD5 +#define SCTP_SIGNATURE_SIZE 16 /* size of a MD5 signature */ +#else +#define SCTP_SIGNATURE_SIZE 20 /* size of a SLA-1 signature */ +#endif +/* Here are the notification constants + * that the code and upper layer will get + */ + +/* association is up */ +#define SCTP_NOTIFY_ASSOC_UP 1 + +/* association is down */ +#define SCTP_NOTIFY_ASSOC_DOWN 2 + +/* interface on a association is down + * and out of consideration for selection. + */ +#define SCTP_NOTIFY_INTF_DOWN 3 + +/* interface on a association is up + * and now back in consideration for selection. + */ +#define SCTP_NOTIFY_INTF_UP 4 + +/* The given datagram cannot be delivered + * to the peer, this will probably be followed + * by a SCTP_NOTFIY_ASSOC_DOWN. + */ +#define SCTP_NOTIFY_DG_FAIL 5 + +/* Sent dg on non-open stream extreme code error! + */ +#define SCTP_NOTIFY_STRDATA_ERR 6 + +#define SCTP_NOTIFY_ASSOC_ABORTED 7 + +/* The stream ones are not used yet, but could + * be when a association opens. + */ +#define SCTP_NOTIFY_PEER_OPENED_STR 8 +#define SCTP_NOTIFY_STREAM_OPENED_OK 9 + +/* association sees a restart event */ +#define SCTP_NOTIFY_ASSOC_RESTART 10 + +/* a user requested HB returned */ +#define SCTP_NOTIFY_HB_RESP 11 + +/* a result from a REL-REQ */ +#define SCTP_NOTIFY_RELREQ_RESULT_OK 12 +#define SCTP_NOTIFY_RELREQ_RESULT_FAILED 13 + +/* clock variance is 10ms or 10,000 us's */ +#define SCTP_CLOCK_GRAINULARITY 10000 + +#define IP_HDR_SIZE 40 /* we use the size of a IP6 header here + * this detracts a small amount for ipv4 + * but it simplifies the ipv6 addition + */ + +#define SCTP_NUM_FDS 3 + +/* raw IP filedescriptor */ +#define SCTP_FD_IP 0 +/* raw ICMP filedescriptor */ +#define SCTP_FD_ICMP 1 +/* processes contact me for requests here */ +#define SCTP_REQUEST 2 + + +#define SCTP_DEAMON_PORT 9899 + + +#ifndef IPPROTO_SCTP +#define IPPROTO_SCTP 132 /* the Official IANA number :-) */ +#endif + +/* Deamon registration message types/responses */ +#define DEAMON_REGISTER 0x01 +#define DEAMON_REGISTER_ACK 0x02 +#define DEAMON_DEREGISTER 0x03 +#define DEAMON_DEREGISTER_ACK 0x04 +#define DEAMON_CHECKADDR_LIST 0x05 + +#define DEAMON_MAGIC_VER_LEN 0xff + +/* max times I will attempt to send a message to deamon */ +#define SCTP_MAX_ATTEMPTS_AT_DEAMON 5 +#define SCTP_TIMEOUT_IN_POLL_FOR_DEAMON 1500 /* 1.5 seconds */ + +/* modular comparison */ +/* True if a > b (mod = M) */ +#define compare_with_wrap(a, b, M) ((a > b) && ((a - b) < (M >> 1))) || \ + ((b > a) && ((b - a) > (M >> 1))) + +#ifndef TIMEVAL_TO_TIMESPEC +#define TIMEVAL_TO_TIMESPEC(tv, ts) \ +{ \ + (ts)->tv_sec = (tv)->tv_sec; \ + (ts)->tv_nsec = (tv)->tv_usec * 1000; \ +} +#endif + +/* pegs */ +#define SCTP_NUMBER_OF_PEGS 21 +/* peg index's */ +#define SCTP_PEG_SACKS_SEEN 0 +#define SCTP_PEG_SACKS_SENT 1 +#define SCTP_PEG_TSNS_SENT 2 +#define SCTP_PEG_TSNS_RCVD 3 +#define SCTP_DATAGRAMS_SENT 4 +#define SCTP_DATAGRAMS_RCVD 5 +#define SCTP_RETRANTSN_SENT 6 +#define SCTP_DUPTSN_RECVD 7 +#define SCTP_HBR_RECV 8 +#define SCTP_HBA_RECV 9 +#define SCTP_HB_SENT 10 +#define SCTP_DATA_DG_SENT 11 +#define SCTP_DATA_DG_RECV 12 +#define SCTP_TMIT_TIMER 13 +#define SCTP_RECV_TIMER 14 +#define SCTP_HB_TIMER 15 +#define SCTP_FAST_RETRAN 16 +#define SCTP_PEG_TSNS_READ 17 +#define SCTP_NONE_LFT_TO 18 +#define SCTP_NONE_LFT_RWND 19 +#define SCTP_NONE_LFT_CWND 20 + + + +#endif + diff --git a/contrib/tcpdump/sctpHeader.h b/contrib/tcpdump/sctpHeader.h new file mode 100644 index 0000000..b4a131a --- /dev/null +++ b/contrib/tcpdump/sctpHeader.h @@ -0,0 +1,323 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/sctpHeader.h,v 1.3 2001/08/01 03:34:00 guy Exp $ (LBL) */ + +/* SCTP reference Implementation Copyright (C) 1999 Cisco And Motorola + * + * 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. + * + * 4. Neither the name of Cisco nor of Motorola 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. + * + * This file is part of the SCTP reference Implementation + * + * + * Please send any bug reports or fixes you make to one of the following email + * addresses: + * + * rstewar1@email.mot.com + * kmorneau@cisco.com + * qxie1@email.mot.com + * + * Any bugs reported given to us we will try to fix... any fixes shared will + * be incorperated into the next SCTP release. + */ + + +#ifndef __sctpHeader_h__ +#define __sctpHeader_h__ + +#include <sctpConstants.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* the sctp common header */ + +#ifdef TRU64 + #define _64BITS 1 +#endif + +struct sctpHeader{ + u_short source; + u_short destination; + u_int verificationTag; + u_int adler32; +}; + +/* various descriptor parsers */ + +struct sctpChunkDesc{ + u_char chunkID; + u_char chunkFlg; + u_short chunkLength; +}; + +struct sctpParamDesc{ + u_short paramType; + u_short paramLength; +}; + + +struct sctpRelChunkDesc{ + struct sctpChunkDesc chk; + u_int serialNumber; +}; + +struct sctpVendorSpecificParam { + struct sctpParamDesc p; /* type must be 0xfffe */ + u_int vendorId; /* vendor ID from RFC 1700 */ + u_short vendorSpecificType; + u_short vendorSpecificLen; +}; + + +/* Structures for the control parts */ + + + +/* Sctp association init request/ack */ + +/* this is used for init ack, too */ +struct sctpInitiation{ + u_int initTag; /* tag of mine */ + u_int rcvWindowCredit; /* rwnd */ + u_short NumPreopenStreams; /* OS */ + u_short MaxInboundStreams; /* MIS */ + u_int initialTSN; + /* optional param's follow in sctpParamDesc form */ +}; + +struct sctpV4IpAddress{ + struct sctpParamDesc p; /* type is set to SCTP_IPV4_PARAM_TYPE, len=10 */ + u_int ipAddress; +}; + + +struct sctpV6IpAddress{ + struct sctpParamDesc p; /* type is set to SCTP_IPV6_PARAM_TYPE, len=22 */ + u_char ipAddress[16]; +}; + +struct sctpDNSName{ + struct sctpParamDesc param; + u_char name[1]; +}; + + +struct sctpCookiePreserve{ + struct sctpParamDesc p; /* type is set to SCTP_COOKIE_PRESERVE, len=8 */ + u_int extraTime; +}; + + +struct sctpTimeStamp{ + u_int ts_sec; + u_int ts_usec; +}; + +/* wire structure of my cookie */ +struct cookieMessage{ + u_int TieTag_curTag; /* copied from assoc if present */ + u_int TieTag_hisTag; /* copied from assoc if present */ + int cookieLife; /* life I will award this cookie */ + struct sctpTimeStamp timeEnteringState; /* the time I built cookie */ + struct sctpInitiation initAckISent; /* the INIT-ACK that I sent to my peer */ + u_int addressWhereISent[4]; /* I make this 4 ints so I get 128bits for future */ + int addrtype; /* address type */ + u_short locScope; /* V6 local scope flag */ + u_short siteScope; /* V6 site scope flag */ + /* at the end is tacked on the INIT chunk sent in + * its entirety and of course our + * signature. + */ +}; + + +/* this guy is for use when + * I have a initiate message gloming the + * things together. + + */ +struct sctpUnifiedInit{ + struct sctpChunkDesc uh; + struct sctpInitiation initm; +}; + +struct sctpSendableInit{ + struct sctpHeader mh; + struct sctpUnifiedInit msg; +}; + + +/* Selective Acknowledgement + * has the following structure with + * a optional ammount of trailing int's + * on the last part (based on the numberOfDesc + * field). + */ + +struct sctpSelectiveAck{ + u_int highestConseqTSN; + u_int updatedRwnd; + u_short numberOfdesc; + u_short numDupTsns; +}; + +struct sctpSelectiveFrag{ + u_short fragmentStart; + u_short fragmentEnd; +}; + + +struct sctpUnifiedSack{ + struct sctpChunkDesc uh; + struct sctpSelectiveAck sack; +}; + +/* for both RTT request/response the + * following is sent + */ + +struct sctpHBrequest { + u_int time_value_1; + u_int time_value_2; +}; + +/* here is what I read and respond with to. */ +struct sctpHBunified{ + struct sctpChunkDesc hdr; + struct sctpParamDesc hb; +}; + + +/* here is what I send */ +struct sctpHBsender{ + struct sctpChunkDesc hdr; + struct sctpParamDesc hb; + struct sctpHBrequest rtt; + char addrFmt[SCTP_ADDRMAX]; + unsigned short userreq; +}; + + + +/* for the abort and shutdown ACK + * we must carry the init tag in the common header. Just the + * common header is all that is needed with a chunk descriptor. + */ +struct sctpUnifiedAbort{ + struct sctpChunkDesc uh; +}; + +struct sctpUnifiedAbortLight{ + struct sctpHeader mh; + struct sctpChunkDesc uh; +}; + +struct sctpUnifiedAbortHeavy{ + struct sctpHeader mh; + struct sctpChunkDesc uh; + unsigned short causeCode; + unsigned short causeLen; +}; + +/* For the graceful shutdown we must carry + * the tag (in common header) and the highest consequitive acking value + */ +struct sctpShutdown { + u_int TSN_Seen; +}; + +struct sctpUnifiedShutdown{ + struct sctpChunkDesc uh; + struct sctpShutdown shut; +}; + +/* in the unified message we add the trailing + * stream id since it is the only message + * that is defined as a operation error. + */ +struct sctpOpErrorCause{ + u_short cause; + u_short causeLen; +}; + +struct sctpUnifiedOpError{ + struct sctpChunkDesc uh; + struct sctpOpErrorCause c; +}; + +struct sctpUnifiedStreamError{ + struct sctpHeader mh; + struct sctpChunkDesc uh; + struct sctpOpErrorCause c; + u_short strmNum; + u_short reserved; +}; + +struct staleCookieMsg{ + struct sctpHeader mh; + struct sctpChunkDesc uh; + struct sctpOpErrorCause c; + u_int moretime; +}; + +/* the following is used in all sends + * where nothing is needed except the + * chunk/type i.e. shutdownAck Abort */ + +struct sctpUnifiedSingleMsg{ + struct sctpHeader mh; + struct sctpChunkDesc uh; +}; + +struct sctpDataPart{ + u_int TSN; + u_short streamId; + u_short sequence; + u_int payloadtype; +}; + +struct sctpUnifiedDatagram{ + struct sctpChunkDesc uh; + struct sctpDataPart dp; +}; + +struct sctpECN_echo{ + struct sctpChunkDesc uh; + u_int Lowest_TSN; +}; + + +struct sctpCWR{ + struct sctpChunkDesc uh; + u_int TSN_reduced_at; +}; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/contrib/tcpdump/smb.h b/contrib/tcpdump/smb.h index 63be64b..3c5ba7d 100644 --- a/contrib/tcpdump/smb.h +++ b/contrib/tcpdump/smb.h @@ -1,44 +1,13 @@ -/* @(#) $Header: /tcpdump/master/tcpdump/smb.h,v 1.3 2000/12/17 23:07:50 guy Exp $ (LBL) */ +/* @(#) $Header: /tcpdump/master/tcpdump/smb.h,v 1.7 2002/01/17 04:38:29 guy Exp $ (LBL) */ /* - Copyright (C) Andrew Tridgell 1995-1999 + * Copyright (C) Andrew Tridgell 1995-1999 + * + * This software may be distributed either under the terms of the + * BSD-style license that accompanies tcpdump or the GNU GPL version 2 + * or later + */ - This software may be distributed either under the terms of the - BSD-style license that accompanies tcpdump or the GNU GPL version 2 - or later */ - -#define CVAL(buf,pos) (((unsigned char *)(buf))[pos]) -#define PVAL(buf,pos) ((unsigned)CVAL(buf,pos)) -#define SCVAL(buf,pos,val) (CVAL(buf,pos) = (val)) - -#define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8) -#define IVAL(buf,pos) (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16) -#define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8) -#define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16)) -#define SVALS(buf,pos) ((int16)SVAL(buf,pos)) -#define IVALS(buf,pos) ((int32)IVAL(buf,pos)) -#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((uint16)(val))) -#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32)(val))) -#define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16)(val))) -#define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32)(val))) - -/* now the reverse routines - these are used in nmb packets (mostly) */ -#define SREV(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF)) -#define IREV(x) ((SREV(x)<<16) | (SREV((x)>>16))) - -#define RSVAL(buf,pos) SREV(SVAL(buf,pos)) -#define RIVAL(buf,pos) IREV(IVAL(buf,pos)) -#define RSSVAL(buf,pos,val) SSVAL(buf,pos,SREV(val)) -#define RSIVAL(buf,pos,val) SIVAL(buf,pos,IREV(val)) - -#define uint16 unsigned short -#define uint32 unsigned int -#ifndef uchar -#define uchar unsigned char -#endif - -#ifndef MIN -#define MIN(a,b) ((a)<(b)?(a):(b)) -#endif +#define SMBMIN(a,b) ((a)<(b)?(a):(b)) /* the complete */ #define SMBmkdir 0x00 /* create directory */ @@ -147,7 +116,7 @@ #define TRANSACT2_FINDNOTIFYNEXT 12 #define TRANSACT2_MKDIR 13 -#define PTR_DIFF(p1,p2) ((unsigned long)(((char *)(p1)) - (char *)(p2))) +#define PTR_DIFF(p1, p2) ((size_t)(((char *)(p1)) - (char *)(p2))) /* some protos */ -const uchar *fdata(const uchar *buf, const char *fmt, const uchar *maxbuf); +const u_char *smb_fdata(const u_char *, const char *, const u_char *); diff --git a/contrib/tcpdump/smbutil.c b/contrib/tcpdump/smbutil.c index 898345d..756a8d2 100644 --- a/contrib/tcpdump/smbutil.c +++ b/contrib/tcpdump/smbutil.c @@ -1,9 +1,10 @@ -/* - Copyright (C) Andrew Tridgell 1995-1999 - - This software may be distributed either under the terms of the - BSD-style license that accompanies tcpdump or the GNU GPL version 2 - or later */ +/* + * Copyright (C) Andrew Tridgell 1995-1999 + * + * This software may be distributed either under the terms of the + * BSD-style license that accompanies tcpdump or the GNU GPL version 2 + * or later + */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -11,7 +12,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.12 2000/12/04 00:35:45 guy Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.18 2002/01/17 04:38:29 guy Exp $"; #endif #include <sys/param.h> @@ -19,7 +20,6 @@ static const char rcsid[] = #include <sys/types.h> #include <sys/socket.h> - #include <netinet/in.h> #include <ctype.h> @@ -29,729 +29,815 @@ static const char rcsid[] = #include <time.h> #include "interface.h" +#include "extract.h" #include "smb.h" -extern const uchar *startbuf; +extern const u_char *startbuf; -/******************************************************************* - interpret a 32 bit dos packed date/time to some parameters -********************************************************************/ -static void interpret_dos_date(uint32 date,int *year,int *month,int *day,int *hour,int *minute,int *second) +/* + * interpret a 32 bit dos packed date/time to some parameters + */ +static void +interpret_dos_date(u_int32_t date, struct tm *tp) { - uint32 p0,p1,p2,p3; - - p0=date&0xFF; p1=((date&0xFF00)>>8)&0xFF; - p2=((date&0xFF0000)>>16)&0xFF; p3=((date&0xFF000000)>>24)&0xFF; - - *second = 2*(p0 & 0x1F); - *minute = ((p0>>5)&0xFF) + ((p1&0x7)<<3); - *hour = (p1>>3)&0xFF; - *day = (p2&0x1F); - *month = ((p2>>5)&0xFF) + ((p3&0x1)<<3) - 1; - *year = ((p3>>1)&0xFF) + 80; + u_int32_t p0, p1, p2, p3; + + p0 = date & 0xFF; + p1 = ((date & 0xFF00) >> 8) & 0xFF; + p2 = ((date & 0xFF0000) >> 16) & 0xFF; + p3 = ((date & 0xFF000000) >> 24) & 0xFF; + + tp->tm_sec = 2 * (p0 & 0x1F); + tp->tm_min = ((p0 >> 5) & 0xFF) + ((p1 & 0x7) << 3); + tp->tm_hour = (p1 >> 3) & 0xFF; + tp->tm_mday = (p2 & 0x1F); + tp->tm_mon = ((p2 >> 5) & 0xFF) + ((p3 & 0x1) << 3) - 1; + tp->tm_year = ((p3 >> 1) & 0xFF) + 80; } -/******************************************************************* - create a unix date from a dos date -********************************************************************/ -static time_t make_unix_date(const void *date_ptr) +/* + * common portion: + * create a unix date from a dos date + */ +static time_t +int_unix_date(u_int32_t dos_date) { - uint32 dos_date=0; - struct tm t; + struct tm t; - dos_date = IVAL(date_ptr,0); + if (dos_date == 0) + return(0); - if (dos_date == 0) return(0); - - interpret_dos_date(dos_date,&t.tm_year,&t.tm_mon, - &t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec); - t.tm_wday = 1; - t.tm_yday = 1; - t.tm_isdst = 0; + interpret_dos_date(dos_date, &t); + t.tm_wday = 1; + t.tm_yday = 1; + t.tm_isdst = 0; - return (mktime(&t)); + return (mktime(&t)); } -/******************************************************************* - create a unix date from a dos date -********************************************************************/ -static time_t make_unix_date2(const void *date_ptr) +/* + * create a unix date from a dos date + * in network byte order + */ +static time_t +make_unix_date(const u_char *date_ptr) { - uint32 x,x2; + u_int32_t dos_date = 0; - x = IVAL(date_ptr,0); - x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); - SIVAL(&x,0,x2); + dos_date = EXTRACT_LE_32BITS(date_ptr); - return(make_unix_date((void *)&x)); + return int_unix_date(dos_date); } -/**************************************************************************** -interpret an 8 byte "filetime" structure to a time_t -It's originally in "100ns units since jan 1st 1601" -****************************************************************************/ -static time_t interpret_long_date(const char *p) +/* + * create a unix date from a dos date + * in halfword-swapped network byte order! + */ +static time_t +make_unix_date2(const u_char *date_ptr) { - double d; - time_t ret; + u_int32_t x, x2; - /* this gives us seconds since jan 1st 1601 (approx) */ - d = (IVAL(p,4)*256.0 + CVAL(p,3)) * (1.0e-7 * (1<<24)); - - /* now adjust by 369 years to make the secs since 1970 */ - d -= 369.0*365.25*24*60*60; + x = EXTRACT_LE_32BITS(date_ptr); + x2 = ((x & 0xFFFF) << 16) | ((x & 0xFFFF0000) >> 16); + return int_unix_date(x2); +} - /* and a fudge factor as we got it wrong by a few days */ - d += (3*24*60*60 + 6*60*60 + 2); +/* + * interpret an 8 byte "filetime" structure to a time_t + * It's originally in "100ns units since jan 1st 1601" + */ +static time_t +interpret_long_date(const u_char *p) +{ + double d; + time_t ret; - if (d<0) - return(0); + TCHECK2(p[4], 4); - ret = (time_t)d; + /* this gives us seconds since jan 1st 1601 (approx) */ + d = (EXTRACT_LE_32BITS(p + 4) * 256.0 + p[3]) * (1.0e-7 * (1 << 24)); - return(ret); -} + /* now adjust by 369 years to make the secs since 1970 */ + d -= 369.0 * 365.25 * 24 * 60 * 60; + /* and a fudge factor as we got it wrong by a few days */ + d += (3 * 24 * 60 * 60 + 6 * 60 * 60 + 2); -/**************************************************************************** -interpret the weird netbios "name". Return the name type, or -1 if -we run past the end of the buffer -****************************************************************************/ -static int name_interpret(const uchar *in,const uchar *maxbuf,char *out) -{ - int ret; - int len; + if (d < 0) + return(0); - if (in >= maxbuf) - return(-1); /* name goes past the end of the buffer */ - TCHECK2(*in, 1); - len = (*in++) / 2; + ret = (time_t)d; - *out=0; + return(ret); +trunc: + return(0); +} - if (len > 30 || len<1) return(0); +/* + * interpret the weird netbios "name". Return the name type, or -1 if + * we run past the end of the buffer + */ +static int +name_interpret(const u_char *in, const u_char *maxbuf, char *out) +{ + int ret; + int len; - while (len--) - { - if (in + 1 >= maxbuf) + if (in >= maxbuf) return(-1); /* name goes past the end of the buffer */ - TCHECK2(*in, 2); - if (in[0] < 'A' || in[0] > 'P' || in[1] < 'A' || in[1] > 'P') { - *out = 0; + TCHECK2(*in, 1); + len = (*in++) / 2; + + *out=0; + + if (len > 30 || len < 1) return(0); - } - *out = ((in[0]-'A')<<4) + (in[1]-'A'); - in += 2; - out++; + + while (len--) { + TCHECK2(*in, 2); + if (in + 1 >= maxbuf) + return(-1); /* name goes past the end of the buffer */ + if (in[0] < 'A' || in[0] > 'P' || in[1] < 'A' || in[1] > 'P') { + *out = 0; + return(0); + } + *out = ((in[0] - 'A') << 4) + (in[1] - 'A'); + in += 2; + out++; } - *out = 0; - ret = out[-1]; + *out = 0; + ret = out[-1]; - return(ret); + return(ret); trunc: - return(-1); + return(-1); } -/**************************************************************************** -find a pointer to a netbios name -****************************************************************************/ -static const uchar *name_ptr(const uchar *buf,int ofs,const uchar *maxbuf) +/* + * find a pointer to a netbios name + */ +static const u_char * +name_ptr(const u_char *buf, int ofs, const u_char *maxbuf) { - const uchar *p; - uchar c; + const u_char *p; + u_char c; - p = buf+ofs; - if (p >= maxbuf) - return(NULL); /* name goes past the end of the buffer */ - TCHECK2(*p, 1); - - c = *p; - - /* XXX - this should use the same code that the DNS dissector does */ - if ((c & 0xC0) == 0xC0) - { - uint16 l = RSVAL(buf, ofs) & 0x3FFF; - if (l == 0) - { - /* We have a pointer that points to itself. */ - return(NULL); - } - p = buf + l; - if (p >= maxbuf) + p = buf + ofs; + if (p >= maxbuf) return(NULL); /* name goes past the end of the buffer */ - TCHECK2(*p, 1); - return(buf + l); - } - else - return(buf+ofs); + TCHECK2(*p, 1); + + c = *p; + + /* XXX - this should use the same code that the DNS dissector does */ + if ((c & 0xC0) == 0xC0) { + u_int16_t l = EXTRACT_16BITS(buf + ofs) & 0x3FFF; + if (l == 0) { + /* We have a pointer that points to itself. */ + return(NULL); + } + p = buf + l; + if (p >= maxbuf) + return(NULL); /* name goes past the end of the buffer */ + TCHECK2(*p, 1); + return(buf + l); + } else + return(buf + ofs); trunc: - return(NULL); /* name goes past the end of the buffer */ -} + return(NULL); /* name goes past the end of the buffer */ +} -/**************************************************************************** -extract a netbios name from a buf -****************************************************************************/ -static int name_extract(const uchar *buf,int ofs,const uchar *maxbuf,char *name) +/* + * extract a netbios name from a buf + */ +static int +name_extract(const u_char *buf, int ofs, const u_char *maxbuf, char *name) { - const uchar *p = name_ptr(buf,ofs,maxbuf); - if (p == NULL) - return(-1); /* error (probably name going past end of buffer) */ - strcpy(name,""); - return(name_interpret(p,maxbuf,name)); -} - - -/**************************************************************************** -return the total storage length of a mangled name -****************************************************************************/ -static int name_len(const unsigned char *s, const unsigned char *maxbuf) + const u_char *p = name_ptr(buf, ofs, maxbuf); + if (p == NULL) + return(-1); /* error (probably name going past end of buffer) */ + name[0] = '\0'; + return(name_interpret(p, maxbuf, name)); +} + + +/* + * return the total storage length of a mangled name + */ +static int +name_len(const unsigned char *s, const unsigned char *maxbuf) { - const unsigned char *s0 = s; - unsigned char c; + const unsigned char *s0 = s; + unsigned char c; - if (s >= maxbuf) - return(-1); /* name goes past the end of the buffer */ - TCHECK2(*s, 1); - c = *s; - if ((c & 0xC0) == 0xC0) - return(2); - while (*s) - { - if (s >= maxbuf) + if (s >= maxbuf) return(-1); /* name goes past the end of the buffer */ - TCHECK2(*s, 1); - s += (*s)+1; + TCHECK2(*s, 1); + c = *s; + if ((c & 0xC0) == 0xC0) + return(2); + while (*s) { + if (s >= maxbuf) + return(-1); /* name goes past the end of the buffer */ + TCHECK2(*s, 1); + s += (*s) + 1; } - return(PTR_DIFF(s,s0)+1); + return(PTR_DIFF(s, s0) + 1); trunc: - return(-1); /* name goes past the end of the buffer */ + return(-1); /* name goes past the end of the buffer */ } -static void print_asc(const unsigned char *buf,int len) +static void +print_asc(const unsigned char *buf, int len) { - int i; - for (i=0;i<len;i++) - printf("%c",isprint(buf[i])?buf[i]:'.'); + int i; + for (i = 0; i < len; i++) + safeputchar(buf[i]); } -static char *name_type_str(int name_type) +static char * +name_type_str(int name_type) { - static char *f = NULL; - switch (name_type) { - case 0: f = "Workstation"; break; - case 0x03: f = "Client?"; break; - case 0x20: f = "Server"; break; - case 0x1d: f = "Master Browser"; break; - case 0x1b: f = "Domain Controller"; break; - case 0x1e: f = "Browser Server"; break; - default: f = "Unknown"; break; - } - return(f); + char *f = NULL; + + switch (name_type) { + case 0: f = "Workstation"; break; + case 0x03: f = "Client?"; break; + case 0x20: f = "Server"; break; + case 0x1d: f = "Master Browser"; break; + case 0x1b: f = "Domain Controller"; break; + case 0x1e: f = "Browser Server"; break; + default: f = "Unknown"; break; + } + return(f); } -void print_data(const unsigned char *buf, int len) +void +print_data(const unsigned char *buf, int len) { - int i=0; - if (len<=0) return; - printf("[%03X] ",i); - for (i=0;i<len;) { - printf("%02X ",(int)buf[i]); - i++; - if (i%8 == 0) printf(" "); - if (i%16 == 0) { - print_asc(&buf[i-16],8); printf(" "); - print_asc(&buf[i-8],8); printf("\n"); - if (i<len) printf("[%03X] ",i); + int i = 0; + + if (len <= 0) + return; + printf("[%03X] ", i); + for (i = 0; i < len; /*nothing*/) { + printf("%02X ", buf[i] & 0xff); + i++; + if (i%8 == 0) + printf(" "); + if (i % 16 == 0) { + print_asc(&buf[i - 16], 8); + printf(" "); + print_asc(&buf[i - 8], 8); + printf("\n"); + if (i < len) + printf("[%03X] ", i); + } + } + if (i % 16) { + int n; + + n = 16 - (i % 16); + printf(" "); + if (n>8) + printf(" "); + while (n--) + printf(" "); + + n = SMBMIN(8, i % 16); + print_asc(&buf[i - (i % 16)], n); + printf(" "); + n = (i % 16) - n; + if (n > 0) + print_asc(&buf[i - n], n); + printf("\n"); } - } - if (i%16) { - int n; - - n = 16 - (i%16); - printf(" "); - if (n>8) printf(" "); - while (n--) printf(" "); - - n = MIN(8,i%16); - print_asc(&buf[i-(i%16)],n); printf(" "); - n = (i%16) - n; - if (n>0) print_asc(&buf[i-n],n); - printf("\n"); - } } -static void write_bits(unsigned int val,char *fmt) +static void +write_bits(unsigned int val, char *fmt) { - char *p = fmt; - int i=0; - - while ((p=strchr(fmt,'|'))) { - int l = PTR_DIFF(p,fmt); - if (l && (val & (1<<i))) - printf("%.*s ",l,fmt); - fmt = p+1; - i++; - } + char *p = fmt; + int i = 0; + + while ((p = strchr(fmt, '|'))) { + size_t l = PTR_DIFF(p, fmt); + if (l && (val & (1 << i))) + printf("%.*s ", (int)l, fmt); + fmt = p + 1; + i++; + } } -/* convert a unicode string */ -static const char *unistr(const char *s, int *len) +/* convert a UCS2 string into iso-8859-1 string */ +static const char * +unistr(const char *s, int *len) { - static char buf[1000]; - int l=0; - static int use_unicode = -1; - - if (use_unicode == -1) { - char *p = getenv("USE_UNICODE"); - if (p && (atoi(p) == 1)) - use_unicode = 1; - else - use_unicode = 0; - } + static char buf[1000]; + int l=0; + static int use_unicode = -1; + + if (use_unicode == -1) { + char *p = getenv("USE_UNICODE"); + if (p && (atoi(p) == 1)) + use_unicode = 1; + else + use_unicode = 0; + } - /* maybe it isn't unicode - a cheap trick */ - if (!use_unicode || (s[0] && s[1])) { - *len = strlen(s)+1; - return s; - } + /* maybe it isn't unicode - a cheap trick */ + if (!use_unicode || (s[0] && s[1])) { + *len = strlen(s) + 1; + return s; + } - *len = 0; + *len = 0; - if (s[0] == 0 && s[1] != 0) { - s++; - *len = 1; - } + if (s[0] == 0 && s[1] != 0) { + s++; + *len = 1; + } - while (l < (sizeof(buf)-1) && s[0] && s[1] == 0) { - buf[l] = s[0]; - s += 2; l++; - *len += 2; - } - buf[l] = 0; + while (l < (sizeof(buf) - 1) && s[0] && s[1] == 0) { + buf[l] = s[0]; + s += 2; + l++; *len += 2; - return buf; + } + buf[l] = 0; + *len += 2; + return buf; } -static const uchar *fdata1(const uchar *buf, const char *fmt, const uchar *maxbuf) +static const u_char * +smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf) { - int reverse=0; - char *attrib_fmt = "READONLY|HIDDEN|SYSTEM|VOLUME|DIR|ARCHIVE|"; - int len; - - while (*fmt && buf<maxbuf) { - switch (*fmt) { - case 'a': - write_bits(CVAL(buf,0),attrib_fmt); - buf++; fmt++; - break; - - case 'A': - write_bits(SVAL(buf,0),attrib_fmt); - buf+=2; fmt++; - break; - - case '{': - { - char bitfmt[128]; - char *p = strchr(++fmt,'}'); - int l = PTR_DIFF(p,fmt); - strncpy(bitfmt,fmt,l); - bitfmt[l]=0; - fmt = p+1; - write_bits(CVAL(buf,0),bitfmt); - buf++; - break; - } - - case 'P': - { - int l = atoi(fmt+1); - buf += l; - fmt++; - while (isdigit(*fmt)) fmt++; - break; - } - case 'r': - reverse = !reverse; - fmt++; - break; - case 'D': - { - unsigned int x = reverse?RIVAL(buf,0):IVAL(buf,0); - printf("%d (0x%x)",x, x); - buf += 4; - fmt++; - break; - } - case 'L': - { - unsigned int x1 = reverse?RIVAL(buf,0):IVAL(buf,0); - unsigned int x2 = reverse?RIVAL(buf,4):IVAL(buf,4); - if (x2) { - printf("0x%08x:%08x",x2, x1); - } else { - printf("%d (0x%08x%08x)",x1, x2, x1); - } - buf += 8; - fmt++; - break; - } - case 'd': - { - unsigned int x = reverse?RSVAL(buf,0):SVAL(buf,0); - printf("%d (0x%x)",x, x); - buf += 2; - fmt++; - break; - } - case 'W': - { - unsigned int x = reverse?RIVAL(buf,0):IVAL(buf,0); - printf("0x%X",x); - buf += 4; - fmt++; - break; - } - case 'w': - { - unsigned int x = reverse?RSVAL(buf,0):SVAL(buf,0); - printf("0x%X",x); - buf += 2; - fmt++; - break; - } - case 'B': - { - unsigned int x = CVAL(buf,0); - printf("0x%X",x); - buf += 1; - fmt++; - break; - } - case 'b': - { - unsigned int x = CVAL(buf,0); - printf("%d (0x%x)",x, x); - buf += 1; - fmt++; - break; - } - case 'S': - { - printf("%.*s",(int)PTR_DIFF(maxbuf,buf),unistr(buf, &len)); - buf += len; - fmt++; - break; - } - case 'Z': - { - if (*buf != 4 && *buf != 2) - printf("Error! ASCIIZ buffer of type %d (safety=%d)\n", - *buf,(int)PTR_DIFF(maxbuf,buf)); - printf("%.*s",(int)PTR_DIFF(maxbuf,buf+1),unistr(buf+1, &len)); - buf += len+1; - fmt++; - break; - } - case 's': - { - int l = atoi(fmt+1); - printf("%-*.*s",l,l,buf); - buf += l; - fmt++; while (isdigit(*fmt)) fmt++; - break; - } - case 'h': - { - int l = atoi(fmt+1); - while (l--) printf("%02x",*buf++); - fmt++; while (isdigit(*fmt)) fmt++; - break; - } - case 'n': - { - int t = atoi(fmt+1); - char nbuf[255]; - int name_type; - int len; - switch (t) { - case 1: - name_type = name_extract(startbuf,PTR_DIFF(buf,startbuf),maxbuf, - nbuf); - if (name_type < 0) - goto trunc; - len = name_len(buf,maxbuf); - if (len < 0) - goto trunc; - buf += len; - printf("%-15.15s NameType=0x%02X (%s)", - nbuf,name_type,name_type_str(name_type)); - break; - case 2: - name_type = buf[15]; - printf("%-15.15s NameType=0x%02X (%s)", - buf,name_type,name_type_str(name_type)); - buf += 16; - break; - } - fmt++; while (isdigit(*fmt)) fmt++; - break; - } - case 'T': - { - time_t t; - int x = IVAL(buf,0); - switch (atoi(fmt+1)) { - case 1: - if (x==0 || x==-1 || x==0xFFFFFFFF) - t = 0; - else - t = make_unix_date(buf); - buf+=4; - break; - case 2: - if (x==0 || x==-1 || x==0xFFFFFFFF) - t = 0; - else - t = make_unix_date2(buf); - buf+=4; - break; - case 3: - t = interpret_long_date(buf); - buf+=8; - break; + int reverse = 0; + char *attrib_fmt = "READONLY|HIDDEN|SYSTEM|VOLUME|DIR|ARCHIVE|"; + int len; + + while (*fmt && buf<maxbuf) { + switch (*fmt) { + case 'a': + write_bits(buf[0], attrib_fmt); + buf++; + fmt++; + break; + + case 'A': + write_bits(EXTRACT_LE_16BITS(buf), attrib_fmt); + buf += 2; + fmt++; + break; + + case '{': + { + char bitfmt[128]; + char *p = strchr(++fmt, '}'); + int l = PTR_DIFF(p, fmt); + strncpy(bitfmt, fmt, l); + bitfmt[l] = 0; + fmt = p + 1; + write_bits(buf[0], bitfmt); + buf++; + break; + } + + case 'P': + { + int l = atoi(fmt + 1); + buf += l; + fmt++; + while (isdigit(*fmt)) + fmt++; + break; + } + case 'r': + reverse = !reverse; + fmt++; + break; + case 'D': + { + unsigned int x; + + TCHECK2(buf[0], 4); + x = reverse ? EXTRACT_32BITS(buf) : EXTRACT_LE_32BITS(buf); + printf("%d (0x%x)", x, x); + buf += 4; + fmt++; + break; + } + case 'L': + { + unsigned int x1, x2; + + TCHECK2(buf[4], 4); + x1 = reverse ? EXTRACT_32BITS(buf) : + EXTRACT_LE_32BITS(buf); + x2 = reverse ? EXTRACT_32BITS(buf + 4) : + EXTRACT_LE_32BITS(buf + 4); + if (x2) + printf("0x%08x:%08x", x2, x1); + else + printf("%d (0x%08x%08x)", x1, x2, x1); + buf += 8; + fmt++; + break; + } + case 'd': + { + unsigned int x; + TCHECK2(buf[0], 2); + x = reverse ? EXTRACT_16BITS(buf) : + EXTRACT_LE_16BITS(buf); + printf("%d (0x%x)", x, x); + buf += 2; + fmt++; + break; + } + case 'W': + { + unsigned int x; + TCHECK2(buf[0], 4); + x = reverse ? EXTRACT_32BITS(buf) : + EXTRACT_LE_32BITS(buf); + printf("0x%X", x); + buf += 4; + fmt++; + break; + } + case 'w': + { + unsigned int x; + TCHECK2(buf[0], 2); + x = reverse ? EXTRACT_16BITS(buf) : + EXTRACT_LE_16BITS(buf); + printf("0x%X", x); + buf += 2; + fmt++; + break; + } + case 'B': + { + unsigned int x; + TCHECK(buf[0]); + x = buf[0]; + printf("0x%X", x); + buf += 1; + fmt++; + break; + } + case 'b': + { + unsigned int x; + TCHECK(buf[0]); + x = buf[0]; + printf("%u (0x%x)", x, x); + buf += 1; + fmt++; + break; + } + case 'S': + { + /*XXX unistr() */ + printf("%.*s", (int)PTR_DIFF(maxbuf, buf), unistr(buf, &len)); + buf += len; + fmt++; + break; + } + case 'Z': + { + if (*buf != 4 && *buf != 2) + printf("Error! ASCIIZ buffer of type %u (safety=%lu)\n", *buf, + (unsigned long)PTR_DIFF(maxbuf, buf)); + printf("%.*s", (int)PTR_DIFF(maxbuf, buf + 1), + unistr(buf + 1, &len)); + buf += len + 1; + fmt++; + break; + } + case 's': + { + int l = atoi(fmt + 1); + printf("%-*.*s", l, l, buf); + buf += l; + fmt++; + while (isdigit(*fmt)) + fmt++; + break; + } + case 'h': + { + int l = atoi(fmt + 1); + while (l--) + printf("%02x", *buf++); + fmt++; + while (isdigit(*fmt)) + fmt++; + break; + } + case 'n': + { + int t = atoi(fmt+1); + char nbuf[255]; + int name_type; + int len; + + switch (t) { + case 1: + name_type = name_extract(startbuf, PTR_DIFF(buf, startbuf), + maxbuf, nbuf); + if (name_type < 0) + goto trunc; + len = name_len(buf, maxbuf); + if (len < 0) + goto trunc; + buf += len; + printf("%-15.15s NameType=0x%02X (%s)", nbuf, name_type, + name_type_str(name_type)); + break; + case 2: + name_type = buf[15]; + printf("%-15.15s NameType=0x%02X (%s)", buf, name_type, + name_type_str(name_type)); + buf += 16; + break; + } + fmt++; + while (isdigit(*fmt)) + fmt++; + break; + } + case 'T': + { + time_t t; + int x; + x = EXTRACT_LE_32BITS(buf); + + switch (atoi(fmt + 1)) { + case 1: + if (x == 0 || x == -1 || x == 0xFFFFFFFF) + t = 0; + else + t = make_unix_date(buf); + buf += 4; + break; + case 2: + if (x == 0 || x == -1 || x == 0xFFFFFFFF) + t = 0; + else + t = make_unix_date2(buf); + buf += 4; + break; + case 3: + t = interpret_long_date(buf); + buf += 8; + break; + } + printf("%s", t ? asctime(localtime(&t)) : "NULL\n"); + fmt++; + while (isdigit(*fmt)) + fmt++; + break; + } + default: + putchar(*fmt); + fmt++; + break; } - printf("%s",t?asctime(localtime(&t)):"NULL\n"); - fmt++; while (isdigit(*fmt)) fmt++; - break; - } - default: - putchar(*fmt); - fmt++; - break; } - } - if (buf>=maxbuf && *fmt) - printf("END OF BUFFER\n"); + if (buf >= maxbuf && *fmt) + printf("END OF BUFFER\n"); - return(buf); + return(buf); trunc: - printf("\n"); - printf("WARNING: Short packet. Try increasing the snap length\n"); - return(NULL); + printf("\n"); + printf("WARNING: Short packet. Try increasing the snap length\n"); + return(NULL); } -const uchar *fdata(const uchar *buf, const char *fmt, const uchar *maxbuf) +const u_char * +smb_fdata(const u_char *buf, const char *fmt, const u_char *maxbuf) { - static int depth=0; - char s[128]; - char *p; - - while (*fmt) { - switch (*fmt) { - case '*': - fmt++; - while (buf < maxbuf) { - const uchar *buf2; - depth++; - buf2 = fdata(buf,fmt,maxbuf); - depth--; - if (buf2 == buf) return(buf); - buf = buf2; - } - break; - - case '|': - fmt++; - if (buf>=maxbuf) return(buf); - break; - - case '%': - fmt++; - buf=maxbuf; - break; - - case '#': - fmt++; - return(buf); - break; - - case '[': - fmt++; - if (buf>=maxbuf) return(buf); - memset(s, 0, sizeof(s)); - p = strchr(fmt,']'); - strncpy(s,fmt,p-fmt); - fmt = p+1; - buf = fdata1(buf,s,maxbuf); - if (buf == NULL) - return(NULL); - break; - - default: - putchar(*fmt); fmt++; - fflush(stdout); - break; + static int depth = 0; + char s[128]; + char *p; + + while (*fmt) { + switch (*fmt) { + case '*': + fmt++; + while (buf < maxbuf) { + const u_char *buf2; + depth++; + buf2 = smb_fdata(buf, fmt, maxbuf); + depth--; + if (buf2 == NULL) + return(NULL); + if (buf2 == buf) + return(buf); + buf = buf2; + } + return(buf); + + case '|': + fmt++; + if (buf >= maxbuf) + return(buf); + break; + + case '%': + fmt++; + buf = maxbuf; + break; + + case '#': + fmt++; + return(buf); + break; + + case '[': + fmt++; + if (buf >= maxbuf) + return(buf); + memset(s, 0, sizeof(s)); + p = strchr(fmt, ']'); + if (p - fmt + 1 > sizeof(s)) { + /* overrun */ + return(buf); + } + strncpy(s, fmt, p - fmt); + s[p - fmt] = '\0'; + fmt = p + 1; + buf = smb_fdata1(buf, s, maxbuf); + if (buf == NULL) + return(NULL); + break; + + default: + putchar(*fmt); + fmt++; + fflush(stdout); + break; + } } - } - if (!depth && buf<maxbuf) { - int len = PTR_DIFF(maxbuf,buf); - printf("Data: (%d bytes)\n",len); - print_data(buf,len); - return(buf+len); - } - return(buf); + if (!depth && buf < maxbuf) { + size_t len = PTR_DIFF(maxbuf, buf); + printf("Data: (%lu bytes)\n", (unsigned long)len); + print_data(buf, len); + return(buf + len); + } + return(buf); } -typedef struct -{ - char *name; - int code; - char *message; +typedef struct { + const char *name; + int code; + const char *message; } err_code_struct; /* Dos Error Messages */ static err_code_struct dos_msgs[] = { - {"ERRbadfunc",1,"Invalid function."}, - {"ERRbadfile",2,"File not found."}, - {"ERRbadpath",3,"Directory invalid."}, - {"ERRnofids",4,"No file descriptors available"}, - {"ERRnoaccess",5,"Access denied."}, - {"ERRbadfid",6,"Invalid file handle."}, - {"ERRbadmcb",7,"Memory control blocks destroyed."}, - {"ERRnomem",8,"Insufficient server memory to perform the requested function."}, - {"ERRbadmem",9,"Invalid memory block address."}, - {"ERRbadenv",10,"Invalid environment."}, - {"ERRbadformat",11,"Invalid format."}, - {"ERRbadaccess",12,"Invalid open mode."}, - {"ERRbaddata",13,"Invalid data."}, - {"ERR",14,"reserved."}, - {"ERRbaddrive",15,"Invalid drive specified."}, - {"ERRremcd",16,"A Delete Directory request attempted to remove the server's current directory."}, - {"ERRdiffdevice",17,"Not same device."}, - {"ERRnofiles",18,"A File Search command can find no more files matching the specified criteria."}, - {"ERRbadshare",32,"The sharing mode specified for an Open conflicts with existing FIDs on the file."}, - {"ERRlock",33,"A Lock request conflicted with an existing lock or specified an invalid mode, or an Unlock requested attempted to remove a lock held by another process."}, - {"ERRfilexists",80,"The file named in a Create Directory, Make New File or Link request already exists."}, - {"ERRbadpipe",230,"Pipe invalid."}, - {"ERRpipebusy",231,"All instances of the requested pipe are busy."}, - {"ERRpipeclosing",232,"Pipe close in progress."}, - {"ERRnotconnected",233,"No process on other end of pipe."}, - {"ERRmoredata",234,"There is more data to be returned."}, - {NULL,-1,NULL}}; + { "ERRbadfunc", 1, "Invalid function." }, + { "ERRbadfile", 2, "File not found." }, + { "ERRbadpath", 3, "Directory invalid." }, + { "ERRnofids", 4, "No file descriptors available" }, + { "ERRnoaccess", 5, "Access denied." }, + { "ERRbadfid", 6, "Invalid file handle." }, + { "ERRbadmcb", 7, "Memory control blocks destroyed." }, + { "ERRnomem", 8, "Insufficient server memory to perform the requested function." }, + { "ERRbadmem", 9, "Invalid memory block address." }, + { "ERRbadenv", 10, "Invalid environment." }, + { "ERRbadformat", 11, "Invalid format." }, + { "ERRbadaccess", 12, "Invalid open mode." }, + { "ERRbaddata", 13, "Invalid data." }, + { "ERR", 14, "reserved." }, + { "ERRbaddrive", 15, "Invalid drive specified." }, + { "ERRremcd", 16, "A Delete Directory request attempted to remove the server's current directory." }, + { "ERRdiffdevice", 17, "Not same device." }, + { "ERRnofiles", 18, "A File Search command can find no more files matching the specified criteria." }, + { "ERRbadshare", 32, "The sharing mode specified for an Open conflicts with existing FIDs on the file." }, + { "ERRlock", 33, "A Lock request conflicted with an existing lock or specified an invalid mode, or an Unlock requested attempted to remove a lock held by another process." }, + { "ERRfilexists", 80, "The file named in a Create Directory, Make New File or Link request already exists." }, + { "ERRbadpipe", 230, "Pipe invalid." }, + { "ERRpipebusy", 231, "All instances of the requested pipe are busy." }, + { "ERRpipeclosing", 232, "Pipe close in progress." }, + { "ERRnotconnected", 233, "No process on other end of pipe." }, + { "ERRmoredata", 234, "There is more data to be returned." }, + { NULL, -1, NULL } + }; /* Server Error Messages */ err_code_struct server_msgs[] = { - {"ERRerror",1,"Non-specific error code."}, - {"ERRbadpw",2,"Bad password - name/password pair in a Tree Connect or Session Setup are invalid."}, - {"ERRbadtype",3,"reserved."}, - {"ERRaccess",4,"The requester does not have the necessary access rights within the specified context for the requested function. The context is defined by the TID or the UID."}, - {"ERRinvnid",5,"The tree ID (TID) specified in a command was invalid."}, - {"ERRinvnetname",6,"Invalid network name in tree connect."}, - {"ERRinvdevice",7,"Invalid device - printer request made to non-printer connection or non-printer request made to printer connection."}, - {"ERRqfull",49,"Print queue full (files) -- returned by open print file."}, - {"ERRqtoobig",50,"Print queue full -- no space."}, - {"ERRqeof",51,"EOF on print queue dump."}, - {"ERRinvpfid",52,"Invalid print file FID."}, - {"ERRsmbcmd",64,"The server did not recognize the command received."}, - {"ERRsrverror",65,"The server encountered an internal error, e.g., system file unavailable."}, - {"ERRfilespecs",67,"The file handle (FID) and pathname parameters contained an invalid combination of values."}, - {"ERRreserved",68,"reserved."}, - {"ERRbadpermits",69,"The access permissions specified for a file or directory are not a valid combination. The server cannot set the requested attribute."}, - {"ERRreserved",70,"reserved."}, - {"ERRsetattrmode",71,"The attribute mode in the Set File Attribute request is invalid."}, - {"ERRpaused",81,"Server is paused."}, - {"ERRmsgoff",82,"Not receiving messages."}, - {"ERRnoroom",83,"No room to buffer message."}, - {"ERRrmuns",87,"Too many remote user names."}, - {"ERRtimeout",88,"Operation timed out."}, - {"ERRnoresource",89,"No resources currently available for request."}, - {"ERRtoomanyuids",90,"Too many UIDs active on this session."}, - {"ERRbaduid",91,"The UID is not known as a valid ID on this session."}, - {"ERRusempx",250,"Temp unable to support Raw, use MPX mode."}, - {"ERRusestd",251,"Temp unable to support Raw, use standard read/write."}, - {"ERRcontmpx",252,"Continue in MPX mode."}, - {"ERRreserved",253,"reserved."}, - {"ERRreserved",254,"reserved."}, - {"ERRnosupport",0xFFFF,"Function not supported."}, - {NULL,-1,NULL}}; + { "ERRerror", 1, "Non-specific error code." }, + { "ERRbadpw", 2, "Bad password - name/password pair in a Tree Connect or Session Setup are invalid." }, + { "ERRbadtype", 3, "reserved." }, + { "ERRaccess", 4, "The requester does not have the necessary access rights within the specified context for the requested function. The context is defined by the TID or the UID." }, + { "ERRinvnid", 5, "The tree ID (TID) specified in a command was invalid." }, + { "ERRinvnetname", 6, "Invalid network name in tree connect." }, + { "ERRinvdevice", 7, "Invalid device - printer request made to non-printer connection or non-printer request made to printer connection." }, + { "ERRqfull", 49, "Print queue full (files) -- returned by open print file." }, + { "ERRqtoobig", 50, "Print queue full -- no space." }, + { "ERRqeof", 51, "EOF on print queue dump." }, + { "ERRinvpfid", 52, "Invalid print file FID." }, + { "ERRsmbcmd", 64, "The server did not recognize the command received." }, + { "ERRsrverror", 65, "The server encountered an internal error, e.g., system file unavailable." }, + { "ERRfilespecs", 67, "The file handle (FID) and pathname parameters contained an invalid combination of values." }, + { "ERRreserved", 68, "reserved." }, + { "ERRbadpermits", 69, "The access permissions specified for a file or directory are not a valid combination. The server cannot set the requested attribute." }, + { "ERRreserved", 70, "reserved." }, + { "ERRsetattrmode", 71, "The attribute mode in the Set File Attribute request is invalid." }, + { "ERRpaused", 81, "Server is paused." }, + { "ERRmsgoff", 82, "Not receiving messages." }, + { "ERRnoroom", 83, "No room to buffer message." }, + { "ERRrmuns", 87, "Too many remote user names." }, + { "ERRtimeout", 88, "Operation timed out." }, + { "ERRnoresource", 89, "No resources currently available for request." }, + { "ERRtoomanyuids", 90, "Too many UIDs active on this session." }, + { "ERRbaduid", 91, "The UID is not known as a valid ID on this session." }, + { "ERRusempx", 250, "Temp unable to support Raw, use MPX mode." }, + { "ERRusestd", 251, "Temp unable to support Raw, use standard read/write." }, + { "ERRcontmpx", 252, "Continue in MPX mode." }, + { "ERRreserved", 253, "reserved." }, + { "ERRreserved", 254, "reserved." }, + { "ERRnosupport", 0xFFFF, "Function not supported." }, + { NULL, -1, NULL } +}; /* Hard Error Messages */ err_code_struct hard_msgs[] = { - {"ERRnowrite",19,"Attempt to write on write-protected diskette."}, - {"ERRbadunit",20,"Unknown unit."}, - {"ERRnotready",21,"Drive not ready."}, - {"ERRbadcmd",22,"Unknown command."}, - {"ERRdata",23,"Data error (CRC)."}, - {"ERRbadreq",24,"Bad request structure length."}, - {"ERRseek",25 ,"Seek error."}, - {"ERRbadmedia",26,"Unknown media type."}, - {"ERRbadsector",27,"Sector not found."}, - {"ERRnopaper",28,"Printer out of paper."}, - {"ERRwrite",29,"Write fault."}, - {"ERRread",30,"Read fault."}, - {"ERRgeneral",31,"General failure."}, - {"ERRbadshare",32,"A open conflicts with an existing open."}, - {"ERRlock",33,"A Lock request conflicted with an existing lock or specified an invalid mode, or an Unlock requested attempted to remove a lock held by another process."}, - {"ERRwrongdisk",34,"The wrong disk was found in a drive."}, - {"ERRFCBUnavail",35,"No FCBs are available to process request."}, - {"ERRsharebufexc",36,"A sharing buffer has been exceeded."}, - {NULL,-1,NULL}}; - - -static struct -{ - int code; - char *class; - err_code_struct *err_msgs; -} err_classes[] = { - {0,"SUCCESS",NULL}, - {0x01,"ERRDOS",dos_msgs}, - {0x02,"ERRSRV",server_msgs}, - {0x03,"ERRHRD",hard_msgs}, - {0x04,"ERRXOS",NULL}, - {0xE1,"ERRRMX1",NULL}, - {0xE2,"ERRRMX2",NULL}, - {0xE3,"ERRRMX3",NULL}, - {0xFF,"ERRCMD",NULL}, - {-1,NULL,NULL}}; - - -/**************************************************************************** -return a SMB error string from a SMB buffer -****************************************************************************/ -char *smb_errstr(int class,int num) + { "ERRnowrite", 19, "Attempt to write on write-protected diskette." }, + { "ERRbadunit", 20, "Unknown unit." }, + { "ERRnotready", 21, "Drive not ready." }, + { "ERRbadcmd", 22, "Unknown command." }, + { "ERRdata", 23, "Data error (CRC)." }, + { "ERRbadreq", 24, "Bad request structure length." }, + { "ERRseek", 25 , "Seek error." }, + { "ERRbadmedia", 26, "Unknown media type." }, + { "ERRbadsector", 27, "Sector not found." }, + { "ERRnopaper", 28, "Printer out of paper." }, + { "ERRwrite", 29, "Write fault." }, + { "ERRread", 30, "Read fault." }, + { "ERRgeneral", 31, "General failure." }, + { "ERRbadshare", 32, "A open conflicts with an existing open." }, + { "ERRlock", 33, "A Lock request conflicted with an existing lock or specified an invalid mode, or an Unlock requested attempted to remove a lock held by another process." }, + { "ERRwrongdisk", 34, "The wrong disk was found in a drive." }, + { "ERRFCBUnavail", 35, "No FCBs are available to process request." }, + { "ERRsharebufexc", 36, "A sharing buffer has been exceeded." }, + { NULL, -1, NULL } +}; + +static struct { + int code; + char *class; + err_code_struct *err_msgs; +} err_classes[] = { + { 0, "SUCCESS", NULL }, + { 0x01, "ERRDOS", dos_msgs }, + { 0x02, "ERRSRV", server_msgs }, + { 0x03, "ERRHRD", hard_msgs }, + { 0x04, "ERRXOS", NULL }, + { 0xE1, "ERRRMX1", NULL }, + { 0xE2, "ERRRMX2", NULL }, + { 0xE3, "ERRRMX3", NULL }, + { 0xFF, "ERRCMD", NULL }, + { -1, NULL, NULL } +}; + +/* + * return a SMB error string from a SMB buffer + */ +char * +smb_errstr(int class, int num) { - static char ret[128]; - int i,j; - - ret[0]=0; - - for (i=0;err_classes[i].class;i++) - if (err_classes[i].code == class) - { - if (err_classes[i].err_msgs) - { - err_code_struct *err = err_classes[i].err_msgs; - for (j=0;err[j].name;j++) - if (num == err[j].code) - { - snprintf(ret,sizeof(ret),"%s - %s (%s)",err_classes[i].class, - err[j].name,err[j].message); - return ret; - } - } + static char ret[128]; + int i, j; + + ret[0] = 0; + + for (i = 0; err_classes[i].class; i++) + if (err_classes[i].code == class) { + if (err_classes[i].err_msgs) { + err_code_struct *err = err_classes[i].err_msgs; + for (j = 0; err[j].name; j++) + if (num == err[j].code) { + snprintf(ret, sizeof(ret), "%s - %s (%s)", + err_classes[i].class, err[j].name, err[j].message); + return ret; + } + } + + snprintf(ret, sizeof(ret), "%s - %d", err_classes[i].class, num); + return ret; + } - snprintf(ret,sizeof(ret),"%s - %d",err_classes[i].class,num); - return ret; - } - - snprintf(ret,sizeof(ret),"ERROR: Unknown error (%d,%d)",class,num); - return(ret); + snprintf(ret, sizeof(ret), "ERROR: Unknown error (%d,%d)", class, num); + return(ret); } diff --git a/contrib/tcpdump/tcp.h b/contrib/tcpdump/tcp.h index a93c14f..fe0e261 100644 --- a/contrib/tcpdump/tcp.h +++ b/contrib/tcpdump/tcp.h @@ -1,4 +1,4 @@ -/* @(#) $Header: /tcpdump/master/tcpdump/tcp.h,v 1.7 2000/10/03 09:17:41 guy Exp $ (LBL) */ +/* @(#) $Header: /tcpdump/master/tcpdump/tcp.h,v 1.8 2001/05/09 01:16:57 fenner Exp $ (LBL) */ /* * Copyright (c) 1982, 1986, 1993 * The Regents of the University of California. All rights reserved. @@ -53,6 +53,8 @@ struct tcphdr { #define TH_PUSH 0x08 #define TH_ACK 0x10 #define TH_URG 0x20 +#define TH_ECNECHO 0x40 /* ECN Echo */ +#define TH_CWR 0x80 /* ECN Cwnd Reduced */ u_int16_t th_win; /* window */ u_int16_t th_sum; /* checksum */ u_int16_t th_urp; /* urgent pointer */ @@ -62,14 +64,17 @@ struct tcphdr { #define TCPOPT_NOP 1 #define TCPOPT_MAXSEG 2 #define TCPOLEN_MAXSEG 4 -#define TCPOPT_WINDOW 3 -#define TCPOLEN_WINDOW 3 -#define TCPOPT_SACK_PERMITTED 4 /* Experimental */ -#define TCPOLEN_SACK_PERMITTED 2 -#define TCPOPT_SACK 5 /* Experimental */ -#define TCPOPT_TIMESTAMP 8 +#define TCPOPT_WSCALE 3 /* window scale factor (rfc1323) */ +#define TCPOPT_SACKOK 4 /* selective ack ok (rfc2018) */ +#define TCPOPT_SACK 5 /* selective ack (rfc2018) */ +#define TCPOPT_ECHO 6 /* echo (rfc1072) */ +#define TCPOPT_ECHOREPLY 7 /* echo (rfc1072) */ +#define TCPOPT_TIMESTAMP 8 /* timestamp (rfc1323) */ #define TCPOLEN_TIMESTAMP 10 #define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */ +#define TCPOPT_CC 11 /* T/TCP CC options (rfc1644) */ +#define TCPOPT_CCNEW 12 /* T/TCP CC options (rfc1644) */ +#define TCPOPT_CCECHO 13 /* T/TCP CC options (rfc1644) */ #define TCPOPT_TSTAMP_HDR \ (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP) diff --git a/contrib/tcpdump/tcpdump.1 b/contrib/tcpdump/tcpdump.1 index 41f823a..7df9554 100644 --- a/contrib/tcpdump/tcpdump.1 +++ b/contrib/tcpdump/tcpdump.1 @@ -1,4 +1,4 @@ -.\" @(#) $Header: /tcpdump/master/tcpdump/tcpdump.1,v 1.92.2.3 2001/03/04 00:19:48 guy Exp $ (LBL) +.\" @(#) $Header: /tcpdump/master/tcpdump/tcpdump.1,v 1.114 2002/01/04 07:37:49 guy Exp $ (LBL) .\" .\" Copyright (c) 1987, 1988, 1989, 1990, 1991, 1992, 1994, 1995, 1996, 1997 .\" The Regents of the University of California. All rights reserved. @@ -27,10 +27,16 @@ tcpdump \- dump traffic on a network .na .B tcpdump [ -.B \-adeflnNOpqRStvxX +.B \-adeflnNOpqRStuvxX ] [ .B \-c .I count +] +.br +.ti +8 +[ +.B \-C +.I file_size ] [ .B \-F .I file @@ -77,32 +83,103 @@ tcpdump \- dump traffic on a network .SH DESCRIPTION .LP \fITcpdump\fP prints out the headers of packets on a network interface -that match the boolean \fIexpression\fP. +that match the boolean \fIexpression\fP. It can also be run with the +.B \-w +flag, which causes it to save the packet data to a file for later +analysis, and/or with the +.B \-b +flag, which causes it to read from a saved packet file rather than to +read packets from a network interface. In all cases, only packets that +match +.I expression +will be processed by +.IR tcpdump . +.LP +.I Tcpdump +will, if not run with the +.B \-c +flag, continue capturing packets until it is interrupted by a SIGINT +signal (generated, for example, by typing your interrupt character, +typically control-C) or a SIGTERM signal (typically generated with the +.BR kill (1) +command); if run with the +.B \-c +flag, it will capture packets until it is interrupted by a SIGINT or +SIGTERM signal or the specified number of packets have been processed. .LP -.B Under SunOS with nit or bpf: -To run +When .I tcpdump -you must have read access to +finishes capturing packets, it will report counts of: +.IP +packets ``received by filter'' (the meaning of this depends on the OS on +which you're running +.IR tcpdump , +and possibly on the way the OS was configured - if a filter was +specified on the command line, on some OSes it counts packets regardless +of whether they were matched by the filter expression, and on other OSes +it counts only packets that were matched by the filter expression and +were processed by +.IR tcpdump ); +.IP +packets ``dropped by kernel'' (this is the number of packets that were +dropped, due to a lack of buffer space, by the packet capture mechanism +in the OS on which +.I tcpdump +is running, if the OS reports that information to applications; if not, +it will be reported as 0). +.LP +On platforms that support the SIGINFO signal, such as most BSDs, it will +report those counts when it receives a SIGINFO signal (generated, for +example, by typing your ``status'' character, typically control-T) and +will continue capturing packets. +.LP +Reading packets from a network interface may require that you have +special privileges: +.TP +.B Under SunOS 3.x or 4.x with NIT or BPF: +You must have read access to .I /dev/nit or .IR /dev/bpf* . -.B Under Solaris with dlpi: +.TP +.B Under Solaris with DLPI: You must have read/write access to the network pseudo device, e.g. .IR /dev/le . -.B Under HP-UX with dlpi: -You must be root or it must be installed setuid to root. +On at least some versions of Solaris, however, this is not sufficient to +allow +.I tcpdump +to capture in promiscuous mode; on those versions of Solaris, you must +be root, or +.I tcpdump +must be installed setuid to root, in order to capture in promiscuous +mode. +.TP +.B Under HP-UX with DLPI: +You must be root or +.I tcpdump +must be installed setuid to root. +.TP .B Under IRIX with snoop: -You must be root or it must be installed setuid to root. +You must be root or +.I tcpdump +must be installed setuid to root. +.TP .B Under Linux: -You must be root or it must be installed setuid to root. +You must be root or +.I tcpdump +must be installed setuid to root. +.TP .B Under Ultrix and Digital UNIX: Once the super-user has enabled promiscuous-mode operation using .IR pfconfig (8), -any user may run -.BR tcpdump . +any user may capture network traffic with +.IR tcpdump . +.TP .B Under BSD: You must have read access to .IR /dev/bpf* . +.LP +Reading a saved packet file doesn't require special privileges. .SH OPTIONS .TP .B \-a @@ -111,6 +188,16 @@ Attempt to convert network and broadcast addresses to names. .B \-c Exit after receiving \fIcount\fP packets. .TP +.B \-C +Before writing a raw packet to a savefile, check whether the file is +currently larger than \fIfile_size\fP and, if so, close the current +savefile and open a new one. Savefiles after the first savefile will +have the name specified with the +.B \-w +flag, with a number after it, starting at 2 and continuing upward. +The units of \fIfile_size\fP are millions of bytes (1,000,000 bytes, +not 1,048,576 bytes). +.TP .B \-d Dump the compiled packet-matching code in a human readable form to standard output and stop. @@ -127,12 +214,13 @@ Dump packet-matching code as decimal numbers (preceded with a count). Print the link-level header on each dump line. .TP .B \-E -Use \fIalgo:secret\fP for decrypting IPsec ESP packets. Algorithms may be -\fBdes-cbc\fP, -\fB3des-cbc\fP, -\fBblowfish-cbc\fP, -\fBrc3-cbc\fP, -\fBcast128-cbc\fP, or +Use \fIalgo:secret\fP for decrypting IPsec ESP packets. +Algorithms may be +\fBdes-cbc\fP, +\fB3des-cbc\fP, +\fBblowfish-cbc\fP, +\fBrc3-cbc\fP, +\fBcast128-cbc\fP, or \fBnone\fP. The default is \fBdes-cbc\fP. The ability to decrypt packets is only present if \fItcpdump\fP was compiled @@ -165,65 +253,86 @@ Ties are broken by choosing the earliest match. .IP On Linux systems with 2.2 or later kernels, an .I interface -argument of ``any'' can be used to capture packets from all interfaces. +argument of ``any'' can be used to capture packets from all interfaces. Note that captures on the ``any'' device will not be done in promiscuous mode. .TP .B \-l -Make stdout line buffered. Useful if you want to see the data -while capturing it. E.g., +Make stdout line buffered. +Useful if you want to see the data +while capturing it. +E.g., .br ``tcpdump\ \ \-l\ \ |\ \ tee dat'' or ``tcpdump\ \ \-l \ \ > dat\ \ &\ \ tail\ \ \-f\ \ dat''. .TP +.B \-m +Load SMI MIB module definitions from file \fImodule\fR. +This option +can be used several times to load several MIB modules into \fItcpdump\fP. +.TP .B \-n Don't convert addresses (i.e., host addresses, port numbers, etc.) to names. .TP .B \-N -Don't print domain name qualification of host names. E.g., +Don't print domain name qualification of host names. +E.g., if you give this flag then \fItcpdump\fP will print ``nic'' instead of ``nic.ddn.mil''. .TP -.B \-m -Load SMI MIB module definitions from file \fImodule\fR. This option -can be used several times to load several MIB modules into \fItcpdump\fP. -.TP .B \-O -Do not run the packet-matching code optimizer. This is useful only +Do not run the packet-matching code optimizer. +This is useful only if you suspect a bug in the optimizer. .TP .B \-p \fIDon't\fP put the interface -into promiscuous mode. Note that the interface might be in promiscuous +into promiscuous mode. +Note that the interface might be in promiscuous mode for some other reason; hence, `-p' cannot be used as an abbreviation for `ether host {local-hw-addr} or ether broadcast'. .TP .B \-q -Quick (quiet?) output. Print less protocol information so output +Quick (quiet?) output. +Print less protocol information so output lines are shorter. .TP +.B \-R +Assume ESP/AH packets to be based on old specification (RFC1825 to RFC1829). +If specified, \fItcpdump\fP will not print replay prevention field. +Since there is no protocol version field in ESP/AH specification, +\fItcpdump\fP cannot deduce the version of ESP/AH protocol. +.TP .B \-r Read packets from \fIfile\fR (which was created with the -w option). Standard input is used if \fIfile\fR is ``-''. .TP +.B \-S +Print absolute, rather than relative, TCP sequence numbers. +.TP .B \-s Snarf \fIsnaplen\fP bytes of data from each packet rather than the default of 68 (with SunOS's NIT, the minimum is actually 96). 68 bytes is adequate for IP, ICMP, TCP and UDP but may truncate protocol information from name server and NFS -packets (see below). Packets truncated because of a limited snapshot +packets (see below). +Packets truncated because of a limited snapshot are indicated in the output with ``[|\fIproto\fP]'', where \fIproto\fP is the name of the protocol level at which the truncation has occurred. Note that taking larger snapshots both increases the amount of time it takes to process packets and, effectively, -decreases the amount of packet buffering. This may cause packets to be -lost. You should limit \fIsnaplen\fP to the smallest number that will -capture the protocol information you're interested in. Setting +decreases the amount of packet buffering. +This may cause packets to be +lost. +You should limit \fIsnaplen\fP to the smallest number that will +capture the protocol information you're interested in. +Setting \fIsnaplen\fP to 0 means use the required length to catch whole packets. .TP .B \-T Force packets selected by "\fIexpression\fP" to be interpreted the -specified \fItype\fR. Currently known types are +specified \fItype\fR. +Currently known types are \fBcnfp\fR (Cisco NetFlow protocol), \fBrpc\fR (Remote Procedure Call), \fBrtp\fR (Real-Time Applications protocol), @@ -233,15 +342,6 @@ specified \fItype\fR. Currently known types are and \fBwb\fR (distributed White Board). .TP -.B \-R -Assume ESP/AH packets to be based on old specification (RFC1825 to RFC1829). -If specified, \fItcpdump\fP will not print replay prevention field. -Since there is no protocol version field in ESP/AH specification, -\fItcpdump\fP cannot deduce the version of ESP/AH protocol. -.TP -.B \-S -Print absolute, rather than relative, TCP sequence numbers. -.TP .B \-t \fIDon't\fP print a timestamp on each dump line. .TP @@ -249,32 +349,39 @@ Print absolute, rather than relative, TCP sequence numbers. Print an unformatted timestamp on each dump line. .TP .B \-ttt -Print a delta (in micro-seconds) between current and previous line +Print a delta (in micro-seconds) between current and previous line on each dump line. .TP .B \-tttt Print a timestamp in default format proceeded by date on each dump line. +.B \-u +Print undecoded NFS handles. .TP .B \-v -(Slightly more) verbose output. For example, the time to live, +(Slightly more) verbose output. +For example, the time to live, identification, total length and options in an IP packet are printed. Also enables additional packet integrity checks such as verifying the IP and ICMP header checksum. .TP .B \-vv -Even more verbose output. For example, additional fields are -printed from NFS reply packets. +Even more verbose output. +For example, additional fields are +printed from NFS reply packets, and SMB packets are fully decoded. .TP .B \-vvv -Even more verbose output. For example, +Even more verbose output. +For example, telnet \fBSB\fP ... \fBSE\fP options -are printed in full. With +are printed in full. +With .B \-X telnet options are printed in hex as well. .TP .B \-w Write the raw packets to \fIfile\fR rather than parsing and printing -them out. They can later be printed with the \-r option. +them out. +They can later be printed with the \-r option. Standard output is used if \fIfile\fR is ``-''. .TP .B \-x @@ -284,7 +391,8 @@ The smaller of the entire packet or bytes will be printed. .TP .B \-X -When printing hex, print ascii too. Thus if +When printing hex, print ascii too. +Thus if .B \-x is also set, the packet is printed in hex/ascii. This is very handy for analysing new protocols. @@ -294,15 +402,18 @@ is not also set, some parts of some packets may be printed in hex/ascii. .IP "\fI expression\fP" .RS -selects which packets will be dumped. If no \fIexpression\fP -is given, all packets on the net will be dumped. Otherwise, +selects which packets will be dumped. +If no \fIexpression\fP +is given, all packets on the net will be dumped. +Otherwise, only packets for which \fIexpression\fP is `true' will be dumped. .LP The \fIexpression\fP consists of one or more .I primitives. Primitives usually consist of an .I id -(name or number) preceded by one or more qualifiers. There are three +(name or number) preceded by one or more qualifiers. +There are three different kinds of qualifier: .IP \fItype\fP qualifiers say what kind of thing the id name or number refers to. @@ -311,7 +422,8 @@ Possible types are .B net and .BR port . -E.g., `host foo', `net 128.3', `port 20'. If there is no type +E.g., `host foo', `net 128.3', `port 20'. +If there is no type qualifier, .B host is assumed. @@ -325,7 +437,8 @@ Possible directions are and .B "src and" .BR dst . -E.g., `src foo', `dst net 128.3', `src or dst port ftp-data'. If +E.g., `src foo', `dst net 128.3', `src or dst port ftp-data'. +If there is no dir qualifier, .B "src or dst" is assumed. @@ -335,7 +448,8 @@ and .B outbound qualifiers can be used to specify a desired direction. .IP \fIproto\fP -qualifiers restrict the match to a particular protocol. Possible +qualifiers restrict the match to a particular protocol. +Possible protos are: .BR ether , .BR fddi , @@ -348,9 +462,11 @@ protos are: .B tcp and .BR udp . -E.g., `ether src foo', `arp net 128.3', `tcp port 21'. If there is +E.g., `ether src foo', `arp net 128.3', `tcp port 21'. +If there is no proto qualifier, all protocols consistent with the type are -assumed. E.g., `src foo' means `(ip or arp or rarp) src foo' +assumed. +E.g., `src foo' means `(ip or arp or rarp) src foo' (except the latter is not legal syntax), `net bar' means `(ip or arp or rarp) net bar' and `port 53' means `(tcp or udp) port 53'. .LP @@ -359,7 +475,8 @@ identically as meaning ``the data link level used on the specified network interface.'' FDDI headers contain Ethernet-like source and destination addresses, and often contain Ethernet-like packet types, so you can filter on these FDDI fields just as with the -analogous Ethernet fields. FDDI headers also contain other fields, +analogous Ethernet fields. +FDDI headers also contain other fields, but you cannot name them explicitly in a filter expression. .LP Similarly, `tr' is an alias for `ether'; the previous paragraph's @@ -371,15 +488,18 @@ that don't follow the pattern: .BR broadcast , .BR less , .B greater -and arithmetic expressions. All of these are described below. +and arithmetic expressions. +All of these are described below. .LP More complex filter expressions are built up by using the words .BR and , .B or and .B not -to combine primitives. E.g., `host foo and not port ftp and not port ftp-data'. -To save typing, identical qualifier lists can be omitted. E.g., +to combine primitives. +E.g., `host foo and not port ftp and not port ftp-data'. +To save typing, identical qualifier lists can be omitted. +E.g., `tcp dst port ftp or ftp-data or domain' is exactly the same as `tcp dst port ftp or tcp dst port ftp-data or tcp dst port domain'. .LP @@ -407,7 +527,8 @@ which is equivalent to: If \fIhost\fR is a name with multiple IP addresses, each address will be checked for a match. .IP "\fBether dst \fIehost\fP -True if the ethernet destination address is \fIehost\fP. \fIEhost\fP +True if the ethernet destination address is \fIehost\fP. +\fIEhost\fP may be either a name from /etc/ethers or a number (see .IR ethers (3N) for numeric format). @@ -416,11 +537,15 @@ True if the ethernet source address is \fIehost\fP. .IP "\fBether host \fIehost\fP True if either the ethernet source or destination address is \fIehost\fP. .IP "\fBgateway\fP \fIhost\fP -True if the packet used \fIhost\fP as a gateway. I.e., the ethernet +True if the packet used \fIhost\fP as a gateway. +I.e., the ethernet source or destination address was \fIhost\fP but neither the IP source -nor the IP destination was \fIhost\fP. \fIHost\fP must be a name and -must be found in both /etc/hosts and /etc/ethers. (An equivalent -expression is +nor the IP destination was \fIhost\fP. +\fIHost\fP must be a name and +must be found both by the machine's host-name-to-IP-address resolution +mechanisms (host name file, DNS, NIS, etc.) and by the machine's +host-name-to-Ethernet-address resolution mechanism (/etc/ethers, etc.). +(An equivalent expression is .in +.5i .nf \fBether host \fIehost \fBand not host \fIhost\fR @@ -430,7 +555,8 @@ which can be used with either names or numbers for \fIhost / ehost\fP.) This syntax does not work in IPv6-enabled configuration at this moment. .IP "\fBdst net \fInet\fR" True if the IPv4/v6 destination address of the packet has a network -number of \fInet\fP. \fINet\fP may be either a name from /etc/networks +number of \fInet\fP. +\fINet\fP may be either a name from /etc/networks or a network number (see \fInetworks(4)\fP for details). .IP "\fBsrc net \fInet\fR" True if the IPv4/v6 source address of the packet has a network @@ -438,12 +564,13 @@ number of \fInet\fP. .IP "\fBnet \fInet\fR" True if either the IPv4/v6 source or destination address of the packet has a network number of \fInet\fP. -.IP "\fBnet \fInet\fR \fBmask \fImask\fR" -True if the IP address matches \fInet\fR with the specific netmask. +.IP "\fBnet \fInet\fR \fBmask \fInetmask\fR" +True if the IP address matches \fInet\fR with the specific \fInetmask\fR. May be qualified with \fBsrc\fR or \fBdst\fR. Note that this syntax is not valid for IPv6 \fInet\fR. .IP "\fBnet \fInet\fR/\fIlen\fR" -True if the IPv4/v6 address matches \fInet\fR a netmask \fIlen\fR bits wide. +True if the IPv4/v6 address matches \fInet\fR with a netmask \fIlen\fR +bits wide. May be qualified with \fBsrc\fR or \fBdst\fR. .IP "\fBdst port \fIport\fR" True if the packet is ip/tcp, ip/udp, ip6/tcp or ip6/udp and has a @@ -453,7 +580,8 @@ The \fIport\fP can be a number or a name used in /etc/services (see and .IR udp (4P)). If a name is used, both the port -number and protocol are checked. If a number or ambiguous name is used, +number and protocol are checked. +If a number or ambiguous name is used, only the port number is checked (e.g., \fBdst port 513\fR will print both tcp/login traffic and udp/who traffic, and \fBport domain\fR will print both tcp/domain and udp/domain traffic). @@ -491,13 +619,13 @@ True if the packet is an IP packet (see of protocol type \fIprotocol\fP. \fIProtocol\fP can be a number or one of the names \fIicmp\fP, \fIicmp6\fP, \fIigmp\fP, \fIigrp\fP, \fIpim\fP, \fIah\fP, -\fIesp\fP, \fIudp\fP, or \fItcp\fP. +\fIesp\fP, \fIvrrp\fP, \fIudp\fP, or \fItcp\fP. Note that the identifiers \fItcp\fP, \fIudp\fP, and \fIicmp\fP are also keywords and must be escaped via backslash (\\), which is \\\\ in the C-shell. -Note that this primitive does not chase protocol header chain. +Note that this primitive does not chase the protocol header chain. .IP "\fBip6 proto \fIprotocol\fR" True if the packet is an IPv6 packet of protocol type \fIprotocol\fP. -Note that this primitive does not chase protocol header chain. +Note that this primitive does not chase the protocol header chain. .IP "\fBip6 protochain \fIprotocol\fR" True if the packet is IPv6 packet, and contains protocol header with type \fIprotocol\fR @@ -518,14 +646,17 @@ so this can be somewhat slow. .IP "\fBip protochain \fIprotocol\fR" Equivalent to \fBip6 protochain \fIprotocol\fR, but this is for IPv4. .IP "\fBether broadcast\fR" -True if the packet is an ethernet broadcast packet. The \fIether\fP +True if the packet is an ethernet broadcast packet. +The \fIether\fP keyword is optional. .IP "\fBip broadcast\fR" -True if the packet is an IP broadcast packet. It checks for both +True if the packet is an IP broadcast packet. +It checks for both the all-zeroes and all-ones broadcast conventions, and looks up the local subnet mask. .IP "\fBether multicast\fR" -True if the packet is an ethernet multicast packet. The \fIether\fP +True if the packet is an ethernet multicast packet. +The \fIether\fP keyword is optional. This is shorthand for `\fBether[0] & 1 != 0\fP'. .IP "\fBip multicast\fR" @@ -536,21 +667,46 @@ True if the packet is an IPv6 multicast packet. True if the packet is of ether type \fIprotocol\fR. \fIProtocol\fP can be a number or one of the names \fIip\fP, \fIip6\fP, \fIarp\fP, \fIrarp\fP, \fIatalk\fP, \fIaarp\fP, -\fIdecnet\fP, \fIsca\fP, \fIlat\fP, \fImopdl\fP, \fImoprc\fP, or -\fIiso\fP. +\fIdecnet\fP, \fIsca\fP, \fIlat\fP, \fImopdl\fP, \fImoprc\fP, +\fIiso\fP, \fIstp\fP, \fIipx\fP, or \fInetbeui\fP. Note these identifiers are also keywords and must be escaped via backslash (\\). -[In the case of FDDI (e.g., `\fBfddi protocol arp\fR'), the -protocol identification comes from the 802.2 Logical Link Control -(LLC) header, which is usually layered on top of the FDDI header. -\fITcpdump\fP assumes, when filtering on the protocol identifier, -that all FDDI packets include an LLC header, and that the LLC header -is in so-called SNAP format. The same applies to Token Ring.] +.IP +[In the case of FDDI (e.g., `\fBfddi protocol arp\fR') and Token Ring +(e.g., `\fBtr protocol arp\fR'), for most of those protocols, the +protocol identification comes from the 802.2 Logical Link Control (LLC) +header, which is usually layered on top of the FDDI or Token Ring +header. +.IP +When filtering for most protocol identifiers on FDDI or Token Ring, +\fItcpdump\fR checks only the protocol ID field of an LLC header in +so-called SNAP format with an Organizational Unit Identifier (OUI) of +0x000000, for encapsulated Ethernet; it doesn't check whether the packet +is in SNAP format with an OUI of 0x000000. +.IP +The exceptions are \fIiso\fP, for which it checks the DSAP (Destination +Service Access Point) and SSAP (Source Service Access Point) fields of +the LLC header, \fIstp\fP and \fInetbeui\fP, where it checks the DSAP of +the LLC header, and \fIatalk\fP, where it checks for a SNAP-format +packet with an OUI of 0x080007 and the Appletalk etype. +.IP +In the case of Ethernet, \fItcpdump\fR checks the Ethernet type field +for most of those protocols; the exceptions are \fIiso\fP, \fIsap\fP, +and \fInetbeui\fP, for which it checks for an 802.3 frame and then +checks the LLC header as it does for FDDI and Token Ring, \fIatalk\fP, +where it checks both for the Appletalk etype in an Ethernet frame and +for a SNAP-format packet as it does for FDDI and Token Ring, \fIaarp\fP, +where it checks for the Appletalk ARP etype in either an Ethernet frame +or an 802.2 SNAP frame with an OUI of 0x000000, and \fIipx\fP, where it +checks for the IPX etype in an Ethernet frame, the IPX DSAP in the LLC +header, the 802.3 with no LLC header encapsulation of IPX, and the IPX +etype in a SNAP frame.] .IP "\fBdecnet src \fIhost\fR" True if the DECNET source address is .IR host , which may be an address of the form ``10.123'', or a DECNET host -name. [DECNET host name support is only available on Ultrix systems +name. +[DECNET host name support is only available on Ultrix systems that are configured to run DECNET.] .IP "\fBdecnet dst \fIhost\fR" True if the DECNET destination address is @@ -558,7 +714,7 @@ True if the DECNET destination address is .IP "\fBdecnet host \fIhost\fR" True if either the DECNET source or destination address is .IR host . -.IP "\fBip\fR, \fBip6\fR, \fBarp\fR, \fBrarp\fR, \fBatalk\fR, \fBaarp\fR, \fBdecnet\fR, \fBiso\fR" +.IP "\fBip\fR, \fBip6\fR, \fBarp\fR, \fBrarp\fR, \fBatalk\fR, \fBaarp\fR, \fBdecnet\fR, \fBiso\fR, \fBstp\fR, \fBipx\fR, \fInetbeui\fP" Abbreviations for: .in +.5i .nf @@ -630,7 +786,8 @@ length of the packet. For example, `\fBether[0] & 1 != 0\fP' catches all multicast traffic. The expression `\fBip[0] & 0xf != 5\fP' -catches all IP packets with options. The expression +catches all IP packets with options. +The expression `\fBip[6:2] & 0x1fff = 0\fP' catches only unfragmented datagrams and frag zero of fragmented datagrams. This check is implicitly applied to the \fBtcp\fP and \fBudp\fP @@ -638,6 +795,23 @@ index operations. For instance, \fBtcp[0]\fP always means the first byte of the TCP \fIheader\fP, and never means the first byte of an intervening fragment. + +Some offsets and field values may be expressed as names rather than +as numeric values. +The following protocol header field offsets are +available: \fBicmptype\fP (ICMP type field), \fBicmpcode\fP (ICMP +code field), and \fBtcpflags\fP (TCP flags field). + +The following ICMP type field values are available: \fBicmp-echoreply\fP, +\fBicmp-unreach\fP, \fBicmp-sourcequench\fP, \fBicmp-redirect\fP, +\fBicmp-echo\fP, \fBicmp-routeradvert\fP, \fBicmp-routersolicit\fP, +\fBicmp-timxceed\fP, \fBicmp-paramprob\fP, \fBicmp-tstamp\fP, +\fBicmp-tstampreply\fP, \fBicmp-ireq\fP, \fBicmp-ireqreply\fP, +\fBicmp-maskreq\fP, \fBicmp-maskreply\fP. + +The following TCP flags field values are available: \fBtcp-fin\fP, +\fBtcp-syn\fP, \fBtcp-rst\fP, \fBtcp-push\fP, \fBtcp-push\fP, +\fBtcp-ack\fP, \fBtcp-urg\fP. .LP Primitives may be combined using: .IP @@ -652,7 +826,8 @@ Alternation (`\fB||\fP' or `\fBor\fP'). .LP Negation has highest precedence. Alternation and concatenation have equal precedence and associate -left to right. Note that explicit \fBand\fR tokens, not juxtaposition, +left to right. +Note that explicit \fBand\fR tokens, not juxtaposition, are now required for concatenation. .LP If an identifier is given without a keyword, the most recent keyword @@ -737,7 +912,7 @@ TCP conversation that involves a non-local host. .RS .nf .B -tcpdump 'tcp[13] & 3 != 0 and not src and dst net \fIlocalnet\fP' +tcpdump 'tcp[tcpflags] & (tcp-syn|tcp-fin) != 0 and not src and dst net \fIlocalnet\fP' .fi .RE .LP @@ -764,12 +939,13 @@ ping packets): .RS .nf .B -tcpdump 'icmp[0] != 8 and icmp[0] != 0' +tcpdump 'icmp[icmptype] != icmp-echo and icmp[icmptype] != icmp-echoreply' .fi .RE .SH OUTPUT FORMAT .LP -The output of \fItcpdump\fP is protocol dependent. The following +The output of \fItcpdump\fP is protocol dependent. +The following gives a brief description and examples of most of the formats. .de HD .sp 1.5 @@ -784,18 +960,23 @@ and packet length are printed. .LP On FDDI networks, the '-e' option causes \fItcpdump\fP to print the `frame control' field, the source and destination addresses, -and the packet length. (The `frame control' field governs the -interpretation of the rest of the packet. Normal packets (such +and the packet length. +(The `frame control' field governs the +interpretation of the rest of the packet. +Normal packets (such as those containing IP datagrams) are `async' packets, with a priority -value between 0 and 7; for example, `\fBasync4\fR'. Such packets +value between 0 and 7; for example, `\fBasync4\fR'. +Such packets are assumed to contain an 802.2 Logical Link Control (LLC) packet; the LLC header is printed if it is \fInot\fR an ISO datagram or a so-called SNAP packet. .LP On Token Ring networks, the '-e' option causes \fItcpdump\fP to print the `access control' and `frame control' fields, the source and -destination addresses, and the packet length. As on FDDI networks, -packets are assumed to contain an LLC packet. Regardless of whether +destination addresses, and the packet length. +As on FDDI networks, +packets are assumed to contain an LLC packet. +Regardless of whether the '-e' option is specified or not, the source routing information is printed for source-routed packets. .LP @@ -832,7 +1013,8 @@ data and 6 bytes of compressed header: .HD ARP/RARP Packets .LP -Arp/rarp output shows the type of request and its arguments. The +Arp/rarp output shows the type of request and its arguments. +The format is intended to be self explanatory. Here is a short sample taken from the start of an `rlogin' from host \fIrtsg\fP to host \fIcsam\fP: @@ -845,11 +1027,12 @@ arp reply csam is-at CSAM\fR .fi .RE The first line says that rtsg sent an arp packet asking -for the ethernet address of internet host csam. Csam +for the ethernet address of internet host csam. +Csam replies with its ethernet address (in this example, ethernet addresses are in caps and internet addresses in lower case). .LP -This would look less redundant if we had done \fBtcpdump \-n\fP: +This would look less redundant if we had done \fItcpdump \-n\fP: .RS .nf .sp .5 @@ -858,7 +1041,7 @@ arp reply 128.3.254.6 is-at 02:07:01:00:01:c4\fP .fi .RE .LP -If we had done \fBtcpdump \-e\fP, the fact that the first packet is +If we had done \fItcpdump \-e\fP, the fact that the first packet is broadcast and the second is point-to-point would be visible: .RS .nf @@ -875,7 +1058,8 @@ contained hex 0806 (type ETHER_ARP) and the total length was 64 bytes. TCP Packets .LP \fI(N.B.:The following description assumes familiarity with -the TCP protocol described in RFC-793. If you are not familiar +the TCP protocol described in RFC-793. +If you are not familiar with the protocol, neither this description nor \fItcpdump\fP will be of much use to you.)\fP .LP @@ -888,7 +1072,8 @@ The general format of a tcp protocol line is: .fi .RE \fISrc\fP and \fIdst\fP are the source and destination IP -addresses and ports. \fIFlags\fP are some combination of S (SYN), +addresses and ports. +\fIFlags\fP are some combination of S (SYN), F (FIN), P (PUSH) or R (RST) or a single `.' (no flags). \fIData-seqno\fP describes the portion of sequence space covered by the data in this packet (see example below). @@ -899,7 +1084,8 @@ the other direction on this connection. \fIUrg\fP indicates there is `urgent' data in the packet. \fIOptions\fP are tcp options enclosed in angle brackets (e.g., <mss 1024>). .LP -\fISrc, dst\fP and \fIflags\fP are always present. The other fields +\fISrc, dst\fP and \fIflags\fP are always present. +The other fields depend on the contents of the packet's tcp protocol header and are output only if appropriate. .LP @@ -922,7 +1108,8 @@ csam.login > rtsg.1023: P 3:4(1) ack 21 win 4077 urg 1\fR\s+2 .RE The first line says that tcp port 1023 on rtsg sent a packet to port \fIlogin\fP -on csam. The \fBS\fP indicates that the \fISYN\fP flag was set. +on csam. +The \fBS\fP indicates that the \fISYN\fP flag was set. The packet sequence number was 768512 and it contained no data. (The notation is `first:last(nbytes)' which means `sequence numbers \fIfirst\fP @@ -932,25 +1119,31 @@ bytes and there was a max-segment-size option requesting an mss of 1024 bytes. .LP Csam replies with a similar packet except it includes a piggy-backed -ack for rtsg's SYN. Rtsg then acks csam's SYN. The `.' means no +ack for rtsg's SYN. +Rtsg then acks csam's SYN. +The `.' means no flags were set. The packet contained no data so there is no data sequence number. Note that the ack sequence -number is a small integer (1). The first time \fItcpdump\fP sees a +number is a small integer (1). +The first time \fItcpdump\fP sees a tcp `conversation', it prints the sequence number from the packet. On subsequent packets of the conversation, the difference between the current packet's sequence number and this initial sequence number -is printed. This means that sequence numbers after the +is printed. +This means that sequence numbers after the first can be interpreted as relative byte positions in the conversation's data stream (with the -first data byte each direction being `1'). `-S' will override this +first data byte each direction being `1'). +`-S' will override this feature, causing the original sequence numbers to be output. .LP On the 6th line, rtsg sends csam 19 bytes of data (bytes 2 through 20 in the rtsg \(-> csam side of the conversation). The PUSH flag is set in the packet. On the 7th line, csam says it's received data sent by rtsg up to -but not including byte 21. Most of this data is apparently sitting in the +but not including byte 21. +Most of this data is apparently sitting in the socket buffer since csam's receive window has gotten 19 bytes smaller. Csam also sends one byte of data to rtsg in this packet. On the 8th and 9th lines, @@ -959,22 +1152,25 @@ csam sends two bytes of urgent, pushed data to rtsg. If the snapshot was small enough that \fItcpdump\fP didn't capture the full TCP header, it interprets as much of the header as it can and then reports ``[|\fItcp\fP]'' to indicate the remainder could not -be interpreted. If the header contains a bogus option (one with a length +be interpreted. +If the header contains a bogus option (one with a length that's either too small or beyond the end of the header), \fItcpdump\fP reports it as ``[\fIbad opt\fP]'' and does not interpret any further -options (since it's impossible to tell where they start). If the header +options (since it's impossible to tell where they start). +If the header length indicates options are present but the IP datagram length is not long enough for the options to actually be there, \fItcpdump\fP reports it as ``[\fIbad hdr length\fP]''. .HD .B Capturing TCP packets with particular flag combinations (SYN-ACK, URG-ACK, etc.) .PP -There are 6 bits in the control bits section of the TCP header: +There are 8 bits in the control bits section of the TCP header: .IP -.I URG | ACK | PSH | RST | SYN | FIN +.I CWR | ECE | URG | ACK | PSH | RST | SYN | FIN .PP Let's assume that we want to watch packets used in establishing -a TCP connection. Recall that TCP uses a 3-way handshake protocol +a TCP connection. +Recall that TCP uses a 3-way handshake protocol when it initializes a new connection; the connection sequence with regard to the TCP control bits is .PP @@ -989,8 +1185,10 @@ regard to the TCP control bits is .RE .PP Now we're interested in capturing packets that have only the -SYN bit set (Step 1). Note that we don't want packets from step 2 -(SYN-ACK), just a plain initial SYN. What we need is a correct filter +SYN bit set (Step 1). +Note that we don't want packets from step 2 +(SYN-ACK), just a plain initial SYN. +What we need is a correct filter expression for \fItcpdump\fP. .PP Recall the structure of a TCP header without options: @@ -1004,14 +1202,15 @@ Recall the structure of a TCP header without options: ----------------------------------------------------------------- | acknowledgment number | ----------------------------------------------------------------- -| HL | reserved |U|A|P|R|S|F| window size | +| HL | rsvd |C|E|U|A|P|R|S|F| window size | ----------------------------------------------------------------- | TCP checksum | urgent pointer | ----------------------------------------------------------------- .fi .PP A TCP header usually holds 20 octets of data, unless options are -present. The fist line of the graph contains octets 0 - 3, the +present. +The first line of the graph contains octets 0 - 3, the second line shows octets 4 - 7 etc. .PP Starting to count with 0, the relevant TCP control bits are contained @@ -1020,7 +1219,7 @@ in octet 13: .nf 0 7| 15| 23| 31 ----------------|---------------|---------------|---------------- -| HL | reserved |U|A|P|R|S|F| window size | +| HL | rsvd |C|E|U|A|P|R|S|F| window size | ----------------|---------------|---------------|---------------- | | 13th octet | | | .fi @@ -1030,15 +1229,14 @@ Let's have a closer look at octet no. 13: .nf | | |---------------| - | |U|A|P|R|S|F| + |C|E|U|A|P|R|S|F| |---------------| |7 5 3 0| .fi .PP -We see that this octet contains 2 bytes from the reserved field. -According to RFC 793 this field is reserved for future use and must -be 0. The remaining 6 bits are the TCP control bits we are interested -in. We have numbered the bits in this octet from 0 to 7, right to +These are the TCP control bits we are interested +in. +We have numbered the bits in this octet from 0 to 7, right to left, so the PSH bit is bit number 3, while the URG bit is number 5. .PP Recall that we want to capture packets with only SYN set. @@ -1046,15 +1244,14 @@ Let's see what happens to octet 13 if a TCP datagram arrives with the SYN bit set in its header: .PP .nf - | |U|A|P|R|S|F| + |C|E|U|A|P|R|S|F| |---------------| |0 0 0 0 0 0 1 0| |---------------| |7 6 5 4 3 2 1 0| .fi .PP -We already mentioned that bits number 7 and 6 belong to the -reserved field, so they must must be 0. Looking at the +Looking at the control bits section we see that only bit number 1 (SYN) is set. .PP Assuming that octet number 13 is an 8-bit unsigned integer in @@ -1091,18 +1288,20 @@ the decimal value 2", which is exactly what we want. .PP Now, let's assume that we need to capture SYN packets, but we don't care if ACK or any other TCP control bit is set at the -same time. Let's see what happens to octet 13 when a TCP datagram +same time. +Let's see what happens to octet 13 when a TCP datagram with SYN-ACK set arrives: .PP .nf - | |U|A|P|R|S|F| + |C|E|U|A|P|R|S|F| |---------------| |0 0 0 1 0 0 1 0| |---------------| |7 6 5 4 3 2 1 0| .fi .PP -Now bits 1 and 4 are set in the 13th octet. The binary value of +Now bits 1 and 4 are set in the 13th octet. +The binary value of octet 13 is .IP 00010010 @@ -1116,12 +1315,14 @@ which translates to decimal .PP Now we can't just use 'tcp[13] == 18' in the \fItcpdump\fP filter expression, because that would select only those packets that have -SYN-ACK set, but not those with only SYN set. Remember that we don't care +SYN-ACK set, but not those with only SYN set. +Remember that we don't care if ACK or any other control bit is set as long as SYN is set. .PP In order to achieve our goal, we need to logically AND the binary value of octet 13 with some other value to preserve -the SYN bit. We know that we want SYN to be set in any case, +the SYN bit. +We know that we want SYN to be set in any case, so we'll logically AND the value in the 13th octet with the binary value of a SYN: .PP @@ -1165,7 +1366,8 @@ UDP format is illustrated by this rwho packet: .RE This says that port \fIwho\fP on host \fIactinide\fP sent a udp datagram to port \fIwho\fP on host \fIbroadcast\fP, the Internet -broadcast address. The packet contained 84 bytes of user data. +broadcast address. +The packet contained 84 bytes of user data. .LP Some UDP services are recognized (from the source or destination port number) and the higher level protocol information printed. @@ -1175,7 +1377,8 @@ RPC calls (RFC-1050) to NFS. UDP Name Server Requests .LP \fI(N.B.:The following description assumes familiarity with -the Domain Service protocol described in RFC-1035. If you are not familiar +the Domain Service protocol described in RFC-1035. +If you are not familiar with the protocol, the following description will appear to be written in greek.)\fP .LP @@ -1191,18 +1394,23 @@ Name server requests are formatted as .RE Host \fIh2opolo\fP asked the domain server on \fIhelios\fP for an address record (qtype=A) associated with the name \fIucbvax.berkeley.edu.\fP -The query id was `3'. The `+' indicates the \fIrecursion desired\fP flag -was set. The query length was 37 bytes, not including the UDP and -IP protocol headers. The query operation was the normal one, \fIQuery\fP, -so the op field was omitted. If the op had been anything else, it would +The query id was `3'. +The `+' indicates the \fIrecursion desired\fP flag +was set. +The query length was 37 bytes, not including the UDP and +IP protocol headers. +The query operation was the normal one, \fIQuery\fP, +so the op field was omitted. +If the op had been anything else, it would have been printed between the `3' and the `+'. Similarly, the qclass was the normal one, -\fIC_IN\fP, and omitted. Any other qclass would have been printed +\fIC_IN\fP, and omitted. +Any other qclass would have been printed immediately after the `A'. .LP A few anomalies are checked and may result in extra fields enclosed in -square brackets: If a query contains an answer, name server or -authority section, +square brackets: If a query contains an answer, authority records or +additional records section, .IR ancount , .IR nscount , or @@ -1227,48 +1435,59 @@ helios.domain > h2opolo.1537: 2 NXDomain* 0/1/0 (97)\fR .fi .RE In the first example, \fIhelios\fP responds to query id 3 from \fIh2opolo\fP -with 3 answer records, 3 name server records and 7 authority records. +with 3 answer records, 3 name server records and 7 additional records. The first answer record is type A (address) and its data is internet -address 128.32.137.3. The total size of the response was 273 bytes, -excluding UDP and IP headers. The op (Query) and response code +address 128.32.137.3. +The total size of the response was 273 bytes, +excluding UDP and IP headers. +The op (Query) and response code (NoError) were omitted, as was the class (C_IN) of the A record. .LP In the second example, \fIhelios\fP responds to query 2 with a response code of non-existent domain (NXDomain) with no answers, -one name server and no authority records. The `*' indicates that -the \fIauthoritative answer\fP bit was set. Since there were no +one name server and no authority records. +The `*' indicates that +the \fIauthoritative answer\fP bit was set. +Since there were no answers, no type, class or data were printed. .LP Other flag characters that might appear are `\-' (recursion available, -RA, \fInot\fP set) and `|' (truncated message, TC, set). If the +RA, \fInot\fP set) and `|' (truncated message, TC, set). +If the `question' section doesn't contain exactly one entry, `[\fIn\fPq]' is printed. .LP Note that name server requests and responses tend to be large and the default \fIsnaplen\fP of 68 bytes may not capture enough of the packet -to print. Use the \fB\-s\fP flag to increase the snaplen if you -need to seriously investigate name server traffic. `\fB\-s 128\fP' +to print. +Use the \fB\-s\fP flag to increase the snaplen if you +need to seriously investigate name server traffic. +`\fB\-s 128\fP' has worked well for me. .HD SMB/CIFS decoding .LP \fItcpdump\fP now includes fairly extensive SMB/CIFS/NBT decoding for data -on UDP/137, UDP/138 and TCP/139. Some primitive decoding of IPX and -NetBEUI SMB data is also done. +on UDP/137, UDP/138 and TCP/139. +Some primitive decoding of IPX and +NetBEUI SMB data is also done. By default a fairly minimal decode is done, with a much more detailed -decode done if -v is used. Be warned that with -v a single SMB packet +decode done if -v is used. +Be warned that with -v a single SMB packet may take up a page or more, so only use -v if you really want all the gory details. If you are decoding SMB sessions containing unicode strings then you -may wish to set the environment variable USE_UNICODE to 1. A patch to +may wish to set the environment variable USE_UNICODE to 1. +A patch to auto-detect unicode srings would be welcome. For information on SMB packet formats and what all te fields mean see www.cifs.org or the pub/samba/specs/ directory on your favourite -samba.org mirror site. The SMB patches were written by Andrew Tridgell +samba.org mirror site. +The SMB patches were written by Andrew Tridgell (tridge@samba.org). .HD @@ -1294,8 +1513,10 @@ wrl.nfs > sushi.201b: .RE In the first line, host \fIsushi\fP sends a transaction with id \fI6709\fP to \fIwrl\fP (note that the number following the src host is a -transaction id, \fInot\fP the source port). The request was 112 bytes, -excluding the UDP and IP headers. The operation was a \fIreadlink\fP +transaction id, \fInot\fP the source port). +The request was 112 bytes, +excluding the UDP and IP headers. +The operation was a \fIreadlink\fP (read symbolic link) on file handle (\fIfh\fP) 21,24/10.731657119. (If one is lucky, as in this case, the file handle can be interpreted as a major,minor device number pair, followed by the inode number and @@ -1303,8 +1524,10 @@ generation number.) \fIWrl\fP replies `ok' with the contents of the link. .LP In the third line, \fIsushi\fP asks \fIwrl\fP to lookup the name -`\fIxcolors\fP' in directory file 9,74/4096.6878. Note that the data printed -depends on the operation type. The format is intended to be self +`\fIxcolors\fP' in directory file 9,74/4096.6878. +Note that the data printed +depends on the operation type. +The format is intended to be self explanatory if read in conjunction with an NFS protocol spec. .LP @@ -1325,11 +1548,13 @@ wrl.nfs > sushi.1372a: (\-v also prints the IP header TTL, ID, length, and fragmentation fields, which have been omitted from this example.) In the first line, \fIsushi\fP asks \fIwrl\fP to read 8192 bytes from file 21,11/12.195, -at byte offset 24576. \fIWrl\fP replies `ok'; the packet shown on the +at byte offset 24576. +\fIWrl\fP replies `ok'; the packet shown on the second line is the first fragment of the reply, and hence is only 1472 bytes long (the other bytes will follow in subsequent fragments, but these fragments do not have NFS or even UDP headers and so might not be -printed, depending on the filter expression used). Because the \-v flag +printed, depending on the filter expression used). +Because the \-v flag is given, some of the file attributes (which are returned in addition to the file data) are printed: the file type (``REG'', for regular file), the file mode (in octal), the uid and gid, and the file size. @@ -1337,12 +1562,15 @@ the file mode (in octal), the uid and gid, and the file size. If the \-v flag is given more than once, even more details are printed. .LP Note that NFS requests are very large and much of the detail won't be printed -unless \fIsnaplen\fP is increased. Try using `\fB\-s 192\fP' to watch +unless \fIsnaplen\fP is increased. +Try using `\fB\-s 192\fP' to watch NFS traffic. .LP -NFS reply packets do not explicitly identify the RPC operation. Instead, +NFS reply packets do not explicitly identify the RPC operation. +Instead, \fItcpdump\fP keeps track of ``recent'' requests, and matches them to the -replies using the transaction ID. If a reply does not closely follow the +replies using the transaction ID. +If a reply does not closely follow the corresponding request, it might not be parsable. .HD AFS Requests and Replies @@ -1366,15 +1594,19 @@ pike.afsfs > elvis.7001: rx data fs reply rename .sp .5 .fi .RE -In the first line, host elvis sends a RX packet to pike. This was +In the first line, host elvis sends a RX packet to pike. +This was a RX data packet to the fs (fileserver) service, and is the start of -an RPC call. The RPC call was a rename, with the old directory file id +an RPC call. +The RPC call was a rename, with the old directory file id of 536876964/1/1 and an old filename of `.newsrc.new', and a new directory -file id of 536876964/1/1 and a new filename of `.newsrc'. The host pike +file id of 536876964/1/1 and a new filename of `.newsrc'. +The host pike responds with a RPC reply to the rename call (which was successful, because it was a data packet and not an abort packet). .LP -In general, all AFS RPCs are decoded at least by RPC call name. Most +In general, all AFS RPCs are decoded at least by RPC call name. +Most AFS RPCs have at least some of the arguments decoded (generally only the `interesting' arguments, for some definition of interesting). .LP @@ -1398,12 +1630,15 @@ beacon packets (because abort packets are used to signify a yes vote for the Ubik protocol). .LP Note that AFS requests are very large and many of the arguments won't -be printed unless \fIsnaplen\fP is increased. Try using `\fB-s 256\fP' +be printed unless \fIsnaplen\fP is increased. +Try using `\fB-s 256\fP' to watch AFS traffic. .LP -AFS reply packets do not explicitly identify the RPC operation. Instead, +AFS reply packets do not explicitly identify the RPC operation. +Instead, \fItcpdump\fP keeps track of ``recent'' requests, and matches them to the -replies using the call number and service ID. If a reply does not closely +replies using the call number and service ID. +If a reply does not closely follow the corresponding request, it might not be parsable. @@ -1412,7 +1647,8 @@ KIP Appletalk (DDP in UDP) .LP Appletalk DDP packets encapsulated in UDP datagrams are de-encapsulated and dumped as DDP packets (i.e., all the UDP header information is -discarded). The file +discarded). +The file .I /etc/atalk.names is used to translate appletalk net and node numbers to names. Lines in this file have the form @@ -1427,7 +1663,8 @@ Lines in this file have the form .sp .5 .fi .RE -The first two lines give the names of appletalk networks. The third +The first two lines give the names of appletalk networks. +The third line gives the name of a particular host (a host is distinguished from a net by the 3rd octet in the number \- a net number \fImust\fP have two octets and a host number \fImust\fP @@ -1457,14 +1694,16 @@ host/net number, addresses are printed in numeric form.) In the first example, NBP (DDP port 2) on net 144.1 node 209 is sending to whatever is listening on port 220 of net icsd node 112. The second line is the same except the full name of the source node -is known (`office'). The third line is a send from port 235 on +is known (`office'). +The third line is a send from port 235 on net jssmag node 149 to broadcast on the icsd-net NBP port (note that the broadcast address (255) is indicated by a net name with no host number \- for this reason it's a good idea to keep node names and net names distinct in /etc/atalk.names). .LP NBP (name binding protocol) and ATP (Appletalk transaction protocol) -packets have their contents interpreted. Other protocols just dump +packets have their contents interpreted. +Other protocols just dump the protocol name (or number if no name is registered for the protocol) and packet size. @@ -1479,10 +1718,12 @@ techpit.2 > icsd-net.112.220: nbp-reply 190: "techpit:LaserWriter@*" 186\fR\s+2 .fi .RE The first line is a name lookup request for laserwriters sent by net icsd host -112 and broadcast on net jssmag. The nbp id for the lookup is 190. +112 and broadcast on net jssmag. +The nbp id for the lookup is 190. The second line shows a reply for this request (note that it has the same id) from host jssmag.209 saying that it has a laserwriter -resource named "RM1140" registered on port 250. The third line is +resource named "RM1140" registered on port 250. +The third line is another reply to the same request saying host techpit has laserwriter "techpit" registered on port 186. @@ -1508,18 +1749,24 @@ jssmag.209.133 > helios.132: atp-req* 12267<0-7> 0xae030002\fR\s+2 .fi .RE Jssmag.209 initiates transaction id 12266 with host helios by requesting -up to 8 packets (the `<0-7>'). The hex number at the end of the line +up to 8 packets (the `<0-7>'). +The hex number at the end of the line is the value of the `userdata' field in the request. .LP -Helios responds with 8 512-byte packets. The `:digit' following the +Helios responds with 8 512-byte packets. +The `:digit' following the transaction id gives the packet sequence number in the transaction and the number in parens is the amount of data in the packet, -excluding the atp header. The `*' on packet 7 indicates that the +excluding the atp header. +The `*' on packet 7 indicates that the EOM bit was set. .LP -Jssmag.209 then requests that packets 3 & 5 be retransmitted. Helios -resends them then jssmag.209 releases the transaction. Finally, -jssmag.209 initiates the next request. The `*' on the request +Jssmag.209 then requests that packets 3 & 5 be retransmitted. +Helios +resends them then jssmag.209 releases the transaction. +Finally, +jssmag.209 initiates the next request. +The `*' on the request indicates that XO (`exactly once') was \fInot\fP set. .HD @@ -1534,16 +1781,21 @@ Fragmented Internet datagrams are printed as .sp .5 .fi .RE -(The first form indicates there are more fragments. The second +(The first form indicates there are more fragments. +The second indicates this is the last fragment.) .LP -\fIId\fP is the fragment id. \fISize\fP is the fragment -size (in bytes) excluding the IP header. \fIOffset\fP is this +\fIId\fP is the fragment id. +\fISize\fP is the fragment +size (in bytes) excluding the IP header. +\fIOffset\fP is this fragment's offset (in bytes) in the original datagram. .LP -The fragment information is output for each fragment. The first +The fragment information is output for each fragment. +The first fragment contains the higher level protocol header and the frag -info is printed after the protocol info. Fragments +info is printed after the protocol info. +Fragments after the first contain no higher level protocol header and the frag info is printed after the source and destination addresses. For example, here is part of an ftp from arizona.edu to lbl-rtsg.arpa @@ -1558,12 +1810,14 @@ rtsg.1170 > arizona.ftp-data: . ack 1536 win 2560\fP\s+2 .fi .RE There are a couple of things to note here: First, addresses in the -2nd line don't include port numbers. This is because the TCP +2nd line don't include port numbers. +This is because the TCP protocol information is all in the first fragment and we have no idea what the port or sequence numbers are when we print the later fragments. Second, the tcp sequence information in the first line is printed as if there were 308 bytes of user data when, in fact, there are 512 bytes (308 in -the first frag and 204 in the second). If you are looking for holes +the first frag and 204 in the second). +If you are looking for holes in the sequence space or trying to match up acks with packets, this can fool you. .LP @@ -1572,7 +1826,8 @@ trailing \fB(DF)\fP. .HD Timestamps .LP -By default, all output lines are preceded by a timestamp. The timestamp +By default, all output lines are preceded by a timestamp. +The timestamp is the current clock time in the form .RS .nf @@ -1580,7 +1835,8 @@ is the current clock time in the form .fi .RE and is as accurate as the kernel's clock. -The timestamp reflects the time the kernel first saw the packet. No attempt +The timestamp reflects the time the kernel first saw the packet. +No attempt is made to account for the time lag between when the ethernet interface removed the packet from the wire and when the kernel serviced the `new packet' interrupt. @@ -1647,7 +1903,8 @@ to compute the right length for the higher level protocol. .LP Name server inverse queries are not dumped correctly: the (empty) question section is printed rather than real query in the answer -section. Some believe that inverse queries are themselves a bug and +section. +Some believe that inverse queries are themselves a bug and prefer to fix the program generating them rather than \fItcpdump\fP. .LP A packet trace that crosses a daylight savings time change will give @@ -1655,8 +1912,10 @@ skewed time stamps (the time change is ignored). .LP Filter expressions that manipulate FDDI or Token Ring headers assume that all FDDI and Token Ring packets are SNAP-encapsulated Ethernet -packets. This is true for IP, ARP, and DECNET Phase IV, but is not true -for protocols such as ISO CLNS. Therefore, the filter may inadvertently +packets. +This is true for IP, ARP, and DECNET Phase IV, but is not true +for protocols such as ISO CLNS. +Therefore, the filter may inadvertently accept certain packets that do not properly match the filter expression. .LP Filter expressions on fields other than those that manipulate Token Ring diff --git a/contrib/tcpdump/tcpdump.c b/contrib/tcpdump/tcpdump.c index 4749271..8b21c20 100644 --- a/contrib/tcpdump/tcpdump.c +++ b/contrib/tcpdump/tcpdump.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -17,14 +17,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. + * + * Support for splitting captures into multiple files with a maximum + * file size: + * + * Copyright (c) 2001 + * Seth Webster <swebster@sst.ll.mit.edu> */ #ifndef lint static const char copyright[] = - "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997\n\ + "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\ The Regents of the University of California. All rights reserved.\n"; static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.158 2000/12/21 10:43:24 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.173 2001/12/22 22:12:23 guy Exp $ (LBL)"; #endif /* @@ -76,11 +82,14 @@ int uflag = 0; /* Print undecoded NFS handles */ int vflag; /* verbose */ int xflag; /* print packet in hex */ int Xflag; /* print packet in ascii as well as hex */ +off_t Cflag = 0; /* rotate dump files after this many bytes */ char *espsecret = NULL; /* ESP secret key */ int packettype; +int infodelay; +int infoprint; char *program_name; @@ -90,6 +99,12 @@ int32_t thiszone; /* seconds offset from gmt to local time */ static RETSIGTYPE cleanup(int); static void usage(void) __attribute__((noreturn)); +static void dump_and_trunc(u_char *, const struct pcap_pkthdr *, const u_char *); + +#ifdef SIGINFO +RETSIGTYPE requestinfo(int); +#endif + /* Length of saved portion of packet. */ int snaplen = DEFAULT_SNAPLEN; @@ -99,6 +114,7 @@ struct printer { }; static struct printer printers[] = { + { arcnet_if_print, DLT_ARCNET }, { ether_if_print, DLT_EN10MB }, { token_if_print, DLT_IEEE802 }, #ifdef DLT_LANE8023 @@ -124,12 +140,24 @@ static struct printer printers[] = { #ifdef DLT_C_HDLC { chdlc_if_print, DLT_C_HDLC }, #endif +#ifdef DLT_HDLC + { chdlc_if_print, DLT_HDLC }, +#endif #ifdef DLT_PPP_SERIAL { ppp_hdlc_if_print, DLT_PPP_SERIAL }, #endif +#ifdef DLT_PPP_ETHER + { pppoe_if_print, DLT_PPP_ETHER }, +#endif #ifdef DLT_LINUX_SLL { sll_if_print, DLT_LINUX_SLL }, #endif +#ifdef DLT_IEEE802_11 + { ieee802_11_if_print, DLT_IEEE802_11}, +#endif +#ifdef DLT_LTALK + { ltalk_if_print, DLT_LTALK }, +#endif { NULL, 0 }, }; @@ -152,6 +180,12 @@ extern int optind; extern int opterr; extern char *optarg; +struct dump_info { + char *WFileName; + pcap_t *pd; + pcap_dumper_t *p; +}; + int main(int argc, char **argv) { @@ -161,6 +195,7 @@ main(int argc, char **argv) pcap_handler printer; struct bpf_program fcode; RETSIGTYPE (*oldhandler)(int); + struct dump_info dumpinfo; u_char *pcap_userdata; char ebuf[PCAP_ERRBUF_SIZE]; @@ -183,7 +218,7 @@ main(int argc, char **argv) opterr = 0; while ( - (op = getopt(argc, argv, "ac:deE:fF:i:lm:nNOpqr:Rs:StT:uvw:xXY")) != -1) + (op = getopt(argc, argv, "ac:C:deE:fF:i:lm:nNOpqr:Rs:StT:uvw:xXY")) != -1) switch (op) { case 'a': @@ -196,6 +231,12 @@ main(int argc, char **argv) error("invalid packet count %s", optarg); break; + case 'C': + Cflag = atoi(optarg) * 1000000; + if (Cflag < 0) + error("invalid file size %s", optarg); + break; + case 'd': ++dflag; break; @@ -372,9 +413,12 @@ main(int argc, char **argv) if (device == NULL) error("%s", ebuf); } + *ebuf = '\0'; pd = pcap_open_live(device, snaplen, !pflag, 1000, ebuf); if (pd == NULL) error("%s", ebuf); + else if (*ebuf) + warning("%s", ebuf); i = pcap_snapshot(pd); if (snaplen < i) { warning("snaplen raised from %d to %d", snaplen, i); @@ -415,11 +459,22 @@ main(int argc, char **argv) pcap_dumper_t *p = pcap_dump_open(pd, WFileName); if (p == NULL) error("%s", pcap_geterr(pd)); - printer = pcap_dump; - pcap_userdata = (u_char *)p; + if (Cflag != 0) { + printer = dump_and_trunc; + dumpinfo.WFileName = WFileName; + dumpinfo.pd = pd; + dumpinfo.p = p; + pcap_userdata = (u_char *)&dumpinfo; + } else { + printer = pcap_dump; + pcap_userdata = (u_char *)p; + } } else { printer = lookup_printer(pcap_datalink(pd)); pcap_userdata = 0; +#ifdef SIGINFO + (void)setsignal(SIGINFO, requestinfo); +#endif } if (RFileName == NULL) { (void)fprintf(stderr, "%s: listening on %s\n", @@ -431,6 +486,8 @@ main(int argc, char **argv) program_name, pcap_geterr(pd)); exit(1); } + if (RFileName == NULL) + info(1); pcap_close(pd); exit(0); } @@ -439,25 +496,94 @@ main(int argc, char **argv) static RETSIGTYPE cleanup(int signo) { - struct pcap_stat stat; /* Can't print the summary if reading from a savefile */ if (pd != NULL && pcap_file(pd) == NULL) { (void)fflush(stdout); putc('\n', stderr); - if (pcap_stats(pd, &stat) < 0) - (void)fprintf(stderr, "pcap_stats: %s\n", - pcap_geterr(pd)); - else { - (void)fprintf(stderr, "%d packets received by filter\n", - stat.ps_recv); - (void)fprintf(stderr, "%d packets dropped by kernel\n", - stat.ps_drop); - } + info(1); } exit(0); } +void +info(register int verbose) +{ + struct pcap_stat stat; + + if (pcap_stats(pd, &stat) < 0) { + (void)fprintf(stderr, "pcap_stats: %s\n", pcap_geterr(pd)); + return; + } + if (!verbose) + fprintf(stderr, "%s: ", program_name); + (void)fprintf(stderr, "%d packets received by filter", stat.ps_recv); + if (!verbose) + fputs(", ", stderr); + else + putc('\n', stderr); + (void)fprintf(stderr, "%d packets dropped by kernel\n", stat.ps_drop); + infoprint = 0; +} + +static void +reverse(char *s) +{ + int i, j, c; + + for (i = 0, j = strlen(s) - 1; i < j; i++, j--) { + c = s[i]; + s[i] = s[j]; + s[j] = c; + } +} + + +static void +swebitoa(unsigned int n, char *s) +{ + unsigned int i; + + i = 0; + do { + s[i++] = n % 10 + '0'; + } while ((n /= 10) > 0); + + s[i] = '\0'; + reverse(s); +} + +static void +dump_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) +{ + struct dump_info *info; + static uint cnt = 2; + char *name; + + info = (struct dump_info *)user; + + /* + * XXX - this won't prevent capture files from getting + * larger than Cflag - the last packet written to the + * file could put it over Cflag. + */ + if (ftell((FILE *)info->p) > Cflag) { + name = (char *) malloc(strlen(info->WFileName) + 4); + if (name == NULL) + error("dump_and_trunc: malloc"); + strcpy(name, info->WFileName); + swebitoa(cnt, name + strlen(info->WFileName)); + cnt++; + pcap_dump_close(info->p); + info->p = pcap_dump_open(info->pd, name); + free(name); + if (info->p == NULL) + error("%s", pcap_geterr(pd)); + } + + pcap_dump((u_char *)info->p, h, sp); +} + /* Like default_print() but data need not be aligned */ void default_print_unaligned(register const u_char *cp, register u_int length) @@ -493,6 +619,16 @@ default_print(register const u_char *bp, register u_int length) default_print_unaligned(bp, length); } +#ifdef SIGINFO +RETSIGTYPE requestinfo(int signo) +{ + if (infodelay) + ++infoprint; + else + info(0); +} +#endif + static void usage(void) { @@ -502,10 +638,10 @@ usage(void) (void)fprintf(stderr, "%s version %s\n", program_name, version); (void)fprintf(stderr, "libpcap version %s\n", pcap_version); (void)fprintf(stderr, -"Usage: %s [-adeflnNOpqStuvxX] [-c count] [ -F file ]\n", program_name); +"Usage: %s [-adeflnNOpqRStuvxX] [ -c count ] [ -C file_size ]\n", program_name); (void)fprintf(stderr, -"\t\t[ -i interface ] [ -r file ] [ -s snaplen ]\n"); +"\t\t[ -F file ] [ -i interface ] [ -r file ] [ -s snaplen ]\n"); (void)fprintf(stderr, -"\t\t[ -T type ] [ -w file ] [ expression ]\n"); - exit(-1); +"\t\t[ -T type ] [ -w file ] [ -E algo:secret ] [ expression ]\n"); + exit(1); } diff --git a/contrib/tcpdump/telnet.h b/contrib/tcpdump/telnet.h new file mode 100644 index 0000000..c29aeac --- /dev/null +++ b/contrib/tcpdump/telnet.h @@ -0,0 +1,348 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/telnet.h,v 1.3 2001/09/17 21:58:06 fenner Exp $ (LBL) */ + +/* $NetBSD: telnet.h,v 1.9 2001/06/11 01:50:50 wiz Exp $ */ + +/* + * Copyright (c) 1983, 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. + * + * @(#)telnet.h 8.2 (Berkeley) 12/15/93 + */ + +#ifndef _ARPA_TELNET_H_ +#define _ARPA_TELNET_H_ + +/* + * Definitions for the TELNET protocol. + */ +#define IAC 255 /* interpret as command: */ +#define DONT 254 /* you are not to use option */ +#define DO 253 /* please, you use option */ +#define WONT 252 /* I won't use option */ +#define WILL 251 /* I will use option */ +#define SB 250 /* interpret as subnegotiation */ +#define GA 249 /* you may reverse the line */ +#define EL 248 /* erase the current line */ +#define EC 247 /* erase the current character */ +#define AYT 246 /* are you there */ +#define AO 245 /* abort output--but let prog finish */ +#define IP 244 /* interrupt process--permanently */ +#define BREAK 243 /* break */ +#define DM 242 /* data mark--for connect. cleaning */ +#define NOP 241 /* nop */ +#define SE 240 /* end sub negotiation */ +#define EOR 239 /* end of record (transparent mode) */ +#define ABORT 238 /* Abort process */ +#define SUSP 237 /* Suspend process */ +#define xEOF 236 /* End of file: EOF is already used... */ + +#define SYNCH 242 /* for telfunc calls */ + +#ifdef TELCMDS +const char *telcmds[] = { + "EOF", "SUSP", "ABORT", "EOR", + "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC", + "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", 0, +}; +#else +extern char *telcmds[]; +#endif + +#define TELCMD_FIRST xEOF +#define TELCMD_LAST IAC +#define TELCMD_OK(x) ((unsigned int)(x) <= TELCMD_LAST && \ + (unsigned int)(x) >= TELCMD_FIRST) +#define TELCMD(x) telcmds[(x)-TELCMD_FIRST] + +/* telnet options */ +#define TELOPT_BINARY 0 /* 8-bit data path */ +#define TELOPT_ECHO 1 /* echo */ +#define TELOPT_RCP 2 /* prepare to reconnect */ +#define TELOPT_SGA 3 /* suppress go ahead */ +#define TELOPT_NAMS 4 /* approximate message size */ +#define TELOPT_STATUS 5 /* give status */ +#define TELOPT_TM 6 /* timing mark */ +#define TELOPT_RCTE 7 /* remote controlled transmission and echo */ +#define TELOPT_NAOL 8 /* negotiate about output line width */ +#define TELOPT_NAOP 9 /* negotiate about output page size */ +#define TELOPT_NAOCRD 10 /* negotiate about CR disposition */ +#define TELOPT_NAOHTS 11 /* negotiate about horizontal tabstops */ +#define TELOPT_NAOHTD 12 /* negotiate about horizontal tab disposition */ +#define TELOPT_NAOFFD 13 /* negotiate about formfeed disposition */ +#define TELOPT_NAOVTS 14 /* negotiate about vertical tab stops */ +#define TELOPT_NAOVTD 15 /* negotiate about vertical tab disposition */ +#define TELOPT_NAOLFD 16 /* negotiate about output LF disposition */ +#define TELOPT_XASCII 17 /* extended ascic character set */ +#define TELOPT_LOGOUT 18 /* force logout */ +#define TELOPT_BM 19 /* byte macro */ +#define TELOPT_DET 20 /* data entry terminal */ +#define TELOPT_SUPDUP 21 /* supdup protocol */ +#define TELOPT_SUPDUPOUTPUT 22 /* supdup output */ +#define TELOPT_SNDLOC 23 /* send location */ +#define TELOPT_TTYPE 24 /* terminal type */ +#define TELOPT_EOR 25 /* end or record */ +#define TELOPT_TUID 26 /* TACACS user identification */ +#define TELOPT_OUTMRK 27 /* output marking */ +#define TELOPT_TTYLOC 28 /* terminal location number */ +#define TELOPT_3270REGIME 29 /* 3270 regime */ +#define TELOPT_X3PAD 30 /* X.3 PAD */ +#define TELOPT_NAWS 31 /* window size */ +#define TELOPT_TSPEED 32 /* terminal speed */ +#define TELOPT_LFLOW 33 /* remote flow control */ +#define TELOPT_LINEMODE 34 /* Linemode option */ +#define TELOPT_XDISPLOC 35 /* X Display Location */ +#define TELOPT_OLD_ENVIRON 36 /* Old - Environment variables */ +#define TELOPT_AUTHENTICATION 37/* Authenticate */ +#define TELOPT_ENCRYPT 38 /* Encryption option */ +#define TELOPT_NEW_ENVIRON 39 /* New - Environment variables */ +#define TELOPT_EXOPL 255 /* extended-options-list */ + + +#define NTELOPTS (1+TELOPT_NEW_ENVIRON) +#ifdef TELOPTS +const char *telopts[NTELOPTS+1] = { + "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", + "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP", + "NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS", + "NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO", + "DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT", + "SEND LOCATION", "TERMINAL TYPE", "END OF RECORD", + "TACACS UID", "OUTPUT MARKING", "TTYLOC", + "3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW", + "LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION", + "ENCRYPT", "NEW-ENVIRON", + 0, +}; +#define TELOPT_FIRST TELOPT_BINARY +#define TELOPT_LAST TELOPT_NEW_ENVIRON +#define TELOPT_OK(x) ((unsigned int)(x) <= TELOPT_LAST) +#define TELOPT(x) telopts[(x)-TELOPT_FIRST] +#endif + +/* sub-option qualifiers */ +#define TELQUAL_IS 0 /* option is... */ +#define TELQUAL_SEND 1 /* send option */ +#define TELQUAL_INFO 2 /* ENVIRON: informational version of IS */ +#define TELQUAL_REPLY 2 /* AUTHENTICATION: client version of IS */ +#define TELQUAL_NAME 3 /* AUTHENTICATION: client version of IS */ + +#define LFLOW_OFF 0 /* Disable remote flow control */ +#define LFLOW_ON 1 /* Enable remote flow control */ +#define LFLOW_RESTART_ANY 2 /* Restart output on any char */ +#define LFLOW_RESTART_XON 3 /* Restart output only on XON */ + +/* + * LINEMODE suboptions + */ + +#define LM_MODE 1 +#define LM_FORWARDMASK 2 +#define LM_SLC 3 + +#define MODE_EDIT 0x01 +#define MODE_TRAPSIG 0x02 +#define MODE_ACK 0x04 +#define MODE_SOFT_TAB 0x08 +#define MODE_LIT_ECHO 0x10 + +#define MODE_MASK 0x1f + +/* Not part of protocol, but needed to simplify things... */ +#define MODE_FLOW 0x0100 +#define MODE_ECHO 0x0200 +#define MODE_INBIN 0x0400 +#define MODE_OUTBIN 0x0800 +#define MODE_FORCE 0x1000 + +#define SLC_SYNCH 1 +#define SLC_BRK 2 +#define SLC_IP 3 +#define SLC_AO 4 +#define SLC_AYT 5 +#define SLC_EOR 6 +#define SLC_ABORT 7 +#define SLC_EOF 8 +#define SLC_SUSP 9 +#define SLC_EC 10 +#define SLC_EL 11 +#define SLC_EW 12 +#define SLC_RP 13 +#define SLC_LNEXT 14 +#define SLC_XON 15 +#define SLC_XOFF 16 +#define SLC_FORW1 17 +#define SLC_FORW2 18 +#define SLC_MCL 19 +#define SLC_MCR 20 +#define SLC_MCWL 21 +#define SLC_MCWR 22 +#define SLC_MCBOL 23 +#define SLC_MCEOL 24 +#define SLC_INSRT 25 +#define SLC_OVER 26 +#define SLC_ECR 27 +#define SLC_EWR 28 +#define SLC_EBOL 29 +#define SLC_EEOL 30 + +#define NSLC 30 + +/* + * For backwards compatibility, we define SLC_NAMES to be the + * list of names if SLC_NAMES is not defined. + */ +#define SLC_NAMELIST "0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \ + "ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \ + "LNEXT", "XON", "XOFF", "FORW1", "FORW2", \ + "MCL", "MCR", "MCWL", "MCWR", "MCBOL", \ + "MCEOL", "INSRT", "OVER", "ECR", "EWR", \ + "EBOL", "EEOL", \ + 0, + +#ifdef SLC_NAMES +const char *slc_names[] = { + SLC_NAMELIST +}; +#else +extern char *slc_names[]; +#define SLC_NAMES SLC_NAMELIST +#endif + +#define SLC_NAME_OK(x) ((unsigned int)(x) <= NSLC) +#define SLC_NAME(x) slc_names[x] + +#define SLC_NOSUPPORT 0 +#define SLC_CANTCHANGE 1 +#define SLC_VARIABLE 2 +#define SLC_DEFAULT 3 +#define SLC_LEVELBITS 0x03 + +#define SLC_FUNC 0 +#define SLC_FLAGS 1 +#define SLC_VALUE 2 + +#define SLC_ACK 0x80 +#define SLC_FLUSHIN 0x40 +#define SLC_FLUSHOUT 0x20 + +#define OLD_ENV_VAR 1 +#define OLD_ENV_VALUE 0 +#define NEW_ENV_VAR 0 +#define NEW_ENV_VALUE 1 +#define ENV_ESC 2 +#define ENV_USERVAR 3 + +/* + * AUTHENTICATION suboptions + */ + +/* + * Who is authenticating who ... + */ +#define AUTH_WHO_CLIENT 0 /* Client authenticating server */ +#define AUTH_WHO_SERVER 1 /* Server authenticating client */ +#define AUTH_WHO_MASK 1 + +/* + * amount of authentication done + */ +#define AUTH_HOW_ONE_WAY 0 +#define AUTH_HOW_MUTUAL 2 +#define AUTH_HOW_MASK 2 + +/* + * should we be encrypting? (not yet formally standardized) + */ +#define AUTH_ENCRYPT_OFF 0 +#define AUTH_ENCRYPT_ON 4 +#define AUTH_ENCRYPT_MASK 4 + +#define AUTHTYPE_NULL 0 +#define AUTHTYPE_KERBEROS_V4 1 +#define AUTHTYPE_KERBEROS_V5 2 +#define AUTHTYPE_SPX 3 +#define AUTHTYPE_MINK 4 +#define AUTHTYPE_CNT 5 + +#define AUTHTYPE_TEST 99 + +#ifdef AUTH_NAMES +const char *authtype_names[] = { + "NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", 0, +}; +#else +extern char *authtype_names[]; +#endif + +#define AUTHTYPE_NAME_OK(x) ((unsigned int)(x) < AUTHTYPE_CNT) +#define AUTHTYPE_NAME(x) authtype_names[x] + +/* + * ENCRYPTion suboptions + */ +#define ENCRYPT_IS 0 /* I pick encryption type ... */ +#define ENCRYPT_SUPPORT 1 /* I support encryption types ... */ +#define ENCRYPT_REPLY 2 /* Initial setup response */ +#define ENCRYPT_START 3 /* Am starting to send encrypted */ +#define ENCRYPT_END 4 /* Am ending encrypted */ +#define ENCRYPT_REQSTART 5 /* Request you start encrypting */ +#define ENCRYPT_REQEND 6 /* Request you send encrypting */ +#define ENCRYPT_ENC_KEYID 7 +#define ENCRYPT_DEC_KEYID 8 +#define ENCRYPT_CNT 9 + +#define ENCTYPE_ANY 0 +#define ENCTYPE_DES_CFB64 1 +#define ENCTYPE_DES_OFB64 2 +#define ENCTYPE_CNT 3 + +#ifdef ENCRYPT_NAMES +const char *encrypt_names[] = { + "IS", "SUPPORT", "REPLY", "START", "END", + "REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID", + 0, +}; +const char *enctype_names[] = { + "ANY", "DES_CFB64", "DES_OFB64", 0, +}; +#else +extern char *encrypt_names[]; +extern char *enctype_names[]; +#endif + + +#define ENCRYPT_NAME_OK(x) ((unsigned int)(x) < ENCRYPT_CNT) +#define ENCRYPT_NAME(x) encrypt_names[x] + +#define ENCTYPE_NAME_OK(x) ((unsigned int)(x) < ENCTYPE_CNT) +#define ENCTYPE_NAME(x) enctype_names[x] + +#endif /* _ARPA_TELNET_H_ */ diff --git a/contrib/tcpdump/util.c b/contrib/tcpdump/util.c index 57e3a03..3e498ac 100644 --- a/contrib/tcpdump/util.c +++ b/contrib/tcpdump/util.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.69 2000/07/11 00:49:03 assar Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.72 2001/10/08 16:12:13 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -178,15 +178,19 @@ ts_print(register const struct timeval *tvp) void relts_print(int secs) { - static char *lengths[] = {"y", "w", "d", "h", "m", "s"}; - static int seconds[] = {31536000, 604800, 86400, 3600, 60, 1}; - char **l = lengths; - int *s = seconds; + static const char *lengths[] = {"y", "w", "d", "h", "m", "s"}; + static const int seconds[] = {31536000, 604800, 86400, 3600, 60, 1}; + const char **l = lengths; + const int *s = seconds; - if (secs <= 0) { + if (secs == 0) { (void)printf("0s"); return; } + if (secs < 0) { + (void)printf("-"); + secs = -secs; + } while (secs > 0) { if (secs >= *s) { (void)printf("%d%s", secs / *s, *l); @@ -217,6 +221,25 @@ tok2str(register const struct tok *lp, register const char *fmt, return (buf); } +/* + * Convert a value to a string using an array; the macro + * tok2strary() in <interface.h> is the public interface to + * this function and ensures that the second argument is + * correct for bounds-checking. + */ +const char * +tok2strary_internal(register const char **lp, int n, register const char *fmt, + register int v) +{ + static char buf[128]; + + if (v >= 0 && v < n && lp[v] != NULL) + return lp[v]; + if (fmt == NULL) + fmt = "#%d"; + (void)snprintf(buf, sizeof(buf), fmt, v); + return (buf); +} /* VARARGS */ void @@ -303,7 +326,10 @@ read_infile(char *fname) error("can't stat %s: %s", fname, pcap_strerror(errno)); cp = malloc((u_int)buf.st_size + 1); - cc = read(fd, cp, (int)buf.st_size); + if (cp == NULL) + error("malloc(%d) for %s: %s", (u_int)buf.st_size + 1, + fname, pcap_strerror(errno)); + cc = read(fd, cp, (u_int)buf.st_size); if (cc < 0) error("read %s: %s", fname, pcap_strerror(errno)); if (cc != buf.st_size) |