]>
The Tcpdump Group git mirrors - tcpdump/blob - print-ppp.c
e3c5462c5ed7c88dd8deee9b9409e810fe22b0e5
2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 static const char rcsid
[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.37 2000-05-23 16:56:08 itojun Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
35 #include <sys/ioctl.h>
43 #include <netinet/in.h>
44 #include <netinet/in_systm.h>
45 #include <netinet/ip.h>
46 #include <netinet/if_ether.h>
53 #include <net/slcompress.h>
54 #include <net/if_ppp.h>
57 #include "interface.h"
59 #include "addrtoname.h"
62 /* XXX This goes somewhere else. */
67 #define LCP_CONF_REQ 1
68 #define LCP_CONF_ACK 2
69 #define LCP_CONF_NAK 3
70 #define LCP_CONF_REJ 4
71 #define LCP_TERM_REQ 5
72 #define LCP_TERM_ACK 6
73 #define LCP_CODE_REJ 7
74 #define LCP_PROT_REJ 8
75 #define LCP_ECHO_REQ 9
76 #define LCP_ECHO_RPL 10
77 #define LCP_DISC_REQ 11
79 #define LCP_MIN LCP_CONF_REQ
80 #define LCP_MAX LCP_DISC_REQ
82 static char *lcpcodes
[] = {
84 * LCP code values (RFC1661, pp26)
101 #define LCPOPT_ACCM 2
106 #define LCPOPT_ACFC 8
109 #define LCPOPT_MAX 24
111 static char *lcpconfopts
[] = {
114 "Async-Ctrl-Char-Map",
120 "Add-Ctrl-Field-Compr",
122 "Self-Describing-Pad",
124 "Multi-Link-Procedure",
128 "Nominal-Data-Encap",
134 "Multilink-Plus-Proc",
135 "Link-Discriminator",
146 #define CHAP_CODEMIN 1
147 #define CHAP_CODEMAX 4
149 static char *chapcode
[] = {
162 #define PAP_CODEMIN 1
163 #define PAP_CODEMAX 3
165 static char *papcode
[] = {
166 "Authenticate-Request",
177 static const char *ppp_protoname
__P((int proto
));
178 static void handle_lcp
__P((const u_char
*p
, int length
));
179 static int print_lcp_config_options
__P((const u_char
*p
));
180 static void handle_chap
__P((const u_char
*p
, int length
));
181 static void handle_ipcp
__P((const u_char
*p
, int length
));
182 static void handle_pap
__P((const u_char
*p
, int length
));
185 ppp_protoname(int proto
)
190 case PPP_IP
: return "IP";
192 case PPP_XNS
: return "XNS";
195 case PPP_IPX
: return "IPX";
198 case PPP_COMP
: return "COMP";
201 case PPP_IPCP
: return "IPCP";
204 case PPP_IPV6CP
: return "IPV6CP";
207 case PPP_IPXCP
: return "IPXCP";
210 case PPP_CCP
: return "CCP";
213 case PPP_LCP
: return "LCP";
216 case PPP_PAP
: return "PAP";
219 case PPP_LQR
: return "LQR";
222 case PPP_CHAP
: return "CHAP";
225 snprintf(buf
, sizeof(buf
), "unknown-0x%04x\n", proto
);
230 /* print LCP frame */
232 handle_lcp(const u_char
*p
, int length
)
239 if ((x
>= LCP_MIN
) && (x
<= LCP_MAX
))
240 printf("%s", lcpcodes
[x
- 1]);
256 if ((j
= print_lcp_config_options(ptr
)) == 0)
265 printf(", Magic-Number=%u",
266 EXTRACT_32BITS(p
+8));
278 /* LCP config options */
280 print_lcp_config_options(const u_char
*p
)
285 if ((opt
>= LCPOPT_MIN
) && (opt
<= LCPOPT_MAX
))
286 printf(", %s", lcpconfopts
[opt
]);
291 printf("=%d", (*(p
+2) << 8) + *(p
+3));
295 if (p
[2] == 0xc0 && p
[3] == 0x23)
297 else if (p
[2] == 0xc2 && p
[3] == 0x23) {
301 printf("unknown-algorithm-%u", p
[4]);
311 else if (p
[2] == 0xc2 && p
[3] == 0x27)
313 else if (p
[2] == 0xc0 && p
[3] == 0x27)
315 else if (p
[2] == 0xc1 && p
[3] == 0x23)
323 if (p
[2] == 0xc0 && p
[3] == 0x25)
331 printf("=%u", EXTRACT_32BITS(p
+2));
345 handle_chap(const u_char
*p
, int length
)
352 if ((x
>= CHAP_CODEMIN
) && (x
<= CHAP_CODEMAX
))
353 printf("%s", chapcode
[x
- 1]);
365 x
= p
[8]; /* value size */
368 printf("%02x", *ptr
++);
369 x
= length
- p
[8] - 1;
375 printf("\\%03o", *ptr
);
384 handle_pap(const u_char
*p
, int length
)
391 if ((x
>= PAP_CODEMIN
) && (x
<= PAP_CODEMAX
))
392 printf("%s", papcode
[x
- 1]);
402 printf(", Peer-Id=");
403 x
= p
[8]; /* peerid size */
409 printf("\\%03o", *ptr
);
418 printf("\\%03o", *ptr
);
430 handle_ipcp(const u_char
*p
, int length
)
436 printf("IP-Addresses");
437 printf(", src=%s", ipaddr_string(p
+ 10));
438 printf(", drc=%s", ipaddr_string(p
+ 14));
442 printf("IP-Compression-Protocol");
446 printf("IP-Address=%s", ipaddr_string(p
+ 10));
451 /* Standard PPP printer */
453 ppp_if_print(u_char
*user
, const struct pcap_pkthdr
*h
,
454 register const u_char
*p
)
456 register u_int length
= h
->len
;
457 register u_int caplen
= h
->caplen
;
463 if (caplen
< PPP_HDRLEN
) {
469 * Some printers want to get back at the link level addresses,
470 * and/or check that they're not walking off the end of the packet.
471 * Rather than pass them all the way down, we set these globals.
473 proto
= ntohs(*(u_int16_t
*)&p
[2]);
475 snapend
= p
+ caplen
;
478 printf("%c %4d %02x %s: ", p
[0] ? 'O' : 'I', length
,
479 p
[1], ppp_protoname(proto
));
481 length
-= PPP_HDRLEN
;
482 ip
= (struct ip
*)(p
+ PPP_HDRLEN
);
485 handle_lcp(p
, length
);
488 handle_chap(p
, length
);
491 handle_pap(p
, length
);
494 handle_ipcp(p
, length
);
496 case ETHERTYPE_IP
: /*XXX*/
498 ip_print((const u_char
*)ip
, length
);
501 case ETHERTYPE_IPV6
: /*XXX*/
503 ip6_print((const u_char
*)ip
, length
);
508 default_print((const u_char
*)ip
, caplen
- PPP_HDRLEN
);
513 struct tok ppptype2str
[] = {
517 { PPP_DECNET
, "DECNET" },
518 { PPP_APPLE
, "APPLE" },
521 { PPP_VJNC
, "VJNC" },
522 { PPP_BRPDU
, "BRPDU" },
523 { PPP_STII
, "STII" },
524 { PPP_VINES
, "VINES" },
526 { PPP_HELLO
, "HELLO" },
527 { PPP_LUXCOM
, "LUXCOM" },
529 { PPP_IPCP
, "IPCP" },
530 { PPP_OSICP
, "OSICP" },
531 { PPP_NSCP
, "NSCP" },
532 { PPP_DECNETCP
, "DECNETCP" },
533 { PPP_APPLECP
, "APPLECP" },
534 { PPP_IPXCP
, "IPXCP" },
535 { PPP_STIICP
, "STIICP" },
536 { PPP_VINESCP
, "VINESCP" },
541 { PPP_CHAP
, "CHAP" },
545 #define PPP_BSDI_HDRLEN 24
547 /* BSD/OS specific PPP printer */
549 ppp_bsdos_if_print(u_char
*user
, const struct pcap_pkthdr
*h
,
550 register const u_char
*p
)
553 register u_int length
= h
->len
;
554 register u_int caplen
= h
->caplen
;
555 register int hdrlength
;
562 if (caplen
< PPP_BSDI_HDRLEN
) {
568 * Some printers want to get back at the link level addresses,
569 * and/or check that they're not walking off the end of the packet.
570 * Rather than pass them all the way down, we set these globals.
573 snapend
= p
+ caplen
;
577 if (p
[0] == PPP_ADDRESS
&& p
[1] == PPP_CONTROL
) {
579 printf("%02x %02x ", p
[0], p
[1]);
585 printf("%d ", length
);
586 /* Retrieve the protocol type */
588 /* Compressed protocol field */
591 printf("%02x ", ptype
);
595 /* Un-compressed protocol field */
596 ptype
= ntohs(*(u_int16_t
*)p
);
598 printf("%04x ", ptype
);
605 printf("%c ", p
[SLC_DIR
] ? 'O' : 'I');
607 /* link level header */
608 struct ppp_header
*ph
;
610 q
= p
+ SLC_BPFHDRLEN
;
611 ph
= (struct ppp_header
*)q
;
612 if (ph
->phdr_addr
== PPP_ADDRESS
613 && ph
->phdr_ctl
== PPP_CONTROL
) {
615 printf("%02x %02x ", q
[0], q
[1]);
616 ptype
= ntohs(ph
->phdr_type
);
617 if (eflag
&& (ptype
== PPP_VJC
|| ptype
== PPP_VJNC
)) {
618 printf("%s ", tok2str(ppptype2str
,
619 "proto-#%d", ptype
));
624 for (i
= 0; i
< p
[SLC_LLHL
]; i
++)
625 printf("%02x", q
[i
]);
630 printf("%d ", length
);
633 q
= p
+ SLC_BPFHDRLEN
+ p
[SLC_LLHL
];
637 ptype
= vjc_print(q
, length
- (q
- p
), ptype
);
638 hdrlength
= PPP_BSDI_HDRLEN
;
646 ip6_print(p
, length
);
652 ptype
= vjc_print(q
, length
- (q
- p
), ptype
);
653 hdrlength
= PPP_BSDI_HDRLEN
;
661 ip6_print(p
, length
);
669 for (i
= 0; i
< p
[SLC_LLHL
]; i
++)
670 printf("%02x", q
[i
]);
677 hdrlength
= PPP_BSDI_HDRLEN
;
689 ip6_print(p
, length
);
693 printf("%s ", tok2str(ppptype2str
, "proto-#%d", ptype
));
698 default_print((const u_char
*)p
, caplen
- hdrlength
);
701 #endif /* __bsdi__ */