X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/6b33165a8fc70eac6dae78d230ed42f8684e03ff..ad6df73f5a6c46a409c7629f5588b1b81dff6357:/print-ppp.c diff --git a/print-ppp.c b/print-ppp.c index e66717ec..59789853 100644 --- a/print-ppp.c +++ b/print-ppp.c @@ -31,7 +31,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.48 2000-09-24 08:08:56 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.66 2002-05-29 10:32:02 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -40,25 +40,18 @@ static const char rcsid[] = #include #include -#include -#include -#include -struct mbuf; -struct rtentry; -#include +#ifdef __bsdi__ +#include +#include +#endif #include -#include #include #include #include #include -#ifdef __bsdi__ -#include -#include -#endif #include "interface.h" #include "extract.h" @@ -67,9 +60,6 @@ struct rtentry; #include "chdlc.h" #include "ethertype.h" -/* XXX This goes somewhere else. */ -#define PPP_HDRLEN 4 - /* * The following constatns are defined by IANA. Please refer to * http://www.isi.edu/in-notes/iana/assignments/ppp-numbers @@ -339,16 +329,16 @@ static const char *papcode[] = { #define BAP_CSIND 7 #define BAP_CSRES 8 -static const char *ppp_protoname __P((u_int proto)); -static void handle_ctrl_proto __P((u_int proto,const u_char *p, int length)); -static void handle_chap __P((const u_char *p, int length)); -static void handle_pap __P((const u_char *p, int length)); -static void handle_bap __P((const u_char *p, int length)); -static int print_lcp_config_options __P((const u_char *p, int)); -static int print_ipcp_config_options __P((const u_char *p, int)); -static int print_ccp_config_options __P((const u_char *p, int)); -static int print_bacp_config_options __P((const u_char *p, int)); -static void handle_ppp __P((u_int proto, const u_char *p, int length)); +static const char *ppp_protoname (u_int proto); +static void handle_ctrl_proto (u_int proto,const u_char *p, int length); +static void handle_chap (const u_char *p, int length); +static void handle_pap (const u_char *p, int length); +static void handle_bap (const u_char *p, int length); +static int print_lcp_config_options (const u_char *p, int); +static int print_ipcp_config_options (const u_char *p, int); +static int print_ccp_config_options (const u_char *p, int); +static int print_bacp_config_options (const u_char *p, int); +static void handle_ppp (u_int proto, const u_char *p, int length); static const char * ppp_protoname(u_int proto) @@ -357,18 +347,19 @@ ppp_protoname(u_int proto) switch (proto) { case PPP_IP: return "IP"; + case PPP_IPV6: return "IPv6"; #ifdef PPP_XNS case PPP_XNS: return "XNS"; #endif case PPP_IPX: return "IPX"; + case PPP_OSI: return "OSI"; case PPP_VJC: return "VJC"; case PPP_VJNC: return "VJNC"; -#ifdef PPP_COMP case PPP_COMP: return "COMP"; -#endif case PPP_IPCP: return "IPCP"; - case PPP_IPV6CP: return "IPV6CP"; + case PPP_IPV6CP: return "IPv6CP"; case PPP_IPXCP: return "IPXCP"; + case PPP_OSICP: return "OSICP"; case PPP_CCP: return "CCP"; case PPP_LCP: return "LCP"; case PPP_PAP: return "PAP"; @@ -446,6 +437,14 @@ handle_ctrl_proto(u_int proto, const u_char *p, int length) case PPP_BACP: pfunc = print_bacp_config_options; break; + default: + /* + * This should never happen, but we set + * "pfunc" to squelch uninitialized + * variable warnings from compilers. + */ + pfunc = NULL; + break; } if ((j = (*pfunc)(p, len)) == 0) break; @@ -494,7 +493,6 @@ static int print_lcp_config_options(const u_char *p, int length) { int len, opt; - int i; if (length < 2) return 0; @@ -755,7 +753,6 @@ handle_pap(const u_char *p, int length) } code = *p; - if (length < 4) if ((code >= PAP_CODEMIN) && (code <= PAP_CODEMAX)) printf("%s", papcode[code - 1]); else { @@ -837,7 +834,7 @@ print_ipcp_config_options(const u_char *p, int length) ipaddr_string(p + 6)); break; case IPCPOPT_IPCOMP: - if (len != 4) + if (len < 4) goto invlen; printf(", IP-Comp"); if (EXTRACT_16BITS(p + 2) == PPP_VJC) { @@ -984,14 +981,21 @@ handle_ppp(u_int proto, const u_char *p, int length) case PPP_IPX: ipx_print(p, length); break; + case PPP_OSI: + isoclns_print(p, length, length, NULL, NULL); + break; + default: + break; } } /* Standard PPP printer */ -void +u_int ppp_print(register const u_char *p, u_int length) { u_int proto; + u_int full_length = length; + u_int hdr_len = 0; /* * Here, we assume that p points to the Address and Control @@ -1002,6 +1006,7 @@ ppp_print(register const u_char *p, u_int length) if (*p == PPP_ADDRESS && *(p + 1) == PPP_CONTROL) { p += 2; /* ACFC not used */ length -= 2; + hdr_len += 2; } if (length < 2) @@ -1010,18 +1015,21 @@ ppp_print(register const u_char *p, u_int length) proto = *p; /* PFC is used */ p++; length--; + hdr_len++; } else { proto = EXTRACT_16BITS(p); p += 2; length -= 2; + hdr_len += 2; } - printf("%s: ", ppp_protoname(proto)); + printf("%s %d: ", ppp_protoname(proto), full_length); handle_ppp(proto, p, length); - return; + return (hdr_len); trunc: printf("[|ppp]"); + return (0); } @@ -1032,9 +1040,8 @@ ppp_if_print(u_char *user, const struct pcap_pkthdr *h, { register u_int length = h->len; register u_int caplen = h->caplen; - const struct ip *ip; - u_int proto; + ++infodelay; ts_print(&h->ts); if (caplen < PPP_HDRLEN) { @@ -1097,6 +1104,9 @@ ppp_if_print(u_char *user, const struct pcap_pkthdr *h, default_print(p, caplen); out: putchar('\n'); + --infodelay; + if (infoprint) + info(0); } /* @@ -1116,6 +1126,9 @@ ppp_hdlc_if_print(u_char *user, const struct pcap_pkthdr *h, register u_int caplen = h->caplen; u_int proto; + ++infodelay; + ts_print(&h->ts); + if (caplen < 2) { printf("[|ppp]"); goto out; @@ -1137,7 +1150,6 @@ ppp_hdlc_if_print(u_char *user, const struct pcap_pkthdr *h, goto out; } - ts_print(&h->ts); if (eflag) printf("%02x %02x %d ", p[0], p[1], length); p += 2; @@ -1153,14 +1165,10 @@ ppp_hdlc_if_print(u_char *user, const struct pcap_pkthdr *h, case CHDLC_UNICAST: case CHDLC_BCAST: - /* - * Have the Cisco HDLC print routine do all the work. - */ - chdlc_if_print(user, h, p); - return; + chdlc_print(p, length, caplen); + goto out; default: - ts_print(&h->ts); if (eflag) printf("%02x %02x %d ", p[0], p[1], length); p += 2; @@ -1179,6 +1187,9 @@ ppp_hdlc_if_print(u_char *user, const struct pcap_pkthdr *h, default_print(p, caplen); out: putchar('\n'); + --infodelay; + if (infoprint) + info(0); } @@ -1233,6 +1244,7 @@ ppp_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *q; int i; + ++infodelay; ts_print(&h->ts); if (caplen < PPP_BSDI_HDRLEN) { @@ -1302,9 +1314,9 @@ ppp_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, printf("] "); } } - if (eflag) - printf("%d ", length); } + if (eflag) + printf("%d ", length); if (p[SLC_CHL]) { q = p + SLC_BPFHDRLEN + p[SLC_LLHL]; @@ -1374,5 +1386,8 @@ printx: default_print((const u_char *)p, caplen - hdrlength); out: putchar('\n'); + --infodelay; + if (infoprint) + info(0); #endif /* __bsdi__ */ }