diff options
author | Brad Smith <brad@cvs.openbsd.org> | 2004-05-21 05:48:51 +0000 |
---|---|---|
committer | Brad Smith <brad@cvs.openbsd.org> | 2004-05-21 05:48:51 +0000 |
commit | 575b9073ba7f2eccb9c3e704f7d25d6f304cea5f (patch) | |
tree | 3eb29361225f1c1fea1babfde7d5f998e77d1176 | |
parent | 96257ff6f7b7d8640dc8c29aed1d395db677a0b3 (diff) |
add DLT_PPP_ETHER support plus some fixes for pppoe_if_print().
ok canacar@
From: Marc Huber <pppoe at pro-bono-publico dot de>
-rw-r--r-- | usr.sbin/tcpdump/interface.h | 6 | ||||
-rw-r--r-- | usr.sbin/tcpdump/print-ppp.c | 127 | ||||
-rw-r--r-- | usr.sbin/tcpdump/tcpdump.c | 5 |
3 files changed, 125 insertions, 13 deletions
diff --git a/usr.sbin/tcpdump/interface.h b/usr.sbin/tcpdump/interface.h index f779ad9433d..5d2593d8aff 100644 --- a/usr.sbin/tcpdump/interface.h +++ b/usr.sbin/tcpdump/interface.h @@ -1,4 +1,4 @@ -/* $OpenBSD: interface.h,v 1.44 2004/04/28 02:17:03 mcbride Exp $ */ +/* $OpenBSD: interface.h,v 1.45 2004/05/21 05:48:50 brad 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.44 2004/04/28 02:17:03 mcbride Exp $ (LBL) + * @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/interface.h,v 1.45 2004/05/21 05:48:50 brad Exp $ (LBL) */ #ifndef tcpdump_interface_h @@ -205,6 +205,8 @@ extern void pfsync_ip_print(const u_char *, u_int, 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 *); +extern void ppp_ether_if_print(u_char *, const struct pcap_pkthdr *, + const u_char *); extern void gre_print(const u_char *, u_int); extern void icmp_print(const u_char *, const u_char *); extern void igrp_print(const u_char *, u_int, const u_char *); diff --git a/usr.sbin/tcpdump/print-ppp.c b/usr.sbin/tcpdump/print-ppp.c index 697c2523cad..ae006173925 100644 --- a/usr.sbin/tcpdump/print-ppp.c +++ b/usr.sbin/tcpdump/print-ppp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-ppp.c,v 1.14 2002/02/19 19:39:40 millert Exp $ */ +/* $OpenBSD: print-ppp.c,v 1.15 2004/05/21 05:48:50 brad Exp $ */ /* * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997 @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ppp.c,v 1.14 2002/02/19 19:39:40 millert Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ppp.c,v 1.15 2004/05/21 05:48:50 brad Exp $ (LBL)"; #endif #ifdef PPP @@ -563,6 +563,115 @@ out: putchar('\n'); } +void +ppp_ether_if_print(user, h, p) + u_char *user; + const struct pcap_pkthdr *h; + register const u_char *p; +{ + u_int16_t pppoe_sid, pppoe_len; + u_int caplen = h->caplen; + u_int16_t length = h->len; + u_int16_t proto; + int i; + + ts_print(&h->ts); + + packetp = p; + snapend = p + caplen; + + if (eflag) + printf("PPPoE "); + + if (caplen < sizeof(struct pppoe_header)) { + printf("[|pppoe]"); + return; + } + + if(eflag) + { + printf("\n\tcode "); + switch (p[1]) { + case PPPOE_CODE_PADI: + printf("Initiation"); + break; + case PPPOE_CODE_PADO: + printf("Offer"); + break; + case PPPOE_CODE_PADR: + printf("Request"); + break; + case PPPOE_CODE_PADS: + printf("Confirm"); + break; + case PPPOE_CODE_PADT: + printf("Terminate"); + break; + case PPPOE_CODE_SESSION: + printf("Session"); + break; + default: + printf("Unknown(0x%02x)", p[1]); + break; + } + } + + pppoe_sid = EXTRACT_16BITS(p + 2); + pppoe_len = EXTRACT_16BITS(p + 4); + + if(eflag) + printf(", version %d, type %d, id 0x%04x, length %d", + (p[0] & 0xf), (p[0] & 0xf0) >> 4, pppoe_sid, pppoe_len); + + length -= sizeof(struct pppoe_header); + caplen -= sizeof(struct pppoe_header); + p += sizeof(struct pppoe_header); + + if (pppoe_len > caplen) + pppoe_len = caplen; + + if (pppoe_len < 2) { + printf("[|pppoe]"); + return; + } + proto = EXTRACT_16BITS(p); + + for (i = sizeof(protonames)/sizeof(protonames[0]) - 1; i >= 0; i--) { + if (proto == protonames[i].protocol) { + if (eflag) + printf("\n\t%s: ", protonames[i].name); + switch (proto) { + case PPP_LCP: + handle_lcp(p - 2, length + 2); + break; + case PPP_CHAP: + handle_chap(p - 2, length + 2); + break; + case PPP_PAP: + handle_pap(p - 2, length + 2); + break; + case PPP_IPCP: + handle_ipcp(p - 2, length + 2); + break; + case PPP_IP: + ip_print(p + 2, length - 2); + break; + case PPP_IPX: + ipx_print(p + 2, length - 2); + } + break; + } + } + if (i < 0) + printf("\n\t%04x: ", proto); + + if (xflag) + default_print((const u_char *) + (p + sizeof(struct pppoe_header)), + caplen - sizeof(struct pppoe_header)); + putchar('\n'); +} + int pppoe_if_print(ethertype, p, length, caplen) u_short ethertype; @@ -576,7 +685,7 @@ pppoe_if_print(ethertype, p, length, caplen) else printf("PPPoE-Session"); - if (length < sizeof(sizeof(struct pppoe_header))) { + if (caplen < sizeof(struct pppoe_header)) { printf("[|pppoe]"); return (1); } @@ -702,22 +811,22 @@ pppoe_if_print(ethertype, p, length, caplen) printf("\n\t%s: ", protonames[i].name); switch (proto) { case PPP_LCP: - handle_lcp(p - 2, pppoe_len + 2); + handle_lcp(p - 2, length + 2); break; case PPP_CHAP: - handle_chap(p - 2, pppoe_len + 2); + handle_chap(p - 2, length + 2); break; case PPP_PAP: - handle_pap(p - 2, pppoe_len + 2); + handle_pap(p - 2, length + 2); break; case PPP_IPCP: - handle_ipcp(p - 2, pppoe_len + 2); + handle_ipcp(p - 2, length + 2); break; case PPP_IP: - ip_print(p + 2, pppoe_len - 2); + ip_print(p + 2, length - 2); break; case PPP_IPX: - ipx_print(p + 2, pppoe_len - 2); + ipx_print(p + 2, length - 2); } break; } diff --git a/usr.sbin/tcpdump/tcpdump.c b/usr.sbin/tcpdump/tcpdump.c index 38768b88fb5..11327029c56 100644 --- a/usr.sbin/tcpdump/tcpdump.c +++ b/usr.sbin/tcpdump/tcpdump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcpdump.c,v 1.36 2004/04/28 02:17:03 mcbride Exp $ */ +/* $OpenBSD: tcpdump.c,v 1.37 2004/05/21 05:48:50 brad Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 @@ -26,7 +26,7 @@ static const char copyright[] = "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997\n\ The Regents of the University of California. All rights reserved.\n"; static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/tcpdump.c,v 1.36 2004/04/28 02:17:03 mcbride Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/tcpdump.c,v 1.37 2004/05/21 05:48:50 brad Exp $ (LBL)"; #endif /* @@ -122,6 +122,7 @@ static struct printer printers[] = { { pflog_if_print, DLT_PFLOG }, { pflog_old_if_print, DLT_OLD_PFLOG }, { pfsync_if_print, DLT_PFSYNC }, + { ppp_ether_if_print, DLT_PPP_ETHER }, { NULL, 0 }, }; |