diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 1996-07-13 11:01:36 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 1996-07-13 11:01:36 +0000 |
commit | 8b4f92eb10cc8475dde595267c343b6fa7e42dc0 (patch) | |
tree | f88f41c10c46d9b00531c0178b7d4301a25e3119 /usr.sbin/tcpdump | |
parent | 3b13e49cceec57c39e28d4263a3b3e19421dd2ea (diff) |
it is 3.2 now.
Diffstat (limited to 'usr.sbin/tcpdump')
57 files changed, 3091 insertions, 2137 deletions
diff --git a/usr.sbin/tcpdump/CHANGES b/usr.sbin/tcpdump/CHANGES index 2d3f4348d17..714d7541901 100644 --- a/usr.sbin/tcpdump/CHANGES +++ b/usr.sbin/tcpdump/CHANGES @@ -1,12 +1,106 @@ -$OpenBSD: CHANGES,v 1.3 1996/06/10 07:47:07 deraadt Exp $ -$NetBSD: CHANGES,v 1.3 1996/05/20 00:41:00 fvdl Exp $ -@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/CHANGES,v 1.3 1996/06/10 07:47:07 deraadt Exp $ (LBL) +$OpenBSD: CHANGES,v 1.4 1996/07/13 11:01:05 mickey Exp $ +@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/CHANGES,v 1.4 1996/07/13 11:01:05 mickey Exp $ (LBL) -v3.0.4 Fri Feb 16 13:35:21 PST 1996 +v3.2 Sun Jun 23 02:28:10 PDT 1996 -- New release purely to raise the version number to adjust for the - mistake the linux contingency made. There are other changes between - this and v3.0.2. +- Print new icmp unreachable codes as suggested by Martin Fredriksson + (martin@msp.se). Also print code value when unknown for icmp redirect + and time exceeded. + +- Fix an alignment endian bug in getname(). Thanks to John Hawkinson. + +- Define "new" domain record types if not found in arpa/nameserv.h. + Resulted from a suggestion from John Hawkinson (jhawk@mit.edu). Also + fixed an endian bug when printing mx record and added some new record + types. + +- Added RIP V2 support. Thanks to Jeffrey Honig (jch@bsdi.com) + +- Added T/TCP options printing. As suggested by Richard Stevens + (rstevens@noao.edu) + +- Use autoconf to detect architectures that can't handle misaligned + accesses. + +v3.1 Thu Jun 13 20:59:32 PDT 1996 + +- Changed u_int32/int32 to u_int32_t/int32_t to be consistent with bsd + and bind (as suggested by Charles Hannum). + +- Port to GNU autoconf. + +- Add support for printing DVMRP and PIM traffic thanks to + Havard Eidnes (Havard.Eidnes@runit.sintef.no). + +- Fix AppleTalk, IPX and DECnet byte order problems due to wrong endian + define being referenced. Reported by Terry Kennedy. + +- Minor fixes to the man page thanks to Mark Andrews. + +- Endian fixes to RTP and vat packet dumpers, thanks to Bruce Mah + (bmah@cs.berkeley.edu). + +- Added support for new dns types, thanks to Rainer Orth. + +- Fixed tftp_print() to print the block number for ACKs. + +- Document -dd and -ddd. Resulted from a bug report from Charlie Slater + (cslater@imatek.com). + +- Check return status from malloc/calloc/etc. + +- Check return status from pcap_loop() so we can print an error and + exit with a bad status if there were problems. + +- Bail if ip option length is <= 0. Resulted from a bug report from + Darren Reed (darrenr@vitruvius.arbld.unimelb.edu.au). + +- Print out a little more information for sun rpc packets. + +- Add suport for Kerberos 4 thanks to John Hawkinson (jhawk@mit.edu). + +- Fixed the Fix EXTRACT_SHORT() and EXTRACT_LONG() macros (which were + wrong on little endian machines). + +- Fixed alignment bug in ipx_decode(). Thanks to Matt Crawford + (crawdad@fnal.gov). + +- Fix ntp_print() to not print garbage when the stratum is + "unspecified." Thanks to Deus Ex Machina (root@belle.bork.com). + +- Rewrote tcp options printer code to check for truncation. Added + selective acknowledgment case. + +- Fixed an endian bug in the ospf printer. Thanks to Jeffrey C Honig + (jch@bsdi.com) + +- Fix rip printer to handle 4.4 BSD sockaddr struct which only uses one + octet for the sa_family member. Thanks to Yoshitaka Tokugawa + (toku@dit.co.jp) + +- Don't checksum ip header if we don't have all of it. Thanks to John + Hawkinson (jhawk@mit.edu). + +- Print out hostnames if possible in egp printer. Thanks to Jeffrey + Honig (jhc@bsdi.com) + + +v3.1a1 Wed May 3 19:21:11 PDT 1995 + +- Include time.h when SVR4 is defined to avoid problems under Solaris + 2.3. + +- Fix etheraddr_string() in the ETHER_SERVICE to return the saved + strings, not the local buffer. Thanks to Stefan Petri + (petri@ibr.cs.tu-bs.de). + +- Detect when pcap raises the snaplen (e.g. with snit). Print a warning + that the selected value was not used. Thanks to Pascal Hennequin + (Pascal.Hennequin@hugo.int-evry.fr). + +- Add a truncated packet test to print-nfs.c. Thanks to Pascal Hennequin. + +- BYTEORDER -> BYTE_ORDER Thanks to Terry Kennedy (terry@spcvxa.spc.edu). v3.0.3 Sun Oct 1 18:35:00 GMT 1995 @@ -40,6 +134,9 @@ v3.0.1 Wed Aug 31 22:42:26 PDT 1994 v3.0 Mon Jun 20 19:23:27 PDT 1994 +- Added support for printing tcp option timestamps thanks to + Mark Andrews (mandrews@alias.com). + - Reorganize protocol dumpers to take const pointers to packets so they never change the contents (i.e., they used to do endian conversions in place). Previously, whenever more than one pass was taken over @@ -111,7 +208,7 @@ v2.2 Fri May 22 17:19:41 PDT 1992 - Many improvements to filter code optimizer. - Added 'multicast' keyword and extended the 'broadcast' keyword can now be - so that protocol qualitfications are allowed. For example, "ip broadcast" + so that protocol qualifications are allowed. For example, "ip broadcast" and "ether multicast" are valid filters. - Added support for monitoring the loopback interface (i.e. 'tcpdump -i lo'). diff --git a/usr.sbin/tcpdump/Makefile b/usr.sbin/tcpdump/Makefile index b0b73aab7f6..49208afb198 100644 --- a/usr.sbin/tcpdump/Makefile +++ b/usr.sbin/tcpdump/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.3 1996/06/10 07:47:08 deraadt Exp $ +# $OpenBSD: Makefile,v 1.4 1996/07/13 11:01:05 mickey Exp $ # $NetBSD: Makefile,v 1.6 1995/03/07 23:18:39 mycroft Exp $ # # Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 @@ -24,7 +24,7 @@ PROG= tcpdump MAN= tcpdump.8 -CFLAGS+=-DCSLIP -DPPP -DFDDI -DETHER_SERVICE +CFLAGS+=-DCSLIP -DPPP -DFDDI -DETHER_SERVICE -DRETSIGTYPE=void LDADD+= -lpcap -ll DPADD+= ${LIBL} ${LIBPCAP} @@ -36,6 +36,7 @@ SRCS= tcpdump.c addrtoname.c \ print-snmp.c print-ntp.c print-null.c print-egp.c print-ospf.c \ print-fddi.c print-llc.c print-sunrpc.c \ print-wb.c print-decnet.c print-isoclns.c print-ipx.c \ + print-atm.c print-dvmrp.c print-krb.c print-pim.c \ util.c bpf_dump.c parsenfsfh.c version.c AWKS = atime.awk packetdat.awk send-ack.awk stime.awk diff --git a/usr.sbin/tcpdump/README b/usr.sbin/tcpdump/README index 374272ff879..1fc81620072 100644 --- a/usr.sbin/tcpdump/README +++ b/usr.sbin/tcpdump/README @@ -1,9 +1,8 @@ -$OpenBSD: README,v 1.3 1996/06/10 07:47:09 deraadt Exp $ -$NetBSD: README,v 1.4 1996/05/20 00:41:01 fvdl Exp $ -@(#) Header: README,v 1.39 94/06/20 20:15:16 leres Exp (LBL) +$OpenBSD: README,v 1.4 1996/07/13 11:01:06 mickey Exp $ +@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/README,v 1.4 1996/07/13 11:01:06 mickey Exp $ (LBL) -TCPDUMP 3.0.4 -Lawrence Berkeley Laboratory +TCPDUMP 3.2 +Lawrence Berkeley National Laboratory Network Research Group tcpdump@ee.lbl.gov ftp://ftp.ee.lbl.gov/tcpdump-*.tar.Z @@ -12,31 +11,20 @@ This directory contains source code for tcpdump, a tool for network monitoring and data acquisition. The original distribution is available via anonymous ftp to ftp.ee.lbl.gov, in tcpdump-*.tar.Z. -Tcpdump now uses libcap, a system-independent interface for -user-level packet capture. Before building tcpdump, you must -first retrieve and build libpcap, also from LBL, in: +Tcpdump now uses libcap, a system-independent interface for user-level +packet capture. Before building tcpdump, you must first retrieve and +build libpcap, also from LBL, in: - ftp://ftp.ee.lbl.gov/libpcap-*.tar.Z. + ftp://ftp.ee.lbl.gov/libpcap-*.tar.Z. Once libpcap is built (either install it or make sure it's in ../libpcap), you can build tcpdump using the procedure in the INSTALL file. -Tcpdump and libpcap have been built and tested under SGI Irix 4.x & 5.2, -SunOS 4.x, Solaris 2.3, BSD/386 v1.1, DEC/OSF v1.3 v2.0, and Ultrix 4.x. -SunOS 3.5, 4.3BSD Reno/Tahoe and 4.4BSD are supported as well, but we -currently do not have the resources to carry out testing in these -environments (we suspect you'll run into problems building the most -recent version under these systems -- please send us the patches if -you fix any porting problems). - -Tcpdump has reportedly been ported to Mach 3.0 and Linux, but we have -not received patches to integrate back into the master source tree. - The program is loosely based on SMI's "etherfind" although none of the etherfind code remains. It was originally written by Van Jacobson as part of an ongoing research project to investigate and -improve tcp and internet gateway performance. The parts of the +improve tcp and internet gateway performance. The parts of the program originally taken from Sun's etherfind were later re-written by Steven McCanne of LBL. To insure that there would be no vestige of proprietary code in tcpdump, Steve wrote these pieces from the @@ -53,12 +41,13 @@ protocols in his book ``TCP/IP Illustrated, Volume 1''. If you want to learn more about tcpdump and how to interpret it's output, pick up this book. -Problems, bugs, questions, desirable enhancements, etc., should be -sent to the email address "tcpdump@ee.lbl.gov". +Problems, bugs, questions, desirable enhancements, source code +contributions, etc., should be sent to the email address +"tcpdump@ee.lbl.gov". - - Steve McCanne (mccanne@ee.lbl.gov) - Craig Leres (leres@ee.lbl.gov) - Van Jacobson (van@ee.lbl.gov) + - Steve McCanne + Craig Leres + Van Jacobson ------------------------------------- This directory also contains some short awk programs intended as examples of ways to reduce tcpdump data when you're tracking @@ -70,10 +59,10 @@ send-ack.awk the other only acks, all address information is left off and we just note if the packet is a "send" or an "ack". - There is one output line per line of the original trace. + There is one output line per line of the original trace. Field 1 is the packet time in decimal seconds, relative to the start of the conversation. Field 2 is delta-time - from last packet. Field 3 is packet type/direction. + from last packet. Field 3 is packet type/direction. "Send" means data going from sender to receiver, "ack" means an ack going from the receiver to the sender. A preceding "*" indicates that the data is a retransmission. @@ -88,7 +77,7 @@ send-ack.awk delta-time from the first send of the packet to the current send (on duplicate packets only). Duplicate sends or acks have a number in square brackets showing - the number of duplicates so far. + the number of duplicates so far. Here is a short sample from near the start of an ftp: 3.00 0.20 send . 512 @@ -99,11 +88,11 @@ send-ack.awk 3.82 0.02 * ack . 1536 (0.62) [2] Three seconds into the conversation, bytes 512 through 1023 were sent. 200ms later they were acked. Shortly thereafter - bytes 1024-1535 were sent and again acked after 200ms. + bytes 1024-1535 were sent and again acked after 200ms. Then, for no apparent reason, 0-511 is retransmitted, 3.8 seconds after its initial send (the round trip time for this ftp was 1sec, +-500ms). Since the receiver is expecting - 1536, 1536 is re-acked when 0 arrives. + 1536, 1536 is re-acked when 0 arrives. packetdat.awk Computes chunk summary data for an ftp (or similar @@ -125,7 +114,7 @@ packetdat.awk 4 - time of last send 5 - time of first ack 6 - time of last ack - 7 - number of times chunk was sent + 7 - number of times chunk was sent 8 - number of times chunk was acked (all times are in decimal seconds, relative to the start of the conversation.) @@ -169,7 +158,7 @@ atime.awk The problem I was looking at was the bulk-data-transfer throughput of medium delay network paths (1-6 sec. round trip time) under typical DARPA Internet conditions. The trace of the -ftp transfer of a large file was used as the raw data source. +ftp transfer of a large file was used as the raw data source. The method was: - On a local host (but not the Sun running tcpdump), connect to diff --git a/usr.sbin/tcpdump/addrtoname.c b/usr.sbin/tcpdump/addrtoname.c index a89659a17ca..c885670a06b 100644 --- a/usr.sbin/tcpdump/addrtoname.c +++ b/usr.sbin/tcpdump/addrtoname.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: addrtoname.c,v 1.3 1996/06/10 07:47:10 deraadt Exp $ */ -/* $NetBSD: addrtoname.c,v 1.4 1995/04/24 13:27:39 cgd Exp $ */ +/* $OpenBSD: addrtoname.c,v 1.4 1996/07/13 11:01:06 mickey Exp $ */ /* - * Copyright (c) 1990, 1991, 1992, 1993, 1994 + * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,13 +25,17 @@ */ #ifndef lint static char rcsid[] = - "@(#) Header: addrtoname.c,v 1.37 94/06/16 00:42:28 mccanne Exp (LBL)"; + "@(#) Header: addrtoname.c,v 1.48 96/06/19 00:50:15 leres Exp (LBL)"; #endif #include <sys/types.h> #include <sys/socket.h> #include <sys/time.h> +#if __STDC__ +struct mbuf; +struct rtentry; +#endif #include <net/if.h> #include <netinet/in.h> @@ -47,20 +50,15 @@ static char rcsid[] = #include <signal.h> #include <stdio.h> #include <string.h> -#ifdef __STDC__ #include <stdlib.h> -#endif #include <unistd.h> #include "interface.h" #include "addrtoname.h" #include "llc.h" -static SIGRET nohostname(int); -#ifdef ETHER_SERVICE -struct ether_addr; -extern int ether_ntohost(char *, struct ether_addr *); -#endif +/* Forwards */ +static RETSIGTYPE nohostname(int); /* * hash tables for whatever-to-name translations @@ -69,7 +67,7 @@ extern int ether_ntohost(char *, struct ether_addr *); #define HASHNAMESIZE 4096 struct hnamemem { - u_int32 addr; + u_int32_t addr; char *name; struct hnamemem *nxt; }; @@ -94,7 +92,7 @@ struct enamemem enametable[HASHNAMESIZE]; struct enamemem nsaptable[HASHNAMESIZE]; struct protoidmem { - u_long p_oui; + u_int32_t p_oui; u_short p_proto; char *p_name; struct protoidmem *p_nxt; @@ -106,7 +104,7 @@ struct protoidmem protoidtable[HASHNAMESIZE]; * A faster replacement for inet_ntoa(). */ char * -intoa(u_int32 addr) +intoa(u_int32_t addr) { register char *cp; register u_int byte; @@ -135,9 +133,9 @@ intoa(u_int32 addr) return cp + 1; } -static u_int32 f_netmask; -static u_int32 f_localnet; -static u_int32 netmask; +static u_int32_t f_netmask; +static u_int32_t f_localnet; +static u_int32_t netmask; /* * "getname" is written in this atrocious way to make sure we don't @@ -147,7 +145,7 @@ static u_int32 netmask; jmp_buf getname_env; -static SIGRET +static RETSIGTYPE nohostname(int signo) { longjmp(getname_env, 1); @@ -161,12 +159,11 @@ char * getname(const u_char *ap) { register struct hostent *hp; - register char *cp; - u_int32 addr; + u_int32_t addr; static struct hnamemem *p; /* static for longjmp() */ #ifndef TCPDUMP_ALIGN - addr = *(const u_int32 *)ap; + addr = *(const u_int32_t *)ap; #else /* * Deal with alignment. @@ -174,30 +171,30 @@ getname(const u_char *ap) switch ((long)ap & 3) { case 0: - addr = *(u_int32 *)ap; + addr = *(u_int32_t *)ap; break; case 2: #if BYTE_ORDER == LITTLE_ENDIAN - addr = ((u_int32)*(u_short *)(ap + 2) << 16) | - (u_int32)*(u_short *)ap; + addr = ((u_int32_t)*(u_short *)(ap + 2) << 16) | + (u_int32_t)*(u_short *)ap; #else - addr = ((u_int32)*(u_short *)ap << 16) | - (u_int32)*(u_short *)(ap + 2); + addr = ((u_int32_t)*(u_short *)ap << 16) | + (u_int32_t)*(u_short *)(ap + 2); #endif break; default: #if BYTE_ORDER == LITTLE_ENDIAN - addr = ((u_int32)ap[0] << 24) | - ((u_int32)ap[1] << 16) | - ((u_int32)ap[2] << 8) | - (u_int32)ap[3]; + addr = ((u_int32_t)ap[3] << 24) | + ((u_int32_t)ap[2] << 16) | + ((u_int32_t)ap[1] << 8) | + (u_int32_t)ap[0]; #else - addr = ((u_int32)ap[3] << 24) | - ((u_int32)ap[2] << 16) | - ((u_int32)ap[1] << 8) | - (u_int32)ap[0]; + addr = ((u_int32_t)ap[0] << 24) | + ((u_int32_t)ap[1] << 16) | + ((u_int32_t)ap[2] << 8) | + (u_int32_t)ap[3]; #endif break; } @@ -208,7 +205,7 @@ getname(const u_char *ap) return (p->name); } p->addr = addr; - p->nxt = (struct hnamemem *)calloc(1, sizeof (*p)); + p->nxt = newhnamemem(); /* * Only print names when: @@ -234,21 +231,20 @@ getname(const u_char *ap) /* Remove domain qualifications */ dotp = strchr(p->name, '.'); if (dotp) - *dotp = 0; + *dotp = '\0'; } return (p->name); } } } - cp = intoa(addr); - p->name = savestr(cp); + p->name = savestr(intoa(addr)); return (p->name); } static char hex[] = "0123456789abcdef"; -/* Find the hash node that corresponds the ether address 'ep'. */ +/* Find the hash node that corresponds the ether address 'ep' */ static inline struct enamemem * lookup_emem(const u_char *ep) @@ -272,11 +268,13 @@ lookup_emem(const u_char *ep) tp->e_addr1 = j; tp->e_addr2 = k; tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp)); + if (tp->e_nxt == NULL) + error("lookup_emem: calloc"); return tp; } -/* Find the hash node that corresponds the NSAP 'nsap'. */ +/* Find the hash node that corresponds the NSAP 'nsap' */ static inline struct enamemem * lookup_nsap(register const u_char *nsap) @@ -300,7 +298,7 @@ lookup_nsap(register const u_char *nsap) tp->e_addr1 == j && tp->e_addr2 == k && tp->e_nsap[0] == nlen && - bcmp((char *)&(nsap[1]), + memcmp((char *)&(nsap[1]), (char *)&(tp->e_nsap[1]), nlen) == 0) return tp; else @@ -308,9 +306,13 @@ lookup_nsap(register const u_char *nsap) tp->e_addr0 = i; tp->e_addr1 = j; tp->e_addr2 = k; - tp->e_nsap = (u_char *) calloc(1, nlen + 1); - bcopy(nsap, tp->e_nsap, nlen + 1); + tp->e_nsap = (u_char *)malloc(nlen + 1); + if (tp->e_nsap == NULL) + error("lookup_nsap: malloc"); + memcpy(tp->e_nsap, nsap, nlen + 1); tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp)); + if (tp->e_nxt == NULL) + error("lookup_nsap: calloc"); return tp; } @@ -337,6 +339,8 @@ lookup_protoid(const u_char *pi) tp->p_oui = i; tp->p_proto = j; tp->p_nxt = (struct protoidmem *)calloc(1, sizeof(*tp)); + if (tp->p_nxt == NULL) + error("lookup_protoid: calloc"); return tp; } @@ -347,11 +351,12 @@ etheraddr_string(register const u_char *ep) register u_int i, j; register char *cp; register struct enamemem *tp; + char buf[sizeof("00:00:00:00:00:00")]; tp = lookup_emem(ep); if (tp->e_name) return (tp->e_name); -#ifdef ETHER_SERVICE +#ifdef HAVE_ETHER_NTOHOST if (!nflag) { char buf[128]; if (ether_ntohost(buf, (struct ether_addr *)ep) == 0) { @@ -360,8 +365,7 @@ etheraddr_string(register const u_char *ep) } } #endif - tp->e_name = cp = (char *)malloc(sizeof("00:00:00:00:00:00")); - + cp = buf; if ((j = *ep >> 4) != 0) *cp++ = hex[j]; *cp++ = hex[*ep++ & 0xf]; @@ -372,6 +376,7 @@ etheraddr_string(register const u_char *ep) *cp++ = hex[*ep++ & 0xf]; } *cp = '\0'; + tp->e_name = savestr(buf); return (tp->e_name); } @@ -380,22 +385,24 @@ etherproto_string(u_short port) { register char *cp; register struct hnamemem *tp; - register u_long i = port; + register u_int32_t i = port; + char buf[sizeof("0000")]; for (tp = &eprototable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt) if (tp->addr == i) return (tp->name); - tp->name = cp = (char *)malloc(sizeof("0000")); tp->addr = i; - tp->nxt = (struct hnamemem *)calloc(1, sizeof (*tp)); + tp->nxt = newhnamemem(); + cp = buf; NTOHS(port); *cp++ = hex[port >> 12 & 0xf]; *cp++ = hex[port >> 8 & 0xf]; *cp++ = hex[port >> 4 & 0xf]; *cp++ = hex[port & 0xf]; *cp++ = '\0'; + tp->name = savestr(buf); return (tp->name); } @@ -405,13 +412,13 @@ protoid_string(register const u_char *pi) register u_int i, j; register char *cp; register struct protoidmem *tp; + char buf[sizeof("00:00:00:00:00")]; tp = lookup_protoid(pi); if (tp->p_name) return tp->p_name; - tp->p_name = cp = (char *)malloc(sizeof("00:00:00:00:00")); - + cp = buf; if ((j = *pi >> 4) != 0) *cp++ = hex[j]; *cp++ = hex[*pi++ & 0xf]; @@ -422,6 +429,7 @@ protoid_string(register const u_char *pi) *cp++ = hex[*pi++ & 0xf]; } *cp = '\0'; + tp->p_name = savestr(buf); return (tp->p_name); } @@ -430,21 +438,23 @@ llcsap_string(u_char sap) { register char *cp; register struct hnamemem *tp; - register u_long i = sap; + register u_int32_t i = sap; + char buf[sizeof("sap 00")]; for (tp = &llcsaptable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt) if (tp->addr == i) return (tp->name); - tp->name = cp = (char *)malloc(sizeof("sap 00")); tp->addr = i; - tp->nxt = (struct hnamemem *)calloc(1, sizeof (*tp)); + tp->nxt = newhnamemem(); + cp = buf; (void)strcpy(cp, "sap "); cp += strlen(cp); *cp++ = hex[sap >> 4 & 0xf]; *cp++ = hex[sap & 0xf]; *cp++ = '\0'; + tp->name = savestr(buf); return (tp->name); } @@ -460,6 +470,8 @@ isonsap_string(const u_char *nsap) return tp->e_name; tp->e_name = cp = (char *)malloc(nlen * 2 + 2); + if (cp == NULL) + error("isonsap_string: malloc"); nsap++; *cp++ = '/'; @@ -475,17 +487,18 @@ char * tcpport_string(u_short port) { register struct hnamemem *tp; - register u_long i = port; + register u_int32_t i = port; + char buf[sizeof("00000")]; for (tp = &tporttable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt) if (tp->addr == i) return (tp->name); - tp->name = (char *)malloc(sizeof("00000")); tp->addr = i; - tp->nxt = (struct hnamemem *)calloc(1, sizeof (*tp)); + tp->nxt = newhnamemem(); - (void)sprintf(tp->name, "%d", i); + (void)sprintf(buf, "%u", i); + tp->name = savestr(buf); return (tp->name); } @@ -493,18 +506,18 @@ char * udpport_string(register u_short port) { register struct hnamemem *tp; - register u_long i = port; + register u_int32_t i = port; + char buf[sizeof("00000")]; for (tp = &uporttable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt) if (tp->addr == i) return (tp->name); - tp->name = (char *)malloc(sizeof("00000")); tp->addr = i; - tp->nxt = (struct hnamemem *)calloc(1, sizeof(*tp)); - - (void)sprintf(tp->name, "%d", i); + tp->nxt = newhnamemem(); + (void)sprintf(buf, "%u", i); + tp->name = savestr(buf); return (tp->name); } @@ -514,6 +527,7 @@ init_servarray(void) struct servent *sv; register struct hnamemem *table; register int i; + char buf[sizeof("0000000000")]; while ((sv = getservent()) != NULL) { int port = ntohs(sv->s_port); @@ -528,14 +542,12 @@ init_servarray(void) while (table->name) table = table->nxt; if (nflag) { - char buf[32]; - (void)sprintf(buf, "%d", port); table->name = savestr(buf); } else table->name = savestr(sv->s_name); table->addr = port; - table->nxt = (struct hnamemem *)calloc(1, sizeof(*table)); + table->nxt = newhnamemem(); } endservent(); } @@ -559,7 +571,7 @@ init_eprotoarray(void) table = table->nxt; table->name = eproto_db[i].s; table->addr = ntohs(eproto_db[i].p); - table->nxt = (struct hnamemem *)calloc(1, sizeof(*table)); + table->nxt = newhnamemem(); } } @@ -579,7 +591,8 @@ init_protoidarray(void) protoid[2] = 0; for (i = 0; eproto_db[i].s; i++) { u_short etype = htons(eproto_db[i].p); - bcopy((char *)&etype, (char *)&protoid[3], 2); + + memcpy((char *)&protoid[3], (char *)&etype, 2); tp = lookup_protoid(protoid); tp->p_name = savestr(eproto_db[i].s); } @@ -612,7 +625,9 @@ init_etherarray(void) { register struct etherlist *el; register struct enamemem *tp; -#ifndef ETHER_SERVICE +#ifdef HAVE_ETHER_NTOHOST + char name[256]; +#else register struct pcap_etherent *ep; register FILE *fp; @@ -629,24 +644,23 @@ init_etherarray(void) /* Hardwire some ethernet names */ for (el = etherlist; el->name != NULL; ++el) { -#ifdef ETHER_SERVICE + tp = lookup_emem(el->addr); + /* Don't override existing name */ + if (tp->e_name != NULL) + continue; + +#ifdef HAVE_ETHER_NTOHOST /* Use yp/nis version of name if available */ - char wrk[256]; - if (ether_ntohost(wrk, (struct ether_addr *)el->addr) == 0) { - tp = lookup_emem(el->addr); - tp->e_name = savestr(wrk); + if (ether_ntohost(name, (struct ether_addr *)el->addr) == 0) { + tp->e_name = savestr(name); + continue; } -#else - /* install if not already present */ - tp = lookup_emem(el->addr); - if (tp->e_name == NULL) - tp->e_name = el->name; #endif - + tp->e_name = el->name; } } -static struct token llcsap_db[] = { +static struct tok llcsap_db[] = { { LLCSAP_NULL, "null" }, { LLCSAP_8021B_I, "802.1b-gsap" }, { LLCSAP_8021B_G, "802.1b-isap" }, @@ -673,7 +687,7 @@ init_llcsaparray(void) table = table->nxt; table->name = llcsap_db[i].s; table->addr = llcsap_db[i].v; - table->nxt = (struct hnamemem *)calloc(1, sizeof(*table)); + table->nxt = newhnamemem(); } } @@ -684,7 +698,7 @@ init_llcsaparray(void) * of the local network. mask is its subnet mask. */ void -init_addrtoname(int fflag, u_int32 localnet, u_int32 mask) +init_addrtoname(int fflag, u_int32_t localnet, u_int32_t mask) { netmask = mask; if (fflag) { @@ -715,7 +729,7 @@ dnaddr_string(u_short dnaddr) return (tp->name); tp->addr = dnaddr; - tp->nxt = (struct hnamemem *)calloc(1, sizeof(*tp)); + tp->nxt = newhnamemem(); if (nflag) tp->name = dnnum_string(dnaddr); else @@ -723,3 +737,22 @@ dnaddr_string(u_short dnaddr) return(tp->name); } + +/* Return a zero'ed hnamemem struct and cuts down on calloc() overhead */ +struct hnamemem * +newhnamemem() +{ + register struct hnamemem *p; + static struct hnamemem *ptr = NULL; + static u_int num = 0; + + if (num <= 0) { + num = 64; + ptr = (struct hnamemem *)calloc(num, sizeof (*ptr)); + if (ptr == NULL) + error("newhnamemem: calloc"); + } + --num; + p = ptr++; + return (p); +} diff --git a/usr.sbin/tcpdump/addrtoname.h b/usr.sbin/tcpdump/addrtoname.h index d8bfa938380..ce0d795444c 100644 --- a/usr.sbin/tcpdump/addrtoname.h +++ b/usr.sbin/tcpdump/addrtoname.h @@ -1,8 +1,7 @@ -/**//* $OpenBSD: addrtoname.h,v 1.3 1996/06/10 07:47:11 deraadt Exp $ */ -/* $NetBSD: addrtoname.h,v 1.2 1995/03/06 19:09:50 mycroft Exp $ */ +/* $OpenBSD: addrtoname.h,v 1.4 1996/07/13 11:01:07 mickey Exp $ */ /* - * Copyright (c) 1990, 1992, 1993, 1994 + * Copyright (c) 1990, 1992, 1993, 1994, 1995 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -21,7 +20,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) Header: addrtoname.h,v 1.11 94/06/14 20:11:41 leres Exp (LBL) + * @(#) Header: addrtoname.h,v 1.13 95/05/04 17:52:44 mccanne Exp (LBL) */ /* Name to address translation routines. */ @@ -31,8 +30,9 @@ extern char *etherproto_string(u_short); extern char *tcpport_string(u_short); extern char *udpport_string(u_short); extern char *getname(const u_char *); -extern char *intoa(u_int32); +extern char *intoa(u_int32_t); -extern void init_addrtoname(int, u_int32, u_int32); +extern void init_addrtoname(int, u_int32_t, u_int32_t); +extern struct hnamemem *newhnamemem(void); #define ipaddr_string(p) getname((const u_char *)(p)) diff --git a/usr.sbin/tcpdump/appletalk.h b/usr.sbin/tcpdump/appletalk.h index 537c0242c41..7943072a778 100644 --- a/usr.sbin/tcpdump/appletalk.h +++ b/usr.sbin/tcpdump/appletalk.h @@ -1,8 +1,7 @@ -/**//* $OpenBSD: appletalk.h,v 1.3 1996/06/10 07:47:12 deraadt Exp $ */ -/* $NetBSD: appletalk.h,v 1.2 1995/03/06 19:09:51 mycroft Exp $ */ +/* $OpenBSD: appletalk.h,v 1.4 1996/07/13 11:01:07 mickey Exp $ */ /* - * Copyright (c) 1988, 1989, 1990, 1993, 1994 + * Copyright (c) 1988, 1989, 1990, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,7 +22,7 @@ * * AppleTalk protocol formats (courtesy Bill Croft of Stanford/SUMEX). * - * @(#) Header: appletalk.h,v 1.10 94/06/14 20:11:44 leres Exp (LBL) + * @(#) Header: appletalk.h,v 1.12 96/06/03 02:54:24 leres Exp (LBL) */ struct LAP { @@ -79,7 +78,7 @@ struct atATP { u_char control; u_char bitmap; u_short transID; - int32 userData; + int32_t userData; }; #define atpReqCode 0x40 diff --git a/usr.sbin/tcpdump/bootp.h b/usr.sbin/tcpdump/bootp.h index fcdf35c468f..3ef7248cb14 100644 --- a/usr.sbin/tcpdump/bootp.h +++ b/usr.sbin/tcpdump/bootp.h @@ -1,7 +1,6 @@ -/**//* $OpenBSD: bootp.h,v 1.3 1996/06/10 07:47:13 deraadt Exp $ */ -/* $NetBSD: bootp.h,v 1.2 1995/03/06 19:09:54 mycroft Exp $ */ +/* $OpenBSD: bootp.h,v 1.4 1996/07/13 11:01:08 mickey Exp $ */ -/* @(#) Header: bootp.h,v 1.6 94/01/13 19:06:29 leres Exp (LBL) */ +/* @(#) Header: bootp.h,v 1.7 95/05/04 17:52:46 mccanne Exp (LBL) */ /* * Bootstrap Protocol (BOOTP). RFC951 and RFC1048. * @@ -28,7 +27,7 @@ struct bootp { unsigned char bp_htype; /* hardware addr type */ unsigned char bp_hlen; /* hardware addr length */ unsigned char bp_hops; /* gateway hops */ - u_int32 bp_xid; /* transaction ID */ + u_int32_t bp_xid; /* transaction ID */ unsigned short bp_secs; /* seconds since boot began */ unsigned short bp_unused; struct in_addr bp_ciaddr; /* client IP address */ @@ -98,7 +97,7 @@ struct bootp { struct cmu_vend { unsigned char v_magic[4]; /* magic number */ - u_int32 v_flags; /* flags/opcodes, etc. */ + u_int32_t v_flags; /* flags/opcodes, etc. */ struct in_addr v_smask; /* Subnet mask */ struct in_addr v_dgate; /* Default gateway */ struct in_addr v_dns1, v_dns2; /* Domain name servers */ diff --git a/usr.sbin/tcpdump/bpf_dump.c b/usr.sbin/tcpdump/bpf_dump.c index 133ef496064..ffce0bcdc43 100644 --- a/usr.sbin/tcpdump/bpf_dump.c +++ b/usr.sbin/tcpdump/bpf_dump.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: bpf_dump.c,v 1.3 1996/06/10 07:47:14 deraadt Exp $ */ -/* $NetBSD: bpf_dump.c,v 1.2 1995/03/06 19:09:55 mycroft Exp $ */ +/* $OpenBSD: bpf_dump.c,v 1.4 1996/07/13 11:01:08 mickey Exp $ */ /* - * Copyright (c) 1992, 1993, 1994 + * Copyright (c) 1992, 1993, 1994, 1995 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,7 +22,7 @@ */ #ifndef lint static char rcsid[] = - "@(#) Header: bpf_dump.c,v 1.6 94/06/06 14:31:21 leres Exp (LBL)"; + "@(#) Header: bpf_dump.c,v 1.8 95/10/19 20:28:00 leres Exp (LBL)"; #endif #include <sys/types.h> @@ -47,7 +46,7 @@ bpf_dump(struct bpf_program *p, int option) if (option > 2) { printf("%d\n", n); for (i = 0; i < n; ++insn, ++i) { - printf("%lu %lu %lu %lu\n", insn->code, + printf("%u %u %u %u\n", insn->code, insn->jt, insn->jf, insn->k); } return ; diff --git a/usr.sbin/tcpdump/decnet.h b/usr.sbin/tcpdump/decnet.h index e8c7dfe5a7a..b3c63389551 100644 --- a/usr.sbin/tcpdump/decnet.h +++ b/usr.sbin/tcpdump/decnet.h @@ -1,8 +1,7 @@ -/**//* $OpenBSD: decnet.h,v 1.3 1996/06/10 07:47:15 deraadt Exp $ */ -/* $NetBSD: decnet.h,v 1.2 1995/03/06 19:09:58 mycroft Exp $ */ +/* $OpenBSD: decnet.h,v 1.4 1996/07/13 11:01:08 mickey Exp $ */ /* - * Copyright (c) 1992, 1994 + * Copyright (c) 1992, 1994, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -21,7 +20,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) Header: decnet.h,v 1.3 94/06/14 20:11:44 leres Exp (LBL) + * @(#) Header: decnet.h,v 1.5 96/06/23 02:11:44 leres Exp (LBL) */ typedef unsigned char byte[1]; /* single byte field */ @@ -109,7 +108,7 @@ union routehdr */ #define RMF_CTLMASK 017 /* mask for message type */ #define RMF_CTLMSG 01 /* control message indicator */ -#define RMF_INIT 01 /* initialisation message */ +#define RMF_INIT 01 /* initialization message */ #define RMF_VER 03 /* verification message */ #define RMF_TEST 05 /* hello and test message */ #define RMF_L1ROUT 07 /* level 1 routing message */ @@ -145,7 +144,7 @@ union routehdr /* * Define control message formats. */ -struct initmsgIII /* phase III initialisation message */ +struct initmsgIII /* phase III initialization message */ { byte inIII_flags; /* route flags */ word inIII_src; /* source node address */ @@ -157,7 +156,7 @@ struct initmsgIII /* phase III initialisation message */ byte inIII_rsvd; /* reserved image field */ }; -struct initmsg /* initialisation message */ +struct initmsg /* initialization message */ { byte in_flags; /* route flags */ word in_src; /* source node address */ @@ -232,7 +231,7 @@ struct ehellomsg /* endnode hello message */ union controlmsg { - struct initmsg cm_init; /* initialisation message */ + struct initmsg cm_init; /* initialization message */ struct verifmsg cm_ver; /* verification message */ struct testmsg cm_test; /* hello and test message */ struct l1rout cm_l1rou; /* level 1 routing message */ @@ -340,9 +339,9 @@ union controlmsg #define UC_OBJREJECT 0 /* object rejected connect */ #define UC_USERDISCONNECT 0 /* user disconnect */ #define UC_RESOURCES 1 /* insufficient resources (local or remote) */ -#define UC_NOSUCHNODE 2 /* unrecognised node name */ +#define UC_NOSUCHNODE 2 /* unrecognized node name */ #define UC_REMOTESHUT 3 /* remote node shutting down */ -#define UC_NOSUCHOBJ 4 /* unrecognised object */ +#define UC_NOSUCHOBJ 4 /* unrecognized object */ #define UC_INVOBJFORMAT 5 /* invalid object name format */ #define UC_OBJTOOBUSY 6 /* object too busy */ #define UC_NETWORKABORT 8 /* network abort */ @@ -457,10 +456,10 @@ struct dcmsg /* disconnect confirm message */ /* * Like the macros in extract.h, except that since DECNET is a little-endian - * protocol, the BYTEORDER sense is reversed. + * protocol, the BYTE_ORDER sense is reversed. */ #define EXTRACT_8BITS(p) (*(p)) -#if BYTEORDER == BIG_ENDIAN +#if BYTE_ORDER == BIG_ENDIAN #define EXTRACT_16BITS(p)\ ((u_short)\ (*((u_char *)p+1)<<8|\ diff --git a/usr.sbin/tcpdump/ethertype.h b/usr.sbin/tcpdump/ethertype.h index dbc5aa41f8e..0715241bb35 100644 --- a/usr.sbin/tcpdump/ethertype.h +++ b/usr.sbin/tcpdump/ethertype.h @@ -1,5 +1,4 @@ -/**//* $OpenBSD: ethertype.h,v 1.3 1996/06/10 07:47:15 deraadt Exp $ */ -/* $NetBSD: ethertype.h,v 1.2 1995/03/06 19:10:06 mycroft Exp $ */ +/* $OpenBSD: ethertype.h,v 1.4 1996/07/13 11:01:09 mickey Exp $ */ /* * Copyright (c) 1993, 1994 diff --git a/usr.sbin/tcpdump/extract.h b/usr.sbin/tcpdump/extract.h index c4133e60303..9561f022669 100644 --- a/usr.sbin/tcpdump/extract.h +++ b/usr.sbin/tcpdump/extract.h @@ -1,8 +1,7 @@ -/**//* $OpenBSD: extract.h,v 1.3 1996/06/10 07:47:16 deraadt Exp $ */ -/* $NetBSD: extract.h,v 1.2 1995/03/06 19:10:08 mycroft Exp $ */ +/* $OpenBSD: extract.h,v 1.4 1996/07/13 11:01:09 mickey Exp $ */ /* - * Copyright (c) 1992, 1993, 1994 + * Copyright (c) 1992, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -21,32 +20,20 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) Header: extract.h,v 1.7 94/06/14 20:11:45 leres Exp (LBL) + * @(#) Header: extract.h,v 1.12 96/06/20 18:48:42 leres Exp (LBL) */ -#ifdef TCPDUMP_ALIGN -#if BYTEORDER == LITTLE_ENDIAN +#ifdef LBL_ALIGN #define EXTRACT_SHORT(p)\ ((u_short)\ - ((u_short)*((u_char *)p+1)<<8|\ - (u_short)*((u_char *)p+0)<<0)) + ((u_short)*((u_char *)(p)+0)<<8|\ + (u_short)*((u_char *)(p)+1)<<0)) #define EXTRACT_LONG(p)\ - ((u_int32)*((u_char *)p+3)<<24|\ - (u_int32)*((u_char *)p+2)<<16|\ - (u_int32)*((u_char *)p+1)<<8|\ - (u_int32)*((u_char *)p+0)<<0) + ((u_int32_t)*((u_char *)(p)+0)<<24|\ + (u_int32_t)*((u_char *)(p)+1)<<16|\ + (u_int32_t)*((u_char *)(p)+2)<<8|\ + (u_int32_t)*((u_char *)(p)+3)<<0) #else -#define EXTRACT_SHORT(p)\ - ((u_short)\ - ((u_short)*((u_char *)p+0)<<8|\ - (u_short)*((u_char *)p+1)<<0)) -#define EXTRACT_LONG(p)\ - ((u_int32)*((u_char *)p+0)<<24|\ - (u_int32)*((u_char *)p+1)<<16|\ - (u_int32)*((u_char *)p+2)<<8|\ - (u_int32)*((u_char *)p+3)<<0) -#endif -#else -#define EXTRACT_SHORT(p) ((u_short)ntohs(*(u_short *)p)) -#define EXTRACT_LONG(p) (ntohl(*(u_int32 *)p)) +#define EXTRACT_SHORT(p) ((u_short)ntohs(*(u_short *)(p))) +#define EXTRACT_LONG(p) (ntohl(*(u_int32_t *)(p))) #endif diff --git a/usr.sbin/tcpdump/fddi.h b/usr.sbin/tcpdump/fddi.h index 800284661bc..a97bd3e0477 100644 --- a/usr.sbin/tcpdump/fddi.h +++ b/usr.sbin/tcpdump/fddi.h @@ -1,8 +1,7 @@ -/**//* $OpenBSD: fddi.h,v 1.3 1996/06/10 07:47:17 deraadt Exp $ */ -/* $NetBSD: fddi.h,v 1.2 1995/03/06 19:10:10 mycroft Exp $ */ +/* $OpenBSD: fddi.h,v 1.4 1996/07/13 11:01:09 mickey Exp $ */ /* - * Copyright (c) 1992, 1993, 1994 + * Copyright (c) 1992, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -21,7 +20,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) Header: fddi.h,v 1.6 94/06/14 20:12:35 leres Exp (LBL) + * @(#) Header: fddi.h,v 1.8 96/06/03 03:06:04 leres Exp (LBL) */ /* @@ -35,13 +34,6 @@ */ struct fddi_header { -#if defined(ultrix) || defined(__alpha) - /* Ultrix pads to make everything line up on a nice boundary */ -#define FDDIPAD 3 - u_char fddi_ph[FDDIPAD]; -#else -#define FDDIPAD 0 -#endif u_char fddi_fc; /* frame control */ u_char fddi_dhost[6]; u_char fddi_shost[6]; diff --git a/usr.sbin/tcpdump/interface.h b/usr.sbin/tcpdump/interface.h index c9fc63bc85c..b46827587b3 100644 --- a/usr.sbin/tcpdump/interface.h +++ b/usr.sbin/tcpdump/interface.h @@ -1,8 +1,7 @@ -/**//* $OpenBSD: interface.h,v 1.3 1996/06/10 07:47:18 deraadt Exp $ */ -/* $NetBSD: interface.h,v 1.2 1995/03/06 19:10:18 mycroft Exp $ */ +/* $OpenBSD: interface.h,v 1.4 1996/07/13 11:01:10 mickey Exp $ */ /* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -21,27 +20,17 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) Header: interface.h,v 1.66 94/06/14 20:21:37 leres Exp (LBL) + * @(#) Header: interface.h,v 1.90 96/06/23 02:44:19 leres Exp (LBL) */ -#ifdef __GNUC__ -#define inline __inline -#ifndef __dead -#define __dead volatile -#endif -#else -#define inline -#define __dead -#endif - -#include "os.h" /* operating system stuff */ -#include "md.h" /* machine dependent stuff */ +#ifndef tcpdump_interface_h +#define tcpdump_interface_h -#ifndef SIGRET -#define SIGRET void /* default */ +#ifdef HAVE_OS_PROTO_H +#include "os-proto.h" #endif -struct token { +struct tok { int v; /* value */ char *s; /* string */ }; @@ -56,40 +45,48 @@ extern int tflag; /* print packet arrival time */ extern int vflag; /* verbose */ extern int xflag; /* print packet in hex */ +extern int packettype; /* as specified by -T */ +#define PT_VAT 1 /* Visual Audio Tool */ +#define PT_WB 2 /* distributed White Board */ +#define PT_RPC 3 /* Remote Procedure Call */ +#define PT_RTP 4 /* Real-Time Applications protocol */ +#define PT_RTCP 5 /* Real-Time Applications control protocol */ + extern char *program_name; /* used to generate self-identifying messages */ +extern int32_t thiszone; /* seconds offset from gmt to local time */ + extern int snaplen; /* global pointers to beginning and end of current packet (during printing) */ extern const u_char *packetp; extern const u_char *snapend; -extern int fddipad; /* alignment offset for FDDI headers, in bytes */ +extern int pcap_fddipad; /* alignment offset for FDDI headers,in bytes */ -/* Eliminate some bogus warnings. */ +#ifdef __STDC__ struct timeval; - -typedef void (*printfunc)(u_char *, struct timeval *, int, int); +#endif extern void ts_print(const struct timeval *); -extern int clock_sigfigs(void); -int gmt2local(void); +extern int32_t gmt2local(void); extern int fn_print(const u_char *, const u_char *); extern int fn_printn(const u_char *, u_int, const u_char *); -extern const char *tok2str(const struct token *, const char *, int); +extern const char *tok2str(const struct tok *, const char *, int); extern char *dnaddr_string(u_short); extern char *savestr(const char *); -extern int initdevice(char *, int, int *); extern void wrapup(int); -extern __dead void error(char *, ...); -extern void warning(char *, ...); +#if __STDC__ +extern __dead void error(const char *, ...) + __attribute__((volatile, format (printf, 1, 2))); +extern void warning(const char *, ...) __attribute__ ((format (printf, 1, 2))); +#endif extern char *read_infile(char *); extern char *copy_argv(char **); -extern void usage(void); extern char *isonsap_string(const u_char *); extern char *llcsap_string(u_char); extern char *protoid_string(const u_char *); @@ -98,8 +95,11 @@ extern char *dnnum_string(u_short); /* The printer routines. */ +#ifdef __STDC__ struct pcap_pkthdr; +#endif +extern void atm_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); extern void ether_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); extern void fddi_if_print(u_char *, const struct pcap_pkthdr *, const u_char*); @@ -135,6 +135,9 @@ extern void snmp_print(const u_char *, int); extern void sunrpcrequest_print(const u_char *, int, const u_char *); extern void tftp_print(const u_char *, int); extern void wb_print(const void *, int); +extern void dvmrp_print(const u_char *, int); +extern void pim_print(const u_char *, int); +extern void krb_print(const u_char *, int); #define min(a,b) ((a)>(b)?(b):(a)) #define max(a,b) ((b)>(a)?(b):(a)) @@ -151,3 +154,47 @@ extern void wb_print(const void *, int); #define BIG_ENDIAN 4321 #define LITTLE_ENDIAN 1234 #endif + +#ifdef ETHER_HEADER_HAS_EA +#define ESRC(ep) ((ep)->ether_shost.ether_addr_octet) +#define EDST(ep) ((ep)->ether_dhost.ether_addr_octet) +#else +#define ESRC(ep) ((ep)->ether_shost) +#define EDST(ep) ((ep)->ether_dhost) +#endif + +#ifdef ETHER_ARP_HAS_X +#define SHA(ap) ((ap)->arp_xsha) +#define THA(ap) ((ap)->arp_xtha) +#define SPA(ap) ((ap)->arp_xspa) +#define TPA(ap) ((ap)->arp_xtpa) +#else +#ifdef ETHER_ARP_HAS_EA +#define SHA(ap) ((ap)->arp_sha.ether_addr_octet) +#define THA(ap) ((ap)->arp_tha.ether_addr_octet) +#else +#define SHA(ap) ((ap)->arp_sha) +#define THA(ap) ((ap)->arp_tha) +#endif +#define SPA(ap) ((ap)->arp_spa) +#define TPA(ap) ((ap)->arp_tpa) +#endif + +#ifndef NTOHL +#define NTOHL(x) (x) = ntohl(x) +#define NTOHS(x) (x) = ntohs(x) +#define HTONL(x) (x) = htonl(x) +#define HTONS(x) (x) = htons(x) +#endif + +/* some systems don't define these */ +#ifndef ETHERTYPE_REVARP +#define ETHERTYPE_REVARP 0x8035 +#endif + +#ifndef REVARP_REQUEST +#define REVARP_REQUEST 3 +#define REVARP_REPLY 4 +#endif + +#endif diff --git a/usr.sbin/tcpdump/ipx.h b/usr.sbin/tcpdump/ipx.h index 1bc24796028..932f1acd96f 100644 --- a/usr.sbin/tcpdump/ipx.h +++ b/usr.sbin/tcpdump/ipx.h @@ -1,5 +1,4 @@ -/**//* $OpenBSD: ipx.h,v 1.3 1996/06/10 07:47:19 deraadt Exp $ */ -/* $NetBSD: ipx.h,v 1.2 1995/03/06 19:10:19 mycroft Exp $ */ +/* $OpenBSD: ipx.h,v 1.4 1996/07/13 11:01:10 mickey Exp $ */ /* * IPX protocol formats diff --git a/usr.sbin/tcpdump/llc.h b/usr.sbin/tcpdump/llc.h index 34f7ac14d36..850fd4f49c9 100644 --- a/usr.sbin/tcpdump/llc.h +++ b/usr.sbin/tcpdump/llc.h @@ -1,5 +1,4 @@ -/**//* $OpenBSD: llc.h,v 1.3 1996/06/10 07:47:20 deraadt Exp $ */ -/* $NetBSD: llc.h,v 1.2 1995/03/06 19:10:20 mycroft Exp $ */ +/* $OpenBSD: llc.h,v 1.4 1996/07/13 11:01:11 mickey Exp $ */ /* * Copyright (c) 1993, 1994 diff --git a/usr.sbin/tcpdump/makemib b/usr.sbin/tcpdump/makemib index 15d3e463353..74b6d073fe5 100644 --- a/usr.sbin/tcpdump/makemib +++ b/usr.sbin/tcpdump/makemib @@ -1,6 +1,6 @@ #!/bin/sh # -# $OpenBSD: makemib,v 1.3 1996/06/10 07:47:20 deraadt Exp $ +# $OpenBSD: makemib,v 1.4 1996/07/13 11:01:11 mickey Exp $ # $NetBSD: makemib,v 1.2 1995/03/06 19:10:22 mycroft Exp $ # # Copyright (c) 1990, by John Robert LoVerso. @@ -16,8 +16,7 @@ # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTIBILITY 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 2.1 90/07/10 23:51:54 loverso Exp Locker: loverso (jlv) # # This script will read either ASN.1-style MIB files or the ".defs" files @@ -52,7 +51,7 @@ sed \ -e 's/--.*//' \ -e 's/\([{}]\)/ \1 /g' \ $@ \ -| gawk ' +| awk ' BEGIN { # for sanity, we prep the namespace with objects from RFC-1155 # (we manually establish the root) diff --git a/usr.sbin/tcpdump/mib.h b/usr.sbin/tcpdump/mib.h index 2017d5f7a6f..41e59de5a0b 100644 --- a/usr.sbin/tcpdump/mib.h +++ b/usr.sbin/tcpdump/mib.h @@ -1,6 +1,4 @@ -/**//* $OpenBSD: mib.h,v 1.3 1996/06/10 07:47:22 deraadt Exp $ */ -/* $NetBSD: mib.h,v 1.2 1995/03/06 19:10:34 mycroft Exp $ */ - +/* $OpenBSD: mib.h,v 1.4 1996/07/13 11:01:12 mickey Exp $ */ /* * This file was generated by tcpdump/makemib on Wed Sep 26 12:12:31 EDT 1990 * You probably don't want to edit this by hand! diff --git a/usr.sbin/tcpdump/nfs.h b/usr.sbin/tcpdump/nfs.h index de71253086e..0ffa071605b 100644 --- a/usr.sbin/tcpdump/nfs.h +++ b/usr.sbin/tcpdump/nfs.h @@ -1,4 +1,4 @@ -/**//* $OpenBSD: nfs.h,v 1.1 1996/06/10 07:51:10 deraadt Exp $ */ +/* $OpenBSD: nfs.h,v 1.2 1996/07/13 11:01:12 mickey Exp $ */ /* $NetBSD: nfs.h,v 1.1 1996/05/23 22:49:53 fvdl Exp $ */ /* diff --git a/usr.sbin/tcpdump/nfsfh.h b/usr.sbin/tcpdump/nfsfh.h index a99bba34308..8f879d51ba8 100644 --- a/usr.sbin/tcpdump/nfsfh.h +++ b/usr.sbin/tcpdump/nfsfh.h @@ -1,8 +1,7 @@ -/**//* $OpenBSD: nfsfh.h,v 1.3 1996/06/10 07:47:23 deraadt Exp $ */ -/* $NetBSD: nfsfh.h,v 1.3 1996/05/20 00:41:03 fvdl Exp $ */ +/* $OpenBSD: nfsfh.h,v 1.4 1996/07/13 11:01:13 mickey Exp $ */ /* - * Header: nfsfh.h,v 1.3 94/06/12 14:32:58 leres Exp + * Header: nfsfh.h,v 1.4 95/10/19 20:27:44 leres Exp * * nfsfh.h - NFS file handle definitions (for portable use) * @@ -16,8 +15,8 @@ * that we might be spying upon use different external representations. */ typedef struct { - u_long Minor; /* upper case to avoid clashing with macro names */ - u_long Major; + u_int32_t Minor; /* upper case to avoid clashing with macro names */ + u_int32_t Major; } my_devt; #define dev_eq(a,b) ((a.Minor == b.Minor) && (a.Major == b.Major)) @@ -28,10 +27,10 @@ typedef struct { */ typedef struct { my_devt fsid_dev; - u_long fsid_code; + u_int32_t fsid_code; } my_fsid; #define fsid_eq(a,b) ((a.fsid_code == b.fsid_code) &&\ dev_eq(a.fsid_dev, b.fsid_dev)) -extern void Parse_fh(caddr_t *, int, my_fsid *, ino_t *, char **, char **, int); +extern void Parse_fh(caddr_t *, my_fsid *, ino_t *, char **, char **, int); diff --git a/usr.sbin/tcpdump/ntp.h b/usr.sbin/tcpdump/ntp.h index b0c7b03d82d..2ef4564b7b9 100644 --- a/usr.sbin/tcpdump/ntp.h +++ b/usr.sbin/tcpdump/ntp.h @@ -1,7 +1,6 @@ -/**//* $OpenBSD: ntp.h,v 1.3 1996/06/10 07:47:25 deraadt Exp $ */ -/* $NetBSD: ntp.h,v 1.2 1995/03/06 19:10:41 mycroft Exp $ */ +/* $OpenBSD: ntp.h,v 1.4 1996/07/13 11:01:13 mickey Exp $ */ -/* Header: ntp.h,v 1.2 93/11/12 21:43:36 mccanne Exp */ +/* Header: ntp.h,v 1.3 95/05/04 17:52:49 mccanne Exp */ /* * Based on ntp.h from the U of MD implementation @@ -31,8 +30,8 @@ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ struct l_fixedpt { - u_int32 int_part; - u_int32 fraction; + u_int32_t int_part; + u_int32_t fraction; }; struct s_fixedpt { @@ -77,7 +76,7 @@ struct ntpdata { int precision:8; struct s_fixedpt distance; struct s_fixedpt dispersion; - u_int32 refid; + u_int32_t refid; struct l_fixedpt reftime; struct l_fixedpt org; struct l_fixedpt rec; diff --git a/usr.sbin/tcpdump/ospf.h b/usr.sbin/tcpdump/ospf.h index 017b9353e0c..67419f3d793 100644 --- a/usr.sbin/tcpdump/ospf.h +++ b/usr.sbin/tcpdump/ospf.h @@ -1,8 +1,7 @@ -/**//* $OpenBSD: ospf.h,v 1.3 1996/06/10 07:47:26 deraadt Exp $ */ -/* $NetBSD: ospf.h,v 1.2 1995/03/06 19:10:57 mycroft Exp $ */ +/* $OpenBSD: ospf.h,v 1.4 1996/07/13 11:01:14 mickey Exp $ */ /* - * Copyright (c) 1991, 1993, 1994 + * Copyright (c) 1991, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -96,7 +95,7 @@ struct lsa_hdr { u_char ls_type; struct in_addr ls_stateid; struct in_addr ls_router; - u_int32 ls_seq; + u_int32_t ls_seq; u_short ls_chksum; u_short ls_length; } ; @@ -130,14 +129,14 @@ struct lsa { /* Summary links advertisements */ struct { struct in_addr sla_mask; - u_int32 sla_tosmetric[1]; /* may repeat */ + u_int32_t sla_tosmetric[1]; /* may repeat */ } un_sla; /* AS external links advertisements */ struct { struct in_addr asla_mask; struct aslametric { - u_int32 asla_tosmetric; + u_int32_t asla_tosmetric; struct in_addr asla_forward; struct in_addr asla_tag; } asla_metric[1]; /* may repeat */ @@ -145,7 +144,7 @@ struct lsa { /* Multicast group membership */ struct mcla { - u_int32 mcla_vtype; + u_int32_t mcla_vtype; struct in_addr mcla_vid; } un_mcla[1]; } lsa_un; @@ -183,7 +182,7 @@ struct ospfhdr { u_short hello_helloint; u_char hello_options; u_char hello_priority; - u_int32 hello_deadint; + u_int32_t hello_deadint; struct in_addr hello_dr; struct in_addr hello_bdr; struct in_addr hello_neighbor[1]; /* may repeat */ @@ -194,24 +193,24 @@ struct ospfhdr { u_char db_zero[2]; u_char db_options; u_char db_flags; - u_int32 db_seq; + u_int32_t db_seq; struct lsa_hdr db_lshdr[1]; /* may repeat */ } un_db; /* Link State Request */ struct lsr { - u_int32 ls_type; + u_int32_t ls_type; struct in_addr ls_stateid; struct in_addr ls_router; } un_lsr[1]; /* may repeat */ /* Link State Update */ struct { - u_int32 lsu_count; + u_int32_t lsu_count; struct lsa lsu_lsa[1]; /* may repeat */ } un_lsu; - /* Link State Acknowledment */ + /* Link State Acknowledgement */ struct { struct lsa_hdr lsa_lshdr[1]; /* may repeat */ } un_lsa ; diff --git a/usr.sbin/tcpdump/parsenfsfh.c b/usr.sbin/tcpdump/parsenfsfh.c index 46f8d923e92..08637b62688 100644 --- a/usr.sbin/tcpdump/parsenfsfh.c +++ b/usr.sbin/tcpdump/parsenfsfh.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: parsenfsfh.c,v 1.3 1996/06/10 07:47:28 deraadt Exp $ */ -/* $NetBSD: parsenfsfh.c,v 1.3 1996/05/20 00:41:07 fvdl Exp $ */ +/* $OpenBSD: parsenfsfh.c,v 1.4 1996/07/13 11:01:14 mickey Exp $ */ #ifndef lint -static char *RCSid = "Header: parsenfsfh.c,v 1.5 94/01/13 19:06:41 leres Exp"; +static char *RCSid = "Header: parsenfsfh.c,v 1.9 95/10/19 20:27:44 leres Exp"; #endif /* @@ -17,22 +16,15 @@ static char *RCSid = "Header: parsenfsfh.c,v 1.5 94/01/13 19:06:41 leres Exp"; #include <sys/types.h> #include <sys/time.h> -#include <stdio.h> #include <ctype.h> +#include <memory.h> +#include <stdio.h> #include <string.h> #include "interface.h" #include "nfsfh.h" /* - * Make sure that we use 32-bit integers when necessary. The "x" - * suffix is to avoid possible identifier conflicts. - */ - -typedef int int32x; -typedef unsigned int u_int32x; - -/* * This routine attempts to parse a file handle (in network byte order), * using heuristics to guess what kind of format it is in. See the * file "fhandle_layouts" for a detailed description of the various @@ -57,7 +49,7 @@ typedef unsigned int u_int32x; #ifdef ultrix /* Nasty hack to keep the Ultrix C compiler from emitting bogus warnings */ -#define XFF(x) ((unsigned long)(x)) +#define XFF(x) ((u_int32_t)(x)) #else #define XFF(x) (x) #endif @@ -84,9 +76,8 @@ typedef unsigned int u_int32x; static int is_UCX(unsigned char *); void -Parse_fh(fh, len, fsidp, inop, osnamep, fsnamep, ourself) +Parse_fh(fh, fsidp, inop, osnamep, fsnamep, ourself) register caddr_t *fh; -int len; my_fsid *fsidp; ino_t *inop; char **osnamep; /* if non-NULL, return OS name here */ @@ -94,7 +85,7 @@ char **fsnamep; /* if non-NULL, return server fs name here (for VMS) */ int ourself; /* true if file handle was generated on this host */ { register unsigned char *fhp = (unsigned char *)fh; - u_int32x temp; + u_int32_t temp; int fhtype = FHT_UNKNOWN; if (ourself) { @@ -321,14 +312,14 @@ int ourself; /* true if file handle was generated on this host */ /* No numeric file system ID, so hash on the device-name */ if (sizeof(*fsidp) >= 14) { if (sizeof(*fsidp) > 14) - bzero((char *)fsidp, sizeof(*fsidp)); - bcopy(fh, (char *)fsidp, 14); /* just use the whole thing */ + memset((char *)fsidp, 0, sizeof(*fsidp)); + memcpy((char *)fsidp, fh, 14); /* just use the whole thing */ } else { - u_long tempa[4]; /* at least 16 bytes, maybe more */ + u_int32_t tempa[4]; /* at least 16 bytes, maybe more */ - bzero((char *)tempa, sizeof(tempa)); - bcopy(fh, (char *)tempa, 14); /* ensure alignment */ + memset((char *)tempa, 0, sizeof(tempa)); + memcpy((char *)tempa, fh, 14); /* ensure alignment */ fsidp->fsid_dev.Minor = tempa[0] + (tempa[1]<<1); fsidp->fsid_dev.Major = tempa[2] + (tempa[3]<<1); fsidp->fsid_code = 0; @@ -375,8 +366,9 @@ int ourself; /* true if file handle was generated on this host */ { /* XXX debugging */ int i; - for (i=0; i<32;i++) fprintf(stderr, "%x.", fhp[i]); - fprintf(stderr, "\n"); + for (i = 0; i < 32; i++) + (void)fprintf(stderr, "%x.", fhp[i]); + (void)fprintf(stderr, "\n"); } #endif /* XXX for now, give "bogus" values to aid debugging */ diff --git a/usr.sbin/tcpdump/print-arp.c b/usr.sbin/tcpdump/print-arp.c index 30cefdfe6af..ce70238085f 100644 --- a/usr.sbin/tcpdump/print-arp.c +++ b/usr.sbin/tcpdump/print-arp.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-arp.c,v 1.3 1996/06/10 07:47:29 deraadt Exp $ */ -/* $NetBSD: print-arp.c,v 1.2 1995/03/06 19:11:02 mycroft Exp $ */ +/* $OpenBSD: print-arp.c,v 1.4 1996/07/13 11:01:15 mickey Exp $ */ /* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,22 +23,32 @@ #ifndef lint static char rcsid[] = - "@(#) Header: print-arp.c,v 1.28 94/06/14 20:17:36 leres Exp (LBL)"; + "@(#) Header: print-arp.c,v 1.35 96/06/20 21:07:34 leres Exp (LBL)"; #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> #include <stdio.h> +#include <string.h> #include "interface.h" #include "addrtoname.h" +#include "extract.h" /* must come after interface.h */ + +#ifndef ETHERTYPE_TRAIL +#define ETHERTYPE_TRAIL 0x1000 +#endif static u_char ezero[6]; @@ -48,8 +57,7 @@ arp_print(register const u_char *bp, int length, int caplen) { register const struct ether_arp *ap; register const struct ether_header *eh; - const u_char *p; - int pro, hrd, op; + register u_short pro, hrd, op; ap = (struct ether_arp *)bp; if ((u_char *)(ap + 1) > snapend) { @@ -61,15 +69,10 @@ arp_print(register const u_char *bp, int length, int caplen) default_print((u_char *)ap, length); return; } - /* - * Don't assume alignment. - */ - p = (u_char*)&ap->arp_pro; - pro = (p[0] << 8) | p[1]; - p = (u_char*)&ap->arp_hrd; - hrd = (p[0] << 8) | p[1]; - p = (u_char*)&ap->arp_op; - op = (p[0] << 8) | p[1]; + + pro = EXTRACT_SHORT(&ap->arp_pro); + hrd = EXTRACT_SHORT(&ap->arp_hrd); + op = EXTRACT_SHORT(&ap->arp_op); if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) || ap->arp_hln != sizeof(SHA(ap)) @@ -86,19 +89,19 @@ arp_print(register const u_char *bp, int length, int caplen) case ARPOP_REQUEST: (void)printf("arp who-has %s", ipaddr_string(TPA(ap))); - if (bcmp((char *)ezero, (char *)THA(ap), 6) != 0) + if (memcmp((char *)ezero, (char *)THA(ap), 6) != 0) (void)printf(" (%s)", etheraddr_string(THA(ap))); (void)printf(" tell %s", ipaddr_string(SPA(ap))); - if (bcmp((char *)ESRC(eh), (char *)SHA(ap), 6) != 0) + if (memcmp((char *)ESRC(eh), (char *)SHA(ap), 6) != 0) (void)printf(" (%s)", etheraddr_string(SHA(ap))); break; case ARPOP_REPLY: (void)printf("arp reply %s", ipaddr_string(SPA(ap))); - if (bcmp((char *)ESRC(eh), (char *)SHA(ap), 6) != 0) + if (memcmp((char *)ESRC(eh), (char *)SHA(ap), 6) != 0) (void)printf(" (%s)", etheraddr_string(SHA(ap))); (void)printf(" is-at %s", etheraddr_string(SHA(ap))); - if (bcmp((char *)EDST(eh), (char *)THA(ap), 6) != 0) + if (memcmp((char *)EDST(eh), (char *)THA(ap), 6) != 0) (void)printf(" (%s)", etheraddr_string(THA(ap))); break; diff --git a/usr.sbin/tcpdump/print-atalk.c b/usr.sbin/tcpdump/print-atalk.c index f0db7b5d6d7..3f096fc6e82 100644 --- a/usr.sbin/tcpdump/print-atalk.c +++ b/usr.sbin/tcpdump/print-atalk.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-atalk.c,v 1.3 1996/06/10 07:47:30 deraadt Exp $ */ -/* $NetBSD: print-atalk.c,v 1.3 1995/03/06 19:11:04 mycroft Exp $ */ +/* $OpenBSD: print-atalk.c,v 1.4 1996/07/13 11:01:15 mickey Exp $ */ /* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,7 +24,7 @@ */ #ifndef lint static char rcsid[] = - "@(#)Header: print-atalk.c,v 1.36 94/06/20 19:44:34 leres Exp (LBL)"; + "@(#)Header: print-atalk.c,v 1.40 95/10/07 22:13:43 leres Exp (LBL)"; #endif #include <sys/param.h> @@ -33,6 +32,10 @@ static char rcsid[] = #include <sys/types.h> #include <sys/socket.h> +#if __STDC__ +struct mbuf; +struct rtentry; +#endif #include <net/if.h> #include <netinet/in.h> @@ -46,9 +49,7 @@ static char rcsid[] = #include <netinet/tcpip.h> #include <stdio.h> -#ifdef __STDC__ #include <stdlib.h> -#endif #include <string.h> #include "interface.h" @@ -57,7 +58,7 @@ static char rcsid[] = #include "extract.h" /* must come after interface.h */ #include "appletalk.h" -static struct token type2str[] = { +static struct tok type2str[] = { { ddpRTMP, "rtmp" }, { ddpRTMPrequest, "rtmpReq" }, { ddpECHO, "echo" }, @@ -211,7 +212,7 @@ static void atp_print(register const struct atATP *ap, int length) { char c; - u_int32 data; + u_int32_t data; if ((const u_char *)(ap + 1) > snapend) { /* Just bail if we don't have the whole chunk. */ @@ -519,7 +520,7 @@ ataddr_string(u_short atnet, u_char athost) tp->nxt; tp = tp->nxt) ; tp->addr = i3; - tp->nxt = (struct hnamemem *)calloc(1, sizeof(*tp)); + tp->nxt = newhnamemem(); tp->name = savestr(nambuf); } fclose(fp); @@ -534,26 +535,25 @@ ataddr_string(u_short atnet, u_char athost) for (tp2 = &hnametable[i & (HASHNAMESIZE-1)]; tp2->nxt; tp2 = tp2->nxt) if (tp2->addr == i) { tp->addr = (atnet << 8) | athost; - tp->nxt = (struct hnamemem *)calloc(1, sizeof(*tp)); + tp->nxt = newhnamemem(); (void)sprintf(nambuf, "%s.%d", tp2->name, athost); tp->name = savestr(nambuf); return (tp->name); } tp->addr = (atnet << 8) | athost; - tp->nxt = (struct hnamemem *)calloc(1, sizeof(*tp)); + tp->nxt = newhnamemem(); if (athost != 255) (void)sprintf(nambuf, "%d.%d.%d", atnet >> 8, atnet & 0xff, athost); else (void)sprintf(nambuf, "%d.%d", atnet >> 8, atnet & 0xff); - i = strlen(nambuf) + 1; - tp->name = strcpy(malloc((u_int) i), nambuf); + tp->name = savestr(nambuf); return (tp->name); } -static struct token skt2str[] = { +static struct tok skt2str[] = { { rtmpSkt, "rtmp" }, /* routing table maintenance */ { nbpSkt, "nis" }, /* name info socket */ { echoSkt, "echo" }, /* AppleTalk echo protocol */ diff --git a/usr.sbin/tcpdump/print-atm.c b/usr.sbin/tcpdump/print-atm.c new file mode 100644 index 00000000000..65e35c81224 --- /dev/null +++ b/usr.sbin/tcpdump/print-atm.c @@ -0,0 +1,150 @@ +/* $OpenBSD: print-atm.c,v 1.1 1996/07/13 11:01:15 mickey Exp $ */ + +/* + * Copyright (c) 1994, 1995 + * 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 char rcsid[] = + "@(#) Header: print-atm.c,v 1.4 95/10/07 22:13:49 leres Exp (LBL)"; +#endif + +#include <sys/param.h> +#include <sys/time.h> +#include <sys/types.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> +#include <netinet/tcpip.h> + +#include <stdio.h> +#include <pcap.h> + +#include "interface.h" +#include "addrtoname.h" + +/* + * This is the top level routine of the printer. 'p' is the points + * to the LLC/SNAP header of the packet, 'tvp' is the timestamp, + * 'length' is the length of the packet off the wire, and 'caplen' + * is the number of bytes actually captured. + */ +void +atm_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) +{ + int caplen = h->caplen; + int length = h->len; + u_short ethertype; + + ts_print(&h->ts); + + if (caplen < 8) { + printf("[|atm]"); + goto out; + } + if (p[0] != 0xaa || p[1] != 0xaa || p[2] != 0x03) { + /*XXX assume 802.6 MAC header from fore driver */ + if (eflag) + printf("%04x%04x %04x%04x ", + p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3], + p[4] << 24 | p[5] << 16 | p[6] << 8 | p[7], + p[8] << 24 | p[9] << 16 | p[10] << 8 | p[11], + p[12] << 24 | p[13] << 16 | p[14] << 8 | p[15]); + p += 20; + length -= 20; + caplen -= 20; + } + ethertype = p[6] << 8 | p[7]; + if (eflag) + printf("%02x %02x %02x %02x-%02x-%02x %04x: ", + p[0], p[1], p[2], /* dsap/ssap/ctrl */ + p[3], p[4], p[5], /* manufacturer's code */ + ethertype); + + /* + * 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 -= 8; + caplen -= 8; + p += 8; + + switch (ethertype) { + + case ETHERTYPE_IP: + ip_print(p, length); + break; + + /*XXX this probably isn't right */ + case ETHERTYPE_ARP: + case ETHERTYPE_REVARP: + arp_print(p, length, caplen); + break; +#ifdef notyet + case ETHERTYPE_DN: + decnet_print(p, length, caplen); + break; + + case ETHERTYPE_ATALK: + if (vflag) + fputs("et1 ", stdout); + atalk_print(p, length); + break; + + case ETHERTYPE_AARP: + aarp_print(p, length); + break; + + case ETHERTYPE_LAT: + case ETHERTYPE_MOPRC: + case ETHERTYPE_MOPDL: + /* default_print for now */ +#endif + default: + /* ether_type not known, print raw packet */ + if (!eflag) + printf("%02x %02x %02x %02x-%02x-%02x %04x: ", + p[0], p[1], p[2], /* dsap/ssap/ctrl */ + p[3], p[4], p[5], /* manufacturer's code */ + ethertype); + if (!xflag && !qflag) + default_print(p, caplen); + } + if (xflag) + default_print(p, caplen); + out: + putchar('\n'); +} diff --git a/usr.sbin/tcpdump/print-bootp.c b/usr.sbin/tcpdump/print-bootp.c index d60023b9cfa..3deff920d10 100644 --- a/usr.sbin/tcpdump/print-bootp.c +++ b/usr.sbin/tcpdump/print-bootp.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-bootp.c,v 1.3 1996/06/10 07:47:31 deraadt Exp $ */ -/* $NetBSD: print-bootp.c,v 1.2 1995/03/06 19:11:05 mycroft Exp $ */ +/* $OpenBSD: print-bootp.c,v 1.4 1996/07/13 11:01:16 mickey Exp $ */ /* - * Copyright (c) 1990, 1991, 1993, 1994 + * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,7 +24,7 @@ */ #ifndef lint static char rcsid[] = - "@(#) Header: print-bootp.c,v 1.30 94/06/14 20:17:37 leres Exp (LBL)"; + "@(#) Header: print-bootp.c,v 1.38 96/06/23 02:11:45 leres Exp (LBL)"; #endif #include <sys/param.h> @@ -33,6 +32,10 @@ static char rcsid[] = #include <sys/types.h> #include <sys/socket.h> +#if __STDC__ +struct mbuf; +struct rtentry; +#endif #include <net/if.h> #include <netinet/in.h> @@ -40,6 +43,7 @@ static char rcsid[] = #include <ctype.h> #include <stdio.h> +#include <string.h> #include "interface.h" #include "addrtoname.h" @@ -65,7 +69,7 @@ bootp_print(register const u_char *cp, int length, #define TCHECK(var, l) if ((u_char *)&(var) > ep - l) goto trunc bp = (struct bootp *)cp; - /* 'ep' points to the end of avaible data. */ + /* 'ep' points to the end of available data. */ ep = snapend; TCHECK(bp->bp_op, sizeof(bp->bp_op)); @@ -101,7 +105,7 @@ bootp_print(register const u_char *cp, int length, if (bp->bp_hops) printf(" hops:%d", bp->bp_hops); if (bp->bp_xid) - printf(" xid:0x%x", ntohl(bp->bp_xid)); + printf(" xid:0x%x", (u_int32_t)ntohl(bp->bp_xid)); if (bp->bp_secs) printf(" secs:%d", ntohs(bp->bp_secs)); @@ -138,7 +142,7 @@ bootp_print(register const u_char *cp, int length, e = (const char *)EDST(eh); else e = 0; - if (e == 0 || bcmp((char *)bp->bp_chaddr, e, 6) != 0) + if (e == 0 || memcmp((char *)bp->bp_chaddr, e, 6) != 0) printf(" ether %s", etheraddr_string(bp->bp_chaddr)); } @@ -162,16 +166,16 @@ bootp_print(register const u_char *cp, int length, /* Decode the vendor buffer */ TCHECK(bp->bp_vend[0], sizeof(bp->bp_vend)); length -= sizeof(*bp) - sizeof(bp->bp_vend); - if (bcmp((char *)bp->bp_vend, (char *)vm_rfc1048, - sizeof(u_int32)) == 0) + if (memcmp((char *)bp->bp_vend, (char *)vm_rfc1048, + sizeof(u_int32_t)) == 0) rfc1048_print(bp->bp_vend, length); - else if (bcmp((char *)bp->bp_vend, (char *)vm_cmu, - sizeof(u_int32)) == 0) + else if (memcmp((char *)bp->bp_vend, (char *)vm_cmu, + sizeof(u_int32_t)) == 0) cmu_print(bp->bp_vend, length); else { - u_int32 ul; + u_int32_t ul; - bcopy((char *)bp->bp_vend, (char *)&ul, sizeof(ul)); + memcpy((char *)&ul, (char *)bp->bp_vend, sizeof(ul)); if (ul != 0) printf("vend-#0x%x", ul); } @@ -183,7 +187,7 @@ trunc: } /* The first character specifies the format to print */ -static struct token tag2str[] = { +static struct tok tag2str[] = { /* RFC1048 tags */ { TAG_PAD, " PAD" }, { TAG_SUBNET_MASK, "iSM" }, /* subnet mask (RFC950) */ @@ -218,7 +222,7 @@ rfc1048_print(register const u_char *bp, register int length) register const char *cp; register char c; int first; - u_int32 ul; + u_int32_t ul; u_short us; printf(" vend-rfc1048"); @@ -227,7 +231,7 @@ rfc1048_print(register const u_char *bp, register int length) ep = bp + length; /* Step over magic cookie */ - bp += sizeof(int32); + bp += sizeof(int32_t); /* Loop while we there is a tag left in the buffer */ while (bp + 1 < ep) { @@ -278,11 +282,11 @@ rfc1048_print(register const u_char *bp, register int length) while (size >= sizeof(ul)) { if (!first) putchar(','); - bcopy((char *)bp, (char *)&ul, sizeof(ul)); + memcpy((char *)&ul, (char *)bp, sizeof(ul)); if (c == 'i') printf("%s", ipaddr_string(&ul)); else - printf("%lu", ul); + printf("%u", ul); bp += sizeof(ul); size -= sizeof(ul); first = 0; @@ -294,7 +298,7 @@ rfc1048_print(register const u_char *bp, register int length) while (size >= sizeof(us)) { if (!first) putchar(','); - bcopy((char *)bp, (char *)&us, sizeof(us)); + memcpy((char *)&us, (char *)bp, sizeof(us)); printf("%d", us); bp += sizeof(us); size -= sizeof(us); diff --git a/usr.sbin/tcpdump/print-decnet.c b/usr.sbin/tcpdump/print-decnet.c index e223cfd2a31..cb05cace8e3 100644 --- a/usr.sbin/tcpdump/print-decnet.c +++ b/usr.sbin/tcpdump/print-decnet.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-decnet.c,v 1.3 1996/06/10 07:47:32 deraadt Exp $ */ -/* $NetBSD: print-decnet.c,v 1.2 1995/03/06 19:11:07 mycroft Exp $ */ +/* $OpenBSD: print-decnet.c,v 1.4 1996/07/13 11:01:17 mickey Exp $ */ /* - * Copyright (c) 1992, 1993, 1994 + * Copyright (c) 1992, 1993, 1994, 1995 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,23 +23,27 @@ #ifndef lint static char rcsid[] = - "@(#) Header: print-decnet.c,v 1.15 94/06/20 19:44:38 leres Exp (LBL)"; + "@(#) Header: print-decnet.c,v 1.19 95/10/07 22:15:12 leres Exp (LBL)"; #endif #include <sys/types.h> #include <sys/time.h> #include <sys/socket.h> +#if __STDC__ +struct mbuf; +struct rtentry; +#endif #include <net/if.h> -#ifdef DECNETLIB + +#ifdef HAVE_LIBDNET #include <netdnet/dnetdb.h> #endif #include <ctype.h> #include <stdio.h> -#ifdef __STDC__ #include <stdlib.h> -#endif +#include <string.h> #include <unistd.h> #include "decnet.h" @@ -60,7 +63,7 @@ static void print_reason(int); static void pdata(u_char *, int); #endif -#ifdef DECNETLIB +#ifdef HAVE_LIBDNET extern char *dnet_htoa(struct dn_naddr *); #endif @@ -86,7 +89,7 @@ decnet_print(register const u_char *ap, register int length, rhlen = min(length, caplen); rhlen = min(rhlen, sizeof(*rhp)); - bcopy(&(ap[sizeof(short)]), rhp, rhlen); + memcpy((char *)rhp, (char *)&(ap[sizeof(short)]), rhlen); mflags = EXTRACT_8BITS(rhp->rh_short.sh_flags); @@ -100,7 +103,7 @@ decnet_print(register const u_char *ap, register int length, caplen -= padlen; rhlen = min(length, caplen); rhlen = min(rhlen, sizeof(*rhp)); - bcopy(&(ap[sizeof(short)]), rhp, rhlen); + memcpy((char *)rhp, (char *)&(ap[sizeof(short)]), rhlen); mflags = EXTRACT_8BITS(rhp->rh_short.sh_flags); } @@ -211,7 +214,8 @@ print_decnet_ctlmsg(register const union routehdr *rhp, int length) vers = EXTRACT_8BITS(cmp->cm_rhello.rh_vers); eco = EXTRACT_8BITS(cmp->cm_rhello.rh_eco); ueco = EXTRACT_8BITS(cmp->cm_rhello.rh_ueco); - bcopy(&(cmp->cm_rhello.rh_src), &srcea, sizeof(srcea)); + memcpy((char *)&srcea, (char *)&(cmp->cm_rhello.rh_src), + sizeof(srcea)); src = EXTRACT_16BITS(srcea.dne_remote.dne_nodeaddr); info = EXTRACT_8BITS(cmp->cm_rhello.rh_info); blksize = EXTRACT_16BITS(cmp->cm_rhello.rh_blksize); @@ -230,12 +234,14 @@ print_decnet_ctlmsg(register const union routehdr *rhp, int length) vers = EXTRACT_8BITS(cmp->cm_ehello.eh_vers); eco = EXTRACT_8BITS(cmp->cm_ehello.eh_eco); ueco = EXTRACT_8BITS(cmp->cm_ehello.eh_ueco); - bcopy(&(cmp->cm_ehello.eh_src), &srcea, sizeof(srcea)); + memcpy((char *)&srcea, (char *)&(cmp->cm_ehello.eh_src), + sizeof(srcea)); src = EXTRACT_16BITS(srcea.dne_remote.dne_nodeaddr); info = EXTRACT_8BITS(cmp->cm_ehello.eh_info); blksize = EXTRACT_16BITS(cmp->cm_ehello.eh_blksize); /*seed*/ - bcopy(&(cmp->cm_ehello.eh_router), &rtea, sizeof(rtea)); + memcpy((char *)&rtea, (char *)&(cmp->cm_ehello.eh_router), + sizeof(rtea)); dst = EXTRACT_16BITS(rtea.dne_remote.dne_nodeaddr); hello = EXTRACT_16BITS(cmp->cm_ehello.eh_hello); other = EXTRACT_8BITS(cmp->cm_ehello.eh_data); @@ -690,7 +696,7 @@ print_nsp(const u_char *nspp, int nsplen) } } -struct token reason2str[] = { +static struct tok reason2str[] = { { UC_OBJREJECT, "object rejected connect" }, { UC_RESOURCES, "insufficient resources" }, { UC_NOSUCHNODE, "unrecognized node name" }, @@ -730,6 +736,8 @@ dnnum_string(u_short dnaddr) int node = dnaddr & NODEMASK; str = (char *)malloc(sizeof("00.0000")); + if (str == NULL) + error("dnnum_string: malloc"); sprintf(str, "%d.%d", area, node); return(str); } @@ -737,11 +745,11 @@ dnnum_string(u_short dnaddr) char * dnname_string(u_short dnaddr) { -#ifdef DECNETLIB +#ifdef HAVE_LIBDNET struct dn_naddr dna; dna.a_len = sizeof(short); - bcopy((char *)&dnaddr, dna.a_addr, sizeof(short)); + memcpy((char *)dna.a_addr, (char *)&dnaddr, sizeof(short)); return (savestr(dnet_htoa(&dna))); #else return(dnnum_string(dnaddr)); /* punt */ diff --git a/usr.sbin/tcpdump/print-domain.c b/usr.sbin/tcpdump/print-domain.c index 7360117cef6..c8ba519d90e 100644 --- a/usr.sbin/tcpdump/print-domain.c +++ b/usr.sbin/tcpdump/print-domain.c @@ -1,7 +1,7 @@ -/* $OpenBSD: print-domain.c,v 1.3 1996/06/10 07:47:33 deraadt Exp $ */ +/* $OpenBSD: print-domain.c,v 1.4 1996/07/13 11:01:18 mickey Exp $ */ /* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,7 +23,7 @@ #ifndef lint static char rcsid[] = - "@(#) Header: print-domain.c,v 1.23 94/06/14 20:17:38 leres Exp (LBL)"; + "@(#) Header: print-domain.c,v 1.29 96/06/19 00:49:25 leres Exp (LBL)"; #endif #include <sys/param.h> @@ -31,6 +31,10 @@ static char rcsid[] = #include <sys/types.h> #include <sys/socket.h> +#if __STDC__ +struct mbuf; +struct rtentry; +#endif #include <net/if.h> #include <netinet/in.h> @@ -50,9 +54,68 @@ static char rcsid[] = #include "interface.h" #include "addrtoname.h" +#include "extract.h" /* must come after interface.h */ + +/* Compatiblity */ +#ifndef T_TXT +#define T_TXT 16 /* text strings */ +#endif +#ifndef T_RP +#define T_RP 17 /* responsible person */ +#endif +#ifndef T_AFSDB +#define T_AFSDB 18 /* AFS cell database */ +#endif +#ifndef T_X25 +#define T_X25 19 /* X_25 calling address */ +#endif +#ifndef T_ISDN +#define T_ISDN 20 /* ISDN calling address */ +#endif +#ifndef T_RT +#define T_RT 21 /* router */ +#endif +#ifndef T_NSAP +#define T_NSAP 22 /* NSAP address */ +#endif +#ifndef T_NSAP_PTR +#define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */ +#endif +#ifndef T_SIG +#define T_SIG 24 /* security signature */ +#endif +#ifndef T_KEY +#define T_KEY 25 /* security key */ +#endif +#ifndef T_PX +#define T_PX 26 /* X.400 mail mapping */ +#endif +#ifndef T_GPOS +#define T_GPOS 27 /* geographical position (withdrawn) */ +#endif +#ifndef T_AAAA +#define T_AAAA 28 /* IP6 Address */ +#endif +#ifndef T_LOC +#define T_LOC 29 /* Location Information */ +#endif + +#ifndef T_UNSPEC +#define T_UNSPEC 103 /* Unspecified format (binary data) */ +#endif +#ifndef T_UNSPECA +#define T_UNSPECA 104 /* "unspecified ascii". Ugly MIT hack */ +#endif + +#ifndef C_CHAOS +#define C_CHAOS 3 /* for chaos net (MIT) */ +#endif +#ifndef C_HS +#define C_HS 4 /* for Hesiod name server (MIT) (XXX) */ +#endif static char *ns_ops[] = { - "", " inv_q", " stat", " op3", " op4", " op5", " op6", " op7", + "", " inv_q", " stat", " op3", " notify", " op5", " op6", " op7", " op8", " updataA", " updateD", " updateDA", " updateM", " updateMA", " zoneInit", " zoneRef", }; @@ -66,30 +129,37 @@ static char *ns_resp[] = { /* skip over a domain name */ static const u_char * -ns_nskip(register const u_char *cp) +ns_nskip(register const u_char *cp, register const u_char *bp) { register u_char i; - if (((i = *cp++) & 0xc0) == 0xc0) + if (((i = *cp++) & INDIR_MASK) == INDIR_MASK) return (cp + 1); - while (i) { + while (i && cp < snapend) { cp += i; i = *cp++; } return (cp); } -/* print a domain name */ -static void -ns_nprint(register const u_char *cp, register const u_char *bp, - register const u_char *ep) +/* print a <domain-name> */ +static const u_char * +ns_nprint(register const u_char *cp, register const u_char *bp) { register u_int i; - - putchar(' '); - if ((i = *cp++) != 0) - while (i && cp < ep) { - if ((i & 0xc0) == 0xc0) { + register const u_char *rp; + register int compress; + + i = *cp++; + rp = cp + i; + if ((i & INDIR_MASK) == INDIR_MASK) { + rp = cp + 1; + compress = 1; + } else + compress = 0; + if (i != 0) + while (i && cp < snapend) { + if ((i & INDIR_MASK) == INDIR_MASK) { cp = bp + (((i << 8) | *cp) & 0x3fff); i = *cp++; continue; @@ -99,12 +169,29 @@ ns_nprint(register const u_char *cp, register const u_char *bp, } while (--i); putchar('.'); i = *cp++; + if (!compress) + rp += i + 1; } else putchar('.'); + return (rp); } -static struct token type2str[] = { +/* print a <character-string> */ +static const u_char * +ns_cprint(register const u_char *cp, register const u_char *bp) +{ + register u_int i; + + i = *cp++; + if (cp + i < snapend) + do { + putchar(*cp++); + } while (--i); + return (cp); +} + +static struct tok type2str[] = { { T_A, "A" }, { T_NS, "NS" }, { T_MD, "MD" }, @@ -120,12 +207,25 @@ static struct token type2str[] = { { T_HINFO, "HINFO" }, { T_MINFO, "MINFO" }, { T_MX, "MX" }, + { T_TXT, "TXT" }, + { T_RP, "RP" }, + { T_AFSDB, "AFSDB" }, + { T_X25, "X25" }, + { T_ISDN, "ISDN" }, + { T_RT, "RT" }, + { T_NSAP, "NSAP" }, + { T_NSAP_PTR, "NSAP_PTR" }, + { T_SIG, "SIG" }, + { T_KEY, "KEY" }, + { T_PX, "PX" }, + { T_GPOS, "GPOS" }, + { T_AAAA, "AAAA" }, + { T_LOC , "LOC " }, { T_UINFO, "UINFO" }, { T_UID, "UID" }, { T_GID, "GID" }, -#ifdef T_UNSPEC { T_UNSPEC, "UNSPEC" }, -#endif + { T_UNSPECA, "UNSPECA" }, { T_AXFR, "AXFR" }, { T_MAILB, "MAILB" }, { T_MAILA, "MAILA" }, @@ -133,17 +233,24 @@ static struct token type2str[] = { { 0, NULL } }; +static struct tok class2str[] = { + { C_IN, "IN" }, /* Not used */ + { C_CHAOS, "CHAOS)" }, + { C_HS, "HS" }, + { C_ANY, "ANY" }, + { 0, NULL } +}; + /* print a query */ static void -ns_qprint(register const u_char *cp, register const u_char *bp, - register const u_char *ep) +ns_qprint(register const u_char *cp, register const u_char *bp) { - const u_char *np = cp; + register const u_char *np = cp; register u_int i; - cp = ns_nskip(cp); + cp = ns_nskip(cp, bp); - if (cp + 4 > ep) + if (cp + 4 > snapend) return; /* print the qtype and qclass (if it's not IN) */ @@ -151,42 +258,47 @@ ns_qprint(register const u_char *cp, register const u_char *bp, i |= *cp++; printf(" %s", tok2str(type2str, "Type%d", i)); i = *cp++ << 8; - if ((i |= *cp++) != C_IN) - if (i == C_ANY) - printf("(c_any)"); - else - printf("(Class %d)", i); - - putchar('?'); - ns_nprint(np, bp, ep); -} + i |= *cp++; + if (i != C_IN) + printf(" %s", tok2str(class2str, "(Class %d)", i)); + fputs("? ", stdout); + ns_nprint(np, bp); +} /* print a reply */ -static void -ns_rprint(register const u_char *cp, register const u_char *bp, - register const u_char *ep) +static const u_char * +ns_rprint(register const u_char *cp, register const u_char *bp) { register u_int i; - u_short typ; + register u_short typ, len; + register const u_char *rp; - cp = ns_nskip(cp); + if (vflag) { + putchar(' '); + cp = ns_nprint(cp, bp); + } else + cp = ns_nskip(cp, bp); - if (cp + 10 > ep) - return; + if (cp + 10 > snapend) + return (snapend); /* print the type/qtype and class (if it's not IN) */ typ = *cp++ << 8; typ |= *cp++; i = *cp++ << 8; - if ((i |= *cp++) != C_IN) - if (i == C_ANY) - printf("(c_any)"); - else - printf("(Class %d)", i); - - /* ignore ttl & len */ - cp += 6; + i |= *cp++; + if (i != C_IN) + printf(" %s", tok2str(class2str, "(Class %d)", i)); + + /* ignore ttl */ + cp += 4; + + len = *cp++ << 8; + len |= *cp++; + + rp = cp + len; + printf(" %s", tok2str(type2str, "Type%d", typ)); switch (typ) { @@ -197,29 +309,34 @@ ns_rprint(register const u_char *cp, register const u_char *bp, case T_NS: case T_CNAME: case T_PTR: - ns_nprint(cp, bp, ep); + putchar(' '); + (void)ns_nprint(cp, bp); break; case T_MX: - ns_nprint(cp+2, bp, ep); -#ifndef TCPDUMP_ALIGN - printf(" %d", *(short *)cp); -#else - { - u_short x = *cp | cp[1] << 8; - printf(" %d", ntohs(x)); - } -#endif + putchar(' '); + (void)ns_nprint(cp + 2, bp); + printf(" %d", EXTRACT_SHORT(cp)); + break; + + case T_TXT: + putchar(' '); + (void)ns_cprint(cp, bp); + break; + + case T_UNSPECA: /* One long string */ + printf(" %.*s", len, cp); break; } + return (rp); /* XXX This isn't always right*/ } void ns_print(register const u_char *bp, int length) { register const HEADER *np; - int qdcount, ancount, nscount, arcount; - const u_char *ep = snapend; + register int qdcount, ancount, nscount, arcount; + register const u_char *cp; np = (const HEADER *)bp; /* get the byte-order right */ @@ -239,10 +356,20 @@ ns_print(register const u_char *bp, int length) np->tc? "|" : ""); if (qdcount != 1) printf(" [%dq]", qdcount); + /* Print QUESTION section on -vv */ + if (vflag > 1) { + fputs(" q: ", stdout); + cp = ns_nprint((const u_char *)(np + 1), bp); + } else + cp = ns_nskip((const u_char *)(np + 1), bp); printf(" %d/%d/%d", ancount, nscount, arcount); - if (ancount) - ns_rprint(ns_nskip((const u_char *)(np + 1)) + 4, - (const u_char *)np, ep); + if (ancount--) { + cp = ns_rprint(cp + 4, bp); + while (ancount-- && cp < snapend) { + putchar(','); + cp = ns_rprint(cp, bp); + } + } } else { /* this is a request */ @@ -272,7 +399,7 @@ ns_print(register const u_char *bp, int length) if (arcount) printf(" [%dau]", arcount); - ns_qprint((const u_char *)(np + 1), (const u_char *)np, ep); + ns_qprint((const u_char *)(np + 1), (const u_char *)np); } printf(" (%d)", length); } diff --git a/usr.sbin/tcpdump/print-dvmrp.c b/usr.sbin/tcpdump/print-dvmrp.c new file mode 100644 index 00000000000..45cd5a4b8aa --- /dev/null +++ b/usr.sbin/tcpdump/print-dvmrp.c @@ -0,0 +1,344 @@ +/* $OpenBSD: print-dvmrp.c,v 1.1 1996/07/13 11:01:19 mickey Exp $ */ + +/* + * Copyright (c) 1995, 1996 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef lint +static char rcsid[] = +"@(#) Header: print-dvmrp.c,v 1.7 96/06/03 02:52:39 leres Exp (LBL)"; +#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 <netinet/tcp.h> +#include <netinet/tcpip.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> + +#include "interface.h" +#include "addrtoname.h" + +/* + * DVMRP message types and flag values shamelessly stolen from + * mrouted/dvmrp.h. + */ +#define DVMRP_PROBE 1 /* for finding neighbors */ +#define DVMRP_REPORT 2 /* for reporting some or all routes */ +#define DVMRP_ASK_NEIGHBORS 3 /* sent by mapper, asking for a list */ + /* + * of this router's neighbors + */ +#define DVMRP_NEIGHBORS 4 /* response to such a request */ +#define DVMRP_ASK_NEIGHBORS2 5 /* as above, want new format reply */ +#define DVMRP_NEIGHBORS2 6 +#define DVMRP_PRUNE 7 /* prune message */ +#define DVMRP_GRAFT 8 /* graft message */ +#define DVMRP_GRAFT_ACK 9 /* graft acknowledgement */ + +/* + * 'flags' byte values in DVMRP_NEIGHBORS2 reply. + */ +#define DVMRP_NF_TUNNEL 0x01 /* neighbors reached via tunnel */ +#define DVMRP_NF_SRCRT 0x02 /* tunnel uses IP source routing */ +#define DVMRP_NF_DOWN 0x10 /* kernel state of interface */ +#define DVMRP_NF_DISABLED 0x20 /* administratively disabled */ +#define DVMRP_NF_QUERIER 0x40 /* I am the subnet's querier */ + +static void print_report(const u_char *, const u_char *, int); +static void print_neighbors(const u_char *, const u_char *, int); +static void print_neighbors2(const u_char *, const u_char *, int); +static void print_prune(const u_char *, const u_char *, int); +static void print_graft(const u_char *, const u_char *, int); +static void print_graft_ack(const u_char *, const u_char *, int); + +static u_int32_t target_level; + +void +dvmrp_print(register const u_char *bp, register int len) +{ + register const u_char *ep; + register u_char type; + + ep = (const u_char *)snapend; + if (bp >= ep) + return; + + type = bp[1]; + bp += 8; + /* + * Skip IGMP header + */ + + len -= 8; + + switch (type) { + case DVMRP_PROBE: + printf(" Probe"); + break; + + case DVMRP_REPORT: + printf(" Report"); + if (vflag) + print_report(bp, ep, len); + break; + + case DVMRP_ASK_NEIGHBORS: + printf(" Ask-neighbors(old)"); + break; + + case DVMRP_NEIGHBORS: + printf(" Neighbors(old)"); + print_neighbors(bp, ep, len); + break; + + case DVMRP_ASK_NEIGHBORS2: + printf(" Ask-neighbors"); + break; + + case DVMRP_NEIGHBORS2: + printf(" Neighbors"); + bp -= 4; + target_level = ((u_int32_t) * bp++ << 24); + /* + * Group address in IGMP + */ + + target_level += ((u_int32_t) * bp++ << 16); + /* + * header is version number + */ + + target_level += ((u_int32_t) * bp++ << 8); + target_level += ((u_int32_t) * bp++); + target_level = htonl(target_level); + print_neighbors2(bp, ep, len); + break; + + case DVMRP_PRUNE: + printf(" Prune"); + print_prune(bp, ep, len); + break; + + case DVMRP_GRAFT: + printf(" Graft"); + print_graft(bp, ep, len); + break; + + case DVMRP_GRAFT_ACK: + printf(" Graft-ACK"); + print_graft_ack(bp, ep, len); + break; + + default: + printf(" [type %d]", type); + break; + } +} + +static void +print_report(const u_char *bp, const u_char *ep, int len) +{ + u_int32_t mask, origin; + int metric; + int i; + int width; + int done; + + while (len > 0) { + if (len < 3) { + printf(" [|]"); + return; + } + mask = 0xff << 24 | bp[0] << 16 | bp[1] << 8 | bp[2]; + width = 1; + if (bp[0]) + width = 2; + if (bp[1]) + width = 3; + if (bp[2]) + width = 4; + + printf("\n\tMask %s", intoa(htonl(mask))); + bp += 3; + len -= 3; + do { + if (bp + width + 1 > ep) { + printf(" [|]"); + return; + } + if (len < width + 1) { + printf("\n\t [Truncated Report]"); + return; + } + origin = 0; + for (i = 0; i < width; ++i) + origin = origin << 8 | *bp++; + for ( ; i < 4; ++i) + origin <<= 8; + + metric = *bp++; + done = metric & 0x80; + metric &= 0x7f; + printf("\n\t %s metric %d", intoa(htonl(origin)), + metric); + len -= width + 1; + } while (!done); + } +} + +#define GET_ADDR(to) (memcpy((char*)to, (char*)bp, 4), bp += 4) + +static void +print_neighbors(const u_char *bp, const u_char *ep, int len) +{ + u_char laddr[4], neighbor[4]; + u_char metric; + u_char thresh; + u_char save_nflag; + int ncount; + + save_nflag = nflag; + while (len > 0 && bp < ep) { + if (len < 7 || (bp + 7) >= ep) { + printf(" [|]"); + return; + } + GET_ADDR(laddr); + metric = *bp++; + thresh = *bp++; + ncount = *bp++; + len -= 7; + while (--ncount >= 0 && (len >= 4) && (bp + 4) < ep) { + GET_ADDR(neighbor); + nflag = 0; + printf(" [%s ->", ipaddr_string(laddr)); + nflag = save_nflag; + printf(" %s, (%d/%d)]", + ipaddr_string(neighbor), metric, thresh); + len -= 4; + } + } +} + +static void +print_neighbors2(const u_char *bp, const u_char *ep, int len) +{ + u_char laddr[4], neighbor[4]; + u_char metric; + u_char thresh; + u_char flags; + u_char save_nflag; + int ncount; + + printf(" (v %d.%d):", + (int)target_level & 0xff, + (int)(target_level >> 8) & 0xff); + + save_nflag = nflag; + while (len > 0 && bp < ep) { + if (len < 8 || (bp + 8) >= ep) { + printf(" [|]"); + return; + } + GET_ADDR(laddr); + metric = *bp++; + thresh = *bp++; + flags = *bp++; + ncount = *bp++; + len -= 8; + while (--ncount >= 0 && (len >= 4) && (bp + 4) < ep) { + GET_ADDR(neighbor); + nflag = 0; + printf(" [%s -> ", ipaddr_string(laddr)); + nflag = save_nflag; + printf("%s (%d/%d", ipaddr_string(neighbor), + metric, thresh); + if (flags & DVMRP_NF_TUNNEL) + printf("/tunnel"); + if (flags & DVMRP_NF_SRCRT) + printf("/srcrt"); + if (flags & DVMRP_NF_QUERIER) + printf("/querier"); + if (flags & DVMRP_NF_DISABLED) + printf("/disabled"); + if (flags & DVMRP_NF_DOWN) + printf("/down"); + printf(")]"); + len -= 4; + } + if (ncount != -1) { + printf(" [|]"); + return; + } + } +} + +static void +print_prune(const u_char *bp, const u_char *ep, int len) +{ + union a { + u_char b[4]; + u_int32_t i; + } prune_timer; + + if (len < 12 || (bp + 12) >= ep) { + printf(" [|]"); + return; + } + 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)); +} + +static void +print_graft(const u_char *bp, const u_char *ep, int len) +{ + + if (len < 8 || (bp + 8) >= ep) { + printf(" [|]"); + return; + } + printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4)); +} + +static void +print_graft_ack(const u_char *bp, const u_char *ep, int len) +{ + + if (len < 8 || (bp + 8) >= ep) { + printf(" [|]"); + return; + } + printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4)); +} diff --git a/usr.sbin/tcpdump/print-egp.c b/usr.sbin/tcpdump/print-egp.c index f16202c8b1a..24df9ffc530 100644 --- a/usr.sbin/tcpdump/print-egp.c +++ b/usr.sbin/tcpdump/print-egp.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-egp.c,v 1.3 1996/06/10 07:47:33 deraadt Exp $ */ -/* $NetBSD: print-egp.c,v 1.2 1995/03/06 19:11:09 mycroft Exp $ */ +/* $OpenBSD: print-egp.c,v 1.4 1996/07/13 11:01:20 mickey Exp $ */ /* - * Copyright (c) 1991, 1992, 1993, 1994 + * Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms are permitted @@ -16,14 +15,14 @@ * specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * Initial contribution from Jeff Honig (jch@MITCHELL.CIT.CORNELL.EDU). */ #ifndef lint static char rcsid[] = - "@(#) Header: print-egp.c,v 1.14 94/06/20 19:44:38 leres Exp (LBL)"; + "@(#) Header: print-egp.c,v 1.19 96/06/23 02:11:45 leres Exp (LBL)"; #endif #include <sys/param.h> @@ -92,7 +91,7 @@ struct egp_packet { #define egp_reason egp_handg.egpu_reason union { u_short egpu_poll; - u_int32 egpu_sourcenet; + u_int32_t egpu_sourcenet; } egp_pands; #define egp_poll egp_pands.egpu_poll #define egp_sourcenet egp_pands.egpu_sourcenet @@ -143,8 +142,8 @@ egpnrprint(register const struct egp_packet *egp, register int length) { register const u_char *cp, *ep; #define TCHECK(n) if (cp > ep - n) goto trunc - register u_int32 addr; - register u_int32 net; + u_int32_t addr; + register u_int32_t net; register int netlen; int gateways, distances, networks; int t_gateways; @@ -188,7 +187,7 @@ egpnrprint(register const struct egp_packet *egp, register int length) distances = *cp++; printf(" %s %s ", gateways < egp->egp_intgw ? "int" : "ext", - intoa(addr)); + ipaddr_string(&addr)); comma = ""; putchar('('); @@ -200,16 +199,16 @@ egpnrprint(register const struct egp_packet *egp, register int length) while (--networks >= 0) { /* Pickup network number */ TCHECK(1); - addr = (u_int32)*cp++ << 24; + addr = (u_int32_t)*cp++ << 24; if (IN_CLASSB(addr)) { TCHECK(1); - addr |= (u_int32)*cp++ << 16; + addr |= (u_int32_t)*cp++ << 16; } else if (!IN_CLASSA(addr)) { TCHECK(2); - addr |= (u_int32)*cp++ << 16; - addr |= (u_int32)*cp++ << 8; + addr |= (u_int32_t)*cp++ << 16; + addr |= (u_int32_t)*cp++ << 8; } - printf(" %s", intoa(addr)); + printf(" %s", ipaddr_string(&addr)); } } putchar(')'); @@ -318,7 +317,7 @@ egp_print(register const u_char *bp, register int length, printf(" state:%s", egp_status_updown[status]); else printf(" [status %d]", status); - printf(" net:%s", intoa(egp->egp_sourcenet)); + printf(" net:%s", ipaddr_string(&egp->egp_sourcenet)); break; case EGPT_UPDATE: @@ -332,7 +331,7 @@ egp_print(register const u_char *bp, register int length, else printf(" [status %d]", status); printf(" %s int %d ext %d", - intoa(egp->egp_sourcenet), + ipaddr_string(&egp->egp_sourcenet), egp->egp_intgw, egp->egp_extgw); if (vflag) diff --git a/usr.sbin/tcpdump/print-ether.c b/usr.sbin/tcpdump/print-ether.c index f5d2bdd0888..b184993ff30 100644 --- a/usr.sbin/tcpdump/print-ether.c +++ b/usr.sbin/tcpdump/print-ether.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-ether.c,v 1.3 1996/06/10 07:47:34 deraadt Exp $ */ -/* $NetBSD: print-ether.c,v 1.3 1995/03/06 19:11:10 mycroft Exp $ */ +/* $OpenBSD: print-ether.c,v 1.4 1996/07/13 11:01:21 mickey Exp $ */ /* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,7 +22,7 @@ */ #ifndef lint static char rcsid[] = - "@(#) Header: print-ether.c,v 1.37 94/06/10 17:01:29 mccanne Exp (LBL)"; + "@(#) Header: print-ether.c,v 1.39 96/06/03 03:05:27 leres Exp (LBL)"; #endif #include <sys/param.h> @@ -31,6 +30,10 @@ static char rcsid[] = #include <sys/types.h> #include <sys/socket.h> +#if __STDC__ +struct mbuf; +struct rtentry; +#endif #include <net/if.h> #include <netinet/in.h> diff --git a/usr.sbin/tcpdump/print-fddi.c b/usr.sbin/tcpdump/print-fddi.c index eec7efd78d9..0c45079c867 100644 --- a/usr.sbin/tcpdump/print-fddi.c +++ b/usr.sbin/tcpdump/print-fddi.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-fddi.c,v 1.3 1996/06/10 07:47:35 deraadt Exp $ */ -/* $NetBSD: print-fddi.c,v 1.2 1995/03/06 19:11:12 mycroft Exp $ */ +/* $OpenBSD: print-fddi.c,v 1.4 1996/07/13 11:01:22 mickey Exp $ */ /* - * Copyright (c) 1991, 1992, 1993, 1994 + * Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,16 +23,20 @@ #ifndef lint static char rcsid[] = - "@(#)Header: print-fddi.c,v 1.21 94/06/10 17:01:29 mccanne Exp (LBL)"; + "@(#)Header: print-fddi.c,v 1.30 96/06/03 03:05:50 leres Exp (LBL)"; #endif -#ifdef FDDI +#ifdef HAVE_FDDI #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> @@ -42,11 +45,11 @@ static char rcsid[] = #include <netinet/ip.h> #include <ctype.h> -#include <errno.h> #include <netdb.h> #include <pcap.h> #include <signal.h> #include <stdio.h> +#include <string.h> #include "interface.h" #include "addrtoname.h" @@ -54,8 +57,6 @@ static char rcsid[] = #include "fddi.h" -int fddipad = FDDIPAD; /* for proper alignment of header */ - /* * Some FDDI interfaces use bit-swapped addresses. */ @@ -219,8 +220,8 @@ extract_fddi_addrs(const struct fddi_header *fddip, char *fsrc, char *fdst) fsrc[i] = fddi_bit_swap[fddip->fddi_shost[i]]; } else { - bcopy(fddip->fddi_dhost, fdst, 6); - bcopy(fddip->fddi_shost, fsrc, 6); + memcpy(fdst, (char *)fddip->fddi_dhost, 6); + memcpy(fsrc, (char *)fddip->fddi_shost, 6); } } @@ -345,7 +346,8 @@ out: #include "interface.h" void -fddi_if_print(u_char *pcap, struct pcap_pkthdr *h, register u_char *p) +fddi_if_print(u_char *pcap, const struct pcap_pkthdr *h, + register const u_char *p) { error("not configured for fddi"); diff --git a/usr.sbin/tcpdump/print-icmp.c b/usr.sbin/tcpdump/print-icmp.c index ba9456330cb..e53cc66a83c 100644 --- a/usr.sbin/tcpdump/print-icmp.c +++ b/usr.sbin/tcpdump/print-icmp.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-icmp.c,v 1.3 1996/06/10 07:47:36 deraadt Exp $ */ -/* $NetBSD: print-icmp.c,v 1.3 1995/03/06 19:11:13 mycroft Exp $ */ +/* $OpenBSD: print-icmp.c,v 1.4 1996/07/13 11:01:23 mickey Exp $ */ /* - * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994 + * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,7 +23,7 @@ #ifndef lint static char rcsid[] = - "@(#) Header: print-icmp.c,v 1.20 94/06/14 20:17:39 leres Exp (LBL)"; + "@(#) Header: print-icmp.c,v 1.27 96/06/24 22:14:23 leres Exp (LBL)"; #endif #include <sys/param.h> @@ -32,6 +31,10 @@ static char rcsid[] = #include <sys/types.h> #include <sys/socket.h> +#if __STDC__ +struct mbuf; +struct rtentry; +#endif #include <net/if.h> #include <netinet/in.h> @@ -50,25 +53,89 @@ static char rcsid[] = #include "interface.h" #include "addrtoname.h" +/* Compatibility */ +#ifndef ICMP_UNREACH_NET_UNKNOWN +#define ICMP_UNREACH_NET_UNKNOWN 6 /* destination net unknown */ +#endif +#ifndef ICMP_UNREACH_HOST_UNKNOWN +#define ICMP_UNREACH_HOST_UNKNOWN 7 /* destination host unknown */ +#endif +#ifndef ICMP_UNREACH_ISOLATED +#define ICMP_UNREACH_ISOLATED 8 /* source host isolated */ +#endif +#ifndef ICMP_UNREACH_NET_PROHIB +#define ICMP_UNREACH_NET_PROHIB 9 /* admin prohibited net */ +#endif +#ifndef ICMP_UNREACH_HOST_PROHIB +#define ICMP_UNREACH_HOST_PROHIB 10 /* admin prohibited host */ +#endif +#ifndef ICMP_UNREACH_TOSNET +#define ICMP_UNREACH_TOSNET 11 /* tos prohibited net */ +#endif +#ifndef ICMP_UNREACH_TOSHOST +#define ICMP_UNREACH_TOSHOST 12 /* tos prohibited host */ +#endif + +/* Most of the icmp types */ +static struct tok icmp2str[] = { + { ICMP_ECHOREPLY, "echo reply" }, + { ICMP_SOURCEQUENCH, "source quench" }, + { ICMP_ECHO, "echo request" }, + { ICMP_TSTAMP, "time stamp request" }, + { ICMP_TSTAMPREPLY, "time stamp reply" }, + { ICMP_IREQ, "information request" }, + { ICMP_IREQREPLY, "information reply" }, + { ICMP_MASKREQ, "address mask request" }, + { 0, NULL } +}; + +/* Formats for most of the ICMP_UNREACH codes */ +static struct tok unreach2str[] = { + { ICMP_UNREACH_NET, "net %s unreachable" }, + { ICMP_UNREACH_HOST, "host %s unreachable" }, + { ICMP_UNREACH_NEEDFRAG, "%s unreachable - need to frag" }, + { ICMP_UNREACH_SRCFAIL, + "%s unreachable - source route failed" }, + { ICMP_UNREACH_NET_UNKNOWN, "net %s unreachable - unknown" }, + { ICMP_UNREACH_HOST_UNKNOWN, "host %s unreachable - unknown" }, + { ICMP_UNREACH_ISOLATED, + "%s unreachable - source host isolated" }, + { ICMP_UNREACH_NET_PROHIB, + "net %s unreachable - admin prohibited" }, + { ICMP_UNREACH_HOST_PROHIB, + "host %s unreachable - admin prohibited" }, + { ICMP_UNREACH_TOSNET, + "net %s unreachable - tos prohibited" }, + { ICMP_UNREACH_TOSHOST, + "host %s unreachable - tos prohibited" }, + { 0, NULL } +}; + +/* Formats for the ICMP_REDIRECT codes */ +static struct tok type2str[] = { + { ICMP_REDIRECT_NET, "redirect %s to net %s" }, + { ICMP_REDIRECT_HOST, "redirect %s to host %s" }, + { ICMP_REDIRECT_TOSNET, "redirect-tos %s to net %s" }, + { ICMP_REDIRECT_TOSHOST, "redirect-tos %s to net %s" }, + { 0, NULL } +}; + void icmp_print(register const u_char *bp, register const u_char *bp2) { register const struct icmp *dp; register const struct ip *ip; - register const char *str; + register const char *str, *fmt; register const struct ip *oip; register const struct udphdr *ouh; register int hlen, dport; - register const u_char *ep; char buf[256]; -#define TCHECK(var, l) if ((u_char *)&(var) > ep - l) goto trunc +#define TCHECK(var, l) if ((u_char *)&(var) > snapend - l) goto trunc dp = (struct icmp *)bp; ip = (struct ip *)bp2; str = buf; - /* 'ep' points to the end of avaible data. */ - ep = snapend; (void)printf("%s > %s: ", ipaddr_string(&ip->ip_src), @@ -76,26 +143,18 @@ icmp_print(register const u_char *bp, register const u_char *bp2) TCHECK(dp->icmp_code, sizeof(dp->icmp_code)); switch (dp->icmp_type) { - case ICMP_ECHOREPLY: - str = "echo reply"; - break; + case ICMP_UNREACH: TCHECK(dp->icmp_ip.ip_dst, sizeof(dp->icmp_ip.ip_dst)); switch (dp->icmp_code) { - case ICMP_UNREACH_NET: - (void)sprintf(buf, "net %s unreachable", - ipaddr_string(&dp->icmp_ip.ip_dst)); - break; - case ICMP_UNREACH_HOST: - (void)sprintf(buf, "host %s unreachable", - ipaddr_string(&dp->icmp_ip.ip_dst)); - break; + case ICMP_UNREACH_PROTOCOL: TCHECK(dp->icmp_ip.ip_p, sizeof(dp->icmp_ip.ip_p)); (void)sprintf(buf, "%s protocol %d unreachable", ipaddr_string(&dp->icmp_ip.ip_dst), dp->icmp_ip.ip_p); break; + case ICMP_UNREACH_PORT: TCHECK(dp->icmp_ip.ip_p, sizeof(dp->icmp_ip.ip_p)); oip = &dp->icmp_ip; @@ -103,18 +162,21 @@ icmp_print(register const u_char *bp, register const u_char *bp2) ouh = (struct udphdr *)(((u_char *)oip) + hlen); dport = ntohs(ouh->uh_dport); switch (oip->ip_p) { + case IPPROTO_TCP: (void)sprintf(buf, "%s tcp port %s unreachable", ipaddr_string(&oip->ip_dst), tcpport_string(dport)); break; + case IPPROTO_UDP: (void)sprintf(buf, "%s udp port %s unreachable", ipaddr_string(&oip->ip_dst), udpport_string(dport)); break; + default: (void)sprintf(buf, "%s protocol %d port %d unreachable", @@ -123,59 +185,43 @@ icmp_print(register const u_char *bp, register const u_char *bp2) break; } break; - case ICMP_UNREACH_NEEDFRAG: - (void)sprintf(buf, "%s unreachable - need to frag", - ipaddr_string(&dp->icmp_ip.ip_dst)); - break; - case ICMP_UNREACH_SRCFAIL: - (void)sprintf(buf, - "%s unreachable - source route failed", - ipaddr_string(&dp->icmp_ip.ip_dst)); + + default: + fmt = tok2str(unreach2str, "#%d %%s unreachable", + dp->icmp_code); + (void)sprintf(buf, fmt, + ipaddr_string(&dp->icmp_ip.ip_dst)); break; } break; - case ICMP_SOURCEQUENCH: - str = "source quench"; - break; + case ICMP_REDIRECT: TCHECK(dp->icmp_ip.ip_dst, sizeof(dp->icmp_ip.ip_dst)); - switch (dp->icmp_code) { - case ICMP_REDIRECT_NET: - (void)sprintf(buf, "redirect %s to net %s", - ipaddr_string(&dp->icmp_ip.ip_dst), - ipaddr_string(&dp->icmp_gwaddr)); - break; - case ICMP_REDIRECT_HOST: - (void)sprintf(buf, "redirect %s to host %s", - ipaddr_string(&dp->icmp_ip.ip_dst), - ipaddr_string(&dp->icmp_gwaddr)); - break; - case ICMP_REDIRECT_TOSNET: - (void)sprintf(buf, "redirect-tos %s to net %s", - ipaddr_string(&dp->icmp_ip.ip_dst), - ipaddr_string(&dp->icmp_gwaddr)); - break; - case ICMP_REDIRECT_TOSHOST: - (void)sprintf(buf, "redirect-tos %s to host %s", - ipaddr_string(&dp->icmp_ip.ip_dst), - ipaddr_string(&dp->icmp_gwaddr)); - break; - } - break; - case ICMP_ECHO: - str = "echo request"; + fmt = tok2str(type2str, "redirect-#%d %%s to net %%s", + dp->icmp_code); + (void)sprintf(buf, fmt, + ipaddr_string(&dp->icmp_ip.ip_dst), + ipaddr_string(&dp->icmp_gwaddr)); break; + case ICMP_TIMXCEED: TCHECK(dp->icmp_ip.ip_dst, sizeof(dp->icmp_ip.ip_dst)); switch (dp->icmp_code) { + case ICMP_TIMXCEED_INTRANS: str = "time exceeded in-transit"; break; + case ICMP_TIMXCEED_REASS: str = "ip reassembly time exceeded"; break; + + default: + (void)sprintf(buf, "time exceeded-#%d", dp->icmp_code); + break; } break; + case ICMP_PARAMPROB: if (dp->icmp_code) (void)sprintf(buf, "parameter problem - code %d", @@ -186,28 +232,15 @@ icmp_print(register const u_char *bp, register const u_char *bp2) dp->icmp_pptr); } break; - case ICMP_TSTAMP: - str = "time stamp request"; - break; - case ICMP_TSTAMPREPLY: - str = "time stamp reply"; - break; - case ICMP_IREQ: - str = "information request"; - break; - case ICMP_IREQREPLY: - str = "information reply"; - break; - case ICMP_MASKREQ: - str = "address mask request"; - break; + case ICMP_MASKREPLY: TCHECK(dp->icmp_mask, sizeof(dp->icmp_mask)); (void)sprintf(buf, "address mask is 0x%08x", - ntohl(dp->icmp_mask)); + (u_int32_t)ntohl(dp->icmp_mask)); break; + default: - (void)sprintf(buf, "type-#%d", dp->icmp_type); + str = tok2str(icmp2str, "type-#%d", dp->icmp_type); break; } (void)printf("icmp: %s", str); diff --git a/usr.sbin/tcpdump/print-ip.c b/usr.sbin/tcpdump/print-ip.c index b8540e61f14..8668e0d01a7 100644 --- a/usr.sbin/tcpdump/print-ip.c +++ b/usr.sbin/tcpdump/print-ip.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-ip.c,v 1.3 1996/06/10 07:47:38 deraadt Exp $ */ -/* $NetBSD: print-ip.c,v 1.4 1995/04/24 13:27:43 cgd Exp $ */ +/* $OpenBSD: print-ip.c,v 1.4 1996/07/13 11:01:23 mickey Exp $ */ /* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,7 +23,7 @@ #ifndef lint static char rcsid[] = - "@(#) Header: print-ip.c,v 1.38 94/06/14 20:17:40 leres Exp (LBL)"; + "@(#) Header: print-ip.c,v 1.49 96/06/20 22:01:23 leres Exp (LBL)"; #endif #include <sys/param.h> @@ -42,14 +41,108 @@ static char rcsid[] = #include <netinet/tcpip.h> #include <stdio.h> -#ifdef __STDC__ #include <stdlib.h> -#endif +#include <string.h> #include <unistd.h> #include "interface.h" #include "addrtoname.h" +/* Compatibility */ +#ifndef IPPROTO_ND +#define IPPROTO_ND 77 +#endif + +#ifndef IN_CLASSD +#define IN_CLASSD(i) (((int32_t)(i) & 0xf0000000) == 0xe0000000) +#endif + +/* (following from ipmulti/mrouted/prune.h) */ + +/* + * The packet format for a traceroute request. + */ +struct tr_query { + u_int tr_src; /* traceroute source */ + u_int tr_dst; /* traceroute destination */ + u_int tr_raddr; /* traceroute response address */ +#if defined(BYTE_ORDER) && (BYTE_ORDER == LITTLE_ENDIAN) + struct { + u_int qid : 24; /* traceroute query id */ + u_int ttl : 8; /* traceroute response ttl */ + } q; +#else + struct { + u_int ttl : 8; /* traceroute response ttl */ + u_int qid : 24; /* traceroute query id */ + } q; +#endif /* BYTE_ORDER */ +}; + +#define tr_rttl q.ttl +#define tr_qid q.qid + +/* + * Traceroute response format. A traceroute response has a tr_query at the + * beginning, followed by one tr_resp for each hop taken. + */ +struct tr_resp { + u_int tr_qarr; /* query arrival time */ + u_int tr_inaddr; /* incoming interface address */ + u_int tr_outaddr; /* outgoing interface address */ + u_int tr_rmtaddr; /* parent address in source tree */ + u_int tr_vifin; /* input packet count on interface */ + u_int tr_vifout; /* output packet count on interface */ + u_int tr_pktcnt; /* total incoming packets for src-grp */ + u_char tr_rproto; /* routing protocol deployed on router */ + u_char tr_fttl; /* ttl required to forward on outvif */ + u_char tr_smask; /* subnet mask for src addr */ + u_char tr_rflags; /* forwarding error codes */ +}; + +/* defs within mtrace */ +#define TR_QUERY 1 +#define TR_RESP 2 + +/* fields for tr_rflags (forwarding error codes) */ +#define TR_NO_ERR 0 +#define TR_WRONG_IF 1 +#define TR_PRUNED 2 +#define TR_OPRUNED 3 +#define TR_SCOPED 4 +#define TR_NO_RTE 5 +#define TR_NO_FWD 7 +#define TR_NO_SPACE 0x81 +#define TR_OLD_ROUTER 0x82 + +/* fields for tr_rproto (routing protocol) */ +#define TR_PROTO_DVMRP 1 +#define TR_PROTO_MOSPF 2 +#define TR_PROTO_PIM 3 +#define TR_PROTO_CBT 4 + +static void print_mtrace(register const u_char *bp, register int len) +{ + register struct tr_query* tr = (struct tr_query*)(bp + 8); + + printf("mtrace %d: %s to %s reply-to %s", tr->tr_qid, + ipaddr_string(&tr->tr_src), ipaddr_string(&tr->tr_dst), + ipaddr_string(&tr->tr_raddr)); + if (IN_CLASSD(ntohl(tr->tr_raddr))) + printf(" with-ttl %d", tr->tr_rttl); +} + +static void print_mresp(register const u_char *bp, register int len) +{ + register struct tr_query* tr = (struct tr_query*)(bp + 8); + + printf("mresp %d: %s to %s reply-to %s", tr->tr_qid, + ipaddr_string(&tr->tr_src), ipaddr_string(&tr->tr_dst), + ipaddr_string(&tr->tr_raddr)); + if (IN_CLASSD(ntohl(tr->tr_raddr))) + printf(" with-ttl %d", tr->tr_rttl); +} + static void igmp_print(register const u_char *bp, register int len, register const u_char *bp2) @@ -67,23 +160,41 @@ igmp_print(register const u_char *bp, register int len, (void)printf("[|igmp]"); return; } - switch (bp[0] & 0xf) { - case 1: + switch (bp[0]) { + case 0x11: (void)printf("igmp query"); if (*(int *)&bp[4]) (void)printf(" [gaddr %s]", ipaddr_string(&bp[4])); if (len != 8) (void)printf(" [len %d]", len); break; - case 2: + case 0x12: (void)printf("igmp report %s", ipaddr_string(&bp[4])); if (len != 8) (void)printf(" [len %d]", len); break; - case 3: - (void)printf("igmp dvmrp %s", ipaddr_string(&bp[4])); + case 0x16: + (void)printf("igmp nreport %s", ipaddr_string(&bp[4])); + break; + case 0x17: + (void)printf("igmp leave %s", ipaddr_string(&bp[4])); + break; + case 0x13: + (void)printf("igmp dvmrp"); if (len < 8) (void)printf(" [len %d]", len); + else + dvmrp_print(bp, len); + break; + case 0x14: + (void)printf("igmp pim"); + pim_print(bp, len); + break; + case 0x1e: + print_mresp(bp, len); + break; + case 0x1f: + print_mtrace(bp, len); break; default: (void)printf("igmp-%d", bp[0] & 0xf); @@ -91,8 +202,6 @@ igmp_print(register const u_char *bp, register int len, } if ((bp[0] >> 4) != 1) (void)printf(" [v%d]", bp[0] >> 4); - if (bp[1]) - (void)printf(" [b1=0x%x]", bp[1]); } /* @@ -117,7 +226,7 @@ ip_printroute(const char *type, register const u_char *cp, int length) #ifdef TCPDUMP_ALIGN { struct in_addr addr; - bcopy((char *)&cp[len], (char *)&addr, sizeof(addr)); + memcpy((char *)&addr, (char *)&cp[len], sizeof(addr)); printf("%s%s", type, ipaddr_string(&addr)); } #else @@ -140,6 +249,10 @@ ip_optprint(register const u_char *cp, int length) int tt = *cp; len = (tt == IPOPT_NOP || tt == IPOPT_EOL) ? 1 : cp[1]; + if (len <= 0) { + printf("[|ip op len %d]", len); + return; + } if (&cp[1] >= snapend || cp + len > snapend) { printf("[|ip]"); return; @@ -192,7 +305,7 @@ static int in_cksum(const struct ip *ip) { register const u_short *sp = (u_short *)ip; - register u_int32 sum = 0; + register u_int32_t sum = 0; register int count; /* @@ -227,11 +340,14 @@ ip_print(register const u_char *bp, register int length) * dumps from -r. */ if ((long)ip & (sizeof(long)-1)) { - static u_char *abuf; + static u_char *abuf = NULL; - if (abuf == 0) + if (abuf == NULL) { abuf = (u_char *)malloc(snaplen); - bcopy((char *)ip, (char *)abuf, min(length, snaplen)); + if (abuf == NULL) + error("ip_print: malloc"); + } + memcpy((char *)abuf, (char *)ip, min(length, snaplen)); snapend += abuf - (u_char *)ip; packetp = abuf; ip = (struct ip *)abuf; @@ -350,11 +466,13 @@ ip_print(register const u_char *bp, register int length) (void)printf("%sid %d", sep, (int)ntohs(ip->ip_id)); sep = ", "; } - sum = in_cksum(ip); - if (sum != 0) { - (void)printf("%sbad cksum %x!", sep, - ntohs(ip->ip_sum)); - sep = ", "; + if ((u_char *)ip + hlen <= snapend) { + sum = in_cksum(ip); + if (sum != 0) { + (void)printf("%sbad cksum %x!", sep, + ntohs(ip->ip_sum)); + sep = ", "; + } } if ((hlen -= sizeof(struct ip)) > 0) { (void)printf("%soptlen=%d", sep, hlen); diff --git a/usr.sbin/tcpdump/print-ipx.c b/usr.sbin/tcpdump/print-ipx.c index 41f0b9d0665..2f9728ae429 100644 --- a/usr.sbin/tcpdump/print-ipx.c +++ b/usr.sbin/tcpdump/print-ipx.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-ipx.c,v 1.3 1996/06/10 07:47:39 deraadt Exp $ */ -/* $NetBSD: print-ipx.c,v 1.2 1995/03/06 19:11:16 mycroft Exp $ */ +/* $OpenBSD: print-ipx.c,v 1.4 1996/07/13 11:01:24 mickey Exp $ */ /* - * Copyright (c) 1994 + * Copyright (c) 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,10 +27,11 @@ */ #ifndef lint static char rcsid[] = - "@(#)Header: print-ipx.c,v 1.6 94/06/20 19:44:38 leres Exp"; + "@(#)Header: print-ipx.c,v 1.10 96/05/16 12:46:02 leres Exp"; #endif #include <sys/param.h> +#include <sys/time.h> #include <sys/types.h> #include <sys/socket.h> @@ -56,7 +56,7 @@ static char rcsid[] = #include "extract.h" -static const char *ipxaddr_string(u_int32 net, const u_char *node); +static const char *ipxaddr_string(u_int32_t net, const u_char *node); void ipx_decode(const struct ipxHdr *ipx, const u_char *datap, int length); void ipx_sap_print(const u_short *ipx, int length); void ipx_rip_print(const u_short *ipx, int length); @@ -93,11 +93,11 @@ ipx_print(const u_char *p, int length) } static const char * -ipxaddr_string(u_int32 net, const u_char *node) +ipxaddr_string(u_int32_t net, const u_char *node) { static char line[256]; - sprintf(line, "%lu.%02x:%02x:%02x:%02x:%02x:%02x", + sprintf(line, "%u.%02x:%02x:%02x:%02x:%02x:%02x", net, node[0], node[1], node[2], node[3], node[4], node[5]); return line; @@ -106,7 +106,10 @@ ipxaddr_string(u_int32 net, const u_char *node) void ipx_decode(const struct ipxHdr *ipx, const u_char *datap, int length) { - switch (EXTRACT_SHORT(&ipx->dstSkt)) { + register u_short dstSkt; + + dstSkt = EXTRACT_SHORT(&ipx->dstSkt); + switch (dstSkt) { case IPX_SKT_NCP: (void)printf(" ipx-ncp %d", length); break; @@ -123,7 +126,7 @@ ipx_decode(const struct ipxHdr *ipx, const u_char *datap, int length) (void)printf(" ipx-diags %d", length); break; default: - (void)printf(" ipx-#%x %d", ipx->dstSkt, length); + (void)printf(" ipx-#%x %d", dstSkt, length); break; } } @@ -195,13 +198,13 @@ ipx_rip_print(const u_short *ipx, int length) case 1: (void)printf("ipx-rip-req"); if (length > 0) - (void)printf(" %lu/%d.%d", EXTRACT_LONG(&ipx[0]), + (void)printf(" %u/%d.%d", EXTRACT_LONG(&ipx[0]), EXTRACT_SHORT(&ipx[2]), EXTRACT_SHORT(&ipx[3])); break; case 2: (void)printf("ipx-rip-resp"); for (i = 0; i < 50 && length > 0; i++) { - (void)printf(" %lu/%d.%d", EXTRACT_LONG(&ipx[0]), + (void)printf(" %u/%d.%d", EXTRACT_LONG(&ipx[0]), EXTRACT_SHORT(&ipx[2]), EXTRACT_SHORT(&ipx[3])); ipx += 4; diff --git a/usr.sbin/tcpdump/print-isoclns.c b/usr.sbin/tcpdump/print-isoclns.c index 9f7229f0d81..7da20c48109 100644 --- a/usr.sbin/tcpdump/print-isoclns.c +++ b/usr.sbin/tcpdump/print-isoclns.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-isoclns.c,v 1.3 1996/06/10 07:47:40 deraadt Exp $ */ -/* $NetBSD: print-isoclns.c,v 1.2 1995/03/06 19:11:17 mycroft Exp $ */ +/* $OpenBSD: print-isoclns.c,v 1.4 1996/07/13 11:01:24 mickey Exp $ */ /* - * Copyright (c) 1992, 1993, 1994 + * Copyright (c) 1992, 1993, 1994, 1995 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,13 +27,17 @@ #ifndef lint static char rcsid[] = - "@(#) Header: print-isoclns.c,v 1.9 94/06/14 20:18:44 leres Exp (LBL)"; + "@(#) Header: print-isoclns.c,v 1.11 95/10/19 20:27:45 leres Exp (LBL)"; #endif #include <sys/types.h> #include <sys/time.h> #include <sys/socket.h> +#if __STDC__ +struct mbuf; +struct rtentry; +#endif #include <net/if.h> #include <netinet/in.h> @@ -288,7 +291,7 @@ osi_cksum(register const u_char *p, register int len, const u_char *toff, u_char *cksum, u_char *off) { int x, y, f = (len - ((toff - p) + 1)); - long c0 = 0, c1 = 0; + int32_t c0 = 0, c1 = 0; if ((cksum[0] = off[0]) == 0 && (cksum[1] = off[1]) == 0) return 0; diff --git a/usr.sbin/tcpdump/print-krb.c b/usr.sbin/tcpdump/print-krb.c new file mode 100644 index 00000000000..299013acc98 --- /dev/null +++ b/usr.sbin/tcpdump/print-krb.c @@ -0,0 +1,301 @@ +/* $OpenBSD: print-krb.c,v 1.1 1996/07/13 11:01:25 mickey Exp $ */ + +/* + * Copyright (c) 1995 + * 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. + * + * Initial contribution from John Hawkinson (jhawk@mit.edu). + */ + +#ifndef lint +static char rcsid[] = + "@(#) Header: print-krb.c,v 1.3 95/10/08 15:15:17 leres 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 <ctype.h> +#include <errno.h> +#include <stdio.h> + +#include "interface.h" +#include "addrtoname.h" + +const u_char *c_print(register const u_char *s, register const u_char *ep); +const u_char *krb4_print_hdr(const u_char *cp); +void krb4_print(const u_char *cp); +void krb_print(const u_char *dat, int length); + + +#define AUTH_MSG_KDC_REQUEST 1<<1 +#define AUTH_MSG_KDC_REPLY 2<<1 +#define AUTH_MSG_APPL_REQUEST 3<<1 +#define AUTH_MSG_APPL_REQUEST_MUTUAL 4<<1 +#define AUTH_MSG_ERR_REPLY 5<<1 +#define AUTH_MSG_PRIVATE 6<<1 +#define AUTH_MSG_SAFE 7<<1 +#define AUTH_MSG_APPL_ERR 8<<1 +#define AUTH_MSG_DIE 63<<1 + +#define KERB_ERR_OK 0 +#define KERB_ERR_NAME_EXP 1 +#define KERB_ERR_SERVICE_EXP 2 +#define KERB_ERR_AUTH_EXP 3 +#define KERB_ERR_PKT_VER 4 +#define KERB_ERR_NAME_MAST_KEY_VER 5 +#define KERB_ERR_SERV_MAST_KEY_VER 6 +#define KERB_ERR_BYTE_ORDER 7 +#define KERB_ERR_PRINCIPAL_UNKNOWN 8 +#define KERB_ERR_PRINCIPAL_NOT_UNIQUE 9 +#define KERB_ERR_NULL_KEY 10 + +struct krb { + u_char pvno; /* Protocol Version */ + u_char type; /* Type+B */ +}; + +static char tstr[] = " [|kerberos]"; + +static struct tok type2str[] = { + { AUTH_MSG_KDC_REQUEST, "KDC_REQUEST" }, + { AUTH_MSG_KDC_REPLY, "KDC_REPLY" }, + { AUTH_MSG_APPL_REQUEST, "APPL_REQUEST" }, + { AUTH_MSG_APPL_REQUEST_MUTUAL, "APPL_REQUEST_MUTUAL" }, + { AUTH_MSG_ERR_REPLY, "ERR_REPLY" }, + { AUTH_MSG_PRIVATE, "PRIVATE" }, + { AUTH_MSG_SAFE, "SAFE" }, + { AUTH_MSG_APPL_ERR, "APPL_ERR" }, + { AUTH_MSG_DIE, "DIE" }, + { 0, NULL } +}; + +static struct tok kerr2str[] = { + { KERB_ERR_OK, "OK" }, + { KERB_ERR_NAME_EXP, "NAME_EXP" }, + { KERB_ERR_SERVICE_EXP, "SERVICE_EXP" }, + { KERB_ERR_AUTH_EXP, "AUTH_EXP" }, + { KERB_ERR_PKT_VER, "PKT_VER" }, + { KERB_ERR_NAME_MAST_KEY_VER, "NAME_MAST_KEY_VER" }, + { KERB_ERR_SERV_MAST_KEY_VER, "SERV_MAST_KEY_VER" }, + { KERB_ERR_BYTE_ORDER, "BYTE_ORDER" }, + { KERB_ERR_PRINCIPAL_UNKNOWN, "PRINCIPAL_UNKNOWN" }, + { KERB_ERR_PRINCIPAL_NOT_UNIQUE, "PRINCIPAL_NOT_UNIQUE" }, + { KERB_ERR_NULL_KEY, "NULL_KEY"}, + { 0, NULL} +}; + + +/* little endian (unaligned) to host byte order */ +/* XXX need to look at this... */ +#define vtohlp(x) ((( ((char*)(x))[0] ) ) | \ + (( ((char*)(x))[1] ) << 8) | \ + (( ((char*)(x))[2] ) << 16) | \ + (( ((char*)(x))[3] ) << 24)) +#define vtohsp(x) ((( ((char*)(x))[0] ) ) | \ + (( ((char*)(x))[1] ) << 8)) +/* network (big endian) (unaligned) to host byte order */ +#define ntohlp(x) ((( ((char*)(x))[3] ) ) | \ + (( ((char*)(x))[2] ) << 8) | \ + (( ((char*)(x))[1] ) << 16) | \ + (( ((char*)(x))[0] ) << 24)) +#define ntohsp(x) ((( ((char*)(x))[1] ) ) | \ + (( ((char*)(x))[0] ) << 8)) + + + +const u_char * +c_print(register const u_char *s, register const u_char *ep) +{ + register u_char c; + register int flag; + + flag = 1; + while (ep == NULL || s < ep) { + c = *s++; + if (c == '\0') { + flag = 0; + break; + } + if (!isascii(c)) { + c = toascii(c); + putchar('M'); + putchar('-'); + } + if (!isprint(c)) { + c ^= 0x40; /* DEL to ?, others to alpha */ + putchar('^'); + } + putchar(c); + } + if (flag) + return NULL; + return(s); +} + +const u_char * +krb4_print_hdr(const u_char *cp) +{ + cp+=2; + +#define TCHECK if (cp >= snapend) goto trunc +#define PRINT if ((cp=c_print(cp, snapend))==NULL) goto trunc + + TCHECK; + PRINT; + TCHECK; + putchar('.'); PRINT; + TCHECK; + putchar('@'); PRINT; + return(cp); + +trunc: + fputs(tstr, stdout); + return(NULL); + +#undef TCHECK +#undef PRINT +} + +void +krb4_print(const u_char *cp) +{ + register const struct krb *kp; + u_char type; + u_short len; + +#define TCHECK if (cp >= snapend) goto trunc +#define PRINT if ((cp=c_print(cp, snapend))==NULL) goto trunc +/* True if struct krb is little endian */ +#define IS_LENDIAN(kp) (((kp)->type & 0x01) != 0) +#define KTOHSP(kp, cp) (IS_LENDIAN(kp) ? vtohsp(cp) : ntohsp(cp)) + + kp = (struct krb *)cp; + + if ((&kp->type) >= snapend) { + fputs(tstr, stdout); + return; + } + + type = kp->type & (0xFF << 1); + + printf(" %s %s: ", + IS_LENDIAN(kp) ? "le" : "be", tok2str(type2str, NULL, type)); + + switch (type) { + + case AUTH_MSG_KDC_REQUEST: + if ((cp = krb4_print_hdr(cp)) == NULL) + return; + cp += 4; /* ctime */ + TCHECK; + printf(" %dmin ", *cp++ * 5); + TCHECK; + PRINT; + TCHECK; + putchar('.'); PRINT; + break; + + case AUTH_MSG_APPL_REQUEST: + cp += 2; + TCHECK; + printf("v%d ", *cp++); + TCHECK; + PRINT; + TCHECK; + printf(" (%d)", *cp++); + TCHECK; + printf(" (%d)", *cp); + TCHECK; + break; + + case AUTH_MSG_KDC_REPLY: + if ((cp = krb4_print_hdr(cp)) == NULL) + return; + cp += 10; /* timestamp + n + exp + kvno */ + TCHECK; + len = KTOHSP(kp, cp); + printf(" (%d)", len); + TCHECK; + break; + + case AUTH_MSG_ERR_REPLY: + if ((cp = krb4_print_hdr(cp)) == NULL) + return; + cp += 4; /* timestamp */ + TCHECK; + printf(" %s ", tok2str(kerr2str, NULL, KTOHSP(kp, cp))); + cp += 4; + TCHECK; + PRINT; + break; + + default: + fputs("(unknown)", stdout); + break; + } + + return; +trunc: + fputs(tstr, stdout); +#undef TCHECK +} + +void +krb_print(const u_char *dat, int length) +{ + register const struct krb *kp; + + kp = (struct krb *)dat; + + if (dat >= snapend) { + fputs(tstr, stdout); + return; + } + + switch (kp->pvno) { + + case 1: + case 2: + case 3: + printf(" v%d", kp->pvno); + break; + + case 4: + printf(" v%d", kp->pvno); + krb4_print((const u_char*)kp); + break; + + case 106: + case 107: + fputs(" v5", stdout); + /* Decode ASN.1 here "someday" */ + break; + } + return; +} diff --git a/usr.sbin/tcpdump/print-llc.c b/usr.sbin/tcpdump/print-llc.c index 6913b3c8684..3aca65d0f30 100644 --- a/usr.sbin/tcpdump/print-llc.c +++ b/usr.sbin/tcpdump/print-llc.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-llc.c,v 1.3 1996/06/10 07:47:41 deraadt Exp $ */ -/* $NetBSD: print-llc.c,v 1.2 1995/03/06 19:11:19 mycroft Exp $ */ +/* $OpenBSD: print-llc.c,v 1.4 1996/07/13 11:01:25 mickey Exp $ */ /* - * Copyright (c) 1992, 1993, 1994 + * Copyright (c) 1992, 1993, 1994, 1995 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,7 +28,7 @@ #ifndef lint static char rcsid[] = - "@(#)Header: print-llc.c,v 1.13 94/06/14 20:18:45 leres Exp"; + "@(#)Header: print-llc.c,v 1.17 95/09/26 02:03:40 leres Exp"; #endif #include <sys/param.h> @@ -39,10 +38,10 @@ static char rcsid[] = #include <netinet/in.h> #include <ctype.h> -#include <errno.h> #include <netdb.h> #include <signal.h> #include <stdio.h> +#include <string.h> #include "interface.h" #include "addrtoname.h" @@ -50,7 +49,7 @@ static char rcsid[] = #include "llc.h" -static struct token cmd2str[] = { +static struct tok cmd2str[] = { { LLC_UI, "ui" }, { LLC_TEST, "test" }, { LLC_XID, "xid" }, @@ -80,7 +79,7 @@ llc_print(const u_char *p, int length, int caplen, } /* Watch out for possible alignment problems */ - bcopy((char *)p, (char *)&llc, min(caplen, sizeof(llc))); + memcpy((char *)&llc, (char *)p, min(caplen, sizeof(llc))); if (llc.ssap == LLCSAP_GLOBAL && llc.dsap == LLCSAP_GLOBAL) { ipx_print(p, length); diff --git a/usr.sbin/tcpdump/print-nfs.c b/usr.sbin/tcpdump/print-nfs.c index 91fe5c6778c..3dd8deb2a7f 100644 --- a/usr.sbin/tcpdump/print-nfs.c +++ b/usr.sbin/tcpdump/print-nfs.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-nfs.c,v 1.3 1996/06/10 07:47:42 deraadt Exp $ */ -/* $NetBSD: print-nfs.c,v 1.5 1996/05/20 00:41:09 fvdl Exp $ */ +/* $OpenBSD: print-nfs.c,v 1.4 1996/07/13 11:01:26 mickey Exp $ */ /* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,7 +23,7 @@ #ifndef lint static char rcsid[] = - "@(#) Header: print-nfs.c,v 1.41 94/06/12 14:35:15 leres Exp (LBL)"; + "@(#) Header: print-nfs.c,v 1.52 95/10/22 02:46:29 leres Exp (LBL)"; #endif #include <sys/param.h> @@ -32,6 +31,10 @@ static char rcsid[] = #include <sys/types.h> #include <sys/socket.h> +#if __STDC__ +struct mbuf; +struct rtentry; +#endif #include <net/if.h> #include <netinet/in.h> @@ -40,202 +43,23 @@ static char rcsid[] = #include <netinet/ip.h> #include <netinet/ip_var.h> -#ifdef SOLARIS -#include <tiuser.h> -#endif #include <rpc/rpc.h> -#include <rpc/pmap_prot.h> #include <ctype.h> +#include <pcap.h> #include <stdio.h> -#include <errno.h> #include <string.h> #include "interface.h" #include "addrtoname.h" -#include "extract.h" /* must come after interface.h */ -#include "nfs.h" +#include "nfsv2.h" #include "nfsfh.h" -static void nfs_printfh(const u_int32 *, const int); +static void nfs_printfh(const u_int32_t *); static void xid_map_enter(const struct rpc_msg *, const struct ip *); -static int32 xid_map_find(const struct rpc_msg *, const struct ip *, u_int32 *, - u_int32 *); -static void interp_reply(const struct rpc_msg *, u_int32, u_int32, int); -static const u_int32 *parse_post_op_attr(const u_int32 *, int); - -/* - * Mapping of old NFS Version 2 RPC numbers to generic numbers. - */ -u_int32 nfsv3_procid[NFS_NPROCS] = { - NFSPROC_NULL, - NFSPROC_GETATTR, - NFSPROC_SETATTR, - NFSPROC_NOOP, - NFSPROC_LOOKUP, - NFSPROC_READLINK, - NFSPROC_READ, - NFSPROC_NOOP, - NFSPROC_WRITE, - NFSPROC_CREATE, - NFSPROC_REMOVE, - NFSPROC_RENAME, - NFSPROC_LINK, - NFSPROC_SYMLINK, - NFSPROC_MKDIR, - NFSPROC_RMDIR, - NFSPROC_READDIR, - NFSPROC_FSSTAT, - NFSPROC_NOOP, - NFSPROC_NOOP, - NFSPROC_NOOP, - NFSPROC_NOOP, - NFSPROC_NOOP, - NFSPROC_NOOP, - NFSPROC_NOOP, - NFSPROC_NOOP -}; - -const char *nfsv3_writemodes[NFSV3WRITE_NMODES] = { - "unstable", - "datasync", - "filesync" -}; - -static struct token type2str[] = { - { NFNON, "NON" }, - { NFREG, "REG" }, - { NFDIR, "DIR" }, - { NFBLK, "BLK" }, - { NFCHR, "CHR" }, - { NFLNK, "LNK" }, - { NFFIFO, "FIFO" }, - { 0, NULL } -}; - -/* - * Print out a 64-bit integer. This appears to be different on each system, - * try to make the best of it. The integer stored as 2 consecutive XDR - * encoded 32-bit integers, to which a pointer is passed. - * - * Assume that a system that has INT64_FORMAT defined, has a 64-bit - * integer datatype and can print it. - */ - -#define UNSIGNED 0 -#define SIGNED 1 -#define HEX 2 - -int print_int64(const u_int32 *dp, int how) -{ - static char buf[32]; -#ifdef INT64_FORMAT - u_int64 res; - - res = ((u_int64)ntohl(dp[0]) << 32) | (u_int64)ntohl(dp[1]); - switch (how) { - case SIGNED: - printf(INT64_FORMAT, res); - break; - case UNSIGNED: - printf(U_INT64_FORMAT, res); - break; - case HEX: - printf(HEX_INT64_FORMAT, res); - break; - default: - return (0); - } -#else - /* - * XXX - throw upper 32 bits away. - * Could also go for hex: printf("0x%x%x", dp[0], dp[1]); - */ - if (sign) - printf("%ld", (int)dp[1]); - else - printf("%lu", (unsigned int)dp[1]); -#endif - return 1; -} - -static const u_int32 * -parse_sattr3(const u_int32 *dp, struct nfsv3_sattr *sa3) -{ - register const u_int32 *ep = (u_int32 *)snapend; - - if (dp + 1 > ep) - return (0); - if ((sa3->sa_modeset = ntohl(*dp++))) { - if (dp + 1 > ep) - return (0); - sa3->sa_mode = ntohl(*dp++); - } - - if (dp + 1 > ep) - return (0); - if ((sa3->sa_uidset = ntohl(*dp++))) { - if (dp + 1 > ep) - return (0); - sa3->sa_uid = ntohl(*dp++); - } - - if (dp + 1 > ep) - return (0); - if ((sa3->sa_gidset = ntohl(*dp++))) { - if (dp + 1 > ep) - return (0); - sa3->sa_gid = ntohl(*dp++); - } - - if (dp + 1 > ep) - return (0); - if ((sa3->sa_sizeset = ntohl(*dp++))) { - if (dp + 1 > ep) - return (0); - sa3->sa_size = ntohl(*dp++); - } - - if (dp + 1 > ep) - return (0); - if ((sa3->sa_atimetype = ntohl(*dp++)) == NFSV3SATTRTIME_TOCLIENT) { - if (dp + 2 > ep) - return (0); - sa3->sa_atime.nfsv3_sec = ntohl(*dp++); - sa3->sa_atime.nfsv3_nsec = ntohl(*dp++); - } - - if (dp + 1 > ep) - return (0); - if ((sa3->sa_mtimetype = ntohl(*dp++)) == NFSV3SATTRTIME_TOCLIENT) { - if (dp + 2 > ep) - return (0); - sa3->sa_mtime.nfsv3_sec = ntohl(*dp++); - sa3->sa_mtime.nfsv3_nsec = ntohl(*dp++); - } - - return dp; -} - -void -print_sattr3(const struct nfsv3_sattr *sa3, int verbose) -{ - if (sa3->sa_modeset) - printf(" mode %o", sa3->sa_mode); - if (sa3->sa_uidset) - printf(" uid %u", sa3->sa_uid); - if (sa3->sa_gidset) - printf(" gid %u", sa3->sa_gid); - if (verbose > 1) { - if (sa3->sa_atimetype == NFSV3SATTRTIME_TOCLIENT) - printf(" atime %u.%06u", sa3->sa_atime.nfsv3_sec, - sa3->sa_atime.nfsv3_nsec); - if (sa3->sa_mtimetype == NFSV3SATTRTIME_TOCLIENT) - printf(" mtime %u.%06u", sa3->sa_mtime.nfsv3_sec, - sa3->sa_mtime.nfsv3_nsec); - } -} +static int32_t xid_map_find(const struct rpc_msg *, const struct ip *); +static void interp_reply(const struct rpc_msg *, u_int32_t, int); void nfsreply_print(register const u_char *bp, int length, @@ -243,7 +67,7 @@ nfsreply_print(register const u_char *bp, int length, { register const struct rpc_msg *rp; register const struct ip *ip; - u_int32 proc, vers; + int32_t proc; rp = (const struct rpc_msg *)bp; ip = (const struct ip *)bp2; @@ -252,7 +76,7 @@ nfsreply_print(register const u_char *bp, int length, (void)printf("%s.nfs > %s.%x: reply %s %d", ipaddr_string(&ip->ip_src), ipaddr_string(&ip->ip_dst), - ntohl(rp->rm_xid), + (u_int32_t)ntohl(rp->rm_xid), ntohl(rp->rm_reply.rp_stat) == MSG_ACCEPTED? "ok":"ERR", length); @@ -261,24 +85,25 @@ nfsreply_print(register const u_char *bp, int length, ipaddr_string(&ip->ip_src), NFS_PORT, ipaddr_string(&ip->ip_dst), - ntohl(rp->rm_xid), + (u_int32_t)ntohl(rp->rm_xid), ntohl(rp->rm_reply.rp_stat) == MSG_ACCEPTED? "ok":"ERR", length); - if (xid_map_find(rp, ip, &proc, &vers) >= 0) - interp_reply(rp, proc, vers, length); + proc = xid_map_find(rp, ip); + if (proc >= 0) + interp_reply(rp, (u_int32_t)proc, length); } /* * Return a pointer to the first file handle in the packet. * If the packet was truncated, return 0. */ -static const u_int32 * +static const u_int32_t * parsereq(register const struct rpc_msg *rp, register int length) { - register const u_int32 *dp = (u_int32 *)&rp->rm_call.cb_cred; - register const u_int32 *ep = (u_int32 *)snapend; + register const u_int32_t *dp = (u_int32_t *)&rp->rm_call.cb_cred; + register const u_int32_t *ep = (u_int32_t *)snapend; register u_int len; if (&dp[2] >= ep) @@ -288,13 +113,15 @@ parsereq(register const struct rpc_msg *rp, register int length) */ len = ntohl(dp[1]); if (dp < ep && len < length) { - dp += (len + (2 * sizeof(u_int32) + 3)) / sizeof(u_int32); - len = ntohl(dp[1]); - if ((dp < ep) && (len < length)) { - dp += (len + (2 * sizeof(u_int32) + 3)) / - sizeof(u_int32); - if (dp < ep) - return (dp); + dp += (len + (2 * sizeof(u_int32_t) + 3)) / sizeof(u_int32_t); + if (&dp[2] < ep) { + len = ntohl(dp[1]); + if (dp < ep && len < length) { + dp += (len + (2 * sizeof(u_int32_t) + 3)) / + sizeof(u_int32_t); + if (dp < ep) + return (dp); + } } } return (0); @@ -304,22 +131,12 @@ parsereq(register const struct rpc_msg *rp, register int length) * Print out an NFS file handle and return a pointer to following word. * If packet was truncated, return 0. */ -static const u_int32 * -parsefh(register const u_int32 *dp, int v3) +static const u_int32_t * +parsefh(register const u_int32_t *dp) { - int len; - - if (v3) { - if (dp + 1 > (u_int32 *)snapend) - return (0); - len = (int)ntohl(*dp) / 4; - dp++; - } else - len = NFSX_V2FH / 4; - - if (dp + len <= (u_int32 *)snapend) { - nfs_printfh(dp, len); - return (dp + len); + if (dp + 8 <= (u_int32_t *)snapend) { + nfs_printfh(dp); + return (dp + 8); } return (0); } @@ -328,10 +145,10 @@ parsefh(register const u_int32 *dp, int v3) * Print out a file name and return pointer to 32-bit word past it. * If packet was truncated, return 0. */ -static const u_int32 * -parsefn(register const u_int32 *dp) +static const u_int32_t * +parsefn(register const u_int32_t *dp) { - register u_int32 len; + register u_int32_t len; register const u_char *cp; /* Bail if we don't have the string length */ @@ -358,10 +175,10 @@ parsefn(register const u_int32 *dp) * Return pointer to 32-bit word past file name. * If packet was truncated (or there was some other error), return 0. */ -static const u_int32 * -parsefhn(register const u_int32 *dp, int v3) +static const u_int32_t * +parsefhn(register const u_int32_t *dp) { - dp = parsefh(dp, v3); + dp = parsefh(dp); if (dp == 0) return (0); putchar(' '); @@ -373,11 +190,8 @@ nfsreq_print(register const u_char *bp, int length, register const u_char *bp2) { register const struct rpc_msg *rp; register const struct ip *ip; - register const u_int32 *dp; + register const u_int32_t *dp; register const u_char *ep; - nfstype type; - int proc, v3; - struct nfsv3_sattr sa3; #define TCHECK(p, l) if ((u_char *)(p) > ep - l) break @@ -387,175 +201,119 @@ nfsreq_print(register const u_char *bp, int length, register const u_char *bp2) if (!nflag) (void)printf("%s.%x > %s.nfs: %d", ipaddr_string(&ip->ip_src), - ntohl(rp->rm_xid), + (u_int32_t)ntohl(rp->rm_xid), ipaddr_string(&ip->ip_dst), length); else (void)printf("%s.%x > %s.%x: %d", ipaddr_string(&ip->ip_src), - ntohl(rp->rm_xid), + (u_int32_t)ntohl(rp->rm_xid), ipaddr_string(&ip->ip_dst), NFS_PORT, length); xid_map_enter(rp, ip); /* record proc number for later on */ - v3 = (ntohl(rp->rm_call.cb_vers) == NFS_VER3); - proc = ntohl(rp->rm_call.cb_proc); - - if (!v3 && proc < NFS_NPROCS) - proc = nfsv3_procid[proc]; - - switch (proc) { + switch (ntohl(rp->rm_call.cb_proc)) { +#ifdef NFSPROC_NOOP case NFSPROC_NOOP: printf(" nop"); return; +#else +#define NFSPROC_NOOP -1 +#endif case NFSPROC_NULL: printf(" null"); return; case NFSPROC_GETATTR: printf(" getattr"); - if ((dp = parsereq(rp, length)) != 0 && parsefh(dp, v3) != 0) + if ((dp = parsereq(rp, length)) != 0 && parsefh(dp) != 0) return; break; case NFSPROC_SETATTR: printf(" setattr"); - if ((dp = parsereq(rp, length)) != 0 && parsefh(dp, v3) != 0) + if ((dp = parsereq(rp, length)) != 0 && parsefh(dp) != 0) return; break; +#if NFSPROC_ROOT != NFSPROC_NOOP + case NFSPROC_ROOT: + printf(" root"); + break; +#endif case NFSPROC_LOOKUP: printf(" lookup"); - if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp, v3) != 0) + if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp) != 0) return; break; - case NFSPROC_ACCESS: - printf(" access"); - if ((dp = parsereq(rp, length)) != 0 && - (dp = parsefh(dp, v3)) != 0) { - TCHECK(dp, 4); - printf(" %04x", ntohl(dp[0])); - return; - } - break; - case NFSPROC_READLINK: printf(" readlink"); - if ((dp = parsereq(rp, length)) != 0 && parsefh(dp, v3) != 0) + if ((dp = parsereq(rp, length)) != 0 && parsefh(dp) != 0) return; break; case NFSPROC_READ: printf(" read"); if ((dp = parsereq(rp, length)) != 0 && - (dp = parsefh(dp, v3)) != 0) { - if (v3) { - TCHECK(dp, 3 * sizeof(*dp)); - printf(" %lu bytes @ ", ntohl(dp[2])); - print_int64(dp, UNSIGNED); - } else { - TCHECK(dp, 2 * sizeof(*dp)); - printf(" %lu bytes @ %lu", - ntohl(dp[1]), ntohl(dp[0])); - } + (dp = parsefh(dp)) != 0) { + TCHECK(dp, 3 * sizeof(*dp)); + printf(" %u bytes @ %u", + (u_int32_t)ntohl(dp[1]), + (u_int32_t)ntohl(dp[0])); return; } break; - case NFSPROC_WRITE: - printf(" write"); +#if NFSPROC_WRITECACHE != NFSPROC_NOOP + case NFSPROC_WRITECACHE: + printf(" writecache"); if ((dp = parsereq(rp, length)) != 0 && - (dp = parsefh(dp, v3)) != 0) { - if (v3) { - TCHECK(dp, 3 * sizeof(*dp)); - printf(" %lu bytes @ ", ntohl(dp[4])); - print_int64(dp, UNSIGNED); - if (vflag) { - dp += 3; - TCHECK(dp, sizeof(*dp)); - printf(" <%s>", - nfsv3_writemodes[ntohl(*dp)]); - } - } else { - TCHECK(dp, 4 * sizeof(*dp)); - printf(" %lu (%lu) bytes @ %lu (%lu)", - ntohl(dp[3]), ntohl(dp[2]), - ntohl(dp[1]), ntohl(dp[0])); - } + (dp = parsefh(dp)) != 0) { + TCHECK(dp, 4 * sizeof(*dp)); + printf(" %u (%u) bytes @ %u (%u)", + (u_int32_t)ntohl(dp[3]), + (u_int32_t)ntohl(dp[2]), + (u_int32_t)ntohl(dp[1]), + (u_int32_t)ntohl(dp[0])); return; } break; - - case NFSPROC_CREATE: - printf(" create"); - if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp, v3) != 0) - return; - break; - - case NFSPROC_MKDIR: - printf(" mkdir"); - if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp, v3) != 0) - return; - break; - - case NFSPROC_SYMLINK: - printf(" symlink"); +#endif + case NFSPROC_WRITE: + printf(" write"); if ((dp = parsereq(rp, length)) != 0 && - (dp = parsefhn(dp, v3)) != 0) { - fputs(" -> ", stdout); - if (v3 && (dp = parse_sattr3(dp, &sa3)) == 0) - break; - if (parsefn(dp) == 0) - break; - if (v3 && vflag) - print_sattr3(&sa3, vflag); + (dp = parsefh(dp)) != 0) { + TCHECK(dp, 4 * sizeof(*dp)); + printf(" %u (%u) bytes @ %u (%u)", + (u_int32_t)ntohl(dp[3]), + (u_int32_t)ntohl(dp[2]), + (u_int32_t)ntohl(dp[1]), + (u_int32_t)ntohl(dp[0])); return; } break; - case NFSPROC_MKNOD: - printf(" mknod"); - if ((dp = parsereq(rp, length)) != 0 && - (dp = parsefhn(dp, v3)) != 0) { - if (dp + 1 > (u_int32 *)snapend) - break; - type = (nfstype)ntohl(*dp++); - if ((dp = parse_sattr3(dp, &sa3)) == 0) - break; - printf(" %s", tok2str(type2str, "unk-ft %d", type)); - if (vflag && (type == NFCHR || type == NFBLK)) { - if (dp + 2 > (u_int32 *)snapend) - break; - printf(" %u/%u", ntohl(dp[0]), ntohl(dp[1])); - dp += 2; - } - if (vflag) - print_sattr3(&sa3, vflag); + case NFSPROC_CREATE: + printf(" create"); + if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp) != 0) return; - } break; case NFSPROC_REMOVE: printf(" remove"); - if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp, v3) != 0) - return; - break; - - case NFSPROC_RMDIR: - printf(" rmdir"); - if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp, v3) != 0) + if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp) != 0) return; break; case NFSPROC_RENAME: printf(" rename"); if ((dp = parsereq(rp, length)) != 0 && - (dp = parsefhn(dp, v3)) != 0) { + (dp = parsefhn(dp)) != 0) { fputs(" ->", stdout); - if (parsefhn(dp, v3) != 0) + if (parsefhn(dp) != 0) return; } break; @@ -563,88 +321,63 @@ nfsreq_print(register const u_char *bp, int length, register const u_char *bp2) case NFSPROC_LINK: printf(" link"); if ((dp = parsereq(rp, length)) != 0 && - (dp = parsefh(dp, v3)) != 0) { + (dp = parsefh(dp)) != 0) { fputs(" ->", stdout); - if (parsefhn(dp, v3) != 0) + if (parsefhn(dp) != 0) return; } break; - case NFSPROC_READDIR: - printf(" readdir"); + case NFSPROC_SYMLINK: + printf(" symlink"); if ((dp = parsereq(rp, length)) != 0 && - (dp = parsefh(dp, v3)) != 0) { - if (v3) { - TCHECK(dp, 20); - /* - * We shouldn't really try to interpret the - * offset cookie here. - */ - printf(" %lu bytes @ ", ntohl(dp[4])); - print_int64(dp, SIGNED); - if (vflag) - printf(" verf %08lx%08lx", dp[2], - dp[3]); - } else { - TCHECK(dp, 2 * sizeof(*dp)); - /* - * Print the offset as signed, since -1 is - * common, but offsets > 2^31 aren't. - */ - printf(" %lu bytes @ %ld", ntohl(dp[1]), - ntohl(dp[0])); - } - return; + (dp = parsefhn(dp)) != 0) { + fputs(" -> ", stdout); + if (parsefn(dp) != 0) + return; } break; - case NFSPROC_READDIRPLUS: - printf(" readdirplus"); - if ((dp = parsereq(rp, length)) != 0 && - (dp = parsefh(dp, v3)) != 0) { - TCHECK(dp, 20); - /* - * We don't try to interpret the offset - * cookie here. - */ - printf(" %lu bytes @ ", ntohl(dp[4])); - print_int64(dp, SIGNED); - if (vflag) - printf(" max %lu verf %08lx%08lx", - ntohl(dp[5]), dp[2], dp[3]); + case NFSPROC_MKDIR: + printf(" mkdir"); + if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp) != 0) return; - } break; - case NFSPROC_FSSTAT: - printf(" fsstat"); - if ((dp = parsereq(rp, length)) != 0 && parsefh(dp, v3) != 0) + case NFSPROC_RMDIR: + printf(" rmdir"); + if ((dp = parsereq(rp, length)) != 0 && parsefhn(dp) != 0) return; break; - case NFSPROC_FSINFO: - printf(" fsinfo"); - break; - - case NFSPROC_PATHCONF: - printf(" pathconf"); - break; - - case NFSPROC_COMMIT: - printf(" commit"); + case NFSPROC_READDIR: + printf(" readdir"); if ((dp = parsereq(rp, length)) != 0 && - (dp = parsefh(dp, v3)) != 0) { - printf(" %lu bytes @ ", ntohl(dp[2])); - print_int64(dp, UNSIGNED); + (dp = parsefh(dp)) != 0) { + TCHECK(dp, 2 * sizeof(*dp)); + /* + * Print the offset as signed, since -1 is common, + * but offsets > 2^31 aren't. + */ + printf(" %u bytes @ %d", + (u_int32_t)ntohl(dp[1]), + (u_int32_t)ntohl(dp[0])); return; } break; + case NFSPROC_STATFS: + printf(" statfs"); + if ((dp = parsereq(rp, length)) != 0 && parsefh(dp) != 0) + return; + break; + default: - printf(" proc-%lu", ntohl(rp->rm_call.cb_proc)); + printf(" proc-%u", (u_int32_t)ntohl(rp->rm_call.cb_proc)); return; } fputs(" [|nfs]", stdout); +#undef TCHECK } /* @@ -657,31 +390,32 @@ nfsreq_print(register const u_char *bp, int length, register const u_char *bp2) * additional hacking on the parser code. */ static void -nfs_printfh(register const u_int32 *dp, const int len) +nfs_printfh(register const u_int32_t *dp) { my_fsid fsid; ino_t ino; char *sfsname = NULL; - Parse_fh((caddr_t*)dp, len, &fsid, &ino, NULL, &sfsname, 0); + Parse_fh((caddr_t*)dp, &fsid, &ino, NULL, &sfsname, 0); if (sfsname) { /* file system ID is ASCII, not numeric, for this server OS */ - static char temp[NFSX_V3FHMAX+1]; + static char temp[NFS_FHSIZE+1]; /* Make sure string is null-terminated */ - strncpy(temp, sfsname, NFSX_V3FHMAX); + strncpy(temp, sfsname, NFS_FHSIZE); /* Remove trailing spaces */ sfsname = strchr(temp, ' '); if (sfsname) *sfsname = 0; - (void)printf(" fh %s/%ld", temp, ino); + (void)printf(" fh %s/%u", temp, (u_int32_t)ino); } else { - (void)printf(" fh %d,%d/%ld", - fsid.fsid_dev.Major, fsid.fsid_dev.Minor, - ino); + (void)printf(" fh %u,%u/%u", + fsid.fsid_dev.Major, + fsid.fsid_dev.Minor, + (u_int32_t)ino); } } @@ -692,11 +426,10 @@ nfs_printfh(register const u_int32 *dp, const int len) */ struct xid_map_entry { - u_int32 xid; /* transaction ID (net order) */ + u_int32_t xid; /* transaction ID (net order) */ struct in_addr client; /* client IP address (net order) */ struct in_addr server; /* server IP address (net order) */ - u_int32 proc; /* call proc number (host order) */ - u_int32 vers; /* program version (host order) */ + u_int32_t proc; /* call proc number (host order) */ }; /* @@ -726,19 +459,17 @@ xid_map_enter(const struct rpc_msg *rp, const struct ip *ip) xmep->client = ip->ip_src; xmep->server = ip->ip_dst; xmep->proc = ntohl(rp->rm_call.cb_proc); - xmep->vers = ntohl(rp->rm_call.cb_vers); } /* Returns NFSPROC_xxx or -1 on failure */ -static int -xid_map_find(const struct rpc_msg *rp, const struct ip *ip, u_int32 *proc, - u_int32 *vers) +static int32_t +xid_map_find(const struct rpc_msg *rp, const struct ip *ip) { int i; struct xid_map_entry *xmep; - u_int32 xid = rp->rm_xid; - u_int32 clip = ip->ip_dst.s_addr; - u_int32 sip = ip->ip_src.s_addr; + u_int32_t xid = rp->rm_xid; + u_int32_t clip = ip->ip_dst.s_addr; + u_int32_t sip = ip->ip_src.s_addr; /* Start searching from where we last left off */ i = xid_map_hint; @@ -748,9 +479,7 @@ xid_map_find(const struct rpc_msg *rp, const struct ip *ip, u_int32 *proc, xmep->server.s_addr == sip) { /* match */ xid_map_hint = i; - *proc = xmep->proc; - *vers = xmep->vers; - return 0; + return ((int32_t)xmep->proc); } if (++i >= XIDMAPSIZE) i = 0; @@ -768,11 +497,11 @@ xid_map_find(const struct rpc_msg *rp, const struct ip *ip, u_int32 *proc, * Return a pointer to the beginning of the actual results. * If the packet was truncated, return 0. */ -static const u_int32 * +static const u_int32_t * parserep(register const struct rpc_msg *rp, register int length) { - register const u_int32 *dp; - register const u_int32 *ep = (const u_int32 *)snapend; + register const u_int32_t *dp; + register const u_int32_t *ep = (const u_int32_t *)snapend; int len; enum accept_stat astat; @@ -780,7 +509,7 @@ parserep(register const struct rpc_msg *rp, register int length) * Portability note: * Here we find the address of the ar_verf credentials. * Originally, this calculation was - * dp = (u_int32 *)&rp->rm_reply.rp_acpt.ar_verf + * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf * On the wire, the rp_acpt field starts immediately after * the (32 bit) rp_stat field. However, rp_acpt (which is a * "struct accepted_reply") contains a "struct opaque_auth", @@ -791,7 +520,7 @@ parserep(register const struct rpc_msg *rp, register int length) * representation. Instead, we skip past the rp_stat field, * which is an "enum" and so occupies one 32-bit word. */ - dp = ((const u_int32 *)&rp->rm_reply) + 1; + dp = ((const u_int32_t *)&rp->rm_reply) + 1; if (&dp[1] >= ep) return(0); len = ntohl(dp[1]); @@ -800,7 +529,7 @@ parserep(register const struct rpc_msg *rp, register int length) /* * skip past the ar_verf credentials. */ - dp += (len + (2*sizeof(u_int32) + 3)) / sizeof(u_int32); + dp += (len + (2*sizeof(u_int32_t) + 3)) / sizeof(u_int32_t); if (dp >= ep) return(0); @@ -839,416 +568,172 @@ parserep(register const struct rpc_msg *rp, register int length) } /* successful return */ if ((sizeof(astat) + ((char *)dp)) < (char *)ep) - return((u_int32 *) (sizeof(astat) + ((char *)dp))); + return((u_int32_t *) (sizeof(astat) + ((char *)dp))); return (0); } #define T2CHECK(p, l) if ((u_char *)(p) > ((u_char *)snapend) - l) return(0) -/* - * Not all systems have strerror(). - */ -static char * -strerr(int errno) -{ - - return (strerror(errno)); -} - -static const u_int32 * -parsestatus(const u_int32 *dp, int *er) +static const u_int32_t * +parsestatus(const u_int32_t *dp) { - int errno; + int errnum; T2CHECK(dp, 4); - errno = ntohl(dp[0]); - if (er) - *er = errno; - if (errno != 0 && !qflag) { + errnum = ntohl(dp[0]); + if (errnum != 0) { char *errmsg; - errmsg = strerr(errno); - if (errmsg) - printf(" ERROR: '%s'", errmsg); - else - printf(" ERROR: %d", errno); + if (qflag) + return(0); + + errmsg = pcap_strerror(errnum); + printf(" ERROR: %s", errmsg); + return(0); } return (dp + 1); } -static const u_int32 * -parsefattr(const u_int32 *dp, int verbose, int v3) +static struct tok type2str[] = { + { NFNON, "NON" }, + { NFREG, "REG" }, + { NFDIR, "DIR" }, + { NFBLK, "BLK" }, + { NFCHR, "CHR" }, + { NFLNK, "LNK" }, + { 0, NULL } +}; + +static const u_int32_t * +parsefattr(const u_int32_t *dp, int verbose) { - const struct nfs_fattr *fap; - - T2CHECK(dp, 5 * sizeof(*dp)); - - fap = (const struct nfs_fattr *)dp; - if (verbose) { - printf(" %s %o ids %d/%d", - tok2str(type2str, "unk-ft %d ", ntohl(fap->fa_type)), - ntohl(fap->fa_mode), ntohl(fap->fa_uid), - ntohl(fap->fa_gid)); - if (v3) { - T2CHECK(dp, 7 * sizeof(*dp)); - printf(" sz "); - print_int64((u_int32 *)&fap->fa3_size, UNSIGNED); - putchar(' '); - } - else { - T2CHECK(dp, 6 * sizeof(*dp)); - printf(" sz %d ", ntohl(fap->fa2_size)); - } - } + const struct nfsv2_fattr *fap; + + T2CHECK(dp, 4); + + fap = (const struct nfsv2_fattr *)dp; + if (verbose) + printf(" %s %o ids %u/%u sz %u ", + tok2str(type2str, "unk-ft %d ", + (u_int32_t)ntohl(fap->fa_type)), + (u_int32_t)ntohl(fap->fa_mode), + (u_int32_t)ntohl(fap->fa_uid), + (u_int32_t)ntohl(fap->fa_gid), + (u_int32_t)ntohl(fap->fa_nfssize)); /* print lots more stuff */ if (verbose > 1) { - if (v3) { - T2CHECK(dp, 64); - printf("nlink %d rdev %d/%d ", - ntohl(fap->fa_nlink), - ntohl(fap->fa3_rdev.specdata1), - ntohl(fap->fa3_rdev.specdata2)); - printf("fsid "); - print_int64((u_int32 *)&fap->fa2_fsid, HEX); - printf(" nodeid "); - print_int64((u_int32 *)&fap->fa2_fileid, HEX); - printf(" a/m/ctime %u.%06u ", - ntohl(fap->fa3_atime.nfsv3_sec), - ntohl(fap->fa3_atime.nfsv3_nsec)); - printf("%u.%06u ", - ntohl(fap->fa3_mtime.nfsv3_sec), - ntohl(fap->fa3_mtime.nfsv3_nsec)); - printf("%u.%06u ", - ntohl(fap->fa3_ctime.nfsv3_sec), - ntohl(fap->fa3_ctime.nfsv3_nsec)); - } else { - T2CHECK(dp, 48); - printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ", - ntohl(fap->fa_nlink), ntohl(fap->fa2_rdev), - ntohl(fap->fa2_fsid), ntohl(fap->fa2_fileid)); - printf("%u.%06u ", - ntohl(fap->fa2_atime.nfsv2_sec), - ntohl(fap->fa2_atime.nfsv2_usec)); - printf("%u.%06u ", - ntohl(fap->fa2_mtime.nfsv2_sec), - ntohl(fap->fa2_mtime.nfsv2_usec)); - printf("%u.%06u ", - ntohl(fap->fa2_ctime.nfsv2_sec), - ntohl(fap->fa2_ctime.nfsv2_usec)); - } + printf("nlink %u rdev %x fsid %x nodeid %x a/m/ctime ", + (u_int32_t)ntohl(fap->fa_nlink), + (u_int32_t)ntohl(fap->fa_nfsrdev), + (u_int32_t)ntohl(fap->fa_nfsfsid), + (u_int32_t)ntohl(fap->fa_nfsfileid)); + printf("%u.%06u ", + (u_int32_t)ntohl(fap->fa_nfsatime.nfs_sec), + (u_int32_t)ntohl(fap->fa_nfsatime.nfs_usec)); + printf("%u.%06u ", + (u_int32_t)ntohl(fap->fa_nfsmtime.nfs_sec), + (u_int32_t)ntohl(fap->fa_nfsmtime.nfs_usec)); + printf("%u.%06u ", + (u_int32_t)ntohl(fap->fa_nfsctime.nfs_sec), + (u_int32_t)ntohl(fap->fa_nfsctime.nfs_usec)); } - return ((const u_int32 *)((unsigned char *)dp + - (v3 ? NFSX_V3FATTR : NFSX_V2FATTR))); + return ((const u_int32_t *)&fap[1]); } static int -parseattrstat(const u_int32 *dp, int verbose, int v3) +parseattrstat(const u_int32_t *dp, int verbose) { - int er; - - dp = parsestatus(dp, &er); - if (dp == NULL || er) + dp = parsestatus(dp); + if (dp == NULL) return (0); - return ((long)parsefattr(dp, verbose, v3)); + return (parsefattr(dp, verbose) != NULL); } static int -parsediropres(const u_int32 *dp) +parsediropres(const u_int32_t *dp) { - int er; - - if (!(dp = parsestatus(dp, &er)) || er) + dp = parsestatus(dp); + if (dp == NULL) return (0); - dp = parsefh(dp, 0); + dp = parsefh(dp); if (dp == NULL) return (0); - return (parsefattr(dp, vflag, 0) != NULL); + return (parsefattr(dp, vflag) != NULL); } static int -parselinkres(const u_int32 *dp, int v3) +parselinkres(const u_int32_t *dp) { - int er; - - dp = parsestatus(dp, &er); - if (dp == NULL || er) + dp = parsestatus(dp); + if (dp == NULL) return(0); - if (v3 && !(dp = parse_post_op_attr(dp, vflag))) - return (0); + putchar(' '); return (parsefn(dp) != NULL); } static int -parsestatfs(const u_int32 *dp, int v3) +parsestatfs(const u_int32_t *dp) { - const struct nfs_statfs *sfsp; - int er; + const struct nfsv2_statfs *sfsp; - dp = parsestatus(dp, &er); - if (dp == NULL || (!v3 && er)) + dp = parsestatus(dp); + if (dp == NULL) return(0); if (qflag) return(1); - if (v3) { - if (vflag) - printf(" POST:"); - if (!(dp = parse_post_op_attr(dp, vflag))) - return (0); - } + T2CHECK(dp, 20); - T2CHECK(dp, (v3 ? NFSX_V3STATFS : NFSX_V2STATFS)); - - sfsp = (const struct nfs_statfs *)dp; - - if (v3) { - printf(" tbytes "); - print_int64((u_int32 *)&sfsp->sf_tbytes, UNSIGNED); - printf(" fbytes "); - print_int64((u_int32 *)&sfsp->sf_fbytes, UNSIGNED); - printf(" abytes "); - print_int64((u_int32 *)&sfsp->sf_abytes, UNSIGNED); - if (vflag) { - printf(" tfiles "); - print_int64((u_int32 *)&sfsp->sf_tfiles, UNSIGNED); - printf(" ffiles "); - print_int64((u_int32 *)&sfsp->sf_ffiles, UNSIGNED); - printf(" afiles "); - print_int64((u_int32 *)&sfsp->sf_afiles, UNSIGNED); - printf(" invar %lu", ntohl(sfsp->sf_invarsec)); - } - } else { - printf(" tsize %d bsize %d blocks %d bfree %d bavail %d", - ntohl(sfsp->sf_tsize), ntohl(sfsp->sf_bsize), - ntohl(sfsp->sf_blocks), ntohl(sfsp->sf_bfree), - ntohl(sfsp->sf_bavail)); - } + sfsp = (const struct nfsv2_statfs *)dp; + printf(" tsize %u bsize %u blocks %u bfree %u bavail %u", + (u_int32_t)ntohl(sfsp->sf_tsize), + (u_int32_t)ntohl(sfsp->sf_bsize), + (u_int32_t)ntohl(sfsp->sf_blocks), + (u_int32_t)ntohl(sfsp->sf_bfree), + (u_int32_t)ntohl(sfsp->sf_bavail)); return (1); } static int -parserddires(const u_int32 *dp) +parserddires(const u_int32_t *dp) { - int er; - - dp = parsestatus(dp, &er); - if (dp == 0 || er) + dp = parsestatus(dp); + if (dp == 0) return (0); if (qflag) return (1); T2CHECK(dp, 12); - printf(" offset %x size %d ", ntohl(dp[0]), ntohl(dp[1])); + printf(" offset %x size %u ", + (u_int32_t)ntohl(dp[0]), + (u_int32_t)ntohl(dp[1])); if (dp[2] != 0) printf("eof"); return (1); } -static const u_int32 * -parse_wcc_attr(const u_int32 *dp) -{ - printf(" sz "); - print_int64(dp, UNSIGNED); - printf(" mtime %u.%06u ctime %u.%06u", ntohl(dp[2]), ntohl(dp[3]), - ntohl(dp[4]), ntohl(dp[5])); - return (dp + 6); -} - -/* - * Pre operation attributes. Print only if vflag > 1. - */ -static const u_int32 * -parse_pre_op_attr(const u_int32 *dp, int verbose) -{ - T2CHECK(dp, 4); - if (!ntohl(dp[0])) - return (dp + 1); - dp++; - T2CHECK(dp, 24); - if (verbose > 1) { - return parse_wcc_attr(dp); - } else { - /* If not verbose enough, just skip over wcc_attr */ - return (dp + 6); - } -} - -/* - * Post operation attributes are printed if vflag >= 1 - */ -static const u_int32 * -parse_post_op_attr(const u_int32 *dp, int verbose) -{ - T2CHECK(dp, 4); - if (!ntohl(dp[0])) - return (dp + 1); - dp++; - if (verbose) { - return parsefattr(dp, verbose, 1); - } else - return (dp + (NFSX_V3FATTR / sizeof (u_int32))); -} - -static const u_int32 * -parse_wcc_data(const u_int32 *dp, int verbose) -{ - if (verbose > 1) - printf(" PRE:"); - if (!(dp = parse_pre_op_attr(dp, verbose))) - return (0); - - if (verbose) - printf(" POST:"); - return parse_post_op_attr(dp, verbose); -} - -static const u_int32 * -parsecreateopres(const u_int32 *dp, int verbose) -{ - int er; - - if (!(dp = parsestatus(dp, &er))) - return (0); - if (er) - dp = parse_wcc_data(dp, verbose); - else { - T2CHECK(dp, 4); - if (!ntohl(dp[0])) - return (dp + 1); - dp++; - if (!(dp = parsefh(dp, 1))) - return (0); - if (verbose) { - if (!(dp = parse_post_op_attr(dp, verbose))) - return (0); - if (vflag > 1) { - printf("dir attr:"); - dp = parse_wcc_data(dp, verbose); - } - } - } - return (dp); -} - -static int -parsewccres(const u_int32 *dp, int verbose) -{ - int er; - - if (!(dp = parsestatus(dp, &er))) - return (0); - return parse_wcc_data(dp, verbose) != 0; -} - -static const u_int32 * -parsev3rddirres(const u_int32 *dp, int verbose) -{ - int er; - - if (!(dp = parsestatus(dp, &er))) - return (0); - if (vflag) - printf(" POST:"); - if (!(dp = parse_post_op_attr(dp, verbose))) - return (0); - if (er) - return dp; - if (vflag) { - T2CHECK(dp, 8); - printf(" verf %08lx%08lx", dp[0], dp[1]); - dp += 2; - } - return dp; -} - -static int -parsefsinfo(const u_int32 *dp) -{ - struct nfsv3_fsinfo *sfp; - int er; - - if (!(dp = parsestatus(dp, &er))) - return (0); - if (vflag) - printf(" POST:"); - if (!(dp = parse_post_op_attr(dp, vflag))) - return (0); - if (er) - return (1); - - T2CHECK(dp, sizeof (struct nfsv3_fsinfo)); - - sfp = (struct nfsv3_fsinfo *)dp; - printf(" rtmax %lu rtpref %lu wtmax %lu wtpref %lu dtpref %lu", - ntohl(sfp->fs_rtmax), ntohl(sfp->fs_rtpref), - ntohl(sfp->fs_wtmax), ntohl(sfp->fs_wtpref), - ntohl(sfp->fs_dtpref)); - if (vflag) { - printf(" rtmult %lu wtmult %lu maxfsz ", - ntohl(sfp->fs_rtmult), ntohl(sfp->fs_wtmult)); - print_int64((u_int32 *)&sfp->fs_maxfilesize, UNSIGNED); - printf(" delta %u.%06u ", ntohl(sfp->fs_timedelta.nfsv3_sec), - ntohl(sfp->fs_timedelta.nfsv3_nsec)); - } - return (1); -} - -static int -parsepathconf(const u_int32 *dp) -{ - int er; - struct nfsv3_pathconf *spp; - - if (!(dp = parsestatus(dp, &er))) - return (0); - if (vflag) - printf(" POST:"); - if (!(dp = parse_post_op_attr(dp, vflag))) - return (0); - if (er) - return (1); - - T2CHECK(dp, sizeof (struct nfsv3_pathconf)); - - spp = (struct nfsv3_pathconf *)dp; - - printf(" linkmax %lu namemax %lu %s %s %s %s", - ntohl(spp->pc_linkmax), - ntohl(spp->pc_namemax), - ntohl(spp->pc_notrunc) ? "notrunc" : "", - ntohl(spp->pc_chownrestricted) ? "chownres" : "", - ntohl(spp->pc_caseinsensitive) ? "igncase" : "", - ntohl(spp->pc_casepreserving) ? "keepcase" : ""); - return (0); -} - static void -interp_reply(const struct rpc_msg *rp, u_int32 proc, u_int32 vers, int length) +interp_reply(const struct rpc_msg *rp, u_int32_t proc, int length) { - register const u_int32 *dp; - register int v3; - register const u_char *ep = snapend; - int er; - - v3 = (vers == NFS_VER3); - - if (!v3 && proc < NFS_NPROCS) - proc = nfsv3_procid[proc]; + register const u_int32_t *dp; switch (proc) { +#ifdef NFSPROC_NOOP case NFSPROC_NOOP: printf(" nop"); return; - +#else +#define NFSPROC_NOOP -1 +#endif case NFSPROC_NULL: printf(" null"); return; @@ -1256,291 +741,120 @@ interp_reply(const struct rpc_msg *rp, u_int32 proc, u_int32 vers, int length) case NFSPROC_GETATTR: printf(" getattr"); dp = parserep(rp, length); - if (dp != 0 && parseattrstat(dp, !qflag, v3) != 0) + if (dp != 0 && parseattrstat(dp, !qflag) != 0) return; break; case NFSPROC_SETATTR: printf(" setattr"); - if (!(dp = parserep(rp, length))) + dp = parserep(rp, length); + if (dp != 0 && parseattrstat(dp, !qflag) != 0) return; - if (v3) { - if (parsewccres(dp, vflag)) - return; - } else { - if (parseattrstat(dp, !qflag, 0) != 0) - return; - } break; +#if NFSPROC_ROOT != NFSPROC_NOOP + case NFSPROC_ROOT: + printf(" root"); + break; +#endif case NFSPROC_LOOKUP: printf(" lookup"); - if (!(dp = parserep(rp, length))) - break; - if (v3) { - if (!(dp = parsestatus(dp, &er))) - break; - if (er) { - if (vflag > 1) { - printf(" post dattr:"); - dp = parse_post_op_attr(dp, vflag); - } - } else { - if (!(dp = parsefh(dp, v3))) - break; - if ((dp = parse_post_op_attr(dp, vflag)) && - vflag > 1) { - printf(" post dattr:"); - dp = parse_post_op_attr(dp, vflag); - } - } - if (dp) - return; - } else { - if (parsediropres(dp) != 0) - return; - } - break; - - case NFSPROC_ACCESS: - printf(" access"); dp = parserep(rp, length); - if (!(dp = parsestatus(dp, &er))) - break; - if (vflag) - printf(" attr:"); - if (!(dp = parse_post_op_attr(dp, vflag))) - break; - if (!er) - printf(" c %04x", ntohl(dp[0])); - return; + if (dp != 0 && parsediropres(dp) != 0) + return; + break; case NFSPROC_READLINK: printf(" readlink"); dp = parserep(rp, length); - if (dp != 0 && parselinkres(dp, v3) != 0) + if (dp != 0 && parselinkres(dp) != 0) return; break; case NFSPROC_READ: printf(" read"); - if (!(dp = parserep(rp, length))) - break; - if (v3) { - if (!(dp = parsestatus(dp, &er))) - break; - if (!(dp = parse_post_op_attr(dp, vflag))) - break; - if (er) - return; - if (vflag) { - TCHECK(dp, 8); - printf("%lu bytes", ntohl(dp[0])); - if (ntohl(dp[1])) - printf(" EOF"); - } + dp = parserep(rp, length); + if (dp != 0 && parseattrstat(dp, vflag) != 0) return; - } else { - if (parseattrstat(dp, vflag, 0) != 0) - return; - } break; +#if NFSPROC_WRITECACHE != NFSPROC_NOOP + case NFSPROC_WRITECACHE: + printf(" writecache"); + break; +#endif case NFSPROC_WRITE: printf(" write"); - if (!(dp = parserep(rp, length))) - break; - if (v3) { - if (!(dp = parsestatus(dp, &er))) - break; - if (!(dp = parse_wcc_data(dp, vflag))) - break; - if (er) - return; - if (vflag) { - TCHECK(dp, 4); - printf("%lu bytes", ntohl(dp[0])); - if (vflag > 1) { - TCHECK(dp, 4); - printf(" <%s>", - nfsv3_writemodes[ntohl(dp[1])]); - } - return; - } - } else { - if (parseattrstat(dp, vflag, v3) != 0) - return; - } + dp = parserep(rp, length); + if (dp != 0 && parseattrstat(dp, vflag) != 0) + return; break; case NFSPROC_CREATE: printf(" create"); - if (!(dp = parserep(rp, length))) - break; - if (v3) { - if (parsecreateopres(dp, vflag) != 0) - return; - } else { - if (parsediropres(dp) != 0) - return; - } - break; - - case NFSPROC_MKDIR: - printf(" mkdir"); - if (!(dp = parserep(rp, length))) - break; - if (v3) { - if (parsecreateopres(dp, vflag) != 0) - return; - } else { - if (parsediropres(dp) != 0) - return; - } - break; - - case NFSPROC_SYMLINK: - printf(" symlink"); - if (!(dp = parserep(rp, length))) - break; - if (v3) { - if (parsecreateopres(dp, vflag) != 0) - return; - } else { - if (parsestatus(dp, &er) != 0) - return; - } - break; - - case NFSPROC_MKNOD: - printf(" mknod"); - if (!(dp = parserep(rp, length))) - break; - if (parsecreateopres(dp, vflag) != 0) + dp = parserep(rp, length); + if (dp != 0 && parsediropres(dp) != 0) return; break; case NFSPROC_REMOVE: printf(" remove"); - if (!(dp = parserep(rp, length))) - break; - if (v3) { - if (parsewccres(dp, vflag)) - return; - } else { - if (parsestatus(dp, &er) != 0) - return; - } - break; - - case NFSPROC_RMDIR: - printf(" rmdir"); - if (!(dp = parserep(rp, length))) - break; - if (v3) { - if (parsewccres(dp, vflag)) - return; - } else { - if (parsestatus(dp, &er) != 0) - return; - } + dp = parserep(rp, length); + if (dp != 0 && parsestatus(dp) != 0) + return; break; case NFSPROC_RENAME: printf(" rename"); - if (!(dp = parserep(rp, length))) - break; - if (v3) { - if (!(dp = parsestatus(dp, &er))) - break; - if (vflag) { - printf(" from:"); - if (!(dp = parse_wcc_data(dp, vflag))) - break; - printf(" to:"); - if (!(dp = parse_wcc_data(dp, vflag))) - break; - } + dp = parserep(rp, length); + if (dp != 0 && parsestatus(dp) != 0) return; - } else { - if (parsestatus(dp, &er) != 0) - return; - } break; case NFSPROC_LINK: printf(" link"); - if (!(dp = parserep(rp, length))) - break; - if (v3) { - if (!(dp = parsestatus(dp, &er))) - break; - if (vflag) { - printf(" file POST:"); - if (!(dp = parse_post_op_attr(dp, vflag))) - break; - printf(" dir:"); - if (!(dp = parse_wcc_data(dp, vflag))) - break; - return; - } - } else { - if (parsestatus(dp, &er) != 0) - return; - } - break; - - case NFSPROC_READDIR: - printf(" readdir"); - if (!(dp = parserep(rp, length))) - break; - if (v3) { - if (parsev3rddirres(dp, vflag)) - return; - } else { - if (parserddires(dp) != 0) - return; - } + dp = parserep(rp, length); + if (dp != 0 && parsestatus(dp) != 0) + return; break; - case NFSPROC_READDIRPLUS: - printf(" readdirplus"); - if (!(dp = parserep(rp, length))) - break; - if (parsev3rddirres(dp, vflag)) + case NFSPROC_SYMLINK: + printf(" symlink"); + dp = parserep(rp, length); + if (dp != 0 && parsestatus(dp) != 0) return; break; - case NFSPROC_FSSTAT: - printf(" fsstat"); + case NFSPROC_MKDIR: + printf(" mkdir"); dp = parserep(rp, length); - if (dp != 0 && parsestatfs(dp, v3) != 0) + if (dp != 0 && parsediropres(dp) != 0) return; break; - case NFSPROC_FSINFO: - printf(" fsinfo"); + case NFSPROC_RMDIR: + printf(" rmdir"); dp = parserep(rp, length); - if (dp != 0 && parsefsinfo(dp) != 0) + if (dp != 0 && parsestatus(dp) != 0) return; break; - case NFSPROC_PATHCONF: - printf(" pathconf"); + case NFSPROC_READDIR: + printf(" readdir"); dp = parserep(rp, length); - if (dp != 0 && parsepathconf(dp) != 0) + if (dp != 0 && parserddires(dp) != 0) return; break; - case NFSPROC_COMMIT: - printf(" commit"); + case NFSPROC_STATFS: + printf(" statfs"); dp = parserep(rp, length); - if (dp != 0 && parsewccres(dp, vflag) != 0) + if (dp != 0 && parsestatfs(dp) != 0) return; break; default: - printf(" proc-%lu", proc); + printf(" proc-%u", proc); return; } fputs(" [|nfs]", stdout); diff --git a/usr.sbin/tcpdump/print-ntp.c b/usr.sbin/tcpdump/print-ntp.c index 047d7b4b651..87e74ba1791 100644 --- a/usr.sbin/tcpdump/print-ntp.c +++ b/usr.sbin/tcpdump/print-ntp.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-ntp.c,v 1.3 1996/06/10 07:47:43 deraadt Exp $ */ -/* $NetBSD: print-ntp.c,v 1.2 1995/03/06 19:11:22 mycroft Exp $ */ +/* $OpenBSD: print-ntp.c,v 1.4 1996/07/13 11:01:26 mickey Exp $ */ /* - * Copyright (c) 1990, 1991, 1992, 1993, 1994 + * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,7 +27,7 @@ #ifndef lint static char rcsid[] = - "@(#) Header: print-ntp.c,v 1.14 94/06/14 20:18:46 leres Exp (LBL)"; + "@(#) Header: print-ntp.c,v 1.20 96/06/23 02:11:46 leres Exp (LBL)"; #endif #include <sys/param.h> @@ -36,6 +35,10 @@ static char rcsid[] = #include <sys/types.h> #include <sys/socket.h> +#if __STDC__ +struct mbuf; +struct rtentry; +#endif #include <net/if.h> #include <netinet/in.h> @@ -72,7 +75,7 @@ ntp_print(register const u_char *cp, int length) if (length != sizeof(struct ntpdata)) (void)printf(" [len=%d]", length); - /* 'ep' points to the end of avaible data. */ + /* 'ep' points to the end of available data. */ ep = snapend; TCHECK(bp->status, sizeof(bp->status)); @@ -159,6 +162,9 @@ ntp_print(register const u_char *cp, int length) switch (bp->stratum) { case UNSPECIFIED: + printf("(unspec)"); + break; + case PRIM_REF: strncpy(rclock, (char *)&(bp->refid), 4); rclock[4] = '\0'; @@ -222,9 +228,9 @@ p_sfix(register const struct s_fixedpt *sfp) static void p_ntp_time(register const struct l_fixedpt *lfp) { - register int32 i; - register u_int32 uf; - register u_int32 f; + register int32_t i; + register u_int32_t uf; + register u_int32_t f; register float ff; i = ntohl(lfp->int_part); @@ -234,7 +240,7 @@ p_ntp_time(register const struct l_fixedpt *lfp) ff += FMAXINT; ff = ff / FMAXINT; /* shift radix point by 32 bits */ f = ff * 1000000000.0; /* treat fraction as parts per billion */ - printf("%lu.%09d", i, f); + printf("%u.%09d", i, f); } /* Prints time difference between *lfp and *olfp */ @@ -242,10 +248,10 @@ static void p_ntp_delta(register const struct l_fixedpt *olfp, register const struct l_fixedpt *lfp) { - register int32 i; - register u_int32 uf; - register u_int32 ouf; - register u_int32 f; + register int32_t i; + register u_int32_t uf; + register u_int32_t ouf; + register u_int32_t f; register float ff; int signbit; diff --git a/usr.sbin/tcpdump/print-null.c b/usr.sbin/tcpdump/print-null.c index 6953c156577..8adfc6bfcfd 100644 --- a/usr.sbin/tcpdump/print-null.c +++ b/usr.sbin/tcpdump/print-null.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-null.c,v 1.3 1996/06/10 07:47:44 deraadt Exp $ */ -/* $NetBSD: print-null.c,v 1.3 1995/03/06 19:11:24 mycroft Exp $ */ +/* $OpenBSD: print-null.c,v 1.4 1996/07/13 11:01:27 mickey Exp $ */ /* - * Copyright (c) 1991, 1993, 1994 + * Copyright (c) 1991, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,7 +23,7 @@ #ifndef lint static char rcsid[] = - "@(#)Header: print-null.c,v 1.14 94/06/10 17:01:35 mccanne Exp (LBL)"; + "@(#)Header: print-null.c,v 1.18 96/06/03 02:53:51 leres Exp (LBL)"; #endif #include <sys/param.h> @@ -33,6 +32,10 @@ static char rcsid[] = #include <sys/file.h> #include <sys/ioctl.h> +#if __STDC__ +struct mbuf; +struct rtentry; +#endif #include <net/if.h> #include <netinet/in.h> @@ -45,8 +48,8 @@ static char rcsid[] = #include <netinet/tcp.h> #include <netinet/tcpip.h> - #include <stdio.h> +#include <string.h> #include "interface.h" #include "addrtoname.h" @@ -59,7 +62,7 @@ null_print(const u_char *p, const struct ip *ip, int length) { u_int family; - bcopy(p, &family, sizeof(family)); + memcpy((char *)&family, (char *)p, sizeof(family)); if (nflag) { /* XXX just dump the header */ diff --git a/usr.sbin/tcpdump/print-ospf.c b/usr.sbin/tcpdump/print-ospf.c index 1acbf091817..259a801a72a 100644 --- a/usr.sbin/tcpdump/print-ospf.c +++ b/usr.sbin/tcpdump/print-ospf.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-ospf.c,v 1.3 1996/06/10 07:47:44 deraadt Exp $ */ -/* $NetBSD: print-ospf.c,v 1.3 1995/03/06 19:11:25 mycroft Exp $ */ +/* $OpenBSD: print-ospf.c,v 1.4 1996/07/13 11:01:27 mickey Exp $ */ /* - * Copyright (c) 1992, 1993, 1994 + * Copyright (c) 1992, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,7 +25,7 @@ #ifndef lint static char rcsid[] = - "@(#) Header: print-ospf.c,v 1.12 94/06/14 20:18:46 leres Exp (LBL)"; + "@(#) Header: print-ospf.c,v 1.18 96/06/15 13:19:49 leres Exp (LBL)"; #endif #include <sys/param.h> @@ -38,7 +37,6 @@ static char rcsid[] = #include <netinet/ip.h> #include <netinet/ip_var.h> -#include <errno.h> #include <ctype.h> #include <stdio.h> @@ -47,12 +45,8 @@ static char rcsid[] = #include "ospf.h" -#ifndef __GNUC__ -#define inline -#endif - struct bits { - u_int32 bit; + u_int32_t bit; const char *str; }; @@ -81,26 +75,25 @@ static const char *ospf_types[OSPF_TYPE_MAX] = { }; static inline void -ospf_print_seqage(register u_int32 seq, register time_t us) +ospf_print_seqage(register u_int32_t seq, register time_t us) { register time_t sec = us % 60; register time_t mins = (us / 60) % 60; register time_t hour = us/3600; - printf(" S %X age ", - seq); + printf(" S %X age ", seq); if (hour) { - printf("%d:%02d:%02d", - hour, - mins, - sec); + printf("%u:%02u:%02u", + (u_int32_t)hour, + (u_int32_t)mins, + (u_int32_t)sec); } else if (mins) { - printf("%d:%02d", - mins, - sec); + printf("%u:%02u", + (u_int32_t)mins, + (u_int32_t)sec); } else { - printf("%d", - sec); + printf("%u", + (u_int32_t)sec); } } @@ -146,14 +139,12 @@ ospf_print_lshdr(register const struct lsa_hdr *lshp, const caddr_t end) printf(" {"); /* } (ctags) */ if (!lshp->ls_type || lshp->ls_type >= LS_TYPE_MAX) { - printf(" ??LS type %d?? }", /* { (ctags) */ - lshp->ls_type); + printf(" ??LS type %d?? }", lshp->ls_type); /* { (ctags) */ return 1; } ospf_print_bits(ospf_option_bits, lshp->ls_options); - ospf_print_seqage(ntohl(lshp->ls_seq), - ntohs(lshp->ls_age)); + ospf_print_seqage(ntohl(lshp->ls_seq), ntohs(lshp->ls_age)); LS_PRINT(lshp, lshp->ls_type); @@ -174,7 +165,7 @@ ospf_print_lsa(register const struct lsa *lsap, const caddr_t end) const struct in_addr *ap; const struct aslametric *almp; const struct mcla *mcp; - const u_int32 *lp; + const u_int32_t *lp; int j, k; if (ospf_print_lshdr(&lsap->ls_hdr, end)) { @@ -235,7 +226,7 @@ ospf_print_lsa(register const struct lsa *lsap, const caddr_t end) tosp = (struct tos_metric *) ((sizeof rlp->link_tos0metric) + (caddr_t) rlp); for (k = 0; k < rlp->link_toscount; k++, tosp++) { printf(" tos %d metric %d", - ntohs(tosp->tos_type), + tosp->tos_type, ntohs(tosp->tos_metric)); } printf(" }"); /* { (ctags) */ @@ -264,7 +255,7 @@ ospf_print_lsa(register const struct lsa *lsap, const caddr_t end) for (lp = lsap->lsa_un.un_sla.sla_tosmetric; (caddr_t) (lp + 1) <= ls_end; lp++) { - u_int32 ul = ntohl(*lp); + u_int32_t ul = ntohl(*lp); printf(" tos %d metric %d", (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS, @@ -279,7 +270,7 @@ ospf_print_lsa(register const struct lsa *lsap, const caddr_t end) for (almp = lsap->lsa_un.un_asla.asla_metric; (caddr_t) (almp + 1) <= ls_end; almp++) { - u_int32 ul = ntohl(almp->asla_tosmetric); + u_int32_t ul = ntohl(almp->asla_tosmetric); printf(" type %d tos %d metric %d", (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1, @@ -313,8 +304,8 @@ ospf_print_lsa(register const struct lsa *lsap, const caddr_t end) break; default: - printf(" ??VertexType %d??", - ntohl(mcp->mcla_vtype)); + printf(" ??VertexType %u??", + (u_int32_t)ntohl(mcp->mcla_vtype)); break; } } @@ -445,11 +436,11 @@ ospf_print(register const u_char *bp, register int length, } if (vflag) { ospf_print_bits(ospf_option_bits, op->ospf_hello.hello_options); - printf(" mask %s int %d pri %d dead %d", + printf(" mask %s int %d pri %d dead %u", ipaddr_string(&op->ospf_hello.hello_mask), ntohs(op->ospf_hello.hello_helloint), op->ospf_hello.hello_priority, - ntohl(op->ospf_hello.hello_deadint)); + (u_int32_t)ntohl(op->ospf_hello.hello_deadint)); } if ((caddr_t) (&op->ospf_hello.hello_dr + 1) > end) { @@ -503,8 +494,7 @@ ospf_print(register const u_char *bp, register int length, sep); sep = '/'; } - printf(" S %X", - ntohl(op->ospf_db.db_seq)); + printf(" S %X", (u_int32_t)ntohl(op->ospf_db.db_seq)); if (vflag) { /* Print all the LS adv's */ @@ -520,16 +510,15 @@ ospf_print(register const u_char *bp, register int length, case OSPF_TYPE_LSR: if (vflag) { for (lsrp = op->ospf_lsr; (caddr_t) (lsrp+1) <= end; lsrp++) { - int32 type; + int32_t type; if ((caddr_t) (lsrp + 1) > end) { break; } printf(" {"); /* } (ctags) */ - if (!(type = lsrp->ls_type) || type >= LS_TYPE_MAX) { - printf(" ??LinkStateType %d }", /* { (ctags) */ - type); + if (!(type = ntohl(lsrp->ls_type)) || type >= LS_TYPE_MAX) { + printf(" ??LinkStateType %d }", type); /* { (ctags) */ printf(" }"); /* { (ctags) */ break; } diff --git a/usr.sbin/tcpdump/print-pim.c b/usr.sbin/tcpdump/print-pim.c new file mode 100644 index 00000000000..675a2c41eee --- /dev/null +++ b/usr.sbin/tcpdump/print-pim.c @@ -0,0 +1,104 @@ +/* $OpenBSD: print-pim.c,v 1.1 1996/07/13 11:01:28 mickey Exp $ */ + +/* + * Copyright (c) 1995 + * 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 char rcsid[] = + "@(#) Header: print-pim.c,v 1.4 95/10/07 22:13:12 leres Exp (LBL)"; +#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 <netinet/tcp.h> +#include <netinet/tcpip.h> + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include "interface.h" +#include "addrtoname.h" + + +void +pim_print(register const u_char *bp, register int len) +{ + register const u_char *ep; + register u_char type; + + ep = (const u_char *)snapend; + if (bp >= ep) + return; + + type = bp[1]; + + switch (type) { + case 0: + (void)printf(" Query"); + break; + + case 1: + (void)printf(" Register"); + break; + + case 2: + (void)printf(" Register-Stop"); + break; + + case 3: + (void)printf(" Join/Prune"); + break; + + case 4: + (void)printf(" RP-reachable"); + break; + + case 5: + (void)printf(" Assert"); + break; + + case 6: + (void)printf(" Graft"); + break; + + case 7: + (void)printf(" Graft-ACK"); + break; + + case 8: + (void)printf(" Mode"); + break; + + default: + (void)printf(" [type %d]", type); + break; + } +} diff --git a/usr.sbin/tcpdump/print-ppp.c b/usr.sbin/tcpdump/print-ppp.c index c33b8eaac44..7c4f369cda5 100644 --- a/usr.sbin/tcpdump/print-ppp.c +++ b/usr.sbin/tcpdump/print-ppp.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-ppp.c,v 1.3 1996/06/10 07:47:45 deraadt Exp $ */ -/* $NetBSD: print-ppp.c,v 1.3 1995/03/06 19:11:27 mycroft Exp $ */ +/* $OpenBSD: print-ppp.c,v 1.4 1996/07/13 11:01:28 mickey Exp $ */ /* - * Copyright (c) 1990, 1991, 1993, 1994 + * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,7 +23,7 @@ #ifndef lint static char rcsid[] = - "@(#)Header: print-ppp.c,v 1.18 94/06/10 17:01:37 mccanne Exp (LBL)"; + "@(#)Header: print-ppp.c,v 1.21 96/06/03 02:54:07 leres Exp (LBL)"; #endif #ifdef PPP @@ -34,6 +33,10 @@ static char rcsid[] = #include <sys/file.h> #include <sys/ioctl.h> +#if __STDC__ +struct mbuf; +struct rtentry; +#endif #include <net/if.h> #include <netinet/in.h> @@ -41,7 +44,6 @@ static char rcsid[] = #include <netinet/ip.h> #include <ctype.h> -#include <errno.h> #include <netdb.h> #include <pcap.h> #include <signal.h> diff --git a/usr.sbin/tcpdump/print-rip.c b/usr.sbin/tcpdump/print-rip.c index 121d946e8f0..6f2c15c461e 100644 --- a/usr.sbin/tcpdump/print-rip.c +++ b/usr.sbin/tcpdump/print-rip.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-rip.c,v 1.3 1996/06/10 07:47:46 deraadt Exp $ */ -/* $NetBSD: print-rip.c,v 1.4 1995/06/20 23:38:49 christos Exp $ */ +/* $OpenBSD: print-rip.c,v 1.4 1996/07/13 11:01:29 mickey Exp $ */ /* - * Copyright (c) 1989, 1990, 1991, 1993, 1994 + * Copyright (c) 1989, 1990, 1991, 1993, 1994, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,7 +23,7 @@ #ifndef lint static char rcsid[] = - "@(#) Header: print-rip.c,v 1.20 94/06/14 20:18:47 leres Exp (LBL)"; + "@(#) Header: print-rip.c,v 1.30 96/06/24 22:12:54 leres Exp (LBL)"; #endif #include <sys/param.h> @@ -39,52 +38,81 @@ static char rcsid[] = #include <netinet/udp.h> #include <netinet/udp_var.h> -#include <protocols/routed.h> - -#include <errno.h> #include <stdio.h> #include "interface.h" #include "addrtoname.h" +#include "extract.h" /* must come after interface.h */ + +struct rip { + u_char rip_cmd; /* request/response */ + u_char rip_vers; /* protocol version # */ + u_short rip_zero2; /* unused */ +}; +#define RIPCMD_REQUEST 1 /* want info */ +#define RIPCMD_RESPONSE 2 /* responding to request */ +#define RIPCMD_TRACEON 3 /* turn tracing on */ +#define RIPCMD_TRACEOFF 4 /* turn it off */ +#define RIPCMD_POLL 5 /* want info from everybody */ +#define RIPCMD_POLLENTRY 6 /* poll for entry */ + +struct rip_netinfo { + u_short rip_family; + u_short rip_tag; + u_int32_t rip_dest; + u_int32_t rip_dest_mask; + u_int32_t rip_router; + u_int32_t rip_metric; /* cost of route */ +}; static void -rip_entry_print(register const struct netinfo *ni) +rip_entry_print(register int vers, register const struct rip_netinfo *ni) { - if (ntohs(ni->rip_family) != AF_INET) { - register int i; + register u_char *cp, *ep; + + if (EXTRACT_SHORT(&ni->rip_family) != AF_INET) { - printf(" [family %d:", ntohs(ni->rip_family)); - printf(" %04x", ni->rip_dst); + printf(" [family %d:", EXTRACT_SHORT(&ni->rip_family)); + cp = (u_char *)&ni->rip_tag; + ep = (u_char *)&ni->rip_metric + sizeof(ni->rip_metric); + for (; cp < ep; cp += 2) + printf(" %04x", EXTRACT_SHORT(cp)); printf("]"); + } else if (vers < 2) { + /* RFC 1058 */ + printf(" %s", ipaddr_string(&ni->rip_dest)); } else { - struct sockaddr_in sin; - sin.sin_addr.s_addr = ni->rip_dst; - printf(" %s", ipaddr_string(&sin.sin_addr)); + /* RFC 1723 */ + printf(" {%s", ipaddr_string(&ni->rip_dest)); + if (ni->rip_dest_mask) + printf("/%s", ipaddr_string(&ni->rip_dest_mask)); + if (ni->rip_router) + printf("->%s", ipaddr_string(&ni->rip_router)); if (ni->rip_tag) - printf(" [port %d]", ni->rip_tag); + printf(" tag %04x", EXTRACT_SHORT(&ni->rip_tag)); + printf("}"); } - printf("(%d)", ntohl(ni->rip_metric)); + printf("(%d)", EXTRACT_LONG(&ni->rip_metric)); } void rip_print(const u_char *dat, int length) { - register const struct rip *rp = (struct rip *)dat; - register const struct netinfo *ni; - register int amt = snapend - dat; - register int i = min(length, amt) - - (sizeof(struct rip) - sizeof(struct netinfo)); - int j; - int trunc; + register const struct rip *rp; + register const struct rip_netinfo *ni; + register int i, j, trunc; + i = min(length, snapend - dat) - (sizeof(*rp) - sizeof(*ni)); if (i < 0) return; + rp = (struct rip *)dat; switch (rp->rip_cmd) { case RIPCMD_REQUEST: printf(" rip-req %d", length); break; + case RIPCMD_RESPONSE: j = length / sizeof(*ni); if (j * sizeof(*ni) != length - 4) @@ -92,27 +120,43 @@ rip_print(const u_char *dat, int length) else printf(" rip-resp %d:", j); trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); - for (ni = rp->rip_nets; (i -= sizeof(*ni)) >= 0; ++ni) - rip_entry_print(ni); + ni = (struct rip_netinfo *)(rp + 1); + for (; (i -= sizeof(*ni)) >= 0; ++ni) + rip_entry_print(rp->rip_vers, ni); if (trunc) printf("[|rip]"); break; + case RIPCMD_TRACEON: - printf(" rip-traceon %d: \"%s\"", length, rp->rip_tracefile); + printf(" rip-traceon %d: ", length); + (void)fn_print((const u_char *)(rp + 1), snapend); + putchar('\n'); break; + case RIPCMD_TRACEOFF: printf(" rip-traceoff %d", length); break; + case RIPCMD_POLL: printf(" rip-poll %d", length); break; + case RIPCMD_POLLENTRY: printf(" rip-pollentry %d", length); break; + default: - printf(" rip-%d ?? %d", rp->rip_cmd, length); + printf(" rip-#%d %d", rp->rip_cmd, length); break; } - if (rp->rip_vers != RIP_VERSION_1) + switch (rp->rip_vers) { + + case 1: + case 2: + break; + + default: printf(" [vers %d]", rp->rip_vers); + break; + } } diff --git a/usr.sbin/tcpdump/print-skip.c b/usr.sbin/tcpdump/print-skip.c index 74db84676bc..563fee454c9 100644 --- a/usr.sbin/tcpdump/print-skip.c +++ b/usr.sbin/tcpdump/print-skip.c @@ -1,4 +1,5 @@ -/* $OpenBSD: print-skip.c,v 1.1 1996/03/04 15:59:35 mickey Exp $ */ +/* $OpenBSD: print-skip.c,v 1.2 1996/07/13 11:01:29 mickey Exp $ */ + /* * Copyright (c) 1995 Sun Microsystems, Inc. * All rights reserved. diff --git a/usr.sbin/tcpdump/print-sl.c b/usr.sbin/tcpdump/print-sl.c index bdc746a9c5f..297c4eae87f 100644 --- a/usr.sbin/tcpdump/print-sl.c +++ b/usr.sbin/tcpdump/print-sl.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-sl.c,v 1.3 1996/06/10 07:47:47 deraadt Exp $ */ -/* $NetBSD: print-sl.c,v 1.6 1996/05/20 00:41:11 fvdl Exp $ */ +/* $OpenBSD: print-sl.c,v 1.4 1996/07/13 11:01:30 mickey Exp $ */ /* - * Copyright (c) 1989, 1990, 1991, 1993, 1994 + * Copyright (c) 1989, 1990, 1991, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,10 +23,10 @@ #ifndef lint static char rcsid[] = - "@(#)Header: print-sl.c,v 1.28+ 94/06/10 17:01:38 mccanne Exp (LBL)"; + "@(#)Header: print-sl.c,v 1.36 96/06/23 02:11:46 leres Exp (LBL)"; #endif -#ifdef CSLIP +#ifdef HAVE_NET_SLIP_H #include <sys/param.h> #include <sys/time.h> #include <sys/timeb.h> @@ -36,7 +35,11 @@ static char rcsid[] = #include <sys/mbuf.h> #include <sys/socket.h> +#if __STDC__ +struct rtentry; +#endif #include <net/if.h> + #include <netinet/in.h> #include <netinet/in_systm.h> #include <netinet/ip.h> @@ -51,7 +54,6 @@ static char rcsid[] = #include <net/slip.h> #include <ctype.h> -#include <errno.h> #include <netdb.h> #include <pcap.h> #include <signal.h> @@ -59,6 +61,7 @@ static char rcsid[] = #include "interface.h" #include "addrtoname.h" +#include "extract.h" /* must come after interface.h */ static int lastlen[2][256]; static int lastconn = 255; @@ -66,6 +69,14 @@ static int lastconn = 255; static void sliplink_print(const u_char *, const struct ip *, int); static void compressed_sl_print(const u_char *, const struct ip *, int, int); +/* XXX BSD/OS 2.1 compatibility */ +#if !defined(SLIP_HDRLEN) && defined(SLC_BPFHDR) +#define SLIP_HDRLEN SLC_BPFHDR +#define SLX_DIR 0 +#define SLX_CHDR (SLC_BPFHDRLEN - 1) +#define CHDR_LEN (SLC_BPFHDR - SLC_BPFHDRLEN) +#endif + void sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) { @@ -115,11 +126,11 @@ sliplink_print(register const u_char *p, register const struct ip *ip, if (nflag) { /* XXX just dump the header */ - int i; + register int i; - for (i = 0; i < 15; ++i) - printf("%02x.", p[SLX_CHDR + i]); - printf("%02x: ", p[SLX_CHDR + 15]); + for (i = SLX_CHDR; i < SLX_CHDR + CHDR_LEN - 1; ++i) + printf("%02x.", p[i]); + printf("%02x: ", p[SLX_CHDR + CHDR_LEN - 1]); return; } switch (p[SLX_CHDR] & 0xf0) { @@ -130,11 +141,11 @@ sliplink_print(register const u_char *p, register const struct ip *ip, case TYPE_UNCOMPRESSED_TCP: /* - * The connection id is stode in the IP protcol field. + * The connection id is stored in the IP protcol field. * Get it from the link layer since sl_uncompress_tcp() * has restored the IP header copy to IPPROTO_TCP. */ - lastconn = ip->ip_p; + lastconn = ((struct ip *)&p[SLX_CHDR])->ip_p; hlen = ip->ip_hl; hlen += ((struct tcphdr *)&((int *)ip)[hlen])->th_off; lastlen[dir][lastconn] = length - (hlen << 2); @@ -157,7 +168,7 @@ print_sl_change(const char *str, register const u_char *cp) register u_int i; if ((i = *cp++) == 0) { - i = (cp[0] << 8) | cp[1]; + i = EXTRACT_SHORT(cp); cp += 2; } printf(" %s%d", str, i); @@ -170,7 +181,7 @@ print_sl_winchange(register const u_char *cp) register short i; if ((i = *cp++) == 0) { - i = (cp[0] << 8) | cp[1]; + i = EXTRACT_SHORT(cp); cp += 2; } if (i >= 0) @@ -227,7 +238,7 @@ compressed_sl_print(const u_char *chdr, const struct ip *ip, * 'length - hlen' is the amount of data in the packet. */ hlen = ip->ip_hl; - hlen += ((struct tcphdr *)&((int32 *)ip)[hlen])->th_off; + hlen += ((struct tcphdr *)&((int32_t *)ip)[hlen])->th_off; lastlen[dir][lastconn] = length - (hlen << 2); printf(" %d (%d)", lastlen[dir][lastconn], cp - chdr); } diff --git a/usr.sbin/tcpdump/print-snmp.c b/usr.sbin/tcpdump/print-snmp.c index 4971e429593..89e80d2acc8 100644 --- a/usr.sbin/tcpdump/print-snmp.c +++ b/usr.sbin/tcpdump/print-snmp.c @@ -1,9 +1,8 @@ -/**//* $OpenBSD: print-snmp.c,v 1.3 1996/06/10 07:47:48 deraadt Exp $ */ -/* $NetBSD: print-snmp.c,v 1.3 1995/03/06 19:11:30 mycroft Exp $ */ +/* $OpenBSD: print-snmp.c,v 1.4 1996/07/13 11:01:30 mickey Exp $ */ /* - * Copyright (c) 1990, 1991, 1993, 1994 - * John Robert LoVerso. All rights reserved. + * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are @@ -13,7 +12,7 @@ * by John Robert LoVerso. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * This implementation has been influenced by the CMU SNMP release, * by Steve Waldbusser. However, this shares no code with that system. @@ -134,7 +133,7 @@ char *ErrorStatus[] = { }; #define DECODE_ErrorStatus(e) \ ( e >= 0 && e <= sizeof(ErrorStatus)/sizeof(ErrorStatus[0]) \ - ? ErrorStatus[e] : (sprintf(errbuf, "err=%d", e), errbuf)) + ? ErrorStatus[e] : (sprintf(errbuf, "err=%u", e), errbuf)) /* * generic-trap values in the SNMP Trap-PDU @@ -254,11 +253,11 @@ struct obj_abrev { * temporary internal representation while decoding an ASN.1 data stream. */ struct be { - u_long asnlen; + u_int32_t asnlen; union { caddr_t raw; - long integer; - u_long uns; + int32_t integer; + u_int32_t uns; const u_char *str; } data; u_char form, class, id; /* tag info */ @@ -416,7 +415,7 @@ asn1_parse(register const u_char *p, int len, struct be *elem) break; case INTEGER: { - register long data; + register int32_t data; elem->type = BE_INT; data = 0; @@ -457,7 +456,7 @@ asn1_parse(register const u_char *p, int len, struct be *elem) case COUNTER: case GAUGE: case TIMETICKS: { - register u_long data; + register u_int32_t data; elem->type = BE_UNS; data = 0; for (i = elem->asnlen; i-- > 0; p++) @@ -529,7 +528,7 @@ static void asn1_print(struct be *elem) { u_char *p = (u_char *)elem->data.raw; - u_long asnlen = elem->asnlen; + u_int32_t asnlen = elem->asnlen; int i; switch (elem->type) { @@ -548,7 +547,8 @@ asn1_print(struct be *elem) if (!nflag && asnlen > 2) { struct obj_abrev *a = &obj_abrev_list[0]; for (; a->node; a++) { - if (!bcmp(a->oid, (char *)p, strlen(a->oid))) { + if (!memcmp(a->oid, (char *)p, + strlen(a->oid))) { objp = a->node->child; i -= strlen(a->oid); p += strlen(a->oid); @@ -582,11 +582,11 @@ asn1_print(struct be *elem) } case BE_INT: - printf("%ld", elem->data.integer); + printf("%d", elem->data.integer); break; case BE_UNS: - printf("%ld", elem->data.uns); + printf("%d", elem->data.uns); break; case BE_STR: { @@ -606,7 +606,7 @@ asn1_print(struct be *elem) } case BE_SEQ: - printf("Seq(%d)", elem->asnlen); + printf("Seq(%u)", elem->asnlen); break; case BE_INETADDR: { @@ -623,7 +623,7 @@ asn1_print(struct be *elem) } case BE_PDU: - printf("%s(%d)", + printf("%s(%u)", Class[CONTEXT].Id[elem->id], elem->asnlen); break; diff --git a/usr.sbin/tcpdump/print-sunrpc.c b/usr.sbin/tcpdump/print-sunrpc.c index f2c17034b78..40dc7f68065 100644 --- a/usr.sbin/tcpdump/print-sunrpc.c +++ b/usr.sbin/tcpdump/print-sunrpc.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-sunrpc.c,v 1.3 1996/06/10 07:47:49 deraadt Exp $ */ -/* $NetBSD: print-sunrpc.c,v 1.3 1995/03/06 19:11:32 mycroft Exp $ */ +/* $OpenBSD: print-sunrpc.c,v 1.4 1996/07/13 11:01:31 mickey Exp $ */ /* - * Copyright (c) 1992, 1993, 1994 + * Copyright (c) 1992, 1993, 1994, 1995 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,7 +23,7 @@ #ifndef lint static char rcsid[] = - "@(#) Header: print-sunrpc.c,v 1.12 94/06/14 20:18:48 leres Exp (LBL)"; + "@(#) Header: print-sunrpc.c,v 1.22 95/10/19 20:27:46 leres Exp (LBL)"; #endif #include <sys/param.h> @@ -32,6 +31,10 @@ static char rcsid[] = #include <sys/types.h> #include <sys/socket.h> +#if __STDC__ +struct mbuf; +struct rtentry; +#endif #include <net/if.h> #include <netinet/in.h> @@ -40,43 +43,21 @@ static char rcsid[] = #include <netinet/ip.h> #include <netinet/ip_var.h> -#ifdef SOLARIS -#include <tiuser.h> -#endif #include <rpc/rpc.h> +#ifdef HAVE_RPC_RPCENT_H +#include <rpc/rpcent.h> +#endif #include <rpc/pmap_prot.h> #include <ctype.h> -#include <errno.h> +#include <netdb.h> #include <stdio.h> +#include <string.h> #include "interface.h" #include "addrtoname.h" -#include "extract.h" /* must come after interface.h */ - -#if BYTE_ORDER == LITTLE_ENDIAN -static void bswap(u_int32 *, u_int); -#endif - -#if BYTE_ORDER == LITTLE_ENDIAN -/* - * Byte swap an array of n 32-bit words. - * Assume input is word-aligned. - * Check that buffer is bounded by "snapend". - */ -static void -bswap(register u_int32 *bp, register u_int n) -{ - register int nwords = ((char *)snapend - (char *)bp) / sizeof(*bp); - - if (nwords > n) - nwords = n; - for (; --nwords >= 0; ++bp) - *bp = ntohl(*bp); -} -#endif -static struct token proc2str[] = { +static struct tok proc2str[] = { { PMAPPROC_NULL, "null" }, { PMAPPROC_SET, "set" }, { PMAPPROC_UNSET, "unset" }, @@ -86,12 +67,16 @@ static struct token proc2str[] = { { 0, NULL } }; +/* Forwards */ +static char *progstr(u_int32_t); + void sunrpcrequest_print(register const u_char *bp, register int length, register const u_char *bp2) { register const struct rpc_msg *rp; register const struct ip *ip; + u_int32_t x; rp = (struct rpc_msg *)bp; ip = (struct ip *)bp2; @@ -99,17 +84,52 @@ sunrpcrequest_print(register const u_char *bp, register int length, if (!nflag) (void)printf("%s.%x > %s.sunrpc: %d", ipaddr_string(&ip->ip_src), - ntohl(rp->rm_xid), + (u_int32_t)ntohl(rp->rm_xid), ipaddr_string(&ip->ip_dst), length); else (void)printf("%s.%x > %s.%x: %d", ipaddr_string(&ip->ip_src), - ntohl(rp->rm_xid), + (u_int32_t)ntohl(rp->rm_xid), ipaddr_string(&ip->ip_dst), PMAPPORT, length); - printf(" %s", tok2str(proc2str, " proc #%d", - ntohl(rp->rm_call.cb_proc))); + printf(" %s", tok2str(proc2str, " proc #%u", + (u_int32_t)ntohl(rp->rm_call.cb_proc))); + x = ntohl(rp->rm_call.cb_rpcvers); + if (x != 2) + printf(" [rpcver %u]", x); + + switch (ntohl(rp->rm_call.cb_proc)) { + + case PMAPPROC_SET: + case PMAPPROC_UNSET: + case PMAPPROC_GETPORT: + case PMAPPROC_CALLIT: + x = ntohl(rp->rm_call.cb_prog); + if (!nflag) + printf(" %s", progstr(x)); + else + printf(" %u", x); + printf(".%u", (u_int32_t)ntohl(rp->rm_call.cb_vers)); + break; + } } +static char * +progstr(prog) + u_int32_t prog; +{ + register struct rpcent *rp; + static char buf[32]; + static lastprog = 0; + + if (lastprog != 0 && prog == lastprog) + return (buf); + rp = getrpcbynumber(prog); + if (rp == NULL) + (void) sprintf(buf, "#%u", prog); + else + strcpy(buf, rp->r_name); + return (buf); +} diff --git a/usr.sbin/tcpdump/print-tcp.c b/usr.sbin/tcpdump/print-tcp.c index e8db63a3357..bc3a90f6342 100644 --- a/usr.sbin/tcpdump/print-tcp.c +++ b/usr.sbin/tcpdump/print-tcp.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-tcp.c,v 1.3 1996/06/10 07:47:50 deraadt Exp $ */ -/* $NetBSD: print-tcp.c,v 1.6.4.1 1996/05/26 18:36:15 fvdl Exp $ */ +/* $OpenBSD: print-tcp.c,v 1.4 1996/07/13 11:01:31 mickey Exp $ */ /* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,7 +23,7 @@ #ifndef lint static char rcsid[] = - "@(#) Header: print-tcp.c,v 1.28 94/06/16 01:26:40 mccanne Exp (LBL)"; + "@(#) Header: print-tcp.c,v 1.40 96/06/24 15:29:37 leres Exp (LBL)"; #endif #include <sys/param.h> @@ -38,18 +37,14 @@ static char rcsid[] = #include <netinet/tcp.h> #include <netinet/tcpip.h> -#include <rpc/rpc.h> - #include <stdio.h> -#ifdef __STDC__ #include <stdlib.h> -#endif +#include <string.h> #include <unistd.h> #include "interface.h" #include "addrtoname.h" - -#include "nfs.h" +#include "extract.h" #ifndef TCPOPT_WSCALE #define TCPOPT_WSCALE 3 /* window scale factor (rfc1072) */ @@ -69,6 +64,16 @@ static char rcsid[] = #ifndef TCPOPT_TIMESTAMP #define TCPOPT_TIMESTAMP 8 /* timestamps (rfc1323) */ #endif +#ifndef TCPOPT_CC +#define TCPOPT_CC 11 /* T/TCP CC options (rfc1644) */ +#endif +#ifndef TCPOPT_CCNEW +#define TCPOPT_CCNEW 12 /* T/TCP CC options (rfc1644) */ +#endif +#ifndef TCPOPT_CCECHO +#define TCPOPT_CCECHO 13 /* T/TCP CC options (rfc1644) */ +#endif + struct tha { struct in_addr src; @@ -85,6 +90,9 @@ struct tcp_seq_hash { #define TSEQ_HASHSIZE 919 +/* These tcp optinos do not have the size octet */ +#define ZEROLENOPT(o) ((o) == TCPOPT_EOL || (o) == TCPOPT_NOP) + static struct tcp_seq_hash tcp_seq_hash[TSEQ_HASHSIZE]; @@ -97,11 +105,11 @@ tcp_print(register const u_char *bp, register int length, register u_char flags; register int hlen; u_short sport, dport, win, urp; - tcp_seq seq, ack; + u_int32_t seq, ack; tp = (struct tcphdr *)bp; ip = (struct ip *)bp2; - if ((const u_char *)(tp + 1) > snapend) { + if ((const u_char *)(tp + 1) > snapend) { printf("[|tcp]"); return; } @@ -116,36 +124,13 @@ tcp_print(register const u_char *bp, register int length, ack = ntohl(tp->th_ack); win = ntohs(tp->th_win); urp = ntohs(tp->th_urp); - hlen = tp->th_off * 4; - length -= hlen; - - /* - * If data present and NFS port used, assume NFS. - * Pass offset of data plus 4 bytes for RPC TCP msg length - * to NFS print routines. - */ - if (!qflag) { - if ((u_char *)tp + 4 + sizeof(struct rpc_msg) <= snapend && - dport == NFS_PORT) { - nfsreq_print((u_char *)tp + hlen + 4, length, - (u_char *)ip); - return; - } - else if ((u_char *)tp + 4 + sizeof(struct rpc_msg) <= snapend && - sport == NFS_PORT) { - nfsreply_print((u_char *)tp + hlen + 4, length, - (u_char *)ip); - return; - } - } - (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); + (void)printf("tcp %d", length - tp->th_off * 4); return; } if ((flags = tp->th_flags) & (TH_SYN|TH_FIN|TH_RST|TH_PUSH)) { @@ -184,15 +169,18 @@ tcp_print(register const u_char *bp, register int length, for (th = &tcp_seq_hash[tha.port % TSEQ_HASHSIZE]; th->nxt; th = th->nxt) - if (!bcmp((char *)&tha, (char *)&th->addr, + if (!memcmp((char *)&tha, (char *)&th->addr, sizeof(th->addr))) break; if (!th->nxt || flags & TH_SYN) { /* didn't find it or new conversation */ - if (!th->nxt) + if (th->nxt == NULL) { th->nxt = (struct tcp_seq_hash *) calloc(1, sizeof (*th)); + if (th->nxt == NULL) + error("tcp_print: calloc"); + } th->addr = tha; if (rev) th->ack = seq, th->seq = ack - 1; @@ -205,8 +193,10 @@ tcp_print(register const u_char *bp, register int length, seq -= th->seq, ack -= th->ack; } } + hlen = tp->th_off * 4; + length -= hlen; if (length > 0 || flags & (TH_SYN | TH_FIN | TH_RST)) - (void)printf(" %lu:%lu(%d)", seq, seq + length, length); + (void)printf(" %u:%u(%d)", seq, seq + length, length); if (flags & TH_ACK) (void)printf(" ack %u", ack); @@ -219,86 +209,150 @@ tcp_print(register const u_char *bp, register int length, */ if ((hlen -= sizeof(struct tcphdr)) > 0) { register const u_char *cp = (const u_char *)tp + sizeof(*tp); - int i; + int i, opt, len, datalen; char ch = '<'; putchar(' '); while (--hlen >= 0) { putchar(ch); - switch (*cp++) { + if (cp > snapend) + goto trunc; + opt = *cp++; + if (ZEROLENOPT(opt)) + len = 1; + else { + if (cp > snapend) + goto trunc; + len = *cp++; + --hlen; + } + datalen = 0; + switch (opt) { + case TCPOPT_MAXSEG: - { - (void)printf("mss %d", cp[1] << 8 | cp[2]); - if (*cp != 4) - (void)printf("[len %d]", *cp); - cp += 3; - hlen -= 3; + (void)printf("mss"); + datalen = 2; + if (cp + datalen > snapend) + goto trunc; + (void)printf(" %u", EXTRACT_SHORT(cp)); + break; - } + case TCPOPT_EOL: (void)printf("eol"); break; + case TCPOPT_NOP: (void)printf("nop"); break; + case TCPOPT_WSCALE: - (void)printf("wscale %d", cp[1]); - if (*cp != 3) - (void)printf("[len %d]", *cp); - cp += 2; - hlen -= 2; + (void)printf("wscale"); + datalen = 1; + if (cp + datalen > snapend) + goto trunc; + (void)printf(" %u", *cp); break; + case TCPOPT_SACKOK: (void)printf("sackOK"); - if (*cp != 2) - (void)printf("[len %d]", *cp); - cp += 1; - hlen -= 1; break; + + case TCPOPT_SACK: + (void)printf("sack"); + datalen = len - 2; + i = datalen; + for (i = datalen; i > 0; i -= 4) { + if (cp + i + 4 > snapend) + goto trunc; + /* block-size@relative-origin */ + (void)printf(" %u@%u", + EXTRACT_SHORT(cp + 2), + EXTRACT_SHORT(cp)); + } + if (datalen % 4) + (void)printf("[len %d]", len); + break; + case TCPOPT_ECHO: - { - (void)printf("echo %u", - cp[1] << 24 | cp[2] << 16 | - cp[3] << 8 | cp[4]); - if (*cp != 6) - (void)printf("[len %d]", *cp); - cp += 5; - hlen -= 5; + (void)printf("echo"); + datalen = 4; + if (cp + datalen > snapend) + goto trunc; + (void)printf(" %u", EXTRACT_LONG(cp)); break; - } + case TCPOPT_ECHOREPLY: - { - (void)printf("echoreply %u", - cp[1] << 24 | cp[2] << 16 | - cp[3] << 8 | cp[4]); - if (*cp != 6) - (void)printf("[len %d]", *cp); - cp += 5; - hlen -= 5; + (void)printf("echoreply"); + datalen = 4; + if (cp + datalen > snapend) + goto trunc; + (void)printf(" %u", EXTRACT_LONG(cp)); break; - } + case TCPOPT_TIMESTAMP: - { - (void)printf("timestamp %lu %lu", - cp[1] << 24 | cp[2] << 16 | - cp[3] << 8 | cp[4], - cp[5] << 24 | cp[6] << 16 | - cp[7] << 8 | cp[8]); - if (*cp != 10) - (void)printf("[len %d]", *cp); - cp += 9; - hlen -= 9; + (void)printf("timestamp"); + datalen = 4; + if (cp + datalen > snapend) + goto trunc; + (void)printf(" %u", EXTRACT_LONG(cp)); + datalen += 4; + if (cp + datalen > snapend) + goto trunc; + (void)printf(" %u", EXTRACT_LONG(cp + 4)); + break; + + case TCPOPT_CC: + (void)printf("cc"); + datalen = 4; + if (cp + datalen > snapend) + goto trunc; + (void)printf(" %u", EXTRACT_LONG(cp)); + break; + + case TCPOPT_CCNEW: + (void)printf("ccnew"); + datalen = 4; + if (cp + datalen > snapend) + goto trunc; + (void)printf(" %u", EXTRACT_LONG(cp)); break; - } + + case TCPOPT_CCECHO: + (void)printf("ccecho"); + datalen = 4; + if (cp + datalen > snapend) + goto trunc; + (void)printf(" %u", EXTRACT_LONG(cp)); + break; + default: - (void)printf("opt-%d:", cp[-1]); - for (i = *cp++ - 2, hlen -= i + 1; i > 0; --i) - (void)printf("%02x", *cp++); + (void)printf("opt-%d:", opt); + datalen = len - 2; + for (i = 0; i < datalen; ++i) { + if (cp + i > snapend) + goto trunc; + (void)printf("%02x", cp[i]); + } break; } + + /* Account for data printed */ + cp += datalen; + hlen -= datalen; + + /* Check specification against observed length */ + ++datalen; /* option octet */ + if (!ZEROLENOPT(opt)) + ++datalen; /* size octet */ + if (datalen != len) + (void)printf("[len %d]", len); ch = ','; } putchar('>'); } + return; +trunc: + (void)printf("[|tcp]>"); } diff --git a/usr.sbin/tcpdump/print-tftp.c b/usr.sbin/tcpdump/print-tftp.c index da9a1f968da..a0c7bfbd68c 100644 --- a/usr.sbin/tcpdump/print-tftp.c +++ b/usr.sbin/tcpdump/print-tftp.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-tftp.c,v 1.3 1996/06/10 07:47:51 deraadt Exp $ */ -/* $NetBSD: print-tftp.c,v 1.2 1995/03/06 19:11:35 mycroft Exp $ */ +/* $OpenBSD: print-tftp.c,v 1.4 1996/07/13 11:01:32 mickey Exp $ */ /* - * Copyright (c) 1990, 1991, 1993, 1994 + * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,7 +25,7 @@ #ifndef lint static char rcsid[] = - "@(#) Header: print-tftp.c,v 1.20 94/06/14 20:18:49 leres Exp (LBL)"; + "@(#) Header: print-tftp.c,v 1.23 96/06/23 02:11:47 leres Exp (LBL)"; #endif #include <sys/param.h> @@ -45,7 +44,7 @@ static char rcsid[] = #include "addrtoname.h" /* op code to string mapping */ -static struct token op2str[] = { +static struct tok op2str[] = { { RRQ, "RRQ" }, /* read request */ { WRQ, "WRQ" }, /* write request */ { DATA, "DATA" }, /* data packet */ @@ -55,7 +54,7 @@ static struct token op2str[] = { }; /* error code to string mapping */ -static struct token err2str[] = { +static struct tok err2str[] = { { EUNDEF, "EUNDEF" }, /* not defined */ { ENOTFOUND, "ENOTFOUND" }, /* file not found */ { EACCESS, "EACCESS" }, /* access violation */ @@ -81,7 +80,7 @@ tftp_print(register const u_char *bp, int length) static char tstr[] = " [|tftp]"; tp = (const struct tftphdr *)bp; - /* 'ep' points to the end of avaible data. */ + /* 'ep' points to the end of available data. */ ep = snapend; /* Print length */ @@ -116,14 +115,12 @@ tftp_print(register const u_char *bp, int length) } break; + case ACK: case DATA: TCHECK(tp->th_block, sizeof(tp->th_block)); printf(" block %d", ntohs(tp->th_block)); break; - case ACK: - break; - case ERROR: /* Print error code string */ TCHECK(tp->th_code, sizeof(tp->th_code)); diff --git a/usr.sbin/tcpdump/print-udp.c b/usr.sbin/tcpdump/print-udp.c index 4194233cef6..d67aa6b26f1 100644 --- a/usr.sbin/tcpdump/print-udp.c +++ b/usr.sbin/tcpdump/print-udp.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-udp.c,v 1.3 1996/06/10 07:47:52 deraadt Exp $ */ -/* $NetBSD: print-udp.c,v 1.4 1996/05/20 00:41:16 fvdl Exp $ */ +/* $OpenBSD: print-udp.c,v 1.4 1996/07/13 11:01:32 mickey Exp $ */ /* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,7 +23,7 @@ #ifndef lint static char rcsid[] = - "@(#) Header: print-udp.c,v 1.37 94/06/10 17:01:42 mccanne Exp (LBL)"; + "@(#) Header: print-udp.c,v 1.51 96/06/23 02:26:12 leres Exp (LBL)"; #endif #include <sys/param.h> @@ -43,22 +42,64 @@ static char rcsid[] = #include <arpa/nameser.h> #include <arpa/tftp.h> -#ifdef SOLARIS -#include <tiuser.h> -#endif #include <rpc/rpc.h> -#include <errno.h> #include <stdio.h> #include "interface.h" #include "addrtoname.h" #include "appletalk.h" -#include "nfs.h" +#include "nfsv2.h" #include "bootp.h" -extern int packettype; +struct rtcphdr { + u_short rh_flags; /* T:2 P:1 CNT:5 PT:8 */ + u_short rh_len; /* length of message (in bytes) */ + u_int rh_ssrc; /* synchronization src id */ +}; + +typedef struct { + u_int upper; /* more significant 32 bits */ + u_int lower; /* less significant 32 bits */ +} ntp64; + +/* + * Sender report. + */ +struct rtcp_sr { + ntp64 sr_ntp; /* 64-bit ntp timestamp */ + u_int sr_ts; /* reference media timestamp */ + u_int sr_np; /* no. packets sent */ + u_int sr_nb; /* no. bytes sent */ +}; + +/* + * Receiver report. + * Time stamps are middle 32-bits of ntp timestamp. + */ +struct rtcp_rr { + u_int rr_srcid; /* sender being reported */ + u_int rr_nr; /* no. packets received */ + u_int rr_np; /* no. packets predicted */ + u_int rr_dv; /* jitter (delay variance) */ + u_int rr_lsr; /* orig. ts from last rr from this src */ + u_int rr_dlsr; /* time from recpt of last rr to xmit time */ +}; + +/*XXX*/ +#define RTCP_PT_SR 0 +#define RTCP_PT_RR 1 +#define RTCP_PT_SDES 2 +#define RTCP_SDES_CNAME 1 +#define RTCP_SDES_NAME 2 +#define RTCP_SDES_EMAIL 3 +#define RTCP_SDES_PHONE 4 +#define RTCP_SDES_LOC 5 +#define RTCP_SDES_TOOL 6 +#define RTCP_SDES_TXT 7 +#define RTCP_PT_BYE 3 +#define RTCP_PT_APP 4 static void vat_print(const void *hdr, int len, register const struct udphdr *up) @@ -67,15 +108,15 @@ vat_print(const void *hdr, int len, register const struct udphdr *up) u_int ts = *(u_short *)hdr; if ((ts & 0xf060) != 0) { /* probably vt */ - (void)printf(" udp/vt %d %d / %d", - ntohs(up->uh_ulen) - sizeof(*up), + (void)printf(" udp/vt %u %d / %d", + (u_int32_t)(ntohs(up->uh_ulen) - sizeof(*up)), ts & 0x3ff, ts >> 10); } else { /* probably vat */ - u_int i0 = ((u_int *)hdr)[0]; - u_int i1 = ((u_int *)hdr)[1]; - printf(" udp/vat %d c%d %u%s", - ntohs(up->uh_ulen) - sizeof(*up) - 8, + u_int i0 = ntohl(((u_int *)hdr)[0]); + u_int i1 = ntohl(((u_int *)hdr)[1]); + printf(" udp/vat %u c%d %u%s", + (u_int32_t)(ntohs(up->uh_ulen) - sizeof(*up) - 8), i0 & 0xffff, i1, i0 & 0x800000? "*" : ""); /* audio format */ @@ -89,22 +130,40 @@ vat_print(const void *hdr, int len, register const struct udphdr *up) static void rtp_print(const void *hdr, int len, register const struct udphdr *up) { - /* rtp v1 video */ + /* rtp v1 or v2 */ u_int *ip = (u_int *)hdr; - u_int i0 = ((u_int *)hdr)[0]; - u_int i1 = ((u_int *)hdr)[1]; - u_int hasopt = i0 & 0x800000; - u_int contype = (i0 >> 16) & 0x3f; - printf(" udp/rtp %d c%d %s%s %d", - ntohs(up->uh_ulen) - sizeof(*up) - 8, + u_int hasopt, contype, hasmarker; + u_int i0 = ntohl(((u_int *)hdr)[0]); + u_int i1 = ntohl(((u_int *)hdr)[1]); + int dlen = ntohs(up->uh_ulen) - sizeof(*up) - 8; + const char* ptype; + ip += 2; + len >>= 2; + len -= 2; + if ((i0 >> 30) == 1) { + /* rtp v1 */ + hasopt = i0 & 0x800000; + contype = (i0 >> 16) & 0x3f; + hasmarker = i0 & 0x400000; + ptype = "rtpv1"; + } else { /*XXX*/ + /* rtp v2 */ + hasopt = i0 & 0x20000000; + contype = (i0 >> 16) & 0x7f; + hasmarker = i0 & 0x800000; + dlen -= 4; + ptype = "rtp"; + ip += 1; + len -= 1; + } + printf(" udp/%s %d c%d %s%s %d", + ptype, + dlen, contype, hasopt? "+" : "", - i0 & 0x400000? "*" : "", + hasmarker? "*" : "", i0 & 0xffff); - if (contype == 31) { - ip += 2; - len >>= 2; - len -= 2; + if (vflag) { if (hasopt) { u_int i2, optlen; do { @@ -117,19 +176,84 @@ rtp_print(const void *hdr, int len, register const struct udphdr *up) ip += optlen; } while ((int)i2 >= 0); } - printf(" 0x%04x", ip[0] >> 16); + if (contype == 0x1f) + printf(" 0x%04x", ip[0] >> 16); + printf(" %u", i1); } +} + +static const u_char* +rtcp_print(const u_char *hdr) +{ + /* rtp v2 control (rtcp) */ + struct rtcp_rr* rr = 0; + struct rtcp_sr* sr; + struct rtcphdr* rh = (struct rtcphdr*)hdr; + int len = (ntohs(rh->rh_len) + 1) * 4; + u_short flags = ntohs(rh->rh_flags); + int cnt = (flags >> 8) & 0x1f; + double ts, dts, jitter; if (vflag) - printf(" %u", i1); + printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc)); + switch (flags & 0xff) { + case RTCP_PT_SR: + sr = (struct rtcp_sr*)(rh + 1); + printf(" sr"); + if (len != cnt * sizeof(*rr) + sizeof(*sr) + sizeof(*rh)) + printf(" [%d]", len); + ts = (double)((u_int32_t)ntohl(sr->sr_ts)) / 65536.; + printf(" @%.2f %up %ub", ts, (u_int32_t)ntohl(sr->sr_np), + (u_int32_t)ntohl(sr->sr_nb)); + rr = (struct rtcp_rr*)(sr + 1); + break; + case RTCP_PT_RR: + printf(" rr"); + if (len != cnt * sizeof(*rr) + sizeof(*rh)) + printf(" [%d]", len); + rr = (struct rtcp_rr*)(rh + 1); + break; + case RTCP_PT_SDES: + printf(" sdes %d", len); + cnt = 0; + break; + case RTCP_PT_BYE: + printf(" bye %d", len); + cnt = 0; + break; + default: + printf(" type-0x%x %d", flags & 0xff, len); + cnt = 0; + break; + } + if (cnt > 1) + printf(" c%d", cnt); + while (--cnt >= 0) { + if ((u_char*)(rr + 1) > snapend) { + printf(" [|rtcp]"); + return (snapend); + } + if (vflag) + printf(" %u", (u_int32_t)ntohl(rr->rr_srcid)); + ts = (double)((u_int32_t)ntohl(rr->rr_lsr)) / 65536.; + dts = (double)((u_int32_t)ntohl(rr->rr_dlsr)) / 65536.; + jitter = (double)((u_int32_t)ntohl(rr->rr_dv)) / 65536.; + printf(" %ur %ue %.2fj @%.2f+%.2f", + (u_int32_t)ntohl(rr->rr_nr), + (u_int32_t)ntohl(rr->rr_np), + jitter, ts, dts); + } + return (hdr + len); } /* XXX probably should use getservbyname() and cache answers */ #define TFTP_PORT 69 /*XXX*/ +#define KERBEROS_PORT 88 /*XXX*/ #define SUNRPC_PORT 111 /*XXX*/ #define SNMP_PORT 161 /*XXX*/ #define NTP_PORT 123 /*XXX*/ #define SNMPTRAP_PORT 162 /*XXX*/ #define RIP_PORT 520 /*XXX*/ +#define KERBEROS_SEC_PORT 750 /*XXX*/ void udp_print(register const u_char *bp, int length, register const u_char *bp2) @@ -160,7 +284,8 @@ udp_print(register const u_char *bp, int length, register const u_char *bp2) enum msg_type direction; switch (packettype) { - case 1: + + case PT_VAT: (void)printf("%s.%s > %s.%s:", ipaddr_string(&ip->ip_src), udpport_string(sport), @@ -168,7 +293,8 @@ udp_print(register const u_char *bp, int length, register const u_char *bp2) udpport_string(dport)); vat_print((void *)(up + 1), length, up); break; - case 2: + + case PT_WB: (void)printf("%s.%s > %s.%s:", ipaddr_string(&ip->ip_src), udpport_string(sport), @@ -176,7 +302,8 @@ udp_print(register const u_char *bp, int length, register const u_char *bp2) udpport_string(dport)); wb_print((void *)(up + 1), length); break; - case 3: + + case PT_RPC: rp = (struct rpc_msg *)(up + 1); direction = (enum msg_type)ntohl(rp->rm_direction); if (direction == CALL) @@ -186,7 +313,8 @@ udp_print(register const u_char *bp, int length, register const u_char *bp2) nfsreply_print((u_char *)rp, length, (u_char *)ip); /*XXX*/ break; - case 4: + + case PT_RTP: (void)printf("%s.%s > %s.%s:", ipaddr_string(&ip->ip_src), udpport_string(sport), @@ -194,6 +322,16 @@ udp_print(register const u_char *bp, int length, register const u_char *bp2) udpport_string(dport)); rtp_print((void *)(up + 1), length, up); break; + + case PT_RTCP: + (void)printf("%s.%s > %s.%s:", + ipaddr_string(&ip->ip_src), + udpport_string(sport), + ipaddr_string(&ip->ip_dst), + udpport_string(dport)); + while (cp < snapend) + cp = rtcp_print(cp); + break; } return; } @@ -239,12 +377,14 @@ udp_print(register const u_char *bp, int length, register const u_char *bp2) else if (ISPORT(IPPORT_BOOTPC) || ISPORT(IPPORT_BOOTPS)) bootp_print((const u_char *)(up + 1), length, sport, dport); - else if (dport == RIP_PORT) + else if (ISPORT(RIP_PORT)) rip_print((const u_char *)(up + 1), length); else if (ISPORT(SNMP_PORT) || ISPORT(SNMPTRAP_PORT)) snmp_print((const u_char *)(up + 1), length); else if (ISPORT(NTP_PORT)) ntp_print((const u_char *)(up + 1), length); + else if (ISPORT(KERBEROS_PORT) || ISPORT(KERBEROS_SEC_PORT)) + krb_print((const void *)(up + 1), length); else if (dport == 3456) vat_print((const void *)(up + 1), length, up); /* @@ -253,8 +393,9 @@ udp_print(register const u_char *bp, int length, register const u_char *bp2) else if (dport == 4567) wb_print((const void *)(up + 1), length); else - (void)printf(" udp %d", ulen - sizeof(*up)); + (void)printf(" udp %u", + (u_int32_t)(ulen - sizeof(*up))); #undef ISPORT } else - (void)printf(" udp %d", ulen - sizeof(*up)); + (void)printf(" udp %u", (u_int32_t)(ulen - sizeof(*up))); } diff --git a/usr.sbin/tcpdump/print-wb.c b/usr.sbin/tcpdump/print-wb.c index 6185802cc3b..5bde81009e2 100644 --- a/usr.sbin/tcpdump/print-wb.c +++ b/usr.sbin/tcpdump/print-wb.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: print-wb.c,v 1.3 1996/06/10 07:47:53 deraadt Exp $ */ -/* $NetBSD: print-wb.c,v 1.2 1995/03/06 19:11:37 mycroft Exp $ */ +/* $OpenBSD: print-wb.c,v 1.4 1996/07/13 11:01:33 mickey Exp $ */ /* - * Copyright (c) 1993, 1994 + * Copyright (c) 1993, 1994, 1995 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,7 +23,7 @@ #ifndef lint static char rcsid[] = - "@(#) Header: print-wb.c,v 1.14 94/06/14 20:18:50 leres Exp (LBL)"; + "@(#) Header: print-wb.c,v 1.18 95/10/18 22:21:27 leres Exp (LBL)"; #endif #include <sys/types.h> @@ -60,8 +59,8 @@ static char rcsid[] = * The transport level header. */ struct pkt_hdr { - u_int32 ph_src; /* site id of source */ - u_int32 ph_ts; /* time stamp (for skew computation) */ + u_int32_t ph_src; /* site id of source */ + u_int32_t ph_ts; /* time stamp (for skew computation) */ u_short ph_version; /* version number */ u_char ph_type; /* message type */ u_char ph_flags; /* message flags */ @@ -81,12 +80,12 @@ struct pkt_hdr { #define PF_VIS 0x02 /* only visible ops wanted */ struct PageID { - u_int32 p_sid; /* session id of initiator */ - u_int32 p_uid; /* page number */ + u_int32_t p_sid; /* session id of initiator */ + u_int32_t p_uid; /* page number */ }; struct dophdr { - u_int32 dh_ts; /* sender's timestamp */ + u_int32_t dh_ts; /* sender's timestamp */ u_short dh_len; /* body length */ u_char dh_flags; u_char dh_type; /* body type */ @@ -116,8 +115,8 @@ struct dophdr { */ struct pkt_dop { struct PageID pd_page; /* page that operations apply to */ - u_int32 pd_sseq; /* start sequence number */ - u_int32 pd_eseq; /* end sequence number */ + u_int32_t pd_sseq; /* start sequence number */ + u_int32_t pd_eseq; /* end sequence number */ /* drawing ops follow */ }; @@ -125,28 +124,28 @@ struct pkt_dop { * A repair request. */ struct pkt_rreq { - u_int32 pr_id; /* source id of drawops to be repaired */ + u_int32_t pr_id; /* source id of drawops to be repaired */ struct PageID pr_page; /* page of drawops */ - u_int32 pr_sseq; /* start seqno */ - u_int32 pr_eseq; /* end seqno*/ + u_int32_t pr_sseq; /* start seqno */ + u_int32_t pr_eseq; /* end seqno*/ }; /* * A repair reply. */ struct pkt_rrep { - u_int32 pr_id; /* original site id of ops */ + u_int32_t pr_id; /* original site id of ops */ struct pkt_dop pr_dop; /* drawing ops follow */ }; struct id_off { - u_int32 id; - u_int32 off; + u_int32_t id; + u_int32_t off; }; struct pgstate { - u_int32 slot; + u_int32_t slot; struct PageID page; u_short nid; u_short rsvd; @@ -157,7 +156,7 @@ struct pgstate { * An announcement packet. */ struct pkt_id { - u_int32 pi_mslot; + u_int32_t pi_mslot; struct PageID pi_mpage; /* current page */ struct pgstate pi_ps; /* seqptr's */ @@ -166,12 +165,12 @@ struct pkt_id { struct pkt_preq { struct PageID pp_page; - u_int32 pp_low; - u_int32 pp_high; + u_int32_t pp_low; + u_int32_t pp_high; }; struct pkt_prep { - u_int32 pp_n; /* size of pageid array */ + u_int32_t pp_n; /* size of pageid array */ /* pgstate's follow */ }; @@ -184,77 +183,66 @@ wb_id(const struct pkt_id *id, int len) char c; int nid; + printf(" wb-id:"); len -= sizeof(*id); - if (len < 0) { - printf(" truncated-wb-id!"); - return (0); - } - if ((u_char *)(id + 1) > snapend) - return (-1); - nid = ntohs(id->pi_ps.nid); - len -= sizeof(*io) * nid; - if (len < 0) { - printf(" truncated-wb-id!"); - return (0); - } - io = (struct id_off *)(id + 1); - cp = (char *)(io + nid); - if ((u_char *)cp + len > snapend) + if (len < 0 || (u_char *)(id + 1) > snapend) return (-1); - printf(" wb-id: %d/%s:%d (max %d/%s:%d) ", - ntohl(id->pi_ps.slot), + printf(" %u/%s:%u (max %u/%s:%u) ", + (u_int32_t)ntohl(id->pi_ps.slot), ipaddr_string(&id->pi_ps.page.p_sid), - ntohl(id->pi_ps.page.p_uid), - ntohl(id->pi_mslot), + (u_int32_t)ntohl(id->pi_ps.page.p_uid), + (u_int32_t)ntohl(id->pi_mslot), ipaddr_string(&id->pi_mpage.p_sid), - ntohl(id->pi_mpage.p_uid)); + (u_int32_t)ntohl(id->pi_mpage.p_uid)); - if (cp[len - 1] != '\0') - printf("(unterm!) "); - - fn_print((u_char *)cp, (u_char *)cp + len); + nid = ntohs(id->pi_ps.nid); + len -= sizeof(*io) * nid; + io = (struct id_off *)(id + 1); + cp = (char *)(io + nid); + if ((u_char *)cp + len <= snapend) + fn_print((u_char *)cp, (u_char *)cp + len); c = '<'; - for (i = 0; i < nid; ++io, ++i) { - printf("%c%s:%d", c, ipaddr_string(&io->id), ntohl(io->off)); + for (i = 0; i < nid && (u_char*)io < snapend; ++io, ++i) { + printf("%c%s:%u", + c, ipaddr_string(&io->id), (u_int32_t)ntohl(io->off)); c = ','; } - printf(">"); - return (0); + if (i >= nid) { + printf(">"); + return (0); + } + return (-1); } static int wb_rreq(const struct pkt_rreq *rreq, int len) { - if (len < sizeof(*rreq)) { - printf(" truncated-wb-rreq!"); - return (0); - } - if ((u_char *)(rreq + 1) > snapend) + printf(" wb-rreq:"); + if (len < sizeof(*rreq) || (u_char *)(rreq + 1) > snapend) return (-1); - printf(" wb-rreq: please repair %s %s:%ld<%ld:%ld>", + printf(" please repair %s %s:%u<%u:%u>", ipaddr_string(&rreq->pr_id), - ipaddr_string(&rreq->pr_page.p_sid), ntohl(rreq->pr_page.p_uid), - ntohl(rreq->pr_sseq), ntohl(rreq->pr_eseq)); + ipaddr_string(&rreq->pr_page.p_sid), + (u_int32_t)ntohl(rreq->pr_page.p_uid), + (u_int32_t)ntohl(rreq->pr_sseq), + (u_int32_t)ntohl(rreq->pr_eseq)); return (0); } static int wb_preq(const struct pkt_preq *preq, int len) { - if (len < sizeof(*preq)) { - printf(" truncated-wb-preq!"); - return (0); - } - if ((u_char *)(preq + 1) > snapend) + printf(" wb-preq:"); + if (len < sizeof(*preq) || (u_char *)(preq + 1) > snapend) return (-1); - printf(" wb-preq: need %d/%s:%ld", - ntohl(preq->pp_low), + printf(" need %u/%s:%u", + (u_int32_t)ntohl(preq->pp_low), ipaddr_string(&preq->pp_page.p_sid), - ntohl(preq->pp_page.p_uid)); + (u_int32_t)ntohl(preq->pp_page.p_uid)); return (0); } @@ -265,24 +253,24 @@ wb_prep(const struct pkt_prep *prep, int len) const struct pgstate* ps; const u_char* ep = snapend; + printf(" wb-prep:"); if (len < sizeof(*prep)) { - printf(" truncated-wb-prep!"); - return (0); + return (-1); } - printf(" wb-prep:"); n = ntohl(prep->pp_n); ps = (const struct pgstate*)(prep + 1); while (--n >= 0 && (u_char*)ps < ep) { const struct id_off *io, *ie; char c = '<'; - printf(" %lu/%s:%lu", ntohl(ps->slot), - ipaddr_string(&ps->page.p_sid), - ntohl(ps->page.p_uid)); + printf(" %u/%s:%u", + (u_int32_t)ntohl(ps->slot), + ipaddr_string(&ps->page.p_sid), + (u_int32_t)ntohl(ps->page.p_uid)); io = (struct id_off*)(ps + 1); for (ie = io + ps->nid; io < ie && (u_char*)io < ep; ++io) { - printf("%c%s:%lu", c, ipaddr_string(&io->id), - ntohl(io->off)); + printf("%c%s:%u", c, ipaddr_string(&io->id), + (u_int32_t)ntohl(io->off)); c = ','; } printf(">"); @@ -312,7 +300,7 @@ char *dopstr[] = { }; static int -wb_dops(const struct dophdr *dh, u_int32 ss, u_int32 es) +wb_dops(const struct dophdr *dh, u_int32_t ss, u_int32_t es) { printf(" <"); for ( ; ss <= es; ++ss) { @@ -348,40 +336,42 @@ wb_rrep(const struct pkt_rrep *rrep, int len) { const struct pkt_dop *dop = &rrep->pr_dop; + printf(" wb-rrep:"); len -= sizeof(*rrep); - if (len < 0) { - printf(" truncated-wb-rrep!"); - return (0); - } - if ((u_char *)(rrep + 1) > snapend) + if (len < 0 || (u_char *)(rrep + 1) > snapend) return (-1); - printf(" wb-rrep: for %s %s:%d<%ld:%ld>", - ipaddr_string(&rrep->pr_id), - ipaddr_string(&dop->pd_page.p_sid), ntohl(dop->pd_page.p_uid), - ntohl(dop->pd_sseq), ntohl(dop->pd_eseq)); + printf(" for %s %s:%u<%u:%u>", + ipaddr_string(&rrep->pr_id), + ipaddr_string(&dop->pd_page.p_sid), + (u_int32_t)ntohl(dop->pd_page.p_uid), + (u_int32_t)ntohl(dop->pd_sseq), + (u_int32_t)ntohl(dop->pd_eseq)); - return (wb_dops((const struct dophdr*)(dop + 1), - ntohl(dop->pd_sseq), ntohl(dop->pd_eseq))); + if (vflag) + return (wb_dops((const struct dophdr*)(dop + 1), + ntohl(dop->pd_sseq), ntohl(dop->pd_eseq))); + return (0); } static int wb_drawop(const struct pkt_dop *dop, int len) { + printf(" wb-dop:"); len -= sizeof(*dop); - if (len < 0) { - printf(" truncated-wb-dop!"); - return (0); - } - if ((u_char *)(dop + 1) > snapend) + if (len < 0 || (u_char *)(dop + 1) > snapend) return (-1); - printf(" wb-dop: %s:%d<%ld:%ld>", - ipaddr_string(&dop->pd_page.p_sid), ntohl(dop->pd_page.p_uid), - ntohl(dop->pd_sseq), ntohl(dop->pd_eseq)); + printf(" %s:%u<%u:%u>", + ipaddr_string(&dop->pd_page.p_sid), + (u_int32_t)ntohl(dop->pd_page.p_uid), + (u_int32_t)ntohl(dop->pd_sseq), + (u_int32_t)ntohl(dop->pd_eseq)); - return (wb_dops((const struct dophdr*)(dop + 1), - ntohl(dop->pd_sseq), ntohl(dop->pd_eseq))); + if (vflag) + return (wb_dops((const struct dophdr*)(dop + 1), + ntohl(dop->pd_sseq), ntohl(dop->pd_eseq))); + return (0); } /* @@ -394,55 +384,49 @@ wb_print(register const void *hdr, register int len) ph = (const struct pkt_hdr*)hdr; len -= sizeof(*ph); - if (len < 0) { - printf(" truncated-wb!"); - return; - } - if ((u_char *)(ph + 1) > snapend) { - trunc: - printf("[|wb]"); - return; - } - if (ph->ph_flags) - printf("*"); - switch (ph->ph_type) { - - case PT_KILL: - printf(" wb-kill"); - break; - - case PT_ID: - if (wb_id((struct pkt_id *)(ph + 1), len) < 0) - goto trunc; - break; - - case PT_RREQ: - if (wb_rreq((struct pkt_rreq *)(ph + 1), len) < 0) - goto trunc; - break; - - case PT_RREP: - if (wb_rrep((struct pkt_rrep *)(ph + 1), len) < 0) - goto trunc; - break; - - case PT_DRAWOP: - if (wb_drawop((struct pkt_dop *)(ph + 1), len) < 0) - goto trunc; - break; - - case PT_PREQ: - if (wb_preq((struct pkt_preq *)(ph + 1), len) < 0) - goto trunc; - break; - - case PT_PREP: - if (wb_prep((struct pkt_prep *)(ph + 1), len) < 0) - goto trunc; - break; - - default: - printf(" wb-%d!", ph->ph_type); - return; + if (len < 0 || (u_char *)(ph + 1) <= snapend) { + if (ph->ph_flags) + printf("*"); + switch (ph->ph_type) { + + case PT_KILL: + printf(" wb-kill"); + return; + + case PT_ID: + if (wb_id((struct pkt_id *)(ph + 1), len) >= 0) + return; + break; + + case PT_RREQ: + if (wb_rreq((struct pkt_rreq *)(ph + 1), len) >= 0) + return; + break; + + case PT_RREP: + if (wb_rrep((struct pkt_rrep *)(ph + 1), len) >= 0) + return; + break; + + case PT_DRAWOP: + if (wb_drawop((struct pkt_dop *)(ph + 1), len) >= 0) + return; + break; + + case PT_PREQ: + if (wb_preq((struct pkt_preq *)(ph + 1), len) >= 0) + return; + break; + + case PT_PREP: + if (wb_prep((struct pkt_prep *)(ph + 1), len) >= 0) + return; + break; + + default: + printf(" wb-%d!", ph->ph_type); + return; + } } + printf("[|wb]"); } diff --git a/usr.sbin/tcpdump/tcpdump.8 b/usr.sbin/tcpdump/tcpdump.8 index 835976a9ddd..995e6f24f46 100644 --- a/usr.sbin/tcpdump/tcpdump.8 +++ b/usr.sbin/tcpdump/tcpdump.8 @@ -1,9 +1,6 @@ -.\" $OpenBSD: tcpdump.8,v 1.3 1996/06/10 07:47:56 deraadt Exp $ -.\" $NetBSD: tcpdump.8,v 1.3 1995/03/06 19:11:46 mycroft Exp $ +.\" @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/tcpdump.8,v 1.4 1996/07/13 11:01:34 mickey Exp $ (LBL) .\" -.\" @(#) Header: tcpdump.1,v 1.45 94/06/20 18:54:27 leres Exp (LBL) -.\" -.\" Copyright (c) 1987, 1988, 1989, 1990, 1991, 1992, 1994 +.\" Copyright (c) 1987, 1988, 1989, 1990, 1991, 1992, 1994, 1995, 1996 .\" The Regents of the University of California. All rights reserved. .\" All rights reserved. .\" @@ -23,7 +20,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH TCPDUMP 1 "20 Jun 1994" +.TH TCPDUMP 1 "22 June 1996" .SH NAME tcpdump \- dump traffic on a network .SH SYNOPSIS @@ -54,34 +51,61 @@ tcpdump \- dump traffic on a network .br .ti +8 [ +.B \-T +.I type +] +[ .B \-w .I file ] +[ .I expression +] .br .ad .SH DESCRIPTION .LP \fITcpdump\fP prints out the headers of packets on a network interface that match the boolean \fIexpression\fP. -.B Under SunOS: -You must be root to invoke \fItcpdump\fP or it must be installed -setuid to root. +.B Under SunOS with nit or bpf: +To run +.I tcpdump +you must have read access to +.I /dev/net +or +.IR /dev/bpf* . +.B Under Solaris with dlpi: +You must have read access to the network pseudo device, e.g. +.IR /dev/le . +.B Under HP-UX with dlpi: +You must be root or it must be installed setuid to root. +.B Under IRIX with snoop: +You must be root or it must be installed setuid to root. .B Under Ultrix: -Any user can invoke \fItcpdump\fP once the super-user has enabled +Once the super-user has enabled promiscuous-mode operation using -.IR pfconfig (8). +.IR pfconfig (8), +any user may run +.BR tcpdump . .B Under BSD: -Access is controlled by the permissions on -.I /dev/bpf0, -etc. +You must have read access to +.IR /dev/bpf* . .SH OPTIONS .TP .B \-c Exit after receiving \fIcount\fP packets. .TP .B \-d -Dump the compiled packet-matching code to standard output and stop. +Dump the compiled packet-matching code in a human readable form to +standard output and stop. +.TP +.B \-dd +Dump packet-matching code as a +.B C +program fragment. +.TP +.B \-ddd +Dump packet-matching code as a decimal numbers (preceded with a count). .TP .B \-e Print the link-level header on each dump line. @@ -124,8 +148,8 @@ if you suspect a bug in the optimizer. .B \-p \fIDon't\fP put the interface into promiscuous mode. Note that the interface might be in promiscuous -for some other reason; hence, `-p' cannot be used as an abbreviation for -`ether host {localhost} or broadcast'. +mode for some other reason; hence, `-p' cannot be used as an abbreviation for +`ether host {local-hw-addr} or ether broadcast'. .TP .B \-q Quick (quiet?) output. Print less protocol information so output @@ -137,7 +161,7 @@ Standard input is used if \fIfile\fR is ``-''. .TP .B \-s Snarf \fIsnaplen\fP bytes of data from each packet rather than the -default of 68 (with NIT, the minimum is actually 96). +default of 68 (with SunOS's NIT, the minimum is actually 96). 68 bytes is adequate for IP, ICMP, TCP and UDP but may truncate protocol information from name server and NFS packets (see below). Packets truncated because of a limited snapshot @@ -149,6 +173,16 @@ decreases the amount of packet buffering. This may cause packets to be lost. You should limit \fIsnaplen\fP to the smallest number that will capture the protocol information you're interested in. .TP +.B \-T +Force packets selected by "\fIexpression\fP" to be interpreted the +specified \fItype\fR. Currently known types are +\fBrpc\fR (Remote Procedure Call), +\fBrtp\fR (Real-Time Applications protocol), +\fBrtcp\fR (Real-Time Applications control protocol), +\fBvat\fR (Visual Audio Tool), +and +\fBwb\fR (distributed White Board). +.TP .B \-S Print absolute, rather than relative, TCP sequence numbers. .TP @@ -200,7 +234,7 @@ qualifier, .B host is assumed. .IP \fIdir\fP -qualifiers specify a particular tranfer direction to and/or from +qualifiers specify a particular transfer direction to and/or from .I id. Possible directions are .BR src , @@ -213,6 +247,11 @@ E.g., `src foo', `dst net 128.3', `src or dst port ftp-data'. If there is no dir qualifier, .B "src or dst" is assumed. +For `null' link layers (i.e. point to point protocols such as slip) the +.B inbound +and +.B outbound +qualifiers can be used to specify a desired direction. .IP \fIproto\fP qualifiers restrict the match to a particular protocol. Possible protos are: @@ -306,7 +345,8 @@ expression is which can be used with either names or numbers for \fIhost / ehost\fP.) .IP "\fBdst net \fInet\fR" True if the IP destination address of the packet has a network -number of \fInet\fP, which may be either an address or a name. +number of \fInet\fP. \fINet\fP may be either a name from /etc/networks +or a network number (see \fInetworks(4)\fP for details). .IP "\fBsrc net \fInet\fR" True if the IP source address of the packet has a network number of \fInet\fP. @@ -336,7 +376,7 @@ Any of the above port expressions can be prepended with the keywords, \fBtcp src port \fIport\fR .fi .in -.5i -which matches only tcp packets. +which matches only tcp packets whose source port is \fIport\fP. .IP "\fBless \fIlength\fR" True if the packet has a length less than or equal to \fIlength\fP. This is equivalent to: @@ -383,7 +423,7 @@ and must be escaped via backslash (\\). [In the case of FDDI (e.g., `\fBfddi protocol arp\fR'), the protocol identification comes from the 802.2 Logical Link Control (LLC) header, which is usually layered on top of the FDDI header. -\fItcpdump\fP assumes, when filtering on the protocol identifier, +\fITcpdump\fP assumes, when filtering on the protocol identifier, that all FDDI packets include an LLC header, and that the LLC header is in so-called SNAP format.] .IP "\fBdecnet src \fIhost\fR" @@ -680,7 +720,7 @@ CSAM RTSG 0806 64: arp reply csam is-at CSAM\fP .fi .RE For the first packet this says the ethernet source address is RTSG, the -destination is the broadcast address, the type field +destination is the ethernet broadcast address, the type field contained hex 0806 (type ETHER_ARP) and the total length was 64 bytes. .HD TCP Packets @@ -860,7 +900,7 @@ RA, \fInot\fP set) and `|' (truncated message, TC, set). If the is printed. .LP Note that name server requests and responses tend to be large and the -default \fIsnaplen\fP of 96 bytes may not capture enough of the packet +default \fIsnaplen\fP of 68 bytes may not capture enough of the packet to print. Use the \fB\-s\fP flag to increase the snaplen if you need to seriously investigate name server traffic. `\fB\-s 128\fP' has worked well for me. @@ -937,7 +977,7 @@ NFS traffic. NFS reply packets do not explicitly identify the RPC operation. Instead, \fItcpdump\fP keeps track of ``recent'' requests, and matches them to the replies using the transaction ID. If a reply does not closely follow the -corresponding request, it might not be parseble. +corresponding request, it might not be parsable. .HD KIP Appletalk (DDP in UDP) .LP @@ -1110,25 +1150,20 @@ is the current clock time in the form \fIhh:mm:ss.frac\fP .fi .RE -and is as accurate as the kernel's clock (e.g., \(+-10ms on a Sun-3). +and is as accurate as the kernel's clock. The timestamp reflects the time the kernel first saw the packet. No attempt is made to account for the time lag between when the ethernet interface removed the packet from the wire and when the kernel -serviced the `new packet' interrupt (of course, -with Sun's lousy clock resolution this time lag is negligible.) +serviced the `new packet' interrupt. .SH "SEE ALSO" -traffic(1C), nit(4P), bpf(4) +traffic(1C), nit(4P), bpf(4), pcap(3) .SH AUTHORS -Van Jacobson (van@helios.ee.lbl.gov), -Craig Leres (leres@helios.ee.lbl.gov) and -Steven McCanne (mccanne@helios.ee.lbl.gov), all of +Van Jacobson (van@ee.lbl.gov), +Craig Leres (leres@ee.lbl.gov) and +Steven McCanne (mccanne@ee.lbl.gov), all of the Lawrence Berkeley Laboratory, University of California, Berkeley, CA. .SH BUGS -The clock resolution on most Suns is pathetic (20ms). -If you want to use the timestamp to generate some of the important -performance distributions (like packet interarrival time) it's best -to watch something that generates packets slowly (like an Arpanet -gateway or a MicroVax running VMS). +Please send bug reports to tcpdump@ee.lbl.gov or libpcap@ee.lbl.gov. .LP NIT doesn't let you watch your own outbound traffic, BPF will. We recommend that you use the latter. diff --git a/usr.sbin/tcpdump/tcpdump.c b/usr.sbin/tcpdump/tcpdump.c index 48285b97ce6..948281fa3c5 100644 --- a/usr.sbin/tcpdump/tcpdump.c +++ b/usr.sbin/tcpdump/tcpdump.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: tcpdump.c,v 1.3 1996/06/10 07:47:58 deraadt Exp $ */ -/* $NetBSD: tcpdump.c,v 1.4.4.1 1996/06/05 18:07:48 cgd Exp $ */ +/* $OpenBSD: tcpdump.c,v 1.4 1996/07/13 11:01:34 mickey Exp $ */ /* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,9 +22,10 @@ */ #ifndef lint char copyright[] = - "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994\nThe Regents of the University of California. All rights reserved.\n"; + "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995\n\ +The Regents of the University of California. All rights reserved.\n"; static char rcsid[] = - "@(#)Header: tcpdump.c,v 1.93 94/06/10 17:01:44 mccanne Exp (LBL)"; + "@(#)Header: tcpdump.c,v 1.109 96/06/22 14:46:37 leres Exp (LBL)"; #endif /* @@ -38,17 +38,19 @@ static char rcsid[] = #include <sys/types.h> #include <sys/time.h> +#ifdef __osf__ +#include <sys/sysinfo.h> +#include <sys/proc.h> +#endif #include <netinet/in.h> #include <pcap.h> #include <signal.h> #include <stdio.h> -#ifdef __STDC__ #include <stdlib.h> -#endif -#include <unistd.h> #include <string.h> +#include <unistd.h> #include "interface.h" #include "addrtoname.h" @@ -70,11 +72,18 @@ int dflag; /* print filter code */ char *program_name; -int thiszone; +int32_t thiszone; /* seconds offset from gmt to local time */ -SIGRET cleanup(int); +/* Externs */ extern void bpf_dump(struct bpf_program *, int); +/* Forwards */ +RETSIGTYPE cleanup(int); +extern __dead void usage(void) __attribute__((volatile)); +#ifdef __osf__ +static void abort_on_misalignment(void); +#endif + /* Length of saved portion of packet. */ int snaplen = DEFAULT_SNAPLEN; @@ -83,12 +92,18 @@ struct printer { int type; }; +/* XXX needed if using old bpf.h */ +#ifndef DLT_ATM_RFC1483 +#define DLT_ATM_RFC1483 11 +#endif + static struct printer printers[] = { { ether_if_print, DLT_EN10MB }, { sl_if_print, DLT_SLIP }, { ppp_if_print, DLT_PPP }, { fddi_if_print, DLT_FDDI }, { null_if_print, DLT_NULL }, + { atm_if_print, DLT_ATM_RFC1483 }, { NULL, 0 }, }; @@ -107,38 +122,33 @@ lookup_printer(int type) static pcap_t *pd; +/* OSF magic */ #ifdef __osf__ -#include <sys/sysinfo.h> -#include <sys/proc.h> -void +static void abort_on_misalignment() { - int buf[2]; - - buf[0] = SSIN_UACPROC; - buf[1] = UAC_SIGBUS; - if (setsysinfo(SSI_NVPAIRS, buf, 1, 0, 0) < 0) { - perror("setsysinfo"); - exit(1); - } -} + static int buf[2] = { SSIN_UACPROC, UAC_SIGBUS }; + if (setsysinfo(SSI_NVPAIRS, (caddr_t)buf, 1, 0, 0) < 0) + error("setsysinfo: %s", pcap_strerror(errno)); +} #endif +extern int optind; +extern int opterr; +extern char *optarg; + int main(int argc, char **argv) { - register int cnt, op; - u_int32_t localnet, netmask; + register int cnt, op, i; + bpf_u_int32 localnet, netmask; register char *cp, *infile, *cmdbuf, *device, *RFileName, *WFileName; pcap_handler printer; struct bpf_program fcode; u_char *pcap_userdata; char errbuf[PCAP_ERRBUF_SIZE]; - extern char *optarg; - extern int optind, opterr; - #ifdef __osf__ abort_on_misalignment(); #endif @@ -181,7 +191,11 @@ main(int argc, char **argv) break; case 'l': +#ifdef HAVE_SETLINEBUF setlinebuf(stdout); +#else + setvbuf(stdout, NULL, _IOLBF, 0); +#endif break; case 'n': @@ -222,13 +236,15 @@ main(int argc, char **argv) case 'T': if (strcasecmp(optarg, "vat") == 0) - packettype = 1; + packettype = PT_VAT; else if (strcasecmp(optarg, "wb") == 0) - packettype = 2; + packettype = PT_WB; else if (strcasecmp(optarg, "rpc") == 0) - packettype = 3; + packettype = PT_RPC; else if (strcasecmp(optarg, "rtp") == 0) - packettype = 4; + packettype = PT_RTP; + else if (strcasecmp(optarg, "rtcp") == 0) + packettype = PT_RTCP; else error("unknown packet type `%s'", optarg); break; @@ -243,6 +259,7 @@ main(int argc, char **argv) #ifdef YYDEBUG case 'Y': { + /* Undocumented flag */ extern int yydebug; yydebug = 1; } @@ -284,6 +301,11 @@ main(int argc, char **argv) pd = pcap_open_live(device, snaplen, !pflag, 1000, errbuf); if (pd == NULL) error(errbuf); + i = pcap_snapshot(pd); + if (snaplen < i) { + warning("snaplen raised from %d to %d", snaplen, i); + snaplen = i; + } if (pcap_lookupnet(device, &localnet, &netmask, errbuf) < 0) error(errbuf); /* @@ -296,6 +318,10 @@ main(int argc, char **argv) else cmdbuf = copy_argv(&argv[optind]); + /* XXX padding only needed for kernel fcode */ + if (RFileName != NULL) + pcap_fddipad = 0; + if (pcap_compile(pd, &fcode, cmdbuf, Oflag, netmask) < 0) error(pcap_geterr(pd)); if (dflag) { @@ -321,11 +347,12 @@ main(int argc, char **argv) pcap_userdata = 0; } if (RFileName == NULL) { - fprintf(stderr, "%s: listening on %s\n", program_name, device); - fflush(stderr); + (void)fprintf(stderr, "%s: listening on %s\n", + program_name, device); + (void)fflush(stderr); } if (pcap_loop(pd, cnt, printer, pcap_userdata) < 0) { - (void)fprintf(stderr, "%s: pcap_loop %s\n", + (void)fprintf(stderr, "%s: pcap_loop: %s\n", program_name, pcap_geterr(pd)); exit(1); } @@ -334,7 +361,7 @@ main(int argc, char **argv) } /* make a clean exit on interrupts */ -SIGRET +RETSIGTYPE cleanup(int signo) { struct pcap_stat stat; @@ -404,15 +431,17 @@ default_print(register const u_char *bp, register int length) } } -void +__dead void usage() { extern char version[]; (void)fprintf(stderr, "Version %s\n", version); (void)fprintf(stderr, -"Usage: tcpdump [-deflnOpqtvx] [-c count] [-i interface]\n"); +"Usage: tcpdump [-deflnNOpqStvx] [-c count] [ -F file ]\n"); + (void)fprintf(stderr, +"\t\t[ -i interface ] [ -r file ] [ -s snaplen ]\n"); (void)fprintf(stderr, -"\t\t[-r filename] [-w filename] [expr]\n"); +"\t\t[ -T type ] [ -w file ] [ expression ]\n"); exit(-1); } diff --git a/usr.sbin/tcpdump/util.c b/usr.sbin/tcpdump/util.c index 9ae7f4bcf10..6fea5b7652c 100644 --- a/usr.sbin/tcpdump/util.c +++ b/usr.sbin/tcpdump/util.c @@ -1,8 +1,7 @@ -/**//* $OpenBSD: util.c,v 1.3 1996/06/10 07:47:59 deraadt Exp $ */ -/* $NetBSD: util.c,v 1.5 1996/05/20 00:41:19 fvdl Exp $ */ +/* $OpenBSD: util.c,v 1.4 1996/07/13 11:01:35 mickey Exp $ */ /* - * Copyright (c) 1990, 1991, 1993, 1994 + * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,29 +23,29 @@ #ifndef lint static char rcsid[] = - "@(#) Header: util.c,v 1.28+ 94/06/12 14:30:31 leres Exp (LBL)"; + "@(#) Header: util.c,v 1.48 96/06/23 02:26:42 leres Exp (LBL)"; #endif -#include <stdlib.h> #include <sys/types.h> #include <sys/time.h> #include <sys/file.h> #include <sys/stat.h> #include <ctype.h> -#ifdef SVR4 +#ifdef HAVE_FCNTL_H #include <fcntl.h> #endif -#ifdef __STDC__ -#include <stdlib.h> -#endif #include <stdio.h> #if __STDC__ #include <stdarg.h> #else #include <varargs.h> #endif +#include <stdlib.h> #include <string.h> +#ifdef TIME_WITH_SYS_TIME +#include <time.h> +#endif #include <unistd.h> #include "interface.h" @@ -127,16 +126,16 @@ void ts_print(register const struct timeval *tvp) { register int s; - extern int32 thiszone; if (tflag > 0) { /* Default */ s = (tvp->tv_sec + thiszone) % 86400; - (void)printf("%02d:%02d:%02d.%06d ", - s / 3600, (s % 3600) / 60, s % 60, tvp->tv_usec); + (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("%d.%06d ", tvp->tv_sec, tvp->tv_usec); + (void)printf("%u.%06u ", + (u_int32_t)tvp->tv_sec, (u_int32_t)tvp->tv_usec); } } @@ -144,7 +143,7 @@ ts_print(register const struct timeval *tvp) * Convert a token value to a string; use "fmt" if not found. */ const char * -tok2str(register const struct token *lp, register const char *fmt, +tok2str(register const struct tok *lp, register const char *fmt, register int v) { static char buf[128]; @@ -160,61 +159,14 @@ tok2str(register const struct token *lp, register const char *fmt, return (buf); } -/* A replacement for strdup() that cuts down on malloc() overhead */ -char * -savestr(register const char *str) -{ - register u_int size; - register char *p; - static char *strptr = NULL; - static u_int strsize = 0; - - size = strlen(str) + 1; - if (size > strsize) { - strsize = 1024; - if (strsize < size) - strsize = size; - strptr = (char *)malloc(strsize); - if (strptr == NULL) - error("savestr: malloc"); - } - (void)strcpy(strptr, str); - p = strptr; - strptr += size; - strsize -= size; - return (p); -} - -#ifdef NOVFPRINTF -/* - * Stock 4.3 doesn't have vfprintf. - * This routine is due to Chris Torek. - */ -vfprintf(f, fmt, args) - FILE *f; - char *fmt; - va_list args; -{ - int ret; - - if ((f->_flag & _IOWRT) == 0) { - if (f->_flag & _IORW) - f->_flag |= _IOWRT; - else - return EOF; - } - ret = _doprnt(fmt, args, f); - return ferror(f) ? EOF : ret; -} -#endif /* VARARGS */ __dead void -#if __STDC__ || defined(SOLARIS) -error(char *fmt, ...) +#if __STDC__ +error(const char *fmt, ...) #else error(fmt, va_alist) - char *fmt; + const char *fmt; va_dcl #endif { @@ -239,11 +191,11 @@ error(fmt, va_alist) /* VARARGS */ void -#if __STDC__ || defined(SOLARIS) -warning(char *fmt, ...) +#if __STDC__ +warning(const char *fmt, ...) #else warning(fmt, va_alist) - char *fmt; + const char *fmt; va_dcl #endif { @@ -283,6 +235,8 @@ copy_argv(register char **argv) len += strlen(*p++) + 1; buf = (char *)malloc(len); + if (buf == NULL) + error("copy_argv: malloc"); p = argv; dst = buf; @@ -296,6 +250,32 @@ copy_argv(register char **argv) return buf; } +/* A replacement for strdup() that cuts down on malloc() overhead */ +char * +savestr(register const char *str) +{ + register u_int size; + register char *p; + static char *strptr = NULL; + static u_int strsize = 0; + + size = strlen(str) + 1; + if (size > strsize) { + strsize = 1024; + if (strsize < size) + strsize = size; + strptr = (char *)malloc(strsize); + if (strptr == NULL) + error("savestr: malloc"); + } + (void)strcpy(strptr, str); + p = strptr; + strptr += size; + strsize -= size; + return (p); +} + + char * read_infile(char *fname) { @@ -308,37 +288,55 @@ read_infile(char *fname) error("can't open '%s'", fname); if (fstat(fd, &buf) < 0) - error("can't state '%s'", fname); + error("can't stat '%s'", fname); - p = (char *)malloc((u_int)buf.st_size); + p = malloc((u_int)buf.st_size + 1); + if (p == NULL) + error("read_infile: malloc"); if (read(fd, p, (int)buf.st_size) != buf.st_size) error("problem reading '%s'", fname); + p[(int)buf.st_size] = '\0'; + return p; } -int +int32_t gmt2local() { -#ifndef SVR4 + register int t; +#if !defined(HAVE_ALTZONE) && !defined(HAVE_TIMEZONE) struct timeval tv; struct timezone tz; register struct tm *tm; - register int t; +#endif + t = 0; +#if !defined(HAVE_ALTZONE) && !defined(HAVE_TIMEZONE) if (gettimeofday(&tv, &tz) < 0) error("gettimeofday"); tm = localtime((time_t *)&tv.tv_sec); -#ifndef SUNOS3 +#ifdef HAVE_TM_GMTOFF t = tm->tm_gmtoff; #else t = tz.tz_minuteswest * -60; + /* XXX Some systems need this, some auto offset tz_minuteswest... */ if (tm->tm_isdst) - t += 3600; + t += 60 * 60; #endif - return (t); -#else +#endif + +#ifdef HAVE_TIMEZONE tzset(); - return (-altzone); + t = -timezone; + if (daylight) + t += 60 * 60; #endif + +#ifdef HAVE_ALTZONE + tzset(); + t = -altzone; +#endif + + return (t); } diff --git a/usr.sbin/tcpdump/version.c b/usr.sbin/tcpdump/version.c index 630a3f34aaa..51a2b5780b6 100644 --- a/usr.sbin/tcpdump/version.c +++ b/usr.sbin/tcpdump/version.c @@ -1,4 +1,4 @@ -/**//* $OpenBSD: version.c,v 1.3 1996/06/10 07:48:00 deraadt Exp $ */ +/* $OpenBSD: version.c,v 1.4 1996/07/13 11:01:35 mickey Exp $ */ /* $NetBSD: version.c,v 1.3 1996/05/20 00:41:20 fvdl Exp $ */ -char version[] = "3.0.4"; +char version[] = "3.2.0"; |