From dfd1ee14ffdc2b29c05331d274a419f5469c1efe Mon Sep 17 00:00:00 2001 From: Bill Fenner Date: Tue, 15 Sep 1998 19:31:43 +0000 Subject: [PATCH] Merge libpcap version 0.4 PR: bin/7877 --- contrib/libpcap/gencode.c | 54 +++++++++++++++++++++++++++++++++--- contrib/libpcap/nametoaddr.c | 6 ++-- contrib/libpcap/pcap.3 | 42 ++++++++++++++++++++-------- contrib/libpcap/pcap.h | 8 +++--- contrib/libpcap/scanner.l | 13 +++++---- 5 files changed, 95 insertions(+), 28 deletions(-) diff --git a/contrib/libpcap/gencode.c b/contrib/libpcap/gencode.c index e758c7191d71..b966e3ef2fab 100644 --- a/contrib/libpcap/gencode.c +++ b/contrib/libpcap/gencode.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996 + * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -20,7 +20,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: gencode.c,v 1.91 96/12/11 19:10:23 leres Exp $ (LBL)"; + "@(#) $Header: gencode.c,v 1.94 98/07/12 13:06:49 leres Exp $ (LBL)"; #endif #include @@ -52,6 +52,7 @@ struct rtentry; #include "ethertype.h" #include "nlpid.h" #include "gencode.h" +#include "ppp.h" #include #include "gnuc.h" @@ -475,6 +476,13 @@ init_linktype(type) off_nl = 16; return; + case DLT_SLIP_BSDOS: + /* XXX this may be the same as the DLT_PPP_BSDOS case */ + off_linktype = -1; + /* XXX end */ + off_nl = 24; + return; + case DLT_NULL: off_linktype = 0; off_nl = 4; @@ -485,6 +493,11 @@ init_linktype(type) off_nl = 4; return; + case DLT_PPP_BSDOS: + off_linktype = 5; + off_nl = 24; + return; + case DLT_FDDI: /* * FDDI doesn't really have a link-level type field. @@ -553,8 +566,10 @@ gen_false() static struct block * gen_linktype(proto) - int proto; + register int proto; { + struct block *b0, *b1; + /* If we're not using encapsulation and checking for IP, we're done */ if (off_linktype == -1 && proto == ETHERTYPE_IP) return gen_true(); @@ -566,7 +581,32 @@ gen_linktype(proto) case DLT_PPP: if (proto == ETHERTYPE_IP) - proto = 0x0021; /* XXX - need ppp.h defs */ + proto = PPP_IP; /* XXX was 0x21 */ + break; + + case DLT_PPP_BSDOS: + switch (proto) { + + case ETHERTYPE_IP: + b0 = gen_cmp(off_linktype, BPF_H, PPP_IP); + b1 = gen_cmp(off_linktype, BPF_H, PPP_VJC); + gen_or(b0, b1); + b0 = gen_cmp(off_linktype, BPF_H, PPP_VJNC); + gen_or(b1, b0); + return b0; + + case ETHERTYPE_DN: + proto = PPP_DECNET; + break; + + case ETHERTYPE_ATALK: + proto = PPP_APPLE; + break; + + case ETHERTYPE_NS: + proto = PPP_NS; + break; + } break; case DLT_NULL: @@ -1374,11 +1414,17 @@ gen_mcode(s1, s2, masklen, q) mlen = __pcap_atoin(s2, &m); /* Promote short ipaddr */ m <<= 32 - mlen; + if ((n & ~m) != 0) + bpf_error("non-network bits set in \"%s mask %s\"", + s1, s2); } else { /* Convert mask len to mask */ if (masklen > 32) bpf_error("mask length must be <= 32"); m = 0xffffffff << (32 - masklen); + if ((n & ~m) != 0) + bpf_error("non-network bits set in \"%s/%d\"", + s1, masklen); } switch (q.addr) { diff --git a/contrib/libpcap/nametoaddr.c b/contrib/libpcap/nametoaddr.c index fc17a30ed85c..7b744c8a8d56 100644 --- a/contrib/libpcap/nametoaddr.c +++ b/contrib/libpcap/nametoaddr.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996 + * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,7 +24,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: nametoaddr.c,v 1.45 96/10/17 23:26:53 leres Exp $ (LBL)"; + "@(#) $Header: nametoaddr.c,v 1.48 98/07/12 13:15:36 leres Exp $ (LBL)"; #endif #include @@ -345,7 +345,7 @@ pcap_ether_hostton(const char *name) if (ether_hostton((char *)name, (struct ether_addr *)a) == 0) { ap = (u_char *)malloc(6); if (ap != NULL) - memcpy(ap, a, 6); + memcpy((char *)ap, (char *)a, 6); } return (ap); } diff --git a/contrib/libpcap/pcap.3 b/contrib/libpcap/pcap.3 index fae0c0ef5aa9..6c1eaeadd962 100644 --- a/contrib/libpcap/pcap.3 +++ b/contrib/libpcap/pcap.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 1994, 1996 +.\" Copyright (c) 1994, 1996, 1997 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -19,7 +19,7 @@ .\" .\" $Id$ .\" -.TH PCAP 3 "18 August 1996" +.TH PCAP 3 "24 June 1998" .SH NAME pcap \- Packet Capture library .SH SYNOPSIS @@ -39,9 +39,9 @@ pcap_dumper_t *pcap_dump_open(pcap_t *p, char *fname) .ft B char errbuf[PCAP_ERRBUF_SIZE]; char *pcap_lookupdev(char *errbuf) -int pcap_lookupnet(char *device, u_long *netp, +int pcap_lookupnet(char *device, bpf_u_int32 *netp, .ti +8 -u_long *maskp, char *errbuf) +bpf_u_int32 *maskp, char *errbuf) .ft .LP .ft B @@ -59,7 +59,7 @@ u_char *sp) .ft B int pcap_compile(pcap_t *p, struct bpf_program *fp, .ti +8 -char *str, int optimize, u_long netmask) +char *str, int optimize, bpf_u_int32 netmask) int pcap_setfilter(pcap_t *p, struct bpf_program *fp) .ft .LP @@ -100,6 +100,10 @@ at packets on the network. is a string that specifies the network device to open. .I snaplen specifies the maximum number of bytes to capture. +.I promisc +specifies if the interface is to be put into promiscuous mode. +(Note that even if this parameter is false, the interface +could well be in promiscuous mode for some other reason.) .I to_ms specifies the read timeout in milliseconds. .I ebuf @@ -165,7 +169,7 @@ Both and .I maskp are -.I u_long +.I bpf_u_int32 pointers. A return of -1 indicates an error in which case .I errbuf @@ -178,9 +182,10 @@ specifies the maximum number of packets to process before returning. A .I cnt of -1 processes all the packets received in one buffer. A .I cnt -of 0 processes all packets until an error occurs (or +of 0 processes all packets until an error occurs, .B EOF -is reached). +is reached, or the read times out (when doing live reads and a non-zero +read timeout is specified). .I callback specifies a routine to be called with three arguments: a @@ -190,7 +195,9 @@ pointer which is passed in from a pointer to the .I pcap_pkthdr struct (which precede the actual network headers and data), -and a length. The number of packets read is returned. +and a +.I u_char +pointer to the packet data. The number of packets read is returned. Zero is returned when .B EOF is reached in a ``savefile.'' A return of -1 indicates @@ -221,12 +228,16 @@ controls whether optimization on the resulting code is performed. specifies the netmask of the local net. .PP .B pcap_setfilter() -is used to specify the a filter program. +is used to specify a filter program. .I fp is a pointer to an array of .I bpf_program struct, usually the result of a call to .BR pcap_compile() . +.B \-1 +is returned on failure; +.B 0 +is returned on success. .PP .B pcap_loop() is similar to @@ -234,6 +245,15 @@ is similar to except it keeps reading packets until .I cnt packets are processed or an error occurs. +It does +.B not +return when live read timeouts occur. +Rather, specifying a non-zero read timeout to +.B pcap_open_live() +and then calling +.B pcap_dispatch() +allows the reception and processing of any packets that arrive when the +timeout occurs. A negative .I cnt causes @@ -263,7 +283,7 @@ returns the major number of the version of the pcap used to write the savefile. .PP .B pcap_minor_version() -returns the major number of the version of the pcap used to write the +returns the minor number of the version of the pcap used to write the savefile. .PP .B pcap_file() diff --git a/contrib/libpcap/pcap.h b/contrib/libpcap/pcap.h index 8180ce9d4ebb..0c8608028aa5 100644 --- a/contrib/libpcap/pcap.h +++ b/contrib/libpcap/pcap.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1993, 1994, 1995, 1996 + * Copyright (c) 1993, 1994, 1995, 1996, 1997 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#) $Header: pcap.h,v 1.20 96/07/12 19:24:15 leres Exp $ (LBL) + * @(#) $Header: pcap.h,v 1.21 97/10/15 21:59:13 leres Exp $ (LBL) */ #ifndef lib_pcap_h @@ -107,7 +107,7 @@ typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *, char *pcap_lookupdev(char *); int pcap_lookupnet(char *, bpf_u_int32 *, bpf_u_int32 *, char *); pcap_t *pcap_open_live(char *, int, int, int, char *); -pcap_t *pcap_open_offline(char *, char *); +pcap_t *pcap_open_offline(const char *, char *); void pcap_close(pcap_t *); int pcap_loop(pcap_t *, int, pcap_handler, u_char *); int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *); @@ -132,7 +132,7 @@ int pcap_minor_version(pcap_t *); FILE *pcap_file(pcap_t *); int pcap_fileno(pcap_t *); -pcap_dumper_t *pcap_dump_open(pcap_t *, char *); +pcap_dumper_t *pcap_dump_open(pcap_t *, const char *); void pcap_dump_close(pcap_dumper_t *); void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *); diff --git a/contrib/libpcap/scanner.l b/contrib/libpcap/scanner.l index 8caa830467a2..a76491c9a35b 100644 --- a/contrib/libpcap/scanner.l +++ b/contrib/libpcap/scanner.l @@ -1,6 +1,6 @@ %{ /* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996 + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -22,7 +22,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: scanner.l,v 1.55 96/09/27 22:34:45 leres Exp $ (LBL)"; + "@(#) $Header: scanner.l,v 1.56 97/07/21 13:31:50 leres Exp $ (LBL)"; #endif #include @@ -139,14 +139,15 @@ outbound return OUTBOUND; ">>" return RSH; {N} { yylval.i = stoi((char *)yytext); return NUM; } ({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) { - yylval.s = sdup((char *)yytext); return HID; -} + yylval.s = sdup((char *)yytext); return HID; } {B}:{B}:{B}:{B}:{B}:{B} { yylval.e = pcap_ether_aton((char *)yytext); return EID; } {B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); } -[A-Za-z][-_.A-Za-z0-9]* { yylval.s = sdup((char *)yytext); return ID; } +[A-Za-z0-9][-_.A-Za-z0-9]*[.A-Za-z0-9] { + yylval.s = sdup((char *)yytext); return ID; } "\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; } -[^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+ { bpf_error("illegal token: %s\n", yytext); } +[^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+i { + bpf_error("illegal token: %s\n", yytext); } . { bpf_error("illegal char '%c'", *yytext); } %% void