diff options
Diffstat (limited to 'contrib')
102 files changed, 20088 insertions, 456 deletions
diff --git a/contrib/tcpdump/CHANGES b/contrib/tcpdump/CHANGES index 9639d41..c11b9d3 100644 --- a/contrib/tcpdump/CHANGES +++ b/contrib/tcpdump/CHANGES @@ -1,4 +1,48 @@ -@(#) $Header: CHANGES,v 1.54 98/07/25 12:41:06 leres Exp $ (LBL) +v3.5 Fri Jan 28 18:00:00 PST 2000 + +Bill Fenner <fenner@research.att.com> +- 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 <assar@sics.se> +- 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 <kenh@cmf.nrl.navy.mil> +- bring in code at + /afs/transarc.com/public/afs-contrib/tools/tcpdump for parsing + AFS3 packets + +Andrew Tridgell <tridge@linuxcare.com> +- SMB printing code + +Love <lha@stacken.kth.se> +- print-rx.c: add code for printing MakeDir and StoreStatus. Also + change date format to the right one. + +Michael C. Richardson <mcr@sandelman.ottawa.on.ca> +- Created tcpdump.org repository + v3.4 Sat Jul 25 12:40:55 PDT 1998 @@ -513,3 +557,5 @@ v2.0.1 Sun Jan 26 21:10:10 PDT v2.0 Sun Jan 13 12:20:40 PST 1991 - Initial public release. + +@(#) $Header: /tcpdump/master/tcpdump/CHANGES,v 1.63.2.1 2000/01/27 23:18:19 fenner Exp $ (LBL) diff --git a/contrib/tcpdump/INSTALL b/contrib/tcpdump/INSTALL index edb4b1b..8a39565 100644 --- a/contrib/tcpdump/INSTALL +++ b/contrib/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.36.1.1.2.2 2000/01/29 17:02:09 itojun Exp $ (LBL) If you have not built libpcap, do so first. See the README file in this directory for the ftp location. @@ -37,21 +37,25 @@ 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: +around this, comment out: - -DETHER_HEADER_HAS_EA=1 -DETHER_ARP_HAS_EA=1 +#define ETHER_HEADER_HAS_EA 1 +and +#define ETHER_ARP_HAS_EA 1 -from the Makefile after running configure (and before attempting to -compile tcpdump. +from config.h after running configure (and before attempting to +compile tcpdump). Another workaround is to use gcc. 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. + +== Tested platforms == +NetBSD 1.4.1/i386 (mcr) +RedHat Linux 6.1/i386 (assar) + FILES ----- @@ -60,20 +64,24 @@ FILES - list of files exported as part of the distribution INSTALL - this file Makefile.in - compilation rules (input to the configure script) README - description of distribution +README-AFS - 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 appletalk.h - AppleTalk definitions atime.awk - TCP ack awk script -bcopy.c - missing routine bootp.h - BOOTP definitions bpf_dump.c - bpf instruction pretty-printer routine 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 +dhcp6.h - IPv6 DHCP definitions +dhcp6opt.h - IPv6 DHCP options ethertype.h - ethernet definitions extract.h - alignment definitions fddi.h - Fiber Distributed Data Interface definitions @@ -82,7 +90,11 @@ gmt2local.h - time conversion prototypes igrp.h - Interior Gateway Routing Protocol definitions install-sh - BSD style install script interface.h - globals, prototypes and definitions +ipsec_doi.h - ISAKMP packet definitions - RFC2407 ipx.h - IPX definitions +isakmp.h - ISAKMP packet definitions - RFC2408 +l2tp.h - +lane.h - lbl/gnuc.h - gcc macros and defines lbl/os-*.h - os dependent defines and prototypes linux-include/* - network include files missing on Linux @@ -91,53 +103,86 @@ 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 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 ppp.h - Point to Point Protocol definitions +print-ah.c - IPSEC Authentication Header 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-bgp.c - Border Gateway Protocol printer routines +print-bootp.c - BOOTP and IPv4 DHCP printer routines +print-chdlc.c - CHDLC printer routines +print-cip.c - 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-egp.c - External Gateway Protocol 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-frag6.c - IPv6 fragmentation header printer routines print-gre.c - Generic Routing Encapsulation printer routines print-icmp.c - Internet Control Message Protocol printer routines +print-icmp6.c - IPv6 Internet Control Message Protocol printer routines print-igrp.c - Interior Gateway Routing Protocol 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-isakmp.c - Internet Security Association and Key Management Protocol print-isoclns.c - isoclns printer routines print-krb.c - Kerberos printer routines +print-l2tp.c - Layer Two Tunneling Protocol printer routines +print-lane.c - +print-lcp.c - print-llc.c - llc printer routines +print-mobile.c - IPv4 mobility printer routines print-netbios.c - netbios 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-ospf.c - Open Shortest Path First printer routines +print-ospf6.c - IPv6 Open Shortest Path First printer routines print-pim.c - Protocol Independent Multicast printer routines print-ppp.c - Point to Point Protocol printer routines +print-pppoe.c - print-raw.c - raw printer routines print-rip.c - Routing Information Protocol printer routines +print-ripng.c - IPv6 Routing Information Protocol printer routines +print-rt6.c - IPv6 routing header printer routines +print-rx.c - AFS RX printer routines print-sl.c - Compressed Serial Line Internet Protocol printer routines +print-smb.c - SMB (samba) printer routines print-snmp.c - Simple Network Management Protocol 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-udp.c - UDP printer routines +print-vjc.c - PPP Van Jacovson compression (RFC1144) printer routines print-wb.c - white board printer routines -savestr.c - savestr prototypes -savestr.h - strdup() replacement +route6d.h - packet definition for IPv6 Routing Information Protocol +rx.h - +savestr.c - strdup() replacement +savestr.h - savestr prototypes send-ack.awk - unidirectional tcp send/ack awk script setsignal.c - os independent signal routines setsignal.h - os independent signal prototypes +smb.h - +smbutil.c - stime.awk - TCP send awk script strcasecmp.c - missing routine tcpdump.1 - manual entry diff --git a/contrib/tcpdump/Makefile.in b/contrib/tcpdump/Makefile.in index 2ad1b24..57a4bc2 100644 --- a/contrib/tcpdump/Makefile.in +++ b/contrib/tcpdump/Makefile.in @@ -17,7 +17,7 @@ # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. # -# @(#) $Header: Makefile.in,v 1.207 97/08/17 13:53:29 leres Exp $ (LBL) +# @(#) $Header: /tcpdump/master/tcpdump/Makefile.in,v 1.219 1999/12/22 15:44:09 itojun Exp $ (LBL) # # Various configurable paths (remember to edit Makefile.in, not Makefile) @@ -43,7 +43,7 @@ CC = @CC@ PROG = tcpdump CCOPT = @V_CCOPT@ INCLS = -I. @V_INCLS@ -DEFS = @DEFS@ -DHAVE_FDDI +DEFS = @DEFS@ # Standard CFLAGS CFLAGS = $(CCOPT) $(DEFS) $(INCLS) @@ -72,9 +72,14 @@ CSRC = tcpdump.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 -LOCALSRC = + parsenfsfh.c util.c savestr.c setsignal.c \ + print-esp.c print-ah.c print-vjc.c print-isakmp.c print-chdlc.c \ + print-ipcomp.c print-mobile.c print-l2tp.c print-bgp.c print-rx.c \ + print-lane.c print-cip.c print-pppoe.c print-lcp.c \ + print-smb.c smbutil.c print-ascii.c print-telnet.c +LOCALSRC = @LOCALSRC@ GENSRC = version.c +LIBOBJS = @LIBOBJS@ SRC = $(CSRC) $(GENSRC) $(LOCALSRC) @@ -82,9 +87,11 @@ SRC = $(CSRC) $(GENSRC) $(LOCALSRC) # hack the extra indirection 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 interface.h igrp.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 + savestr.c setsignal.h \ + gnuc.h ipsec_doi.h isakmp.h l2tp.h netbios.h oakley.h ospf6.h ppp.h \ + route6d.h TAGHDR = \ /usr/include/arpa/tftp.h \ @@ -107,16 +114,31 @@ $(PROG): $(OBJ) @V_PCAPDEP@ @rm -f $@ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) +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 + version.o: version.c + $(CC) $(CFLAGS) -c version.c + version.c: $(srcdir)/VERSION @rm -f $@ sed -e 's/.*/char version[] = "&";/' $(srcdir)/VERSION > $@ install: force + [ -d $(DESTDIR)$(BINDEST) ] || mkdir -p $(DESTDIR)$(BINDEST) $(INSTALL) -m 550 -o bin -g @V_GROUP@ $(PROG) \ $(DESTDIR)$(BINDEST)/$(PROG) install-man: force + [ -d $(DESTDIR)$(MANDEST)/man1 ] || mkdir -p $(DESTDIR)$(MANDEST)/man1 $(INSTALL) -m 444 -o bin -g bin $(srcdir)/$(PROG).1 \ $(DESTDIR)$(MANDEST)/man1/$(PROG).1 @@ -130,7 +152,7 @@ clean: distclean: rm -f $(CLEANFILES) Makefile config.cache config.log config.status \ - gnuc.h os-proto.h + config.h gnuc.h os-proto.h tags: $(TAGFILES) ctags -wtd $(TAGFILES) diff --git a/contrib/tcpdump/README b/contrib/tcpdump/README index b607c4f..644181a 100644 --- a/contrib/tcpdump/README +++ b/contrib/tcpdump/README @@ -1,4 +1,4 @@ -@(#) $Header: README,v 1.54 98/01/27 21:36:20 vern Exp $ (LBL) +@(#) $Header: /tcpdump/master/tcpdump/README,v 1.54.1.1 1999/10/07 23:47:09 mcr Exp $ (LBL) TCPDUMP 3.4 Lawrence Berkeley National Laboratory diff --git a/contrib/tcpdump/VERSION b/contrib/tcpdump/VERSION index 2f4b607..5a95802 100644 --- a/contrib/tcpdump/VERSION +++ b/contrib/tcpdump/VERSION @@ -1 +1 @@ -3.4 +3.5 diff --git a/contrib/tcpdump/acconfig.h b/contrib/tcpdump/acconfig.h new file mode 100644 index 0000000..5721258 --- /dev/null +++ b/contrib/tcpdump/acconfig.h @@ -0,0 +1,106 @@ +/* "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 XXX why isn't this HAVE_LIBCRYPTO? */ +#undef CRYPTO + +/* Define if you have SSLeay 0.9.0b with the buggy cast128. */ +#undef HAVE_BUGGY_CAST128 + +/* Define both to enable IPv6 support XXX why 2? ENABLE_IPV6 is not used. */ +#undef ENABLE_IPV6 +#undef INET6 + +/* Define if you enable support for the libsmi. */ +#undef LIBSMI + +/* Define if you have the <smi.h> header file. */ +#undef HAVE_SMI_H + +/* Is T_AAAA predefined? */ +#undef HAVE_AAAA + +/* Fallback definition if not in headers */ +/* XXX why is this not #ifndef HAVE_AAA #define T_AAAA ... ? */ +/* XXX or even #ifndef T_AAAA ... */ +#undef T_AAAA + +/* 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.arp_sha is a struct with ether_addr_octet + */ +#undef ETHER_ARP_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 you have <net/slip.h> */ +#undef HAVE_NET_SLIP_H + +/* define if this is a development version, to use additional prototypes. */ +#undef HAVE_OS_PROTO_H + +/* define if <unistd.h> 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 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 + +/* OSF hack: "Workaround around ip_hl vs. ip_vhl problem in netinet/ip.h" */ +#undef __STDC__ + +/* Workaround for missing sized types */ +/* XXX this should move to the more standard uint*_t */ +#undef int16_t +#undef int32_t +#undef u_int16_t +#undef u_int32_t +#undef u_int8_t diff --git a/contrib/tcpdump/addrtoname.h b/contrib/tcpdump/addrtoname.h index 9c43cb8..72e79b8 100644 --- a/contrib/tcpdump/addrtoname.h +++ b/contrib/tcpdump/addrtoname.h @@ -18,7 +18,7 @@ * 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.16 1999/10/30 05:11:07 itojun Exp $ (LBL) */ /* Name to address translation routines. */ @@ -28,9 +28,18 @@ extern char *etherproto_string(u_short); extern char *tcpport_string(u_short); extern char *udpport_string(u_short); extern char *getname(const u_char *); +#ifdef INET6 +extern char *getname6(const u_char *); +#endif extern char *intoa(u_int32_t); extern void init_addrtoname(u_int32_t, u_int32_t); extern struct hnamemem *newhnamemem(void); +#ifdef INET6 +extern struct h6namemem *newh6namemem(void); +#endif #define ipaddr_string(p) getname((const u_char *)(p)) +#ifdef INET6 +#define ip6addr_string(p) getname6((const u_char *)(p)) +#endif diff --git a/contrib/tcpdump/appletalk.h b/contrib/tcpdump/appletalk.h index 4f690f9..766982e 100644 --- a/contrib/tcpdump/appletalk.h +++ b/contrib/tcpdump/appletalk.h @@ -20,7 +20,7 @@ * * 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.12.1.1 1999/10/07 23:47:09 mcr Exp $ (LBL) */ struct LAP { diff --git a/contrib/tcpdump/bootp.h b/contrib/tcpdump/bootp.h index bb872c2..bea254e 100644 --- a/contrib/tcpdump/bootp.h +++ b/contrib/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.8 1999/10/17 23:35:46 mcr Exp $ (LBL) */ /* * Bootstrap Protocol (BOOTP). RFC951 and RFC1048. * @@ -27,7 +27,7 @@ struct bootp { unsigned char bp_hops; /* gateway hops */ u_int32_t bp_xid; /* transaction ID */ unsigned short bp_secs; /* seconds since boot began */ - unsigned short bp_unused; + unsigned short bp_flags; /* flags: 0x8000 is broadcast */ struct in_addr bp_ciaddr; /* client IP address */ struct in_addr bp_yiaddr; /* 'your' IP address */ struct in_addr bp_siaddr; /* server IP address */ @@ -86,7 +86,74 @@ struct bootp { #define TAG_SWAP_SERVER ((unsigned char) 16) #define TAG_ROOTPATH ((unsigned char) 17) #define TAG_EXTPATH ((unsigned char) 18) - +/* RFC2132 */ +#define TAG_IP_FORWARD ((unsigned char) 19) +#define TAG_NL_SRCRT ((unsigned char) 20) +#define TAG_PFILTERS ((unsigned char) 21) +#define TAG_REASS_SIZE ((unsigned char) 22) +#define TAG_DEF_TTL ((unsigned char) 23) +#define TAG_MTU_TIMEOUT ((unsigned char) 24) +#define TAG_MTU_TABLE ((unsigned char) 25) +#define TAG_INT_MTU ((unsigned char) 26) +#define TAG_LOCAL_SUBNETS ((unsigned char) 27) +#define TAG_BROAD_ADDR ((unsigned char) 28) +#define TAG_DO_MASK_DISC ((unsigned char) 29) +#define TAG_SUPPLY_MASK ((unsigned char) 30) +#define TAG_DO_RDISC ((unsigned char) 31) +#define TAG_RTR_SOL_ADDR ((unsigned char) 32) +#define TAG_STATIC_ROUTE ((unsigned char) 33) +#define TAG_USE_TRAILERS ((unsigned char) 34) +#define TAG_ARP_TIMEOUT ((unsigned char) 35) +#define TAG_ETH_ENCAP ((unsigned char) 36) +#define TAG_TCP_TTL ((unsigned char) 37) +#define TAG_TCP_KEEPALIVE ((unsigned char) 38) +#define TAG_KEEPALIVE_GO ((unsigned char) 39) +#define TAG_NIS_DOMAIN ((unsigned char) 40) +#define TAG_NIS_SERVERS ((unsigned char) 41) +#define TAG_NTP_SERVERS ((unsigned char) 42) +#define TAG_VENDOR_OPTS ((unsigned char) 43) +#define TAG_NETBIOS_NS ((unsigned char) 44) +#define TAG_NETBIOS_DDS ((unsigned char) 45) +#define TAG_NETBIOS_NODE ((unsigned char) 46) +#define TAG_NETBIOS_SCOPE ((unsigned char) 47) +#define TAG_XWIN_FS ((unsigned char) 48) +#define TAG_XWIN_DM ((unsigned char) 49) +#define TAG_NIS_P_DOMAIN ((unsigned char) 64) +#define TAG_NIS_P_SERVERS ((unsigned char) 65) +#define TAG_MOBILE_HOME ((unsigned char) 68) +#define TAG_SMPT_SERVER ((unsigned char) 69) +#define TAG_POP3_SERVER ((unsigned char) 70) +#define TAG_NNTP_SERVER ((unsigned char) 71) +#define TAG_WWW_SERVER ((unsigned char) 72) +#define TAG_FINGER_SERVER ((unsigned char) 73) +#define TAG_IRC_SERVER ((unsigned char) 74) +#define TAG_STREETTALK_SRVR ((unsigned char) 75) +#define TAG_STREETTALK_STDA ((unsigned char) 76) +/* DHCP options */ +#define TAG_REQUESTED_IP ((unsigned char) 50) +#define TAG_IP_LEASE ((unsigned char) 51) +#define TAG_OPT_OVERLOAD ((unsigned char) 52) +#define TAG_TFTP_SERVER ((unsigned char) 66) +#define TAG_BOOTFILENAME ((unsigned char) 67) +#define TAG_DHCP_MESSAGE ((unsigned char) 53) +#define TAG_SERVER_ID ((unsigned char) 54) +#define TAG_PARM_REQUEST ((unsigned char) 55) +#define TAG_MESSAGE ((unsigned char) 56) +#define TAG_MAX_MSG_SIZE ((unsigned char) 57) +#define TAG_RENEWAL_TIME ((unsigned char) 58) +#define TAG_REBIND_TIME ((unsigned char) 59) +#define TAG_VENDOR_CLASS ((unsigned char) 60) +#define TAG_CLIENT_ID ((unsigned char) 61) + +/* 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 /* diff --git a/contrib/tcpdump/bpf_dump.c b/contrib/tcpdump/bpf_dump.c index 8364325..8e799ce 100644 --- a/contrib/tcpdump/bpf_dump.c +++ b/contrib/tcpdump/bpf_dump.c @@ -20,7 +20,11 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: bpf_dump.c,v 1.9 96/09/26 23:11:04 leres Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/bpf_dump.c,v 1.10 1999/11/21 09:36:44 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/types.h> diff --git a/contrib/tcpdump/config.h.in b/contrib/tcpdump/config.h.in new file mode 100644 index 0000000..f07e42a --- /dev/null +++ b/contrib/tcpdump/config.h.in @@ -0,0 +1,220 @@ +/* config.h.in. Generated automatically 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 to empty if the keyword does not work. */ +#undef const + +/* Define as __inline if that's what the C compiler calls it. */ +#undef inline + +/* Define as the return type of signal handlers (int or void). */ +#undef RETSIGTYPE + +/* Define if you can safely include both <sys/time.h> and <time.h>. */ +#undef TIME_WITH_SYS_TIME + +/* Define if your processor stores words with the most significant + byte first (like Motorola and SPARC, unlike Intel and VAX). */ +#undef WORDS_BIGENDIAN + +/* Define if you have SSLeay XXX why isn't this HAVE_LIBCRYPTO? */ +#undef CRYPTO + +/* Define if you have SSLeay 0.9.0b with the buggy cast128. */ +#undef HAVE_BUGGY_CAST128 + +/* Define both to enable IPv6 support XXX why 2? ENABLE_IPV6 is not used. */ +#undef ENABLE_IPV6 +#undef INET6 + +/* Define if you enable support for the libsmi. */ +#undef LIBSMI + +/* Is T_AAAA predefined? */ +#undef HAVE_AAAA + +/* Fallback definition if not in headers */ +/* XXX why is this not #ifndef HAVE_AAA #define T_AAAA ... ? */ +/* XXX or even #ifndef T_AAAA ... */ +#undef T_AAAA + +/* 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.arp_sha is a struct with ether_addr_octet + */ +#undef ETHER_ARP_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 you have <net/slip.h> */ +#undef HAVE_NET_SLIP_H + +/* define if this is a development version, to use additional prototypes. */ +#undef HAVE_OS_PROTO_H + +/* define if <unistd.h> 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 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 + +/* OSF hack: "Workaround around ip_hl vs. ip_vhl problem in netinet/ip.h" */ +#undef __STDC__ + +/* Workaround for missing sized types */ +/* XXX this should move to the more standard uint*_t */ +#undef int16_t +#undef int32_t +#undef u_int16_t +#undef u_int32_t +#undef u_int8_t + +/* The number of bytes in a char. */ +#undef SIZEOF_CHAR + +/* The number of bytes in a int. */ +#undef SIZEOF_INT + +/* The number of bytes in a long. */ +#undef SIZEOF_LONG + +/* The number of bytes in a short. */ +#undef SIZEOF_SHORT + +/* Define if you have the ether_ntohost function. */ +#undef HAVE_ETHER_NTOHOST + +/* Define if you have the getaddrinfo function. */ +#undef HAVE_GETADDRINFO + +/* Define if you have the gethostbyname2 function. */ +#undef HAVE_GETHOSTBYNAME2 + +/* Define if you have the getnameinfo function. */ +#undef HAVE_GETNAMEINFO + +/* Define if you have the inet_aton function. */ +#undef HAVE_INET_ATON + +/* Define if you have the inet_ntop function. */ +#undef HAVE_INET_NTOP + +/* Define if you have the inet_pton function. */ +#undef HAVE_INET_PTON + +/* Define if you have the pfopen function. */ +#undef HAVE_PFOPEN + +/* Define if you have the setlinebuf function. */ +#undef HAVE_SETLINEBUF + +/* Define if you have the sigaction function. */ +#undef HAVE_SIGACTION + +/* Define if you have the sigset function. */ +#undef HAVE_SIGSET + +/* Define if you have the strcasecmp function. */ +#undef HAVE_STRCASECMP + +/* Define if you have the vfprintf function. */ +#undef HAVE_VFPRINTF + +/* Define if you have the <cast.h> header file. */ +#undef HAVE_CAST_H + +/* Define if you have the <fcntl.h> header file. */ +#undef HAVE_FCNTL_H + +/* Define if you have the <malloc.h> header file. */ +#undef HAVE_MALLOC_H + +/* Define if you have the <memory.h> header file. */ +#undef HAVE_MEMORY_H + +/* Define if you have the <net/slip.h> header file. */ +#undef HAVE_NET_SLIP_H + +/* Define if you have the <rc5.h> header file. */ +#undef HAVE_RC5_H + +/* Define if you have the <rpc/rpcent.h> header file. */ +#undef HAVE_RPC_RPCENT_H + +/* Define if you have the <smi.h> header file. */ +#undef HAVE_SMI_H + +/* Define if you have the <zlib.h> header file. */ +#undef HAVE_ZLIB_H + +/* Define if you have the crypto library (-lcrypto). */ +#undef HAVE_LIBCRYPTO + +/* Define if you have the dnet library (-ldnet). */ +#undef HAVE_LIBDNET + +/* Define if you have the resolv library (-lresolv). */ +#undef HAVE_LIBRESOLV + +/* Define if you have the rpc library (-lrpc). */ +#undef HAVE_LIBRPC + +/* Define if you have the smi library (-lsmi). */ +#undef HAVE_LIBSMI + +/* Define if you have the socket library (-lsocket). */ +#undef HAVE_LIBSOCKET + +/* Define if you have the str library (-lstr). */ +#undef HAVE_LIBSTR + +/* Define if you have the z library (-lz). */ +#undef HAVE_LIBZ diff --git a/contrib/tcpdump/configure b/contrib/tcpdump/configure index 3afbf90..3c5cfa4 100755 --- a/contrib/tcpdump/configure +++ b/contrib/tcpdump/configure @@ -1,7 +1,7 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated automatically using autoconf version 2.12 +# Generated automatically using autoconf version 2.13 # Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc. # # This configure script is free software; the Free Software Foundation @@ -13,6 +13,9 @@ 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 enable ipv6 (with ipv4) support + --disable-ipv6 disable ipv6 support" # Initialize some variables set by options. # The variables have the same names as the options, with @@ -51,6 +54,7 @@ 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 @@ -334,7 +338,7 @@ EOF verbose=yes ;; -version | --version | --versio | --versi | --vers) - echo "configure generated by autoconf version 2.12" + echo "configure generated by autoconf version 2.13" exit 0 ;; -with-* | --with-*) @@ -504,9 +508,11 @@ 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 $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 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 @@ -563,33 +569,33 @@ esac # Make sure we can run config.sub. -if $ac_config_sub sun4 >/dev/null 2>&1; then : +if ${CONFIG_SHELL-/bin/sh} $ac_config_sub sun4 >/dev/null 2>&1; then : else { echo "configure: error: can not run $ac_config_sub" 1>&2; exit 1; } fi echo $ac_n "checking host system type""... $ac_c" 1>&6 -echo "configure:572: checking host system type" >&5 +echo "configure:578: checking host system type" >&5 host_alias=$host case "$host_alias" in NONE) case $nonopt in NONE) - if host_alias=`$ac_config_guess`; then : + 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 -host=`$ac_config_sub $host_alias` +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:593: checking target system type" >&5 +echo "configure:599: checking target system type" >&5 target_alias=$target case "$target_alias" in @@ -600,14 +606,14 @@ NONE) esac ;; esac -target=`$ac_config_sub $target_alias` +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:611: checking build system type" >&5 +echo "configure:617: checking build system type" >&5 build_alias=$build case "$build_alias" in @@ -618,7 +624,7 @@ NONE) esac ;; esac -build=`$ac_config_sub $build_alias` +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/'` @@ -649,7 +655,7 @@ 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" @@ -661,15 +667,16 @@ fi # 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:665: checking for $ac_word" >&5 +echo "configure:671: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_SHLICC2'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$SHLICC2"; then ac_cv_prog_SHLICC2="$SHLICC2" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" - for ac_dir in $PATH; do + 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" @@ -701,15 +708,16 @@ fi # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:705: checking for $ac_word" >&5 +echo "configure:712: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" - for ac_dir in $PATH; do + 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" @@ -730,16 +738,17 @@ 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:734: checking for $ac_word" >&5 +echo "configure:742: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" ac_prog_rejected=no - for ac_dir in $PATH; do + 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 @@ -774,25 +783,61 @@ else echo "$ac_t""no" 1>&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:793: checking for $ac_word" >&5 +if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + 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" +fi +fi +CC="$ac_cv_prog_CC" +if test -n "$CC"; then + echo "$ac_t""$CC" 1>&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; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:782: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 +echo "configure:825: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. ac_cpp='$CPP $CPPFLAGS' ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 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 -cat > conftest.$ac_ext <<EOF -#line 792 "configure" +cat > conftest.$ac_ext << EOF + +#line 836 "configure" #include "confdefs.h" + main(){return(0);} EOF -if { (eval echo configure:796: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:841: \"$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 @@ -806,18 +851,24 @@ else 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:816: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 +echo "configure:867: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 cross_compiling=$ac_cv_prog_cc_cross echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 -echo "configure:821: checking whether we are using GNU C" >&5 +echo "configure:872: checking whether we are using GNU C" >&5 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -826,7 +877,7 @@ else yes; #endif EOF -if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:830: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then +if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:881: \"$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 @@ -837,11 +888,15 @@ echo "$ac_t""$ac_cv_prog_gcc" 1>&6 if test $ac_cv_prog_gcc = yes; then GCC=yes - 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:845: checking whether ${CC-cc} accepts -g" >&5 +else + GCC= +fi + +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:900: 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 @@ -856,16 +911,20 @@ rm -f conftest* fi echo "$ac_t""$ac_cv_prog_cc_g" 1>&6 - if test "$ac_test_CFLAGS" = set; then - CFLAGS="$ac_save_CFLAGS" - elif test $ac_cv_prog_cc_g = yes; then +if test "$ac_test_CFLAGS" = set; then + CFLAGS="$ac_save_CFLAGS" +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then CFLAGS="-g -O2" else - CFLAGS="-O2" + CFLAGS="-g" fi else - GCC= - test "${CFLAGS+set}" = set || CFLAGS="-g" + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi fi if test "$GCC" = yes ; then @@ -874,7 +933,7 @@ fi V_CCOPT="-O2" else echo $ac_n "checking gcc version""... $ac_c" 1>&6 -echo "configure:878: checking gcc version" >&5 +echo "configure:937: checking gcc version" >&5 if eval "test \"`echo '$''{'ac_cv_lbl_gcc_vers'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -892,19 +951,19 @@ fi fi else echo $ac_n "checking that $CC handles ansi prototypes""... $ac_c" 1>&6 -echo "configure:896: checking that $CC handles ansi prototypes" >&5 +echo "configure:955: checking that $CC handles ansi prototypes" >&5 if eval "test \"`echo '$''{'ac_cv_lbl_cc_ansi_prototypes'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 901 "configure" +#line 960 "configure" #include "confdefs.h" #include <sys/types.h> int main() { int frob(int, char *) ; return 0; } EOF -if { (eval echo configure:908: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:967: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_lbl_cc_ansi_prototypes=yes else @@ -922,21 +981,21 @@ fi hpux*) echo $ac_n "checking for HP-UX ansi compiler ($CC -Aa -D_HPUX_SOURCE)""... $ac_c" 1>&6 -echo "configure:926: checking for HP-UX ansi compiler ($CC -Aa -D_HPUX_SOURCE)" >&5 +echo "configure:985: checking for HP-UX ansi compiler ($CC -Aa -D_HPUX_SOURCE)" >&5 savedcflags="$CFLAGS" CFLAGS="-Aa -D_HPUX_SOURCE $CFLAGS" if eval "test \"`echo '$''{'ac_cv_lbl_cc_hpux_cc_aa'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 933 "configure" +#line 992 "configure" #include "confdefs.h" #include <sys/types.h> int main() { int frob(int, char *) ; return 0; } EOF -if { (eval echo configure:940: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:999: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_lbl_cc_hpux_cc_aa=yes else @@ -980,12 +1039,12 @@ EOF ultrix*) echo $ac_n "checking that Ultrix $CC hacks const in prototypes""... $ac_c" 1>&6 -echo "configure:984: checking that Ultrix $CC hacks const in prototypes" >&5 +echo "configure:1043: checking that Ultrix $CC hacks const in prototypes" >&5 if eval "test \"`echo '$''{'ac_cv_lbl_cc_const_proto'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 989 "configure" +#line 1048 "configure" #include "confdefs.h" #include <sys/types.h> int main() { @@ -993,7 +1052,7 @@ struct a { int b; }; void c(const struct a *) ; return 0; } EOF -if { (eval echo configure:997: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1056: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_lbl_cc_const_proto=yes else @@ -1016,9 +1075,49 @@ EOF esac fi +echo $ac_n "checking for inline""... $ac_c" 1>&6 +echo "configure:1080: checking for inline" >&5 +if eval "test \"`echo '$''{'ac_cv_c_inline'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + ac_cv_c_inline=no +for ac_kw in inline __inline__ __inline; do + cat > conftest.$ac_ext <<EOF +#line 1087 "configure" +#include "confdefs.h" + +int main() { +} $ac_kw foo() { +; return 0; } +EOF +if { (eval echo configure:1094: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_c_inline=$ac_kw; break +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 +fi +rm -f conftest* +done + +fi + +echo "$ac_t""$ac_cv_c_inline" 1>&6 +case "$ac_cv_c_inline" in + inline | yes) ;; + no) cat >> confdefs.h <<\EOF +#define inline +EOF + ;; + *) cat >> confdefs.h <<EOF +#define inline $ac_cv_c_inline +EOF + ;; +esac + echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 -echo "configure:1022: checking how to run the C preprocessor" >&5 +echo "configure:1121: checking how to run the C preprocessor" >&5 # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= @@ -1033,14 +1132,14 @@ else # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. cat > conftest.$ac_ext <<EOF -#line 1037 "configure" +#line 1136 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1043: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out` +{ (eval echo configure:1142: \"$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 : else @@ -1050,14 +1149,31 @@ else rm -rf conftest* CPP="${CC-cc} -E -traditional-cpp" cat > conftest.$ac_ext <<EOF -#line 1054 "configure" +#line 1153 "configure" +#include "confdefs.h" +#include <assert.h> +Syntax Error +EOF +ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" +{ (eval echo configure:1159: \"$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 + : +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 <<EOF +#line 1170 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1060: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out` +{ (eval echo configure:1176: \"$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 : else @@ -1070,6 +1186,8 @@ fi rm -f conftest* fi rm -f conftest* +fi +rm -f conftest* ac_cv_prog_CPP="$CPP" fi CPP="$ac_cv_prog_CPP" @@ -1082,18 +1200,18 @@ for ac_hdr in fcntl.h malloc.h memory.h rpc/rpcent.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1086: checking for $ac_hdr" >&5 +echo "configure:1204: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1091 "configure" +#line 1209 "configure" #include "confdefs.h" #include <$ac_hdr> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1096: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out` +{ (eval echo configure:1214: \"$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" @@ -1119,12 +1237,12 @@ fi done echo $ac_n "checking whether time.h and sys/time.h may both be included""... $ac_c" 1>&6 -echo "configure:1123: checking whether time.h and sys/time.h may both be included" >&5 +echo "configure:1241: checking whether time.h and sys/time.h may both be included" >&5 if eval "test \"`echo '$''{'ac_cv_header_time'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1128 "configure" +#line 1246 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/time.h> @@ -1133,7 +1251,7 @@ int main() { struct tm *tp; ; return 0; } EOF -if { (eval echo configure:1137: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1255: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_header_time=yes else @@ -1158,7 +1276,7 @@ case "$target_os" in linux*) echo $ac_n "checking Linux kernel version""... $ac_c" 1>&6 -echo "configure:1162: checking Linux kernel version" >&5 +echo "configure:1280: checking Linux kernel version" >&5 if eval "test \"`echo '$''{'ac_cv_linux_vers'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1181,18 +1299,18 @@ EOF do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1185: checking for $ac_hdr" >&5 +echo "configure:1303: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1190 "configure" +#line 1308 "configure" #include "confdefs.h" #include <$ac_hdr> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1195: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out` +{ (eval echo configure:1313: \"$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" @@ -1220,15 +1338,1323 @@ done ;; esac + +for ac_hdr in smi.h +do +ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` +echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 +echo "configure:1347: checking for $ac_hdr" >&5 +if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 1352 "configure" +#include "confdefs.h" +#include <$ac_hdr> +EOF +ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" +{ (eval echo configure:1357: \"$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 <<EOF +#define $ac_tr_hdr 1 +EOF + +else + echo "$ac_t""no" 1>&6 +fi +done + +echo $ac_n "checking for main in -lsmi""... $ac_c" 1>&6 +echo "configure:1384: checking for main in -lsmi" >&5 +ac_lib_var=`echo smi'_'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="-lsmi $LIBS" +cat > conftest.$ac_ext <<EOF +#line 1392 "configure" +#include "confdefs.h" + +int main() { +main() +; return 0; } +EOF +if { (eval echo configure:1399: \"$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 smi | sed -e 's/[^a-zA-Z0-9_]/_/g' \ + -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` + cat >> confdefs.h <<EOF +#define $ac_tr_lib 1 +EOF + + LIBS="-lsmi $LIBS" + +else + echo "$ac_t""no" 1>&6 +fi + +echo $ac_n "checking whether to enable libsmi""... $ac_c" 1>&6 +echo "configure:1427: checking whether to enable libsmi" >&5 + if test "$cross_compiling" = yes; then + { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } +else + cat > conftest.$ac_ext <<EOF +#line 1432 "configure" +#include "confdefs.h" + /* libsmi available check */ +#include <smi.h> +main() +{ + if (smiInit("")) + exit(1); + else + exit(0); +} + +EOF +if { (eval echo configure:1445: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +then + echo "$ac_t""yes" 1>&6 + cat >> confdefs.h <<\EOF +#define LIBSMI 1 +EOF + + libsmi=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -fr conftest* + echo "$ac_t""no" 1>&6 + libsmi=no + +fi +rm -fr conftest* +fi + + + +CFLAGS="$CFLAGS -Dss_family=__ss_family -Dss_len=__ss_len" +echo $ac_n "checking whether to enable ipv6""... $ac_c" 1>&6 +echo "configure:1468: checking whether to enable ipv6" >&5 +# Check whether --enable-ipv6 or --disable-ipv6 was given. +if test "${enable_ipv6+set}" = set; then + enableval="$enable_ipv6" + case "$enableval" in +yes) echo "$ac_t""yes" 1>&6 + cat >> confdefs.h <<\EOF +#define ENABLE_IPV6 1 +EOF + + LOCALSRC="print-ip6.c print-ip6opts.c print-ripng.c print-icmp6.c print-frag6.c print-rt6.c print-ospf6.c print-dhcp6.c $LOCALSRC" + cat >> confdefs.h <<\EOF +#define INET6 1 +EOF + + ipv6=yes + ;; +*) + echo "$ac_t""no" 1>&6 + ipv6=no + ;; + esac +else + if test "$cross_compiling" = yes; then + echo "$ac_t""no" 1>&6 + ipv6=no + +else + cat > conftest.$ac_ext <<EOF +#line 1497 "configure" +#include "confdefs.h" + /* AF_INET6 available check */ +#include <sys/types.h> +#include <sys/socket.h> +main() +{ + if (socket(AF_INET6, SOCK_STREAM, 0) < 0) + exit(1); + else + exit(0); +} + +EOF +if { (eval echo configure:1511: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +then + echo "$ac_t""yes" 1>&6 + cat >> confdefs.h <<\EOF +#define ENABLE_IPV6 1 +EOF + + LOCALSRC="print-ip6.c print-ip6opts.c print-ripng.c print-icmp6.c print-frag6.c print-rt6.c print-ospf6.c print-dhcp6.c $LOCALSRC" + cat >> confdefs.h <<\EOF +#define INET6 1 +EOF + + ipv6=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -fr conftest* + echo "$ac_t""no" 1>&6 + ipv6=no +fi +rm -fr conftest* +fi + +fi + + +ipv6type=unknown +ipv6lib=none +ipv6trylibc=no + +if test "$ipv6" = "yes"; then + echo $ac_n "checking ipv6 stack type""... $ac_c" 1>&6 +echo "configure:1543: checking ipv6 stack type" >&5 + for i in inria kame linux-glibc linux-libinet6 toshiba v6d zeta; do + case $i in + inria) + cat > conftest.$ac_ext <<EOF +#line 1548 "configure" +#include "confdefs.h" +dnl +#include <netinet/in.h> +#ifdef IPV6_INRIA_VERSION +yes +#endif +EOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + egrep "yes" >/dev/null 2>&1; then + rm -rf conftest* + ipv6type=$i; + CFLAGS="-DINET6 $CFLAGS" +fi +rm -f conftest* + + ;; + kame) + cat > conftest.$ac_ext <<EOF +#line 1567 "configure" +#include "confdefs.h" +dnl +#include <netinet/in.h> +#ifdef __KAME__ +yes +#endif +EOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + egrep "yes" >/dev/null 2>&1; then + rm -rf conftest* + ipv6type=$i; + ipv6lib=inet6; + ipv6libdir=/usr/local/v6/lib; + ipv6trylibc=yes; + CFLAGS="-DINET6 $CFLAGS" +fi +rm -f conftest* + + ;; + linux-glibc) + cat > conftest.$ac_ext <<EOF +#line 1589 "configure" +#include "confdefs.h" +dnl +#include <features.h> +#if defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1 +yes +#endif +EOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + egrep "yes" >/dev/null 2>&1; then + rm -rf conftest* + 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 <<EOF +#line 1617 "configure" +#include "confdefs.h" +dnl +#include <sys/param.h> +#ifdef _TOSHIBA_INET6 +yes +#endif +EOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + egrep "yes" >/dev/null 2>&1; then + rm -rf conftest* + ipv6type=$i; + ipv6lib=inet6; + ipv6libdir=/usr/local/v6/lib; + CFLAGS="-DINET6 $CFLAGS" +fi +rm -f conftest* + + ;; + v6d) + cat > conftest.$ac_ext <<EOF +#line 1638 "configure" +#include "confdefs.h" +dnl +#include </usr/local/v6/include/sys/v6config.h> +#ifdef __V6D__ +yes +#endif +EOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + egrep "yes" >/dev/null 2>&1; then + rm -rf conftest* + 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 <<EOF +#line 1659 "configure" +#include "confdefs.h" +dnl +#include <sys/param.h> +#ifdef _ZETA_MINAMI_INET6 +yes +#endif +EOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + egrep "yes" >/dev/null 2>&1; then + rm -rf conftest* + 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 "$ac_t""$ipv6type" 1>&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 + for ac_func in getaddrinfo +do +echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 +echo "configure:1707: checking for $ac_func" >&5 +if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 1712 "configure" +#include "confdefs.h" +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func(); below. */ +#include <assert.h> +/* Override any gcc2 internal prototype to avoid an error. */ +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $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:1735: \"$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 <<EOF +#define $ac_tr_func 1 +EOF + echo $ac_n "checking getaddrinfo bug""... $ac_c" 1>&6 +echo "configure:1754: checking getaddrinfo bug" >&5 + if test "$cross_compiling" = yes; then + echo "$ac_t""buggy" 1>&6 + buggygetaddrinfo=yes +else + cat > conftest.$ac_ext <<EOF +#line 1760 "configure" +#include "confdefs.h" + +#include <sys/types.h> +#include <netdb.h> +#include <string.h> +#include <sys/socket.h> +#include <netinet/in.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; + 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); +} + +EOF +if { (eval echo configure:1857: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +then + echo "$ac_t""good" 1>&6 + buggygetaddrinfo=no +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -fr conftest* + echo "$ac_t""buggy" 1>&6 + buggygetaddrinfo=yes +fi +rm -fr conftest* +fi + +else + echo "$ac_t""no" 1>&6 +buggygetaddrinfo=yes +fi +done + + + if test "$buggygetaddrinfo" = "yes"; then + 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 upgreade your system library to newest version' + echo ' of GNU C library (aka glibc).' + fi + fi + for ac_func in getaddrinfo getnameinfo +do +echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 +echo "configure:1892: checking for $ac_func" >&5 +if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 1897 "configure" +#include "confdefs.h" +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func(); below. */ +#include <assert.h> +/* Override any gcc2 internal prototype to avoid an error. */ +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $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:1920: \"$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 <<EOF +#define $ac_tr_func 1 +EOF + +else + echo "$ac_t""no" 1>&6 +LIBOBJS="$LIBOBJS ${ac_func}.${ac_objext}" +fi +done + + +fi +for ac_func in inet_ntop inet_pton inet_aton +do +echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 +echo "configure:1950: checking for $ac_func" >&5 +if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 1955 "configure" +#include "confdefs.h" +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func(); below. */ +#include <assert.h> +/* Override any gcc2 internal prototype to avoid an error. */ +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $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:1978: \"$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 <<EOF +#define $ac_tr_func 1 +EOF + +else + echo "$ac_t""no" 1>&6 +LIBOBJS="$LIBOBJS ${ac_func}.${ac_objext}" +fi +done + + + + + echo $ac_n "checking if sockaddr struct has sa_len member""... $ac_c" 1>&6 +echo "configure:2007: checking if sockaddr struct has sa_len member" >&5 + if eval "test \"`echo '$''{'ac_cv_sockaddr_has_sa_len'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 2012 "configure" +#include "confdefs.h" + +# include <sys/types.h> +# include <sys/socket.h> +int main() { +u_int i = sizeof(((struct sockaddr *)0)->sa_len) +; return 0; } +EOF +if { (eval echo configure:2021: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_sockaddr_has_sa_len=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_sockaddr_has_sa_len=no +fi +rm -f conftest* +fi + + echo "$ac_t""$ac_cv_sockaddr_has_sa_len" 1>&6 + if test $ac_cv_sockaddr_has_sa_len = yes ; then + cat >> confdefs.h <<\EOF +#define HAVE_SOCKADDR_SA_LEN 1 +EOF + + fi + +if test "$ac_cv_sockaddr_has_sa_len" = no; then + missing_includes=yes +fi + + + echo $ac_n "checking for __P""... $ac_c" 1>&6 +echo "configure:2047: checking for __P" >&5 + if eval "test \"`echo '$''{'ac_cv_portable_proto'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 2052 "configure" +#include "confdefs.h" + +# include <unistd.h> +int main() { +int f __P(()) +; return 0; } +EOF +if { (eval echo configure:2060: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_portable_proto=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_portable_proto=no +fi +rm -f conftest* +fi + + echo "$ac_t""$ac_cv_portable_proto" 1>&6 + if test $ac_cv_portable_proto = yes; then + cat >> confdefs.h <<\EOF +#define HAVE_PORTABLE_PROTOTYPE 1 +EOF + + fi + +if test "$ac_cv_portable_proto" = no; then + missing_includes=yes +fi + +echo $ac_n "checking size of char""... $ac_c" 1>&6 +echo "configure:2085: checking size of char" >&5 +if eval "test \"`echo '$''{'ac_cv_sizeof_char'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + if test "$cross_compiling" = yes; then + ac_cv_sizeof_char=1 +else + cat > conftest.$ac_ext <<EOF +#line 2093 "configure" +#include "confdefs.h" +#include <stdio.h> +main() +{ + FILE *f=fopen("conftestval", "w"); + if (!f) exit(1); + fprintf(f, "%d\n", sizeof(char)); + exit(0); +} +EOF +if { (eval echo configure:2104: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +then + ac_cv_sizeof_char=`cat conftestval` +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -fr conftest* + ac_cv_sizeof_char=0 +fi +rm -fr conftest* +fi + +fi +echo "$ac_t""$ac_cv_sizeof_char" 1>&6 +cat >> confdefs.h <<EOF +#define SIZEOF_CHAR $ac_cv_sizeof_char +EOF + + +echo $ac_n "checking size of short""... $ac_c" 1>&6 +echo "configure:2124: checking size of short" >&5 +if eval "test \"`echo '$''{'ac_cv_sizeof_short'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + if test "$cross_compiling" = yes; then + ac_cv_sizeof_short=2 +else + cat > conftest.$ac_ext <<EOF +#line 2132 "configure" +#include "confdefs.h" +#include <stdio.h> +main() +{ + FILE *f=fopen("conftestval", "w"); + if (!f) exit(1); + fprintf(f, "%d\n", sizeof(short)); + exit(0); +} +EOF +if { (eval echo configure:2143: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +then + ac_cv_sizeof_short=`cat conftestval` +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -fr conftest* + ac_cv_sizeof_short=0 +fi +rm -fr conftest* +fi + +fi +echo "$ac_t""$ac_cv_sizeof_short" 1>&6 +cat >> confdefs.h <<EOF +#define SIZEOF_SHORT $ac_cv_sizeof_short +EOF + + +echo $ac_n "checking size of int""... $ac_c" 1>&6 +echo "configure:2163: checking size of int" >&5 +if eval "test \"`echo '$''{'ac_cv_sizeof_int'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + if test "$cross_compiling" = yes; then + ac_cv_sizeof_int=4 +else + cat > conftest.$ac_ext <<EOF +#line 2171 "configure" +#include "confdefs.h" +#include <stdio.h> +main() +{ + FILE *f=fopen("conftestval", "w"); + if (!f) exit(1); + fprintf(f, "%d\n", sizeof(int)); + exit(0); +} +EOF +if { (eval echo configure:2182: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +then + ac_cv_sizeof_int=`cat conftestval` +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -fr conftest* + ac_cv_sizeof_int=0 +fi +rm -fr conftest* +fi + +fi +echo "$ac_t""$ac_cv_sizeof_int" 1>&6 +cat >> confdefs.h <<EOF +#define SIZEOF_INT $ac_cv_sizeof_int +EOF + + +echo $ac_n "checking size of long""... $ac_c" 1>&6 +echo "configure:2202: checking size of long" >&5 +if eval "test \"`echo '$''{'ac_cv_sizeof_long'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + if test "$cross_compiling" = yes; then + ac_cv_sizeof_long=4 +else + cat > conftest.$ac_ext <<EOF +#line 2210 "configure" +#include "confdefs.h" +#include <stdio.h> +main() +{ + FILE *f=fopen("conftestval", "w"); + if (!f) exit(1); + fprintf(f, "%d\n", sizeof(long)); + exit(0); +} +EOF +if { (eval echo configure:2221: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +then + ac_cv_sizeof_long=`cat conftestval` +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -fr conftest* + ac_cv_sizeof_long=0 +fi +rm -fr conftest* +fi + +fi +echo "$ac_t""$ac_cv_sizeof_long" 1>&6 +cat >> confdefs.h <<EOF +#define SIZEOF_LONG $ac_cv_sizeof_long +EOF + + + + + + echo $ac_n "checking for addrinfo""... $ac_c" 1>&6 +echo "configure:2244: checking for addrinfo" >&5 + if eval "test \"`echo '$''{'ac_cv_addrinfo'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 2249 "configure" +#include "confdefs.h" + +# include <netdb.h> +int main() { +struct addrinfo a +; return 0; } +EOF +if { (eval echo configure:2257: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_addrinfo=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_addrinfo=no +fi +rm -f conftest* +fi + + echo "$ac_t""$ac_cv_addrinfo" 1>&6 + if test $ac_cv_addrinfo = yes; then + cat >> confdefs.h <<\EOF +#define HAVE_ADDRINFO 1 +EOF + + else + cat >> confdefs.h <<\EOF +#define NEED_ADDRINFO_H 1 +EOF + + fi + +if test "$ac_cv_addrinfo" = no; then + missing_includes=yes +fi + + + echo $ac_n "checking for NI_MAXSERV""... $ac_c" 1>&6 +echo "configure:2288: checking for NI_MAXSERV" >&5 + if eval "test \"`echo '$''{'ac_cv_maxserv'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 2293 "configure" +#include "confdefs.h" +#include <netdb.h> +#ifdef NI_MAXSERV +yes +#endif +EOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + egrep "yes" >/dev/null 2>&1; then + rm -rf conftest* + ac_cv_maxserv=yes +else + rm -rf conftest* + ac_cv_maxserv=no +fi +rm -f conftest* + +fi + + echo "$ac_t""$ac_cv_maxserv" 1>&6 + if test $ac_cv_maxserv != yes; then + cat >> confdefs.h <<\EOF +#define NEED_ADDRINFO_H 1 +EOF + + fi + +if test "$ac_cv_maxserv" = no; then + missing_includes=yes +fi + + + echo $ac_n "checking for NI_NAMEREQD""... $ac_c" 1>&6 +echo "configure:2326: checking for NI_NAMEREQD" >&5 + if eval "test \"`echo '$''{'ac_cv_namereqd'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 2331 "configure" +#include "confdefs.h" +#include <netdb.h> +#ifdef NI_NOFQDN +yes +#endif +EOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + egrep "yes" >/dev/null 2>&1; then + rm -rf conftest* + ac_cv_namereqd=yes +else + rm -rf conftest* + ac_cv_namereqd=no +fi +rm -f conftest* + +fi + + echo "$ac_t""$ac_cv_namereqd" 1>&6 + if test $ac_cv_namereqd != yes; then + cat >> confdefs.h <<\EOF +#define NEED_ADDRINFO_H 1 +EOF + + fi + +if test "$ac_cv_namereqd" = no; then + missing_includes=yes +fi + + + echo $ac_n "checking for sockaddr_storage""... $ac_c" 1>&6 +echo "configure:2364: checking for sockaddr_storage" >&5 + if eval "test \"`echo '$''{'ac_cv_sa_storage'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 2369 "configure" +#include "confdefs.h" + +# include <sys/types.h> +# include <sys/socket.h> +int main() { +struct sockaddr_storage s +; return 0; } +EOF +if { (eval echo configure:2378: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_sa_storage=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_sa_storage=no +fi +rm -f conftest* +fi + + echo "$ac_t""$ac_cv_sa_storage" 1>&6 + if test $ac_cv_sa_storage = yes; then + cat >> confdefs.h <<\EOF +#define HAVE_SOCKADDR_STORAGE 1 +EOF + + fi + +if test "$ac_cv_sa_storage" = no; then + missing_includes=yes +fi + + + ac_cv_addrsz=yes + echo $ac_n "checking for INADDRSZ""... $ac_c" 1>&6 +echo "configure:2405: checking for INADDRSZ" >&5 + if eval "test \"`echo '$''{'ac_cv_inaddrsz'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 2410 "configure" +#include "confdefs.h" + +# include <arpa/nameser.h> +int main() { +int a = INADDRSZ +; return 0; } +EOF +if { (eval echo configure:2418: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_inaddrsz=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_inaddrsz=no +fi +rm -f conftest* +fi + + echo "$ac_t""$ac_cv_inaddrsz" 1>&6 + if test $ac_cv_inaddrsz = yes; then + cat >> confdefs.h <<\EOF +#define HAVE_INADDRSZ 1 +EOF + + else + ac_cv_addrsz=no + fi + echo $ac_n "checking for IN6ADDRSZ""... $ac_c" 1>&6 +echo "configure:2440: checking for IN6ADDRSZ" >&5 + if eval "test \"`echo '$''{'ac_cv_in6addrsz'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 2445 "configure" +#include "confdefs.h" + +# include <arpa/nameser.h> +int main() { +int a = IN6ADDRSZ +; return 0; } +EOF +if { (eval echo configure:2453: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_in6addrsz=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_in6addrsz=no +fi +rm -f conftest* +fi + + echo "$ac_t""$ac_cv_in6addrsz" 1>&6 + if test $ac_cv_in6addrsz = yes; then + cat >> confdefs.h <<\EOF +#define HAVE_IN6ADDRSZ 1 +EOF + + else + ac_cv_addrsz=no + fi + +if test "$ac_cv_addrsz" = no; then + missing_includes=yes +fi + + + echo $ac_n "checking for RES_USE_INET6""... $ac_c" 1>&6 +echo "configure:2481: checking for RES_USE_INET6" >&5 + if eval "test \"`echo '$''{'ac_cv_res_inet6'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 2486 "configure" +#include "confdefs.h" + +# include <sys/types.h> +# include <netinet/in.h> +# include <resolv.h> +int main() { +int a = RES_USE_INET6 +; return 0; } +EOF +if { (eval echo configure:2496: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_res_inet6=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_res_inet6=no +fi +rm -f conftest* +fi + + echo "$ac_t""$ac_cv_res_inet6" 1>&6 + if test $ac_cv_res_inet6 = yes; then + cat >> confdefs.h <<\EOF +#define HAVE_RES_USE_INET6 1 +EOF + + fi + +if test "$ac_cv_res_inet6" = no; then + missing_includes=yes +fi + + + echo $ac_n "checking for AAAA""... $ac_c" 1>&6 +echo "configure:2522: checking for AAAA" >&5 + if eval "test \"`echo '$''{'ac_cv_aaaa'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 2527 "configure" +#include "confdefs.h" + +# include <sys/types.h> +# include <arpa/nameser.h> +int main() { +int a = T_AAAA +; return 0; } +EOF +if { (eval echo configure:2536: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_aaaa=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_aaaa=no +fi +rm -f conftest* +fi + + echo "$ac_t""$ac_cv_aaaa" 1>&6 + if test $ac_cv_aaaa = yes; then + cat >> confdefs.h <<\EOF +#define HAVE_AAAA 1 +EOF + + fi + +if test "$ac_cv_aaaa" = no; then + cat >> confdefs.h <<\EOF +#define T_AAAA 28 +EOF + +fi + + + echo $ac_n "checking for res_state_ext""... $ac_c" 1>&6 +echo "configure:2565: checking for res_state_ext" >&5 + if eval "test \"`echo '$''{'ac_cv_res_state_ext'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 2570 "configure" +#include "confdefs.h" + +# include <sys/types.h> +# include <netinet/in.h> +# include <netinet6/in6.h> +# include <resolv.h> +int main() { +struct __res_state_ext e +; return 0; } +EOF +if { (eval echo configure:2581: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_res_state_ext=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_res_state_ext=no +fi +rm -f conftest* +fi + + echo "$ac_t""$ac_cv_res_state_ext" 1>&6 + if test $ac_cv_res_state_ext = yes; then + cat >> confdefs.h <<\EOF +#define HAVE_RES_STATE_EXT 1 +EOF + + fi + +if test "$ac_cv_res_state_ext" = no; then + missing_includes=yes +fi + + + echo $ac_n "checking for nsort in res_state""... $ac_c" 1>&6 +echo "configure:2607: checking for nsort in res_state" >&5 + if eval "test \"`echo '$''{'ac_cv_res_state'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 2612 "configure" +#include "confdefs.h" + +# include <sys/types.h> +# include <netinet/in.h> +# include <netinet6/in6.h> +# include <resolv.h> +int main() { +struct __res_state e; e.nsort = 0 +; return 0; } +EOF +if { (eval echo configure:2623: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_res_state=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_res_state=no +fi +rm -f conftest* +fi + + echo "$ac_t""$ac_cv_res_state" 1>&6 + if test $ac_cv_res_state = yes; then + cat >> confdefs.h <<\EOF +#define HAVE_NEW_RES_STATE 1 +EOF + + 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 do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1227: checking for $ac_func" >&5 +echo "configure:2653: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1232 "configure" +#line 2658 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -1251,7 +2677,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:1255: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:2681: \"$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 @@ -1272,20 +2698,20 @@ EOF else echo "$ac_t""no" 1>&6 -LIBOBJS="$LIBOBJS ${ac_func}.o" +LIBOBJS="$LIBOBJS ${ac_func}.${ac_objext}" fi done -for ac_func in ether_ntoa setlinebuf +for ac_func in ether_ntohost setlinebuf gethostbyname2 do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1284: checking for $ac_func" >&5 +echo "configure:2710: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1289 "configure" +#line 2715 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -1308,7 +2734,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:1312: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:2738: \"$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 @@ -1334,14 +2760,14 @@ done echo $ac_n "checking whether byte ordering is bigendian""... $ac_c" 1>&6 -echo "configure:1338: checking whether byte ordering is bigendian" >&5 +echo "configure:2764: checking whether byte ordering is bigendian" >&5 if eval "test \"`echo '$''{'ac_cv_c_bigendian'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_cv_c_bigendian=unknown # See if sys/param.h defines the BYTE_ORDER macro. cat > conftest.$ac_ext <<EOF -#line 1345 "configure" +#line 2771 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/param.h> @@ -1352,11 +2778,11 @@ int main() { #endif ; return 0; } EOF -if { (eval echo configure:1356: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2782: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* # It does; now see whether it defined to BIG_ENDIAN or not. cat > conftest.$ac_ext <<EOF -#line 1360 "configure" +#line 2786 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/param.h> @@ -1367,7 +2793,7 @@ int main() { #endif ; return 0; } EOF -if { (eval echo configure:1371: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:2797: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_bigendian=yes else @@ -1387,7 +2813,7 @@ if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <<EOF -#line 1391 "configure" +#line 2817 "configure" #include "confdefs.h" main () { /* Are we little or big endian? From Harbison&Steele. */ @@ -1400,7 +2826,7 @@ main () { exit (u.c[sizeof (long) - 1] == 1); } EOF -if { (eval echo configure:1404: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:2830: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_c_bigendian=no else @@ -1425,7 +2851,7 @@ fi echo $ac_n "checking for main in -ldnet""... $ac_c" 1>&6 -echo "configure:1429: checking for main in -ldnet" >&5 +echo "configure:2855: 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 @@ -1433,14 +2859,14 @@ else ac_save_LIBS="$LIBS" LIBS="-ldnet $LIBS" cat > conftest.$ac_ext <<EOF -#line 1437 "configure" +#line 2863 "configure" #include "confdefs.h" int main() { main() ; return 0; } EOF -if { (eval echo configure:1444: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:2870: \"$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 @@ -1468,7 +2894,7 @@ else fi echo $ac_n "checking for main in -lrpc""... $ac_c" 1>&6 -echo "configure:1472: checking for main in -lrpc" >&5 +echo "configure:2898: 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 @@ -1476,14 +2902,14 @@ else ac_save_LIBS="$LIBS" LIBS="-lrpc $LIBS" cat > conftest.$ac_ext <<EOF -#line 1480 "configure" +#line 2906 "configure" #include "confdefs.h" int main() { main() ; return 0; } EOF -if { (eval echo configure:1487: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:2913: \"$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 @@ -1510,15 +2936,102 @@ else echo "$ac_t""no" 1>&6 fi +echo $ac_n "checking for uncompress in -lz""... $ac_c" 1>&6 +echo "configure:2941: 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 +else + ac_save_LIBS="$LIBS" +LIBS="-lz $LIBS" +cat > conftest.$ac_ext <<EOF +#line 2949 "configure" +#include "confdefs.h" +/* Override any gcc2 internal prototype to avoid an error. */ +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char uncompress(); + +int main() { +uncompress() +; return 0; } +EOF +if { (eval echo configure:2960: \"$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 z | sed -e 's/[^a-zA-Z0-9_]/_/g' \ + -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` + cat >> confdefs.h <<EOF +#define $ac_tr_lib 1 +EOF + + LIBS="-lz $LIBS" + +else + echo "$ac_t""no" 1>&6 +fi + +for ac_hdr in zlib.h +do +ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` +echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 +echo "configure:2991: checking for $ac_hdr" >&5 +if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 2996 "configure" +#include "confdefs.h" +#include <$ac_hdr> +EOF +ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" +{ (eval echo configure:3001: \"$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 <<EOF +#define $ac_tr_hdr 1 +EOF + +else + echo "$ac_t""no" 1>&6 +fi +done + echo $ac_n "checking return type of signal handlers""... $ac_c" 1>&6 -echo "configure:1517: checking return type of signal handlers" >&5 +echo "configure:3030: checking return type of signal handlers" >&5 if eval "test \"`echo '$''{'ac_cv_type_signal'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1522 "configure" +#line 3035 "configure" #include "confdefs.h" #include <sys/types.h> #include <signal.h> @@ -1535,7 +3048,7 @@ int main() { int i; ; return 0; } EOF -if { (eval echo configure:1539: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:3052: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_type_signal=void else @@ -1577,12 +3090,12 @@ EOF for ac_func in sigset do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1581: checking for $ac_func" >&5 +echo "configure:3094: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1586 "configure" +#line 3099 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -1605,7 +3118,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:1609: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3122: \"$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 @@ -1633,12 +3146,12 @@ done for ac_func in sigaction do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1637: checking for $ac_func" >&5 +echo "configure:3150: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1642 "configure" +#line 3155 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -1661,7 +3174,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:1665: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3178: \"$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 @@ -1693,12 +3206,12 @@ done # 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:1697: checking for gethostbyname" >&5 +echo "configure:3210: 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 <<EOF -#line 1702 "configure" +#line 3215 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char gethostbyname(); below. */ @@ -1721,7 +3234,7 @@ gethostbyname(); ; return 0; } EOF -if { (eval echo configure:1725: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3238: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_gethostbyname=yes" else @@ -1740,7 +3253,7 @@ 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:1744: checking for gethostbyname in -lnsl" >&5 +echo "configure:3257: 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 @@ -1748,7 +3261,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lnsl $LIBS" cat > conftest.$ac_ext <<EOF -#line 1752 "configure" +#line 3265 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -1759,7 +3272,7 @@ int main() { gethostbyname() ; return 0; } EOF -if { (eval echo configure:1763: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3276: \"$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 @@ -1786,7 +3299,7 @@ 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:1790: checking for gethostbyname in -lsocket" >&5 +echo "configure:3303: 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 @@ -1794,7 +3307,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lsocket $LIBS" cat > conftest.$ac_ext <<EOF -#line 1798 "configure" +#line 3311 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -1805,7 +3318,7 @@ int main() { gethostbyname() ; return 0; } EOF -if { (eval echo configure:1809: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3322: \"$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 @@ -1834,7 +3347,7 @@ else # 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:1838: checking for gethostbyname in -lsocket" >&5 +echo "configure:3351: 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 @@ -1842,7 +3355,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lsocket -lnsl $LIBS" cat > conftest.$ac_ext <<EOF -#line 1846 "configure" +#line 3359 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -1853,7 +3366,7 @@ int main() { gethostbyname() ; return 0; } EOF -if { (eval echo configure:1857: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3370: \"$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 @@ -1872,7 +3385,7 @@ if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then else echo "$ac_t""no" 1>&6 echo $ac_n "checking for gethostbyname in -lresolv""... $ac_c" 1>&6 -echo "configure:1876: checking for gethostbyname in -lresolv" >&5 +echo "configure:3389: 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 @@ -1880,7 +3393,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lresolv $LIBS" cat > conftest.$ac_ext <<EOF -#line 1884 "configure" +#line 3397 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -1891,7 +3404,7 @@ int main() { gethostbyname() ; return 0; } EOF -if { (eval echo configure:1895: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3408: \"$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 @@ -1927,12 +3440,12 @@ fi fi echo $ac_n "checking for socket""... $ac_c" 1>&6 -echo "configure:1931: checking for socket" >&5 +echo "configure:3444: 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 <<EOF -#line 1936 "configure" +#line 3449 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char socket(); below. */ @@ -1955,7 +3468,7 @@ socket(); ; return 0; } EOF -if { (eval echo configure:1959: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3472: \"$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 @@ -1973,7 +3486,7 @@ if eval "test \"`echo '$ac_cv_func_'socket`\" = yes"; then else echo "$ac_t""no" 1>&6 echo $ac_n "checking for socket in -lsocket""... $ac_c" 1>&6 -echo "configure:1977: checking for socket in -lsocket" >&5 +echo "configure:3490: 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 @@ -1981,7 +3494,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lsocket $LIBS" cat > conftest.$ac_ext <<EOF -#line 1985 "configure" +#line 3498 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -1992,7 +3505,7 @@ int main() { socket() ; return 0; } EOF -if { (eval echo configure:1996: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3509: \"$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 @@ -2018,7 +3531,7 @@ EOF else echo "$ac_t""no" 1>&6 echo $ac_n "checking for socket in -lsocket""... $ac_c" 1>&6 -echo "configure:2022: checking for socket in -lsocket" >&5 +echo "configure:3535: 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 @@ -2026,7 +3539,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lsocket -lnsl $LIBS" cat > conftest.$ac_ext <<EOF -#line 2030 "configure" +#line 3543 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -2037,7 +3550,7 @@ int main() { socket() ; return 0; } EOF -if { (eval echo configure:2041: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3554: \"$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 @@ -2063,7 +3576,7 @@ fi # DLPI needs putmsg under HPUX so test for -lstr while we're at it echo $ac_n "checking for putmsg in -lstr""... $ac_c" 1>&6 -echo "configure:2067: checking for putmsg in -lstr" >&5 +echo "configure:3580: 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 @@ -2071,7 +3584,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lstr $LIBS" cat > conftest.$ac_ext <<EOF -#line 2075 "configure" +#line 3588 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -2082,7 +3595,7 @@ int main() { putmsg() ; return 0; } EOF -if { (eval echo configure:2086: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3599: \"$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 @@ -2117,12 +3630,12 @@ fi for ac_func in pfopen do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:2121: checking for $ac_func" >&5 +echo "configure:3634: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2126 "configure" +#line 3639 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -2145,7 +3658,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:2149: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3662: \"$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 @@ -2175,7 +3688,7 @@ done fi fi echo $ac_n "checking for local pcap library""... $ac_c" 1>&6 -echo "configure:2179: checking for local pcap library" >&5 +echo "configure:3692: checking for local pcap library" >&5 libpcap=FAIL lastdir=FAIL places=`ls .. | sed -e 's,/$,,' -e 's,^,../,' | \ @@ -2186,7 +3699,7 @@ echo "configure:2179: checking for local pcap library" >&5 continue; fi lastdir=$dir - if test -r $dir/pcap.c ; then + if test -r $dir/libpcap.a ; then libpcap=$dir/libpcap.a d=$dir fi @@ -2194,7 +3707,7 @@ echo "configure:2179: checking for local pcap library" >&5 if test $libpcap = FAIL ; then echo "$ac_t""not found" 1>&6 echo $ac_n "checking for main in -lpcap""... $ac_c" 1>&6 -echo "configure:2198: checking for main in -lpcap" >&5 +echo "configure:3711: 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 @@ -2202,14 +3715,14 @@ else ac_save_LIBS="$LIBS" LIBS="-lpcap $LIBS" cat > conftest.$ac_ext <<EOF -#line 2206 "configure" +#line 3719 "configure" #include "confdefs.h" int main() { main() ; return 0; } EOF -if { (eval echo configure:2213: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:3726: \"$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 @@ -2234,7 +3747,13 @@ fi fi else V_PCAPDEP=$libpcap + if test -r $d/pcap.h; then V_INCLS="-I$d $V_INCLS" + elif test -r $srcdir/../libpcap/pcap.h; then + V_INCLS="-I$d -I$srcdir/../libpcap $V_INCLS" + else + { echo "configure: error: cannot find pcap.h" 1>&2; exit 1; } + fi echo "$ac_t""$libpcap" 1>&6 fi LIBS="$libpcap $LIBS" @@ -2243,7 +3762,7 @@ fi aix*) pseexe="/lib/pse.exp" echo $ac_n "checking for $pseexe""... $ac_c" 1>&6 -echo "configure:2247: checking for $pseexe" >&5 +echo "configure:3766: checking for $pseexe" >&5 if test -f $pseexe ; then echo "$ac_t""yes" 1>&6 LIBS="$LIBS -I:$pseexe" @@ -2269,7 +3788,7 @@ irix*) ;; linux*) - V_INCLS="$V_INCLS -Ilinux-include" + V_INCLS="$V_INCLS -I\$(srcdir)/linux-include" ;; osf*) @@ -2289,13 +3808,127 @@ if test -f /dev/bpf0 ; then V_GROUP=bpf fi +echo $ac_n "checking for u_int8_t using $CC""... $ac_c" 1>&6 +echo "configure:3813: checking for u_int8_t using $CC" >&5 + if eval "test \"`echo '$''{'ac_cv_lbl_have_u_int8_t'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 3818 "configure" +#include "confdefs.h" + +# include "confdefs.h" +# include <sys/types.h> +# if STDC_HEADERS +# include <stdlib.h> +# include <stddef.h> +# endif +int main() { +u_int8_t i +; return 0; } +EOF +if { (eval echo configure:3831: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_lbl_have_u_int8_t=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_lbl_have_u_int8_t=no +fi +rm -f conftest* +fi + + echo "$ac_t""$ac_cv_lbl_have_u_int8_t" 1>&6 + if test $ac_cv_lbl_have_u_int8_t = no ; then + cat >> confdefs.h <<\EOF +#define u_int8_t u_char +EOF + + fi +echo $ac_n "checking for int16_t using $CC""... $ac_c" 1>&6 +echo "configure:3851: checking for int16_t using $CC" >&5 + if eval "test \"`echo '$''{'ac_cv_lbl_have_int16_t'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 3856 "configure" +#include "confdefs.h" + +# include "confdefs.h" +# include <sys/types.h> +# if STDC_HEADERS +# include <stdlib.h> +# include <stddef.h> +# endif +int main() { +int16_t i +; return 0; } +EOF +if { (eval echo configure:3869: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_lbl_have_int16_t=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_lbl_have_int16_t=no +fi +rm -f conftest* +fi + + echo "$ac_t""$ac_cv_lbl_have_int16_t" 1>&6 + if test $ac_cv_lbl_have_int16_t = no ; then + cat >> confdefs.h <<\EOF +#define int16_t short +EOF + + fi +echo $ac_n "checking for u_int16_t using $CC""... $ac_c" 1>&6 +echo "configure:3889: checking for u_int16_t using $CC" >&5 + if eval "test \"`echo '$''{'ac_cv_lbl_have_u_int16_t'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 3894 "configure" +#include "confdefs.h" + +# include "confdefs.h" +# include <sys/types.h> +# if STDC_HEADERS +# include <stdlib.h> +# include <stddef.h> +# endif +int main() { +u_int16_t i +; return 0; } +EOF +if { (eval echo configure:3907: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_lbl_have_u_int16_t=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_lbl_have_u_int16_t=no +fi +rm -f conftest* +fi + + echo "$ac_t""$ac_cv_lbl_have_u_int16_t" 1>&6 + if test $ac_cv_lbl_have_u_int16_t = no ; then + cat >> confdefs.h <<\EOF +#define u_int16_t u_short +EOF + + fi echo $ac_n "checking for int32_t using $CC""... $ac_c" 1>&6 -echo "configure:2294: checking for int32_t using $CC" >&5 +echo "configure:3927: checking for int32_t using $CC" >&5 if eval "test \"`echo '$''{'ac_cv_lbl_have_int32_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2299 "configure" +#line 3932 "configure" #include "confdefs.h" # include "confdefs.h" @@ -2308,7 +3941,7 @@ int main() { int32_t i ; return 0; } EOF -if { (eval echo configure:2312: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:3945: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_lbl_have_int32_t=yes else @@ -2328,12 +3961,12 @@ EOF fi echo $ac_n "checking for u_int32_t using $CC""... $ac_c" 1>&6 -echo "configure:2332: checking for u_int32_t using $CC" >&5 +echo "configure:3965: checking for u_int32_t using $CC" >&5 if eval "test \"`echo '$''{'ac_cv_lbl_have_u_int32_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2337 "configure" +#line 3970 "configure" #include "confdefs.h" # include "confdefs.h" @@ -2346,7 +3979,7 @@ int main() { u_int32_t i ; return 0; } EOF -if { (eval echo configure:2350: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:3983: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_lbl_have_u_int32_t=yes else @@ -2406,12 +4039,12 @@ EOF fi echo $ac_n "checking if sockaddr struct has sa_len member""... $ac_c" 1>&6 -echo "configure:2410: checking if sockaddr struct has sa_len member" >&5 +echo "configure:4043: checking if sockaddr struct has sa_len member" >&5 if eval "test \"`echo '$''{'ac_cv_lbl_sockaddr_has_sa_len'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2415 "configure" +#line 4048 "configure" #include "confdefs.h" # include <sys/types.h> @@ -2420,7 +4053,7 @@ int main() { u_int i = sizeof(((struct sockaddr *)0)->sa_len) ; return 0; } EOF -if { (eval echo configure:2424: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:4057: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_lbl_sockaddr_has_sa_len=yes else @@ -2441,14 +4074,14 @@ EOF fi echo $ac_n "checking if ether_header uses ether_addr structs""... $ac_c" 1>&6 -echo "configure:2445: checking if ether_header uses ether_addr structs" >&5 +echo "configure:4078: 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 <<EOF -#line 2452 "configure" +#line 4085 "configure" #include "confdefs.h" # include <sys/types.h> @@ -2466,7 +4099,7 @@ u_int i = sizeof(((struct ether_header *)0)->ether_dhost.ether_addr_octet) ; return 0; } EOF -if { (eval echo configure:2470: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:4103: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_ether_header_has_ea=yes else @@ -2488,14 +4121,14 @@ EOF fi echo $ac_n "checking if ether_arp uses ether_addr structs""... $ac_c" 1>&6 -echo "configure:2492: checking if ether_arp uses ether_addr structs" >&5 +echo "configure:4125: 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 <<EOF -#line 2499 "configure" +#line 4132 "configure" #include "confdefs.h" # include <sys/types.h> @@ -2513,7 +4146,7 @@ u_int i = sizeof(((struct ether_arp *)0)->arp_sha.ether_addr_octet) ; return 0; } EOF -if { (eval echo configure:2517: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:4150: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_ether_arp_has_ea=yes else @@ -2535,14 +4168,14 @@ EOF fi echo $ac_n "checking if ether_arp uses erp_xsha member""... $ac_c" 1>&6 -echo "configure:2539: checking if ether_arp uses erp_xsha member" >&5 +echo "configure:4172: 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 <<EOF -#line 2546 "configure" +#line 4179 "configure" #include "confdefs.h" # include <sys/types.h> @@ -2559,7 +4192,7 @@ int main() { u_int i = sizeof( ((struct ether_arp *)0)->arp_xsha) ; return 0; } EOF -if { (eval echo configure:2563: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:4196: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_struct_ether_arp_x=yes else @@ -2581,7 +4214,7 @@ EOF fi echo $ac_n "checking if unaligned accesses fail""... $ac_c" 1>&6 -echo "configure:2585: checking if unaligned accesses fail" >&5 +echo "configure:4218: 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 @@ -2643,15 +4276,227 @@ EOF fi -if test "${srcdir}" = "." ; then - srcdirprefix="" + + echo $ac_n "checking for h_errno""... $ac_c" 1>&6 +echo "configure:4282: checking for h_errno" >&5 + if eval "test \"`echo '$''{'ac_cv_var_h_errno'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 4287 "configure" +#include "confdefs.h" + +# include <sys/types.h> +# include <netdb.h> +int main() { +int foo = h_errno; +; return 0; } +EOF +if { (eval echo configure:4296: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_var_h_errno=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_var_h_errno=no +fi +rm -f conftest* +fi + + echo "$ac_t""$ac_cv_var_h_errno" 1>&6 + if test "$ac_cv_var_h_errno" = "yes"; then + cat >> confdefs.h <<\EOF +#define HAVE_H_ERRNO 1 +EOF + + fi + + +echo $ac_n "checking for SSLeay""... $ac_c" 1>&6 +echo "configure:4318: checking for SSLeay" >&5 +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 + ac_cv_ssleay_path=$dir + fi + if test -d $dir/include -a -f $dir/include/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; + else + ac_cv_ssleay_path=no + incdir=no + fi +done +echo "$ac_t""$ac_cv_ssleay_path" 1>&6 +if test "$ac_cv_ssleay_path" != no; then + V_INCLS="$V_INCLS $incdir" + LIBS="$LIBS -L$dir/lib" + 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 + echo $ac_n "checking for des_cbc_encrypt in -lcrypto""... $ac_c" 1>&6 +echo "configure:4352: 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 - srcdirprefix="./" + ac_save_LIBS="$LIBS" +LIBS="-lcrypto $LIBS" +cat > conftest.$ac_ext <<EOF +#line 4360 "configure" +#include "confdefs.h" +/* Override any gcc2 internal prototype to avoid an error. */ +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char des_cbc_encrypt(); + +int main() { +des_cbc_encrypt() +; return 0; } +EOF +if { (eval echo configure:4371: \"$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" -if test -r ${srcdirprefix}lbl/gnuc.h ; then +fi +if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then + echo "$ac_t""yes" 1>&6 + ac_tr_lib=HAVE_LIB`echo crypto | sed -e 's/[^a-zA-Z0-9_]/_/g' \ + -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` + cat >> confdefs.h <<EOF +#define $ac_tr_lib 1 +EOF + + 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:4409: checking for $ac_hdr" >&5 +if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 4414 "configure" +#include "confdefs.h" +#include <$ac_hdr> +EOF +ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" +{ (eval echo configure:4419: \"$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 <<EOF +#define $ac_tr_hdr 1 +EOF + +else + echo "$ac_t""no" 1>&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:4448: checking for buggy CAST128" >&5 + if test "$cross_compiling" = yes; then + buggy_cast128="cross-compiling, assume yes" +else + cat > conftest.$ac_ext <<EOF +#line 4453 "configure" +#include "confdefs.h" + +#include <cast.h> +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:4472: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +then + buggy_cast128=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -fr conftest* + buggy_cast128=no +fi +rm -fr conftest* +fi + + 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 + + CPPFLAGS=$bak_CPPFLAGS +fi + +if test -r ${srcdir}/lbl/gnuc.h ; then rm -f gnuc.h - ln -s ${srcdirprefix}lbl/gnuc.h gnuc.h + ln -s ${srcdir}/lbl/gnuc.h gnuc.h fi @@ -2659,6 +4504,7 @@ fi + # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or # incompatible versions: @@ -2666,28 +4512,30 @@ fi # SunOS /usr/etc/install # IRIX /sbin/install # AIX /bin/install +# 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:2674: checking for a BSD compatible install" >&5 +echo "configure:4521: checking for a BSD compatible install" >&5 if test -z "$INSTALL"; then if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else - IFS="${IFS= }"; ac_save_IFS="$IFS"; IFS="${IFS}:" + 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. - for ac_prog in ginstall installbsd scoinst install; do + # 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. - # OSF/1 installbsd also uses dspmsg, but is usable. : else ac_cv_path_install="$ac_dir/$ac_prog -c" @@ -2717,9 +4565,13 @@ echo "$ac_t""$INSTALL" 1>&6 # 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_DATA" && INSTALL_DATA='${INSTALL} -m 644' + + trap '' 1 2 15 cat > confcache <<\EOF # This file is a shell script that caches the results of configure @@ -2743,7 +4595,7 @@ EOF # 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) 2>&1` in + 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 \). @@ -2783,19 +4635,7 @@ fi trap 'rm -f $CONFIG_STATUS conftest*; exit 1' 1 2 15 -# 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 - +DEFS=-DHAVE_CONFIG_H # Without the "./", some shells look in PATH for config.status. : ${CONFIG_STATUS=./config.status} @@ -2822,7 +4662,7 @@ do 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.12" + echo "$CONFIG_STATUS generated by autoconf version 2.13" exit 0 ;; -help | --help | --hel | --he | --h) echo "\$ac_cs_usage"; exit 0 ;; @@ -2833,7 +4673,7 @@ done ac_given_srcdir=$srcdir ac_given_INSTALL="$INSTALL" -trap 'rm -fr `echo "Makefile" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 +trap 'rm -fr `echo "Makefile config.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 EOF cat >> $CONFIG_STATUS <<EOF @@ -2842,9 +4682,11 @@ 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 @@ -2886,7 +4728,9 @@ 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 @@ -2988,6 +4832,113 @@ s%@INSTALL@%$INSTALL%g fi; done rm -f conftest.s* +# 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='\3' +ac_dD='%g' +# ac_u turns "#undef NAME" with trailing blanks into "#define NAME VALUE". +ac_uA='s%^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' +ac_uB='\([ ]\)%\1#\2define\3' +ac_uC=' ' +ac_uD='\4%g' +# ac_e turns "#undef NAME" without trailing blanks into "#define NAME VALUE". +ac_eA='s%^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' +ac_eB='$%\1#\2define\3' +ac_eC=' ' +ac_eD='%g' + +if test "${CONFIG_HEADERS+set}" != set; then +EOF +cat >> $CONFIG_STATUS <<EOF + CONFIG_HEADERS="config.h" +EOF +cat >> $CONFIG_STATUS <<\EOF +fi +for ac_file in .. $CONFIG_HEADERS; 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" ;; + esac + + echo creating $ac_file + + rm -f conftest.frag conftest.in conftest.out + ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"` + cat $ac_file_inputs > conftest.in + +EOF + +# Transform confdefs.h into a sed script conftest.vals that substitutes +# the proper values into config.h.in to produce config.h. 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.vals +cat > conftest.hdr <<\EOF +s/[\\&%]/\\&/g +s%[\\$`]%\\&%g +s%#define \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD}%gp +s%ac_d%ac_u%gp +s%ac_u%ac_e%gp +EOF +sed -n -f conftest.hdr confdefs.h > conftest.vals +rm -f conftest.hdr + +# 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.vals <<\EOF +s%^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*%/* & */% +EOF + +# Break up conftest.vals because some shells have a limit on +# the size of here documents, and old seds have small limits too. + +rm -f conftest.tail +while : +do + ac_lines=`grep -c . conftest.vals` + # grep -c gives empty output for an empty file on some AIX systems. + if test -z "$ac_lines" || test "$ac_lines" -eq 0; then break; fi + # Write a limited-size here document to conftest.frag. + echo ' cat > conftest.frag <<CEOF' >> $CONFIG_STATUS + sed ${ac_max_here_lines}q conftest.vals >> $CONFIG_STATUS + echo 'CEOF + sed -f conftest.frag conftest.in > conftest.out + rm -f conftest.in + mv conftest.out conftest.in +' >> $CONFIG_STATUS + sed 1,${ac_max_here_lines}d conftest.vals > conftest.tail + rm -f conftest.vals + mv conftest.tail conftest.vals +done +rm -f conftest.vals + +cat >> $CONFIG_STATUS <<\EOF + rm -f conftest.frag conftest.h + echo "/* $ac_file. Generated automatically by configure. */" > conftest.h + cat conftest.in >> conftest.h + rm -f conftest.in + if cmp -s $ac_file conftest.h 2>/dev/null; then + echo "$ac_file is unchanged" + rm -f conftest.h + else + # 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" + fi + rm -f $ac_file + mv conftest.h $ac_file + fi +fi; done + EOF cat >> $CONFIG_STATUS <<EOF diff --git a/contrib/tcpdump/configure.in b/contrib/tcpdump/configure.in index f2a2126..6161766 100755 --- a/contrib/tcpdump/configure.in +++ b/contrib/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.87.2.4 2000/01/25 18:39:02 itojun Exp $ (LBL) dnl dnl Copyright (c) 1994, 1995, 1996, 1997 dnl The Regents of the University of California. All rights reserved. @@ -17,6 +17,7 @@ if test -z "$PWD" ; then fi AC_LBL_C_INIT(V_CCOPT, V_INCLS) +AC_C_INLINE AC_CHECK_HEADERS(fcntl.h malloc.h memory.h rpc/rpcent.h) AC_HEADER_TIME @@ -40,14 +41,404 @@ linux*) ;; esac + +AC_CHECK_HEADERS(smi.h) +AC_CHECK_LIB(smi, main) +AC_MSG_CHECKING([whether to enable libsmi]) + AC_TRY_RUN([ /* libsmi available check */ +#include <smi.h> +main() +{ + if (smiInit("")) + exit(1); + else + exit(0); +} +], +[ AC_MSG_RESULT(yes) + AC_DEFINE(LIBSMI) + libsmi=yes], +[ AC_MSG_RESULT(no) + libsmi=no] +) + + +CFLAGS="$CFLAGS -Dss_family=__ss_family -Dss_len=__ss_len" +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) + AC_DEFINE(ENABLE_IPV6) + LOCALSRC="print-ip6.c print-ip6opts.c print-ripng.c print-icmp6.c print-frag6.c print-rt6.c print-ospf6.c print-dhcp6.c $LOCALSRC" + AC_DEFINE(INET6) + ipv6=yes + ;; +*) + AC_MSG_RESULT(no) + ipv6=no + ;; + esac ], + + AC_TRY_RUN([ /* AF_INET6 available check */ +#include <sys/types.h> +#include <sys/socket.h> +main() +{ + if (socket(AF_INET6, SOCK_STREAM, 0) < 0) + exit(1); + else + exit(0); +} +], +[ AC_MSG_RESULT(yes) + AC_DEFINE(ENABLE_IPV6) + LOCALSRC="print-ip6.c print-ip6opts.c print-ripng.c print-icmp6.c print-frag6.c print-rt6.c print-ospf6.c print-dhcp6.c $LOCALSRC" + 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, [dnl +#include <netinet/in.h> +#ifdef IPV6_INRIA_VERSION +yes +#endif], + [ipv6type=$i; + CFLAGS="-DINET6 $CFLAGS"]) + ;; + kame) + dnl http://www.kame.net/ + AC_EGREP_CPP(yes, [dnl +#include <netinet/in.h> +#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, [dnl +#include <features.h> +#if defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1 +yes +#endif], + [ipv6type=$i; + CFLAGS="-DINET6 $CFLAGS"]) + ;; + linux-libinet6) + dnl http://www.v6.linux.or.jp/ + 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, [dnl +#include <sys/param.h> +#ifdef _TOSHIBA_INET6 +yes +#endif], + [ipv6type=$i; + ipv6lib=inet6; + ipv6libdir=/usr/local/v6/lib; + CFLAGS="-DINET6 $CFLAGS"]) + ;; + v6d) + AC_EGREP_CPP(yes, [dnl +#include </usr/local/v6/include/sys/v6config.h> +#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, [dnl +#include <sys/param.h> +#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 + + +if test "$ipv6" = "yes"; then + AC_CHECK_FUNCS(getaddrinfo, [dnl + AC_MSG_CHECKING(getaddrinfo bug) + AC_TRY_RUN([ +#include <sys/types.h> +#include <netdb.h> +#include <string.h> +#include <sys/socket.h> +#include <netinet/in.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; + 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); +} +], + AC_MSG_RESULT(good) + buggygetaddrinfo=no, + AC_MSG_RESULT(buggy) + buggygetaddrinfo=yes, + AC_MSG_RESULT(buggy) + buggygetaddrinfo=yes)], [buggygetaddrinfo=yes]) + + if test "$buggygetaddrinfo" = "yes"; then + 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 upgreade your system library to newest version' + echo ' of GNU C library (aka glibc).' + fi + fi + AC_REPLACE_FUNCS(getaddrinfo getnameinfo) +fi +AC_REPLACE_FUNCS(inet_ntop inet_pton inet_aton) + +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 + +dnl +dnl check __P macro +AC_CHECK_PORTABLE_PROTO(ac_cv_portable_proto) +if test "$ac_cv_portable_proto" = no; then + missing_includes=yes +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 AAAA +AC_CHECK_AAAA(ac_cv_aaaa) +if test "$ac_cv_aaaa" = no; then + AC_DEFINE(T_AAAA, 28) +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) -AC_CHECK_FUNCS(ether_ntoa setlinebuf) +AC_CHECK_FUNCS(ether_ntohost setlinebuf gethostbyname2) dnl The following generates a warning from autoconf... AC_C_BIGENDIAN AC_CHECK_LIB(dnet, main) AC_CHECK_LIB(rpc, main) +AC_CHECK_LIB(z, uncompress) +AC_CHECK_HEADERS(zlib.h) AC_LBL_TYPE_SIGNAL @@ -69,7 +460,7 @@ irix*) ;; linux*) - V_INCLS="$V_INCLS -Ilinux-include" + V_INCLS="$V_INCLS -I\$(srcdir)/linux-include" ;; osf*) @@ -87,6 +478,9 @@ if test -f /dev/bpf0 ; then V_GROUP=bpf fi +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) @@ -170,24 +564,96 @@ fi AC_LBL_UNALIGNED_ACCESS -if test "${srcdir}" = "." ; then - srcdirprefix="" -else - srcdirprefix="./" +AC_VAR_H_ERRNO + +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 + ac_cv_ssleay_path=$dir + fi + if test -d $dir/include -a -f $dir/include/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; + else + ac_cv_ssleay_path=no + incdir=no + fi +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" + 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 <cast.h> +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 -r ${srcdirprefix}lbl/gnuc.h ; then +if test -r ${srcdir}/lbl/gnuc.h ; then rm -f gnuc.h - ln -s ${srcdirprefix}lbl/gnuc.h gnuc.h + ln -s ${srcdir}/lbl/gnuc.h gnuc.h fi AC_SUBST(V_CCOPT) AC_SUBST(V_GROUP) AC_SUBST(V_INCLS) AC_SUBST(V_PCAPDEP) +AC_SUBST(LOCALSRC) AC_PROG_INSTALL +AC_CONFIG_HEADER(config.h) + AC_OUTPUT(Makefile) if test -f .devel ; then diff --git a/contrib/tcpdump/decnet.h b/contrib/tcpdump/decnet.h index 0f4bd4c..86dea61 100644 --- a/contrib/tcpdump/decnet.h +++ b/contrib/tcpdump/decnet.h @@ -18,7 +18,7 @@ * 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.6.1.1 1999/10/07 23:47:10 mcr Exp $ (LBL) */ typedef unsigned char byte[1]; /* single byte field */ diff --git a/contrib/tcpdump/dhcp6.h b/contrib/tcpdump/dhcp6.h new file mode 100644 index 0000000..161796f --- /dev/null +++ b/contrib/tcpdump/dhcp6.h @@ -0,0 +1,191 @@ +/* + * 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. + */ +/* + * draft-ietf-dhc-dhcpv6-14 + */ + +#ifndef __DHCP6_H_DEFINED +#define __DHCP6_H_DEFINED + +/* Error Values */ +#define DH6ERR_FAILURE 16 +#define DH6ERR_AUTHFAIL 17 +#define DH6ERR_POORLYFORMED 18 +#define DH6ERR_UNAVAIL 19 +#define DH6ERR_NOBINDING 20 +#define DH6ERR_INVALIDSOURCE 21 +#define DH6ERR_NOSERVER 23 +#define DH6ERR_ICMPERROR 64 + +/* Message type */ +#define DH6_SOLICIT 1 +#define DH6_ADVERT 2 +#define DH6_REQUEST 3 +#define DH6_REPLY 4 +#define DH6_RELEASE 5 +#define DH6_RECONFIG 6 + +/* Predefined addresses */ +#define DH6ADDR_ALLAGENT "ff02::1:2" +#define DH6ADDR_ALLSERVER "ff05::1:3" +#define DH6ADDR_ALLRELAY "ff05::1:4" +#define DH6PORT_DOWNSTREAM "546" +#define DH6PORT_UPSTREAM "547" + +/* Protocol constants */ +#define ADV_CLIENT_WAIT 2 /* sec */ +#define DEFAULT_SOLICIT_HOPCOUNT 4 +#define SERVER_MIN_ADV_DELAY 100 /* msec */ +#define SERVER_MAX_ADV_DELAY 1000 /* msec */ +#define REPLY_MSG_TIMEOUT 2 /* sec */ +#define REQUEST_MSG_MIN_RETRANS 10 /* retransmissions */ +#define RECONF_MSG_MIN_RETRANS 10 /* retransmissions */ +#define RECONF_MSG_RETRANS_INTERVAL 12 /* sec */ +#define RECONF_MMSG_MIN_RESP 2 /* sec */ +#define RECONF_MMSG_MAX_RESP 10 /* sec */ +#define RECONF_MULTICAST_REQUEST_WAIT 120 /* sec */ +#define MIN_SOLICIT_DELAY 1 /* sec */ +#define MAX_SOLICIT_DELAY 5 /* sec */ +#define XID_TIMEOUT 600 /* sec */ + +/* DHCP6 base packet format */ +struct dhcp6_solicit { + u_int8_t dh6sol_msgtype; /* DH6_SOLICIT */ + u_int8_t dh6sol_flags; +#define DH6SOL_CLOSE 0x80 + u_int8_t dh6sol_pad; + u_int8_t dh6sol_prefixsiz; /* prefix-size */ + struct in6_addr dh6sol_cliaddr; /* client's lladdr */ + struct in6_addr dh6sol_relayaddr; /* relay agent's lladdr */ +}; + +/* NOTE: dhcpv6-12 and dhcpv6-13+n are not compatible at all */ +struct dhcp6_advert { + u_int8_t dh6adv_msgtype; /* DH6_ADVERT */ + u_int8_t dh6adv_flags; +#define DH6ADV_SERVPRESENT 0x80 + u_int8_t dh6adv_pad; + u_int8_t dh6adv_pref; + struct in6_addr dh6adv_cliaddr; /* client's lladdr */ + struct in6_addr dh6adv_relayaddr; /* relay agent's (non-ll) addr */ + struct in6_addr dh6adv_serveraddr; /* server's addr */ + /* extensions */ +}; + +struct dhcp6_request { + u_int8_t dh6req_msgtype; /* DH6_REQUEST */ + u_int8_t dh6req_flags; +#define DH6REQ_CLOSE 0x80 +#define DH6REQ_SERVPRESENT 0x40 +#define DH6REQ_REBOOT 0x20 + u_int16_t dh6req_xid; /* transaction-ID */ + struct in6_addr dh6req_cliaddr; /* client's lladdr */ + struct in6_addr dh6req_relayaddr; /* relay agent's (non-ll) addr */ + /* struct in6_addr dh6req_serveraddr; optional: server's addr */ + /* extensions */ +}; + +struct dhcp6_reply { + u_int8_t dh6rep_msgtype; /* DH6_REPLY */ + u_int8_t dh6rep_flagandstat; +#define DH6REP_CLIPRESENT 0x80 +#define DH6REP_STATMASK 0x7f + u_int16_t dh6rep_xid; /* transaction-ID */ + /* struct in6_addr dh6rep_cliaddr; optional: client's lladdr */ + /* extensions */ +}; + +struct dhcp6_release { + u_int8_t dh6rel_msgtype; /* DH6_RELEASE */ + u_int8_t dh6rel_flags; +#define DH6REL_DIRECT 0x80 + u_int16_t dh6rel_xid; /* transaction-ID */ + struct in6_addr dh6rel_cliaddr; /* client's lladdr */ + struct in6_addr dh6rel_relayaddr; /* relay agent's (non-ll) addr */ + struct in6_addr dh6rel_reladdr; /* server's addr to be released */ + /* extensions */ +}; + +struct dhcp6_reconfig { + u_int8_t dh6cfg_msgtype; /* DH6_RECONFIG */ + u_int8_t dh6cfg_flags; +#define DH6REP_NOREPLY 0x80 + u_int16_t dh6cfg_xid; /* transaction-ID */ + struct in6_addr dh6cfg_servaddr; /* server's addr */ + /* extensions */ +}; + +union dhcp6 { + u_int8_t dh6_msgtype; + struct dhcp6_solicit dh6_sol; + struct dhcp6_advert dh6_adv; + struct dhcp6_request dh6_req; + struct dhcp6_reply dh6_rep; + struct dhcp6_release dh6_rel; + struct dhcp6_reconfig dh6_cfg; +}; + +/* DHCP6 extension */ +struct dhcp6e_ipaddr { + u_int16_t dh6eip_type; + u_int16_t dh6eip_len; + u_int8_t dh6eip_status; +#define DH6EX_IP_SUCCESS 0 /* request granted, no errors */ +#define DH6EX_IP_SECFAIL 18 /* Security parameters failed */ +#define DH6EX_IP_AAAAFAIL 20 /* AAAA Record Parameter Problem */ +#define DH6EX_IP_PTRFAIL 21 /* PTR Record Parameter Problem */ +#define DH6EX_IP_PARAMFAIL 22 /* Unable to honor required params */ +#define DH6EX_IP_DNSNAMEFAIL 23 /* DNS name string error */ +#define DH6EX_IP_NODYNDNS 24 /* dynDNS Not Implemented */ +#define DH6EX_IP_NOAUTHDNS 25 /* Authoritative DNS Server not found */ +#define DH6EX_IP_DNSFORMFAIL 33 /* DNS format error */ +#define DH6EX_IP_SERVFAIL 34 /* dynDNS unavailable at this time */ +#define DH6EX_IP_NXDOMAIN 35 /* name does not exist */ +#define DH6EX_IP_NOTIMP 36 /* DNS does not support the Opcode */ +#define DH6EX_IP_REFUSED 37 /* DNS refuses specified operation */ +#define DH6EX_IP_YXDOMAIN 38 /* name does not exist */ +#define DH6EX_IP_YXRRSET 39 /* RRset does not exist */ +#define DH6EX_IP_NXRRSET 40 /* RRset does not exist */ +#define DH6EX_IP_NOTAUTH 41 /* non authoritative name server */ +#define DH6EX_IP_NOTZONE 42 /* prerequisite out of zone */ + u_int8_t dh6eip_flags; +#define DH6EX_IP_CLIANTADDR 0x80 /* C: cliant's addr */ +#define DH6EX_IP_LIFETIME 0x40 /* L: preferred/valid lifetime */ +#define DH6EX_IP_FORCEOPTS 0x20 /* Q: options are mandatory */ +#define DH6EX_IP_AAAA 0x10 /* A: DNS dynamic update for AAAA */ +#define DH6EX_IP_PTR 0x08 /* P: DNS dynamic update for PTR*/ + u_int8_t dh6eip_pad; + u_int8_t dh6eip_prefixlen; + /* struct in6_addr: client's address (if C bit = 1) */ + /* u_int: preferred lifetime (if L bit = 1) */ + /* u_int: valid lifetime (if L bit = 1) */ + /* string: DNS name */ +}; + +#endif /*__DHCP6_H_DEFINED*/ diff --git a/contrib/tcpdump/dhcp6opt.h b/contrib/tcpdump/dhcp6opt.h new file mode 100644 index 0000000..a9177c6 --- /dev/null +++ b/contrib/tcpdump/dhcp6opt.h @@ -0,0 +1,80 @@ +/* + * 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. + */ + +/* + * draft-ietf-dhc-v6exts-11 + */ + +#ifndef __DHCP6OPT_H_DEFINED +#define __DHCP6OPT_H_DEFINED + +#define OL6_N -1 +#define OL6_16N -2 +#define OL6_Z -3 + +#define OT6_NONE 0 +#define OT6_V6 1 +#define OT6_STR 2 +#define OT6_NUM 3 + +struct dhcp6_opt { + u_int code; + int len; + char *name; + int type; +}; + +/* index to parameters */ +#define DH6T_CLIENT_ADV_WAIT 1 /* milliseconds */ +#define DH6T_DEFAULT_SOLICIT_HOPCOUNT 2 /* times */ +#define DH6T_SERVER_MIN_ADV_DELAY 3 /* milliseconds */ +#define DH6T_SERVER_MAX_ADV_DELAY 4 /* milliseconds */ +#define DH6T_REQUEST_MSG_MIN_RETRANS 5 /* retransmissions */ +#define DH6T_REPLY_MSG_TIMEOUT 6 /* milliseconds */ +#define DH6T_REPLY_MSG_RETRANS_INTERVAL 7 /* milliseconds */ +#define DH6T_RECONF_MSG_TIMEOUT 8 /* milliseconds */ +#define DH6T_RECONF_MSG_MIN_RETRANS 9 /* retransmissions */ +#define DH6T_RECONF_MSG_RETRANS_INTERVAL 10 /* milliseconds */ +#define DH6T_RECONF_MMSG_MIN_RESP 11 /* milliseconds */ +#define DH6T_RECONF_MMSG_MAX_RESP 12 /* milliseconds */ +#define DH6T_MIN_SOLICIT_DELAY 13 /* milliseconds */ +#define DH6T_MAX_SOLICIT_DELAY 14 /* milliseconds */ +#define DH6T_XID_TIMEOUT 15 /* milliseconds */ +#define DH6T_RECONF_MULTICAST_REQUEST_WAIT 16 /* milliseconds */ + +#if 0 +extern struct dhcp6_opt *dh6o_pad; +extern struct dhcp6_opt *dh6o_end; +extern int dhcp6_param[]; +extern void dhcp6opttab_init __P((void)); +extern struct dhcp6_opt *dhcp6opttab_byname __P((char *)); +extern struct dhcp6_opt *dhcp6opttab_bycode __P((u_int)); +#endif + +#endif /*__DHCP6OPT_H_DEFINED*/ diff --git a/contrib/tcpdump/extract.h b/contrib/tcpdump/extract.h index fbc8b5f..e4fb6f2 100644 --- a/contrib/tcpdump/extract.h +++ b/contrib/tcpdump/extract.h @@ -18,7 +18,7 @@ * 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.15.1.1 1999/10/07 23:47:10 mcr Exp $ (LBL) */ /* Network to host order macros */ diff --git a/contrib/tcpdump/fddi.h b/contrib/tcpdump/fddi.h index 96ff820..894cee3 100644 --- a/contrib/tcpdump/fddi.h +++ b/contrib/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.8.1.1 1999/10/07 23:47:10 mcr Exp $ (LBL) */ /* diff --git a/contrib/tcpdump/gmt2local.c b/contrib/tcpdump/gmt2local.c index 5812cfe..2310dbc 100644 --- a/contrib/tcpdump/gmt2local.c +++ b/contrib/tcpdump/gmt2local.c @@ -21,7 +21,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: gmt2local.c,v 1.2 97/01/23 22:31:25 leres Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/gmt2local.c,v 1.3 1999/11/21 09:36:47 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/types.h> diff --git a/contrib/tcpdump/gmt2local.h b/contrib/tcpdump/gmt2local.h index 4933b09..81b0e96 100644 --- a/contrib/tcpdump/gmt2local.h +++ b/contrib/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/contrib/tcpdump/igrp.h b/contrib/tcpdump/igrp.h index cc6088a..1d84b54 100644 --- a/contrib/tcpdump/igrp.h +++ b/contrib/tcpdump/igrp.h @@ -4,11 +4,11 @@ struct igrphdr { #ifdef WORDS_BIGENDIAN - u_char ig_v:4; /* protocol version number */ - u_char ig_op:4; /* opcode */ + u_int ig_v:4; /* protocol version number */ + u_int ig_op:4; /* opcode */ #else - u_char ig_op:4; /* opcode */ - u_char ig_v:4; /* protocol version number */ + u_int ig_op:4; /* opcode */ + u_int ig_v:4; /* protocol version number */ #endif u_char ig_ed; /* edition number */ u_short ig_as; /* autonomous system number */ diff --git a/contrib/tcpdump/ipsec_doi.h b/contrib/tcpdump/ipsec_doi.h new file mode 100644 index 0000000..b2a9c93 --- /dev/null +++ b/contrib/tcpdump/ipsec_doi.h @@ -0,0 +1,164 @@ +/* + * 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. + */ +/* YIPS @(#)$Id: ipsec_doi.h,v 1.1 1999/10/30 05:11:09 itojun Exp $ */ + +/* refer to RFC 2407 */ + +#if !defined(_IPSEC_DOI_H_) +#define _IPSEC_DOI_H_ + +#define IPSEC_DOI 1 + +/* 4.2 IPSEC Situation Definition */ +#define IPSECDOI_SIT_IDENTITY_ONLY 0x00000001 +#define IPSECDOI_SIT_SECRECY 0x00000002 +#define IPSECDOI_SIT_INTEGRITY 0x00000004 + +/* 4.4.1 IPSEC Security Protocol Identifiers */ + /* 4.4.2 IPSEC ISAKMP Transform Values */ +#define IPSECDOI_PROTO_ISAKMP 1 +#define IPSECDOI_KEY_IKE 1 + +/* 4.4.1 IPSEC Security Protocol Identifiers */ +#define IPSECDOI_PROTO_IPSEC_AH 2 + /* 4.4.3 IPSEC AH Transform Values */ +#define IPSECDOI_AH_MD5 2 +#define IPSECDOI_AH_SHA 3 +#define IPSECDOI_AH_DES 4 + +/* 4.4.1 IPSEC Security Protocol Identifiers */ +#define IPSECDOI_PROTO_IPSEC_ESP 3 + /* 4.4.4 IPSEC ESP Transform Identifiers */ +#define IPSECDOI_ESP_DES_IV64 1 +#define IPSECDOI_ESP_DES 2 +#define IPSECDOI_ESP_3DES 3 +#define IPSECDOI_ESP_RC5 4 +#define IPSECDOI_ESP_IDEA 5 +#define IPSECDOI_ESP_CAST 6 +#define IPSECDOI_ESP_BLOWFISH 7 +#define IPSECDOI_ESP_3IDEA 8 +#define IPSECDOI_ESP_DES_IV32 9 +#define IPSECDOI_ESP_RC4 10 +#define IPSECDOI_ESP_NULL 11 + +/* 4.4.1 IPSEC Security Protocol Identifiers */ +#define IPSECDOI_PROTO_IPCOMP 4 + /* 4.4.5 IPSEC IPCOMP Transform Identifiers */ +#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 */ +#define IPSECDOI_ATTR_SA_LTYPE_DEFAULT 1 +#define IPSECDOI_ATTR_SA_LTYPE_SEC 1 +#define IPSECDOI_ATTR_SA_LTYPE_KB 2 +#define IPSECDOI_ATTR_SA_LDUR 2 /* V */ +#define IPSECDOI_ATTR_SA_LDUR_DEFAULT 28800 /* 8 hours */ +#define IPSECDOI_ATTR_GRP_DESC 3 /* B */ +#define IPSECDOI_ATTR_ENC_MODE 4 /* B */ + /* default value: host dependent */ +#define IPSECDOI_ATTR_ENC_MODE_TUNNEL 1 +#define IPSECDOI_ATTR_ENC_MODE_TRNS 2 +#define IPSECDOI_ATTR_AUTH 5 /* B */ +#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 + /* + 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 */ +#define IPSECDOI_ATTR_COMP_DICT_SIZE 8 /* B */ +#define IPSECDOI_ATTR_COMP_PRIVALG 9 /* V */ + +/* 4.6.1 Security Association Payload */ +struct ipsecdoi_sa { + struct isakmp_gen h; + u_int32_t doi; /* Domain of Interpretation */ + u_int32_t sit; /* Situation */ +}; + +struct ipsecdoi_secrecy_h { + u_int16_t len; + u_int16_t reserved; +}; + +/* 4.6.2.1 Identification Type Values */ +struct ipsecdoi_id { + struct isakmp_gen h; + u_int8_t type; /* ID Type */ + u_int8_t proto_id; /* Protocol ID */ + u_int16_t port; /* Port */ + /* Identification Data */ +}; + +#define IPSECDOI_ID_IPV4_ADDR 1 +#define IPSECDOI_ID_FQDN 2 +#define IPSECDOI_ID_USER_FQDN 3 +#define IPSECDOI_ID_IPV4_ADDR_SUBNET 4 +#define IPSECDOI_ID_IPV6_ADDR 5 +#define IPSECDOI_ID_IPV6_ADDR_SUBNET 6 +#define IPSECDOI_ID_IPV4_ADDR_RANGE 7 +#define IPSECDOI_ID_IPV6_ADDR_RANGE 8 +#define IPSECDOI_ID_DER_ASN1_DN 9 +#define IPSECDOI_ID_DER_ASN1_GN 10 +#define IPSECDOI_ID_KEY_ID 11 + +/* 4.6.3 IPSEC DOI Notify Message Types */ +/* Notify Messages - Status Types */ +#define IPSECDOI_NTYPE_RESPONDER_LIFETIME 24576 +#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/contrib/tcpdump/ipx.h b/contrib/tcpdump/ipx.h index 0a70724..7d7fbc5 100644 --- a/contrib/tcpdump/ipx.h +++ b/contrib/tcpdump/ipx.h @@ -1,7 +1,7 @@ /* * 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.1.1.1 1999/10/07 23:47:10 mcr Exp $ */ /* well-known sockets */ diff --git a/contrib/tcpdump/isakmp.h b/contrib/tcpdump/isakmp.h new file mode 100644 index 0000000..fbd9a1d --- /dev/null +++ b/contrib/tcpdump/isakmp.h @@ -0,0 +1,447 @@ +/* + * 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. + */ +/* YIPS @(#)$Id: isakmp.h,v 1.4.2.1 2000/01/14 19:19:56 mcr Exp $ */ + +/* refer to RFC 2408 */ + +/* must include <netinet/in.h> */ + +#if !defined(_ISAKMP_H_) +#define _ISAKMP_H_ + +typedef u_char cookie_t[8]; +typedef u_char msgid_t[4]; + +typedef struct { /* i_cookie + r_cookie */ + cookie_t i_ck; + cookie_t r_ck; +} isakmp_index; + +#define INITIATOR 1 +#define RESPONDER 2 + +#define PORT_ISAKMP 500 + +#define GENERATE 1 +#define VALIDATE 0 + +/* Phase of oakley definition */ +/* + 0000 0000 0000 0000 + | |||| |||| + | |||| ++++--> negosiation number in phase + | ++++-------> phase number + +---------------> expire ? + */ +#define ISAKMP_PH1 0x0010 +#define ISAKMP_PH2 0x0020 +#define ISAKMP_EXPIRED 0x0100 + +#define ISAKMP_NGP_0 0x0000 +#define ISAKMP_NGP_1 0x0001 +#define ISAKMP_NGP_2 0x0002 +#define ISAKMP_NGP_3 0x0003 +#define ISAKMP_NGP_4 0x0004 + +#define ISAKMP_PH1_N (ISAKMP_PH1 | ISAKMP_NGP_0) /* i.e. spawn */ +#define ISAKMP_PH1_1 (ISAKMP_PH1 | ISAKMP_NGP_1) +#define ISAKMP_PH1_2 (ISAKMP_PH1 | ISAKMP_NGP_2) +#define ISAKMP_PH1_3 (ISAKMP_PH1 | ISAKMP_NGP_3) +#define ISAKMP_PH2_N (ISAKMP_PH2 | ISAKMP_NGP_0) +#define ISAKMP_PH2_1 (ISAKMP_PH2 | ISAKMP_NGP_1) +#define ISAKMP_PH2_2 (ISAKMP_PH2 | ISAKMP_NGP_2) +#define ISAKMP_PH2_3 (ISAKMP_PH2 | ISAKMP_NGP_3) + +#define ISAKMP_TIMER_DEFAULT 10 /* seconds */ +#define ISAKMP_TRY_DEFAULT 3 /* times */ + +/* 3.1 ISAKMP Header Format + 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 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + ! Initiator ! + ! Cookie ! + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + ! Responder ! + ! Cookie ! + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + ! Next Payload ! MjVer ! MnVer ! Exchange Type ! Flags ! + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + ! Message ID ! + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + ! Length ! + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +*/ +struct isakmp { + 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 */ +#define ISAKMP_NPTYPE_NONE 0 /* NONE*/ +#define ISAKMP_NPTYPE_SA 1 /* Security Association */ +#define ISAKMP_NPTYPE_P 2 /* Proposal */ +#define ISAKMP_NPTYPE_T 3 /* Transform */ +#define ISAKMP_NPTYPE_KE 4 /* Key Exchange */ +#define ISAKMP_NPTYPE_ID 5 /* Identification */ +#define ISAKMP_NPTYPE_CERT 6 /* Certificate */ +#define ISAKMP_NPTYPE_CR 7 /* Certificate Request */ +#define ISAKMP_NPTYPE_HASH 8 /* Hash */ +#define ISAKMP_NPTYPE_SIG 9 /* Signature */ +#define ISAKMP_NPTYPE_NONCE 10 /* Nonce */ +#define ISAKMP_NPTYPE_N 11 /* Notification */ +#define ISAKMP_NPTYPE_D 12 /* Delete */ +#define ISAKMP_NPTYPE_VID 13 /* Vendor ID */ + +#define ISAKMP_MAJOR_VERSION 1 +#define ISAKMP_MINOR_VERSION 0 + +/* Exchange Type */ +#define ISAKMP_ETYPE_NONE 0 /* NONE */ +#define ISAKMP_ETYPE_BASE 1 /* Base */ +#define ISAKMP_ETYPE_IDENT 2 /* Identity Proteciton */ +#define ISAKMP_ETYPE_AUTH 3 /* Authentication Only */ +#define ISAKMP_ETYPE_AGG 4 /* Aggressive */ +#define ISAKMP_ETYPE_INF 5 /* Informational */ + +/* Flags */ +#define ISAKMP_FLAG_E 0x01 /* Encryption Bit */ +#define ISAKMP_FLAG_C 0x02 /* Commit Bit */ + +/* 3.2 Payload Generic Header + 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 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + ! Next Payload ! RESERVED ! Payload Length ! + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +*/ +struct isakmp_gen { + u_int8_t np; /* Next Payload */ + u_int8_t reserved; /* RESERVED, unused, must set to 0 */ + u_int16_t len; /* Payload Length */ +}; + +/* 3.3 Data Attributes + 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 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + !A! Attribute Type ! AF=0 Attribute Length ! + !F! ! AF=1 Attribute Value ! + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + . AF=0 Attribute Value . + . AF=1 Not Transmitted . + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +*/ +struct isakmp_data { + u_int16_t type; /* defined by DOI-spec, and Attribute Format */ + u_int16_t lorv; /* if f equal 1, Attribute Length */ + /* if f equal 0, Attribute Value */ + /* if f equal 1, Attribute Value */ +}; +#define ISAKMP_GEN_TLV 0x0000 +#define ISAKMP_GEN_TV 0x8000 + /* mask for type of attribute format */ +#define ISAKMP_GEN_MASK 0x8000 + +/* 3.4 Security Association Payload */ + /* MAY NOT be used, because of being defined in ipsec-doi. */ + /* + If the current payload is the last in the message, + then the value of the next payload field will be 0. + This field MUST NOT contain the + values for the Proposal or Transform payloads as they are considered + part of the security association negotiation. For example, this + field would contain the value "10" (Nonce payload) in the first + message of a Base Exchange (see Section 4.4) and the value "0" in the + first message of an Identity Protect Exchange (see Section 4.5). + */ +struct isakmp_pl_sa { + struct isakmp_gen h; + u_int32_t doi; /* Domain of Interpretation */ + u_int32_t sit; /* Situation */ +}; + +/* 3.5 Proposal Payload */ + /* + The value of the next payload field MUST only contain the value "2" + or "0". If there are additional Proposal payloads in the message, + then this field will be 2. If the current Proposal payload is the + last within the security association proposal, then this field will + be 0. + */ +struct isakmp_pl_p { + struct isakmp_gen h; + u_int8_t p_no; /* Proposal # */ + u_int8_t prot_id; /* Protocol */ + u_int8_t spi_size; /* SPI Size */ + u_int8_t num_t; /* Number of Transforms */ + /* SPI */ +}; + +/* 3.6 Transform Payload */ + /* + The value of the next payload field MUST only contain the value "3" + or "0". If there are additional Transform payloads in the proposal, + then this field will be 3. If the current Transform payload is the + last within the proposal, then this field will be 0. + */ +struct isakmp_pl_t { + struct isakmp_gen h; + u_int8_t t_no; /* Transform # */ + u_int8_t t_id; /* Transform-Id */ + u_int16_t reserved; /* RESERVED2 */ + /* SA Attributes */ +}; + +/* 3.7 Key Exchange Payload */ +struct isakmp_pl_ke { + struct isakmp_gen h; + /* Key Exchange Data */ +}; + +/* 3.8 Identification Payload */ + /* MUST NOT to be used, because of being defined in ipsec-doi. */ +struct isakmp_pl_id { + struct isakmp_gen h; + union { + u_int8_t id_type; /* ID Type */ + u_int32_t doi_data; /* DOI Specific ID Data */ + } d; + /* Identification Data */ +}; + +/* 3.9 Certificate Payload */ +struct isakmp_pl_cert { + struct isakmp_gen h; + u_int8_t encode; /* Cert Encoding */ + char cert; /* Certificate Data */ + /* + This field indicates the type of + certificate or certificate-related information contained in the + Certificate Data field. + */ +}; + +/* Certificate Type */ +#define ISAKMP_CERT_NONE 0 +#define ISAKMP_CERT_PKCS 1 +#define ISAKMP_CERT_PGP 2 +#define ISAKMP_CERT_DNS 3 +#define ISAKMP_CERT_SIGN 4 +#define ISAKMP_CERT_KE 5 +#define ISAKMP_CERT_KT 6 +#define ISAKMP_CERT_CRL 7 +#define ISAKMP_CERT_ARL 8 +#define ISAKMP_CERT_SPKI 9 + +/* 3.10 Certificate Request Payload */ +struct isakmp_pl_cr { + struct isakmp_gen h; + u_int8_t num_cert; /* # Cert. Types */ + /* + Certificate Types (variable length) + -- Contains a list of the types of certificates requested, + sorted in order of preference. Each individual certificate + type is 1 octet. This field is NOT requiredo + */ + /* # Certificate Authorities (1 octet) */ + /* Certificate Authorities (variable length) */ +}; + +/* 3.11 Hash Payload */ + /* may not be used, because of having only data. */ +struct isakmp_pl_hash { + struct isakmp_gen h; + /* Hash Data */ +}; + +/* 3.12 Signature Payload */ + /* may not be used, because of having only data. */ +struct isakmp_pl_sig { + struct isakmp_gen h; + /* Signature Data */ +}; + +/* 3.13 Nonce Payload */ + /* may not be used, because of having only data. */ +struct isakmp_pl_nonce { + struct isakmp_gen h; + /* Nonce Data */ +}; + +/* 3.14 Notification Payload */ +struct isakmp_pl_n { + struct isakmp_gen h; + u_int32_t doi; /* Domain of Interpretation */ + u_int8_t prot_id; /* Protocol-ID */ + u_int8_t spi_size; /* SPI Size */ + u_int16_t type; /* Notify Message Type */ + /* SPI */ + /* Notification Data */ +}; + +/* 3.14.1 Notify Message Types */ +/* NOTIFY MESSAGES - ERROR TYPES */ +#define ISAKMP_NTYPE_INVALID_PAYLOAD_TYPE 1 +#define ISAKMP_NTYPE_DOI_NOT_SUPPORTED 2 +#define ISAKMP_NTYPE_SITUATION_NOT_SUPPORTED 3 +#define ISAKMP_NTYPE_INVALID_COOKIE 4 +#define ISAKMP_NTYPE_INVALID_MAJOR_VERSION 5 +#define ISAKMP_NTYPE_INVALID_MINOR_VERSION 6 +#define ISAKMP_NTYPE_INVALID_EXCHANGE_TYPE 7 +#define ISAKMP_NTYPE_INVALID_FLAGS 8 +#define ISAKMP_NTYPE_INVALID_MESSAGE_ID 9 +#define ISAKMP_NTYPE_INVALID_PROTOCOL_ID 10 +#define ISAKMP_NTYPE_INVALID_SPI 11 +#define ISAKMP_NTYPE_INVALID_TRANSFORM_ID 12 +#define ISAKMP_NTYPE_ATTRIBUTES_NOT_SUPPORTED 13 +#define ISAKMP_NTYPE_NO_PROPOSAL_CHOSEN 14 +#define ISAKMP_NTYPE_BAD_PROPOSAL_SYNTAX 15 +#define ISAKMP_NTYPE_PAYLOAD_MALFORMED 16 +#define ISAKMP_NTYPE_INVALID_KEY_INFORMATION 17 +#define ISAKMP_NTYPE_INVALID_ID_INFORMATION 18 +#define ISAKMP_NTYPE_INVALID_CERT_ENCODING 19 +#define ISAKMP_NTYPE_INVALID_CERTIFICATE 20 +#define ISAKMP_NTYPE_BAD_CERT_REQUEST_SYNTAX 21 +#define ISAKMP_NTYPE_INVALID_CERT_AUTHORITY 22 +#define ISAKMP_NTYPE_INVALID_HASH_INFORMATION 23 +#define ISAKMP_NTYPE_AUTHENTICATION_FAILED 24 +#define ISAKMP_NTYPE_INVALID_SIGNATURE 25 +#define ISAKMP_NTYPE_ADDRESS_NOTIFICATION 26 +/* NOTIFY MESSAGES - STATUS TYPES */ +#define ISAKMP_NTYPE_CONNECTED 16384 +/* using only to log */ +#define ISAKMP_LOG_RETRY_LIMIT_REACHED 65530 + +/* 3.15 Delete Payload */ +struct isakmp_pl_d { + struct isakmp_gen h; + u_int32_t doi; /* Domain of Interpretation */ + u_int8_t prot_id; /* Protocol-Id */ + u_int8_t spi_size; /* SPI Size */ + u_int16_t num_spi; /* # of SPIs */ + /* SPI(es) */ +}; + + +struct isakmp_ph1tab { + struct isakmp_ph1 *head; + struct isakmp_ph1 *tail; + int len; +}; + +struct isakmp_ph2tab { + struct isakmp_ph2 *head; + struct isakmp_ph2 *tail; + 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 + +#define PFS_NEED 1 +#define PFS_NONEED 0 + +#endif /* !defined(_ISAKMP_H_) */ diff --git a/contrib/tcpdump/l2tp.h b/contrib/tcpdump/l2tp.h new file mode 100644 index 0000000..008491e --- /dev/null +++ b/contrib/tcpdump/l2tp.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * L2TP support contributed by Motonori Shindo (mshindo@ascend.co.jp) + */ + + +#define L2TP_FLAG_TYPE 0x8000 /* Type (0=Data, 1=Control) */ +#define L2TP_FLAG_LENGTH 0x4000 /* Length */ +#define L2TP_FLAG_SEQUENCE 0x0800 /* Sequence */ +#define L2TP_FLAG_OFFSET 0x0200 /* Offset */ +#define L2TP_FLAG_PRIORITY 0x0100 /* Priority */ + +#define L2TP_VERSION_MASK 0x000f /* Version Mask */ +#define L2TP_VERSION_L2F 0x0001 /* L2F */ +#define L2TP_VERSION_L2TP 0x0002 /* L2TP */ + +#define L2TP_AVP_HDR_FLAG_MANDATORY 0x8000 /* Mandatory Flag */ +#define L2TP_AVP_HDR_FLAG_HIDDEN 0x4000 /* Hidden Flag */ +#define L2TP_AVP_HDR_LEN_MASK 0x03ff /* Length Mask */ + +#define L2TP_FRAMING_CAP_SYNC_MASK 0x00000001 /* Synchronous */ +#define L2TP_FRAMING_CAP_ASYNC_MASK 0x00000002 /* Asynchronous */ + +#define L2TP_FRAMING_TYPE_SYNC_MASK 0x00000001 /* Synchronous */ +#define L2TP_FRAMING_TYPE_ASYNC_MASK 0x00000002 /* Asynchronous */ + +#define L2TP_BEARER_CAP_DIGITAL_MASK 0x00000001 /* Digital */ +#define L2TP_BEARER_CAP_ANALOG_MASK 0x00000002 /* Analog */ + +#define L2TP_BEARER_TYPE_DIGITAL_MASK 0x00000001 /* Digital */ +#define L2TP_BEARER_TYPE_ANALOG_MASK 0x00000002 /* Analog */ + +/* Authen Type */ +#define L2TP_AUTHEN_TYPE_RESERVED 0x0000 /* Reserved */ +#define L2TP_AUTHEN_TYPE_TEXTUAL 0x0001 /* Textual username/password exchange */ +#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_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/contrib/tcpdump/lane.h b/contrib/tcpdump/lane.h new file mode 100644 index 0000000..1e17103 --- /dev/null +++ b/contrib/tcpdump/lane.h @@ -0,0 +1,34 @@ +/* + * 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.2 1999/11/21 16:35:11 assar Exp $ */ + +#ifndef ETHER_ADDR_LEN +#define ETHER_ADDR_LEN 6 +#endif + +struct lecdatahdr_8023 { + u_short le_header; + u_char h_dest[ETHER_ADDR_LEN]; + u_char h_source[ETHER_ADDR_LEN]; + u_short h_type; +}; diff --git a/contrib/tcpdump/lbl/gnuc.h b/contrib/tcpdump/lbl/gnuc.h index 9a3200c..1615d43 100644 --- a/contrib/tcpdump/lbl/gnuc.h +++ b/contrib/tcpdump/lbl/gnuc.h @@ -1,4 +1,4 @@ -/* @(#) $Header: gnuc.h,v 1.3 95/10/09 02:47:01 leres Exp $ (LBL) */ +/* @(#) $Header: /tcpdump/master/tcpdump/lbl/gnuc.h,v 1.3.1.1 1999/10/07 23:47:13 mcr Exp $ (LBL) */ /* Define __P() macro, if necessary */ #ifndef __P diff --git a/contrib/tcpdump/lbl/os-solaris2.h b/contrib/tcpdump/lbl/os-solaris2.h index 7c0e772..9a8b831 100644 --- a/contrib/tcpdump/lbl/os-solaris2.h +++ b/contrib/tcpdump/lbl/os-solaris2.h @@ -18,7 +18,7 @@ * 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.18.1.1 1999/10/07 23:47:13 mcr Exp $ (LBL) */ /* Prototypes missing in SunOS 5 */ diff --git a/contrib/tcpdump/lbl/os-sunos4.h b/contrib/tcpdump/lbl/os-sunos4.h index 667fdb8..2e0f25f 100644 --- a/contrib/tcpdump/lbl/os-sunos4.h +++ b/contrib/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/contrib/tcpdump/lbl/os-ultrix4.h b/contrib/tcpdump/lbl/os-ultrix4.h index 1949fa4..676b3bd 100644 --- a/contrib/tcpdump/lbl/os-ultrix4.h +++ b/contrib/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/contrib/tcpdump/llc.h b/contrib/tcpdump/llc.h index 36185a7..cd6ea20 100644 --- a/contrib/tcpdump/llc.h +++ b/contrib/tcpdump/llc.h @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: llc.h,v 1.6 97/06/13 02:06:07 leres Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/llc.h,v 1.6.1.1 1999/10/07 23:47:10 mcr Exp $ (LBL) */ /* diff --git a/contrib/tcpdump/machdep.c b/contrib/tcpdump/machdep.c index 7dd443a..1ed3fd4 100644 --- a/contrib/tcpdump/machdep.c +++ b/contrib/tcpdump/machdep.c @@ -21,7 +21,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: machdep.c,v 1.4 97/09/30 15:03:53 leres Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/machdep.c,v 1.5 1999/11/21 09:36:47 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/types.h> diff --git a/contrib/tcpdump/machdep.h b/contrib/tcpdump/machdep.h index 87946b6..4cac15b 100644 --- a/contrib/tcpdump/machdep.h +++ b/contrib/tcpdump/machdep.h @@ -18,7 +18,7 @@ * 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.1.1.1 1999/10/07 23:47:10 mcr Exp $ (LBL) */ #ifndef tcpdump_machdep_h #define tcpdump_machdep_h diff --git a/contrib/tcpdump/makemib b/contrib/tcpdump/makemib index 3ab2d7d..8516263 100755 --- a/contrib/tcpdump/makemib +++ b/contrib/tcpdump/makemib @@ -2,6 +2,7 @@ # # Copyright (c) 1990, 1996, by John Robert LoVerso. # All rights reserved. +# SMIv2 parsing copyright (c) 1999 by William C. Fenner. # # Redistribution and use in source and binary forms are permitted # provided that the above copyright notice and this paragraph are @@ -13,8 +14,7 @@ # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. # -# @(#) $Id: makemib,v 2.1 90/07/10 23:51:54 loverso Exp Locker: loverso $ (jlv -) +# @(#) $Id: makemib,v 1.2 1999/11/21 17:24:15 fenner Exp $ (jlv) # # This script will read either ASN.1-style MIB files or the ".defs" files @@ -42,15 +42,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 +53,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 +69,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 +} +$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" } -$2 == "OBJECT-TYPE" { +# +# "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 +156,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 +169,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 +232,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/contrib/tcpdump/mib.h b/contrib/tcpdump/mib.h index 48ead9b..92c6c2c 100644 --- a/contrib/tcpdump/mib.h +++ b/contrib/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/contrib/tcpdump/missing/addrinfo.h b/contrib/tcpdump/missing/addrinfo.h new file mode 100644 index 0000000..954b0b2 --- /dev/null +++ b/contrib/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.2 1999/11/21 01:35:41 assar 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 __P((struct addrinfo *)); +extern void freehostent __P((struct hostent *)); +extern char *gai_strerror __P((int)); +extern int getaddrinfo __P((const char *, const char *, + const struct addrinfo *, struct addrinfo **)); +extern int getnameinfo __P((const struct sockaddr *, size_t, char *, + size_t, char *, size_t, int)); +extern struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *)); +extern struct hostent *getipnodebyname __P((const char *, int, int, int *)); +extern int inet_pton __P((int, const char *, void *)); +extern const char *inet_ntop __P((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/contrib/tcpdump/missing/addrsize.h b/contrib/tcpdump/missing/addrsize.h new file mode 100644 index 0000000..2880956 --- /dev/null +++ b/contrib/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/contrib/tcpdump/missing/bittypes.h b/contrib/tcpdump/missing/bittypes.h new file mode 100644 index 0000000..500f39f --- /dev/null +++ b/contrib/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/contrib/tcpdump/missing/cdecl_ext.h b/contrib/tcpdump/missing/cdecl_ext.h new file mode 100644 index 0000000..9591db2 --- /dev/null +++ b/contrib/tcpdump/missing/cdecl_ext.h @@ -0,0 +1,37 @@ +/* + * 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_PORTABLE_PROTOTYPE + +#if defined(__STDC__) || defined(__cplusplus) +#define __P(protos) protos /* full-blown ANSI C */ +#else +#define __P(protos) () /* traditional C preprocessor */ +#endif + +#endif /* !HAVE_PORTABLE_PROTOTYPE */ diff --git a/contrib/tcpdump/missing/getaddrinfo.c b/contrib/tcpdump/missing/getaddrinfo.c new file mode 100644 index 0000000..87fd652 --- /dev/null +++ b/contrib/tcpdump/missing/getaddrinfo.c @@ -0,0 +1,1119 @@ +/* + * 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 <config.h> +#endif + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/missing/getaddrinfo.c,v 1.6.2.2 2000/01/25 18:39:03 itojun Exp $"; +#endif + +#include <sys/types.h> +#include <sys/param.h> +#if 0 +#include <sys/sysctl.h> +#endif +#include <sys/socket.h> +#include <net/if.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <arpa/nameser.h> +#include <netdb.h> +#include <resolv.h> +#include <string.h> +#include <stdlib.h> +#include <stddef.h> +#include <ctype.h> +#include <unistd.h> +#include <stdio.h> +#include <errno.h> + +#ifndef HAVE_PORTABLE_PROTOTYPE +#include "cdecl_ext.h" +#endif + +#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 __P((const char *)); +static int explore_fqdn __P((const struct addrinfo *, const char *, + const char *, struct addrinfo **)); +static int explore_null __P((const struct addrinfo *, const char *, + const char *, struct addrinfo **)); +static int explore_numeric __P((const struct addrinfo *, const char *, + const char *, struct addrinfo **)); +static int explore_numeric_scope __P((const struct addrinfo *, const char *, + const char *, struct addrinfo **)); +static int get_name __P((const char *, const struct afd *, struct addrinfo **, + char *, const struct addrinfo *, const char *)); +static int get_canonname __P((const struct addrinfo *, + struct addrinfo *, const char *)); +static struct addrinfo *get_ai __P((const struct addrinfo *, + const struct afd *, const char *)); +static int get_portmatch __P((const struct addrinfo *, const char *)); +static int get_port __P((struct addrinfo *, const char *, int)); +static const struct afd *find_afd __P((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 <scoped_address><delimiter><scope id> + */ + 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/contrib/tcpdump/missing/getnameinfo.c b/contrib/tcpdump/missing/getnameinfo.c new file mode 100644 index 0000000..2d23425 --- /dev/null +++ b/contrib/tcpdump/missing/getnameinfo.c @@ -0,0 +1,285 @@ +/* + * 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 <config.h> +#endif + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/missing/getnameinfo.c,v 1.3.2.2 2000/01/25 18:39:03 itojun Exp $"; +#endif + +#include <sys/types.h> +#include <sys/socket.h> +#include <net/if.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <arpa/nameser.h> +#include <netdb.h> +#include <resolv.h> +#include <string.h> +#include <stddef.h> +#include <errno.h> + +#ifndef HAVE_PORTABLE_PROTOTYPE +#include "cdecl_ext.h" +#endif + +#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) > servlen) + return ENI_MEMORY; + strcpy(serv, sp->s_name); + } else { + sprintf(numserv, "%d", ntohs(port)); + if (strlen(numserv) > 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) > 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) > 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) > hostlen) + return ENI_MEMORY; + strcpy(host, numaddr); + } + } + return SUCCESS; +} diff --git a/contrib/tcpdump/missing/inet_aton.c b/contrib/tcpdump/missing/inet_aton.c new file mode 100644 index 0000000..355b6a1 --- /dev/null +++ b/contrib/tcpdump/missing/inet_aton.c @@ -0,0 +1,63 @@ +/* + * 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.1.2.1 2000/01/11 06:58:29 fenner Exp $ */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/missing/inet_aton.c,v 1.1.2.1 2000/01/11 06:58:29 fenner Exp $"; +#endif + +#include <sys/types.h> +#include <netinet/in.h> +#include <netdb.h> +#include <arpa/inet.h> + +/* 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/contrib/tcpdump/missing/inet_ntop.c b/contrib/tcpdump/missing/inet_ntop.c new file mode 100644 index 0000000..09506fd --- /dev/null +++ b/contrib/tcpdump/missing/inet_ntop.c @@ -0,0 +1,105 @@ +/* + * 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.2.2.1 2000/01/11 06:58:30 fenner Exp $ */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/missing/inet_ntop.c,v 1.2.2.1 2000/01/11 06:58:30 fenner Exp $"; +#endif + +#include <stdio.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> + +/* + * + */ + +#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/contrib/tcpdump/missing/inet_pton.c b/contrib/tcpdump/missing/inet_pton.c new file mode 100644 index 0000000..1138627 --- /dev/null +++ b/contrib/tcpdump/missing/inet_pton.c @@ -0,0 +1,59 @@ +/* + * 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.1.2.1 2000/01/11 06:58:30 fenner Exp $ */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/missing/inet_pton.c,v 1.1.2.1 2000/01/11 06:58:30 fenner Exp $"; +#endif + +#include <errno.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> + +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/contrib/tcpdump/missing/resolv6.h b/contrib/tcpdump/missing/resolv6.h new file mode 100644 index 0000000..b1d45c0 --- /dev/null +++ b/contrib/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/contrib/tcpdump/missing/resolv_ext.h b/contrib/tcpdump/missing/resolv_ext.h new file mode 100644 index 0000000..c33ed7e --- /dev/null +++ b/contrib/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/contrib/tcpdump/missing/sockstorage.h b/contrib/tcpdump/missing/sockstorage.h new file mode 100644 index 0000000..557eb4d --- /dev/null +++ b/contrib/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/contrib/tcpdump/netbios.h b/contrib/tcpdump/netbios.h index ebc80e1..b2a1d71 100644 --- a/contrib/tcpdump/netbios.h +++ b/contrib/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.1.1.1 1999/10/07 23:47:10 mcr Exp $ */ struct p8022Hdr { diff --git a/contrib/tcpdump/ntp.h b/contrib/tcpdump/ntp.h index 32eae64..e92408f2 100644 --- a/contrib/tcpdump/ntp.h +++ b/contrib/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.3.1.1 1999/10/07 23:47:11 mcr Exp $ */ /* * Based on ntp.h from the U of MD implementation diff --git a/contrib/tcpdump/oakley.h b/contrib/tcpdump/oakley.h new file mode 100644 index 0000000..b2d0639 --- /dev/null +++ b/contrib/tcpdump/oakley.h @@ -0,0 +1,126 @@ +/* + * 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. + */ +/* YIPS @(#)$Id: oakley.h,v 1.1 1999/10/30 05:11:10 itojun Exp $ */ + +/* refer to RFC 2409 */ + +#if !defined(_ISAKMP_OAKLEY_H_) +#define _ISAKMP_OAKLEY_H_ + +/* Attribute Classes */ +#define OAKLEY_ATTR_ENC_ALG 1 /* B */ +#define OAKLEY_ATTR_ENC_ALG_DES 1 +#define OAKLEY_ATTR_ENC_ALG_IDEA 2 +#define OAKLEY_ATTR_ENC_ALG_BL 3 +#define OAKLEY_ATTR_ENC_ALG_RC5 4 +#define OAKLEY_ATTR_ENC_ALG_3DES 5 +#define OAKLEY_ATTR_ENC_ALG_CAST 6 +#define OAKLEY_ATTR_HASH_ALG 2 /* B */ +#define OAKLEY_ATTR_HASH_ALG_MD5 1 +#define OAKLEY_ATTR_HASH_ALG_SHA 2 +#define OAKLEY_ATTR_HASH_ALG_TIGER 3 +#define OAKLEY_ATTR_AUTH_METHOD 3 /* B */ +#define OAKLEY_ATTR_AUTH_METHOD_PSKEY 1 +#define OAKLEY_ATTR_AUTH_METHOD_DSS 2 +#define OAKLEY_ATTR_AUTH_METHOD_RSA 3 +#define OAKLEY_ATTR_AUTH_METHOD_RSAENC 4 +#define OAKLEY_ATTR_AUTH_METHOD_RSAREV 5 +#define OAKLEY_ATTR_GRP_DESC 4 /* B */ +#define OAKLEY_ATTR_GRP_DESC_MODP768 1 +#define OAKLEY_ATTR_GRP_DESC_MODP1024 2 +#define OAKLEY_ATTR_GRP_DESC_EC2N155 3 +#define OAKLEY_ATTR_GRP_DESC_EC2N185 4 +#define OAKLEY_ATTR_GRP_TYPE 5 /* B */ +#define OAKLEY_ATTR_GRP_TYPE_MODP 1 +#define OAKLEY_ATTR_GRP_TYPE_ECP 2 +#define OAKLEY_ATTR_GRP_TYPE_EC2N 3 +#define OAKLEY_ATTR_GRP_PI 6 /* V */ +#define OAKLEY_ATTR_GRP_GEN_ONE 7 /* V */ +#define OAKLEY_ATTR_GRP_GEN_TWO 8 /* V */ +#define OAKLEY_ATTR_GRP_CURVE_A 9 /* V */ +#define OAKLEY_ATTR_GRP_CURVE_B 10 /* V */ +#define OAKLEY_ATTR_SA_LTYPE 11 /* B */ +#define OAKLEY_ATTR_SA_LTYPE_DEFAULT 1 +#define OAKLEY_ATTR_SA_LTYPE_SEC 1 +#define OAKLEY_ATTR_SA_LTYPE_KB 2 +#define OAKLEY_ATTR_SA_LDUR 12 /* V */ +#define OAKLEY_ATTR_SA_LDUR_DEFAULT 28800 /* 8 hours */ +#define OAKLEY_ATTR_PRF 13 /* B */ +#define OAKLEY_ATTR_KEY_LEN 14 /* B */ +#define OAKLEY_ATTR_FIELD_SIZE 15 /* B */ +#define OAKLEY_ATTR_GRP_ORDER 16 /* V */ + +#define OAKLEY_ID_IPV4_ADDR 0 +#define OAKLEY_ID_IPV4_ADDR_SUBNET 1 +#define OAKLEY_ID_IPV6_ADDR 2 +#define OAKLEY_ID_IPV6_ADDR_SUBNET 3 + +/* Additional Exchange Type */ +#define ISAKMP_ETYPE_QUICK 32 +#define ISAKMP_ETYPE_NEWGRP 33 + +/* The use for checking proposal payload. This is not exchange type. */ +#define OAKLEY_MAIN_MODE 0 +#define OAKLEY_QUICK_MODE 1 + +#define OAKLEY_PRIME_MODP768 "\ + FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1 \ + 29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD \ + EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245 \ + E485B576 625E7EC6 F44C42E9 A63A3620 FFFFFFFF FFFFFFFF" + +#define OAKLEY_PRIME_MODP1024 "\ + FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1 \ + 29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD \ + EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245 \ + E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED \ + EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE65381 \ + FFFFFFFF FFFFFFFF" + +#define DEFAULTSECRETSIZE ( 128 / 8 ) /* 128 bits */ +#define DEFAULTNONCESIZE ( 128 / 8 ) /* 128 bits */ + +#define MAXPADLWORD 20 + +#if 0 +/* isakmp sa structure */ +struct oakley_sa { + u_int8_t proto_id; /* OAKLEY */ + vchar_t *spi; /* spi */ + u_int8_t dhgrp; /* DH; group */ + u_int8_t auth_t; /* method of authentication */ + u_int8_t prf_t; /* type of prf */ + u_int8_t hash_t; /* type of hash */ + u_int8_t enc_t; /* type of cipher */ + u_int8_t life_t; /* type of duration of lifetime */ + u_int32_t ldur; /* life duration */ +}; +#endif + +#endif /* !defined(_ISAKMP_OAKLEY_H_) */ diff --git a/contrib/tcpdump/ospf6.h b/contrib/tcpdump/ospf6.h new file mode 100644 index 0000000..85e81d7 --- /dev/null +++ b/contrib/tcpdump/ospf6.h @@ -0,0 +1,280 @@ +/* + * Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * 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 OSPF6_OPTION_V6 0x01 /* V6 bit: A bit for peeping tom */ +#define OSPF6_OPTION_E 0x02 /* E bit: External routes advertised */ +#define OSPF6_OPTION_MC 0x04 /* MC bit: Multicast capable */ +#define OSPF6_OPTION_N 0x08 /* N bit: For type-7 LSA */ +#define OSPF6_OPTION_R 0x10 /* R bit: Router bit */ +#define OSPF6_OPTION_DC 0x20 /* DC bit: Demand circuits */ + + +/* db_flags */ +#define OSPF6_DB_INIT 0x04 /* */ +#define OSPF6_DB_MORE 0x02 +#define OSPF6_DB_MASTER 0x01 + +/* ls_type */ +#define LS_TYPE_ROUTER 1 /* router link */ +#define LS_TYPE_NETWORK 2 /* network link */ +#define LS_TYPE_INTER_AP 3 /* Inter-Area-Prefix */ +#define LS_TYPE_INTER_AR 4 /* Inter-Area-Router */ +#define LS_TYPE_ASE 5 /* ASE */ +#define LS_TYPE_GROUP 6 /* Group membership */ +#define LS_TYPE_TYPE7 7 /* Type 7 LSA */ +#define LS_TYPE_LINK 8 /* Link LSA */ +#define LS_TYPE_INTRA_AP 9 /* Intra-Area-Prefix */ +#define LS_TYPE_MAX 10 +#define LS_TYPE_MASK 0x1fff + +#define LS_SCOPE_LINKLOCAL 0x0000 +#define LS_SCOPE_AREA 0x2000 +#define LS_SCOPE_AS 0x4000 +#define LS_SCOPE_MASK 0x6000 + +/************************************************* + * + * is the above a bug in the documentation? + * + *************************************************/ + + +/* rla_link.link_type */ +#define RLA_TYPE_ROUTER 1 /* point-to-point to another router */ +#define RLA_TYPE_TRANSIT 2 /* connection to transit network */ +#define RLA_TYPE_VIRTUAL 4 /* virtual link */ + +/* rla_flags */ +#define RLA_FLAG_B 0x01 +#define RLA_FLAG_E 0x02 +#define RLA_FLAG_V 0x04 +#define RLA_FLAG_W 0x08 + +/* sla_tosmetric breakdown */ +#define SLA_MASK_TOS 0x7f000000 +#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 +#define ASLA_MASK_METRIC 0x00ffffff + +/* multicast vertex type */ +#define MCLA_VERTEX_ROUTER 1 +#define MCLA_VERTEX_NETWORK 2 + +typedef u_int32_t rtrid_t; + +/* link state advertisement header */ +struct lsa_hdr { + u_int16_t ls_age; + u_int16_t ls_type; + rtrid_t ls_stateid; + rtrid_t ls_router; + u_int32_t ls_seq; + u_int16_t ls_chksum; + u_int16_t ls_length; +} ; + +struct lsa_prefix { + u_int8_t lsa_p_len; + u_int8_t lsa_p_opt; + u_int16_t lsa_p_mbz; + u_int8_t lsa_p_prefix[4]; +}; + +/* link state advertisement */ +struct lsa { + struct lsa_hdr ls_hdr; + + /* Link state types */ + union { + /* Router links advertisements */ + struct { + union { + u_int8_t flg; + u_int32_t opt; + } rla_flgandopt; +#define rla_flags rla_flgandopt.flg +#define rla_options rla_flgandopt.opt + struct rlalink { + u_int8_t link_type; + u_int8_t link_zero[1]; + u_int16_t link_metric; + u_int32_t link_ifid; + u_int32_t link_nifid; + rtrid_t link_nrtid; + } rla_link[1]; /* may repeat */ + } un_rla; + + /* Network links advertisements */ + struct { + u_int32_t nla_options; + rtrid_t nla_router[1]; /* may repeat */ + } un_nla; + + /* Inter Area Prefix LSA */ + struct { + u_int32_t inter_ap_metric; + struct lsa_prefix inter_ap_prefix[1]; + } un_inter_ap; + +#if 0 + /* Summary links advertisements */ + struct { + struct in_addr sla_mask; + 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; + struct in_addr mcla_vid; + } un_mcla[1]; +#endif + + /* Type 7 LSA */ + + /* Link LSA */ + struct llsa { + union { + u_int8_t pri; + u_int32_t opt; + } llsa_priandopt; +#define llsa_priority llsa_priandopt.pri +#define llsa_options llsa_priandopt.opt + struct in6_addr llsa_lladdr; + u_int32_t llsa_nprefix; + struct lsa_prefix llsa_prefix[1]; + } un_llsa; + + /* Intra-Area-Prefix */ + struct { + u_int16_t intra_ap_nprefix; + u_int16_t intra_ap_lstype; + rtrid_t intra_ap_lsid; + rtrid_t intra_ap_rtid; + struct lsa_prefix intra_ap_prefix[1]; + } un_intra_ap; + } lsa_un; +} ; + + +/* + * TOS metric struct (will be 0 or more in router links update) + */ +struct tos_metric { + u_int8_t tos_type; + u_int8_t tos_zero; + u_int16_t tos_metric; +} ; + +#define OSPF_AUTH_SIZE 8 + +/* + * the main header + */ +struct ospf6hdr { + u_int8_t ospf6_version; + u_int8_t ospf6_type; + u_int16_t ospf6_len; + rtrid_t ospf6_routerid; + rtrid_t ospf6_areaid; + u_int16_t ospf6_chksum; + u_int8_t ospf6_instanceid; + u_int8_t ospf6_rsvd; + union { + + /* Hello packet */ + struct { + u_int32_t hello_ifid; + union { + u_int8_t pri; + u_int32_t opt; + } hello_priandopt; +#define hello_priority hello_priandopt.pri +#define hello_options hello_priandopt.opt + u_int16_t hello_helloint; + u_int16_t hello_deadint; + rtrid_t hello_dr; + rtrid_t hello_bdr; + rtrid_t hello_neighbor[1]; /* may repeat */ + } un_hello; + + /* Database Description packet */ + struct { + u_int32_t db_options; + u_int16_t db_mtu; + u_int8_t db_mbz; + 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_int16_t ls_mbz; + u_int16_t ls_type; + rtrid_t ls_stateid; + rtrid_t ls_router; + } un_lsr[1]; /* may repeat */ + + /* Link State Update */ + struct { + u_int32_t lsu_count; + struct lsa lsu_lsa[1]; /* may repeat */ + } un_lsu; + + /* Link State Acknowledgement */ + struct { + 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 +#define ospf6_lsr ospf6_un.un_lsr +#define ospf6_lsu ospf6_un.un_lsu +#define ospf6_lsa ospf6_un.un_lsa + diff --git a/contrib/tcpdump/print-ah.c b/contrib/tcpdump/print-ah.c new file mode 100644 index 0000000..9a36ff4 --- /dev/null +++ b/contrib/tcpdump/print-ah.c @@ -0,0 +1,103 @@ +/* $NetBSD: print-ah.c,v 1.4 1996/05/20 00:41:16 fvdl Exp $ */ + +/* + * 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 + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-ah.c,v 1.5 1999/12/15 08:10:17 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <net/route.h> +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/if_ether.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_icmp.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> +#include <netinet/tcp.h> + +#include <stdio.h> + +/* there's no standard definition so we are on our own */ +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 */ +}; + +#include "interface.h" +#include "addrtoname.h" + +int +ah_print(register const u_char *bp, register const u_char *bp2) +{ + 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. */ + + if ((u_char *)(ah + 1) >= ep - sizeof(struct ah)) + goto trunc; + + sumlen = ah->ah_len << 2; + spi = (u_int32_t)ntohl(ah->ah_spi); + + printf("AH(spi=%u", spi); + if (vflag) + printf(",sumlen=%d", sumlen); + printf(",seq=0x%x", (u_int32_t)ntohl(*(u_int32_t *)(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; +} diff --git a/contrib/tcpdump/print-ascii.c b/contrib/tcpdump/print-ascii.c new file mode 100644 index 0000000..29f57b8 --- /dev/null +++ b/contrib/tcpdump/print-ascii.c @@ -0,0 +1,158 @@ +/* $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[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-ascii.c,v 1.2.2.2 2000/01/11 06:58:23 fenner Exp $"; +#endif +#include <stdio.h> +#include <sys/types.h> +#include <ctype.h> + +#include "interface.h" + +#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 *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[HEXDUMP_BYTES_PER_LINE+1], *asp; + + nshorts = length / sizeof(u_short); + i = 0; + hsp = hexstuff; asp = asciistuff; + while (--nshorts >= 0) { + s1 = *cp++; + s2 = *cp++; + (void)sprintf(hsp, " %02x%02x", s1, s2); + hsp += HEXDUMP_HEXSTUFF_PER_SHORT; + *(asp++) = (isgraph(s1) ? s1 : '.'); + *(asp++) = (isgraph(s2) ? s2 : '.'); + if (++i >= HEXDUMP_SHORTS_PER_LINE) { + *hsp = *asp = '\0'; + (void)printf("\n0x%04x\t%-*s\t%s", + oset, HEXDUMP_HEXSTUFF_PER_LINE, + hexstuff, asciistuff); + i = 0; hsp = hexstuff; asp = asciistuff; + oset += HEXDUMP_BYTES_PER_LINE; + } + } + if (length & 1) { + s1 = *cp++; + (void)sprintf(hsp, " %02x", s1); + hsp += 3; + *(asp++) = (isgraph(s1) ? s1 : '.'); + ++i; + } + if (i > 0) { + *hsp = *asp = '\0'; + (void)printf("\n0x%04x\t%-*s\t%s", + oset, HEXDUMP_HEXSTUFF_PER_LINE, + hexstuff, asciistuff); + } +} + +void +ascii_print(register const u_char *cp, register u_int length) +{ + ascii_print_with_offset(cp, length, 0); +} + +/* + * telnet_print() wants this. It is essentially default_print_unaligned() + */ +void +hex_print_with_offset(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("\n0x%04x\t", oset); + oset += HEXDUMP_BYTES_PER_LINE; + } + s = *cp++; + (void)printf(" %02x%02x", s, *cp++); + } + if (length & 1) { + if ((i % 8) == 0) + (void)printf("\n0x%04x\t", oset); + (void)printf(" %02x", *cp); + } +} + +/* + * just for completeness + */ +void +hex_print(register const u_char *cp, register u_int length) +{ + hex_print_with_offset(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/contrib/tcpdump/print-bgp.c b/contrib/tcpdump/print-bgp.c new file mode 100644 index 0000000..23c3faf --- /dev/null +++ b/contrib/tcpdump/print-bgp.c @@ -0,0 +1,727 @@ +/* + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.9.2.2 2000/01/25 18:32:53 itojun Exp $"; +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> + +#include <errno.h> +#include <stdio.h> +#include <string.h> + +#include "interface.h" +#include "addrtoname.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 + +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 */ +}; + +struct bgp_opt { + u_int8_t bgpopt_type; + u_int8_t bgpopt_len; + /* variable length */ +}; + +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; + /* data should follow */ +}; + +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) ? \ + ntohs((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 /* work in progress */ +#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 */ + + +static const char *bgptype[] = { + NULL, "OPEN", "UPDATE", "NOTIFICATION", "KEEPALIVE", +}; +#define bgp_type(x) num_or_str(bgptype, sizeof(bgptype)/sizeof(bgptype[0]), (x)) + +static const char *bgpopt_type[] = { + NULL, "Authentication Information", +}; +#define bgp_opttype(x) \ + num_or_str(bgpopt_type, sizeof(bgpopt_type)/sizeof(bgpopt_type[0]), (x)) + +static const char *bgpnotify_major[] = { + NULL, "Message Header Error", + "OPEN Message Error", "UPDATE Message Error", + "Hold Timer Expired", "Finite State Machine Error", + "Cease", +}; +#define bgp_notify_major(x) \ + num_or_str(bgpnotify_major, \ + sizeof(bgpnotify_major)/sizeof(bgpnotify_major[0]), (x)) + +static const char *bgpnotify_minor_1[] = { + NULL, "Connection Not Synchronized", + "Bad Message Length", "Bad Message Type", +}; + +static const char *bgpnotify_minor_2[] = { + NULL, "Unsupported Version Number", + "Bad Peer AS", "Bad BGP Identifier", + "Unsupported Optional Parameter", "Authentication Failure", + "Unacceptable Hold Time", +}; + +static const char *bgpnotify_minor_3[] = { + NULL, "Malformed Attribute List", + "Unrecognized Well-known Attribute", "Missing Well-known Attribute", + "Attribute Flags Error", "Attribute Length Error", + "Invalid ORIGIN Attribute", "AS Routing Loop", + "Invalid NEXT_HOP Attribute", "Optional Attribute Error", + "Invalid Network Field", "Malformed AS_PATH", +}; + +static const char **bgpnotify_minor[] = { + NULL, bgpnotify_minor_1, bgpnotify_minor_2, bgpnotify_minor_3, +}; +static const int bgpnotify_minor_siz[] = { + 0, sizeof(bgpnotify_minor_1)/sizeof(bgpnotify_minor_1[0]), + sizeof(bgpnotify_minor_2)/sizeof(bgpnotify_minor_2[0]), + sizeof(bgpnotify_minor_3)/sizeof(bgpnotify_minor_3[0]), +}; + +static const char *bgpattr_origin[] = { + "IGP", "EGP", "INCOMPLETE", +}; +#define bgp_attr_origin(x) \ + num_or_str(bgpattr_origin, \ + sizeof(bgpattr_origin)/sizeof(bgpattr_origin[0]), (x)) + +static const char *bgpattr_type[] = { + NULL, "ORIGIN", "AS_PATH", "NEXT_HOP", + "MULTI_EXIT_DISC", "LOCAL_PREF", "ATOMIC_AGGREGATE", "AGGREGATOR", + "COMMUNITIES", "ORIGINATOR_ID", "CLUSTER_LIST", "DPA", + "ADVERTISERS", "RCID_PATH", "MP_REACH_NLRI", "MP_UNREACH_NLRI", +}; +#define bgp_attr_type(x) \ + num_or_str(bgpattr_type, \ + sizeof(bgpattr_type)/sizeof(bgpattr_type[0]), (x)) + +/* Subsequent address family identifier, RFC2283 section 7 */ +static const char *bgpattr_nlri_safi[] = { + "Reserved", "Unicast", "Multicast", "Unicast+Multicast", +}; +#define bgp_attr_nlri_safi(x) \ + num_or_str(bgpattr_nlri_safi, \ + sizeof(bgpattr_nlri_safi)/sizeof(bgpattr_nlri_safi[0]), (x)) + +/* 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 + +static const char *afnumber[] = { + "Reserved", "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", +}; +#define af_name(x) \ + (((x) == 65535) ? afnumber[0] : \ + num_or_str(afnumber, \ + sizeof(afnumber)/sizeof(afnumber[0]), (x))) + + +static const char * +num_or_str(const char **table, size_t siz, int value) +{ + static char buf[20]; + if (value < 0 || siz <= value || table[value] == NULL) { + sprintf(buf, "#%d", value); + return buf; + } else + return table[value]; +} + +static const char * +bgp_notify_minor(int major, int minor) +{ + static const char **table; + int siz; + static char buf[20]; + const char *p; + + if (0 <= major + && major < sizeof(bgpnotify_minor)/sizeof(bgpnotify_minor[0]) + && bgpnotify_minor[major]) { + table = bgpnotify_minor[major]; + siz = bgpnotify_minor_siz[major]; + if (0 <= minor && minor < siz && table[minor]) + p = table[minor]; + else + p = NULL; + } else + p = NULL; + if (p == NULL) { + sprintf(buf, "#%d", minor); + return buf; + } else + return p; +} + +static int +decode_prefix4(const u_char *pd, char *buf, int buflen) +{ + struct in_addr addr; + int plen; + + plen = pd[0]; + if (plen < 0 || 32 < plen) + return -1; + + memset(&addr, 0, sizeof(addr)); + memcpy(&addr, &pd[1], (plen + 7) / 8); + if (plen % 8) { + ((u_char *)&addr)[(plen + 7) / 8 - 1] &= + ((0xff00 >> (plen % 8)) & 0xff); + } + sprintf(buf, "%s/%d", getname((char *)&addr), plen); + return 1 + (plen + 7) / 8; +} + +#ifdef INET6 +static int +decode_prefix6(const u_char *pd, char *buf, int buflen) +{ + struct in6_addr addr; + int plen; + + plen = pd[0]; + if (plen < 0 || 128 < plen) + return -1; + + memset(&addr, 0, sizeof(addr)); + memcpy(&addr, &pd[1], (plen + 7) / 8); + if (plen % 8) { + addr.s6_addr[(plen + 7) / 8 - 1] &= + ((0xff00 >> (plen % 8)) & 0xff); + } + sprintf(buf, "%s/%d", getname6((char *)&addr), plen); + return 1 + (plen + 7) / 8; +} +#endif + +static void +bgp_attr_print(const struct bgp_attr *attr, const u_char *dat, int len) +{ + int i; + u_int16_t af; + u_int8_t safi, snpa; + int advance; + int tlen; + const u_char *p; + char buf[256]; + + p = dat; + + switch (attr->bgpa_type) { + case BGPTYPE_ORIGIN: + if (len != 1) + printf(" invalid len"); + else + printf(" %s", bgp_attr_origin(p[0])); + break; + case BGPTYPE_AS_PATH: + if (len % 2) { + printf(" invalid len"); + break; + } + while (p < dat + len) { + /* + * under RFC1965, p[0] means: + * 1: AS_SET 2: AS_SEQUENCE + * 3: AS_CONFED_SET 4: AS_CONFED_SEQUENCE + */ + printf(" "); + if (p[0] == 3 || p[0] == 4) + printf("confed"); + printf("%s", (p[0] & 1) ? "{" : ""); + for (i = 0; i < p[1]; i += 2) { + printf("%s%u", i == 0 ? "" : " ", + ntohs(*(u_int16_t *)&p[2 + i])); + } + printf("%s", (p[0] & 1) ? "}" : ""); + p += 2 + p[1] * 2; + } + break; + case BGPTYPE_NEXT_HOP: + if (len != 4) + printf(" invalid len"); + else + printf(" %s", getname(p)); + break; + case BGPTYPE_MULTI_EXIT_DISC: + case BGPTYPE_LOCAL_PREF: + if (len != 4) + printf(" invalid len"); + else + printf(" %u", (u_int32_t)ntohl(*(u_int32_t *)p)); + break; + case BGPTYPE_ATOMIC_AGGREGATE: + if (len != 0) + printf(" invalid len"); + break; + case BGPTYPE_AGGREGATOR: + if (len != 6) { + printf(" invalid len"); + break; + } + printf(" AS #%u, origin %s", ntohs(*(u_int16_t *)p), + getname(p + 2)); + break; + case BGPTYPE_COMMUNITIES: + if (len % 4) { + printf(" invalid len"); + break; + } + for (i = 0; i < len; i += 4) { + u_int32_t comm; + comm = (u_int32_t)ntohl(*(u_int32_t *)&p[i]); + 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(" (AS #%d value 0x%04x)", + (comm >> 16) & 0xffff, comm & 0xffff); + break; + } + } + break; + case BGPTYPE_MP_REACH_NLRI: + af = ntohs(*(u_int16_t *)p); + safi = p[2]; + if (safi >= 128) + printf(" %s vendor specific,", af_name(af)); + else { + printf(" %s %s,", af_name(af), + bgp_attr_nlri_safi(safi)); + } + p += 3; + + if (af == AFNUM_INET) + ; +#ifdef INET6 + else if (af == AFNUM_INET6) + ; +#endif + else + break; + + tlen = p[0]; + if (tlen) { + printf(" nexthop"); + if (af == AFNUM_INET) + advance = 4; +#ifdef INET6 + else if (af == AFNUM_INET6) + advance = 16; +#endif + + for (i = 0; i < tlen; i += advance) { + if (af == AFNUM_INET) + printf(" %s", getname(p + 1 + i)); +#ifdef INET6 + else if (af == AFNUM_INET6) + printf(" %s", getname6(p + 1 + i)); +#endif + } + printf(","); + } + p += 1 + tlen; + + snpa = p[0]; + p++; + if (snpa) { + printf(" %u snpa", snpa); + for (/*nothing*/; snpa > 0; snpa--) { + printf("(%d bytes)", p[0]); + p += p[0] + 1; + } + printf(","); + } + + printf(" NLRI"); + while (len - (p - dat) > 0) { + if (af == AFNUM_INET) + advance = decode_prefix4(p, buf, sizeof(buf)); +#ifdef INET6 + else if (af == AFNUM_INET6) + advance = decode_prefix6(p, buf, sizeof(buf)); +#endif + printf(" %s", buf); + + p += advance; + } + + break; + + case BGPTYPE_MP_UNREACH_NLRI: + af = ntohs(*(u_int16_t *)p); + safi = p[2]; + if (safi >= 128) + printf(" %s vendor specific,", af_name(af)); + else { + printf(" %s %s,", af_name(af), + bgp_attr_nlri_safi(safi)); + } + p += 3; + + printf(" Withdraw"); + while (len - (p - dat) > 0) { + if (af == AFNUM_INET) + advance = decode_prefix4(p, buf, sizeof(buf)); +#ifdef INET6 + else if (af == AFNUM_INET6) + advance = decode_prefix6(p, buf, sizeof(buf)); +#endif + printf(" %s", buf); + + p += advance; + } + break; + default: + break; + } +} + +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; + + memcpy(&bgpo, dat, sizeof(bgpo)); + hlen = ntohs(bgpo.bgpo_len); + + printf(": Version %d,", bgpo.bgpo_version); + printf(" AS #%u,", ntohs(bgpo.bgpo_myas)); + printf(" Holdtime %u,", ntohs(bgpo.bgpo_holdtime)); + printf(" ID %s,", getname((char *)&bgpo.bgpo_id)); + printf(" Option length %u", bgpo.bgpo_optlen); + + /* ugly! */ + opt = &((struct bgp_open *)dat)->bgpo_optlen; + opt++; + + for (i = 0; i < bgpo.bgpo_optlen; i++) { + memcpy(&bgpopt, &opt[i], sizeof(bgpopt)); + if (i + 2 + bgpopt.bgpopt_len > bgpo.bgpo_optlen) { + printf(" [|opt %d %d]", bgpopt.bgpopt_len, bgpopt.bgpopt_type); + break; + } + + printf(" (option %s, len=%d)", bgp_opttype(bgpopt.bgpopt_type), + bgpopt.bgpopt_len); + i += sizeof(bgpopt) + bgpopt.bgpopt_len; + } +} + +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; + int newline; + + memcpy(&bgp, dat, sizeof(bgp)); + hlen = ntohs(bgp.bgp_len); + p = dat + BGP_SIZE; /*XXX*/ + printf(":"); + + /* Unfeasible routes */ + len = ntohs(*(u_int16_t *)p); + if (len) { + printf(" (Withdrawn routes: %d bytes)", len); + } + p += 2 + len; + + len = ntohs(*(u_int16_t *)p); + if (len) { + /* do something more useful!*/ + i = 2; + printf(" (Path attributes:"); /* ) */ + newline = 0; + while (i < 2 + len) { + int alen, aoff; + + memcpy(&bgpa, &p[i], sizeof(bgpa)); + alen = bgp_attr_len(&bgpa); + aoff = bgp_attr_off(&bgpa); + + if (vflag && newline) + printf("\n\t\t"); + else + printf(" "); + printf("("); /* ) */ + printf("%s", bgp_attr_type(bgpa.bgpa_type)); + if (bgpa.bgpa_flags) { + printf("[%s%s%s%s]", + bgpa.bgpa_flags & 0x80 ? "O" : "", + bgpa.bgpa_flags & 0x40 ? "T" : "", + bgpa.bgpa_flags & 0x20 ? "P" : "", + bgpa.bgpa_flags & 0x00 ? "E" : ""); + } + + bgp_attr_print(&bgpa, &p[i + aoff], alen); + newline = 1; + + /* ( */ + printf(")"); + + i += aoff + alen; + } + + /* ( */ + printf(")"); + } + p += 2 + len; + + if (len && dat + length > p) + printf("\n\t\t"); + if (dat + length > p) { + printf("(NLRI:"); /* ) */ + while (dat + length > p) { + char buf[256]; + i = decode_prefix4(p, buf, sizeof(buf)); + printf(" %s", buf); + if (i < 0) + break; + p += i; + } + + /* ( */ + printf(")"); + } +} + +static void +bgp_notification_print(const u_char *dat, int length) +{ + struct bgp_notification bgpn; + int hlen; + + memcpy(&bgpn, dat, sizeof(bgpn)); + hlen = ntohs(bgpn.bgpn_len); + + printf(": error %s,", bgp_notify_major(bgpn.bgpn_major)); + printf(" subcode %s", + bgp_notify_minor(bgpn.bgpn_major, bgpn.bgpn_minor)); +} + +static void +bgp_header_print(const u_char *dat, int length) +{ + struct bgp bgp; + + memcpy(&bgp, dat, sizeof(bgp)); + printf("(%s", bgp_type(bgp.bgp_type)); /* ) */ + + 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; + } + + /* ( */ + printf(")"); +} + +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; + int newline; + + ep = dat + length; + if (snapend < dat + length) + ep = snapend; + + printf(": BGP"); + + p = dat; + newline = 0; + 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, sizeof(bgp)); + + if (start != p) + printf(" [|BGP]"); + + hlen = ntohs(bgp.bgp_len); + if (vflag && newline) + printf("\n\t"); + else + printf(" "); + if (TTEST2(p[0], hlen)) { + bgp_header_print(p, hlen); + newline = 1; + p += hlen; + start = p; + } else { + printf("[|BGP %s]", bgp_type(bgp.bgp_type)); + break; + } + } + + return; + +trunc: + printf(" [|BGP]"); +} diff --git a/contrib/tcpdump/print-chdlc.c b/contrib/tcpdump/print-chdlc.c new file mode 100644 index 0000000..f9c5ecf --- /dev/null +++ b/contrib/tcpdump/print-chdlc.c @@ -0,0 +1,196 @@ +/* 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. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-chdlc.c,v 1.2 1999/11/21 09:36:49 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/socket.h> +#include <sys/file.h> +#include <sys/ioctl.h> + +#if __STDC__ +struct mbuf; +struct rtentry; +#endif +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/if_ether.h> + +#include <ctype.h> +#include <netdb.h> +#include <pcap.h> +#include <stdio.h> +#ifdef __bsdi__ +#include <net/slcompress.h> +#include <net/if_ppp.h> +#endif + +#include "interface.h" +#include "addrtoname.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 + +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) +{ + 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; + } + + /* + * 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; + + if (eflag) { + switch (p[0]) { + case CHDLC_UNICAST: + printf("unicast "); + break; + case CHDLC_BCAST: + printf("bcast "); + break; + default: + printf("0x%02x ", p[0]); + break; + } + printf("%d %04x: ", length, proto); + } + + length -= CHDLC_HDRLEN; + ip = (struct ip *)(p + CHDLC_HDRLEN); + switch(proto) { + case ETHERTYPE_IP: + ip_print((const u_char *)ip, length); + break; +#ifdef INET6 + case ETHERTYPE_IPV6: + ip6_print((const u_char *)ip, length); + break; +#endif + case CHDLC_TYPE_SLARP: + chdlc_slarp_print((const u_char *)ip, length); + break; +#if 0 + case CHDLC_TYPE_CDP: + chdlc_cdp_print((const u_char *)ip, length); + break; +#endif + } + if (xflag) + default_print((const u_char *)ip, caplen - CHDLC_HDRLEN); +out: + putchar('\n'); +} + +struct cisco_slarp { + long code; +#define SLARP_REQUEST 0 +#define SLARP_REPLY 1 +#define SLARP_KEEPALIVE 2 + union { + struct { + struct in_addr addr; + struct in_addr mask; + u_short unused[3]; + } addr; + struct { + long myseq; + long yourseq; + short rel; + short t1; + short t2; + } keep; + } un; +}; + +#define SLARP_LEN 18 + +static void +chdlc_slarp_print(const u_char *cp, u_int length) +{ + struct cisco_slarp *slarp; + + if (length < SLARP_LEN) { + printf("[|slarp]"); + return; + } + + slarp = (struct cisco_slarp *)cp; + switch (ntohl(slarp->code)) { + case SLARP_REQUEST: + printf("slarp-request"); + break; + case SLARP_REPLY: + printf("slarp-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)); + break; + default: + printf("slarp-0x%x unknown", (u_int32_t)ntohl(slarp->code)); + break; + } + + if (SLARP_LEN < length && vflag) + printf("(trailing junk: %d bytes)", length - SLARP_LEN); +} diff --git a/contrib/tcpdump/print-cip.c b/contrib/tcpdump/print-cip.c new file mode 100644 index 0000000..5021bc0 --- /dev/null +++ b/contrib/tcpdump/print-cip.c @@ -0,0 +1,162 @@ +/* + * 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[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-cip.c,v 1.2 1999/11/21 09:36:49 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/if_ether.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> +#include <netinet/tcp.h> +#include <netinet/tcpip.h> + +#include <stdio.h> +#include <pcap.h> + +#include "interface.h" +#include "addrtoname.h" + +const u_char *packetp; +const u_char *snapend; + +#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(register const u_char *bp, int length) +{ + int i; + + if (memcmp(rfcllc, bp, sizeof(rfcllc))) { + if (qflag) { + for(i=0;i<RFC1483LLC_LEN;i++) + (void)printf("%2.2x ",bp[i]); + } else { + for(i=0;i<RFC1483LLC_LEN-2;i++) + (void)printf("%2.2x ",bp[i]); + etherproto_string(((u_short*)bp)[3]); + } + } else { + if (qflag) + (void)printf("(null encapsulation)"); + else { + (void)printf("(null encap)"); + etherproto_string(ETHERTYPE_IP); + } + } +} + +/* + * This is the top level routine of the printer. 'p' is the points + * to the raw 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 +cip_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) +{ + int caplen = h->caplen; + int length = h->len; + u_short ether_type; + u_short extracted_ethertype; + u_short *bp; + + ts_print(&h->ts); + + if (memcmp(rfcllc, p, sizeof(rfcllc))==0 && caplen < RFC1483LLC_LEN) { + printf("[|cip]"); + goto out; + } + + if (eflag) + cip_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; + + if (memcmp(rfcllc, p, sizeof(rfcllc))==0) { + length -= RFC1483LLC_LEN; + caplen -= RFC1483LLC_LEN; + bp = (u_short*)p; + p += RFC1483LLC_LEN; + ether_type = ntohs(bp[3]); + } else + ether_type = ETHERTYPE_IP; + + /* + * 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, NULL, NULL)==0) { + /* ether_type not known, print raw packet */ + if (!eflag) + cip_print((u_char *)bp, length); + 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) == 0) { + /* ether_type not known, print raw packet */ + if (!eflag) + cip_print((u_char *)bp, length + RFC1483LLC_LEN); + if (!xflag && !qflag) + default_print(p, caplen); + } + if (xflag) + default_print(p, caplen); + out: + putchar('\n'); +} diff --git a/contrib/tcpdump/print-decnet.c b/contrib/tcpdump/print-decnet.c index 29b85bd..c2c5c5a 100644 --- a/contrib/tcpdump/print-decnet.c +++ b/contrib/tcpdump/print-decnet.c @@ -21,7 +21,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: print-decnet.c,v 1.26 97/05/28 12:51:29 leres Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-decnet.c,v 1.27 1999/11/21 09:36:50 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/param.h> diff --git a/contrib/tcpdump/print-dhcp6.c b/contrib/tcpdump/print-dhcp6.c new file mode 100644 index 0000000..411f166 --- /dev/null +++ b/contrib/tcpdump/print-dhcp6.c @@ -0,0 +1,342 @@ +/* + * 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. + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-dhcp6.c,v 1.3 1999/12/22 06:27:20 itojun Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/socket.h> + +#if __STDC__ +struct mbuf; +struct rtentry; +#endif +#include <net/if.h> + +#include <netinet/in.h> + +#include <ctype.h> +#ifdef HAVE_MEMORY_H +#include <memory.h> +#endif +#include <stdio.h> +#include <string.h> +#include <arpa/inet.h> + +#include "interface.h" +#include "addrtoname.h" +#include "dhcp6.h" +#include "dhcp6opt.h" + +#if 0 +static void dhcp6opttab_init __P((void)); +static struct dhcp6_opt *dhcp6opttab_byname __P((char *)); +#endif +static struct dhcp6_opt *dhcp6opttab_bycode __P((u_int)); + +static char tstr[] = " [|dhcp6]"; + +static struct dhcp6_opt dh6opttab[] = { + /* IP Address Extension */ + { 1, OL6_N, "IP Address", OT6_NONE, }, + + /* General Extension */ + { 2, 4, "Time Offset", OT6_NUM, }, + { 3, OL6_N, "IEEE 1003.1 POSIX Timezone", OT6_STR, }, + { 6, OL6_16N, "Domain Name Server", OT6_V6, }, + { 10, OL6_N, "Domain Name", OT6_STR, }, + + /* Application and Service Parameters */ + { 16, OL6_N, "Directory Agent", OT6_NONE, }, + { 17, OL6_N, "Service Scope" , OT6_NONE, }, + { 18, OL6_16N, "Network Time Protocol Servers", OT6_V6, }, + { 19, OL6_N, "NIS Domain", OT6_STR, }, + { 20, OL6_16N, "NIS Servers", OT6_V6, }, + { 21, OL6_N, "NIS+ Domain", OT6_STR, }, + { 22, OL6_16N, "NIS+ Servers", OT6_V6, }, + + /* TCP Parameters */ + { 32, 4, "TCP Keepalive Interval", OT6_NUM, }, + + /* DHCPv6 Extensions */ + { 40, 4, "Maximum DHCPv6 Message Size", OT6_NUM, }, + { 41, OL6_N, "DHCP Retransmission and Configuration Parameter", + OT6_NONE, }, + { 48, OL6_N, "Platform Specific Information", OT6_NONE, }, + { 49, OL6_N, "Platform Class Identifier", OT6_STR, }, + { 64, OL6_N, "Class Identifier", OT6_STR, }, + { 66, 16, "Reconfigure Multicast Address", OT6_V6, }, + { 67, 16, "Renumber DHCPv6 Server Address", + OT6_V6, }, + { 68, OL6_N, "DHCP Relay ICMP Error Message", OT6_NONE, }, + { 84, OL6_N, "Client-Server Authentication", OT6_NONE, }, + { 85, 4, "Client Key Selection", OT6_NUM, }, + + /* End Extension */ + { 65536, OL6_Z, "End", OT6_NONE, }, + + { 0 }, +}; + +#if 0 +static struct dhcp6_opt *dh6o_pad; +static struct dhcp6_opt *dh6o_end; + +static void +dhcp6opttab_init() +{ + dh6o_pad = dhcp6opttab_bycode(0); + dh6o_end = dhcp6opttab_bycode(65536); +} +#endif + +#if 0 +static struct dhcp6_opt * +dhcp6opttab_byname(name) + char *name; +{ + struct dhcp6_opt *p; + + for (p = dh6opttab; p->code; p++) + if (strcmp(name, p->name) == 0) + return p; + return NULL; +} +#endif + +static struct dhcp6_opt * +dhcp6opttab_bycode(code) + u_int code; +{ + struct dhcp6_opt *p; + + for (p = dh6opttab; p->code; p++) + if (p->code == code) + return p; + return NULL; +} + +static void +dhcp6ext_print(u_char *cp, u_char *ep) +{ + u_int16_t code, len; + struct dhcp6_opt *p; + char buf[BUFSIZ]; + int i; + + if (cp == ep) + return; + printf(" "); + while (cp < ep) { + code = ntohs(*(u_int16_t *)&cp[0]); + if (code != 65535) + len = ntohs(*(u_int16_t *)&cp[2]); + else + len = 0; + p = dhcp6opttab_bycode(code); + if (p == NULL) { + printf("(unknown, len=%d)", len); + cp += len + 4; + continue; + } + + /* sanity check on length */ + switch (p->len) { + case OL6_N: + break; + case OL6_16N: + if (len % 16 != 0) + goto trunc; + break; + case OL6_Z: + if (len != 0) + goto trunc; + break; + default: + if (len != p->len) + goto trunc; + break; + } + if (cp + 4 + len > ep) { + printf("[|%s]", p->name); + return; + } + + printf("(%s, ", p->name); + switch (p->type) { + case OT6_V6: + for (i = 0; i < len; i += 16) { + inet_ntop(AF_INET6, &cp[4 + i], buf, + sizeof(buf)); + if (i != 0) + printf(","); + printf("%s", buf); + } + break; + case OT6_STR: + memset(&buf, 0, sizeof(buf)); + strncpy(buf, &cp[4], len); + printf("%s", buf); + break; + case OT6_NUM: + printf("%d", (u_int32_t)ntohl(*(u_int32_t *)&cp[4])); + break; + default: + for (i = 0; i < len; i++) + printf("%02x", cp[4 + i] & 0xff); + } + printf(")"); + cp += len + 4; + } + return; + +trunc: + printf("[|dhcp6ext]"); +} + +/* + * Print dhcp6 requests + */ +void +dhcp6_print(register const u_char *cp, u_int length, + u_short sport, u_short dport) +{ + union dhcp6 *dh6; + u_char *ep; + u_char *extp; + + printf("dhcp6"); + + ep = (u_char *)snapend; + + dh6 = (union dhcp6 *)cp; + TCHECK(dh6->dh6_msgtype); + switch (dh6->dh6_msgtype) { + case DH6_SOLICIT: + if (vflag && TTEST(dh6->dh6_sol.dh6sol_relayaddr)) { + printf(" solicit("); + if ((dh6->dh6_sol.dh6sol_flags & DH6SOL_CLOSE) != 0) + printf("C"); + if (dh6->dh6_sol.dh6sol_flags != 0) + printf(" "); + printf("cliaddr=%s", + ip6addr_string(&dh6->dh6_sol.dh6sol_cliaddr)); + printf(" relayaddr=%s", + ip6addr_string(&dh6->dh6_sol.dh6sol_relayaddr)); + printf(")"); + } else + printf(" solicit"); + break; + case DH6_ADVERT: + if (!(vflag && TTEST(dh6->dh6_adv.dh6adv_serveraddr))) { + printf(" advert"); + break; + } + printf(" advert("); + if ((dh6->dh6_adv.dh6adv_flags & DH6ADV_SERVPRESENT) != 0) + printf("S"); + if (dh6->dh6_adv.dh6adv_flags != 0) + printf(" "); + printf("pref=%u", dh6->dh6_adv.dh6adv_pref); + printf(" cliaddr=%s", + ip6addr_string(&dh6->dh6_adv.dh6adv_cliaddr)); + printf(" relayaddr=%s", + ip6addr_string(&dh6->dh6_adv.dh6adv_relayaddr)); + printf(" servaddr=%s", + ip6addr_string(&dh6->dh6_adv.dh6adv_serveraddr)); + extp = (u_char *)((&dh6->dh6_adv) + 1); + dhcp6ext_print(extp, ep); + printf(")"); + break; + case DH6_REQUEST: + if (!(vflag && TTEST(dh6->dh6_req.dh6req_relayaddr))) { + printf(" request"); + break; + } + printf(" request("); + if ((dh6->dh6_req.dh6req_flags & DH6REQ_CLOSE) != 0) + printf("C"); + if ((dh6->dh6_req.dh6req_flags & DH6REQ_SERVPRESENT) != 0) + printf("S"); + if ((dh6->dh6_req.dh6req_flags & DH6REQ_REBOOT) != 0) + printf("R"); + if (dh6->dh6_req.dh6req_flags != 0) + printf(" "); + printf("xid=0x%04x", dh6->dh6_req.dh6req_xid); + printf(" cliaddr=%s", + ip6addr_string(&dh6->dh6_req.dh6req_cliaddr)); + printf(" relayaddr=%s", + ip6addr_string(&dh6->dh6_req.dh6req_relayaddr)); + extp = (char *)((&dh6->dh6_req) + 1); + if ((dh6->dh6_req.dh6req_flags & DH6REQ_SERVPRESENT) != 0) { + printf(" servaddr=%s", ip6addr_string(extp)); + extp += 16; + } + dhcp6ext_print(extp, ep); + printf(")"); + break; + case DH6_REPLY: + if (!(vflag && TTEST(dh6->dh6_rep.dh6rep_xid))) { + printf(" reply"); + break; + } + printf(" reply("); + if ((dh6->dh6_rep.dh6rep_flagandstat & DH6REP_CLIPRESENT) != 0) + printf("C"); + if (dh6->dh6_rep.dh6rep_flagandstat != 0) + printf(" "); + printf("stat=0x%02x", + dh6->dh6_rep.dh6rep_flagandstat & DH6REP_STATMASK); + extp = (u_char *)((&dh6->dh6_rep) + 1); + if ((dh6->dh6_rep.dh6rep_flagandstat & DH6REP_CLIPRESENT) != 0) { + printf(" cliaddr=%s", ip6addr_string(extp)); + extp += 16; + } + dhcp6ext_print(extp, ep); + printf(")"); + break; + case DH6_RELEASE: + printf(" release"); + break; + case DH6_RECONFIG: + printf(" reconfig"); + break; + } + return; + +trunc: + printf("%s", tstr); +} diff --git a/contrib/tcpdump/print-dvmrp.c b/contrib/tcpdump/print-dvmrp.c index 585fde9..6727c36 100644 --- a/contrib/tcpdump/print-dvmrp.c +++ b/contrib/tcpdump/print-dvmrp.c @@ -21,7 +21,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: print-dvmrp.c,v 1.13 96/12/10 23:16:30 leres Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-dvmrp.c,v 1.17 1999/11/22 04:30:34 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/param.h> @@ -35,7 +39,6 @@ static const char rcsid[] = #include <netinet/udp.h> #include <netinet/udp_var.h> #include <netinet/tcp.h> -#include <netinet/tcpip.h> #include <stdio.h> #include <string.h> @@ -43,6 +46,7 @@ static const char rcsid[] = #include <unistd.h> #include "interface.h" +#include "extract.h" #include "addrtoname.h" /* @@ -209,15 +213,13 @@ print_report(register const u_char *bp, register const u_char *ep, } } -#define GET_ADDR(to) (memcpy((char *)to, (char *)bp, 4), bp += 4) - static void 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(" [|}"); @@ -229,50 +231,51 @@ print_probe(register const u_char *bp, register const u_char *ep, printf("\n\tgenid %u", genid); 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; +trunc: + (void)printf("[|dvmrp]"); } static void 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; +trunc: + (void)printf("[|dvmrp]"); } static void 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; @@ -281,20 +284,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"); @@ -307,6 +307,7 @@ 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) { @@ -314,47 +315,43 @@ print_neighbors2(register const u_char *bp, register const u_char *ep, return; } } + return; +trunc: + (void)printf("[|dvmrp]"); } static void print_prune(register const u_char *bp, register const u_char *ep, register u_int len) { - 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; +trunc: + (void)printf("[|dvmrp]"); } static void print_graft(register const u_char *bp, register const u_char *ep, register u_int len) { - - 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; +trunc: + (void)printf("[|dvmrp]"); } static void print_graft_ack(register const u_char *bp, register const u_char *ep, register u_int len) { - - 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; +trunc: + (void)printf("[|dvmrp]"); } diff --git a/contrib/tcpdump/print-egp.c b/contrib/tcpdump/print-egp.c index a621630..af52023 100644 --- a/contrib/tcpdump/print-egp.c +++ b/contrib/tcpdump/print-egp.c @@ -20,7 +20,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: print-egp.c,v 1.23 96/11/05 13:30:35 leres Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-egp.c,v 1.24 1999/11/21 09:36:51 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/param.h> diff --git a/contrib/tcpdump/print-esp.c b/contrib/tcpdump/print-esp.c new file mode 100644 index 0000000..bc5b7b7 --- /dev/null +++ b/contrib/tcpdump/print-esp.c @@ -0,0 +1,336 @@ +/* $NetBSD: print-ah.c,v 1.4 1996/05/20 00:41:16 fvdl Exp $ */ + +/* + * 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 + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-esp.c,v 1.5 1999/12/15 08:10:18 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <string.h> +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <net/route.h> +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/if_ether.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_icmp.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> +#include <netinet/tcp.h> + +#ifdef CRYPTO +#include <des.h> +#include <blowfish.h> +#ifdef HAVE_RC5_H +#include <rc5.h> +#endif +#ifdef HAVE_CAST_H +#include <cast.h> +#endif +#endif + +#include <stdio.h> + +#ifdef INET6 +#include <netinet/ip6.h> +#endif + +/* there's no standard definition so we are on our own */ +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 */ +}; + +#include "interface.h" +#include "addrtoname.h" + +int +esp_print(register const u_char *bp, register const u_char *bp2, int *nhdr) +{ + register const struct esp *esp; + register const u_char *ep; + u_int32_t spi; + enum { NONE, DESCBC, BLOWFISH, RC5, CAST128, DES3CBC } algo = NONE; + struct ip *ip = NULL; +#ifdef INET6 + struct ip6_hdr *ip6 = NULL; +#endif + int advance; + int len; + char *secret = NULL; + int ivlen = 0; + u_char *ivoff; + + esp = (struct esp *)bp; + spi = (u_int32_t)ntohl(esp->esp_spi); + + /* 'ep' points to the end of avaible data. */ + ep = snapend; + + if ((u_char *)(esp + 1) >= ep - sizeof(struct esp)) { + fputs("[|ESP]", stdout); + goto fail; + } + printf("ESP(spi=%u", spi); + printf(",seq=0x%x", (u_int32_t)ntohl(*(u_int32_t *)(esp + 1))); + printf(")"); + + /* if we don't have decryption key, we can't decrypt this packet. */ + 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; + } + + ip = (struct ip *)bp2; + switch (ip->ip_v) { +#ifdef INET6 + case 6: + ip6 = (struct ip6_hdr *)bp2; + ip = NULL; + /* we do not attempt to decrypt jumbograms */ + if (!ntohs(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); + break; +#endif /*INET6*/ + case 4: +#ifdef INET6 + ip6 = NULL; +#endif + len = ntohs(ip->ip_len); + 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((void *)secret, schedule); + + p = ivoff + ivlen; + des_cbc_encrypt((void *)p, (void *)p, + (long)(ep - p), schedule, (void *)iv, + DES_DECRYPT); + advance = ivoff - (u_char *)esp + ivlen; + break; + } +#else + 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 + 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); + + 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*/ + + case CAST128: +#if defined(CRYPTO) && defined(HAVE_CAST_H) && !defined(HAVE_BUGGY_CAST128) + { + CAST_KEY schedule; + u_char *p; + + CAST_set_key(&schedule, strlen(secret), secret); + + p = ivoff + ivlen; + CAST_cbc_encrypt(p, p, (long)(ep - p), &schedule, ivoff, + CAST_DECRYPT); + 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((void *)secret, s1); + des_set_key((void *)(secret + 8), s2); + des_set_key((void *)(secret + 16), s3); + + p = ivoff + ivlen; + des_ede3_cbc_encrypt((void *)p, (void *)p, + (long)(ep - p), s1, s2, s3, (void *)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; + } + + /* sanity check for pad length */ + if (ep - bp < *(ep - 2)) + goto fail; + + if (nhdr) + *nhdr = *(ep - 1); + + printf(": "); + return advance; + +fail: + if (nhdr) + *nhdr = -1; + return 65536; +} diff --git a/contrib/tcpdump/print-frag6.c b/contrib/tcpdump/print-frag6.c new file mode 100644 index 0000000..a043e8f --- /dev/null +++ b/contrib/tcpdump/print-frag6.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 1988, 1989, 1990, 1991, 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: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-frag6.c,v 1.3.2.1 2000/01/11 06:58:24 fenner Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef INET6 + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/if_ether.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_icmp.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> +#include <netinet/tcp.h> + +#include <stdio.h> + +#include <netinet/ip6.h> + +#include "interface.h" +#include "addrtoname.h" + +int +frag6_print(register const u_char *bp, register const u_char *bp2) +{ + register const struct ip6_frag *dp; + register const struct ip6_hdr *ip6; + register const u_char *ep; + +#if 0 +#define TCHECK(var) if ((u_char *)&(var) >= ep - sizeof(var)) goto trunc +#endif + + dp = (struct ip6_frag *)bp; + ip6 = (struct ip6_hdr *)bp2; + + /* 'ep' points to the end of avaible data. */ + ep = snapend; + + TCHECK(dp->ip6f_offlg); + + if (vflag) { + printf("frag (0x%08x:%d|%ld)", + (u_int32_t)ntohl(dp->ip6f_ident), + ntohs(dp->ip6f_offlg & IP6F_OFF_MASK), + sizeof(struct ip6_hdr) + ntohs(ip6->ip6_plen) - + (long)(bp - bp2) - sizeof(struct ip6_frag)); + } else { + printf("frag (%d|%ld)", + ntohs(dp->ip6f_offlg & IP6F_OFF_MASK), + sizeof(struct ip6_hdr) + ntohs(ip6->ip6_plen) - + (long)(bp - bp2) - sizeof(struct ip6_frag)); + } + +#if 0 + /* it is meaningless to decode non-first fragment */ + if (ntohs(dp->ip6f_offlg & IP6F_OFF_MASK) != 0) + return 65535; + else +#endif + { + fputs(" ", stdout); + return sizeof(struct ip6_frag); + } +trunc: + fputs("[|frag]", stdout); + return 65535; +#undef TCHECK +} +#endif /* INET6 */ diff --git a/contrib/tcpdump/print-gre.c b/contrib/tcpdump/print-gre.c index dd1ac83..8584595 100644 --- a/contrib/tcpdump/print-gre.c +++ b/contrib/tcpdump/print-gre.c @@ -24,7 +24,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: print-gre.c,v 1.4 96/12/10 23:28:23 leres Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-gre.c,v 1.6 1999/11/21 09:36:52 fenner Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/param.h> @@ -76,9 +80,6 @@ struct gre { #define GRE_SP 0x1000 /* Sequence Present */ -#define GREPROTO_IP 0x0800 - - /* * Deencapsulate and print a GRE-tunneled IP datagram */ @@ -123,16 +124,9 @@ gre_print(const u_char *bp, u_int length) if (flags & GRE_SP) cp += 4; - switch (proto) { - - case GREPROTO_IP: - ip_print(cp, length - ((cp - bp) / sizeof(u_char))); - break; - - default: - printf("gre-proto-0x%04X", proto); - break; - } + length -= cp - bp; + if (ether_encap_print(proto, cp, length, length) == 0) + printf("gre-proto-0x%04X", proto); return; trunc: diff --git a/contrib/tcpdump/print-icmp6.c b/contrib/tcpdump/print-icmp6.c new file mode 100644 index 0000000..f6bc864 --- /dev/null +++ b/contrib/tcpdump/print-icmp6.c @@ -0,0 +1,574 @@ +/* + * Copyright (c) 1988, 1989, 1990, 1991, 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: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-icmp6.c,v 1.2.2.1 2000/01/11 06:58:24 fenner Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef INET6 + +#include <ctype.h> + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/if_ether.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_icmp.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> +#include <netinet/tcp.h> + +#include <arpa/inet.h> + +#include <stdio.h> + +#include <netinet/ip6.h> +#include <netinet/icmp6.h> + +#include "interface.h" +#include "addrtoname.h" + +void icmp6_opt_print(const u_char *, int); +void mld6_print(const u_char *); + +void +icmp6_print(register const u_char *bp, register const u_char *bp2) +{ + 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; + char buf[256]; + int icmp6len; + +#if 0 +#define TCHECK(var) if ((u_char *)&(var) > ep - sizeof(var)) goto trunc +#endif + + dp = (struct icmp6_hdr *)bp; + ip = (struct ip6_hdr *)bp2; + oip = (struct ip6_hdr *)(dp + 1); + str = buf; + /* 'ep' points to the end of avaible 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) { + case ICMP6_DST_UNREACH: + TCHECK(oip->ip6_dst); + switch (dp->icmp6_code) { + case ICMP6_DST_UNREACH_NOROUTE: + printf("icmp6: %s unreachable route", + ip6addr_string(&oip->ip6_dst)); + break; + case ICMP6_DST_UNREACH_ADMIN: + 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)); + break; + case ICMP6_DST_UNREACH_ADDR: + printf("icmp6: %s unreachable address", + 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) { + case IPPROTO_TCP: + printf("icmp6: %s tcp port %s unreachable", + ip6addr_string(&oip->ip6_dst), + tcpport_string(dport)); + break; + case IPPROTO_UDP: + printf("icmp6: %s udp port %s unreachable", + ip6addr_string(&oip->ip6_dst), + udpport_string(dport)); + break; + default: + printf("icmp6: %s protocol %d port %d unreachable", + ip6addr_string(&oip->ip6_dst), + oip->ip6_nxt, dport); + break; + } + break; + default: + printf("icmp6: %s unreachable code-#%d", + ip6addr_string(&oip->ip6_dst), + dp->icmp6_code); + break; + } + break; + case ICMP6_PACKET_TOO_BIG: + TCHECK(dp->icmp6_mtu); + printf("icmp6: too big %u\n", (u_int32_t)ntohl(dp->icmp6_mtu)); + break; + case ICMP6_TIME_EXCEEDED: + TCHECK(oip->ip6_dst); + switch (dp->icmp6_code) { + case ICMP6_TIME_EXCEED_TRANSIT: + printf("icmp6: time exceeded in-transit for %s", + ip6addr_string(&oip->ip6_dst)); + break; + case ICMP6_TIME_EXCEED_REASSEMBLY: + printf("icmp6: ip6 reassembly time exceeded"); + break; + default: + printf("icmp6: time exceeded code-#%d", + dp->icmp6_code); + break; + } + break; + case ICMP6_PARAM_PROB: + 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)); + break; + case ICMP6_PARAMPROB_NEXTHEADER: + printf("icmp6: parameter problem next header - octet %u\n", + (u_int32_t)ntohl(dp->icmp6_pptr)); + break; + case ICMP6_PARAMPROB_OPTION: + printf("icmp6: parameter problem option - octet %u\n", + (u_int32_t)ntohl(dp->icmp6_pptr)); + break; + default: + printf("icmp6: parameter problem code-#%d", + dp->icmp6_code); + break; + } + break; + case ICMP6_ECHO_REQUEST: + printf("icmp6: echo request"); + break; + case ICMP6_ECHO_REPLY: + printf("icmp6: echo reply"); + break; + case ICMP6_MEMBERSHIP_QUERY: + printf("icmp6: multicast listener query "); + mld6_print((const u_char *)dp); + break; + case ICMP6_MEMBERSHIP_REPORT: + printf("icmp6: multicast listener report "); + mld6_print((const u_char *)dp); + break; + case ICMP6_MEMBERSHIP_REDUCTION: + printf("icmp6: multicast listener done "); + mld6_print((const u_char *)dp); + break; + case ND_ROUTER_SOLICIT: + printf("icmp6: router solicitation "); + if (vflag) { +#define RTSOLLEN 8 + icmp6_opt_print((const u_char *)dp + RTSOLLEN, + icmp6len - RTSOLLEN); + } + break; + case ND_ROUTER_ADVERT: + printf("icmp6: router advertisement"); + if (vflag) { + struct nd_router_advert *p; + + p = (struct nd_router_advert *)dp; + TCHECK(p->nd_ra_retransmit); + printf("(chlim=%d, ", (int)p->nd_ra_curhoplimit); + if (p->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED) + printf("M"); + if (p->nd_ra_flags_reserved & ND_RA_FLAG_OTHER) + printf("O"); + if (p->nd_ra_flags_reserved != 0) + printf(" "); + printf("router_ltime=%d, ", ntohs(p->nd_ra_router_lifetime)); + printf("reachable_time=%u, ", + (u_int32_t)ntohl(p->nd_ra_reachable)); + printf("retrans_time=%u)", + (u_int32_t)ntohl(p->nd_ra_retransmit)); +#define RTADVLEN 16 + icmp6_opt_print((const u_char *)dp + RTADVLEN, + icmp6len - RTADVLEN); + } + break; + case ND_NEIGHBOR_SOLICIT: + { + struct nd_neighbor_solicit *p; + p = (struct nd_neighbor_solicit *)dp; + TCHECK(p->nd_ns_target); + printf("icmp6: neighbor sol: who has %s", + ip6addr_string(&p->nd_ns_target)); + if (vflag) { +#define NDSOLLEN 24 + icmp6_opt_print((const u_char *)dp + NDSOLLEN, + icmp6len - NDSOLLEN); + } + } + break; + case ND_NEIGHBOR_ADVERT: + { + struct nd_neighbor_advert *p; + + p = (struct nd_neighbor_advert *)dp; + TCHECK(p->nd_na_target); + printf("icmp6: neighbor adv: tgt is %s", + ip6addr_string(&p->nd_na_target)); + 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. */ + if (p->nd_na_flags_reserved & ND_NA_FLAG_ALL) { +#undef ND_NA_FLAG_ALL + u_int32_t flags; + + flags = p->nd_na_flags_reserved; + printf("("); + if (flags & ND_NA_FLAG_ROUTER) + printf("R"); + if (flags & ND_NA_FLAG_SOLICITED) + printf("S"); + if (flags & ND_NA_FLAG_OVERRIDE) + printf("O"); + printf(")"); + } +#define NDADVLEN 24 + icmp6_opt_print((const u_char *)dp + NDADVLEN, + icmp6len - 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); +#define REDIRECTLEN 40 + if (vflag) { + icmp6_opt_print((const u_char *)dp + REDIRECTLEN, + icmp6len - REDIRECTLEN); + } + break; + } + 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; + } + 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); + } + } + 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; + } + } +#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(\""); + } + for (; cp < ep; cp++) + printf((isprint(*cp) ? "%c" : "\\%03o"), *cp); + printf("\""); + 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)); + } + } + } + printf(")"); + break; + } +#endif /*ICMP6_WRUREPLY*/ + default: + printf("icmp6: type-#%d", dp->icmp6_type); + break; + } + return; +trunc: + fputs("[|icmp6]", stdout); +#if 0 +#undef TCHECK +#endif +} + +void +icmp6_opt_print(register const u_char *bp, int resid) +{ + register const struct nd_opt_hdr *op; + register const struct nd_opt_hdr *opl; /* why there's no struct? */ + register const struct nd_opt_prefix_info *opp; + register const struct icmp6_opts_redirect *opr; + register const struct nd_opt_mtu *opm; + register const 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 + +#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. */ + 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) + 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) + goto trunc; +#else + TCHECK((u_char *)opl + (opl->nd_opt_len << 3) - 1); +#endif + printf("(tgt lladdr: %s", + etheraddr_string((u_char *)(opl + 1))); + if (opl->nd_opt_len != 1) + printf("!"); + printf(")"); + icmp6_opt_print((const u_char *)op + (op->nd_opt_len << 3), + resid - (op->nd_opt_len << 3)); + break; + case ND_OPT_PREFIX_INFORMATION: + opp = (struct nd_opt_prefix_info *)op; + TCHECK(opp->nd_opt_pi_prefix); + printf("(prefix info: "); + if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK) + printf("L"); + if (opp->nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO) + printf("A"); + if (opp->nd_opt_pi_flags_reserved) + 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)); + } + 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; + } + return; + trunc: + fputs("[ndp opt]", stdout); + return; +#if 0 +#undef TCHECK +#endif +#undef ECHECK +} + +void +mld6_print(register const u_char *bp) +{ + register struct mld6_hdr *mp = (struct mld6_hdr *)bp; + register const u_char *ep; + + /* 'ep' points to the end of avaible data. */ + ep = snapend; + + if ((u_char *)mp + sizeof(*mp) > ep) + return; + + printf("max resp delay: %d ", ntohs(mp->mld6_maxdelay)); + printf("addr: %s", ip6addr_string(&mp->mld6_addr)); + + return; +} +#endif /* INET6 */ diff --git a/contrib/tcpdump/print-igrp.c b/contrib/tcpdump/print-igrp.c index 87e8e79..edbc1f1 100644 --- a/contrib/tcpdump/print-igrp.c +++ b/contrib/tcpdump/print-igrp.c @@ -23,7 +23,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: print-igrp.c,v 1.8 97/05/28 12:52:47 leres Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-igrp.c,v 1.11 1999/11/21 09:36:53 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/param.h> diff --git a/contrib/tcpdump/print-ip6.c b/contrib/tcpdump/print-ip6.c new file mode 100644 index 0000000..44ce6ce --- /dev/null +++ b/contrib/tcpdump/print-ip6.c @@ -0,0 +1,228 @@ +/* + * 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 + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-ip6.c,v 1.2.2.1 2000/01/11 06:58:25 fenner Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef INET6 + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> +#include <netinet/tcp.h> + +#include <stdio.h> +#ifdef __STDC__ +#include <stdlib.h> +#endif +#include <unistd.h> + +#include "interface.h" +#include "addrtoname.h" + +#include <netinet/ip6.h> + +/* + * print an IP6 datagram. + */ +void +ip6_print(register const u_char *bp, register int length) +{ + register const struct ip6_hdr *ip6; + register int hlen; + register int len; + register const u_char *cp; + int nh; + 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; + } + 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) + (void)printf("truncated-ip6 - %d bytes missing!", + len + hlen - length); + + cp = (const u_char *)ip6; + nh = ip6->ip6_nxt; + while (cp < snapend) { + cp += hlen; + + if (cp == (u_char *)(ip6 + 1) + && nh != IPPROTO_TCP && nh != IPPROTO_UDP) { + (void)printf("%s > %s: ", ip6addr_string(&ip6->ip6_src), + ip6addr_string(&ip6->ip6_dst)); + } + + switch (nh) { + case IPPROTO_HOPOPTS: + hlen = hbhopt_print(cp); + nh = *cp; + break; + case IPPROTO_DSTOPTS: + hlen = dstopt_print(cp); + nh = *cp; + break; + case IPPROTO_FRAGMENT: + hlen = frag6_print(cp, (const u_char *)ip6); + if (snapend <= cp + hlen) + goto end; + nh = *cp; + break; + case IPPROTO_ROUTING: + hlen = rt6_print(cp, (const u_char *)ip6); + nh = *cp; + break; + case IPPROTO_TCP: + tcp_print(cp, len + sizeof(struct ip6_hdr) - (cp - bp), + (const u_char *)ip6); + goto end; + case IPPROTO_UDP: + udp_print(cp, len + sizeof(struct ip6_hdr) - (cp - bp), + (const u_char *)ip6); + goto end; + case IPPROTO_ICMPV6: + icmp6_print(cp, (const u_char *)ip6); + goto end; + case IPPROTO_AH: + hlen = ah_print(cp, (const u_char *)ip6); + nh = *cp; + break; + case IPPROTO_ESP: + { + int enh; + cp += esp_print(cp, (const u_char *)ip6, &enh); + if (enh < 0) + goto end; + nh = enh & 0xff; + 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; + 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; + + default: + (void)printf("ip-proto-%d %d", ip6->ip6_nxt, len); + goto end; + } + } + + end: + + flow = ntohl(ip6->ip6_flow); +#if 0 + /* rfc1883 */ + if (flow & 0x0f000000) + (void)printf(" [pri 0x%x]", (flow & 0x0f000000) >> 24); + if (flow & 0x00ffffff) + (void)printf(" [flowlabel 0x%x]", flow & 0x00ffffff); +#else + /* RFC 2460 */ + if (flow & 0x0ff00000) + (void)printf(" [class 0x%x]", (flow & 0x0ff00000) >> 20); + if (flow & 0x000fffff) + (void)printf(" [flowlabel 0x%x]", flow & 0x000fffff); +#endif + + if (ip6->ip6_hlim <= 1) + (void)printf(" [hlim %d]", (int)ip6->ip6_hlim); + + if (vflag) { + printf(" ("); + (void)printf("len %d", len); + if (ip6->ip6_hlim > 1) + (void)printf(", hlim %d", (int)ip6->ip6_hlim); + printf(")"); + } +} + +#endif /* INET6 */ diff --git a/contrib/tcpdump/print-ip6opts.c b/contrib/tcpdump/print-ip6opts.c new file mode 100644 index 0000000..756f098 --- /dev/null +++ b/contrib/tcpdump/print-ip6opts.c @@ -0,0 +1,162 @@ +/* + * 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: + * 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[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-ip6opts.c,v 1.2.2.1 2000/01/11 06:58:25 fenner Exp $"; +#endif + +#ifdef INET6 +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <netinet/in.h> +#include <netinet/ip6.h> + +#include <stdio.h> + +#include "interface.h" +#include "addrtoname.h" + +void +ip6_opt_print(const u_char *bp, int len) +{ + int i; + int optlen; + + for (i = 0; i < len; i += optlen) { + switch (bp[i]) { + case IP6OPT_PAD1: + optlen = 1; + break; + case IP6OPT_PADN: + if (len - i < IP6OPT_MINLEN) { + printf("(padn: trunc)"); + goto trunc; + } + optlen = bp[i + 1] + 2; + break; + case IP6OPT_RTALERT: + if (len - i < IP6OPT_RTALERT_LEN) { + printf("(rtalert: trunc)"); + goto trunc; + } + if (bp[i + 1] != IP6OPT_RTALERT_LEN - 2) { + printf("(rtalert: invalid len %d)", bp[i + 1]); + goto trunc; + } + printf("(rtalert: 0x%04x) ", ntohs(*(u_short *)&bp[i + 2])); + optlen = IP6OPT_RTALERT_LEN; + break; + case IP6OPT_JUMBO: + if (len - i < IP6OPT_JUMBO_LEN) { + printf("(jumbo: trunc)"); + goto trunc; + } + if (bp[i + 1] != IP6OPT_JUMBO_LEN - 2) { + 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; + 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; + break; + } + } + +#if 0 +end: +#endif + return; + +trunc: + printf("[trunc] "); +} + +int +hbhopt_print(register const u_char *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 = 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)); + + return(hbhlen); + + trunc: + fputs("[|HBH]", stdout); + return(hbhlen); +} + +int +dstopt_print(register const u_char *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 = 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), + dstoptlen - sizeof(*dp)); + } + + return(dstoptlen); + + trunc: + fputs("[|DSTOPT]", stdout); + return(dstoptlen); +} +#endif /* INET6 */ diff --git a/contrib/tcpdump/print-ipcomp.c b/contrib/tcpdump/print-ipcomp.c new file mode 100644 index 0000000..8b2dd47 --- /dev/null +++ b/contrib/tcpdump/print-ipcomp.c @@ -0,0 +1,112 @@ +/* + * Copyright (c) 1988, 1989, 1990, 1991, 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: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-ipcomp.c,v 1.2.2.2 2000/01/25 18:31:10 itojun Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <string.h> +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <net/route.h> +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/if_ether.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_icmp.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> +#include <netinet/tcp.h> + +#include <stdio.h> + +#ifdef INET6 +#include <netinet/ip6.h> +#endif + +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 */ +}; + +#if defined(HAVE_LIBZ) && defined(HAVE_ZLIB_H) +#include <zlib.h> +#endif + +#include "interface.h" +#include "addrtoname.h" + +int +ipcomp_print(register const u_char *bp, register const u_char *bp2, int *nhdr) +{ + register const struct ipcomp *ipcomp; + register const u_char *ep; + u_int16_t cpi; +#if defined(HAVE_LIBZ) && defined(HAVE_ZLIB_H) + int advance; +#endif + + ipcomp = (struct ipcomp *)bp; + cpi = (u_int16_t)ntohs(ipcomp->comp_cpi); + + /* 'ep' points to the end of avaible data. */ + ep = snapend; + + if ((u_char *)(ipcomp + 1) >= ep - sizeof(struct ipcomp)) { + fputs("[|IPCOMP]", stdout); + goto fail; + } + printf("IPComp(cpi=%u)", cpi); + +#if defined(HAVE_LIBZ) && defined(HAVE_ZLIB_H) + if (1) + goto fail; + + /* + * We may want to decompress the packet here. Packet buffer + * management is a headache (if we decompress, packet will become + * larger). + */ + if (nhdr) + *nhdr = ipcomp->comp_nxt; + advance = sizeof(struct ipcomp); + + printf(": "); + return advance; + +#endif +fail: + if (nhdr) + *nhdr = -1; + return 65536; +} diff --git a/contrib/tcpdump/print-isakmp.c b/contrib/tcpdump/print-isakmp.c new file mode 100644 index 0000000..f3c38ac --- /dev/null +++ b/contrib/tcpdump/print-isakmp.c @@ -0,0 +1,1102 @@ +/* + * 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. + * + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-isakmp.c,v 1.8.2.1 2000/01/14 19:19:56 mcr Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <string.h> +#include <ctype.h> +#include <sys/param.h> +#include <sys/time.h> +#include <sys/socket.h> + +#if __STDC__ +struct mbuf; +struct rtentry; +#endif +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/if_ether.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> +#include <netinet/tcp.h> + +#ifdef INET6 +#include <netinet/ip6.h> +#endif + +#include <stdio.h> +#include <netdb.h> + +#include "isakmp.h" +#include "ipsec_doi.h" +#include "oakley.h" +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" /* must come after interface.h */ + +#ifndef HAVE_SOCKADDR_STORAGE +#define sockaddr_storage sockaddr +#endif + +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)); + +#define MAXINITIATORS 20 +int ninitiator = 0; +struct { + cookie_t initiator; + struct sockaddr_storage iaddr; + struct sockaddr_storage raddr; +} cookiecache[MAXINITIATORS]; + +/* protocol id */ +static char *protoidstr[] = { + NULL, "isakmp", "ipsec-ah", "ipsec-esp", "ipcomp", +}; + +/* isakmp->np */ +static 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)) = { + NULL, + isakmp_sa_print, + isakmp_p_print, + isakmp_t_print, + isakmp_ke_print, + isakmp_id_print, + NULL, + NULL, + isakmp_hash_print, + NULL, + isakmp_nonce_print, + isakmp_n_print, + isakmp_d_print, + isakmp_vid_print, +}; + +/* isakmp->etype */ +static 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, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + "oakley-quick", "oakley-newgroup", +}; + +#define STR_OR_ID(x, tab) \ + (((x) < sizeof(tab)/sizeof(tab[0]) && tab[(x)]) ? tab[(x)] : numstr(x)) +#define PROTOIDSTR(x) STR_OR_ID(x, protoidstr) +#define NPSTR(x) STR_OR_ID(x, npstr) +#define ETYPESTR(x) STR_OR_ID(x, etypestr) + +#define NPFUNC(x) \ + (((x) < sizeof(npfunc)/sizeof(npfunc[0]) && npfunc[(x)]) \ + ? npfunc[(x)] : NULL) + +static int +iszero(u_char *p, size_t l) +{ + while (l--) { + if (*p++) + return 0; + } + return 1; +} + +/* find cookie from initiator cache */ +static int +cookie_find(cookie_t *in) +{ + int i; + + for (i = 0; i < MAXINITIATORS; i++) { + if (memcmp(in, &cookiecache[i].initiator, sizeof(*in)) == 0) + return i; + } + + return -1; +} + +/* record initiator */ +static void +cookie_record(cookie_t *in, const u_char *bp2) +{ + int i; + struct ip *ip; + struct sockaddr_in *sin; +#ifdef INET6 + struct ip6_hdr *ip6; + struct sockaddr_in6 *sin6; +#endif + + i = cookie_find(in); + if (0 <= i) { + ninitiator = (i + 1) % MAXINITIATORS; + return; + } + + ip = (struct ip *)bp2; + switch (ip->ip_v) { + case 4: + memset(&cookiecache[ninitiator].iaddr, 0, + sizeof(cookiecache[ninitiator].iaddr)); + memset(&cookiecache[ninitiator].raddr, 0, + 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; +#ifdef INET6 + case 6: + memset(&cookiecache[ninitiator].iaddr, 0, + sizeof(cookiecache[ninitiator].iaddr)); + memset(&cookiecache[ninitiator].raddr, 0, + sizeof(cookiecache[ninitiator].raddr)); + + 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; +#endif + default: + return; + } + memcpy(&cookiecache[ninitiator].initiator, in, sizeof(*in)); + ninitiator = (ninitiator + 1) % MAXINITIATORS; +} + +#define cookie_isinitiator(x, y) cookie_sidecheck((x), (y), 1) +#define cookie_isresponder(x, y) cookie_sidecheck((x), (y), 0) +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) { + 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; +#ifdef INET6 + 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; +#endif + default: + return 0; + } + + sa = (struct sockaddr *)&ss; + if (initiator) { + if (sa->sa_family != ((struct sockaddr *)&cookiecache[i].iaddr)->sa_family) + return 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 (sa->sa_family != ((struct sockaddr *)&cookiecache[i].raddr)->sa_family) + return 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 +rawprint(caddr_t loc, size_t len) +{ + static u_char *p; + int i; + + p = (u_char *)loc; + for (i = 0; i < len; i++) + printf("%02x", p[i] & 0xff); +} + +struct attrmap { + char *type; + int nvalue; + char *value[30]; /*XXX*/ +}; + +static u_char * +isakmp_attrmap_print(u_char *p, u_char *ep, struct attrmap *map, size_t nmap) +{ + u_short *q; + int totlen; + u_int32_t t, v; + + q = (u_short *)p; + if (p[0] & 0x80) + totlen = 4; + else + totlen = 4 + ntohs(q[1]); + if (ep < p + totlen) { + printf("[|attr]"); + return ep + 1; + } + + printf("("); + t = ntohs(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]); + 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(")"); + return p + totlen; +} + +static u_char * +isakmp_attr_print(u_char *p, u_char *ep) +{ + u_short *q; + int totlen; + u_int32_t t; + + q = (u_short *)p; + if (p[0] & 0x80) + totlen = 4; + else + totlen = 4 + ntohs(q[1]); + if (ep < p + totlen) { + printf("[|attr]"); + return ep + 1; + } + + printf("("); + t = ntohs(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(")"); + 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) +{ + struct isakmp_pl_sa *p; + u_int32_t *q; + u_int32_t doi; + u_int32_t sit; + u_char *cp; + int t; + + printf("%s:", NPSTR(ISAKMP_NPTYPE_SA)); + + p = (struct isakmp_pl_sa *)ext; + doi = ntohl(p->doi); + if (doi != 1) { + printf(" doi=%d", doi); + printf(" situation=%u", (u_int32_t)ntohl(p->sit)); + return (u_char *)(p + 1); + } + + printf(" doi=ipsec"); + q = (u_int32_t *)&p->sit; + printf(" situation="); + t = 0; + if (ntohl(*q) & 0x01) { + printf("identity"); + t++; + } + if (ntohl(*q) & 0x02) { + printf("%ssecrecy", t ? "+" : ""); + t++; + } + if (ntohl(*q) & 0x04) + printf("%sintegrity", t ? "+" : ""); + sit = htonl(*q++); + + if (sit != 0x01) + printf(" ident=%u", (u_int32_t)ntohl(*q++)); + + ext = (struct isakmp_gen *)q; + + cp = isakmp_sub_print(ISAKMP_NPTYPE_P, ext, ep, phase, doi, proto0); + + return cp; +} + +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) +{ + struct isakmp_pl_p *p; + u_char *cp; + + printf("%s:", NPSTR(ISAKMP_NPTYPE_P)); + + p = (struct isakmp_pl_p *)ext; + printf(" #%d protoid=%s transform=%d", + p->p_no, PROTOIDSTR(p->prot_id), p->num_t); + if (p->spi_size) { + printf(" spi="); + rawprint((caddr_t)(p + 1), p->spi_size); + } + + ext = (struct isakmp_gen *)((u_char *)(p + 1) + p->spi_size); + + cp = isakmp_sub_print(ISAKMP_NPTYPE_T, ext, ep, phase, doi0, + p->prot_id); + + return cp; +} + +static char *isakmp_p_map[] = { + NULL, "ike", +}; + +static char *ah_p_map[] = { + NULL, "md5", "sha", "1des", +}; + +static char *esp_p_map[] = { + NULL, "1des-iv64", "1des", "3des", "rc5", "idea", "cast", + "blowfish", "3idea", "1des-iv32", "rc4", "null" +}; + +static char *ipcomp_p_map[] = { + NULL, "oui", "deflate", "lzs", +}; + +struct attrmap ipsec_t_map[] = { + { NULL, 0, }, + { "lifetype", 3, { NULL, "sec", "kb", }, }, + { "life", 0, }, + { "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, }, +}; + +struct attrmap oakley_t_map[] = { + { NULL, 0 }, + { "enc", 7, { NULL, "1des", "idea", "blowfish", "rc5", + "3des", "cast"}, }, + { "hash", 4, { NULL, "md5", "sha1", "tiger", }, }, + { "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, }, + { "lifetype", 3, { NULL, "sec", "kb", }, }, + { "lifeduration", 0, }, + { "prf", 0, }, + { "keylen", 0, }, + { "field", 0, }, + { "order", 0, }, +}; + +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) +{ + struct isakmp_pl_t *p; + u_char *cp; + char *idstr; + struct attrmap *map; + size_t nmap; + u_char *ep2; + + printf("%s:", NPSTR(ISAKMP_NPTYPE_T)); + + p = (struct isakmp_pl_t *)ext; + + switch (proto) { + case 1: + idstr = STR_OR_ID(p->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); + 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); + 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); + map = ipsec_t_map; + nmap = sizeof(ipsec_t_map)/sizeof(ipsec_t_map[0]); + break; + default: + idstr = NULL; + map = NULL; + nmap = 0; + break; + } + + if (idstr) + printf(" #%d id=%s ", p->t_no, idstr); + else + printf(" #%d id=%d ", p->t_no, p->t_id); + cp = (u_char *)(p + 1); + ep2 = (u_char *)p + ntohs(ext->len); + while (cp < ep && cp < ep2) { + if (map && nmap) { + cp = isakmp_attrmap_print(cp, (ep < ep2) ? ep : ep2, + map, nmap); + } else + cp = isakmp_attr_print(cp, (ep < ep2) ? ep : ep2); + } + if (ep < ep2) + printf("..."); + return cp; +} + +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) +{ + printf("%s:", NPSTR(ISAKMP_NPTYPE_KE)); + + printf(" key len=%d", ntohs(ext->len) - 4); + if (2 < vflag && 4 < ntohs(ext->len)) { + printf(" "); + rawprint((caddr_t)(ext + 1), ntohs(ext->len) - 4); + } + return (u_char *)ext + ntohs(ext->len); +} + +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) +{ +#define USE_IPSECDOI_IN_PHASE1 1 + struct isakmp_pl_id *p; + static char *idtypestr[] = { + "IPv4", "IPv4net", "IPv6", "IPv6net", + }; + static char *ipsecidtypestr[] = { + NULL, "IPv4", "FQDN", "user FQDN", "IPv4net", "IPv6", + "IPv6net", "IPv4range", "IPv6range", "ASN1 DN", "ASN1 GN", + "keyid", + }; + int len; + u_char *data; + + printf("%s:", NPSTR(ISAKMP_NPTYPE_ID)); + + p = (struct isakmp_pl_id *)ext; + if (sizeof(*p) < ext->len) + data = (u_char *)(p + 1); + else + data = NULL; + len = ntohs(ext->len) - sizeof(*p); + +#if 0 /*debug*/ + printf(" [phase=%d doi=%d proto=%d]", phase, doi, proto); +#endif + switch (phase) { +#ifndef USE_IPSECDOI_IN_PHASE1 + case 1: +#endif + default: + printf(" idtype=%s", STR_OR_ID(p->d.id_type, idtypestr)); + printf(" doi_data=%u", + (u_int32_t)(ntohl(p->d.doi_data) & 0xffffff)); + break; + +#ifdef USE_IPSECDOI_IN_PHASE1 + case 1: +#endif + case 2: + { + struct ipsecdoi_id *p; + 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)); + if (!len) + break; + switch (p->type) { + case IPSECDOI_ID_IPV4_ADDR: + printf(" len=%d %s", len, ipaddr_string(data)); + len = 0; + break; + case IPSECDOI_ID_FQDN: + case IPSECDOI_ID_USER_FQDN: + { + 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]); + } + 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]); + len = 0; + break; + } +#ifdef INET6 + case IPSECDOI_ID_IPV6_ADDR: + 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]); + 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))); + 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))); + len = 0; + break; +#endif /*INET6*/ + case IPSECDOI_ID_DER_ASN1_DN: + case IPSECDOI_ID_DER_ASN1_GN: + case IPSECDOI_ID_KEY_ID: + break; + } + break; + } + } + if (data && len) { + len -= sizeof(*p); + printf(" len=%d", len); + if (2 < vflag) { + printf(" "); + rawprint((caddr_t)data, len); + } + } + return (u_char *)ext + ntohs(ext->len); +} + +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) +{ + printf("%s:", NPSTR(ISAKMP_NPTYPE_HASH)); + + printf(" len=%d", ntohs(ext->len) - 4); + if (2 < vflag && 4 < ntohs(ext->len)) { + printf(" "); + rawprint((caddr_t)(ext + 1), ntohs(ext->len) - 4); + } + return (u_char *)ext + ntohs(ext->len); +} + +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) +{ + printf("%s:", NPSTR(ISAKMP_NPTYPE_NONCE)); + + printf(" n len=%d", ntohs(ext->len) - 4); + if (2 < vflag && 4 < ntohs(ext->len)) { + printf(" "); + rawprint((caddr_t)(ext + 1), ntohs(ext->len) - 4); + } + return (u_char *)ext + ntohs(ext->len); +} + +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) +{ + struct isakmp_pl_n *p; + u_char *cp; + u_char *ep2; + u_int32_t doi; + u_int32_t proto; + static char *notifystr[] = { + NULL, "INVALID-PAYLOAD-TYPE", + "DOI-NOT-SUPPORTED", "SITUATION-NOT-SUPPORTED", + "INVALID-COOKIE", "INVALID-MAJOR-VERSION", + "INVALID-MINOR-VERSION", "INVALID-EXCHANGE-TYPE", + "INVALID-FLAGS", "INVALID-MESSAGE-ID", + "INVALID-PROTOCOL-ID", "INVALID-SPI", + "INVALID-TRANSFORM-ID", "ATTRIBUTES-NOT-SUPPORTED", + "NO-PROPOSAL-CHOSEN", "BAD-PROPOSAL-SYNTAX", + "PAYLOAD-MALFORMED", "INVALID-KEY-INFORMATION", + "INVALID-ID-INFORMATION", "INVALID-CERT-ENCODING", + "INVALID-CERTIFICATE", "CERT-TYPE-UNSUPPORTED", + "INVALID-CERT-AUTHORITY", "INVALID-HASH-INFORMATION", + "AUTHENTICATION-FAILED", "INVALID-SIGNATURE", + "ADDRESS-NOTIFICATION", "NOTIFY-SA-LIFETIME", + "CERTIFICATE-UNAVAILABLE", "UNSUPPORTED-EXCHANGE-TYPE", + "UNEQUAL-PAYLOAD-LENGTHS", + }; + static char *ipsecnotifystr[] = { + "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)) + + printf("%s:", NPSTR(ISAKMP_NPTYPE_N)); + + p = (struct isakmp_pl_n *)ext; + doi = ntohl(p->doi); + proto = p->prot_id; + if (doi != 1) { + printf(" doi=%d", doi); + printf(" proto=%d", proto); + printf(" type=%s", NOTIFYSTR(ntohs(p->type))); + if (p->spi_size) { + printf(" spi="); + rawprint((caddr_t)(p + 1), p->spi_size); + } + return (u_char *)(p + 1) + p->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))); + else + printf(" type=%s", NOTIFYSTR(ntohs(p->type))); + if (p->spi_size) { + printf(" spi="); + rawprint((caddr_t)(p + 1), p->spi_size); + } + + cp = (u_char *)(p + 1) + p->spi_size; + ep2 = (u_char *)p + ntohs(ext->len); + + if (cp < ep) { + printf(" orig=("); + switch (ntohs(p->type)) { + case IPSECDOI_NTYPE_RESPONDER_LIFETIME: + { + 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, + (ep < ep2) ? ep : ep2, map, nmap); + } + break; + } + case IPSECDOI_NTYPE_REPLAY_STATUS: + printf("replay detection %sabled", + (*(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); + break; + default: + /* NULL is dummy */ + isakmp_print(cp, + ntohs(ext->len) - sizeof(*p) - p->spi_size, + NULL); + } + printf(")"); + } + return (u_char *)ext + ntohs(ext->len); +} + +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) +{ + struct isakmp_pl_d *p; + u_int8_t *q; + u_int32_t doi; + u_int32_t proto; + int i; + + printf("%s:", NPSTR(ISAKMP_NPTYPE_D)); + + p = (struct isakmp_pl_d *)ext; + doi = ntohl(p->doi); + proto = p->prot_id; + if (doi != 1) { + printf(" doi=%u", doi); + printf(" proto=%u", proto); + } else { + printf(" doi=ipsec"); + printf(" proto=%s", PROTOIDSTR(proto)); + } + printf(" spilen=%u", p->spi_size); + printf(" nspi=%u", ntohs(p->num_spi)); + printf(" spi="); + q = (u_int8_t *)(p + 1); + for (i = 0; i < ntohs(p->num_spi); i++) { + if (i != 0) + printf(","); + rawprint((caddr_t)q, p->spi_size); + q += p->spi_size; + } + return q; +} + +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) +{ + printf("%s:", NPSTR(ISAKMP_NPTYPE_VID)); + + printf(" len=%d", ntohs(ext->len) - 4); + if (2 < vflag && 4 < ntohs(ext->len)) { + printf(" "); + rawprint((caddr_t)(ext + 1), ntohs(ext->len) - 4); + } + return (u_char *)ext + ntohs(ext->len); +} + +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) +{ + u_char *cp; + + cp = (u_char *)ext; + + if (NPFUNC(np)) + cp = (*NPFUNC(np))(ext, ep, phase, doi, proto); + else { + printf("%s", NPSTR(np)); + cp += ntohs(ext->len); + } + return cp; +} + +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) +{ + u_char *cp; + static int depth = 0; + int i; + + cp = (u_char *)ext; + + while (np) { + if (ep < (u_char *)ext + ntohs(ext->len)) { + printf(" [|%s]", NPSTR(np)); + cp = ep + 1; + break; + } + depth++; + printf("\n"); + for (i = 0; i < depth; i++) + printf(" "); + printf("("); + cp = isakmp_sub0_print(np, ext, ep, phase, doi, proto); + printf(")"); + depth--; + + np = ext->np; + ext = (struct isakmp_gen *)cp; + } + return cp; +} + +static char * +numstr(int x) +{ + static char buf[20]; + sprintf(buf, "#%d", x); + return buf; +} + +void +isakmp_print(const u_char *bp, u_int length, const u_char *bp2) +{ + struct isakmp *base; + u_char *ep; + u_char np; + int i; + int phase; + int major, minor; + + base = (struct isakmp *)bp; + ep = (u_char *)snapend; + + if ((struct isakmp *)ep < base + 1) { + printf("[|isakmp]"); + return; + } + + printf("isakmp"); + 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)); + } + + if (1 < vflag) { + printf(" cookie "); + rawprint((caddr_t)&base->i_ck, sizeof(base->i_ck)); + printf("->"); + rawprint((caddr_t)&base->r_ck, sizeof(base->r_ck)); + } + printf(":"); + + 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); + if (i < 0) { + if (iszero((u_char *)&base->r_ck, sizeof(base->r_ck))) { + /* the first packet */ + printf(" I"); + if (bp2) + cookie_record(&base->i_ck, bp2); + } else + printf(" ?"); + } else { + if (bp2 && cookie_isinitiator(i, bp2)) + printf(" I"); + else if (bp2 && cookie_isresponder(i, bp2)) + printf(" R"); + else + 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(":"); + + { + struct isakmp_gen *ext; + int nparen; + +#define CHECKLEN(p, np) \ + 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; + } + + nparen = 0; + CHECKLEN(base + 1, base->np) + + np = base->np; + ext = (struct isakmp_gen *)(base + 1); + isakmp_sub_print(np, ext, ep, phase, 0, 0); + } + +done: + if (vflag) { + if (ntohl(base->len) != length) { + printf(" (len mismatch: isakmp %u/ip %d)", + (u_int32_t)ntohl(base->len), length); + } + } +} diff --git a/contrib/tcpdump/print-krb.c b/contrib/tcpdump/print-krb.c index eca6265..694e5b5 100644 --- a/contrib/tcpdump/print-krb.c +++ b/contrib/tcpdump/print-krb.c @@ -23,7 +23,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: print-krb.c,v 1.9 97/04/26 14:01:45 leres Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-krb.c,v 1.12 1999/11/21 09:36:55 fenner Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/param.h> diff --git a/contrib/tcpdump/print-l2tp.c b/contrib/tcpdump/print-l2tp.c new file mode 100644 index 0000000..94d7188 --- /dev/null +++ b/contrib/tcpdump/print-l2tp.c @@ -0,0 +1,716 @@ +/* + * Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * L2TP support contributed by Motonori Shindo (mshindo@ascend.co.jp) + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-l2tp.c,v 1.6 1999/12/22 06:27:21 itojun Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdio.h> +#include <sys/types.h> +#include <sys/param.h> +#include <netinet/in.h> +#include <arpa/inet.h> + +#include "l2tp.h" +#include "interface.h" + +static char tstr[] = " [|l2tp]"; + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +static char *l2tp_message_type_string[] = { + "RESERVED_0", /* 0 Reserved */ + "SCCRQ", /* 1 Start-Control-Connection-Request */ + "SCCRP", /* 2 Start-Control-Connection-Reply */ + "SCCCN", /* 3 Start-Control-Connection-Connected */ + "StopCCN", /* 4 Stop-Control-Connection-Notification */ + "RESERVED_5", /* 5 Reserved */ + "HELLO", /* 6 Hello */ + "OCRQ", /* 7 Outgoing-Call-Request */ + "OCRP", /* 8 Outgoing-Call-Reply */ + "OCCN", /* 9 Outgoing-Call-Connected */ + "ICRQ", /* 10 Incoming-Call-Request */ + "ICRP", /* 11 Incoming-Call-Reply */ + "ICCN", /* 12 Incoming-Call-Connected */ + "RESERVED_13", /* 13 Reserved */ + "CDN", /* 14 Call-Disconnect-Notify */ + "WEN", /* 15 WAN-Error-Notify */ + "SLI" /* 16 Set-Link-Info */ +#define L2TP_MAX_MSGTYPE_INDEX 17 +}; + +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 +}; + +#if 0 +static char *l2tp_result_code_StopCCN[] = { + "Reserved", + "General request to clear control connection", + "General error--Error Code indicates the problem", + "Control channel already exists", + "Requester is not authorized to establish a control channel", + "The protocol version of the requester is not supported", + "Requester is being shut down", + "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", + "Call disconnected for the reason indicated in error code", + "Call disconnected for administrative reasons", + "Call failed due to lack of appropriate facilities being " \ + "available (temporary condition)", + "Call failed due to lack of appropriate facilities being " \ + "available (permanent condition)", + "Invalid destination", + "Call failed due to no carrier detected", + "Call failed due to detection of a busy signal", + "Call failed due to lack of a dial tone", + "Call was not established within time allotted by LAC", + "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", + "Length is wrong", + "One of the field values was out of range or " \ + "reserved field was non-zero" + "Insufficient resources to handle this operation now", + "The Session ID is invalid in this context", + "A generic vendor-specific error occurred in the LAC", + "Try another" +#define L2TP_MAX_ERROR_CODE_GENERAL_INDEX 8 +}; +#endif + +/******************************/ +/* generic print out routines */ +/******************************/ +static void +print_string(const u_char *dat, u_int length) +{ + int i; + for (i=0; i<length; i++) { + printf("%c", *dat++); + } +} + +static void +print_octets(const u_char *dat, u_int length) +{ + int i; + for (i=0; i<length; i++) { + printf("%02x", *dat++); + } +} + +static void +print_short(const u_short *dat) +{ + printf("%u", ntohs(*dat)); +} + +static void +print_int(const u_int *dat) +{ + printf("%lu", (u_long)ntohl(*dat)); +} + +/**********************************/ +/* AVP-specific print out routines*/ +/**********************************/ +static void +l2tp_msgtype_print(const u_char *dat, u_int length) +{ + u_short *ptr = (u_short *)dat; + + if (ntohs(*ptr) < L2TP_MAX_MSGTYPE_INDEX) { + printf("%s", l2tp_message_type_string[ntohs(*ptr)]); + } +} + +static void +l2tp_result_code_print(const u_char *dat, u_int length) +{ + /* we just print out the result and error code number */ + u_short *ptr = (u_short *)dat; + + if (length == 2) { /* result code */ + printf("%u", ntohs(*ptr)); + } else if (length == 4) { /* result & error code */ + printf("%u/%u", ntohs(*ptr), ntohs(*(ptr+1))); + } else if (length > 4) { /* result & error code & msg */ + printf("%u/%u ", ntohs(*ptr), ntohs(*(ptr+1))); + print_string((u_char *)(ptr+2), length - 4); + } +} + +static void +l2tp_proto_ver_print(const u_char *dat, u_int length) +{ + printf("%d.%d", *dat, *(dat+1)); +} + + +static void +l2tp_framing_cap_print(const u_char *dat, u_int length) +{ + u_int *ptr = (u_int *)dat; + + if (ntohl(*ptr) & L2TP_FRAMING_CAP_ASYNC_MASK) { + printf("A"); + } + if (ntohl(*ptr) & L2TP_FRAMING_CAP_SYNC_MASK) { + printf("S"); + } +} + +static void +l2tp_bearer_cap_print(const u_char *dat, u_int length) +{ + u_int *ptr = (u_int *)dat; + + if (ntohl(*ptr) & L2TP_BEARER_CAP_ANALOG_MASK) { + printf("A"); + } + if (ntohl(*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]); + 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) +{ + u_int *ptr = (u_int *)dat; + + if (ntohl(*ptr) & L2TP_BEARER_TYPE_ANALOG_MASK) { + printf("A"); + } + if (ntohl(*ptr) & L2TP_BEARER_TYPE_DIGITAL_MASK) { + printf("D"); + } +} + +static void +l2tp_framing_type_print(const u_char *dat, u_int length) +{ + u_int *ptr = (u_int *)dat; + + if (ntohl(*ptr) & L2TP_FRAMING_TYPE_ASYNC_MASK) { + printf("A"); + } + if (ntohl(*ptr) & L2TP_FRAMING_TYPE_SYNC_MASK) { + printf("S"); + } +} + +static void +l2tp_packet_proc_delay_print(const u_char *dat, u_int length) +{ + printf("obsolete"); +} + +static void +l2tp_called_number_print(const u_char *dat, u_int length) +{ + print_string(dat, length); +} + +static void +l2tp_calling_number_print(const u_char *dat, u_int length) +{ + print_string(dat, length); +} + +static void +l2tp_sub_address_print(const u_char *dat, u_int length) +{ + print_string(dat, length); +} + +static void +l2tp_tx_conn_speed_print(const u_char *dat, u_int length) +{ + print_int((u_int *)dat); +} + +static void +l2tp_phy_channel_id_print(const u_char *dat, u_int length) +{ + print_int((u_int *)dat); +} + +static void +l2tp_ini_recv_lcp_print(const u_char *dat, u_int length) +{ + print_octets(dat, length); +} + +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"); + } +} + +static void +l2tp_proxy_auth_name_print(const u_char *dat, u_int length) +{ + print_octets(dat, length); +} + +static void +l2tp_proxy_auth_chal_print(const u_char *dat, u_int length) +{ + print_octets(dat, length); +} + +static void +l2tp_proxy_auth_id_print(const u_char *dat, u_int length) +{ + u_short *ptr = (u_short *)dat; + + printf("%u", ntohs(*ptr) & L2TP_PROXY_AUTH_ID_MASK); +} + +static void +l2tp_proxy_auth_resp_print(const u_char *dat, u_int length) +{ + print_octets(dat, length); +} + +static void +l2tp_call_errors_print(const u_char *dat, u_int length) +{ + struct l2tp_call_errors *ptr = (struct l2tp_call_errors *)dat; + + printf("CRCErr=%d FrameErr=%d HardOver=%d BufOver=%d ", + ptr->crc_errs, + ptr->framing_errs, + ptr->hardware_overruns, + ptr->buffer_overruns); + printf("Timeout=%d AlingErr=%d", + ptr->timeout_errs, + ptr->alignment_errs); +} + +static void +l2tp_accm_print(const u_char *dat, u_int length) +{ + struct l2tp_accm *ptr = (struct l2tp_accm *)dat; + + printf("send=%x recv=%x", ptr->send_accm, ptr->recv_accm); +} + +static void +l2tp_random_vector_print(const u_char *dat, u_int length) +{ + print_octets(dat, length); +} + +static void +l2tp_private_grp_id_print(const u_char *dat, u_int length) +{ + print_string(dat, length); + /* XXX print_octets is more appropriate?? */ +} + +static void +l2tp_rx_conn_speed_print(const u_char *dat, u_int length) +{ + print_int((u_int *)dat); +} + +static void +l2tp_seq_required_print(const u_char *dat, u_int length) +{ + return; +} + +static void +l2tp_avp_print(const u_char *dat, u_int length) +{ + u_int len; + const u_short *ptr = (u_short *)dat; + int hidden = FALSE; + + 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++; + + if (ntohs(*ptr) < L2TP_MAX_AVP_INDEX) { + printf("%s", l2tp_avp[ntohs(*ptr)].name); + printf("("); + if (!hidden) { + (l2tp_avp[ntohs(*ptr)].print) + ((u_char *)ptr+2, len-6); + } else { + printf("???"); + } + printf(")"); + } else { + printf(" invalid AVP %u", ntohs(*ptr)); + } + + l2tp_avp_print(dat + len, length - len); + } else if (length == 0) { + return; + } else { + printf("|..."); + } +} + + +void +l2tp_print(const u_char *dat, u_int length) +{ + const u_short *ptr = (u_short *)dat; + u_int cnt = 0; /* total octets consumed */ + u_short pad; + int flag_t, flag_l, flag_s, flag_o, flag_p; + u_short 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) { + printf(" l2tp:"); + } else if ((ntohs(*ptr) & L2TP_VERSION_MASK) == L2TP_VERSION_L2F) { + printf(" l2f:"); + return; /* nothing to do */ + } else { + printf(" Unknown Version, neither L2F(1) nor L2TP(2)"); + return; /* nothing we can do */ + } + + printf("["); + if (ntohs(*ptr) & L2TP_FLAG_TYPE) { + flag_t = TRUE; + printf("T"); + } + if (ntohs(*ptr) & L2TP_FLAG_LENGTH) { + flag_l = TRUE; + printf("L"); + } + if (ntohs(*ptr) & L2TP_FLAG_SEQUENCE) { + flag_s = TRUE; + printf("S"); + } + if (ntohs(*ptr) & L2TP_FLAG_OFFSET) { + flag_o = TRUE; + printf("O"); + } + if (ntohs(*ptr) & L2TP_FLAG_PRIORITY) { + flag_p = TRUE; + printf("P"); + } + printf("]"); + + ptr++; + cnt += 2; + + if (flag_l) { + l2tp_len = ntohs(*ptr++); /* XXX need to consider + truncation ?? */ + cnt += 2; + } else { + l2tp_len = 0; + } + + printf("(%u/", ntohs(*ptr++)); /* Tunnel ID */ + printf("%u)", ntohs(*ptr++)); /* Session ID */ + cnt += 4; + + if (flag_s) { + printf("Ns=%u,", ntohs(*ptr++)); + printf("Nr=%u", ntohs(*ptr++)); + cnt += 4; + } + + if (flag_o) { + pad = ntohs(*ptr++); + ptr += pad / sizeof(*ptr); + cnt += (2 + pad); + } + + if (flag_t) { + if (length - cnt == 0) { + printf(" ZLB"); + } else { + l2tp_avp_print((u_char *)ptr, length - cnt); + } + } else { +#if 0 + printf(" {"); + ppp_hdlc_print((u_char *)ptr, length - cnt); + printf("}"); +#else + printf("[hdlc|]"); +#endif + } +} diff --git a/contrib/tcpdump/print-lane.c b/contrib/tcpdump/print-lane.c new file mode 100644 index 0000000..19061de --- /dev/null +++ b/contrib/tcpdump/print-lane.c @@ -0,0 +1,148 @@ +/* + * 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[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-lane.c,v 1.2 1999/11/21 09:36:56 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/if_ether.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> +#include <netinet/tcp.h> +#include <netinet/tcpip.h> + +#include <stdio.h> +#include <pcap.h> + +#include "interface.h" +#include "addrtoname.h" +#include "lane.h" + +static const u_char *packetp; +static const u_char *snapend; + +static inline void +lane_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:%d %s %s %d: ", + ntohs(ep->le_header), + etheraddr_string(ep->h_source), + etheraddr_string(ep->h_dest), + length); + else + (void)printf("lecid:%d %s %s %s %d: ", + ntohs(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' is the points + * to the ether header of the packet, 'h->tv' is the timestamp, + * 'h->length' is the length of the packet off the wire, and 'h->caplen' + * is the number of bytes actually captured. + */ +void +lane_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) +{ + int caplen = h->caplen; + int length = h->len; + struct lecdatahdr_8023 *ep; + u_short ether_type; + u_short extracted_ethertype; + + ts_print(&h->ts); + + if (caplen < sizeof(struct lecdatahdr_8023)) { + printf("[|lane]"); + goto out; + } + + if (eflag) + lane_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; + + length -= sizeof(struct lecdatahdr_8023); + caplen -= sizeof(struct lecdatahdr_8023); + ep = (struct lecdatahdr_8023 *)p; + p += sizeof(struct lecdatahdr_8023); + + ether_type = ntohs(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)==0) { + /* ether_type not known, print raw packet */ + if (!eflag) + lane_print((u_char *)ep, length); + 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) == 0) { + /* ether_type not known, print raw packet */ + if (!eflag) + lane_print((u_char *)ep, length + sizeof(*ep)); + if (!xflag && !qflag) + default_print(p, caplen); + } + if (xflag) + default_print(p, caplen); + out: + putchar('\n'); +} diff --git a/contrib/tcpdump/print-lcp.c b/contrib/tcpdump/print-lcp.c new file mode 100644 index 0000000..78f353a --- /dev/null +++ b/contrib/tcpdump/print-lcp.c @@ -0,0 +1,226 @@ +/* + * 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[] = +"@(#) $Header: /tcpdump/master/tcpdump/print-lcp.c,v 1.3 1999/12/15 07:55:42 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/socket.h> + +#if __STDC__ +struct mbuf; +struct rtentry; +#endif +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/if_ether.h> + +#ifdef HAVE_MEMORY_H +#include <memory.h> +#endif +#include <stdio.h> +#include <string.h> + +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" /* must come after interface.h */ +#include "ppp.h" + +/* Codes */ +enum { + LCP_CONFREQ = 1, + LCP_CONFACK = 2, + LCP_CONFNAK = 3, + LCP_CONFREJ = 4, + LCP_TERMREQ = 5, + LCP_TERMACK = 6, + LCP_CODEREJ = 7, + LCP_PROTREJ = 8, + LCP_ECHOREQ = 9, + LCP_ECHOREP = 10, + LCP_DISCARD = 11 +}; + +static struct tok lcpcode2str[] = { + { LCP_CONFREQ, "ConfReq" }, + { LCP_CONFACK, "ConfAck" }, + { LCP_CONFNAK, "ConfNak" }, + { LCP_CONFREJ, "ConfRej" }, + { LCP_TERMREQ, "TermReq" }, + { LCP_TERMACK, "TermAck" }, + { LCP_CODEREJ, "CodeRej" }, + { LCP_PROTREJ, "ProtRej" }, + { LCP_ECHOREQ, "EchoReq" }, + { LCP_ECHOREP, "EchoRep" }, + { LCP_DISCARD, "Discard" }, + { 0, NULL } +}; + + +enum { + LCP_RESERVED = 0, + LCP_MRU = 1, + LCP_ASYNCMAP = 2, + LCP_AUTHPROTO = 3, + LCP_QUALPROTO = 4, + LCP_MAGICNUM = 5, + LCP_PCOMP = 7, + LCP_ACFCOMP = 8, + LCP_CALLBACK = 13 +}; + +static struct tok lcpoption2str[] = { + { LCP_RESERVED, "reserved"}, + { LCP_MRU, "mru"}, + { LCP_ASYNCMAP, "asyncmap"}, + { LCP_AUTHPROTO, "auth"}, + { LCP_QUALPROTO, "qual"}, + { LCP_MAGICNUM, "magic"}, + { LCP_PCOMP, "pcomp"}, + { LCP_ACFCOMP, "acfcomp"}, + { LCP_CALLBACK, "callback"}, + { 0, NULL } +}; + +static struct tok lcpauth2str[] = { + {0xc023, "PAP"}, + {0xc223, "CHAP"}, + { 0, NULL } +}; + +static struct tok lcpqual2str[] = { + {0xc025, "LQR"}, + { 0, NULL } +}; + +static struct tok lcpchap2str[] = { + {0x05, "MD5"}, + {0x80, "MS"}, + { 0, NULL } +}; + +void +lcp_print(register const u_char *bp, u_int length) +{ + u_short lcp_code, lcp_id, lcp_length; + const u_char *lcp_data; + + lcp_data = bp+4; + + if (snapend < lcp_data) { + printf(" [LCP|]"); + return; + } + + lcp_code = bp[0]; + lcp_id = bp[1]; + lcp_length = EXTRACT_16BITS(bp+2); + + printf("LCP %s id=0x%x", tok2str(lcpcode2str, "LCP-#%d", lcp_code), lcp_id); + + switch(lcp_code) { + case LCP_CONFREQ: + case LCP_CONFACK: + case LCP_CONFNAK: + case LCP_CONFREJ: + /* Print Options */ + { + u_char lcpopt_type, lcpopt_length; + const u_char *p=lcp_data; + while (p+2 < lcp_data+lcp_length && p+2 < snapend) { + lcpopt_type = p[0]; + lcpopt_length = p[1]; + p+=2; + printf(" <%s ",tok2str(lcpoption2str, "option-#%d", lcpopt_type)); + if (lcpopt_length) + switch (lcpopt_type) { + case LCP_MRU: + if (snapend < p+2) return; + printf("%d",ntohs(*(u_short*)p)); + if (lcpopt_length != 4) printf(" len=%d!",lcpopt_length); + break; + case LCP_AUTHPROTO: + if (snapend < p+2) return; + printf("%s",tok2str(lcpauth2str, "AUTH-%#x", ntohs(*(u_short*)p))); + if (lcpopt_length < 4) printf(" len=%d!",lcpopt_length); + if (lcpopt_length >= 5 && p < snapend) + printf(" %s",tok2str(lcpchap2str, "%#x", p[0])); + break; + case LCP_QUALPROTO: + if (snapend < p+2) return; + printf("%s",tok2str(lcpqual2str, "QUAL-%#x", ntohs(*(u_short*)p))); + if (lcpopt_length < 4) printf(" len=%d!",lcpopt_length); + /* Print data field of auth? */ + break; + case LCP_ASYNCMAP: + case LCP_MAGICNUM: + if (snapend < p+4) return; + printf("%#x",ntohl(*(u_long*)p)); + if (lcpopt_length != 6) printf(" len=%d!",lcpopt_length); + break; + case LCP_PCOMP: + case LCP_ACFCOMP: + case LCP_RESERVED: + if (lcpopt_length != 2) printf(" len=%d!",lcpopt_length); + break; + default: + if (lcpopt_length != 2) printf(" len=%d",lcpopt_length); + break; + } + printf(">"); + p+=lcpopt_length-2; + } + } + break; + case LCP_ECHOREQ: + case LCP_ECHOREP: + case LCP_DISCARD: + if (snapend < lcp_data+4) return; + printf(" magic=%#x", ntohl(*(u_long *) lcp_data)); + lcp_data +=4; + break; + case LCP_PROTREJ: + if (snapend < lcp_data+2) return; + printf(" prot=%s", tok2str(ppptype2str, "PROT-%#x", ntohs(*(u_short *) lcp_data))); + /* TODO print rejected packet too ? */ + break; + case LCP_CODEREJ: + if (snapend < lcp_data+4) return; + printf(" "); + lcp_print(lcp_data, (lcp_length+lcp_data > snapend ? snapend-lcp_data : lcp_length)); + break; + case LCP_TERMREQ: + case LCP_TERMACK: + break; + default: + break; + } + + return; +} diff --git a/contrib/tcpdump/print-mobile.c b/contrib/tcpdump/print-mobile.c new file mode 100644 index 0000000..4c09ace --- /dev/null +++ b/contrib/tcpdump/print-mobile.c @@ -0,0 +1,143 @@ +/* $NetBSD: print-mobile.c,v 1.2 1998/09/30 08:57:01 hwr Exp $ */ + +/* + * (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Heiko W.Rupp <hwr@pilhuhn.de> + * + * 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[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-mobile.c,v 1.2.2.1 2000/01/11 06:58:26 fenner Exp $"; +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/uio.h> +#include <sys/socket.h> + +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> + +#include <netdb.h> +#include <stdio.h> + +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" /* must come after interface.h */ + +#define MOBILE_SIZE (8) + +struct mobile_ip { + u_int16_t proto; + u_int16_t hcheck; + u_int32_t odst; + u_int32_t osrc; +}; + +#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 + */ +void +mobile_print(const u_char *bp, u_int length) +{ + const u_char *cp = bp +8 ; + const struct mobile_ip *mob; + u_short proto,crc; + u_char osp =0; /* old source address present */ + + mob = (const struct mobile_ip *)bp; + + if (length < MOBILE_SIZE) { + fputs("[|mobile]", stdout); + return; + } + + proto = EXTRACT_16BITS(&mob->proto); + crc = EXTRACT_16BITS(&mob->hcheck); + if (proto & OSRC_PRES) { + osp=1; + cp +=4 ; + } + + if (osp) { + fputs("[S] ",stdout); + if (vflag) + (void)printf("%s ",ipaddr_string(&mob->osrc)); + } else { + fputs("[] ",stdout); + } + if (vflag) { + (void)printf("> %s ",ipaddr_string(&mob->odst)); + (void)printf("(oproto=%d)",proto>>8); + } + if (mob_in_cksum((u_short *)mob, osp ? 12 : 8)!=0) { + (void)printf(" (bad checksum %d)",crc); + } + + return; +} + +static u_int16_t mob_in_cksum(u_short *p, int len) +{ + u_int32_t sum = 0; + int nwords = len >> 1; + + while (nwords-- != 0) + sum += *p++; + + if (len & 1) { + union { + u_int16_t w; + u_int8_t c[2]; + } u; + u.c[0] = *(u_char *)p; + u.c[1] = 0; + sum += u.w; + } + + /* end-around-carry */ + sum = (sum >> 16) + (sum & 0xffff); + sum += (sum >> 16); + return (~sum); +} + diff --git a/contrib/tcpdump/print-netbios.c b/contrib/tcpdump/print-netbios.c index 34cc655..fbf22fb 100644 --- a/contrib/tcpdump/print-netbios.c +++ b/contrib/tcpdump/print-netbios.c @@ -24,7 +24,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: print-netbios.c,v 1.10 96/12/10 23:25:12 leres Exp $"; + "@(#) $Header: /tcpdump/master/tcpdump/print-netbios.c,v 1.13 1999/11/21 09:36:57 fenner Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/param.h> diff --git a/contrib/tcpdump/print-ospf.c b/contrib/tcpdump/print-ospf.c index 3de4ce5..f69eb84 100644 --- a/contrib/tcpdump/print-ospf.c +++ b/contrib/tcpdump/print-ospf.c @@ -23,7 +23,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: print-ospf.c,v 1.24 97/04/26 13:31:46 leres Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ospf.c,v 1.27 1999/11/21 09:36:58 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/param.h> @@ -507,9 +511,11 @@ 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); diff --git a/contrib/tcpdump/print-ospf6.c b/contrib/tcpdump/print-ospf6.c new file mode 100644 index 0000000..f368346 --- /dev/null +++ b/contrib/tcpdump/print-ospf6.c @@ -0,0 +1,668 @@ +/* + * 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. + * + * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu) + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-ospf6.c,v 1.2 1999/11/21 09:36:58 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/socket.h> + +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_var.h> + +#include <ctype.h> +#include <stdio.h> +#include <string.h> + +#include "interface.h" +#include "addrtoname.h" + +#include "ospf6.h" + +struct bits { + u_int32_t bit; + const char *str; +}; + +static const struct bits ospf6_option_bits[] = { + { OSPF6_OPTION_V6, "V6" }, + { OSPF6_OPTION_E, "E" }, + { OSPF6_OPTION_MC, "MC" }, + { OSPF6_OPTION_N, "N" }, + { OSPF6_OPTION_R, "R" }, + { OSPF6_OPTION_DC, "DC" }, + { 0, NULL } +}; + +static const struct bits ospf6_rla_flag_bits[] = { + { RLA_FLAG_B, "B" }, + { RLA_FLAG_E, "E" }, + { RLA_FLAG_V, "V" }, + { RLA_FLAG_W, "W" }, + { 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" }, + { 0, NULL } +}; + +static char tstr[] = " [|ospf]"; + +/* Forwards */ +static inline void ospf6_print_seqage(u_int32_t, time_t); +static inline void ospf6_print_bits(const struct bits *, u_char); +static void ospf6_print_ls_type(u_int, const rtrid_t *, + const rtrid_t *, const char *); +static int ospf6_print_lshdr(const struct lsa_hdr *); +static int ospf6_print_lsa(const struct lsa *); +static int ospf6_decode_v3(const struct ospf6hdr *, const u_char *); + +static inline void +ospf6_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 +ospf6_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 void +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; + + switch (ls_type & LS_SCOPE_MASK) { + case LS_SCOPE_LINKLOCAL: + scope = "linklocal-"; + break; + case LS_SCOPE_AREA: + scope = "area-"; + break; + case LS_SCOPE_AS: + scope = "AS-"; + break; + default: + scope = ""; + break; + } + + switch (ls_type & LS_TYPE_MASK) { + case LS_TYPE_ROUTER: + printf(" %srtr %s", scope, ipaddr_string(ls_router)); + break; + + case LS_TYPE_NETWORK: + printf(" %snet dr %s if %s", scope, + ipaddr_string(ls_router), + ipaddr_string(ls_stateid)); + break; + + case LS_TYPE_INTER_AP: + printf(" %sinter-area-prefix %s abr %s", scope, + ipaddr_string(ls_stateid), + ipaddr_string(ls_router)); + break; + + case LS_TYPE_INTER_AR: + printf(" %sinter-area-router %s rtr %s", scope, + ipaddr_string(ls_router), + ipaddr_string(ls_stateid)); + break; + + case LS_TYPE_ASE: + printf(" %sase %s asbr %s", scope, + ipaddr_string(ls_stateid), + ipaddr_string(ls_router)); + break; + + case LS_TYPE_GROUP: + printf(" %sgroup %s rtr %s", scope, + ipaddr_string(ls_stateid), + ipaddr_string(ls_router)); + break; + + case LS_TYPE_TYPE7: + printf(" %stype7 %s rtr %s", scope, + ipaddr_string(ls_stateid), + ipaddr_string(ls_router)); + break; + + case LS_TYPE_LINK: + printf(" %slink %s rtr %s", scope, + ipaddr_string(ls_stateid), + ipaddr_string(ls_router)); + break; + + case LS_TYPE_INTRA_AP: + printf(" %sintra-area-prefix %s rtr %s", scope, + ipaddr_string(ls_stateid), + ipaddr_string(ls_router)); + break; + + default: + printf(" %s", scope); + printf(fmt, ls_type); + break; + } + +} + +static int +ospf6_print_lshdr(register const struct lsa_hdr *lshp) +{ + + TCHECK(lshp->ls_type); + 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, + &lshp->ls_router, "ls_type %d"); + + return (0); +trunc: + return (1); +} + +static int +ospf6_print_lsaprefix(register const struct lsa_prefix *lsapp) +{ + int k; + struct in6_addr prefix; + + TCHECK(*lsapp); + k = (lsapp->lsa_p_len + 31) / 32; + if (k * 4 > sizeof(struct in6_addr)) { + printf("??prefixlen %d??", lsapp->lsa_p_len); + goto trunc; + } + memset(&prefix, 0, sizeof(prefix)); + memcpy(&prefix, lsapp->lsa_p_prefix, k * 4); + printf(" %s/%d", ip6addr_string(&prefix), + lsapp->lsa_p_len); + if (lsapp->lsa_p_opt) + printf("(opt=%x)", lsapp->lsa_p_opt); + return sizeof(*lsapp) - 4 + k * 4; + +trunc: + return -1; +} + + +/* + * Print a single link state advertisement. If truncated return 1, else 0. + */ +static int +ospf6_print_lsa(register const struct lsa *lsap) +{ + register const u_char *ls_end; + register const struct rlalink *rlp; +#if 0 + register const struct tos_metric *tosp; +#endif + register const rtrid_t *ap; +#if 0 + register const struct aslametric *almp; + register const struct mcla *mcp; +#endif + register const struct llsa *llsap; + register const struct lsa_prefix *lsapp; +#if 0 + register const u_int32_t *lp; +#endif + register int j, k; + + 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)) { + 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)); + + TCHECK(lsap->lsa_un.un_rla.rla_link); + rlp = lsap->lsa_un.un_rla.rla_link; + while (rlp + sizeof(*rlp) <= (struct rlalink *)ls_end) { + TCHECK(*rlp); + printf(" {"); /* } (ctags) */ + switch (rlp->link_type) { + + case RLA_TYPE_VIRTUAL: + printf(" virt"); + /* Fall through */ + + case RLA_TYPE_ROUTER: + printf(" nbrid %s nbrif %s if %s", + ipaddr_string(&rlp->link_nrtid), + ipaddr_string(&rlp->link_nifid), + ipaddr_string(&rlp->link_ifid)); + break; + + case RLA_TYPE_TRANSIT: + printf(" dr %s drif %s if %s", + ipaddr_string(&rlp->link_nrtid), + ipaddr_string(&rlp->link_nifid), + ipaddr_string(&rlp->link_ifid)); + break; + + default: + /* { (ctags) */ + printf(" ??RouterLinksType 0x%02x?? }", + rlp->link_type); + return (0); + } + printf(" metric %d", ntohs(rlp->link_metric)); + /* { (ctags) */ + printf(" }"); + rlp++; + } + break; + + 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)); + printf(" rtrs"); + ap = lsap->lsa_un.un_nla.nla_router; + while ((u_char *)ap < ls_end) { + TCHECK(*ap); + printf(" %s", ipaddr_string(ap)); + ++ap; + } + break; + + 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); + 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) + goto trunc; + lsapp = (struct lsa_prefix *)(((u_char *)lsapp) + k); + } + break; + +#if 0 + case LS_TYPE_SUM_ABR: + TCHECK(lsap->lsa_un.un_sla.sla_tosmetric); + lp = lsap->lsa_un.un_sla.sla_tosmetric; + while ((u_char *)lp < ls_end) { + register u_int32_t ul; + + TCHECK(*lp); + ul = ntohl(*lp); + printf(" tos %d metric %d", + (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS, + ul & SLA_MASK_METRIC); + ++lp; + } + 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)) { + + case MCLA_VERTEX_ROUTER: + printf(" rtr rtrid %s", + ipaddr_string(&mcp->mcla_vid)); + break; + + case MCLA_VERTEX_NETWORK: + printf(" net dr %s", + ipaddr_string(&mcp->mcla_vid)); + break; + + default: + printf(" ??VertexType %u??", + (u_int32_t)ntohl(mcp->mcla_vtype)); + break; + } + ++mcp; + } +#endif + + case LS_TYPE_LINK: + /* Link LSA */ + llsap = &lsap->lsa_un.un_llsa; + TCHECK(llsap->llsa_options); + ospf6_print_bits(ospf6_option_bits, ntohl(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)); + lsapp = llsap->llsa_prefix; + for (j = 0; j < ntohl(llsap->llsa_nprefix); j++) { + k = ospf6_print_lsaprefix(lsapp); + if (k < 0) + goto trunc; + lsapp = (struct lsa_prefix *)(((u_char *)lsapp) + k); + } + break; + + case LS_TYPE_INTRA_AP | LS_SCOPE_AREA: + /* 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), + &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)); + + 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++) { + k = ospf6_print_lsaprefix(lsapp); + if (k < 0) + goto trunc; + lsapp = (struct lsa_prefix *)(((u_char *)lsapp) + k); + } + break; + + default: + printf(" ??LinkStateType 0x%04x??", + ntohs(lsap->ls_hdr.ls_type)); + } + + /* { (ctags) */ + fputs(" }", stdout); + return (0); +trunc: + fputs(" }", stdout); + return (1); +} + +static int +ospf6_decode_v3(register const struct ospf6hdr *op, + register const u_char *dataend) +{ + register const rtrid_t *ap; + register const struct lsr *lsrp; + register const struct lsa_hdr *lshp; + register const struct lsa *lsap; + register char sep; + register int i; + + switch (op->ospf6_type) { + + case OSPF_TYPE_UMD: + /* + * Rob Coltun's special monitoring packets; + * do nothing + */ + break; + + case OSPF_TYPE_HELLO: + if (vflag) { + TCHECK(op->ospf6_hello.hello_deadint); + ospf6_print_bits(ospf6_option_bits, + ntohl(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)); + } + TCHECK(op->ospf6_hello.hello_dr); + if (op->ospf6_hello.hello_dr != 0) + printf(" dr %s", + ipaddr_string(&op->ospf6_hello.hello_dr)); + TCHECK(op->ospf6_hello.hello_bdr); + if (op->ospf6_hello.hello_bdr != 0) + printf(" bdr %s", + ipaddr_string(&op->ospf6_hello.hello_bdr)); + if (vflag) { + printf(" nbrs"); + ap = op->ospf6_hello.hello_neighbor; + while ((u_char *)ap < dataend) { + TCHECK(*ap); + printf(" %s", ipaddr_string(ap)); + ++ap; + } + } + break; /* HELLO */ + + case OSPF_TYPE_DB: + TCHECK(op->ospf6_db.db_options); + ospf6_print_bits(ospf6_option_bits, + ntohl(op->ospf6_db.db_options)); + sep = ' '; + TCHECK(op->ospf6_db.db_flags); + if (op->ospf6_db.db_flags & OSPF6_DB_INIT) { + printf("%cI", sep); + sep = '/'; + } + if (op->ospf6_db.db_flags & OSPF6_DB_MORE) { + printf("%cM", sep); + sep = '/'; + } + if (op->ospf6_db.db_flags & OSPF6_DB_MASTER) { + printf("%cMS", sep); + 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)); + + if (vflag) { + /* Print all the LS adv's */ + lshp = op->ospf6_db.db_lshdr; + + while (!ospf6_print_lshdr(lshp)) { + /* { (ctags) */ + printf(" }"); + ++lshp; + } + } + break; + + case OSPF_TYPE_LSR: + if (vflag) { + lsrp = op->ospf6_lsr; + while ((u_char *)lsrp < dataend) { + TCHECK(*lsrp); + printf(" {"); /* } (ctags) */ + ospf6_print_ls_type(ntohs(lsrp->ls_type), + &lsrp->ls_stateid, + &lsrp->ls_router, + "LinkStateType %d"); + /* { (ctags) */ + printf(" }"); + ++lsrp; + } + } + break; + + case OSPF_TYPE_LSU: + if (vflag) { + lsap = op->ospf6_lsu.lsu_lsa; + TCHECK(op->ospf6_lsu.lsu_count); + i = ntohl(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)); + } + } + break; + + + case OSPF_TYPE_LSA: + if (vflag) { + lshp = op->ospf6_lsa.lsa_lshdr; + + while (!ospf6_print_lshdr(lshp)) { + /* { (ctags) */ + printf(" }"); + ++lshp; + } + } + break; + + default: + printf("v3 type %d", op->ospf6_type); + break; + } + return (0); +trunc: + return (1); +} + +void +ospf6_print(register const u_char *bp, register u_int length) +{ + register const struct ospf6hdr *op; + register const u_char *dataend; + register const char *cp; + + op = (struct ospf6hdr *)bp; + + /* If the type is valid translate it, or just print the type */ + /* 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); + if (*cp == 't') + return; + + TCHECK(op->ospf6_len); + if (length != ntohs(op->ospf6_len)) { + printf(" [len %d]", ntohs(op->ospf6_len)); + return; + } + dataend = bp + length; + + /* Print the routerid if it is not the same as the source */ + TCHECK(op->ospf6_routerid); + printf(" rtrid %s", ipaddr_string(&op->ospf6_routerid)); + + TCHECK(op->ospf6_areaid); + if (op->ospf6_areaid != 0) + printf(" area %s", ipaddr_string(&op->ospf6_areaid)); + else + printf(" backbone"); + TCHECK(op->ospf6_instanceid); + if (op->ospf6_instanceid) + printf(" instance %u", op->ospf6_instanceid); + + /* Do rest according to version. */ + switch (op->ospf6_version) { + + case 3: + /* ospf version 3 */ + if (ospf6_decode_v3(op, dataend)) + goto trunc; + break; + + default: + printf(" ospf [version %d]", op->ospf6_version); + break; + } /* end switch on version */ + + return; +trunc: + fputs(tstr, stdout); +} diff --git a/contrib/tcpdump/print-pim.c b/contrib/tcpdump/print-pim.c index 9b52ef8..5a3bdd0 100644 --- a/contrib/tcpdump/print-pim.c +++ b/contrib/tcpdump/print-pim.c @@ -21,7 +21,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: print-pim.c,v 1.7 96/09/26 23:36:48 leres Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-pim.c,v 1.15.2.1 2000/01/25 18:29:05 itojun Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/param.h> @@ -31,11 +35,26 @@ static const char rcsid[] = #include <netinet/in.h> #include <netinet/in_systm.h> #include <netinet/ip.h> -#include <netinet/ip_var.h> -#include <netinet/udp.h> -#include <netinet/udp_var.h> -#include <netinet/tcp.h> -#include <netinet/tcpip.h> + +/* + * XXX: We consider a case where IPv6 is not ready yet for portability, + * but PIM dependent defintions should be independent of IPv6... + */ + +struct pim { + u_int8_t pim_typever; + /* upper 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 + */ + /* lower 4bit: PIM version number; 2 for PIMv2 */ +#define PIM_TYPE(x) (((x) & 0xf0) >> 4) +#define PIM_VER(x) ((x) & 0x0f) + u_char pim_rsv; /* Reserved */ + u_short pim_cksum; /* IP style check sum */ +}; + #include <stdio.h> #include <stdlib.h> @@ -43,9 +62,86 @@ static const char rcsid[] = #include "interface.h" #include "addrtoname.h" +#include "extract.h" + +static void pimv2_print(register const u_char *bp, register u_int len); + +static void +pimv1_join_prune_print(register const u_char *bp, register u_int len) +{ + int maddrlen, addrlen, ngroups, njoin, nprune; + int njp; + + /* If it's a single group and a single source, use 1-line output. */ + if (TTEST2(bp[0], 30) && bp[11] == 1 && + ((njoin = EXTRACT_16BITS(&bp[20])) + EXTRACT_16BITS(&bp[22])) == 1) { + int hold; + + (void)printf(" RPF %s ", ipaddr_string(bp)); + hold = EXTRACT_16BITS(&bp[6]); + if (hold != 180) { + (void)printf("Hold "); + relts_print(hold); + } + (void)printf("%s (%s/%d, %s", njoin ? "Join" : "Prune", + ipaddr_string(&bp[26]), bp[25] & 0x3f, + ipaddr_string(&bp[12])); + if (EXTRACT_32BITS(&bp[16]) != 0xffffffff) + (void)printf("/%s", ipaddr_string(&bp[16])); + (void)printf(") %s%s %s", + (bp[24] & 0x01) ? "Sparse" : "Dense", + (bp[25] & 0x80) ? " WC" : "", + (bp[25] & 0x40) ? "RP" : "SPT"); + return; + } + + TCHECK2(bp[0], 4); + (void)printf("\n Upstream Nbr: %s", ipaddr_string(bp)); + TCHECK2(bp[6], 2); + (void)printf("\n Hold time: "); + relts_print(EXTRACT_16BITS(&bp[6])); + bp += 8; len -= 8; + + TCHECK2(bp[0], 4); + maddrlen = bp[1]; + addrlen = bp[2]; + ngroups = bp[3]; + bp += 4; len -= 4; + while (ngroups--) { + TCHECK2(bp[0], 4); + (void)printf("\n\tGroup: %s", ipaddr_string(bp)); + if (EXTRACT_32BITS(&bp[4]) != 0xffffffff) + (void)printf("/%s", ipaddr_string(&bp[4])); + TCHECK2(bp[8], 4); + njoin = EXTRACT_16BITS(&bp[8]); + nprune = EXTRACT_16BITS(&bp[10]); + (void)printf(" joined: %d pruned: %d", njoin, nprune); + bp += 12; len -= 12; + for (njp = 0; njp < (njoin + nprune); njp++) { + char *type; + + if (njp < njoin) { + type = "Join "; + } else { + type = "Prune"; + } + TCHECK2(bp[0], 6); + (void)printf("\n\t%s %s%s%s%s/%d", type, + (bp[0] & 0x01) ? "Sparse " : "Dense ", + (bp[1] & 0x80) ? "WC " : "", + (bp[1] & 0x40) ? "RP " : "SPT ", + ipaddr_string(&bp[2]), bp[1] & 0x3f); + bp += 6; len -= 6; + } + } + return; +trunc: + (void)printf("[|pim]"); + return; +} void -pim_print(register const u_char *bp, register u_int len) +pimv1_print(register const u_char *bp, register u_int len) { register const u_char *ep; register u_char type; @@ -59,34 +155,87 @@ pim_print(register const u_char *bp, register u_int len) 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 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: @@ -97,4 +246,694 @@ pim_print(register const u_char *bp, register u_int len) (void)printf(" [type %d]", type); break; } + if ((bp[4] >> 4) != 1) + (void)printf(" [v%d]", bp[4] >> 4); + return; + +trunc: + (void)printf("[|pim]"); + return; +} + +/* + * auto-RP is a cisco protocol, documented at + * ftp://ftpeng.cisco.com/ipmulticast/pim-autorp-spec01.txt + */ +void +cisco_autorp_print(register const u_char *bp, register u_int len) +{ + int type; + int numrps; + int hold; + + TCHECK(bp[0]); + (void)printf(" auto-rp "); + type = bp[0]; + switch (type) { + case 0x11: + (void)printf("candidate-advert"); + break; + case 0x12: + (void)printf("mapping"); + break; + default: + (void)printf("type-0x%02x", type); + break; + } + + TCHECK(bp[1]); + numrps = bp[1]; + + TCHECK2(bp[2], 2); + (void)printf(" Hold "); + hold = EXTRACT_16BITS(&bp[2]); + if (hold) + relts_print(EXTRACT_16BITS(&bp[2])); + else + printf("FOREVER"); + + /* Next 4 bytes are reserved. */ + + bp += 8; len -= 8; + + /*XXX skip unless -v? */ + + /* + * Rest of packet: + * numrps entries of the form: + * 32 bits: RP + * 6 bits: reserved + * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2". + * 8 bits: # of entries for this RP + * each entry: 7 bits: reserved, 1 bit: negative, + * 8 bits: mask 32 bits: source + * lather, rinse, repeat. + */ + while (numrps--) { + int nentries; + char s; + + 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; + } + TCHECK(bp[5]); + nentries = bp[5]; + bp += 6; len -= 6; + s = ' '; + for (; nentries; nentries--) { + TCHECK2(bp[0], 6); + (void)printf("%c%s%s/%d", s, bp[0] & 1 ? "!" : "", + ipaddr_string(&bp[2]), bp[1]); + s = ','; + bp += 6; len -= 6; + } + } + return; + +trunc: + (void)printf("[|autorp]"); + return; +} + +void +pim_print(register const u_char *bp, register u_int len) +{ + register const u_char *ep; + register struct pim *pim = (struct pim *)bp; + + ep = (const u_char *)snapend; + if (bp >= ep) + return; +#ifdef notyet /* currently we see only version and type */ + TCHECK(pim->pim_rsv); +#endif + + switch(PIM_VER(pim->pim_typever)) { + case 2: /* avoid hardcoding? */ + (void)printf("v2"); + pimv2_print(bp, len); + break; + default: + (void)printf("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) +{ + int af; + char *afstr; + int len, hdrlen; + + TCHECK(bp[0]); + + if (pimv2_addr_len == 0) { + TCHECK(bp[1]); + switch (bp[0]) { + case 1: + af = AF_INET; + afstr = "IPv4"; + len = 4; + break; +#ifdef INET6 + case 2: + af = AF_INET6; + afstr = "IPv6"; + len = 16; + 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 + 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) { + if (!silent) + (void)printf("%s", ipaddr_string(bp)); + } +#ifdef INET6 + else if (af == AF_INET6) { + if (!silent) + (void)printf("%s", ip6addr_string(bp)); + } +#endif + return hdrlen + len; + case pimv2_group: + case pimv2_source: + TCHECK2(bp[0], len + 2); + if (af == AF_INET) { + 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) { + if (!silent) { + (void)printf("%s", ip6addr_string(bp + 2)); + if (bp[1] != 128) + (void)printf("/%u", bp[1]); + } + } +#endif + 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 hdrlen + 2 + len; + default: + return -1; + } +trunc: + return -1; +} + +static void +pimv2_print(register const u_char *bp, register u_int len) +{ + register const u_char *ep; + register struct pim *pim = (struct pim *)bp; + int advance; + + ep = (const u_char *)snapend; + if (bp >= ep) + return; + TCHECK(pim->pim_rsv); + pimv2_addr_len = pim->pim_rsv; + if (pimv2_addr_len != 0) + (void)printf("[RFC2117-encoding] "); + + switch (PIM_TYPE(pim->pim_typever)) { + case 0: + { + u_int16_t otype, olen; + (void)printf(" Hello"); + bp += 4; + while (bp < ep) { + 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; + + /* XXX + * draft-ietf-idmr-pimv2-dr-priority-00.txt + * says that DR-Priority is option 19. + * draft-ietf-pim-v2-sm-00.txt says it's 18. + */ + case 18: /* DR-Priority */ + (void)printf(" (DR-Priority: %d)", EXTRACT_32BITS(&bp[4])); + break; + + case 19: /* Bidir-Capable */ + if (olen == 4) + (void)printf(" (OLD-DR-Priority: %d)", EXTRACT_32BITS(&bp[4])); + else + (void)printf(" (bidir-capable)"); + break; + + case 20: + (void)printf(" (Genid: 0x%08x)", EXTRACT_32BITS(&bp[4])); + break; + + case 21: + (void)printf(" (State Refresh Capable"); + if (EXTRACT_32BITS(&bp[4]) != 1) { + (void)printf(" ?0x%x?", EXTRACT_32BITS(&bp[4])); + } + (void)printf(")"); + break; + + default: + if (vflag) + (void)printf(" [Hello option %d]", otype); + } + bp += 4 + olen; + } + break; + } + + case 1: + { + struct ip *ip; + + (void)printf(" Register"); + if (vflag && bp + 8 <= ep) { + (void)printf(" %s%s", bp[4] & 0x80 ? "B" : "", + bp[4] & 0x40 ? "N" : ""); + } + bp += 8; len -= 8; + + /* encapsulated multicast packet */ + if (bp >= ep) + break; + ip = (struct ip *)bp; + switch(ip->ip_v) { + case 4: /* IPv4 */ + printf(" "); + ip_print(bp, len); + break; +#ifdef INET6 + case 6: /* IPv6 */ + printf(" "); + ip6_print(bp, len); + break; +#endif + default: + (void)printf(" IP ver %d", ip->ip_v); + break; + } + break; + } + + case 2: + (void)printf(" Register-Stop"); + bp += 4; len -= 4; + if (bp >= ep) + break; + (void)printf(" group="); + if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) { + (void)printf("..."); + break; + } + bp += advance; len -= advance; + if (bp >= ep) + break; + (void)printf(" source="); + if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) { + (void)printf("..."); + break; + } + bp += advance; len -= advance; + break; + + case 3: + case 6: + case 7: + { + u_int8_t ngroup; + u_int16_t holdtime; + u_int16_t njoin; + u_int16_t nprune; + int i, j; + + switch (PIM_TYPE(pim->pim_typever)) { + case 3: + (void)printf(" Join/Prune"); + break; + case 6: + (void)printf(" Graft"); + break; + case 7: + (void)printf(" Graft-ACK"); + break; + } + bp += 4; len -= 4; + if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/ + if (bp >= ep) + break; + (void)printf(" upstream-neighbor="); + if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) { + (void)printf("..."); + break; + } + bp += advance; len -= advance; + } + if (bp + 4 > ep) + break; + ngroup = bp[1]; + holdtime = EXTRACT_16BITS(&bp[2]); + (void)printf(" groups=%u", ngroup); + if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/ + (void)printf(" holdtime="); + if (holdtime == 0xffff) + (void)printf("infty"); + else + relts_print(holdtime); + } + bp += 4; len -= 4; + for (i = 0; i < ngroup; i++) { + if (bp >= ep) + goto jp_done; + (void)printf(" (group%d: ", i); + if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) { + (void)printf("...)"); + goto jp_done; + } + bp += advance; len -= advance; + if (bp + 4 > ep) { + (void)printf("...)"); + goto jp_done; + } + 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++) { + (void)printf(" "); + if ((advance = pimv2_addr_print(bp, pimv2_source, 0)) < 0) { + (void)printf("...)"); + goto jp_done; + } + bp += advance; len -= advance; + } + (void)printf(" prune=%u", nprune); + for (j = 0; j < nprune; j++) { + (void)printf(" "); + if ((advance = pimv2_addr_print(bp, pimv2_source, 0)) < 0) { + (void)printf("...)"); + goto jp_done; + } + bp += advance; len -= advance; + } + (void)printf(")"); + } + jp_done: + break; + } + + case 4: + { + int i, j, frpcnt; + + (void)printf(" Bootstrap"); + bp += 4; + + /* Fragment Tag, Hash Mask len, and BSR-priority */ + if (bp + sizeof(u_int16_t) >= ep) break; + (void)printf(" tag=%x", EXTRACT_16BITS(bp)); + bp += sizeof(u_int16_t); + if (bp >= ep) break; + (void)printf(" hashmlen=%d", bp[0]); + if (bp + 1 >= ep) break; + (void)printf(" BSRprio=%d", bp[1]); + bp += 2; + + /* Encoded-Unicast-BSR-Address */ + if (bp >= ep) break; + (void)printf(" BSR="); + if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) { + (void)printf("..."); + break; + } + bp += advance; + + for (i = 0; bp < ep; i++) { + /* Encoded-Group Address */ + (void)printf(" (group%d: ", i); + if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) + < 0) { + (void)printf("...)"); + goto bs_done; + } + bp += advance; + + /* RP-Count, Frag RP-Cnt, and rsvd */ + if (bp >= ep) { + (void)printf("...)"); + goto bs_done; + } + (void)printf(" RPcnt=%d", frpcnt = bp[0]); + if (bp + 1 >= ep) { + (void)printf("...)"); + goto bs_done; + } + (void)printf(" FRPcnt=%d", bp[1]); + bp += 4; + + for (j = 0; j < frpcnt && bp < ep; j++) { + /* each RP info */ + (void)printf(" RP%d=", j); + if ((advance = pimv2_addr_print(bp, + pimv2_unicast, + 0)) < 0) { + (void)printf("...)"); + goto bs_done; + } + bp += advance; + + if (bp + 1 >= ep) { + (void)printf("...)"); + goto bs_done; + } + (void)printf(",holdtime="); + relts_print(EXTRACT_16BITS(bp)); + if (bp + 2 >= ep) { + (void)printf("...)"); + goto bs_done; + } + (void)printf(",prio=%d", bp[2]); + bp += 4; + } + (void)printf(")"); + } + bs_done: + break; + } + case 5: + (void)printf(" Assert"); + bp += 4; len -= 4; + if (bp >= ep) + break; + (void)printf(" group="); + if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) { + (void)printf("..."); + break; + } + bp += advance; len -= advance; + if (bp >= ep) + break; + (void)printf(" src="); + if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) { + (void)printf("..."); + break; + } + bp += advance; len -= advance; + if (bp + 8 > ep) + break; + if (bp[0] & 0x80) + (void)printf(" RPT"); + (void)printf(" pref=%u", EXTRACT_32BITS(&bp[0]) & 0x7fffffff); + (void)printf(" metric=%u", EXTRACT_32BITS(&bp[4])); + break; + + case 8: + { + int i, pfxcnt; + + (void)printf(" Candidate-RP-Advertisement"); + bp += 4; + + /* Prefix-Cnt, Priority, and Holdtime */ + if (bp >= ep) break; + (void)printf(" prefix-cnt=%d", bp[0]); + pfxcnt = bp[0]; + if (bp + 1 >= ep) break; + (void)printf(" prio=%d", bp[1]); + if (bp + 3 >= ep) break; + (void)printf(" holdtime="); + relts_print(EXTRACT_16BITS(&bp[2])); + bp += 4; + + /* Encoded-Unicast-RP-Address */ + if (bp >= ep) break; + (void)printf(" RP="); + if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) { + (void)printf("..."); + break; + } + bp += advance; + + /* Encoded-Group Addresses */ + for (i = 0; i < pfxcnt && bp < ep; i++) { + (void)printf(" Group%d=", i); + if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) + < 0) { + (void)printf("..."); + break; + } + 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_TYPE(pim->pim_typever)); + break; + } + + return; + +trunc: + (void)printf("[|pim]"); } diff --git a/contrib/tcpdump/print-pppoe.c b/contrib/tcpdump/print-pppoe.c new file mode 100644 index 0000000..1aaa0da --- /dev/null +++ b/contrib/tcpdump/print-pppoe.c @@ -0,0 +1,224 @@ +/* + * 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[] = +"@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.3 1999/12/15 00:23:06 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/socket.h> + +#if __STDC__ +struct mbuf; +struct rtentry; +#endif +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/if_ether.h> + +#ifdef HAVE_MEMORY_H +#include <memory.h> +#endif +#include <stdio.h> +#include <string.h> + +#include "interface.h" +#include "addrtoname.h" +#include "ppp.h" +#include "ethertype.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 + +void +pppoe_print(register const u_char *bp, u_int length) +{ + register const struct ether_header *eh; + register u_short pppoe_ver, pppoe_type, pppoe_code, pppoe_sessionid, pppoe_length; + const u_char *pppoe_packet, *pppoe_payload; + + eh = (struct ether_header *)packetp; + pppoe_packet = packetp+sizeof(struct ether_header); + if (pppoe_packet > snapend) { + printf("[|pppoe]"); + return; + } + + pppoe_ver = (pppoe_packet[0]&0xF0)>>4; + pppoe_type = (pppoe_packet[0]&0x0F); + pppoe_code = (pppoe_packet[1]); + pppoe_sessionid = (EXTRACT_16BITS(pppoe_packet+2)); + pppoe_length = (EXTRACT_16BITS(pppoe_packet+4)); + pppoe_payload = pppoe_packet+6; + + if (snapend < pppoe_payload) { + printf(" truncated PPPoE"); + return; + } + + if (pppoe_ver != 1) { + printf(" [ver %d]",pppoe_ver); + } + if (pppoe_type != 1) { + printf(" [type %d]",pppoe_type); + } + + printf("PPPoE %s", tok2str(pppoecode2str, "PAD-%x", pppoe_code)); + if (pppoe_code == PPPOE_PADI && pppoe_length > 1484-PPPOE_HDRLEN) { + printf(" [len %d!]",pppoe_length); + } + if (pppoe_sessionid) { + printf(" [ses 0x%x]",pppoe_sessionid); + } + + if (pppoe_payload + pppoe_length < snapend) { + /* + printf(" [length %d (%d extra bytes)]", pppoe_length, snapend-pppoe_payload-pppoe_length); + { + const u_char *x = pppoe_payload+pppoe_length; + default_print(x, snapend - x); + } + */ + snapend = pppoe_payload+pppoe_length; + } + + + if (pppoe_code) { + /* PPP session packets don't contain tags */ + u_short tag_type = -1, tag_len; + const u_char *p = pppoe_payload; + + /* loop invariant: + p points to next tag, + tag_type is previous tag or -1 for first iteration + */ + while (tag_type && + p+4 < pppoe_payload + length && + p+4 < snapend) { + tag_type = EXTRACT_16BITS(p); + tag_len = EXTRACT_16BITS(p+2); + p += 4; + /* p points to tag_value */ + + if (tag_len) { + int isascii = 1; + const u_char *v = p; + + for (v=p; v<p+tag_len; v++) + if (*v >= 127 || *v < 32) { + isascii = 0; + break; + } + + /* TODO print UTF8 decoded text */ + if (isascii) + printf(" [%s \"%*.*s\"]", + tok2str(pppoetag2str, "TAG-0x%x", tag_type), + tag_len < 80 ? tag_len : 80, + tag_len < 80 ? tag_len : 80, + p + ); + else + printf(" [%s UTF8]", tok2str(pppoetag2str, "TAG-0x%x", tag_type)); + } else + printf(" [%s]", tok2str(pppoetag2str, "TAG-0x%x", tag_type)); + + p += tag_len; + /* p points to next tag */ + } + } else { + u_short ptype; + if (pppoe_payload[0] & 0x1) { + ptype = pppoe_payload[0]; + pppoe_payload +=1; + pppoe_length -=1; + } else if (pppoe_payload[1] & 0x1) { + ptype = ntohs(*(u_short *)pppoe_payload); + pppoe_payload +=2; + pppoe_length -=2; + } else { + printf(" Invalid PPP protocol ID: %x %x", pppoe_payload[0],pppoe_payload[1]); + return; + } + printf(" "); + if (ptype == PPP_IP) + ip_print(pppoe_payload, pppoe_length); + else if (ptype == PPP_LCP) + lcp_print(pppoe_payload, pppoe_length); + else + printf("%s ", tok2str(ppptype2str, "proto-0x%x", ptype)); + } + return; +} diff --git a/contrib/tcpdump/print-raw.c b/contrib/tcpdump/print-raw.c index 3628955..114ff09 100644 --- a/contrib/tcpdump/print-raw.c +++ b/contrib/tcpdump/print-raw.c @@ -21,7 +21,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: print-raw.c,v 1.22 96/12/10 23:18:58 leres Locked $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-raw.c,v 1.25 1999/11/21 09:37:00 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/param.h> @@ -44,7 +48,6 @@ struct rtentry; #include <netinet/udp.h> #include <netinet/udp_var.h> #include <netinet/tcp.h> -#include <netinet/tcpip.h> #include <pcap.h> #include <stdio.h> diff --git a/contrib/tcpdump/print-rip.c b/contrib/tcpdump/print-rip.c index 4daf6e2..72e6cfb 100644 --- a/contrib/tcpdump/print-rip.c +++ b/contrib/tcpdump/print-rip.c @@ -21,7 +21,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: print-rip.c,v 1.36 96/11/29 01:22:50 leres Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-rip.c,v 1.40 1999/11/22 04:24:28 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/param.h> @@ -100,8 +104,10 @@ rip_print(const u_char *dat, u_int length) register int i, j, trunc; i = min(length, snapend - dat) - sizeof(*rp); - if (i < 0) + if (i < 0) { + printf(" [|rip]"); return; + } rp = (struct rip *)dat; switch (rp->rip_cmd) { @@ -116,7 +122,7 @@ rip_print(const u_char *dat, u_int length) printf(" rip-resp %d[%d]:", j, length); else printf(" rip-resp %d:", j); - trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); + trunc = (i / sizeof(*ni)) != j; ni = (struct rip_netinfo *)(rp + 1); for (; (i -= sizeof(*ni)) >= 0; ++ni) rip_entry_print(rp->rip_vers, ni); diff --git a/contrib/tcpdump/print-ripng.c b/contrib/tcpdump/print-ripng.c new file mode 100644 index 0000000..7a4aee6 --- /dev/null +++ b/contrib/tcpdump/print-ripng.c @@ -0,0 +1,127 @@ +/* + * Copyright (c) 1989, 1990, 1991, 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: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-ripng.c,v 1.2.2.1 2000/01/11 06:58:26 fenner Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef INET6 + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> + +#include <errno.h> +#include <stdio.h> + +#include <netinet/ip6.h> + +#include "route6d.h" +#include "interface.h" +#include "addrtoname.h" + +static int +rip6_entry_print(register const struct netinfo6 *ni, int metric) +{ + int l; + l = printf("%s/%d", ip6addr_string(&ni->rip6_dest), ni->rip6_plen); + if (ni->rip6_tag) + l += printf(" [%d]", ntohs(ni->rip6_tag)); + if (metric) + l += printf(" (%d)", ni->rip6_metric); + return l; +} + +void +ripng_print(const u_char *dat, 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)); + int j; + int trunc; + + if (i < 0) + return; + + switch (rp->rip6_cmd) { + + case RIP6_REQUEST: + j = length / sizeof(*ni); + if (j == 1 + && rp->rip6_nets->rip6_metric == HOPCNT_INFINITY6 + && IN6_IS_ADDR_UNSPECIFIED(&rp->rip6_nets->rip6_dest)) { + printf(" ripng-req dump"); + break; + } + if (j * sizeof(*ni) != length - 4) + printf(" ripng-req %d[%d]:", j, length); + else + printf(" ripng-req %d:", j); + trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); + for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) { + if (vflag) + 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); + else + printf(" ripng-resp %d:", j); + trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); + for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) { + if (vflag) + printf("\n\t"); + else + printf(" "); + rip6_entry_print(ni, ni->rip6_metric); + } + if (trunc) + printf("[|rip]"); + break; + default: + printf(" ripng-%d ?? %d", rp->rip6_cmd, length); + break; + } + if (rp->rip6_vers != RIP6_VERSION) + printf(" [vers %d]", rp->rip6_vers); +} +#endif /* INET6 */ diff --git a/contrib/tcpdump/print-rt6.c b/contrib/tcpdump/print-rt6.c new file mode 100644 index 0000000..f8a7fcb --- /dev/null +++ b/contrib/tcpdump/print-rt6.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 1988, 1989, 1990, 1991, 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: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-rt6.c,v 1.3.2.1 2000/01/11 06:58:26 fenner Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef INET6 + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/if_ether.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_icmp.h> +#include <netinet/ip_var.h> +#include <netinet/udp.h> +#include <netinet/udp_var.h> +#include <netinet/tcp.h> + +#include <stdio.h> + +#include <netinet/ip6.h> + +#include "interface.h" +#include "addrtoname.h" + +int +rt6_print(register const u_char *bp, register const u_char *bp2) +{ + register const struct ip6_rthdr *dp; + register const struct ip6_rthdr0 *dp0; + register const struct ip6_hdr *ip; + register const u_char *ep; + int i, len; + + dp = (struct ip6_rthdr *)bp; + ip = (struct ip6_hdr *)bp2; + len = dp->ip6r_len; + + /* 'ep' points to the end of avaible data. */ + ep = snapend; + + printf("%s > %s: ", + ip6addr_string(&ip->ip6_src), + ip6addr_string(&ip->ip6_dst)); + + 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) { + case IPV6_RTHDR_TYPE_0: + dp0 = (struct ip6_rthdr0 *)dp; + + TCHECK(dp0->ip6r0_reserved); + if (dp0->ip6r0_reserved || vflag) { + printf("rsv=0x%0x, ", + (u_int32_t)ntohl(dp0->ip6r0_reserved)); + } + + if (len % 2 == 1) + goto trunc; + len >>= 1; + for (i = 0; i < len; i++) { + struct in6_addr *addr; + + addr = ((struct in6_addr *)(dp0 + 1)) + i; + if ((u_char *)addr > ep - sizeof(*addr)) + goto trunc; + + printf("[%d]%s", i, ip6addr_string((u_char *)addr)); + if (i != len - 1) + printf(", "); + + } + printf(")"); + return((dp0->ip6r0_len + 1) << 3); + break; + default: + goto trunc; + break; + } + + trunc: + fputs("[|srcrt]", stdout); + return 65535; /* XXX */ +} +#endif /* INET6 */ diff --git a/contrib/tcpdump/print-rx.c b/contrib/tcpdump/print-rx.c new file mode 100644 index 0000000..5f42ce7 --- /dev/null +++ b/contrib/tcpdump/print-rx.c @@ -0,0 +1,2190 @@ +/* + * 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 <kenh@cmf.nrl.navy.mil> + * + */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-rx.c,v 1.5.2.1 2000/01/11 06:58:27 fenner Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdio.h> +#include <string.h> +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <arpa/inet.h> + +#include "interface.h" +#include "addrtoname.h" + +#undef NOERROR /* Solaris sucks */ +#include <arpa/nameser.h> + +#include "rx.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 tok rx_flags[] = { + { RX_CLIENT_INITIATED, "client-init" }, + { RX_REQUEST_ACK, "req-ack" }, + { RX_LAST_PACKET, "last-pckt" }, + { RX_MORE_PACKETS, "more-pckts" }, + { RX_FREE_PACKET, "free-pckt" } +}; + +static struct 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" }, + { 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" }, + { 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" }, + { 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" }, + { 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" }, + { 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 char *voltype[] = { "read-write", "read-only", "backup" }; + +/* + * 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, 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 *, 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 *, int); +static void ubik_reply_print(const u_char *, int, int32_t); + +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 < 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 > 1) { + int firstflag = 0; + printf(" cid %08x call# %d seq %d ser %d", + (int) ntohl(rxh->cid), + (int) ntohl(rxh->callNumber), + (int) ntohl(rxh->seq), + (int) ntohl(rxh->serial)); + if (vflag > 2) + printf(" secindex %d serviceid %hu", + (int) rxh->securityIndex, + ntohs(rxh->serviceId)); + for (i = 0; i < NUM_RX_FLAGS; i++) { + if (rxh->flags & rx_flags[i].v) { + 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 && ntohl(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, length); + + 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 && + ntohl(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: + ; + } + } + + + 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, + int length) +{ + struct rx_cache_entry *rxent; + const struct rx_header *rxh = (const struct rx_header *) bp; + + if (snapend - bp + 1 <= 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 = ntohl(*((int *) (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 TRUNC(n) if (snapend - bp + 1 <= n) goto trunc; +#define FIDOUT() { unsigned long n1, n2, n3; \ + TRUNC(sizeof(int32_t) * 3); \ + n1 = ntohl(*((int *) bp)); \ + bp += sizeof(int32_t); \ + n2 = ntohl(*((int *) bp)); \ + bp += sizeof(int32_t); \ + n3 = ntohl(*((int *) bp)); \ + bp += sizeof(int32_t); \ + printf(" fid %d/%d/%d", (int) n1, (int) n2, (int) n3); \ + } + +#define STROUT(MAX) { int i; \ + TRUNC(sizeof(int32_t)); \ + i = (int) ntohl(*((int *) bp)); \ + bp += sizeof(int32_t); \ + TRUNC(i); \ + strncpy(s, bp, min(MAX, i)); \ + s[i] = '\0'; \ + printf(" \"%s\"", s); \ + bp += ((i + sizeof(int32_t) - 1) / sizeof(int32_t)) * sizeof(int32_t); \ + } + +#define INTOUT() { int i; \ + TRUNC(sizeof(int32_t)); \ + i = (int) ntohl(*((int *) bp)); \ + bp += sizeof(int32_t); \ + printf(" %d", i); \ + } + +#define UINTOUT() { unsigned long i; \ + TRUNC(sizeof(int32_t)); \ + i = ntohl(*((int *) bp)); \ + bp += sizeof(int32_t); \ + printf(" %lu", i); \ + } + +#define DATEOUT() { time_t t; struct tm *tm; char str[256]; \ + TRUNC(sizeof(int32_t)); \ + t = (time_t) ntohl(*((int *) 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; \ + TRUNC((sizeof(int32_t)*6)); \ + mask = ntohl(*((int *) bp)); bp += sizeof(int32_t); \ + if (mask) printf (" StoreStatus"); \ + if (mask & 1) { printf(" date"); DATEOUT(); } \ + else bp += sizeof(int32_t); \ + i = ntohl(*((int *) bp)); bp += sizeof(int32_t); \ + if (mask & 2) printf(" owner %lu", i); \ + i = ntohl(*((int32_t *) bp)); bp += sizeof(int32_t); \ + if (mask & 4) printf(" group %lu", i); \ + i = ntohl(*((int32_t *) bp)); bp += sizeof(int32_t); \ + if (mask & 8) printf(" mode %lo", i & 07777); \ + i = ntohl(*((int32_t *) 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; \ + TRUNC(sizeof(int32_t) * 2); \ + epoch = ntohl(*((int *) bp)); \ + bp += sizeof(int32_t); \ + counter = ntohl(*((int *) bp)); \ + bp += sizeof(int32_t); \ + printf(" %d.%d", epoch, counter); \ + } + +#define AFSUUIDOUT() {u_int32_t temp; int i; \ + TRUNC(11*sizeof(u_int32_t)); \ + temp = ntohl(*((int *) bp)); \ + bp += sizeof(u_int32_t); \ + printf(" %08x", temp); \ + temp = ntohl(*((int *) bp)); \ + bp += sizeof(u_int32_t); \ + printf("%04x", temp); \ + temp = ntohl(*((int *) bp)); \ + bp += sizeof(u_int32_t); \ + printf("%04x", temp); \ + for (i = 0; i < 8; i++) { \ + temp = ntohl(*((int *) bp)); \ + bp += sizeof(u_int32_t); \ + printf("%02x", (unsigned char) temp); \ + } \ + } + +/* + * This is the sickest one of all + */ + +#define VECOUT(MAX) { char *sp; \ + int k; \ + TRUNC(MAX * sizeof(int32_t)); \ + sp = s; \ + for (k = 0; k < MAX; k++) { \ + *sp++ = (char) ntohl(*((int *) bp)); \ + bp += sizeof(int32_t); \ + } \ + s[MAX] = '\0'; \ + printf(" \"%s\"", s); \ + } + +/* + * Handle calls to the AFS file service (fs) + */ + +void +fs_print(register const u_char *bp, int length) +{ + int fs_op; + unsigned long i; + char s[AFSNAMEMAX]; + + if (length <= sizeof(struct rx_header)) + return; + + if (snapend - bp + 1 <= 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 = ntohl(*((int *) (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]; + FIDOUT(); + TRUNC(4); + i = ntohl(*((int *) bp)); + bp += sizeof(int32_t); + TRUNC(i); + strncpy(a, bp, min(AFSOPAQUEMAX, i)); + a[i] = '\0'; + acl_print((u_char *) 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; + TRUNC(4); + j = ntohl(*((int *) bp)); + bp += sizeof(int32_t); + + for (i = 0; i < j; i++) { + FIDOUT(); + if (i != j - 1) + printf(","); + } + if (j == 0) + printf(" <none!>"); + } + 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; + char s[AFSNAMEMAX]; + struct rx_header *rxh; + + if (length <= 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]; + TRUNC(4); + i = ntohl(*((int *) bp)); + bp += sizeof(int32_t); + TRUNC(i); + strncpy(a, bp, min(AFSOPAQUEMAX, i)); + a[i] = '\0'; + acl_print((u_char *) 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 { + /* + * Otherwise, just print out the return code + */ + printf(" errcode"); + INTOUT(); + } + + return; + +trunc: + printf(" [|fs]"); +} + +/* + * Print out an AFS ACL string. An AFS ACL is a string that has the + * following format: + * + * <positive> <negative> + * <uid1> <aclbits1> + * .... + * + * "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, u_char *end) +{ + int pos, neg, acl; + int n, i; + char user[128]; + + if (sscanf((char *) s, "%d %d\n%n", &pos, &neg, &n) != 2) + return; + + s += n; + + if (s > end) + return; + + /* + * 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) + return; + s += n; + printf(" +{%s ", user); + ACLOUT(acl); + printf("}"); + if (s > end) + return; + } + + for (i = 0; i < neg; i++) { + if (sscanf((char *) s, "%s %d\n%n", user, &acl, &n) != 2) + return; + s += n; + printf(" -{%s ", user); + ACLOUT(acl); + printf("}"); + if (s > end) + 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 <= sizeof(struct rx_header)) + return; + + if (snapend - bp + 1 <= 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 = ntohl(*((int *) (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; + TRUNC(4); + j = ntohl(*((int *) bp)); + bp += sizeof(int32_t); + + for (i = 0; i < j; i++) { + FIDOUT(); + if (i != j - 1) + printf(","); + } + + if (j == 0) + printf(" <none!>"); + + j = ntohl(*((int *) bp)); + bp += sizeof(int32_t); + + if (j != 0) + printf(";"); + + for (i = 0; i < j; i++) { + printf(" ver"); + INTOUT(); + printf(" expires"); + DATEOUT(); + TRUNC(4); + t = ntohl(*((int *) 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 <= 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; + char s[AFSNAMEMAX]; + int pt_op; + + if (length <= sizeof(struct rx_header)) + return; + + if (snapend - bp + 1 <= 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 = ntohl(*((int *) (bp + sizeof(struct rx_header)))); + + printf(" pt"); + + if (is_ubik(pt_op)) { + ubik_print(bp, length); + 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; + TRUNC(4); + j = ntohl(*((int *) 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(" <none!>"); + } + break; + case 505: /* Id to name */ + { + unsigned long j; + printf(" ids:"); + TRUNC(4); + i = ntohl(*((int *) bp)); + bp += sizeof(int32_t); + for (j = 0; j < i; j++) + INTOUT(); + if (j == 0) + printf(" <none!>"); + } + 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; + char s[AFSNAMEMAX]; + + if (length < 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:"); + TRUNC(4); + i = ntohl(*((int *) bp)); + bp += sizeof(int32_t); + for (j = 0; j < i; j++) + INTOUT(); + if (j == 0) + printf(" <none!>"); + } + break; + case 505: /* ID to name */ + { + unsigned long j; + TRUNC(4); + j = ntohl(*((int *) 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(" <none!>"); + } + 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; + TRUNC(4); + j = ntohl(*((int *) bp)); + bp += sizeof(int32_t); + for (i = 0; i < j; i++) { + INTOUT(); + } + if (j == 0) + printf(" <none!>"); + } + 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; + char s[AFSNAMEMAX]; + + if (length <= sizeof(struct rx_header)) + return; + + if (snapend - bp + 1 <= 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 = ntohl(*((int *) (bp + sizeof(struct rx_header)))); + + printf(" vldb"); + + if (is_ubik(vldb_op)) { + ubik_print(bp, length); + 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(); + TRUNC(sizeof(int32_t)); + i = ntohl(*((int *) 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(); + TRUNC(sizeof(int32_t)); + i = ntohl(*((int *) 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; + char s[AFSNAMEMAX]; + + if (length < 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); + TRUNC(sizeof(int32_t)); + bp += sizeof(int32_t); + printf(" numservers"); + TRUNC(sizeof(int32_t)); + nservers = ntohl(*((int *) bp)); + bp += sizeof(int32_t); + printf(" %lu", nservers); + printf(" servers"); + for (i = 0; i < 8; i++) { + TRUNC(sizeof(int32_t)); + if (i < nservers) + printf(" %s", + inet_ntoa(*((struct in_addr *) bp))); + bp += sizeof(int32_t); + } + printf(" partitions"); + for (i = 0; i < 8; i++) { + TRUNC(sizeof(int32_t)); + j = ntohl(*((int *) bp)); + if (i < nservers && j <= 26) + printf(" %c", 'a' + (int)j); + else if (i < nservers) + printf(" %lu", j); + bp += sizeof(int32_t); + } + TRUNC(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"); + TRUNC(sizeof(int32_t)); + nservers = ntohl(*((int *) bp)); + bp += sizeof(int32_t); + printf(" %lu", nservers); + printf(" servers"); + for (i = 0; i < 13; i++) { + TRUNC(sizeof(int32_t)); + if (i < nservers) + printf(" %s", + inet_ntoa(*((struct in_addr *) bp))); + bp += sizeof(int32_t); + } + printf(" partitions"); + for (i = 0; i < 13; i++) { + TRUNC(sizeof(int32_t)); + j = ntohl(*((int *) bp)); + if (i < nservers && j <= 26) + printf(" %c", 'a' + (int)j); + else if (i < nservers) + printf(" %lu", j); + bp += sizeof(int32_t); + } + TRUNC(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"); + TRUNC(sizeof(int32_t)); + nservers = ntohl(*((int *) bp)); + bp += sizeof(int32_t); + printf(" %lu", nservers); + printf(" servers"); + for (i = 0; i < 13; i++) { + if (i < nservers) { + printf(" afsuuid"); + AFSUUIDOUT(); + } else { + TRUNC(44); + bp += 44; + } + } + TRUNC(4 * 13); + bp += 4 * 13; + printf(" partitions"); + for (i = 0; i < 13; i++) { + TRUNC(sizeof(int32_t)); + j = ntohl(*((int *) bp)); + if (i < nservers && j <= 26) + printf(" %c", 'a' + (int)j); + else if (i < nservers) + printf(" %lu", j); + bp += sizeof(int32_t); + } + TRUNC(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; + char s[AFSNAMEMAX]; + + if (length <= sizeof(struct rx_header)) + return; + + if (snapend - bp + 1 <= 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 = ntohl(*((int *) (bp + sizeof(struct rx_header)))); + + printf(" kauth"); + + if (is_ubik(kauth_op)) { + ubik_print(bp, length); + 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); + TRUNC(sizeof(int32_t)); + i = (int) ntohl(*((int *) bp)); + bp += sizeof(int32_t); + TRUNC(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 <= 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 <= sizeof(struct rx_header)) + return; + + if (snapend - bp + 1 <= 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 = ntohl(*((int *) (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 <= 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; + char s[BOSNAMEMAX]; + + if (length <= sizeof(struct rx_header)) + return; + + if (snapend - bp + 1 <= 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 = ntohl(*((int *) (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 <= 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 length) +{ + 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 = ntohl(*((int *) (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 */ + TRUNC(4); + temp = ntohl(*((int *) 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 = ntohl(*((int *) 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 < 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]"); +} diff --git a/contrib/tcpdump/print-smb.c b/contrib/tcpdump/print-smb.c new file mode 100644 index 0000000..0a14f59 --- /dev/null +++ b/contrib/tcpdump/print-smb.c @@ -0,0 +1,1008 @@ +/* + 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[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-smb.c,v 1.3.2.1 2000/01/11 06:58:27 fenner Exp $"; +#endif + +#include <stdio.h> +#include <string.h> +#include <sys/types.h> + +#include "interface.h" +#include "smb.h" + +static int request=0; + +const uchar *startbuf=NULL; + +struct smbdescript +{ + char *req_f1; + char *req_f2; + char *rep_f1; + char *rep_f2; + void (*fn)(); /* sometimes (u_char *, u_char *, u_char *, u_char *) + and sometimes (u_char *, u_char *, int, int) */ +}; + +struct smbfns +{ + int id; + char *name; + int flags; + struct smbdescript descript; +}; + +#define DEFDESCRIPT {NULL,NULL,NULL,NULL,NULL} + +#define FLG_CHAIN (1<<0) + +static struct smbfns *smbfind(int id,struct smbfns *list) +{ + int sindex; + + for (sindex=0;list[sindex].name;sindex++) + if (list[sindex].id == id) return(&list[sindex]); + + return(&list[0]); +} + +static void trans2_findfirst(uchar *param,uchar *data,int pcnt,int dcnt) +{ + char *fmt; + + if (request) { + fmt = "Attribute=[A]\nSearchCount=[d]\nFlags=[w]\nLevel=[dP5]\nFile=[S]\n"; + } else { + fmt = "Handle=[w]\nCount=[d]\nEOS=[w]\nEoffset=[d]\nLastNameOfs=[w]\n"; + } + + fdata(param,fmt,param+pcnt); + if (dcnt) { + printf("data:\n"); + print_data(data,dcnt); + } +} + +static void trans2_qfsinfo(uchar *param,uchar *data,int pcnt,int dcnt) +{ + static int level=0; + char *fmt=""; + + if (request) { + level = SVAL(param,0); + fmt = "InfoLevel=[d]\n"; + fdata(param,fmt,param+pcnt); + } else { + switch (level) { + case 1: + fmt = "idFileSystem=[W]\nSectorUnit=[D]\nUnit=[D]\nAvail=[D]\nSectorSize=[d]\n"; + break; + case 2: + fmt = "CreationTime=[T2]VolNameLength=[B]\nVolumeLabel=[s12]\n"; + break; + case 0x105: + fmt = "Capabilities=[W]\nMaxFileLen=[D]\nVolNameLen=[D]\nVolume=[S]\n"; + break; + default: + fmt = "UnknownLevel\n"; + } + fdata(data,fmt,data+dcnt); + } + if (dcnt) { + printf("data:\n"); + print_data(data,dcnt); + } +} + +struct smbfns trans2_fns[] = { +{0,"TRANSACT2_OPEN",0, + {"Flags2=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]\nOFun=[w]\nSize=[D]\nRes=([w,w,w,w,w])\nPath=[S]",NULL, + "Handle=[d]\nAttrib=[A]\nTime=[T2]\nSize=[D]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nInode=[W]\nOffErr=[d]\n|EALength=[d]\n",NULL,NULL}}, + +{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(uchar *words,uchar *dat,uchar *buf,uchar *maxbuf) +{ + static struct smbfns *fn = &trans2_fns[0]; + uchar *data,*param; + uchar *f1=NULL,*f2=NULL; + int pcnt,dcnt; + + if (request) { + fn = smbfind(SVAL(words+1,14*2),trans2_fns); + data = buf+SVAL(words+1,12*2); + param = buf+SVAL(words+1,10*2); + pcnt = SVAL(words+1,9*2); + dcnt = SVAL(words+1,11*2); + } else { + data = buf+SVAL(words+1,7*2); + param = buf+SVAL(words+1,4*2); + pcnt = SVAL(words+1,3*2); + dcnt = SVAL(words+1,6*2); + } + + printf("%s param_length=%d data_length=%d\n", + fn->name,pcnt,dcnt); + + if (request) { + if (CVAL(words,0) == 8) { + fdata(words+1,"Trans2Secondary\nTotParam=[d]\nTotData=[d]\nParamCnt=[d]\nParamOff=[d]\nParamDisp=[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nHandle=[d]\n",maxbuf); + return; + } else { + fdata(words+1,"TotParam=[d]\nTotData=[d]\nMaxParam=[d]\nMaxData=[d]\nMaxSetup=[d]\nFlags=[w]\nTimeOut=[D]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nDataCnt=[d]\nDataOff=[d]\nSetupCnt=[d]\n",words+1+14*2); + fdata(data+1,"TransactionName=[S]\n%",maxbuf); + } + f1 = fn->descript.req_f1; + f2 = fn->descript.req_f2; + } else { + if (CVAL(words,0) == 0) { + printf("Trans2Interim\n"); + return; + } else { + fdata(words+1,"TotParam=[d]\nTotData=[d]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nParamDisp[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nSetupCnt=[d]\n",words+1+10*2); + } + f1 = fn->descript.rep_f1; + f2 = fn->descript.rep_f2; + } + + if (fn->descript.fn) { + fn->descript.fn(param,data,pcnt,dcnt); + } else { + fdata(param,f1?f1:(uchar*)"Paramaters=\n",param+pcnt); + fdata(data,f2?f2:(uchar*)"Data=\n",data+dcnt); + } +} + + +static void print_browse(uchar *param,int paramlen,const uchar *data,int datalen) +{ + const uchar *maxbuf = data + datalen; + int command = CVAL(data,0); + + fdata(param,"BROWSE PACKET\n|Param ",param+paramlen); + + switch (command) { + case 0xF: + data = fdata(data,"BROWSE PACKET:\nType=[B] (LocalMasterAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",maxbuf); + break; + + case 0x1: + data = fdata(data,"BROWSE PACKET:\nType=[B] (HostAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",maxbuf); + break; + + case 0x2: + data = fdata(data,"BROWSE PACKET:\nType=[B] (AnnouncementRequest)\nFlags=[B]\nReplySystemName=[S]\n",maxbuf); + break; + + case 0xc: + data = fdata(data,"BROWSE PACKET:\nType=[B] (WorkgroupAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nCommentPointer=[W]\nServerName=[S]\n",maxbuf); + break; + + case 0x8: + data = fdata(data,"BROWSE PACKET:\nType=[B] (ElectionFrame)\nElectionVersion=[B]\nOSSummary=[W]\nUptime=[(W,W)]\nServerName=[S]\n",maxbuf); + break; + + case 0xb: + data = fdata(data,"BROWSE PACKET:\nType=[B] (BecomeBackupBrowser)\nName=[S]\n",maxbuf); + break; + + case 0x9: + data = fdata(data,"BROWSE PACKET:\nType=[B] (GetBackupList)\nListCount?=[B]\nToken?=[B]\n",maxbuf); + break; + + case 0xa: + data = fdata(data,"BROWSE PACKET:\nType=[B] (BackupListResponse)\nServerCount?=[B]\nToken?=[B]*Name=[S]\n",maxbuf); + break; + + case 0xd: + data = fdata(data,"BROWSE PACKET:\nType=[B] (MasterAnnouncement)\nMasterName=[S]\n",maxbuf); + break; + + case 0xe: + data = fdata(data,"BROWSE PACKET:\nType=[B] (ResetBrowser)\nOptions=[B]\n",maxbuf); + break; + + default: + data = fdata(data,"Unknown Browser Frame ",maxbuf); + break; + } +} + + +static void print_ipc(uchar *param,int paramlen,uchar *data,int datalen) +{ + if (paramlen) + fdata(param,"Command=[w]\nStr1=[S]\nStr2=[S]\n",param+paramlen); + if (datalen) + fdata(data,"IPC ",data+datalen); +} + + +static void print_trans(uchar *words,uchar *data1,uchar *buf,uchar *maxbuf) +{ + uchar *f1,*f2,*f3,*f4; + uchar *data,*param; + int datalen,paramlen; + + if (request) { + paramlen = SVAL(words+1,9*2); + param = buf + SVAL(words+1,10*2); + datalen = SVAL(words+1,11*2); + data = buf + SVAL(words+1,12*2); + f1 = "TotParamCnt=[d] \nTotDataCnt=[d] \nMaxParmCnt=[d] \nMaxDataCnt=[d]\nMaxSCnt=[d] \nTransFlags=[w] \nRes1=[w] \nRes2=[w] \nRes3=[w]\nParamCnt=[d] \nParamOff=[d] \nDataCnt=[d] \nDataOff=[d] \nSUCnt=[d]\n"; + f2 = "|Name=[S]\n"; + f3 = "|Param "; + f4 = "|Data "; + } else { + paramlen = SVAL(words+1,3*2); + param = buf + SVAL(words+1,4*2); + datalen = SVAL(words+1,6*2); + data = buf + SVAL(words+1,7*2); + f1 = "TotParamCnt=[d] \nTotDataCnt=[d] \nRes1=[d]\nParamCnt=[d] \nParamOff=[d] \nRes2=[d] \nDataCnt=[d] \nDataOff=[d] \nRes3=[d]\nLsetup=[d]\n"; + f2 = "|Unknown "; + f3 = "|Param "; + f4 = "|Data "; + } + + fdata(words+1,f1,MIN(words+1+2*CVAL(words,0),maxbuf)); + fdata(data1+2,f2,maxbuf - (paramlen + datalen)); + + if (!strcmp(data1+2,"\\MAILSLOT\\BROWSE")) { + print_browse(param,paramlen,data,datalen); + return; + } + + if (!strcmp(data1+2,"\\PIPE\\LANMAN")) { + print_ipc(param,paramlen,data,datalen); + return; + } + + if (paramlen) fdata(param,f3,MIN(param+paramlen,maxbuf)); + if (datalen) fdata(data,f4,MIN(data+datalen,maxbuf)); +} + + + +static void print_negprot(uchar *words,uchar *data,uchar *buf,uchar *maxbuf) +{ + uchar *f1=NULL,*f2=NULL; + + if (request) { + f2 = "*|Dialect=[Z]\n"; + } else { + if (CVAL(words,0) == 1) { + f1 = "Core Protocol\nDialectIndex=[d]"; + } else if (CVAL(words,0) == 17) { + f1 = "NT1 Protocol\nDialectIndex=[d]\nSecMode=[B]\nMaxMux=[d]\nNumVcs=[d]\nMaxBuffer=[D]\nRawSize=[D]\nSessionKey=[W]\nCapabilities=[W]\nServerTime=[T3]TimeZone=[d]\nCryptKey="; + } else if (CVAL(words,0) == 13) { + f1 = "Coreplus/Lanman1/Lanman2 Protocol\nDialectIndex=[d]\nSecMode=[w]\nMaxXMit=[d]\nMaxMux=[d]\nMaxVcs=[d]\nBlkMode=[w]\nSessionKey=[W]\nServerTime=[T1]TimeZone=[d]\nRes=[W]\nCryptKey="; + } + } + + if (f1) + fdata(words+1,f1,MIN(words + 1 + CVAL(words,0)*2,maxbuf)); + else + print_data(words+1,MIN(CVAL(words,0)*2,PTR_DIFF(maxbuf,words+1))); + + if (f2) + fdata(data+2,f2,MIN(data + 2 + SVAL(data,0),maxbuf)); + else + print_data(data+2,MIN(SVAL(data,0),PTR_DIFF(maxbuf,data+2))); + +} + +static void print_sesssetup(uchar *words,uchar *data,uchar *buf,uchar *maxbuf) +{ + int wcnt = CVAL(words,0); + uchar *f1=NULL,*f2=NULL; + + 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 (CVAL(words,0) == 3) { + f1 = "Com2=[w]\nOff2=[d]\nAction=[w]\n"; + } else if (CVAL(words,0) == 13) { + f1 = "Com2=[B]\nRes=[B]\nOff2=[d]\nAction=[w]\n"; + f2 = "NativeOS=[S]\nNativeLanMan=[S]\nPrimaryDomain=[S]\n"; + } + } + + if (f1) + fdata(words+1,f1,MIN(words + 1 + CVAL(words,0)*2,maxbuf)); + else + print_data(words+1,MIN(CVAL(words,0)*2,PTR_DIFF(maxbuf,words+1))); + + if (f2) + fdata(data+2,f2,MIN(data + 2 + SVAL(data,0),maxbuf)); + else + print_data(data+2,MIN(SVAL(data,0),PTR_DIFF(maxbuf,data+2))); +} + + +static 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}}, + +{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"}}, + +{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}}, + +{SMBntcancel,"SMBntcancel", 0, DEFDESCRIPT}, + +{-1,NULL,0,DEFDESCRIPT}}; + + +/******************************************************************* +print a SMB message +********************************************************************/ +static void print_smb(const uchar *buf, const uchar *maxbuf) +{ + int command; + const uchar *words, *data; + struct smbfns *fn; + char *fmt_smbheader = +"[P4]SMB Command = [B]\nError class = [BP1]\nError code = [d]\nFlags1 = [B]\nFlags2 = [B][P13]\nTree ID = [d]\nProc ID = [d]\nUID = [d]\nMID = [d]\nWord Count = [b]\n"; + + request = (CVAL(buf,9)&0x80)?0:1; + + command = CVAL(buf,4); + + fn = smbfind(command,smb_fns); + + printf("\nSMB PACKET: %s (%s)\n",fn->name,request?"REQUEST":"REPLY"); + + if (vflag == 0) return; + + /* print out the header */ + fdata(buf,fmt_smbheader,buf+33); + + if (CVAL(buf,5)) { + int class = CVAL(buf,5); + int num = SVAL(buf,7); + printf("SMBError = %s\n",smb_errstr(class,num)); + } + + words = buf+32; + data = words + 1 + CVAL(words,0)*2; + + + while (words && data) + { + char *f1,*f2; + int wct = CVAL(words,0); + + if (request) { + f1 = fn->descript.req_f1; + f2 = fn->descript.req_f2; + } else { + f1 = fn->descript.rep_f1; + f2 = fn->descript.rep_f2; + } + + if (fn->descript.fn) { + fn->descript.fn(words,data,buf,maxbuf); + } else { + if (f1) { + printf("smbvwv[]=\n"); + fdata(words+1,f1,words + 1 + wct*2); + } else if (wct) { + int i; + int v; + printf("smbvwv[]=\n"); + for (i=0;i<wct;i++) { + v = SVAL(words+1,2*i); + printf("smb_vwv[%d]=%d (0x%X)\n",i,v,v); + } + } + + if (f2) { + printf("smbbuf[]=\n"); + fdata(data+2,f2,maxbuf); + } else { + int bcc = SVAL(data,0); + printf("smb_bcc=%d\n",bcc); + if (bcc>0) { + printf("smb_buf[]=\n"); + print_data(data + 2, MIN(bcc,PTR_DIFF(maxbuf,data+2))); + } + } + } + + if ((fn->flags & FLG_CHAIN) && CVAL(words,0) && SVAL(words,1)!=0xFF) { + command = SVAL(words,1); + words = buf + SVAL(words,3); + data = words + 1 + CVAL(words,0)*2; + + fn = smbfind(command,smb_fns); + + printf("\nSMB PACKET: %s (%s) (CHAINED)\n",fn->name,request?"REQUEST":"REPLY"); + } else { + words = data = NULL; + } + } + + printf("\n"); +} + + +/* + print a NBT packet received across tcp on port 139 +*/ +void nbt_tcp_print(const uchar *data,int length) +{ + const uchar *maxbuf = data + length; + int flags = CVAL(data,0); + int nbt_len = RSVAL(data,2); + + startbuf = data; + if (maxbuf <= data) return; + + printf("\n>>> NBT Packet\n"); + + switch (flags) { + case 1: + printf("flags=0x%x\n", flags); + case 0: + data = fdata(data,"NBT Session Packet\nFlags=[rw]\nLength=[rd]\n",data+4); + if (memcmp(data,"\377SMB",4)==0) { + if (nbt_len>PTR_DIFF(maxbuf,data)) + printf("WARNING: Short packet. Try increasing the snap length (%ld)\n", + PTR_DIFF(maxbuf,data)); + print_smb(data,maxbuf>data+nbt_len?data+nbt_len:maxbuf); + } else { + printf("Session packet:(raw data?)\n"); + } + break; + + case 0x81: + data = fdata(data,"NBT Session Request\nFlags=[rW]\nDestination=[n1]\nSource=[n1]\n",maxbuf); + break; + + case 0x82: + data = fdata(data,"NBT Session Granted\nFlags=[rW]\n",maxbuf); + break; + + case 0x83: + { + int ecode = CVAL(data,4); + data = fdata(data,"NBT SessionReject\nFlags=[rW]\nReason=[B]\n",maxbuf); + switch (ecode) { + case 0x80: + printf("Not listening on called name\n"); + break; + case 0x81: + printf("Not listening for calling name\n"); + break; + case 0x82: + printf("Called name not present\n"); + break; + case 0x83: + printf("Called name present, but insufficient resources\n"); + break; + default: + printf("Unspecified error 0x%X\n",ecode); + break; + } + } + break; + + case 0x85: + data = fdata(data,"NBT Session Keepalive\nFlags=[rW]\n",maxbuf); + break; + + default: + printf("flags=0x%x\n", flags); + data = fdata(data,"NBT - Unknown packet type\nType=[rW]\n",maxbuf); + } + printf("\n"); + fflush(stdout); +} + + +/* + print a NBT packet received across udp on port 137 +*/ +void nbt_udp137_print(const uchar *data, int length) +{ + const uchar *maxbuf = data + length; + int name_trn_id = RSVAL(data,0); + int response = (CVAL(data,2)>>7); + int opcode = (CVAL(data,2) >> 3) & 0xF; + int nm_flags = ((CVAL(data,2) & 0x7) << 4) + (CVAL(data,3)>>4); + int rcode = CVAL(data,3) & 0xF; + int qdcount = RSVAL(data,4); + int ancount = RSVAL(data,6); + int nscount = RSVAL(data,8); + int arcount = RSVAL(data,10); + char des[1024]; + char *opcodestr="OPUNKNOWN"; + const char *p; + + startbuf = data; + + if (maxbuf <= data) return; + + strcpy(des,"\n>>> NBT UDP PACKET(137): "); + + switch (opcode) { + case 0: opcodestr = "QUERY"; break; + case 5: opcodestr = "REGISTRATION"; break; + case 6: opcodestr = "RELEASE"; break; + case 7: opcodestr = "WACK"; break; + case 8: opcodestr = "REFRESH(8)"; break; + case 9: opcodestr = "REFRESH"; break; + } + strcat(des,opcodestr); + if (response) { + if (rcode) + strcat(des,"; NEGATIVE"); + else + strcat(des,"; POSITIVE"); + } + + if (response) + strcat(des,"; RESPONSE"); + else + strcat(des,"; REQUEST"); + + if (nm_flags&1) + strcat(des,"; BROADCAST"); + else + strcat(des,"; UNICAST"); + + printf("%s", des); + + if (vflag == 0) return; + + printf("\nTrnID=0x%X\nOpCode=%d\nNmFlags=0x%X\nRcode=%d\nQueryCount=%d\nAnswerCount=%d\nAuthorityCount=%d\nAddressRecCount=%d\n", + name_trn_id,opcode,nm_flags,rcode,qdcount,ancount,nscount,arcount); + + p = data + 12; + + { + int total = ancount+nscount+arcount; + int i; + + if (qdcount>100 || total>100) { + printf("Corrupt packet??\n"); + return; + } + + if (qdcount) { + printf("QuestionRecords:\n"); + for (i=0;i<qdcount;i++) + p = fdata(p,"|Name=[n1]\nQuestionType=[rw]\nQuestionClass=[rw]\n#",maxbuf); + } + + if (total) { + printf("\nResourceRecords:\n"); + for (i=0;i<total;i++) { + int rdlen; + int restype; + p = fdata(p,"Name=[n1]\n#",maxbuf); + restype = RSVAL(p,0); + p = fdata(p,"ResType=[rw]\nResClass=[rw]\nTTL=[rD]\n",p+8); + rdlen = RSVAL(p,0); + printf("ResourceLength=%d\nResourceData=\n",rdlen); + p += 2; + if (rdlen == 6) { + p = fdata(p,"AddrType=[rw]\nAddress=[b.b.b.b]\n",p+rdlen); + } else { + if (restype == 0x21) { + int numnames = CVAL(p,0); + p = fdata(p,"NumNames=[B]\n",p+1); + while (numnames--) { + char flags[128]=""; + p = fdata(p,"Name=[n2]\t#",maxbuf); + if (p[0] & 0x80) strcat(flags,"<GROUP> "); + if ((p[0] & 0x60) == 0x00) strcat(flags,"B "); + if ((p[0] & 0x60) == 0x20) strcat(flags,"P "); + if ((p[0] & 0x60) == 0x40) strcat(flags,"M "); + if ((p[0] & 0x60) == 0x60) strcat(flags,"_ "); + if (p[0] & 0x10) strcat(flags,"<DEREGISTERING> "); + if (p[0] & 0x08) strcat(flags,"<CONFLICT> "); + if (p[0] & 0x04) strcat(flags,"<ACTIVE> "); + if (p[0] & 0x02) strcat(flags,"<PERMANENT> "); + printf("%s\n",flags); + p += 2; + } + } else { + print_data(p,rdlen); + p += rdlen; + } + } + } + } + } + + if ((uchar*)p < maxbuf) { + fdata(p,"AdditionalData:\n",maxbuf); + } + + printf("\n"); + fflush(stdout); +} + + + +/* + print a NBT packet received across udp on port 138 +*/ +void nbt_udp138_print(const uchar *data, int length) +{ + const uchar *maxbuf = data + length; + startbuf = data; + if (maxbuf <= data) return; + + data = fdata(data,"\n>>> NBT UDP PACKET(138) Res=[rw] ID=[rw] IP=[b.b.b.b] Port=[rd] Length=[rd] Res2=[rw]\nSourceName=[n1]\nDestName=[n1]\n#",maxbuf); + + print_smb(data,maxbuf); + + printf("\n"); + fflush(stdout); +} + + + +/* + print netbeui frames +*/ +void netbeui_print(const uchar *data, const uchar *maxbuf) +{ + int len = SVAL(data,1); + int command = CVAL(data,5); + const uchar *data2 = data + 1 + len; + + startbuf = data; + + data = fdata(data,"\n>>> NetBeui Packet\nType=[B] Length=[d] Signature=[w] Command=[B]\n#",maxbuf); + + switch (command) { + case 0xA: + data = fdata(data,"NameQuery:[P1]\nSessionNumber=[B]\nNameType=[B][P2]\nResponseCorrelator=[w]\nDestination=[n2]\nSource=[n2]\n",data2); + break; + + case 0x8: + data = fdata(data,"NetbiosDataGram:[P7]\nDestination=[n2]\nSource=[n2]\n",data2); + break; + + case 0xE: + data = fdata(data,"NameRecognise:\n[P1]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nDestination=[n2]\nSource=[n2]\n",data2); + break; + + case 0x19: + data = fdata(data,"SessionInitialise:\nData1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n",data2); + break; + + case 0x17: + data = fdata(data,"SessionConfirm:\nData1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n",data2); + break; + + case 0x16: + data = fdata(data,"NetbiosDataOnlyLast:\nFlags=[{|NO_ACK|PIGGYBACK_ACK_ALLOWED|PIGGYBACK_ACK_INCLUDED|}]\nResyncIndicator=[w][P2]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n",data2); + break; + + case 0x14: + data = fdata(data,"NetbiosDataAck:\n[P3]TransmitCorrelator=[w][P2]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n",data2); + break; + + case 0x18: + data = fdata(data,"SessionEnd:\n[P1]Data2=[w][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n",data2); + break; + + default: + data = fdata(data,"Unknown Netbios Command ",data2); + break; + } + + if (memcmp(data2,"\377SMB",4)==0) { + print_smb(data2,maxbuf); + } else { + int i; + for (i=0;i<128;i++) { + if (memcmp(&data2[i],"\377SMB",4)==0) { + printf("found SMB packet at %d\n", i); + print_smb(&data2[i],maxbuf); + break; + } + } + } + + printf("\n"); +} + + +/* + print IPX-Netbios frames +*/ +void ipx_netbios_print(const uchar *data, const uchar *maxbuf) +{ + /* this is a hack till I work out how to parse the rest of the IPX stuff */ + int i; + startbuf = data; + for (i=0;i<128;i++) + if (memcmp(&data[i],"\377SMB",4)==0) { + fdata(data,"\n>>> IPX transport ",&data[i]); + print_smb(&data[i],maxbuf); + printf("\n"); + fflush(stdout); + break; + } + if (i==128) + fdata(data,"\n>>> Unknown IPX ",maxbuf); +} diff --git a/contrib/tcpdump/print-snmp.c b/contrib/tcpdump/print-snmp.c index 8367470..5013952 100644 --- a/contrib/tcpdump/print-snmp.c +++ b/contrib/tcpdump/print-snmp.c @@ -21,6 +21,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. * @@ -42,7 +45,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: print-snmp.c,v 1.33 97/06/15 13:20:28 leres Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.39 1999/12/22 06:27:22 itojun Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/param.h> @@ -55,6 +62,10 @@ static const char rcsid[] = #include <stdio.h> #include <string.h> +#ifdef HAVE_SMI_H +#include <smi.h> +#endif + #include "interface.h" #include "addrtoname.h" @@ -94,7 +105,11 @@ char *Application[] = { #define GAUGE 2 "TimeTicks", #define TIMETICKS 3 - "Opaque" + "Opaque", +#define OPAQUE 4 + "C-5", + "Counter64" +#define COUNTER64 6 }; /* @@ -109,8 +124,34 @@ 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 + */ +char *Exceptions[] = { + "noSuchObject", +#define NOSUCHOBJECT 0 + "noSuchInstance", +#define NOSUCHINSTANCE 1 + "endOfMibView", +#define ENDOFMIBVIEW 2 }; /* @@ -130,10 +171,23 @@ char *ErrorStatus[] = { "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]) \ + ( e >= 0 && e < sizeof(ErrorStatus)/sizeof(ErrorStatus[0]) \ ? ErrorStatus[e] : (sprintf(errbuf, "err=%u", e), errbuf)) /* @@ -150,7 +204,7 @@ char *GenericTrap[] = { #define GT_ENTERPRISE 7 }; #define DECODE_GenericTrap(t) \ - ( t >= 0 && t <= sizeof(GenericTrap)/sizeof(GenericTrap[0]) \ + ( t >= 0 && t < sizeof(GenericTrap)/sizeof(GenericTrap[0]) \ ? GenericTrap[t] : (sprintf(buf, "gt=%d", t), buf)) /* @@ -172,6 +226,8 @@ struct { #define CONTEXT 2 defineCLASS(Private), #define PRIVATE 3 + defineCLASS(Exceptions), +#define EXCEPTIONS 4 }; /* @@ -227,6 +283,10 @@ struct obj_abrev { /* .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 +320,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 +339,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 + */ +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 +406,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; } @@ -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; @@ -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,11 +678,12 @@ 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 */ @@ -592,8 +707,49 @@ 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???*/ + sprintf(first, "%.f", d); +#else + sprintf(first, "%f", d); +#endif + sprintf(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 +773,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='.'; + 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 +835,274 @@ asn1_decode(u_char *p, u_int length) } #endif +#ifdef LIBSMI + +struct smi2be { + SmiBasetype basetype; + int be; +}; + +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 *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 + */ + if (first < 0) { + first = 0; + oid[(*oidlen)++] = o/OIDMUX; + o %= OIDMUX; + } + 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; + + 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->module, smiType->name); + smiRange; + smiRange = smiGetNextRange(smiRange)) { + + ok = smi_check_a_range(smiType, smiRange, elem); + + if (ok) { + smiFreeRange(smiRange); + break; + } + } + + if (ok && smiType->parentmodule && smiType->parentname) { + SmiType *parentType; + parentType = smiGetType(smiType->parentmodule, + smiType->parentname); + if (parentType) { + ok = smi_check_range(parentType, elem); + smiFreeType(parentType); + } + } + + 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, &oidlen); + smiNode = smiGetNodeByOID(oidlen, oid); + if (! smiNode) { + asn1_print(elem); + return NULL; + } + if (vflag) { + fputs(smiNode->module, 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 (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); + } + + if (! smi_check_type(smiNode->basetype, elem->type)) { + fputs("[wrongType]", stdout); + } + + smiType = smiGetType(smiNode->typemodule, smiNode->typename); + if (! smiType) { + asn1_print(elem); + return; + } + + if (! smi_check_range(smiType, elem)) { + fputs("[wrongLength]", 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 (smiNode->basetype == SMI_BASETYPE_BITS + && smiNode->typemodule && smiNode->typename) { + /* print bit labels */ + } else { + smi_decode_oid(elem, oid, &oidlen); + smiNode = smiGetNodeByOID(oidlen, oid); + if (smiNode) { + if (vflag) { + fputs(smiNode->module, 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 (smiNode->basetype == SMI_BASETYPE_ENUM + && smiNode->typemodule && smiNode->typename) { + for (nn = smiGetFirstNamedNumber(smiNode->typemodule, + smiNode->typename); + 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); + } + + if (smiType) { + smiFreeType(smiType); + } +} +#endif + /* * General SNMP header * SEQUENCE { @@ -715,10 +1140,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) @@ -738,8 +1166,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 +1190,45 @@ 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); + smiFreeNode(smiNode); +#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) @@ -820,11 +1257,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 +1281,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 +1302,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 +1310,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 +1389,124 @@ 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 (count < length) + printf("[%d extra after PDU]", length - count); + asn1_print(&pdu); + /* 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; + } +} + +/* + * 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; @@ -1014,30 +1523,295 @@ snmp_print(const u_char *np, u_int length) 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; + } + length = elem.asnlen; + np = (u_char *)elem.data.raw; + + /* 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 (count < length) - printf("[%d extra after PDU]", length - count); - asn1_print(&pdu); - /* descend into PDU */ - length = pdu.asnlen; - np = (u_char *)pdu.data.raw; + printf("[%d extra after usm SEQ]", length - count); +} - switch (pdu.id) { - case TRAP: - trap_print(np, length); +/* + * 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; + + /* 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 (count < length) + printf("[%d extra after message SEQ]", length - count); + + 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("ScopedPDU ", stdout); + } + + scopedpdu_print(np, length, 3); +} + +/* + * 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 (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; } diff --git a/contrib/tcpdump/print-tcp.c b/contrib/tcpdump/print-tcp.c index fbda84c..451bab6 100644 --- a/contrib/tcpdump/print-tcp.c +++ b/contrib/tcpdump/print-tcp.c @@ -21,7 +21,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: print-tcp.c,v 1.55 97/06/15 13:20:28 leres Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.63 1999/12/22 15:44:10 itojun Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/param.h> @@ -32,7 +36,6 @@ static const char rcsid[] = #include <netinet/ip.h> #include <netinet/ip_var.h> #include <netinet/tcp.h> -#include <netinet/tcpip.h> #ifdef HAVE_MEMORY_H #include <memory.h> @@ -42,6 +45,10 @@ static const char rcsid[] = #include <string.h> #include <unistd.h> +#ifdef INET6 +#include <netinet/ip6.h> +#endif + #include "interface.h" #include "addrtoname.h" #include "extract.h" @@ -76,8 +83,13 @@ static const char rcsid[] = #endif struct tha { +#ifndef INET6 struct in_addr src; struct in_addr dst; +#else + struct in6_addr src; + struct in6_addr dst; +#endif /*INET6*/ u_int port; }; @@ -96,6 +108,14 @@ 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 + void tcp_print(register const u_char *bp, register u_int length, register const u_char *bp2) @@ -106,33 +126,75 @@ tcp_print(register const u_char *bp, register u_int length, register int hlen; register char ch; u_short sport, dport, win, urp; - u_int32_t seq, ack; + u_int32_t seq, ack, thseq, thack; + int threv; +#ifdef INET6 + register const struct ip6_hdr *ip6; +#endif tp = (struct tcphdr *)bp; ip = (struct ip *)bp2; +#ifdef INET6 + if (ip->ip_v == 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); + +#ifdef INET6 + if (ip6) { + if (ip6->ip6_nxt == IPPROTO_TCP) { + (void)printf("%s.%s > %s.%s: ", + ip6addr_string(&ip6->ip6_src), + tcpport_string(sport), + ip6addr_string(&ip6->ip6_dst), + tcpport_string(dport)); + } else { + (void)printf("%s > %s: ", + tcpport_string(sport), tcpport_string(dport)); + } + } else +#endif /*INET6*/ + { + if (ip->ip_p == IPPROTO_TCP) { + (void)printf("%s.%s > %s.%s: ", + ipaddr_string(&ip->ip_src), + tcpport_string(sport), + ipaddr_string(&ip->ip_dst), + tcpport_string(dport)); + } else { + (void)printf("%s > %s: ", + tcpport_string(sport), tcpport_string(dport)); + } + } + + TCHECK(*tp); + seq = ntohl(tp->th_seq); ack = ntohl(tp->th_ack); win = ntohs(tp->th_win); urp = ntohs(tp->th_urp); - (void)printf("%s.%s > %s.%s: ", - ipaddr_string(&ip->ip_src), tcpport_string(sport), - ipaddr_string(&ip->ip_dst), tcpport_string(dport)); - if (qflag) { (void)printf("tcp %d", length - tp->th_off * 4); return; } - if ((flags = tp->th_flags) & (TH_SYN|TH_FIN|TH_RST|TH_PUSH)) { +#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 & TH_SYN) putchar('S'); if (flags & TH_FIN) @@ -141,9 +203,22 @@ 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 } else putchar('.'); + if (flags&0xc0) { + printf(" ["); + if (flags&0x40) + printf("ECN-Echo"); + if (flags&0x80) + printf("%sCWR", (flags&0x40) ? "," : ""); + printf("]"); + } + if (!Sflag && (flags & TH_ACK)) { register struct tcp_seq_hash *th; register int rev; @@ -154,6 +229,49 @@ tcp_print(register const u_char *bp, register u_int length, * collating order so there's only one entry for * both directions). */ +#ifdef INET6 + bzero(&tha, sizeof(tha)); + rev = 0; + if (ip6) { + if (sport > dport) { + rev = 1; + } else if (sport == dport) { + int i; + + for (i = 0; i < 4; i++) { + if (((u_int32_t *)(&ip6->ip6_src))[i] > + ((u_int32_t *)(&ip6->ip6_dst))[i]) { + rev = 1; + break; + } + } + } + if (rev) { + tha.src = ip6->ip6_dst; + tha.dst = ip6->ip6_src; + tha.port = dport << 16 | sport; + } else { + tha.dst = ip6->ip6_dst; + tha.src = ip6->ip6_src; + tha.port = sport << 16 | dport; + } + } else { + if (sport > dport || + (sport == dport && + ip->ip_src.s_addr > ip->ip_dst.s_addr)) { + rev = 1; + } + if (rev) { + *(struct in_addr *)&tha.src = ip->ip_dst; + *(struct in_addr *)&tha.dst = 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; + tha.port = sport << 16 | dport; + } + } +#else if (sport < dport || (sport == dport && ip->ip_src.s_addr < ip->ip_dst.s_addr)) { @@ -165,7 +283,9 @@ tcp_print(register const u_char *bp, register u_int length, tha.port = dport << 16 | sport; rev = 1; } +#endif + threv = rev; for (th = &tcp_seq_hash[tha.port % TSEQ_HASHSIZE]; th->nxt; th = th->nxt) if (!memcmp((char *)&tha, (char *)&th->addr, @@ -186,6 +306,10 @@ tcp_print(register const u_char *bp, register u_int length, else th->seq = seq, th->ack = ack - 1; } else { + + thseq = th->seq; + thack = th->ack; + if (rev) seq -= th->ack, ack -= th->seq; else @@ -198,7 +322,7 @@ tcp_print(register const u_char *bp, register u_int length, return; } length -= hlen; - if (length > 0 || flags & (TH_SYN | TH_FIN | TH_RST)) + if (vflag > 1 || length > 0 || flags & (TH_SYN | TH_FIN | TH_RST)) (void)printf(" %u:%u(%d)", seq, seq + length, length); if (flags & TH_ACK) (void)printf(" ack %u", ack); @@ -268,15 +392,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: @@ -349,6 +486,21 @@ tcp_print(register const u_char *bp, register u_int length, } putchar('>'); } + + if (length <= 0) + return; + + /* + * Decode payload if necessary. + */ + bp += (tp->th_off * 4); + if (!qflag && vflag && length > 0 + && (sport == TELNET_PORT || dport == TELNET_PORT)) + telnet_print(bp, length); + else if (sport == BGP_PORT || dport == BGP_PORT) + bgp_print(bp, length); + else if (sport == NETBIOS_SSN_PORT || dport == NETBIOS_SSN_PORT) + nbt_tcp_print(bp, length); return; bad: fputs("[bad opt]", stdout); diff --git a/contrib/tcpdump/print-telnet.c b/contrib/tcpdump/print-telnet.c new file mode 100644 index 0000000..bb0f4ab --- /dev/null +++ b/contrib/tcpdump/print-telnet.c @@ -0,0 +1,191 @@ +/* $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[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-telnet.c,v 1.2.2.2 2000/01/11 06:58:28 fenner Exp $"; +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> + +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_var.h> +#include <netinet/tcp.h> +#include <netinet/tcpip.h> + +#define TELCMDS +#define TELOPTS +#include <arpa/telnet.h> + +#include <stdio.h> +#ifdef __STDC__ +#include <stdlib.h> +#endif +#include <unistd.h> +#include <string.h> + +#include "interface.h" +#include "addrtoname.h" + + +#ifndef TELCMD_FIRST +# define TELCMD_FIRST SE +#endif + +void +telnet_print(register const u_char *sp, u_int length) +{ + static char tnet[128]; + register int i, c, x; + register u_char *rcp; + int off, first = 1; + u_char *osp; + + off = 0; + x = 0; + + while (length > 0 && *sp == IAC) { + osp = (u_char *) sp; + tnet[0] = '\0'; + + c = *sp++; + length--; + switch (*sp) { + case IAC: /* <IAC><IAC>! */ + if (length > 1 && sp[1] == IAC) { + (void)strcpy(tnet, "IAC IAC"); + } else { + length = 0; + continue; + } + break; + default: + c = *sp++; + length--; + if ((i = c - TELCMD_FIRST) < 0 + || i > IAC - TELCMD_FIRST) { + (void)printf("unknown: ff%02x\n", c); + return; + } + switch (c) { + case DONT: + case DO: + case WONT: + case WILL: + case SB: + x = *sp++; /* option */ + length--; + if (x >= 0 && x < NTELOPTS) { + (void)sprintf(tnet, "%s %s", + telcmds[i], telopts[x]); + } else { + (void)sprintf(tnet, "%s %#x", + telcmds[i], x); + } + break; + default: + (void)strcpy(tnet, telcmds[i]); + } + if (c == SB) { + c = *sp++; + length--; + (void)strcat(tnet, c ? " SEND" : " IS '"); + rcp = (u_char *) sp; + i = strlen(tnet); + while (length > 0 && (x = *sp++) != IAC) + --length; + if (x == IAC) { + if (2 < vflag + && i + 16 + sp - rcp < sizeof(tnet)) { + (void)strncpy(&tnet[i], rcp, sp - rcp); + i += (sp - rcp) - 1; + tnet[i] = '\0'; + } else if (i + 8 < sizeof(tnet)) { + (void)strcat(&tnet[i], "..."); + } + if (*sp++ == SE + && i + 4 < sizeof(tnet)) + (void)strcat(tnet, c ? " SE" : "' SE"); + } else if (i + 16 < sizeof(tnet)) { + (void)strcat(tnet, " truncated!"); + } + } + break; + } + /* + * now print it + */ + if (Xflag && 2 < vflag) { + if (first) + printf("\nTelnet:\n"); + i = sp - osp; + hex_print_with_offset(osp, i, off); + off += i; + if (i > 8) + printf("\n\t\t\t\t%s", tnet); + else + printf("%*s\t%s", (8 - i) * 3, "", tnet); + } else { + printf("%s%s", (first) ? " [telnet " : ", ", tnet); + } + first = 0; + } + if (!first) { + if (Xflag && 2 < vflag) + printf("\n"); + else + printf("]"); + } +} diff --git a/contrib/tcpdump/print-tftp.c b/contrib/tcpdump/print-tftp.c index d8a7b3e..66c1392 100644 --- a/contrib/tcpdump/print-tftp.c +++ b/contrib/tcpdump/print-tftp.c @@ -23,7 +23,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: print-tftp.c,v 1.30 97/06/13 12:57:12 leres Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-tftp.c,v 1.31 1999/11/21 09:37:03 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/param.h> diff --git a/contrib/tcpdump/print-vjc.c b/contrib/tcpdump/print-vjc.c new file mode 100644 index 0000000..1b8847f --- /dev/null +++ b/contrib/tcpdump/print-vjc.c @@ -0,0 +1,104 @@ +/* + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#if defined(__bsdi__) + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /tcpdump/master/tcpdump/print-vjc.c,v 1.2.2.1 2000/01/11 06:58:28 fenner Exp $ (LBL)"; +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/socket.h> +#include <sys/file.h> +#include <sys/ioctl.h> + +#if __STDC__ +struct mbuf; +struct rtentry; +#endif +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/if_ether.h> + +#include <ctype.h> +#include <netdb.h> +#include <pcap.h> +#include <stdio.h> + +#if defined(__NetBSD__) +#include <sys/mbuf.h> +#include <net/ppp_defs.h> +#endif + +#if defined(__bsdi__) || defined(__NetBSD__) +#include <net/if_ppp.h> +#include <net/slcompress.h> +#endif + +#include "interface.h" +#include "addrtoname.h" + +int +vjc_print(register const char *bp, register u_int length, u_short proto) +{ + int i; + + switch (bp[0] & 0xf0) { + case TYPE_IP: + if (eflag) + printf("(vjc type=IP) "); + return PPP_IP; + case TYPE_UNCOMPRESSED_TCP: + if (eflag) + printf("(vjc type=raw TCP) "); + return PPP_IP; + case TYPE_COMPRESSED_TCP: + if (eflag) + printf("(vjc type=compressed TCP) "); + for (i = 0; i < 8; i++) { + if (bp[1] & (0x80 >> i)) + printf("%c", "?CI?SAWU"[i]); + } + if (bp[1]) + printf(" "); + printf("C=0x%02x ", bp[2]); + printf("sum=0x%04x ", *(u_short *)&bp[3]); + return -1; + case TYPE_ERROR: + if (eflag) + printf("(vjc type=error) "); + return -1; + default: + if (eflag) + printf("(vjc type=0x%02x) ", bp[0] & 0xf0); + return -1; + } +} +#endif /* defined(__bsdi__) || defined(__NetBSD__) */ diff --git a/contrib/tcpdump/print-wb.c b/contrib/tcpdump/print-wb.c index cd60848..fa10541 100644 --- a/contrib/tcpdump/print-wb.c +++ b/contrib/tcpdump/print-wb.c @@ -21,7 +21,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: print-wb.c,v 1.24 96/12/31 21:27:44 leres Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-wb.c,v 1.25 1999/11/21 09:37:03 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/types.h> diff --git a/contrib/tcpdump/route6d.h b/contrib/tcpdump/route6d.h new file mode 100644 index 0000000..f9cc3dd --- /dev/null +++ b/contrib/tcpdump/route6d.h @@ -0,0 +1,49 @@ +/* + * $Header: /tcpdump/master/tcpdump/route6d.h,v 1.1 1999/10/30 05:11:22 itojun Exp $ + */ + +#define RIP6_VERSION 1 + +#define RIP6_REQUEST 1 +#define RIP6_RESPONSE 2 + +struct netinfo6 { + struct in6_addr rip6_dest; + u_short rip6_tag; + u_char rip6_plen; + u_char rip6_metric; +}; + +struct rip6 { + u_char rip6_cmd; + u_char rip6_vers; + u_char rip6_res1[2]; + union { + struct netinfo6 ru6_nets[1]; + char ru6_tracefile[1]; + } rip6un; +#define rip6_nets rip6un.ru6_nets +#define rip6_tracefile rip6un.ru6_tracefile +}; + +#define HOPCNT_INFINITY6 16 +#define MAXRTE 24 +#define NEXTHOP_METRIC 0xff + +#ifndef DEBUG +#define SUPPLY_INTERVAL6 30 +#define RIP_LIFETIME 180 +#define RIP_HOLDDOWN 120 +#define RIP_TRIG_INTERVAL6 5 +#define RIP_TRIG_INTERVAL6_MIN 1 +#else +/* only for debugging; can not wait for 30sec to appear a bug */ +#define SUPPLY_INTERVAL6 10 +#define RIP_LIFETIME 60 +#define RIP_HOLDDOWN 40 +#define RIP_TRIG_INTERVAL6 5 +#define RIP_TRIG_INTERVAL6_MIN 1 +#endif + +#define RIP6_PORT 521 +#define RIP6_DEST "ff02::9" diff --git a/contrib/tcpdump/rx.h b/contrib/tcpdump/rx.h new file mode 100644 index 0000000..5435beb --- /dev/null +++ b/contrib/tcpdump/rx.h @@ -0,0 +1,68 @@ +/* + * Rx protocol format + * + * $Id: rx.h,v 1.1 1999/11/17 05:45:58 assar 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_char 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_char 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 + u_char userStatus; + u_char securityIndex; + u_short spare; /* How clever: even though the AFS */ + u_short 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 5 diff --git a/contrib/tcpdump/savestr.c b/contrib/tcpdump/savestr.c index 2b0c864..a148802 100644 --- a/contrib/tcpdump/savestr.c +++ b/contrib/tcpdump/savestr.c @@ -21,7 +21,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: savestr.c,v 1.2 97/05/09 14:52:31 leres Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/savestr.c,v 1.4 1999/11/21 09:37:04 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/types.h> @@ -31,6 +35,7 @@ static const char rcsid[] = #endif #include <stdio.h> #include <stdlib.h> +#include <string.h> #include "gnuc.h" #ifdef HAVE_OS_PROTO_H diff --git a/contrib/tcpdump/savestr.h b/contrib/tcpdump/savestr.h index 51b4402..26f9c21 100644 --- a/contrib/tcpdump/savestr.h +++ b/contrib/tcpdump/savestr.h @@ -18,7 +18,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: savestr.h,v 1.1 97/04/22 13:30:21 leres Exp $ (LBL) + * @(#) $Header: /tcpdump/master/tcpdump/savestr.h,v 1.1.1.1 1999/10/07 23:47:12 mcr Exp $ (LBL) */ extern char *savestr(const char *); diff --git a/contrib/tcpdump/setsignal.c b/contrib/tcpdump/setsignal.c index 6f797ff..756d1fe 100644 --- a/contrib/tcpdump/setsignal.c +++ b/contrib/tcpdump/setsignal.c @@ -21,7 +21,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: setsignal.c,v 1.4 97/06/15 13:20:29 leres Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/setsignal.c,v 1.5 1999/11/21 09:37:04 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/types.h> diff --git a/contrib/tcpdump/setsignal.h b/contrib/tcpdump/setsignal.h index 39b6065..a7fb2a7 100644 --- a/contrib/tcpdump/setsignal.h +++ b/contrib/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/contrib/tcpdump/smb.h b/contrib/tcpdump/smb.h new file mode 100644 index 0000000..0c5461a --- /dev/null +++ b/contrib/tcpdump/smb.h @@ -0,0 +1,152 @@ +/* + 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 CVAL(buf,pos) (((unsigned char *)(buf))[pos]) +#define PVAL(buf,pos) ((unsigned)CVAL(buf,pos)) +#define SCVAL(buf,pos,val) (CVAL(buf,pos) = (val)) + +#define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8) +#define IVAL(buf,pos) (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16) +#define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8) +#define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16)) +#define SVALS(buf,pos) ((int16)SVAL(buf,pos)) +#define IVALS(buf,pos) ((int32)IVAL(buf,pos)) +#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((uint16)(val))) +#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32)(val))) +#define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16)(val))) +#define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32)(val))) + +/* now the reverse routines - these are used in nmb packets (mostly) */ +#define SREV(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF)) +#define IREV(x) ((SREV(x)<<16) | (SREV((x)>>16))) + +#define RSVAL(buf,pos) SREV(SVAL(buf,pos)) +#define RIVAL(buf,pos) IREV(IVAL(buf,pos)) +#define RSSVAL(buf,pos,val) SSVAL(buf,pos,SREV(val)) +#define RSIVAL(buf,pos,val) SIVAL(buf,pos,IREV(val)) + +#define uint16 unsigned short +#define uint32 unsigned int +#ifndef uchar +#define uchar unsigned char +#endif + +#ifndef MIN +#define MIN(a,b) ((a)<(b)?(a):(b)) +#endif + +/* 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) ((unsigned long)(((char *)(p1)) - (char *)(p2))) + +/* some protos */ +const uchar *fdata(const uchar *buf, const char *fmt, const uchar *maxbuf); diff --git a/contrib/tcpdump/smbutil.c b/contrib/tcpdump/smbutil.c new file mode 100644 index 0000000..2ddd3f6 --- /dev/null +++ b/contrib/tcpdump/smbutil.c @@ -0,0 +1,698 @@ +/* + 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[] = + "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.4.2.1 2000/01/11 06:58:28 fenner Exp $"; +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +#include <net/if.h> + +#include <netinet/in.h> +#include <netinet/if_ether.h> + +#include <ctype.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "interface.h" +#include "smb.h" + +extern uchar *startbuf; + +/******************************************************************* + interpret a 32 bit dos packed date/time to some parameters +********************************************************************/ +static void interpret_dos_date(uint32 date,int *year,int *month,int *day,int *hour,int *minute,int *second) +{ + uint32 p0,p1,p2,p3; + + p0=date&0xFF; p1=((date&0xFF00)>>8)&0xFF; + p2=((date&0xFF0000)>>16)&0xFF; p3=((date&0xFF000000)>>24)&0xFF; + + *second = 2*(p0 & 0x1F); + *minute = ((p0>>5)&0xFF) + ((p1&0x7)<<3); + *hour = (p1>>3)&0xFF; + *day = (p2&0x1F); + *month = ((p2>>5)&0xFF) + ((p3&0x1)<<3) - 1; + *year = ((p3>>1)&0xFF) + 80; +} + +/******************************************************************* + create a unix date from a dos date +********************************************************************/ +static time_t make_unix_date(const void *date_ptr) +{ + uint32 dos_date=0; + struct tm t; + + dos_date = IVAL(date_ptr,0); + + if (dos_date == 0) return(0); + + interpret_dos_date(dos_date,&t.tm_year,&t.tm_mon, + &t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec); + t.tm_wday = 1; + t.tm_yday = 1; + t.tm_isdst = 0; + + return (mktime(&t)); +} + +/******************************************************************* + create a unix date from a dos date +********************************************************************/ +static time_t make_unix_date2(const void *date_ptr) +{ + uint32 x,x2; + + x = IVAL(date_ptr,0); + x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); + SIVAL(&x,0,x2); + + return(make_unix_date((void *)&x)); +} + +/**************************************************************************** +interpret an 8 byte "filetime" structure to a time_t +It's originally in "100ns units since jan 1st 1601" +****************************************************************************/ +static time_t interpret_long_date(const char *p) +{ + double d; + time_t ret; + + /* this gives us seconds since jan 1st 1601 (approx) */ + d = (IVAL(p,4)*256.0 + CVAL(p,3)) * (1.0e-7 * (1<<24)); + + /* now adjust by 369 years to make the secs since 1970 */ + d -= 369.0*365.25*24*60*60; + + /* 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); +} + + +/**************************************************************************** +interpret the weird netbios "name". Return the name type +****************************************************************************/ +static int name_interpret(char *in,char *out) +{ + int ret; + int len = (*in++) / 2; + + *out=0; + + if (len > 30 || len<1) return(0); + + while (len--) + { + 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); +} + +/**************************************************************************** +find a pointer to a netbios name +****************************************************************************/ +static char *name_ptr(char *buf,int ofs) +{ + unsigned char c = *(unsigned char *)(buf+ofs); + + if ((c & 0xC0) == 0xC0) + { + uint16 l = RSVAL(buf, ofs) & 0x3FFF; + return(buf + l); + } + else + return(buf+ofs); +} + +/**************************************************************************** +extract a netbios name from a buf +****************************************************************************/ +static int name_extract(char *buf,int ofs,char *name) +{ + char *p = name_ptr(buf,ofs); + strcpy(name,""); + return(name_interpret(p,name)); +} + + +/**************************************************************************** +return the total storage length of a mangled name +****************************************************************************/ +static int name_len(const unsigned char *s) +{ + const char *s0 = s; + unsigned char c = *(unsigned char *)s; + if ((c & 0xC0) == 0xC0) + return(2); + while (*s) s += (*s)+1; + return(PTR_DIFF(s,s0)+1); +} + +static void print_asc(const unsigned char *buf,int len) +{ + int i; + for (i=0;i<len;i++) + printf("%c",isprint(buf[i])?buf[i]:'.'); +} + +static char *name_type_str(int name_type) +{ + static char *f = NULL; + switch (name_type) { + case 0: f = "Workstation"; break; + case 0x03: f = "Client?"; break; + case 0x20: f = "Server"; break; + case 0x1d: f = "Master Browser"; break; + case 0x1b: f = "Domain Controller"; break; + case 0x1e: f = "Browser Server"; break; + default: f = "Unknown"; break; + } + return(f); +} + +void print_data(const unsigned char *buf, int len) +{ + int i=0; + if (len<=0) return; + printf("[%03X] ",i); + for (i=0;i<len;) { + printf("%02X ",(int)buf[i]); + i++; + if (i%8 == 0) printf(" "); + if (i%16 == 0) { + print_asc(&buf[i-16],8); printf(" "); + print_asc(&buf[i-8],8); printf("\n"); + if (i<len) printf("[%03X] ",i); + } + } + if (i%16) { + int n; + + n = 16 - (i%16); + printf(" "); + if (n>8) printf(" "); + while (n--) printf(" "); + + n = MIN(8,i%16); + print_asc(&buf[i-(i%16)],n); printf(" "); + n = (i%16) - n; + if (n>0) print_asc(&buf[i-n],n); + printf("\n"); + } +} + + +static void write_bits(unsigned int val,char *fmt) +{ + char *p = fmt; + int i=0; + + while ((p=strchr(fmt,'|'))) { + int l = PTR_DIFF(p,fmt); + if (l && (val & (1<<i))) + printf("%.*s ",l,fmt); + fmt = p+1; + i++; + } +} + +/* convert a unicode string */ +static const char *unistr(const char *s, int *len) +{ + static char buf[1000]; + int l=0; + static int use_unicode = -1; + + if (use_unicode == -1) { + char *p = getenv("USE_UNICODE"); + if (p && (atoi(p) == 1)) + use_unicode = 1; + else + use_unicode = 0; + } + + /* maybe it isn't unicode - a cheap trick */ + if (!use_unicode || (s[0] && s[1])) { + *len = strlen(s)+1; + return s; + } + + *len = 0; + + if (s[0] == 0 && s[1] != 0) { + s++; + *len = 1; + } + + while (l < (sizeof(buf)-1) && s[0] && s[1] == 0) { + buf[l] = s[0]; + s += 2; l++; + *len += 2; + } + buf[l] = 0; + *len += 2; + return buf; +} + +static const uchar *fdata1(const uchar *buf, const char *fmt, const uchar *maxbuf) +{ + int reverse=0; + char *attrib_fmt = "READONLY|HIDDEN|SYSTEM|VOLUME|DIR|ARCHIVE|"; + int len; + + while (*fmt && buf<maxbuf) { + switch (*fmt) { + case 'a': + write_bits(CVAL(buf,0),attrib_fmt); + buf++; fmt++; + break; + + case 'A': + write_bits(SVAL(buf,0),attrib_fmt); + buf+=2; fmt++; + break; + + case '{': + { + char bitfmt[128]; + char *p = strchr(++fmt,'}'); + int l = PTR_DIFF(p,fmt); + strncpy(bitfmt,fmt,l); + bitfmt[l]=0; + fmt = p+1; + write_bits(CVAL(buf,0),bitfmt); + buf++; + break; + } + + case 'P': + { + int l = atoi(fmt+1); + buf += l; + fmt++; + while (isdigit(*fmt)) fmt++; + break; + } + case 'r': + reverse = !reverse; + fmt++; + break; + case 'D': + { + unsigned int x = reverse?RIVAL(buf,0):IVAL(buf,0); + printf("%d (0x%x)",x, x); + buf += 4; + fmt++; + break; + } + case 'L': + { + unsigned int x1 = reverse?RIVAL(buf,0):IVAL(buf,0); + unsigned int x2 = reverse?RIVAL(buf,4):IVAL(buf,4); + if (x2) { + printf("0x%08x:%08x",x2, x1); + } else { + printf("%d (0x%08x%08x)",x1, x2, x1); + } + buf += 8; + fmt++; + break; + } + case 'd': + { + unsigned int x = reverse?RSVAL(buf,0):SVAL(buf,0); + printf("%d (0x%x)",x, x); + buf += 2; + fmt++; + break; + } + case 'W': + { + unsigned int x = reverse?RIVAL(buf,0):IVAL(buf,0); + printf("0x%X",x); + buf += 4; + fmt++; + break; + } + case 'w': + { + unsigned int x = reverse?RSVAL(buf,0):SVAL(buf,0); + printf("0x%X",x); + buf += 2; + fmt++; + break; + } + case 'B': + { + unsigned int x = CVAL(buf,0); + printf("0x%X",x); + buf += 1; + fmt++; + break; + } + case 'b': + { + unsigned int x = CVAL(buf,0); + printf("%d (0x%x)",x, x); + buf += 1; + fmt++; + break; + } + case 'S': + { + printf("%.*s",(int)PTR_DIFF(maxbuf,buf),unistr(buf, &len)); + buf += len; + fmt++; + break; + } + case 'Z': + { + if (*buf != 4 && *buf != 2) + printf("Error! ASCIIZ buffer of type %d (safety=%d)\n", + *buf,(int)PTR_DIFF(maxbuf,buf)); + printf("%.*s",(int)PTR_DIFF(maxbuf,buf+1),unistr(buf+1, &len)); + buf += len+1; + fmt++; + break; + } + case 's': + { + int l = atoi(fmt+1); + printf("%-*.*s",l,l,buf); + buf += l; + fmt++; while (isdigit(*fmt)) fmt++; + break; + } + case 'h': + { + int l = atoi(fmt+1); + while (l--) printf("%02x",*buf++); + fmt++; while (isdigit(*fmt)) fmt++; + break; + } + case 'n': + { + int t = atoi(fmt+1); + char nbuf[255]; + int name_type; + switch (t) { + case 1: + name_type = name_extract(startbuf,PTR_DIFF(buf,startbuf),nbuf); + buf += name_len(buf); + printf("%-15.15s NameType=0x%02X (%s)", + nbuf,name_type,name_type_str(name_type)); + break; + case 2: + name_type = buf[15]; + printf("%-15.15s NameType=0x%02X (%s)", + buf,name_type,name_type_str(name_type)); + buf += 16; + break; + } + fmt++; while (isdigit(*fmt)) fmt++; + break; + } + case 'T': + { + time_t t; + int x = IVAL(buf,0); + switch (atoi(fmt+1)) { + case 1: + if (x==0 || x==-1 || x==0xFFFFFFFF) + t = 0; + else + t = make_unix_date(buf); + buf+=4; + break; + case 2: + if (x==0 || x==-1 || x==0xFFFFFFFF) + t = 0; + else + t = make_unix_date2(buf); + buf+=4; + break; + case 3: + t = interpret_long_date(buf); + buf+=8; + break; + } + printf("%s",t?asctime(localtime(&t)):"NULL\n"); + fmt++; while (isdigit(*fmt)) fmt++; + break; + } + default: + putchar(*fmt); + fmt++; + break; + } + } + + if (buf>=maxbuf && *fmt) + printf("END OF BUFFER\n"); + + return(buf); +} + +const uchar *fdata(const uchar *buf, const char *fmt, const uchar *maxbuf) +{ + static int depth=0; + char s[128]; + char *p; + + while (*fmt) { + switch (*fmt) { + case '*': + fmt++; + while (buf < maxbuf) { + const uchar *buf2; + depth++; + buf2 = fdata(buf,fmt,maxbuf); + depth--; + if (buf2 == buf) return(buf); + buf = buf2; + } + break; + + case '|': + fmt++; + if (buf>=maxbuf) return(buf); + break; + + case '%': + fmt++; + buf=maxbuf; + break; + + case '#': + fmt++; + return(buf); + break; + + case '[': + fmt++; + if (buf>=maxbuf) return(buf); + bzero(s,sizeof(s)); + p = strchr(fmt,']'); + strncpy(s,fmt,p-fmt); + fmt = p+1; + buf = fdata1(buf,s,maxbuf); + break; + + default: + putchar(*fmt); fmt++; + fflush(stdout); + break; + } + } + if (!depth && buf<maxbuf) { + int len = PTR_DIFF(maxbuf,buf); + printf("Data: (%d bytes)\n",len); + print_data(buf,len); + return(buf+len); + } + return(buf); +} + +typedef struct +{ + char *name; + int code; + 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; + 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) + { + sprintf(ret,"%s - %s (%s)",err_classes[i].class, + err[j].name,err[j].message); + return ret; + } + } + + sprintf(ret,"%s - %d",err_classes[i].class,num); + return ret; + } + + sprintf(ret,"ERROR: Unknown error (%d,%d)",class,num); + return(ret); +} + + + diff --git a/contrib/tcpdump/strcasecmp.c b/contrib/tcpdump/strcasecmp.c index f2ac077..78d5ae7 100644 --- a/contrib/tcpdump/strcasecmp.c +++ b/contrib/tcpdump/strcasecmp.c @@ -10,9 +10,9 @@ * 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 <sys/types.h> diff --git a/contrib/tcpdump/util.c b/contrib/tcpdump/util.c index 6b07200..3a3094c 100644 --- a/contrib/tcpdump/util.c +++ b/contrib/tcpdump/util.c @@ -21,7 +21,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: util.c,v 1.58 97/05/09 14:52:17 leres Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.62 1999/12/15 06:58:03 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/types.h> @@ -132,10 +136,57 @@ ts_print(register const struct timeval *tvp) (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 */ - (void)printf("%u.%06u ", - (u_int32_t)tvp->tv_sec, (u_int32_t)tvp->tv_usec); + if (tflag < -1) { + static unsigned b_sec; + static unsigned b_usec; + 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; + } else { + /* Unix timeval style */ + (void)printf("%u.%06u ", + (u_int32_t)tvp->tv_sec, (u_int32_t)tvp->tv_usec); + } + } +} + +/* + * 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 char *lengths[]={"y","w","d","h","m","s"}; + static int seconds[]={31536000,604800,86400,3600,60,1}; + char **l = lengths; + int *s = seconds; + + if (secs == 0) { + (void)printf("0s"); + return; + } + while (secs) { + if (secs >= *s) { + (void)printf("%d%s", secs / *s, *l); + secs -= (secs / *s) * *s; } + s++; l++; + } } /* diff --git a/contrib/tcpdump/vfprintf.c b/contrib/tcpdump/vfprintf.c index 8682859..51fa63e 100644 --- a/contrib/tcpdump/vfprintf.c +++ b/contrib/tcpdump/vfprintf.c @@ -21,7 +21,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: vfprintf.c,v 1.2 96/09/26 23:36:51 leres Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/vfprintf.c,v 1.3 1999/11/21 09:37:05 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include <sys/types.h> |