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/tcpdump.c | |
parent | 3b13e49cceec57c39e28d4263a3b3e19421dd2ea (diff) |
it is 3.2 now.
Diffstat (limited to 'usr.sbin/tcpdump/tcpdump.c')
-rw-r--r-- | usr.sbin/tcpdump/tcpdump.c | 105 |
1 files changed, 67 insertions, 38 deletions
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); } |