]>
The Tcpdump Group git mirrors - tcpdump/blob - print-ppp.c
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.39 2000-07-01 03:39:08 assar Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
35 #include <sys/ioctl.h>
41 #include <netinet/in.h>
42 #include <netinet/in_systm.h>
43 #include <netinet/ip.h>
44 #include <netinet/if_ether.h>
51 #include <net/slcompress.h>
52 #include <net/if_ppp.h>
55 #include "interface.h"
57 #include "addrtoname.h"
60 /* XXX This goes somewhere else. */
65 #define LCP_CONF_REQ 1
66 #define LCP_CONF_ACK 2
67 #define LCP_CONF_NAK 3
68 #define LCP_CONF_REJ 4
69 #define LCP_TERM_REQ 5
70 #define LCP_TERM_ACK 6
71 #define LCP_CODE_REJ 7
72 #define LCP_PROT_REJ 8
73 #define LCP_ECHO_REQ 9
74 #define LCP_ECHO_RPL 10
75 #define LCP_DISC_REQ 11
77 #define LCP_MIN LCP_CONF_REQ
78 #define LCP_MAX LCP_DISC_REQ
80 static char *lcpcodes
[] = {
82 * LCP code values (RFC1661, pp26)
104 #define LCPOPT_ACFC 8
107 #define LCPOPT_MAX 24
109 static char *lcpconfopts
[] = {
112 "Async-Ctrl-Char-Map",
118 "Add-Ctrl-Field-Compr",
120 "Self-Describing-Pad",
122 "Multi-Link-Procedure",
126 "Nominal-Data-Encap",
132 "Multilink-Plus-Proc",
133 "Link-Discriminator",
144 #define CHAP_CODEMIN 1
145 #define CHAP_CODEMAX 4
147 static char *chapcode
[] = {
160 #define PAP_CODEMIN 1
161 #define PAP_CODEMAX 3
163 static char *papcode
[] = {
164 "Authenticate-Request",
175 static const char *ppp_protoname
__P((int proto
));
176 static void handle_lcp
__P((const u_char
*p
, int length
));
177 static int print_lcp_config_options
__P((const u_char
*p
));
178 static void handle_chap
__P((const u_char
*p
, int length
));
179 static void handle_ipcp
__P((const u_char
*p
, int length
));
180 static void handle_pap
__P((const u_char
*p
, int length
));
183 ppp_protoname(int proto
)
188 case PPP_IP
: return "IP";
190 case PPP_XNS
: return "XNS";
193 case PPP_IPX
: return "IPX";
196 case PPP_COMP
: return "COMP";
199 case PPP_IPCP
: return "IPCP";
202 case PPP_IPV6CP
: return "IPV6CP";
205 case PPP_IPXCP
: return "IPXCP";
208 case PPP_CCP
: return "CCP";
211 case PPP_LCP
: return "LCP";
214 case PPP_PAP
: return "PAP";
217 case PPP_LQR
: return "LQR";
220 case PPP_CHAP
: return "CHAP";
223 snprintf(buf
, sizeof(buf
), "unknown-0x%04x", proto
);
228 /* print LCP frame */
230 handle_lcp(const u_char
*p
, int length
)
237 if ((x
>= LCP_MIN
) && (x
<= LCP_MAX
))
238 printf("%s", lcpcodes
[x
- 1]);
254 if ((j
= print_lcp_config_options(ptr
)) == 0)
263 printf(", Magic-Number=%u",
264 EXTRACT_32BITS(p
+8));
276 /* LCP config options */
278 print_lcp_config_options(const u_char
*p
)
283 if ((opt
>= LCPOPT_MIN
) && (opt
<= LCPOPT_MAX
))
284 printf(", %s", lcpconfopts
[opt
]);
289 printf("=%d", (*(p
+2) << 8) + *(p
+3));
293 if (p
[2] == 0xc0 && p
[3] == 0x23)
295 else if (p
[2] == 0xc2 && p
[3] == 0x23) {
299 printf("unknown-algorithm-%u", p
[4]);
309 else if (p
[2] == 0xc2 && p
[3] == 0x27)
311 else if (p
[2] == 0xc0 && p
[3] == 0x27)
313 else if (p
[2] == 0xc1 && p
[3] == 0x23)
321 if (p
[2] == 0xc0 && p
[3] == 0x25)
329 printf("=%u", EXTRACT_32BITS(p
+2));
343 handle_chap(const u_char
*p
, int length
)
350 if ((x
>= CHAP_CODEMIN
) && (x
<= CHAP_CODEMAX
))
351 printf("%s", chapcode
[x
- 1]);
363 x
= p
[8]; /* value size */
366 printf("%02x", *ptr
++);
367 x
= length
- p
[8] - 1;
373 printf("\\%03o", *ptr
);
382 handle_pap(const u_char
*p
, int length
)
389 if ((x
>= PAP_CODEMIN
) && (x
<= PAP_CODEMAX
))
390 printf("%s", papcode
[x
- 1]);
400 printf(", Peer-Id=");
401 x
= p
[8]; /* peerid size */
407 printf("\\%03o", *ptr
);
416 printf("\\%03o", *ptr
);
428 handle_ipcp(const u_char
*p
, int length
)
434 printf("IP-Addresses");
435 printf(", src=%s", ipaddr_string(p
+ 10));
436 printf(", drc=%s", ipaddr_string(p
+ 14));
440 printf("IP-Compression-Protocol");
444 printf("IP-Address=%s", ipaddr_string(p
+ 10));
449 /* Standard PPP printer */
451 ppp_if_print(u_char
*user
, const struct pcap_pkthdr
*h
,
452 register const u_char
*p
)
454 register u_int length
= h
->len
;
455 register u_int caplen
= h
->caplen
;
461 if (caplen
< PPP_HDRLEN
) {
467 * Some printers want to get back at the link level addresses,
468 * and/or check that they're not walking off the end of the packet.
469 * Rather than pass them all the way down, we set these globals.
471 proto
= ntohs(*(u_int16_t
*)&p
[2]);
473 snapend
= p
+ caplen
;
476 printf("%c %4d %02x %s: ", p
[0] ? 'O' : 'I', length
,
477 p
[1], ppp_protoname(proto
));
479 length
-= PPP_HDRLEN
;
480 ip
= (struct ip
*)(p
+ PPP_HDRLEN
);
483 handle_lcp(p
, length
);
486 handle_chap(p
, length
);
489 handle_pap(p
, length
);
492 handle_ipcp(p
, length
);
494 case ETHERTYPE_IP
: /*XXX*/
496 ip_print((const u_char
*)ip
, length
);
499 case ETHERTYPE_IPV6
: /*XXX*/
501 ip6_print((const u_char
*)ip
, length
);
506 default_print((const u_char
*)ip
, caplen
- PPP_HDRLEN
);
511 struct tok ppptype2str
[] = {
515 { PPP_DECNET
, "DECNET" },
516 { PPP_APPLE
, "APPLE" },
519 { PPP_VJNC
, "VJNC" },
520 { PPP_BRPDU
, "BRPDU" },
521 { PPP_STII
, "STII" },
522 { PPP_VINES
, "VINES" },
524 { PPP_HELLO
, "HELLO" },
525 { PPP_LUXCOM
, "LUXCOM" },
527 { PPP_IPCP
, "IPCP" },
528 { PPP_OSICP
, "OSICP" },
529 { PPP_NSCP
, "NSCP" },
530 { PPP_DECNETCP
, "DECNETCP" },
531 { PPP_APPLECP
, "APPLECP" },
532 { PPP_IPXCP
, "IPXCP" },
533 { PPP_STIICP
, "STIICP" },
534 { PPP_VINESCP
, "VINESCP" },
539 { PPP_CHAP
, "CHAP" },
543 #define PPP_BSDI_HDRLEN 24
545 /* BSD/OS specific PPP printer */
547 ppp_bsdos_if_print(u_char
*user
, const struct pcap_pkthdr
*h
,
548 register const u_char
*p
)
551 register u_int length
= h
->len
;
552 register u_int caplen
= h
->caplen
;
553 register int hdrlength
;
560 if (caplen
< PPP_BSDI_HDRLEN
) {
566 * Some printers want to get back at the link level addresses,
567 * and/or check that they're not walking off the end of the packet.
568 * Rather than pass them all the way down, we set these globals.
571 snapend
= p
+ caplen
;
575 if (p
[0] == PPP_ADDRESS
&& p
[1] == PPP_CONTROL
) {
577 printf("%02x %02x ", p
[0], p
[1]);
583 printf("%d ", length
);
584 /* Retrieve the protocol type */
586 /* Compressed protocol field */
589 printf("%02x ", ptype
);
593 /* Un-compressed protocol field */
594 ptype
= ntohs(*(u_int16_t
*)p
);
596 printf("%04x ", ptype
);
603 printf("%c ", p
[SLC_DIR
] ? 'O' : 'I');
605 /* link level header */
606 struct ppp_header
*ph
;
608 q
= p
+ SLC_BPFHDRLEN
;
609 ph
= (struct ppp_header
*)q
;
610 if (ph
->phdr_addr
== PPP_ADDRESS
611 && ph
->phdr_ctl
== PPP_CONTROL
) {
613 printf("%02x %02x ", q
[0], q
[1]);
614 ptype
= ntohs(ph
->phdr_type
);
615 if (eflag
&& (ptype
== PPP_VJC
|| ptype
== PPP_VJNC
)) {
616 printf("%s ", tok2str(ppptype2str
,
617 "proto-#%d", ptype
));
622 for (i
= 0; i
< p
[SLC_LLHL
]; i
++)
623 printf("%02x", q
[i
]);
628 printf("%d ", length
);
631 q
= p
+ SLC_BPFHDRLEN
+ p
[SLC_LLHL
];
635 ptype
= vjc_print(q
, length
- (q
- p
), ptype
);
636 hdrlength
= PPP_BSDI_HDRLEN
;
644 ip6_print(p
, length
);
650 ptype
= vjc_print(q
, length
- (q
- p
), ptype
);
651 hdrlength
= PPP_BSDI_HDRLEN
;
659 ip6_print(p
, length
);
667 for (i
= 0; i
< p
[SLC_LLHL
]; i
++)
668 printf("%02x", q
[i
]);
675 hdrlength
= PPP_BSDI_HDRLEN
;
687 ip6_print(p
, length
);
691 printf("%s ", tok2str(ppptype2str
, "proto-#%d", ptype
));
696 default_print((const u_char
*)p
, caplen
- hdrlength
);
699 #endif /* __bsdi__ */