From dd47fb4ef3dfc552fbf04aacd6643c27da5193cf Mon Sep 17 00:00:00 2001 From: itojun Date: Mon, 12 Apr 2004 08:26:08 +0000 Subject: [PATCH] tcpdump 3.8.3 --- kame/kame/tcpdump/.cvsignore | 9 +- kame/kame/tcpdump/CHANGES | 221 +- kame/kame/tcpdump/CREDITS | 120 + kame/kame/tcpdump/FILES | 149 +- kame/kame/tcpdump/INSTALL | 196 +- kame/kame/tcpdump/LICENSE | 19 + kame/kame/tcpdump/Makefile-devel-adds | 22 + kame/kame/tcpdump/Makefile.in | 106 +- kame/kame/tcpdump/PLATFORMS | 9 + kame/kame/tcpdump/README | 64 +- kame/kame/tcpdump/Readme.Win32 | 24 + kame/kame/tcpdump/TODO | 6 + kame/kame/tcpdump/VERSION | 2 +- kame/kame/tcpdump/acconfig.h | 128 + kame/kame/tcpdump/aclocal.m4 | 590 +- kame/kame/tcpdump/addrtoname.c | 717 +- kame/kame/tcpdump/addrtoname.h | 17 +- kame/kame/tcpdump/ah.h | 57 + kame/kame/tcpdump/aodv.h | 190 + kame/kame/tcpdump/appletalk.h | 60 +- kame/kame/tcpdump/arcnet.h | 101 + kame/kame/tcpdump/atm.h | 25 + kame/kame/tcpdump/atmuni31.h | 87 + kame/kame/tcpdump/bootp.h | 243 +- kame/kame/tcpdump/bpf_dump.c | 13 +- kame/kame/tcpdump/chdlc.h | 27 + kame/kame/tcpdump/config.guess | 1074 +- kame/kame/tcpdump/config.h.in | 293 + kame/kame/tcpdump/config.sub | 806 +- kame/kame/tcpdump/configure | 12575 +++++++++++++--- kame/kame/tcpdump/configure.in | 825 +- kame/kame/tcpdump/decnet.h | 26 +- kame/kame/tcpdump/enc.h | 47 + kame/kame/tcpdump/esp.h | 68 + kame/kame/tcpdump/ether.h | 59 + kame/kame/tcpdump/ethertype.h | 61 +- kame/kame/tcpdump/extract.h | 81 +- kame/kame/tcpdump/fddi.h | 9 +- kame/kame/tcpdump/gmpls.c | 134 + kame/kame/tcpdump/gmpls.h | 20 + kame/kame/tcpdump/gmt2local.c | 15 +- kame/kame/tcpdump/gmt2local.h | 2 +- kame/kame/tcpdump/icmp6.h | 451 + kame/kame/tcpdump/ieee802_11.h | 285 + kame/kame/tcpdump/igrp.h | 37 +- kame/kame/tcpdump/interface.h | 272 +- kame/kame/tcpdump/ip.h | 162 + kame/kame/tcpdump/ip6.h | 194 + kame/kame/tcpdump/ipfc.h | 29 + kame/kame/tcpdump/ipproto.h | 136 + kame/kame/tcpdump/ipsec_doi.h | 43 +- kame/kame/tcpdump/ipx.h | 28 +- kame/kame/tcpdump/isakmp.h | 101 +- kame/kame/tcpdump/l2tp.h | 26 +- kame/kame/tcpdump/lane.h | 41 + kame/kame/tcpdump/lbl/os-osf4.h | 26 + kame/kame/tcpdump/lbl/os-solaris2.h | 26 +- kame/kame/tcpdump/lbl/os-sunos4.h | 2 +- kame/kame/tcpdump/lbl/os-ultrix4.h | 2 +- kame/kame/tcpdump/llc.h | 75 +- kame/kame/tcpdump/machdep.c | 32 +- kame/kame/tcpdump/machdep.h | 4 +- kame/kame/tcpdump/makemib | 146 +- kame/kame/tcpdump/mib.h | 206 +- kame/kame/tcpdump/missing/addrinfo.h | 122 + kame/kame/tcpdump/missing/addrsize.h | 36 + kame/kame/tcpdump/missing/bittypes.h | 67 + kame/kame/tcpdump/missing/datalinks.c | 67 + kame/kame/tcpdump/missing/dlnames.c | 175 + kame/kame/tcpdump/missing/getaddrinfo.c | 1115 ++ kame/kame/tcpdump/missing/getnameinfo.c | 281 + kame/kame/tcpdump/missing/inet_aton.c | 60 + kame/kame/tcpdump/missing/inet_ntop.c | 104 + kame/kame/tcpdump/missing/inet_pton.c | 58 + kame/kame/tcpdump/missing/resolv6.h | 36 + kame/kame/tcpdump/missing/resolv_ext.h | 49 + kame/kame/tcpdump/missing/snprintf.c | 632 + kame/kame/tcpdump/missing/sockstorage.h | 38 + kame/kame/tcpdump/missing/strdup.c | 57 + kame/kame/tcpdump/missing/strlcat.c | 76 + kame/kame/tcpdump/missing/strlcpy.c | 73 + kame/kame/tcpdump/missing/strsep.c | 83 + kame/kame/tcpdump/nameser.h | 295 + kame/kame/tcpdump/netbios.h | 2 +- kame/kame/tcpdump/nfs.h | 453 + kame/kame/tcpdump/nfsfh.h | 38 +- kame/kame/tcpdump/ntp.h | 8 +- kame/kame/tcpdump/oakley.h | 6 +- kame/kame/tcpdump/ospf.h | 151 +- kame/kame/tcpdump/ospf6.h | 34 +- kame/kame/tcpdump/oui.c | 62 + kame/kame/tcpdump/oui.h | 41 + kame/kame/tcpdump/parsenfsfh.c | 79 +- kame/kame/tcpdump/pcap-missing.h | 56 + kame/kame/tcpdump/pf.h | 77 + kame/kame/tcpdump/ppp.h | 19 +- kame/kame/tcpdump/print-802_11.c | 1003 ++ kame/kame/tcpdump/print-ah.c | 51 +- kame/kame/tcpdump/print-aodv.c | 455 + kame/kame/tcpdump/print-ap1394.c | 119 + kame/kame/tcpdump/print-arcnet.c | 290 + kame/kame/tcpdump/print-arp.c | 305 +- kame/kame/tcpdump/print-ascii.c | 185 + kame/kame/tcpdump/print-atalk.c | 144 +- kame/kame/tcpdump/print-atm.c | 274 +- kame/kame/tcpdump/print-beep.c | 71 + kame/kame/tcpdump/print-bfd.c | 160 + kame/kame/tcpdump/print-bgp.c | 1859 +++ kame/kame/tcpdump/print-bootp.c | 545 +- kame/kame/tcpdump/print-cdp.c | 365 + kame/kame/tcpdump/print-chdlc.c | 142 +- kame/kame/tcpdump/print-cip.c | 108 + kame/kame/tcpdump/print-cnfp.c | 184 + kame/kame/tcpdump/print-decnet.c | 46 +- kame/kame/tcpdump/print-dhcp6.c | 609 + kame/kame/tcpdump/print-domain.c | 734 +- kame/kame/tcpdump/print-dvmrp.c | 220 +- kame/kame/tcpdump/print-egp.c | 86 +- kame/kame/tcpdump/print-enc.c | 78 + kame/kame/tcpdump/print-esp.c | 633 +- kame/kame/tcpdump/print-ether.c | 244 +- kame/kame/tcpdump/print-fddi.c | 109 +- kame/kame/tcpdump/print-fr.c | 487 + kame/kame/tcpdump/print-frag6.c | 70 +- kame/kame/tcpdump/print-gre.c | 438 +- kame/kame/tcpdump/print-hsrp.c | 136 + kame/kame/tcpdump/print-icmp.c | 330 +- kame/kame/tcpdump/print-icmp6.c | 1187 +- kame/kame/tcpdump/print-igmp.c | 335 + kame/kame/tcpdump/print-igrp.c | 31 +- kame/kame/tcpdump/print-ip.c | 781 +- kame/kame/tcpdump/print-ip6.c | 164 +- kame/kame/tcpdump/print-ip6opts.c | 234 +- kame/kame/tcpdump/print-ipcomp.c | 46 +- kame/kame/tcpdump/print-ipfc.c | 137 + kame/kame/tcpdump/print-ipx.c | 64 +- kame/kame/tcpdump/print-isakmp.c | 1037 +- kame/kame/tcpdump/print-isoclns.c | 2006 ++- kame/kame/tcpdump/print-krb.c | 61 +- kame/kame/tcpdump/print-l2tp.c | 846 +- kame/kame/tcpdump/print-lane.c | 168 + kame/kame/tcpdump/print-ldp.c | 382 + kame/kame/tcpdump/print-llc.c | 337 +- kame/kame/tcpdump/print-lwres.c | 601 + kame/kame/tcpdump/print-mobile.c | 52 +- kame/kame/tcpdump/print-mobility.c | 314 + kame/kame/tcpdump/print-mpls.c | 196 + kame/kame/tcpdump/print-msdp.c | 101 + kame/kame/tcpdump/print-netbios.c | 20 +- kame/kame/tcpdump/print-nfs.c | 1529 +- kame/kame/tcpdump/print-ntp.c | 79 +- kame/kame/tcpdump/print-null.c | 210 +- kame/kame/tcpdump/print-ospf.c | 769 +- kame/kame/tcpdump/print-ospf6.c | 177 +- kame/kame/tcpdump/print-pflog.c | 160 + kame/kame/tcpdump/print-pim.c | 810 +- kame/kame/tcpdump/print-ppp.c | 1378 +- kame/kame/tcpdump/print-pppoe.c | 218 + kame/kame/tcpdump/print-pptp.c | 1068 ++ kame/kame/tcpdump/print-radius.c | 910 ++ kame/kame/tcpdump/print-raw.c | 52 +- kame/kame/tcpdump/print-rip.c | 275 +- kame/kame/tcpdump/print-ripng.c | 85 +- kame/kame/tcpdump/print-rsvp.c | 1254 ++ kame/kame/tcpdump/print-rt6.c | 123 +- kame/kame/tcpdump/print-rx.c | 2485 +++ kame/kame/tcpdump/print-sctp.c | 345 + kame/kame/tcpdump/print-sl.c | 140 +- kame/kame/tcpdump/print-sll.c | 179 + kame/kame/tcpdump/print-smb.c | 1297 ++ kame/kame/tcpdump/print-snmp.c | 1075 +- kame/kame/tcpdump/print-stp.c | 102 + kame/kame/tcpdump/print-sunatm.c | 117 + kame/kame/tcpdump/print-sunrpc.c | 102 +- kame/kame/tcpdump/print-tcp.c | 456 +- kame/kame/tcpdump/print-telnet.c | 267 + kame/kame/tcpdump/print-tftp.c | 31 +- kame/kame/tcpdump/print-timed.c | 111 + kame/kame/tcpdump/print-token.c | 195 + kame/kame/tcpdump/print-udp.c | 476 +- kame/kame/tcpdump/print-vjc.c | 85 +- kame/kame/tcpdump/print-vrrp.c | 138 + kame/kame/tcpdump/print-wb.c | 85 +- kame/kame/tcpdump/print-zephyr.c | 311 + kame/kame/tcpdump/route6d.h | 44 +- kame/kame/tcpdump/rx.h | 113 + kame/kame/tcpdump/sctpConstants.h | 571 + kame/kame/tcpdump/sctpHeader.h | 323 + kame/kame/tcpdump/setsignal.c | 49 +- kame/kame/tcpdump/setsignal.h | 2 +- kame/kame/tcpdump/slcompress.h | 87 + kame/kame/tcpdump/slip.h | 34 + kame/kame/tcpdump/sll.h | 127 + kame/kame/tcpdump/smb.h | 122 + kame/kame/tcpdump/smbutil.c | 853 ++ kame/kame/tcpdump/strcasecmp.c | 13 +- kame/kame/tcpdump/tcp.h | 80 + kame/kame/tcpdump/tcpdump-stdinc.h | 128 + kame/kame/tcpdump/tcpdump.1 | 1388 +- kame/kame/tcpdump/tcpdump.c | 871 +- kame/kame/tcpdump/telnet.h | 348 + kame/kame/tcpdump/tests/.cvsignore | 6 + .../tcpdump/tests/02-sunrise-sunset-esp.puu | 34 + .../tcpdump/tests/08-sunrise-sunset-esp2.puu | 43 + kame/kame/tcpdump/tests/alltests.sh | 12 + kame/kame/tcpdump/tests/bgp_vpn_attrset.out | 18 + kame/kame/tcpdump/tests/bgp_vpn_attrset.pcap | Bin 0 -> 217 bytes kame/kame/tcpdump/tests/bgp_vpn_attrset.sh | 11 + kame/kame/tcpdump/tests/eapon1.gdbinit | 1 + kame/kame/tcpdump/tests/eapon1.out | 114 + kame/kame/tcpdump/tests/eapon1.pcap | Bin 0 -> 16412 bytes kame/kame/tcpdump/tests/eapon1.puu | 368 + kame/kame/tcpdump/tests/eapon1.sh | 12 + kame/kame/tcpdump/tests/eapon2.puu | 66 + kame/kame/tcpdump/tests/esp-secrets.txt | 5 + kame/kame/tcpdump/tests/esp0.out | 8 + kame/kame/tcpdump/tests/esp0.sh | 12 + kame/kame/tcpdump/tests/esp1.gdbinit | 1 + kame/kame/tcpdump/tests/esp1.out | 8 + kame/kame/tcpdump/tests/esp1.sh | 12 + kame/kame/tcpdump/tests/esp2.gdbinit | 1 + kame/kame/tcpdump/tests/esp2.out | 8 + kame/kame/tcpdump/tests/esp2.sh | 12 + kame/kame/tcpdump/tests/esp3.gdbinit | 1 + kame/kame/tcpdump/tests/esp3.sh | 11 + kame/kame/tcpdump/tests/esp4.gdbinit | 2 + kame/kame/tcpdump/tests/esp4.sh | 12 + .../tcpdump/tests/isakmp-delete-segfault.puu | 20 + .../tests/isakmp-identification-segfault.puu | 11 + .../tcpdump/tests/isakmp-pointer-loop.puu | 6 + kame/kame/tcpdump/tests/isakmp1.out | 1 + kame/kame/tcpdump/tests/isakmp1.sh | 12 + kame/kame/tcpdump/tests/isakmp2.out | 1 + kame/kame/tcpdump/tests/isakmp2.sh | 12 + kame/kame/tcpdump/tests/isakmp3.out | 2 + kame/kame/tcpdump/tests/isakmp3.sh | 12 + kame/kame/tcpdump/tests/mpls-ldp-hello.out | 9 + kame/kame/tcpdump/tests/mpls-ldp-hello.pcap | Bin 0 -> 114 bytes kame/kame/tcpdump/tests/mpls-ldp-hello.sh | 11 + kame/kame/tcpdump/tests/ospf-gmpls.out | 83 + kame/kame/tcpdump/tests/ospf-gmpls.pcap | Bin 0 -> 640 bytes kame/kame/tcpdump/tests/ospf-gmpls.sh | 11 + kame/kame/tcpdump/timed.h | 92 + kame/kame/tcpdump/token.h | 52 + kame/kame/tcpdump/udp.h | 84 + kame/kame/tcpdump/util.c | 297 +- kame/kame/tcpdump/vfprintf.c | 12 +- kame/kame/tcpdump/win32/Include/Arpa/tftp.h | 84 + .../tcpdump/win32/Include/Netinet/in_systm.h | 56 + kame/kame/tcpdump/win32/Include/Netinet/ip.h | 177 + kame/kame/tcpdump/win32/Include/Rpc/rpc.h | 157 + kame/kame/tcpdump/win32/Include/errno.h | 132 + kame/kame/tcpdump/win32/Include/getopt.h | 138 + kame/kame/tcpdump/win32/Include/inetprivate.h | 40 + kame/kame/tcpdump/win32/Include/telnet.h | 320 + kame/kame/tcpdump/win32/Include/w32_fzs.h | 48 + kame/kame/tcpdump/win32/Src/getopt.c | 121 + kame/kame/tcpdump/win32/prj/GNUmakefile | 141 + kame/kame/tcpdump/win32/prj/WinDump.dsp | 527 + kame/kame/tcpdump/win32/prj/WinDump.dsw | 29 + 260 files changed, 61756 insertions(+), 9618 deletions(-) create mode 100644 kame/kame/tcpdump/CREDITS create mode 100644 kame/kame/tcpdump/LICENSE create mode 100644 kame/kame/tcpdump/Makefile-devel-adds create mode 100644 kame/kame/tcpdump/PLATFORMS create mode 100644 kame/kame/tcpdump/Readme.Win32 create mode 100644 kame/kame/tcpdump/TODO create mode 100644 kame/kame/tcpdump/acconfig.h create mode 100644 kame/kame/tcpdump/ah.h create mode 100644 kame/kame/tcpdump/aodv.h create mode 100644 kame/kame/tcpdump/arcnet.h create mode 100644 kame/kame/tcpdump/atm.h create mode 100644 kame/kame/tcpdump/atmuni31.h create mode 100644 kame/kame/tcpdump/chdlc.h create mode 100644 kame/kame/tcpdump/config.h.in create mode 100644 kame/kame/tcpdump/enc.h create mode 100644 kame/kame/tcpdump/esp.h create mode 100644 kame/kame/tcpdump/ether.h create mode 100644 kame/kame/tcpdump/gmpls.c create mode 100644 kame/kame/tcpdump/gmpls.h create mode 100644 kame/kame/tcpdump/icmp6.h create mode 100644 kame/kame/tcpdump/ieee802_11.h create mode 100644 kame/kame/tcpdump/ip.h create mode 100644 kame/kame/tcpdump/ip6.h create mode 100644 kame/kame/tcpdump/ipfc.h create mode 100644 kame/kame/tcpdump/ipproto.h create mode 100644 kame/kame/tcpdump/lane.h create mode 100644 kame/kame/tcpdump/lbl/os-osf4.h create mode 100644 kame/kame/tcpdump/missing/addrinfo.h create mode 100644 kame/kame/tcpdump/missing/addrsize.h create mode 100644 kame/kame/tcpdump/missing/bittypes.h create mode 100644 kame/kame/tcpdump/missing/datalinks.c create mode 100644 kame/kame/tcpdump/missing/dlnames.c create mode 100644 kame/kame/tcpdump/missing/getaddrinfo.c create mode 100644 kame/kame/tcpdump/missing/getnameinfo.c create mode 100644 kame/kame/tcpdump/missing/inet_aton.c create mode 100644 kame/kame/tcpdump/missing/inet_ntop.c create mode 100644 kame/kame/tcpdump/missing/inet_pton.c create mode 100644 kame/kame/tcpdump/missing/resolv6.h create mode 100644 kame/kame/tcpdump/missing/resolv_ext.h create mode 100644 kame/kame/tcpdump/missing/snprintf.c create mode 100644 kame/kame/tcpdump/missing/sockstorage.h create mode 100644 kame/kame/tcpdump/missing/strdup.c create mode 100644 kame/kame/tcpdump/missing/strlcat.c create mode 100644 kame/kame/tcpdump/missing/strlcpy.c create mode 100644 kame/kame/tcpdump/missing/strsep.c create mode 100644 kame/kame/tcpdump/nameser.h create mode 100644 kame/kame/tcpdump/nfs.h create mode 100644 kame/kame/tcpdump/oui.c create mode 100644 kame/kame/tcpdump/oui.h create mode 100644 kame/kame/tcpdump/pcap-missing.h create mode 100644 kame/kame/tcpdump/pf.h create mode 100644 kame/kame/tcpdump/print-802_11.c create mode 100644 kame/kame/tcpdump/print-aodv.c create mode 100644 kame/kame/tcpdump/print-ap1394.c create mode 100644 kame/kame/tcpdump/print-arcnet.c create mode 100644 kame/kame/tcpdump/print-ascii.c create mode 100644 kame/kame/tcpdump/print-beep.c create mode 100644 kame/kame/tcpdump/print-bfd.c create mode 100644 kame/kame/tcpdump/print-bgp.c create mode 100644 kame/kame/tcpdump/print-cdp.c create mode 100644 kame/kame/tcpdump/print-cip.c create mode 100644 kame/kame/tcpdump/print-cnfp.c create mode 100644 kame/kame/tcpdump/print-dhcp6.c create mode 100644 kame/kame/tcpdump/print-enc.c create mode 100644 kame/kame/tcpdump/print-fr.c create mode 100644 kame/kame/tcpdump/print-hsrp.c create mode 100644 kame/kame/tcpdump/print-igmp.c create mode 100644 kame/kame/tcpdump/print-ipfc.c create mode 100644 kame/kame/tcpdump/print-lane.c create mode 100644 kame/kame/tcpdump/print-ldp.c create mode 100644 kame/kame/tcpdump/print-lwres.c create mode 100644 kame/kame/tcpdump/print-mobility.c create mode 100644 kame/kame/tcpdump/print-mpls.c create mode 100644 kame/kame/tcpdump/print-msdp.c create mode 100644 kame/kame/tcpdump/print-pflog.c create mode 100644 kame/kame/tcpdump/print-pppoe.c create mode 100644 kame/kame/tcpdump/print-pptp.c create mode 100644 kame/kame/tcpdump/print-radius.c create mode 100644 kame/kame/tcpdump/print-rsvp.c create mode 100644 kame/kame/tcpdump/print-rx.c create mode 100644 kame/kame/tcpdump/print-sctp.c create mode 100644 kame/kame/tcpdump/print-sll.c create mode 100644 kame/kame/tcpdump/print-smb.c create mode 100644 kame/kame/tcpdump/print-stp.c create mode 100644 kame/kame/tcpdump/print-sunatm.c create mode 100644 kame/kame/tcpdump/print-telnet.c create mode 100644 kame/kame/tcpdump/print-timed.c create mode 100644 kame/kame/tcpdump/print-token.c create mode 100644 kame/kame/tcpdump/print-vrrp.c create mode 100644 kame/kame/tcpdump/print-zephyr.c create mode 100644 kame/kame/tcpdump/rx.h create mode 100644 kame/kame/tcpdump/sctpConstants.h create mode 100644 kame/kame/tcpdump/sctpHeader.h create mode 100644 kame/kame/tcpdump/slcompress.h create mode 100644 kame/kame/tcpdump/slip.h create mode 100644 kame/kame/tcpdump/sll.h create mode 100644 kame/kame/tcpdump/smb.h create mode 100644 kame/kame/tcpdump/smbutil.c create mode 100644 kame/kame/tcpdump/tcp.h create mode 100644 kame/kame/tcpdump/tcpdump-stdinc.h create mode 100644 kame/kame/tcpdump/telnet.h create mode 100644 kame/kame/tcpdump/tests/.cvsignore create mode 100644 kame/kame/tcpdump/tests/02-sunrise-sunset-esp.puu create mode 100644 kame/kame/tcpdump/tests/08-sunrise-sunset-esp2.puu create mode 100644 kame/kame/tcpdump/tests/alltests.sh create mode 100644 kame/kame/tcpdump/tests/bgp_vpn_attrset.out create mode 100644 kame/kame/tcpdump/tests/bgp_vpn_attrset.pcap create mode 100755 kame/kame/tcpdump/tests/bgp_vpn_attrset.sh create mode 100644 kame/kame/tcpdump/tests/eapon1.gdbinit create mode 100644 kame/kame/tcpdump/tests/eapon1.out create mode 100644 kame/kame/tcpdump/tests/eapon1.pcap create mode 100644 kame/kame/tcpdump/tests/eapon1.puu create mode 100755 kame/kame/tcpdump/tests/eapon1.sh create mode 100644 kame/kame/tcpdump/tests/eapon2.puu create mode 100644 kame/kame/tcpdump/tests/esp-secrets.txt create mode 100644 kame/kame/tcpdump/tests/esp0.out create mode 100644 kame/kame/tcpdump/tests/esp0.sh create mode 100644 kame/kame/tcpdump/tests/esp1.gdbinit create mode 100644 kame/kame/tcpdump/tests/esp1.out create mode 100644 kame/kame/tcpdump/tests/esp1.sh create mode 100644 kame/kame/tcpdump/tests/esp2.gdbinit create mode 100644 kame/kame/tcpdump/tests/esp2.out create mode 100644 kame/kame/tcpdump/tests/esp2.sh create mode 100644 kame/kame/tcpdump/tests/esp3.gdbinit create mode 100644 kame/kame/tcpdump/tests/esp3.sh create mode 100644 kame/kame/tcpdump/tests/esp4.gdbinit create mode 100644 kame/kame/tcpdump/tests/esp4.sh create mode 100644 kame/kame/tcpdump/tests/isakmp-delete-segfault.puu create mode 100644 kame/kame/tcpdump/tests/isakmp-identification-segfault.puu create mode 100644 kame/kame/tcpdump/tests/isakmp-pointer-loop.puu create mode 100644 kame/kame/tcpdump/tests/isakmp1.out create mode 100644 kame/kame/tcpdump/tests/isakmp1.sh create mode 100644 kame/kame/tcpdump/tests/isakmp2.out create mode 100644 kame/kame/tcpdump/tests/isakmp2.sh create mode 100644 kame/kame/tcpdump/tests/isakmp3.out create mode 100644 kame/kame/tcpdump/tests/isakmp3.sh create mode 100644 kame/kame/tcpdump/tests/mpls-ldp-hello.out create mode 100644 kame/kame/tcpdump/tests/mpls-ldp-hello.pcap create mode 100755 kame/kame/tcpdump/tests/mpls-ldp-hello.sh create mode 100644 kame/kame/tcpdump/tests/ospf-gmpls.out create mode 100644 kame/kame/tcpdump/tests/ospf-gmpls.pcap create mode 100755 kame/kame/tcpdump/tests/ospf-gmpls.sh create mode 100644 kame/kame/tcpdump/timed.h create mode 100644 kame/kame/tcpdump/token.h create mode 100644 kame/kame/tcpdump/udp.h create mode 100644 kame/kame/tcpdump/win32/Include/Arpa/tftp.h create mode 100644 kame/kame/tcpdump/win32/Include/Netinet/in_systm.h create mode 100644 kame/kame/tcpdump/win32/Include/Netinet/ip.h create mode 100644 kame/kame/tcpdump/win32/Include/Rpc/rpc.h create mode 100644 kame/kame/tcpdump/win32/Include/errno.h create mode 100644 kame/kame/tcpdump/win32/Include/getopt.h create mode 100644 kame/kame/tcpdump/win32/Include/inetprivate.h create mode 100644 kame/kame/tcpdump/win32/Include/telnet.h create mode 100644 kame/kame/tcpdump/win32/Include/w32_fzs.h create mode 100644 kame/kame/tcpdump/win32/Src/getopt.c create mode 100644 kame/kame/tcpdump/win32/prj/GNUmakefile create mode 100644 kame/kame/tcpdump/win32/prj/WinDump.dsp create mode 100644 kame/kame/tcpdump/win32/prj/WinDump.dsw diff --git a/kame/kame/tcpdump/.cvsignore b/kame/kame/tcpdump/.cvsignore index 9f175ed83e..f07c8e4d03 100644 --- a/kame/kame/tcpdump/.cvsignore +++ b/kame/kame/tcpdump/.cvsignore @@ -1,6 +1,11 @@ +version.c Makefile +Makefile-devel.in +config.status config.log config.cache -config.status -version.c +config.h +.devel +stamp-h +stamp-h.in tcpdump diff --git a/kame/kame/tcpdump/CHANGES b/kame/kame/tcpdump/CHANGES index 9639d4104b..e69ba22403 100644 --- a/kame/kame/tcpdump/CHANGES +++ b/kame/kame/tcpdump/CHANGES @@ -1,4 +1,223 @@ -@(#) $Header: CHANGES,v 1.54 98/07/25 12:41:06 leres Exp $ (LBL) +$Header: /tcpdump/master/tcpdump/CHANGES,v 1.84.2.3 2004/03/30 14:36:24 mcr Exp $ + +Tue. March 30, 2004. mcr@sandelman.ottawa.on.ca. Summary for 3.8.3 release + + No changes from 3.8.2. Version bumped only to maintain consistency + with libpcap 0.8.3. + +Mon. March 29, 2004. mcr@sandelman.ottawa.on.ca. Summary for 3.8.2 release + + Fixes for print-isakmp.c CVE: CAN-2004-0183, CAN-2004-0184 + http://www.rapid7.com/advisories/R7-0017.html + IP-over-IEEE1394 printing. + some MINGW32 changes. + updates for autoconf 2.5 + fixes for print-aodv.c - check for too short packets + formatting changes to print-ascii for hex output. + check for too short packets: print-bgp.c, print-bootp.c, print-cdp.c, + print-chdlc.c, print-domain.c, print-icmp.c, print-icmp6.c, + print-ip.c, print-lwres.c, print-ospf.c, print-pim.c, + print-ppp.c,print-pppoe.c, print-rsvp.c, print-wb.c + print-ether.c - better handling of unknown types. + print-isoclns.c - additional decoding of types. + print-llc.c - strings for LLC names added. + print-pfloc.c - various enhancements + print-radius.c - better decoding to strings. + +Wed. November 12, 2003. mcr@sandelman.ottawa.on.ca. Summary for 3.8 release + + changed syntax of -E argument so that multiple SAs can be decrypted + fixes for Digital Unix headers and Documentation + __attribute__ fixes + CDP changes from Terry Kennedy . + IPv6 mobility updates from Kazushi Sugyo + Fixes for ASN.1 decoder for 2.100.3 forms. + Added a count of packets received and processed to clarify numbers. + Incorporated WinDUMP patches for Win32 builds. + PPPoE payload length headers. + Fixes for HP C compiler builds. + Use new pcap_breakloop() and pcap_findalldevs() if we can. + BGP output split into multiple lines. + Fixes to 802.11 decoding. + Fixes to PIM decoder. + SuperH is a CPU that can't handle unaligned access. Many fixes for + unaligned access work. + Fixes to Frame-Relay decoder for Q.933/922 frames. + Clarified when Solaris can do captures as non-root. + Added tests/ subdir for examples/regression tests. + New -U flag. -flush stdout after every packet + New -A flag -print ascii only + support for decoding IS-IS inside Cisco HDLC Frames + more verbosity for tftp decoder + mDNS decoder + new BFD decoder + cross compilation patches + RFC 3561 AODV support. + UDP/TCP pseudo-checksum properly for source-route options. + sanitized all files to modified BSD license + Add support for RFC 2625 IP-over-Fibre Channel. + fixes for DECnet support. + Support RFC 2684 bridging of Ethernet, 802.5 Token Ring, and FDDI. + RFC 2684 encapsulation of BPDUs. + +Tuesday, February 25, 2003. fenner@research.att.com. 3.7.2 release + + Fixed infinite loop when parsing malformed isakmp packets. + (reported by iDefense; already fixed in CVS) + Fixed infinite loop when parsing malformed BGP packets. + Fixed buffer overflow with certain malformed NFS packets. + Pretty-print unprintable network names in 802.11 printer. + Handle truncated nbp (appletalk) packets. + Updated DHCPv6 printer to match draft-ietf-dhc-dhcpv6-22.txt + Print IP protocol name even if we don't have a printer for it. + Print IP protocol name or number for fragments. + Print the whole MPLS label stack, not just the top label. + Print request header and file handle for NFS v3 FSINFO and PATHCONF + requests. + Fix NFS packet truncation checks. + Handle "old" DR-Priority and Bidir-Capable PIM HELLO options. + Handle unknown RADIUS attributes properly. + Fix an ASN.1 parsing error that would cause e.g. the OID + 2.100.3 to be misrepresented as 4.20.3 . + +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 + SMB printing has much improved bounds checks + OUI 0x0000f8 decoded as encapsulated ethernet for Cisco-custom bridging + Zephyr support, from Nickolai Zeldovich . + Solaris - devices with digits in them. Stefan Hudson + IPX socket 0x85be is for Cisco EIGRP over IPX. + Improvements to fragmented ESP handling. + SCTP support from Armando L. Caro Jr. + 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 . + 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 . + now we are -Wstrict-prototype clean. + NetBSD DLT_PPP_ETHER; adapted from Martin Husemann . + PPPoE dissector cleaned up. + Support for LocalTalk hardware, from Uns Lider . + 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 + ARCNet support, from NetBSD. + HSRP dissector, from Julian Cowley . + 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 . + PPTP support, from Motonori Shindo . + IS-IS over PPP support, from Hannes Gredler . + CNFP support for IPv6,format. Harry Raaymakers . + 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. + Promisc mode fixes for Linux + IPsec changes/cleanups. + Alignment fixes for picky architectures + + Removed dependency on native headers for packet dissectors. + Removed Linux specific headers that were shipped + + libpcap changes provide for exchanging capture files between + systems. Save files now have well known PACKET_ values instead of + depending upon system dependant mappings of DLT_* types. + + Support for computing/checking IP and UDP/TCP checksums. + + Updated autoconf stock files. + + IPv6 improvements: dhcp (draft-15), mobile-ip6, ppp, ospf6, + + Added dissector support for: ISOCLNS, Token Ring, IGMPv3, bxxp, + timed, vrrp, radius, chdlc, cnfp, cdp, IEEE802.1d, raw-AppleTalk + + Added filtering support for: VLANs, ESIS, ISIS + + Improvements to: print-telnet, IPTalk, bootp/dhcp, ECN, PPP, + L2TP, PPPoE + + HP-UX 11.0 -- find the right dlpi device. + Solaris 8 - IPv6 works + Linux - Added support for an "any" device to capture on all interfaces + + Security fixes: buffer overrun audit done. Strcpy replaced with + strlcpy, sprintf replaced with snprintf. + Look for lex problems, and warn about them. + + +v3.5 Fri Jan 28 18:00:00 PST 2000 + +Bill Fenner +- switch to config.h for autoconf +- unify RCSID strings +- Updated PIMv1, PIMv2, DVMRP, IGMP parsers, add Cisco Auto-RP parser +- Really fix the RIP printer +- Fix MAC address -> name translation. +- some -Wall -Wformat fixes +- update makemib to parse much of SMIv2 +- Print TCP sequence # with -vv even if you normally wouldn't +- Print as much of IP/TCP/UDP headers as possible even if truncated. + +itojun@iijlab.net +- -X will make a ascii dump. from netbsd. +- telnet command sequence decoder (ff xx xx). from netbsd. +- print-bgp.c: improve options printing. ugly code exists for + unaligned option parsing (need some fix). +- const poisoning in SMB decoder. +- -Wall -Werror clean checks. +- bring in KAME IPv6/IPsec decoding code. + +Assar Westerlund +- SNMPv2 and SNMPv3 printer +- If compiled with libsmi, tcpdump can load MIBs on the fly to decode + SNMP packets. +- Incorporate NFS parsing code from NetBSD. Adds support for nfsv3. +- portability fixes +- permit building in different directories. + +Ken Hornstein +- bring in code at + /afs/transarc.com/public/afs-contrib/tools/tcpdump for parsing + AFS3 packets + +Andrew Tridgell +- SMB printing code + +Love +- print-rx.c: add code for printing MakeDir and StoreStatus. Also + change date format to the right one. + +Michael C. Richardson +- Created tcpdump.org repository v3.4 Sat Jul 25 12:40:55 PDT 1998 diff --git a/kame/kame/tcpdump/CREDITS b/kame/kame/tcpdump/CREDITS new file mode 100644 index 0000000000..b5c286c2b6 --- /dev/null +++ b/kame/kame/tcpdump/CREDITS @@ -0,0 +1,120 @@ +This file lists people who have contributed to tcpdump: + +The current maintainers: + Bill Fenner + Fulvio Risso + Guy Harris + Hannes Gredler + Jun-ichiro itojun Hagino + Michael Richardson + +Additional people who have contributed patches: + + Andrew Brown + Alfredo Andres + Andrew Hintz + Andrew Tridgell + Arkadiusz Miskiewicz + Armando L. Caro Jr. + Atsushi Onoe + Ben Smithurst + Brent L. Bates + Brian Ginsbach + Bruce M. Simpson + Carles Kishimoto Bisbe + Charlie Lenahan + Charles M. Hannum + Chris Cogdon + Chris G. Demetriou + Chris Jepeway + Craig Rodrigues + Crist J. Clark + Daniel Hagerty + Darren Reed + David Binderman + David Young + Francisco Matias Cuenca-Acuna + Frank Volf + Fulvio Risso + George Bakos + Gerald Combs + Gert Doering + Greg Stark + Gilbert Ramirez Jr. + Gisle Vanem + Hank Leininger + Harry Raaymakers + Heinz-Ado Arnolds + Hendrik Scholz + Jakob Schlyter + Jan Oravec + Jason R. Thorpe + Jefferson Ogata + Jeffrey Hutzelman + Jesper Peterson + Jim Hutchins + Jonathan Heusser + Tatuya Jinmei + Jørgen Thomsen + Julian Cowley + Kaarthik Sivakumar + Kazushi Sugyo + Kelly Carmichael + Ken Hornstein + Kevin Steves + Klaus Klein + Kris Kennaway + Krzysztof Halasa + Larry Lile + Lennert Buytenhek + Loris Degioanni + Love Hörnquist-Åstrand + Maciej W. Rozycki + Marc A. Lehmann + Mark Ellzey Thomas + Marko Kiiskila + Marshall Rose + Martin Husemann + Michael Madore + Michael Shalayeff + Michael T. Stolarchuk + Michele "mydecay" Marchetto + Monroe Williams + Motonori Shindo + Nathan J. Williams + Nathaniel Couper-Noles + Neil T. Spring + Niels Provos + Nickolai Zeldovich + Olaf Kirch + Onno van der Linden + Pascal Hennequin + Pasvorn Boonmark + Paul Mundt + Paul S. Traina + Pavlin Radoslavov + Pekka Savola + Peter Fales + Peter Jeremy + Phil Wood + Rafal Maszkowski + Rick Jones + Rick Watson + Rob Braun + Roderick Schertler + Sami Farin + Scott Rose + Sebastian Krahmer + Seth Webster + Takashi Yamamoto + Terry Kennedy + Timo Koskiahde + Tony Li + Uns Lider + Wilbert de Graaf + Yen Yen Lim + +The original LBL crew: + Steve McCanne + Craig Leres + Van Jacobson diff --git a/kame/kame/tcpdump/FILES b/kame/kame/tcpdump/FILES index 47ffa71c7b..0b868170cc 100644 --- a/kame/kame/tcpdump/FILES +++ b/kame/kame/tcpdump/FILES @@ -1,103 +1,218 @@ CHANGES +CREDITS FILES INSTALL +LICENSE Makefile.in README +Readme.Win32 VERSION +acconfig.h aclocal.m4 addrtoname.c addrtoname.h +ah.h +aodv.h appletalk.h +arcnet.h atime.awk +atm.h +atmuni31.h bootp.h bpf_dump.c +chdlc.h config.guess +config.h.in config.sub configure configure.in decnet.h +enc.h +esp.h +ether.h ethertype.h extract.h fddi.h +gmpls.c +gmpls.h gmt2local.c gmt2local.h +icmp6.h +ieee802_11.h igrp.h install-sh interface.h +ip.h +ip6.h +ipfc.h +ipproto.h +ipsec_doi.h ipx.h -lbl/gnuc.h +isakmp.h +l2tp.h +lane.h +lbl/os-osf4.h lbl/os-solaris2.h lbl/os-sunos4.h lbl/os-ultrix4.h -linux-include/net/slcompress.h -linux-include/net/slip.h -linux-include/netinet/if_ether.h -linux-include/netinet/in_systm.h -linux-include/netinet/ip.h -linux-include/netinet/ip_icmp.h -linux-include/netinet/ip_var.h -linux-include/netinet/tcp.h -linux-include/netinet/tcp_var.h -linux-include/netinet/tcpip.h -linux-include/netinet/udp.h -linux-include/netinet/udp_var.h -linux-include/sys/mbuf.h llc.h machdep.c machdep.h makemib mib.h +missing/addrinfo.h +missing/addrsize.h +missing/bittypes.h +missing/dlnames.c +missing/datalinks.c +missing/getaddrinfo.c +missing/getnameinfo.c +missing/inet_aton.c +missing/inet_ntop.c +missing/inet_pton.c +missing/resolv6.h +missing/resolv_ext.h +missing/snprintf.c +missing/sockstorage.h +missing/strdup.c +missing/strlcat.c +missing/strlcpy.c +missing/strsep.c mkdep +nameser.h netbios.h +nfs.h nfsfh.h -nfsv2.h ntp.h +oakley.h ospf.h +ospf6.h packetdat.awk parsenfsfh.c +pcap-missing.h ppp.h +print-802_11.c +print-ap1394.c +print-ah.c +print-aodv.c +print-arcnet.c print-arp.c +print-ascii.c print-atalk.c print-atm.c +print-beep.c +print-bfd.c +print-bgp.c print-bootp.c +print-cdp.c +print-chdlc.c +print-cip.c +print-cnfp.c print-decnet.c +print-dhcp6.c print-domain.c print-dvmrp.c print-egp.c +print-enc.c +print-esp.c print-ether.c print-fddi.c +print-fr.c +print-frag6.c print-gre.c +print-hsrp.c print-icmp.c +print-icmp6.c +print-igmp.c print-igrp.c print-ip.c +print-ip6.c +print-ip6opts.c +print-ipcomp.c +print-ipfc.c print-ipx.c +print-isakmp.c print-isoclns.c print-krb.c +print-l2tp.c +print-lane.c +print-ldp.c print-llc.c +print-lwres.c +print-mobile.c +print-mobility.c +print-mpls.c +print-msdp.c print-netbios.c print-nfs.c print-ntp.c print-null.c print-ospf.c +print-ospf6.c +print-pflog.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-rsvp.c +print-rt6.c +print-rx.c +print-sctp.c print-sl.c +print-sll.c +print-smb.c print-snmp.c +print-stp.c +print-sunatm.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 -savestr.c -savestr.h +print-zephyr.c +route6d.h +rx.h +sctpConstants.h +sctpHeader.h send-ack.awk setsignal.c setsignal.h +slcompress.h +slip.h +sll.h +smb.h +smbutil.c stime.awk strcasecmp.c +tcp.h tcpdump.1 tcpdump.c +tcpdump-stdinc.h +telnet.h +timed.h +token.h +udp.h util.c vfprintf.c +win32/Include/Arpa/tftp.h +win32/Include/errno.h +win32/Include/getopt.h +win32/Include/inetprivate.h +win32/Include/telnet.h +win32/Include/w32_fzs.h +win32/Include/Netinet/in_systm.h +win32/Include/Netinet/ip.h +win32/Include/Rpc/rpc.h +win32/Src/getopt.c +win32/prj/GNUmakefile +win32/prj/WinDump.dsp +win32/prj/WinDump.dsw diff --git a/kame/kame/tcpdump/INSTALL b/kame/kame/tcpdump/INSTALL index edb4b1be6b..359397388d 100644 --- a/kame/kame/tcpdump/INSTALL +++ b/kame/kame/tcpdump/INSTALL @@ -1,4 +1,4 @@ -@(#) $Header: INSTALL,v 1.36 98/07/12 13:12:26 leres Exp $ (LBL) +@(#) $Header: /tcpdump/master/tcpdump/INSTALL,v 1.56.2.3 2004/03/17 19:47:47 guy Exp $ (LBL) If you have not built libpcap, do so first. See the README file in this directory for the ftp location. @@ -7,140 +7,218 @@ You will need an ANSI C compiler to build tcpdump. The configure script will abort if your compiler is not ANSI compliant. If this happens, use the GNU C compiler, available via anonymous ftp: - ftp://prep.ai.mit.edu/pub/gnu/gcc.tar.gz + ftp://ftp.gnu.org/pub/gnu/gcc/ -After libpcap has been built (either install it with "make install" and -"make install-incl" or make sure both the libpcap and tcpdump source -trees are in the same directory), edit the BINDEST and MANDEST paths in -Makefile.in and run ./configure (a shell script). "configure" will +After libpcap has been built (either install it with "make install" or +make sure both the libpcap and tcpdump source trees are in the same +directory), run ./configure (a shell script). "configure" will determine your system attributes and generate an appropriate Makefile from Makefile.in. Now build tcpdump by running "make". -If everything builds ok, su and type "make install" (and optionally -"make install-man). This will install tcpdump and the manual entry. By -default, tcpdump is installed with group execute permissions. The group -used depends on your os. In addition, BPF packet access is controlled -by permissions to /dev/bpf0. In any case, DO NOT give untrusted users -the capability of running tcpdump. Tcpdump can capture any traffic on -your net, including passwords. +If everything builds ok, su and type "make install". This will install +tcpdump and the manual entry. By default, tcpdump is installed with +group execute permissions. The group used depends on your os. In +addition, BPF packet access is controlled by permissions to +/dev/bpf0. In any case, DO NOT give untrusted users the capability of +running tcpdump. Tcpdump can capture any traffic on your net, +including passwords. -Note that tcpdump is shipped with some systems, for example, DEC/OSF -and BSD/386. Remember to remove or rename the installed binary -when upgrading. +Note that most systems ship tcpdump, but usually an older version. +Remember to remove or rename the installed binary when upgrading. If you use Linux, this version of libpcap is known to compile and run -under Red Hat 4.0 with the 2.0.25 kernel. It may work with earlier 2.X -versions but is guaranteed not to work with 1.X kernels. - -If you use OSF 4, note that that there appears to be some serious bugs -with the stock C compiler. The configure code fragments that detect if -the ether_header and ether_arp structs use the ether_addr struct -generates warnings instead of fatal errors (?!?!) This makes configure -think that the ether_arp struct is used when in fact it is not. To get -around this, delete: - - -DETHER_HEADER_HAS_EA=1 -DETHER_ARP_HAS_EA=1 - -from the Makefile after running configure (and before attempting to -compile tcpdump. - -Another workaround is to use gcc. +with 2.0.25 and more modern, and 2.2 and later, kernels. It is +guaranteed not to work with 1.X kernels. If your system is not one which we have tested tcpdump on, you may have to modify the configure script and Makefile.in. Please send us patches -for any modifications you need to make. However, we are not interested -in ascii packet printer patches. We believe adding this feature would -make it too easy for crackers who do not have the programming skills -needed to write a password sniffer to grab clear text passwords. +for any modifications you need to make. + +Please see "PLATFORMS" for notes about tested platforms. + FILES ----- -CHANGES - description of differences between releases +CHANGES - description of differences between releases +CREDITS - people that have helped tcpdump along FILES - list of files exported as part of the distribution -INSTALL - this file +INSTALL - this file +LICENSE - the license under which tcpdump is distributed Makefile.in - compilation rules (input to the configure script) README - description of distribution +Readme.Win32 - notes on building tcpdump on Win32 systems (with WinPcap) VERSION - version of this release +acconfig.h - autoconf input aclocal.m4 - autoconf macros addrtoname.c - address to hostname routines addrtoname.h - address to hostname definitions +ah.h - IPSEC Authentication Header definitions +aodv.h - AODV definitions appletalk.h - AppleTalk definitions +arcnet.h - ARCNET definitions atime.awk - TCP ack awk script -bcopy.c - missing routine +atm.h - ATM traffic type definitions +atmuni31.h - ATM Q.2931 definitions bootp.h - BOOTP definitions -bpf_dump.c - bpf instruction pretty-printer routine +bpf_dump.c - BPF program printing routines, in case libpcap doesn't + have them +chdlc.h - Cisco HDLC definitions config.guess - autoconf support +config.h.in - autoconf input config.sub - autoconf support configure - configure script (run this first) configure.in - configure script source decnet.h - DECnet definitions -ethertype.h - ethernet definitions +enc.h - OpenBSD IPsec encapsulation BPF layer definitions +esp.h - IPSEC Encapsulating Security Payload definitions +ether.h - Ethernet definitions +ethertype.h - Ethernet type value definitions extract.h - alignment definitions fddi.h - Fiber Distributed Data Interface definitions +gmpls.c - GMPLS definitions +gmpls.h - GMPLS declarations gmt2local.c - time conversion routines gmt2local.h - time conversion prototypes +icmp6.h - ICMPv6 definitiions +ieee802_11.h - IEEE 802.11 definitions igrp.h - Interior Gateway Routing Protocol definitions install-sh - BSD style install script interface.h - globals, prototypes and definitions +ip.h - IP definitions +ip6.h - IPv6 definitions +ipfc.h - IP-over-Fibre Channel definitions +ipproto.h - IP protocol type value definitions +ipsec_doi.h - ISAKMP packet definitions - RFC2407 ipx.h - IPX definitions -lbl/gnuc.h - gcc macros and defines -lbl/os-*.h - os dependent defines and prototypes -linux-include/* - network include files missing on Linux +isakmp.h - ISAKMP packet definitions - RFC2408 +l2tp.h - Layer Two Tunneling Protocol definitions +lane.h - ATM LANE definitions +lbl/os-*.h - OS-dependent defines and prototypes llc.h - LLC definitions machdep.c - machine dependent routines machdep.h - machine dependent definitions makemib - mib to header script mib.h - mib definitions +missing/* - replacements for missing library functions mkdep - construct Makefile dependency list +nameser.h - DNS definitions netbios.h - NETBIOS definitions +nfs.h - Network File System V2 definitions nfsfh.h - Network File System file handle definitions -nfsv2.h - Network File System V2 definitions ntp.h - Network Time Protocol definitions +oakley.h - ISAKMP packet definitions - RFC2409 ospf.h - Open Shortest Path First definitions +ospf6.h - IPv6 Open Shortest Path First definitions packetdat.awk - TCP chunk summary awk script parsenfsfh.c - Network File System file parser routines +pcap-missing.h - declarations of functions possibly missing from libpcap ppp.h - Point to Point Protocol definitions +print-802_11.c - IEEE 802.11 printer routines +print-ap1394.c - Apple IP-over-IEEE 1394 printer routines +print-ah.c - IPSEC Authentication Header printer routines +print-aodv.c - AODV printer routines +print-arcnet.c - ARCNET printer routines print-arp.c - Address Resolution Protocol printer routines +print-ascii.c - ASCII packet dump routines print-atalk.c - AppleTalk printer routines -print-atm.c - atm printer routines -print-bootp.c - BOOTP printer routines +print-atm.c - ATM printer routines +print-bgp.c - Border Gateway Protocol printer routines +print-bootp.c - BOOTP and IPv4 DHCP printer routines +print-beep.c - BEEP printer routines +print-cdp.c - Cisco Discovery Protocol printer routines +print-chdlc.c - Cisco HDLC printer routines +print-cip.c - Classical-IP over ATM routines +print-cnfp.c - Cisco NetFlow printer routines print-decnet.c - DECnet printer routines +print-dhcp6.c - IPv6 DHCP printer routines print-domain.c - Domain Name System printer routines +print-dvmrp.c - Distance Vector Multicast Routing Protocol printer routines +print-enc.c - OpenBSD IPsec encapsulation BPF layer printer routines print-egp.c - External Gateway Protocol printer routines -print-ether.c - ethernet printer routines +print-esp.c - IPSEC Encapsulating Security Payload printer routines +print-ether.c - Ethernet printer routines print-fddi.c - Fiber Distributed Data Interface printer routines +print-fr.c - Frame Relay printer routines +print-frag6.c - IPv6 fragmentation header printer routines print-gre.c - Generic Routing Encapsulation printer routines +print-hsrp.c - Cisco Hot Standby Router Protocol printer routines print-icmp.c - Internet Control Message Protocol printer routines +print-icmp6.c - IPv6 Internet Control Message Protocol printer routines +print-igmp.c - Internet Group Management Protocol printer routines print-igrp.c - Interior Gateway Routing Protocol printer routines -print-ip.c - ip printer routines +print-ip.c - IP printer routines +print-ip6.c - IPv6 printer routines +print-ip6opts.c - IPv6 header option printer routines +print-ipcomp.c - IP Payload Compression Protocol printer routines print-ipx.c - IPX printer routines -print-isoclns.c - isoclns printer routines +print-isakmp.c - Internet Security Association and Key Management Protocol +print-isoclns.c - ISO CLNS, ESIS, and ISIS printer routines print-krb.c - Kerberos printer routines -print-llc.c - llc printer routines -print-netbios.c - netbios printer routines +print-l2tp.c - Layer Two Tunneling Protocol printer routines +print-lane.c - ATM LANE printer routines +print-llc.c - IEEE 802.2 LLC printer routines +print-lwres.c - Lightweight Resolver protocol printer routines +print-mobile.c - IPv4 mobility printer routines +print-mobility.c - IPv6 mobility printer routines +print-mpls.c - Multi-Protocol Label Switching printer routines +print-msdp.c - Multicast Source Discovery Protocol printer routines +print-netbios.c - NetBIOS frame protocol printer routines print-nfs.c - Network File System printer routines print-ntp.c - Network Time Protocol printer routines -print-null.c - null printer routines +print-null.c - BSD loopback device printer routines print-ospf.c - Open Shortest Path First printer routines +print-ospf6.c - IPv6 Open Shortest Path First printer routines +print-pflog.c - OpenBSD packet filter log file printer routines print-pim.c - Protocol Independent Multicast printer routines print-ppp.c - Point to Point Protocol printer routines -print-raw.c - raw printer routines +print-pppoe.c - PPP-over-Ethernet printer routines +print-pptp.c - Point-to-Point Tunnelling Protocol printer routines +print-radius.c - Radius protocol printer routines +print-raw.c - Raw IP printer routines print-rip.c - Routing Information Protocol printer routines +print-ripng.c - IPv6 Routing Information Protocol printer routines +print-rsvp.c - Resource reSerVation Protocol (RSVP) printer routines +print-rt6.c - IPv6 routing header printer routines +print-rx.c - AFS RX printer routines +print-sctp.c - Stream Control Transmission Protocol printer routines print-sl.c - Compressed Serial Line Internet Protocol printer routines +print-sll.c - Linux "cooked" capture printer routines +print-smb.c - SMB/CIFS printer routines print-snmp.c - Simple Network Management Protocol printer routines +print-stp.c - IEEE 802.1d spanning tree protocol printer routines +print-sunatm.c - SunATM DLPI capture printer routines print-sunrpc.c - Sun Remote Procedure Call printer routines print-tcp.c - TCP printer routines +print-telnet.c - Telnet option printer routines print-tftp.c - Trivial File Transfer Protocol printer routines +print-timed.c - BSD time daemon protocol printer routines +print-token.c - Token Ring printer routines print-udp.c - UDP printer routines -print-wb.c - white board printer routines -savestr.c - savestr prototypes -savestr.h - strdup() replacement +print-vjc.c - PPP Van Jacobson compression (RFC1144) printer routines +print-vrrp.c - Virtual Router Redundancy Protocol +print-wb.c - White Board printer routines +print-zephyr.c - Zephyr printer routines +route6d.h - packet definition for IPv6 Routing Information Protocol +rx.h - AFS RX definitions +sctpConstants.h - Stream Control Transmission Protocol constant definitions +sctpHeader.h - Stream Control Transmission Protocol packet definitions send-ack.awk - unidirectional tcp send/ack awk script -setsignal.c - os independent signal routines -setsignal.h - os independent signal prototypes +setsignal.c - OS-independent signal routines +setsignal.h - OS-independent signal prototypes +slcompress.h - SLIP/PPP Van Jacobson compression (RFC1144) definitions +slip.h - SLIP definitions +sll.h - Linux "cooked" capture definitions +smb.h - SMB/CIFS definitions +smbutil.c - SMB/CIFS utility routines stime.awk - TCP send awk script strcasecmp.c - missing routine +tcp.h - TCP definitions tcpdump.1 - manual entry tcpdump.c - main program +telnet.h - Telnet definitions +timed.h - BSD time daemon protocol definitions +token.h - Token Ring definitions +udp.h - UDP definitions util.c - utility routines vfprintf.c - emulation routine +win32 - headers and routines for building on Win32 systems diff --git a/kame/kame/tcpdump/LICENSE b/kame/kame/tcpdump/LICENSE new file mode 100644 index 0000000000..dea5f7d54d --- /dev/null +++ b/kame/kame/tcpdump/LICENSE @@ -0,0 +1,19 @@ +License: BSD + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + 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. diff --git a/kame/kame/tcpdump/Makefile-devel-adds b/kame/kame/tcpdump/Makefile-devel-adds new file mode 100644 index 0000000000..512a119979 --- /dev/null +++ b/kame/kame/tcpdump/Makefile-devel-adds @@ -0,0 +1,22 @@ +# +# Auto-regenerate configure script or Makefile when things change. +# From autoconf.info . Works best with GNU Make. +# +${srcdir}/configure: configure.in + cd ${srcdir} && autoconf + +# autoheader might not change config.h.in, so touch a stamp file. +${srcdir}/config.h.in: ${srcdir}/stamp-h.in +${srcdir}/stamp-h.in: configure.in acconfig.h + cd ${srcdir} && autoheader + echo timestamp > ${srcdir}/stamp-h.in + +config.h: stamp-h +stamp-h: ${srcdir}/config.h.in config.status + ./config.status + +Makefile: Makefile.in config.status + ./config.status + +config.status: ${srcdir}/configure + ./config.status --recheck diff --git a/kame/kame/tcpdump/Makefile.in b/kame/kame/tcpdump/Makefile.in index 77622779e1..38fe8742bc 100644 --- a/kame/kame/tcpdump/Makefile.in +++ b/kame/kame/tcpdump/Makefile.in @@ -17,7 +17,7 @@ # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. # -# @(#) $Header: Makefile.in,v 1.207 97/08/17 13:53:29 leres Exp $ (LBL) +# @(#) $Header: /tcpdump/master/tcpdump/Makefile.in,v 1.276.2.4 2004/03/28 21:25:02 fenner Exp $ (LBL) # # Various configurable paths (remember to edit Makefile.in, not Makefile) @@ -27,9 +27,9 @@ prefix = @prefix@ exec_prefix = @exec_prefix@ # Pathname of directory to install the binary -BINDEST = @sbindir@ +sbindir = @sbindir@ # Pathname of directory to install the man page -MANDEST = @mandir@ +mandir = @mandir@ # VPATH srcdir = @srcdir@ @@ -43,7 +43,7 @@ CC = @CC@ PROG = tcpdump CCOPT = @V_CCOPT@ INCLS = -I. @V_INCLS@ -DEFS = @DEFS@ -DHAVE_FDDI +DEFS = @DEFS@ @V_DEFS@ # Standard CFLAGS CFLAGS = $(CCOPT) $(DEFS) $(INCLS) @@ -55,6 +55,8 @@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_DATA = @INSTALL_DATA@ # Explicitly define compilation rule since SunOS 4's make doesn't like gcc. # Also, gcc does not remove the .o before forking 'as', which can be a @@ -63,32 +65,42 @@ INSTALL = @INSTALL@ @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-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-sunrpc.c print-tcp.c print-tftp.c print-udp.c \ - print-wb.c addrtoname.c bpf_dump.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 +CSRC = addrtoname.c gmpls.c gmt2local.c machdep.c oui.c parsenfsfh.c \ + print-802_11.c print-ap1394.c print-ah.c print-arcnet.c \ + print-aodv.c print-arp.c print-ascii.c print-atalk.c print-atm.c \ + print-beep.c print-bfd.c print-bgp.c print-bootp.c print-cdp.c \ + print-chdlc.c print-cip.c print-cnfp.c print-decnet.c \ + print-domain.c print-dvmrp.c print-enc.c print-egp.c \ + print-esp.c print-ether.c print-fddi.c print-fr.c \ + print-gre.c print-hsrp.c print-icmp.c print-igmp.c \ + print-igrp.c print-ip.c print-ipcomp.c print-ipfc.c \ + print-ipx.c print-isakmp.c print-isoclns.c print-krb.c \ + print-l2tp.c print-lane.c print-ldp.c print-llc.c \ + print-lwres.c print-mobile.c print-mpls.c print-msdp.c \ + print-nfs.c print-ntp.c print-null.c print-ospf.c \ + print-pflog.c print-pim.c print-ppp.c print-pppoe.c \ + print-pptp.c print-radius.c print-raw.c print-rip.c \ + print-rsvp.c print-rx.c print-sctp.c print-sl.c print-sll.c \ + print-snmp.c print-stp.c print-sunatm.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 +LIBOBJS = @LIBOBJS@ SRC = $(CSRC) $(GENSRC) $(LOCALSRC) # We would like to say "OBJ = $(SRC:.c=.o)" but Ultrix's make cannot # hack the extra indirection -OBJ = $(CSRC:.c=.o) $(GENSRC:.c=.o) $(LOCALSRC:.c=.o) @LIBOBJS@ +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 \ - gnuc.h ipsec_doi.h isakmp.h l2tp.h netbios.h oakley.h ospf6.h ppp.h \ - route6d.h + setsignal.h \ + gnuc.h ipsec_doi.h isakmp.h l2tp.h nameser.h \ + netbios.h oakley.h ospf6.h pf.h ppp.h route6d.h TAGHDR = \ /usr/include/arpa/tftp.h \ @@ -111,20 +123,49 @@ $(PROG): $(OBJ) @V_PCAPDEP@ @rm -f $@ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) +datalinks.o: $(srcdir)/missing/datalinks.c + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/datalinks.c +dlnames.o: $(srcdir)/missing/dlnames.c + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/dlnames.c +getnameinfo.o: $(srcdir)/missing/getnameinfo.c + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/getnameinfo.c +getaddrinfo.o: $(srcdir)/missing/getaddrinfo.c + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/getaddrinfo.c +inet_pton.o: $(srcdir)/missing/inet_pton.c + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/inet_pton.c +inet_ntop.o: $(srcdir)/missing/inet_ntop.c + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/inet_ntop.c +inet_aton.o: $(srcdir)/missing/inet_aton.c + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/inet_aton.c +snprintf.o: $(srcdir)/missing/snprintf.c + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/snprintf.c +strlcat.o: $(srcdir)/missing/strlcat.c + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/strlcat.c +strlcpy.o: $(srcdir)/missing/strlcpy.c + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/strlcpy.c +strsep.o: $(srcdir)/missing/strsep.c + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/strsep.c + version.o: version.c + $(CC) $(CFLAGS) -c version.c + version.c: $(srcdir)/VERSION @rm -f $@ sed -e 's/.*/char version[] = "&";/' $(srcdir)/VERSION > $@ -install: force - $(INSTALL) -m 550 -o bin -g @V_GROUP@ $(PROG) \ - $(DESTDIR)$(BINDEST)/$(PROG) +install: + [ -d $(DESTDIR)$(sbindir) ] || \ + (mkdir -p $(DESTDIR)$(sbindir); chmod 755 $(DESTDIR)$(sbindir)) + $(INSTALL_PROGRAM) $(PROG) $(DESTDIR)$(sbindir)/$(PROG) + [ -d $(DESTDIR)$(mandir)/man1 ] || \ + (mkdir -p $(DESTDIR)$(mandir)/man1; chmod 755 $(DESTDIR)$(mandir)/man1) + $(INSTALL_DATA) $(srcdir)/$(PROG).1 $(DESTDIR)$(mandir)/man1/$(PROG).1 -install-man: force - $(INSTALL) -m 444 -o bin -g bin $(srcdir)/$(PROG).1 \ - $(DESTDIR)$(MANDEST)/man1/$(PROG).1 +uninstall: + rm -f $(DESTDIR)$(sbindir)/$(PROG) + rm -f $(DESTDIR)$(mandir)/man1/$(PROG).1 -lint: $(GENSRC) force +lint: $(GENSRC) lint -hbxn $(SRC) | \ grep -v 'struct/union .* never defined' | \ grep -v 'possible pointer alignment problem' @@ -134,14 +175,14 @@ clean: distclean: rm -f $(CLEANFILES) Makefile config.cache config.log config.status \ - gnuc.h os-proto.h + config.h gnuc.h os-proto.h stamp-h stamp-h.in tags: $(TAGFILES) ctags -wtd $(TAGFILES) -tar: force +tar: @cwd=`pwd` ; dir=`basename $$cwd` ; name=$(PROG)-`cat VERSION` ; \ - list="" ; tar="tar chFFf" ; \ + list="" ; tar="tar chf" ; \ for i in `cat FILES` ; do list="$$list $$name/$$i" ; done; \ echo \ "rm -f ../$$name; ln -s $$dir ../$$name" ; \ @@ -153,6 +194,5 @@ tar: force "rm -f ../$$name" ; \ rm -f ../$$name -force: /tmp -depend: $(GENSRC) force - ./mkdep -c $(CC) $(DEFS) $(INCLS) $(SRC) +depend: $(GENSRC) + ${srcdir}/mkdep -c $(CC) $(DEFS) $(INCLS) $(SRC) diff --git a/kame/kame/tcpdump/PLATFORMS b/kame/kame/tcpdump/PLATFORMS new file mode 100644 index 0000000000..2e1aedf773 --- /dev/null +++ b/kame/kame/tcpdump/PLATFORMS @@ -0,0 +1,9 @@ +== Tested platforms == +NetBSD 1.5/i386 (mcr - 2002/1/1) +Debian Linux (woody/i386) (mcr - 2002/1/1) + +--- +RedHat Linux 6.1/i386 (assar) +FreeBSD 2.2.8/i386 (itojun) + + diff --git a/kame/kame/tcpdump/README b/kame/kame/tcpdump/README index b607c4face..f1e02670a8 100644 --- a/kame/kame/tcpdump/README +++ b/kame/kame/tcpdump/README @@ -1,20 +1,36 @@ -@(#) $Header: README,v 1.54 98/01/27 21:36:20 vern Exp $ (LBL) +@(#) $Header: /tcpdump/master/tcpdump/README,v 1.63.2.1 2003/11/16 10:17:30 guy Exp $ (LBL) -TCPDUMP 3.4 -Lawrence Berkeley National Laboratory -Network Research Group -tcpdump@ee.lbl.gov -ftp://ftp.ee.lbl.gov/tcpdump.tar.Z +TCPDUMP 3.8 +Now maintained by "The Tcpdump Group" +See www.tcpdump.org + +Please send inquiries/comments/reports to tcpdump-workers@tcpdump.org + +Anonymous CVS is available via: + cvs -d :pserver:cvs.tcpdump.org:/tcpdump/master login + (password "anoncvs") + cvs -d :pserver:cvs.tcpdump.org:/tcpdump/master checkout tcpdump + +Version 3.8 of TCPDUMP can be retrived with the CVS tag "tcpdump_3_8rel1": + cvs -d :pserver:cvs.tcpdump.org:/tcpdump/master checkout -r tcpdump_3_8rel1 tcpdump + +Please send patches against the master copy to patches@tcpdump.org. + +formerly from Lawrence Berkeley National Laboratory + Network Research Group + ftp://ftp.ee.lbl.gov/tcpdump.tar.Z (3.4) This directory contains source code for tcpdump, a tool for network -monitoring and data acquisition. The original distribution is -available via anonymous ftp to ftp.ee.lbl.gov, in tcpdump.tar.Z. +monitoring and data acquisition. This software was originally +developed by the Network Research Group at the Lawrence Berkeley +National Laboratory. The original distribution is available via +anonymous ftp to ftp.ee.lbl.gov, in tcpdump.tar.Z. More recent +development is performed at tcpdump.org, http://www.tcpdump.org/ -Tcpdump now uses libpcap, a system-independent interface for user-level +Tcpdump uses libpcap, a system-independent interface for user-level packet capture. Before building tcpdump, you must first retrieve and -build libpcap, also from LBL, in: - - ftp://ftp.ee.lbl.gov/libpcap.tar.Z +build libpcap, also originally from LBL and now being maintained by +tcpdump.org; see http://www.tcpdump.org/ . Once libpcap is built (either install it or make sure it's in ../libpcap), you can build tcpdump using the procedure in the INSTALL @@ -50,13 +66,24 @@ It is a program that can be used to extract portions of tcpdump binary trace files. See the above distribution for further details and documentation. -Problems, bugs, questions, desirable enhancements, source code -contributions, etc., should be sent to the email address -"tcpdump@ee.lbl.gov". +Problems, bugs, questions, desirable enhancements, etc. should be sent +to the address "tcpdump-workers@tcpdump.org". Bugs, support requests, +and feature requests may also be submitted on the SourceForge site for +tcpdump at + + http://sourceforge.net/projects/tcpdump/ + +Source code contributions, etc. should be sent to the email address +"patches@tcpdump.org", or submitted as patches on the SourceForge site +for tcpdump. + +Current versions can be found at www.tcpdump.org, or the SourceForge +site for tcpdump. + + - The TCPdump team + +original text by: Steve McCanne, Craig Leres, Van Jacobson - - Steve McCanne - Craig Leres - Van Jacobson ------------------------------------- This directory also contains some short awk programs intended as examples of ways to reduce tcpdump data when you're tracking @@ -205,4 +232,3 @@ The method was: - Once a week, tell your funding agent that you're discovering wonderful things and you'll write up that research report "real soon now". - diff --git a/kame/kame/tcpdump/Readme.Win32 b/kame/kame/tcpdump/Readme.Win32 new file mode 100644 index 0000000000..fdf8b12bc7 --- /dev/null +++ b/kame/kame/tcpdump/Readme.Win32 @@ -0,0 +1,24 @@ +To build tcpdump under Windows, you need: + +- version 6 (or higher) of Microsoft Visual Studio or the Cygnus gnu +C compiler. +- The November 2001 (or later) edition of Microsoft Platform +Software Development Kit (SDK), that contains some necessary includes +for IPv6 support. You can download it from http://www.microsoft.com/sdk +- the WinPcap source code, that includes libpcap for win32. Download it +from http://winpcap.polito.it or download libpcap sources from +http://www.tcpdump.org and follow the instructions in the README.Win32 +file. + +First, extract tcpdump and WinPcap in the same folder, and build WinPcap. + +The Visual Studio project and the cygwin makefile are in the Win32\prj +folder. + +From Visual Studio, open windump.dsw and build the program. The release +version of the WinDump.exe executable file will be created in the +windump\win32\prj\release directory . The debug version will be generated +in windump\win32\prj\debug. + +From cygnus, go to windump\win32\prj\ and type "make". WinDump.exe will be +created in the same directory. \ No newline at end of file diff --git a/kame/kame/tcpdump/TODO b/kame/kame/tcpdump/TODO new file mode 100644 index 0000000000..12c8b3f519 --- /dev/null +++ b/kame/kame/tcpdump/TODO @@ -0,0 +1,6 @@ +1. update credits +2. review "FILES" +3. search for version info +4. get PLATFORMS filled in +5. update CHANGES file +6. do same for libpcap diff --git a/kame/kame/tcpdump/VERSION b/kame/kame/tcpdump/VERSION index 2f4b60750d..269aa9c86d 100644 --- a/kame/kame/tcpdump/VERSION +++ b/kame/kame/tcpdump/VERSION @@ -1 +1 @@ -3.4 +3.8.3 diff --git a/kame/kame/tcpdump/acconfig.h b/kame/kame/tcpdump/acconfig.h new file mode 100644 index 0000000000..09e8351566 --- /dev/null +++ b/kame/kame/tcpdump/acconfig.h @@ -0,0 +1,128 @@ +/* "generated automatically" means DO NOT MAKE CHANGES TO config.h.in -- + * make them to acconfig.h and rerun autoheader */ +@TOP@ + +/* Define if you have SSLeay 0.9.0b with the buggy cast128. */ +#undef HAVE_BUGGY_CAST128 + +/* Define if you enable IPv6 support */ +#undef INET6 + +/* Define if you enable support for the libsmi. */ +#undef LIBSMI + +/* Define if you have the header file. */ +#undef HAVE_SMI_H + +/* define if you have struct __res_state_ext */ +#undef HAVE_RES_STATE_EXT + +/* define if your struct __res_state has the nsort member */ +#undef HAVE_NEW_RES_STATE + + +/* + * define if struct ether_header.ether_dhost is a struct with ether_addr_octet + */ +#undef ETHER_HEADER_HAS_EA + +/* define if struct ether_arp contains arp_xsha */ +#undef ETHER_ARP_HAS_X + +/* define if you have the addrinfo function. */ +#undef HAVE_ADDRINFO + +/* define if you need to include missing/addrinfoh.h. */ +#undef NEED_ADDRINFO_H + +/* define ifyou have the h_errno variable. */ +#undef HAVE_H_ERRNO + +/* define if IN6ADDRSZ is defined (XXX not used!) */ +#undef HAVE_IN6ADDRSZ + +/* define if INADDRSZ is defined (XXX not used!) */ +#undef HAVE_INADDRSZ + +/* define if this is a development version, to use additional prototypes. */ +#undef HAVE_OS_PROTO_H + +/* define if defines __P() */ +#undef HAVE_PORTABLE_PROTOTYPE + +/* define if RES_USE_INET6 is defined */ +#undef HAVE_RES_USE_INET6 + +/* define if struct sockaddr has the sa_len member */ +#undef HAVE_SOCKADDR_SA_LEN + +/* 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 libpcap has pcap_version */ +#undef HAVE_PCAP_VERSION + +/* define if libpcap has pcap_debug */ +#undef HAVE_PCAP_DEBUG + +/* define if libpcap has yydebug */ +#undef HAVE_YYDEBUG + +/* define if libpcap has pcap_list_datalinks() */ +#undef HAVE_PCAP_LIST_DATALINKS + +/* define if libpcap has pcap_set_datalink() */ +#undef HAVE_PCAP_SET_DATALINK + +/* define if libpcap has pcap_datalink_name_to_val() */ +#undef HAVE_PCAP_DATALINK_NAME_TO_VAL + +/* define if libpcap has pcap_datalink_val_to_description() */ +#undef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION + +/* define if unaligned memory accesses fail */ +#undef LBL_ALIGN + +/* The successful return value from signal (?)XXX */ +#undef RETSIGVAL + +/* Define this on IRIX */ +#undef _BSD_SIGNALS + +/* For HP/UX ANSI compiler? */ +#undef _HPUX_SOURCE + +/* AIX hack. */ +#undef _SUN + +/* Workaround for missing sized types */ +/* XXX this should move to the more standard uint*_t */ +#undef int8_t +#undef int16_t +#undef int32_t +#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 + +/* Define if you have the dnet_htoa function. */ +#undef HAVE_DNET_HTOA + +/* Define if you have a dnet_htoa declaration in . */ +#undef HAVE_NETDNET_DNETDB_H_DNET_HTOA diff --git a/kame/kame/tcpdump/aclocal.m4 b/kame/kame/tcpdump/aclocal.m4 index d8227a9960..5db51f3283 100644 --- a/kame/kame/tcpdump/aclocal.m4 +++ b/kame/kame/tcpdump/aclocal.m4 @@ -1,4 +1,4 @@ -dnl @(#) $Header: aclocal.m4,v 1.63 98/06/12 03:44:50 leres Exp $ (LBL) +dnl @(#) $Header: /tcpdump/master/tcpdump/aclocal.m4,v 1.98.2.4 2004/03/28 21:04:49 fenner Exp $ (LBL) dnl dnl Copyright (c) 1995, 1996, 1997, 1998 dnl The Regents of the University of California. All rights reserved. @@ -51,13 +51,13 @@ AC_DEFUN(AC_LBL_C_INIT, $1="-O" $2="" if test "${srcdir}" != "." ; then - $2="-I\$\(srcdir\)" + $2="-I\$(srcdir)" fi if test "${CFLAGS+set}" = set; then 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*) @@ -157,6 +157,51 @@ AC_DEFUN(AC_LBL_C_INIT, fi ]) +# +# Try compiling a sample of the type of code that appears in +# gencode.c with "inline", "__inline__", and "__inline". +# +# Autoconf's AC_C_INLINE, at least in autoconf 2.13, isn't good enough, +# as it just tests whether a function returning "int" can be inlined; +# at least some versions of HP's C compiler can inline that, but can't +# inline a function that returns a struct pointer. +# +AC_DEFUN(AC_LBL_C_INLINE, + [AC_MSG_CHECKING(for inline) + AC_CACHE_VAL(ac_cv_lbl_inline, [ + ac_cv_lbl_inline="" + ac_lbl_cc_inline=no + for ac_lbl_inline in inline __inline__ __inline + do + AC_TRY_COMPILE( + [#define inline $ac_lbl_inline + static inline struct iltest *foo(void); + struct iltest { + int iltest1; + int iltest2; + }; + + static inline struct iltest * + foo() + { + static struct iltest xxx; + + return &xxx; + }],,ac_lbl_cc_inline=yes,) + if test "$ac_lbl_cc_inline" = yes ; then + break; + fi + done + if test "$ac_lbl_cc_inline" = yes ; then + ac_cv_lbl_inline=$ac_lbl_inline + fi]) + if test ! -z "$ac_cv_lbl_inline" ; then + AC_MSG_RESULT($ac_cv_lbl_inline) + else + AC_MSG_RESULT(no) + fi + AC_DEFINE_UNQUOTED(inline, $ac_cv_lbl_inline, [Define as token for inline if inlining supported])]) + dnl dnl Use pfopen.c if available and pfopen() not in standard libraries dnl Require libpcap @@ -191,16 +236,16 @@ AC_DEFUN(AC_LBL_LIBPCAP, AC_MSG_CHECKING(for local pcap library) libpcap=FAIL lastdir=FAIL - places=`ls .. | sed -e 's,/$,,' -e 's,^,../,' | \ - egrep '/libpcap-[[0-9]]*\.[[0-9]]*(\.[[0-9]]*)?([[ab]][[0-9]]*)?$'` - for dir in $places ../libpcap libpcap ; do + places=`ls $srcdir/.. | sed -e 's,/$,,' -e "s,^,$srcdir/../," | \ + egrep '/libpcap-[[0-9]]*.[[0-9]]*(.[[0-9]]*)?([[ab]][[0-9]]*)?$'` + for dir in $places $srcdir/../libpcap $srcdir/libpcap ; do basedir=`echo $dir | sed -e 's/[[ab]][[0-9]]*$//'` if test $lastdir = $basedir ; then dnl skip alphas when an actual release is present continue; fi lastdir=$dir - if test -r $dir/pcap.c ; then + if test -r $dir/libpcap.a ; then libpcap=$dir/libpcap.a d=$dir dnl continue and select the last one that exists @@ -212,13 +257,51 @@ AC_DEFUN(AC_LBL_LIBPCAP, if test $libpcap = FAIL ; then AC_MSG_ERROR(see the INSTALL doc for more info) fi + dnl + dnl Good old Red Hat Linux puts "pcap.h" in + dnl "/usr/include/pcap"; had the LBL folks done so, + dnl that would have been a good idea, but for + dnl the Red Hat folks to do so just breaks source + dnl compatibility with other systems. + dnl + dnl We work around this by assuming that, as we didn't + dnl find a local libpcap, libpcap is in /usr/lib or + dnl /usr/local/lib and that the corresponding header + dnl file is under one of those directories; if we don't + dnl find it in either of those directories, we check to + dnl see if it's in a "pcap" subdirectory of them and, + dnl if so, add that subdirectory to the "-I" list. + dnl + AC_MSG_CHECKING(for extraneous pcap header directories) + if test \( ! -r /usr/local/include/pcap.h \) -a \ + \( ! -r /usr/include/pcap.h \); then + if test -r /usr/local/include/pcap/pcap.h; then + d="/usr/local/include/pcap" + elif test -r /usr/include/pcap/pcap.h; then + d="/usr/include/pcap" + fi + fi + if test -z "$d" ; then + AC_MSG_RESULT(not found) + else + $2="-I$d $$2" + AC_MSG_RESULT(found -- -I$d added) + fi else $1=$libpcap - $2="-I$d $$2" + 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 $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" @@ -227,8 +310,42 @@ AC_DEFUN(AC_LBL_LIBPCAP, AC_MSG_RESULT(yes) LIBS="$LIBS -I:$pseexe" fi + # + # We need "-lodm" and "-lcfg", as libpcap requires them on + # AIX, and we just build a static libpcap.a and thus can't + # arrange that when you link with libpcap you automatically + # link with those libraries. + # + LIBS="$LIBS -lodm -lcfg" ;; - esac]) + esac + + dnl + dnl Check for "pcap_list_datalinks()", "pcap_set_datalink()", + dnl and "pcap_datalink_name_to_val()", and use substitute versions + dnl if they're not present + dnl + AC_CHECK_FUNC(pcap_list_datalinks, + AC_DEFINE(HAVE_PCAP_LIST_DATALINKS), + AC_LIBOBJ(datalinks)) + AC_CHECK_FUNC(pcap_set_datalink, + AC_DEFINE(HAVE_PCAP_SET_DATALINK)) + AC_CHECK_FUNC(pcap_datalink_name_to_val, + [ + AC_DEFINE(HAVE_PCAP_DATALINK_NAME_TO_VAL) + AC_CHECK_FUNC(pcap_datalink_val_to_description, + AC_DEFINE(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION), + AC_LIBOBJ(dlnames)) + ], + AC_LIBOBJ(dlnames)) + + dnl + dnl Check for "pcap_breakloop()"; you can't substitute for it if + dnl it's absent (it has hooks into the live capture routines), + dnl so just define the HAVE_ value if it's there. + dnl + AC_CHECK_FUNCS(pcap_breakloop) +]) dnl dnl Define RETSIGTYPE and RETSIGVAL @@ -250,17 +367,17 @@ 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) ;; *) - dnl prefer sigset() to sigaction() - AC_CHECK_FUNCS(sigset) - if test $ac_cv_func_sigset = no ; then - AC_CHECK_FUNCS(sigaction) + dnl prefer sigaction() to sigset() + AC_CHECK_FUNCS(sigaction) + if test $ac_cv_func_sigaction = no ; then + AC_CHECK_FUNCS(sigset) fi ;; esac]) @@ -483,9 +600,41 @@ 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 - alpha|hp*|mips|sparc) + # + # These are CPU types where: + # + # the CPU faults on an unaligned access, but at least some + # OSes that support that CPU catch the fault and simulate + # the unaligned access (e.g., Alpha/{Digital,Tru64} UNIX) - + # the simulation is slow, so we don't want to use it; + # + # the CPU, I infer (from the old + # + # XXX: should also check that they don't do weird things (like on arm) + # + # comment) doesn't fault on unaligned accesses, but doesn't + # do a normal unaligned fetch, either (e.g., presumably, ARM); + # + # for whatever reason, the test program doesn't work + # (this has been claimed to be the case for several of those + # CPUs - I don't know what the problem is; the problem + # was reported as "the test program dumps core" for SuperH, + # but that's what the test program is *supposed* to do - + # it dumps core before it writes anything, so the test + # for an empty output file should find an empty output + # file and conclude that unaligned accesses don't work). + # + # This run-time test won't work if you're cross-compiling, so + # in order to support cross-compiling for a particular CPU, + # we have to wire in the list of CPU types anyway, as far as + # I know, so perhaps we should just have a set of CPUs on + # which we know it doesn't work, a set of CPUs on which we + # know it does work, and have the script just fail on other + # cpu types and update it when such a failure occurs. + # + alpha*|arm*|hp*|mips*|sh*|sparc*|ia64|nv1) ac_cv_lbl_unaligned_fail=yes ;; @@ -540,7 +689,8 @@ EOF dnl dnl If using gcc and the file .devel exists: dnl Compile with -g (if supported) and -Wall -dnl If using gcc 2, do extra prototype checking +dnl If using gcc 2 or later, do extra prototype checking and some other +dnl checks dnl If an os prototype include exists, symlink os-proto.h to it dnl dnl usage: @@ -566,11 +716,11 @@ AC_DEFUN(AC_LBL_DEVEL, fi $1="$$1 -Wall" if test $ac_cv_lbl_gcc_vers -gt 1 ; then - $1="$$1 -Wmissing-prototypes -Wstrict-prototypes" + $1="$$1 -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -W" fi fi else - case "$target_os" in + case "$host_os" in irix6*) V_CCOPT="$V_CCOPT -n32" @@ -580,7 +730,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 @@ -604,13 +754,19 @@ dnl results: dnl dnl LIBS dnl +dnl XXX - "AC_LBL_LIBRARY_NET" was redone to use "AC_SEARCH_LIBS" +dnl rather than "AC_LBL_CHECK_LIB", so this isn't used any more. +dnl We keep it around for reference purposes in case it's ever +dnl useful in the future. +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" @@ -686,21 +842,365 @@ 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. +dnl +dnl Redistribution and use in source and binary forms, with or without +dnl modification, are permitted provided that the following conditions +dnl are met: +dnl 1. Redistributions of source code must retain the above copyright +dnl notice, this list of conditions and the following disclaimer. +dnl 2. Redistributions in binary form must reproduce the above copyright +dnl notice, this list of conditions and the following disclaimer in the +dnl documentation and/or other materials provided with the distribution. +dnl 3. Neither the name of the project nor the names of its contributors +dnl may be used to endorse or promote products derived from this software +dnl without specific prior written permission. +dnl +dnl THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND +dnl ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +dnl IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +dnl ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE +dnl FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +dnl OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +dnl HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +dnl LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +dnl OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +dnl SUCH DAMAGE. + +dnl +dnl Checks to see if AF_INET6 is defined +AC_DEFUN(AC_CHECK_AF_INET6, [ + AC_MSG_CHECKING(for AF_INET6) + AC_CACHE_VAL($1, + AC_TRY_COMPILE([ +# include +# include ], + [int a = AF_INET6], + $1=yes, + $1=no)) + AC_MSG_RESULT($$1) + if test $$1 = yes ; then + AC_DEFINE(HAVE_AF_INET6) + fi +]) + +dnl +dnl Checks to see if the sockaddr struct has the 4.4 BSD sa_len member +dnl borrowed from LBL libpcap +AC_DEFUN(AC_CHECK_SA_LEN, [ + AC_MSG_CHECKING(if sockaddr struct has sa_len member) + AC_CACHE_VAL($1, + AC_TRY_COMPILE([ +# include +# include ], + [u_int i = sizeof(((struct sockaddr *)0)->sa_len)], + $1=yes, + $1=no)) + AC_MSG_RESULT($$1) + if test $$1 = yes ; then + AC_DEFINE(HAVE_SOCKADDR_SA_LEN) + fi +]) + +dnl +dnl Checks for portable prototype declaration macro +AC_DEFUN(AC_CHECK_PORTABLE_PROTO, [ + AC_MSG_CHECKING(for __P) + AC_CACHE_VAL($1, + AC_TRY_COMPILE([ +# include ], + [int f __P(())], + $1=yes, + $1=no)) + AC_MSG_RESULT($$1) + if test $$1 = yes; then + AC_DEFINE(HAVE_PORTABLE_PROTOTYPE) + fi +]) + +dnl checks for u_intXX_t +AC_DEFUN(AC_CHECK_BITTYPES, [ + $1=yes +dnl check for u_int8_t + AC_MSG_CHECKING(for u_int8_t) + AC_CACHE_VAL(ac_cv_u_int8_t, + AC_TRY_COMPILE([ +# include ], + [u_int8_t i], + ac_cv_u_int8_t=yes, + ac_cv_u_int8_t=no)) + AC_MSG_RESULT($ac_cv_u_int8_t) + if test $ac_cv_u_int8_t = yes; then + AC_DEFINE(HAVE_U_INT8_T) + else + $1=no + fi +dnl check for u_int16_t + AC_MSG_CHECKING(for u_int16_t) + AC_CACHE_VAL(ac_cv_u_int16_t, + AC_TRY_COMPILE([ +# include ], + [u_int16_t i], + ac_cv_u_int16_t=yes, + ac_cv_u_int16_t=no)) + AC_MSG_RESULT($ac_cv_u_int16_t) + if test $ac_cv_u_int16_t = yes; then + AC_DEFINE(HAVE_U_INT16_T) + else + $1=no + fi +dnl check for u_int32_t + AC_MSG_CHECKING(for u_int32_t) + AC_CACHE_VAL(ac_cv_u_int32_t, + AC_TRY_COMPILE([ +# include ], + [u_int32_t i], + ac_cv_u_int32_t=yes, + ac_cv_u_int32_t=no)) + AC_MSG_RESULT($ac_cv_u_int32_t) + if test $ac_cv_u_int32_t = yes; then + AC_DEFINE(HAVE_U_INT32_T) + else + $1=no + fi +]) + +dnl +dnl Checks for addrinfo structure +AC_DEFUN(AC_STRUCT_ADDRINFO, [ + AC_MSG_CHECKING(for addrinfo) + AC_CACHE_VAL($1, + AC_TRY_COMPILE([ +# include ], + [struct addrinfo a], + $1=yes, + $1=no)) + AC_MSG_RESULT($$1) + if test $$1 = yes; then + AC_DEFINE(HAVE_ADDRINFO) + else + AC_DEFINE(NEED_ADDRINFO_H) + fi +]) + +dnl +dnl Checks for NI_MAXSERV +AC_DEFUN(AC_NI_MAXSERV, [ + AC_MSG_CHECKING(for NI_MAXSERV) + AC_CACHE_VAL($1, + AC_EGREP_CPP(yes, [#include +#ifdef NI_MAXSERV +yes +#endif], + $1=yes, + $1=no)) + AC_MSG_RESULT($$1) + if test $$1 != yes; then + AC_DEFINE(NEED_ADDRINFO_H) + fi +]) + +dnl +dnl Checks for NI_NAMEREQD +AC_DEFUN(AC_NI_NAMEREQD, [ + AC_MSG_CHECKING(for NI_NAMEREQD) + AC_CACHE_VAL($1, + AC_EGREP_CPP(yes, [#include +#ifdef NI_NOFQDN +yes +#endif], + $1=yes, + $1=no)) + AC_MSG_RESULT($$1) + if test $$1 != yes; then + AC_DEFINE(NEED_ADDRINFO_H) + fi +]) + +dnl +dnl Checks for sockaddr_storage structure +AC_DEFUN(AC_STRUCT_SA_STORAGE, [ + AC_MSG_CHECKING(for sockaddr_storage) + AC_CACHE_VAL($1, + AC_TRY_COMPILE([ +# include +# include ], + [struct sockaddr_storage s], + $1=yes, + $1=no)) + AC_MSG_RESULT($$1) + if test $$1 = yes; then + AC_DEFINE(HAVE_SOCKADDR_STORAGE) + fi +]) + +dnl +dnl Checks for macro of IP address size +AC_DEFUN(AC_CHECK_ADDRSZ, [ + $1=yes +dnl check for INADDRSZ + AC_MSG_CHECKING(for INADDRSZ) + AC_CACHE_VAL(ac_cv_inaddrsz, + AC_TRY_COMPILE([ +# include ], + [int a = INADDRSZ], + ac_cv_inaddrsz=yes, + ac_cv_inaddrsz=no)) + AC_MSG_RESULT($ac_cv_inaddrsz) + if test $ac_cv_inaddrsz = yes; then + AC_DEFINE(HAVE_INADDRSZ) + else + $1=no + fi +dnl check for IN6ADDRSZ + AC_MSG_CHECKING(for IN6ADDRSZ) + AC_CACHE_VAL(ac_cv_in6addrsz, + AC_TRY_COMPILE([ +# include ], + [int a = IN6ADDRSZ], + ac_cv_in6addrsz=yes, + ac_cv_in6addrsz=no)) + AC_MSG_RESULT($ac_cv_in6addrsz) + if test $ac_cv_in6addrsz = yes; then + AC_DEFINE(HAVE_IN6ADDRSZ) + else + $1=no + fi +]) + +dnl +dnl check for RES_USE_INET6 +AC_DEFUN(AC_CHECK_RES_USE_INET6, [ + AC_MSG_CHECKING(for RES_USE_INET6) + AC_CACHE_VAL($1, + AC_TRY_COMPILE([ +# include +# include +# include ], + [int a = RES_USE_INET6], + $1=yes, + $1=no)) + AC_MSG_RESULT($$1) + if test $$1 = yes; then + AC_DEFINE(HAVE_RES_USE_INET6) + fi +]) + +dnl +dnl check for AAAA +AC_DEFUN(AC_CHECK_AAAA, [ + AC_MSG_CHECKING(for AAAA) + AC_CACHE_VAL($1, + AC_TRY_COMPILE([ +# include +# include ], + [int a = T_AAAA], + $1=yes, + $1=no)) + AC_MSG_RESULT($$1) + if test $$1 = yes; then + AC_DEFINE(HAVE_AAAA) + fi +]) + +dnl +dnl check for struct res_state_ext +AC_DEFUN(AC_STRUCT_RES_STATE_EXT, [ + AC_MSG_CHECKING(for res_state_ext) + AC_CACHE_VAL($1, + AC_TRY_COMPILE([ +# include +# include +# include +# include ], + [struct __res_state_ext e], + $1=yes, + $1=no)) + AC_MSG_RESULT($$1) + if test $$1 = yes; then + AC_DEFINE(HAVE_RES_STATE_EXT) + fi +]) + +dnl +dnl check for struct res_state_ext +AC_DEFUN(AC_STRUCT_RES_STATE, [ + AC_MSG_CHECKING(for nsort in res_state) + AC_CACHE_VAL($1, + AC_TRY_COMPILE([ +# include +# include +# include +# include ], + [struct __res_state e; e.nsort = 0], + $1=yes, + $1=no)) + AC_MSG_RESULT($$1) + if test $$1 = yes; then + AC_DEFINE(HAVE_NEW_RES_STATE) + fi +]) + +dnl +dnl check for h_errno +AC_DEFUN(AC_VAR_H_ERRNO, [ + AC_MSG_CHECKING(for h_errno) + AC_CACHE_VAL(ac_cv_var_h_errno, + AC_TRY_COMPILE([ +# include +# include ], + [int foo = h_errno;], + ac_cv_var_h_errno=yes, + ac_cv_var_h_errno=no)) + AC_MSG_RESULT($ac_cv_var_h_errno) + if test "$ac_cv_var_h_errno" = "yes"; then + AC_DEFINE(HAVE_H_ERRNO) + fi +]) + +dnl +dnl Test for __attribute__ +dnl + +AC_DEFUN(AC_C___ATTRIBUTE__, [ +AC_MSG_CHECKING(for __attribute__) +AC_CACHE_VAL(ac_cv___attribute__, [ +AC_TRY_COMPILE([ +#include +], +[ +static void foo(void) __attribute__ ((noreturn)); + +static void +foo(void) +{ + exit(1); +} +], +ac_cv___attribute__=yes, +ac_cv___attribute__=no)]) +if test "$ac_cv___attribute__" = "yes"; then + AC_DEFINE(HAVE___ATTRIBUTE__, 1, [define if your compiler has __attribute__]) + V_DEFS="$V_DEFS -D_U_=\"__attribute__((unused))\"" +else + V_DEFS="$V_DEFS -D_U_=\"\"" +fi +AC_MSG_RESULT($ac_cv___attribute__) +]) diff --git a/kame/kame/tcpdump/addrtoname.c b/kame/kame/tcpdump/addrtoname.c index e78502cc7d..81d60e3a6a 100644 --- a/kame/kame/tcpdump/addrtoname.c +++ b/kame/kame/tcpdump/addrtoname.c @@ -22,63 +22,51 @@ * and address to string conversion routines */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: addrtoname.c,v 1.61 97/06/15 13:20:18 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/addrtoname.c,v 1.96.2.6 2004/03/24 04:14:31 guy Exp $ (LBL)"; #endif -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include - -#include -#include -#ifdef INET6 -#include -#endif +#include -#include +#ifdef USE_ETHER_NTOHOST +#ifdef HAVE_NETINET_IF_ETHER_H +struct mbuf; /* Squelch compiler warnings on some platforms for */ +struct rtentry; /* declarations in */ +#include /* for "struct ifnet" in "struct arpcom" on Solaris */ +#include +#endif /* HAVE_NETINET_IF_ETHER_H */ +#ifdef HAVE_NETINET_ETHER_H +#include /* ether_ntohost on linux */ +#endif /* HAVE_NETINET_ETHER_H */ +#endif /* USE_ETHER_NTOHOST */ -#include -#include #include #include -#ifdef HAVE_MALLOC_H -#include -#endif -#ifdef HAVE_MEMORY_H -#include -#endif #include #include #include #include -#include #include "interface.h" #include "addrtoname.h" #include "llc.h" -#include "savestr.h" #include "setsignal.h" -/* Forwards */ -static RETSIGTYPE nohostname(int); - /* * hash tables for whatever-to-name translations + * + * XXX there has to be error checks against strdup(3) failure */ #define HASHNAMESIZE 4096 struct hnamemem { u_int32_t addr; - char *name; + const char *name; struct hnamemem *nxt; }; @@ -88,6 +76,52 @@ struct hnamemem uporttable[HASHNAMESIZE]; struct hnamemem eprototable[HASHNAMESIZE]; struct hnamemem dnaddrtable[HASHNAMESIZE]; struct hnamemem llcsaptable[HASHNAMESIZE]; +struct hnamemem ipxsaptable[HASHNAMESIZE]; + +#if defined(INET6) && defined(WIN32) +/* + * fake gethostbyaddr for Win2k/XP + * gethostbyaddr() returns incorrect value when AF_INET6 is passed + * to 3rd argument. + * + * h_name in struct hostent is only valid. + */ +static struct hostent * +win32_gethostbyaddr(const char *addr, int len, int type) +{ + static struct hostent host; + static char hostbuf[NI_MAXHOST]; + char hname[NI_MAXHOST]; + struct sockaddr_in6 addr6; + + host.h_name = hostbuf; + switch (type) { + case AF_INET: + return gethostbyaddr(addr, len, type); + break; + case AF_INET6: + memset(&addr6, 0, sizeof(addr6)); + addr6.sin6_family = AF_INET6; + memcpy(&addr6.sin6_addr, addr, len); +#ifdef __MINGW32__ + /* MinGW doesn't provide getnameinfo */ + return NULL; +#else + if (getnameinfo((struct sockaddr *)&addr6, sizeof(addr6), + hname, sizeof(hname), NULL, 0, 0)) { + return NULL; + } else { + strcpy(host.h_name, hname); + return &host; + } +#endif /* __MINGW32__ */ + break; + default: + return NULL; + } +} +#define gethostbyaddr win32_gethostbyaddr +#endif /* INET6 & WIN32*/ #ifdef INET6 struct h6namemem { @@ -103,18 +137,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; }; @@ -123,7 +159,7 @@ struct protoidmem protoidtable[HASHNAMESIZE]; /* * A faster replacement for inet_ntoa(). */ -char * +const char * intoa(u_int32_t addr) { register char *cp; @@ -155,70 +191,34 @@ intoa(u_int32_t addr) static u_int32_t f_netmask; static u_int32_t f_localnet; -static u_int32_t netmask; - -/* - * "getname" is written in this atrocious way to make sure we don't - * wait forever while trying to get hostnames from yp. - */ -#include - -jmp_buf getname_env; - -static RETSIGTYPE -nohostname(int signo) -{ - longjmp(getname_env, 1); -} /* * Return a name for the IP address pointed to by ap. This address * is assumed to be in network byte order. + * + * NOTE: ap is *NOT* necessarily part of the packet data (not even if + * this is being called with the "ipaddr_string()" macro), so you + * *CANNOT* use the TCHECK{2}/TTEST{2} macros on it. Furthermore, + * even in cases where it *is* part of the packet data, the caller + * would still have to check for a null return value, even if it's + * just printing the return value with "%s" - not all versions of + * printf print "(null)" with "%s" and a null pointer, some of them + * don't check for a null pointer and crash in that case. + * + * The callers of this routine should, before handing this routine + * a pointer to packet data, be sure that the data is present in + * the packet buffer. They should probably do those checks anyway, + * as other data at that layer might not be IP addresses, and it + * also needs to check whether they're present in the packet buffer. */ -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 - /* - * Extract 32 bits in network order, dealing with alignment. - */ - switch ((long)ap & 3) { - - case 0: - addr = *(u_int32_t *)ap; - break; - - case 2: -#ifdef WORDS_BIGENDIAN - addr = ((u_int32_t)*(u_short *)ap << 16) | - (u_int32_t)*(u_short *)(ap + 2); -#else - addr = ((u_int32_t)*(u_short *)(ap + 2) << 16) | - (u_int32_t)*(u_short *)ap; -#endif - break; - - default: -#ifdef WORDS_BIGENDIAN - addr = ((u_int32_t)ap[0] << 24) | - ((u_int32_t)ap[1] << 16) | - ((u_int32_t)ap[2] << 8) | - (u_int32_t)ap[3]; -#else - addr = ((u_int32_t)ap[3] << 24) | - ((u_int32_t)ap[2] << 16) | - ((u_int32_t)ap[1] << 8) | - (u_int32_t)ap[0]; -#endif - break; - } -#endif + memcpy(&addr, ap, sizeof(addr)); p = &hnametable[addr & (HASHNAMESIZE-1)]; for (; p->nxt; p = p->nxt) { if (p->addr == addr) @@ -228,38 +228,29 @@ getname(const u_char *ap) p->nxt = newhnamemem(); /* - * Only print names when: - * (1) -n was not given. + * Print names unless: + * (1) -n was given. * (2) Address is foreign and -f was given. (If -f was not - * give, f_netmask and f_local are 0 and the test + * given, f_netmask and f_localnet are 0 and the test * evaluates to true) - * (3) -a was given or the host portion is not all ones - * nor all zeros (i.e. not a network or broadcast address) */ if (!nflag && - (addr & f_netmask) == f_localnet && - (aflag || - !((addr & ~netmask) == 0 || (addr | netmask) == 0xffffffff))) { - if (!setjmp(getname_env)) { - (void)setsignal(SIGALRM, nohostname); - (void)alarm(20); - hp = gethostbyaddr((char *)&addr, 4, AF_INET); - (void)alarm(0); - if (hp) { - char *dotp; - - p->name = savestr(hp->h_name); - if (Nflag) { - /* Remove domain qualifications */ - dotp = strchr(p->name, '.'); - if (dotp) - *dotp = '\0'; - } - return (p->name); + (addr & f_netmask) == f_localnet) { + hp = gethostbyaddr((char *)&addr, 4, AF_INET); + if (hp) { + char *dotp; + + p->name = strdup(hp->h_name); + if (Nflag) { + /* Remove domain qualifications */ + dotp = strchr(p->name, '.'); + if (dotp) + *dotp = '\0'; } + return (p->name); } } - p->name = savestr(intoa(addr)); + p->name = strdup(intoa(addr)); return (p->name); } @@ -268,17 +259,17 @@ 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)); - p = &h6nametable[addr.s6_addr16[7] & (HASHNAMESIZE-1)]; + p = &h6nametable[*(u_int16_t *)&addr.s6_addr[14] & (HASHNAMESIZE-1)]; for (; p->nxt; p = p->nxt) { if (memcmp(&p->addr, &addr, sizeof(addr)) == 0) return (p->name); @@ -287,43 +278,25 @@ getname6(const u_char *ap) p->nxt = newh6namemem(); /* - * Only print names when: - * (1) -n was not given. - * (2) Address is foreign and -f was given. (If -f was not - * give, f_netmask and f_local are 0 and the test - * evaluates to true) - * (3) -a was given or the host portion is not all ones - * nor all zeros (i.e. not a network or broadcast address) + * Do not print names if -n was given. */ - if (!nflag -#if 0 - && - (addr & f_netmask) == f_localnet && - (aflag || - !((addr & ~netmask) == 0 || (addr | netmask) == 0xffffffff)) -#endif - ) { - if (!setjmp(getname_env)) { - (void)setsignal(SIGALRM, nohostname); - (void)alarm(20); - hp = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET6); - (void)alarm(0); - if (hp) { - char *dotp; - - p->name = savestr(hp->h_name); - if (Nflag) { - /* Remove domain qualifications */ - dotp = strchr(p->name, '.'); - if (dotp) - *dotp = '\0'; - } - return (p->name); + if (!nflag) { + hp = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET6); + if (hp) { + char *dotp; + + p->name = strdup(hp->h_name); + if (Nflag) { + /* Remove domain qualifications */ + dotp = strchr(p->name, '.'); + if (dotp) + *dotp = '\0'; } + return (p->name); } } - 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 */ @@ -361,13 +334,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; @@ -385,7 +403,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 @@ -396,7 +414,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"); @@ -432,10 +450,10 @@ lookup_protoid(const u_char *pi) return tp; } -char * +const char * etheraddr_string(register const u_char *ep) { - register u_int i, j; + register u_int i; register char *cp; register struct enamemem *tp; char buf[sizeof("00:00:00:00:00:00")]; @@ -443,31 +461,59 @@ 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); + char buf2[128]; + if (ether_ntohost(buf2, (const struct ether_addr *)ep) == 0) { + tp->e_name = strdup(buf2); return (tp->e_name); } } #endif cp = buf; + *cp++ = hex[*ep >> 4 ]; + *cp++ = hex[*ep++ & 0xf]; + for (i = 5; (int)--i >= 0;) { + *cp++ = ':'; + *cp++ = hex[*ep >> 4 ]; + *cp++ = hex[*ep++ & 0xf]; + } + *cp = '\0'; + tp->e_name = strdup(buf); + return (tp->e_name); +} + +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 = 5; (int)--i >= 0;) { + for (i = len-1; i > 0 ; --i) { *cp++ = ':'; if ((j = *ep >> 4) != 0) *cp++ = hex[j]; *cp++ = hex[*ep++ & 0xf]; } *cp = '\0'; - tp->e_name = savestr(buf); return (tp->e_name); } -char * +const char * etherproto_string(u_short port) { register char *cp; @@ -489,11 +535,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; @@ -516,14 +562,13 @@ 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 char *cp; register struct hnamemem *tp; register u_int32_t i = sap; char buf[sizeof("sap 00")]; @@ -535,17 +580,12 @@ llcsap_string(u_char sap) tp->addr = i; tp->nxt = newhnamemem(); - cp = buf; - (void)strcpy(cp, "sap "); - cp += strlen(cp); - *cp++ = hex[sap >> 4 & 0xf]; - *cp++ = hex[sap & 0xf]; - *cp++ = '\0'; - tp->name = savestr(buf); + snprintf(buf, sizeof(buf), "sap %02x", sap & 0xff); + tp->name = strdup(buf); return (tp->name); } -char * +const char * isonsap_string(const u_char *nsap) { register u_int i, nlen = nsap[0]; @@ -570,7 +610,7 @@ isonsap_string(const u_char *nsap) return (tp->e_name); } -char * +const char * tcpport_string(u_short port) { register struct hnamemem *tp; @@ -584,12 +624,12 @@ tcpport_string(u_short port) tp->addr = i; tp->nxt = newhnamemem(); - (void)sprintf(buf, "%u", i); - tp->name = savestr(buf); + (void)snprintf(buf, sizeof(buf), "%u", i); + tp->name = strdup(buf); return (tp->name); } -char * +const char * udpport_string(register u_short port) { register struct hnamemem *tp; @@ -603,8 +643,34 @@ udpport_string(register u_short port) tp->addr = i; tp->nxt = newhnamemem(); - (void)sprintf(buf, "%u", i); - tp->name = savestr(buf); + (void)snprintf(buf, sizeof(buf), "%u", i); + tp->name = strdup(buf); + return (tp->name); +} + +const char * +ipxsap_string(u_short port) +{ + register char *cp; + register struct hnamemem *tp; + register u_int32_t i = port; + char buf[sizeof("0000")]; + + for (tp = &ipxsaptable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt) + if (tp->addr == i) + return (tp->name); + + tp->addr = i; + tp->nxt = newhnamemem(); + + cp = buf; + NTOHS(port); + *cp++ = hex[port >> 12 & 0xf]; + *cp++ = hex[port >> 8 & 0xf]; + *cp++ = hex[port >> 4 & 0xf]; + *cp++ = hex[port & 0xf]; + *cp++ = '\0'; + tp->name = strdup(buf); return (tp->name); } @@ -629,10 +695,10 @@ init_servarray(void) while (table->name) table = table->nxt; if (nflag) { - (void)sprintf(buf, "%d", port); - table->name = savestr(buf); + (void)snprintf(buf, sizeof(buf), "%d", port); + table->name = strdup(buf); } else - table->name = savestr(sv->s_name); + table->name = strdup(sv->s_name); table->addr = port; table->nxt = newhnamemem(); } @@ -640,7 +706,11 @@ init_servarray(void) } /*XXX from libbpfc.a */ +#ifndef WIN32 extern struct eproto { +#else +__declspec( dllimport) struct eproto { +#endif char *s; u_short p; } eproto_db[]; @@ -652,16 +722,28 @@ init_eprotoarray(void) register struct hnamemem *table; for (i = 0; eproto_db[i].s; i++) { - int j = ntohs(eproto_db[i].p) & (HASHNAMESIZE-1); + int j = htons(eproto_db[i].p) & (HASHNAMESIZE-1); table = &eprototable[j]; while (table->name) table = table->nxt; table->name = eproto_db[i].s; - table->addr = ntohs(eproto_db[i].p); + table->addr = htons(eproto_db[i].p); table->nxt = newhnamemem(); } } +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. @@ -671,6 +753,7 @@ init_protoidarray(void) { register int i; register struct protoidmem *tp; + struct protoidlist *pl; u_char protoid[5]; protoid[0] = 0; @@ -681,13 +764,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 } @@ -712,7 +804,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; @@ -723,7 +815,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); } @@ -736,10 +828,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 @@ -757,6 +849,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 } @@ -778,6 +873,240 @@ init_llcsaparray(void) } } +static struct tok ipxsap_db[] = { + { 0x0000, "Unknown" }, + { 0x0001, "User" }, + { 0x0002, "User Group" }, + { 0x0003, "PrintQueue" }, + { 0x0004, "FileServer" }, + { 0x0005, "JobServer" }, + { 0x0006, "Gateway" }, + { 0x0007, "PrintServer" }, + { 0x0008, "ArchiveQueue" }, + { 0x0009, "ArchiveServer" }, + { 0x000a, "JobQueue" }, + { 0x000b, "Administration" }, + { 0x000F, "Novell TI-RPC" }, + { 0x0017, "Diagnostics" }, + { 0x0020, "NetBIOS" }, + { 0x0021, "NAS SNA Gateway" }, + { 0x0023, "NACS AsyncGateway" }, + { 0x0024, "RemoteBridge/RoutingService" }, + { 0x0026, "BridgeServer" }, + { 0x0027, "TCP/IP Gateway" }, + { 0x0028, "Point-to-point X.25 BridgeServer" }, + { 0x0029, "3270 Gateway" }, + { 0x002a, "CHI Corp" }, + { 0x002c, "PC Chalkboard" }, + { 0x002d, "TimeSynchServer" }, + { 0x002e, "ARCserve5.0/PalindromeBackup" }, + { 0x0045, "DI3270 Gateway" }, + { 0x0047, "AdvertisingPrintServer" }, + { 0x004a, "NetBlazerModems" }, + { 0x004b, "BtrieveVAP" }, + { 0x004c, "NetwareSQL" }, + { 0x004d, "XtreeNetwork" }, + { 0x0050, "BtrieveVAP4.11" }, + { 0x0052, "QuickLink" }, + { 0x0053, "PrintQueueUser" }, + { 0x0058, "Multipoint X.25 Router" }, + { 0x0060, "STLB/NLM" }, + { 0x0064, "ARCserve" }, + { 0x0066, "ARCserve3.0" }, + { 0x0072, "WAN CopyUtility" }, + { 0x007a, "TES-NetwareVMS" }, + { 0x0092, "WATCOM Debugger/EmeraldTapeBackupServer" }, + { 0x0095, "DDA OBGYN" }, + { 0x0098, "NetwareAccessServer" }, + { 0x009a, "Netware for VMS II/NamedPipeServer" }, + { 0x009b, "NetwareAccessServer" }, + { 0x009e, "PortableNetwareServer/SunLinkNVT" }, + { 0x00a1, "PowerchuteAPC UPS" }, + { 0x00aa, "LAWserve" }, + { 0x00ac, "CompaqIDA StatusMonitor" }, + { 0x0100, "PIPE STAIL" }, + { 0x0102, "LAN ProtectBindery" }, + { 0x0103, "OracleDataBaseServer" }, + { 0x0107, "Netware386/RSPX RemoteConsole" }, + { 0x010f, "NovellSNA Gateway" }, + { 0x0111, "TestServer" }, + { 0x0112, "HP PrintServer" }, + { 0x0114, "CSA MUX" }, + { 0x0115, "CSA LCA" }, + { 0x0116, "CSA CM" }, + { 0x0117, "CSA SMA" }, + { 0x0118, "CSA DBA" }, + { 0x0119, "CSA NMA" }, + { 0x011a, "CSA SSA" }, + { 0x011b, "CSA STATUS" }, + { 0x011e, "CSA APPC" }, + { 0x0126, "SNA TEST SSA Profile" }, + { 0x012a, "CSA TRACE" }, + { 0x012b, "NetwareSAA" }, + { 0x012e, "IKARUS VirusScan" }, + { 0x0130, "CommunicationsExecutive" }, + { 0x0133, "NNS DomainServer/NetwareNamingServicesDomain" }, + { 0x0135, "NetwareNamingServicesProfile" }, + { 0x0137, "Netware386 PrintQueue/NNS PrintQueue" }, + { 0x0141, "LAN SpoolServer" }, + { 0x0152, "IRMALAN Gateway" }, + { 0x0154, "NamedPipeServer" }, + { 0x0166, "NetWareManagement" }, + { 0x0168, "Intel PICKIT CommServer/Intel CAS TalkServer" }, + { 0x0173, "Compaq" }, + { 0x0174, "Compaq SNMP Agent" }, + { 0x0175, "Compaq" }, + { 0x0180, "XTreeServer/XTreeTools" }, + { 0x018A, "NASI ServicesBroadcastServer" }, + { 0x01b0, "GARP Gateway" }, + { 0x01b1, "Binfview" }, + { 0x01bf, "IntelLanDeskManager" }, + { 0x01ca, "AXTEC" }, + { 0x01cb, "ShivaNetModem/E" }, + { 0x01cc, "ShivaLanRover/E" }, + { 0x01cd, "ShivaLanRover/T" }, + { 0x01ce, "ShivaUniversal" }, + { 0x01d8, "CastelleFAXPressServer" }, + { 0x01da, "CastelleLANPressPrintServer" }, + { 0x01dc, "CastelleFAX/Xerox7033 FaxServer/ExcelLanFax" }, + { 0x01f0, "LEGATO" }, + { 0x01f5, "LEGATO" }, + { 0x0233, "NMS Agent/NetwareManagementAgent" }, + { 0x0237, "NMS IPX Discovery/LANternReadWriteChannel" }, + { 0x0238, "NMS IP Discovery/LANternTrapAlarmChannel" }, + { 0x023a, "LANtern" }, + { 0x023c, "MAVERICK" }, + { 0x023f, "NovellSMDR" }, + { 0x024e, "NetwareConnect" }, + { 0x024f, "NASI ServerBroadcast Cisco" }, + { 0x026a, "NMS ServiceConsole" }, + { 0x026b, "TimeSynchronizationServer Netware 4.x" }, + { 0x0278, "DirectoryServer Netware 4.x" }, + { 0x027b, "NetwareManagementAgent" }, + { 0x0280, "Novell File and Printer Sharing Service for PC" }, + { 0x0304, "NovellSAA Gateway" }, + { 0x0308, "COM/VERMED" }, + { 0x030a, "GalacticommWorldgroupServer" }, + { 0x030c, "IntelNetport2/HP JetDirect/HP Quicksilver" }, + { 0x0320, "AttachmateGateway" }, + { 0x0327, "MicrosoftDiagnostiocs" }, + { 0x0328, "WATCOM SQL Server" }, + { 0x0335, "MultiTechSystems MultisynchCommServer" }, + { 0x0343, "Xylogics RemoteAccessServer/LANModem" }, + { 0x0355, "ArcadaBackupExec" }, + { 0x0358, "MSLCD1" }, + { 0x0361, "NETINELO" }, + { 0x037e, "Powerchute UPS Monitoring" }, + { 0x037f, "ViruSafeNotify" }, + { 0x0386, "HP Bridge" }, + { 0x0387, "HP Hub" }, + { 0x0394, "NetWare SAA Gateway" }, + { 0x039b, "LotusNotes" }, + { 0x03b7, "CertusAntiVirus" }, + { 0x03c4, "ARCserve4.0" }, + { 0x03c7, "LANspool3.5" }, + { 0x03d7, "LexmarkPrinterServer" }, + { 0x03d8, "LexmarkXLE PrinterServer" }, + { 0x03dd, "BanyanENS NetwareClient" }, + { 0x03de, "GuptaSequelBaseServer/NetWareSQL" }, + { 0x03e1, "UnivelUnixware" }, + { 0x03e4, "UnivelUnixware" }, + { 0x03fc, "IntelNetport" }, + { 0x03fd, "PrintServerQueue" }, + { 0x040A, "ipnServer" }, + { 0x040D, "LVERRMAN" }, + { 0x040E, "LVLIC" }, + { 0x0414, "NET Silicon (DPI)/Kyocera" }, + { 0x0429, "SiteLockVirus" }, + { 0x0432, "UFHELPR???" }, + { 0x0433, "Synoptics281xAdvancedSNMPAgent" }, + { 0x0444, "MicrosoftNT SNA Server" }, + { 0x0448, "Oracle" }, + { 0x044c, "ARCserve5.01" }, + { 0x0457, "CanonGP55" }, + { 0x045a, "QMS Printers" }, + { 0x045b, "DellSCSI Array" }, + { 0x0491, "NetBlazerModems" }, + { 0x04ac, "OnTimeScheduler" }, + { 0x04b0, "CD-Net" }, + { 0x0513, "EmulexNQA" }, + { 0x0520, "SiteLockChecks" }, + { 0x0529, "SiteLockChecks" }, + { 0x052d, "CitrixOS2 AppServer" }, + { 0x0535, "Tektronix" }, + { 0x0536, "Milan" }, + { 0x055d, "Attachmate SNA gateway" }, + { 0x056b, "IBM8235 ModemServer" }, + { 0x056c, "ShivaLanRover/E PLUS" }, + { 0x056d, "ShivaLanRover/T PLUS" }, + { 0x0580, "McAfeeNetShield" }, + { 0x05B8, "NLM to workstation communication (Revelation Software)" }, + { 0x05BA, "CompatibleSystemsRouters" }, + { 0x05BE, "CheyenneHierarchicalStorageManager" }, + { 0x0606, "JCWatermarkImaging" }, + { 0x060c, "AXISNetworkPrinter" }, + { 0x0610, "AdaptecSCSIManagement" }, + { 0x0621, "IBM AntiVirus" }, + { 0x0640, "Windows95 RemoteRegistryService" }, + { 0x064e, "MicrosoftIIS" }, + { 0x067b, "Microsoft Win95/98 File and Print Sharing for NetWare" }, + { 0x067c, "Microsoft Win95/98 File and Print Sharing for NetWare" }, + { 0x076C, "Xerox" }, + { 0x079b, "ShivaLanRover/E 115" }, + { 0x079c, "ShivaLanRover/T 115" }, + { 0x07B4, "CubixWorldDesk" }, + { 0x07c2, "Quarterdeck IWare Connect V2.x NLM" }, + { 0x07c1, "Quarterdeck IWare Connect V3.x NLM" }, + { 0x0810, "ELAN License Server Demo" }, + { 0x0824, "ShivaLanRoverAccessSwitch/E" }, + { 0x086a, "ISSC Collector" }, + { 0x087f, "ISSC DAS AgentAIX" }, + { 0x0880, "Intel Netport PRO" }, + { 0x0881, "Intel Netport PRO" }, + { 0x0b29, "SiteLock" }, + { 0x0c29, "SiteLockApplications" }, + { 0x0c2c, "LicensingServer" }, + { 0x2101, "PerformanceTechnologyInstantInternet" }, + { 0x2380, "LAI SiteLock" }, + { 0x238c, "MeetingMaker" }, + { 0x4808, "SiteLockServer/SiteLockMetering" }, + { 0x5555, "SiteLockUser" }, + { 0x6312, "Tapeware" }, + { 0x6f00, "RabbitGateway" }, + { 0x7703, "MODEM" }, + { 0x8002, "NetPortPrinters" }, + { 0x8008, "WordPerfectNetworkVersion" }, + { 0x85BE, "Cisco EIGRP" }, + { 0x8888, "WordPerfectNetworkVersion/QuickNetworkManagement" }, + { 0x9000, "McAfeeNetShield" }, + { 0x9604, "CSA-NT_MON" }, + { 0xb6a8, "OceanIsleReachoutRemoteControl" }, + { 0xf11f, "SiteLockMetering" }, + { 0xf1ff, "SiteLock" }, + { 0xf503, "Microsoft SQL Server" }, + { 0xF905, "IBM TimeAndPlace" }, + { 0xfbfb, "TopCallIII FaxServer" }, + { 0xffff, "AnyService/Wildcard" }, + { 0, (char *)0 } +}; + +static void +init_ipxsaparray(void) +{ + register int i; + register struct hnamemem *table; + + for (i = 0; ipxsap_db[i].s != NULL; i++) { + int j = htons(ipxsap_db[i].v) & (HASHNAMESIZE-1); + table = &ipxsaptable[j]; + while (table->name) + table = table->nxt; + table->name = ipxsap_db[i].s; + table->addr = htons(ipxsap_db[i].v); + table->nxt = newhnamemem(); + } +} + /* * Initialize the address to name translation machinery. We map all * non-local IP addresses to numeric addresses if fflag is true (i.e., @@ -787,7 +1116,6 @@ init_llcsaparray(void) void init_addrtoname(u_int32_t localnet, u_int32_t mask) { - netmask = mask; if (fflag) { f_localnet = localnet; f_netmask = mask; @@ -803,9 +1131,10 @@ init_addrtoname(u_int32_t localnet, u_int32_t mask) init_eprotoarray(); init_llcsaparray(); init_protoidarray(); + init_ipxsaparray(); } -char * +const char * dnaddr_string(u_short dnaddr) { register struct hnamemem *tp; diff --git a/kame/kame/tcpdump/addrtoname.h b/kame/kame/tcpdump/addrtoname.h index 9483ef82d2..67ded6e694 100644 --- a/kame/kame/tcpdump/addrtoname.h +++ b/kame/kame/tcpdump/addrtoname.h @@ -18,20 +18,21 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: addrtoname.h,v 1.15 97/01/01 21:01:16 leres 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/kame/kame/tcpdump/ah.h b/kame/kame/tcpdump/ah.h new file mode 100644 index 0000000000..c22806afe8 --- /dev/null +++ b/kame/kame/tcpdump/ah.h @@ -0,0 +1,57 @@ +/* $NetBSD: ah.h,v 1.12 2000/07/23 05:23:04 itojun Exp $ */ +/* $KAME: ah.h,v 1.12 2000/07/20 17:41:01 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. + */ + +/* + * RFC1826/2402 authentication header. + */ + +#ifndef _NETINET6_AH_H_ +#define _NETINET6_AH_H_ + +struct ah { + u_int8_t ah_nxt; /* Next Header */ + u_int8_t ah_len; /* Length of data, in 32bit */ + u_int16_t ah_reserve; /* Reserved for future use */ + u_int32_t ah_spi; /* Security parameter index */ + /* variable size, 32bit bound*/ /* Authentication data */ +}; + +struct newah { + u_int8_t ah_nxt; /* Next Header */ + u_int8_t ah_len; /* Length of data + 1, in 32bit */ + u_int16_t ah_reserve; /* Reserved for future use */ + u_int32_t ah_spi; /* Security parameter index */ + u_int32_t ah_seq; /* Sequence number field */ + /* variable size, 32bit bound*/ /* Authentication data */ +}; + +#endif /*_NETINET6_AH_H_*/ diff --git a/kame/kame/tcpdump/aodv.h b/kame/kame/tcpdump/aodv.h new file mode 100644 index 0000000000..335c175c12 --- /dev/null +++ b/kame/kame/tcpdump/aodv.h @@ -0,0 +1,190 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/aodv.h,v 1.3 2003/09/13 01:34:42 guy Exp $ (LBL) */ +/* + * Copyright (c) 2003 Bruce M. Simpson + * 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 Bruce M. Simpson. + * 4. Neither the name of Bruce M. Simpson nor the names of co- + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bruce M. Simpson 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 Bruce M. Simpson 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 _AODV_H_ +#define _AODV_H_ + +struct aodv_rreq { + u_int8_t rreq_type; /* AODV message type (1) */ + u_int8_t rreq_flags; /* various flags */ + u_int8_t rreq_zero0; /* reserved, set to zero */ + u_int8_t rreq_hops; /* number of hops from originator */ + u_int32_t rreq_id; /* request ID */ + u_int32_t rreq_da; /* destination IPv4 address */ + u_int32_t rreq_ds; /* destination sequence number */ + u_int32_t rreq_oa; /* originator IPv4 address */ + u_int32_t rreq_os; /* originator sequence number */ +}; +#ifdef INET6 +struct aodv_rreq6 { + u_int8_t rreq_type; /* AODV message type (1) */ + u_int8_t rreq_flags; /* various flags */ + u_int8_t rreq_zero0; /* reserved, set to zero */ + u_int8_t rreq_hops; /* number of hops from originator */ + u_int32_t rreq_id; /* request ID */ + struct in6_addr rreq_da; /* destination IPv6 address */ + u_int32_t rreq_ds; /* destination sequence number */ + struct in6_addr rreq_oa; /* originator IPv6 address */ + u_int32_t rreq_os; /* originator sequence number */ +}; +struct aodv_rreq6_draft_01 { + u_int8_t rreq_type; /* AODV message type (16) */ + u_int8_t rreq_flags; /* various flags */ + u_int8_t rreq_zero0; /* reserved, set to zero */ + u_int8_t rreq_hops; /* number of hops from originator */ + u_int32_t rreq_id; /* request ID */ + u_int32_t rreq_ds; /* destination sequence number */ + u_int32_t rreq_os; /* originator sequence number */ + struct in6_addr rreq_da; /* destination IPv6 address */ + struct in6_addr rreq_oa; /* originator IPv6 address */ +}; +#endif + +#define RREQ_JOIN 0x80 /* join (reserved for multicast */ +#define RREQ_REPAIR 0x40 /* repair (reserved for multicast */ +#define RREQ_GRAT 0x20 /* gratuitous RREP */ +#define RREQ_DEST 0x10 /* destination only */ +#define RREQ_UNKNOWN 0x08 /* unknown destination sequence num */ +#define RREQ_FLAGS_MASK 0xF8 /* mask for rreq_flags */ + +struct aodv_rrep { + u_int8_t rrep_type; /* AODV message type (2) */ + u_int8_t rrep_flags; /* various flags */ + u_int8_t rrep_ps; /* prefix size */ + u_int8_t rrep_hops; /* number of hops from o to d */ + u_int32_t rrep_da; /* destination IPv4 address */ + u_int32_t rrep_ds; /* destination sequence number */ + u_int32_t rrep_oa; /* originator IPv4 address */ + u_int32_t rrep_life; /* lifetime of this route */ +}; +#ifdef INET6 +struct aodv_rrep6 { + u_int8_t rrep_type; /* AODV message type (2) */ + u_int8_t rrep_flags; /* various flags */ + u_int8_t rrep_ps; /* prefix size */ + u_int8_t rrep_hops; /* number of hops from o to d */ + struct in6_addr rrep_da; /* destination IPv6 address */ + u_int32_t rrep_ds; /* destination sequence number */ + struct in6_addr rrep_oa; /* originator IPv6 address */ + u_int32_t rrep_life; /* lifetime of this route */ +}; +struct aodv_rrep6_draft_01 { + u_int8_t rrep_type; /* AODV message type (17) */ + u_int8_t rrep_flags; /* various flags */ + u_int8_t rrep_ps; /* prefix size */ + u_int8_t rrep_hops; /* number of hops from o to d */ + u_int32_t rrep_ds; /* destination sequence number */ + struct in6_addr rrep_da; /* destination IPv6 address */ + struct in6_addr rrep_oa; /* originator IPv6 address */ + u_int32_t rrep_life; /* lifetime of this route */ +}; +#endif + +#define RREP_REPAIR 0x80 /* repair (reserved for multicast */ +#define RREP_ACK 0x40 /* acknowledgement required */ +#define RREP_FLAGS_MASK 0xC0 /* mask for rrep_flags */ +#define RREP_PREFIX_MASK 0x1F /* mask for prefix size */ + +struct rerr_unreach { + u_int32_t u_da; /* IPv4 address */ + u_int32_t u_ds; /* sequence number */ +}; +#ifdef INET6 +struct rerr_unreach6 { + struct in6_addr u_da; /* IPv6 address */ + u_int32_t u_ds; /* sequence number */ +}; +struct rerr_unreach6_draft_01 { + struct in6_addr u_da; /* IPv6 address */ + u_int32_t u_ds; /* sequence number */ +}; +#endif + +struct aodv_rerr { + u_int8_t rerr_type; /* AODV message type (3 or 18) */ + u_int8_t rerr_flags; /* various flags */ + u_int8_t rerr_zero0; /* reserved, set to zero */ + u_int8_t rerr_dc; /* destination count */ + union { + struct rerr_unreach dest[1]; +#ifdef INET6 + struct rerr_unreach6 dest6[1]; + struct rerr_unreach6_draft_01 dest6_draft_01[1]; +#endif + } r; +}; + +#define RERR_NODELETE 0x80 /* don't delete the link */ +#define RERR_FLAGS_MASK 0x80 /* mask for rerr_flags */ + +struct aodv_rrep_ack { + u_int8_t ra_type; + u_int8_t ra_zero0; +}; + +union aodv { + struct aodv_rreq rreq; + struct aodv_rrep rrep; + struct aodv_rerr rerr; + struct aodv_rrep_ack rrep_ack; +#ifdef INET6 + struct aodv_rreq6 rreq6; + struct aodv_rreq6_draft_01 rreq6_draft_01; + struct aodv_rrep6 rrep6; + struct aodv_rrep6_draft_01 rrep6_draft_01; +#endif +}; + +#define AODV_RREQ 1 /* route request */ +#define AODV_RREP 2 /* route response */ +#define AODV_RERR 3 /* error report */ +#define AODV_RREP_ACK 4 /* route response acknowledgement */ + +#define AODV_V6_DRAFT_01_RREQ 16 /* IPv6 route request */ +#define AODV_V6_DRAFT_01_RREP 17 /* IPv6 route response */ +#define AODV_V6_DRAFT_01_RERR 18 /* IPv6 error report */ +#define AODV_V6_DRAFT_01_RREP_ACK 19 /* IPV6 route response acknowledgment */ + +struct aodv_ext { + u_int8_t type; /* extension type */ + u_int8_t length; /* extension length */ +}; + +struct aodv_hello { + struct aodv_ext eh; /* extension header */ + u_int32_t interval; /* expect my next hello in + * (n) ms */ +}; + +#define AODV_EXT_HELLO 1 + +#endif /* _AODV_H_ */ diff --git a/kame/kame/tcpdump/appletalk.h b/kame/kame/tcpdump/appletalk.h index 4f690f9a24..83e6f70e8e 100644 --- a/kame/kame/tcpdump/appletalk.h +++ b/kame/kame/tcpdump/appletalk.h @@ -20,13 +20,13 @@ * * AppleTalk protocol formats (courtesy Bill Croft of Stanford/SUMEX). * - * @(#) $Header: appletalk.h,v 1.12 96/06/03 02:54:24 leres Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/appletalk.h,v 1.15 2002/12/11 07:13:49 guy Exp $ (LBL) */ struct LAP { - u_char dst; - u_char src; - u_char type; + u_int8_t dst; + u_int8_t src; + u_int8_t type; }; #define lapShortDDP 1 /* short DDP type */ #define lapDDP 2 /* DDP type */ @@ -35,22 +35,22 @@ struct LAP { /* Datagram Delivery Protocol */ struct atDDP { - u_short length; - u_short checksum; - u_short dstNet; - u_short srcNet; - u_char dstNode; - u_char srcNode; - u_char dstSkt; - u_char srcSkt; - u_char type; + u_int16_t length; + u_int16_t checksum; + u_int16_t dstNet; + u_int16_t srcNet; + u_int8_t dstNode; + u_int8_t srcNode; + u_int8_t dstSkt; + u_int8_t srcSkt; + u_int8_t type; }; struct atShortDDP { - u_short length; - u_char dstSkt; - u_char srcSkt; - u_char type; + u_int16_t length; + u_int8_t dstSkt; + u_int8_t srcSkt; + u_int8_t type; }; #define ddpMaxWKS 0x7F @@ -73,9 +73,9 @@ struct atShortDDP { /* AppleTalk Transaction Protocol */ struct atATP { - u_char control; - u_char bitmap; - u_short transID; + u_int8_t control; + u_int8_t bitmap; + u_int16_t transID; int32_t userData; }; @@ -94,8 +94,8 @@ struct atATP { /* AppleTalk Echo Protocol */ struct atEcho { - u_char echoFunction; - u_char *echoData; + u_int8_t echoFunction; + u_int8_t *echoData; }; #define echoSkt 4 /* the echoer socket */ @@ -107,15 +107,15 @@ struct atEcho { /* Name Binding Protocol */ struct atNBP { - u_char control; - u_char id; + u_int8_t control; + u_int8_t id; }; struct atNBPtuple { - u_short net; - u_char node; - u_char skt; - u_char enumerator; + u_int16_t net; + u_int8_t node; + u_int8_t skt; + u_int8_t enumerator; }; #define nbpBrRq 0x10 @@ -141,8 +141,8 @@ struct atNBPtuple { /* Zone Information Protocol */ struct zipHeader { - u_char command; - u_char netcount; + u_int8_t command; + u_int8_t netcount; }; #define zipHeaderSize 2 diff --git a/kame/kame/tcpdump/arcnet.h b/kame/kame/tcpdump/arcnet.h new file mode 100644 index 0000000000..6e649f61e0 --- /dev/null +++ b/kame/kame/tcpdump/arcnet.h @@ -0,0 +1,101 @@ +/* + * 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.3 2003/01/23 09:05:37 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 on the BSDs, + * 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 */ +}; + +#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 */ + +/* + * Structure of a 2.5MB/s Arcnet header on Linux. Linux has + * an extra "offset" field when given to interface code, and + * never presents packets that look like exception frames. + */ +struct arc_linux_header { + u_int8_t arc_shost; + u_int8_t arc_dhost; + u_int16_t arc_offset; + u_int8_t arc_type; + /* + * only present for newstyle encoding with LL fragmentation. + * Don't use sizeof(anything), use ARC_LINUX_HDR{,NEW}LEN + * instead. + */ + u_int8_t arc_flag; + u_int16_t arc_seqid; +}; + +#define ARC_LINUX_HDRLEN 5 +#define ARC_LINUX_HDRNEWLEN 8 diff --git a/kame/kame/tcpdump/atm.h b/kame/kame/tcpdump/atm.h new file mode 100644 index 0000000000..4fe2021055 --- /dev/null +++ b/kame/kame/tcpdump/atm.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2002 Guy Harris. + * 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 Guy Harris 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. + * + * @(#) $Header: /tcpdump/master/tcpdump/atm.h,v 1.1 2002/07/11 09:17:22 guy Exp $ + */ + +/* + * Traffic types for ATM. + */ +#define ATM_UNKNOWN 0 /* Unknown */ +#define ATM_LANE 1 /* LANE */ +#define ATM_LLC 2 /* LLC encapsulation */ diff --git a/kame/kame/tcpdump/atmuni31.h b/kame/kame/tcpdump/atmuni31.h new file mode 100644 index 0000000000..304859a9f1 --- /dev/null +++ b/kame/kame/tcpdump/atmuni31.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 1997 Yen Yen Lim and North Dakota State University + * 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 Yen Yen Lim and + North Dakota State University + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * 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. + * + * @(#) $Header: /tcpdump/master/tcpdump/atmuni31.h,v 1.2 2002/08/05 07:47:23 guy Exp $ (LBL) + */ + +/* Based on UNI3.1 standard by ATM Forum */ + +/* ATM traffic types based on VPI=0 and (the following VCI */ +#define PPC 0x05 /* Point-to-point signal msg */ +#define BCC 0x02 /* Broadcast signal msg */ +#define OAMF4SC 0x03 /* Segment OAM F4 flow cell */ +#define OAMF4EC 0x04 /* End-to-end OAM F4 flow cell */ +#define METAC 0x01 /* Meta signal msg */ +#define ILMIC 0x10 /* ILMI msg */ + +/* Q.2931 signalling messages */ +#define CALL_PROCEED 0x02 /* call proceeding */ +#define CONNECT 0x07 /* connect */ +#define CONNECT_ACK 0x0f /* connect_ack */ +#define SETUP 0x05 /* setup */ +#define RELEASE 0x4d /* release */ +#define RELEASE_DONE 0x5a /* release_done */ +#define RESTART 0x46 /* restart */ +#define RESTART_ACK 0x4e /* restart ack */ +#define STATUS 0x7d /* status */ +#define STATUS_ENQ 0x75 /* status ack */ +#define ADD_PARTY 0x80 /* add party */ +#define ADD_PARTY_ACK 0x81 /* add party ack */ +#define ADD_PARTY_REJ 0x82 /* add party rej */ +#define DROP_PARTY 0x83 /* drop party */ +#define DROP_PARTY_ACK 0x84 /* drop party ack */ + +/* Information Element Parameters in the signalling messages */ +#define CAUSE 0x08 /* cause */ +#define ENDPT_REF 0x54 /* endpoint reference */ +#define AAL_PARA 0x58 /* ATM adaptation layer parameters */ +#define TRAFF_DESCRIP 0x59 /* atm traffic descriptors */ +#define CONNECT_ID 0x5a /* connection identifier */ +#define QOS_PARA 0x5c /* quality of service parameters */ +#define B_HIGHER 0x5d /* broadband higher layer information */ +#define B_BEARER 0x5e /* broadband bearer capability */ +#define B_LOWER 0x5f /* broadband lower information */ +#define CALLING_PARTY 0x6c /* calling party number */ +#define CALLED_PARTY 0x70 /* called party nmber */ + +#define Q2931 0x09 + +/* Q.2931 signalling general messages format */ +#define PROTO_POS 0 /* offset of protocol discriminator */ +#define CALL_REF_POS 2 /* offset of call reference value */ +#define MSG_TYPE_POS 5 /* offset of message type */ +#define MSG_LEN_POS 7 /* offset of mesage length */ +#define IE_BEGIN_POS 9 /* offset of first information element */ + +/* format of signalling messages */ +#define TYPE_POS 0 +#define LEN_POS 2 +#define FIELD_BEGIN_POS 4 diff --git a/kame/kame/tcpdump/bootp.h b/kame/kame/tcpdump/bootp.h index f6ba65df5f..2e5d401410 100644 --- a/kame/kame/tcpdump/bootp.h +++ b/kame/kame/tcpdump/bootp.h @@ -1,4 +1,4 @@ -/* @(#) $Header: bootp.h,v 1.7 95/05/04 17:52:46 mccanne Exp $ (LBL) */ +/* @(#) $Header: /tcpdump/master/tcpdump/bootp.h,v 1.15 2003/07/01 19:16:06 guy Exp $ (LBL) */ /* * Bootstrap Protocol (BOOTP). RFC951 and RFC1048. * @@ -21,21 +21,21 @@ struct bootp { - unsigned char bp_op; /* packet opcode type */ - unsigned char bp_htype; /* hardware addr type */ - unsigned char bp_hlen; /* hardware addr length */ - unsigned char bp_hops; /* gateway hops */ + u_int8_t bp_op; /* packet opcode type */ + u_int8_t bp_htype; /* hardware addr type */ + u_int8_t bp_hlen; /* hardware addr length */ + u_int8_t bp_hops; /* gateway hops */ u_int32_t bp_xid; /* transaction ID */ - unsigned short bp_secs; /* seconds since boot began */ - unsigned short bp_unused; + u_int16_t bp_secs; /* seconds since boot began */ + u_int16_t bp_flags; /* flags - see bootp_flag_values[] in print-bootp.c */ struct in_addr bp_ciaddr; /* client IP address */ struct in_addr bp_yiaddr; /* 'your' IP address */ struct in_addr bp_siaddr; /* server IP address */ struct in_addr bp_giaddr; /* gateway IP address */ - unsigned char bp_chaddr[16]; /* client hardware address */ - unsigned char bp_sname[64]; /* server host name */ - unsigned char bp_file[128]; /* boot file name */ - unsigned char bp_vend[64]; /* vendor-specific area */ + u_int8_t bp_chaddr[16]; /* client hardware address */ + u_int8_t bp_sname[64]; /* server host name */ + u_int8_t bp_file[128]; /* boot file name */ + u_int8_t bp_vend[64]; /* vendor-specific area */ }; /* @@ -44,9 +44,8 @@ struct bootp { #define IPPORT_BOOTPS 67 #define IPPORT_BOOTPC 68 -#define BOOTREPLY 2 -#define BOOTREQUEST 1 - +#define BOOTPREPLY 2 +#define BOOTPREQUEST 1 /* * Vendor magic cookie (v_magic) for CMU @@ -65,86 +64,140 @@ struct bootp { * the vendor field of the packet. */ -#define TAG_PAD ((unsigned char) 0) -#define TAG_SUBNET_MASK ((unsigned char) 1) -#define TAG_TIME_OFFSET ((unsigned char) 2) -#define TAG_GATEWAY ((unsigned char) 3) -#define TAG_TIME_SERVER ((unsigned char) 4) -#define TAG_NAME_SERVER ((unsigned char) 5) -#define TAG_DOMAIN_SERVER ((unsigned char) 6) -#define TAG_LOG_SERVER ((unsigned char) 7) -#define TAG_COOKIE_SERVER ((unsigned char) 8) -#define TAG_LPR_SERVER ((unsigned char) 9) -#define TAG_IMPRESS_SERVER ((unsigned char) 10) -#define TAG_RLP_SERVER ((unsigned char) 11) -#define TAG_HOSTNAME ((unsigned char) 12) -#define TAG_BOOTSIZE ((unsigned char) 13) -#define TAG_END ((unsigned char) 255) +#define TAG_PAD ((u_int8_t) 0) +#define TAG_SUBNET_MASK ((u_int8_t) 1) +#define TAG_TIME_OFFSET ((u_int8_t) 2) +#define TAG_GATEWAY ((u_int8_t) 3) +#define TAG_TIME_SERVER ((u_int8_t) 4) +#define TAG_NAME_SERVER ((u_int8_t) 5) +#define TAG_DOMAIN_SERVER ((u_int8_t) 6) +#define TAG_LOG_SERVER ((u_int8_t) 7) +#define TAG_COOKIE_SERVER ((u_int8_t) 8) +#define TAG_LPR_SERVER ((u_int8_t) 9) +#define TAG_IMPRESS_SERVER ((u_int8_t) 10) +#define TAG_RLP_SERVER ((u_int8_t) 11) +#define TAG_HOSTNAME ((u_int8_t) 12) +#define TAG_BOOTSIZE ((u_int8_t) 13) +#define TAG_END ((u_int8_t) 255) /* RFC1497 tags */ -#define TAG_DUMPPATH ((unsigned char) 14) -#define TAG_DOMAINNAME ((unsigned char) 15) -#define TAG_SWAP_SERVER ((unsigned char) 16) -#define TAG_ROOTPATH ((unsigned char) 17) -#define TAG_EXTPATH ((unsigned char) 18) -/* RFC1533 tags */ -#define TAG_IP_FORWARD ((unsigned char) 19) -#define TAG_IP_SRCRT ((unsigned char) 20) -#define TAG_IP_FILTER ((unsigned char) 21) -#define TAG_IP_REASS ((unsigned char) 22) -#define TAG_IP_TTL ((unsigned char) 23) -#define TAG_IP_PMTUTO ((unsigned char) 24) -#define TAG_IP_PMTUPTAB ((unsigned char) 25) -#define TAG_IPIF_MTU ((unsigned char) 26) -#define TAG_IPIF_LSUBNET ((unsigned char) 27) -#define TAG_IPIF_BADDR ((unsigned char) 28) -#define TAG_IPIF_MDISC ((unsigned char) 29) -#define TAG_IPIF_MSUPP ((unsigned char) 30) -#define TAG_IPIF_RDISC ((unsigned char) 31) -#define TAG_IPIF_RSOLADDR ((unsigned char) 32) -#define TAG_IPIF_SROUTE ((unsigned char) 33) -#define TAG_LINK_TRAILER ((unsigned char) 34) -#define TAG_LINK_ARPTO ((unsigned char) 35) -#define TAG_LINK_ETHER802 ((unsigned char) 36) -#define TAG_TCP_DEFTTL ((unsigned char) 37) -#define TAG_TCP_KAINT ((unsigned char) 38) -#define TAG_TCP_KAGARBAGE ((unsigned char) 39) -#define TAG_APP_NISDOM ((unsigned char) 40) -#define TAG_APP_NISOPT ((unsigned char) 41) -#define TAG_APP_NTPSRV ((unsigned char) 42) -#define TAG_VENDOR ((unsigned char) 43) -#define TAG_APP_NB_NS_SERVER ((unsigned char) 44) -#define TAG_APP_NB_DD_SERVER ((unsigned char) 45) -#define TAG_APP_NB_NODETYPE ((unsigned char) 46) -#define TAG_APP_NB_SCOPE ((unsigned char) 47) -#define TAG_APP_X_FS ((unsigned char) 48) -#define TAG_APP_X_DM ((unsigned char) 49) -#define TAG_APP_NISPDOM ((unsigned char) 64) -#define TAG_APP_NISPSRV ((unsigned char) 65) -#define TAG_APP_MIPHA ((unsigned char) 68) -#define TAG_APP_SMTPSRV ((unsigned char) 69) -#define TAG_APP_POP3SRV ((unsigned char) 70) -#define TAG_APP_NNTPSRV ((unsigned char) 71) -#define TAG_APP_HTTPSRV ((unsigned char) 72) -#define TAG_APP_FINGERSRV ((unsigned char) 73) -#define TAG_APP_IRCSRV ((unsigned char) 74) -#define TAG_APP_STREETTALKSRV ((unsigned char) 75) -#define TAG_APP_STREETTALKDA ((unsigned char) 76) -/* (post-)RFC1533 DHCP extensions */ -#define TAG_DHCP_REQIPADDR ((unsigned char) 50) -#define TAG_DHCP_LEASETIME ((unsigned char) 51) -#define TAG_DHCP_OVERLOAD ((unsigned char) 52) -#define TAG_DHCP_TFTPSRV ((unsigned char) 66) -#define TAG_DHCP_BOOTFILE ((unsigned char) 67) -#define TAG_DHCP_MSGTYP ((unsigned char) 53) -#define TAG_DHCP_SRVID ((unsigned char) 54) -#define TAG_DHCP_PRMREQ ((unsigned char) 55) -#define TAG_DHCP_MSG ((unsigned char) 56) -#define TAG_DHCP_MAXSIZ ((unsigned char) 57) -#define TAG_DHCP_T1 ((unsigned char) 58) -#define TAG_DHCP_T2 ((unsigned char) 59) -#define TAG_DHCP_CLASSID ((unsigned char) 60) -#define TAG_DHCP_CLIENTID ((unsigned char) 61) - +#define TAG_DUMPPATH ((u_int8_t) 14) +#define TAG_DOMAINNAME ((u_int8_t) 15) +#define TAG_SWAP_SERVER ((u_int8_t) 16) +#define TAG_ROOTPATH ((u_int8_t) 17) +#define TAG_EXTPATH ((u_int8_t) 18) +/* RFC2132 */ +#define TAG_IP_FORWARD ((u_int8_t) 19) +#define TAG_NL_SRCRT ((u_int8_t) 20) +#define TAG_PFILTERS ((u_int8_t) 21) +#define TAG_REASS_SIZE ((u_int8_t) 22) +#define TAG_DEF_TTL ((u_int8_t) 23) +#define TAG_MTU_TIMEOUT ((u_int8_t) 24) +#define TAG_MTU_TABLE ((u_int8_t) 25) +#define TAG_INT_MTU ((u_int8_t) 26) +#define TAG_LOCAL_SUBNETS ((u_int8_t) 27) +#define TAG_BROAD_ADDR ((u_int8_t) 28) +#define TAG_DO_MASK_DISC ((u_int8_t) 29) +#define TAG_SUPPLY_MASK ((u_int8_t) 30) +#define TAG_DO_RDISC ((u_int8_t) 31) +#define TAG_RTR_SOL_ADDR ((u_int8_t) 32) +#define TAG_STATIC_ROUTE ((u_int8_t) 33) +#define TAG_USE_TRAILERS ((u_int8_t) 34) +#define TAG_ARP_TIMEOUT ((u_int8_t) 35) +#define TAG_ETH_ENCAP ((u_int8_t) 36) +#define TAG_TCP_TTL ((u_int8_t) 37) +#define TAG_TCP_KEEPALIVE ((u_int8_t) 38) +#define TAG_KEEPALIVE_GO ((u_int8_t) 39) +#define TAG_NIS_DOMAIN ((u_int8_t) 40) +#define TAG_NIS_SERVERS ((u_int8_t) 41) +#define TAG_NTP_SERVERS ((u_int8_t) 42) +#define TAG_VENDOR_OPTS ((u_int8_t) 43) +#define TAG_NETBIOS_NS ((u_int8_t) 44) +#define TAG_NETBIOS_DDS ((u_int8_t) 45) +#define TAG_NETBIOS_NODE ((u_int8_t) 46) +#define TAG_NETBIOS_SCOPE ((u_int8_t) 47) +#define TAG_XWIN_FS ((u_int8_t) 48) +#define TAG_XWIN_DM ((u_int8_t) 49) +#define TAG_NIS_P_DOMAIN ((u_int8_t) 64) +#define TAG_NIS_P_SERVERS ((u_int8_t) 65) +#define TAG_MOBILE_HOME ((u_int8_t) 68) +#define TAG_SMPT_SERVER ((u_int8_t) 69) +#define TAG_POP3_SERVER ((u_int8_t) 70) +#define TAG_NNTP_SERVER ((u_int8_t) 71) +#define TAG_WWW_SERVER ((u_int8_t) 72) +#define TAG_FINGER_SERVER ((u_int8_t) 73) +#define TAG_IRC_SERVER ((u_int8_t) 74) +#define TAG_STREETTALK_SRVR ((u_int8_t) 75) +#define TAG_STREETTALK_STDA ((u_int8_t) 76) +/* DHCP options */ +#define TAG_REQUESTED_IP ((u_int8_t) 50) +#define TAG_IP_LEASE ((u_int8_t) 51) +#define TAG_OPT_OVERLOAD ((u_int8_t) 52) +#define TAG_TFTP_SERVER ((u_int8_t) 66) +#define TAG_BOOTFILENAME ((u_int8_t) 67) +#define TAG_DHCP_MESSAGE ((u_int8_t) 53) +#define TAG_SERVER_ID ((u_int8_t) 54) +#define TAG_PARM_REQUEST ((u_int8_t) 55) +#define TAG_MESSAGE ((u_int8_t) 56) +#define TAG_MAX_MSG_SIZE ((u_int8_t) 57) +#define TAG_RENEWAL_TIME ((u_int8_t) 58) +#define TAG_REBIND_TIME ((u_int8_t) 59) +#define TAG_VENDOR_CLASS ((u_int8_t) 60) +#define TAG_CLIENT_ID ((u_int8_t) 61) +/* RFC 2241 */ +#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 */ +#define TAG_DISABLE_AUTOCONF ((u_int8_t) 116) +/* RFC 2610 */ +#define TAG_SLP_DA ((u_int8_t) 78) +#define TAG_SLP_SCOPE ((u_int8_t) 79) +/* RFC 2937 */ +#define TAG_NS_SEARCH ((u_int8_t) 117) +/* RFC 3011 */ +#define TAG_IP4_SUBNET_SELECT ((u_int8_t) 118) +/* ftp://ftp.isi.edu/.../assignments/bootp-dhcp-extensions */ +#define TAG_USER_CLASS ((u_int8_t) 77) +#define TAG_SLP_NAMING_AUTH ((u_int8_t) 80) +#define TAG_CLIENT_FQDN ((u_int8_t) 81) +#define TAG_AGENT_CIRCUIT ((u_int8_t) 82) +#define TAG_AGENT_REMOTE ((u_int8_t) 83) +#define TAG_AGENT_MASK ((u_int8_t) 84) +#define TAG_TZ_STRING ((u_int8_t) 88) +#define TAG_FQDN_OPTION ((u_int8_t) 89) +#define TAG_AUTH ((u_int8_t) 90) +#define TAG_VINES_SERVERS ((u_int8_t) 91) +#define TAG_SERVER_RANK ((u_int8_t) 92) +#define TAG_CLIENT_ARCH ((u_int8_t) 93) +#define TAG_CLIENT_NDI ((u_int8_t) 94) +#define TAG_CLIENT_GUID ((u_int8_t) 97) +#define TAG_LDAP_URL ((u_int8_t) 95) +#define TAG_6OVER4 ((u_int8_t) 96) +#define TAG_PRINTER_NAME ((u_int8_t) 100) +#define TAG_MDHCP_SERVER ((u_int8_t) 101) +#define TAG_IPX_COMPAT ((u_int8_t) 110) +#define TAG_NETINFO_PARENT ((u_int8_t) 112) +#define TAG_NETINFO_PARENT_TAG ((u_int8_t) 113) +#define TAG_URL ((u_int8_t) 114) +#define TAG_FAILOVER ((u_int8_t) 115) +#define TAG_EXTENDED_REQUEST ((u_int8_t) 126) +#define TAG_EXTENDED_OPTION ((u_int8_t) 127) + + +/* DHCP Message types (values for TAG_DHCP_MESSAGE option) */ +#define DHCPDISCOVER 1 +#define DHCPOFFER 2 +#define DHCPREQUEST 3 +#define DHCPDECLINE 4 +#define DHCPACK 5 +#define DHCPNAK 6 +#define DHCPRELEASE 7 +#define DHCPINFORM 8 /* @@ -152,14 +205,14 @@ struct bootp { */ struct cmu_vend { - unsigned char v_magic[4]; /* magic number */ + u_int8_t v_magic[4]; /* magic number */ u_int32_t v_flags; /* flags/opcodes, etc. */ struct in_addr v_smask; /* Subnet mask */ struct in_addr v_dgate; /* Default gateway */ struct in_addr v_dns1, v_dns2; /* Domain name servers */ struct in_addr v_ins1, v_ins2; /* IEN-116 name servers */ struct in_addr v_ts1, v_ts2; /* Time servers */ - unsigned char v_unused[24]; /* currently unused */ + u_int8_t v_unused[24]; /* currently unused */ }; diff --git a/kame/kame/tcpdump/bpf_dump.c b/kame/kame/tcpdump/bpf_dump.c index 8364325993..4f289a14f9 100644 --- a/kame/kame/tcpdump/bpf_dump.c +++ b/kame/kame/tcpdump/bpf_dump.c @@ -19,20 +19,21 @@ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: bpf_dump.c,v 1.9 96/09/26 23:11:04 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/bpf_dump.c,v 1.14.2.2 2003/11/16 08:51:04 guy Exp $ (LBL)"; #endif -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include #include #include #include "interface.h" -extern void bpf_dump(struct bpf_program *, int); - void bpf_dump(struct bpf_program *p, int option) { diff --git a/kame/kame/tcpdump/chdlc.h b/kame/kame/tcpdump/chdlc.h new file mode 100644 index 0000000000..4fb6e1d4e4 --- /dev/null +++ b/kame/kame/tcpdump/chdlc.h @@ -0,0 +1,27 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/chdlc.h,v 1.1 2000/09/18 05:11:43 guy Exp $ (LBL) */ +/* + * Copyright (c) 1990, 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. + */ + +#define CHDLC_HDRLEN 4 +#define CHDLC_UNICAST 0x0f +#define CHDLC_BCAST 0x8f +#define CHDLC_TYPE_SLARP 0x8035 +#define CHDLC_TYPE_CDP 0x2000 diff --git a/kame/kame/tcpdump/config.guess b/kame/kame/tcpdump/config.guess index e9e44559f8..4c5bde8a28 100755 --- a/kame/kame/tcpdump/config.guess +++ b/kame/kame/tcpdump/config.guess @@ -1,7 +1,10 @@ #! /bin/sh # Attempt to guess a canonical system name. -# Copyright (C) 1992, 93, 94, 95, 1996 Free Software Foundation, Inc. -# +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003 Free Software Foundation, Inc. + +timestamp='2003-10-16' + # 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 # the Free Software Foundation; either version 2 of the License, or @@ -21,59 +24,302 @@ # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. -# Written by Per Bothner . -# The master version of this file is at the FSF in /home/gd/gnu/lib. +# Originally written by Per Bothner . +# Please send patches to . Submit a context +# diff and a properly formatted ChangeLog entry. # # This script attempts to guess a canonical system name similar to # config.sub. If it succeeds, it prints the system name on stdout, and # exits with 0. Otherwise, it exits with 1. # # The plan is that this can be called by configure scripts if you -# don't specify an explicit system type (host/target name). -# -# Only a few systems have been added to this list; please add others -# (but try to keep the structure clean). -# +# don't specify an explicit build system type. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] + +Output the configuration name of the system \`$me' is run on. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.guess ($timestamp) + +Originally written by Per Bothner. +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 +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit 0 ;; + --version | -v ) + echo "$version" ; exit 0 ;; + --help | --h* | -h ) + echo "$usage"; exit 0 ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + * ) + break ;; + esac +done + +if test $# != 0; then + echo "$me: too many arguments$help" >&2 + exit 1 +fi + +trap 'exit 1' 1 2 15 + +# CC_FOR_BUILD -- compiler used by this script. Note that the use of a +# compiler to aid in system detection is discouraged as it requires +# temporary files to be created and, as you can see below, it is a +# headache to deal with in a portable fashion. + +# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still +# use `HOST_CC' if defined, but it is deprecated. + +# Portable tmp directory creation inspired by the Autoconf team. + +set_cc_for_build=' +trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; +trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; +: ${TMPDIR=/tmp} ; + { tmp=`(umask 077 && mktemp -d -q "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; +dummy=$tmp/dummy ; +tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; +case $CC_FOR_BUILD,$HOST_CC,$CC in + ,,) echo "int x;" > $dummy.c ; + for c in cc gcc c89 c99 ; do + if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then + CC_FOR_BUILD="$c"; break ; + fi ; + done ; + if test x"$CC_FOR_BUILD" = x ; then + CC_FOR_BUILD=no_compiler_found ; + fi + ;; + ,,*) CC_FOR_BUILD=$CC ;; + ,*,*) CC_FOR_BUILD=$HOST_CC ;; +esac ;' # This is needed to find uname on a Pyramid OSx when run in the BSD universe. -# (ghazi@noc.rutgers.edu 8/24/94.) +# (ghazi@noc.rutgers.edu 1994-08-24) if (test -f /.attbin/uname) >/dev/null 2>&1 ; then PATH=$PATH:/.attbin ; export PATH fi UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown -UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown -trap 'rm -f dummy.c dummy.o dummy; exit 1' 1 2 15 - # Note: order is significant - the case branches are not exclusive. case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in + *:NetBSD:*:*) + # NetBSD (nbsd) targets should (where applicable) match one or + # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, + # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently + # switched to ELF, *-*-netbsd* would select the old + # object file format. This provides both forward + # compatibility and a consistent mechanism for selecting the + # object file format. + # + # Note: NetBSD doesn't particularly care about the vendor + # portion of the name. We always set it to "unknown". + sysctl="sysctl -n hw.machine_arch" + UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ + /usr/sbin/$sysctl 2>/dev/null || echo unknown)` + case "${UNAME_MACHINE_ARCH}" in + armeb) machine=armeb-unknown ;; + arm*) machine=arm-unknown ;; + sh3el) machine=shl-unknown ;; + sh3eb) machine=sh-unknown ;; + *) machine=${UNAME_MACHINE_ARCH}-unknown ;; + esac + # The Operating System including object format, if it has switched + # to ELF recently, or will in the future. + case "${UNAME_MACHINE_ARCH}" in + arm*|i386|m68k|ns32k|sh3*|sparc|vax) + eval $set_cc_for_build + if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep __ELF__ >/dev/null + then + # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). + # Return netbsd for either. FIX? + os=netbsd + else + os=netbsdelf + fi + ;; + *) + os=netbsd + ;; + esac + # The OS release + # Debian GNU/NetBSD machines have a different userland, and + # thus, need a distinct triplet. However, they do not need + # kernel version information, so it can be replaced with a + # suitable tag, in the style of linux-gnu. + case "${UNAME_VERSION}" in + Debian*) + release='-gnu' + ;; + *) + release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + ;; + esac + # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: + # contains redundant information, the shorter form: + # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. + echo "${machine}-${os}${release}" + exit 0 ;; + amiga:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + arc:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + hp300:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mac68k:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + macppc:OpenBSD:*:*) + echo powerpc-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvme68k:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvme88k:OpenBSD:*:*) + echo m88k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvmeppc:OpenBSD:*:*) + echo powerpc-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + pegasos:OpenBSD:*:*) + echo powerpc-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + pmax:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + sgi:OpenBSD:*:*) + echo mipseb-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + sun3:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + wgrisc:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + *:OpenBSD:*:*) + echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; alpha:OSF1:*:*) + if test $UNAME_RELEASE = "V4.0"; then + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + fi + # According to Compaq, /usr/sbin/psrinfo has been available on + # OSF/1 and Tru64 systems produced since 1995. I hope that + # covers most systems running today. This code pipes the CPU + # types through head -n 1, so we only detect the type of CPU 0. + ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` + case "$ALPHA_CPU_TYPE" in + "EV4 (21064)") + UNAME_MACHINE="alpha" ;; + "EV4.5 (21064)") + UNAME_MACHINE="alpha" ;; + "LCA4 (21066/21068)") + UNAME_MACHINE="alpha" ;; + "EV5 (21164)") + UNAME_MACHINE="alphaev5" ;; + "EV5.6 (21164A)") + UNAME_MACHINE="alphaev56" ;; + "EV5.6 (21164PC)") + UNAME_MACHINE="alphapca56" ;; + "EV5.7 (21164PC)") + UNAME_MACHINE="alphapca57" ;; + "EV6 (21264)") + UNAME_MACHINE="alphaev6" ;; + "EV6.7 (21264A)") + UNAME_MACHINE="alphaev67" ;; + "EV6.8CB (21264C)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8AL (21264B)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8CX (21264D)") + UNAME_MACHINE="alphaev68" ;; + "EV6.9A (21264/EV69A)") + UNAME_MACHINE="alphaev69" ;; + "EV7 (21364)") + UNAME_MACHINE="alphaev7" ;; + "EV7.9 (21364A)") + UNAME_MACHINE="alphaev79" ;; + esac # A Vn.n version is a released version. # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. - echo alpha-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//'` + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + exit 0 ;; + Alpha*:OpenVMS:*:*) + echo alpha-hp-vms + exit 0 ;; + Alpha\ *:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # Should we change UNAME_MACHINE based on the output of uname instead + # of the specific Alpha model? + echo alpha-pc-interix exit 0 ;; 21064:Windows_NT:50:3) echo alpha-dec-winnt3.5 exit 0 ;; Amiga*:UNIX_System_V:4.0:*) - echo m68k-cbm-sysv4 + echo m68k-unknown-sysv4 exit 0;; - amiga:NetBSD:*:*) - echo m68k-cbm-netbsd${UNAME_RELEASE} - exit 0 ;; - amiga:OpenBSD:*:*) - echo m68k-cbm-openbsd${UNAME_RELEASE} - exit 0 ;; + *:[Aa]miga[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-amigaos + exit 0 ;; + *:[Mm]orph[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-morphos + exit 0 ;; + *:OS/390:*:*) + echo i370-ibm-openedition + exit 0 ;; + *:OS400:*:*) + echo powerpc-ibm-os400 + exit 0 ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) echo arm-acorn-riscix${UNAME_RELEASE} exit 0;; - Pyramid*:OSx*:*:*|MIS*:OSx*:*:*) + SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) + echo hppa1.1-hitachi-hiuxmpp + exit 0;; + Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. if test "`(/bin/universe) 2>/dev/null`" = att ; then echo pyramid-pyramid-sysv3 @@ -81,9 +327,19 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in echo pyramid-pyramid-bsd fi exit 0 ;; - NILE:*:*:dcosx) + NILE*:*:*:dcosx) echo pyramid-pyramid-svr4 exit 0 ;; + DRS?6000:unix:4.0:6*) + echo sparc-icl-nx6 + exit 0 ;; + DRS?6000:UNIX_SV:4.2*:7*) + case `/usr/bin/uname -p` in + sparc) echo sparc-icl-nx7 && exit 0 ;; + esac ;; + sun4H:SunOS:5.*:*) + echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit 0 ;; @@ -108,27 +364,47 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in sun3*:SunOS:*:*) echo m68k-sun-sunos${UNAME_RELEASE} exit 0 ;; + sun*:*:4.2BSD:*) + UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 + case "`/bin/arch`" in + sun3) + echo m68k-sun-sunos${UNAME_RELEASE} + ;; + sun4) + echo sparc-sun-sunos${UNAME_RELEASE} + ;; + esac + exit 0 ;; aushp:SunOS:*:*) echo sparc-auspex-sunos${UNAME_RELEASE} exit 0 ;; - atari*:NetBSD:*:*) - echo m68k-atari-netbsd${UNAME_RELEASE} - exit 0 ;; - atari*:OpenBSD:*:*) - echo m68k-atari-openbsd${UNAME_RELEASE} - exit 0 ;; - sun3*:NetBSD:*:*) - echo m68k-sun-netbsd${UNAME_RELEASE} - exit 0 ;; - sun3*:OpenBSD:*:*) - echo m68k-sun-openbsd${UNAME_RELEASE} - exit 0 ;; - mac68k:NetBSD:*:*) - echo m68k-apple-netbsd${UNAME_RELEASE} - exit 0 ;; - mac68k:OpenBSD:*:*) - echo m68k-apple-openbsd${UNAME_RELEASE} + # The situation for MiNT is a little confusing. The machine name + # can be virtually everything (everything which is not + # "atarist" or "atariste" at least should have a processor + # > m68000). The system name ranges from "MiNT" over "FreeMiNT" + # to the lowercase version "mint" (or "freemint"). Finally + # the system name "TOS" denotes a system which is actually not + # MiNT. But MiNT is downward compatible to TOS, so this should + # be no problem. + atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit 0 ;; + atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit 0 ;; + *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} exit 0 ;; + milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) + echo m68k-milan-mint${UNAME_RELEASE} + exit 0 ;; + hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) + echo m68k-hades-mint${UNAME_RELEASE} + exit 0 ;; + *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) + echo m68k-unknown-mint${UNAME_RELEASE} + exit 0 ;; powerpc:machten:*:*) echo powerpc-apple-machten${UNAME_RELEASE} exit 0 ;; @@ -141,9 +417,18 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in VAX*:ULTRIX*:*:*) echo vax-dec-ultrix${UNAME_RELEASE} exit 0 ;; + 2020:CLIX:*:* | 2430:CLIX:*:*) + echo clipper-intergraph-clix${UNAME_RELEASE} + exit 0 ;; mips:*:*:UMIPS | mips:*:*:RISCos) - sed 's/^ //' << EOF >dummy.c - int main (argc, argv) int argc; char **argv; { + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c +#ifdef __cplusplus +#include /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif #if defined (host_mips) && defined (MIPSEB) #if defined (SYSTYPE_SYSV) printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); @@ -158,12 +443,20 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in exit (-1); } EOF - ${CC-cc} 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 + $CC_FOR_BUILD -o $dummy $dummy.c \ + && $dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \ + && exit 0 echo mips-mips-riscos${UNAME_RELEASE} exit 0 ;; + Motorola:PowerMAX_OS:*:*) + echo powerpc-motorola-powermax + exit 0 ;; + Motorola:*:4.3:PL8-*) + echo powerpc-harris-powermax + exit 0 ;; + Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) + echo powerpc-harris-powermax + exit 0 ;; Night_Hawk:Power_UNIX:*:*) echo powerpc-harris-powerunix exit 0 ;; @@ -179,15 +472,18 @@ EOF AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures UNAME_PROCESSOR=`/usr/bin/uname -p` - if [ $UNAME_PROCESSOR = mc88100 -o $UNAME_PROCESSOR = mc88110 ] ; then - if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx \ - -o ${TARGET_BINARY_INTERFACE}x = x ] ; then + if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] + then + if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ + [ ${TARGET_BINARY_INTERFACE}x = x ] + then echo m88k-dg-dgux${UNAME_RELEASE} - else + else echo m88k-dg-dguxbcs${UNAME_RELEASE} + fi + else + echo i586-dg-dgux${UNAME_RELEASE} fi - else echo i586-dg-dgux${UNAME_RELEASE} - fi exit 0 ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) echo m88k-dolphin-sysv3 @@ -208,12 +504,21 @@ 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 + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c #include main() @@ -224,8 +529,7 @@ EOF exit(0); } EOF - ${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0 - rm -f dummy.c dummy + $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0 echo rs6000-ibm-aix3.2.5 elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then echo rs6000-ibm-aix3.2.4 @@ -233,8 +537,9 @@ EOF echo rs6000-ibm-aix3.2 fi exit 0 ;; - *:AIX:*:4) - if /usr/sbin/lsattr -EHl proc0 | grep POWER >/dev/null 2>&1; then + *:AIX:*:[45]) + IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` + if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then IBM_ARCH=rs6000 else IBM_ARCH=powerpc @@ -242,7 +547,7 @@ 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 ;; @@ -252,7 +557,7 @@ EOF ibmrt:4.4BSD:*|romp-ibm:BSD:*) echo romp-ibm-bsd4.4 exit 0 ;; - ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC NetBSD and + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to exit 0 ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) @@ -267,18 +572,85 @@ EOF hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) echo m68k-hp-bsd4.4 exit 0 ;; - 9000/[3478]??:HP-UX:*:*) + 9000/[34678]??:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` case "${UNAME_MACHINE}" in 9000/31? ) HP_ARCH=m68000 ;; 9000/[34]?? ) HP_ARCH=m68k ;; - 9000/7?? | 9000/8?[1679] ) HP_ARCH=hppa1.1 ;; - 9000/8?? ) HP_ARCH=hppa1.0 ;; + 9000/[678][0-9][0-9]) + if [ -x /usr/bin/getconf ]; then + sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` + sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + case "${sc_cpu_version}" in + 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 + 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 + 532) # CPU_PA_RISC2_0 + case "${sc_kernel_bits}" in + 32) HP_ARCH="hppa2.0n" ;; + 64) HP_ARCH="hppa2.0w" ;; + '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 + esac ;; + esac + fi + if [ "${HP_ARCH}" = "" ]; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + + #define _HPUX_SOURCE + #include + #include + + int main () + { + #if defined(_SC_KERNEL_BITS) + long bits = sysconf(_SC_KERNEL_BITS); + #endif + long cpu = sysconf (_SC_CPU_VERSION); + + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1"); break; + case CPU_PA_RISC2_0: + #if defined(_SC_KERNEL_BITS) + switch (bits) + { + case 64: puts ("hppa2.0w"); break; + case 32: puts ("hppa2.0n"); break; + default: puts ("hppa2.0"); break; + } break; + #else /* !defined(_SC_KERNEL_BITS) */ + puts ("hppa2.0"); break; + #endif + default: puts ("hppa1.0"); break; + } + exit (0); + } +EOF + (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` + test -z "$HP_ARCH" && HP_ARCH=hppa + fi ;; esac - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + if [ ${HP_ARCH} = "hppa2.0w" ] + then + # avoid double evaluation of $set_cc_for_build + test -n "$CC_FOR_BUILD" || eval $set_cc_for_build + if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E -) | grep __LP64__ >/dev/null + then + HP_ARCH="hppa2.0w" + else + HP_ARCH="hppa64" + fi + fi 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 + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c #include int main () @@ -303,8 +675,7 @@ EOF exit (0); } EOF - ${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0 - rm -f dummy.c dummy + $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0 echo unknown-hitachi-hiuxwe2 exit 0 ;; 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) @@ -313,13 +684,16 @@ EOF 9000/8??:4.3bsd:*:*) echo hppa1.0-hp-bsd exit 0 ;; + *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) + echo hppa1.0-hp-mpeix + exit 0 ;; hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) echo hppa1.1-hp-osf exit 0 ;; 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 @@ -347,129 +721,328 @@ EOF C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) echo c4-convex-bsd exit 0 ;; - CRAY*X-MP:*:*:*) - echo xmp-cray-unicos - exit 0 ;; CRAY*Y-MP:*:*:*) - echo ymp-cray-unicos${UNAME_RELEASE} + echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit 0 ;; CRAY*[A-Z]90:*:*:*) echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ - -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ + -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ + -e 's/\.[^.]*$/.X/' exit 0 ;; CRAY*TS:*:*:*) - echo t90-cray-unicos${UNAME_RELEASE} + echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit 0 ;; - CRAY-2:*:*:*) - echo cray2-cray-unicos - exit 0 ;; - F300:UNIX_System_V:*:*) - FUJITSU_SYS=`uname -p | tr [A-Z] [a-z] | sed -e 's/\///'` + CRAY*T3E:*:*:*) + echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY*SV1:*:*:*) + echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + *:UNICOS/mp:*:*) + echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + 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 ;; - hp3[0-9][05]:NetBSD:*:*) - echo m68k-hp-netbsd${UNAME_RELEASE} + 5000:UNIX_System_V:4.*:*) + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` + echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit 0 ;; - hp3[0-9][05]:OpenBSD:*:*) - echo m68k-hp-openbsd${UNAME_RELEASE} - exit 0 ;; - i?86:BSD/386:*:* | *:BSD/OS:*:*) + i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} exit 0 ;; - *:FreeBSD:*:*) - echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + sparc*:BSD/OS:*:*) + echo sparc-unknown-bsdi${UNAME_RELEASE} exit 0 ;; - *:NetBSD:*:*) - echo ${UNAME_MACHINE}-unknown-netbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + *:BSD/OS:*:*) + echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} exit 0 ;; - *:OpenBSD:*:*) - echo ${UNAME_MACHINE}-unknown-openbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + *:FreeBSD:*:*) + # Determine whether the default compiler uses glibc. + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + #if __GLIBC__ >= 2 + LIBC=gnu + #else + LIBC= + #endif +EOF + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` + # GNU/KFreeBSD systems have a "k" prefix to indicate we are using + # FreeBSD's kernel, but not the complete OS. + case ${LIBC} in gnu) kernel_only='k' ;; esac + echo ${UNAME_MACHINE}-unknown-${kernel_only}freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC} exit 0 ;; i*:CYGWIN*:*) - echo i386-pc-cygwin32 + echo ${UNAME_MACHINE}-pc-cygwin + exit 0 ;; + i*:MINGW*:*) + echo ${UNAME_MACHINE}-pc-mingw32 + exit 0 ;; + i*:PW*:*) + echo ${UNAME_MACHINE}-pc-pw32 + exit 0 ;; + x86:Interix*:[34]*) + echo i586-pc-interix${UNAME_RELEASE}|sed -e 's/\..*//' + exit 0 ;; + [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) + echo i${UNAME_MACHINE}-pc-mks + exit 0 ;; + i*:Windows_NT*:* | Pentium*:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we + # UNAME_MACHINE based on the output of uname instead of i386? + echo i586-pc-interix + exit 0 ;; + i*:UWIN*:*) + echo ${UNAME_MACHINE}-pc-uwin exit 0 ;; p*:CYGWIN*:*) - echo powerpcle-unknown-cygwin32 + echo powerpcle-unknown-cygwin exit 0 ;; prep*:SunOS:5.*:*) echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit 0 ;; *:GNU:*:*) - echo `echo ${UNAME_MACHINE}|sed -e 's,/.*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + # the GNU system + echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + exit 0 ;; + *:GNU/*:*:*) + # other systems with GNU libc and userland + echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu + exit 0 ;; + i*86:Minix:*:*) + echo ${UNAME_MACHINE}-pc-minix + exit 0 ;; + arm*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + cris:Linux:*:*) + echo cris-axis-linux-gnu + exit 0 ;; + ia64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + m68*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + mips:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef mips + #undef mipsel + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=mipsel + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=mips + #else + CPU= + #endif + #endif +EOF + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` + test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0 + ;; + mips64:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef mips64 + #undef mips64el + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=mips64el + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=mips64 + #else + CPU= + #endif + #endif +EOF + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` + test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0 + ;; + ppc:Linux:*:*) + echo powerpc-unknown-linux-gnu + exit 0 ;; + ppc64:Linux:*:*) + echo powerpc64-unknown-linux-gnu + exit 0 ;; + alpha:Linux:*:*) + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in + EV5) UNAME_MACHINE=alphaev5 ;; + EV56) UNAME_MACHINE=alphaev56 ;; + PCA56) UNAME_MACHINE=alphapca56 ;; + PCA57) UNAME_MACHINE=alphapca56 ;; + EV6) UNAME_MACHINE=alphaev6 ;; + EV67) UNAME_MACHINE=alphaev67 ;; + EV68*) UNAME_MACHINE=alphaev68 ;; + esac + objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null + if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi + 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 ;; + sh64*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + sh*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu exit 0 ;; - *:Linux:*:*) + 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. - ld_help_string=`ld --help 2>&1` - if echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: elf_i.86"; then - echo "${UNAME_MACHINE}-pc-linux-gnu" ; exit 0 - elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: i.86linux"; then - echo "${UNAME_MACHINE}-pc-linux-gnuaout" ; exit 0 - elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: i.86coff"; then - echo "${UNAME_MACHINE}-pc-linux-gnucoff" ; exit 0 - elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: m68kelf"; then - echo "${UNAME_MACHINE}-unknown-linux-gnu" ; exit 0 - elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: m68klinux"; then - echo "${UNAME_MACHINE}-unknown-linux-gnuaout" ; exit 0 - elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: elf32ppc"; then - echo "powerpc-unknown-linux-gnu" ; exit 0 - elif test "${UNAME_MACHINE}" = "alpha" ; then - echo alpha-unknown-linux-gnu ; exit 0 - elif test "${UNAME_MACHINE}" = "sparc" ; then - echo sparc-unknown-linux-gnu ; 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. - test ! -d /usr/lib/ldscripts/. \ - && echo "${UNAME_MACHINE}-pc-linux-gnuoldld" && exit 0 - # Determine whether the default compiler is a.out or elf - cat >dummy.c <&1 \ + | sed -ne '/supported targets:/!d + s/[ ][ ]*/ /g + s/.*supported targets: *// + s/ .*// + p'` + case "$ld_supported_targets" in + elf32-i386) + TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" + ;; + a.out-i386-linux) + echo "${UNAME_MACHINE}-pc-linux-gnuaout" + exit 0 ;; + coff-i386) + echo "${UNAME_MACHINE}-pc-linux-gnucoff" + exit 0 ;; + "") + # Either a pre-BFD a.out linker (linux-gnuoldld) or + # one that does not give us useful --help. + echo "${UNAME_MACHINE}-pc-linux-gnuoldld" + exit 0 ;; + esac + # Determine whether the default compiler is a.out or elf + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + #ifdef __ELF__ + # ifdef __GLIBC__ + # if __GLIBC__ >= 2 + LIBC=gnu + # else + LIBC=gnulibc1 + # endif + # else + LIBC=gnulibc1 + # endif + #else + #ifdef __INTEL_COMPILER + LIBC=gnu + #else + LIBC=gnuaout + #endif + #endif + #ifdef __dietlibc__ + LIBC=dietlibc + #endif EOF - ${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy "${UNAME_MACHINE}" && rm dummy.c dummy && exit 0 - rm -f dummy.c dummy - fi ;; -# 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*:*) + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` + test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0 + test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0 + ;; + i*86:DYNIX/ptx:4*:*) + # 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. echo i386-sequent-sysv4 exit 0 ;; - i?86:*:4.*:* | i?86:SYSTEM_V:4.*:*) + 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, + # I just have to hope. -- rms. + # Use sysv4.2uw... so that sysv4* matches it. + echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} + exit 0 ;; + 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 ;; + i*86:XTS-300:*:STOP) + echo ${UNAME_MACHINE}-unknown-stop + exit 0 ;; + i*86:atheos:*:*) + echo ${UNAME_MACHINE}-unknown-atheos + exit 0 ;; + i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) + echo i386-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + i*86:*DOS:*:*) + echo ${UNAME_MACHINE}-pc-msdosdjgpp + exit 0 ;; + 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_RELEASE} + echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} else - echo ${UNAME_MACHINE}-pc-sysv${UNAME_RELEASE} + echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} fi exit 0 ;; - i?86:*:3.2:*) + i*86:*:5:[78]*) + case `/bin/uname -X | grep "^Machine"` in + *486*) UNAME_MACHINE=i486 ;; + *Pentium) UNAME_MACHINE=i586 ;; + *Pent*|*Celeron) UNAME_MACHINE=i686 ;; + esac + echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + exit 0 ;; + i*86:*:3.2:*) if test -f /usr/options/cb.name; then UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then - UNAME_REL=`(/bin/uname -X|egrep Release|sed -e 's/.*= //')` - (/bin/uname -X|egrep i80486 >/dev/null) && UNAME_MACHINE=i486 - (/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \ + UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` + (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 + (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ && UNAME_MACHINE=i586 + (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ + && UNAME_MACHINE=i686 + (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ + && UNAME_MACHINE=i686 echo ${UNAME_MACHINE}-pc-sco$UNAME_REL else echo ${UNAME_MACHINE}-pc-sysv32 fi exit 0 ;; + pc:*:*:*) + # Left here for compatibility: + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i386. + echo i386-pc-msdosdjgpp + exit 0 ;; Intel:Mach:3*:*) echo i386-pc-mach3 exit 0 ;; @@ -487,9 +1060,15 @@ EOF # "miniframe" echo m68010-convergent-sysv exit 0 ;; + mc68k:UNIX:SYSTEM5:3.51m) + echo m68k-convergent-sysv + exit 0 ;; + M680?0:D-NIX:5.3:*) + echo m68k-diab-dnix + exit 0 ;; M68*:*:R3V[567]*:*) test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;; - 3[34]??:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 4850:*:4.0:3.0) + 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0) OS_REL='' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` @@ -500,24 +1079,27 @@ 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.*:*) - 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 ;; + RM*:ReliantUNIX-*:*:*) + echo mips-sni-sysv4 + exit 0 ;; RM*:SINIX-*:*:*) echo mips-sni-sysv4 exit 0 ;; @@ -529,6 +1111,10 @@ EOF echo ns32k-sni-sysv fi exit 0 ;; + PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says + echo i586-unisys-sysv4 + exit 0 ;; *:UNIX_System_V:4*:FTX*) # From Gerald Hewes . # How about differentiating between stratus architectures? -djm @@ -538,26 +1124,119 @@ EOF # From seanf@swdc.stratus.com. echo i860-stratus-sysv4 exit 0 ;; + *:VOS:*:*) + # From Paul.Green@stratus.com. + echo hppa1.1-stratus-vos + exit 0 ;; mc68*:A/UX:*:*) echo m68k-apple-aux${UNAME_RELEASE} exit 0 ;; - R3000:*System_V*:*:* | R4000:UNIX_SYSV:*:*) + news*:NEWS-OS:6*:*) + echo mips-sony-newsos6 + exit 0 ;; + R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) if [ -d /usr/nec ]; then echo mips-nec-sysv${UNAME_RELEASE} else echo mips-unknown-sysv${UNAME_RELEASE} fi exit 0 ;; - PENTIUM:CPunix:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort - # says - echo i586-unisys-sysv4 - exit 0 ;; + BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. + echo powerpc-be-beos + exit 0 ;; + BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. + echo powerpc-apple-beos + exit 0 ;; + BePC:BeOS:*:*) # BeOS running on Intel PC compatible. + echo i586-pc-beos + exit 0 ;; + SX-4:SUPER-UX:*:*) + echo sx4-nec-superux${UNAME_RELEASE} + exit 0 ;; + SX-5:SUPER-UX:*:*) + echo sx5-nec-superux${UNAME_RELEASE} + exit 0 ;; + SX-6:SUPER-UX:*:*) + echo sx6-nec-superux${UNAME_RELEASE} + exit 0 ;; + Power*:Rhapsody:*:*) + echo powerpc-apple-rhapsody${UNAME_RELEASE} + exit 0 ;; + *:Rhapsody:*:*) + echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} + exit 0 ;; + *:Darwin:*:*) + case `uname -p` in + *86) UNAME_PROCESSOR=i686 ;; + powerpc) UNAME_PROCESSOR=powerpc ;; + esac + echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} + exit 0 ;; + *:procnto*:*:* | *:QNX:[0123456789]*:*) + UNAME_PROCESSOR=`uname -p` + if test "$UNAME_PROCESSOR" = "x86"; then + UNAME_PROCESSOR=i386 + UNAME_MACHINE=pc + fi + echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} + exit 0 ;; + *:QNX:*:4*) + echo i386-pc-qnx + exit 0 ;; + NSR-[DGKLNPTVWY]:NONSTOP_KERNEL:*:*) + echo nsr-tandem-nsk${UNAME_RELEASE} + exit 0 ;; + *:NonStop-UX:*:*) + echo mips-compaq-nonstopux + exit 0 ;; + BS2000:POSIX*:*:*) + echo bs2000-siemens-sysv + exit 0 ;; + DS/*:UNIX_System_V:*:*) + echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} + exit 0 ;; + *:Plan9:*:*) + # "uname -m" is not consistent, so use $cputype instead. 386 + # is converted to i386 for consistency with other x86 + # operating systems. + if test "$cputype" = "386"; then + UNAME_MACHINE=i386 + else + UNAME_MACHINE="$cputype" + fi + echo ${UNAME_MACHINE}-unknown-plan9 + 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 ;; + SEI:*:*:SEIUX) + echo mips-sei-seiux${UNAME_RELEASE} + exit 0 ;; + *:DRAGONFLY:*:*) + echo ${UNAME_MACHINE}-unknown-dragonfly${UNAME_RELEASE} + exit 0 ;; esac #echo '(No uname command or uname output not recognized.)' 1>&2 #echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 -cat >dummy.c <$dummy.c < # include @@ -595,7 +1274,10 @@ main () #endif int version; version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; - printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); exit (0); #endif @@ -640,11 +1322,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 +# 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) @@ -655,8 +1350,7 @@ main () } EOF -${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy && rm dummy.c dummy && exit 0 -rm -f dummy.c dummy +$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && $dummy && exit 0 # Apollos put the system type in the environment. @@ -688,6 +1382,48 @@ then esac fi -#echo '(Unable to guess system type)' 1>&2 +cat >&2 < in order to provide the needed +information to handle your system. + +config.guess timestamp = $timestamp + +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null` + +hostinfo = `(hostinfo) 2>/dev/null` +/bin/universe = `(/bin/universe) 2>/dev/null` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` +/bin/arch = `(/bin/arch) 2>/dev/null` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` + +UNAME_MACHINE = ${UNAME_MACHINE} +UNAME_RELEASE = ${UNAME_RELEASE} +UNAME_SYSTEM = ${UNAME_SYSTEM} +UNAME_VERSION = ${UNAME_VERSION} +EOF exit 1 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/kame/kame/tcpdump/config.h.in b/kame/kame/tcpdump/config.h.in new file mode 100644 index 0000000000..a8d564d6e9 --- /dev/null +++ b/kame/kame/tcpdump/config.h.in @@ -0,0 +1,293 @@ +/* config.h.in. Generated from configure.in by autoheader. */ +/* "generated automatically" means DO NOT MAKE CHANGES TO config.h.in -- + * make them to acconfig.h and rerun autoheader */ + +/* Define if you have SSLeay 0.9.0b with the buggy cast128. */ +#undef HAVE_BUGGY_CAST128 + +/* Define if you enable IPv6 support */ +#undef INET6 + +/* Define if you enable support for the libsmi. */ +#undef LIBSMI + +/* Define if you have the header file. */ +#undef HAVE_SMI_H + +/* define if you have struct __res_state_ext */ +#undef HAVE_RES_STATE_EXT + +/* define if your struct __res_state has the nsort member */ +#undef HAVE_NEW_RES_STATE + + +/* + * define if struct ether_header.ether_dhost is a struct with ether_addr_octet + */ +#undef ETHER_HEADER_HAS_EA + +/* define if struct ether_arp contains arp_xsha */ +#undef ETHER_ARP_HAS_X + +/* define if you have the addrinfo function. */ +#undef HAVE_ADDRINFO + +/* define if you need to include missing/addrinfoh.h. */ +#undef NEED_ADDRINFO_H + +/* define ifyou have the h_errno variable. */ +#undef HAVE_H_ERRNO + +/* define if IN6ADDRSZ is defined (XXX not used!) */ +#undef HAVE_IN6ADDRSZ + +/* define if INADDRSZ is defined (XXX not used!) */ +#undef HAVE_INADDRSZ + +/* define if this is a development version, to use additional prototypes. */ +#undef HAVE_OS_PROTO_H + +/* define if defines __P() */ +#undef HAVE_PORTABLE_PROTOTYPE + +/* define if RES_USE_INET6 is defined */ +#undef HAVE_RES_USE_INET6 + +/* define if struct sockaddr has the sa_len member */ +#undef HAVE_SOCKADDR_SA_LEN + +/* 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 libpcap has pcap_version */ +#undef HAVE_PCAP_VERSION + +/* define if libpcap has pcap_debug */ +#undef HAVE_PCAP_DEBUG + +/* define if libpcap has yydebug */ +#undef HAVE_YYDEBUG + +/* define if libpcap has pcap_list_datalinks() */ +#undef HAVE_PCAP_LIST_DATALINKS + +/* define if libpcap has pcap_set_datalink() */ +#undef HAVE_PCAP_SET_DATALINK + +/* define if libpcap has pcap_datalink_name_to_val() */ +#undef HAVE_PCAP_DATALINK_NAME_TO_VAL + +/* define if libpcap has pcap_datalink_val_to_description() */ +#undef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION + +/* define if unaligned memory accesses fail */ +#undef LBL_ALIGN + +/* The successful return value from signal (?)XXX */ +#undef RETSIGVAL + +/* Define this on IRIX */ +#undef _BSD_SIGNALS + +/* For HP/UX ANSI compiler? */ +#undef _HPUX_SOURCE + +/* AIX hack. */ +#undef _SUN + +/* Workaround for missing sized types */ +/* XXX this should move to the more standard uint*_t */ +#undef int8_t +#undef int16_t +#undef int32_t +#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 + +/* Define if you have the dnet_htoa function. */ +#undef HAVE_DNET_HTOA + +/* Define if you have a dnet_htoa declaration in . */ +#undef HAVE_NETDNET_DNETDB_H_DNET_HTOA + +/* Define to 1 if you have the `bpf_dump' function. */ +#undef HAVE_BPF_DUMP + +/* Define to 1 if you have the `ether_ntohost' function. */ +#undef HAVE_ETHER_NTOHOST + +/* Define to 1 if you have the header file. */ +#undef HAVE_FCNTL_H + +/* Define to 1 if you have the `getaddrinfo' function. */ +#undef HAVE_GETADDRINFO + +/* Define to 1 if you have the `getnameinfo' function. */ +#undef HAVE_GETNAMEINFO + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the `crypto' library (-lcrypto). */ +#undef HAVE_LIBCRYPTO + +/* Define to 1 if you have the `rpc' library (-lrpc). */ +#undef HAVE_LIBRPC + +/* Define to 1 if you have the `smi' library (-lsmi). */ +#undef HAVE_LIBSMI + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETDNET_DNETDB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETINET_ETHER_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETINET_IF_ETHER_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_OPENSSL_EVP_H + +/* Define to 1 if you have the `pcap_breakloop' function. */ +#undef HAVE_PCAP_BREAKLOOP + +/* Define to 1 if you have the `pcap_dump_flush' function. */ +#undef HAVE_PCAP_DUMP_FLUSH + +/* Define to 1 if you have the `pcap_findalldevs' function. */ +#undef HAVE_PCAP_FINDALLDEVS + +/* Define to 1 if the system has the type `pcap_if_t'. */ +#undef HAVE_PCAP_IF_T + +/* Define to 1 if you have the `pcap_lib_version' function. */ +#undef HAVE_PCAP_LIB_VERSION + +/* Define to 1 if you have the `pfopen' function. */ +#undef HAVE_PFOPEN + +/* Define to 1 if you have the header file. */ +#undef HAVE_RPC_RPCENT_H + +/* Define to 1 if you have the `setlinebuf' function. */ +#undef HAVE_SETLINEBUF + +/* Define to 1 if you have the `sigaction' function. */ +#undef HAVE_SIGACTION + +/* Define to 1 if you have the `sigset' function. */ +#undef HAVE_SIGSET + +/* Define to 1 if you have the header file. */ +#undef HAVE_SMI_H + +/* Define to 1 if you have the `snprintf' function. */ +#undef HAVE_SNPRINTF + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the `strcasecmp' function. */ +#undef HAVE_STRCASECMP + +/* Define to 1 if you have the `strdup' function. */ +#undef HAVE_STRDUP + +/* Define to 1 if you have the `strftime' function. */ +#undef HAVE_STRFTIME + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the `strlcat' function. */ +#undef HAVE_STRLCAT + +/* Define to 1 if you have the `strlcpy' function. */ +#undef HAVE_STRLCPY + +/* Define to 1 if you have the `strsep' function. */ +#undef HAVE_STRSEP + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Define to 1 if you have the `vfprintf' function. */ +#undef HAVE_VFPRINTF + +/* Define to 1 if you have the `vsnprintf' function. */ +#undef HAVE_VSNPRINTF + +/* define if your compiler has __attribute__ */ +#undef HAVE___ATTRIBUTE__ + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define as the return type of signal handlers (`int' or `void'). */ +#undef RETSIGTYPE + +/* The size of a `char', as computed by sizeof. */ +#undef SIZEOF_CHAR + +/* The size of a `int', as computed by sizeof. */ +#undef SIZEOF_INT + +/* The size of a `long', as computed by sizeof. */ +#undef SIZEOF_LONG + +/* The size of a `short', as computed by sizeof. */ +#undef SIZEOF_SHORT + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Define to 1 if you can safely include both and . */ +#undef TIME_WITH_SYS_TIME + +/* Define as token for inline if inlining supported */ +#undef inline diff --git a/kame/kame/tcpdump/config.sub b/kame/kame/tcpdump/config.sub index 0432524944..56981740d6 100755 --- a/kame/kame/tcpdump/config.sub +++ b/kame/kame/tcpdump/config.sub @@ -1,6 +1,10 @@ #! /bin/sh -# Configuration validation subroutine script, version 1.1. -# Copyright (C) 1991, 92, 93, 94, 95, 1996 Free Software Foundation, Inc. +# Configuration validation subroutine script. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003 Free Software Foundation, Inc. + +timestamp='2003-11-03' + # This file is (in principle) common to ALL GNU software. # The presence of a machine in this file suggests that SOME GNU software # can handle that machine. It does not imply ALL GNU software can. @@ -25,6 +29,9 @@ # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. +# Please send patches to . Submit a context +# diff and a properly formatted ChangeLog entry. +# # Configuration subroutine to validate and canonicalize a configuration type. # Supply the specified configuration type as an argument. # If it is invalid, we print an error message on stderr and exit with code 1. @@ -45,30 +52,74 @@ # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM # It is wrong to echo any other type of specification. -if [ x$1 = x ] -then - echo Configuration name missing. 1>&2 - echo "Usage: $0 CPU-MFR-OPSYS" 1>&2 - echo "or $0 ALIAS" 1>&2 - echo where ALIAS is a recognized configuration type. 1>&2 - exit 1 -fi +me=`echo "$0" | sed -e 's,.*/,,'` -# First pass through any local machine types. -case $1 in - *local*) - echo $1 - exit 0 - ;; - *) - ;; +usage="\ +Usage: $0 [OPTION] CPU-MFR-OPSYS + $0 [OPTION] ALIAS + +Canonicalize a configuration name. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.sub ($timestamp) + +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 +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit 0 ;; + --version | -v ) + echo "$version" ; exit 0 ;; + --help | --h* | -h ) + echo "$usage"; exit 0 ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" + exit 1 ;; + + *local*) + # First pass through any local machine types. + echo $1 + exit 0;; + + * ) + break ;; + esac +done + +case $# in + 0) echo "$me: missing argument$help" >&2 + exit 1;; + 1) ;; + *) echo "$me: too many arguments$help" >&2 + exit 1;; esac # Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). # Here we must recognize all the valid KERNEL-OS combinations. maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` case $maybe_os in - linux-gnu*) + nto-qnx* | linux-gnu* | linux-dietlibc | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | \ + kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*) os=-$maybe_os basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` ;; @@ -94,15 +145,33 @@ case $os in -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ - -apple) + -apple | -axis) + os= + basic_machine=$1 + ;; + -sim | -cisco | -oki | -wec | -winbond) os= basic_machine=$1 ;; + -scout) + ;; + -wrs) + os=-vxworks + basic_machine=$1 + ;; + -chorusos*) + os=-chorusos + basic_machine=$1 + ;; + -chorusrdb) + os=-chorusrdb + basic_machine=$1 + ;; -hiux*) os=-hiuxwe2 ;; -sco5) - os=sco3.2v5 + os=-sco3.2v5 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco4) @@ -121,6 +190,9 @@ case $os in os=-sco3.2v2 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; + -udk*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; -isc) os=-isc2.2 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` @@ -143,25 +215,74 @@ case $os in -psos*) os=-psos ;; + -mint | -mint[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; esac # Decode aliases for certain CPU-COMPANY combinations. case $basic_machine in # Recognize the basic CPU types without company name. # Some are omitted here because they have special meanings below. - tahoe | i860 | m68k | m68000 | m88k | ns32k | arm \ - | arme[lb] | pyramid \ - | tron | a29k | 580 | i960 | h8300 | hppa | hppa1.0 | hppa1.1 \ - | alpha | we32k | ns16k | clipper | i370 | sh \ - | powerpc | powerpcle | 1750a | dsp16xx | mips64 | mipsel \ - | pdp11 | mips64el | mips64orion | mips64orionel \ - | sparc | sparclet | sparclite | sparc64) + 1750a | 580 \ + | a29k \ + | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ + | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ + | am33_2.0 \ + | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \ + | c4x | clipper \ + | d10v | d30v | dlx | dsp16xx \ + | fr30 | frv \ + | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ + | i370 | i860 | i960 | ia64 \ + | ip2k | iq2000 \ + | m32r | m68000 | m68k | m88k | mcore \ + | mips | mipsbe | mipseb | mipsel | mipsle \ + | mips16 \ + | mips64 | mips64el \ + | mips64vr | mips64vrel \ + | mips64orion | mips64orionel \ + | mips64vr4100 | mips64vr4100el \ + | mips64vr4300 | mips64vr4300el \ + | mips64vr5000 | mips64vr5000el \ + | mipsisa32 | mipsisa32el \ + | mipsisa32r2 | mipsisa32r2el \ + | mipsisa64 | mipsisa64el \ + | mipsisa64r2 | mipsisa64r2el \ + | mipsisa64sb1 | mipsisa64sb1el \ + | mipsisa64sr71k | mipsisa64sr71kel \ + | mipstx39 | mipstx39el \ + | mn10200 | mn10300 \ + | msp430 \ + | ns16k | ns32k \ + | openrisc | or32 \ + | pdp10 | pdp11 | pj | pjl \ + | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ + | pyramid \ + | sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \ + | sh64 | sh64le \ + | sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \ + | strongarm \ + | tahoe | thumb | tic4x | tic80 | tron \ + | v850 | v850e \ + | we32k \ + | x86 | xscale | xstormy16 | xtensa \ + | z8k) basic_machine=$basic_machine-unknown ;; + m6811 | m68hc11 | m6812 | m68hc12) + # Motorola 68HC11/12. + basic_machine=$basic_machine-unknown + os=-none + ;; + m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) + ;; + # 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[3456]86) + i*86 | x86_64) basic_machine=$basic_machine-pc ;; # Object if more than one company name word. @@ -170,23 +291,82 @@ case $basic_machine in exit 1 ;; # Recognize the basic CPU types with company name. - vax-* | tahoe-* | i[3456]86-* | i860-* | m68k-* | m68000-* | m88k-* \ - | sparc-* | ns32k-* | fx80-* | arm-* | c[123]* \ - | mips-* | pyramid-* | tron-* | a29k-* | romp-* | rs6000-* | power-* \ - | none-* | 580-* | cray2-* | h8300-* | i960-* | xmp-* | ymp-* \ - | hppa-* | hppa1.0-* | hppa1.1-* | alpha-* | we32k-* | cydra-* | ns16k-* \ - | pn-* | np1-* | xps100-* | clipper-* | orion-* | sparclite-* \ - | pdp11-* | sh-* | powerpc-* | powerpcle-* | sparc64-* | mips64-* | mipsel-* \ - | mips64el-* | mips64orion-* | mips64orionel-* | f301-*) + 580-* \ + | a29k-* \ + | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ + | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ + | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ + | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ + | avr-* \ + | bs2000-* \ + | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ + | clipper-* | cydra-* \ + | d10v-* | d30v-* | dlx-* \ + | elxsi-* \ + | f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \ + | h8300-* | h8500-* \ + | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ + | i*86-* | i860-* | i960-* | ia64-* \ + | ip2k-* | iq2000-* \ + | m32r-* \ + | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ + | m88110-* | m88k-* | mcore-* \ + | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ + | mips16-* \ + | mips64-* | mips64el-* \ + | mips64vr-* | mips64vrel-* \ + | mips64orion-* | mips64orionel-* \ + | mips64vr4100-* | mips64vr4100el-* \ + | mips64vr4300-* | mips64vr4300el-* \ + | mips64vr5000-* | mips64vr5000el-* \ + | mipsisa32-* | mipsisa32el-* \ + | mipsisa32r2-* | mipsisa32r2el-* \ + | mipsisa64-* | mipsisa64el-* \ + | mipsisa64r2-* | mipsisa64r2el-* \ + | mipsisa64sb1-* | mipsisa64sb1el-* \ + | mipsisa64sr71k-* | mipsisa64sr71kel-* \ + | mipstx39-* | mipstx39el-* \ + | msp430-* \ + | none-* | np1-* | nv1-* | ns16k-* | ns32k-* \ + | orion-* \ + | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ + | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ + | pyramid-* \ + | romp-* | rs6000-* \ + | sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \ + | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ + | sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \ + | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \ + | tahoe-* | thumb-* \ + | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ + | tron-* \ + | v850-* | v850e-* | vax-* \ + | we32k-* \ + | x86-* | x86_64-* | xps100-* | xscale-* | xstormy16-* \ + | xtensa-* \ + | ymp-* \ + | z8k-*) ;; # Recognize the various machine names and aliases which stand # for a CPU type and a company and sometimes even an OS. + 386bsd) + basic_machine=i386-unknown + os=-bsd + ;; 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) basic_machine=m68000-att ;; 3b*) basic_machine=we32k-att ;; + a29khif) + basic_machine=a29k-amd + os=-udi + ;; + adobe68k) + basic_machine=m68010-adobe + os=-scout + ;; alliant | fx80) basic_machine=fx80-alliant ;; @@ -197,25 +377,32 @@ case $basic_machine in basic_machine=a29k-none os=-bsd ;; + amd64) + basic_machine=x86_64-pc + ;; amdahl) basic_machine=580-amdahl os=-sysv ;; amiga | amiga-*) - basic_machine=m68k-cbm + basic_machine=m68k-unknown ;; - amigados) - basic_machine=m68k-cbm - os=-amigados + amigaos | amigados) + basic_machine=m68k-unknown + os=-amigaos ;; amigaunix | amix) - basic_machine=m68k-cbm + basic_machine=m68k-unknown os=-sysv4 ;; apollo68) basic_machine=m68k-apollo os=-sysv ;; + apollo68bsd) + basic_machine=m68k-apollo + os=-bsd + ;; aux) basic_machine=m68k-apple os=-aux @@ -224,6 +411,10 @@ case $basic_machine in basic_machine=ns32k-sequent os=-dynix ;; + c90) + basic_machine=c90-cray + os=-unicos + ;; convex-c1) basic_machine=c1-convex os=-bsd @@ -244,27 +435,30 @@ case $basic_machine in basic_machine=c38-convex os=-bsd ;; - cray | ymp) - basic_machine=ymp-cray - os=-unicos - ;; - cray2) - basic_machine=cray2-cray - os=-unicos - ;; - [ctj]90-cray) - basic_machine=c90-cray + cray | j90) + basic_machine=j90-cray os=-unicos ;; crds | unos) basic_machine=m68k-crds ;; + cris | cris-* | etrax*) + basic_machine=cris-axis + ;; da30 | da30-*) basic_machine=m68k-da30 ;; decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) basic_machine=mips-dec ;; + decsystem10* | dec10*) + basic_machine=pdp10-dec + os=-tops10 + ;; + decsystem20* | dec20*) + basic_machine=pdp10-dec + os=-tops20 + ;; delta | 3300 | motorola-3300 | motorola-delta \ | 3300-motorola | delta-motorola) basic_machine=m68k-motorola @@ -292,6 +486,10 @@ case $basic_machine in encore | umax | mmax) basic_machine=ns32k-encore ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + os=-ose + ;; fx2800) basic_machine=i860-alliant ;; @@ -302,6 +500,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 @@ -310,6 +512,14 @@ case $basic_machine in basic_machine=h8300-hitachi os=-hms ;; + h8300xray) + basic_machine=h8300-hitachi + os=-xray + ;; + h8500hms) + basic_machine=h8500-hitachi + os=-hms + ;; harris) basic_machine=m88k-harris os=-sysv3 @@ -325,13 +535,30 @@ case $basic_machine in basic_machine=m68k-hp os=-hpux ;; + hp3k9[0-9][0-9] | hp9[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; hp9k2[0-9][0-9] | hp9k31[0-9]) basic_machine=m68000-hp ;; hp9k3[2-9][0-9]) basic_machine=m68k-hp ;; - hp9k7[0-9][0-9] | hp7[0-9][0-9] | hp9k8[0-9]7 | hp8[0-9]7) + hp9k6[0-9][0-9] | hp6[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k7[0-79][0-9] | hp7[0-79][0-9]) + basic_machine=hppa1.1-hp + ;; + hp9k78[0-9] | hp78[0-9]) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][13679] | hp8[0-9][13679]) basic_machine=hppa1.1-hp ;; hp9k8[0-9][0-9] | hp8[0-9][0-9]) @@ -340,27 +567,42 @@ case $basic_machine in hppa-next) os=-nextstep3 ;; + hppaosf) + basic_machine=hppa1.1-hp + os=-osf + ;; + hppro) + basic_machine=hppa1.1-hp + os=-proelf + ;; i370-ibm* | ibm*) basic_machine=i370-ibm - os=-mvs ;; # I'm not sure what "Sysv32" means. Should this be sysv3.2? - i[3456]86v32) + i*86v32) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv32 ;; - i[3456]86v4*) + i*86v4*) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv4 ;; - i[3456]86v) + i*86v) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv ;; - i[3456]86sol2) + i*86sol2) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-solaris2 ;; + i386mach) + basic_machine=i386-mach + os=-mach + ;; + i386-vsta | vsta) + basic_machine=i386-unknown + os=-vsta + ;; iris | iris4d) basic_machine=mips-sgi case $os in @@ -386,19 +628,55 @@ case $basic_machine in basic_machine=ns32k-utek os=-sysv ;; + mingw32) + basic_machine=i386-pc + os=-mingw32 + ;; miniframe) basic_machine=m68000-convergent ;; + *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; mips3*-*) basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` ;; mips3*) basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown ;; + mmix*) + basic_machine=mmix-knuth + os=-mmixware + ;; + monitor) + basic_machine=m68k-rom68k + os=-coff + ;; + morphos) + basic_machine=powerpc-unknown + os=-morphos + ;; + msdos) + basic_machine=i386-pc + os=-msdos + ;; + mvs) + basic_machine=i370-ibm + os=-mvs + ;; ncr3000) basic_machine=i486-ncr os=-sysv4 ;; + netbsd386) + basic_machine=i386-unknown + os=-netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + os=-linux + ;; news | news700 | news800 | news900) basic_machine=m68k-sony os=-newsos @@ -411,6 +689,10 @@ case $basic_machine in basic_machine=mips-sony os=-newsos ;; + necv70) + basic_machine=v70-nec + os=-sysv + ;; next | m*-next ) basic_machine=m68k-next case $os in @@ -436,9 +718,44 @@ case $basic_machine in basic_machine=i960-intel os=-nindy ;; + mon960) + basic_machine=i960-intel + os=-mon960 + ;; + nonstopux) + basic_machine=mips-compaq + os=-nonstopux + ;; np1) basic_machine=np1-gould ;; + nv1) + basic_machine=nv1-cray + os=-unicosmp + ;; + nsr-tandem) + basic_machine=nsr-tandem + ;; + op50n-* | op60c-*) + basic_machine=hppa1.1-oki + os=-proelf + ;; + or32 | or32-*) + basic_machine=or32-unknown + os=-coff + ;; + os400) + basic_machine=powerpc-ibm + os=-os400 + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + os=-ose + ;; + os68k) + basic_machine=m68k-none + os=-os68k + ;; pa-hitachi) basic_machine=hppa1.1-hitachi os=-hiuxwe2 @@ -453,53 +770,95 @@ case $basic_machine in pbb) basic_machine=m68k-tti ;; - pc532 | pc532-*) + pc532 | pc532-*) basic_machine=ns32k-pc532 ;; - pentium | p5) - basic_machine=i586-intel + pentium | p5 | k5 | k6 | nexgen | viac3) + basic_machine=i586-pc + ;; + pentiumpro | p6 | 6x86 | athlon | athlon_*) + basic_machine=i686-pc ;; - pentiumpro | p6) - basic_machine=i686-intel + pentiumii | pentium2 | pentiumiii | pentium3) + basic_machine=i686-pc ;; - pentium-* | p5-*) + pentium4) + basic_machine=i786-pc + ;; + pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` ;; - pentiumpro-* | p6-*) + pentiumpro-* | p6-* | 6x86-* | athlon-*) basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` ;; - k5) - # We don't have specific support for AMD's K5 yet, so just call it a Pentium - basic_machine=i586-amd + pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` ;; - nexen) - # We don't have specific support for Nexgen yet, so just call it a Pentium - basic_machine=i586-nexgen + pentium4-*) + basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pn) basic_machine=pn-gould ;; - power) basic_machine=rs6000-ibm + power) basic_machine=power-ibm ;; ppc) basic_machine=powerpc-unknown - ;; + ;; ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` ;; ppcle | powerpclittle | ppc-le | powerpc-little) basic_machine=powerpcle-unknown - ;; + ;; ppcle-* | powerpclittle-*) basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` ;; + ppc64) basic_machine=powerpc64-unknown + ;; + ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64le | powerpc64little | ppc64-le | powerpc64-little) + basic_machine=powerpc64le-unknown + ;; + ppc64le-* | powerpc64little-*) + basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; ps2) basic_machine=i386-ibm ;; + pw32) + basic_machine=i586-unknown + os=-pw32 + ;; + rom68k) + basic_machine=m68k-rom68k + os=-coff + ;; rm[46]00) basic_machine=mips-siemens ;; rtpc | rtpc-*) basic_machine=romp-ibm ;; + s390 | s390-*) + basic_machine=s390-ibm + ;; + s390x | s390x-*) + basic_machine=s390x-ibm + ;; + sa29200) + basic_machine=a29k-amd + os=-udi + ;; + sb1) + basic_machine=mipsisa64sb1-unknown + ;; + sb1el) + basic_machine=mipsisa64sb1el-unknown + ;; + sei) + basic_machine=mips-sei + os=-seiux + ;; sequent) basic_machine=i386-sequent ;; @@ -507,6 +866,13 @@ case $basic_machine in basic_machine=sh-hitachi os=-hms ;; + sh64) + basic_machine=sh64-unknown + ;; + sparclite-wrs | simso-wrs) + basic_machine=sparclite-wrs + os=-vxworks + ;; sps7) basic_machine=m68k-bull os=-sysv2 @@ -514,6 +880,13 @@ case $basic_machine in spur) basic_machine=spur-unknown ;; + st2000) + basic_machine=m68k-tandem + ;; + stratus) + basic_machine=i860-stratus + os=-sysv4 + ;; sun2) basic_machine=m68000-sun ;; @@ -554,13 +927,51 @@ case $basic_machine in sun386 | sun386i | roadrunner) basic_machine=i386-sun ;; + sv1) + basic_machine=sv1-cray + os=-unicos + ;; symmetry) basic_machine=i386-sequent os=-dynix ;; + t3e) + basic_machine=alphaev5-cray + os=-unicos + ;; + t90) + basic_machine=t90-cray + os=-unicos + ;; + tic54x | c54x*) + basic_machine=tic54x-unknown + os=-coff + ;; + tic55x | c55x*) + basic_machine=tic55x-unknown + os=-coff + ;; + tic6x | c6x*) + basic_machine=tic6x-unknown + os=-coff + ;; + tx39) + basic_machine=mipstx39-unknown + ;; + tx39el) + basic_machine=mipstx39el-unknown + ;; + toad1) + basic_machine=pdp10-xkl + os=-tops20 + ;; tower | tower-32) basic_machine=m68k-ncr ;; + tpf) + basic_machine=s390x-ibm + os=-tpf + ;; udi29k) basic_machine=a29k-amd os=-udi @@ -569,6 +980,10 @@ case $basic_machine in basic_machine=a29k-nyu os=-sym1 ;; + v810 | necv810) + basic_machine=v810-nec + os=-none + ;; vaxv) basic_machine=vax-dec os=-sysv @@ -577,9 +992,9 @@ case $basic_machine in basic_machine=vax-dec os=-vms ;; - vpp*|vx|vx-*) - basic_machine=f301-fujitsu - ;; + vpp*|vx|vx-*) + basic_machine=f301-fujitsu + ;; vxworks960) basic_machine=i960-wrs os=-vxworks @@ -592,13 +1007,25 @@ case $basic_machine in basic_machine=a29k-wrs os=-vxworks ;; - xmp) - basic_machine=xmp-cray - os=-unicos + w65*) + basic_machine=w65-wdc + os=-none ;; - xps | xps100) + w89k-*) + basic_machine=hppa1.1-winbond + os=-proelf + ;; + xps | xps100) basic_machine=xps100-honeywell ;; + ymp) + basic_machine=ymp-cray + os=-unicos + ;; + z8k-*-coff) + basic_machine=z8k-unknown + os=-sim + ;; none) basic_machine=none-none os=-none @@ -606,8 +1033,14 @@ case $basic_machine in # Here we handle the default manufacturer of certain CPU types. It is in # some cases the only manufacturer, in others, it is the most popular. - mips) - basic_machine=mips-mips + w89k) + basic_machine=hppa1.1-winbond + ;; + op50n) + basic_machine=hppa1.1-oki + ;; + op60c) + basic_machine=hppa1.1-oki ;; romp) basic_machine=romp-ibm @@ -618,16 +1051,26 @@ 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 ;; we32k) basic_machine=we32k-att ;; - sparc) + sh3 | sh4 | sh[34]eb | sh[1234]le | sh[23]ele) + basic_machine=sh-unknown + ;; + sh64) + basic_machine=sh64-unknown + ;; + sparc | sparcv9 | sparcv9b) basic_machine=sparc-sun ;; - cydra) + cydra) basic_machine=cydra-cydrome ;; orion) @@ -636,6 +1079,15 @@ case $basic_machine in orion105) basic_machine=clipper-highlevel ;; + mac | mpw | mac-mpw) + basic_machine=m68k-apple + ;; + pmac | pmac-mpw) + basic_machine=powerpc-apple + ;; + *-unknown) + # Make sure to match an already-canonicalized machine name. + ;; *) echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 exit 1 @@ -668,9 +1120,12 @@ case $os in -solaris) os=-solaris2 ;; - -unixware* | svr4*) + -svr4*) os=-sysv4 ;; + -unixware*) + os=-sysv4.2uw + ;; -gnu/linux*) os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` ;; @@ -681,17 +1136,49 @@ case $os in -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ - | -amigados* | -msdos* | -newsos* | -unicos* | -aof* | -aos* \ + | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ + | -aos* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ - | -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \ - | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* \ + | -hiux* | -386bsd* | -knetbsd* | -netbsd* | -openbsd* | -kfreebsd* | -freebsd* | -riscix* \ + | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ - | -cygwin32* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ - | -linux-gnu* | -uxpv*) + | -chorusos* | -chorusrdb* \ + | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ + | -mingw32* | -linux-gnu* | -linux-uclibc* | -uxpv* | -beos* | -mpeix* | -udk* \ + | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ + | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ + | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ + | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ + | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ + | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly*) # Remember, each alternative MUST END IN *, to match a version number. ;; + -qnx*) + case $basic_machine in + x86-* | i*86-*) + ;; + *) + os=-nto$os + ;; + esac + ;; + -nto-qnx*) + ;; + -nto*) + os=`echo $os | sed -e 's|nto|nto-qnx|'` + ;; + -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ + | -windows* | -osx | -abug | -netware* | -os9* | -beos* \ + | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) + ;; + -mac*) + os=`echo $os | sed -e 's|mac|macos|'` + ;; + -linux-dietlibc) + os=-linux-dietlibc + ;; -linux*) os=`echo $os | sed -e 's|linux|linux-gnu|'` ;; @@ -701,6 +1188,15 @@ case $os in -sunos6*) os=`echo $os | sed -e 's|sunos6|solaris3|'` ;; + -opened*) + os=-openedition + ;; + -os400*) + os=-os400 + ;; + -wince*) + os=-wince + ;; -osfrose*) os=-osfrose ;; @@ -716,11 +1212,23 @@ case $os in -acis*) os=-aos ;; + -atheos*) + os=-atheos + ;; + -386bsd) + os=-bsd + ;; -ctix* | -uts*) os=-sysv ;; + -nova*) + os=-rtmk-nova + ;; -ns2 ) - os=-nextstep2 + os=-nextstep2 + ;; + -nsk*) + os=-nsk ;; # Preserve the version number of sinix5. -sinix5.*) @@ -729,6 +1237,9 @@ case $os in -sinix*) os=-sysv4 ;; + -tpf*) + os=-tpf + ;; -triton*) os=-sysv3 ;; @@ -747,9 +1258,24 @@ case $os in # This must come after -sysvr4. -sysv*) ;; + -ose*) + os=-ose + ;; + -es1800*) + os=-ose + ;; -xenix) os=-xenix ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + os=-mint + ;; + -aros*) + os=-aros + ;; + -kaos*) + os=-kaos + ;; -none) ;; *) @@ -775,10 +1301,20 @@ case $basic_machine in *-acorn) os=-riscix1.2 ;; + arm*-rebel) + os=-linux + ;; arm*-semi) os=-aout ;; - pdp11-*) + c4x-* | tic4x-*) + os=-coff + ;; + # This must come before the *-dec entry. + pdp10-*) + os=-tops20 + ;; + pdp11-*) os=-none ;; *-dec | vax-*) @@ -796,15 +1332,39 @@ case $basic_machine in # default. # os=-sunos4 ;; + m68*-cisco) + os=-aout + ;; + mips*-cisco) + os=-elf + ;; + mips*-*) + os=-elf + ;; + or32-*) + os=-coff + ;; *-tti) # must be before sparc entry or we get the wrong os. os=-sysv3 ;; sparc-* | *-sun) os=-sunos4.1.1 ;; + *-be) + os=-beos + ;; *-ibm) os=-aix ;; + *-wec) + os=-proelf + ;; + *-winbond) + os=-proelf + ;; + *-oki) + os=-proelf + ;; *-hp) os=-hpux ;; @@ -815,7 +1375,7 @@ case $basic_machine in os=-sysv ;; *-cbm) - os=-amigados + os=-amigaos ;; *-dg) os=-dgux @@ -847,27 +1407,39 @@ case $basic_machine in *-next) os=-nextstep3 ;; - *-gould) + *-gould) os=-sysv ;; - *-highlevel) + *-highlevel) os=-bsd ;; *-encore) os=-bsd ;; - *-sgi) + *-sgi) os=-irix ;; - *-siemens) + *-siemens) os=-sysv4 ;; *-masscomp) os=-rtu ;; - f301-fujitsu) + f30[01]-fujitsu | f700-fujitsu) os=-uxpv ;; + *-rom68k) + os=-coff + ;; + *-*bug) + os=-coff + ;; + *-apple) + os=-macos + ;; + *-atari*) + os=-mint + ;; *) os=-none ;; @@ -889,9 +1461,15 @@ case $basic_machine in -aix*) vendor=ibm ;; + -beos*) + vendor=be + ;; -hpux*) vendor=hp ;; + -mpeix*) + vendor=hp + ;; -hiux*) vendor=hitachi ;; @@ -907,21 +1485,47 @@ case $basic_machine in -genix*) vendor=ns ;; - -mvs*) + -mvs* | -opened*) + vendor=ibm + ;; + -os400*) vendor=ibm ;; -ptx*) vendor=sequent ;; - -vxsim* | -vxworks*) + -tpf*) + vendor=ibm + ;; + -vxsim* | -vxworks* | -windiss*) vendor=wrs ;; -aux*) vendor=apple ;; + -hms*) + vendor=hitachi + ;; + -mpw* | -macos*) + vendor=apple + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + vendor=atari + ;; + -vos*) + vendor=stratus + ;; esac basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` ;; esac echo $basic_machine$os +exit 0 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/kame/kame/tcpdump/configure b/kame/kame/tcpdump/configure index 2ec17ab976..7907b87ec9 100755 --- a/kame/kame/tcpdump/configure +++ b/kame/kame/tcpdump/configure @@ -1,30 +1,325 @@ #! /bin/sh - +# From configure.in Revision: 1.169.2.3 . # Guess values for system-dependent variables and create Makefiles. -# Generated automatically using autoconf version 2.13 -# Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc. +# Generated by GNU Autoconf 2.57. # +# Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002 +# Free Software Foundation, Inc. # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. +## --------------------- ## +## M4sh Initialization. ## +## --------------------- ## + +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' +elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then + set -o posix +fi + +# Support unset when possible. +if (FOO=FOO; unset FOO) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + + +# Work around bugs in pre-3.0 UWIN ksh. +$as_unset ENV MAIL MAILPATH +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +for as_var in \ + LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ + LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ + LC_TELEPHONE LC_TIME +do + if (set +x; test -n "`(eval $as_var=C; export $as_var) 2>&1`"); then + eval $as_var=C; export $as_var + else + $as_unset $as_var + fi +done + +# Required to use basename. +if expr a : '\(a\)' >/dev/null 2>&1; then + as_expr=expr +else + as_expr=false +fi + +if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + + +# Name of the executable. +as_me=`$as_basename "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)$' \| \ + . : '\(.\)' 2>/dev/null || +echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; } + /^X\/\(\/\/\)$/{ s//\1/; q; } + /^X\/\(\/\).*/{ s//\1/; q; } + s/.*/./; q'` + + +# PATH needs CR, and LINENO needs CR and PATH. +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' + else + PATH_SEPARATOR=: + fi + rm -f conf$$.sh +fi + + + as_lineno_1=$LINENO + as_lineno_2=$LINENO + as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null` + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x$as_lineno_3" = "x$as_lineno_2" || { + # Find who we are. Look in the path if we contain no path at all + # relative or not. + case $0 in + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break +done + + ;; + esac + # We did not find ourselves, most probably we were run as `sh COMMAND' + # in which case we are not to be found in the path. + if test "x$as_myself" = x; then + as_myself=$0 + fi + if test ! -f "$as_myself"; then + { echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2 + { (exit 1); exit 1; }; } + fi + case $CONFIG_SHELL in + '') + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for as_base in sh bash ksh sh5; do + case $as_dir in + /*) + if ("$as_dir/$as_base" -c ' + as_lineno_1=$LINENO + as_lineno_2=$LINENO + as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null` + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x$as_lineno_3" = "x$as_lineno_2" ') 2>/dev/null; then + $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; } + $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; } + CONFIG_SHELL=$as_dir/$as_base + export CONFIG_SHELL + exec "$CONFIG_SHELL" "$0" ${1+"$@"} + fi;; + esac + done +done +;; + esac + + # Create $as_me.lineno as a copy of $as_myself, but with $LINENO + # uniformly replaced by the line number. The first 'sed' inserts a + # line-number line before each line; the second 'sed' does the real + # work. The second script uses 'N' to pair each line-number line + # with the numbered line, and appends trailing '-' during + # substitution so that $LINENO is not a special case at line end. + # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the + # second 'sed' script. Blame Lee E. McMahon for sed's syntax. :-) + sed '=' <$as_myself | + sed ' + N + s,$,-, + : loop + s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3, + t loop + s,-$,, + s,^['$as_cr_digits']*\n,, + ' >$as_me.lineno && + chmod +x $as_me.lineno || + { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2 + { (exit 1); exit 1; }; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensible to this). + . ./$as_me.lineno + # Exit status is that of the last command. + exit +} + + +case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in + *c*,-n*) ECHO_N= ECHO_C=' +' ECHO_T=' ' ;; + *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;; + *) ECHO_N= ECHO_C='\c' ECHO_T= ;; +esac + +if expr a : '\(a\)' >/dev/null 2>&1; then + as_expr=expr +else + as_expr=false +fi + +rm -f conf$$ conf$$.exe conf$$.file +echo >conf$$.file +if ln -s conf$$.file conf$$ 2>/dev/null; then + # We could just check for DJGPP; but this test a) works b) is more generic + # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04). + if test -f conf$$.exe; then + # Don't use ln at all; we don't have any links + as_ln_s='cp -p' + else + as_ln_s='ln -s' + fi +elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.file + +if mkdir -p . 2>/dev/null; then + as_mkdir_p=: +else + as_mkdir_p=false +fi + +as_executable_p="test -f" + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="sed y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="sed y%*+%pp%;s%[^_$as_cr_alnum]%_%g" + + +# IFS +# We need space, tab and new line, in precisely that order. +as_nl=' +' +IFS=" $as_nl" + +# CDPATH. +$as_unset CDPATH + + +# Name of the host. +# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, +# so uname gets run too. +ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` + +exec 6>&1 -# Defaults: -ac_help= +# +# Initializations. +# ac_default_prefix=/usr/local -# Any additions from configure.in: -ac_help="$ac_help - --without-gcc don't use gcc" -ac_help="$ac_help - --enable-ipv6 build IPv6-capable version" +ac_config_libobj_dir=. +cross_compiling=no +subdirs= +MFLAGS= +MAKEFLAGS= +SHELL=${CONFIG_SHELL-/bin/sh} + +# Maximum number of lines to put in a shell here document. +# This variable seems obsolete. It should probably be removed, and +# only ac_max_sed_lines should be used. +: ${ac_max_here_lines=38} + +# Identity of this package. +PACKAGE_NAME= +PACKAGE_TARNAME= +PACKAGE_VERSION= +PACKAGE_STRING= +PACKAGE_BUGREPORT= + +ac_unique_file="tcpdump.c" +# Factoring default headers for most tests. +ac_includes_default="\ +#include +#if HAVE_SYS_TYPES_H +# include +#endif +#if HAVE_SYS_STAT_H +# include +#endif +#if STDC_HEADERS +# include +# include +#else +# if HAVE_STDLIB_H +# include +# endif +#endif +#if HAVE_STRING_H +# if !STDC_HEADERS && HAVE_MEMORY_H +# include +# endif +# include +#endif +#if HAVE_STRINGS_H +# include +#endif +#if HAVE_INTTYPES_H +# include +#else +# if HAVE_STDINT_H +# include +# endif +#endif +#if HAVE_UNISTD_H +# include +#endif" + +ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os SHLICC2 CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP EGREP LIBOBJS V_CCOPT V_DEFS V_GROUP V_INCLS V_PCAPDEP LOCALSRC INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LTLIBOBJS' +ac_subst_files='' # Initialize some variables set by options. +ac_init_help= +ac_init_version=false # The variables have the same names as the options, with # dashes changed to underlines. -build=NONE -cache_file=./config.cache +cache_file=/dev/null exec_prefix=NONE -host=NONE no_create= -nonopt=NONE no_recursion= prefix=NONE program_prefix=NONE @@ -33,10 +328,15 @@ program_transform_name=s,x,x, silent= site= srcdir= -target=NONE verbose= x_includes=NONE x_libraries=NONE + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' @@ -50,17 +350,9 @@ oldincludedir='/usr/include' infodir='${prefix}/info' mandir='${prefix}/man' -# Initialize some other variables. -subdirs= -MFLAGS= MAKEFLAGS= -SHELL=${CONFIG_SHELL-/bin/sh} -# Maximum number of lines to put in a shell here document. -ac_max_here_lines=12 - ac_prev= for ac_option do - # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then eval "$ac_prev=\$ac_option" @@ -68,59 +360,59 @@ do continue fi - case "$ac_option" in - -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;; - *) ac_optarg= ;; - esac + ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` # Accept the important Cygnus configure options, so we can diagnose typos. - case "$ac_option" in + case $ac_option in -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) - bindir="$ac_optarg" ;; + bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) - ac_prev=build ;; + ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) - build="$ac_optarg" ;; + build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) - cache_file="$ac_optarg" ;; + cache_file=$ac_optarg ;; + + --config-cache | -C) + cache_file=config.cache ;; -datadir | --datadir | --datadi | --datad | --data | --dat | --da) ac_prev=datadir ;; -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \ | --da=*) - datadir="$ac_optarg" ;; + datadir=$ac_optarg ;; -disable-* | --disable-*) - ac_feature=`echo $ac_option|sed -e 's/-*disable-//'` + ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_feature| sed 's/[-a-zA-Z0-9_]//g'`"; then - { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } - fi - ac_feature=`echo $ac_feature| sed 's/-/_/g'` - eval "enable_${ac_feature}=no" ;; + expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid feature name: $ac_feature" >&2 + { (exit 1); exit 1; }; } + ac_feature=`echo $ac_feature | sed 's/-/_/g'` + eval "enable_$ac_feature=no" ;; -enable-* | --enable-*) - ac_feature=`echo $ac_option|sed -e 's/-*enable-//' -e 's/=.*//'` + ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_feature| sed 's/[-_a-zA-Z0-9]//g'`"; then - { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } - fi - ac_feature=`echo $ac_feature| sed 's/-/_/g'` - case "$ac_option" in - *=*) ;; + expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid feature name: $ac_feature" >&2 + { (exit 1); exit 1; }; } + ac_feature=`echo $ac_feature | sed 's/-/_/g'` + case $ac_option in + *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;; *) ac_optarg=yes ;; esac - eval "enable_${ac_feature}='$ac_optarg'" ;; + eval "enable_$ac_feature='$ac_optarg'" ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ @@ -129,95 +421,47 @@ do -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) - exec_prefix="$ac_optarg" ;; + exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; - -help | --help | --hel | --he) - # Omit some internal or obsolete options to make the list less imposing. - # This message is too long to be a string in the A/UX 3.1 sh. - cat << EOF -Usage: configure [options] [host] -Options: [defaults in brackets after descriptions] -Configuration: - --cache-file=FILE cache test results in FILE - --help print this message - --no-create do not create output files - --quiet, --silent do not print \`checking...' messages - --version print the version of autoconf that created configure -Directory and file names: - --prefix=PREFIX install architecture-independent files in PREFIX - [$ac_default_prefix] - --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX - [same as prefix] - --bindir=DIR user executables in DIR [EPREFIX/bin] - --sbindir=DIR system admin executables in DIR [EPREFIX/sbin] - --libexecdir=DIR program executables in DIR [EPREFIX/libexec] - --datadir=DIR read-only architecture-independent data in DIR - [PREFIX/share] - --sysconfdir=DIR read-only single-machine data in DIR [PREFIX/etc] - --sharedstatedir=DIR modifiable architecture-independent data in DIR - [PREFIX/com] - --localstatedir=DIR modifiable single-machine data in DIR [PREFIX/var] - --libdir=DIR object code libraries in DIR [EPREFIX/lib] - --includedir=DIR C header files in DIR [PREFIX/include] - --oldincludedir=DIR C header files for non-gcc in DIR [/usr/include] - --infodir=DIR info documentation in DIR [PREFIX/info] - --mandir=DIR man documentation in DIR [PREFIX/man] - --srcdir=DIR find the sources in DIR [configure dir or ..] - --program-prefix=PREFIX prepend PREFIX to installed program names - --program-suffix=SUFFIX append SUFFIX to installed program names - --program-transform-name=PROGRAM - run sed PROGRAM on installed program names -EOF - cat << EOF -Host type: - --build=BUILD configure for building on BUILD [BUILD=HOST] - --host=HOST configure for HOST [guessed] - --target=TARGET configure for TARGET [TARGET=HOST] -Features and packages: - --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) - --enable-FEATURE[=ARG] include FEATURE [ARG=yes] - --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] - --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) - --x-includes=DIR X include files are in DIR - --x-libraries=DIR X library files are in DIR -EOF - if test -n "$ac_help"; then - echo "--enable and --with options recognized:$ac_help" - fi - exit 0 ;; + -help | --help | --hel | --he | -h) + ac_init_help=long ;; + -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) + ac_init_help=recursive ;; + -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) + ac_init_help=short ;; -host | --host | --hos | --ho) - ac_prev=host ;; + ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) - host="$ac_optarg" ;; + host_alias=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) - includedir="$ac_optarg" ;; + includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) - infodir="$ac_optarg" ;; + infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) - libdir="$ac_optarg" ;; + libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) - libexecdir="$ac_optarg" ;; + libexecdir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ | --localstate | --localstat | --localsta | --localst \ @@ -226,19 +470,19 @@ EOF -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ | --localstate=* | --localstat=* | --localsta=* | --localst=* \ | --locals=* | --local=* | --loca=* | --loc=* | --lo=*) - localstatedir="$ac_optarg" ;; + localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) - mandir="$ac_optarg" ;; + mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c) + | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ @@ -252,26 +496,26 @@ EOF -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) - oldincludedir="$ac_optarg" ;; + oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) - prefix="$ac_optarg" ;; + prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) - program_prefix="$ac_optarg" ;; + program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) - program_suffix="$ac_optarg" ;; + program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ @@ -288,7 +532,7 @@ EOF | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) - program_transform_name="$ac_optarg" ;; + program_transform_name=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) @@ -298,7 +542,7 @@ EOF ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) - sbindir="$ac_optarg" ;; + sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ @@ -309,58 +553,57 @@ EOF | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) - sharedstatedir="$ac_optarg" ;; + sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) - site="$ac_optarg" ;; + site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) - srcdir="$ac_optarg" ;; + srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) - sysconfdir="$ac_optarg" ;; + sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) - ac_prev=target ;; + ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) - target="$ac_optarg" ;; + target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; - -version | --version | --versio | --versi | --vers) - echo "configure generated by autoconf version 2.13" - exit 0 ;; + -version | --version | --versio | --versi | --vers | -V) + ac_init_version=: ;; -with-* | --with-*) - ac_package=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'` + ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_package| sed 's/[-_a-zA-Z0-9]//g'`"; then - { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } - fi + expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid package name: $ac_package" >&2 + { (exit 1); exit 1; }; } ac_package=`echo $ac_package| sed 's/-/_/g'` - case "$ac_option" in - *=*) ;; + case $ac_option in + *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;; *) ac_optarg=yes ;; esac - eval "with_${ac_package}='$ac_optarg'" ;; + eval "with_$ac_package='$ac_optarg'" ;; -without-* | --without-*) - ac_package=`echo $ac_option|sed -e 's/-*without-//'` + ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. - if test -n "`echo $ac_package| sed 's/[-a-zA-Z0-9_]//g'`"; then - { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } - fi - ac_package=`echo $ac_package| sed 's/-/_/g'` - eval "with_${ac_package}=no" ;; + expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid package name: $ac_package" >&2 + { (exit 1); exit 1; }; } + ac_package=`echo $ac_package | sed 's/-/_/g'` + eval "with_$ac_package=no" ;; --x) # Obsolete; use --with-x. @@ -371,99 +614,110 @@ EOF ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) - x_includes="$ac_optarg" ;; + x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) - x_libraries="$ac_optarg" ;; + x_libraries=$ac_optarg ;; - -*) { echo "configure: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; } + -*) { echo "$as_me: error: unrecognized option: $ac_option +Try \`$0 --help' for more information." >&2 + { (exit 1); exit 1; }; } ;; + *=*) + ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` + # Reject names that are not valid shell variable names. + expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid variable name: $ac_envvar" >&2 + { (exit 1); exit 1; }; } + ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` + eval "$ac_envvar='$ac_optarg'" + export $ac_envvar ;; + *) - if test -n "`echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then - echo "configure: warning: $ac_option: invalid host type" 1>&2 - fi - if test "x$nonopt" != xNONE; then - { echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; } - fi - nonopt="$ac_option" + # FIXME: should be removed in autoconf 3.0. + echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && + echo "$as_me: WARNING: invalid host type: $ac_option" >&2 + : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} ;; esac done if test -n "$ac_prev"; then - { echo "configure: error: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" 1>&2; exit 1; } -fi - -trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15 - -# File descriptor usage: -# 0 standard input -# 1 file creation -# 2 errors and warnings -# 3 some systems may open it to /dev/tty -# 4 used on the Kubota Titan -# 6 checking for... messages and results -# 5 compiler messages saved in config.log -if test "$silent" = yes; then - exec 6>/dev/null -else - exec 6>&1 + ac_option=--`echo $ac_prev | sed 's/_/-/g'` + { echo "$as_me: error: missing argument to $ac_option" >&2 + { (exit 1); exit 1; }; } fi -exec 5>./config.log -echo "\ -This file contains any messages produced by compilers while -running configure, to aid debugging if configure makes a mistake. -" 1>&5 +# Be sure to have absolute paths. +for ac_var in exec_prefix prefix +do + eval ac_val=$`echo $ac_var` + case $ac_val in + [\\/$]* | ?:[\\/]* | NONE | '' ) ;; + *) { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2 + { (exit 1); exit 1; }; };; + esac +done -# Strip out --no-create and --no-recursion so they do not pile up. -# Also quote any args containing shell metacharacters. -ac_configure_args= -for ac_arg +# Be sure to have absolute paths. +for ac_var in bindir sbindir libexecdir datadir sysconfdir sharedstatedir \ + localstatedir libdir includedir oldincludedir infodir mandir do - case "$ac_arg" in - -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c) ;; - -no-recursion | --no-recursion | --no-recursio | --no-recursi \ - | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) ;; - *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*) - ac_configure_args="$ac_configure_args '$ac_arg'" ;; - *) ac_configure_args="$ac_configure_args $ac_arg" ;; + eval ac_val=$`echo $ac_var` + case $ac_val in + [\\/$]* | ?:[\\/]* ) ;; + *) { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2 + { (exit 1); exit 1; }; };; esac done -# NLS nuisances. -# Only set these to C if already set. These must not be set unconditionally -# because not all systems understand e.g. LANG=C (notably SCO). -# Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'! -# Non-C LC_CTYPE values break the ctype check. -if test "${LANG+set}" = set; then LANG=C; export LANG; fi -if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi -if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi -if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi +# There might be people who depend on the old broken behavior: `$host' +# used to hold the argument of --host etc. +# FIXME: To remove some day. +build=$build_alias +host=$host_alias +target=$target_alias + +# FIXME: To remove some day. +if test "x$host_alias" != x; then + if test "x$build_alias" = x; then + cross_compiling=maybe + echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used." >&2 + elif test "x$build_alias" != "x$host_alias"; then + cross_compiling=yes + fi +fi -# confdefs.h avoids OS command line length limits that DEFS can exceed. -rm -rf conftest* confdefs.h -# AIX cpp loses on an empty file, so make sure it contains at least a newline. -echo > confdefs.h +ac_tool_prefix= +test -n "$host_alias" && ac_tool_prefix=$host_alias- + +test "$silent" = yes && exec 6>/dev/null -# A filename unique to this package, relative to the directory that -# configure is in, which we can look for to find out if srcdir is correct. -ac_unique_file=tcpdump.c # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes # Try the directory containing this script, then its parent. - ac_prog=$0 - ac_confdir=`echo $ac_prog|sed 's%/[^/][^/]*$%%'` - test "x$ac_confdir" = "x$ac_prog" && ac_confdir=. + ac_confdir=`(dirname "$0") 2>/dev/null || +$as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$0" : 'X\(//\)[^/]' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| \ + . : '\(.\)' 2>/dev/null || +echo X"$0" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } + /^X\(\/\/\)[^/].*/{ s//\1/; q; } + /^X\(\/\/\)$/{ s//\1/; q; } + /^X\(\/\).*/{ s//\1/; q; } + s/.*/./; q'` srcdir=$ac_confdir if test ! -r $srcdir/$ac_unique_file; then srcdir=.. @@ -473,13 +727,440 @@ else fi if test ! -r $srcdir/$ac_unique_file; then if test "$ac_srcdir_defaulted" = yes; then - { echo "configure: error: can not find sources in $ac_confdir or .." 1>&2; exit 1; } + { echo "$as_me: error: cannot find sources ($ac_unique_file) in $ac_confdir or .." >&2 + { (exit 1); exit 1; }; } else - { echo "configure: error: can not find sources in $srcdir" 1>&2; exit 1; } + { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2 + { (exit 1); exit 1; }; } fi fi -srcdir=`echo "${srcdir}" | sed 's%\([^/]\)/*$%\1%'` +(cd $srcdir && test -r ./$ac_unique_file) 2>/dev/null || + { echo "$as_me: error: sources are in $srcdir, but \`cd $srcdir' does not work" >&2 + { (exit 1); exit 1; }; } +srcdir=`echo "$srcdir" | sed 's%\([^\\/]\)[\\/]*$%\1%'` +ac_env_build_alias_set=${build_alias+set} +ac_env_build_alias_value=$build_alias +ac_cv_env_build_alias_set=${build_alias+set} +ac_cv_env_build_alias_value=$build_alias +ac_env_host_alias_set=${host_alias+set} +ac_env_host_alias_value=$host_alias +ac_cv_env_host_alias_set=${host_alias+set} +ac_cv_env_host_alias_value=$host_alias +ac_env_target_alias_set=${target_alias+set} +ac_env_target_alias_value=$target_alias +ac_cv_env_target_alias_set=${target_alias+set} +ac_cv_env_target_alias_value=$target_alias +ac_env_CC_set=${CC+set} +ac_env_CC_value=$CC +ac_cv_env_CC_set=${CC+set} +ac_cv_env_CC_value=$CC +ac_env_CFLAGS_set=${CFLAGS+set} +ac_env_CFLAGS_value=$CFLAGS +ac_cv_env_CFLAGS_set=${CFLAGS+set} +ac_cv_env_CFLAGS_value=$CFLAGS +ac_env_LDFLAGS_set=${LDFLAGS+set} +ac_env_LDFLAGS_value=$LDFLAGS +ac_cv_env_LDFLAGS_set=${LDFLAGS+set} +ac_cv_env_LDFLAGS_value=$LDFLAGS +ac_env_CPPFLAGS_set=${CPPFLAGS+set} +ac_env_CPPFLAGS_value=$CPPFLAGS +ac_cv_env_CPPFLAGS_set=${CPPFLAGS+set} +ac_cv_env_CPPFLAGS_value=$CPPFLAGS +ac_env_CPP_set=${CPP+set} +ac_env_CPP_value=$CPP +ac_cv_env_CPP_set=${CPP+set} +ac_cv_env_CPP_value=$CPP +# +# Report the --help message. +# +if test "$ac_init_help" = "long"; then + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat <<_ACEOF +\`configure' configures this package to adapt to many kinds of systems. + +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + --help=recursive display the short help of all the included packages + -V, --version display version information and exit + -q, --quiet, --silent do not print \`checking...' messages + --cache-file=FILE cache test results in FILE [disabled] + -C, --config-cache alias for \`--cache-file=config.cache' + -n, --no-create do not create output files + --srcdir=DIR find the sources in DIR [configure dir or \`..'] + +_ACEOF + + cat <<_ACEOF +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX + [$ac_default_prefix] + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + [PREFIX] + +By default, \`make install' will install all the files in +\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify +an installation prefix other than \`$ac_default_prefix' using \`--prefix', +for instance \`--prefix=\$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --datadir=DIR read-only architecture-independent data [PREFIX/share] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc [/usr/include] + --infodir=DIR info documentation [PREFIX/info] + --mandir=DIR man documentation [PREFIX/man] +_ACEOF + + cat <<\_ACEOF + +System types: + --build=BUILD configure for building on BUILD [guessed] + --host=HOST cross-compile to build programs to run on HOST [BUILD] +_ACEOF +fi + +if test -n "$ac_init_help"; then + + cat <<\_ACEOF + +Optional Features: + --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --enable-smb enable possibly-buggy SMB printer default=yes + --disable-smb disable possibly-buggy SMB printer + --enable-ipv6 enable ipv6 (with ipv4) support + --disable-ipv6 disable ipv6 support + +Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] + --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) + --without-gcc don't use gcc + --without-crypto disable crypto support + +Some influential environment variables: + CC C compiler command + CFLAGS C compiler flags + LDFLAGS linker flags, e.g. -L if you have libraries in a + nonstandard directory + CPPFLAGS C/C++ preprocessor flags, e.g. -I if you have + headers in a nonstandard directory + CPP C preprocessor + +Use these variables to override the choices made by `configure' or to help +it to find libraries and programs with nonstandard names/locations. + +_ACEOF +fi + +if test "$ac_init_help" = "recursive"; then + # If there are subdirs, report their specific --help. + ac_popdir=`pwd` + for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue + test -d $ac_dir || continue + ac_builddir=. + +if test "$ac_dir" != .; then + ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` + # A "../" for each directory in $ac_dir_suffix. + ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'` +else + ac_dir_suffix= ac_top_builddir= +fi + +case $srcdir in + .) # No --srcdir option. We are building in place. + ac_srcdir=. + if test -z "$ac_top_builddir"; then + ac_top_srcdir=. + else + ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'` + fi ;; + [\\/]* | ?:[\\/]* ) # Absolute path. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir ;; + *) # Relative path. + ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_builddir$srcdir ;; +esac +# Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be +# absolute. +ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd` +ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd` +ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd` +ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd` + + cd $ac_dir + # Check for guested configure; otherwise get Cygnus style configure. + if test -f $ac_srcdir/configure.gnu; then + echo + $SHELL $ac_srcdir/configure.gnu --help=recursive + elif test -f $ac_srcdir/configure; then + echo + $SHELL $ac_srcdir/configure --help=recursive + elif test -f $ac_srcdir/configure.ac || + test -f $ac_srcdir/configure.in; then + echo + $ac_configure --help + else + echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + fi + cd $ac_popdir + done +fi + +test -n "$ac_init_help" && exit 0 +if $ac_init_version; then + cat <<\_ACEOF + +Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002 +Free Software Foundation, Inc. +This configure script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it. +_ACEOF + exit 0 +fi +exec 5>config.log +cat >&5 <<_ACEOF +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by $as_me, which was +generated by GNU Autoconf 2.57. Invocation command line was + + $ $0 $@ + +_ACEOF +{ +cat <<_ASUNAME +## --------- ## +## Platform. ## +## --------- ## + +hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` + +/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` +hostinfo = `(hostinfo) 2>/dev/null || echo unknown` +/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` +/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` + +_ASUNAME + +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + echo "PATH: $as_dir" +done + +} >&5 + +cat >&5 <<_ACEOF + + +## ----------- ## +## Core tests. ## +## ----------- ## + +_ACEOF + + +# Keep a trace of the command line. +# Strip out --no-create and --no-recursion so they do not pile up. +# Strip out --silent because we don't want to record it for future runs. +# Also quote any args containing shell meta-characters. +# Make two passes to allow for proper duplicate-argument suppression. +ac_configure_args= +ac_configure_args0= +ac_configure_args1= +ac_sep= +ac_must_keep_next=false +for ac_pass in 1 2 +do + for ac_arg + do + case $ac_arg in + -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + continue ;; + *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*) + ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + case $ac_pass in + 1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;; + 2) + ac_configure_args1="$ac_configure_args1 '$ac_arg'" + if test $ac_must_keep_next = true; then + ac_must_keep_next=false # Got value, back to normal. + else + case $ac_arg in + *=* | --config-cache | -C | -disable-* | --disable-* \ + | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ + | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ + | -with-* | --with-* | -without-* | --without-* | --x) + case "$ac_configure_args0 " in + "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; + esac + ;; + -* ) ac_must_keep_next=true ;; + esac + fi + ac_configure_args="$ac_configure_args$ac_sep'$ac_arg'" + # Get rid of the leading space. + ac_sep=" " + ;; + esac + done +done +$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; } +$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; } + +# When interrupted or exit'd, cleanup temporary files, and complete +# config.log. We remove comments because anyway the quotes in there +# would cause problems or look ugly. +# WARNING: Be sure not to use single quotes in there, as some shells, +# such as our DU 5.0 friend, will then `close' the trap. +trap 'exit_status=$? + # Save into config.log some information that might help in debugging. + { + echo + + cat <<\_ASBOX +## ---------------- ## +## Cache variables. ## +## ---------------- ## +_ASBOX + echo + # The following way of writing the cache mishandles newlines in values, +{ + (set) 2>&1 | + case `(ac_space='"'"' '"'"'; set | grep ac_space) 2>&1` in + *ac_space=\ *) + sed -n \ + "s/'"'"'/'"'"'\\\\'"'"''"'"'/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='"'"'\\2'"'"'/p" + ;; + *) + sed -n \ + "s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p" + ;; + esac; +} + echo + + cat <<\_ASBOX +## ----------------- ## +## Output variables. ## +## ----------------- ## +_ASBOX + echo + for ac_var in $ac_subst_vars + do + eval ac_val=$`echo $ac_var` + echo "$ac_var='"'"'$ac_val'"'"'" + done | sort + echo + + if test -n "$ac_subst_files"; then + cat <<\_ASBOX +## ------------- ## +## Output files. ## +## ------------- ## +_ASBOX + echo + for ac_var in $ac_subst_files + do + eval ac_val=$`echo $ac_var` + echo "$ac_var='"'"'$ac_val'"'"'" + done | sort + echo + fi + + if test -s confdefs.h; then + cat <<\_ASBOX +## ----------- ## +## confdefs.h. ## +## ----------- ## +_ASBOX + echo + sed "/^$/d" confdefs.h | sort + echo + fi + test "$ac_signal" != 0 && + echo "$as_me: caught signal $ac_signal" + echo "$as_me: exit $exit_status" + } >&5 + rm -f core core.* *.core && + rm -rf conftest* confdefs* conf$$* $ac_clean_files && + exit $exit_status + ' 0 +for ac_signal in 1 2 13 15; do + trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal +done +ac_signal=0 + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -rf conftest* confdefs.h +# AIX cpp loses on an empty file, so make sure it contains at least a newline. +echo >confdefs.h + +# Predefined preprocessor variables. + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_NAME "$PACKAGE_NAME" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_TARNAME "$PACKAGE_TARNAME" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_VERSION "$PACKAGE_VERSION" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_STRING "$PACKAGE_STRING" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" +_ACEOF + + +# Let the site file select an alternate cache file if it wants to. # Prefer explicitly selected file to automatically selected ones. if test -z "$CONFIG_SITE"; then if test "x$prefix" != xNONE; then @@ -490,39 +1171,103 @@ if test -z "$CONFIG_SITE"; then fi for ac_site_file in $CONFIG_SITE; do if test -r "$ac_site_file"; then - echo "loading site script $ac_site_file" + { echo "$as_me:$LINENO: loading site script $ac_site_file" >&5 +echo "$as_me: loading site script $ac_site_file" >&6;} + sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" fi done if test -r "$cache_file"; then - echo "loading cache $cache_file" - . $cache_file + # Some versions of bash will fail to source /dev/null (special + # files actually), so we avoid doing that. + if test -f "$cache_file"; then + { echo "$as_me:$LINENO: loading cache $cache_file" >&5 +echo "$as_me: loading cache $cache_file" >&6;} + case $cache_file in + [\\/]* | ?:[\\/]* ) . $cache_file;; + *) . ./$cache_file;; + esac + fi else - echo "creating cache $cache_file" - > $cache_file + { echo "$as_me:$LINENO: creating cache $cache_file" >&5 +echo "$as_me: creating cache $cache_file" >&6;} + >$cache_file +fi + +# Check that the precious variables saved in the cache have kept the same +# value. +ac_cache_corrupted=false +for ac_var in `(set) 2>&1 | + sed -n 's/^ac_env_\([a-zA-Z_0-9]*\)_set=.*/\1/p'`; do + eval ac_old_set=\$ac_cv_env_${ac_var}_set + eval ac_new_set=\$ac_env_${ac_var}_set + eval ac_old_val="\$ac_cv_env_${ac_var}_value" + eval ac_new_val="\$ac_env_${ac_var}_value" + case $ac_old_set,$ac_new_set in + set,) + { echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,set) + { echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5 +echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,);; + *) + if test "x$ac_old_val" != "x$ac_new_val"; then + { echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5 +echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + { echo "$as_me:$LINENO: former value: $ac_old_val" >&5 +echo "$as_me: former value: $ac_old_val" >&2;} + { echo "$as_me:$LINENO: current value: $ac_new_val" >&5 +echo "$as_me: current value: $ac_new_val" >&2;} + ac_cache_corrupted=: + fi;; + esac + # Pass precious variables to config.status. + if test "$ac_new_set" = set; then + case $ac_new_val in + *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*) + ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *) ac_arg=$ac_var=$ac_new_val ;; + esac + case " $ac_configure_args " in + *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. + *) ac_configure_args="$ac_configure_args '$ac_arg'" ;; + esac + fi +done +if $ac_cache_corrupted; then + { echo "$as_me:$LINENO: error: changes in the environment can compromise the build" >&5 +echo "$as_me: error: changes in the environment can compromise the build" >&2;} + { { echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5 +echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;} + { (exit 1); exit 1; }; } fi ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross - -ac_exeext= -ac_objext=o -if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then - # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu. - if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then - ac_n= ac_c=' -' ac_t=' ' - else - ac_n=-n ac_c= ac_t= - fi -else - ac_n= ac_c='\c' ac_t= -fi +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + + + + + + + + + + + + + + + @@ -536,161 +1281,132 @@ for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/install.sh -c" break + elif test -f $ac_dir/shtool; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/shtool install -c" + break fi done if test -z "$ac_aux_dir"; then - { echo "configure: error: can not find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." 1>&2; exit 1; } + { { echo "$as_me:$LINENO: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&5 +echo "$as_me: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&2;} + { (exit 1); exit 1; }; } fi -ac_config_guess=$ac_aux_dir/config.guess -ac_config_sub=$ac_aux_dir/config.sub -ac_configure=$ac_aux_dir/configure # This should be Cygnus configure. +ac_config_guess="$SHELL $ac_aux_dir/config.guess" +ac_config_sub="$SHELL $ac_aux_dir/config.sub" +ac_configure="$SHELL $ac_aux_dir/configure" # This should be Cygnus configure. +# Make sure we can run config.sub. +$ac_config_sub sun4 >/dev/null 2>&1 || + { { echo "$as_me:$LINENO: error: cannot run $ac_config_sub" >&5 +echo "$as_me: error: cannot run $ac_config_sub" >&2;} + { (exit 1); exit 1; }; } -# 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 - +echo "$as_me:$LINENO: checking build system type" >&5 +echo $ECHO_N "checking build system type... $ECHO_C" >&6 +if test "${ac_cv_build+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_cv_build_alias=$build_alias +test -z "$ac_cv_build_alias" && + ac_cv_build_alias=`$ac_config_guess` +test -z "$ac_cv_build_alias" && + { { echo "$as_me:$LINENO: error: cannot guess build type; you must specify one" >&5 +echo "$as_me: error: cannot guess build type; you must specify one" >&2;} + { (exit 1); exit 1; }; } +ac_cv_build=`$ac_config_sub $ac_cv_build_alias` || + { { echo "$as_me:$LINENO: error: $ac_config_sub $ac_cv_build_alias failed" >&5 +echo "$as_me: error: $ac_config_sub $ac_cv_build_alias failed" >&2;} + { (exit 1); exit 1; }; } -# 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 "$as_me:$LINENO: result: $ac_cv_build" >&5 +echo "${ECHO_T}$ac_cv_build" >&6 +build=$ac_cv_build +build_cpu=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'` +build_vendor=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` +build_os=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` -echo $ac_n "checking host system type""... $ac_c" 1>&6 -echo "configure:577: checking host system type" >&5 -host_alias=$host -case "$host_alias" in -NONE) - case $nonopt in - NONE) - if host_alias=`${CONFIG_SHELL-/bin/sh} $ac_config_guess`; then : - else { echo "configure: error: can not guess host type; you must specify one" 1>&2; exit 1; } - fi ;; - *) host_alias=$nonopt ;; - esac ;; -esac +echo "$as_me:$LINENO: checking host system type" >&5 +echo $ECHO_N "checking host system type... $ECHO_C" >&6 +if test "${ac_cv_host+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_cv_host_alias=$host_alias +test -z "$ac_cv_host_alias" && + ac_cv_host_alias=$ac_cv_build_alias +ac_cv_host=`$ac_config_sub $ac_cv_host_alias` || + { { echo "$as_me:$LINENO: error: $ac_config_sub $ac_cv_host_alias failed" >&5 +echo "$as_me: error: $ac_config_sub $ac_cv_host_alias failed" >&2;} + { (exit 1); exit 1; }; } -host=`${CONFIG_SHELL-/bin/sh} $ac_config_sub $host_alias` -host_cpu=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'` -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:598: 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 +fi +echo "$as_me:$LINENO: result: $ac_cv_host" >&5 +echo "${ECHO_T}$ac_cv_host" >&6 +host=$ac_cv_host +host_cpu=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'` +host_vendor=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` +host_os=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` -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:616: 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}- -umask 002 -if test -z "$PWD" ; then - PWD=`pwd` -fi - - - - # Check whether --with-gcc or --without-gcc was given. +# Check whether --with-gcc or --without-gcc was given. if test "${with_gcc+set}" = set; then withval="$with_gcc" - : -fi +fi; V_CCOPT="-O" V_INCLS="" if test "${srcdir}" != "." ; then - V_INCLS="-I\$\(srcdir\)" + V_INCLS="-I\$(srcdir)" fi if test "${CFLAGS+set}" = set; then 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: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 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_SHLICC2+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else if test -n "$SHLICC2"; then ac_cv_prog_SHLICC2="$SHLICC2" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then - ac_cv_prog_SHLICC2="yes" - break - fi - done - IFS="$ac_save_ifs" +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_SHLICC2="yes" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + test -z "$ac_cv_prog_SHLICC2" && ac_cv_prog_SHLICC2="no" fi fi -SHLICC2="$ac_cv_prog_SHLICC2" +SHLICC2=$ac_cv_prog_SHLICC2 if test -n "$SHLICC2"; then - echo "$ac_t""$SHLICC2" 1>&6 + echo "$as_me:$LINENO: result: $SHLICC2" >&5 +echo "${ECHO_T}$SHLICC2" >&6 else - echo "$ac_t""no" 1>&6 + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 fi if test $SHLICC2 = yes ; then @@ -704,214 +1420,643 @@ fi CC=cc export CC fi - # Extract the first word of "gcc", so it can be a program name with args. + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # 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: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 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="gcc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + + CC=$ac_ct_CC +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then - ac_cv_prog_CC="gcc" - break - fi - done - IFS="$ac_save_ifs" +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + fi fi -CC="$ac_cv_prog_CC" +CC=$ac_cv_prog_CC if test -n "$CC"; then - echo "$ac_t""$CC" 1>&6 + echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="cc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + + CC=$ac_ct_CC else - echo "$ac_t""no" 1>&6 + CC="$ac_cv_prog_CC" fi +fi 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: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 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" ac_prog_rejected=no - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then - if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then - ac_prog_rejected=yes - continue - fi - ac_cv_prog_CC="cc" - break - fi - done - IFS="$ac_save_ifs" +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + if test $ac_prog_rejected = yes; then # We found a bogon in the path, so make sure we never use it. set dummy $ac_cv_prog_CC shift - if test $# -gt 0; then + if test $# != 0; then # We chose a different compiler from the bogus one. # However, it has the same basename, so the bogon will be chosen # first if we set CC to just the basename; use the full file name. shift - set dummy "$ac_dir/$ac_word" "$@" - shift - ac_cv_prog_CC="$@" + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" fi fi fi fi -CC="$ac_cv_prog_CC" +CC=$ac_cv_prog_CC if test -n "$CC"; then - echo "$ac_t""$CC" 1>&6 + echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6 else - echo "$ac_t""no" 1>&6 + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 fi - if test -z "$CC"; then - case "`uname -s`" in - *win32* | *WIN32*) - # 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: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 +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then - ac_cv_prog_CC="cl" - break - fi - done - IFS="$ac_save_ifs" +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + fi fi -CC="$ac_cv_prog_CC" +CC=$ac_cv_prog_CC if test -n "$CC"; then - echo "$ac_t""$CC" 1>&6 + echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6 else - echo "$ac_t""no" 1>&6 -fi - ;; - esac - fi - test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; } + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 fi -echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:824: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done -ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi -cat > conftest.$ac_ext << EOF + test -n "$ac_ct_CC" && break +done -#line 835 "configure" -#include "confdefs.h" + CC=$ac_ct_CC +fi + +fi + + +test -z "$CC" && { { echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH +See \`config.log' for more details." >&5 +echo "$as_me: error: no acceptable C compiler found in \$PATH +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } + +# Provide some information about the compiler. +echo "$as_me:$LINENO:" \ + "checking for C compiler version" >&5 +ac_compiler=`set X $ac_compile; echo $2` +{ (eval echo "$as_me:$LINENO: \"$ac_compiler --version &5\"") >&5 + (eval $ac_compiler --version &5) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (eval echo "$as_me:$LINENO: \"$ac_compiler -v &5\"") >&5 + (eval $ac_compiler -v &5) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (eval echo "$as_me:$LINENO: \"$ac_compiler -V &5\"") >&5 + (eval $ac_compiler -V &5) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } + +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ -main(){return(0);} -EOF -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 - ac_cv_prog_cc_cross=no + ; + return 0; +} +_ACEOF +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files a.out a.exe b.out" +# Try to create an executable without -o first, disregard a.out. +# It will help us diagnose broken compilers, and finding out an intuition +# of exeext. +echo "$as_me:$LINENO: checking for C compiler default output" >&5 +echo $ECHO_N "checking for C compiler default output... $ECHO_C" >&6 +ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` +if { (eval echo "$as_me:$LINENO: \"$ac_link_default\"") >&5 + (eval $ac_link_default) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + # Find the output, starting from the most likely. This scheme is +# not robust to junk in `.', hence go to wildcards (a.*) only as a last +# resort. + +# Be careful to initialize this variable, since it used to be cached. +# Otherwise an old cache value of `no' led to `EXEEXT = no' in a Makefile. +ac_cv_exeext= +# b.out is created by i960 compilers. +for ac_file in a_out.exe a.exe conftest.exe a.out conftest a.* conftest.* b.out +do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj ) + ;; + conftest.$ac_ext ) + # This is the source file. + ;; + [ab].out ) + # We found the default executable, but exeext='' is most + # certainly right. + break;; + *.* ) + ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + # FIXME: I believe we export ac_cv_exeext for Libtool, + # but it would be cool to find out if it's true. Does anybody + # maintain Libtool? --akim. + export ac_cv_exeext + break;; + * ) + break;; + esac +done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { echo "$as_me:$LINENO: error: C compiler cannot create executables +See \`config.log' for more details." >&5 +echo "$as_me: error: C compiler cannot create executables +See \`config.log' for more details." >&2;} + { (exit 77); exit 77; }; } +fi + +ac_exeext=$ac_cv_exeext +echo "$as_me:$LINENO: result: $ac_file" >&5 +echo "${ECHO_T}$ac_file" >&6 + +# Check the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +echo "$as_me:$LINENO: checking whether the C compiler works" >&5 +echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6 +# FIXME: These cross compiler hacks should be removed for Autoconf 3.0 +# If not cross compiling, check that we can run a simple program. +if test "$cross_compiling" != yes; then + if { ac_try='./$ac_file' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + cross_compiling=no else - ac_cv_prog_cc_cross=yes + if test "$cross_compiling" = maybe; then + cross_compiling=yes + else + { { echo "$as_me:$LINENO: error: cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } + fi fi -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - ac_cv_prog_cc_works=no -fi -rm -fr conftest* -ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross - -echo "$ac_t""$ac_cv_prog_cc_works" 1>&6 -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: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 "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 + +rm -f a.out a.exe conftest$ac_cv_exeext b.out +ac_clean_files=$ac_clean_files_save +# Check the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +echo "$as_me:$LINENO: checking whether we are cross compiling" >&5 +echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6 +echo "$as_me:$LINENO: result: $cross_compiling" >&5 +echo "${ECHO_T}$cross_compiling" >&6 + +echo "$as_me:$LINENO: checking for suffix of executables" >&5 +echo $ECHO_N "checking for suffix of executables... $ECHO_C" >&6 +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + # If both `conftest.exe' and `conftest' are `present' (well, observable) +# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will +# work properly (i.e., refer to `conftest.exe'), while it won't with +# `rm'. +for ac_file in conftest.exe conftest conftest.*; do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj ) ;; + *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + export ac_cv_exeext + break;; + * ) break;; + esac +done +else + { { echo "$as_me:$LINENO: error: cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + +rm -f conftest$ac_cv_exeext +echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5 +echo "${ECHO_T}$ac_cv_exeext" >&6 + +rm -f conftest.$ac_ext +EXEEXT=$ac_cv_exeext +ac_exeext=$EXEEXT +echo "$as_me:$LINENO: checking for suffix of object files" >&5 +echo $ECHO_N "checking for suffix of object files... $ECHO_C" >&6 +if test "${ac_cv_objext+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ -echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 -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 + ; + return 0; +} +_ACEOF +rm -f conftest.o conftest.obj +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + for ac_file in `(ls conftest.o conftest.obj; ls conftest.*) 2>/dev/null`; do + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg ) ;; + *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` + break;; + esac +done else - cat > conftest.c <&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { echo "$as_me:$LINENO: error: cannot compute suffix of object files: cannot compile +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute suffix of object files: cannot compile +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + +rm -f conftest.$ac_cv_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_objext" >&5 +echo "${ECHO_T}$ac_cv_objext" >&6 +OBJEXT=$ac_cv_objext +ac_objext=$OBJEXT +echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5 +echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6 +if test "${ac_cv_c_compiler_gnu+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me #endif -EOF -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 -fi -fi -echo "$ac_t""$ac_cv_prog_gcc" 1>&6 - -if test $ac_cv_prog_gcc = yes; then - GCC=yes -else - GCC= -fi + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_compiler_gnu=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_compiler_gnu=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5 +echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6 +GCC=`test $ac_compiler_gnu = yes && echo yes` +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +CFLAGS="-g" +echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5 +echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6 +if test "${ac_cv_prog_cc_g+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ -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: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 - echo 'void f(){}' > conftest.c -if test -z "`${CC-cc} -g -c conftest.c 2>&1`"; then + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then ac_cv_prog_cc_g=yes else - ac_cv_prog_cc_g=no -fi -rm -f conftest* + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 +ac_cv_prog_cc_g=no fi - -echo "$ac_t""$ac_cv_prog_cc_g" 1>&6 +rm -f conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5 +echo "${ECHO_T}$ac_cv_prog_cc_g" >&6 if test "$ac_test_CFLAGS" = set; then - CFLAGS="$ac_save_CFLAGS" + CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then CFLAGS="-g -O2" @@ -925,16 +2070,233 @@ else CFLAGS= fi fi +echo "$as_me:$LINENO: checking for $CC option to accept ANSI C" >&5 +echo $ECHO_N "checking for $CC option to accept ANSI C... $ECHO_C" >&6 +if test "${ac_cv_prog_cc_stdc+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_cv_prog_cc_stdc=no +ac_save_CC=$CC +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#include +#include +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +# Don't try gcc -ansi; that turns off useful extensions and +# breaks some systems' header files. +# AIX -qlanglvl=ansi +# Ultrix and OSF/1 -std1 +# HP-UX 10.20 and later -Ae +# HP-UX older versions -Aa -D_HPUX_SOURCE +# SVR4 -Xc -D__EXTENSIONS__ +for ac_arg in "" -qlanglvl=ansi -std1 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_prog_cc_stdc=$ac_arg +break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext +done +rm -f conftest.$ac_ext conftest.$ac_objext +CC=$ac_save_CC + +fi + +case "x$ac_cv_prog_cc_stdc" in + x|xno) + echo "$as_me:$LINENO: result: none needed" >&5 +echo "${ECHO_T}none needed" >&6 ;; + *) + echo "$as_me:$LINENO: result: $ac_cv_prog_cc_stdc" >&5 +echo "${ECHO_T}$ac_cv_prog_cc_stdc" >&6 + CC="$CC $ac_cv_prog_cc_stdc" ;; +esac + +# Some people use a C++ compiler to compile C. Since we use `exit', +# in C++ we need to declare it. In case someone uses the same compiler +# for both compiling C and C++ we need to have the C++ compiler decide +# the declaration of exit, since it's the most demanding environment. +cat >conftest.$ac_ext <<_ACEOF +#ifndef __cplusplus + choke me +#endif +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + for ac_declaration in \ + ''\ + '#include ' \ + 'extern "C" void std::exit (int) throw (); using std::exit;' \ + 'extern "C" void std::exit (int); using std::exit;' \ + 'extern "C" void exit (int) throw ();' \ + 'extern "C" void exit (int);' \ + 'void exit (int);' +do + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +$ac_declaration +int +main () +{ +exit (42); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +continue +fi +rm -f conftest.$ac_objext conftest.$ac_ext + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_declaration +int +main () +{ +exit (42); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext conftest.$ac_ext +done +rm -f conftest* +if test -n "$ac_declaration"; then + echo '#ifdef __cplusplus' >>confdefs.h + echo $ac_declaration >>confdefs.h + echo '#endif' >>confdefs.h +fi + +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext conftest.$ac_ext +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu if test "$GCC" = yes ; then if test "$SHLICC2" = yes ; then ac_cv_lbl_gcc_vers=2 V_CCOPT="-O2" else - echo $ac_n "checking gcc version""... $ac_c" 1>&6 -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 + echo "$as_me:$LINENO: checking gcc version" >&5 +echo $ECHO_N "checking gcc version... $ECHO_C" >&6 + if test "${ac_cv_lbl_gcc_vers+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else ac_cv_lbl_gcc_vers=`$CC -v 2>&1 | \ sed -e '/^gcc version /!d' \ @@ -943,1608 +2305,6781 @@ else -e 's/\..*//'` fi - echo "$ac_t""$ac_cv_lbl_gcc_vers" 1>&6 + echo "$as_me:$LINENO: result: $ac_cv_lbl_gcc_vers" >&5 +echo "${ECHO_T}$ac_cv_lbl_gcc_vers" >&6 if test $ac_cv_lbl_gcc_vers -gt 1 ; then V_CCOPT="-O2" fi fi else - echo $ac_n "checking that $CC handles ansi prototypes""... $ac_c" 1>&6 -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 <&5 +echo $ECHO_N "checking that $CC handles ansi prototypes... $ECHO_C" >&6 + if test "${ac_cv_lbl_cc_ansi_prototypes+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ #include -int main() { +int +main () +{ int frob(int, char *) -; return 0; } -EOF -if { (eval echo configure:966: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then - rm -rf conftest* + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then ac_cv_lbl_cc_ansi_prototypes=yes else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - ac_cv_lbl_cc_ansi_prototypes=no + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lbl_cc_ansi_prototypes=no fi -rm -f conftest* +rm -f conftest.$ac_objext conftest.$ac_ext fi - echo "$ac_t""$ac_cv_lbl_cc_ansi_prototypes" 1>&6 + echo "$as_me:$LINENO: result: $ac_cv_lbl_cc_ansi_prototypes" >&5 +echo "${ECHO_T}$ac_cv_lbl_cc_ansi_prototypes" >&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:984: checking for HP-UX ansi compiler ($CC -Aa -D_HPUX_SOURCE)" >&5 + echo "$as_me:$LINENO: checking for HP-UX ansi compiler ($CC -Aa -D_HPUX_SOURCE)" >&5 +echo $ECHO_N "checking for HP-UX ansi compiler ($CC -Aa -D_HPUX_SOURCE)... $ECHO_C" >&6 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 <&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ #include -int main() { +int +main () +{ int frob(int, char *) -; return 0; } -EOF -if { (eval echo configure:998: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then - rm -rf conftest* + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then ac_cv_lbl_cc_hpux_cc_aa=yes else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - ac_cv_lbl_cc_hpux_cc_aa=no + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lbl_cc_hpux_cc_aa=no fi -rm -f conftest* +rm -f conftest.$ac_objext conftest.$ac_ext fi - echo "$ac_t""$ac_cv_lbl_cc_hpux_cc_aa" 1>&6 + echo "$as_me:$LINENO: result: $ac_cv_lbl_cc_hpux_cc_aa" >&5 +echo "${ECHO_T}$ac_cv_lbl_cc_hpux_cc_aa" >&6 if test $ac_cv_lbl_cc_hpux_cc_aa = no ; then - { echo "configure: error: see the INSTALL doc for more info" 1>&2; exit 1; } + { { echo "$as_me:$LINENO: error: see the INSTALL doc for more info" >&5 +echo "$as_me: error: see the INSTALL doc for more info" >&2;} + { (exit 1); exit 1; }; } fi CFLAGS="$savedcflags" V_CCOPT="-Aa $V_CCOPT" - cat >> confdefs.h <<\EOF + cat >>confdefs.h <<\_ACEOF #define _HPUX_SOURCE 1 -EOF +_ACEOF ;; *) - { echo "configure: error: see the INSTALL doc for more info" 1>&2; exit 1; } + { { echo "$as_me:$LINENO: error: see the INSTALL doc for more info" >&5 +echo "$as_me: error: see the INSTALL doc for more info" >&2;} + { (exit 1); exit 1; }; } ;; esac fi 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: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 <&5 +echo $ECHO_N "checking that Ultrix $CC hacks const in prototypes... $ECHO_C" >&6 + if test "${ac_cv_lbl_cc_const_proto+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ #include -int main() { +int +main () +{ struct a { int b; }; void c(const struct a *) -; return 0; } -EOF -if { (eval echo configure:1055: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then - rm -rf conftest* + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then ac_cv_lbl_cc_const_proto=yes else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - ac_cv_lbl_cc_const_proto=no + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lbl_cc_const_proto=no fi -rm -f conftest* +rm -f conftest.$ac_objext conftest.$ac_ext fi - echo "$ac_t""$ac_cv_lbl_cc_const_proto" 1>&6 + echo "$as_me:$LINENO: result: $ac_cv_lbl_cc_const_proto" >&5 +echo "${ECHO_T}$ac_cv_lbl_cc_const_proto" >&6 if test $ac_cv_lbl_cc_const_proto = no ; then - cat >> confdefs.h <<\EOF -#define const -EOF + cat >>confdefs.h <<\_ACEOF +#define const +_ACEOF fi ;; esac fi +echo "$as_me:$LINENO: checking for inline" >&5 +echo $ECHO_N "checking for inline... $ECHO_C" >&6 + if test "${ac_cv_lbl_inline+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + + ac_cv_lbl_inline="" + ac_lbl_cc_inline=no + for ac_lbl_inline in inline __inline__ __inline + do + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#define inline $ac_lbl_inline + static inline struct iltest *foo(void); + struct iltest { + int iltest1; + int iltest2; + }; + + static inline struct iltest * + foo() + { + static struct iltest xxx; + + return &xxx; + } +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_lbl_cc_inline=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext conftest.$ac_ext + if test "$ac_lbl_cc_inline" = yes ; then + break; + fi + done + if test "$ac_lbl_cc_inline" = yes ; then + ac_cv_lbl_inline=$ac_lbl_inline + fi +fi + + if test ! -z "$ac_cv_lbl_inline" ; then + echo "$as_me:$LINENO: result: $ac_cv_lbl_inline" >&5 +echo "${ECHO_T}$ac_cv_lbl_inline" >&6 + else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 + fi + +cat >>confdefs.h <<_ACEOF +#define inline $ac_cv_lbl_inline +_ACEOF + + +echo "$as_me:$LINENO: checking for __attribute__" >&5 +echo $ECHO_N "checking for __attribute__... $ECHO_C" >&6 +if test "${ac_cv___attribute__+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +#include + +int +main () +{ + +static void foo(void) __attribute__ ((noreturn)); + +static void +foo(void) +{ + exit(1); +} + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv___attribute__=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv___attribute__=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi + +if test "$ac_cv___attribute__" = "yes"; then + +cat >>confdefs.h <<\_ACEOF +#define HAVE___ATTRIBUTE__ 1 +_ACEOF -echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 -echo "configure:1080: checking how to run the C preprocessor" >&5 + V_DEFS="$V_DEFS -D_U_=\"__attribute__((unused))\"" +else + V_DEFS="$V_DEFS -D_U_=\"\"" +fi +echo "$as_me:$LINENO: result: $ac_cv___attribute__" >&5 +echo "${ECHO_T}$ac_cv___attribute__" >&6 + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5 +echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6 # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= fi if test -z "$CPP"; then -if eval "test \"`echo '$''{'ac_cv_prog_CPP'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - # This must be in double quotes, not single quotes, because CPP may get - # substituted into the Makefile and "${CC-cc}" will confuse make. - CPP="${CC-cc} -E" + if test "${ac_cv_prog_CPP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + # Double quotes because CPP needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" + do + ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. - cat > conftest.$ac_ext < -Syntax Error -EOF -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1101: \"$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 - : + # not just through cpp. "Syntax error" is here to catch this case. + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 + (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + else + ac_cpp_err= + fi else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - CPP="${CC-cc} -E -traditional-cpp" - cat > conftest.$ac_ext < -Syntax Error -EOF -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1118: \"$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 + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then : else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - CPP="${CC-cc} -nologo -E" - cat > conftest.$ac_ext < -Syntax Error -EOF -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1135: \"$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 - : + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether non-existent headers + # can be detected and how. + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 + (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + else + ac_cpp_err= + fi else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - CPP=/lib/cpp + ac_cpp_err=yes fi -rm -f conftest* +if test -z "$ac_cpp_err"; then + # Broken: success on invalid input. +continue +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Passes both tests. +ac_preproc_ok=: +break fi -rm -f conftest* +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then + break fi -rm -f conftest* - ac_cv_prog_CPP="$CPP" + + done + ac_cv_prog_CPP=$CPP + fi - CPP="$ac_cv_prog_CPP" + CPP=$ac_cv_prog_CPP else - ac_cv_prog_CPP="$CPP" + ac_cv_prog_CPP=$CPP fi -echo "$ac_t""$CPP" 1>&6 - -for ac_hdr in fcntl.h malloc.h memory.h rpc/rpcent.h +echo "$as_me:$LINENO: result: $CPP" >&5 +echo "${ECHO_T}$CPP" >&6 +ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes do -ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` -echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1163: 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 -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1173: \"$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* - eval "ac_cv_header_$ac_safe=yes" -else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_header_$ac_safe=no" -fi -rm -f conftest* -fi -if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'` - cat >> confdefs.h < to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 + (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + else + ac_cpp_err= + fi else - echo "$ac_t""no" 1>&6 + ac_cpp_err=yes fi -done - -echo $ac_n "checking whether time.h and sys/time.h may both be included""... $ac_c" 1>&6 -echo "configure:1200: 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 +if test -z "$ac_cpp_err"; then + : else - cat > conftest.$ac_ext < -#include -#include -int main() { -struct tm *tp; -; return 0; } -EOF -if { (eval echo configure:1214: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then - rm -rf conftest* - ac_cv_header_time=yes + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether non-existent headers + # can be detected and how. + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 + (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + else + ac_cpp_err= + fi else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - ac_cv_header_time=no -fi -rm -f conftest* + ac_cpp_err=yes fi +if test -z "$ac_cpp_err"; then + # Broken: success on invalid input. +continue +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 -echo "$ac_t""$ac_cv_header_time" 1>&6 -if test $ac_cv_header_time = yes; then - cat >> confdefs.h <<\EOF -#define TIME_WITH_SYS_TIME 1 -EOF + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.$ac_ext +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then + : +else + { { echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details." >&5 +echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu -case "$target_os" in -linux*) - echo $ac_n "checking Linux kernel version""... $ac_c" 1>&6 -echo "configure:1239: checking Linux kernel version" >&5 - if eval "test \"`echo '$''{'ac_cv_linux_vers'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 +echo "$as_me:$LINENO: checking for egrep" >&5 +echo $ECHO_N "checking for egrep... $ECHO_C" >&6 +if test "${ac_cv_prog_egrep+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - ac_cv_linux_vers=`uname -r 2>&1 | \ - sed -n -e '$s/.* //' -e '$s/\..*//p'` + if echo a | (grep -E '(a|b)') >/dev/null 2>&1 + then ac_cv_prog_egrep='grep -E' + else ac_cv_prog_egrep='egrep' + fi fi +echo "$as_me:$LINENO: result: $ac_cv_prog_egrep" >&5 +echo "${ECHO_T}$ac_cv_prog_egrep" >&6 + EGREP=$ac_cv_prog_egrep + + +echo "$as_me:$LINENO: checking for ANSI C header files" >&5 +echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6 +if test "${ac_cv_header_stdc+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ - echo "$ac_t""$ac_cv_linux_vers" 1>&6 - if test $ac_cv_linux_vers -lt 2 ; then - { echo "configure: error: version 2 or higher required; see the INSTALL doc for more info" 1>&2; exit 1; } - fi - cat >> confdefs.h <<\EOF -#define HAVE_NET_SLIP_H 1 -EOF - - ;; - -*) - for ac_hdr in net/slip.h -do -ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` -echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1262: 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 -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1272: \"$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* - eval "ac_cv_header_$ac_safe=yes" -else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_header_$ac_safe=no" + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_header_stdc=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_header_stdc=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then + : +else + ac_cv_header_stdc=no fi rm -f conftest* + fi -if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'` - cat >> confdefs.h <&6 -fi -done - ;; -esac +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include -echo $ac_n "checking if --enable-ipv6 option is specified""... $ac_c" 1>&6 -echo "configure:1302: checking if --enable-ipv6 option is specified" >&5 -# Check whether --enable-ipv6 or --disable-ipv6 was given. -if test "${enable_ipv6+set}" = set; then - enableval="$enable_ipv6" +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then : +else + ac_cv_header_stdc=no fi +rm -f conftest* -echo "$ac_t""${enable_ipv6-no}" 1>&6 -if test "$enable_ipv6" = "yes"; then - cat >> confdefs.h <<\EOF -#define INET6 1 -EOF - - LOCALSRC="print-ip6.c print-ip6opts.c print-ripng.c print-icmp6.c print-frag6.c print-rt6.c print-ospf6.c $LOCALSRC" - LIBS="$LIBS -L../libinet6 -L../libinet6/obj -L/usr/local/v6/lib" - for ac_func in getaddrinfo -do -echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1320: 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 < -/* 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 $ac_func(); - -int main() { +fi -/* 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_$ac_func) || defined (__stub___$ac_func) -choke me +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then + : +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) #else -$ac_func(); +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) #endif -; return 0; } -EOF -if { (eval echo configure:1348: \"$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" +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + exit(2); + exit (0); +} +_ACEOF +rm -f conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + : else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_func_$ac_func=no" + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +ac_cv_header_stdc=no +fi +rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext fi -rm -f conftest* fi +fi +echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5 +echo "${ECHO_T}$ac_cv_header_stdc" >&6 +if test $ac_cv_header_stdc = yes; then -if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'` - cat >> confdefs.h <&6 -echo $ac_n "checking for getaddrinfo in -linet6""... $ac_c" 1>&6 -echo "configure:1370: checking for getaddrinfo in -linet6" >&5 -ac_lib_var=`echo inet6'_'getaddrinfo | 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="-linet6 $LIBS" -cat > conftest.$ac_ext <>confdefs.h <<\_ACEOF +#define STDC_HEADERS 1 +_ACEOF -int main() { -getaddrinfo() -; return 0; } -EOF -if { (eval echo configure:1389: \"$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 inet6 | sed -e 's/^a-zA-Z0-9_/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` - cat >> confdefs.h <&6 -fi -fi -done -fi -for ac_func in vfprintf strcasecmp -do -echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1424: 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 < -/* 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 $ac_func(); -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_$ac_func) || defined (__stub___$ac_func) -choke me -#else -$ac_func(); -#endif -; return 0; } -EOF -if { (eval echo configure:1452: \"$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 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_func_$ac_func=no" -fi -rm -f conftest* -fi -if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'` - cat >> confdefs.h <&6 -LIBOBJS="$LIBOBJS ${ac_func}.${ac_objext}" +for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ + inttypes.h stdint.h unistd.h +do +as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + +#include <$ac_header> +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_Header=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_Header=no" +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 +if test `eval echo '${'$as_ac_Header'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + fi + done -for ac_func in ether_ntoa setlinebuf -do -echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1481: 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 < -/* 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 $ac_func(); -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_$ac_func) || defined (__stub___$ac_func) -choke me -#else -$ac_func(); -#endif -; return 0; } -EOF -if { (eval echo configure:1509: \"$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" + +for ac_header in fcntl.h rpc/rpcent.h netdnet/dnetdb.h netinet/ether.h +do +as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 +else + # Is the header compilable? +echo "$as_me:$LINENO: checking $ac_header usability" >&5 +echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +#include <$ac_header> +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_header_compiler=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_header_compiler=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +echo "${ECHO_T}$ac_header_compiler" >&6 + +# Is the header present? +echo "$as_me:$LINENO: checking $ac_header presence" >&5 +echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <$ac_header> +_ACEOF +if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 + (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then + ac_header_preproc=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_preproc=no +fi +rm -f conftest.err conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +echo "${ECHO_T}$ac_header_preproc" >&6 + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc in + yes:no ) + { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 +echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} + ( + cat <<\_ASBOX +## ------------------------------------ ## +## Report this to bug-autoconf@gnu.org. ## +## ------------------------------------ ## +_ASBOX + ) | + sed "s/^/$as_me: WARNING: /" >&2 + ;; + no:yes ) + { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 +echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 +echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} + ( + cat <<\_ASBOX +## ------------------------------------ ## +## Report this to bug-autoconf@gnu.org. ## +## ------------------------------------ ## +_ASBOX + ) | + sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac +echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_func_$ac_func=no" + eval "$as_ac_Header=$ac_header_preproc" fi -rm -f conftest* +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 + fi +if test `eval echo '${'$as_ac_Header'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF -if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'` - cat >> confdefs.h <&6 fi -done +done -echo $ac_n "checking whether byte ordering is bigendian""... $ac_c" 1>&6 -echo "configure:1535: 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 < -#include -int main() { -#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN - bogus endian macros -#endif -; return 0; } -EOF -if { (eval echo configure:1553: \"$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 <&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ #include -#include -int main() { +#include -#if BYTE_ORDER != BIG_ENDIAN - not big endian -#endif -; return 0; } -EOF -if { (eval echo configure:1568: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then - rm -rf conftest* - ac_cv_c_bigendian=yes +#include <$ac_header> +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_Header=yes" else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - ac_cv_c_bigendian=no + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_Header=no" fi -rm -f conftest* -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 +rm -f conftest.$ac_objext conftest.$ac_ext 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 <&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 +if test `eval echo '${'$as_ac_Header'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + +echo "$as_me:$LINENO: checking whether time.h and sys/time.h may both be included" >&5 +echo $ECHO_N "checking whether time.h and sys/time.h may both be included... $ECHO_C" >&6 +if test "${ac_cv_header_time+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#include + +int +main () +{ +if ((struct tm *) 0) +return 0; + ; + return 0; } -EOF -if { (eval echo configure:1601: \"$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 +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_header_time=yes 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 + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 +ac_cv_header_time=no fi +rm -f conftest.$ac_objext conftest.$ac_ext fi +echo "$as_me:$LINENO: result: $ac_cv_header_time" >&5 +echo "${ECHO_T}$ac_cv_header_time" >&6 +if test $ac_cv_header_time = yes; then -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 +cat >>confdefs.h <<\_ACEOF +#define TIME_WITH_SYS_TIME 1 +_ACEOF fi -echo $ac_n "checking for main in -ldnet""... $ac_c" 1>&6 -echo "configure:1626: 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 <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then - rm -rf conftest* - eval "ac_cv_lib_$ac_lib_var=yes" +linux*) + echo "$as_me:$LINENO: checking Linux kernel version" >&5 +echo $ECHO_N "checking Linux kernel version... $ECHO_C" >&6 + if test "$cross_compiling" = yes; then + if test "${ac_cv_linux_vers+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_lib_$ac_lib_var=no" + ac_cv_linux_vers=unknown fi -rm -f conftest* -LIBS="$ac_save_LIBS" + else + if test "${ac_cv_linux_vers+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_cv_linux_vers=`uname -r 2>&1 | \ + sed -n -e '$s/.* //' -e '$s/\..*//p'` 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 <&5 +echo "${ECHO_T}$ac_cv_linux_vers" >&6 + if test $ac_cv_linux_vers = unknown ; then + { { echo "$as_me:$LINENO: error: cannot determine linux version when cross-compiling" >&5 +echo "$as_me: error: cannot determine linux version when cross-compiling" >&2;} + { (exit 1); exit 1; }; } + fi + if test $ac_cv_linux_vers -lt 2 ; then + { { echo "$as_me:$LINENO: error: version 2 or higher required; see the INSTALL doc for more info" >&5 +echo "$as_me: error: version 2 or higher required; see the INSTALL doc for more info" >&2;} + { (exit 1); exit 1; }; } + fi + ;; + +*) + ;; +esac -else - echo "$ac_t""no" 1>&6 -fi -echo $ac_n "checking for main in -lrpc""... $ac_c" 1>&6 -echo "configure:1669: 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 <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then - rm -rf conftest* - eval "ac_cv_lib_$ac_lib_var=yes" +for ac_header in smi.h +do +as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 +else + # Is the header compilable? +echo "$as_me:$LINENO: checking $ac_header usability" >&5 +echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +#include <$ac_header> +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_header_compiler=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_header_compiler=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +echo "${ECHO_T}$ac_header_compiler" >&6 + +# Is the header present? +echo "$as_me:$LINENO: checking $ac_header presence" >&5 +echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <$ac_header> +_ACEOF +if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 + (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then + ac_header_preproc=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_preproc=no +fi +rm -f conftest.err conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +echo "${ECHO_T}$ac_header_preproc" >&6 + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc in + yes:no ) + { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 +echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} + ( + cat <<\_ASBOX +## ------------------------------------ ## +## Report this to bug-autoconf@gnu.org. ## +## ------------------------------------ ## +_ASBOX + ) | + sed "s/^/$as_me: WARNING: /" >&2 + ;; + no:yes ) + { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 +echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 +echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} + ( + cat <<\_ASBOX +## ------------------------------------ ## +## Report this to bug-autoconf@gnu.org. ## +## ------------------------------------ ## +_ASBOX + ) | + sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac +echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_lib_$ac_lib_var=no" + eval "$as_ac_Header=$ac_header_preproc" fi -rm -f conftest* -LIBS="$ac_save_LIBS" +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 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 <>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF -else - echo "$ac_t""no" 1>&6 fi -echo $ac_n "checking for uncompress in -lz""... $ac_c" 1>&6 -echo "configure:1712: checking for uncompress in -lz" >&5 -ac_lib_var=`echo z'_'uncompress | sed 'y%./+-%__p_%'` -if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 +done + + +echo "$as_me:$LINENO: checking for smiInit in -lsmi" >&5 +echo $ECHO_N "checking for smiInit in -lsmi... $ECHO_C" >&6 +if test "${ac_cv_lib_smi_smiInit+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - ac_save_LIBS="$LIBS" -LIBS="-lz $LIBS" -cat > conftest.$ac_ext <conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + /* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif /* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char uncompress(); - -int main() { -uncompress() -; return 0; } -EOF -if { (eval echo configure:1731: \"$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" + builtin and then its argument prototype would still apply. */ +char smiInit (); +int +main () +{ +smiInit (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_smi_smiInit=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" + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 +ac_cv_lib_smi_smiInit=no 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 z | sed -e 's/[^a-zA-Z0-9_]/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` - cat >> confdefs.h <&5 +echo "${ECHO_T}$ac_cv_lib_smi_smiInit" >&6 +if test $ac_cv_lib_smi_smiInit = yes; then + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBSMI 1 +_ACEOF - LIBS="-lz $LIBS" + LIBS="-lsmi $LIBS" -else - echo "$ac_t""no" 1>&6 fi -for ac_hdr in zlib.h netinet6/ipcomp.h -do -ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` -echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1762: 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 -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1772: \"$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* - eval "ac_cv_header_$ac_safe=yes" -else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_header_$ac_safe=no" +if test "$ac_cv_header_smi_h" = yes -a "$ac_cv_lib_smi_smiInit" = yes +then +echo "$as_me:$LINENO: checking whether to enable libsmi" >&5 +echo $ECHO_N "checking whether to enable libsmi... $ECHO_C" >&6 + if test "$cross_compiling" = yes; then + echo "$as_me:$LINENO: result: not when cross-compiling" >&5 +echo "${ECHO_T}not when cross-compiling" >&6 + libsmi=no + +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + /* libsmi available check */ +#include +main() +{ + int current, revision, age, n; + const int required = 2; + if (smiInit("")) + exit(1); + if (strcmp(SMI_LIBRARY_VERSION, smi_library_version)) + exit(2); + n = sscanf(smi_library_version, "%d:%d:%d", ¤t, &revision, &age); + if (n != 3) + exit(3); + if (required < current - age || required > current) + exit(4); + exit(0); +} + +_ACEOF +rm -f conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 + cat >>confdefs.h <<\_ACEOF +#define LIBSMI 1 +_ACEOF + + libsmi=yes +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) + case $? in + 1) echo "$as_me:$LINENO: result: no - smiInit failed" >&5 +echo "${ECHO_T}no - smiInit failed" >&6 ;; + 2) echo "$as_me:$LINENO: result: no - header/library version mismatch" >&5 +echo "${ECHO_T}no - header/library version mismatch" >&6 ;; + 3) echo "$as_me:$LINENO: result: no - can't determine library version" >&5 +echo "${ECHO_T}no - can't determine library version" >&6 ;; + 4) echo "$as_me:$LINENO: result: no - too old" >&5 +echo "${ECHO_T}no - too old" >&6 ;; + *) echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 ;; + esac + libsmi=no fi -rm -f conftest* +rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext fi -if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'` - cat >> confdefs.h <&6 fi -done - +echo "$as_me:$LINENO: checking whether to enable the possibly-buggy SMB printer" >&5 +echo $ECHO_N "checking whether to enable the possibly-buggy SMB printer... $ECHO_C" >&6 +# Check whether --enable-smb or --disable-smb was given. +if test "${enable_smb+set}" = set; then + enableval="$enable_smb" - echo $ac_n "checking return type of signal handlers""... $ac_c" 1>&6 -echo "configure:1801: 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 < -#include -#ifdef signal -#undef signal -#endif -#ifdef __cplusplus -extern "C" void (*signal (int, void (*)(int)))(int); -#else -void (*signal ()) (); -#endif + enableval=yes +fi; +case "$enableval" in +yes) echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 + { echo "$as_me:$LINENO: WARNING: The SMB printer may have exploitable buffer overflows!!!" >&5 +echo "$as_me: WARNING: The SMB printer may have exploitable buffer overflows!!!" >&2;} + cat >>confdefs.h <<\_ACEOF +#define TCPDUMP_DO_SMB 1 +_ACEOF + + LOCALSRC="print-smb.c smbutil.c $LOCALSRC" + ;; +*) echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 + ;; +esac + +echo "$as_me:$LINENO: checking whether to enable ipv6" >&5 +echo $ECHO_N "checking whether to enable ipv6... $ECHO_C" >&6 +# Check whether --enable-ipv6 or --disable-ipv6 was given. +if test "${enable_ipv6+set}" = set; then + enableval="$enable_ipv6" + case "$enableval" in +yes) echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 + LOCALSRC="print-ip6.c print-ip6opts.c print-mobility.c print-ripng.c print-icmp6.c print-frag6.c print-rt6.c print-ospf6.c print-dhcp6.c $LOCALSRC" + cat >>confdefs.h <<\_ACEOF +#define INET6 1 +_ACEOF + + ipv6=yes + ;; +*) + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 + ipv6=no + ;; + esac +else + if test "$cross_compiling" = yes; then + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 + ipv6=no -int main() { -int i; -; return 0; } -EOF -if { (eval echo configure:1823: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then - rm -rf conftest* - ac_cv_type_signal=void else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - ac_cv_type_signal=int + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + /* AF_INET6 available check */ +#include +#include +main() +{ + if (socket(AF_INET6, SOCK_STREAM, 0) < 0) + exit(1); + else + exit(0); +} + +_ACEOF +rm -f conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 + LOCALSRC="print-ip6.c print-ip6opts.c print-mobility.c print-ripng.c print-icmp6.c print-frag6.c print-rt6.c print-ospf6.c print-dhcp6.c $LOCALSRC" + cat >>confdefs.h <<\_ACEOF +#define INET6 1 +_ACEOF + + ipv6=yes +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 + ipv6=no +fi +rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi +fi; + +ipv6type=unknown +ipv6lib=none +ipv6trylibc=no + +if test "$ipv6" = "yes"; then + echo "$as_me:$LINENO: checking ipv6 stack type" >&5 +echo $ECHO_N "checking ipv6 stack type... $ECHO_C" >&6 + for i in inria kame linux-glibc linux-libinet6 toshiba v6d zeta; do + case $i in + inria) + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#ifdef IPV6_INRIA_VERSION +yes +#endif +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "yes" >/dev/null 2>&1; then + ipv6type=$i; + CFLAGS="-DINET6 $CFLAGS" fi rm -f conftest* + + ;; + kame) + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#ifdef __KAME__ +yes +#endif +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "yes" >/dev/null 2>&1; then + ipv6type=$i; + ipv6lib=inet6; + ipv6libdir=/usr/local/v6/lib; + ipv6trylibc=yes; + CFLAGS="-DINET6 $CFLAGS" fi +rm -f conftest* -echo "$ac_t""$ac_cv_type_signal" 1>&6 -cat >> confdefs.h <conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#if defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1 +yes +#endif +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "yes" >/dev/null 2>&1; then + ipv6type=$i; + CFLAGS="-DINET6 $CFLAGS" +fi +rm -f conftest* + + ;; + linux-libinet6) + if test -d /usr/inet6 -o -f /usr/include/netinet/ip6.h; then + ipv6type=$i + ipv6lib=inet6 + ipv6libdir=/usr/inet6/lib + ipv6trylibc=yes; + CFLAGS="-DINET6 -I/usr/inet6/include $CFLAGS" + fi + ;; + toshiba) + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#ifdef _TOSHIBA_INET6 +yes +#endif +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "yes" >/dev/null 2>&1; then + ipv6type=$i; + ipv6lib=inet6; + ipv6libdir=/usr/local/v6/lib; + CFLAGS="-DINET6 $CFLAGS" +fi +rm -f conftest* + + ;; + v6d) + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#ifdef __V6D__ +yes +#endif +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "yes" >/dev/null 2>&1; then + ipv6type=$i; + ipv6lib=v6; + ipv6libdir=/usr/local/v6/lib; + CFLAGS="-I/usr/local/v6/include $CFLAGS" +fi +rm -f conftest* + + ;; + zeta) + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#ifdef _ZETA_MINAMI_INET6 +yes +#endif +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "yes" >/dev/null 2>&1; then + ipv6type=$i; + ipv6lib=inet6; + ipv6libdir=/usr/local/v6/lib; + CFLAGS="-DINET6 $CFLAGS" +fi +rm -f conftest* + + ;; + esac + if test "$ipv6type" != "unknown"; then + break + fi + done + echo "$as_me:$LINENO: result: $ipv6type" >&5 +echo "${ECHO_T}$ipv6type" >&6 +fi + +if test "$ipv6" = "yes" -a "$ipv6lib" != "none"; then + if test -d $ipv6libdir -a -f $ipv6libdir/lib$ipv6lib.a; then + LIBS="-L$ipv6libdir -l$ipv6lib $LIBS" + echo "You have $ipv6lib library, using it" + else + if test "$ipv6trylibc" = "yes"; then + echo "You do not have $ipv6lib library, using libc" + else + echo 'Fatal: no $ipv6lib library found. cannot continue.' + echo "You need to fetch lib$ipv6lib.a from appropriate" + echo 'ipv6 kit and compile beforehand.' + exit 1 + fi + fi +fi + + +if test "$ipv6" = "yes"; then + # + # XXX - on Tru64 UNIX 5.1, there is no "getaddrinfo()" + # function in libc; there are "ngetaddrinfo()" and + # "ogetaddrinfo()" functions, and #defines + # "getaddrinfo" to be either "ngetaddrinfo" or + # "ogetaddrinfo", depending on whether _SOCKADDR_LEN + # or _XOPEN_SOURCE_EXTENDED are defined or not. + # + # So this test doesn't work on Tru64 5.1, and possibly + # on other 5.x releases. This causes the configure + # script to become confused, and results in libpcap + # being unbuildable. + # + echo "$as_me:$LINENO: checking for library containing getaddrinfo" >&5 +echo $ECHO_N "checking for library containing getaddrinfo... $ECHO_C" >&6 +if test "${ac_cv_search_getaddrinfo+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_func_search_save_LIBS=$LIBS +ac_cv_search_getaddrinfo=no +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char getaddrinfo (); +int +main () +{ +getaddrinfo (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_search_getaddrinfo="none required" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +if test "$ac_cv_search_getaddrinfo" = no; then + for ac_lib in socket; do + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char getaddrinfo (); +int +main () +{ +getaddrinfo (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_search_getaddrinfo="-l$ac_lib" +break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext + done +fi +LIBS=$ac_func_search_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_search_getaddrinfo" >&5 +echo "${ECHO_T}$ac_cv_search_getaddrinfo" >&6 +if test "$ac_cv_search_getaddrinfo" != no; then + test "$ac_cv_search_getaddrinfo" = "none required" || LIBS="$ac_cv_search_getaddrinfo $LIBS" + echo "$as_me:$LINENO: checking getaddrinfo bug" >&5 +echo $ECHO_N "checking getaddrinfo bug... $ECHO_C" >&6 + if test "${td_cv_buggygetaddrinfo+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test "$cross_compiling" = yes; then + td_cv_buggygetaddrinfo=yes +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +#include +#include +#include +#include +#include + +main() +{ + int passive, gaierr, inet4 = 0, inet6 = 0; + struct addrinfo hints, *ai, *aitop; + char straddr[INET6_ADDRSTRLEN], strport[16]; + + for (passive = 0; passive <= 1; passive++) { + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_flags = passive ? AI_PASSIVE : 0; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + if ((gaierr = getaddrinfo(NULL, "54321", &hints, &aitop)) != 0) { + (void)gai_strerror(gaierr); + goto bad; + } + for (ai = aitop; ai; ai = ai->ai_next) { + if (ai->ai_addr == NULL || + ai->ai_addrlen == 0 || + getnameinfo(ai->ai_addr, ai->ai_addrlen, + straddr, sizeof(straddr), strport, sizeof(strport), + NI_NUMERICHOST|NI_NUMERICSERV) != 0) { + goto bad; + } + switch (ai->ai_family) { + case AF_INET: + if (strcmp(strport, "54321") != 0) { + goto bad; + } + if (passive) { + if (strcmp(straddr, "0.0.0.0") != 0) { + goto bad; + } + } else { + if (strcmp(straddr, "127.0.0.1") != 0) { + goto bad; + } + } + inet4++; + break; + case AF_INET6: + if (strcmp(strport, "54321") != 0) { + goto bad; + } + if (passive) { + if (strcmp(straddr, "::") != 0) { + goto bad; + } + } else { + if (strcmp(straddr, "::1") != 0) { + goto bad; + } + } + inet6++; + break; + case AF_UNSPEC: + goto bad; + break; +#ifdef AF_UNIX + case AF_UNIX: +#else +#ifdef AF_LOCAL + case AF_LOCAL: +#endif +#endif + default: + /* another family support? */ + break; + } + } + } + + /* supported family should be 2, unsupported family should be 0 */ + if (!(inet4 == 0 || inet4 == 2)) + goto bad; + if (!(inet6 == 0 || inet6 == 2)) + goto bad; + + if (aitop) + freeaddrinfo(aitop); + exit(0); + + bad: + if (aitop) + freeaddrinfo(aitop); + exit(1); +} + +_ACEOF +rm -f conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + td_cv_buggygetaddrinfo=no +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +td_cv_buggygetaddrinfo=yes +fi +rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi +fi + + if test "$td_cv_buggygetaddrinfo" = no; then + echo "$as_me:$LINENO: result: good" >&5 +echo "${ECHO_T}good" >&6 + else + echo "$as_me:$LINENO: result: buggy" >&5 +echo "${ECHO_T}buggy" >&6 + fi + + if test "$td_cv_buggygetaddrinfo" = "yes"; then + # + # XXX - it doesn't appear that "ipv6type" can ever be + # set to "linux". Should this be testing for + # "linux-glibc", or for that *or* "linux-libinet6"? + # If the latter, note that "linux-libinet6" is also + # the type given to some non-Linux OSes. + # + if test "$ipv6type" != "linux"; then + echo 'Fatal: You must get working getaddrinfo() function.' + echo ' or you can specify "--disable-ipv6"'. + exit 1 + else + echo 'Warning: getaddrinfo() implementation on your system seems be buggy.' + echo ' Better upgrade your system library to newest version' + echo ' of GNU C library (aka glibc).' + fi + fi + +fi + + + +for ac_func in getaddrinfo getnameinfo +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* 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_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +else + LIBOBJS="$LIBOBJS $ac_func.$ac_objext" +fi +done + + +fi + +echo "$as_me:$LINENO: checking for dnet_htoa declaration in netdnet/dnetdb.h" >&5 +echo $ECHO_N "checking for dnet_htoa declaration in netdnet/dnetdb.h... $ECHO_C" >&6 +if test "${td_cv_decl_netdnet_dnetdb_h_dnet_htoa+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "dnet_htoa" >/dev/null 2>&1; then + td_cv_decl_netdnet_dnetdb_h_dnet_htoa=yes +else + td_cv_decl_netdnet_dnetdb_h_dnet_htoa=no +fi +rm -f conftest* + +fi +echo "$as_me:$LINENO: result: $td_cv_decl_netdnet_dnetdb_h_dnet_htoa" >&5 +echo "${ECHO_T}$td_cv_decl_netdnet_dnetdb_h_dnet_htoa" >&6 +if test "$td_cv_decl_netdnet_dnetdb_h_dnet_htoa" = yes; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_NETDNET_DNETDB_H_DNET_HTOA 1 +_ACEOF + +fi + +echo "$as_me:$LINENO: checking for char" >&5 +echo $ECHO_N "checking for char... $ECHO_C" >&6 +if test "${ac_cv_type_char+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +if ((char *) 0) + return 0; +if (sizeof (char)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_type_char=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_type_char=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_type_char" >&5 +echo "${ECHO_T}$ac_cv_type_char" >&6 + +echo "$as_me:$LINENO: checking size of char" >&5 +echo $ECHO_N "checking size of char... $ECHO_C" >&6 +if test "${ac_cv_sizeof_char+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test "$ac_cv_type_char" = yes; then + # The cast to unsigned long works around a bug in the HP C Compiler + # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects + # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. + # This bug is HP SR number 8606223364. + if test "$cross_compiling" = yes; then + # Depending upon the size, compute the lo and hi bounds. +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (char))) >= 0)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_lo=0 ac_mid=0 + while :; do + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (char))) <= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=$ac_mid; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_lo=`expr $ac_mid + 1` + if test $ac_lo -le $ac_mid; then + ac_lo= ac_hi= + break + fi + ac_mid=`expr 2 '*' $ac_mid + 1` +fi +rm -f conftest.$ac_objext conftest.$ac_ext + done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (char))) < 0)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=-1 ac_mid=-1 + while :; do + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (char))) >= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_lo=$ac_mid; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_hi=`expr '(' $ac_mid ')' - 1` + if test $ac_mid -le $ac_hi; then + ac_lo= ac_hi= + break + fi + ac_mid=`expr 2 '*' $ac_mid` +fi +rm -f conftest.$ac_objext conftest.$ac_ext + done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_lo= ac_hi= +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi +rm -f conftest.$ac_objext conftest.$ac_ext +# Binary search between lo and hi bounds. +while test "x$ac_lo" != "x$ac_hi"; do + ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (char))) <= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=$ac_mid +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_lo=`expr '(' $ac_mid ')' + 1` +fi +rm -f conftest.$ac_objext conftest.$ac_ext +done +case $ac_lo in +?*) ac_cv_sizeof_char=$ac_lo;; +'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (char), 77 +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute sizeof (char), 77 +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } ;; +esac +else + if test "$cross_compiling" = yes; then + { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot run test program while cross compiling +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +long longval () { return (long) (sizeof (char)); } +unsigned long ulongval () { return (long) (sizeof (char)); } +#include +#include +int +main () +{ + + FILE *f = fopen ("conftest.val", "w"); + if (! f) + exit (1); + if (((long) (sizeof (char))) < 0) + { + long i = longval (); + if (i != ((long) (sizeof (char)))) + exit (1); + fprintf (f, "%ld\n", i); + } + else + { + unsigned long i = ulongval (); + if (i != ((long) (sizeof (char)))) + exit (1); + fprintf (f, "%lu\n", i); + } + exit (ferror (f) || fclose (f) != 0); + + ; + return 0; +} +_ACEOF +rm -f conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_sizeof_char=`cat conftest.val` +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +{ { echo "$as_me:$LINENO: error: cannot compute sizeof (char), 77 +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute sizeof (char), 77 +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi +rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi +fi +rm -f conftest.val +else + ac_cv_sizeof_char=0 +fi +fi +echo "$as_me:$LINENO: result: $ac_cv_sizeof_char" >&5 +echo "${ECHO_T}$ac_cv_sizeof_char" >&6 +cat >>confdefs.h <<_ACEOF +#define SIZEOF_CHAR $ac_cv_sizeof_char +_ACEOF + + +echo "$as_me:$LINENO: checking for short" >&5 +echo $ECHO_N "checking for short... $ECHO_C" >&6 +if test "${ac_cv_type_short+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +if ((short *) 0) + return 0; +if (sizeof (short)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_type_short=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_type_short=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_type_short" >&5 +echo "${ECHO_T}$ac_cv_type_short" >&6 + +echo "$as_me:$LINENO: checking size of short" >&5 +echo $ECHO_N "checking size of short... $ECHO_C" >&6 +if test "${ac_cv_sizeof_short+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test "$ac_cv_type_short" = yes; then + # The cast to unsigned long works around a bug in the HP C Compiler + # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects + # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. + # This bug is HP SR number 8606223364. + if test "$cross_compiling" = yes; then + # Depending upon the size, compute the lo and hi bounds. +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (short))) >= 0)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_lo=0 ac_mid=0 + while :; do + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (short))) <= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=$ac_mid; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_lo=`expr $ac_mid + 1` + if test $ac_lo -le $ac_mid; then + ac_lo= ac_hi= + break + fi + ac_mid=`expr 2 '*' $ac_mid + 1` +fi +rm -f conftest.$ac_objext conftest.$ac_ext + done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (short))) < 0)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=-1 ac_mid=-1 + while :; do + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (short))) >= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_lo=$ac_mid; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_hi=`expr '(' $ac_mid ')' - 1` + if test $ac_mid -le $ac_hi; then + ac_lo= ac_hi= + break + fi + ac_mid=`expr 2 '*' $ac_mid` +fi +rm -f conftest.$ac_objext conftest.$ac_ext + done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_lo= ac_hi= +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi +rm -f conftest.$ac_objext conftest.$ac_ext +# Binary search between lo and hi bounds. +while test "x$ac_lo" != "x$ac_hi"; do + ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (short))) <= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=$ac_mid +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_lo=`expr '(' $ac_mid ')' + 1` +fi +rm -f conftest.$ac_objext conftest.$ac_ext +done +case $ac_lo in +?*) ac_cv_sizeof_short=$ac_lo;; +'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (short), 77 +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute sizeof (short), 77 +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } ;; +esac +else + if test "$cross_compiling" = yes; then + { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot run test program while cross compiling +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +long longval () { return (long) (sizeof (short)); } +unsigned long ulongval () { return (long) (sizeof (short)); } +#include +#include +int +main () +{ + + FILE *f = fopen ("conftest.val", "w"); + if (! f) + exit (1); + if (((long) (sizeof (short))) < 0) + { + long i = longval (); + if (i != ((long) (sizeof (short)))) + exit (1); + fprintf (f, "%ld\n", i); + } + else + { + unsigned long i = ulongval (); + if (i != ((long) (sizeof (short)))) + exit (1); + fprintf (f, "%lu\n", i); + } + exit (ferror (f) || fclose (f) != 0); + + ; + return 0; +} +_ACEOF +rm -f conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_sizeof_short=`cat conftest.val` +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +{ { echo "$as_me:$LINENO: error: cannot compute sizeof (short), 77 +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute sizeof (short), 77 +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi +rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi +fi +rm -f conftest.val +else + ac_cv_sizeof_short=0 +fi +fi +echo "$as_me:$LINENO: result: $ac_cv_sizeof_short" >&5 +echo "${ECHO_T}$ac_cv_sizeof_short" >&6 +cat >>confdefs.h <<_ACEOF +#define SIZEOF_SHORT $ac_cv_sizeof_short +_ACEOF + + +echo "$as_me:$LINENO: checking for int" >&5 +echo $ECHO_N "checking for int... $ECHO_C" >&6 +if test "${ac_cv_type_int+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +if ((int *) 0) + return 0; +if (sizeof (int)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_type_int=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_type_int=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_type_int" >&5 +echo "${ECHO_T}$ac_cv_type_int" >&6 + +echo "$as_me:$LINENO: checking size of int" >&5 +echo $ECHO_N "checking size of int... $ECHO_C" >&6 +if test "${ac_cv_sizeof_int+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test "$ac_cv_type_int" = yes; then + # The cast to unsigned long works around a bug in the HP C Compiler + # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects + # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. + # This bug is HP SR number 8606223364. + if test "$cross_compiling" = yes; then + # Depending upon the size, compute the lo and hi bounds. +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (int))) >= 0)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_lo=0 ac_mid=0 + while :; do + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (int))) <= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=$ac_mid; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_lo=`expr $ac_mid + 1` + if test $ac_lo -le $ac_mid; then + ac_lo= ac_hi= + break + fi + ac_mid=`expr 2 '*' $ac_mid + 1` +fi +rm -f conftest.$ac_objext conftest.$ac_ext + done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (int))) < 0)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=-1 ac_mid=-1 + while :; do + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (int))) >= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_lo=$ac_mid; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_hi=`expr '(' $ac_mid ')' - 1` + if test $ac_mid -le $ac_hi; then + ac_lo= ac_hi= + break + fi + ac_mid=`expr 2 '*' $ac_mid` +fi +rm -f conftest.$ac_objext conftest.$ac_ext + done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_lo= ac_hi= +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi +rm -f conftest.$ac_objext conftest.$ac_ext +# Binary search between lo and hi bounds. +while test "x$ac_lo" != "x$ac_hi"; do + ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (int))) <= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=$ac_mid +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_lo=`expr '(' $ac_mid ')' + 1` +fi +rm -f conftest.$ac_objext conftest.$ac_ext +done +case $ac_lo in +?*) ac_cv_sizeof_int=$ac_lo;; +'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (int), 77 +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute sizeof (int), 77 +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } ;; +esac +else + if test "$cross_compiling" = yes; then + { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot run test program while cross compiling +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +long longval () { return (long) (sizeof (int)); } +unsigned long ulongval () { return (long) (sizeof (int)); } +#include +#include +int +main () +{ + + FILE *f = fopen ("conftest.val", "w"); + if (! f) + exit (1); + if (((long) (sizeof (int))) < 0) + { + long i = longval (); + if (i != ((long) (sizeof (int)))) + exit (1); + fprintf (f, "%ld\n", i); + } + else + { + unsigned long i = ulongval (); + if (i != ((long) (sizeof (int)))) + exit (1); + fprintf (f, "%lu\n", i); + } + exit (ferror (f) || fclose (f) != 0); + + ; + return 0; +} +_ACEOF +rm -f conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_sizeof_int=`cat conftest.val` +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +{ { echo "$as_me:$LINENO: error: cannot compute sizeof (int), 77 +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute sizeof (int), 77 +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi +rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi +fi +rm -f conftest.val +else + ac_cv_sizeof_int=0 +fi +fi +echo "$as_me:$LINENO: result: $ac_cv_sizeof_int" >&5 +echo "${ECHO_T}$ac_cv_sizeof_int" >&6 +cat >>confdefs.h <<_ACEOF +#define SIZEOF_INT $ac_cv_sizeof_int +_ACEOF + + +echo "$as_me:$LINENO: checking for long" >&5 +echo $ECHO_N "checking for long... $ECHO_C" >&6 +if test "${ac_cv_type_long+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +if ((long *) 0) + return 0; +if (sizeof (long)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_type_long=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_type_long=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_type_long" >&5 +echo "${ECHO_T}$ac_cv_type_long" >&6 + +echo "$as_me:$LINENO: checking size of long" >&5 +echo $ECHO_N "checking size of long... $ECHO_C" >&6 +if test "${ac_cv_sizeof_long+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test "$ac_cv_type_long" = yes; then + # The cast to unsigned long works around a bug in the HP C Compiler + # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects + # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. + # This bug is HP SR number 8606223364. + if test "$cross_compiling" = yes; then + # Depending upon the size, compute the lo and hi bounds. +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (long))) >= 0)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_lo=0 ac_mid=0 + while :; do + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (long))) <= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=$ac_mid; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_lo=`expr $ac_mid + 1` + if test $ac_lo -le $ac_mid; then + ac_lo= ac_hi= + break + fi + ac_mid=`expr 2 '*' $ac_mid + 1` +fi +rm -f conftest.$ac_objext conftest.$ac_ext + done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (long))) < 0)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=-1 ac_mid=-1 + while :; do + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (long))) >= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_lo=$ac_mid; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_hi=`expr '(' $ac_mid ')' - 1` + if test $ac_mid -le $ac_hi; then + ac_lo= ac_hi= + break + fi + ac_mid=`expr 2 '*' $ac_mid` +fi +rm -f conftest.$ac_objext conftest.$ac_ext + done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_lo= ac_hi= +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi +rm -f conftest.$ac_objext conftest.$ac_ext +# Binary search between lo and hi bounds. +while test "x$ac_lo" != "x$ac_hi"; do + ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(((long) (sizeof (long))) <= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=$ac_mid +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_lo=`expr '(' $ac_mid ')' + 1` +fi +rm -f conftest.$ac_objext conftest.$ac_ext +done +case $ac_lo in +?*) ac_cv_sizeof_long=$ac_lo;; +'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (long), 77 +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute sizeof (long), 77 +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } ;; +esac +else + if test "$cross_compiling" = yes; then + { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot run test program while cross compiling +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +long longval () { return (long) (sizeof (long)); } +unsigned long ulongval () { return (long) (sizeof (long)); } +#include +#include +int +main () +{ + + FILE *f = fopen ("conftest.val", "w"); + if (! f) + exit (1); + if (((long) (sizeof (long))) < 0) + { + long i = longval (); + if (i != ((long) (sizeof (long)))) + exit (1); + fprintf (f, "%ld\n", i); + } + else + { + unsigned long i = ulongval (); + if (i != ((long) (sizeof (long)))) + exit (1); + fprintf (f, "%lu\n", i); + } + exit (ferror (f) || fclose (f) != 0); + + ; + return 0; +} +_ACEOF +rm -f conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_sizeof_long=`cat conftest.val` +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +{ { echo "$as_me:$LINENO: error: cannot compute sizeof (long), 77 +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute sizeof (long), 77 +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi +rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi +fi +rm -f conftest.val +else + ac_cv_sizeof_long=0 +fi +fi +echo "$as_me:$LINENO: result: $ac_cv_sizeof_long" >&5 +echo "${ECHO_T}$ac_cv_sizeof_long" >&6 +cat >>confdefs.h <<_ACEOF +#define SIZEOF_LONG $ac_cv_sizeof_long +_ACEOF + + + + + + echo "$as_me:$LINENO: checking for addrinfo" >&5 +echo $ECHO_N "checking for addrinfo... $ECHO_C" >&6 + if test "${ac_cv_addrinfo+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +# include +int +main () +{ +struct addrinfo a + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_addrinfo=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_addrinfo=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi + + echo "$as_me:$LINENO: result: $ac_cv_addrinfo" >&5 +echo "${ECHO_T}$ac_cv_addrinfo" >&6 + if test $ac_cv_addrinfo = yes; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_ADDRINFO 1 +_ACEOF + + else + cat >>confdefs.h <<\_ACEOF +#define NEED_ADDRINFO_H 1 +_ACEOF + + fi + +if test "$ac_cv_addrinfo" = no; then + missing_includes=yes +fi + + + echo "$as_me:$LINENO: checking for NI_MAXSERV" >&5 +echo $ECHO_N "checking for NI_MAXSERV... $ECHO_C" >&6 + if test "${ac_cv_maxserv+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#ifdef NI_MAXSERV +yes +#endif +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "yes" >/dev/null 2>&1; then + ac_cv_maxserv=yes +else + ac_cv_maxserv=no +fi +rm -f conftest* + +fi + + echo "$as_me:$LINENO: result: $ac_cv_maxserv" >&5 +echo "${ECHO_T}$ac_cv_maxserv" >&6 + if test $ac_cv_maxserv != yes; then + cat >>confdefs.h <<\_ACEOF +#define NEED_ADDRINFO_H 1 +_ACEOF + + fi + +if test "$ac_cv_maxserv" = no; then + missing_includes=yes +fi + + + echo "$as_me:$LINENO: checking for NI_NAMEREQD" >&5 +echo $ECHO_N "checking for NI_NAMEREQD... $ECHO_C" >&6 + if test "${ac_cv_namereqd+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#ifdef NI_NOFQDN +yes +#endif +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "yes" >/dev/null 2>&1; then + ac_cv_namereqd=yes +else + ac_cv_namereqd=no +fi +rm -f conftest* + +fi + + echo "$as_me:$LINENO: result: $ac_cv_namereqd" >&5 +echo "${ECHO_T}$ac_cv_namereqd" >&6 + if test $ac_cv_namereqd != yes; then + cat >>confdefs.h <<\_ACEOF +#define NEED_ADDRINFO_H 1 +_ACEOF + + fi + +if test "$ac_cv_namereqd" = no; then + missing_includes=yes +fi + + + echo "$as_me:$LINENO: checking for sockaddr_storage" >&5 +echo $ECHO_N "checking for sockaddr_storage... $ECHO_C" >&6 + if test "${ac_cv_sa_storage+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +# include +# include +int +main () +{ +struct sockaddr_storage s + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_sa_storage=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_sa_storage=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi + + echo "$as_me:$LINENO: result: $ac_cv_sa_storage" >&5 +echo "${ECHO_T}$ac_cv_sa_storage" >&6 + if test $ac_cv_sa_storage = yes; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_SOCKADDR_STORAGE 1 +_ACEOF + + fi + +if test "$ac_cv_sa_storage" = no; then + missing_includes=yes +fi + + + ac_cv_addrsz=yes + echo "$as_me:$LINENO: checking for INADDRSZ" >&5 +echo $ECHO_N "checking for INADDRSZ... $ECHO_C" >&6 + if test "${ac_cv_inaddrsz+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +# include +int +main () +{ +int a = INADDRSZ + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_inaddrsz=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_inaddrsz=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi + + echo "$as_me:$LINENO: result: $ac_cv_inaddrsz" >&5 +echo "${ECHO_T}$ac_cv_inaddrsz" >&6 + if test $ac_cv_inaddrsz = yes; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_INADDRSZ 1 +_ACEOF + + else + ac_cv_addrsz=no + fi + echo "$as_me:$LINENO: checking for IN6ADDRSZ" >&5 +echo $ECHO_N "checking for IN6ADDRSZ... $ECHO_C" >&6 + if test "${ac_cv_in6addrsz+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +# include +int +main () +{ +int a = IN6ADDRSZ + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_in6addrsz=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_in6addrsz=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi + + echo "$as_me:$LINENO: result: $ac_cv_in6addrsz" >&5 +echo "${ECHO_T}$ac_cv_in6addrsz" >&6 + if test $ac_cv_in6addrsz = yes; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_IN6ADDRSZ 1 +_ACEOF + + else + ac_cv_addrsz=no + fi + +if test "$ac_cv_addrsz" = no; then + missing_includes=yes +fi + + + echo "$as_me:$LINENO: checking for RES_USE_INET6" >&5 +echo $ECHO_N "checking for RES_USE_INET6... $ECHO_C" >&6 + if test "${ac_cv_res_inet6+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +# include +# include +# include +int +main () +{ +int a = RES_USE_INET6 + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_res_inet6=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_res_inet6=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi + + echo "$as_me:$LINENO: result: $ac_cv_res_inet6" >&5 +echo "${ECHO_T}$ac_cv_res_inet6" >&6 + if test $ac_cv_res_inet6 = yes; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_RES_USE_INET6 1 +_ACEOF + + fi + +if test "$ac_cv_res_inet6" = no; then + missing_includes=yes +fi + + + echo "$as_me:$LINENO: checking for res_state_ext" >&5 +echo $ECHO_N "checking for res_state_ext... $ECHO_C" >&6 + if test "${ac_cv_res_state_ext+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +# include +# include +# include +# include +int +main () +{ +struct __res_state_ext e + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_res_state_ext=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_res_state_ext=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi + + echo "$as_me:$LINENO: result: $ac_cv_res_state_ext" >&5 +echo "${ECHO_T}$ac_cv_res_state_ext" >&6 + if test $ac_cv_res_state_ext = yes; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_RES_STATE_EXT 1 +_ACEOF + + fi + +if test "$ac_cv_res_state_ext" = no; then + missing_includes=yes +fi + + + echo "$as_me:$LINENO: checking for nsort in res_state" >&5 +echo $ECHO_N "checking for nsort in res_state... $ECHO_C" >&6 + if test "${ac_cv_res_state+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +# include +# include +# include +# include +int +main () +{ +struct __res_state e; e.nsort = 0 + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_res_state=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_res_state=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi + + echo "$as_me:$LINENO: result: $ac_cv_res_state" >&5 +echo "${ECHO_T}$ac_cv_res_state" >&6 + if test $ac_cv_res_state = yes; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_NEW_RES_STATE 1 +_ACEOF + + fi + + +if test "$missing_includes" = "yes"; then + CPPFLAGS="$CPPFLAGS -I\$(srcdir)/missing" + V_INCLS="$V_INCLS -I\$(srcdir)/missing" +fi + + + + + + + + +for ac_func in vfprintf strcasecmp strlcat strlcpy strdup strsep +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* 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_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +else + LIBOBJS="$LIBOBJS $ac_func.$ac_objext" +fi +done + + + +for ac_func in strftime +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* 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_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + +for ac_func in ether_ntohost +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* 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_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + + echo "$as_me:$LINENO: checking for buggy ether_ntohost" >&5 +echo $ECHO_N "checking for buggy ether_ntohost... $ECHO_C" >&6 +if test "${ac_cv_buggy_ether_ntohost+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + + if test "$cross_compiling" = yes; then + ac_cv_buggy_ether_ntohost="not while cross-compiling" +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + #include + #include + #include + #include + + 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); + } + +_ACEOF +rm -f conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_buggy_ether_ntohost=no +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +ac_cv_buggy_ether_ntohost=yes +fi +rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi +fi +echo "$as_me:$LINENO: result: $ac_cv_buggy_ether_ntohost" >&5 +echo "${ECHO_T}$ac_cv_buggy_ether_ntohost" >&6 + if test "$ac_cv_buggy_ether_ntohost" = "no"; then + cat >>confdefs.h <<\_ACEOF +#define USE_ETHER_NTOHOST 1 +_ACEOF + + fi + +fi +done + + +for ac_func in setlinebuf +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* 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_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + +needsnprintf=no + + +for ac_func in vsnprintf snprintf +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* 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_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +else + needsnprintf=yes +fi +done + +if test $needsnprintf = yes; then + LIBOBJS="$LIBOBJS snprintf.o.$ac_objext" +fi + + + echo "$as_me:$LINENO: checking return type of signal handlers" >&5 +echo $ECHO_N "checking return type of signal handlers... $ECHO_C" >&6 +if test "${ac_cv_type_signal+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#ifdef signal +# undef signal +#endif +#ifdef __cplusplus +extern "C" void (*signal (int, void (*)(int)))(int); +#else +void (*signal ()) (); +#endif + +int +main () +{ +int i; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_type_signal=void +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_type_signal=int +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_type_signal" >&5 +echo "${ECHO_T}$ac_cv_type_signal" >&6 + +cat >>confdefs.h <<_ACEOF +#define RETSIGTYPE $ac_cv_type_signal +_ACEOF + + + if test "$ac_cv_type_signal" = void ; then + cat >>confdefs.h <<\_ACEOF +#define RETSIGVAL +_ACEOF + + else + cat >>confdefs.h <<\_ACEOF +#define RETSIGVAL (0) +_ACEOF + + fi + case "$host_os" in + + irix*) + cat >>confdefs.h <<\_ACEOF +#define _BSD_SIGNALS 1 +_ACEOF + + ;; + + *) + +for ac_func in sigaction +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* 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_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + if test $ac_cv_func_sigaction = no ; then + +for ac_func in sigset +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* 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_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + fi + ;; + esac + +echo "$as_me:$LINENO: checking for library containing dnet_htoa" >&5 +echo $ECHO_N "checking for library containing dnet_htoa... $ECHO_C" >&6 +if test "${ac_cv_search_dnet_htoa+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_func_search_save_LIBS=$LIBS +ac_cv_search_dnet_htoa=no +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char dnet_htoa (); +int +main () +{ +dnet_htoa (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_search_dnet_htoa="none required" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +if test "$ac_cv_search_dnet_htoa" = no; then + for ac_lib in dnet; do + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char dnet_htoa (); +int +main () +{ +dnet_htoa (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_search_dnet_htoa="-l$ac_lib" +break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext + done +fi +LIBS=$ac_func_search_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_search_dnet_htoa" >&5 +echo "${ECHO_T}$ac_cv_search_dnet_htoa" >&6 +if test "$ac_cv_search_dnet_htoa" != no; then + test "$ac_cv_search_dnet_htoa" = "none required" || LIBS="$ac_cv_search_dnet_htoa $LIBS" + cat >>confdefs.h <<\_ACEOF +#define HAVE_DNET_HTOA 1 +_ACEOF + +fi + + + +echo "$as_me:$LINENO: checking for main in -lrpc" >&5 +echo $ECHO_N "checking for main in -lrpc... $ECHO_C" >&6 +if test "${ac_cv_lib_rpc_main+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lrpc $LIBS" +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + +int +main () +{ +main (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_rpc_main=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_rpc_main=no +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_rpc_main" >&5 +echo "${ECHO_T}$ac_cv_lib_rpc_main" >&6 +if test $ac_cv_lib_rpc_main = yes; then + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBRPC 1 +_ACEOF + + LIBS="-lrpc $LIBS" + +fi + +echo "$as_me:$LINENO: checking for library containing getrpcbynumber" >&5 +echo $ECHO_N "checking for library containing getrpcbynumber... $ECHO_C" >&6 +if test "${ac_cv_search_getrpcbynumber+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_func_search_save_LIBS=$LIBS +ac_cv_search_getrpcbynumber=no +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* 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; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_search_getrpcbynumber="none required" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +if test "$ac_cv_search_getrpcbynumber" = no; then + for ac_lib in nsl; do + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* 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; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_search_getrpcbynumber="-l$ac_lib" +break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext + done +fi +LIBS=$ac_func_search_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_search_getrpcbynumber" >&5 +echo "${ECHO_T}$ac_cv_search_getrpcbynumber" >&6 +if test "$ac_cv_search_getrpcbynumber" != no; then + test "$ac_cv_search_getrpcbynumber" = "none required" || LIBS="$ac_cv_search_getrpcbynumber $LIBS" + +fi + + + + + # 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 "$as_me:$LINENO: checking for library containing gethostbyname" >&5 +echo $ECHO_N "checking for library containing gethostbyname... $ECHO_C" >&6 +if test "${ac_cv_search_gethostbyname+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_func_search_save_LIBS=$LIBS +ac_cv_search_gethostbyname=no +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* 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; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_search_gethostbyname="none required" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +if test "$ac_cv_search_gethostbyname" = no; then + for ac_lib in nsl socket resolv; do + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* 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; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_search_gethostbyname="-l$ac_lib" +break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext + done +fi +LIBS=$ac_func_search_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_search_gethostbyname" >&5 +echo "${ECHO_T}$ac_cv_search_gethostbyname" >&6 +if test "$ac_cv_search_gethostbyname" != no; then + test "$ac_cv_search_gethostbyname" = "none required" || LIBS="$ac_cv_search_gethostbyname $LIBS" + +fi + + # 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 "$as_me:$LINENO: checking for gethostbyname in -lsocket" >&5 +echo $ECHO_N "checking for gethostbyname in -lsocket... $ECHO_C" >&6 +if test "${ac_cv_lib_socket_gethostbyname+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lsocket -lnsl $LIBS" +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* 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; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_socket_gethostbyname=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_socket_gethostbyname=no +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_socket_gethostbyname" >&5 +echo "${ECHO_T}$ac_cv_lib_socket_gethostbyname" >&6 +if test $ac_cv_lib_socket_gethostbyname = yes; then + LIBS="-lsocket -lnsl $LIBS" +fi + + fi + echo "$as_me:$LINENO: checking for library containing socket" >&5 +echo $ECHO_N "checking for library containing socket... $ECHO_C" >&6 +if test "${ac_cv_search_socket+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_func_search_save_LIBS=$LIBS +ac_cv_search_socket=no +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* 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 () +{ +socket (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_search_socket="none required" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +if test "$ac_cv_search_socket" = no; then + for ac_lib in socket; do + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* 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 () +{ +socket (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_search_socket="-l$ac_lib" +break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext + done +fi +LIBS=$ac_func_search_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_search_socket" >&5 +echo "${ECHO_T}$ac_cv_search_socket" >&6 +if test "$ac_cv_search_socket" != no; then + test "$ac_cv_search_socket" = "none required" || LIBS="$ac_cv_search_socket $LIBS" + +else + echo "$as_me:$LINENO: checking for socket in -lsocket" >&5 +echo $ECHO_N "checking for socket in -lsocket... $ECHO_C" >&6 +if test "${ac_cv_lib_socket_socket+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lsocket -lnsl $LIBS" +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* 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 () +{ +socket (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_socket_socket=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_socket_socket=no +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_socket_socket" >&5 +echo "${ECHO_T}$ac_cv_lib_socket_socket" >&6 +if test $ac_cv_lib_socket_socket = yes; then + LIBS="-lsocket -lnsl $LIBS" +fi + +fi + + # DLPI needs putmsg under HPUX so test for -lstr while we're at it + echo "$as_me:$LINENO: checking for library containing putmsg" >&5 +echo $ECHO_N "checking for library containing putmsg... $ECHO_C" >&6 +if test "${ac_cv_search_putmsg+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_func_search_save_LIBS=$LIBS +ac_cv_search_putmsg=no +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char putmsg (); +int +main () +{ +putmsg (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_search_putmsg="none required" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +if test "$ac_cv_search_putmsg" = no; then + for ac_lib in str; do + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char putmsg (); +int +main () +{ +putmsg (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_search_putmsg="-l$ac_lib" +break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext + done +fi +LIBS=$ac_func_search_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_search_putmsg" >&5 +echo "${ECHO_T}$ac_cv_search_putmsg" >&6 +if test "$ac_cv_search_putmsg" != no; then + test "$ac_cv_search_putmsg" = "none required" || LIBS="$ac_cv_search_putmsg $LIBS" + +fi + + + + LBL_LIBS="$LIBS" + pfopen=/usr/examples/packetfilter/pfopen.c + if test -f $pfopen ; then + +for ac_func in pfopen +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* 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_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + if test $ac_cv_func_pfopen = "no" ; then + echo "$as_me:$LINENO: result: Using $pfopen" >&5 +echo "${ECHO_T}Using $pfopen" >&6 + LIBS="$LIBS $pfopen" + fi + fi + echo "$as_me:$LINENO: checking for local pcap library" >&5 +echo $ECHO_N "checking for local pcap library... $ECHO_C" >&6 + libpcap=FAIL + lastdir=FAIL + places=`ls $srcdir/.. | sed -e 's,/$,,' -e "s,^,$srcdir/../," | \ + egrep '/libpcap-[0-9]*.[0-9]*(.[0-9]*)?([ab][0-9]*)?$'` + for dir in $places $srcdir/../libpcap $srcdir/libpcap ; do + basedir=`echo $dir | sed -e 's/[ab][0-9]*$//'` + if test $lastdir = $basedir ; then + continue; + fi + lastdir=$dir + if test -r $dir/libpcap.a ; then + libpcap=$dir/libpcap.a + d=$dir + fi + done + if test $libpcap = FAIL ; then + echo "$as_me:$LINENO: result: not found" >&5 +echo "${ECHO_T}not found" >&6 + echo "$as_me:$LINENO: checking for main in -lpcap" >&5 +echo $ECHO_N "checking for main in -lpcap... $ECHO_C" >&6 +if test "${ac_cv_lib_pcap_main+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lpcap $LIBS" +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ - if test "$ac_cv_type_signal" = void ; then - cat >> confdefs.h <<\EOF -#define RETSIGVAL -EOF +int +main () +{ +main (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_pcap_main=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_pcap_main=no +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_pcap_main" >&5 +echo "${ECHO_T}$ac_cv_lib_pcap_main" >&6 +if test $ac_cv_lib_pcap_main = yes; then + libpcap="-lpcap" +fi + if test $libpcap = FAIL ; then + { { echo "$as_me:$LINENO: error: see the INSTALL doc for more info" >&5 +echo "$as_me: error: see the INSTALL doc for more info" >&2;} + { (exit 1); exit 1; }; } + fi + echo "$as_me:$LINENO: checking for extraneous pcap header directories" >&5 +echo $ECHO_N "checking for extraneous pcap header directories... $ECHO_C" >&6 + if test \( ! -r /usr/local/include/pcap.h \) -a \ + \( ! -r /usr/include/pcap.h \); then + if test -r /usr/local/include/pcap/pcap.h; then + d="/usr/local/include/pcap" + elif test -r /usr/include/pcap/pcap.h; then + d="/usr/include/pcap" + fi + fi + if test -z "$d" ; then + echo "$as_me:$LINENO: result: not found" >&5 +echo "${ECHO_T}not found" >&6 + else + V_INCLS="-I$d $V_INCLS" + echo "$as_me:$LINENO: result: found -- -I$d added" >&5 +echo "${ECHO_T}found -- -I$d added" >&6 + fi else - cat >> confdefs.h <<\EOF -#define RETSIGVAL (0) -EOF - + 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 $places/pcap.h; then + V_INCLS="-I$places $V_INCLS" + else + { { echo "$as_me:$LINENO: error: cannot find pcap.h" >&5 +echo "$as_me: error: cannot find pcap.h" >&2;} + { (exit see INSTALL); exit see INSTALL; }; } + fi + echo "$as_me:$LINENO: result: $libpcap" >&5 +echo "${ECHO_T}$libpcap" >&6 fi - case "$target_os" in - - irix*) - cat >> confdefs.h <<\EOF -#define _BSD_SIGNALS 1 -EOF + LIBS="$libpcap $LIBS" + case "$host_os" in + aix*) + pseexe="/lib/pse.exp" + echo "$as_me:$LINENO: checking for $pseexe" >&5 +echo $ECHO_N "checking for $pseexe... $ECHO_C" >&6 + if test -f $pseexe ; then + echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 + LIBS="$LIBS -I:$pseexe" + fi + # + # We need "-lodm" and "-lcfg", as libpcap requires them on + # AIX, and we just build a static libpcap.a and thus can't + # arrange that when you link with libpcap you automatically + # link with those libraries. + # + LIBS="$LIBS -lodm -lcfg" ;; + esac - *) - for ac_func in sigset -do -echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1865: 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 <&5 +echo $ECHO_N "checking for pcap_list_datalinks... $ECHO_C" >&6 +if test "${ac_cv_func_pcap_list_datalinks+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ /* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func(); below. */ -#include + which can conflict with char pcap_list_datalinks (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif /* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif /* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func(); - -int main() { - + builtin and then its argument prototype would still apply. */ +char pcap_list_datalinks (); /* 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_$ac_func) || defined (__stub___$ac_func) +#if defined (__stub_pcap_list_datalinks) || defined (__stub___pcap_list_datalinks) choke me #else -$ac_func(); +char (*f) () = pcap_list_datalinks; +#endif +#ifdef __cplusplus +} #endif -; return 0; } -EOF -if { (eval echo configure:1893: \"$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 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_func_$ac_func=no" -fi -rm -f conftest* -fi - -if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'` - cat >> confdefs.h <&6 -fi -done - - if test $ac_cv_func_sigset = no ; then - for ac_func in sigaction -do -echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1921: 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 <&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_func_pcap_list_datalinks=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_func_pcap_list_datalinks=no +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_func_pcap_list_datalinks" >&5 +echo "${ECHO_T}$ac_cv_func_pcap_list_datalinks" >&6 +if test $ac_cv_func_pcap_list_datalinks = yes; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_PCAP_LIST_DATALINKS 1 +_ACEOF + +else + LIBOBJS="$LIBOBJS datalinks.$ac_objext" +fi + + echo "$as_me:$LINENO: checking for pcap_set_datalink" >&5 +echo $ECHO_N "checking for pcap_set_datalink... $ECHO_C" >&6 +if test "${ac_cv_func_pcap_set_datalink+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ /* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func(); below. */ -#include + which can conflict with char pcap_set_datalink (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif /* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif /* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func(); - -int main() { - + builtin and then its argument prototype would still apply. */ +char pcap_set_datalink (); /* 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_$ac_func) || defined (__stub___$ac_func) +#if defined (__stub_pcap_set_datalink) || defined (__stub___pcap_set_datalink) choke me #else -$ac_func(); +char (*f) () = pcap_set_datalink; +#endif +#ifdef __cplusplus +} #endif -; return 0; } -EOF -if { (eval echo configure:1949: \"$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 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_func_$ac_func=no" -fi -rm -f conftest* -fi - -if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'` - cat >> confdefs.h <&6 -fi -done - - fi - ;; - 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:1981: checking for gethostbyname" >&5 -if eval "test \"`echo '$''{'ac_cv_func_gethostbyname'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - cat > conftest.$ac_ext <&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_func_pcap_set_datalink=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_func_pcap_set_datalink=no +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_func_pcap_set_datalink" >&5 +echo "${ECHO_T}$ac_cv_func_pcap_set_datalink" >&6 +if test $ac_cv_func_pcap_set_datalink = yes; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_PCAP_SET_DATALINK 1 +_ACEOF + +fi + + echo "$as_me:$LINENO: checking for pcap_datalink_name_to_val" >&5 +echo $ECHO_N "checking for pcap_datalink_name_to_val... $ECHO_C" >&6 +if test "${ac_cv_func_pcap_datalink_name_to_val+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ /* System header to define __stub macros and hopefully few prototypes, - which can conflict with char gethostbyname(); below. */ -#include + which can conflict with char pcap_datalink_name_to_val (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif /* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif /* 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() { - + builtin and then its argument prototype would still apply. */ +char pcap_datalink_name_to_val (); /* 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) +#if defined (__stub_pcap_datalink_name_to_val) || defined (__stub___pcap_datalink_name_to_val) choke me #else -gethostbyname(); +char (*f) () = pcap_datalink_name_to_val; +#endif +#ifdef __cplusplus +} #endif -; return 0; } -EOF -if { (eval echo configure:2009: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then - rm -rf conftest* - eval "ac_cv_func_gethostbyname=yes" -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_func_gethostbyname=no" -fi -rm -f conftest* -fi - -if eval "test \"`echo '$ac_cv_func_'gethostbyname`\" = yes"; then - echo "$ac_t""yes" 1>&6 - : -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:2028: 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 - echo $ac_n "(cached) $ac_c" 1>&6 -else - ac_save_LIBS="$LIBS" -LIBS="-lnsl $LIBS" -cat > conftest.$ac_ext <&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_func_pcap_datalink_name_to_val=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_func_pcap_datalink_name_to_val=no +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_func_pcap_datalink_name_to_val" >&5 +echo "${ECHO_T}$ac_cv_func_pcap_datalink_name_to_val" >&6 +if test $ac_cv_func_pcap_datalink_name_to_val = yes; then + + cat >>confdefs.h <<\_ACEOF +#define HAVE_PCAP_DATALINK_NAME_TO_VAL 1 +_ACEOF + + echo "$as_me:$LINENO: checking for pcap_datalink_val_to_description" >&5 +echo $ECHO_N "checking for pcap_datalink_val_to_description... $ECHO_C" >&6 +if test "${ac_cv_func_pcap_datalink_val_to_description+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char pcap_datalink_val_to_description (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif /* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif /* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char gethostbyname(); + builtin and then its argument prototype would still apply. */ +char pcap_datalink_val_to_description (); +/* 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_pcap_datalink_val_to_description) || defined (__stub___pcap_datalink_val_to_description) +choke me +#else +char (*f) () = pcap_datalink_val_to_description; +#endif +#ifdef __cplusplus +} +#endif -int main() { -gethostbyname() -; return 0; } -EOF -if { (eval echo configure:2047: \"$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" +int +main () +{ +return f != pcap_datalink_val_to_description; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_func_pcap_datalink_val_to_description=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" -fi -rm -f conftest* -LIBS="$ac_save_LIBS" + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 +ac_cv_func_pcap_datalink_val_to_description=no 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 nsl | sed -e 's/^a-zA-Z0-9_/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` - cat >> confdefs.h <&5 +echo "${ECHO_T}$ac_cv_func_pcap_datalink_val_to_description" >&6 +if test $ac_cv_func_pcap_datalink_val_to_description = yes; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION 1 +_ACEOF 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:2074: 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 - echo $ac_n "(cached) $ac_c" 1>&6 -else - ac_save_LIBS="$LIBS" -LIBS="-lsocket $LIBS" -cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then - rm -rf conftest* - eval "ac_cv_lbl_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" + LIBOBJS="$LIBOBJS dlnames.$ac_objext" fi -rm -f conftest* -LIBS="$ac_save_LIBS" -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 <&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:2122: 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 - echo $ac_n "(cached) $ac_c" 1>&6 -else - ac_save_LIBS="$LIBS" -LIBS="-lsocket -lnsl $LIBS" -cat > conftest.$ac_ext <&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif /* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif /* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char gethostbyname(); + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* 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_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif -int main() { -gethostbyname() -; return 0; } -EOF -if { (eval echo configure:2141: \"$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" -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_lbl_lib_$ac_lib_var=no" -fi -rm -f conftest* -LIBS="$ac_save_LIBS" +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF 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:2160: checking for gethostbyname in -lresolv" >&5 -ac_lib_var=`echo resolv'_'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" -cat > conftest.$ac_ext <&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 resolv | sed -e 's/^a-zA-Z0-9_/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` - cat >> confdefs.h <&5 +echo $ECHO_N "checking for inet_ntop... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#include +#include +int +main () +{ +char src[4], dst[128]; +inet_ntop(AF_INET, src, dst, sizeof(dst)); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 + LIBOBJS="$LIBOBJS inet_ntop.o.$ac_objext" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +echo "$as_me:$LINENO: checking for inet_pton" >&5 +echo $ECHO_N "checking for inet_pton... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#include +#include +int +main () +{ +char src[128], dst[4]; +inet_pton(AF_INET, src, dst); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 + LIBOBJS="$LIBOBJS inet_pton.o.$ac_objext" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +echo "$as_me:$LINENO: checking for inet_aton" >&5 +echo $ECHO_N "checking for inet_aton... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#include +int +main () +{ +char src[128]; +struct in_addr dst; +inet_aton(src, &dst); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 + LIBOBJS="$LIBOBJS inet_aton.o.$ac_objext" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext + + + echo "$as_me:$LINENO: checking if sockaddr struct has sa_len member" >&5 +echo $ECHO_N "checking if sockaddr struct has sa_len member... $ECHO_C" >&6 + if test "${ac_cv_sockaddr_has_sa_len+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +# include +# include +int +main () +{ +u_int i = sizeof(((struct sockaddr *)0)->sa_len) + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_sockaddr_has_sa_len=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_sockaddr_has_sa_len=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi + + echo "$as_me:$LINENO: result: $ac_cv_sockaddr_has_sa_len" >&5 +echo "${ECHO_T}$ac_cv_sockaddr_has_sa_len" >&6 + if test $ac_cv_sockaddr_has_sa_len = yes ; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_SOCKADDR_SA_LEN 1 +_ACEOF -else - echo "$ac_t""no" 1>&6 -fi + fi +if test "$ac_cv_sockaddr_has_sa_len" = no; then + missing_includes=yes fi -fi -fi -fi - echo $ac_n "checking for socket""... $ac_c" 1>&6 -echo "configure:2215: checking for socket" >&5 -if eval "test \"`echo '$''{'ac_cv_func_socket'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - cat > conftest.$ac_ext <&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ /* System header to define __stub macros and hopefully few prototypes, - which can conflict with char socket(); below. */ -#include + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif /* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif /* 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() { - + builtin and then its argument prototype would still apply. */ +char $ac_func (); /* 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) +#if defined (__stub_$ac_func) || defined (__stub___$ac_func) choke me #else -socket(); +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} #endif -; return 0; } -EOF -if { (eval echo configure:2243: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then - rm -rf conftest* - eval "ac_cv_func_socket=yes" -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* +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + fi +done -if eval "test \"`echo '$ac_cv_func_'socket`\" = yes"; then - echo "$ac_t""yes" 1>&6 - : +if test $ac_cv_func_pcap_findalldevs = "yes" ; then + echo "$as_me:$LINENO: checking for pcap_if_t" >&5 +echo $ECHO_N "checking for pcap_if_t... $ECHO_C" >&6 +if test "${ac_cv_type_pcap_if_t+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include + +int +main () +{ +if ((pcap_if_t *) 0) + return 0; +if (sizeof (pcap_if_t)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_type_pcap_if_t=yes else - echo "$ac_t""no" 1>&6 -echo $ac_n "checking for socket in -lsocket""... $ac_c" 1>&6 -echo "configure:2261: 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" -cat > conftest.$ac_ext <&5 +sed 's/^/| /' conftest.$ac_ext >&5 -int main() { -socket() -; return 0; } -EOF -if { (eval echo configure:2280: \"$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" +ac_cv_type_pcap_if_t=no fi -rm -f conftest* -LIBS="$ac_save_LIBS" - +rm -f conftest.$ac_objext conftest.$ac_ext 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 <&5 +echo "${ECHO_T}$ac_cv_type_pcap_if_t" >&6 +if test $ac_cv_type_pcap_if_t = yes; then - LIBS="-lsocket $LIBS" +cat >>confdefs.h <<_ACEOF +#define HAVE_PCAP_IF_T 1 +_ACEOF -else - echo "$ac_t""no" 1>&6 -echo $ac_n "checking for socket in -lsocket""... $ac_c" 1>&6 -echo "configure:2306: 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_n "(cached) $ac_c" 1>&6 -else - ac_save_LIBS="$LIBS" -LIBS="-lsocket -lnsl $LIBS" -cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then - rm -rf conftest* - eval "ac_cv_lbl_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" fi -rm -f conftest* -LIBS="$ac_save_LIBS" 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 -fi +if test $ac_cv_func_pcap_lib_version = "no" ; then + echo "$as_me:$LINENO: checking whether pcap_version is defined by libpcap" >&5 +echo $ECHO_N "checking whether pcap_version is defined by libpcap... $ECHO_C" >&6 + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + +char * +return_pcap_version(void) +{ + extern char pcap_version[]; + + return pcap_version; +} -fi + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_lbl_cv_pcap_version_defined=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_lbl_cv_pcap_version_defined=no +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext + if test "$ac_lbl_cv_pcap_version_defined" = yes ; then + echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 + cat >>confdefs.h <<\_ACEOF +#define HAVE_PCAP_VERSION 1 +_ACEOF + else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 + fi fi +echo "$as_me:$LINENO: checking whether pcap_debug is defined by libpcap" >&5 +echo $ECHO_N "checking whether pcap_debug is defined by libpcap... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ - # 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:2351: 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 "(cached) $ac_c" 1>&6 -else - ac_save_LIBS="$LIBS" -LIBS="-lstr $LIBS" -cat > conftest.$ac_ext <&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" + return pcap_debug; +} -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 <&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_lbl_cv_pcap_debug_defined=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_lbl_cv_pcap_debug_defined=no +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +if test "$ac_lbl_cv_pcap_debug_defined" = yes ; then + echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 + cat >>confdefs.h <<\_ACEOF +#define HAVE_PCAP_DEBUG 1 +_ACEOF + +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 + # + # OK, what about "yydebug"? + # + echo "$as_me:$LINENO: checking whether yydebug is defined by libpcap" >&5 +echo $ECHO_N "checking whether yydebug is defined by libpcap... $ECHO_C" >&6 + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ - LIBS="-lstr $LIBS" + int + return_yydebug(void) + { + extern int yydebug; -else - echo "$ac_t""no" 1>&6 -fi + return yydebug; + } - + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_lbl_cv_yydebug_defined=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_lbl_cv_yydebug_defined=no +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext + if test "$ac_lbl_cv_yydebug_defined" = yes ; then + echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 + cat >>confdefs.h <<\_ACEOF +#define HAVE_YYDEBUG 1 +_ACEOF - LBL_LIBS="$LIBS" - pfopen=/usr/examples/packetfilter/pfopen.c - if test -f $pfopen ; then - for ac_func in pfopen + else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 + fi +fi + +for ac_func in bpf_dump do -echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:2405: 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 <&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ /* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func(); below. */ -#include + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif /* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif /* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func(); - -int main() { - + builtin and then its argument prototype would still apply. */ +char $ac_func (); /* 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_$ac_func) || defined (__stub___$ac_func) choke me #else -$ac_func(); +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} #endif -; return 0; } -EOF -if { (eval echo configure:2433: \"$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 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_func_$ac_func=no" -fi -rm -f conftest* -fi - -if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'` - cat >> confdefs.h <&6 +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +else + LIBOBJS="$LIBOBJS $ac_func.$ac_objext" fi done - if test $ac_cv_func_pfopen = "no" ; then - echo "$ac_t""Using $pfopen" 1>&6 - LIBS="$LIBS $pfopen" - fi - fi - echo $ac_n "checking for local pcap library""... $ac_c" 1>&6 -echo "configure:2463: checking for local pcap library" >&5 - libpcap=FAIL - lastdir=FAIL - places=`ls .. | sed -e 's,/$,,' -e 's,^,../,' | \ - egrep '/libpcap-[0-9]*\.[0-9]*(\.[0-9]*)?([ab][0-9]*)?$'` - for dir in $places ../libpcap libpcap ; do - basedir=`echo $dir | sed -e 's/[ab][0-9]*$//'` - if test $lastdir = $basedir ; then - continue; - fi - lastdir=$dir - if test -r $dir/pcap.c ; then - libpcap=$dir/libpcap.a - d=$dir - fi - done - 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:2482: 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 -else - ac_save_LIBS="$LIBS" -LIBS="-lpcap $LIBS" -cat > conftest.$ac_ext <&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 - libpcap="-lpcap" -else - echo "$ac_t""no" 1>&6 -fi - - if test $libpcap = FAIL ; then - { echo "configure: error: see the INSTALL doc for more info" 1>&2; exit 1; } - fi - else - V_PCAPDEP=$libpcap - V_INCLS="-I$d $V_INCLS" - echo "$ac_t""$libpcap" 1>&6 - fi - LIBS="$libpcap $LIBS" - case "$target_os" in - - aix*) - pseexe="/lib/pse.exp" - echo $ac_n "checking for $pseexe""... $ac_c" 1>&6 -echo "configure:2531: checking for $pseexe" >&5 - if test -f $pseexe ; then - echo "$ac_t""yes" 1>&6 - LIBS="$LIBS -I:$pseexe" - fi - ;; - esac 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 + cat >>confdefs.h <<\_ACEOF #define _SUN 1 -EOF +_ACEOF ;; @@ -2552,16 +9087,8 @@ irix*) V_GROUP=sys ;; -linux*) - V_INCLS="$V_INCLS -Ilinux-include" - ;; - osf*) V_GROUP=system - cat >> confdefs.h <<\EOF -#define __STDC__ 2 -EOF - ;; solaris*) @@ -2573,14 +9100,246 @@ if test -f /dev/bpf0 ; then V_GROUP=bpf fi -echo $ac_n "checking for int32_t using $CC""... $ac_c" 1>&6 -echo "configure:2578: 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 +echo "$as_me:$LINENO: checking for int8_t using $CC" >&5 +echo $ECHO_N "checking for int8_t using $CC... $ECHO_C" >&6 + if test "${ac_cv_lbl_have_int8_t+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - cat > conftest.$ac_ext <conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +# include "confdefs.h" +# include +# if STDC_HEADERS +# include +# include +# endif +int +main () +{ +int8_t i + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lbl_have_int8_t=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lbl_have_int8_t=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi + + echo "$as_me:$LINENO: result: $ac_cv_lbl_have_int8_t" >&5 +echo "${ECHO_T}$ac_cv_lbl_have_int8_t" >&6 + if test $ac_cv_lbl_have_int8_t = no ; then + cat >>confdefs.h <<\_ACEOF +#define int8_t signed char +_ACEOF + + fi +echo "$as_me:$LINENO: checking for u_int8_t using $CC" >&5 +echo $ECHO_N "checking for u_int8_t using $CC... $ECHO_C" >&6 + if test "${ac_cv_lbl_have_u_int8_t+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +# include "confdefs.h" +# include +# if STDC_HEADERS +# include +# include +# endif +int +main () +{ +u_int8_t i + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lbl_have_u_int8_t=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lbl_have_u_int8_t=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi + + echo "$as_me:$LINENO: result: $ac_cv_lbl_have_u_int8_t" >&5 +echo "${ECHO_T}$ac_cv_lbl_have_u_int8_t" >&6 + if test $ac_cv_lbl_have_u_int8_t = no ; then + cat >>confdefs.h <<\_ACEOF +#define u_int8_t u_char +_ACEOF + + fi +echo "$as_me:$LINENO: checking for int16_t using $CC" >&5 +echo $ECHO_N "checking for int16_t using $CC... $ECHO_C" >&6 + if test "${ac_cv_lbl_have_int16_t+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +# include "confdefs.h" +# include +# if STDC_HEADERS +# include +# include +# endif +int +main () +{ +int16_t i + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lbl_have_int16_t=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lbl_have_int16_t=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi + + echo "$as_me:$LINENO: result: $ac_cv_lbl_have_int16_t" >&5 +echo "${ECHO_T}$ac_cv_lbl_have_int16_t" >&6 + if test $ac_cv_lbl_have_int16_t = no ; then + cat >>confdefs.h <<\_ACEOF +#define int16_t short +_ACEOF + + fi +echo "$as_me:$LINENO: checking for u_int16_t using $CC" >&5 +echo $ECHO_N "checking for u_int16_t using $CC... $ECHO_C" >&6 + if test "${ac_cv_lbl_have_u_int16_t+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +# include "confdefs.h" +# include +# if STDC_HEADERS +# include +# include +# endif +int +main () +{ +u_int16_t i + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lbl_have_u_int16_t=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lbl_have_u_int16_t=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi + + echo "$as_me:$LINENO: result: $ac_cv_lbl_have_u_int16_t" >&5 +echo "${ECHO_T}$ac_cv_lbl_have_u_int16_t" >&6 + if test $ac_cv_lbl_have_u_int16_t = no ; then + cat >>confdefs.h <<\_ACEOF +#define u_int16_t u_short +_ACEOF + + fi +echo "$as_me:$LINENO: checking for int32_t using $CC" >&5 +echo $ECHO_N "checking for int32_t using $CC... $ECHO_C" >&6 + if test "${ac_cv_lbl_have_int32_t+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ # include "confdefs.h" # include @@ -2588,37 +9347,56 @@ else # include # include # endif -int main() { +int +main () +{ int32_t i -; return 0; } -EOF -if { (eval echo configure:2596: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then - rm -rf conftest* + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then ac_cv_lbl_have_int32_t=yes else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - ac_cv_lbl_have_int32_t=no + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lbl_have_int32_t=no fi -rm -f conftest* +rm -f conftest.$ac_objext conftest.$ac_ext fi - echo "$ac_t""$ac_cv_lbl_have_int32_t" 1>&6 + echo "$as_me:$LINENO: result: $ac_cv_lbl_have_int32_t" >&5 +echo "${ECHO_T}$ac_cv_lbl_have_int32_t" >&6 if test $ac_cv_lbl_have_int32_t = no ; then - cat >> confdefs.h <<\EOF + cat >>confdefs.h <<\_ACEOF #define int32_t int -EOF +_ACEOF fi -echo $ac_n "checking for u_int32_t using $CC""... $ac_c" 1>&6 -echo "configure:2616: 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 <&5 +echo $ECHO_N "checking for u_int32_t using $CC... $ECHO_C" >&6 + if test "${ac_cv_lbl_have_u_int32_t+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ # include "confdefs.h" # include @@ -2626,27 +9404,42 @@ else # include # include # endif -int main() { +int +main () +{ u_int32_t i -; return 0; } -EOF -if { (eval echo configure:2634: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then - rm -rf conftest* + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then ac_cv_lbl_have_u_int32_t=yes else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - ac_cv_lbl_have_u_int32_t=no + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lbl_have_u_int32_t=no fi -rm -f conftest* +rm -f conftest.$ac_objext conftest.$ac_ext fi - echo "$ac_t""$ac_cv_lbl_have_u_int32_t" 1>&6 + echo "$as_me:$LINENO: result: $ac_cv_lbl_have_u_int32_t" >&5 +echo "${ECHO_T}$ac_cv_lbl_have_u_int32_t" >&6 if test $ac_cv_lbl_have_u_int32_t = no ; then - cat >> confdefs.h <<\EOF + cat >>confdefs.h <<\_ACEOF #define u_int32_t u_int -EOF +_ACEOF fi @@ -2662,11 +9455,11 @@ rm -f os-proto.h fi V_CCOPT="$V_CCOPT -Wall" if test $ac_cv_lbl_gcc_vers -gt 1 ; then - V_CCOPT="$V_CCOPT -Wmissing-prototypes -Wstrict-prototypes" + V_CCOPT="$V_CCOPT -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -W" fi fi else - case "$target_os" in + case "$host_os" in irix6*) V_CCOPT="$V_CCOPT -n32" @@ -2676,202 +9469,114 @@ 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 - cat >> confdefs.h <<\EOF + cat >>confdefs.h <<\_ACEOF #define HAVE_OS_PROTO_H 1 -EOF +_ACEOF else - echo "configure: warning: can't find $name" 1>&2 + { echo "$as_me:$LINENO: WARNING: can't find $name" >&5 +echo "$as_me: WARNING: can't find $name" >&2;} fi fi -echo $ac_n "checking if sockaddr struct has sa_len member""... $ac_c" 1>&6 -echo "configure:2694: 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 +echo "$as_me:$LINENO: checking if sockaddr struct has sa_len member" >&5 +echo $ECHO_N "checking if sockaddr struct has sa_len member... $ECHO_C" >&6 + if test "${ac_cv_lbl_sockaddr_has_sa_len+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - cat > conftest.$ac_ext <conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ # include # include -int main() { +int +main () +{ u_int i = sizeof(((struct sockaddr *)0)->sa_len) -; return 0; } -EOF -if { (eval echo configure:2708: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then - rm -rf conftest* + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then ac_cv_lbl_sockaddr_has_sa_len=yes else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - ac_cv_lbl_sockaddr_has_sa_len=no + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lbl_sockaddr_has_sa_len=no fi -rm -f conftest* +rm -f conftest.$ac_objext conftest.$ac_ext fi - echo "$ac_t""$ac_cv_lbl_sockaddr_has_sa_len" 1>&6 + echo "$as_me:$LINENO: result: $ac_cv_lbl_sockaddr_has_sa_len" >&5 +echo "${ECHO_T}$ac_cv_lbl_sockaddr_has_sa_len" >&6 if test $ac_cv_lbl_sockaddr_has_sa_len = yes ; then - cat >> confdefs.h <<\EOF + cat >>confdefs.h <<\_ACEOF #define HAVE_SOCKADDR_SA_LEN 1 -EOF +_ACEOF fi -echo $ac_n "checking if ether_header uses ether_addr structs""... $ac_c" 1>&6 -echo "configure:2729: checking if ether_header uses ether_addr structs" >&5 -if eval "test \"`echo '$''{'ac_cv_ether_header_has_ea'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - LBL_SAVE_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $V_INCLS" - cat > conftest.$ac_ext < -# if __STDC__ - /* osf3 has REALLY good prototyes */ - struct mbuf; - struct rtentry; -# endif -# include -# include -# include -# include -int main() { -u_int i = - sizeof(((struct ether_header *)0)->ether_dhost.ether_addr_octet) -; return 0; } -EOF -if { (eval echo configure:2754: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then - rm -rf conftest* - ac_cv_ether_header_has_ea=yes -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - ac_cv_ether_header_has_ea=no -fi -rm -f conftest* - CFLAGS="$LBL_SAVE_CFLAGS" -fi - -echo "$ac_t""$ac_cv_ether_header_has_ea" 1>&6 -if test $ac_cv_ether_header_has_ea = yes ; then - cat >> confdefs.h <<\EOF -#define ETHER_HEADER_HAS_EA 1 -EOF - -fi - -echo $ac_n "checking if ether_arp uses ether_addr structs""... $ac_c" 1>&6 -echo "configure:2776: checking if ether_arp uses ether_addr structs" >&5 -if eval "test \"`echo '$''{'ac_cv_ether_arp_has_ea'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - LBL_SAVE_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $V_INCLS" - cat > conftest.$ac_ext < -# if __STDC__ - /* osf3 has REALLY good prototyes */ - struct mbuf; - struct rtentry; -# endif -# include -# include -# include -# include -int main() { -u_int i = - sizeof(((struct ether_arp *)0)->arp_sha.ether_addr_octet) -; return 0; } -EOF -if { (eval echo configure:2801: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then - rm -rf conftest* - ac_cv_ether_arp_has_ea=yes -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - ac_cv_ether_arp_has_ea=no -fi -rm -f conftest* - CFLAGS="$LBL_SAVE_CFLAGS" -fi - -echo "$ac_t""$ac_cv_ether_arp_has_ea" 1>&6 -if test $ac_cv_ether_arp_has_ea = yes ; then - cat >> confdefs.h <<\EOF -#define ETHER_ARP_HAS_EA 1 -EOF - -fi - -echo $ac_n "checking if ether_arp uses erp_xsha member""... $ac_c" 1>&6 -echo "configure:2823: checking if ether_arp uses erp_xsha member" >&5 -if eval "test \"`echo '$''{'ac_cv_struct_ether_arp_x'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - LBL_SAVE_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $V_INCLS" - cat > conftest.$ac_ext < -# include -# if __STDC__ - /* osf3 has REALLY good prototyes */ - struct mbuf; - struct rtentry; -# endif -# include -# include -# include -int main() { -u_int i = sizeof( ((struct ether_arp *)0)->arp_xsha) -; return 0; } -EOF -if { (eval echo configure:2847: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then - rm -rf conftest* - ac_cv_struct_ether_arp_x=yes -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - ac_cv_struct_ether_arp_x=no -fi -rm -f conftest* - CFLAGS="$LBL_SAVE_CFLAGS" -fi - -echo "$ac_t""$ac_cv_struct_ether_arp_x" 1>&6 -if test $ac_cv_struct_ether_arp_x = yes ; then - cat >> confdefs.h <<\EOF -#define ETHER_ARP_HAS_X 1 -EOF - -fi - -echo $ac_n "checking if unaligned accesses fail""... $ac_c" 1>&6 -echo "configure:2869: 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 - - alpha|hp*|mips|sparc) +echo "$as_me:$LINENO: checking if unaligned accesses fail" >&5 +echo $ECHO_N "checking if unaligned accesses fail... $ECHO_C" >&6 + if test "${ac_cv_lbl_unaligned_fail+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + case "$host_cpu" in + + # + # These are CPU types where: + # + # the CPU faults on an unaligned access, but at least some + # OSes that support that CPU catch the fault and simulate + # the unaligned access (e.g., Alpha/{Digital,Tru64} UNIX) - + # the simulation is slow, so we don't want to use it; + # + # the CPU, I infer (from the old + # + # XXX: should also check that they don't do weird things (like on arm) + # + # comment) doesn't fault on unaligned accesses, but doesn't + # do a normal unaligned fetch, either (e.g., presumably, ARM); + # + # for whatever reason, the test program doesn't work + # (this has been claimed to be the case for several of those + # CPUs - I don't know what the problem is; the problem + # was reported as "the test program dumps core" for SuperH, + # but that's what the test program is *supposed* to do - + # it dumps core before it writes anything, so the test + # for an empty output file should find an empty output + # file and conclude that unaligned accesses don't work). + # + # This run-time test won't work if you're cross-compiling, so + # in order to support cross-compiling for a particular CPU, + # we have to wire in the list of CPU types anyway, as far as + # I know, so perhaps we should just have a set of CPUs on + # which we know it doesn't work, a set of CPUs on which we + # know it does work, and have the script just fail on other + # cpu types and update it when such a failure occurs. + # + alpha*|arm*|hp*|mips*|sh*|sparc*|ia64|nv1) ac_cv_lbl_unaligned_fail=yes ;; @@ -2919,30 +9624,101 @@ EOF esac fi - echo "$ac_t""$ac_cv_lbl_unaligned_fail" 1>&6 + echo "$as_me:$LINENO: result: $ac_cv_lbl_unaligned_fail" >&5 +echo "${ECHO_T}$ac_cv_lbl_unaligned_fail" >&6 if test $ac_cv_lbl_unaligned_fail = yes ; then - cat >> confdefs.h <<\EOF + cat >>confdefs.h <<\_ACEOF #define LBL_ALIGN 1 -EOF +_ACEOF fi -echo $ac_n "checking for SSLeay""... $ac_c" 1>&6 -echo "configure:2932: checking for SSLeay" >&5 + + echo "$as_me:$LINENO: checking for h_errno" >&5 +echo $ECHO_N "checking for h_errno... $ECHO_C" >&6 + if test "${ac_cv_var_h_errno+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +# include +# include +int +main () +{ +int foo = h_errno; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_var_h_errno=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_var_h_errno=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi + + echo "$as_me:$LINENO: result: $ac_cv_var_h_errno" >&5 +echo "${ECHO_T}$ac_cv_var_h_errno" >&6 + if test "$ac_cv_var_h_errno" = "yes"; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_H_ERRNO 1 +_ACEOF + + fi + + + +# Check whether --with-crypto or --without-crypto was given. +if test "${with_crypto+set}" = set; then + withval="$with_crypto" + +else + +echo "$as_me:$LINENO: checking for SSLeay" >&5 +echo $ECHO_N "checking for SSLeay... $ECHO_C" >&6 ac_cv_ssleay_path=no incdir=no -for dir in /usr/local /usr/local/ssl /usr/pkg; do - if test -d $dir/lib -a -f $dir/lib/libcrypto.a; then +for dir in /usr/${host_alias} /usr /usr/local /usr/local/ssl /usr/pkg; do + # + # XXX - is there a better way to check if a given library is + # in a given directory than checking each of the possible + # shared library suffixes? + # + # Are there any other suffixes we need to look for? Do we have to + # worry about ".so.{version}"? + # + # Or should we just look for "libcrypto.*"? + # + if test -d $dir/lib -a \( -f $dir/lib/libcrypto.a -o \ + -f $dir/lib/libcrypto.so -o \ + -f $dir/lib/libcrypto.sl -o \ + -f $dir/lib/libcrypto.dylib \); then ac_cv_ssleay_path=$dir fi - if 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" - else - 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" - fi fi if test "$ac_cv_ssleay_path" != "no" -a "$incdir" != "no"; then break; @@ -2951,167 +9727,229 @@ for dir in /usr/local /usr/local/ssl /usr/pkg; do incdir=no fi done -echo "$ac_t""$ac_cv_ssleay_path" 1>&6 +echo "$as_me:$LINENO: result: $ac_cv_ssleay_path" >&5 +echo "${ECHO_T}$ac_cv_ssleay_path" >&6 if test "$ac_cv_ssleay_path" != no; then V_INCLS="$V_INCLS $incdir" - LIBS="$LIBS -L$dir/lib" - echo $ac_n "checking for des_cbc_encrypt in -lcrypto""... $ac_c" 1>&6 -echo "configure:2960: 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 -else - ac_save_LIBS="$LIBS" -LIBS="-lcrypto $LIBS" -cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then - rm -rf conftest* - eval "ac_cv_lib_$ac_lib_var=yes" +echo "$as_me:$LINENO: checking for des_cbc_encrypt in -lcrypto" >&5 +echo $ECHO_N "checking for des_cbc_encrypt in -lcrypto... $ECHO_C" >&6 +if test "${ac_cv_lib_crypto_des_cbc_encrypt+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 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" + ac_check_lib_save_LIBS=$LIBS +LIBS="-lcrypto $LIBS" +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ -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 crypto | sed -e 's/[^a-zA-Z0-9_]/_/g' \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` - cat >> confdefs.h <&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_crypto_des_cbc_encrypt=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_crypto_des_cbc_encrypt=no +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_crypto_des_cbc_encrypt" >&5 +echo "${ECHO_T}$ac_cv_lib_crypto_des_cbc_encrypt" >&6 +if test $ac_cv_lib_crypto_des_cbc_encrypt = yes; then + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBCRYPTO 1 +_ACEOF LIBS="-lcrypto $LIBS" -else - echo "$ac_t""no" 1>&6 -fi - - cat >> confdefs.h <<\EOF -#define CRYPTO 1 -EOF - - - bak_CPPFLAGS=$CPPFLAGS - CPPFLAGS="$CPPFLAGS $V_INCLS" - for ac_hdr in cast.h rc5.h -do -ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` -echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:3017: 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 -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:3027: \"$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* - eval "ac_cv_header_$ac_safe=yes" -else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_header_$ac_safe=no" -fi -rm -f conftest* -fi -if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then - echo "$ac_t""yes" 1>&6 - ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'` - cat >> confdefs.h <&6 fi -done - if test "$ac_cv_header_cast_h" = "yes"; then - echo $ac_n "checking for buggy CAST128""... $ac_c" 1>&6 -echo "configure:3056: checking for buggy CAST128" >&5 - if test "$cross_compiling" = yes; then - buggy_cast128="cross-compiling, assume yes" -else - cat > conftest.$ac_ext < -main() -{ - unsigned char key[] = {0x01,0x23,0x45,0x67,0x12}; - unsigned char in[] = {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}; - unsigned char out[sizeof(in)]; - unsigned char ok[] = {0x7A,0xC8,0x16,0xD1,0x6E,0x9B,0x30,0x2E}; - CAST_KEY ks; - CAST_set_key(&ks, sizeof(key), key); - CAST_ecb_encrypt(in, out, &ks, CAST_ENCRYPT); - if (memcmp(out, ok, sizeof(ok)) != 0) - return 0; - else - return 1; -} -EOF -if { (eval echo configure:3080: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null -then - buggy_cast128=yes +for ac_header in openssl/evp.h +do +as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 +else + # Is the header compilable? +echo "$as_me:$LINENO: checking $ac_header usability" >&5 +echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +#include <$ac_header> +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_header_compiler=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_header_compiler=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +echo "${ECHO_T}$ac_header_compiler" >&6 + +# Is the header present? +echo "$as_me:$LINENO: checking $ac_header presence" >&5 +echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <$ac_header> +_ACEOF +if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 + (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then + ac_header_preproc=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_preproc=no +fi +rm -f conftest.err conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +echo "${ECHO_T}$ac_header_preproc" >&6 + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc in + yes:no ) + { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 +echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} + ( + cat <<\_ASBOX +## ------------------------------------ ## +## Report this to bug-autoconf@gnu.org. ## +## ------------------------------------ ## +_ASBOX + ) | + sed "s/^/$as_me: WARNING: /" >&2 + ;; + no:yes ) + { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 +echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 +echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} + ( + cat <<\_ASBOX +## ------------------------------------ ## +## Report this to bug-autoconf@gnu.org. ## +## ------------------------------------ ## +_ASBOX + ) | + sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac +echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -fr conftest* - buggy_cast128=no + eval "$as_ac_Header=$ac_header_preproc" fi -rm -fr conftest* +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 + fi +if test `eval echo '${'$as_ac_Header'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF - echo "$ac_t""$buggy_cast128" 1>&6 - if test "$buggy_cast128" != no; then - echo "NOTE: SSLeay 0.9.0b has a bug in CAST128 en/decoding routine." - echo "disabling CAST128 support." - cat >> confdefs.h <<\EOF -#define HAVE_BUGGY_CAST128 1 -EOF +fi - fi - fi +done - CPPFLAGS=$bak_CPPFLAGS fi -if test "${srcdir}" = "." ; then - srcdirprefix="" -else - srcdirprefix="./" -fi +fi; -if test -r ${srcdirprefix}lbl/gnuc.h ; then - rm -f gnuc.h - ln -s ${srcdirprefix}lbl/gnuc.h gnuc.h -fi @@ -3126,350 +9964,1253 @@ fi # SunOS /usr/etc/install # IRIX /sbin/install # AIX /bin/install +# AmigaOS /C/install, which installs bootblocks on floppy discs # AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag # AFS /usr/afsws/bin/install, which mishandles nonexistent args # 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:3135: checking for a BSD compatible install" >&5 +echo "$as_me:$LINENO: checking for a BSD-compatible install" >&5 +echo $ECHO_N "checking for a BSD-compatible install... $ECHO_C" >&6 if test -z "$INSTALL"; then -if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - IFS="${IFS= }"; ac_save_IFS="$IFS"; IFS=":" - for ac_dir in $PATH; do - # Account for people who put trailing slashes in PATH elements. - case "$ac_dir/" in - /|./|.//|/etc/*|/usr/sbin/*|/usr/etc/*|/sbin/*|/usr/afsws/bin/*|/usr/ucb/*) ;; - *) - # OSF1 and SCO ODT 3.0 have their own names for install. - # Don't use installbsd from OSF since it installs stuff as root - # by default. - for ac_prog in ginstall scoinst install; do - if test -f $ac_dir/$ac_prog; then - if test $ac_prog = install && - grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then - # AIX install. It has an incompatible calling convention. - : - else - ac_cv_path_install="$ac_dir/$ac_prog -c" - break 2 - fi - fi +if test "${ac_cv_path_install+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + # Account for people who put trailing slashes in PATH elements. +case $as_dir/ in + ./ | .// | /cC/* | \ + /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ + /usr/ucb/* ) ;; + *) + # OSF1 and SCO ODT 3.0 have their own names for install. + # Don't use installbsd from OSF since it installs stuff as root + # by default. + for ac_prog in ginstall scoinst install; do + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then + if test $ac_prog = install && + grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # AIX install. It has an incompatible calling convention. + : + elif test $ac_prog = install && + grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # program-specific install script used by HP pwplus--don't use. + : + else + ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" + break 3 + fi + fi done - ;; - esac - done - IFS="$ac_save_IFS" + done + ;; +esac +done + fi if test "${ac_cv_path_install+set}" = set; then - INSTALL="$ac_cv_path_install" + INSTALL=$ac_cv_path_install else # As a last resort, use the slow shell script. We don't cache a # path for INSTALL within a source directory, because that will # break other packages using the cache if that directory is # removed, or if the path is relative. - INSTALL="$ac_install_sh" + INSTALL=$ac_install_sh fi fi -echo "$ac_t""$INSTALL" 1>&6 +echo "$as_me:$LINENO: result: $INSTALL" >&5 +echo "${ECHO_T}$INSTALL" >&6 # Use test -z because SunOS4 sh mishandles braces in ${var-val}. # It thinks the first close brace ends the variable substitution. test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' -test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL_PROGRAM}' +test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' -trap '' 1 2 15 -cat > confcache <<\EOF + ac_config_headers="$ac_config_headers config.h" + + + ac_config_commands="$ac_config_commands default-1" + + ac_config_files="$ac_config_files Makefile" +cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure -# scripts and configure runs. It is not useful on other systems. -# If it contains results you don't want to keep, you may remove or edit it. +# scripts and configure runs, see configure's option --config-cache. +# It is not useful on other systems. If it contains results you don't +# want to keep, you may remove or edit it. # -# By default, configure uses ./config.cache as the cache file, -# creating it if it does not exist already. You can give configure -# the --cache-file=FILE option to use a different cache file; that is -# what configure does when it calls configure scripts in -# subdirectories, so they share the cache. -# Giving --cache-file=/dev/null disables caching, for debugging configure. -# config.status only pays attention to the cache file if you give it the -# --recheck option to rerun configure. +# config.status only pays attention to the cache file if you give it +# the --recheck option to rerun configure. # -EOF +# `ac_cv_env_foo' variables (set or unset) will be overridden when +# loading this file, other *unset* `ac_cv_foo' will be assigned the +# following values. + +_ACEOF + # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. # So, don't put newlines in cache variables' values. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. -(set) 2>&1 | - case `(ac_space=' '; set | grep ac_space) 2>&1` in - *ac_space=\ *) - # `set' does not quote correctly, so add quotes (double-quote substitution - # turns \\\\ into \\, and sed turns \\ into \). - sed -n \ - -e "s/'/'\\\\''/g" \ - -e "s/^\\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\\)=\\(.*\\)/\\1=\${\\1='\\2'}/p" - ;; - *) - # `set' quotes correctly as required by POSIX, so do not add quotes. - sed -n -e 's/^\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\)=\(.*\)/\1=${\1=\2}/p' - ;; - esac >> confcache -if cmp -s $cache_file confcache; then - : -else +{ + (set) 2>&1 | + case `(ac_space=' '; set | grep ac_space) 2>&1` in + *ac_space=\ *) + # `set' does not quote correctly, so add quotes (double-quote + # substitution turns \\\\ into \\, and sed turns \\ into \). + sed -n \ + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + ;; + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n \ + "s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p" + ;; + esac; +} | + sed ' + t clear + : clear + s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + t end + /^ac_cv_env/!s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ + : end' >>confcache +if diff $cache_file confcache >/dev/null 2>&1; then :; else if test -w $cache_file; then - echo "updating cache $cache_file" - cat confcache > $cache_file + test "x$cache_file" != "x/dev/null" && echo "updating cache $cache_file" + cat confcache >$cache_file else echo "not updating unwritable cache $cache_file" fi fi rm -f confcache -trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15 - test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' -# Any assignment to VPATH causes Sun make to only execute -# the first set of double-colon rules, so remove it if not needed. -# If there is a colon in the path, we need to keep it. +# VPATH may cause trouble with some makes, so we remove $(srcdir), +# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and +# trailing colons and then remove the whole line if VPATH becomes empty +# (actually we leave an empty line to preserve line numbers). if test "x$srcdir" = x.; then - ac_vpsub='/^[ ]*VPATH[ ]*=[^:]*$/d' -fi + ac_vpsub='/^[ ]*VPATH[ ]*=/{ +s/:*\$(srcdir):*/:/; +s/:*\${srcdir}:*/:/; +s/:*@srcdir@:*/:/; +s/^\([^=]*=[ ]*\):*/\1/; +s/:*$//; +s/^[^=]*=[ ]*$//; +}' +fi + +DEFS=-DHAVE_CONFIG_H + +ac_libobjs= +ac_ltlibobjs= +for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue + # 1. Remove the extension, and $U if already installed. + ac_i=`echo "$ac_i" | + sed 's/\$U\././;s/\.o$//;s/\.obj$//'` + # 2. Add them. + ac_libobjs="$ac_libobjs $ac_i\$U.$ac_objext" + ac_ltlibobjs="$ac_ltlibobjs $ac_i"'$U.lo' +done +LIBOBJS=$ac_libobjs -trap 'rm -f $CONFIG_STATUS conftest*; exit 1' 1 2 15 +LTLIBOBJS=$ac_ltlibobjs -# Transform confdefs.h into DEFS. -# Protect against shell expansion while executing Makefile rules. -# Protect against Makefile macro expansion. -cat > conftest.defs <<\EOF -s%#define \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%-D\1=\2%g -s%[ `~#$^&*(){}\\|;'"<>?]%\\&%g -s%\[%\\&%g -s%\]%\\&%g -s%\$%$$%g -EOF -DEFS=`sed -f conftest.defs confdefs.h | tr '\012' ' '` -rm -f conftest.defs -# Without the "./", some shells look in PATH for config.status. : ${CONFIG_STATUS=./config.status} - -echo creating $CONFIG_STATUS -rm -f $CONFIG_STATUS -cat > $CONFIG_STATUS <&5 +echo "$as_me: creating $CONFIG_STATUS" >&6;} +cat >$CONFIG_STATUS <<_ACEOF +#! $SHELL +# Generated by $as_me. # Run this file to recreate the current configuration. -# This directory was configured as follows, -# on host `(hostname || uname -n) 2>/dev/null | sed 1q`: -# -# $0 $ac_configure_args -# # Compiler output produced by configure, useful for debugging -# configure, is in ./config.log if it exists. +# configure, is in config.log if it exists. -ac_cs_usage="Usage: $CONFIG_STATUS [--recheck] [--version] [--help]" -for ac_option +debug=false +ac_cs_recheck=false +ac_cs_silent=false +SHELL=\${CONFIG_SHELL-$SHELL} +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +## --------------------- ## +## M4sh Initialization. ## +## --------------------- ## + +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' +elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then + set -o posix +fi + +# Support unset when possible. +if (FOO=FOO; unset FOO) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + + +# Work around bugs in pre-3.0 UWIN ksh. +$as_unset ENV MAIL MAILPATH +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +for as_var in \ + LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ + LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ + LC_TELEPHONE LC_TIME do - case "\$ac_option" in - -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) - echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion" - exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;; - -version | --version | --versio | --versi | --vers | --ver | --ve | --v) - echo "$CONFIG_STATUS generated by autoconf version 2.13" - exit 0 ;; - -help | --help | --hel | --he | --h) - echo "\$ac_cs_usage"; exit 0 ;; - *) echo "\$ac_cs_usage"; exit 1 ;; - esac + if (set +x; test -n "`(eval $as_var=C; export $as_var) 2>&1`"); then + eval $as_var=C; export $as_var + else + $as_unset $as_var + fi done -ac_given_srcdir=$srcdir -ac_given_INSTALL="$INSTALL" +# Required to use basename. +if expr a : '\(a\)' >/dev/null 2>&1; then + as_expr=expr +else + as_expr=false +fi -trap 'rm -fr `echo "Makefile" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 -EOF -cat >> $CONFIG_STATUS </dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi -# Protect against being on the right side of a sed subst in config.status. -sed 's/%@/@@/; s/@%/@@/; s/%g\$/@g/; /@g\$/s/[\\\\&%]/\\\\&/g; - s/@@/%@/; s/@@/@%/; s/@g\$/%g/' > conftest.subs <<\\CEOF -$ac_vpsub -$extrasub -s%@SHELL@%$SHELL%g -s%@CFLAGS@%$CFLAGS%g -s%@CPPFLAGS@%$CPPFLAGS%g -s%@CXXFLAGS@%$CXXFLAGS%g -s%@FFLAGS@%$FFLAGS%g -s%@DEFS@%$DEFS%g -s%@LDFLAGS@%$LDFLAGS%g -s%@LIBS@%$LIBS%g -s%@exec_prefix@%$exec_prefix%g -s%@prefix@%$prefix%g -s%@program_transform_name@%$program_transform_name%g -s%@bindir@%$bindir%g -s%@sbindir@%$sbindir%g -s%@libexecdir@%$libexecdir%g -s%@datadir@%$datadir%g -s%@sysconfdir@%$sysconfdir%g -s%@sharedstatedir@%$sharedstatedir%g -s%@localstatedir@%$localstatedir%g -s%@libdir@%$libdir%g -s%@includedir@%$includedir%g -s%@oldincludedir@%$oldincludedir%g -s%@infodir@%$infodir%g -s%@mandir@%$mandir%g -s%@host@%$host%g -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 -s%@LIBOBJS@%$LIBOBJS%g -s%@V_CCOPT@%$V_CCOPT%g -s%@V_GROUP@%$V_GROUP%g -s%@V_INCLS@%$V_INCLS%g -s%@V_PCAPDEP@%$V_PCAPDEP%g -s%@LOCALSRC@%$LOCALSRC%g -s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g -s%@INSTALL_SCRIPT@%$INSTALL_SCRIPT%g -s%@INSTALL_DATA@%$INSTALL_DATA%g -CEOF -EOF +# Name of the executable. +as_me=`$as_basename "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)$' \| \ + . : '\(.\)' 2>/dev/null || +echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; } + /^X\/\(\/\/\)$/{ s//\1/; q; } + /^X\/\(\/\).*/{ s//\1/; q; } + s/.*/./; q'` -cat >> $CONFIG_STATUS <<\EOF - -# Split the substitutions into bite-sized pieces for seds with -# small command number limits, like on Digital OSF/1 and HP-UX. -ac_max_sed_cmds=90 # Maximum number of lines to put in a sed script. -ac_file=1 # Number of current file. -ac_beg=1 # First line for current file. -ac_end=$ac_max_sed_cmds # Line after last line for current file. -ac_more_lines=: -ac_sed_cmds="" -while $ac_more_lines; do - if test $ac_beg -gt 1; then - sed "1,${ac_beg}d; ${ac_end}q" conftest.subs > conftest.s$ac_file + +# PATH needs CR, and LINENO needs CR and PATH. +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' else - sed "${ac_end}q" conftest.subs > conftest.s$ac_file + PATH_SEPARATOR=: + fi + rm -f conf$$.sh +fi + + + as_lineno_1=$LINENO + as_lineno_2=$LINENO + as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null` + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x$as_lineno_3" = "x$as_lineno_2" || { + # Find who we are. Look in the path if we contain no path at all + # relative or not. + case $0 in + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break +done + + ;; + esac + # We did not find ourselves, most probably we were run as `sh COMMAND' + # in which case we are not to be found in the path. + if test "x$as_myself" = x; then + as_myself=$0 fi - if test ! -s conftest.s$ac_file; then - ac_more_lines=false - rm -f conftest.s$ac_file + if test ! -f "$as_myself"; then + { { echo "$as_me:$LINENO: error: cannot find myself; rerun with an absolute path" >&5 +echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2;} + { (exit 1); exit 1; }; } + fi + case $CONFIG_SHELL in + '') + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for as_base in sh bash ksh sh5; do + case $as_dir in + /*) + if ("$as_dir/$as_base" -c ' + as_lineno_1=$LINENO + as_lineno_2=$LINENO + as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null` + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x$as_lineno_3" = "x$as_lineno_2" ') 2>/dev/null; then + $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; } + $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; } + CONFIG_SHELL=$as_dir/$as_base + export CONFIG_SHELL + exec "$CONFIG_SHELL" "$0" ${1+"$@"} + fi;; + esac + done +done +;; + esac + + # Create $as_me.lineno as a copy of $as_myself, but with $LINENO + # uniformly replaced by the line number. The first 'sed' inserts a + # line-number line before each line; the second 'sed' does the real + # work. The second script uses 'N' to pair each line-number line + # with the numbered line, and appends trailing '-' during + # substitution so that $LINENO is not a special case at line end. + # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the + # second 'sed' script. Blame Lee E. McMahon for sed's syntax. :-) + sed '=' <$as_myself | + sed ' + N + s,$,-, + : loop + s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3, + t loop + s,-$,, + s,^['$as_cr_digits']*\n,, + ' >$as_me.lineno && + chmod +x $as_me.lineno || + { { echo "$as_me:$LINENO: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&5 +echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2;} + { (exit 1); exit 1; }; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensible to this). + . ./$as_me.lineno + # Exit status is that of the last command. + exit +} + + +case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in + *c*,-n*) ECHO_N= ECHO_C=' +' ECHO_T=' ' ;; + *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;; + *) ECHO_N= ECHO_C='\c' ECHO_T= ;; +esac + +if expr a : '\(a\)' >/dev/null 2>&1; then + as_expr=expr +else + as_expr=false +fi + +rm -f conf$$ conf$$.exe conf$$.file +echo >conf$$.file +if ln -s conf$$.file conf$$ 2>/dev/null; then + # We could just check for DJGPP; but this test a) works b) is more generic + # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04). + if test -f conf$$.exe; then + # Don't use ln at all; we don't have any links + as_ln_s='cp -p' else - if test -z "$ac_sed_cmds"; then - ac_sed_cmds="sed -f conftest.s$ac_file" - else - ac_sed_cmds="$ac_sed_cmds | sed -f conftest.s$ac_file" - fi - ac_file=`expr $ac_file + 1` - ac_beg=$ac_end - ac_end=`expr $ac_end + $ac_max_sed_cmds` + as_ln_s='ln -s' fi +elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.file + +if mkdir -p . 2>/dev/null; then + as_mkdir_p=: +else + as_mkdir_p=false +fi + +as_executable_p="test -f" + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="sed y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="sed y%*+%pp%;s%[^_$as_cr_alnum]%_%g" + + +# IFS +# We need space, tab and new line, in precisely that order. +as_nl=' +' +IFS=" $as_nl" + +# CDPATH. +$as_unset CDPATH + +exec 6>&1 + +# Open the log real soon, to keep \$[0] and so on meaningful, and to +# report actual input values of CONFIG_FILES etc. instead of their +# values after options handling. Logging --version etc. is OK. +exec 5>>config.log +{ + echo + sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX +## Running $as_me. ## +_ASBOX +} >&5 +cat >&5 <<_CSEOF + +This file was extended by $as_me, which was +generated by GNU Autoconf 2.57. Invocation command line was + + CONFIG_FILES = $CONFIG_FILES + CONFIG_HEADERS = $CONFIG_HEADERS + CONFIG_LINKS = $CONFIG_LINKS + CONFIG_COMMANDS = $CONFIG_COMMANDS + $ $0 $@ + +_CSEOF +echo "on `(hostname || uname -n) 2>/dev/null | sed 1q`" >&5 +echo >&5 +_ACEOF + +# Files that config.status was made for. +if test -n "$ac_config_files"; then + echo "config_files=\"$ac_config_files\"" >>$CONFIG_STATUS +fi + +if test -n "$ac_config_headers"; then + echo "config_headers=\"$ac_config_headers\"" >>$CONFIG_STATUS +fi + +if test -n "$ac_config_links"; then + echo "config_links=\"$ac_config_links\"" >>$CONFIG_STATUS +fi + +if test -n "$ac_config_commands"; then + echo "config_commands=\"$ac_config_commands\"" >>$CONFIG_STATUS +fi + +cat >>$CONFIG_STATUS <<\_ACEOF + +ac_cs_usage="\ +\`$as_me' instantiates files from templates according to the +current configuration. + +Usage: $0 [OPTIONS] [FILE]... + + -h, --help print this help, then exit + -V, --version print version number, then exit + -q, --quiet do not print progress messages + -d, --debug don't remove temporary files + --recheck update $as_me by reconfiguring in the same conditions + --file=FILE[:TEMPLATE] + instantiate the configuration file FILE + --header=FILE[:TEMPLATE] + instantiate the configuration header FILE + +Configuration files: +$config_files + +Configuration headers: +$config_headers + +Configuration commands: +$config_commands + +Report bugs to ." +_ACEOF + +cat >>$CONFIG_STATUS <<_ACEOF +ac_cs_version="\\ +config.status +configured by $0, generated by GNU Autoconf 2.57, + with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" + +Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 +Free Software Foundation, Inc. +This config.status script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it." +srcdir=$srcdir +INSTALL="$INSTALL" +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +# If no file are specified by the user, then we need to provide default +# value. By we need to know if files were specified by the user. +ac_need_defaults=: +while test $# != 0 +do + case $1 in + --*=*) + ac_option=`expr "x$1" : 'x\([^=]*\)='` + ac_optarg=`expr "x$1" : 'x[^=]*=\(.*\)'` + ac_shift=: + ;; + -*) + ac_option=$1 + ac_optarg=$2 + ac_shift=shift + ;; + *) # This is not an option, so the user has probably given explicit + # arguments. + ac_option=$1 + ac_need_defaults=false;; + esac + + case $ac_option in + # Handling of the options. +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + ac_cs_recheck=: ;; + --version | --vers* | -V ) + echo "$ac_cs_version"; exit 0 ;; + --he | --h) + # Conflict between --help and --header + { { echo "$as_me:$LINENO: error: ambiguous option: $1 +Try \`$0 --help' for more information." >&5 +echo "$as_me: error: ambiguous option: $1 +Try \`$0 --help' for more information." >&2;} + { (exit 1); exit 1; }; };; + --help | --hel | -h ) + echo "$ac_cs_usage"; exit 0 ;; + --debug | --d* | -d ) + debug=: ;; + --file | --fil | --fi | --f ) + $ac_shift + CONFIG_FILES="$CONFIG_FILES $ac_optarg" + ac_need_defaults=false;; + --header | --heade | --head | --hea ) + $ac_shift + CONFIG_HEADERS="$CONFIG_HEADERS $ac_optarg" + ac_need_defaults=false;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil | --si | --s) + ac_cs_silent=: ;; + + # This is an error. + -*) { { echo "$as_me:$LINENO: error: unrecognized option: $1 +Try \`$0 --help' for more information." >&5 +echo "$as_me: error: unrecognized option: $1 +Try \`$0 --help' for more information." >&2;} + { (exit 1); exit 1; }; } ;; + + *) ac_config_targets="$ac_config_targets $1" ;; + + esac + shift done -if test -z "$ac_sed_cmds"; then - ac_sed_cmds=cat + +ac_configure_extra_args= + +if $ac_cs_silent; then + exec 6>/dev/null + ac_configure_extra_args="$ac_configure_extra_args --silent" fi -EOF -cat >> $CONFIG_STATUS <>$CONFIG_STATUS <<_ACEOF +if \$ac_cs_recheck; then + echo "running $SHELL $0 " $ac_configure_args \$ac_configure_extra_args " --no-create --no-recursion" >&6 + exec $SHELL $0 $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion +fi -CONFIG_FILES=\${CONFIG_FILES-"Makefile"} -EOF -cat >> $CONFIG_STATUS <<\EOF -for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then - # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". - case "$ac_file" in - *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'` - ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; - *) ac_file_in="${ac_file}.in" ;; +_ACEOF + +cat >>$CONFIG_STATUS <<_ACEOF +# +# INIT-COMMANDS section. +# + + + +_ACEOF + + + +cat >>$CONFIG_STATUS <<\_ACEOF +for ac_config_target in $ac_config_targets +do + case "$ac_config_target" in + # Handling of arguments. + "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;; + "default-1" ) CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;; + "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; + *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 +echo "$as_me: error: invalid argument: $ac_config_target" >&2;} + { (exit 1); exit 1; }; };; esac +done + +# If the user did not use the arguments to specify the items to instantiate, +# then the envvar interface is used. Set only those that are not. +# We use the long form for the default assignment because of an extremely +# bizarre bug on SunOS 4.1.3. +if $ac_need_defaults; then + test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files + test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers + test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands +fi + +# Have a temporary directory for convenience. Make it in the build tree +# simply because there is no reason to put it here, and in addition, +# creating and moving files from /tmp can sometimes cause problems. +# Create a temporary directory, and hook for its removal unless debugging. +$debug || +{ + trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0 + trap '{ (exit 1); exit 1; }' 1 2 13 15 +} - # Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories. +# Create a (secure) tmp directory for tmp files. - # Remove last slash and all that follows it. Not all systems have dirname. - ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'` - if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then - # The file is in a subdirectory. - test ! -d "$ac_dir" && mkdir "$ac_dir" - ac_dir_suffix="/`echo $ac_dir|sed 's%^\./%%'`" - # A "../" for each directory in $ac_dir_suffix. - ac_dots=`echo $ac_dir_suffix|sed 's%/[^/]*%../%g'` - else - ac_dir_suffix= ac_dots= +{ + tmp=`(umask 077 && mktemp -d -q "./confstatXXXXXX") 2>/dev/null` && + test -n "$tmp" && test -d "$tmp" +} || +{ + tmp=./confstat$$-$RANDOM + (umask 077 && mkdir $tmp) +} || +{ + echo "$me: cannot create a temporary directory in ." >&2 + { (exit 1); exit 1; } +} + +_ACEOF + +cat >>$CONFIG_STATUS <<_ACEOF + +# +# CONFIG_FILES section. +# + +# No need to generate the scripts if there are no CONFIG_FILES. +# This happens for instance when ./config.status config.h +if test -n "\$CONFIG_FILES"; then + # Protect against being on the right side of a sed subst in config.status. + sed 's/,@/@@/; s/@,/@@/; s/,;t t\$/@;t t/; /@;t t\$/s/[\\\\&,]/\\\\&/g; + s/@@/,@/; s/@@/@,/; s/@;t t\$/,;t t/' >\$tmp/subs.sed <<\\CEOF +s,@SHELL@,$SHELL,;t t +s,@PATH_SEPARATOR@,$PATH_SEPARATOR,;t t +s,@PACKAGE_NAME@,$PACKAGE_NAME,;t t +s,@PACKAGE_TARNAME@,$PACKAGE_TARNAME,;t t +s,@PACKAGE_VERSION@,$PACKAGE_VERSION,;t t +s,@PACKAGE_STRING@,$PACKAGE_STRING,;t t +s,@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,;t t +s,@exec_prefix@,$exec_prefix,;t t +s,@prefix@,$prefix,;t t +s,@program_transform_name@,$program_transform_name,;t t +s,@bindir@,$bindir,;t t +s,@sbindir@,$sbindir,;t t +s,@libexecdir@,$libexecdir,;t t +s,@datadir@,$datadir,;t t +s,@sysconfdir@,$sysconfdir,;t t +s,@sharedstatedir@,$sharedstatedir,;t t +s,@localstatedir@,$localstatedir,;t t +s,@libdir@,$libdir,;t t +s,@includedir@,$includedir,;t t +s,@oldincludedir@,$oldincludedir,;t t +s,@infodir@,$infodir,;t t +s,@mandir@,$mandir,;t t +s,@build_alias@,$build_alias,;t t +s,@host_alias@,$host_alias,;t t +s,@target_alias@,$target_alias,;t t +s,@DEFS@,$DEFS,;t t +s,@ECHO_C@,$ECHO_C,;t t +s,@ECHO_N@,$ECHO_N,;t t +s,@ECHO_T@,$ECHO_T,;t t +s,@LIBS@,$LIBS,;t t +s,@build@,$build,;t t +s,@build_cpu@,$build_cpu,;t t +s,@build_vendor@,$build_vendor,;t t +s,@build_os@,$build_os,;t t +s,@host@,$host,;t t +s,@host_cpu@,$host_cpu,;t t +s,@host_vendor@,$host_vendor,;t t +s,@host_os@,$host_os,;t t +s,@SHLICC2@,$SHLICC2,;t t +s,@CC@,$CC,;t t +s,@CFLAGS@,$CFLAGS,;t t +s,@LDFLAGS@,$LDFLAGS,;t t +s,@CPPFLAGS@,$CPPFLAGS,;t t +s,@ac_ct_CC@,$ac_ct_CC,;t t +s,@EXEEXT@,$EXEEXT,;t t +s,@OBJEXT@,$OBJEXT,;t t +s,@CPP@,$CPP,;t t +s,@EGREP@,$EGREP,;t t +s,@LIBOBJS@,$LIBOBJS,;t t +s,@V_CCOPT@,$V_CCOPT,;t t +s,@V_DEFS@,$V_DEFS,;t t +s,@V_GROUP@,$V_GROUP,;t t +s,@V_INCLS@,$V_INCLS,;t t +s,@V_PCAPDEP@,$V_PCAPDEP,;t t +s,@LOCALSRC@,$LOCALSRC,;t t +s,@INSTALL_PROGRAM@,$INSTALL_PROGRAM,;t t +s,@INSTALL_SCRIPT@,$INSTALL_SCRIPT,;t t +s,@INSTALL_DATA@,$INSTALL_DATA,;t t +s,@LTLIBOBJS@,$LTLIBOBJS,;t t +CEOF + +_ACEOF + + cat >>$CONFIG_STATUS <<\_ACEOF + # Split the substitutions into bite-sized pieces for seds with + # small command number limits, like on Digital OSF/1 and HP-UX. + ac_max_sed_lines=48 + ac_sed_frag=1 # Number of current file. + ac_beg=1 # First line for current file. + ac_end=$ac_max_sed_lines # Line after last line for current file. + ac_more_lines=: + ac_sed_cmds= + while $ac_more_lines; do + if test $ac_beg -gt 1; then + sed "1,${ac_beg}d; ${ac_end}q" $tmp/subs.sed >$tmp/subs.frag + else + sed "${ac_end}q" $tmp/subs.sed >$tmp/subs.frag + fi + if test ! -s $tmp/subs.frag; then + ac_more_lines=false + else + # The purpose of the label and of the branching condition is to + # speed up the sed processing (if there are no `@' at all, there + # is no need to browse any of the substitutions). + # These are the two extra sed commands mentioned above. + (echo ':t + /@[a-zA-Z_][a-zA-Z_0-9]*@/!b' && cat $tmp/subs.frag) >$tmp/subs-$ac_sed_frag.sed + if test -z "$ac_sed_cmds"; then + ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed" + else + ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed" + fi + ac_sed_frag=`expr $ac_sed_frag + 1` + ac_beg=$ac_end + ac_end=`expr $ac_end + $ac_max_sed_lines` + fi + done + if test -z "$ac_sed_cmds"; then + ac_sed_cmds=cat fi +fi # test -n "$CONFIG_FILES" - case "$ac_given_srcdir" in - .) srcdir=. - if test -z "$ac_dots"; then top_srcdir=. - else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;; - /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;; - *) # Relative path. - srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix" - top_srcdir="$ac_dots$ac_given_srcdir" ;; +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF +for ac_file in : $CONFIG_FILES; do test "x$ac_file" = x: && continue + # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". + case $ac_file in + - | *:- | *:-:* ) # input from stdin + cat >$tmp/stdin + ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` + ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; + *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` + ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; + * ) ac_file_in=$ac_file.in ;; esac - case "$ac_given_INSTALL" in - [/$]*) INSTALL="$ac_given_INSTALL" ;; - *) INSTALL="$ac_dots$ac_given_INSTALL" ;; - esac + # Compute @srcdir@, @top_srcdir@, and @INSTALL@ for subdirectories. + ac_dir=`(dirname "$ac_file") 2>/dev/null || +$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| \ + . : '\(.\)' 2>/dev/null || +echo X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } + /^X\(\/\/\)[^/].*/{ s//\1/; q; } + /^X\(\/\/\)$/{ s//\1/; q; } + /^X\(\/\).*/{ s//\1/; q; } + s/.*/./; q'` + { if $as_mkdir_p; then + mkdir -p "$ac_dir" + else + as_dir="$ac_dir" + as_dirs= + while test ! -d "$as_dir"; do + as_dirs="$as_dir $as_dirs" + as_dir=`(dirname "$as_dir") 2>/dev/null || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| \ + . : '\(.\)' 2>/dev/null || +echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } + /^X\(\/\/\)[^/].*/{ s//\1/; q; } + /^X\(\/\/\)$/{ s//\1/; q; } + /^X\(\/\).*/{ s//\1/; q; } + s/.*/./; q'` + done + test ! -n "$as_dirs" || mkdir $as_dirs + fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5 +echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;} + { (exit 1); exit 1; }; }; } + + ac_builddir=. + +if test "$ac_dir" != .; then + ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` + # A "../" for each directory in $ac_dir_suffix. + ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'` +else + ac_dir_suffix= ac_top_builddir= +fi + +case $srcdir in + .) # No --srcdir option. We are building in place. + ac_srcdir=. + if test -z "$ac_top_builddir"; then + ac_top_srcdir=. + else + ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'` + fi ;; + [\\/]* | ?:[\\/]* ) # Absolute path. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir ;; + *) # Relative path. + ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_builddir$srcdir ;; +esac +# Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be +# absolute. +ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd` +ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd` +ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd` +ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd` + - echo creating "$ac_file" - rm -f "$ac_file" - configure_input="Generated automatically from `echo $ac_file_in|sed 's%.*/%%'` by configure." - case "$ac_file" in - *Makefile*) ac_comsub="1i\\ -# $configure_input" ;; - *) ac_comsub= ;; + case $INSTALL in + [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; + *) ac_INSTALL=$ac_top_builddir$INSTALL ;; esac - ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"` - sed -e "$ac_comsub -s%@configure_input@%$configure_input%g -s%@srcdir@%$srcdir%g -s%@top_srcdir@%$top_srcdir%g -s%@INSTALL@%$INSTALL%g -" $ac_file_inputs | (eval "$ac_sed_cmds") > $ac_file -fi; done -rm -f conftest.s* + if test x"$ac_file" != x-; then + { echo "$as_me:$LINENO: creating $ac_file" >&5 +echo "$as_me: creating $ac_file" >&6;} + rm -f "$ac_file" + fi + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated by config.status. */ + if test x"$ac_file" = x-; then + configure_input= + else + configure_input="$ac_file. " + fi + configure_input=$configure_input"Generated from `echo $ac_file_in | + sed 's,.*/,,'` by configure." + + # First look for the input files in the build tree, otherwise in the + # src tree. + ac_file_inputs=`IFS=: + for f in $ac_file_in; do + case $f in + -) echo $tmp/stdin ;; + [\\/$]*) + # Absolute (can't be DOS-style, as IFS=:) + test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5 +echo "$as_me: error: cannot find input file: $f" >&2;} + { (exit 1); exit 1; }; } + echo $f;; + *) # Relative + if test -f "$f"; then + # Build tree + echo $f + elif test -f "$srcdir/$f"; then + # Source tree + echo $srcdir/$f + else + # /dev/null tree + { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5 +echo "$as_me: error: cannot find input file: $f" >&2;} + { (exit 1); exit 1; }; } + fi;; + esac + done` || { (exit 1); exit 1; } +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF + sed "$ac_vpsub +$extrasub +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF +:t +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +s,@configure_input@,$configure_input,;t t +s,@srcdir@,$ac_srcdir,;t t +s,@abs_srcdir@,$ac_abs_srcdir,;t t +s,@top_srcdir@,$ac_top_srcdir,;t t +s,@abs_top_srcdir@,$ac_abs_top_srcdir,;t t +s,@builddir@,$ac_builddir,;t t +s,@abs_builddir@,$ac_abs_builddir,;t t +s,@top_builddir@,$ac_top_builddir,;t t +s,@abs_top_builddir@,$ac_abs_top_builddir,;t t +s,@INSTALL@,$ac_INSTALL,;t t +" $ac_file_inputs | (eval "$ac_sed_cmds") >$tmp/out + rm -f $tmp/stdin + if test x"$ac_file" != x-; then + mv $tmp/out $ac_file + else + cat $tmp/out + rm -f $tmp/out + fi -EOF -cat >> $CONFIG_STATUS <>$CONFIG_STATUS <<\_ACEOF -EOF -cat >> $CONFIG_STATUS <<\EOF +# +# CONFIG_HEADER section. +# -exit 0 -EOF -chmod +x $CONFIG_STATUS -rm -fr confdefs* $ac_clean_files -test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1 +# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where +# NAME is the cpp macro being defined and VALUE is the value it is being given. +# +# ac_d sets the value in "#define NAME VALUE" lines. +ac_dA='s,^\([ ]*\)#\([ ]*define[ ][ ]*\)' +ac_dB='[ ].*$,\1#\2' +ac_dC=' ' +ac_dD=',;t' +# ac_u turns "#undef NAME" without trailing blanks into "#define NAME VALUE". +ac_uA='s,^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' +ac_uB='$,\1#\2define\3' +ac_uC=' ' +ac_uD=',;t' + +for ac_file in : $CONFIG_HEADERS; do test "x$ac_file" = x: && continue + # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". + case $ac_file in + - | *:- | *:-:* ) # input from stdin + cat >$tmp/stdin + ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` + ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; + *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` + ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; + * ) ac_file_in=$ac_file.in ;; + esac + + test x"$ac_file" != x- && { echo "$as_me:$LINENO: creating $ac_file" >&5 +echo "$as_me: creating $ac_file" >&6;} + + # First look for the input files in the build tree, otherwise in the + # src tree. + ac_file_inputs=`IFS=: + for f in $ac_file_in; do + case $f in + -) echo $tmp/stdin ;; + [\\/$]*) + # Absolute (can't be DOS-style, as IFS=:) + test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5 +echo "$as_me: error: cannot find input file: $f" >&2;} + { (exit 1); exit 1; }; } + echo $f;; + *) # Relative + if test -f "$f"; then + # Build tree + echo $f + elif test -f "$srcdir/$f"; then + # Source tree + echo $srcdir/$f + else + # /dev/null tree + { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5 +echo "$as_me: error: cannot find input file: $f" >&2;} + { (exit 1); exit 1; }; } + fi;; + esac + done` || { (exit 1); exit 1; } + # Remove the trailing spaces. + sed 's/[ ]*$//' $ac_file_inputs >$tmp/in + +_ACEOF + +# Transform confdefs.h into two sed scripts, `conftest.defines' and +# `conftest.undefs', that substitutes the proper values into +# config.h.in to produce config.h. The first handles `#define' +# templates, and the second `#undef' templates. +# And first: Protect against being on the right side of a sed subst in +# config.status. Protect against being in an unquoted here document +# in config.status. +rm -f conftest.defines conftest.undefs +# Using a here document instead of a string reduces the quoting nightmare. +# Putting comments in sed scripts is not portable. +# +# `end' is used to avoid that the second main sed command (meant for +# 0-ary CPP macros) applies to n-ary macro definitions. +# See the Autoconf documentation for `clear'. +cat >confdef2sed.sed <<\_ACEOF +s/[\\&,]/\\&/g +s,[\\$`],\\&,g +t clear +: clear +s,^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*\)\(([^)]*)\)[ ]*\(.*\)$,${ac_dA}\1${ac_dB}\1\2${ac_dC}\3${ac_dD},gp +t end +s,^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)$,${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD},gp +: end +_ACEOF +# If some macros were called several times there might be several times +# the same #defines, which is useless. Nevertheless, we may not want to +# sort them, since we want the *last* AC-DEFINE to be honored. +uniq confdefs.h | sed -n -f confdef2sed.sed >conftest.defines +sed 's/ac_d/ac_u/g' conftest.defines >conftest.undefs +rm -f confdef2sed.sed + +# This sed command replaces #undef with comments. This is necessary, for +# example, in the case of _POSIX_SOURCE, which is predefined and required +# on some systems where configure will not decide to define it. +cat >>conftest.undefs <<\_ACEOF +s,^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */, +_ACEOF + +# Break up conftest.defines because some shells have a limit on the size +# of here documents, and old seds have small limits too (100 cmds). +echo ' # Handle all the #define templates only if necessary.' >>$CONFIG_STATUS +echo ' if grep "^[ ]*#[ ]*define" $tmp/in >/dev/null; then' >>$CONFIG_STATUS +echo ' # If there are no defines, we may have an empty if/fi' >>$CONFIG_STATUS +echo ' :' >>$CONFIG_STATUS +rm -f conftest.tail +while grep . conftest.defines >/dev/null +do + # Write a limited-size here document to $tmp/defines.sed. + echo ' cat >$tmp/defines.sed <>$CONFIG_STATUS + # Speed up: don't consider the non `#define' lines. + echo '/^[ ]*#[ ]*define/!b' >>$CONFIG_STATUS + # Work around the forget-to-reset-the-flag bug. + echo 't clr' >>$CONFIG_STATUS + echo ': clr' >>$CONFIG_STATUS + sed ${ac_max_here_lines}q conftest.defines >>$CONFIG_STATUS + echo 'CEOF + sed -f $tmp/defines.sed $tmp/in >$tmp/out + rm -f $tmp/in + mv $tmp/out $tmp/in +' >>$CONFIG_STATUS + sed 1,${ac_max_here_lines}d conftest.defines >conftest.tail + rm -f conftest.defines + mv conftest.tail conftest.defines +done +rm -f conftest.defines +echo ' fi # grep' >>$CONFIG_STATUS +echo >>$CONFIG_STATUS + +# Break up conftest.undefs because some shells have a limit on the size +# of here documents, and old seds have small limits too (100 cmds). +echo ' # Handle all the #undef templates' >>$CONFIG_STATUS +rm -f conftest.tail +while grep . conftest.undefs >/dev/null +do + # Write a limited-size here document to $tmp/undefs.sed. + echo ' cat >$tmp/undefs.sed <>$CONFIG_STATUS + # Speed up: don't consider the non `#undef' + echo '/^[ ]*#[ ]*undef/!b' >>$CONFIG_STATUS + # Work around the forget-to-reset-the-flag bug. + echo 't clr' >>$CONFIG_STATUS + echo ': clr' >>$CONFIG_STATUS + sed ${ac_max_here_lines}q conftest.undefs >>$CONFIG_STATUS + echo 'CEOF + sed -f $tmp/undefs.sed $tmp/in >$tmp/out + rm -f $tmp/in + mv $tmp/out $tmp/in +' >>$CONFIG_STATUS + sed 1,${ac_max_here_lines}d conftest.undefs >conftest.tail + rm -f conftest.undefs + mv conftest.tail conftest.undefs +done +rm -f conftest.undefs + +cat >>$CONFIG_STATUS <<\_ACEOF + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated by config.status. */ + if test x"$ac_file" = x-; then + echo "/* Generated by configure. */" >$tmp/config.h + else + echo "/* $ac_file. Generated by configure. */" >$tmp/config.h + fi + cat $tmp/in >>$tmp/config.h + rm -f $tmp/in + if test x"$ac_file" != x-; then + if diff $ac_file $tmp/config.h >/dev/null 2>&1; then + { echo "$as_me:$LINENO: $ac_file is unchanged" >&5 +echo "$as_me: $ac_file is unchanged" >&6;} + else + ac_dir=`(dirname "$ac_file") 2>/dev/null || +$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| \ + . : '\(.\)' 2>/dev/null || +echo X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } + /^X\(\/\/\)[^/].*/{ s//\1/; q; } + /^X\(\/\/\)$/{ s//\1/; q; } + /^X\(\/\).*/{ s//\1/; q; } + s/.*/./; q'` + { if $as_mkdir_p; then + mkdir -p "$ac_dir" + else + as_dir="$ac_dir" + as_dirs= + while test ! -d "$as_dir"; do + as_dirs="$as_dir $as_dirs" + as_dir=`(dirname "$as_dir") 2>/dev/null || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| \ + . : '\(.\)' 2>/dev/null || +echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } + /^X\(\/\/\)[^/].*/{ s//\1/; q; } + /^X\(\/\/\)$/{ s//\1/; q; } + /^X\(\/\).*/{ s//\1/; q; } + s/.*/./; q'` + done + test ! -n "$as_dirs" || mkdir $as_dirs + fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5 +echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;} + { (exit 1); exit 1; }; }; } + rm -f $ac_file + mv $tmp/config.h $ac_file + fi + else + cat $tmp/config.h + rm -f $tmp/config.h + fi +done +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF -if test -f .devel ; then +# +# CONFIG_COMMANDS section. +# +for ac_file in : $CONFIG_COMMANDS; do test "x$ac_file" = x: && continue + ac_dest=`echo "$ac_file" | sed 's,:.*,,'` + ac_source=`echo "$ac_file" | sed 's,[^:]*:,,'` + ac_dir=`(dirname "$ac_dest") 2>/dev/null || +$as_expr X"$ac_dest" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_dest" : 'X\(//\)[^/]' \| \ + X"$ac_dest" : 'X\(//\)$' \| \ + X"$ac_dest" : 'X\(/\)' \| \ + . : '\(.\)' 2>/dev/null || +echo X"$ac_dest" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } + /^X\(\/\/\)[^/].*/{ s//\1/; q; } + /^X\(\/\/\)$/{ s//\1/; q; } + /^X\(\/\).*/{ s//\1/; q; } + s/.*/./; q'` + ac_builddir=. + +if test "$ac_dir" != .; then + ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` + # A "../" for each directory in $ac_dir_suffix. + ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'` +else + ac_dir_suffix= ac_top_builddir= +fi + +case $srcdir in + .) # No --srcdir option. We are building in place. + ac_srcdir=. + if test -z "$ac_top_builddir"; then + ac_top_srcdir=. + else + ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'` + fi ;; + [\\/]* | ?:[\\/]* ) # Absolute path. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir ;; + *) # Relative path. + ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_builddir$srcdir ;; +esac +# Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be +# absolute. +ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd` +ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd` +ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd` +ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd` + + + { echo "$as_me:$LINENO: executing $ac_dest commands" >&5 +echo "$as_me: executing $ac_dest commands" >&6;} + case $ac_dest in + default-1 ) if test -f .devel; then + echo timestamp > stamp-h + cat Makefile-devel-adds >> Makefile make depend +fi ;; + esac +done +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF + +{ (exit 0); exit 0; } +_ACEOF +chmod +x $CONFIG_STATUS +ac_clean_files=$ac_clean_files_save + + +# configure is writing to config.log, and then calls config.status. +# config.status does its own redirection, appending to config.log. +# Unfortunately, on DOS this fails, as config.log is still kept open +# by configure, so config.status won't be able to write to it; its +# output is simply discarded. So we exec the FD to /dev/null, +# effectively closing config.log, so it can be properly (re)opened and +# appended to by config.status. When coming back to configure, we +# need to make the FD available again. +if test "$no_create" != yes; then + ac_cs_success=: + ac_config_status_args= + test "$silent" = yes && + ac_config_status_args="$ac_config_status_args --quiet" + exec 5>/dev/null + $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false + exec 5>>config.log + # Use ||, not &&, to avoid exiting from the if with $? = 1, which + # would make configure fail if this is the last instruction. + $ac_cs_success || { (exit 1); exit 1; } fi + exit 0 diff --git a/kame/kame/tcpdump/configure.in b/kame/kame/tcpdump/configure.in index 1a0b0900cf..3479473367 100755 --- a/kame/kame/tcpdump/configure.in +++ b/kame/kame/tcpdump/configure.in @@ -1,4 +1,4 @@ -dnl @(#) $Header: configure.in,v 1.71 97/07/27 22:17:59 leres Exp $ (LBL) +dnl @(#) $Header: /tcpdump/master/tcpdump/configure.in,v 1.169.2.3 2004/03/28 21:04:48 fenner Exp $ (LBL) dnl dnl Copyright (c) 1994, 1995, 1996, 1997 dnl The Regents of the University of California. All rights reserved. @@ -6,70 +6,652 @@ dnl dnl Process this file with autoconf to produce a configure script. dnl +AC_REVISION($Revision: 1.169.2.3 $) +AC_PREREQ(2.50) AC_INIT(tcpdump.c) -AC_CANONICAL_SYSTEM - -umask 002 - -if test -z "$PWD" ; then - PWD=`pwd` -fi +AC_CANONICAL_HOST AC_LBL_C_INIT(V_CCOPT, V_INCLS) +AC_LBL_C_INLINE +AC_C___ATTRIBUTE__ -AC_CHECK_HEADERS(fcntl.h malloc.h memory.h rpc/rpcent.h) +AC_CHECK_HEADERS(fcntl.h rpc/rpcent.h netdnet/dnetdb.h netinet/ether.h) +AC_CHECK_HEADERS(netinet/if_ether.h, , , [#include +#include ]) AC_HEADER_TIME -case "$target_os" in +case "$host_os" in linux*) AC_MSG_CHECKING(Linux kernel version) - AC_CACHE_VAL(ac_cv_linux_vers, - ac_cv_linux_vers=`uname -r 2>&1 | \ - sed -n -e '$s/.* //' -e '$s/\..*//p'`) + if test "$cross_compiling" = yes; then + AC_CACHE_VAL(ac_cv_linux_vers, + ac_cv_linux_vers=unknown) + else + AC_CACHE_VAL(ac_cv_linux_vers, + ac_cv_linux_vers=`uname -r 2>&1 | \ + sed -n -e '$s/.* //' -e '$s/\..*//p'`) + fi AC_MSG_RESULT($ac_cv_linux_vers) + if test $ac_cv_linux_vers = unknown ; then + AC_MSG_ERROR(cannot determine linux version when cross-compiling) + fi if test $ac_cv_linux_vers -lt 2 ; then AC_MSG_ERROR(version 2 or higher required; see the INSTALL doc for more info) fi - AC_DEFINE(HAVE_NET_SLIP_H) ;; *) - AC_CHECK_HEADERS(net/slip.h) ;; esac -AC_MSG_CHECKING(if --enable-ipv6 option is specified) -AC_ARG_ENABLE(ipv6, [ --enable-ipv6 build IPv6-capable version]) -AC_MSG_RESULT(${enable_ipv6-no}) -if test "$enable_ipv6" = "yes"; then - AC_DEFINE(INET6) - LOCALSRC="print-ip6.c print-ip6opts.c print-ripng.c print-icmp6.c print-frag6.c print-rt6.c print-ospf6.c $LOCALSRC" - LIBS="$LIBS -L../libinet6 -L../libinet6/obj -L/usr/local/v6/lib" - AC_CHECK_FUNCS(getaddrinfo,, AC_CHECK_LIB(inet6, getaddrinfo)) + +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 +main() +{ + int current, revision, age, n; + const int required = 2; + if (smiInit("")) + exit(1); + if (strcmp(SMI_LIBRARY_VERSION, smi_library_version)) + exit(2); + n = sscanf(smi_library_version, "%d:%d:%d", ¤t, &revision, &age); + if (n != 3) + exit(3); + if (required < current - age || required > current) + exit(4); + exit(0); +} +], +[ AC_MSG_RESULT(yes) + AC_DEFINE(LIBSMI) + libsmi=yes], +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 + +AC_MSG_CHECKING([whether to enable ipv6]) +AC_ARG_ENABLE(ipv6, +[ --enable-ipv6 enable ipv6 (with ipv4) support + --disable-ipv6 disable ipv6 support], +[ case "$enableval" in +yes) AC_MSG_RESULT(yes) + LOCALSRC="print-ip6.c print-ip6opts.c print-mobility.c print-ripng.c print-icmp6.c print-frag6.c print-rt6.c print-ospf6.c print-dhcp6.c $LOCALSRC" + AC_DEFINE(INET6) + ipv6=yes + ;; +*) + AC_MSG_RESULT(no) + ipv6=no + ;; + esac ], + + AC_TRY_RUN([ /* AF_INET6 available check */ +#include +#include +main() +{ + if (socket(AF_INET6, SOCK_STREAM, 0) < 0) + exit(1); + else + exit(0); +} +], +[ AC_MSG_RESULT(yes) + LOCALSRC="print-ip6.c print-ip6opts.c print-mobility.c print-ripng.c print-icmp6.c print-frag6.c print-rt6.c print-ospf6.c print-dhcp6.c $LOCALSRC" + AC_DEFINE(INET6) + ipv6=yes], +[ AC_MSG_RESULT(no) + ipv6=no], +[ AC_MSG_RESULT(no) + ipv6=no] +)) + +ipv6type=unknown +ipv6lib=none +ipv6trylibc=no + +if test "$ipv6" = "yes"; then + AC_MSG_CHECKING([ipv6 stack type]) + for i in inria kame linux-glibc linux-libinet6 toshiba v6d zeta; do + case $i in + inria) + dnl http://www.kame.net/ + AC_EGREP_CPP(yes, +[#include +#ifdef IPV6_INRIA_VERSION +yes +#endif], + [ipv6type=$i; + CFLAGS="-DINET6 $CFLAGS"]) + ;; + kame) + dnl http://www.kame.net/ + AC_EGREP_CPP(yes, +[#include +#ifdef __KAME__ +yes +#endif], + [ipv6type=$i; + ipv6lib=inet6; + ipv6libdir=/usr/local/v6/lib; + ipv6trylibc=yes; + CFLAGS="-DINET6 $CFLAGS"]) + ;; + linux-glibc) + dnl http://www.v6.linux.or.jp/ + AC_EGREP_CPP(yes, +[#include +#if defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1 +yes +#endif], + [ipv6type=$i; + CFLAGS="-DINET6 $CFLAGS"]) + ;; + linux-libinet6) + dnl http://www.v6.linux.or.jp/ + dnl + dnl This also matches Solaris 8 and Tru64 UNIX 5.1, + dnl and possibly other versions of those OSes + dnl + if test -d /usr/inet6 -o -f /usr/include/netinet/ip6.h; then + ipv6type=$i + ipv6lib=inet6 + ipv6libdir=/usr/inet6/lib + ipv6trylibc=yes; + CFLAGS="-DINET6 -I/usr/inet6/include $CFLAGS" + fi + ;; + toshiba) + AC_EGREP_CPP(yes, +[#include +#ifdef _TOSHIBA_INET6 +yes +#endif], + [ipv6type=$i; + ipv6lib=inet6; + ipv6libdir=/usr/local/v6/lib; + CFLAGS="-DINET6 $CFLAGS"]) + ;; + v6d) + AC_EGREP_CPP(yes, +[#include +#ifdef __V6D__ +yes +#endif], + [ipv6type=$i; + ipv6lib=v6; + ipv6libdir=/usr/local/v6/lib; + CFLAGS="-I/usr/local/v6/include $CFLAGS"]) + ;; + zeta) + AC_EGREP_CPP(yes, +[#include +#ifdef _ZETA_MINAMI_INET6 +yes +#endif], + [ipv6type=$i; + ipv6lib=inet6; + ipv6libdir=/usr/local/v6/lib; + CFLAGS="-DINET6 $CFLAGS"]) + ;; + esac + if test "$ipv6type" != "unknown"; then + break + fi + done + AC_MSG_RESULT($ipv6type) +fi + +if test "$ipv6" = "yes" -a "$ipv6lib" != "none"; then + if test -d $ipv6libdir -a -f $ipv6libdir/lib$ipv6lib.a; then + LIBS="-L$ipv6libdir -l$ipv6lib $LIBS" + echo "You have $ipv6lib library, using it" + else + if test "$ipv6trylibc" = "yes"; then + echo "You do not have $ipv6lib library, using libc" + else + echo 'Fatal: no $ipv6lib library found. cannot continue.' + echo "You need to fetch lib$ipv6lib.a from appropriate" + echo 'ipv6 kit and compile beforehand.' + exit 1 + fi + fi fi -AC_REPLACE_FUNCS(vfprintf strcasecmp) -AC_CHECK_FUNCS(ether_ntoa setlinebuf) -dnl The following generates a warning from autoconf... -AC_C_BIGENDIAN +if test "$ipv6" = "yes"; then + # + # XXX - on Tru64 UNIX 5.1, there is no "getaddrinfo()" + # function in libc; there are "ngetaddrinfo()" and + # "ogetaddrinfo()" functions, and #defines + # "getaddrinfo" to be either "ngetaddrinfo" or + # "ogetaddrinfo", depending on whether _SOCKADDR_LEN + # or _XOPEN_SOURCE_EXTENDED are defined or not. + # + # So this test doesn't work on Tru64 5.1, and possibly + # on other 5.x releases. This causes the configure + # script to become confused, and results in libpcap + # being unbuildable. + # + AC_SEARCH_LIBS(getaddrinfo, socket, [dnl + AC_MSG_CHECKING(getaddrinfo bug) + AC_CACHE_VAL(td_cv_buggygetaddrinfo, [AC_TRY_RUN([ +#include +#include +#include +#include +#include -AC_CHECK_LIB(dnet, main) -AC_CHECK_LIB(rpc, main) -AC_CHECK_LIB(z, uncompress) -AC_CHECK_HEADERS(zlib.h netinet6/ipcomp.h) +main() +{ + int passive, gaierr, inet4 = 0, inet6 = 0; + struct addrinfo hints, *ai, *aitop; + char straddr[INET6_ADDRSTRLEN], strport[16]; + + for (passive = 0; passive <= 1; passive++) { + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_flags = passive ? AI_PASSIVE : 0; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + if ((gaierr = getaddrinfo(NULL, "54321", &hints, &aitop)) != 0) { + (void)gai_strerror(gaierr); + goto bad; + } + for (ai = aitop; ai; ai = ai->ai_next) { + if (ai->ai_addr == NULL || + ai->ai_addrlen == 0 || + getnameinfo(ai->ai_addr, ai->ai_addrlen, + straddr, sizeof(straddr), strport, sizeof(strport), + NI_NUMERICHOST|NI_NUMERICSERV) != 0) { + goto bad; + } + switch (ai->ai_family) { + case AF_INET: + if (strcmp(strport, "54321") != 0) { + goto bad; + } + if (passive) { + if (strcmp(straddr, "0.0.0.0") != 0) { + goto bad; + } + } else { + if (strcmp(straddr, "127.0.0.1") != 0) { + goto bad; + } + } + inet4++; + break; + case AF_INET6: + if (strcmp(strport, "54321") != 0) { + goto bad; + } + if (passive) { + if (strcmp(straddr, "::") != 0) { + goto bad; + } + } else { + if (strcmp(straddr, "::1") != 0) { + goto bad; + } + } + inet6++; + break; + case AF_UNSPEC: + goto bad; + break; +#ifdef AF_UNIX + case AF_UNIX: +#else +#ifdef AF_LOCAL + case AF_LOCAL: +#endif +#endif + default: + /* another family support? */ + break; + } + } + } + + /* supported family should be 2, unsupported family should be 0 */ + if (!(inet4 == 0 || inet4 == 2)) + goto bad; + if (!(inet6 == 0 || inet6 == 2)) + goto bad; + + if (aitop) + freeaddrinfo(aitop); + exit(0); + + bad: + if (aitop) + freeaddrinfo(aitop); + exit(1); +} +], + td_cv_buggygetaddrinfo=no, + td_cv_buggygetaddrinfo=yes, + td_cv_buggygetaddrinfo=yes)]) + if test "$td_cv_buggygetaddrinfo" = no; then + AC_MSG_RESULT(good) + else + AC_MSG_RESULT(buggy) + fi + + if test "$td_cv_buggygetaddrinfo" = "yes"; then + # + # XXX - it doesn't appear that "ipv6type" can ever be + # set to "linux". Should this be testing for + # "linux-glibc", or for that *or* "linux-libinet6"? + # If the latter, note that "linux-libinet6" is also + # the type given to some non-Linux OSes. + # + if test "$ipv6type" != "linux"; then + echo 'Fatal: You must get working getaddrinfo() function.' + echo ' or you can specify "--disable-ipv6"'. + exit 1 + else + echo 'Warning: getaddrinfo() implementation on your system seems be buggy.' + echo ' Better upgrade your system library to newest version' + echo ' of GNU C library (aka glibc).' + fi + fi + ]) + AC_REPLACE_FUNCS(getaddrinfo getnameinfo) +fi + +AC_CACHE_CHECK([for dnet_htoa declaration in netdnet/dnetdb.h], +[td_cv_decl_netdnet_dnetdb_h_dnet_htoa], +[AC_EGREP_HEADER(dnet_htoa, netdnet/dnetdb.h, + td_cv_decl_netdnet_dnetdb_h_dnet_htoa=yes, + td_cv_decl_netdnet_dnetdb_h_dnet_htoa=no)]) +if test "$td_cv_decl_netdnet_dnetdb_h_dnet_htoa" = yes; then + AC_DEFINE(HAVE_NETDNET_DNETDB_H_DNET_HTOA) +fi + +dnl +dnl check sizeof basic types. +dnl They're very likely to be wrong for cross-compiling. +AC_CHECK_SIZEOF(char, 1) +AC_CHECK_SIZEOF(short, 2) +AC_CHECK_SIZEOF(int, 4) +AC_CHECK_SIZEOF(long, 4) + +dnl +dnl Checks for u_intXX_t +dnl AC_CHECK_BITTYPES(ac_cv_bittypes) +dnl if test "$ac_cv_bittypes" = no; then +dnl missing_includes=yes +dnl fi + +dnl +dnl Checks for addrinfo structure +AC_STRUCT_ADDRINFO(ac_cv_addrinfo) +if test "$ac_cv_addrinfo" = no; then + missing_includes=yes +fi + +dnl +dnl Checks for NI_MAXSERV +AC_NI_MAXSERV(ac_cv_maxserv) +if test "$ac_cv_maxserv" = no; then + missing_includes=yes +fi + +dnl +dnl Checks for NI_NAMEREQD +AC_NI_NAMEREQD(ac_cv_namereqd) +if test "$ac_cv_namereqd" = no; then + missing_includes=yes +fi + +dnl +dnl Checks for sockaddr_storage structure +AC_STRUCT_SA_STORAGE(ac_cv_sa_storage) +if test "$ac_cv_sa_storage" = no; then + missing_includes=yes +fi + +dnl +dnl Checks for IN[6]ADDRSZ +AC_CHECK_ADDRSZ(ac_cv_addrsz) +if test "$ac_cv_addrsz" = no; then + missing_includes=yes +fi + +dnl +dnl Checks for RES_USE_INET6 +AC_CHECK_RES_USE_INET6(ac_cv_res_inet6) +if test "$ac_cv_res_inet6" = no; then + missing_includes=yes +fi + +dnl +dnl Checks for res_state_ext structure +AC_STRUCT_RES_STATE_EXT(ac_cv_res_state_ext) +if test "$ac_cv_res_state_ext" = no; then + missing_includes=yes +fi + +dnl +dnl Checks if res_state structure has nsort member. +AC_STRUCT_RES_STATE(ac_cv_res_state) + +dnl +dnl set additional include path if necessary +if test "$missing_includes" = "yes"; then + CPPFLAGS="$CPPFLAGS -I\$(srcdir)/missing" + V_INCLS="$V_INCLS -I\$(srcdir)/missing" +fi + + +AC_REPLACE_FUNCS(vfprintf strcasecmp strlcat strlcpy strdup strsep) +AC_CHECK_FUNCS(strftime) +AC_CHECK_FUNCS(ether_ntohost, [ + AC_CACHE_CHECK(for buggy ether_ntohost, ac_cv_buggy_ether_ntohost, [ + AC_TRY_RUN([ + #include + #include + #include + #include + + 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,, + [needsnprintf=yes]) +if test $needsnprintf = yes; then + AC_LIBOBJ(snprintf.o) +fi AC_LBL_TYPE_SIGNAL +AC_SEARCH_LIBS(dnet_htoa, dnet, AC_DEFINE(HAVE_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) + +dnl AC_CHECK_LIB(z, uncompress) +dnl AC_CHECK_HEADERS(zlib.h) + AC_LBL_LIBPCAP(V_PCAPDEP, V_INCLS) +# +# Check for these after AC_LBL_LIBPCAP, so we link with the appropriate +# libraries (e.g., "-lsocket -lnsl" on Solaris). +# +# We don't use AC_REPLACE_FUNCS because that uses AC_CHECK_FUNCS which +# use AC_CHECK_FUNC which doesn't let us specify the right #includes +# to make this work on BSD/OS 4.x. BSD/OS 4.x ships with the BIND8 +# resolver, and the way it defines inet_{ntop,pton} is rather strange; +# it does not ship with a libc symbol "inet_ntop()", it ships with +# "_inet_ntop()", and has a #define macro in one of the system headers +# to rename it. +# +dnl AC_TRY_COMPILE(inet_ntop inet_pton inet_aton) +AC_MSG_CHECKING(for inet_ntop) +AC_TRY_LINK([#include +#include +#include +#include ], [char src[4], dst[128]; +inet_ntop(AF_INET, src, dst, sizeof(dst));], + [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no) + AC_LIBOBJ(inet_ntop.o)]) +AC_MSG_CHECKING(for inet_pton) +AC_TRY_LINK([#include +#include +#include +#include ], [char src[128], dst[4]; +inet_pton(AF_INET, src, dst);], + [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no) + AC_LIBOBJ(inet_pton.o)]) +AC_MSG_CHECKING(for inet_aton) +AC_TRY_LINK([#include +#include +#include ], [char src[128]; +struct in_addr dst; +inet_aton(src, &dst);], + [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no) + AC_LIBOBJ(inet_aton.o)]) + +dnl portability macros for getaddrinfo/getnameinfo +dnl +dnl Check for sa_len +AC_CHECK_SA_LEN(ac_cv_sockaddr_has_sa_len) +if test "$ac_cv_sockaddr_has_sa_len" = no; then + missing_includes=yes +fi + +AC_CHECK_FUNCS(pcap_findalldevs pcap_dump_flush pcap_lib_version) +if test $ac_cv_func_pcap_findalldevs = "yes" ; then +dnl Check for MacOS X, which may ship pcap.h from 0.6 but libpcap may +dnl be 0.8; this means that lib has pcap_findalldevs but header doesn't +dnl have pcap_if_t. + AC_CHECK_TYPES(pcap_if_t, , , [#include ]) +fi +if test $ac_cv_func_pcap_lib_version = "no" ; then + AC_MSG_CHECKING(whether pcap_version is defined by libpcap) + AC_TRY_LINK([], + [ +char * +return_pcap_version(void) +{ + extern char pcap_version[]; + + return pcap_version; +} + ], + ac_lbl_cv_pcap_version_defined=yes, + ac_lbl_cv_pcap_version_defined=no) + if test "$ac_lbl_cv_pcap_version_defined" = yes ; then + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_PCAP_VERSION) + else + AC_MSG_RESULT(no) + fi +fi +AC_MSG_CHECKING(whether pcap_debug is defined by libpcap) +AC_TRY_LINK([], + [ +int +return_pcap_debug(void) +{ + extern int pcap_debug; + + return pcap_debug; +} + ], + ac_lbl_cv_pcap_debug_defined=yes, + ac_lbl_cv_pcap_debug_defined=no) +if test "$ac_lbl_cv_pcap_debug_defined" = yes ; then + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_PCAP_DEBUG) +else + AC_MSG_RESULT(no) + # + # OK, what about "yydebug"? + # + AC_MSG_CHECKING(whether yydebug is defined by libpcap) + AC_TRY_LINK([], + [ + int + return_yydebug(void) + { + extern int yydebug; + + return yydebug; + } + ], + ac_lbl_cv_yydebug_defined=yes, + ac_lbl_cv_yydebug_defined=no) + if test "$ac_lbl_cv_yydebug_defined" = yes ; then + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_YYDEBUG) + else + AC_MSG_RESULT(no) + fi +fi +AC_REPLACE_FUNCS(bpf_dump) dnl moved to libpcap in 0.6 + 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 @@ -80,14 +662,8 @@ irix*) V_GROUP=sys ;; -linux*) - V_INCLS="$V_INCLS -Ilinux-include" - ;; - osf*) V_GROUP=system - dnl Workaround around ip_hl vs. ip_vhl problem in netinet/ip.h - AC_DEFINE(__STDC__,2) ;; solaris*) @@ -99,6 +675,10 @@ if test -f /dev/bpf0 ; then V_GROUP=bpf fi +AC_LBL_CHECK_TYPE(int8_t, signed char) +AC_LBL_CHECK_TYPE(u_int8_t, u_char) +AC_LBL_CHECK_TYPE(int16_t, short) +AC_LBL_CHECK_TYPE(u_int16_t, u_short) AC_LBL_CHECK_TYPE(int32_t, int) AC_LBL_CHECK_TYPE(u_int32_t, u_int) @@ -106,97 +686,34 @@ AC_LBL_DEVEL(V_CCOPT) AC_LBL_SOCKADDR_SA_LEN -AC_MSG_CHECKING(if ether_header uses ether_addr structs) -AC_CACHE_VAL(ac_cv_ether_header_has_ea, - LBL_SAVE_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $V_INCLS" - AC_TRY_COMPILE([ -# include -# if __STDC__ - /* osf3 has REALLY good prototyes */ - struct mbuf; - struct rtentry; -# endif -# include -# include -# include -# include ], - [u_int i = - sizeof(((struct ether_header *)0)->ether_dhost.ether_addr_octet)], - ac_cv_ether_header_has_ea=yes, - ac_cv_ether_header_has_ea=no) - CFLAGS="$LBL_SAVE_CFLAGS") -AC_MSG_RESULT($ac_cv_ether_header_has_ea) -if test $ac_cv_ether_header_has_ea = yes ; then - AC_DEFINE(ETHER_HEADER_HAS_EA) -fi - -AC_MSG_CHECKING(if ether_arp uses ether_addr structs) -AC_CACHE_VAL(ac_cv_ether_arp_has_ea, - LBL_SAVE_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $V_INCLS" - AC_TRY_COMPILE([ -# include -# if __STDC__ - /* osf3 has REALLY good prototyes */ - struct mbuf; - struct rtentry; -# endif -# include -# include -# include -# include ], - [u_int i = - sizeof(((struct ether_arp *)0)->arp_sha.ether_addr_octet)], - ac_cv_ether_arp_has_ea=yes, - ac_cv_ether_arp_has_ea=no) - CFLAGS="$LBL_SAVE_CFLAGS") -AC_MSG_RESULT($ac_cv_ether_arp_has_ea) -if test $ac_cv_ether_arp_has_ea = yes ; then - AC_DEFINE(ETHER_ARP_HAS_EA) -fi - -AC_MSG_CHECKING(if ether_arp uses erp_xsha member) -AC_CACHE_VAL(ac_cv_struct_ether_arp_x, - LBL_SAVE_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $V_INCLS" - AC_TRY_COMPILE([ -# include -# include -# if __STDC__ - /* osf3 has REALLY good prototyes */ - struct mbuf; - struct rtentry; -# endif -# include -# include -# include ], - [u_int i = sizeof( ((struct ether_arp *)0)->arp_xsha)], - ac_cv_struct_ether_arp_x=yes, - ac_cv_struct_ether_arp_x=no) - CFLAGS="$LBL_SAVE_CFLAGS") -AC_MSG_RESULT($ac_cv_struct_ether_arp_x) -if test $ac_cv_struct_ether_arp_x = yes ; then - AC_DEFINE(ETHER_ARP_HAS_X) -fi - AC_LBL_UNALIGNED_ACCESS +AC_VAR_H_ERRNO + +AC_ARG_WITH(crypto, [ --without-crypto disable crypto support], + [], [ AC_MSG_CHECKING(for SSLeay) ac_cv_ssleay_path=no incdir=no -for dir in /usr/local /usr/local/ssl /usr/pkg; do - if test -d $dir/lib -a -f $dir/lib/libcrypto.a; then +for dir in /usr/${host_alias} /usr /usr/local /usr/local/ssl /usr/pkg; do + # + # XXX - is there a better way to check if a given library is + # in a given directory than checking each of the possible + # shared library suffixes? + # + # Are there any other suffixes we need to look for? Do we have to + # worry about ".so.{version}"? + # + # Or should we just look for "libcrypto.*"? + # + if test -d $dir/lib -a \( -f $dir/lib/libcrypto.a -o \ + -f $dir/lib/libcrypto.so -o \ + -f $dir/lib/libcrypto.sl -o \ + -f $dir/lib/libcrypto.dylib \); then ac_cv_ssleay_path=$dir fi - if 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" - else - 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" - fi fi if test "$ac_cv_ssleay_path" != "no" -a "$incdir" != "no"; then break; @@ -208,59 +725,22 @@ done AC_MSG_RESULT($ac_cv_ssleay_path) if test "$ac_cv_ssleay_path" != no; then V_INCLS="$V_INCLS $incdir" - LIBS="$LIBS -L$dir/lib" + LDFLAGS="-L$dir/lib $LDFLAGS" + if test -f $ac_cv_ssleay_path/lib/libRSAglue.a; then + LIBS="$LIBS -lRSAglue" + fi + if test -f $ac_cv_ssleay_path/lib/librsaref.a; then + LIBS="$LIBS -lrsaref" + fi AC_CHECK_LIB(crypto, des_cbc_encrypt) - AC_DEFINE(CRYPTO) - bak_CPPFLAGS=$CPPFLAGS CPPFLAGS="$CPPFLAGS $V_INCLS" - AC_CHECK_HEADERS(cast.h rc5.h) - - if test "$ac_cv_header_cast_h" = "yes"; then - AC_MSG_CHECKING(for buggy CAST128) - AC_TRY_RUN(dnl -[ -#include -main() -{ - unsigned char key[] = {0x01,0x23,0x45,0x67,0x12}; - unsigned char in[] = {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}; - unsigned char out[sizeof(in)]; - unsigned char ok[] = {0x7A,0xC8,0x16,0xD1,0x6E,0x9B,0x30,0x2E}; - CAST_KEY ks; - CAST_set_key(&ks, sizeof(key), key); - CAST_ecb_encrypt(in, out, &ks, CAST_ENCRYPT); - if (memcmp(out, ok, sizeof(ok)) != 0) - return 0; - else - return 1; -}], - [buggy_cast128=yes], - [buggy_cast128=no], - [buggy_cast128="cross-compiling, assume yes"]) - AC_MSG_RESULT($buggy_cast128) - if test "$buggy_cast128" != no; then - echo "NOTE: SSLeay 0.9.0b has a bug in CAST128 en/decoding routine." - echo "disabling CAST128 support." - AC_DEFINE(HAVE_BUGGY_CAST128) - fi - fi - - CPPFLAGS=$bak_CPPFLAGS -fi - -if test "${srcdir}" = "." ; then - srcdirprefix="" -else - srcdirprefix="./" -fi - -if test -r ${srcdirprefix}lbl/gnuc.h ; then - rm -f gnuc.h - ln -s ${srcdirprefix}lbl/gnuc.h gnuc.h + AC_CHECK_HEADERS(openssl/evp.h) fi +]) AC_SUBST(V_CCOPT) +AC_SUBST(V_DEFS) AC_SUBST(V_GROUP) AC_SUBST(V_INCLS) AC_SUBST(V_PCAPDEP) @@ -268,9 +748,12 @@ AC_SUBST(LOCALSRC) AC_PROG_INSTALL -AC_OUTPUT(Makefile) +AC_CONFIG_HEADER(config.h) -if test -f .devel ; then +AC_OUTPUT_COMMANDS([if test -f .devel; then + echo timestamp > stamp-h + cat Makefile-devel-adds >> Makefile make depend -fi +fi]) +AC_OUTPUT(Makefile) exit 0 diff --git a/kame/kame/tcpdump/decnet.h b/kame/kame/tcpdump/decnet.h index 0f4bd4c4d0..9a5c147703 100644 --- a/kame/kame/tcpdump/decnet.h +++ b/kame/kame/tcpdump/decnet.h @@ -18,21 +18,29 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: decnet.h,v 1.6 96/07/15 18:15:19 leres Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/decnet.h,v 1.11 2002/12/11 07:13:50 guy Exp $ (LBL) */ -typedef unsigned char byte[1]; /* single byte field */ -typedef unsigned char word[2]; /* 2 byte field */ -typedef unsigned char longword[4]; /* 4 bytes field */ +#ifndef WIN32 +typedef u_int8_t byte[1]; /* single byte field */ +#else +/* + * the keyword 'byte' generates conflicts in Windows + */ +typedef unsigned char Byte[1]; /* single byte field */ +#define byte Byte +#endif /* WIN32 */ +typedef u_int8_t word[2]; /* 2 byte field */ +typedef u_int8_t longword[4]; /* 4 bytes field */ /* * Definitions for DECNET Phase IV protocol headers */ union etheraddress { - unsigned char dne_addr[6]; /* full ethernet address */ + u_int8_t dne_addr[6]; /* full ethernet address */ struct { - unsigned char dne_hiord[4]; /* DECnet HIORD prefix */ - unsigned char dne_nodeaddr[2]; /* DECnet node address */ + u_int8_t dne_hiord[4]; /* DECnet HIORD prefix */ + u_int8_t dne_nodeaddr[2]; /* DECnet node address */ } dne_remote; }; @@ -46,8 +54,8 @@ typedef union etheraddress etheraddr; /* Ethernet address */ #define DN_MAXADDL 20 /* max size of DECnet address */ struct dn_naddr { - unsigned short a_len; /* length of address */ - unsigned char a_addr[DN_MAXADDL]; /* address as bytes */ + u_int16_t a_len; /* length of address */ + u_int8_t a_addr[DN_MAXADDL]; /* address as bytes */ }; /* diff --git a/kame/kame/tcpdump/enc.h b/kame/kame/tcpdump/enc.h new file mode 100644 index 0000000000..f54b4eb695 --- /dev/null +++ b/kame/kame/tcpdump/enc.h @@ -0,0 +1,47 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/enc.h,v 1.1 2003/03/08 08:55:33 guy Exp $ (LBL) */ +/* From $OpenBSD: if_enc.h,v 1.8 2001/06/25 05:14:00 angelos Exp $ */ +/* + * The authors of this code are John Ioannidis (ji@tla.org), + * Angelos D. Keromytis (kermit@csd.uch.gr) and + * Niels Provos (provos@physnet.uni-hamburg.de). + * + * This code was written by John Ioannidis for BSD/OS in Athens, Greece, + * in November 1995. + * + * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996, + * by Angelos D. Keromytis. + * + * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis + * and Niels Provos. + * + * Copyright (C) 1995, 1996, 1997, 1998 by John Ioannidis, Angelos D. Keromytis + * and Niels Provos. + * Copyright (c) 2001, Angelos D. Keromytis. + * + * Permission to use, copy, and modify this software with or without fee + * is hereby granted, provided that this entire notice is included in + * all copies of any software which is or includes a copy or + * modification of this software. + * You may use this code under the GNU public license if you so wish. Please + * contribute changes back to the authors under this freer than GPL license + * so that we may further the use of strong encryption without limitations to + * all. + * + * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY + * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE + * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR + * PURPOSE. + */ + +#define ENC_HDRLEN 12 + +/* From $OpenBSD: mbuf.h,v 1.56 2002/01/25 15:50:23 art Exp $ */ +#define M_CONF 0x0400 /* packet was encrypted (ESP-transport) */ +#define M_AUTH 0x0800 /* packet was authenticated (AH) */ + +struct enchdr { + u_int32_t af; + u_int32_t spi; + u_int32_t flags; +}; diff --git a/kame/kame/tcpdump/esp.h b/kame/kame/tcpdump/esp.h new file mode 100644 index 0000000000..56cdada01e --- /dev/null +++ b/kame/kame/tcpdump/esp.h @@ -0,0 +1,68 @@ +/* $NetBSD: esp.h,v 1.13 2000/09/26 08:37:38 itojun Exp $ */ +/* $KAME: esp.h,v 1.15 2000/09/20 18:15:22 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. + */ + +/* + * RFC1827/2406 Encapsulated Security Payload. + */ + +#ifndef _NETINET6_ESP_H_ +#define _NETINET6_ESP_H_ + +struct esp { + u_int32_t esp_spi; /* ESP */ + /*variable size, 32bit bound*/ /* Initialization Vector */ + /*variable size*/ /* Payload data */ + /*variable size*/ /* padding */ + /*8bit*/ /* pad size */ + /*8bit*/ /* next header */ + /*8bit*/ /* next header */ + /*variable size, 32bit bound*/ /* Authentication data (new IPsec) */ +}; + +struct newesp { + u_int32_t esp_spi; /* ESP */ + u_int32_t esp_seq; /* Sequence number */ + /*variable size*/ /* (IV and) Payload data */ + /*variable size*/ /* padding */ + /*8bit*/ /* pad size */ + /*8bit*/ /* next header */ + /*8bit*/ /* next header */ + /*variable size, 32bit bound*/ /* Authentication data */ +}; + +struct esptail { + u_int8_t esp_padlen; /* pad length */ + u_int8_t esp_nxt; /* Next header */ + /*variable size, 32bit bound*/ /* Authentication data (new IPsec)*/ +}; + +#endif /*_NETINET6_ESP_H_*/ diff --git a/kame/kame/tcpdump/ether.h b/kame/kame/tcpdump/ether.h new file mode 100644 index 0000000000..3d3f3be501 --- /dev/null +++ b/kame/kame/tcpdump/ether.h @@ -0,0 +1,59 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/ether.h,v 1.8 2002/12/11 07:13:51 guy Exp $ (LBL) */ +/* + * 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. + * + * @(#)if_ether.h 8.3 (Berkeley) 5/2/95 + */ + +#define ETHERMTU 1500 + +/* + * The number of bytes in an ethernet (MAC) address. + */ +#define ETHER_ADDR_LEN 6 + +/* + * Structure of a DEC/Intel/Xerox or 802.3 Ethernet header. + */ +struct ether_header { + u_int8_t ether_dhost[ETHER_ADDR_LEN]; + u_int8_t ether_shost[ETHER_ADDR_LEN]; + u_int16_t ether_type; +}; + +/* + * Length of a DEC/Intel/Xerox or 802.3 Ethernet header; note that some + * compilers may pad "struct ether_header" to a multiple of 4 bytes, + * for example, so "sizeof (struct ether_header)" may not give the right + * answer. + */ +#define ETHER_HDRLEN 14 diff --git a/kame/kame/tcpdump/ethertype.h b/kame/kame/tcpdump/ethertype.h index 2403073750..f09ea6eff4 100644 --- a/kame/kame/tcpdump/ethertype.h +++ b/kame/kame/tcpdump/ethertype.h @@ -18,11 +18,33 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: ethertype.h,v 1.6 96/07/14 18:21:49 leres Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/ethertype.h,v 1.20 2003/07/01 19:10:26 guy Exp $ (LBL) */ -/* Types missing from some systems */ +/* + * Ethernet types. + * + * We wrap the declarations with #ifdef, so that if a file includes + * , which may declare some of these, we don't + * get a bunch of complaints from the C compiler about redefinitions + * of these values. + * + * We declare all of them here so that no file has to include + * if all it needs are ETHERTYPE_ values. + */ +#ifndef ETHERTYPE_PUP +#define ETHERTYPE_PUP 0x0200 /* PUP protocol */ +#endif +#ifndef ETHERTYPE_IP +#define ETHERTYPE_IP 0x0800 /* IP protocol */ +#endif +#ifndef ETHERTYPE_ARP +#define ETHERTYPE_ARP 0x0806 /* Addr. resolution protocol */ +#endif +#ifndef ETHERTYPE_REVARP +#define ETHERTYPE_REVARP 0x8035 /* reverse Addr. resolution protocol */ +#endif #ifndef ETHERTYPE_NS #define ETHERTYPE_NS 0x0600 #endif @@ -47,9 +69,6 @@ #ifndef ETHERTYPE_SCA #define ETHERTYPE_SCA 0x6007 #endif -#ifndef ETHERTYPE_REVARP -#define ETHERTYPE_REVARP 0x8035 -#endif #ifndef ETHERTYPE_LANBRIDGE #define ETHERTYPE_LANBRIDGE 0x8038 #endif @@ -71,6 +90,38 @@ #ifndef ETHERTYPE_AARP #define ETHERTYPE_AARP 0x80f3 #endif +#ifndef ETHERTYPE_8021Q +#define ETHERTYPE_8021Q 0x8100 +#endif +#ifndef ETHERTYPE_IPX +#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 +#ifndef ETHERTYPE_PPPOES +#define ETHERTYPE_PPPOES 0x8864 +#endif #ifndef ETHERTYPE_LOOPBACK #define ETHERTYPE_LOOPBACK 0x9000 #endif +#ifndef ETHERTYPE_VMAN +#define ETHERTYPE_VMAN 0x9100 /* Extreme VMAN Protocol */ +#endif +#ifndef ETHERTYPE_ISO +#define ETHERTYPE_ISO 0xfefe /* nonstandard - used in Cisco HDLC encapsulation */ +#endif + +extern const struct tok ethertype_values[]; diff --git a/kame/kame/tcpdump/extract.h b/kame/kame/tcpdump/extract.h index fbc8b5fa9d..25980e46a4 100644 --- a/kame/kame/tcpdump/extract.h +++ b/kame/kame/tcpdump/extract.h @@ -18,40 +18,81 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: extract.h,v 1.15 96/11/26 22:03:22 leres Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/extract.h,v 1.19 2002/12/11 07:13:51 guy Exp $ (LBL) */ /* Network to host order macros */ #ifdef LBL_ALIGN +/* + * The processor doesn't natively handle unaligned loads. + */ +#ifdef HAVE___ATTRIBUTE__ +/* + * We have __attribute__; we assume that means we have __attribute__((packed)). + * Declare packed structures containing a u_int16_t and a u_int32_t, + * cast the pointer to point to one of those, and fetch through it; + * the GCC manual doesn't appear to explicitly say that + * __attribute__((packed)) causes the compiler to generate unaligned-safe + * code, but it apppears to do so. + * + * We do this in case the compiler can generate, for this instruction set, + * better code to do an unaligned load and pass stuff to "ntohs()" or + * "ntohl()" than the code to fetch the bytes one at a time and + * assemble them. (That might not be the case on a little-endian platform, + * where "ntohs()" and "ntohl()" might not be done inline.) + */ +typedef struct { + u_int16_t val; +} __attribute__((packed)) unaligned_u_int16_t; + +typedef struct { + u_int32_t val; +} __attribute__((packed)) unaligned_u_int32_t; + #define EXTRACT_16BITS(p) \ - ((u_short)*((u_char *)(p) + 0) << 8 | \ - (u_short)*((u_char *)(p) + 1)) + ((u_int16_t)ntohs(((const unaligned_u_int16_t *)(p))->val)) #define EXTRACT_32BITS(p) \ - ((u_int32_t)*((u_char *)(p) + 0) << 24 | \ - (u_int32_t)*((u_char *)(p) + 1) << 16 | \ - (u_int32_t)*((u_char *)(p) + 2) << 8 | \ - (u_int32_t)*((u_char *)(p) + 3)) -#else + ((u_int32_t)ntohl(((const unaligned_u_int32_t *)(p))->val)) +#else /* HAVE___ATTRIBUTE__ */ +/* + * We don't have __attribute__, so do unaligned loads of big-endian + * quantities the hard way - fetch the bytes one at a time and + * assemble them. + */ +#define EXTRACT_16BITS(p) \ + ((u_int16_t)((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_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))) +#endif /* HAVE___ATTRIBUTE__ */ +#else /* LBL_ALIGN */ +/* + * The processor natively handles unaligned loads, so we can just + * cast the pointer and fetch through it. + */ #define EXTRACT_16BITS(p) \ - ((u_short)ntohs(*(u_short *)(p))) + ((u_int16_t)ntohs(*(const u_int16_t *)(p))) #define EXTRACT_32BITS(p) \ - ((u_int32_t)ntohl(*(u_int32_t *)(p))) -#endif + ((u_int32_t)ntohl(*(const u_int32_t *)(p))) +#endif /* LBL_ALIGN */ #define EXTRACT_24BITS(p) \ - ((u_int32_t)*((u_char *)(p) + 0) << 16 | \ - (u_int32_t)*((u_char *)(p) + 1) << 8 | \ - (u_int32_t)*((u_char *)(p) + 2)) + ((u_int32_t)((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_short)*((u_char *)(p) + 1) << 8 | \ - (u_short)*((u_char *)(p) + 0)) + ((u_int16_t)((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_char *)(p) + 3) << 24 | \ - (u_int32_t)*((u_char *)(p) + 2) << 16 | \ - (u_int32_t)*((u_char *)(p) + 1) << 8 | \ - (u_int32_t)*((u_char *)(p) + 0)) + ((u_int32_t)((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/kame/kame/tcpdump/fddi.h b/kame/kame/tcpdump/fddi.h index 96ff8201be..690af48d87 100644 --- a/kame/kame/tcpdump/fddi.h +++ b/kame/kame/tcpdump/fddi.h @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: fddi.h,v 1.8 96/06/03 03:06:04 leres Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/fddi.h,v 1.11 2002/12/11 07:13:51 guy Exp $ (LBL) */ /* @@ -37,6 +37,13 @@ struct fddi_header { u_char fddi_shost[6]; }; +/* + * Length of an FDDI header; note that some compilers may pad + * "struct fddi_header" to a multiple of 4 bytes, for example, so + * "sizeof (struct fddi_header)" may not give the right + * answer. + */ +#define FDDI_HDRLEN 13 /* Useful values for fddi_fc (frame control) field */ diff --git a/kame/kame/tcpdump/gmpls.c b/kame/kame/tcpdump/gmpls.c new file mode 100644 index 0000000000..325b53a95a --- /dev/null +++ b/kame/kame/tcpdump/gmpls.c @@ -0,0 +1,134 @@ +/* + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code + * distributions retain the above copyright notice and this paragraph + * in its entirety, and (2) distributions including binary code include + * the above copyright notice and this paragraph in its entirety in + * the documentation or other materials provided with the distribution. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND + * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT + * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * Original code by Hannes Gredler (hannes@juniper.net) + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/gmpls.c,v 1.2.2.2 2003/11/16 08:51:05 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "interface.h" + +/* rfc3471 */ +struct tok gmpls_link_prot_values[] = { + { 0x01, "Extra Traffic"}, + { 0x02, "Unprotected"}, + { 0x04, "Shared"}, + { 0x08, "Dedicated 1:1"}, + { 0x10, "Dedicated 1+1"}, + { 0x20, "Enhanced"}, + { 0x40, "Reserved"}, + { 0x80, "Reserved"}, + { 0, NULL } +}; + +/* rfc3471 */ +struct tok gmpls_switch_cap_values[] = { + { 1, "Packet-Switch Capable-1"}, + { 2, "Packet-Switch Capable-2"}, + { 3, "Packet-Switch Capable-3"}, + { 4, "Packet-Switch Capable-4"}, + { 51, "Layer-2 Switch Capable"}, + { 100, "Time-Division-Multiplex"}, + { 150, "Lambda-Switch Capable"}, + { 200, "Fiber-Switch Capable"}, + { 0, NULL } +}; + +/* rfc3471 */ +struct tok gmpls_encoding_values[] = { + { 1, "Packet"}, + { 2, "Ethernet V2/DIX"}, + { 3, "ANSI/ETSI PDH"}, + { 4, "Reserved"}, + { 5, "SDH ITU-T G.707/SONET ANSI T1.105"}, + { 6, "Reserved"}, + { 7, "Digital Wrapper"}, + { 8, "Lambda (photonic)"}, + { 9, "Fiber"}, + { 10, "Reserved"}, + { 11, "FiberChannel"}, + { 0, NULL } +}; + +/* rfc3471 */ +struct tok gmpls_payload_values[] = { + { 0, "Unknown"}, + { 1, "Reserved"}, + { 2, "Reserved"}, + { 3, "Reserved"}, + { 4, "Reserved"}, + { 5, "Asynchronous mapping of E4"}, + { 6, "Asynchronous mapping of DS3/T3"}, + { 7, "Asynchronous mapping of E3"}, + { 8, "Bit synchronous mapping of E3"}, + { 9, "Byte synchronous mapping of E3"}, + { 10, "Asynchronous mapping of DS2/T2"}, + { 11, "Bit synchronous mapping of DS2/T2"}, + { 12, "Reserved"}, + { 13, "Asynchronous mapping of E1"}, + { 14, "Byte synchronous mapping of E1"}, + { 15, "Byte synchronous mapping of 31 * DS0"}, + { 16, "Asynchronous mapping of DS1/T1"}, + { 17, "Bit synchronous mapping of DS1/T1"}, + { 18, "Byte synchronous mapping of DS1/T1"}, + { 19, "VC-11 in VC-12"}, + { 20, "Reserved"}, + { 21, "Reserved"}, + { 22, "DS1 SF Asynchronous"}, + { 23, "DS1 ESF Asynchronous"}, + { 24, "DS3 M23 Asynchronous"}, + { 25, "DS3 C-Bit Parity Asynchronous"}, + { 26, "VT/LOVC"}, + { 27, "STS SPE/HOVC"}, + { 28, "POS - No Scrambling, 16 bit CRC"}, + { 29, "POS - No Scrambling, 32 bit CRC"}, + { 30, "POS - Scrambling, 16 bit CRC"}, + { 31, "POS - Scrambling, 32 bit CRC"}, + { 32, "ATM mapping"}, + { 33, "Ethernet PHY"}, + { 34, "SONET/SDH"}, + { 35, "Reserved (SONET deprecated)"}, + { 36, "Digital Wrapper"}, + { 37, "Lambda"}, + { 38, "ANSI/ETSI PDH"}, + { 39, "Reserved"}, + { 40, "Link Access Protocol SDH (X.85 and X.86)"}, + { 41, "FDDI"}, + { 42, "DQDB (ETSI ETS 300 216)"}, + { 43, "FiberChannel-3 (Services)"}, + { 44, "HDLC"}, + { 45, "Ethernet V2/DIX (only)"}, + { 46, "Ethernet 802.3 (only)"}, +/* draft-ietf-ccamp-gmpls-g709-04.txt */ + { 47, "G.709 ODUj"}, + { 48, "G.709 OTUk(v)"}, + { 49, "CBR/CBRa"}, + { 50, "CBRb"}, + { 51, "BSOT"}, + { 52, "BSNT"}, + { 53, "IP/PPP (GFP)"}, + { 54, "Ethernet MAC (framed GFP)"}, + { 55, "Ethernet PHY (transparent GFP)"}, + { 56, "ESCON"}, + { 57, "FICON"}, + { 58, "Fiber Channel"}, + { 0, NULL } +}; diff --git a/kame/kame/tcpdump/gmpls.h b/kame/kame/tcpdump/gmpls.h new file mode 100644 index 0000000000..f35211fbc8 --- /dev/null +++ b/kame/kame/tcpdump/gmpls.h @@ -0,0 +1,20 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/gmpls.h,v 1.2 2003/06/09 23:28:09 guy Exp $ (LBL) */ +/* + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code + * distributions retain the above copyright notice and this paragraph + * in its entirety, and (2) distributions including binary code include + * the above copyright notice and this paragraph in its entirety in + * the documentation or other materials provided with the distribution. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND + * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT + * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * Original code by Hannes Gredler (hannes@juniper.net) + */ + +extern struct tok gmpls_link_prot_values[]; +extern struct tok gmpls_switch_cap_values[]; +extern struct tok gmpls_encoding_values[]; +extern struct tok gmpls_payload_values[]; diff --git a/kame/kame/tcpdump/gmt2local.c b/kame/kame/tcpdump/gmt2local.c index 5812cfecbb..978e583c62 100644 --- a/kame/kame/tcpdump/gmt2local.c +++ b/kame/kame/tcpdump/gmt2local.c @@ -20,19 +20,18 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: gmt2local.c,v 1.2 97/01/23 22:31:25 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/gmt2local.c,v 1.7.2.2 2003/11/16 08:51:06 guy Exp $ (LBL)"; #endif -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include #include -#ifdef TIME_WITH_SYS_TIME -#include -#endif -#include "gnuc.h" #ifdef HAVE_OS_PROTO_H #include "os-proto.h" #endif diff --git a/kame/kame/tcpdump/gmt2local.h b/kame/kame/tcpdump/gmt2local.h index 4933b09137..81b0e96072 100644 --- a/kame/kame/tcpdump/gmt2local.h +++ b/kame/kame/tcpdump/gmt2local.h @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: gmt2local.h,v 1.2 97/01/23 22:31:40 leres Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/gmt2local.h,v 1.2.1.1 1999/10/07 23:47:10 mcr Exp $ (LBL) */ #ifndef gmt2local_h #define gmt2local_h diff --git a/kame/kame/tcpdump/icmp6.h b/kame/kame/tcpdump/icmp6.h new file mode 100644 index 0000000000..931de2f249 --- /dev/null +++ b/kame/kame/tcpdump/icmp6.h @@ -0,0 +1,451 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/icmp6.h,v 1.14 2002/12/11 07:13:52 guy 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 $ */ + +/* + * 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. + */ + +/* + * 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. + * + * @(#)ip_icmp.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_ICMP6_H_ +#define _NETINET_ICMP6_H_ + +struct icmp6_hdr { + u_int8_t icmp6_type; /* type field */ + u_int8_t icmp6_code; /* code field */ + u_int16_t icmp6_cksum; /* checksum field */ + union { + u_int32_t icmp6_un_data32[1]; /* type-specific field */ + u_int16_t icmp6_un_data16[2]; /* type-specific field */ + u_int8_t icmp6_un_data8[4]; /* type-specific field */ + } icmp6_dataun; +}; + +#define icmp6_data32 icmp6_dataun.icmp6_un_data32 +#define icmp6_data16 icmp6_dataun.icmp6_un_data16 +#define icmp6_data8 icmp6_dataun.icmp6_un_data8 +#define icmp6_pptr icmp6_data32[0] /* parameter prob */ +#define icmp6_mtu icmp6_data32[0] /* packet too big */ +#define icmp6_id icmp6_data16[0] /* echo request/reply */ +#define icmp6_seq icmp6_data16[1] /* echo request/reply */ +#define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */ + +#define ICMP6_DST_UNREACH 1 /* dest unreachable, codes: */ +#define ICMP6_PACKET_TOO_BIG 2 /* packet too big */ +#define ICMP6_TIME_EXCEEDED 3 /* time exceeded, code: */ +#define ICMP6_PARAM_PROB 4 /* ip6 header bad */ + +#define ICMP6_ECHO_REQUEST 128 /* echo service */ +#define ICMP6_ECHO_REPLY 129 /* echo reply */ +#define ICMP6_MEMBERSHIP_QUERY 130 /* group membership query */ +#define MLD6_LISTENER_QUERY 130 /* multicast listener query */ +#define ICMP6_MEMBERSHIP_REPORT 131 /* group membership report */ +#define MLD6_LISTENER_REPORT 131 /* multicast listener report */ +#define ICMP6_MEMBERSHIP_REDUCTION 132 /* group membership termination */ +#define MLD6_LISTENER_DONE 132 /* multicast listener done */ + +#define ND_ROUTER_SOLICIT 133 /* router solicitation */ +#define ND_ROUTER_ADVERT 134 /* router advertisment */ +#define ND_NEIGHBOR_SOLICIT 135 /* neighbor solicitation */ +#define ND_NEIGHBOR_ADVERT 136 /* neighbor advertisment */ +#define ND_REDIRECT 137 /* redirect */ + +#define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */ + +#define ICMP6_WRUREQUEST 139 /* who are you request */ +#define ICMP6_WRUREPLY 140 /* who are you reply */ +#define ICMP6_FQDN_QUERY 139 /* FQDN query */ +#define ICMP6_FQDN_REPLY 140 /* FQDN reply */ +#define ICMP6_NI_QUERY 139 /* node information request */ +#define ICMP6_NI_REPLY 140 /* node information reply */ + +/* The definitions below are experimental. TBA */ +#define MLD6_MTRACE_RESP 141 /* mtrace response(to sender) */ +#define MLD6_MTRACE 142 /* mtrace messages */ + +/* Folloing numbers are defined in the mobile-ip draft. */ +#define ICMP6_HADISCOV_REQUEST 150 /* XXX To be authorized */ +#define ICMP6_HADISCOV_REPLY 151 /* XXX To be authorized */ +#define ICMP6_MOBILEPREFIX_SOLICIT 152 /* XXX To be authorized */ +#define ICMP6_MOBILEPREFIX_ADVERT 153 /* XXX To be authorized */ + +#define ICMP6_MAXTYPE 153 + +#define ICMP6_DST_UNREACH_NOROUTE 0 /* no route to destination */ +#define ICMP6_DST_UNREACH_ADMIN 1 /* administratively prohibited */ +#define ICMP6_DST_UNREACH_NOTNEIGHBOR 2 /* not a neighbor(obsolete) */ +#define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source address */ +#define ICMP6_DST_UNREACH_ADDR 3 /* address unreachable */ +#define ICMP6_DST_UNREACH_NOPORT 4 /* port unreachable */ + +#define ICMP6_TIME_EXCEED_TRANSIT 0 /* ttl==0 in transit */ +#define ICMP6_TIME_EXCEED_REASSEMBLY 1 /* ttl==0 in reass */ + +#define ICMP6_PARAMPROB_HEADER 0 /* erroneous header field */ +#define ICMP6_PARAMPROB_NEXTHEADER 1 /* unrecognized next header */ +#define ICMP6_PARAMPROB_OPTION 2 /* unrecognized option */ + +#define ICMP6_INFOMSG_MASK 0x80 /* all informational messages */ + +#define ICMP6_NI_SUBJ_IPV6 0 /* Query Subject is an IPv6 address */ +#define ICMP6_NI_SUBJ_FQDN 1 /* Query Subject is a Domain name */ +#define ICMP6_NI_SUBJ_IPV4 2 /* Query Subject is an IPv4 address */ + +#define ICMP6_NI_SUCCESS 0 /* node information successful reply */ +#define ICMP6_NI_REFUSED 1 /* node information request is refused */ +#define ICMP6_NI_UNKNOWN 2 /* unknown Qtype */ + +#define ICMP6_ROUTER_RENUMBERING_COMMAND 0 /* rr command */ +#define ICMP6_ROUTER_RENUMBERING_RESULT 1 /* rr result */ +#define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255 /* rr seq num reset */ + +/* Used in kernel only */ +#define ND_REDIRECT_ONLINK 0 /* redirect to an on-link node */ +#define ND_REDIRECT_ROUTER 1 /* redirect to a better router */ + +/* + * Multicast Listener Discovery + */ +struct mld6_hdr { + struct icmp6_hdr mld6_hdr; + struct in6_addr mld6_addr; /* multicast address */ +}; + +#define mld6_type mld6_hdr.icmp6_type +#define mld6_code mld6_hdr.icmp6_code +#define mld6_cksum mld6_hdr.icmp6_cksum +#define mld6_maxdelay mld6_hdr.icmp6_data16[0] +#define mld6_reserved mld6_hdr.icmp6_data16[1] + +/* + * Neighbor Discovery + */ + +struct nd_router_solicit { /* router solicitation */ + struct icmp6_hdr nd_rs_hdr; + /* could be followed by options */ +}; + +#define nd_rs_type nd_rs_hdr.icmp6_type +#define nd_rs_code nd_rs_hdr.icmp6_code +#define nd_rs_cksum nd_rs_hdr.icmp6_cksum +#define nd_rs_reserved nd_rs_hdr.icmp6_data32[0] + +struct nd_router_advert { /* router advertisement */ + struct icmp6_hdr nd_ra_hdr; + u_int32_t nd_ra_reachable; /* reachable time */ + u_int32_t nd_ra_retransmit; /* retransmit timer */ + /* could be followed by options */ +}; + +#define nd_ra_type nd_ra_hdr.icmp6_type +#define nd_ra_code nd_ra_hdr.icmp6_code +#define nd_ra_cksum nd_ra_hdr.icmp6_cksum +#define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0] +#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 */ + struct icmp6_hdr nd_ns_hdr; + struct in6_addr nd_ns_target; /*target address */ + /* could be followed by options */ +}; + +#define nd_ns_type nd_ns_hdr.icmp6_type +#define nd_ns_code nd_ns_hdr.icmp6_code +#define nd_ns_cksum nd_ns_hdr.icmp6_cksum +#define nd_ns_reserved nd_ns_hdr.icmp6_data32[0] + +struct nd_neighbor_advert { /* neighbor advertisement */ + struct icmp6_hdr nd_na_hdr; + struct in6_addr nd_na_target; /* target address */ + /* could be followed by options */ +}; + +#define nd_na_type nd_na_hdr.icmp6_type +#define nd_na_code nd_na_hdr.icmp6_code +#define nd_na_cksum nd_na_hdr.icmp6_cksum +#define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0] +/* netowkr endian */ +#define ND_NA_FLAG_ROUTER ((u_int32_t)htonl(0x80000000)) +#define ND_NA_FLAG_SOLICITED ((u_int32_t)htonl(0x40000000)) +#define ND_NA_FLAG_OVERRIDE ((u_int32_t)htonl(0x20000000)) + +struct nd_redirect { /* redirect */ + struct icmp6_hdr nd_rd_hdr; + struct in6_addr nd_rd_target; /* target address */ + struct in6_addr nd_rd_dst; /* destination address */ + /* could be followed by options */ +}; + +#define nd_rd_type nd_rd_hdr.icmp6_type +#define nd_rd_code nd_rd_hdr.icmp6_code +#define nd_rd_cksum nd_rd_hdr.icmp6_cksum +#define nd_rd_reserved nd_rd_hdr.icmp6_data32[0] + +struct nd_opt_hdr { /* Neighbor discovery option header */ + u_int8_t nd_opt_type; + u_int8_t nd_opt_len; + /* followed by option specific data*/ +}; + +#define ND_OPT_SOURCE_LINKADDR 1 +#define ND_OPT_TARGET_LINKADDR 2 +#define ND_OPT_PREFIX_INFORMATION 3 +#define ND_OPT_REDIRECTED_HEADER 4 +#define ND_OPT_MTU 5 +#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; + u_int8_t nd_opt_pi_len; + u_int8_t nd_opt_pi_prefix_len; + u_int8_t nd_opt_pi_flags_reserved; + u_int32_t nd_opt_pi_valid_time; + u_int32_t nd_opt_pi_preferred_time; + u_int32_t nd_opt_pi_reserved2; + struct in6_addr nd_opt_pi_prefix; +}; + +#define ND_OPT_PI_FLAG_ONLINK 0x80 +#define ND_OPT_PI_FLAG_AUTO 0x40 +#define ND_OPT_PI_FLAG_ROUTER 0x20 /*2292bis*/ + +struct nd_opt_rd_hdr { /* redirected header */ + u_int8_t nd_opt_rh_type; + u_int8_t nd_opt_rh_len; + u_int16_t nd_opt_rh_reserved1; + u_int32_t nd_opt_rh_reserved2; + /* followed by IP header and data */ +}; + +struct nd_opt_mtu { /* MTU option */ + u_int8_t nd_opt_mtu_type; + u_int8_t nd_opt_mtu_len; + u_int16_t nd_opt_mtu_reserved; + u_int32_t nd_opt_mtu_mtu; +}; + +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 */ +}; + +/* + * icmp6 namelookup + */ + +struct icmp6_namelookup { + struct icmp6_hdr icmp6_nl_hdr; + u_int8_t icmp6_nl_nonce[8]; + int32_t icmp6_nl_ttl; +#if 0 + u_int8_t icmp6_nl_len; + u_int8_t icmp6_nl_name[3]; +#endif + /* could be followed by options */ +}; + +/* + * icmp6 node information + */ +struct icmp6_nodeinfo { + struct icmp6_hdr icmp6_ni_hdr; + u_int8_t icmp6_ni_nonce[8]; + /* could be followed by reply data */ +}; + +#define ni_type icmp6_ni_hdr.icmp6_type +#define ni_code icmp6_ni_hdr.icmp6_code +#define ni_cksum icmp6_ni_hdr.icmp6_cksum +#define ni_qtype icmp6_ni_hdr.icmp6_data16[0] +#define ni_flags icmp6_ni_hdr.icmp6_data16[1] + +#define NI_QTYPE_NOOP 0 /* NOOP */ +#define NI_QTYPE_SUPTYPES 1 /* Supported Qtypes */ +#define NI_QTYPE_FQDN 2 /* FQDN (draft 04) */ +#define NI_QTYPE_DNSNAME 2 /* DNS Name */ +#define NI_QTYPE_NODEADDR 3 /* Node Addresses */ +#define NI_QTYPE_IPV4ADDR 4 /* IPv4 Addresses */ + +/* network endian */ +#define NI_SUPTYPE_FLAG_COMPRESS ((u_int16_t)htons(0x1)) +#define NI_FQDN_FLAG_VALIDTTL ((u_int16_t)htons(0x1)) + +/* network endian */ +#define NI_NODEADDR_FLAG_TRUNCATE ((u_int16_t)htons(0x1)) +#define NI_NODEADDR_FLAG_ALL ((u_int16_t)htons(0x2)) +#define NI_NODEADDR_FLAG_COMPAT ((u_int16_t)htons(0x4)) +#define NI_NODEADDR_FLAG_LINKLOCAL ((u_int16_t)htons(0x8)) +#define NI_NODEADDR_FLAG_SITELOCAL ((u_int16_t)htons(0x10)) +#define NI_NODEADDR_FLAG_GLOBAL ((u_int16_t)htons(0x20)) +#define NI_NODEADDR_FLAG_ANYCAST ((u_int16_t)htons(0x40)) /* just experimental. not in spec */ + +struct ni_reply_fqdn { + u_int32_t ni_fqdn_ttl; /* TTL */ + u_int8_t ni_fqdn_namelen; /* length in octets of the FQDN */ + u_int8_t ni_fqdn_name[3]; /* XXX: alignment */ +}; + +/* + * Router Renumbering. as router-renum-08.txt + */ +struct icmp6_router_renum { /* router renumbering header */ + struct icmp6_hdr rr_hdr; + u_int8_t rr_segnum; + u_int8_t rr_flags; + u_int16_t rr_maxdelay; + u_int32_t rr_reserved; +}; +#define ICMP6_RR_FLAGS_TEST 0x80 +#define ICMP6_RR_FLAGS_REQRESULT 0x40 +#define ICMP6_RR_FLAGS_FORCEAPPLY 0x20 +#define ICMP6_RR_FLAGS_SPECSITE 0x10 +#define ICMP6_RR_FLAGS_PREVDONE 0x08 + +#define rr_type rr_hdr.icmp6_type +#define rr_code rr_hdr.icmp6_code +#define rr_cksum rr_hdr.icmp6_cksum +#define rr_seqnum rr_hdr.icmp6_data32[0] + +struct rr_pco_match { /* match prefix part */ + u_int8_t rpm_code; + u_int8_t rpm_len; + u_int8_t rpm_ordinal; + u_int8_t rpm_matchlen; + u_int8_t rpm_minlen; + u_int8_t rpm_maxlen; + u_int16_t rpm_reserved; + struct in6_addr rpm_prefix; +}; + +#define RPM_PCO_ADD 1 +#define RPM_PCO_CHANGE 2 +#define RPM_PCO_SETGLOBAL 3 +#define RPM_PCO_MAX 4 + +struct rr_pco_use { /* use prefix part */ + u_int8_t rpu_uselen; + u_int8_t rpu_keeplen; + u_int8_t rpu_ramask; + u_int8_t rpu_raflags; + u_int32_t rpu_vltime; + u_int32_t rpu_pltime; + u_int32_t rpu_flags; + struct in6_addr rpu_prefix; +}; +#define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x80 +#define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x40 + +/* network endian */ +#define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME ((u_int32_t)htonl(0x80000000)) +#define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME ((u_int32_t)htonl(0x40000000)) + +struct rr_result { /* router renumbering result message */ + u_int16_t rrr_flags; + u_int8_t rrr_ordinal; + u_int8_t rrr_matchedlen; + u_int32_t rrr_ifid; + struct in6_addr rrr_prefix; +}; +/* network endian */ +#define ICMP6_RR_RESULT_FLAGS_OOB ((u_int16_t)htons(0x0002)) +#define ICMP6_RR_RESULT_FLAGS_FORBIDDEN ((u_int16_t)htons(0x0001)) + +#endif /* not _NETINET_ICMP6_H_ */ diff --git a/kame/kame/tcpdump/ieee802_11.h b/kame/kame/tcpdump/ieee802_11.h new file mode 100644 index 0000000000..fa5a555ff7 --- /dev/null +++ b/kame/kame/tcpdump/ieee802_11.h @@ -0,0 +1,285 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/ieee802_11.h,v 1.9 2003/07/22 17:36:57 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. + */ + +/* Lengths of 802.11 header components. */ +#define IEEE802_11_FC_LEN 2 +#define IEEE802_11_DUR_LEN 2 +#define IEEE802_11_DA_LEN 6 +#define IEEE802_11_SA_LEN 6 +#define IEEE802_11_BSSID_LEN 6 +#define IEEE802_11_RA_LEN 6 +#define IEEE802_11_TA_LEN 6 +#define IEEE802_11_SEQ_LEN 2 +#define IEEE802_11_IV_LEN 3 +#define IEEE802_11_KID_LEN 1 + +/* Frame check sequence length. */ +#define IEEE802_11_FCS_LEN 4 + +/* Lengths of beacon components. */ +#define IEEE802_11_TSTAMP_LEN 8 +#define IEEE802_11_BCNINT_LEN 2 +#define IEEE802_11_CAPINFO_LEN 2 +#define IEEE802_11_LISTENINT_LEN 2 + +#define IEEE802_11_AID_LEN 2 +#define IEEE802_11_STATUS_LEN 2 +#define IEEE802_11_REASON_LEN 2 + +/* Length of previous AP in reassocation frame */ +#define IEEE802_11_AP_LEN 6 + +#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 + +#define DATA_DATA 0x0 +#define DATA_DATA_CF_ACK 0x1 +#define DATA_DATA_CF_POLL 0x2 +#define DATA_DATA_CF_ACK_POLL 0x3 +#define DATA_NODATA 0x4 +#define DATA_NODATA_CF_ACK 0x5 +#define DATA_NODATA_CF_POLL 0x6 +#define DATA_NODATA_CF_ACK_POLL 0x7 + +/* + * 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_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\ + IEEE802_11_DA_LEN+IEEE802_11_SA_LEN+\ + IEEE802_11_BSSID_LEN+IEEE802_11_SEQ_LEN) + +#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_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\ + IEEE802_11_RA_LEN+IEEE802_11_TA_LEN) + +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_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN) + +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_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN) + +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_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_AID_LEN+\ + IEEE802_11_BSSID_LEN+IEEE802_11_TA_LEN) + +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_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\ + IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN) + +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_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\ + IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN) + +#define IV_IV(iv) ((iv) & 0xFFFFFF) +#define IV_PAD(iv) (((iv) >> 24) & 0x3F) +#define IV_KEYID(iv) (((iv) >> 30) & 0x03) diff --git a/kame/kame/tcpdump/igrp.h b/kame/kame/tcpdump/igrp.h index cc6088a821..78876d3d84 100644 --- a/kame/kame/tcpdump/igrp.h +++ b/kame/kame/tcpdump/igrp.h @@ -1,21 +1,18 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/igrp.h,v 1.6 2002/12/11 07:13:52 guy Exp $ (LBL) */ /* Cisco IGRP definitions */ /* IGRP Header */ struct igrphdr { -#ifdef WORDS_BIGENDIAN - u_char ig_v:4; /* protocol version number */ - u_char ig_op:4; /* opcode */ -#else - u_char ig_op:4; /* opcode */ - u_char ig_v:4; /* protocol version number */ -#endif - u_char ig_ed; /* edition number */ - u_short ig_as; /* autonomous system number */ - u_short ig_ni; /* number of subnet in local net */ - u_short ig_ns; /* number of networks in AS */ - u_short ig_nx; /* number of networks ouside AS */ - u_short ig_sum; /* checksum of IGRP header & data */ + u_int8_t ig_vop; /* protocol version number / opcode */ +#define IGRP_V(x) (((x) & 0xf0) >> 4) +#define IGRP_OP(x) ((x) & 0x0f) + u_int8_t ig_ed; /* edition number */ + u_int16_t ig_as; /* autonomous system number */ + u_int16_t ig_ni; /* number of subnet in local net */ + u_int16_t ig_ns; /* number of networks in AS */ + u_int16_t ig_nx; /* number of networks ouside AS */ + u_int16_t ig_sum; /* checksum of IGRP header & data */ }; #define IGRP_UPDATE 1 @@ -24,13 +21,13 @@ struct igrphdr { /* IGRP routing entry */ struct igrprte { - u_char igr_net[3]; /* 3 significant octets of IP address */ - u_char igr_dly[3]; /* delay in tens of microseconds */ - u_char igr_bw[3]; /* bandwidth in units of 1 kb/s */ - u_char igr_mtu[2]; /* MTU in octets */ - u_char igr_rel; /* percent packets successfully tx/rx */ - u_char igr_ld; /* percent of channel occupied */ - u_char igr_hct; /* hop count */ + u_int8_t igr_net[3]; /* 3 significant octets of IP address */ + u_int8_t igr_dly[3]; /* delay in tens of microseconds */ + u_int8_t igr_bw[3]; /* bandwidth in units of 1 kb/s */ + u_int8_t igr_mtu[2]; /* MTU in octets */ + u_int8_t igr_rel; /* percent packets successfully tx/rx */ + u_int8_t igr_ld; /* percent of channel occupied */ + u_int8_t igr_hct; /* hop count */ }; #define IGRP_RTE_SIZE 14 /* don't believe sizeof ! */ diff --git a/kame/kame/tcpdump/interface.h b/kame/kame/tcpdump/interface.h index 0101a3891c..df84eec150 100644 --- a/kame/kame/tcpdump/interface.h +++ b/kame/kame/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,20 +18,52 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: interface.h,v 1.105 97/04/26 13:39:58 leres Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.217.2.5 2004/03/17 19:47:48 guy Exp $ (LBL) */ #ifndef tcpdump_interface_h #define tcpdump_interface_h -#include "gnuc.h" #ifdef HAVE_OS_PROTO_H #include "os-proto.h" #endif +#ifndef HAVE___ATTRIBUTE__ +#define __attribute__(x) +#endif + +/* snprintf et al */ + +#include + +#if !defined(HAVE_SNPRINTF) +int snprintf(char *, size_t, const char *, ...) + __attribute__((format(printf, 3, 4))); +#endif + +#if !defined(HAVE_VSNPRINTF) +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); +#endif +#ifndef HAVE_STRLCPY +extern size_t strlcpy(char *, const char *, size_t); +#endif + +#ifndef HAVE_STRDUP +extern char *strdup(const char *); +#endif + +#ifndef HAVE_STRSEP +extern char *strsep(char **, const char *); +#endif + struct tok { int v; /* value */ - char *s; /* string */ + const char *s; /* string */ }; extern int aflag; /* translate network and broadcast addresses */ @@ -42,13 +74,15 @@ extern int nflag; /* leave addresses as numbers */ extern int Nflag; /* remove domains from printed host names */ extern int qflag; /* quick (shorter) output */ extern int Rflag; /* print sequence # field in AH/ESP*/ +extern int sflag; /* use the libsmi to translate OIDs */ extern int Sflag; /* print raw TCP sequence numbers */ extern int tflag; /* print packet arrival time */ +extern int uflag; /* Print undecoded NFS handles */ extern int vflag; /* verbose */ extern int xflag; /* print packet in hex */ - -extern char *ahsecret; /* AH secret key */ -extern char *espsecret; /* ESP secret key */ +extern int Xflag; /* print packet in hex/ascii */ +extern int Aflag; /* print packet only in ascii observing TAB, LF, CR and SPACE as graphical chars */ +extern char *espsecret; extern int packettype; /* as specified by -T */ #define PT_VAT 1 /* Visual Audio Tool */ @@ -56,6 +90,10 @@ extern int packettype; /* as specified by -T */ #define PT_RPC 3 /* Remote Procedure Call */ #define PT_RTP 4 /* Real-Time Applications protocol */ #define PT_RTCP 5 /* Real-Time Applications control protocol */ +#define PT_SNMP 6 /* Simple Network Management Protocol */ +#define PT_CNFP 7 /* Cisco NetFlow protocol */ +#define PT_TFTP 8 /* trivial file transfer protocol */ +#define PT_AODV 9 /* Ad-hoc On-demand Distance Vector Protocol */ #ifndef min #define min(a,b) ((a)>(b)?(b):(a)) @@ -64,16 +102,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 @@ -81,30 +117,8 @@ extern int packettype; /* as specified by -T */ #define LITTLE_ENDIAN 1234 #endif -#ifdef ETHER_HEADER_HAS_EA -#define ESRC(ep) ((ep)->ether_shost.ether_addr_octet) -#define EDST(ep) ((ep)->ether_dhost.ether_addr_octet) -#else #define ESRC(ep) ((ep)->ether_shost) #define EDST(ep) ((ep)->ether_dhost) -#endif - -#ifdef ETHER_ARP_HAS_X -#define SHA(ap) ((ap)->arp_xsha) -#define THA(ap) ((ap)->arp_xtha) -#define SPA(ap) ((ap)->arp_xspa) -#define TPA(ap) ((ap)->arp_xtpa) -#else -#ifdef ETHER_ARP_HAS_EA -#define SHA(ap) ((ap)->arp_sha.ether_addr_octet) -#define THA(ap) ((ap)->arp_tha.ether_addr_octet) -#else -#define SHA(ap) ((ap)->arp_sha) -#define THA(ap) ((ap)->arp_tha) -#endif -#define SPA(ap) ((ap)->arp_spa) -#define TPA(ap) ((ap)->arp_tpa) -#endif #ifndef NTOHL #define NTOHL(x) (x) = ntohl(x) @@ -119,12 +133,19 @@ extern char *program_name; /* used to generate self-identifying messages */ extern int32_t thiszone; /* seconds offset from gmt to local time */ extern int snaplen; -/* global pointers to beginning and end of current packet (during printing) */ -extern const u_char *packetp; +/* global pointer to end of current packet (during printing) */ extern const u_char *snapend; -/* True if "l" bytes of "var" were captured */ -#define TTEST2(var, l) ((u_char *)&(var) <= snapend - (l)) +/* + * True if "l" bytes of "var" were captured. + * + * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large + * that "snapend - (l)" underflows. + * + * The check is for <= rather than < because "l" might be 0. + */ +#define TTEST2(var, l) (snapend - (l) <= snapend && \ + (const u_char *)&(var) <= snapend - (l)) /* True if "var" was captured */ #define TTEST(var) TTEST2(var, sizeof(var)) @@ -135,102 +156,175 @@ extern const u_char *snapend; /* Bail if "var" was not captured */ #define TCHECK(var) TCHECK2(var, sizeof(var)) -#ifdef __STDC__ -struct timeval; -#endif - 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 int mask2plen(u_int32_t); +extern char *bittok2str(const struct tok *, const char *, int); +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 void wrapup(int); +extern const char *dnaddr_string(u_short); -#if __STDC__ -extern __dead void error(const char *, ...) - __attribute__((volatile, format (printf, 1, 2))); +extern void error(const char *, ...) + __attribute__((noreturn, format (printf, 1, 2))); extern void warning(const char *, ...) __attribute__ ((format (printf, 1, 2))); -#endif extern char *read_infile(char *); extern char *copy_argv(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 void safeputchar(int); +extern void safeputs(const char *); + +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. */ -#ifdef __STDC__ -struct pcap_pkthdr; -#endif +#include -extern int ether_encap_print(u_short, const u_char *, u_int, u_int); +extern int print_unknown_data(const u_char *, const char *,int); +extern void ascii_print_with_offset(const u_char *, const u_char *, u_int, u_int); +extern void ascii_print(const u_char *, const u_char *, u_int); +extern void hex_print_with_offset(const u_char *, const u_char *, u_int, u_int); +extern void telnet_print(const u_char *, u_int); +extern void hex_print(const u_char *, const u_char *, u_int); +extern int ether_encap_print(u_short, const u_char *, u_int, u_int, u_short *); extern int llc_print(const u_char *, u_int, u_int, const u_char *, - const u_char *); + const u_char *, u_short *); +extern int snap_print(const u_char *, u_int, u_int, u_short *, u_int32_t, + u_short, u_int); extern void aarp_print(const u_char *, u_int); +extern void aodv_print(const u_char *, u_int, int); extern void arp_print(const u_char *, u_int, u_int); 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 atm_print(u_int, u_int, u_int, const u_char *, u_int, u_int); +extern u_int atm_if_print(const struct pcap_pkthdr *, const u_char *); +extern u_int sunatm_if_print(const struct pcap_pkthdr *, const u_char *); +extern void bootp_print(const u_char *, u_int); +extern void bgp_print(const u_char *, int); +extern void beep_print(const u_char *, u_int); +extern void cnfp_print(const u_char *, 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 ether_if_print(u_char *, const struct pcap_pkthdr *, +extern void egp_print(const u_char *); +extern u_int enc_if_print(const struct pcap_pkthdr *, const u_char *); +extern u_int pflog_if_print(const struct pcap_pkthdr *, const u_char *); +extern u_int arcnet_if_print(const struct pcap_pkthdr *, const u_char *); +extern u_int arcnet_linux_if_print(const struct pcap_pkthdr *, const u_char *); +extern void ether_print(const u_char *, u_int, u_int); +extern u_int ether_if_print(const struct pcap_pkthdr *, const u_char *); +extern u_int token_print(const u_char *, u_int, u_int); +extern u_int token_if_print(const struct pcap_pkthdr *, const u_char *); +extern void fddi_print(const u_char *, u_int, u_int); +extern u_int fddi_if_print(const struct pcap_pkthdr *, const u_char *); +extern u_int fr_if_print(const struct pcap_pkthdr *, const u_char *); +extern u_int ieee802_11_if_print(const struct pcap_pkthdr *, const u_char *); +extern u_int ieee802_11_radio_if_print(const struct pcap_pkthdr *, const u_char *); -extern void fddi_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); +extern u_int ap1394_if_print(const struct pcap_pkthdr *, const u_char *); extern void gre_print(const u_char *, u_int); -extern void icmp_print(const u_char *, const u_char *); +extern void icmp_print(const u_char *, u_int, const u_char *, int); +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); +extern u_int ipfc_if_print(const struct pcap_pkthdr *, const u_char *); extern void ipx_print(const u_char *, u_int); -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 isoclns_print(const u_char *, u_int, u_int); +extern void krb_print(const u_char *); +extern u_int llap_print(const u_char *, u_int); +extern u_int ltalk_if_print(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); +extern void ns_print(const u_char *, u_int, int); extern void ntp_print(const u_char *, u_int); -extern void null_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); +extern u_int null_if_print(const struct pcap_pkthdr *, const u_char *); extern void ospf_print(const u_char *, u_int, const u_char *); -extern void igmp_pim_print(const u_char *, u_int); +extern void pimv1_print(const u_char *, u_int); +extern void cisco_autorp_print(const u_char *, u_int); +extern void rsvp_print(const u_char *, u_int); +extern void ldp_print(const u_char *, u_int); extern void mobile_print(const u_char *, u_int); extern void pim_print(const u_char *, u_int); -extern void ppp_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 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 u_int pppoe_print(const u_char *, u_int); +extern u_int ppp_print(register const u_char *, u_int); +extern u_int ppp_if_print(const struct pcap_pkthdr *, const u_char *); +extern u_int ppp_hdlc_if_print(const struct pcap_pkthdr *, const u_char *); +extern u_int ppp_bsdos_if_print(const struct pcap_pkthdr *, const u_char *); +extern u_int pppoe_if_print(const struct pcap_pkthdr *, const u_char *); +extern u_int prism_if_print(const struct pcap_pkthdr *, const u_char *); +extern int vjc_print(register const char *, u_short); +extern u_int raw_if_print(const struct pcap_pkthdr *, const u_char *); extern void rip_print(const u_char *, u_int); -extern void sl_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); -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 u_int sl_if_print(const struct pcap_pkthdr *, const u_char *); +extern void lane_print(const u_char *, u_int, u_int); +extern u_int lane_if_print(const struct pcap_pkthdr *, const u_char *); +extern u_int cip_if_print(const struct pcap_pkthdr *, const u_char *); +extern u_int sl_bsdos_if_print(const struct pcap_pkthdr *, const u_char *); +extern u_int chdlc_if_print(const struct pcap_pkthdr *, const u_char *); +extern u_int sll_if_print(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 *); -extern void tcp_print(const u_char *, u_int, const u_char *); +extern void tcp_print(const u_char *, u_int, const u_char *, int); extern void tftp_print(const u_char *, u_int); -extern void udp_print(const u_char *, u_int, const u_char *); +extern void timed_print(const u_char *); +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 ah_print(register const u_char *); +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 int ipcomp_print(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 *, 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 *, 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 vrrp_print(const u_char *, u_int, int); +extern void cdp_print(const u_char *, u_int, u_int); +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 *); +extern void sctp_print(const u_char *, const u_char *, u_int); +extern void mpls_print(const u_char *, u_int); +extern void mpls_lsp_ping_print(const u_char *, u_int); +extern void zephyr_print(const u_char *, int); +extern void hsrp_print(const u_char *, u_int); +extern void bfd_print(const u_char *, u_int, 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 void 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 int frag6_print(const u_char *, const u_char *); +extern int mobility_print(const u_char *, const u_char *); +extern void icmp6_print(const u_char *, u_int, 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); #endif /*INET6*/ +extern u_short in_cksum(const u_short *, register u_int, int); +extern u_int16_t in_cksum_shouldbe(u_int16_t, u_int16_t); + +#ifndef HAVE_BPF_DUMP +struct bpf_program; + +extern void bpf_dump(struct bpf_program *, int); +#endif diff --git a/kame/kame/tcpdump/ip.h b/kame/kame/tcpdump/ip.h new file mode 100644 index 0000000000..37ef7742a9 --- /dev/null +++ b/kame/kame/tcpdump/ip.h @@ -0,0 +1,162 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/ip.h,v 1.10 2002/12/11 07:13:53 guy Exp $ (LBL) */ +/* + * 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. + * + * @(#)ip.h 8.2 (Berkeley) 6/1/94 + */ + +/* + * Definitions for internet protocol version 4. + * Per RFC 791, September 1981. + */ +#define IPVERSION 4 + +/* + * Structure of an internet header, naked of options. + * + * We declare ip_len and ip_off to be short, rather than u_short + * pragmatically since otherwise unsigned comparisons can result + * against negative integers quite easily, and fail in subtle ways. + */ +struct ip { + u_int8_t ip_vhl; /* header length, version */ +#define IP_V(ip) (((ip)->ip_vhl & 0xf0) >> 4) +#define IP_HL(ip) ((ip)->ip_vhl & 0x0f) + u_int8_t ip_tos; /* type of service */ + u_int16_t ip_len; /* total length */ + u_int16_t ip_id; /* identification */ + u_int16_t ip_off; /* fragment offset field */ +#define IP_DF 0x4000 /* dont fragment flag */ +#define IP_MF 0x2000 /* more fragments flag */ +#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ + u_int8_t ip_ttl; /* time to live */ + u_int8_t ip_p; /* protocol */ + u_int16_t ip_sum; /* checksum */ + struct in_addr ip_src,ip_dst; /* source and dest address */ +}; + +#define IP_MAXPACKET 65535 /* maximum packet size */ + +/* + * Definitions for IP type of service (ip_tos) + */ +#define IPTOS_LOWDELAY 0x10 +#define IPTOS_THROUGHPUT 0x08 +#define IPTOS_RELIABILITY 0x04 + +/* + * Definitions for IP precedence (also in ip_tos) (hopefully unused) + */ +#define IPTOS_PREC_NETCONTROL 0xe0 +#define IPTOS_PREC_INTERNETCONTROL 0xc0 +#define IPTOS_PREC_CRITIC_ECP 0xa0 +#define IPTOS_PREC_FLASHOVERRIDE 0x80 +#define IPTOS_PREC_FLASH 0x60 +#define IPTOS_PREC_IMMEDIATE 0x40 +#define IPTOS_PREC_PRIORITY 0x20 +#define IPTOS_PREC_ROUTINE 0x00 + +/* + * Definitions for options. + */ +#define IPOPT_COPIED(o) ((o)&0x80) +#define IPOPT_CLASS(o) ((o)&0x60) +#define IPOPT_NUMBER(o) ((o)&0x1f) + +#define IPOPT_CONTROL 0x00 +#define IPOPT_RESERVED1 0x20 +#define IPOPT_DEBMEAS 0x40 +#define IPOPT_RESERVED2 0x60 + +#define IPOPT_EOL 0 /* end of option list */ +#define IPOPT_NOP 1 /* no operation */ + +#define IPOPT_RR 7 /* record packet route */ +#define IPOPT_TS 68 /* timestamp */ +#define IPOPT_SECURITY 130 /* provide s,c,h,tcc */ +#define IPOPT_LSRR 131 /* loose source route */ +#define IPOPT_SATID 136 /* satnet id */ +#define IPOPT_SSRR 137 /* strict source route */ + +/* + * Offsets to fields in options other than EOL and NOP. + */ +#define IPOPT_OPTVAL 0 /* option ID */ +#define IPOPT_OLEN 1 /* option length */ +#define IPOPT_OFFSET 2 /* offset within option */ +#define IPOPT_MINOFF 4 /* min value of above */ + +/* + * Time stamp option structure. + */ +struct ip_timestamp { + u_int8_t ipt_code; /* IPOPT_TS */ + u_int8_t ipt_len; /* size of structure (variable) */ + u_int8_t ipt_ptr; /* index of current entry */ + u_int8_t ipt_oflwflg; /* flags, overflow counter */ +#define IPTS_OFLW(ip) (((ipt)->ipt_oflwflg & 0xf0) >> 4) +#define IPTS_FLG(ip) ((ipt)->ipt_oflwflg & 0x0f) + union ipt_timestamp { + u_int32_t ipt_time[1]; + struct ipt_ta { + struct in_addr ipt_addr; + u_int32_t ipt_time; + } ipt_ta[1]; + } ipt_timestamp; +}; + +/* flag bits for ipt_flg */ +#define IPOPT_TS_TSONLY 0 /* timestamps only */ +#define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ +#define IPOPT_TS_PRESPEC 3 /* specified modules only */ + +/* bits for security (not byte swapped) */ +#define IPOPT_SECUR_UNCLASS 0x0000 +#define IPOPT_SECUR_CONFID 0xf135 +#define IPOPT_SECUR_EFTO 0x789a +#define IPOPT_SECUR_MMMM 0xbc4d +#define IPOPT_SECUR_RESTR 0xaf13 +#define IPOPT_SECUR_SECRET 0xd788 +#define IPOPT_SECUR_TOPSECRET 0x6bc5 + +/* + * Internet implementation parameters. + */ +#define MAXTTL 255 /* maximum time to live (seconds) */ +#define IPDEFTTL 64 /* default ttl, from RFC 1340 */ +#define IPFRAGTTL 60 /* time to live for frags, slowhz */ +#define IPTTLDEC 1 /* subtracted when forwarding */ + +#define IP_MSS 576 /* default maximum segment size */ + +/* in print-ip.c */ +extern u_int32_t ip_finddst(const struct ip *); diff --git a/kame/kame/tcpdump/ip6.h b/kame/kame/tcpdump/ip6.h new file mode 100644 index 0000000000..c858a48a69 --- /dev/null +++ b/kame/kame/tcpdump/ip6.h @@ -0,0 +1,194 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/ip6.h,v 1.6 2002/12/11 22:29:21 guy Exp $ (LBL) */ +/* $NetBSD: ip6.h,v 1.9 2000/07/13 05:34:21 itojun Exp $ */ +/* $KAME: ip6.h,v 1.9 2000/07/02 21:01:32 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. + */ + +/* + * 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. + * + * @(#)ip.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_IP6_H_ +#define _NETINET_IP6_H_ + +/* + * Definition for internet protocol version 6. + * RFC 2460 + */ + +struct ip6_hdr { + union { + struct ip6_hdrctl { + u_int32_t ip6_un1_flow; /* 20 bits of flow-ID */ + u_int16_t ip6_un1_plen; /* payload length */ + u_int8_t ip6_un1_nxt; /* next header */ + u_int8_t ip6_un1_hlim; /* hop limit */ + } ip6_un1; + u_int8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */ + } ip6_ctlun; + struct in6_addr ip6_src; /* source address */ + struct in6_addr ip6_dst; /* destination address */ +}; + +#define ip6_vfc ip6_ctlun.ip6_un2_vfc +#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow +#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen +#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt +#define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim +#define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim + +#define IPV6_VERSION 0x60 +#define IPV6_VERSION_MASK 0xf0 + +/* in network endian */ +#define IPV6_FLOWINFO_MASK ((u_int32_t)htonl(0x0fffffff)) /* flow info (28 bits) */ +#define IPV6_FLOWLABEL_MASK ((u_int32_t)htonl(0x000fffff)) /* flow label (20 bits) */ +#if 1 +/* ECN bits proposed by Sally Floyd */ +#define IP6TOS_CE 0x01 /* congestion experienced */ +#define IP6TOS_ECT 0x02 /* ECN-capable transport */ +#endif + +/* + * Extension Headers + */ + +struct ip6_ext { + u_char ip6e_nxt; + u_char ip6e_len; +}; + +/* Hop-by-Hop options header */ +/* XXX should we pad it to force alignment on an 8-byte boundary? */ +struct ip6_hbh { + u_int8_t ip6h_nxt; /* next header */ + u_int8_t ip6h_len; /* length in units of 8 octets */ + /* followed by options */ +}; + +/* Destination options header */ +/* XXX should we pad it to force alignment on an 8-byte boundary? */ +struct ip6_dest { + u_int8_t ip6d_nxt; /* next header */ + u_int8_t ip6d_len; /* length in units of 8 octets */ + /* followed by options */ +}; + +/* Option types and related macros */ +#define IP6OPT_PAD1 0x00 /* 00 0 00000 */ +#define IP6OPT_PADN 0x01 /* 00 0 00001 */ +#define IP6OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */ +#define IP6OPT_JUMBO_LEN 6 +#define IP6OPT_ROUTER_ALERT 0x05 /* 00 0 00101 */ + +#define IP6OPT_RTALERT_LEN 4 +#define IP6OPT_RTALERT_MLD 0 /* Datagram contains an MLD message */ +#define IP6OPT_RTALERT_RSVP 1 /* Datagram contains an RSVP message */ +#define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */ +#define IP6OPT_MINLEN 2 + +#define IP6OPT_BINDING_UPDATE 0xc6 /* 11 0 00110 */ +#define IP6OPT_BINDING_ACK 0x07 /* 00 0 00111 */ +#define IP6OPT_BINDING_REQ 0x08 /* 00 0 01000 */ +#define IP6OPT_HOME_ADDRESS 0xc9 /* 11 0 01001 */ +#define IP6OPT_EID 0x8a /* 10 0 01010 */ + +#define IP6OPT_TYPE(o) ((o) & 0xC0) +#define IP6OPT_TYPE_SKIP 0x00 +#define IP6OPT_TYPE_DISCARD 0x40 +#define IP6OPT_TYPE_FORCEICMP 0x80 +#define IP6OPT_TYPE_ICMP 0xC0 + +#define IP6OPT_MUTABLE 0x20 + +/* Routing header */ +struct ip6_rthdr { + u_int8_t ip6r_nxt; /* next header */ + u_int8_t ip6r_len; /* length in units of 8 octets */ + u_int8_t ip6r_type; /* routing type */ + u_int8_t ip6r_segleft; /* segments left */ + /* followed by routing type specific data */ +}; + +/* Type 0 Routing header */ +struct ip6_rthdr0 { + u_int8_t ip6r0_nxt; /* next header */ + u_int8_t ip6r0_len; /* length in units of 8 octets */ + u_int8_t ip6r0_type; /* always zero */ + u_int8_t ip6r0_segleft; /* segments left */ + u_int8_t ip6r0_reserved; /* reserved field */ + u_int8_t ip6r0_slmap[3]; /* strict/loose bit map */ + struct in6_addr ip6r0_addr[1]; /* up to 23 addresses */ +}; + +/* Fragment header */ +struct ip6_frag { + u_int8_t ip6f_nxt; /* next header */ + u_int8_t ip6f_reserved; /* reserved field */ + u_int16_t ip6f_offlg; /* offset, reserved, and flag */ + u_int32_t ip6f_ident; /* identification */ +}; + +#define IP6F_OFF_MASK 0xfff8 /* mask out offset from ip6f_offlg */ +#define IP6F_RESERVED_MASK 0x0006 /* reserved bits in ip6f_offlg */ +#define IP6F_MORE_FRAG 0x0001 /* more-fragments flag */ + +#endif /* not _NETINET_IP6_H_ */ diff --git a/kame/kame/tcpdump/ipfc.h b/kame/kame/tcpdump/ipfc.h new file mode 100644 index 0000000000..f822d4af2e --- /dev/null +++ b/kame/kame/tcpdump/ipfc.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 1992, 1993, 1994, 1995, 1996 + * 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. + * + * @(#) $Header: /tcpdump/master/tcpdump/ipfc.h,v 1.4 2002/12/11 07:13:53 guy Exp $ (LBL) + */ + +struct ipfc_header { + u_char ipfc_dhost[8]; + u_char ipfc_shost[8]; +}; + +#define IPFC_HDRLEN 16 diff --git a/kame/kame/tcpdump/ipproto.h b/kame/kame/tcpdump/ipproto.h new file mode 100644 index 0000000000..dcfdd3ac25 --- /dev/null +++ b/kame/kame/tcpdump/ipproto.h @@ -0,0 +1,136 @@ +/* + * Copyright (c) 1982, 1986, 1990, 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. + * + * @(#) $Header: /tcpdump/master/tcpdump/ipproto.h,v 1.1.2.1 2003/11/24 20:31:22 guy Exp $ (LBL) + * + * From: + * @(#)in.h 8.3 (Berkeley) 1/3/94 + * $FreeBSD: src/sys/netinet/in.h,v 1.38.2.3 1999/08/29 16:29:34 peter Exp $ + */ + +#ifndef IPPROTO_IP +#define IPPROTO_IP 0 /* dummy for IP */ +#endif +#ifndef IPPROTO_HOPOPTS +#define IPPROTO_HOPOPTS 0 /* IPv6 hop-by-hop options */ +#endif +#ifndef IPPROTO_ICMP +#define IPPROTO_ICMP 1 /* control message protocol */ +#endif +#ifndef IPPROTO_IGMP +#define IPPROTO_IGMP 2 /* group mgmt protocol */ +#endif +#ifndef IPPROTO_IPV4 +#define IPPROTO_IPV4 4 +#endif +#ifndef IPPROTO_TCP +#define IPPROTO_TCP 6 /* tcp */ +#endif +#ifndef IPPROTO_EGP +#define IPPROTO_EGP 8 /* exterior gateway protocol */ +#endif +#ifndef IPPROTO_IGRP +#define IPPROTO_IGRP 9 +#endif +#ifndef IPPROTO_UDP +#define IPPROTO_UDP 17 /* user datagram protocol */ +#endif +#ifndef IPPROTO_IPV6 +#define IPPROTO_IPV6 41 +#endif +#ifndef IPPROTO_ROUTING +#define IPPROTO_ROUTING 43 /* IPv6 routing header */ +#endif +#ifndef IPPROTO_FRAGMENT +#define IPPROTO_FRAGMENT 44 /* IPv6 fragmentation header */ +#endif +#ifndef IPPROTO_RSVP +#define IPPROTO_RSVP 46 /* resource reservation */ +#endif +#ifndef IPPROTO_GRE +#define IPPROTO_GRE 47 /* General Routing Encap. */ +#endif +#ifndef IPPROTO_ESP +#define IPPROTO_ESP 50 /* SIPP Encap Sec. Payload */ +#endif +#ifndef IPPROTO_AH +#define IPPROTO_AH 51 /* SIPP Auth Header */ +#endif +#ifndef IPPROTO_MOBILE +#define IPPROTO_MOBILE 55 +#endif +#ifndef IPPROTO_ICMPV6 +#define IPPROTO_ICMPV6 58 /* ICMPv6 */ +#endif +#ifndef IPPROTO_NONE +#define IPPROTO_NONE 59 /* IPv6 no next header */ +#endif +#ifndef IPPROTO_DSTOPTS +#define IPPROTO_DSTOPTS 60 /* IPv6 destination options */ +#endif +#ifndef IPPROTO_MOBILITY_OLD +/* + * The current Protocol Numbers list says that the IP protocol number for + * mobility headers is 135; it cites draft-ietf-mobileip-ipv6-24, but + * that draft doesn't actually give a number. + * + * It appears that 62 used to be used, even though that's assigned to + * a protocol called CFTP; however, the only reference for CFTP is a + * Network Message from BBN back in 1982, so, for now, we support 62, + * aas well as 135, as a protocol number for mobility headers. + */ +#define IPPROTO_MOBILITY_OLD 62 +#endif +#ifndef IPPROTO_ND +#define IPPROTO_ND 77 /* Sun net disk proto (temp.) */ +#endif +#ifndef IPPROTO_IGRP +#define IPPROTO_IGRP 88 /* Cisco/GXS IGRP */ +#endif +#ifndef IPPROTO_OSPF +#define IPPROTO_OSPF 89 +#endif +#ifndef IPPROTO_PIM +#define IPPROTO_PIM 103 +#endif +#ifndef IPPROTO_IPCOMP +#define IPPROTO_IPCOMP 108 +#endif +#ifndef IPPROTO_VRRP +#define IPPROTO_VRRP 112 +#endif +#ifndef IPPROTO_SCTP +#define IPPROTO_SCTP 132 +#endif +#ifndef IPPROTO_MOBILITY +#define IPPROTO_MOBILITY 135 +#endif diff --git a/kame/kame/tcpdump/ipsec_doi.h b/kame/kame/tcpdump/ipsec_doi.h index 2852c4641a..83d05ea54b 100644 --- a/kame/kame/tcpdump/ipsec_doi.h +++ b/kame/kame/tcpdump/ipsec_doi.h @@ -1,7 +1,7 @@ /* * 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: @@ -13,7 +13,7 @@ * 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 @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -/* YIPS @(#)$Id: ipsec_doi.h,v 1.1.2.1.4.1 1999/02/12 08:10:00 sumikawa Exp $ */ +/* YIPS @(#)$Id: ipsec_doi.h,v 1.7 2002/12/11 07:13:53 guy Exp $ */ /* refer to RFC 2407 */ @@ -51,6 +51,9 @@ #define IPSECDOI_AH_MD5 2 #define IPSECDOI_AH_SHA 3 #define IPSECDOI_AH_DES 4 +#define IPSECDOI_AH_SHA2_256 5 +#define IPSECDOI_AH_SHA2_384 6 +#define IPSECDOI_AH_SHA2_512 7 /* 4.4.1 IPSEC Security Protocol Identifiers */ #define IPSECDOI_PROTO_IPSEC_ESP 3 @@ -66,6 +69,8 @@ #define IPSECDOI_ESP_DES_IV32 9 #define IPSECDOI_ESP_RC4 10 #define IPSECDOI_ESP_NULL 11 +#define IPSECDOI_ESP_RIJNDAEL 12 +#define IPSECDOI_ESP_AES 12 /* 4.4.1 IPSEC Security Protocol Identifiers */ #define IPSECDOI_PROTO_IPCOMP 4 @@ -73,7 +78,6 @@ #define IPSECDOI_IPCOMP_OUI 1 #define IPSECDOI_IPCOMP_DEFLATE 2 #define IPSECDOI_IPCOMP_LZS 3 -#define IPSECDOI_IPCOMP_V42BIS 4 /* 4.5 IPSEC Security Association Attributes */ #define IPSECDOI_ATTR_SA_LTYPE 1 /* B */ @@ -88,16 +92,17 @@ #define IPSECDOI_ATTR_ENC_MODE_TUNNEL 1 #define IPSECDOI_ATTR_ENC_MODE_TRNS 2 #define IPSECDOI_ATTR_AUTH 5 /* B */ + /* 0 means not to use authentication. */ #define IPSECDOI_ATTR_AUTH_HMAC_MD5 1 #define IPSECDOI_ATTR_AUTH_HMAC_SHA1 2 #define IPSECDOI_ATTR_AUTH_DES_MAC 3 -#define IPSECDOI_ATTR_AUTH_KPDK 4 +#define IPSECDOI_ATTR_AUTH_KPDK 4 /*RFC-1826(Key/Pad/Data/Key)*/ /* - When negotiating ESP without authentication, the Auth - Algorithm attribute MUST NOT be included in the proposal. - When negotiating ESP without confidentiality, the Auth - Algorithm attribute MUST be included in the proposal and - the ESP transform ID must be ESP_NULL. + * When negotiating ESP without authentication, the Auth + * Algorithm attribute MUST NOT be included in the proposal. + * When negotiating ESP without confidentiality, the Auth + * Algorithm attribute MUST be included in the proposal and + * the ESP transform ID must be ESP_NULL. */ #define IPSECDOI_ATTR_KEY_LENGTH 6 /* B */ #define IPSECDOI_ATTR_KEY_ROUNDS 7 /* B */ @@ -143,22 +148,4 @@ struct ipsecdoi_id { #define IPSECDOI_NTYPE_REPLAY_STATUS 24577 #define IPSECDOI_NTYPE_INITIAL_CONTACT 24578 -#if 0 -/* ipsec sa structure */ -struct ipsec_sa { - u_int8_t proto_id; /* Protocol id */ - vchar_t *spi; /* spi to receive, network byte order */ - vchar_t *spi_p; /* spi to send, network byte order */ - vchar_t *keymat; /* KEYMAT */ - u_int8_t t_id; /* transform id */ - u_int8_t enc_t; /* type of cipher */ - u_int8_t mode_t; /* tunnel or transport */ - u_int8_t hash_t; /* type of hash */ - u_int8_t life_t; /* type of duration of lifetime */ - u_int32_t ldur; /* life duration */ - u_int8_t dhgrp; /* DH; group */ - struct ipsec_sa *next; -}; -#endif - #endif /* !defined(_IPSEC_DOI_H_) */ diff --git a/kame/kame/tcpdump/ipx.h b/kame/kame/tcpdump/ipx.h index 0a70724170..a8c1cd5115 100644 --- a/kame/kame/tcpdump/ipx.h +++ b/kame/kame/tcpdump/ipx.h @@ -1,7 +1,7 @@ /* - * IPX protocol formats + * IPX protocol formats * - * @(#) $Header: ipx.h,v 1.1 94/06/09 11:47:03 mccanne Exp $ + * @(#) $Header: /tcpdump/master/tcpdump/ipx.h,v 1.8 2002/12/11 07:13:54 guy Exp $ */ /* well-known sockets */ @@ -10,20 +10,22 @@ #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 { - u_short cksum; /* Checksum */ - u_short length; /* Length, in bytes, including header */ - u_char tCtl; /* Transport Control (i.e. hop count) */ - u_char pType; /* Packet Type (i.e. level 2 protocol) */ - u_short dstNet[2]; /* destination net */ - u_char dstNode[6]; /* destination node */ - u_short dstSkt; /* destination socket */ - u_short srcNet[2]; /* source net */ - u_char srcNode[6]; /* source node */ - u_short srcSkt; /* source socket */ -} ipx_hdr_t; + u_int16_t cksum; /* Checksum */ + u_int16_t length; /* Length, in bytes, including header */ + u_int8_t tCtl; /* Transport Control (i.e. hop count) */ + u_int8_t pType; /* Packet Type (i.e. level 2 protocol) */ + u_int16_t dstNet[2]; /* destination net */ + u_int8_t dstNode[6]; /* destination node */ + u_int16_t dstSkt; /* destination socket */ + u_int16_t srcNet[2]; /* source net */ + u_int8_t srcNode[6]; /* source node */ + u_int16_t srcSkt; /* source socket */ +}; #define ipxSize 30 diff --git a/kame/kame/tcpdump/isakmp.h b/kame/kame/tcpdump/isakmp.h index 2976a323df..94fac401d4 100644 --- a/kame/kame/tcpdump/isakmp.h +++ b/kame/kame/tcpdump/isakmp.h @@ -1,7 +1,7 @@ /* * 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: @@ -13,7 +13,7 @@ * 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 @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -/* YIPS @(#)$Id: isakmp.h,v 1.1.2.2.4.1 1999/02/12 08:10:02 sumikawa Exp $ */ +/* YIPS @(#)$Id: isakmp.h,v 1.10 2002/12/11 07:13:54 guy Exp $ */ /* refer to RFC 2408 */ @@ -98,20 +98,18 @@ typedef struct { /* i_cookie + r_cookie */ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ struct isakmp { - cookie_t i_ck; /* Initiator Cookie */ - cookie_t r_ck; /* Responder Cookie */ - u_int8_t np; /* Next Payload Type */ -#if BYTE_ORDER == LITTLE_ENDIAN - u_int8_t v_min:4, /* MnVer */ - v_maj:4; /* MjVer */ -#else - u_int8_t v_maj:4, /* MnVer */ - v_min:4; /* MjVer */ -#endif - u_int8_t etype; /* Exchange Type */ - u_int8_t flags; /* Flags */ - msgid_t msgid; - u_int32_t len; /* Length */ + cookie_t i_ck; /* Initiator Cookie */ + cookie_t r_ck; /* Responder Cookie */ + u_int8_t np; /* Next Payload Type */ + u_int8_t vers; +#define ISAKMP_VERS_MAJOR 0xf0 +#define ISAKMP_VERS_MAJOR_SHIFT 4 +#define ISAKMP_VERS_MINOR 0x0f +#define ISAKMP_VERS_MINOR_SHIFT 0 + u_int8_t etype; /* Exchange Type */ + u_int8_t flags; /* Flags */ + msgid_t msgid; + u_int32_t len; /* Length */ }; /* Next Payload Type */ @@ -371,75 +369,6 @@ struct isakmp_ph2tab { int len; }; -#if 0 -/* isakmp status structure */ -struct isakmp_ph1 { - isakmp_index index; - u_int8_t dir; /* INITIATOR or RESPONDER */ - u_int16_t status; /* status of this SA */ - u_int16_t etype; - u_int32_t doi; - u_int32_t sit; - vchar_t *dhp; /* DH; prime, static value */ - vchar_t *dhpriv; /* DH; private value */ - vchar_t *dhpub; /* DH; public value */ - vchar_t *dhpub_p; /* DH; partner's public value */ - vchar_t *dhgxy; /* DH; shared secret */ - vchar_t *nonce; /* nonce value */ - vchar_t *nonce_p; /* partner's nonce value */ - vchar_t *skeyid; /* SKEYID */ - vchar_t *skeyid_d; /* SKEYID_d */ - vchar_t *skeyid_a; /* SKEYID_a, i.e. hash */ - vchar_t *skeyid_e; /* SKEYID_e, i.e. encryption */ - vchar_t *key; /* cipher key */ - vchar_t *hash; /* HASH minus general header */ - vchar_t *iv; /* IV */ - vchar_t *ive; /* new IV to encrypt next packet */ - vchar_t *ivd; /* new IV to decrypt next packet */ - vchar_t *sa; /* SA minus general header including p,t.*/ - vchar_t *id; /* ID minus general header */ - vchar_t *id_p; /* partner's ID minus general header */ - struct sockaddr *local; /* pointer to the my sockaddr */ - struct sockaddr *remote; /* partner's sockaddr */ - struct oakley_sa *isa; /* Is it good that caddr_t ? */ - struct sched *sc; /* back pointer to the record in schedule - used to resend. */ - struct isakmp_ph1 *next; - struct isakmp_ph1 *prev; - struct isakmp_conf *cfp; /* pointer to isakmp configuration */ - struct isakmp_ph2tab ph2tab; /* list on negotiating Phase 2 */ - u_int32_t msgid2; /* XXX: msgid counter for Phase 2 */ -}; - -struct isakmp_ph2 { - msgid_t msgid; - u_int8_t dir; /* INITIATOR or RESPONDER */ - u_int16_t status; /* status of this SA */ - vchar_t *dhp; /* DH; prime, static value */ - vchar_t *dhpriv; /* DH; private value */ - vchar_t *dhpub; /* DH; public value */ - vchar_t *dhpub_p; /* DH; partner's public value */ - vchar_t *dhgxy; /* DH; shared secret */ - vchar_t *id; /* ID */ - vchar_t *id_p; /* ID for peer */ - vchar_t *nonce; /* nonce value in phase 2 */ - vchar_t *nonce_p; /* partner's nonce value in phase 2 */ - vchar_t *hash; /* HASH2 minus general header */ - vchar_t *iv; /* IV for Phase 2 */ - vchar_t *ive; /* new IV to encrypt next packet */ - vchar_t *ivd; /* new IV to decrypt next packet */ - struct isakmp_ph1 *ph1; /* back pointer to isakmp status */ - struct sched *sc; /* back pointer to the schedule using resend */ - struct pfkey_st *pst; /* pointer to the pfkey status record. - is only used by initiator. */ - u_int8_t proxy; /* is proxy or not ?. */ - vchar_t *sa; /* SA payload */ - struct ipsec_sa *isa; /* values of SA to use, same SA in use. */ - struct isakmp_ph2 *next; - struct isakmp_ph2 *prev; -}; -#endif - #define EXCHANGE_PROXY 1 #define EXCHANGE_MYSELF 0 diff --git a/kame/kame/tcpdump/l2tp.h b/kame/kame/tcpdump/l2tp.h index 008491e711..156888347f 100644 --- a/kame/kame/tcpdump/l2tp.h +++ b/kame/kame/tcpdump/l2tp.h @@ -1,3 +1,4 @@ +/* @(#) $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. @@ -18,7 +19,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * L2TP support contributed by Motonori Shindo (mshindo@ascend.co.jp) + * L2TP support contributed by Motonori Shindo (mshindo@mshindo.net) */ @@ -54,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_int); -}; - -struct l2tp_call_errors { - u_short reserved; - u_int crc_errs; - u_int framing_errs; - u_int hardware_overruns; - u_int buffer_overruns; - u_int timeout_errs; - u_int alignment_errs; -}; - -struct l2tp_accm { - u_short reserved; - u_int send_accm; - u_int recv_accm; -}; - diff --git a/kame/kame/tcpdump/lane.h b/kame/kame/tcpdump/lane.h new file mode 100644 index 0000000000..51b6e19c93 --- /dev/null +++ b/kame/kame/tcpdump/lane.h @@ -0,0 +1,41 @@ +/* + * Marko Kiiskila carnil@cs.tut.fi + * + * Tampere University of Technology - Telecommunications Laboratory + * + * Permission to use, copy, modify and distribute this + * software and its documentation is hereby granted, + * provided that both the copyright notice and this + * permission notice appear in all copies of the software, + * derivative works or modified versions, and any portions + * thereof, that both notices appear in supporting + * documentation, and that the use of this software is + * acknowledged in any publications resulting from using + * the software. + * + * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS + * SOFTWARE. + * + */ + +/* $Id: lane.h,v 1.7 2002/12/11 07:13:54 guy Exp $ */ + +#ifndef ETHER_ADDR_LEN +#define ETHER_ADDR_LEN 6 +#endif + +struct lecdatahdr_8023 { + u_int16_t le_header; + u_int8_t h_dest[ETHER_ADDR_LEN]; + u_int8_t h_source[ETHER_ADDR_LEN]; + u_int16_t h_type; +}; + +struct lane_controlhdr { + u_int16_t lec_header; + u_int8_t lec_proto; + u_int8_t lec_vers; + u_int16_t lec_opcode; +}; diff --git a/kame/kame/tcpdump/lbl/os-osf4.h b/kame/kame/tcpdump/lbl/os-osf4.h new file mode 100644 index 0000000000..62866ede58 --- /dev/null +++ b/kame/kame/tcpdump/lbl/os-osf4.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1993, 1994, 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * 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. + * + * @(#) $Header: /tcpdump/master/tcpdump/lbl/os-osf4.h,v 1.1 2002/12/11 05:03:13 guy Exp $ (LBL) + */ + +/* Prototypes missing in Digital UNIX 4.x */ +int snprintf(char *, size_t, const char *, ...); +int vsnprintf(char *, size_t, const char *, va_list); diff --git a/kame/kame/tcpdump/lbl/os-solaris2.h b/kame/kame/tcpdump/lbl/os-solaris2.h index 7c0e772644..de481c2f7e 100644 --- a/kame/kame/tcpdump/lbl/os-solaris2.h +++ b/kame/kame/tcpdump/lbl/os-solaris2.h @@ -18,37 +18,13 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: os-solaris2.h,v 1.18 97/10/01 01:10:22 leres Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/lbl/os-solaris2.h,v 1.19 2000/10/11 04:02:15 guy Exp $ (LBL) */ /* Prototypes missing in SunOS 5 */ -int daemon(int, int); -int dn_expand(const u_char *, const u_char *, const u_char *, char *, int); -int dn_skipname(const u_char *, const u_char *); -int flock(int, int); -int getdtablesize(void); -int gethostname(char *, int); -int getpagesize(void); -char *getusershell(void); -char *getwd(char *); -int iruserok(u_int, int, char *, char *); -#ifdef __STDC__ -struct utmp; -void login(struct utmp *); -#endif -int logout(const char *); -int res_query(const char *, int, int, u_char *, int); -int setenv(const char *, const char *, int); #if defined(_STDIO_H) && defined(HAVE_SETLINEBUF) int setlinebuf(FILE *); #endif -int sigblock(int); -int sigsetmask(int); char *strerror(int); int snprintf(char *, size_t, const char *, ...); int strcasecmp(const char *, const char *); -void unsetenv(const char *); -#ifdef __STDC__ -struct timeval; -#endif -int utimes(const char *, struct timeval *); diff --git a/kame/kame/tcpdump/lbl/os-sunos4.h b/kame/kame/tcpdump/lbl/os-sunos4.h index 667fdb81b9..2e0f25fc58 100644 --- a/kame/kame/tcpdump/lbl/os-sunos4.h +++ b/kame/kame/tcpdump/lbl/os-sunos4.h @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: os-sunos4.h,v 1.32 96/11/29 15:18:18 leres Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/lbl/os-sunos4.h,v 1.32.1.1 1999/10/07 23:47:13 mcr Exp $ (LBL) */ /* Prototypes missing in SunOS 4 */ diff --git a/kame/kame/tcpdump/lbl/os-ultrix4.h b/kame/kame/tcpdump/lbl/os-ultrix4.h index 1949fa4335..676b3bdd93 100644 --- a/kame/kame/tcpdump/lbl/os-ultrix4.h +++ b/kame/kame/tcpdump/lbl/os-ultrix4.h @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: os-ultrix4.h,v 1.19 96/11/29 15:33:19 leres Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/lbl/os-ultrix4.h,v 1.19.1.1 1999/10/07 23:47:13 mcr Exp $ (LBL) */ /* Prototypes missing in Ultrix 4 */ diff --git a/kame/kame/tcpdump/llc.h b/kame/kame/tcpdump/llc.h index 36185a7ec1..c11432645f 100644 --- a/kame/kame/tcpdump/llc.h +++ b/kame/kame/tcpdump/llc.h @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: llc.h,v 1.6 97/06/13 02:06:07 leres Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/llc.h,v 1.16 2002/12/11 07:13:54 guy Exp $ (LBL) */ /* @@ -32,27 +32,27 @@ */ struct llc { - u_char dsap; - u_char ssap; + u_int8_t dsap; + u_int8_t ssap; union { - u_char u_ctl; - u_short is_ctl; + u_int8_t u_ctl; + u_int16_t is_ctl; struct { - u_char snap_ui; - u_char snap_pi[5]; + u_int8_t snap_ui; + u_int8_t snap_pi[5]; } snap; struct { - u_char snap_ui; - u_char snap_orgcode[3]; - u_char snap_ethertype[2]; + u_int8_t snap_ui; + u_int8_t snap_orgcode[3]; + u_int8_t snap_ethertype[2]; } snap_ether; } ctl; }; #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 @@ -61,7 +61,7 @@ struct llc { #define LLC_S_FMT 1 #define LLC_U_POLL 0x10 -#define LLC_IS_POLL 0x0001 +#define LLC_IS_POLL 0x0100 #define LLC_XID_FI 0x81 #define LLC_U_CMD(u) ((u) & 0xef) @@ -74,13 +74,13 @@ struct llc { #define LLC_XID 0xaf #define LLC_FRMR 0x87 -#define LLC_S_CMD(is) (((is) >> 10) & 0x03) -#define LLC_RR 0x0100 -#define LLC_RNR 0x0500 -#define LLC_REJ 0x0900 +#define LLC_S_CMD(is) (((is) >> 1) & 0x03) +#define LLC_RR 0x0001 +#define LLC_RNR 0x0005 +#define LLC_REJ 0x0009 -#define LLC_IS_NR(is) (((is) >> 1) & 0x7f) -#define LLC_I_NS(is) (((is) >> 9) & 0x7f) +#define LLC_IS_NR(is) (((is) >> 9) & 0x7f) +#define LLC_I_NS(is) (((is) >> 1) & 0x7f) #ifndef LLCSAP_NULL #define LLCSAP_NULL 0x00 @@ -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,39 @@ 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 OUI_CISCO_90 0x0000f8 /* Cisco bridging */ +#define OUI_RFC2684 0x0080c2 /* RFC 2684 bridged Ethernet */ +#define OUI_APPLETALK 0x080007 /* Appletalk */ + +/* + * PIDs for use with OUI_CISCO. + */ +#define PID_CISCO_CDP 0x2000 /* Cisco Discovery Protocol */ + +/* + * PIDs for use with OUI_RFC2684. + */ +#define PID_RFC2684_ETH_FCS 0x0001 /* Ethernet, with FCS */ +#define PID_RFC2684_ETH_NOFCS 0x0007 /* Ethernet, without FCS */ +#define PID_RFC2684_802_4_FCS 0x0002 /* 802.4, with FCS */ +#define PID_RFC2684_802_4_NOFCS 0x0008 /* 802.4, without FCS */ +#define PID_RFC2684_802_5_FCS 0x0003 /* 802.5, with FCS */ +#define PID_RFC2684_802_5_NOFCS 0x0009 /* 802.5, without FCS */ +#define PID_RFC2684_FDDI_FCS 0x0004 /* FDDI, with FCS */ +#define PID_RFC2684_FDDI_NOFCS 0x000a /* FDDI, without FCS */ +#define PID_RFC2684_802_6_FCS 0x0005 /* 802.6, with FCS */ +#define PID_RFC2684_802_6_NOFCS 0x000b /* 802.6, without FCS */ +#define PID_RFC2684_BPDU 0x000e /* BPDUs */ + diff --git a/kame/kame/tcpdump/machdep.c b/kame/kame/tcpdump/machdep.c index 7dd443a828..6c73ee7ccc 100644 --- a/kame/kame/tcpdump/machdep.c +++ b/kame/kame/tcpdump/machdep.c @@ -20,26 +20,46 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: machdep.c,v 1.4 97/09/30 15:03:53 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/machdep.c,v 1.10.2.3 2003/12/15 03:53:42 guy Exp $ (LBL)"; #endif -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* + * XXX - all we need, on platforms other than DEC OSF/1 (a/k/a Digital UNIX, + * a/k/a Tru64 UNIX), is "size_t", which is a standard C type; what do we + * need to do to get it defined? This is clearly wrong, as we shouldn't + * have to include UNIX or Windows system header files to get it. + */ +#include + +#ifndef HAVE___ATTRIBUTE__ +#define __attribute__(x) +#endif /* HAVE___ATTRIBUTE__ */ + #ifdef __osf__ #include #include -#endif + +#if !defined(HAVE_SNPRINTF) +int snprintf(char *, size_t, const char *, ...) + __attribute__((format(printf, 3, 4))); +#endif /* !defined(HAVE_SNPRINTF) */ +#endif /* __osf__ */ #include "machdep.h" int -abort_on_misalignment(char *ebuf) +abort_on_misalignment(char *ebuf _U_, size_t ebufsiz _U_) { #ifdef __osf__ static int buf[2] = { SSIN_UACPROC, UAC_SIGBUS }; if (setsysinfo(SSI_NVPAIRS, (caddr_t)buf, 1, 0, 0) < 0) { - (void)sprintf(ebuf, "setsysinfo: errno %d", errno); + (void)snprintf(ebuf, ebufsiz, "setsysinfo: errno %d", errno); return (-1); } #endif diff --git a/kame/kame/tcpdump/machdep.h b/kame/kame/tcpdump/machdep.h index 87946b6904..8d49a7af71 100644 --- a/kame/kame/tcpdump/machdep.h +++ b/kame/kame/tcpdump/machdep.h @@ -18,10 +18,10 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: machdep.h,v 1.1 96/07/15 18:33:19 leres Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/machdep.h,v 1.2 2000/01/17 06:24:24 itojun Exp $ (LBL) */ #ifndef tcpdump_machdep_h #define tcpdump_machdep_h -int abort_on_misalignment(char *); +int abort_on_misalignment(char *, size_t); #endif diff --git a/kame/kame/tcpdump/makemib b/kame/kame/tcpdump/makemib index 3ab2d7d0d5..2c80bef058 100755 --- a/kame/kame/tcpdump/makemib +++ b/kame/kame/tcpdump/makemib @@ -1,20 +1,33 @@ #!/bin/sh # -# Copyright (c) 1990, 1996, by John Robert LoVerso. -# All rights reserved. +# 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 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. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# @(#) $Id: makemib,v 2.1 90/07/10 23:51:54 loverso Exp Locker: loverso $ (jlv -) +# 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 @@ -42,15 +55,9 @@ cat << EOF EOF -# use sed to make the ASN.1 easier to parse -# I should really just use a recursive descent parser in awk, but... -sed \ - -e 's/--\*.*\*--//' \ - -e 's/--.*//' \ - -e 's/\([{}]\)/ \1 /g' \ - $@ \ -| gawk ' +awk ' BEGIN { + debug=0; # for sanity, we prep the namespace with objects from RFC-1155 # (we manually establish the root) oid["iso"]=1 @@ -59,10 +66,13 @@ BEGIN { oidadd("internet", "dod", 1) oidadd("directory", "internet", 1) oidadd("mgmt", "internet", 2) - oidadd("mib", "mgmt", 1) +#XXX oidadd("mib", "mgmt", 1) + oidadd("mib-2", "mgmt", 1) oidadd("experimental", "internet", 3) oidadd("private", "internet", 4) oidadd("enterprises", "private", 1) + oidadd("ip", "mib-2", 4) + oidadd("transmission", "mib-2", 10) holddesc="none" } @@ -72,30 +82,82 @@ BEGIN { # its simple and straightforward output. It would not be too hard to make # tcpdump directly read mosy output, but... # +# Ignore these unless the current file is called something.defs; false +# positives are too common in DESCRIPTIONs. -NF > 1 && index($2,".")>0 { +NF > 1 && index($2,".")>0 && FILENAME ~ /\.defs/ { # currently ignore items of the form "{ iso.3.6.1 }" - if (split($2, p, ".") == 2) + if (split($2, p, ".") == 2) { oidadd($1, p[1], p[2]) + } next } # -# this next section is simple and naive, but does the job 100% +# Must be a MIB file +# Make it easier to parse - used to be done by sed +{ sub(/--\*.*\*--/, ""); sub(/--.*/, ""); gsub(/[{}]/, " & "); } + +# +# this next section is simple and naive, but does the job ok # +# foo OBJECT IDENTIFIER ::= { baz 17 } +# or +# foo OBJECT IDENTIFIER ::= +# { baz 17 } $2$3$4 == "OBJECTIDENTIFIER::=" { holddesc="none" if (NF == 8) oidadd($1, $6, $7) + if (NF == 4) + holddesc=$1 + next } -$2 == "OBJECT-TYPE" { +$1 == "{" && holddesc != "none" && NF == 4 { + oidadd(holddesc, $2, $3) + holddesc="none" +} +# +# foo OBJECT IDENTIFIER +# ::= { bar 1 } +$2$3 == "OBJECTIDENTIFIER" && $1 != "SYNTAX" && NF == 3 { + holddesc=$1 +} +# +# foo +# OBJECT IDENTIFIER ::= { bar 1 } +# a couple of heuristics to exclude single words in e.g. long +# DESCRIPTION clauses +NF == 1 && $1 ~ "[a-z][a-z]*[A-Z]" && $1 !~ /[(){}.,]/ && holddesc == "none" { + holddesc=$1 +} +$1$2$3 == "OBJECTIDENTIFIER::=" && holddesc != "none" { + oidadd(holddesc, $5, $6) + holddesc="none" +} +# +# "normal" style +# foo OBJECT-TYPE ... +# ... +# ::= { baz 5 } +$2 == "MODULE-IDENTITY" || $2 == "MODULE-COMPLIANCE" || + $2 == "OBJECT-IDENTITY" || $2 == "OBJECT-TYPE" || + $2 == "OBJECT-GROUP" || + $2 == "NOTIFICATION-TYPE" || $2 == "NOTIFICATION-GROUP" { holddesc=$1 } $1 == "::=" && holddesc != "none" && NF == 5 { oidadd(holddesc, $3, $4) holddesc="none" } +# +# foo ::= { baz 17 } +$2$3 == "::={" { + oidadd($1,$4,$5) + holddesc="none" +} + # # End of the road - output the data. @@ -107,6 +169,12 @@ END { print "*mibroot = &_iso_obj;" } +function inn(file) { + if (file == "" || file == "-") + return "" + return " in " file +} + # # add a new object to the tree # @@ -114,28 +182,36 @@ END { # function oidadd(new, parent, value) { + # Ignore 0.0 + if (parent == "0" && value == 0) + return + if (debug) + print "/* oidadd" inn(FILENAME) ":", new, "in", parent, "as", value, "line", $0, "*/" # use safe C identifiers gsub(/[-&\/]/,"",new) gsub(/[-&\/]/,"",parent) # check if parent missing - if (oid[parent] == 0) { - printf "/* parse problem: no parent for %s.%s(%d) */\n", \ - parent, new, value + if (oid[parent] == "") { + printf "/* parse problem%s: no parent for %s.%s(%d) */\n", \ + inn(FILENAME), parent, new, value return } # check if parent.value already exists if (oid[new] > 0 && oid[new] != value) { - printf "/* parse problem: dup %s.%s(%d) != old (%d) */\n", \ - parent, new, value, oid[new] + printf "/* parse problem%s: dup %s.%s(%d) != old (%d) */\n", \ + inn(FILENAME), parent, new, value, oid[new] return } # check for new name for parent.value if (child[parent] != "") { for (sib = child[parent]; sib != ""; sib = sibling[sib]) if (oid[sib] == value) { - printf "/* parse problem: new name \"%s\"" \ - " for %s.%s(%d) ignored */\n", \ - new, parent, sib, value + if (new != sib) + printf "/* parse problem%s: new name" \ + " \"%s\"" \ + " for %s.%s(%d) ignored */\n", \ + inn(FILENAME), new, parent, \ + sib, value return } } @@ -169,5 +245,5 @@ function dump(item, c, s) { printf "_%s_obj = {\n\t\"%s\", %d, 0,\n\t%s, %s\n},\n", \ item, item, oid[item], c, s } -' +' $@ exit 0 diff --git a/kame/kame/tcpdump/mib.h b/kame/kame/tcpdump/mib.h index 48ead9b969..92c6c2c58f 100644 --- a/kame/kame/tcpdump/mib.h +++ b/kame/kame/tcpdump/mib.h @@ -1217,6 +1217,202 @@ _snmp_obj = { "snmp", 11, 0, &_snmpEnableAuthTraps_obj, &_transmission_obj }, +_usmMIBCompliances_obj = { + "usmMIBCompliances", 1, 0, + NULL, NULL +}, +_usmMIBGroups_obj = { + "usmMIBGroups", 2, 0, + NULL, &_usmMIBCompliances_obj +}, +_usmUserEngineID_obj = { + "usmUserEngineID", 1, 0, + NULL, NULL +}, +_usmUserName_obj = { + "usmUserName", 2, 0, + NULL, &_usmUserEngineID_obj +}, +_usmUserSecurityName_obj = { + "usmUserSecurityName", 3, 0, + NULL, &_usmUserName_obj +}, +_usmUserCloneFrom_obj = { + "usmUserCloneFrom", 4, 0, + NULL, &_usmUserSecurityName_obj +}, +_usmUserAuthProtocol_obj = { + "usmUserAuthProtocol", 5, 0, + NULL, &_usmUserCloneFrom_obj +}, +_usmUserAuthKeyChange_obj = { + "usmUserAuthKeyChange", 6, 0, + NULL, &_usmUserAuthProtocol_obj +}, +_usmUserOwnAuthKeyChange_obj = { + "usmUserOwnAuthKeyChange", 7, 0, + NULL, &_usmUserAuthKeyChange_obj +}, +_usmUserPrivProtocol_obj = { + "usmUserPrivProtocol", 8, 0, + NULL, &_usmUserOwnAuthKeyChange_obj +}, +_usmUserPrivKeyChange_obj = { + "usmUserPrivKeyChange", 9, 0, + NULL, &_usmUserPrivProtocol_obj +}, +_usmUserOwnPrivKeyChange_obj = { + "usmUserOwnPrivKeyChange", 10, 0, + NULL, &_usmUserPrivKeyChange_obj +}, +_usmUserPublic_obj = { + "usmUserPublic", 11, 0, + NULL, &_usmUserOwnPrivKeyChange_obj +}, +_usmUserStorageType_obj = { + "usmUserStorageType", 12, 0, + NULL, &_usmUserPublic_obj +}, +_usmUserStatus_obj = { + "usmUserStatus", 13, 0, + NULL, &_usmUserStorageType_obj +}, +_usmUserEntry_obj = { + "usmUserEntry", 1, 0, + &_usmUserStatus_obj, NULL +}, +_usmUserSpinLock_obj = { + "usmUserSpinLock", 1, 0, + NULL, NULL +}, +_usmUserTable_obj = { + "usmUserTable", 2, 0, + &_usmUserEntry_obj, &_usmUserSpinLock_obj +}, +_usmStatsUnsupportedSecLevels_obj = { + "usmStatsUnsupportedSecLevels", 1, 0, + NULL, NULL +}, +_usmStatsNotInTimeWindows_obj = { + "usmStatsNotInTimeWindows", 2, 0, + NULL, &_usmStatsUnsupportedSecLevels_obj +}, +_usmStatsUnknownUserNames_obj = { + "usmStatsUnknownUserNames", 3, 0, + NULL, &_usmStatsNotInTimeWindows_obj +}, +_usmStatsUnknownEngineIDs_obj = { + "usmStatsUnknownEngineIDs", 4, 0, + NULL, &_usmStatsUnknownUserNames_obj +}, +_usmStatsWrongDigests_obj = { + "usmStatsWrongDigests", 5, 0, + NULL, &_usmStatsUnknownEngineIDs_obj +}, +_usmStatsDecryptionErrors_obj = { + "usmStatsDecryptionErrors", 6, 0, + NULL, &_usmStatsWrongDigests_obj +}, +_usmStats_obj = { + "usmStats", 1, 0, + &_usmStatsDecryptionErrors_obj, NULL +}, +_usmUser_obj = { + "usmUser", 2, 0, + &_usmUserTable_obj, &_usmStats_obj +}, +_usmMIBObjects_obj = { + "usmMIBObjects", 1, 0, + &_usmUser_obj, NULL +}, +_usmMIBConformance_obj = { + "usmMIBConformance", 2, 0, + &_usmMIBGroups_obj, &_usmMIBObjects_obj +}, +_snmpMPDMIBCompliances_obj = { + "snmpMPDMIBCompliances", 1, 0, + NULL, NULL +}, +_snmpMPDMIBGroups_obj = { + "snmpMPDMIBGroups", 2, 0, + NULL, &_snmpMPDMIBCompliances_obj +}, +_snmpUnknownSecurityModels_obj = { + "snmpUnknownSecurityModels", 1, 0, + NULL, NULL +}, +_snmpInvalidMsgs_obj = { + "snmpInvalidMsgs", 2, 0, + NULL, &_snmpUnknownSecurityModels_obj +}, +_snmpUnknownPDUHandlers_obj = { + "snmpUnknownPDUHandlers", 3, 0, + NULL, &_snmpInvalidMsgs_obj +}, +_snmpMPDStats_obj = { + "snmpMPDStats", 1, 0, + &_snmpUnknownPDUHandlers_obj, NULL +}, +_snmpMPDAdmin_obj = { + "snmpMPDAdmin", 1, 0, + NULL, NULL +}, +_snmpMPDMIBObjects_obj = { + "snmpMPDMIBObjects", 2, 0, + &_snmpMPDStats_obj, &_snmpMPDAdmin_obj +}, +_snmpMPDMIBConformance_obj = { + "snmpMPDMIBConformance", 3, 0, + &_snmpMPDMIBGroups_obj, &_snmpMPDMIBObjects_obj +}, +_snmpEngineID_obj = { + "snmpEngineID", 1, 0, + NULL, NULL +}, +_snmpEngineBoots_obj = { + "snmpEngineBoots", 2, 0, + NULL, &_snmpEngineID_obj +}, +_snmpEngineTime_obj = { + "snmpEngineTime", 3, 0, + NULL, &_snmpEngineBoots_obj +}, +_snmpEngineMaxMessageSize_obj = { + "snmpEngineMaxMessageSize", 4, 0, + NULL, &_snmpEngineTime_obj +}, +_snmpEngine_obj = { + "snmpEngine", 1, 0, + &_snmpEngineMaxMessageSize_obj, NULL +}, +_snmpFrameworkAdmin_obj = { + "snmpFrameworkAdmin", 1, 0, + NULL, NULL +}, +_snmpFrameworkMIBObjects_obj = { + "snmpFrameworkMIBObjects", 2, 0, + &_snmpEngine_obj, &_snmpFrameworkAdmin_obj +}, +_snmpFrameworkMIBConformance_obj = { + "snmpFrameworkMIBConformance", 3, 0, + NULL, &_snmpFrameworkMIBObjects_obj +}, +_snmpFrameworkMIB_obj = { + "snmpFrameworkMIB", 10, 0, + &_snmpFrameworkMIBConformance_obj, NULL +}, +_snmpMPDMIB_obj = { + "snmpMPDMIB", 11, 0, + &_snmpMPDMIBConformance_obj, &_snmpFrameworkMIB_obj +}, +_snmpUsmMIB_obj = { + "snmpUsmMIB", 15, 0, + &_usmMIBConformance_obj, &_snmpMPDMIB_obj +}, +_snmpModules_obj = { + "snmpModules", 3, 0, + &_snmpUsmMIB_obj, NULL +}, _mib_obj = { "mib", 1, 0, &_snmp_obj, NULL @@ -1237,9 +1433,17 @@ _private_obj = { "private", 4, 0, &_enterprises_obj, &_experimental_obj }, +_security_obj = { + "security", 5, 0, + NULL, &_private_obj +}, +_snmpV2_obj = { + "snmpV2", 6, 0, + &_snmpModules_obj, &_security_obj +}, _internet_obj = { "internet", 1, 0, - &_private_obj, NULL + &_snmpV2_obj, NULL }, _dod_obj = { "dod", 6, 0, diff --git a/kame/kame/tcpdump/missing/addrinfo.h b/kame/kame/tcpdump/missing/addrinfo.h new file mode 100644 index 0000000000..09f6a425ea --- /dev/null +++ b/kame/kame/tcpdump/missing/addrinfo.h @@ -0,0 +1,122 @@ +/* + * Copyright (C) 1995, 1996, 1997, 1998, and 1999 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. + */ + +/* $Id: addrinfo.h,v 1.4 2002/06/11 17:13:36 itojun Exp $ */ + +#ifndef HAVE_ADDRINFO + +/* + * Error return codes from getaddrinfo() + */ +#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ +#define EAI_AGAIN 2 /* temporary failure in name resolution */ +#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ +#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ +#define EAI_FAMILY 5 /* ai_family not supported */ +#define EAI_MEMORY 6 /* memory allocation failure */ +#define EAI_NODATA 7 /* no address associated with hostname */ +#define EAI_NONAME 8 /* hostname nor servname provided, or not known */ +#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ +#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ +#define EAI_SYSTEM 11 /* system error returned in errno */ +#define EAI_BADHINTS 12 +#define EAI_PROTOCOL 13 +#define EAI_MAX 14 + +/* internal error */ +#define NETDB_INTERNAL -1 /* see errno */ + +/* + * Flag values for getaddrinfo() + */ +#define AI_PASSIVE 0x00000001 /* get address to use bind() */ +#define AI_CANONNAME 0x00000002 /* fill ai_canonname */ +#define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ +/* valid flags for addrinfo */ +#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST) + +#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ +#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ +#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ +#define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ +/* special recommended flags for getipnodebyname */ +#define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) + +struct addrinfo { + int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ + int ai_family; /* PF_xxx */ + int ai_socktype; /* SOCK_xxx */ + int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ + size_t ai_addrlen; /* length of ai_addr */ + char *ai_canonname; /* canonical name for hostname */ + struct sockaddr *ai_addr; /* binary address */ + struct addrinfo *ai_next; /* next structure in linked list */ +}; + +extern void freeaddrinfo (struct addrinfo *); +extern void freehostent (struct hostent *); +extern char *gai_strerror (int); +extern int getaddrinfo (const char *, const char *, + const struct addrinfo *, struct addrinfo **); +extern int getnameinfo (const struct sockaddr *, size_t, char *, + size_t, char *, size_t, int); +extern struct hostent *getipnodebyaddr (const void *, size_t, int, int *); +extern struct hostent *getipnodebyname (const char *, int, int, int *); +extern int inet_pton (int, const char *, void *); +extern const char *inet_ntop (int, const void *, char *, size_t); +#endif /* HAVE_ADDRINFO */ + +/* + * Constants for getnameinfo() + */ +#ifndef NI_MAXHOST +#define NI_MAXHOST 1025 +#endif +#ifndef NI_MAXSERV +#define NI_MAXSERV 32 +#endif + +/* + * Flag values for getnameinfo() + */ +#ifndef NI_NOFQDN +#define NI_NOFQDN 0x00000001 +#endif +#ifndef NI_NUMERICHOST +#define NI_NUMERICHOST 0x00000002 +#endif +#ifndef NI_NAMEREQD +#define NI_NAMEREQD 0x00000004 +#endif +#ifndef NI_NUMERICSERV +#define NI_NUMERICSERV 0x00000008 +#endif +#ifndef NI_DGRAM +#define NI_DGRAM 0x00000010 +#endif diff --git a/kame/kame/tcpdump/missing/addrsize.h b/kame/kame/tcpdump/missing/addrsize.h new file mode 100644 index 0000000000..13db4da915 --- /dev/null +++ b/kame/kame/tcpdump/missing/addrsize.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 1999 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 INADDRSZ +#define INADDRSZ 4 /* IPv4 T_A */ +#endif + +#ifndef IN6ADDRSZ +#define IN6ADDRSZ 16 /* IPv6 T_AAAA */ +#endif + diff --git a/kame/kame/tcpdump/missing/bittypes.h b/kame/kame/tcpdump/missing/bittypes.h new file mode 100644 index 0000000000..577da9448e --- /dev/null +++ b/kame/kame/tcpdump/missing/bittypes.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 1999 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 HAVE_U_INT8_T + +#if SIZEOF_CHAR == 1 +typedef unsigned char u_int8_t; +#elif SIZEOF_INT == 1 +typedef unsigned int u_int8_t; +#else /* XXX */ +#error "there's no appropriate type for u_int8_t" +#endif + +#endif /* HAVE_U_INT8_T */ + +#ifndef HAVE_U_INT16_T + +#if SIZEOF_SHORT == 2 +typedef unsigned short u_int16_t; +#elif SIZEOF_INT == 2 +typedef unsigned int u_int16_t; +#elif SIZEOF_CHAR == 2 +typedef unsigned char u_int16_t; +#else /* XXX */ +#error "there's no appropriate type for u_int16_t" +#endif + +#endif /* HAVE_U_INT16_T */ + +#ifndef HAVE_U_INT32_T + +#if SIZEOF_INT == 4 +typedef unsigned int u_int32_t; +#elif SIZEOF_LONG == 4 +typedef unsigned long u_int32_t; +#elif SIZEOF_SHORT == 4 +typedef unsigned short u_int32_t; +#else /* XXX */ +#error "there's no appropriate type for u_int32_t" +#endif + +#endif /* HAVE_U_INT32_T */ diff --git a/kame/kame/tcpdump/missing/datalinks.c b/kame/kame/tcpdump/missing/datalinks.c new file mode 100644 index 0000000000..9439142867 --- /dev/null +++ b/kame/kame/tcpdump/missing/datalinks.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Computer Systems + * Engineering Group at Lawrence Berkeley Laboratory. + * 4. Neither the name of the University nor of the Laboratory may be used + * to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/missing/datalinks.c,v 1.1.2.3 2003/11/16 09:29:48 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include + +#include "pcap-missing.h" + +/* + * Stub versions for platforms that don't support them. + */ +int +pcap_list_datalinks(pcap_t *p, int **dlt_buffer) +{ + /* + * This platform doesn't support changing the DLT for an + * interface. Return a list of DLTs containing only the + * DLT this device supports. + */ + *dlt_buffer = (int*)malloc(sizeof(**dlt_buffer)); + if (*dlt_buffer == NULL) + return (-1); + **dlt_buffer = pcap_datalink(p); + return (1); +} diff --git a/kame/kame/tcpdump/missing/dlnames.c b/kame/kame/tcpdump/missing/dlnames.c new file mode 100644 index 0000000000..97f3788d6e --- /dev/null +++ b/kame/kame/tcpdump/missing/dlnames.c @@ -0,0 +1,175 @@ +/* + * Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Computer Systems + * Engineering Group at Lawrence Berkeley Laboratory. + * 4. Neither the name of the University nor of the Laboratory may be used + * to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/missing/dlnames.c,v 1.2.2.3 2003/11/18 23:12:12 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include + +#include "pcap-missing.h" + +struct dlt_choice { + const char *name; + const char *description; + int dlt; +}; + +#define DLT_CHOICE(code, description) { #code, description, code } +#define DLT_CHOICE_SENTINEL { NULL, NULL, 0 } + +static struct dlt_choice dlt_choices[] = { + DLT_CHOICE(DLT_NULL, "BSD loopback"), + DLT_CHOICE(DLT_EN10MB, "Ethernet"), + DLT_CHOICE(DLT_IEEE802, "Token ring"), + DLT_CHOICE(DLT_ARCNET, "ARCNET"), + DLT_CHOICE(DLT_SLIP, "SLIP"), + DLT_CHOICE(DLT_PPP, "PPP"), + DLT_CHOICE(DLT_FDDI, "FDDI"), + DLT_CHOICE(DLT_ATM_RFC1483, "RFC 1483 IP-over-ATM"), + DLT_CHOICE(DLT_RAW, "Raw IP"), +#ifdef DLT_SLIP_BSDOS + DLT_CHOICE(DLT_SLIP_BSDOS, "BSD/OS SLIP"), +#endif +#ifdef DLT_PPP_BSDOS + DLT_CHOICE(DLT_PPP_BSDOS, "BSD/OS PPP"), +#endif +#ifdef DLT_ATM_CLIP + DLT_CHOICE(DLT_ATM_CLIP, "Linux Classical IP-over-ATM"), +#endif +#ifdef DLT_PPP_SERIAL + DLT_CHOICE(DLT_PPP_SERIAL, "PPP over serial"), +#endif +#ifdef DLT_PPP_ETHER + DLT_CHOICE(DLT_PPP_ETHER, "PPPoE"), +#endif +#ifdef DLT_C_HDLC + DLT_CHOICE(DLT_C_HDLC, "Cisco HDLC"), +#endif +#ifdef DLT_IEEE802_11 + DLT_CHOICE(DLT_IEEE802_11, "802.11"), +#endif +#ifdef DLT_FRELAY + DLT_CHOICE(DLT_FRELAY, "Frame Relay"), +#endif +#ifdef DLT_LOOP + DLT_CHOICE(DLT_LOOP, "OpenBSD loopback"), +#endif +#ifdef DLT_ENC + DLT_CHOICE(DLT_ENC, "OpenBSD encapsulated IP"), +#endif +#ifdef DLT_LINUX_SLL + DLT_CHOICE(DLT_LINUX_SLL, "Linux cooked"), +#endif +#ifdef DLT_LTALK + DLT_CHOICE(DLT_LTALK, "Localtalk"), +#endif +#ifdef DLT_PFLOG + DLT_CHOICE(DLT_PFLOG, "OpenBSD pflog file"), +#endif +#ifdef DLT_PRISM_HEADER + DLT_CHOICE(DLT_PRISM_HEADER, "802.11 plus Prism header"), +#endif +#ifdef DLT_IP_OVER_FC + DLT_CHOICE(DLT_IP_OVER_FC, "RFC 2625 IP-over-Fibre Channel"), +#endif +#ifdef DLT_SUNATM + DLT_CHOICE(DLT_SUNATM, "Sun raw ATM"), +#endif +#ifdef DLT_IEEE802_11_RADIO + DLT_CHOICE(DLT_IEEE802_11_RADIO, "802.11 plus radio information header"), +#endif +#ifdef DLT_ARCNET_LINUX + DLT_CHOICE(DLT_ARCNET_LINUX, "Linux ARCNET"), +#endif +#ifdef DLT_LINUX_IRDA + DLT_CHOICE(DLT_LINUX_IRDA, "Linux IrDA"), +#endif +#ifdef DLT_LANE8023 + DLT_CHOICE(DLT_LANE8023, "Linux 802.3 LANE"), +#endif +#ifdef DLT_CIP + DLT_CHOICE(DLT_CIP, "Linux Classical IP-over-ATM"), +#endif +#ifdef DLT_HDLC + DLT_CHOICE(DLT_HDLC, "Cisco HDLC"), +#endif + DLT_CHOICE_SENTINEL +}; + +#ifndef HAVE_PCAP_DATALINK_NAME_TO_VAL +int +pcap_datalink_name_to_val(const char *name) +{ + int i; + + for (i = 0; dlt_choices[i].name != NULL; i++) { + if (strcasecmp(dlt_choices[i].name + sizeof("DLT_") - 1, + name) == 0) + return (dlt_choices[i].dlt); + } + return (-1); +} + +const char * +pcap_datalink_val_to_name(int dlt) +{ + int i; + + for (i = 0; dlt_choices[i].name != NULL; i++) { + if (dlt_choices[i].dlt == dlt) + return (dlt_choices[i].name + sizeof("DLT_") - 1); + } + return (NULL); +} +#endif + +const char * +pcap_datalink_val_to_description(int dlt) +{ + int i; + + for (i = 0; dlt_choices[i].name != NULL; i++) { + if (dlt_choices[i].dlt == dlt) + return (dlt_choices[i].description); + } + return (NULL); +} diff --git a/kame/kame/tcpdump/missing/getaddrinfo.c b/kame/kame/tcpdump/missing/getaddrinfo.c new file mode 100644 index 0000000000..2a9e0e1bcd --- /dev/null +++ b/kame/kame/tcpdump/missing/getaddrinfo.c @@ -0,0 +1,1115 @@ +/* + * 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. + */ + +/* + * "#ifdef FAITH" part is local hack for supporting IPv4-v6 translator. + * + * Issues to be discussed: + * - Thread safe-ness must be checked. + * - Return values. There are nonstandard return values defined and used + * in the source code. This is because RFC2553 is silent about which error + * code must be returned for which situation. + * Note: + * - We use getipnodebyname() just for thread-safeness. There's no intent + * to let it do PF_UNSPEC (actually we never pass PF_UNSPEC to + * getipnodebyname(). + * - The code filters out AFs that are not supported by the kernel, + * when globbing NULL hostname (to loopback, or wildcard). Is it the right + * thing to do? What is the relationship with post-RFC2553 AI_ADDRCONFIG + * in ai_flags? + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/missing/getaddrinfo.c,v 1.11.2.2 2003/11/16 08:52:00 guy Exp $"; +#endif + +#include +#include +#if 0 +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef HAVE_U_INT32_T +#include "bittypes.h" +#endif + +#ifndef HAVE_SOCKADDR_STORAGE +#include "sockstorage.h" +#endif + +#ifdef NEED_ADDRINFO_H +#include "addrinfo.h" +#endif + +#if defined(__KAME__) && defined(INET6) +# define FAITH +#endif + +#define SUCCESS 0 +#define ANY 0 +#define YES 1 +#define NO 0 + +#ifdef FAITH +static int translate = NO; +static struct in6_addr faith_prefix = IN6ADDR_ANY_INIT; +#endif + +static const char in_addrany[] = { 0, 0, 0, 0 }; +static const char in6_addrany[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; +static const char in_loopback[] = { 127, 0, 0, 1 }; +static const char in6_loopback[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 +}; + +struct sockinet { + u_char si_len; + u_char si_family; + u_short si_port; + u_int32_t si_scope_id; +}; + +static const struct afd { + int a_af; + int a_addrlen; + int a_socklen; + int a_off; + const char *a_addrany; + const char *a_loopback; + int a_scoped; +} afdl [] = { +#ifdef INET6 + {PF_INET6, sizeof(struct in6_addr), + sizeof(struct sockaddr_in6), + offsetof(struct sockaddr_in6, sin6_addr), + in6_addrany, in6_loopback, 1}, +#endif + {PF_INET, sizeof(struct in_addr), + sizeof(struct sockaddr_in), + offsetof(struct sockaddr_in, sin_addr), + in_addrany, in_loopback, 0}, + {0, 0, 0, 0, NULL, NULL, 0}, +}; + +struct explore { + int e_af; + int e_socktype; + int e_protocol; + const char *e_protostr; + int e_wild; +#define WILD_AF(ex) ((ex)->e_wild & 0x01) +#define WILD_SOCKTYPE(ex) ((ex)->e_wild & 0x02) +#define WILD_PROTOCOL(ex) ((ex)->e_wild & 0x04) +}; + +static const struct explore explore[] = { +#if 0 + { PF_LOCAL, 0, ANY, ANY, NULL, 0x01 }, +#endif +#ifdef INET6 + { PF_INET6, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 }, + { PF_INET6, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 }, + { PF_INET6, SOCK_RAW, ANY, NULL, 0x05 }, +#endif + { PF_INET, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 }, + { PF_INET, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 }, + { PF_INET, SOCK_RAW, ANY, NULL, 0x05 }, + { -1, 0, 0, NULL, 0 }, +}; + +#ifdef INET6 +#define PTON_MAX 16 +#else +#define PTON_MAX 4 +#endif + + +static int str_isnumber (const char *); +static int explore_fqdn (const struct addrinfo *, const char *, + const char *, struct addrinfo **); +static int explore_null (const struct addrinfo *, const char *, + const char *, struct addrinfo **); +static int explore_numeric (const struct addrinfo *, const char *, + const char *, struct addrinfo **); +static int explore_numeric_scope (const struct addrinfo *, const char *, + const char *, struct addrinfo **); +static int get_name (const char *, const struct afd *, struct addrinfo **, + char *, const struct addrinfo *, const char *); +static int get_canonname (const struct addrinfo *, + struct addrinfo *, const char *); +static struct addrinfo *get_ai (const struct addrinfo *, + const struct afd *, const char *); +static int get_portmatch (const struct addrinfo *, const char *); +static int get_port (struct addrinfo *, const char *, int); +static const struct afd *find_afd (int); + +static char *ai_errlist[] = { + "Success", + "Address family for hostname not supported", /* EAI_ADDRFAMILY */ + "Temporary failure in name resolution", /* EAI_AGAIN */ + "Invalid value for ai_flags", /* EAI_BADFLAGS */ + "Non-recoverable failure in name resolution", /* EAI_FAIL */ + "ai_family not supported", /* EAI_FAMILY */ + "Memory allocation failure", /* EAI_MEMORY */ + "No address associated with hostname", /* EAI_NODATA */ + "hostname nor servname provided, or not known", /* EAI_NONAME */ + "servname not supported for ai_socktype", /* EAI_SERVICE */ + "ai_socktype not supported", /* EAI_SOCKTYPE */ + "System error returned in errno", /* EAI_SYSTEM */ + "Invalid value for hints", /* EAI_BADHINTS */ + "Resolved protocol is unknown", /* EAI_PROTOCOL */ + "Unknown error", /* EAI_MAX */ +}; + +/* XXX macros that make external reference is BAD. */ + +#define GET_AI(ai, afd, addr) \ +do { \ + /* external reference: pai, error, and label free */ \ + (ai) = get_ai(pai, (afd), (addr)); \ + if ((ai) == NULL) { \ + error = EAI_MEMORY; \ + goto free; \ + } \ +} while (0) + +#define GET_PORT(ai, serv) \ +do { \ + /* external reference: error and label free */ \ + error = get_port((ai), (serv), 0); \ + if (error != 0) \ + goto free; \ +} while (0) + +#define GET_CANONNAME(ai, str) \ +do { \ + /* external reference: pai, error and label free */ \ + error = get_canonname(pai, (ai), (str)); \ + if (error != 0) \ + goto free; \ +} while (0) + +#define ERR(err) \ +do { \ + /* external reference: error, and label bad */ \ + error = (err); \ + goto bad; \ +} while (0) + +#define MATCH_FAMILY(x, y, w) \ + ((x) == (y) || ((w) && ((x) == PF_UNSPEC || (y) == PF_UNSPEC))) +#define MATCH(x, y, w) \ + ((x) == (y) || ((w) && ((x) == ANY || (y) == ANY))) + +char * +gai_strerror(ecode) + int ecode; +{ + if (ecode < 0 || ecode > EAI_MAX) + ecode = EAI_MAX; + return ai_errlist[ecode]; +} + +void +freeaddrinfo(ai) + struct addrinfo *ai; +{ + struct addrinfo *next; + + do { + next = ai->ai_next; + if (ai->ai_canonname) + free(ai->ai_canonname); + /* no need to free(ai->ai_addr) */ + free(ai); + } while ((ai = next) != NULL); +} + +static int +str_isnumber(p) + const char *p; +{ + char *q = (char *)p; + while (*q) { + if (! isdigit(*q)) + return NO; + q++; + } + return YES; +} + +int +getaddrinfo(hostname, servname, hints, res) + const char *hostname, *servname; + const struct addrinfo *hints; + struct addrinfo **res; +{ + struct addrinfo sentinel; + struct addrinfo *cur; + int error = 0; + struct addrinfo ai; + struct addrinfo ai0; + struct addrinfo *pai; + const struct afd *afd; + const struct explore *ex; + +#ifdef FAITH + static int firsttime = 1; + + if (firsttime) { + /* translator hack */ + char *q = getenv("GAI"); + if (q && inet_pton(AF_INET6, q, &faith_prefix) == 1) + translate = YES; + firsttime = 0; + } +#endif + + sentinel.ai_next = NULL; + cur = &sentinel; + pai = &ai; + pai->ai_flags = 0; + pai->ai_family = PF_UNSPEC; + pai->ai_socktype = ANY; + pai->ai_protocol = ANY; + pai->ai_addrlen = 0; + pai->ai_canonname = NULL; + pai->ai_addr = NULL; + pai->ai_next = NULL; + + if (hostname == NULL && servname == NULL) + return EAI_NONAME; + if (hints) { + /* error check for hints */ + if (hints->ai_addrlen || hints->ai_canonname || + hints->ai_addr || hints->ai_next) + ERR(EAI_BADHINTS); /* xxx */ + if (hints->ai_flags & ~AI_MASK) + ERR(EAI_BADFLAGS); + switch (hints->ai_family) { + case PF_UNSPEC: + case PF_INET: +#ifdef INET6 + case PF_INET6: +#endif + break; + default: + ERR(EAI_FAMILY); + } + memcpy(pai, hints, sizeof(*pai)); + + /* + * if both socktype/protocol are specified, check if they + * are meaningful combination. + */ + if (pai->ai_socktype != ANY && pai->ai_protocol != ANY) { + for (ex = explore; ex->e_af >= 0; ex++) { + if (pai->ai_family != ex->e_af) + continue; + if (ex->e_socktype == ANY) + continue; + if (ex->e_protocol == ANY) + continue; + if (pai->ai_socktype == ex->e_socktype + && pai->ai_protocol != ex->e_protocol) { + ERR(EAI_BADHINTS); + } + } + } + } + + /* + * check for special cases. (1) numeric servname is disallowed if + * socktype/protocol are left unspecified. (2) servname is disallowed + * for raw and other inet{,6} sockets. + */ + if (MATCH_FAMILY(pai->ai_family, PF_INET, 1) +#ifdef PF_INET6 + || MATCH_FAMILY(pai->ai_family, PF_INET6, 1) +#endif + ) { + ai0 = *pai; + + if (pai->ai_family == PF_UNSPEC) { +#ifdef PF_INET6 + pai->ai_family = PF_INET6; +#else + pai->ai_family = PF_INET; +#endif + } + error = get_portmatch(pai, servname); + if (error) + ERR(error); + + *pai = ai0; + } + + ai0 = *pai; + + /* NULL hostname, or numeric hostname */ + for (ex = explore; ex->e_af >= 0; ex++) { + *pai = ai0; + + if (!MATCH_FAMILY(pai->ai_family, ex->e_af, WILD_AF(ex))) + continue; + if (!MATCH(pai->ai_socktype, ex->e_socktype, WILD_SOCKTYPE(ex))) + continue; + if (!MATCH(pai->ai_protocol, ex->e_protocol, WILD_PROTOCOL(ex))) + continue; + + if (pai->ai_family == PF_UNSPEC) + pai->ai_family = ex->e_af; + if (pai->ai_socktype == ANY && ex->e_socktype != ANY) + pai->ai_socktype = ex->e_socktype; + if (pai->ai_protocol == ANY && ex->e_protocol != ANY) + pai->ai_protocol = ex->e_protocol; + + if (hostname == NULL) + error = explore_null(pai, hostname, servname, &cur->ai_next); + else + error = explore_numeric_scope(pai, hostname, servname, &cur->ai_next); + + if (error) + goto free; + + while (cur && cur->ai_next) + cur = cur->ai_next; + } + + /* + * XXX + * If numreic representation of AF1 can be interpreted as FQDN + * representation of AF2, we need to think again about the code below. + */ + if (sentinel.ai_next) + goto good; + + if (pai->ai_flags & AI_NUMERICHOST) + ERR(EAI_NONAME); + if (hostname == NULL) + ERR(EAI_NONAME); + + /* + * hostname as alphabetical name. + * we would like to prefer AF_INET6 than AF_INET, so we'll make a + * outer loop by AFs. + */ + for (afd = afdl; afd->a_af; afd++) { + *pai = ai0; + + if (!MATCH_FAMILY(pai->ai_family, afd->a_af, 1)) + continue; + + for (ex = explore; ex->e_af >= 0; ex++) { + *pai = ai0; + + if (pai->ai_family == PF_UNSPEC) + pai->ai_family = afd->a_af; + + if (!MATCH_FAMILY(pai->ai_family, ex->e_af, WILD_AF(ex))) + continue; + if (!MATCH(pai->ai_socktype, ex->e_socktype, + WILD_SOCKTYPE(ex))) { + continue; + } + if (!MATCH(pai->ai_protocol, ex->e_protocol, + WILD_PROTOCOL(ex))) { + continue; + } + + if (pai->ai_family == PF_UNSPEC) + pai->ai_family = ex->e_af; + if (pai->ai_socktype == ANY && ex->e_socktype != ANY) + pai->ai_socktype = ex->e_socktype; + if (pai->ai_protocol == ANY && ex->e_protocol != ANY) + pai->ai_protocol = ex->e_protocol; + + error = explore_fqdn(pai, hostname, servname, + &cur->ai_next); + + while (cur && cur->ai_next) + cur = cur->ai_next; + } + } + + /* XXX */ + if (sentinel.ai_next) + error = 0; + + if (error) + goto free; + if (error == 0) { + if (sentinel.ai_next) { + good: + *res = sentinel.ai_next; + return SUCCESS; + } else + error = EAI_FAIL; + } + free: + bad: + if (sentinel.ai_next) + freeaddrinfo(sentinel.ai_next); + *res = NULL; + return error; +} + +/* + * FQDN hostname, DNS lookup + */ +static int +explore_fqdn(pai, hostname, servname, res) + const struct addrinfo *pai; + const char *hostname; + const char *servname; + struct addrinfo **res; +{ + struct hostent *hp; + int h_error; + int af; + char **aplist = NULL, *apbuf = NULL; + char *ap; + struct addrinfo sentinel, *cur; + int i; +#ifndef USE_GETIPNODEBY + int naddrs; +#endif + const struct afd *afd; + int error; + + *res = NULL; + sentinel.ai_next = NULL; + cur = &sentinel; + + /* + * Do not filter unsupported AFs here. We need to honor content of + * databases (/etc/hosts, DNS and others). Otherwise we cannot + * replace gethostbyname() by getaddrinfo(). + */ + + /* + * if the servname does not match socktype/protocol, ignore it. + */ + if (get_portmatch(pai, servname) != 0) + return 0; + + afd = find_afd(pai->ai_family); + + /* + * post-RFC2553: should look at (pai->ai_flags & AI_ADDRCONFIG) + * rather than hardcoding it. we may need to add AI_ADDRCONFIG + * handling code by ourselves in case we don't have getipnodebyname(). + */ +#ifdef USE_GETIPNODEBY + hp = getipnodebyname(hostname, pai->ai_family, AI_ADDRCONFIG, &h_error); +#else +#ifdef HAVE_GETHOSTBYNAME2 + hp = gethostbyname2(hostname, pai->ai_family); +#else + if (pai->ai_family != AF_INET) + return 0; + hp = gethostbyname(hostname); +#ifdef HAVE_H_ERRNO + h_error = h_errno; +#else + h_error = EINVAL; +#endif +#endif /*HAVE_GETHOSTBYNAME2*/ +#endif /*USE_GETIPNODEBY*/ + + if (hp == NULL) { + switch (h_error) { + case HOST_NOT_FOUND: + case NO_DATA: + error = EAI_NODATA; + break; + case TRY_AGAIN: + error = EAI_AGAIN; + break; + case NO_RECOVERY: + case NETDB_INTERNAL: + default: + error = EAI_FAIL; + break; + } + } else if ((hp->h_name == NULL) || (hp->h_name[0] == 0) + || (hp->h_addr_list[0] == NULL)) { +#ifdef USE_GETIPNODEBY + freehostent(hp); +#endif + hp = NULL; + error = EAI_FAIL; + } + + if (hp == NULL) + goto free; + +#ifdef USE_GETIPNODEBY + aplist = hp->h_addr_list; +#else + /* + * hp will be overwritten if we use gethostbyname2(). + * always deep copy for simplification. + */ + for (naddrs = 0; hp->h_addr_list[naddrs] != NULL; naddrs++) + ; + naddrs++; + aplist = (char **)malloc(sizeof(aplist[0]) * naddrs); + apbuf = (char *)malloc(hp->h_length * naddrs); + if (aplist == NULL || apbuf == NULL) { + error = EAI_MEMORY; + goto free; + } + memset(aplist, 0, sizeof(aplist[0]) * naddrs); + for (i = 0; i < naddrs; i++) { + if (hp->h_addr_list[i] == NULL) { + aplist[i] = NULL; + continue; + } + memcpy(&apbuf[i * hp->h_length], hp->h_addr_list[i], + hp->h_length); + aplist[i] = &apbuf[i * hp->h_length]; + } +#endif + + for (i = 0; aplist[i] != NULL; i++) { + af = hp->h_addrtype; + ap = aplist[i]; +#ifdef AF_INET6 + if (af == AF_INET6 + && IN6_IS_ADDR_V4MAPPED((struct in6_addr *)ap)) { + af = AF_INET; + ap = ap + sizeof(struct in6_addr) + - sizeof(struct in_addr); + } +#endif + + if (af != pai->ai_family) + continue; + + if ((pai->ai_flags & AI_CANONNAME) == 0) { + GET_AI(cur->ai_next, afd, ap); + GET_PORT(cur->ai_next, servname); + } else { + /* + * if AI_CANONNAME and if reverse lookup + * fail, return ai anyway to pacify + * calling application. + * + * XXX getaddrinfo() is a name->address + * translation function, and it looks + * strange that we do addr->name + * translation here. + */ + get_name(ap, afd, &cur->ai_next, + ap, pai, servname); + } + + while (cur && cur->ai_next) + cur = cur->ai_next; + } + + *res = sentinel.ai_next; + return 0; + +free: +#ifdef USE_GETIPNODEBY + if (hp) + freehostent(hp); +#endif + if (aplist) + free(aplist); + if (apbuf) + free(apbuf); + if (sentinel.ai_next) + freeaddrinfo(sentinel.ai_next); + return error; +} + +/* + * hostname == NULL. + * passive socket -> anyaddr (0.0.0.0 or ::) + * non-passive socket -> localhost (127.0.0.1 or ::1) + */ +static int +explore_null(pai, hostname, servname, res) + const struct addrinfo *pai; + const char *hostname; + const char *servname; + struct addrinfo **res; +{ + int s; + const struct afd *afd; + struct addrinfo *cur; + struct addrinfo sentinel; + int error; + + *res = NULL; + sentinel.ai_next = NULL; + cur = &sentinel; + + /* + * filter out AFs that are not supported by the kernel + * XXX errno? + */ + s = socket(pai->ai_family, SOCK_DGRAM, 0); + if (s < 0) { + if (errno != EMFILE) + return 0; + } else + close(s); + + /* + * if the servname does not match socktype/protocol, ignore it. + */ + if (get_portmatch(pai, servname) != 0) + return 0; + + afd = find_afd(pai->ai_family); + + if (pai->ai_flags & AI_PASSIVE) { + GET_AI(cur->ai_next, afd, afd->a_addrany); + /* xxx meaningless? + * GET_CANONNAME(cur->ai_next, "anyaddr"); + */ + GET_PORT(cur->ai_next, servname); + } else { + GET_AI(cur->ai_next, afd, afd->a_loopback); + /* xxx meaningless? + * GET_CANONNAME(cur->ai_next, "localhost"); + */ + GET_PORT(cur->ai_next, servname); + } + cur = cur->ai_next; + + *res = sentinel.ai_next; + return 0; + +free: + if (sentinel.ai_next) + freeaddrinfo(sentinel.ai_next); + return error; +} + +/* + * numeric hostname + */ +static int +explore_numeric(pai, hostname, servname, res) + const struct addrinfo *pai; + const char *hostname; + const char *servname; + struct addrinfo **res; +{ + const struct afd *afd; + struct addrinfo *cur; + struct addrinfo sentinel; + int error; + char pton[PTON_MAX]; + int flags; + + *res = NULL; + sentinel.ai_next = NULL; + cur = &sentinel; + + /* + * if the servname does not match socktype/protocol, ignore it. + */ + if (get_portmatch(pai, servname) != 0) + return 0; + + afd = find_afd(pai->ai_family); + flags = pai->ai_flags; + + if (inet_pton(afd->a_af, hostname, pton) == 1) { + u_int32_t v4a; +#ifdef INET6 + u_char pfx; +#endif + + switch (afd->a_af) { + case AF_INET: + v4a = (u_int32_t)ntohl(((struct in_addr *)pton)->s_addr); + if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a)) + flags &= ~AI_CANONNAME; + v4a >>= IN_CLASSA_NSHIFT; + if (v4a == 0 || v4a == IN_LOOPBACKNET) + flags &= ~AI_CANONNAME; + break; +#ifdef INET6 + case AF_INET6: + pfx = ((struct in6_addr *)pton)->s6_addr[0]; + if (pfx == 0 || pfx == 0xfe || pfx == 0xff) + flags &= ~AI_CANONNAME; + break; +#endif + } + + if (pai->ai_family == afd->a_af || + pai->ai_family == PF_UNSPEC /*?*/) { + if ((flags & AI_CANONNAME) == 0) { + GET_AI(cur->ai_next, afd, pton); + GET_PORT(cur->ai_next, servname); + } else { + /* + * if AI_CANONNAME and if reverse lookup + * fail, return ai anyway to pacify + * calling application. + * + * XXX getaddrinfo() is a name->address + * translation function, and it looks + * strange that we do addr->name + * translation here. + */ + get_name(pton, afd, &cur->ai_next, + pton, pai, servname); + } + while (cur && cur->ai_next) + cur = cur->ai_next; + } else + ERR(EAI_FAMILY); /*xxx*/ + } + + *res = sentinel.ai_next; + return 0; + +free: +bad: + if (sentinel.ai_next) + freeaddrinfo(sentinel.ai_next); + return error; +} + +/* + * numeric hostname with scope + */ +static int +explore_numeric_scope(pai, hostname, servname, res) + const struct addrinfo *pai; + const char *hostname; + const char *servname; + struct addrinfo **res; +{ +#ifndef SCOPE_DELIMITER + return explore_numeric(pai, hostname, servname, res); +#else + const struct afd *afd; + struct addrinfo *cur; + int error; + char *cp, *hostname2 = NULL; + int scope; + struct sockaddr_in6 *sin6; + + /* + * if the servname does not match socktype/protocol, ignore it. + */ + if (get_portmatch(pai, servname) != 0) + return 0; + + afd = find_afd(pai->ai_family); + if (!afd->a_scoped) + return explore_numeric(pai, hostname, servname, res); + + cp = strchr(hostname, SCOPE_DELIMITER); + if (cp == NULL) + return explore_numeric(pai, hostname, servname, res); + + /* + * Handle special case of + */ + hostname2 = strdup(hostname); + if (hostname2 == NULL) + return EAI_MEMORY; + /* terminate at the delimiter */ + hostname2[cp - hostname] = '\0'; + + cp++; + switch (pai->ai_family) { +#ifdef INET6 + case AF_INET6: + scope = if_nametoindex(cp); + if (scope == 0) { + free(hostname2); + return (EAI_NONAME); + } + break; +#endif + } + + error = explore_numeric(pai, hostname2, servname, res); + if (error == 0) { + for (cur = *res; cur; cur = cur->ai_next) { + if (cur->ai_family != AF_INET6) + continue; + sin6 = (struct sockaddr_in6 *)cur->ai_addr; + if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) || + IN6_IS_ADDR_MC_LINKLOCAL(&sin6->sin6_addr)) + sin6->sin6_scope_id = scope; + } + } + + free(hostname2); + + return error; +#endif +} + +static int +get_name(addr, afd, res, numaddr, pai, servname) + const char *addr; + const struct afd *afd; + struct addrinfo **res; + char *numaddr; + const struct addrinfo *pai; + const char *servname; +{ + struct hostent *hp = NULL; + struct addrinfo *cur = NULL; + int error = 0; + char *ap = NULL, *cn = NULL; +#ifdef USE_GETIPNODEBY + int h_error; + + hp = getipnodebyaddr(addr, afd->a_addrlen, afd->a_af, &h_error); +#else + hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af); +#endif + if (hp && hp->h_name && hp->h_name[0] && hp->h_addr_list[0]) { +#ifdef USE_GETIPNODEBY + GET_AI(cur, afd, hp->h_addr_list[0]); + GET_PORT(cur, servname); + GET_CANONNAME(cur, hp->h_name); +#else + /* hp will be damaged if we use gethostbyaddr() */ + if ((ap = (char *)malloc(hp->h_length)) == NULL) { + error = EAI_MEMORY; + goto free; + } + memcpy(ap, hp->h_addr_list[0], hp->h_length); + if ((cn = strdup(hp->h_name)) == NULL) { + error = EAI_MEMORY; + goto free; + } + + GET_AI(cur, afd, ap); + GET_PORT(cur, servname); + GET_CANONNAME(cur, cn); + free(ap); ap = NULL; + free(cn); cn = NULL; +#endif + } else { + GET_AI(cur, afd, numaddr); + GET_PORT(cur, servname); + } + +#ifdef USE_GETIPNODEBY + if (hp) + freehostent(hp); +#endif + *res = cur; + return SUCCESS; + free: + if (cur) + freeaddrinfo(cur); + if (ap) + free(ap); + if (cn) + free(cn); +#ifdef USE_GETIPNODEBY + if (hp) + freehostent(hp); +#endif + *res = NULL; + return error; +} + +static int +get_canonname(pai, ai, str) + const struct addrinfo *pai; + struct addrinfo *ai; + const char *str; +{ + if ((pai->ai_flags & AI_CANONNAME) != 0) { + ai->ai_canonname = (char *)malloc(strlen(str) + 1); + if (ai->ai_canonname == NULL) + return EAI_MEMORY; + strcpy(ai->ai_canonname, str); + } + return 0; +} + +static struct addrinfo * +get_ai(pai, afd, addr) + const struct addrinfo *pai; + const struct afd *afd; + const char *addr; +{ + char *p; + struct addrinfo *ai; + + ai = (struct addrinfo *)malloc(sizeof(struct addrinfo) + + (afd->a_socklen)); + if (ai == NULL) + return NULL; + + memcpy(ai, pai, sizeof(struct addrinfo)); + ai->ai_addr = (struct sockaddr *)(ai + 1); + memset(ai->ai_addr, 0, afd->a_socklen); +#ifdef HAVE_SOCKADDR_SA_LEN + ai->ai_addr->sa_len = afd->a_socklen; +#endif + ai->ai_addrlen = afd->a_socklen; + ai->ai_addr->sa_family = ai->ai_family = afd->a_af; + p = (char *)(ai->ai_addr); + memcpy(p + afd->a_off, addr, afd->a_addrlen); + return ai; +} + +static int +get_portmatch(ai, servname) + const struct addrinfo *ai; + const char *servname; +{ + + /* get_port does not touch first argument. when matchonly == 1. */ + return get_port((struct addrinfo *)ai, servname, 1); +} + +static int +get_port(ai, servname, matchonly) + struct addrinfo *ai; + const char *servname; + int matchonly; +{ + const char *proto; + struct servent *sp; + int port; + int allownumeric; + + if (servname == NULL) + return 0; + switch (ai->ai_family) { + case AF_INET: +#ifdef AF_INET6 + case AF_INET6: +#endif + break; + default: + return 0; + } + + switch (ai->ai_socktype) { + case SOCK_RAW: + return EAI_SERVICE; + case SOCK_DGRAM: + case SOCK_STREAM: + allownumeric = 1; + break; + case ANY: + allownumeric = 0; + break; + default: + return EAI_SOCKTYPE; + } + + if (str_isnumber(servname)) { + if (!allownumeric) + return EAI_SERVICE; + port = htons(atoi(servname)); + if (port < 0 || port > 65535) + return EAI_SERVICE; + } else { + switch (ai->ai_socktype) { + case SOCK_DGRAM: + proto = "udp"; + break; + case SOCK_STREAM: + proto = "tcp"; + break; + default: + proto = NULL; + break; + } + + if ((sp = getservbyname(servname, proto)) == NULL) + return EAI_SERVICE; + port = sp->s_port; + } + + if (!matchonly) { + switch (ai->ai_family) { + case AF_INET: + ((struct sockaddr_in *)ai->ai_addr)->sin_port = port; + break; +#ifdef INET6 + case AF_INET6: + ((struct sockaddr_in6 *)ai->ai_addr)->sin6_port = port; + break; +#endif + } + } + + return 0; +} + +static const struct afd * +find_afd(af) + int af; +{ + const struct afd *afd; + + if (af == PF_UNSPEC) + return NULL; + for (afd = afdl; afd->a_af; afd++) { + if (afd->a_af == af) + return afd; + } + return NULL; +} diff --git a/kame/kame/tcpdump/missing/getnameinfo.c b/kame/kame/tcpdump/missing/getnameinfo.c new file mode 100644 index 0000000000..f39770c1ad --- /dev/null +++ b/kame/kame/tcpdump/missing/getnameinfo.c @@ -0,0 +1,281 @@ +/* + * 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. + */ + +/* + * Issues to be discussed: + * - Thread safe-ness must be checked + * - Return values. There seems to be no standard for return value (RFC2553) + * but INRIA implementation returns EAI_xxx defined for getaddrinfo(). + * - RFC2553 says that we should raise error on short buffer. X/Open says + * we need to truncate the result. We obey RFC2553 (and X/Open should be + * modified). + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/missing/getnameinfo.c,v 1.9.2.2 2003/11/16 08:52:00 guy Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef NEED_ADDRINFO_H +#include "addrinfo.h" +#endif + +#define SUCCESS 0 +#define ANY 0 +#define YES 1 +#define NO 0 + +static struct afd { + int a_af; + int a_addrlen; + int a_socklen; + int a_off; +} afdl [] = { +#ifdef INET6 + {PF_INET6, sizeof(struct in6_addr), sizeof(struct sockaddr_in6), + offsetof(struct sockaddr_in6, sin6_addr)}, +#endif + {PF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in), + offsetof(struct sockaddr_in, sin_addr)}, + {0, 0, 0}, +}; + +struct sockinet { + u_char si_len; + u_char si_family; + u_short si_port; +}; + +#define ENI_NOSOCKET 0 +#define ENI_NOSERVNAME 1 +#define ENI_NOHOSTNAME 2 +#define ENI_MEMORY 3 +#define ENI_SYSTEM 4 +#define ENI_FAMILY 5 +#define ENI_SALEN 6 + +int +getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) + const struct sockaddr *sa; + size_t salen; + char *host; + size_t hostlen; + char *serv; + size_t servlen; + int flags; +{ + struct afd *afd; + struct servent *sp; + struct hostent *hp; + u_short port; + int family, i; + char *addr, *p; + u_int32_t v4a; + int h_error; + char numserv[512]; + char numaddr[512]; + + if (sa == NULL) + return ENI_NOSOCKET; + +#ifdef HAVE_SA_LEN /*XXX*/ + if (sa->sa_len != salen) + return ENI_SALEN; +#endif + + family = sa->sa_family; + for (i = 0; afdl[i].a_af; i++) + if (afdl[i].a_af == family) { + afd = &afdl[i]; + goto found; + } + return ENI_FAMILY; + + found: + if (salen != afd->a_socklen) + return ENI_SALEN; + + port = ((struct sockinet *)sa)->si_port; /* network byte order */ + addr = (char *)sa + afd->a_off; + + if (serv == NULL || servlen == 0) { + /* + * do nothing in this case. + * in case you are wondering if "&&" is more correct than + * "||" here: RFC2553 says that serv == NULL OR servlen == 0 + * means that the caller does not want the result. + */ + } else { + if (flags & NI_NUMERICSERV) + sp = NULL; + else { + sp = getservbyport(port, + (flags & NI_DGRAM) ? "udp" : "tcp"); + } + if (sp) { + if (strlen(sp->s_name) + 1 > servlen) + return ENI_MEMORY; + strcpy(serv, sp->s_name); + } else { + snprintf(numserv, sizeof(numserv), "%d", ntohs(port)); + if (strlen(numserv) + 1 > servlen) + return ENI_MEMORY; + strcpy(serv, numserv); + } + } + + switch (sa->sa_family) { + case AF_INET: + v4a = (u_int32_t) + ntohl(((struct sockaddr_in *)sa)->sin_addr.s_addr); + if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a)) + flags |= NI_NUMERICHOST; + v4a >>= IN_CLASSA_NSHIFT; + if (v4a == 0) + flags |= NI_NUMERICHOST; + break; +#ifdef INET6 + case AF_INET6: + { + struct sockaddr_in6 *sin6; + sin6 = (struct sockaddr_in6 *)sa; + switch (sin6->sin6_addr.s6_addr[0]) { + case 0x00: + if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) + ; + else if (IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr)) + ; + else + flags |= NI_NUMERICHOST; + break; + default: + if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { + flags |= NI_NUMERICHOST; + } + else if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) + flags |= NI_NUMERICHOST; + break; + } + } + break; +#endif + } + if (host == NULL || hostlen == 0) { + /* + * do nothing in this case. + * in case you are wondering if "&&" is more correct than + * "||" here: RFC2553 says that host == NULL OR hostlen == 0 + * means that the caller does not want the result. + */ + } else if (flags & NI_NUMERICHOST) { + /* NUMERICHOST and NAMEREQD conflicts with each other */ + if (flags & NI_NAMEREQD) + return ENI_NOHOSTNAME; + if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr)) + == NULL) + return ENI_SYSTEM; + if (strlen(numaddr) + 1 > hostlen) + return ENI_MEMORY; + strcpy(host, numaddr); +#if defined(INET6) && defined(NI_WITHSCOPEID) + if (afd->a_af == AF_INET6 && + (IN6_IS_ADDR_LINKLOCAL((struct in6_addr *)addr) || + IN6_IS_ADDR_MULTICAST((struct in6_addr *)addr)) && + ((struct sockaddr_in6 *)sa)->sin6_scope_id) { +#ifndef ALWAYS_WITHSCOPE + if (flags & NI_WITHSCOPEID) +#endif /* !ALWAYS_WITHSCOPE */ + { + char *ep = strchr(host, '\0'); + unsigned int ifindex = + ((struct sockaddr_in6 *)sa)->sin6_scope_id; + + *ep = SCOPE_DELIMITER; + if ((if_indextoname(ifindex, ep + 1)) == NULL) + /* XXX what should we do? */ + strncpy(ep + 1, "???", 3); + } + } +#endif /* INET6 */ + } else { +#ifdef USE_GETIPNODEBY + hp = getipnodebyaddr(addr, afd->a_addrlen, afd->a_af, &h_error); +#else + hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af); +#ifdef HAVE_H_ERRNO + h_error = h_errno; +#else + h_error = EINVAL; +#endif +#endif + + if (hp) { + if (flags & NI_NOFQDN) { + p = strchr(hp->h_name, '.'); + if (p) *p = '\0'; + } + if (strlen(hp->h_name) + 1 > hostlen) { +#ifdef USE_GETIPNODEBY + freehostent(hp); +#endif + return ENI_MEMORY; + } + strcpy(host, hp->h_name); +#ifdef USE_GETIPNODEBY + freehostent(hp); +#endif + } else { + if (flags & NI_NAMEREQD) + return ENI_NOHOSTNAME; + if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr)) + == NULL) + return ENI_NOHOSTNAME; + if (strlen(numaddr) + 1 > hostlen) + return ENI_MEMORY; + strcpy(host, numaddr); + } + } + return SUCCESS; +} diff --git a/kame/kame/tcpdump/missing/inet_aton.c b/kame/kame/tcpdump/missing/inet_aton.c new file mode 100644 index 0000000000..b12c105077 --- /dev/null +++ b/kame/kame/tcpdump/missing/inet_aton.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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 Kungliga Tekniska + * Högskolan and its contributors. + * + * 4. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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: inet_aton.c,v 1.4.2.2 2003/11/16 08:52:01 guy Exp $ */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/missing/inet_aton.c,v 1.4.2.2 2003/11/16 08:52:01 guy Exp $"; +#endif + +#include + +/* Minimal implementation of inet_aton. + * Cannot distinguish between failure and a local broadcast address. */ + +#ifndef INADDR_NONE +#define INADDR_NONE 0xffffffff +#endif + +int +inet_aton(const char *cp, struct in_addr *addr) +{ + addr->s_addr = inet_addr(cp); + return (addr->s_addr == INADDR_NONE) ? 0 : 1; +} diff --git a/kame/kame/tcpdump/missing/inet_ntop.c b/kame/kame/tcpdump/missing/inet_ntop.c new file mode 100644 index 0000000000..175face4a6 --- /dev/null +++ b/kame/kame/tcpdump/missing/inet_ntop.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 1999 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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 Kungliga Tekniska + * Högskolan and its contributors. + * + * 4. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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: inet_ntop.c,v 1.5.2.2 2003/11/16 08:52:01 guy Exp $ */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/missing/inet_ntop.c,v 1.5.2.2 2003/11/16 08:52:01 guy Exp $"; +#endif + +#include + +#include +#include + +/* + * + */ + +#ifndef INET_ADDRSTRLEN +#define INET_ADDRSTRLEN 16 +#endif + +static const char * +inet_ntop_v4 (const void *src, char *dst, size_t size) +{ + const char digits[] = "0123456789"; + int i; + struct in_addr *addr = (struct in_addr *)src; + u_long a = ntohl(addr->s_addr); + const char *orig_dst = dst; + + if (size < INET_ADDRSTRLEN) { + errno = ENOSPC; + return NULL; + } + for (i = 0; i < 4; ++i) { + int n = (a >> (24 - i * 8)) & 0xFF; + int non_zerop = 0; + + if (non_zerop || n / 100 > 0) { + *dst++ = digits[n / 100]; + n %= 100; + non_zerop = 1; + } + if (non_zerop || n / 10 > 0) { + *dst++ = digits[n / 10]; + n %= 10; + non_zerop = 1; + } + *dst++ = digits[n]; + if (i != 3) + *dst++ = '.'; + } + *dst++ = '\0'; + return orig_dst; +} + +const char * +inet_ntop(int af, const void *src, char *dst, size_t size) +{ + switch (af) { + case AF_INET : + return inet_ntop_v4 (src, dst, size); + default : + errno = EAFNOSUPPORT; + return NULL; + } +} diff --git a/kame/kame/tcpdump/missing/inet_pton.c b/kame/kame/tcpdump/missing/inet_pton.c new file mode 100644 index 0000000000..f1eecf1e99 --- /dev/null +++ b/kame/kame/tcpdump/missing/inet_pton.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 1999 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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 Kungliga Tekniska + * Högskolan and its contributors. + * + * 4. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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: inet_pton.c,v 1.4.2.2 2003/11/16 08:52:01 guy Exp $ */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/missing/inet_pton.c,v 1.4.2.2 2003/11/16 08:52:01 guy Exp $"; +#endif + +#include + +#include + +int +inet_pton(int af, const char *src, void *dst) +{ + if (af != AF_INET) { + errno = EAFNOSUPPORT; + return -1; + } + return inet_aton (src, dst); +} diff --git a/kame/kame/tcpdump/missing/resolv6.h b/kame/kame/tcpdump/missing/resolv6.h new file mode 100644 index 0000000000..ccee03e6c4 --- /dev/null +++ b/kame/kame/tcpdump/missing/resolv6.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 1999 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. + */ + +/* + * Resolver options for IPv6. + * XXX: this should be in an offical include file. There may be conflicts... + */ +#ifndef HAVE_RES_USE_INET6 +#define RES_USE_INET6 0x80000000 /* use/map IPv6 in gethostbyname() */ +#endif diff --git a/kame/kame/tcpdump/missing/resolv_ext.h b/kame/kame/tcpdump/missing/resolv_ext.h new file mode 100644 index 0000000000..92c531d860 --- /dev/null +++ b/kame/kame/tcpdump/missing/resolv_ext.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 1999 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 MAXRESOLVSORT /* XXX */ +#define MAXRESOLVSORT 10 /* number of net to sort on */ +#endif + +#ifndef HAVE_RES_STATE_EXT +struct __res_state_ext { + struct sockaddr_storage nsaddr_list[MAXNS]; + struct { + int af; /* address family for addr, mask */ + union { + struct in_addr ina; +#ifdef INET6 + struct in6_addr in6a; +#endif + } addr, mask; + } sort_list[MAXRESOLVSORT]; +}; +#endif + +extern struct __res_state_ext _res_ext; diff --git a/kame/kame/tcpdump/missing/snprintf.c b/kame/kame/tcpdump/missing/snprintf.c new file mode 100644 index 0000000000..c569bb8ae3 --- /dev/null +++ b/kame/kame/tcpdump/missing/snprintf.c @@ -0,0 +1,632 @@ +/* + * Copyright (c) 1995-1999 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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: snprintf.c,v 1.6.2.2 2003/11/16 08:52:02 guy Exp $ */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/missing/snprintf.c,v 1.6.2.2 2003/11/16 08:52:02 guy Exp $"; +#endif + +#include +#include +#include +#include +#include +#include + +#include + +enum format_flags { + minus_flag = 1, + plus_flag = 2, + space_flag = 4, + alternate_flag = 8, + zero_flag = 16 +}; + +/* + * Common state + */ + +struct state { + unsigned char *str; + unsigned char *s; + unsigned char *theend; + size_t sz; + size_t max_sz; + int (*append_char)(struct state *, unsigned char); + int (*reserve)(struct state *, size_t); + /* XXX - methods */ +}; + +#ifndef HAVE_VSNPRINTF +static int +sn_reserve (struct state *state, size_t n) +{ + return state->s + n > state->theend; +} + +static int +sn_append_char (struct state *state, unsigned char c) +{ + if (sn_reserve (state, 1)) { + return 1; + } else { + *state->s++ = c; + return 0; + } +} +#endif + +#if 0 +static int +as_reserve (struct state *state, size_t n) +{ + if (state->s + n > state->theend) { + int off = state->s - state->str; + unsigned char *tmp; + + if (state->max_sz && state->sz >= state->max_sz) + return 1; + + state->sz = max(state->sz * 2, state->sz + n); + if (state->max_sz) + state->sz = min(state->sz, state->max_sz); + tmp = realloc (state->str, state->sz); + if (tmp == NULL) + return 1; + state->str = tmp; + state->s = state->str + off; + state->theend = state->str + state->sz - 1; + } + return 0; +} + +static int +as_append_char (struct state *state, unsigned char c) +{ + if(as_reserve (state, 1)) + return 1; + else { + *state->s++ = c; + return 0; + } +} +#endif + +static int +append_number(struct state *state, + unsigned long num, unsigned base, char *rep, + int width, int prec, int flags, int minusp) +{ + int len = 0; + int i; + + /* given precision, ignore zero flag */ + if(prec != -1) + flags &= ~zero_flag; + else + prec = 1; + /* zero value with zero precision -> "" */ + if(prec == 0 && num == 0) + return 0; + do{ + if((*state->append_char)(state, rep[num % base])) + return 1; + len++; + num /= base; + }while(num); + prec -= len; + /* pad with prec zeros */ + while(prec-- > 0){ + if((*state->append_char)(state, '0')) + return 1; + len++; + } + /* add length of alternate prefix (added later) to len */ + if(flags & alternate_flag && (base == 16 || base == 8)) + len += base / 8; + /* pad with zeros */ + if(flags & zero_flag){ + width -= len; + if(minusp || (flags & space_flag) || (flags & plus_flag)) + width--; + while(width-- > 0){ + if((*state->append_char)(state, '0')) + return 1; + len++; + } + } + /* add alternate prefix */ + if(flags & alternate_flag && (base == 16 || base == 8)){ + if(base == 16) + if((*state->append_char)(state, rep[10] + 23)) /* XXX */ + return 1; + if((*state->append_char)(state, '0')) + return 1; + } + /* add sign */ + if(minusp){ + if((*state->append_char)(state, '-')) + return 1; + len++; + } else if(flags & plus_flag) { + if((*state->append_char)(state, '+')) + return 1; + len++; + } else if(flags & space_flag) { + if((*state->append_char)(state, ' ')) + return 1; + len++; + } + if(flags & minus_flag) + /* swap before padding with spaces */ + for(i = 0; i < len / 2; i++){ + char c = state->s[-i-1]; + state->s[-i-1] = state->s[-len+i]; + state->s[-len+i] = c; + } + width -= len; + while(width-- > 0){ + if((*state->append_char)(state, ' ')) + return 1; + len++; + } + if(!(flags & minus_flag)) + /* swap after padding with spaces */ + for(i = 0; i < len / 2; i++){ + char c = state->s[-i-1]; + state->s[-i-1] = state->s[-len+i]; + state->s[-len+i] = c; + } + + return 0; +} + +static int +append_string (struct state *state, + unsigned char *arg, + int width, + int prec, + int flags) +{ + if(prec != -1) + width -= prec; + else + width -= strlen((char *)arg); + if(!(flags & minus_flag)) + while(width-- > 0) + if((*state->append_char) (state, ' ')) + return 1; + if (prec != -1) { + while (*arg && prec--) + if ((*state->append_char) (state, *arg++)) + return 1; + } else { + while (*arg) + if ((*state->append_char) (state, *arg++)) + return 1; + } + if(flags & minus_flag) + while(width-- > 0) + if((*state->append_char) (state, ' ')) + return 1; + return 0; +} + +static int +append_char(struct state *state, + unsigned char arg, + int width, + int flags) +{ + while(!(flags & minus_flag) && --width > 0) + if((*state->append_char) (state, ' ')) + return 1; + + if((*state->append_char) (state, arg)) + return 1; + while((flags & minus_flag) && --width > 0) + if((*state->append_char) (state, ' ')) + return 1; + + return 0; +} + +/* + * This can't be made into a function... + */ + +#define PARSE_INT_FORMAT(res, arg, unsig) \ +if (long_flag) \ + res = (unsig long)va_arg(arg, unsig long); \ +else if (short_flag) \ + res = (unsig short)va_arg(arg, unsig int); \ +else \ + res = (unsig int)va_arg(arg, unsig int) + +/* + * zyxprintf - return 0 or -1 + */ + +static int +xyzprintf (struct state *state, const char *char_format, va_list ap) +{ + const unsigned char *format = (const unsigned char *)char_format; + unsigned char c; + + while((c = *format++)) { + if (c == '%') { + int flags = 0; + int width = 0; + int prec = -1; + int long_flag = 0; + int short_flag = 0; + + /* flags */ + while((c = *format++)){ + if(c == '-') + flags |= minus_flag; + else if(c == '+') + flags |= plus_flag; + else if(c == ' ') + flags |= space_flag; + else if(c == '#') + flags |= alternate_flag; + else if(c == '0') + flags |= zero_flag; + else + break; + } + + if((flags & space_flag) && (flags & plus_flag)) + flags ^= space_flag; + + if((flags & minus_flag) && (flags & zero_flag)) + flags ^= zero_flag; + + /* width */ + if (isdigit(c)) + do { + width = width * 10 + c - '0'; + c = *format++; + } while(isdigit(c)); + else if(c == '*') { + width = va_arg(ap, int); + c = *format++; + } + + /* precision */ + if (c == '.') { + prec = 0; + c = *format++; + if (isdigit(c)) + do { + prec = prec * 10 + c - '0'; + c = *format++; + } while(isdigit(c)); + else if (c == '*') { + prec = va_arg(ap, int); + c = *format++; + } + } + + /* size */ + + if (c == 'h') { + short_flag = 1; + c = *format++; + } else if (c == 'l') { + long_flag = 1; + c = *format++; + } + + switch (c) { + case 'c' : + if(append_char(state, va_arg(ap, int), width, flags)) + return -1; + break; + case 's' : + if (append_string(state, + va_arg(ap, unsigned char*), + width, + prec, + flags)) + return -1; + break; + case 'd' : + case 'i' : { + long arg; + unsigned long num; + int minusp = 0; + + PARSE_INT_FORMAT(arg, ap, signed); + + if (arg < 0) { + minusp = 1; + num = -arg; + } else + num = arg; + + if (append_number (state, num, 10, "0123456789", + width, prec, flags, minusp)) + return -1; + break; + } + case 'u' : { + unsigned long arg; + + PARSE_INT_FORMAT(arg, ap, unsigned); + + if (append_number (state, arg, 10, "0123456789", + width, prec, flags, 0)) + return -1; + break; + } + case 'o' : { + unsigned long arg; + + PARSE_INT_FORMAT(arg, ap, unsigned); + + if (append_number (state, arg, 010, "01234567", + width, prec, flags, 0)) + return -1; + break; + } + case 'x' : { + unsigned long arg; + + PARSE_INT_FORMAT(arg, ap, unsigned); + + if (append_number (state, arg, 0x10, "0123456789abcdef", + width, prec, flags, 0)) + return -1; + break; + } + case 'X' :{ + unsigned long arg; + + PARSE_INT_FORMAT(arg, ap, unsigned); + + if (append_number (state, arg, 0x10, "0123456789ABCDEF", + width, prec, flags, 0)) + return -1; + break; + } + case 'p' : { + unsigned long arg = (unsigned long)va_arg(ap, void*); + + if (append_number (state, arg, 0x10, "0123456789ABCDEF", + width, prec, flags, 0)) + return -1; + break; + } + case 'n' : { + int *arg = va_arg(ap, int*); + *arg = state->s - state->str; + break; + } + case '\0' : + --format; + /* FALLTHROUGH */ + case '%' : + if ((*state->append_char)(state, c)) + return -1; + break; + default : + if ( (*state->append_char)(state, '%') + || (*state->append_char)(state, c)) + return -1; + break; + } + } else + if ((*state->append_char) (state, c)) + return -1; + } + return 0; +} + +#ifndef HAVE_SNPRINTF +int +snprintf (char *str, size_t sz, const char *format, ...) +{ + va_list args; + int ret; + + va_start(args, format); + ret = vsnprintf (str, sz, format, args); + +#ifdef PARANOIA + { + int ret2; + char *tmp; + + tmp = malloc (sz); + if (tmp == NULL) + abort (); + + ret2 = vsprintf (tmp, format, args); + if (ret != ret2 || strcmp(str, tmp)) + abort (); + free (tmp); + } +#endif + + va_end(args); + return ret; +} +#endif + +#if 0 +#ifndef HAVE_ASPRINTF +int +asprintf (char **ret, const char *format, ...) +{ + va_list args; + int val; + + va_start(args, format); + val = vasprintf (ret, format, args); + +#ifdef PARANOIA + { + int ret2; + char *tmp; + tmp = malloc (val + 1); + if (tmp == NULL) + abort (); + + ret2 = vsprintf (tmp, format, args); + if (val != ret2 || strcmp(*ret, tmp)) + abort (); + free (tmp); + } +#endif + + va_end(args); + return val; +} +#endif + +#ifndef HAVE_ASNPRINTF +int +asnprintf (char **ret, size_t max_sz, const char *format, ...) +{ + va_list args; + int val; + + va_start(args, format); + val = vasnprintf (ret, max_sz, format, args); + +#ifdef PARANOIA + { + int ret2; + char *tmp; + tmp = malloc (val + 1); + if (tmp == NULL) + abort (); + + ret2 = vsprintf (tmp, format, args); + if (val != ret2 || strcmp(*ret, tmp)) + abort (); + free (tmp); + } +#endif + + va_end(args); + return val; +} +#endif + +#ifndef HAVE_VASPRINTF +int +vasprintf (char **ret, const char *format, va_list args) +{ + return vasnprintf (ret, 0, format, args); +} +#endif + + +#ifndef HAVE_VASNPRINTF +int +vasnprintf (char **ret, size_t max_sz, const char *format, va_list args) +{ + int st; + size_t len; + struct state state; + + state.max_sz = max_sz; + state.sz = 1; + state.str = malloc(state.sz); + if (state.str == NULL) { + *ret = NULL; + return -1; + } + state.s = state.str; + state.theend = state.s + state.sz - 1; + state.append_char = as_append_char; + state.reserve = as_reserve; + + st = xyzprintf (&state, format, args); + if (st) { + free (state.str); + *ret = NULL; + return -1; + } else { + char *tmp; + + *state.s = '\0'; + len = state.s - state.str; + tmp = realloc (state.str, len+1); + if (tmp == NULL) { + free (state.str); + *ret = NULL; + return -1; + } + *ret = tmp; + return len; + } +} +#endif +#endif + +#ifndef HAVE_VSNPRINTF +int +vsnprintf (char *str, size_t sz, const char *format, va_list args) +{ + struct state state; + int ret; + unsigned char *ustr = (unsigned char *)str; + + state.max_sz = 0; + state.sz = sz; + state.str = ustr; + state.s = ustr; + state.theend = ustr + sz - 1; + state.append_char = sn_append_char; + state.reserve = sn_reserve; + + ret = xyzprintf (&state, format, args); + *state.s = '\0'; + if (ret) + return sz; + else + return state.s - state.str; +} +#endif + diff --git a/kame/kame/tcpdump/missing/sockstorage.h b/kame/kame/tcpdump/missing/sockstorage.h new file mode 100644 index 0000000000..e7333289f1 --- /dev/null +++ b/kame/kame/tcpdump/missing/sockstorage.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 1999 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. + */ +struct sockaddr_storage { +#ifdef HAVE_SOCKADDR_SA_LEN + u_int8_t ss_len; + u_int8_t ss_family; + u_int8_t fill[126]; +#else + u_int8_t ss_family; + u_int8_t fill[127]; +#endif /* HAVE_SOCKADDR_SA_LEN */ +}; diff --git a/kame/kame/tcpdump/missing/strdup.c b/kame/kame/tcpdump/missing/strdup.c new file mode 100644 index 0000000000..103c3b26f6 --- /dev/null +++ b/kame/kame/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 +#include +#include + +#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/kame/kame/tcpdump/missing/strlcat.c b/kame/kame/tcpdump/missing/strlcat.c new file mode 100644 index 0000000000..7e9cdbab0b --- /dev/null +++ b/kame/kame/tcpdump/missing/strlcat.c @@ -0,0 +1,76 @@ +/* $NetBSD: strlcat.c,v 1.5 1999/09/20 04:39:47 lukem Exp $ */ +/* from OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp */ + +/* + * Copyright (c) 1998 Todd C. Miller + * 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 name of the author 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 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. + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/missing/strlcat.c,v 1.3.2.2 2003/11/16 08:52:03 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include + +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t +strlcat(char *dst, const char *src, size_t siz) +{ + register char *d = dst; + register const char *s = src; + register size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (*d != '\0' && n-- != 0) + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} diff --git a/kame/kame/tcpdump/missing/strlcpy.c b/kame/kame/tcpdump/missing/strlcpy.c new file mode 100644 index 0000000000..12747dd64d --- /dev/null +++ b/kame/kame/tcpdump/missing/strlcpy.c @@ -0,0 +1,73 @@ +/* $NetBSD: strlcpy.c,v 1.5 1999/09/20 04:39:47 lukem Exp $ */ +/* from OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp */ + +/* + * Copyright (c) 1998 Todd C. Miller + * 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 name of the author 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 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. + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/missing/strlcpy.c,v 1.3.2.2 2003/11/16 08:52:03 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t +strlcpy(char *dst, const char *src, size_t siz) +{ + register char *d = dst; + register const char *s = src; + register size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} diff --git a/kame/kame/tcpdump/missing/strsep.c b/kame/kame/tcpdump/missing/strsep.c new file mode 100644 index 0000000000..19fb6b2c01 --- /dev/null +++ b/kame/kame/tcpdump/missing/strsep.c @@ -0,0 +1,83 @@ +/*- + * Copyright (c) 1990, 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/strsep.c,v 1.3 2003/03/25 08:33:48 guy Exp $ (LBL)"; +#endif /* LIBC_SCCS and not lint */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include + +/* + * Get next token from string *stringp, where tokens are possibly-empty + * strings separated by characters from delim. + * + * Writes NULs into the string at *stringp to end tokens. + * delim need not remain constant from call to call. + * On return, *stringp points past the last NUL written (if there might + * be further tokens), or is NULL (if there are definitely no more tokens). + * + * If *stringp is NULL, strsep returns NULL. + */ +char * +strsep(char **stringp, const char *delim) +{ + register char *s; + register const char *spanp; + register int c, sc; + char *tok; + + if ((s = *stringp) == NULL) + return (NULL); + for (tok = s;;) { + c = *s++; + spanp = delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + *stringp = s; + return (tok); + } + } while (sc != 0); + } + /* NOTREACHED */ +} diff --git a/kame/kame/tcpdump/nameser.h b/kame/kame/tcpdump/nameser.h new file mode 100644 index 0000000000..2b94ee3b75 --- /dev/null +++ b/kame/kame/tcpdump/nameser.h @@ -0,0 +1,295 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/nameser.h,v 1.14 2003/11/05 06:02:59 guy Exp $ (LBL) */ +/* + * Copyright (c) 1983, 1989, 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. + * + * @(#)nameser.h 8.2 (Berkeley) 2/16/94 + * - + * Portions Copyright (c) 1993 by Digital Equipment Corporation. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies, and that + * the name of Digital Equipment Corporation not be used in advertising or + * publicity pertaining to distribution of the document or software without + * specific, written prior permission. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT + * 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. + * - + * --Copyright-- + */ + +#ifndef _NAMESER_H_ +#define _NAMESER_H_ + +#include + +/* + * Define constants based on rfc883 + */ +#define PACKETSZ 512 /* maximum packet size */ +#define MAXDNAME 256 /* maximum domain name */ +#define MAXCDNAME 255 /* maximum compressed domain name */ +#define MAXLABEL 63 /* maximum length of domain label */ + /* Number of bytes of fixed size data in query structure */ +#define QFIXEDSZ 4 + /* number of bytes of fixed size data in resource record */ +#define RRFIXEDSZ 10 + +/* + * Internet nameserver port number + */ +#define NAMESERVER_PORT 53 +#define MULTICASTDNS_PORT 5353 + +/* + * Currently defined opcodes + */ +#define QUERY 0x0 /* standard query */ +#define IQUERY 0x1 /* inverse query */ +#define STATUS 0x2 /* nameserver status query */ +#if 0 +#define xxx 0x3 /* 0x3 reserved */ +#endif + /* non standard - supports ALLOW_UPDATES stuff from Mike Schwartz */ +#define UPDATEA 0x9 /* add resource record */ +#define UPDATED 0xa /* delete a specific resource record */ +#define UPDATEDA 0xb /* delete all named resource record */ +#define UPDATEM 0xc /* modify a specific resource record */ +#define UPDATEMA 0xd /* modify all named resource record */ + +#define ZONEINIT 0xe /* initial zone transfer */ +#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 */ +#define FORMERR 1 /* format error */ +#define SERVFAIL 2 /* server failure */ +#define NXDOMAIN 3 /* non existent domain */ +#define NOTIMP 4 /* not implemented */ +#define REFUSED 5 /* query refused */ + /* non standard */ +#define NOCHANGE 0xf /* update failed to change db */ + +/* + * Type values for resources and queries + */ +#define T_A 1 /* host address */ +#define T_NS 2 /* authoritative server */ +#define T_MD 3 /* mail destination */ +#define T_MF 4 /* mail forwarder */ +#define T_CNAME 5 /* connonical name */ +#define T_SOA 6 /* start of authority zone */ +#define T_MB 7 /* mailbox domain name */ +#define T_MG 8 /* mail group member */ +#define T_MR 9 /* mail rename name */ +#define T_NULL 10 /* null resource record */ +#define T_WKS 11 /* well known service */ +#define T_PTR 12 /* domain name pointer */ +#define T_HINFO 13 /* host information */ +#define T_MINFO 14 /* mailbox information */ +#define T_MX 15 /* mail routing information */ +#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 */ +#define T_ANY 255 /* wildcard match */ + +/* + * Values for class field + */ + +#define C_IN 1 /* the arpa internet */ +#define C_CHAOS 3 /* for chaos net (MIT) */ +#define C_HS 4 /* for Hesiod name server (MIT) (XXX) */ + /* Query class values which do not appear in resource records */ +#define C_ANY 255 /* wildcard match */ +#define C_CACHE_FLUSH 0x8000 /* mDNS cache flush flag */ + +/* + * Status return codes for T_UNSPEC conversion routines + */ +#define CONV_SUCCESS 0 +#define CONV_OVERFLOW -1 +#define CONV_BADFMT -2 +#define CONV_BADCKSUM -3 +#define CONV_BADBUFLEN -4 + +/* + * Structure for query header. + */ +typedef struct { + u_int16_t id; /* query identification number */ + u_int8_t flags1; /* first byte of flags */ + u_int8_t flags2; /* second byte of flags */ + u_int16_t qdcount; /* number of question entries */ + u_int16_t ancount; /* number of answer entries */ + u_int16_t nscount; /* number of authority entries */ + u_int16_t arcount; /* number of resource entries */ +} HEADER; + +/* + * Macros for subfields of flag fields. + */ +#define DNS_QR(np) ((np)->flags1 & 0x80) /* response flag */ +#define DNS_OPCODE(np) ((((np)->flags1) >> 3) & 0xF) /* purpose of message */ +#define DNS_AA(np) ((np)->flags1 & 0x04) /* authoritative answer */ +#define DNS_TC(np) ((np)->flags1 & 0x02) /* truncated message */ +#define DNS_RD(np) ((np)->flags1 & 0x01) /* recursion desired */ + +#define DNS_RA(np) ((np)->flags2 & 0x80) /* recursion available */ +#define DNS_AD(np) ((np)->flags2 & 0x20) /* authentic data from named */ +#define DNS_CD(np) ((np)->flags2 & 0x10) /* checking disabled by resolver */ +#define DNS_RCODE(np) ((np)->flags2 & 0xF) /* response code */ + +/* + * Defines for handling compressed domain names, EDNS0 labels, etc. + */ +#define INDIR_MASK 0xc0 /* 11.... */ +#define EDNS0_MASK 0x40 /* 01.... */ +# define EDNS0_ELT_BITLABEL 0x01 + +/* + * Structure for passing resource records around. + */ +struct rrec { + int16_t r_zone; /* zone number */ + int16_t r_class; /* class number */ + int16_t r_type; /* type number */ + u_int32_t r_ttl; /* time to live */ + int r_size; /* size of data area */ + char *r_data; /* pointer to data */ +}; + +/* + * Inline versions of get/put short/long. Pointer is advanced. + * We also assume that a "u_int16_t" holds 2 "chars" + * and that a "u_int32_t" holds 4 "chars". + * + * These macros demonstrate the property of C whereby it can be + * portable or it can be elegant but never both. + */ +#define GETSHORT(s, cp) { \ + register u_char *t_cp = (u_char *)(cp); \ + (s) = ((u_int16_t)t_cp[0] << 8) | (u_int16_t)t_cp[1]; \ + (cp) += 2; \ +} + +#define GETLONG(l, cp) { \ + register u_char *t_cp = (u_char *)(cp); \ + (l) = (((u_int32_t)t_cp[0]) << 24) \ + | (((u_int32_t)t_cp[1]) << 16) \ + | (((u_int32_t)t_cp[2]) << 8) \ + | (((u_int32_t)t_cp[3])); \ + (cp) += 4; \ +} + +#define PUTSHORT(s, cp) { \ + register u_int16_t t_s = (u_int16_t)(s); \ + register u_char *t_cp = (u_char *)(cp); \ + *t_cp++ = t_s >> 8; \ + *t_cp = t_s; \ + (cp) += 2; \ +} + +/* + * Warning: PUTLONG --no-longer-- destroys its first argument. if you + * were depending on this "feature", you will lose. + */ +#define PUTLONG(l, cp) { \ + register u_int32_t t_l = (u_int32_t)(l); \ + register u_char *t_cp = (u_char *)(cp); \ + *t_cp++ = t_l >> 24; \ + *t_cp++ = t_l >> 16; \ + *t_cp++ = t_l >> 8; \ + *t_cp = t_l; \ + (cp) += 4; \ +} + +#endif /* !_NAMESER_H_ */ diff --git a/kame/kame/tcpdump/netbios.h b/kame/kame/tcpdump/netbios.h index ebc80e1db3..34abebae8e 100644 --- a/kame/kame/tcpdump/netbios.h +++ b/kame/kame/tcpdump/netbios.h @@ -1,7 +1,7 @@ /* * NETBIOS protocol formats * - * @(#) $Header: netbios.h,v 1.1 94/06/09 11:47:15 mccanne Exp $ + * @(#) $Header: /tcpdump/master/tcpdump/netbios.h,v 1.3 2002/12/11 07:13:55 guy Exp $ */ struct p8022Hdr { diff --git a/kame/kame/tcpdump/nfs.h b/kame/kame/tcpdump/nfs.h new file mode 100644 index 0000000000..3d47c7d3d9 --- /dev/null +++ b/kame/kame/tcpdump/nfs.h @@ -0,0 +1,453 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/nfs.h,v 1.7 2002/12/11 07:13:55 guy Exp $ (LBL) */ +/* $NetBSD: nfs.h,v 1.1 1996/05/23 22:49:53 fvdl Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Rick Macklem at The University of Guelph. + * + * 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. + * + * @(#)nfsproto.h 8.2 (Berkeley) 3/30/95 + */ + +/* + * nfs definitions as per the Version 2 and 3 specs + */ + +/* + * Constants as defined in the Sun NFS Version 2 and 3 specs. + * "NFS: Network File System Protocol Specification" RFC1094 + * and in the "NFS: Network File System Version 3 Protocol + * Specification" + */ + +#define NFS_PORT 2049 +#define NFS_PROG 100003 +#define NFS_VER2 2 +#define NFS_VER3 3 +#define NFS_V2MAXDATA 8192 +#define NFS_MAXDGRAMDATA 16384 +#define NFS_MAXDATA 32768 +#define NFS_MAXPATHLEN 1024 +#define NFS_MAXNAMLEN 255 +#define NFS_MAXPKTHDR 404 +#define NFS_MAXPACKET (NFS_MAXPKTHDR + NFS_MAXDATA) +#define NFS_MINPACKET 20 +#define NFS_FABLKSIZE 512 /* Size in bytes of a block wrt fa_blocks */ + +/* Stat numbers for rpc returns (version 2 and 3) */ +#define NFS_OK 0 +#define NFSERR_PERM 1 +#define NFSERR_NOENT 2 +#define NFSERR_IO 5 +#define NFSERR_NXIO 6 +#define NFSERR_ACCES 13 +#define NFSERR_EXIST 17 +#define NFSERR_XDEV 18 /* Version 3 only */ +#define NFSERR_NODEV 19 +#define NFSERR_NOTDIR 20 +#define NFSERR_ISDIR 21 +#define NFSERR_INVAL 22 /* Version 3 only */ +#define NFSERR_FBIG 27 +#define NFSERR_NOSPC 28 +#define NFSERR_ROFS 30 +#define NFSERR_MLINK 31 /* Version 3 only */ +#define NFSERR_NAMETOL 63 +#define NFSERR_NOTEMPTY 66 +#define NFSERR_DQUOT 69 +#define NFSERR_STALE 70 +#define NFSERR_REMOTE 71 /* Version 3 only */ +#define NFSERR_WFLUSH 99 /* Version 2 only */ +#define NFSERR_BADHANDLE 10001 /* The rest Version 3 only */ +#define NFSERR_NOT_SYNC 10002 +#define NFSERR_BAD_COOKIE 10003 +#define NFSERR_NOTSUPP 10004 +#define NFSERR_TOOSMALL 10005 +#define NFSERR_SERVERFAULT 10006 +#define NFSERR_BADTYPE 10007 +#define NFSERR_JUKEBOX 10008 +#define NFSERR_TRYLATER NFSERR_JUKEBOX +#define NFSERR_STALEWRITEVERF 30001 /* Fake return for nfs_commit() */ + +#define NFSERR_RETVOID 0x20000000 /* Return void, not error */ +#define NFSERR_AUTHERR 0x40000000 /* Mark an authentication error */ +#define NFSERR_RETERR 0x80000000 /* Mark an error return for V3 */ + +/* Sizes in bytes of various nfs rpc components */ +#define NFSX_UNSIGNED 4 + +/* specific to NFS Version 2 */ +#define NFSX_V2FH 32 +#define NFSX_V2FATTR 68 +#define NFSX_V2SATTR 32 +#define NFSX_V2COOKIE 4 +#define NFSX_V2STATFS 20 + +/* specific to NFS Version 3 */ +#if 0 +#define NFSX_V3FH (sizeof (fhandle_t)) /* size this server uses */ +#endif +#define NFSX_V3FHMAX 64 /* max. allowed by protocol */ +#define NFSX_V3FATTR 84 +#define NFSX_V3SATTR 60 /* max. all fields filled in */ +#define NFSX_V3SRVSATTR (sizeof (struct nfsv3_sattr)) +#define NFSX_V3POSTOPATTR (NFSX_V3FATTR + NFSX_UNSIGNED) +#define NFSX_V3WCCDATA (NFSX_V3POSTOPATTR + 8 * NFSX_UNSIGNED) +#define NFSX_V3COOKIEVERF 8 +#define NFSX_V3WRITEVERF 8 +#define NFSX_V3CREATEVERF 8 +#define NFSX_V3STATFS 52 +#define NFSX_V3FSINFO 48 +#define NFSX_V3PATHCONF 24 + +/* variants for both versions */ +#define NFSX_FH(v3) ((v3) ? (NFSX_V3FHMAX + NFSX_UNSIGNED) : \ + NFSX_V2FH) +#define NFSX_SRVFH(v3) ((v3) ? NFSX_V3FH : NFSX_V2FH) +#define NFSX_FATTR(v3) ((v3) ? NFSX_V3FATTR : NFSX_V2FATTR) +#define NFSX_PREOPATTR(v3) ((v3) ? (7 * NFSX_UNSIGNED) : 0) +#define NFSX_POSTOPATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : 0) +#define NFSX_POSTOPORFATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : \ + NFSX_V2FATTR) +#define NFSX_WCCDATA(v3) ((v3) ? NFSX_V3WCCDATA : 0) +#define NFSX_WCCORFATTR(v3) ((v3) ? NFSX_V3WCCDATA : NFSX_V2FATTR) +#define NFSX_SATTR(v3) ((v3) ? NFSX_V3SATTR : NFSX_V2SATTR) +#define NFSX_COOKIEVERF(v3) ((v3) ? NFSX_V3COOKIEVERF : 0) +#define NFSX_WRITEVERF(v3) ((v3) ? NFSX_V3WRITEVERF : 0) +#define NFSX_READDIR(v3) ((v3) ? (5 * NFSX_UNSIGNED) : \ + (2 * NFSX_UNSIGNED)) +#define NFSX_STATFS(v3) ((v3) ? NFSX_V3STATFS : NFSX_V2STATFS) + +/* nfs rpc procedure numbers (before version mapping) */ +#define NFSPROC_NULL 0 +#define NFSPROC_GETATTR 1 +#define NFSPROC_SETATTR 2 +#define NFSPROC_LOOKUP 3 +#define NFSPROC_ACCESS 4 +#define NFSPROC_READLINK 5 +#define NFSPROC_READ 6 +#define NFSPROC_WRITE 7 +#define NFSPROC_CREATE 8 +#define NFSPROC_MKDIR 9 +#define NFSPROC_SYMLINK 10 +#define NFSPROC_MKNOD 11 +#define NFSPROC_REMOVE 12 +#define NFSPROC_RMDIR 13 +#define NFSPROC_RENAME 14 +#define NFSPROC_LINK 15 +#define NFSPROC_READDIR 16 +#define NFSPROC_READDIRPLUS 17 +#define NFSPROC_FSSTAT 18 +#define NFSPROC_FSINFO 19 +#define NFSPROC_PATHCONF 20 +#define NFSPROC_COMMIT 21 + +/* And leasing (nqnfs) procedure numbers (must be last) */ +#define NQNFSPROC_GETLEASE 22 +#define NQNFSPROC_VACATED 23 +#define NQNFSPROC_EVICTED 24 + +#define NFSPROC_NOOP 25 +#define NFS_NPROCS 26 + +/* Actual Version 2 procedure numbers */ +#define NFSV2PROC_NULL 0 +#define NFSV2PROC_GETATTR 1 +#define NFSV2PROC_SETATTR 2 +#define NFSV2PROC_NOOP 3 +#define NFSV2PROC_ROOT NFSV2PROC_NOOP /* Obsolete */ +#define NFSV2PROC_LOOKUP 4 +#define NFSV2PROC_READLINK 5 +#define NFSV2PROC_READ 6 +#define NFSV2PROC_WRITECACHE NFSV2PROC_NOOP /* Obsolete */ +#define NFSV2PROC_WRITE 8 +#define NFSV2PROC_CREATE 9 +#define NFSV2PROC_REMOVE 10 +#define NFSV2PROC_RENAME 11 +#define NFSV2PROC_LINK 12 +#define NFSV2PROC_SYMLINK 13 +#define NFSV2PROC_MKDIR 14 +#define NFSV2PROC_RMDIR 15 +#define NFSV2PROC_READDIR 16 +#define NFSV2PROC_STATFS 17 + +/* + * Constants used by the Version 3 protocol for various RPCs + */ +#define NFSV3SATTRTIME_DONTCHANGE 0 +#define NFSV3SATTRTIME_TOSERVER 1 +#define NFSV3SATTRTIME_TOCLIENT 2 + +#define NFSV3ATTRTIME_NMODES 3 + +#define NFSV3ACCESS_READ 0x01 +#define NFSV3ACCESS_LOOKUP 0x02 +#define NFSV3ACCESS_MODIFY 0x04 +#define NFSV3ACCESS_EXTEND 0x08 +#define NFSV3ACCESS_DELETE 0x10 +#define NFSV3ACCESS_EXECUTE 0x20 + +#define NFSV3WRITE_UNSTABLE 0 +#define NFSV3WRITE_DATASYNC 1 +#define NFSV3WRITE_FILESYNC 2 + +#define NFSV3WRITE_NMODES 3 + +#define NFSV3CREATE_UNCHECKED 0 +#define NFSV3CREATE_GUARDED 1 +#define NFSV3CREATE_EXCLUSIVE 2 + +#define NFSV3CREATE_NMODES 3 + +#define NFSV3FSINFO_LINK 0x01 +#define NFSV3FSINFO_SYMLINK 0x02 +#define NFSV3FSINFO_HOMOGENEOUS 0x08 +#define NFSV3FSINFO_CANSETTIME 0x10 + +/* Conversion macros */ +#define vtonfsv2_mode(t,m) \ + txdr_unsigned(((t) == VFIFO) ? MAKEIMODE(VCHR, (m)) : \ + MAKEIMODE((t), (m))) +#define vtonfsv3_mode(m) txdr_unsigned((m) & 07777) +#define nfstov_mode(a) (fxdr_unsigned(u_int16_t, (a))&07777) +#define vtonfsv2_type(a) txdr_unsigned(nfsv2_type[((int32_t)(a))]) +#define vtonfsv3_type(a) txdr_unsigned(nfsv3_type[((int32_t)(a))]) +#define nfsv2tov_type(a) nv2tov_type[fxdr_unsigned(u_int32_t,(a))&0x7] +#define nfsv3tov_type(a) nv3tov_type[fxdr_unsigned(u_int32_t,(a))&0x7] + +/* File types */ +typedef enum { NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5, + NFSOCK=6, NFFIFO=7 } nfs_type; + +/* Structs for common parts of the rpc's */ +/* + * File Handle (32 bytes for version 2), variable up to 64 for version 3. + * File Handles of up to NFS_SMALLFH in size are stored directly in the + * nfs node, whereas larger ones are malloc'd. (This never happens when + * NFS_SMALLFH is set to 64.) + * NFS_SMALLFH should be in the range of 32 to 64 and be divisible by 4. + */ +#ifndef NFS_SMALLFH +#define NFS_SMALLFH 64 +#endif +union nfsfh { +/* fhandle_t fh_generic; */ + u_char fh_bytes[NFS_SMALLFH]; +}; +typedef union nfsfh nfsfh_t; + +struct nfsv2_time { + u_int32_t nfsv2_sec; + u_int32_t nfsv2_usec; +}; +typedef struct nfsv2_time nfstime2; + +struct nfsv3_time { + u_int32_t nfsv3_sec; + u_int32_t nfsv3_nsec; +}; +typedef struct nfsv3_time nfstime3; + +/* + * Quads are defined as arrays of 2 longs to ensure dense packing for the + * protocol and to facilitate xdr conversion. + */ +struct nfs_uquad { + u_int32_t nfsuquad[2]; +}; +typedef struct nfs_uquad nfsuint64; + +#if 0 /* XXX - this doesn't seemed to be used and it doesn't work + * with non-gcc, so comment it out for now. + */ + +/* + * Used to convert between two u_longs and a u_quad_t. + */ +union nfs_quadconvert { + u_int32_t lval[2]; + u_int64_t qval; +}; +typedef union nfs_quadconvert nfsquad_t; + +#endif + +/* + * NFS Version 3 special file number. + */ +struct nfsv3_spec { + u_int32_t specdata1; + u_int32_t specdata2; +}; +typedef struct nfsv3_spec nfsv3spec; + +/* + * File attributes and setable attributes. These structures cover both + * NFS version 2 and the version 3 protocol. Note that the union is only + * used so that one pointer can refer to both variants. These structures + * go out on the wire and must be densely packed, so no quad data types + * are used. (all fields are longs or u_longs or structures of same) + * NB: You can't do sizeof(struct nfs_fattr), you must use the + * NFSX_FATTR(v3) macro. + */ +struct nfs_fattr { + u_int32_t fa_type; + u_int32_t fa_mode; + u_int32_t fa_nlink; + u_int32_t fa_uid; + u_int32_t fa_gid; + union { + struct { + u_int32_t nfsv2fa_size; + u_int32_t nfsv2fa_blocksize; + u_int32_t nfsv2fa_rdev; + u_int32_t nfsv2fa_blocks; + u_int32_t nfsv2fa_fsid; + u_int32_t nfsv2fa_fileid; + nfstime2 nfsv2fa_atime; + nfstime2 nfsv2fa_mtime; + nfstime2 nfsv2fa_ctime; + } fa_nfsv2; + struct { + nfsuint64 nfsv3fa_size; + nfsuint64 nfsv3fa_used; + nfsv3spec nfsv3fa_rdev; + nfsuint64 nfsv3fa_fsid; + nfsuint64 nfsv3fa_fileid; + nfstime3 nfsv3fa_atime; + nfstime3 nfsv3fa_mtime; + nfstime3 nfsv3fa_ctime; + } fa_nfsv3; + } fa_un; +}; + +/* and some ugly defines for accessing union components */ +#define fa2_size fa_un.fa_nfsv2.nfsv2fa_size +#define fa2_blocksize fa_un.fa_nfsv2.nfsv2fa_blocksize +#define fa2_rdev fa_un.fa_nfsv2.nfsv2fa_rdev +#define fa2_blocks fa_un.fa_nfsv2.nfsv2fa_blocks +#define fa2_fsid fa_un.fa_nfsv2.nfsv2fa_fsid +#define fa2_fileid fa_un.fa_nfsv2.nfsv2fa_fileid +#define fa2_atime fa_un.fa_nfsv2.nfsv2fa_atime +#define fa2_mtime fa_un.fa_nfsv2.nfsv2fa_mtime +#define fa2_ctime fa_un.fa_nfsv2.nfsv2fa_ctime +#define fa3_size fa_un.fa_nfsv3.nfsv3fa_size +#define fa3_used fa_un.fa_nfsv3.nfsv3fa_used +#define fa3_rdev fa_un.fa_nfsv3.nfsv3fa_rdev +#define fa3_fsid fa_un.fa_nfsv3.nfsv3fa_fsid +#define fa3_fileid fa_un.fa_nfsv3.nfsv3fa_fileid +#define fa3_atime fa_un.fa_nfsv3.nfsv3fa_atime +#define fa3_mtime fa_un.fa_nfsv3.nfsv3fa_mtime +#define fa3_ctime fa_un.fa_nfsv3.nfsv3fa_ctime + +struct nfsv2_sattr { + u_int32_t sa_mode; + u_int32_t sa_uid; + u_int32_t sa_gid; + u_int32_t sa_size; + nfstime2 sa_atime; + nfstime2 sa_mtime; +}; + +/* + * NFS Version 3 sattr structure for the new node creation case. + */ +struct nfsv3_sattr { + u_int32_t sa_modeset; + u_int32_t sa_mode; + u_int32_t sa_uidset; + u_int32_t sa_uid; + u_int32_t sa_gidset; + u_int32_t sa_gid; + u_int32_t sa_sizeset; + u_int32_t sa_size; + u_int32_t sa_atimetype; + nfstime3 sa_atime; + u_int32_t sa_mtimetype; + nfstime3 sa_mtime; +}; + +struct nfs_statfs { + union { + struct { + u_int32_t nfsv2sf_tsize; + u_int32_t nfsv2sf_bsize; + u_int32_t nfsv2sf_blocks; + u_int32_t nfsv2sf_bfree; + u_int32_t nfsv2sf_bavail; + } sf_nfsv2; + struct { + nfsuint64 nfsv3sf_tbytes; + nfsuint64 nfsv3sf_fbytes; + nfsuint64 nfsv3sf_abytes; + nfsuint64 nfsv3sf_tfiles; + nfsuint64 nfsv3sf_ffiles; + nfsuint64 nfsv3sf_afiles; + u_int32_t nfsv3sf_invarsec; + } sf_nfsv3; + } sf_un; +}; + +#define sf_tsize sf_un.sf_nfsv2.nfsv2sf_tsize +#define sf_bsize sf_un.sf_nfsv2.nfsv2sf_bsize +#define sf_blocks sf_un.sf_nfsv2.nfsv2sf_blocks +#define sf_bfree sf_un.sf_nfsv2.nfsv2sf_bfree +#define sf_bavail sf_un.sf_nfsv2.nfsv2sf_bavail +#define sf_tbytes sf_un.sf_nfsv3.nfsv3sf_tbytes +#define sf_fbytes sf_un.sf_nfsv3.nfsv3sf_fbytes +#define sf_abytes sf_un.sf_nfsv3.nfsv3sf_abytes +#define sf_tfiles sf_un.sf_nfsv3.nfsv3sf_tfiles +#define sf_ffiles sf_un.sf_nfsv3.nfsv3sf_ffiles +#define sf_afiles sf_un.sf_nfsv3.nfsv3sf_afiles +#define sf_invarsec sf_un.sf_nfsv3.nfsv3sf_invarsec + +struct nfsv3_fsinfo { + u_int32_t fs_rtmax; + u_int32_t fs_rtpref; + u_int32_t fs_rtmult; + u_int32_t fs_wtmax; + u_int32_t fs_wtpref; + u_int32_t fs_wtmult; + u_int32_t fs_dtpref; + nfsuint64 fs_maxfilesize; + nfstime3 fs_timedelta; + u_int32_t fs_properties; +}; + +struct nfsv3_pathconf { + u_int32_t pc_linkmax; + u_int32_t pc_namemax; + u_int32_t pc_notrunc; + u_int32_t pc_chownrestricted; + u_int32_t pc_caseinsensitive; + u_int32_t pc_casepreserving; +}; diff --git a/kame/kame/tcpdump/nfsfh.h b/kame/kame/tcpdump/nfsfh.h index 5881d523aa..b8a82e4bd9 100644 --- a/kame/kame/tcpdump/nfsfh.h +++ b/kame/kame/tcpdump/nfsfh.h @@ -1,6 +1,39 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/nfsfh.h,v 1.13 2002/04/24 06:27:05 guy Exp $ (LBL) */ + /* - * $Header: nfsfh.h,v 1.6 96/12/16 03:40:31 leres 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 @@ -25,10 +58,11 @@ typedef struct { */ typedef struct { my_devt Fsid_dev; /* XXX avoid name conflict with AIX */ + char Opaque_Handle[2 * 32 + 1]; u_int32_t fsid_code; } my_fsid; #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 *, my_fsid *, ino_t *, char **, char **, int); +extern void Parse_fh(const unsigned char *, int, my_fsid *, ino_t *, const char **, const char **, int); diff --git a/kame/kame/tcpdump/ntp.h b/kame/kame/tcpdump/ntp.h index 32eae642e1..f195d6db25 100644 --- a/kame/kame/tcpdump/ntp.h +++ b/kame/kame/tcpdump/ntp.h @@ -1,4 +1,4 @@ -/* $Header: ntp.h,v 1.3 95/05/04 17:52:49 mccanne Exp $ */ +/* $Header: /tcpdump/master/tcpdump/ntp.h,v 1.7 2003/08/06 04:58:21 guy Exp $ */ /* * Based on ntp.h from the U of MD implementation @@ -8,7 +8,7 @@ /* * Definitions for the masses */ -#define JAN_1970 2208988800 /* 1970 - 1900 in seconds */ +#define JAN_1970 2208988800U /* 1970 - 1900 in seconds */ /* * Structure definitions for NTP fixed point values @@ -33,8 +33,8 @@ struct l_fixedpt { }; struct s_fixedpt { - u_short int_part; - u_short fraction; + u_int16_t int_part; + u_int16_t fraction; }; /* ================= Table 3.3. Packet Variables ================= */ diff --git a/kame/kame/tcpdump/oakley.h b/kame/kame/tcpdump/oakley.h index 679884d7f3..f40d6073eb 100644 --- a/kame/kame/tcpdump/oakley.h +++ b/kame/kame/tcpdump/oakley.h @@ -1,7 +1,7 @@ /* * 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: @@ -13,7 +13,7 @@ * 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 @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -/* YIPS @(#)$Id: oakley.h,v 1.1.2.2.4.1 1999/02/12 08:10:03 sumikawa Exp $ */ +/* YIPS @(#)$Id: oakley.h,v 1.4 2002/12/11 07:13:56 guy Exp $ */ /* refer to RFC 2409 */ diff --git a/kame/kame/tcpdump/ospf.h b/kame/kame/tcpdump/ospf.h index eee79441fb..40c75c966a 100644 --- a/kame/kame/tcpdump/ospf.h +++ b/kame/kame/tcpdump/ospf.h @@ -1,3 +1,4 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/ospf.h,v 1.11 2003/10/22 17:08:46 hannes Exp $ (LBL) */ /* * Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997 * The Regents of the University of California. All rights reserved. @@ -20,25 +21,34 @@ * * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu) */ -#define OSPF_TYPE_UMD 0 /* UMd's special monitoring packets */ -#define OSPF_TYPE_HELLO 1 /* Hello */ -#define OSPF_TYPE_DB 2 /* Database Description */ -#define OSPF_TYPE_LSR 3 /* Link State Request */ -#define OSPF_TYPE_LSU 4 /* Link State Update */ -#define OSPF_TYPE_LSA 5 /* Link State Ack */ -#define OSPF_TYPE_MAX 6 - -/* Options *_options */ +#define OSPF_TYPE_UMD 0 /* UMd's special monitoring packets */ +#define OSPF_TYPE_HELLO 1 /* Hello */ +#define OSPF_TYPE_DD 2 /* Database Description */ +#define OSPF_TYPE_LS_REQ 3 /* Link State Request */ +#define OSPF_TYPE_LS_UPDATE 4 /* Link State Update */ +#define OSPF_TYPE_LS_ACK 5 /* Link State Ack */ + +/* Options field + * + * +------------------------------------+ + * | * | O | DC | EA | N/P | MC | E | T | + * +------------------------------------+ + * + */ + #define OSPF_OPTION_T 0x01 /* T bit: TOS support */ #define OSPF_OPTION_E 0x02 /* E bit: External routes advertised */ #define OSPF_OPTION_MC 0x04 /* MC bit: Multicast capable */ +#define OSPF_OPTION_NP 0x08 /* N/P bit: NSSA capable */ +#define OSPF_OPTION_EA 0x10 /* EA bit: External Attribute capable */ +#define OSPF_OPTION_DC 0x20 /* DC bit: Demand circuit capable */ +#define OSPF_OPTION_O 0x40 /* O bit: Opaque LSA capable */ /* ospf_authtype */ #define OSPF_AUTH_NONE 0 /* No auth-data */ #define OSPF_AUTH_SIMPLE 1 /* Simple password */ #define OSPF_AUTH_MD5 2 /* MD5 authentication */ -#define OSPF_AUTH_MD5_LEN 16 /* length of MD5 authentication */ - +#define OSPF_AUTH_MD5_LEN 16 /* length of MD5 authentication */ /* db_flags */ #define OSPF_DB_INIT 0x04 /* */ @@ -53,7 +63,33 @@ #define LS_TYPE_ASE 5 /* ASE */ #define LS_TYPE_GROUP 6 /* Group membership (multicast */ /* extensions 23 July 1991) */ -#define LS_TYPE_MAX 7 +#define LS_TYPE_NSSA 7 /* rfc1587 - Not so Stubby Areas */ +#define LS_TYPE_OPAQUE_LL 9 /* rfc2370 - Opaque Link Local */ +#define LS_TYPE_OPAQUE_AL 10 /* rfc2370 - Opaque Link Local */ +#define LS_TYPE_OPAQUE_DW 11 /* rfc2370 - Opaque Domain Wide */ + +#define LS_OPAQUE_TYPE_TE 1 /* rfc3630 */ +#define LS_OPAQUE_TYPE_GRACE 3 /* draft-ietf-ospf-hitless-restart */ + +#define LS_OPAQUE_TE_TLV_ROUTER 1 /* rfc3630 */ +#define LS_OPAQUE_TE_TLV_LINK 2 /* rfc3630 */ + +#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE 1 /* rfc3630 */ +#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID 2 /* rfc3630 */ +#define LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP 3 /* rfc3630 */ +#define LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP 4 /* rfc3630 */ +#define LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC 5 /* rfc3630 */ +#define LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW 6 /* rfc3630 */ +#define LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW 7 /* rfc3630 */ +#define LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW 8 /* rfc3630 */ +#define LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP 9 /* rfc3630 */ +#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID 11 /* draft-ietf-ccamp-ospf-gmpls-extensions */ +#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE 14 /* draft-ietf-ccamp-ospf-gmpls-extensions */ +#define LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR 15 /* draft-ietf-ccamp-ospf-gmpls-extensions */ +#define LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP 16 /* draft-ietf-ccamp-ospf-gmpls-extensions */ + +#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP 1 /* rfc3630 */ +#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA 2 /* rfc3630 */ /************************************************* * @@ -91,15 +127,21 @@ /* link state advertisement header */ struct lsa_hdr { - u_short ls_age; - u_char ls_options; - u_char ls_type; - struct in_addr ls_stateid; + u_int16_t ls_age; + u_int8_t ls_options; + u_int8_t ls_type; + union { + struct in_addr lsa_id; + struct { /* opaque LSAs change the LSA-ID field */ + u_int8_t opaque_type; + u_int8_t opaque_id[3]; + } opaque_field; + } un_lsa_id; struct in_addr ls_router; u_int32_t ls_seq; - u_short ls_chksum; - u_short ls_length; -} ; + u_int16_t ls_chksum; + u_int16_t ls_length; +}; /* link state advertisement */ struct lsa { @@ -109,15 +151,15 @@ struct lsa { union { /* Router links advertisements */ struct { - u_char rla_flags; - u_char rla_zero[1]; - u_short rla_count; + u_int8_t rla_flags; + u_int8_t rla_zero[1]; + u_int16_t rla_count; struct rlalink { struct in_addr link_id; struct in_addr link_data; - u_char link_type; - u_char link_toscount; - u_short link_tos0metric; + u_int8_t link_type; + u_int8_t link_toscount; + u_int16_t link_tos0metric; } rla_link[1]; /* may repeat */ } un_rla; @@ -148,18 +190,31 @@ struct lsa { u_int32_t mcla_vtype; struct in_addr mcla_vid; } un_mcla[1]; + + /* Opaque TE LSA */ + struct { + u_int16_t type; + u_int16_t length; + u_int8_t data[1]; /* may repeat */ + } un_te_lsa_tlv; + + /* Unknown LSA */ + struct unknown { + u_int8_t data[1]; /* may repeat */ + } un_unknown[1]; + } lsa_un; -} ; +}; /* * TOS metric struct (will be 0 or more in router links update) */ struct tos_metric { - u_char tos_type; - u_char tos_zero; - u_short tos_metric; -} ; + u_int8_t tos_type; + u_int8_t tos_zero; + u_int16_t tos_metric; +}; #define OSPF_AUTH_SIZE 8 @@ -167,22 +222,22 @@ struct tos_metric { * the main header */ struct ospfhdr { - u_char ospf_version; - u_char ospf_type; - u_short ospf_len; + u_int8_t ospf_version; + u_int8_t ospf_type; + u_int16_t ospf_len; struct in_addr ospf_routerid; struct in_addr ospf_areaid; - u_short ospf_chksum; - u_short ospf_authtype; - u_char ospf_authdata[OSPF_AUTH_SIZE]; + u_int16_t ospf_chksum; + u_int16_t ospf_authtype; + u_int8_t ospf_authdata[OSPF_AUTH_SIZE]; union { /* Hello packet */ struct { struct in_addr hello_mask; - u_short hello_helloint; - u_char hello_options; - u_char hello_priority; + u_int16_t hello_helloint; + u_int8_t hello_options; + u_int8_t hello_priority; u_int32_t hello_deadint; struct in_addr hello_dr; struct in_addr hello_bdr; @@ -191,17 +246,23 @@ struct ospfhdr { /* Database Description packet */ struct { - u_char db_zero[2]; - u_char db_options; - u_char db_flags; + u_int8_t db_zero[2]; + u_int8_t db_options; + u_int8_t db_flags; u_int32_t db_seq; struct lsa_hdr db_lshdr[1]; /* may repeat */ } un_db; /* Link State Request */ struct lsr { - u_int32_t ls_type; - struct in_addr ls_stateid; + u_int8_t ls_type[4]; + union { + struct in_addr ls_stateid; + struct { /* opaque LSAs change the LSA-ID field */ + u_int8_t opaque_type; + u_int8_t opaque_id[3]; + } opaque_field; + } un_ls_stateid; struct in_addr ls_router; } un_lsr[1]; /* may repeat */ @@ -216,7 +277,7 @@ struct ospfhdr { struct lsa_hdr lsa_lshdr[1]; /* may repeat */ } un_lsa ; } ospf_un ; -} ; +}; #define ospf_hello ospf_un.un_hello #define ospf_db ospf_un.un_db diff --git a/kame/kame/tcpdump/ospf6.h b/kame/kame/tcpdump/ospf6.h index 85e81d7f7e..b8298ead91 100644 --- a/kame/kame/tcpdump/ospf6.h +++ b/kame/kame/tcpdump/ospf6.h @@ -1,3 +1,4 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/ospf6.h,v 1.6 2002/12/11 07:13:56 guy Exp $ (LBL) */ /* * Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997 * The Regents of the University of California. All rights reserved. @@ -83,10 +84,10 @@ #define SLA_MASK_METRIC 0x00ffffff #define SLA_SHIFT_TOS 24 -/* asla_tosmetric breakdown */ -#define ASLA_FLAG_EXTERNAL 0x80000000 -#define ASLA_MASK_TOS 0x7f000000 -#define ASLA_SHIFT_TOS 24 +/* asla_metric */ +#define ASLA_FLAG_EXTERNAL 0x04000000 +#define ASLA_FLAG_FWDADDR 0x02000000 +#define ASLA_FLAG_ROUTETAG 0x01000000 #define ASLA_MASK_METRIC 0x00ffffff /* multicast vertex type */ @@ -104,7 +105,7 @@ struct lsa_hdr { u_int32_t ls_seq; u_int16_t ls_chksum; u_int16_t ls_length; -} ; +}; struct lsa_prefix { u_int8_t lsa_p_len; @@ -149,6 +150,13 @@ struct lsa { struct lsa_prefix inter_ap_prefix[1]; } un_inter_ap; + /* AS external links advertisements */ + struct { + u_int32_t asla_metric; + struct lsa_prefix asla_prefix[1]; + /* some optional fields follow */ + } un_asla; + #if 0 /* Summary links advertisements */ struct { @@ -156,16 +164,6 @@ struct lsa { u_int32_t sla_tosmetric[1]; /* may repeat */ } un_sla; - /* AS external links advertisements */ - struct { - struct in_addr asla_mask; - struct aslametric { - u_int32_t asla_tosmetric; - struct in_addr asla_forward; - struct in_addr asla_tag; - } asla_metric[1]; /* may repeat */ - } un_asla; - /* Multicast group membership */ struct mcla { u_int32_t mcla_vtype; @@ -197,7 +195,7 @@ struct lsa { struct lsa_prefix intra_ap_prefix[1]; } un_intra_ap; } lsa_un; -} ; +}; /* @@ -207,7 +205,7 @@ struct tos_metric { u_int8_t tos_type; u_int8_t tos_zero; u_int16_t tos_metric; -} ; +}; #define OSPF_AUTH_SIZE 8 @@ -270,7 +268,7 @@ struct ospf6hdr { struct lsa_hdr lsa_lshdr[1]; /* may repeat */ } un_lsa ; } ospf6_un ; -} ; +}; #define ospf6_hello ospf6_un.un_hello #define ospf6_db ospf6_un.un_db diff --git a/kame/kame/tcpdump/oui.c b/kame/kame/tcpdump/oui.c new file mode 100644 index 0000000000..3348bd298f --- /dev/null +++ b/kame/kame/tcpdump/oui.c @@ -0,0 +1,62 @@ +/* + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code + * distributions retain the above copyright notice and this paragraph + * in its entirety, and (2) distributions including binary code include + * the above copyright notice and this paragraph in its entirety in + * the documentation or other materials provided with the distribution. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND + * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT + * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * Original code by Hannes Gredler (hannes@juniper.net) + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/oui.c,v 1.2.2.1 2004/02/06 14:38:51 hannes Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "interface.h" +#include "oui.h" + +/* FIXME complete OUI list using a script */ + +struct tok oui_values[] = { + { 0x009069, "Juniper"}, + { 0x00000c, "Cisco"}, +}; + +/* list taken from ethereal/packet-radius.c */ + +struct tok smi_values[] = { + { SMI_ACC, "ACC"}, + { SMI_CISCO, "Cisco"}, + { SMI_SHIVA, "Shiva"}, + { SMI_MICROSOFT, "Microsoft"}, + { SMI_LIVINGSTON, "Livingston"}, + { SMI_3COM, "3Com"}, + { SMI_ASCEND, "Ascend"}, + { SMI_BAY, "Bay Networks"}, + { SMI_FOUNDRY, "Foundry"}, + { SMI_VERSANET, "Versanet"}, + { SMI_REDBACK, "Redback"}, + { SMI_JUNIPER, "Juniper Networks"}, + { SMI_APTIS, "Aptis"}, + { SMI_COSINE, "CoSine Communications"}, + { SMI_SHASTA, "Shasta"}, + { SMI_NOMADIX, "Nomadix"}, + { SMI_UNISPHERE, "Unisphere Networks"}, + { SMI_ISSANNI, "Issanni Communications"}, + { SMI_QUINTUM, "Quintum"}, + { SMI_COLUBRIS, "Colubris"}, + { SMI_COLUMBIA_UNIVERSITY, "Columbia University"}, + { SMI_THE3GPP, "3GPP"}, + { 0, NULL } +}; diff --git a/kame/kame/tcpdump/oui.h b/kame/kame/tcpdump/oui.h new file mode 100644 index 0000000000..39df977269 --- /dev/null +++ b/kame/kame/tcpdump/oui.h @@ -0,0 +1,41 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/oui.h,v 1.2.2.1 2004/02/06 14:38:50 hannes Exp $ (LBL) */ +/* + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code + * distributions retain the above copyright notice and this paragraph + * in its entirety, and (2) distributions including binary code include + * the above copyright notice and this paragraph in its entirety in + * the documentation or other materials provided with the distribution. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND + * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT + * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * Original code by Hannes Gredler (hannes@juniper.net) + */ + +extern struct tok oui_values[]; +extern struct tok smi_values[]; + +#define SMI_ACC 5 +#define SMI_CISCO 9 +#define SMI_SHIVA 166 +#define SMI_LIVINGSTON 307 +#define SMI_MICROSOFT 311 +#define SMI_3COM 429 +#define SMI_ASCEND 529 +#define SMI_BAY 1584 +#define SMI_FOUNDRY 1991 +#define SMI_VERSANET 2180 +#define SMI_REDBACK 2352 +#define SMI_JUNIPER 2636 +#define SMI_APTIS 2637 +#define SMI_COSINE 3085 +#define SMI_SHASTA 3199 +#define SMI_NOMADIX 3309 +#define SMI_UNISPHERE 4874 +#define SMI_ISSANNI 5948 +#define SMI_QUINTUM 6618 +#define SMI_COLUBRIS 8744 +#define SMI_COLUMBIA_UNIVERSITY 11862 +#define SMI_THE3GPP 10415 diff --git a/kame/kame/tcpdump/parsenfsfh.c b/kame/kame/tcpdump/parsenfsfh.c index d7969bb280..21af367ac2 100644 --- a/kame/kame/tcpdump/parsenfsfh.c +++ b/kame/kame/tcpdump/parsenfsfh.c @@ -1,3 +1,36 @@ +/* + * 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 @@ -8,17 +41,16 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: parsenfsfh.c,v 1.14 97/06/15 13:20:27 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/parsenfsfh.c,v 1.25.2.2 2003/11/16 08:51:07 guy Exp $ (LBL)"; #endif -#include -#include - -#include -#ifdef HAVE_MEMORY_H -#include +#ifdef HAVE_CONFIG_H +#include "config.h" #endif + +#include + #include #include @@ -74,20 +106,22 @@ static const char rcsid[] = ((lsb) + ((e)<<8) + ((d)<<16) + ((c)<<24)) #endif -static int is_UCX(unsigned char *); +static int is_UCX(const unsigned char *); void -Parse_fh(fh, fsidp, inop, osnamep, fsnamep, ourself) -register caddr_t *fh; +Parse_fh(fh, len, fsidp, inop, osnamep, fsnamep, ourself) +register const unsigned char *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; + register const unsigned char *fhp = fh; u_int32_t temp; int fhtype = FHT_UNKNOWN; + int i; if (ourself) { /* File handle generated on this host, no need for guessing */ @@ -365,14 +399,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"); - } + /* XXX debugging */ + for (i = 0; i < 32; i++) + (void)fprintf(stderr, "%x.", fhp[i]); + (void)fprintf(stderr, "\n"); #endif + /* Save the actual handle, so it can be display with -u */ + for (i = 0; i < 32; 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; @@ -399,7 +434,7 @@ int ourself; /* true if file handle was generated on this host */ */ static int is_UCX(fhp) -unsigned char *fhp; +const unsigned char *fhp; { register int i; int seen_null = 0; diff --git a/kame/kame/tcpdump/pcap-missing.h b/kame/kame/tcpdump/pcap-missing.h new file mode 100644 index 0000000000..adf24d8717 --- /dev/null +++ b/kame/kame/tcpdump/pcap-missing.h @@ -0,0 +1,56 @@ +/* + * 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 + * 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. + * + * @(#) $Header: /tcpdump/master/tcpdump/pcap-missing.h,v 1.1.2.1 2003/11/18 23:12:11 guy Exp $ (LBL) + */ + +#ifndef tcpdump_pcap_missing_h +#define tcpdump_pcap_missing_h + +/* + * Declarations of functions that might be missing from libpcap. + */ + +#ifndef HAVE_PCAP_LIST_DATALINKS +extern int pcap_list_datalinks(pcap_t *, int **); +#endif + +#ifndef HAVE_PCAP_DATALINK_NAME_TO_VAL +/* + * We assume no platform has one but not the other. + */ +extern int pcap_datalink_name_to_val(const char *); +extern const char *pcap_datalink_val_to_name(int); +#endif + +#ifndef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION +extern const char *pcap_datalink_val_to_description(int); +#endif + +#endif + + + + + + + + + diff --git a/kame/kame/tcpdump/pf.h b/kame/kame/tcpdump/pf.h new file mode 100644 index 0000000000..314802c29b --- /dev/null +++ b/kame/kame/tcpdump/pf.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2001 Daniel Hartmeier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDERS 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/pf.h,v 1.1.2.1 2004/03/28 21:25:03 fenner Exp $ (LBL) + */ + +/* from $OpenBSD: pfvar.h,v 1.170 2003/08/22 21:50:34 david Exp $ */ + +enum { PF_INOUT=0, PF_IN=1, PF_OUT=2 }; +enum { PF_PASS=0, PF_DROP=1, PF_SCRUB=2, PF_NAT=3, PF_NONAT=4, + PF_BINAT=5, PF_NOBINAT=6, PF_RDR=7, PF_NORDR=8, PF_SYNPROXY_DROP=9 }; + +/* Reasons code for passing/dropping a packet */ +#define PFRES_MATCH 0 /* Explicit match of a rule */ +#define PFRES_BADOFF 1 /* Bad offset for pull_hdr */ +#define PFRES_FRAG 2 /* Dropping following fragment */ +#define PFRES_SHORT 3 /* Dropping short packet */ +#define PFRES_NORM 4 /* Dropping by normalizer */ +#define PFRES_MEMORY 5 /* Dropped due to lacking mem */ +#define PFRES_MAX 6 /* total+1 */ + +#define PFRES_NAMES { \ + "match", \ + "bad-offset", \ + "fragment", \ + "short", \ + "normalize", \ + "memory", \ + NULL \ +} + +#define PF_RULESET_NAME_SIZE 16 + +/* from $OpenBSD: if_pflog.h,v 1.9 2003/07/15 20:27:27 dhartmei Exp $ */ + +#ifndef IFNAMSIZ +#define IFNAMSIZ 16 +#endif + +struct pfloghdr { + u_int8_t length; + sa_family_t af; + u_int8_t action; + u_int8_t reason; + char ifname[IFNAMSIZ]; + char ruleset[PF_RULESET_NAME_SIZE]; + u_int32_t rulenr; + u_int32_t subrulenr; + u_int8_t dir; + u_int8_t pad[3]; +}; +#define PFLOG_HDRLEN sizeof(struct pfloghdr) diff --git a/kame/kame/tcpdump/ppp.h b/kame/kame/tcpdump/ppp.h index ccd546a0b3..d09efbd002 100644 --- a/kame/kame/tcpdump/ppp.h +++ b/kame/kame/tcpdump/ppp.h @@ -1,4 +1,4 @@ -/* @(#) $Header: ppp.h,v 1.7 95/05/04 17:52:46 mccanne Exp $ (LBL) */ +/* @(#) $Header: /tcpdump/master/tcpdump/ppp.h,v 1.14 2003/05/22 15:29:22 hannes Exp $ (LBL) */ /* * Point to Point Protocol (PPP) RFC1331 * @@ -15,6 +15,8 @@ * suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. */ +#define PPP_HDRLEN 4 /* length of PPP header */ + #define PPP_ADDRESS 0xff /* The address byte value */ #define PPP_CONTROL 0x03 /* The control byte value */ @@ -30,10 +32,14 @@ #define PPP_BRPDU 0x0031 /* Bridging PDU */ #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 */ #define PPP_SNS 0x0233 /* Sigma Network Systems */ +#define PPP_MPLS_UCAST 0x0281 /* rfc 3032 */ +#define PPP_MPLS_MCAST 0x0283 /* rfc 3022 */ #define PPP_IPCP 0x8021 /* IP Control Protocol */ #define PPP_OSICP 0x8023 /* OSI Network Layer Control Protocol */ @@ -43,8 +49,19 @@ #define PPP_IPXCP 0x802b /* Novell IPX Control Protocol */ #define PPP_STIICP 0x8033 /* Strean Protocol Control Protocol */ #define PPP_VINESCP 0x8035 /* Banyan Vines Control Protocol */ +#define PPP_IPV6CP 0x8057 /* IPv6 Control Protocol */ +#define PPP_CCP 0x80fd /* Compress Control Protocol */ +#define PPP_MPLSCP 0x8281 /* rfc 3022 */ #define PPP_LCP 0xc021 /* Link Control Protocol */ #define PPP_PAP 0xc023 /* Password Authentication Protocol */ #define PPP_LQM 0xc025 /* Link Quality Monitoring */ +#define PPP_SPAP 0xc027 #define PPP_CHAP 0xc223 /* Challenge Handshake Authentication Protocol */ +#define PPP_BACP 0xc02b /* Bandwidth Allocation Control Protocol */ +#define PPP_BAP 0xc02d /* BAP */ +#define PPP_MP 0xc03d /* Multi-Link */ +#define PPP_SPAP_OLD 0xc123 +#define PPP_EAP 0xc227 + +extern struct tok ppptype2str[]; diff --git a/kame/kame/tcpdump/print-802_11.c b/kame/kame/tcpdump/print-802_11.c new file mode 100644 index 0000000000..56462c9448 --- /dev/null +++ b/kame/kame/tcpdump/print-802_11.c @@ -0,0 +1,1003 @@ +/* + * 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[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-802_11.c,v 1.22.2.6 2003/12/10 09:52:33 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "ethertype.h" + +#include "extract.h" + +#include "ieee802_11.h" + +#define PRINT_RATES(p) \ +do { \ + int z; \ + const char *sep = " ["; \ + for (z = 0; z < p.rates.length ; z++) { \ + printf("%s%2.1f", sep, (.5 * (p.rates.rate[z] & 0x7f))); \ + if (p.rates.rate[z] & 0x80) printf("*"); \ + sep = " "; \ + } \ + if (p.rates.length != 0) \ + printf(" Mbit]"); \ +} 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", + "", + "", + "Beacon", + "ATIM", + "Disassociation", + "Authentication", + "DeAuthentication", + "", + "" +}; + +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_int32_t iv; + + if (!TTEST2(*p, IEEE802_11_IV_LEN + IEEE802_11_KID_LEN)) + 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 1; + 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) + break; + 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) + break; + 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) + break; + 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) + break; + 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(const u_char *p) +{ + struct mgmt_body_t pbody; + int offset = 0; + + memset(&pbody, 0, sizeof(pbody)); + + if (!TTEST2(*p, IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN + + IEEE802_11_CAPINFO_LEN)) + return 0; + memcpy(&pbody.timestamp, p, 8); + offset += IEEE802_11_TSTAMP_LEN; + pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); + offset += IEEE802_11_BCNINT_LEN; + pbody.capability_info = EXTRACT_LE_16BITS(p+offset); + offset += IEEE802_11_CAPINFO_LEN; + + if (!parse_elements(&pbody, p, offset)) + return 0; + + printf(" ("); + fn_print(pbody.ssid.ssid, NULL); + printf(")"); + PRINT_RATES(pbody); + printf(" %s CH: %u%s", + CAPABILITY_ESS(pbody.capability_info) ? "ESS" : "IBSS", + pbody.ds.channel, + CAPABILITY_PRIVACY(pbody.capability_info) ? ", PRIVACY" : "" ); + + return 1; +} + +static int +handle_assoc_request(const u_char *p) +{ + struct mgmt_body_t pbody; + int offset = 0; + + memset(&pbody, 0, sizeof(pbody)); + + if (!TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN)) + return 0; + pbody.capability_info = EXTRACT_LE_16BITS(p); + offset += IEEE802_11_CAPINFO_LEN; + pbody.listen_interval = EXTRACT_LE_16BITS(p+offset); + offset += IEEE802_11_LISTENINT_LEN; + + if (!parse_elements(&pbody, p, offset)) + return 0; + + printf(" ("); + fn_print(pbody.ssid.ssid, NULL); + printf(")"); + PRINT_RATES(pbody); + return 1; +} + +static int +handle_assoc_response(const u_char *p) +{ + struct mgmt_body_t pbody; + int offset = 0; + + memset(&pbody, 0, sizeof(pbody)); + + if (!TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_STATUS_LEN + + IEEE802_11_AID_LEN)) + return 0; + pbody.capability_info = EXTRACT_LE_16BITS(p); + offset += IEEE802_11_CAPINFO_LEN; + pbody.status_code = EXTRACT_LE_16BITS(p+offset); + offset += IEEE802_11_STATUS_LEN; + pbody.aid = EXTRACT_LE_16BITS(p+offset); + offset += IEEE802_11_AID_LEN; + + if (!parse_elements(&pbody, p, offset)) + return 0; + + printf(" AID(%x) :%s: %s", ((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(const u_char *p) +{ + struct mgmt_body_t pbody; + int offset = 0; + + memset(&pbody, 0, sizeof(pbody)); + + if (!TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN + + IEEE802_11_AP_LEN)) + return 0; + pbody.capability_info = EXTRACT_LE_16BITS(p); + offset += IEEE802_11_CAPINFO_LEN; + pbody.listen_interval = EXTRACT_LE_16BITS(p+offset); + offset += IEEE802_11_LISTENINT_LEN; + memcpy(&pbody.ap, p+offset, IEEE802_11_AP_LEN); + offset += IEEE802_11_AP_LEN; + + if (!parse_elements(&pbody, p, offset)) + return 0; + + printf(" ("); + fn_print(pbody.ssid.ssid, NULL); + printf(") AP : %s", etheraddr_string( pbody.ap )); + + return 1; +} + +static int +handle_reassoc_response(const u_char *p) +{ + /* Same as a Association Reponse */ + return handle_assoc_response(p); +} + +static int +handle_probe_request(const u_char *p) +{ + struct mgmt_body_t pbody; + int offset = 0; + + memset(&pbody, 0, sizeof(pbody)); + + if (!parse_elements(&pbody, p, offset)) + return 0; + + printf(" ("); + fn_print(pbody.ssid.ssid, NULL); + printf(")"); + PRINT_RATES(pbody); + + return 1; +} + +static int +handle_probe_response(const u_char *p) +{ + struct mgmt_body_t pbody; + int offset = 0; + + memset(&pbody, 0, sizeof(pbody)); + + if (!TTEST2(*p, IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN + + IEEE802_11_CAPINFO_LEN)) + return 0; + + memcpy(&pbody.timestamp, p, IEEE802_11_TSTAMP_LEN); + offset += IEEE802_11_TSTAMP_LEN; + pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); + offset += IEEE802_11_BCNINT_LEN; + pbody.capability_info = EXTRACT_LE_16BITS(p+offset); + offset += IEEE802_11_CAPINFO_LEN; + + if (!parse_elements(&pbody, p, offset)) + return 0; + + printf(" ("); + fn_print(pbody.ssid.ssid, NULL); + printf(") "); + PRINT_RATES(pbody); + printf(" CH: %u%s", pbody.ds.channel, + CAPABILITY_PRIVACY(pbody.capability_info) ? ", PRIVACY" : "" ); + + return 1; +} + +static int +handle_atim(void) +{ + /* the frame body for ATIM is null. */ + return 1; +} + +static int +handle_disassoc(const u_char *p) +{ + struct mgmt_body_t pbody; + + memset(&pbody, 0, sizeof(pbody)); + + if (!TTEST2(*p, IEEE802_11_REASON_LEN)) + return 0; + pbody.reason_code = EXTRACT_LE_16BITS(p); + + printf(": %s", + (pbody.reason_code < 10) ? reason_text[pbody.reason_code] + : "Reserved" ); + + return 1; +} + +static int +handle_auth(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)-%x [Challenge Text] %s", + (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; + } + printf(" (%s)-%x: %s", + (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(const struct mgmt_header_t *pmh, const u_char *p) +{ + struct mgmt_body_t pbody; + int offset = 0; + const char *reason = NULL; + + memset(&pbody, 0, sizeof(pbody)); + + if (!TTEST2(*p, IEEE802_11_REASON_LEN)) + return 0; + pbody.reason_code = EXTRACT_LE_16BITS(p); + offset += IEEE802_11_REASON_LEN; + + reason = (pbody.reason_code < 10) ? reason_text[pbody.reason_code] + : "Reserved"; + + if (eflag) { + printf(": %s", reason); + } else { + printf(" (%s): %s", etheraddr_string(pmh->sa), reason); + } + return 1; +} + + +/********************************************************************************* + * Print Body funcs + *********************************************************************************/ + + +static int +mgmt_body_print(u_int16_t fc, const struct mgmt_header_t *pmh, + const u_char *p) +{ + printf("%s", subtype_text[FC_SUBTYPE(fc)]); + + switch (FC_SUBTYPE(fc)) { + case ST_ASSOC_REQUEST: + return handle_assoc_request(p); + case ST_ASSOC_RESPONSE: + return handle_assoc_response(p); + case ST_REASSOC_REQUEST: + return handle_reassoc_request(p); + case ST_REASSOC_RESPONSE: + return handle_reassoc_response(p); + case ST_PROBE_REQUEST: + return handle_probe_request(p); + case ST_PROBE_RESPONSE: + return handle_probe_response(p); + case ST_BEACON: + return handle_beacon(p); + case ST_ATIM: + return handle_atim(); + case ST_DISASSOC: + return handle_disassoc(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); + } + return handle_auth(p); + case ST_DEAUTH: + return handle_deauth(pmh, p); + break; + default: + printf("Unhandled Management 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) +{ + switch (FC_SUBTYPE(fc)) { + case CTRL_PS_POLL: + printf("Power Save-Poll"); + if (!TTEST2(*p, CTRL_PS_POLL_HDRLEN)) + return 0; + printf(" AID(%x)", + EXTRACT_LE_16BITS(&(((const struct ctrl_ps_poll_t *)p)->aid))); + break; + case CTRL_RTS: + printf("Request-To-Send"); + if (!TTEST2(*p, CTRL_RTS_HDRLEN)) + return 0; + if (!eflag) + printf(" TA:%s ", + etheraddr_string(((const struct ctrl_rts_t *)p)->ta)); + break; + case CTRL_CTS: + printf("Clear-To-Send"); + if (!TTEST2(*p, CTRL_CTS_HDRLEN)) + return 0; + if (!eflag) + printf(" RA:%s ", + etheraddr_string(((const struct ctrl_cts_t *)p)->ra)); + break; + case CTRL_ACK: + printf("Acknowledgment"); + if (!TTEST2(*p, CTRL_ACK_HDRLEN)) + return 0; + if (!eflag) + printf(" RA:%s ", + etheraddr_string(((const struct ctrl_ack_t *)p)->ra)); + break; + case CTRL_CF_END: + printf("CF-End"); + if (!TTEST2(*p, CTRL_END_HDRLEN)) + return 0; + if (!eflag) + printf(" RA:%s ", + etheraddr_string(((const struct ctrl_end_t *)p)->ra)); + break; + case CTRL_END_ACK: + printf("CF-End+CF-Ack"); + if (!TTEST2(*p, CTRL_END_ACK_HDRLEN)) + return 0; + if (!eflag) + printf(" RA:%s ", + etheraddr_string(((const struct ctrl_end_ack_t *)p)->ra)); + break; + default: + printf("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, const u_int8_t **srcp, + const u_int8_t **dstp) +{ + switch (FC_SUBTYPE(fc)) { + case DATA_DATA: + case DATA_NODATA: + break; + case DATA_DATA_CF_ACK: + case DATA_NODATA_CF_ACK: + printf("CF Ack "); + break; + case DATA_DATA_CF_POLL: + case DATA_NODATA_CF_POLL: + printf("CF Poll "); + break; + case DATA_DATA_CF_ACK_POLL: + case DATA_NODATA_CF_ACK_POLL: + printf("CF Ack/Poll "); + break; + } + +#define ADDR1 (p + 4) +#define ADDR2 (p + 10) +#define ADDR3 (p + 16) +#define ADDR4 (p + 24) + + if (!FC_TO_DS(fc) && !FC_FROM_DS(fc)) { + if (srcp != NULL) + *srcp = ADDR2; + if (dstp != NULL) + *dstp = ADDR1; + if (!eflag) + return; + printf("DA:%s SA:%s BSSID:%s ", + etheraddr_string(ADDR1), etheraddr_string(ADDR2), + etheraddr_string(ADDR3)); + } else if (!FC_TO_DS(fc) && FC_FROM_DS(fc)) { + if (srcp != NULL) + *srcp = ADDR3; + if (dstp != NULL) + *dstp = ADDR1; + if (!eflag) + return; + printf("DA:%s BSSID:%s SA:%s ", + etheraddr_string(ADDR1), etheraddr_string(ADDR2), + etheraddr_string(ADDR3)); + } else if (FC_TO_DS(fc) && !FC_FROM_DS(fc)) { + if (srcp != NULL) + *srcp = ADDR2; + if (dstp != NULL) + *dstp = ADDR3; + if (!eflag) + return; + printf("BSSID:%s SA:%s DA:%s ", + etheraddr_string(ADDR1), etheraddr_string(ADDR2), + etheraddr_string(ADDR3)); + } else if (FC_TO_DS(fc) && FC_FROM_DS(fc)) { + if (srcp != NULL) + *srcp = ADDR4; + if (dstp != NULL) + *dstp = ADDR3; + if (!eflag) + return; + 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, const u_int8_t **srcp, + const u_int8_t **dstp) +{ + const struct mgmt_header_t *hp = (const struct mgmt_header_t *) p; + + if (srcp != NULL) + *srcp = hp->sa; + if (dstp != NULL) + *dstp = hp->da; + if (!eflag) + return; + + 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, const u_int8_t **srcp, + const u_int8_t **dstp) +{ + if (srcp != NULL) + *srcp = NULL; + if (dstp != NULL) + *dstp = NULL; + if (!eflag) + return; + + 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"); + break; + } +} + +static int +extract_header_length(u_int16_t fc) +{ + switch (FC_TYPE(fc)) { + case T_MGMT: + return MGMT_HDRLEN; + case T_CTRL: + switch (FC_SUBTYPE(fc)) { + case CTRL_PS_POLL: + return CTRL_PS_POLL_HDRLEN; + case CTRL_RTS: + return CTRL_RTS_HDRLEN; + case CTRL_CTS: + return CTRL_CTS_HDRLEN; + case CTRL_ACK: + return CTRL_ACK_HDRLEN; + case CTRL_CF_END: + return CTRL_END_HDRLEN; + case CTRL_END_ACK: + return CTRL_END_ACK_HDRLEN; + default: + return 0; + } + case T_DATA: + return (FC_TO_DS(fc) && FC_FROM_DS(fc)) ? 30 : 24; + default: + printf("unknown IEEE802.11 frame type (%d)", FC_TYPE(fc)); + return 0; + } +} + +/* + * Print the 802.11 MAC header if eflag is set, and set "*srcp" and "*dstp" + * to point to the source and destination MAC addresses in any case if + * "srcp" and "dstp" aren't null. + */ +static inline void +ieee_802_11_hdr_print(u_int16_t fc, const u_char *p, const u_int8_t **srcp, + const u_int8_t **dstp) +{ + if (vflag) { + if (FC_MORE_DATA(fc)) + printf("More Data "); + if (FC_MORE_FLAG(fc)) + printf("More Fragments "); + if (FC_POWER_MGMT(fc)) + printf("Pwr Mgmt "); + if (FC_RETRY(fc)) + printf("Retry "); + if (FC_ORDER(fc)) + printf("Strictly Ordered "); + if (FC_WEP(fc)) + printf("WEP Encrypted "); + if (FC_TYPE(fc) != T_CTRL || FC_SUBTYPE(fc) != CTRL_PS_POLL) + printf("%dus ", + EXTRACT_LE_16BITS( + &((const struct mgmt_header_t *)p)->duration)); + } + + switch (FC_TYPE(fc)) { + case T_MGMT: + mgmt_header_print(p, srcp, dstp); + break; + case T_CTRL: + ctrl_header_print(fc, p, srcp, dstp); + break; + case T_DATA: + data_header_print(fc, p, srcp, dstp); + break; + default: + printf("(header) unknown IEEE802.11 frame type (%d)", + FC_TYPE(fc)); + *srcp = NULL; + *dstp = NULL; + break; + } +} + +static u_int +ieee802_11_print(const u_char *p, u_int length, u_int caplen) +{ + u_int16_t fc; + u_int hdrlen; + const u_int8_t *src, *dst; + u_short extracted_ethertype; + + if (caplen < IEEE802_11_FC_LEN) { + printf("[|802.11]"); + return caplen; + } + + fc = EXTRACT_LE_16BITS(p); + hdrlen = extract_header_length(fc); + + if (caplen < hdrlen) { + printf("[|802.11]"); + return hdrlen; + } + + ieee_802_11_hdr_print(fc, p, &src, &dst); + + /* + * Go past the 802.11 header. + */ + length -= hdrlen; + caplen -= hdrlen; + p += hdrlen; + + switch (FC_TYPE(fc)) { + case T_MGMT: + if (!mgmt_body_print(fc, + (const struct mgmt_header_t *)(p - hdrlen), p)) { + printf("[|802.11]"); + return hdrlen; + } + break; + case T_CTRL: + if (!ctrl_body_print(fc, p - hdrlen)) { + printf("[|802.11]"); + return hdrlen; + } + break; + case T_DATA: + /* There may be a problem w/ AP not having this bit set */ + if (FC_WEP(fc)) { + if (!wep_print(p)) { + printf("[|802.11]"); + return hdrlen; + } + } else if (llc_print(p, length, caplen, dst, src, + &extracted_ethertype) == 0) { + /* + * Some kinds of LLC packet we cannot + * handle intelligently + */ + if (!eflag) + ieee_802_11_hdr_print(fc, p - hdrlen, NULL, + NULL); + if (extracted_ethertype) + printf("(LLC %s) ", + etherproto_string( + htons(extracted_ethertype))); + if (!xflag && !qflag) + default_print(p, caplen); + } + break; + default: + printf("unknown 802.11 frame type (%d)", FC_TYPE(fc)); + break; + } + + return hdrlen; +} + +/* + * This is the top level routine of the printer. 'p' points + * to the 802.11 header of the packet, 'h->ts' is the timestamp, + * 'h->length' is the length of the packet off the wire, and 'h->caplen' + * is the number of bytes actually captured. + */ +u_int +ieee802_11_if_print(const struct pcap_pkthdr *h, const u_char *p) +{ + return ieee802_11_print(p, h->len, h->caplen); +} + +static u_int +ieee802_11_radio_print(const u_char *p, u_int length, u_int caplen) +{ + u_int32_t caphdr_len; + + caphdr_len = EXTRACT_32BITS(p + 4); + if (caphdr_len < 8) { + /* + * Yow! The capture header length is claimed not + * to be large enough to include even the version + * cookie or capture header length! + */ + printf("[|802.11]"); + return caplen; + } + + if (caplen < caphdr_len) { + printf("[|802.11]"); + return caplen; + } + + return caphdr_len + ieee802_11_print(p + caphdr_len, + length - caphdr_len, caplen - caphdr_len); +} + +#define PRISM_HDR_LEN 144 + +#define WLANCAP_MAGIC_COOKIE_V1 0x80211001 + +/* + * For DLT_PRISM_HEADER; like DLT_IEEE802_11, but with an extra header, + * containing information such as radio information, which we + * currently ignore. + * + * If, however, the packet begins with WLANCAP_MAGIC_COOKIE_V1, it's + * really DLT_IEEE802_11_RADIO (currently, on Linux, there's no + * ARPHRD_ type for DLT_IEEE802_11_RADIO, as there is a + * ARPHRD_IEEE80211_PRISM for DLT_PRISM_HEADER, so + * ARPHRD_IEEE80211_PRISM is used for DLT_IEEE802_11_RADIO, and + * the first 4 bytes of the header are used to indicate which it is). + */ +u_int +prism_if_print(const struct pcap_pkthdr *h, const u_char *p) +{ + u_int caplen = h->caplen; + u_int length = h->len; + + if (caplen < 4) { + printf("[|802.11]"); + return caplen; + } + + if (EXTRACT_32BITS(p) == WLANCAP_MAGIC_COOKIE_V1) + return ieee802_11_radio_print(p, length, caplen); + + if (caplen < PRISM_HDR_LEN) { + printf("[|802.11]"); + return caplen; + } + + return PRISM_HDR_LEN + ieee802_11_print(p + PRISM_HDR_LEN, + length - PRISM_HDR_LEN, caplen - PRISM_HDR_LEN); +} + +/* + * For DLT_IEEE802_11_RADIO; like DLT_IEEE802_11, but with an extra + * header, containing information such as radio information, which we + * currently ignore. + */ +u_int +ieee802_11_radio_if_print(const struct pcap_pkthdr *h, const u_char *p) +{ + u_int caplen = h->caplen; + u_int length = h->len; + + if (caplen < 8) { + printf("[|802.11]"); + return caplen; + } + + return ieee802_11_radio_print(p, length, caplen); +} diff --git a/kame/kame/tcpdump/print-ah.c b/kame/kame/tcpdump/print-ah.c index 69855f49ce..4094c25984 100644 --- a/kame/kame/tcpdump/print-ah.c +++ b/kame/kame/tcpdump/print-ah.c @@ -1,5 +1,7 @@ +/* $NetBSD: print-ah.c,v 1.4 1996/05/20 00:41:16 fvdl Exp $ */ + /* - * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994 + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -20,63 +22,50 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) /master/usr.sbin/tcpdump/tcpdump/print-icmp.c,v 2.1 1995/02/03 18:14:42 polk Exp (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-ah.c,v 1.19.2.3 2003/11/19 00:35:43 guy Exp $ (LBL)"; #endif -#include -#include -#include -#include - -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include -#include +#include "ah.h" #include "interface.h" #include "addrtoname.h" +#include "extract.h" int -ah_print(register const u_char *bp, register const u_char *bp2) +ah_print(register const u_char *bp) { register const struct ah *ah; register const u_char *ep; int sumlen; u_int32_t spi; - ah = (struct ah *)bp; - ep = snapend; /* 'ep' points to the end of avaible data. */ + 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); + spi = EXTRACT_32BITS(&ah->ah_spi); - printf("AH(spi=%u", spi); + printf("AH(spi=0x%08x", spi); if (vflag) printf(",sumlen=%d", sumlen); - if (Rflag) - printf(",seq=0x%x", (u_int32_t)ntohl(*(u_int32_t *)(ah + 1))); + printf(",seq=0x%x", EXTRACT_32BITS(ah + 1)); if (bp + sizeof(struct ah) + sumlen > ep) fputs("[truncated]", stdout); fputs("): ", stdout); - + return sizeof(struct ah) + sumlen; trunc: fputs("[|AH]", stdout); - return 65535; + return -1; } diff --git a/kame/kame/tcpdump/print-aodv.c b/kame/kame/tcpdump/print-aodv.c new file mode 100644 index 0000000000..099e3554f6 --- /dev/null +++ b/kame/kame/tcpdump/print-aodv.c @@ -0,0 +1,455 @@ +/* + * Copyright (c) 2003 Bruce M. Simpson + * 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 Bruce M. Simpson. + * 4. Neither the name of Bruce M. Simpson nor the names of co- + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bruce M. Simpson 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 Bruce M. Simpson 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[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-aodv.c,v 1.8.2.3 2004/03/24 00:30:41 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" /* must come after interface.h */ + +#include "aodv.h" + +static void +aodv_extension(const struct aodv_ext *ep, u_int length) +{ + u_int i; + const struct aodv_hello *ah; + + switch (ep->type) { + case AODV_EXT_HELLO: + if (snapend < (u_char *) ep) { + printf(" [|hello]"); + return; + } + i = min(length, (u_int)(snapend - (u_char *)ep)); + if (i < sizeof(struct aodv_hello)) { + printf(" [|hello]"); + return; + } + i -= sizeof(struct aodv_hello); + ah = (void *)ep; + printf("\n\text HELLO %ld ms", + (unsigned long)EXTRACT_32BITS(&ah->interval)); + break; + + default: + printf("\n\text %u %u", ep->type, ep->length); + break; + } +} + +static void +aodv_rreq(const union aodv *ap, const u_char *dat, u_int length) +{ + u_int i; + + if (snapend < dat) { + printf(" [|aodv]"); + return; + } + i = min(length, (u_int)(snapend - dat)); + if (i < sizeof(ap->rreq)) { + printf(" [|rreq]"); + return; + } + i -= sizeof(ap->rreq); + printf(" rreq %u %s%s%s%s%shops %u id 0x%08lx\n" + "\tdst %s seq %lu src %s seq %lu", length, + ap->rreq.rreq_type & RREQ_JOIN ? "[J]" : "", + ap->rreq.rreq_type & RREQ_REPAIR ? "[R]" : "", + ap->rreq.rreq_type & RREQ_GRAT ? "[G]" : "", + ap->rreq.rreq_type & RREQ_DEST ? "[D]" : "", + ap->rreq.rreq_type & RREQ_UNKNOWN ? "[U] " : " ", + ap->rreq.rreq_hops, + (unsigned long)EXTRACT_32BITS(&ap->rreq.rreq_id), + ipaddr_string(&ap->rreq.rreq_da), + (unsigned long)EXTRACT_32BITS(&ap->rreq.rreq_ds), + ipaddr_string(&ap->rreq.rreq_oa), + (unsigned long)EXTRACT_32BITS(&ap->rreq.rreq_os)); + if (i >= sizeof(struct aodv_ext)) + aodv_extension((void *)(&ap->rreq + 1), i); +} + +static void +aodv_rrep(const union aodv *ap, const u_char *dat, u_int length) +{ + u_int i; + + if (snapend < dat) { + printf(" [|aodv]"); + return; + } + i = min(length, (u_int)(snapend - dat)); + if (i < sizeof(ap->rrep)) { + printf(" [|rrep]"); + return; + } + i -= sizeof(ap->rrep); + printf(" rrep %u %s%sprefix %u hops %u\n" + "\tdst %s dseq %lu src %s %lu ms", length, + ap->rrep.rrep_type & RREP_REPAIR ? "[R]" : "", + ap->rrep.rrep_type & RREP_ACK ? "[A] " : " ", + ap->rrep.rrep_ps & RREP_PREFIX_MASK, + ap->rrep.rrep_hops, + ipaddr_string(&ap->rrep.rrep_da), + (unsigned long)EXTRACT_32BITS(&ap->rrep.rrep_ds), + ipaddr_string(&ap->rrep.rrep_oa), + (unsigned long)EXTRACT_32BITS(&ap->rrep.rrep_life)); + if (i >= sizeof(struct aodv_ext)) + aodv_extension((void *)(&ap->rrep + 1), i); +} + +static void +aodv_rerr(const union aodv *ap, const u_char *dat, u_int length) +{ + u_int i; + const struct rerr_unreach *dp = NULL; + int n, trunc; + + if (snapend < dat) { + printf(" [|aodv]"); + return; + } + i = min(length, (u_int)(snapend - dat)); + if (i < offsetof(struct aodv_rerr, r)) { + printf(" [|rerr]"); + return; + } + i -= offsetof(struct aodv_rerr, r); + dp = &ap->rerr.r.dest[0]; + n = ap->rerr.rerr_dc * sizeof(ap->rerr.r.dest[0]); + printf(" rerr %s [items %u] [%u]:", + ap->rerr.rerr_flags & RERR_NODELETE ? "[D]" : "", + ap->rerr.rerr_dc, length); + trunc = n - (i/sizeof(ap->rerr.r.dest[0])); + for (; i >= sizeof(ap->rerr.r.dest[0]); + ++dp, i -= sizeof(ap->rerr.r.dest[0])) { + printf(" {%s}(%ld)", ipaddr_string(&dp->u_da), + (unsigned long)EXTRACT_32BITS(&dp->u_ds)); + } + if (trunc) + printf("[|rerr]"); +} + +static void +#ifdef INET6 +aodv_v6_rreq(const union aodv *ap, const u_char *dat, u_int length) +#else +aodv_v6_rreq(const union aodv *ap _U_, const u_char *dat _U_, u_int length) +#endif +{ +#ifdef INET6 + u_int i; + + if (snapend < dat) { + printf(" [|aodv]"); + return; + } + i = min(length, (u_int)(snapend - dat)); + if (i < sizeof(ap->rreq6)) { + printf(" [|rreq6]"); + return; + } + i -= sizeof(ap->rreq6); + printf(" v6 rreq %u %s%s%s%s%shops %u id 0x%08lx\n" + "\tdst %s seq %lu src %s seq %lu", length, + ap->rreq6.rreq_type & RREQ_JOIN ? "[J]" : "", + ap->rreq6.rreq_type & RREQ_REPAIR ? "[R]" : "", + ap->rreq6.rreq_type & RREQ_GRAT ? "[G]" : "", + ap->rreq6.rreq_type & RREQ_DEST ? "[D]" : "", + ap->rreq6.rreq_type & RREQ_UNKNOWN ? "[U] " : " ", + ap->rreq6.rreq_hops, + (unsigned long)EXTRACT_32BITS(&ap->rreq6.rreq_id), + ip6addr_string(&ap->rreq6.rreq_da), + (unsigned long)EXTRACT_32BITS(&ap->rreq6.rreq_ds), + ip6addr_string(&ap->rreq6.rreq_oa), + (unsigned long)EXTRACT_32BITS(&ap->rreq6.rreq_os)); + if (i >= sizeof(struct aodv_ext)) + aodv_extension((void *)(&ap->rreq6 + 1), i); +#else + printf(" v6 rreq %u", length); +#endif +} + +static void +#ifdef INET6 +aodv_v6_rrep(const union aodv *ap, const u_char *dat, u_int length) +#else +aodv_v6_rrep(const union aodv *ap _U_, const u_char *dat _U_, u_int length) +#endif +{ +#ifdef INET6 + u_int i; + + if (snapend < dat) { + printf(" [|aodv]"); + return; + } + i = min(length, (u_int)(snapend - dat)); + if (i < sizeof(ap->rrep6)) { + printf(" [|rrep6]"); + return; + } + i -= sizeof(ap->rrep6); + printf(" rrep %u %s%sprefix %u hops %u\n" + "\tdst %s dseq %lu src %s %lu ms", length, + ap->rrep6.rrep_type & RREP_REPAIR ? "[R]" : "", + ap->rrep6.rrep_type & RREP_ACK ? "[A] " : " ", + ap->rrep6.rrep_ps & RREP_PREFIX_MASK, + ap->rrep6.rrep_hops, + ip6addr_string(&ap->rrep6.rrep_da), + (unsigned long)EXTRACT_32BITS(&ap->rrep6.rrep_ds), + ip6addr_string(&ap->rrep6.rrep_oa), + (unsigned long)EXTRACT_32BITS(&ap->rrep6.rrep_life)); + if (i >= sizeof(struct aodv_ext)) + aodv_extension((void *)(&ap->rrep6 + 1), i); +#else + printf(" rrep %u", length); +#endif +} + +static void +#ifdef INET6 +aodv_v6_rerr(const union aodv *ap, u_int length) +#else +aodv_v6_rerr(const union aodv *ap _U_, u_int length) +#endif +{ +#ifdef INET6 + const struct rerr_unreach6 *dp6 = NULL; + int i, j, n, trunc; + + i = length - offsetof(struct aodv_rerr, r); + j = sizeof(ap->rerr.r.dest6[0]); + dp6 = &ap->rerr.r.dest6[0]; + n = ap->rerr.rerr_dc * j; + printf(" rerr %s [items %u] [%u]:", + ap->rerr.rerr_flags & RERR_NODELETE ? "[D]" : "", + ap->rerr.rerr_dc, length); + trunc = n - (i/j); + for (; i -= j >= 0; ++dp6) { + printf(" {%s}(%ld)", ip6addr_string(&dp6->u_da), + (unsigned long)EXTRACT_32BITS(&dp6->u_ds)); + } + if (trunc) + printf("[|rerr]"); +#else + printf(" rerr %u", length); +#endif +} + +static void +#ifdef INET6 +aodv_v6_draft_01_rreq(const union aodv *ap, const u_char *dat, u_int length) +#else +aodv_v6_draft_01_rreq(const union aodv *ap _U_, const u_char *dat _U_, + u_int length) +#endif +{ +#ifdef INET6 + u_int i; + + if (snapend < dat) { + printf(" [|aodv]"); + return; + } + i = min(length, (u_int)(snapend - dat)); + if (i < sizeof(ap->rreq6_draft_01)) { + printf(" [|rreq6]"); + return; + } + i -= sizeof(ap->rreq6_draft_01); + printf(" rreq %u %s%s%s%s%shops %u id 0x%08lx\n" + "\tdst %s seq %lu src %s seq %lu", length, + ap->rreq6_draft_01.rreq_type & RREQ_JOIN ? "[J]" : "", + ap->rreq6_draft_01.rreq_type & RREQ_REPAIR ? "[R]" : "", + ap->rreq6_draft_01.rreq_type & RREQ_GRAT ? "[G]" : "", + ap->rreq6_draft_01.rreq_type & RREQ_DEST ? "[D]" : "", + ap->rreq6_draft_01.rreq_type & RREQ_UNKNOWN ? "[U] " : " ", + ap->rreq6_draft_01.rreq_hops, + (unsigned long)EXTRACT_32BITS(&ap->rreq6_draft_01.rreq_id), + ip6addr_string(&ap->rreq6_draft_01.rreq_da), + (unsigned long)EXTRACT_32BITS(&ap->rreq6_draft_01.rreq_ds), + ip6addr_string(&ap->rreq6_draft_01.rreq_oa), + (unsigned long)EXTRACT_32BITS(&ap->rreq6_draft_01.rreq_os)); + if (i >= sizeof(struct aodv_ext)) + aodv_extension((void *)(&ap->rreq6_draft_01 + 1), i); +#else + printf(" rreq %u", length); +#endif +} + +static void +#ifdef INET6 +aodv_v6_draft_01_rrep(const union aodv *ap, const u_char *dat, u_int length) +#else +aodv_v6_draft_01_rrep(const union aodv *ap _U_, const u_char *dat _U_, + u_int length) +#endif +{ +#ifdef INET6 + u_int i; + + if (snapend < dat) { + printf(" [|aodv]"); + return; + } + i = min(length, (u_int)(snapend - dat)); + if (i < sizeof(ap->rrep6_draft_01)) { + printf(" [|rrep6]"); + return; + } + i -= sizeof(ap->rrep6_draft_01); + printf(" rrep %u %s%sprefix %u hops %u\n" + "\tdst %s dseq %lu src %s %lu ms", length, + ap->rrep6_draft_01.rrep_type & RREP_REPAIR ? "[R]" : "", + ap->rrep6_draft_01.rrep_type & RREP_ACK ? "[A] " : " ", + ap->rrep6_draft_01.rrep_ps & RREP_PREFIX_MASK, + ap->rrep6_draft_01.rrep_hops, + ip6addr_string(&ap->rrep6_draft_01.rrep_da), + (unsigned long)EXTRACT_32BITS(&ap->rrep6_draft_01.rrep_ds), + ip6addr_string(&ap->rrep6_draft_01.rrep_oa), + (unsigned long)EXTRACT_32BITS(&ap->rrep6_draft_01.rrep_life)); + if (i >= sizeof(struct aodv_ext)) + aodv_extension((void *)(&ap->rrep6_draft_01 + 1), i); +#else + printf(" rrep %u", length); +#endif +} + +static void +#ifdef INET6 +aodv_v6_draft_01_rerr(const union aodv *ap, u_int length) +#else +aodv_v6_draft_01_rerr(const union aodv *ap _U_, u_int length) +#endif +{ +#ifdef INET6 + const struct rerr_unreach6_draft_01 *dp6 = NULL; + int i, j, n, trunc; + + i = length - offsetof(struct aodv_rerr, r); + j = sizeof(ap->rerr.r.dest6_draft_01[0]); + dp6 = &ap->rerr.r.dest6_draft_01[0]; + n = ap->rerr.rerr_dc * j; + printf(" rerr %s [items %u] [%u]:", + ap->rerr.rerr_flags & RERR_NODELETE ? "[D]" : "", + ap->rerr.rerr_dc, length); + trunc = n - (i/j); + for (; i -= j >= 0; ++dp6) { + printf(" {%s}(%ld)", ip6addr_string(&dp6->u_da), + (unsigned long)EXTRACT_32BITS(&dp6->u_ds)); + } + if (trunc) + printf("[|rerr]"); +#else + printf(" rerr %u", length); +#endif +} + +void +aodv_print(const u_char *dat, u_int length, int is_ip6) +{ + const union aodv *ap; + + ap = (union aodv *)dat; + if (snapend < dat) { + printf(" [|aodv]"); + return; + } + if (min(length, (u_int)(snapend - dat)) < sizeof(ap->rrep_ack)) { + printf(" [|aodv]"); + return; + } + printf(" aodv"); + + switch (ap->rerr.rerr_type) { + + case AODV_RREQ: + if (is_ip6) + aodv_v6_rreq(ap, dat, length); + else + aodv_rreq(ap, dat, length); + break; + + case AODV_RREP: + if (is_ip6) + aodv_v6_rrep(ap, dat, length); + else + aodv_rrep(ap, dat, length); + break; + + case AODV_RERR: + if (is_ip6) + aodv_v6_rerr(ap, length); + else + aodv_rerr(ap, dat, length); + break; + + case AODV_RREP_ACK: + printf(" rrep-ack %u", length); + break; + + case AODV_V6_DRAFT_01_RREQ: + aodv_v6_draft_01_rreq(ap, dat, length); + break; + + case AODV_V6_DRAFT_01_RREP: + aodv_v6_draft_01_rrep(ap, dat, length); + break; + + case AODV_V6_DRAFT_01_RERR: + aodv_v6_draft_01_rerr(ap, length); + break; + + case AODV_V6_DRAFT_01_RREP_ACK: + printf(" rrep-ack %u", length); + break; + + default: + printf(" %u %u", ap->rreq.rreq_type, length); + } +} diff --git a/kame/kame/tcpdump/print-ap1394.c b/kame/kame/tcpdump/print-ap1394.c new file mode 100644 index 0000000000..8c07456177 --- /dev/null +++ b/kame/kame/tcpdump/print-ap1394.c @@ -0,0 +1,119 @@ +/* + * 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 + * 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[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-ap1394.c,v 1.1.2.1 2004/03/17 22:15:53 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "ethertype.h" + +/* + * Structure of a header for Apple's IP-over-IEEE 1384 BPF header. + */ +#define FIREWIRE_EUI64_LEN 8 +struct firewire_header { + u_char firewire_dhost[FIREWIRE_EUI64_LEN]; + u_char firewire_shost[FIREWIRE_EUI64_LEN]; + u_short firewire_type; +}; + +/* + * Length of that header; note that some compilers may pad + * "struct firewire_header" to a multiple of 4 bytes, for example, so + * "sizeof (struct firewire_header)" may not give the right answer. + */ +#define FIREWIRE_HDRLEN 18 + +static inline void +ap1394_hdr_print(register const u_char *bp, u_int length) +{ + register const struct firewire_header *fp; + fp = (const struct firewire_header *)bp; + + (void)printf("%s > %s", + linkaddr_string(fp->firewire_dhost, FIREWIRE_EUI64_LEN), + linkaddr_string(fp->firewire_shost, FIREWIRE_EUI64_LEN)); + + if (!qflag) { + (void)printf(", ethertype %s (0x%04x)", + tok2str(ethertype_values,"Unknown", ntohs(fp->firewire_type)), + ntohs(fp->firewire_type)); + } else { + (void)printf(", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", ntohs(fp->firewire_type))); + } + + (void)printf(", length %u: ", length); +} + +/* + * This is the top level routine of the printer. 'p' points + * to the ether header of the packet, 'h->ts' is the timestamp, + * 'h->length' is the length of the packet off the wire, and 'h->caplen' + * is the number of bytes actually captured. + */ +u_int +ap1394_if_print(const struct pcap_pkthdr *h, const u_char *p) +{ + u_int length = h->len; + u_int caplen = h->caplen; + struct firewire_header *fp; + u_short ether_type; + u_short extracted_ether_type; + + if (caplen < FIREWIRE_HDRLEN) { + printf("[|ap1394]"); + return FIREWIRE_HDRLEN; + } + + if (eflag) + ap1394_hdr_print(p, length); + + length -= FIREWIRE_HDRLEN; + caplen -= FIREWIRE_HDRLEN; + fp = (struct firewire_header *)p; + p += FIREWIRE_HDRLEN; + + ether_type = ntohs(fp->firewire_type); + + extracted_ether_type = 0; + if (ether_encap_print(ether_type, p, length, caplen, + &extracted_ether_type) == 0) { + /* ether_type not known, print raw packet */ + if (!eflag) + ap1394_hdr_print((u_char *)fp, length + FIREWIRE_HDRLEN); + + if (!xflag && !qflag) + default_print(p, caplen); + } + + return FIREWIRE_HDRLEN; +} diff --git a/kame/kame/tcpdump/print-arcnet.c b/kame/kame/tcpdump/print-arcnet.c new file mode 100644 index 0000000000..32bb161ad1 --- /dev/null +++ b/kame/kame/tcpdump/print-arcnet.c @@ -0,0 +1,290 @@ +/* + * 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[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-arcnet.c,v 1.15.2.2 2003/11/16 08:51:09 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include + +#include "interface.h" +#include "arcnet.h" + +static 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' points + * to the ARCNET header of the packet, 'h->ts' is the timestamp, + * 'h->length' is the length of the packet off the wire, and 'h->caplen' + * is the number of bytes actually captured. + */ +u_int +arcnet_if_print(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; + + if (caplen < ARC_HDRLEN) { + printf("[|arcnet]"); + return (caplen); + } + + 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]"); + return (caplen); + } + + if (ap->arc_flag == 0xff) { + if (caplen < ARC_HDRNEWLEN_EXC) { + arcnet_print(p, length, 0, 0, 0); + printf("[|phds extended]"); + return (caplen); + } + flag = ap->arc_flag2; + seqid = ntohs(ap->arc_seqid2); + archdrlen = ARC_HDRNEWLEN_EXC; + } else { + flag = ap->arc_flag; + seqid = ntohs(ap->arc_seqid); + archdrlen = ARC_HDRNEWLEN; + } + } + + + if (eflag) + arcnet_print(p, length, phds, flag, seqid); + + /* + * Go past the ARCNET header. + */ + length -= archdrlen; + caplen -= archdrlen; + p += archdrlen; + + if (phds && flag && (flag & 1) == 0) { + /* + * This is a middle fragment. + */ + return (archdrlen); + } + + if (!arcnet_encap_print(arc_type, p, length, caplen)) + default_print(p, caplen); + + return (archdrlen); +} + +/* + * This is the top level routine of the printer. 'p' points + * to the ARCNET header of the packet, 'h->ts' is the timestamp, + * 'h->length' is the length of the packet off the wire, and 'h->caplen' + * is the number of bytes actually captured. It is quite similar + * to the non-Linux style printer except that Linux doesn't ever + * supply packets that look like exception frames, it always supplies + * reassembled packets rather than raw frames, and headers have an + * extra "offset" field between the src/dest and packet type. + */ +u_int +arcnet_linux_if_print(const struct pcap_pkthdr *h, const u_char *p) +{ + u_int caplen = h->caplen; + u_int length = h->len; + const struct arc_linux_header *ap; + + int archdrlen = 0; + u_char arc_type; + + if (caplen < ARC_LINUX_HDRLEN) { + printf("[|arcnet]"); + return (caplen); + } + + ap = (const struct arc_linux_header *)p; + arc_type = ap->arc_type; + + switch (arc_type) { + default: + archdrlen = ARC_LINUX_HDRNEWLEN; + if (caplen < ARC_LINUX_HDRNEWLEN) { + printf("[|arcnet]"); + return (caplen); + } + break; + case ARCTYPE_IP_OLD: + case ARCTYPE_ARP_OLD: + case ARCTYPE_DIAGNOSE: + archdrlen = ARC_LINUX_HDRLEN; + break; + } + + if (eflag) + arcnet_print(p, length, 0, 0, 0); + + /* + * Go past the ARCNET header. + */ + length -= archdrlen; + caplen -= archdrlen; + p += archdrlen; + + if (!arcnet_encap_print(arc_type, p, length, caplen)) + default_print(p, caplen); + + return (archdrlen); +} + +/* + * 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. + */ + + +static 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); + + case ARCTYPE_IPX: + ipx_print(p, length); + return (1); + + default: + return (0); + } +} diff --git a/kame/kame/tcpdump/print-arp.c b/kame/kame/tcpdump/print-arp.c index adafdf588f..da8e79960d 100644 --- a/kame/kame/tcpdump/print-arp.c +++ b/kame/kame/tcpdump/print-arp.c @@ -20,114 +20,311 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-arp.c,v 1.43 97/06/15 13:20:27 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-arp.c,v 1.61.2.2 2003/11/16 08:51:10 guy Exp $ (LBL)"; #endif -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include -#include -#include +#include -#ifdef HAVE_MEMORY_H -#include -#endif #include #include #include "interface.h" #include "addrtoname.h" +#include "ether.h" #include "ethertype.h" #include "extract.h" /* must come after interface.h */ -/* Compatibility */ -#ifndef REVARP_REQUEST -#define REVARP_REQUEST 3 +/* + * Address Resolution Protocol. + * + * See RFC 826 for protocol description. ARP packets are variable + * in size; the arphdr structure defines the fixed-length portion. + * Protocol type values are the same as those for 10 Mb/s Ethernet. + * It is followed by the variable-sized fields ar_sha, arp_spa, + * arp_tha and arp_tpa in that order, according to the lengths + * specified. Field names used correspond to RFC 826. + */ +struct arp_pkthdr { + 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 */ + u_short ar_op; /* one of: */ +#define ARPOP_REQUEST 1 /* request to resolve address */ +#define ARPOP_REPLY 2 /* response to previous request */ +#define ARPOP_REVREQUEST 3 /* request protocol address given hardware */ +#define ARPOP_REVREPLY 4 /* response giving protocol address */ +#define ARPOP_INVREQUEST 8 /* request to identify peer */ +#define ARPOP_INVREPLY 9 /* response identifying peer */ +/* + * The remaining fields are variable in size, + * according to the sizes above. + */ +#ifdef COMMENT_ONLY + u_char ar_sha[]; /* sender hardware address */ + u_char ar_spa[]; /* sender protocol address */ + u_char ar_tha[]; /* target hardware address */ + u_char ar_tpa[]; /* target protocol address */ #endif -#ifndef REVARP_REPLY -#define REVARP_REPLY 4 +#define ar_sha(ap) (((const u_char *)((ap)+1))+0) +#define ar_spa(ap) (((const u_char *)((ap)+1))+ (ap)->ar_hln) +#define ar_tha(ap) (((const u_char *)((ap)+1))+ (ap)->ar_hln+(ap)->ar_pln) +#define ar_tpa(ap) (((const u_char *)((ap)+1))+2*(ap)->ar_hln+(ap)->ar_pln) +}; + +#define ARP_HDRLEN 8 + +#define HRD(ap) EXTRACT_16BITS(&(ap)->ar_hrd) +#define HLN(ap) ((ap)->ar_hln) +#define PLN(ap) ((ap)->ar_pln) +#define OP(ap) EXTRACT_16BITS(&(ap)->ar_op) +#define PRO(ap) EXTRACT_16BITS(&(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)) + +/* + * ATM Address Resolution Protocol. + * + * See RFC 2225 for protocol description. ATMARP packets are similar + * to ARP packets, except that there are no length fields for the + * protocol address - instead, there are type/length fields for + * the ATM number and subaddress - and the hardware addresses consist + * of an ATM number and an ATM subaddress. + */ +struct atmarp_pkthdr { + u_short aar_hrd; /* format of hardware address */ +#define ARPHRD_ATM2225 19 /* ATM (RFC 2225) */ + u_short aar_pro; /* format of protocol address */ + u_char aar_shtl; /* length of source ATM number */ + u_char aar_sstl; /* length of source ATM subaddress */ +#define ATMARP_IS_E164 0x40 /* bit in type/length for E.164 format */ +#define ATMARP_LEN_MASK 0x3F /* length of {sub}address in type/length */ + u_short aar_op; /* same as regular ARP */ +#define ATMARPOP_NAK 10 /* NAK */ + u_char aar_spln; /* length of source protocol address */ + u_char aar_thtl; /* length of target ATM number */ + u_char aar_tstl; /* length of target ATM subaddress */ + u_char aar_tpln; /* length of target protocol address */ +/* + * The remaining fields are variable in size, + * according to the sizes above. + */ +#ifdef COMMENT_ONLY + u_char aar_sha[]; /* source ATM number */ + u_char aar_ssa[]; /* source ATM subaddress */ + u_char aar_spa[]; /* sender protocol address */ + u_char aar_tha[]; /* target ATM number */ + u_char aar_tsa[]; /* target ATM subaddress */ + u_char aar_tpa[]; /* target protocol address */ #endif +#define ATMHRD(ap) EXTRACT_16BITS(&(ap)->aar_hrd) +#define ATMSHLN(ap) ((ap)->aar_shtl & ATMARP_LEN_MASK) +#define ATMSSLN(ap) ((ap)->aar_sstl & ATMARP_LEN_MASK) +#define ATMSPLN(ap) ((ap)->aar_spln) +#define ATMOP(ap) EXTRACT_16BITS(&(ap)->aar_op) +#define ATMPRO(ap) EXTRACT_16BITS(&(ap)->aar_pro) +#define ATMTHLN(ap) ((ap)->aar_thtl & ATMARP_LEN_MASK) +#define ATMTSLN(ap) ((ap)->aar_tstl & ATMARP_LEN_MASK) +#define ATMTPLN(ap) ((ap)->aar_tpln) +#define aar_sha(ap) ((const u_char *)((ap)+1)) +#define aar_ssa(ap) (aar_sha(ap) + ATMSHLN(ap)) +#define aar_spa(ap) (aar_ssa(ap) + ATMSSLN(ap)) +#define aar_tha(ap) (aar_spa(ap) + ATMSPLN(ap)) +#define aar_tsa(ap) (aar_tha(ap) + ATMTHLN(ap)) +#define aar_tpa(ap) (aar_tsa(ap) + ATMTSLN(ap)) +}; + +#define ATMSHA(ap) (aar_sha(ap)) +#define ATMSSA(ap) (aar_ssa(ap)) +#define ATMSPA(ap) (aar_spa(ap)) +#define ATMTHA(ap) (aar_tha(ap)) +#define ATMTSA(ap) (aar_tsa(ap)) +#define ATMTPA(ap) (aar_tpa(ap)) + static u_char ezero[6]; +static void +atmarp_addr_print(const u_char *ha, u_int ha_len, const u_char *srca, + u_int srca_len) +{ + if (ha_len == 0) + (void)printf(""); + else { + (void)printf("%s", linkaddr_string(ha, ha_len)); + if (srca_len != 0) + (void)printf(",%s", linkaddr_string(srca, srca_len)); + } +} + +static void +atmarp_print(const u_char *bp, u_int length, u_int caplen) +{ + const struct atmarp_pkthdr *ap; + u_short pro, hrd, op; + + ap = (const struct atmarp_pkthdr *)bp; + TCHECK(*ap); + + hrd = ATMHRD(ap); + pro = ATMPRO(ap); + op = ATMOP(ap); + + if (!TTEST2(*aar_tpa(ap), ATMTPLN(ap))) { + (void)printf("truncated-atmarp"); + default_print((const u_char *)ap, length); + return; + } + + if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) || + ATMSPLN(ap) != 4 || ATMTPLN(ap) != 4) { + (void)printf("atmarp-#%d for proto #%d (%d/%d) hardware #%d", + op, pro, ATMSPLN(ap), ATMTPLN(ap), hrd); + return; + } + if (pro == ETHERTYPE_TRAIL) + (void)printf("trailer-"); + switch (op) { + + case ARPOP_REQUEST: + (void)printf("arp who-has %s", ipaddr_string(ATMTPA(ap))); + if (ATMTHLN(ap) != 0) { + (void)printf(" ("); + atmarp_addr_print(ATMTHA(ap), ATMTHLN(ap), + ATMTSA(ap), ATMTSLN(ap)); + (void)printf(")"); + } + (void)printf(" tell %s", ipaddr_string(ATMSPA(ap))); + break; + + case ARPOP_REPLY: + (void)printf("arp reply %s", ipaddr_string(ATMSPA(ap))); + (void)printf(" is-at "); + atmarp_addr_print(ATMSHA(ap), ATMSHLN(ap), ATMSSA(ap), + ATMSSLN(ap)); + break; + + case ARPOP_INVREQUEST: + (void)printf("invarp who-is "); + atmarp_addr_print(ATMTHA(ap), ATMTHLN(ap), ATMTSA(ap), + ATMTSLN(ap)); + (void)printf(" tell "); + atmarp_addr_print(ATMSHA(ap), ATMSHLN(ap), ATMSSA(ap), + ATMSSLN(ap)); + break; + + case ARPOP_INVREPLY: + (void)printf("invarp reply "); + atmarp_addr_print(ATMSHA(ap), ATMSHLN(ap), ATMSSA(ap), + ATMSSLN(ap)); + (void)printf(" at %s", ipaddr_string(ATMSPA(ap))); + break; + + case ATMARPOP_NAK: + (void)printf("nak reply for %s", + ipaddr_string(ATMSPA(ap))); + break; + + default: + (void)printf("atmarp-#%d", op); + default_print((const u_char *)ap, caplen); + return; + } + return; +trunc: + (void)printf("[|atmarp]"); +} + 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 arp_pkthdr *ap; + u_short pro, hrd, op; - ap = (struct ether_arp *)bp; - if ((u_char *)(ap + 1) > snapend) { - printf("[|arp]"); + ap = (const struct arp_pkthdr *)bp; + TCHECK(*ap); + hrd = HRD(ap); + if (hrd == ARPHRD_ATM2225) { + atmarp_print(bp, length, caplen); return; } - if (length < sizeof(struct ether_arp)) { + pro = PRO(ap); + op = OP(ap); + + if (!TTEST2(*ar_tpa(ap), PLN(ap))) { (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); - - 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) || + PLN(ap) != 4 || HLN(ap) == 0) { (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; + + case ARPOP_INVREQUEST: + (void)printf("invarp who-is %s tell %s", + linkaddr_string(THA(ap), HLN(ap)), + linkaddr_string(SHA(ap), HLN(ap))); + break; + + case ARPOP_INVREPLY: + (void)printf("invarp reply %s at %s", + 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/kame/kame/tcpdump/print-ascii.c b/kame/kame/tcpdump/print-ascii.c new file mode 100644 index 0000000000..b7f868d086 --- /dev/null +++ b/kame/kame/tcpdump/print-ascii.c @@ -0,0 +1,185 @@ +/* $NetBSD: print-ascii.c,v 1.1 1999/09/30 14:49:12 sjg Exp $ */ + +/*- + * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Alan Barrett and Simon J. Gerraty. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-ascii.c,v 1.10.2.3 2003/12/29 22:42:20 hannes Exp $"; +#endif +#include +#include + +#include "interface.h" + +#define ASCII_LINELENGTH 300 +#define HEXDUMP_BYTES_PER_LINE 16 +#define HEXDUMP_SHORTS_PER_LINE (HEXDUMP_BYTES_PER_LINE / 2) +#define HEXDUMP_HEXSTUFF_PER_SHORT 5 /* 4 hex digits and a space */ +#define HEXDUMP_HEXSTUFF_PER_LINE \ + (HEXDUMP_HEXSTUFF_PER_SHORT * HEXDUMP_SHORTS_PER_LINE) + +void +ascii_print_with_offset(register const u_char *ident, register const u_char *cp, register u_int length, + register u_int oset) +{ + register u_int i; + register int s1, s2; + register int nshorts; + char hexstuff[HEXDUMP_SHORTS_PER_LINE*HEXDUMP_HEXSTUFF_PER_SHORT+1], *hsp; + char asciistuff[ASCII_LINELENGTH+1], *asp; + u_int maxlength = (Aflag ? ASCII_LINELENGTH : HEXDUMP_SHORTS_PER_LINE); + + nshorts = length / sizeof(u_short); + i = 0; + hsp = hexstuff; asp = asciistuff; + if (Aflag) *(asp++) = '\n'; + while (--nshorts >= 0) { + s1 = *cp++; + s2 = *cp++; + if (Aflag) { + i += 2; + *(asp++) = (isgraph(s1) ? s1 : (s1 != '\t' && s1 != ' ' && s1 != '\n' && s1 != '\r' ? '.' : s1) ); + *(asp++) = (isgraph(s2) ? s2 : (s2 != '\t' && s2 != ' ' && s2 != '\n' && s2 != '\r' ? '.' : s2) ); + if (s1 == '\n' || s2 == '\n') i = maxlength; + + } else { + (void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff), + " %02x%02x", s1, s2); + hsp += HEXDUMP_HEXSTUFF_PER_SHORT; + *(asp++) = (isgraph(s1) ? s1 : '.'); + *(asp++) = (isgraph(s2) ? s2 : '.'); + i++; + } + if (i >= maxlength) { + *hsp = *asp = '\0'; + if (Aflag) { + (void)printf("%s", asciistuff); + } else { + (void)printf("%s0x%04x: %-*s %s", + ident, oset, HEXDUMP_HEXSTUFF_PER_LINE, + hexstuff, asciistuff); + } + i = 0; hsp = hexstuff; asp = asciistuff; + oset += HEXDUMP_BYTES_PER_LINE; + } + } + if (length & 1) { + s1 = *cp++; + if (Aflag) { + *(asp++) = (isgraph(s1) ? s1 : (s1 != '\t' && s1 != ' ' && s1 != '\n' && s1 != '\r' ? '.' : s1) ); + } else { + (void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff), + " %02x", s1); + hsp += 3; + *(asp++) = (isgraph(s1) ? s1 : '.'); + } + ++i; + } + if (i > 0) { + *hsp = *asp = '\0'; + if (Aflag) { + (void)printf("%s%s", ident, asciistuff); + } else { + (void)printf("%s0x%04x: %-*s %s", + ident, oset, HEXDUMP_HEXSTUFF_PER_LINE, + hexstuff, asciistuff); + } + } +} + +void +ascii_print(register const u_char *ident, register const u_char *cp, register u_int length) +{ + ascii_print_with_offset(ident, cp, length, 0); +} + +/* + * telnet_print() wants this. It is essentially default_print_unaligned() + */ +void +hex_print_with_offset(register const u_char *ident, register const u_char *cp, register u_int length, + register u_int oset) +{ + register u_int i, s; + register int nshorts; + + nshorts = (u_int) length / sizeof(u_short); + i = 0; + while (--nshorts >= 0) { + if ((i++ % 8) == 0) { + (void)printf("%s0x%04x: ", ident, oset); + oset += HEXDUMP_BYTES_PER_LINE; + } + s = *cp++; + (void)printf(" %02x%02x", s, *cp++); + } + if (length & 1) { + if ((i % 8) == 0) + (void)printf("%s0x%04x: ", ident, oset); + (void)printf(" %02x", *cp); + } +} + +/* + * just for completeness + */ +void +hex_print(register const u_char *ident, register const u_char *cp, register u_int length) +{ + hex_print_with_offset(ident, cp, length, 0); +} + +#ifdef MAIN +int +main(int argc, char *argv[]) +{ + hex_print("Hello, World!\n", 14); + printf("\n"); + ascii_print("Hello, World!\n", 14); + printf("\n"); +#define TMSG "Now is the winter of our discontent...\n" + ascii_print_with_offset(TMSG, sizeof(TMSG) - 1, 0x100); + printf("\n"); + exit(0); +} +#endif /* MAIN */ + + diff --git a/kame/kame/tcpdump/print-atalk.c b/kame/kame/tcpdump/print-atalk.c index 7a5e0c901a..30224821f8 100644 --- a/kame/kame/tcpdump/print-atalk.c +++ b/kame/kame/tcpdump/print-atalk.c @@ -22,39 +22,26 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-atalk.c,v 1.48 97/05/28 12:50:58 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-atalk.c,v 1.78.2.2 2003/11/16 08:51:11 guy Exp $ (LBL)"; #endif -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include #include +#include #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" }, @@ -67,13 +54,13 @@ static struct tok type2str[] = { }; struct aarp { - u_short htype, ptype; - u_char halen, palen; - u_short op; - u_char hsaddr[6]; - u_char psaddr[4]; - u_char hdaddr[6]; - u_char pdaddr[4]; + u_int16_t htype, ptype; + u_int8_t halen, palen; + u_int16_t op; + u_int8_t hsaddr[6]; + u_int8_t psaddr[4]; + u_int8_t hdaddr[6]; + u_int8_t pdaddr[4]; }; static char tstr[] = "[|atalk]"; @@ -92,25 +79,44 @@ static void ddp_print(const u_char *, u_int, int, u_short, u_char, u_char); static const char *ddpskt_string(int); /* - * Print AppleTalk Datagram Delivery Protocol packets. + * Print LLAP packets received on a physical LocalTalk interface. */ -void -atalk_print(register const u_char *bp, u_int length) +u_int +ltalk_if_print(const struct pcap_pkthdr *h, const u_char *p) +{ + return (llap_print(p, h->caplen)); +} + +/* + * Print AppleTalk LLAP packets. + */ +u_int +llap_print(register const u_char *bp, u_int length) { register const struct LAP *lp; register const struct atDDP *dp; register const struct atShortDDP *sdp; u_short snet; + u_int hdrlen; - lp = (struct LAP *)bp; + /* + * Our packet is on a 4-byte boundary, as we're either called + * directly from a top-level link-layer printer (ltalk_if_print) + * or from the UDP printer. The LLAP+DDP header is a multiple + * of 4 bytes in length, so the DDP payload is also on a 4-byte + * boundary, and we don't need to align it before calling + * "ddp_print()". + */ + lp = (const struct LAP *)bp; bp += sizeof(*lp); length -= sizeof(*lp); + hdrlen = sizeof(*lp); switch (lp->type) { case lapShortDDP: if (length < ddpSSize) { (void)printf(" [|sddp %d]", length); - return; + return (length); } sdp = (const struct atShortDDP *)bp; printf("%s.%s", @@ -119,13 +125,14 @@ atalk_print(register const u_char *bp, u_int length) ataddr_string(0, lp->dst), ddpskt_string(sdp->dstSkt)); bp += ddpSSize; length -= ddpSSize; + hdrlen += ddpSSize; ddp_print(bp, length, sdp->type, 0, lp->src, sdp->srcSkt); break; case lapDDP: if (length < ddpSize) { (void)printf(" [|ddp %d]", length); - return; + return (length); } dp = (const struct atDDP *)bp; snet = EXTRACT_16BITS(&dp->srcNet); @@ -136,6 +143,7 @@ atalk_print(register const u_char *bp, u_int length) ddpskt_string(dp->dstSkt)); bp += ddpSize; length -= ddpSize; + hdrlen += ddpSize; ddp_print(bp, length, dp->type, snet, dp->srcNode, dp->srcSkt); break; @@ -150,6 +158,34 @@ atalk_print(register const u_char *bp, u_int length) lp->src, lp->dst, lp->type, length); break; } + return (hdrlen); +} + +/* + * Print EtherTalk/TokenTalk packets (or FDDITalk, or whatever it's called + * when it runs over FDDI; yes, I've seen FDDI captures with AppleTalk + * packets in them). + */ +void +atalk_print(register const u_char *bp, u_int length) +{ + register const struct atDDP *dp; + u_short snet; + + if (length < ddpSize) { + (void)printf(" [|ddp %d]", length); + return; + } + dp = (const struct atDDP *)bp; + snet = EXTRACT_16BITS(&dp->srcNet); + printf("%s.%s", ataddr_string(snet, dp->srcNode), + ddpskt_string(dp->srcSkt)); + printf(" > %s.%s:", + ataddr_string(EXTRACT_16BITS(&dp->dstNet), dp->dstNode), + ddpskt_string(dp->dstSkt)); + bp += ddpSize; + length -= ddpSize; + ddp_print(bp, length, dp->type, snet, dp->srcNode, dp->srcSkt); } /* XXX should probably pass in the snap header and do checks like arp_print() */ @@ -162,9 +198,10 @@ aarp_print(register const u_char *bp, u_int length) printf("aarp "); ap = (const struct aarp *)bp; - if (ap->htype == 1 && ap->ptype == ETHERTYPE_ATALK && + if (EXTRACT_16BITS(&ap->htype) == 1 && + EXTRACT_16BITS(&ap->ptype) == ETHERTYPE_ATALK && ap->halen == 6 && ap->palen == 4 ) - switch (ap->op) { + switch (EXTRACT_16BITS(&ap->op)) { case 1: /* request */ (void)printf("who-has %s tell %s", @@ -181,10 +218,14 @@ aarp_print(register const u_char *bp, u_int length) AT(pdaddr), AT(psaddr)); return; } - (void)printf("len %d op %d htype %d ptype %#x halen %d palen %d", - length, ap->op, ap->htype, ap->ptype, ap->halen, ap->palen ); + (void)printf("len %u op %u htype %u ptype %#x halen %u palen %u", + length, EXTRACT_16BITS(&ap->op), EXTRACT_16BITS(&ap->htype), + EXTRACT_16BITS(&ap->ptype), ap->halen, ap->palen); } +/* + * Print AppleTalk Datagram Delivery Protocol packets. + */ static void ddp_print(register const u_char *bp, register u_int length, register int t, register u_short snet, register u_char snode, u_char skt) @@ -334,10 +375,15 @@ 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; + if (length < nbpHeaderSize) { + (void)printf(" truncated-nbp %d", length); + return; + } + length -= nbpHeaderSize; if (length < 8) { /* must be room for at least one tuple */ @@ -410,7 +456,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); } @@ -487,7 +533,7 @@ ataddr_string(u_short atnet, u_char athost) { register struct hnamemem *tp, *tp2; register int i = (atnet << 8) | athost; - char nambuf[256]; + char nambuf[MAXHOSTNAMELEN + 20]; static int first = 1; FILE *fp; @@ -503,11 +549,11 @@ ataddr_string(u_short atnet, u_char athost) while (fgets(line, sizeof(line), fp)) { if (line[0] == '\n' || line[0] == 0 || line[0] == '#') continue; - if (sscanf(line, "%d.%d.%d %s", &i1, &i2, &i3, + if (sscanf(line, "%d.%d.%d %256s", &i1, &i2, &i3, nambuf) == 4) /* got a hostname. */ i3 |= ((i1 << 8) | i2) << 8; - else if (sscanf(line, "%d.%d %s", &i1, &i2, + else if (sscanf(line, "%d.%d %256s", &i1, &i2, nambuf) == 3) /* got a net name */ i3 = (((i1 << 8) | i2) << 8) | 255; @@ -519,7 +565,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); } @@ -534,19 +580,21 @@ ataddr_string(u_short atnet, u_char athost) if (tp2->addr == i) { tp->addr = (atnet << 8) | athost; tp->nxt = newhnamemem(); - (void)sprintf(nambuf, "%s.%d", tp2->name, athost); - tp->name = savestr(nambuf); + (void)snprintf(nambuf, sizeof(nambuf), "%s.%d", + tp2->name, athost); + tp->name = strdup(nambuf); return (tp->name); } tp->addr = (atnet << 8) | athost; tp->nxt = newhnamemem(); if (athost != 255) - (void)sprintf(nambuf, "%d.%d.%d", + (void)snprintf(nambuf, sizeof(nambuf), "%d.%d.%d", atnet >> 8, atnet & 0xff, athost); else - (void)sprintf(nambuf, "%d.%d", atnet >> 8, atnet & 0xff); - tp->name = savestr(nambuf); + (void)snprintf(nambuf, sizeof(nambuf), "%d.%d", atnet >> 8, + atnet & 0xff); + tp->name = strdup(nambuf); return (tp->name); } @@ -565,7 +613,7 @@ ddpskt_string(register int skt) static char buf[8]; if (nflag) { - (void)sprintf(buf, "%d", skt); + (void)snprintf(buf, sizeof(buf), "%d", skt); return (buf); } return (tok2str(skt2str, "%d", skt)); diff --git a/kame/kame/tcpdump/print-atm.c b/kame/kame/tcpdump/print-atm.c index aa8bfb6a1a..a6cfa11e11 100644 --- a/kame/kame/tcpdump/print-atm.c +++ b/kame/kame/tcpdump/print-atm.c @@ -19,135 +19,225 @@ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-atm.c,v 1.9 97/05/28 12:52:40 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-atm.c,v 1.33.2.2 2003/11/16 08:51:11 guy Exp $ (LBL)"; #endif -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include +#include #include "interface.h" +#include "extract.h" #include "addrtoname.h" #include "ethertype.h" +#include "atm.h" +#include "atmuni31.h" +#include "llc.h" + +#include "ether.h" + +/* + * Print an RFC 1483 LLC-encapsulated ATM frame. + */ +static void +atm_llc_print(const u_char *p, int length, int caplen) +{ + u_short extracted_ethertype; + + if (!llc_print(p, length, caplen, NULL, NULL, + &extracted_ethertype)) { + /* ether_type not known, print raw packet */ + if (extracted_ethertype) { + printf("(LLC %s) ", + etherproto_string(htons(extracted_ethertype))); + } + if (!xflag && !qflag) + default_print(p, caplen); + } +} + +/* + * Given a SAP value, generate the LLC header value for a UI packet + * with that SAP as the source and destination SAP. + */ +#define LLC_UI_HDR(sap) ((sap)<<16 | (sap<<8) | 0x03) /* - * This is the top level routine of the printer. 'p' is the points - * to the LLC/SNAP header of the packet, 'tvp' is the timestamp, - * 'length' is the length of the packet off the wire, and 'caplen' + * This is the top level routine of the printer. 'p' points + * to the LLC/SNAP header of the packet, 'h->ts' 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 -atm_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) +u_int +atm_if_print(const struct pcap_pkthdr *h, const u_char *p) { u_int caplen = h->caplen; u_int length = h->len; - u_short ethertype; - - ts_print(&h->ts); + u_int32_t llchdr; + u_int hdrlen = 0; if (caplen < 8) { printf("[|atm]"); - goto out; + return (caplen); } - if (p[0] != 0xaa || p[1] != 0xaa || p[2] != 0x03) { - /*XXX assume 802.6 MAC header from fore driver */ + + /* + * Extract the presumed LLC header into a variable, for quick + * testing. + * Then check for a header that's neither a header for a SNAP + * packet nor an RFC 2684 routed NLPID-formatted PDU nor + * an 802.2-but-no-SNAP IP packet. + */ + llchdr = EXTRACT_24BITS(p); + if (llchdr != LLC_UI_HDR(LLCSAP_SNAP) && + llchdr != LLC_UI_HDR(LLCSAP_ISONS) && + llchdr != LLC_UI_HDR(LLCSAP_IP)) { + /* + * XXX - assume 802.6 MAC header from Fore driver. + * + * Unfortunately, the above list doesn't check for + * all known SAPs, doesn't check for headers where + * the source and destination SAP aren't the same, + * and doesn't check for non-UI frames. It also + * runs the risk of an 802.6 MAC header that happens + * to begin with one of those values being + * incorrectly treated as an 802.2 header. + * + * So is that Fore driver still around? And, if so, + * is it still putting 802.6 MAC headers on ATM + * packets? If so, could it be changed to use a + * new DLT_IEEE802_6 value if we added it? + */ if (eflag) - printf("%04x%04x %04x%04x ", - p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3], - p[4] << 24 | p[5] << 16 | p[6] << 8 | p[7], - p[8] << 24 | p[9] << 16 | p[10] << 8 | p[11], - p[12] << 24 | p[13] << 16 | p[14] << 8 | p[15]); + printf("%08x%08x %08x%08x ", + EXTRACT_32BITS(p), + EXTRACT_32BITS(p+4), + EXTRACT_32BITS(p+8), + EXTRACT_32BITS(p+12)); p += 20; length -= 20; caplen -= 20; + hdrlen += 20; } - ethertype = p[6] << 8 | p[7]; + atm_llc_print(p, length, caplen); + return (hdrlen); +} + +/* + * ATM signalling. + */ +static struct tok msgtype2str[] = { + { CALL_PROCEED, "Call_proceeding" }, + { CONNECT, "Connect" }, + { CONNECT_ACK, "Connect_ack" }, + { SETUP, "Setup" }, + { RELEASE, "Release" }, + { RELEASE_DONE, "Release_complete" }, + { RESTART, "Restart" }, + { RESTART_ACK, "Restart_ack" }, + { STATUS, "Status" }, + { STATUS_ENQ, "Status_enquiry" }, + { ADD_PARTY, "Add_party" }, + { ADD_PARTY_ACK, "Add_party_ack" }, + { ADD_PARTY_REJ, "Add_party_reject" }, + { DROP_PARTY, "Drop_party" }, + { DROP_PARTY_ACK, "Drop_party_ack" }, + { 0, NULL } +}; + +static void +sig_print(const u_char *p, int caplen) +{ + bpf_u_int32 call_ref; + + if (caplen < PROTO_POS) { + printf("[|atm]"); + return; + } + if (p[PROTO_POS] == Q2931) { + /* + * protocol:Q.2931 for User to Network Interface + * (UNI 3.1) signalling + */ + printf("Q.2931"); + if (caplen < MSG_TYPE_POS) { + printf(" [|atm]"); + return; + } + printf(":%s ", + tok2str(msgtype2str, "msgtype#%d", p[MSG_TYPE_POS])); + + if (caplen < CALL_REF_POS+3) { + printf("[|atm]"); + return; + } + call_ref = EXTRACT_24BITS(&p[CALL_REF_POS]); + printf("CALL_REF:0x%06x", call_ref); + } else { + /* SCCOP with some unknown protocol atop it */ + printf("SSCOP, proto %d ", p[PROTO_POS]); + } +} + +/* + * Print an ATM PDU (such as an AAL5 PDU). + */ +void +atm_print(u_int vpi, u_int vci, u_int traftype, const u_char *p, u_int length, + u_int caplen) +{ if (eflag) - printf("%02x %02x %02x %02x-%02x-%02x %04x: ", - p[0], p[1], p[2], /* dsap/ssap/ctrl */ - p[3], p[4], p[5], /* manufacturer's code */ - ethertype); + printf("VPI:%u VCI:%u ", vpi, vci); - /* - * 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; + if (vpi == 0) { + switch (vci) { - length -= 8; - caplen -= 8; - p += 8; + case PPC: + sig_print(p, caplen); + return; - switch (ethertype) { + case BCC: + printf("broadcast sig: "); + return; - case ETHERTYPE_IP: - ip_print(p, length); - break; + case OAMF4SC: + printf("oamF4(segment): "); + return; -#ifdef INET6 - case ETHERTYPE_IPV6: - ip6_print(p, length); - break; -#endif /*INET6*/ + case OAMF4EC: + printf("oamF4(end): "); + return; - /*XXX this probably isn't right */ - case ETHERTYPE_ARP: - case ETHERTYPE_REVARP: - arp_print(p, length, caplen); - break; -#ifdef notyet - case ETHERTYPE_DN: - decnet_print(p, length, caplen); - break; + case METAC: + printf("meta: "); + return; - case ETHERTYPE_ATALK: - if (vflag) - fputs("et1 ", stdout); - atalk_print(p, length); - break; + case ILMIC: + printf("ilmi: "); + snmp_print(p, length); + return; + } + } - case ETHERTYPE_AARP: - aarp_print(p, length); - break; + switch (traftype) { - case ETHERTYPE_LAT: - case ETHERTYPE_MOPRC: - case ETHERTYPE_MOPDL: - /* default_print for now */ -#endif + case ATM_LLC: default: - /* ether_type not known, print raw packet */ - if (!eflag) - printf("%02x %02x %02x %02x-%02x-%02x %04x: ", - p[0], p[1], p[2], /* dsap/ssap/ctrl */ - p[3], p[4], p[5], /* manufacturer's code */ - ethertype); - if (!xflag && !qflag) - default_print(p, caplen); + /* + * Assumes traffic is LLC if unknown. + */ + atm_llc_print(p, length, caplen); + break; + + case ATM_LANE: + lane_print(p, length, caplen); + break; } - if (xflag) - default_print(p, caplen); - out: - putchar('\n'); } diff --git a/kame/kame/tcpdump/print-beep.c b/kame/kame/tcpdump/print-beep.c new file mode 100644 index 0000000000..b566254670 --- /dev/null +++ b/kame/kame/tcpdump/print-beep.c @@ -0,0 +1,71 @@ +/* + * 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[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-beep.c,v 1.4.2.2 2003/11/16 08:51:12 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#ifdef HAVE_MEMORY_H +#include +#endif +#include +#include +#include + +#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, (const char *)bp, length)) /* A REQuest */ + printf(" BEEP MSG"); + else if (l_strnstart("RPY ", 4, (const char *)bp, length)) + printf(" BEEP RPY"); + else if (l_strnstart("ERR ", 4, (const char *)bp, length)) + printf(" BEEP ERR"); + else if (l_strnstart("ANS ", 4, (const char *)bp, length)) + printf(" BEEP ANS"); + else if (l_strnstart("NUL ", 4, (const char *)bp, length)) + printf(" BEEP NUL"); + else if (l_strnstart("SEQ ", 4, (const char *)bp, length)) + printf(" BEEP SEQ"); + else if (l_strnstart("END", 4, (const char *)bp, length)) + printf(" BEEP END"); + else + printf(" BEEP (payload or undecoded)"); +} diff --git a/kame/kame/tcpdump/print-bfd.c b/kame/kame/tcpdump/print-bfd.c new file mode 100644 index 0000000000..2c6aec4029 --- /dev/null +++ b/kame/kame/tcpdump/print-bfd.c @@ -0,0 +1,160 @@ +/* + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code + * distributions retain the above copyright notice and this paragraph + * in its entirety, and (2) distributions including binary code include + * the above copyright notice and this paragraph in its entirety in + * the documentation or other materials provided with the distribution. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND + * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT + * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * Original code by Hannes Gredler (hannes@juniper.net) + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-bfd.c,v 1.3.2.2 2003/11/16 08:51:12 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include + +#include "interface.h" +#include "extract.h" +#include "addrtoname.h" + +#include "udp.h" + +/* + * Control packet, draft-katz-ward-bfd-01.txt + * + * 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 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |Vers | Diag |H|D|P|F| Rsvd | Detect Mult | Length | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | My Discriminator | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Your Discriminator | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Desired Min TX Interval | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Required Min RX Interval | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Required Min Echo RX Interval | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +struct bfd_header_t { + u_int8_t version_diag; + u_int8_t flags; + u_int8_t detect_time_multiplier; + u_int8_t length; + u_int8_t my_discriminator[4]; + u_int8_t your_discriminator[4]; + u_int8_t desired_min_tx_interval[4]; + u_int8_t required_min_rx_interval[4]; + u_int8_t required_min_echo_interval[4]; +}; + +#define BFD_EXTRACT_VERSION(x) (((x)&0xe0)>>5) +#define BFD_EXTRACT_DIAG(x) ((x)&0x1f) + +static const struct tok bfd_port_values[] = { + { BFD_CONTROL_PORT, "Control" }, + { BFD_ECHO_PORT, "Echo" }, + { 0, NULL } +}; + + +static const struct tok bfd_diag_values[] = { + { 0, "No Diagnostic" }, + { 1, "Control Detection Time Expired" }, + { 2, "Echo Function Failed" }, + { 3, "Neighbor Signaled Session Down" }, + { 4, "Forwarding Plane Reset" }, + { 5, "Path Down" }, + { 6, "Concatenated Path Down" }, + { 7, "Administratively Down" }, + { 0, NULL } +}; + +static const struct tok bfd_flag_values[] = { + { 0x80, "I Hear You" }, + { 0x40, "Demand" }, + { 0x20, "Poll" }, + { 0x10, "Final" }, + { 0x08, "Reserved" }, + { 0x04, "Reserved" }, + { 0x02, "Reserved" }, + { 0x01, "Reserved" }, + { 0, NULL } +}; + +void +bfd_print(register const u_char *pptr, register u_int len, register u_int port) +{ + const struct bfd_header_t *bfd_header; + + bfd_header = (const struct bfd_header_t *)pptr; + TCHECK(*bfd_header); + + switch (port) { + + case BFD_CONTROL_PORT: + if (vflag < 1 ) + { + printf("BFDv%u, %s, Flags: [%s], length: %u", + BFD_EXTRACT_VERSION(bfd_header->version_diag), + tok2str(bfd_port_values, "unknown (%u)", port), + bittok2str(bfd_flag_values, "none", bfd_header->flags), + len); + return; + } + + printf("BFDv%u, length: %u\n\t%s, Flags: [%s], Diagnostic: %s (0x%02x)", + BFD_EXTRACT_VERSION(bfd_header->version_diag), + len, + tok2str(bfd_port_values, "unknown (%u)", port), + bittok2str(bfd_flag_values, "none", bfd_header->flags), + tok2str(bfd_diag_values,"unknown",BFD_EXTRACT_DIAG(bfd_header->version_diag)), + BFD_EXTRACT_DIAG(bfd_header->version_diag)); + + printf("\n\tDetection Timer Multiplier: %u (%u ms Detection time), BFD Length: %u", + bfd_header->detect_time_multiplier, + bfd_header->detect_time_multiplier * EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000, + bfd_header->length); + + + printf("\n\tMy Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->my_discriminator)); + printf(", Your Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->your_discriminator)); + printf("\n\t Desired min Tx Interval: %4u ms", EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000); + printf("\n\t Required min Rx Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_rx_interval)/1000); + printf("\n\t Required min Echo Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_echo_interval)/1000); + break; + + case BFD_ECHO_PORT: /* not yet supported - fall through */ + + default: + printf("BFD, %s, length: %u", + tok2str(bfd_port_values, "unknown (%u)", port), + len); + if (vflag >= 1) { + if(!print_unknown_data(pptr,"\n\t",len)) + return; + } + break; + } + return; + +trunc: + printf("[|BFD]"); +} diff --git a/kame/kame/tcpdump/print-bgp.c b/kame/kame/tcpdump/print-bgp.c new file mode 100644 index 0000000000..bfa472a83f --- /dev/null +++ b/kame/kame/tcpdump/print-bgp.c @@ -0,0 +1,1859 @@ +/* + * Copyright (C) 1999 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. + * + * Extensively modified by Hannes Gredler (hannes@juniper.net) for more + * complete BGP support. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.72.2.4 2004/03/24 00:04:04 guy Exp $"; +#endif + +#include + +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" + +struct bgp { + u_int8_t bgp_marker[16]; + u_int16_t bgp_len; + u_int8_t bgp_type; +}; +#define BGP_SIZE 19 /* unaligned */ + +#define BGP_OPEN 1 +#define BGP_UPDATE 2 +#define BGP_NOTIFICATION 3 +#define BGP_KEEPALIVE 4 +#define BGP_ROUTE_REFRESH 5 + +static struct tok bgp_msg_values[] = { + { BGP_OPEN, "Open"}, + { BGP_UPDATE, "Update"}, + { BGP_NOTIFICATION, "Notification"}, + { BGP_KEEPALIVE, "Keepalive"}, + { BGP_ROUTE_REFRESH, "Route Refresh"}, + { 0, NULL} +}; + +struct bgp_open { + u_int8_t bgpo_marker[16]; + u_int16_t bgpo_len; + u_int8_t bgpo_type; + u_int8_t bgpo_version; + u_int16_t bgpo_myas; + u_int16_t bgpo_holdtime; + u_int32_t bgpo_id; + 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]; + u_int16_t bgpn_len; + u_int8_t bgpn_type; + u_int8_t bgpn_major; + u_int8_t bgpn_minor; +}; +#define BGP_NOTIFICATION_SIZE 21 /* unaligned */ + +struct bgp_route_refresh { + u_int8_t bgp_marker[16]; + u_int16_t len; + u_int8_t type; + u_int8_t afi[2]; /* the compiler messes this structure up */ + u_int8_t res; /* when doing misaligned sequences of int8 and int16 */ + u_int8_t safi; /* afi should be int16 - so we have to access it using */ +}; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */ +#define BGP_ROUTE_REFRESH_SIZE 23 + +struct bgp_attr { + u_int8_t bgpa_flags; + u_int8_t bgpa_type; + union { + u_int8_t len; + u_int16_t elen; + } bgpa_len; +#define bgp_attr_len(p) \ + (((p)->bgpa_flags & 0x10) ? \ + EXTRACT_16BITS(&(p)->bgpa_len.elen) : (p)->bgpa_len.len) +#define bgp_attr_off(p) \ + (((p)->bgpa_flags & 0x10) ? 4 : 3) +}; + +#define BGPTYPE_ORIGIN 1 +#define BGPTYPE_AS_PATH 2 +#define BGPTYPE_NEXT_HOP 3 +#define BGPTYPE_MULTI_EXIT_DISC 4 +#define BGPTYPE_LOCAL_PREF 5 +#define BGPTYPE_ATOMIC_AGGREGATE 6 +#define BGPTYPE_AGGREGATOR 7 +#define BGPTYPE_COMMUNITIES 8 /* RFC1997 */ +#define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */ +#define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */ +#define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */ +#define BGPTYPE_ADVERTISERS 12 /* RFC1863 */ +#define BGPTYPE_RCID_PATH 13 /* RFC1863 */ +#define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */ +#define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */ +#define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */ + +static struct tok bgp_attr_values[] = { + { BGPTYPE_ORIGIN, "Origin"}, + { BGPTYPE_AS_PATH, "AS Path"}, + { BGPTYPE_NEXT_HOP, "Next Hop"}, + { BGPTYPE_MULTI_EXIT_DISC, "Multi Exit Discriminator"}, + { BGPTYPE_LOCAL_PREF, "Local Preference"}, + { BGPTYPE_ATOMIC_AGGREGATE, "Atomic Aggregate"}, + { BGPTYPE_AGGREGATOR, "Aggregator"}, + { BGPTYPE_COMMUNITIES, "Community"}, + { BGPTYPE_ORIGINATOR_ID, "Originator ID"}, + { BGPTYPE_CLUSTER_LIST, "Cluster List"}, + { BGPTYPE_DPA, "DPA"}, + { BGPTYPE_ADVERTISERS, "Advertisers"}, + { BGPTYPE_RCID_PATH, "RCID Path / Cluster ID"}, + { BGPTYPE_MP_REACH_NLRI, "Multi-Protocol Reach NLRI"}, + { BGPTYPE_MP_UNREACH_NLRI, "Multi-Protocol Unreach NLRI"}, + { BGPTYPE_EXTD_COMMUNITIES, "Extended Community"}, + { 255, "Reserved for development"}, + { 0, NULL} +}; + +#define BGP_AS_SET 1 +#define BGP_AS_SEQUENCE 2 +#define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */ +#define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */ + +static struct tok bgp_as_path_segment_open_values[] = { + { BGP_AS_SEQUENCE, ""}, + { BGP_AS_SET, "{ "}, + { BGP_CONFED_AS_SEQUENCE, "( "}, + { BGP_CONFED_AS_SET, "({ "}, + { 0, NULL} +}; + +static struct tok bgp_as_path_segment_close_values[] = { + { BGP_AS_SEQUENCE, ""}, + { BGP_AS_SET, "}"}, + { BGP_CONFED_AS_SEQUENCE, ")"}, + { BGP_CONFED_AS_SET, "})"}, + { 0, NULL} +}; + +#define BGP_OPT_AUTH 1 +#define BGP_OPT_CAP 2 + + +static struct tok bgp_opt_values[] = { + { BGP_OPT_AUTH, "Authentication Information"}, + { BGP_OPT_CAP, "Capabilities Advertisement"}, + { 0, NULL} +}; + +#define BGP_CAPCODE_MP 1 +#define BGP_CAPCODE_RR 2 +#define BGP_CAPCODE_RESTART 64 /* draft-ietf-idr-restart-05 */ +#define BGP_CAPCODE_RR_CISCO 128 + +static struct tok bgp_capcode_values[] = { + { BGP_CAPCODE_MP, "Multiprotocol Extensions"}, + { BGP_CAPCODE_RR, "Route Refresh"}, + { BGP_CAPCODE_RESTART, "Graceful Restart"}, + { BGP_CAPCODE_RR_CISCO, "Route Refresh (Cisco)"}, + { 0, NULL} +}; + +#define BGP_NOTIFY_MAJOR_MSG 1 +#define BGP_NOTIFY_MAJOR_OPEN 2 +#define BGP_NOTIFY_MAJOR_UPDATE 3 +#define BGP_NOTIFY_MAJOR_HOLDTIME 4 +#define BGP_NOTIFY_MAJOR_FSM 5 +#define BGP_NOTIFY_MAJOR_CEASE 6 +#define BGP_NOTIFY_MAJOR_CAP 7 + +static struct tok bgp_notify_major_values[] = { + { BGP_NOTIFY_MAJOR_MSG, "Message Header Error"}, + { BGP_NOTIFY_MAJOR_OPEN, "OPEN Message Error"}, + { BGP_NOTIFY_MAJOR_UPDATE, "UPDATE Message Error"}, + { BGP_NOTIFY_MAJOR_HOLDTIME,"Hold Timer Expired"}, + { BGP_NOTIFY_MAJOR_FSM, "Finite State Machine Error"}, + { BGP_NOTIFY_MAJOR_CEASE, "Cease"}, + { BGP_NOTIFY_MAJOR_CAP, "Capability Message Error"}, + { 0, NULL} +}; + +/* draft-ietf-idr-cease-subcode-02 */ +#define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1 +static struct tok bgp_notify_minor_cease_values[] = { + { BGP_NOTIFY_MINOR_CEASE_MAXPRFX, "Maximum Number of Prefixes Reached"}, + { 2, "Administratively Shutdown"}, + { 3, "Peer Unconfigured"}, + { 4, "Administratively Reset"}, + { 5, "Connection Rejected"}, + { 6, "Other Configuration Change"}, + { 7, "Connection Collision Resolution"}, + { 0, NULL} +}; + +static struct tok bgp_notify_minor_msg_values[] = { + { 1, "Connection Not Synchronized"}, + { 2, "Bad Message Length"}, + { 3, "Bad Message Type"}, + { 0, NULL} +}; + +static struct tok bgp_notify_minor_open_values[] = { + { 1, "Unsupported Version Number"}, + { 2, "Bad Peer AS"}, + { 3, "Bad BGP Identifier"}, + { 4, "Unsupported Optional Parameter"}, + { 5, "Authentication Failure"}, + { 6, "Unacceptable Hold Time"}, + { 0, NULL} +}; + +static struct tok bgp_notify_minor_update_values[] = { + { 1, "Malformed Attribute List"}, + { 2, "Unrecognized Well-known Attribute"}, + { 3, "Missing Well-known Attribute"}, + { 4, "Attribute Flags Error"}, + { 5, "Attribute Length Error"}, + { 6, "Invalid ORIGIN Attribute"}, + { 7, "AS Routing Loop"}, + { 8, "Invalid NEXT_HOP Attribute"}, + { 9, "Optional Attribute Error"}, + { 10, "Invalid Network Field"}, + { 11, "Malformed AS_PATH"}, + { 0, NULL} +}; + +static struct tok bgp_notify_minor_cap_values[] = { + { 1, "Invalid Action Value" }, + { 2, "Invalid Capability Length" }, + { 3, "Malformed Capability Value" }, + { 4, "Unsupported Capability Code" }, + { 0, NULL } +}; + +static struct tok bgp_origin_values[] = { + { 0, "IGP"}, + { 1, "EGP"}, + { 2, "Incomplete"}, + { 0, NULL} +}; + +/* Subsequent address family identifier, RFC2283 section 7 */ +#define SAFNUM_RES 0 +#define SAFNUM_UNICAST 1 +#define SAFNUM_MULTICAST 2 +#define SAFNUM_UNIMULTICAST 3 +/* labeled BGP RFC3107 */ +#define SAFNUM_LABUNICAST 4 +/* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */ +#define SAFNUM_VPNUNICAST 128 +#define SAFNUM_VPNMULTICAST 129 +#define SAFNUM_VPNUNIMULTICAST 130 +/* draft-marques-ppvpn-rt-constrain-01.txt */ +#define SAFNUM_RT_ROUTING_INFO 132 + +#define BGP_VPN_RD_LEN 8 + +static struct tok bgp_safi_values[] = { + { SAFNUM_RES, "Reserved"}, + { SAFNUM_UNICAST, "Unicast"}, + { SAFNUM_MULTICAST, "Multicast"}, + { SAFNUM_UNIMULTICAST, "Unicast+Multicast"}, + { SAFNUM_LABUNICAST, "labeled Unicast"}, + { SAFNUM_VPNUNICAST, "labeled VPN Unicast"}, + { SAFNUM_VPNMULTICAST, "labeled VPN Multicast"}, + { SAFNUM_VPNUNIMULTICAST, "labeled VPN Unicast+Multicast"}, + { SAFNUM_RT_ROUTING_INFO, "Route Target Routing Information"}, + { 0, NULL } +}; + +/* well-known community */ +#define BGP_COMMUNITY_NO_EXPORT 0xffffff01 +#define BGP_COMMUNITY_NO_ADVERT 0xffffff02 +#define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03 + +/* RFC1700 address family numbers */ +#define AFNUM_INET 1 +#define AFNUM_INET6 2 +#define AFNUM_NSAP 3 +#define AFNUM_HDLC 4 +#define AFNUM_BBN1822 5 +#define AFNUM_802 6 +#define AFNUM_E163 7 +#define AFNUM_E164 8 +#define AFNUM_F69 9 +#define AFNUM_X121 10 +#define AFNUM_IPX 11 +#define AFNUM_ATALK 12 +#define AFNUM_DECNET 13 +#define AFNUM_BANYAN 14 +#define AFNUM_E164NSAP 15 +/* draft-kompella-ppvpn-l2vpn */ +#define AFNUM_L2VPN 196 /* still to be approved by IANA */ + +static struct tok bgp_afi_values[] = { + { 0, "Reserved"}, + { AFNUM_INET, "IPv4"}, + { AFNUM_INET6, "IPv6"}, + { AFNUM_NSAP, "NSAP"}, + { AFNUM_HDLC, "HDLC"}, + { AFNUM_BBN1822, "BBN 1822"}, + { AFNUM_802, "802"}, + { AFNUM_E163, "E.163"}, + { AFNUM_E164, "E.164"}, + { AFNUM_F69, "F.69"}, + { AFNUM_X121, "X.121"}, + { AFNUM_IPX, "Novell IPX"}, + { AFNUM_ATALK, "Appletalk"}, + { AFNUM_DECNET, "Decnet IV"}, + { AFNUM_BANYAN, "Banyan Vines"}, + { AFNUM_E164NSAP, "E.164 with NSAP subaddress"}, + { AFNUM_L2VPN, "Layer-2 VPN"}, + { 0, NULL}, +}; + +/* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */ +#define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */ +#define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */ +#define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */ +#define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */ +#define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */ +#define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */ +#define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */ + /* rfc2547 bgp-mpls-vpns */ + +#define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */ +#define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */ +#define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */ +#define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */ + +#define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */ +#define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */ + +#define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */ +#define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */ + +#define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */ + +static struct tok bgp_extd_comm_flag_values[] = { + { 0x8000, "vendor-specific"}, + { 0x4000, "non-transitive"}, + { 0, NULL}, +}; + +static struct tok bgp_extd_comm_subtype_values[] = { + { BGP_EXT_COM_RT_0, "target"}, + { BGP_EXT_COM_RT_1, "target"}, + { BGP_EXT_COM_RT_2, "target"}, + { BGP_EXT_COM_RO_0, "origin"}, + { BGP_EXT_COM_RO_1, "origin"}, + { BGP_EXT_COM_RO_2, "origin"}, + { BGP_EXT_COM_LINKBAND, "link-BW"}, + { BGP_EXT_COM_VPN_ORIGIN, "ospf-domain"}, + { BGP_EXT_COM_VPN_ORIGIN2, "ospf-domain"}, + { BGP_EXT_COM_VPN_ORIGIN3, "ospf-domain"}, + { BGP_EXT_COM_VPN_ORIGIN4, "ospf-domain"}, + { BGP_EXT_COM_OSPF_RTYPE, "ospf-route-type"}, + { BGP_EXT_COM_OSPF_RTYPE2, "ospf-route-type"}, + { BGP_EXT_COM_OSPF_RID, "ospf-router-id"}, + { BGP_EXT_COM_OSPF_RID2, "ospf-router-id"}, + { BGP_EXT_COM_L2INFO, "layer2-info"}, + { 0, NULL}, +}; + +/* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */ +#define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */ +#define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */ +#define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */ +#define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */ +#define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/ +#define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */ +#define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */ + +static struct tok bgp_extd_comm_ospf_rtype_values[] = { + { BGP_OSPF_RTYPE_RTR, "Router" }, + { BGP_OSPF_RTYPE_NET, "Network" }, + { BGP_OSPF_RTYPE_SUM, "Summary" }, + { BGP_OSPF_RTYPE_EXT, "External" }, + { BGP_OSPF_RTYPE_NSSA,"NSSA External" }, + { BGP_OSPF_RTYPE_SHAM,"MPLS-VPN Sham" }, + { 0, NULL }, +}; + +static struct tok bgp_l2vpn_encaps_values[] = { + { 0, "Reserved"}, + { 1, "Frame Relay"}, + { 2, "ATM AAL5 VCC transport"}, + { 3, "ATM transparent cell transport"}, + { 4, "Ethernet VLAN"}, + { 5, "Ethernet"}, + { 6, "Cisco-HDLC"}, + { 7, "PPP"}, + { 8, "CEM"}, + { 9, "ATM VCC cell transport"}, + { 10, "ATM VPC cell transport"}, + { 11, "MPLS"}, + { 12, "VPLS"}, + { 64, "IP-interworking"}, + { 0, NULL}, +}; + +static int +decode_prefix4(const u_char *pptr, char *buf, u_int buflen) +{ + struct in_addr addr; + u_int plen; + + TCHECK(pptr[0]); + plen = pptr[0]; + if (32 < plen) + return -1; + + memset(&addr, 0, sizeof(addr)); + TCHECK2(pptr[1], (plen + 7) / 8); + memcpy(&addr, &pptr[1], (plen + 7) / 8); + if (plen % 8) { + ((u_char *)&addr)[(plen + 7) / 8 - 1] &= + ((0xff00 >> (plen % 8)) & 0xff); + } + snprintf(buf, buflen, "%s/%d", getname((u_char *)&addr), plen); + return 1 + (plen + 7) / 8; + +trunc: + return -2; +} + +static int +decode_labeled_prefix4(const u_char *pptr, char *buf, u_int buflen) +{ + struct in_addr addr; + u_int plen; + + TCHECK(pptr[0]); + plen = pptr[0]; /* get prefix length */ + + /* this is one of the weirdnesses of rfc3107 + the label length (actually the label + COS bits) + is added to the prefix length; + we also do only read out just one label - + there is no real application for advertisement of + stacked labels in a a single BGP message + */ + + plen-=24; /* adjust prefixlen - labellength */ + + if (32 < plen) + return -1; + + memset(&addr, 0, sizeof(addr)); + TCHECK2(pptr[4], (plen + 7) / 8); + memcpy(&addr, &pptr[4], (plen + 7) / 8); + if (plen % 8) { + ((u_char *)&addr)[(plen + 7) / 8 - 1] &= + ((0xff00 >> (plen % 8)) & 0xff); + } + /* the label may get offsetted by 4 bits so lets shift it right */ + snprintf(buf, buflen, "%s/%d, label:%u %s", + getname((u_char *)&addr), + plen, + EXTRACT_24BITS(pptr+1)>>4, + ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); + + return 4 + (plen + 7) / 8; + +trunc: + return -2; +} + +/* RDs and RTs share the same semantics + * we use bgp_vpn_rd_print for + * printing route targets inside a NLRI */ +static char * +bgp_vpn_rd_print (const u_char *pptr) { + + /* allocate space for the following string + * xxx.xxx.xxx.xxx:xxxxx + * 21 bytes plus one termination byte */ + static char rd[22]; + char *pos = rd; + + /* ok lets load the RD format */ + switch (EXTRACT_16BITS(pptr)) { + + /* AS:IP-address fmt*/ + case 0: + snprintf(pos, sizeof(rd) - (pos - rd), "%u:%u.%u.%u.%u", + EXTRACT_16BITS(pptr+2), *(pptr+4), *(pptr+5), *(pptr+6), *(pptr+7)); + break; + /* IP-address:AS fmt*/ + + case 1: + snprintf(pos, sizeof(rd) - (pos - rd), "%u.%u.%u.%u:%u", + *(pptr+2), *(pptr+3), *(pptr+4), *(pptr+5), EXTRACT_16BITS(pptr+6)); + break; + + /* 4-byte-AS:number fmt*/ + case 2: + snprintf(pos, sizeof(rd) - (pos - rd), "%u:%u", + EXTRACT_32BITS(pptr+2), EXTRACT_16BITS(pptr+6)); + break; + default: + snprintf(pos, sizeof(rd) - (pos - rd), "unknown RD format"); + break; + } + pos += strlen(pos); + *(pos) = '\0'; + return (rd); +} + +static int +decode_rt_routing_info(const u_char *pptr, char *buf, u_int buflen) +{ + u_int8_t route_target[8]; + u_int plen; + + TCHECK(pptr[0]); + plen = pptr[0]; /* get prefix length */ + + plen-=32; /* adjust prefix length */ + + if (0 < plen) + return -1; + + memset(&route_target, 0, sizeof(route_target)); + TCHECK2(pptr[1], (plen + 7) / 8); + memcpy(&route_target, &pptr[1], (plen + 7) / 8); + if (plen % 8) { + ((u_char *)&route_target)[(plen + 7) / 8 - 1] &= + ((0xff00 >> (plen % 8)) & 0xff); + } + snprintf(buf, buflen, "origin AS: %u, route target %s", + EXTRACT_32BITS(pptr+1), + bgp_vpn_rd_print((u_char *)&route_target)); + + return 5 + (plen + 7) / 8; + +trunc: + return -2; +} + +static int +decode_labeled_vpn_prefix4(const u_char *pptr, char *buf, u_int buflen) +{ + struct in_addr addr; + u_int plen; + + TCHECK(pptr[0]); + plen = pptr[0]; /* get prefix length */ + + plen-=(24+64); /* adjust prefixlen - labellength - RD len*/ + + if (32 < plen) + return -1; + + memset(&addr, 0, sizeof(addr)); + TCHECK2(pptr[12], (plen + 7) / 8); + memcpy(&addr, &pptr[12], (plen + 7) / 8); + if (plen % 8) { + ((u_char *)&addr)[(plen + 7) / 8 - 1] &= + ((0xff00 >> (plen % 8)) & 0xff); + } + /* the label may get offsetted by 4 bits so lets shift it right */ + snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s", + bgp_vpn_rd_print(pptr+4), + getname((u_char *)&addr), + plen, + EXTRACT_24BITS(pptr+1)>>4, + ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); + + return 12 + (plen + 7) / 8; + +trunc: + return -2; +} + +static int +decode_labeled_vpn_l2(const u_char *pptr, char *buf, u_int buflen) +{ + int plen,tlen,strlen,tlv_type,tlv_len,ttlv_len; + + TCHECK2(pptr[0], 2); + plen=EXTRACT_16BITS(pptr); + tlen=plen; + pptr+=2; + TCHECK2(pptr[0],15); + strlen=snprintf(buf, buflen, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u", + bgp_vpn_rd_print(pptr), + EXTRACT_16BITS(pptr+8), + EXTRACT_16BITS(pptr+10), + EXTRACT_24BITS(pptr+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */ + pptr+=15; + tlen-=15; + + /* ok now the variable part - lets read out TLVs*/ + while (tlen>0) { + if (tlen < 3) + return -1; + TCHECK2(pptr[0], 3); + tlv_type=*pptr++; + tlv_len=EXTRACT_16BITS(pptr); + ttlv_len=tlv_len; + pptr+=2; + + switch(tlv_type) { + case 1: + strlen+=snprintf(buf+strlen,buflen-strlen, "\n\t\tcircuit status vector (%u) length: %u: 0x", + tlv_type, + tlv_len); + ttlv_len=ttlv_len/8+1; /* how many bytes do we need to read ? */ + while (ttlv_len>0) { + TCHECK(pptr[0]); + strlen+=snprintf(buf+strlen,buflen-strlen, "%02x",*pptr++); + ttlv_len--; + } + break; + default: + snprintf(buf+strlen,buflen-strlen, "\n\t\tunknown TLV #%u, length: %u", + tlv_type, + tlv_len); + break; + } + tlen-=(tlv_len<<3); /* the tlv-length is expressed in bits so lets shift it tright */ + } + return plen+2; + +trunc: + return -2; +} + +#ifdef INET6 +static int +decode_prefix6(const u_char *pd, char *buf, u_int buflen) +{ + struct in6_addr addr; + u_int plen; + + TCHECK(pd[0]); + plen = pd[0]; + if (128 < plen) + return -1; + + memset(&addr, 0, sizeof(addr)); + TCHECK2(pd[1], (plen + 7) / 8); + memcpy(&addr, &pd[1], (plen + 7) / 8); + if (plen % 8) { + addr.s6_addr[(plen + 7) / 8 - 1] &= + ((0xff00 >> (plen % 8)) & 0xff); + } + snprintf(buf, buflen, "%s/%d", getname6((u_char *)&addr), plen); + return 1 + (plen + 7) / 8; + +trunc: + return -2; +} + +static int +decode_labeled_prefix6(const u_char *pptr, char *buf, u_int buflen) +{ + struct in6_addr addr; + u_int plen; + + TCHECK(pptr[0]); + plen = pptr[0]; /* get prefix length */ + plen-=24; /* adjust prefixlen - labellength */ + + if (128 < plen) + return -1; + + memset(&addr, 0, sizeof(addr)); + TCHECK2(pptr[4], (plen + 7) / 8); + memcpy(&addr, &pptr[4], (plen + 7) / 8); + if (plen % 8) { + addr.s6_addr[(plen + 7) / 8 - 1] &= + ((0xff00 >> (plen % 8)) & 0xff); + } + /* the label may get offsetted by 4 bits so lets shift it right */ + snprintf(buf, buflen, "%s/%d, label:%u %s", + getname6((u_char *)&addr), + plen, + EXTRACT_24BITS(pptr+1)>>4, + ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); + + return 4 + (plen + 7) / 8; + +trunc: + return -2; +} + +static int +decode_labeled_vpn_prefix6(const u_char *pptr, char *buf, u_int buflen) +{ + struct in6_addr addr; + u_int plen; + + TCHECK(pptr[0]); + plen = pptr[0]; /* get prefix length */ + + plen-=(24+64); /* adjust prefixlen - labellength - RD len*/ + + if (128 < plen) + return -1; + + memset(&addr, 0, sizeof(addr)); + TCHECK2(pptr[12], (plen + 7) / 8); + memcpy(&addr, &pptr[12], (plen + 7) / 8); + if (plen % 8) { + addr.s6_addr[(plen + 7) / 8 - 1] &= + ((0xff00 >> (plen % 8)) & 0xff); + } + /* the label may get offsetted by 4 bits so lets shift it right */ + snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s", + bgp_vpn_rd_print(pptr+4), + getname6((u_char *)&addr), + plen, + EXTRACT_24BITS(pptr+1)>>4, + ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); + + return 12 + (plen + 7) / 8; + +trunc: + return -2; +} +#endif + +static int +bgp_attr_print(const struct bgp_attr *attr, const u_char *pptr, int len) +{ + int i; + u_int16_t af; + u_int8_t safi, snpa; + union { /* copy buffer for bandwidth values */ + float f; + u_int32_t i; + } bw; + int advance; + int tlen; + const u_char *tptr; + char buf[MAXHOSTNAMELEN + 100]; + + tptr = pptr; + tlen=len; + + switch (attr->bgpa_type) { + case BGPTYPE_ORIGIN: + if (len != 1) + printf("invalid len"); + else { + TCHECK(*tptr); + printf("%s", tok2str(bgp_origin_values, "Unknown Origin Typecode", tptr[0])); + } + break; + case BGPTYPE_AS_PATH: + if (len % 2) { + printf("invalid len"); + break; + } + if (!len) { + printf("empty"); + break; + } + + while (tptr < pptr + len) { + TCHECK(tptr[0]); + printf("%s", tok2str(bgp_as_path_segment_open_values, "?", tptr[0])); + for (i = 0; i < tptr[1] * 2; i += 2) { + TCHECK2(tptr[2 + i], 2); + printf("%u ", EXTRACT_16BITS(&tptr[2 + i])); + } + TCHECK(tptr[0]); + printf("%s", tok2str(bgp_as_path_segment_close_values, "?", tptr[0])); + TCHECK(tptr[1]); + tptr += 2 + tptr[1] * 2; + } + break; + case BGPTYPE_NEXT_HOP: + if (len != 4) + printf("invalid len"); + else { + TCHECK2(tptr[0], 4); + printf("%s", getname(tptr)); + } + break; + case BGPTYPE_MULTI_EXIT_DISC: + case BGPTYPE_LOCAL_PREF: + if (len != 4) + printf("invalid len"); + else { + TCHECK2(tptr[0], 4); + printf("%u", EXTRACT_32BITS(tptr)); + } + break; + case BGPTYPE_ATOMIC_AGGREGATE: + if (len != 0) + printf("invalid len"); + break; + case BGPTYPE_AGGREGATOR: + if (len != 6) { + printf("invalid len"); + break; + } + TCHECK2(tptr[0], 6); + printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr), + getname(tptr + 2)); + break; + case BGPTYPE_COMMUNITIES: + if (len % 4) { + printf("invalid len"); + break; + } + while (tlen>0) { + u_int32_t comm; + TCHECK2(tptr[0], 4); + comm = EXTRACT_32BITS(tptr); + switch (comm) { + case BGP_COMMUNITY_NO_EXPORT: + printf(" NO_EXPORT"); + break; + case BGP_COMMUNITY_NO_ADVERT: + printf(" NO_ADVERTISE"); + break; + case BGP_COMMUNITY_NO_EXPORT_SUBCONFED: + printf(" NO_EXPORT_SUBCONFED"); + break; + default: + printf("%u:%u%s", + (comm >> 16) & 0xffff, + comm & 0xffff, + (tlen>4) ? ", " : ""); + break; + } + tlen -=4; + tptr +=4; + } + break; + case BGPTYPE_ORIGINATOR_ID: + if (len != 4) { + printf("invalid len"); + break; + } + TCHECK2(tptr[0], 4); + printf("%s",getname(tptr)); + break; + case BGPTYPE_CLUSTER_LIST: + if (len % 4) { + printf("invalid len"); + break; + } + while (tlen>0) { + TCHECK2(tptr[0], 4); + printf("%s%s", + getname(tptr), + (tlen>4) ? ", " : ""); + tlen -=4; + tptr +=4; + } + break; + case BGPTYPE_MP_REACH_NLRI: + TCHECK2(tptr[0], 3); + af = EXTRACT_16BITS(tptr); + safi = tptr[2]; + + printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)", + tok2str(bgp_afi_values, "Unknown AFI", af), + af, + (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */ + tok2str(bgp_safi_values, "Unknown SAFI", safi), + safi); + + if (af == AFNUM_INET || af==AFNUM_L2VPN) + ; +#ifdef INET6 + else if (af == AFNUM_INET6) + ; +#endif + else { + printf("\n\t no AFI %u decoder",af); + if (vflag <= 1) + print_unknown_data(tptr,"\n\t ",tlen); + break; + } + + tptr +=3; + + TCHECK(tptr[0]); + tlen = tptr[0]; + tptr++; + + if (tlen) { + printf("\n\t nexthop: "); + while (tlen > 0) { + switch (af) { + case AFNUM_INET: + switch(safi) { + case SAFNUM_UNICAST: + case SAFNUM_MULTICAST: + case SAFNUM_UNIMULTICAST: + case SAFNUM_LABUNICAST: + case SAFNUM_RT_ROUTING_INFO: + if (tlen < (int)sizeof(struct in_addr)) { + printf("invalid len"); + tlen = 0; + } else { + TCHECK2(tptr[0], sizeof(struct in_addr)); + printf("%s",getname(tptr)); + tlen -= sizeof(struct in_addr); + tptr += sizeof(struct in_addr); + } + break; + case SAFNUM_VPNUNICAST: + case SAFNUM_VPNMULTICAST: + case SAFNUM_VPNUNIMULTICAST: + if (tlen < (int)(sizeof(struct in_addr)+BGP_VPN_RD_LEN)) { + printf("invalid len"); + tlen = 0; + } else { + TCHECK2(tptr[0], sizeof(struct in_addr)+BGP_VPN_RD_LEN); + printf("RD: %s, %s", + bgp_vpn_rd_print(tptr), + getname(tptr+BGP_VPN_RD_LEN)); + tlen -= (sizeof(struct in_addr)+BGP_VPN_RD_LEN); + tptr += (sizeof(struct in_addr)+BGP_VPN_RD_LEN); + } + break; + default: + TCHECK2(tptr[0], tlen); + printf("no SAFI %u decoder",safi); + if (vflag <= 1) + print_unknown_data(tptr,"\n\t ",tlen); + tptr += tlen; + tlen = 0; + break; + } + break; +#ifdef INET6 + case AFNUM_INET6: + switch(safi) { + case SAFNUM_UNICAST: + case SAFNUM_MULTICAST: + case SAFNUM_UNIMULTICAST: + case SAFNUM_LABUNICAST: + case SAFNUM_RT_ROUTING_INFO: + if (tlen < (int)sizeof(struct in6_addr)) { + printf("invalid len"); + tlen = 0; + } else { + TCHECK2(tptr[0], sizeof(struct in6_addr)); + printf("%s", getname6(tptr)); + tlen -= sizeof(struct in6_addr); + tptr += sizeof(struct in6_addr); + } + break; + case SAFNUM_VPNUNICAST: + case SAFNUM_VPNMULTICAST: + case SAFNUM_VPNUNIMULTICAST: + if (tlen < (int)(sizeof(struct in6_addr)+BGP_VPN_RD_LEN)) { + printf("invalid len"); + tlen = 0; + } else { + TCHECK2(tptr[0], sizeof(struct in6_addr)+BGP_VPN_RD_LEN); + printf("RD: %s, %s", + bgp_vpn_rd_print(tptr), + getname6(tptr+BGP_VPN_RD_LEN)); + tlen -= (sizeof(struct in6_addr)+BGP_VPN_RD_LEN); + tptr += (sizeof(struct in6_addr)+BGP_VPN_RD_LEN); + } + break; + default: + TCHECK2(tptr[0], tlen); + printf("no SAFI %u decoder",safi); + if (vflag <= 1) + print_unknown_data(tptr,"\n\t ",tlen); + tptr += tlen; + tlen = 0; + break; + } + break; +#endif + case AFNUM_L2VPN: + switch(safi) { + case SAFNUM_VPNUNICAST: + case SAFNUM_VPNMULTICAST: + case SAFNUM_VPNUNIMULTICAST: + if (tlen < (int)sizeof(struct in_addr)) { + printf("invalid len"); + tlen = 0; + } else { + TCHECK2(tptr[0], sizeof(struct in_addr)); + printf("%s", getname(tptr)); + tlen -= (sizeof(struct in_addr)); + tptr += (sizeof(struct in_addr)); + } + break; + default: + TCHECK2(tptr[0], tlen); + printf("no SAFI %u decoder",safi); + if (vflag <= 1) + print_unknown_data(tptr,"\n\t ",tlen); + tptr += tlen; + tlen = 0; + break; + } + break; + + default: + TCHECK2(tptr[0], tlen); + printf("no AFI %u decoder",af); + if (vflag <= 1) + print_unknown_data(tptr,"\n\t ",tlen); + tptr += tlen; + tlen = 0; + break; + } + } + } + tptr += tlen; + + TCHECK(tptr[0]); + snpa = tptr[0]; + tptr++; + + if (snpa) { + printf("\n\t %u SNPA", snpa); + for (/*nothing*/; snpa > 0; snpa--) { + TCHECK(tptr[0]); + printf("\n\t %d bytes", tptr[0]); + tptr += tptr[0] + 1; + } + } else { + printf(", no SNPA"); + } + + while (len - (tptr - pptr) > 0) { + switch (af) { + case AFNUM_INET: + switch (safi) { + case SAFNUM_UNICAST: + case SAFNUM_MULTICAST: + case SAFNUM_UNIMULTICAST: + advance = decode_prefix4(tptr, buf, sizeof(buf)); + if (advance == -1) + printf("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + printf("\n\t %s", buf); + break; + case SAFNUM_LABUNICAST: + advance = decode_labeled_prefix4(tptr, buf, sizeof(buf)); + if (advance == -1) + printf("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + printf("\n\t %s", buf); + break; + case SAFNUM_VPNUNICAST: + case SAFNUM_VPNMULTICAST: + case SAFNUM_VPNUNIMULTICAST: + advance = decode_labeled_vpn_prefix4(tptr, buf, sizeof(buf)); + if (advance == -1) + printf("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + printf("\n\t %s", buf); + break; + case SAFNUM_RT_ROUTING_INFO: + advance = decode_rt_routing_info(tptr, buf, sizeof(buf)); + if (advance == -1) + printf("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + printf("\n\t %s", buf); + break; + default: + TCHECK2(*(tptr-3),tlen); + printf("\n\t no SAFI %u decoder",safi); + if (vflag <= 1) + print_unknown_data(tptr-3,"\n\t ",tlen); + advance = 0; + tptr = pptr + len; + break; + } + break; +#ifdef INET6 + case AFNUM_INET6: + switch (safi) { + case SAFNUM_UNICAST: + case SAFNUM_MULTICAST: + case SAFNUM_UNIMULTICAST: + advance = decode_prefix6(tptr, buf, sizeof(buf)); + if (advance == -1) + printf("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + printf("\n\t %s", buf); + break; + case SAFNUM_LABUNICAST: + advance = decode_labeled_prefix6(tptr, buf, sizeof(buf)); + if (advance == -1) + printf("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + printf("\n\t %s", buf); + break; + case SAFNUM_VPNUNICAST: + case SAFNUM_VPNMULTICAST: + case SAFNUM_VPNUNIMULTICAST: + advance = decode_labeled_vpn_prefix6(tptr, buf, sizeof(buf)); + if (advance == -1) + printf("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + printf("\n\t %s", buf); + break; + case SAFNUM_RT_ROUTING_INFO: + advance = decode_rt_routing_info(tptr, buf, sizeof(buf)); + if (advance == -1) + printf("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + printf("\n\t %s", buf); + break; + default: + TCHECK2(*(tptr-3),tlen); + printf("\n\t no SAFI %u decoder ",safi); + if (vflag <= 1) + print_unknown_data(tptr-3,"\n\t ",tlen); + advance = 0; + tptr = pptr + len; + break; + } + break; +#endif + case AFNUM_L2VPN: + switch(safi) { + case SAFNUM_VPNUNICAST: + case SAFNUM_VPNMULTICAST: + case SAFNUM_VPNUNIMULTICAST: + advance = decode_labeled_vpn_l2(tptr, buf, sizeof(buf)); + if (advance == -1) + printf("\n\t (illegal length)"); + else if (advance == -2) + goto trunc; + else + printf("\n\t %s", buf); + break; + default: + TCHECK2(*tptr,tlen); + printf("no SAFI %u decoder",safi); + if (vflag <= 1) + print_unknown_data(tptr,"\n\t ",tlen); + advance = 0; + tptr = pptr + len; + break; + } + break; + + + default: + TCHECK2(*(tptr-3),tlen); + printf("\n\t no AFI %u decoder ",af); + if (vflag <= 1) + print_unknown_data(tptr-3,"\n\t ",tlen); + advance = 0; + tptr = pptr + len; + break; + } + tptr += advance; + } + break; + + case BGPTYPE_MP_UNREACH_NLRI: + TCHECK2(tptr[0], 3); + af = EXTRACT_16BITS(tptr); + safi = tptr[2]; + + printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)", + tok2str(bgp_afi_values, "Unknown AFI", af), + af, + (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */ + tok2str(bgp_safi_values, "Unknown SAFI", safi), + safi); + + tptr += 3; + + while (len - (tptr - pptr) > 0) { + switch (af) { + case AFNUM_INET: + switch (safi) { + case SAFNUM_UNICAST: + case SAFNUM_MULTICAST: + case SAFNUM_UNIMULTICAST: + advance = decode_prefix4(tptr, buf, sizeof(buf)); + if (advance == -1) + printf("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + printf("\n\t %s", buf); + break; + case SAFNUM_LABUNICAST: + advance = decode_labeled_prefix4(tptr, buf, sizeof(buf)); + if (advance == -1) + printf("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + printf("\n\t %s", buf); + break; + case SAFNUM_VPNUNICAST: + case SAFNUM_VPNMULTICAST: + case SAFNUM_VPNUNIMULTICAST: + advance = decode_labeled_vpn_prefix4(tptr, buf, sizeof(buf)); + if (advance == -1) + printf("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + printf("\n\t %s", buf); + break; + default: + TCHECK2(*(tptr-3),tlen); + printf("\n\t no SAFI %u decoder",safi); + if (vflag <= 1) + print_unknown_data(tptr-3,"\n\t ",tlen); + advance = 0; + tptr = pptr + len; + break; + } + break; + +#ifdef INET6 + case AFNUM_INET6: + switch (safi) { + case SAFNUM_UNICAST: + case SAFNUM_MULTICAST: + case SAFNUM_UNIMULTICAST: + advance = decode_prefix6(tptr, buf, sizeof(buf)); + if (advance == -1) + printf("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + printf("\n\t %s", buf); + break; + case SAFNUM_LABUNICAST: + advance = decode_labeled_prefix6(tptr, buf, sizeof(buf)); + if (advance == -1) + printf("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + printf("\n\t %s", buf); + break; + case SAFNUM_VPNUNICAST: + case SAFNUM_VPNMULTICAST: + case SAFNUM_VPNUNIMULTICAST: + advance = decode_labeled_vpn_prefix6(tptr, buf, sizeof(buf)); + if (advance == -1) + printf("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + printf("\n\t %s", buf); + break; + default: + TCHECK2(*(tptr-3),tlen); + printf("\n\t no SAFI %u decoder",safi); + if (vflag <= 1) + print_unknown_data(tptr-3,"\n\t ",tlen); + advance = 0; + tptr = pptr + len; + break; + } + break; +#endif + + case AFNUM_L2VPN: + switch(safi) { + case SAFNUM_VPNUNICAST: + case SAFNUM_VPNMULTICAST: + case SAFNUM_VPNUNIMULTICAST: + advance = decode_labeled_vpn_l2(tptr, buf, sizeof(buf)); + if (advance == -1) + printf("\n\t (illegal length)"); + else if (advance == -2) + goto trunc; + else + printf("\n\t %s", buf); + break; + default: + TCHECK2(*(tptr-3),tlen); + printf("no SAFI %u decoder",safi); + if (vflag <= 1) + print_unknown_data(tptr-3,"\n\t ",tlen); + advance = 0; + tptr = pptr + len; + break; + } + break; + + default: + TCHECK2(*(tptr-3),tlen); + printf("\n\t no AFI %u decoder",af); + if (vflag <= 1) + print_unknown_data(tptr-3,"\n\t ",tlen); + advance = 0; + tptr = pptr + len; + break; + } + + tptr += advance; + } + break; + case BGPTYPE_EXTD_COMMUNITIES: + if (len % 8) { + printf("invalid len"); + break; + } + while (tlen>0) { + u_int16_t extd_comm; + + TCHECK2(tptr[0], 2); + extd_comm=EXTRACT_16BITS(tptr); + + printf("\n\t %s (0x%04x), Flags [%s]", + tok2str(bgp_extd_comm_subtype_values, "unknown extd community typecode", extd_comm), + extd_comm, + bittok2str(bgp_extd_comm_flag_values, "none", extd_comm)); + + TCHECK2(*(tptr+2), 6); + switch(extd_comm) { + case BGP_EXT_COM_RT_0: + case BGP_EXT_COM_RO_0: + printf(": %u:%s", + EXTRACT_16BITS(tptr+2), + getname(tptr+4)); + break; + case BGP_EXT_COM_RT_1: + case BGP_EXT_COM_RO_1: + printf(": %s:%u", + getname(tptr+2), + EXTRACT_16BITS(tptr+6)); + break; + case BGP_EXT_COM_RT_2: + case BGP_EXT_COM_RO_2: + printf(": %u:%u", + EXTRACT_32BITS(tptr+2), + EXTRACT_16BITS(tptr+6)); + break; + case BGP_EXT_COM_LINKBAND: + bw.i = EXTRACT_32BITS(tptr+2); + printf(": bandwidth: %.3f Mbps", + bw.f*8/1000000); + break; + case BGP_EXT_COM_VPN_ORIGIN: + case BGP_EXT_COM_VPN_ORIGIN2: + case BGP_EXT_COM_VPN_ORIGIN3: + case BGP_EXT_COM_VPN_ORIGIN4: + case BGP_EXT_COM_OSPF_RID: + case BGP_EXT_COM_OSPF_RID2: + printf("%s", getname(tptr+2)); + break; + case BGP_EXT_COM_OSPF_RTYPE: + case BGP_EXT_COM_OSPF_RTYPE2: + printf(": area:%s, router-type:%s, metric-type:%s%s", + getname(tptr+2), + tok2str(bgp_extd_comm_ospf_rtype_values, + "unknown (0x%02x)", + *(tptr+6)), + (*(tptr+7) & BGP_OSPF_RTYPE_METRIC_TYPE) ? "E2" : "", + (*(tptr+6) == (BGP_OSPF_RTYPE_EXT ||BGP_OSPF_RTYPE_NSSA )) ? "E1" : ""); + break; + case BGP_EXT_COM_L2INFO: + printf(": %s Control Flags [0x%02x]:MTU %u", + tok2str(bgp_l2vpn_encaps_values, + "unknown encaps", + *(tptr+2)), + *(tptr+3), + EXTRACT_16BITS(tptr+4)); + break; + default: + print_unknown_data(tptr,"\n\t ",8); + break; + } + tlen -=8; + tptr +=8; + } + break; + + default: + TCHECK2(*pptr,len); + printf("\n\t no Attribute %u decoder",attr->bgpa_type); /* we have no decoder for the attribute */ + if (vflag <= 1) + print_unknown_data(pptr,"\n\t ",len); + break; + } + if (vflag > 1 && len) /* omit zero length attributes*/ + print_unknown_data(pptr,"\n\t ",len); + return 1; + +trunc: + return 0; +} + +static void +bgp_open_print(const u_char *dat, int length) +{ + struct bgp_open bgpo; + struct bgp_opt bgpopt; + int hlen; + const u_char *opt; + int i,cap_type,cap_len,tcap_len,cap_offset; + + TCHECK2(dat[0], BGP_OPEN_SIZE); + memcpy(&bgpo, dat, BGP_OPEN_SIZE); + hlen = ntohs(bgpo.bgpo_len); + + printf("\n\t Version %d, ", bgpo.bgpo_version); + printf("my AS %u, ", ntohs(bgpo.bgpo_myas)); + printf("Holdtime %us, ", ntohs(bgpo.bgpo_holdtime)); + printf("ID %s", getname((u_char *)&bgpo.bgpo_id)); + printf("\n\t Optional parameters, length: %u", bgpo.bgpo_optlen); + + /* some little sanity checking */ + if (length < bgpo.bgpo_optlen+BGP_OPEN_SIZE) + return; + + /* ugly! */ + opt = &((const struct bgp_open *)dat)->bgpo_optlen; + opt++; + + 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("\n\t Option %d, length: %u", bgpopt.bgpopt_type, bgpopt.bgpopt_len); + break; + } + + printf("\n\t Option %s (%u), length: %u", + tok2str(bgp_opt_values,"Unknown", bgpopt.bgpopt_type), + bgpopt.bgpopt_type, + bgpopt.bgpopt_len); + + /* now lets decode the options we know*/ + switch(bgpopt.bgpopt_type) { + case BGP_OPT_CAP: + cap_type=opt[i+BGP_OPT_SIZE]; + cap_len=opt[i+BGP_OPT_SIZE+1]; + tcap_len=cap_len; + printf("\n\t %s, length: %u", + tok2str(bgp_capcode_values,"Unknown", cap_type), + cap_len); + switch(cap_type) { + case BGP_CAPCODE_MP: + printf("\n\t\tAFI %s (%u), SAFI %s (%u)", + tok2str(bgp_afi_values,"Unknown", EXTRACT_16BITS(opt+i+BGP_OPT_SIZE+2)), + EXTRACT_16BITS(opt+i+BGP_OPT_SIZE+2), + tok2str(bgp_safi_values,"Unknown", opt[i+BGP_OPT_SIZE+5]), + opt[i+BGP_OPT_SIZE+5]); + break; + case BGP_CAPCODE_RESTART: + printf("\n\t\tRestart Flags: [%s], Restart Time %us", + ((opt[i+BGP_OPT_SIZE+2])&0x80) ? "R" : "none", + EXTRACT_16BITS(opt+i+BGP_OPT_SIZE+2)&0xfff); + tcap_len-=2; + cap_offset=4; + while(tcap_len>=4) { + printf("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s", + tok2str(bgp_afi_values,"Unknown", EXTRACT_16BITS(opt+i+BGP_OPT_SIZE+cap_offset)), + EXTRACT_16BITS(opt+i+BGP_OPT_SIZE+cap_offset), + tok2str(bgp_safi_values,"Unknown", opt[i+BGP_OPT_SIZE+cap_offset+2]), + opt[i+BGP_OPT_SIZE+cap_offset+2], + ((opt[i+BGP_OPT_SIZE+cap_offset+3])&0x80) ? "yes" : "no" ); + tcap_len-=4; + cap_offset+=4; + } + break; + case BGP_CAPCODE_RR: + case BGP_CAPCODE_RR_CISCO: + break; + default: + printf("\n\t\tno decoder for Capability %u", + cap_type); + if (vflag <= 1) + print_unknown_data(&opt[i+BGP_OPT_SIZE+2],"\n\t\t",cap_len); + break; + } + if (vflag > 1) + print_unknown_data(&opt[i+BGP_OPT_SIZE+2],"\n\t\t",cap_len); + break; + case BGP_OPT_AUTH: + default: + printf("\n\t no decoder for option %u", + bgpopt.bgpopt_type); + break; + } + + i += BGP_OPT_SIZE + bgpopt.bgpopt_len; + } + return; +trunc: + printf("[|BGP]"); +} + +static void +bgp_update_print(const u_char *dat, int length) +{ + struct bgp bgp; + struct bgp_attr bgpa; + int hlen; + const u_char *p; + int len; + int i; + + TCHECK2(dat[0], BGP_SIZE); + memcpy(&bgp, dat, BGP_SIZE); + hlen = ntohs(bgp.bgp_len); + p = dat + BGP_SIZE; /*XXX*/ + + /* 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. + */ +#ifdef INET6 + printf("\n\t Withdrawn routes: %d bytes", len); +#else + char buf[MAXHOSTNAMELEN + 100]; + int wpfx; + + TCHECK2(p[2], len); + i = 2; + + printf("\n\t Withdrawn routes:"); + + while(i < 2 + len) { + wpfx = decode_prefix4(&p[i], buf, sizeof(buf)); + if (wpfx == -1) { + printf("\n\t (illegal prefix length)"); + break; + } else if (wpfx == -2) + goto trunc; + else { + i += wpfx; + printf("\n\t %s", buf); + } + } +#endif + } + p += 2 + len; + + TCHECK2(p[0], 2); + len = EXTRACT_16BITS(p); + if (len) { + /* do something more useful!*/ + i = 2; + while (i < 2 + len) { + int alen, aoff; + + TCHECK2(p[i], sizeof(bgpa)); + memcpy(&bgpa, &p[i], sizeof(bgpa)); + alen = bgp_attr_len(&bgpa); + aoff = bgp_attr_off(&bgpa); + + printf("\n\t %s (%u), length: %u", + tok2str(bgp_attr_values, "Unknown Attribute", bgpa.bgpa_type), + bgpa.bgpa_type, + alen); + + if (bgpa.bgpa_flags) { + printf(", Flags [%s%s%s%s", + bgpa.bgpa_flags & 0x80 ? "O" : "", + bgpa.bgpa_flags & 0x40 ? "T" : "", + bgpa.bgpa_flags & 0x20 ? "P" : "", + bgpa.bgpa_flags & 0x10 ? "E" : ""); + if (bgpa.bgpa_flags & 0xf) + printf("+%x", bgpa.bgpa_flags & 0xf); + printf("]: "); + } + if (!bgp_attr_print(&bgpa, &p[i + aoff], alen)) + goto trunc; + i += aoff + alen; + } + } + p += 2 + len; + + if (dat + length > p) { + printf("\n\t Updated routes:"); + while (dat + length > p) { + char buf[MAXHOSTNAMELEN + 100]; + i = decode_prefix4(p, buf, sizeof(buf)); + if (i == -1) + printf("\n\t (illegal prefix length)"); + else if (i == -2) + goto trunc; + else { + printf("\n\t %s", buf); + p += i; + } + } + } + return; +trunc: + printf("[|BGP]"); +} + +static void +bgp_notification_print(const u_char *dat, int length) +{ + struct bgp_notification bgpn; + int hlen; + const u_char *tptr; + + TCHECK2(dat[0], BGP_NOTIFICATION_SIZE); + memcpy(&bgpn, dat, BGP_NOTIFICATION_SIZE); + hlen = ntohs(bgpn.bgpn_len); + + /* some little sanity checking */ + if (length= BGP_NOTIFICATION_SIZE + 7) { + tptr = dat + BGP_NOTIFICATION_SIZE; + TCHECK2(*tptr, 7); + printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u", + tok2str(bgp_afi_values, "Unknown", EXTRACT_16BITS(tptr)), + EXTRACT_16BITS(tptr), + tok2str(bgp_safi_values, "Unknown", *(tptr+2)), + *(tptr+2), + EXTRACT_32BITS(tptr+3)); + } + break; + default: + break; + } + + return; +trunc: + printf("[|BGP]"); +} + +static void +bgp_route_refresh_print(const u_char *pptr, int len) { + + const struct bgp_route_refresh *bgp_route_refresh_header; + bgp_route_refresh_header = (const struct bgp_route_refresh *)pptr; + + printf("\n\t AFI %s (%u), SAFI %s (%u)", + tok2str(bgp_afi_values,"Unknown", + EXTRACT_16BITS(&bgp_route_refresh_header->afi)), /* this stinks but the compiler pads the structure weird */ + EXTRACT_16BITS(&bgp_route_refresh_header->afi), + tok2str(bgp_safi_values,"Unknown", + bgp_route_refresh_header->safi), + bgp_route_refresh_header->safi); + + if (vflag > 1) + print_unknown_data(pptr,"\n\t ", len); + + return; +} + +static int +bgp_header_print(const u_char *dat, int length) +{ + struct bgp bgp; + + TCHECK2(dat[0], BGP_SIZE); + memcpy(&bgp, dat, BGP_SIZE); + printf("\n\t%s Message (%u), length: %u", + tok2str(bgp_msg_values, "Unknown", bgp.bgp_type), + bgp.bgp_type, + length); + + switch (bgp.bgp_type) { + case BGP_OPEN: + bgp_open_print(dat, length); + break; + case BGP_UPDATE: + bgp_update_print(dat, length); + break; + case BGP_NOTIFICATION: + bgp_notification_print(dat, length); + break; + case BGP_KEEPALIVE: + break; + case BGP_ROUTE_REFRESH: + bgp_route_refresh_print(dat, length); + break; + default: + /* we have no decoder for the BGP message */ + printf("\n\t no Message %u decoder",bgp.bgp_type); + print_unknown_data(dat,"\n\t ",length); + break; + } + return 1; +trunc: + printf("[|BGP]"); + return 0; +} + +void +bgp_print(const u_char *dat, int length) +{ + const u_char *p; + const u_char *ep; + const u_char *start; + const u_char marker[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + }; + struct bgp bgp; + u_int16_t hlen; + + ep = dat + length; + if (snapend < dat + length) + ep = snapend; + + printf(": BGP, length: %u",length); + + if (vflag < 1) /* lets be less chatty */ + return; + + p = dat; + start = p; + while (p < snapend) { + if (!TTEST2(p[0], 1)) + break; + if (p[0] != 0xff) { + p++; + continue; + } + + if (!TTEST2(p[0], sizeof(marker))) + break; + if (memcmp(p, marker, sizeof(marker)) != 0) { + p++; + continue; + } + + /* found BGP header */ + TCHECK2(p[0], BGP_SIZE); /*XXX*/ + memcpy(&bgp, p, BGP_SIZE); + + if (start != p) + printf(" [|BGP]"); + + hlen = ntohs(bgp.bgp_len); + if (hlen < BGP_SIZE) { + printf("\n[|BGP Bogus header length %u < %u]", hlen, + BGP_SIZE); + break; + } + + if (TTEST2(p[0], hlen)) { + if (!bgp_header_print(p, hlen)) + return; + p += hlen; + start = p; + } else { + printf("\n[|BGP %s]", tok2str(bgp_msg_values, "Unknown Message Type",bgp.bgp_type)); + break; + } + } + + return; + +trunc: + printf(" [|BGP]"); +} diff --git a/kame/kame/tcpdump/print-bootp.c b/kame/kame/tcpdump/print-bootp.c index 081bb94066..896bd9d831 100644 --- a/kame/kame/tcpdump/print-bootp.c +++ b/kame/kame/tcpdump/print-bootp.c @@ -21,128 +21,119 @@ * Format and print bootp packets. */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-bootp.c,v 1.46 98/07/18 13:33:58 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.75.2.3 2004/03/02 07:45:13 hannes Exp $ (LBL)"; #endif -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include -#include -#include +#include -#include -#ifdef HAVE_MEMORY_H -#include -#endif #include #include #include "interface.h" #include "addrtoname.h" +#include "extract.h" +#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]"; +static const struct tok bootp_flag_values[] = { + { 0x8000, "Broadcast" }, + { 0, NULL} +}; + +static const struct tok bootp_op_values[] = { + { BOOTPREQUEST, "Request" }, + { BOOTPREPLY, "Reply" }, + { 0, NULL} +}; + /* * Print bootp requests */ void -bootp_print(register const u_char *cp, u_int length, - u_short sport, u_short dport) +bootp_print(register const u_char *cp, u_int length) { 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) { - - case BOOTREQUEST: - /* Usually, a request goes from a client to a server */ - if (sport != IPPORT_BOOTPC || dport != IPPORT_BOOTPS) - printf(" (request)"); - break; - - case BOOTREPLY: - /* Usually, a reply goes from a server to a client */ - if (sport != IPPORT_BOOTPS || dport != IPPORT_BOOTPC) - printf(" (reply)"); - break; - - default: - printf(" bootp-#%d", bp->bp_op); + + printf("BOOTP/DHCP, %s", + tok2str(bootp_op_values, "unknown (0x%02x)", bp->bp_op)); + + if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) { + TCHECK2(bp->bp_chaddr[0], 6); + printf(" from %s", etheraddr_string(bp->bp_chaddr)); } + printf(", length: %u", length); + + if (!vflag) + return; + TCHECK(bp->bp_secs); /* The usual hardware address type is 1 (10Mb Ethernet) */ if (bp->bp_htype != 1) - printf(" htype-#%d", bp->bp_htype); + printf(", htype-#%d", bp->bp_htype); /* The usual length for 10Mb Ethernet address is 6 bytes */ if (bp->bp_htype != 1 || bp->bp_hlen != 6) - printf(" hlen:%d", bp->bp_hlen); + printf(", hlen:%d", bp->bp_hlen); /* Only print interesting fields */ if (bp->bp_hops) - printf(" hops:%d", bp->bp_hops); + printf(", hops:%d", bp->bp_hops); if (bp->bp_xid) - printf(" xid:0x%x", (u_int32_t)ntohl(bp->bp_xid)); + printf(", xid:0x%x", EXTRACT_32BITS(&bp->bp_xid)); if (bp->bp_secs) - printf(" secs:%d", ntohs(bp->bp_secs)); + printf(", secs:%d", EXTRACT_16BITS(&bp->bp_secs)); + + printf(", flags: [%s]", + bittok2str(bootp_flag_values, "none", EXTRACT_16BITS(&bp->bp_flags))); + if (vflag>1) + printf( " (0x%04x)", EXTRACT_16BITS(&bp->bp_flags)); /* Client's ip address */ TCHECK(bp->bp_ciaddr); if (bp->bp_ciaddr.s_addr) - printf(" C:%s", ipaddr_string(&bp->bp_ciaddr)); + printf("\n\t Client IP: %s", ipaddr_string(&bp->bp_ciaddr)); /* 'your' ip address (bootp client) */ TCHECK(bp->bp_yiaddr); if (bp->bp_yiaddr.s_addr) - printf(" Y:%s", ipaddr_string(&bp->bp_yiaddr)); + printf("\n\t Your IP: %s", ipaddr_string(&bp->bp_yiaddr)); /* Server's ip address */ TCHECK(bp->bp_siaddr); if (bp->bp_siaddr.s_addr) - printf(" S:%s", ipaddr_string(&bp->bp_siaddr)); + printf("\n\t Server IP: %s", ipaddr_string(&bp->bp_siaddr)); /* Gateway's ip address */ TCHECK(bp->bp_giaddr); if (bp->bp_giaddr.s_addr) - printf(" G:%s", ipaddr_string(&bp->bp_giaddr)); + printf("\n\t Gateway IP: %s", ipaddr_string(&bp->bp_giaddr)); /* Client's Ethernet address */ if (bp->bp_htype == 1 && bp->bp_hlen == 6) { - register const struct ether_header *eh; - register const char *e; - TCHECK2(bp->bp_chaddr[0], 6); - eh = (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) - printf(" ether %s", etheraddr_string(bp->bp_chaddr)); + printf("\n\t Client Ethernet Address: %s", etheraddr_string(bp->bp_chaddr)); } TCHECK2(bp->bp_sname[0], 1); /* check first char only */ if (*bp->bp_sname) { - printf(" sname \""); + printf("\n\t sname \""); if (fn_print(bp->bp_sname, snapend)) { putchar('"'); fputs(tstr + 1, stdout); @@ -150,9 +141,9 @@ bootp_print(register const u_char *cp, u_int length, } putchar('"'); } - TCHECK2(bp->bp_sname[0], 1); /* check first char only */ + TCHECK2(bp->bp_file[0], 1); /* check first char only */ if (*bp->bp_file) { - printf(" file \""); + printf("\n\t file \""); if (fn_print(bp->bp_file, snapend)) { putchar('"'); fputs(tstr + 1, stdout); @@ -163,19 +154,18 @@ 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; - memcpy((char *)&ul, (char *)bp->bp_vend, sizeof(ul)); + ul = EXTRACT_32BITS(&bp->bp_vend); if (ul != 0) - printf("vend-#0x%x", ul); + printf("\n\t Vendor-#0x%x", ul); } return; @@ -183,12 +173,24 @@ bootp_print(register const u_char *cp, u_int length, 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" }, { TAG_SUBNET_MASK, "iSM" }, /* subnet mask (RFC950) */ - { TAG_TIME_OFFSET, "lTZ" }, /* seconds from UTC */ + { TAG_TIME_OFFSET, "LTZ" }, /* seconds from UTC */ { TAG_GATEWAY, "iDG" }, /* default gateway */ { TAG_TIME_SERVER, "iTS" }, /* time servers (RFC868) */ { TAG_NAME_SERVER, "iIEN" }, /* IEN name servers (IEN116) */ @@ -202,84 +204,151 @@ static struct tok tag2str[] = { { TAG_BOOTSIZE, "sBS" }, /* 512 byte blocks */ { TAG_END, " END" }, /* RFC1497 tags */ - { TAG_DUMPPATH, "aDP" }, /* merit dump file */ - { TAG_DOMAINNAME, "aDN" }, /* domain name */ - { TAG_SWAP_SERVER, "iSS" }, /* swap server */ - { TAG_ROOTPATH, "aRP" }, /* root path */ - { TAG_EXTPATH, "aEP" }, /* extensions path */ -/* RFC1533 tags */ - { TAG_IP_FORWARD, "bip-fw" }, - { TAG_IP_SRCRT, "bip-sr" }, - { TAG_IP_FILTER, "iip-fil" }, - { TAG_IP_REASS, "sip-reass" }, - { TAG_IP_TTL, "bip-ttl" }, - { TAG_IP_PMTUTO, "lip-mtuto" }, - { TAG_IP_PMTUPTAB, "sip-mtutab" }, - { TAG_IPIF_MTU, "sif-mtu" }, - { TAG_IPIF_LSUBNET, "bif-lsubnet" }, - { TAG_IPIF_BADDR, "iif-bcast" }, - { TAG_IPIF_MDISC, "bif-mdisc" }, - { TAG_IPIF_MSUPP, "bif-msupp" }, - { TAG_IPIF_RDISC, "bif-rdisc" }, - { TAG_IPIF_RSOLADDR, "iif-rsoladdr" }, - { TAG_IPIF_SROUTE, "iif-staticroute" }, - { TAG_LINK_TRAILER, "blink-trailer" }, - { TAG_LINK_ARPTO, "blink-arpto" }, - { TAG_LINK_ETHER802, "blink-ether822" }, - { TAG_TCP_DEFTTL, "btcp-defttl" }, - { TAG_TCP_KAINT, "ltcp-kaint" }, - { TAG_TCP_KAGARBAGE, "btcp-kagarbage" }, - { TAG_APP_NISDOM, "anis-dom" }, - { TAG_APP_NISOPT, "inis-srv" }, - { TAG_APP_NTPSRV, "intp-srv" }, - { TAG_VENDOR, "bvendor" }, - { TAG_APP_NB_NS_SERVER, "inetbios-ns-srv" }, - { TAG_APP_NB_DD_SERVER, "inetbios-dd-srv" }, - { TAG_APP_NB_NODETYPE, "bnetbios-nodetype" }, - { TAG_APP_NB_SCOPE, "inetbios-scope" }, - { TAG_APP_X_FS, "ix-fs" }, - { TAG_APP_X_DM, "ix-dm" }, - { TAG_APP_NISPDOM, "anis+-dom" }, - { TAG_APP_NISPSRV, "inis+-srv" }, - { TAG_APP_MIPHA, "imip-ha" }, - { TAG_APP_SMTPSRV, "ismtp-srv" }, - { TAG_APP_POP3SRV, "ipop3-srv" }, - { TAG_APP_NNTPSRV, "inntp-srv" }, - { TAG_APP_HTTPSRV, "ihttp-srv" }, - { TAG_APP_FINGERSRV, "ifinger-srv" }, - { TAG_APP_IRCSRV, "iirc-srv" }, - { TAG_APP_STREETTALKSRV,"istreettalk-srv" }, - { TAG_APP_STREETTALKDA, "istreettalk-da" }, -/* (post-)RFC1533 DHCP extensions */ - { TAG_DHCP_REQIPADDR, "idhcp-reqipaddr" }, - { TAG_DHCP_LEASETIME, "ldhcp-leasetime" }, - { TAG_DHCP_OVERLOAD, "bdhcp-oerload" }, - { TAG_DHCP_TFTPSRV, "adhcp-tftpsrv" }, - { TAG_DHCP_BOOTFILE, "adhcp-bootfile" }, - { TAG_DHCP_MSGTYP, "bdhcp-msgtyp" }, - { TAG_DHCP_SRVID, "idhpc-srvid" }, - { TAG_DHCP_PRMREQ, "bdhcp-prmreq" }, - { TAG_DHCP_MSG, "adhcp-msg" }, - { TAG_DHCP_MAXSIZ, "sdhpc-maxsiz" }, - { TAG_DHCP_T1, "ldhcp-t1" }, - { TAG_DHCP_T2, "ldhcp-t2" }, - { TAG_DHCP_CLASSID, "bdhcp-classid" }, - { TAG_DHCP_CLIENTID, "bdhcp-cliid" }, + { TAG_DUMPPATH, "aDP" }, + { TAG_DOMAINNAME, "aDN" }, + { TAG_SWAP_SERVER, "iSS" }, + { TAG_ROOTPATH, "aRP" }, + { TAG_EXTPATH, "aEP" }, +/* RFC2132 tags */ + { TAG_IP_FORWARD, "BIPF" }, + { TAG_NL_SRCRT, "BSRT" }, + { TAG_PFILTERS, "pPF" }, + { TAG_REASS_SIZE, "sRSZ" }, + { TAG_DEF_TTL, "bTTL" }, + { TAG_MTU_TIMEOUT, "lMA" }, + { TAG_MTU_TABLE, "sMT" }, + { TAG_INT_MTU, "sMTU" }, + { TAG_LOCAL_SUBNETS, "BLSN" }, + { TAG_BROAD_ADDR, "iBR" }, + { TAG_DO_MASK_DISC, "BMD" }, + { TAG_SUPPLY_MASK, "BMS" }, + { TAG_DO_RDISC, "BRD" }, + { TAG_RTR_SOL_ADDR, "iRSA" }, + { TAG_STATIC_ROUTE, "pSR" }, + { TAG_USE_TRAILERS, "BUT" }, + { TAG_ARP_TIMEOUT, "lAT" }, + { TAG_ETH_ENCAP, "BIE" }, + { TAG_TCP_TTL, "bTT" }, + { TAG_TCP_KEEPALIVE, "lKI" }, + { TAG_KEEPALIVE_GO, "BKG" }, + { TAG_NIS_DOMAIN, "aYD" }, + { TAG_NIS_SERVERS, "iYS" }, + { TAG_NTP_SERVERS, "iNTP" }, + { TAG_VENDOR_OPTS, "bVO" }, + { TAG_NETBIOS_NS, "iWNS" }, + { TAG_NETBIOS_DDS, "iWDD" }, + { TAG_NETBIOS_NODE, "$WNT" }, + { TAG_NETBIOS_SCOPE, "aWSC" }, + { TAG_XWIN_FS, "iXFS" }, + { TAG_XWIN_DM, "iXDM" }, + { TAG_NIS_P_DOMAIN, "sN+D" }, + { TAG_NIS_P_SERVERS, "iN+S" }, + { TAG_MOBILE_HOME, "iMH" }, + { TAG_SMPT_SERVER, "iSMTP" }, + { TAG_POP3_SERVER, "iPOP3" }, + { TAG_NNTP_SERVER, "iNNTP" }, + { TAG_WWW_SERVER, "iWWW" }, + { TAG_FINGER_SERVER, "iFG" }, + { TAG_IRC_SERVER, "iIRC" }, + { TAG_STREETTALK_SRVR, "iSTS" }, + { TAG_STREETTALK_STDA, "iSTDA" }, + { TAG_REQUESTED_IP, "iRQ" }, + { TAG_IP_LEASE, "lLT" }, + { TAG_OPT_OVERLOAD, "$OO" }, + { TAG_TFTP_SERVER, "aTFTP" }, + { TAG_BOOTFILENAME, "aBF" }, + { TAG_DHCP_MESSAGE, " DHCP" }, + { TAG_SERVER_ID, "iSID" }, + { TAG_PARM_REQUEST, "bPR" }, + { TAG_MESSAGE, "aMSG" }, + { TAG_MAX_MSG_SIZE, "sMSZ" }, + { TAG_RENEWAL_TIME, "lRN" }, + { TAG_REBIND_TIME, "lRB" }, + { TAG_VENDOR_CLASS, "aVC" }, + { TAG_CLIENT_ID, "$CID" }, +/* RFC 2485 */ + { TAG_OPEN_GROUP_UAP, "aUAP" }, +/* RFC 2563 */ + { TAG_DISABLE_AUTOCONF, "BNOAUTO" }, +/* RFC 2610 */ + { TAG_SLP_DA, "bSLP-DA" }, /*"b" is a little wrong */ + { TAG_SLP_SCOPE, "bSLP-SCOPE" }, /*"b" is a little wrong */ +/* RFC 2937 */ + { TAG_NS_SEARCH, "sNSSEARCH" }, /* XXX 's' */ +/* RFC 3011 */ + { TAG_IP4_SUBNET_SELECT, "iSUBNET" }, +/* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */ + { TAG_USER_CLASS, "aCLASS" }, + { TAG_SLP_NAMING_AUTH, "aSLP-NA" }, + { TAG_CLIENT_FQDN, "$FQDN" }, + { TAG_AGENT_CIRCUIT, "bACKT" }, + { TAG_AGENT_REMOTE, "bARMT" }, + { TAG_AGENT_MASK, "bAMSK" }, + { TAG_TZ_STRING, "aTZSTR" }, + { TAG_FQDN_OPTION, "bFQDNS" }, /* XXX 'b' */ + { TAG_AUTH, "bAUTH" }, /* XXX 'b' */ + { TAG_VINES_SERVERS, "iVINES" }, + { TAG_SERVER_RANK, "sRANK" }, + { TAG_CLIENT_ARCH, "sARCH" }, + { TAG_CLIENT_NDI, "bNDI" }, /* XXX 'b' */ + { TAG_CLIENT_GUID, "bGUID" }, /* XXX 'b' */ + { TAG_LDAP_URL, "aLDAP" }, + { TAG_6OVER4, "i6o4" }, + { TAG_PRINTER_NAME, "aPRTR" }, + { TAG_MDHCP_SERVER, "bMDHCP" }, /* XXX 'b' */ + { TAG_IPX_COMPAT, "bIPX" }, /* XXX 'b' */ + { TAG_NETINFO_PARENT, "iNI" }, + { TAG_NETINFO_PARENT_TAG, "aNITAG" }, + { TAG_URL, "aURL" }, + { TAG_FAILOVER, "bFAIL" }, /* XXX 'b' */ + { 0, NULL } +}; +/* 2-byte extended tags */ +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_int16_t tag; register u_int len, size; register const char *cp; register char c; int first; u_int32_t ul; - u_short us; + u_int16_t us; + u_int8_t uc; - printf(" vend-rfc1048"); + printf("\n\t Vendor-rfc1048:"); /* Step over magic cookie */ bp += sizeof(int32_t); @@ -291,9 +360,18 @@ rfc1048_print(register const u_char *bp, register u_int length) continue; if (tag == TAG_END) return; - cp = tok2str(tag2str, "?T%d", tag); + if (tag == TAG_EXTENDED_OPTION) { + TCHECK2(*(bp + 1), 2); + tag = EXTRACT_16BITS(bp + 1); + /* XXX we don't know yet if the IANA will + * preclude overlap of 1-byte and 2-byte spaces. + * If not, we need to offset tag after this step. + */ + cp = tok2str(xtag2str, "?xT%u", tag); + } else + cp = tok2str(tag2str, "?T%u", tag); c = *cp++; - printf(" %s:", cp); + printf("\n\t %s:", cp); /* Get the length; check for truncation */ if (bp + 1 >= snapend) { @@ -302,10 +380,53 @@ rfc1048_print(register const u_char *bp, register u_int length) } len = *bp++; if (bp + len >= snapend) { - fputs(tstr, stdout); + printf("[|bootp %u]", len); return; } + if (tag == TAG_DHCP_MESSAGE && len == 1) { + uc = *bp++; + switch (uc) { + case DHCPDISCOVER: printf("DISCOVER"); break; + case DHCPOFFER: printf("OFFER"); break; + case DHCPREQUEST: printf("REQUEST"); break; + case DHCPDECLINE: printf("DECLINE"); break; + case DHCPACK: printf("ACK"); break; + case DHCPNAK: printf("NACK"); break; + case DHCPRELEASE: printf("RELEASE"); break; + case DHCPINFORM: printf("INFORM"); break; + default: printf("%u", uc); break; + } + continue; + } + + if (tag == TAG_PARM_REQUEST) { + first = 1; + while (len-- > 0) { + uc = *bp++; + cp = tok2str(tag2str, "?T%u", uc); + if (!first) + putchar('+'); + printf("%s", cp + 1); + first = 0; + } + continue; + } + if (tag == TAG_EXTENDED_REQUEST) { + first = 1; + while (len > 1) { + len -= 2; + us = EXTRACT_16BITS(bp); + bp += 2; + cp = tok2str(xtag2str, "?xT%u", us); + if (!first) + putchar('+'); + printf("%s", cp + 1); + first = 0; + } + continue; + } + /* Print data */ size = len; if (c == '?') { @@ -331,13 +452,17 @@ rfc1048_print(register const u_char *bp, register u_int length) case 'i': case 'l': + case 'L': /* ip addresses/32-bit words */ while (size >= sizeof(ul)) { if (!first) putchar(','); - memcpy((char *)&ul, (char *)bp, sizeof(ul)); - if (c == 'i') + ul = EXTRACT_32BITS(bp); + if (c == 'i') { + ul = htonl(ul); printf("%s", ipaddr_string(&ul)); + } else if (c == 'L') + printf("%d", ul); else printf("%u", ul); bp += sizeof(ul); @@ -346,50 +471,162 @@ rfc1048_print(register const u_char *bp, register u_int length) } break; + case 'p': + /* IP address pairs */ + while (size >= 2*sizeof(ul)) { + if (!first) + putchar(','); + memcpy((char *)&ul, (const char *)bp, sizeof(ul)); + printf("(%s:", ipaddr_string(&ul)); + bp += sizeof(ul); + memcpy((char *)&ul, (const char *)bp, sizeof(ul)); + printf("%s)", ipaddr_string(&ul)); + bp += sizeof(ul); + size -= 2*sizeof(ul); + first = 0; + } + break; + case 's': /* shorts */ while (size >= sizeof(us)) { if (!first) putchar(','); - memcpy((char *)&us, (char *)bp, sizeof(us)); - printf("%d", us); + us = EXTRACT_16BITS(bp); + printf("%u", us); bp += sizeof(us); size -= sizeof(us); first = 0; } break; + case 'B': + /* boolean */ + while (size > 0) { + if (!first) + putchar(','); + switch (*bp) { + case 0: + putchar('N'); + break; + case 1: + putchar('Y'); + break; + default: + printf("%u?", *bp); + break; + } + ++bp; + --size; + first = 0; + } + break; + case 'b': + case 'x': default: /* Bytes */ while (size > 0) { if (!first) - putchar('.'); - printf("%d", *bp); + putchar(c == 'x' ? ':' : '.'); + if (c == 'x') + printf("%02x", *bp); + else + printf("%u", *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: + /* option 81 should be at least 4 bytes long */ + if (len < 4) + printf("ERROR: options 81 len %u < 4 bytes", len); + break; + if (*bp++) + printf("[svrreg]"); + if (*bp) + printf("%u/%u/", *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('"'); + bp += size; + size = 0; + 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 %u, size %u]", + tag, size); + bp += size; + size = 0; + break; + } + break; } /* Data left over? */ - if (size) - printf("[len %d]", len); + if (size) { + printf("[len %u]", len); + bp += size; + } } + return; +trunc: + printf("|[rfc1048]"); } 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/kame/kame/tcpdump/print-cdp.c b/kame/kame/tcpdump/print-cdp.c new file mode 100644 index 0000000000..c69d962983 --- /dev/null +++ b/kame/kame/tcpdump/print-cdp.c @@ -0,0 +1,365 @@ +/* + * Copyright (c) 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. + * + * Code by Gert Doering, SpaceNet GmbH, gert@space.net + * + * Reference documentation: + * http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-cdp.c,v 1.19.2.5 2004/03/24 06:00:51 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" /* must come after interface.h */ + +#define CDP_HEADER_LEN 4 + +static struct tok cdp_tlv_values[] = { + { 0x01, "Device-ID"}, + { 0x02, "Address"}, + { 0x03, "Port-ID"}, + { 0x04, "Capability"}, + { 0x05, "Version String"}, + { 0x06, "Platform"}, + { 0x07, "Prefixes"}, + { 0x08, "Protocol-Hello option"}, + { 0x09, "VTP Management Domain"}, + { 0x0a, "Native VLAN ID"}, + { 0x0b, "Duplex"}, + { 0x0e, "ATA-186 VoIP VLAN request"}, + { 0x0f, "ATA-186 VoIP VLAN assignment"}, + { 0x10, "power consumption"}, + { 0x11, "MTU"}, + { 0x12, "AVVID trust bitmap"}, + { 0x13, "AVVID untrusted ports CoS"}, + { 0x14, "System Name"}, + { 0x15, "System Object ID (not decoded)"}, + { 0x16, "Management Addresses"}, + { 0x17, "Physical Location"}, + { 0, NULL} +}; + +static struct tok cdp_capability_values[] = { + { 0x01, "Router" }, + { 0x02, "Transparent Bridge" }, + { 0x04, "Source Route Bridge" }, + { 0x08, "L2 Switch" }, + { 0x10, "L3 capable" }, + { 0x20, "IGMP snooping" }, + { 0x40, "L1 capable" }, + { 0, NULL } +}; + +static int cdp_print_addr(const u_char *, int); +static int cdp_print_prefixes(const u_char *, int); +static unsigned long cdp_get_number(const u_char *, int); + +void +cdp_print(const u_char *pptr, u_int length, u_int caplen) +{ + int type, len, i, j; + const u_char *tptr; + + if (caplen < CDP_HEADER_LEN) { + (void)printf("[|cdp]"); + return; + } + + tptr = pptr; /* temporary pointer */ + + if (!TTEST2(*tptr, CDP_HEADER_LEN)) + goto trunc; + printf("CDPv%u, ttl: %us", *tptr, *(tptr+1)); + if (vflag) + printf(", checksum: %u (unverified), length %u", EXTRACT_16BITS(tptr), length); + tptr += CDP_HEADER_LEN; + + while (tptr < (pptr+length)) { + + if (!TTEST2(*tptr, 4)) /* read out Type and Length */ + goto trunc; + type = EXTRACT_16BITS(tptr); + len = EXTRACT_16BITS(tptr+2); /* object length includes the 4 bytes header length */ + tptr += 4; + len -= 4; + + if (!TTEST2(*tptr, len)) + goto trunc; + + if (vflag || type == 1) { /* in non-verbose mode just print Device-ID */ + + if (vflag) + printf("\n\t%s (0x%02x), length: %u byte%s: ", + tok2str(cdp_tlv_values,"unknown field type", type), + type, + len, + len>1 ? "s" : ""); /* plural */ + + switch (type) { + + case 0x01: /* Device-ID */ + if (!vflag) + printf(", Device-ID '%.*s'", len, tptr); + else + printf("'%.*s'", len, tptr); + break; + case 0x02: /* Address */ + if (cdp_print_addr(tptr, len) < 0) + goto trunc; + break; + case 0x03: /* Port-ID */ + printf("'%.*s'", len, tptr); + break; + case 0x04: /* Capabilities */ + printf("(0x%08x): %s", + EXTRACT_32BITS(tptr), + bittok2str(cdp_capability_values, "none",EXTRACT_32BITS(tptr))); + break; + case 0x05: /* Version */ + printf("\n\t "); + for (i=0;i= 0) { + TCHECK2(*p, 2); + if (p + 2 > endp) + goto trunc; + pt = p[0]; /* type of "protocol" field */ + pl = p[1]; /* length of "protocol" field */ + p += 2; + + TCHECK2(p[pl], 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; + + TCHECK2(*p, 4); + if (p + 4 > endp) + goto trunc; + printf("IPv4 (%u) %s", + num, + ipaddr_string(p)); + 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; + TCHECK2(*p, al); + if (p + al > endp) + goto trunc; + + printf("IPv6 (%u) %s", + num, + ip6addr_string(p)); + p += al; + } +#endif + else { + /* + * Generic case: just print raw data + */ + TCHECK2(*p, pl); + if (p + pl > endp) + goto trunc; + printf("pt=0x%02x, pl=%d, pb=", *(p - 2), pl); + while (pl-- > 0) + printf(" %02x", *p++); + TCHECK2(*p, 2); + if (p + 2 > endp) + goto trunc; + al = (*p << 8) + *(p + 1); + printf(", al=%d, a=", al); + p += 2; + TCHECK2(*p, al); + if (p + al > endp) + goto trunc; + while (al-- > 0) + printf(" %02x", *p++); + } + num--; + if (num) + printf(" "); + } + + return 0; + +trunc: + return -1; +} + + +static int +cdp_print_prefixes(const u_char * p, int l) +{ + 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; + +trunc: + return -1; +} + +/* read in a -byte number, MSB first + * (of course this can handle max sizeof(long)) + */ +static unsigned long cdp_get_number(const u_char * p, int l) +{ + unsigned long res=0; + while( l>0 ) + { + res = (res<<8) + *p; + p++; l--; + } + return res; +} diff --git a/kame/kame/tcpdump/print-chdlc.c b/kame/kame/tcpdump/print-chdlc.c index 8a5fe55939..583b0ba48a 100644 --- a/kame/kame/tcpdump/print-chdlc.c +++ b/kame/kame/tcpdump/print-chdlc.c @@ -1,4 +1,3 @@ -/* maybe it should be merged into print-ppp.c */ /* * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997 * The Regents of the University of California. All rights reserved. @@ -21,75 +20,43 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvsroot/hydrangea-freebsd/kit/src/tcpdump/Attic/print-chdlc.c,v 1.1.2.1.2.2 1999/01/29 07:55:57 itojun Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-chdlc.c,v 1.28.2.3 2004/03/24 00:46:03 guy Exp $ (LBL)"; #endif -#include -#include -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include -#include -#include -#include -#include +#include -#include -#include #include #include -#ifdef __bsdi__ -#include -#include -#endif #include "interface.h" #include "addrtoname.h" +#include "ethertype.h" +#include "extract.h" #include "ppp.h" - -/* XXX This goes somewhere else. */ -#define CHDLC_HDRLEN 4 -#define CHDLC_UNICAST 0x0f -#define CHDLC_BCAST 0x8f -#define CHDLC_TYPE_SLARP 0x8035 -#define CHDLC_TYPE_CDP 0x2000 +#include "chdlc.h" static void chdlc_slarp_print(const u_char *, u_int); /* Standard CHDLC printer */ -void -chdlc_if_print(u_char *user, const struct pcap_pkthdr *h, - register const u_char *p) +u_int +chdlc_if_print(const struct pcap_pkthdr *h, register const u_char *p) { register u_int length = h->len; register u_int caplen = h->caplen; const struct ip *ip; u_int proto; - ts_print(&h->ts); - if (caplen < CHDLC_HDRLEN) { printf("[|chdlc]"); - goto out; + return (caplen); } - /* - * 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; - + proto = EXTRACT_16BITS(&p[2]); if (eflag) { switch (p[0]) { case CHDLC_UNICAST: @@ -106,8 +73,8 @@ chdlc_if_print(u_char *user, const struct pcap_pkthdr *h, } length -= CHDLC_HDRLEN; - ip = (struct ip *)(p + CHDLC_HDRLEN); - switch(proto) { + ip = (const struct ip *)(p + CHDLC_HDRLEN); + switch (proto) { case ETHERTYPE_IP: ip_print((const u_char *)ip, length); break; @@ -124,15 +91,29 @@ chdlc_if_print(u_char *user, const struct pcap_pkthdr *h, chdlc_cdp_print((const u_char *)ip, length); break; #endif + case ETHERTYPE_MPLS: + case ETHERTYPE_MPLS_MULTI: + mpls_print((const u_char *)(ip), length); + break; + case ETHERTYPE_ISO: + /* is the fudge byte set ? lets verify by spotting ISO headers */ + if (*(p+CHDLC_HDRLEN+1) == 0x81 || + *(p+CHDLC_HDRLEN+1) == 0x82 || + *(p+CHDLC_HDRLEN+1) == 0x83) + isoclns_print(p+CHDLC_HDRLEN+1, length-1, length-1); + else + isoclns_print(p+CHDLC_HDRLEN, length, length); + break; + default: + printf("unknown CHDLC protocol (0x%04x)", proto); + break; } - if (xflag) - default_print((const u_char *)ip, caplen - CHDLC_HDRLEN); -out: - putchar('\n'); + + return (CHDLC_HDRLEN); } struct cisco_slarp { - long code; + u_int32_t code; #define SLARP_REQUEST 0 #define SLARP_REPLY 1 #define SLARP_KEEPALIVE 2 @@ -140,14 +121,14 @@ struct cisco_slarp { struct { struct in_addr addr; struct in_addr mask; - u_short unused[3]; + u_int16_t unused[3]; } addr; struct { - long myseq; - long yourseq; - short rel; - short t1; - short t2; + u_int32_t myseq; + u_int32_t yourseq; + u_int16_t rel; + u_int16_t t1; + u_int16_t t2; } keep; } un; }; @@ -157,36 +138,47 @@ 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; - } + if (length < SLARP_LEN) + goto trunc; - slarp = (struct cisco_slarp *)cp; - switch (ntohl(slarp->code)) { + slarp = (const struct cisco_slarp *)cp; + TCHECK(*slarp); + printf("SLARP (length: %u), ",length); + switch (EXTRACT_32BITS(&slarp->code)) { case SLARP_REQUEST: - printf("slarp-request"); + printf("request"); + /* ok we do not know it - but lets at least dump it */ + print_unknown_data(cp+4,"\n\t",length-4); break; case SLARP_REPLY: - printf("slarp-reply %s/%s", + printf("reply %s/%s", ipaddr_string(&slarp->un.addr.addr), ipaddr_string(&slarp->un.addr.mask)); break; case SLARP_KEEPALIVE: - printf("slarp-keepalive my=0x%x your=0x%x ", - (u_int32_t)ntohl(slarp->un.keep.myseq), - (u_int32_t)ntohl(slarp->un.keep.yourseq)); - printf("reliability=0x%04x t1=%d.%d", - ntohs(slarp->un.keep.rel), ntohs(slarp->un.keep.t1), - ntohs(slarp->un.keep.t2)); + printf("keepalive: mineseen=0x%08x, yourseen=0x%08x", + EXTRACT_32BITS(&slarp->un.keep.myseq), + EXTRACT_32BITS(&slarp->un.keep.yourseq)); + printf(", reliability=0x%04x, t1=%d.%d", + EXTRACT_16BITS(&slarp->un.keep.rel), + EXTRACT_16BITS(&slarp->un.keep.t1), + EXTRACT_16BITS(&slarp->un.keep.t2)); break; default: - printf("slarp-0x%x unknown", (u_int32_t)ntohl(slarp->code)); + printf("0x%02x unknown", EXTRACT_32BITS(&slarp->code)); + if (vflag <= 1) + print_unknown_data(cp+4,"\n\t",length-4); break; } if (SLARP_LEN < length && vflag) - printf("(trailing junk: %d bytes)", length - SLARP_LEN); + printf(", (trailing junk: %d bytes)", length - SLARP_LEN); + if (vflag > 1) + print_unknown_data(cp+4,"\n\t",length-4); + return; + +trunc: + printf("[|slarp]"); } diff --git a/kame/kame/tcpdump/print-cip.c b/kame/kame/tcpdump/print-cip.c new file mode 100644 index 0000000000..17dd308ef1 --- /dev/null +++ b/kame/kame/tcpdump/print-cip.c @@ -0,0 +1,108 @@ +/* + * Marko Kiiskila carnil@cs.tut.fi + * + * Tampere University of Technology - Telecommunications Laboratory + * + * Permission to use, copy, modify and distribute this + * software and its documentation is hereby granted, + * provided that both the copyright notice and this + * permission notice appear in all copies of the software, + * derivative works or modified versions, and any portions + * thereof, that both notices appear in supporting + * documentation, and that the use of this software is + * acknowledged in any publications resulting from using + * the software. + * + * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS + * SOFTWARE. + * + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-cip.c,v 1.21.2.2 2003/11/16 08:51:15 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include + +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "ethertype.h" +#include "ether.h" + +#define RFC1483LLC_LEN 8 + +static unsigned char rfcllc[] = { + 0xaa, /* DSAP: non-ISO */ + 0xaa, /* SSAP: non-ISO */ + 0x03, /* Ctrl: Unnumbered Information Command PDU */ + 0x00, /* OUI: EtherType */ + 0x00, + 0x00 }; + +static inline void +cip_print(int length) +{ + /* + * There is no MAC-layer header, so just print the length. + */ + printf("%d: ", length); +} + +/* + * This is the top level routine of the printer. 'p' points + * to the LLC/SNAP or raw header of the packet, 'h->ts' is the timestamp, + * 'h->length' is the length of the packet off the wire, and 'h->caplen' + * is the number of bytes actually captured. + */ +u_int +cip_if_print(const struct pcap_pkthdr *h, const u_char *p) +{ + u_int caplen = h->caplen; + u_int length = h->len; + u_short extracted_ethertype; + + if (memcmp(rfcllc, p, sizeof(rfcllc))==0 && caplen < RFC1483LLC_LEN) { + printf("[|cip]"); + return (0); + } + + if (eflag) + cip_print(length); + + 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) { + /* ether_type not known, print raw packet */ + if (!eflag) + cip_print(length); + if (extracted_ethertype) { + printf("(LLC %s) ", + etherproto_string(htons(extracted_ethertype))); + } + if (!xflag && !qflag) + default_print(p, caplen); + } + } else { + /* + * LLC header is absent; treat it as just IP. + */ + ip_print(p, length); + } + + return (0); +} diff --git a/kame/kame/tcpdump/print-cnfp.c b/kame/kame/tcpdump/print-cnfp.c new file mode 100644 index 0000000000..0179ba7bee --- /dev/null +++ b/kame/kame/tcpdump/print-cnfp.c @@ -0,0 +1,184 @@ +/* $OpenBSD: print-cnfp.c,v 1.2 1998/06/25 20:26:59 mickey Exp $ */ + +/* + * Copyright (c) 1998 Michael Shalayeff + * 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 Michael Shalayeff. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * 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. + */ + +/* Cisco NetFlow protocol */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-cnfp.c,v 1.14.2.2 2003/11/16 08:51:15 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" + +#include "tcp.h" +#include "ipproto.h" + +struct nfhdr { + u_int32_t ver_cnt; /* version [15], and # of records */ + u_int32_t msys_uptime; + u_int32_t utc_sec; + u_int32_t utc_nsec; + u_int32_t sequence; /* v5 flow sequence number */ + u_int32_t reserved; /* v5 only */ +}; + +struct nfrec { + struct in_addr src_ina; + struct in_addr dst_ina; + struct in_addr nhop_ina; + u_int32_t ifaces; /* src,dst ifaces */ + u_int32_t packets; + u_int32_t octets; + u_int32_t start_time; /* sys_uptime value */ + u_int32_t last_time; /* sys_uptime value */ + 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; v6: encaps */ + struct in_addr peer_nexthop; /* v6: IP address of the nexthop within the peer (FIB)*/ +}; + +void +cnfp_print(const u_char *cp, const u_char *bp) +{ + register const struct nfhdr *nh; + register const struct nfrec *nr; + register const struct ip *ip; + struct protoent *pent; + int nrecs, ver; + time_t t; + + ip = (const struct ip *)bp; + nh = (const struct nfhdr *)cp; + + if ((const u_char *)(nh + 1) > snapend) + return; + + nrecs = EXTRACT_32BITS(&nh->ver_cnt) & 0xffff; + ver = (EXTRACT_32BITS(&nh->ver_cnt) & 0xffff0000) >> 16; + t = EXTRACT_32BITS(&nh->utc_sec); +/* (p = ctime(&t))[24] = '\0'; */ + + printf("NetFlow v%x, %u.%03u uptime, %u.%09u, ", ver, + EXTRACT_32BITS(&nh->msys_uptime)/1000, + EXTRACT_32BITS(&nh->msys_uptime)%1000, + EXTRACT_32BITS(&nh->utc_sec), EXTRACT_32BITS(&nh->utc_nsec)); + + if (ver == 5 || ver == 6) { + printf("#%u, ", EXTRACT_32BITS(&nh->sequence)); + nr = (const struct nfrec *)&nh[1]; + snaplen -= 24; + } else { + nr = (const struct nfrec *)&nh->sequence; + snaplen -= 16; + } + + printf("%2u recs", nrecs); + + for (; nrecs-- && (const u_char *)(nr + 1) <= snapend; nr++) { + char buf[20]; + char asbuf[20]; + + printf("\n started %u.%03u, last %u.%03u", + EXTRACT_32BITS(&nr->start_time)/1000, + EXTRACT_32BITS(&nr->start_time)%1000, + EXTRACT_32BITS(&nr->last_time)/1000, + EXTRACT_32BITS(&nr->last_time)%1000); + + asbuf[0] = buf[0] = '\0'; + if (ver == 5 || ver == 6) { + snprintf(buf, sizeof(buf), "/%u", + (EXTRACT_32BITS(&nr->masks) >> 24) & 0xff); + snprintf(asbuf, sizeof(asbuf), ":%u", + (EXTRACT_32BITS(&nr->asses) >> 16) & 0xffff); + } + printf("\n %s%s%s:%u ", intoa(nr->src_ina.s_addr), buf, asbuf, + EXTRACT_32BITS(&nr->ports) >> 16); + + if (ver == 5 || ver ==6) { + snprintf(buf, sizeof(buf), "/%d", + (EXTRACT_32BITS(&nr->masks) >> 16) & 0xff); + snprintf(asbuf, sizeof(asbuf), ":%u", + EXTRACT_32BITS(&nr->asses) & 0xffff); + } + printf("> %s%s%s:%u ", intoa(nr->dst_ina.s_addr), buf, asbuf, + EXTRACT_32BITS(&nr->ports) & 0xffff); + + printf(">> %s\n ", intoa(nr->nhop_ina.s_addr)); + + pent = getprotobynumber((EXTRACT_32BITS(&nr->proto_tos) >> 8) & 0xff); + if (!pent || nflag) + printf("%u ", + (EXTRACT_32BITS(&nr->proto_tos) >> 8) & 0xff); + else + printf("%s ", pent->p_name); + + /* tcp flags for tcp only */ + if (pent && pent->p_proto == IPPROTO_TCP) { + int flags; + if (ver == 1) + flags = (EXTRACT_32BITS(&nr->asses) >> 24) & 0xff; + else + flags = (EXTRACT_32BITS(&nr->proto_tos) >> 16) & 0xff; + if (flags & TH_FIN) putchar('F'); + if (flags & TH_SYN) putchar('S'); + if (flags & TH_RST) putchar('R'); + if (flags & TH_PUSH) putchar('P'); + if (flags & TH_ACK) putchar('A'); + if (flags & TH_URG) putchar('U'); + if (flags) + putchar(' '); + } + + buf[0]='\0'; + if (ver == 6) { + snprintf(buf, sizeof(buf), "(%u<>%u encaps)", + (EXTRACT_32BITS(&nr->masks) >> 8) & 0xff, + (EXTRACT_32BITS(&nr->masks)) & 0xff); + } + printf("tos %u, %u (%u octets) %s", + EXTRACT_32BITS(&nr->proto_tos) & 0xff, + EXTRACT_32BITS(&nr->packets), + EXTRACT_32BITS(&nr->octets), buf); + } +} diff --git a/kame/kame/tcpdump/print-decnet.c b/kame/kame/tcpdump/print-decnet.c index 29b85bdacc..f84b080e4d 100644 --- a/kame/kame/tcpdump/print-decnet.c +++ b/kame/kame/tcpdump/print-decnet.c @@ -20,32 +20,26 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-decnet.c,v 1.26 97/05/28 12:51:29 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-decnet.c,v 1.36.2.2 2003/11/16 08:51:16 guy Exp $ (LBL)"; #endif -#include -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include -#if __STDC__ struct mbuf; struct rtentry; -#endif -#include -#ifdef HAVE_LIBDNET +#ifdef HAVE_NETDNET_DNETDB_H #include #endif -#include -#ifdef HAVE_MALLOC_H -#include -#endif #include #include #include -#include #include "decnet.h" #include "extract.h" @@ -65,7 +59,7 @@ static void print_reason(int); static void pdata(u_char *, int); #endif -#ifdef HAVE_LIBDNET +#ifndef HAVE_NETDNET_DNETDB_H_DNET_HTOA extern char *dnet_htoa(struct dn_naddr *); #endif @@ -346,13 +340,13 @@ print_i_info(int info) } static void -print_elist(const char *elp, u_int len) +print_elist(const char *elp _U_, u_int len _U_) { /* Not enough examples available for me to debug this */ } static void -print_nsp(const u_char *nspp, u_int nsplen) +print_nsp(const u_char *nspp, u_int nsplen _U_) { const struct nsphdr *nsphp = (struct nsphdr *)nspp; int dst, src, flags; @@ -732,29 +726,30 @@ print_reason(register int reason) printf("%s ", tok2str(reason2str, "reason-%d", reason)); } -char * +const char * dnnum_string(u_short dnaddr) { char *str; + size_t siz; int area = (u_short)(dnaddr & AREAMASK) >> AREASHIFT; int node = dnaddr & NODEMASK; - str = (char *)malloc(sizeof("00.0000")); + str = (char *)malloc(siz = sizeof("00.0000")); if (str == NULL) error("dnnum_string: malloc"); - sprintf(str, "%d.%d", area, node); + snprintf(str, siz, "%d.%d", area, node); return(str); } -char * +const char * dnname_string(u_short dnaddr) { -#ifdef HAVE_LIBDNET +#ifdef HAVE_DNET_HTOA struct dn_naddr dna; 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 @@ -769,10 +764,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/kame/kame/tcpdump/print-dhcp6.c b/kame/kame/tcpdump/print-dhcp6.c new file mode 100644 index 0000000000..1193e3778a --- /dev/null +++ b/kame/kame/tcpdump/print-dhcp6.c @@ -0,0 +1,609 @@ +/* + * Copyright (C) 1998 and 1999 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. + */ +/* + * RFC3315: DHCPv6 + * supported DHCPv6 options: + * RFC3319, + * draft-ietf-dhc-dhcpv6-opt-dnsconfig-04.txt, + * draft-ietf-dhc-dhcpv6-opt-prefix-delegation-05.txt + * draft-ietf-dhc-dhcpv6-opt-timeconfig-02.txt, + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-dhcp6.c,v 1.27.2.4 2003/11/18 23:26:14 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" + +/* lease duration */ +#define DHCP6_DURATITION_INFINITE 0xffffffff + +/* Error Values */ +#define DH6ERR_FAILURE 16 +#define DH6ERR_AUTHFAIL 17 +#define DH6ERR_POORLYFORMED 18 +#define DH6ERR_UNAVAIL 19 +#define DH6ERR_OPTUNAVAIL 20 + +/* Message type */ +#define DH6_SOLICIT 1 +#define DH6_ADVERTISE 2 +#define DH6_REQUEST 3 +#define DH6_CONFIRM 4 +#define DH6_RENEW 5 +#define DH6_REBIND 6 +#define DH6_REPLY 7 +#define DH6_RELEASE 8 +#define DH6_DECLINE 9 +#define DH6_RECONFIGURE 10 +#define DH6_INFORM_REQ 11 +#define DH6_RELAY_FORW 12 +#define DH6_RELAY_REPLY 13 + +/* DHCP6 base packet format */ +struct dhcp6 { + union { + u_int8_t m; + u_int32_t x; + } dh6_msgtypexid; + /* options follow */ +}; +#define dh6_msgtype dh6_msgtypexid.m +#define dh6_xid dh6_msgtypexid.x +#define DH6_XIDMASK 0x00ffffff + +/* DHCPv6 relay messages */ +struct dhcp6_relay { + u_int8_t dh6relay_msgtype; + u_int8_t dh6relay_hcnt; + u_int8_t dh6relay_linkaddr[16]; /* XXX: badly aligned */ + u_int8_t dh6relay_peeraddr[16]; + /* options follow */ +}; + +/* options */ +#define DH6OPT_CLIENTID 1 +#define DH6OPT_SERVERID 2 +#define DH6OPT_IA_NA 3 +#define DH6OPT_IA_TMP 4 +#define DH6OPT_IADDR 5 +#define DH6OPT_ORO 6 +#define DH6OPT_PREFERENCE 7 +# define DH6OPT_PREF_UNDEF -1 +# define DH6OPT_PREF_MAX 255 +#define DH6OPT_ELAPSED_TIME 8 +#define DH6OPT_RELAY_MSG 9 +/*#define DH6OPT_SERVER_MSG 10 deprecated */ +#define DH6OPT_AUTH 11 +#define DH6OPT_UNICAST 12 +#define DH6OPT_STATUS_CODE 13 +# define DH6OPT_STCODE_SUCCESS 0 +# define DH6OPT_STCODE_UNSPECFAIL 1 +# define DH6OPT_STCODE_NOADDRAVAIL 2 +# define DH6OPT_STCODE_NOBINDING 3 +# define DH6OPT_STCODE_NOTONLINK 4 +# define DH6OPT_STCODE_USEMULTICAST 5 +# define DH6OPT_STCODE_NOPREFIXAVAIL 6 +#define DH6OPT_RAPID_COMMIT 14 +#define DH6OPT_USER_CLASS 15 +#define DH6OPT_VENDOR_CLASS 16 +#define DH6OPT_VENDOR_OPTS 17 +#define DH6OPT_INTERFACE_ID 18 +#define DH6OPT_RECONF_MSG 19 +#define DH6OPT_RECONF_ACCEPT 20 +#define DH6OPT_SIP_SERVER_D 21 +#define DH6OPT_SIP_SERVER_A 22 +#define DH6OPT_DNS 23 +#define DH6OPT_DNSNAME 24 + +/* + * The option type has not been assigned for the following options. + * We temporarily adopt values used in the service specification document + * (200206xx version) by NTT Communications. + * Note that we'll change the following definitions if different type values + * are officially assigned. + */ +#define DH6OPT_PREFIX_DELEGATION 30 +#define DH6OPT_PREFIX_INFORMATION 31 +#define DH6OPT_PREFIX_REQUEST 32 + +/* + * The followings are also unassigned numbers. + * We temporarily use values as of KAME snap 20031013. + */ +#define DH6OPT_IA_PD 33 +#define DH6OPT_IA_PD_PREFIX 34 +#define DH6OPT_NTP_SERVERS 35 + +struct dhcp6opt { + u_int16_t dh6opt_type; + u_int16_t dh6opt_len; + /* type-dependent data follows */ +}; + +struct dhcp6_ia { + u_int16_t dh6opt_ia_type; + u_int16_t dh6opt_ia_len; + u_int32_t dh6opt_ia_iaid; + u_int32_t dh6opt_ia_t1; + u_int32_t dh6opt_ia_t2; +}; + +struct dhcp6_ia_prefix { + u_int16_t dh6opt_ia_prefix_type; + u_int16_t dh6opt_ia_prefix_len; + u_int32_t dh6opt_ia_prefix_pltime; + u_int32_t dh6opt_ia_prefix_vltime; + u_int8_t dh6opt_ia_prefix_plen; + struct in6_addr dh6opt_ia_prefix_addr; +} __attribute__ ((__packed__)); + +static const char * +dhcp6opt_name(int type) +{ + static char genstr[sizeof("opt_65535") + 1]; /* XXX thread unsafe */ + + if (type > 65535) + return "INVALID option"; + + switch(type) { + case DH6OPT_CLIENTID: + return "client ID"; + case DH6OPT_SERVERID: + return "server ID"; + case DH6OPT_IA_NA: + return "IA_NA"; + case DH6OPT_ORO: + return "option request"; + case DH6OPT_PREFERENCE: + return "preference"; + case DH6OPT_ELAPSED_TIME: + return "elapsed time"; + case DH6OPT_RELAY_MSG: + return "relay message"; + case DH6OPT_STATUS_CODE: + return "status code"; + case DH6OPT_RAPID_COMMIT: + return "rapid commit"; + case DH6OPT_INTERFACE_ID: + return "interface ID"; + case DH6OPT_RECONF_MSG: + return "reconfigure message"; + case DH6OPT_RECONF_ACCEPT: + return "reconfigure accept"; + case DH6OPT_SIP_SERVER_D: + return "SIP Servers Domain"; + case DH6OPT_SIP_SERVER_A: + return "SIP Servers Address"; + case DH6OPT_DNS: + return "DNS"; + case DH6OPT_PREFIX_DELEGATION: + return "prefix delegation"; + case DH6OPT_PREFIX_INFORMATION: + return "prefix information"; + case DH6OPT_IA_PD: + return "IA_PD"; + case DH6OPT_IA_PD_PREFIX: + return "IA_PD prefix"; + case DH6OPT_NTP_SERVERS: + return "NTP Server"; + default: + snprintf(genstr, sizeof(genstr), "opt_%d", type); + return(genstr); + } +} + +static const char * +dhcp6stcode(int code) +{ + static char genstr[sizeof("code255") + 1]; /* XXX thread unsafe */ + + if (code > 255) + return "INVALID code"; + + switch(code) { + case DH6OPT_STCODE_SUCCESS: + return "success"; + case DH6OPT_STCODE_UNSPECFAIL: + return "unspec failure"; + case DH6OPT_STCODE_NOADDRAVAIL: + return "no addresses"; + case DH6OPT_STCODE_NOBINDING: + return "no binding"; + case DH6OPT_STCODE_NOTONLINK: + return "not on-link"; + case DH6OPT_STCODE_USEMULTICAST: + return "use multicast"; + case DH6OPT_STCODE_NOPREFIXAVAIL: + return "no prefixes"; + default: + snprintf(genstr, sizeof(genstr), "code%d", code); + return(genstr); + } +} + +static void +dhcp6opt_print(const u_char *cp, const u_char *ep) +{ + struct dhcp6opt *dh6o; + u_char *tp; + size_t i; + u_int16_t opttype; + size_t optlen; + u_int16_t val16; + u_int32_t val32; + struct in6_addr addr6; + struct dhcp6_ia ia; + struct dhcp6_ia_prefix ia_prefix; + + if (cp == ep) + return; + while (cp < ep) { + if (ep < cp + sizeof(*dh6o)) + goto trunc; + dh6o = (struct dhcp6opt *)cp; + optlen = EXTRACT_16BITS(&dh6o->dh6opt_len); + if (ep < cp + sizeof(*dh6o) + optlen) + goto trunc; + opttype = EXTRACT_16BITS(&dh6o->dh6opt_type); + printf(" (%s", dhcp6opt_name(opttype)); + switch (opttype) { + case DH6OPT_CLIENTID: + case DH6OPT_SERVERID: + if (optlen < 2) { + /*(*/ + printf(" ?)"); + break; + } + tp = (u_char *)(dh6o + 1); + switch (EXTRACT_16BITS(tp)) { + case 1: + if (optlen >= 2 + 6) { + printf(" hwaddr/time type %u time %u ", + EXTRACT_16BITS(&tp[2]), + EXTRACT_32BITS(&tp[4])); + for (i = 8; i < optlen; i++) + printf("%02x", tp[i]); + /*(*/ + printf(")"); + } else { + /*(*/ + printf(" ?)"); + } + break; + case 2: + if (optlen >= 2 + 8) { + printf(" vid "); + for (i = 2; i < 2 + 8; i++) + printf("%02x", tp[i]); + /*(*/ + printf(")"); + } else { + /*(*/ + printf(" ?)"); + } + break; + case 3: + if (optlen >= 2 + 2) { + printf(" hwaddr type %u ", + EXTRACT_16BITS(&tp[2])); + for (i = 4; i < optlen; i++) + printf("%02x", tp[i]); + /*(*/ + printf(")"); + } else { + /*(*/ + printf(" ?)"); + } + break; + default: + printf(" type %d)", EXTRACT_16BITS(tp)); + break; + } + break; + case DH6OPT_ORO: + if (optlen % 2) { + printf(" ?)"); + break; + } + tp = (u_char *)(dh6o + 1); + for (i = 0; i < optlen; i += 2) { + u_int16_t opt; + + memcpy(&opt, &tp[i], sizeof(opt)); + printf(" %s", dhcp6opt_name(ntohs(opt))); + } + printf(")"); + break; + case DH6OPT_PREFERENCE: + if (optlen != 1) { + printf(" ?)"); + break; + } + printf(" %d)", *((u_char *)(dh6o + 1) + 1)); + break; + case DH6OPT_ELAPSED_TIME: + if (optlen != 2) { + printf(" ?)"); + break; + } + memcpy(&val16, dh6o + 1, sizeof(val16)); + val16 = ntohs(val16); + printf(" %d)", (int)val16); + break; + case DH6OPT_RELAY_MSG: + printf(" ("); + dhcp6_print((const u_char *)(dh6o + 1), optlen); + printf(")"); + break; + case DH6OPT_RAPID_COMMIT: /* nothing todo */ + printf(")"); + break; + case DH6OPT_INTERFACE_ID: + /* + * Since we cannot predict the encoding, print hex dump + * at most 10 characters. + */ + for (i = 0; i < optlen && i < 10; i++) + printf("%02x", ((u_char *)(dh6o + 1))[i]); + break; + case DH6OPT_RECONF_MSG: + tp = (u_char *)(dh6o + 1); + switch (*tp) { + case DH6_RENEW: + printf(" for renew)"); + break; + case DH6_INFORM_REQ: + printf(" for inf-req)"); + break; + default: + printf(" for ?\?\?(%02x))", *tp); + break; + } + break; + case DH6OPT_RECONF_ACCEPT: /* nothing todo */ + printf(")"); + break; + case DH6OPT_SIP_SERVER_A: + case DH6OPT_DNS: + case DH6OPT_NTP_SERVERS: + if (optlen % 16) { + printf(" ?)"); + break; + } + tp = (u_char *)(dh6o + 1); + for (i = 0; i < optlen; i += 16) + printf(" %s", ip6addr_string(&tp[i])); + printf(")"); + break; + case DH6OPT_PREFIX_DELEGATION: + dhcp6opt_print((u_char *)(dh6o + 1), + (u_char *)(dh6o + 1) + optlen); + printf(")"); + break; + case DH6OPT_PREFIX_INFORMATION: + if (optlen % 21) + printf(" ?)"); + memcpy(&addr6, (u_char *)(dh6o + 1) + 5, + sizeof(addr6)); + printf(" %s/%d", ip6addr_string(&addr6), + (int)*((u_char *)(dh6o + 1) + 4)); + memcpy(&val32, dh6o + 1, sizeof(val32)); + val32 = ntohl(val32); + if (val32 == DHCP6_DURATITION_INFINITE) + printf(" lease-duration: infinite)"); + else + printf(" lease-duration: %u)", val32); + break; + case DH6OPT_STATUS_CODE: + if (optlen < 2) { + printf(" ?)"); + break; + } + memcpy(&val16, (u_char *)(dh6o + 1), sizeof(val16)); + val16 = ntohs(val16); + printf(" %s)", dhcp6stcode(val16)); + break; + case DH6OPT_IA_NA: + case DH6OPT_IA_PD: + if (optlen < sizeof(ia) - 4) { + printf(" ?)"); + break; + } + memcpy(&ia, (u_char *)dh6o, sizeof(ia)); + ia.dh6opt_ia_iaid = ntohl(ia.dh6opt_ia_iaid); + ia.dh6opt_ia_t1 = ntohl(ia.dh6opt_ia_t1); + ia.dh6opt_ia_t2 = ntohl(ia.dh6opt_ia_t2); + printf(" IAID:%lu T1:%lu T2:%lu", + (unsigned long)ia.dh6opt_ia_iaid, + (unsigned long)ia.dh6opt_ia_t1, + (unsigned long)ia.dh6opt_ia_t2); + if (optlen > sizeof(ia) - 4) { + /* there are sub-options */ + dhcp6opt_print((u_char *)dh6o + sizeof(ia), + (u_char *)(dh6o + 1) + optlen); + } + printf(")"); + break; + case DH6OPT_IA_PD_PREFIX: + if (optlen < sizeof(ia_prefix) - 4) { + printf(" ?)"); + break; + } + memcpy(&ia_prefix, (u_char *)dh6o, sizeof(ia_prefix)); + printf(" %s/%d", + ip6addr_string(&ia_prefix.dh6opt_ia_prefix_addr), + ia_prefix.dh6opt_ia_prefix_plen); + ia_prefix.dh6opt_ia_prefix_pltime = + ntohl(ia_prefix.dh6opt_ia_prefix_pltime); + ia_prefix.dh6opt_ia_prefix_vltime = + ntohl(ia_prefix.dh6opt_ia_prefix_vltime); + printf(" pltime:%lu vltime:%lu", + (unsigned long)ia_prefix.dh6opt_ia_prefix_pltime, + (unsigned long)ia_prefix.dh6opt_ia_prefix_vltime); + if (optlen > sizeof(ia_prefix) - 4) { + /* there are sub-options */ + dhcp6opt_print((u_char *)dh6o + + sizeof(ia_prefix), + (u_char *)(dh6o + 1) + optlen); + } + printf(")"); + break; + default: + printf(")"); + break; + } + + cp += sizeof(*dh6o) + optlen; + } + return; + +trunc: + printf("[|dhcp6ext]"); +} + +/* + * Print dhcp6 packets + */ +void +dhcp6_print(const u_char *cp, u_int length) +{ + struct dhcp6 *dh6; + struct dhcp6_relay *dh6relay; + const u_char *ep; + u_char *extp; + const char *name; + + printf("dhcp6"); + + ep = (u_char *)snapend; + if (cp + length < ep) + ep = cp + length; + + dh6 = (struct dhcp6 *)cp; + dh6relay = (struct dhcp6_relay *)cp; + TCHECK(dh6->dh6_xid); + switch (dh6->dh6_msgtype) { + case DH6_SOLICIT: + name = "solicit"; + break; + case DH6_ADVERTISE: + name = "advertise"; + break; + case DH6_REQUEST: + name = "request"; + break; + case DH6_CONFIRM: + name = "confirm"; + break; + case DH6_RENEW: + name = "renew"; + break; + case DH6_REBIND: + name = "rebind"; + break; + case DH6_REPLY: + name = "reply"; + break; + case DH6_RELEASE: + name = "release"; + break; + case DH6_DECLINE: + name = "decline"; + break; + case DH6_RECONFIGURE: + name = "reconfigure"; + break; + case DH6_INFORM_REQ: + name= "inf-req"; + break; + case DH6_RELAY_FORW: + name= "relay-fwd"; + break; + case DH6_RELAY_REPLY: + name= "relay-reply"; + break; + default: + name = NULL; + break; + } + + if (!vflag) { + if (name) + printf(" %s", name); + else if (dh6->dh6_msgtype != DH6_RELAY_FORW && + dh6->dh6_msgtype != DH6_RELAY_REPLY) { + printf(" msgtype-%u", dh6->dh6_msgtype); + } + return; + } + + /* XXX relay agent messages have to be handled differently */ + + if (name) + printf(" %s (", name); /*)*/ + else + printf(" msgtype-%u (", dh6->dh6_msgtype); /*)*/ + if (dh6->dh6_msgtype != DH6_RELAY_FORW && + dh6->dh6_msgtype != DH6_RELAY_REPLY) { + printf("xid=%x", EXTRACT_32BITS(&dh6->dh6_xid) & DH6_XIDMASK); + extp = (u_char *)(dh6 + 1); + dhcp6opt_print(extp, ep); + } else { /* relay messages */ + struct in6_addr addr6; + + TCHECK(dh6relay->dh6relay_peeraddr); + + memcpy(&addr6, dh6relay->dh6relay_linkaddr, sizeof (addr6)); + printf("linkaddr=%s", ip6addr_string(&addr6)); + + memcpy(&addr6, dh6relay->dh6relay_peeraddr, sizeof (addr6)); + printf(" peeraddr=%s", ip6addr_string(&addr6)); + + dhcp6opt_print((u_char *)(dh6relay + 1), ep); + } + /*(*/ + printf(")"); + return; + +trunc: + printf("[|dhcp6]"); +} diff --git a/kame/kame/tcpdump/print-domain.c b/kame/kame/tcpdump/print-domain.c index 5ab2b16582..e24869c20e 100644 --- a/kame/kame/tcpdump/print-domain.c +++ b/kame/kame/tcpdump/print-domain.c @@ -20,36 +20,17 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-domain.c,v 1.39 97/06/13 12:56:28 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.86.2.3 2004/03/28 20:54:00 fenner Exp $ (LBL)"; #endif -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef NOERROR -#undef NOERROR /* Solaris sucks */ -#endif -#ifdef NOERROR -#undef T_UNSPEC /* SINIX does too */ +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include + +#include + +#include "nameser.h" #include #include @@ -58,108 +39,46 @@ struct rtentry; #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 (ipngwg-dns-lookups) */ -#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", }; /* skip over a domain name */ static const u_char * -ns_nskip(register const u_char *cp, register const u_char *bp) +ns_nskip(register const u_char *cp) { register u_char i; - if (((i = *cp++) & INDIR_MASK) == INDIR_MASK) - return (cp + 1); - while (i && cp < snapend) { - cp += i; + if (!TTEST2(*cp, 1)) + return (NULL); + i = *cp++; + while (i) { + if ((i & INDIR_MASK) == INDIR_MASK) + return (cp + 1); + 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 (!TTEST2(*cp, 1)) + return (NULL); i = *cp++; } return (cp); @@ -167,33 +86,140 @@ ns_nskip(register const u_char *cp, register const u_char *bp) /* print a */ static const u_char * -ns_nprint(register const u_char *cp, register const u_char *bp) +blabel_print(const u_char *cp) +{ + int bitlen, slen, b; + const u_char *bitp, *lim; + char tc; + + if (!TTEST2(*cp, 1)) + return(NULL); + if ((bitlen = *cp) == 0) + bitlen = 256; + slen = (bitlen + 3) / 4; + lim = cp + 1 + slen; + + /* print the bit string as a hex string */ + printf("\\[x"); + for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++) { + TCHECK(*bitp); + printf("%02x", *bitp); + } + if (b > 4) { + TCHECK(*bitp); + tc = *bitp++; + printf("%02x", tc & (0xff << (8 - b))); + } else if (b > 0) { + TCHECK(*bitp); + tc = *bitp++; + printf("%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b))); + } + printf("/%d]", bitlen); + return lim; +trunc: + printf(".../%d]", bitlen); + return NULL; +} + +static int +labellen(const u_char *cp) { register u_int i; - register const u_char *rp; - register int compress; - i = *cp++; - rp = cp + i; - if ((i & INDIR_MASK) == INDIR_MASK) { - rp = cp + 1; - compress = 1; + if (!TTEST2(*cp, 1)) + return(-1); + i = *cp; + if ((i & INDIR_MASK) == EDNS0_MASK) { + int bitlen, elt; + + if ((elt = (i & ~INDIR_MASK)) != EDNS0_ELT_BITLABEL) + return(-1); + if (!TTEST2(*(cp + 1), 1)) + return(-1); + if ((bitlen = *(cp + 1)) == 0) + bitlen = 256; + return(((bitlen + 7) / 8) + 1); } else + return(i); +} + +static const u_char * +ns_nprint(register const u_char *cp, register const u_char *bp) +{ + register u_int i, l; + register const u_char *rp = NULL; + register int compress = 0; + int chars_processed; + int elt; + int data_size = snapend - bp; + + if ((l = labellen(cp)) == (u_int)-1) + return(NULL); + if (!TTEST2(*cp, 1)) + return(NULL); + chars_processed = 1; + if (((i = *cp++) & INDIR_MASK) != INDIR_MASK) { compress = 0; + rp = cp + l; + } + if (i != 0) while (i && cp < snapend) { if ((i & INDIR_MASK) == INDIR_MASK) { + if (!compress) { + rp = cp + 1; + compress = 1; + } + if (!TTEST2(*cp, 1)) + return(NULL); cp = bp + (((i << 8) | *cp) & 0x3fff); + if ((l = labellen(cp)) == (u_int)-1) + return(NULL); + if (!TTEST2(*cp, 1)) + return(NULL); i = *cp++; + chars_processed++; + + /* + * If we've looked at every character in + * the message, this pointer will make + * us look at some character again, + * which means we're looping. + */ + if (chars_processed >= data_size) { + printf(""); + return (NULL); + } continue; } - if (fn_printn(cp, i, snapend)) - break; - cp += i; + if ((i & INDIR_MASK) == EDNS0_MASK) { + elt = (i & ~INDIR_MASK); + switch(elt) { + case EDNS0_ELT_BITLABEL: + if (blabel_print(cp) == NULL) + return (NULL); + break; + default: + /* unknown ELT */ + printf("", elt); + return(NULL); + } + } else { + if (fn_printn(cp, l, snapend)) + return(NULL); + } + + cp += l; + chars_processed += l; putchar('.'); + if ((l = labellen(cp)) == (u_int)-1) + return(NULL); + if (!TTEST2(*cp, 1)) + return(NULL); i = *cp++; + chars_processed++; if (!compress) - rp += i + 1; + rp += l + 1; } else putchar('.'); @@ -202,143 +228,153 @@ ns_nprint(register const u_char *cp, register const u_char *bp) /* print a */ static const u_char * -ns_cprint(register const u_char *cp, register const u_char *bp) +ns_cprint(register const u_char *cp) { register u_int i; + 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[] = { - { T_A, "A" }, - { T_NS, "NS" }, - { T_MD, "MD" }, - { T_MF, "MF" }, - { T_CNAME, "CNAME" }, - { T_SOA, "SOA" }, - { T_MB, "MB" }, - { T_MG, "MG" }, - { T_MR, "MR" }, - { T_NULL, "NULL" }, - { T_WKS, "WKS" }, - { T_PTR, "PTR" }, - { T_HINFO, "HINFO" }, - { T_MINFO, "MINFO" }, - { T_MX, "MX" }, - { T_TXT, "TXT" }, - { T_RP, "RP" }, - { T_AFSDB, "AFSDB" }, - { T_X25, "X25" }, - { T_ISDN, "ISDN" }, - { T_RT, "RT" }, - { T_NSAP, "NSAP" }, +/* http://www.iana.org/assignments/dns-parameters */ +struct tok ns_type2str[] = { + { T_A, "A" }, /* RFC 1035 */ + { T_NS, "NS" }, /* RFC 1035 */ + { T_MD, "MD" }, /* RFC 1035 */ + { T_MF, "MF" }, /* RFC 1035 */ + { T_CNAME, "CNAME" }, /* RFC 1035 */ + { T_SOA, "SOA" }, /* RFC 1035 */ + { T_MB, "MB" }, /* RFC 1035 */ + { T_MG, "MG" }, /* RFC 1035 */ + { T_MR, "MR" }, /* RFC 1035 */ + { T_NULL, "NULL" }, /* RFC 1035 */ + { T_WKS, "WKS" }, /* RFC 1035 */ + { T_PTR, "PTR" }, /* RFC 1035 */ + { T_HINFO, "HINFO" }, /* RFC 1035 */ + { T_MINFO, "MINFO" }, /* RFC 1035 */ + { T_MX, "MX" }, /* RFC 1035 */ + { T_TXT, "TXT" }, /* RFC 1035 */ + { T_RP, "RP" }, /* RFC 1183 */ + { T_AFSDB, "AFSDB" }, /* RFC 1183 */ + { T_X25, "X25" }, /* RFC 1183 */ + { T_ISDN, "ISDN" }, /* RFC 1183 */ + { T_RT, "RT" }, /* RFC 1183 */ + { T_NSAP, "NSAP" }, /* RFC 1706 */ { T_NSAP_PTR, "NSAP_PTR" }, - { T_SIG, "SIG" }, - { T_KEY, "KEY" }, - { 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 " }, -#ifndef T_UINFO -#define T_UINFO 100 -#endif + { T_SIG, "SIG" }, /* RFC 2535 */ + { T_KEY, "KEY" }, /* RFC 2535 */ + { T_PX, "PX" }, /* RFC 2163 */ + { T_GPOS, "GPOS" }, /* RFC 1712 */ + { T_AAAA, "AAAA" }, /* RFC 1886 */ + { T_LOC, "LOC" }, /* RFC 1876 */ + { T_NXT, "NXT" }, /* RFC 2535 */ + { T_EID, "EID" }, /* Nimrod */ + { T_NIMLOC, "NIMLOC" }, /* Nimrod */ + { T_SRV, "SRV" }, /* RFC 2782 */ + { T_ATMA, "ATMA" }, /* ATM Forum */ + { T_NAPTR, "NAPTR" }, /* RFC 2168, RFC 2915 */ + { T_A6, "A6" }, /* RFC 2874 */ + { T_DNAME, "DNAME" }, /* RFC 2672 */ + { T_OPT, "OPT" }, /* RFC 2671 */ { T_UINFO, "UINFO" }, -#ifndef T_UID -#define T_UID 101 -#endif { T_UID, "UID" }, -#ifndef T_GID -#define T_GID 102 -#endif { T_GID, "GID" }, { T_UNSPEC, "UNSPEC" }, { T_UNSPECA, "UNSPECA" }, - { T_AXFR, "AXFR" }, - { T_MAILB, "MAILB" }, - { T_MAILA, "MAILA" }, + { T_TKEY, "TKEY" }, /* RFC 2930 */ + { T_TSIG, "TSIG" }, /* RFC 2845 */ + { T_IXFR, "IXFR" }, /* RFC 1995 */ + { T_AXFR, "AXFR" }, /* RFC 1035 */ + { T_MAILB, "MAILB" }, /* RFC 1035 */ + { T_MAILA, "MAILA" }, /* RFC 1035 */ { T_ANY, "ANY" }, { 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 } }; /* print a query */ -static void -ns_qprint(register const u_char *cp, register const u_char *bp) +static const u_char * +ns_qprint(register const u_char *cp, register const u_char *bp, int is_mdns) { register const u_char *np = cp; register u_int i; - cp = ns_nskip(cp, bp); + cp = ns_nskip(cp); - if (cp + 4 > snapend) - return; + 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)); - i = *cp++ << 8; - i |= *cp++; - if (i != C_IN) - printf(" %s", tok2str(class2str, "(Class %d)", i)); + i = EXTRACT_16BITS(cp); + cp += 2; + printf(" %s", tok2str(ns_type2str, "Type%d", i)); + i = EXTRACT_16BITS(cp); + cp += 2; + if (is_mdns && i == (C_IN|C_CACHE_FLUSH)) + printf(" (Cache flush)"); + else if (i != C_IN) + printf(" %s", tok2str(ns_class2str, "(Class %d)", i)); fputs("? ", stdout); - ns_nprint(np, bp); + cp = ns_nprint(np, bp); + return(cp ? cp + 4 : NULL); } /* print a reply */ static const u_char * -ns_rprint(register const u_char *cp, register const u_char *bp) +ns_rprint(register const u_char *cp, register const u_char *bp, int is_mdns) { - register u_int i; + register u_int class; register u_short typ, len; register const u_char *rp; if (vflag) { putchar(' '); - cp = ns_nprint(cp, bp); + if ((cp = ns_nprint(cp, bp)) == NULL) + return NULL; } else - cp = ns_nskip(cp, bp); + cp = ns_nskip(cp); - if (cp + 10 > snapend) + if (cp == NULL || !TTEST2(*cp, 10)) return (snapend); /* print the type/qtype and class (if it's not IN) */ - typ = *cp++ << 8; - typ |= *cp++; - i = *cp++ << 8; - i |= *cp++; - if (i != C_IN) - printf(" %s", tok2str(class2str, "(Class %d)", i)); + typ = EXTRACT_16BITS(cp); + cp += 2; + class = EXTRACT_16BITS(cp); + cp += 2; + if (is_mdns && class == (C_IN|C_CACHE_FLUSH)) + printf(" (Cache flush)"); + else if (class != C_IN && typ != T_OPT) + printf(" %s", tok2str(ns_class2str, "(Class %d)", class)); /* ignore ttl */ cp += 4; - len = *cp++ << 8; - len |= *cp++; + len = EXTRACT_16BITS(cp); + cp += 2; rp = cp + len; - printf(" %s", tok2str(type2str, "Type%d", typ)); - switch (typ) { + printf(" %s", tok2str(ns_type2str, "Type%d", typ)); + if (rp > snapend) + return(NULL); + switch (typ) { case T_A: + if (!TTEST2(*cp, sizeof(struct in_addr))) + return(NULL); printf(" %s", ipaddr_string(cp)); break; @@ -346,101 +382,241 @@ ns_rprint(register const u_char *cp, register const u_char *bp) case T_CNAME: case T_PTR: #ifdef T_DNAME - case T_DNAME: /*XXX not checked as there's no server support yet*/ + case T_DNAME: #endif putchar(' '); - (void)ns_nprint(cp, bp); + if (ns_nprint(cp, bp) == NULL) + return(NULL); break; + case T_SOA: + if (!vflag) + break; + putchar(' '); + if ((cp = ns_nprint(cp, bp)) == NULL) + return(NULL); + putchar(' '); + if ((cp = ns_nprint(cp, bp)) == NULL) + return(NULL); + if (!TTEST2(*cp, 5 * 4)) + return(NULL); + printf(" %u", EXTRACT_32BITS(cp)); + cp += 4; + printf(" %u", EXTRACT_32BITS(cp)); + cp += 4; + printf(" %u", EXTRACT_32BITS(cp)); + cp += 4; + printf(" %u", EXTRACT_32BITS(cp)); + cp += 4; + printf(" %u", EXTRACT_32BITS(cp)); + cp += 4; + break; case T_MX: putchar(' '); - (void)ns_nprint(cp + 2, bp); + if (!TTEST2(*cp, 2)) + return(NULL); + if (ns_nprint(cp + 2, bp) == NULL) + return(NULL); printf(" %d", EXTRACT_16BITS(cp)); break; case T_TXT: + while (cp < rp) { + printf(" \""); + cp = ns_cprint(cp); + if (cp == NULL) + return(NULL); + putchar('"'); + } + break; + + case T_SRV: putchar(' '); - (void)ns_cprint(cp, bp); + if (!TTEST2(*cp, 6)) + return(NULL); + if (ns_nprint(cp + 6, bp) == NULL) + return(NULL); + printf(":%d %d %d", EXTRACT_16BITS(cp + 4), + EXTRACT_16BITS(cp), EXTRACT_16BITS(cp + 2)); break; #ifdef INET6 case T_AAAA: + if (!TTEST2(*cp, sizeof(struct in6_addr))) + return(NULL); printf(" %s", ip6addr_string(cp)); break; - case T_A6: /*XXX not checked as there's no server support yet*/ + case T_A6: { struct in6_addr a; - int pbyte; - - pbyte = (*cp + 7) / 8; - memset(&a, 0, sizeof(a)); - memcpy(&a, cp + 1, pbyte); - printf(" %u %s ", *cp, ip6addr_string(&a)); - (void)ns_nprint(cp + 1 + pbyte, bp); + 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)); + } + if (pbit > 0) { + putchar(' '); + if (ns_nprint(cp + 1 + sizeof(a) - pbyte, bp) == NULL) + return(NULL); + } break; } #endif /*INET6*/ + case T_OPT: + printf(" UDPsize=%u", class); + break; + case T_UNSPECA: /* One long string */ - printf(" %.*s", len, cp); + if (!TTEST2(*cp, len)) + return(NULL); + if (fn_printn(cp, len, snapend)) + return(NULL); 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 */ } void -ns_print(register const u_char *bp, u_int length) +ns_print(register const u_char *bp, u_int length, int is_mdns) { register const HEADER *np; register int qdcount, ancount, nscount, arcount; register const u_char *cp; + u_int16_t b2; np = (const HEADER *)bp; + TCHECK(*np); /* get the byte-order right */ - qdcount = ntohs(np->qdcount); - ancount = ntohs(np->ancount); - nscount = ntohs(np->nscount); - arcount = ntohs(np->arcount); + qdcount = EXTRACT_16BITS(&np->qdcount); + ancount = EXTRACT_16BITS(&np->ancount); + nscount = EXTRACT_16BITS(&np->nscount); + arcount = EXTRACT_16BITS(&np->arcount); - if (np->qr) { + if (DNS_QR(np)) { /* this is a response */ - printf(" %d%s%s%s%s%s", - ntohs(np->id), - ns_ops[np->opcode], - ns_resp[np->rcode], - np->aa? "*" : "", - np->ra? "" : "-", - np->tc? "|" : ""); + printf(" %d%s%s%s%s%s%s", + EXTRACT_16BITS(&np->id), + ns_ops[DNS_OPCODE(np)], + ns_resp[DNS_RCODE(np)], + DNS_AA(np)? "*" : "", + DNS_RA(np)? "" : "-", + DNS_TC(np)? "|" : "", + DNS_AD(np)? "$" : ""); + if (qdcount != 1) printf(" [%dq]", qdcount); /* Print QUESTION section on -vv */ - if (vflag > 1) { - fputs(" q: ", stdout); - cp = ns_nprint((const u_char *)(np + 1), bp); - } else - cp = ns_nskip((const u_char *)(np + 1), bp); + cp = (const u_char *)(np + 1); + while (qdcount--) { + if (qdcount < EXTRACT_16BITS(&np->qdcount) - 1) + putchar(','); + if (vflag > 1) { + fputs(" q:", stdout); + if ((cp = ns_qprint(cp, bp, is_mdns)) == NULL) + goto trunc; + } else { + if ((cp = ns_nskip(cp)) == NULL) + goto trunc; + cp += 4; /* skip QTYPE and QCLASS */ + } + } printf(" %d/%d/%d", ancount, nscount, arcount); if (ancount--) { - cp = ns_rprint(cp + 4, bp); - while (ancount-- && cp < snapend) { + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) + goto trunc; + while (cp < snapend && ancount--) { putchar(','); - cp = ns_rprint(cp, bp); + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) + goto trunc; } } + if (ancount > 0) + goto trunc; + /* Print NS and AR sections on -vv */ + if (vflag > 1) { + if (cp < snapend && nscount--) { + fputs(" ns:", stdout); + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) + goto trunc; + while (cp < snapend && nscount--) { + putchar(','); + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) + goto trunc; + } + } + if (nscount > 0) + goto trunc; + if (cp < snapend && arcount--) { + fputs(" ar:", stdout); + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) + goto trunc; + while (cp < snapend && arcount--) { + putchar(','); + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) + goto trunc; + } + } + if (arcount > 0) + goto trunc; + } } else { /* this is a request */ - printf(" %d%s%s", - ntohs(np->id), - ns_ops[np->opcode], - np->rd? "+" : ""); + printf(" %d%s%s%s", EXTRACT_16BITS(&np->id), ns_ops[DNS_OPCODE(np)], + DNS_RD(np) ? "+" : "", + DNS_CD(np) ? "%" : ""); /* any weirdness? */ - if (*(((u_short *)np)+1) & htons(0x6ff)) - printf(" [b2&3=0x%x]", ntohs(*(((u_short *)np)+1))); + b2 = EXTRACT_16BITS(((u_short *)np)+1); + if (b2 & 0x6cf) + printf(" [b2&3=0x%x]", b2); - if (np->opcode == IQUERY) { + if (DNS_OPCODE(np) == IQUERY) { if (qdcount) printf(" [%dq]", qdcount); if (ancount != 1) @@ -457,7 +633,65 @@ ns_print(register const u_char *bp, u_int length) if (arcount) printf(" [%dau]", arcount); - ns_qprint((const u_char *)(np + 1), (const u_char *)np); + cp = (const u_char *)(np + 1); + if (qdcount--) { + cp = ns_qprint(cp, (const u_char *)np, is_mdns); + if (!cp) + goto trunc; + while (cp < snapend && qdcount--) { + cp = ns_qprint((const u_char *)cp, + (const u_char *)np, + is_mdns); + if (!cp) + goto trunc; + } + } + if (qdcount > 0) + goto trunc; + + /* Print remaining sections on -vv */ + if (vflag > 1) { + if (ancount--) { + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) + goto trunc; + while (cp < snapend && ancount--) { + putchar(','); + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) + goto trunc; + } + } + if (ancount > 0) + goto trunc; + if (cp < snapend && nscount--) { + fputs(" ns:", stdout); + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) + goto trunc; + while (nscount-- && cp < snapend) { + putchar(','); + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) + goto trunc; + } + } + if (nscount > 0) + goto trunc; + if (cp < snapend && arcount--) { + fputs(" ar:", stdout); + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) + goto trunc; + while (cp < snapend && arcount--) { + putchar(','); + if ((cp = ns_rprint(cp, bp, is_mdns)) == NULL) + goto trunc; + } + } + if (arcount > 0) + goto trunc; + } } printf(" (%d)", length); + return; + + trunc: + printf("[|domain]"); + return; } diff --git a/kame/kame/tcpdump/print-dvmrp.c b/kame/kame/tcpdump/print-dvmrp.c index aa250cbd7d..5e45d55197 100644 --- a/kame/kame/tcpdump/print-dvmrp.c +++ b/kame/kame/tcpdump/print-dvmrp.c @@ -20,28 +20,22 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-dvmrp.c,v 1.13 96/12/10 23:16:30 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-dvmrp.c,v 1.24.2.3 2003/11/19 09:41:28 guy Exp $ (LBL)"; #endif -#include -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include -#include -#include -#include -#include -#include -#include +#include #include #include #include -#include #include "interface.h" +#include "extract.h" #include "addrtoname.h" /* @@ -51,9 +45,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 @@ -70,13 +62,13 @@ static const char rcsid[] = #define DVMRP_NF_DISABLED 0x20 /* administratively disabled */ #define DVMRP_NF_QUERIER 0x40 /* I am the subnet's querier */ -static void print_probe(const u_char *, const u_char *, u_int); -static void print_report(const u_char *, const u_char *, u_int); -static void print_neighbors(const u_char *, const u_char *, u_int); -static void print_neighbors2(const u_char *, const u_char *, u_int); -static void print_prune(const u_char *, const u_char *, u_int); -static void print_graft(const u_char *, const u_char *, u_int); -static void print_graft_ack(const u_char *, const u_char *, u_int); +static int print_probe(const u_char *, const u_char *, u_int); +static int print_report(const u_char *, const u_char *, u_int); +static int print_neighbors(const u_char *, const u_char *, u_int); +static int print_neighbors2(const u_char *, const u_char *, u_int); +static int print_prune(const u_char *); +static int print_graft(const u_char *); +static int print_graft_ack(const u_char *); static u_int32_t target_level; @@ -90,26 +82,29 @@ dvmrp_print(register const u_char *bp, register u_int len) if (bp >= ep) return; + TCHECK(bp[1]); type = bp[1]; - bp += 8; - /* - * Skip IGMP header - */ + /* Skip IGMP header */ + bp += 8; len -= 8; switch (type) { case DVMRP_PROBE: printf(" Probe"); - if (vflag) - print_probe(bp, ep, len); + if (vflag) { + if (print_probe(bp, ep, len) < 0) + goto trunc; + } break; case DVMRP_REPORT: printf(" Report"); - if (vflag) - print_report(bp, ep, len); + if (vflag > 1) { + if (print_report(bp, ep, len) < 0) + goto trunc; + } break; case DVMRP_ASK_NEIGHBORS: @@ -118,7 +113,8 @@ dvmrp_print(register const u_char *bp, register u_int len) case DVMRP_NEIGHBORS: printf(" Neighbors(old)"); - print_neighbors(bp, ep, len); + if (print_neighbors(bp, ep, len) < 0) + goto trunc; break; case DVMRP_ASK_NEIGHBORS2: @@ -132,45 +128,57 @@ dvmrp_print(register const u_char *bp, register u_int len) * address field */ bp -= 4; + TCHECK2(bp[0], 4); target_level = (bp[0] << 24) | (bp[1] << 16) | (bp[2] << 8) | bp[3]; bp += 4; - print_neighbors2(bp, ep, len); + if (print_neighbors2(bp, ep, len) < 0) + goto trunc; break; case DVMRP_PRUNE: printf(" Prune"); - print_prune(bp, ep, len); + if (print_prune(bp) < 0) + goto trunc; break; case DVMRP_GRAFT: printf(" Graft"); - print_graft(bp, ep, len); + if (print_graft(bp) < 0) + goto trunc; break; case DVMRP_GRAFT_ACK: printf(" Graft-ACK"); - print_graft_ack(bp, ep, len); + if (print_graft_ack(bp) < 0) + goto trunc; break; default: printf(" [type %d]", type); break; } + return; + +trunc: + printf("[|dvmrp]"); + return; } -static void +static int print_report(register const u_char *bp, register const u_char *ep, register u_int len) { register u_int32_t mask, origin; - register int metric, i, width, done; + register int metric, done; + register u_int i, width; while (len > 0) { if (len < 3) { printf(" [|]"); - return; + return (0); } + TCHECK2(bp[0], 3); mask = (u_int32_t)0xff << 24 | bp[0] << 16 | bp[1] << 8 | bp[2]; width = 1; if (bp[0]) @@ -186,18 +194,21 @@ print_report(register const u_char *bp, register const u_char *ep, do { if (bp + width + 1 > ep) { printf(" [|]"); - return; + return (0); } if (len < width + 1) { printf("\n\t [Truncated Report]"); - return; + return (0); } origin = 0; - for (i = 0; i < width; ++i) + for (i = 0; i < width; ++i) { + TCHECK(*bp); origin = origin << 8 | *bp++; + } for ( ; i < 4; ++i) origin <<= 8; + TCHECK(*bp); metric = *bp++; done = metric & 0x80; metric &= 0x7f; @@ -206,72 +217,80 @@ print_report(register const u_char *bp, register const u_char *ep, len -= width + 1; } while (!done); } + return (0); +trunc: + return (-1); } -#define GET_ADDR(to) (memcpy((char *)to, (char *)bp, 4), bp += 4) - -static void +static int print_probe(register const u_char *bp, register const u_char *ep, register u_int len) { register u_int32_t genid; - u_char neighbor[4]; + TCHECK2(bp[0], 4); if ((len < 4) || ((bp + 4) > ep)) { /* { (ctags) */ printf(" [|}"); - return; + return (0); } 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 (0); while ((len > 0) && (bp < ep)) { - if ((len < 4) || ((bp + 4) > ep)) { - printf(" [|]"); - return; - } - GET_ADDR(neighbor); - len -= 4; - printf("\n\tneighbor %s", ipaddr_string(neighbor)); + TCHECK2(bp[0], 4); + printf("\n\tneighbor %s", ipaddr_string(bp)); + bp += 4; len -= 4; } + return (0); +trunc: + return (-1); } -static void +static int print_neighbors(register const u_char *bp, register const u_char *ep, register u_int len) { - u_char laddr[4], neighbor[4]; + const u_char *laddr; register u_char metric; register u_char thresh; register int ncount; while (len > 0 && bp < ep) { - if (len < 7 || (bp + 7) >= ep) { - printf(" [|]"); - return; - } - GET_ADDR(laddr); + TCHECK2(bp[0], 7); + laddr = bp; + bp += 4; metric = *bp++; thresh = *bp++; ncount = *bp++; len -= 7; - while (--ncount >= 0 && (len >= 4) && (bp + 4) < ep) { - GET_ADDR(neighbor); + while (--ncount >= 0) { + TCHECK2(bp[0], 4); printf(" [%s ->", ipaddr_string(laddr)); printf(" %s, (%d/%d)]", - ipaddr_string(neighbor), metric, thresh); + ipaddr_string(bp), metric, thresh); + bp += 4; len -= 4; } } + return (0); +trunc: + return (-1); } -static void +static int print_neighbors2(register const u_char *bp, register const u_char *ep, register u_int len) { - u_char laddr[4], neighbor[4]; + const u_char *laddr; register u_char metric, thresh, flags; register int ncount; @@ -280,20 +299,17 @@ print_neighbors2(register const u_char *bp, register const u_char *ep, (int)(target_level >> 8) & 0xff); while (len > 0 && bp < ep) { - if (len < 8 || (bp + 8) >= ep) { - printf(" [|]"); - return; - } - GET_ADDR(laddr); + TCHECK2(bp[0], 8); + laddr = bp; + bp += 4; metric = *bp++; thresh = *bp++; flags = *bp++; ncount = *bp++; len -= 8; while (--ncount >= 0 && (len >= 4) && (bp + 4) <= ep) { - GET_ADDR(neighbor); printf(" [%s -> ", ipaddr_string(laddr)); - printf("%s (%d/%d", ipaddr_string(neighbor), + printf("%s (%d/%d", ipaddr_string(bp), metric, thresh); if (flags & DVMRP_NF_TUNNEL) printf("/tunnel"); @@ -306,54 +322,48 @@ print_neighbors2(register const u_char *bp, register const u_char *ep, if (flags & DVMRP_NF_DOWN) printf("/down"); printf(")]"); + bp += 4; len -= 4; } if (ncount != -1) { printf(" [|]"); - return; + return (0); } } + return (0); +trunc: + return (-1); } -static void -print_prune(register const u_char *bp, register const u_char *ep, - register u_int len) +static int +print_prune(register const u_char *bp) { - union a { - u_char b[4]; - u_int32_t i; - } prune_timer; - - if (len < 12 || (bp + 12) > ep) { - printf(" [|]"); - return; - } + TCHECK2(bp[0], 12); printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4)); bp += 8; - GET_ADDR(prune_timer.b); - printf(" timer %d", (int)ntohl(prune_timer.i)); + (void)printf(" timer "); + relts_print(EXTRACT_32BITS(bp)); + return (0); +trunc: + return (-1); } -static void -print_graft(register const u_char *bp, register const u_char *ep, - register u_int len) +static int +print_graft(register const u_char *bp) { - - if (len < 8 || (bp + 8) > ep) { - printf(" [|]"); - return; - } + TCHECK2(bp[0], 8); printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4)); + return (0); +trunc: + return (-1); } -static void -print_graft_ack(register const u_char *bp, register const u_char *ep, - register u_int len) +static int +print_graft_ack(register const u_char *bp) { - - if (len < 8 || (bp + 8) > ep) { - printf(" [|]"); - return; - } + TCHECK2(bp[0], 8); printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4)); + return (0); +trunc: + return (-1); } diff --git a/kame/kame/tcpdump/print-egp.c b/kame/kame/tcpdump/print-egp.c index a621630abb..6cfaa30bce 100644 --- a/kame/kame/tcpdump/print-egp.c +++ b/kame/kame/tcpdump/print-egp.c @@ -19,35 +19,34 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-egp.c,v 1.23 96/11/05 13:30:35 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-egp.c,v 1.34.2.2 2003/11/16 08:51:18 guy Exp $ (LBL)"; #endif -#include -#include -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include -#include -#include +#include -#include #include #include "interface.h" #include "addrtoname.h" +#include "extract.h" + +#include "ip.h" struct egp_packet { - u_char egp_version; + u_int8_t egp_version; #define EGP_VERSION 2 - u_char egp_type; + u_int8_t egp_type; #define EGPT_ACQUIRE 3 #define EGPT_REACH 5 #define EGPT_POLL 2 #define EGPT_UPDATE 1 #define EGPT_ERROR 8 - u_char egp_code; + u_int8_t egp_code; #define EGPC_REQUEST 0 #define EGPC_CONFIRM 1 #define EGPC_REFUSE 2 @@ -55,7 +54,7 @@ struct egp_packet { #define EGPC_CEASEACK 4 #define EGPC_HELLO 0 #define EGPC_HEARDU 1 - u_char egp_status; + u_int8_t egp_status; #define EGPS_UNSPEC 0 #define EGPS_ACTIVE 1 #define EGPS_PASSIVE 2 @@ -68,13 +67,13 @@ struct egp_packet { #define EGPS_UP 1 #define EGPS_DOWN 2 #define EGPS_UNSOL 0x80 - u_short egp_checksum; - u_short egp_as; - u_short egp_sequence; + u_int16_t egp_checksum; + u_int16_t egp_as; + u_int16_t egp_sequence; union { - u_short egpu_hello; - u_char egpu_gws[2]; - u_short egpu_reason; + u_int16_t egpu_hello; + u_int8_t egpu_gws[2]; + u_int16_t egpu_reason; #define EGPR_UNSPEC 0 #define EGPR_BADHEAD 1 #define EGPR_BADDATA 2 @@ -88,14 +87,14 @@ struct egp_packet { #define egp_extgw egp_handg.egpu_gws[1] #define egp_reason egp_handg.egpu_reason union { - u_short egpu_poll; + u_int16_t egpu_poll; u_int32_t egpu_sourcenet; } egp_pands; #define egp_poll egp_pands.egpu_poll #define egp_sourcenet egp_pands.egpu_sourcenet }; -char *egp_acquire_codes[] = { +const char *egp_acquire_codes[] = { "request", "confirm", "refuse", @@ -103,7 +102,7 @@ char *egp_acquire_codes[] = { "cease_ack" }; -char *egp_acquire_status[] = { +const char *egp_acquire_status[] = { "unspecified", "active_mode", "passive_mode", @@ -114,18 +113,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", @@ -136,15 +135,15 @@ char *egp_reasons[] = { }; static void -egpnrprint(register const struct egp_packet *egp, register u_int length) +egpnrprint(register const struct egp_packet *egp) { - register const u_char *cp; + register const u_int8_t *cp; u_int32_t addr; register u_int32_t net; register u_int netlen; int gateways, distances, networks; int t_gateways; - char *comma; + const char *comma; addr = egp->egp_sourcenet; if (IN_CLASSA(addr)) { @@ -160,7 +159,7 @@ egpnrprint(register const struct egp_packet *egp, register u_int length) net = 0; netlen = 0; } - cp = (u_char *)(egp + 1); + cp = (u_int8_t *)(egp + 1); t_gateways = egp->egp_intgw + egp->egp_extgw; for (gateways = 0; gateways < t_gateways; ++gateways) { @@ -215,26 +214,25 @@ egpnrprint(register const struct egp_packet *egp, register u_int length) } void -egp_print(register const u_char *bp, register u_int length, - register const u_char *bp2) +egp_print(register const u_int8_t *bp) { register const struct egp_packet *egp; - register const struct ip *ip; register int status; register int code; register int type; egp = (struct egp_packet *)bp; - ip = (struct ip *)bp2; - (void)printf("%s > %s: egp: ", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); + if (!TTEST(*egp)) { + printf("[|egp]"); + return; + } + (void)printf("egp: "); if (egp->egp_version != EGP_VERSION) { printf("[version %d]", egp->egp_version); return; } - printf("as:%d seq:%d", ntohs(egp->egp_as), ntohs(egp->egp_sequence)); + printf("as:%d seq:%d", EXTRACT_16BITS(&egp->egp_as), EXTRACT_16BITS(&egp->egp_sequence)); type = egp->egp_type; code = egp->egp_code; @@ -259,8 +257,8 @@ egp_print(register const u_char *bp, register u_int length, break; } printf(" hello:%d poll:%d", - ntohs(egp->egp_hello), - ntohs(egp->egp_poll)); + EXTRACT_16BITS(&egp->egp_hello), + EXTRACT_16BITS(&egp->egp_poll)); break; case EGPC_REFUSE: @@ -331,7 +329,7 @@ egp_print(register const u_char *bp, register u_int length, egp->egp_intgw, egp->egp_extgw); if (vflag) - egpnrprint(egp, length); + egpnrprint(egp); break; case EGPT_ERROR: @@ -341,10 +339,10 @@ egp_print(register const u_char *bp, register u_int length, else printf(" [status %d]", status); - if (ntohs(egp->egp_reason) <= EGPR_UVERSION) - printf(" %s", egp_reasons[ntohs(egp->egp_reason)]); + if (EXTRACT_16BITS(&egp->egp_reason) <= EGPR_UVERSION) + printf(" %s", egp_reasons[EXTRACT_16BITS(&egp->egp_reason)]); else - printf(" [reason %d]", ntohs(egp->egp_reason)); + printf(" [reason %d]", EXTRACT_16BITS(&egp->egp_reason)); break; default: diff --git a/kame/kame/tcpdump/print-enc.c b/kame/kame/tcpdump/print-enc.c new file mode 100644 index 0000000000..c7196e7d22 --- /dev/null +++ b/kame/kame/tcpdump/print-enc.c @@ -0,0 +1,78 @@ +/* $OpenBSD: print-enc.c,v 1.7 2002/02/19 19:39:40 millert Exp $ */ + +/* + * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-enc.c,v 1.1.2.2 2003/11/16 08:51:19 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include + +#include "interface.h" +#include "addrtoname.h" + +#include "enc.h" + +#define ENC_PRINT_TYPE(wh, xf, nam) \ + if ((wh) & (xf)) { \ + printf("%s%s", nam, (wh) == (xf) ? "): " : ","); \ + (wh) &= ~(xf); \ + } + +u_int +enc_if_print(const struct pcap_pkthdr *h, register const u_char *p) +{ + register u_int length = h->len; + register u_int caplen = h->caplen; + int flags; + const struct enchdr *hdr; + + if (caplen < ENC_HDRLEN) { + printf("[|enc]"); + goto out; + } + + hdr = (struct enchdr *)p; + flags = hdr->flags; + if (flags == 0) + printf("(unprotected): "); + else + printf("("); + ENC_PRINT_TYPE(flags, M_AUTH, "authentic"); + ENC_PRINT_TYPE(flags, M_CONF, "confidential"); + /* ENC_PRINT_TYPE(flags, M_TUNNEL, "tunnel"); */ + printf("SPI 0x%08x: ", (u_int32_t)ntohl(hdr->spi)); + + length -= ENC_HDRLEN; + /* XXX - use the address family */ + ip_print(p + ENC_HDRLEN, length); + +out: + return (ENC_HDRLEN); +} diff --git a/kame/kame/tcpdump/print-esp.c b/kame/kame/tcpdump/print-esp.c index 1eb5294011..0ca0cfa649 100644 --- a/kame/kame/tcpdump/print-esp.c +++ b/kame/kame/tcpdump/print-esp.c @@ -1,5 +1,7 @@ +/* $NetBSD: print-ah.c,v 1.4 1996/05/20 00:41:16 fvdl Exp $ */ + /* - * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994 + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -20,290 +22,489 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) /master/usr.sbin/tcpdump/tcpdump/print-icmp.c,v 2.1 1995/02/03 18:14:42 polk Exp (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-esp.c,v 1.44.2.4 2003/11/19 05:36:40 guy Exp $ (LBL)"; #endif -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef CRYPTO -#include -#include -#ifdef HAVE_RC5_H -#include +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#ifdef HAVE_CAST_H -#include + +#include + +#include + +#include + +#ifdef HAVE_LIBCRYPTO +#ifdef HAVE_OPENSSL_EVP_H +#include #endif #endif #include +#include "ip.h" +#include "esp.h" #ifdef INET6 -#include +#include "ip6.h" +#endif + +#if defined(__MINGW32__) || defined(__WATCOMC__) +extern char *strsep(char **stringp, const char *delim); /* Missing/strsep.c */ #endif -#include #include "interface.h" #include "addrtoname.h" +#include "extract.h" + +#ifndef HAVE_SOCKADDR_STORAGE +#ifdef INET6 +struct sockaddr_storage { + union { + struct sockaddr_in sin; + struct sockaddr_in6 sin6; + } un; +}; +#else +#define sockaddr_storage sockaddr +#endif +#endif /* HAVE_SOCKADDR_STORAGE */ + +#ifdef HAVE_LIBCRYPTO +struct sa_list { + struct sa_list *next; + struct sockaddr_storage daddr; + u_int32_t spi; + const EVP_CIPHER *evp; + int ivlen; + int authlen; + char secret[256]; /* is that big enough for all secrets? */ + int secretlen; +}; + +static struct sa_list *sa_list_head = NULL; +static struct sa_list *sa_default = NULL; + +static void esp_print_addsa(struct sa_list *sa, int sa_def) +{ + /* copy the "sa" */ + + struct sa_list *nsa; + + nsa = (struct sa_list *)malloc(sizeof(struct sa_list)); + if (nsa == NULL) + error("ran out of memory to allocate sa structure"); + + *nsa = *sa; + + if (sa_def) + sa_default = nsa; + + nsa->next = sa_list_head; + sa_list_head = nsa; +} + + +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; +} + +/* + * decode the form: SPINUM@IP ALGONAME:0xsecret + * + * special form: file /name + * causes us to go read from this file instead. + * + */ +static void esp_print_decode_onesecret(char *line) +{ + struct sa_list sa1; + int sa_def; + + char *spikey; + char *decode; + + spikey = strsep(&line, " \t"); + sa_def = 0; + memset(&sa1, 0, sizeof(struct sa_list)); + + /* if there is only one token, then it is an algo:key token */ + if (line == NULL) { + decode = spikey; + spikey = NULL; + /* memset(&sa1.daddr, 0, sizeof(sa1.daddr)); */ + /* sa1.spi = 0; */ + sa_def = 1; + } else + decode = line; + + if (spikey && strcasecmp(spikey, "file") == 0) { + /* open file and read it */ + FILE *secretfile; + char fileline[1024]; + char *nl; + + secretfile = fopen(line, FOPEN_READ_TXT); + if (secretfile == NULL) { + perror(line); + exit(3); + } + + while (fgets(fileline, sizeof(fileline)-1, secretfile) != NULL) { + /* remove newline from the line */ + nl = strchr(fileline, '\n'); + if (nl) + *nl = '\0'; + if (fileline[0] == '#') continue; + if (fileline[0] == '\0') continue; + + esp_print_decode_onesecret(fileline); + } + fclose(secretfile); + + return; + } + + if (spikey) { + char *spistr, *foo; + u_int32_t spino; + struct sockaddr_in *sin; +#ifdef INET6 + struct sockaddr_in6 *sin6; +#endif + + spistr = strsep(&spikey, "@"); + + spino = strtoul(spistr, &foo, 0); + if (spistr == foo || !spikey) { + printf("print_esp: failed to decode spi# %s\n", foo); + return; + } + + sa1.spi = spino; + + sin = (struct sockaddr_in *)&sa1.daddr; +#ifdef INET6 + sin6 = (struct sockaddr_in6 *)&sa1.daddr; + if (inet_pton(AF_INET6, spikey, &sin6->sin6_addr) == 1) { +#ifdef HAVE_SOCKADDR_SA_LEN + sin6->sin6_len = sizeof(struct sockaddr_in6); +#endif + sin6->sin6_family = AF_INET6; + } else +#endif + if (inet_pton(AF_INET, spikey, &sin->sin_addr) == 1) { +#ifdef HAVE_SOCKADDR_SA_LEN + sin->sin_len = sizeof(struct sockaddr_in); +#endif + sin->sin_family = AF_INET; + } else { + printf("print_esp: can not decode IP# %s\n", spikey); + return; + } + } + + if (decode) { + char *colon, *p; + char espsecret_key[256]; + int len; + size_t i; + const EVP_CIPHER *evp; + int ivlen = 8; + int authlen = 0; + + /* skip any blank spaces */ + while (isspace((unsigned char)*decode)) + decode++; + + colon = strchr(decode, ':'); + if (colon == NULL) { + printf("failed to decode espsecret: %s\n", decode); + return; + } + *colon = '\0'; + + len = colon - decode; + if (strlen(decode) > strlen("-hmac96") && + !strcmp(decode + strlen(decode) - strlen("-hmac96"), + "-hmac96")) { + p = strstr(decode, "-hmac96"); + *p = '\0'; + authlen = 12; + } + if (strlen(decode) > strlen("-cbc") && + !strcmp(decode + strlen(decode) - strlen("-cbc"), "-cbc")) { + p = strstr(decode, "-cbc"); + *p = '\0'; + } + evp = EVP_get_cipherbyname(decode); + if (!evp) { + printf("failed to find cipher algo %s\n", decode); + sa1.evp = NULL; + sa1.authlen = 0; + sa1.ivlen = 0; + return; + } + + sa1.evp = evp; + sa1.authlen = authlen; + sa1.ivlen = ivlen; + + colon++; + if (colon[0] == '0' && colon[1] == 'x') { + /* decode some hex! */ + colon += 2; + len = strlen(colon) / 2; + + if (len > 256) { + printf("secret is too big: %d\n", len); + return; + } + + i = 0; + while (colon[0] != '\0' && colon[1]!='\0') { + espsecret_key[i] = hex2byte(colon); + colon += 2; + i++; + } + + memcpy(sa1.secret, espsecret_key, i); + sa1.secretlen = i; + } else { + i = strlen(colon); + + if (i < sizeof(sa1.secret)) { + memcpy(sa1.secret, colon, i); + sa1.secretlen = i; + } else { + memcpy(sa1.secret, colon, sizeof(sa1.secret)); + sa1.secretlen = sizeof(sa1.secret); + } + } + } + + esp_print_addsa(&sa1, sa_def); +} + +static void esp_print_decodesecret(void) +{ + char *line; + char *p; + + p = espsecret; + + while (espsecret && espsecret[0] != '\0') { + /* pick out the first line or first thing until a comma */ + if ((line = strsep(&espsecret, "\n,")) == NULL) { + line = espsecret; + espsecret = NULL; + } + + esp_print_decode_onesecret(line); + } +} + +static void esp_init(void) +{ + + OpenSSL_add_all_algorithms(); + EVP_add_cipher_alias(SN_des_ede3_cbc, "3des"); +} +#endif int -esp_print(register const u_char *bp, register const u_char *bp2, int *nhdr) +esp_print(const u_char *bp, const u_char *bp2 +#ifndef HAVE_LIBCRYPTO + _U_ +#endif + , + int *nhdr +#ifndef HAVE_LIBCRYPTO + _U_ +#endif + , + int *padlen +#ifndef HAVE_LIBCRYPTO + _U_ +#endif + ) { - register const struct esp *esp; + register const struct newesp *esp; register const u_char *ep; - u_int32_t spi; - enum { NONE, DESCBC, BLOWFISH, RC5, CAST128, DES3CBC } algo = NONE; - struct ip *ip = NULL; +#ifdef HAVE_LIBCRYPTO + struct ip *ip; + struct sa_list *sa = NULL; + int espsecret_keylen; #ifdef INET6 struct ip6_hdr *ip6 = NULL; #endif int advance; int len; - char *secret = NULL; + char *secret; int ivlen = 0; u_char *ivoff; + const u_char *p; + EVP_CIPHER_CTX ctx; + int blocksz; + static int initialized = 0; +#endif + + esp = (struct newesp *)bp; + +#ifdef HAVE_LIBCRYPTO + secret = NULL; + advance = 0; + + if (!initialized) { + esp_init(); + initialized = 1; + } +#endif - esp = (struct esp *)bp; - spi = (u_int32_t)ntohl(esp->esp_spi); +#if 0 + /* keep secret out of a register */ + p = (u_char *)&secret; +#endif - /* 'ep' points to the end of avaible data. */ + /* 'ep' points to the end of available data. */ ep = snapend; - if ((u_char *)(esp + 1) >= ep - sizeof(struct esp)) { + if ((u_char *)(esp + 1) >= ep) { fputs("[|ESP]", stdout); goto fail; } - printf("ESP(spi=%u", spi); - if (Rflag) - printf(",seq=0x%x", (u_int32_t)ntohl(*(u_int32_t *)(esp + 1))); + printf("ESP(spi=0x%08x", EXTRACT_32BITS(&esp->esp_spi)); + printf(",seq=0x%x", EXTRACT_32BITS(&esp->esp_seq)); printf(")"); - /* if we don't have decryption key, we can't decrypt this packet. */ - if (!espsecret) - goto fail; +#ifndef HAVE_LIBCRYPTO + goto fail; +#else + /* initiailize SAs */ + if (sa_list_head == NULL) { + 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; + esp_print_decodesecret(); } + if (sa_list_head == NULL) + goto fail; + ip = (struct ip *)bp2; - switch (ip->ip_v) { + switch (IP_V(ip)) { #ifdef INET6 case 6: ip6 = (struct ip6_hdr *)bp2; - ip = NULL; /* we do not attempt to decrypt jumbograms */ - if (!ntohs(ip6->ip6_plen)) + if (!EXTRACT_16BITS(&ip6->ip6_plen)) goto fail; /* if we can't get nexthdr, we do not need to decrypt it */ - len = sizeof(struct ip6_hdr) + ntohs(ip6->ip6_plen); + len = sizeof(struct ip6_hdr) + EXTRACT_16BITS(&ip6->ip6_plen); + + /* see if we can find the SA, and if so, decode it */ + for (sa = sa_list_head; sa != NULL; sa = sa->next) { + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sa->daddr; + if (sa->spi == ntohl(esp->esp_spi) && + sin6->sin6_family == AF_INET6 && + memcmp(&sin6->sin6_addr, &ip6->ip6_dst, + sizeof(struct in6_addr)) == 0) { + break; + } + } break; #endif /*INET6*/ case 4: -#ifdef INET6 - ip6 = NULL; -#endif - len = ntohs(ip->ip_len); + /* nexthdr & padding are in the last fragment */ + if (EXTRACT_16BITS(&ip->ip_off) & IP_MF) + goto fail; + len = EXTRACT_16BITS(&ip->ip_len); + + /* see if we can find the SA, and if so, decode it */ + for (sa = sa_list_head; sa != NULL; sa = sa->next) { + struct sockaddr_in *sin = (struct sockaddr_in *)&sa->daddr; + if (sa->spi == ntohl(esp->esp_spi) && + sin->sin_family == AF_INET && + sin->sin_addr.s_addr == ip->ip_dst.s_addr) { + break; + } + } break; default: goto fail; } - /* if we can't get nexthdr, we do not need to decrypt it */ - if (ep - bp2 < len) - goto fail; - - if (Rflag) - ivoff = (u_char *)(esp + 1) + sizeof(u_int32_t); - else - ivoff = (u_char *)(esp + 1); - - switch (algo) { - case DESCBC: -#ifdef CRYPTO - { - u_char iv[8]; - des_key_schedule schedule; - u_char *p; - - switch (ivlen) { - case 4: - memcpy(iv, ivoff, 4); - memcpy(&iv[4], ivoff, 4); - p = &iv[4]; - *p++ ^= 0xff; - *p++ ^= 0xff; - *p++ ^= 0xff; - *p++ ^= 0xff; - break; - case 8: - memcpy(iv, ivoff, 8); - break; - default: - goto fail; - } - - des_check_key = 0; - des_set_key((des_cblock *)secret, schedule); - - p = ivoff + ivlen; - des_cbc_encrypt((des_cblock *)p, (des_cblock *)p, - (long)(ep - p), schedule, (des_cblock *)iv, - DES_DECRYPT); - advance = ivoff - (u_char *)esp + ivlen; - break; - } -#else + /* if we didn't find the specific one, then look for + * an unspecified one. + */ + if (sa == NULL) + sa = sa_default; + + /* if not found fail */ + if (sa == NULL) goto fail; -#endif /*CRYPTO*/ - - case BLOWFISH: -#ifdef CRYPTO - { - BF_KEY schedule; - u_char *p; - BF_set_key(&schedule, strlen(secret), secret); - - p = ivoff + ivlen; - BF_cbc_encrypt(p, p, (long)(ep - p), &schedule, ivoff, - BF_DECRYPT); - advance = ivoff - (u_char *)esp + ivlen; - break; - } -#else + /* if we can't get nexthdr, we do not need to decrypt it */ + if (ep - bp2 < len) goto fail; -#endif /*CRYPTO*/ - - case RC5: -#if defined(CRYPTO) && defined(HAVE_RC5_H) - { - RC5_32_KEY schedule; - u_char *p; - - RC5_32_set_key(&schedule, strlen(secret), secret, - RC5_16_ROUNDS); + if (ep - bp2 > len) { + /* FCS included at end of frame (NetBSD 1.6 or later) */ + ep = bp2 + len; + } - p = ivoff + ivlen; - RC5_32_cbc_encrypt(p, p, (long)(ep - p), &schedule, ivoff, - RC5_DECRYPT); - advance = ivoff - (u_char *)esp + ivlen; - break; - } -#else - goto fail; -#endif /*CRYPTO*/ + ivoff = (u_char *)(esp + 1) + 0; + ivlen = sa->ivlen; + secret = sa->secret; + espsecret_keylen = sa->secretlen; - case CAST128: -#if defined(CRYPTO) && defined(HAVE_CAST_H) && !defined(HAVE_BUGGY_CAST128) - { - CAST_KEY schedule; - u_char *p; + if (sa->evp) { + memset(&ctx, 0, sizeof(ctx)); + if (EVP_CipherInit(&ctx, sa->evp, secret, NULL, 0) < 0) + printf("espkey init failed"); - CAST_set_key(&schedule, strlen(secret), secret); + blocksz = EVP_CIPHER_CTX_block_size(&ctx); - p = ivoff + ivlen; - CAST_cbc_encrypt(p, p, (long)(ep - p), &schedule, ivoff, - CAST_DECRYPT); + p = ivoff; + EVP_CipherInit(&ctx, NULL, NULL, p, 0); + EVP_Cipher(&ctx, p + ivlen, p + ivlen, ep - (p + ivlen)); advance = ivoff - (u_char *)esp + ivlen; - break; - } -#else - goto fail; -#endif /*CRYPTO*/ - - case DES3CBC: -#if defined(CRYPTO) - { - des_key_schedule s1, s2, s3; - u_char *p; - - des_check_key = 0; - des_set_key((des_cblock *)secret, s1); - des_set_key((des_cblock *)(secret + 8), s2); - des_set_key((des_cblock *)(secret + 16), s3); - - p = ivoff + ivlen; - des_ede3_cbc_encrypt((des_cblock *)p, (des_cblock *)p, - (long)(ep - p), s1, s2, s3, (des_cblock *)ivoff, DES_DECRYPT); - advance = ivoff - (u_char *)esp + ivlen; - break; - } -#else - goto fail; -#endif /*CRYPTO*/ - - case NONE: - default: - if (Rflag) - advance = sizeof(struct esp) + sizeof(u_int32_t); - else - advance = sizeof(struct esp); - break; - } + } else + advance = sizeof(struct newesp); + ep = ep - sa->authlen; /* sanity check for pad length */ if (ep - bp < *(ep - 2)) goto fail; + if (padlen) + *padlen = *(ep - 2) + 2; + if (nhdr) *nhdr = *(ep - 1); printf(": "); return advance; +#endif fail: - if (nhdr) - *nhdr = -1; - return 65536; + return -1; } diff --git a/kame/kame/tcpdump/print-ether.c b/kame/kame/tcpdump/print-ether.c index 4ce2ad3e71..20d7d81d99 100644 --- a/kame/kame/tcpdump/print-ether.c +++ b/kame/kame/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 @@ -19,130 +19,147 @@ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-ether.c,v 1.44 97/05/26 17:18:13 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.82.2.3 2003/12/29 22:42:21 hannes Exp $ (LBL)"; #endif -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include -#ifdef INET6 -#include -#endif - #include "interface.h" #include "addrtoname.h" #include "ethertype.h" -const u_char *packetp; +#include "ether.h" + const u_char *snapend; +const struct tok ethertype_values[] = { + { ETHERTYPE_IP, "IPv4" }, + { ETHERTYPE_MPLS, "MPLS unicast" }, + { ETHERTYPE_MPLS_MULTI, "MPLS multicast" }, + { ETHERTYPE_IPV6, "IPv6" }, + { ETHERTYPE_8021Q, "802.1Q" }, + { ETHERTYPE_VMAN, "VMAN" }, + { ETHERTYPE_PUP, "PUP" }, + { ETHERTYPE_ARP, "ARP"}, + { ETHERTYPE_REVARP , "Reverse ARP"}, + { ETHERTYPE_NS, "NS" }, + { ETHERTYPE_SPRITE, "Sprite" }, + { ETHERTYPE_TRAIL, "Trail" }, + { ETHERTYPE_MOPDL, "MOP DL" }, + { ETHERTYPE_MOPRC, "MOP RC" }, + { ETHERTYPE_DN, "DN" }, + { ETHERTYPE_LAT, "LAT" }, + { ETHERTYPE_SCA, "SCA" }, + { ETHERTYPE_LANBRIDGE, "Lanbridge" }, + { ETHERTYPE_DECDNS, "DEC DNS" }, + { ETHERTYPE_DECDTS, "DEC DTS" }, + { ETHERTYPE_VEXP, "VEXP" }, + { ETHERTYPE_VPROD, "VPROD" }, + { ETHERTYPE_ATALK, "Appletalk" }, + { ETHERTYPE_AARP, "Appletalk ARP" }, + { ETHERTYPE_IPX, "IPX" }, + { ETHERTYPE_PPP, "PPP" }, + { ETHERTYPE_PPPOED, "PPPoE D" }, + { ETHERTYPE_PPPOES, "PPPoE S" }, + { ETHERTYPE_LOOPBACK, "Loopback" }, + { 0, NULL} +}; + static inline void -ether_print(register const u_char *bp, u_int length) +ether_hdr_print(register const u_char *bp, u_int length) { register const struct ether_header *ep; - ep = (const struct ether_header *)bp; - if (qflag) - (void)printf("%s %s %d: ", - etheraddr_string(ESRC(ep)), - etheraddr_string(EDST(ep)), - length); - else - (void)printf("%s %s %s %d: ", - etheraddr_string(ESRC(ep)), - etheraddr_string(EDST(ep)), - etherproto_string(ep->ether_type), - length); + + (void)printf("%s > %s", + etheraddr_string(ESRC(ep)), + etheraddr_string(EDST(ep))); + + if (!qflag) { + if (ntohs(ep->ether_type) <= ETHERMTU) + (void)printf(", 802.3"); + else + (void)printf(", ethertype %s (0x%04x)", + tok2str(ethertype_values,"Unknown", ntohs(ep->ether_type)), + ntohs(ep->ether_type)); + } else { + if (ntohs(ep->ether_type) <= ETHERMTU) + (void)printf(", 802.3"); + else + (void)printf(", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", ntohs(ep->ether_type))); + } + + (void)printf(", length %u: ", 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 -ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) +ether_print(const u_char *p, u_int length, u_int caplen) { - u_int caplen = h->caplen; - u_int length = h->len; struct ether_header *ep; u_short ether_type; - extern u_short extracted_ethertype; + u_short extracted_ether_type; - ts_print(&h->ts); - - if (caplen < sizeof(struct ether_header)) { + if (caplen < ETHER_HDRLEN) { printf("[|ether]"); - goto out; + return; } if (eflag) - ether_print(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; + ether_hdr_print(p, length); - length -= sizeof(struct ether_header); - caplen -= sizeof(struct ether_header); + length -= ETHER_HDRLEN; + caplen -= ETHER_HDRLEN; ep = (struct ether_header *)p; - p += sizeof(struct ether_header); + p += ETHER_HDRLEN; ether_type = ntohs(ep->ether_type); /* * Is it (gag) an 802.3 encapsulation? */ - extracted_ethertype = 0; + extracted_ether_type = 0; if (ether_type <= ETHERMTU) { /* Try to print the LLC-layer header & higher layers */ - if (llc_print(p, length, caplen, ESRC(ep), EDST(ep)) == 0) { + if (llc_print(p, length, caplen, ESRC(ep), EDST(ep), + &extracted_ether_type) == 0) { /* ether_type not known, print raw packet */ if (!eflag) - ether_print((u_char *)ep, length); - if (extracted_ethertype) { - printf("(LLC %s) ", - etherproto_string(htons(extracted_ethertype))); - } + ether_hdr_print((u_char *)ep, length + ETHER_HDRLEN); + if (!xflag && !qflag) default_print(p, caplen); } - } else if (ether_encap_print(ether_type, p, length, caplen) == 0) { + } else if (ether_encap_print(ether_type, p, length, caplen, + &extracted_ether_type) == 0) { /* ether_type not known, print raw packet */ if (!eflag) - ether_print((u_char *)ep, length + sizeof(*ep)); + ether_hdr_print((u_char *)ep, length + ETHER_HDRLEN); + if (!xflag && !qflag) default_print(p, caplen); - } - if (xflag) - default_print(p, caplen); - out: - putchar('\n'); + } +} + +/* + * This is the top level routine of the printer. 'p' points + * to the ether header of the packet, 'h->ts' is the timestamp, + * 'h->length' is the length of the packet off the wire, and 'h->caplen' + * is the number of bytes actually captured. + */ +u_int +ether_if_print(const struct pcap_pkthdr *h, const u_char *p) +{ + ether_print(p, h->len, h->caplen); + + return (ETHER_HDRLEN); } /* @@ -151,19 +168,20 @@ ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) * * Returns non-zero if it can do so, zero if the ethertype is unknown. * - * Stuffs the ether type into a global for the benefit of lower layers - * that might want to know what it is. + * The Ethernet type code is passed through a pointer; if it was + * ETHERTYPE_8021Q, it gets updated to be the Ethernet type of + * the 802.1Q payload, for the benefit of lower layers that might + * want to know what it is. */ -u_short extracted_ethertype; - int -ether_encap_print(u_short ethertype, const u_char *p, - u_int length, u_int caplen) +ether_encap_print(u_short ether_type, const u_char *p, + u_int length, u_int caplen, u_short *extracted_ether_type) { - extracted_ethertype = ethertype; + recurse: + *extracted_ether_type = ether_type; - switch (ethertype) { + switch (ether_type) { case ETHERTYPE_IP: ip_print(p, length); @@ -194,6 +212,62 @@ ether_encap_print(u_short ethertype, const u_char *p, aarp_print(p, length); return (1); + case ETHERTYPE_IPX: + printf("(NOV-ETHII) "); + ipx_print(p, length); + return (1); + + case ETHERTYPE_8021Q: + if (eflag) + printf("vlan %u, p %u%s, ", + ntohs(*(u_int16_t *)p) & 0xfff, + ntohs(*(u_int16_t *)p) >> 13, + (ntohs(*(u_int16_t *)p) & 0x1000) ? ", CFI" : ""); + + ether_type = ntohs(*(u_int16_t *)(p + 2)); + p += 4; + length -= 4; + caplen -= 4; + + if (ether_type > ETHERMTU) { + if (eflag) + printf("ethertype %s, ", + tok2str(ethertype_values,"0x%04x", ether_type)); + goto recurse; + } + + *extracted_ether_type = 0; + + if (llc_print(p, length, caplen, p - 18, p - 12, + extracted_ether_type) == 0) { + ether_hdr_print(p - 18, length + 4); + } + + if (!xflag && !qflag) + default_print(p - 18, caplen + 4); + + return (1); + + case ETHERTYPE_PPPOED: + case ETHERTYPE_PPPOES: + pppoe_print(p, length); + return (1); + + case ETHERTYPE_PPP: + if (length) { + printf(": "); + ppp_print(p, length); + } + return (1); + + case ETHERTYPE_LOOPBACK: + return (0); + + 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/kame/kame/tcpdump/print-fddi.c b/kame/kame/tcpdump/print-fddi.c index 3c1813aad1..cf6c1ccfc9 100644 --- a/kame/kame/tcpdump/print-fddi.c +++ b/kame/kame/tcpdump/print-fddi.c @@ -20,30 +20,16 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-fddi.c,v 1.36 97/05/26 17:13:35 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-fddi.c,v 1.61.2.2 2003/11/16 08:51:20 guy Exp $ (LBL)"; #endif -#ifdef HAVE_FDDI -#include -#include -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include -#include -#include -#include -#include +#include -#include -#include #include #include #include @@ -52,12 +38,13 @@ struct rtentry; #include "addrtoname.h" #include "ethertype.h" +#include "ether.h" #include "fddi.h" /* * Some FDDI interfaces use bit-swapped addresses. */ -#if defined(ultrix) || defined(__alpha) || defined(__bsdi) +#if defined(ultrix) || defined(__alpha) || defined(__bsdi) || defined(__NetBSD__) || defined(__linux__) int fddi_bitswap = 0; #else int fddi_bitswap = 1; @@ -93,8 +80,6 @@ int fddi_bitswap = 1; * - vj */ -#define FDDI_HDRLEN (sizeof(struct fddi_header)) - static u_char fddi_bit_swap[] = { 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, @@ -217,8 +202,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); } } @@ -226,10 +211,10 @@ extract_fddi_addrs(const struct fddi_header *fddip, char *fsrc, char *fdst) * Print the FDDI MAC header */ static inline void -fddi_print(register const struct fddi_header *fddip, register u_int length, +fddi_hdr_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); @@ -248,53 +233,30 @@ fddi_print(register const struct fddi_header *fddip, register u_int length, } static inline void -fddi_smt_print(const u_char *p, u_int length) +fddi_smt_print(const u_char *p _U_, u_int length _U_) { printf(""); } -/* - * This is the top level routine of the printer. 'sp' is the points - * to the FDDI 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 -fddi_if_print(u_char *pcap, const struct pcap_pkthdr *h, - register const u_char *p) +fddi_print(const u_char *p, u_int length, u_int caplen) { - u_int caplen = h->caplen; - u_int length = h->len; - const struct fddi_header *fddip = (struct fddi_header *)p; - extern u_short extracted_ethertype; + const struct fddi_header *fddip = (const struct fddi_header *)p; struct ether_header ehdr; - - ts_print(&h->ts); + u_short extracted_ethertype; if (caplen < FDDI_HDRLEN) { printf("[|fddi]"); - goto out; + return; } + /* * Get the FDDI addresses into a canonical form */ extract_fddi_addrs(fddip, (char *)ESRC(&ehdr), (char *)EDST(&ehdr)); - /* - * 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. - */ - snapend = p + caplen; - /* - * Actually, the only printer that uses packetp is print-bootp.c, - * and it assumes that packetp points to an Ethernet header. The - * right thing to do is to fix print-bootp.c to know which link - * type is in use when it excavates. XXX - */ - packetp = (u_char *)&ehdr; if (eflag) - fddi_print(fddip, length, ESRC(&ehdr), EDST(&ehdr)); + fddi_hdr_print(fddip, length, ESRC(&ehdr), EDST(&ehdr)); /* Skip over FDDI MAC header */ length -= FDDI_HDRLEN; @@ -305,14 +267,14 @@ fddi_if_print(u_char *pcap, const struct pcap_pkthdr *h, extracted_ethertype = 0; if ((fddip->fddi_fc & FDDIFC_CLFF) == FDDIFC_LLC_ASYNC) { /* Try to print the LLC-layer header & higher layers */ - if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr)) - == 0) { + if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr), + &extracted_ethertype) == 0) { /* * Some kinds of LLC packet we cannot * handle intelligently */ if (!eflag) - fddi_print(fddip, length, + fddi_hdr_print(fddip, length + FDDI_HDRLEN, ESRC(&ehdr), EDST(&ehdr)); if (extracted_ethertype) { printf("(LLC %s) ", @@ -326,28 +288,23 @@ fddi_if_print(u_char *pcap, const struct pcap_pkthdr *h, else { /* Some kinds of FDDI packet we cannot handle intelligently */ if (!eflag) - fddi_print(fddip, length, ESRC(&ehdr), EDST(&ehdr)); + fddi_hdr_print(fddip, length + FDDI_HDRLEN, ESRC(&ehdr), + EDST(&ehdr)); if (!xflag && !qflag) default_print(p, caplen); } - if (xflag) - default_print(p, caplen); -out: - putchar('\n'); } -#else -#include -#include -#include - -#include "interface.h" -void -fddi_if_print(u_char *pcap, const struct pcap_pkthdr *h, - register const u_char *p) +/* + * This is the top level routine of the printer. 'p' points + * to the FDDI header of the packet, 'h->ts' is the timestamp, + * 'h->length' is the length of the packet off the wire, and 'h->caplen' + * is the number of bytes actually captured. + */ +u_int +fddi_if_print(const struct pcap_pkthdr *h, register const u_char *p) { + fddi_print(p, h->len, h->caplen); - error("not configured for fddi"); - /* NOTREACHED */ + return (FDDI_HDRLEN); } -#endif diff --git a/kame/kame/tcpdump/print-fr.c b/kame/kame/tcpdump/print-fr.c new file mode 100644 index 0000000000..0239e0c518 --- /dev/null +++ b/kame/kame/tcpdump/print-fr.c @@ -0,0 +1,487 @@ +/* + * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#)$Header: /tcpdump/master/tcpdump/print-fr.c,v 1.17.2.3 2003/12/15 03:37:45 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include + +#include "addrtoname.h" +#include "interface.h" +#include "ethertype.h" +#include "extract.h" + +static void lmi_print(const u_char *, u_int); + +#define NLPID_LMI 0x08 /* ANSI T1.617 Annex D or ITU-T Q.933 Annex A */ +#define NLPID_CISCO_LMI 0x09 /* The original, aka Cisco, aka Gang of Four */ +#define NLPID_SNAP 0x80 +#define NLPID_CLNP 0x81 +#define NLPID_ESIS 0x82 +#define NLPID_ISIS 0x83 +#define NLPID_CONS 0x84 +#define NLPID_IDRP 0x85 +#define NLPID_X25_ESIS 0x8a +#define NLPID_IPV6 0x8e +#define NLPID_IP 0xcc + +#define FR_EA_BIT 0x01 + + +/* Finds out Q.922 address length, DLCI and flags. Returns 0 on success */ +static int parse_q922_addr(const u_char *p, u_int *dlci, u_int *addr_len, + char **flags_ptr) +{ + static char flags[32]; + size_t len; + + if ((p[0] & FR_EA_BIT)) + return -1; + + *flags_ptr = flags; + *addr_len = 2; + *dlci = ((p[0] & 0xFC) << 2) | ((p[1] & 0xF0) >> 4); + + strcpy(flags, (p[0] & 0x02) ? "C!, " : ""); + if (p[1] & 0x08) + strcat(flags, "FECN, "); + if (p[1] & 0x04) + strcat(flags, "BECN, "); + if (p[1] & 0x02) + strcat(flags, "DE, "); + + len = strlen(flags); + if (len > 1) + flags[len - 2] = '\x0'; /* delete trailing comma and space */ + + if (p[1] & FR_EA_BIT) + return 0; /* 2-byte Q.922 address */ + + p += 2; + (*addr_len)++; /* 3- or 4-byte Q.922 address */ + if ((p[0] & FR_EA_BIT) == 0) { + *dlci = (*dlci << 7) | (p[0] >> 1); + (*addr_len)++; /* 4-byte Q.922 address */ + p++; + } + + if ((p[0] & FR_EA_BIT) == 0) + return -1; /* more than 4 bytes of Q.922 address? */ + + if (p[0] & 0x02) { + len = strlen(flags); + snprintf(flags + len, sizeof(flags) - len, + "%sdlcore %x", len ? ", " : "", p[0] >> 2); + } else + *dlci = (*dlci << 6) | (p[0] >> 2); + + return 0; +} + + +static const char *fr_nlpids[256]; + +static void +init_fr_nlpids(void) +{ + int i; + static int fr_nlpid_flag = 0; + + if (!fr_nlpid_flag) { + for (i=0; i < 256; i++) + fr_nlpids[i] = NULL; + fr_nlpids[NLPID_LMI] = "LMI"; + fr_nlpids[NLPID_CISCO_LMI] = "Cisco LMI"; + fr_nlpids[NLPID_SNAP] = "SNAP"; + fr_nlpids[NLPID_CLNP] = "CLNP"; + fr_nlpids[NLPID_ESIS] = "ESIS"; + fr_nlpids[NLPID_ISIS] = "ISIS"; + fr_nlpids[NLPID_CONS] = "CONS"; + fr_nlpids[NLPID_IDRP] = "IDRP"; + fr_nlpids[NLPID_X25_ESIS] = "X25_ESIS"; + fr_nlpids[NLPID_IP] = "IP"; + } + fr_nlpid_flag = 1; +} + +/* Frame Relay packet structure, with flags and CRC removed + + +---------------------------+ + | Q.922 Address* | + +-- --+ + | | + +---------------------------+ + | Control (UI = 0x03) | + +---------------------------+ + | Optional Pad (0x00) | + +---------------------------+ + | NLPID | + +---------------------------+ + | . | + | . | + | . | + | Data | + | . | + | . | + +---------------------------+ + + * Q.922 addresses, as presently defined, are two octets and + contain a 10-bit DLCI. In some networks Q.922 addresses + may optionally be increased to three or four octets. +*/ + +static u_int +fr_hdrlen(const u_char *p, u_int addr_len, u_int caplen) +{ + if ((caplen > addr_len + 1 /* UI */ + 1 /* pad */) && + !p[addr_len + 1] /* pad exist */) + return addr_len + 1 /* UI */ + 1 /* pad */ + 1 /* NLPID */; + else + return addr_len + 1 /* UI */ + 1 /* NLPID */; +} + +static const char * +fr_protostring(u_int8_t proto) +{ + static char buf[5+1+2+1]; + + init_fr_nlpids(); + + if (nflag || fr_nlpids[proto] == NULL) { + snprintf(buf, sizeof(buf), "proto %02x", proto); + return buf; + } + return fr_nlpids[proto]; +} + +static void +fr_hdr_print(int length, u_int dlci, char *flags, u_char nlpid) +{ + if (qflag) + (void)printf("DLCI %u, %s%slength %d: ", + dlci, flags, *flags ? ", " : "", length); + else + (void)printf("DLCI %u, %s%s%s, length %d: ", + dlci, flags, *flags ? ", " : "", + fr_protostring(nlpid), length); +} + +u_int +fr_if_print(const struct pcap_pkthdr *h, register const u_char *p) +{ + register u_int length = h->len; + register u_int caplen = h->caplen; + u_short extracted_ethertype; + u_int32_t orgcode; + register u_short et; + u_int dlci; + int addr_len; + u_char nlpid; + u_int hdr_len; + char *flags; + + if (caplen < 4) { /* minimum frame header length */ + printf("[|fr]"); + return caplen; + } + + if (parse_q922_addr(p, &dlci, &addr_len, &flags)) { + printf("Invalid Q.922 address"); + return caplen; + } + + hdr_len = fr_hdrlen(p, addr_len, caplen); + + if (caplen < hdr_len) { + printf("[|fr]"); + return caplen; + } + + if (p[addr_len] != 0x03) + printf("UI %02x! ", p[addr_len]); + + if (!p[addr_len + 1]) { /* pad byte should be used with 3-byte Q.922 */ + if (addr_len != 3) + printf("Pad! "); + } else if (addr_len == 3) + printf("No pad! "); + + nlpid = p[hdr_len - 1]; + + p += hdr_len; + length -= hdr_len; + caplen -= hdr_len; + + if (eflag) + fr_hdr_print(length, dlci, flags, nlpid); + + switch (nlpid) { + case NLPID_IP: + ip_print(p, length); + break; + +#ifdef INET6 + case NLPID_IPV6: + ip6_print(p, length); + break; +#endif + case NLPID_CLNP: + case NLPID_ESIS: + case NLPID_ISIS: + isoclns_print(p, length, caplen); + break; + + case NLPID_SNAP: + orgcode = EXTRACT_24BITS(p); + et = EXTRACT_16BITS(p + 3); + if (snap_print((const u_char *)(p + 5), length - 5, + caplen - 5, &extracted_ethertype, orgcode, et, + 0) == 0) { + /* ether_type not known, print raw packet */ + if (!eflag) + fr_hdr_print(length + hdr_len, + dlci, flags, nlpid); + if (extracted_ethertype) { + printf("(SNAP %s) ", + etherproto_string(htons(extracted_ethertype))); + } + if (!xflag && !qflag) + default_print(p - hdr_len, caplen + hdr_len); + } + break; + + case NLPID_LMI: + lmi_print(p, length); + break; + + default: + if (!eflag) + fr_hdr_print(length + hdr_len, + dlci, flags, nlpid); + if (!xflag) + default_print(p, caplen); + } + + return hdr_len; +} + +/* + * Q.933 decoding portion for framerelay specific. + */ + +/* Q.933 packet format + Format of Other Protocols + using Q.933 NLPID + +-------------------------------+ + | Q.922 Address | + +---------------+---------------+ + |Control 0x03 | NLPID 0x08 | + +---------------+---------------+ + | L2 Protocol ID | + | octet 1 | octet 2 | + +-------------------------------+ + | L3 Protocol ID | + | octet 2 | octet 2 | + +-------------------------------+ + | Protocol Data | + +-------------------------------+ + | FCS | + +-------------------------------+ + */ + +/* L2 (Octet 1)- Call Reference Usually is 0x0 */ + +/* + * L2 (Octet 2)- Message Types definition 1 byte long. + */ +/* Call Establish */ +#define MSG_TYPE_ESC_TO_NATIONAL 0x00 +#define MSG_TYPE_ALERT 0x01 +#define MSG_TYPE_CALL_PROCEEDING 0x02 +#define MSG_TYPE_CONNECT 0x07 +#define MSG_TYPE_CONNECT_ACK 0x0F +#define MSG_TYPE_PROGRESS 0x03 +#define MSG_TYPE_SETUP 0x05 +/* Call Clear */ +#define MSG_TYPE_DISCONNECT 0x45 +#define MSG_TYPE_RELEASE 0x4D +#define MSG_TYPE_RELEASE_COMPLETE 0x5A +#define MSG_TYPE_RESTART 0x46 +#define MSG_TYPE_RESTART_ACK 0x4E +/* Status */ +#define MSG_TYPE_STATUS 0x7D +#define MSG_TYPE_STATUS_ENQ 0x75 + +#define MSG_ANSI_LOCKING_SHIFT 0x95 +#define ONE_BYTE_IE_MASK 0xF0 /* details? */ + +#define ANSI_REPORT_TYPE_IE 0x01 +#define ANSI_LINK_VERIFY_IE_91 0x19 /* details? */ +#define ANSI_LINK_VERIFY_IE 0x03 +#define ANSI_PVC_STATUS_IE 0x07 + +#define CCITT_REPORT_TYPE_IE 0x51 +#define CCITT_LINK_VERIFY_IE 0x53 +#define CCITT_PVC_STATUS_IE 0x57 + +struct common_ie_header { + u_int8_t ie_id; + u_int8_t ie_len; +}; + +#define FULL_STATUS 0 +#define LINK_VERIFY 1 +#define ASYNC_PVC 2 + + +/* Parses DLCI information element. */ +static const char * parse_dlci_ie(const u_char *p, u_int ie_len, char *buffer, + size_t buffer_len) +{ + u_int dlci; + + if ((ie_len < 3) || + (p[0] & 0x80) || + ((ie_len == 3) && !(p[1] & 0x80)) || + ((ie_len == 4) && ((p[1] & 0x80) || !(p[2] & 0x80))) || + ((ie_len == 5) && ((p[1] & 0x80) || (p[2] & 0x80) || + !(p[3] & 0x80))) || + (ie_len > 5) || + !(p[ie_len - 1] & 0x80)) + return "Invalid DLCI IE"; + + dlci = ((p[0] & 0x3F) << 4) | ((p[1] & 0x78) >> 3); + if (ie_len == 4) + dlci = (dlci << 6) | ((p[2] & 0x7E) >> 1); + else if (ie_len == 5) + dlci = (dlci << 13) | (p[2] & 0x7F) | ((p[3] & 0x7E) >> 1); + + snprintf(buffer, buffer_len, "DLCI %d: status %s%s", dlci, + p[ie_len - 1] & 0x8 ? "New, " : "", + p[ie_len - 1] & 0x2 ? "Active" : "Inactive"); + + return buffer; +} + + +static void +lmi_print(const u_char *p, u_int length) +{ + const u_char *ptemp = p; + const char *decode_str; + char temp_str[255]; + struct common_ie_header *ie_p; + int is_ansi = 0; + + if (length < 9) { /* shortest: Q.933a LINK VERIFY */ + printf("[|lmi]"); + return; + } + + if (p[2] == MSG_ANSI_LOCKING_SHIFT) + is_ansi = 1; + + /* printing out header part */ + printf(is_ansi ? "ANSI" : "CCITT"); + if (p[0]) + printf(" Call Ref: %02x!", p[0]); + + switch(p[1]) { + + case MSG_TYPE_STATUS: + printf(" STATUS REPLY\n"); + break; + + case MSG_TYPE_STATUS_ENQ: + printf(" STATUS ENQUIRY\n"); + break; + + default: + printf(" UNKNOWN MSG Type %02x\n", p[1]); + break; + } + + if (length < (u_int)(2 - is_ansi)) { + printf("[|lmi]"); + return; + } + length -= 2 - is_ansi; + ptemp += 2 + is_ansi; + + /* Loop through the rest of IE */ + while (length > 0) { + ie_p = (struct common_ie_header *)ptemp; + if (length < sizeof(struct common_ie_header) || + length < sizeof(struct common_ie_header) + ie_p->ie_len) { + printf("[|lmi]"); + return; + } + + if ((is_ansi && ie_p->ie_id == ANSI_REPORT_TYPE_IE) || + (!is_ansi && ie_p->ie_id == CCITT_REPORT_TYPE_IE)) { + switch(ptemp[2]) { + + case FULL_STATUS: + decode_str = "FULL STATUS"; + break; + + case LINK_VERIFY: + decode_str = "LINK VERIFY"; + break; + + case ASYNC_PVC: + decode_str = "Async PVC Status"; + break; + + default: + decode_str = "Reserved Value"; + break; + } + } else if ((is_ansi && (ie_p->ie_id == ANSI_LINK_VERIFY_IE_91 || + ie_p->ie_id == ANSI_LINK_VERIFY_IE)) || + (!is_ansi && ie_p->ie_id == CCITT_LINK_VERIFY_IE)) { + snprintf(temp_str, sizeof(temp_str), + "TX Seq: %3d, RX Seq: %3d", + ptemp[2], ptemp[3]); + decode_str = temp_str; + } else if ((is_ansi && ie_p->ie_id == ANSI_PVC_STATUS_IE) || + (!is_ansi && ie_p->ie_id == CCITT_PVC_STATUS_IE)) { + decode_str = parse_dlci_ie(ptemp + 2, ie_p->ie_len, + temp_str, sizeof(temp_str)); + } else + decode_str = "Non-decoded Value"; + + printf("\t\tIE: %02X Len: %d, %s\n", + ie_p->ie_id, ie_p->ie_len, decode_str); + length = length - ie_p->ie_len - 2; + ptemp = ptemp + ie_p->ie_len + 2; + } +} diff --git a/kame/kame/tcpdump/print-frag6.c b/kame/kame/tcpdump/print-frag6.c index 8197710286..2356efbbb0 100644 --- a/kame/kame/tcpdump/print-frag6.c +++ b/kame/kame/tcpdump/print-frag6.c @@ -20,61 +20,67 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) /master/usr.sbin/tcpdump/tcpdump/print-icmp.c,v 2.1 1995/02/03 18:14:42 polk Exp (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-frag6.c,v 1.16.2.3 2003/11/19 00:35:43 guy Exp $"; #endif -#ifdef INET6 - -#include -#include -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include +#ifdef INET6 -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include -#include +#include "ip6.h" #include "interface.h" #include "addrtoname.h" +#include "extract.h" -void +int frag6_print(register const u_char *bp, register const u_char *bp2) { register const struct ip6_frag *dp; - register const struct ip6_hdr *ip; + 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; - ip = (struct ip6_hdr *)bp2; + dp = (const struct ip6_frag *)bp; + ip6 = (const struct ip6_hdr *)bp2; - /* 'ep' points to the end of avaible data. */ + /* 'ep' points to the end of available data. */ ep = snapend; TCHECK(dp->ip6f_offlg); - printf("frag (%d|%d) ", - ntohs(dp->ip6f_offlg & IP6F_OFF_MASK), - ntohs(ip->ip6_plen)); - return; + if (vflag) { + printf("frag (0x%08x:%d|%ld)", + EXTRACT_32BITS(&dp->ip6f_ident), + EXTRACT_16BITS(&dp->ip6f_offlg) & IP6F_OFF_MASK, + sizeof(struct ip6_hdr) + EXTRACT_16BITS(&ip6->ip6_plen) - + (long)(bp - bp2) - sizeof(struct ip6_frag)); + } else { + printf("frag (%d|%ld)", + EXTRACT_16BITS(&dp->ip6f_offlg) & IP6F_OFF_MASK, + sizeof(struct ip6_hdr) + EXTRACT_16BITS(&ip6->ip6_plen) - + (long)(bp - bp2) - sizeof(struct ip6_frag)); + } + +#if 1 + /* it is meaningless to decode non-first fragment */ + if ((EXTRACT_16BITS(&dp->ip6f_offlg) & IP6F_OFF_MASK) != 0) + return -1; + else +#endif + { + fputs(" ", stdout); + return sizeof(struct ip6_frag); + } trunc: fputs("[|frag]", stdout); + return -1; #undef TCHECK } #endif /* INET6 */ diff --git a/kame/kame/tcpdump/print-gre.c b/kame/kame/tcpdump/print-gre.c index dd1ac83163..8657b58229 100644 --- a/kame/kame/tcpdump/print-gre.c +++ b/kame/kame/tcpdump/print-gre.c @@ -1,141 +1,373 @@ +/* $OpenBSD: print-gre.c,v 1.6 2002/10/30 03:04:04 fgsch Exp $ */ + /* - * Copyright (c) 1996 - * The Regents of the University of California. All rights reserved. - * - * 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 the University of California, Lawrence Berkeley Laboratory, - * Berkeley, CA. The name of the University 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 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * Copyright (c) 2002 Jason L. Wright (jason@thought.net) + * All rights reserved. * - * Initial contribution from John Hawkinson + * 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 Jason L. Wright + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. * - * This module implements support for decoding GRE (Generic Routing - * Encapsulation) tunnels; they're documented in RFC1701 and RFC1702. - * This code only supports the IP encapsulation thereof. + * 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. + */ + +/* + * tcpdump filter for GRE - Generic Routing Encapsulation + * RFC1701 (GRE), RFC1702 (GRE IPv4), and RFC2637 (Enhanced GRE) */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-gre.c,v 1.4 96/12/10 23:28:23 leres Exp $"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-gre.c,v 1.22.2.2 2003/11/16 08:51:24 guy Exp $ (LBL)"; #endif -#include -#include -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include -#include -#include +#include -#include #include +#include #include "interface.h" #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; -}; - -#define GRE_CP 0x8000 /* Checksum Present */ -#define GRE_RP 0x4000 /* Routing Present */ -#define GRE_KP 0x2000 /* Key Present */ -#define GRE_SP 0x1000 /* Sequence Present */ - - -#define GREPROTO_IP 0x0800 +#include "extract.h" +#include "ip.h" + +#define GRE_CP 0x8000 /* checksum present */ +#define GRE_RP 0x4000 /* routing present */ +#define GRE_KP 0x2000 /* key present */ +#define GRE_SP 0x1000 /* sequence# present */ +#define GRE_sP 0x0800 /* source routing */ +#define GRE_RECRS 0x0700 /* recursion count */ +#define GRE_AP 0x0080 /* acknowledgment# present */ +#define GRE_VERS 0x0007 /* protocol version */ + +#define GREPROTO_IP 0x0800 /* IP */ +#define GREPROTO_PPP 0x880b /* PPTP */ +#define GREPROTO_ISO 0x00fe /* OSI */ + +/* source route entry types */ +#define GRESRE_IP 0x0800 /* IP */ +#define GRESRE_ASN 0xfffe /* ASN */ + +void gre_print_0(const u_char *, u_int); +void gre_print_1(const u_char *, u_int); +void gre_sre_print(u_int16_t, u_int8_t, u_int8_t, const u_char *, u_int); +void gre_sre_ip_print(u_int8_t, u_int8_t, const u_char *, u_int); +void gre_sre_asn_print(u_int8_t, u_int8_t, const u_char *, u_int); -/* - * Deencapsulate and print a GRE-tunneled IP datagram - */ void gre_print(const u_char *bp, u_int length) { - const u_char *cp = bp + 4; - const struct gre *gre; - u_short flags, proto; + u_int len = length, vers; - gre = (const struct gre *)bp; + if (len < 2) { + printf("[|gre]"); + return; + } + vers = EXTRACT_16BITS(bp) & 7; - if (length < GRE_SIZE) { + if (vers == 0) + gre_print_0(bp, len); + else if (vers == 1) + gre_print_1(bp, len); + else + printf("gre-unknown-version=%u", vers); + return; + +} + +void +gre_print_0(const u_char *bp, u_int length) +{ + u_int len = length; + u_int16_t flags, prot; + + flags = EXTRACT_16BITS(bp); + if (vflag) { + printf("[%s%s%s%s%s] ", + (flags & GRE_CP) ? "C" : "", + (flags & GRE_RP) ? "R" : "", + (flags & GRE_KP) ? "K" : "", + (flags & GRE_SP) ? "S" : "", + (flags & GRE_sP) ? "s" : ""); + } + + len -= 2; + bp += 2; + + if (len < 2) goto trunc; + prot = EXTRACT_16BITS(bp); + len -= 2; + bp += 2; + + if ((flags & GRE_CP) | (flags & GRE_RP)) { + if (len < 2) + goto trunc; + if (vflag) + printf("sum 0x%x ", EXTRACT_16BITS(bp)); + bp += 2; + len -= 2; + + if (len < 2) + goto trunc; + printf("off 0x%x ", EXTRACT_16BITS(bp)); + bp += 2; + len -= 2; } - flags = EXTRACT_16BITS(&gre->flags); - proto = EXTRACT_16BITS(&gre->proto); - if (vflag) { - /* Decode the flags */ - putchar('['); - if (flags & GRE_CP) - putchar('C'); - if (flags & GRE_RP) - putchar('R'); - if (flags & GRE_KP) - putchar('K'); - if (flags & GRE_SP) - putchar('S'); - fputs("] ", stdout); - } - /* Checksum & Offset are present */ - if ((flags & GRE_CP) | (flags & GRE_RP)) - cp += 4; - - /* We don't support routing fields (variable length) now. Punt. */ - if (flags & GRE_RP) - return; + if (flags & GRE_KP) { + if (len < 4) + goto trunc; + printf("key=0x%x ", EXTRACT_32BITS(bp)); + bp += 4; + len -= 4; + } + + if (flags & GRE_SP) { + if (len < 4) + goto trunc; + printf("seq %u ", EXTRACT_32BITS(bp)); + bp += 4; + len -= 4; + } + + if (flags & GRE_RP) { + for (;;) { + u_int16_t af; + u_int8_t sreoff; + u_int8_t srelen; + + if (len < 4) + goto trunc; + af = EXTRACT_16BITS(bp); + sreoff = *(bp + 2); + srelen = *(bp + 3); + bp += 4; + len -= 4; - if (flags & GRE_KP) - cp += 4; - if (flags & GRE_SP) - cp += 4; + if (af == 0 && srelen == 0) + break; - switch (proto) { + gre_sre_print(af, sreoff, srelen, bp, len); + if (len < srelen) + goto trunc; + bp += srelen; + len -= srelen; + } + } + + switch (prot) { case GREPROTO_IP: - ip_print(cp, length - ((cp - bp) / sizeof(u_char))); + ip_print(bp, len); break; + case GREPROTO_ISO: + isoclns_print(bp, len, len); + break; + default: + printf("gre-proto-0x%x", prot); + } + return; + +trunc: + printf("[|gre]"); +} + +void +gre_print_1(const u_char *bp, u_int length) +{ + u_int len = length; + u_int16_t flags, prot; + + flags = EXTRACT_16BITS(bp); + len -= 2; + bp += 2; + + if (vflag) { + printf("[%s%s%s%s%s%s] ", + (flags & GRE_CP) ? "C" : "", + (flags & GRE_RP) ? "R" : "", + (flags & GRE_KP) ? "K" : "", + (flags & GRE_SP) ? "S" : "", + (flags & GRE_sP) ? "s" : "", + (flags & GRE_AP) ? "A" : ""); + } + + if (len < 2) + goto trunc; + prot = EXTRACT_16BITS(bp); + len -= 2; + bp += 2; + + if (flags & GRE_CP) { + printf("cpset!"); + return; + } + if (flags & GRE_RP) { + printf("rpset!"); + return; + } + if ((flags & GRE_KP) == 0) { + printf("kpunset!"); + return; + } + if (flags & GRE_sP) { + printf("spset!"); + return; + } + + if (flags & GRE_KP) { + u_int32_t k; + + if (len < 4) + goto trunc; + k = EXTRACT_32BITS(bp); + printf("call %d ", k & 0xffff); + len -= 4; + bp += 4; + } + + if (flags & GRE_SP) { + if (len < 4) + goto trunc; + printf("seq %u ", EXTRACT_32BITS(bp)); + bp += 4; + len -= 4; + } + + if (flags & GRE_AP) { + if (len < 4) + goto trunc; + printf("ack %u ", EXTRACT_32BITS(bp)); + bp += 4; + len -= 4; + } + if ((flags & GRE_SP) == 0) { + printf("no-payload"); + return; + } + + switch (prot) { + case GREPROTO_PPP: + printf("gre-ppp-payload"); + break; default: - printf("gre-proto-0x%04X", proto); + printf("gre-proto-0x%x", prot); break; } return; trunc: - fputs("[|gre]", stdout); + printf("[|gre]"); +} + +void +gre_sre_print(u_int16_t af, u_int8_t sreoff, u_int8_t srelen, + const u_char *bp, u_int len) +{ + switch (af) { + case GRESRE_IP: + printf("(rtaf=ip"); + gre_sre_ip_print(sreoff, srelen, bp, len); + printf(") "); + break; + case GRESRE_ASN: + printf("(rtaf=asn"); + gre_sre_asn_print(sreoff, srelen, bp, len); + printf(") "); + break; + default: + printf("(rtaf=0x%x) ", af); + } +} +void +gre_sre_ip_print(u_int8_t sreoff, u_int8_t srelen, const u_char *bp, u_int len) +{ + struct in_addr a; + const u_char *up = bp; + + if (sreoff & 3) { + printf(" badoffset=%u", sreoff); + return; + } + if (srelen & 3) { + printf(" badlength=%u", srelen); + return; + } + if (sreoff >= srelen) { + printf(" badoff/len=%u/%u", sreoff, srelen); + return; + } + + for (;;) { + if (len < 4 || srelen == 0) + return; + + memcpy(&a, bp, sizeof(a)); + printf(" %s%s", + ((bp - up) == sreoff) ? "*" : "", + inet_ntoa(a)); + + bp += 4; + len -= 4; + srelen -= 4; + } +} +void +gre_sre_asn_print(u_int8_t sreoff, u_int8_t srelen, const u_char *bp, u_int len) +{ + const u_char *up = bp; + + if (sreoff & 1) { + printf(" badoffset=%u", sreoff); + return; + } + if (srelen & 1) { + printf(" badlength=%u", srelen); + return; + } + if (sreoff >= srelen) { + printf(" badoff/len=%u/%u", sreoff, srelen); + return; + } + + for (;;) { + if (len < 2 || srelen == 0) + return; + + printf(" %s%x", + ((bp - up) == sreoff) ? "*" : "", + EXTRACT_16BITS(bp)); + + bp += 2; + len -= 2; + srelen -= 2; + } } diff --git a/kame/kame/tcpdump/print-hsrp.c b/kame/kame/tcpdump/print-hsrp.c new file mode 100644 index 0000000000..92050383f9 --- /dev/null +++ b/kame/kame/tcpdump/print-hsrp.c @@ -0,0 +1,136 @@ +/* + * 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[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-hsrp.c,v 1.7.2.2 2003/11/16 08:51:24 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include + +#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_int8_t hsrp_version; + u_int8_t hsrp_op_code; + u_int8_t hsrp_state; + u_int8_t hsrp_hellotime; + u_int8_t hsrp_holdtime; + u_int8_t hsrp_priority; + u_int8_t hsrp_group; + u_int8_t hsrp_reserved; + u_int8_t hsrp_authdata[HSRP_AUTH_SIZE]; + struct in_addr hsrp_virtaddr; +}; + +void +hsrp_print(register const u_int8_t *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); + } + TCHECK(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/kame/kame/tcpdump/print-icmp.c b/kame/kame/tcpdump/print-icmp.c index 17d3c70186..3cfbe6b62d 100644 --- a/kame/kame/tcpdump/print-icmp.c +++ b/kame/kame/tcpdump/print-icmp.c @@ -20,29 +20,15 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-icmp.c,v 1.38 96/09/26 23:36:44 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-icmp.c,v 1.73.2.3 2004/03/24 00:56:34 guy Exp $ (LBL)"; #endif -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include + +#include #include #include @@ -51,6 +37,127 @@ struct rtentry; #include "addrtoname.h" #include "extract.h" /* must come after interface.h */ +#include "ip.h" +#include "udp.h" +#include "ipproto.h" + +/* + * Interface Control Message Protocol Definitions. + * Per RFC 792, September 1981. + */ + +/* + * Structure of an icmp header. + */ +struct icmp { + u_int8_t icmp_type; /* type of message, see below */ + u_int8_t icmp_code; /* type sub code */ + u_int16_t icmp_cksum; /* ones complement cksum of struct */ + union { + u_int8_t ih_pptr; /* ICMP_PARAMPROB */ + struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ + struct ih_idseq { + u_int16_t icd_id; + u_int16_t icd_seq; + } ih_idseq; + u_int32_t ih_void; + + /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */ + struct ih_pmtu { + u_int16_t ipm_void; + u_int16_t ipm_nextmtu; + } ih_pmtu; + } icmp_hun; +#define icmp_pptr icmp_hun.ih_pptr +#define icmp_gwaddr icmp_hun.ih_gwaddr +#define icmp_id icmp_hun.ih_idseq.icd_id +#define icmp_seq icmp_hun.ih_idseq.icd_seq +#define icmp_void icmp_hun.ih_void +#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void +#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu + union { + struct id_ts { + u_int32_t its_otime; + u_int32_t its_rtime; + u_int32_t its_ttime; + } id_ts; + struct id_ip { + struct ip idi_ip; + /* options and then 64 bits of data */ + } id_ip; + u_int32_t id_mask; + u_int8_t id_data[1]; + } icmp_dun; +#define icmp_otime icmp_dun.id_ts.its_otime +#define icmp_rtime icmp_dun.id_ts.its_rtime +#define icmp_ttime icmp_dun.id_ts.its_ttime +#define icmp_ip icmp_dun.id_ip.idi_ip +#define icmp_mask icmp_dun.id_mask +#define icmp_data icmp_dun.id_data +}; + +/* + * Lower bounds on packet lengths for various types. + * For the error advice packets must first insure that the + * packet is large enought to contain the returned ip header. + * Only then can we do the check to see if 64 bits of packet + * data have been returned, since we need to check the returned + * ip header length. + */ +#define ICMP_MINLEN 8 /* abs minimum */ +#define ICMP_TSLEN (8 + 3 * sizeof (u_int32_t)) /* timestamp */ +#define ICMP_MASKLEN 12 /* address mask */ +#define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) /* min */ +#define ICMP_ADVLEN(p) (8 + (IP_HL(&(p)->icmp_ip) << 2) + 8) + /* N.B.: must separately check that ip_hl >= 5 */ + +/* + * Definition of type and code field values. + */ +#define ICMP_ECHOREPLY 0 /* echo reply */ +#define ICMP_UNREACH 3 /* dest unreachable, codes: */ +#define ICMP_UNREACH_NET 0 /* bad net */ +#define ICMP_UNREACH_HOST 1 /* bad host */ +#define ICMP_UNREACH_PROTOCOL 2 /* bad protocol */ +#define ICMP_UNREACH_PORT 3 /* bad port */ +#define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */ +#define ICMP_UNREACH_SRCFAIL 5 /* src route failed */ +#define ICMP_UNREACH_NET_UNKNOWN 6 /* unknown net */ +#define ICMP_UNREACH_HOST_UNKNOWN 7 /* unknown host */ +#define ICMP_UNREACH_ISOLATED 8 /* src host isolated */ +#define ICMP_UNREACH_NET_PROHIB 9 /* prohibited access */ +#define ICMP_UNREACH_HOST_PROHIB 10 /* ditto */ +#define ICMP_UNREACH_TOSNET 11 /* bad tos for net */ +#define ICMP_UNREACH_TOSHOST 12 /* bad tos for host */ +#define ICMP_SOURCEQUENCH 4 /* packet lost, slow down */ +#define ICMP_REDIRECT 5 /* shorter route, codes: */ +#define ICMP_REDIRECT_NET 0 /* for network */ +#define ICMP_REDIRECT_HOST 1 /* for host */ +#define ICMP_REDIRECT_TOSNET 2 /* for tos and net */ +#define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */ +#define ICMP_ECHO 8 /* echo service */ +#define ICMP_ROUTERADVERT 9 /* router advertisement */ +#define ICMP_ROUTERSOLICIT 10 /* router solicitation */ +#define ICMP_TIMXCEED 11 /* time exceeded, code: */ +#define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */ +#define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */ +#define ICMP_PARAMPROB 12 /* ip header bad */ +#define ICMP_PARAMPROB_OPTABSENT 1 /* req. opt. absent */ +#define ICMP_TSTAMP 13 /* timestamp request */ +#define ICMP_TSTAMPREPLY 14 /* timestamp reply */ +#define ICMP_IREQ 15 /* information request */ +#define ICMP_IREQREPLY 16 /* information reply */ +#define ICMP_MASKREQ 17 /* address mask request */ +#define ICMP_MASKREPLY 18 /* address mask reply */ + +#define ICMP_MAXTYPE 18 + +#define ICMP_INFOTYPE(type) \ + ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \ + (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \ + (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \ + (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \ + (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) /* rfc1700 */ #ifndef ICMP_UNREACH_NET_UNKNOWN #define ICMP_UNREACH_NET_UNKNOWN 6 /* destination net unknown */ @@ -85,14 +192,6 @@ struct rtentry; #define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* precedence cutoff */ #endif -/* rfc1256 */ -#ifndef ICMP_ROUTERADVERT -#define ICMP_ROUTERADVERT 9 /* router advertisement */ -#endif -#ifndef ICMP_ROUTERSOLICIT -#define ICMP_ROUTERSOLICIT 10 /* router solicitation */ -#endif - /* Most of the icmp types */ static struct tok icmp2str[] = { { ICMP_ECHOREPLY, "echo reply" }, @@ -139,21 +238,21 @@ 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 } }; /* rfc1191 */ struct mtu_discovery { - short unused; - short nexthopmtu; + u_int16_t unused; + u_int16_t nexthopmtu; }; /* rfc1256 */ struct ih_rdiscovery { - u_char ird_addrnum; - u_char ird_addrsiz; - u_short ird_lifetime; + u_int8_t ird_addrnum; + u_int8_t ird_addrsiz; + u_int16_t ird_lifetime; }; struct id_rdiscovery { @@ -162,65 +261,70 @@ struct id_rdiscovery { }; void -icmp_print(register const u_char *bp, register const u_char *bp2) +icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented) { - 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 buf[256]; + 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) { + case ICMP_ECHO: + case ICMP_ECHOREPLY: + TCHECK(dp->icmp_seq); + (void)snprintf(buf, sizeof(buf), "echo %s seq %u", + dp->icmp_type == ICMP_ECHO ? + "request" : "reply", + EXTRACT_16BITS(&dp->icmp_seq)); + break; + case ICMP_UNREACH: TCHECK(dp->icmp_ip.ip_dst); switch (dp->icmp_code) { case ICMP_UNREACH_PROTOCOL: TCHECK(dp->icmp_ip.ip_p); - (void)sprintf(buf, "%s protocol %d unreachable", - ipaddr_string(&dp->icmp_ip.ip_dst), - dp->icmp_ip.ip_p); + (void)snprintf(buf, sizeof(buf), + "%s protocol %d unreachable", + ipaddr_string(&dp->icmp_ip.ip_dst), + dp->icmp_ip.ip_p); break; case ICMP_UNREACH_PORT: TCHECK(dp->icmp_ip.ip_p); oip = &dp->icmp_ip; - hlen = oip->ip_hl * 4; + hlen = IP_HL(oip) * 4; ouh = (struct udphdr *)(((u_char *)oip) + hlen); - dport = ntohs(ouh->uh_dport); + TCHECK(ouh->uh_dport); + dport = EXTRACT_16BITS(&ouh->uh_dport); switch (oip->ip_p) { case IPPROTO_TCP: - (void)sprintf(buf, + (void)snprintf(buf, sizeof(buf), "%s tcp port %s unreachable", ipaddr_string(&oip->ip_dst), tcpport_string(dport)); break; case IPPROTO_UDP: - (void)sprintf(buf, + (void)snprintf(buf, sizeof(buf), "%s udp port %s unreachable", ipaddr_string(&oip->ip_dst), udpport_string(dport)); break; default: - (void)sprintf(buf, + (void)snprintf(buf, sizeof(buf), "%s protocol %d port %d unreachable", ipaddr_string(&oip->ip_dst), oip->ip_p, dport); @@ -229,26 +333,26 @@ icmp_print(register const u_char *bp, register const u_char *bp2) break; case ICMP_UNREACH_NEEDFRAG: - { + { register const struct mtu_discovery *mp; - mp = (struct mtu_discovery *)&dp->icmp_void; - mtu = EXTRACT_16BITS(&mp->nexthopmtu); - if (mtu) - (void)sprintf(buf, - "%s unreachable - need to frag (mtu %d)", - ipaddr_string(&dp->icmp_ip.ip_dst), mtu); - else - (void)sprintf(buf, - "%s unreachable - need to frag", - ipaddr_string(&dp->icmp_ip.ip_dst)); + 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 { + (void)snprintf(buf, sizeof(buf), + "%s unreachable - need to frag", + ipaddr_string(&dp->icmp_ip.ip_dst)); } + } break; default: fmt = tok2str(unreach2str, "#%d %%s unreachable", dp->icmp_code); - (void)sprintf(buf, fmt, + (void)snprintf(buf, sizeof(buf), fmt, ipaddr_string(&dp->icmp_ip.ip_dst)); break; } @@ -258,55 +362,60 @@ icmp_print(register const u_char *bp, register const u_char *bp2) TCHECK(dp->icmp_ip.ip_dst); fmt = tok2str(type2str, "redirect-#%d %%s to net %%s", dp->icmp_code); - (void)sprintf(buf, fmt, + (void)snprintf(buf, sizeof(buf), fmt, ipaddr_string(&dp->icmp_ip.ip_dst), ipaddr_string(&dp->icmp_gwaddr)); break; case ICMP_ROUTERADVERT: - { + { register const struct ih_rdiscovery *ihp; register const struct id_rdiscovery *idp; u_int lifetime, num, size; - (void)strcpy(buf, "router advertisement"); + (void)snprintf(buf, sizeof(buf), "router advertisement"); cp = buf + strlen(buf); ihp = (struct ih_rdiscovery *)&dp->icmp_void; TCHECK(*ihp); - (void)strcpy(cp, " lifetime "); + (void)strncpy(cp, " lifetime ", sizeof(buf) - (cp - buf)); cp = buf + strlen(buf); lifetime = EXTRACT_16BITS(&ihp->ird_lifetime); - if (lifetime < 60) - (void)sprintf(cp, "%u", lifetime); - else if (lifetime < 60 * 60) - (void)sprintf(cp, "%u:%02u", + if (lifetime < 60) { + (void)snprintf(cp, sizeof(buf) - (cp - buf), "%u", + lifetime); + } else if (lifetime < 60 * 60) { + (void)snprintf(cp, sizeof(buf) - (cp - buf), "%u:%02u", lifetime / 60, lifetime % 60); - else - (void)sprintf(cp, "%u:%02u:%02u", + } else { + (void)snprintf(cp, sizeof(buf) - (cp - buf), + "%u:%02u:%02u", lifetime / 3600, (lifetime % 3600) / 60, lifetime % 60); + } cp = buf + strlen(buf); num = ihp->ird_addrnum; - (void)sprintf(cp, " %d:", num); + (void)snprintf(cp, sizeof(buf) - (cp - buf), " %d:", num); cp = buf + strlen(buf); size = ihp->ird_addrsiz; if (size != 2) { - (void)sprintf(cp, " [size %d]", size); + (void)snprintf(cp, sizeof(buf) - (cp - buf), + " [size %d]", size); break; } idp = (struct id_rdiscovery *)&dp->icmp_data; while (num-- > 0) { TCHECK(*idp); - (void)sprintf(cp, " {%s %u}", + (void)snprintf(cp, sizeof(buf) - (cp - buf), " {%s %u}", ipaddr_string(&idp->ird_addr), EXTRACT_32BITS(&idp->ird_pref)); cp = buf + strlen(buf); + ++idp; } - } + } break; case ICMP_TIMXCEED: @@ -322,33 +431,72 @@ icmp_print(register const u_char *bp, register const u_char *bp2) break; default: - (void)sprintf(buf, "time exceeded-#%d", dp->icmp_code); + (void)snprintf(buf, sizeof(buf), "time exceeded-#%d", + dp->icmp_code); break; } break; case ICMP_PARAMPROB: if (dp->icmp_code) - (void)sprintf(buf, "parameter problem - code %d", - dp->icmp_code); + (void)snprintf(buf, sizeof(buf), + "parameter problem - code %d", dp->icmp_code); else { TCHECK(dp->icmp_pptr); - (void)sprintf(buf, "parameter problem - octet %d", - dp->icmp_pptr); + (void)snprintf(buf, sizeof(buf), + "parameter problem - octet %d", dp->icmp_pptr); } break; case ICMP_MASKREPLY: TCHECK(dp->icmp_mask); - (void)sprintf(buf, "address mask is 0x%08x", - (u_int32_t)ntohl(dp->icmp_mask)); + (void)snprintf(buf, sizeof(buf), "address mask is 0x%08x", + EXTRACT_32BITS(&dp->icmp_mask)); + break; + + case ICMP_TSTAMP: + TCHECK(dp->icmp_seq); + (void)snprintf(buf, sizeof(buf), + "time stamp query id %u seq %u", + EXTRACT_16BITS(&dp->icmp_id), + EXTRACT_16BITS(&dp->icmp_seq)); + break; + + case ICMP_TSTAMPREPLY: + TCHECK(dp->icmp_ttime); + (void)snprintf(buf, sizeof(buf), + "time stamp reply id %u seq %u : org 0x%x recv 0x%x xmit 0x%x", + EXTRACT_16BITS(&dp->icmp_id), + EXTRACT_16BITS(&dp->icmp_seq), + EXTRACT_32BITS(&dp->icmp_otime), + EXTRACT_32BITS(&dp->icmp_rtime), + EXTRACT_32BITS(&dp->icmp_ttime)); break; default: str = tok2str(icmp2str, "type-#%d", dp->icmp_type); break; } - (void)printf("icmp: %s", str); + (void)printf("icmp %d: %s", plen, str); + if (vflag && !fragmented) { /* don't attempt checksumming if this is a frag */ + u_int16_t sum, icmp_sum; + if (TTEST2(*bp, plen)) { + sum = in_cksum((u_short*)dp, plen, 0); + if (sum != 0) { + icmp_sum = EXTRACT_16BITS(&dp->icmp_cksum); + (void)printf(" (wrong icmp cksum %x (->%x)!)", + icmp_sum, + in_cksum_shouldbe(icmp_sum, sum)); + } + } + } + if (vflag > 1 && !ICMP_INFOTYPE(dp->icmp_type)) { + bp += 8; + (void)printf(" for "); + ip = (struct ip *)bp; + snaplen = snapend - bp; + ip_print(bp, EXTRACT_16BITS(&ip->ip_len)); + } return; trunc: fputs("[|icmp]", stdout); diff --git a/kame/kame/tcpdump/print-icmp6.c b/kame/kame/tcpdump/print-icmp6.c index bb90b130ca..88580b2502 100644 --- a/kame/kame/tcpdump/print-icmp6.c +++ b/kame/kame/tcpdump/print-icmp6.c @@ -20,81 +20,165 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) /master/usr.sbin/tcpdump/tcpdump/print-icmp.c,v 2.1 1995/02/03 18:14:42 polk Exp (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-icmp6.c,v 1.72.2.4 2004/03/24 00:14:09 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #ifdef INET6 -#include +#include -#include -#include -#include -#include +#include +#include -#include +#include "ip6.h" +#include "icmp6.h" +#include "ipproto.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" -#include +#include "udp.h" +#include "ah.h" -#include +static const char *get_rtpref(u_int); +static const char *get_lifetime(u_int32_t); +static void print_lladdr(const u_char *, size_t); +static void icmp6_opt_print(const u_char *, int); +static void mld6_print(const u_char *); +static struct udphdr *get_upperlayer(u_char *, u_int *); +static void dnsname_print(const u_char *, const u_char *); +static void icmp6_nodeinfo_print(u_int, const u_char *, const u_char *); +static void icmp6_rrenum_print(const u_char *, const u_char *); + +#ifndef abs +#define abs(a) ((0 < (a)) ? (a) : -(a)) +#endif -#include -#include +static const char * +get_rtpref(u_int v) +{ + static const char *rtpref_str[] = { + "medium", /* 00 */ + "high", /* 01 */ + "rsv", /* 10 */ + "low" /* 11 */ + }; -#include "interface.h" -#include "addrtoname.h" + return rtpref_str[((v & ND_RA_FLAG_RTPREF_MASK) >> 3) & 0xff]; +} -void icmp6_opt_print(const u_char *, int); -void mld6_print(const u_char *); +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--; + } +} + +static int icmp6_cksum(const struct ip6_hdr *ip6, const struct icmp6_hdr *icp, + u_int len) +{ + size_t i; + register const u_int16_t *sp; + u_int32_t sum; + union { + struct { + struct in6_addr ph_src; + struct in6_addr ph_dst; + u_int32_t ph_len; + u_int8_t ph_zero[3]; + u_int8_t ph_nxt; + } ph; + u_int16_t pa[20]; + } phu; + + /* pseudo-header */ + memset(&phu, 0, sizeof(phu)); + phu.ph.ph_src = ip6->ip6_src; + phu.ph.ph_dst = ip6->ip6_dst; + phu.ph.ph_len = htonl(len); + phu.ph.ph_nxt = IPPROTO_ICMPV6; + + sum = 0; + for (i = 0; i < sizeof(phu.pa) / sizeof(phu.pa[0]); i++) + sum += phu.pa[i]; + + sp = (const u_int16_t *)icp; + + for (i = 0; i < (len & ~1); i += 2) + sum += *sp++; + + if (len & 1) + sum += htons((*(const u_int8_t *)sp) << 8); + + while (sum > 0xffff) + sum = (sum & 0xffff) + (sum >> 16); + sum = ~sum & 0xffff; + + return (sum); +} void -icmp6_print(register const u_char *bp, register const u_char *bp2) +icmp6_print(const u_char *bp, u_int length, const u_char *bp2, int fragmented) { - register 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 hlen, dport; - register const u_char *ep; + const struct icmp6_hdr *dp; + 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; - -#if 0 -#define TCHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) goto trunc -#endif + u_int prot; dp = (struct icmp6_hdr *)bp; ip = (struct ip6_hdr *)bp2; oip = (struct ip6_hdr *)(dp + 1); str = buf; - /* 'ep' points to the end of avaible data. */ + /* 'ep' points to the end of available data. */ ep = snapend; - if (ip->ip6_plen) - icmp6len = (ntohs(ip->ip6_plen) + sizeof(struct ip6_hdr) - - (bp - 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) { + TCHECK(dp->icmp6_cksum); + + if (vflag && !fragmented) { + int sum = dp->icmp6_cksum; + + if (TTEST2(bp[0], length)) { + sum = icmp6_cksum(ip, dp, length); + if (sum != 0) + (void)printf("[bad icmp6 cksum %x!] ", sum); + else + (void)printf("[icmp6 sum ok] "); + } + } + + switch (dp->icmp6_type) { case ICMP6_DST_UNREACH: TCHECK(oip->ip6_dst); switch (dp->icmp6_code) { @@ -106,11 +190,7 @@ icmp6_print(register const u_char *bp, register const u_char *bp2) printf("icmp6: %s unreachable prohibited", ip6addr_string(&oip->ip6_dst)); break; -#ifdef ICMP6_DST_UNREACH_BEYONDSCOPE case ICMP6_DST_UNREACH_BEYONDSCOPE: -#else - case ICMP6_DST_UNREACH_NOTNEIGHBOR: -#endif printf("icmp6: %s beyond scope of source address %s", ip6addr_string(&oip->ip6_dst), ip6addr_string(&oip->ip6_src)); @@ -120,11 +200,12 @@ icmp6_print(register const u_char *bp, register const u_char *bp2) ip6addr_string(&oip->ip6_dst)); break; case ICMP6_DST_UNREACH_NOPORT: - TCHECK(oip->ip6_nxt); - hlen = sizeof(struct ip6_hdr); - ouh = (struct udphdr *)(((u_char *)oip) + hlen); - dport = ntohs(ouh->uh_dport); - switch (oip->ip6_nxt) { + if ((ouh = get_upperlayer((u_char *)oip, &prot)) + == NULL) + goto trunc; + + dport = EXTRACT_16BITS(&ouh->uh_dport); + switch (prot) { case IPPROTO_TCP: printf("icmp6: %s tcp port %s unreachable", ip6addr_string(&oip->ip6_dst), @@ -151,7 +232,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", EXTRACT_32BITS(&dp->icmp6_mtu)); break; case ICMP6_TIME_EXCEEDED: TCHECK(oip->ip6_dst); @@ -173,16 +254,16 @@ 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", - (u_int32_t)ntohl(dp->icmp6_pptr)); + printf("icmp6: parameter problem errorneous - octet %u", + EXTRACT_32BITS(&dp->icmp6_pptr)); break; case ICMP6_PARAMPROB_NEXTHEADER: - printf("icmp6: parameter problem next header - octet %u\n", - (u_int32_t)ntohl(dp->icmp6_pptr)); + printf("icmp6: parameter problem next header - octet %u", + EXTRACT_32BITS(&dp->icmp6_pptr)); break; case ICMP6_PARAMPROB_OPTION: - printf("icmp6: parameter problem option - octet %u\n", - (u_int32_t)ntohl(dp->icmp6_pptr)); + printf("icmp6: parameter problem option - octet %u", + EXTRACT_32BITS(&dp->icmp6_pptr)); break; default: printf("icmp6: parameter problem code-#%d", @@ -191,10 +272,12 @@ icmp6_print(register const u_char *bp, register const u_char *bp2) } break; case ICMP6_ECHO_REQUEST: - printf("icmp6: echo request"); - break; case ICMP6_ECHO_REPLY: - printf("icmp6: echo reply"); + TCHECK(dp->icmp6_seq); + printf("icmp6: echo %s seq %u", + dp->icmp6_type == ICMP6_ECHO_REQUEST ? + "request" : "reply", + EXTRACT_16BITS(&dp->icmp6_seq)); break; case ICMP6_MEMBERSHIP_QUERY: printf("icmp6: multicast listener query "); @@ -212,8 +295,8 @@ icmp6_print(register const u_char *bp, register const u_char *bp2) printf("icmp6: router solicitation "); if (vflag) { #define RTSOLLEN 8 - icmp6_opt_print((const u_char *)dp + RTSOLLEN, - icmp6len - RTSOLLEN); + icmp6_opt_print((const u_char *)dp + RTSOLLEN, + length - RTSOLLEN); } break; case ND_ROUTER_ADVERT: @@ -228,15 +311,24 @@ 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"); - printf(" "); - printf("router_ltime=%d, ", ntohs(p->nd_ra_router_lifetime)); + if (p->nd_ra_flags_reserved & ND_RA_FLAG_HOME_AGENT) + printf("H"); + + 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, ", EXTRACT_16BITS(&p->nd_ra_router_lifetime)); printf("reachable_time=%u, ", - (u_int32_t)ntohl(p->nd_ra_reachable)); + EXTRACT_32BITS(&p->nd_ra_reachable)); printf("retrans_time=%u)", - (u_int32_t)ntohl(p->nd_ra_retransmit)); + EXTRACT_32BITS(&p->nd_ra_retransmit)); #define RTADVLEN 16 - icmp6_opt_print((const u_char *)dp + RTADVLEN, - icmp6len - RTADVLEN); + icmp6_opt_print((const u_char *)dp + RTADVLEN, + length - RTADVLEN); } break; case ND_NEIGHBOR_SOLICIT: @@ -248,8 +340,8 @@ icmp6_print(register const u_char *bp, register const u_char *bp2) ip6addr_string(&p->nd_ns_target)); if (vflag) { #define NDSOLLEN 24 - icmp6_opt_print((const u_char *)dp + NDSOLLEN, - icmp6len - NDSOLLEN); + icmp6_opt_print((const u_char *)dp + NDSOLLEN, + length - NDSOLLEN); } } break; @@ -261,7 +353,7 @@ icmp6_print(register const u_char *bp, register const u_char *bp2) TCHECK(p->nd_na_target); printf("icmp6: neighbor adv: tgt is %s", ip6addr_string(&p->nd_na_target)); - if (vflag) { + if (vflag) { #define ND_NA_FLAG_ALL \ (ND_NA_FLAG_ROUTER|ND_NA_FLAG_SOLICITED|ND_NA_FLAG_OVERRIDE) /* we don't need ntohl() here. see advanced-api-04. */ @@ -280,124 +372,83 @@ icmp6_print(register const u_char *bp, register const u_char *bp2) printf(")"); } #define NDADVLEN 24 - icmp6_opt_print((const u_char *)dp + NDADVLEN, - icmp6len - NDADVLEN); + icmp6_opt_print((const u_char *)dp + NDADVLEN, + length - NDADVLEN); +#undef NDADVLEN } } break; case ND_REDIRECT: - { #define RDR(i) ((struct nd_redirect *)(i)) - char tgtbuf[INET6_ADDRSTRLEN], dstbuf[INET6_ADDRSTRLEN]; - TCHECK(RDR(dp)->nd_rd_dst); - inet_ntop(AF_INET6, &RDR(dp)->nd_rd_target, - tgtbuf, INET6_ADDRSTRLEN); - inet_ntop(AF_INET6, &RDR(dp)->nd_rd_dst, - dstbuf, INET6_ADDRSTRLEN); - printf("icmp6: redirect %s to %s", dstbuf, tgtbuf); + printf("icmp6: redirect %s", + getname6((const u_char *)&RDR(dp)->nd_rd_dst)); + TCHECK(RDR(dp)->nd_rd_target); + printf(" to %s", + getname6((const u_char*)&RDR(dp)->nd_rd_target)); #define REDIRECTLEN 40 if (vflag) { icmp6_opt_print((const u_char *)dp + REDIRECTLEN, - icmp6len - REDIRECTLEN); + length - REDIRECTLEN); } break; - } +#undef REDIRECTLEN +#undef RDR case ICMP6_ROUTER_RENUMBERING: - switch (dp->icmp6_code) { - case ICMP6_ROUTER_RENUMBERING_COMMAND: - printf("icmp6: router renum command"); - break; - case ICMP6_ROUTER_RENUMBERING_RESULT: - printf("icmp6: router renum result"); - break; - default: - printf("icmp6: router renum code-#%d", dp->icmp6_code); - break; - } + icmp6_rrenum_print(bp, ep); break; -#ifdef ICMP6_WRUREQUEST - case ICMP6_WRUREQUEST: /*ICMP6_FQDN_QUERY*/ - { - int siz; - siz = ep - (u_char *)(dp + 1); - if (siz == 4) - printf("icmp6: who-are-you request"); - else { - printf("icmp6: FQDN request"); - if (vflag) { - if (siz < 8) - printf("?(icmp6_data %d bytes)", siz); - else if (8 < siz) - printf("?(extra %d bytes)", siz - 8); - } + case ICMP6_NI_QUERY: + case ICMP6_NI_REPLY: + icmp6_nodeinfo_print(length, bp, ep); + break; + case ICMP6_HADISCOV_REQUEST: + printf("icmp6: ha discovery request"); + if (vflag) { + TCHECK(dp->icmp6_data16[0]); + printf("(id=%d)", EXTRACT_16BITS(&dp->icmp6_data16[0])); } break; - } -#endif /*ICMP6_WRUREQUEST*/ -#ifdef ICMP6_WRUREPLY - case ICMP6_WRUREPLY: /*ICMP6_FQDN_REPLY*/ - { - enum { UNKNOWN, WRU, FQDN } mode = UNKNOWN; - u_char const *buf; - u_char const *cp = NULL; - - buf = (u_char *)(dp + 1); - - /* fair guess */ - if (buf[12] == ep - buf - 13) - mode = FQDN; - else if (dp->icmp6_code == 1) - mode = FQDN; - - /* wild guess */ - if (mode == UNKNOWN) { - cp = buf + 4; - while (cp < ep) { - if (!isprint(*cp++)) - mode = FQDN; + case ICMP6_HADISCOV_REPLY: + printf("icmp6: ha discovery reply"); + if (vflag) { + struct in6_addr *in6; + u_char *cp; + + TCHECK(dp->icmp6_data16[0]); + printf("(id=%d", EXTRACT_16BITS(&dp->icmp6_data16[0])); + cp = (u_char *)dp + length; + in6 = (struct in6_addr *)(dp + 1); + for (; (u_char *)in6 < cp; in6++) { + TCHECK(*in6); + printf(", %s", ip6addr_string(in6)); } + printf(")"); } -#ifndef abs -#define abs(a) ((0 < (a)) ? (a) : -(a)) -#endif - if (mode == UNKNOWN && 2 < abs(buf[12] - (ep - buf - 13))) - mode = WRU; - if (mode == UNKNOWN) - mode = FQDN; - - if (mode == WRU) { - cp = buf + 4; - printf("icmp6: who-are-you reply(\""); - } else if (mode == FQDN) { - cp = buf + 13; - printf("icmp6: FQDN reply(\""); + break; + case ICMP6_MOBILEPREFIX_SOLICIT: + printf("icmp6: mobile router solicitation"); + if (vflag) { + TCHECK(dp->icmp6_data16[0]); + printf("(id=%d)", EXTRACT_16BITS(&dp->icmp6_data16[0])); } - for (; cp < ep; cp++) - printf((isprint(*cp) ? "%c" : "\\%03o"), *cp); - printf("\""); + break; + case ICMP6_MOBILEPREFIX_ADVERT: + printf("icmp6: mobile router advertisement"); if (vflag) { - printf(",%s", mode == FQDN ? "FQDN" : "WRU"); - if (mode == FQDN) { - long ttl; - ttl = (long)ntohl(*(u_long *)&buf[8]); - if (dp->icmp6_code == 1) - printf(",TTL=unknown"); - else if (ttl < 0) - printf(",TTL=%ld:invalid", ttl); - else - printf(",TTL=%ld", ttl); - if (buf[12] != ep - buf - 13) { - (void)printf(",invalid namelen:%d/%u", - buf[12], - (unsigned int)(ep - buf - 13)); - } - } + TCHECK(dp->icmp6_data16[0]); + printf("(id=%d", EXTRACT_16BITS(&dp->icmp6_data16[0])); + if (dp->icmp6_data16[1] & 0xc0) + printf(" "); + if (dp->icmp6_data16[1] & 0x80) + printf("M"); + if (dp->icmp6_data16[1] & 0x40) + printf("O"); + printf(")"); +#define MPADVLEN 8 + icmp6_opt_print((const u_char *)dp + MPADVLEN, + length - MPADVLEN); } - printf(")"); break; - } -#endif /*ICMP6_WRUREPLY*/ default: printf("icmp6: type-#%d", dp->icmp6_type); break; @@ -405,164 +456,682 @@ icmp6_print(register const u_char *bp, register const u_char *bp2) return; trunc: fputs("[|icmp6]", stdout); -#if 0 -#undef TCHECK -#endif } -void -icmp6_opt_print(register const u_char *bp, int resid) +static struct udphdr * +get_upperlayer(u_char *bp, u_int *prot) { - 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 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 u_char *ep; + struct ip6_hdr *ip6 = (struct ip6_hdr *)bp; + struct udphdr *uh; + struct ip6_hbh *hbh; + struct ip6_frag *fragh; + struct ah *ah; + u_int nh; + int hlen; + + /* 'ep' points to the end of available data. */ + ep = snapend; + + if (!TTEST(ip6->ip6_nxt)) + return NULL; + + nh = ip6->ip6_nxt; + hlen = sizeof(struct ip6_hdr); + + while (bp < snapend) { + bp += hlen; + + switch(nh) { + case IPPROTO_UDP: + case IPPROTO_TCP: + uh = (struct udphdr *)bp; + if (TTEST(uh->uh_dport)) { + *prot = nh; + return(uh); + } + else + return(NULL); + /* NOTREACHED */ + + case IPPROTO_HOPOPTS: + case IPPROTO_DSTOPTS: + case IPPROTO_ROUTING: + hbh = (struct ip6_hbh *)bp; + if (!TTEST(hbh->ip6h_len)) + return(NULL); + nh = hbh->ip6h_nxt; + hlen = (hbh->ip6h_len + 1) << 3; + break; + + case IPPROTO_FRAGMENT: /* this should be odd, but try anyway */ + fragh = (struct ip6_frag *)bp; + if (!TTEST(fragh->ip6f_offlg)) + return(NULL); + /* fragments with non-zero offset are meaningless */ + if ((EXTRACT_16BITS(&fragh->ip6f_offlg) & IP6F_OFF_MASK) != 0) + return(NULL); + nh = fragh->ip6f_nxt; + hlen = sizeof(struct ip6_frag); + break; + + case IPPROTO_AH: + ah = (struct ah *)bp; + if (!TTEST(ah->ah_len)) + return(NULL); + nh = ah->ah_nxt; + hlen = (ah->ah_len + 2) << 2; + break; + + default: /* unknown or undecodable header */ + *prot = nh; /* meaningless, but set here anyway */ + return(NULL); + } + } + + return(NULL); /* should be notreached, though */ +} + +static void +icmp6_opt_print(const u_char *bp, int resid) +{ + 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_homeagent_info *oph; + const struct nd_opt_route_info *opri; + const u_char *cp, *ep; + struct in6_addr in6, *in6p; + size_t l; -#if 0 -#define TCHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) goto trunc -#endif #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 - /* 'ep' points to the end of avaible data. */ + 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"); - 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(EXTRACT_32BITS(&opp->nd_opt_pi_valid_time))); + printf("preferred_ltime=%s,", + get_lifetime(EXTRACT_32BITS(&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", EXTRACT_32BITS(&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", + EXTRACT_32BITS(&opa->nd_opt_adv_interval)); + /*(*/ + printf(")"); + break; + case ND_OPT_HOMEAGENT_INFO: + oph = (struct nd_opt_homeagent_info *)op; + TCHECK(oph->nd_opt_hai_lifetime); + printf("(ha info:"); /*)*/ + printf(" pref=%d", EXTRACT_16BITS(&oph->nd_opt_hai_preference)); + printf(", lifetime=%u", EXTRACT_16BITS(&oph->nd_opt_hai_lifetime)); + 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(EXTRACT_32BITS(&opri->nd_opt_rti_lifetime))); + /*(*/ + printf(")"); + break; + default: + printf("(unknown 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; - 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; -#if 0 -#undef TCHECK -#endif #undef ECHECK } -void -mld6_print(register const u_char *bp) +static void +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 avaible data. */ + /* 'ep' points to the end of available data. */ ep = snapend; if ((u_char *)mp + sizeof(*mp) > ep) return; - printf("max resp delay: %d ", ntohs(mp->mld6_maxdelay)); + printf("max resp delay: %d ", EXTRACT_16BITS(&mp->mld6_maxdelay)); printf("addr: %s", ip6addr_string(&mp->mld6_addr)); +} + +static void +dnsname_print(const u_char *cp, const u_char *ep) +{ + int i; + + /* DNS name decoding - no decompression */ + printf(", \""); + while (cp < ep) { + i = *cp++; + if (i) { + if (i > ep - cp) { + printf("???"); + break; + } + while (i-- && cp < ep) { + safeputchar(*cp); + cp++; + } + if (cp + 1 < ep && *cp) + printf("."); + } else { + if (cp == ep) { + /* FQDN */ + printf("."); + } else if (cp + 1 == ep && *cp == '\0') { + /* truncated */ + } else { + /* invalid */ + printf("???"); + } + break; + } + } + printf("\""); +} + +static void +icmp6_nodeinfo_print(u_int icmp6len, const u_char *bp, const u_char *ep) +{ + struct icmp6_nodeinfo *ni6; + struct icmp6_hdr *dp; + const u_char *cp; + size_t siz, i; + int needcomma; + + if (ep < bp) + return; + dp = (struct icmp6_hdr *)bp; + ni6 = (struct icmp6_nodeinfo *)bp; + siz = ep - bp; + + switch (ni6->ni_type) { + case ICMP6_NI_QUERY: + if (siz == sizeof(*dp) + 4) { + /* KAME who-are-you */ + printf("icmp6: who-are-you request"); + break; + } + printf("icmp6: node information query"); + + TCHECK2(*dp, sizeof(*ni6)); + ni6 = (struct icmp6_nodeinfo *)dp; + printf(" ("); /*)*/ + switch (EXTRACT_16BITS(&ni6->ni_qtype)) { + case NI_QTYPE_NOOP: + printf("noop"); + break; + case NI_QTYPE_SUPTYPES: + printf("supported qtypes"); + i = EXTRACT_16BITS(&ni6->ni_flags); + if (i) + printf(" [%s]", (i & 0x01) ? "C" : ""); + break; + break; + case NI_QTYPE_FQDN: + printf("DNS name"); + break; + case NI_QTYPE_NODEADDR: + printf("node addresses"); + i = ni6->ni_flags; + if (!i) + break; + /* NI_NODEADDR_FLAG_TRUNCATE undefined for query */ + printf(" [%s%s%s%s%s%s]", + (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "", + (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "", + (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "", + (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "", + (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "", + (i & NI_NODEADDR_FLAG_ALL) ? "A" : ""); + break; + default: + printf("unknown"); + break; + } + + if (ni6->ni_qtype == NI_QTYPE_NOOP || + ni6->ni_qtype == NI_QTYPE_SUPTYPES) { + if (siz != sizeof(*ni6)) + if (vflag) + printf(", invalid len"); + /*(*/ + printf(")"); + break; + } + + /* XXX backward compat, icmp-name-lookup-03 */ + if (siz == sizeof(*ni6)) { + printf(", 03 draft"); + /*(*/ + printf(")"); + break; + } + + switch (ni6->ni_code) { + case ICMP6_NI_SUBJ_IPV6: + if (!TTEST2(*dp, + sizeof(*ni6) + sizeof(struct in6_addr))) + break; + if (siz != sizeof(*ni6) + sizeof(struct in6_addr)) { + if (vflag) + printf(", invalid subject len"); + break; + } + printf(", subject=%s", + getname6((const u_char *)(ni6 + 1))); + break; + case ICMP6_NI_SUBJ_FQDN: + printf(", subject=DNS name"); + cp = (const u_char *)(ni6 + 1); + if (cp[0] == ep - cp - 1) { + /* icmp-name-lookup-03, pascal string */ + if (vflag) + printf(", 03 draft"); + cp++; + printf(", \""); + while (cp < ep) { + safeputchar(*cp); + cp++; + } + printf("\""); + } else + dnsname_print(cp, ep); + break; + case ICMP6_NI_SUBJ_IPV4: + if (!TTEST2(*dp, sizeof(*ni6) + sizeof(struct in_addr))) + break; + if (siz != sizeof(*ni6) + sizeof(struct in_addr)) { + if (vflag) + printf(", invalid subject len"); + break; + } + printf(", subject=%s", + getname((const u_char *)(ni6 + 1))); + break; + default: + printf(", unknown subject"); + break; + } + + /*(*/ + printf(")"); + break; + + case ICMP6_NI_REPLY: + if (icmp6len > siz) { + printf("[|icmp6: node information reply]"); + break; + } + + needcomma = 0; + + ni6 = (struct icmp6_nodeinfo *)dp; + printf("icmp6: node information reply"); + printf(" ("); /*)*/ + switch (ni6->ni_code) { + case ICMP6_NI_SUCCESS: + if (vflag) { + printf("success"); + needcomma++; + } + break; + case ICMP6_NI_REFUSED: + printf("refused"); + needcomma++; + if (siz != sizeof(*ni6)) + if (vflag) + printf(", invalid length"); + break; + case ICMP6_NI_UNKNOWN: + printf("unknown"); + needcomma++; + if (siz != sizeof(*ni6)) + if (vflag) + printf(", invalid length"); + break; + } + + if (ni6->ni_code != ICMP6_NI_SUCCESS) { + /*(*/ + printf(")"); + break; + } + + switch (EXTRACT_16BITS(&ni6->ni_qtype)) { + case NI_QTYPE_NOOP: + if (needcomma) + printf(", "); + printf("noop"); + if (siz != sizeof(*ni6)) + if (vflag) + printf(", invalid length"); + break; + case NI_QTYPE_SUPTYPES: + if (needcomma) + printf(", "); + printf("supported qtypes"); + i = EXTRACT_16BITS(&ni6->ni_flags); + if (i) + printf(" [%s]", (i & 0x01) ? "C" : ""); + break; + case NI_QTYPE_FQDN: + if (needcomma) + printf(", "); + printf("DNS name"); + cp = (const u_char *)(ni6 + 1) + 4; + if (cp[0] == ep - cp - 1) { + /* icmp-name-lookup-03, pascal string */ + if (vflag) + printf(", 03 draft"); + cp++; + printf(", \""); + while (cp < ep) { + safeputchar(*cp); + cp++; + } + printf("\""); + } else + dnsname_print(cp, ep); + if ((EXTRACT_16BITS(&ni6->ni_flags) & 0x01) != 0) + printf(" [TTL=%u]", *(u_int32_t *)(ni6 + 1)); + break; + case NI_QTYPE_NODEADDR: + if (needcomma) + printf(", "); + printf("node addresses"); + i = sizeof(*ni6); + while (i < siz) { + if (i + sizeof(struct in6_addr) + sizeof(int32_t) > siz) + break; + printf(" %s", getname6(bp + i)); + i += sizeof(struct in6_addr); + printf("(%d)", (int32_t)EXTRACT_32BITS(bp + i)); + i += sizeof(int32_t); + } + i = ni6->ni_flags; + if (!i) + break; + printf(" [%s%s%s%s%s%s%s]", + (i & NI_NODEADDR_FLAG_ANYCAST) ? "a" : "", + (i & NI_NODEADDR_FLAG_GLOBAL) ? "G" : "", + (i & NI_NODEADDR_FLAG_SITELOCAL) ? "S" : "", + (i & NI_NODEADDR_FLAG_LINKLOCAL) ? "L" : "", + (i & NI_NODEADDR_FLAG_COMPAT) ? "C" : "", + (i & NI_NODEADDR_FLAG_ALL) ? "A" : "", + (i & NI_NODEADDR_FLAG_TRUNCATE) ? "T" : ""); + break; + default: + if (needcomma) + printf(", "); + printf("unknown"); + break; + } + + /*(*/ + printf(")"); + break; + } return; + +trunc: + fputs("[|icmp6]", stdout); } + +static void +icmp6_rrenum_print(const u_char *bp, const u_char *ep) +{ + struct icmp6_router_renum *rr6; + struct icmp6_hdr *dp; + size_t siz; + const char *cp; + struct rr_pco_match *match; + struct rr_pco_use *use; + char hbuf[NI_MAXHOST]; + int n; + + if (ep < bp) + return; + dp = (struct icmp6_hdr *)bp; + rr6 = (struct icmp6_router_renum *)bp; + siz = ep - bp; + cp = (const char *)(rr6 + 1); + + TCHECK(rr6->rr_reserved); + switch (rr6->rr_code) { + case ICMP6_ROUTER_RENUMBERING_COMMAND: + printf("router renum: command"); + break; + case ICMP6_ROUTER_RENUMBERING_RESULT: + printf("router renum: result"); + break; + case ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET: + printf("router renum: sequence number reset"); + break; + default: + printf("router renum: code-#%d", rr6->rr_code); + break; + } + + printf(", seq=%u", EXTRACT_32BITS(&rr6->rr_seqnum)); + + if (vflag) { +#define F(x, y) ((rr6->rr_flags) & (x) ? (y) : "") + printf("["); /*]*/ + 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_FORCEAPPLY, "A"), + F(ICMP6_RR_FLAGS_SPECSITE, "S"), + F(ICMP6_RR_FLAGS_PREVDONE, "P")); + } + printf("seg=%u,", rr6->rr_segnum); + printf("maxdelay=%u", rr6->rr_maxdelay); + if (rr6->rr_reserved) + printf("rsvd=0x%x", EXTRACT_16BITS(&rr6->rr_reserved)); + /*[*/ + printf("]"); +#undef F + } + + if (rr6->rr_code == ICMP6_ROUTER_RENUMBERING_COMMAND) { + match = (struct rr_pco_match *)cp; + cp = (const char *)(match + 1); + + TCHECK(match->rpm_prefix); + + if (vflag > 1) + printf("\n\t"); + else + printf(" "); + printf("match("); /*)*/ + switch (match->rpm_code) { + case RPM_PCO_ADD: printf("add"); break; + case RPM_PCO_CHANGE: printf("change"); break; + case RPM_PCO_SETGLOBAL: printf("setglobal"); break; + default: printf("#%u", match->rpm_code); break; + } + + if (vflag) { + printf(",ord=%u", match->rpm_ordinal); + printf(",min=%u", match->rpm_minlen); + printf(",max=%u", match->rpm_maxlen); + } + if (inet_ntop(AF_INET6, &match->rpm_prefix, hbuf, sizeof(hbuf))) + printf(",%s/%u", hbuf, match->rpm_matchlen); + else + printf(",?/%u", match->rpm_matchlen); + /*(*/ + printf(")"); + + n = match->rpm_len - 3; + if (n % 4) + goto trunc; + n /= 4; + while (n-- > 0) { + use = (struct rr_pco_use *)cp; + cp = (const char *)(use + 1); + + TCHECK(use->rpu_prefix); + + if (vflag > 1) + printf("\n\t"); + else + printf(" "); + printf("use("); /*)*/ + if (use->rpu_flags) { +#define F(x, y) ((use->rpu_flags) & (x) ? (y) : "") + printf("%s%s,", + F(ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME, "V"), + F(ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME, "P")); +#undef F + } + if (vflag) { + printf("mask=0x%x,", use->rpu_ramask); + printf("raflags=0x%x,", use->rpu_raflags); + if (~use->rpu_vltime == 0) + printf("vltime=infty,"); + else + printf("vltime=%u,", + EXTRACT_32BITS(&use->rpu_vltime)); + if (~use->rpu_pltime == 0) + printf("pltime=infty,"); + else + printf("pltime=%u,", + EXTRACT_32BITS(&use->rpu_pltime)); + } + if (inet_ntop(AF_INET6, &use->rpu_prefix, hbuf, + sizeof(hbuf))) + printf("%s/%u/%u", hbuf, use->rpu_uselen, + use->rpu_keeplen); + else + printf("?/%u/%u", use->rpu_uselen, + use->rpu_keeplen); + /*(*/ + printf(")"); + } + } + + return; + +trunc: + fputs("[|icmp6]", stdout); +} + #endif /* INET6 */ diff --git a/kame/kame/tcpdump/print-igmp.c b/kame/kame/tcpdump/print-igmp.c new file mode 100644 index 0000000000..717ae169c3 --- /dev/null +++ b/kame/kame/tcpdump/print-igmp.c @@ -0,0 +1,335 @@ +/* + * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-igmp.c,v 1.11.2.3 2003/11/19 09:41:29 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" /* must come after interface.h */ + +#ifndef IN_CLASSD +#define IN_CLASSD(i) (((int32_t)(i) & 0xf0000000) == 0xe0000000) +#endif + +/* (following from ipmulti/mrouted/prune.h) */ + +/* + * The packet format for a traceroute request. + */ +struct tr_query { + u_int32_t tr_src; /* traceroute source */ + u_int32_t tr_dst; /* traceroute destination */ + u_int32_t tr_raddr; /* traceroute response address */ + u_int32_t tr_rttlqid; /* response ttl and qid */ +}; + +#define TR_GETTTL(x) (int)(((x) >> 24) & 0xff) +#define TR_GETQID(x) ((x) & 0x00ffffff) + +/* + * Traceroute response format. A traceroute response has a tr_query at the + * beginning, followed by one tr_resp for each hop taken. + */ +struct tr_resp { + u_int32_t tr_qarr; /* query arrival time */ + u_int32_t tr_inaddr; /* incoming interface address */ + u_int32_t tr_outaddr; /* outgoing interface address */ + u_int32_t tr_rmtaddr; /* parent address in source tree */ + u_int32_t tr_vifin; /* input packet count on interface */ + u_int32_t tr_vifout; /* output packet count on interface */ + u_int32_t tr_pktcnt; /* total incoming packets for src-grp */ + u_int8_t tr_rproto; /* routing proto deployed on router */ + u_int8_t tr_fttl; /* ttl required to forward on outvif */ + u_int8_t tr_smask; /* subnet mask for src addr */ + u_int8_t tr_rflags; /* forwarding error codes */ +}; + +/* defs within mtrace */ +#define TR_QUERY 1 +#define TR_RESP 2 + +/* fields for tr_rflags (forwarding error codes) */ +#define TR_NO_ERR 0 +#define TR_WRONG_IF 1 +#define TR_PRUNED 2 +#define TR_OPRUNED 3 +#define TR_SCOPED 4 +#define TR_NO_RTE 5 +#define TR_NO_FWD 7 +#define TR_NO_SPACE 0x81 +#define TR_OLD_ROUTER 0x82 + +/* fields for tr_rproto (routing protocol) */ +#define TR_PROTO_DVMRP 1 +#define TR_PROTO_MOSPF 2 +#define TR_PROTO_PIM 3 +#define TR_PROTO_CBT 4 + +/* igmpv3 report types */ +static struct tok igmpv3report2str[] = { + { 1, "is_in" }, + { 2, "is_ex" }, + { 3, "to_in" }, + { 4, "to_ex" }, + { 5, "allow" }, + { 6, "block" }, + { 0, NULL } +}; + +static void +print_mtrace(register const u_char *bp, register u_int len) +{ + register const struct tr_query *tr = (const struct tr_query *)(bp + 8); + + TCHECK(*tr); + if (len < 8 + sizeof (struct tr_query)) { + (void)printf(" [invalid len %d]", len); + return; + } + printf("mtrace %u: %s to %s reply-to %s", + TR_GETQID(EXTRACT_32BITS(&tr->tr_rttlqid)), + ipaddr_string(&tr->tr_src), ipaddr_string(&tr->tr_dst), + ipaddr_string(&tr->tr_raddr)); + if (IN_CLASSD(EXTRACT_32BITS(&tr->tr_raddr))) + printf(" with-ttl %d", TR_GETTTL(EXTRACT_32BITS(&tr->tr_rttlqid))); + return; +trunc: + (void)printf("[|igmp]"); + return; +} + +static void +print_mresp(register const u_char *bp, register u_int len) +{ + register const struct tr_query *tr = (const struct tr_query *)(bp + 8); + + TCHECK(*tr); + if (len < 8 + sizeof (struct tr_query)) { + (void)printf(" [invalid len %d]", len); + return; + } + printf("mresp %lu: %s to %s reply-to %s", + (u_long)TR_GETQID(EXTRACT_32BITS(&tr->tr_rttlqid)), + ipaddr_string(&tr->tr_src), ipaddr_string(&tr->tr_dst), + ipaddr_string(&tr->tr_raddr)); + if (IN_CLASSD(EXTRACT_32BITS(&tr->tr_raddr))) + printf(" with-ttl %d", TR_GETTTL(EXTRACT_32BITS(&tr->tr_rttlqid))); + return; +trunc: + (void)printf("[|igmp]"); + return; +} + +static void +print_igmpv3_report(register const u_char *bp, register u_int len) +{ + 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) { + (void)printf(" [invalid len %d]", len); + return; + } + TCHECK2(bp[6], 2); + ngroups = EXTRACT_16BITS(&bp[6]); + (void)printf(", %d group record(s)", ngroups); + if (vflag > 0) { + /* Print the group records */ + group = 8; + for (i=0; i> 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; + (void)printf(" [gaddr %s", ipaddr_string(&bp[4])); + TCHECK2(bp[10], 2); + nsrcs = EXTRACT_16BITS(&bp[10]); + if (nsrcs > 0) { + if (len < 12 + (nsrcs << 2)) + (void)printf(" [invalid number of sources]"); + else if (vflag > 1) { + (void)printf(" {"); + for (i=0; i= 12) + print_igmpv3_query(bp, len); + else { + TCHECK(bp[1]); + if (bp[1]) { + (void)printf(" v2"); + if (bp[1] != 100) + (void)printf(" [max resp time %d]", bp[1]); + } else + (void)printf(" v1"); + TCHECK2(bp[4], 4); + if (EXTRACT_32BITS(&bp[4])) + (void)printf(" [gaddr %s]", ipaddr_string(&bp[4])); + if (len != 8) + (void)printf(" [len %d]", len); + } + break; + case 0x12: + TCHECK2(bp[4], 4); + (void)printf("igmp v1 report %s", ipaddr_string(&bp[4])); + if (len != 8) + (void)printf(" [len %d]", len); + break; + case 0x16: + TCHECK2(bp[4], 4); + (void)printf("igmp v2 report %s", ipaddr_string(&bp[4])); + break; + case 0x22: + (void)printf("igmp v3 report"); + print_igmpv3_report(bp, len); + break; + case 0x17: + (void)printf("igmp leave %s", ipaddr_string(&bp[4])); + break; + case 0x13: + (void)printf("igmp dvmrp"); + if (len < 8) + (void)printf(" [len %d]", len); + else + dvmrp_print(bp, len); + break; + case 0x14: + (void)printf("igmp pimv1"); + pimv1_print(bp, len); + break; + case 0x1e: + print_mresp(bp, len); + break; + case 0x1f: + print_mtrace(bp, len); + break; + default: + (void)printf("igmp-%d", bp[0]); + break; + } + + if (vflag && TTEST2(bp[0], len)) { + /* Check the IGMP checksum */ + if (in_cksum((const u_short*)bp, len, 0)) + printf(" bad igmp cksum %x!", EXTRACT_16BITS(&bp[2])); + } + return; +trunc: + fputs("[|igmp]", stdout); +} diff --git a/kame/kame/tcpdump/print-igrp.c b/kame/kame/tcpdump/print-igrp.c index 87e8e79819..4622a93537 100644 --- a/kame/kame/tcpdump/print-igrp.c +++ b/kame/kame/tcpdump/print-igrp.c @@ -22,27 +22,22 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-igrp.c,v 1.8 97/05/28 12:52:47 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-igrp.c,v 1.18.2.2 2003/11/16 08:51:26 guy Exp $ (LBL)"; #endif -#include -#include /* concession to AIX */ -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include -#include -#include -#include -#include -#include +#include -#include #include #include "interface.h" #include "addrtoname.h" #include "igrp.h" +#include "ip.h" #include "extract.h" /* must come after interface.h */ static void @@ -92,9 +87,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); @@ -103,8 +96,8 @@ igrp_print(register const u_char *bp, u_int length, register const u_char *bp2) next = EXTRACT_16BITS(&hdr->ig_nx); (void)printf(" %s V%d edit=%d AS=%d (%d/%d/%d)", - tok2str(op2str, "op-#%d", hdr->ig_op), - hdr->ig_v, + tok2str(op2str, "op-#%d", IGRP_OP(hdr->ig_vop)), + IGRP_V(hdr->ig_vop), hdr->ig_ed, EXTRACT_16BITS(&hdr->ig_as), nint, @@ -126,7 +119,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 +128,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/kame/kame/tcpdump/print-ip.c b/kame/kame/tcpdump/print-ip.c index 7266c6c98d..0cc559892e 100644 --- a/kame/kame/tcpdump/print-ip.c +++ b/kame/kame/tcpdump/print-ip.c @@ -20,229 +20,166 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-ip.c,v 1.66 97/05/28 12:51:43 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.128.2.6 2004/03/24 09:01:39 guy Exp $ (LBL)"; #endif -#include -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include -#include -#include -#include -#include -#include -#include +#include -#ifdef HAVE_MALLOC_H -#include -#endif #include #include #include -#include #include "addrtoname.h" #include "interface.h" #include "extract.h" /* must come after interface.h */ -/* Compatibility */ -#ifndef IPPROTO_ND -#define IPPROTO_ND 77 -#endif - -#ifndef IN_CLASSD -#define IN_CLASSD(i) (((int32_t)(i) & 0xf0000000) == 0xe0000000) -#endif - -/* (following from ipmulti/mrouted/prune.h) */ +#include "ip.h" +#include "ipproto.h" /* - * The packet format for a traceroute request. + * print the recorded route in an IP RR, LSRR or SSRR option. */ -struct tr_query { - u_int tr_src; /* traceroute source */ - u_int tr_dst; /* traceroute destination */ - u_int tr_raddr; /* traceroute response address */ -#ifdef WORDS_BIGENDIAN - struct { - u_int ttl : 8; /* traceroute response ttl */ - u_int qid : 24; /* traceroute query id */ - } q; -#else - struct { - u_int qid : 24; /* traceroute query id */ - u_int ttl : 8; /* traceroute response ttl */ - } q; -#endif -}; +static void +ip_printroute(const char *type, register const u_char *cp, u_int length) +{ + register u_int ptr; + register u_int len; -#define tr_rttl q.ttl -#define tr_qid q.qid + if (length < 3) { + printf(" [bad length %u]", length); + return; + } + printf(" %s{", type); + if ((length + 1) & 3) + printf(" [bad length %u]", length); + ptr = cp[2] - 1; + if (ptr < 3 || ((ptr + 1) & 3) || ptr > length + 1) + printf(" [bad ptr %u]", cp[2]); + + type = ""; + for (len = 3; len < length; len += 4) { + if (ptr == len) + type = "#"; + printf("%s%s", type, ipaddr_string(&cp[len])); + type = " "; + } + printf("%s}", ptr == len? "#" : ""); +} /* - * Traceroute response format. A traceroute response has a tr_query at the - * beginning, followed by one tr_resp for each hop taken. + * If source-routing is present, return the final destination. + * Otherwise, return IP destination. + * + * This is used for UDP and TCP pseudo-header in the checksum + * calculation. */ -struct tr_resp { - u_int tr_qarr; /* query arrival time */ - u_int tr_inaddr; /* incoming interface address */ - u_int tr_outaddr; /* outgoing interface address */ - u_int tr_rmtaddr; /* parent address in source tree */ - u_int tr_vifin; /* input packet count on interface */ - u_int tr_vifout; /* output packet count on interface */ - u_int tr_pktcnt; /* total incoming packets for src-grp */ - u_char tr_rproto; /* routing proto deployed on router */ - u_char tr_fttl; /* ttl required to forward on outvif */ - u_char tr_smask; /* subnet mask for src addr */ - u_char tr_rflags; /* forwarding error codes */ -}; - -/* defs within mtrace */ -#define TR_QUERY 1 -#define TR_RESP 2 - -/* fields for tr_rflags (forwarding error codes) */ -#define TR_NO_ERR 0 -#define TR_WRONG_IF 1 -#define TR_PRUNED 2 -#define TR_OPRUNED 3 -#define TR_SCOPED 4 -#define TR_NO_RTE 5 -#define TR_NO_FWD 7 -#define TR_NO_SPACE 0x81 -#define TR_OLD_ROUTER 0x82 - -/* fields for tr_rproto (routing protocol) */ -#define TR_PROTO_DVMRP 1 -#define TR_PROTO_MOSPF 2 -#define TR_PROTO_PIM 3 -#define TR_PROTO_CBT 4 - -static void print_mtrace(register const u_char *bp, register u_int len) +u_int32_t +ip_finddst(const struct ip *ip) { - register struct tr_query *tr = (struct tr_query *)(bp + 8); + int length; + int len; + const u_char *cp; + u_int32_t retval; - printf("mtrace %d: %s to %s reply-to %s", tr->tr_qid, - ipaddr_string(&tr->tr_src), ipaddr_string(&tr->tr_dst), - ipaddr_string(&tr->tr_raddr)); - if (IN_CLASSD(ntohl(tr->tr_raddr))) - printf(" with-ttl %d", tr->tr_rttl); -} + cp = (const u_char *)(ip + 1); + length = (IP_HL(ip) << 2) - sizeof(struct ip); -static void print_mresp(register const u_char *bp, register u_int len) -{ - register struct tr_query *tr = (struct tr_query *)(bp + 8); + for (; length > 0; cp += len, length -= len) { + int tt; + + TCHECK(*cp); + tt = *cp; + if (tt == IPOPT_NOP || tt == IPOPT_EOL) + len = 1; + else { + TCHECK(cp[1]); + len = cp[1]; + } + if (len < 2) { + return 0; + } + TCHECK2(*cp, len); + switch (tt) { - printf("mresp %d: %s to %s reply-to %s", tr->tr_qid, - ipaddr_string(&tr->tr_src), ipaddr_string(&tr->tr_dst), - ipaddr_string(&tr->tr_raddr)); - if (IN_CLASSD(ntohl(tr->tr_raddr))) - printf(" with-ttl %d", tr->tr_rttl); + case IPOPT_SSRR: + case IPOPT_LSRR: + if (len < 7) + return 0; + memcpy(&retval, cp + len - 4, 4); + return retval; + } + } + return ip->ip_dst.s_addr; + +trunc: + return 0; } static void -igmp_print(register const u_char *bp, register u_int len, - register const u_char *bp2) +ip_printts(register const u_char *cp, u_int length) { - register const struct ip *ip; + register u_int ptr; + register u_int len; + int hoplen; + const char *type; - ip = (const struct ip *)bp2; - (void)printf("%s > %s: ", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); - - TCHECK2(bp[0], 8); - switch (bp[0]) { - case 0x11: - (void)printf("igmp query"); - if (*(int *)&bp[4]) - (void)printf(" [gaddr %s]", ipaddr_string(&bp[4])); - if (len != 8) - (void)printf(" [len %d]", len); - break; - case 0x12: - (void)printf("igmp report %s", ipaddr_string(&bp[4])); - if (len != 8) - (void)printf(" [len %d]", len); - break; - case 0x16: - (void)printf("igmp nreport %s", ipaddr_string(&bp[4])); - break; - case 0x17: - (void)printf("igmp leave %s", ipaddr_string(&bp[4])); + if (length < 4) { + printf("[bad length %d]", length); + return; + } + printf(" TS{"); + hoplen = ((cp[3]&0xF) != IPOPT_TS_TSONLY) ? 8 : 4; + if ((length - 4) & (hoplen-1)) + printf("[bad length %d]", length); + ptr = cp[2] - 1; + len = 0; + if (ptr < 4 || ((ptr - 4) & (hoplen-1)) || ptr > length + 1) + printf("[bad ptr %d]", cp[2]); + switch (cp[3]&0xF) { + case IPOPT_TS_TSONLY: + printf("TSONLY"); break; - case 0x13: - (void)printf("igmp dvmrp"); - if (len < 8) - (void)printf(" [len %d]", len); - else - dvmrp_print(bp, len); + case IPOPT_TS_TSANDADDR: + printf("TS+ADDR"); break; - case 0x14: - (void)printf("igmp pim"); - igmp_pim_print(bp, len); - break; - case 0x1e: - print_mresp(bp, len); + /* + * prespecified should really be 3, but some ones might send 2 + * instead, and the IPOPT_TS_PRESPEC constant can apparently + * have both values, so we have to hard-code it here. + */ + + case 2: + printf("PRESPEC2.0"); break; - case 0x1f: - print_mtrace(bp, len); + case 3: /* IPOPT_TS_PRESPEC */ + printf("PRESPEC"); break; default: - (void)printf("igmp-%d", bp[0] & 0xf); - break; - } - if ((bp[0] >> 4) != 1) - (void)printf(" [v%d]", bp[0] >> 4); - - TCHECK2(bp[0], len); - if (vflag) { - /* Check the IGMP checksum */ - u_int32_t sum = 0; - int count; - const u_short *sp = (u_short *)bp; - - for (count = len / 2; --count >= 0; ) - sum += *sp++; - if (len & 1) - sum += ntohs(*(u_char *) sp << 8); - while (sum >> 16) - sum = (sum & 0xffff) + (sum >> 16); - sum = 0xffff & ~sum; - if (sum != 0) - printf(" bad igmp cksum %x!", EXTRACT_16BITS(&bp[2])); + printf("[bad ts type %d]", cp[3]&0xF); + goto done; } - return; -trunc: - fputs("[|igmp]", stdout); -} - -/* - * print the recorded route in an IP RR, LSRR or SSRR option. - */ -static void -ip_printroute(const char *type, register const u_char *cp, u_int length) -{ - register u_int ptr = cp[2] - 1; - register u_int len; - printf(" %s{", type); - if ((length + 1) & 3) - printf(" [bad length %d]", length); - if (ptr < 3 || ((ptr + 1) & 3) || ptr > length + 1) - printf(" [bad ptr %d]", cp[2]); - - type = ""; - for (len = 3; len < length; len += 4) { + type = " "; + for (len = 4; len < length; len += hoplen) { if (ptr == len) - type = "#"; - printf("%s%s", type, ipaddr_string(&cp[len])); + type = " ^ "; + printf("%s%d@%s", type, EXTRACT_32BITS(&cp[len+hoplen-4]), + hoplen!=8 ? "" : ipaddr_string(&cp[len])); type = " "; } - printf("%s}", ptr == len? "#" : ""); + +done: + printf("%s", ptr == len ? " ^ " : ""); + + if (cp[3]>>4) + printf(" [%d hops not recorded]} ", cp[3]>>4); + else + printf("}"); } /* @@ -254,16 +191,20 @@ ip_optprint(register const u_char *cp, u_int length) register u_int len; for (; length > 0; cp += len, length -= len) { - int tt = *cp; - - len = (tt == IPOPT_NOP || tt == IPOPT_EOL) ? 1 : cp[1]; - if (len <= 0) { - printf("[|ip op len %d]", len); - return; - } - if (&cp[1] >= snapend || cp + len > snapend) { - printf("[|ip]"); - return; + int tt; + + TCHECK(*cp); + tt = *cp; + if (tt == IPOPT_NOP || tt == IPOPT_EOL) + len = 1; + else { + TCHECK(cp[1]); + len = cp[1]; + if (len < 2) { + printf("[|ip op len %d]", len); + return; + } + TCHECK2(*cp, len); } switch (tt) { @@ -278,15 +219,17 @@ ip_optprint(register const u_char *cp, u_int length) break; case IPOPT_TS: - printf(" TS{%d}", len); + ip_printts(cp, len); break; +#ifndef IPOPT_SECURITY +#define IPOPT_SECURITY 130 +#endif /* IPOPT_SECURITY */ case IPOPT_SECURITY: printf(" SECURITY{%d}", len); break; case IPOPT_RR: - printf(" RR{%d}=", len); ip_printroute("RR", cp, len); break; @@ -298,36 +241,132 @@ ip_optprint(register const u_char *cp, u_int length) ip_printroute("LSRR", cp, len); break; +#ifndef IPOPT_RA +#define IPOPT_RA 148 /* router alert */ +#endif + case IPOPT_RA: + printf(" RA"); + if (len != 4) + printf("{%d}", len); + else { + TCHECK(cp[3]); + if (cp[2] || cp[3]) + printf("%d.%d", cp[2], cp[3]); + } + break; + default: printf(" IPOPT-%d{%d}", cp[0], len); break; } } + return; + +trunc: + printf("[|ip]"); } /* * compute an IP header checksum. * don't modifiy the packet. */ -static int -in_cksum(const struct ip *ip) +u_short +in_cksum(const u_short *addr, register u_int len, int csum) { - register const u_short *sp = (u_short *)ip; - register u_int32_t sum = 0; - register int count; + int nleft = len; + const u_short *w = addr; + u_short answer; + int sum = csum; /* - * No need for endian conversions. + * Our algorithm is simple, using a 32 bit accumulator (sum), + * we add sequential 16 bit words to it, and at the end, fold + * back all the carry bits from the top 16 bits into the lower + * 16 bits. */ - for (count = ip->ip_hl * 2; --count >= 0; ) - sum += *sp++; - while (sum > 0xffff) - sum = (sum & 0xffff) + (sum >> 16); - sum = ~sum & 0xffff; + while (nleft > 1) { + sum += *w++; + nleft -= 2; + } + if (nleft == 1) + sum += htons(*(u_char *)w<<8); - return (sum); + /* + * add back carry outs from top 16 bits to low 16 bits + */ + sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */ + sum += (sum >> 16); /* add carry */ + answer = ~sum; /* truncate to 16 bits */ + return (answer); } +/* + * Given the host-byte-order value of the checksum field in a packet + * header, and the network-byte-order computed checksum of the data + * that the checksum covers (including the checksum itself), compute + * what the checksum field *should* have been. + */ +u_int16_t +in_cksum_shouldbe(u_int16_t sum, u_int16_t computed_sum) +{ + u_int32_t shouldbe; + + /* + * The value that should have gone into the checksum field + * is the negative of the value gotten by summing up everything + * *but* the checksum field. + * + * We can compute that by subtracting the value of the checksum + * field from the sum of all the data in the packet, and then + * computing the negative of that value. + * + * "sum" is the value of the checksum field, and "computed_sum" + * is the negative of the sum of all the data in the packets, + * so that's -(-computed_sum - sum), or (sum + computed_sum). + * + * All the arithmetic in question is one's complement, so the + * addition must include an end-around carry; we do this by + * doing the arithmetic in 32 bits (with no sign-extension), + * and then adding the upper 16 bits of the sum, which contain + * the carry, to the lower 16 bits of the sum, and then do it + * again in case *that* sum produced a carry. + * + * As RFC 1071 notes, the checksum can be computed without + * byte-swapping the 16-bit words; summing 16-bit words + * on a big-endian machine gives a big-endian checksum, which + * can be directly stuffed into the big-endian checksum fields + * in protocol headers, and summing words on a little-endian + * machine gives a little-endian checksum, which must be + * byte-swapped before being stuffed into a big-endian checksum + * field. + * + * "computed_sum" is a network-byte-order value, so we must put + * it in host byte order before subtracting it from the + * host-byte-order value from the header; the adjusted checksum + * will be in host byte order, which is what we'll return. + */ + shouldbe = sum; + shouldbe += ntohs(computed_sum); + shouldbe = (shouldbe & 0xFFFF) + (shouldbe >> 16); + shouldbe = (shouldbe & 0xFFFF) + (shouldbe >> 16); + return shouldbe; +} + +#ifndef IP_MF +#define IP_MF 0x2000 +#endif /* IP_MF */ +#ifndef IP_DF +#define IP_DF 0x4000 +#endif /* IP_DF */ +#define IP_RES 0x8000 + +static struct tok ip_frag_values[] = { + { IP_MF, "+" }, + { IP_DF, "DF" }, + { IP_RES, "rsvd" }, /* The RFC3514 evil ;-) bit */ + { 0, NULL } +}; + /* * print an IP datagram. */ @@ -335,38 +374,23 @@ void ip_print(register const u_char *bp, register u_int length) { register const struct ip *ip; - register u_int hlen, len, off; + register u_int hlen, len, len0, off; + const u_char *ipend; register const u_char *cp; u_char nh; int advance; + struct protoent *proto; + u_int16_t sum, ip_sum; ip = (const struct ip *)bp; -#ifdef LBL_ALIGN - /* - * If the IP header is not aligned, copy into abuf. - * This will never happen with BPF. It does happen raw packet - * dumps from -r. - */ - if ((long)ip & 3) { - static u_char *abuf = NULL; - static int didwarn = 0; - - if (abuf == NULL) { - abuf = (u_char *)malloc(snaplen); - if (abuf == NULL) - error("ip_print: malloc"); - } - memcpy((char *)abuf, (char *)ip, min(length, snaplen)); - snapend += abuf - (u_char *)ip; - packetp = abuf; - ip = (struct ip *)abuf; - /* We really want libpcap to give us aligned packets */ - if (!didwarn) { - warning("compensating for unaligned libpcap packets"); - ++didwarn; - } + if (IP_V(ip) != 4) { /* print version if != 4 */ + printf("IP%u ", IP_V(ip)); + if (IP_V(ip) == 6) + printf(", wrong link-layer encapsulation"); } -#endif + else + printf("IP "); + if ((u_char *)(ip + 1) > snapend) { printf("[|ip]"); return; @@ -375,24 +399,93 @@ ip_print(register const u_char *bp, register u_int length) (void)printf("truncated-ip %d", length); return; } - hlen = ip->ip_hl * 4; + hlen = IP_HL(ip) * 4; + if (hlen < sizeof (struct ip)) { + (void)printf("bad-hlen %u", hlen); + return; + } - len = ntohs(ip->ip_len); + len = EXTRACT_16BITS(&ip->ip_len); if (length < len) - (void)printf("truncated-ip - %d bytes missing!", + (void)printf("truncated-ip - %u bytes missing! ", len - length); + if (len < hlen) { + (void)printf("bad-len %u", len); + return; + } + + /* + * Cut off the snapshot length to the end of the IP payload. + */ + ipend = bp + len; + if (ipend < snapend) + snapend = ipend; + len -= hlen; + len0 = len; + + off = EXTRACT_16BITS(&ip->ip_off); + + if (vflag) { + (void)printf("(tos 0x%x", (int)ip->ip_tos); + /* ECN bits */ + 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"); + } + } + + if (ip->ip_ttl >= 1) + (void)printf(", ttl %3u", ip->ip_ttl); + + /* + * for the firewall guys, print id, offset. + * On all but the last stick a "+" in the flags portion. + * For unfragmented datagrams, note the don't fragment flag. + */ + + (void)printf(", id %u, offset %u, flags [%s]", + EXTRACT_16BITS(&ip->ip_id), + (off & 0x1fff) * 8, + bittok2str(ip_frag_values, "none", off & 0xe000 )); + + (void)printf(", length: %u", EXTRACT_16BITS(&ip->ip_len)); + + if ((hlen - sizeof(struct ip)) > 0) { + (void)printf(", optlength: %u (", hlen - (u_int)sizeof(struct ip)); + ip_optprint((u_char *)(ip + 1), hlen - sizeof(struct ip)); + printf(" )"); + } + + if ((u_char *)ip + hlen <= snapend) { + sum = in_cksum((const u_short *)ip, hlen, 0); + if (sum != 0) { + ip_sum = EXTRACT_16BITS(&ip->ip_sum); + (void)printf(", bad cksum %x (->%x)!", ip_sum, + in_cksum_shouldbe(ip_sum, sum)); + } + } + + printf(") "); + } /* * If this is fragment zero, hand it to the next higher * level protocol. */ - off = ntohs(ip->ip_off); if ((off & 0x1fff) == 0) { cp = (const u_char *)ip + hlen; nh = ip->ip_p; - if (nh != IPPROTO_TCP && nh != IPPROTO_UDP) { + if (nh != IPPROTO_TCP && nh != IPPROTO_UDP && + nh != IPPROTO_SCTP) { (void)printf("%s > %s: ", ipaddr_string(&ip->ip_src), ipaddr_string(&ip->ip_dst)); } @@ -401,53 +494,54 @@ ip_print(register const u_char *bp, register u_int length) case IPPROTO_AH: nh = *cp; - advance = ah_print(cp, (const u_char *)ip); + advance = ah_print(cp); + if (advance <= 0) + break; cp += advance; len -= advance; goto again; case IPPROTO_ESP: { - int enh; - advance = esp_print(cp, (const u_char *)ip, &enh); - cp += advance; - len -= advance; - if (enh < 0) + int enh, padlen; + advance = esp_print(cp, (const u_char *)ip, &enh, &padlen); + if (advance <= 0) break; + cp += advance; + len -= advance + padlen; nh = enh & 0xff; goto again; } -#ifndef IPPROTO_IPCOMP -#define IPPROTO_IPCOMP 108 -#endif case IPPROTO_IPCOMP: { int enh; - advance = ipcomp_print(cp, (const u_char *)ip, &enh); + advance = ipcomp_print(cp, &enh); + if (advance <= 0) + break; cp += advance; len -= advance; - if (enh < 0) - break; nh = enh & 0xff; 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); + tcp_print(cp, len, (const u_char *)ip, (off &~ 0x6000)); break; case IPPROTO_UDP: - udp_print(cp, len, (const u_char *)ip); + udp_print(cp, len, (const u_char *)ip, (off &~ 0x6000)); break; case IPPROTO_ICMP: - icmp_print(cp, (const u_char *)ip); + /* pass on the MF bit plus the offset to detect fragments */ + icmp_print(cp, len, (const u_char *)ip, (off & 0x3fff)); break; -#ifndef IPPROTO_IGRP -#define IPPROTO_IGRP 9 -#endif case IPPROTO_IGRP: igrp_print(cp, len, (const u_char *)ip); break; @@ -457,152 +551,107 @@ ip_print(register const u_char *bp, register u_int length) break; case IPPROTO_EGP: - egp_print(cp, len, (const u_char *)ip); + egp_print(cp); break; -#ifndef IPPROTO_OSPF -#define IPPROTO_OSPF 89 -#endif case IPPROTO_OSPF: ospf_print(cp, len, (const u_char *)ip); break; -#ifndef IPPROTO_IGMP -#define IPPROTO_IGMP 2 -#endif case IPPROTO_IGMP: - igmp_print(cp, len, (const u_char *)ip); + igmp_print(cp, len); break; - case 4: + case IPPROTO_IPV4: /* 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; #ifdef INET6 -#ifndef IP6PROTO_ENCAP -#define IP6PROTO_ENCAP 41 -#endif - case IP6PROTO_ENCAP: + case IPPROTO_IPV6: /* 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*/ + case IPPROTO_RSVP: + rsvp_print(cp, len); + break; -#ifndef IPPROTO_GRE -#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; case IPPROTO_PIM: pim_print(cp, len); break; + case IPPROTO_VRRP: + 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); + if ((proto = getprotobynumber(nh)) != NULL) + (void)printf(" %s", proto->p_name); + else + (void)printf(" ip-proto-%d", nh); + printf(" %d", len); break; } + } else { + /* Ultra quiet now means that all this stuff should be suppressed */ + if (qflag > 1) return; + + /* + * if this isn't the first frag, we're missing the + * next level protocol header. print the ip addr + * and the protocol. + */ + if (off & 0x1fff) { + (void)printf("%s > %s:", ipaddr_string(&ip->ip_src), + ipaddr_string(&ip->ip_dst)); + if ((proto = getprotobynumber(ip->ip_p)) != NULL) + (void)printf(" %s", proto->p_name); + else + (void)printf(" ip-proto-%d", ip->ip_p); + } } - /* - * for fragmented datagrams, print id:size@offset. On all - * but the last stick a "+". For unfragmented datagrams, note - * the don't fragment flag. - */ - if (off & 0x3fff) { - /* - * if this isn't the first frag, we're missing the - * next level protocol header. print the ip addr. - */ - if (off & 0x1fff) - (void)printf("%s > %s:", ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); - (void)printf(" (frag %d:%d@%d%s)", ntohs(ip->ip_id), len, - (off & 0x1fff) * 8, - (off & IP_MF)? "+" : ""); - } else if (off & IP_DF) - (void)printf(" (DF)"); - - if (ip->ip_tos) - (void)printf(" [tos 0x%x]", (int)ip->ip_tos); - if (ip->ip_ttl <= 1) - (void)printf(" [ttl %d]", (int)ip->ip_ttl); - - if (vflag) { - int sum; - char *sep = ""; - - printf(" ("); - if (ip->ip_ttl > 1) { - (void)printf("%sttl %d", sep, (int)ip->ip_ttl); - sep = ", "; - } - if ((off & 0x3fff) == 0) { - (void)printf("%sid %d", sep, (int)ntohs(ip->ip_id)); - sep = ", "; - } - if ((u_char *)ip + hlen <= snapend) { - sum = in_cksum(ip); - if (sum != 0) { - (void)printf("%sbad cksum %x!", sep, - ntohs(ip->ip_sum)); - sep = ", "; - } - } - if ((hlen -= sizeof(struct ip)) > 0) { - (void)printf("%soptlen=%d", sep, hlen); - ip_optprint((u_char *)(ip + 1), hlen); - } - printf(")"); +} + +void +ipN_print(register const u_char *bp, register u_int length) +{ + struct ip *ip, hdr; + + ip = (struct ip *)bp; + if (length < 4) { + (void)printf("truncated-ip %d", length); + return; + } + memcpy (&hdr, (char *)ip, 4); + switch (IP_V(&hdr)) { + case 4: + ip_print (bp, length); + return; +#ifdef INET6 + case 6: + ip6_print (bp, length); + return; +#endif + default: + (void)printf("unknown ip %d", IP_V(&hdr)); + return; } } + + + diff --git a/kame/kame/tcpdump/print-ip6.c b/kame/kame/tcpdump/print-ip6.c index 2f57656eca..948e020bda 100644 --- a/kame/kame/tcpdump/print-ip6.c +++ b/kame/kame/tcpdump/print-ip6.c @@ -20,165 +20,163 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) /master/usr.sbin/tcpdump/tcpdump/print-ip.c,v 2.1 1995/02/03 18:14:45 polk Exp (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-ip6.c,v 1.32.2.8 2003/11/24 20:31:22 guy Exp $"; #endif -#ifdef INET6 +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include -#include -#include -#include +#ifdef INET6 -#include -#include -#include -#include -#include -#include -#include +#include #include -#ifdef __STDC__ #include -#endif -#include +#include #include "interface.h" #include "addrtoname.h" +#include "extract.h" -#include +#include "ip6.h" +#include "ipproto.h" /* * 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 hlen; - register int len; + register int advance; + u_int len; + const u_char *ipend; register const u_char *cp; + register u_int payload_len; int nh; + int fragmented = 0; u_int flow; - + ip6 = (const struct ip6_hdr *)bp; -#ifdef TCPDUMP_ALIGN - /* - * The IP header is not word aligned, so copy into abuf. - * This will never happen with BPF. It does happen raw packet - * dumps from -r. - */ - if ((int)ip & (sizeof(long)-1)) { - static u_char *abuf; - - if (abuf == 0) - abuf = (u_char *)malloc(snaplen); - bcopy((char *)ip, (char *)abuf, min(length, snaplen)); - snapend += abuf - (u_char *)ip; - packetp = abuf; - ip = (struct ip6_hdr *)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; } - hlen = sizeof(struct ip6_hdr); - len = ntohs(ip6->ip6_plen); - if (length < len + hlen) + payload_len = EXTRACT_16BITS(&ip6->ip6_plen); + len = payload_len + sizeof(struct ip6_hdr); + if (length < len) (void)printf("truncated-ip6 - %d bytes missing!", - len + hlen - length); + len - length); + + /* + * Cut off the snapshot length to the end of the IP payload. + */ + ipend = bp + len; + if (ipend < snapend) + snapend = ipend; cp = (const u_char *)ip6; + advance = sizeof(struct ip6_hdr); nh = ip6->ip6_nxt; - while (cp < snapend) { - cp += hlen; + while (cp < snapend && advance > 0) { + cp += advance; + len -= advance; - if (cp == (u_char *)(ip6 + 1) - && nh != IPPROTO_TCP && nh != IPPROTO_UDP) { + if (cp == (const u_char *)(ip6 + 1) && + nh != IPPROTO_TCP && nh != IPPROTO_UDP && + nh != IPPROTO_SCTP) { (void)printf("%s > %s: ", ip6addr_string(&ip6->ip6_src), ip6addr_string(&ip6->ip6_dst)); } switch (nh) { case IPPROTO_HOPOPTS: - hlen = hbhopt_print(cp); + advance = hbhopt_print(cp); nh = *cp; break; case IPPROTO_DSTOPTS: - hlen = dstopt_print(cp); + advance = dstopt_print(cp); nh = *cp; break; case IPPROTO_FRAGMENT: - frag6_print(cp, (const u_char *)ip6); - hlen = 8; + advance = frag6_print(cp, (const u_char *)ip6); + if (snapend <= cp + advance) + goto end; nh = *cp; + fragmented = 1; break; + + case IPPROTO_MOBILITY_OLD: + case IPPROTO_MOBILITY: + /* + * XXX - we don't use "advance"; the current + * "Mobility Support in IPv6" draft + * (draft-ietf-mobileip-ipv6-24) says that + * the next header field in a mobility header + * should be IPPROTO_NONE, but speaks of + * the possiblity of a future extension in + * which payload can be piggybacked atop a + * mobility header. + */ + advance = mobility_print(cp, (const u_char *)ip6); + nh = *cp; + goto end; case IPPROTO_ROUTING: - hlen = rt6_print(cp, (const u_char *)ip6); + advance = rt6_print(cp, (const u_char *)ip6); nh = *cp; break; + case IPPROTO_SCTP: + sctp_print(cp, (const u_char *)ip6, len); + goto end; case IPPROTO_TCP: - tcp_print(cp, len, (const u_char *)ip6); + tcp_print(cp, len, (const u_char *)ip6, fragmented); goto end; case IPPROTO_UDP: - udp_print(cp, len, (const u_char *)ip6); + udp_print(cp, len, (const u_char *)ip6, fragmented); goto end; case IPPROTO_ICMPV6: - icmp6_print(cp, (const u_char *)ip6); + icmp6_print(cp, len, (const u_char *)ip6, fragmented); goto end; case IPPROTO_AH: - hlen = ah_print(cp, (const u_char *)ip6); + advance = ah_print(cp); nh = *cp; break; case IPPROTO_ESP: { - int enh; - cp += esp_print(cp, (const u_char *)ip6, &enh); - if (enh < 0) - goto end; + int enh, padlen; + advance = esp_print(cp, (const u_char *)ip6, &enh, &padlen); nh = enh & 0xff; + len -= padlen; break; } -#ifndef IPPROTO_IPCOMP -#define IPPROTO_IPCOMP 108 -#endif case IPPROTO_IPCOMP: { int enh; - cp += ipcomp_print(cp, (const u_char *)ip6, &enh); - if (enh < 0) - goto end; + advance = ipcomp_print(cp, &enh); nh = enh & 0xff; break; } + case IPPROTO_PIM: - (void)printf("PIM"); pim_print(cp, len); goto end; -#ifndef IPPROTO_OSPF -#define IPPROTO_OSPF 89 -#endif case IPPROTO_OSPF: ospf6_print(cp, len); goto end; + case IPPROTO_IPV6: ip6_print(cp, len); goto end; -#ifndef IPPROTO_IPV4 -#define IPPROTO_IPV4 4 -#endif + case IPPROTO_IPV4: ip_print(cp, len); goto end; + case IPPROTO_NONE: (void)printf("no next header"); goto end; @@ -190,8 +188,8 @@ ip6_print(register const u_char *bp, register int length) } end: - - flow = ntohl(ip6->ip6_flow); + + flow = EXTRACT_32BITS(&ip6->ip6_flow); #if 0 /* rfc1883 */ if (flow & 0x0f000000) @@ -206,13 +204,19 @@ ip6_print(register const u_char *bp, register int length) (void)printf(" [flowlabel 0x%x]", flow & 0x000fffff); #endif + if (ip6->ip6_hlim <= 1) + (void)printf(" [hlim %u]", ip6->ip6_hlim); + if (vflag) { printf(" ("); - (void)printf("len %d", len); + (void)printf("len %u", payload_len); if (ip6->ip6_hlim > 1) (void)printf(", hlim %d", (int)ip6->ip6_hlim); printf(")"); } + return; +trunc: + (void)printf("[|ip6]"); } #endif /* INET6 */ diff --git a/kame/kame/tcpdump/print-ip6opts.c b/kame/kame/tcpdump/print-ip6opts.c index 0c02a5c887..a6960b8651 100644 --- a/kame/kame/tcpdump/print-ip6opts.c +++ b/kame/kame/tcpdump/print-ip6opts.c @@ -1,7 +1,7 @@ /* * Copyright (C) 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: @@ -13,7 +13,7 @@ * 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 @@ -27,39 +27,144 @@ * SUCH DAMAGE. */ -#ifdef INET6 -#include -#include -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-ip6opts.c,v 1.14.2.3 2003/11/19 00:35:44 guy Exp $"; +#endif -#include -#include +#ifdef INET6 +#include #include +#include "ip6.h" + #include "interface.h" #include "addrtoname.h" +#include "extract.h" -void -ip6_opt_print(const u_char *bp, int len) +/* items outside of rfc2292bis */ +#ifndef IP6OPT_MINLEN +#define IP6OPT_MINLEN 2 +#endif +#ifndef IP6OPT_RTALERT_LEN +#define IP6OPT_RTALERT_LEN 4 +#endif +#ifndef IP6OPT_JUMBO_LEN +#define IP6OPT_JUMBO_LEN 6 +#endif +#define IP6OPT_HOMEADDR_MINLEN 18 +#define IP6OPT_BU_MINLEN 10 +#define IP6OPT_BA_MINLEN 13 +#define IP6OPT_BR_MINLEN 2 +#define IP6SOPT_UI 0x2 +#define IP6SOPT_UI_MINLEN 4 +#define IP6SOPT_ALTCOA 0x3 +#define IP6SOPT_ALTCOA_MINLEN 18 +#define IP6SOPT_AUTH 0x4 +#define IP6SOPT_AUTH_MINLEN 6 + +static void ip6_sopt_print(const u_char *, int); + +static void +ip6_sopt_print(const u_char *bp, int len) { int i; 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"); + break; + case IP6OPT_PADN: + if (len - i < IP6OPT_MINLEN) { + printf(", padn: trunc"); + goto trunc; + } + printf(", padn"); + break; + case IP6SOPT_UI: + if (len - i < IP6SOPT_UI_MINLEN) { + printf(", ui: trunc"); + goto trunc; + } + printf(", ui: 0x%04x ", EXTRACT_16BITS(&bp[i + 2])); + break; + case IP6SOPT_ALTCOA: + if (len - i < IP6SOPT_ALTCOA_MINLEN) { + printf(", altcoa: trunc"); + goto trunc; + } + printf(", alt-CoA: %s", ip6addr_string(&bp[i+2])); + break; + case IP6SOPT_AUTH: + if (len - i < IP6SOPT_AUTH_MINLEN) { + printf(", auth: trunc"); + goto trunc; + } + printf(", auth spi: 0x%08x", EXTRACT_32BITS(&bp[i + 2])); + break; + default: + if (len - i < IP6OPT_MINLEN) { + printf(", sopt_type %d: trunc)", bp[i]); + goto trunc; + } + printf(", sopt_type 0x%02x: len=%d", bp[i], bp[i + 1]); + break; + } + } + return; + +trunc: + printf("[trunc] "); +} + +void +ip6_opt_print(const u_char *bp, int len) +{ + int i; + int optlen = 0; + + 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)"); break; case IP6OPT_PADN: if (len - i < IP6OPT_MINLEN) { printf("(padn: trunc)"); goto trunc; } - optlen = bp[i + 1] + 2; + printf("(padn)"); break; - case IP6OPT_RTALERT: + case IP6OPT_ROUTER_ALERT: if (len - i < IP6OPT_RTALERT_LEN) { printf("(rtalert: trunc)"); goto trunc; @@ -68,8 +173,7 @@ ip6_opt_print(const u_char *bp, int len) printf("(rtalert: invalid len %d)", bp[i + 1]); goto trunc; } - printf("(rtalert: 0x%04x) ", ntohs(*(u_short *)&bp[i + 2])); - optlen = IP6OPT_RTALERT_LEN; + printf("(rtalert: 0x%04x) ", EXTRACT_16BITS(&bp[i + 2])); break; case IP6OPT_JUMBO: if (len - i < IP6OPT_JUMBO_LEN) { @@ -80,16 +184,94 @@ ip6_opt_print(const u_char *bp, int len) printf("(jumbo: invalid len %d)", bp[i + 1]); goto trunc; } - printf("(jumbo: %u) ", (u_int32_t)ntohl(*(u_int *)&bp[i + 2])); - optlen = IP6OPT_JUMBO_LEN; + printf("(jumbo: %u) ", EXTRACT_32BITS(&bp[i + 2])); + break; + case IP6OPT_HOME_ADDRESS: + if (len - i < IP6OPT_HOMEADDR_MINLEN) { + printf("(homeaddr: trunc)"); + goto trunc; + } + if (bp[i + 1] < IP6OPT_HOMEADDR_MINLEN - 2) { + printf("(homeaddr: invalid len %d)", bp[i + 1]); + goto trunc; + } + 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)); + } + printf(")"); + break; + case IP6OPT_BINDING_UPDATE: + if (len - i < IP6OPT_BU_MINLEN) { + printf("(bu: trunc)"); + goto trunc; + } + if (bp[i + 1] < IP6OPT_BU_MINLEN - 2) { + printf("(bu: invalid len %d)", bp[i + 1]); + goto trunc; + } + printf("(bu: "); + if (bp[i + 2] & 0x80) + printf("A"); + if (bp[i + 2] & 0x40) + printf("H"); + if (bp[i + 2] & 0x20) + printf("S"); + if (bp[i + 2] & 0x10) + printf("D"); + if ((bp[i + 2] & 0x0f) || bp[i + 3] || bp[i + 4]) + printf("res"); + printf(", sequence: %u", bp[i + 5]); + printf(", lifetime: %u", EXTRACT_32BITS(&bp[i + 6])); + + if (bp[i + 1] > IP6OPT_BU_MINLEN - 2) { + ip6_sopt_print(&bp[i + IP6OPT_BU_MINLEN], + (optlen - IP6OPT_BU_MINLEN)); + } + printf(")"); + break; + case IP6OPT_BINDING_ACK: + if (len - i < IP6OPT_BA_MINLEN) { + printf("(ba: trunc)"); + goto trunc; + } + if (bp[i + 1] < IP6OPT_BA_MINLEN - 2) { + printf("(ba: invalid len %d)", bp[i + 1]); + goto trunc; + } + printf("(ba: "); + printf("status: %u", bp[i + 2]); + if (bp[i + 3]) + printf("res"); + printf(", sequence: %u", bp[i + 4]); + printf(", lifetime: %u", EXTRACT_32BITS(&bp[i + 5])); + printf(", refresh: %u", EXTRACT_32BITS(&bp[i + 9])); + + if (bp[i + 1] > IP6OPT_BA_MINLEN - 2) { + ip6_sopt_print(&bp[i + IP6OPT_BA_MINLEN], + (optlen - IP6OPT_BA_MINLEN)); + } + printf(")"); + break; + case IP6OPT_BINDING_REQ: + if (len - i < IP6OPT_BR_MINLEN) { + printf("(br: trunc)"); + goto trunc; + } + printf("(br"); + if (bp[i + 1] > IP6OPT_BR_MINLEN - 2) { + ip6_sopt_print(&bp[i + IP6OPT_BR_MINLEN], + (optlen - IP6OPT_BR_MINLEN)); + } + printf(")"); break; default: if (len - i < IP6OPT_MINLEN) { printf("(type %d: trunc)", bp[i]); goto trunc; } - printf("(type 0x%02x: len=%d) ", bp[i], bp[i + 1]); - optlen = bp[i + 1] + 2; + printf("(opt_type 0x%02x: len=%d) ", bp[i], bp[i + 1]); break; } } @@ -106,14 +288,15 @@ ip6_opt_print(const u_char *bp, int len) int hbhopt_print(register const u_char *bp) { - register const struct ip6_hbh *dp = (struct ip6_hbh *)bp; + const struct ip6_hbh *dp = (struct ip6_hbh *)bp; register const u_char *ep; int hbhlen = 0; - /* 'ep' points to the end of avaible data. */ + /* 'ep' points to the end of available data. */ ep = snapend; TCHECK(dp->ip6h_len); hbhlen = (int)((dp->ip6h_len + 1) << 3); + TCHECK2(*dp, hbhlen); printf("HBH "); if (vflag) ip6_opt_print((const u_char *)dp + sizeof(*dp), hbhlen - sizeof(*dp)); @@ -122,20 +305,21 @@ hbhopt_print(register const u_char *bp) trunc: fputs("[|HBH]", stdout); - return(hbhlen); + return(-1); } int dstopt_print(register const u_char *bp) { - register const struct ip6_dest *dp = (struct ip6_dest *)bp; + const struct ip6_dest *dp = (struct ip6_dest *)bp; register const u_char *ep; int dstoptlen = 0; - /* 'ep' points to the end of avaible data. */ + /* 'ep' points to the end of available data. */ ep = snapend; TCHECK(dp->ip6d_len); dstoptlen = (int)((dp->ip6d_len + 1) << 3); + TCHECK2(*dp, dstoptlen); printf("DSTOPT "); if (vflag) { ip6_opt_print((const u_char *)dp + sizeof(*dp), @@ -146,6 +330,6 @@ dstopt_print(register const u_char *bp) trunc: fputs("[|DSTOPT]", stdout); - return(dstoptlen); + return(-1); } #endif /* INET6 */ diff --git a/kame/kame/tcpdump/print-ipcomp.c b/kame/kame/tcpdump/print-ipcomp.c index ed2f49d07e..7a3c1baf3a 100644 --- a/kame/kame/tcpdump/print-ipcomp.c +++ b/kame/kame/tcpdump/print-ipcomp.c @@ -20,43 +20,24 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) /master/usr.sbin/tcpdump/tcpdump/print-icmp.c,v 2.1 1995/02/03 18:14:42 polk Exp (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-ipcomp.c,v 1.17.2.3 2003/11/19 00:35:45 guy Exp $"; #endif -#include -#include -#include -#include -#include - -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include -#ifdef INET6 -#include -#endif -#ifdef HAVE_NETINET6_IPCOMP_H -#include -#else struct ipcomp { u_int8_t comp_nxt; /* Next Header */ u_int8_t comp_flags; /* Length of data, in 32bit */ u_int16_t comp_cpi; /* Compression parameter index */ }; -#endif #if defined(HAVE_LIBZ) && defined(HAVE_ZLIB_H) #include @@ -64,9 +45,10 @@ struct ipcomp { #include "interface.h" #include "addrtoname.h" +#include "extract.h" int -ipcomp_print(register const u_char *bp, register const u_char *bp2, int *nhdr) +ipcomp_print(register const u_char *bp, int *nhdr _U_) { register const struct ipcomp *ipcomp; register const u_char *ep; @@ -76,16 +58,16 @@ ipcomp_print(register const u_char *bp, register const u_char *bp2, int *nhdr) #endif ipcomp = (struct ipcomp *)bp; - cpi = (u_int16_t)ntohs(ipcomp->comp_cpi); + cpi = EXTRACT_16BITS(&ipcomp->comp_cpi); - /* 'ep' points to the end of avaible data. */ + /* 'ep' points to the end of available data. */ ep = snapend; if ((u_char *)(ipcomp + 1) >= ep - sizeof(struct ipcomp)) { fputs("[|IPCOMP]", stdout); goto fail; } - printf("IPComp(cpi=%u)", cpi); + printf("IPComp(cpi=0x%04x)", cpi); #if defined(HAVE_LIBZ) && defined(HAVE_ZLIB_H) if (1) @@ -105,7 +87,5 @@ ipcomp_print(register const u_char *bp, register const u_char *bp2, int *nhdr) #endif fail: - if (nhdr) - *nhdr = -1; - return 65536; + return -1; } diff --git a/kame/kame/tcpdump/print-ipfc.c b/kame/kame/tcpdump/print-ipfc.c new file mode 100644 index 0000000000..1262ecf2d4 --- /dev/null +++ b/kame/kame/tcpdump/print-ipfc.c @@ -0,0 +1,137 @@ +/* + * Copyright (c) 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. + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-ipfc.c,v 1.4.2.2 2003/11/16 08:51:28 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "ethertype.h" + +#include "ether.h" +#include "ipfc.h" + +/* + * RFC 2625 IP-over-Fibre Channel. + */ + +/* Extract src, dst addresses */ +static inline void +extract_ipfc_addrs(const struct ipfc_header *ipfcp, char *ipfcsrc, + char *ipfcdst) +{ + /* + * We assume that, as per RFC 2625, the lower 48 bits of the + * source and destination addresses are MAC addresses. + */ + memcpy(ipfcdst, (const char *)&ipfcp->ipfc_dhost[2], 6); + memcpy(ipfcsrc, (const char *)&ipfcp->ipfc_shost[2], 6); +} + +/* + * Print the Network_Header + */ +static inline void +ipfc_hdr_print(register const struct ipfc_header *ipfcp _U_, + register u_int length, register const u_char *ipfcsrc, + register const u_char *ipfcdst) +{ + const char *srcname, *dstname; + + srcname = etheraddr_string(ipfcsrc); + dstname = etheraddr_string(ipfcdst); + + /* + * XXX - show the upper 16 bits? Do so only if "vflag" is set? + */ + (void) printf("%s %s %d: ", srcname, dstname, length); +} + +static void +ipfc_print(const u_char *p, u_int length, u_int caplen) +{ + const struct ipfc_header *ipfcp = (const struct ipfc_header *)p; + struct ether_header ehdr; + u_short extracted_ethertype; + + if (caplen < IPFC_HDRLEN) { + printf("[|ipfc]"); + return; + } + /* + * Get the network addresses into a canonical form + */ + extract_ipfc_addrs(ipfcp, (char *)ESRC(&ehdr), (char *)EDST(&ehdr)); + + if (eflag) + ipfc_hdr_print(ipfcp, length, ESRC(&ehdr), EDST(&ehdr)); + + /* Skip over Network_Header */ + length -= IPFC_HDRLEN; + p += IPFC_HDRLEN; + caplen -= IPFC_HDRLEN; + + /* Frame Control field determines interpretation of packet */ + extracted_ethertype = 0; + /* Try to print the LLC-layer header & higher layers */ + if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr), + &extracted_ethertype) == 0) { + /* + * Some kinds of LLC packet we cannot + * handle intelligently + */ + if (!eflag) + ipfc_hdr_print(ipfcp, length + IPFC_HDRLEN, + ESRC(&ehdr), EDST(&ehdr)); + if (extracted_ethertype) { + printf("(LLC %s) ", + etherproto_string(htons(extracted_ethertype))); + } + if (!xflag && !qflag) + default_print(p, caplen); + } +} + +/* + * This is the top level routine of the printer. 'p' points + * to the Network_Header of the packet, 'h->ts' is the timestamp, + * 'h->length' is the length of the packet off the wire, and 'h->caplen' + * is the number of bytes actually captured. + */ +u_int +ipfc_if_print(const struct pcap_pkthdr *h, register const u_char *p) +{ + ipfc_print(p, h->len, h->caplen); + + return (IPFC_HDRLEN); +} diff --git a/kame/kame/tcpdump/print-ipx.c b/kame/kame/tcpdump/print-ipx.c index d92adb2f22..f7b522adc8 100644 --- a/kame/kame/tcpdump/print-ipx.c +++ b/kame/kame/tcpdump/print-ipx.c @@ -23,25 +23,17 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-ipx.c,v 1.19 96/12/10 23:23:52 leres Exp $"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-ipx.c,v 1.34.2.2 2003/11/16 08:51:28 guy Exp $"; #endif -#include -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include -#include -#include -#include -#include -#include -#include +#include -#ifdef __STDC__ #include -#endif #include #include @@ -65,11 +57,11 @@ ipx_print(const u_char *p, u_int length) const struct ipxHdr *ipx = (const struct ipxHdr *)p; TCHECK(ipx->srcSkt); - (void)printf("%s.%x > ", + (void)printf("%s.%04x > ", ipxaddr_string(EXTRACT_32BITS(ipx->srcNet), ipx->srcNode), EXTRACT_16BITS(&ipx->srcSkt)); - (void)printf("%s.%x:", + (void)printf("%s.%04x:", ipxaddr_string(EXTRACT_32BITS(ipx->dstNet), ipx->dstNode), EXTRACT_16BITS(&ipx->dstSkt)); @@ -88,7 +80,7 @@ ipxaddr_string(u_int32_t net, const u_char *node) { static char line[256]; - sprintf(line, "%x.%02x:%02x:%02x:%02x:%02x:%02x", + snprintf(line, sizeof(line), "%08x.%02x:%02x:%02x:%02x:%02x:%02x", net, node[0], node[1], node[2], node[3], node[4], node[5]); return line; @@ -112,10 +104,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; @@ -140,12 +144,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(" %s", ipxsap_string(htons(EXTRACT_16BITS(&ipx[0])))); break; case 2: @@ -156,8 +156,8 @@ 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); - (void)printf(" %x '", EXTRACT_16BITS(&ipx[0])); + TCHECK2(ipx[25], 10); + (void)printf(" %s '", ipxsap_string(htons(EXTRACT_16BITS(&ipx[0])))); fn_print((u_char *)&ipx[1], (u_char *)&ipx[1] + 48); printf("' addr %s", ipxaddr_string(EXTRACT_32BITS(&ipx[25]), (u_char *)&ipx[27])); @@ -166,12 +166,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 @@ -205,10 +205,10 @@ 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/kame/kame/tcpdump/print-isakmp.c b/kame/kame/tcpdump/print-isakmp.c index 20a22c0adf..d5caa739db 100644 --- a/kame/kame/tcpdump/print-isakmp.c +++ b/kame/kame/tcpdump/print-isakmp.c @@ -1,7 +1,7 @@ /* * 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: @@ -13,7 +13,7 @@ * 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 @@ -29,37 +29,19 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvsroot/hydrangea-freebsd/kit/src/tcpdump/Attic/print-isakmp.c,v 1.1.2.18.2.12 1999/06/13 18:39:02 itojun Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-isakmp.c,v 1.36.2.11 2004/03/24 01:32:42 guy Exp $ (LBL)"; #endif -#include -#include -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include -#ifdef INET6 -#include -#endif +#include #include -#include #include "isakmp.h" #include "ipsec_doi.h" @@ -68,31 +50,47 @@ struct rtentry; #include "addrtoname.h" #include "extract.h" /* must come after interface.h */ -static u_char *isakmp_sa_print __P((struct isakmp_gen *, u_char *, u_int32_t, - u_int32_t, u_int32_t)); -static u_char *isakmp_p_print __P((struct isakmp_gen *, u_char *, u_int32_t, - u_int32_t, u_int32_t)); -static u_char *isakmp_t_print __P((struct isakmp_gen *, u_char *, u_int32_t, - u_int32_t, u_int32_t)); -static u_char *isakmp_ke_print __P((struct isakmp_gen *, u_char *, u_int32_t, - u_int32_t, u_int32_t)); -static u_char *isakmp_id_print __P((struct isakmp_gen *, u_char *, u_int32_t, - u_int32_t, u_int32_t)); -static u_char *isakmp_hash_print __P((struct isakmp_gen *, u_char *, - u_int32_t, u_int32_t, u_int32_t)); -static u_char *isakmp_nonce_print __P((struct isakmp_gen *, u_char *, - u_int32_t, u_int32_t, u_int32_t)); -static u_char *isakmp_n_print __P((struct isakmp_gen *, u_char *, u_int32_t, - u_int32_t, u_int32_t)); -static u_char *isakmp_d_print __P((struct isakmp_gen *, u_char *, u_int32_t, - u_int32_t, u_int32_t)); -static u_char *isakmp_vid_print __P((struct isakmp_gen *, u_char *, u_int32_t, - u_int32_t, u_int32_t)); -static u_char *isakmp_sub0_print __P((u_char, struct isakmp_gen *, u_char *, - u_int32_t, u_int32_t, u_int32_t)); -static u_char *isakmp_sub_print __P((u_char, struct isakmp_gen *, u_char *, - u_int32_t, u_int32_t, u_int32_t)); -static char *numstr __P((int)); +#include "ip.h" +#ifdef INET6 +#include "ip6.h" +#endif + +#ifndef HAVE_SOCKADDR_STORAGE +#define sockaddr_storage sockaddr +#endif + +static const u_char *isakmp_sa_print(const struct isakmp_gen *, + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int); +static const u_char *isakmp_p_print(const struct isakmp_gen *, + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int); +static const u_char *isakmp_t_print(const struct isakmp_gen *, + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int); +static const u_char *isakmp_ke_print(const struct isakmp_gen *, + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int); +static const u_char *isakmp_id_print(const struct isakmp_gen *, + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int); +static const u_char *isakmp_cert_print(const struct isakmp_gen *, + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int); +static const u_char *isakmp_cr_print(const struct isakmp_gen *, + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int); +static const u_char *isakmp_sig_print(const struct isakmp_gen *, + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int); +static const u_char *isakmp_hash_print(const struct isakmp_gen *, + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int); +static const u_char *isakmp_nonce_print(const struct isakmp_gen *, + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int); +static const u_char *isakmp_n_print(const struct isakmp_gen *, + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int); +static const u_char *isakmp_d_print(const struct isakmp_gen *, + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int); +static const u_char *isakmp_vid_print(const struct isakmp_gen *, + u_int, const u_char *, u_int32_t, u_int32_t, u_int32_t, int); +static const u_char *isakmp_sub0_print(u_char, const struct isakmp_gen *, + const u_char *, u_int32_t, u_int32_t, u_int32_t, int); +static const u_char *isakmp_sub_print(u_char, const struct isakmp_gen *, + const u_char *, u_int32_t, u_int32_t, u_int32_t, int); +static char *numstr(int); +static void safememcpy(void *, const void *, size_t); #define MAXINITIATORS 20 int ninitiator = 0; @@ -103,29 +101,29 @@ struct { } cookiecache[MAXINITIATORS]; /* protocol id */ -static char *protoidstr[] = { +static const char *protoidstr[] = { NULL, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp", }; /* isakmp->np */ -static char *npstr[] = { +static const char *npstr[] = { "none", "sa", "p", "t", "ke", "id", "cert", "cr", "hash", "sig", "nonce", "n", "d", "vid" }; /* isakmp->np */ -static u_char *(*npfunc[]) __P((struct isakmp_gen *, u_char *, u_int32_t, - u_int32_t, u_int32_t)) = { +static const u_char *(*npfunc[])(const struct isakmp_gen *, u_int, + const u_char *, u_int32_t, u_int32_t, u_int32_t, int) = { NULL, isakmp_sa_print, isakmp_p_print, isakmp_t_print, isakmp_ke_print, isakmp_id_print, - NULL, - NULL, + isakmp_cert_print, + isakmp_cr_print, isakmp_hash_print, - NULL, + isakmp_sig_print, isakmp_nonce_print, isakmp_n_print, isakmp_d_print, @@ -133,7 +131,7 @@ static u_char *(*npfunc[]) __P((struct isakmp_gen *, u_char *, u_int32_t, }; /* isakmp->etype */ -static char *etypestr[] = { +static const char *etypestr[] = { "none", "base", "ident", "auth", "agg", "inf", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, @@ -194,7 +192,7 @@ cookie_record(cookie_t *in, const u_char *bp2) } ip = (struct ip *)bp2; - switch (ip->ip_v) { + switch (IP_V(ip)) { case 4: memset(&cookiecache[ninitiator].iaddr, 0, sizeof(cookiecache[ninitiator].iaddr)); @@ -202,11 +200,15 @@ cookie_record(cookie_t *in, const u_char *bp2) sizeof(cookiecache[ninitiator].raddr)); sin = (struct sockaddr_in *)&cookiecache[ninitiator].iaddr; +#ifdef HAVE_SOCKADDR_SA_LEN sin->sin_len = sizeof(struct sockaddr_in); +#endif sin->sin_family = AF_INET; memcpy(&sin->sin_addr, &ip->ip_src, sizeof(ip->ip_src)); sin = (struct sockaddr_in *)&cookiecache[ninitiator].raddr; +#ifdef HAVE_SOCKADDR_SA_LEN sin->sin_len = sizeof(struct sockaddr_in); +#endif sin->sin_family = AF_INET; memcpy(&sin->sin_addr, &ip->ip_dst, sizeof(ip->ip_dst)); break; @@ -219,11 +221,15 @@ cookie_record(cookie_t *in, const u_char *bp2) ip6 = (struct ip6_hdr *)bp2; sin6 = (struct sockaddr_in6 *)&cookiecache[ninitiator].iaddr; +#ifdef HAVE_SOCKADDR_SA_LEN sin6->sin6_len = sizeof(struct sockaddr_in6); +#endif sin6->sin6_family = AF_INET6; memcpy(&sin6->sin6_addr, &ip6->ip6_src, sizeof(ip6->ip6_src)); sin6 = (struct sockaddr_in6 *)&cookiecache[ninitiator].raddr; +#ifdef HAVE_SOCKADDR_SA_LEN sin6->sin6_len = sizeof(struct sockaddr_in6); +#endif sin6->sin6_family = AF_INET6; memcpy(&sin6->sin6_addr, &ip6->ip6_dst, sizeof(ip6->ip6_dst)); break; @@ -241,19 +247,23 @@ static int cookie_sidecheck(int i, const u_char *bp2, int initiator) { struct sockaddr_storage ss; + struct sockaddr *sa; struct ip *ip; struct sockaddr_in *sin; #ifdef INET6 struct ip6_hdr *ip6; struct sockaddr_in6 *sin6; #endif + int salen; memset(&ss, 0, sizeof(ss)); ip = (struct ip *)bp2; - switch (ip->ip_v) { + switch (IP_V(ip)) { case 4: sin = (struct sockaddr_in *)&ss; +#ifdef HAVE_SOCKADDR_SA_LEN sin->sin_len = sizeof(struct sockaddr_in); +#endif sin->sin_family = AF_INET; memcpy(&sin->sin_addr, &ip->ip_src, sizeof(ip->ip_src)); break; @@ -261,7 +271,9 @@ cookie_sidecheck(int i, const u_char *bp2, int initiator) case 6: ip6 = (struct ip6_hdr *)bp2; sin6 = (struct sockaddr_in6 *)&ss; +#ifdef HAVE_SOCKADDR_SA_LEN sin6->sin6_len = sizeof(struct sockaddr_in6); +#endif sin6->sin6_family = AF_INET6; memcpy(&sin6->sin6_addr, &ip6->ip6_src, sizeof(ip6->ip6_src)); break; @@ -270,270 +282,325 @@ cookie_sidecheck(int i, const u_char *bp2, int initiator) return 0; } + sa = (struct sockaddr *)&ss; if (initiator) { - if (ss.__ss_family != cookiecache[i].iaddr.__ss_family) - return 0; - if (ss.__ss_len != cookiecache[i].iaddr.__ss_len) + if (sa->sa_family != ((struct sockaddr *)&cookiecache[i].iaddr)->sa_family) return 0; - if (memcmp(&ss, &cookiecache[i].iaddr, ss.__ss_len) == 0) +#ifdef HAVE_SOCKADDR_SA_LEN + salen = sa->sa_len; +#else +#ifdef INET6 + if (sa->sa_family == AF_INET6) + salen = sizeof(struct sockaddr_in6); + else + salen = sizeof(struct sockaddr); +#else + salen = sizeof(struct sockaddr); +#endif +#endif + if (memcmp(&ss, &cookiecache[i].iaddr, salen) == 0) return 1; } else { - if (ss.__ss_family != cookiecache[i].raddr.__ss_family) - return 0; - if (ss.__ss_len != cookiecache[i].raddr.__ss_len) + if (sa->sa_family != ((struct sockaddr *)&cookiecache[i].raddr)->sa_family) return 0; - if (memcmp(&ss, &cookiecache[i].raddr, ss.__ss_len) == 0) +#ifdef HAVE_SOCKADDR_SA_LEN + salen = sa->sa_len; +#else +#ifdef INET6 + if (sa->sa_family == AF_INET6) + salen = sizeof(struct sockaddr_in6); + else + salen = sizeof(struct sockaddr); +#else + salen = sizeof(struct sockaddr); +#endif +#endif + if (memcmp(&ss, &cookiecache[i].raddr, salen) == 0) return 1; } return 0; } -static void +static int rawprint(caddr_t loc, size_t len) { static u_char *p; - int i; + size_t i; + TCHECK2(*loc, len); + p = (u_char *)loc; for (i = 0; i < len; i++) printf("%02x", p[i] & 0xff); + return 1; +trunc: + return 0; } struct attrmap { - u_char *type; - int nvalue; - u_char *value[30]; /*XXX*/ + const char *type; + u_int nvalue; + const char *value[30]; /*XXX*/ }; -static u_char * -isakmp_attrmap_print(u_char *p, u_char *ep, struct attrmap *map, size_t nmap) +static const u_char * +isakmp_attrmap_print(const u_char *p, const u_char *ep, + const struct attrmap *map, size_t nmap) { - u_short *q; + u_int16_t *q; int totlen; u_int32_t t, v; - q = (u_short *)p; + q = (u_int16_t *)p; if (p[0] & 0x80) totlen = 4; else - totlen = 4 + ntohs(q[1]); + totlen = 4 + EXTRACT_16BITS(&q[1]); if (ep < p + totlen) { printf("[|attr]"); return ep + 1; } printf("("); - t = ntohs(q[0]) & 0x7fff; + t = EXTRACT_16BITS(&q[0]) & 0x7fff; if (map && t < nmap && map[t].type) printf("type=%s ", map[t].type); else printf("type=#%d ", t); if (p[0] & 0x80) { printf("value="); - v = ntohs(q[1]); + v = EXTRACT_16BITS(&q[1]); if (map && t < nmap && v < map[t].nvalue && map[t].value[v]) printf("%s", map[t].value[v]); else rawprint((caddr_t)&q[1], 2); } else { - printf("len=%d value=", ntohs(q[1])); - rawprint((caddr_t)&p[4], ntohs(q[1])); + printf("len=%d value=", EXTRACT_16BITS(&q[1])); + rawprint((caddr_t)&p[4], EXTRACT_16BITS(&q[1])); } printf(")"); return p + totlen; } -static u_char * -isakmp_attr_print(u_char *p, u_char *ep) +static const u_char * +isakmp_attr_print(const u_char *p, const u_char *ep) { - u_short *q; + u_int16_t *q; int totlen; u_int32_t t; - q = (u_short *)p; + q = (u_int16_t *)p; if (p[0] & 0x80) totlen = 4; else - totlen = 4 + ntohs(q[1]); + totlen = 4 + EXTRACT_16BITS(&q[1]); if (ep < p + totlen) { printf("[|attr]"); return ep + 1; } printf("("); - t = ntohs(q[0]) & 0x7fff; + t = EXTRACT_16BITS(&q[0]) & 0x7fff; printf("type=#%d ", t); if (p[0] & 0x80) { printf("value="); t = q[1]; rawprint((caddr_t)&q[1], 2); } else { - printf("len=%d value=", ntohs(q[1])); - rawprint((caddr_t)&p[2], ntohs(q[1])); + printf("len=%d value=", EXTRACT_16BITS(&q[1])); + rawprint((caddr_t)&p[2], EXTRACT_16BITS(&q[1])); } printf(")"); return p + totlen; } -static u_char * -isakmp_sa_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, - u_int32_t doi0, u_int32_t proto0) +static const u_char * +isakmp_sa_print(const struct isakmp_gen *ext, u_int item_len, + const u_char *ep, u_int32_t phase, u_int32_t doi0 _U_, + u_int32_t proto0, int depth) { - struct isakmp_pl_sa *p; - u_int32_t *q; - u_int32_t doi; - u_int32_t sit; - u_char *cp; + const struct isakmp_pl_sa *p; + struct isakmp_pl_sa sa; + const u_int32_t *q; + u_int32_t doi, sit, ident; + const u_char *cp, *np; int t; printf("%s:", NPSTR(ISAKMP_NPTYPE_SA)); p = (struct isakmp_pl_sa *)ext; - doi = ntohl(p->doi); + TCHECK(*p); + safememcpy(&sa, ext, sizeof(sa)); + doi = ntohl(sa.doi); + sit = ntohl(sa.sit); if (doi != 1) { printf(" doi=%d", doi); - printf(" situation=%u", (u_int32_t)ntohl(p->sit)); + printf(" situation=%u", (u_int32_t)ntohl(sa.sit)); return (u_char *)(p + 1); } printf(" doi=ipsec"); - q = (u_int32_t *)&p->sit; + q = (u_int32_t *)&sa.sit; printf(" situation="); t = 0; - if (ntohl(*q) & 0x01) { + if (sit & 0x01) { printf("identity"); t++; } - if (ntohl(*q) & 0x02) { + if (sit & 0x02) { printf("%ssecrecy", t ? "+" : ""); t++; } - if (ntohl(*q) & 0x04) + if (sit & 0x04) printf("%sintegrity", t ? "+" : ""); - sit = htonl(*q++); - if (sit != 0x01) - printf(" ident=%u", (u_int32_t)ntohl(*q++)); + np = (u_char *)ext + sizeof(sa); + if (sit != 0x01) { + TCHECK2(*(ext + 1), sizeof(ident)); + safememcpy(&ident, ext + 1, sizeof(ident)); + printf(" ident=%u", (u_int32_t)ntohl(ident)); + np += sizeof(ident); + } - ext = (struct isakmp_gen *)q; + ext = (struct isakmp_gen *)np; + TCHECK(*ext); - cp = isakmp_sub_print(ISAKMP_NPTYPE_P, ext, ep, phase, doi, proto0); + cp = isakmp_sub_print(ISAKMP_NPTYPE_P, ext, ep, phase, doi, proto0, + depth); return cp; +trunc: + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_SA)); + return NULL; } -static u_char * -isakmp_p_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, - u_int32_t doi0, u_int32_t proto0) +static const u_char * +isakmp_p_print(const struct isakmp_gen *ext, u_int item_len, + const u_char *ep, u_int32_t phase, u_int32_t doi0, + u_int32_t proto0 _U_, int depth) { - struct isakmp_pl_p *p; - u_char *cp; + const struct isakmp_pl_p *p; + struct isakmp_pl_p prop; + const u_char *cp; printf("%s:", NPSTR(ISAKMP_NPTYPE_P)); p = (struct isakmp_pl_p *)ext; + TCHECK(*p); + safememcpy(&prop, ext, sizeof(prop)); printf(" #%d protoid=%s transform=%d", - p->p_no, PROTOIDSTR(p->prot_id), p->num_t); - if (p->spi_size) { + prop.p_no, PROTOIDSTR(prop.prot_id), prop.num_t); + if (prop.spi_size) { printf(" spi="); - rawprint((caddr_t)(p + 1), p->spi_size); + if (!rawprint((caddr_t)(p + 1), prop.spi_size)) + goto trunc; } - ext = (struct isakmp_gen *)((u_char *)(p + 1) + p->spi_size); + ext = (struct isakmp_gen *)((u_char *)(p + 1) + prop.spi_size); + TCHECK(*ext); cp = isakmp_sub_print(ISAKMP_NPTYPE_T, ext, ep, phase, doi0, - p->prot_id); + prop.prot_id, depth); return cp; +trunc: + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_P)); + return NULL; } -static char *isakmp_p_map[] = { +static const char *isakmp_p_map[] = { NULL, "ike", }; -static char *ah_p_map[] = { - NULL, "md5", "sha", "1des", +static const char *ah_p_map[] = { + NULL, "(reserved)", "md5", "sha", "1des", + "sha2-256", "sha2-384", "sha2-512", }; -static char *esp_p_map[] = { +static const char *esp_p_map[] = { NULL, "1des-iv64", "1des", "3des", "rc5", "idea", "cast", - "blowfish", "3idea", "1des-iv32", "rc4", "null" + "blowfish", "3idea", "1des-iv32", "rc4", "null", "aes" }; -static char *ipcomp_p_map[] = { +static const char *ipcomp_p_map[] = { NULL, "oui", "deflate", "lzs", }; -struct attrmap ipsec_t_map[] = { - { NULL, 0 }, +const struct attrmap ipsec_t_map[] = { + { NULL, 0, { NULL } }, { "lifetype", 3, { NULL, "sec", "kb", }, }, - { "life", 0, }, + { "life", 0, { NULL } }, { "group desc", 5, { NULL, "modp768", "modp1024", "EC2N 2^155", "EC2N 2^185", }, }, { "enc mode", 3, { NULL, "tunnel", "transport", }, }, { "auth", 5, { NULL, "hmac-md5", "hmac-sha1", "1des-mac", "keyed", }, }, - { "keylen", 0, }, - { "rounds", 0, }, - { "dictsize", 0, }, - { "privalg", 0, }, + { "keylen", 0, { NULL } }, + { "rounds", 0, { NULL } }, + { "dictsize", 0, { NULL } }, + { "privalg", 0, { NULL } }, }; -struct attrmap oakley_t_map[] = { - { NULL, 0 }, - { "enc", 7, { NULL, "1des", "idea", "blowfish", "rc5", - "3des", "cast"}, }, - { "hash", 4, { NULL, "md5", "sha1", "tiger", }, }, +const struct attrmap oakley_t_map[] = { + { NULL, 0, { NULL } }, + { "enc", 8, { NULL, "1des", "idea", "blowfish", "rc5", + "3des", "cast", "aes", }, }, + { "hash", 7, { NULL, "md5", "sha1", "tiger", + "sha2-256", "sha2-384", "sha2-512", }, }, { "auth", 6, { NULL, "preshared", "dss", "rsa sig", "rsa enc", "rsa enc revised", }, }, { "group desc", 5, { NULL, "modp768", "modp1024", "EC2N 2^155", "EC2N 2^185", }, }, { "group type", 4, { NULL, "MODP", "ECP", "EC2N", }, }, - { "group prime", 0, }, - { "group gen1", 0, }, - { "group gen2", 0, }, - { "group curve A", 0, }, - { "group curve B", 0, }, + { "group prime", 0, { NULL } }, + { "group gen1", 0, { NULL } }, + { "group gen2", 0, { NULL } }, + { "group curve A", 0, { NULL } }, + { "group curve B", 0, { NULL } }, { "lifetype", 3, { NULL, "sec", "kb", }, }, - { "lifeduration", 0, }, - { "prf", 0, }, - { "keylen", 0, }, - { "field", 0, }, - { "order", 0, }, + { "lifeduration", 0, { NULL } }, + { "prf", 0, { NULL } }, + { "keylen", 0, { NULL } }, + { "field", 0, { NULL } }, + { "order", 0, { NULL } }, }; -static u_char * -isakmp_t_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, - u_int32_t doi, u_int32_t proto) +static const u_char * +isakmp_t_print(const struct isakmp_gen *ext, u_int item_len, + const u_char *ep, u_int32_t phase _U_, u_int32_t doi _U_, + u_int32_t proto, int depth _U_) { - struct isakmp_pl_t *p; - u_char *cp; - char *idstr; - struct attrmap *map; + const struct isakmp_pl_t *p; + struct isakmp_pl_t t; + const u_char *cp; + const char *idstr; + const struct attrmap *map; size_t nmap; - u_char *ep2; + const u_char *ep2; printf("%s:", NPSTR(ISAKMP_NPTYPE_T)); p = (struct isakmp_pl_t *)ext; + TCHECK(*p); + safememcpy(&t, ext, sizeof(t)); switch (proto) { case 1: - idstr = STR_OR_ID(p->t_id, isakmp_p_map); + idstr = STR_OR_ID(t.t_id, isakmp_p_map); map = oakley_t_map; nmap = sizeof(oakley_t_map)/sizeof(oakley_t_map[0]); break; case 2: - idstr = STR_OR_ID(p->t_id, ah_p_map); + idstr = STR_OR_ID(t.t_id, ah_p_map); map = ipsec_t_map; nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]); break; case 3: - idstr = STR_OR_ID(p->t_id, esp_p_map); + idstr = STR_OR_ID(t.t_id, esp_p_map); map = ipsec_t_map; nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]); break; case 4: - idstr = STR_OR_ID(p->t_id, ipcomp_p_map); + idstr = STR_OR_ID(t.t_id, ipcomp_p_map); map = ipsec_t_map; nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]); break; @@ -545,11 +612,11 @@ isakmp_t_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, } if (idstr) - printf(" #%d id=%s ", p->t_no, idstr); + printf(" #%d id=%s ", t.t_no, idstr); else - printf(" #%d id=%d ", p->t_no, p->t_id); + printf(" #%d id=%d ", t.t_no, t.t_id); cp = (u_char *)(p + 1); - ep2 = (u_char *)p + ntohs(ext->len); + ep2 = (u_char *)p + item_len; while (cp < ep && cp < ep2) { if (map && nmap) { cp = isakmp_attrmap_print(cp, (ep < ep2) ? ep : ep2, @@ -560,47 +627,65 @@ isakmp_t_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, if (ep < ep2) printf("..."); return cp; +trunc: + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_T)); + return NULL; } -static u_char * -isakmp_ke_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, - u_int32_t doi, u_int32_t proto) +static const u_char * +isakmp_ke_print(const struct isakmp_gen *ext, u_int item_len, + const u_char *ep, u_int32_t phase _U_, u_int32_t doi _U_, + u_int32_t proto _U_, int depth _U_) { + struct isakmp_gen e; + printf("%s:", NPSTR(ISAKMP_NPTYPE_KE)); - printf(" key len=%d", ntohs(ext->len) - 4); - if (2 < vflag && 4 < ntohs(ext->len)) { + TCHECK(*ext); + safememcpy(&e, ext, sizeof(e)); + printf(" key len=%d", ntohs(e.len) - 4); + if (2 < vflag && 4 < ntohs(e.len)) { printf(" "); - rawprint((caddr_t)(ext + 1), ntohs(ext->len) - 4); + if (!rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4)) + goto trunc; } - return (u_char *)ext + ntohs(ext->len); + return (u_char *)ext + ntohs(e.len); +trunc: + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_KE)); + return NULL; } -static u_char * -isakmp_id_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, - u_int32_t doi, u_int32_t proto) +static const u_char * +isakmp_id_print(const struct isakmp_gen *ext, u_int item_len, + const u_char *ep, u_int32_t phase, u_int32_t doi _U_, + u_int32_t proto _U_, int depth _U_) { #define USE_IPSECDOI_IN_PHASE1 1 - struct isakmp_pl_id *p; - static char *idtypestr[] = { + const struct isakmp_pl_id *p; + struct isakmp_pl_id id; + static const char *idtypestr[] = { "IPv4", "IPv4net", "IPv6", "IPv6net", }; - static char *ipsecidtypestr[] = { + static const char *ipsecidtypestr[] = { NULL, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6", "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN", "keyid", }; int len; - u_char *data; + const u_char *data; printf("%s:", NPSTR(ISAKMP_NPTYPE_ID)); p = (struct isakmp_pl_id *)ext; - if (sizeof(*p) < ext->len) + TCHECK(*p); + safememcpy(&id, ext, sizeof(id)); + if (sizeof(*p) < item_len) { data = (u_char *)(p + 1); - else + len = item_len - sizeof(*p); + } else { data = NULL; - len = ntohs(ext->len) - sizeof(*p); + len = 0; + } #if 0 /*debug*/ printf(" [phase=%d doi=%d proto=%d]", phase, doi, proto); @@ -610,9 +695,9 @@ isakmp_id_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, case 1: #endif default: - printf(" idtype=%s", STR_OR_ID(p->d.id_type, idtypestr)); + printf(" idtype=%s", STR_OR_ID(id.d.id_type, idtypestr)); printf(" doi_data=%u", - (u_int32_t)(ntohl(p->d.doi_data) & 0xffffff)); + (u_int32_t)(ntohl(id.d.doi_data) & 0xffffff)); break; #ifdef USE_IPSECDOI_IN_PHASE1 @@ -620,24 +705,40 @@ isakmp_id_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, #endif case 2: { - struct ipsecdoi_id *p; + const struct ipsecdoi_id *p; + struct ipsecdoi_id id; struct protoent *pe; p = (struct ipsecdoi_id *)ext; - printf(" idtype=%s", STR_OR_ID(p->type, ipsecidtypestr)); - setprotoent(1); - pe = getprotobynumber(p->proto_id); - if (pe) - printf(" protoid=%s", pe->p_name); - else - printf(" protoid=%s", PROTOIDSTR(p->proto_id)); - endprotoent(); - printf(" port=%d", ntohs(p->port)); + TCHECK(*p); + safememcpy(&id, ext, sizeof(id)); + printf(" idtype=%s", STR_OR_ID(id.type, ipsecidtypestr)); + if (id.proto_id) { +#ifndef WIN32 + setprotoent(1); +#endif /* WIN32 */ + pe = getprotobynumber(id.proto_id); + if (pe) + printf(" protoid=%s", pe->p_name); +#ifndef WIN32 + endprotoent(); +#endif /* WIN32 */ + } else { + /* it DOES NOT mean IPPROTO_IP! */ + printf(" protoid=%s", "0"); + } + printf(" port=%d", ntohs(id.port)); if (!len) break; - switch (p->type) { + if (data == NULL) + goto trunc; + TCHECK2(*data, len); + switch (id.type) { case IPSECDOI_ID_IPV4_ADDR: - printf(" len=%d %s", len, ipaddr_string(data)); + if (len < 4) + printf(" len=%d [bad: < 4]", len); + else + printf(" len=%d %s", len, ipaddr_string(data)); len = 0; break; case IPSECDOI_ID_FQDN: @@ -645,51 +746,68 @@ 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; } case IPSECDOI_ID_IPV4_ADDR_SUBNET: { - u_char *mask; - mask = data + sizeof(struct in_addr); - printf(" len=%d %s/%u.%u.%u.%u", len, - ipaddr_string(data), - mask[0], mask[1], mask[2], mask[3]); + const u_char *mask; + if (len < 8) + printf(" len=%d [bad: < 8]", len); + else { + mask = data + sizeof(struct in_addr); + printf(" len=%d %s/%u.%u.%u.%u", len, + ipaddr_string(data), + mask[0], mask[1], mask[2], mask[3]); + } len = 0; break; } #ifdef INET6 case IPSECDOI_ID_IPV6_ADDR: - printf(" len=%d %s", len, ip6addr_string(data)); + if (len < 16) + printf(" len=%d [bad: < 16]", len); + else + printf(" len=%d %s", len, ip6addr_string(data)); len = 0; break; case IPSECDOI_ID_IPV6_ADDR_SUBNET: { - u_int32_t *mask; - mask = (u_int32_t *)(data + sizeof(struct in6_addr)); - /*XXX*/ - printf(" len=%d %s/0x%08x%08x%08x%08x", len, - ip6addr_string(data), - mask[0], mask[1], mask[2], mask[3]); + const u_int32_t *mask; + if (len < 20) + printf(" len=%d [bad: < 20]", len); + else { + mask = (u_int32_t *)(data + sizeof(struct in6_addr)); + /*XXX*/ + printf(" len=%d %s/0x%08x%08x%08x%08x", len, + ip6addr_string(data), + mask[0], mask[1], mask[2], mask[3]); + } len = 0; break; } #endif /*INET6*/ case IPSECDOI_ID_IPV4_ADDR_RANGE: - printf(" len=%d %s-%s", len, ipaddr_string(data), - ipaddr_string(data + sizeof(struct in_addr))); + if (len < 8) + printf(" len=%d [bad: < 8]", len); + else { + printf(" len=%d %s-%s", len, + ipaddr_string(data), + ipaddr_string(data + sizeof(struct in_addr))); + } len = 0; break; #ifdef INET6 case IPSECDOI_ID_IPV6_ADDR_RANGE: - printf(" len=%d %s-%s", len, ip6addr_string(data), - ip6addr_string(data + sizeof(struct in6_addr))); + if (len < 32) + printf(" len=%d [bad: < 32]", len); + else { + printf(" len=%d %s-%s", len, + ip6addr_string(data), + ip6addr_string(data + sizeof(struct in6_addr))); + } len = 0; break; #endif /*INET6*/ @@ -702,54 +820,161 @@ 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(" "); - rawprint(data, len); + if (!rawprint((caddr_t)data, len)) + goto trunc; } } - return (u_char *)ext + ntohs(ext->len); + return (u_char *)ext + item_len; +trunc: + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_ID)); + return NULL; +} + +static const u_char * +isakmp_cert_print(const struct isakmp_gen *ext, u_int item_len, + const u_char *ep, u_int32_t phase _U_, u_int32_t doi0 _U_, + u_int32_t proto0 _U_, int depth _U_) +{ + const struct isakmp_pl_cert *p; + struct isakmp_pl_cert cert; + static const char *certstr[] = { + "none", "pkcs7", "pgp", "dns", + "x509sign", "x509ke", "kerberos", "crl", + "arl", "spki", "x509attr", + }; + + printf("%s:", NPSTR(ISAKMP_NPTYPE_CERT)); + + p = (struct isakmp_pl_cert *)ext; + TCHECK(*p); + safememcpy(&cert, ext, sizeof(cert)); + printf(" len=%d", item_len - 4); + printf(" type=%s", STR_OR_ID((cert.encode), certstr)); + if (2 < vflag && 4 < item_len) { + printf(" "); + if (!rawprint((caddr_t)(ext + 1), item_len - 4)) + goto trunc; + } + return (u_char *)ext + item_len; +trunc: + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_CERT)); + return NULL; } -static u_char * -isakmp_hash_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, - u_int32_t doi, u_int32_t proto) +static const u_char * +isakmp_cr_print(const struct isakmp_gen *ext, u_int item_len, + const u_char *ep, u_int32_t phase _U_, u_int32_t doi0 _U_, + u_int32_t proto0 _U_, int depth _U_) { + const struct isakmp_pl_cert *p; + struct isakmp_pl_cert cert; + static const char *certstr[] = { + "none", "pkcs7", "pgp", "dns", + "x509sign", "x509ke", "kerberos", "crl", + "arl", "spki", "x509attr", + }; + + printf("%s:", NPSTR(ISAKMP_NPTYPE_CR)); + + p = (struct isakmp_pl_cert *)ext; + TCHECK(*p); + safememcpy(&cert, ext, sizeof(cert)); + printf(" len=%d", item_len - 4); + printf(" type=%s", STR_OR_ID((cert.encode), certstr)); + if (2 < vflag && 4 < item_len) { + printf(" "); + if (!rawprint((caddr_t)(ext + 1), item_len - 4)) + goto trunc; + } + return (u_char *)ext + item_len; +trunc: + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_CR)); + return NULL; +} + +static const u_char * +isakmp_hash_print(const struct isakmp_gen *ext, u_int item_len, + const u_char *ep, u_int32_t phase _U_, u_int32_t doi _U_, + u_int32_t proto _U_, int depth _U_) +{ + struct isakmp_gen e; + printf("%s:", NPSTR(ISAKMP_NPTYPE_HASH)); - printf(" len=%d", ntohs(ext->len) - 4); - if (2 < vflag && 4 < ntohs(ext->len)) { + TCHECK(*ext); + safememcpy(&e, ext, sizeof(e)); + printf(" len=%d", ntohs(e.len) - 4); + if (2 < vflag && 4 < ntohs(e.len)) { + printf(" "); + if (!rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4)) + goto trunc; + } + return (u_char *)ext + ntohs(e.len); +trunc: + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_HASH)); + return NULL; +} + +static const u_char * +isakmp_sig_print(const struct isakmp_gen *ext, u_int item_len, + const u_char *ep, u_int32_t phase _U_, u_int32_t doi _U_, + u_int32_t proto _U_, int depth _U_) +{ + struct isakmp_gen e; + + printf("%s:", NPSTR(ISAKMP_NPTYPE_SIG)); + + TCHECK(*ext); + safememcpy(&e, ext, sizeof(e)); + printf(" len=%d", ntohs(e.len) - 4); + if (2 < vflag && 4 < ntohs(e.len)) { printf(" "); - rawprint((caddr_t)(ext + 1), ntohs(ext->len) - 4); + if (!rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4)) + goto trunc; } - return (u_char *)ext + ntohs(ext->len); + return (u_char *)ext + ntohs(e.len); +trunc: + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_SIG)); + return NULL; } -static u_char * -isakmp_nonce_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, - u_int32_t doi, u_int32_t proto) +static const u_char * +isakmp_nonce_print(const struct isakmp_gen *ext, u_int item_len, + const u_char *ep, u_int32_t phase _U_, u_int32_t doi _U_, + u_int32_t proto _U_, int depth _U_) { + struct isakmp_gen e; + printf("%s:", NPSTR(ISAKMP_NPTYPE_NONCE)); - printf(" n len=%d", ntohs(ext->len) - 4); - if (2 < vflag && 4 < ntohs(ext->len)) { + TCHECK(*ext); + safememcpy(&e, ext, sizeof(e)); + printf(" n len=%d", ntohs(e.len) - 4); + if (2 < vflag && 4 < ntohs(e.len)) { printf(" "); - rawprint((caddr_t)(ext + 1), ntohs(ext->len) - 4); + if (!rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4)) + goto trunc; } - return (u_char *)ext + ntohs(ext->len); + return (u_char *)ext + ntohs(e.len); +trunc: + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_NONCE)); + return NULL; } -static u_char * -isakmp_n_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, - u_int32_t doi0, u_int32_t proto0) +static const u_char * +isakmp_n_print(const struct isakmp_gen *ext, u_int item_len, + const u_char *ep, u_int32_t phase, u_int32_t doi0 _U_, + u_int32_t proto0 _U_, int depth) { - struct isakmp_pl_n *p; - u_char *cp; + struct isakmp_pl_n *p, n; + const u_char *cp; u_char *ep2; u_int32_t doi; u_int32_t proto; - static char *notifystr[] = { + static const char *notify_error_str[] = { NULL, "INVALID-PAYLOAD-TYPE", "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED", "INVALID-COOKIE", "INVALID-MAJOR-VERSION", @@ -767,58 +992,87 @@ isakmp_n_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE", "UNEQUAL-PAYLOAD-LENGTHS", }; - static char *ipsecnotifystr[] = { + static const char *ipsec_notify_error_str[] = { + "RESERVED", + }; + static const char *notify_status_str[] = { + "CONNECTED", + }; + static const char *ipsec_notify_status_str[] = { "RESPONDER-LIFETIME", "REPLAY-STATUS", "INITIAL-CONTACT", }; /* NOTE: these macro must be called with x in proper range */ -#define NOTIFYSTR(x) \ - (((x) == 16384) ? "CONNECTED" : STR_OR_ID((x), notifystr)) -#define IPSECNOTIFYSTR(x) \ - (((x) == 8192) ? "RESERVED" : STR_OR_ID(((x) - 24576), ipsecnotifystr)) + +/* 0 - 8191 */ +#define NOTIFY_ERROR_STR(x) \ + STR_OR_ID((x), notify_error_str) + +/* 8192 - 16383 */ +#define IPSEC_NOTIFY_ERROR_STR(x) \ + STR_OR_ID((u_int)((x) - 8192), ipsec_notify_error_str) + +/* 16384 - 24575 */ +#define NOTIFY_STATUS_STR(x) \ + STR_OR_ID((u_int)((x) - 16384), notify_status_str) + +/* 24576 - 32767 */ +#define IPSEC_NOTIFY_STATUS_STR(x) \ + STR_OR_ID((u_int)((x) - 24576), ipsec_notify_status_str) printf("%s:", NPSTR(ISAKMP_NPTYPE_N)); p = (struct isakmp_pl_n *)ext; - doi = ntohl(p->doi); - proto = p->prot_id; + TCHECK(*p); + safememcpy(&n, ext, sizeof(n)); + doi = ntohl(n.doi); + proto = n.prot_id; if (doi != 1) { printf(" doi=%d", doi); printf(" proto=%d", proto); - printf(" type=%s", NOTIFYSTR(ntohs(p->type))); - if (p->spi_size) { + if (ntohs(n.type) < 8192) + printf(" type=%s", NOTIFY_ERROR_STR(ntohs(n.type))); + else if (ntohs(n.type) < 16384) + printf(" type=%s", numstr(ntohs(n.type))); + else if (ntohs(n.type) < 24576) + printf(" type=%s", NOTIFY_STATUS_STR(ntohs(n.type))); + else + printf(" type=%s", numstr(ntohs(n.type))); + if (n.spi_size) { printf(" spi="); - rawprint((caddr_t)(p + 1), p->spi_size); + if (!rawprint((caddr_t)(p + 1), n.spi_size)) + goto trunc; } - return (u_char *)(p + 1) + p->spi_size; + return (u_char *)(p + 1) + n.spi_size; } printf(" doi=ipsec"); printf(" proto=%s", PROTOIDSTR(proto)); - if (ntohs(p->type) < 8192) - printf(" type=%s", NOTIFYSTR(ntohs(p->type))); - else if (ntohs(p->type) < 16384) - printf(" type=%s", IPSECNOTIFYSTR(ntohs(p->type))); - else if (ntohs(p->type) < 24576) - printf(" type=%s", NOTIFYSTR(ntohs(p->type))); - else if (ntohs(p->type) < 40960) - printf(" type=%s", IPSECNOTIFYSTR(ntohs(p->type))); + if (ntohs(n.type) < 8192) + printf(" type=%s", NOTIFY_ERROR_STR(ntohs(n.type))); + else if (ntohs(n.type) < 16384) + printf(" type=%s", IPSEC_NOTIFY_ERROR_STR(ntohs(n.type))); + else if (ntohs(n.type) < 24576) + printf(" type=%s", NOTIFY_STATUS_STR(ntohs(n.type))); + else if (ntohs(n.type) < 32768) + printf(" type=%s", IPSEC_NOTIFY_STATUS_STR(ntohs(n.type))); else - printf(" type=%s", NOTIFYSTR(ntohs(p->type))); - if (p->spi_size) { + printf(" type=%s", numstr(ntohs(n.type))); + if (n.spi_size) { printf(" spi="); - rawprint((caddr_t)(p + 1), p->spi_size); + if (!rawprint((caddr_t)(p + 1), n.spi_size)) + goto trunc; } - cp = (u_char *)(p + 1) + p->spi_size; - ep2 = (u_char *)p + ntohs(ext->len); + cp = (u_char *)(p + 1) + n.spi_size; + ep2 = (u_char *)p + item_len; if (cp < ep) { printf(" orig=("); - switch (ntohs(p->type)) { + switch (ntohs(n.type)) { case IPSECDOI_NTYPE_RESPONDER_LIFETIME: { - struct attrmap *map = oakley_t_map; + const struct attrmap *map = oakley_t_map; size_t nmap = sizeof(oakley_t_map)/sizeof(oakley_t_map[0]); while (cp < ep && cp < ep2) { cp = isakmp_attrmap_print(cp, @@ -831,26 +1085,32 @@ isakmp_n_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, (*(u_int32_t *)cp) ? "en" : "dis"); break; case ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN: - isakmp_sub_print(ISAKMP_NPTYPE_SA, - (struct isakmp_gen *)cp, ep, phase, doi, proto); + if (isakmp_sub_print(ISAKMP_NPTYPE_SA, + (struct isakmp_gen *)cp, ep, phase, doi, proto, + depth) == NULL) + return NULL; break; default: /* NULL is dummy */ - isakmp_print(cp, - ntohs(ext->len) - sizeof(*p) - p->spi_size, + isakmp_print(cp, item_len - sizeof(*p) - n.spi_size, NULL); } printf(")"); } - return (u_char *)ext + ntohs(ext->len); + return (u_char *)ext + item_len; +trunc: + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_N)); + return NULL; } -static u_char * -isakmp_d_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, - u_int32_t doi0, u_int32_t proto0) +static const u_char * +isakmp_d_print(const struct isakmp_gen *ext, u_int item_len, + const u_char *ep, u_int32_t phase _U_, u_int32_t doi0 _U_, + u_int32_t proto0 _U_, int depth _U_) { - struct isakmp_pl_d *p; - u_int8_t *q; + const struct isakmp_pl_d *p; + struct isakmp_pl_d d; + const u_int8_t *q; u_int32_t doi; u_int32_t proto; int i; @@ -858,8 +1118,10 @@ isakmp_d_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, printf("%s:", NPSTR(ISAKMP_NPTYPE_D)); p = (struct isakmp_pl_d *)ext; - doi = ntohl(p->doi); - proto = p->prot_id; + TCHECK(*p); + safememcpy(&d, ext, sizeof(d)); + doi = ntohl(d.doi); + proto = d.prot_id; if (doi != 1) { printf(" doi=%u", doi); printf(" proto=%u", proto); @@ -867,79 +1129,123 @@ isakmp_d_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, printf(" doi=ipsec"); printf(" proto=%s", PROTOIDSTR(proto)); } - printf(" spilen=%u", p->spi_size); - printf(" nspi=%u", ntohs(p->num_spi)); + printf(" spilen=%u", d.spi_size); + printf(" nspi=%u", ntohs(d.num_spi)); printf(" spi="); q = (u_int8_t *)(p + 1); - for (i = 0; i < ntohs(p->num_spi); i++) { + for (i = 0; i < ntohs(d.num_spi); i++) { if (i != 0) printf(","); - rawprint(q, p->spi_size); - q += p->spi_size; + if (!rawprint((caddr_t)q, d.spi_size)) + goto trunc; + q += d.spi_size; } return q; +trunc: + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_D)); + return NULL; } -static u_char * -isakmp_vid_print(struct isakmp_gen *ext, u_char *ep, u_int32_t phase, - u_int32_t doi, u_int32_t proto) +static const u_char * +isakmp_vid_print(const struct isakmp_gen *ext, u_int item_len, + const u_char *ep, u_int32_t phase _U_, u_int32_t doi _U_, + u_int32_t proto _U_, int depth _U_) { + struct isakmp_gen e; + printf("%s:", NPSTR(ISAKMP_NPTYPE_VID)); - printf(" len=%d", ntohs(ext->len) - 4); - if (2 < vflag && 4 < ntohs(ext->len)) { + TCHECK(*ext); + safememcpy(&e, ext, sizeof(e)); + printf(" len=%d", ntohs(e.len) - 4); + if (2 < vflag && 4 < ntohs(e.len)) { printf(" "); - rawprint((caddr_t)(ext + 1), ntohs(ext->len) - 4); + if (!rawprint((caddr_t)(ext + 1), ntohs(e.len) - 4)) + goto trunc; } - return (u_char *)ext + ntohs(ext->len); + return (u_char *)ext + ntohs(e.len); +trunc: + printf(" [|%s]", NPSTR(ISAKMP_NPTYPE_VID)); + return NULL; } -static u_char * -isakmp_sub0_print(u_char np, struct isakmp_gen *ext, u_char *ep, - u_int32_t phase, u_int32_t doi, u_int32_t proto) +static const u_char * +isakmp_sub0_print(u_char np, const struct isakmp_gen *ext, const u_char *ep, + u_int32_t phase, u_int32_t doi, u_int32_t proto, int depth) { - u_char *cp; + const u_char *cp; + struct isakmp_gen e; + u_int item_len; cp = (u_char *)ext; - - if (NPFUNC(np)) - cp = (*NPFUNC(np))(ext, ep, phase, doi, proto); - else { + TCHECK(*ext); + safememcpy(&e, ext, sizeof(e)); + + /* + * Since we can't have a payload length of less than 4 bytes, + * we need to bail out here if the generic header is nonsensical + * or truncated, otherwise we could loop forever processing + * zero-length items or otherwise misdissect the packet. + */ + item_len = ntohs(e.len); + if (item_len <= 4) + return NULL; + + if (NPFUNC(np)) { + /* + * XXX - what if item_len is too short, or too long, + * for this payload type? + */ + cp = (*NPFUNC(np))(ext, item_len, ep, phase, doi, proto, depth); + } else { printf("%s", NPSTR(np)); - cp += ntohs(ext->len); + cp += item_len; } + return cp; +trunc: + printf(" [|isakmp]"); + return NULL; } -static u_char * -isakmp_sub_print(u_char np, struct isakmp_gen *ext, u_char *ep, - u_int32_t phase, u_int32_t doi, u_int32_t proto) +static const u_char * +isakmp_sub_print(u_char np, const struct isakmp_gen *ext, const u_char *ep, + u_int32_t phase, u_int32_t doi, u_int32_t proto, int depth) { - u_char *cp; - static int depth = 0; + const u_char *cp; int i; + struct isakmp_gen e; - cp = (u_char *)ext; + cp = (const u_char *)ext; while (np) { - if (ep < (u_char *)ext + ntohs(ext->len)) { - printf(" [|%s]", NPSTR(np)); - cp = ep + 1; - break; - } + TCHECK(*ext); + + safememcpy(&e, ext, sizeof(e)); + + TCHECK2(*ext, ntohs(e.len)); + depth++; printf("\n"); for (i = 0; i < depth; i++) printf(" "); printf("("); - cp = isakmp_sub0_print(np, ext, ep, phase, doi, proto); + cp = isakmp_sub0_print(np, ext, ep, phase, doi, proto, depth); printf(")"); depth--; - np = ext->np; + if (cp == NULL) { + /* Zero-length subitem */ + return NULL; + } + + np = e.np; ext = (struct isakmp_gen *)cp; } return cp; +trunc: + printf(" [|%s]", NPSTR(np)); + return NULL; } static char * @@ -950,53 +1256,73 @@ numstr(int x) return buf; } +/* + * some compiler tries to optimize memcpy(), using the alignment constraint + * on the argument pointer type. by using this function, we try to avoid the + * optimization. + */ +static void +safememcpy(void *p, const void *q, size_t l) +{ + memcpy(p, q, l); +} + void isakmp_print(const u_char *bp, u_int length, const u_char *bp2) { - struct isakmp *base; - u_char *ep; + const struct isakmp *p; + struct isakmp base; + const u_char *ep; u_char np; int i; int phase; + int major, minor; - base = (struct isakmp *)bp; - ep = (u_char *)snapend; + p = (const struct isakmp *)bp; + ep = snapend; - if ((struct isakmp *)ep < base + 1) { + if ((struct isakmp *)ep < p + 1) { printf("[|isakmp]"); return; } + safememcpy(&base, p, sizeof(base)); + printf("isakmp"); - if (vflag) - printf(" %d.%d", base->v_maj, base->v_min); + if (vflag) { + major = (base.vers & ISAKMP_VERS_MAJOR) + >> ISAKMP_VERS_MAJOR_SHIFT; + minor = (base.vers & ISAKMP_VERS_MINOR) + >> ISAKMP_VERS_MINOR_SHIFT; + printf(" %d.%d", major, minor); + } if (vflag) { printf(" msgid "); - rawprint((caddr_t)&base->msgid, sizeof(base->msgid)); + rawprint((caddr_t)&base.msgid, sizeof(base.msgid)); } if (1 < vflag) { printf(" cookie "); - rawprint((caddr_t)&base->i_ck, sizeof(base->i_ck)); + rawprint((caddr_t)&base.i_ck, sizeof(base.i_ck)); printf("->"); - rawprint((caddr_t)&base->r_ck, sizeof(base->r_ck)); + rawprint((caddr_t)&base.r_ck, sizeof(base.r_ck)); } printf(":"); - phase = (*(u_int32_t *)base->msgid == 0) ? 1 : 2; + phase = (*(u_int32_t *)base.msgid == 0) ? 1 : 2; if (phase == 1) printf(" phase %d", phase); else printf(" phase %d/others", phase); - i = cookie_find(&base->i_ck); + i = cookie_find(&base.i_ck); if (i < 0) { - if (iszero((u_char *)&base->r_ck, sizeof(base->r_ck))) { + if (iszero((u_char *)&base.r_ck, sizeof(base.r_ck))) { /* the first packet */ printf(" I"); if (bp2) - cookie_record(&base->i_ck, bp2); + cookie_record(&base.i_ck, bp2); } else printf(" ?"); } else { @@ -1008,46 +1334,47 @@ isakmp_print(const u_char *bp, u_int length, const u_char *bp2) printf(" ?"); } - printf(" %s", ETYPESTR(base->etype)); - if (base->flags) { - printf("[%s%s]", base->flags & ISAKMP_FLAG_E ? "E" : "", - base->flags & ISAKMP_FLAG_C ? "C" : ""); + printf(" %s", ETYPESTR(base.etype)); + if (base.flags) { + printf("[%s%s]", base.flags & ISAKMP_FLAG_E ? "E" : "", + base.flags & ISAKMP_FLAG_C ? "C" : ""); } - printf(":"); - { - struct isakmp_gen *ext; - int nparen; + if (vflag) { + const struct isakmp_gen *ext; + int nparen; #define CHECKLEN(p, np) \ - if (ep < (u_char *)(p)) { \ - printf(" [|%s]", NPSTR(np)); \ - goto done; \ - } + if (ep < (u_char *)(p)) { \ + printf(" [|%s]", NPSTR(np)); \ + goto done; \ + } - /* regardless of phase... */ - if (base->flags & ISAKMP_FLAG_E) { - /* - * encrypted, nothing we can do right now. - * we hope to decrypt the packet in the future... - */ - printf(" [|%s]", NPSTR(base->np)); - goto done; - } + printf(":"); - nparen = 0; - CHECKLEN(base + 1, base->np) + /* regardless of phase... */ + if (base.flags & ISAKMP_FLAG_E) { + /* + * encrypted, nothing we can do right now. + * we hope to decrypt the packet in the future... + */ + printf(" [encrypted %s]", NPSTR(base.np)); + goto done; + } + + nparen = 0; + CHECKLEN(p + 1, base.np) - np = base->np; - ext = (struct isakmp_gen *)(base + 1); - isakmp_sub_print(np, ext, ep, phase, 0, 0); - } + np = base.np; + ext = (struct isakmp_gen *)(p + 1); + isakmp_sub_print(np, ext, ep, phase, 0, 0, 0); + } done: if (vflag) { - if (ntohl(base->len) != length) { - printf(" (len mismatch: isakmp %u/ip %d)", - (u_int32_t)ntohl(base->len), length); + if (ntohl(base.len) != length) { + printf(" (len mismatch: isakmp %u/ip %u)", + (u_int32_t)ntohl(base.len), length); } } } diff --git a/kame/kame/tcpdump/print-isoclns.c b/kame/kame/tcpdump/print-isoclns.c index 629dfe04f8..bef8b23c84 100644 --- a/kame/kame/tcpdump/print-isoclns.c +++ b/kame/kame/tcpdump/print-isoclns.c @@ -19,102 +19,491 @@ * 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: print-isoclns.c,v 1.15 96/12/31 21:27:41 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-isoclns.c,v 1.106.2.5 2004/03/24 01:45:26 guy Exp $ (LBL)"; #endif -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include -#include -#include +#include #include +#include #include "interface.h" #include "addrtoname.h" #include "ethertype.h" +#include "ether.h" +#include "extract.h" +#include "gmpls.h" + +#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 + +#define IPV4 1 /* AFI value */ +#define IPV6 2 /* AFI value */ + +/* + * IS-IS is defined in ISO 10589. Look there for protocol definitions. + */ + +#define SYSTEM_ID_LEN ETHER_ADDR_LEN +#define NODE_ID_LEN SYSTEM_ID_LEN+1 +#define LSP_ID_LEN SYSTEM_ID_LEN+2 + +#define ISIS_VERSION 1 +#define PDU_TYPE_MASK 0x1F +#define PRIORITY_MASK 0x7F + +#define L1_LAN_IIH 15 +#define L2_LAN_IIH 16 +#define PTP_IIH 17 +#define L1_LSP 18 +#define L2_LSP 20 +#define L1_CSNP 24 +#define L2_CSNP 25 +#define L1_PSNP 26 +#define L2_PSNP 27 + +static struct tok isis_pdu_values[] = { + { L1_LAN_IIH, "L1 Lan IIH"}, + { L2_LAN_IIH, "L2 Lan IIH"}, + { PTP_IIH, "p2p IIH"}, + { L1_LSP, "L1 LSP"}, + { L2_LSP, "L2 LSP"}, + { L1_CSNP, "L1 CSNP"}, + { L2_CSNP, "L2 CSNP"}, + { L1_PSNP, "L1 PSNP"}, + { L2_PSNP, "L2 PSNP"}, + { 0, NULL} +}; + +/* + * A TLV is a tuple of a type, length and a value and is normally used for + * encoding information in all sorts of places. This is an enumeration of + * the well known types. + * + * list taken from rfc3359 plus some memory from veterans ;-) + */ + +#define TLV_AREA_ADDR 1 /* iso10589 */ +#define TLV_IS_REACH 2 /* iso10589 */ +#define TLV_ESNEIGH 3 /* iso10589 */ +#define TLV_PART_DIS 4 /* iso10589 */ +#define TLV_PREFIX_NEIGH 5 /* iso10589 */ +#define TLV_ISNEIGH 6 /* iso10589 */ +#define TLV_ISNEIGH_VARLEN 7 /* iso10589 */ +#define TLV_PADDING 8 /* iso10589 */ +#define TLV_LSP 9 /* iso10589 */ +#define TLV_AUTH 10 /* iso10589, rfc3567 */ +#define TLV_CHECKSUM 12 /* rfc3358 */ +#define TLV_LSP_BUFFERSIZE 14 /* iso10589 rev2 */ +#define TLV_EXT_IS_REACH 22 /* draft-ietf-isis-traffic-05 */ +#define TLV_IS_ALIAS_ID 24 /* draft-ietf-isis-ext-lsp-frags-02 */ +#define TLV_DECNET_PHASE4 42 +#define TLV_LUCENT_PRIVATE 66 +#define TLV_INT_IP_REACH 128 /* rfc1195, rfc2966 */ +#define TLV_PROTOCOLS 129 /* rfc1195 */ +#define TLV_EXT_IP_REACH 130 /* rfc1195, rfc2966 */ +#define TLV_IDRP_INFO 131 /* rfc1195 */ +#define TLV_IPADDR 132 /* rfc1195 */ +#define TLV_IPAUTH 133 /* rfc1195 */ +#define TLV_TE_ROUTER_ID 134 /* draft-ietf-isis-traffic-05 */ +#define TLV_EXTD_IP_REACH 135 /* draft-ietf-isis-traffic-05 */ +#define TLV_HOSTNAME 137 /* rfc2763 */ +#define TLV_SHARED_RISK_GROUP 138 /* draft-ietf-isis-gmpls-extensions */ +#define TLV_NORTEL_PRIVATE1 176 +#define TLV_NORTEL_PRIVATE2 177 +#define TLV_HOLDTIME 198 /* ES-IS */ +#define TLV_RESTART_SIGNALING 211 /* draft-ietf-isis-restart-01 */ +#define TLV_MT_IS_REACH 222 /* draft-ietf-isis-wg-multi-topology-05 */ +#define TLV_MT_SUPPORTED 229 /* draft-ietf-isis-wg-multi-topology-05 */ +#define TLV_IP6ADDR 232 /* draft-ietf-isis-ipv6-02 */ +#define TLV_MT_IP_REACH 235 /* draft-ietf-isis-wg-multi-topology-05 */ +#define TLV_IP6_REACH 236 /* draft-ietf-isis-ipv6-02 */ +#define TLV_MT_IP6_REACH 237 /* draft-ietf-isis-wg-multi-topology-05 */ +#define TLV_PTP_ADJ 240 /* rfc3373 */ +#define TLV_IIH_SEQNR 241 /* draft-shen-isis-iih-sequence-00 */ +#define TLV_VENDOR_PRIVATE 250 /* draft-ietf-isis-proprietary-tlv-00 */ + +static struct tok isis_tlv_values[] = { + { TLV_AREA_ADDR, "Area address(es)"}, + { TLV_IS_REACH, "IS Reachability"}, + { TLV_ESNEIGH, "ES Neighbor(s)"}, + { TLV_PART_DIS, "Partition DIS"}, + { TLV_PREFIX_NEIGH, "Prefix Neighbors"}, + { TLV_ISNEIGH, "IS Neighbor(s)"}, + { TLV_ISNEIGH_VARLEN, "IS Neighbor(s) (variable length)"}, + { TLV_PADDING, "Padding"}, + { TLV_LSP, "LSP entries"}, + { TLV_AUTH, "Authentication"}, + { TLV_CHECKSUM, "Checksum"}, + { TLV_LSP_BUFFERSIZE, "LSP Buffersize"}, + { TLV_EXT_IS_REACH, "Extended IS Reachability"}, + { TLV_IS_ALIAS_ID, "IS Alias ID"}, + { TLV_DECNET_PHASE4, "DECnet Phase IV"}, + { TLV_LUCENT_PRIVATE, "Lucent Proprietary"}, + { TLV_INT_IP_REACH, "IPv4 Internal Reachability"}, + { TLV_PROTOCOLS, "Protocols supported"}, + { TLV_EXT_IP_REACH, "IPv4 External Reachability"}, + { TLV_IDRP_INFO, "Inter-Domain Information Type"}, + { TLV_IPADDR, "IPv4 Interface address(es)"}, + { TLV_IPAUTH, "IPv4 authentication (deprecated)"}, + { TLV_TE_ROUTER_ID, "Traffic Engineering Router ID"}, + { TLV_EXTD_IP_REACH, "Extended IPv4 Reachability"}, + { TLV_HOSTNAME, "Hostname"}, + { TLV_SHARED_RISK_GROUP, "Shared Risk Link Group"}, + { TLV_NORTEL_PRIVATE1, "Nortel Proprietary"}, + { TLV_NORTEL_PRIVATE2, "Nortel Proprietary"}, + { TLV_HOLDTIME, "Holdtime"}, + { TLV_RESTART_SIGNALING, "Restart Signaling"}, + { TLV_MT_IS_REACH, "Multi Topology IS Reachability"}, + { TLV_MT_SUPPORTED, "Multi Topology"}, + { TLV_IP6ADDR, "IPv6 Interface address(es)"}, + { TLV_MT_IP_REACH, "Multi-Topology IPv4 Reachability"}, + { TLV_IP6_REACH, "IPv6 reachability"}, + { TLV_MT_IP6_REACH, "Multi-Topology IP6 Reachability"}, + { TLV_PTP_ADJ, "Point-to-point Adjacency State"}, + { TLV_IIH_SEQNR, "Hello PDU Sequence Number"}, + { TLV_VENDOR_PRIVATE, "Vendor Private"}, + { 0, NULL } +}; + +#define SUBTLV_EXT_IS_REACH_ADMIN_GROUP 3 /* draft-ietf-isis-traffic-05 */ +#define SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID 4 /* draft-ietf-isis-gmpls-extensions */ +#define SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID 5 /* draft-ietf-isis-traffic-05 */ +#define SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR 6 /* draft-ietf-isis-traffic-05 */ +#define SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR 8 /* draft-ietf-isis-traffic-05 */ +#define SUBTLV_EXT_IS_REACH_MAX_LINK_BW 9 /* draft-ietf-isis-traffic-05 */ +#define SUBTLV_EXT_IS_REACH_RESERVABLE_BW 10 /* draft-ietf-isis-traffic-05 */ +#define SUBTLV_EXT_IS_REACH_UNRESERVED_BW 11 /* draft-ietf-isis-traffic-05 */ +#define SUBTLV_EXT_IS_REACH_TE_METRIC 18 /* draft-ietf-isis-traffic-05 */ +#define SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE 20 /* draft-ietf-isis-gmpls-extensions */ +#define SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR 21 /* draft-ietf-isis-gmpls-extensions */ + +static struct tok isis_ext_is_reach_subtlv_values[] = { + { SUBTLV_EXT_IS_REACH_ADMIN_GROUP, "Administrative groups" }, + { SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID, "Link Local/Remote Identifier" }, + { SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID, "Link Remote Identifier" }, + { SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR, "IPv4 interface address" }, + { SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR, "IPv4 neighbor address" }, + { SUBTLV_EXT_IS_REACH_MAX_LINK_BW, "Maximum link bandwidth" }, + { SUBTLV_EXT_IS_REACH_RESERVABLE_BW, "Reservable link bandwidth" }, + { SUBTLV_EXT_IS_REACH_UNRESERVED_BW, "Unreserved bandwidth" }, + { SUBTLV_EXT_IS_REACH_TE_METRIC, "Traffic Engineering Metric" }, + { SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE, "Link Protection Type" }, + { SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR, "Interface Switching Capability" }, + { 250, "Reserved for cisco specific extensions" }, + { 251, "Reserved for cisco specific extensions" }, + { 252, "Reserved for cisco specific extensions" }, + { 253, "Reserved for cisco specific extensions" }, + { 254, "Reserved for cisco specific extensions" }, + { 255, "Reserved for future expansion" }, + { 0, NULL } +}; + +#define SUBTLV_EXTD_IP_REACH_ADMIN_TAG32 1 +#define SUBTLV_EXTD_IP_REACH_ADMIN_TAG64 2 + +static struct tok isis_ext_ip_reach_subtlv_values[] = { + { SUBTLV_EXTD_IP_REACH_ADMIN_TAG32, "32-Bit Administrative tag" }, + { SUBTLV_EXTD_IP_REACH_ADMIN_TAG64, "64-Bit Administrative tag" }, + { 0, NULL } +}; + +#define SUBTLV_AUTH_SIMPLE 1 +#define SUBTLV_AUTH_MD5 54 +#define SUBTLV_AUTH_MD5_LEN 16 +#define SUBTLV_AUTH_PRIVATE 255 + +static struct tok isis_subtlv_auth_values[] = { + { SUBTLV_AUTH_SIMPLE, "simple text password"}, + { SUBTLV_AUTH_MD5, "HMAC-MD5 password"}, + { SUBTLV_AUTH_PRIVATE, "Routing Domain private password"}, + { 0, NULL } +}; + +#define SUBTLV_IDRP_RES 0 +#define SUBTLV_IDRP_LOCAL 1 +#define SUBTLV_IDRP_ASN 2 + +static struct tok isis_subtlv_idrp_values[] = { + { SUBTLV_IDRP_RES, "Reserved"}, + { SUBTLV_IDRP_LOCAL, "Routing-Domain Specific"}, + { SUBTLV_IDRP_ASN, "AS Number Tag"}, + { 0, NULL} +}; + +#define ISIS_8BIT_MASK(x) ((x)&0xff) + +#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_MTID(x) ((x)&0x0fff) +#define ISIS_MASK_MTFLAGS(x) ((x)&0xf000) + +static struct tok isis_mt_flag_values[] = { + { 0x4000, "sub-TLVs present"}, + { 0x8000, "ATT bit set"}, + { 0, NULL} +}; + +#define ISIS_MASK_TLV_EXTD_IP_UPDOWN(x) ((x)&0x80) +#define ISIS_MASK_TLV_EXTD_IP_SUBTLV(x) ((x)&0x40) + +#define ISIS_MASK_TLV_EXTD_IP6_IE(x) ((x)&0x40) +#define ISIS_MASK_TLV_EXTD_IP6_SUBTLV(x) ((x)&0x20) + +#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_MASK_TLV_SHARED_RISK_GROUP(x) ((x)&0x1) + +static struct tok isis_mt_values[] = { + { 0, "IPv4 unicast"}, + { 1, "In-Band Management"}, + { 2, "IPv6 unicast"}, + { 3, "Multicast"}, + { 4095, "Development, Experimental or Proprietary"}, + { 0, NULL } +}; -#define CLNS 129 -#define ESIS 130 -#define ISIS 131 -#define NULLNS 0 +static struct tok isis_iih_circuit_type_values[] = { + { 1, "Level 1 only"}, + { 2, "Level 2 only"}, + { 3, "Level 1, Level 2"}, + { 0, NULL} +}; + +#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 osi_nlpid_values[] = { + { NLPID_CLNS, "CLNS"}, + { NLPID_IP, "IPv4"}, + { NLPID_IP6, "IPv6"}, + { 0, NULL } +}; + +/* + * Katz's point to point adjacency TLV uses codes to tell us the state of + * the remote adjacency. Enumerate them. + */ + +#define ISIS_PTP_ADJ_UP 0 +#define ISIS_PTP_ADJ_INIT 1 +#define ISIS_PTP_ADJ_DOWN 2 + + +static struct tok isis_ptp_adjancey_values[] = { + { ISIS_PTP_ADJ_UP, "Up" }, + { ISIS_PTP_ADJ_INIT, "Initializing" }, + { ISIS_PTP_ADJ_DOWN, "Down" }, + { 0, NULL} +}; + +struct isis_tlv_ptp_adj { + u_int8_t adjacency_state; + u_int8_t extd_local_circuit_id[4]; + u_int8_t neighbor_sysid[SYSTEM_ID_LEN]; + u_int8_t neighbor_extd_local_circuit_id[4]; +}; + +static int osi_cksum(const u_int8_t *, u_int); +static void esis_print(const u_int8_t *, u_int); +static int isis_print(const u_int8_t *, u_int); + +struct isis_metric_block { + u_int8_t metric_default; + u_int8_t metric_delay; + u_int8_t metric_expense; + u_int8_t metric_error; +}; + +struct isis_tlv_is_reach { + struct isis_metric_block isis_metric_block; + u_int8_t neighbor_nodeid[NODE_ID_LEN]; +}; + +struct isis_tlv_es_reach { + struct isis_metric_block isis_metric_block; + u_int8_t neighbor_sysid[SYSTEM_ID_LEN]; +}; + +struct isis_tlv_ip_reach { + struct isis_metric_block isis_metric_block; + u_int8_t prefix[4]; + u_int8_t mask[4]; +}; -static int osi_cksum(const u_char *, u_int, const u_char *, u_char *, u_char *); -static void esis_print(const u_char *, u_int); +static struct tok isis_is_reach_virtual_values[] = { + { 0, "IsNotVirtual"}, + { 1, "IsVirtual"}, + { 0, NULL } +}; + +static struct tok isis_restart_flag_values[] = { + { 0x1, "Restart Request"}, + { 0x2, "Restart Acknowledgement"}, + { 0, NULL } +}; -void -isoclns_print(const u_char *p, u_int length, u_int caplen, - const u_char *esrc, const u_char *edst) +struct isis_common_header { + u_int8_t nlpid; + u_int8_t fixed_len; + u_int8_t version; /* Protocol version */ + u_int8_t id_length; + u_int8_t pdu_type; /* 3 MSbits are reserved */ + u_int8_t pdu_version; /* Packet format version */ + u_int8_t reserved; + u_int8_t max_area; +}; + +struct isis_iih_lan_header { + u_int8_t circuit_type; + u_int8_t source_id[SYSTEM_ID_LEN]; + u_int8_t holding_time[2]; + u_int8_t pdu_len[2]; + u_int8_t priority; + u_int8_t lan_id[NODE_ID_LEN]; +}; + +struct isis_iih_ptp_header { + u_int8_t circuit_type; + u_int8_t source_id[SYSTEM_ID_LEN]; + u_int8_t holding_time[2]; + u_int8_t pdu_len[2]; + u_int8_t circuit_id; +}; + +struct isis_lsp_header { + u_int8_t pdu_len[2]; + u_int8_t remaining_lifetime[2]; + u_int8_t lsp_id[LSP_ID_LEN]; + u_int8_t sequence_number[4]; + u_int8_t checksum[2]; + u_int8_t typeblock; +}; + +struct isis_csnp_header { + u_int8_t pdu_len[2]; + u_int8_t source_id[NODE_ID_LEN]; + u_int8_t start_lsp_id[LSP_ID_LEN]; + u_int8_t end_lsp_id[LSP_ID_LEN]; +}; + +struct isis_psnp_header { + u_int8_t pdu_len[2]; + u_int8_t source_id[NODE_ID_LEN]; +}; + +struct isis_tlv_lsp { + u_int8_t remaining_lifetime[2]; + u_int8_t lsp_id[LSP_ID_LEN]; + u_int8_t sequence_number[4]; + u_int8_t checksum[2]; +}; + +static char * +print_nsap(register const u_int8_t *pptr, register int nsap_length) { - if (caplen < 1) { - printf("[|iso-clns] "); - if (!eflag) - printf("%s > %s", - etheraddr_string(esrc), - etheraddr_string(edst)); - return; + int nsap_idx; + static char nsap_ascii_output[sizeof("xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xx")]; + char *junk_buf = nsap_ascii_output; + + if (nsap_length < 1 || nsap_length > 20) { + snprintf(nsap_ascii_output, sizeof(nsap_ascii_output), + "illegal length"); + return (nsap_ascii_output); + } + + for (nsap_idx = 0; nsap_idx < nsap_length; nsap_idx++) { + if (!TTEST2(*pptr, 1)) + return (0); + snprintf(junk_buf, + sizeof(nsap_ascii_output) - (junk_buf - nsap_ascii_output), + "%02x", *pptr++); + junk_buf += strlen(junk_buf); + if (((nsap_idx & 1) == 0) && + (nsap_idx + 1 < nsap_length)) { + *junk_buf++ = '.'; + } } + *(junk_buf) = '\0'; + return (nsap_ascii_output); +} + +#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_int8_t *p, u_int length, u_int caplen) +{ + const struct isis_common_header *header; + + header = (const struct isis_common_header *)p; + + printf("%sOSI", caplen < 1 ? "|" : ""); + + if (caplen < 1) /* enough bytes on the wire ? */ + return; switch (*p) { - case CLNS: - /* esis_print(&p, &length); */ - printf("iso-clns"); - if (!eflag) - (void)printf(" %s > %s", - etheraddr_string(esrc), - etheraddr_string(edst)); + case NLPID_CLNS: + (void)printf(", CLNS, length %u", length); break; - case ESIS: - printf("iso-esis"); - if (!eflag) - (void)printf(" %s > %s", - etheraddr_string(esrc), - etheraddr_string(edst)); + case NLPID_ESIS: esis_print(p, length); return; - case ISIS: - printf("iso-isis"); - if (!eflag) - (void)printf(" %s > %s", - etheraddr_string(esrc), - etheraddr_string(edst)); - /* isis_print(&p, &length); */ - (void)printf(" len=%d ", length); - if (caplen > 1) - default_print_unaligned(p, caplen); + case NLPID_ISIS: + if (!isis_print(p, length)) + print_unknown_data(p,"\n\t",caplen); break; - case NULLNS: - printf("iso-nullns"); - if (!eflag) - (void)printf(" %s > %s", - etheraddr_string(esrc), - etheraddr_string(edst)); + case NLPID_NULLNS: + (void)printf(", ISO NULLNS, length: %u", length); break; default: - printf("iso-clns %02x", p[0]); - if (!eflag) - (void)printf(" %s > %s", - etheraddr_string(esrc), - etheraddr_string(edst)); - (void)printf(" len=%d ", length); + (void)printf(", Unknown NLPID 0x%02x, length: %u", p[0], length); if (caplen > 1) - default_print_unaligned(p, caplen); + print_unknown_data(p,"\n\t",caplen); break; } } @@ -123,30 +512,37 @@ isoclns_print(const u_char *p, u_int length, u_int caplen, #define ESIS_ESH 2 #define ESIS_ISH 4 +static struct tok esis_values[] = { + { ESIS_REDIRECT, "redirect"}, + { ESIS_ESH, "ESH"}, + { ESIS_ISH, "ISH"}, + { 0, NULL } +}; + struct esis_hdr { - u_char version; - u_char reserved; - u_char type; - u_char tmo[2]; - u_char cksum[2]; + u_int8_t version; + u_int8_t reserved; + u_int8_t type; + u_int8_t tmo[2]; + u_int8_t cksum[2]; }; static void -esis_print(const u_char *p, u_int length) +esis_print(const u_int8_t *p, u_int length) { - const u_char *ep; - int li = p[1]; - const struct esis_hdr *eh = (const struct esis_hdr *) &p[2]; - u_char cksum[2]; - u_char off[2]; + const u_int8_t *ep; + u_int li; + const struct esis_hdr *eh; - 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) @@ -165,29 +561,18 @@ esis_print(const u_char *p, u_int length) } return; } - switch (eh->type & 0x1f) { - - case ESIS_REDIRECT: - printf(" redirect"); - break; - case ESIS_ESH: - printf(" esh"); - break; + printf(", ES-IS, %s, length %u", + tok2str(esis_values,"unknown type: %u",eh->type & 0x1f), + length); - case ESIS_ISH: - printf(" ish"); - break; + if(vflag < 1) + return; - default: - printf(" type %d", eh->type & 0x1f); - break; - } - off[0] = eh->cksum[0]; - off[1] = eh->cksum[1]; - if (vflag && osi_cksum(p, li, eh->cksum, cksum, off)) { - printf(" bad cksum (got %02x%02x want %02x%02x)", - eh->cksum[1], eh->cksum[0], cksum[1], cksum[0]); + if (vflag && osi_cksum(p, li)) { + printf(" bad cksum (got 0x%02x%02x)", + eh->cksum[1], eh->cksum[0]); + default_print(p, length); return; } if (eh->version != 1) { @@ -199,12 +584,12 @@ esis_print(const u_char *p, u_int length) switch (eh->type & 0x1f) { case ESIS_REDIRECT: { - const u_char *dst, *snpa, *is; + const u_int8_t *dst, *snpa, *is; dst = p; p += *p + 1; if (p > snapend) return; - printf(" %s", isonsap_string(dst)); + printf("\n\t\t %s", isonsap_string(dst)); snpa = p; p += *p + 1; is = p; p += *p + 1; if (p > snapend) @@ -220,13 +605,12 @@ esis_print(const u_char *p, u_int length) li = ep - p; break; } -#if 0 + case ESIS_ESH: - printf(" esh"); break; -#endif + case ESIS_ISH: { - const u_char *is; + const u_int8_t *is; is = p; p += *p + 1; if (p > ep) { @@ -235,83 +619,1419 @@ esis_print(const u_char *p, u_int length) } if (p > snapend) return; - printf(" %s", isonsap_string(is)); + if (!qflag) + printf("\n\tNET: %s", print_nsap(is+1,*is)); li = ep - p; break; } default: - (void)printf(" len=%d", length); - if (length && p < snapend) { - length = snapend - p; - default_print(p, length); - } - return; + if (vflag <= 1) { + if (p < snapend) + print_unknown_data(p,"\n\t ",snapend-p); + } + return; } + + /* hexdump - FIXME ? */ + if (vflag > 1) { + if (p < snapend) + print_unknown_data(p,"\n\t ",snapend-p); + } if (vflag) while (p < ep && li) { - int op, opli; - const u_char *q; + u_int op, opli; + const u_int8_t *q; if (snapend - p < 2) return; if (li < 2) { - printf(" bad opts/li"); + printf(", bad opts/li"); return; } op = *p++; opli = *p++; li -= 2; if (opli > li) { - printf(" opt (%d) too long", op); + printf(", opt (%d) too long", op); return; } li -= opli; q = p; p += opli; + if (snapend < p) return; - if (op == 198 && opli == 2) { - printf(" tmo=%d", q[0] * 256 + q[1]); + + if (op == TLV_HOLDTIME && opli == 2) { + printf("\n\tholdtime: %us", EXTRACT_16BITS(q)); continue; } - printf (" %d:<", op); - while (--opli >= 0) - printf("%02x", *q++); - printf (">"); + + if (op == TLV_PROTOCOLS && opli >= 1) { + printf("\n\t%s (length: %u): %s", + tok2str(isis_tlv_values, "unknown", op), + opli, + tok2str(osi_nlpid_values,"Unknown 0x%02x",*q)); + continue; + } + + print_unknown_data(q,"\n\t ",opli); } } +/* shared routine for printing system, node and lsp-ids */ +static char * +isis_print_id(const u_int8_t *cp, int id_len) +{ + int i; + static char id[sizeof("xxxx.xxxx.xxxx.yy-zz")]; + char *pos = id; + + for (i = 1; i <= SYSTEM_ID_LEN; i++) { + snprintf(pos, sizeof(id) - (pos - id), "%02x", *cp++); + pos += strlen(pos); + if (i == 2 || i == 4) + *pos++ = '.'; + } + if (id_len >= NODE_ID_LEN) { + snprintf(pos, sizeof(id) - (pos - id), ".%02x", *cp++); + pos += strlen(pos); + } + if (id_len == LSP_ID_LEN) + snprintf(pos, sizeof(id) - (pos - id), "-%02x", *cp); + return (id); +} + +/* print the 4-byte metric block which is common found in the old-style TLVs */ static int -osi_cksum(register const u_char *p, register u_int len, - const u_char *toff, u_char *cksum, u_char *off) +isis_print_metric_block (const struct isis_metric_block *isis_metric_block) { - int x, y, f = (len - ((toff - p) + 1)); - int32_t c0 = 0, c1 = 0; + printf(", Default Metric: %d, %s", + ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_default), + ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_default) ? "External" : "Internal"); + if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_delay)) + printf("\n\t\t Delay Metric: %d, %s", + ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_delay), + ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_delay) ? "External" : "Internal"); + if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_expense)) + printf("\n\t\t Expense Metric: %d, %s", + ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_expense), + ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_expense) ? "External" : "Internal"); + if (!ISIS_LSP_TLV_METRIC_SUPPORTED(isis_metric_block->metric_error)) + printf("\n\t\t Error Metric: %d, %s", + ISIS_LSP_TLV_METRIC_VALUE(isis_metric_block->metric_error), + ISIS_LSP_TLV_METRIC_IE(isis_metric_block->metric_error) ? "External" : "Internal"); + + return(1); /* everything is ok */ +} - if ((cksum[0] = off[0]) == 0 && (cksum[1] = off[1]) == 0) - return 0; +static int +isis_print_tlv_ip_reach (const u_int8_t *cp, const char *ident, int length) +{ + int 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 ((size_t)length < sizeof(*tlv_ip_reach)) { + printf("short IPv4 Reachability (%d vs %lu)", + length, + (unsigned long)sizeof(*tlv_ip_reach)); + return (0); + } + + if (!TTEST(*tlv_ip_reach)) + return (0); + + prefix_len = mask2plen(EXTRACT_32BITS(tlv_ip_reach->mask)); + + if (prefix_len == -1) + printf("%sIPv4 prefix: %s mask %s", + ident, + ipaddr_string((tlv_ip_reach->prefix)), + ipaddr_string((tlv_ip_reach->mask))); + else + printf("%sIPv4 prefix: %15s/%u", + ident, + ipaddr_string((tlv_ip_reach->prefix)), + prefix_len); + + printf(", Distribution: %s, Metric: %u, %s", + ISIS_LSP_TLV_METRIC_UPDOWN(tlv_ip_reach->isis_metric_block.metric_default) ? "down" : "up", + ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_default), + ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_default) ? "External" : "Internal"); + + if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_delay)) + printf("%s Delay Metric: %u, %s", + ident, + ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_delay), + ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_delay) ? "External" : "Internal"); + + if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_expense)) + printf("%s Expense Metric: %u, %s", + ident, + ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_expense), + ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_expense) ? "External" : "Internal"); + + if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_error)) + printf("%s Error Metric: %u, %s", + ident, + ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_error), + ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_error) ? "External" : "Internal"); + + length -= sizeof(struct isis_tlv_ip_reach); + tlv_ip_reach++; + } + return (1); +} + +/* + * this is the common IP-REACH subTLV decoder it is called + * from various EXTD-IP REACH TLVs (135,235,236,237) + */ + +static int +isis_print_ip_reach_subtlv (const u_int8_t *tptr,int subt,int subl,const char *ident) { + + /* first lets see if we know the subTLVs name*/ + printf("%s%s subTLV #%u, length: %u", + ident, + tok2str(isis_ext_ip_reach_subtlv_values, + "unknown", + subt), + subt, + subl); + + if (!TTEST2(*tptr,subl)) + goto trunctlv; + + switch(subt) { + case SUBTLV_EXTD_IP_REACH_ADMIN_TAG32: + while (subl >= 4) { + printf(", 0x%08x (=%u)", + EXTRACT_32BITS(tptr), + EXTRACT_32BITS(tptr)); + tptr+=4; + subl-=4; + } + break; + case SUBTLV_EXTD_IP_REACH_ADMIN_TAG64: + while (subl >= 8) { + printf(", 0x%08x%08x", + EXTRACT_32BITS(tptr), + EXTRACT_32BITS(tptr+4)); + tptr+=8; + subl-=8; + } + break; + default: + if(!print_unknown_data(tptr,"\n\t\t ", + subl)) + return(0); + break; + } + return(1); + +trunctlv: + printf("%spacket exceeded snapshot",ident); + return(0); +} + +/* + * this is the common IS-REACH subTLV decoder it is called + * from isis_print_ext_is_reach() + */ + +static int +isis_print_is_reach_subtlv (const u_int8_t *tptr,int subt,int subl,const char *ident) { + + int priority_level; + union { /* int to float conversion buffer for several subTLVs */ + float f; + u_int32_t i; + } bw; + + /* first lets see if we know the subTLVs name*/ + printf("%s%s subTLV #%u, length: %u", + ident, + tok2str(isis_ext_is_reach_subtlv_values, + "unknown", + subt), + subt, + subl); + + if (!TTEST2(*tptr,subl)) + goto trunctlv; + + switch(subt) { + case SUBTLV_EXT_IS_REACH_ADMIN_GROUP: + case SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID: + case SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID: + if (subl >= 4) { + printf(", 0x%08x", EXTRACT_32BITS(tptr)); + if (subl == 8) /* draft-ietf-isis-gmpls-extensions */ + printf(", 0x%08x", EXTRACT_32BITS(tptr+4)); + } + break; + case SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR: + case SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR: + if (subl >= 4) + printf(", %s", ipaddr_string(tptr)); + break; + case SUBTLV_EXT_IS_REACH_MAX_LINK_BW : + case SUBTLV_EXT_IS_REACH_RESERVABLE_BW: + if (subl >= 4) { + bw.i = EXTRACT_32BITS(tptr); + printf(", %.3f Mbps", bw.f*8/1000000 ); + } + break; + case SUBTLV_EXT_IS_REACH_UNRESERVED_BW : + if (subl >= 32) { + for (priority_level = 0; priority_level < 8; priority_level++) { + bw.i = EXTRACT_32BITS(tptr); + printf("%s priority level %d: %.3f Mbps", + ident, + priority_level, + bw.f*8/1000000 ); + tptr+=4; + } + } + break; + case SUBTLV_EXT_IS_REACH_TE_METRIC: + if (subl >= 3) + printf(", %u", EXTRACT_24BITS(tptr)); + break; + case SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE: + if (subl >= 2) { + printf(", %s, Priority %u", + bittok2str(gmpls_link_prot_values, "none", *tptr), + *(tptr+1)); + } + break; + case SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR: + if (subl >= 36) { + printf("%s Interface Switching Capability:%s", + ident, + tok2str(gmpls_switch_cap_values, "Unknown", *(tptr))); + printf(", LSP Encoding: %s", + tok2str(gmpls_encoding_values, "Unknown", *(tptr+1))); + tptr+=4; + printf("%s Max LSP Bandwidth:",ident); + for (priority_level = 0; priority_level < 8; priority_level++) { + bw.i = EXTRACT_32BITS(tptr); + printf("%s priority level %d: %.3f Mbps", + ident, + priority_level, + bw.f*8/1000000 ); + tptr+=4; + } + subl-=36; + /* there is some optional stuff left to decode but this is as of yet + not specified so just lets hexdump what is left */ + if(subl>0){ + if(!print_unknown_data(tptr,"\n\t\t ", + subl-36)) + return(0); + } + } + break; + default: + if(!print_unknown_data(tptr,"\n\t\t ", + subl)) + return(0); + break; + } + return(1); + +trunctlv: + printf("%spacket exceeded snapshot",ident); + return(0); +} + + +/* + * this is the common IS-REACH decoder it is called + * from various EXTD-IS REACH style TLVs (22,24,222) + */ + +static int +isis_print_ext_is_reach (const u_int8_t *tptr,const char *ident, int tlv_type) { + + char ident_buffer[20]; + int subtlv_type,subtlv_len,subtlv_sum_len; + int proc_bytes = 0; /* how many bytes did we process ? */ + + if (!TTEST2(*tptr, NODE_ID_LEN)) + return(0); + + printf("%sIS Neighbor: %s", ident, isis_print_id(tptr, NODE_ID_LEN)); + tptr+=(NODE_ID_LEN); + + if (tlv_type != TLV_IS_ALIAS_ID) { /* the Alias TLV Metric field is implicit 0 */ + if (!TTEST2(*tptr, 3)) /* and is therefore skipped */ + return(0); + printf(", Metric: %d",EXTRACT_24BITS(tptr)); + tptr+=3; + } + + if (!TTEST2(*tptr, 1)) + return(0); + subtlv_sum_len=*(tptr++); /* read out subTLV length */ + proc_bytes=NODE_ID_LEN+3+1; + printf(", %ssub-TLVs present",subtlv_sum_len ? "" : "no "); + if (subtlv_sum_len) { + printf(" (%u)",subtlv_sum_len); + while (subtlv_sum_len>0) { + if (!TTEST2(*tptr,2)) + return(0); + subtlv_type=*(tptr++); + subtlv_len=*(tptr++); + /* prepend the ident string */ + snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident); + if(!isis_print_is_reach_subtlv(tptr,subtlv_type,subtlv_len,ident_buffer)) + return(0); + tptr+=subtlv_len; + subtlv_sum_len-=(subtlv_len+2); + proc_bytes+=(subtlv_len+2); + } + } + return(proc_bytes); +} + +/* + * this is the common Multi Topology ID decoder + * it is called from various MT-TLVs (222,229,235,237) + */ + +static int +isis_print_mtid (const u_int8_t *tptr,const char *ident) { + + if (!TTEST2(*tptr, 2)) + return(0); + + printf("%s%s", + ident, + tok2str(isis_mt_values, + "Reserved for IETF Consensus", + ISIS_MASK_MTID(EXTRACT_16BITS(tptr)))); + + printf(" Topology (0x%03x), Flags: [%s]", + ISIS_MASK_MTID(EXTRACT_16BITS(tptr)), + bittok2str(isis_mt_flag_values, "none",ISIS_MASK_MTFLAGS(EXTRACT_16BITS(tptr)))); + + return(2); +} + +/* + * this is the common extended IP reach decoder + * it is called from TLVs (135,235,236,237) + * we process the TLV and optional subTLVs and return + * the amount of processed bytes + */ + +static int +isis_print_extd_ip_reach (const u_int8_t *tptr, const char *ident, u_int16_t afi) { + + char ident_buffer[20]; + u_int8_t prefix[16]; /* shared copy buffer for IPv4 and IPv6 prefixes */ + u_int metric, status_byte, bit_length, byte_length, sublen, processed, subtlvtype, subtlvlen; + + if (!TTEST2(*tptr, 4)) + return (0); + metric = EXTRACT_32BITS(tptr); + processed=4; + tptr+=4; + + if (afi == IPV4) { + if (!TTEST2(*tptr, 1)) /* fetch status byte */ + return (0); + status_byte=*(tptr++); + bit_length = status_byte&0x3f; + processed++; +#ifdef INET6 + } else if (afi == IPV6) { + if (!TTEST2(*tptr, 1)) /* fetch status & prefix_len byte */ + return (0); + status_byte=*(tptr++); + bit_length=*(tptr++); + processed+=2; +#endif + } else + return (0); /* somebody is fooling us */ + + byte_length = (bit_length + 7) / 8; /* prefix has variable length encoding */ + + if (!TTEST2(*tptr, byte_length)) + return (0); + memset(prefix, 0, 16); /* clear the copy buffer */ + memcpy(prefix,tptr,byte_length); /* copy as much as is stored in the TLV */ + tptr+=byte_length; + processed+=byte_length; + + if (afi == IPV4) + printf("%sIPv4 prefix: %15s/%u", + ident, + ipaddr_string(prefix), + bit_length); +#ifdef INET6 + if (afi == IPV6) + printf("%sIPv6 prefix: %s/%u", + ident, + ip6addr_string(prefix), + bit_length); +#endif + + printf(", Distribution: %s, Metric: %u", + ISIS_MASK_TLV_EXTD_IP_UPDOWN(status_byte) ? "down" : "up", + metric); + + if (afi == IPV4 && ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte)) + printf(", sub-TLVs present"); +#ifdef INET6 + if (afi == IPV6) + printf(", %s%s", + ISIS_MASK_TLV_EXTD_IP6_IE(status_byte) ? "External" : "Internal", + ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte) ? ", sub-TLVs present" : ""); +#endif + + if ((ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte) && afi == IPV4) || + (ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte) && afi == IPV6)) { + /* assume that one prefix can hold more + than one subTLV - therefore the first byte must reflect + the aggregate bytecount of the subTLVs for this prefix + */ + if (!TTEST2(*tptr, 1)) + return (0); + sublen=*(tptr++); + processed+=sublen+1; + printf(" (%u)",sublen); /* print out subTLV length */ + + while (sublen>0) { + if (!TTEST2(*tptr,2)) + return (0); + subtlvtype=*(tptr++); + subtlvlen=*(tptr++); + /* prepend the ident string */ + snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident); + if(!isis_print_ip_reach_subtlv(tptr,subtlvtype,subtlvlen,ident_buffer)) + return(0); + tptr+=subtlvlen; + sublen-=(subtlvlen+2); + } + } + return (processed); +} + +/* + * isis_print + * Decode IS-IS packets. Return 0 on error. + */ + +static int isis_print (const u_int8_t *p, u_int length) +{ + 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; + const struct isis_tlv_es_reach *tlv_es_reach; + + u_int8_t pdu_type, max_area, id_length, tlv_type, tlv_len, tmp, alen, lan_alen, prefix_len; + u_int8_t ext_is_len, ext_ip_len, mt_len; + const u_int8_t *optr, *pptr, *tptr; + u_short packet_len,pdu_len; + u_int i; + + packet_len=length; + optr = p; /* initialize the _o_riginal pointer to the packet start - + 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->version != ISIS_VERSION) { + 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", + header->id_length); + return (0); + } + + if (header->pdu_version != ISIS_VERSION) { + printf(", version %d packet not supported", header->pdu_version); + return (0); + } + + 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); + default: + break; + } + + id_length = header->id_length; + switch(id_length) { + case 0: + id_length = 6; /* silly shit again */ + break; + case 1: /* 1-8 are valid sys-ID lenghts */ + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + break; + case 255: + id_length = 0; /* entirely useless */ + break; + default: + break; + } + + /* toss any non 6-byte sys-ID len PDUs */ + if (id_length != 6 ) { + printf(", bad packet -- illegal sys-ID length (%u)", id_length); + return (0); + } + + pdu_type=header->pdu_type; + + /* in non-verbose mode print the basic PDU Type plus PDU specific brief information*/ + if (vflag < 1) { + printf(", IS-IS, %s", + tok2str(isis_pdu_values,"unknown PDU-Type %u",pdu_type)); + + switch (pdu_type) { + + case L1_LAN_IIH: + case L2_LAN_IIH: + printf(", src-id %s", + isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN)); + printf(", lan-id %s, prio %u", + isis_print_id(header_iih_lan->lan_id,NODE_ID_LEN), + header_iih_lan->priority); + break; + case PTP_IIH: + printf(", src-id %s", isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN)); + break; + case L1_LSP: + case L2_LSP: + printf(", lsp-id %s, seq 0x%08x, lifetime %5us", + isis_print_id(header_lsp->lsp_id, LSP_ID_LEN), + EXTRACT_32BITS(header_lsp->sequence_number), + EXTRACT_16BITS(header_lsp->remaining_lifetime)); + break; + case L1_CSNP: + case L2_CSNP: + printf(", src-id %s", isis_print_id(header_csnp->source_id,SYSTEM_ID_LEN)); + break; + case L1_PSNP: + case L2_PSNP: + printf(", src-id %s", isis_print_id(header_psnp->source_id,SYSTEM_ID_LEN)); + break; + + } + printf(", length %u", length); + + return(1); + } + + /* ok they seem to want to know everything - lets fully decode it */ + printf(", IS-IS, length: %u",length); + + printf("\n\t%s, hlen: %u, v: %u, pdu-v: %u, sys-id-len: %u (%u), max-area: %u (%u)", + tok2str(isis_pdu_values, + "unknown, type %u", + pdu_type), + header->fixed_len, + header->version, + header->pdu_version, + id_length, + header->id_length, + max_area, + header->max_area); + + if (vflag > 1) { + if(!print_unknown_data(optr,"\n\t",8)) /* provide the _o_riginal pointer */ + return(0); /* for optionally debugging the common header */ + } + + 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); + } + + 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; + } + + TCHECK(*header_iih_lan); + printf("\n\t source-id: %s, holding time: %us, Flags: [%s]", + isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN), + EXTRACT_16BITS(header_iih_lan->holding_time), + tok2str(isis_iih_circuit_type_values, + "unknown circuit type 0x%02x", + header_iih_lan->circuit_type)); + + printf("\n\t lan-id: %s, Priority: %u, PDU length: %u", + isis_print_id(header_iih_lan->lan_id, NODE_ID_LEN), + (header_iih_lan->priority) & PRIORITY_MASK, + pdu_len); + + if (vflag > 1) { + if(!print_unknown_data(pptr,"\n\t ",ISIS_IIH_LAN_HEADER_SIZE)) + return(0); + } + + 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: + 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; + } + + TCHECK(*header_iih_ptp); + printf("\n\t source-id: %s, holding time: %us, Flags: [%s]", + isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN), + EXTRACT_16BITS(header_iih_ptp->holding_time), + tok2str(isis_iih_circuit_type_values, + "unknown circuit type 0x%02x", + header_iih_ptp->circuit_type)); + + printf("\n\t circuit-id: 0x%02x, PDU length: %u", + header_iih_ptp->circuit_id, + pdu_len); + + if (vflag > 1) { + if(!print_unknown_data(pptr,"\n\t ",ISIS_IIH_PTP_HEADER_SIZE)) + return(0); + } + + packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE); + pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE); + break; + + 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; + } + + TCHECK(*header_lsp); + printf("\n\t lsp-id: %s, seq: 0x%08x, lifetime: %5us\n\t chksum: 0x%04x", + isis_print_id(header_lsp->lsp_id, LSP_ID_LEN), + EXTRACT_32BITS(header_lsp->sequence_number), + EXTRACT_16BITS(header_lsp->remaining_lifetime), + EXTRACT_16BITS(header_lsp->checksum)); + + /* if this is a purge do not attempt to verify the checksum */ + if ( EXTRACT_16BITS(header_lsp->remaining_lifetime) == 0 && + EXTRACT_16BITS(header_lsp->checksum) == 0) + printf(" (purged)"); + else + /* verify the checksum - + * checking starts at the lsp-id field at byte position [12] + * hence the length needs to be reduced by 12 bytes */ + printf(" (%s)", (osi_cksum((u_int8_t *)header_lsp->lsp_id, length-12)) ? "incorrect" : "correct"); + + printf(", PDU length: %u, Flags: [ %s", + pdu_len, + 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))); + + if (vflag > 1) { + if(!print_unknown_data(pptr,"\n\t ",ISIS_LSP_HEADER_SIZE)) + return(0); + } + + packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE); + pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE); + break; + + 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; + } + + TCHECK(*header_csnp); + printf("\n\t source-id: %s, PDU length: %u", + isis_print_id(header_csnp->source_id, NODE_ID_LEN), + pdu_len); + printf("\n\t start lsp-id: %s", + isis_print_id(header_csnp->start_lsp_id, LSP_ID_LEN)); + printf("\n\t end lsp-id: %s", + isis_print_id(header_csnp->end_lsp_id, LSP_ID_LEN)); + + if (vflag > 1) { + if(!print_unknown_data(pptr,"\n\t ",ISIS_CSNP_HEADER_SIZE)) + return(0); + } + + 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; + } + + TCHECK(*header_psnp); + printf("\n\t source-id: %s, PDU length: %u", + isis_print_id(header_psnp->source_id, NODE_ID_LEN), + pdu_len); + + if (vflag > 1) { + if(!print_unknown_data(pptr,"\n\t ",ISIS_PSNP_HEADER_SIZE)) + return(0); + } + + packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE); + pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE); + break; + + default: + if(!print_unknown_data(pptr,"\n\t ",length)) + return(0); + return (0); + } + + /* + * Now print the TLV's. + */ + + while (packet_len >= 2) { + if (pptr == snapend) { + return (1); + } + + if (!TTEST2(*pptr, 2)) { + printf("\n\t\t packet exceeded snapshot (%ld) bytes", + (long)(pptr-snapend)); + return (1); + } + tlv_type = *pptr++; + tlv_len = *pptr++; + tmp =tlv_len; /* copy temporary len & pointer to packet data */ + tptr = pptr; + packet_len -= 2; + if (tlv_len > packet_len) { + break; + } + + /* first lets see if we know the TLVs name*/ + printf("\n\t %s TLV #%u, length: %u", + tok2str(isis_tlv_values, + "unknown", + tlv_type), + tlv_type, + tlv_len); + + /* now check if we have a decoder otherwise do a hexdump at the end*/ + switch (tlv_type) { + case TLV_AREA_ADDR: + if (!TTEST2(*tptr, 1)) + goto trunctlv; + alen = *tptr++; + while (tmp && alen < tmp) { + printf("\n\t Area address (length: %u): %s", + alen, + print_nsap(tptr, alen)); + 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: + while (tmp >= ETHER_ADDR_LEN) { + if (!TTEST2(*tptr, ETHER_ADDR_LEN)) + goto trunctlv; + printf("\n\t SNPA: %s",isis_print_id(tptr,ETHER_ADDR_LEN)); + tmp -= ETHER_ADDR_LEN; + tptr += ETHER_ADDR_LEN; + } + break; + + case TLV_ISNEIGH_VARLEN: + if (!TTEST2(*tptr, 1)) + goto trunctlv; + lan_alen = *tptr++; /* LAN adress length */ + tmp --; + printf("\n\t LAN address length %u bytes ",lan_alen); + while (tmp >= lan_alen) { + if (!TTEST2(*tptr, lan_alen)) + goto trunctlv; + printf("\n\t\tIS Neighbor: %s",isis_print_id(tptr,lan_alen)); + tmp -= lan_alen; + tptr +=lan_alen; + } + break; + + case TLV_PADDING: + break; + + case TLV_MT_IS_REACH: + while (tmp >= 2+NODE_ID_LEN+3+1) { + mt_len = isis_print_mtid(tptr, "\n\t "); + if (mt_len == 0) /* did something go wrong ? */ + goto trunctlv; + tptr+=mt_len; + tmp-=mt_len; + + ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type); + if (ext_is_len == 0) /* did something go wrong ? */ + goto trunctlv; + + tmp-=ext_is_len; + tptr+=ext_is_len; + } + break; + + case TLV_IS_ALIAS_ID: + while (tmp >= NODE_ID_LEN+1) { /* is it worth attempting a decode ? */ + ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type); + if (ext_is_len == 0) /* did something go wrong ? */ + goto trunctlv; + tmp-=ext_is_len; + tptr+=ext_is_len; + } + break; + + case TLV_EXT_IS_REACH: + while (tmp >= NODE_ID_LEN+3+1) { /* is it worth attempting a decode ? */ + ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type); + if (ext_is_len == 0) /* did something go wrong ? */ + goto trunctlv; + tmp-=ext_is_len; + tptr+=ext_is_len; + } + break; + case TLV_IS_REACH: + if (!TTEST2(*tptr,1)) /* check if there is one byte left to read out the virtual flag */ + goto trunctlv; + printf("\n\t %s", + tok2str(isis_is_reach_virtual_values, + "bogus virtual flag 0x%02x", + *tptr++)); + tlv_is_reach = (const struct isis_tlv_is_reach *)tptr; + while (tmp >= sizeof(struct isis_tlv_is_reach)) { + if (!TTEST(*tlv_is_reach)) + goto trunctlv; + printf("\n\t IS Neighbor: %s", + isis_print_id(tlv_is_reach->neighbor_nodeid, NODE_ID_LEN)); + isis_print_metric_block(&tlv_is_reach->isis_metric_block); + tmp -= sizeof(struct isis_tlv_is_reach); + tlv_is_reach++; + } + break; + + case TLV_ESNEIGH: + tlv_es_reach = (const struct isis_tlv_es_reach *)tptr; + while (tmp >= sizeof(struct isis_tlv_es_reach)) { + if (!TTEST(*tlv_es_reach)) + goto trunctlv; + printf("\n\t ES Neighbor: %s", + isis_print_id(tlv_es_reach->neighbor_sysid,SYSTEM_ID_LEN)); + isis_print_metric_block(&tlv_es_reach->isis_metric_block); + tmp -= sizeof(struct isis_tlv_es_reach); + tlv_es_reach++; + } + break; + + /* those two TLVs share the same format */ + case TLV_INT_IP_REACH: + case TLV_EXT_IP_REACH: + if (!isis_print_tlv_ip_reach(pptr, "\n\t ", tlv_len)) + return (1); + break; + + case TLV_EXTD_IP_REACH: + while (tmp>0) { + ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV4); + if (ext_ip_len == 0) /* did something go wrong ? */ + goto trunctlv; + tptr+=ext_ip_len; + tmp-=ext_ip_len; + } + break; + + case TLV_MT_IP_REACH: + while (tmp>0) { + mt_len = isis_print_mtid(tptr, "\n\t "); + if (mt_len == 0) /* did something go wrong ? */ + goto trunctlv; + tptr+=mt_len; + tmp-=mt_len; + + ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV4); + if (ext_ip_len == 0) /* did something go wrong ? */ + goto trunctlv; + tptr+=ext_ip_len; + tmp-=ext_ip_len; + } + break; + +#ifdef INET6 + case TLV_IP6_REACH: + while (tmp>0) { + ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV6); + if (ext_ip_len == 0) /* did something go wrong ? */ + goto trunctlv; + tptr+=ext_ip_len; + tmp-=ext_ip_len; + } + break; + + case TLV_MT_IP6_REACH: + while (tmp>0) { + mt_len = isis_print_mtid(tptr, "\n\t "); + if (mt_len == 0) /* did something go wrong ? */ + goto trunctlv; + tptr+=mt_len; + tmp-=mt_len; + + ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV6); + if (ext_ip_len == 0) /* did something go wrong ? */ + goto trunctlv; + tptr+=ext_ip_len; + tmp-=ext_ip_len; + } + break; + + case TLV_IP6ADDR: + while (tmp>0) { + if (!TTEST2(*tptr, 16)) + goto trunctlv; + + printf("\n\t IPv6 interface address: %s", + ip6addr_string(tptr)); + + tptr += 16; + tmp -= 16; + } + break; +#endif + case TLV_AUTH: + if (!TTEST2(*tptr, 1)) + goto trunctlv; + + printf("\n\t %s: ", + tok2str(isis_subtlv_auth_values, + "unknown Authentication type 0x%02x", + *tptr)); + + switch (*tptr) { + case SUBTLV_AUTH_SIMPLE: + for(i=1;i=1) { + if (!TTEST2(*tptr, 1)) + goto trunctlv; + printf("\n\t Adjacency State: %s (%u)", + tok2str(isis_ptp_adjancey_values, "unknown", *tptr), + *tptr); + tmp--; + } + if(tmp>sizeof(tlv_ptp_adj->extd_local_circuit_id)) { + if (!TTEST2(tlv_ptp_adj->extd_local_circuit_id, + sizeof(tlv_ptp_adj->extd_local_circuit_id))) + goto trunctlv; + printf("\n\t Extended Local circuit-ID: 0x%08x", + EXTRACT_32BITS(tlv_ptp_adj->extd_local_circuit_id)); + tmp-=sizeof(tlv_ptp_adj->extd_local_circuit_id); + } + if(tmp>=SYSTEM_ID_LEN) { + if (!TTEST2(tlv_ptp_adj->neighbor_sysid, SYSTEM_ID_LEN)) + goto trunctlv; + printf("\n\t Neighbor System-ID: %s", + isis_print_id(tlv_ptp_adj->neighbor_sysid,SYSTEM_ID_LEN)); + tmp-=SYSTEM_ID_LEN; + } + if(tmp>=sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id)) { + if (!TTEST2(tlv_ptp_adj->neighbor_extd_local_circuit_id, + sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id))) + goto trunctlv; + printf("\n\t Neighbor Extended Local circuit-ID: 0x%08x", + EXTRACT_32BITS(tlv_ptp_adj->neighbor_extd_local_circuit_id)); + } + break; + + case TLV_PROTOCOLS: + printf("\n\t NLPID(s): "); + while (tmp>0) { + if (!TTEST2(*(tptr), 1)) + goto trunctlv; + printf("%s (0x%02x)", + tok2str(osi_nlpid_values, + "unknown", + *tptr), + *tptr); + if (tmp>1) /* further NPLIDs ? - put comma */ + printf(", "); + tptr++; + tmp--; + } + break; + + case TLV_TE_ROUTER_ID: + if (!TTEST2(*pptr, 4)) + goto trunctlv; + printf("\n\t Traffic Engineering Router ID: %s", ipaddr_string(pptr)); + break; + + case TLV_IPADDR: + while (tmp>0) { + if (!TTEST2(*tptr, 4)) + goto trunctlv; + printf("\n\t IPv4 interface address: %s", ipaddr_string(tptr)); + tptr += 4; + tmp -= 4; + } + break; + + case TLV_HOSTNAME: + printf("\n\t Hostname: "); + while (tmp>0) { + if (!TTEST2(*tptr, 1)) + goto trunctlv; + printf("%c",*tptr++); + tmp--; + } + break; + + case TLV_SHARED_RISK_GROUP: + if (!TTEST2(*tptr, NODE_ID_LEN)) + goto trunctlv; + printf("\n\t IS Neighbor: %s", isis_print_id(tptr, NODE_ID_LEN)); + tptr+=(NODE_ID_LEN); + tmp-=(NODE_ID_LEN); + + if (!TTEST2(*tptr, 1)) + goto trunctlv; + printf(", Flags: [%s]", ISIS_MASK_TLV_SHARED_RISK_GROUP(*tptr++) ? "numbered" : "unnumbered"); + tmp--; + + if (!TTEST2(*tptr,4)) + goto trunctlv; + printf("\n\t IPv4 interface address: %s", ipaddr_string(tptr)); + tptr+=4; + tmp-=4; + + if (!TTEST2(*tptr,4)) + goto trunctlv; + printf("\n\t IPv4 neighbor address: %s", ipaddr_string(tptr)); + tptr+=4; + tmp-=4; + + while (tmp>0) { + if (!TTEST2(*tptr, 4)) + goto trunctlv; + printf("\n\t Link-ID: 0x%08x", EXTRACT_32BITS(tptr)); + tptr+=4; + tmp-=4; + } + break; + + case TLV_LSP: + tlv_lsp = (const struct isis_tlv_lsp *)tptr; + while(tmp>0) { + if (!TTEST((tlv_lsp->lsp_id)[LSP_ID_LEN-1])) + goto trunctlv; + printf("\n\t lsp-id: %s", + isis_print_id(tlv_lsp->lsp_id, LSP_ID_LEN)); + if (!TTEST2(tlv_lsp->sequence_number, 4)) + goto trunctlv; + printf(", seq: 0x%08x",EXTRACT_32BITS(tlv_lsp->sequence_number)); + if (!TTEST2(tlv_lsp->remaining_lifetime, 2)) + goto trunctlv; + printf(", lifetime: %5ds",EXTRACT_16BITS(tlv_lsp->remaining_lifetime)); + if (!TTEST2(tlv_lsp->checksum, 2)) + goto trunctlv; + printf(", chksum: 0x%04x",EXTRACT_16BITS(tlv_lsp->checksum)); + tmp-=sizeof(struct isis_tlv_lsp); + tlv_lsp++; + } + break; + + case TLV_CHECKSUM: + if (!TTEST2(*tptr, 2)) + goto trunctlv; + printf("\n\t checksum: 0x%04x ", EXTRACT_16BITS(tptr)); + /* do not attempt to verify the checksum if it is zero + * most likely a HMAC-MD5 TLV is also present and + * to avoid conflicts the checksum TLV is zeroed. + * see rfc3358 for details + */ + if (EXTRACT_16BITS(tptr) == 0) + printf("(unverified)"); + else printf("(%s)", osi_cksum(optr, length) ? "incorrect" : "correct"); + break; + + case TLV_MT_SUPPORTED: + while (tmp>1) { + /* length can only be a multiple of 2, otherwise there is + something broken -> so decode down until length is 1 */ + if (tmp!=1) { + mt_len = isis_print_mtid(tptr, "\n\t "); + if (mt_len == 0) /* did something go wrong ? */ + goto trunctlv; + tptr+=mt_len; + tmp-=mt_len; + } else { + printf("\n\t malformed MT-ID"); + break; + } + } + break; + + case TLV_RESTART_SIGNALING: + if (!TTEST2(*tptr, 3)) + goto trunctlv; + printf("\n\t Flags [%s], Remaining holding time %us", + bittok2str(isis_restart_flag_values, "none", *tptr), + EXTRACT_16BITS(tptr+1)); + tptr+=3; + break; + + case TLV_IDRP_INFO: + if (!TTEST2(*tptr, 1)) + goto trunctlv; + printf("\n\t Inter-Domain Information Type: %s", + tok2str(isis_subtlv_idrp_values, + "Unknown (0x%02x)", + *tptr)); + switch (*tptr++) { + case SUBTLV_IDRP_ASN: + if (!TTEST2(*tptr, 2)) /* fetch AS number */ + goto trunctlv; + printf("AS Number: %u",EXTRACT_16BITS(tptr)); + break; + case SUBTLV_IDRP_LOCAL: + case SUBTLV_IDRP_RES: + default: + if(!print_unknown_data(tptr,"\n\t ",tlv_len-1)) + return(0); + break; + } + break; + + case TLV_LSP_BUFFERSIZE: + if (!TTEST2(*tptr, 2)) + goto trunctlv; + printf("\n\t LSP Buffersize: %u",EXTRACT_16BITS(tptr)); + break; + + case TLV_PART_DIS: + while (tmp >= SYSTEM_ID_LEN) { + if (!TTEST2(*tptr, SYSTEM_ID_LEN)) + goto trunctlv; + printf("\n\t %s",isis_print_id(tptr,SYSTEM_ID_LEN)); + tptr+=SYSTEM_ID_LEN; + tmp-=SYSTEM_ID_LEN; + } + break; + + case TLV_PREFIX_NEIGH: + if (!TTEST2(*tptr, sizeof(struct isis_metric_block))) + goto trunctlv; + printf("\n\t Metric Block"); + isis_print_metric_block((const struct isis_metric_block *)tptr); + tptr+=sizeof(struct isis_metric_block); + tmp-=sizeof(struct isis_metric_block); + + while(tmp>0) { + if (!TTEST2(*tptr, 1)) + goto trunctlv; + prefix_len=*tptr++; /* read out prefix length in semioctets*/ + tmp--; + if (!TTEST2(*tptr, prefix_len/2)) + goto trunctlv; + printf("\n\t\tAddress: %s/%u", + print_nsap(tptr,prefix_len/2), + prefix_len*4); + tptr+=prefix_len/2; + tmp-=prefix_len/2; + } + break; + + case TLV_IIH_SEQNR: + if (!TTEST2(*tptr, 4)) /* check if four bytes are on the wire */ + goto trunctlv; + printf("\n\t Sequence number: %u", EXTRACT_32BITS(tptr) ); + break; + + case TLV_VENDOR_PRIVATE: + if (!TTEST2(*tptr, 3)) /* check if enough byte for a full oui */ + goto trunctlv; + printf("\n\t Vendor OUI Code: 0x%06x", EXTRACT_24BITS(tptr) ); + tptr+=3; + tmp-=3; + if (tmp > 0) /* hexdump the rest */ + if(!print_unknown_data(tptr,"\n\t\t",tmp)) + return(0); + break; + /* + * FIXME those are the defined TLVs that lack a decoder + * you are welcome to contribute code ;-) + */ + + case TLV_DECNET_PHASE4: + case TLV_LUCENT_PRIVATE: + case TLV_IPAUTH: + case TLV_NORTEL_PRIVATE1: + case TLV_NORTEL_PRIVATE2: + + default: + if (vflag <= 1) { + if(!print_unknown_data(pptr,"\n\t\t",tlv_len)) + return(0); + } + break; + } + /* do we want to see an additionally hexdump ? */ + if (vflag> 1) { + if(!print_unknown_data(pptr,"\n\t ",tlv_len)) + return(0); + } + + pptr += tlv_len; + packet_len -= tlv_len; + } + + if (packet_len != 0) { + printf("\n\t %u straggler bytes", packet_len); + } + return (1); + + trunc: + fputs("[|isis]", stdout); + return (1); + + trunctlv: + printf("\n\t\t packet exceeded snapshot"); + return(1); +} + +/* + * Verify the checksum. See 8473-1, Appendix C, section C.4. + */ + +static int +osi_cksum(const u_int8_t *tptr, u_int len) +{ + int32_t c0 = 0, c1 = 0; - off[0] = off[1] = 0; while ((int)--len >= 0) { - c0 += *p++; - c1 += c0; + c0 += *tptr++; c0 %= 255; + c1 += c0; c1 %= 255; } - x = (c0 * f - c1); - if (x < 0) - x = 255 - (-x % 255); - else - x %= 255; - y = -1 * (x + c0); - if (y < 0) - y = 255 - (-y % 255); - else - y %= 255; - - off[0] = x; - off[1] = y; - - return (off[0] != cksum[0] || off[1] != cksum[1]); + return (c0 | c1); } diff --git a/kame/kame/tcpdump/print-krb.c b/kame/kame/tcpdump/print-krb.c index eca6265fa6..1d3a6d75a2 100644 --- a/kame/kame/tcpdump/print-krb.c +++ b/kame/kame/tcpdump/print-krb.c @@ -22,33 +22,25 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-krb.c,v 1.9 97/04/26 14:01:45 leres Exp $"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-krb.c,v 1.21.2.2 2003/11/16 08:51:30 guy Exp $"; #endif -#include -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include -#include -#include -#include -#include -#include +#include -#include -#include #include #include "interface.h" #include "addrtoname.h" +#include "extract.h" -const u_char *c_print(register const u_char *, register const u_char *); -const u_char *krb4_print_hdr(const u_char *); -void krb4_print(const u_char *); -void krb_print(const u_char *, u_int); - +static const u_char *c_print(register const u_char *, register const u_char *); +static const u_char *krb4_print_hdr(const u_char *); +static void krb4_print(const u_char *); #define AUTH_MSG_KDC_REQUEST 1<<1 #define AUTH_MSG_KDC_REPLY 2<<1 @@ -73,8 +65,8 @@ void krb_print(const u_char *, u_int); #define KERB_ERR_NULL_KEY 10 struct krb { - u_char pvno; /* Protocol Version */ - u_char type; /* Type+B */ + u_int8_t pvno; /* Protocol Version */ + u_int8_t type; /* Type+B */ }; static char tstr[] = " [|kerberos]"; @@ -107,26 +99,7 @@ static struct tok kerr2str[] = { { 0, NULL} }; - -/* little endian (unaligned) to host byte order */ -/* XXX need to look at this... */ -#define vtohlp(x) ((( ((char *)(x))[0] ) ) | \ - (( ((char *)(x))[1] ) << 8) | \ - (( ((char *)(x))[2] ) << 16) | \ - (( ((char *)(x))[3] ) << 24)) -#define vtohsp(x) ((( ((char *)(x))[0] ) ) | \ - (( ((char *)(x))[1] ) << 8)) -/* network (big endian) (unaligned) to host byte order */ -#define ntohlp(x) ((( ((char *)(x))[3] ) ) | \ - (( ((char *)(x))[2] ) << 8) | \ - (( ((char *)(x))[1] ) << 16) | \ - (( ((char *)(x))[0] ) << 24)) -#define ntohsp(x) ((( ((char *)(x))[1] ) ) | \ - (( ((char *)(x))[0] ) << 8)) - - - -const u_char * +static const u_char * c_print(register const u_char *s, register const u_char *ep) { register u_char c; @@ -155,7 +128,7 @@ c_print(register const u_char *s, register const u_char *ep) return (s); } -const u_char * +static const u_char * krb4_print_hdr(const u_char *cp) { cp += 2; @@ -176,7 +149,7 @@ krb4_print_hdr(const u_char *cp) #undef PRINT } -void +static void krb4_print(const u_char *cp) { register const struct krb *kp; @@ -186,7 +159,7 @@ krb4_print(const u_char *cp) #define PRINT if ((cp = c_print(cp, snapend)) == NULL) goto trunc /* True if struct krb is little endian */ #define IS_LENDIAN(kp) (((kp)->type & 0x01) != 0) -#define KTOHSP(kp, cp) (IS_LENDIAN(kp) ? vtohsp(cp) : ntohsp(cp)) +#define KTOHSP(kp, cp) (IS_LENDIAN(kp) ? EXTRACT_LE_16BITS(cp) : EXTRACT_16BITS(cp)) kp = (struct krb *)cp; @@ -254,7 +227,7 @@ krb4_print(const u_char *cp) } void -krb_print(const u_char *dat, u_int length) +krb_print(const u_char *dat) { register const struct krb *kp; diff --git a/kame/kame/tcpdump/print-l2tp.c b/kame/kame/tcpdump/print-l2tp.c index 63d856b8c4..a8f0568c61 100644 --- a/kame/kame/tcpdump/print-l2tp.c +++ b/kame/kame/tcpdump/print-l2tp.c @@ -18,19 +18,25 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * L2TP support contributed by Motonori Shindo (mshindo@ascend.co.jp) + * L2TP support contributed by Motonori Shindo (mshindo@mshindo.net) */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvsroot/hydrangea-freebsd/kit/src/tcpdump/Attic/print-l2tp.c,v 1.1.2.1 1999/07/26 12:32:51 itojun Exp $"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-l2tp.c,v 1.14.2.3 2003/12/26 23:21:42 guy Exp $"; #endif -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include #include "l2tp.h" #include "interface.h" +#include "extract.h" static char tstr[] = " [|l2tp]"; @@ -42,113 +48,148 @@ static char tstr[] = " [|l2tp]"; #define FALSE 0 #endif -static u_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 } +}; + +#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 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 +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 static char *l2tp_result_code_StopCCN[] = { "Reserved", "General request to clear control connection", @@ -160,7 +201,9 @@ static char *l2tp_result_code_StopCCN[] = { "Finite State Machine error" #define L2TP_MAX_RESULT_CODE_STOPCC_INDEX 8 }; +#endif +#if 0 static char *l2tp_result_code_CDN[] = { "Reserved", "Call disconnected due to loss of carrier", @@ -178,7 +221,9 @@ static char *l2tp_result_code_CDN[] = { "Call was connected but no appropriate framing was detected" #define L2TP_MAX_RESULT_CODE_CDN_INDEX 12 }; +#endif +#if 0 static char *l2tp_error_code_general[] = { "No general error", "No control connection exists yet for this LAC-LNS pair", @@ -191,443 +236,396 @@ static char *l2tp_error_code_general[] = { "Try another" #define L2TP_MAX_ERROR_CODE_GENERAL_INDEX 8 }; +#endif /******************************/ /* generic print out routines */ /******************************/ -static void +static void print_string(const u_char *dat, u_int length) { - int i; + u_int i; for (i=0; i 4) { /* result & error code & msg */ - printf("%d/%d %s", ntohs(*ptr), ntohs(*(ptr+1))); - print_string((u_char *)(ptr+2), length - 4); + u_int16_t *ptr = (u_int16_t *)dat; + + printf("%u", EXTRACT_16BITS(ptr)); ptr++; /* Result Code */ + if (length > 2) { /* Error Code (opt) */ + printf("/%u", EXTRACT_16BITS(ptr)); 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", (EXTRACT_16BITS(dat) >> 8), + (EXTRACT_16BITS(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) { + if (EXTRACT_32BITS(ptr) & L2TP_FRAMING_CAP_ASYNC_MASK) { printf("A"); } - if (ntohl(*ptr) & L2TP_FRAMING_CAP_SYNC_MASK) { + if (EXTRACT_32BITS(ptr) & L2TP_FRAMING_CAP_SYNC_MASK) { printf("S"); } } 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) { + if (EXTRACT_32BITS(ptr) & L2TP_BEARER_CAP_ANALOG_MASK) { printf("A"); } - if (ntohl(*ptr) & L2TP_BEARER_CAP_DIGITAL_MASK) { + if (EXTRACT_32BITS(ptr) & L2TP_BEARER_CAP_DIGITAL_MASK) { printf("D"); } } -static void -l2tp_tie_breaker_print(const u_char *dat, u_int length) -{ - printf("%lx", *(u_long *)dat); /* XXX */ -} - -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); - printf(",%02x", dat+2); + print_16bits_val((u_int16_t *)dat); + printf(", %02x", dat[2]); if (length > 3) { printf(" "); print_string(dat+3, length-3); - } -} - -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) { + if (EXTRACT_32BITS(ptr) & L2TP_BEARER_TYPE_ANALOG_MASK) { printf("A"); } - if (ntohl(*ptr) & L2TP_BEARER_TYPE_DIGITAL_MASK) { + if (EXTRACT_32BITS(ptr) & L2TP_BEARER_TYPE_DIGITAL_MASK) { printf("D"); } } 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) { + if (EXTRACT_32BITS(ptr) & L2TP_FRAMING_TYPE_ASYNC_MASK) { printf("A"); } - if (ntohl(*ptr) & L2TP_FRAMING_TYPE_SYNC_MASK) { + if (EXTRACT_32BITS(ptr) & L2TP_FRAMING_TYPE_SYNC_MASK) { printf("S"); } } 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", EXTRACT_16BITS(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", EXTRACT_16BITS(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; -static void -l2tp_ini_recv_lcp_print(const u_char *dat, u_int length) -{ - print_octets(dat, length); -} + ptr++; /* skip "Reserved" */ -static void -l2tp_last_sent_lcp_print(const u_char *dat, u_int length) -{ - print_octets(dat, length); -} - -static void -l2tp_last_recv_lcp_print(const u_char *dat, u_int length) -{ - print_octets(dat, length); -} - -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 = EXTRACT_16BITS(ptr); ptr++; + val_l = EXTRACT_16BITS(ptr); ptr++; + printf("CRCErr=%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 = EXTRACT_16BITS(ptr); ptr++; + val_l = EXTRACT_16BITS(ptr); ptr++; + printf("FrameErr=%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 = EXTRACT_16BITS(ptr); ptr++; + val_l = EXTRACT_16BITS(ptr); ptr++; + printf("HardOver=%u ", (val_h<<16) + val_l); -static void -l2tp_proxy_auth_id_print(const u_char *dat, u_int length) -{ - u_short *ptr = (u_short *)dat; + val_h = EXTRACT_16BITS(ptr); ptr++; + val_l = EXTRACT_16BITS(ptr); ptr++; + printf("BufOver=%u ", (val_h<<16) + val_l); - printf("%d", ntohs(*ptr) & L2TP_PROXY_AUTH_ID_MASK); -} + val_h = EXTRACT_16BITS(ptr); ptr++; + val_l = EXTRACT_16BITS(ptr); ptr++; + printf("Timeout=%u ", (val_h<<16) + val_l); -static void -l2tp_proxy_auth_resp_print(const u_char *dat, u_int length) -{ - print_octets(dat, length); + val_h = EXTRACT_16BITS(ptr); ptr++; + val_l = EXTRACT_16BITS(ptr); ptr++; + printf("AlignErr=%u ", (val_h<<16) + val_l); } static void -l2tp_call_errors_print(const u_char *dat, u_int length) +l2tp_accm_print(const u_char *dat) { - 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); -} + u_int16_t *ptr = (u_int16_t *)dat; + u_int16_t val_h, val_l; -static void -l2tp_accm_print(const u_char *dat, u_int length) -{ - struct l2tp_accm *ptr = (struct l2tp_accm *)dat; + ptr++; /* skip "Reserved" */ - printf("send=%x recv=%x", ptr->send_accm, ptr->recv_accm); -} + val_h = EXTRACT_16BITS(ptr); ptr++; + val_l = EXTRACT_16BITS(ptr); ptr++; + printf("send=%08x ", (val_h<<16) + val_l); -static void -l2tp_random_vector_print(const u_char *dat, u_int length) -{ - print_octets(dat, length); + val_h = EXTRACT_16BITS(ptr); ptr++; + val_l = EXTRACT_16BITS(ptr); ptr++; + printf("recv=%08x ", (val_h<<16) + val_l); } static void -l2tp_private_grp_id_print(const u_char *dat, u_int length) +l2tp_ppp_discon_cc_print(const u_char *dat, u_int length) { - print_string(dat, length); - /* XXX print_octets is more appropriate?? */ -} + u_int16_t *ptr = (u_int16_t *)dat; -static void -l2tp_rx_conn_speed_print(const u_char *dat, u_int length) -{ - print_int((u_int *)dat); -} + printf("%04x, ", EXTRACT_16BITS(ptr)); ptr++; /* Disconnect Code */ + printf("%04x ", EXTRACT_16BITS(ptr)); ptr++; /* Control Protocol Number */ + printf("%s", tok2str(l2tp_cc_direction2str, + "Direction-#%u", *((u_char *)ptr++))); -static void -l2tp_seq_required_print(const u_char *dat, u_int length) -{ - return; + if (length > 5) { + printf(" "); + print_string((const u_char *)ptr, length-5); + } } static void -l2tp_avp_print(const u_char *dat, u_int length) +l2tp_avp_print(const u_char *dat, int length) { u_int len; - const u_short *ptr = (u_short *)dat; + const u_int16_t *ptr = (u_int16_t *)dat; + u_int16_t attr_type; int hidden = FALSE; + if (length <= 0) { + return; + } + 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)) { /* IETF == 0 */ - printf("vendor=%04x", ntohs(*ptr)); - } - ptr++; + TCHECK(*ptr); /* Flags & Length */ + len = EXTRACT_16BITS(ptr) & L2TP_AVP_HDR_LEN_MASK; - 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 %s", ntohs(*ptr)); - } + /* If it is not long enough to contain the header, we'll give up. */ + if (len < 6) + goto trunc; - l2tp_avp_print(dat + len, length - len); - } else if (length == 0) { - return; + /* If it goes past the end of the remaining length of the packet, + we'll give up. */ + if (len > (u_int)length) + goto trunc; + + /* If it goes past the end of the remaining length of the captured + data, we'll give up. */ + TCHECK2(*ptr, len); + /* After this point, no need to worry about truncation */ + + if (EXTRACT_16BITS(ptr) & L2TP_AVP_HDR_FLAG_MANDATORY) { + printf("*"); + } + if (EXTRACT_16BITS(ptr) & L2TP_AVP_HDR_FLAG_HIDDEN) { + hidden = TRUE; + printf("?"); + } + ptr++; + + if (EXTRACT_16BITS(ptr)) { + /* Vendor Specific Attribute */ + printf("VENDOR%04x:", EXTRACT_16BITS(ptr)); ptr++; + printf("ATTR%04x", EXTRACT_16BITS(ptr)); ptr++; + printf("("); + print_octets((u_char *)ptr, len-6); + printf(")"); } else { - printf("|..."); + /* IETF-defined Attributes */ + ptr++; + attr_type = EXTRACT_16BITS(ptr); ptr++; + printf("%s", tok2str(l2tp_avp2str, "AVP-#%u", attr_type)); + printf("("); + if (hidden) { + printf("???"); + } else { + 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; + } + } + 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; - } - - if ((ntohs(*ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2TP) { + TCHECK(*ptr); /* Flags & Version */ + if ((EXTRACT_16BITS(ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2TP) { printf(" l2tp:"); - } else if ((ntohs(*ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2F) { + } else if ((EXTRACT_16BITS(ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2F) { printf(" l2f:"); return; /* nothing to do */ } else { @@ -636,23 +634,23 @@ l2tp_print(const u_char *dat, u_int length) } printf("["); - if (ntohs(*ptr) & L2TP_FLAG_TYPE) { + if (EXTRACT_16BITS(ptr) & L2TP_FLAG_TYPE) { flag_t = TRUE; printf("T"); } - if (ntohs(*ptr) & L2TP_FLAG_LENGTH) { + if (EXTRACT_16BITS(ptr) & L2TP_FLAG_LENGTH) { flag_l = TRUE; printf("L"); } - if (ntohs(*ptr) & L2TP_FLAG_SEQUENCE) { + if (EXTRACT_16BITS(ptr) & L2TP_FLAG_SEQUENCE) { flag_s = TRUE; printf("S"); } - if (ntohs(*ptr) & L2TP_FLAG_OFFSET) { + if (EXTRACT_16BITS(ptr) & L2TP_FLAG_OFFSET) { flag_o = TRUE; printf("O"); } - if (ntohs(*ptr) & L2TP_FLAG_PRIORITY) { + if (EXTRACT_16BITS(ptr) & L2TP_FLAG_PRIORITY) { flag_p = TRUE; printf("P"); } @@ -660,28 +658,35 @@ l2tp_print(const u_char *dat, u_int length) ptr++; cnt += 2; - + if (flag_l) { - l2tp_len = ntohs(*ptr++); /* XXX need to consider - truncation ?? */ + TCHECK(*ptr); /* Length */ + l2tp_len = EXTRACT_16BITS(ptr); ptr++; cnt += 2; } else { l2tp_len = 0; } - printf("(%d/", ntohs(*ptr++)); /* Tunnel ID */ - printf("%d)", ntohs(*ptr++)); /* Session ID */ - cnt += 4; + TCHECK(*ptr); /* Tunnel ID */ + printf("(%u/", EXTRACT_16BITS(ptr)); ptr++; + cnt += 2; + TCHECK(*ptr); /* Session ID */ + printf("%u)", EXTRACT_16BITS(ptr)); ptr++; + cnt += 2; if (flag_s) { - printf("Ns=%d,", ntohs(*ptr++)); - printf("Nr=%d", ntohs(*ptr++)); - cnt += 4; + TCHECK(*ptr); /* Ns */ + printf("Ns=%u,", EXTRACT_16BITS(ptr)); ptr++; + cnt += 2; + TCHECK(*ptr); /* Nr */ + printf("Nr=%u", EXTRACT_16BITS(ptr)); ptr++; + cnt += 2; } if (flag_o) { - pad = ntohs(*ptr++); - (u_char *)ptr += pad; + TCHECK(*ptr); /* Offset Size */ + pad = EXTRACT_16BITS(ptr); ptr++; + ptr += pad / sizeof(*ptr); cnt += (2 + pad); } @@ -692,12 +697,13 @@ l2tp_print(const u_char *dat, u_int length) l2tp_avp_print((u_char *)ptr, length - cnt); } } else { -#if 0 printf(" {"); - ppp_hdlc_print((u_char *)ptr, length - cnt); + ppp_print((u_char *)ptr, length - cnt); printf("}"); -#else - printf("[hdlc|]"); -#endif } -} + + return; + + trunc: + printf("%s", tstr); +} diff --git a/kame/kame/tcpdump/print-lane.c b/kame/kame/tcpdump/print-lane.c new file mode 100644 index 0000000000..3cdee5a5b9 --- /dev/null +++ b/kame/kame/tcpdump/print-lane.c @@ -0,0 +1,168 @@ +/* + * Marko Kiiskila carnil@cs.tut.fi + * + * Tampere University of Technology - Telecommunications Laboratory + * + * Permission to use, copy, modify and distribute this + * software and its documentation is hereby granted, + * provided that both the copyright notice and this + * permission notice appear in all copies of the software, + * derivative works or modified versions, and any portions + * thereof, that both notices appear in supporting + * documentation, and that the use of this software is + * acknowledged in any publications resulting from using + * the software. + * + * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS + * SOFTWARE. + * + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-lane.c,v 1.20.2.2 2003/11/16 08:51:31 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" +#include "ether.h" +#include "lane.h" + +static const struct tok lecop2str[] = { + { 0x0001, "configure request" }, + { 0x0101, "configure response" }, + { 0x0002, "join request" }, + { 0x0102, "join response" }, + { 0x0003, "ready query" }, + { 0x0103, "ready indication" }, + { 0x0004, "register request" }, + { 0x0104, "register response" }, + { 0x0005, "unregister request" }, + { 0x0105, "unregister response" }, + { 0x0006, "ARP request" }, + { 0x0106, "ARP response" }, + { 0x0007, "flush request" }, + { 0x0107, "flush response" }, + { 0x0008, "NARP request" }, + { 0x0009, "topology request" }, + { 0, NULL } +}; + +static inline void +lane_hdr_print(register const u_char *bp, int length) +{ + register const struct lecdatahdr_8023 *ep; + + ep = (const struct lecdatahdr_8023 *)bp; + if (qflag) + (void)printf("lecid:%x %s %s %d: ", + EXTRACT_16BITS(&ep->le_header), + etheraddr_string(ep->h_source), + etheraddr_string(ep->h_dest), + length); + else + (void)printf("lecid:%x %s %s %s %d: ", + EXTRACT_16BITS(&ep->le_header), + etheraddr_string(ep->h_source), + etheraddr_string(ep->h_dest), + etherproto_string(ep->h_type), + length); +} + +/* + * This is the top level routine of the printer. 'p' points + * to the LANE header of the packet, 'h->ts' is the timestamp, + * 'h->length' is the length of the packet off the wire, and 'h->caplen' + * is the number of bytes actually captured. + * + * This assumes 802.3, not 802.5, LAN emulation. + */ +void +lane_print(const u_char *p, u_int length, u_int caplen) +{ + struct lane_controlhdr *lec; + struct lecdatahdr_8023 *ep; + u_short ether_type; + u_short extracted_ethertype; + + if (caplen < sizeof(struct lane_controlhdr)) { + printf("[|lane]"); + return; + } + + lec = (struct lane_controlhdr *)p; + if (EXTRACT_16BITS(&lec->lec_header) == 0xff00) { + /* + * LE Control. + */ + printf("lec: proto %x vers %x %s", + lec->lec_proto, lec->lec_vers, + tok2str(lecop2str, "opcode-#%u", EXTRACT_16BITS(&lec->lec_opcode))); + return; + } + + if (caplen < sizeof(struct lecdatahdr_8023)) { + printf("[|lane]"); + return; + } + + if (eflag) + lane_hdr_print(p, length); + + /* + * Go past the LANE header. + */ + length -= sizeof(struct lecdatahdr_8023); + caplen -= sizeof(struct lecdatahdr_8023); + ep = (struct lecdatahdr_8023 *)p; + p += sizeof(struct lecdatahdr_8023); + + ether_type = EXTRACT_16BITS(&ep->h_type); + + /* + * Is it (gag) an 802.3 encapsulation? + */ + extracted_ethertype = 0; + if (ether_type <= ETHERMTU) { + /* Try to print the LLC-layer header & higher layers */ + if (llc_print(p, length, caplen, ep->h_source, ep->h_dest, + &extracted_ethertype) == 0) { + /* ether_type not known, print raw packet */ + if (!eflag) + lane_hdr_print((u_char *)ep, length + sizeof(*ep)); + if (extracted_ethertype) { + printf("(LLC %s) ", + etherproto_string(htons(extracted_ethertype))); + } + 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) + lane_hdr_print((u_char *)ep, length + sizeof(*ep)); + if (!xflag && !qflag) + default_print(p, caplen); + } +} + +u_int +lane_if_print(const struct pcap_pkthdr *h, const u_char *p) +{ + lane_print(p, h->len, h->caplen); + + return (sizeof(struct lecdatahdr_8023)); +} diff --git a/kame/kame/tcpdump/print-ldp.c b/kame/kame/tcpdump/print-ldp.c new file mode 100644 index 0000000000..1162ac39af --- /dev/null +++ b/kame/kame/tcpdump/print-ldp.c @@ -0,0 +1,382 @@ +/* + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code + * distributions retain the above copyright notice and this paragraph + * in its entirety, and (2) distributions including binary code include + * the above copyright notice and this paragraph in its entirety in + * the documentation or other materials provided with the distribution. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND + * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT + * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * Original code by Hannes Gredler (hannes@juniper.net) + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-ldp.c,v 1.4.2.2 2003/11/16 08:51:31 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include + +#include "interface.h" +#include "extract.h" +#include "addrtoname.h" + +/* + * ldp common header + * + * 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 | PDU Length | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | LDP Identifier | + * + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + */ + +struct ldp_common_header { + u_int8_t version[2]; + u_int8_t pdu_length[2]; + u_int8_t lsr_id[4]; + u_int8_t label_space[2]; +}; + +#define LDP_VERSION 1 + +/* + * ldp message header + * + * 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 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |U| Message Type | Message Length | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Message ID | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | | + * + + + * | Mandatory Parameters | + * + + + * | | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | | + * + + + * | Optional Parameters | + * + + + * | | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +struct ldp_msg_header { + u_int8_t type[2]; + u_int8_t length[2]; + u_int8_t id[4]; +}; + +#define LDP_MASK_MSG_TYPE(x) ((x)&0x7fff) +#define LDP_MASK_U_BIT(x) ((x)&0x8000) + +#define LDP_MSG_NOTIF 0x0001 +#define LDP_MSG_HELLO 0x0100 +#define LDP_MSG_INIT 0x0200 +#define LDP_MSG_KEEPALIVE 0x0201 +#define LDP_MSG_ADDRESS 0x0300 +#define LDP_MSG_ADDRESS_WITHDRAW 0x0301 +#define LDP_MSG_LABEL_MAPPING 0x0400 +#define LDP_MSG_LABEL_REQUEST 0x0401 +#define LDP_MSG_LABEL_WITHDRAW 0x0402 +#define LDP_MSG_LABEL_RELEASE 0x0403 +#define LDP_MSG_LABEL_ABORT_REQUEST 0x0404 + +#define LDP_VENDOR_PRIVATE_MIN 0x3e00 +#define LDP_VENDOR_PRIVATE_MAX 0x3eff +#define LDP_EXPERIMENTAL_MIN 0x3f00 +#define LDP_EXPERIMENTAL_MAX 0x3fff + +static const struct tok ldp_msg_values[] = { + { LDP_MSG_NOTIF, "Notification" }, + { LDP_MSG_HELLO, "Hello" }, + { LDP_MSG_INIT, "Initialization" }, + { LDP_MSG_KEEPALIVE, "Keepalive" }, + { LDP_MSG_ADDRESS, "Address" }, + { LDP_MSG_ADDRESS_WITHDRAW, "Address Widthdraw" }, + { LDP_MSG_LABEL_MAPPING, "Label Mapping" }, + { LDP_MSG_LABEL_REQUEST, "Label Request" }, + { LDP_MSG_LABEL_WITHDRAW, "Label Withdraw" }, + { LDP_MSG_LABEL_RELEASE, "Label Release" }, + { LDP_MSG_LABEL_ABORT_REQUEST, "Label Abort Request" }, + { 0, NULL} +}; + +#define LDP_MASK_TLV_TYPE(x) ((x)&0x3fff) +#define LDP_MASK_F_BIT(x) ((x)&0x4000) + +#define LDP_TLV_FEC 0x0100 +#define LDP_TLV_ADDRESS_LIST 0x0101 +#define LDP_TLV_HOP_COUNT 0x0103 +#define LDP_TLV_PATH_VECTOR 0x0104 +#define LDP_TLV_GENERIC_LABEL 0x0200 +#define LDP_TLV_ATM_LABEL 0x0201 +#define LDP_TLV_FR_LABEL 0x0202 +#define LDP_TLV_STATUS 0x0300 +#define LDP_TLV_EXTD_STATUS 0x0301 +#define LDP_TLV_RETURNED_PDU 0x0302 +#define LDP_TLV_RETURNED_MSG 0x0303 +#define LDP_TLV_COMMON_HELLO 0x0400 +#define LDP_TLV_IPV4_TRANSPORT_ADDR 0x0401 +#define LDP_TLV_CONFIG_SEQ_NUMBER 0x0402 +#define LDP_TLV_IPV6_TRANSPORT_ADDR 0x0403 +#define LDP_TLV_COMMON_SESSION 0x0500 +#define LDP_TLV_ATM_SESSION_PARM 0x0501 +#define LDP_TLV_FR_SESSION_PARM 0x0502 +#define LDP_TLV_LABEL_REQUEST_MSG_ID 0x0600 + +static const struct tok ldp_tlv_values[] = { + { LDP_TLV_FEC, "FEC" }, + { LDP_TLV_ADDRESS_LIST, "Address List" }, + { LDP_TLV_HOP_COUNT, "Hop Count" }, + { LDP_TLV_PATH_VECTOR, "Path Vector" }, + { LDP_TLV_GENERIC_LABEL, "Generic Label" }, + { LDP_TLV_ATM_LABEL, "ATM Label" }, + { LDP_TLV_FR_LABEL, "Frame-Relay Label" }, + { LDP_TLV_STATUS, "Status" }, + { LDP_TLV_EXTD_STATUS, "Extended Status" }, + { LDP_TLV_RETURNED_PDU, "Returned PDU" }, + { LDP_TLV_RETURNED_MSG, "Returned Message" }, + { LDP_TLV_COMMON_HELLO, "Common Hello Parameters" }, + { LDP_TLV_IPV4_TRANSPORT_ADDR, "IPv4 Transport Address" }, + { LDP_TLV_CONFIG_SEQ_NUMBER, "Configuration Sequence Number" }, + { LDP_TLV_IPV6_TRANSPORT_ADDR, "IPv6 Transport Address" }, + { LDP_TLV_COMMON_SESSION, "Common Session Parameters" }, + { LDP_TLV_ATM_SESSION_PARM, "ATM Session Parameters" }, + { LDP_TLV_FR_SESSION_PARM, "Frame-Relay Session Parameters" }, + { LDP_TLV_LABEL_REQUEST_MSG_ID, "Label Request Message ID" }, + { 0, NULL} +}; + +#define FALSE 0 +#define TRUE 1 + +int ldp_tlv_print(register const u_char *); + +/* + * ldp tlv header + * + * 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 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |U|F| Type | Length | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | | + * | Value | + * ~ ~ + * | | + * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +int +ldp_tlv_print(register const u_char *tptr) { + + struct ldp_tlv_header { + u_int8_t type[2]; + u_int8_t length[2]; + }; + + const struct ldp_tlv_header *ldp_tlv_header; + u_short tlv_type,tlv_len,tlv_tlen; + + ldp_tlv_header = (const struct ldp_tlv_header *)tptr; + tlv_len=EXTRACT_16BITS(ldp_tlv_header->length); + tlv_tlen=tlv_len; + tlv_type=LDP_MASK_TLV_TYPE(EXTRACT_16BITS(ldp_tlv_header->type)); + + /* FIXME vendor private / experimental check */ + printf("\n\t %s TLV (0x%04x), length: %u, Flags: [%s and %s forward if unknown]", + tok2str(ldp_tlv_values, + "Unknown", + tlv_type), + tlv_type, + tlv_len, + LDP_MASK_U_BIT(EXTRACT_16BITS(&ldp_tlv_header->type)) ? "continue processing" : "ignore", + LDP_MASK_F_BIT(EXTRACT_16BITS(&ldp_tlv_header->type)) ? "do" : "don't"); + + tptr+=sizeof(struct ldp_tlv_header); + + switch(tlv_type) { + + case LDP_TLV_COMMON_HELLO: + printf("\n\t Hold Time: %us, Flags: [%s Hello%s]", + EXTRACT_16BITS(tptr), + (EXTRACT_16BITS(tptr+2)&0x8000) ? "Targeted" : "Link", + (EXTRACT_16BITS(tptr+2)&0x4000) ? ", Request for targeted Hellos" : ""); + break; + + case LDP_TLV_IPV4_TRANSPORT_ADDR: + printf("\n\t IPv4 Transport Address: %s", ipaddr_string(tptr)); + break; +#ifdef INET6 + case LDP_TLV_IPV6_TRANSPORT_ADDR: + printf("\n\t IPv6 Transport Address: %s", ip6addr_string(tptr)); + break; +#endif + case LDP_TLV_CONFIG_SEQ_NUMBER: + printf("\n\t Sequence Number: %u", EXTRACT_32BITS(tptr)); + break; + + /* + * FIXME those are the defined TLVs that lack a decoder + * you are welcome to contribute code ;-) + */ + + case LDP_TLV_FEC: + case LDP_TLV_ADDRESS_LIST: + case LDP_TLV_HOP_COUNT: + case LDP_TLV_PATH_VECTOR: + case LDP_TLV_GENERIC_LABEL: + case LDP_TLV_ATM_LABEL: + case LDP_TLV_FR_LABEL: + case LDP_TLV_STATUS: + case LDP_TLV_EXTD_STATUS: + case LDP_TLV_RETURNED_PDU: + case LDP_TLV_RETURNED_MSG: + case LDP_TLV_COMMON_SESSION: + case LDP_TLV_ATM_SESSION_PARM: + case LDP_TLV_FR_SESSION_PARM: + case LDP_TLV_LABEL_REQUEST_MSG_ID: + + default: + if (vflag <= 1) + print_unknown_data(tptr,"\n\t ",tlv_tlen); + break; + } + return(tlv_len+4); /* Type & Length fields not included */ +} + +void +ldp_print(register const u_char *pptr, register u_int len) { + + const struct ldp_common_header *ldp_com_header; + const struct ldp_msg_header *ldp_msg_header; + const u_char *tptr,*msg_tptr; + u_short tlen; + u_short msg_len,msg_type,msg_tlen; + int hexdump,processed; + + tptr=pptr; + ldp_com_header = (const struct ldp_common_header *)pptr; + TCHECK(*ldp_com_header); + + /* + * Sanity checking of the header. + */ + if (EXTRACT_16BITS(&ldp_com_header->version) != LDP_VERSION) { + printf("LDP version %u packet not supported", + EXTRACT_16BITS(&ldp_com_header->version)); + return; + } + + /* print the LSR-ID, label-space & length */ + printf("%sLDP, Label-Space-ID: %s:%u, length: %u", + (vflag < 1) ? "" : "\n\t", + ipaddr_string(&ldp_com_header->lsr_id), + EXTRACT_16BITS(&ldp_com_header->label_space), + len); + + /* bail out if non-verbose */ + if (vflag < 1) + return; + + /* ok they seem to want to know everything - lets fully decode it */ + tlen=EXTRACT_16BITS(ldp_com_header->pdu_length); + + tptr+=sizeof(const struct ldp_common_header); + tlen-=sizeof(const struct ldp_common_header); + + while(tlen>0) { + /* did we capture enough for fully decoding the msg header ? */ + if (!TTEST2(*tptr, sizeof(struct ldp_msg_header))) + goto trunc; + + ldp_msg_header = (const struct ldp_msg_header *)tptr; + msg_len=EXTRACT_16BITS(ldp_msg_header->length); + msg_type=LDP_MASK_MSG_TYPE(EXTRACT_16BITS(ldp_msg_header->type)); + + /* FIXME vendor private / experimental check */ + printf("\n\t %s Message (0x%04x), length: %u, Message ID: 0x%08x, Flags: [%s if unknown]", + tok2str(ldp_msg_values, + "Unknown", + msg_type), + msg_type, + msg_len, + EXTRACT_32BITS(&ldp_msg_header->id), + LDP_MASK_U_BIT(EXTRACT_16BITS(&ldp_msg_header->type)) ? "continue processing" : "ignore"); + + msg_tptr=tptr+sizeof(struct ldp_msg_header); + msg_tlen=msg_len-sizeof(struct ldp_msg_header)+4; /* Type & Length fields not included */ + + /* did we capture enough for fully decoding the message ? */ + if (!TTEST2(*tptr, msg_len)) + goto trunc; + hexdump=FALSE; + + switch(msg_type) { + + case LDP_MSG_HELLO: + while(msg_tlen >= 4) { + processed = ldp_tlv_print(msg_tptr); + if (processed == 0) + break; + msg_tlen-=processed; + msg_tptr+=processed; + } + break; + + /* + * FIXME those are the defined messages that lack a decoder + * you are welcome to contribute code ;-) + */ + + case LDP_MSG_NOTIF: + case LDP_MSG_INIT: + case LDP_MSG_KEEPALIVE: + case LDP_MSG_ADDRESS: + case LDP_MSG_ADDRESS_WITHDRAW: + case LDP_MSG_LABEL_MAPPING: + case LDP_MSG_LABEL_REQUEST: + case LDP_MSG_LABEL_WITHDRAW: + case LDP_MSG_LABEL_RELEASE: + case LDP_MSG_LABEL_ABORT_REQUEST: + + default: + if (vflag <= 1) + print_unknown_data(msg_tptr,"\n\t ",msg_tlen); + break; + } + /* do we want to see an additionally hexdump ? */ + if (vflag > 1 || hexdump==TRUE) + print_unknown_data(tptr+sizeof(sizeof(struct ldp_msg_header)),"\n\t ", + msg_len); + + tptr+=msg_len; + tlen-=msg_len; + } + return; +trunc: + printf("\n\t\t packet exceeded snapshot"); +} + diff --git a/kame/kame/tcpdump/print-llc.c b/kame/kame/tcpdump/print-llc.c index da68156fd0..4caaf5d86f 100644 --- a/kame/kame/tcpdump/print-llc.c +++ b/kame/kame/tcpdump/print-llc.c @@ -23,17 +23,16 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-llc.c,v 1.24 97/01/01 20:56:48 leres Exp $"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-llc.c,v 1.53.2.3 2003/12/29 22:33:18 hannes Exp $"; #endif -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include +#include -#include -#include #include #include @@ -42,6 +41,24 @@ static const char rcsid[] = #include "extract.h" /* must come after interface.h */ #include "llc.h" +#include "ethertype.h" + +static struct tok llc_values[] = { + { LLCSAP_NULL, "Null" }, + { LLCSAP_GLOBAL, "Global" }, + { LLCSAP_8021B_I, "802.1B I" }, + { LLCSAP_8021B_G, "802.1B G" }, + { LLCSAP_IP, "IP" }, + { LLCSAP_PROWAYNM, "ProWay NM" }, + { LLCSAP_8021D, "STP" }, + { LLCSAP_RS511, "RS511" }, + { LLCSAP_ISO8208, "ISO8208" }, + { LLCSAP_PROWAY, "ProWay" }, + { LLCSAP_SNAP, "SNAP" }, + { LLCSAP_IPX, "IPX" }, + { LLCSAP_NETBEUI, "NetBeui" }, + { LLCSAP_ISONS, "OSI" }, +}; static struct tok cmd2str[] = { { LLC_UI, "ui" }, @@ -60,10 +77,11 @@ static struct tok cmd2str[] = { */ int llc_print(const u_char *p, u_int length, u_int caplen, - const u_char *esrc, const u_char *edst) + const u_char *esrc, const u_char *edst, u_short *extracted_ethertype) { struct llc llc; register u_short et; + u_int16_t control; register int ret; if (caplen < 3) { @@ -75,43 +93,142 @@ llc_print(const u_char *p, u_int length, u_int caplen, /* Watch out for possible alignment problems */ memcpy((char *)&llc, (char *)p, min(caplen, sizeof(llc))); + if (eflag) + printf("LLC, dsap %s (0x%02x), ssap %s (0x%02x), cmd 0x%02x, ", + tok2str(llc_values,"Unknown",llc.dsap), + llc.dsap, + tok2str(llc_values,"Unknown",llc.ssap), + llc.ssap, + llc.llcu); + 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.) + */ + printf("(NOV-802.3) "); + ipx_print(p, length); + return (1); + } + + if (llc.ssap == LLCSAP_8021D && llc.dsap == LLCSAP_8021D) { + stp_print(p, length); + return (1); + } + + if (llc.ssap == LLCSAP_IP && llc.dsap == LLCSAP_IP) { + ip_print(p+4, length-4); + return (1); + } + + 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. + */ + printf("(NOV-802.2) "); + p += 3; + length -= 3; + caplen -= 3; ipx_print(p, length); return (1); } -#ifdef notyet - else if (p[0] == 0xf0 && p[1] == 0xf0) - netbios_print(p, length); + +#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 + * smb parser can handle many smb-in-netbeui packets, which + * is very useful, so we call that + * + * We don't call it for S frames, however, just I frames + * (which are frames that don't have the low-order bit, + * LLC_S_FMT, set in the first byte of the control field) + * and UI frames (whose control field is just 3, LLC_U_FMT). + */ + + /* + * Skip the DSAP and LSAP. + */ + p += 2; + length -= 2; + caplen -= 2; + + /* + * OK, what type of LLC frame is this? The length + * of the control field depends on that - I frames + * have a two-byte control field, and U frames have + * a one-byte control field. + */ + if (llc.llcu == LLC_U_FMT) { + control = llc.llcu; + p += 1; + length -= 1; + caplen -= 1; + } else { + /* + * The control field in I and S frames is + * little-endian. + */ + control = EXTRACT_LE_16BITS(&llc.llcu); + p += 2; + length -= 2; + caplen -= 2; + } + 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); + isoclns_print(p + 3, length - 3, caplen - 3); return (1); } 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); - return (0); + (void)printf("[|llc-snap]"); + default_print((u_char *)p, caplen); + return (0); } - if (vflag) - (void)printf("snap %s ", protoid_string(llc.llcpi)); caplen -= sizeof(llc); 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); + orgcode = EXTRACT_24BITS(&llc.llc_orgcode[0]); + et = EXTRACT_16BITS(&llc.llc_ethertype[0]); + /* + * XXX - what *is* the right bridge pad value here? + * Does anybody ever bridge one form of LAN traffic + * over a networking type that uses 802.2 LLC? + */ + ret = snap_print(p, length, caplen, extracted_ethertype, + orgcode, et, 2); if (ret) return (ret); } 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 ", @@ -119,7 +236,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)); @@ -132,15 +249,18 @@ llc_print(const u_char *p, u_int length, u_int caplen, } if ((llc.llcu & LLC_U_FMT) == LLC_U_FMT) { + u_int16_t cmd; const char *m; char f; - m = tok2str(cmd2str, "%02x", LLC_U_CMD(llc.llcu)); + + cmd = LLC_U_CMD(llc.llcu); + m = tok2str(cmd2str, "%02x", cmd); switch ((llc.ssap & LLC_GSAP) | (llc.llcu & LLC_U_POLL)) { - case 0: f = 'C'; break; - case LLC_GSAP: f = 'R'; break; - case LLC_U_POLL: f = 'P'; break; - case LLC_GSAP|LLC_U_POLL: f = 'F'; break; - default: f = '?'; break; + case 0: f = 'C'; break; + case LLC_GSAP: f = 'R'; break; + case LLC_U_POLL: f = 'P'; break; + case LLC_GSAP|LLC_U_POLL: f = 'F'; break; + default: f = '?'; break; } printf("%s/%c", m, f); @@ -150,34 +270,38 @@ llc_print(const u_char *p, u_int length, u_int caplen, caplen -= 3; if ((llc.llcu & ~LLC_U_POLL) == LLC_XID) { - if (*p == LLC_XID_FI) { - printf(": %02x %02x", p[1], p[2]); - p += 3; - length -= 3; - caplen -= 3; - } + if (*p == LLC_XID_FI) { + printf(": %02x %02x", p[1], p[2]); + p += 3; + length -= 3; + caplen -= 3; + } } } else { char f; - llc.llcis = ntohs(llc.llcis); - switch ((llc.ssap & LLC_GSAP) | (llc.llcu & LLC_U_POLL)) { - case 0: f = 'C'; break; - case LLC_GSAP: f = 'R'; break; - case LLC_U_POLL: f = 'P'; break; - case LLC_GSAP|LLC_U_POLL: f = 'F'; break; - default: f = '?'; break; + + /* + * The control field in I and S frames is little-endian. + */ + control = EXTRACT_LE_16BITS(&llc.llcu); + switch ((llc.ssap & LLC_GSAP) | (control & LLC_IS_POLL)) { + case 0: f = 'C'; break; + case LLC_GSAP: f = 'R'; break; + case LLC_IS_POLL: f = 'P'; break; + case LLC_GSAP|LLC_IS_POLL: f = 'F'; break; + default: f = '?'; break; } - if ((llc.llcu & LLC_S_FMT) == LLC_S_FMT) { - static char *llc_s[] = { "rr", "rej", "rnr", "03" }; + if ((control & LLC_S_FMT) == LLC_S_FMT) { + static const char *llc_s[] = { "rr", "rej", "rnr", "03" }; (void)printf("%s (r=%d,%c)", - llc_s[LLC_S_CMD(llc.llcis)], - LLC_IS_NR(llc.llcis), + llc_s[LLC_S_CMD(control)], + LLC_IS_NR(control), f); } else { (void)printf("I (s=%d,r=%d,%c)", - LLC_I_NS(llc.llcis), - LLC_IS_NR(llc.llcis), + LLC_I_NS(control), + LLC_IS_NR(control), f); } p += 4; @@ -185,8 +309,121 @@ llc_print(const u_char *p, u_int length, u_int caplen, caplen -= 4; } (void)printf(" len=%d", length); - if (caplen > 0) { - default_print_unaligned(p, caplen); - } return(1); } + +int +snap_print(const u_char *p, u_int length, u_int caplen, + u_short *extracted_ethertype, u_int32_t orgcode, u_short et, + u_int bridge_pad) +{ + register int ret; + + 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 == PID_CISCO_CDP) { + cdp_print(p, length, caplen); + return (1); + } + break; + + case OUI_RFC2684: + switch (et) { + + case PID_RFC2684_ETH_FCS: + case PID_RFC2684_ETH_NOFCS: + /* + * XXX - remove the last two bytes for + * PID_RFC2684_ETH_FCS? + */ + /* + * Skip the padding. + */ + caplen -= bridge_pad; + length -= bridge_pad; + p += bridge_pad; + + /* + * What remains is an Ethernet packet. + */ + ether_print(p, length, caplen); + return (1); + + case PID_RFC2684_802_5_FCS: + case PID_RFC2684_802_5_NOFCS: + /* + * XXX - remove the last two bytes for + * PID_RFC2684_ETH_FCS? + */ + /* + * Skip the padding, but not the Access + * Control field. + */ + caplen -= bridge_pad; + length -= bridge_pad; + p += bridge_pad; + + /* + * What remains is an 802.5 Token Ring + * packet. + */ + token_print(p, length, caplen); + return (1); + + case PID_RFC2684_FDDI_FCS: + case PID_RFC2684_FDDI_NOFCS: + /* + * XXX - remove the last two bytes for + * PID_RFC2684_ETH_FCS? + */ + /* + * Skip the padding. + */ + caplen -= bridge_pad + 1; + length -= bridge_pad + 1; + p += bridge_pad + 1; + + /* + * What remains is an FDDI packet. + */ + fddi_print(p, length, caplen); + return (1); + + case PID_RFC2684_BPDU: + stp_print(p, length); + return (1); + } + } + return (0); +} diff --git a/kame/kame/tcpdump/print-lwres.c b/kame/kame/tcpdump/print-lwres.c new file mode 100644 index 0000000000..5272d4391a --- /dev/null +++ b/kame/kame/tcpdump/print-lwres.c @@ -0,0 +1,601 @@ +/* + * 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[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-lwres.c,v 1.10.2.3 2004/03/24 01:54:58 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "nameser.h" + +#include +#include + +#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; + size_t 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 = EXTRACT_16BITS(&ap->length); + /* XXX ap points to packed struct */ + p = (const char *)&ap->length + sizeof(ap->length); + TCHECK2(*p, l); + + switch (EXTRACT_32BITS(&ap->family)) { + case 1: /* IPv4 */ + if (l < 4) + return -1; + printf(" %s", ipaddr_string(p)); + p += sizeof(struct in_addr); + break; +#ifdef INET6 + case 2: /* IPv6 */ + if (l < 16) + return -1; + printf(" %s", ip6addr_string(p)); + p += sizeof(struct in6_addr); + break; +#endif + default: + printf(" %u/", EXTRACT_32BITS(&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 = EXTRACT_16BITS(&np->version); + if (vflag || v != LWRES_LWPACKETVERSION_0) + printf(" v%u", v); + if (v != LWRES_LWPACKETVERSION_0) { + s = (const char *)np + EXTRACT_32BITS(&np->length); + goto tail; + } + + response = EXTRACT_16BITS(&np->pktflags) & LWRES_LWPACKETFLAG_RESPONSE; + + /* opcode and pktflags */ + v = EXTRACT_32BITS(&np->opcode); + s = tok2str(opcode, "#0x%x", v); + printf(" %s%s", s, response ? "" : "?"); + + /* pktflags */ + v = EXTRACT_16BITS(&np->pktflags); + if (v & ~LWRES_LWPACKETFLAG_RESPONSE) + printf("[0x%x]", v); + + if (vflag > 1) { + printf(" ("); /*)*/ + printf("serial:0x%x", EXTRACT_32BITS(&np->serial)); + printf(" result:0x%x", EXTRACT_32BITS(&np->result)); + printf(" recvlen:%u", EXTRACT_32BITS(&np->recvlength)); + /* BIND910: not used */ + if (vflag > 2) { + printf(" authtype:0x%x", EXTRACT_16BITS(&np->authtype)); + printf(" authlen:%u", EXTRACT_16BITS(&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 (EXTRACT_32BITS(&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 = EXTRACT_16BITS(&gabn->namelen); + + /* BIND910: not used */ + if (vflag > 2) { + printf(" flags:0x%x", + EXTRACT_32BITS(&gabn->flags)); + } + + v = EXTRACT_32BITS(&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%x", + EXTRACT_32BITS(&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%x", + EXTRACT_32BITS(&grbn->flags)); + } + + printf(" %s", tok2str(ns_type2str, "Type%d", + EXTRACT_16BITS(&grbn->rdtype))); + if (EXTRACT_16BITS(&grbn->rdclass) != C_IN) { + printf(" %s", tok2str(ns_class2str, "Class%d", + EXTRACT_16BITS(&grbn->rdclass))); + } + + /* XXX grbn points to packed struct */ + s = (const char *)&grbn->namelen + + sizeof(grbn->namelen); + l = EXTRACT_16BITS(&grbn->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; + u_int32_t i; + + gabn = NULL; + gnba = NULL; + grbn = NULL; + + switch (EXTRACT_32BITS(&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 = EXTRACT_16BITS(&gabn->realnamelen); + + /* BIND910: not used */ + if (vflag > 2) { + printf(" flags:0x%x", + EXTRACT_32BITS(&gabn->flags)); + } + + printf(" %u/%u", EXTRACT_16BITS(&gabn->naliases), + EXTRACT_16BITS(&gabn->naddrs)); + + advance = lwres_printname(l, s); + if (advance < 0) + goto trunc; + s += advance; + + /* aliases */ + na = EXTRACT_16BITS(&gabn->naliases); + for (i = 0; i < na; i++) { + advance = lwres_printnamelen(s); + if (advance < 0) + goto trunc; + s += advance; + } + + /* addrs */ + na = EXTRACT_16BITS(&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 = EXTRACT_16BITS(&gnba->realnamelen); + + /* BIND910: not used */ + if (vflag > 2) { + printf(" flags:0x%x", + EXTRACT_32BITS(&gnba->flags)); + } + + printf(" %u", EXTRACT_16BITS(&gnba->naliases)); + + advance = lwres_printname(l, s); + if (advance < 0) + goto trunc; + s += advance; + + /* aliases */ + na = EXTRACT_16BITS(&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%x", + EXTRACT_32BITS(&grbn->flags)); + } + + printf(" %s", tok2str(ns_type2str, "Type%d", + EXTRACT_16BITS(&grbn->rdtype))); + if (EXTRACT_16BITS(&grbn->rdclass) != C_IN) { + printf(" %s", tok2str(ns_class2str, "Class%d", + EXTRACT_16BITS(&grbn->rdclass))); + } + printf(" TTL "); + relts_print(EXTRACT_32BITS(&grbn->ttl)); + printf(" %u/%u", EXTRACT_16BITS(&grbn->nrdatas), + EXTRACT_16BITS(&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 = EXTRACT_16BITS(&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 = EXTRACT_16BITS(&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 (EXTRACT_32BITS(&np->length) != length) { + printf(" [len: %u != %u]", EXTRACT_32BITS(&np->length), + length); + } + if (!unsupported && s < (const char *)np + EXTRACT_32BITS(&np->length)) + printf("[extra]"); + return; + + trunc: + printf("[|lwres]"); + return; +} diff --git a/kame/kame/tcpdump/print-mobile.c b/kame/kame/tcpdump/print-mobile.c index 4cbbc91812..5815102425 100644 --- a/kame/kame/tcpdump/print-mobile.c +++ b/kame/kame/tcpdump/print-mobile.c @@ -36,23 +36,17 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#if 0 -#include -#ifndef lint -__RCSID("$NetBSD: print-mobile.c,v 1.2 1998/09/30 08:57:01 hwr Exp $"); -#endif +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include -#include -#include -#include +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-mobile.c,v 1.12.2.2 2003/11/16 08:51:33 guy Exp $"; +#endif -#include -#include -#include +#include -#include #include #include "interface.h" @@ -70,8 +64,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 +81,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); @@ -96,7 +89,7 @@ mobile_print(const u_char *bp, u_int length) osp=1; cp +=4 ; } - + if (osp) { fputs("[S] ",stdout); if (vflag) @@ -108,34 +101,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/kame/kame/tcpdump/print-mobility.c b/kame/kame/tcpdump/print-mobility.c new file mode 100644 index 0000000000..f5a1a4cdf3 --- /dev/null +++ b/kame/kame/tcpdump/print-mobility.c @@ -0,0 +1,314 @@ +/* + * Copyright (C) 2002 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-mobility.c,v 1.9.2.2 2003/11/16 08:51:33 guy Exp $"; +#endif + +#ifdef INET6 +#include + +#include + +#include "ip6.h" + +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" /* must come after interface.h */ + +/* Mobility header */ +struct ip6_mobility { + u_int8_t ip6m_pproto; /* following payload protocol (for PG) */ + u_int8_t ip6m_len; /* length in units of 8 octets */ + u_int8_t ip6m_type; /* message type */ + u_int8_t reserved; /* reserved */ + u_int16_t ip6m_cksum; /* sum of IPv6 pseudo-header and MH */ + union { + u_int16_t ip6m_un_data16[1]; /* type-specific field */ + u_int8_t ip6m_un_data8[2]; /* type-specific fiedl */ + } ip6m_dataun; +}; + +#define ip6m_data16 ip6m_dataun.ip6m_un_data16 +#define ip6m_data8 ip6m_dataun.ip6m_un_data8 + +#define IP6M_MINLEN 8 + +/* message type */ +#define IP6M_BINDING_REQUEST 0 /* Binding Refresh Request */ +#define IP6M_HOME_TEST_INIT 1 /* Home Test Init */ +#define IP6M_CAREOF_TEST_INIT 2 /* Care-of Test Init */ +#define IP6M_HOME_TEST 3 /* Home Test */ +#define IP6M_CAREOF_TEST 4 /* Care-of Test */ +#define IP6M_BINDING_UPDATE 5 /* Binding Update */ +#define IP6M_BINDING_ACK 6 /* Binding Acknowledgement */ +#define IP6M_BINDING_ERROR 7 /* Binding Error */ + +/* Mobility Header Options */ +#define IP6MOPT_MINLEN 2 +#define IP6MOPT_PAD1 0x0 /* Pad1 */ +#define IP6MOPT_PADN 0x1 /* PadN */ +#define IP6MOPT_REFRESH 0x2 /* Binding Refresh Advice */ +#define IP6MOPT_REFRESH_MINLEN 4 +#define IP6MOPT_ALTCOA 0x3 /* Alternate Care-of Address */ +#define IP6MOPT_ALTCOA_MINLEN 18 +#define IP6MOPT_NONCEID 0x4 /* Nonce Indices */ +#define IP6MOPT_NONCEID_MINLEN 6 +#define IP6MOPT_AUTH 0x5 /* Binding Authorization Data */ +#define IP6MOPT_AUTH_MINLEN 12 + +static void +mobility_opt_print(const u_char *bp, int len) +{ + int i; + int optlen; + + for (i = 0; i < len; i += optlen) { + if (bp[i] == IP6MOPT_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 IP6MOPT_PAD1: + printf("(pad1)"); + break; + case IP6MOPT_PADN: + if (len - i < IP6MOPT_MINLEN) { + printf("(padn: trunc)"); + goto trunc; + } + printf("(padn)"); + break; + case IP6MOPT_REFRESH: + if (len - i < IP6MOPT_REFRESH_MINLEN) { + printf("(refresh: trunc)"); + goto trunc; + } + /* units of 4 secs */ + printf("(refresh: %d)", + EXTRACT_16BITS(&bp[i+2]) << 2); + break; + case IP6MOPT_ALTCOA: + if (len - i < IP6MOPT_ALTCOA_MINLEN) { + printf("(altcoa: trunc)"); + goto trunc; + } + printf("(alt-CoA: %s)", ip6addr_string(&bp[i+2])); + break; + case IP6MOPT_NONCEID: + if (len - i < IP6MOPT_NONCEID_MINLEN) { + printf("(ni: trunc)"); + goto trunc; + } + printf("(ni: ho=0x%04x co=0x%04x)", + EXTRACT_16BITS(&bp[i+2]), + EXTRACT_16BITS(&bp[i+4])); + break; + case IP6MOPT_AUTH: + if (len - i < IP6MOPT_AUTH_MINLEN) { + printf("(auth: trunc)"); + goto trunc; + } + printf("(auth)"); + break; + default: + if (len - i < IP6MOPT_MINLEN) { + printf("(sopt_type %d: trunc)", bp[i]); + goto trunc; + } + printf("(type-0x%02x: len=%d)", bp[i], bp[i + 1]); + break; + } + } + return; + +trunc: + printf("[trunc] "); +} + +/* + * Mobility Header + */ +int +mobility_print(const u_char *bp, const u_char *bp2) +{ + const struct ip6_mobility *mh; + const struct ip6_hdr *ip6; + const u_char *ep; + int mhlen, hlen, type; + + mh = (struct ip6_mobility *)bp; + ip6 = (struct ip6_hdr *)bp2; + + /* 'ep' points to the end of available data. */ + ep = snapend; + + if (!TTEST(mh->ip6m_len)) { + /* + * There's not enough captured data to include the + * mobility header length. + * + * Our caller expects us to return the length, however, + * so return a value that will run to the end of the + * captured data. + * + * XXX - "ip6_print()" doesn't do anything with the + * returned length, however, as it breaks out of the + * header-processing loop. + */ + mhlen = ep - bp; + goto trunc; + } + mhlen = (int)((mh->ip6m_len + 1) << 3); + + /* XXX ip6m_cksum */ + + TCHECK(mh->ip6m_type); + type = mh->ip6m_type; + switch (type) { + case IP6M_BINDING_REQUEST: + printf("mobility: BRR"); + hlen = IP6M_MINLEN; + break; + case IP6M_HOME_TEST_INIT: + case IP6M_CAREOF_TEST_INIT: + printf("mobility: %soTI", + type == IP6M_HOME_TEST_INIT ? "H" : "C"); + hlen = IP6M_MINLEN; + if (vflag) { + TCHECK2(*mh, hlen + 8); + printf(" %s Init Cookie=%08x:%08x", + type == IP6M_HOME_TEST_INIT ? "Home" : "Care-of", + EXTRACT_32BITS(&bp[hlen]), + EXTRACT_32BITS(&bp[hlen + 4])); + } + hlen += 8; + break; + case IP6M_HOME_TEST: + case IP6M_CAREOF_TEST: + printf("mobility: %soT", + type == IP6M_HOME_TEST ? "H" : "C"); + TCHECK(mh->ip6m_data16[0]); + printf(" nonce id=0x%x", EXTRACT_16BITS(&mh->ip6m_data16[0])); + hlen = IP6M_MINLEN; + if (vflag) { + TCHECK2(*mh, hlen + 8); + printf(" %s Init Cookie=%08x:%08x", + type == IP6M_HOME_TEST ? "Home" : "Care-of", + EXTRACT_32BITS(&bp[hlen]), + EXTRACT_32BITS(&bp[hlen + 4])); + } + hlen += 8; + if (vflag) { + TCHECK2(*mh, hlen + 8); + printf(" %s Keygen Token=%08x:%08x", + type == IP6M_HOME_TEST ? "Home" : "Care-of", + EXTRACT_32BITS(&bp[hlen]), + EXTRACT_32BITS(&bp[hlen + 4])); + } + hlen += 8; + break; + case IP6M_BINDING_UPDATE: + printf("mobility: BU"); + TCHECK(mh->ip6m_data16[0]); + printf(" seq#=%d", EXTRACT_16BITS(&mh->ip6m_data16[0])); + hlen = IP6M_MINLEN; + TCHECK2(*mh, hlen + 1); + if (bp[hlen] & 0xf0) + printf(" "); + if (bp[hlen] & 0x80) + printf("A"); + if (bp[hlen] & 0x40) + printf("H"); + if (bp[hlen] & 0x20) + printf("L"); + if (bp[hlen] & 0x10) + printf("K"); + /* Reserved (4bits) */ + hlen += 1; + /* Reserved (8bits) */ + hlen += 1; + TCHECK2(*mh, hlen + 2); + /* units of 4 secs */ + printf(" lifetime=%d", EXTRACT_16BITS(&bp[hlen]) << 2); + hlen += 2; + break; + case IP6M_BINDING_ACK: + printf("mobility: BA"); + TCHECK(mh->ip6m_data8[0]); + printf(" status=%d", mh->ip6m_data8[0]); + if (mh->ip6m_data8[1] & 0x80) + printf(" K"); + /* Reserved (7bits) */ + hlen = IP6M_MINLEN; + TCHECK2(*mh, hlen + 2); + printf(" seq#=%d", EXTRACT_16BITS(&bp[hlen])); + hlen += 2; + TCHECK2(*mh, hlen + 2); + /* units of 4 secs */ + printf(" lifetime=%d", EXTRACT_16BITS(&bp[hlen]) << 2); + hlen += 2; + break; + case IP6M_BINDING_ERROR: + printf("mobility: BE"); + TCHECK(mh->ip6m_data8[0]); + printf(" status=%d", mh->ip6m_data8[0]); + /* Reserved */ + hlen = IP6M_MINLEN; + TCHECK2(*mh, hlen + 16); + printf(" homeaddr %s", ip6addr_string(&bp[hlen])); + hlen += 16; + break; + default: + printf("mobility: type-#%d len=%d", type, mh->ip6m_len); + return(mhlen); + break; + } + if (vflag) + mobility_opt_print(&bp[hlen], mhlen - hlen); + + return(mhlen); + + trunc: + fputs("[|MOBILITY]", stdout); + return(mhlen); +} +#endif /* INET6 */ diff --git a/kame/kame/tcpdump/print-mpls.c b/kame/kame/tcpdump/print-mpls.c new file mode 100644 index 0000000000..6e936c8698 --- /dev/null +++ b/kame/kame/tcpdump/print-mpls.c @@ -0,0 +1,196 @@ +/* + * 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[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-mpls.c,v 1.8.2.2 2003/11/16 08:51:34 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include + +#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"); + do { + TCHECK2(*p, sizeof(v)); + v = EXTRACT_32BITS(p); + printf(" ("); /*)*/ + printf("label %u", MPLS_LABEL(v)); + if (vflag && + MPLS_LABEL(v) < sizeof(mpls_labelname) / sizeof(mpls_labelname[0])) + printf(" (%s)", mpls_labelname[MPLS_LABEL(v)]); + printf(", exp %u", MPLS_EXP(v)); + if (MPLS_STACK(v)) + printf(", [S]"); + printf(", ttl %u", MPLS_TTL(v)); + /*(*/ + printf(")"); + + p += sizeof(v); + } while (!MPLS_STACK(v)); + + switch (MPLS_LABEL(v)) { + case 0: /* IPv4 explicit NULL label */ + case 3: /* IPv4 implicit 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: + /* + * Generally there's no indication of protocol in MPLS label + * encoding, however draft-hsmit-isis-aal5mux-00.txt describes + * a technique that looks at the first payload byte if the BOS (bottom of stack) + * bit is set and tries to determine the network layer protocol + * 0x45-0x4f is IPv4 + * 0x60-0x6f is IPv6 + * 0x81-0x83 is OSI (CLNP,ES-IS,IS-IS) + * this technique is sometimes known as NULL encapsulation + * and decoding is particularly useful for control-plane traffic [BGP] + * which cisco by default sends MPLS encapsulated + */ + + if (MPLS_STACK(v)) { /* only do this if the stack bit is set */ + switch(*p) { + case 0x45: + case 0x46: + case 0x47: + case 0x48: + case 0x49: + case 0x4a: + case 0x4b: + case 0x4c: + case 0x4d: + case 0x4e: + case 0x4f: + if (vflag>0) { + printf("\n\t"); + ip_print(p, length - (p - bp)); + } + else printf(", IP, length: %u",length); + break; +#ifdef INET6 + case 0x60: + case 0x61: + case 0x62: + case 0x63: + case 0x64: + case 0x65: + case 0x66: + case 0x67: + case 0x68: + case 0x69: + case 0x6a: + case 0x6b: + case 0x6c: + case 0x6d: + case 0x6e: + case 0x6f: + if (vflag>0) { + printf("\n\t"); + ip6_print(p, length - (p - bp)); + } + else printf(", IPv6, length: %u",length); + break; +#endif + case 0x81: + case 0x82: + case 0x83: + if (vflag>0) { + printf("\n\t"); + isoclns_print(p, length - (p - bp), length - (p - bp)); + } + else printf(", OSI, length: %u",length); + break; + default: + /* ok bail out - we did not figure out what it is*/ + break; + } + } + return; + } + +trunc: + printf("[|MPLS]"); +} + +/* + * draft-ietf-mpls-lsp-ping-02.txt + */ +void +mpls_lsp_ping_print(const u_char *pptr, u_int length) +{ + printf("UDP, LSP-PING, length: %u", length); + if (vflag >1) + print_unknown_data(pptr,"\n\t ", length); +} diff --git a/kame/kame/tcpdump/print-msdp.c b/kame/kame/tcpdump/print-msdp.c new file mode 100644 index 0000000000..0606574ab3 --- /dev/null +++ b/kame/kame/tcpdump/print-msdp.c @@ -0,0 +1,101 @@ +/* + * 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[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-msdp.c,v 1.4.2.2 2003/11/16 08:51:34 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include + +#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 %u]", 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(" %u entries", *sp); + if ((u_int)((*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/kame/kame/tcpdump/print-netbios.c b/kame/kame/tcpdump/print-netbios.c index 34cc65562c..c25f343abd 100644 --- a/kame/kame/tcpdump/print-netbios.c +++ b/kame/kame/tcpdump/print-netbios.c @@ -23,25 +23,17 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-netbios.c,v 1.10 96/12/10 23:25:12 leres Exp $"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-netbios.c,v 1.18.2.2 2003/11/16 08:51:35 guy Exp $"; #endif -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include -#include -#include -#include -#include -#include -#include -#include +#include -#ifdef __STDC__ #include -#endif #include #include diff --git a/kame/kame/tcpdump/print-nfs.c b/kame/kame/tcpdump/print-nfs.c index a8e371e337..77d4ebffbf 100644 --- a/kame/kame/tcpdump/print-nfs.c +++ b/kame/kame/tcpdump/print-nfs.c @@ -20,79 +20,350 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-nfs.c,v 1.65 97/08/17 13:24:22 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.99.2.2 2003/11/16 08:51:35 guy Exp $ (LBL)"; #endif -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include -#include -#include -#include -#include -#include +#include #include -#include #include #include #include #include "interface.h" #include "addrtoname.h" +#include "extract.h" -#include "nfsv2.h" +#include "nfs.h" #include "nfsfh.h" -static void nfs_printfh(const u_int32_t *); -static void xid_map_enter(const struct rpc_msg *, const struct ip *); -static u_int32_t xid_map_find(const struct rpc_msg *, const struct ip *, - u_int32_t *); -static void interp_reply(const struct rpc_msg *, u_int32_t, u_int); +#include "ip.h" +#ifdef INET6 +#include "ip6.h" +#endif + +static void nfs_printfh(const u_int32_t *, const u_int); +static void xid_map_enter(const struct rpc_msg *, const u_char *); +static int32_t xid_map_find(const struct rpc_msg *, const u_char *, + u_int32_t *, u_int32_t *); +static void interp_reply(const struct rpc_msg *, u_int32_t, u_int32_t, int); +static const u_int32_t *parse_post_op_attr(const u_int32_t *, int); +static void print_sattr3(const struct nfsv3_sattr *sa3, int verbose); +static int print_int64(const u_int32_t *dp, int how); +static void print_nfsaddr(const u_char *, const char *, const char *); + +/* + * Mapping of old NFS Version 2 RPC numbers to generic numbers. + */ +u_int32_t nfsv3_procid[NFS_NPROCS] = { + NFSPROC_NULL, + NFSPROC_GETATTR, + NFSPROC_SETATTR, + NFSPROC_NOOP, + NFSPROC_LOOKUP, + NFSPROC_READLINK, + NFSPROC_READ, + NFSPROC_NOOP, + NFSPROC_WRITE, + NFSPROC_CREATE, + NFSPROC_REMOVE, + NFSPROC_RENAME, + NFSPROC_LINK, + NFSPROC_SYMLINK, + NFSPROC_MKDIR, + NFSPROC_RMDIR, + NFSPROC_READDIR, + NFSPROC_FSSTAT, + NFSPROC_NOOP, + NFSPROC_NOOP, + NFSPROC_NOOP, + NFSPROC_NOOP, + NFSPROC_NOOP, + NFSPROC_NOOP, + NFSPROC_NOOP, + NFSPROC_NOOP +}; + +/* + * NFS V2 and V3 status values. + * + * Some of these come from the RFCs for NFS V2 and V3, with the message + * strings taken from the FreeBSD C library "errlst.c". + * + * Others are errors that are not in the RFC but that I suspect some + * NFS servers could return; the values are FreeBSD errno values, as + * the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS + * was primarily BSD-derived. + */ +static struct tok status2str[] = { + { 1, "Operation not permitted" }, /* EPERM */ + { 2, "No such file or directory" }, /* ENOENT */ + { 5, "Input/output error" }, /* EIO */ + { 6, "Device not configured" }, /* ENXIO */ + { 11, "Resource deadlock avoided" }, /* EDEADLK */ + { 12, "Cannot allocate memory" }, /* ENOMEM */ + { 13, "Permission denied" }, /* EACCES */ + { 17, "File exists" }, /* EEXIST */ + { 18, "Cross-device link" }, /* EXDEV */ + { 19, "Operation not supported by device" }, /* ENODEV */ + { 20, "Not a directory" }, /* ENOTDIR */ + { 21, "Is a directory" }, /* EISDIR */ + { 22, "Invalid argument" }, /* EINVAL */ + { 26, "Text file busy" }, /* ETXTBSY */ + { 27, "File too large" }, /* EFBIG */ + { 28, "No space left on device" }, /* ENOSPC */ + { 30, "Read-only file system" }, /* EROFS */ + { 31, "Too many links" }, /* EMLINK */ + { 45, "Operation not supported" }, /* EOPNOTSUPP */ + { 62, "Too many levels of symbolic links" }, /* ELOOP */ + { 63, "File name too long" }, /* ENAMETOOLONG */ + { 66, "Directory not empty" }, /* ENOTEMPTY */ + { 69, "Disc quota exceeded" }, /* EDQUOT */ + { 70, "Stale NFS file handle" }, /* ESTALE */ + { 71, "Too many levels of remote in path" }, /* EREMOTE */ + { 99, "Write cache flushed to disk" }, /* NFSERR_WFLUSH (not used) */ + { 10001, "Illegal NFS file handle" }, /* NFS3ERR_BADHANDLE */ + { 10002, "Update synchronization mismatch" }, /* NFS3ERR_NOT_SYNC */ + { 10003, "READDIR/READDIRPLUS cookie is stale" }, /* NFS3ERR_BAD_COOKIE */ + { 10004, "Operation not supported" }, /* NFS3ERR_NOTSUPP */ + { 10005, "Buffer or request is too small" }, /* NFS3ERR_TOOSMALL */ + { 10006, "Unspecified error on server" }, /* NFS3ERR_SERVERFAULT */ + { 10007, "Object of that type not supported" }, /* NFS3ERR_BADTYPE */ + { 10008, "Request couldn't be completed in time" }, /* NFS3ERR_JUKEBOX */ + { 0, NULL } +}; + +static struct tok nfsv3_writemodes[] = { + { 0, "unstable" }, + { 1, "datasync" }, + { 2, "filesync" }, + { 0, NULL } +}; + +static struct tok type2str[] = { + { NFNON, "NON" }, + { NFREG, "REG" }, + { NFDIR, "DIR" }, + { NFBLK, "BLK" }, + { NFCHR, "CHR" }, + { NFLNK, "LNK" }, + { NFFIFO, "FIFO" }, + { 0, NULL } +}; + +/* + * Print out a 64-bit integer. This appears to be different on each system, + * try to make the best of it. The integer stored as 2 consecutive XDR + * encoded 32-bit integers, to which a pointer is passed. + * + * Assume that a system that has INT64_FORMAT defined, has a 64-bit + * integer datatype and can print it. + */ + +#define UNSIGNED 0 +#define SIGNED 1 +#define HEX 2 + +static int print_int64(const u_int32_t *dp, int how) +{ +#ifdef INT64_FORMAT + u_int64_t res; + + res = ((u_int64_t)EXTRACT_32BITS(&dp[0]) << 32) | (u_int64_t)EXTRACT_32BITS(&dp[1]); + switch (how) { + case SIGNED: + printf(INT64_FORMAT, res); + break; + case UNSIGNED: + printf(U_INT64_FORMAT, res); + break; + case HEX: + printf(HEX_INT64_FORMAT, res); + break; + default: + return (0); + } +#else + u_int32_t high; + + high = EXTRACT_32BITS(&dp[0]); + + switch (how) { + case SIGNED: + case UNSIGNED: + case HEX: + if (high != 0) + printf("0x%x%08x", high, EXTRACT_32BITS(&dp[1])); + else + printf("0x%x", EXTRACT_32BITS(&dp[1])); + break; + default: + return (0); + } +#endif + return 1; +} + +static void +print_nfsaddr(const u_char *bp, const char *s, const char *d) +{ + struct ip *ip; +#ifdef INET6 + struct ip6_hdr *ip6; + char srcaddr[INET6_ADDRSTRLEN], dstaddr[INET6_ADDRSTRLEN]; +#else +#ifndef INET_ADDRSTRLEN +#define INET_ADDRSTRLEN 16 +#endif + char srcaddr[INET_ADDRSTRLEN], dstaddr[INET_ADDRSTRLEN]; +#endif + + srcaddr[0] = dstaddr[0] = '\0'; + switch (IP_V((struct ip *)bp)) { + case 4: + ip = (struct ip *)bp; + strlcpy(srcaddr, ipaddr_string(&ip->ip_src), sizeof(srcaddr)); + strlcpy(dstaddr, ipaddr_string(&ip->ip_dst), sizeof(dstaddr)); + break; +#ifdef INET6 + case 6: + ip6 = (struct ip6_hdr *)bp; + strlcpy(srcaddr, ip6addr_string(&ip6->ip6_src), + sizeof(srcaddr)); + strlcpy(dstaddr, ip6addr_string(&ip6->ip6_dst), + sizeof(dstaddr)); + break; +#endif + default: + strlcpy(srcaddr, "?", sizeof(srcaddr)); + strlcpy(dstaddr, "?", sizeof(dstaddr)); + break; + } + + (void)printf("%s.%s > %s.%s: ", srcaddr, s, dstaddr, d); +} + +static const u_int32_t * +parse_sattr3(const u_int32_t *dp, struct nfsv3_sattr *sa3) +{ + TCHECK(dp[0]); + sa3->sa_modeset = EXTRACT_32BITS(dp); + dp++; + if (sa3->sa_modeset) { + TCHECK(dp[0]); + sa3->sa_mode = EXTRACT_32BITS(dp); + dp++; + } + + TCHECK(dp[0]); + sa3->sa_uidset = EXTRACT_32BITS(dp); + dp++; + if (sa3->sa_uidset) { + TCHECK(dp[0]); + sa3->sa_uid = EXTRACT_32BITS(dp); + dp++; + } + + TCHECK(dp[0]); + sa3->sa_gidset = EXTRACT_32BITS(dp); + dp++; + if (sa3->sa_gidset) { + TCHECK(dp[0]); + sa3->sa_gid = EXTRACT_32BITS(dp); + dp++; + } + + TCHECK(dp[0]); + sa3->sa_sizeset = EXTRACT_32BITS(dp); + dp++; + if (sa3->sa_sizeset) { + TCHECK(dp[0]); + sa3->sa_size = EXTRACT_32BITS(dp); + dp++; + } + + TCHECK(dp[0]); + sa3->sa_atimetype = EXTRACT_32BITS(dp); + dp++; + if (sa3->sa_atimetype == NFSV3SATTRTIME_TOCLIENT) { + TCHECK(dp[1]); + sa3->sa_atime.nfsv3_sec = EXTRACT_32BITS(dp); + dp++; + sa3->sa_atime.nfsv3_nsec = EXTRACT_32BITS(dp); + dp++; + } + + TCHECK(dp[0]); + sa3->sa_mtimetype = EXTRACT_32BITS(dp); + dp++; + if (sa3->sa_mtimetype == NFSV3SATTRTIME_TOCLIENT) { + TCHECK(dp[1]); + sa3->sa_mtime.nfsv3_sec = EXTRACT_32BITS(dp); + dp++; + sa3->sa_mtime.nfsv3_nsec = EXTRACT_32BITS(dp); + dp++; + } + + return dp; +trunc: + return NULL; +} static int nfserr; /* true if we error rather than trunc */ +static void +print_sattr3(const struct nfsv3_sattr *sa3, int verbose) +{ + if (sa3->sa_modeset) + printf(" mode %o", sa3->sa_mode); + if (sa3->sa_uidset) + printf(" uid %u", sa3->sa_uid); + if (sa3->sa_gidset) + printf(" gid %u", sa3->sa_gid); + if (verbose > 1) { + if (sa3->sa_atimetype == NFSV3SATTRTIME_TOCLIENT) + printf(" atime %u.%06u", sa3->sa_atime.nfsv3_sec, + sa3->sa_atime.nfsv3_nsec); + if (sa3->sa_mtimetype == NFSV3SATTRTIME_TOCLIENT) + printf(" mtime %u.%06u", sa3->sa_mtime.nfsv3_sec, + sa3->sa_mtime.nfsv3_nsec); + } +} + void nfsreply_print(register const u_char *bp, u_int length, register const u_char *bp2) { register const struct rpc_msg *rp; - register const struct ip *ip; - u_int32_t proc; + u_int32_t proc, vers; + char srcid[20], dstid[20]; /*fits 32bit*/ nfserr = 0; /* assume no error */ rp = (const struct rpc_msg *)bp; - ip = (const struct ip *)bp2; - - if (!nflag) - (void)printf("%s.nfs > %s.%u: reply %s %d", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst), - (u_int32_t)ntohl(rp->rm_xid), - ntohl(rp->rm_reply.rp_stat) == MSG_ACCEPTED? - "ok":"ERR", - length); - else - (void)printf("%s.%u > %s.%u: reply %s %d", - ipaddr_string(&ip->ip_src), - NFS_PORT, - ipaddr_string(&ip->ip_dst), - (u_int32_t)ntohl(rp->rm_xid), - ntohl(rp->rm_reply.rp_stat) == MSG_ACCEPTED? - "ok":"ERR", + + if (!nflag) { + strlcpy(srcid, "nfs", sizeof(srcid)); + snprintf(dstid, sizeof(dstid), "%u", + EXTRACT_32BITS(&rp->rm_xid)); + } else { + snprintf(srcid, sizeof(srcid), "%u", NFS_PORT); + snprintf(dstid, sizeof(dstid), "%u", + EXTRACT_32BITS(&rp->rm_xid)); + } + print_nfsaddr(bp2, srcid, dstid); + (void)printf("reply %s %d", + EXTRACT_32BITS(&rp->rm_reply.rp_stat) == MSG_ACCEPTED? + "ok":"ERR", length); - if (xid_map_find(rp, ip, &proc)) - interp_reply(rp, proc, length); + if (xid_map_find(rp, bp2, &proc, &vers) >= 0) + interp_reply(rp, proc, vers, length); } /* @@ -110,11 +381,11 @@ parsereq(register const struct rpc_msg *rp, register u_int length) */ dp = (u_int32_t *)&rp->rm_call.cb_cred; TCHECK(dp[1]); - len = ntohl(dp[1]); + len = EXTRACT_32BITS(&dp[1]); if (len < length) { dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp); TCHECK(dp[1]); - len = ntohl(dp[1]); + len = EXTRACT_32BITS(&dp[1]); if (len < length) { dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp); TCHECK2(dp[0], 0); @@ -130,12 +401,22 @@ parsereq(register const struct rpc_msg *rp, register u_int length) * If packet was truncated, return 0. */ static const u_int32_t * -parsefh(register const u_int32_t *dp) +parsefh(register const u_int32_t *dp, int v3) { - if (dp + 8 <= (u_int32_t *)snapend) { - nfs_printfh(dp); - return (dp + 8); + u_int len; + + if (v3) { + TCHECK(dp[0]); + len = EXTRACT_32BITS(dp) / 4; + dp++; + } else + len = NFSX_V2FH / 4; + + if (TTEST2(*dp, len * sizeof(*dp))) { + nfs_printfh(dp, len); + return (dp + len); } +trunc: return (NULL); } @@ -150,24 +431,25 @@ parsefn(register const u_int32_t *dp) register const u_char *cp; /* Bail if we don't have the string length */ - if ((u_char *)dp > snapend - sizeof(*dp)) - return (NULL); + TCHECK(*dp); /* Fetch string length; convert to host order */ len = *dp++; NTOHL(len); + TCHECK2(*dp, ((len + 3) & ~3)); + cp = (u_char *)dp; /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */ dp += ((len + 3) & ~3) / sizeof(*dp); - if ((u_char *)dp > snapend) - return (NULL); /* XXX seems like we should be checking the length */ putchar('"'); (void) fn_printn(cp, len, NULL); putchar('"'); return (dp); +trunc: + return NULL; } /* @@ -176,9 +458,9 @@ parsefn(register const u_int32_t *dp) * If packet was truncated (or there was some other error), return 0. */ static const u_int32_t * -parsefhn(register const u_int32_t *dp) +parsefhn(register const u_int32_t *dp, int v3) { - dp = parsefh(dp); + dp = parsefh(dp, v3); if (dp == NULL) return (NULL); putchar(' '); @@ -190,128 +472,199 @@ nfsreq_print(register const u_char *bp, u_int length, register const u_char *bp2) { register const struct rpc_msg *rp; - register const struct ip *ip; register const u_int32_t *dp; + nfs_type type; + int v3; + u_int32_t proc; + struct nfsv3_sattr sa3; + char srcid[20], dstid[20]; /*fits 32bit*/ nfserr = 0; /* assume no error */ rp = (const struct rpc_msg *)bp; - ip = (const struct ip *)bp2; - if (!nflag) - (void)printf("%s.%u > %s.nfs: %d", - ipaddr_string(&ip->ip_src), - (u_int32_t)ntohl(rp->rm_xid), - ipaddr_string(&ip->ip_dst), - length); - else - (void)printf("%s.%u > %s.%u: %d", - ipaddr_string(&ip->ip_src), - (u_int32_t)ntohl(rp->rm_xid), - ipaddr_string(&ip->ip_dst), - NFS_PORT, - length); + if (!nflag) { + snprintf(srcid, sizeof(srcid), "%u", + EXTRACT_32BITS(&rp->rm_xid)); + strlcpy(dstid, "nfs", sizeof(dstid)); + } else { + snprintf(srcid, sizeof(srcid), "%u", + EXTRACT_32BITS(&rp->rm_xid)); + snprintf(dstid, sizeof(dstid), "%u", NFS_PORT); + } + print_nfsaddr(bp2, srcid, dstid); + (void)printf("%d", length); + + xid_map_enter(rp, bp2); /* record proc number for later on */ - xid_map_enter(rp, ip); /* record proc number for later on */ + v3 = (EXTRACT_32BITS(&rp->rm_call.cb_vers) == NFS_VER3); + proc = EXTRACT_32BITS(&rp->rm_call.cb_proc); - switch (ntohl(rp->rm_call.cb_proc)) { -#ifdef NFSPROC_NOOP + if (!v3 && proc < NFS_NPROCS) + proc = nfsv3_procid[proc]; + + switch (proc) { case NFSPROC_NOOP: printf(" nop"); return; -#else -#define NFSPROC_NOOP -1 -#endif case NFSPROC_NULL: printf(" null"); return; case NFSPROC_GETATTR: printf(" getattr"); - if ((dp = parsereq(rp, length)) != NULL && parsefh(dp) != NULL) + if ((dp = parsereq(rp, length)) != NULL && + parsefh(dp, v3) != NULL) return; break; case NFSPROC_SETATTR: printf(" setattr"); - if ((dp = parsereq(rp, length)) != NULL && parsefh(dp) != NULL) + if ((dp = parsereq(rp, length)) != NULL && + parsefh(dp, v3) != NULL) return; break; -#if NFSPROC_ROOT != NFSPROC_NOOP - case NFSPROC_ROOT: - printf(" root"); - break; -#endif case NFSPROC_LOOKUP: printf(" lookup"); - if ((dp = parsereq(rp, length)) != NULL && parsefhn(dp) != NULL) + if ((dp = parsereq(rp, length)) != NULL && + parsefhn(dp, v3) != NULL) + return; + break; + + case NFSPROC_ACCESS: + printf(" access"); + if ((dp = parsereq(rp, length)) != NULL && + (dp = parsefh(dp, v3)) != NULL) { + TCHECK(dp[0]); + printf(" %04x", EXTRACT_32BITS(&dp[0])); return; + } break; case NFSPROC_READLINK: printf(" readlink"); - if ((dp = parsereq(rp, length)) != NULL && parsefh(dp) != NULL) + if ((dp = parsereq(rp, length)) != NULL && + parsefh(dp, v3) != NULL) return; break; case NFSPROC_READ: printf(" read"); if ((dp = parsereq(rp, length)) != NULL && - (dp = parsefh(dp)) != NULL) { - TCHECK2(dp[0], 3 * sizeof(*dp)); - printf(" %u bytes @ %u", - (u_int32_t)ntohl(dp[1]), - (u_int32_t)ntohl(dp[0])); + (dp = parsefh(dp, v3)) != NULL) { + if (v3) { + TCHECK(dp[2]); + printf(" %u bytes @ ", + EXTRACT_32BITS(&dp[2])); + print_int64(dp, UNSIGNED); + } else { + TCHECK(dp[1]); + printf(" %u bytes @ %u", + EXTRACT_32BITS(&dp[1]), + EXTRACT_32BITS(&dp[0])); + } return; } break; -#if NFSPROC_WRITECACHE != NFSPROC_NOOP - case NFSPROC_WRITECACHE: - printf(" writecache"); - if ((dp = parsereq(rp, length)) != NULL && - (dp = parsefh(dp)) != NULL) { - TCHECK2(dp[0], 4 * sizeof(*dp)); - printf(" %u (%u) bytes @ %u (%u)", - (u_int32_t)ntohl(dp[3]), - (u_int32_t)ntohl(dp[2]), - (u_int32_t)ntohl(dp[1]), - (u_int32_t)ntohl(dp[0])); - return; - } - break; -#endif case NFSPROC_WRITE: printf(" write"); if ((dp = parsereq(rp, length)) != NULL && - (dp = parsefh(dp)) != NULL) { - TCHECK2(dp[0], 4 * sizeof(*dp)); - printf(" %u (%u) bytes @ %u (%u)", - (u_int32_t)ntohl(dp[3]), - (u_int32_t)ntohl(dp[2]), - (u_int32_t)ntohl(dp[1]), - (u_int32_t)ntohl(dp[0])); + (dp = parsefh(dp, v3)) != NULL) { + if (v3) { + TCHECK(dp[4]); + printf(" %u bytes @ ", + EXTRACT_32BITS(&dp[4])); + print_int64(dp, UNSIGNED); + if (vflag) { + dp += 3; + TCHECK(dp[0]); + printf(" <%s>", + tok2str(nfsv3_writemodes, + NULL, EXTRACT_32BITS(dp))); + } + } else { + TCHECK(dp[3]); + printf(" %u (%u) bytes @ %u (%u)", + EXTRACT_32BITS(&dp[3]), + EXTRACT_32BITS(&dp[2]), + EXTRACT_32BITS(&dp[1]), + EXTRACT_32BITS(&dp[0])); + } return; } break; case NFSPROC_CREATE: printf(" create"); - if ((dp = parsereq(rp, length)) != NULL && parsefhn(dp) != NULL) + if ((dp = parsereq(rp, length)) != NULL && + parsefhn(dp, v3) != NULL) + return; + break; + + case NFSPROC_MKDIR: + printf(" mkdir"); + if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp, v3) != 0) return; break; + case NFSPROC_SYMLINK: + printf(" symlink"); + if ((dp = parsereq(rp, length)) != 0 && + (dp = parsefhn(dp, v3)) != 0) { + fputs(" ->", stdout); + if (v3 && (dp = parse_sattr3(dp, &sa3)) == 0) + break; + if (parsefn(dp) == 0) + break; + if (v3 && vflag) + print_sattr3(&sa3, vflag); + return; + } + break; + + case NFSPROC_MKNOD: + printf(" mknod"); + if ((dp = parsereq(rp, length)) != 0 && + (dp = parsefhn(dp, v3)) != 0) { + TCHECK(*dp); + type = (nfs_type)EXTRACT_32BITS(dp); + dp++; + if ((dp = parse_sattr3(dp, &sa3)) == 0) + break; + printf(" %s", tok2str(type2str, "unk-ft %d", type)); + if (vflag && (type == NFCHR || type == NFBLK)) { + TCHECK(dp[1]); + printf(" %u/%u", + EXTRACT_32BITS(&dp[0]), + EXTRACT_32BITS(&dp[1])); + dp += 2; + } + if (vflag) + print_sattr3(&sa3, vflag); + return; + } + break; + case NFSPROC_REMOVE: printf(" remove"); - if ((dp = parsereq(rp, length)) != NULL && parsefhn(dp) != NULL) + if ((dp = parsereq(rp, length)) != NULL && + parsefhn(dp, v3) != NULL) + return; + break; + + case NFSPROC_RMDIR: + printf(" rmdir"); + if ((dp = parsereq(rp, length)) != NULL && + parsefhn(dp, v3) != NULL) return; break; case NFSPROC_RENAME: printf(" rename"); if ((dp = parsereq(rp, length)) != NULL && - (dp = parsefhn(dp)) != NULL) { + (dp = parsefhn(dp, v3)) != NULL) { fputs(" ->", stdout); - if (parsefhn(dp) != NULL) + if (parsefhn(dp, v3) != NULL) return; } break; @@ -319,61 +672,97 @@ nfsreq_print(register const u_char *bp, u_int length, case NFSPROC_LINK: printf(" link"); if ((dp = parsereq(rp, length)) != NULL && - (dp = parsefh(dp)) != NULL) { + (dp = parsefh(dp, v3)) != NULL) { fputs(" ->", stdout); - if (parsefhn(dp) != NULL) + if (parsefhn(dp, v3) != NULL) return; } break; - case NFSPROC_SYMLINK: - printf(" symlink"); + case NFSPROC_READDIR: + printf(" readdir"); if ((dp = parsereq(rp, length)) != NULL && - (dp = parsefhn(dp)) != NULL) { - fputs(" -> ", stdout); - if (parsefn(dp) != NULL) - return; + (dp = parsefh(dp, v3)) != NULL) { + if (v3) { + TCHECK(dp[4]); + /* + * We shouldn't really try to interpret the + * offset cookie here. + */ + printf(" %u bytes @ ", + EXTRACT_32BITS(&dp[4])); + print_int64(dp, SIGNED); + if (vflag) + printf(" verf %08x%08x", dp[2], + dp[3]); + } else { + TCHECK(dp[1]); + /* + * Print the offset as signed, since -1 is + * common, but offsets > 2^31 aren't. + */ + printf(" %u bytes @ %d", + EXTRACT_32BITS(&dp[1]), + EXTRACT_32BITS(&dp[0])); + } + return; } break; - case NFSPROC_MKDIR: - printf(" mkdir"); - if ((dp = parsereq(rp, length)) != NULL && parsefhn(dp) != NULL) + case NFSPROC_READDIRPLUS: + printf(" readdirplus"); + if ((dp = parsereq(rp, length)) != NULL && + (dp = parsefh(dp, v3)) != NULL) { + TCHECK(dp[4]); + /* + * We don't try to interpret the offset + * cookie here. + */ + printf(" %u bytes @ ", EXTRACT_32BITS(&dp[4])); + print_int64(dp, SIGNED); + if (vflag) + printf(" max %u verf %08x%08x", + EXTRACT_32BITS(&dp[5]), dp[2], dp[3]); return; + } break; - case NFSPROC_RMDIR: - printf(" rmdir"); - if ((dp = parsereq(rp, length)) != NULL && parsefhn(dp) != NULL) + case NFSPROC_FSSTAT: + printf(" fsstat"); + if ((dp = parsereq(rp, length)) != NULL && + parsefh(dp, v3) != NULL) return; break; - case NFSPROC_READDIR: - printf(" readdir"); + case NFSPROC_FSINFO: + printf(" fsinfo"); if ((dp = parsereq(rp, length)) != NULL && - (dp = parsefh(dp)) != NULL) { - TCHECK2(dp[0], 2 * sizeof(*dp)); - /* - * Print the offset as signed, since -1 is common, - * but offsets > 2^31 aren't. - */ - printf(" %u bytes @ %d", - (u_int32_t)ntohl(dp[1]), - (u_int32_t)ntohl(dp[0])); + parsefh(dp, v3) != NULL) return; - } break; - case NFSPROC_STATFS: - printf(" statfs"); - if ((dp = parsereq(rp, length)) != NULL && parsefh(dp) != NULL) + case NFSPROC_PATHCONF: + printf(" pathconf"); + if ((dp = parsereq(rp, length)) != NULL && + parsefh(dp, v3) != NULL) return; break; + case NFSPROC_COMMIT: + printf(" commit"); + if ((dp = parsereq(rp, length)) != NULL && + (dp = parsefh(dp, v3)) != NULL) { + printf(" %u bytes @ ", EXTRACT_32BITS(&dp[2])); + print_int64(dp, UNSIGNED); + return; + } + break; + default: - printf(" proc-%u", (u_int32_t)ntohl(rp->rm_call.cb_proc)); + printf(" proc-%u", EXTRACT_32BITS(&rp->rm_call.cb_proc)); return; } + trunc: if (!nfserr) fputs(" [|nfs]", stdout); @@ -389,30 +778,51 @@ nfsreq_print(register const u_char *bp, u_int length, * additional hacking on the parser code. */ static void -nfs_printfh(register const u_int32_t *dp) +nfs_printfh(register const u_int32_t *dp, const u_int len) { my_fsid fsid; ino_t ino; - char *sfsname = NULL; + const char *sfsname = NULL; + char *spacep; + + if (uflag) { + u_int i; + char const *sep = ""; + + printf(" fh["); + for (i=0; i= XIDMAPSIZE) xid_map_next = 0; xmep->xid = rp->rm_xid; - xmep->client = ip->ip_src; - xmep->server = ip->ip_dst; - xmep->proc = ntohl(rp->rm_call.cb_proc); + if (ip) { + xmep->ipver = 4; + memcpy(&xmep->client, &ip->ip_src, sizeof(ip->ip_src)); + memcpy(&xmep->server, &ip->ip_dst, sizeof(ip->ip_dst)); + } +#ifdef INET6 + else if (ip6) { + xmep->ipver = 6; + memcpy(&xmep->client, &ip6->ip6_src, sizeof(ip6->ip6_src)); + memcpy(&xmep->server, &ip6->ip6_dst, sizeof(ip6->ip6_dst)); + } +#endif + xmep->proc = EXTRACT_32BITS(&rp->rm_call.cb_proc); + xmep->vers = EXTRACT_32BITS(&rp->rm_call.cb_vers); } -/* Returns true and sets proc success or false on failure */ -static u_int32_t -xid_map_find(const struct rpc_msg *rp, const struct ip *ip, u_int32_t *proc) +/* + * Returns 0 and puts NFSPROC_xxx in proc return and + * version in vers return, or returns -1 on failure + */ +static int +xid_map_find(const struct rpc_msg *rp, const u_char *bp, u_int32_t *proc, + u_int32_t *vers) { int i; struct xid_map_entry *xmep; u_int32_t xid = rp->rm_xid; - u_int32_t clip = ip->ip_dst.s_addr; - u_int32_t sip = ip->ip_src.s_addr; + struct ip *ip = (struct ip *)bp; +#ifdef INET6 + struct ip6_hdr *ip6 = (struct ip6_hdr *)bp; +#endif + int cmp; /* Start searching from where we last left off */ i = xid_map_hint; do { xmep = &xid_map[i]; - if (xmep->xid == xid && xmep->client.s_addr == clip && - xmep->server.s_addr == sip) { + cmp = 1; + if (xmep->ipver != IP_V(ip) || xmep->xid != xid) + goto nextitem; + switch (xmep->ipver) { + case 4: + if (memcmp(&ip->ip_src, &xmep->server, + sizeof(ip->ip_src)) != 0 || + memcmp(&ip->ip_dst, &xmep->client, + sizeof(ip->ip_dst)) != 0) { + cmp = 0; + } + break; +#ifdef INET6 + case 6: + if (memcmp(&ip6->ip6_src, &xmep->server, + sizeof(ip6->ip6_src)) != 0 || + memcmp(&ip6->ip6_dst, &xmep->client, + sizeof(ip6->ip6_dst)) != 0) { + cmp = 0; + } + break; +#endif + default: + cmp = 0; + break; + } + if (cmp) { /* match */ xid_map_hint = i; *proc = xmep->proc; - return (1); + *vers = xmep->vers; + return 0; } + nextitem: if (++i >= XIDMAPSIZE) i = 0; } while (i != xid_map_hint); /* search failed */ - return (0); + return (-1); } /* @@ -517,8 +996,8 @@ parserep(register const struct rpc_msg *rp, register u_int length) * which is an "enum" and so occupies one 32-bit word. */ dp = ((const u_int32_t *)&rp->rm_reply) + 1; - TCHECK2(dp[0], 1); - len = ntohl(dp[1]); + TCHECK(dp[1]); + len = EXTRACT_32BITS(&dp[1]); if (len >= length) return (NULL); /* @@ -530,7 +1009,7 @@ parserep(register const struct rpc_msg *rp, register u_int length) /* * now we can check the ar_stat field */ - astat = ntohl(*(enum accept_stat *)dp); + astat = EXTRACT_32BITS(dp); switch (astat) { case SUCCESS: @@ -567,138 +1046,198 @@ parserep(register const struct rpc_msg *rp, register u_int length) return (NULL); } /* successful return */ - if ((sizeof(astat) + ((u_char *)dp)) < snapend) - return ((u_int32_t *) (sizeof(astat) + ((char *)dp))); - + TCHECK2(*dp, sizeof(astat)); + return ((u_int32_t *) (sizeof(astat) + ((char *)dp))); trunc: - return (NULL); + return (0); } static const u_int32_t * -parsestatus(const u_int32_t *dp) +parsestatus(const u_int32_t *dp, int *er) { - register int errnum; + int errnum; TCHECK(dp[0]); - errnum = ntohl(dp[0]); + + errnum = EXTRACT_32BITS(&dp[0]); + if (er) + *er = errnum; if (errnum != 0) { if (!qflag) - printf(" ERROR: %s", pcap_strerror(errnum)); - nfserr = 1; /* suppress trunc string */ - return (NULL); + printf(" ERROR: %s", + tok2str(status2str, "unk %d", errnum)); + nfserr = 1; } return (dp + 1); trunc: - return (NULL); + return NULL; } -static struct tok type2str[] = { - { NFNON, "NON" }, - { NFREG, "REG" }, - { NFDIR, "DIR" }, - { NFBLK, "BLK" }, - { NFCHR, "CHR" }, - { NFLNK, "LNK" }, - { 0, NULL } -}; - static const u_int32_t * -parsefattr(const u_int32_t *dp, int verbose) +parsefattr(const u_int32_t *dp, int verbose, int v3) { - const struct nfsv2_fattr *fap; + const struct nfs_fattr *fap; - fap = (const struct nfsv2_fattr *)dp; + fap = (const struct nfs_fattr *)dp; + TCHECK(fap->fa_gid); if (verbose) { - TCHECK(fap->fa_nfssize); - printf(" %s %o ids %u/%u sz %u ", + printf(" %s %o ids %d/%d", tok2str(type2str, "unk-ft %d ", - (u_int32_t)ntohl(fap->fa_type)), - (u_int32_t)ntohl(fap->fa_mode), - (u_int32_t)ntohl(fap->fa_uid), - (u_int32_t)ntohl(fap->fa_gid), - (u_int32_t)ntohl(fap->fa_nfssize)); + EXTRACT_32BITS(&fap->fa_type)), + EXTRACT_32BITS(&fap->fa_mode), + EXTRACT_32BITS(&fap->fa_uid), + EXTRACT_32BITS(&fap->fa_gid)); + if (v3) { + TCHECK(fap->fa3_size); + printf(" sz "); + print_int64((u_int32_t *)&fap->fa3_size, UNSIGNED); + } else { + TCHECK(fap->fa2_size); + printf(" sz %d", EXTRACT_32BITS(&fap->fa2_size)); + } } /* print lots more stuff */ if (verbose > 1) { - TCHECK(fap->fa_nfsfileid); - printf("nlink %u rdev %x fsid %x nodeid %x a/m/ctime ", - (u_int32_t)ntohl(fap->fa_nlink), - (u_int32_t)ntohl(fap->fa_nfsrdev), - (u_int32_t)ntohl(fap->fa_nfsfsid), - (u_int32_t)ntohl(fap->fa_nfsfileid)); - TCHECK(fap->fa_nfsatime); - printf("%u.%06u ", - (u_int32_t)ntohl(fap->fa_nfsatime.nfs_sec), - (u_int32_t)ntohl(fap->fa_nfsatime.nfs_usec)); - TCHECK(fap->fa_nfsmtime); - printf("%u.%06u ", - (u_int32_t)ntohl(fap->fa_nfsmtime.nfs_sec), - (u_int32_t)ntohl(fap->fa_nfsmtime.nfs_usec)); - TCHECK(fap->fa_nfsctime); - printf("%u.%06u ", - (u_int32_t)ntohl(fap->fa_nfsctime.nfs_sec), - (u_int32_t)ntohl(fap->fa_nfsctime.nfs_usec)); + if (v3) { + TCHECK(fap->fa3_ctime); + printf(" nlink %d rdev %d/%d", + EXTRACT_32BITS(&fap->fa_nlink), + EXTRACT_32BITS(&fap->fa3_rdev.specdata1), + EXTRACT_32BITS(&fap->fa3_rdev.specdata2)); + printf(" fsid "); + print_int64((u_int32_t *)&fap->fa3_fsid, HEX); + printf(" fileid "); + print_int64((u_int32_t *)&fap->fa3_fileid, HEX); + printf(" a/m/ctime %u.%06u", + EXTRACT_32BITS(&fap->fa3_atime.nfsv3_sec), + EXTRACT_32BITS(&fap->fa3_atime.nfsv3_nsec)); + printf(" %u.%06u", + EXTRACT_32BITS(&fap->fa3_mtime.nfsv3_sec), + EXTRACT_32BITS(&fap->fa3_mtime.nfsv3_nsec)); + printf(" %u.%06u", + EXTRACT_32BITS(&fap->fa3_ctime.nfsv3_sec), + EXTRACT_32BITS(&fap->fa3_ctime.nfsv3_nsec)); + } else { + TCHECK(fap->fa2_ctime); + printf(" nlink %d rdev %x fsid %x nodeid %x a/m/ctime", + EXTRACT_32BITS(&fap->fa_nlink), + EXTRACT_32BITS(&fap->fa2_rdev), + EXTRACT_32BITS(&fap->fa2_fsid), + EXTRACT_32BITS(&fap->fa2_fileid)); + printf(" %u.%06u", + EXTRACT_32BITS(&fap->fa2_atime.nfsv2_sec), + EXTRACT_32BITS(&fap->fa2_atime.nfsv2_usec)); + printf(" %u.%06u", + EXTRACT_32BITS(&fap->fa2_mtime.nfsv2_sec), + EXTRACT_32BITS(&fap->fa2_mtime.nfsv2_usec)); + printf(" %u.%06u", + EXTRACT_32BITS(&fap->fa2_ctime.nfsv2_sec), + EXTRACT_32BITS(&fap->fa2_ctime.nfsv2_usec)); + } } - return ((const u_int32_t *)&fap[1]); + return ((const u_int32_t *)((unsigned char *)dp + + (v3 ? NFSX_V3FATTR : NFSX_V2FATTR))); trunc: return (NULL); } static int -parseattrstat(const u_int32_t *dp, int verbose) +parseattrstat(const u_int32_t *dp, int verbose, int v3) { + int er; - dp = parsestatus(dp); + dp = parsestatus(dp, &er); if (dp == NULL) return (0); + if (er) + return (1); - return (parsefattr(dp, verbose) != NULL); + return (parsefattr(dp, verbose, v3) != NULL); } static int parsediropres(const u_int32_t *dp) { + int er; - dp = parsestatus(dp); - if (dp == NULL) + if (!(dp = parsestatus(dp, &er))) return (0); + if (er) + return (1); - dp = parsefh(dp); + dp = parsefh(dp, 0); if (dp == NULL) return (0); - return (parsefattr(dp, vflag) != NULL); + return (parsefattr(dp, vflag, 0) != NULL); } static int -parselinkres(const u_int32_t *dp) +parselinkres(const u_int32_t *dp, int v3) { - dp = parsestatus(dp); + int er; + + dp = parsestatus(dp, &er); if (dp == NULL) + return(0); + if (er) + return(1); + if (v3 && !(dp = parse_post_op_attr(dp, vflag))) return (0); - putchar(' '); return (parsefn(dp) != NULL); } static int -parsestatfs(const u_int32_t *dp) +parsestatfs(const u_int32_t *dp, int v3) { - const struct nfsv2_statfs *sfsp; + const struct nfs_statfs *sfsp; + int er; - dp = parsestatus(dp); + dp = parsestatus(dp, &er); if (dp == NULL) return (0); + if (!v3 && er) + return (1); - if (!qflag) { - sfsp = (const struct nfsv2_statfs *)dp; - TCHECK(sfsp->sf_bavail); - printf(" tsize %u bsize %u blocks %u bfree %u bavail %u", - (u_int32_t)ntohl(sfsp->sf_tsize), - (u_int32_t)ntohl(sfsp->sf_bsize), - (u_int32_t)ntohl(sfsp->sf_blocks), - (u_int32_t)ntohl(sfsp->sf_bfree), - (u_int32_t)ntohl(sfsp->sf_bavail)); + if (qflag) + return(1); + + if (v3) { + if (vflag) + printf(" POST:"); + if (!(dp = parse_post_op_attr(dp, vflag))) + return (0); + } + + TCHECK2(*dp, (v3 ? NFSX_V3STATFS : NFSX_V2STATFS)); + + sfsp = (const struct nfs_statfs *)dp; + + if (v3) { + printf(" tbytes "); + print_int64((u_int32_t *)&sfsp->sf_tbytes, UNSIGNED); + printf(" fbytes "); + print_int64((u_int32_t *)&sfsp->sf_fbytes, UNSIGNED); + printf(" abytes "); + print_int64((u_int32_t *)&sfsp->sf_abytes, UNSIGNED); + if (vflag) { + printf(" tfiles "); + print_int64((u_int32_t *)&sfsp->sf_tfiles, UNSIGNED); + printf(" ffiles "); + print_int64((u_int32_t *)&sfsp->sf_ffiles, UNSIGNED); + printf(" afiles "); + print_int64((u_int32_t *)&sfsp->sf_afiles, UNSIGNED); + printf(" invar %u", + EXTRACT_32BITS(&sfsp->sf_invarsec)); + } + } else { + printf(" tsize %d bsize %d blocks %d bfree %d bavail %d", + EXTRACT_32BITS(&sfsp->sf_tsize), + EXTRACT_32BITS(&sfsp->sf_bsize), + EXTRACT_32BITS(&sfsp->sf_blocks), + EXTRACT_32BITS(&sfsp->sf_bfree), + EXTRACT_32BITS(&sfsp->sf_bavail)); } return (1); @@ -709,38 +1248,238 @@ parsestatfs(const u_int32_t *dp) static int parserddires(const u_int32_t *dp) { - dp = parsestatus(dp); + int er; + + dp = parsestatus(dp, &er); if (dp == NULL) return (0); - if (!qflag) { + if (er) + return (1); + if (qflag) + return (1); + + TCHECK(dp[2]); + printf(" offset %x size %d ", + EXTRACT_32BITS(&dp[0]), EXTRACT_32BITS(&dp[1])); + if (dp[2] != 0) + printf(" eof"); + + return (1); +trunc: + return (0); +} + +static const u_int32_t * +parse_wcc_attr(const u_int32_t *dp) +{ + printf(" sz "); + print_int64(dp, UNSIGNED); + printf(" mtime %u.%06u ctime %u.%06u", + EXTRACT_32BITS(&dp[2]), EXTRACT_32BITS(&dp[3]), + EXTRACT_32BITS(&dp[4]), EXTRACT_32BITS(&dp[5])); + return (dp + 6); +} + +/* + * Pre operation attributes. Print only if vflag > 1. + */ +static const u_int32_t * +parse_pre_op_attr(const u_int32_t *dp, int verbose) +{ + TCHECK(dp[0]); + if (!EXTRACT_32BITS(&dp[0])) + return (dp + 1); + dp++; + TCHECK2(*dp, 24); + if (verbose > 1) { + return parse_wcc_attr(dp); + } else { + /* If not verbose enough, just skip over wcc_attr */ + return (dp + 6); + } +trunc: + return (NULL); +} + +/* + * Post operation attributes are printed if vflag >= 1 + */ +static const u_int32_t * +parse_post_op_attr(const u_int32_t *dp, int verbose) +{ + TCHECK(dp[0]); + if (!EXTRACT_32BITS(&dp[0])) + return (dp + 1); + dp++; + if (verbose) { + return parsefattr(dp, verbose, 1); + } else + return (dp + (NFSX_V3FATTR / sizeof (u_int32_t))); +trunc: + return (NULL); +} + +static const u_int32_t * +parse_wcc_data(const u_int32_t *dp, int verbose) +{ + if (verbose > 1) + printf(" PRE:"); + if (!(dp = parse_pre_op_attr(dp, verbose))) + return (0); + + if (verbose) + printf(" POST:"); + return parse_post_op_attr(dp, verbose); +} + +static const u_int32_t * +parsecreateopres(const u_int32_t *dp, int verbose) +{ + int er; + + if (!(dp = parsestatus(dp, &er))) + return (0); + if (er) + dp = parse_wcc_data(dp, verbose); + else { TCHECK(dp[0]); - printf(" offset %x", (u_int32_t)ntohl(dp[0])); + if (!EXTRACT_32BITS(&dp[0])) + return (dp + 1); + dp++; + if (!(dp = parsefh(dp, 1))) + return (0); + if (verbose) { + if (!(dp = parse_post_op_attr(dp, verbose))) + return (0); + if (vflag > 1) { + printf(" dir attr:"); + dp = parse_wcc_data(dp, verbose); + } + } + } + return (dp); +trunc: + return (NULL); +} + +static int +parsewccres(const u_int32_t *dp, int verbose) +{ + int er; + + if (!(dp = parsestatus(dp, &er))) + return (0); + return parse_wcc_data(dp, verbose) != 0; +} + +static const u_int32_t * +parsev3rddirres(const u_int32_t *dp, int verbose) +{ + int er; + + if (!(dp = parsestatus(dp, &er))) + return (0); + if (vflag) + printf(" POST:"); + if (!(dp = parse_post_op_attr(dp, verbose))) + return (0); + if (er) + return dp; + if (vflag) { TCHECK(dp[1]); - printf(" size %u", (u_int32_t)ntohl(dp[1])); - TCHECK(dp[2]); - if (dp[2] != 0) - printf(" eof"); + printf(" verf %08x%08x", dp[0], dp[1]); + dp += 2; + } + return dp; +trunc: + return (NULL); +} + +static int +parsefsinfo(const u_int32_t *dp) +{ + struct nfsv3_fsinfo *sfp; + int er; + + if (!(dp = parsestatus(dp, &er))) + return (0); + if (vflag) + printf(" POST:"); + if (!(dp = parse_post_op_attr(dp, vflag))) + return (0); + if (er) + return (1); + + sfp = (struct nfsv3_fsinfo *)dp; + TCHECK(*sfp); + printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u", + EXTRACT_32BITS(&sfp->fs_rtmax), + EXTRACT_32BITS(&sfp->fs_rtpref), + EXTRACT_32BITS(&sfp->fs_wtmax), + EXTRACT_32BITS(&sfp->fs_wtpref), + EXTRACT_32BITS(&sfp->fs_dtpref)); + if (vflag) { + printf(" rtmult %u wtmult %u maxfsz ", + EXTRACT_32BITS(&sfp->fs_rtmult), + EXTRACT_32BITS(&sfp->fs_wtmult)); + print_int64((u_int32_t *)&sfp->fs_maxfilesize, UNSIGNED); + printf(" delta %u.%06u ", + EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_sec), + EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_nsec)); } + return (1); +trunc: + return (0); +} + +static int +parsepathconf(const u_int32_t *dp) +{ + int er; + struct nfsv3_pathconf *spp; + if (!(dp = parsestatus(dp, &er))) + return (0); + if (vflag) + printf(" POST:"); + if (!(dp = parse_post_op_attr(dp, vflag))) + return (0); + if (er) + return (1); + + spp = (struct nfsv3_pathconf *)dp; + TCHECK(*spp); + + printf(" linkmax %u namemax %u %s %s %s %s", + EXTRACT_32BITS(&spp->pc_linkmax), + EXTRACT_32BITS(&spp->pc_namemax), + EXTRACT_32BITS(&spp->pc_notrunc) ? "notrunc" : "", + EXTRACT_32BITS(&spp->pc_chownrestricted) ? "chownres" : "", + EXTRACT_32BITS(&spp->pc_caseinsensitive) ? "igncase" : "", + EXTRACT_32BITS(&spp->pc_casepreserving) ? "keepcase" : ""); return (1); trunc: return (0); } static void -interp_reply(const struct rpc_msg *rp, u_int32_t proc, u_int length) +interp_reply(const struct rpc_msg *rp, u_int32_t proc, u_int32_t vers, int length) { register const u_int32_t *dp; + register int v3; + int er; + + v3 = (vers == NFS_VER3); + + if (!v3 && proc < NFS_NPROCS) + proc = nfsv3_procid[proc]; switch (proc) { -#ifdef NFSPROC_NOOP case NFSPROC_NOOP: printf(" nop"); return; -#else -#define NFSPROC_NOOP -1 -#endif + case NFSPROC_NULL: printf(" null"); return; @@ -748,115 +1487,288 @@ interp_reply(const struct rpc_msg *rp, u_int32_t proc, u_int length) case NFSPROC_GETATTR: printf(" getattr"); dp = parserep(rp, length); - if (dp != NULL && parseattrstat(dp, !qflag) != 0) + if (dp != NULL && parseattrstat(dp, !qflag, v3) != 0) return; break; case NFSPROC_SETATTR: printf(" setattr"); - dp = parserep(rp, length); - if (dp != NULL && parseattrstat(dp, !qflag) != 0) + if (!(dp = parserep(rp, length))) return; + if (v3) { + if (parsewccres(dp, vflag)) + return; + } else { + if (parseattrstat(dp, !qflag, 0) != 0) + return; + } break; -#if NFSPROC_ROOT != NFSPROC_NOOP - case NFSPROC_ROOT: - printf(" root"); - break; -#endif case NFSPROC_LOOKUP: printf(" lookup"); - dp = parserep(rp, length); - if (dp != NULL && parsediropres(dp) != 0) - return; + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (!(dp = parsestatus(dp, &er))) + break; + if (er) { + if (vflag > 1) { + printf(" post dattr:"); + dp = parse_post_op_attr(dp, vflag); + } + } else { + if (!(dp = parsefh(dp, v3))) + break; + if ((dp = parse_post_op_attr(dp, vflag)) && + vflag > 1) { + printf(" post dattr:"); + dp = parse_post_op_attr(dp, vflag); + } + } + if (dp) + return; + } else { + if (parsediropres(dp) != 0) + return; + } break; + case NFSPROC_ACCESS: + printf(" access"); + if (!(dp = parserep(rp, length))) + break; + if (!(dp = parsestatus(dp, &er))) + break; + if (vflag) + printf(" attr:"); + if (!(dp = parse_post_op_attr(dp, vflag))) + break; + if (!er) + printf(" c %04x", EXTRACT_32BITS(&dp[0])); + return; + case NFSPROC_READLINK: printf(" readlink"); dp = parserep(rp, length); - if (dp != NULL && parselinkres(dp) != 0) + if (dp != NULL && parselinkres(dp, v3) != 0) return; break; case NFSPROC_READ: printf(" read"); - dp = parserep(rp, length); - if (dp != NULL && parseattrstat(dp, vflag) != 0) + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (!(dp = parsestatus(dp, &er))) + break; + if (!(dp = parse_post_op_attr(dp, vflag))) + break; + if (er) + return; + if (vflag) { + TCHECK(dp[1]); + printf(" %u bytes", EXTRACT_32BITS(&dp[0])); + if (EXTRACT_32BITS(&dp[1])) + printf(" EOF"); + } return; + } else { + if (parseattrstat(dp, vflag, 0) != 0) + return; + } break; -#if NFSPROC_WRITECACHE != NFSPROC_NOOP - case NFSPROC_WRITECACHE: - printf(" writecache"); - break; -#endif case NFSPROC_WRITE: printf(" write"); - dp = parserep(rp, length); - if (dp != NULL && parseattrstat(dp, vflag) != 0) - return; + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (!(dp = parsestatus(dp, &er))) + break; + if (!(dp = parse_wcc_data(dp, vflag))) + break; + if (er) + return; + if (vflag) { + TCHECK(dp[0]); + printf(" %u bytes", EXTRACT_32BITS(&dp[0])); + if (vflag > 1) { + TCHECK(dp[1]); + printf(" <%s>", + tok2str(nfsv3_writemodes, + NULL, EXTRACT_32BITS(&dp[1]))); + } + return; + } + } else { + if (parseattrstat(dp, vflag, v3) != 0) + return; + } break; case NFSPROC_CREATE: printf(" create"); - dp = parserep(rp, length); - if (dp != NULL && parsediropres(dp) != 0) + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (parsecreateopres(dp, vflag) != 0) + return; + } else { + if (parsediropres(dp) != 0) + return; + } + break; + + case NFSPROC_MKDIR: + printf(" mkdir"); + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (parsecreateopres(dp, vflag) != 0) + return; + } else { + if (parsediropres(dp) != 0) + return; + } + break; + + case NFSPROC_SYMLINK: + printf(" symlink"); + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (parsecreateopres(dp, vflag) != 0) + return; + } else { + if (parsestatus(dp, &er) != 0) + return; + } + break; + + case NFSPROC_MKNOD: + printf(" mknod"); + if (!(dp = parserep(rp, length))) + break; + if (parsecreateopres(dp, vflag) != 0) return; break; case NFSPROC_REMOVE: printf(" remove"); - dp = parserep(rp, length); - if (dp != NULL && parsestatus(dp) != 0) - return; + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (parsewccres(dp, vflag)) + return; + } else { + if (parsestatus(dp, &er) != 0) + return; + } + break; + + case NFSPROC_RMDIR: + printf(" rmdir"); + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (parsewccres(dp, vflag)) + return; + } else { + if (parsestatus(dp, &er) != 0) + return; + } break; case NFSPROC_RENAME: printf(" rename"); - dp = parserep(rp, length); - if (dp != NULL && parsestatus(dp) != 0) + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (!(dp = parsestatus(dp, &er))) + break; + if (vflag) { + printf(" from:"); + if (!(dp = parse_wcc_data(dp, vflag))) + break; + printf(" to:"); + if (!(dp = parse_wcc_data(dp, vflag))) + break; + } return; + } else { + if (parsestatus(dp, &er) != 0) + return; + } break; case NFSPROC_LINK: printf(" link"); - dp = parserep(rp, length); - if (dp != NULL && parsestatus(dp) != 0) - return; + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (!(dp = parsestatus(dp, &er))) + break; + if (vflag) { + printf(" file POST:"); + if (!(dp = parse_post_op_attr(dp, vflag))) + break; + printf(" dir:"); + if (!(dp = parse_wcc_data(dp, vflag))) + break; + return; + } + } else { + if (parsestatus(dp, &er) != 0) + return; + } break; - case NFSPROC_SYMLINK: - printf(" symlink"); - dp = parserep(rp, length); - if (dp != NULL && parsestatus(dp) != 0) + case NFSPROC_READDIR: + printf(" readdir"); + if (!(dp = parserep(rp, length))) + break; + if (v3) { + if (parsev3rddirres(dp, vflag)) + return; + } else { + if (parserddires(dp) != 0) + return; + } + break; + + case NFSPROC_READDIRPLUS: + printf(" readdirplus"); + if (!(dp = parserep(rp, length))) + break; + if (parsev3rddirres(dp, vflag)) return; break; - case NFSPROC_MKDIR: - printf(" mkdir"); + case NFSPROC_FSSTAT: + printf(" fsstat"); dp = parserep(rp, length); - if (dp != NULL && parsediropres(dp) != 0) + if (dp != NULL && parsestatfs(dp, v3) != 0) return; break; - case NFSPROC_RMDIR: - printf(" rmdir"); + case NFSPROC_FSINFO: + printf(" fsinfo"); dp = parserep(rp, length); - if (dp != NULL && parsestatus(dp) != 0) + if (dp != NULL && parsefsinfo(dp) != 0) return; break; - case NFSPROC_READDIR: - printf(" readdir"); + case NFSPROC_PATHCONF: + printf(" pathconf"); dp = parserep(rp, length); - if (dp != NULL && parserddires(dp) != 0) + if (dp != NULL && parsepathconf(dp) != 0) return; break; - case NFSPROC_STATFS: - printf(" statfs"); + case NFSPROC_COMMIT: + printf(" commit"); dp = parserep(rp, length); - if (dp != NULL && parsestatfs(dp) != 0) + if (dp != NULL && parsewccres(dp, vflag) != 0) return; break; @@ -864,6 +1776,7 @@ interp_reply(const struct rpc_msg *rp, u_int32_t proc, u_int length) printf(" proc-%u", proc); return; } +trunc: if (!nfserr) fputs(" [|nfs]", stdout); } diff --git a/kame/kame/tcpdump/print-ntp.c b/kame/kame/tcpdump/print-ntp.c index dc14ba1c44..d1560089b5 100644 --- a/kame/kame/tcpdump/print-ntp.c +++ b/kame/kame/tcpdump/print-ntp.c @@ -24,29 +24,25 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-ntp.c,v 1.26 97/06/13 12:56:37 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-ntp.c,v 1.37.2.2 2003/11/16 08:51:36 guy Exp $ (LBL)"; #endif -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include -#include -#include +#include -#include #include #include +#ifdef HAVE_STRFTIME +#include +#endif #include "interface.h" #include "addrtoname.h" +#include "extract.h" #ifdef MODEMASK #undef MODEMASK /* Solaris sucks */ #endif @@ -64,7 +60,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 */ @@ -74,7 +69,7 @@ ntp_print(register const u_char *cp, u_int length) TCHECK(bp->status); version = (int)(bp->status & VERSIONMASK) >> 3; - printf(" v%d", version); + printf("NTPv%d", version); leapind = bp->status & LEAPMASK; switch (leapind) { @@ -129,14 +124,14 @@ ntp_print(register const u_char *cp, u_int length) } TCHECK(bp->stratum); - printf(" strat %d", bp->stratum); + printf(", strat %d", bp->stratum); TCHECK(bp->ppoll); - printf(" poll %d", bp->ppoll); + printf(", poll %d", bp->ppoll); /* Can't TCHECK bp->precision bitfield so bp->distance + 0 instead */ TCHECK2(bp->distance, 0); - printf(" prec %d", bp->precision); + printf(", prec %d", bp->precision); if (!vflag) return; @@ -146,11 +141,11 @@ ntp_print(register const u_char *cp, u_int length) p_sfix(&bp->distance); TCHECK(bp->dispersion); - fputs(" disp ", stdout); + fputs(", disp ", stdout); p_sfix(&bp->dispersion); TCHECK(bp->refid); - fputs(" ref ", stdout); + fputs(", ref ", stdout); /* Interpretation depends on stratum */ switch (bp->stratum) { @@ -159,9 +154,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((u_char *)&(bp->refid), 4, NULL); break; case INFO_QUERY: @@ -208,8 +201,8 @@ p_sfix(register const struct s_fixedpt *sfp) register int f; register float ff; - i = ntohs(sfp->int_part); - f = ntohs(sfp->fraction); + i = EXTRACT_16BITS(&sfp->int_part); + f = EXTRACT_16BITS(&sfp->fraction); ff = f / 65536.0; /* shift radix point by 16 bits */ f = ff * 1000000.0; /* Treat fraction as parts per million */ printf("%d.%06d", i, f); @@ -225,14 +218,29 @@ p_ntp_time(register const struct l_fixedpt *lfp) register u_int32_t f; register float ff; - i = ntohl(lfp->int_part); - uf = ntohl(lfp->fraction); + i = EXTRACT_32BITS(&lfp->int_part); + uf = EXTRACT_32BITS(&lfp->fraction); ff = uf; if (ff < 0.0) /* some compilers are buggy */ ff += FMAXINT; ff = ff / FMAXINT; /* shift radix point by 32 bits */ f = ff * 1000000000.0; /* treat fraction as parts per billion */ printf("%u.%09d", i, f); + +#ifdef HAVE_STRFTIME + /* + * For extra verbosity, print the time in human-readable format. + */ + if (vflag > 1 && i) { + time_t seconds = i - JAN_1970; + struct tm *tm; + char time_buf[128]; + + tm = localtime(&seconds); + strftime(time_buf, sizeof (time_buf), "%Y/%m/%d %H:%M:%S", tm); + printf (" (%s)", time_buf); + } +#endif } /* Prints time difference between *lfp and *olfp */ @@ -241,16 +249,22 @@ p_ntp_delta(register const struct l_fixedpt *olfp, register const struct l_fixedpt *lfp) { register int32_t i; - register u_int32_t uf; - register u_int32_t ouf; + register u_int32_t u, uf; + register u_int32_t ou, ouf; register u_int32_t f; register float ff; int signbit; - i = ntohl(lfp->int_part) - ntohl(olfp->int_part); + u = EXTRACT_32BITS(&lfp->int_part); + ou = EXTRACT_32BITS(&olfp->int_part); + uf = EXTRACT_32BITS(&lfp->fraction); + ouf = EXTRACT_32BITS(&olfp->fraction); + if (ou == 0 && ouf == 0) { + p_ntp_time(lfp); + return; + } - uf = ntohl(lfp->fraction); - ouf = ntohl(olfp->fraction); + i = u - ou; if (i > 0) { /* new is definitely greater than old */ signbit = 0; @@ -284,3 +298,4 @@ p_ntp_delta(register const struct l_fixedpt *olfp, putchar('+'); printf("%d.%09d", i, f); } + diff --git a/kame/kame/tcpdump/print-null.c b/kame/kame/tcpdump/print-null.c index ba97cf4d7a..c34693103d 100644 --- a/kame/kame/tcpdump/print-null.c +++ b/kame/kame/tcpdump/print-null.c @@ -20,120 +20,180 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-null.c,v 1.24 97/05/28 12:52:47 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-null.c,v 1.49.2.2 2003/11/16 08:51:36 guy Exp $ (LBL)"; #endif -#include -#include -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include #include -#ifdef INET6 -#include -#endif - #include "interface.h" #include "addrtoname.h" -#ifndef AF_NS -#define AF_NS 6 /* XEROX NS protocols */ +#include "ip.h" +#ifdef INET6 +#include "ip6.h" #endif /* - * The DLT_NULL packet header is 4 bytes long. It contains a network - * order 32 bit integer that specifies the family, e.g. AF_INET + * The DLT_NULL packet header is 4 bytes long. It contains a host-byte-order + * 32-bit integer that specifies the family, e.g. AF_INET. + * + * Note here that "host" refers to the host on which the packets were + * captured; that isn't necessarily *this* host. + * + * The OpenBSD DLT_LOOP packet header is the same, except that the integer + * is in network byte order. */ #define NULL_HDRLEN 4 +/* + * BSD AF_ values. + * + * Unfortunately, the BSDs don't all use the same value for AF_INET6, + * so, because we want to be able to read captures from all of the BSDs, + * we check for all of them. + */ +#define BSD_AF_INET 2 +#define BSD_AF_NS 6 /* XEROX NS protocols */ +#define BSD_AF_ISO 7 +#define BSD_AF_APPLETALK 16 +#define BSD_AF_IPX 23 +#define BSD_AF_INET6_BSD 24 /* OpenBSD (and probably NetBSD), BSD/OS */ +#define BSD_AF_INET6_FREEBSD 28 +#define BSD_AF_INET6_DARWIN 30 + static void -null_print(const u_char *p, const struct ip *ip, u_int length) +null_print(u_int family, u_int length) { - u_int family; + if (nflag) + printf("AF %u ", family); + else { + switch (family) { - memcpy((char *)&family, (char *)p, sizeof(family)); - - if (nflag) { - /* XXX just dump the header */ - return; - } - switch (family) { - - case AF_INET: - printf("ip: "); - break; + case BSD_AF_INET: + printf("ip "); + break; #ifdef INET6 - case AF_INET6: - printf("ip6: "); - break; + case BSD_AF_INET6_BSD: + case BSD_AF_INET6_FREEBSD: + case BSD_AF_INET6_DARWIN: + printf("ip6 "); + break; #endif - case AF_NS: - printf("ns: "); - break; + case BSD_AF_NS: + printf("ns "); + break; - default: - printf("AF %d: ", family); - break; + case BSD_AF_ISO: + printf("osi "); + break; + + case BSD_AF_APPLETALK: + printf("atalk "); + break; + + case BSD_AF_IPX: + printf("ipx "); + break; + + default: + printf("AF %u ", family); + break; + } } + printf("%d: ", length); } -void -null_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) +/* + * Byte-swap a 32-bit number. + * ("htonl()" or "ntohl()" won't work - we want to byte-swap even on + * big-endian platforms.) + */ +#define SWAPLONG(y) \ +((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff)) + +/* + * This is the top level routine of the printer. 'p' points + * to the ether header of the packet, 'h->ts' is the timestamp, + * 'h->length' is the length of the packet off the wire, and 'h->caplen' + * is the number of bytes actually captured. + */ +u_int +null_if_print(const struct pcap_pkthdr *h, const u_char *p) { u_int length = h->len; u_int caplen = h->caplen; - const struct ip *ip; + u_int family; - ts_print(&h->ts); + if (caplen < NULL_HDRLEN) { + printf("[|null]"); + return (NULL_HDRLEN); + } + + memcpy((char *)&family, (char *)p, sizeof(family)); /* - * 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. + * This isn't necessarily in our host byte order; if this is + * a DLT_LOOP capture, it's in network byte order, and if + * this is a DLT_NULL capture from a machine with the opposite + * byte-order, it's in the opposite byte order from ours. + * + * If the upper 16 bits aren't all zero, assume it's byte-swapped. */ - packetp = p; - snapend = p + caplen; + if ((family & 0xFFFF0000) != 0) + family = SWAPLONG(family); length -= NULL_HDRLEN; - - ip = (struct ip *)(p + NULL_HDRLEN); + caplen -= NULL_HDRLEN; + p += NULL_HDRLEN; if (eflag) - null_print(p, ip, length); - -#ifndef INET6 - ip_print((const u_char *)ip, length); -#else - if (ip->ip_v == IPVERSION) - ip_print((const u_char *)ip, length); - else if (ip->ip_v == 6) - ip6_print((const u_char *)ip, length); -#endif /*INET6*/ - - if (xflag) - default_print((const u_char *)ip, caplen - NULL_HDRLEN); - putchar('\n'); + null_print(family, length); + + switch (family) { + + case BSD_AF_INET: + ip_print(p, length); + break; + +#ifdef INET6 + case BSD_AF_INET6_BSD: + case BSD_AF_INET6_FREEBSD: + case BSD_AF_INET6_DARWIN: + ip6_print(p, length); + break; +#endif + + case BSD_AF_ISO: + isoclns_print(p, length, caplen); + break; + + case BSD_AF_APPLETALK: + atalk_print(p, length); + break; + + case BSD_AF_IPX: + ipx_print(p, length); + break; + + default: + /* unknown AF_ value */ + if (!eflag) + null_print(family, length + NULL_HDRLEN); + if (!xflag && !qflag) + default_print(p, caplen); + } + + return (NULL_HDRLEN); } diff --git a/kame/kame/tcpdump/print-ospf.c b/kame/kame/tcpdump/print-ospf.c index bf1595d459..d239cafd1e 100644 --- a/kame/kame/tcpdump/print-ospf.c +++ b/kame/kame/tcpdump/print-ospf.c @@ -22,242 +22,271 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-ospf.c,v 1.24 97/04/26 13:31:46 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-ospf.c,v 1.45.2.4 2004/03/24 02:44:30 guy Exp $ (LBL)"; #endif -#include -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include -#include -#include -#include +#include -#include #include #include "interface.h" #include "addrtoname.h" +#include "extract.h" +#include "gmpls.h" #include "ospf.h" -struct bits { - u_int32_t bit; - const char *str; +#include "ip.h" + +static struct tok ospf_option_values[] = { + { OSPF_OPTION_T, "TOS" }, + { OSPF_OPTION_E, "External" }, + { OSPF_OPTION_MC, "Multicast" }, + { OSPF_OPTION_NP, "NSSA" }, + { OSPF_OPTION_EA, "Advertise External" }, + { OSPF_OPTION_DC, "Demand Circuit" }, + { OSPF_OPTION_O, "Opaque" }, + { 0, NULL } }; -static const struct bits ospf_option_bits[] = { - { OSPF_OPTION_T, "T" }, - { OSPF_OPTION_E, "E" }, - { OSPF_OPTION_MC, "MC" }, +static struct tok ospf_authtype_values[] = { + { OSPF_AUTH_NONE, "none" }, + { OSPF_AUTH_NONE, "simple" }, + { OSPF_AUTH_MD5, "MD5" }, { 0, NULL } }; -static const struct bits ospf_rla_flag_bits[] = { - { RLA_FLAG_B, "B" }, - { RLA_FLAG_E, "E" }, - { RLA_FLAG_W1, "W1" }, +static struct tok ospf_rla_flag_values[] = { + { RLA_FLAG_B, "ABR" }, + { RLA_FLAG_E, "ASBR" }, + { RLA_FLAG_W1, "Virtual" }, { RLA_FLAG_W2, "W2" }, { 0, NULL } }; static struct tok type2str[] = { - { OSPF_TYPE_UMD, "umd" }, - { OSPF_TYPE_HELLO, "hello" }, - { OSPF_TYPE_DB, "dd" }, - { OSPF_TYPE_LSR, "ls_req" }, - { OSPF_TYPE_LSU, "ls_upd" }, - { OSPF_TYPE_LSA, "ls_ack" }, + { OSPF_TYPE_UMD, "UMD" }, + { OSPF_TYPE_HELLO, "Hello" }, + { OSPF_TYPE_DD, "Database Description" }, + { OSPF_TYPE_LS_REQ, "LS-Request" }, + { OSPF_TYPE_LS_UPDATE, "LS-Update" }, + { OSPF_TYPE_LS_ACK, "LS-Ack" }, { 0, NULL } }; -static char tstr[] = " [|ospf]"; - -/* Forwards */ -static inline void ospf_print_seqage(u_int32_t, time_t); -static inline void ospf_print_bits(const struct bits *, u_char); -static void ospf_print_ls_type(u_int, const struct in_addr *, - const struct in_addr *, const char *); -static int ospf_print_lshdr(const struct lsa_hdr *); -static int ospf_print_lsa(const struct lsa *); -static int ospf_decode_v2(const struct ospfhdr *, const u_char *); - -static inline void -ospf_print_seqage(register u_int32_t seq, register time_t us) -{ - register time_t sec = us % 60; - register time_t mins = (us / 60) % 60; - register time_t hour = us / 3600; - - printf(" S %X age ", seq); - if (hour) - printf("%u:%02u:%02u", - (u_int32_t) hour, (u_int32_t) mins, (u_int32_t) sec); - else if (mins) - printf("%u:%02u", (u_int32_t) mins, (u_int32_t) sec); - else - printf("%u", (u_int32_t) sec); -} - - -static inline void -ospf_print_bits(register const struct bits *bp, register u_char options) -{ - register char sep = ' '; - - do { - if (options & bp->bit) { - printf("%c%s", sep, bp->str); - sep = '/'; - } - } while ((++bp)->bit); -} +static struct tok lsa_values[] = { + { LS_TYPE_ROUTER, "Router" }, + { LS_TYPE_NETWORK, "Network" }, + { LS_TYPE_SUM_IP, "Summary" }, + { LS_TYPE_SUM_ABR, "ASBR Summary" }, + { LS_TYPE_ASE, "External" }, + { LS_TYPE_GROUP, "Multicast Group" }, + { LS_TYPE_NSSA, "NSSA" }, + { LS_TYPE_OPAQUE_LL, "Link Local Opaque" }, + { LS_TYPE_OPAQUE_AL, "Area Local Opaque" }, + { LS_TYPE_OPAQUE_DW, "Domain Wide Opaque" }, + { 0, NULL } +}; -static void -ospf_print_ls_type(register u_int ls_type, - register const struct in_addr *ls_stateid, - register const struct in_addr *ls_router, register const char *fmt) -{ +static struct tok ospf_dd_flag_values[] = { + { OSPF_DB_INIT, "Init" }, + { OSPF_DB_MORE, "More" }, + { OSPF_DB_MASTER, "Master" }, + { 0, NULL } +}; - switch (ls_type) { +static struct tok lsa_opaque_values[] = { + { LS_OPAQUE_TYPE_TE, "Traffic Engineering" }, + { LS_OPAQUE_TYPE_GRACE, "Graceful restart" }, + { 0, NULL } +}; - case LS_TYPE_ROUTER: - printf(" rtr %s ", ipaddr_string(ls_router)); - break; +static struct tok lsa_opaque_te_tlv_values[] = { + { LS_OPAQUE_TE_TLV_ROUTER, "Router Address" }, + { LS_OPAQUE_TE_TLV_LINK, "Link" }, + { 0, NULL } +}; - case LS_TYPE_NETWORK: - printf(" net dr %s if %s", - ipaddr_string(ls_router), - ipaddr_string(ls_stateid)); - break; +static struct tok lsa_opaque_te_link_tlv_subtlv_values[] = { + { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE, "Link Type" }, + { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID, "Link ID" }, + { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP, "Local Interface IP address" }, + { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP, "Remote Interface IP address" }, + { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC, "Traffic Engineering Metric" }, + { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW, "Maximum Bandwidth" }, + { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW, "Maximum Reservable Bandwidth" }, + { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW, "Unreserved Bandwidth" }, + { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP, "Administrative Group" }, + { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID, "Link Local/Remote Identifier" }, + { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE, "Link Protection Type" }, + { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR, "Interface Switching Capability" }, + { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP, "Shared Risk Link Group" }, + { 0, NULL } +}; - case LS_TYPE_SUM_IP: - printf(" sum %s abr %s", - ipaddr_string(ls_stateid), - ipaddr_string(ls_router)); - break; +#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP 1 /* rfc3630 */ +#define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA 2 /* rfc3630 */ - case LS_TYPE_SUM_ABR: - printf(" abr %s rtr %s", - ipaddr_string(ls_router), - ipaddr_string(ls_stateid)); - break; +static struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values[] = { + { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP, "Point-to-point" }, + { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA, "Multi-Access" }, + { 0, NULL } +}; - case LS_TYPE_ASE: - printf(" ase %s asbr %s", - ipaddr_string(ls_stateid), - ipaddr_string(ls_router)); - break; +static char tstr[] = " [|ospf]"; - case LS_TYPE_GROUP: - printf(" group %s rtr %s", - ipaddr_string(ls_stateid), - ipaddr_string(ls_router)); - break; +#ifdef WIN32 +#define inline __inline +#endif /* WIN32 */ - default: - putchar(' '); - printf(fmt, ls_type); - break; - } -} +static int ospf_print_lshdr(const struct lsa_hdr *); +static const u_char *ospf_print_lsa(const struct lsa *); +static int ospf_decode_v2(const struct ospfhdr *, const u_char *); static int ospf_print_lshdr(register const struct lsa_hdr *lshp) { + u_int ls_length; + + TCHECK(lshp->ls_length); + ls_length = EXTRACT_16BITS(&lshp->ls_length); + if (ls_length < sizeof(struct lsa_hdr)) { + printf("\n\t Bogus length %u < %lu", ls_length, + (unsigned long)sizeof(struct lsa_hdr)); + return(-1); + } - TCHECK(lshp->ls_type); - printf(" {"); /* } (ctags) */ + TCHECK(lshp->ls_seq); /* XXX - ls_length check checked this */ + printf("\n\t Advertising Router: %s, seq 0x%08x, age %us, length: %u", + ipaddr_string(&lshp->ls_router), + EXTRACT_32BITS(&lshp->ls_seq), + EXTRACT_16BITS(&lshp->ls_age), + ls_length-(u_int)sizeof(struct lsa_hdr)); + + TCHECK(lshp->ls_type); /* XXX - ls_length check checked this */ + switch (lshp->ls_type) { + /* the LSA header for opaque LSAs was slightly changed */ + case LS_TYPE_OPAQUE_LL: + case LS_TYPE_OPAQUE_AL: + case LS_TYPE_OPAQUE_DW: + printf("\n\t %s LSA (%d), Opaque-Type: %s LSA (%u), Opaque-ID: %u", + tok2str(lsa_values,"unknown",lshp->ls_type), + lshp->ls_type, + + tok2str(lsa_opaque_values, + "unknown", + *(&lshp->un_lsa_id.opaque_field.opaque_type)), + *(&lshp->un_lsa_id.opaque_field.opaque_type), + EXTRACT_24BITS(&lshp->un_lsa_id.opaque_field.opaque_id) + + ); + break; + + /* all other LSA types use regular style LSA headers */ + default: + printf("\n\t %s LSA (%d), LSA-ID: %s", + tok2str(lsa_values,"unknown",lshp->ls_type), + lshp->ls_type, + ipaddr_string(&lshp->un_lsa_id.lsa_id)); + break; + } - TCHECK(lshp->ls_options); - ospf_print_bits(ospf_option_bits, lshp->ls_options); - TCHECK(lshp->ls_seq); - ospf_print_seqage(ntohl(lshp->ls_seq), ntohs(lshp->ls_age)); - ospf_print_ls_type(lshp->ls_type, &lshp->ls_stateid, &lshp->ls_router, - "ls_type %d"); + TCHECK(lshp->ls_options); /* XXX - ls_length check checked this */ + printf("\n\t Options: [%s]", bittok2str(ospf_option_values,"none",lshp->ls_options)); - return (0); + return (ls_length); trunc: - return (1); + return (-1); } - /* - * Print a single link state advertisement. If truncated return 1, else 0. + * Print a single link state advertisement. If truncated or if LSA length + * field is less than the length of the LSA header, return NULl, else + * return pointer to data past end of LSA. */ -static int +static const u_int8_t * ospf_print_lsa(register const struct lsa *lsap) { - register const u_char *ls_end; + register const u_int8_t *ls_end; register const struct rlalink *rlp; register const struct tos_metric *tosp; register const struct in_addr *ap; register const struct aslametric *almp; register const struct mcla *mcp; register const u_int32_t *lp; - register int j, k; + register int j, k, tlv_type, tlv_length, subtlv_type, subtlv_length, priority_level; + register int ls_length; + const u_int8_t *tptr; + int count_srlg; + union { /* int to float conversion buffer for several subTLVs */ + float f; + u_int32_t i; + } bw; + + tptr = (u_int8_t *)lsap->lsa_un.un_unknown; /* squelch compiler warnings */ + ls_length = ospf_print_lshdr(&lsap->ls_hdr); + if (ls_length == -1) + return(NULL); + ls_end = (u_int8_t *)lsap + ls_length; + ls_length -= sizeof(struct lsa_hdr); - if (ospf_print_lshdr(&lsap->ls_hdr)) - return (1); - TCHECK(lsap->ls_hdr.ls_length); - ls_end = (u_char *)lsap + ntohs(lsap->ls_hdr.ls_length); switch (lsap->ls_hdr.ls_type) { case LS_TYPE_ROUTER: TCHECK(lsap->lsa_un.un_rla.rla_flags); - ospf_print_bits(ospf_rla_flag_bits, - lsap->lsa_un.un_rla.rla_flags); + printf("\n\t Router LSA Options: [%s]", bittok2str(ospf_rla_flag_values,"none",lsap->lsa_un.un_rla.rla_flags)); TCHECK(lsap->lsa_un.un_rla.rla_count); - j = ntohs(lsap->lsa_un.un_rla.rla_count); + j = EXTRACT_16BITS(&lsap->lsa_un.un_rla.rla_count); TCHECK(lsap->lsa_un.un_rla.rla_link); rlp = lsap->lsa_un.un_rla.rla_link; while (j--) { TCHECK(*rlp); - printf(" {"); /* } (ctags) */ switch (rlp->link_type) { case RLA_TYPE_VIRTUAL: - printf(" virt"); - /* Fall through */ + printf("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s", + ipaddr_string(&rlp->link_id), + ipaddr_string(&rlp->link_data)); + break; case RLA_TYPE_ROUTER: - printf(" nbrid %s if %s", + printf("\n\t Neighbor Router-ID: %s, Interface Address: %s", ipaddr_string(&rlp->link_id), ipaddr_string(&rlp->link_data)); break; case RLA_TYPE_TRANSIT: - printf(" dr %s if %s", + printf("\n\t Neighbor Network-ID: %s, Interface Address: %s", ipaddr_string(&rlp->link_id), ipaddr_string(&rlp->link_data)); break; case RLA_TYPE_STUB: - printf(" net %s mask %s", + printf("\n\t Stub Network: %s, Mask: %s", ipaddr_string(&rlp->link_id), ipaddr_string(&rlp->link_data)); break; default: - /* { (ctags) */ - printf(" ??RouterLinksType %d?? }", + printf("\n\t Unknown Router Link Type (%u)", rlp->link_type); - return (0); + return (ls_end); } - printf(" tos 0 metric %d", ntohs(rlp->link_tos0metric)); + printf(", tos 0, metric: %d", EXTRACT_16BITS(&rlp->link_tos0metric)); tosp = (struct tos_metric *) ((sizeof rlp->link_tos0metric) + (u_char *) rlp); for (k = 0; k < (int) rlp->link_toscount; ++k, ++tosp) { TCHECK(*tosp); - printf(" tos %d metric %d", + printf(", tos %d, metric: %d", tosp->tos_type, - ntohs(tosp->tos_metric)); + EXTRACT_16BITS(&tosp->tos_metric)); } - /* { (ctags) */ - printf(" }"); rlp = (struct rlalink *)((u_char *)(rlp + 1) + ((rlp->link_toscount) * sizeof(*tosp))); } @@ -265,31 +294,53 @@ ospf_print_lsa(register const struct lsa *lsap) case LS_TYPE_NETWORK: TCHECK(lsap->lsa_un.un_nla.nla_mask); - printf(" mask %s rtrs", + printf("\n\t Mask %s\n\t Connected Routers:", ipaddr_string(&lsap->lsa_un.un_nla.nla_mask)); ap = lsap->lsa_un.un_nla.nla_router; while ((u_char *)ap < ls_end) { TCHECK(*ap); - printf(" %s", ipaddr_string(ap)); + printf("\n\t %s", ipaddr_string(ap)); ++ap; } break; case LS_TYPE_SUM_IP: TCHECK(lsap->lsa_un.un_nla.nla_mask); - printf(" mask %s", + printf("\n\t Mask %s", ipaddr_string(&lsap->lsa_un.un_sla.sla_mask)); - /* Fall through */ + TCHECK(lsap->lsa_un.un_sla.sla_tosmetric); + lp = lsap->lsa_un.un_sla.sla_tosmetric; + /* suppress tos if its not supported */ + if(!((lsap->ls_hdr.ls_options)&OSPF_OPTION_T)) { + printf(", metric: %u", EXTRACT_32BITS(lp)&SLA_MASK_METRIC); + break; + } + while ((u_char *)lp < ls_end) { + register u_int32_t ul; + + TCHECK(*lp); + ul = EXTRACT_32BITS(lp); + printf(", tos %d metric %d", + (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS, + ul & SLA_MASK_METRIC); + ++lp; + } + break; case LS_TYPE_SUM_ABR: TCHECK(lsap->lsa_un.un_sla.sla_tosmetric); lp = lsap->lsa_un.un_sla.sla_tosmetric; + /* suppress tos if its not supported */ + if(!((lsap->ls_hdr.ls_options)&OSPF_OPTION_T)) { + printf(", metric: %u", EXTRACT_32BITS(lp)&SLA_MASK_METRIC); + break; + } while ((u_char *)lp < ls_end) { register u_int32_t ul; TCHECK(*lp); - ul = ntohl(*lp); - printf(" tos %d metric %d", + ul = EXTRACT_32BITS(lp); + printf(", tos %d metric %d", (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS, ul & SLA_MASK_METRIC); ++lp; @@ -298,7 +349,7 @@ ospf_print_lsa(register const struct lsa *lsap) case LS_TYPE_ASE: TCHECK(lsap->lsa_un.un_nla.nla_mask); - printf(" mask %s", + printf("\n\t Mask %s", ipaddr_string(&lsap->lsa_un.un_asla.asla_mask)); TCHECK(lsap->lsa_un.un_sla.sla_tosmetric); @@ -307,19 +358,23 @@ ospf_print_lsa(register const struct lsa *lsap) register u_int32_t ul; TCHECK(almp->asla_tosmetric); - ul = ntohl(almp->asla_tosmetric); - printf(" type %d tos %d metric %d", + ul = EXTRACT_32BITS(&almp->asla_tosmetric); + printf(", type %d, tos %d metric:", (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1, - (ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS, - (ul & ASLA_MASK_METRIC)); + (ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS); + if ((ul & ASLA_MASK_METRIC)==0xffffff) + printf(" infinite"); + else + printf(" %d", (ul & ASLA_MASK_METRIC)); + TCHECK(almp->asla_forward); if (almp->asla_forward.s_addr) { - printf(" forward %s", + printf(", forward %s", ipaddr_string(&almp->asla_forward)); } TCHECK(almp->asla_tag); if (almp->asla_tag.s_addr) { - printf(" tag %s", + printf(", tag %s", ipaddr_string(&almp->asla_tag)); } ++almp; @@ -331,33 +386,205 @@ ospf_print_lsa(register const struct lsa *lsap) mcp = lsap->lsa_un.un_mcla; while ((u_char *)mcp < ls_end) { TCHECK(mcp->mcla_vid); - switch (ntohl(mcp->mcla_vtype)) { + switch (EXTRACT_32BITS(&mcp->mcla_vtype)) { case MCLA_VERTEX_ROUTER: - printf(" rtr rtrid %s", + printf("\n\t Router Router-ID %s", ipaddr_string(&mcp->mcla_vid)); break; case MCLA_VERTEX_NETWORK: - printf(" net dr %s", + printf("\n\t Network Designated Router %s", ipaddr_string(&mcp->mcla_vid)); break; default: - printf(" ??VertexType %u??", - (u_int32_t)ntohl(mcp->mcla_vtype)); + printf("\n\t unknown VertexType (%u)", + EXTRACT_32BITS(&mcp->mcla_vtype)); break; } ++mcp; } - } + break; - /* { (ctags) */ - fputs(" }", stdout); - return (0); + case LS_TYPE_OPAQUE_LL: /* fall through */ + case LS_TYPE_OPAQUE_AL: + case LS_TYPE_OPAQUE_DW: + + switch (*(&lsap->ls_hdr.un_lsa_id.opaque_field.opaque_type)) { + case LS_OPAQUE_TYPE_TE: + tptr = (u_int8_t *)(&lsap->lsa_un.un_te_lsa_tlv.type); + + while (ls_length != 0) { + TCHECK2(*tptr, 4); + if (ls_length < 4) { + printf("\n\t Remaining LS length %u < 4", ls_length); + return(ls_end); + } + tlv_type = EXTRACT_16BITS(tptr); + tlv_length = EXTRACT_16BITS(tptr+2); + tptr+=4; + ls_length-=4; + + printf("\n\t %s TLV (%u), length: %u", + tok2str(lsa_opaque_te_tlv_values,"unknown",tlv_type), + tlv_type, + tlv_length); + + if (tlv_length > ls_length) { + printf("\n\t Bogus length %u > %u", tlv_length, + ls_length); + return(ls_end); + } + ls_length-=tlv_length; + switch(tlv_type) { + case LS_OPAQUE_TE_TLV_LINK: + while (tlv_length != 0) { + if (tlv_length < 4) { + printf("\n\t Remaining TLV length %u < 4", + tlv_length); + return(ls_end); + } + TCHECK2(*tptr, 4); + subtlv_type = EXTRACT_16BITS(tptr); + subtlv_length = EXTRACT_16BITS(tptr+2); + tptr+=4; + tlv_length-=4; + + printf("\n\t %s subTLV (%u), length: %u", + tok2str(lsa_opaque_te_link_tlv_subtlv_values,"unknown",subtlv_type), + subtlv_type, + subtlv_length); + + TCHECK2(*tptr, subtlv_length); + switch(subtlv_type) { + case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP: + printf(", 0x%08x", EXTRACT_32BITS(tptr)); + break; + case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID: + case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID: + printf(", %s (0x%08x)", + ipaddr_string(tptr), + EXTRACT_32BITS(tptr)); + if (subtlv_length == 8) /* draft-ietf-ccamp-ospf-gmpls-extensions */ + printf(", %s (0x%08x)", + ipaddr_string(tptr+4), + EXTRACT_32BITS(tptr+4)); + break; + case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP: + case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP: + printf(", %s", ipaddr_string(tptr)); + break; + case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW: + case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW: + bw.i = EXTRACT_32BITS(tptr); + printf(", %.3f Mbps", bw.f*8/1000000 ); + break; + case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW: + for (priority_level = 0; priority_level < 8; priority_level++) { + bw.i = EXTRACT_32BITS(tptr+priority_level*4); + printf("\n\t\tpriority level %d: %.3f Mbps", + priority_level, + bw.f*8/1000000 ); + } + break; + case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC: + printf(", Metric %u", EXTRACT_32BITS(tptr)); + break; + case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE: + printf(", %s, Priority %u", + bittok2str(gmpls_link_prot_values, "none", *tptr), + *(tptr+1)); + break; + case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR: + printf("\n\t\tInterface Switching Capability: %s", + tok2str(gmpls_switch_cap_values, "Unknown", *(tptr))); + printf("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:", + tok2str(gmpls_encoding_values, "Unknown", *(tptr+1))); + for (priority_level = 0; priority_level < 8; priority_level++) { + bw.i = EXTRACT_32BITS(tptr+4+(priority_level*4)); + printf("\n\t\t priority level %d: %.3f Mbps", + priority_level, + bw.f*8/1000000 ); + } + break; + case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE: + printf(", %s (%u)", + tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values,"unknown",*tptr), + *tptr); + break; + + case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP: + count_srlg = subtlv_length / 4; + if (count_srlg != 0) + printf("\n\t\t Shared risk group: "); + while (count_srlg > 0) { + bw.i = EXTRACT_32BITS(tptr); + printf("%d",bw.i); + tptr+=4; + count_srlg--; + if (count_srlg > 0) + printf(", "); + } + break; + + default: + if (vflag <= 1) { + if(!print_unknown_data(tptr,"\n\t\t",subtlv_length)) + return(ls_end); + } + break; + } + /* in OSPF everything has to be 32-bit aligned, including TLVs */ + if (subtlv_length%4 != 0) + subtlv_length+=4-(subtlv_length%4); + + tlv_length-=subtlv_length; + tptr+=subtlv_length; + + } + break; + + case LS_OPAQUE_TE_TLV_ROUTER: + if (tlv_length < 4) { + printf("\n\t TLV length %u < 4", tlv_length); + return(ls_end); + } + TCHECK2(*tptr, 4); + printf(", %s", ipaddr_string(tptr)); + break; + + default: + if (vflag <= 1) { + if(!print_unknown_data(tptr,"\n\t ",tlv_length)) + return(ls_end); + } + break; + } + tptr+=tlv_length; + } + break; + } + break; + default: + if (vflag <= 1) { + if(!print_unknown_data((u_int8_t *)lsap->lsa_un.un_unknown, + "\n\t ", ls_length)) + return(ls_end); + } + break; + } + + /* do we want to see an additionally hexdump ? */ + if (vflag> 1) + if(!print_unknown_data((u_int8_t *)lsap->lsa_un.un_unknown, + "\n\t ", ls_length)) { + return(ls_end); + } + + return (ls_end); trunc: - fputs(" }", stdout); - return (1); + return (NULL); } static int @@ -368,8 +595,7 @@ ospf_decode_v2(register const struct ospfhdr *op, register const struct lsr *lsrp; register const struct lsa_hdr *lshp; register const struct lsa *lsap; - register char sep; - register int i; + register u_int32_t lsa_count,lsa_count_max; switch (op->ospf_type) { @@ -381,113 +607,105 @@ ospf_decode_v2(register const struct ospfhdr *op, break; case OSPF_TYPE_HELLO: - if (vflag) { - TCHECK(op->ospf_hello.hello_deadint); - ospf_print_bits(ospf_option_bits, - op->ospf_hello.hello_options); - printf(" mask %s int %d pri %d dead %u", - ipaddr_string(&op->ospf_hello.hello_mask), - ntohs(op->ospf_hello.hello_helloint), - op->ospf_hello.hello_priority, - (u_int32_t)ntohl(op->ospf_hello.hello_deadint)); - } + printf("\n\tOptions: [%s]", + bittok2str(ospf_option_values,"none",op->ospf_hello.hello_options)); + + TCHECK(op->ospf_hello.hello_deadint); + printf("\n\t Hello Timer: %us, Dead Timer %us, Mask: %s, Priority: %u", + EXTRACT_16BITS(&op->ospf_hello.hello_helloint), + EXTRACT_32BITS(&op->ospf_hello.hello_deadint), + ipaddr_string(&op->ospf_hello.hello_mask), + op->ospf_hello.hello_priority); + TCHECK(op->ospf_hello.hello_dr); if (op->ospf_hello.hello_dr.s_addr != 0) - printf(" dr %s", + printf("\n\t Designated Router %s", ipaddr_string(&op->ospf_hello.hello_dr)); + TCHECK(op->ospf_hello.hello_bdr); if (op->ospf_hello.hello_bdr.s_addr != 0) - printf(" bdr %s", + printf(", Backup Designated Router %s", ipaddr_string(&op->ospf_hello.hello_bdr)); - if (vflag) { - printf(" nbrs"); - ap = op->ospf_hello.hello_neighbor; - while ((u_char *)ap < dataend) { - TCHECK(*ap); - printf(" %s", ipaddr_string(ap)); - ++ap; - } - } + + ap = op->ospf_hello.hello_neighbor; + if ((u_char *)ap < dataend) + printf("\n\t Neighbor List:"); + while ((u_char *)ap < dataend) { + TCHECK(*ap); + printf("\n\t %s", ipaddr_string(ap)); + ++ap; + } break; /* HELLO */ - case OSPF_TYPE_DB: + case OSPF_TYPE_DD: TCHECK(op->ospf_db.db_options); - ospf_print_bits(ospf_option_bits, op->ospf_db.db_options); - sep = ' '; + printf("\n\tOptions: [%s]", + bittok2str(ospf_option_values,"none",op->ospf_db.db_options)); TCHECK(op->ospf_db.db_flags); - if (op->ospf_db.db_flags & OSPF_DB_INIT) { - printf("%cI", sep); - sep = '/'; - } - if (op->ospf_db.db_flags & OSPF_DB_MORE) { - printf("%cM", sep); - sep = '/'; - } - if (op->ospf_db.db_flags & OSPF_DB_MASTER) { - printf("%cMS", sep); - sep = '/'; - } - TCHECK(op->ospf_db.db_seq); - printf(" S %X", (u_int32_t)ntohl(op->ospf_db.db_seq)); + printf(", DD Flags: [%s]", + bittok2str(ospf_dd_flag_values,"none",op->ospf_db.db_flags)); if (vflag) { /* Print all the LS adv's */ lshp = op->ospf_db.db_lshdr; - - while (!ospf_print_lshdr(lshp)) { - /* { (ctags) */ - printf(" }"); + while (ospf_print_lshdr(lshp) != -1) { ++lshp; } } break; - case OSPF_TYPE_LSR: - if (vflag) { - lsrp = op->ospf_lsr; - while ((u_char *)lsrp < dataend) { - TCHECK(*lsrp); - printf(" {"); /* } (ctags) */ - ospf_print_ls_type(ntohl(lsrp->ls_type), - &lsrp->ls_stateid, - &lsrp->ls_router, - "LinkStateType %d"); - /* { (ctags) */ - printf(" }"); - ++lsrp; - } - } + case OSPF_TYPE_LS_REQ: + lsrp = op->ospf_lsr; + while ((u_char *)lsrp < dataend) { + TCHECK(*lsrp); + + printf("\n\t Advertising Router: %s, %s LSA (%u)", + ipaddr_string(&lsrp->ls_router), + tok2str(lsa_values,"unknown",EXTRACT_32BITS(lsrp->ls_type)), + EXTRACT_32BITS(&lsrp->ls_type)); + + switch (EXTRACT_32BITS(lsrp->ls_type)) { + /* the LSA header for opaque LSAs was slightly changed */ + case LS_TYPE_OPAQUE_LL: + case LS_TYPE_OPAQUE_AL: + case LS_TYPE_OPAQUE_DW: + printf(", Opaque-Type: %s LSA (%u), Opaque-ID: %u", + tok2str(lsa_opaque_values, "unknown",lsrp->un_ls_stateid.opaque_field.opaque_type), + lsrp->un_ls_stateid.opaque_field.opaque_type, + EXTRACT_24BITS(&lsrp->un_ls_stateid.opaque_field.opaque_id)); + break; + default: + printf(", LSA-ID: %s", + ipaddr_string(&lsrp->un_ls_stateid.ls_stateid)); + break; + } + + ++lsrp; + } break; - case OSPF_TYPE_LSU: - if (vflag) { - lsap = op->ospf_lsu.lsu_lsa; - TCHECK(op->ospf_lsu.lsu_count); - i = ntohl(op->ospf_lsu.lsu_count); - while (i--) { - if (ospf_print_lsa(lsap)) - goto trunc; - lsap = (struct lsa *)((u_char *)lsap + - ntohs(lsap->ls_hdr.ls_length)); - } - } + case OSPF_TYPE_LS_UPDATE: + lsap = op->ospf_lsu.lsu_lsa; + TCHECK(op->ospf_lsu.lsu_count); + lsa_count_max = EXTRACT_32BITS(&op->ospf_lsu.lsu_count); + printf(", %d LSA%s",lsa_count_max, lsa_count_max > 1 ? "s" : ""); + for (lsa_count=1;lsa_count <= lsa_count_max;lsa_count++) { + printf("\n\t LSA #%u",lsa_count); + lsap = (const struct lsa *)ospf_print_lsa(lsap); + if (lsap == NULL) + goto trunc; + } break; - - case OSPF_TYPE_LSA: - if (vflag) { - lshp = op->ospf_lsa.lsa_lshdr; - - while (!ospf_print_lshdr(lshp)) { - /* { (ctags) */ - printf(" }"); - ++lshp; - } - } - break; + case OSPF_TYPE_LS_ACK: + lshp = op->ospf_lsa.lsa_lshdr; + while (ospf_print_lshdr(lshp) != -1) { + ++lshp; + } + break; default: - printf("v2 type %d", op->ospf_type); + printf("v2 type (%d)", op->ospf_type); break; } return (0); @@ -506,16 +724,10 @@ 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); - if (ntohs(op->ospf_authtype) == OSPF_AUTH_MD5) { + if (EXTRACT_16BITS(&op->ospf_authtype) == OSPF_AUTH_MD5) { length -= OSPF_AUTH_MD5_LEN; snapend -= OSPF_AUTH_MD5_LEN; } @@ -523,50 +735,61 @@ ospf_print(register const u_char *bp, register u_int length, /* If the type is valid translate it, or just print the type */ /* 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); - if (*cp == 't') + cp = tok2str(type2str, "unknown LS-type", op->ospf_type); + printf("OSPFv%u, %s (%u), length: %u", + op->ospf_version, + cp, + op->ospf_type, + length); + if (*cp == 'u') return; + if(!vflag) /* non verbose - so lets bail out here */ + return; + TCHECK(op->ospf_len); - if (length != ntohs(op->ospf_len)) { - printf(" [len %d]", ntohs(op->ospf_len)); + if (length != EXTRACT_16BITS(&op->ospf_len)) { + printf(" [len %d]", EXTRACT_16BITS(&op->ospf_len)); return; } dataend = bp + length; - /* Print the routerid if it is not the same as the source */ TCHECK(op->ospf_routerid); - if (ip->ip_src.s_addr != op->ospf_routerid.s_addr) - printf(" rtrid %s", ipaddr_string(&op->ospf_routerid)); + printf("\n\tRouter-ID: %s", ipaddr_string(&op->ospf_routerid)); TCHECK(op->ospf_areaid); if (op->ospf_areaid.s_addr != 0) - printf(" area %s", ipaddr_string(&op->ospf_areaid)); + printf(", Area %s", ipaddr_string(&op->ospf_areaid)); else - printf(" backbone"); + printf(", Backbone Area"); if (vflag) { /* Print authentication data (should we really do this?) */ TCHECK2(op->ospf_authdata[0], sizeof(op->ospf_authdata)); - switch (ntohs(op->ospf_authtype)) { + + printf(", Authentication Type: %s (%u)", + tok2str(ospf_authtype_values,"unknown",EXTRACT_16BITS(&op->ospf_authtype)), + EXTRACT_16BITS(&op->ospf_authtype)); + + switch (EXTRACT_16BITS(&op->ospf_authtype)) { case OSPF_AUTH_NONE: break; case OSPF_AUTH_SIMPLE: - printf(" auth \""); (void)fn_printn(op->ospf_authdata, sizeof(op->ospf_authdata), NULL); printf("\""); break; case OSPF_AUTH_MD5: - printf(" auth MD5"); + printf("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x", + *((op->ospf_authdata)+2), + *((op->ospf_authdata)+3), + EXTRACT_32BITS((op->ospf_authdata)+4)); break; default: - printf(" ??authtype-%d??", ntohs(op->ospf_authtype)); return; } } diff --git a/kame/kame/tcpdump/print-ospf6.c b/kame/kame/tcpdump/print-ospf6.c index 646a65ea22..5e6e69a3a3 100644 --- a/kame/kame/tcpdump/print-ospf6.c +++ b/kame/kame/tcpdump/print-ospf6.c @@ -22,25 +22,22 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-ospf.c,v 1.24 97/04/26 13:31:46 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-ospf6.c,v 1.11.2.2 2003/11/16 08:51:37 guy Exp $ (LBL)"; #endif -#include -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include -#include -#include -#include +#include -#include #include #include #include "interface.h" #include "addrtoname.h" +#include "extract.h" #include "ospf6.h" @@ -67,6 +64,13 @@ static const struct bits ospf6_rla_flag_bits[] = { { 0, NULL } }; +static const struct bits ospf6_asla_flag_bits[] = { + { ASLA_FLAG_EXTERNAL, "E" }, + { ASLA_FLAG_FWDADDR, "F" }, + { ASLA_FLAG_ROUTETAG, "T" }, + { 0, NULL } +}; + static struct tok type2str[] = { { OSPF_TYPE_UMD, "umd" }, { OSPF_TYPE_HELLO, "hello" }, @@ -79,6 +83,10 @@ static struct tok type2str[] = { static char tstr[] = " [|ospf]"; +#ifdef WIN32 +#define inline __inline +#endif /* WIN32 */ + /* Forwards */ static inline void ospf6_print_seqage(u_int32_t, time_t); static inline void ospf6_print_bits(const struct bits *, u_char); @@ -124,7 +132,7 @@ ospf6_print_ls_type(register u_int ls_type, register const rtrid_t *ls_stateid, register const rtrid_t *ls_router, register const char *fmt) { - char *scope; + const char *scope; switch (ls_type & LS_SCOPE_MASK) { case LS_SCOPE_LINKLOCAL: @@ -210,8 +218,8 @@ ospf6_print_lshdr(register const struct lsa_hdr *lshp) printf(" {"); /* } (ctags) */ TCHECK(lshp->ls_seq); - ospf6_print_seqage(ntohl(lshp->ls_seq), ntohs(lshp->ls_age)); - ospf6_print_ls_type(ntohs(lshp->ls_type), &lshp->ls_stateid, + ospf6_print_seqage(EXTRACT_32BITS(&lshp->ls_seq), EXTRACT_16BITS(&lshp->ls_age)); + ospf6_print_ls_type(EXTRACT_16BITS(&lshp->ls_type), &lshp->ls_stateid, &lshp->ls_router, "ls_type %d"); return (0); @@ -222,7 +230,7 @@ ospf6_print_lshdr(register const struct lsa_hdr *lshp) static int ospf6_print_lsaprefix(register const struct lsa_prefix *lsapp) { - int k; + u_int k; struct in6_addr prefix; TCHECK(*lsapp); @@ -233,10 +241,12 @@ ospf6_print_lsaprefix(register const struct lsa_prefix *lsapp) } memset(&prefix, 0, sizeof(prefix)); memcpy(&prefix, lsapp->lsa_p_prefix, k * 4); - printf(" %s/%d", ip6addr_string(&prefix), + printf(" %s/%d", ip6addr_string(&prefix), lsapp->lsa_p_len); if (lsapp->lsa_p_opt) printf("(opt=%x)", lsapp->lsa_p_opt); + if (lsapp->lsa_p_mbz) + printf("(mbz=%x)", EXTRACT_16BITS(&lsapp->lsa_p_mbz)); /* XXX */ return sizeof(*lsapp) - 4 + k * 4; trunc: @@ -250,7 +260,7 @@ ospf6_print_lsaprefix(register const struct lsa_prefix *lsapp) static int ospf6_print_lsa(register const struct lsa *lsap) { - register const u_char *ls_end; + register const u_char *ls_end, *ls_opt; register const struct rlalink *rlp; #if 0 register const struct tos_metric *tosp; @@ -265,20 +275,22 @@ ospf6_print_lsa(register const struct lsa *lsap) #if 0 register const u_int32_t *lp; #endif - register int j, k; + register u_int j; + register int k; + u_int32_t flags32; if (ospf6_print_lshdr(&lsap->ls_hdr)) return (1); TCHECK(lsap->ls_hdr.ls_length); - ls_end = (u_char *)lsap + ntohs(lsap->ls_hdr.ls_length); - switch (ntohs(lsap->ls_hdr.ls_type)) { + ls_end = (u_char *)lsap + EXTRACT_16BITS(&lsap->ls_hdr.ls_length); + switch (EXTRACT_16BITS(&lsap->ls_hdr.ls_type)) { case LS_TYPE_ROUTER | LS_SCOPE_AREA: TCHECK(lsap->lsa_un.un_rla.rla_flags); ospf6_print_bits(ospf6_rla_flag_bits, lsap->lsa_un.un_rla.rla_flags); TCHECK(lsap->lsa_un.un_rla.rla_options); ospf6_print_bits(ospf6_option_bits, - ntohl(lsap->lsa_un.un_rla.rla_options)); + EXTRACT_32BITS(&lsap->lsa_un.un_rla.rla_options)); TCHECK(lsap->lsa_un.un_rla.rla_link); rlp = lsap->lsa_un.un_rla.rla_link; @@ -311,7 +323,7 @@ ospf6_print_lsa(register const struct lsa *lsap) rlp->link_type); return (0); } - printf(" metric %d", ntohs(rlp->link_metric)); + printf(" metric %d", EXTRACT_16BITS(&rlp->link_metric)); /* { (ctags) */ printf(" }"); rlp++; @@ -321,7 +333,7 @@ ospf6_print_lsa(register const struct lsa *lsap) case LS_TYPE_NETWORK | LS_SCOPE_AREA: TCHECK(lsap->lsa_un.un_nla.nla_options); ospf6_print_bits(ospf6_option_bits, - ntohl(lsap->lsa_un.un_nla.nla_options)); + EXTRACT_32BITS(&lsap->lsa_un.un_nla.nla_options)); printf(" rtrs"); ap = lsap->lsa_un.un_nla.nla_router; while ((u_char *)ap < ls_end) { @@ -334,16 +346,55 @@ ospf6_print_lsa(register const struct lsa *lsap) case LS_TYPE_INTER_AP | LS_SCOPE_AREA: TCHECK(lsap->lsa_un.un_inter_ap.inter_ap_metric); printf(" metric %u", - (u_int32_t)ntohl(lsap->lsa_un.un_inter_ap.inter_ap_metric) & SLA_MASK_METRIC); + EXTRACT_32BITS(&lsap->lsa_un.un_inter_ap.inter_ap_metric) & SLA_MASK_METRIC); lsapp = lsap->lsa_un.un_inter_ap.inter_ap_prefix; while (lsapp + sizeof(lsapp) <= (struct lsa_prefix *)ls_end) { k = ospf6_print_lsaprefix(lsapp); - if (k < 0) + if (k) goto trunc; lsapp = (struct lsa_prefix *)(((u_char *)lsapp) + k); } break; + case LS_SCOPE_AS | LS_TYPE_ASE: + TCHECK(lsap->lsa_un.un_asla.asla_metric); + flags32 = EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric); + ospf6_print_bits(ospf6_asla_flag_bits, flags32); + printf(" metric %u", + EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric) & + ASLA_MASK_METRIC); + lsapp = lsap->lsa_un.un_asla.asla_prefix; + k = ospf6_print_lsaprefix(lsapp); + if (k < 0) + goto trunc; + if ((ls_opt = (u_char *)(((u_char *)lsapp) + k)) < ls_end) { + struct in6_addr *fwdaddr6; + + if ((flags32 & ASLA_FLAG_FWDADDR) != 0) { + fwdaddr6 = (struct in6_addr *)ls_opt; + TCHECK(*fwdaddr6); + printf(" forward %s", + ip6addr_string(fwdaddr6)); + + ls_opt += sizeof(struct in6_addr); + } + + if ((flags32 & ASLA_FLAG_ROUTETAG) != 0) { + TCHECK(*(u_int32_t *)ls_opt); + printf(" tag %s", + ipaddr_string((u_int32_t *)ls_opt)); + + ls_opt += sizeof(u_int32_t); + } + + if (lsapp->lsa_p_mbz) { + TCHECK(*(u_int32_t *)ls_opt); + printf(" RefLSID: %s", + ipaddr_string((u_int32_t *)ls_opt)); + ls_opt += sizeof(u_int32_t); + } + } + break; #if 0 case LS_TYPE_SUM_ABR: TCHECK(lsap->lsa_un.un_sla.sla_tosmetric); @@ -352,7 +403,7 @@ ospf6_print_lsa(register const struct lsa *lsap) register u_int32_t ul; TCHECK(*lp); - ul = ntohl(*lp); + ul = EXTRACT_32BITS(lp); printf(" tos %d metric %d", (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS, ul & SLA_MASK_METRIC); @@ -360,42 +411,12 @@ ospf6_print_lsa(register const struct lsa *lsap) } break; - case LS_TYPE_ASE: - TCHECK(lsap->lsa_un.un_nla.nla_mask); - printf(" mask %s", - ipaddr_string(&lsap->lsa_un.un_asla.asla_mask)); - - TCHECK(lsap->lsa_un.un_sla.sla_tosmetric); - almp = lsap->lsa_un.un_asla.asla_metric; - while ((u_char *)almp < ls_end) { - register u_int32_t ul; - - TCHECK(almp->asla_tosmetric); - ul = ntohl(almp->asla_tosmetric); - printf(" type %d tos %d metric %d", - (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1, - (ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS, - (ul & ASLA_MASK_METRIC)); - TCHECK(almp->asla_forward); - if (almp->asla_forward.s_addr) { - printf(" forward %s", - ipaddr_string(&almp->asla_forward)); - } - TCHECK(almp->asla_tag); - if (almp->asla_tag.s_addr) { - printf(" tag %s", - ipaddr_string(&almp->asla_tag)); - } - ++almp; - } - break; - case LS_TYPE_GROUP: /* Multicast extensions as of 23 July 1991 */ mcp = lsap->lsa_un.un_mcla; while ((u_char *)mcp < ls_end) { TCHECK(mcp->mcla_vid); - switch (ntohl(mcp->mcla_vtype)) { + switch (EXTRACT_32BITS(&mcp->mcla_vtype)) { case MCLA_VERTEX_ROUTER: printf(" rtr rtrid %s", @@ -409,7 +430,7 @@ ospf6_print_lsa(register const struct lsa *lsap) default: printf(" ??VertexType %u??", - (u_int32_t)ntohl(mcp->mcla_vtype)); + EXTRACT_32BITS(&mcp->mcla_vtype)); break; } ++mcp; @@ -420,15 +441,15 @@ ospf6_print_lsa(register const struct lsa *lsap) /* Link LSA */ llsap = &lsap->lsa_un.un_llsa; TCHECK(llsap->llsa_options); - ospf6_print_bits(ospf6_option_bits, ntohl(llsap->llsa_options)); + ospf6_print_bits(ospf6_option_bits, EXTRACT_32BITS(&llsap->llsa_options)); TCHECK(llsap->llsa_nprefix); printf(" pri %d lladdr %s npref %d", llsap->llsa_priority, ip6addr_string(&llsap->llsa_lladdr), - (u_int32_t)ntohl(llsap->llsa_nprefix)); + EXTRACT_32BITS(&llsap->llsa_nprefix)); lsapp = llsap->llsa_prefix; - for (j = 0; j < ntohl(llsap->llsa_nprefix); j++) { + for (j = 0; j < EXTRACT_32BITS(&llsap->llsa_nprefix); j++) { k = ospf6_print_lsaprefix(lsapp); - if (k < 0) + if (k) goto trunc; lsapp = (struct lsa_prefix *)(((u_char *)lsapp) + k); } @@ -438,20 +459,20 @@ ospf6_print_lsa(register const struct lsa *lsap) /* Intra-Area-Prefix LSA */ TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_rtid); ospf6_print_ls_type( - ntohs(lsap->lsa_un.un_intra_ap.intra_ap_lstype), + EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_lstype), &lsap->lsa_un.un_intra_ap.intra_ap_lsid, &lsap->lsa_un.un_intra_ap.intra_ap_rtid, "LinkStateType %d"); TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_nprefix); printf(" npref %d", - ntohs(lsap->lsa_un.un_intra_ap.intra_ap_nprefix)); + EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_nprefix)); lsapp = lsap->lsa_un.un_intra_ap.intra_ap_prefix; for (j = 0; - j < ntohs(lsap->lsa_un.un_intra_ap.intra_ap_nprefix); + j < EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_nprefix); j++) { k = ospf6_print_lsaprefix(lsapp); - if (k < 0) + if (k) goto trunc; lsapp = (struct lsa_prefix *)(((u_char *)lsapp) + k); } @@ -459,7 +480,7 @@ ospf6_print_lsa(register const struct lsa *lsap) default: printf(" ??LinkStateType 0x%04x??", - ntohs(lsap->ls_hdr.ls_type)); + EXTRACT_16BITS(&lsap->ls_hdr.ls_type)); } /* { (ctags) */ @@ -494,12 +515,12 @@ ospf6_decode_v3(register const struct ospf6hdr *op, if (vflag) { TCHECK(op->ospf6_hello.hello_deadint); ospf6_print_bits(ospf6_option_bits, - ntohl(op->ospf6_hello.hello_options)); + EXTRACT_32BITS(&op->ospf6_hello.hello_options)); printf(" ifid %s pri %d int %d dead %u", ipaddr_string(&op->ospf6_hello.hello_ifid), op->ospf6_hello.hello_priority, - ntohs(op->ospf6_hello.hello_helloint), - ntohs(op->ospf6_hello.hello_deadint)); + EXTRACT_16BITS(&op->ospf6_hello.hello_helloint), + EXTRACT_16BITS(&op->ospf6_hello.hello_deadint)); } TCHECK(op->ospf6_hello.hello_dr); if (op->ospf6_hello.hello_dr != 0) @@ -523,7 +544,7 @@ ospf6_decode_v3(register const struct ospf6hdr *op, case OSPF_TYPE_DB: TCHECK(op->ospf6_db.db_options); ospf6_print_bits(ospf6_option_bits, - ntohl(op->ospf6_db.db_options)); + EXTRACT_32BITS(&op->ospf6_db.db_options)); sep = ' '; TCHECK(op->ospf6_db.db_flags); if (op->ospf6_db.db_flags & OSPF6_DB_INIT) { @@ -539,8 +560,8 @@ ospf6_decode_v3(register const struct ospf6hdr *op, sep = '/'; } TCHECK(op->ospf6_db.db_seq); - printf(" mtu %u S %X", ntohs(op->ospf6_db.db_mtu), - (u_int32_t)ntohl(op->ospf6_db.db_seq)); + printf(" mtu %u S %X", EXTRACT_16BITS(&op->ospf6_db.db_mtu), + EXTRACT_32BITS(&op->ospf6_db.db_seq)); if (vflag) { /* Print all the LS adv's */ @@ -560,7 +581,7 @@ ospf6_decode_v3(register const struct ospf6hdr *op, while ((u_char *)lsrp < dataend) { TCHECK(*lsrp); printf(" {"); /* } (ctags) */ - ospf6_print_ls_type(ntohs(lsrp->ls_type), + ospf6_print_ls_type(EXTRACT_16BITS(&lsrp->ls_type), &lsrp->ls_stateid, &lsrp->ls_router, "LinkStateType %d"); @@ -575,12 +596,12 @@ ospf6_decode_v3(register const struct ospf6hdr *op, if (vflag) { lsap = op->ospf6_lsu.lsu_lsa; TCHECK(op->ospf6_lsu.lsu_count); - i = ntohl(op->ospf6_lsu.lsu_count); + i = EXTRACT_32BITS(&op->ospf6_lsu.lsu_count); while (i--) { if (ospf6_print_lsa(lsap)) goto trunc; lsap = (struct lsa *)((u_char *)lsap + - ntohs(lsap->ls_hdr.ls_length)); + EXTRACT_16BITS(&lsap->ls_hdr.ls_length)); } } break; @@ -620,13 +641,13 @@ ospf6_print(register const u_char *bp, register u_int length) /* value. If it's not valid, say so and return */ TCHECK(op->ospf6_type); cp = tok2str(type2str, "type%d", op->ospf6_type); - printf(" OSPFv%d-%s %d:", op->ospf6_version, cp, length); + printf("OSPFv%d-%s %d:", op->ospf6_version, cp, length); if (*cp == 't') return; TCHECK(op->ospf6_len); - if (length != ntohs(op->ospf6_len)) { - printf(" [len %d]", ntohs(op->ospf6_len)); + if (length != EXTRACT_16BITS(&op->ospf6_len)) { + printf(" [len %d]", EXTRACT_16BITS(&op->ospf6_len)); return; } dataend = bp + length; diff --git a/kame/kame/tcpdump/print-pflog.c b/kame/kame/tcpdump/print-pflog.c new file mode 100644 index 0000000000..24634b2ff6 --- /dev/null +++ b/kame/kame/tcpdump/print-pflog.c @@ -0,0 +1,160 @@ +/* + * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-pflog.c,v 1.7.2.4 2004/03/29 21:56:26 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "pf.h" + +static struct tok pf_reasons[] = { + { 0, "0(match)" }, + { 1, "1(bad-offset)" }, + { 2, "2(fragment)" }, + { 3, "3(short)" }, + { 4, "4(normalize)" }, + { 5, "5(memory)" }, + { 0, NULL } +}; + +static struct tok pf_actions[] = { + { PF_PASS, "pass" }, + { PF_DROP, "block" }, + { PF_SCRUB, "scrub" }, + { PF_NAT, "nat" }, + { PF_NONAT, "nat" }, + { PF_BINAT, "binat" }, + { PF_NOBINAT, "binat" }, + { PF_RDR, "rdr" }, + { PF_NORDR, "rdr" }, + { PF_SYNPROXY_DROP, "synproxy-drop" }, + { 0, NULL } +}; + +static struct tok pf_directions[] = { + { PF_INOUT, "in/out" }, + { PF_IN, "in" }, + { PF_OUT, "out" }, + { 0, NULL } +}; + +/* For reading capture files on other systems */ +#define OPENBSD_AF_INET 2 +#define OPENBSD_AF_INET6 24 + +static void +pflog_print(const struct pfloghdr *hdr) +{ + if (ntohl(hdr->subrulenr) == (u_int32_t)-1) + printf("rule %u/", ntohl(hdr->rulenr)); + else + printf("rule %u.%s.%u/", ntohl(hdr->rulenr), hdr->ruleset, + ntohl(hdr->subrulenr)); + + printf("%s: %s %s on %s: ", + tok2str(pf_reasons, "unkn(%u)", hdr->reason), + tok2str(pf_actions, "unkn(%u)", hdr->action), + tok2str(pf_directions, "unkn(%u)", hdr->dir), + hdr->ifname); +} + +u_int +pflog_if_print(const struct pcap_pkthdr *h, register const u_char *p) +{ + u_int length = h->len; + u_int hdrlen; + u_int caplen = h->caplen; + const struct pfloghdr *hdr; + u_int8_t af; + + /* check length */ + if (caplen < sizeof(u_int8_t)) { + printf("[|pflog]"); + return (caplen); + } + +#define MIN_PFLOG_HDRLEN 45 + hdr = (struct pfloghdr *)p; + if (hdr->length < MIN_PFLOG_HDRLEN) { + printf("[pflog: invalid header length!]"); + return (hdr->length); /* XXX: not really */ + } + hdrlen = BPF_WORDALIGN(hdr->length); + + if (caplen < hdrlen) { + printf("[|pflog]"); + return (hdrlen); /* XXX: true? */ + } + + /* print what we know */ + hdr = (struct pfloghdr *)p; + TCHECK(*hdr); + if (eflag) + pflog_print(hdr); + + /* skip to the real packet */ + af = hdr->af; + length -= hdrlen; + caplen -= hdrlen; + p += hdrlen; + switch (af) { + + case AF_INET: +#if OPENBSD_AF_INET != AF_INET + case OPENBSD_AF_INET: /* XXX: read pcap files */ +#endif + ip_print(p, length); + break; + +#ifdef INET6 + case AF_INET6: +#if OPENBSD_AF_INET6 != AF_INET6 + case OPENBSD_AF_INET6: /* XXX: read pcap files */ +#endif + ip6_print(p, length); + break; +#endif + + default: + /* address family not handled, print raw packet */ + if (!eflag) + pflog_print(hdr); + if (!xflag && !qflag) + default_print(p, caplen); + } + + return (hdrlen); +trunc: + printf("[|pflog]"); + return (hdrlen); +} diff --git a/kame/kame/tcpdump/print-pim.c b/kame/kame/tcpdump/print-pim.c index 37a9c844c6..de3b4d518b 100644 --- a/kame/kame/tcpdump/print-pim.c +++ b/kame/kame/tcpdump/print-pim.c @@ -20,109 +20,333 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-pim.c,v 1.7 96/09/26 23:36:48 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-pim.c,v 1.37.2.4 2004/03/24 02:52:37 guy Exp $ (LBL)"; #endif -#include -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include -#include -#include -#include -#include -#include -#include +#include /* * XXX: We consider a case where IPv6 is not ready yet for portability, * but PIM dependent defintions should be independent of IPv6... */ -#ifdef INET6 -#include -#else + struct pim { -#if defined(BYTE_ORDER) && (BYTE_ORDER == LITTLE_ENDIAN) - u_char pim_type:4, /* the PIM message type, currently they are: - * Hello, Register, Register-Stop, Join/Prune, - * Bootstrap, Assert, Graft (PIM-DM only), - * Graft-Ack (PIM-DM only), C-RP-Adv - */ - pim_ver:4; /* PIM version number; 2 for PIMv2 */ -#else - u_char pim_ver:4, /* PIM version */ - pim_type:4; /* PIM type */ -#endif + u_int8_t pim_typever; + /* upper 4bit: PIM version number; 2 for PIMv2 */ + /* lower 4bit: the PIM message type, currently they are: + * Hello, Register, Register-Stop, Join/Prune, + * Bootstrap, Assert, Graft (PIM-DM only), + * Graft-Ack (PIM-DM only), C-RP-Adv + */ +#define PIM_VER(x) (((x) & 0xf0) >> 4) +#define PIM_TYPE(x) ((x) & 0x0f) u_char pim_rsv; /* Reserved */ u_short pim_cksum; /* IP style check sum */ }; -#endif #include #include -#include #include "interface.h" #include "addrtoname.h" +#include "extract.h" + +#include "ip.h" static void pimv2_print(register const u_char *bp, register u_int len); -void -igmp_pim_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) { - register const u_char *ep; - register u_char type; + 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; + } - ep = (const u_char *)snapend; - if (bp >= ep) + TCHECK2(bp[0], 4); + 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)); + TCHECK2(bp[4], 4); + 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++) { + const 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; + } + } return; +trunc: + (void)printf("[|pim]"); + return; +} - type = bp[1]; - - switch (type) { - case 0: - (void)printf(" Query"); - break; - - case 1: - (void)printf(" Register"); - break; +void +pimv1_print(register const u_char *bp, register u_int len) +{ + register const u_char *ep; + register u_char type; - case 2: - (void)printf(" Register-Stop"); - break; + ep = (const u_char *)snapend; + if (bp >= ep) + return; - case 3: - (void)printf(" Join/Prune"); - break; + TCHECK(bp[1]); + type = bp[1]; - case 4: - (void)printf(" RP-reachable"); - break; + 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"); + break; + case 2: + (void)printf(" Sparse-Dense-mode"); + break; + 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 5: - (void)printf(" Assert"); - 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; + 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])); + 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 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; - case 6: - (void)printf(" Graft"); - break; +trunc: + (void)printf("[|pim]"); + return; +} - case 7: - (void)printf(" Graft-ACK"); - break; +/* + * auto-RP is a cisco protocol, documented at + * 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; + } - case 8: - (void)printf(" Mode"); - 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; + + 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; - default: - (void)printf(" [type %d]", type); - break; - } +trunc: + (void)printf("[|autorp]"); + return; } void @@ -138,121 +362,188 @@ pim_print(register const u_char *bp, register u_int len) TCHECK(pim->pim_rsv); #endif - switch(pim->pim_ver) { - case 2: /* avoid hardcoding? */ - (void)printf("v2"); + switch (PIM_VER(pim->pim_typever)) { + case 2: /* avoid hardcoding? */ + (void)printf("pim v2"); pimv2_print(bp, len); break; - default: - (void)printf("v%d", pim->pim_ver); + default: + (void)printf("pim v%d", PIM_VER(pim->pim_typever)); break; } return; } +/* + * PIMv2 uses encoded address representations. + * + * The last PIM-SM I-D before RFC2117 was published specified the + * following representation for unicast addresses. However, RFC2117 + * specified no encoding for unicast addresses with the unicast + * address length specified in the header. Therefore, we have to + * guess which encoding is being used (Cisco's PIMv2 implementation + * uses the non-RFC encoding). RFC2117 turns a previously "Reserved" + * field into a 'unicast-address-length-in-bytes' field. We guess + * that it's the draft encoding if this reserved field is zero. + * + * RFC2362 goes back to the encoded format, and calls the addr length + * field "reserved" again. + * + * The first byte is the address family, from: + * + * 0 Reserved + * 1 IP (IP version 4) + * 2 IP6 (IP version 6) + * 3 NSAP + * 4 HDLC (8-bit multidrop) + * 5 BBN 1822 + * 6 802 (includes all 802 media plus Ethernet "canonical format") + * 7 E.163 + * 8 E.164 (SMDS, Frame Relay, ATM) + * 9 F.69 (Telex) + * 10 X.121 (X.25, Frame Relay) + * 11 IPX + * 12 Appletalk + * 13 Decnet IV + * 14 Banyan Vines + * 15 E.164 with NSAP format subaddress + * + * In addition, the second byte is an "Encoding". 0 is the default + * encoding for the address family, and no other encodings are currently + * specified. + * + */ + +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 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Addr Family | Encoding Type | Unicast Address | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++ + * 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 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Addr Family | Encoding Type | Reserved | Mask Len | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Group multicast Address | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * 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 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Source Address | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ static int pimv2_addr_print(const u_char *bp, enum pimv2_addrtype at, int silent) { - const u_char *ep; int af; - char *afstr; - int len; - - ep = (const u_char *)snapend; - if (bp >= ep) - return -1; + const char *afstr; + int len, hdrlen; - switch (bp[0]) { - case 1: - af = AF_INET; - afstr = "IPv4"; - break; -#ifdef INET6 - case 2: - af = AF_INET6; - afstr = "IPv6"; - break; -#endif - default: - return -1; - } - - if (bp[1] != 0) - return -1; + TCHECK(bp[0]); - switch (at) { - case pimv2_unicast: - if (af == AF_INET) { + if (pimv2_addr_len == 0) { + TCHECK(bp[1]); + switch (bp[0]) { + case 1: + af = AF_INET; + afstr = "IPv4"; len = 4; - if (bp + 2 + len > ep) - return -1; - if (!silent) - (void)printf("%s", ipaddr_string(bp + 2)); - } + break; #ifdef INET6 - else if (af == AF_INET6) { + case 2: + af = AF_INET6; + afstr = "IPv6"; len = 16; - if (bp + 2 + len > ep) - return -1; - if (!silent) - (void)printf("%s", ip6addr_string(bp + 2)); + break; +#endif + default: + return -1; } + if (bp[1] != 0) + return -1; + hdrlen = 2; + } else { + switch (pimv2_addr_len) { + case 4: + af = AF_INET; + afstr = "IPv4"; + break; +#ifdef INET6 + case 16: + af = AF_INET6; + afstr = "IPv6"; + break; #endif - return 2 + len; - case pimv2_group: + default: + return -1; + break; + } + len = pimv2_addr_len; + hdrlen = 0; + } + + bp += hdrlen; + switch (at) { + case pimv2_unicast: + TCHECK2(bp[0], len); if (af == AF_INET) { - len = 4; - if (bp + 4 + len > ep) - return -1; if (!silent) - (void)printf("%s/%u", ipaddr_string(bp + 4), bp[3]); + (void)printf("%s", ipaddr_string(bp)); } #ifdef INET6 else if (af == AF_INET6) { - len = 16; - if (bp + 4 + len > ep) - return -1; if (!silent) - (void)printf("%s/%u", ip6addr_string(bp + 4), bp[3]); + (void)printf("%s", ip6addr_string(bp)); } #endif - return 4 + len; - case pimv2_source: + return hdrlen + len; + case pimv2_group: + case pimv2_source: + TCHECK2(bp[0], len + 2); if (af == AF_INET) { - len = 4; - if (bp + 4 + len > ep) - return -1; - if (!silent) - (void)printf("%s/%u", ipaddr_string(bp + 4), bp[3]); + if (!silent) { + (void)printf("%s", ipaddr_string(bp + 2)); + if (bp[1] != 32) + (void)printf("/%u", bp[1]); + } } #ifdef INET6 else if (af == AF_INET6) { - len = 16; - if (bp + 4 + len > ep) - return -1; - if (!silent) - (void)printf("%s/%u", ip6addr_string(bp + 4), bp[3]); + if (!silent) { + (void)printf("%s", ip6addr_string(bp + 2)); + if (bp[1] != 128) + (void)printf("/%u", bp[1]); + } } #endif - if (vflag && bp[2] && !silent) { - (void)printf("(%s%s%s)", - bp[2] & 0x04 ? "S" : "", - bp[2] & 0x02 ? "W" : "", - bp[2] & 0x01 ? "R" : ""); + if (bp[0] && !silent) { + if (at == pimv2_group) { + (void)printf("(0x%02x)", bp[0]); + } else { + (void)printf("(%s%s%s", + bp[0] & 0x04 ? "S" : "", + bp[0] & 0x02 ? "W" : "", + bp[0] & 0x01 ? "R" : ""); + if (bp[0] & 0xf8) { + (void) printf("+0x%02x", bp[0] & 0xf8); + } + (void)printf(")"); + } } - return 4 + len; + return hdrlen + 2 + len; default: return -1; } +trunc: + return -1; } static void @@ -265,36 +556,121 @@ pimv2_print(register const u_char *bp, register u_int len) ep = (const u_char *)snapend; if (bp >= ep) return; -#ifdef notyet /* currently we see only version and type */ + if (ep > bp + len) + ep = bp + len; TCHECK(pim->pim_rsv); -#endif + pimv2_addr_len = pim->pim_rsv; + if (pimv2_addr_len != 0) + (void)printf("[RFC2117-encoding] "); - switch (pim->pim_type) { - case 0: + switch (PIM_TYPE(pim->pim_typever)) { + case 0: { u_int16_t otype, olen; (void)printf(" Hello"); bp += 4; while (bp < ep) { - otype = ntohs(*(u_int16_t *)(bp + 0)); - olen = ntohs(*(u_int16_t *)(bp + 2)); - if (otype == 1 && olen == 2 && bp + 4 + olen <= ep) { - u_int16_t value; - (void)printf(" holdtime="); - value = ntohs(*(u_int16_t *)(bp + 4)); - if (value == 0xffff) - (void)printf("infty"); + TCHECK2(bp[0], 4); + otype = EXTRACT_16BITS(&bp[0]); + olen = EXTRACT_16BITS(&bp[2]); + TCHECK2(bp[0], 4 + olen); + switch (otype) { + case 1: /* Hold time */ + (void)printf(" (Hold-time "); + relts_print(EXTRACT_16BITS(&bp[4])); + (void)printf(")"); + break; + + case 2: /* LAN Prune Delay */ + (void)printf(" (LAN-Prune-Delay: "); + if (olen != 4) { + (void)printf("!olen=%d!)", olen); + } else { + char t_bit; + u_int16_t lan_delay, override_interval; + lan_delay = EXTRACT_16BITS(&bp[4]); + override_interval = EXTRACT_16BITS(&bp[6]); + t_bit = (lan_delay & 0x8000)? 1 : 0; + lan_delay &= ~0x8000; + (void)printf("T-bit=%d lan-delay=%dms override-interval=%dms)", + t_bit, lan_delay, override_interval); + } + break; + + case 18: /* Old DR-Priority */ + if (olen == 4) + (void)printf(" (OLD-DR-Priority: %d)", + EXTRACT_32BITS(&bp[4])); else - (void)printf("%u", value); - bp += 4 + olen; - } else + goto unknown; + break; + + + case 19: /* DR-Priority */ + if (olen == 0) { + (void)printf(" (OLD-bidir-capable)"); + break; + } + (void)printf(" (DR-Priority: "); + if (olen != 4) { + (void)printf("!olen=%d!)", olen); + } else { + (void)printf("%d)", EXTRACT_32BITS(&bp[4])); + } + break; + + case 20: + (void)printf(" (Genid: 0x%08x)", EXTRACT_32BITS(&bp[4])); + break; + + case 21: + (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; + + case 24: /* Address List */ + case 65001: /* Address List (old implementations) */ + (void)printf(" (%saddr-list", + otype == 65001 ? "old" : ""); + if (vflag > 1) { + const u_char *ptr = &bp[4]; + while (ptr < &bp[4 + olen]) { + int advance; + + printf(" "); + advance = pimv2_addr_print(ptr, pimv2_unicast, 0); + if (advance < 0) { + printf("..."); + break; + } + ptr += advance; + } + } + (void)printf(")"); + break; + default: + unknown: + if (vflag) + (void)printf(" [Hello option %d]", otype); + } + bp += 4 + olen; } break; } - case 1: - { + case 1: + { struct ip *ip; (void)printf(" Register"); @@ -308,23 +684,25 @@ pimv2_print(register const u_char *bp, register u_int len) if (bp >= ep) break; ip = (struct ip *)bp; - switch(ip->ip_v) { - case 4: /* IPv4 */ + switch (IP_V(ip)) { + 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: - (void)printf(" IP ver %d", ip->ip_v); + 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) @@ -345,9 +723,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; @@ -355,19 +733,19 @@ pimv2_print(register const u_char *bp, register u_int len) u_int16_t nprune; int i, j; - switch (pim->pim_type) { - case 3: + switch (PIM_TYPE(pim->pim_typever)) { + case 3: (void)printf(" Join/Prune"); break; - case 6: + case 6: (void)printf(" Graft"); break; - case 7: + case 7: (void)printf(" Graft-ACK"); break; } bp += 4; len -= 4; - if (pim->pim_type != 7) { /*not for Graft-ACK*/ + if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/ if (bp >= ep) break; (void)printf(" upstream-neighbor="); @@ -380,14 +758,14 @@ pimv2_print(register const u_char *bp, register u_int len) if (bp + 4 > ep) break; ngroup = bp[1]; - holdtime = ntohs(*(u_int16_t *)(bp + 2)); + holdtime = EXTRACT_16BITS(&bp[2]); (void)printf(" groups=%u", ngroup); - if (pim->pim_type != 7) { /*not for Graft-ACK*/ + if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/ (void)printf(" holdtime="); if (holdtime == 0xffff) (void)printf("infty"); else - (void)printf("%u", holdtime); + relts_print(holdtime); } bp += 4; len -= 4; for (i = 0; i < ngroup; i++) { @@ -403,8 +781,8 @@ pimv2_print(register const u_char *bp, register u_int len) (void)printf("...)"); goto jp_done; } - njoin = ntohs(*(u_int16_t *)(bp + 0)); - nprune = ntohs(*(u_int16_t *)(bp + 2)); + njoin = EXTRACT_16BITS(&bp[0]); + nprune = EXTRACT_16BITS(&bp[2]); (void)printf(" join=%u", njoin); bp += 4; len -= 4; for (j = 0; j < njoin; j++) { @@ -430,8 +808,8 @@ pimv2_print(register const u_char *bp, register u_int len) break; } - case 4: - { + case 4: + { int i, j, frpcnt; (void)printf(" Bootstrap"); @@ -439,7 +817,7 @@ pimv2_print(register const u_char *bp, register u_int len) /* Fragment Tag, Hash Mask len, and BSR-priority */ if (bp + sizeof(u_int16_t) >= ep) break; - (void)printf(" tag=%x", ntohs(*(u_int16_t *)bp)); + (void)printf(" tag=%x", EXTRACT_16BITS(bp)); bp += sizeof(u_int16_t); if (bp >= ep) break; (void)printf(" hashmlen=%d", bp[0]); @@ -471,12 +849,12 @@ pimv2_print(register const u_char *bp, register u_int len) (void)printf("...)"); goto bs_done; } - (void)printf(" RPcnt=%d", frpcnt = bp[0]); + (void)printf(" RPcnt=%d", bp[0]); if (bp + 1 >= ep) { (void)printf("...)"); goto bs_done; } - (void)printf(" FRPcnt=%d", bp[1]); + (void)printf(" FRPcnt=%d", frpcnt = bp[1]); bp += 4; for (j = 0; j < frpcnt && bp < ep; j++) { @@ -490,25 +868,25 @@ pimv2_print(register const u_char *bp, register u_int len) } bp += advance; - if (bp + 2 >= ep) { + if (bp + 1 >= ep) { (void)printf("...)"); goto bs_done; } - (void)printf(",holdtime=%d", - ntohs(*(u_int16_t *)bp)); - if (bp + 3 >= ep) { + (void)printf(",holdtime="); + relts_print(EXTRACT_16BITS(bp)); + if (bp + 2 >= ep) { (void)printf("...)"); goto bs_done; } - (void)printf(",prio=%d", bp[3]); + (void)printf(",prio=%d", bp[2]); bp += 4; } (void)printf(")"); } bs_done: break; - } - case 5: + } + case 5: (void)printf(" Assert"); bp += 4; len -= 4; if (bp >= ep) @@ -529,14 +907,14 @@ pimv2_print(register const u_char *bp, register u_int len) bp += advance; len -= advance; if (bp + 8 > ep) break; - if (ntohl(*(u_int32_t *)bp) & 0x80000000) + if (bp[0] & 0x80) (void)printf(" RPT"); - (void)printf(" pref=%u", ntohl(*(u_int32_t *)bp)); - (void)printf(" metric=%u", ntohl(*(u_int32_t *)(bp + 4))); + (void)printf(" pref=%u", EXTRACT_32BITS(&bp[0]) & 0x7fffffff); + (void)printf(" metric=%u", EXTRACT_32BITS(&bp[4])); break; - case 8: - { + case 8: + { int i, pfxcnt; (void)printf(" Candidate-RP-Advertisement"); @@ -549,7 +927,8 @@ pimv2_print(register const u_char *bp, register u_int len) if (bp + 1 >= ep) break; (void)printf(" prio=%d", bp[1]); if (bp + 3 >= ep) break; - (void)printf(" holdtime=%d", ntohs(*(u_int16_t *)(bp + 2))); + (void)printf(" holdtime="); + relts_print(EXTRACT_16BITS(&bp[2])); bp += 4; /* Encoded-Unicast-RP-Address */ @@ -572,12 +951,41 @@ pimv2_print(register const u_char *bp, register u_int len) bp += advance; } break; - } + } + + case 9: + (void)printf(" Prune-Refresh"); + (void)printf(" src="); + if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) { + (void)printf("..."); + break; + } + bp += advance; + (void)printf(" grp="); + if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) { + (void)printf("..."); + break; + } + bp += advance; + (void)printf(" forwarder="); + if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) { + (void)printf("..."); + break; + } + bp += advance; + TCHECK2(bp[0], 2); + (void)printf(" TUNR "); + relts_print(EXTRACT_16BITS(bp)); + break; + default: - (void)printf(" [type %d]", pim->pim_type); + (void)printf(" [type %d]", PIM_TYPE(pim->pim_typever)); break; } return; + +trunc: + (void)printf("[|pim]"); } diff --git a/kame/kame/tcpdump/print-ppp.c b/kame/kame/tcpdump/print-ppp.c index d7e2a5a0b9..f4e5bd0b17 100644 --- a/kame/kame/tcpdump/print-ppp.c +++ b/kame/kame/tcpdump/print-ppp.c @@ -17,160 +17,1307 @@ * 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. + * + * Extensively modified by Motonori Shindo (mshindo@mshindo.net) for more + * complete PPP support. + */ + +/* + * TODO: + * o resolve XXX as much as possible + * o MP support + * o BAP support */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-ppp.c,v 1.26 97/06/12 14:21:29 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.89.2.3 2004/03/24 03:32:43 guy Exp $ (LBL)"; #endif -#include -#include -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include -#include -#include -#include -#include +#include -#include -#include -#include -#include #ifdef __bsdi__ #include #include #endif +#include +#include + #include "interface.h" +#include "extract.h" #include "addrtoname.h" #include "ppp.h" +#include "chdlc.h" +#include "ethertype.h" -/* XXX This goes somewhere else. */ -#define PPP_HDRLEN 4 +/* + * The following constatns are defined by IANA. Please refer to + * http://www.isi.edu/in-notes/iana/assignments/ppp-numbers + * for the up-to-date information. + */ -/* Standard PPP printer */ -void -ppp_if_print(u_char *user, const struct pcap_pkthdr *h, - register const u_char *p) +/* Protocol Codes defined in ppp.h */ + +struct tok ppptype2str[] = { + { PPP_IP, "IP" }, + { PPP_OSI, "OSI" }, + { PPP_NS, "NS" }, + { PPP_DECNET, "DECNET" }, + { PPP_APPLE, "APPLE" }, + { PPP_IPX, "IPX" }, + { PPP_VJC, "VJC" }, + { PPP_VJNC, "VJNC" }, + { PPP_BRPDU, "BRPDU" }, + { PPP_STII, "STII" }, + { PPP_VINES, "VINES" }, + { PPP_MPLS_UCAST, "MPLS" }, + { PPP_MPLS_MCAST, "MPLS" }, + + { PPP_HELLO, "HELLO" }, + { PPP_LUXCOM, "LUXCOM" }, + { PPP_SNS, "SNS" }, + { PPP_IPCP, "IPCP" }, + { PPP_OSICP, "OSICP" }, + { PPP_NSCP, "NSCP" }, + { PPP_DECNETCP, "DECNETCP" }, + { PPP_APPLECP, "APPLECP" }, + { PPP_IPXCP, "IPXCP" }, + { PPP_STIICP, "STIICP" }, + { PPP_VINESCP, "VINESCP" }, + { PPP_MPLSCP, "MPLSCP" }, + + { PPP_LCP, "LCP" }, + { PPP_PAP, "PAP" }, + { PPP_LQM, "LQM" }, + { PPP_CHAP, "CHAP" }, + { PPP_BACP, "BACP" }, + { PPP_BAP, "BAP" }, + { PPP_MP, "ML" }, + { 0, NULL } +}; + +/* Control Protocols (LCP/IPCP/CCP etc.) Codes defined in RFC 1661 */ + +#define CPCODES_VEXT 0 /* Vendor-Specific (RFC2153) */ +#define CPCODES_CONF_REQ 1 /* Configure-Request */ +#define CPCODES_CONF_ACK 2 /* Configure-Ack */ +#define CPCODES_CONF_NAK 3 /* Configure-Nak */ +#define CPCODES_CONF_REJ 4 /* Configure-Reject */ +#define CPCODES_TERM_REQ 5 /* Terminate-Request */ +#define CPCODES_TERM_ACK 6 /* Terminate-Ack */ +#define CPCODES_CODE_REJ 7 /* Code-Reject */ +#define CPCODES_PROT_REJ 8 /* Protocol-Reject (LCP only) */ +#define CPCODES_ECHO_REQ 9 /* Echo-Request (LCP only) */ +#define CPCODES_ECHO_RPL 10 /* Echo-Reply (LCP only) */ +#define CPCODES_DISC_REQ 11 /* Discard-Request (LCP only) */ +#define CPCODES_ID 12 /* Identification (LCP only) RFC1570 */ +#define CPCODES_TIME_REM 13 /* Time-Remaining (LCP only) RFC1570 */ +#define CPCODES_RESET_REQ 14 /* Reset-Request (CCP only) RFC1962 */ +#define CPCODES_RESET_REP 15 /* Reset-Reply (CCP only) */ + +struct tok cpcodes[] = { + {CPCODES_VEXT, "Vendor-Extension"}, /* RFC2153 */ + {CPCODES_CONF_REQ, "Conf-Request"}, + {CPCODES_CONF_ACK, "Conf-Ack"}, + {CPCODES_CONF_NAK, "Conf-Nack"}, + {CPCODES_CONF_REJ, "Conf-Reject"}, + {CPCODES_TERM_REQ, "Term-Request"}, + {CPCODES_TERM_ACK, "Term-Ack"}, + {CPCODES_CODE_REJ, "Code-Reject"}, + {CPCODES_PROT_REJ, "Prot-Reject"}, + {CPCODES_ECHO_REQ, "Echo-Request"}, + {CPCODES_ECHO_RPL, "Echo-Reply"}, + {CPCODES_DISC_REQ, "Disc-Req"}, + {CPCODES_ID, "Ident"}, /* RFC1570 */ + {CPCODES_TIME_REM, "Time-Rem"}, /* RFC1570 */ + {CPCODES_RESET_REQ, "Reset-Req"}, /* RFC1962 */ + {CPCODES_RESET_REP, "Reset-Ack"}, /* RFC1962 */ + {0, NULL} +}; + +/* LCP Config Options */ + +#define LCPOPT_VEXT 0 +#define LCPOPT_MRU 1 +#define LCPOPT_ACCM 2 +#define LCPOPT_AP 3 +#define LCPOPT_QP 4 +#define LCPOPT_MN 5 +#define LCPOPT_DEP6 6 +#define LCPOPT_PFC 7 +#define LCPOPT_ACFC 8 +#define LCPOPT_FCSALT 9 +#define LCPOPT_SDP 10 +#define LCPOPT_NUMMODE 11 +#define LCPOPT_DEP12 12 +#define LCPOPT_CBACK 13 +#define LCPOPT_DEP14 14 +#define LCPOPT_DEP15 15 +#define LCPOPT_DEP16 16 +#define LCPOPT_MLMRRU 17 +#define LCPOPT_MLSSNHF 18 +#define LCPOPT_MLED 19 +#define LCPOPT_PROP 20 +#define LCPOPT_DCEID 21 +#define LCPOPT_MPP 22 +#define LCPOPT_LD 23 +#define LCPOPT_LCPAOPT 24 +#define LCPOPT_COBS 25 +#define LCPOPT_PE 26 +#define LCPOPT_MLHF 27 +#define LCPOPT_I18N 28 +#define LCPOPT_SDLOS 29 +#define LCPOPT_PPPMUX 30 + +#define LCPOPT_MIN LCPOPT_VEXT +#define LCPOPT_MAX LCPOPT_PPPMUX + +static const char *lcpconfopts[] = { + "Vend-Ext", /* (0) */ + "MRU", /* (1) */ + "ACCM", /* (2) */ + "Auth-Prot", /* (3) */ + "Qual-Prot", /* (4) */ + "Magic-Num", /* (5) */ + "deprecated(6)", /* used to be a Quality Protocol */ + "PFC", /* (7) */ + "ACFC", /* (8) */ + "FCS-Alt", /* (9) */ + "SDP", /* (10) */ + "Num-Mode", /* (11) */ + "deprecated(12)", /* used to be a Multi-Link-Procedure*/ + "Call-Back", /* (13) */ + "deprecated(14)", /* used to be a Connect-Time */ + "deprecated(15)", /* used to be a Compund-Frames */ + "deprecated(16)", /* used to be a Nominal-Data-Encap */ + "MRRU", /* (17) */ + "SSNHF", /* (18) */ + "End-Disc", /* (19) */ + "Proprietary", /* (20) */ + "DCE-Id", /* (21) */ + "MP+", /* (22) */ + "Link-Disc", /* (23) */ + "LCP-Auth-Opt", /* (24) */ + "COBS", /* (25) */ + "Prefix-elision", /* (26) */ + "Multilink-header-Form",/* (27) */ + "I18N", /* (28) */ + "SDL-over-SONET/SDH", /* (29) */ + "PPP-Muxing", /* (30) */ +}; + +/* IPV6CP - to be supported */ +/* ECP - to be supported */ + +/* CCP Config Options */ + +#define CCPOPT_OUI 0 /* RFC1962 */ +#define CCPOPT_PRED1 1 /* RFC1962 */ +#define CCPOPT_PRED2 2 /* RFC1962 */ +#define CCPOPT_PJUMP 3 /* RFC1962 */ +/* 4-15 unassigned */ +#define CCPOPT_HPPPC 16 /* RFC1962 */ +#define CCPOPT_STACLZS 17 /* RFC1974 */ +#define CCPOPT_MPPC 18 /* RFC2118 */ +#define CCPOPT_GFZA 19 /* RFC1962 */ +#define CCPOPT_V42BIS 20 /* RFC1962 */ +#define CCPOPT_BSDCOMP 21 /* RFC1977 */ +/* 22 unassigned */ +#define CCPOPT_LZSDCP 23 /* RFC1967 */ +#define CCPOPT_MVRCA 24 /* RFC1975 */ +#define CCPOPT_DEC 25 /* RFC1976 */ +#define CCPOPT_DEFLATE 26 /* RFC1979 */ +/* 27-254 unassigned */ +#define CCPOPT_RESV 255 /* RFC1962 */ + +#define CCPOPT_MIN CCPOPT_OUI +#define CCPOPT_MAX CCPOPT_DEFLATE /* XXX: should be CCPOPT_RESV but... */ + +static const char *ccpconfopts[] = { + "OUI", /* (0) */ + "Pred-1", /* (1) */ + "Pred-2", /* (2) */ + "Puddle", /* (3) */ + "unassigned(4)", /* (4) */ + "unassigned(5)", /* (5) */ + "unassigned(6)", /* (6) */ + "unassigned(7)", /* (7) */ + "unassigned(8)", /* (8) */ + "unassigned(9)", /* (9) */ + "unassigned(10)", /* (10) */ + "unassigned(11)", /* (11) */ + "unassigned(12)", /* (12) */ + "unassigned(13)", /* (13) */ + "unassigned(14)", /* (14) */ + "unassigned(15)", /* (15) */ + "HP-PPC", /* (16) */ + "Stac-LZS", /* (17) */ + "MPPC", /* (18) */ + "Gand-FZA", /* (19) */ + "V.42bis", /* (20) */ + "BSD-Comp", /* (21) */ + "unassigned(22)", /* (22) */ + "LZS-DCP", /* (23) */ + "MVRCA", /* (24) */ + "DEC", /* (25) */ + "Deflate", /* (26) */ +}; + +/* BACP Config Options */ + +#define BACPOPT_FPEER 1 /* RFC2125 */ + +/* SDCP - to be supported */ + +/* IPCP Config Options */ + +#define IPCPOPT_2ADDR 1 /* RFC1172, RFC1332 (deprecated) */ +#define IPCPOPT_IPCOMP 2 /* RFC1332 */ +#define IPCPOPT_ADDR 3 /* RFC1332 */ +#define IPCPOPT_MOBILE4 4 /* RFC2290 */ + +#define IPCPOPT_PRIDNS 129 /* RFC1877 */ +#define IPCPOPT_PRINBNS 130 /* RFC1877 */ +#define IPCPOPT_SECDNS 131 /* RFC1877 */ +#define IPCPOPT_SECNBNS 132 /* RFC1877 */ + +/* ATCP - to be supported */ +/* OSINLCP - to be supported */ +/* BVCP - to be supported */ +/* BCP - to be supported */ +/* IPXCP - to be supported */ +/* MPLSCP - to be supported */ + +/* Auth Algorithms */ + +/* 0-4 Reserved (RFC1994) */ +#define AUTHALG_CHAPMD5 5 /* RFC1994 */ +#define AUTHALG_MSCHAP1 128 /* RFC2433 */ +#define AUTHALG_MSCHAP2 129 /* RFC2795 */ + +/* FCS Alternatives - to be supported */ + +/* Multilink Endpoint Discriminator (RFC1717) */ +#define MEDCLASS_NULL 0 /* Null Class */ +#define MEDCLASS_LOCAL 1 /* Locally Assigned */ +#define MEDCLASS_IPV4 2 /* Internet Protocol (IPv4) */ +#define MEDCLASS_MAC 3 /* IEEE 802.1 global MAC address */ +#define MEDCLASS_MNB 4 /* PPP Magic Number Block */ +#define MEDCLASS_PSNDN 5 /* Public Switched Network Director Number */ + +/* PPP LCP Callback */ +#define CALLBACK_AUTH 0 /* Location determined by user auth */ +#define CALLBACK_DSTR 1 /* Dialing string */ +#define CALLBACK_LID 2 /* Location identifier */ +#define CALLBACK_E164 3 /* E.164 number */ +#define CALLBACK_X500 4 /* X.500 distinguished name */ +#define CALLBACK_CBCP 6 /* Location is determined during CBCP nego */ + +/* CHAP */ + +#define CHAP_CHAL 1 +#define CHAP_RESP 2 +#define CHAP_SUCC 3 +#define CHAP_FAIL 4 + +#define CHAP_CODEMIN CHAP_CHAL +#define CHAP_CODEMAX CHAP_FAIL + +static const char *chapcode[] = { + "Chal", /* (1) */ + "Resp", /* (2) */ + "Succ", /* (3) */ + "Fail", /* (4) */ +}; + +/* PAP */ + +#define PAP_AREQ 1 +#define PAP_AACK 2 +#define PAP_ANAK 3 + +#define PAP_CODEMIN PAP_AREQ +#define PAP_CODEMAX PAP_ANAK + +static const char *papcode[] = { + "Auth-Req", /* (1) */ + "Auth-Ack", /* (2) */ + "Auth-Nak", /* (3) */ +}; + +/* BAP */ +#define BAP_CALLREQ 1 +#define BAP_CALLRES 2 +#define BAP_CBREQ 3 +#define BAP_CBRES 4 +#define BAP_LDQREQ 5 +#define BAP_LDQRES 6 +#define BAP_CSIND 7 +#define BAP_CSRES 8 + +static void handle_ctrl_proto (u_int proto,const u_char *p, int length); +static void handle_chap (const u_char *p, int length); +static void handle_pap (const u_char *p, int length); +static void handle_bap (const u_char *p, int length); +static int print_lcp_config_options (const u_char *p, int); +static int print_ipcp_config_options (const u_char *p, int); +static int print_ccp_config_options (const u_char *p, int); +static int print_bacp_config_options (const u_char *p, int); +static void handle_ppp (u_int proto, const u_char *p, int length); + +/* generic Control Protocol (e.g. LCP, IPCP, CCP, etc.) handler */ +static void +handle_ctrl_proto(u_int proto, const u_char *pptr, int length) { - register u_int length = h->len; - register u_int caplen = h->caplen; - const struct ip *ip; - u_int proto; + const char *typestr; + u_int code, len; + int (*pfunc)(const u_char *, int); + int x, j; + const u_char *tptr; - ts_print(&h->ts); + tptr=pptr; - if (caplen < PPP_HDRLEN) { - printf("[|ppp]"); - goto out; + typestr = tok2str(ppptype2str, "unknown", proto); + printf("%s, ",typestr); + + if (length < 4) /* FIXME weak boundary checking */ + goto trunc; + TCHECK2(*tptr, 2); + + code = *tptr++; + + printf("%s (0x%02x), id %u", + tok2str(cpcodes, "Unknown Opcode",code), + code, + *tptr++); /* ID */ + + TCHECK2(*tptr, 2); + len = EXTRACT_16BITS(tptr); + tptr += 2; + + if (length <= 4) + return; /* there may be a NULL confreq etc. */ + + switch (code) { + case CPCODES_VEXT: + if (length < 11) + break; + TCHECK2(*tptr, 4); + printf(", Magic-Num 0x%08x", EXTRACT_32BITS(tptr)); + tptr += 4; + TCHECK2(*tptr, 3); + printf(" OUI 0x%06x", EXTRACT_24BITS(tptr)); + /* XXX: need to decode Kind and Value(s)? */ + break; + case CPCODES_CONF_REQ: + case CPCODES_CONF_ACK: + case CPCODES_CONF_NAK: + case CPCODES_CONF_REJ: + x = len - 4; /* Code(1), Identifier(1) and Length(2) */ + do { + switch (proto) { + case PPP_LCP: + pfunc = print_lcp_config_options; + break; + case PPP_IPCP: + pfunc = print_ipcp_config_options; + break; + case PPP_CCP: + pfunc = print_ccp_config_options; + break; + case PPP_BACP: + pfunc = print_bacp_config_options; + break; + default: + /* + * This should never happen, but we set + * "pfunc" to squelch uninitialized + * variable warnings from compilers. + */ + pfunc = NULL; + break; + } + if ((j = (*pfunc)(tptr, len)) == 0) + break; + x -= j; + tptr += j; + } while (x > 0); + break; + + case CPCODES_TERM_REQ: + case CPCODES_TERM_ACK: + /* XXX: need to decode Data? */ + break; + case CPCODES_CODE_REJ: + /* XXX: need to decode Rejected-Packet? */ + break; + case CPCODES_PROT_REJ: + if (length < 6) + break; + TCHECK2(*tptr, 2); + printf(", Rejected %s Protocol (0x%04x)", + tok2str(ppptype2str,"unknown", EXTRACT_16BITS(tptr)), + EXTRACT_16BITS(tptr)); + /* XXX: need to decode Rejected-Information? */ + break; + case CPCODES_ECHO_REQ: + case CPCODES_ECHO_RPL: + case CPCODES_DISC_REQ: + case CPCODES_ID: + if (length < 8) + break; + TCHECK2(*tptr, 4); + printf(", Magic-Num 0x%08x", EXTRACT_32BITS(tptr)); + /* XXX: need to decode Data? */ + break; + case CPCODES_TIME_REM: + if (length < 12) + break; + TCHECK2(*tptr, 4); + printf(", Magic-Num 0x%08x", EXTRACT_32BITS(tptr)); + TCHECK2(*(tptr + 4), 4); + printf(", Seconds-Remaining %us", EXTRACT_32BITS(tptr + 4)); + /* XXX: need to decode Message? */ + break; + default: + /* XXX this is dirty but we do not get the + * original pointer passed to the begin + * the PPP packet */ + if (vflag <= 1) + print_unknown_data(pptr-2,"\n\t",length+2); + break; + } + printf(", length %u", length); + + if (vflag >1) + print_unknown_data(pptr-2,"\n\t",length+2); + return; + +trunc: + printf("[|%s]", typestr); +} + +/* LCP config options */ +static int +print_lcp_config_options(const u_char *p, int length) +{ + int len, opt; + + if (length < 2) + return 0; + TCHECK2(*p, 2); + len = p[1]; + opt = p[0]; + if (length < len) + return 0; + if ((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX)) + printf(", %s ", lcpconfopts[opt]); + else { + printf(", unknown LCP option 0x%02x", opt); + return len; + } + + switch (opt) { + case LCPOPT_VEXT: + if (len >= 6) { + TCHECK2(*(p + 2), 3); + printf(" OUI 0x%06x", EXTRACT_24BITS(p+2)); +#if 0 + TCHECK(p[5]); + printf(" kind 0x%02x", p[5]); + printf(" val 0x") + for (i = 0; i < len - 6; i++) { + TCHECK(p[6 + i]); + printf("%02x", p[6 + i]); + } +#endif + } + break; + case LCPOPT_MRU: + if (len == 4) { + TCHECK2(*(p + 2), 2); + printf(" %u", EXTRACT_16BITS(p + 2)); + } + break; + case LCPOPT_ACCM: + if (len == 6) { + TCHECK2(*(p + 2), 4); + printf(" %08x", EXTRACT_32BITS(p + 2)); + } + break; + case LCPOPT_AP: + if (len >= 4) { + TCHECK2(*(p + 2), 2); + switch (EXTRACT_16BITS(p+2)) { + case PPP_PAP: + printf(" PAP"); + break; + case PPP_CHAP: + printf(" CHAP"); + TCHECK(p[4]); + switch (p[4]) { + default: + printf(", unknown-algorithm-%u", p[4]); + break; + case AUTHALG_CHAPMD5: + printf(", MD5"); + break; + case AUTHALG_MSCHAP1: + printf(", MSCHAPv1"); + break; + case AUTHALG_MSCHAP2: + printf(", MSCHAPv2"); + break; + } + break; + case PPP_EAP: + printf(" EAP"); + break; + case PPP_SPAP: + printf(" SPAP"); + break; + case PPP_SPAP_OLD: + printf(" Old-SPAP"); + break; + default: + printf("unknown"); + } + } + break; + case LCPOPT_QP: + if (len >= 4) { + TCHECK2(*(p + 2), 2); + if (EXTRACT_16BITS(p+2) == PPP_LQM) + printf(" LQR"); + else + printf(" unknown"); + } + break; + case LCPOPT_MN: + if (len == 6) { + TCHECK2(*(p + 2), 4); + printf(" 0x%08x", EXTRACT_32BITS(p + 2)); + } + break; + case LCPOPT_PFC: + break; + case LCPOPT_ACFC: + break; + case LCPOPT_LD: + if (len == 4) { + TCHECK2(*(p + 2), 2); + printf(" 0x%04x", EXTRACT_16BITS(p + 2)); + } + break; + case LCPOPT_CBACK: + if (len < 3) + break; + TCHECK(p[2]); + switch (p[2]) { /* Operation */ + case CALLBACK_AUTH: + printf(" UserAuth"); + break; + case CALLBACK_DSTR: + printf(" DialString"); + break; + case CALLBACK_LID: + printf(" LocalID"); + break; + case CALLBACK_E164: + printf(" E.164"); + break; + case CALLBACK_X500: + printf(" X.500"); + break; + case CALLBACK_CBCP: + printf(" CBCP"); + break; + default: + printf(" unknown-operation=%u", p[2]); + break; + } + break; + case LCPOPT_MLMRRU: + if (len == 4) { + TCHECK2(*(p + 2), 2); + printf(" %u", EXTRACT_16BITS(p + 2)); + } + break; + case LCPOPT_MLED: + if (len < 3) + break; + TCHECK(p[2]); + switch (p[2]) { /* class */ + case MEDCLASS_NULL: + printf(" Null"); + break; + case MEDCLASS_LOCAL: + printf(" Local"); /* XXX */ + break; + case MEDCLASS_IPV4: + if (len != 7) + break; + TCHECK2(*(p + 3), 4); + printf(" IPv4 %s", ipaddr_string(p + 3)); + break; + case MEDCLASS_MAC: + if (len != 9) + break; + TCHECK(p[8]); + printf(" MAC %02x:%02x:%02x:%02x:%02x:%02x", + p[3], p[4], p[5], p[6], p[7], p[8]); + break; + case MEDCLASS_MNB: + printf(" Magic-Num-Block"); /* XXX */ + break; + case MEDCLASS_PSNDN: + printf(" PSNDN"); /* XXX */ + break; + } + break; + +/* XXX: to be supported */ +#if 0 + case LCPOPT_DEP6: + case LCPOPT_FCSALT: + case LCPOPT_SDP: + case LCPOPT_NUMMODE: + case LCPOPT_DEP12: + case LCPOPT_DEP14: + case LCPOPT_DEP15: + case LCPOPT_DEP16: + case LCPOPT_MLSSNHF: + case LCPOPT_PROP: + case LCPOPT_DCEID: + case LCPOPT_MPP: + case LCPOPT_LCPAOPT: + case LCPOPT_COBS: + case LCPOPT_PE: + case LCPOPT_MLHF: + case LCPOPT_I18N: + case LCPOPT_SDLOS: + case LCPOPT_PPPMUX: + break; +#endif } + return len; + +trunc: + printf("[|lcp]"); + return 0; +} + +/* CHAP */ +static void +handle_chap(const u_char *p, int length) +{ + u_int code, len; + int val_size, name_size, msg_size; + const u_char *p0; + int i; + + p0 = p; + if (length < 1) { + printf("[|chap]"); + return; + } else if (length < 4) { + TCHECK(*p); + printf("[|chap 0x%02x]", *p); + return; + } + + TCHECK(*p); + code = *p; + if ((code >= CHAP_CODEMIN) && (code <= CHAP_CODEMAX)) + printf("%s", chapcode[code - 1]); + else { + printf("0x%02x", code); + return; + } + p++; + + TCHECK(*p); + printf("(%u)", *p); /* ID */ + p++; + + TCHECK2(*p, 2); + len = EXTRACT_16BITS(p); + p += 2; /* - * 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. + * Note that this is a generic CHAP decoding routine. Since we + * don't know which flavor of CHAP (i.e. CHAP-MD5, MS-CHAPv1, + * MS-CHAPv2) is used at this point, we can't decode packet + * specifically to each algorithms. Instead, we simply decode + * the GCD (Gratest Common Denominator) for all algorithms. */ - proto = ntohs(*(u_short *)&p[2]); - packetp = p; - snapend = p + caplen; + switch (code) { + case CHAP_CHAL: + case CHAP_RESP: + if (length - (p - p0) < 1) + return; + TCHECK(*p); + val_size = *p; /* value size */ + p++; + if (length - (p - p0) < val_size) + return; + printf(", Value "); + for (i = 0; i < val_size; i++) { + TCHECK(*p); + printf("%02x", *p++); + } + name_size = len - (p - p0); + printf(", Name "); + for (i = 0; i < name_size; i++) { + TCHECK(*p); + safeputchar(*p++); + } + break; + case CHAP_SUCC: + case CHAP_FAIL: + msg_size = len - (p - p0); + printf(", Msg "); + for (i = 0; i< msg_size; i++) { + TCHECK(*p); + safeputchar(*p++); + } + break; + } + return; - if (eflag) - printf("%c %4d %02x %04x: ", p[0] ? 'O' : 'I', length, - p[1], proto); +trunc: + printf("[|chap]"); +} + +/* PAP (see RFC 1334) */ +static void +handle_pap(const u_char *p, int length) +{ + u_int code, len; + int peerid_len, passwd_len, msg_len; + const u_char *p0; + int i; + + p0 = p; + if (length < 1) { + printf("[|pap]"); + return; + } else if (length < 4) { + TCHECK(*p); + printf("[|pap 0x%02x]", *p); + return; + } + + TCHECK(*p); + code = *p; + if ((code >= PAP_CODEMIN) && (code <= PAP_CODEMAX)) + printf("%s", papcode[code - 1]); + else { + printf("0x%02x", code); + return; + } + p++; + + TCHECK(*p); + printf("(%u)", *p); /* ID */ + p++; + + TCHECK2(*p, 2); + len = EXTRACT_16BITS(p); + p += 2; + + switch (code) { + case PAP_AREQ: + if (length - (p - p0) < 1) + return; + TCHECK(*p); + peerid_len = *p; /* Peer-ID Length */ + p++; + if (length - (p - p0) < peerid_len) + return; + printf(", Peer "); + for (i = 0; i < peerid_len; i++) { + TCHECK(*p); + safeputchar(*p++); + } + + if (length - (p - p0) < 1) + return; + TCHECK(*p); + passwd_len = *p; /* Password Length */ + p++; + if (length - (p - p0) < passwd_len) + return; + printf(", Name "); + for (i = 0; i < passwd_len; i++) { + TCHECK(*p); + safeputchar(*p++); + } + break; + case PAP_AACK: + case PAP_ANAK: + if (length - (p - p0) < 1) + return; + TCHECK(*p); + msg_len = *p; /* Msg-Length */ + p++; + if (length - (p - p0) < msg_len) + return; + printf(", Msg "); + for (i = 0; i< msg_len; i++) { + TCHECK(*p); + safeputchar(*p++); + } + break; + } + return; + +trunc: + printf("[|pap]"); +} + +/* BAP */ +static void +handle_bap(const u_char *p _U_, int length _U_) +{ + /* XXX: to be supported!! */ +} + + +/* IPCP config options */ +static int +print_ipcp_config_options(const u_char *p, int length) +{ + int len, opt; + + if (length < 2) + return 0; + TCHECK2(*p, 2); + len = p[1]; + opt = p[0]; + if (length < len) + return 0; + switch (opt) { + case IPCPOPT_2ADDR: /* deprecated */ + if (len != 10) + goto invlen; + TCHECK2(*(p + 6), 4); + printf(", IP-Addrs src %s, dst %s", + ipaddr_string(p + 2), + ipaddr_string(p + 6)); + break; + case IPCPOPT_IPCOMP: + if (len < 4) + goto invlen; + printf(", IP-Comp"); + TCHECK2(*(p + 2), 2); + if (EXTRACT_16BITS(p + 2) == PPP_VJC) { + printf(" VJ-Comp"); + /* XXX: VJ-Comp parameters should be decoded */ + } else + printf(" unknown-comp-proto=%04x", EXTRACT_16BITS(p + 2)); + break; + case IPCPOPT_ADDR: + if (len != 6) + goto invlen; + TCHECK2(*(p + 2), 4); + printf(", IP-Addr %s", ipaddr_string(p + 2)); + break; + case IPCPOPT_MOBILE4: + if (len != 6) + goto invlen; + TCHECK2(*(p + 2), 4); + printf(", Home-Addr %s", ipaddr_string(p + 2)); + break; + case IPCPOPT_PRIDNS: + if (len != 6) + goto invlen; + TCHECK2(*(p + 2), 4); + printf(", Pri-DNS %s", ipaddr_string(p + 2)); + break; + case IPCPOPT_PRINBNS: + if (len != 6) + goto invlen; + TCHECK2(*(p + 2), 4); + printf(", Pri-NBNS %s", ipaddr_string(p + 2)); + break; + case IPCPOPT_SECDNS: + if (len != 6) + goto invlen; + TCHECK2(*(p + 2), 4); + printf(", Sec-DNS %s", ipaddr_string(p + 2)); + break; + case IPCPOPT_SECNBNS: + if (len != 6) + goto invlen; + TCHECK2(*(p + 2), 4); + printf(", Sec-NBNS %s", ipaddr_string(p + 2)); + break; + default: + printf(", unknown-%d", opt); + break; + } + return len; + +invlen: + printf(", invalid-length-%d", opt); + return 0; + +trunc: + printf("[|ipcp]"); + return 0; +} + +/* CCP config options */ +static int +print_ccp_config_options(const u_char *p, int length) +{ + int len, opt; + + if (length < 2) + return 0; + TCHECK2(*p, 2); + len = p[1]; + opt = p[0]; + if (length < len) + return 0; + if ((opt >= CCPOPT_MIN) && (opt <= CCPOPT_MAX)) + printf(", %s", ccpconfopts[opt]); +#if 0 /* XXX */ + switch (opt) { + case CCPOPT_OUI: + case CCPOPT_PRED1: + case CCPOPT_PRED2: + case CCPOPT_PJUMP: + case CCPOPT_HPPPC: + case CCPOPT_STACLZS: + case CCPOPT_MPPC: + case CCPOPT_GFZA: + case CCPOPT_V42BIS: + case CCPOPT_BSDCOMP: + case CCPOPT_LZSDCP: + case CCPOPT_MVRCA: + case CCPOPT_DEC: + case CCPOPT_DEFLATE: + case CCPOPT_RESV: + break; + + default: + printf(", unknown-%d", opt); + break; + } +#endif + return len; + +trunc: + printf("[|ccp]"); + return 0; +} + +/* BACP config options */ +static int +print_bacp_config_options(const u_char *p, int length) +{ + int len, opt; - length -= PPP_HDRLEN; - ip = (struct ip *)(p + PPP_HDRLEN); + if (length < 2) + return 0; + TCHECK2(*p, 2); + len = p[1]; + opt = p[0]; + if (length < len) + return 0; + if (opt == BACPOPT_FPEER) { + TCHECK2(*(p + 2), 4); + printf(", Favored-Peer"); + printf(", Magic-Num 0x%08x", EXTRACT_32BITS(p + 2)); + } else { + printf(", unknown-option-%d", opt); + } + return len; + +trunc: + printf("[|bacp]"); + return 0; +} + + +/* PPP */ +static void +handle_ppp(u_int proto, const u_char *p, int length) +{ switch (proto) { - case ETHERTYPE_IP: + case PPP_LCP: + case PPP_IPCP: + case PPP_OSICP: + case PPP_MPLSCP: + case PPP_IPV6CP: + case PPP_CCP: + case PPP_BACP: + handle_ctrl_proto(proto, p, length); + break; + case PPP_CHAP: + handle_chap(p, length); + break; + case PPP_PAP: + handle_pap(p, length); + break; + case PPP_BAP: /* XXX: not yet completed */ + handle_bap(p, length); + break; + case ETHERTYPE_IP: /*XXX*/ case PPP_IP: - ip_print((const u_char *)ip, length); + ip_print(p, length); break; #ifdef INET6 - case ETHERTYPE_IPV6: - ip6_print((const u_char *)ip, length); + case ETHERTYPE_IPV6: /*XXX*/ + case PPP_IPV6: + ip6_print(p, length); break; #endif + case ETHERTYPE_IPX: /*XXX*/ + case PPP_IPX: + ipx_print(p, length); + break; + case PPP_OSI: + isoclns_print(p, length, length); + break; + case PPP_MPLS_UCAST: + case PPP_MPLS_MCAST: + mpls_print(p, length); + break; + default: + printf("unknown PPP protocol (0x%04x)", proto); + print_unknown_data(p,"\n\t",length); + break; } - if (xflag) - default_print((const u_char *)ip, caplen - PPP_HDRLEN); -out: - putchar('\n'); } -#ifdef __bsdi__ -/* proto type to string mapping */ -static struct tok ptype2str[] = { - { PPP_VJC, "VJC" }, - { PPP_VJNC, "VJNC" }, - { PPP_OSI, "OSI" }, - { PPP_LCP, "LCP" }, - { PPP_IPCP, "IPCP" }, - { 0, NULL } -}; +/* Standard PPP printer */ +u_int +ppp_print(register const u_char *p, u_int length) +{ + u_int proto; + u_int olen = length; /* _o_riginal length */ + u_int hdr_len = 0; + + /* + * Here, we assume that p points to the Address and Control + * field (if they present). + */ + if (length < 2) + goto trunc; + TCHECK2(*p, 2); + if (*p == PPP_ADDRESS && *(p + 1) == PPP_CONTROL) { + p += 2; /* ACFC not used */ + length -= 2; + hdr_len += 2; + } + + if (length < 2) + goto trunc; + TCHECK(*p); + if (*p % 2) { + proto = *p; /* PFC is used */ + p++; + length--; + hdr_len++; + } else { + TCHECK2(*p, 2); + proto = EXTRACT_16BITS(p); + p += 2; + length -= 2; + hdr_len += 2; + } + + if (eflag) + printf("PPP-%s (0x%04x), length %u: ", + tok2str(ppptype2str, "unknown", proto), + proto, + olen); + + handle_ppp(proto, p, length); + return (hdr_len); +trunc: + printf("[|ppp]"); + return (0); +} + + +/* PPP I/F printer */ +u_int +ppp_if_print(const struct pcap_pkthdr *h, register const u_char *p) +{ + register u_int length = h->len; + register u_int caplen = h->caplen; + + if (caplen < PPP_HDRLEN) { + printf("[|ppp]"); + return (caplen); + } + +#if 0 + /* + * XXX: seems to assume that there are 2 octets prepended to an + * actual PPP frame. The 1st octet looks like Input/Output flag + * while 2nd octet is unknown, at least to me + * (mshindo@mshindo.net). + * + * That was what the original tcpdump code did. + * + * FreeBSD's "if_ppp.c" *does* set the first octet to 1 for outbound + * packets and 0 for inbound packets - but only if the + * protocol field has the 0x8000 bit set (i.e., it's a network + * control protocol); it does so before running the packet through + * "bpf_filter" to see if it should be discarded, and to see + * if we should update the time we sent the most recent packet... + * + * ...but it puts the original address field back after doing + * so. + * + * NetBSD's "if_ppp.c" doesn't set the first octet in that fashion. + * + * I don't know if any PPP implementation handed up to a BPF + * device packets with the first octet being 1 for outbound and + * 0 for inbound packets, so I (guy@alum.mit.edu) don't know + * whether that ever needs to be checked or not. + * + * Note that NetBSD has a DLT_PPP_SERIAL, which it uses for PPP, + * and its tcpdump appears to assume that the frame always + * begins with an address field and a control field, and that + * the address field might be 0x0f or 0x8f, for Cisco + * point-to-point with HDLC framing as per section 4.3.1 of RFC + * 1547, as well as 0xff, for PPP in HDLC-like framing as per + * RFC 1662. + * + * (Is the Cisco framing in question what DLT_C_HDLC, in + * BSD/OS, is?) + */ + if (eflag) + printf("%c %4d %02x ", p[0] ? 'O' : 'I', length, p[1]); #endif + ppp_print(p, length); + + return (0); +} + +/* + * PPP I/F printer to use if we know that RFC 1662-style PPP in HDLC-like + * framing, or Cisco PPP with HDLC framing as per section 4.3.1 of RFC 1547, + * is being used (i.e., we don't check for PPP_ADDRESS and PPP_CONTROL, + * discard them *if* those are the first two octets, and parse the remaining + * packet as a PPP packet, as "ppp_print()" does). + * + * This handles, for example, DLT_PPP_SERIAL in NetBSD. + */ +u_int +ppp_hdlc_if_print(const struct pcap_pkthdr *h, register const u_char *p) +{ + register u_int length = h->len; + register u_int caplen = h->caplen; + u_int proto; + u_int hdrlen = 0; + + if (caplen < 2) { + printf("[|ppp]"); + return (caplen); + } + + switch (p[0]) { + + case PPP_ADDRESS: + if (caplen < 4) { + printf("[|ppp]"); + return (caplen); + } + + if (eflag) + printf("%02x %02x %d ", p[0], p[1], length); + p += 2; + length -= 2; + hdrlen += 2; + + proto = EXTRACT_16BITS(p); + p += 2; + length -= 2; + hdrlen += 2; + printf("%s: ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", proto)); + + handle_ppp(proto, p, length); + break; + + case CHDLC_UNICAST: + case CHDLC_BCAST: + return (chdlc_if_print(h, p)); + + default: + if (eflag) + printf("%02x %02x %d ", p[0], p[1], length); + p += 2; + length -= 2; + hdrlen += 2; + + /* + * XXX - NetBSD's "ppp_netbsd_serial_if_print()" treats + * the next two octets as an Ethernet type; does that + * ever happen? + */ + printf("unknown addr %02x; ctrl %02x", p[0], p[1]); + break; + } + + return (hdrlen); +} + #define PPP_BSDI_HDRLEN 24 /* BSD/OS specific PPP printer */ -void -ppp_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, - register const u_char *p) +u_int +ppp_bsdos_if_print(const struct pcap_pkthdr *h _U_, register const u_char *p _U_) { + register int hdrlength; #ifdef __bsdi__ register u_int length = h->len; register u_int caplen = h->caplen; - register int hdrlength; - u_short ptype; + u_int16_t ptype; const u_char *q; int i; - ts_print(&h->ts); - if (caplen < PPP_BSDI_HDRLEN) { printf("[|ppp]"); - goto out; + return (caplen) } - /* - * 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; hdrlength = 0; #if 0 if (p[0] == PPP_ADDRESS && p[1] == PPP_CONTROL) { - if (eflag) + if (eflag) printf("%02x %02x ", p[0], p[1]); p += 2; hdrlength = 2; } - if (eflag) + if (eflag) printf("%d ", length); /* Retrieve the protocol type */ if (*p & 01) { /* Compressed protocol field */ ptype = *p; - if (eflag) + if (eflag) printf("%02x ", ptype); p++; hdrlength += 1; } else { /* Un-compressed protocol field */ - ptype = ntohs(*(u_short *)p); - if (eflag) + ptype = ntohs(*(u_int16_t *)p); + if (eflag) printf("%04x ", ptype); p += 2; hdrlength += 2; @@ -187,11 +1334,11 @@ ppp_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, ph = (struct ppp_header *)q; if (ph->phdr_addr == PPP_ADDRESS && ph->phdr_ctl == PPP_CONTROL) { - if (eflag) + if (eflag) printf("%02x %02x ", q[0], q[1]); ptype = ntohs(ph->phdr_type); if (eflag && (ptype == PPP_VJC || ptype == PPP_VJNC)) { - printf("%s ", tok2str(ptype2str, + printf("%s ", tok2str(ppptype2str, "proto-#%d", ptype)); } } else { @@ -202,26 +1349,50 @@ ppp_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, printf("] "); } } - if (eflag) - printf("%d ", length); } + if (eflag) + printf("%d ", length); if (p[SLC_CHL]) { q = p + SLC_BPFHDRLEN + p[SLC_LLHL]; switch (ptype) { case PPP_VJC: - ptype = vjc_print(q, length - (q - p), ptype); + ptype = vjc_print(q, ptype); hdrlength = PPP_BSDI_HDRLEN; p += hdrlength; - if (ptype == PPP_IP) + switch (ptype) { + case PPP_IP: ip_print(p, length); + break; +#ifdef INET6 + case PPP_IPV6: + ip6_print(p, length); + break; +#endif + case PPP_MPLS_UCAST: + case PPP_MPLS_MCAST: + mpls_print(p, length); + break; + } goto printx; case PPP_VJNC: - ptype = vjc_print(q, length - (q - p), ptype); + ptype = vjc_print(q, ptype); hdrlength = PPP_BSDI_HDRLEN; p += hdrlength; - if (ptype == PPP_IP) + switch (ptype) { + case PPP_IP: ip_print(p, length); + break; +#ifdef INET6 + case PPP_IPV6: + ip6_print(p, length); + break; +#endif + case PPP_MPLS_UCAST: + case PPP_MPLS_MCAST: + mpls_print(p, length); + break; + } goto printx; default: if (eflag) { @@ -240,15 +1411,26 @@ ppp_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, length -= hdrlength; p += hdrlength; - if (ptype == PPP_IP) + switch (ptype) { + case PPP_IP: ip_print(p, length); - else - printf("%s ", tok2str(ptype2str, "proto-#%d", ptype)); + break; +#ifdef INET6 + case PPP_IPV6: + ip6_print(p, length); + break; +#endif + case PPP_MPLS_UCAST: + case PPP_MPLS_MCAST: + mpls_print(p, length); + break; + default: + printf("%s ", tok2str(ppptype2str, "unknown PPP protocol (0x%04x)", ptype)); + } printx: - if (xflag) - default_print((const u_char *)p, caplen - hdrlength); -out: - putchar('\n'); +#else /* __bsdi */ + hdrlength = 0; #endif /* __bsdi__ */ + return (hdrlength); } diff --git a/kame/kame/tcpdump/print-pppoe.c b/kame/kame/tcpdump/print-pppoe.c new file mode 100644 index 0000000000..69179c61b4 --- /dev/null +++ b/kame/kame/tcpdump/print-pppoe.c @@ -0,0 +1,218 @@ +/* + * 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. + * + * Original code by Greg Stark + */ + +#ifndef lint +static const char rcsid[] _U_ = +"@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.24.2.4 2004/03/24 03:04:22 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "ppp.h" +#include "ethertype.h" +#include "ether.h" +#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 +}; + +static struct tok pppoecode2str[] = { + { 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 +}; + +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 } +}; + +#define PPPOE_HDRLEN 6 +#define MAXTAGPRINT 80 + +u_int +pppoe_if_print(const struct pcap_pkthdr *h, register const u_char *p) +{ + return (pppoe_print(p, h->len)); +} + +u_int +pppoe_print(register const u_char *bp, u_int length) +{ + u_short pppoe_ver, pppoe_type, pppoe_code, pppoe_sessionid, pppoe_length; + const u_char *pppoe_packet, *pppoe_payload; + + pppoe_packet = bp; + TCHECK2(*pppoe_packet, PPPOE_HDRLEN); + 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 (PPPOE_HDRLEN); + } + + 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 && snapend-pppoe_payload+14 > 64) { + /* (small packets are probably just padded up to the ethernet + minimum of 64 bytes) */ + printf(" [length %d (%d extra bytes)]", + pppoe_length, snapend - pppoe_payload - pppoe_length); +#if RESPECT_PAYLOAD_LENGTH + snapend = pppoe_payload+pppoe_length; +#else + /* Actual PPPoE implementations appear to ignore the payload + length and use the full ethernet frame anyways */ + pppoe_length = snapend-pppoe_payload; +#endif + + } + + 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) { + unsigned isascii = 0, isgarbage = 0; + const u_char *v = p; + char tag_str[MAXTAGPRINT]; + unsigned tag_str_len = 0; + + /* TODO print UTF-8 decoded text */ + for (v = p; v < p + tag_len && tag_str_len < MAXTAGPRINT-1; v++) + if (*v >= 32 && *v < 127) { + tag_str[tag_str_len++] = *v; + isascii++; + } else { + tag_str[tag_str_len++] = '.'; + isgarbage++; + } + tag_str[tag_str_len] = 0; + + if (isascii > isgarbage) { + printf(" [%s \"%*.*s\"]", + tok2str(pppoetag2str, "TAG-0x%x", tag_type), + (int)tag_str_len, + (int)tag_str_len, + tag_str); + } else { + /* Print hex, not fast to abuse printf but this doesn't get used much */ + printf(" [%s 0x", tok2str(pppoetag2str, "TAG-0x%x", tag_type)); + for (v=p; v + +#include + +#include "interface.h" +#include "extract.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 const 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 (EXTRACT_32BITS(bearer_cap) & PPTP_BEARER_CAP_DIGITAL_MASK) { + printf("D"); + } + if (EXTRACT_32BITS(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 (EXTRACT_32BITS(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)", EXTRACT_16BITS(call_id)); +} + +static void +pptp_call_ser_print(const u_int16_t *call_ser) +{ + printf(" CALL_SER_NUM(%u)", EXTRACT_16BITS(call_ser)); +} + +static void +pptp_cause_code_print(const u_int16_t *cause_code) +{ + printf(" CAUSE_CODE(%u)", EXTRACT_16BITS(cause_code)); +} + +static void +pptp_conn_speed_print(const u_int32_t *conn_speed) +{ + printf(" CONN_SPEED(%u)", EXTRACT_32BITS(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)", EXTRACT_16BITS(firm_rev)); +} + +static void +pptp_framing_cap_print(const u_int32_t *framing_cap) +{ + printf(" FRAME_CAP("); + if (EXTRACT_32BITS(framing_cap) & PPTP_FRAMING_CAP_ASYNC_MASK) { + printf("A"); /* Async */ + } + if (EXTRACT_32BITS(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 (EXTRACT_32BITS(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(%u)", EXTRACT_32BITS(id)); +} + +static void +pptp_max_channel_print(const u_int16_t *max_channel) +{ + printf(" MAX_CHAN(%u)", EXTRACT_16BITS(max_channel)); +} + +static void +pptp_peer_call_id_print(const u_int16_t *peer_call_id) +{ + printf(" PEER_CALL_ID(%u)", EXTRACT_16BITS(peer_call_id)); +} + +static void +pptp_phy_chan_id_print(const u_int32_t *phy_chan_id) +{ + printf(" PHY_CHAN_ID(%u)", EXTRACT_32BITS(phy_chan_id)); +} + +static void +pptp_pkt_proc_delay_print(const u_int16_t *pkt_proc_delay) +{ + printf(" PROC_DELAY(%u)", EXTRACT_16BITS(pkt_proc_delay)); +} + +static void +pptp_proto_ver_print(const u_int16_t *proto_ver) +{ + printf(" PROTO_VER(%u.%u)", /* Version.Revision */ + EXTRACT_16BITS(proto_ver) >> 8, + EXTRACT_16BITS(proto_ver) & 0xff); +} + +static void +pptp_recv_winsiz_print(const u_int16_t *recv_winsiz) +{ + printf(" RECV_WIN(%u)", EXTRACT_16BITS(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(%u)", EXTRACT_32BITS(&ptr->min_bps)); + TCHECK(ptr->max_bps); + printf(" MAX_BPS(%u)", EXTRACT_32BITS(&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)", EXTRACT_16BITS(&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)", EXTRACT_16BITS(&ptr->dialed_no_len)); + TCHECK(ptr->dialing_no_len); + printf(" DIALING_NO_LEN(%u)", EXTRACT_16BITS(&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(%u)", EXTRACT_32BITS(&ptr->crc_err)); + TCHECK(ptr->framing_err); + printf(" FRAMING_ERR(%u)", EXTRACT_32BITS(&ptr->framing_err)); + TCHECK(ptr->hardware_overrun); + printf(" HARDWARE_OVERRUN(%u)", EXTRACT_32BITS(&ptr->hardware_overrun)); + TCHECK(ptr->buffer_overrun); + printf(" BUFFER_OVERRUN(%u)", EXTRACT_32BITS(&ptr->buffer_overrun)); + TCHECK(ptr->timeout_err); + printf(" TIMEOUT_ERR(%u)", EXTRACT_32BITS(&ptr->timeout_err)); + TCHECK(ptr->align_err); + printf(" ALIGN_ERR(%u)", EXTRACT_32BITS(&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%08x)", EXTRACT_32BITS(&ptr->send_accm)); + TCHECK(ptr->recv_accm); + printf(" RECV_ACCM(0x%08x)", EXTRACT_32BITS(&ptr->recv_accm)); + + return; + +trunc: + printf("%s", tstr); +} + +void +pptp_print(const u_char *dat) +{ + 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", EXTRACT_16BITS(&hdr->length)); + } + TCHECK(hdr->msg_type); + if (vflag) { + switch(EXTRACT_16BITS(&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 = EXTRACT_32BITS(&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 = EXTRACT_16BITS(&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/kame/kame/tcpdump/print-radius.c b/kame/kame/tcpdump/print-radius.c new file mode 100644 index 0000000000..b3f790ec90 --- /dev/null +++ b/kame/kame/tcpdump/print-radius.c @@ -0,0 +1,910 @@ +/* + * 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: + * "Remote Authentication Dial In User Service (RADIUS)" + * + * RFC 2866: + * "RADIUS Accounting" + * + * RFC 2867: + * "RADIUS Accounting Modifications for Tunnel Protocol Support" + * + * RFC 2868: + * "RADIUS Attributes for Tunnel Protocol Support" + * + * RFC 2869: + * "RADIUS Extensions" + * + * Alfredo Andres Omella (aandres@s21sec.com) v0.1 2000/09/15 + * + * TODO: Among other things to print ok MacIntosh and Vendor values + */ + +#ifndef lint +static const char rcsid[] _U_ = + "$Id: print-radius.c,v 1.19.2.4 2004/02/06 14:38:51 hannes Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include + +#include + +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" +#include "oui.h" + +#define TAM_SIZE(x) (sizeof(x)/sizeof(x[0]) ) + +#define PRINT_HEX(bytes_len, ptr_data) \ + while(bytes_len) \ + { \ + printf("%02X", *ptr_data ); \ + ptr_data++; \ + bytes_len--; \ + } + + +/* Radius packet codes */ +#define RADCMD_ACCESS_REQ 1 /* Access-Request */ +#define RADCMD_ACCESS_ACC 2 /* Access-Accept */ +#define RADCMD_ACCESS_REJ 3 /* Access-Reject */ +#define RADCMD_ACCOUN_REQ 4 /* Accounting-Request */ +#define RADCMD_ACCOUN_RES 5 /* Accounting-Response */ +#define RADCMD_ACCESS_CHA 11 /* Access-Challenge */ +#define RADCMD_STATUS_SER 12 /* Status-Server */ +#define RADCMD_STATUS_CLI 13 /* Status-Client */ +#define RADCMD_RESERVED 255 /* Reserved */ + +static struct tok radius_command_values[] = { + { RADCMD_ACCESS_REQ, "Access Request" }, + { RADCMD_ACCESS_ACC, "Access Accept" }, + { RADCMD_ACCESS_REJ, "Access Reject" }, + { RADCMD_ACCOUN_REQ, "Accounting Request" }, + { RADCMD_ACCOUN_RES, "Accounting Response" }, + { RADCMD_ACCESS_CHA, "Access Challenge" }, + { RADCMD_STATUS_SER, "Status Server" }, + { RADCMD_STATUS_CLI, "Status Client" }, + { RADCMD_RESERVED, "Reserved" }, + { 0, NULL} +}; + +/********************************/ +/* Begin Radius Attribute types */ +/********************************/ +#define SERV_TYPE 6 +#define FRM_IPADDR 8 +#define LOG_IPHOST 14 +#define LOG_SERVICE 15 +#define FRM_IPX 23 +#define SESSION_TIMEOUT 27 +#define IDLE_TIMEOUT 28 +#define FRM_ATALK_LINK 37 +#define FRM_ATALK_NETWORK 38 + +#define ACCT_DELAY 41 +#define ACCT_SESSION_TIME 46 + +#define TUNNEL_TYPE 64 +#define TUNNEL_MEDIUM 65 +#define TUNNEL_CLIENT_END 66 +#define TUNNEL_SERVER_END 67 +#define TUNNEL_PASS 69 + +#define ARAP_PASS 70 +#define ARAP_FEATURES 71 + +#define TUNNEL_PRIV_GROUP 81 +#define TUNNEL_ASSIGN_ID 82 +#define TUNNEL_PREFERENCE 83 + +#define ARAP_CHALLENGE_RESP 84 +#define ACCT_INT_INTERVAL 85 + +#define TUNNEL_CLIENT_AUTH 90 +#define TUNNEL_SERVER_AUTH 91 +/********************************/ +/* End Radius Attribute types */ +/********************************/ + + +static void print_attr_string(register u_char *, u_int, u_short ); +static void print_attr_num(register u_char *, u_int, u_short ); +static void print_vendor_attr(register u_char *, u_int, u_short ); +static void print_attr_address(register u_char *, u_int, u_short); +static void print_attr_time(register u_char *, u_int, u_short); +static void print_attr_strange(register u_char *, u_int, u_short); + + +struct radius_hdr { u_int8_t code; /* Radius packet code */ + u_int8_t id; /* Radius packet id */ + u_int16_t len; /* Radius total length */ + 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 */ + }; + + +/* Service-Type Attribute standard values */ +static const char *serv_type[]={ NULL, + "Login", + "Framed", + "Callback Login", + "Callback Framed", + "Outbound", + "Administrative", + "NAS Prompt", + "Authenticate Only", + "Callback NAS Prompt", + "Call Check", + "Callback Administrative", + }; + +/* Framed-Protocol Attribute standard values */ +static const char *frm_proto[]={ NULL, + "PPP", + "SLIP", + "ARAP", + "Gandalf proprietary", + "Xylogics IPX/SLIP", + "X.75 Synchronous", + }; + +/* Framed-Routing Attribute standard values */ +static const char *frm_routing[]={ "None", + "Send", + "Listen", + "Send&Listen", + }; + +/* Framed-Compression Attribute standard values */ +static const char *frm_comp[]={ "None", + "VJ TCP/IP", + "IPX", + "Stac-LZS", + }; + +/* Login-Service Attribute standard values */ +static const char *login_serv[]={ "Telnet", + "Rlogin", + "TCP Clear", + "PortMaster(proprietary)", + "LAT", + "X.25-PAD", + "X.25-T3POS", + "Unassigned", + "TCP Clear Quiet", + }; + + +/* Termination-Action Attribute standard values */ +static const char *term_action[]={ "Default", + "RADIUS-Request", + }; + +/* NAS-Port-Type Attribute standard values */ +static const char *nas_port_type[]={ "Async", + "Sync", + "ISDN Sync", + "ISDN Async V.120", + "ISDN Async V.110", + "Virtual", + "PIAFS", + "HDLC Clear Channel", + "X.25", + "X.75", + "G.3 Fax", + "SDSL", + "ADSL-CAP", + "ADSL-DMT", + "ISDN-DSL", + "Ethernet", + "xDSL", + "Cable", + "Wireless - Other", + "Wireless - IEEE 802.11", + }; + +/* Acct-Status-Type Accounting Attribute standard values */ +static const char *acct_status[]={ NULL, + "Start", + "Stop", + "Interim-Update", + "Unassigned", + "Unassigned", + "Unassigned", + "Accounting-On", + "Accounting-Off", + "Tunnel-Start", + "Tunnel-Stop", + "Tunnel-Reject", + "Tunnel-Link-Start", + "Tunnel-Link-Stop", + "Tunnel-Link-Reject", + "Failed", + }; + +/* Acct-Authentic Accounting Attribute standard values */ +static const char *acct_auth[]={ NULL, + "RADIUS", + "Local", + "Remote", + }; + +/* Acct-Terminate-Cause Accounting Attribute standard values */ +static const char *acct_term[]={ NULL, + "User Request", + "Lost Carrier", + "Lost Service", + "Idle Timeout", + "Session Timeout", + "Admin Reset", + "Admin Reboot", + "Port Error", + "NAS Error", + "NAS Request", + "NAS Reboot", + "Port Unneeded", + "Port Preempted", + "Port Suspended", + "Service Unavailable", + "Callback", + "User Error", + "Host Request", + }; + +/* Tunnel-Type Attribute standard values */ +static const char *tunnel_type[]={ NULL, + "PPTP", + "L2F", + "L2TP", + "ATMP", + "VTP", + "AH", + "IP-IP", + "MIN-IP-IP", + "ESP", + "GRE", + "DVS", + "IP-in-IP Tunneling", + }; + +/* Tunnel-Medium-Type Attribute standard values */ +static const char *tunnel_medium[]={ NULL, + "IPv4", + "IPv6", + "NSAP", + "HDLC", + "BBN 1822", + "802", + "E.163", + "E.164", + "F.69", + "X.121", + "IPX", + "Appletalk", + "Decnet IV", + "Banyan Vines", + "E.164 with NSAP subaddress", + }; + +/* ARAP-Zone-Access Attribute standard values */ +static const char *arap_zone[]={ NULL, + "Only access to dfl zone", + "Use zone filter inc.", + "Not used", + "Use zone filter exc.", + }; + +static const char *prompt[]={ "No Echo", + "Echo", + }; + + +struct attrtype { const char *name; /* Attribute name */ + const char **subtypes; /* Standard Values (if any) */ + u_char siz_subtypes; /* Size of total standard values */ + u_char first_subtype; /* First standard value is 0 or 1 */ + void (*print_func)(register u_char *, u_int, u_short ); + } attr_type[]= + { + { NULL, NULL, 0, 0, NULL }, + { "Username", NULL, 0, 0, print_attr_string }, + { "Password", NULL, 0, 0, NULL }, + { "CHAP Password", NULL, 0, 0, NULL }, + { "NAS IP Address", NULL, 0, 0, print_attr_address }, + { "NAS Port", NULL, 0, 0, print_attr_num }, + { "Service Type", serv_type, TAM_SIZE(serv_type)-1, 1, print_attr_num }, + { "Framed Protocol", frm_proto, TAM_SIZE(frm_proto)-1, 1, print_attr_num }, + { "Framed IP Address", NULL, 0, 0, print_attr_address }, + { "Framed IP Network", NULL, 0, 0, print_attr_address }, + { "Framed Routing", frm_routing, TAM_SIZE(frm_routing), 0, print_attr_num }, + { "Filter ID", NULL, 0, 0, print_attr_string }, + { "Framed MTU", NULL, 0, 0, print_attr_num }, + { "Framed Compression", frm_comp, TAM_SIZE(frm_comp), 0, print_attr_num }, + { "Login IP Host", NULL, 0, 0, print_attr_address }, + { "Login Service", login_serv, TAM_SIZE(login_serv), 0, print_attr_num }, + { "Login TCP Port", NULL, 0, 0, print_attr_num }, + { "Unassigned", NULL, 0, 0, NULL }, /*17*/ + { "Reply", NULL, 0, 0, print_attr_string }, + { "Callback-number", NULL, 0, 0, print_attr_string }, + { "Callback-ID", NULL, 0, 0, print_attr_string }, + { "Unassigned", NULL, 0, 0, NULL }, /*21*/ + { "Framed Route", NULL, 0, 0, print_attr_string }, + { "Framed IPX Network", NULL, 0, 0, print_attr_num }, + { "State", NULL, 0, 0, print_attr_string }, + { "Class", NULL, 0, 0, print_attr_string }, + { "Vendor Specific", NULL, 0, 0, print_vendor_attr }, + { "Session Timeout", NULL, 0, 0, print_attr_num }, + { "Idle Timeout", NULL, 0, 0, print_attr_num }, + { "Termination Action", term_action, TAM_SIZE(term_action), 0, print_attr_num }, + { "Called Station", NULL, 0, 0, print_attr_string }, + { "Calling Station", NULL, 0, 0, print_attr_string }, + { "NAS ID", NULL, 0, 0, print_attr_string }, + { "Proxy State", NULL, 0, 0, print_attr_string }, + { "Login LAT Service", NULL, 0, 0, print_attr_string }, + { "Login LAT Node", NULL, 0, 0, print_attr_string }, + { "Login LAT Group", NULL, 0, 0, print_attr_string }, + { "Framed Appletalk Link", NULL, 0, 0, print_attr_num }, + { "Framed Appltalk Net", NULL, 0, 0, print_attr_num }, + { "Framed Appletalk Zone", NULL, 0, 0, print_attr_string }, + { "Accounting Status", acct_status, TAM_SIZE(acct_status)-1, 1, print_attr_num }, + { "Accounting Delay", NULL, 0, 0, print_attr_num }, + { "Accounting Input Octets", NULL, 0, 0, print_attr_num }, + { "Accounting Output Octets", NULL, 0, 0, print_attr_num }, + { "Accounting Session ID", NULL, 0, 0, print_attr_string }, + { "Accounting Authentication", acct_auth, TAM_SIZE(acct_auth)-1, 1, print_attr_num }, + { "Accounting Session Time", NULL, 0, 0, print_attr_num }, + { "Accounting Input Packets", NULL, 0, 0, print_attr_num }, + { "Accounting Output Packets", NULL, 0, 0, print_attr_num }, + { "Accounting Termination Cause", acct_term, TAM_SIZE(acct_term)-1, 1, print_attr_num }, + { "Accounting Multilink Session ID", NULL, 0, 0, print_attr_string }, + { "Accounting Link Count", NULL, 0, 0, print_attr_num }, + { "Accounting Input Giga", NULL, 0, 0, print_attr_num }, + { "Accounting Output Giga", NULL, 0, 0, print_attr_num }, + { "Unassigned", NULL, 0, 0, NULL }, /*54*/ + { "Event Timestamp", NULL, 0, 0, print_attr_time }, + { "Unassigned", NULL, 0, 0, NULL }, /*56*/ + { "Unassigned", NULL, 0, 0, NULL }, /*57*/ + { "Unassigned", NULL, 0, 0, NULL }, /*58*/ + { "Unassigned", NULL, 0, 0, NULL }, /*59*/ + { "CHAP challenge", NULL, 0, 0, print_attr_string }, + { "NAS Port Type", nas_port_type, TAM_SIZE(nas_port_type), 0, print_attr_num }, + { "Port Limit", NULL, 0, 0, print_attr_num }, + { "Login LAT Port", NULL, 0, 0, print_attr_string }, /*63*/ + { "Tunnel Type", tunnel_type, TAM_SIZE(tunnel_type)-1, 1, print_attr_num }, + { "Tunnel Medium", tunnel_medium, TAM_SIZE(tunnel_medium)-1, 1, print_attr_num }, + { "Tunnel Client End", NULL, 0, 0, print_attr_string }, + { "Tunnel Server End", NULL, 0, 0, print_attr_string }, + { "Accounting Tunnel connect", NULL, 0, 0, print_attr_string }, + { "Tunnel Password", NULL, 0, 0, print_attr_string }, + { "ARAP Password", NULL, 0, 0, print_attr_strange }, + { "ARAP Feature", NULL, 0, 0, print_attr_strange }, + { "ARAP Zone Acces", arap_zone, TAM_SIZE(arap_zone)-1, 1, print_attr_num }, /*72*/ + { "ARAP Security", NULL, 0, 0, print_attr_string }, + { "ARAP Security Data", NULL, 0, 0, print_attr_string }, + { "Password Retry", NULL, 0, 0, print_attr_num }, + { "Prompt", prompt, TAM_SIZE(prompt), 0, print_attr_num }, + { "Connect Info", NULL, 0, 0, print_attr_string }, + { "Config Token", NULL, 0, 0, print_attr_string }, + { "EAP Message", NULL, 0, 0, print_attr_string }, + { "Message Authentication", NULL, 0, 0, print_attr_string }, /*80*/ + { "Tunnel Private Group", NULL, 0, 0, print_attr_string }, + { "Tunnel Assigned ID", NULL, 0, 0, print_attr_string }, + { "Tunnel Preference", NULL, 0, 0, print_attr_num }, + { "ARAP Challenge Response", NULL, 0, 0, print_attr_strange }, + { "Accounting Interim Interval", NULL, 0, 0, print_attr_num }, + { "Accounting Tunnel packets lost", NULL, 0, 0, print_attr_num }, /*86*/ + { "NAS Port ID", NULL, 0, 0, print_attr_string }, + { "Framed Pool", NULL, 0, 0, print_attr_string }, + { "Unassigned", NULL, 0, 0, NULL }, + { "Tunnel Client Authentication ID", NULL, 0, 0, print_attr_string }, + { "Tunnel Server Authentication ID", NULL, 0, 0, print_attr_string }, + { "Unassigned", NULL, 0, 0, NULL }, /*92*/ + { "Unassigned", NULL, 0, 0, NULL } /*93*/ + }; + + +/*****************************/ +/* Print an attribute string */ +/* value pointed by 'data' */ +/* and 'length' size. */ +/*****************************/ +/* Returns nothing. */ +/*****************************/ +static void +print_attr_string(register u_char *data, u_int length, u_short attr_code ) +{ + register u_int i; + + TCHECK2(data[0],length); + + switch(attr_code) + { + case TUNNEL_PASS: + if (*data && (*data <=0x1F) ) + printf("Tag %u, ",*data); + data++; + printf("Salt %u ",EXTRACT_16BITS(data) ); + data+=2; + length-=2; + break; + case TUNNEL_CLIENT_END: + case TUNNEL_SERVER_END: + case TUNNEL_PRIV_GROUP: + case TUNNEL_ASSIGN_ID: + case TUNNEL_CLIENT_AUTH: + case TUNNEL_SERVER_AUTH: + if (*data <= 0x1F) + { + printf("Tag %u",*data); + data++; + length--; + } + break; + } + + for (i=0; *data && i < length ; i++, data++) + printf("%c",(*data < 32 || *data > 128) ? '.' : *data ); + + return; + + trunc: + printf("|radius"); +} + +/* + * print vendor specific attributes + */ + +static void +print_vendor_attr(register u_char *data, u_int length, u_short attr_code _U_) +{ + u_int idx; + u_int vendor_id; + u_int vendor_type; + u_int vendor_length; + + /* FIXME: all sort of boundary checks */ + vendor_id = EXTRACT_32BITS(data); + data+=4; + length-=4; + + printf("Vendor: %s (%u)", + tok2str(smi_values,"Unknown",vendor_id), + vendor_id); + + while (length >= 2) { + if(!TTEST2(*data, 2)) + return; + + vendor_type = *(data); + vendor_length = *(data+1); + + data+=2; + if(!TTEST2(*data, vendor_length)) + return; + + printf("\n\t Vendor Attribute: %u, Length: %u, Value: ", + vendor_type, + vendor_length); + for (idx = 0; idx < vendor_length ; idx++, data++) + printf("%c",(*data < 32 || *data > 128) ? '.' : *data ); + length-=vendor_length; + } +} + + + +/******************************/ +/* Print an attribute numeric */ +/* value pointed by 'data' */ +/* and 'length' size. */ +/******************************/ +/* Returns nothing. */ +/******************************/ +static void +print_attr_num(register u_char *data, u_int length, u_short attr_code ) +{ + u_int8_t tag; + u_int32_t timeout; + + if (length != 4) + { + printf("ERROR: length %u != 4", length); + return; + } + + TCHECK2(data[0],4); + /* This attribute has standard values */ + if (attr_type[attr_code].siz_subtypes) + { + static const char **table; + u_int32_t data_value; + table = attr_type[attr_code].subtypes; + + if ( (attr_code == TUNNEL_TYPE) || (attr_code == TUNNEL_MEDIUM) ) + { + if (!*data) + printf("Tag[Unused]"); + else + printf("Tag[%d]", *data); + data++; + data_value = EXTRACT_24BITS(data); + } + else + { + data_value = EXTRACT_32BITS(data); + } + if ( data_value <= (u_int32_t)(attr_type[attr_code].siz_subtypes - 1 + + attr_type[attr_code].first_subtype) && + data_value >= attr_type[attr_code].first_subtype ) + printf("%s",table[data_value]); + else + printf("#%u",data_value); + } + else + { + switch(attr_code) /* Be aware of special cases... */ + { + case FRM_IPX: + if (EXTRACT_32BITS( data) == 0xFFFFFFFE ) + printf("NAS Select"); + else + printf("%d",EXTRACT_32BITS( data) ); + break; + + case SESSION_TIMEOUT: + case IDLE_TIMEOUT: + case ACCT_DELAY: + case ACCT_SESSION_TIME: + case ACCT_INT_INTERVAL: + timeout = EXTRACT_32BITS( data); + if ( timeout < 60 ) + printf( "%02d secs", timeout); + else + { + if ( timeout < 3600 ) + printf( "%02d:%02d min", + timeout / 60, timeout % 60); + else + printf( "%02d:%02d:%02d hours", + timeout / 3600, (timeout % 3600) / 60, + timeout % 60); + } + break; + + case FRM_ATALK_LINK: + if (EXTRACT_32BITS(data) ) + printf("%d",EXTRACT_32BITS(data) ); + else + printf("Unnumbered" ); + break; + + case FRM_ATALK_NETWORK: + if (EXTRACT_32BITS(data) ) + printf("%d",EXTRACT_32BITS(data) ); + else + printf("NAS assigned" ); + break; + + case TUNNEL_PREFERENCE: + tag = *data; + data++; + if (tag == 0) + printf("Tag (Unused) %d",EXTRACT_24BITS(data) ); + else + printf("Tag (%d) %d", tag, EXTRACT_24BITS(data) ); + break; + + default: + printf("%d",EXTRACT_32BITS( data) ); + break; + + } /* switch */ + + } /* if-else */ + + return; + + trunc: + printf("|radius}"); +} + + +/*****************************/ +/* Print an attribute IPv4 */ +/* address value pointed by */ +/* 'data' and 'length' size. */ +/*****************************/ +/* Returns nothing. */ +/*****************************/ +static void +print_attr_address(register u_char *data, u_int length, u_short attr_code ) +{ + if (length != 4) + { + printf("ERROR: length %u != 4", length); + return; + } + + TCHECK2(data[0],4); + + switch(attr_code) + { + case FRM_IPADDR: + case LOG_IPHOST: + if (EXTRACT_32BITS(data) == 0xFFFFFFFF ) + printf("User Selected"); + else + if (EXTRACT_32BITS(data) == 0xFFFFFFFE ) + printf("NAS Select"); + else + printf("%s",ipaddr_string(data)); + break; + + default: + printf("%s",ipaddr_string(data) ); + break; + } + + return; + + trunc: + printf("|radius"); +} + + +/*************************************/ +/* Print an attribute of 'secs since */ +/* January 1, 1970 00:00 UTC' value */ +/* pointed by 'data' and 'length' */ +/* size. */ +/*************************************/ +/* Returns nothing. */ +/*************************************/ +static void print_attr_time(register u_char *data, u_int length, u_short attr_code _U_) +{ + time_t attr_time; + char string[26]; + + if (length != 4) + { + printf("ERROR: length %u != 4", length); + return; + } + + TCHECK2(data[0],4); + + attr_time = EXTRACT_32BITS(data); + strlcpy(string, ctime(&attr_time), sizeof(string)); + /* Get rid of the newline */ + string[24] = '\0'; + printf("%.24s", string); + return; + + trunc: + printf("|radius"); +} + + +/***********************************/ +/* Print an attribute of 'strange' */ +/* data format pointed by 'data' */ +/* and 'length' size. */ +/***********************************/ +/* Returns nothing. */ +/***********************************/ +static void print_attr_strange(register u_char *data, u_int length, u_short attr_code) +{ + u_short len_data; + + switch(attr_code) + { + case ARAP_PASS: + if (length != 16) + { + printf("ERROR: length %u != 16", length); + return; + } + printf("User_challenge ("); + TCHECK2(data[0],8); + len_data = 8; + PRINT_HEX(len_data, data); + printf(") User_resp("); + TCHECK2(data[0],8); + len_data = 8; + PRINT_HEX(len_data, data); + printf(")"); + break; + + case ARAP_FEATURES: + if (length != 14) + { + printf("ERROR: length %u != 14", length); + return; + } + TCHECK2(data[0],1); + if (*data) + printf("User can change password"); + else + printf("User cannot change password"); + data++; + TCHECK2(data[0],1); + printf(", Min password length: %d",*data); + data++; + printf(", created at: "); + TCHECK2(data[0],4); + len_data = 4; + PRINT_HEX(len_data, data); + printf(", expires in: "); + TCHECK2(data[0],4); + len_data = 4; + PRINT_HEX(len_data, data); + printf(", Current Time: "); + len_data = 4; + TCHECK2(data[0],4); + PRINT_HEX(len_data, data); + break; + + case ARAP_CHALLENGE_RESP: + if (length < 8) + { + printf("ERROR: length %u != 8", length); + return; + } + TCHECK2(data[0],8); + len_data = 8; + PRINT_HEX(len_data, data); + break; + } + + trunc: + printf("|radius}"); +} + + + +static void +radius_attr_print(register const u_char *attr, u_int length) +{ + register const struct radius_attr *rad_attr = (struct radius_attr *)attr; + + if (length < 3) + { + printf(" [|radius]"); + return; + } + + while (length > 0) + { + if (rad_attr->len == 0 && rad_attr->type < (TAM_SIZE(attr_type)-1)) + { + printf("\n\t %s Attribute (%u), zero-length", + attr_type[rad_attr->type].name, + rad_attr->type); + return; + } + if ( rad_attr->len <= length && rad_attr->type < (TAM_SIZE(attr_type)-1)) + { + printf("\n\t %s Attribute (%u), length: %u, Value: ", + attr_type[rad_attr->type].name, + rad_attr->type, + rad_attr->len); + + if ( !rad_attr->type || (rad_attr->type > (TAM_SIZE(attr_type)-1)) ) { + } + else { + if (rad_attr->len > 2) + { + if ( attr_type[rad_attr->type].print_func ) + (*attr_type[rad_attr->type].print_func)( + ((u_char *)(rad_attr+1)), + rad_attr->len - 2, rad_attr->type); + } + } + } + else { + printf(" [|radius]"); + return; + } + /* do we want to see an additionally hexdump ? */ + if (vflag> 1 && rad_attr->len >= 2) + print_unknown_data((char *)rad_attr+2,"\n\t ",(rad_attr->len)-2); + + length-=(rad_attr->len); + rad_attr = (struct radius_attr *)( ((char *)(rad_attr))+rad_attr->len); + } +} + + +void +radius_print(const u_char *dat, u_int length) +{ + register const struct radius_hdr *rad; + register u_int i; + u_int len, auth_idx; + + if (snapend < dat) + { + printf(" [|radius]"); + return; + } + i = snapend - dat; + if (i > length) + i = length; + + if (i < MIN_RADIUS_LEN) + { + printf(" [|radius]"); + return; + } + + rad = (struct radius_hdr *)dat; + len = EXTRACT_16BITS(&rad->len); + + if (len < MIN_RADIUS_LEN) + { + printf(" [|radius]"); + return; + } + + if (len < i) + i = len; + + i -= MIN_RADIUS_LEN; + + if (vflag < 1) { + printf("RADIUS, %s (%u), id: 0x%02x length: %u", + tok2str(radius_command_values,"Unknown Command",rad->code), + rad->code, + rad->id, + length); + return; + } + else { + printf("RADIUS, length: %u\n\t%s (%u), id: 0x%02x, Authenticator: ", + length, + tok2str(radius_command_values,"Unknown Command",rad->code), + rad->code, + rad->id); + + for(auth_idx=0; auth_idx < 16; auth_idx++) + printf("%02x", rad->auth[auth_idx] ); + } + + if (i) + radius_attr_print( dat + MIN_RADIUS_LEN, i); +} diff --git a/kame/kame/tcpdump/print-raw.c b/kame/kame/tcpdump/print-raw.c index b16efeab7d..00153e58cb 100644 --- a/kame/kame/tcpdump/print-raw.c +++ b/kame/kame/tcpdump/print-raw.c @@ -20,30 +20,15 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-raw.c,v 1.22 96/12/10 23:18:58 leres Locked $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-raw.c,v 1.39.2.2 2003/11/16 08:51:40 guy Exp $ (LBL)"; #endif -#include -#include -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include @@ -52,36 +37,17 @@ struct rtentry; #include "addrtoname.h" #include "interface.h" -#ifndef AF_NS -#define AF_NS 6 /* XEROX NS protocols */ -#endif - /* * The DLT_RAW packet has no header. It contains a raw IP packet. */ -void -raw_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) +u_int +raw_if_print(const struct pcap_pkthdr *h, const u_char *p) { - u_int length = h->len; - u_int caplen = h->caplen; - - 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; - if (eflag) printf("ip: "); - ip_print(p, length); + ipN_print(p, h->len); - if (xflag) - default_print(p, caplen); - putchar('\n'); + return (0); } diff --git a/kame/kame/tcpdump/print-rip.c b/kame/kame/tcpdump/print-rip.c index 4daf6e2840..8c4301f7b2 100644 --- a/kame/kame/tcpdump/print-rip.c +++ b/kame/kame/tcpdump/print-rip.c @@ -20,32 +20,29 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-rip.c,v 1.36 96/11/29 01:22:50 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-rip.c,v 1.55.2.2 2003/11/16 08:51:41 guy Exp $ (LBL)"; #endif -#include -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include -#include -#include -#include -#include -#include +#include #include +#include #include "interface.h" #include "addrtoname.h" #include "extract.h" /* must come after interface.h */ struct rip { - u_char rip_cmd; /* request/response */ - u_char rip_vers; /* protocol version # */ - u_short rip_zero2; /* unused */ + u_int8_t rip_cmd; /* request/response */ + u_int8_t rip_vers; /* protocol version # */ + u_int8_t unused[2]; /* unused */ }; + #define RIPCMD_REQUEST 1 /* want info */ #define RIPCMD_RESPONSE 2 /* responding to request */ #define RIPCMD_TRACEON 3 /* turn tracing on */ @@ -53,9 +50,43 @@ struct rip { #define RIPCMD_POLL 5 /* want info from everybody */ #define RIPCMD_POLLENTRY 6 /* poll for entry */ +static const struct tok rip_cmd_values[] = { + { RIPCMD_REQUEST, "Request" }, + { RIPCMD_RESPONSE, "Response" }, + { RIPCMD_TRACEON, "Trace on" }, + { RIPCMD_TRACEOFF, "Trace off" }, + { RIPCMD_POLL, "Poll" }, + { RIPCMD_POLLENTRY, "Poll Entry" }, + { 0, NULL} +}; + +#define RIP_AUTHLEN 16 +#define RIP_ROUTELEN 20 + +/* + * rfc 1723 + * + * 0 1 2 3 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 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Command (1) | Version (1) | unused | + * +---------------+---------------+-------------------------------+ + * | Address Family Identifier (2) | Route Tag (2) | + * +-------------------------------+-------------------------------+ + * | IP Address (4) | + * +---------------------------------------------------------------+ + * | Subnet Mask (4) | + * +---------------------------------------------------------------+ + * | Next Hop (4) | + * +---------------------------------------------------------------+ + * | Metric (4) | + * +---------------------------------------------------------------+ + * + */ + struct rip_netinfo { - u_short rip_family; - u_short rip_tag; + u_int16_t rip_family; + u_int16_t rip_tag; u_int32_t rip_dest; u_int32_t rip_dest_mask; u_int32_t rip_router; @@ -63,33 +94,66 @@ struct rip_netinfo { }; static void -rip_entry_print(register int vers, register const struct rip_netinfo *ni) +rip_entry_print_v1(register const struct rip_netinfo *ni) +{ + register u_short family; + + /* RFC 1058 */ + family = EXTRACT_16BITS(&ni->rip_family); + if (family != AF_INET) { + printf("\n\t AFI: %u:", family); + print_unknown_data((u_int8_t *)&ni->rip_family,"\n\t ",RIP_ROUTELEN); + return; + } + if (EXTRACT_16BITS(&ni->rip_tag) || + EXTRACT_32BITS(&ni->rip_dest_mask) || + EXTRACT_32BITS(&ni->rip_router)) { + /* MBZ fields not zero */ + print_unknown_data((u_int8_t *)&ni->rip_family,"\n\t ",RIP_ROUTELEN); + return; + } /* AF_INET */ + printf("\n\t %s, metric: %u", + ipaddr_string(&ni->rip_dest), + EXTRACT_32BITS(&ni->rip_metric)); +} + +static void +rip_entry_print_v2(register const struct rip_netinfo *ni) { - register u_char *cp, *ep; - - if (EXTRACT_16BITS(&ni->rip_family) != AF_INET) { - - printf(" [family %d:", EXTRACT_16BITS(&ni->rip_family)); - cp = (u_char *)&ni->rip_tag; - ep = (u_char *)&ni->rip_metric + sizeof(ni->rip_metric); - for (; cp < ep; cp += 2) - printf(" %04x", EXTRACT_16BITS(cp)); - printf("]"); - } else if (vers < 2) { - /* RFC 1058 */ - printf(" %s", ipaddr_string(&ni->rip_dest)); - } else { - /* RFC 1723 */ - printf(" {%s", ipaddr_string(&ni->rip_dest)); - if (ni->rip_dest_mask) - printf("/%s", ipaddr_string(&ni->rip_dest_mask)); - if (ni->rip_router) - printf("->%s", ipaddr_string(&ni->rip_router)); - if (ni->rip_tag) - printf(" tag %04x", EXTRACT_16BITS(&ni->rip_tag)); - printf("}"); + register u_char *p; + register u_short family; + u_char buf[RIP_AUTHLEN]; + + family = EXTRACT_16BITS(&ni->rip_family); + if (family == 0xFFFF) { /* 16 bytes authentication ? */ + if (EXTRACT_16BITS(&ni->rip_tag) == 2) { /* simple text authentication ? */ + memcpy(buf, &ni->rip_dest, sizeof(buf)); + buf[sizeof(buf)-1] = '\0'; + for (p = buf; *p; p++) { + if (!isprint(*p)) + break; + } + printf("\n\t Simple Text Authentication data: %s", buf); + } else { + printf("\n\t Unknown (%u) Authentication data:", + EXTRACT_16BITS(&ni->rip_tag)); + print_unknown_data((u_int8_t *)&ni->rip_dest,"\n\t ",RIP_AUTHLEN); + } + } else if (family != AF_INET) { + printf("\n\t AFI: %u", family); + print_unknown_data((u_int8_t *)&ni->rip_tag,"\n\t ",RIP_ROUTELEN-2); + return; + } else { /* AF_INET */ + printf("\n\t AFI: IPv4: %15s/%-2d, tag 0x%04x, metric: %u, next-hop: ", + ipaddr_string(&ni->rip_dest), + mask2plen(EXTRACT_32BITS(&ni->rip_dest_mask)), + EXTRACT_16BITS(&ni->rip_tag), + EXTRACT_32BITS(&ni->rip_metric)); + if (EXTRACT_32BITS(&ni->rip_router)) + printf("%s", ipaddr_string(&ni->rip_router)); + else + printf("self"); } - printf("(%d)", EXTRACT_32BITS(&ni->rip_metric)); } void @@ -97,63 +161,94 @@ rip_print(const u_char *dat, u_int length) { register const struct rip *rp; register const struct rip_netinfo *ni; - register int i, j, trunc; + register u_int i, j; + register int trunc; - i = min(length, snapend - dat) - sizeof(*rp); - if (i < 0) + if (snapend < dat) { + printf(" [|rip]"); + return; + } + i = snapend - dat; + if (i > length) + i = length; + if (i < sizeof(*rp)) { + printf(" [|rip]"); return; + } + i -= sizeof(*rp); rp = (struct rip *)dat; - switch (rp->rip_cmd) { - - case RIPCMD_REQUEST: - printf(" rip-req %d", length); - break; - - case RIPCMD_RESPONSE: - j = length / sizeof(*ni); - if (j * sizeof(*ni) != length - 4) - printf(" rip-resp %d[%d]:", j, length); - else - printf(" rip-resp %d:", j); - trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); - ni = (struct rip_netinfo *)(rp + 1); - for (; (i -= sizeof(*ni)) >= 0; ++ni) - rip_entry_print(rp->rip_vers, ni); - if (trunc) - printf("[|rip]"); - break; - - case RIPCMD_TRACEON: - printf(" rip-traceon %d: \"", length); - (void)fn_print((const u_char *)(rp + 1), snapend); - fputs("\"\n", stdout); - break; - - case RIPCMD_TRACEOFF: - printf(" rip-traceoff %d", length); - break; - - case RIPCMD_POLL: - printf(" rip-poll %d", length); - break; - case RIPCMD_POLLENTRY: - printf(" rip-pollentry %d", length); - break; + printf("%sRIPv%u", + (vflag >= 1) ? "\n\t" : "", + rp->rip_vers); - default: - printf(" rip-#%d %d", rp->rip_cmd, length); - break; - } switch (rp->rip_vers) { - - case 1: - case 2: + case 0: + /* + * RFC 1058. + * + * XXX - RFC 1058 says + * + * 0 Datagrams whose version number is zero are to be ignored. + * These are from a previous version of the protocol, whose + * packet format was machine-specific. + * + * so perhaps we should just dump the packet, in hex. + */ + print_unknown_data((u_int8_t *)&rp->rip_cmd,"\n\t",length); break; - default: - printf(" [vers %d]", rp->rip_vers); - break; + /* dump version and lets see if we know the commands name*/ + printf(", %s, length: %u", + tok2str(rip_cmd_values, + "unknown command (%u)", + rp->rip_cmd), + length); + + if (vflag < 1) + return; + + switch (rp->rip_cmd) { + case RIPCMD_RESPONSE: + j = length / sizeof(*ni); + printf(", routes: %u",j); + trunc = (i / sizeof(*ni)) != j; + ni = (struct rip_netinfo *)(rp + 1); + for (; i >= sizeof(*ni); ++ni) { + if (rp->rip_vers == 1) + rip_entry_print_v1(ni); + else if (rp->rip_vers == 2) + rip_entry_print_v2(ni); + else + break; + i -= sizeof(*ni); + } + if (trunc) + printf("[|rip]"); + break; + + case RIPCMD_REQUEST: + case RIPCMD_TRACEOFF: + case RIPCMD_POLL: + case RIPCMD_POLLENTRY: + break; + + case RIPCMD_TRACEON: + /* fall through */ + default: + if (vflag <= 1) { + if(!print_unknown_data((u_int8_t *)rp,"\n\t",length)) + return; + } + break; + } + /* do we want to see an additionally hexdump ? */ + if (vflag> 1) { + if(!print_unknown_data((u_int8_t *)rp,"\n\t",length)) + return; + } } } + + diff --git a/kame/kame/tcpdump/print-ripng.c b/kame/kame/tcpdump/print-ripng.c index 3470b82d9b..3432207fc8 100644 --- a/kame/kame/tcpdump/print-ripng.c +++ b/kame/kame/tcpdump/print-ripng.c @@ -20,56 +20,69 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) /master/usr.sbin/tcpdump/tcpdump/print-rip.c,v 2.1 1995/02/03 18:15:05 polk Exp (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-ripng.c,v 1.15.2.2 2003/11/16 08:51:42 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #ifdef INET6 -#include -#include -#include -#include +#include -#include -#include -#include -#include -#include -#include +#ifdef WIN32 +const struct in6_addr in6addr_any; /* :: */ +#endif /* WIN32 */ -#include -#include +#ifdef __MINGW32__ +int +IN6_ADDR_EQUAL(const struct in6_addr *a, const struct in6_addr *b) +{ + return (memcmp(a, b, sizeof(struct in6_addr)) == 0); +} + +#define IN6_IS_ADDR_UNSPECIFIED(a) IN6_ADDR_EQUAL((a), &in6addr_any) -#include +#endif /* __MINGW32__ */ + +#include #include "route6d.h" #include "interface.h" #include "addrtoname.h" +#include "extract.h" -static void +static int rip6_entry_print(register const struct netinfo6 *ni, int metric) { - printf(" %s/%d", ip6addr_string(&ni->rip6_dest), ni->rip6_plen); + int l; + l = printf("%s/%d", ip6addr_string(&ni->rip6_dest), ni->rip6_plen); if (ni->rip6_tag) - printf(" [%d]", ntohs(ni->rip6_tag)); + l += printf(" [%d]", EXTRACT_16BITS(&ni->rip6_tag)); if (metric) - printf(" (%d)", ni->rip6_metric); + l += printf(" (%d)", ni->rip6_metric); + return l; } 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; - register int amt = snapend - dat; - register int i = min(length, amt) - - (sizeof(struct rip6) - sizeof(struct netinfo6)); + register u_int amt; + register u_int i; int j; int trunc; - if (i < 0) + if (snapend < dat) + return; + amt = snapend - dat; + i = min(length, amt); + if (i < (sizeof(struct rip6) - sizeof(struct netinfo6))) return; + i -= (sizeof(struct rip6) - sizeof(struct netinfo6)); switch (rp->rip6_cmd) { @@ -82,27 +95,39 @@ 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) + for (ni = rp->rip6_nets; i >= sizeof(*ni); + i -= sizeof(*ni), ++ni) { + if (vflag > 1) + printf("\n\t"); + else + printf(" "); rip6_entry_print(ni, 0); + } break; 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) + for (ni = rp->rip6_nets; i >= sizeof(*ni); + i -= sizeof(*ni), ++ni) { + 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/kame/kame/tcpdump/print-rsvp.c b/kame/kame/tcpdump/print-rsvp.c new file mode 100644 index 0000000000..534878ed2a --- /dev/null +++ b/kame/kame/tcpdump/print-rsvp.c @@ -0,0 +1,1254 @@ +/* + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code + * distributions retain the above copyright notice and this paragraph + * in its entirety, and (2) distributions including binary code include + * the above copyright notice and this paragraph in its entirety in + * the documentation or other materials provided with the distribution. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND + * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT + * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE. + * + * Original code by Hannes Gredler (hannes@juniper.net) + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-rsvp.c,v 1.24.2.3 2004/03/24 04:01:08 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include + +#include "interface.h" +#include "extract.h" +#include "addrtoname.h" +#include "ethertype.h" +#include "gmpls.h" + +/* + * RFC 2205 common header + * + * 0 1 2 3 + * +-------------+-------------+-------------+-------------+ + * | Vers | Flags| Msg Type | RSVP Checksum | + * +-------------+-------------+-------------+-------------+ + * | Send_TTL | (Reserved) | RSVP Length | + * +-------------+-------------+-------------+-------------+ + * + */ + +struct rsvp_common_header { + u_int8_t version_flags; + u_int8_t msg_type; + u_int8_t checksum[2]; + u_int8_t ttl; + u_int8_t reserved; + u_int8_t length[2]; +}; + +/* + * RFC2205 object header + * + * + * 0 1 2 3 + * +-------------+-------------+-------------+-------------+ + * | Length (bytes) | Class-Num | C-Type | + * +-------------+-------------+-------------+-------------+ + * | | + * // (Object contents) // + * | | + * +-------------+-------------+-------------+-------------+ + */ + +struct rsvp_object_header { + u_int8_t length[2]; + u_int8_t class_num; + u_int8_t ctype; +}; + +#define RSVP_VERSION 1 +#define RSVP_EXTRACT_VERSION(x) (((x)&0xf0)>>4) +#define RSVP_EXTRACT_FLAGS(x) ((x)&0x0f) + +#define RSVP_MSGTYPE_PATH 1 +#define RSVP_MSGTYPE_RESV 2 +#define RSVP_MSGTYPE_PATHERR 3 +#define RSVP_MSGTYPE_RESVERR 4 +#define RSVP_MSGTYPE_PATHTEAR 5 +#define RSVP_MSGTYPE_RESVTEAR 6 +#define RSVP_MSGTYPE_RESVCONF 7 +#define RSVP_MSGTYPE_AGGREGATE 12 +#define RSVP_MSGTYPE_ACK 13 +#define RSVP_MSGTYPE_HELLO_OLD 14 /* ancient Hellos */ +#define RSVP_MSGTYPE_SREFRESH 15 +#define RSVP_MSGTYPE_HELLO 20 + +static const struct tok rsvp_msg_type_values[] = { + { RSVP_MSGTYPE_PATH, "Path" }, + { RSVP_MSGTYPE_RESV, "Resv" }, + { RSVP_MSGTYPE_PATHERR, "PathErr" }, + { RSVP_MSGTYPE_RESVERR, "ResvErr" }, + { RSVP_MSGTYPE_PATHTEAR, "PathTear" }, + { RSVP_MSGTYPE_RESVTEAR, "ResvTear" }, + { RSVP_MSGTYPE_RESVCONF, "ResvConf" }, + { RSVP_MSGTYPE_AGGREGATE, "Aggregate" }, + { RSVP_MSGTYPE_ACK, "Acknowledgement" }, + { RSVP_MSGTYPE_HELLO_OLD, "Hello (Old)" }, + { RSVP_MSGTYPE_SREFRESH, "Refresh" }, + { RSVP_MSGTYPE_HELLO, "Hello" }, + { 0, NULL} +}; + +static const struct tok rsvp_header_flag_values[] = { + { 0x01, "Refresh reduction capable" }, /* rfc2961 */ + { 0, NULL} +}; + +#define RSVP_OBJ_SESSION 1 /* rfc2205 */ +#define RSVP_OBJ_RSVP_HOP 3 /* rfc2205, rfc3473 */ +#define RSVP_OBJ_INTEGRITY 4 +#define RSVP_OBJ_TIME_VALUES 5 /* rfc2205 */ +#define RSVP_OBJ_ERROR_SPEC 6 +#define RSVP_OBJ_SCOPE 7 +#define RSVP_OBJ_STYLE 8 /* rfc2205 */ +#define RSVP_OBJ_FLOWSPEC 9 /* rfc2215 */ +#define RSVP_OBJ_FILTERSPEC 10 /* rfc2215 */ +#define RSVP_OBJ_SENDER_TEMPLATE 11 +#define RSVP_OBJ_SENDER_TSPEC 12 /* rfc2215 */ +#define RSVP_OBJ_ADSPEC 13 /* rfc2215 */ +#define RSVP_OBJ_POLICY_DATA 14 +#define RSVP_OBJ_CONFIRM 15 /* rfc2205 */ +#define RSVP_OBJ_LABEL 16 /* rfc3209 */ +#define RSVP_OBJ_LABEL_REQ 19 /* rfc3209 */ +#define RSVP_OBJ_ERO 20 /* rfc3209 */ +#define RSVP_OBJ_RRO 21 /* rfc3209 */ +#define RSVP_OBJ_HELLO 22 /* rfc3209 */ +#define RSVP_OBJ_MESSAGE_ID 23 +#define RSVP_OBJ_MESSAGE_ID_ACK 24 +#define RSVP_OBJ_MESSAGE_ID_LIST 25 +#define RSVP_OBJ_RECOVERY_LABEL 34 /* rfc3473 */ +#define RSVP_OBJ_UPSTREAM_LABEL 35 /* rfc3473 */ +#define RSVP_OBJ_LABEL_SET 36 /* rfc3473 */ +#define RSVP_OBJ_PROTECTION 37 /* rfc3473 */ +#define RSVP_OBJ_DETOUR 63 /* draft-ietf-mpls-rsvp-lsp-fastreroute-01 */ +#define RSVP_OBJ_SUGGESTED_LABEL 129 /* rfc3473 */ +#define RSVP_OBJ_ACCEPT_LABEL_SET 130 /* rfc3473 */ +#define RSVP_OBJ_RESTART_CAPABILITY 131 /* rfc3473 */ +#define RSVP_OBJ_NOTIFY_REQ 195 /* rfc3473 */ +#define RSVP_OBJ_ADMIN_STATUS 196 /* rfc3473 */ +#define RSVP_OBJ_PROPERTIES 204 /* juniper proprietary */ +#define RSVP_OBJ_FASTREROUTE 205 /* draft-ietf-mpls-rsvp-lsp-fastreroute-01 */ +#define RSVP_OBJ_SESSION_ATTRIBUTE 207 /* rfc3209 */ +#define RSVP_OBJ_CALL_ID 230 /* rfc3474 */ +#define RSVP_OBJ_CALL_OPS 236 /* rfc3474 */ + +static const struct tok rsvp_obj_values[] = { + { RSVP_OBJ_SESSION, "Session" }, + { RSVP_OBJ_RSVP_HOP, "RSVP Hop" }, + { RSVP_OBJ_INTEGRITY, "Integrity" }, + { RSVP_OBJ_TIME_VALUES, "Time Values" }, + { RSVP_OBJ_ERROR_SPEC, "Error Spec" }, + { RSVP_OBJ_SCOPE, "Scope" }, + { RSVP_OBJ_STYLE, "Style" }, + { RSVP_OBJ_FLOWSPEC, "Flowspec" }, + { RSVP_OBJ_FILTERSPEC, "FilterSpec" }, + { RSVP_OBJ_SENDER_TEMPLATE, "Sender Template" }, + { RSVP_OBJ_SENDER_TSPEC, "Sender TSpec" }, + { RSVP_OBJ_ADSPEC, "Adspec" }, + { RSVP_OBJ_POLICY_DATA, "Policy Data" }, + { RSVP_OBJ_CONFIRM, "Confirm" }, + { RSVP_OBJ_LABEL, "Label" }, + { RSVP_OBJ_LABEL_REQ, "Label Request" }, + { RSVP_OBJ_ERO, "ERO" }, + { RSVP_OBJ_RRO, "RRO" }, + { RSVP_OBJ_HELLO, "Hello" }, + { RSVP_OBJ_MESSAGE_ID, "Message ID" }, + { RSVP_OBJ_MESSAGE_ID_ACK, "Message ID Ack" }, + { RSVP_OBJ_MESSAGE_ID_LIST, "Message ID List" }, + { RSVP_OBJ_RECOVERY_LABEL, "Recovery Label" }, + { RSVP_OBJ_UPSTREAM_LABEL, "Upstream Label" }, + { RSVP_OBJ_LABEL_SET, "Label Set" }, + { RSVP_OBJ_ACCEPT_LABEL_SET, "Acceptable Label Set" }, + { RSVP_OBJ_DETOUR, "Detour" }, + { RSVP_OBJ_SUGGESTED_LABEL, "Suggested Label" }, + { RSVP_OBJ_PROPERTIES, "Properties" }, + { RSVP_OBJ_FASTREROUTE, "Fast Re-Route" }, + { RSVP_OBJ_SESSION_ATTRIBUTE, "Session Attribute" }, + { RSVP_OBJ_CALL_ID, "Call-ID" }, + { RSVP_OBJ_CALL_OPS, "Call Capability" }, + { RSVP_OBJ_RESTART_CAPABILITY, "Restart Capability" }, + { RSVP_OBJ_NOTIFY_REQ, "Notify Request" }, + { RSVP_OBJ_PROTECTION, "Protection" }, + { RSVP_OBJ_ADMIN_STATUS, "Administrative Status" }, + { 0, NULL} +}; + +#define RSVP_CTYPE_IPV4 1 +#define RSVP_CTYPE_IPV6 2 +#define RSVP_CTYPE_TUNNEL_IPV4 7 +#define RSVP_CTYPE_TUNNEL_IPV6 8 +#define RSVP_CTYPE_1 1 +#define RSVP_CTYPE_2 2 +#define RSVP_CTYPE_3 3 +#define RSVP_CTYPE_4 4 + +/* + * the ctypes are not globally unique so for + * translating it to strings we build a table based + * on objects offsetted by the ctype + */ + +static const struct tok rsvp_ctype_values[] = { + { 256*RSVP_OBJ_RSVP_HOP+RSVP_CTYPE_IPV4, "IPv4" }, + { 256*RSVP_OBJ_RSVP_HOP+RSVP_CTYPE_IPV6, "IPv6" }, + { 256*RSVP_OBJ_RSVP_HOP+RSVP_CTYPE_3, "IPv4 plus opt. TLVs" }, + { 256*RSVP_OBJ_RSVP_HOP+RSVP_CTYPE_4, "IPv6 plus opt. TLVs" }, + { 256*RSVP_OBJ_NOTIFY_REQ+RSVP_CTYPE_IPV4, "IPv4" }, + { 256*RSVP_OBJ_NOTIFY_REQ+RSVP_CTYPE_IPV6, "IPv6" }, + { 256*RSVP_OBJ_CONFIRM+RSVP_CTYPE_IPV4, "IPv4" }, + { 256*RSVP_OBJ_CONFIRM+RSVP_CTYPE_IPV6, "IPv6" }, + { 256*RSVP_OBJ_TIME_VALUES+RSVP_CTYPE_1, "1" }, + { 256*RSVP_OBJ_FLOWSPEC+RSVP_CTYPE_1, "obsolete" }, + { 256*RSVP_OBJ_FLOWSPEC+RSVP_CTYPE_2, "IntServ" }, + { 256*RSVP_OBJ_SENDER_TSPEC+RSVP_CTYPE_2, "IntServ" }, + { 256*RSVP_OBJ_ADSPEC+RSVP_CTYPE_2, "IntServ" }, + { 256*RSVP_OBJ_FILTERSPEC+RSVP_CTYPE_IPV4, "IPv4" }, + { 256*RSVP_OBJ_FILTERSPEC+RSVP_CTYPE_IPV6, "IPv6" }, + { 256*RSVP_OBJ_FILTERSPEC+RSVP_CTYPE_3, "IPv6 Flow-label" }, + { 256*RSVP_OBJ_FILTERSPEC+RSVP_CTYPE_TUNNEL_IPV4, "Tunnel IPv4" }, + { 256*RSVP_OBJ_SESSION+RSVP_CTYPE_IPV4, "IPv4" }, + { 256*RSVP_OBJ_SESSION+RSVP_CTYPE_IPV6, "IPv6" }, + { 256*RSVP_OBJ_SESSION+RSVP_CTYPE_TUNNEL_IPV4, "Tunnel IPv4" }, + { 256*RSVP_OBJ_SENDER_TEMPLATE+RSVP_CTYPE_IPV4, "IPv4" }, + { 256*RSVP_OBJ_SENDER_TEMPLATE+RSVP_CTYPE_IPV6, "IPv6" }, + { 256*RSVP_OBJ_SENDER_TEMPLATE+RSVP_CTYPE_TUNNEL_IPV4, "Tunnel IPv4" }, + { 256*RSVP_OBJ_STYLE+RSVP_CTYPE_1, "1" }, + { 256*RSVP_OBJ_HELLO+RSVP_CTYPE_1, "Hello Request" }, + { 256*RSVP_OBJ_HELLO+RSVP_CTYPE_2, "Hello Ack" }, + { 256*RSVP_OBJ_LABEL_REQ+RSVP_CTYPE_1, "without label range" }, + { 256*RSVP_OBJ_LABEL_REQ+RSVP_CTYPE_2, "with ATM label range" }, + { 256*RSVP_OBJ_LABEL_REQ+RSVP_CTYPE_3, "with FR label range" }, + { 256*RSVP_OBJ_LABEL_REQ+RSVP_CTYPE_4, "Generalized Label" }, + { 256*RSVP_OBJ_LABEL+RSVP_CTYPE_1, "Label" }, + { 256*RSVP_OBJ_LABEL+RSVP_CTYPE_2, "Generalized Label" }, + { 256*RSVP_OBJ_LABEL+RSVP_CTYPE_3, "Waveband Switching" }, + { 256*RSVP_OBJ_SUGGESTED_LABEL+RSVP_CTYPE_1, "Label" }, + { 256*RSVP_OBJ_SUGGESTED_LABEL+RSVP_CTYPE_2, "Generalized Label" }, + { 256*RSVP_OBJ_SUGGESTED_LABEL+RSVP_CTYPE_3, "Waveband Switching" }, + { 256*RSVP_OBJ_UPSTREAM_LABEL+RSVP_CTYPE_1, "Label" }, + { 256*RSVP_OBJ_UPSTREAM_LABEL+RSVP_CTYPE_2, "Generalized Label" }, + { 256*RSVP_OBJ_UPSTREAM_LABEL+RSVP_CTYPE_3, "Waveband Switching" }, + { 256*RSVP_OBJ_RECOVERY_LABEL+RSVP_CTYPE_1, "Label" }, + { 256*RSVP_OBJ_RECOVERY_LABEL+RSVP_CTYPE_2, "Generalized Label" }, + { 256*RSVP_OBJ_RECOVERY_LABEL+RSVP_CTYPE_3, "Waveband Switching" }, + { 256*RSVP_OBJ_ERO+RSVP_CTYPE_IPV4, "IPv4" }, + { 256*RSVP_OBJ_RRO+RSVP_CTYPE_IPV4, "IPv4" }, + { 256*RSVP_OBJ_ERROR_SPEC+RSVP_CTYPE_IPV4, "IPv4" }, + { 256*RSVP_OBJ_ERROR_SPEC+RSVP_CTYPE_IPV6, "IPv6" }, + { 256*RSVP_OBJ_ERROR_SPEC+RSVP_CTYPE_3, "IPv4 plus opt. TLVs" }, + { 256*RSVP_OBJ_ERROR_SPEC+RSVP_CTYPE_4, "IPv6 plus opt. TLVs" }, + { 256*RSVP_OBJ_RESTART_CAPABILITY+RSVP_CTYPE_1, "IPv4" }, + { 256*RSVP_OBJ_SESSION_ATTRIBUTE+RSVP_CTYPE_TUNNEL_IPV4, "Tunnel IPv4" }, + { 256*RSVP_OBJ_FASTREROUTE+RSVP_CTYPE_TUNNEL_IPV4, "Tunnel IPv4" }, + { 256*RSVP_OBJ_DETOUR+RSVP_CTYPE_TUNNEL_IPV4, "Tunnel IPv4" }, + { 256*RSVP_OBJ_PROPERTIES+RSVP_CTYPE_1, "1" }, + { 0, NULL} +}; + +#define RSVP_OBJ_XRO_MASK_SUBOBJ(x) ((x)&0x7f) +#define RSVP_OBJ_XRO_MASK_LOOSE(x) ((x)&0x80) + +#define RSVP_OBJ_XRO_RES 0 +#define RSVP_OBJ_XRO_IPV4 1 +#define RSVP_OBJ_XRO_IPV6 2 +#define RSVP_OBJ_XRO_ASN 32 +#define RSVP_OBJ_XRO_MPLS 64 + +static const struct tok rsvp_obj_xro_values[] = { + { RSVP_OBJ_XRO_RES, "Reserved" }, + { RSVP_OBJ_XRO_IPV4, "IPv4 prefix" }, + { RSVP_OBJ_XRO_IPV6, "IPv6 prefix" }, + { RSVP_OBJ_XRO_ASN, "Autonomous system number" }, + { RSVP_OBJ_XRO_MPLS, "MPLS label switched path termination" }, + { 0, NULL} +}; + +/* draft-ietf-mpls-rsvp-lsp-fastreroute-02.txt */ +static const struct tok rsvp_obj_rro_flag_values[] = { + { 0x01, "Local protection available" }, + { 0x02, "Local protection in use" }, + { 0x04, "Bandwidth protection" }, + { 0x08, "Node protection" }, + { 0, NULL} +}; + +static const struct tok rsvp_resstyle_values[] = { + { 17, "Wildcard Filter" }, + { 10, "Fixed Filter" }, + { 18, "Shared Explicit" }, + { 0, NULL} +}; + +#define RSVP_OBJ_INTSERV_GUARANTEED_SERV 2 +#define RSVP_OBJ_INTSERV_CONTROLLED_LOAD 5 + +static const struct tok rsvp_intserv_service_type_values[] = { + { 1, "Default/Global Information" }, + { RSVP_OBJ_INTSERV_GUARANTEED_SERV, "Guaranteed Service" }, + { RSVP_OBJ_INTSERV_CONTROLLED_LOAD, "Controlled Load" }, + { 0, NULL} +}; + +static const struct tok rsvp_intserv_parameter_id_values[] = { + { 4, "IS hop cnt" }, + { 6, "Path b/w estimate" }, + { 8, "Minimum path latency" }, + { 10, "Composed MTU" }, + { 127, "Token Bucket TSpec" }, + { 130, "Guaranteed Service RSpec" }, + { 133, "End-to-end composed value for C" }, + { 134, "End-to-end composed value for D" }, + { 135, "Since-last-reshaping point composed C" }, + { 136, "Since-last-reshaping point composed D" }, + { 0, NULL} +}; + +static struct tok rsvp_session_attribute_flag_values[] = { + { 0x01, "Local Protection desired" }, + { 0x02, "Label Recording desired" }, + { 0x04, "SE Style desired" }, + { 0x08, "Bandwidth protection desired" }, /* draft-ietf-mpls-rsvp-lsp-fastreroute-02.txt */ + { 0x10, "Node protection desired" }, /* draft-ietf-mpls-rsvp-lsp-fastreroute-02.txt */ + { 0, NULL} +}; + +static struct tok rsvp_obj_prop_tlv_values[] = { + { 0x01, "Cos" }, + { 0x02, "Metric 1" }, + { 0x04, "Metric 2" }, + { 0x08, "CCC Status" }, + { 0x10, "Path Type" }, + { 0, NULL} +}; + +#define RSVP_OBJ_ERROR_SPEC_CODE_ROUTING 24 +#define RSVP_OBJ_ERROR_SPEC_CODE_NOTIFY 25 + +static struct tok rsvp_obj_error_code_values[] = { + { RSVP_OBJ_ERROR_SPEC_CODE_ROUTING, "Routing Problem" }, + { RSVP_OBJ_ERROR_SPEC_CODE_NOTIFY, "Notify Error" }, + { 0, NULL} +}; + +static struct tok rsvp_obj_error_code_routing_values[] = { + { 1, "Bad EXPLICIT_ROUTE object" }, + { 2, "Bad strict node" }, + { 3, "Bad loose node" }, + { 4, "Bad initial subobject" }, + { 5, "No route available toward destination" }, + { 6, "Unacceptable label value" }, + { 7, "RRO indicated routing loops" }, + { 8, "non-RSVP-capable router in the path" }, + { 9, "MPLS label allocation failure" }, + { 10, "Unsupported L3PID" }, + { 0, NULL} +}; + +#define FALSE 0 +#define TRUE 1 + + +static int rsvp_intserv_print(const u_char *, u_short); + +/* + * this is a dissector for all the intserv defined + * specs as defined per rfc2215 + * it is called from various rsvp objects; + * returns the amount of bytes being processed + */ +static int +rsvp_intserv_print(const u_char *tptr, u_short obj_tlen) { + + int parameter_id,parameter_length; + union { + float f; + u_int32_t i; + } bw; + + if (obj_tlen < 4) + return 0; + parameter_id = *(tptr); + parameter_length = EXTRACT_16BITS(tptr+2)<<2; /* convert wordcount to bytecount */ + + printf("\n\t Parameter ID: %s (%u), length: %u, Flags: [0x%02x]", + tok2str(rsvp_intserv_parameter_id_values,"unknown",parameter_id), + parameter_id, + parameter_length, + *(tptr+1)); + + if (obj_tlen < parameter_length+4) + return 0; + switch(parameter_id) { /* parameter_id */ + + case 4: + /* + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | 4 (e) | (f) | 1 (g) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | IS hop cnt (32-bit unsigned integer) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + if (parameter_length == 4) + printf("\n\t\tIS hop count: %u", EXTRACT_32BITS(tptr+4)); + break; + + case 6: + /* + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | 6 (h) | (i) | 1 (j) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Path b/w estimate (32-bit IEEE floating point number) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + if (parameter_length == 4) { + bw.i = EXTRACT_32BITS(tptr+4); + printf("\n\t\tPath b/w estimate: %.10g Mbps", bw.f/125000); + } + break; + + case 8: + /* + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | 8 (k) | (l) | 1 (m) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Minimum path latency (32-bit integer) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + if (parameter_length == 4) { + printf("\n\t\tMinimum path latency: "); + if (EXTRACT_32BITS(tptr+4) == 0xffffffff) + printf("don't care"); + else + printf("%u", EXTRACT_32BITS(tptr+4)); + } + break; + + case 10: + + /* + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | 10 (n) | (o) | 1 (p) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Composed MTU (32-bit unsigned integer) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + if (parameter_length == 4) + printf("\n\t\tComposed MTU: %u bytes", EXTRACT_32BITS(tptr+4)); + break; + case 127: + /* + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | 127 (e) | 0 (f) | 5 (g) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Token Bucket Rate [r] (32-bit IEEE floating point number) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Token Bucket Size [b] (32-bit IEEE floating point number) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Peak Data Rate [p] (32-bit IEEE floating point number) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Minimum Policed Unit [m] (32-bit integer) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Maximum Packet Size [M] (32-bit integer) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + + if (parameter_length == 20) { + bw.i = EXTRACT_32BITS(tptr+4); + printf("\n\t\tToken Bucket Rate: %.10g Mbps", bw.f/125000); + bw.i = EXTRACT_32BITS(tptr+8); + printf("\n\t\tToken Bucket Size: %.10g bytes", bw.f); + bw.i = EXTRACT_32BITS(tptr+12); + printf("\n\t\tPeak Data Rate: %.10g Mbps", bw.f/125000); + printf("\n\t\tMinimum Policed Unit: %u bytes", EXTRACT_32BITS(tptr+16)); + printf("\n\t\tMaximum Packet Size: %u bytes", EXTRACT_32BITS(tptr+20)); + } + break; + + case 130: + /* + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | 130 (h) | 0 (i) | 2 (j) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Rate [R] (32-bit IEEE floating point number) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Slack Term [S] (32-bit integer) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + + if (parameter_length == 8) { + bw.i = EXTRACT_32BITS(tptr+4); + printf("\n\t\tRate: %.10g Mbps", bw.f/125000); + printf("\n\t\tSlack Term: %u", EXTRACT_32BITS(tptr+8)); + } + break; + + case 133: + case 134: + case 135: + case 136: + if (parameter_length == 4) + printf("\n\t\tValue: %u", EXTRACT_32BITS(tptr+4)); + break; + + default: + if (vflag <= 1) + print_unknown_data(tptr+4,"\n\t\t",parameter_length); + } + return (parameter_length+4); /* header length 4 bytes */ +} + +void +rsvp_print(register const u_char *pptr, register u_int len) { + + const struct rsvp_common_header *rsvp_com_header; + const struct rsvp_object_header *rsvp_obj_header; + const u_char *tptr,*obj_tptr; + u_short tlen,rsvp_obj_len,rsvp_obj_ctype,obj_tlen,intserv_serv_tlen; + int hexdump,processed,padbytes,error_code,error_value; + union { + float f; + u_int32_t i; + } bw; + u_int8_t namelen; + u_int i; + + tptr=pptr; + rsvp_com_header = (const struct rsvp_common_header *)pptr; + TCHECK(*rsvp_com_header); + + /* + * Sanity checking of the header. + */ + if (RSVP_EXTRACT_VERSION(rsvp_com_header->version_flags) != RSVP_VERSION) { + printf("RSVP version %u packet not supported", + RSVP_EXTRACT_VERSION(rsvp_com_header->version_flags)); + return; + } + + /* in non-verbose mode just lets print the basic Message Type*/ + if (vflag < 1) { + printf("RSVP %s Message, length: %u", + tok2str(rsvp_msg_type_values, "unknown (%u)",rsvp_com_header->msg_type), + len); + return; + } + + /* ok they seem to want to know everything - lets fully decode it */ + + tlen=EXTRACT_16BITS(rsvp_com_header->length); + + printf("RSVP\n\tv: %u, msg-type: %s, Flags: [%s], length: %u, ttl: %u, checksum: 0x%04x", + RSVP_EXTRACT_VERSION(rsvp_com_header->version_flags), + tok2str(rsvp_msg_type_values, "unknown, type: %u",rsvp_com_header->msg_type), + bittok2str(rsvp_header_flag_values,"none",RSVP_EXTRACT_FLAGS(rsvp_com_header->version_flags)), + tlen, + rsvp_com_header->ttl, + EXTRACT_16BITS(rsvp_com_header->checksum)); + + if (tlen < sizeof(const struct rsvp_common_header)) + return; + tptr+=sizeof(const struct rsvp_common_header); + tlen-=sizeof(const struct rsvp_common_header); + + while(tlen>0) { + /* did we capture enough for fully decoding the object header ? */ + if (!TTEST2(*tptr, sizeof(struct rsvp_object_header))) + goto trunc; + + rsvp_obj_header = (const struct rsvp_object_header *)tptr; + rsvp_obj_len=EXTRACT_16BITS(rsvp_obj_header->length); + rsvp_obj_ctype=rsvp_obj_header->ctype; + + if(rsvp_obj_len % 4 || rsvp_obj_len < sizeof(struct rsvp_object_header)) + return; + + printf("\n\t %s Object (%u) Flags: [%s", + tok2str(rsvp_obj_values, + "Unknown", + rsvp_obj_header->class_num), + rsvp_obj_header->class_num, + ((rsvp_obj_header->class_num)&0x80) ? "ignore" : "reject"); + + if (rsvp_obj_header->class_num > 128) + printf(" %s", + ((rsvp_obj_header->class_num)&0x40) ? "and forward" : "silently"); + + printf(" if unknown], Class-Type: %s (%u), length: %u", + tok2str(rsvp_ctype_values, + "Unknown", + ((rsvp_obj_header->class_num)<<8)+rsvp_obj_ctype), + rsvp_obj_ctype, + rsvp_obj_len); + + obj_tptr=tptr+sizeof(struct rsvp_object_header); + obj_tlen=rsvp_obj_len-sizeof(struct rsvp_object_header); + + /* did we capture enough for fully decoding the object ? */ + if (!TTEST2(*tptr, rsvp_obj_len)) + goto trunc; + hexdump=FALSE; + + switch(rsvp_obj_header->class_num) { + case RSVP_OBJ_SESSION: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_IPV4: + if (obj_tlen < 8) + return; + printf("\n\t IPv4 DestAddress: %s, Protocol ID: 0x%02x", + ipaddr_string(obj_tptr), + *(obj_tptr+4)); + printf("\n\t Flags: [0x%02x], DestPort %u", + *(obj_tptr+5), + EXTRACT_16BITS(obj_tptr+6)); + obj_tlen-=8; + obj_tptr+=8; + break; +#ifdef INET6 + case RSVP_CTYPE_IPV6: + if (obj_tlen < 20) + return; + printf("\n\t IPv6 DestAddress: %s, Protocol ID: 0x%02x", + ip6addr_string(obj_tptr), + *(obj_tptr+16)); + printf("\n\t Flags: [0x%02x], DestPort %u", + *(obj_tptr+17), + EXTRACT_16BITS(obj_tptr+18)); + obj_tlen-=20; + obj_tptr+=20; + break; + + case RSVP_CTYPE_TUNNEL_IPV6: + if (obj_tlen < 36) + return; + printf("\n\t IPv6 Tunnel EndPoint: %s, Tunnel ID: 0x%04x, Extended Tunnel ID: %s", + ip6addr_string(obj_tptr), + EXTRACT_16BITS(obj_tptr+18), + ip6addr_string(obj_tptr+20)); + obj_tlen-=36; + obj_tptr+=36; + break; +#endif + case RSVP_CTYPE_TUNNEL_IPV4: + if (obj_tlen < 12) + return; + printf("\n\t IPv4 Tunnel EndPoint: %s, Tunnel ID: 0x%04x, Extended Tunnel ID: %s", + ipaddr_string(obj_tptr), + EXTRACT_16BITS(obj_tptr+6), + ipaddr_string(obj_tptr+8)); + obj_tlen-=12; + obj_tptr+=12; + break; + default: + hexdump=TRUE; + } + break; + + case RSVP_OBJ_CONFIRM: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_IPV4: + if (obj_tlen < 4) + return; + printf("\n\t IPv4 Receiver Address: %s", + ipaddr_string(obj_tptr)); + obj_tlen-=4; + obj_tptr+=4; + break; +#ifdef INET6 + case RSVP_CTYPE_IPV6: + if (obj_tlen < 16) + return; + printf("\n\t IPv6 Receiver Address: %s", + ip6addr_string(obj_tptr)); + obj_tlen-=16; + obj_tptr+=16; + break; +#endif + default: + hexdump=TRUE; + } + break; + + case RSVP_OBJ_NOTIFY_REQ: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_IPV4: + if (obj_tlen < 4) + return; + printf("\n\t IPv4 Notify Node Address: %s", + ipaddr_string(obj_tptr)); + obj_tlen-=4; + obj_tptr+=4; + break; +#ifdef INET6 + case RSVP_CTYPE_IPV6: + if (obj_tlen < 16) + return; + printf("\n\t IPv6 Notify Node Address: %s", + ip6addr_string(obj_tptr)); + obj_tlen-=16; + obj_tptr+=16; + break; +#endif + default: + hexdump=TRUE; + } + break; + + case RSVP_OBJ_SUGGESTED_LABEL: /* fall through */ + case RSVP_OBJ_UPSTREAM_LABEL: /* fall through */ + case RSVP_OBJ_RECOVERY_LABEL: /* fall through */ + case RSVP_OBJ_LABEL: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_1: + while(obj_tlen >= 4 ) { + printf("\n\t Label: %u", EXTRACT_32BITS(obj_tptr)); + obj_tlen-=4; + obj_tptr+=4; + } + break; + case RSVP_CTYPE_2: + if (obj_tlen < 4) + return; + printf("\n\t Generalized Label: %u", + EXTRACT_32BITS(obj_tptr)); + obj_tlen-=4; + obj_tptr+=4; + break; + case RSVP_CTYPE_3: + if (obj_tlen < 12) + return; + printf("\n\t Waveband ID: %u\n\t Start Label: %u, Stop Label: %u", + EXTRACT_32BITS(obj_tptr), + EXTRACT_32BITS(obj_tptr+4), + EXTRACT_32BITS(obj_tptr+8)); + obj_tlen-=12; + obj_tptr+=12; + break; + default: + hexdump=TRUE; + } + break; + + case RSVP_OBJ_STYLE: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_1: + if (obj_tlen < 4) + return; + printf("\n\t Reservation Style: %s, Flags: [0x%02x]", + tok2str(rsvp_resstyle_values, + "Unknown", + EXTRACT_24BITS(obj_tptr+1)), + *(obj_tptr)); + obj_tlen-=4; + obj_tptr+=4; + break; + default: + hexdump=TRUE; + } + break; + + case RSVP_OBJ_SENDER_TEMPLATE: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_IPV4: + if (obj_tlen < 8) + return; + printf("\n\t Source Address: %s, Source Port: %u", + ipaddr_string(obj_tptr), + EXTRACT_16BITS(obj_tptr+6)); + obj_tlen-=8; + obj_tptr+=8; + break; +#ifdef INET6 + case RSVP_CTYPE_IPV6: + if (obj_tlen < 20) + return; + printf("\n\t Source Address: %s, Source Port: %u", + ip6addr_string(obj_tptr), + EXTRACT_16BITS(obj_tptr+18)); + obj_tlen-=20; + obj_tptr+=20; + break; +#endif + case RSVP_CTYPE_TUNNEL_IPV4: + if (obj_tlen < 8) + return; + printf("\n\t IPv4 Tunnel Sender Address: %s, LSP-ID: 0x%04x", + ipaddr_string(obj_tptr), + EXTRACT_16BITS(obj_tptr+6)); + obj_tlen-=8; + obj_tptr+=8; + break; + default: + hexdump=TRUE; + } + break; + + case RSVP_OBJ_LABEL_REQ: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_1: + while(obj_tlen >= 4 ) { + printf("\n\t L3 Protocol ID: %s", + tok2str(ethertype_values, + "Unknown Protocol (0x%04x)", + EXTRACT_16BITS(obj_tptr+2))); + obj_tlen-=4; + obj_tptr+=4; + } + break; + case RSVP_CTYPE_2: + if (obj_tlen < 12) + return; + printf("\n\t L3 Protocol ID: %s", + tok2str(ethertype_values, + "Unknown Protocol (0x%04x)", + EXTRACT_16BITS(obj_tptr+2))); + printf(",%s merge capability",((*(obj_tptr+4))&0x80) ? "no" : "" ); + printf("\n\t Minimum VPI/VCI: %u/%u", + (EXTRACT_16BITS(obj_tptr+4))&0xfff, + (EXTRACT_16BITS(obj_tptr+6))&0xfff); + printf("\n\t Maximum VPI/VCI: %u/%u", + (EXTRACT_16BITS(obj_tptr+8))&0xfff, + (EXTRACT_16BITS(obj_tptr+10))&0xfff); + obj_tlen-=12; + obj_tptr+=12; + break; + case RSVP_CTYPE_3: + if (obj_tlen < 12) + return; + printf("\n\t L3 Protocol ID: %s", + tok2str(ethertype_values, + "Unknown Protocol (0x%04x)", + EXTRACT_16BITS(obj_tptr+2))); + printf("\n\t Minimum/Maximum DLCI: %u/%u, %s%s bit DLCI", + (EXTRACT_32BITS(obj_tptr+4))&0x7fffff, + (EXTRACT_32BITS(obj_tptr+8))&0x7fffff, + (((EXTRACT_16BITS(obj_tptr+4)>>7)&3) == 0 ) ? "10" : "", + (((EXTRACT_16BITS(obj_tptr+4)>>7)&3) == 2 ) ? "23" : ""); + obj_tlen-=12; + obj_tptr+=12; + break; + case RSVP_CTYPE_4: + if (obj_tlen < 8) + return; + printf("\n\t LSP Encoding Type: %s (%u)", + tok2str(gmpls_encoding_values, + "Unknown", + *obj_tptr), + *obj_tptr); + printf("\n\t Switching Type: %s (%u), Payload ID: %s (0x%04x)", + tok2str(gmpls_switch_cap_values, + "Unknown", + *(obj_tptr+1)), + *(obj_tptr+1), + tok2str(gmpls_payload_values, + "Unknown", + EXTRACT_16BITS(obj_tptr+2)), + EXTRACT_16BITS(obj_tptr+2)); + obj_tlen-=8; + obj_tptr+=8; + break; + default: + hexdump=TRUE; + } + break; + + case RSVP_OBJ_RRO: + case RSVP_OBJ_ERO: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_IPV4: + while(obj_tlen >= 4 ) { + printf("\n\t Subobject Type: %s", + tok2str(rsvp_obj_xro_values, + "Unknown %u", + RSVP_OBJ_XRO_MASK_SUBOBJ(*obj_tptr))); + switch(RSVP_OBJ_XRO_MASK_SUBOBJ(*obj_tptr)) { + case RSVP_OBJ_XRO_IPV4: + printf(", %s, %s/%u, Flags: [%s]", + RSVP_OBJ_XRO_MASK_LOOSE(*obj_tptr) ? "Loose" : "Strict", + ipaddr_string(obj_tptr+2), + *(obj_tptr+6), + bittok2str(rsvp_obj_rro_flag_values, + "none", + *(obj_tptr+7))); /* rfc3209 says that this field is rsvd. */ + } + obj_tlen-=*(obj_tptr+1); + obj_tptr+=*(obj_tptr+1); + } + break; + default: + hexdump=TRUE; + } + break; + + case RSVP_OBJ_HELLO: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_1: + case RSVP_CTYPE_2: + if (obj_tlen < 8) + return; + printf("\n\t Source Instance: 0x%08x, Destination Instance: 0x%08x", + EXTRACT_32BITS(obj_tptr), + EXTRACT_32BITS(obj_tptr+4)); + obj_tlen-=8; + obj_tptr+=8; + break; + default: + hexdump=TRUE; + } + break; + + case RSVP_OBJ_RESTART_CAPABILITY: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_1: + if (obj_tlen < 8) + return; + printf("\n\t Restart Time: %ums, Recovery Time: %ums", + EXTRACT_16BITS(obj_tptr), + EXTRACT_16BITS(obj_tptr+4)); + obj_tlen-=8; + obj_tptr+=8; + break; + default: + hexdump=TRUE; + } + break; + + case RSVP_OBJ_SESSION_ATTRIBUTE: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_TUNNEL_IPV4: + if (obj_tlen < 4) + return; + namelen = *(obj_tptr+3); + if (obj_tlen < 4+namelen) + return; + printf("\n\t Session Name: "); + for (i = 0; i < namelen; i++) + safeputchar(*(obj_tptr+4+i)); + printf("\n\t Setup Priority: %u, Holding Priority: %u, Flags: [%s]", + (int)*obj_tptr, + (int)*(obj_tptr+1), + tok2str(rsvp_session_attribute_flag_values, + "none", + *(obj_tptr+2))); + + obj_tlen-=4+*(obj_tptr+3); + obj_tptr+=4+*(obj_tptr+3); + break; + default: + hexdump=TRUE; + } + break; + + case RSVP_OBJ_RSVP_HOP: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_3: /* fall through - FIXME add TLV parser */ + case RSVP_CTYPE_IPV4: + if (obj_tlen < 8) + return; + printf("\n\t Previous/Next Interface: %s, Logical Interface Handle: 0x%08x", + ipaddr_string(obj_tptr), + EXTRACT_32BITS(obj_tptr+4)); + obj_tlen-=8; + obj_tptr+=8; + hexdump=TRUE; /* unless we have a TLV parser lets just hexdump */ + break; +#ifdef INET6 + case RSVP_CTYPE_4: /* fall through - FIXME add TLV parser */ + case RSVP_CTYPE_IPV6: + if (obj_tlen < 20) + return; + printf("\n\t Previous/Next Interface: %s, Logical Interface Handle: 0x%08x", + ip6addr_string(obj_tptr), + EXTRACT_32BITS(obj_tptr+16)); + obj_tlen-=20; + obj_tptr+=20; + hexdump=TRUE; /* unless we have a TLV parser lets just hexdump */ + break; +#endif + default: + hexdump=TRUE; + } + break; + + case RSVP_OBJ_TIME_VALUES: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_1: + if (obj_tlen < 4) + return; + printf("\n\t Refresh Period: %ums", + EXTRACT_32BITS(obj_tptr)); + obj_tlen-=4; + obj_tptr+=4; + break; + default: + hexdump=TRUE; + } + break; + + /* those three objects do share the same semantics */ + case RSVP_OBJ_SENDER_TSPEC: + case RSVP_OBJ_ADSPEC: + case RSVP_OBJ_FLOWSPEC: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_2: + if (obj_tlen < 4) + return; + printf("\n\t Msg-Version: %u, length: %u", + (*obj_tptr & 0xf0) >> 4, + EXTRACT_16BITS(obj_tptr+2)<<2); + obj_tptr+=4; /* get to the start of the service header */ + obj_tlen-=4; + + while (obj_tlen >= 4) { + intserv_serv_tlen=EXTRACT_16BITS(obj_tptr+2)<<2; + printf("\n\t Service Type: %s (%u), break bit %s set, Service length: %u", + tok2str(rsvp_intserv_service_type_values,"unknown",*(obj_tptr)), + *(obj_tptr), + (*(obj_tptr+1)&0x80) ? "" : "not", + intserv_serv_tlen); + + obj_tptr+=4; /* get to the start of the parameter list */ + obj_tlen-=4; + + while (intserv_serv_tlen>=4) { + processed = rsvp_intserv_print(obj_tptr, obj_tlen); + if (processed == 0) + break; + obj_tlen-=processed; + intserv_serv_tlen-=processed; + obj_tptr+=processed; + } + } + break; + default: + hexdump=TRUE; + } + break; + + case RSVP_OBJ_FILTERSPEC: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_IPV4: + if (obj_tlen < 8) + return; + printf("\n\t Source Address: %s, Source Port: %u", + ipaddr_string(obj_tptr), + EXTRACT_16BITS(obj_tptr+6)); + obj_tlen-=8; + obj_tptr+=8; + break; +#ifdef INET6 + case RSVP_CTYPE_IPV6: + if (obj_tlen < 20) + return; + printf("\n\t Source Address: %s, Source Port: %u", + ip6addr_string(obj_tptr), + EXTRACT_16BITS(obj_tptr+18)); + obj_tlen-=20; + obj_tptr+=20; + break; + case RSVP_CTYPE_3: + if (obj_tlen < 20) + return; + printf("\n\t Source Address: %s, Flow Label: %u", + ip6addr_string(obj_tptr), + EXTRACT_24BITS(obj_tptr+17)); + obj_tlen-=20; + obj_tptr+=20; + break; + case RSVP_CTYPE_TUNNEL_IPV6: + if (obj_tlen < 20) + return; + printf("\n\t Source Address: %s, LSP-ID: 0x%04x", + ipaddr_string(obj_tptr), + EXTRACT_16BITS(obj_tptr+18)); + obj_tlen-=20; + obj_tptr+=20; + break; +#endif + case RSVP_CTYPE_TUNNEL_IPV4: + if (obj_tlen < 8) + return; + printf("\n\t Source Address: %s, LSP-ID: 0x%04x", + ipaddr_string(obj_tptr), + EXTRACT_16BITS(obj_tptr+6)); + obj_tlen-=8; + obj_tptr+=8; + break; + default: + hexdump=TRUE; + } + break; + + case RSVP_OBJ_FASTREROUTE: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_TUNNEL_IPV4: + if (obj_tlen < 16) + return; + bw.i = EXTRACT_32BITS(obj_tptr+4); + printf("\n\t Setup Priority: %u, Holding Priority: %u, Hop-limit: %u, Bandwidth: %.10g Mbps", + (int)*obj_tptr, + (int)*(obj_tptr+1), + (int)*(obj_tptr+2), + bw.f*8/1000000); + printf("\n\t Include Colors: 0x%08x, Exclude Colors: 0x%08x", + EXTRACT_32BITS(obj_tptr+8), + EXTRACT_32BITS(obj_tptr+12)); + obj_tlen-=16; + obj_tptr+=16; + break; + default: + hexdump=TRUE; + } + break; + + case RSVP_OBJ_DETOUR: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_TUNNEL_IPV4: + while(obj_tlen >= 8) { + printf("\n\t PLR-ID: %s, Avoid-Node-ID: %s", + ipaddr_string(obj_tptr), + ipaddr_string(obj_tptr+4)); + obj_tlen-=8; + obj_tptr+=8; + } + break; + default: + hexdump=TRUE; + } + break; + + case RSVP_OBJ_ERROR_SPEC: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_3: /* fall through - FIXME add TLV parser */ + case RSVP_CTYPE_IPV4: + if (obj_tlen < 8) + return; + error_code=*(obj_tptr+5); + error_value=EXTRACT_16BITS(obj_tptr+6); + printf("\n\t Error Node Adress: %s, Flags: [0x%02x]\n\t Error Code: %s (%u)", + ipaddr_string(obj_tptr), + *(obj_tptr+4), + tok2str(rsvp_obj_error_code_values,"unknown",error_code), + error_code); + switch (error_code) { + case RSVP_OBJ_ERROR_SPEC_CODE_ROUTING: + printf(", Error Value: %s (%u)", + tok2str(rsvp_obj_error_code_routing_values,"unknown",error_value), + error_value); + break; + default: + printf(", Unknown Error Value (%u)", error_value); + break; + } + obj_tlen-=8; + obj_tptr+=8; + break; +#ifdef INET6 + case RSVP_CTYPE_4: /* fall through - FIXME add TLV parser */ + case RSVP_CTYPE_IPV6: + if (obj_tlen < 20) + return; + error_code=*(obj_tptr+17); + error_value=EXTRACT_16BITS(obj_tptr+18); + printf("\n\t Error Node Adress: %s, Flags: [0x%02x]\n\t Error Code: %s (%u)", + ip6addr_string(obj_tptr), + *(obj_tptr+16), + tok2str(rsvp_obj_error_code_values,"unknown",error_code), + error_code); + + switch (error_code) { + case RSVP_OBJ_ERROR_SPEC_CODE_ROUTING: + printf(", Error Value: %s (%u)", + tok2str(rsvp_obj_error_code_routing_values,"unknown",error_value), + error_value); + break; + default: + break; + } + obj_tlen-=20; + obj_tptr+=20; + break; +#endif + default: + hexdump=TRUE; + } + break; + + case RSVP_OBJ_PROPERTIES: + switch(rsvp_obj_ctype) { + case RSVP_CTYPE_1: + if (obj_tlen < 4) + return; + padbytes = EXTRACT_16BITS(obj_tptr+2); + printf("\n\t TLV count: %u, padding bytes: %u", + EXTRACT_16BITS(obj_tptr), + padbytes); + obj_tlen-=4; + obj_tptr+=4; + /* loop through as long there is anything longer than the TLV header (2) */ + while(obj_tlen >= 2 + padbytes) { + printf("\n\t %s TLV (0x%02x), length: %u", /* length includes header */ + tok2str(rsvp_obj_prop_tlv_values,"unknown",*obj_tptr), + *obj_tptr, + *(obj_tptr+1)); + if (obj_tlen < *(obj_tptr+1)) + return; + print_unknown_data(obj_tptr+2,"\n\t\t",*(obj_tptr+1)-2); + obj_tlen-=*(obj_tptr+1); + obj_tptr+=*(obj_tptr+1); + } + break; + default: + hexdump=TRUE; + } + break; + + /* + * FIXME those are the defined objects that lack a decoder + * you are welcome to contribute code ;-) + */ + + case RSVP_OBJ_INTEGRITY: + case RSVP_OBJ_SCOPE: + case RSVP_OBJ_POLICY_DATA: + case RSVP_OBJ_MESSAGE_ID: + case RSVP_OBJ_MESSAGE_ID_ACK: + case RSVP_OBJ_MESSAGE_ID_LIST: + case RSVP_OBJ_LABEL_SET: + case RSVP_OBJ_ACCEPT_LABEL_SET: + case RSVP_OBJ_PROTECTION: + default: + if (vflag <= 1) + print_unknown_data(obj_tptr,"\n\t ",obj_tlen); + break; + } + /* do we want to see an additionally hexdump ? */ + if (vflag > 1 || hexdump==TRUE) + print_unknown_data(tptr+sizeof(sizeof(struct rsvp_object_header)),"\n\t ", + rsvp_obj_len-sizeof(struct rsvp_object_header)); + + tptr+=rsvp_obj_len; + tlen-=rsvp_obj_len; + } + return; +trunc: + printf("\n\t\t packet exceeded snapshot"); +} diff --git a/kame/kame/tcpdump/print-rt6.c b/kame/kame/tcpdump/print-rt6.c index 39c09b3d7b..6adc009ded 100644 --- a/kame/kame/tcpdump/print-rt6.c +++ b/kame/kame/tcpdump/print-rt6.c @@ -20,97 +20,88 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) /master/usr.sbin/tcpdump/tcpdump/print-icmp.c,v 2.1 1995/02/03 18:14:42 polk Exp (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-rt6.c,v 1.23.2.3 2003/11/19 00:35:45 guy Exp $"; #endif -#ifdef INET6 - -#include -#include -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include +#ifdef INET6 -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include -#include +#include "ip6.h" #include "interface.h" #include "addrtoname.h" +#include "extract.h" int rt6_print(register const u_char *bp, register const u_char *bp2) { - register const struct ip6_rthdr0 *dp; + register const struct ip6_rthdr *dp; + register const struct ip6_rthdr0 *dp0; register const struct ip6_hdr *ip; register const u_char *ep; - u_long bitmap = 0x0800; - u_long slmap; int i, len; + register const struct in6_addr *addr; -#if 0 -#define TCHECK(var) if ((u_char *)&(var) >= ep - sizeof(var)) goto trunc -#endif - - dp = (struct ip6_rthdr0 *)bp; + dp = (struct ip6_rthdr *)bp; ip = (struct ip6_hdr *)bp2; - len = dp->ip6r0_len; + len = dp->ip6r_len; - /* 'ep' points to the end of avaible data. */ + /* 'ep' points to the end of available data. */ ep = snapend; - printf("%s > %s: ", - ip6addr_string(&ip->ip6_src), - ip6addr_string(&ip->ip6_dst)); - - TCHECK(dp->ip6r0_slmap[2]); - printf("srcrt (len=%d, ", dp->ip6r0_len); - printf("type=%d, ", dp->ip6r0_type); - printf("segleft=%d, ", dp->ip6r0_segleft); - if (dp->ip6r0_type != 0) - goto trunc; - slmap = (dp->ip6r0_slmap[0] << 16) - | (dp->ip6r0_slmap[1] << 8) - | (dp->ip6r0_slmap[2]); - printf("bitmap="); - for (i = 24; i > 0; i--) { - if (slmap & bitmap) - printf("S"); - else - printf("L"); - bitmap >>= 1; - } - if (len % 2 == 1) + TCHECK(dp->ip6r_segleft); + + printf("srcrt (len=%d", dp->ip6r_len); /*)*/ + printf(", type=%d", dp->ip6r_type); + printf(", segleft=%d", dp->ip6r_segleft); + + switch (dp->ip6r_type) { +#ifndef IPV6_RTHDR_TYPE_0 +#define IPV6_RTHDR_TYPE_0 0 +#endif +#ifndef IPV6_RTHDR_TYPE_2 +#define IPV6_RTHDR_TYPE_2 2 +#endif + case IPV6_RTHDR_TYPE_0: + case IPV6_RTHDR_TYPE_2: /* Mobile IPv6 ID-20 */ + dp0 = (struct ip6_rthdr0 *)dp; + + TCHECK(dp0->ip6r0_reserved); + if (dp0->ip6r0_reserved || vflag) { + printf(", rsv=0x%0x", + EXTRACT_32BITS(&dp0->ip6r0_reserved)); + } + + if (len % 2 == 1) + goto trunc; + len >>= 1; + addr = &dp0->ip6r0_addr[0]; + for (i = 0; i < len; i++) { + if ((u_char *)(addr + 1) > ep) + goto trunc; + + printf(", [%d]%s", i, ip6addr_string(addr)); + addr++; + } + /*(*/ + printf(") "); + return((dp0->ip6r0_len + 1) << 3); + break; + default: goto trunc; - len >>= 1; - printf(", "); - for (i = 0; i < len; i++) { - if ((((u_char *)&(dp->ip6r0_reserved)) + sizeof(u_long) - + (i<<4)) > ep) goto trunc; - printf(" [%d]%s", i, - ip6addr_string(((u_char *)&(dp->ip6r0_reserved)) + - sizeof(u_long) + (i<<4))); - if (i != len - 1) - printf(", "); - + break; } - printf(")"); - return((dp->ip6r0_len + 1) << 3); + trunc: fputs("[|srcrt]", stdout); - return 65535; -#undef TCHECK + return -1; } #endif /* INET6 */ diff --git a/kame/kame/tcpdump/print-rx.c b/kame/kame/tcpdump/print-rx.c new file mode 100644 index 0000000000..64ec7edaad --- /dev/null +++ b/kame/kame/tcpdump/print-rx.c @@ -0,0 +1,2485 @@ +/* + * 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. + * + * In this code, I mainly concern myself with decoding the AFS calls, not + * with the guts of RX, per se. + * + * Bah. If I never look at rx_packet.h again, it will be too soon. + * + * Ken Hornstein + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-rx.c,v 1.35.2.2 2003/11/16 08:51:43 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" + +#include "rx.h" + +#include "ip.h" + +static struct tok rx_types[] = { + { RX_PACKET_TYPE_DATA, "data" }, + { RX_PACKET_TYPE_ACK, "ack" }, + { RX_PACKET_TYPE_BUSY, "busy" }, + { RX_PACKET_TYPE_ABORT, "abort" }, + { RX_PACKET_TYPE_ACKALL, "ackall" }, + { RX_PACKET_TYPE_CHALLENGE, "challenge" }, + { RX_PACKET_TYPE_RESPONSE, "response" }, + { RX_PACKET_TYPE_DEBUG, "debug" }, + { RX_PACKET_TYPE_PARAMS, "params" }, + { RX_PACKET_TYPE_VERSION, "version" }, + { 0, NULL }, +}; + +static struct double_tok { + int flag; /* Rx flag */ + int packetType; /* Packet type */ + const 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[] = { + { 130, "fetch-data" }, + { 131, "fetch-acl" }, + { 132, "fetch-status" }, + { 133, "store-data" }, + { 134, "store-acl" }, + { 135, "store-status" }, + { 136, "remove-file" }, + { 137, "create-file" }, + { 138, "rename" }, + { 139, "symlink" }, + { 140, "link" }, + { 141, "makedir" }, + { 142, "rmdir" }, + { 143, "oldsetlock" }, + { 144, "oldextlock" }, + { 145, "oldrellock" }, + { 146, "get-stats" }, + { 147, "give-cbs" }, + { 148, "get-vlinfo" }, + { 149, "get-vlstats" }, + { 150, "set-vlstats" }, + { 151, "get-rootvl" }, + { 152, "check-token" }, + { 153, "get-time" }, + { 154, "nget-vlinfo" }, + { 155, "bulk-stat" }, + { 156, "setlock" }, + { 157, "extlock" }, + { 158, "rellock" }, + { 159, "xstat-ver" }, + { 160, "get-xstat" }, + { 161, "dfs-lookup" }, + { 162, "dfs-flushcps" }, + { 163, "dfs-symlink" }, + { 220, "residency" }, + { 0, NULL }, +}; + +static struct tok cb_req[] = { + { 204, "callback" }, + { 205, "initcb" }, + { 206, "probe" }, + { 207, "getlock" }, + { 208, "getce" }, + { 209, "xstatver" }, + { 210, "getxstat" }, + { 211, "initcb2" }, + { 212, "whoareyou" }, + { 213, "initcb3" }, + { 214, "probeuuid" }, + { 215, "getsrvprefs" }, + { 216, "getcellservdb" }, + { 217, "getlocalcell" }, + { 218, "getcacheconf" }, + { 0, NULL }, +}; + +static struct tok pt_req[] = { + { 500, "new-user" }, + { 501, "where-is-it" }, + { 502, "dump-entry" }, + { 503, "add-to-group" }, + { 504, "name-to-id" }, + { 505, "id-to-name" }, + { 506, "delete" }, + { 507, "remove-from-group" }, + { 508, "get-cps" }, + { 509, "new-entry" }, + { 510, "list-max" }, + { 511, "set-max" }, + { 512, "list-entry" }, + { 513, "change-entry" }, + { 514, "list-elements" }, + { 515, "same-mbr-of" }, + { 516, "set-fld-sentry" }, + { 517, "list-owned" }, + { 518, "get-cps2" }, + { 519, "get-host-cps" }, + { 520, "update-entry" }, + { 521, "list-entries" }, + { 0, NULL }, +}; + +static struct tok vldb_req[] = { + { 501, "create-entry" }, + { 502, "delete-entry" }, + { 503, "get-entry-by-id" }, + { 504, "get-entry-by-name" }, + { 505, "get-new-volume-id" }, + { 506, "replace-entry" }, + { 507, "update-entry" }, + { 508, "setlock" }, + { 509, "releaselock" }, + { 510, "list-entry" }, + { 511, "list-attrib" }, + { 512, "linked-list" }, + { 513, "get-stats" }, + { 514, "probe" }, + { 515, "get-addrs" }, + { 516, "change-addr" }, + { 517, "create-entry-n" }, + { 518, "get-entry-by-id-n" }, + { 519, "get-entry-by-name-n" }, + { 520, "replace-entry-n" }, + { 521, "list-entry-n" }, + { 522, "list-attrib-n" }, + { 523, "linked-list-n" }, + { 524, "update-entry-by-name" }, + { 525, "create-entry-u" }, + { 526, "get-entry-by-id-u" }, + { 527, "get-entry-by-name-u" }, + { 528, "replace-entry-u" }, + { 529, "list-entry-u" }, + { 530, "list-attrib-u" }, + { 531, "linked-list-u" }, + { 532, "regaddr" }, + { 533, "get-addrs-u" }, + { 534, "list-attrib-n2" }, + { 0, NULL }, +}; + +static struct tok kauth_req[] = { + { 1, "auth-old" }, + { 21, "authenticate" }, + { 22, "authenticate-v2" }, + { 2, "change-pw" }, + { 3, "get-ticket-old" }, + { 23, "get-ticket" }, + { 4, "set-pw" }, + { 5, "set-fields" }, + { 6, "create-user" }, + { 7, "delete-user" }, + { 8, "get-entry" }, + { 9, "list-entry" }, + { 10, "get-stats" }, + { 11, "debug" }, + { 12, "get-pw" }, + { 13, "get-random-key" }, + { 14, "unlock" }, + { 15, "lock-status" }, + { 0, NULL }, +}; + +static struct tok vol_req[] = { + { 100, "create-volume" }, + { 101, "delete-volume" }, + { 102, "restore" }, + { 103, "forward" }, + { 104, "end-trans" }, + { 105, "clone" }, + { 106, "set-flags" }, + { 107, "get-flags" }, + { 108, "trans-create" }, + { 109, "dump" }, + { 110, "get-nth-volume" }, + { 111, "set-forwarding" }, + { 112, "get-name" }, + { 113, "get-status" }, + { 114, "sig-restore" }, + { 115, "list-partitions" }, + { 116, "list-volumes" }, + { 117, "set-id-types" }, + { 118, "monitor" }, + { 119, "partition-info" }, + { 120, "reclone" }, + { 121, "list-one-volume" }, + { 122, "nuke" }, + { 123, "set-date" }, + { 124, "x-list-volumes" }, + { 125, "x-list-one-volume" }, + { 126, "set-info" }, + { 127, "x-list-partitions" }, + { 128, "forward-multiple" }, + { 0, NULL }, +}; + +static struct tok bos_req[] = { + { 80, "create-bnode" }, + { 81, "delete-bnode" }, + { 82, "set-status" }, + { 83, "get-status" }, + { 84, "enumerate-instance" }, + { 85, "get-instance-info" }, + { 86, "get-instance-parm" }, + { 87, "add-superuser" }, + { 88, "delete-superuser" }, + { 89, "list-superusers" }, + { 90, "list-keys" }, + { 91, "add-key" }, + { 92, "delete-key" }, + { 93, "set-cell-name" }, + { 94, "get-cell-name" }, + { 95, "get-cell-host" }, + { 96, "add-cell-host" }, + { 97, "delete-cell-host" }, + { 98, "set-t-status" }, + { 99, "shutdown-all" }, + { 100, "restart-all" }, + { 101, "startup-all" }, + { 102, "set-noauth-flag" }, + { 103, "re-bozo" }, + { 104, "restart" }, + { 105, "start-bozo-install" }, + { 106, "uninstall" }, + { 107, "get-dates" }, + { 108, "exec" }, + { 109, "prune" }, + { 110, "set-restart-time" }, + { 111, "get-restart-time" }, + { 112, "start-bozo-log" }, + { 113, "wait-all" }, + { 114, "get-instance-strings" }, + { 115, "get-restricted" }, + { 116, "set-restricted" }, + { 0, NULL }, +}; + +static struct tok ubik_req[] = { + { 10000, "vote-beacon" }, + { 10001, "vote-debug-old" }, + { 10002, "vote-sdebug-old" }, + { 10003, "vote-getsyncsite" }, + { 10004, "vote-debug" }, + { 10005, "vote-sdebug" }, + { 20000, "disk-begin" }, + { 20001, "disk-commit" }, + { 20002, "disk-lock" }, + { 20003, "disk-write" }, + { 20004, "disk-getversion" }, + { 20005, "disk-getfile" }, + { 20006, "disk-sendfile" }, + { 20007, "disk-abort" }, + { 20008, "disk-releaselocks" }, + { 20009, "disk-truncate" }, + { 20010, "disk-probe" }, + { 20011, "disk-writev" }, + { 20012, "disk-interfaceaddr" }, + { 20013, "disk-setversion" }, + { 0, NULL }, +}; + +#define VOTE_LOW 10000 +#define VOTE_HIGH 10005 +#define DISK_LOW 20000 +#define DISK_HIGH 20013 + +static struct tok cb_types[] = { + { 1, "exclusive" }, + { 2, "shared" }, + { 3, "dropped" }, + { 0, NULL }, +}; + +static struct tok ubik_lock_types[] = { + { 1, "read" }, + { 2, "write" }, + { 3, "wait" }, + { 0, NULL }, +}; + +static const char *voltype[] = { "read-write", "read-only", "backup" }; + +static struct tok afs_fs_errors[] = { + { 101, "salvage volume" }, + { 102, "no such vnode" }, + { 103, "no such volume" }, + { 104, "volume exist" }, + { 105, "no service" }, + { 106, "volume offline" }, + { 107, "voline online" }, + { 108, "diskfull" }, + { 109, "diskquota exceeded" }, + { 110, "volume busy" }, + { 111, "volume moved" }, + { 112, "AFS IO error" }, + { -100, "restarting fileserver" }, + { 0, NULL } +}; + +/* + * Reasons for acknowledging a packet + */ + +static struct tok rx_ack_reasons[] = { + { 1, "ack requested" }, + { 2, "duplicate packet" }, + { 3, "out of sequence" }, + { 4, "exceeds window" }, + { 5, "no buffer space" }, + { 6, "ping" }, + { 7, "ping response" }, + { 8, "delay" }, + { 9, "idle" }, + { 0, NULL }, +}; + +/* + * Cache entries we keep around so we can figure out the RX opcode + * numbers for replies. This allows us to make sense of RX reply packets. + */ + +struct rx_cache_entry { + u_int32_t callnum; /* Call number (net order) */ + struct in_addr client; /* client IP address (net order) */ + struct in_addr server; /* server IP address (net order) */ + int dport; /* server port (host order) */ + u_short serviceId; /* Service identifier (net order) */ + u_int32_t opcode; /* RX opcode (host order) */ +}; + +#define RX_CACHE_SIZE 64 + +static struct rx_cache_entry rx_cache[RX_CACHE_SIZE]; + +static int rx_cache_next = 0; +static int rx_cache_hint = 0; +static void rx_cache_insert(const u_char *, const struct ip *, int); +static int rx_cache_find(const struct rx_header *, const struct ip *, + int, int32_t *); + +static void fs_print(const u_char *, int); +static void fs_reply_print(const u_char *, int, int32_t); +static void acl_print(u_char *, int, u_char *); +static void cb_print(const u_char *, int); +static void cb_reply_print(const u_char *, int, int32_t); +static void prot_print(const u_char *, int); +static void prot_reply_print(const u_char *, int, int32_t); +static void vldb_print(const u_char *, int); +static void vldb_reply_print(const u_char *, int, int32_t); +static void kauth_print(const u_char *, int); +static void kauth_reply_print(const u_char *, int, int32_t); +static void vol_print(const u_char *, int); +static void vol_reply_print(const u_char *, int, int32_t); +static void bos_print(const u_char *, int); +static void bos_reply_print(const u_char *, int, int32_t); +static void ubik_print(const u_char *); +static void ubik_reply_print(const u_char *, int, int32_t); + +static void rx_ack_print(const u_char *, int); + +static int is_ubik(u_int32_t); + +/* + * Handle the rx-level packet. See if we know what port it's going to so + * we can peek at the afs call inside + */ + +void +rx_print(register const u_char *bp, int length, int sport, int dport, + u_char *bp2) +{ + register struct rx_header *rxh; + int i; + int32_t opcode; + + if (snapend - bp < (int)sizeof (struct rx_header)) { + printf(" [|rx] (%d)", length); + return; + } + + rxh = (struct rx_header *) bp; + + printf(" rx %s", tok2str(rx_types, "type %d", rxh->type)); + + if (vflag) { + int firstflag = 0; + + if (vflag > 1) + printf(" cid %08x call# %d", + (int) EXTRACT_32BITS(&rxh->cid), + (int) EXTRACT_32BITS(&rxh->callNumber)); + + printf(" seq %d ser %d", + (int) EXTRACT_32BITS(&rxh->seq), + (int) EXTRACT_32BITS(&rxh->serial)); + + if (vflag > 2) + printf(" secindex %d serviceid %hu", + (int) rxh->securityIndex, + EXTRACT_16BITS(&rxh->serviceId)); + + if (vflag > 1) + for (i = 0; i < NUM_RX_FLAGS; i++) { + if (rxh->flags & rx_flags[i].flag && + (!rx_flags[i].packetType || + rxh->type == rx_flags[i].packetType)) { + if (!firstflag) { + firstflag = 1; + printf(" "); + } else { + printf(","); + } + printf("<%s>", rx_flags[i].s); + } + } + } + + /* + * Try to handle AFS calls that we know about. Check the destination + * port and make sure it's a data packet. Also, make sure the + * seq number is 1 (because otherwise it's a continuation packet, + * and we can't interpret that). Also, seems that reply packets + * do not have the client-init flag set, so we check for that + * as well. + */ + + if (rxh->type == RX_PACKET_TYPE_DATA && + EXTRACT_32BITS(&rxh->seq) == 1 && + rxh->flags & RX_CLIENT_INITIATED) { + + /* + * Insert this call into the call cache table, so we + * have a chance to print out replies + */ + + rx_cache_insert(bp, (const struct ip *) bp2, dport); + + switch (dport) { + case FS_RX_PORT: /* AFS file service */ + fs_print(bp, length); + break; + case CB_RX_PORT: /* AFS callback service */ + cb_print(bp, length); + break; + case PROT_RX_PORT: /* AFS protection service */ + prot_print(bp, length); + break; + case VLDB_RX_PORT: /* AFS VLDB service */ + vldb_print(bp, length); + break; + case KAUTH_RX_PORT: /* AFS Kerberos auth service */ + kauth_print(bp, length); + break; + case VOL_RX_PORT: /* AFS Volume service */ + vol_print(bp, length); + break; + case BOS_RX_PORT: /* AFS BOS service */ + bos_print(bp, length); + break; + default: + ; + } + + /* + * If it's a reply (client-init is _not_ set, but seq is one) + * then look it up in the cache. If we find it, call the reply + * printing functions Note that we handle abort packets here, + * because printing out the return code can be useful at times. + */ + + } else if (((rxh->type == RX_PACKET_TYPE_DATA && + EXTRACT_32BITS(&rxh->seq) == 1) || + rxh->type == RX_PACKET_TYPE_ABORT) && + (rxh->flags & RX_CLIENT_INITIATED) == 0 && + rx_cache_find(rxh, (const struct ip *) bp2, + sport, &opcode)) { + + switch (sport) { + case FS_RX_PORT: /* AFS file service */ + fs_reply_print(bp, length, opcode); + break; + case CB_RX_PORT: /* AFS callback service */ + cb_reply_print(bp, length, opcode); + break; + case PROT_RX_PORT: /* AFS PT service */ + prot_reply_print(bp, length, opcode); + break; + case VLDB_RX_PORT: /* AFS VLDB service */ + vldb_reply_print(bp, length, opcode); + break; + case KAUTH_RX_PORT: /* AFS Kerberos auth service */ + kauth_reply_print(bp, length, opcode); + break; + case VOL_RX_PORT: /* AFS Volume service */ + vol_reply_print(bp, length, opcode); + break; + case BOS_RX_PORT: /* AFS BOS service */ + bos_reply_print(bp, length, opcode); + break; + default: + ; + } + + /* + * If it's an RX ack packet, then use the appropriate ack decoding + * function (there isn't any service-specific information in the + * ack packet, so we can use one for all AFS services) + */ + + } else if (rxh->type == RX_PACKET_TYPE_ACK) + rx_ack_print(bp, length); + + + printf(" (%d)", length); +} + +/* + * Insert an entry into the cache. Taken from print-nfs.c + */ + +static void +rx_cache_insert(const u_char *bp, const struct ip *ip, int dport) +{ + struct rx_cache_entry *rxent; + const struct rx_header *rxh = (const struct rx_header *) bp; + + if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) + return; + + rxent = &rx_cache[rx_cache_next]; + + if (++rx_cache_next >= RX_CACHE_SIZE) + rx_cache_next = 0; + + rxent->callnum = rxh->callNumber; + rxent->client = ip->ip_src; + rxent->server = ip->ip_dst; + rxent->dport = dport; + rxent->serviceId = rxh->serviceId; + rxent->opcode = EXTRACT_32BITS(bp + sizeof(struct rx_header)); +} + +/* + * Lookup an entry in the cache. Also taken from print-nfs.c + * + * Note that because this is a reply, we're looking at the _source_ + * port. + */ + +static int +rx_cache_find(const struct rx_header *rxh, const struct ip *ip, int sport, + int32_t *opcode) +{ + int i; + struct rx_cache_entry *rxent; + u_int32_t clip = ip->ip_dst.s_addr; + u_int32_t sip = ip->ip_src.s_addr; + + /* Start the search where we last left off */ + + i = rx_cache_hint; + do { + rxent = &rx_cache[i]; + if (rxent->callnum == rxh->callNumber && + rxent->client.s_addr == clip && + rxent->server.s_addr == sip && + rxent->serviceId == rxh->serviceId && + rxent->dport == sport) { + + /* We got a match! */ + + rx_cache_hint = i; + *opcode = rxent->opcode; + return(1); + } + if (++i > RX_CACHE_SIZE) + i = 0; + } while (i != rx_cache_hint); + + /* Our search failed */ + return(0); +} + +/* + * These extrememly grody macros handle the printing of various AFS stuff. + */ + +#define FIDOUT() { unsigned long n1, n2, n3; \ + TCHECK2(bp[0], sizeof(int32_t) * 3); \ + n1 = EXTRACT_32BITS(bp); \ + bp += sizeof(int32_t); \ + n2 = EXTRACT_32BITS(bp); \ + bp += sizeof(int32_t); \ + n3 = EXTRACT_32BITS(bp); \ + bp += sizeof(int32_t); \ + printf(" fid %d/%d/%d", (int) n1, (int) n2, (int) n3); \ + } + +#define STROUT(MAX) { unsigned int i; \ + TCHECK2(bp[0], sizeof(int32_t)); \ + i = EXTRACT_32BITS(bp); \ + if (i > (MAX)) \ + goto trunc; \ + bp += sizeof(int32_t); \ + printf(" \""); \ + if (fn_printn(bp, i, snapend)) \ + goto trunc; \ + printf("\""); \ + bp += ((i + sizeof(int32_t) - 1) / sizeof(int32_t)) * sizeof(int32_t); \ + } + +#define INTOUT() { int i; \ + TCHECK2(bp[0], sizeof(int32_t)); \ + i = (int) EXTRACT_32BITS(bp); \ + bp += sizeof(int32_t); \ + printf(" %d", i); \ + } + +#define UINTOUT() { unsigned long i; \ + TCHECK2(bp[0], sizeof(int32_t)); \ + i = EXTRACT_32BITS(bp); \ + bp += sizeof(int32_t); \ + printf(" %lu", i); \ + } + +#define DATEOUT() { time_t t; struct tm *tm; char str[256]; \ + TCHECK2(bp[0], sizeof(int32_t)); \ + t = (time_t) EXTRACT_32BITS(bp); \ + bp += sizeof(int32_t); \ + tm = localtime(&t); \ + strftime(str, 256, "%Y/%m/%d %T", tm); \ + printf(" %s", str); \ + } + +#define STOREATTROUT() { unsigned long mask, i; \ + TCHECK2(bp[0], (sizeof(int32_t)*6)); \ + mask = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \ + if (mask) printf (" StoreStatus"); \ + if (mask & 1) { printf(" date"); DATEOUT(); } \ + else bp += sizeof(int32_t); \ + i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \ + if (mask & 2) printf(" owner %lu", i); \ + i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \ + if (mask & 4) printf(" group %lu", i); \ + i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \ + if (mask & 8) printf(" mode %lo", i & 07777); \ + i = EXTRACT_32BITS(bp); bp += sizeof(int32_t); \ + if (mask & 16) printf(" segsize %lu", i); \ + /* undocumented in 3.3 docu */ \ + if (mask & 1024) printf(" fsync"); \ + } + +#define UBIK_VERSIONOUT() {int32_t epoch; int32_t counter; \ + TCHECK2(bp[0], sizeof(int32_t) * 2); \ + epoch = EXTRACT_32BITS(bp); \ + bp += sizeof(int32_t); \ + counter = EXTRACT_32BITS(bp); \ + bp += sizeof(int32_t); \ + printf(" %d.%d", epoch, counter); \ + } + +#define AFSUUIDOUT() {u_int32_t temp; int i; \ + TCHECK2(bp[0], 11*sizeof(u_int32_t)); \ + temp = EXTRACT_32BITS(bp); \ + bp += sizeof(u_int32_t); \ + printf(" %08x", temp); \ + temp = EXTRACT_32BITS(bp); \ + bp += sizeof(u_int32_t); \ + printf("%04x", temp); \ + temp = EXTRACT_32BITS(bp); \ + bp += sizeof(u_int32_t); \ + printf("%04x", temp); \ + for (i = 0; i < 8; i++) { \ + temp = EXTRACT_32BITS(bp); \ + bp += sizeof(u_int32_t); \ + printf("%02x", (unsigned char) temp); \ + } \ + } + +/* + * This is the sickest one of all + */ + +#define VECOUT(MAX) { u_char *sp; \ + u_char s[AFSNAMEMAX]; \ + int k; \ + if ((MAX) + 1 > sizeof(s)) \ + goto trunc; \ + TCHECK2(bp[0], (MAX) * sizeof(int32_t)); \ + sp = s; \ + for (k = 0; k < (MAX); k++) { \ + *sp++ = (u_char) EXTRACT_32BITS(bp); \ + bp += sizeof(int32_t); \ + } \ + s[(MAX)] = '\0'; \ + printf(" \""); \ + fn_print(s, NULL); \ + printf("\""); \ + } + +/* + * Handle calls to the AFS file service (fs) + */ + +static void +fs_print(register const u_char *bp, int length) +{ + int fs_op; + unsigned long i; + + if (length <= (int)sizeof(struct rx_header)) + return; + + if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) { + goto trunc; + } + + /* + * Print out the afs call we're invoking. The table used here was + * gleaned from fsint/afsint.xg + */ + + fs_op = EXTRACT_32BITS(bp + sizeof(struct rx_header)); + + printf(" fs call %s", tok2str(fs_req, "op#%d", fs_op)); + + /* + * Print out arguments to some of the AFS calls. This stuff is + * all from afsint.xg + */ + + bp += sizeof(struct rx_header) + 4; + + /* + * Sigh. This is gross. Ritchie forgive me. + */ + + switch (fs_op) { + case 130: /* Fetch data */ + FIDOUT(); + printf(" offset"); + UINTOUT(); + printf(" length"); + UINTOUT(); + break; + case 131: /* Fetch ACL */ + case 132: /* Fetch Status */ + case 143: /* Old set lock */ + case 144: /* Old extend lock */ + case 145: /* Old release lock */ + case 156: /* Set lock */ + case 157: /* Extend lock */ + case 158: /* Release lock */ + FIDOUT(); + break; + case 135: /* Store status */ + FIDOUT(); + STOREATTROUT(); + break; + case 133: /* Store data */ + FIDOUT(); + STOREATTROUT(); + printf(" offset"); + UINTOUT(); + printf(" length"); + UINTOUT(); + printf(" flen"); + UINTOUT(); + break; + case 134: /* Store ACL */ + { + char a[AFSOPAQUEMAX+1]; + FIDOUT(); + TCHECK2(bp[0], 4); + i = EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + TCHECK2(bp[0], i); + i = min(AFSOPAQUEMAX, i); + strncpy(a, (char *) bp, i); + a[i] = '\0'; + acl_print((u_char *) a, sizeof(a), (u_char *) a + i); + break; + } + case 137: /* Create file */ + case 141: /* MakeDir */ + FIDOUT(); + STROUT(AFSNAMEMAX); + STOREATTROUT(); + break; + case 136: /* Remove file */ + case 142: /* Remove directory */ + FIDOUT(); + STROUT(AFSNAMEMAX); + break; + case 138: /* Rename file */ + printf(" old"); + FIDOUT(); + STROUT(AFSNAMEMAX); + printf(" new"); + FIDOUT(); + STROUT(AFSNAMEMAX); + break; + case 139: /* Symlink */ + FIDOUT(); + STROUT(AFSNAMEMAX); + printf(" link to"); + STROUT(AFSNAMEMAX); + break; + case 140: /* Link */ + FIDOUT(); + STROUT(AFSNAMEMAX); + printf(" link to"); + FIDOUT(); + break; + case 148: /* Get volume info */ + STROUT(AFSNAMEMAX); + break; + case 149: /* Get volume stats */ + case 150: /* Set volume stats */ + printf(" volid"); + UINTOUT(); + break; + case 154: /* New get volume info */ + printf(" volname"); + STROUT(AFSNAMEMAX); + break; + case 155: /* Bulk stat */ + { + unsigned long j; + TCHECK2(bp[0], 4); + j = EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + + for (i = 0; i < j; i++) { + FIDOUT(); + if (i != j - 1) + printf(","); + } + if (j == 0) + printf(" "); + } + default: + ; + } + + return; + +trunc: + printf(" [|fs]"); +} + +/* + * Handle replies to the AFS file service + */ + +static void +fs_reply_print(register const u_char *bp, int length, int32_t opcode) +{ + unsigned long i; + struct rx_header *rxh; + + if (length <= (int)sizeof(struct rx_header)) + return; + + rxh = (struct rx_header *) bp; + + /* + * Print out the afs call we're invoking. The table used here was + * gleaned from fsint/afsint.xg + */ + + printf(" fs reply %s", tok2str(fs_req, "op#%d", opcode)); + + bp += sizeof(struct rx_header); + + /* + * If it was a data packet, interpret the response + */ + + if (rxh->type == RX_PACKET_TYPE_DATA) { + switch (opcode) { + case 131: /* Fetch ACL */ + { + char a[AFSOPAQUEMAX+1]; + TCHECK2(bp[0], 4); + i = EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + TCHECK2(bp[0], i); + i = min(AFSOPAQUEMAX, i); + strncpy(a, (char *) bp, i); + a[i] = '\0'; + acl_print((u_char *) a, sizeof(a), (u_char *) a + i); + break; + } + case 137: /* Create file */ + case 141: /* MakeDir */ + printf(" new"); + FIDOUT(); + break; + case 151: /* Get root volume */ + printf(" root volume"); + STROUT(AFSNAMEMAX); + break; + case 153: /* Get time */ + DATEOUT(); + break; + default: + ; + } + } else if (rxh->type == RX_PACKET_TYPE_ABORT) { + int i; + + /* + * Otherwise, just print out the return code + */ + TCHECK2(bp[0], sizeof(int32_t)); + i = (int) EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + + printf(" error %s", tok2str(afs_fs_errors, "#%d", i)); + } else { + printf(" strange fs reply of type %d", rxh->type); + } + + return; + +trunc: + printf(" [|fs]"); +} + +/* + * Print out an AFS ACL string. An AFS ACL is a string that has the + * following format: + * + * + * + * .... + * + * "positive" and "negative" are integers which contain the number of + * positive and negative ACL's in the string. The uid/aclbits pair are + * ASCII strings containing the UID/PTS record and and a ascii number + * representing a logical OR of all the ACL permission bits + */ + +static void +acl_print(u_char *s, int maxsize, u_char *end) +{ + int pos, neg, acl; + int n, i; + char *user; + + if ((user = (char *)malloc(maxsize)) == NULL) + return; + + if (sscanf((char *) s, "%d %d\n%n", &pos, &neg, &n) != 2) + goto finish; + + s += n; + + if (s > end) + goto finish; + + /* + * This wacky order preserves the order used by the "fs" command + */ + +#define ACLOUT(acl) \ + if (acl & PRSFS_READ) \ + printf("r"); \ + if (acl & PRSFS_LOOKUP) \ + printf("l"); \ + if (acl & PRSFS_INSERT) \ + printf("i"); \ + if (acl & PRSFS_DELETE) \ + printf("d"); \ + if (acl & PRSFS_WRITE) \ + printf("w"); \ + if (acl & PRSFS_LOCK) \ + printf("k"); \ + if (acl & PRSFS_ADMINISTER) \ + printf("a"); + + for (i = 0; i < pos; i++) { + if (sscanf((char *) s, "%s %d\n%n", user, &acl, &n) != 2) + goto finish; + s += n; + printf(" +{"); + fn_print((u_char *)user, NULL); + printf(" "); + ACLOUT(acl); + printf("}"); + if (s > end) + goto finish; + } + + for (i = 0; i < neg; i++) { + if (sscanf((char *) s, "%s %d\n%n", user, &acl, &n) != 2) + goto finish; + s += n; + printf(" -{"); + fn_print((u_char *)user, NULL); + printf(" "); + ACLOUT(acl); + printf("}"); + if (s > end) + goto finish; + } + +finish: + free(user); + return; +} + +#undef ACLOUT + +/* + * Handle calls to the AFS callback service + */ + +static void +cb_print(register const u_char *bp, int length) +{ + int cb_op; + unsigned long i; + + if (length <= (int)sizeof(struct rx_header)) + return; + + if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) { + goto trunc; + } + + /* + * Print out the afs call we're invoking. The table used here was + * gleaned from fsint/afscbint.xg + */ + + cb_op = EXTRACT_32BITS(bp + sizeof(struct rx_header)); + + printf(" cb call %s", tok2str(cb_req, "op#%d", cb_op)); + + bp += sizeof(struct rx_header) + 4; + + /* + * Print out the afs call we're invoking. The table used here was + * gleaned from fsint/afscbint.xg + */ + + switch (cb_op) { + case 204: /* Callback */ + { + unsigned long j, t; + TCHECK2(bp[0], 4); + j = EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + + for (i = 0; i < j; i++) { + FIDOUT(); + if (i != j - 1) + printf(","); + } + + if (j == 0) + printf(" "); + + j = EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + + if (j != 0) + printf(";"); + + for (i = 0; i < j; i++) { + printf(" ver"); + INTOUT(); + printf(" expires"); + DATEOUT(); + TCHECK2(bp[0], 4); + t = EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + tok2str(cb_types, "type %d", t); + } + } + case 214: { + printf(" afsuuid"); + AFSUUIDOUT(); + break; + } + default: + ; + } + + return; + +trunc: + printf(" [|cb]"); +} + +/* + * Handle replies to the AFS Callback Service + */ + +static void +cb_reply_print(register const u_char *bp, int length, int32_t opcode) +{ + struct rx_header *rxh; + + if (length <= (int)sizeof(struct rx_header)) + return; + + rxh = (struct rx_header *) bp; + + /* + * Print out the afs call we're invoking. The table used here was + * gleaned from fsint/afscbint.xg + */ + + printf(" cb reply %s", tok2str(cb_req, "op#%d", opcode)); + + bp += sizeof(struct rx_header); + + /* + * If it was a data packet, interpret the response. + */ + + if (rxh->type == RX_PACKET_TYPE_DATA) + switch (opcode) { + case 213: /* InitCallBackState3 */ + AFSUUIDOUT(); + break; + default: + ; + } + else { + /* + * Otherwise, just print out the return code + */ + printf(" errcode"); + INTOUT(); + } + + return; + +trunc: + printf(" [|cb]"); +} + +/* + * Handle calls to the AFS protection database server + */ + +static void +prot_print(register const u_char *bp, int length) +{ + unsigned long i; + int pt_op; + + if (length <= (int)sizeof(struct rx_header)) + return; + + if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) { + goto trunc; + } + + /* + * Print out the afs call we're invoking. The table used here was + * gleaned from ptserver/ptint.xg + */ + + pt_op = EXTRACT_32BITS(bp + sizeof(struct rx_header)); + + printf(" pt"); + + if (is_ubik(pt_op)) { + ubik_print(bp); + return; + } + + printf(" call %s", tok2str(pt_req, "op#%d", pt_op)); + + /* + * Decode some of the arguments to the PT calls + */ + + bp += sizeof(struct rx_header) + 4; + + switch (pt_op) { + case 500: /* I New User */ + STROUT(PRNAMEMAX); + printf(" id"); + INTOUT(); + printf(" oldid"); + INTOUT(); + break; + case 501: /* Where is it */ + case 506: /* Delete */ + case 508: /* Get CPS */ + case 512: /* List entry */ + case 514: /* List elements */ + case 517: /* List owned */ + case 518: /* Get CPS2 */ + case 519: /* Get host CPS */ + printf(" id"); + INTOUT(); + break; + case 502: /* Dump entry */ + printf(" pos"); + INTOUT(); + break; + case 503: /* Add to group */ + case 507: /* Remove from group */ + case 515: /* Is a member of? */ + printf(" uid"); + INTOUT(); + printf(" gid"); + INTOUT(); + break; + case 504: /* Name to ID */ + { + unsigned long j; + TCHECK2(bp[0], 4); + j = EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + + /* + * Who designed this chicken-shit protocol? + * + * Each character is stored as a 32-bit + * integer! + */ + + for (i = 0; i < j; i++) { + VECOUT(PRNAMEMAX); + } + if (j == 0) + printf(" "); + } + break; + case 505: /* Id to name */ + { + unsigned long j; + printf(" ids:"); + TCHECK2(bp[0], 4); + i = EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + for (j = 0; j < i; j++) + INTOUT(); + if (j == 0) + printf(" "); + } + break; + case 509: /* New entry */ + STROUT(PRNAMEMAX); + printf(" flag"); + INTOUT(); + printf(" oid"); + INTOUT(); + break; + case 511: /* Set max */ + printf(" id"); + INTOUT(); + printf(" gflag"); + INTOUT(); + break; + case 513: /* Change entry */ + printf(" id"); + INTOUT(); + STROUT(PRNAMEMAX); + printf(" oldid"); + INTOUT(); + printf(" newid"); + INTOUT(); + break; + case 520: /* Update entry */ + printf(" id"); + INTOUT(); + STROUT(PRNAMEMAX); + break; + default: + ; + } + + + return; + +trunc: + printf(" [|pt]"); +} + +/* + * Handle replies to the AFS protection service + */ + +static void +prot_reply_print(register const u_char *bp, int length, int32_t opcode) +{ + struct rx_header *rxh; + unsigned long i; + + if (length < (int)sizeof(struct rx_header)) + return; + + rxh = (struct rx_header *) bp; + + /* + * Print out the afs call we're invoking. The table used here was + * gleaned from ptserver/ptint.xg. Check to see if it's a + * Ubik call, however. + */ + + printf(" pt"); + + if (is_ubik(opcode)) { + ubik_reply_print(bp, length, opcode); + return; + } + + printf(" reply %s", tok2str(pt_req, "op#%d", opcode)); + + bp += sizeof(struct rx_header); + + /* + * If it was a data packet, interpret the response + */ + + if (rxh->type == RX_PACKET_TYPE_DATA) + switch (opcode) { + case 504: /* Name to ID */ + { + unsigned long j; + printf(" ids:"); + TCHECK2(bp[0], 4); + i = EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + for (j = 0; j < i; j++) + INTOUT(); + if (j == 0) + printf(" "); + } + break; + case 505: /* ID to name */ + { + unsigned long j; + TCHECK2(bp[0], 4); + j = EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + + /* + * Who designed this chicken-shit protocol? + * + * Each character is stored as a 32-bit + * integer! + */ + + for (i = 0; i < j; i++) { + VECOUT(PRNAMEMAX); + } + if (j == 0) + printf(" "); + } + break; + case 508: /* Get CPS */ + case 514: /* List elements */ + case 517: /* List owned */ + case 518: /* Get CPS2 */ + case 519: /* Get host CPS */ + { + unsigned long j; + TCHECK2(bp[0], 4); + j = EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + for (i = 0; i < j; i++) { + INTOUT(); + } + if (j == 0) + printf(" "); + } + break; + case 510: /* List max */ + printf(" maxuid"); + INTOUT(); + printf(" maxgid"); + INTOUT(); + break; + default: + ; + } + else { + /* + * Otherwise, just print out the return code + */ + printf(" errcode"); + INTOUT(); + } + + return; + +trunc: + printf(" [|pt]"); +} + +/* + * Handle calls to the AFS volume location database service + */ + +static void +vldb_print(register const u_char *bp, int length) +{ + int vldb_op; + unsigned long i; + + if (length <= (int)sizeof(struct rx_header)) + return; + + if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) { + goto trunc; + } + + /* + * Print out the afs call we're invoking. The table used here was + * gleaned from vlserver/vldbint.xg + */ + + vldb_op = EXTRACT_32BITS(bp + sizeof(struct rx_header)); + + printf(" vldb"); + + if (is_ubik(vldb_op)) { + ubik_print(bp); + return; + } + printf(" call %s", tok2str(vldb_req, "op#%d", vldb_op)); + + /* + * Decode some of the arguments to the VLDB calls + */ + + bp += sizeof(struct rx_header) + 4; + + switch (vldb_op) { + case 501: /* Create new volume */ + case 517: /* Create entry N */ + VECOUT(VLNAMEMAX); + break; + case 502: /* Delete entry */ + case 503: /* Get entry by ID */ + case 507: /* Update entry */ + case 508: /* Set lock */ + case 509: /* Release lock */ + case 518: /* Get entry by ID N */ + printf(" volid"); + INTOUT(); + TCHECK2(bp[0], sizeof(int32_t)); + i = EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + if (i <= 2) + printf(" type %s", voltype[i]); + break; + case 504: /* Get entry by name */ + case 519: /* Get entry by name N */ + case 524: /* Update entry by name */ + case 527: /* Get entry by name U */ + STROUT(VLNAMEMAX); + break; + case 505: /* Get new vol id */ + printf(" bump"); + INTOUT(); + break; + case 506: /* Replace entry */ + case 520: /* Replace entry N */ + printf(" volid"); + INTOUT(); + TCHECK2(bp[0], sizeof(int32_t)); + i = EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + if (i <= 2) + printf(" type %s", voltype[i]); + VECOUT(VLNAMEMAX); + break; + case 510: /* List entry */ + case 521: /* List entry N */ + printf(" index"); + INTOUT(); + break; + default: + ; + } + + return; + +trunc: + printf(" [|vldb]"); +} + +/* + * Handle replies to the AFS volume location database service + */ + +static void +vldb_reply_print(register const u_char *bp, int length, int32_t opcode) +{ + struct rx_header *rxh; + unsigned long i; + + if (length < (int)sizeof(struct rx_header)) + return; + + rxh = (struct rx_header *) bp; + + /* + * Print out the afs call we're invoking. The table used here was + * gleaned from vlserver/vldbint.xg. Check to see if it's a + * Ubik call, however. + */ + + printf(" vldb"); + + if (is_ubik(opcode)) { + ubik_reply_print(bp, length, opcode); + return; + } + + printf(" reply %s", tok2str(vldb_req, "op#%d", opcode)); + + bp += sizeof(struct rx_header); + + /* + * If it was a data packet, interpret the response + */ + + if (rxh->type == RX_PACKET_TYPE_DATA) + switch (opcode) { + case 510: /* List entry */ + printf(" count"); + INTOUT(); + printf(" nextindex"); + INTOUT(); + case 503: /* Get entry by id */ + case 504: /* Get entry by name */ + { unsigned long nservers, j; + VECOUT(VLNAMEMAX); + TCHECK2(bp[0], sizeof(int32_t)); + bp += sizeof(int32_t); + printf(" numservers"); + TCHECK2(bp[0], sizeof(int32_t)); + nservers = EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + printf(" %lu", nservers); + printf(" servers"); + for (i = 0; i < 8; i++) { + TCHECK2(bp[0], sizeof(int32_t)); + if (i < nservers) + printf(" %s", + intoa(((struct in_addr *) bp)->s_addr)); + bp += sizeof(int32_t); + } + printf(" partitions"); + for (i = 0; i < 8; i++) { + TCHECK2(bp[0], sizeof(int32_t)); + j = EXTRACT_32BITS(bp); + if (i < nservers && j <= 26) + printf(" %c", 'a' + (int)j); + else if (i < nservers) + printf(" %lu", j); + bp += sizeof(int32_t); + } + TCHECK2(bp[0], 8 * sizeof(int32_t)); + bp += 8 * sizeof(int32_t); + printf(" rwvol"); + UINTOUT(); + printf(" rovol"); + UINTOUT(); + printf(" backup"); + UINTOUT(); + } + break; + case 505: /* Get new volume ID */ + printf(" newvol"); + UINTOUT(); + break; + case 521: /* List entry */ + case 529: /* List entry U */ + printf(" count"); + INTOUT(); + printf(" nextindex"); + INTOUT(); + case 518: /* Get entry by ID N */ + case 519: /* Get entry by name N */ + { unsigned long nservers, j; + VECOUT(VLNAMEMAX); + printf(" numservers"); + TCHECK2(bp[0], sizeof(int32_t)); + nservers = EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + printf(" %lu", nservers); + printf(" servers"); + for (i = 0; i < 13; i++) { + TCHECK2(bp[0], sizeof(int32_t)); + if (i < nservers) + printf(" %s", + intoa(((struct in_addr *) bp)->s_addr)); + bp += sizeof(int32_t); + } + printf(" partitions"); + for (i = 0; i < 13; i++) { + TCHECK2(bp[0], sizeof(int32_t)); + j = EXTRACT_32BITS(bp); + if (i < nservers && j <= 26) + printf(" %c", 'a' + (int)j); + else if (i < nservers) + printf(" %lu", j); + bp += sizeof(int32_t); + } + TCHECK2(bp[0], 13 * sizeof(int32_t)); + bp += 13 * sizeof(int32_t); + printf(" rwvol"); + UINTOUT(); + printf(" rovol"); + UINTOUT(); + printf(" backup"); + UINTOUT(); + } + break; + case 526: /* Get entry by ID U */ + case 527: /* Get entry by name U */ + { unsigned long nservers, j; + VECOUT(VLNAMEMAX); + printf(" numservers"); + TCHECK2(bp[0], sizeof(int32_t)); + nservers = EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + printf(" %lu", nservers); + printf(" servers"); + for (i = 0; i < 13; i++) { + if (i < nservers) { + printf(" afsuuid"); + AFSUUIDOUT(); + } else { + TCHECK2(bp[0], 44); + bp += 44; + } + } + TCHECK2(bp[0], 4 * 13); + bp += 4 * 13; + printf(" partitions"); + for (i = 0; i < 13; i++) { + TCHECK2(bp[0], sizeof(int32_t)); + j = EXTRACT_32BITS(bp); + if (i < nservers && j <= 26) + printf(" %c", 'a' + (int)j); + else if (i < nservers) + printf(" %lu", j); + bp += sizeof(int32_t); + } + TCHECK2(bp[0], 13 * sizeof(int32_t)); + bp += 13 * sizeof(int32_t); + printf(" rwvol"); + UINTOUT(); + printf(" rovol"); + UINTOUT(); + printf(" backup"); + UINTOUT(); + } + default: + ; + } + + else { + /* + * Otherwise, just print out the return code + */ + printf(" errcode"); + INTOUT(); + } + + return; + +trunc: + printf(" [|vldb]"); +} + +/* + * Handle calls to the AFS Kerberos Authentication service + */ + +static void +kauth_print(register const u_char *bp, int length) +{ + int kauth_op; + + if (length <= (int)sizeof(struct rx_header)) + return; + + if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) { + goto trunc; + } + + /* + * Print out the afs call we're invoking. The table used here was + * gleaned from kauth/kauth.rg + */ + + kauth_op = EXTRACT_32BITS(bp + sizeof(struct rx_header)); + + printf(" kauth"); + + if (is_ubik(kauth_op)) { + ubik_print(bp); + return; + } + + + printf(" call %s", tok2str(kauth_req, "op#%d", kauth_op)); + + /* + * Decode some of the arguments to the KA calls + */ + + bp += sizeof(struct rx_header) + 4; + + switch (kauth_op) { + case 1: /* Authenticate old */; + case 21: /* Authenticate */ + case 22: /* Authenticate-V2 */ + case 2: /* Change PW */ + case 5: /* Set fields */ + case 6: /* Create user */ + case 7: /* Delete user */ + case 8: /* Get entry */ + case 14: /* Unlock */ + case 15: /* Lock status */ + printf(" principal"); + STROUT(KANAMEMAX); + STROUT(KANAMEMAX); + break; + case 3: /* GetTicket-old */ + case 23: /* GetTicket */ + { + int i; + printf(" kvno"); + INTOUT(); + printf(" domain"); + STROUT(KANAMEMAX); + TCHECK2(bp[0], sizeof(int32_t)); + i = (int) EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + TCHECK2(bp[0], i); + bp += i; + printf(" principal"); + STROUT(KANAMEMAX); + STROUT(KANAMEMAX); + break; + } + case 4: /* Set Password */ + printf(" principal"); + STROUT(KANAMEMAX); + STROUT(KANAMEMAX); + printf(" kvno"); + INTOUT(); + break; + case 12: /* Get password */ + printf(" name"); + STROUT(KANAMEMAX); + break; + default: + ; + } + + return; + +trunc: + printf(" [|kauth]"); +} + +/* + * Handle replies to the AFS Kerberos Authentication Service + */ + +static void +kauth_reply_print(register const u_char *bp, int length, int32_t opcode) +{ + struct rx_header *rxh; + + if (length <= (int)sizeof(struct rx_header)) + return; + + rxh = (struct rx_header *) bp; + + /* + * Print out the afs call we're invoking. The table used here was + * gleaned from kauth/kauth.rg + */ + + printf(" kauth"); + + if (is_ubik(opcode)) { + ubik_reply_print(bp, length, opcode); + return; + } + + printf(" reply %s", tok2str(kauth_req, "op#%d", opcode)); + + bp += sizeof(struct rx_header); + + /* + * If it was a data packet, interpret the response. + */ + + if (rxh->type == RX_PACKET_TYPE_DATA) + /* Well, no, not really. Leave this for later */ + ; + else { + /* + * Otherwise, just print out the return code + */ + printf(" errcode"); + INTOUT(); + } + + return; + +trunc: + printf(" [|kauth]"); +} + +/* + * Handle calls to the AFS Volume location service + */ + +static void +vol_print(register const u_char *bp, int length) +{ + int vol_op; + + if (length <= (int)sizeof(struct rx_header)) + return; + + if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) { + goto trunc; + } + + /* + * Print out the afs call we're invoking. The table used here was + * gleaned from volser/volint.xg + */ + + vol_op = EXTRACT_32BITS(bp + sizeof(struct rx_header)); + + printf(" vol call %s", tok2str(vol_req, "op#%d", vol_op)); + + /* + * Normally there would be a switch statement here to decode the + * arguments to the AFS call, but since I don't have access to + * an AFS server (yet) and I'm not an AFS admin, I can't + * test any of these calls. Leave this blank for now. + */ + + return; + +trunc: + printf(" [|vol]"); +} + +/* + * Handle replies to the AFS Volume Service + */ + +static void +vol_reply_print(register const u_char *bp, int length, int32_t opcode) +{ + struct rx_header *rxh; + + if (length <= (int)sizeof(struct rx_header)) + return; + + rxh = (struct rx_header *) bp; + + /* + * Print out the afs call we're invoking. The table used here was + * gleaned from volser/volint.xg + */ + + printf(" vol reply %s", tok2str(vol_req, "op#%d", opcode)); + + bp += sizeof(struct rx_header); + + /* + * If it was a data packet, interpret the response. + */ + + if (rxh->type == RX_PACKET_TYPE_DATA) + /* Well, no, not really. Leave this for later */ + ; + else { + /* + * Otherwise, just print out the return code + */ + printf(" errcode"); + INTOUT(); + } + + return; + +trunc: + printf(" [|vol]"); +} + +/* + * Handle calls to the AFS BOS service + */ + +static void +bos_print(register const u_char *bp, int length) +{ + int bos_op; + + if (length <= (int)sizeof(struct rx_header)) + return; + + if (snapend - bp + 1 <= (int)(sizeof(struct rx_header) + sizeof(int32_t))) { + goto trunc; + } + + /* + * Print out the afs call we're invoking. The table used here was + * gleaned from bozo/bosint.xg + */ + + bos_op = EXTRACT_32BITS(bp + sizeof(struct rx_header)); + + printf(" bos call %s", tok2str(bos_req, "op#%d", bos_op)); + + /* + * Decode some of the arguments to the BOS calls + */ + + bp += sizeof(struct rx_header) + 4; + + switch (bos_op) { + case 80: /* Create B node */ + printf(" type"); + STROUT(BOSNAMEMAX); + printf(" instance"); + STROUT(BOSNAMEMAX); + break; + case 81: /* Delete B node */ + case 83: /* Get status */ + case 85: /* Get instance info */ + case 87: /* Add super user */ + case 88: /* Delete super user */ + case 93: /* Set cell name */ + case 96: /* Add cell host */ + case 97: /* Delete cell host */ + case 104: /* Restart */ + case 106: /* Uninstall */ + case 108: /* Exec */ + case 112: /* Getlog */ + case 114: /* Get instance strings */ + STROUT(BOSNAMEMAX); + break; + case 82: /* Set status */ + case 98: /* Set T status */ + STROUT(BOSNAMEMAX); + printf(" status"); + INTOUT(); + break; + case 86: /* Get instance parm */ + STROUT(BOSNAMEMAX); + printf(" num"); + INTOUT(); + break; + case 84: /* Enumerate instance */ + case 89: /* List super users */ + case 90: /* List keys */ + case 91: /* Add key */ + case 92: /* Delete key */ + case 95: /* Get cell host */ + INTOUT(); + break; + case 105: /* Install */ + STROUT(BOSNAMEMAX); + printf(" size"); + INTOUT(); + printf(" flags"); + INTOUT(); + printf(" date"); + INTOUT(); + break; + default: + ; + } + + return; + +trunc: + printf(" [|bos]"); +} + +/* + * Handle replies to the AFS BOS Service + */ + +static void +bos_reply_print(register const u_char *bp, int length, int32_t opcode) +{ + struct rx_header *rxh; + + if (length <= (int)sizeof(struct rx_header)) + return; + + rxh = (struct rx_header *) bp; + + /* + * Print out the afs call we're invoking. The table used here was + * gleaned from volser/volint.xg + */ + + printf(" bos reply %s", tok2str(bos_req, "op#%d", opcode)); + + bp += sizeof(struct rx_header); + + /* + * If it was a data packet, interpret the response. + */ + + if (rxh->type == RX_PACKET_TYPE_DATA) + /* Well, no, not really. Leave this for later */ + ; + else { + /* + * Otherwise, just print out the return code + */ + printf(" errcode"); + INTOUT(); + } + + return; + +trunc: + printf(" [|bos]"); +} + +/* + * Check to see if this is a Ubik opcode. + */ + +static int +is_ubik(u_int32_t opcode) +{ + if ((opcode >= VOTE_LOW && opcode <= VOTE_HIGH) || + (opcode >= DISK_LOW && opcode <= DISK_HIGH)) + return(1); + else + return(0); +} + +/* + * Handle Ubik opcodes to any one of the replicated database services + */ + +static void +ubik_print(register const u_char *bp) +{ + int ubik_op; + int32_t temp; + + /* + * Print out the afs call we're invoking. The table used here was + * gleaned from ubik/ubik_int.xg + */ + + ubik_op = EXTRACT_32BITS(bp + sizeof(struct rx_header)); + + printf(" ubik call %s", tok2str(ubik_req, "op#%d", ubik_op)); + + /* + * Decode some of the arguments to the Ubik calls + */ + + bp += sizeof(struct rx_header) + 4; + + switch (ubik_op) { + case 10000: /* Beacon */ + TCHECK2(bp[0], 4); + temp = EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + printf(" syncsite %s", temp ? "yes" : "no"); + printf(" votestart"); + DATEOUT(); + printf(" dbversion"); + UBIK_VERSIONOUT(); + printf(" tid"); + UBIK_VERSIONOUT(); + break; + case 10003: /* Get sync site */ + printf(" site"); + UINTOUT(); + break; + case 20000: /* Begin */ + case 20001: /* Commit */ + case 20007: /* Abort */ + case 20008: /* Release locks */ + case 20010: /* Writev */ + printf(" tid"); + UBIK_VERSIONOUT(); + break; + case 20002: /* Lock */ + printf(" tid"); + UBIK_VERSIONOUT(); + printf(" file"); + INTOUT(); + printf(" pos"); + INTOUT(); + printf(" length"); + INTOUT(); + temp = EXTRACT_32BITS(bp); + bp += sizeof(int32_t); + tok2str(ubik_lock_types, "type %d", temp); + break; + case 20003: /* Write */ + printf(" tid"); + UBIK_VERSIONOUT(); + printf(" file"); + INTOUT(); + printf(" pos"); + INTOUT(); + break; + case 20005: /* Get file */ + printf(" file"); + INTOUT(); + break; + case 20006: /* Send file */ + printf(" file"); + INTOUT(); + printf(" length"); + INTOUT(); + printf(" dbversion"); + UBIK_VERSIONOUT(); + break; + case 20009: /* Truncate */ + printf(" tid"); + UBIK_VERSIONOUT(); + printf(" file"); + INTOUT(); + printf(" length"); + INTOUT(); + break; + case 20012: /* Set version */ + printf(" tid"); + UBIK_VERSIONOUT(); + printf(" oldversion"); + UBIK_VERSIONOUT(); + printf(" newversion"); + UBIK_VERSIONOUT(); + break; + default: + ; + } + + return; + +trunc: + printf(" [|ubik]"); +} + +/* + * Handle Ubik replies to any one of the replicated database services + */ + +static void +ubik_reply_print(register const u_char *bp, int length, int32_t opcode) +{ + struct rx_header *rxh; + + if (length < (int)sizeof(struct rx_header)) + return; + + rxh = (struct rx_header *) bp; + + /* + * Print out the ubik call we're invoking. This table was gleaned + * from ubik/ubik_int.xg + */ + + printf(" ubik reply %s", tok2str(ubik_req, "op#%d", opcode)); + + bp += sizeof(struct rx_header); + + /* + * If it was a data packet, print out the arguments to the Ubik calls + */ + + if (rxh->type == RX_PACKET_TYPE_DATA) + switch (opcode) { + case 10000: /* Beacon */ + printf(" vote no"); + break; + case 20004: /* Get version */ + printf(" dbversion"); + UBIK_VERSIONOUT(); + break; + default: + ; + } + + /* + * Otherwise, print out "yes" it it was a beacon packet (because + * that's how yes votes are returned, go figure), otherwise + * just print out the error code. + */ + + else + switch (opcode) { + case 10000: /* Beacon */ + printf(" vote yes until"); + DATEOUT(); + break; + default: + printf(" errcode"); + INTOUT(); + } + + return; + +trunc: + printf(" [|ubik]"); +} + +/* + * Handle RX ACK packets. + */ + +static void +rx_ack_print(register const u_char *bp, int length) +{ + struct rx_ackPacket *rxa; + int i, start, last; + + if (length < (int)sizeof(struct rx_header)) + return; + + bp += sizeof(struct rx_header); + + /* + * This may seem a little odd .... the rx_ackPacket structure + * contains an array of individual packet acknowledgements + * (used for selective ack/nack), but since it's variable in size, + * we don't want to truncate based on the size of the whole + * rx_ackPacket structure. + */ + + TCHECK2(bp[0], sizeof(struct rx_ackPacket) - RX_MAXACKS); + + rxa = (struct rx_ackPacket *) bp; + bp += (sizeof(struct rx_ackPacket) - RX_MAXACKS); + + /* + * Print out a few useful things from the ack packet structure + */ + + if (vflag > 2) + printf(" bufspace %d maxskew %d", + (int) EXTRACT_16BITS(&rxa->bufferSpace), + (int) EXTRACT_16BITS(&rxa->maxSkew)); + + printf(" first %d serial %d reason %s", + EXTRACT_32BITS(&rxa->firstPacket), EXTRACT_32BITS(&rxa->serial), + tok2str(rx_ack_reasons, "#%d", (int) rxa->reason)); + + /* + * Okay, now we print out the ack array. The way _this_ works + * is that we start at "first", and step through the ack array. + * If we have a contiguous range of acks/nacks, try to + * collapse them into a range. + * + * If you're really clever, you might have noticed that this + * doesn't seem quite correct. Specifically, due to structure + * padding, sizeof(struct rx_ackPacket) - RX_MAXACKS won't actually + * yield the start of the ack array (because RX_MAXACKS is 255 + * and the structure will likely get padded to a 2 or 4 byte + * boundary). However, this is the way it's implemented inside + * of AFS - the start of the extra fields are at + * sizeof(struct rx_ackPacket) - RX_MAXACKS + nAcks, which _isn't_ + * the exact start of the ack array. Sigh. That's why we aren't + * using bp, but instead use rxa->acks[]. But nAcks gets added + * to bp after this, so bp ends up at the right spot. Go figure. + */ + + if (rxa->nAcks != 0) { + + TCHECK2(bp[0], rxa->nAcks); + + /* + * Sigh, this is gross, but it seems to work to collapse + * ranges correctly. + */ + + for (i = 0, start = last = -2; i < rxa->nAcks; i++) + if (rxa->acks[i] == RX_ACK_TYPE_ACK) { + + /* + * I figured this deserved _some_ explanation. + * First, print "acked" and the packet seq + * number if this is the first time we've + * seen an acked packet. + */ + + if (last == -2) { + printf(" acked %d", + rxa->firstPacket + i); + start = i; + } + + /* + * Otherwise, if the there is a skip in + * the range (such as an nacked packet in + * the middle of some acked packets), + * then print the current packet number + * seperated from the last number by + * a comma. + */ + + else if (last != i - 1) { + printf(",%d", rxa->firstPacket + i); + start = i; + } + + /* + * We always set last to the value of + * the last ack we saw. Conversely, start + * is set to the value of the first ack + * we saw in a range. + */ + + last = i; + + /* + * Okay, this bit a code gets executed when + * we hit a nack ... in _this_ case we + * want to print out the range of packets + * that were acked, so we need to print + * the _previous_ packet number seperated + * from the first by a dash (-). Since we + * already printed the first packet above, + * just print the final packet. Don't + * do this if there will be a single-length + * range. + */ + } else if (last == i - 1 && start != last) + printf("-%d", rxa->firstPacket + i - 1); + + /* + * So, what's going on here? We ran off the end of the + * ack list, and if we got a range we need to finish it up. + * So we need to determine if the last packet in the list + * was an ack (if so, then last will be set to it) and + * we need to see if the last range didn't start with the + * last packet (because if it _did_, then that would mean + * that the packet number has already been printed and + * we don't need to print it again). + */ + + if (last == i - 1 && start != last) + printf("-%d", rxa->firstPacket + i - 1); + + /* + * Same as above, just without comments + */ + + for (i = 0, start = last = -2; i < rxa->nAcks; i++) + if (rxa->acks[i] == RX_ACK_TYPE_NACK) { + if (last == -2) { + printf(" nacked %d", + rxa->firstPacket + i); + start = i; + } else if (last != i - 1) { + printf(",%d", rxa->firstPacket + i); + start = i; + } + last = i; + } else if (last == i - 1 && start != last) + printf("-%d", rxa->firstPacket + i - 1); + + if (last == i - 1 && start != last) + printf("-%d", rxa->firstPacket + i - 1); + + bp += rxa->nAcks; + } + + + /* + * These are optional fields; depending on your version of AFS, + * you may or may not see them + */ + +#define TRUNCRET(n) if (snapend - bp + 1 <= n) return; + + if (vflag > 1) { + TRUNCRET(4); + printf(" ifmtu"); + INTOUT(); + + TRUNCRET(4); + printf(" maxmtu"); + INTOUT(); + + TRUNCRET(4); + printf(" rwind"); + INTOUT(); + + TRUNCRET(4); + printf(" maxpackets"); + INTOUT(); + } + + return; + +trunc: + printf(" [|ack]"); +} +#undef TRUNCRET diff --git a/kame/kame/tcpdump/print-sctp.c b/kame/kame/tcpdump/print-sctp.c new file mode 100644 index 0000000000..deac2395ff --- /dev/null +++ b/kame/kame/tcpdump/print-sctp.c @@ -0,0 +1,345 @@ +/* Copyright (c) 2001 NETLAB, Temple University + * Copyright (c) 2001 Protocol Engineering Lab, University of Delaware + * + * Jerry Heinz + * John Fiore + * Armando L. Caro Jr. + * + * 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[] _U_ = +"@(#) $Header: /tcpdump/master/tcpdump/print-sctp.c,v 1.13.2.2 2003/11/16 08:51:44 guy Exp $ (NETLAB/PEL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "sctpHeader.h" +#include "sctpConstants.h" +#include + +#include +#include + +#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; + const void *endPacketPtr; + u_short sourcePort, destPort; + int chunkCount; + const struct sctpChunkDesc *chunkDescPtr; + const void *nextChunk; + + sctpPktHdr = (const struct sctpHeader*) bp; + endPacketPtr = (const u_char*)sctpPktHdr+sctpPacketLength; + + if( (u_long) endPacketPtr > (u_long) snapend) + endPacketPtr = (const void *) snapend; + ip = (struct ip *)bp2; +#ifdef INET6 + if (IP_V(ip) == 6) + ip6 = (const struct ip6_hdr *)bp2; + else + ip6 = NULL; +#endif /*INET6*/ + cp = (const 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 = EXTRACT_16BITS(&sctpPktHdr->source); + destPort = EXTRACT_16BITS(&sctpPktHdr->destination); + +#ifdef INET6 + if (ip6) { + (void)printf("%s.%d > %s.%d: sctp", + ip6addr_string(&ip6->ip6_src), + sourcePort, + ip6addr_string(&ip6->ip6_dst), + destPort); + } else +#endif /*INET6*/ + { + (void)printf("%s.%d > %s.%d: sctp", + ipaddr_string(&ip->ip_src), + sourcePort, + ipaddr_string(&ip->ip_dst), + destPort); + } + fflush(stdout); + + if (vflag < 2) + return; + + /* cycle through all chunks, printing information on each one */ + for (chunkCount = 0, + chunkDescPtr = (const struct sctpChunkDesc *) + ((const u_char*) sctpPktHdr + sizeof(struct sctpHeader)); + chunkDescPtr != NULL && + ( (const void *) + ((const u_char *) chunkDescPtr + sizeof(struct sctpChunkDesc)) + <= endPacketPtr); + + chunkDescPtr = (const struct sctpChunkDesc *) nextChunk, chunkCount++) + { + u_short align; + const u_char *chunkEnd; + + chunkEnd = ((const u_char*)chunkDescPtr + EXTRACT_16BITS(&chunkDescPtr->chunkLength)); + + align=EXTRACT_16BITS(&chunkDescPtr->chunkLength) % 4; + if (align != 0) + align = 4 - align; + + nextChunk = (const void *) (chunkEnd + align); + + printf("\n\t%d) ", chunkCount+1); + switch (chunkDescPtr->chunkID) + { + case SCTP_DATA : + { + const 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=(const struct sctpDataPart*)(chunkDescPtr+1); + + printf("[TSN: %u] ", EXTRACT_32BITS(&dataHdrPtr->TSN)); + printf("[SID: %u] ", EXTRACT_16BITS(&dataHdrPtr->streamId)); + printf("[SSEQ %u] ", EXTRACT_16BITS(&dataHdrPtr->sequence)); + printf("[PPID 0x%x] ", EXTRACT_32BITS(&dataHdrPtr->payloadtype)); + fflush(stdout); + + if (vflag) /* if verbose output is specified */ + { /* at the command line */ + const u_char *payloadPtr; + + printf("[Payload"); + + if (!xflag && !qflag) { + payloadPtr = (const u_char *) (++dataHdrPtr); + printf(":"); + if (htons(chunkDescPtr->chunkLength) < + sizeof(struct sctpDataPart)+ + sizeof(struct sctpChunkDesc)+1) { + printf("bogus chunk length %u]", + htons(chunkDescPtr->chunkLength)); + return; + } + default_print(payloadPtr, + htons(chunkDescPtr->chunkLength) - + (sizeof(struct sctpDataPart)+ + sizeof(struct sctpChunkDesc)+1)); + } else + printf("]"); + } + break; + } + case SCTP_INITIATION : + { + const struct sctpInitiation *init; + + printf("[INIT] "); + init=(const struct sctpInitiation*)(chunkDescPtr+1); + printf("[init tag: %u] ", EXTRACT_32BITS(&init->initTag)); + printf("[rwnd: %u] ", EXTRACT_32BITS(&init->rcvWindowCredit)); + printf("[OS: %u] ", EXTRACT_16BITS(&init->NumPreopenStreams)); + printf("[MIS: %u] ", EXTRACT_16BITS(&init->MaxInboundStreams)); + printf("[init TSN: %u] ", EXTRACT_32BITS(&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 : + { + const struct sctpInitiation *init; + + printf("[INIT ACK] "); + init=(const struct sctpInitiation*)(chunkDescPtr+1); + printf("[init tag: %u] ", EXTRACT_32BITS(&init->initTag)); + printf("[rwnd: %u] ", EXTRACT_32BITS(&init->rcvWindowCredit)); + printf("[OS: %u] ", EXTRACT_16BITS(&init->NumPreopenStreams)); + printf("[MIS: %u] ", EXTRACT_16BITS(&init->MaxInboundStreams)); + printf("[init TSN: %u] ", EXTRACT_32BITS(&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: + { + const struct sctpSelectiveAck *sack; + const struct sctpSelectiveFrag *frag; + int fragNo, tsnNo; + const u_long *dupTSN; + + printf("[SACK] "); + sack=(const struct sctpSelectiveAck*)(chunkDescPtr+1); + printf("[cum ack %u] ", EXTRACT_32BITS(&sack->highestConseqTSN)); + printf("[a_rwnd %u] ", EXTRACT_32BITS(&sack->updatedRwnd)); + printf("[#gap acks %u] ", EXTRACT_16BITS(&sack->numberOfdesc)); + printf("[#dup tsns %u] ", EXTRACT_16BITS(&sack->numDupTsns)); + + + /* print gaps */ + for (frag = ( (const struct sctpSelectiveFrag *) + ((const struct sctpSelectiveAck *) sack+1)), + fragNo=0; + (const void *)frag < nextChunk && fragNo < EXTRACT_16BITS(&sack->numberOfdesc); + frag++, fragNo++) + printf("\n\t\t[gap ack block #%d: start = %u, end = %u] ", + fragNo+1, + EXTRACT_32BITS(&sack->highestConseqTSN) + EXTRACT_16BITS(&frag->fragmentStart), + EXTRACT_32BITS(&sack->highestConseqTSN) + EXTRACT_16BITS(&frag->fragmentEnd)); + + + /* print duplicate TSNs */ + for (dupTSN = (const u_long*)frag, tsnNo=0; + (const void *) dupTSN < nextChunk && tsnNonumDupTsns); + dupTSN++, tsnNo++) + printf("\n\t\t[dup TSN #%u: %u] ", tsnNo+1, + EXTRACT_32BITS(dupTSN)); + + break; + } + case SCTP_HEARTBEAT_REQUEST : + { + const struct sctpHBsender *hb; + + hb=(const 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/kame/kame/tcpdump/print-sl.c b/kame/kame/tcpdump/print-sl.c index 98a376dc30..9e5cdb1ce3 100644 --- a/kame/kame/tcpdump/print-sl.c +++ b/kame/kame/tcpdump/print-sl.c @@ -20,38 +20,16 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-sl.c,v 1.42 97/06/12 14:21:35 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-sl.c,v 1.62.2.2 2003/11/16 08:51:44 guy Exp $ (LBL)"; #endif -#ifdef HAVE_NET_SLIP_H -#include -#include -#include -#include -#include -#include -#include - -#if __STDC__ -struct rtentry; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include + +#include + #include #include @@ -59,42 +37,28 @@ struct rtentry; #include "addrtoname.h" #include "extract.h" /* must come after interface.h */ +#include "ip.h" +#include "tcp.h" +#include "slip.h" +#include "slcompress.h" + static u_int lastlen[2][256]; static u_int lastconn = 255; static void sliplink_print(const u_char *, const struct ip *, u_int); static void compressed_sl_print(const u_char *, const struct ip *, u_int, int); -/* XXX BSD/OS 2.1 compatibility */ -#if !defined(SLIP_HDRLEN) && defined(SLC_BPFHDR) -#define SLIP_HDRLEN SLC_BPFHDR -#define SLX_DIR 0 -#define SLX_CHDR (SLC_BPFHDRLEN - 1) -#define CHDR_LEN (SLC_BPFHDR - SLC_BPFHDRLEN) -#endif - -/* XXX needs more hacking to work right */ - -void -sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) +u_int +sl_if_print(const struct pcap_pkthdr *h, const u_char *p) { register u_int caplen = h->caplen; register u_int length = h->len; register const struct ip *ip; - ts_print(&h->ts); - if (caplen < SLIP_HDRLEN) { printf("[|slip]"); - goto out; + return (caplen); } - /* - * 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; length -= SLIP_HDRLEN; @@ -103,35 +67,33 @@ sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) if (eflag) sliplink_print(p, ip, length); - ip_print((u_char *)ip, length); + switch (IP_V(ip)) { + case 4: + ip_print((u_char *)ip, length); + break; +#ifdef INET6 + case 6: + ip6_print((u_char *)ip, length); + break; +#endif + default: + printf ("ip v%d", IP_V(ip)); + } - if (xflag) - default_print((u_char *)ip, caplen - SLIP_HDRLEN); - out: - putchar('\n'); + return (SLIP_HDRLEN); } - -void -sl_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) +u_int +sl_bsdos_if_print(const struct pcap_pkthdr *h, const u_char *p) { register u_int caplen = h->caplen; register u_int length = h->len; register const struct ip *ip; - ts_print(&h->ts); - if (caplen < SLIP_HDRLEN) { printf("[|slip]"); - goto out; + return (caplen); } - /* - * 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; length -= SLIP_HDRLEN; @@ -144,10 +106,7 @@ sl_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) ip_print((u_char *)ip, length); - if (xflag) - default_print((u_char *)ip, caplen - SLIP_HDRLEN); - out: - putchar('\n'); + return (SLIP_HDRLEN); } static void @@ -183,8 +142,8 @@ sliplink_print(register const u_char *p, register const struct ip *ip, * has restored the IP header copy to IPPROTO_TCP. */ lastconn = ((struct ip *)&p[SLX_CHDR])->ip_p; - hlen = ip->ip_hl; - hlen += ((struct tcphdr *)&((int *)ip)[hlen])->th_off; + hlen = IP_HL(ip); + hlen += TH_OFF((struct tcphdr *)&((int *)ip)[hlen]); lastlen[dir][lastconn] = length - (hlen << 2); printf("utcp %d: ", lastconn); break; @@ -273,33 +232,8 @@ compressed_sl_print(const u_char *chdr, const struct ip *ip, * 'cp - chdr' is the length of the compressed header. * 'length - hlen' is the amount of data in the packet. */ - hlen = ip->ip_hl; - hlen += ((struct tcphdr *)&((int32_t *)ip)[hlen])->th_off; + hlen = IP_HL(ip); + hlen += TH_OFF((struct tcphdr *)&((int32_t *)ip)[hlen]); lastlen[dir][lastconn] = length - (hlen << 2); - printf(" %d (%d)", lastlen[dir][lastconn], cp - chdr); -} -#else -#include -#include - -#include -#include - -#include "interface.h" - -void -sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) -{ - - error("not configured for slip"); - /* NOTREACHED */ -} - -void -sl_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) -{ - - error("not configured for slip"); - /* NOTREACHED */ + printf(" %d (%ld)", lastlen[dir][lastconn], (long)(cp - chdr)); } -#endif diff --git a/kame/kame/tcpdump/print-sll.c b/kame/kame/tcpdump/print-sll.c new file mode 100644 index 0000000000..df0ce59272 --- /dev/null +++ b/kame/kame/tcpdump/print-sll.c @@ -0,0 +1,179 @@ +/* + * 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. + */ +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-sll.c,v 1.12.2.2 2003/11/16 08:51:44 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "ethertype.h" + +#include "ether.h" +#include "sll.h" + +static inline void +sll_print(register const struct sll_header *sllp, u_int length) +{ + u_short halen; + + switch (ntohs(sllp->sll_pkttype)) { + + case LINUX_SLL_HOST: + (void)printf("< "); + break; + + case LINUX_SLL_BROADCAST: + (void)printf("B "); + break; + + case LINUX_SLL_MULTICAST: + (void)printf("M "); + break; + + case LINUX_SLL_OTHERHOST: + (void)printf("P "); + break; + + case LINUX_SLL_OUTGOING: + (void)printf("> "); + break; + + default: + (void)printf("? "); + break; + } + + /* + * XXX - check the link-layer address type value? + * For now, we just assume 6 means Ethernet. + * XXX - print others as strings of hex? + */ + halen = ntohs(sllp->sll_halen); + if (halen == 6) + (void)printf("%s ", etheraddr_string(sllp->sll_addr)); + + if (!qflag) + (void)printf("%s ", etherproto_string(sllp->sll_protocol)); + (void)printf("%d: ", length); +} + +/* + * This is the top level routine of the printer. 'p' points to the + * Linux "cooked capture" header of the packet, 'h->ts' is the timestamp, + * 'h->length' is the length of the packet off the wire, and 'h->caplen' + * is the number of bytes actually captured. + */ +u_int +sll_if_print(const struct pcap_pkthdr *h, const u_char *p) +{ + u_int caplen = h->caplen; + u_int length = h->len; + register const struct sll_header *sllp; + u_short ether_type; + u_short extracted_ethertype; + + if (caplen < SLL_HDR_LEN) { + /* + * XXX - this "can't happen" because "pcap-linux.c" always + * adds this many bytes of header to every packet in a + * cooked socket capture. + */ + printf("[|sll]"); + return (caplen); + } + + sllp = (const struct sll_header *)p; + + if (eflag) + sll_print(sllp, length); + + /* + * Go past the cooked-mode header. + */ + length -= SLL_HDR_LEN; + caplen -= SLL_HDR_LEN; + p += SLL_HDR_LEN; + + ether_type = ntohs(sllp->sll_protocol); + + /* + * Is it (gag) an 802.3 encapsulation, or some non-Ethernet + * packet type? + */ + extracted_ethertype = 0; + if (ether_type <= ETHERMTU) { + /* + * Yes - what type is it? + */ + 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. + * Try to print the LLC-layer header & higher layers. + */ + if (llc_print(p, length, caplen, NULL, NULL, + &extracted_ethertype) == 0) + goto unknown; /* unknown LLC type */ + break; + + default: + unknown: + /* ether_type not known, print raw packet */ + if (!eflag) + sll_print(sllp, length + SLL_HDR_LEN); + if (extracted_ethertype) { + printf("(LLC %s) ", + etherproto_string(htons(extracted_ethertype))); + } + if (!xflag && !qflag) + default_print(p, caplen); + break; + } + } else if (ether_encap_print(ether_type, p, length, caplen, + &extracted_ethertype) == 0) { + /* ether_type not known, print raw packet */ + if (!eflag) + sll_print(sllp, length + SLL_HDR_LEN); + if (!xflag && !qflag) + default_print(p, caplen); + } + + return (SLL_HDR_LEN); +} diff --git a/kame/kame/tcpdump/print-smb.c b/kame/kame/tcpdump/print-smb.c new file mode 100644 index 0000000000..5f683eff52 --- /dev/null +++ b/kame/kame/tcpdump/print-smb.c @@ -0,0 +1,1297 @@ +/* + * 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" +#endif + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-smb.c,v 1.27.2.2 2003/11/16 08:51:45 guy Exp $"; +#endif + +#include + +#include +#include + +#include "interface.h" +#include "extract.h" +#include "smb.h" + +static int request = 0; + +const u_char *startbuf = NULL; + +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; + const char *name; + int flags; + struct smbdescript descript; +}; + +struct smbfnsint +{ + int id; + const char *name; + int flags; + struct smbdescriptint descript; +}; + +#define DEFDESCRIPT { NULL, NULL, NULL, NULL, NULL } + +#define FLG_CHAIN (1 << 0) + +static struct smbfns * +smbfind(int id, struct smbfns *list) +{ + int sindex; + + for (sindex = 0; list[sindex].name; sindex++) + if (list[sindex].id == id) + return(&list[sindex]); + + return(&list[0]); +} + +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]); + + return(&list[0]); +} + +static void +trans2_findfirst(const u_char *param, const u_char *data, int pcnt, int dcnt) +{ + 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"; + + smb_fdata(param, fmt, param + pcnt); + if (dcnt) { + printf("data:\n"); + print_data(data, dcnt); + } +} + +static void +trans2_qfsinfo(const u_char *param, const u_char *data, int pcnt, int dcnt) +{ + 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; +trunc: + printf("[|SMB]"); + return; +} + +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_trans2(const u_char *words, const u_char *dat _U_, const u_char *buf, const u_char *maxbuf) +{ + static struct smbfnsint *fn = &trans2_fns[0]; + const u_char *data, *param; + const u_char *w = words + 1; + const 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); + } + + printf("%s param_length=%d data_length=%d\n", fn->name, pcnt, dcnt); + + 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 { + 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; + } + + if (fn->descript.fn) + (*fn->descript.fn)(param, data, pcnt, dcnt); + else { + smb_fdata(param, f1 ? f1 : "Parameters=\n", param + pcnt); + smb_fdata(data, f2 ? f2 : "Data=\n", data + dcnt); + } + return; +trunc: + printf("[|SMB]"); + return; +} + + +static void +print_browse(const u_char *param, int paramlen, const u_char *data, int datalen) +{ + const u_char *maxbuf = data + datalen; + int command; + + TCHECK(data[0]); + command = data[0]; + + smb_fdata(param, "BROWSE PACKET\n|Param ", param+paramlen); + + 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; + + 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; + + case 0x2: + data = smb_fdata(data, + "BROWSE PACKET:\nType=[B] (AnnouncementRequest)\nFlags=[B]\nReplySystemName=[S]\n", + maxbuf); + break; + + 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; + + case 0x8: + data = smb_fdata(data, + "BROWSE PACKET:\nType=[B] (ElectionFrame)\nElectionVersion=[B]\nOSSummary=[W]\nUptime=[(W, W)]\nServerName=[S]\n", + maxbuf); + break; + + case 0xb: + data = smb_fdata(data, + "BROWSE PACKET:\nType=[B] (BecomeBackupBrowser)\nName=[S]\n", + maxbuf); + break; + + 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; + + case 0xd: + data = smb_fdata(data, + "BROWSE PACKET:\nType=[B] (MasterAnnouncement)\nMasterName=[S]\n", + maxbuf); + break; + + case 0xe: + data = smb_fdata(data, + "BROWSE PACKET:\nType=[B] (ResetBrowser)\nOptions=[B]\n", maxbuf); + break; + + default: + data = smb_fdata(data, "Unknown Browser Frame ", maxbuf); + break; + } + return; +trunc: + printf("[|SMB]"); + return; +} + + +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); +} + + +static void +print_trans(const u_char *words, const u_char *data1, const u_char *buf, const u_char *maxbuf) +{ + const 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 "; + } + + smb_fdata(words + 1, f1, SMBMIN(words + 1 + 2 * words[0], maxbuf)); + smb_fdata(data1 + 2, f2, maxbuf - (paramlen + datalen)); + + if (strcmp((const char *)(data1 + 2), "\\MAILSLOT\\BROWSE") == 0) { + print_browse(param, paramlen, data, datalen); + return; + } + + if (strcmp((const char *)(data1 + 2), "\\PIPE\\LANMAN") == 0) { + print_ipc(param, paramlen, data, datalen); + return; + } + + 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; +} + + +static void +print_negprot(const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf) +{ + u_int wcnt; + const char *f1 = NULL, *f2 = NULL; + + TCHECK(words[0]); + wcnt = words[0]; + if (request) + f2 = "*|Dialect=[Z]\n"; + else { + if (wcnt == 1) + f1 = "Core Protocol\nDialectIndex=[d]"; + else if (wcnt == 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 (wcnt == 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="; + } + + if (f1) + smb_fdata(words + 1, f1, SMBMIN(words + 1 + wcnt * 2, maxbuf)); + else + print_data(words + 1, SMBMIN(wcnt * 2, PTR_DIFF(maxbuf, words + 1))); + + 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 void +print_sesssetup(const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf) +{ + u_int wcnt; + const 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 (wcnt == 3) { + f1 = "Com2=[w]\nOff2=[d]\nAction=[w]\n"; + } else if (wcnt == 13) { + f1 = "Com2=[B]\nRes=[B]\nOff2=[d]\nAction=[w]\n"; + f2 = "NativeOS=[S]\nNativeLanMan=[S]\nPrimaryDomain=[S]\n"; + } + } + + if (f1) + smb_fdata(words + 1, f1, SMBMIN(words + 1 + wcnt * 2, maxbuf)); + else + print_data(words + 1, SMBMIN(wcnt * 2, PTR_DIFF(maxbuf, words + 1))); + + 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 } }, + + { SMBtdis, "SMBtdis", 0, DEFDESCRIPT }, + { SMBexit, "SMBexit", 0, DEFDESCRIPT }, + { SMBioctl, "SMBioctl", 0, DEFDESCRIPT }, + + { SMBecho, "SMBecho", 0, + { "ReverbCount=[d]\n", NULL, + "SequenceNum=[d]\n", NULL, + NULL } }, + + { SMBulogoffX, "SMBulogoffX", FLG_CHAIN, DEFDESCRIPT }, + + { SMBgetatr, "SMBgetatr", 0, + { NULL, "Path=[Z]\n", + "Attribute=[A]\nTime=[T2]Size=[D]\nRes=([w,w,w,w,w])\n", NULL, + NULL } }, + + { SMBsetatr, "SMBsetatr", 0, + { "Attribute=[A]\nTime=[T2]Res=([w,w,w,w,w])\n", "Path=[Z]\n", + NULL, NULL, NULL } }, + + { SMBchkpth, "SMBchkpth", 0, + { NULL, "Path=[Z]\n", NULL, 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 } }, + + { SMBopen, "SMBopen", 0, + { "Mode=[w]\nAttribute=[A]\n", "Path=[Z]\n", + "Handle=[d]\nOAttrib=[A]\nTime=[T2]Size=[D]\nAccess=[w]\n", + NULL, NULL } }, + + { SMBcreate, "SMBcreate", 0, + { "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[d]\n", NULL, NULL } }, + + { SMBmknew, "SMBmknew", 0, + { "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[d]\n", NULL, NULL } }, + + { 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 } }, + + { 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 } }, + + { SMBmkdir, "SMBmkdir", 0, + { NULL, "Path=[Z]\n", NULL, NULL, NULL } }, + + { SMBrmdir, "SMBrmdir", 0, + { NULL, "Path=[Z]\n", NULL, NULL, NULL } }, + + { SMBdskattr, "SMBdskattr", 0, + { NULL, NULL, + "TotalUnits=[d]\nBlocksPerUnit=[d]\nBlockSize=[d]\nFreeUnits=[d]\nMedia=[w]\n", + NULL, NULL } }, + + { SMBmv, "SMBmv", 0, + { "Attrib=[A]\n", "OldPath=[Z]\nNewPath=[Z]\n", NULL, 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 } }, + + { SMBlseek, "SMBlseek", 0, + { "Handle=[d]\nMode=[w]\nOffset=[D]\n", "Offset=[D]\n", NULL, NULL, NULL } }, + + { SMBflush, "SMBflush", 0, { "Handle=[d]\n", NULL, NULL, NULL, NULL } }, + + { SMBsplopen, "SMBsplopen", 0, + { "SetupLen=[d]\nMode=[w]\n", "Ident=[Z]\n", "Handle=[d]\n", + NULL, NULL } }, + + { SMBsplclose, "SMBsplclose", 0, + { "Handle=[d]\n", NULL, NULL, NULL, 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 } }, + + { SMBwriteunlock, "SMBwriteunlock", 0, + { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL, + "Count=[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 } }, + + { 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 } }, + + { SMBwriteBs, "SMBwriteBs", 0, + { "Handle=[d]\nTotCount=[d]\nOffset=[D]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\n", + NULL, "Count=[d]\n", NULL, NULL } }, + + { SMBsetattrE, "SMBsetattrE", 0, + { "Handle=[d]\nCreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]", NULL, + 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 } }, + + { SMBtranss, "SMBtranss", 0, DEFDESCRIPT }, + { SMBioctls, "SMBioctls", 0, DEFDESCRIPT }, + + { SMBcopy, "SMBcopy", 0, + { "TreeID2=[d]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n", + "CopyCount=[d]\n", "|ErrStr=[S]\n", NULL } }, + + { SMBmove, "SMBmove", 0, + { "TreeID2=[d]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n", + "MoveCount=[d]\n", "|ErrStr=[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 } }, + + { 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 } }, + + { 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 } }, + + { 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 } }, + + { 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 } }, + + { 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 } }, + + { 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 }, + + { 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, 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 u_char *words, *data; + struct smbfns *fn; + const 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"; + + + TCHECK(buf[9]); + request = (buf[9] & 0x80) ? 0 : 1; + + command = buf[4]; + + fn = smbfind(command, smb_fns); + + if (vflag > 1) + printf("\n"); + + printf("SMB PACKET: %s (%s)\n", fn->name, request ? "REQUEST" : "REPLY"); + + if (vflag < 2) + return; + + /* 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]))); + + words = buf + 32; + TCHECK(words[0]); + + for (;;) { + const char *f1, *f2; + int wct; + u_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 { + f1 = fn->descript.rep_f1; + f2 = fn->descript.rep_f2; + } + + 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); + } + } + } + + 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=%u\n", bcc); + if (bcc > 0) { + printf("smb_buf[]=\n"); + print_data(data + 2, SMBMIN(bcc, PTR_DIFF(maxbuf, data + 2))); + } + } + } + + 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"); + return; +trunc: + printf("[|SMB]"); + return; +} + + +/* + * print a NBT packet received across tcp on port 139 + */ +void +nbt_tcp_print(const u_char *data, int length) +{ + const u_char *maxbuf = data + length; + int flags; + u_int nbt_len; + + TCHECK2(data[2], 2); + flags = data[0]; + nbt_len = EXTRACT_16BITS(data + 2); + + startbuf = data; + if (maxbuf <= data) + return; + + 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 = 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); + } + printf("\n"); + fflush(stdout); + return; +trunc: + printf("[|SMB]"); + return; +} + + +/* + * print a NBT packet received across udp on port 137 + */ +void +nbt_udp137_print(const u_char *data, int length) +{ + const u_char *maxbuf = data + length; + int name_trn_id, response, opcode, nm_flags, rcode; + int qdcount, ancount, nscount, arcount; + const char *opcodestr; + const u_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("; REQUEST"); + + if (nm_flags & 1) + printf("; BROADCAST"); + else + printf("; UNICAST"); + + if (vflag < 2) + 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 = smb_fdata(p, + "|Name=[n1]\nQuestionType=[rw]\nQuestionClass=[rw]\n#", + maxbuf); + if (p == NULL) + goto out; + } + + if (total) { + 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; + 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(" "); + 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(" "); + if (p[0] & 0x08) + printf(" "); + if (p[0] & 0x04) + printf(" "); + if (p[0] & 0x02) + printf(" "); + printf("\n"); + p += 2; + } + } else { + print_data(p, min(rdlen, length - (p - data))); + p += rdlen; + } + } + } + } + + if (p < maxbuf) + smb_fdata(p, "AdditionalData:\n", maxbuf); + +out: + printf("\n"); + fflush(stdout); + return; +trunc: + printf("[|SMB]"); + return; +} + + + +/* + * print a NBT packet received across udp on port 138 + */ +void +nbt_udp138_print(const u_char *data, int length) +{ + const u_char *maxbuf = data + length; + + if (maxbuf > snapend) + maxbuf = snapend; + if (maxbuf <= data) + return; + startbuf = data; + + 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 +*/ +void +netbeui_print(u_short control, const u_char *data, int length) +{ + 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"); + return; +trunc: + printf("[|SMB]"); + return; +} + + +/* + * 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 + * 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) + smb_fdata(data, "\n>>> Unknown IPX ", maxbuf); +} diff --git a/kame/kame/tcpdump/print-snmp.c b/kame/kame/tcpdump/print-snmp.c index 83674705b3..e1db2166bc 100644 --- a/kame/kame/tcpdump/print-snmp.c +++ b/kame/kame/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. @@ -21,6 +34,9 @@ * that work is preserved below, even though it may not rightly apply * to this file. * + * Support for SNMPv2c/SNMPv3 and the ability to link the module against + * the libsmi was added by J. Schoenwaelder, Copyright (c) 1999. + * * This started out as a very simple program, but the incremental decoding * (into the BE structure) complicated things. * @@ -41,20 +57,23 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-snmp.c,v 1.33 97/06/15 13:20:28 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.56.2.3 2004/03/23 06:59:59 guy Exp $ (LBL)"; #endif -#include -#include - -#include -#ifdef HAVE_MEMORY_H -#include +#ifdef HAVE_CONFIG_H +#include "config.h" #endif + +#include + #include #include +#ifdef HAVE_SMI_H +#include +#endif + #include "interface.h" #include "addrtoname.h" @@ -62,7 +81,7 @@ static const char rcsid[] = * Universal ASN.1 types * (we only care about the tag values for those allowed in the Internet SMI) */ -char *Universal[] = { +const char *Universal[] = { "U-0", "Boolean", "Integer", @@ -85,7 +104,7 @@ char *Universal[] = { /* * Application-wide ASN.1 types from the Internet SMI and their tags */ -char *Application[] = { +const char *Application[] = { "IpAddress", #define IPADDR 0 "Counter", @@ -94,13 +113,17 @@ char *Application[] = { #define GAUGE 2 "TimeTicks", #define TIMETICKS 3 - "Opaque" + "Opaque", +#define OPAQUE 4 + "C-5", + "Counter64" +#define COUNTER64 6 }; /* * Context-specific ASN.1 types for the SNMP PDUs and their tags */ -char *Context[] = { +const char *Context[] = { "GetRequest", #define GETREQ 0 "GetNextRequest", @@ -109,37 +132,77 @@ char *Context[] = { #define GETRESP 2 "SetRequest", #define SETREQ 3 - "Trap" + "Trap", #define TRAP 4 + "GetBulk", +#define GETBULKREQ 5 + "Inform", +#define INFORMREQ 6 + "V2Trap", +#define V2TRAP 7 + "Report" +#define REPORT 8 +}; + +#define NOTIFY_CLASS(x) (x == TRAP || x == V2TRAP || x == INFORMREQ) +#define READ_CLASS(x) (x == GETREQ || x == GETNEXTREQ || x == GETBULKREQ) +#define WRITE_CLASS(x) (x == SETREQ) +#define RESPONSE_CLASS(x) (x == GETRESP) +#define INTERNAL_CLASS(x) (x == REPORT) + +/* + * Context-specific ASN.1 types for the SNMP Exceptions and their tags + */ +const char *Exceptions[] = { + "noSuchObject", +#define NOSUCHOBJECT 0 + "noSuchInstance", +#define NOSUCHINSTANCE 1 + "endOfMibView", +#define ENDOFMIBVIEW 2 }; /* * Private ASN.1 types * The Internet SMI does not specify any */ -char *Private[] = { +const char *Private[] = { "P-0" }; /* * error-status values for any SNMP PDU */ -char *ErrorStatus[] = { +const char *ErrorStatus[] = { "noError", "tooBig", "noSuchName", "badValue", "readOnly", - "genErr" + "genErr", + "noAccess", + "wrongType", + "wrongLength", + "wrongEncoding", + "wrongValue", + "noCreation", + "inconsistentValue", + "resourceUnavailable", + "commitFailed", + "undoFailed", + "authorizationError", + "notWritable", + "inconsistentName" }; #define DECODE_ErrorStatus(e) \ - ( e >= 0 && e <= sizeof(ErrorStatus)/sizeof(ErrorStatus[0]) \ - ? ErrorStatus[e] : (sprintf(errbuf, "err=%u", e), errbuf)) + ( e >= 0 && (size_t)e < sizeof(ErrorStatus)/sizeof(ErrorStatus[0]) \ + ? ErrorStatus[e] \ + : (snprintf(errbuf, sizeof(errbuf), "err=%u", e), errbuf)) /* * generic-trap values in the SNMP Trap-PDU */ -char *GenericTrap[] = { +const char *GenericTrap[] = { "coldStart", "warmStart", "linkDown", @@ -147,11 +210,12 @@ char *GenericTrap[] = { "authenticationFailure", "egpNeighborLoss", "enterpriseSpecific" -#define GT_ENTERPRISE 7 +#define GT_ENTERPRISE 6 }; #define DECODE_GenericTrap(t) \ - ( t >= 0 && t <= sizeof(GenericTrap)/sizeof(GenericTrap[0]) \ - ? GenericTrap[t] : (sprintf(buf, "gt=%d", t), buf)) + ( t >= 0 && (size_t)t < sizeof(GenericTrap)/sizeof(GenericTrap[0]) \ + ? GenericTrap[t] \ + : (snprintf(buf, sizeof(buf), "gt=%d", t), buf)) /* * ASN.1 type class table @@ -160,8 +224,8 @@ char *GenericTrap[] = { */ #define defineCLASS(x) { "x", x, sizeof(x)/sizeof(x[0]) } /* not ANSI-C */ struct { - char *name; - char **Id; + const char *name; + const char **Id; int numIDs; } Class[] = { defineCLASS(Universal), @@ -172,12 +236,14 @@ struct { #define CONTEXT 2 defineCLASS(Private), #define PRIVATE 3 + defineCLASS(Exceptions), +#define EXCEPTIONS 4 }; /* * defined forms for ASN.1 types */ -char *Form[] = { +const char *Form[] = { "Primitive", #define PRIMITIVE 0 "Constructed", @@ -189,7 +255,7 @@ char *Form[] = { * This is stored as a general-order tree. */ struct obj { - char *desc; /* name of object */ + const char *desc; /* name of object */ u_char oid; /* sub-id following parent */ u_char type; /* object type (unused) */ struct obj *child, *next; /* child and next sibling pointers */ @@ -211,9 +277,9 @@ struct obj { * private enterprises tree, and the experimental tree. */ struct obj_abrev { - char *prefix; /* prefix for this abrev */ + const char *prefix; /* prefix for this abrev */ struct obj *node; /* pointer into object table */ - char *oid; /* ASN.1 encoded OID */ + const char *oid; /* ASN.1 encoded OID */ } obj_abrev_list[] = { #ifndef NO_ABREV_MIB /* .iso.org.dod.internet.mgmt.mib */ @@ -226,6 +292,10 @@ struct obj_abrev { #ifndef NO_ABREV_EXPERI /* .iso.org.dod.internet.experimental */ { "X:", &_experimental_obj, "\53\6\1\3" }, +#endif +#ifndef NO_ABBREV_SNMPMODS + /* .iso.org.dod.internet.snmpV2.snmpModules */ + { "S:", &_snmpModules_obj, "\53\6\1\6\3" }, #endif { 0,0,0 } }; @@ -260,6 +330,10 @@ struct be { int32_t integer; u_int32_t uns; const u_char *str; + struct { + u_int32_t high; + u_int32_t low; + } uns64; } data; u_short id; u_char form, class; /* tag info */ @@ -275,13 +349,30 @@ struct be { #define BE_SEQ 7 #define BE_INETADDR 8 #define BE_PDU 9 +#define BE_UNS64 10 +#define BE_NOSUCHOBJECT 128 +#define BE_NOSUCHINST 129 +#define BE_ENDOFMIBVIEW 130 +}; + +/* + * SNMP versions recognized by this module + */ +const char *SnmpVersion[] = { + "SNMPv1", +#define SNMP_VERSION_1 0 + "SNMPv2c", +#define SNMP_VERSION_2 1 + "SNMPv2u", +#define SNMP_VERSION_2U 2 + "SNMPv3" +#define SNMP_VERSION_3 3 }; /* * Defaults for SNMP PDU components */ #define DEF_COMMUNITY "public" -#define DEF_VERSION 0 /* * constants for ASN.1 decoding @@ -325,7 +416,7 @@ asn1_parse(register const u_char *p, u_int len, struct be *elem) elem->asnlen = 0; elem->type = BE_ANY; if (len < 1) { - ifNotTruncated puts("[nothing to parse], stdout"); + ifNotTruncated fputs("[nothing to parse]", stdout); return -1; } @@ -348,16 +439,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) - 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) - 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; @@ -372,21 +458,16 @@ asn1_parse(register const u_char *p, u_int len, struct be *elem) return -1; } elem->asnlen = *p; - if (vflag) - printf("|%.2x", *p); p++; len--; hdr++; if (elem->asnlen & ASN_BIT8) { - int noct = elem->asnlen % ASN_BIT8; + u_int32_t noct = elem->asnlen % ASN_BIT8; elem->asnlen = 0; if (len < noct) { ifNotTruncated printf("[asnlen? %d<%d]", len, noct); return -1; } - for (; noct-- > 0; len--, hdr++) { - if (vflag) - printf("|%.2x", *p); + for (; noct-- > 0; len--, hdr++) elem->asnlen = (elem->asnlen << ASN_SHIFT8) | *p++; - } } if (len < elem->asnlen) { if (!truncated) { @@ -471,6 +552,20 @@ asn1_parse(register const u_char *p, u_int len, struct be *elem) break; } + case COUNTER64: { + register u_int32_t high, low; + elem->type = BE_UNS64; + high = 0, low = 0; + for (i = elem->asnlen; i-- > 0; p++) { + high = (high << 8) | + ((low & 0xFF000000) >> 24); + low = (low << 8) | *p; + } + elem->data.uns64.high = high; + elem->data.uns64.low = low; + break; + } + default: elem->type = BE_OCTET; elem->data.raw = (caddr_t)p; @@ -480,6 +575,25 @@ asn1_parse(register const u_char *p, u_int len, struct be *elem) } break; + case CONTEXT: + switch (id) { + case NOSUCHOBJECT: + elem->type = BE_NOSUCHOBJECT; + elem->data.raw = NULL; + break; + + case NOSUCHINSTANCE: + elem->type = BE_NOSUCHINST; + elem->data.raw = NULL; + break; + + case ENDOFMIBVIEW: + elem->type = BE_ENDOFMIBVIEW; + elem->data.raw = NULL; + break; + } + break; + default: elem->type = BE_OCTET; elem->data.raw = (caddr_t)p; @@ -535,12 +649,12 @@ asn1_print(struct be *elem) { u_char *p = (u_char *)elem->data.raw; u_int32_t asnlen = elem->asnlen; - int i; + u_int32_t i; switch (elem->type) { case BE_OCTET: - for (i = asnlen; i-- > 0; p++); + for (i = asnlen; i-- > 0; p++) printf("_%.2x", *p); break; @@ -550,7 +664,7 @@ asn1_print(struct be *elem) case BE_OID: { int o = 0, first = -1, i = asnlen; - if (!nflag && asnlen > 2) { + if (!sflag && !nflag && asnlen > 2) { struct obj_abrev *a = &obj_abrev_list[0]; for (; a->node; a++) { if (!memcmp(a->oid, (char *)p, @@ -564,20 +678,25 @@ asn1_print(struct be *elem) } } } - for (; i-- > 0; p++) { + + for (; !sflag && i-- > 0; p++) { o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8); if (*p & ASN_LONGLEN) - continue; + continue; /* * first subitem encodes two items with 1st*OIDMUX+2nd + * (see X.690:1997 clause 8.19 for the details) */ if (first < 0) { + int s; if (!nflag) objp = mibroot; first = 0; - OBJ_PRINT(o/OIDMUX, first); - o %= OIDMUX; + s = o / OIDMUX; + if (s > 2) s = 2; + OBJ_PRINT(s, first); + o -= s * OIDMUX; } OBJ_PRINT(o, first); if (--first < 0) @@ -592,8 +711,50 @@ asn1_print(struct be *elem) break; case BE_UNS: - printf("%d", elem->data.uns); + printf("%u", elem->data.uns); + break; + + case BE_UNS64: { /* idea borrowed from by Marshall Rose */ + double d; + int j, carry; + char *cpf, *cpl, last[6], first[30]; + if (elem->data.uns64.high == 0) { + printf("%u", elem->data.uns64.low); + break; + } + 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?*/ + printf("%.f", d); +#else + printf("%f", d); +#endif + break; + } + d += (elem->data.uns64.low & 0xfffff000); +#if 0 /*is looks illegal, but what is the intention?*/ + snprintf(first, sizeof(first), "%.f", d); +#else + snprintf(first, sizeof(first), "%f", d); +#endif + snprintf(last, sizeof(last), "%5.5d", + elem->data.uns64.low & 0xfff); + for (carry = 0, cpf = first+strlen(first)-1, cpl = last+4; + cpl >= last; + cpf--, cpl--) { + j = carry + (*cpf - '0') + (*cpl - '0'); + if (j > 9) { + j -= 10; + carry = 1; + } else { + carry = 0; + } + *cpf = j + '0'; + } + fputs(first, stdout); break; + } case BE_STR: { register int printable = 1, first = 1; @@ -617,18 +778,19 @@ asn1_print(struct be *elem) printf("Seq(%u)", elem->asnlen); break; - case BE_INETADDR: { - char sep; + case BE_INETADDR: if (asnlen != ASNLEN_INETADDR) printf("[inetaddr len!=%d]", ASNLEN_INETADDR); - sep='['; - for (i = asnlen; i-- > 0; p++) { - printf("%c%u", sep, *p); - sep='.'; + for (i = asnlen; i-- != 0; p++) { + printf((i == asnlen-1) ? "%u" : ".%u", *p); } - putchar(']'); break; - } + + case BE_NOSUCHOBJECT: + case BE_NOSUCHINST: + case BE_ENDOFMIBVIEW: + printf("[%s]", Class[EXCEPTIONS].Id[elem->id]); + break; case BE_PDU: printf("%s(%u)", @@ -678,6 +840,280 @@ asn1_decode(u_char *p, u_int length) } #endif +#ifdef LIBSMI + +struct smi2be { + SmiBasetype basetype; + int be; +}; + +static struct smi2be smi2betab[] = { + { SMI_BASETYPE_INTEGER32, BE_INT }, + { SMI_BASETYPE_OCTETSTRING, BE_STR }, + { SMI_BASETYPE_OCTETSTRING, BE_INETADDR }, + { SMI_BASETYPE_OBJECTIDENTIFIER, BE_OID }, + { SMI_BASETYPE_UNSIGNED32, BE_UNS }, + { SMI_BASETYPE_INTEGER64, BE_NONE }, + { SMI_BASETYPE_UNSIGNED64, BE_UNS64 }, + { SMI_BASETYPE_FLOAT32, BE_NONE }, + { SMI_BASETYPE_FLOAT64, BE_NONE }, + { SMI_BASETYPE_FLOAT128, BE_NONE }, + { SMI_BASETYPE_ENUM, BE_INT }, + { SMI_BASETYPE_BITS, BE_STR }, + { SMI_BASETYPE_UNKNOWN, BE_NONE } +}; + +static void smi_decode_oid(struct be *elem, unsigned int *oid, + unsigned int oidsize, unsigned int *oidlen) +{ + u_char *p = (u_char *)elem->data.raw; + u_int32_t asnlen = elem->asnlen; + int o = 0, first = -1, i = asnlen; + + for (*oidlen = 0; sflag && i-- > 0; p++) { + o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8); + if (*p & ASN_LONGLEN) + continue; + + /* + * first subitem encodes two items with 1st*OIDMUX+2nd + * (see X.690:1997 clause 8.19 for the details) + */ + if (first < 0) { + first = 0; + if (*oidlen < oidsize) { + oid[*oidlen] = o / OIDMUX; + if (oid[*oidlen] > 2) oid[*oidlen] = 2; + } + o -= oid[*oidlen] * OIDMUX; + if (*oidlen < oidsize) (*oidlen)++; + } + if (*oidlen < oidsize) { + oid[(*oidlen)++] = o; + } + o = 0; + } +} + +static int smi_check_type(SmiBasetype basetype, int be) +{ + int i; + + for (i = 0; smi2betab[i].basetype != SMI_BASETYPE_UNKNOWN; i++) { + if (smi2betab[i].basetype == basetype && smi2betab[i].be == be) { + return 1; + } + } + + return 0; +} + +static int smi_check_a_range(SmiType *smiType, SmiRange *smiRange, + struct be *elem) +{ + int ok = 1; + + switch (smiType->basetype) { + case SMI_BASETYPE_OBJECTIDENTIFIER: + case SMI_BASETYPE_OCTETSTRING: + if (smiRange->minValue.value.unsigned32 + == smiRange->maxValue.value.unsigned32) { + ok = (elem->asnlen == smiRange->minValue.value.unsigned32); + } else { + ok = (elem->asnlen >= smiRange->minValue.value.unsigned32 + && elem->asnlen <= smiRange->maxValue.value.unsigned32); + } + break; + + case SMI_BASETYPE_INTEGER32: + ok = (elem->data.integer >= smiRange->minValue.value.integer32 + && elem->data.integer <= smiRange->maxValue.value.integer32); + break; + + case SMI_BASETYPE_UNSIGNED32: + ok = (elem->data.uns >= smiRange->minValue.value.unsigned32 + && elem->data.uns <= smiRange->maxValue.value.unsigned32); + break; + + case SMI_BASETYPE_UNSIGNED64: + /* XXX */ + break; + + /* case SMI_BASETYPE_INTEGER64: SMIng */ + /* case SMI_BASETYPE_FLOAT32: SMIng */ + /* case SMI_BASETYPE_FLOAT64: SMIng */ + /* case SMI_BASETYPE_FLOAT128: SMIng */ + + case SMI_BASETYPE_ENUM: + case SMI_BASETYPE_BITS: + case SMI_BASETYPE_UNKNOWN: + ok = 1; + break; + } + + return ok; +} + +static int smi_check_range(SmiType *smiType, struct be *elem) +{ + SmiRange *smiRange; + int ok = 1; + + for (smiRange = smiGetFirstRange(smiType); + smiRange; + smiRange = smiGetNextRange(smiRange)) { + + ok = smi_check_a_range(smiType, smiRange, elem); + + if (ok) { + break; + } + } + + if (ok) { + SmiType *parentType; + parentType = smiGetParentType(smiType); + if (parentType) { + ok = smi_check_range(parentType, elem); + } + } + + return ok; +} + +static SmiNode *smi_print_variable(struct be *elem) +{ + unsigned int oid[128], oidlen; + SmiNode *smiNode = NULL; + int i; + + smi_decode_oid(elem, oid, sizeof(oid)/sizeof(unsigned int), &oidlen); + smiNode = smiGetNodeByOID(oidlen, oid); + if (! smiNode) { + asn1_print(elem); + return NULL; + } + if (vflag) { + fputs(smiGetNodeModule(smiNode)->name, stdout); + fputs("::", stdout); + } + fputs(smiNode->name, stdout); + if (smiNode->oidlen < oidlen) { + for (i = smiNode->oidlen; i < oidlen; i++) { + printf(".%u", oid[i]); + } + } + return smiNode; +} + +static void smi_print_value(SmiNode *smiNode, u_char pduid, struct be *elem) +{ + unsigned int oid[128], oidlen; + SmiType *smiType; + SmiNamedNumber *nn; + int i, done = 0; + + if (! smiNode || ! (smiNode->nodekind + & (SMI_NODEKIND_SCALAR | SMI_NODEKIND_COLUMN))) { + asn1_print(elem); + return; + } + + if (elem->type == BE_NOSUCHOBJECT + || elem->type == BE_NOSUCHINST + || elem->type == BE_ENDOFMIBVIEW) { + asn1_print(elem); + return; + } + + if (NOTIFY_CLASS(pduid) && smiNode->access < SMI_ACCESS_NOTIFY) { + fputs("[notNotifyable]", stdout); + } + + if (READ_CLASS(pduid) && smiNode->access < SMI_ACCESS_READ_ONLY) { + fputs("[notReadable]", stdout); + } + + if (WRITE_CLASS(pduid) && smiNode->access < SMI_ACCESS_READ_WRITE) { + fputs("[notWritable]", stdout); + } + + if (RESPONSE_CLASS(pduid) + && smiNode->access == SMI_ACCESS_NOT_ACCESSIBLE) { + fputs("[noAccess]", stdout); + } + + smiType = smiGetNodeType(smiNode); + if (! smiType) { + asn1_print(elem); + return; + } + + if (! smi_check_type(smiType->basetype, elem->type)) { + fputs("[wrongType]", stdout); + } + + if (! smi_check_range(smiType, elem)) { + fputs("[outOfRange]", stdout); + } + + /* resolve bits to named bits */ + + /* check whether instance identifier is valid */ + + /* apply display hints (integer, octetstring) */ + + /* convert instance identifier to index type values */ + + switch (elem->type) { + case BE_OID: + if (smiType->basetype == SMI_BASETYPE_BITS) { + /* print bit labels */ + } else { + smi_decode_oid(elem, oid, + sizeof(oid)/sizeof(unsigned int), + &oidlen); + smiNode = smiGetNodeByOID(oidlen, oid); + if (smiNode) { + if (vflag) { + fputs(smiGetNodeModule(smiNode)->name, stdout); + fputs("::", stdout); + } + fputs(smiNode->name, stdout); + if (smiNode->oidlen < oidlen) { + for (i = smiNode->oidlen; + i < oidlen; i++) { + printf(".%u", oid[i]); + } + } + done++; + } + } + break; + + case BE_INT: + if (smiType->basetype == SMI_BASETYPE_ENUM) { + for (nn = smiGetFirstNamedNumber(smiType); + nn; + nn = smiGetNextNamedNumber(nn)) { + if (nn->value.value.integer32 + == elem->data.integer) { + fputs(nn->name, stdout); + printf("(%d)", elem->data.integer); + done++; + break; + } + } + } + break; + } + + if (! done) { + asn1_print(elem); + } +} +#endif + /* * General SNMP header * SEQUENCE { @@ -715,10 +1151,13 @@ asn1_decode(u_char *p, u_int length) * Decode SNMP varBind */ static void -varbind_print(u_char pduid, const u_char *np, u_int length, int error) +varbind_print(u_char pduid, const u_char *np, u_int length) { struct be elem; int count = 0, ind; +#ifdef LIBSMI + SmiNode *smiNode = NULL; +#endif /* Sequence of varBind */ if ((count = asn1_parse(np, length, &elem)) < 0) @@ -728,7 +1167,7 @@ varbind_print(u_char pduid, const u_char *np, u_int length, int error) asn1_print(&elem); return; } - if (count < length) + if ((u_int)count < length) printf("[%d extra after SEQ of varbind]", length - count); /* descend */ length = elem.asnlen; @@ -738,8 +1177,7 @@ varbind_print(u_char pduid, const u_char *np, u_int length, int error) const u_char *vbend; u_int vblength; - if (!error || ind == error) - fputs(" ", stdout); + fputs(" ", stdout); /* Sequence */ if ((count = asn1_parse(np, length, &elem)) < 0) @@ -763,35 +1201,44 @@ varbind_print(u_char pduid, const u_char *np, u_int length, int error) asn1_print(&elem); return; } - if (!error || ind == error) - asn1_print(&elem); +#ifdef LIBSMI + smiNode = smi_print_variable(&elem); +#else + asn1_print(&elem); +#endif length -= count; np += count; - if (pduid != GETREQ && pduid != GETNEXTREQ && !error) + if (pduid != GETREQ && pduid != GETNEXTREQ + && pduid != GETBULKREQ) fputs("=", stdout); /* objVal (ANY) */ if ((count = asn1_parse(np, length, &elem)) < 0) return; - if (pduid == GETREQ || pduid == GETNEXTREQ) { + if (pduid == GETREQ || pduid == GETNEXTREQ + || pduid == GETBULKREQ) { if (elem.type != BE_NULL) { fputs("[objVal!=NULL]", stdout); asn1_print(&elem); } - } else - if (error && ind == error && elem.type != BE_NULL) - fputs("[err objVal!=NULL]", stdout); - if (!error || ind == error) + } else { + if (elem.type != BE_NULL) { +#ifdef LIBSMI + smi_print_value(smiNode, pduid, &elem); +#else asn1_print(&elem); - +#endif + } + } length = vblength; np = vbend; } } /* - * Decode SNMP PDUs: GetRequest, GetNextRequest, GetResponse, and SetRequest + * Decode SNMP PDUs: GetRequest, GetNextRequest, GetResponse, SetRequest, + * GetBulk, Inform, V2Trap, and Report */ static void snmppdu_print(u_char pduid, const u_char *np, u_int length) @@ -807,7 +1254,8 @@ snmppdu_print(u_char pduid, const u_char *np, u_int length) asn1_print(&elem); return; } - /* ignore the reqId */ + if (vflag) + printf("R=%d ", elem.data.integer); length -= count; np += count; @@ -820,11 +1268,14 @@ snmppdu_print(u_char pduid, const u_char *np, u_int length) return; } error = 0; - if ((pduid == GETREQ || pduid == GETNEXTREQ) + if ((pduid == GETREQ || pduid == GETNEXTREQ || pduid == SETREQ + || pduid == INFORMREQ || pduid == V2TRAP || pduid == REPORT) && elem.data.integer != 0) { char errbuf[10]; printf("[errorStatus(%s)!=0]", DECODE_ErrorStatus(elem.data.integer)); + } else if (pduid == GETBULKREQ) { + printf(" N=%d", elem.data.integer); } else if (elem.data.integer != 0) { char errbuf[10]; printf(" %s", DECODE_ErrorStatus(elem.data.integer)); @@ -841,9 +1292,12 @@ snmppdu_print(u_char pduid, const u_char *np, u_int length) asn1_print(&elem); return; } - if ((pduid == GETREQ || pduid == GETNEXTREQ) + if ((pduid == GETREQ || pduid == GETNEXTREQ || pduid == SETREQ + || pduid == INFORMREQ || pduid == V2TRAP || pduid == REPORT) && elem.data.integer != 0) printf("[errorIndex(%d)!=0]", elem.data.integer); + else if (pduid == GETBULKREQ) + printf(" M=%d", elem.data.integer); else if (elem.data.integer != 0) { if (!error) printf("[errorIndex(%d) w/o errorStatus]", @@ -859,7 +1313,7 @@ snmppdu_print(u_char pduid, const u_char *np, u_int length) length -= count; np += count; - varbind_print(pduid, np, length, error); + varbind_print(pduid, np, length); return; } @@ -867,7 +1321,7 @@ snmppdu_print(u_char pduid, const u_char *np, u_int length) * Decode SNMP Trap PDU */ static void -trap_print(const u_char *np, u_int length) +trappdu_print(const u_char *np, u_int length) { struct be elem; int count = 0, generic; @@ -946,58 +1400,132 @@ trap_print(const u_char *np, u_int length) length -= count; np += count; - varbind_print (TRAP, np, length, 0); + varbind_print (TRAP, np, length); return; } /* - * Decode SNMP header and pass on to PDU printing routines + * Decode arbitrary SNMP PDUs. */ -void -snmp_print(const u_char *np, u_int length) +static void +pdu_print(const u_char *np, u_int length, int version) { - struct be elem, pdu; + struct be pdu; int count = 0; - truncated = 0; + /* PDU (Context) */ + if ((count = asn1_parse(np, length, &pdu)) < 0) + return; + if (pdu.type != BE_PDU) { + fputs("[no PDU]", stdout); + return; + } + if ((u_int)count < length) + printf("[%d extra after PDU]", length - count); + if (vflag) { + fputs("{ ", stdout); + } + asn1_print(&pdu); + fputs(" ", stdout); + /* descend into PDU */ + length = pdu.asnlen; + np = (u_char *)pdu.data.raw; - /* truncated packet? */ - if (np + length > snapend) { - truncated = 1; - length = snapend - np; + if (version == SNMP_VERSION_1 && + (pdu.id == GETBULKREQ || pdu.id == INFORMREQ || + pdu.id == V2TRAP || pdu.id == REPORT)) { + printf("[v2 PDU in v1 message]"); + return; } - putchar(' '); + if (version == SNMP_VERSION_2 && pdu.id == TRAP) { + printf("[v1 PDU in v2 message]"); + return; + } - /* initial Sequence */ + switch (pdu.id) { + case TRAP: + trappdu_print(np, length); + break; + case GETREQ: + case GETNEXTREQ: + case GETRESP: + case SETREQ: + case GETBULKREQ: + case INFORMREQ: + case V2TRAP: + case REPORT: + snmppdu_print(pdu.id, np, length); + break; + } + + if (vflag) { + fputs(" } ", stdout); + } +} + +/* + * Decode a scoped SNMP PDU. + */ +static void +scopedpdu_print(const u_char *np, u_int length, int version) +{ + struct be elem; + int i, count = 0; + + /* Sequence */ if ((count = asn1_parse(np, length, &elem)) < 0) return; if (elem.type != BE_SEQ) { - fputs("[!init SEQ]", stdout); + fputs("[!scoped PDU]", stdout); asn1_print(&elem); return; } - if (count < length) - printf("[%d extra after iSEQ]", length - count); - /* descend */ length = elem.asnlen; np = (u_char *)elem.data.raw; - /* Version (Integer) */ + + /* contextEngineID (OCTET STRING) */ if ((count = asn1_parse(np, length, &elem)) < 0) return; - if (elem.type != BE_INT) { - fputs("[version!=INT]", stdout); + if (elem.type != BE_STR) { + fputs("[contextEngineID!=STR]", stdout); asn1_print(&elem); return; } - /* only handle version==0 */ - if (elem.data.integer != DEF_VERSION) { - printf("[version(%d)!=0]", elem.data.integer); + length -= count; + np += count; + + fputs("E= ", stdout); + for (i = 0; i < (int)elem.asnlen; i++) { + printf("0x%02X", elem.data.str[i]); + } + fputs(" ", stdout); + + /* contextName (OCTET STRING) */ + if ((count = asn1_parse(np, length, &elem)) < 0) + return; + if (elem.type != BE_STR) { + fputs("[contextName!=STR]", stdout); + asn1_print(&elem); return; } length -= count; np += count; + printf("C=%.*s ", (int)elem.asnlen, elem.data.str); + + pdu_print(np, length, version); +} + +/* + * Decode SNMP Community Header (SNMPv1 and SNMPv2c) + */ +static void +community_print(const u_char *np, u_int length, int version) +{ + struct be elem; + int count = 0; + /* Community (String) */ if ((count = asn1_parse(np, length, &elem)) < 0) return; @@ -1007,37 +1535,322 @@ snmp_print(const u_char *np, u_int length) return; } /* default community */ - if (strncmp((char *)elem.data.str, DEF_COMMUNITY, - sizeof(DEF_COMMUNITY) - 1)) + if (!(elem.asnlen == sizeof(DEF_COMMUNITY) - 1 && + strncmp((char *)elem.data.str, DEF_COMMUNITY, + sizeof(DEF_COMMUNITY) - 1) == 0)) /* ! "public" */ printf("C=%.*s ", (int)elem.asnlen, elem.data.str); length -= count; np += count; - /* PDU (Context) */ - if ((count = asn1_parse(np, length, &pdu)) < 0) + pdu_print(np, length, version); +} + +/* + * Decode SNMPv3 User-based Security Message Header (SNMPv3) + */ +static void +usm_print(const u_char *np, u_int length) +{ + struct be elem; + int count = 0; + + /* Sequence */ + if ((count = asn1_parse(np, length, &elem)) < 0) return; - if (pdu.type != BE_PDU) { - fputs("[no PDU]", stdout); + if (elem.type != BE_SEQ) { + fputs("[!usm]", stdout); + asn1_print(&elem); return; } - if (count < length) - printf("[%d extra after PDU]", length - count); - asn1_print(&pdu); - /* descend into PDU */ - length = pdu.asnlen; - np = (u_char *)pdu.data.raw; + length = elem.asnlen; + np = (u_char *)elem.data.raw; - switch (pdu.id) { - case TRAP: - trap_print(np, length); + /* msgAuthoritativeEngineID (OCTET STRING) */ + if ((count = asn1_parse(np, length, &elem)) < 0) + return; + if (elem.type != BE_STR) { + fputs("[msgAuthoritativeEngineID!=STR]", stdout); + asn1_print(&elem); + return; + } + length -= count; + np += count; + + /* msgAuthoritativeEngineBoots (INTEGER) */ + if ((count = asn1_parse(np, length, &elem)) < 0) + return; + if (elem.type != BE_INT) { + fputs("[msgAuthoritativeEngineBoots!=INT]", stdout); + asn1_print(&elem); + return; + } + if (vflag) + printf("B=%d ", elem.data.integer); + length -= count; + np += count; + + /* msgAuthoritativeEngineTime (INTEGER) */ + if ((count = asn1_parse(np, length, &elem)) < 0) + return; + if (elem.type != BE_INT) { + fputs("[msgAuthoritativeEngineTime!=INT]", stdout); + asn1_print(&elem); + return; + } + if (vflag) + printf("T=%d ", elem.data.integer); + length -= count; + np += count; + + /* msgUserName (OCTET STRING) */ + if ((count = asn1_parse(np, length, &elem)) < 0) + return; + if (elem.type != BE_STR) { + fputs("[msgUserName!=STR]", stdout); + asn1_print(&elem); + return; + } + length -= count; + np += count; + + printf("U=%.*s ", (int)elem.asnlen, elem.data.str); + + /* msgAuthenticationParameters (OCTET STRING) */ + if ((count = asn1_parse(np, length, &elem)) < 0) + return; + if (elem.type != BE_STR) { + fputs("[msgAuthenticationParameters!=STR]", stdout); + asn1_print(&elem); + return; + } + length -= count; + np += count; + + /* msgPrivacyParameters (OCTET STRING) */ + if ((count = asn1_parse(np, length, &elem)) < 0) + return; + if (elem.type != BE_STR) { + fputs("[msgPrivacyParameters!=STR]", stdout); + asn1_print(&elem); + return; + } + length -= count; + np += count; + + if ((u_int)count < length) + printf("[%d extra after usm SEQ]", length - count); +} + +/* + * Decode SNMPv3 Message Header (SNMPv3) + */ +static void +v3msg_print(const u_char *np, u_int length) +{ + struct be elem; + int count = 0; + u_char flags; + int model; + const u_char *xnp = np; + int xlength = length; + + /* Sequence */ + if ((count = asn1_parse(np, length, &elem)) < 0) + return; + if (elem.type != BE_SEQ) { + fputs("[!message]", stdout); + asn1_print(&elem); + return; + } + length = elem.asnlen; + np = (u_char *)elem.data.raw; + + if (vflag) { + fputs("{ ", stdout); + } + + /* msgID (INTEGER) */ + if ((count = asn1_parse(np, length, &elem)) < 0) + return; + if (elem.type != BE_INT) { + fputs("[msgID!=INT]", stdout); + asn1_print(&elem); + return; + } + length -= count; + np += count; + + /* msgMaxSize (INTEGER) */ + if ((count = asn1_parse(np, length, &elem)) < 0) + return; + if (elem.type != BE_INT) { + fputs("[msgMaxSize!=INT]", stdout); + asn1_print(&elem); + return; + } + length -= count; + np += count; + + /* msgFlags (OCTET STRING) */ + if ((count = asn1_parse(np, length, &elem)) < 0) + return; + if (elem.type != BE_STR) { + fputs("[msgFlags!=STR]", stdout); + asn1_print(&elem); + return; + } + if (elem.asnlen != 1) { + printf("[msgFlags size %d]", elem.asnlen); + return; + } + flags = elem.data.str[0]; + if (flags != 0x00 && flags != 0x01 && flags != 0x03 + && flags != 0x04 && flags != 0x05 && flags != 0x07) { + printf("[msgFlags=0x%02X]", flags); + return; + } + length -= count; + np += count; + + fputs("F=", stdout); + if (flags & 0x01) fputs("a", stdout); + if (flags & 0x02) fputs("p", stdout); + if (flags & 0x04) fputs("r", stdout); + fputs(" ", stdout); + + /* msgSecurityModel (INTEGER) */ + if ((count = asn1_parse(np, length, &elem)) < 0) + return; + if (elem.type != BE_INT) { + fputs("[msgSecurityModel!=INT]", stdout); + asn1_print(&elem); + return; + } + model = elem.data.integer; + length -= count; + np += count; + + if ((u_int)count < length) + printf("[%d extra after message SEQ]", length - count); + + if (vflag) { + fputs("} ", stdout); + } + + if (model == 3) { + if (vflag) { + fputs("{ USM ", stdout); + } + } else { + printf("[security model %d]", model); + return; + } + + np = xnp + (np - xnp); + length = xlength - (np - xnp); + + /* msgSecurityParameters (OCTET STRING) */ + if ((count = asn1_parse(np, length, &elem)) < 0) + return; + if (elem.type != BE_STR) { + fputs("[msgSecurityParameters!=STR]", stdout); + asn1_print(&elem); + return; + } + length -= count; + np += count; + + if (model == 3) { + usm_print(elem.data.str, elem.asnlen); + if (vflag) { + fputs("} ", stdout); + } + } + + if (vflag) { + fputs("{ ScopedPDU ", stdout); + } + + scopedpdu_print(np, length, 3); + + if (vflag) { + fputs("} ", stdout); + } +} + +/* + * Decode SNMP header and pass on to PDU printing routines + */ +void +snmp_print(const u_char *np, u_int length) +{ + struct be elem; + int count = 0; + int version = 0; + + truncated = 0; + + /* truncated packet? */ + if (np + length > snapend) { + truncated = 1; + length = snapend - np; + } + + putchar(' '); + + /* initial Sequence */ + if ((count = asn1_parse(np, length, &elem)) < 0) + return; + if (elem.type != BE_SEQ) { + fputs("[!init SEQ]", stdout); + asn1_print(&elem); + return; + } + if ((u_int)count < length) + printf("[%d extra after iSEQ]", length - count); + /* descend */ + length = elem.asnlen; + np = (u_char *)elem.data.raw; + + /* Version (INTEGER) */ + if ((count = asn1_parse(np, length, &elem)) < 0) + return; + if (elem.type != BE_INT) { + fputs("[version!=INT]", stdout); + asn1_print(&elem); + return; + } + + switch (elem.data.integer) { + case SNMP_VERSION_1: + case SNMP_VERSION_2: + case SNMP_VERSION_3: + if (vflag) + printf("{ %s ", SnmpVersion[elem.data.integer]); break; - case GETREQ: - case GETNEXTREQ: - case GETRESP: - case SETREQ: - snmppdu_print(pdu.id, np, length); + default: + printf("[version = %d]", elem.data.integer); + return; + } + version = elem.data.integer; + length -= count; + np += count; + + switch (version) { + case SNMP_VERSION_1: + case SNMP_VERSION_2: + community_print(np, length, version); + break; + case SNMP_VERSION_3: + v3msg_print(np, length); + break; + default: + printf("[version = %d]", elem.data.integer); break; } - return; + + if (vflag) { + fputs("} ", stdout); + } } diff --git a/kame/kame/tcpdump/print-stp.c b/kame/kame/tcpdump/print-stp.c new file mode 100644 index 0000000000..7b28070d48 --- /dev/null +++ b/kame/kame/tcpdump/print-stp.c @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2000 Lennert Buytenhek + * + * This software may be distributed either under the terms of the + * BSD-style license that accompanies tcpdump or the GNU General + * Public License + * + * Format and print IEEE 802.1d spanning tree protocol packets. + * Contributed by Lennert Buytenhek + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-stp.c,v 1.11.2.2 2003/11/16 08:51:46 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" + +static void +stp_print_bridge_id(const u_char *p) +{ + printf("%.2x%.2x.%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", + p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); +} + +static void +stp_print_config_bpdu(const u_char *p) +{ + printf("config "); + if (p[7] & 1) + printf("TOP_CHANGE "); + if (p[7] & 0x80) + printf("TOP_CHANGE_ACK "); + + stp_print_bridge_id(p+20); + printf(".%.2x%.2x ", p[28], p[29]); + + printf("root "); + stp_print_bridge_id(p+8); + + printf(" pathcost %i ", (p[16] << 24) | (p[17] << 16) | (p[18] << 8) | p[19]); + + printf("age %i ", p[30]); + printf("max %i ", p[32]); + printf("hello %i ", p[34]); + printf("fdelay %i ", p[36]); +} + +static void +stp_print_tcn_bpdu(void) +{ + printf("tcn"); +} + +/* + * Print 802.1d packets. + */ +void +stp_print(const u_char *p, u_int length) +{ + if (length < 7) + goto trunc; + + printf("802.1d "); + if (p[2] != 0x03 || p[3] || p[4] || p[5]) { + printf("unknown version"); + return; + } + + switch (p[6]) + { + case 0x00: + if (length < 10) + goto trunc; + stp_print_config_bpdu(p); + break; + + case 0x80: + stp_print_tcn_bpdu(); + break; + + default: + printf("unknown type %i", p[6]); + break; + } + + return; +trunc: + printf("[|stp %d]", length); +} diff --git a/kame/kame/tcpdump/print-sunatm.c b/kame/kame/tcpdump/print-sunatm.c new file mode 100644 index 0000000000..10be48708e --- /dev/null +++ b/kame/kame/tcpdump/print-sunatm.c @@ -0,0 +1,117 @@ +/* + * Copyright (c) 1997 Yen Yen Lim and North Dakota State University + * 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 Yen Yen Lim and + North Dakota State University + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * 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. + */ +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-sunatm.c,v 1.5.2.2 2003/11/16 08:51:47 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +struct mbuf; +struct rtentry; + +#include +#include + +#include "interface.h" +#include "extract.h" +#include "addrtoname.h" + +#include "atm.h" +#include "atmuni31.h" + +/* SunATM header for ATM packet */ +#define DIR_POS 0 /* Direction (0x80 = transmit, 0x00 = receive) */ +#define VPI_POS 1 /* VPI */ +#define VCI_POS 2 /* VCI */ +#define PKT_BEGIN_POS 4 /* Start of the ATM packet */ + +/* Protocol type values in the bottom for bits of the byte at SUNATM_DIR_POS. */ +#define PT_LANE 0x01 /* LANE */ +#define PT_LLC 0x02 /* LLC encapsulation */ + +/* + * This is the top level routine of the printer. 'p' points + * to the SunATM pseudo-header for the packet, 'h->ts' is the timestamp, + * 'h->length' is the length of the packet off the wire, and 'h->caplen' + * is the number of bytes actually captured. + */ +u_int +sunatm_if_print(const struct pcap_pkthdr *h, const u_char *p) +{ + u_int caplen = h->caplen; + u_int length = h->len; + u_short vci; + u_char vpi; + u_int traftype; + + if (caplen < PKT_BEGIN_POS) { + printf("[|atm]"); + return (caplen); + } + + if (eflag) { + if (p[DIR_POS] & 0x80) + printf("Tx: "); + else + printf("Rx: "); + } + + switch (p[DIR_POS] & 0x0f) { + + case PT_LANE: + traftype = ATM_LANE; + break; + + case PT_LLC: + traftype = ATM_LLC; + break; + + default: + traftype = ATM_UNKNOWN; + break; + } + + vci = EXTRACT_16BITS(&p[VCI_POS]); + vpi = p[VPI_POS]; + + p += PKT_BEGIN_POS; + caplen -= PKT_BEGIN_POS; + length -= PKT_BEGIN_POS; + atm_print(vpi, vci, traftype, p, length, caplen); + + return (PKT_BEGIN_POS); +} diff --git a/kame/kame/tcpdump/print-sunrpc.c b/kame/kame/tcpdump/print-sunrpc.c index 8bd9ae80f3..3ac556a287 100644 --- a/kame/kame/tcpdump/print-sunrpc.c +++ b/kame/kame/tcpdump/print-sunrpc.c @@ -20,39 +20,35 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-sunrpc.c,v 1.26 96/12/31 21:27:43 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-sunrpc.c,v 1.43.2.2 2003/11/16 08:51:47 guy Exp $ (LBL)"; #endif -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include -#include -#include -#include -#include -#include +#include #include #ifdef HAVE_RPC_RPCENT_H #include #endif +#ifndef WIN32 #include +#endif /* WIN32 */ -#include -#include #include #include #include "interface.h" #include "addrtoname.h" +#include "extract.h" + +#include "ip.h" +#ifdef INET6 +#include "ip6.h" +#endif static struct tok proc2str[] = { { PMAPPROC_NULL, "null" }, @@ -73,42 +69,62 @@ sunrpcrequest_print(register const u_char *bp, register u_int length, { register const struct rpc_msg *rp; register const struct ip *ip; +#ifdef INET6 + register const struct ip6_hdr *ip6; +#endif u_int32_t x; + char srcid[20], dstid[20]; /*fits 32bit*/ rp = (struct rpc_msg *)bp; - ip = (struct ip *)bp2; - - if (!nflag) - (void)printf("%s.%x > %s.sunrpc: %d", - ipaddr_string(&ip->ip_src), - (u_int32_t)ntohl(rp->rm_xid), - ipaddr_string(&ip->ip_dst), - length); - else - (void)printf("%s.%x > %s.%x: %d", - ipaddr_string(&ip->ip_src), - (u_int32_t)ntohl(rp->rm_xid), - ipaddr_string(&ip->ip_dst), - PMAPPORT, - length); + + if (!nflag) { + snprintf(srcid, sizeof(srcid), "0x%x", + EXTRACT_32BITS(&rp->rm_xid)); + strlcpy(dstid, "sunrpc", sizeof(dstid)); + } else { + snprintf(srcid, sizeof(srcid), "0x%x", + EXTRACT_32BITS(&rp->rm_xid)); + snprintf(dstid, sizeof(dstid), "0x%x", PMAPPORT); + } + + switch (IP_V((struct ip *)bp2)) { + case 4: + ip = (struct ip *)bp2; + printf("%s.%s > %s.%s: %d", + ipaddr_string(&ip->ip_src), srcid, + ipaddr_string(&ip->ip_dst), dstid, length); + break; +#ifdef INET6 + case 6: + ip6 = (struct ip6_hdr *)bp2; + printf("%s.%s > %s.%s: %d", + ip6addr_string(&ip6->ip6_src), srcid, + ip6addr_string(&ip6->ip6_dst), dstid, length); + break; +#endif + default: + printf("%s.%s > %s.%s: %d", "?", srcid, "?", dstid, length); + break; + } + printf(" %s", tok2str(proc2str, " proc #%u", - (u_int32_t)ntohl(rp->rm_call.cb_proc))); - x = ntohl(rp->rm_call.cb_rpcvers); + EXTRACT_32BITS(&rp->rm_call.cb_proc))); + x = EXTRACT_32BITS(&rp->rm_call.cb_rpcvers); if (x != 2) printf(" [rpcver %u]", x); - switch (ntohl(rp->rm_call.cb_proc)) { + switch (EXTRACT_32BITS(&rp->rm_call.cb_proc)) { case PMAPPROC_SET: case PMAPPROC_UNSET: case PMAPPROC_GETPORT: case PMAPPROC_CALLIT: - x = ntohl(rp->rm_call.cb_prog); + x = EXTRACT_32BITS(&rp->rm_call.cb_prog); if (!nflag) printf(" %s", progstr(x)); else printf(" %u", x); - printf(".%u", (u_int32_t)ntohl(rp->rm_call.cb_vers)); + printf(".%u", EXTRACT_32BITS(&rp->rm_call.cb_vers)); break; } } @@ -117,16 +133,22 @@ static char * progstr(prog) u_int32_t prog; { +#ifndef WIN32 register struct rpcent *rp; +#endif static char buf[32]; - static int lastprog = 0; + static u_int32_t lastprog = 0; if (lastprog != 0 && prog == lastprog) return (buf); +#ifndef WIN32 rp = getrpcbynumber(prog); if (rp == NULL) - (void) sprintf(buf, "#%u", prog); +#endif /* WIN32 */ + (void) snprintf(buf, sizeof(buf), "#%u", prog); +#ifndef WIN32 else - strcpy(buf, rp->r_name); + strlcpy(buf, rp->r_name, sizeof(buf)); +#endif return (buf); } diff --git a/kame/kame/tcpdump/print-tcp.c b/kame/kame/tcpdump/print-tcp.c index bbe89e327e..5b0b06c901 100644 --- a/kame/kame/tcpdump/print-tcp.c +++ b/kame/kame/tcpdump/print-tcp.c @@ -20,63 +20,40 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-tcp.c,v 1.55 97/06/15 13:20:28 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.107.2.3 2003/11/19 00:17:02 guy Exp $ (LBL)"; #endif -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include -#include -#include -#include -#include +#include + +#include -#ifdef HAVE_MEMORY_H -#include -#endif #include #include #include -#include - -#ifdef INET6 -#include -#endif #include "interface.h" #include "addrtoname.h" #include "extract.h" -/* 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) */ +#include "tcp.h" + +#include "ip.h" +#ifdef INET6 +#include "ip6.h" #endif +#include "ipproto.h" + +#include "nameser.h" + +static void print_tcp_rst_data(register const u_char *sp, u_int length); + +#define MAX_RST_DATA_LEN 30 + struct tha { #ifndef INET6 @@ -104,17 +81,111 @@ struct tcp_seq_hash { static struct tcp_seq_hash tcp_seq_hash[TSEQ_HASHSIZE]; +#ifndef TELNET_PORT +#define TELNET_PORT 23 +#endif +#ifndef BGP_PORT +#define BGP_PORT 179 +#endif +#define NETBIOS_SSN_PORT 139 +#ifndef PPTP_PORT +#define PPTP_PORT 1723 +#endif +#define BEEP_PORT 10288 +#ifndef NFS_PORT +#define NFS_PORT 2049 +#endif +#define MSDP_PORT 639 +#define LDP_PORT 646 + +static int tcp_cksum(register const struct ip *ip, + register const struct tcphdr *tp, + register u_int len) +{ + union phu { + struct phdr { + u_int32_t src; + u_int32_t dst; + u_char mbz; + u_char proto; + u_int16_t len; + } ph; + u_int16_t pa[6]; + } phu; + const u_int16_t *sp; + + /* pseudo-header.. */ + phu.ph.len = htons((u_int16_t)len); + phu.ph.mbz = 0; + phu.ph.proto = IPPROTO_TCP; + memcpy(&phu.ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t)); + if (IP_HL(ip) == 5) + memcpy(&phu.ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t)); + else + phu.ph.dst = ip_finddst(ip); + + sp = &phu.pa[0]; + return in_cksum((u_short *)tp, len, + sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5]); +} + +#ifdef INET6 +static int tcp6_cksum(const struct ip6_hdr *ip6, const struct tcphdr *tp, + u_int len) +{ + size_t i; + register const u_int16_t *sp; + u_int32_t sum; + union { + struct { + struct in6_addr ph_src; + struct in6_addr ph_dst; + u_int32_t ph_len; + u_int8_t ph_zero[3]; + u_int8_t ph_nxt; + } ph; + u_int16_t pa[20]; + } phu; + + /* pseudo-header */ + memset(&phu, 0, sizeof(phu)); + phu.ph.ph_src = ip6->ip6_src; + phu.ph.ph_dst = ip6->ip6_dst; + phu.ph.ph_len = htonl(len); + phu.ph.ph_nxt = IPPROTO_TCP; + + sum = 0; + for (i = 0; i < sizeof(phu.pa) / sizeof(phu.pa[0]); i++) + sum += phu.pa[i]; + + sp = (const u_int16_t *)tp; + + for (i = 0; i < (len & ~1); i += 2) + sum += *sp++; + + if (len & 1) + sum += htons((*(const u_int8_t *)sp) << 8); + + while (sum > 0xffff) + sum = (sum & 0xffff) + (sum >> 16); + sum = ~sum & 0xffff; + + return (sum); +} +#endif + void tcp_print(register const u_char *bp, register u_int length, - register const u_char *bp2) + register const u_char *bp2, int fragmented) { register const struct tcphdr *tp; register const struct ip *ip; register u_char flags; - register int hlen; + register u_int hlen; register char ch; - u_short sport, dport, win, urp; - u_int32_t seq, ack; + u_int16_t sport, dport, win, urp; + u_int32_t seq, ack, thseq, thack; + int threv; #ifdef INET6 register const struct ip6_hdr *ip6; #endif @@ -122,28 +193,46 @@ tcp_print(register const u_char *bp, register u_int length, tp = (struct tcphdr *)bp; ip = (struct ip *)bp2; #ifdef INET6 - if (ip->ip_v == 6) + if (IP_V(ip) == 6) ip6 = (struct ip6_hdr *)bp2; else ip6 = NULL; #endif /*INET6*/ ch = '\0'; - TCHECK(*tp); - if (length < sizeof(*tp)) { - (void)printf("truncated-tcp %d", length); + if (!TTEST(tp->th_dport)) { + (void)printf("%s > %s: [|tcp]", + ipaddr_string(&ip->ip_src), + ipaddr_string(&ip->ip_dst)); return; } - sport = ntohs(tp->th_sport); - dport = ntohs(tp->th_dport); - seq = ntohl(tp->th_seq); - ack = ntohl(tp->th_ack); - win = ntohs(tp->th_win); - urp = ntohs(tp->th_urp); + sport = EXTRACT_16BITS(&tp->th_sport); + dport = EXTRACT_16BITS(&tp->th_dport); + + hlen = TH_OFF(tp) * 4; + /* + * If data present and NFS port used, assume NFS. + * Pass offset of data plus 4 bytes for RPC TCP msg length + * to NFS print routines. + */ + if (!qflag) { + if ((u_char *)tp + 4 + sizeof(struct rpc_msg) <= snapend && + dport == NFS_PORT) { + 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, + (u_char *)ip); + return; + } + } #ifdef INET6 if (ip6) { - if (bp == (u_char *)(ip6 + 1)) { + if (ip6->ip6_nxt == IPPROTO_TCP) { (void)printf("%s.%s > %s.%s: ", ip6addr_string(&ip6->ip6_src), tcpport_string(sport), @@ -156,7 +245,7 @@ tcp_print(register const u_char *bp, register u_int length, } else #endif /*INET6*/ { - if (bp == (u_char *)(ip + 1)) { + if (ip->ip_p == IPPROTO_TCP) { (void)printf("%s.%s > %s.%s: ", ipaddr_string(&ip->ip_src), tcpport_string(sport), @@ -168,15 +257,19 @@ tcp_print(register const u_char *bp, register u_int length, } } + TCHECK(*tp); + + seq = EXTRACT_32BITS(&tp->th_seq); + ack = EXTRACT_32BITS(&tp->th_ack); + win = EXTRACT_16BITS(&tp->th_win); + urp = EXTRACT_16BITS(&tp->th_urp); + if (qflag) { - (void)printf("tcp %d", length - tp->th_off * 4); + (void)printf("tcp %d", length - TH_OFF(tp) * 4); return; } -#ifdef TH_ECN - if ((flags = tp->th_flags) & (TH_SYN|TH_FIN|TH_RST|TH_PUSH|TH_ECN)) { -#else - if ((flags = tp->th_flags) & (TH_SYN|TH_FIN|TH_RST|TH_PUSH)) { -#endif + if ((flags = tp->th_flags) & (TH_SYN|TH_FIN|TH_RST|TH_PUSH| + TH_ECNECHO|TH_CWR)) { if (flags & TH_SYN) putchar('S'); if (flags & TH_FIN) @@ -185,15 +278,16 @@ tcp_print(register const u_char *bp, register u_int length, putchar('R'); if (flags & TH_PUSH) putchar('P'); -#ifdef TH_ECN - if (flags & TH_ECN) - putchar('C'); -#endif + if (flags & TH_CWR) + putchar('W'); /* congestion _W_indow reduced (ECN) */ + if (flags & TH_ECNECHO) + putchar('E'); /* ecn _E_cho sent (ECN) */ } else putchar('.'); if (!Sflag && (flags & TH_ACK)) { register struct tcp_seq_hash *th; + const void *src, *dst; register int rev; struct tha tha; /* @@ -203,68 +297,74 @@ tcp_print(register const u_char *bp, register u_int length, * both directions). */ #ifdef INET6 - bzero(&tha, sizeof(tha)); + memset(&tha, 0, sizeof(tha)); rev = 0; if (ip6) { - if (sport > dport) { + src = &ip6->ip6_src; + dst = &ip6->ip6_dst; + 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]) { + else if (sport == dport) { + if (memcmp(src, dst, sizeof ip6->ip6_dst) > 0) rev = 1; - break; - } - } } if (rev) { - tha.src = ip6->ip6_dst; - tha.dst = ip6->ip6_src; + memcpy(&tha.src, dst, sizeof ip6->ip6_dst); + memcpy(&tha.dst, src, sizeof ip6->ip6_src); tha.port = dport << 16 | sport; } else { - tha.dst = ip6->ip6_dst; - tha.src = ip6->ip6_src; + memcpy(&tha.dst, dst, sizeof ip6->ip6_dst); + memcpy(&tha.src, src, sizeof ip6->ip6_src); tha.port = sport << 16 | dport; } } else { - if (sport > dport || - (sport == dport && - ip->ip_src.s_addr > ip->ip_dst.s_addr)) { + src = &ip->ip_src; + dst = &ip->ip_dst; + if (sport > dport) rev = 1; + else if (sport == dport) { + if (memcmp(src, dst, sizeof ip->ip_dst) > 0) + rev = 1; } if (rev) { - *(struct in_addr *)&tha.src = ip->ip_dst; - *(struct in_addr *)&tha.dst = ip->ip_src; + memcpy(&tha.src, dst, sizeof ip->ip_dst); + memcpy(&tha.dst, src, sizeof ip->ip_src); tha.port = dport << 16 | sport; } else { - *(struct in_addr *)&tha.dst = ip->ip_dst; - *(struct in_addr *)&tha.src = ip->ip_src; + memcpy(&tha.dst, dst, sizeof ip->ip_dst); + memcpy(&tha.src, src, sizeof ip->ip_src); tha.port = sport << 16 | dport; } } #else - if (sport < dport || - (sport == dport && - ip->ip_src.s_addr < ip->ip_dst.s_addr)) { - tha.src = ip->ip_src, tha.dst = ip->ip_dst; - tha.port = sport << 16 | dport; - rev = 0; - } else { - tha.src = ip->ip_dst, tha.dst = ip->ip_src; - tha.port = dport << 16 | sport; + rev = 0; + src = &ip->ip_src; + dst = &ip->ip_dst; + if (sport > dport) rev = 1; + else if (sport == dport) { + if (memcmp(src, dst, sizeof ip->ip_dst) > 0) + rev = 1; + } + if (rev) { + memcpy(&tha.src, dst, sizeof ip->ip_dst); + memcpy(&tha.dst, src, sizeof ip->ip_src); + tha.port = dport << 16 | sport; + } else { + memcpy(&tha.dst, dst, sizeof ip->ip_dst); + memcpy(&tha.src, src, sizeof ip->ip_src); + tha.port = sport << 16 | dport; } #endif + threv = rev; for (th = &tcp_seq_hash[tha.port % TSEQ_HASHSIZE]; th->nxt; th = th->nxt) - if (!memcmp((char *)&tha, (char *)&th->addr, - sizeof(th->addr))) + if (memcmp((char *)&tha, (char *)&th->addr, + sizeof(th->addr)) == 0) break; - if (!th->nxt || flags & TH_SYN) { + if (!th->nxt || (flags & TH_SYN)) { /* didn't find it or new conversation */ if (th->nxt == NULL) { th->nxt = (struct tcp_seq_hash *) @@ -283,15 +383,46 @@ tcp_print(register const u_char *bp, register u_int length, else seq -= th->seq, ack -= th->ack; } + + thseq = th->seq; + thack = th->ack; + } else { + /*fool gcc*/ + thseq = thack = threv = 0; } - hlen = tp->th_off * 4; if (hlen > length) { (void)printf(" [bad hdr length]"); return; } + + if (IP_V(ip) == 4 && vflag && !fragmented) { + u_int16_t sum, tcp_sum; + if (TTEST2(tp->th_sport, length)) { + sum = tcp_cksum(ip, tp, length); + if (sum != 0) { + tcp_sum = EXTRACT_16BITS(&tp->th_sum); + (void)printf(" [bad tcp cksum %x (->%x)!]", + tcp_sum, in_cksum_shouldbe(tcp_sum, sum)); + } else + (void)printf(" [tcp sum ok]"); + } + } +#ifdef INET6 + if (IP_V(ip) == 6 && ip6->ip6_plen && vflag && !fragmented) { + int sum; + if (TTEST2(tp->th_sport, length)) { + sum = tcp6_cksum(ip6, tp, length); + if (sum != 0) + (void)printf(" [bad tcp cksum %x!]", sum); + else + (void)printf(" [tcp sum ok]"); + } + } +#endif + length -= hlen; - if (length > 0 || flags & (TH_SYN | TH_FIN | TH_RST)) - (void)printf(" %u:%u(%d)", seq, seq + length, length); + if (vflag > 1 || length > 0 || flags & (TH_SYN | TH_FIN | TH_RST)) + (void)printf(" %u:%u(%u)", seq, seq + length, length); if (flags & TH_ACK) (void)printf(" ack %u", ack); @@ -302,10 +433,12 @@ tcp_print(register const u_char *bp, register u_int length, /* * Handle any options. */ - if ((hlen -= sizeof(*tp)) > 0) { + if (hlen > sizeof(*tp)) { register const u_char *cp; - register int i, opt, len, datalen; + register u_int i, opt, datalen; + register u_int len; + hlen -= sizeof(*tp); cp = (const u_char *)tp + sizeof(*tp); putchar(' '); ch = '<'; @@ -360,15 +493,28 @@ tcp_print(register const u_char *bp, register u_int length, case TCPOPT_SACK: (void)printf("sack"); datalen = len - 2; - for (i = 0; i < datalen; i += 4) { - LENCHECK(i + 4); - /* block-size@relative-origin */ - (void)printf(" %u@%u", - EXTRACT_16BITS(cp + i + 2), - EXTRACT_16BITS(cp + i)); + if (datalen % 8 != 0) { + (void)printf(" malformed sack "); + } else { + u_int32_t s, e; + + (void)printf(" sack %d ", datalen / 8); + for (i = 0; i < datalen; i += 8) { + LENCHECK(i + 4); + s = EXTRACT_32BITS(cp + i); + LENCHECK(i + 8); + e = EXTRACT_32BITS(cp + i + 4); + if (threv) { + s -= thseq; + e -= thseq; + } else { + s -= thack; + e -= thack; + } + (void)printf("{%u:%u}", s, e); + } + (void)printf(" "); } - if (datalen % 4) - (void)printf("[len %d]", len); break; case TCPOPT_ECHO: @@ -416,7 +562,7 @@ tcp_print(register const u_char *bp, register u_int length, break; default: - (void)printf("opt-%d:", opt); + (void)printf("opt-%u:", opt); datalen = len - 2; for (i = 0; i < datalen; ++i) { LENCHECK(i); @@ -441,6 +587,45 @@ tcp_print(register const u_char *bp, register u_int length, } putchar('>'); } + + if (length <= 0) + return; + + /* + * Decode payload if necessary. + */ + bp += TH_OFF(tp) * 4; + if (flags & TH_RST) { + if (vflag) + print_tcp_rst_data(bp, length); + } else { + if (sport == TELNET_PORT || dport == TELNET_PORT) { + if (!qflag && vflag) + 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); +#ifdef TCPDUMP_DO_SMB + else if (sport == NETBIOS_SSN_PORT || dport == NETBIOS_SSN_PORT) + nbt_tcp_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 || + sport == MULTICASTDNS_PORT || dport == MULTICASTDNS_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, 0); + } else if (sport == MSDP_PORT || dport == MSDP_PORT) { + msdp_print(bp, length); + } + else if (sport == LDP_PORT || dport == LDP_PORT) + printf(": LDP, length: %u", length); + } return; bad: fputs("[bad opt]", stdout); @@ -453,3 +638,38 @@ tcp_print(register const u_char *bp, register u_int length, putchar('>'); } +/* + * RFC1122 says the following on data in RST segments: + * + * 4.2.2.12 RST Segment: RFC-793 Section 3.4 + * + * A TCP SHOULD allow a received RST segment to include data. + * + * DISCUSSION + * It has been suggested that a RST segment could contain + * ASCII text that encoded and explained the cause of the + * RST. No standard has yet been established for such + * data. + * + */ + +static void +print_tcp_rst_data(register const u_char *sp, u_int length) +{ + int c; + + if (TTEST2(*sp, length)) + printf(" [RST"); + else + printf(" [!RST"); + if (length > MAX_RST_DATA_LEN) { + length = MAX_RST_DATA_LEN; /* can use -X for longer */ + putchar('+'); /* indicate we truncate */ + } + putchar(' '); + while (length-- && sp <= snapend) { + c = *sp++; + safeputchar(c); + } + putchar(']'); +} diff --git a/kame/kame/tcpdump/print-telnet.c b/kame/kame/tcpdump/print-telnet.c new file mode 100644 index 0000000000..b420d35b51 --- /dev/null +++ b/kame/kame/tcpdump/print-telnet.c @@ -0,0 +1,267 @@ +/* $NetBSD: print-telnet.c,v 1.2 1999/10/11 12:40:12 sjg Exp $ */ + +/*- + * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Simon J. Gerraty. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ +/* + * @(#)Copyright (c) 1994, Simon J. Gerraty. + * + * This is free software. It comes with NO WARRANTY. + * Permission to use, modify and distribute this source code + * is granted subject to the following conditions. + * 1/ that the above copyright notice and this notice + * are preserved in all copies. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-telnet.c,v 1.21.2.3 2003/12/29 22:42:23 hannes Exp $"; +#endif + +#include + +#include +#include +#include + +#include "interface.h" +#include "addrtoname.h" + +#define TELCMDS +#define TELOPTS +#include "telnet.h" + +/* 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 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, x; + u_int c; + 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) { /* ! */ + 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 > (u_int)(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: + if (p <= sp) + break; + 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:"); + hex_print_with_offset("\n", sp, l, sp - osp); + if (l > 8) + printf("\n\t\t\t\t"); + else + printf("%*s\t", (8 - l) * 3, ""); + } else + printf("%s", (first) ? " [telnet " : ", "); + + (void)telnet_parse(sp, length, 1); + first = 0; + + sp += l; + length -= l; + } + if (!first) { + if (Xflag && 2 < vflag) + printf("\n"); + else + printf("]"); + } +} diff --git a/kame/kame/tcpdump/print-tftp.c b/kame/kame/tcpdump/print-tftp.c index d8a7b3e647..261b59487c 100644 --- a/kame/kame/tcpdump/print-tftp.c +++ b/kame/kame/tcpdump/print-tftp.c @@ -22,26 +22,27 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-tftp.c,v 1.30 97/06/13 12:57:12 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-tftp.c,v 1.35.2.2 2003/11/16 08:51:50 guy Exp $ (LBL)"; #endif -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include +#include #ifdef SEGSIZE #undef SEGSIZE /* SINIX sucks */ #endif #include -#include #include #include #include "interface.h" #include "addrtoname.h" +#include "extract.h" /* op code to string mapping */ static struct tok op2str[] = { @@ -85,7 +86,7 @@ tftp_print(register const u_char *bp, u_int length) /* Print tftp request type */ TCHECK(tp->th_opcode); - opcode = ntohs(tp->th_opcode); + opcode = EXTRACT_16BITS(&tp->th_opcode); cp = tok2str(op2str, "tftp-#%d", opcode); printf(" %s", cp); /* Bail if bogus opcode */ @@ -108,6 +109,18 @@ tftp_print(register const u_char *bp, u_int length) fputs(" \"", stdout); i = fn_print(p, snapend); putchar('"'); + + /* Print the mode and any options */ + while ((p = (const u_char *)strchr((const char *)p, '\0')) != NULL) { + if (length <= (u_int)(p - (const u_char *)&tp->th_block)) + break; + p++; + if (*p != '\0') { + putchar(' '); + fn_print(p, snapend); + } + } + if (i) goto trunc; break; @@ -115,14 +128,14 @@ tftp_print(register const u_char *bp, u_int length) case ACK: case DATA: TCHECK(tp->th_block); - printf(" block %d", ntohs(tp->th_block)); + printf(" block %d", EXTRACT_16BITS(&tp->th_block)); break; case ERROR: /* Print error code string */ TCHECK(tp->th_code); printf(" %s ", tok2str(err2str, "tftp-err-#%d \"", - ntohs(tp->th_code))); + EXTRACT_16BITS(&tp->th_code))); /* Print error message string */ i = fn_print((const u_char *)tp->th_data, snapend); putchar('"'); diff --git a/kame/kame/tcpdump/print-timed.c b/kame/kame/tcpdump/print-timed.c new file mode 100644 index 0000000000..9ad7668aec --- /dev/null +++ b/kame/kame/tcpdump/print-timed.c @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2000 Ben Smithurst + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-timed.c,v 1.7.2.2 2003/11/16 08:51:51 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include + +#include "timed.h" +#include "interface.h" +#include "extract.h" + +static const char *tsptype[TSPTYPENUMBER] = + { "ANY", "ADJTIME", "ACK", "MASTERREQ", "MASTERACK", "SETTIME", "MASTERUP", + "SLAVEUP", "ELECTION", "ACCEPT", "REFUSE", "CONFLICT", "RESOLVE", "QUIT", + "DATE", "DATEREQ", "DATEACK", "TRACEON", "TRACEOFF", "MSITE", "MSITEREQ", + "TEST", "SETDATE", "SETDATEREQ", "LOOP" }; + +void +timed_print(register const u_char *bp) +{ +#define endof(x) ((u_char *)&(x) + sizeof (x)) + struct tsp *tsp = (struct tsp *)bp; + long sec, usec; + const u_char *end; + + if (endof(tsp->tsp_type) > snapend) { + fputs("[|timed]", stdout); + return; + } + if (tsp->tsp_type < TSPTYPENUMBER) + printf("TSP_%s", tsptype[tsp->tsp_type]); + else + printf("(tsp_type %#x)", tsp->tsp_type); + + if (endof(tsp->tsp_vers) > snapend) { + fputs(" [|timed]", stdout); + return; + } + printf(" vers %d", tsp->tsp_vers); + + if (endof(tsp->tsp_seq) > snapend) { + fputs(" [|timed]", stdout); + return; + } + printf(" seq %d", tsp->tsp_seq); + + if (tsp->tsp_type == TSP_LOOP) { + if (endof(tsp->tsp_hopcnt) > snapend) { + fputs(" [|timed]", stdout); + return; + } + printf(" hopcnt %d", tsp->tsp_hopcnt); + } else if (tsp->tsp_type == TSP_SETTIME || + tsp->tsp_type == TSP_ADJTIME || + tsp->tsp_type == TSP_SETDATE || + tsp->tsp_type == TSP_SETDATEREQ) { + if (endof(tsp->tsp_time) > snapend) { + fputs(" [|timed]", stdout); + return; + } + sec = EXTRACT_32BITS(&tsp->tsp_time.tv_sec); + usec = EXTRACT_32BITS(&tsp->tsp_time.tv_usec); + if (usec < 0) + /* corrupt, skip the rest of the packet */ + return; + fputs(" time ", stdout); + if (sec < 0 && usec != 0) { + sec++; + if (sec == 0) + fputc('-', stdout); + usec = 1000000 - usec; + } + printf("%ld.%06ld", sec, usec); + } + + end = memchr(tsp->tsp_name, '\0', snapend - (u_char *)tsp->tsp_name); + if (end == NULL) + fputs(" [|timed]", stdout); + else { + fputs(" name ", stdout); + fwrite(tsp->tsp_name, end - (u_char *)tsp->tsp_name, 1, stdout); + } +} diff --git a/kame/kame/tcpdump/print-token.c b/kame/kame/tcpdump/print-token.c new file mode 100644 index 0000000000..74f6d8bb69 --- /dev/null +++ b/kame/kame/tcpdump/print-token.c @@ -0,0 +1,195 @@ +/* + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996 + * 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. + * + * Hacked version of print-ether.c Larry Lile + * + * Further tweaked to more closely resemble print-fddi.c + * Guy Harris + */ +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-token.c,v 1.22.2.2 2003/11/16 08:51:51 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "ethertype.h" + +#include "ether.h" +#include "token.h" + +/* Extract src, dst addresses */ +static inline void +extract_token_addrs(const struct token_header *trp, char *fsrc, char *fdst) +{ + memcpy(fdst, (const char *)trp->token_dhost, 6); + memcpy(fsrc, (const char *)trp->token_shost, 6); +} + +/* + * Print the TR MAC header + */ +static inline void +token_hdr_print(register const struct token_header *trp, register u_int length, + register const u_char *fsrc, register const u_char *fdst) +{ + const char *srcname, *dstname; + + srcname = etheraddr_string(fsrc); + dstname = etheraddr_string(fdst); + + if (vflag) + (void) printf("%02x %02x %s %s %d: ", + trp->token_ac, + trp->token_fc, + srcname, dstname, + length); + else + printf("%s %s %d: ", srcname, dstname, length); +} + +static const char *broadcast_indicator[] = { + "Non-Broadcast", "Non-Broadcast", + "Non-Broadcast", "Non-Broadcast", + "All-routes", "All-routes", + "Single-route", "Single-route" +}; + +static const char *direction[] = { + "Forward", "Backward" +}; + +static const char *largest_frame[] = { + "516", + "1500", + "2052", + "4472", + "8144", + "11407", + "17800", + "??" +}; + +u_int +token_print(const u_char *p, u_int length, u_int caplen) +{ + const struct token_header *trp; + u_short extracted_ethertype; + struct ether_header ehdr; + u_int route_len = 0, hdr_len = TOKEN_HDRLEN; + int seg; + + trp = (const struct token_header *)p; + + if (caplen < TOKEN_HDRLEN) { + printf("[|token-ring]"); + return hdr_len; + } + + /* + * Get the TR addresses into a canonical form + */ + extract_token_addrs(trp, (char*)ESRC(&ehdr), (char*)EDST(&ehdr)); + + /* Adjust for source routing information in the MAC header */ + if (IS_SOURCE_ROUTED(trp)) { + /* Clear source-routed bit */ + *ESRC(&ehdr) &= 0x7f; + + if (eflag) + token_hdr_print(trp, length, ESRC(&ehdr), EDST(&ehdr)); + + route_len = RIF_LENGTH(trp); + if (vflag) { + printf("%s ", broadcast_indicator[BROADCAST(trp)]); + printf("%s", direction[DIRECTION(trp)]); + + for (seg = 0; seg < SEGMENT_COUNT(trp); seg++) + printf(" [%d:%d]", RING_NUMBER(trp, seg), + BRIDGE_NUMBER(trp, seg)); + } else { + printf("rt = %x", ntohs(trp->token_rcf)); + + for (seg = 0; seg < SEGMENT_COUNT(trp); seg++) + printf(":%x", ntohs(trp->token_rseg[seg])); + } + printf(" (%s) ", largest_frame[LARGEST_FRAME(trp)]); + } else { + if (eflag) + token_hdr_print(trp, length, ESRC(&ehdr), EDST(&ehdr)); + } + + /* Skip over token ring MAC header and routing information */ + hdr_len += route_len; + length -= hdr_len; + p += hdr_len; + caplen -= hdr_len; + + /* Frame Control field determines interpretation of packet */ + extracted_ethertype = 0; + if (FRAME_TYPE(trp) == TOKEN_FC_LLC) { + /* Try to print the LLC-layer header & higher layers */ + if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr), + &extracted_ethertype) == 0) { + /* ether_type not known, print raw packet */ + if (!eflag) + token_hdr_print(trp, + length + TOKEN_HDRLEN + route_len, + ESRC(&ehdr), EDST(&ehdr)); + if (extracted_ethertype) { + printf("(LLC %s) ", + etherproto_string(htons(extracted_ethertype))); + } + if (!xflag && !qflag) + default_print(p, caplen); + } + } else { + /* Some kinds of TR packet we cannot handle intelligently */ + /* XXX - dissect MAC packets if frame type is 0 */ + if (!eflag) + token_hdr_print(trp, length + TOKEN_HDRLEN + route_len, + ESRC(&ehdr), EDST(&ehdr)); + if (!xflag && !qflag) + default_print(p, caplen); + } + return (hdr_len); +} + +/* + * This is the top level routine of the printer. 'p' points + * to the TR header of the packet, 'h->ts' is the timestamp, + * 'h->length' is the length of the packet off the wire, and 'h->caplen' + * is the number of bytes actually captured. + */ +u_int +token_if_print(const struct pcap_pkthdr *h, const u_char *p) +{ + return (token_print(p, h->len, h->caplen)); +} diff --git a/kame/kame/tcpdump/print-udp.c b/kame/kame/tcpdump/print-udp.c index ac198a2a96..6fb83f7684 100644 --- a/kame/kame/tcpdump/print-udp.c +++ b/kame/kame/tcpdump/print-udp.c @@ -20,28 +20,16 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-udp.c,v 1.60 97/07/27 21:58:48 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.124.2.5 2003/11/19 00:19:25 guy Exp $ (LBL)"; #endif -#include -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include -#include -#include -#include -#include -#include +#include -#ifdef NOERROR -#undef NOERROR /* Solaris sucks */ -#endif -#ifdef T_UNSPEC -#undef T_UNSPEC /* SINIX does too */ -#endif -#include #ifdef SEGSIZE #undef SEGSIZE #endif @@ -50,27 +38,34 @@ static const char rcsid[] = #include #include - -#ifdef INET6 -#include -#endif +#include #include "interface.h" #include "addrtoname.h" +#include "extract.h" #include "appletalk.h" -#include "nfsv2.h" +#include "udp.h" + +#include "ip.h" +#ifdef INET6 +#include "ip6.h" +#endif +#include "ipproto.h" + +#include "nameser.h" +#include "nfs.h" #include "bootp.h" struct rtcphdr { - u_short rh_flags; /* T:2 P:1 CNT:5 PT:8 */ - u_short rh_len; /* length of message (in words) */ - u_int rh_ssrc; /* synchronization src id */ + u_int16_t rh_flags; /* T:2 P:1 CNT:5 PT:8 */ + u_int16_t rh_len; /* length of message (in words) */ + u_int32_t rh_ssrc; /* synchronization src id */ }; typedef struct { - u_int upper; /* more significant 32 bits */ - u_int lower; /* less significant 32 bits */ + u_int32_t upper; /* more significant 32 bits */ + u_int32_t lower; /* less significant 32 bits */ } ntp64; /* @@ -78,9 +73,9 @@ typedef struct { */ struct rtcp_sr { ntp64 sr_ntp; /* 64-bit ntp timestamp */ - u_int sr_ts; /* reference media timestamp */ - u_int sr_np; /* no. packets sent */ - u_int sr_nb; /* no. bytes sent */ + u_int32_t sr_ts; /* reference media timestamp */ + u_int32_t sr_np; /* no. packets sent */ + u_int32_t sr_nb; /* no. bytes sent */ }; /* @@ -88,12 +83,12 @@ struct rtcp_sr { * Time stamps are middle 32-bits of ntp timestamp. */ struct rtcp_rr { - u_int rr_srcid; /* sender being reported */ - u_int rr_nl; /* no. packets lost */ - u_int rr_ls; /* extended last seq number received */ - u_int rr_dv; /* jitter (delay variance) */ - u_int rr_lsr; /* orig. ts from last rr from this src */ - u_int rr_dlsr; /* time from recpt of last rr to xmit time */ + u_int32_t rr_srcid; /* sender being reported */ + u_int32_t rr_nl; /* no. packets lost */ + u_int32_t rr_ls; /* extended last seq number received */ + u_int32_t rr_dv; /* jitter (delay variance) */ + u_int32_t rr_lsr; /* orig. ts from last rr from this src */ + u_int32_t rr_dlsr; /* time from recpt of last rr to xmit time */ }; /*XXX*/ @@ -112,21 +107,21 @@ struct rtcp_rr { #define RTCP_PT_APP 204 static void -vat_print(const void *hdr, u_int len, register const struct udphdr *up) +vat_print(const void *hdr, register const struct udphdr *up) { /* vat/vt audio */ - u_int ts = *(u_short *)hdr; + u_int ts = *(u_int16_t *)hdr; if ((ts & 0xf060) != 0) { /* probably vt */ - (void)printf(" udp/vt %u %d / %d", - (u_int32_t)(ntohs(up->uh_ulen) - sizeof(*up)), + (void)printf("udp/vt %u %d / %d", + (u_int32_t)(EXTRACT_16BITS(&up->uh_ulen) - sizeof(*up)), ts & 0x3ff, ts >> 10); } else { /* probably vat */ - u_int i0 = ntohl(((u_int *)hdr)[0]); - u_int i1 = ntohl(((u_int *)hdr)[1]); - printf(" udp/vat %u c%d %u%s", - (u_int32_t)(ntohs(up->uh_ulen) - sizeof(*up) - 8), + u_int32_t i0 = EXTRACT_32BITS(&((u_int *)hdr)[0]); + u_int32_t i1 = EXTRACT_32BITS(&((u_int *)hdr)[1]); + printf("udp/vat %u c%d %u%s", + (u_int32_t)(EXTRACT_16BITS(&up->uh_ulen) - sizeof(*up) - 8), i0 & 0xffff, i1, i0 & 0x800000? "*" : ""); /* audio format */ @@ -143,9 +138,9 @@ rtp_print(const void *hdr, u_int len, register const struct udphdr *up) /* rtp v1 or v2 */ u_int *ip = (u_int *)hdr; u_int hasopt, hasext, contype, hasmarker; - u_int i0 = ntohl(((u_int *)hdr)[0]); - u_int i1 = ntohl(((u_int *)hdr)[1]); - u_int dlen = ntohs(up->uh_ulen) - sizeof(*up) - 8; + u_int32_t i0 = EXTRACT_32BITS(&((u_int *)hdr)[0]); + u_int32_t i1 = EXTRACT_32BITS(&((u_int *)hdr)[1]); + u_int dlen = EXTRACT_16BITS(&up->uh_ulen) - sizeof(*up) - 8; const char * ptype; ip += 2; @@ -169,7 +164,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, @@ -178,7 +173,7 @@ rtp_print(const void *hdr, u_int len, register const struct udphdr *up) i0 & 0xffff, i1); if (vflag) { - printf(" %u", i1); + printf(" %u", EXTRACT_32BITS(&((u_int *)hdr)[2])); if (hasopt) { u_int i2, optlen; do { @@ -215,15 +210,15 @@ rtcp_print(const u_char *hdr, const u_char *ep) struct rtcp_sr *sr; struct rtcphdr *rh = (struct rtcphdr *)hdr; u_int len; - u_short flags; + u_int16_t flags; int cnt; double ts, dts; if ((u_char *)(rh + 1) > ep) { printf(" [|rtcp]"); return (ep); } - len = (ntohs(rh->rh_len) + 1) * 4; - flags = ntohs(rh->rh_flags); + len = (EXTRACT_16BITS(&rh->rh_len) + 1) * 4; + flags = EXTRACT_16BITS(&rh->rh_flags); cnt = (flags >> 8) & 0x1f; switch (flags & 0xff) { case RTCP_PT_SR: @@ -232,16 +227,16 @@ rtcp_print(const u_char *hdr, const u_char *ep) if (len != cnt * sizeof(*rr) + sizeof(*sr) + sizeof(*rh)) printf(" [%d]", len); if (vflag) - printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc)); + printf(" %u", EXTRACT_32BITS(&rh->rh_ssrc)); if ((u_char *)(sr + 1) > ep) { printf(" [|rtcp]"); return (ep); } - ts = (double)((u_int32_t)ntohl(sr->sr_ntp.upper)) + - ((double)((u_int32_t)ntohl(sr->sr_ntp.lower)) / + ts = (double)(EXTRACT_32BITS(&sr->sr_ntp.upper)) + + ((double)(EXTRACT_32BITS(&sr->sr_ntp.lower)) / 4294967296.0); - printf(" @%.2f %u %up %ub", ts, (u_int32_t)ntohl(sr->sr_ts), - (u_int32_t)ntohl(sr->sr_np), (u_int32_t)ntohl(sr->sr_nb)); + printf(" @%.2f %u %up %ub", ts, EXTRACT_32BITS(&sr->sr_ts), + EXTRACT_32BITS(&sr->sr_np), EXTRACT_32BITS(&sr->sr_nb)); rr = (struct rtcp_rr *)(sr + 1); break; case RTCP_PT_RR: @@ -250,18 +245,18 @@ rtcp_print(const u_char *hdr, const u_char *ep) printf(" [%d]", len); rr = (struct rtcp_rr *)(rh + 1); if (vflag) - printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc)); + printf(" %u", EXTRACT_32BITS(&rh->rh_ssrc)); break; case RTCP_PT_SDES: printf(" sdes %d", len); if (vflag) - printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc)); + printf(" %u", EXTRACT_32BITS(&rh->rh_ssrc)); cnt = 0; break; case RTCP_PT_BYE: printf(" bye %d", len); if (vflag) - printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc)); + printf(" %u", EXTRACT_32BITS(&rh->rh_ssrc)); cnt = 0; break; default: @@ -277,41 +272,158 @@ rtcp_print(const u_char *hdr, const u_char *ep) return (ep); } if (vflag) - printf(" %u", (u_int32_t)ntohl(rr->rr_srcid)); - ts = (double)((u_int32_t)ntohl(rr->rr_lsr)) / 65536.; - dts = (double)((u_int32_t)ntohl(rr->rr_dlsr)) / 65536.; + printf(" %u", EXTRACT_32BITS(&rr->rr_srcid)); + ts = (double)(EXTRACT_32BITS(&rr->rr_lsr)) / 65536.; + dts = (double)(EXTRACT_32BITS(&rr->rr_dlsr)) / 65536.; printf(" %ul %us %uj @%.2f+%.2f", - (u_int32_t)ntohl(rr->rr_nl) & 0x00ffffff, - (u_int32_t)ntohl(rr->rr_ls), - (u_int32_t)ntohl(rr->rr_dv), ts, dts); + EXTRACT_32BITS(&rr->rr_nl) & 0x00ffffff, + EXTRACT_32BITS(&rr->rr_ls), + EXTRACT_32BITS(&rr->rr_dv), ts, dts); } return (hdr + len); } -/* XXX probably should use getservbyname() and cache answers */ -#define TFTP_PORT 69 /*XXX*/ -#define KERBEROS_PORT 88 /*XXX*/ -#define SUNRPC_PORT 111 /*XXX*/ -#define SNMP_PORT 161 /*XXX*/ -#define NTP_PORT 123 /*XXX*/ -#define SNMPTRAP_PORT 162 /*XXX*/ -#define ISAKMP_PORT 500 /*XXX*/ -#define RIP_PORT 520 /*XXX*/ -#define KERBEROS_SEC_PORT 750 /*XXX*/ -#define L2TP_PORT 1701 /*XXX*/ +static int udp_cksum(register const struct ip *ip, + register const struct udphdr *up, + register u_int len) +{ + union phu { + struct phdr { + u_int32_t src; + u_int32_t dst; + u_char mbz; + u_char proto; + u_int16_t len; + } ph; + u_int16_t pa[6]; + } phu; + register const u_int16_t *sp; + + /* pseudo-header.. */ + phu.ph.len = htons((u_int16_t)len); + phu.ph.mbz = 0; + phu.ph.proto = IPPROTO_UDP; + memcpy(&phu.ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t)); + if (IP_HL(ip) == 5) + memcpy(&phu.ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t)); + else + phu.ph.dst = ip_finddst(ip); + + sp = &phu.pa[0]; + return in_cksum((u_short *)up, len, + sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5]); +} #ifdef INET6 -#define RIPNG_PORT 521 /*XXX*/ +static int udp6_cksum(const struct ip6_hdr *ip6, const struct udphdr *up, + u_int len) +{ + size_t i; + register const u_int16_t *sp; + u_int32_t sum; + union { + struct { + struct in6_addr ph_src; + struct in6_addr ph_dst; + u_int32_t ph_len; + u_int8_t ph_zero[3]; + u_int8_t ph_nxt; + } ph; + u_int16_t pa[20]; + } phu; + + /* pseudo-header */ + memset(&phu, 0, sizeof(phu)); + phu.ph.ph_src = ip6->ip6_src; + phu.ph.ph_dst = ip6->ip6_dst; + phu.ph.ph_len = htonl(len); + phu.ph.ph_nxt = IPPROTO_UDP; + + sum = 0; + for (i = 0; i < sizeof(phu.pa) / sizeof(phu.pa[0]); i++) + sum += phu.pa[i]; + + sp = (const u_int16_t *)up; + + for (i = 0; i < (len & ~1); i += 2) + sum += *sp++; + + if (len & 1) + sum += htons((*(const u_int8_t *)sp) << 8); + + while (sum > 0xffff) + sum = (sum & 0xffff) + (sum >> 16); + sum = ~sum & 0xffff; + + return (sum); +} #endif +static void +udpipaddr_print(const struct ip *ip, int sport, int dport) +{ +#ifdef INET6 + const struct ip6_hdr *ip6; + + if (IP_V(ip) == 6) + ip6 = (const struct ip6_hdr *)ip; + else + ip6 = NULL; + + if (ip6) { + if (ip6->ip6_nxt == IPPROTO_UDP) { + if (sport == -1) { + (void)printf("%s > %s: ", + ip6addr_string(&ip6->ip6_src), + ip6addr_string(&ip6->ip6_dst)); + } else { + (void)printf("%s.%s > %s.%s: ", + ip6addr_string(&ip6->ip6_src), + udpport_string(sport), + ip6addr_string(&ip6->ip6_dst), + udpport_string(dport)); + } + } else { + if (sport != -1) { + (void)printf("%s > %s: ", + udpport_string(sport), + udpport_string(dport)); + } + } + } else +#endif /*INET6*/ + { + if (ip->ip_p == IPPROTO_UDP) { + if (sport == -1) { + (void)printf("%s > %s: ", + ipaddr_string(&ip->ip_src), + ipaddr_string(&ip->ip_dst)); + } else { + (void)printf("%s.%s > %s.%s: ", + ipaddr_string(&ip->ip_src), + udpport_string(sport), + ipaddr_string(&ip->ip_dst), + udpport_string(dport)); + } + } else { + if (sport != -1) { + (void)printf("%s > %s: ", + udpport_string(sport), + udpport_string(dport)); + } + } + } +} + void -udp_print(register const u_char *bp, u_int length, register const u_char *bp2) +udp_print(register const u_char *bp, u_int length, + register const u_char *bp2, int fragmented) { register const struct udphdr *up; register const struct ip *ip; register const u_char *cp; register const u_char *ep = bp + length; - u_short sport, dport, ulen; + u_int16_t sport, dport, ulen; #ifdef INET6 register const struct ip6_hdr *ip6; #endif @@ -321,25 +433,40 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) up = (struct udphdr *)bp; ip = (struct ip *)bp2; #ifdef INET6 - if (ip->ip_v == 6) + if (IP_V(ip) == 6) ip6 = (struct ip6_hdr *)bp2; else ip6 = NULL; #endif /*INET6*/ cp = (u_char *)(up + 1); - if (cp > snapend) { - printf("[|udp]"); + if (!TTEST(up->uh_dport)) { + udpipaddr_print(ip, -1, -1); + (void)printf("[|udp]"); return; } + + sport = EXTRACT_16BITS(&up->uh_sport); + dport = EXTRACT_16BITS(&up->uh_dport); + if (length < sizeof(struct udphdr)) { - (void)printf(" truncated-udp %d", length); + udpipaddr_print(ip, sport, dport); + (void)printf("truncated-udp %d", length); return; } length -= sizeof(struct udphdr); - sport = ntohs(up->uh_sport); - dport = ntohs(up->uh_dport); - ulen = ntohs(up->uh_ulen); + if (cp > snapend) { + udpipaddr_print(ip, sport, dport); + (void)printf("[|udp]"); + return; + } + + ulen = EXTRACT_16BITS(&up->uh_ulen); + if (ulen < 8) { + udpipaddr_print(ip, sport, dport); + (void)printf("truncated-udplength %d", ulen); + return; + } if (packettype) { register struct rpc_msg *rp; enum msg_type direction; @@ -347,26 +474,18 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) switch (packettype) { case PT_VAT: - (void)printf("%s.%s > %s.%s:", - ipaddr_string(&ip->ip_src), - udpport_string(sport), - ipaddr_string(&ip->ip_dst), - udpport_string(dport)); - vat_print((void *)(up + 1), length, up); + udpipaddr_print(ip, sport, dport); + vat_print((void *)(up + 1), up); break; case PT_WB: - (void)printf("%s.%s > %s.%s:", - ipaddr_string(&ip->ip_src), - udpport_string(sport), - ipaddr_string(&ip->ip_dst), - udpport_string(dport)); + udpipaddr_print(ip, sport, dport); wb_print((void *)(up + 1), length); break; case PT_RPC: rp = (struct rpc_msg *)(up + 1); - direction = (enum msg_type)ntohl(rp->rm_direction); + direction = (enum msg_type)EXTRACT_32BITS(&rp->rm_direction); if (direction == CALL) sunrpcrequest_print((u_char *)rp, length, (u_char *)ip); @@ -376,23 +495,40 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) break; case PT_RTP: - (void)printf("%s.%s > %s.%s:", - ipaddr_string(&ip->ip_src), - udpport_string(sport), - ipaddr_string(&ip->ip_dst), - udpport_string(dport)); + udpipaddr_print(ip, sport, dport); rtp_print((void *)(up + 1), length, up); break; case PT_RTCP: - (void)printf("%s.%s > %s.%s:", - ipaddr_string(&ip->ip_src), - udpport_string(sport), - ipaddr_string(&ip->ip_dst), - udpport_string(dport)); + udpipaddr_print(ip, sport, dport); while (cp < ep) cp = rtcp_print(cp, ep); break; + + case PT_SNMP: + udpipaddr_print(ip, sport, dport); + snmp_print((const u_char *)(up + 1), length); + break; + + case PT_CNFP: + udpipaddr_print(ip, sport, dport); + cnfp_print(cp, (const u_char *)ip); + break; + + case PT_TFTP: + udpipaddr_print(ip, sport, dport); + tftp_print(cp, length); + break; + + case PT_AODV: + udpipaddr_print(ip, sport, dport); + aodv_print((const u_char *)(up + 1), length, +#ifdef INET6 + ip6 != NULL); +#else + FALSE); +#endif + break; } return; } @@ -403,7 +539,7 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) rp = (struct rpc_msg *)(up + 1); if (TTEST(rp->rm_direction)) { - direction = (enum msg_type)ntohl(rp->rm_direction); + direction = (enum msg_type)EXTRACT_32BITS(&rp->rm_direction); if (dport == NFS_PORT && direction == CALL) { nfsreq_print((u_char *)rp, length, (u_char *)ip); @@ -426,39 +562,34 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) (atalk_port(sport) || atalk_port(dport))) { if (vflag) fputs("kip ", stdout); - atalk_print(cp, length); + llap_print(cp, 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 (bp == (u_char *)(ip6 + 1)) { - (void)printf("%s.%s > %s.%s: ", - ip6addr_string(&ip6->ip6_src), - udpport_string(sport), - ip6addr_string(&ip6->ip6_dst), - udpport_string(dport)); - } else { - (void)printf("%s > %s: ", - udpport_string(sport), udpport_string(dport)); + udpipaddr_print(ip, sport, dport); + + if (IP_V(ip) == 4 && vflag && !fragmented) { + int sum = up->uh_sum; + if (sum == 0) { + (void)printf("[no cksum] "); + } else if (TTEST2(cp[0], length)) { + sum = udp_cksum(ip, up, length + sizeof(struct udphdr)); + if (sum != 0) + (void)printf("[bad udp cksum %x!] ", sum); + else + (void)printf("[udp sum ok] "); } - } else -#endif /*INET6*/ - { - if (bp == (u_char *)(ip + 1)) { - (void)printf("%s.%s > %s.%s: ", - ipaddr_string(&ip->ip_src), - udpport_string(sport), - ipaddr_string(&ip->ip_dst), - udpport_string(dport)); - } else { - (void)printf("%s > %s: ", - udpport_string(sport), udpport_string(dport)); + } +#ifdef INET6 + if (IP_V(ip) == 6 && ip6->ip6_plen && vflag && !fragmented) { + int sum = up->uh_sum; + /* for IPv6, UDP checksum is mandatory */ + if (TTEST2(cp[0], length)) { + sum = udp6_cksum(ip6, up, length + sizeof(struct udphdr)); + if (sum != 0) + (void)printf("[bad udp cksum %x!] ", sum); + else + (void)printf("[udp sum ok] "); } } #endif @@ -466,39 +597,90 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) if (!qflag) { #define ISPORT(p) (dport == (p) || sport == (p)) if (ISPORT(NAMESERVER_PORT)) - ns_print((const u_char *)(up + 1), length); + ns_print((const u_char *)(up + 1), length, 0); + else if (ISPORT(MULTICASTDNS_PORT)) + ns_print((const u_char *)(up + 1), length, 1); + else if (ISPORT(TIMED_PORT)) + timed_print((const u_char *)(up + 1)); else if (ISPORT(TFTP_PORT)) tftp_print((const u_char *)(up + 1), length); else if (ISPORT(IPPORT_BOOTPC) || ISPORT(IPPORT_BOOTPS)) - bootp_print((const u_char *)(up + 1), length, - sport, dport); + bootp_print((const u_char *)(up + 1), length); else if (ISPORT(RIP_PORT)) rip_print((const u_char *)(up + 1), length); + else if (ISPORT(AODV_PORT)) + aodv_print((const u_char *)(up + 1), length, +#ifdef INET6 + ip6 != NULL); +#else + FALSE); +#endif else if (ISPORT(ISAKMP_PORT)) isakmp_print((const u_char *)(up + 1), length, bp2); +#if 1 /*???*/ + else if (ISPORT(ISAKMP_PORT_USER1) || ISPORT(ISAKMP_PORT_USER2)) + isakmp_print((const u_char *)(up + 1), length, bp2); +#endif else if (ISPORT(SNMP_PORT) || ISPORT(SNMPTRAP_PORT)) snmp_print((const u_char *)(up + 1), length); else if (ISPORT(NTP_PORT)) ntp_print((const u_char *)(up + 1), length); else if (ISPORT(KERBEROS_PORT) || ISPORT(KERBEROS_SEC_PORT)) - krb_print((const void *)(up + 1), length); + krb_print((const void *)(up + 1)); else if (ISPORT(L2TP_PORT)) l2tp_print((const u_char *)(up + 1), length); +#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)) + nbt_udp138_print((const u_char *)(up + 1), length); +#endif else if (dport == 3456) - vat_print((const void *)(up + 1), length, up); + vat_print((const void *)(up + 1), 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 + */ + else if ((sport >= RX_PORT_LOW && sport <= RX_PORT_HIGH) || + (dport >= RX_PORT_LOW && dport <= RX_PORT_HIGH)) + rx_print((const void *)(up + 1), length, sport, dport, + (u_char *) ip); #ifdef INET6 else if (ISPORT(RIPNG_PORT)) ripng_print((const u_char *)(up + 1), length); + else if (ISPORT(DHCP6_SERV_PORT) || ISPORT(DHCP6_CLI_PORT)) { + dhcp6_print((const u_char *)(up + 1), length); + } #endif /*INET6*/ /* * Kludge in test for whiteboard packets. */ else if (dport == 4567) wb_print((const void *)(up + 1), 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); + 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 if (ISPORT(LDP_PORT)) + ldp_print((const u_char *)(up + 1), length); + else if (ISPORT(MPLS_LSP_PING_PORT)) + mpls_lsp_ping_print((const u_char *)(up + 1), length); + else if (dport == BFD_CONTROL_PORT || + dport == BFD_ECHO_PORT ) + bfd_print((const u_char *)(up+1), length, dport); else - (void)printf(" udp %u", + (void)printf("UDP, length: %u", (u_int32_t)(ulen - sizeof(*up))); #undef ISPORT } else - (void)printf(" udp %u", (u_int32_t)(ulen - sizeof(*up))); + (void)printf("UDP, length: %u", (u_int32_t)(ulen - sizeof(*up))); } diff --git a/kame/kame/tcpdump/print-vjc.c b/kame/kame/tcpdump/print-vjc.c index 31ee13fa6a..f1877f2139 100644 --- a/kame/kame/tcpdump/print-vjc.c +++ b/kame/kame/tcpdump/print-vjc.c @@ -19,50 +19,70 @@ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#if defined(__bsdi__) - -#ifndef lint -static const char rcsid[] = - "@(#) print-vjc.c,v 1.1.2.2 1998/08/31 05:44:21 onoe Exp (LBL)"; +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include -#include -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-vjc.c,v 1.11.2.3 2003/11/19 01:09:12 guy Exp $ (LBL)"; #endif -#include -#include -#include -#include -#include +#include -#include -#include #include #include -#if defined(__NetBSD__) -#include -#include -#endif - -#if defined(__bsdi__) || defined(__NetBSD__) -#include -#include -#endif - #include "interface.h" #include "addrtoname.h" +#include "slcompress.h" +#include "ppp.h" + +/* + * XXX - for BSD/OS PPP, what packets get supplied with a PPP header type + * of PPP_VJC and what packets get supplied with a PPP header type of + * PPP_VJNC? PPP_VJNC is for "UNCOMPRESSED_TCP" packets, and PPP_VJC + * is for COMPRESSED_TCP packets (PPP_IP is used for TYPE_IP packets). + * + * RFC 1144 implies that, on the wire, the packet type is *not* needed + * for PPP, as different PPP protocol types can be used; it only needs + * to be put on the wire for SLIP. + * + * It also indicates that, for compressed SLIP: + * + * If the COMPRESSED_TCP bit is set in the first byte, it's + * a COMPRESSED_TCP packet; that byte is the change byte, and + * the COMPRESSED_TCP bit, 0x80, isn't used in the change byte. + * + * If the upper 4 bits of the first byte are 7, it's an + * UNCOMPRESSED_TCP packet; that byte is the first byte of + * the UNCOMPRESSED_TCP modified IP header, with a connection + * number in the protocol field, and with the version field + * being 7, not 4. + * + * Otherwise, the packet is an IPv4 packet (where the upper 4 bits + * of the packet are 4). + * + * So this routine looks as if it's sort-of intended to handle + * compressed SLIP, although it doesn't handle UNCOMPRESSED_TCP + * correctly for that (it doesn't fix the version number and doesn't + * do anything to the protocol field), and doesn't check for COMPRESSED_TCP + * packets correctly for that (you only check the first bit - see + * B.1 in RFC 1144). + * + * But it's called for BSD/OS PPP, not SLIP - perhaps BSD/OS does weird + * things with the headers? + * + * Without a BSD/OS VJC-compressed PPP trace, or knowledge of what the + * BSD/OS VJC code does, we can't say what's the case. + * + * We therefore leave "proto" - which is the PPP protocol type - in place, + * *not* marked as unused, for now, so that GCC warnings about the + * unused argument remind us that we should fix this some day. + */ int -vjc_print(register const char *bp, register u_int length, u_short proto) +vjc_print(register const char *bp, u_short proto) { int i; @@ -97,4 +117,3 @@ vjc_print(register const char *bp, register u_int length, u_short proto) return -1; } } -#endif /* defined(__bsdi__) || defined(__NetBSD__) */ diff --git a/kame/kame/tcpdump/print-vrrp.c b/kame/kame/tcpdump/print-vrrp.c new file mode 100644 index 0000000000..f615dfd027 --- /dev/null +++ b/kame/kame/tcpdump/print-vrrp.c @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2000 William C. Fenner. + * All rights reserved. + * + * Kevin Steves July 2000 + * Modified to: + * - print version, type string and packet length + * - print IP address count if > 1 (-v) + * - verify checksum (-v) + * - print authentication string (-v) + * + * 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[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-vrrp.c,v 1.7.2.2 2003/11/16 08:51:55 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include + +#include "interface.h" +#include "extract.h" +#include "addrtoname.h" + +/* + * RFC 2338: + * 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| Type | Virtual Rtr ID| Priority | Count IP Addrs| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Auth Type | Adver Int | Checksum | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | IP Address (1) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | . | + * | . | + * | . | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | IP Address (n) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Authentication Data (1) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | 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; + const char *type_s; + + TCHECK(bp[0]); + version = (bp[0] & 0xf0) >> 4; + type = bp[0] & 0x0f; + type_s = tok2str(type2str, "unknown type (%u)", type); + printf("VRRPv%u, %s", version, type_s); + if (ttl != 255) + printf(", (ttl %u)", ttl); + if (version != 2 || type != VRRP_TYPE_ADVERTISEMENT) + return; + TCHECK(bp[2]); + printf(", vrid %u, prio %u", bp[1], bp[2]); + TCHECK(bp[5]); + auth_type = bp[4]; + printf(", authtype %s", tok2str(auth2str, NULL, auth_type)); + printf(", intvl %us, length %u", bp[5],len); + if (vflag) { + int naddrs = bp[3]; + int i; + char c; + + if (TTEST2(bp[0], len) && in_cksum((const u_short*)bp, len, 0)) + printf(", (bad vrrp cksum %x)", + EXTRACT_16BITS(&bp[6])); + printf(", addrs"); + if (naddrs > 1) + printf("(%d)", naddrs); + printf(":"); + c = ' '; + bp += 8; + for (i = 0; i < naddrs; i++) { + TCHECK(bp[3]); + printf("%c%s", c, ipaddr_string(bp)); + c = ','; + bp += 4; + } + if (auth_type == VRRP_AUTH_SIMPLE) { /* simple text password */ + TCHECK(bp[7]); + printf(" auth \""); + fn_printn(bp, 8, NULL); + printf("\""); + } + } + return; +trunc: + printf("[|vrrp]"); +} diff --git a/kame/kame/tcpdump/print-wb.c b/kame/kame/tcpdump/print-wb.c index cd60848e37..678e325b2d 100644 --- a/kame/kame/tcpdump/print-wb.c +++ b/kame/kame/tcpdump/print-wb.c @@ -20,21 +20,24 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: print-wb.c,v 1.24 96/12/31 21:27:44 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-wb.c,v 1.30.2.3 2004/03/24 04:06:52 guy Exp $ (LBL)"; #endif -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include +#include #include #include "interface.h" #include "addrtoname.h" +#include "extract.h" /* XXX need to add byte-swapping macros! */ +/* XXX - you mean like the ones in "extract.h"? */ /* * Largest packet size. Everything should fit within this space. @@ -50,7 +53,7 @@ static const char rcsid[] = #define DOP_ROUNDUP(x) ((((int)(x)) + (DOP_ALIGN - 1)) & ~(DOP_ALIGN - 1)) #define DOP_NEXT(d)\ ((struct dophdr *)((u_char *)(d) + \ - DOP_ROUNDUP(ntohs((d)->dh_len) + sizeof(*(d))))) + DOP_ROUNDUP(EXTRACT_16BITS(&(d)->dh_len) + sizeof(*(d))))) /* * Format of the whiteboard packet header. @@ -59,7 +62,7 @@ static const char rcsid[] = struct pkt_hdr { u_int32_t ph_src; /* site id of source */ u_int32_t ph_ts; /* time stamp (for skew computation) */ - u_short ph_version; /* version number */ + u_int16_t ph_version; /* version number */ u_char ph_type; /* message type */ u_char ph_flags; /* message flags */ }; @@ -73,6 +76,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 */ @@ -84,7 +91,7 @@ struct PageID { struct dophdr { u_int32_t dh_ts; /* sender's timestamp */ - u_short dh_len; /* body length */ + u_int16_t dh_len; /* body length */ u_char dh_flags; u_char dh_type; /* body type */ /* body follows */ @@ -145,8 +152,8 @@ struct id_off { struct pgstate { u_int32_t slot; struct PageID page; - u_short nid; - u_short rsvd; + u_int16_t nid; + u_int16_t rsvd; /* seqptr's */ }; @@ -187,14 +194,14 @@ wb_id(const struct pkt_id *id, u_int len) len -= sizeof(*id); printf(" %u/%s:%u (max %u/%s:%u) ", - (u_int32_t)ntohl(id->pi_ps.slot), + EXTRACT_32BITS(&id->pi_ps.slot), ipaddr_string(&id->pi_ps.page.p_sid), - (u_int32_t)ntohl(id->pi_ps.page.p_uid), - (u_int32_t)ntohl(id->pi_mslot), + EXTRACT_32BITS(&id->pi_ps.page.p_uid), + EXTRACT_32BITS(&id->pi_mslot), ipaddr_string(&id->pi_mpage.p_sid), - (u_int32_t)ntohl(id->pi_mpage.p_uid)); + EXTRACT_32BITS(&id->pi_mpage.p_uid)); - nid = ntohs(id->pi_ps.nid); + nid = EXTRACT_16BITS(&id->pi_ps.nid); len -= sizeof(*io) * nid; io = (struct id_off *)(id + 1); cp = (char *)(io + nid); @@ -205,9 +212,9 @@ wb_id(const struct pkt_id *id, u_int len) } c = '<'; - for (i = 0; i < nid && (u_char *)io < snapend; ++io, ++i) { + for (i = 0; i < nid && (u_char *)(io + 1) <= snapend; ++io, ++i) { printf("%c%s:%u", - c, ipaddr_string(&io->id), (u_int32_t)ntohl(io->off)); + c, ipaddr_string(&io->id), EXTRACT_32BITS(&io->off)); c = ','; } if (i >= nid) { @@ -227,9 +234,9 @@ wb_rreq(const struct pkt_rreq *rreq, u_int len) printf(" please repair %s %s:%u<%u:%u>", ipaddr_string(&rreq->pr_id), ipaddr_string(&rreq->pr_page.p_sid), - (u_int32_t)ntohl(rreq->pr_page.p_uid), - (u_int32_t)ntohl(rreq->pr_sseq), - (u_int32_t)ntohl(rreq->pr_eseq)); + EXTRACT_32BITS(&rreq->pr_page.p_uid), + EXTRACT_32BITS(&rreq->pr_sseq), + EXTRACT_32BITS(&rreq->pr_eseq)); return (0); } @@ -241,9 +248,9 @@ wb_preq(const struct pkt_preq *preq, u_int len) return (-1); printf(" need %u/%s:%u", - (u_int32_t)ntohl(preq->pp_low), + EXTRACT_32BITS(&preq->pp_low), ipaddr_string(&preq->pp_page.p_sid), - (u_int32_t)ntohl(preq->pp_page.p_uid)); + EXTRACT_32BITS(&preq->pp_page.p_uid)); return (0); } @@ -258,20 +265,20 @@ wb_prep(const struct pkt_prep *prep, u_int len) if (len < sizeof(*prep)) { return (-1); } - n = ntohl(prep->pp_n); + n = EXTRACT_32BITS(&prep->pp_n); ps = (const struct pgstate *)(prep + 1); - while (--n >= 0 && (u_char *)ps < ep) { + while (--n >= 0 && (u_char *)(ps + 1) <= ep) { const struct id_off *io, *ie; char c = '<'; printf(" %u/%s:%u", - (u_int32_t)ntohl(ps->slot), + EXTRACT_32BITS(&ps->slot), ipaddr_string(&ps->page.p_sid), - (u_int32_t)ntohl(ps->page.p_uid)); + EXTRACT_32BITS(&ps->page.p_uid)); io = (struct id_off *)(ps + 1); - for (ie = io + ps->nid; io < ie && (u_char *)io < ep; ++io) { + for (ie = io + ps->nid; io < ie && (u_char *)(io + 1) <= ep; ++io) { printf("%c%s:%u", c, ipaddr_string(&io->id), - (u_int32_t)ntohl(io->off)); + EXTRACT_32BITS(&io->off)); c = ','; } printf(">"); @@ -281,7 +288,7 @@ wb_prep(const struct pkt_prep *prep, u_int len) } -char *dopstr[] = { +const char *dopstr[] = { "dop-0!", "dop-1!", "RECT", @@ -312,7 +319,7 @@ wb_dops(const struct dophdr *dh, u_int32_t ss, u_int32_t es) else { printf(" %s", dopstr[t]); if (t == DT_SKIP || t == DT_HOLE) { - int ts = ntohl(dh->dh_ts); + u_int32_t ts = EXTRACT_32BITS(&dh->dh_ts); printf("%d", ts - ss + 1); if (ss > ts || ts > es) { printf("[|]"); @@ -345,13 +352,14 @@ wb_rrep(const struct pkt_rrep *rrep, u_int len) printf(" for %s %s:%u<%u:%u>", ipaddr_string(&rrep->pr_id), ipaddr_string(&dop->pd_page.p_sid), - (u_int32_t)ntohl(dop->pd_page.p_uid), - (u_int32_t)ntohl(dop->pd_sseq), - (u_int32_t)ntohl(dop->pd_eseq)); + EXTRACT_32BITS(&dop->pd_page.p_uid), + EXTRACT_32BITS(&dop->pd_sseq), + EXTRACT_32BITS(&dop->pd_eseq)); if (vflag) return (wb_dops((const struct dophdr *)(dop + 1), - ntohl(dop->pd_sseq), ntohl(dop->pd_eseq))); + EXTRACT_32BITS(&dop->pd_sseq), + EXTRACT_32BITS(&dop->pd_eseq))); return (0); } @@ -365,13 +373,14 @@ wb_drawop(const struct pkt_dop *dop, u_int len) printf(" %s:%u<%u:%u>", ipaddr_string(&dop->pd_page.p_sid), - (u_int32_t)ntohl(dop->pd_page.p_uid), - (u_int32_t)ntohl(dop->pd_sseq), - (u_int32_t)ntohl(dop->pd_eseq)); + EXTRACT_32BITS(&dop->pd_page.p_uid), + EXTRACT_32BITS(&dop->pd_sseq), + EXTRACT_32BITS(&dop->pd_eseq)); if (vflag) return (wb_dops((const struct dophdr *)(dop + 1), - ntohl(dop->pd_sseq), ntohl(dop->pd_eseq))); + EXTRACT_32BITS(&dop->pd_sseq), + EXTRACT_32BITS(&dop->pd_eseq))); return (0); } diff --git a/kame/kame/tcpdump/print-zephyr.c b/kame/kame/tcpdump/print-zephyr.c new file mode 100644 index 0000000000..186960cb0e --- /dev/null +++ b/kame/kame/tcpdump/print-zephyr.c @@ -0,0 +1,311 @@ +/* + * Decode and print Zephyr packets. + * + * Copyright (c) 2001 Nickolai Zeldovich + * 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[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/print-zephyr.c,v 1.6.2.2 2003/11/16 08:51:56 guy Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include + +#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; + const char *recipient; + char *format; + int cksum; + int multi; + char *multi_uid; + /* Other fields follow here.. */ +}; + +enum z_packet_type { + 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 +}; + +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, const 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((unsigned char)(*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/kame/kame/tcpdump/route6d.h b/kame/kame/tcpdump/route6d.h index 87a8544703..ee0033148c 100644 --- a/kame/kame/tcpdump/route6d.h +++ b/kame/kame/tcpdump/route6d.h @@ -1,5 +1,33 @@ /* - * $Header: /cvsroot/hydrangea-freebsd/kit/src/tcpdump/Attic/route6d.h,v 1.1.2.1 1998/05/10 15:38:08 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.5 2002/12/11 07:14:10 guy Exp $ */ #define RIP6_VERSION 1 @@ -8,16 +36,16 @@ #define RIP6_RESPONSE 2 struct netinfo6 { - struct in6_addr rip6_dest; - u_short rip6_tag; - u_char rip6_plen; - u_char rip6_metric; + struct in6_addr rip6_dest; + u_int16_t rip6_tag; + u_int8_t rip6_plen; + u_int8_t rip6_metric; }; struct rip6 { - u_char rip6_cmd; - u_char rip6_vers; - u_char rip6_res1[2]; + u_int8_t rip6_cmd; + u_int8_t rip6_vers; + u_int8_t rip6_res1[2]; union { struct netinfo6 ru6_nets[1]; char ru6_tracefile[1]; diff --git a/kame/kame/tcpdump/rx.h b/kame/kame/tcpdump/rx.h new file mode 100644 index 0000000000..1912e51ae3 --- /dev/null +++ b/kame/kame/tcpdump/rx.h @@ -0,0 +1,113 @@ +/* + * 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.8 2002/12/11 07:14:11 guy Exp $ + */ + +#define FS_RX_PORT 7000 +#define CB_RX_PORT 7001 +#define PROT_RX_PORT 7002 +#define VLDB_RX_PORT 7003 +#define KAUTH_RX_PORT 7004 +#define VOL_RX_PORT 7005 +#define ERROR_RX_PORT 7006 /* Doesn't seem to be used */ +#define BOS_RX_PORT 7007 + +#ifndef AFSNAMEMAX +#define AFSNAMEMAX 256 +#endif + +#ifndef AFSOPAQUEMAX +#define AFSOPAQUEMAX 1024 +#endif + +#define PRNAMEMAX 64 +#define VLNAMEMAX 65 +#define KANAMEMAX 64 +#define BOSNAMEMAX 256 + +#define PRSFS_READ 1 /* Read files */ +#define PRSFS_WRITE 2 /* Write files */ +#define PRSFS_INSERT 4 /* Insert files into a directory */ +#define PRSFS_LOOKUP 8 /* Lookup files into a directory */ +#define PRSFS_DELETE 16 /* Delete files */ +#define PRSFS_LOCK 32 /* Lock files */ +#define PRSFS_ADMINISTER 64 /* Change ACL's */ + +struct rx_header { + u_int32_t epoch; + u_int32_t cid; + u_int32_t callNumber; + u_int32_t seq; + u_int32_t serial; + u_int8_t type; +#define RX_PACKET_TYPE_DATA 1 +#define RX_PACKET_TYPE_ACK 2 +#define RX_PACKET_TYPE_BUSY 3 +#define RX_PACKET_TYPE_ABORT 4 +#define RX_PACKET_TYPE_ACKALL 5 +#define RX_PACKET_TYPE_CHALLENGE 6 +#define RX_PACKET_TYPE_RESPONSE 7 +#define RX_PACKET_TYPE_DEBUG 8 +#define RX_PACKET_TYPE_PARAMS 9 +#define RX_PACKET_TYPE_VERSION 13 + u_int8_t flags; +#define RX_CLIENT_INITIATED 1 +#define RX_REQUEST_ACK 2 +#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 */ + u_int16_t serviceId; /* header files indicate that the */ +}; /* serviceId is first, it's really */ + /* encoded _after_ the spare field */ + /* I wasted a day figuring that out! */ + +#define NUM_RX_FLAGS 7 + +#define RX_MAXACKS 255 + +struct rx_ackPacket { + u_int16_t bufferSpace; /* Number of packet buffers available */ + u_int16_t maxSkew; /* Max diff between ack'd packet and */ + /* highest packet received */ + u_int32_t firstPacket; /* The first packet in ack list */ + u_int32_t previousPacket; /* Previous packet recv'd (obsolete) */ + u_int32_t serial; /* # of packet that prompted the ack */ + u_int8_t reason; /* Reason for acknowledgement */ + u_int8_t nAcks; /* Number of acknowledgements */ + u_int8_t acks[RX_MAXACKS]; /* Up to RX_MAXACKS acknowledgements */ +}; + +/* + * Values for the acks array + */ + +#define RX_ACK_TYPE_NACK 0 /* Don't have this packet */ +#define RX_ACK_TYPE_ACK 1 /* I have this packet */ diff --git a/kame/kame/tcpdump/sctpConstants.h b/kame/kame/tcpdump/sctpConstants.h new file mode 100644 index 0000000000..f70226b624 --- /dev/null +++ b/kame/kame/tcpdump/sctpConstants.h @@ -0,0 +1,571 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/sctpConstants.h,v 1.4 2003/06/03 23:49:23 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 + +/* 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/kame/kame/tcpdump/sctpHeader.h b/kame/kame/tcpdump/sctpHeader.h new file mode 100644 index 0000000000..3b26094c1b --- /dev/null +++ b/kame/kame/tcpdump/sctpHeader.h @@ -0,0 +1,323 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/sctpHeader.h,v 1.6 2002/12/11 07:14:11 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 + +#ifdef __cplusplus +extern "C" { +#endif + +/* the sctp common header */ + +#ifdef TRU64 + #define _64BITS 1 +#endif + +struct sctpHeader{ + u_int16_t source; + u_int16_t destination; + u_int32_t verificationTag; + u_int32_t adler32; +}; + +/* various descriptor parsers */ + +struct sctpChunkDesc{ + u_int8_t chunkID; + u_int8_t chunkFlg; + u_int16_t chunkLength; +}; + +struct sctpParamDesc{ + u_int16_t paramType; + u_int16_t paramLength; +}; + + +struct sctpRelChunkDesc{ + struct sctpChunkDesc chk; + u_int32_t serialNumber; +}; + +struct sctpVendorSpecificParam { + struct sctpParamDesc p; /* type must be 0xfffe */ + u_int32_t vendorId; /* vendor ID from RFC 1700 */ + u_int16_t vendorSpecificType; + u_int16_t vendorSpecificLen; +}; + + +/* Structures for the control parts */ + + + +/* Sctp association init request/ack */ + +/* this is used for init ack, too */ +struct sctpInitiation{ + u_int32_t initTag; /* tag of mine */ + u_int32_t rcvWindowCredit; /* rwnd */ + u_int16_t NumPreopenStreams; /* OS */ + u_int16_t MaxInboundStreams; /* MIS */ + u_int32_t initialTSN; + /* optional param's follow in sctpParamDesc form */ +}; + +struct sctpV4IpAddress{ + struct sctpParamDesc p; /* type is set to SCTP_IPV4_PARAM_TYPE, len=10 */ + u_int32_t ipAddress; +}; + + +struct sctpV6IpAddress{ + struct sctpParamDesc p; /* type is set to SCTP_IPV6_PARAM_TYPE, len=22 */ + u_int8_t ipAddress[16]; +}; + +struct sctpDNSName{ + struct sctpParamDesc param; + u_int8_t name[1]; +}; + + +struct sctpCookiePreserve{ + struct sctpParamDesc p; /* type is set to SCTP_COOKIE_PRESERVE, len=8 */ + u_int32_t extraTime; +}; + + +struct sctpTimeStamp{ + u_int32_t ts_sec; + u_int32_t ts_usec; +}; + +/* wire structure of my cookie */ +struct cookieMessage{ + u_int32_t TieTag_curTag; /* copied from assoc if present */ + u_int32_t TieTag_hisTag; /* copied from assoc if present */ + int32_t 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_int32_t addressWhereISent[4]; /* I make this 4 ints so I get 128bits for future */ + int32_t addrtype; /* address type */ + u_int16_t locScope; /* V6 local scope flag */ + u_int16_t 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_int32_t highestConseqTSN; + u_int32_t updatedRwnd; + u_int16_t numberOfdesc; + u_int16_t numDupTsns; +}; + +struct sctpSelectiveFrag{ + u_int16_t fragmentStart; + u_int16_t fragmentEnd; +}; + + +struct sctpUnifiedSack{ + struct sctpChunkDesc uh; + struct sctpSelectiveAck sack; +}; + +/* for both RTT request/response the + * following is sent + */ + +struct sctpHBrequest { + u_int32_t time_value_1; + u_int32_t 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; + int8_t addrFmt[SCTP_ADDRMAX]; + u_int16_t 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; + u_int16_t causeCode; + u_int16_t causeLen; +}; + +/* For the graceful shutdown we must carry + * the tag (in common header) and the highest consequitive acking value + */ +struct sctpShutdown { + u_int32_t 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_int16_t cause; + u_int16_t causeLen; +}; + +struct sctpUnifiedOpError{ + struct sctpChunkDesc uh; + struct sctpOpErrorCause c; +}; + +struct sctpUnifiedStreamError{ + struct sctpHeader mh; + struct sctpChunkDesc uh; + struct sctpOpErrorCause c; + u_int16_t strmNum; + u_int16_t reserved; +}; + +struct staleCookieMsg{ + struct sctpHeader mh; + struct sctpChunkDesc uh; + struct sctpOpErrorCause c; + u_int32_t 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_int32_t TSN; + u_int16_t streamId; + u_int16_t sequence; + u_int32_t payloadtype; +}; + +struct sctpUnifiedDatagram{ + struct sctpChunkDesc uh; + struct sctpDataPart dp; +}; + +struct sctpECN_echo{ + struct sctpChunkDesc uh; + u_int32_t Lowest_TSN; +}; + + +struct sctpCWR{ + struct sctpChunkDesc uh; + u_int32_t TSN_reduced_at; +}; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/kame/kame/tcpdump/setsignal.c b/kame/kame/tcpdump/setsignal.c index 6f797ff83c..b7722648a0 100644 --- a/kame/kame/tcpdump/setsignal.c +++ b/kame/kame/tcpdump/setsignal.c @@ -20,21 +20,21 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: setsignal.c,v 1.4 97/06/15 13:20:29 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/setsignal.c,v 1.9.2.2 2003/11/16 08:51:56 guy Exp $ (LBL)"; #endif -#include - -#ifdef HAVE_MEMORY_H -#include +#ifdef HAVE_CONFIG_H +#include "config.h" #endif + +#include + #include #ifdef HAVE_SIGACTION #include #endif -#include "gnuc.h" #ifdef HAVE_OS_PROTO_H #include "os-proto.h" #endif @@ -42,15 +42,33 @@ static const char rcsid[] = #include "setsignal.h" /* - * An os independent signal() with BSD semantics, e.g. the signal - * catcher is restored following service of the signal. + * An OS-independent signal() with, whenever possible, partial BSD + * semantics, i.e. the signal handler is restored following service + * of the signal, but system calls are *not* restarted, so that if + * "pcap_breakloop()" is called in a signal handler in a live capture, + * the read/recvfrom/whatever in the live capture doesn't get restarted, + * it returns -1 and sets "errno" to EINTR, so we can break out of the + * live capture loop. * - * When sigset() is available, signal() has SYSV semantics and sigset() - * has BSD semantics and call interface. Unfortunately, Linux does not - * have sigset() so we use the more complicated sigaction() interface - * there. + * We use "sigaction()" if available. We don't specify that the signal + * should restart system calls, so that should always do what we want. * - * Did I mention that signals suck? + * Otherwise, if "sigset()" is available, it probably has BSD semantics + * while "signal()" has traditional semantics, so we use "sigset()"; it + * might cause system calls to be restarted for the signal, however. + * I don't know whether, in any systems where it did cause system calls to + * be restarted, there was a way to ask it not to do so; there may no + * longer be any interesting systems without "sigaction()", however, + * and, if there are, they might have "sigvec()" with SV_INTERRUPT + * (which I think first appeared in 4.3BSD). + * + * Otherwise, we use "signal()" - which means we might get traditional + * semantics, wherein system calls don't get restarted *but* the + * signal handler is reset to SIG_DFL and the signal is not blocked, + * so that a subsequent signal would kill the process immediately. + * + * Did I mention that signals suck? At least in POSIX-compliant systems + * they suck far less, as those systems have "sigaction()". */ RETSIGTYPE (*setsignal (int sig, RETSIGTYPE (*func)(int)))(int) @@ -60,9 +78,6 @@ RETSIGTYPE memset(&new, 0, sizeof(new)); new.sa_handler = func; -#ifdef SA_RESTART - new.sa_flags |= SA_RESTART; -#endif if (sigaction(sig, &new, &old) < 0) return (SIG_ERR); return (old.sa_handler); diff --git a/kame/kame/tcpdump/setsignal.h b/kame/kame/tcpdump/setsignal.h index 39b606597e..a7fb2a7481 100644 --- a/kame/kame/tcpdump/setsignal.h +++ b/kame/kame/tcpdump/setsignal.h @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: setsignal.h,v 1.2 97/06/13 13:10:44 leres Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/setsignal.h,v 1.2.1.1 1999/10/07 23:47:13 mcr Exp $ (LBL) */ #ifndef setsignal_h #define setsignal_h diff --git a/kame/kame/tcpdump/slcompress.h b/kame/kame/tcpdump/slcompress.h new file mode 100644 index 0000000000..d8a596cf52 --- /dev/null +++ b/kame/kame/tcpdump/slcompress.h @@ -0,0 +1,87 @@ +/* + * Definitions for tcp compression routines. + * + * @(#) $Header: /tcpdump/master/tcpdump/slcompress.h,v 1.2 2000/10/09 02:03:44 guy Exp $ (LBL) + * + * Copyright (c) 1989, 1990, 1992, 1993 Regents of the University of + * California. All rights reserved. + * + * 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 the University of California, Berkeley. The name of the + * University 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 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Van Jacobson (van@ee.lbl.gov), Dec 31, 1989: + * - Initial distribution. + */ + +/* + * Compressed packet format: + * + * The first octet contains the packet type (top 3 bits), TCP + * 'push' bit, and flags that indicate which of the 4 TCP sequence + * numbers have changed (bottom 5 bits). The next octet is a + * conversation number that associates a saved IP/TCP header with + * the compressed packet. The next two octets are the TCP checksum + * from the original datagram. The next 0 to 15 octets are + * sequence number changes, one change per bit set in the header + * (there may be no changes and there are two special cases where + * the receiver implicitly knows what changed -- see below). + * + * There are 5 numbers which can change (they are always inserted + * in the following order): TCP urgent pointer, window, + * acknowlegement, sequence number and IP ID. (The urgent pointer + * is different from the others in that its value is sent, not the + * change in value.) Since typical use of SLIP links is biased + * toward small packets (see comments on MTU/MSS below), changes + * use a variable length coding with one octet for numbers in the + * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the + * range 256 - 65535 or 0. (If the change in sequence number or + * ack is more than 65535, an uncompressed packet is sent.) + */ + +/* + * Packet types (must not conflict with IP protocol version) + * + * The top nibble of the first octet is the packet type. There are + * three possible types: IP (not proto TCP or tcp with one of the + * control flags set); uncompressed TCP (a normal IP/TCP packet but + * with the 8-bit protocol field replaced by an 8-bit connection id -- + * this type of packet syncs the sender & receiver); and compressed + * TCP (described above). + * + * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and + * is logically part of the 4-bit "changes" field that follows. Top + * three bits are actual packet type. For backward compatibility + * and in the interest of conserving bits, numbers are chosen so the + * IP protocol version number (4) which normally appears in this nibble + * means "IP packet". + */ + +/* packet types */ +#define TYPE_IP 0x40 +#define TYPE_UNCOMPRESSED_TCP 0x70 +#define TYPE_COMPRESSED_TCP 0x80 +#define TYPE_ERROR 0x00 + +/* Bits in first octet of compressed packet */ +#define NEW_C 0x40 /* flag bits for what changed in a packet */ +#define NEW_I 0x20 +#define NEW_S 0x08 +#define NEW_A 0x04 +#define NEW_W 0x02 +#define NEW_U 0x01 + +/* reserved, special-case values of above */ +#define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */ +#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */ +#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U) + +#define TCP_PUSH_BIT 0x10 diff --git a/kame/kame/tcpdump/slip.h b/kame/kame/tcpdump/slip.h new file mode 100644 index 0000000000..e64f3015ac --- /dev/null +++ b/kame/kame/tcpdump/slip.h @@ -0,0 +1,34 @@ +/* + * Definitions that user level programs might need to know to interact + * with serial line IP (slip) lines. + * + * @(#) $Header: /tcpdump/master/tcpdump/slip.h,v 1.1 2000/10/09 01:53:21 guy Exp $ + * + * Copyright (c) 1990 Regents of the University of California. + * All rights reserved. + * + * 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 the University of California, Berkeley. The name of the + * University 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 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +/* + * definitions of the pseudo- link-level header attached to slip + * packets grabbed by the packet filter (bpf) traffic monitor. + */ +#define SLIP_HDRLEN 16 + +#define SLX_DIR 0 +#define SLX_CHDR 1 +#define CHDR_LEN 15 + +#define SLIPDIR_IN 0 +#define SLIPDIR_OUT 1 diff --git a/kame/kame/tcpdump/sll.h b/kame/kame/tcpdump/sll.h new file mode 100644 index 0000000000..693f05efa4 --- /dev/null +++ b/kame/kame/tcpdump/sll.h @@ -0,0 +1,127 @@ +/*- + * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from the Stanford/CMU enet packet filter, + * (net/enet.c) distributed as part of 4.3BSD, and code contributed + * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence + * Berkeley Laboratory. + * + * 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. + * + * @(#) $Header: /tcpdump/master/tcpdump/sll.h,v 1.7 2002/12/11 07:14:11 guy Exp $ (LBL) + */ + +/* + * For captures on Linux cooked sockets, we construct a fake header + * that includes: + * + * a 2-byte "packet type" which is one of: + * + * LINUX_SLL_HOST packet was sent to us + * LINUX_SLL_BROADCAST packet was broadcast + * LINUX_SLL_MULTICAST packet was multicast + * LINUX_SLL_OTHERHOST packet was sent to somebody else + * LINUX_SLL_OUTGOING packet was sent *by* us; + * + * a 2-byte Ethernet protocol field; + * + * a 2-byte link-layer type; + * + * a 2-byte link-layer address length; + * + * an 8-byte source link-layer address, whose actual length is + * specified by the previous value. + * + * All fields except for the link-layer address are in network byte order. + * + * DO NOT change the layout of this structure, or change any of the + * LINUX_SLL_ values below. If you must change the link-layer header + * for a "cooked" Linux capture, introduce a new DLT_ type (ask + * "tcpdump-workers@tcpdump.org" for one, so that you don't give it a + * value that collides with a value already being used), and use the + * new header in captures of that type, so that programs that can + * handle DLT_LINUX_SLL captures will continue to handle them correctly + * without any change, and so that capture files with different headers + * can be told apart and programs that read them can dissect the + * packets in them. + * + * This structure, and the #defines below, must be the same in the + * libpcap and tcpdump versions of "sll.h". + */ + +/* + * A DLT_LINUX_SLL fake link-layer header. + */ +#define SLL_HDR_LEN 16 /* total header length */ +#define SLL_ADDRLEN 8 /* length of address field */ + +struct sll_header { + u_int16_t sll_pkttype; /* packet type */ + u_int16_t sll_hatype; /* link-layer address type */ + u_int16_t sll_halen; /* link-layer address length */ + u_int8_t sll_addr[SLL_ADDRLEN]; /* link-layer address */ + u_int16_t sll_protocol; /* protocol */ +}; + +/* + * The LINUX_SLL_ values for "sll_pkttype"; these correspond to the + * PACKET_ values on Linux, but are defined here so that they're + * available even on systems other than Linux, and so that they + * don't change even if the PACKET_ values change. + */ +#define LINUX_SLL_HOST 0 +#define LINUX_SLL_BROADCAST 1 +#define LINUX_SLL_MULTICAST 2 +#define LINUX_SLL_OTHERHOST 3 +#define LINUX_SLL_OUTGOING 4 + +/* + * The LINUX_SLL_ values for "sll_protocol"; these correspond to the + * ETH_P_ values on Linux, but are defined here so that they're + * available even on systems other than Linux. We assume, for now, + * that the ETH_P_ values won't change in Linux; if they do, then: + * + * if we don't translate them in "pcap-linux.c", capture files + * won't necessarily be readable if captured on a system that + * defines ETH_P_ values that don't match these values; + * + * if we do translate them in "pcap-linux.c", that makes life + * unpleasant for the BPF code generator, as the values you test + * for in the kernel aren't the values that you test for when + * reading a capture file, so the fixup code run on BPF programs + * handed to the kernel ends up having to do more work. + * + * Add other values here as necessary, for handling packet types that + * might show up on non-Ethernet, non-802.x networks. (Not all the ones + * in the Linux "if_ether.h" will, I suspect, actually show up in + * captures.) + */ +#define LINUX_SLL_P_802_3 0x0001 /* Novell 802.3 frames without 802.2 LLC header */ +#define LINUX_SLL_P_802_2 0x0004 /* 802.2 frames (not D/I/X Ethernet) */ diff --git a/kame/kame/tcpdump/smb.h b/kame/kame/tcpdump/smb.h new file mode 100644 index 0000000000..883ba64009 --- /dev/null +++ b/kame/kame/tcpdump/smb.h @@ -0,0 +1,122 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/smb.h,v 1.8 2002/06/11 17:09:00 itojun Exp $ (LBL) */ +/* + * 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 + */ + +#define SMBMIN(a,b) ((a)<(b)?(a):(b)) + +/* the complete */ +#define SMBmkdir 0x00 /* create directory */ +#define SMBrmdir 0x01 /* delete directory */ +#define SMBopen 0x02 /* open file */ +#define SMBcreate 0x03 /* create file */ +#define SMBclose 0x04 /* close file */ +#define SMBflush 0x05 /* flush file */ +#define SMBunlink 0x06 /* delete file */ +#define SMBmv 0x07 /* rename file */ +#define SMBgetatr 0x08 /* get file attributes */ +#define SMBsetatr 0x09 /* set file attributes */ +#define SMBread 0x0A /* read from file */ +#define SMBwrite 0x0B /* write to file */ +#define SMBlock 0x0C /* lock byte range */ +#define SMBunlock 0x0D /* unlock byte range */ +#define SMBctemp 0x0E /* create temporary file */ +#define SMBmknew 0x0F /* make new file */ +#define SMBchkpth 0x10 /* check directory path */ +#define SMBexit 0x11 /* process exit */ +#define SMBlseek 0x12 /* seek */ +#define SMBtcon 0x70 /* tree connect */ +#define SMBtconX 0x75 /* tree connect and X*/ +#define SMBtdis 0x71 /* tree disconnect */ +#define SMBnegprot 0x72 /* negotiate protocol */ +#define SMBdskattr 0x80 /* get disk attributes */ +#define SMBsearch 0x81 /* search directory */ +#define SMBsplopen 0xC0 /* open print spool file */ +#define SMBsplwr 0xC1 /* write to print spool file */ +#define SMBsplclose 0xC2 /* close print spool file */ +#define SMBsplretq 0xC3 /* return print queue */ +#define SMBsends 0xD0 /* send single block message */ +#define SMBsendb 0xD1 /* send broadcast message */ +#define SMBfwdname 0xD2 /* forward user name */ +#define SMBcancelf 0xD3 /* cancel forward */ +#define SMBgetmac 0xD4 /* get machine name */ +#define SMBsendstrt 0xD5 /* send start of multi-block message */ +#define SMBsendend 0xD6 /* send end of multi-block message */ +#define SMBsendtxt 0xD7 /* send text of multi-block message */ + +/* Core+ protocol */ +#define SMBlockread 0x13 /* Lock a range and read */ +#define SMBwriteunlock 0x14 /* Unlock a range then write */ +#define SMBreadbraw 0x1a /* read a block of data with no smb header */ +#define SMBwritebraw 0x1d /* write a block of data with no smb header */ +#define SMBwritec 0x20 /* secondary write request */ +#define SMBwriteclose 0x2c /* write a file then close it */ + +/* dos extended protocol */ +#define SMBreadBraw 0x1A /* read block raw */ +#define SMBreadBmpx 0x1B /* read block multiplexed */ +#define SMBreadBs 0x1C /* read block (secondary response) */ +#define SMBwriteBraw 0x1D /* write block raw */ +#define SMBwriteBmpx 0x1E /* write block multiplexed */ +#define SMBwriteBs 0x1F /* write block (secondary request) */ +#define SMBwriteC 0x20 /* write complete response */ +#define SMBsetattrE 0x22 /* set file attributes expanded */ +#define SMBgetattrE 0x23 /* get file attributes expanded */ +#define SMBlockingX 0x24 /* lock/unlock byte ranges and X */ +#define SMBtrans 0x25 /* transaction - name, bytes in/out */ +#define SMBtranss 0x26 /* transaction (secondary request/response) */ +#define SMBioctl 0x27 /* IOCTL */ +#define SMBioctls 0x28 /* IOCTL (secondary request/response) */ +#define SMBcopy 0x29 /* copy */ +#define SMBmove 0x2A /* move */ +#define SMBecho 0x2B /* echo */ +#define SMBopenX 0x2D /* open and X */ +#define SMBreadX 0x2E /* read and X */ +#define SMBwriteX 0x2F /* write and X */ +#define SMBsesssetupX 0x73 /* Session Set Up & X (including User Logon) */ +#define SMBffirst 0x82 /* find first */ +#define SMBfunique 0x83 /* find unique */ +#define SMBfclose 0x84 /* find close */ +#define SMBinvalid 0xFE /* invalid command */ + +/* Extended 2.0 protocol */ +#define SMBtrans2 0x32 /* TRANS2 protocol set */ +#define SMBtranss2 0x33 /* TRANS2 protocol set, secondary command */ +#define SMBfindclose 0x34 /* Terminate a TRANSACT2_FINDFIRST */ +#define SMBfindnclose 0x35 /* Terminate a TRANSACT2_FINDNOTIFYFIRST */ +#define SMBulogoffX 0x74 /* user logoff */ + +/* NT SMB extensions. */ +#define SMBnttrans 0xA0 /* NT transact */ +#define SMBnttranss 0xA1 /* NT transact secondary */ +#define SMBntcreateX 0xA2 /* NT create and X */ +#define SMBntcancel 0xA4 /* NT cancel */ + +/* pathworks special */ +#define pSETDIR '\377' + + +/* these are the TRANS2 sub commands */ +#define TRANSACT2_OPEN 0 +#define TRANSACT2_FINDFIRST 1 +#define TRANSACT2_FINDNEXT 2 +#define TRANSACT2_QFSINFO 3 +#define TRANSACT2_SETFSINFO 4 +#define TRANSACT2_QPATHINFO 5 +#define TRANSACT2_SETPATHINFO 6 +#define TRANSACT2_QFILEINFO 7 +#define TRANSACT2_SETFILEINFO 8 +#define TRANSACT2_FSCTL 9 +#define TRANSACT2_IOCTL 10 +#define TRANSACT2_FINDNOTIFYFIRST 11 +#define TRANSACT2_FINDNOTIFYNEXT 12 +#define TRANSACT2_MKDIR 13 + +#define PTR_DIFF(p1, p2) ((size_t)(((char *)(p1)) - (char *)(p2))) + +/* some protos */ +const u_char *smb_fdata(const u_char *, const char *, const u_char *); diff --git a/kame/kame/tcpdump/smbutil.c b/kame/kame/tcpdump/smbutil.c new file mode 100644 index 0000000000..5c1350f834 --- /dev/null +++ b/kame/kame/tcpdump/smbutil.c @@ -0,0 +1,853 @@ +/* + * 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" +#endif + +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.26.2.2 2003/11/16 08:51:56 guy Exp $"; +#endif + +#include + +#include +#include +#include + +#include "interface.h" +#include "extract.h" +#include "smb.h" + +extern const u_char *startbuf; + +/* + * interpret a 32 bit dos packed date/time to some parameters + */ +static void +interpret_dos_date(u_int32_t date, struct tm *tp) +{ + 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; +} + +/* + * common portion: + * create a unix date from a dos date + */ +static time_t +int_unix_date(u_int32_t dos_date) +{ + struct tm t; + + if (dos_date == 0) + return(0); + + interpret_dos_date(dos_date, &t); + t.tm_wday = 1; + t.tm_yday = 1; + t.tm_isdst = 0; + + return (mktime(&t)); +} + +/* + * create a unix date from a dos date + * in network byte order + */ +static time_t +make_unix_date(const u_char *date_ptr) +{ + u_int32_t dos_date = 0; + + dos_date = EXTRACT_LE_32BITS(date_ptr); + + return int_unix_date(dos_date); +} + +/* + * 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) +{ + u_int32_t x, x2; + + x = EXTRACT_LE_32BITS(date_ptr); + x2 = ((x & 0xFFFF) << 16) | ((x & 0xFFFF0000) >> 16); + return int_unix_date(x2); +} + +/* + * 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; + + TCHECK2(p[4], 4); + + /* this gives us seconds since jan 1st 1601 (approx) */ + d = (EXTRACT_LE_32BITS(p + 4) * 256.0 + 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; + + /* and a fudge factor as we got it wrong by a few days */ + d += (3 * 24 * 60 * 60 + 6 * 60 * 60 + 2); + + if (d < 0) + return(0); + + ret = (time_t)d; + + return(ret); +trunc: + 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; + + if (in >= maxbuf) + return(-1); /* name goes past the end of the buffer */ + TCHECK2(*in, 1); + len = (*in++) / 2; + + *out=0; + + if (len > 30 || len < 1) + return(0); + + 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]; + + return(ret); + +trunc: + return(-1); +} + +/* + * find a pointer to a netbios name + */ +static const u_char * +name_ptr(const u_char *buf, int ofs, const u_char *maxbuf) +{ + 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) { + 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 */ +} + +/* + * extract a netbios name from a buf + */ +static int +name_extract(const u_char *buf, int ofs, const u_char *maxbuf, char *name) +{ + 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; + + 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) + return(-1); /* name goes past the end of the buffer */ + TCHECK2(*s, 1); + s += (*s) + 1; + } + return(PTR_DIFF(s, s0) + 1); + +trunc: + return(-1); /* name goes past the end of the buffer */ +} + +static void +print_asc(const unsigned char *buf, int len) +{ + int i; + for (i = 0; i < len; i++) + safeputchar(buf[i]); +} + +static const char * +name_type_str(int name_type) +{ + const 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) +{ + 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"); + } +} + + +static void +write_bits(unsigned int val, const char *fmt) +{ + const 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 UCS2 string into iso-8859-1 string */ +static const char * +unistr(const u_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; + } + + /* maybe it isn't unicode - a cheap trick */ + if (!use_unicode || (s[0] && s[1])) { + *len = strlen((const char *)s) + 1; + return (const char *)s; + } + + *len = 0; + + if (s[0] == 0 && s[1] != 0) { + s++; + *len = 1; + } + + while (l < (int)(sizeof(buf) - 1) && s[0] && s[1] == 0) { + buf[l] = s[0]; + s += 2; + l++; + *len += 2; + } + buf[l] = 0; + *len += 2; + return buf; +} + +static const u_char * +smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf) +{ + int reverse = 0; + const char *attrib_fmt = "READONLY|HIDDEN|SYSTEM|VOLUME|DIR|ARCHIVE|"; + int len; + + while (*fmt && buf sizeof(bitfmt) - 1) + l = sizeof(bitfmt)-1; + + 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((unsigned char)*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((unsigned char)*fmt)) + fmt++; + break; + } + case 'h': + { + int l = atoi(fmt + 1); + while (l--) + printf("%02x", *buf++); + fmt++; + while (isdigit((unsigned char)*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((unsigned char)*fmt)) + fmt++; + break; + } + case 'T': + { + time_t t; + struct tm *lt; + const char *tstring; + u_int32_t x; + x = EXTRACT_LE_32BITS(buf); + + switch (atoi(fmt + 1)) { + case 1: + if (x == 0 || x == 0xFFFFFFFF) + t = 0; + else + t = make_unix_date(buf); + buf += 4; + break; + case 2: + if (x == 0 || x == 0xFFFFFFFF) + t = 0; + else + t = make_unix_date2(buf); + buf += 4; + break; + case 3: + t = interpret_long_date(buf); + buf += 8; + break; + } + if (t != 0) { + lt = localtime(&t); + if (lt != NULL) + tstring = asctime(lt); + else + tstring = "(Can't convert time)\n"; + } else + tstring = "NULL\n"; + printf("%s", tstring); + fmt++; + while (isdigit((unsigned char)*fmt)) + fmt++; + break; + } + default: + putchar(*fmt); + fmt++; + break; + } + } + + if (buf >= maxbuf && *fmt) + printf("END OF BUFFER\n"); + + return(buf); + +trunc: + printf("\n"); + printf("WARNING: Short packet. Try increasing the snap length\n"); + return(NULL); +} + +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 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 ((size_t)(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) { + 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 { + 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 } + }; + +/* 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 } +}; + +/* 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; + const 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; + } + } + + 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); +} diff --git a/kame/kame/tcpdump/strcasecmp.c b/kame/kame/tcpdump/strcasecmp.c index f2ac077131..7f087a47f1 100644 --- a/kame/kame/tcpdump/strcasecmp.c +++ b/kame/kame/tcpdump/strcasecmp.c @@ -10,11 +10,16 @@ * is provided ``as is'' without express or implied warranty. */ -#if defined(LIBC_SCCS) && !defined(lint) -static const char sccsid[] = "@(#)strcasecmp.c 5.5 (Berkeley) 11/24/87"; -#endif /* LIBC_SCCS and not lint */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#include +#ifndef lint +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/strcasecmp.c,v 1.4.2.2 2003/11/16 08:51:57 guy Exp $"; +#endif + +#include #include "interface.h" diff --git a/kame/kame/tcpdump/tcp.h b/kame/kame/tcpdump/tcp.h new file mode 100644 index 0000000000..414b481989 --- /dev/null +++ b/kame/kame/tcpdump/tcp.h @@ -0,0 +1,80 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/tcp.h,v 1.10 2002/12/11 07:14:11 guy Exp $ (LBL) */ +/* + * 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. + * + * @(#)tcp.h 8.1 (Berkeley) 6/10/93 + */ + +typedef u_int32_t tcp_seq; +/* + * TCP header. + * Per RFC 793, September, 1981. + */ +struct tcphdr { + u_int16_t th_sport; /* source port */ + u_int16_t th_dport; /* destination port */ + tcp_seq th_seq; /* sequence number */ + tcp_seq th_ack; /* acknowledgement number */ + u_int8_t th_offx2; /* data offset, rsvd */ +#define TH_OFF(th) (((th)->th_offx2 & 0xf0) >> 4) + u_int8_t th_flags; +#define TH_FIN 0x01 +#define TH_SYN 0x02 +#define TH_RST 0x04 +#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 */ +}; + +#define TCPOPT_EOL 0 +#define TCPOPT_NOP 1 +#define TCPOPT_MAXSEG 2 +#define TCPOLEN_MAXSEG 4 +#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/kame/kame/tcpdump/tcpdump-stdinc.h b/kame/kame/tcpdump/tcpdump-stdinc.h new file mode 100644 index 0000000000..00e6abea93 --- /dev/null +++ b/kame/kame/tcpdump/tcpdump-stdinc.h @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2002 - 2003 + * NetGroup, Politecnico di Torino (Italy) + * 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 Politecnico di Torino 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 COPYRIGHT HOLDERS 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 COPYRIGHT + * OWNER 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/tcpdump-stdinc.h,v 1.7.2.1 2003/11/16 09:57:50 guy Exp $ (LBL) + */ + +/* + * Include the appropriate OS header files on Windows and various flavors + * of UNIX, and also define some additional items and include various + * non-OS header files on Windows, and; this isolates most of the platform + * differences to this one file. + */ + +#ifndef tcpdump_stdinc_h +#define tcpdump_stdinc_h + +#ifdef WIN32 + +#include +#include +#include "bittypes.h" +#include +#include +#include +#include "IP6_misc.h" +#include + +#ifdef __MINGW32__ +#include +int* _errno(); +#define errno (*_errno()) + +#define INET_ADDRSTRLEN 16 +#define INET6_ADDRSTRLEN 46 + +#endif /* __MINGW32__ */ + +#ifndef toascii +#define toascii(c) ((c) & 0x7f) +#endif + +#ifndef caddr_t +typedef char* caddr_t; +#endif /* caddr_t */ + +#define MAXHOSTNAMELEN 64 +#define NI_MAXHOST 1025 +#define snprintf _snprintf +#define vsnprintf _vsnprintf +#define RETSIGTYPE void + +#if !defined(__MINGW32__) && !defined(__WATCOMC__) +#undef toascii +#define isascii __isascii +#define toascii __toascii +#define stat _stat +#define open _open +#define fstat _fstat +#define read _read +#define O_RDONLY _O_RDONLY + +typedef short ino_t; +#endif /* __MINGW32__ */ + +#else /* WIN32 */ + +#include +#include +#include +#include +#include /* concession to AIX */ +#include +#include +#include + +#ifdef TIME_WITH_SYS_TIME +#include +#endif + +#include + +#endif /* WIN32 */ + +#ifdef INET6 +#include "ip6.h" +#endif + +#if defined(WIN32) || defined(MSDOS) + #define FOPEN_READ_TXT "rt" + #define FOPEN_READ_BIN "rb" + #define FOPEN_WRITE_TXT "wt" + #define FOPEN_WRITE_BIN "wb" +#else + #define FOPEN_READ_TXT "r" + #define FOPEN_READ_BIN FOPEN_READ_TXT + #define FOPEN_WRITE_TXT "w" + #define FOPEN_WRITE_BIN FOPEN_WRITE_TXT +#endif + +#endif /* tcpdump_stdinc_h */ diff --git a/kame/kame/tcpdump/tcpdump.1 b/kame/kame/tcpdump/tcpdump.1 index 8451cd8d40..2cbc6b2923 100644 --- a/kame/kame/tcpdump/tcpdump.1 +++ b/kame/kame/tcpdump/tcpdump.1 @@ -1,4 +1,6 @@ -.\" @(#) $Header: tcpdump.1,v 1.67 97/06/30 16:31:50 leres Exp $ (LBL) +.\" @(#) $Header: /tcpdump/master/tcpdump/tcpdump.1,v 1.148.2.6 2004/03/28 21:25:03 fenner Exp $ (LBL) +.\" +.\" $NetBSD: tcpdump.8,v 1.9 2003/03/31 00:18:17 perry Exp $ .\" .\" Copyright (c) 1987, 1988, 1989, 1990, 1991, 1992, 1994, 1995, 1996, 1997 .\" The Regents of the University of California. All rights reserved. @@ -20,17 +22,23 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH TCPDUMP 1 "30 June 1997" +.TH TCPDUMP 1 "7 January 2004" .SH NAME tcpdump \- dump traffic on a network .SH SYNOPSIS .na .B tcpdump [ -.B \-adeflnNOpqRStvx +.B \-AdDeflLnNOpqRStuUvxX ] [ .B \-c .I count +] +.br +.ti +8 +[ +.B \-C +.I file_size ] [ .B \-F .I file @@ -40,16 +48,21 @@ tcpdump \- dump traffic on a network [ .B \-i .I interface -] [ +] +[ +.B \-m +.I module +] +[ .B \-r .I file ] +.br +.ti +8 [ .B \-s .I snaplen ] -.br -.ti +8 [ .B \-T .I type @@ -58,6 +71,19 @@ tcpdump \- dump traffic on a network .B \-w .I file ] +.br +.ti +8 +[ +.B \-E +.I spi@ipaddr algo:secret,... +] +.br +.ti +8 +[ +.B \-y +.I datalinktype +] +.ti +8 [ .I expression ] @@ -66,40 +92,161 @@ 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 \-r +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 +finishes capturing packets, it will report counts of: +.IP +packets ``captured'' (this is the number of packets that +.I tcpdump +has received and processed); +.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, even if they +were matched by the filter expression, regardless of whether +.I tcpdump +has read and processed them yet, on other OSes it counts only packets that were +matched by the filter expression regardless of whether +.I tcpdump +has read and processed them yet, 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 -you must have read access to +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 +(including Mac OS X) and Digital/Tru64 UNIX, it will report those counts +when it receives a SIGINFO signal (generated, for example, by typing +your ``status'' character, typically control-T, although on some +platforms, such as Mac OS X, the ``status'' character is not set by +default, so you must set it with +.BR stty (1) +in order to use it) 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: -You must have read access to the network pseudo device, e.g. +.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. Note that, on many (perhaps all) interfaces, if you don't capture +in promiscuous mode, you will not see any outgoing packets, so a capture +not done in promiscuous mode may not be very useful. +.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. -.B Under Ultrix and Digital UNIX: -Once the super-user has enabled promiscuous-mode operation using +You must be root or +.I tcpdump +must be installed setuid to root (unless your distribution has a kernel +that supports capability bits such as CAP_NET_RAW and code to allow +those capability bits to be given to particular accounts and to cause +those bits to be set on a user's initial processes when they log in, in +which case you must have CAP_NET_RAW in order to capture and +CAP_NET_ADMIN to enumerate network devices with, for example, the +.B \-D +flag). +.TP +.B Under ULTRIX and Digital UNIX/Tru64 UNIX: +Any user may capture network traffic with +.IR tcpdump . +However, no user (not even the super-user) can capture in promiscuous +mode on an interface unless the super-user has enabled promiscuous-mode +operation on that interface using .IR pfconfig (8), -any user may run -.BR tcpdump . -.B Under BSD: +and no user (not even the super-user) can capture unicast traffic +received by or sent by the machine on an interface unless the super-user +has enabled copy-all-mode operation on that interface using +.IR pfconfig , +so +.I useful +packet capture on an interface probably requires that either +promiscuous-mode or copy-all-mode operation, or both modes of +operation, be enabled on that interface. +.TP +.B Under BSD (this includes Mac OS X): You must have read access to .IR /dev/bpf* . +On BSDs with a devfs (this includes Mac OS X), this might involve more +than just having somebody with super-user access setting the ownership +or permissions on the BPF devices - it might involve configuring devfs +to set the ownership or permissions every time the system is booted, +if the system even supports that; if it doesn't support that, you might +have to find some other way to make that happen at boot time. +.LP +Reading a saved packet file doesn't require special privileges. .SH OPTIONS .TP -.B \-a -Attempt to convert network and broadcast addresses to names. +.B \-A +Print each packet (minus its link level header) in ASCII. Handy for +capturing web pages. .TP .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. @@ -112,14 +259,83 @@ program fragment. .B \-ddd Dump packet-matching code as decimal numbers (preceded with a count). .TP +.B \-D +Print the list of the network interfaces available on the system and on +which +.I tcpdump +can capture packets. For each network interface, a number and an +interface name, possibly followed by a text description of the +interface, is printed. The interface name or the number can be supplied +to the +.B \-i +flag to specify an interface on which to capture. +.IP +This can be useful on systems that don't have a command to list them +(e.g., Windows systems, or UNIX systems lacking +.BR "ifconfig \-a" ); +the number can be useful on Windows 2000 and later systems, where the +interface name is a somewhat complex string. +.IP +The +.B \-D +flag will not be supported if +.I tcpdump +was built with an older version of +.I libpcap +that lacks the +.B pcap_findalldevs() +function. +.TP .B \-e Print the link-level header on each dump line. .TP +.B \-E +Use \fIspi@ipaddr algo:secret\fP for decrypting IPsec ESP packets that +are addressed to \fIaddr\fP and contain Security Parameter Index value +\fIspi\fP. This combination may be repeated with comma or newline seperation. +.IP +Note that setting the secret for IPv4 ESP packets is supported at this time. +.IP +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 +with cryptography enabled. +.IP +\fIsecret\fP is the ASCII text for ESP secret key. +If preceeded by 0x, then a hex value will be read. +.IP +The option assumes RFC2406 ESP, not RFC1827 ESP. +The option is only for debugging purposes, and +the use of this option with a true `secret' key is discouraged. +By presenting IPsec secret key onto command line +you make it visible to others, via +.IR ps (1) +and other occasions. +.IP +In addition to the above syntax, the syntax \fIfile name\fP may be used +to have tcpdump read the provided file in. The file is opened upon +receiving the first ESP packet, so any special permissions that tcpdump +may have been given should already have been given up. +.TP .B \-f -Print `foreign' internet addresses numerically rather than symbolically +Print `foreign' IPv4 addresses numerically rather than symbolically (this option is intended to get around serious brain damage in -Sun's yp server \(em usually it hangs forever translating non-local +Sun's NIS server \(em usually it hangs forever translating non-local internet numbers). +.IP +The test for `foreign' IPv4 addresses is done using the IPv4 address and +netmask of the interface on which capture is being done. If that +address or netmask are not available, available, either because the +interface on which capture is being done has no address or netmask or +because the capture is being done on the Linux "any" interface, which +can capture on more than one interface, this option will not work +correctly. .TP .B \-F Use \fIfile\fP as input for the filter expression. @@ -130,108 +346,211 @@ Listen on \fIinterface\fP. If unspecified, \fItcpdump\fP searches the system interface list for the lowest numbered, configured up interface (excluding loopback). 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. +Note that captures on the ``any'' device will not be done in promiscuous +mode. +.IP +If the +.B \-D +flag is supported, an interface number as printed by that flag can be +used as the +.I interface +argument. .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 \-L +List the known data link types for the interface and exit. +.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 \-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). +Read packets from \fIfile\fR (which was created with the +.B \-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 +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 +\fBaodv\fR (Ad-hoc On-demand Distance Vector protocol), +\fBcnfp\fR (Cisco NetFlow protocol), \fBrpc\fR (Remote Procedure Call), \fBrtp\fR (Real-Time Applications protocol), \fBrtcp\fR (Real-Time Applications control protocol), +\fBsnmp\fR (Simple Network Management Protocol), +\fBtftp\fR (Trivial File Transfer Protocol), \fBvat\fR (Visual Audio Tool), 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 .B \-tt Print an unformatted timestamp on each dump line. .TP +.B \-ttt +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. +.TP +.B \-u +Print undecoded NFS handles. +.TP +.B \-U +Make output saved via the +.B \-w +option ``packet-buffered''; i.e., as each packet is saved, it will be +written to the output file, rather than being written only when the +output buffer fills. +.IP +The +.B \-U +flag will not be supported if +.I tcpdump +was built with an older version of +.I libpcap +that lacks the +.B pcap_dump_flush() +function. +.TP .B \-v -(Slightly more) verbose output. For example, the time to live -and type of service information in an IP packet is printed. +(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, +telnet \fBSB\fP ... \fBSE\fP options +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 Print each packet (minus its link level header) in hex. The smaller of the entire packet or .I snaplen -bytes will be printed. +bytes will be printed. Note that this is the entire link-layer +packet, so for link layers that pad (e.g. Ethernet), the padding bytes +will also be printed when the higher layer packet is shorter than the +required padding. +.TP +.B \-xx +Print each packet, +.I including +its link level header, in hex. +.TP +.B \-X +Print each packet (minus its link level header) in hex and ASCII. +This is very handy for analysing new protocols. +.TP +.B \-XX +Print each packet, +.I including +its link level header, in hex and ASCII. +.TP +.B \-y +Set the data link type to use while capturing packets to \fIdatalinktype\fP. .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. @@ -240,13 +559,14 @@ 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. .IP \fIdir\fP qualifiers specify a particular transfer direction to and/or from -.I id. +.IR id . Possible directions are .BR src , .BR dst , @@ -254,37 +574,38 @@ 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. -For `null' link layers (i.e. point to point protocols such as slip) the +For some link layers, such as SLIP and the ``cooked'' Linux capture mode +used for the ``any'' device and for some other device types, the .B inbound 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 , +.BR tr , +.BR wlan , .BR ip , .BR ip6 , .BR arp , .BR rarp , .BR decnet , -.BR lat , -.BR sca , -.BR moprc , -.BR mopdl , -.BR icmp , -.BR icmp6 , .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 @@ -293,8 +614,15 @@ 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, -but you cannot name them explicitly in a filter expression.] +analogous Ethernet fields. +FDDI headers also contain other fields, +but you cannot name them explicitly in a filter expression. +.LP +Similarly, `tr' and `wlan' are aliases for `ether'; the previous +paragraph's statements about FDDI headers also apply to Token Ring +and 802.11 wireless LAN headers. For 802.11 headers, the destination +address is the DA field and the source address is the SA field; the +BSSID, RA, and TA fields aren't tested.] .LP In addition to the above, there are some special `primitive' keywords that don't follow the pattern: @@ -302,15 +630,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 @@ -338,7 +669,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). @@ -347,11 +679,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 @@ -361,7 +697,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 @@ -369,12 +706,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 @@ -384,7 +722,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). @@ -417,17 +756,18 @@ This is equivalent to: .fi .in -.5i .IP "\fBip proto \fIprotocol\fR" -True if the packet is an ip packet (see +True if the packet is an IP packet (see .IR ip (4P)) of protocol type \fIprotocol\fP. \fIProtocol\fP can be a number or one of the names -\fIicmp\fP, \fIigrp\fP, \fIudp\fP, \fInd\fP, or \fItcp\fP. +\fIicmp\fP, \fIicmp6\fP, \fIigmp\fP, \fIigrp\fP, \fIpim\fP, \fIah\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 @@ -448,14 +788,23 @@ 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 -the all-zeroes and all-ones broadcast conventions, and looks up -the local subnet mask. +True if the packet is an IPv4 broadcast packet. +It checks for both the all-zeroes and all-ones broadcast conventions, +and looks up the subnet mask on the interface on which the capture is +being done. +.IP +If the subnet mask of the interface on which the capture is being done +is not available, either because the interface on which capture is being +done has no netmask or because the capture is being done on the Linux +"any" interface, which can capture on more than one interface, this +check will not work correctly. .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" @@ -464,21 +813,67 @@ True if the packet is an IP multicast packet. True if the packet is an IPv6 multicast packet. .IP "\fBether proto \fIprotocol\fR" True if the packet is of ether type \fIprotocol\fR. -\fIProtocol\fP can be a number or a name like -\fIip\fP, \fIip6\fP, \fIarp\fP, or \fIrarp\fP. +\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, +\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.] +.IP +[In the case of FDDI (e.g., `\fBfddi protocol arp\fR'), Token Ring +(e.g., `\fBtr protocol arp\fR'), and IEEE 802.11 wireless LANS (e.g., +`\fBwlan 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, Token Ring, or +802.11 header. +.IP +When filtering for most protocol identifiers on FDDI, Token Ring, or +802.11, \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. +The exceptions are: +.RS +.TP +\fBiso\fP +\fItcpdump\fR checks the DSAP (Destination Service Access Point) and +SSAP (Source Service Access Point) fields of the LLC header; +.TP +\fBstp\fP and \fInetbeui\fP +\fItcpdump\fR checks the DSAP of the LLC header; +.TP +\fIatalk\fP +\fItcpdump\fR checks for a SNAP-format packet with an OUI of 0x080007 +and the AppleTalk etype. +.RE +.IP +In the case of Ethernet, \fItcpdump\fR checks the Ethernet type field +for most of those protocols. The exceptions are: +.RS +.TP +\fBiso\fP, \fBsap\fP, and \fBnetbeui\fP +\fItcpdump\fR checks for an 802.3 frame and then checks the LLC header as +it does for FDDI, Token Ring, and 802.11; +.TP +\fBatalk\fP +\fItcpdump\fR checks both for the AppleTalk etype in an Ethernet frame and +for a SNAP-format packet as it does for FDDI, Token Ring, and 802.11; +.TP +\fBaarp\fP +\fItcpdump\fR checks for the AppleTalk ARP etype in either an Ethernet +frame or an 802.2 SNAP frame with an OUI of 0x000000; +.TP +\fBipx\fP +\fItcpdump\fR 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. +.RE .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 @@ -486,7 +881,59 @@ 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, \fBdecnet\fR" +.IP "\fBifname \fIinterface\fR" +True if the packet was logged as coming from the specified interface (applies +only to packets logged by OpenBSD's +.BR pf (4)). +.IP "\fBon \fIinterface\fR" +Synonymous with the +.B ifname +modifier. +.IP "\fBrnr \fInum\fR" +True if the packet was logged as matching the specified PF rule number +(applies only to packets logged by OpenBSD's +.BR pf (4)). +.IP "\fBrulenum \fInum\fR" +Synonomous with the +.B rnr +modifier. +.IP "\fBreason \fIcode\fR" +True if the packet was logged with the specified PF reason code. The known +codes are: +.BR match , +.BR bad-offset , +.BR fragment , +.BR short , +.BR normalize , +and +.B memory +(applies only to packets logged by OpenBSD's +.BR pf (4)). +.IP "\fBrset \fIname\fR" +True if the packet was logged as matching the specified PF ruleset +name of an anchored ruleset (applies only to packets logged by +.BR pf (4)). +.IP "\fBruleset \fIname\fR" +Synonomous with the +.B rset +modifier. +.IP "\fBsrnr \fInum\fR" +True if the packet was logged as matching the specified PF rule number +of an anchored ruleset (applies only to packets logged by +.BR pf (4)). +.IP "\fBsubrulenum \fInum\fR" +Synonomous with the +.B srnr +modifier. +.IP "\fBaction \fIact\fR" +True if PF took the specified action when the packet was logged. Known actions +are: +.B pass +and +.B block +(applies only to packets logged by OpenBSD's +.BR pf (4)). +.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 @@ -504,6 +951,13 @@ Abbreviations for: where \fIp\fR is one of the above protocols. Note that \fItcpdump\fP does not currently know how to parse these protocols. +.IP "\fBvlan \fI[vlan_id]\fR" +True if the packet is an IEEE 802.1Q VLAN packet. +If \fI[vlan_id]\fR is specified, only true is the packet has the specified +\fIvlan_id\fR. +Note that the first \fBvlan\fR keyword encountered in \fIexpression\fR +changes the decoding offsets for the remainder of \fIexpression\fR +on the assumption that the packet is a VLAN packet. .IP "\fBtcp\fR, \fBudp\fR, \fBicmp\fR" Abbreviations for: .in +.5i @@ -512,11 +966,78 @@ Abbreviations for: .fi .in -.5i where \fIp\fR is one of the above protocols. +.IP "\fBiso proto \fIprotocol\fR" +True if the packet is an OSI packet of protocol type \fIprotocol\fP. +\fIProtocol\fP can be a number or one of the names +\fIclnp\fP, \fIesis\fP, or \fIisis\fP. +.IP "\fBclnp\fR, \fBesis\fR, \fBisis\fR" +Abbreviations for: +.in +.5i +.nf +\fBiso proto \fIp\fR +.fi +.in -.5i +where \fIp\fR is one of the above protocols. +.IP "\fBl1\fR, \fBl2\fR, \fBiih\fR, \fBlsp\fR, \fBsnp\fR, \fBcsnp\fR, \fBpsnp\fR" +Abbreviations for IS-IS PDU types. +.IP "\fBvpi\fP \fIn\fR +True if the packet is an ATM packet, for SunATM on Solaris, with a +virtual path identifier of +.IR n . +.IP "\fBvci\fP \fIn\fR +True if the packet is an ATM packet, for SunATM on Solaris, with a +virtual channel identifier of +.IR n . +.IP \fBlane\fP +True if the packet is an ATM packet, for SunATM on Solaris, and is +an ATM LANE packet. +Note that the first \fBlane\fR keyword encountered in \fIexpression\fR +changes the tests done in the remainder of \fIexpression\fR +on the assumption that the packet is either a LANE emulated Ethernet +packet or a LANE LE Control packet. If \fBlane\fR isn't specified, the +tests are done under the assumption that the packet is an +LLC-encapsulated packet. +.IP \fBllc\fP +True if the packet is an ATM packet, for SunATM on Solaris, and is +an LLC-encapsulated packet. +.IP \fBoamf4s\fP +True if the packet is an ATM packet, for SunATM on Solaris, and is +a segment OAM F4 flow cell (VPI=0 & VCI=3). +.IP \fBoamf4e\fP +True if the packet is an ATM packet, for SunATM on Solaris, and is +an end-to-end OAM F4 flow cell (VPI=0 & VCI=4). +.IP \fBoamf4\fP +True if the packet is an ATM packet, for SunATM on Solaris, and is +a segment or end-to-end OAM F4 flow cell (VPI=0 & (VCI=3 | VCI=4)). +.IP \fBoam\fP +True if the packet is an ATM packet, for SunATM on Solaris, and is +a segment or end-to-end OAM F4 flow cell (VPI=0 & (VCI=3 | VCI=4)). +.IP \fBmetac\fP +True if the packet is an ATM packet, for SunATM on Solaris, and is +on a meta signaling circuit (VPI=0 & VCI=1). +.IP \fBbcc\fP +True if the packet is an ATM packet, for SunATM on Solaris, and is +on a broadcast signaling circuit (VPI=0 & VCI=2). +.IP \fBsc\fP +True if the packet is an ATM packet, for SunATM on Solaris, and is +on a signaling circuit (VPI=0 & VCI=5). +.IP \fBilmic\fP +True if the packet is an ATM packet, for SunATM on Solaris, and is +on an ILMI circuit (VPI=0 & VCI=16). +.IP \fBconnectmsg\fP +True if the packet is an ATM packet, for SunATM on Solaris, and is +on a signaling circuit and is a Q.2931 Setup, Call Proceeding, Connect, +Connect Ack, Release, or Release Done message. +.IP \fBmetaconnect\fP +True if the packet is an ATM packet, for SunATM on Solaris, and is +on a meta signaling circuit and is a Q.2931 Setup, Call Proceeding, Connect, +Release, or Release Done message. .IP "\fIexpr relop expr\fR" -True if the relation holds, where \fIrelop\fR is one of >, <, >=, <=, =, !=, -and \fIexpr\fR is an arithmetic expression composed of integer constants -(expressed in standard C syntax), the normal binary operators -[+, -, *, /, &, |], a length operator, and special packet data accessors. +True if the relation holds, where \fIrelop\fR is one of >, <, >=, <=, =, +!=, and \fIexpr\fR is an arithmetic expression composed of integer +constants (expressed in standard C syntax), the normal binary operators +[+, -, *, /, &, |, <<, >>], a length operator, and special packet data +accessors. To access data inside the packet, use the following syntax: .in +.5i @@ -524,9 +1045,11 @@ data inside the packet, use the following syntax: \fIproto\fB [ \fIexpr\fB : \fIsize\fB ]\fR .fi .in -.5i -\fIProto\fR is one of \fBether, fddi, +\fIProto\fR is one of \fBether, fddi, tr, wlan, ppp, slip, link, ip, arp, rarp, tcp, udp, icmp\fR or \fBip6\fR, and indicates the protocol layer for the index operation. +(\fBether, fddi, wlan, tr, ppp, slip\fR and \fBlink\fR all refer to the +link layer.) Note that \fItcp, udp\fR and other upper-layer protocol types only apply to IPv4, not IPv6 (this will be fixed in the future). The byte offset, relative to the indicated protocol layer, is @@ -538,7 +1061,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 @@ -546,6 +1070,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-ack\fP, \fBtcp-urg\fP. .LP Primitives may be combined using: .IP @@ -560,7 +1101,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 @@ -584,8 +1126,8 @@ which should not be confused with .fi .in -.5i .LP -Expression arguments can be passed to tcpdump as either a single argument -or as multiple arguments, whichever is more convenient. +Expression arguments can be passed to \fItcpdump\fP as either a single +argument or as multiple arguments, whichever is more convenient. Generally, if the expression contains Shell metacharacters, it is easier to pass it as a single, quoted argument. Multiple arguments are concatenated with spaces before being parsed. @@ -645,7 +1187,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 @@ -672,12 +1214,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 @@ -692,14 +1235,32 @@ 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 +the '-e' option is specified or not, the source routing information is +printed for source-routed packets. +.LP +On 802.11 networks, the '-e' option causes \fItcpdump\fP to print +the `frame control' fields, all of the addresses in the 802.11 header, +and the packet length. +As on FDDI networks, +packets are assumed to contain an LLC packet. +.LP \fI(N.B.: The following description assumes familiarity with the SLIP compression algorithm described in RFC-1144.)\fP .LP @@ -733,7 +1294,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: @@ -741,16 +1303,17 @@ host \fIrtsg\fP to host \fIcsam\fP: .nf .sp .5 \f(CWarp who-has csam tell rtsg -arp reply csam is-at CSAM\fP +arp reply csam is-at CSAM\fR .sp .5 .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 @@ -759,13 +1322,13 @@ 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 .sp .5 \f(CWRTSG Broadcast 0806 64: arp who-has csam tell rtsg -CSAM RTSG 0806 64: arp reply csam is-at CSAM\fP +CSAM RTSG 0806 64: arp reply csam is-at CSAM\fR .sp .5 .fi .RE @@ -776,8 +1339,9 @@ 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 -with the protocol, neither this description nor tcpdump will +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 The general format of a tcp protocol line is: @@ -789,8 +1353,10 @@ 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), -F (FIN), P (PUSH) or R (RST) or a single `.' (no flags). +addresses and ports. +\fIFlags\fP are some combination of S (SYN), +F (FIN), P (PUSH), R (RST), W (ECN CWR) or E (ECN-Echo), or a single +`.' (no flags). \fIData-seqno\fP describes the portion of sequence space covered by the data in this packet (see example below). \fIAck\fP is sequence number of the next data expected the other @@ -800,7 +1366,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., ). .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 @@ -817,13 +1384,14 @@ csam.login > rtsg.1023: . ack 2 win 4096 rtsg.1023 > csam.login: P 2:21(19) ack 1 win 4096 csam.login > rtsg.1023: P 1:2(1) ack 21 win 4077 csam.login > rtsg.1023: P 2:3(1) ack 21 win 4077 urg 1 -csam.login > rtsg.1023: P 3:4(1) ack 21 win 4077 urg 1\fP\s+2 +csam.login > rtsg.1023: P 3:4(1) ack 21 win 4077 urg 1\fR\s+2 .sp .5 .fi .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 @@ -833,39 +1401,239 @@ 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 \fBtcpdump\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, csam sends two bytes of urgent, pushed data to rtsg. .LP -If the snapshot was small enough that \fBtcpdump\fP didn't capture +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 -that's either too small or beyond the end of the header), tcpdump 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 length indicates -options are present but the IP datagram length is not long enough for the -options to actually be there, tcpdump reports it as ``[\fIbad hdr length\fP]''. +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 +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 8 bits in the control bits section of the TCP header: +.IP +.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 +when it initializes a new connection; the connection sequence with +regard to the TCP control bits is +.PP +.RS +1) Caller sends SYN +.RE +.RS +2) Recipient responds with SYN, ACK +.RE +.RS +3) Caller sends ACK +.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 +expression for \fItcpdump\fP. +.PP +Recall the structure of a TCP header without options: +.PP +.nf + 0 15 31 +----------------------------------------------------------------- +| source port | destination port | +----------------------------------------------------------------- +| sequence number | +----------------------------------------------------------------- +| acknowledgment number | +----------------------------------------------------------------- +| 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 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 +in octet 13: +.PP +.nf + 0 7| 15| 23| 31 +----------------|---------------|---------------|---------------- +| HL | rsvd |C|E|U|A|P|R|S|F| window size | +----------------|---------------|---------------|---------------- +| | 13th octet | | | +.fi +.PP +Let's have a closer look at octet no. 13: +.PP +.nf + | | + |---------------| + |C|E|U|A|P|R|S|F| + |---------------| + |7 5 3 0| +.fi +.PP +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. +Let's see what happens to octet 13 if a TCP datagram arrives +with the SYN bit set in its header: +.PP +.nf + |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 +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 +network byte order, the binary value of this octet is +.IP +00000010 +.PP +and its decimal representation is +.PP +.nf + 7 6 5 4 3 2 1 0 +0*2 + 0*2 + 0*2 + 0*2 + 0*2 + 0*2 + 1*2 + 0*2 = 2 +.fi +.PP +We're almost done, because now we know that if only SYN is set, +the value of the 13th octet in the TCP header, when interpreted +as a 8-bit unsigned integer in network byte order, must be exactly 2. +.PP +This relationship can be expressed as +.RS +.B +tcp[13] == 2 +.RE +.PP +We can use this expression as the filter for \fItcpdump\fP in order +to watch packets which have only SYN set: +.RS +.B +tcpdump -i xl0 tcp[13] == 2 +.RE +.PP +The expression says "let the 13th octet of a TCP datagram have +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 +with SYN-ACK set arrives: +.PP +.nf + |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 +octet 13 is +.IP + 00010010 +.PP +which translates to decimal +.PP +.nf + 7 6 5 4 3 2 1 0 +0*2 + 0*2 + 0*2 + 1*2 + 0*2 + 0*2 + 1*2 + 0*2 = 18 +.fi +.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 +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, +so we'll logically AND the value in the 13th octet with +the binary value of a SYN: +.PP +.nf + + 00010010 SYN-ACK 00000010 SYN + AND 00000010 (we want SYN) AND 00000010 (we want SYN) + -------- -------- + = 00000010 = 00000010 +.fi +.PP +We see that this AND operation delivers the same result +regardless whether ACK or another TCP control bit is set. +The decimal representation of the AND value as well as +the result of this operation is 2 (binary 00000010), +so we know that for packets with SYN set the following +relation must hold true: +.IP +( ( value of octet 13 ) AND ( 2 ) ) == ( 2 ) +.PP +This points us to the \fItcpdump\fP filter expression +.RS +.B + tcpdump -i xl0 'tcp[13] & 2 == 2' +.RE +.PP +Note that you should use single quotes or a backslash +in the expression to hide the AND ('&') special character +from the shell. .HD .B UDP Packets @@ -880,7 +1648,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. @@ -890,7 +1659,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 @@ -900,24 +1670,29 @@ Name server requests are formatted as .sp .5 \fIsrc > dst: id op? flags qtype qclass name (len)\fP .sp .5 -\f(CWh2opolo.1538 > helios.domain: 3+ A? ucbvax.berkeley.edu. (37)\fP +\f(CWh2opolo.1538 > helios.domain: 3+ A? ucbvax.berkeley.edu. (37)\fR .sp .5 .fi .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 @@ -937,34 +1712,66 @@ Name server responses are formatted as \fIsrc > dst: id op rcode flags a/n/au type class data (len)\fP .sp .5 \f(CWhelios.domain > h2opolo.1538: 3 3/3/7 A 128.32.137.3 (273) -helios.domain > h2opolo.1537: 2 NXDomain* 0/1/0 (97)\fP +helios.domain > h2opolo.1537: 2 NXDomain* 0/1/0 (97)\fR .sp .5 .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. + +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 +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 +auto-detect unicode strings 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 favorite +samba.org mirror site. +The SMB patches were written by Andrew Tridgell +(tridge@samba.org). + .HD NFS Requests and Replies .LP @@ -982,14 +1789,16 @@ sushi.201b > wrl.nfs: 144 lookup fh 9,74/4096.6878 "xcolors" wrl.nfs > sushi.201b: reply ok 128 lookup fh 9,74/4134.3150 -\fP +\fR .sp .5 .fi .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 @@ -997,8 +1806,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 @@ -1016,14 +1827,16 @@ wrl.nfs > sushi.1372a: .sp .5 .fi .RE -(\-v also prints the IP header TTL, ID, and fragmentation fields, +(\-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. @@ -1031,21 +1844,95 @@ 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 -KIP Appletalk (DDP in UDP) +AFS Requests and Replies .LP -Appletalk DDP packets encapsulated in UDP datagrams are de-encapsulated +Transarc AFS (Andrew File System) requests and replies are printed +as: +.HD +.RS +.nf +.sp .5 +\fIsrc.sport > dst.dport: rx packet-type\fP +\fIsrc.sport > dst.dport: rx packet-type service call call-name args\fP +\fIsrc.sport > dst.dport: rx packet-type service reply call-name args\fP +.sp .5 +\f(CW +elvis.7001 > pike.afsfs: + rx data fs call rename old fid 536876964/1/1 ".newsrc.new" + new fid 536876964/1/1 ".newsrc" +pike.afsfs > elvis.7001: rx data fs reply rename +\fR +.sp .5 +.fi +.RE +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 +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 +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 +AFS RPCs have at least some of the arguments decoded (generally only +the `interesting' arguments, for some definition of interesting). +.LP +The format is intended to be self-describing, but it will probably +not be useful to people who are not familiar with the workings of +AFS and RX. +.LP +If the -v (verbose) flag is given twice, acknowledgement packets and +additional header information is printed, such as the the RX call ID, +call number, sequence number, serial number, and the RX packet flags. +.LP +If the -v flag is given twice, additional information is printed, +such as the the RX call ID, serial number, and the RX packet flags. +The MTU negotiation information is also printed from RX ack packets. +.LP +If the -v flag is given three times, the security index and service id +are printed. +.LP +Error codes are printed for abort packets, with the exception of Ubik +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' +to watch AFS traffic. +.LP +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 +follow the +corresponding request, it might not be parsable. + +.HD +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. +is used to translate AppleTalk net and node numbers to names. Lines in this file have the form .RS .nf @@ -1054,11 +1941,12 @@ Lines in this file have the form \f(CW1.254 ether 16.1 icsd-net -1.254.110 ace\fP +1.254.110 ace\fR .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 @@ -1069,7 +1957,7 @@ The file may contain blank lines or comment lines (lines starting with a `#'). .LP -Appletalk addresses are printed in the form +AppleTalk addresses are printed in the form .RS .nf .sp .5 @@ -1077,25 +1965,27 @@ Appletalk addresses are printed in the form \f(CW144.1.209.2 > icsd-net.112.220 office.2 > icsd-net.112.220 -jssmag.149.235 > icsd-net.2\fP +jssmag.149.235 > icsd-net.2\fR .sp .5 .fi .RE (If the .I /etc/atalk.names -doesn't exist or doesn't contain an entry for some appletalk +doesn't exist or doesn't contain an entry for some AppleTalk 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 +NBP (name binding protocol) and ATP (AppleTalk transaction protocol) +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. @@ -1105,15 +1995,17 @@ protocol) and packet size. .sp .5 \s-2\f(CWicsd-net.112.220 > jssmag.2: nbp-lkup 190: "=:LaserWriter@*" jssmag.209.2 > icsd-net.112.220: nbp-reply 190: "RM1140:LaserWriter@*" 250 -techpit.2 > icsd-net.112.220: nbp-reply 190: "techpit:LaserWriter@*" 186\fP\s+2 +techpit.2 > icsd-net.112.220: nbp-reply 190: "techpit:LaserWriter@*" 186\fR\s+2 .sp .5 .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. @@ -1134,23 +2026,29 @@ jssmag.209.165 > helios.132: atp-req 12266<3,5> 0xae030001 helios.132 > jssmag.209.165: atp-resp 12266:3 (512) 0xae040000 helios.132 > jssmag.209.165: atp-resp 12266:5 (512) 0xae040000 jssmag.209.165 > helios.132: atp-rel 12266<0-7> 0xae030001 -jssmag.209.133 > helios.132: atp-req* 12267<0-7> 0xae030002\fP\s+2 +jssmag.209.133 > helios.132: atp-req* 12267<0-7> 0xae030002\fR\s+2 .sp .5 .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 @@ -1165,16 +2063,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 @@ -1189,12 +2092,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 @@ -1203,7 +2108,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 @@ -1211,19 +2117,30 @@ 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. .SH "SEE ALSO" -traffic(1C), nit(4P), bpf(4), pcap(3) +stty(1), pcap(3), bpf(4), nit(4P), pfconfig(8) .SH AUTHORS +The original authors are: +.LP Van Jacobson, Craig Leres and Steven McCanne, all of the Lawrence Berkeley National Laboratory, University of California, Berkeley, CA. .LP -The current version is available via anonymous ftp: +It is currently being maintained by tcpdump.org. +.LP +The current version is available via http: +.LP +.RS +.I http://www.tcpdump.org/ +.RE +.LP +The original distribution is available via anonymous ftp: .LP .RS .I ftp://ftp.ee.lbl.gov/tcpdump.tar.Z @@ -1232,37 +2149,62 @@ The current version is available via anonymous ftp: IPv6/IPsec support is added by WIDE/KAME project. This program uses Eric Young's SSLeay library, under specific configuration. .SH BUGS -Please send bug reports to tcpdump@ee.lbl.gov. +Please send problems, bugs, questions, desirable enhancements, etc. to: +.LP +.RS +tcpdump-workers@tcpdump.org +.RE +.LP +Please send source code contributions, etc. to: +.LP +.RS +patches@tcpdump.org +.RE .LP NIT doesn't let you watch your own outbound traffic, BPF will. We recommend that you use the latter. .LP +On Linux systems with 2.0[.x] kernels: +.IP +packets on the loopback device will be seen twice; +.IP +packet filtering cannot be done in the kernel, so that all packets must +be copied from the kernel in order to be filtered in user mode; +.IP +all of a packet, not just the part that's within the snapshot length, +will be copied from the kernel (the 2.0[.x] packet capture mechanism, if +asked to copy only part of a packet to userland, will not report the +true length of the packet; this would cause most IP packets to get an +error from +.BR tcpdump ); +.IP +capturing on some PPP devices won't work correctly. +.LP +We recommend that you upgrade to a 2.2 or later kernel. +.LP Some attempt should be made to reassemble IP fragments or, at least to compute the right length for the higher level protocol. .LP -Name server inverse queries are not dumped correctly: The (empty) +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 -prefer to fix the program generating them rather than tcpdump. -.LP -Apple Ethertalk DDP packets could be dumped as easily as KIP DDP -packets but aren't. -Even if we were inclined to do anything to promote the use of -Ethertalk (we aren't), LBL doesn't allow Ethertalk on any of its -networks so we'd would have no way of testing this code. +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 skewed time stamps (the time change is ignored). .LP -Filters expressions that manipulate FDDI headers assume that all FDDI -packets are 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 accept certain packets that -do not properly match the filter expression. +Filter expressions on fields other than those in Token Ring headers will +not correctly handle source-routed Token Ring packets. +.LP +Filter expressions on fields other than those in 802.11 headers will not +correctly handle 802.11 data packets with both To DS and From DS set. .LP .BR "ip6 proto" should chase header chain, but at this moment it does not. -.BR tcp -or -.BR udp -should chase header chain too. +.BR "ip6 protochain" +is supplied for this behavior. +.LP +Arithmetic expression against transport layer headers, like \fBtcp[0]\fP, +does not work against IPv6 packets. +It only looks at IPv4 packets. diff --git a/kame/kame/tcpdump/tcpdump.c b/kame/kame/tcpdump/tcpdump.c index 8a9aecbbcf..9b8ff30687 100644 --- a/kame/kame/tcpdump/tcpdump.c +++ b/kame/kame/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 */ #ifndef lint -static const char copyright[] = - "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997\n\ +static const char copyright[] _U_ = + "@(#) 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.c,v 1.129 97/06/13 13:10:11 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.216.2.10 2004/03/17 19:47:48 guy Exp $ (LBL)"; #endif /* @@ -35,82 +41,178 @@ static const char rcsid[] = * combined efforts of Van, Steve McCanne and Craig Leres of LBL. */ -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include -#include +#ifdef WIN32 +#include "getopt.h" +#include "w32_fzs.h" +extern int strcasecmp (const char *__s1, const char *__s2); +extern int SIZE_BUF; +#define off_t long +#define uint UINT +#endif /* WIN32 */ #include #include #include #include #include -#include #include "interface.h" #include "addrtoname.h" #include "machdep.h" #include "setsignal.h" #include "gmt2local.h" +#include "pcap-missing.h" -int aflag; /* translate network and broadcast addresses */ int dflag; /* print filter code */ int eflag; /* print ethernet header */ int fflag; /* don't translate "foreign" IP address */ +int Lflag; /* list available data link types and exit */ int nflag; /* leave addresses as numbers */ int Nflag; /* remove domains from printed host names */ int Oflag = 1; /* run filter code optimizer */ int pflag; /* don't go promiscuous */ int qflag; /* quick (shorter) output */ int Rflag = 1; /* print sequence # field in AH/ESP*/ +int sflag = 0; /* use the libsmi to translate OIDs */ int Sflag; /* print raw TCP sequence numbers */ int tflag = 1; /* print packet arrival time */ +int Uflag = 0; /* "unbuffered" output of dump files */ +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 */ +int Aflag = 0; /* print packet only in ascii observing LF, CR, TAB, SPACE */ +int dlt = -1; /* if != -1, ask libpcap for the DLT it names */ + +const char *dlt_name = NULL; -char *ahsecret = NULL; /* AH secret key */ char *espsecret = NULL; /* ESP secret key */ int packettype; +static int infodelay; +static int infoprint; char *program_name; int32_t thiszone; /* seconds offset from gmt to local time */ -/* Externs */ -extern void bpf_dump(struct bpf_program *, int); - /* Forwards */ -RETSIGTYPE cleanup(int); -extern __dead void usage(void) __attribute__((volatile)); +static RETSIGTYPE cleanup(int); +static void usage(void) __attribute__((noreturn)); +static void show_dlts_and_exit(pcap_t *pd) __attribute__((noreturn)); + +static void print_packet(u_char *, const struct pcap_pkthdr *, const u_char *); +static void dump_packet_and_trunc(u_char *, const struct pcap_pkthdr *, const u_char *); +static void dump_packet(u_char *, const struct pcap_pkthdr *, const u_char *); + +#ifdef SIGINFO +RETSIGTYPE requestinfo(int); +#endif + +static void info(int); +static u_int packets_captured; /* Length of saved portion of packet. */ int snaplen = DEFAULT_SNAPLEN; +typedef u_int (*if_printer)(const struct pcap_pkthdr *, const u_char *); + struct printer { - pcap_handler f; + if_printer f; int type; }; static struct printer printers[] = { + { arcnet_if_print, DLT_ARCNET }, +#ifdef DLT_ARCNET_LINUX + { arcnet_linux_if_print, DLT_ARCNET_LINUX }, +#endif { ether_if_print, DLT_EN10MB }, - { ether_if_print, DLT_IEEE802 }, + { token_if_print, DLT_IEEE802 }, +#ifdef DLT_LANE8023 + { lane_if_print, DLT_LANE8023 }, +#endif +#ifdef DLT_CIP + { cip_if_print, DLT_CIP }, +#endif +#ifdef DLT_ATM_CLIP + { cip_if_print, DLT_ATM_CLIP }, +#endif { sl_if_print, DLT_SLIP }, +#ifdef DLT_SLIP_BSDOS { sl_bsdos_if_print, DLT_SLIP_BSDOS }, +#endif { ppp_if_print, DLT_PPP }, +#ifdef DLT_PPP_BSDOS { ppp_bsdos_if_print, DLT_PPP_BSDOS }, +#endif { fddi_if_print, DLT_FDDI }, { null_if_print, DLT_NULL }, +#ifdef DLT_LOOP + { null_if_print, DLT_LOOP }, +#endif { raw_if_print, DLT_RAW }, { atm_if_print, DLT_ATM_RFC1483 }, -#ifdef DLT_CHDLC - { chdlc_if_print, DLT_CHDLC }, +#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 +#ifdef DLT_PFLOG + { pflog_if_print, DLT_PFLOG }, +#endif +#ifdef DLT_FR + { fr_if_print, DLT_FR }, +#endif +#ifdef DLT_FRELAY + { fr_if_print, DLT_FRELAY }, +#endif +#ifdef DLT_SUNATM + { sunatm_if_print, DLT_SUNATM }, +#endif +#ifdef DLT_IP_OVER_FC + { ipfc_if_print, DLT_IP_OVER_FC }, +#endif +#ifdef DLT_PRISM_HEADER + { prism_if_print, DLT_PRISM_HEADER }, +#endif +#ifdef DLT_IEEE802_11_RADIO + { ieee802_11_radio_if_print, DLT_IEEE802_11_RADIO }, +#endif +#ifdef DLT_ENC + { enc_if_print, DLT_ENC }, +#endif +#ifdef DLT_APPLE_IP_OVER_IEEE1394 + { ap1394_if_print, DLT_APPLE_IP_OVER_IEEE1394 }, #endif { NULL, 0 }, }; -static pcap_handler +static if_printer lookup_printer(int type) { struct printer *p; @@ -119,7 +221,7 @@ lookup_printer(int type) if (type == p->type) return p->f; - error("unknown data link type 0x%x", type); + return NULL; /* NOTREACHED */ } @@ -129,17 +231,101 @@ extern int optind; extern int opterr; extern char *optarg; +struct print_info { + if_printer printer; +}; + +struct dump_info { + char *WFileName; + pcap_t *pd; + pcap_dumper_t *p; +}; + +static void +show_dlts_and_exit(pcap_t *pd) +{ + int n_dlts; + int *dlts = 0; + const char *dlt_name; + + n_dlts = pcap_list_datalinks(pd, &dlts); + if (n_dlts < 0) + error("%s", pcap_geterr(pd)); + else if (n_dlts == 0 || !dlts) + error("No data link types."); + + (void) fprintf(stderr, "Data link types (use option -y to set):\n"); + + while (--n_dlts >= 0) { + dlt_name = pcap_datalink_val_to_name(dlts[n_dlts]); + if (dlt_name != NULL) { + (void) fprintf(stderr, " %s (%s)", dlt_name, + pcap_datalink_val_to_description(dlts[n_dlts])); + + /* + * OK, does tcpdump handle that type? + */ + if (lookup_printer(dlts[n_dlts]) == NULL) + (void) fprintf(stderr, " (not supported)"); + putchar('\n'); + } else { + (void) fprintf(stderr, " DLT %d (not supported)\n", + dlts[n_dlts]); + } + } + free(dlts); + exit(0); +} + +/* + * Set up flags that might or might not be supported depending on the + * version of libpcap we're using. + */ +#ifdef WIN32 +#define B_FLAG "B:" +#define B_FLAG_USAGE " [ -B size ]" +#else /* WIN32 */ +#define B_FLAG +#define B_FLAG_USAGE +#endif /* WIN32 */ + +#ifdef HAVE_PCAP_FINDALLDEVS +#define D_FLAG "D" +#else +#define D_FLAG +#endif + +#ifdef HAVE_PCAP_DUMP_FLUSH +#define U_FLAG "U" +#else +#define U_FLAG +#endif + int main(int argc, char **argv) { register int cnt, op, i; bpf_u_int32 localnet, netmask; register char *cp, *infile, *cmdbuf, *device, *RFileName, *WFileName; - pcap_handler printer; + pcap_handler callback; + int type; struct bpf_program fcode; +#ifndef WIN32 RETSIGTYPE (*oldhandler)(int); +#endif + struct print_info printinfo; + struct dump_info dumpinfo; u_char *pcap_userdata; char ebuf[PCAP_ERRBUF_SIZE]; +#ifdef HAVE_PCAP_FINDALLDEVS + pcap_if_t *devpointer; + int devnum; +#endif + int status; +#ifdef WIN32 + u_int UserBufferSize = 1000000; + if(wsockinit() != 0) return 1; +#endif /* WIN32 */ cnt = -1; device = NULL; @@ -151,26 +337,35 @@ main(int argc, char **argv) else program_name = argv[0]; - if (abort_on_misalignment(ebuf) < 0) + if (abort_on_misalignment(ebuf, sizeof(ebuf)) < 0) error("%s", ebuf); +#ifdef LIBSMI + smiInit("tcpdump"); +#endif + opterr = 0; while ( - (op = getopt(argc, argv, "ac:deE:fF:i:lnNOpqr:Rs:StT:vw:xY")) != EOF) + (op = getopt(argc, argv, "aA" B_FLAG "c:C:d" D_FLAG "eE:fF:i:lLm:nNOpqr:Rs:StT:u" U_FLAG "vw:xXy:Y")) != -1) switch (op) { case 'a': - ++aflag; + /* compatibility for old -a */ break; -#if 0 case 'A': -#ifndef CRYPTO - warning("crypto code not compiled in"); -#endif - ahsecret = optarg; + ++xflag; + ++Xflag; + ++Aflag; break; -#endif + +#ifdef WIN32 + case 'B': + UserBufferSize = atoi(optarg)*1024; + if (UserBufferSize < 0) + error("invalid packet buffer size %s", optarg); + break; +#endif /* WIN32 */ case 'c': cnt = atoi(optarg); @@ -178,16 +373,42 @@ 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; +#ifdef HAVE_PCAP_FINDALLDEVS + case 'D': + if (pcap_findalldevs(&devpointer, ebuf) < 0) + error("%s", ebuf); + else { + for (i = 0; devpointer != 0; i++) { + printf("%d.%s", i+1, devpointer->name); + if (devpointer->description != NULL) + printf(" (%s)", devpointer->description); + printf("\n"); + devpointer = devpointer->next; + } + } + return 0; +#endif /* HAVE_PCAP_FINDALLDEVS */ + + case 'L': + Lflag++; + break; + case 'e': ++eflag; break; case 'E': -#ifndef CRYPTO +#ifndef HAVE_LIBCRYPTO warning("crypto code not compiled in"); #endif espsecret = optarg; @@ -202,15 +423,59 @@ main(int argc, char **argv) break; case 'i': + if (optarg[0] == '0' && optarg[1] == 0) + error("Invalid adapter index"); + +#ifdef HAVE_PCAP_FINDALLDEVS + /* + * If the argument is a number, treat it as + * an index into the list of adapters, as + * printed by "tcpdump -D". + * + * This should be OK on UNIX systems, as interfaces + * shouldn't have names that begin with digits. + * It can be useful on Windows, where more than + * one interface can have the same name. + */ + if ((devnum = atoi(optarg)) != 0) { + if (devnum < 0) + error("Invalid adapter index"); + + if (pcap_findalldevs(&devpointer, ebuf) < 0) + error("%s", ebuf); + else { + for (i = 0; i < devnum-1; i++){ + devpointer = devpointer->next; + if (devpointer == NULL) + error("Invalid adapter index"); + } + } + device = devpointer->name; + break; + } +#endif /* HAVE_PCAP_FINDALLDEVS */ device = optarg; break; case 'l': +#ifdef WIN32 + /* + * _IOLBF is the same as _IOFBF in Microsoft's C + * libraries; the only alternative they offer + * is _IONBF. + * + * XXX - this should really be checking for MSVC++, + * not WIN32, if, for example, MinGW has its own + * C library that is more UNIX-compatible. + */ + setvbuf(stdout, NULL, _IONBF, 0); +#else /* WIN32 */ #ifdef HAVE_SETLINEBUF setlinebuf(stdout); #else setvbuf(stdout, NULL, _IOLBF, 0); #endif +#endif /* WIN32 */ break; case 'n': @@ -221,6 +486,19 @@ main(int argc, char **argv) ++Nflag; break; + case 'm': +#ifdef LIBSMI + if (smiLoadModule(optarg) == 0) { + error("could not load MIB module %s", optarg); + } + sflag = 1; +#else + (void)fprintf(stderr, "%s: ignoring option `-m %s' ", + program_name, optarg); + (void)fprintf(stderr, "(no libsmi support)\n"); +#endif + break; + case 'O': Oflag = 0; break; @@ -241,11 +519,17 @@ main(int argc, char **argv) Rflag = 0; break; - case 's': - snaplen = atoi(optarg); - if (snaplen <= 0) + case 's': { + char *end; + + snaplen = strtol(optarg, &end, 0); + if (optarg == end || *end != '\0' + || snaplen < 0 || snaplen > 65535) error("invalid snaplen %s", optarg); + else if (snaplen == 0) + snaplen = 65535; break; + } case 'S': ++Sflag; @@ -266,10 +550,28 @@ main(int argc, char **argv) packettype = PT_RTP; else if (strcasecmp(optarg, "rtcp") == 0) packettype = PT_RTCP; + else if (strcasecmp(optarg, "snmp") == 0) + packettype = PT_SNMP; + else if (strcasecmp(optarg, "cnfp") == 0) + packettype = PT_CNFP; + else if (strcasecmp(optarg, "tftp") == 0) + packettype = PT_TFTP; + else if (strcasecmp(optarg, "aodv") == 0) + packettype = PT_AODV; else error("unknown packet type `%s'", optarg); break; + case 'u': + ++uflag; + break; + +#ifdef HAVE_PCAP_DUMP_FLUSH + case 'U': + ++Uflag; + break; +#endif + case 'v': ++vflag; break; @@ -277,41 +579,75 @@ main(int argc, char **argv) case 'w': WFileName = optarg; break; -#ifdef YYDEBUG + + case 'x': + ++xflag; + break; + + case 'X': + ++xflag; + ++Xflag; + break; + + case 'y': + dlt_name = optarg; + dlt = pcap_datalink_name_to_val(dlt_name); + if (dlt < 0) + error("invalid data link type %s", dlt_name); + break; + +#if defined(HAVE_PCAP_DEBUG) || defined(HAVE_YYDEBUG) case 'Y': { /* Undocumented flag */ +#ifdef HAVE_PCAP_DEBUG + extern int pcap_debug; + pcap_debug = 1; +#else extern int yydebug; yydebug = 1; +#endif } break; #endif - case 'x': - ++xflag; - break; - default: usage(); /* NOTREACHED */ } - if (aflag && nflag) - error("-a and -n options are incompatible"); - if (tflag > 0) thiszone = gmt2local(0); if (RFileName != NULL) { + int dlt; + const char *dlt_name; + +#ifndef WIN32 /* - * We don't need network access, so set it back to the user id. - * Also, this prevents the user from reading anyone's - * trace file. + * We don't need network access, so relinquish any set-UID + * or set-GID privileges we have (if any). + * + * We do *not* want set-UID privileges when opening a + * trace file, as that might let the user read other + * people's trace files (especially if we're set-UID + * root). */ setuid(getuid()); - +#endif /* WIN32 */ pd = pcap_open_offline(RFileName, ebuf); if (pd == NULL) error("%s", ebuf); + dlt = pcap_datalink(pd); + dlt_name = pcap_datalink_val_to_name(dlt); + if (dlt_name == NULL) { + fprintf(stderr, "reading from file %s, link-type %u\n", + RFileName, dlt); + } else { + fprintf(stderr, + "reading from file %s, link-type %s (%s)\n", + RFileName, dlt_name, + pcap_datalink_val_to_description(dlt)); + } localnet = 0; netmask = 0; if (fflag != 0) @@ -322,9 +658,54 @@ main(int argc, char **argv) if (device == NULL) error("%s", ebuf); } +#ifdef WIN32 + if(IsTextUnicode(device, + wcslen((short*)device), // Device always ends with a double \0, so this way to determine its + // length should be always valid + NULL)) + { + fprintf(stderr, "%s: listening on %ws\n", program_name, device); + } + else + { + fprintf(stderr, "%s: listening on %s\n", program_name, device); + } + + fflush(stderr); +#endif /* WIN32 */ + *ebuf = '\0'; pd = pcap_open_live(device, snaplen, !pflag, 1000, ebuf); if (pd == NULL) error("%s", ebuf); + else if (*ebuf) + warning("%s", ebuf); +#ifdef WIN32 + if(UserBufferSize != 1000000) + if(pcap_setbuff(pd, UserBufferSize)==-1){ + error("%s", pcap_geterr(pd)); + } +#endif /* WIN32 */ + if (Lflag) + show_dlts_and_exit(pd); + if (dlt >= 0) { +#ifdef HAVE_PCAP_SET_DATALINK + if (pcap_set_datalink(pd, dlt) < 0) + error("%s", pcap_geterr(pd)); +#else + /* + * We don't actually support changing the + * data link type, so we only let them + * set it to what it already is. + */ + if (dlt != pcap_datalink(pd)) { + error("%s is not one of the DLTs supported by this device\n", + dlt_name); + } +#endif + (void)fprintf(stderr, "%s: data link type %s\n", + program_name, dlt_name); + (void)fflush(stderr); + } i = pcap_snapshot(pd); if (snaplen < i) { warning("snaplen raised from %d to %d", snaplen, i); @@ -338,7 +719,9 @@ main(int argc, char **argv) /* * Let user own process after socket has been opened. */ +#ifndef WIN32 setuid(getuid()); +#endif /* WIN32 */ } if (infile) cmdbuf = read_infile(infile); @@ -349,15 +732,21 @@ main(int argc, char **argv) error("%s", pcap_geterr(pd)); if (dflag) { bpf_dump(&fcode, dflag); + pcap_close(pd); exit(0); } init_addrtoname(localnet, netmask); +#ifndef WIN32 + (void)setsignal(SIGPIPE, cleanup); +#endif /* WIN32 */ (void)setsignal(SIGTERM, cleanup); (void)setsignal(SIGINT, cleanup); /* Cooperate with nohup(1) */ +#ifndef WIN32 if ((oldhandler = setsignal(SIGHUP, cleanup)) != SIG_DFL) (void)setsignal(SIGHUP, oldhandler); +#endif /* WIN32 */ if (pcap_setfilter(pd, &fcode) < 0) error("%s", pcap_geterr(pd)); @@ -365,115 +754,367 @@ 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) { + callback = dump_packet_and_trunc; + dumpinfo.WFileName = WFileName; + dumpinfo.pd = pd; + dumpinfo.p = p; + pcap_userdata = (u_char *)&dumpinfo; + } else { + callback = dump_packet; + pcap_userdata = (u_char *)p; + } } else { - printer = lookup_printer(pcap_datalink(pd)); - pcap_userdata = 0; + type = pcap_datalink(pd); + printinfo.printer = lookup_printer(type); + if (printinfo.printer == NULL) { + dlt_name = pcap_datalink_val_to_name(type); + if (dlt_name != NULL) + error("unsupported data link type %s", dlt_name); + else + error("unsupported data link type %d", type); + } + callback = print_packet; + pcap_userdata = (u_char *)&printinfo; } +#ifdef SIGINFO + (void)setsignal(SIGINFO, requestinfo); +#endif +#ifndef WIN32 if (RFileName == NULL) { - (void)fprintf(stderr, "%s: listening on %s\n", - program_name, device); + int dlt; + const char *dlt_name; + + if (!vflag && !WFileName) { + (void)fprintf(stderr, + "%s: verbose output suppressed, use -v or -vv for full protocol decode\n", + program_name); + } else + (void)fprintf(stderr, "%s: ", program_name); + dlt = pcap_datalink(pd); + dlt_name = pcap_datalink_val_to_name(dlt); + if (dlt_name == NULL) { + (void)fprintf(stderr, "listening on %s, link-type %u, capture size %u bytes\n", + device, dlt, snaplen); + } else { + (void)fprintf(stderr, "listening on %s, link-type %s (%s), capture size %u bytes\n", + device, dlt_name, + pcap_datalink_val_to_description(dlt), snaplen); + } (void)fflush(stderr); } - if (pcap_loop(pd, cnt, printer, pcap_userdata) < 0) { +#endif /* WIN32 */ + status = pcap_loop(pd, cnt, callback, pcap_userdata); + if (WFileName == NULL) { + /* + * We're printing packets. Flush the printed output, + * so it doesn't get intermingled with error output. + */ + if (status == -2) { + /* + * We got interrupted, so perhaps we didn't + * manage to finish a line we were printing. + * Print an extra newline, just in case. + */ + putchar('\n'); + } + (void)fflush(stdout); + } + if (status == -1) { + /* + * Error. Report it. + */ (void)fprintf(stderr, "%s: pcap_loop: %s\n", program_name, pcap_geterr(pd)); - exit(1); + } + if (RFileName == NULL) { + /* + * We're doing a live capture. Report the capture + * statistics. + */ + info(1); } pcap_close(pd); - exit(0); + exit(status == -1 ? 1 : 0); } /* make a clean exit on interrupts */ -RETSIGTYPE -cleanup(int signo) +static RETSIGTYPE +cleanup(int signo _U_) { - struct pcap_stat stat; - - /* Can't print the summary if reading from a savefile */ +#ifdef HAVE_PCAP_BREAKLOOP + /* + * We have "pcap_breakloop()"; use it, so that we do as little + * as possible in the signal handler (it's probably not safe + * to do anything with standard I/O streams in a signal handler - + * the ANSI C standard doesn't say it is). + */ + pcap_breakloop(pd); +#else + /* + * We don't have "pcap_breakloop()"; this isn't safe, but + * it's the best we can do. Print the summary if we're + * not reading from a savefile - i.e., if we're doing a + * live capture - and exit. + */ if (pd != NULL && pcap_file(pd) == NULL) { + /* + * We got interrupted, so perhaps we didn't + * manage to finish a line we were printing. + * Print an extra newline, just in case. + */ + putchar('\n'); (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); +#endif } -/* Like default_print() but data need not be aligned */ -void -default_print_unaligned(register const u_char *cp, register u_int length) +static 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, "%u packets captured", packets_captured); + if (!verbose) + fputs(", ", stderr); + else + putc('\n', stderr); + (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) { - register u_int i, s; - register int nshorts; + unsigned int i; - nshorts = (u_int) length / sizeof(u_short); i = 0; - while (--nshorts >= 0) { - if ((i++ % 8) == 0) - (void)printf("\n\t\t\t"); - s = *cp++; - (void)printf(" %02x%02x", s, *cp++); + do { + s[i++] = n % 10 + '0'; + } while ((n /= 10) > 0); + + s[i] = '\0'; + reverse(s); +} + +static void +dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) +{ + struct dump_info *dump_info; + static uint cnt = 2; + char *name; + + ++packets_captured; + + ++infodelay; + + dump_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 *)dump_info->p) > Cflag) { + /* + * Close the current file and open a new one. + */ + pcap_dump_close(dump_info->p); + if (cnt >= 1000) + error("too many output files"); + name = (char *) malloc(strlen(dump_info->WFileName) + 4); + if (name == NULL) + error("dump_packet_and_trunc: malloc"); + strcpy(name, dump_info->WFileName); + swebitoa(cnt, name + strlen(dump_info->WFileName)); + cnt++; + dump_info->p = pcap_dump_open(dump_info->pd, name); + free(name); + if (dump_info->p == NULL) + error("%s", pcap_geterr(pd)); } - if (length & 1) { - if ((i % 8) == 0) - (void)printf("\n\t\t\t"); - (void)printf(" %02x", *cp); + + pcap_dump((u_char *)dump_info->p, h, sp); +#ifdef HAVE_PCAP_DUMP_FLUSH + if (Uflag) + pcap_dump_flush(dump_info->p); +#endif + + --infodelay; + if (infoprint) + info(0); +} + +static void +dump_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) +{ + ++packets_captured; + + ++infodelay; + + pcap_dump(user, h, sp); +#ifdef HAVE_PCAP_DUMP_FLUSH + if (Uflag) + pcap_dump_flush((pcap_dumper_t *)user); +#endif + + --infodelay; + if (infoprint) + info(0); +} + +static void +print_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) +{ + struct print_info *print_info; + u_int hdrlen; + + ++packets_captured; + + ++infodelay; + ts_print(&h->ts); + + print_info = (struct print_info *)user; + + /* + * Some printers want to check that they're not walking off the + * end of the packet. + * Rather than pass it all the way down, we set this global. + */ + snapend = sp + h->caplen; + + hdrlen = (*print_info->printer)(h, sp); + if (xflag) { + /* + * Print the raw packet data. + */ + if (xflag > 1) { + /* + * Include the link-layer header. + */ + default_print(sp, h->caplen); + } else { + /* + * Don't include the link-layer header - and if + * we have nothing past the link-layer header, + * print nothing. + */ + if (h->caplen > hdrlen) + default_print(sp + hdrlen, + h->caplen - hdrlen); + } } + + putchar('\n'); + + --infodelay; + if (infoprint) + info(0); } +#ifdef WIN32 + /* + * XXX - there should really be libpcap calls to get the version + * number as a string (the string would be generated from #defines + * at run time, so that it's not generated from string constants + * in the library, as, on many UNIX systems, those constants would + * be statically linked into the application executable image, and + * would thus reflect the version of libpcap on the system on + * which the application was *linked*, not the system on which it's + * *running*. + * + * That routine should be documented, unlike the "version[]" + * string, so that UNIX vendors providing their own libpcaps + * don't omit it (as a couple of vendors have...). + * + * Packet.dll should perhaps also export a routine to return the + * version number of the Packet.dll code, to supply the + * "Wpcap_version" information on Windows. + */ + char WDversion[]="current-cvs.tcpdump.org"; + char version[]="current-cvs.tcpdump.org"; + char pcap_version[]="current-cvs.tcpdump.org"; + char Wpcap_version[]="3.0 alpha"; +#endif + /* - * By default, print the packet out in hex. - * - * (BTW, please don't send us patches to print the packet out in ascii) + * By default, print the specified data out in hex. */ void default_print(register const u_char *bp, register u_int length) { - register const u_short *sp; - register u_int i; - register int nshorts; + ascii_print("\n\t", bp, length); /* pass on lf and identation string */ +} - if ((long)bp & 1) { - default_print_unaligned(bp, length); - return; - } - sp = (u_short *)bp; - nshorts = (u_int) length / sizeof(u_short); - i = 0; - while (--nshorts >= 0) { - if ((i++ % 8) == 0) - (void)printf("\n\t\t\t"); - (void)printf(" %04x", ntohs(*sp++)); - } - if (length & 1) { - if ((i % 8) == 0) - (void)printf("\n\t\t\t"); - (void)printf(" %02x", *(u_char *)sp); - } +#ifdef SIGINFO +RETSIGTYPE requestinfo(int signo _U_) +{ + if (infodelay) + ++infoprint; + else + info(0); } +#endif -__dead void +static void usage(void) { extern char version[]; +#ifndef HAVE_PCAP_LIB_VERSION +#if defined(WIN32) || defined(HAVE_PCAP_VERSION) extern char pcap_version[]; +#else /* defined(WIN32) || defined(HAVE_PCAP_VERSION) */ + static char pcap_version[] = "unknown"; +#endif /* defined(WIN32) || defined(HAVE_PCAP_VERSION) */ +#endif /* HAVE_PCAP_LIB_VERSION */ +#ifdef HAVE_PCAP_LIB_VERSION + (void)fprintf(stderr, "%s version %s\n", program_name, version); + (void)fprintf(stderr, "%s\n", pcap_lib_version()); +#else /* HAVE_PCAP_LIB_VERSION */ +#ifdef WIN32 + (void)fprintf(stderr, "%s version %s, based on tcpdump version %s\n", program_name, WDversion, version); + (void)fprintf(stderr, "WinPcap version %s, based on libpcap version %s\n",Wpcap_version, pcap_version); +#else /* WIN32 */ (void)fprintf(stderr, "%s version %s\n", program_name, version); (void)fprintf(stderr, "libpcap version %s\n", pcap_version); +#endif /* WIN32 */ +#endif /* HAVE_PCAP_LIB_VERSION */ + (void)fprintf(stderr, +"Usage: %s [-aAd" D_FLAG "eflLnNOpqRStu" U_FLAG "vxX]" B_FLAG_USAGE " [-c count] [ -C file_size ]\n", program_name); (void)fprintf(stderr, -"Usage: %s [-adeflnNOpqStvx] [-c count] [ -F file ]\n", program_name); +"\t\t[ -E algo:secret ] [ -F file ] [ -i interface ] [ -r file ]\n"); (void)fprintf(stderr, -"\t\t[ -i interface ] [ -r file ] [ -s snaplen ]\n"); +"\t\t[ -s snaplen ] [ -T type ] [ -w file ] [ -y datalinktype ]\n"); (void)fprintf(stderr, -"\t\t[ -T type ] [ -w file ] [ expression ]\n"); - exit(-1); +"\t\t[ expression ]\n"); + exit(1); } diff --git a/kame/kame/tcpdump/telnet.h b/kame/kame/tcpdump/telnet.h new file mode 100644 index 0000000000..da11043019 --- /dev/null +++ b/kame/kame/tcpdump/telnet.h @@ -0,0 +1,348 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/telnet.h,v 1.4 2002/06/11 17:09:01 itojun 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/kame/kame/tcpdump/tests/.cvsignore b/kame/kame/tcpdump/tests/.cvsignore new file mode 100644 index 0000000000..d0012cca21 --- /dev/null +++ b/kame/kame/tcpdump/tests/.cvsignore @@ -0,0 +1,6 @@ +02-sunrise-sunset-esp.pcap +08-sunrise-sunset-esp.pcap +08-sunrise-sunset-esp2.pcap +isakmp-delete-segfault.pcap +isakmp-identification-segfault.pcap +isakmp-pointer-loop.pcap diff --git a/kame/kame/tcpdump/tests/02-sunrise-sunset-esp.puu b/kame/kame/tcpdump/tests/02-sunrise-sunset-esp.puu new file mode 100644 index 0000000000..0ceffc1c1c --- /dev/null +++ b/kame/kame/tcpdump/tests/02-sunrise-sunset-esp.puu @@ -0,0 +1,34 @@ +begin 644 02-sunrise-sunset-esp.pcap +MU,.RH0(`!``````````````&```!``````````````"6````E@```!```&1D +M11```&1D(P@`10``B/]G``!`,O:5P`$"%\`!`BT2-%9X`````4P@12\\L)(1 +MTZ=(S>7($>.<3N@\_I:AY"K/TKAZJP719"NCKYP;PT(0+$"M%=]-X"`*8V.' +M-'$1A]02"3N#OZI#&1R]A*1;`G8S@YFQ]`````(:<$'CW)%VZ',2KQMB@CN?'"^GJ<=: +MD-0`+.V^J'2AK).'XQ_B"B8:[%A_+K[6KS2'XR[UN`,R"BJP?^].ZM#/[$)# +M17^!D"8_[BZ>GU4Z*$7I"N$U*>J47?C-4;I>#`%6+#0%]D75YC']*Z\````` +M`````)8```"6````$```9&1%$```9&0C"`!%``"(_VD``$`R]I/``0(7P`$" +M+1(T5G@````#7?C-4;I>#`%@W%89?QJ#$TJ,4G\FO&HO=F+,,%1E(]);XI]T +MV7W.RY$2=JZ1%!QCNX[;^.JD4W91;7)NJWV2MF4?7`=&_3OWW%V&6RIXKB75 +M#;2TWNL"A:MF!I@_5R^]L6;Z`L?E@1:T&71G``````````"6````E@```!`` +M`&1D11```&1D(P@`10``B/]J``!`,O:2P`$"%\`!`BT2-%9X````!*MF!I@_ +M5R^]%';9*Q:S_B]]O_8FV:2K1A!]/SQHI7>OS815*I?4%/:.=BBJUEGJ(X8\ +MP1E/@&P\9MR)DP3[UCWI@,MR%A$\CR]=G(("[CFB7AUN$AENZOO&\:7% +M2KLW<'NP,L(I=!;8=0``````````E@```)8````0``!D9$40``!D9",(`$4` +M`(C_:P``0#+VD<`!`A?``0(M$C16>`````5NZOO&\:7%2J12,9;LOK"-S,=$ +MO0]X+J(OJQED#PLBRY[\^352UZK&576,Z<:%73AWV3:;Y/:=@(` +M`````````)8```"6````$```9&1%$```9&0C"`!%``"(_VP``$`R]I#``0(7 +MP`$"+1(T5G@````&M,^T?7>6,Z=>N_YZQFV[H1^6\!/I*IMAOHZE\E0M.Z!X +M#[0EG3#>%]7`]*2F?@S4X2''TK09J@NG/.HEXCE./..K^'-@":X[\?0L+B`S +MQA\HTK\'J]:S]N6O`]\)NQD)9;H2P\K`^NX37`R5``````````"6````E@`` +M`!```&1D11```&1D(P@`10``B/]M``!`,O:/P`$"%\`!`BT2-%9X````!^6O +M`]\)NQD)>BYZ>`/DA=N;A2...3-7FZOK?:5KGXBN`/E?$\[-11-$G#E;(>N" +M+<$/YP'SM$>16LU18&Q]9)$]0)/M]:2Z#A6]-,SM*>FI/`X*K-*-:KS3IW<" +MO(>(P(K=:X::SJ;O[J>0K```````````E@```)8````0``!D9$40``!D9",( +M`$4``(C_;@``0#+VCL`!`A?``0(M$C16>`````C3IW<"O(>(P'-43;C[`MCD +M`BMZAX]F!?'Z$8Q"5HYMVDC9"8I^O(Z4!/)`/IVD-(ZK)_52-H2XK+,(-LR) +MM)K#XLF">KY0>C?\[MA%3F%$?ORJ@:>O]5H>?-$OQH)J<9K.^\9N><18TY9Z\!I\S./L8R +MFE53,S6Y5X_Z\(T)ZIUS?X$8>&(_MT1"!SV:VPP!\XU$[3S-5L)4-O"&>]`Z +M1:./61=%C6`6U1/65"A&KUE902]*``````````#.````S@```!```&1D11`` +M`&1D(P@`10``P"E/``!`,LQVP`$"%\`!`BT2-%9X`````CIU^SX%;G^!GUSP +MSA +ML7P6FM81),N>T/1Z'"P7H5;```````````#.````S@```!```&1D11```&1D +M(P@`10``P"E1``!`,LQTP`$"%\`!`BT2-%9X`````R4)-P&F>HPK/?_$MTFC +M^TOO=/L#W_APTK6MIH_BC*I7\L<,9(?/0M"HK3[T3F;(Y2V70$P5?D'7GFIB +MJZ/C",S/BD!9N8GV"\.;GVME[P!@!B1"DT=1W0_75FMI23H!T2^C);4GY>`I +M-2T^O_0_WU&$)&+/P)%[TQUQ-T7G%\RXYJT0HO[$=< +M`@@TL1#(Y980]E*/!^2@G`*&S9O^QMS1S?/`TL=5F9B(12?(145>Y2I+;+T? +MKWUD@&.7U36]K-$[.%9CB*FK^E8>N:K/)4#$]ZO/:=#;MRH-)_139\,W6M4T +M7SQ?BBX>,+A3#BB5^O=>+GKIC-4]5VBP)D-S7-)\W&;<@_J@,*!``````````#.````S@```!```&1D11```&1D(P@`10`` +MP"E5``!`,LQPP`$"%\`!`BT2-%9X````!0OIFA;,@2C4HF3>5!-C(0>5LR0" +M='1\OQ.!-?@D(U0!453"``````````#.````S@```!```&1D11```&1D(P@`10``P"E7 +M``!`,LQNP`$"%\`!`BT2-%9X````!I0M"-THEF=+!L=>A3N,\1+"'Z7(J?O0 +M.B?)(#X=/5F-.">%3.X'(=JKK:WZMN +M=B+^Q3"(KE\1299]=5E,'.&U(`H9N)+>9FS/`CA*>D^>AV.-C(S\)BM&)*XM +M^BF__^<_``````````#.````S@```!```&1D11```&1D(P@`10``P"E9``!` +M,LQLP`$"%\`!`BT2-%9X````!R"SQ'[6%(;Q>>O+]CS6D*+AD3IMC\^MMK8[ +M:T3)KM06!G^.H\>%UAT@)X6JL9\3V.HR"+_Q^_T-O$Y_S":_TP;V,LIV1O]H +M-G@DOL'V-5)O@%<%!#O$2V,AS@W7(&$IX.YKK]\K#>FITU)<>O42T2GKFW+^ +M\/[,>E4P[Q"+7O,Y1(R22LND[H+469(%3,SN&3:U:/I`'&R@<`HKGOV,^#L9,QF%)W^9!VFM +MXG'XY]CWI5VF33?7,*P?6:.PS'&[\N$7W<*==+;P*$./4*OH&=O,6G!JIN>I +M'ZDP*D&4K>SK-\/!7\Z&<&5J4%NU?NRM&25'*_"'UE3VH&?U]/V@932UYZT\ +` +end diff --git a/kame/kame/tcpdump/tests/alltests.sh b/kame/kame/tcpdump/tests/alltests.sh new file mode 100644 index 0000000000..7df25991f1 --- /dev/null +++ b/kame/kame/tcpdump/tests/alltests.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +for i in *.sh +do + if [ "X$i" = "Xalltests.sh" ] + then + continue; + fi + sh ./$i +done + + diff --git a/kame/kame/tcpdump/tests/bgp_vpn_attrset.out b/kame/kame/tcpdump/tests/bgp_vpn_attrset.out new file mode 100644 index 0000000000..c826e7662c --- /dev/null +++ b/kame/kame/tcpdump/tests/bgp_vpn_attrset.out @@ -0,0 +1,18 @@ +IP (tos 0xc0, ttl 62, id 58628, offset 0, flags [none], proto 6, length: 173) 12.4.4.4.2051 > 12.1.1.1.179: P [tcp sum ok] 3293077573:3293077694(121) ack 3348108582 win 16384 : BGP, length: 121 + Update Message (2), length: 121 + Origin (1), length: 1, Flags [T]: IGP + AS Path (2), length: 0, Flags [T]: empty + Local Preference (5), length: 4, Flags [T]: 100 + Extended Community (16), length: 8, Flags [OT]: + target (0x0002), Flags [none]: 300:0.0.1.44 + Attribute Set (128), length: 36, Flags [OT]: + Origin AS: 65001 + Origin (1), length: 1, Flags [T]: IGP + AS Path (2), length: 4, Flags [T]: 5555 + Local Preference (5), length: 4, Flags [T]: 44 + Originator ID (9), length: 4, Flags [O]: 22.5.5.5 + Cluster List (10), length: 4, Flags [O]: 22.5.5.5 + Multi-Protocol Reach NLRI (14), length: 30, Flags [OE]: + AFI: IPv4 (1), SAFI: labeled VPN Unicast (128) + nexthop: RD: 0:0.0.0.0, 12.4.4.4, no SNPA + RD: 500:0.0.1.244, 133.0.0.0/8, label:100208 (bottom) diff --git a/kame/kame/tcpdump/tests/bgp_vpn_attrset.pcap b/kame/kame/tcpdump/tests/bgp_vpn_attrset.pcap new file mode 100644 index 0000000000000000000000000000000000000000..e60aff5c838bf9cd06213d916d83c94b91b111af GIT binary patch literal 217 zcmca|c+)~A1{MYw*ul-fzzO6yS-r5|@|uldBajWk|Ct#ST@Ns 192.168.1.255.netbios-dgm: NBT UDP PACKET(138) +10:17:28.958708 IP 192.168.1.249.netbios-dgm > 192.168.1.255.netbios-dgm: NBT UDP PACKET(138) +10:17:28.959360 IP 192.168.1.249.netbios-dgm > 192.168.1.255.netbios-dgm: NBT UDP PACKET(138) +10:17:28.961018 IP 192.168.1.249.netbios-ns > 192.168.1.255.netbios-ns: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST +10:17:29.710899 IP 192.168.1.249.netbios-ns > 192.168.1.255.netbios-ns: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST +10:17:30.461235 IP 192.168.1.249.netbios-ns > 192.168.1.255.netbios-ns: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST +10:17:30.798408 IP 192.168.1.249.netbios-dgm > 192.168.1.255.netbios-dgm: NBT UDP PACKET(138) +10:17:33.464213 IP 192.168.1.249.netbios-ns > 192.168.1.255.netbios-ns: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST +10:17:34.214302 IP 192.168.1.249.netbios-ns > 192.168.1.255.netbios-ns: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST +10:17:34.964688 IP 192.168.1.249.netbios-ns > 192.168.1.255.netbios-ns: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST +10:17:35.473290 arp who-has 192.168.1.1 tell 192.168.1.249 +10:17:35.481559 arp reply 192.168.1.1 is-at 00:0d:88:4f:25:91 +10:17:35.481577 IP 192.168.1.249.bootpc > 192.168.1.1.bootps: BOOTP/DHCP, Request from 00:04:23:57:a5:7a, length: 300 +10:17:35.622870 EAP code=1 id=0 length=5 +10:17:35.666378 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from 00:04:23:57:a5:7a, length: 300 +10:17:35.851486 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from 00:04:23:57:a5:7a, length: 300 +10:17:36.156548 EAP code=1 id=1 length=0 +10:17:36.158698 EAP code=1 id=0 length=5 +10:17:37.766046 EAP code=1 id=0 length=45 +10:17:37.790625 EAP code=1 id=0 length=20 +10:17:37.830669 EAP code=1 id=0 length=76 +10:17:37.848577 EAP code=1 id=0 length=80 +10:17:38.661939 EAP code=1 id=0 length=28 +10:17:38.685352 EAP code=1 id=0 length=4 +10:17:38.686358 EAP code=1 id=3 length=57 +10:17:38.687182 EAP code=1 id=3 length=44 +10:17:39.852392 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from 00:04:23:57:a5:7a, length: 300 +10:17:46.852719 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from 00:04:23:57:a5:7a, length: 300 +10:18:02.852731 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from 00:04:23:57:a5:7a, length: 300 +10:18:08.689384 EAP code=1 id=1 length=0 +10:18:08.696826 EAP code=1 id=0 length=5 +10:18:08.713116 EAP code=1 id=0 length=45 +10:18:08.787664 EAP code=1 id=0 length=20 +10:18:10.344628 EAP code=1 id=0 length=76 +10:18:10.473292 EAP code=1 id=0 length=80 +10:18:11.152435 EAP code=1 id=0 length=28 +10:18:11.251425 EAP code=1 id=0 length=4 +10:18:11.252509 EAP code=1 id=3 length=57 +10:18:11.253336 EAP code=1 id=3 length=44 +10:18:35.856823 arp who-has 169.254.67.194 tell 169.254.67.194 +10:18:35.885105 arp who-has 169.254.67.194 tell 169.254.67.194 +10:18:36.885304 arp who-has 169.254.67.194 tell 169.254.67.194 +10:18:37.907817 IP 169.254.67.194.4299 > 239.255.255.250.1900: UDP, length 133 +10:18:37.910524 IP 169.254.67.194 > IGMP.MCAST.NET: igmp v3 report, 1 group record(s) +10:18:37.964030 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:38.691974 IP 169.254.67.194 > IGMP.MCAST.NET: igmp v3 report, 1 group record(s) +10:18:38.714004 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:39.464435 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:39.898479 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from 00:04:23:57:a5:7a, length: 300 +10:18:40.214836 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:40.909196 IP 169.254.67.194.4299 > 239.255.255.250.1900: UDP, length 133 +10:18:40.965632 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:41.254259 EAP code=1 id=1 length=0 +10:18:41.256353 EAP code=1 id=0 length=5 +10:18:41.275901 EAP code=1 id=0 length=45 +10:18:41.388857 EAP code=1 id=0 length=20 +10:18:41.715620 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:42.466013 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:42.963175 EAP code=1 id=0 length=76 +10:18:42.987906 EAP code=1 id=0 length=80 +10:18:43.216408 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:43.675053 EAP code=1 id=0 length=28 +10:18:43.695554 EAP code=1 id=0 length=4 +10:18:43.696547 EAP code=1 id=3 length=57 +10:18:43.697368 EAP code=1 id=3 length=44 +10:18:43.899684 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from 00:04:23:57:a5:7a, length: 300 +10:18:43.909719 IP 169.254.67.194.4299 > 239.255.255.250.1900: UDP, length 133 +10:18:43.967353 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:43.967896 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:44.717196 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:44.718161 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:45.467593 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:45.468557 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:46.217980 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:46.218950 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:46.969929 IP 169.254.67.194.netbios-dgm > 169.254.255.255.netbios-dgm: NBT UDP PACKET(138) +10:18:46.970205 IP 169.254.67.194.netbios-dgm > 169.254.255.255.netbios-dgm: NBT UDP PACKET(138) +10:18:48.470207 IP 169.254.67.194.netbios-dgm > 169.254.255.255.netbios-dgm: NBT UDP PACKET(138) +10:18:49.970986 IP 169.254.67.194.netbios-dgm > 169.254.255.255.netbios-dgm: NBT UDP PACKET(138) +10:18:51.471768 IP 169.254.67.194.netbios-dgm > 169.254.255.255.netbios-dgm: NBT UDP PACKET(138) +10:18:52.900388 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from 00:04:23:57:a5:7a, length: 300 +10:18:52.972547 IP 169.254.67.194.netbios-dgm > 169.254.255.255.netbios-dgm: NBT UDP PACKET(138) +10:18:53.972751 IP 169.254.67.194.netbios-dgm > 169.254.255.255.netbios-dgm: NBT UDP PACKET(138) +10:18:54.972939 IP 169.254.67.194.netbios-dgm > 169.254.255.255.netbios-dgm: NBT UDP PACKET(138) +10:18:55.973129 IP 169.254.67.194.netbios-dgm > 169.254.255.255.netbios-dgm: NBT UDP PACKET(138) +10:18:56.973475 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:57.723686 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:58.474079 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:59.224473 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:18:59.974983 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:19:00.725263 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:19:01.475654 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:19:02.226046 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): REGISTRATION; REQUEST; BROADCAST +10:19:02.976511 IP 169.254.67.194.netbios-dgm > 169.254.255.255.netbios-dgm: NBT UDP PACKET(138) +10:19:02.976737 IP 169.254.67.194.netbios-dgm > 169.254.255.255.netbios-dgm: NBT UDP PACKET(138) +10:19:02.977520 IP 169.254.67.194.netbios-dgm > 169.254.255.255.netbios-dgm: NBT UDP PACKET(138) +10:19:02.979092 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST +10:19:03.728840 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST +10:19:04.479238 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST +10:19:07.482218 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST +10:19:08.232205 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST +10:19:08.982597 IP 169.254.67.194.netbios-ns > 169.254.255.255.netbios-ns: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST +10:19:09.900631 IP 0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from 00:04:23:57:a5:7a, length: 300 +10:19:13.696821 EAP code=1 id=1 length=0 +10:19:13.704581 EAP code=1 id=0 length=5 +10:19:13.718221 EAP code=1 id=0 length=45 +10:19:13.734974 EAP code=1 id=0 length=20 +10:19:14.801245 IP 169.254.67.194.netbios-dgm > 169.254.255.255.netbios-dgm: NBT UDP PACKET(138) +10:19:15.293800 EAP code=1 id=0 length=76 +10:19:15.312531 EAP code=1 id=0 length=80 +10:19:15.997763 EAP code=1 id=0 length=28 +10:19:16.022323 EAP code=1 id=0 length=4 +10:19:16.023335 EAP code=1 id=3 length=57 +10:19:16.024149 EAP code=1 id=3 length=44 diff --git a/kame/kame/tcpdump/tests/eapon1.pcap b/kame/kame/tcpdump/tests/eapon1.pcap new file mode 100644 index 0000000000000000000000000000000000000000..4a87ed192bd738424e2f684c2ba3b388f0fd9f6f GIT binary patch literal 16412 zcmeHO3s_Xu7T#xO7+@G)J}}D^EZ+(Pgbsri!!RQ%;K)Gg6%+(~B=WS()KAn*$9!B% zuU*r8m!`K&)2oq+kJJbsn3-S-CTe18shDuRaM#)c%$z|t!vKA8KaStVbIzQz{`0T3 z_gZVe&K=pgUO+^o`lzfVgo6vasMx^w);W<&aE_&t9z^uQ@Xc@85j7#FRu9oAg9is|G{M12^$?ZP^q*1*PXuXHYL!}} z9;{Jog4H1!l}4jcYLsdXJ_%1$>cWD$RDa+T{&ywBq2~54!s=58@+uJm8IA}@2NE5o z92BYx9U2)O6ftzTP7ODM2W$QPbh5#e>;pF01(a+UpRDvAknLD6vdSQ(N~6_i)!{%@ z1;n+Q5IED|JzyL3=a9|Z=tTYldcso6vbW`WO4gG{HeYoa$abnCd&DBkHU`-q)#fBd z%l0s_tfIDMr6jh55M@M=dQhZpU__KwtArQTg`Vh%V$M{(2j>DZ=}|`o4hjWb5zZbO)cp$*7S>{l^=-qkB!IQc-j;>6gkqg& z9IO+bQgR=3fu)uXugRBEELjZ}I*Pm-A47HOjQ7xO)LETWbvlZmp_a5A4};C%udzCL zR8=PeKEbDUb#f+|k0nNDLDESI$sjhI(8Y#0b5WlXM^JZETc)~~QxzPpQGuZvrRuxa zw;DMCR!6mvW!e=K>rmrhY4)mh=S6VBu9GG2!fpSOg7@#vfW~ zs2$;q!#CTFv?cxF4i>{R#BssUF3aqy-xL_G@p*F@R8Z9)l+^=dy$Vemi{UL})Z;?r zD=Fh6Rg5_jOjO)U(=KwHn4IX-Wx!G{lNi6RN-X_qQ=H~~9zRDH@5kBp6`?u@*j8y2 z5(f(p)Uw-bdvl9PPc86XwO|RT-3F{=gX*vQKv|Mrk{XNg>J8*6V6nAmG0qlc;jadZ z9omK#`=H%?T4ieC{9js(n_^-vAGBVX)UG-h_O}buX(HYIJZ1eHIA@`_x2IPpkFs6{ ztD=@WR!CV|UQe}b!`JeXlc?n%gfl&BX&7&`Xql&F7tr$C@dDBsRD*@k7Gcm5vCS!?eLDWghOT>2bodMjc^RZ)sU^C%QS|B+j|O<|(|xjH=LrwTH$qav z=cZkGtK*d9fMta+-esz@ktS-#Rc(P z(6gZBy8@<`Kc`y$0}a}u<(llLUg5MSX!$>EE$^gSe$b+2>ys84X!)17C9H6YkCd-x zcv9%)SsG4J*6J$~RyY;bBb=hRGa_a<^|Caa`hcvLf^1mf)XTbX`r|s6>GyN5`8plz zl-KWX{cJFtB3dqVT#3i`v!hp36b*|ma(L8n;p(k!?kM_$OF|36sWG3T(H}p*2!2}*>04(~f@9enW^zag zr5xDpM3Uhei+Kh_V&!0_OxM?>C}nE}baiox=a9uDZ@r4km0qm+Xmivvn&b4|kH@D1f)-xM5%0=lo8Eerh^MYn4z^v`!QbF1St z>KB4>O>(OhlQ4sQPwgKLzv55)qa}moWw2VX@k;}REE}JoHWu@3ya!rI_Xf8TL|;_M zbW}OeN?bP_NA$m(qr%T8Uo%}yE>)g@uRK|)-pka*)HS1L?qZ6liy4N^^NNs_u;C+d zHyN?o2Hd5ELx(79zn_Seu!-uCu%WoJJ2p>GBie9UOA|Jfm2ivcCQnj3a7|%{2tbeN zz;u(RC_1&8G0-$lEkN|~JDpg`s@A$>RnhHI?^$sr*B`$VSFZ0iMvciTq6u0%vy#ns_0iXdyZ{e92$Yx9;A>89sA z_h49Nh@ida)^);t8&}4}E_0)Ew8-7jGSj_Rb?-{Yh2 zfjVy*$*imMh^`sVM2CfI5J!LKqrU)k-W1)sI*;hz<}%mEU8U$VYS8KWIC~{5d-1`0 zu8WiOVmk3+JTPCBvH_!LvJi9E7-E&?FyTSc}}*7#UN z)}xxMj2ooYrl0LaRl8QEwc`{I6PE_)NnlKt2MT5?(I z=J!y`!XKRosFIdiBefUhCA3OS(C%&SZ&g z_u6YB?KpR5&Sm5m?c3se)oX}I3=lufCVq<&pI}B@0>l+nZK*jD9}UFcy}-2iuax+B zGvf9@JfIm99|Ob(4{hKlISRlT!fZ64`Lx~sF5T~;-8?WmJSl;D= zA%FKL&Bnw5`gMr|Yn1ygMK5d$^s#_m7{Kgy{6^6)HwAh;pywws6MtBU4vGIoKKdrm zyyc1i(=?Ch^NW~vhgBPZUcg7c`K$hA6T8>BHNxEPhOTx3pgX%V?OsaJ^P2)a5zxg! zOuIj%=ogv-eH@@yq%-XftCB$TKl0H_K=UScw^H+nKI=L&Cw@fH`5r#Y%?}*iEBHl? z)ZzOxHbf!WxEoBeWt1%6t7n~70NKELk*(7lO}_gJ$)=VtH$;_FvIA@C6?WzGySxBo zl~rV$?S`nNif_a<`5UTY`ESe}AFyQ%n%K1(RnVO*DTR7feRr~q2Q0fz4y>Ilk11Ah z!?7j+mRQT&q4Qsgb+zGGlK|_}Q7kN2Qj0p|hh{~}Mg73~>M#kg9N%T_2J#nBEPf!i z8cSWlsvG_yiuIG34z1ud8F;lj!0M*@ixG>g!|q2*H`TgsY8q&{6jnbn_8Z_M>TJe@ zpABbY>3loNS_}jAjQs{S^_Xu*aTR?XSo7_vmd>}QgRD#btWAvYBevNAHFcYAV!VG7 zLcn0W2LYi`1~@J1uv;;}X}*bZB>3GZI>1@Ai7^9Iuw}Z4HSL~i-L$*?ogsTlPx>Et zr&Ig0+qrBpPP-%8_eVvnY4@~-O}lH4#!T!gy|Fjy`5j>aX=~;o;#_}c)*8_?XK9vAfwz5!8#Wl4Y%(-%5vj+-H_GZZ%COynz2zdEte-mm!!sRz zIRC}tTg4v~a|dq-a^f{R<{uuFXZO)An}k)%lRR!8@ro_(SD@*3G4Ldcj)Jv?FN0Ua v^7Jhi>10EX3D*P#u?25$@lKlXoAjV)?zyXudAc;I_}|$NFR#k}_|X3V?u9~! literal 0 HcmV?d00001 diff --git a/kame/kame/tcpdump/tests/eapon1.puu b/kame/kame/tcpdump/tests/eapon1.puu new file mode 100644 index 0000000000..25c1436778 --- /dev/null +++ b/kame/kame/tcpdump/tests/eapon1.puu @@ -0,0 +1,368 @@ +begin 644 eapon1.pcap +MU,.RH0(`!````````````/__```!````"%5@0)*@#@#=````W0```/______ +M_P`$(U>E>@@`10``SSB'``"`$7Q.P*@!^<"H`?\`B@"*`+M3[!$.B1W`J`'Y +M`(H`I0``($5%14M&041*1$9&1$1!14M#04-!0T%#04-!0T%#04%!`"!%0D9# +M14-%1D5*1D5&1$5(1D-&1D9!1D%%1D-!0T%!00#_4TU")0`````````````` +M`````````````````````!$```L```````````#H`P``````````"P!6``,` +M`0`!``(`'`!<34%)3%-,3U1<0E)/5U-%``(`1$I0.353,$H`"%5@0/2@#@#= +M````W0```/_______P`$(U>E>@@`10``SSB(``"`$7Q-P*@!^<"H`?\`B@"* +M`+L,\A$.B1[`J`'Y`(H`I0``($5%14M&041*1$9&1$1!14M#04-!0T%#04-! +M0T%#04%!`"!!0D%#1E!&4$5.1D1%0T9#15!&2$9$149&4$9004-!0@#_4TU" +M)0```````````````````````````````````!$```L```````````#H`P`` +M````````"P!6``,``0`!``(`'`!<34%)3%-,3U1<0E)/5U-%``(`1$I0.353 +M,$H`"%5@0("C#@#[````^P```/_______P`$(U>E>@@`10``[3B)``"`$7PN +MP*@!^<"H`?\`B@"*`-E#WA$.B1_`J`'Y`(H`PP``($5%14M&041*1$9&1$1! +M14M#04-!0T%#04-!0T%#04%!`"!!0D%#1E!&4$5.1D1%0T9#15!&2$9$149& +M4$9004-!0@#_4TU")0```````````````````````````````````!$``"D` +M``````````#H`P``````````*0!6``,``0`!``(`.@!<34%)3%-,3U1<0E)/ +M5U-%``P`8.H``$%20D5)5%-'4E504$4``0`#"@`0`(!,_@0#1$I0.353,$H` +M"%5@0/JI#@!<````7````/_______P`$(U>E>@@`10``3CB*``"`$7S,P*@! +M^<"H`?\`B0")`#J"=XDA`1```0```````"!%0D9#14-%1D5*1D5&1$5(1D-& +M1D9!1D%%1D-!0T%"3```(``!"55@0//8"@!<````7````/_______P`$(U>E +M>@@`10``3CB-``"`$7S)P*@!^<"H`?\`B0")`#J"=XDA`1```0```````"!% +M0D9#14-%1D5*1D5&1$5(1D-&1D9!1D%%1D-!0T%"3```(``!"E5@0+,)!P!< +M````7````/_______P`$(U>E>@@`10``3CB.``"`$7S(P*@!^<"H`?\`B0") +M`#J"=XDA`1```0```````"!%0D9#14-%1D5*1D5&1$5(1D-&1D9!1D%%1D-! +M0T%"3```(``!"E5@0,@N#`#S````\P```/_______P`$(U>E>@@`10``Y3B/ +M``"`$7PPP*@!^<"H`?\`B@"*`-'GIA$.B2+`J`'Y`(H`NP``($5%14M&041* +M1$9&1$1!14M#04-!0T%#04-!0T%#04-!`"!%0D9#14-%1D5*1D5&1$5(1D-& +M1D9!1D%%1D-!0T%"3P#_4TU")0`````````````````````````````````` +M`!$``"$```````````#H`P``````````(0!6``,``0````(`,@!<34%)3%-, +M3U1<0E)/5U-%``\`@/P*`$1*4#DU4S!*``!R`&\`10,`7````%P```#_______\`!"-7I7H( +M`$4``$XXE0``@!%\P<"H`?G`J`'_`(D`B0`Z@G")*`$0``$````````@14)& +M0T5#149%2D9%1D1%2$9#1D9&049!149#04-!0DP``"```0Y58$!0N`X`7``` +M`%P```#_______\`!"-7I7H(`$4``$XXE@``@!%\P,"H`?G`J`'_`(D`B0`Z +M@G")*`$0``$````````@14)&0T5#149%2D9%1D1%2$9#1D9&049!149#04-! +M0DP``"```0]58$#*.`<`*@```"H```#_______\`!"-7I7H(!@`!"``&!``! +M``0C5Z5ZP*@!^0```````,"H`0$/56!`%UD'`#P````\``````0C5Z5Z``V( +M3R61"`8``0@`!@0``@`-B$\ED<"H`0$`!"-7I7K`J`'Y```````````````` +M````````#U5@0"E9!P!6`0``5@$````-B$\ED0`$(U>E>@@`10`!2#B7``"` +M$7S#P*@!^<"H`0$`1`!#`31YVP$!!@#(+24]CP&``,"H`?D````````````` +M````!"-7I7H````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M````````````````````````````````````````8X)38S4!!S8$P*@!`3T' +M`0`$(U>E>O\````````````````````````````````````````````````` +M``````]58$`6@0D`/````#P`````!"-7I7H`#,Z(,9J(C@$```4!`0`%`0`` +M```````````````````````````````````````````````/56!`"BL*`%8! +M``!6`0``________``0C5Z5Z"`!%``%(.)\``(`1`0<`````_____P!$`$,! +M-,&K`0$&`)@7ASP````````````````````````````$(U>E>@`````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M``````````````````!C@E-C-0$!=`$!/0E>@@`10`!2#BA``"`$0$%`````/____\`1`!#`32. +MS0$!!@#5`WTN````````````````````````````!"-7I7H````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M````````````````8X)38S4!`70!`3T'`0`$(U>E>C($P*@!^0P(1$I0.353 +M,$H\"$U31E0@-2XP-PL!#P,&+"XO'R'Y*_\``````!!58$"$8P(`$P```!,` +M````#,Z(,9H`!"-7I7J(C@$!````$%5@0.IK`@`\````/``````$(U>E>@`, +MSH@QFHB.`0``!0$"``4!```````````````````````````````````````` +M`````````!%58$!>L`L`/P```#\`````#,Z(,9H`!"-7I7J(C@$``"T"`@`M +M`3$R.34P,C,X,C`P,#4S.3%`;6YC,#(S+FUC8S(Y-2YO=VQA;BYO````7@`````, +MSH@QF@`$(U>E>HB.`0``3`(0`$P2"@``#@L`*#$R.34P,C,X,C`P,#4S.3%` +M;6YC,#(S+FUC8S(Y-2YO=VQA;BYOL.*X:RH)3A8\F +M`ET1,5U'QWV%1Z`@V,N=24.:\=%3TKIE>@`,SH@QFHB.`0,`+`$`#0``0&!5$0"=&X[D=]]>4;W^,JD$U5@0*@!#0!6`0``5@$``/_______P`$(U>E +M>@@`10`!2#BG``"`$0#_`````/____\`1`!#`30ES`$!!@#5`WTN:0$````` +M````````````````````!"-7I7H````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M````````````````````````````````````````````````````````8X)3 +M8S4!`70!`3T'`0`$(U>E>C($P*@!^0P(1$I0.353,$H\"$U31E0@-2XP-PL! +M#P,&+"XO'R'Y*_\``````!I58$#O`@T`5@$``%8!``#_______\`!"-7I7H( +M`$4``4@XKP``@!$`]P````#_____`$0`0P$T)E>@`````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M``````````````````````````````````````````````````!C@E-C-0$! +M=`$!/0E>HB.`0$` +M```P56!`^J$*`#P````\``````0C5Z5Z``S.B#&:B(X!```%`0,`!0$````` +M````````````````````````````````````````````,%5@0)SA"@`_```` +M/P`````,SH@QF@`$(U>E>HB.`0``+0(#`"T!,3(Y-3`R,S@R,#`P-3,Y,4!M +M;F,P,C,N;6-C,CDU+F]W;&%N+F]R9S!58$#0!`P`/````#P`````!"-7I7H` +M#,Z(,9J(C@$``!0!+P`4$@H```\"``(``0``$0$!```````````````````` +M```````````R56!`-$(%`%X```!>``````S.B#&:``0C5Z5ZB(X!``!,`B\` +M3!(*```."P`H,3(Y-3`R,S@R,#`P-3,Y,4!M;F,P,C,N;6-C,CDU+F]W;&%N +M+F]R9P<%``#7H!![\\SE,P[&']$W6C<%$`$``3)58$#,.`<`8@```&(````` +M!"-7I7H`#,Z(,9J(C@$``%`!,`!0$@L```$-```P```````````````````` +M,0```````````````````#(````````````````````+!0``0WL?0G!%;49D +M0(DL@MD'#C-58$!S4P(`+@```"X`````#,Z(,9H`!"-7I7J(C@$``!P",``< +M$@L```L%``!%[_\P8H+&6U!$B#@$)T-",U5@0"'6`P`\````/``````$(U>E +M>@`,SH@QFHB.`0``!`,```0````````````````````````````````````` +M`````````````#-58$!=V@,`2P```$L`````!"-7I7H`#,Z(,9J(C@$#`#D! +M``T``$!@53$`G7]!<++?0.3Y>#A83O[YHHT"0T@&N\)FL/6P9NHATX%BIRI%B`S56!`F-T#`#X````^``````0C5Z5Z``S.B#&:B(X!`P`L +M`0`-``!`8%4Q`)[N$`!R;$K*.XLG`JO9N"A#@XK>5*[_:U"C]E[O?""IR!5+ +M56!`]Q(-`"H````J````________``0C5Z5Z"`8``0@`!@0``0`$(U>E>JG^ +M0\(```````"I_D/"2U5@0'&!#0`J````*@```/_______P`$(U>E>@@&``$( +M``8$``$`!"-7I7JI_D/"````````J?Y#PDQ58$`X@@T`*@```"H```#_____ +M__\`!"-7I7H(!@`!"``&!``!``0C5Z5ZJ?Y#P@```````*G^0\)-56!`*=H- +M`*\```"O`````0!>?__Z``0C5Z5Z"`!%``"A.+X```$1HM.I_D/"[___^A#+ +M!VP`C6+X32U314%20T@@*B!(5%10+S$N,0T*2&]S=#HR,SDN,C4U+C(U-2XR +M-3`Z,3DP,`T*4U0Z=7)N.G-C:&5M87,M=7!N<"UO41E=FEC93HQ#0I-86XZ(G-S9'`Z9&ES8V]V97(B#0I-6#HS +M#0H-"DU58$"\Y`T`-@```#8````!`%X``!8`!"-7I7H(`$8``"@XP````0(> +M.:G^0\+@```6E`0``"(`Z@,````!!````.____I-56!`OK4.`&X```!N```` +M________``0C5Z5Z"`!%``!@.,(``(`1:@RI_D/"J?[__P")`(D`3+4(B2XI +M$``!```````!($5%14M&041*1$9&1$1!14M#04-!0T%#04-!0T%#04%!```@ +M``'`#``@``$`!)/@``9@`*G^0\).56!`!H\*`#8````V`````0!>```6``0C +M5Z5Z"`!&```H.,0```$"'C6I_D/"X```%I0$```B`.H#`````00```#O___Z +M3E5@0!3E"@!N````;@```/_______P`$(U>E>@@`10``8#C%``"`$6H)J?Y# +MPJG^__\`B0")`$RU"(DN*1```0```````2!%145+1D%$2D1&1D1$045+0T%# +M04-!0T%#04-!0T%!00``(``!P`P`(``!``23X``&8`"I_D/"3U5@0#,6!P!N +M````;@```/_______P`$(U>E>@@`10``8#C&``"`$6H(J?Y#PJG^__\`B0") +M`$RU"(DN*1```0```````2!%145+1D%$2D1&1D1$045+0T%#04-!0T%#04-! +M0T%!00``(``!P`P`(``!``23X``&8`"I_D/"3U5@0*^U#0!6`0``5@$``/__ +M_____P`$(U>E>@@`10`!2#C'``"`$0#?`````/____\`1`!#`325:P$!!@"2 +M13E.``"`````````````````````````!"-7I7H````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M````````8X)38S4!`70!`3T'`0`$(U>E>C($P*@!^0P(1$I0.353,$H\"$U3 +M1E0@-2XP-PL!#P,&+"XO'R'Y*_\``````%!58$`T1P,`;@```&X```#_____ +M__\`!"-7I7H(`$4``&`XR```@!%J!JG^0\*I_O__`(D`B0!,M@B)+B@0``$` +M``````$@145%2T9!1$I$1D9$1$%%2T-!0T%#04-!0T%#04-!04$``"```<`, +M`"```0`$D^``!F``J?Y#PE!58$",WPT`KP```*\````!`%Y___H`!"-7I7H( +M`$4``*$XR@```1&BQZG^0\+O___Z$,L';`"-8OA-+5-%05)#2"`J($A45%`O +M,2XQ#0I(;W-T.C(S.2XR-34N,C4U+C(U,#HQ.3`P#0I35#IUE>@@`10``8#C,``"`$6H"J?Y#PJG^__\`B0")`$PP]8DO*1`` +M`0```````2!%0D9#14-%1D5*1D5&1$5(1D-&1D9!1D%%1D-!0T%!00``(``! +MP`P`(``!``23X``&X`"I_D/"455@0#/A`P`3````$P`````,SH@QF@`$(U>E +M>HB.`0$```!156!`8>D#`#P````\``````0C5Z5Z``S.B#&:B(X!```%`00` +M!0$`````````````````````````````````````````````````455@0+TU +M!``_````/P`````,SH@QF@`$(U>E>HB.`0``+0($`"T!,3(Y-3`R,S@R,#`P +M-3,Y,4!M;F,P,C,N;6-C,CDU+F]W;&%N+F]R9U%58$#Y[@4`/````#P````` +M!"-7I7H`#,Z(,9J(C@$``!0!4``4$@H```\"``(``0``$0$!```````````` +M``````````````````!156!`9.L*`&X```!N````________``0C5Z5Z"`!% +M``!@.,T``(`1:@&I_D/"J?[__P")`(D`3##UB2\I$``!```````!($5"1D-% +M0T5&14I&149$14A&0T9&1D%&045&0T%#04%!```@``'`#``@``$`!)/@``;@ +M`*G^0\)256!`71P'`&X```!N````________``0C5Z5Z"`!%``!@.,X``(`1 +M:@"I_D/"J?[__P")`(D`3##UB2\I$``!```````!($5"1D-%0T5&14I&149$ +M14A&0T9&1D%&045&0T%#04%!```@``'`#``@``$`!)/@``;@`*G^0\)256!` +M9[(.`%X```!>``````S.B#&:``0C5Z5ZB(X!``!,`E``3!(*```."P`H,3(Y +M-3`R,S@R,#`P-3,Y,4!M;F,P,C,N;6-C,CDU+F]W;&%N+F]R9P<%```Z)]TL +M?V'JYOR&8?J))U]%$`$``5)58$`"$P\`8@```&(`````!"-7I7H`#,Z(,9J( +MC@$``%`!40!0$@L```$-```P````````````````````,0`````````````` +M`````#(````````````````````+!0``*IFHOZ$\8[TX!>!F]%P6:%-58$!8 +M30,`;@```&X```#_______\`!"-7I7H(`$4``&`XSP``@!%I_ZG^0\*I_O__ +M`(D`B0!,,?6)+R@0``$```````$@14)&0T5#149%2D9%1D1%2$9#1D9&049! +M149#04-!04$``"```<`,`"```0`$D^``!N``J?Y#PE-58$#M3`H`+@```"X` +M````#,Z(,9H`!"-7I7J(C@$``!P"40`<$@L```L%``#BE(K>$<9]M,I(_@G, +MC).Y4U5@0`*="@`\````/``````$(U>E>@`,SH@QFHB.`0``!`,```0````` +M`````````````````````````````````````````````%-58$#CH`H`2P`` +M`$L`````!"-7I7H`#,Z(,9J(C@$#`#D!``T``$!@55(`GZN0MGOEA8[@4WO* +M&_11@$@"&2ZIH`.YHY==8)$_%6#R:U/Z"F'14BLDK,Z)I:%356!`&*0*`#X` +M```^``````0C5Z5Z``S.B#&:B(X!`P`L`0`-``!`8%52`*!&UK1?KE>@`````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M``!C@E-C-0$!=`$!/0E>@@`10``H3C2```!$:*_J?Y#PN____H0RP=L`(UB^$TM4T5!4D-(("H@ +M2%144"\Q+C$-"DAOE>@@`10``SSCF``"` +M$6EYJ?Y#PJG^__\`B@"*`+L)/1$.B3:I_D/"`(H`I0``($5%14M&041*1$9& +M1$1!14M#04-!0T%#04-!0T%#04%!`"!%0D9#14-%1D5*1D5&1$5(1D-&1D9! +M1D%%1D-!0T%"3@#_4TU")0```````````````````````````````````!$` +M``L```````````#H`P``````````"P!6``,``0`!``(`'`!<34%)3%-,3U1< +M0E)/5U-%``(`1$I0.353,$H`655@0.K0#@#=````W0```/_______P`$(U>E +M>@@`10``SSCG``"`$6EXJ?Y#PJG^__\`B@"*`+L)/!$.B3>I_D/"`(H`I0`` +M($5%14M&041*1$9&1$1!14M#04-!0T%#04-!0T%#04%!`"!%0D9#14-%1D5* +M1D5&1$5(1D-&1D9!1D%%1D-!0T%"3@#_4TU")0`````````````````````` +M`````````````!$```L```````````#H`P``````````"P!6``,``0`!``(` +M'`!<34%)3%-,3U1<0E)/5U-%``(`1$I0.353,$H`6U5@0-@R!P#=````W0`` +M`/_______P`$(U>E>@@`10``SSCH``"`$6EWJ?Y#PJG^__\`B@"*`+L).Q$. +MB3BI_D/"`(H`I0``($5%14M&041*1$9&1$1!14M#04-!0T%#04-!0T%#04%! +M`"!%0D9#14-%1D5*1D5&1$5(1D-&1D9!1D%%1D-!0T%"3@#_4TU")0`````` +M`````````````````````````````!$```L```````````#H`P`````````` +M"P!6``,``0`!``(`'`!<34%)3%-,3U1<0E)/5U-%``(`1$I0.353,$H`7%5@ +M0"2]#0!6`0``5@$``/_______P`$(U>E>@@`10`!2#CI``"`$0"]`````/__ +M__\`1`!#`31L:@$!!@"213E.*0&`````````````````````````!"-7I7H` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M````````````````````````````8X)38S4!`70!`3T'`0`$(U>E>C($P*@! +M^0P(1$I0.353,$H\"$U31E0@-2XP-PL!#P,&+"XO'R'Y*_\``````%Q58$`# +MUPX`Z0```.D```#_______\`!"-7I7H(`$4``-LXZ@``@!%I::G^0\*I_O__ +M`(H`B@#';@L1#HDYJ?Y#P@"*`+$``"!%145+1D%$2D1&1D1$045+0T%#04-! +M0T%#04-!0T%!00`@14)&0T5#149%2D9%1D1%2$9#1D9&049!149#04-!0D\` +M_U--0B4````````````````````````````````````1```7```````````` +MZ`,``````````!<`5@`#``$``0`"`"@`7$U!24Q33$]47$)23U=310`(`2`/ +M`1!9L1D5`````$1*4#DU4S!*`%U58$#/UPX`Z0```.D```#_______\`!"-7 +MI7H(`$4``-LXZP``@!%I:*G^0\*I_O__`(H`B@#';@H1#HDZJ?Y#P@"*`+$` +M`"!%145+1D%$2D1&1D1$045+0T%#04-!0T%#04-!0T%!00`@14)&0T5#149% +M2D9%1D1%2$9#1D9&049!149#04-!0D\`_U--0B4````````````````````` +M```````````````1```7````````````Z`,``````````!<`5@`#``$``0`" +M`"@`7$U!24Q33$]47$)23U=310`(`2`/`1!9L1D5`````$1*4#DU4S!*`%Y5 +M8$"+V`X`Z0```.D```#_______\`!"-7I7H(`$4``-LX[```@!%I9ZG^0\*I +M_O__`(H`B@#';@D1#HD[J?Y#P@"*`+$``"!%145+1D%$2D1&1D1$045+0T%# +M04-!0T%#04-!0T%!00`@14)&0T5#149%2D9%1D1%2$9#1D9&049!149#04-! +M0D\`_U--0B4````````````````````````````````````1```7```````` +M````Z`,``````````!<`5@`#``$``0`"`"@`7$U!24Q33$]47$)23U=310`( +M`2`/`1!9L1D5`````$1*4#DU4S!*`%]58$!)V0X`Z0```.D```#_______\` +M!"-7I7H(`$4``-LX[0``@!%I9JG^0\*I_O__`(H`B@#';@@1#HD\J?Y#P@"* +M`+$``"!%145+1D%$2D1&1D1$045+0T%#04-!0T%#04-!0T%!00`@14)&0T5# +M149%2D9%1D1%2$9#1D9&049!149#04-!0D\`_U--0B4````````````````` +M```````````````````1```7````````````Z`,``````````!<`5@`#``$` +M`0`"`"@`7$U!24Q33$]47$)23U=310`(`2`/`1!9L1D5`````$1*4#DU4S!* +M`&!58$"CV@X`;@```&X```#_______\`!"-7I7H(`$4``&`X[@``@!%IX*G^ +M0\*I_O__`(D`B0!,H^:)/2D0``$```````$@14)&0T5#149%2D9%1D1%2$9# +M1D9&049!149#04-!0DX``"```<`,`"```0`$D^``!F``J?Y#PF%58$#F"@L` +M;@```&X```#_______\`!"-7I7H(`$4``&`X[P``@!%IWZG^0\*I_O__`(D` +MB0!,H^:)/2D0``$```````$@14)&0T5#149%2D9%1D1%2$9#1D9&049!149# +M04-!0DX``"```<`,`"```0`$D^``!F``J?Y#PF)58$#?.P<`;@```&X```#_ +M______\`!"-7I7H(`$4``&`X\```@!%IWJG^0\*I_O__`(D`B0!,H^:)/2D0 +M``$```````$@14)&0T5#149%2D9%1D1%2$9#1D9&049!149#04-!0DX``"`` +M`<`,`"```0`$D^``!F``J?Y#PF-58$#9;`,`;@```&X```#_______\`!"-7 +MI7H(`$4``&`X\P``@!%IVZG^0\*I_O__`(D`B0!,I.:)/2@0``$```````$@ +M14)&0T5#149%2D9%1D1%2$9#1D9&049!149#04-!0DX``"```<`,`"```0`$ +MD^``!F``J?Y#PF-58$"'X`X`;@```&X```#_______\`!"-7I7H(`$4``&`X +M]```@!%IVJG^0\*I_O__`(D`B0!,Z>R)/BD0``$```````$@04)!0T901E!% +M3D9$14-&0T501DA&1$5&1E!&4$%#04(``"```<`,`"```0`$D^``!N``J?Y# +MPF158$`/$0L`;@```&X```#_______\`!"-7I7H(`$4``&`X]0``@!%IV:G^ +M0\*I_O__`(D`B0!,Z>R)/BD0``$```````$@04)!0T901E!%3D9$14-&0T50 +M1DA&1$5&1E!&4$%#04(``"```<`,`"```0`$D^``!N``J?Y#PF558$`&0@<` +M;@```&X```#_______\`!"-7I7H(`$4``&`X]@``@!%IV*G^0\*I_O__`(D` +MB0!,Z>R)/BD0``$```````$@04)!0T901E!%3D9$14-&0T501DA&1$5&1E!& +M4$%#04(``"```<`,`"```0`$D^``!N``J?Y#PF958$#^<@,`;@```&X```#_ +M______\`!"-7I7H(`$4``&`X]P``@!%IUZG^0\*I_O__`(D`B0!,ZNR)/B@0 +M``$```````$@04)!0T901E!%3D9$14-&0T501DA&1$5&1E!&4$%#04(``"`` +M`<`,`"```0`$D^``!N``J?Y#PF958$!_Y@X`W0```-T```#_______\`!"-7 +MI7H(`$4``,\X^```@!%I9ZG^0\*I_O__`(H`B@"[%C41#HD_J?Y#P@"*`*4` +M`"!%145+1D%$2D1&1D1$045+0T%#04-!0T%#04-!0T%!00`@14)&0T5#149% +M2D9%1D1%2$9#1D9&049!149#04-!04$`_U--0B4````````````````````` +M```````````````1```+````````````Z`,```````````L`5@`#``$``0`" +M`!P`7$U!24Q33$]47$)23U=310`"`$1*4#DU4S!*`&958$!AYPX`W0```-T` +M``#_______\`!"-7I7H(`$4``,\X^0``@!%I9JG^0\*I_O__`(H`B@"[SSH1 +M#HE`J?Y#P@"*`*4``"!%145+1D%$2D1&1D1$045+0T%#04-!0T%#04-!0T%! +M00`@04)!0T901E!%3D9$14-&0T501DA&1$5&1E!&4$%#04(`_U--0B4````` +M```````````````````````````````1```+````````````Z`,````````` +M``L`5@`#``$``0`"`!P`7$U!24Q33$]47$)23U=310`"`$1*4#DU4S!*`&95 +M8$!PZ@X`^P```/L```#_______\`!"-7I7H(`$4``.TX^@``@!%I1ZG^0\*I +M_O__`(H`B@#9)2,1#HE!J?Y#P@"*`,,``"!%145+1D%$2D1&1D1$045+0T%# +M04-!0T%#04-!0T%!00`@04)!0T901E!%3D9$14-&0T501DA&1$5&1E!&4$%# +M04(`_U--0B4````````````````````````````````````1```I```````` +M````Z`,``````````"D`5@`#``$``0`"`#H`7$U!24Q33$]47$)23U=310`, +M`&#J``!!4D)%25131U)54%!%``$``PH`$`"`;/[%!D1*4#DU4S!*`&958$"4 +M\`X`7````%P```#_______\`!"-7I7H(`$4``$XX^P``@!%IY:G^0\*I_O__ +M`(D`B0`Z;]^)0P$0``$````````@14)&0T5#149%2D9%1D1%2$9#1D9&049! +M149#04-!0DP``"```6=58$`('PL`7````%P```#_______\`!"-7I7H(`$4` +M`$XX_```@!%IY*G^0\*I_O__`(D`B0`Z;]^)0P$0``$````````@14)&0T5# +M149%2D9%1D1%2$9#1D9&049!149#04-!0DP``"```6A58$`&4`<`7````%P` +M``#_______\`!"-7I7H(`$4``$XX_0``@!%IXZG^0\*I_O__`(D`B0`Z;]^) +M0P$0``$````````@14)&0T5#149%2D9%1D1%2$9#1D9&049!149#04-!0DP` +M`"```6M58$"J6P<`7````%P```#_______\`!"-7I7H(`$4``$XY`0``@!%I +MWZG^0\*I_O__`(D`B0`Z;]N)1P$0``$````````@14)&0T5#149%2D9%1D1% +M2$9#1D9&049!149#04-!0DP``"```6Q58$`-BP,`7````%P```#_______\` +M!"-7I7H(`$4``$XY`@``@!%IWJG^0\*I_O__`(D`B0`Z;]N)1P$0``$````` +M```@14)&0T5#149%2D9%1D1%2$9#1D9&049!149#04-!0DP``"```6Q58$!% +M_@X`7````%P```#_______\`!"-7I7H(`$4``$XY!```@!%IW*G^0\*I_O__ +M`(D`B0`Z;]N)1P$0``$````````@14)&0T5#149%2D9%1D1%2$9#1D9&049! +M149#04-!0DP``"```6U58$`7O@T`5@$``%8!``#_______\`!"-7I7H(`$4` +M`4@Y!@``@!$`H`````#_____`$0`0P$T;&H!`08`DD4Y3BD!@``````````` +M``````````````0C5Z5Z```````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M`````````````````````````````````````````````````&."4V,U`0%T +M`0$]!P$`!"-7I7HR!,"H`?D,"$1*4#DU4S!*/`A-4T94(#4N,#<+`0\#!BPN +M+Q\A^2O_``````!Q56!`]:$*`!,````3``````S.B#&:``0C5Z5ZB(X!`0`` +M`'%58$!%P`H`/````#P`````!"-7I7H`#,Z(,9J(C@$```4!!0`%`0`````` +M``````````````````````````````````````````!Q56!`C?4*`#\````_ +M``````S.B#&:``0C5Z5ZB(X!```M`@4`+0$Q,CDU,#(S.#(P,#`U,SDQ0&UN +M8S`R,RYM8V,R.34N;W=L86XN;W)G<55@0/XV"P`\````/``````$(U>E>@`, +MSH@QFHB.`0``%`%P`!02"@``#P(``@`!```1`0$````````````````````` +M`````````')58$#=.0P`\P```/,```#_______\`!"-7I7H(`$4``.4Y#``` +M@!%I/:G^0\*I_O__`(H`B@#1\^D1#HE*J?Y#P@"*`+L``"!%145+1D%$2D1& +M1D1$045+0T%#04-!0T%#04-!0T%#00`@14)&0T5#149%2D9%1D1%2$9#1D9& +M049!149#04-!0D\`_U--0B4````````````````````````````````````1 +M```A````````````Z`,``````````"$`5@`#``$````"`#(`7$U!24Q33$]4 +M7$)23U=310`/`(#\"@!$2E`Y-5,P2@``60!<`%4`!0$#$`4`#P%5J@!S56!` +MJ'L$`%X```!>``````S.B#&:``0C5Z5ZB(X!``!,`G``3!(*```."P`H,3(Y +M-3`R,S@R,#`P-3,Y,4!M;F,P,C,N;6-C,CDU+F]W;&%N+F]R9P<%```)[DNV +M]E>@`,SH@QFHB.`0`` +M!`,```0``````````````````````````````````````````````````'15 +M8$`G6P``2P```$L`````!"-7I7H`#,Z(,9J(C@$#`#D!``T``$!@57(`H7=G +MF]`L&:EKBMN@`6*6Y2?^.:F>V`$/C@ +M9C@```$!"`H974FMBM15+Q!58$!QG`8`8````.L`````"]N0_0(`X$]@<4 +M5(X`:)P-"Q0`8$$!L&:EKA4C@<4`/I,<`$5`/+M5G/\`0<0G:=Q]S4< +MM*"$``/81;I[5@?]ZP9J6N%2.!Q0`RHLB`18`PB*WG4W^01LM]B4XN&`' +M6E(!*C$R.34P,C,X,C`P,#4S.3%`;6YC,#(S+FUC8S(Y-2YO$55@0!P&!0!@ +M````!@$`````#`>LA0`+VY#]`@@`10``^``"0`!`$0RDP9J6N-6!_WH'%%2. +M`.2>DP(6`-P04TN>&O"\WL%@,.`1V142"`;____^#`8```)`!@8````"&CH` +M``$W$32`+U<1;LS62B]58$!:H@8`8````.L`````"]N0_0(`X$]@M>A=G +MB0$J,3(Y-3`R,S@R,#`P-3,Y,4!M;F,P,C,N;6-C,CDU+F\O56!`G*<&`&`` +M``"*```````,!ZR%``O;D/T""`!%``!\``-``$`1#1_!FI:XU8'_>@<45(X` +M:#L&:EKA4C@<4`/H2$P$9`/)6HP7H8R0(O +M*"8``/81;IG5@?]ZP9J6N%2.!Q0`R@WC`1H`PCS/?&QHIT8SX.[2#=[S68H! +M*C$R.34P,C,X,C`P,#4S.3%`;6YC,#(S+FUC8S(Y-2YO,55@0#VS#0!@```` +M!@$`````#`>LA0`+VY#]`@@`10``^``%0`!`$0RAP9J6N-6!_WH'%%2.`.3B +MMP(:`-S*Z(?9H34)&AB0":D9@<45(X`:#0% +M"QL`8(N:^N5L(EK&#H6-':U$XV((!O____X,!@```D`&!@````)/%@%0`!02 +M"@``#P(``@`!455@0*VL"0!@````'`$````+VY#]`@#@3UR$8`@`10`!#B@I +M``#V$6YFU8'_>L&:EKA4C@<4`/KDFP$<`/+H$R8P9(B"W[^G<4!"HKQ+`2HQ +M,CDU,#(S.#(P,#`U,SDQ0&UN8S`R,RYM8V,R.34N;U%58$"ZL@D`8````,8` +M``````P'K(4`"]N0_0((`$4``+@`!T``0!$,W\&:EKC5@?]Z!Q14C@"DI=@+ +M'`";*!>&FY;C?2/)T74`@&_____@P&```"0`8&`````D]2`5$`4!(+ +M```!#0``,`!256!`@SL%`&````#L``````O;D/T"`.!/7(1@"`!%``#>*"H` +M`/81;I75@?]ZP9J6N%2.!Q0`RI"T`1T`PE:^P6JH@]U$D*!C#8CO0UP!*C$R +M.34P,C,X,C`P,#4S.3%`;6YC,#(S+FUC8S(Y-2YO4E5@0'M`!0!@````!@$` +M````#`>LA0`+VY#]`@@`10``^``(0`!`$0R>P9J6N-6!_WH'%%2.`.2<&@(= +M`-P&]WGHNB++Z0K&A"^B<2S/"`;____^#`8```)`!@8````"&CH```$W$32F +M=DT@&\D[/G!58$!OW04`8````.L`````"]N0_0(`X$]AS"W^P0$J,3(Y +M-3`R,S@R,#`P-3,Y,4!M;F,P,C,N;6-C,CDU+F]P56!`L>(%`&````"*```` +M```,!ZR%``O;D/T""`!%``!\``E``$`1#1G!FI:XU8'_>@<45(X`:`.V"QX` +M8+P/!*Y!RZ>(/:C.%/A62\((!O____X,!@```D`&!@````)/%@%P`!02"@`` +M#P(``@`!<55@0)*H#@!@````'`$````+VY#]`@#@3UR$8`@`10`!#B@L``#V +M$6YCU8'_>L&:EKA4C@<4`/JLH@$?`/*.M".D<>M4,KL=.(:"[-F;`2HQ,CDU +M,#(S.#(P,#`U,SDQ0&UN8S`R,RYM8V,R.34N;W%58$#$K@X`8````,8````` +M``P'K(4`"]N0_0((`$4``+@`"D``0!$,W,&:EKC5@?]Z!Q14C@"DK7D+'P"< +MMWVPJO:XC`JEY#15<5U0Z@@&_____@P&```"0`8&`````D]2`7$`4!(+```! +M#0``,`!R56!`S#4*`&````#L``````O;D/T"`.!/7(1@"`!%``#>*"T``/81 +M;I+5@?]ZP9J6N%2.!Q0`RE>1`2``PK+"]?UCV]G1I<-+X16?0+L!*C$R.34P +M,C,X,C`P,#4S.3%`;6YC,#(S+FUC8S(Y-2YOLA0`+VY#]`@@`10``^``+0`!`$0R;P9J6N-6!_WH'%%2.`.1M%P(@`-PJ +M=?H'6<1=UD&:FRVA,V+S"`;____^#`8```)`!@8````"&CH```$W$32RVRE= +$I%P\00`` +` +end diff --git a/kame/kame/tcpdump/tests/esp-secrets.txt b/kame/kame/tcpdump/tests/esp-secrets.txt new file mode 100644 index 0000000000..e5bb2262cd --- /dev/null +++ b/kame/kame/tcpdump/tests/esp-secrets.txt @@ -0,0 +1,5 @@ +# a comment + +0x12345678@192.1.2.45 3des-cbc-hmac96:0x43434545464649494a4a4c4c4f4f51515252545457575840 +0xabcdabcd@192.0.1.1 3des-cbc-hmac96:0x434545464649494a4a4c4c4f4f5151525254545757584043 + diff --git a/kame/kame/tcpdump/tests/esp0.out b/kame/kame/tcpdump/tests/esp0.out new file mode 100644 index 0000000000..701da2b901 --- /dev/null +++ b/kame/kame/tcpdump/tests/esp0.out @@ -0,0 +1,8 @@ +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x1) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x2) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x3) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x4) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x5) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x6) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x7) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x8) diff --git a/kame/kame/tcpdump/tests/esp0.sh b/kame/kame/tcpdump/tests/esp0.sh new file mode 100644 index 0000000000..daf407c441 --- /dev/null +++ b/kame/kame/tcpdump/tests/esp0.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +echo -n test esp0... +uudecode 02-sunrise-sunset-esp.puu +if (../tcpdump -t -n -r 02-sunrise-sunset-esp.pcap | diff - esp0.out) +then + echo passed. +else + echo failed. +fi + + diff --git a/kame/kame/tcpdump/tests/esp1.gdbinit b/kame/kame/tcpdump/tests/esp1.gdbinit new file mode 100644 index 0000000000..6c8ae890cb --- /dev/null +++ b/kame/kame/tcpdump/tests/esp1.gdbinit @@ -0,0 +1 @@ +set args -t -n -E "0x12345678@192.1.2.45 3des-cbc-hmac96:0x4043434545464649494a4a4c4c4f4f515152525454575758" -r 02-sunrise-sunset-esp.pcap diff --git a/kame/kame/tcpdump/tests/esp1.out b/kame/kame/tcpdump/tests/esp1.out new file mode 100644 index 0000000000..b8a2c7c982 --- /dev/null +++ b/kame/kame/tcpdump/tests/esp1.out @@ -0,0 +1,8 @@ +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x1): 192.0.2.1 > 192.0.1.1: icmp 64: echo request seq 1280 (DF) (ipip-proto-4) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x2): 192.0.2.1 > 192.0.1.1: icmp 64: echo request seq 1536 (DF) (ipip-proto-4) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x3): 192.0.2.1 > 192.0.1.1: icmp 64: echo request seq 1792 (DF) (ipip-proto-4) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x4): 192.0.2.1 > 192.0.1.1: icmp 64: echo request seq 2048 (DF) (ipip-proto-4) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x5): 192.0.2.1 > 192.0.1.1: icmp 64: echo request seq 2304 (DF) (ipip-proto-4) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x6): 192.0.2.1 > 192.0.1.1: icmp 64: echo request seq 2560 (DF) (ipip-proto-4) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x7): 192.0.2.1 > 192.0.1.1: icmp 64: echo request seq 2816 (DF) (ipip-proto-4) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x8): 192.0.2.1 > 192.0.1.1: icmp 64: echo request seq 3072 (DF) (ipip-proto-4) diff --git a/kame/kame/tcpdump/tests/esp1.sh b/kame/kame/tcpdump/tests/esp1.sh new file mode 100644 index 0000000000..791f22771e --- /dev/null +++ b/kame/kame/tcpdump/tests/esp1.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +uudecode 02-sunrise-sunset-esp.puu + +echo -n test esp1... +if (../tcpdump -t -n -E "0x12345678@192.1.2.45 3des-cbc-hmac96:0x4043434545464649494a4a4c4c4f4f515152525454575758" -r 02-sunrise-sunset-esp.pcap | diff - esp1.out) +then + echo passed. +else + echo failed. +fi + diff --git a/kame/kame/tcpdump/tests/esp2.gdbinit b/kame/kame/tcpdump/tests/esp2.gdbinit new file mode 100644 index 0000000000..7c18407586 --- /dev/null +++ b/kame/kame/tcpdump/tests/esp2.gdbinit @@ -0,0 +1 @@ +set args -t -n -E "0x12345678@192.1.2.45 3des-cbc-hmac96:0x43434545464649494a4a4c4c4f4f51515252545457575840,0xabcdabcd@192.0.1.1 3des-cbc-hmac96:0x434545464649494a4a4c4c4f4f5151525254545757584043" -r 08-sunrise-sunset-esp2.pcap diff --git a/kame/kame/tcpdump/tests/esp2.out b/kame/kame/tcpdump/tests/esp2.out new file mode 100644 index 0000000000..bf7c480293 --- /dev/null +++ b/kame/kame/tcpdump/tests/esp2.out @@ -0,0 +1,8 @@ +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x1): 192.1.2.23 > 192.0.1.1: ESP(spi=0xabcdabcd,seq=0x1): 192.0.2.1 > 192.0.1.1: icmp 64: echo request seq 1280 (DF) (ipip-proto-4) (ipip-proto-4) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x2): 192.1.2.23 > 192.0.1.1: ESP(spi=0xabcdabcd,seq=0x2): 192.0.2.1 > 192.0.1.1: icmp 64: echo request seq 1536 (DF) (ipip-proto-4) (ipip-proto-4) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x3): 192.1.2.23 > 192.0.1.1: ESP(spi=0xabcdabcd,seq=0x3): 192.0.2.1 > 192.0.1.1: icmp 64: echo request seq 1792 (DF) (ipip-proto-4) (ipip-proto-4) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x4): 192.1.2.23 > 192.0.1.1: ESP(spi=0xabcdabcd,seq=0x4): 192.0.2.1 > 192.0.1.1: icmp 64: echo request seq 2048 (DF) (ipip-proto-4) (ipip-proto-4) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x5): 192.1.2.23 > 192.0.1.1: ESP(spi=0xabcdabcd,seq=0x5): 192.0.2.1 > 192.0.1.1: icmp 64: echo request seq 2304 (DF) (ipip-proto-4) (ipip-proto-4) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x6): 192.1.2.23 > 192.0.1.1: ESP(spi=0xabcdabcd,seq=0x6): 192.0.2.1 > 192.0.1.1: icmp 64: echo request seq 2560 (DF) (ipip-proto-4) (ipip-proto-4) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x7): 192.1.2.23 > 192.0.1.1: ESP(spi=0xabcdabcd,seq=0x7): 192.0.2.1 > 192.0.1.1: icmp 64: echo request seq 2816 (DF) (ipip-proto-4) (ipip-proto-4) +192.1.2.23 > 192.1.2.45: ESP(spi=0x12345678,seq=0x8): 192.1.2.23 > 192.0.1.1: ESP(spi=0xabcdabcd,seq=0x8): 192.0.2.1 > 192.0.1.1: icmp 64: echo request seq 3072 (DF) (ipip-proto-4) (ipip-proto-4) diff --git a/kame/kame/tcpdump/tests/esp2.sh b/kame/kame/tcpdump/tests/esp2.sh new file mode 100644 index 0000000000..fa85b5b445 --- /dev/null +++ b/kame/kame/tcpdump/tests/esp2.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +uudecode 08-sunrise-sunset-esp2.puu + +echo -n test esp2... +if (../tcpdump -t -n -E "0x12345678@192.1.2.45 3des-cbc-hmac96:0x43434545464649494a4a4c4c4f4f51515252545457575840,0xabcdabcd@192.0.1.1 3des-cbc-hmac96:0x434545464649494a4a4c4c4f4f5151525254545757584043" -r 08-sunrise-sunset-esp2.pcap | diff - esp2.out) +then + echo passed. +else + echo failed. +fi + diff --git a/kame/kame/tcpdump/tests/esp3.gdbinit b/kame/kame/tcpdump/tests/esp3.gdbinit new file mode 100644 index 0000000000..71501187a2 --- /dev/null +++ b/kame/kame/tcpdump/tests/esp3.gdbinit @@ -0,0 +1 @@ +set args -t -n -E "3des-cbc-hmac96:0x43434545464649494a4a4c4c4f4f51515252545457575840" -r 08-sunrise-sunset-esp2.pcap diff --git a/kame/kame/tcpdump/tests/esp3.sh b/kame/kame/tcpdump/tests/esp3.sh new file mode 100644 index 0000000000..ffb303fce0 --- /dev/null +++ b/kame/kame/tcpdump/tests/esp3.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +uudecode 02-sunrise-sunset-esp.puu +echo -n test esp3... +if ( ../tcpdump -t -n -E "3des-cbc-hmac96:0x4043434545464649494a4a4c4c4f4f515152525454575758" -r 02-sunrise-sunset-esp.pcap | diff - esp1.out) +then + echo passed. +else + echo failed. +fi + diff --git a/kame/kame/tcpdump/tests/esp4.gdbinit b/kame/kame/tcpdump/tests/esp4.gdbinit new file mode 100644 index 0000000000..8007444b74 --- /dev/null +++ b/kame/kame/tcpdump/tests/esp4.gdbinit @@ -0,0 +1,2 @@ +set args -t -n -E "file esp-secrets.txt" -r 08-sunrise-sunset-esp2.pcap + diff --git a/kame/kame/tcpdump/tests/esp4.sh b/kame/kame/tcpdump/tests/esp4.sh new file mode 100644 index 0000000000..f3a911769e --- /dev/null +++ b/kame/kame/tcpdump/tests/esp4.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +uudecode 08-sunrise-sunset-esp2.puu + +echo -n test esp2... +if (../tcpdump -t -n -E "file esp-secrets.txt" -r 08-sunrise-sunset-esp2.pcap | diff - esp2.out) +then + echo passed. +else + echo failed. +fi + diff --git a/kame/kame/tcpdump/tests/isakmp-delete-segfault.puu b/kame/kame/tcpdump/tests/isakmp-delete-segfault.puu new file mode 100644 index 0000000000..11512b1284 --- /dev/null +++ b/kame/kame/tcpdump/tests/isakmp-delete-segfault.puu @@ -0,0 +1,20 @@ +begin 644 isakmp-delete-segfault.pcap +MU,.RH0(`!``````````````$```!````@"X```````"I`@``J0(``/______ +M_P$!`0$!`0@`10``I@`O0`!`$3PA?P```7\```$!]`'T`<@``!N3$,+\/7K^ +M3SF!FR'H6?T,OKXN&YH=5T,AEYH%R@(@71+C65#___\````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +!```` +` +end diff --git a/kame/kame/tcpdump/tests/isakmp-identification-segfault.puu b/kame/kame/tcpdump/tests/isakmp-identification-segfault.puu new file mode 100644 index 0000000000..6f0ae0e8db --- /dev/null +++ b/kame/kame/tcpdump/tests/isakmp-identification-segfault.puu @@ -0,0 +1,11 @@ +begin 644 isakmp-identification-segfault.pcap +MU,.RH0(`!````````````/__````````HV%@0"_*#@`\`0``/`$```(```!% +M``$XH&P``/\1'$9_```!?P```0'U`?0!)$KL)9EPC(1ZBP(```````````40 +M`@`````````!'````0`"```````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +I```````````````````````````````````````````````````````` +` +end diff --git a/kame/kame/tcpdump/tests/isakmp-pointer-loop.puu b/kame/kame/tcpdump/tests/isakmp-pointer-loop.puu new file mode 100644 index 0000000000..fc582482c1 --- /dev/null +++ b/kame/kame/tcpdump/tests/isakmp-pointer-loop.puu @@ -0,0 +1,6 @@ +begin 644 isakmp-pointer-loop.pcap +MU,.RH0(`!````````````/__```!````DR;5/[_@!0!(````2``````$6D[H +ME``"+6_:]@@`10``.H=E0`#S$0HB@:KY?H&J^5 127.0.0.1.500: isakmp: phase 2/others ? #190[C] diff --git a/kame/kame/tcpdump/tests/isakmp1.sh b/kame/kame/tcpdump/tests/isakmp1.sh new file mode 100644 index 0000000000..ce2de7d1ba --- /dev/null +++ b/kame/kame/tcpdump/tests/isakmp1.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +uudecode isakmp-delete-segfault.puu + +echo -n test isakmp1... +if (../tcpdump -t -n -r isakmp-delete-segfault.pcap | diff - isakmp1.out) +then + echo passed. +else + echo failed. +fi + diff --git a/kame/kame/tcpdump/tests/isakmp2.out b/kame/kame/tcpdump/tests/isakmp2.out new file mode 100644 index 0000000000..44c28db87b --- /dev/null +++ b/kame/kame/tcpdump/tests/isakmp2.out @@ -0,0 +1 @@ +IP 129.170.249.126.500 > 129.170.249.87.500: isakmp: phase 1 ? base diff --git a/kame/kame/tcpdump/tests/isakmp2.sh b/kame/kame/tcpdump/tests/isakmp2.sh new file mode 100644 index 0000000000..d0006a8fee --- /dev/null +++ b/kame/kame/tcpdump/tests/isakmp2.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +uudecode isakmp-pointer-loop.puu + +echo -n test isakmp2... +if (../tcpdump -t -n -r isakmp-pointer-loop.pcap | diff - isakmp2.out) +then + echo passed. +else + echo failed. +fi + diff --git a/kame/kame/tcpdump/tests/isakmp3.out b/kame/kame/tcpdump/tests/isakmp3.out new file mode 100644 index 0000000000..fdc2f00c52 --- /dev/null +++ b/kame/kame/tcpdump/tests/isakmp3.out @@ -0,0 +1,2 @@ +IP (tos 0x0, ttl 255, id 41068, offset 0, flags [none], proto 17, length: 312) 127.0.0.1.501 > 127.0.0.1.500: isakmp 1.0 msgid : phase 1 I ident: + (id: idtype=FQDN protoid=0 port=0 len=248 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000) diff --git a/kame/kame/tcpdump/tests/isakmp3.sh b/kame/kame/tcpdump/tests/isakmp3.sh new file mode 100644 index 0000000000..f97d5eb96e --- /dev/null +++ b/kame/kame/tcpdump/tests/isakmp3.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +uudecode isakmp-identification-segfault.puu + +echo -n test isakmp3... +if (../tcpdump -t -v -n -r isakmp-identification-segfault.pcap | diff - isakmp3.out) +then + echo passed. +else + echo failed. +fi + diff --git a/kame/kame/tcpdump/tests/mpls-ldp-hello.out b/kame/kame/tcpdump/tests/mpls-ldp-hello.out new file mode 100644 index 0000000000..6888f87fc6 --- /dev/null +++ b/kame/kame/tcpdump/tests/mpls-ldp-hello.out @@ -0,0 +1,9 @@ +IP (tos 0xc0, ttl 1, id 15579, offset 0, flags [none], proto 17, length: 70) 10.1.1.3.646 > 224.0.0.2.646: + LDP, Label-Space-ID: 10.1.0.2:0, length: 42 + Hello Message (0x0100), length: 28, Message ID: 0x00011970, Flags: [ignore if unknown] + Common Hello Parameters TLV (0x0400), length: 4, Flags: [ignore and don't forward if unknown] + Hold Time: 15s, Flags: [Link Hello] + IPv4 Transport Address TLV (0x0401), length: 4, Flags: [ignore and don't forward if unknown] + IPv4 Transport Address: 10.1.0.2 + Configuration Sequence Number TLV (0x0402), length: 4, Flags: [ignore and don't forward if unknown] + Sequence Number: 1 diff --git a/kame/kame/tcpdump/tests/mpls-ldp-hello.pcap b/kame/kame/tcpdump/tests/mpls-ldp-hello.pcap new file mode 100644 index 0000000000000000000000000000000000000000..a4a42b71e6696ed176dc8c9e81a2f3d895fddc18 GIT binary patch literal 114 zcmca|c+)~A1{MYwc*V-VzzO8INA9uj4Hgo7)TwjDi!{xEL9k xA22X5F|{$ZF&JH$$H2&-#>L3M1e9f9kYQkyEC8Cx!oUwC7#UbVGAs~l7y*}J58?m- literal 0 HcmV?d00001 diff --git a/kame/kame/tcpdump/tests/mpls-ldp-hello.sh b/kame/kame/tcpdump/tests/mpls-ldp-hello.sh new file mode 100755 index 0000000000..d8c01a7645 --- /dev/null +++ b/kame/kame/tcpdump/tests/mpls-ldp-hello.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +echo -n test mpls-ldp-hello ... +if (../tcpdump -t -n -v -r mpls-ldp-hello.pcap | diff - mpls-ldp-hello.out) +then + echo passed. +else + echo failed. +fi + + diff --git a/kame/kame/tcpdump/tests/ospf-gmpls.out b/kame/kame/tcpdump/tests/ospf-gmpls.out new file mode 100644 index 0000000000..104ea9698e --- /dev/null +++ b/kame/kame/tcpdump/tests/ospf-gmpls.out @@ -0,0 +1,83 @@ +IP (tos 0xc0, ttl 1, id 4052, offset 0, flags [none], proto 89, length: 172) 40.35.1.2 > 224.0.0.5: OSPFv2, LS-Update (4), length: 152 + Router-ID: 10.255.245.35, Backbone Area, Authentication Type: none (0), 1 LSA + LSA #1 + Advertising Router: 10.255.245.37, seq 0x80000002, age 9s, length: 104 + Area Local Opaque LSA (10), Opaque-Type: Traffic Engineering LSA (1), Opaque-ID: 8 + Options: [External] + Link TLV (2), length: 100 + Link Type subTLV (1), length: 1, Point-to-point (1) + Link ID subTLV (2), length: 4, 10.255.245.69 (0x0afff545) + Local Interface IP address subTLV (3), length: 4, 10.9.142.1 + Remote Interface IP address subTLV (4), length: 4, 10.9.142.2 + Traffic Engineering Metric subTLV (5), length: 4, Metric 63 + Maximum Bandwidth subTLV (6), length: 4, 622.080 Mbps + Maximum Reservable Bandwidth subTLV (7), length: 4, 622.080 Mbps + Unreserved Bandwidth subTLV (8), length: 32 + priority level 0: 622.080 Mbps + priority level 1: 622.080 Mbps + priority level 2: 622.080 Mbps + priority level 3: 622.080 Mbps + priority level 4: 622.080 Mbps + priority level 5: 622.080 Mbps + priority level 6: 622.080 Mbps + priority level 7: 622.080 Mbps + Administrative Group subTLV (9), length: 4, 0x00000000 +IP (tos 0xc0, ttl 1, id 4106, offset 0, flags [none], proto 89, length: 172) 40.35.1.2 > 224.0.0.5: OSPFv2, LS-Update (4), length: 152 + Router-ID: 10.255.245.35, Backbone Area, Authentication Type: none (0), 1 LSA + LSA #1 + Advertising Router: 10.255.245.37, seq 0x80000002, age 9s, length: 104 + Area Local Opaque LSA (10), Opaque-Type: Traffic Engineering LSA (1), Opaque-ID: 9 + Options: [External] + Link TLV (2), length: 100 + Link Type subTLV (1), length: 1, Point-to-point (1) + Link ID subTLV (2), length: 4, 10.255.245.69 (0x0afff545) + Local Interface IP address subTLV (3), length: 4, 10.9.143.1 + Remote Interface IP address subTLV (4), length: 4, 10.9.143.2 + Traffic Engineering Metric subTLV (5), length: 4, Metric 63 + Maximum Bandwidth subTLV (6), length: 4, 622.080 Mbps + Maximum Reservable Bandwidth subTLV (7), length: 4, 622.080 Mbps + Unreserved Bandwidth subTLV (8), length: 32 + priority level 0: 622.080 Mbps + priority level 1: 622.080 Mbps + priority level 2: 622.080 Mbps + priority level 3: 622.080 Mbps + priority level 4: 622.080 Mbps + priority level 5: 622.080 Mbps + priority level 6: 622.080 Mbps + priority level 7: 622.080 Mbps + Administrative Group subTLV (9), length: 4, 0x00000000 +IP (tos 0xc0, ttl 1, id 4160, offset 0, flags [none], proto 89, length: 212) 40.35.1.2 > 224.0.0.5: OSPFv2, LS-Update (4), length: 192 + Router-ID: 10.255.245.35, Backbone Area, Authentication Type: none (0), 1 LSA + LSA #1 + Advertising Router: 10.255.245.35, seq 0x80000003, age 3s, length: 144 + Area Local Opaque LSA (10), Opaque-Type: Traffic Engineering LSA (1), Opaque-ID: 3 + Options: [External] + Link TLV (2), length: 140 + Link Type subTLV (1), length: 1, Point-to-point (1) + Link ID subTLV (2), length: 4, 10.255.245.40 (0x0afff528) + Local Interface IP address subTLV (3), length: 4, 10.40.35.14 + Remote Interface IP address subTLV (4), length: 4, 10.40.35.13 + Traffic Engineering Metric subTLV (5), length: 4, Metric 1 + Maximum Bandwidth subTLV (6), length: 4, 100.000 Mbps + Maximum Reservable Bandwidth subTLV (7), length: 4, 100.000 Mbps + Unreserved Bandwidth subTLV (8), length: 32 + priority level 0: 0.000 Mbps + priority level 1: 0.000 Mbps + priority level 2: 0.000 Mbps + priority level 3: 0.000 Mbps + priority level 4: 0.000 Mbps + priority level 5: 0.000 Mbps + priority level 6: 0.000 Mbps + priority level 7: 0.000 Mbps + Interface Switching Capability subTLV (15), length: 44 + Interface Switching Capability: Packet-Switch Capable-1 + LSP Encoding: Ethernet V2/DIX + Max LSP Bandwidth: + priority level 0: 0.000 Mbps + priority level 1: 0.000 Mbps + priority level 2: 0.000 Mbps + priority level 3: 0.000 Mbps + priority level 4: 0.000 Mbps + priority level 5: 0.000 Mbps + priority level 6: 0.000 Mbps + priority level 7: 0.000 Mbps diff --git a/kame/kame/tcpdump/tests/ospf-gmpls.pcap b/kame/kame/tcpdump/tests/ospf-gmpls.pcap new file mode 100644 index 0000000000000000000000000000000000000000..d36982a1e0ffa54c3b58328ae9fd7ea05f64f6dd GIT binary patch literal 640 zcmca|c+)~A1{MYwC=-OR*4>P;|GI>gVFQp0!c0KydVpaK{}l!X#>n~B8p@1J4;UC& znOGQRaQ*+P43uVA*##oufRTZdiHnhefdeS7+5j}7!j7Q^Xiy3RBLgE)9Aqd9P|lTs z8Ax;XF#??dqL~<2!49%#U}IqMnG$e-fgMV7Ferfd_%H(}#4}HT?q@s0i{X9&F0lJq zvAIA02;A);2F(4OF!yg@#^?TisQde=;(p0nG4`f5Yz#Mm4gq0k_+Jrl0J(qOawPX3 zfQA1pbD%;5U}Rthhd(n&zJY;(S&@Zd3DBS(wD8vehrfn0A2|FqlzE}y&j<>CZ@WDT dpzsIN!0<;HkAua}pu-4qECB#Ak4uAr0RSA>Zj1l` literal 0 HcmV?d00001 diff --git a/kame/kame/tcpdump/tests/ospf-gmpls.sh b/kame/kame/tcpdump/tests/ospf-gmpls.sh new file mode 100755 index 0000000000..bc938dfd89 --- /dev/null +++ b/kame/kame/tcpdump/tests/ospf-gmpls.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +echo -n test ospf-gmpls... +if (../tcpdump -t -n -v -r ospf-gmpls.pcap | diff - ospf-gmpls.out) +then + echo passed. +else + echo failed. +fi + + diff --git a/kame/kame/tcpdump/timed.h b/kame/kame/tcpdump/timed.h new file mode 100644 index 0000000000..0a5c5fe57a --- /dev/null +++ b/kame/kame/tcpdump/timed.h @@ -0,0 +1,92 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/timed.h,v 1.5 2002/12/11 07:14:12 guy Exp $ (LBL) */ +/* + * 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. + * + * @(#)timed.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _PROTOCOLS_TIMED_H_ +#define _PROTOCOLS_TIMED_H_ + +/* + * Time Synchronization Protocol + */ + +#define TSPVERSION 1 +#define ANYADDR NULL + +struct tsp { + u_int8_t tsp_type; + u_int8_t tsp_vers; + u_int16_t tsp_seq; + union { + struct timeval tspu_time; + int8_t tspu_hopcnt; + } tsp_u; + int8_t tsp_name[256]; +}; + +#define tsp_time tsp_u.tspu_time +#define tsp_hopcnt tsp_u.tspu_hopcnt + +/* + * Command types. + */ +#define TSP_ANY 0 /* match any types */ +#define TSP_ADJTIME 1 /* send adjtime */ +#define TSP_ACK 2 /* generic acknowledgement */ +#define TSP_MASTERREQ 3 /* ask for master's name */ +#define TSP_MASTERACK 4 /* acknowledge master request */ +#define TSP_SETTIME 5 /* send network time */ +#define TSP_MASTERUP 6 /* inform slaves that master is up */ +#define TSP_SLAVEUP 7 /* slave is up but not polled */ +#define TSP_ELECTION 8 /* advance candidature for master */ +#define TSP_ACCEPT 9 /* support candidature of master */ +#define TSP_REFUSE 10 /* reject candidature of master */ +#define TSP_CONFLICT 11 /* two or more masters present */ +#define TSP_RESOLVE 12 /* masters' conflict resolution */ +#define TSP_QUIT 13 /* reject candidature if master is up */ +#define TSP_DATE 14 /* reset the time (date command) */ +#define TSP_DATEREQ 15 /* remote request to reset the time */ +#define TSP_DATEACK 16 /* acknowledge time setting */ +#define TSP_TRACEON 17 /* turn tracing on */ +#define TSP_TRACEOFF 18 /* turn tracing off */ +#define TSP_MSITE 19 /* find out master's site */ +#define TSP_MSITEREQ 20 /* remote master's site request */ +#define TSP_TEST 21 /* for testing election algo */ +#define TSP_SETDATE 22 /* New from date command */ +#define TSP_SETDATEREQ 23 /* New remote for above */ +#define TSP_LOOP 24 /* loop detection packet */ + +#define TSPTYPENUMBER 25 + +#endif /* !_TIMED_H_ */ diff --git a/kame/kame/tcpdump/token.h b/kame/kame/tcpdump/token.h new file mode 100644 index 0000000000..8e7fd6d4e2 --- /dev/null +++ b/kame/kame/tcpdump/token.h @@ -0,0 +1,52 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/token.h,v 1.6 2002/12/11 07:14:12 guy Exp $ (LBL) */ +/* + * Copyright (c) 1998, Larry Lile + * 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 unmodified, 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 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 AUTHOR 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. + * + */ + +#define TOKEN_HDRLEN 14 +#define TOKEN_RING_MAC_LEN 6 +#define ROUTING_SEGMENT_MAX 16 +#define IS_SOURCE_ROUTED(trp) ((trp)->token_shost[0] & 0x80) +#define FRAME_TYPE(trp) (((trp)->token_fc & 0xC0) >> 6) +#define TOKEN_FC_LLC 1 + +#define BROADCAST(trp) ((ntohs((trp)->token_rcf) & 0xE000) >> 13) +#define RIF_LENGTH(trp) ((ntohs((trp)->token_rcf) & 0x1f00) >> 8) +#define DIRECTION(trp) ((ntohs((trp)->token_rcf) & 0x0080) >> 7) +#define LARGEST_FRAME(trp) ((ntohs((trp)->token_rcf) & 0x0070) >> 4) +#define RING_NUMBER(trp, x) ((ntohs((trp)->token_rseg[x]) & 0xfff0) >> 4) +#define BRIDGE_NUMBER(trp, x) ((ntohs((trp)->token_rseg[x]) & 0x000f)) +#define SEGMENT_COUNT(trp) ((int)((RIF_LENGTH(trp) - 2) / 2)) + +struct token_header { + u_int8_t token_ac; + u_int8_t token_fc; + u_int8_t token_dhost[TOKEN_RING_MAC_LEN]; + u_int8_t token_shost[TOKEN_RING_MAC_LEN]; + u_int16_t token_rcf; + u_int16_t token_rseg[ROUTING_SEGMENT_MAX]; +}; diff --git a/kame/kame/tcpdump/udp.h b/kame/kame/tcpdump/udp.h new file mode 100644 index 0000000000..eb6c20bc0b --- /dev/null +++ b/kame/kame/tcpdump/udp.h @@ -0,0 +1,84 @@ +/* @(#) $Header: /tcpdump/master/tcpdump/udp.h,v 1.5 2003/10/27 22:44:37 hannes Exp $ (LBL) */ +/* + * 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. + * + * @(#)udp.h 8.1 (Berkeley) 6/10/93 + */ + +/* + * Udp protocol header. + * Per RFC 768, September, 1981. + */ +struct udphdr { + u_int16_t uh_sport; /* source port */ + u_int16_t uh_dport; /* destination port */ + u_int16_t uh_ulen; /* udp length */ + u_int16_t uh_sum; /* udp checksum */ +}; + +#define TFTP_PORT 69 /*XXX*/ +#define KERBEROS_PORT 88 /*XXX*/ +#define SUNRPC_PORT 111 /*XXX*/ +#define SNMP_PORT 161 /*XXX*/ +#define NTP_PORT 123 /*XXX*/ +#define SNMPTRAP_PORT 162 /*XXX*/ +#define ISAKMP_PORT 500 /*XXX*/ +#define TIMED_PORT 525 /*XXX*/ +#define RIP_PORT 520 /*XXX*/ +#define LDP_PORT 646 +#define AODV_PORT 654 /*XXX*/ +#define KERBEROS_SEC_PORT 750 /*XXX*/ +#define L2TP_PORT 1701 /*XXX*/ +#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 +#define NETBIOS_DGRAM_PORT 138 +#define CISCO_AUTORP_PORT 496 /*XXX*/ +#define RADIUS_PORT 1645 +#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 +#define MPLS_LSP_PING_PORT 3503 /* draft-ietf-mpls-lsp-ping-02.txt */ +#define BFD_CONTROL_PORT 3784 /* draft-katz-ward-bfd-v4v6-1hop-00.txt */ +#define BFD_ECHO_PORT 3785 /* draft-katz-ward-bfd-v4v6-1hop-00.txt */ + +#ifdef INET6 +#define RIPNG_PORT 521 /*XXX*/ +#define DHCP6_SERV_PORT 546 /*XXX*/ +#define DHCP6_CLI_PORT 547 /*XXX*/ +#endif diff --git a/kame/kame/tcpdump/util.c b/kame/kame/tcpdump/util.c index 6b07200175..f7df263de5 100644 --- a/kame/kame/tcpdump/util.c +++ b/kame/kame/tcpdump/util.c @@ -20,36 +20,27 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: util.c,v 1.58 97/05/09 14:52:17 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.87.2.3 2003/12/29 22:42:23 hannes Exp $ (LBL)"; #endif -#include -#include -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + #include -#include #include #ifdef HAVE_FCNTL_H #include #endif -#ifdef HAVE_MALLOC_H -#include -#endif #include #include -#if __STDC__ #include -#else -#include -#endif #include #include -#ifdef TIME_WITH_SYS_TIME -#include -#endif -#include #include "interface.h" @@ -94,15 +85,10 @@ int fn_printn(register const u_char *s, register u_int n, register const u_char *ep) { - register int ret; register u_char c; - ret = 1; /* assume truncated */ - while (ep == NULL || s < ep) { - if (n-- <= 0) { - ret = 0; - break; - } + while (n > 0 && (ep == NULL || s < ep)) { + n--; c = *s++; if (!isascii(c)) { c = toascii(c); @@ -115,7 +101,7 @@ fn_printn(register const u_char *s, register u_int n, } putchar(c); } - return(ret); + return (n == 0) ? 0 : 1; } /* @@ -125,17 +111,98 @@ void ts_print(register const struct timeval *tvp) { register int s; + struct tm *tm; + time_t Time; + static unsigned b_sec; + static unsigned b_usec; - if (tflag > 0) { - /* Default */ + switch(tflag) { + case 1: /* Default */ s = (tvp->tv_sec + thiszone) % 86400; (void)printf("%02d:%02d:%02d.%06u ", - s / 3600, (s % 3600) / 60, s % 60, (u_int32_t)tvp->tv_usec); - } else if (tflag < 0) { - /* Unix timeval style */ + s / 3600, (s % 3600) / 60, s % 60, + (unsigned)tvp->tv_usec); + break; + case -1: /* Unix timeval style */ (void)printf("%u.%06u ", - (u_int32_t)tvp->tv_sec, (u_int32_t)tvp->tv_usec); + (unsigned)tvp->tv_sec, + (unsigned)tvp->tv_usec); + break; + case -2: + if (b_sec == 0) { + printf("000000 "); + } else { + int d_usec = tvp->tv_usec - b_usec; + int d_sec = tvp->tv_sec - b_sec; + + while (d_usec < 0) { + d_usec += 1000000; + d_sec--; + } + if (d_sec) + printf("%d. ", d_sec); + printf("%06d ", d_usec); + } + b_sec = tvp->tv_sec; + b_usec = tvp->tv_usec; + break; + case -3: /* Default + Date*/ + s = (tvp->tv_sec + thiszone) % 86400; + Time = (tvp->tv_sec + thiszone) - s; + tm = gmtime (&Time); + if (!tm) + printf("Date fail "); + else + printf("%04d-%02d-%02d ", + tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday); + printf("%02d:%02d:%02d.%06u ", + s / 3600, (s % 3600) / 60, s % 60, (unsigned)tvp->tv_usec); + break; + } +} + +/* + * Print a relative number of seconds (e.g. hold time, prune timer) + * in the form 5m1s. This does no truncation, so 32230861 seconds + * is represented as 1y1w1d1h1m1s. + */ +void +relts_print(int secs) +{ + 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) { + (void)printf("0s"); + return; + } + if (secs < 0) { + (void)printf("-"); + secs = -secs; } + while (secs > 0) { + if (secs >= *s) { + (void)printf("%d%s", secs / *s, *l); + secs -= (secs / *s) * *s; + } + s++; + l++; + } +} + +/* + * this is a generic routine for printing unknown data; + * we pass on the linefeed plus indentation string to + * get a proper output - returns 0 on error + */ + +int +print_unknown_data(const u_char *cp,const char *ident,int len) +{ + hex_print(ident,cp,len); + return(1); /* everything is ok */ } /* @@ -154,29 +221,114 @@ tok2str(register const struct tok *lp, register const char *fmt, } if (fmt == NULL) fmt = "#%d"; - (void)sprintf(buf, fmt, v); + (void)snprintf(buf, sizeof(buf), fmt, v); return (buf); } +/* + * Convert a bit token value to a string; use "fmt" if not found. + * this is useful for parsing bitfields, the output strings are comma seperated + */ +char * +bittok2str(register const struct tok *lp, register const char *fmt, + register int v) +{ + static char buf[256]; /* our stringbuffer */ + int buflen=0; + register int rotbit; /* this is the bit we rotate through all bitpositions */ + register int tokval; + + while (lp->s != NULL) { + tokval=lp->v; /* load our first value */ + rotbit=1; + while (rotbit != 0) { + /* + * lets AND the rotating bit with our token value + * and see if we have got a match + */ + if (tokval == (v&rotbit)) { + /* ok we have found something */ + buflen+=snprintf(buf+buflen, sizeof(buf)-buflen, "%s, ",lp->s); + break; + } + rotbit=rotbit<<1; /* no match - lets shift and try again */ + } + lp++; + } + + if (buflen != 0) { /* did we find anything */ + /* yep, set the the trailing zero 2 bytes before to eliminate the last comma & whitespace */ + buf[buflen-2] = '\0'; + return (buf); + } + else { + /* bummer - lets print the "unknown" message as advised in the fmt string if we got one */ + if (fmt == NULL) + fmt = "#%d"; + (void)snprintf(buf, sizeof(buf), fmt, v); + return (buf); + } +} + +/* + * Convert a value to a string using an array; the macro + * tok2strary() in 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); +} + +/* + * Convert a 32-bit netmask to prefixlen if possible + * the function returns the prefix-len; if plen == -1 + * then conversion was not possible; + */ + +int +mask2plen (u_int32_t mask) +{ + u_int32_t 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 prefix_len = 32; + + /* let's see if we can transform the mask into a prefixlen */ + while (prefix_len >= 0) { + if (bitmasks[prefix_len] == mask) + break; + prefix_len--; + } + return (prefix_len); +} /* VARARGS */ -__dead void -#if __STDC__ +void error(const char *fmt, ...) -#else -error(fmt, va_alist) - const char *fmt; - va_dcl -#endif { va_list ap; (void)fprintf(stderr, "%s: ", program_name); -#if __STDC__ va_start(ap, fmt); -#else - va_start(ap); -#endif (void)vfprintf(stderr, fmt, ap); va_end(ap); if (*fmt) { @@ -190,22 +342,12 @@ error(fmt, va_alist) /* VARARGS */ void -#if __STDC__ warning(const char *fmt, ...) -#else -warning(fmt, va_alist) - const char *fmt; - va_dcl -#endif { va_list ap; (void)fprintf(stderr, "%s: WARNING: ", program_name); -#if __STDC__ va_start(ap, fmt); -#else - va_start(ap); -#endif (void)vfprintf(stderr, fmt, ap); va_end(ap); if (*fmt) { @@ -249,14 +391,24 @@ copy_argv(register char **argv) return buf; } +/* + * On Windows, we need to open the file in binary mode, so that + * we get all the bytes specified by the size we get from "fstat()". + * On UNIX, that's not necessary. O_BINARY is defined on Windows; + * we define it as 0 if it's not defined, so it does nothing. + */ +#ifndef O_BINARY +#define O_BINARY 0 +#endif + char * read_infile(char *fname) { - register int fd, cc; + register int i, fd, cc; register char *cp; struct stat buf; - fd = open(fname, O_RDONLY); + fd = open(fname, O_RDONLY|O_BINARY); if (fd < 0) error("can't open %s: %s", fname, pcap_strerror(errno)); @@ -264,12 +416,43 @@ 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) error("short read %s (%d != %d)", fname, cc, (int)buf.st_size); - cp[(int)buf.st_size] = '\0'; + close(fd); + /* replace "# comment" with spaces */ + for (i = 0; i < cc; i++) { + if (cp[i] == '#') + while (i < cc && cp[i] != '\n') + cp[i++] = ' '; + } + cp[cc] = '\0'; return (cp); } + +void +safeputs(const char *s) +{ + while (*s) { + safeputchar(*s); + s++; + } +} + +void +safeputchar(int c) +{ + unsigned char ch; + + ch = (unsigned char)(c & 0xff); + if (ch < 0x80 && isprint(ch)) + printf("%c", ch); + else + printf("\\%03o", ch); +} diff --git a/kame/kame/tcpdump/vfprintf.c b/kame/kame/tcpdump/vfprintf.c index 868285995b..0a9e2356de 100644 --- a/kame/kame/tcpdump/vfprintf.c +++ b/kame/kame/tcpdump/vfprintf.c @@ -20,18 +20,18 @@ */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: vfprintf.c,v 1.2 96/09/26 23:36:51 leres Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/vfprintf.c,v 1.4.8.2 2003/11/16 08:51:58 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include #include -#if __STDC__ #include -#else -#include -#endif #include #include diff --git a/kame/kame/tcpdump/win32/Include/Arpa/tftp.h b/kame/kame/tcpdump/win32/Include/Arpa/tftp.h new file mode 100644 index 0000000000..6f21045b00 --- /dev/null +++ b/kame/kame/tcpdump/win32/Include/Arpa/tftp.h @@ -0,0 +1,84 @@ +/* + * 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. + * + * @(#)tftp.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _ARPA_TFTP_H +#define _ARPA_TFTP_H + +/* + * Trivial File Transfer Protocol (IEN-133) + */ +#define SEGSIZE 512 /* data segment size */ + +/* + * Packet types. + */ +#define RRQ 01 /* read request */ +#define WRQ 02 /* write request */ +#define DATA 03 /* data packet */ +#define ACK 04 /* acknowledgement */ + +#ifdef ERROR +#undef ERROR +#define ERROR 05 /* error code */ +#endif + +struct tftphdr { + short th_opcode; /* packet type */ + union { + short tu_block; /* block # */ + short tu_code; /* error code */ + char tu_stuff[1]; /* request packet stuff */ + } th_u; + char th_data[1]; /* data or error string */ +}; + +#define th_block th_u.tu_block +#define th_code th_u.tu_code +#define th_stuff th_u.tu_stuff +#define th_msg th_data + +/* + * Error codes. + */ +#define EUNDEF 0 /* not defined */ +#define ENOTFOUND 1 /* file not found */ +#define EACCESS 2 /* access violation */ +#define ENOSPACE 3 /* disk full or allocation exceeded */ +#define EBADOP 4 /* illegal TFTP operation */ +#define EBADID 5 /* unknown transfer ID */ +#define EEXISTS 6 /* file already exists */ +#define ENOUSER 7 /* no such user */ + +#endif /* _ARPA_TFTP_H */ diff --git a/kame/kame/tcpdump/win32/Include/Netinet/in_systm.h b/kame/kame/tcpdump/win32/Include/Netinet/in_systm.h new file mode 100644 index 0000000000..d9a7c3e233 --- /dev/null +++ b/kame/kame/tcpdump/win32/Include/Netinet/in_systm.h @@ -0,0 +1,56 @@ +/* + * 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. + * + * @(#)in_systm.h 8.1 (Berkeley) 6/10/93 + */ + +/* + * Miscellaneous internetwork + * definitions for kernel. + */ + +/* + * Network types. + * + * Internally the system keeps counters in the headers with the bytes + * swapped so that VAX instructions will work on them. It reverses + * the bytes before transmission at each protocol level. The n_ types + * represent the types with the bytes in ``high-ender'' order. + */ +typedef u_short n_short; /* short as received from the net */ +typedef u_int n_long; /* long as received from the net */ + +typedef u_int n_time; /* ms since 00:00 GMT, byte rev */ + +#ifdef KERNEL +n_time iptime __P((void)); +#endif diff --git a/kame/kame/tcpdump/win32/Include/Netinet/ip.h b/kame/kame/tcpdump/win32/Include/Netinet/ip.h new file mode 100644 index 0000000000..78dfa87681 --- /dev/null +++ b/kame/kame/tcpdump/win32/Include/Netinet/ip.h @@ -0,0 +1,177 @@ +/* + * 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. + * + * @(#)ip.h 8.2 (Berkeley) 6/1/94 + */ +#ifndef WIN32 +#include +#else +#ifndef LITTLE_ENDIAN +#define LITTLE_ENDIAN 1234 +#define BIG_ENDIAN 4321 +#define BYTE_ORDER LITTLE_ENDIAN +#endif +#endif + +/* + * Definitions for internet protocol version 4. + * Per RFC 791, September 1981. + */ +#define IPVERSION 4 + +/* + * Structure of an internet header, naked of options. + * + * We declare ip_len and ip_off to be short, rather than u_short + * pragmatically since otherwise unsigned comparisons can result + * against negative integers quite easily, and fail in subtle ways. + */ +struct ip { +#if BYTE_ORDER == LITTLE_ENDIAN + u_char ip_hl:4, /* header length */ + ip_v:4; /* version */ +#endif +#if BYTE_ORDER == BIG_ENDIAN + u_char ip_v:4, /* version */ + ip_hl:4; /* header length */ +#endif + u_char ip_tos; /* type of service */ + short ip_len; /* total length */ + u_short ip_id; /* identification */ + short ip_off; /* fragment offset field */ +#define IP_DF 0x4000 /* dont fragment flag */ +#define IP_MF 0x2000 /* more fragments flag */ +#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ + u_char ip_ttl; /* time to live */ + u_char ip_p; /* protocol */ + u_short ip_sum; /* checksum */ + struct in_addr ip_src,ip_dst; /* source and dest address */ +}; + +#define IP_MAXPACKET 65535 /* maximum packet size */ + +/* + * Definitions for IP type of service (ip_tos) + */ +#define IPTOS_LOWDELAY 0x10 +#define IPTOS_THROUGHPUT 0x08 +#define IPTOS_RELIABILITY 0x04 + +/* + * Definitions for IP precedence (also in ip_tos) (hopefully unused) + */ +#define IPTOS_PREC_NETCONTROL 0xe0 +#define IPTOS_PREC_INTERNETCONTROL 0xc0 +#define IPTOS_PREC_CRITIC_ECP 0xa0 +#define IPTOS_PREC_FLASHOVERRIDE 0x80 +#define IPTOS_PREC_FLASH 0x60 +#define IPTOS_PREC_IMMEDIATE 0x40 +#define IPTOS_PREC_PRIORITY 0x20 +#define IPTOS_PREC_ROUTINE 0x00 + +/* + * Definitions for options. + */ +#define IPOPT_COPIED(o) ((o)&0x80) +#define IPOPT_CLASS(o) ((o)&0x60) +#define IPOPT_NUMBER(o) ((o)&0x1f) + +#define IPOPT_CONTROL 0x00 +#define IPOPT_RESERVED1 0x20 +#define IPOPT_DEBMEAS 0x40 +#define IPOPT_RESERVED2 0x60 + +#define IPOPT_EOL 0 /* end of option list */ +#define IPOPT_NOP 1 /* no operation */ + +#define IPOPT_RR 7 /* record packet route */ +#define IPOPT_TS 68 /* timestamp */ +#define IPOPT_SECURITY 130 /* provide s,c,h,tcc */ +#define IPOPT_LSRR 131 /* loose source route */ +#define IPOPT_SATID 136 /* satnet id */ +#define IPOPT_SSRR 137 /* strict source route */ + +/* + * Offsets to fields in options other than EOL and NOP. + */ +#define IPOPT_OPTVAL 0 /* option ID */ +#define IPOPT_OLEN 1 /* option length */ +#define IPOPT_OFFSET 2 /* offset within option */ +#define IPOPT_MINOFF 4 /* min value of above */ + +/* + * Time stamp option structure. + */ +struct ip_timestamp { + u_char ipt_code; /* IPOPT_TS */ + u_char ipt_len; /* size of structure (variable) */ + u_char ipt_ptr; /* index of current entry */ +#if BYTE_ORDER == LITTLE_ENDIAN + u_char ipt_flg:4, /* flags, see below */ + ipt_oflw:4; /* overflow counter */ +#endif +#if BYTE_ORDER == BIG_ENDIAN + u_char ipt_oflw:4, /* overflow counter */ + ipt_flg:4; /* flags, see below */ +#endif + union ipt_timestamp { + n_long ipt_time[1]; + struct ipt_ta { + struct in_addr ipt_addr; + n_long ipt_time; + } ipt_ta[1]; + } ipt_timestamp; +}; + +/* flag bits for ipt_flg */ +#define IPOPT_TS_TSONLY 0 /* timestamps only */ +#define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ +#define IPOPT_TS_PRESPEC 3 /* specified modules only */ + +/* bits for security (not byte swapped) */ +#define IPOPT_SECUR_UNCLASS 0x0000 +#define IPOPT_SECUR_CONFID 0xf135 +#define IPOPT_SECUR_EFTO 0x789a +#define IPOPT_SECUR_MMMM 0xbc4d +#define IPOPT_SECUR_RESTR 0xaf13 +#define IPOPT_SECUR_SECRET 0xd788 +#define IPOPT_SECUR_TOPSECRET 0x6bc5 + +/* + * Internet implementation parameters. + */ +#define MAXTTL 255 /* maximum time to live (seconds) */ +#define IPDEFTTL 64 /* default ttl, from RFC 1340 */ +#define IPFRAGTTL 60 /* time to live for frags, slowhz */ +#define IPTTLDEC 1 /* subtracted when forwarding */ + +#define IP_MSS 576 /* default maximum segment size */ diff --git a/kame/kame/tcpdump/win32/Include/Rpc/rpc.h b/kame/kame/tcpdump/win32/Include/Rpc/rpc.h new file mode 100644 index 0000000000..b60d0a4d9d --- /dev/null +++ b/kame/kame/tcpdump/win32/Include/Rpc/rpc.h @@ -0,0 +1,157 @@ +/* + * Copyright (c) 1999 - 2000 + * NetGroup, Politecnico di Torino (Italy) + * 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 Politecnico di Torino 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 COPYRIGHT HOLDERS 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 COPYRIGHT + * OWNER 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. + * + */ + +enum auth_stat { + AUTH_OK=0, + /* + * failed at remote end + */ + AUTH_BADCRED=1, /* bogus credentials (seal broken) */ + AUTH_REJECTEDCRED=2, /* client should begin new session */ + AUTH_BADVERF=3, /* bogus verifier (seal broken) */ + AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */ + AUTH_TOOWEAK=5, /* rejected due to security reasons */ + /* + * failed locally + */ + AUTH_INVALIDRESP=6, /* bogus response verifier */ + AUTH_FAILED=7 /* some unknown reason */ +}; + +enum msg_type { + CALL=0, + REPLY=1 +}; + +enum reply_stat { + MSG_ACCEPTED=0, + MSG_DENIED=1 +}; + +enum accept_stat { + SUCCESS=0, + PROG_UNAVAIL=1, + PROG_MISMATCH=2, + PROC_UNAVAIL=3, + GARBAGE_ARGS=4, + SYSTEM_ERR=5 +}; + +enum reject_stat { + RPC_MISMATCH=0, + AUTH_ERROR=1 +}; + +#define u_long unsigned long +#define u_int unsigned int +#define u_short unsigned short +#define enum_t int +#define caddr_t char* + +struct opaque_auth { + enum_t oa_flavor; /* flavor of auth */ + caddr_t oa_base; /* address of more auth stuff */ + u_int oa_length; /* not to exceed MAX_AUTH_BYTES */ +}; + +struct accepted_reply { + struct opaque_auth ar_verf; + enum accept_stat ar_stat; + union { + struct { + u_long low; + u_long high; + } AR_versions; + /*struct { + caddr_t where; + xdrproc_t proc; + } AR_results; + /* and many other null cases */ + } ru; +#define ar_results ru.AR_results +#define ar_vers ru.AR_versions +}; + +struct rejected_reply { + enum reject_stat rj_stat; + union { + struct { + u_long low; + u_long high; + } RJ_versions; + enum auth_stat RJ_why; /* why authentication did not work */ + } ru; +#define rj_vers ru.RJ_versions +#define rj_why ru.RJ_why +}; + +struct reply_body { + enum reply_stat rp_stat; + union { + struct accepted_reply RP_ar; + struct rejected_reply RP_dr; + } ru; +#define rp_acpt ru.RP_ar +#define rp_rjct ru.RP_dr +}; + +struct call_body { + u_long cb_rpcvers; /* must be equal to two */ + u_long cb_prog; + u_long cb_vers; + u_long cb_proc; + struct opaque_auth cb_cred; + struct opaque_auth cb_verf; /* protocol specific - provided by client */ +}; + +struct rpc_msg { + u_long rm_xid; + enum msg_type rm_direction; + union { + struct call_body RM_cmb; + struct reply_body RM_rmb; + } ru; +#define rm_call ru.RM_cmb +#define rm_reply ru.RM_rmb +}; + +#define PMAPPORT ((u_short)111) +#define PMAPPROG ((u_long)100000) +#define PMAPVERS ((u_long)2) +#define PMAPVERS_PROTO ((u_long)2) +#define PMAPVERS_ORIG ((u_long)1) +#define PMAPPROC_NULL ((u_long)0) +#define PMAPPROC_SET ((u_long)1) +#define PMAPPROC_UNSET ((u_long)2) +#define PMAPPROC_GETPORT ((u_long)3) +#define PMAPPROC_DUMP ((u_long)4) +#define PMAPPROC_CALLIT ((u_long)5) diff --git a/kame/kame/tcpdump/win32/Include/errno.h b/kame/kame/tcpdump/win32/Include/errno.h new file mode 100644 index 0000000000..7cf599f4de --- /dev/null +++ b/kame/kame/tcpdump/win32/Include/errno.h @@ -0,0 +1,132 @@ +#ifndef _I386_ERRNO_H +#define _I386_ERRNO_H + +#define EPERM 1 /* Operation not permitted */ +#define ENOENT 2 /* No such file or directory */ +#define ESRCH 3 /* No such process */ +#define EINTR 4 /* Interrupted system call */ +#define EIO 5 /* I/O error */ +#define ENXIO 6 /* No such device or address */ +#define E2BIG 7 /* Arg list too long */ +#define ENOEXEC 8 /* Exec format error */ +#define EBADF 9 /* Bad file number */ +#define ECHILD 10 /* No child processes */ +#define EAGAIN 11 /* Try again */ +#define ENOMEM 12 /* Out of memory */ +#define EACCES 13 /* Permission denied */ +#define EFAULT 14 /* Bad address */ +#define ENOTBLK 15 /* Block device required */ +#define EBUSY 16 /* Device or resource busy */ +#define EEXIST 17 /* File exists */ +#define EXDEV 18 /* Cross-device link */ +#define ENODEV 19 /* No such device */ +#define ENOTDIR 20 /* Not a directory */ +#define EISDIR 21 /* Is a directory */ +#define EINVAL 22 /* Invalid argument */ +#define ENFILE 23 /* File table overflow */ +#define EMFILE 24 /* Too many open files */ +#define ENOTTY 25 /* Not a typewriter */ +#define ETXTBSY 26 /* Text file busy */ +#define EFBIG 27 /* File too large */ +#define ENOSPC 28 /* No space left on device */ +#define ESPIPE 29 /* Illegal seek */ +#define EROFS 30 /* Read-only file system */ +#define EMLINK 31 /* Too many links */ +#define EPIPE 32 /* Broken pipe */ +#define EDOM 33 /* Math argument out of domain of func */ +#define ERANGE 34 /* Math result not representable */ +#define EDEADLK 35 /* Resource deadlock would occur */ +#define ENAMETOOLONG 36 /* File name too long */ +#define ENOLCK 37 /* No record locks available */ +#define ENOSYS 38 /* Function not implemented */ +#define ENOTEMPTY 39 /* Directory not empty */ +#define ELOOP 40 /* Too many symbolic links encountered */ +#define EWOULDBLOCK EAGAIN /* Operation would block */ +#define ENOMSG 42 /* No message of desired type */ +#define EIDRM 43 /* Identifier removed */ +#define ECHRNG 44 /* Channel number out of range */ +#define EL2NSYNC 45 /* Level 2 not synchronized */ +#define EL3HLT 46 /* Level 3 halted */ +#define EL3RST 47 /* Level 3 reset */ +#define ELNRNG 48 /* Link number out of range */ +#define EUNATCH 49 /* Protocol driver not attached */ +#define ENOCSI 50 /* No CSI structure available */ +#define EL2HLT 51 /* Level 2 halted */ +#define EBADE 52 /* Invalid exchange */ +#define EBADR 53 /* Invalid request descriptor */ +#define EXFULL 54 /* Exchange full */ +#define ENOANO 55 /* No anode */ +#define EBADRQC 56 /* Invalid request code */ +#define EBADSLT 57 /* Invalid slot */ + +#define EDEADLOCK EDEADLK + +#define EBFONT 59 /* Bad font file format */ +#define ENOSTR 60 /* Device not a stream */ +#define ENODATA 61 /* No data available */ +#define ETIME 62 /* Timer expired */ +#define ENOSR 63 /* Out of streams resources */ +#define ENONET 64 /* Machine is not on the network */ +#define ENOPKG 65 /* Package not installed */ +#define EREMOTE 66 /* Object is remote */ +#define ENOLINK 67 /* Link has been severed */ +#define EADV 68 /* Advertise error */ +#define ESRMNT 69 /* Srmount error */ +#define ECOMM 70 /* Communication error on send */ +#define EPROTO 71 /* Protocol error */ +#define EMULTIHOP 72 /* Multihop attempted */ +#define EDOTDOT 73 /* RFS specific error */ +#define EBADMSG 74 /* Not a data message */ +#define EOVERFLOW 75 /* Value too large for defined data type */ +#define ENOTUNIQ 76 /* Name not unique on network */ +#define EBADFD 77 /* File descriptor in bad state */ +#define EREMCHG 78 /* Remote address changed */ +#define ELIBACC 79 /* Can not access a needed shared library */ +#define ELIBBAD 80 /* Accessing a corrupted shared library */ +#define ELIBSCN 81 /* .lib section in a.out corrupted */ +#define ELIBMAX 82 /* Attempting to link in too many shared libraries */ +#define ELIBEXEC 83 /* Cannot exec a shared library directly */ +#define EILSEQ 84 /* Illegal byte sequence */ +#define ERESTART 85 /* Interrupted system call should be restarted */ +#define ESTRPIPE 86 /* Streams pipe error */ +#define EUSERS 87 /* Too many users */ +#define ENOTSOCK 88 /* Socket operation on non-socket */ +#define EDESTADDRREQ 89 /* Destination address required */ +#define EMSGSIZE 90 /* Message too long */ +#define EPROTOTYPE 91 /* Protocol wrong type for socket */ +#define ENOPROTOOPT 92 /* Protocol not available */ +#define EPROTONOSUPPORT 93 /* Protocol not supported */ +#define ESOCKTNOSUPPORT 94 /* Socket type not supported */ +#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ +#define EPFNOSUPPORT 96 /* Protocol family not supported */ +#define EAFNOSUPPORT 97 /* Address family not supported by protocol */ +#define EADDRINUSE 98 /* Address already in use */ +#define EADDRNOTAVAIL 99 /* Cannot assign requested address */ +#define ENETDOWN 100 /* Network is down */ +#define ENETUNREACH 101 /* Network is unreachable */ +#define ENETRESET 102 /* Network dropped connection because of reset */ +#define ECONNABORTED 103 /* Software caused connection abort */ +#define ECONNRESET 104 /* Connection reset by peer */ +#define ENOBUFS 105 /* No buffer space available */ +#define EISCONN 106 /* Transport endpoint is already connected */ +#define ENOTCONN 107 /* Transport endpoint is not connected */ +#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ +#define ETOOMANYREFS 109 /* Too many references: cannot splice */ +#define ETIMEDOUT 110 /* Connection timed out */ +#define ECONNREFUSED 111 /* Connection refused */ +#define EHOSTDOWN 112 /* Host is down */ +#define EHOSTUNREACH 113 /* No route to host */ +#define EALREADY 114 /* Operation already in progress */ +#define EINPROGRESS 115 /* Operation now in progress */ +#define ESTALE 116 /* Stale NFS file handle */ +#define EUCLEAN 117 /* Structure needs cleaning */ +#define ENOTNAM 118 /* Not a XENIX named type file */ +#define ENAVAIL 119 /* No XENIX semaphores available */ +#define EISNAM 120 /* Is a named type file */ +#define EREMOTEIO 121 /* Remote I/O error */ +#define EDQUOT 122 /* Quota exceeded */ + +#define ENOMEDIUM 123 /* No medium found */ +#define EMEDIUMTYPE 124 /* Wrong medium type */ + +#endif diff --git a/kame/kame/tcpdump/win32/Include/getopt.h b/kame/kame/tcpdump/win32/Include/getopt.h new file mode 100644 index 0000000000..b439ab1237 --- /dev/null +++ b/kame/kame/tcpdump/win32/Include/getopt.h @@ -0,0 +1,138 @@ +/* Declarations for getopt. + Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#ifndef _GETOPT_H +#define _GETOPT_H 1 + +#ifdef __cplusplus +extern "C" { +#endif + +/* For communication from `getopt' to the caller. + When `getopt' finds an option that takes an argument, + the argument value is returned here. + Also, when `ordering' is RETURN_IN_ORDER, + each non-option ARGV-element is returned here. */ + +#ifndef WIN32 +extern char *optarg; +#endif + +/* Index in ARGV of the next element to be scanned. + This is used for communication to and from the caller + and for communication between successive calls to `getopt'. + + On entry to `getopt', zero means this is the first call; initialize. + + When `getopt' returns EOF, this is the index of the first of the + non-option elements that the caller should itself scan. + + Otherwise, `optind' communicates from one call to the next + how much of ARGV has been scanned so far. */ + +#ifndef WIN32 +extern int optind; +#endif + +/* Callers store zero here to inhibit the error message `getopt' prints + for unrecognized options. */ + +#ifndef WIN32 +extern int opterr; +#endif + +/* Set to an option character which was unrecognized. */ + +extern int optopt; + +/* Describe the long-named options requested by the application. + The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector + of `struct option' terminated by an element containing a name which is + zero. + + The field `has_arg' is: + no_argument (or 0) if the option does not take an argument, + required_argument (or 1) if the option requires an argument, + optional_argument (or 2) if the option takes an optional argument. + + If the field `flag' is not NULL, it points to a variable that is set + to the value given in the field `val' when the option is found, but + left unchanged if the option is not found. + + To have a long-named option do something other than set an `int' to + a compiled-in constant, such as set a value from `optarg', set the + option's `flag' field to zero and its `val' field to a nonzero + value (the equivalent single-letter option character, if there is + one). For long options that have a zero `flag' field, `getopt' + returns the contents of the `val' field. */ + +struct option +{ +#if __STDC__ + const char *name; +#else + char *name; +#endif + /* has_arg can't be an enum because some compilers complain about + type mismatches in all the code that assumes it is an int. */ + int has_arg; + int *flag; + int val; +}; + +/* Names for the values of the `has_arg' field of `struct option'. */ + +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +#if __STDC__ +#if defined(__GNU_LIBRARY__) +/* Many other libraries have conflicting prototypes for getopt, with + differences in the consts, in stdlib.h. To avoid compilation + errors, only prototype getopt for the GNU C library. */ +extern int getopt (int argc, char *const *argv, const char *shortopts); +#else /* not __GNU_LIBRARY__ */ +extern int getopt (); +#endif /* not __GNU_LIBRARY__ */ +extern int getopt_long (int argc, char *const *argv, const char *shortopts, + const struct option *longopts, int *longind); +extern int getopt_long_only (int argc, char *const *argv, + const char *shortopts, + const struct option *longopts, int *longind); + +/* Internal only. Users should not call this directly. */ +extern int _getopt_internal (int argc, char *const *argv, + const char *shortopts, + const struct option *longopts, int *longind, + int long_only); +#else /* not __STDC__ */ +extern int getopt (); +extern int getopt_long (); +extern int getopt_long_only (); + +extern int _getopt_internal (); +#endif /* not __STDC__ */ + +#ifdef __cplusplus +} +#endif + +#endif /* _GETOPT_H */ diff --git a/kame/kame/tcpdump/win32/Include/inetprivate.h b/kame/kame/tcpdump/win32/Include/inetprivate.h new file mode 100644 index 0000000000..1052acf2de --- /dev/null +++ b/kame/kame/tcpdump/win32/Include/inetprivate.h @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include +#include +#include +//#include +#include +//#include + +#include + +extern void _sethtent(int f); +extern void _endhtent(void); +extern struct hostent *_gethtent(void); +extern struct hostent *_gethtbyname(const char *name); +extern struct hostent *_gethtbyaddr(const char *addr, int len, + int type); +extern int _validuser(FILE *hostf, const char *rhost, + const char *luser, const char *ruser, int baselen); +extern int _checkhost(const char *rhost, const char *lhost, int len); +#if 0 +extern void putlong(u_long l, u_char *msgp); +extern void putshort(u_short l, u_char *msgp); +extern u_int32_t _getlong(register const u_char *msgp); +extern u_int16_t _getshort(register const u_char *msgp); +extern void p_query(char *msg); +extern void fp_query(char *msg, FILE *file); +extern char *p_cdname(char *cp, char *msg, FILE *file); +extern char *p_rr(char *cp, char *msg, FILE *file); +extern char *p_type(int type); +extern char * p_class(int class); +extern char *p_time(u_long value); +#endif +extern char * hostalias(const char *name); +extern void sethostfile(char *name); +extern void _res_close (void); +extern void ruserpass(const char *host, char **aname, char **apass); diff --git a/kame/kame/tcpdump/win32/Include/telnet.h b/kame/kame/tcpdump/win32/Include/telnet.h new file mode 100644 index 0000000000..3309e5d727 --- /dev/null +++ b/kame/kame/tcpdump/win32/Include/telnet.h @@ -0,0 +1,320 @@ +/* + * 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 1 + +/* + * 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 +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 ascii 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 +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 NSLC 18 + +/* + * 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", 0, +#ifdef SLC_NAMES +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 + +#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 +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 +char *encrypt_names[] = { + "IS", "SUPPORT", "REPLY", "START", "END", + "REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID", + 0, +}; +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/kame/kame/tcpdump/win32/Include/w32_fzs.h b/kame/kame/tcpdump/win32/Include/w32_fzs.h new file mode 100644 index 0000000000..8b5e598d33 --- /dev/null +++ b/kame/kame/tcpdump/win32/Include/w32_fzs.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 1999 + * NetGroup, Politecnico di Torino (Italy) + * 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 Politecnico di Torino 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 COPYRIGHT HOLDERS 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 COPYRIGHT + * OWNER 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 _WINSOCKAPI_ +#define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */ +#endif /* _WINSOCKAPI_ */ +#include +#include + +extern int progress; +int wsockinit(); +void InitP(); +void PrintCapBegins (char* program_name, char* device); +extern char* AdapterName1; +#ifndef WIN95 +WCHAR* SChar2WChar(char* nome); +#else +BOOLEAN StartPacketDriver(LPTSTR ServiceName); +#endif diff --git a/kame/kame/tcpdump/win32/Src/getopt.c b/kame/kame/tcpdump/win32/Src/getopt.c new file mode 100644 index 0000000000..03c2086efd --- /dev/null +++ b/kame/kame/tcpdump/win32/Src/getopt.c @@ -0,0 +1,121 @@ +/* + * Copyright (c) 1987, 1993, 1994 + * 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 char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include + +int opterr = 1, /* if error message should be printed */ + optind = 1, /* index into parent argv vector */ + optopt, /* character checked for validity */ + optreset; /* reset getopt */ +char *optarg; /* argument associated with option */ + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" + +/* + * getopt -- + * Parse argc/argv argument vector. + */ +int +getopt(nargc, nargv, ostr) + int nargc; + char * const *nargv; + const char *ostr; +{ +#ifdef WIN32 + char *__progname="windump"; +#else + extern char *__progname; +#endif + static char *place = EMSG; /* option letter processing */ + char *oli; /* option letter list index */ + + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc || *(place = nargv[optind]) != '-') { + place = EMSG; + return (-1); + } + if (place[1] && *++place == '-') { /* found "--" */ + ++optind; + place = EMSG; + return (-1); + } + } /* option letter okay? */ + if ((optopt = (int)*place++) == (int)':' || + !(oli = strchr(ostr, optopt))) { + /* + * if the user didn't specify '-' as an option, + * assume it means -1. + */ + if (optopt == (int)'-') + return (-1); + if (!*place) + ++optind; + if (opterr && *ostr != ':') + (void)fprintf(stderr, + "%s: illegal option -- %c\n", __progname, optopt); + return (BADCH); + } + if (*++oli != ':') { /* don't need argument */ + optarg = NULL; + if (!*place) + ++optind; + } + else { /* need an argument */ + if (*place) /* no white space */ + optarg = place; + else if (nargc <= ++optind) { /* no arg */ + place = EMSG; + if (*ostr == ':') + return (BADARG); + if (opterr) + (void)fprintf(stderr, + "%s: option requires an argument -- %c\n", + __progname, optopt); + return (BADCH); + } + else /* white space */ + optarg = nargv[optind]; + place = EMSG; + ++optind; + } + return (optopt); /* dump back option letter */ +} diff --git a/kame/kame/tcpdump/win32/prj/GNUmakefile b/kame/kame/tcpdump/win32/prj/GNUmakefile new file mode 100644 index 0000000000..516c3e2ff7 --- /dev/null +++ b/kame/kame/tcpdump/win32/prj/GNUmakefile @@ -0,0 +1,141 @@ +# Makefile for cygwin gcc +# Nate Lawson + +# Location of your pcap src tree, build it first +PCAP_DIR = ../../../winpcap + +# OPTFLAGS = -g +OPTFLAGS = -O +# -O2 may break things. Use at your own risk. + +CFLAGS = -I ${PCAP_DIR}/wpcap/libpcap/bpf \ + -I ${PCAP_DIR}/wpcap/libpcap \ + -I ${PCAP_DIR}/wpcap/libpcap/Win32/Include \ + -I ${PCAP_DIR}/wpcap/libpcap/Win32/Include/net \ + -I ../../Win32/Include -I ../../linux-Include \ + -I ../../lbl -I../.. \ + -DWIN32 -DHAVE_ADDRINFO_H -DHAVE_PCAP_FINDALLDEVS \ + -DINET6 -DSIZEOF_CHAR=1 -DHAVE_SOCKADDR_STORAGE -DHAVE_PCAP_DUMP_FLUSH\ + -DSIZEOF_SHORT=2 -DSIZEOF_INT=4 -D_U_="__attribute__((unused))" \ + -mno-cygwin ${OPTFLAGS} +LDFLAGS = +LIBS = -L ${PCAP_DIR}/WPCAP/LIB -lwpcap -lwsock32 +OBJS = \ + ../../addrtoname.o \ + ../../gmpls.o \ + ../../gmt2local.o \ + ../../missing/inet_aton.o \ + ../../missing/inet_ntop.o \ + ../../missing/strlcpy.o \ + ../../missing/dlnames.o \ + ../../missing/datalinks.o \ + ../../missing/strsep.o \ + ../../missing/inet_pton.o \ + ../../machdep.o \ + ../../oui.o \ + ../../parsenfsfh.o \ + ../../print-802_11.o \ + ../../print-ah.o \ + ../../print-aodv.o \ + ../../print-ap1394.o \ + ../../print-arcnet.o \ + ../../print-arp.o \ + ../../print-ascii.o \ + ../../print-atalk.o \ + ../../print-atm.o \ + ../../print-beep.o \ + ../../print-bfd.o \ + ../../print-bgp.o \ + ../../print-bootp.o \ + ../../print-cdp.o \ + ../../print-chdlc.o \ + ../../print-cip.o \ + ../../print-cnfp.o \ + ../../print-decnet.o \ + ../../print-dhcp6.o \ + ../../print-domain.o \ + ../../print-dvmrp.o \ + ../../print-egp.o \ + ../../print-enc.o \ + ../../print-esp.o \ + ../../print-ether.o \ + ../../print-fddi.o \ + ../../print-fr.o \ + ../../print-frag6.o \ + ../../print-gre.o \ + ../../print-hsrp.o \ + ../../print-icmp.o \ + ../../print-icmp6.o \ + ../../print-igmp.o \ + ../../print-igrp.o \ + ../../print-ip.o \ + ../../print-ip6.o \ + ../../print-ip6opts.o \ + ../../print-ipcomp.o \ + ../../print-ipfc.o \ + ../../print-ipx.o \ + ../../print-isakmp.o \ + ../../print-isoclns.o \ + ../../print-krb.o \ + ../../print-l2tp.o \ + ../../print-lane.o \ + ../../print-ldp.o \ + ../../print-llc.o \ + ../../print-lwres.o \ + ../../print-mobile.o \ + ../../print-mobility.o \ + ../../print-mpls.o \ + ../../print-msdp.o \ + ../../print-nfs.o \ + ../../print-ntp.o \ + ../../print-null.o \ + ../../print-ospf.o \ + ../../print-ospf6.o \ + ../../print-pflog.o \ + ../../print-pim.o \ + ../../print-ppp.o \ + ../../print-pppoe.o \ + ../../print-pptp.o \ + ../../print-radius.o \ + ../../print-raw.o \ + ../../print-rip.o \ + ../../print-ripng.o \ + ../../print-rsvp.o \ + ../../print-rt6.o \ + ../../print-rx.o \ + ../../print-sctp.o \ + ../../print-sl.o \ + ../../print-sll.o \ + ../../print-smb.o \ + ../../print-snmp.o \ + ../../print-stp.o \ + ../../print-sunatm.o \ + ../../print-sunrpc.o \ + ../../print-symantec.o \ + ../../print-tcp.o \ + ../../print-telnet.o \ + ../../print-tftp.o \ + ../../print-timed.o \ + ../../print-token.o \ + ../../print-udp.o \ + ../../print-vjc.o \ + ../../print-vrrp.o \ + ../../print-wb.o \ + ../../print-zephyr.o \ + ../../setsignal.o \ + ../../smbutil.o \ + ../../tcpdump.o \ + ../../util.o \ + ../../Win32/src/getopt.o + +main: ${OBJS} + ${CC} ${CFLAGS} ${LDFLAGS} -o windump.exe ${OBJS} ${LIBS} + +install: windump.exe + cp windump.exe c:/windows + +clean: + rm -f ${OBJS} windump.exe + +.c.o: + ${CC} ${CFLAGS} -o $*.o -c $< diff --git a/kame/kame/tcpdump/win32/prj/WinDump.dsp b/kame/kame/tcpdump/win32/prj/WinDump.dsp new file mode 100644 index 0000000000..321133de4e --- /dev/null +++ b/kame/kame/tcpdump/win32/prj/WinDump.dsp @@ -0,0 +1,527 @@ +# Microsoft Developer Studio Project File - Name="WinDump" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=WinDump - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "WinDump.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "WinDump.mak" CFG="WinDump - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "WinDump - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "WinDump - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 1 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "WinDump - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "../../" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /I "../../../winpcap/wpcap/libpcap/bpf" /I "../../../winpcap/wpcap/libpcap" /I "../../../winpcap/wpcap/libpcap/Win32/Include" /I "../../../winpcap/wpcap/libpcap/Win32/Include/net" /I "../../Win32/Include" /I "../../linux-Include" /I "../../lbl" /I "../../" /I "../../../winpcap/wpcap/win32-extensions" /D "NDEBUG" /D HAVE_ADDRINFO=1 /D HAVE_PCAP_DUMP_FLUSH=1 /D HAVE_PCAP_FINDALLDEVS=1 /D "_CONSOLE" /D "__STDC__" /D "INET6" /D "WIN32" /D "_MBCS" /D SIZEOF_CHAR=1 /D SIZEOF_SHORT=2 /D SIZEOF_INT=4 /D "WPCAP" /D "HAVE_SOCKADDR_STORAGE" /D _U_= /YX /FD /c +# ADD BASE RSC /l 0x410 /d "NDEBUG" +# ADD RSC /l 0x410 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib wpcap.lib /nologo /subsystem:console /machine:I386 /out:"release/WinDump.exe" /libpath:"../../../winpcap/wpcap/lib" + +!ELSEIF "$(CFG)" == "WinDump - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "WinDump_" +# PROP BASE Intermediate_Dir "WinDump_" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "../../" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /Gm /Gi /GX /ZI /I "../../../winpcap/wpcap/libpcap/bpf" /I "../../../winpcap/wpcap/libpcap" /I "../../../winpcap/wpcap/libpcap/Win32/Include" /I "../../../winpcap/wpcap/libpcap/Win32/Include/net" /I "../../Win32/Include" /I "../../linux-Include" /I "../../lbl" /I "../../" /I "../../../winpcap/wpcap/win32-extensions" /D "_DEBUG" /D "_WINDOWS" /D "HAVE_ADDRINFO" /D HAVE_PCAP_FINDALLDEVS=1 /D "_CONSOLE" /D "__STDC__" /D "INET6" /D "WIN32" /D "_MBCS" /D SIZEOF_CHAR=1 /D SIZEOF_SHORT=2 /D SIZEOF_INT=4 /D "WPCAP" /D "HAVE_SOCKADDR_STORAGE" /D HAVE_PCAP_DUMP_FLUSH=1 /D _U_= /FR /YX /FD /c +# ADD BASE RSC /l 0x410 /d "_DEBUG" +# ADD RSC /l 0x410 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 wpcap.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /map /debug /debugtype:both /machine:I386 /out:"debug/WinDump.exe" /pdbtype:sept /libpath:"../../../winpcap/wpcap/lib" +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "WinDump - Win32 Release" +# Name "WinDump - Win32 Debug" +# Begin Source File + +SOURCE=..\..\addrtoname.c +# End Source File +# Begin Source File + +SOURCE=..\..\bpf_dump.c +# End Source File +# Begin Source File + +SOURCE=..\..\missing\datalinks.c +# End Source File +# Begin Source File + +SOURCE=..\..\missing\dlnames.c +# End Source File +# Begin Source File + +SOURCE=..\Src\getopt.c +# End Source File +# Begin Source File + +SOURCE=..\..\gmpls.c +# End Source File +# Begin Source File + +SOURCE=..\..\gmt2local.c +# End Source File +# Begin Source File + +SOURCE=..\..\missing\inet_aton.c +# End Source File +# Begin Source File + +SOURCE=..\..\missing\inet_ntop.c +# End Source File +# Begin Source File + +SOURCE=..\..\missing\inet_pton.c +# End Source File +# Begin Source File + +SOURCE=..\..\machdep.c +# End Source File +# Begin Source File + +SOURCE=..\..\oui.c +# End Source File +# Begin Source File + +SOURCE=..\..\parsenfsfh.c +# End Source File +# Begin Source File + +SOURCE="..\..\print-802_11.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-ah.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-aodv.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-ap1394.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-arcnet.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-arp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-ascii.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-atalk.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-atm.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-beep.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-bfd.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-bgp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-bootp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-cdp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-chdlc.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-cip.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-cnfp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-decnet.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-dhcp6.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-domain.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-dvmrp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-egp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-enc.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-esp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-ether.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-fddi.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-fr.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-frag6.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-gre.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-hsrp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-icmp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-icmp6.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-igmp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-igrp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-ip.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-ip6.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-ip6opts.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-ipcomp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-ipfc.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-ipx.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-isakmp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-isoclns.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-krb.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-l2tp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-lane.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-ldp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-llc.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-lwres.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-mobile.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-mobility.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-mpls.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-msdp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-netbios.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-nfs.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-ntp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-null.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-ospf.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-ospf6.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-pflog.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-pim.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-ppp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-pppoe.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-pptp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-radius.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-raw.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-rip.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-ripng.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-rsvp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-rt6.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-rx.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-sctp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-sl.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-sll.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-smb.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-snmp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-stp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-sunatm.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-sunrpc.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-symantec.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-tcp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-telnet.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-tftp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-timed.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-token.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-udp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-vjc.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-vrrp.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-wb.c" +# End Source File +# Begin Source File + +SOURCE="..\..\print-zephyr.c" +# End Source File +# Begin Source File + +SOURCE=..\..\setsignal.c +# End Source File +# Begin Source File + +SOURCE=..\..\smbutil.c +# End Source File +# Begin Source File + +SOURCE=..\..\strcasecmp.c +# End Source File +# Begin Source File + +SOURCE=..\..\missing\strlcat.c +# End Source File +# Begin Source File + +SOURCE=..\..\missing\strlcpy.c +# End Source File +# Begin Source File + +SOURCE=..\..\missing\strsep.c +# End Source File +# Begin Source File + +SOURCE=..\..\Tcpdump.c +# End Source File +# Begin Source File + +SOURCE=..\..\util.c +# End Source File +# End Target +# End Project diff --git a/kame/kame/tcpdump/win32/prj/WinDump.dsw b/kame/kame/tcpdump/win32/prj/WinDump.dsw new file mode 100644 index 0000000000..6bf740813b --- /dev/null +++ b/kame/kame/tcpdump/win32/prj/WinDump.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "WinDump"=".\WinDump.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### +