diff options
-rw-r--r-- | usr.sbin/tcpdump/interface.h | 6 | ||||
-rw-r--r-- | usr.sbin/tcpdump/print-ether.c | 20 | ||||
-rw-r--r-- | usr.sbin/tcpdump/print-etherip.c | 28 | ||||
-rw-r--r-- | usr.sbin/tcpdump/print-ip.c | 7 |
4 files changed, 39 insertions, 22 deletions
diff --git a/usr.sbin/tcpdump/interface.h b/usr.sbin/tcpdump/interface.h index 885aaecfb04..c126e09895d 100644 --- a/usr.sbin/tcpdump/interface.h +++ b/usr.sbin/tcpdump/interface.h @@ -1,4 +1,4 @@ -/* $OpenBSD: interface.h,v 1.53 2006/05/23 14:20:19 stevesk Exp $ */ +/* $OpenBSD: interface.h,v 1.54 2006/06/01 17:18:38 moritz Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 @@ -20,7 +20,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/interface.h,v 1.53 2006/05/23 14:20:19 stevesk Exp $ (LBL) + * @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/interface.h,v 1.54 2006/06/01 17:18:38 moritz Exp $ (LBL) */ #ifndef tcpdump_interface_h @@ -271,7 +271,7 @@ extern void stp_print(const u_char *, u_int); extern void radius_print(const u_char *, u_int); extern void lwres_print(const u_char *, u_int); extern void ether_print(const u_char *, u_int); -extern void etherip_print(const u_char *, u_int, const u_char *); +extern void etherip_print(const u_char *, u_int, u_int, const u_char *); extern void ipcomp_print(const u_char *, u_int, const u_char *); extern void mpls_print(const u_char *, u_int); extern void lldp_print(const u_char *, u_int); diff --git a/usr.sbin/tcpdump/print-ether.c b/usr.sbin/tcpdump/print-ether.c index c8f1934680c..f5c7d38bf27 100644 --- a/usr.sbin/tcpdump/print-ether.c +++ b/usr.sbin/tcpdump/print-ether.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-ether.c,v 1.21 2006/03/28 15:48:33 reyk Exp $ */ +/* $OpenBSD: print-ether.c,v 1.22 2006/06/01 17:18:39 moritz Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 @@ -22,7 +22,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ether.c,v 1.21 2006/03/28 15:48:33 reyk Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ether.c,v 1.22 2006/06/01 17:18:39 moritz Exp $ (LBL)"; #endif #include <sys/param.h> @@ -65,17 +65,23 @@ ether_print(register const u_char *bp, u_int length) register const struct ether_header *ep; ep = (const struct ether_header *)bp; - if (qflag) + if (qflag) { + TCHECK2(*ep, 12); (void)printf("%s %s %d: ", etheraddr_string(ESRC(ep)), etheraddr_string(EDST(ep)), length); - else + } else { + TCHECK2(*ep, 14); (void)printf("%s %s %s %d: ", etheraddr_string(ESRC(ep)), etheraddr_string(EDST(ep)), etherproto_string(ep->ether_type), length); + } + return; +trunc: + printf("[|ether] "); } u_short extracted_ethertype; @@ -101,9 +107,6 @@ ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) goto out; } - if (eflag) - ether_print(p, length); - /* * Some printers want to get back at the ethernet addresses, * and/or check that they're not walking off the end of the packet. @@ -112,6 +115,9 @@ ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) packetp = p; snapend = p + caplen; + if (eflag) + ether_print(p, length); + length -= sizeof(struct ether_header); caplen -= sizeof(struct ether_header); ep = (struct ether_header *)p; diff --git a/usr.sbin/tcpdump/print-etherip.c b/usr.sbin/tcpdump/print-etherip.c index 653dbf655bb..0c3faa1a108 100644 --- a/usr.sbin/tcpdump/print-etherip.c +++ b/usr.sbin/tcpdump/print-etherip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-etherip.c,v 1.3 2006/05/29 18:05:22 moritz Exp $ */ +/* $OpenBSD: print-etherip.c,v 1.4 2006/06/01 17:18:39 moritz Exp $ */ /* * Copyright (c) 2001 Jason L. Wright (jason@thought.net) @@ -32,7 +32,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-etherip.c,v 1.3 2006/05/29 18:05:22 moritz Exp $"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-etherip.c,v 1.4 2006/06/01 17:18:39 moritz Exp $"; #endif #include <sys/param.h> @@ -64,12 +64,12 @@ static const char rcsid[] = extern u_short extracted_ethertype; void -etherip_print(const u_char *bp, u_int len, const u_char *bp2) +etherip_print(const u_char *bp, u_int caplen, u_int len, const u_char *bp2) { const struct ip *ip = (const struct ip *)bp2; struct ether_header *eh; const u_char *pbuf = bp; - u_int plen = len, hlen; + u_int plen = caplen, hlen; u_int16_t etype; if (plen < sizeof(struct etherip_header)) { @@ -100,22 +100,32 @@ etherip_print(const u_char *bp, u_int len, const u_char *bp2) printf(": "); + if (plen < hlen) { + printf("[|etherip]"); + return; + } pbuf += hlen; plen -= hlen; + len -= hlen; if (eflag) - ether_print(pbuf, plen); + ether_print(pbuf, len); eh = (struct ether_header *)pbuf; + if (plen < sizeof(struct ether_header)) { + printf("[|ether]"); + return; + } etype = EXTRACT_16BITS(pbuf + offsetof(struct ether_header, ether_type)); pbuf += sizeof(struct ether_header); plen -= sizeof(struct ether_header); + len -= sizeof(struct ether_header); /* XXX LLC? */ extracted_ethertype = 0; if (etype <= ETHERMTU) { - if (llc_print(pbuf, plen, plen, ESRC(eh), EDST(eh)) == 0) { + if (llc_print(pbuf, len, plen, ESRC(eh), EDST(eh)) == 0) { if (!eflag) - ether_print((u_char *)eh, plen); + ether_print((u_char *)eh, len); if (extracted_ethertype) { printf("LLC %s", etherproto_string(htons(extracted_ethertype))); @@ -123,9 +133,9 @@ etherip_print(const u_char *bp, u_int len, const u_char *bp2) if (!xflag && !qflag) default_print(pbuf, plen); } - } else if (ether_encap_print(etype, pbuf, plen, plen) == 0) { + } else if (ether_encap_print(etype, pbuf, len, plen) == 0) { if (!eflag) - ether_print((u_char *)eh, plen + sizeof(*eh)); + ether_print((u_char *)eh, len + sizeof(*eh)); if (!xflag && !qflag) default_print(pbuf, plen); } diff --git a/usr.sbin/tcpdump/print-ip.c b/usr.sbin/tcpdump/print-ip.c index f0d9d4f40c4..685959f11de 100644 --- a/usr.sbin/tcpdump/print-ip.c +++ b/usr.sbin/tcpdump/print-ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-ip.c,v 1.31 2006/05/29 20:41:41 moritz Exp $ */ +/* $OpenBSD: print-ip.c,v 1.32 2006/06/01 17:18:39 moritz Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ip.c,v 1.31 2006/05/29 20:41:41 moritz Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ip.c,v 1.32 2006/06/01 17:18:39 moritz Exp $ (LBL)"; #endif #include <sys/param.h> @@ -542,7 +542,8 @@ ip_print(register const u_char *bp, register u_int length) #define IPPROTO_ETHERIP 97 #endif case IPPROTO_ETHERIP: - etherip_print(cp, len, (const u_char *)ip); + etherip_print(cp, snapend - cp, len, + (const u_char *)ip); break; #ifndef IPPROTO_IPCOMP |