]>
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.33 1999-12-22 06:27:22 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"
58 #include "addrtoname.h"
61 /* XXX This goes somewhere else. */
66 #define LCP_CONF_REQ 1
67 #define LCP_CONF_ACK 2
68 #define LCP_CONF_NAK 3
69 #define LCP_CONF_REJ 4
70 #define LCP_TERM_REQ 5
71 #define LCP_TERM_ACK 6
72 #define LCP_CODE_REJ 7
73 #define LCP_PROT_REJ 8
74 #define LCP_ECHO_REQ 9
75 #define LCP_ECHO_RPL 10
76 #define LCP_DISC_REQ 11
78 #define LCP_MIN LCP_CONF_REQ
79 #define LCP_MAX LCP_DISC_REQ
81 static char *lcpcodes
[] = {
83 * LCP code values (RFC1661, pp26)
100 #define LCPOPT_ACCM 2
105 #define LCPOPT_ACFC 8
108 #define LCPOPT_MAX 24
110 static char *lcpconfopts
[] = {
113 "Async-Ctrl-Char-Map",
119 "Add-Ctrl-Field-Compr",
121 "Self-Describing-Pad",
123 "Multi-Link-Procedure",
127 "Nominal-Data-Encap",
133 "Multilink-Plus-Proc",
134 "Link-Discriminator",
145 #define CHAP_CODEMIN 1
146 #define CHAP_CODEMAX 4
148 static char *chapcode
[] = {
161 #define PAP_CODEMIN 1
162 #define PAP_CODEMAX 3
164 static char *papcode
[] = {
165 "Authenticate-Request",
176 static const char *ppp_protoname
__P((int proto
));
177 static void handle_lcp
__P((const u_char
*p
, int length
));
178 static int print_lcp_config_options
__P((const u_char
*p
));
179 static void handle_chap
__P((const u_char
*p
, int length
));
180 static void handle_ipcp
__P((const u_char
*p
, int length
));
181 static void handle_pap
__P((const u_char
*p
, int length
));
184 ppp_protoname(int proto
)
189 case PPP_IP
: return "IP";
191 case PPP_XNS
: return "XNS";
194 case PPP_IPX
: return "IPX";
197 case PPP_COMP
: return "COMP";
200 case PPP_IPCP
: return "IPCP";
203 case PPP_IPV6CP
: return "IPV6CP";
206 case PPP_IPXCP
: return "IPXCP";
209 case PPP_CCP
: return "CCP";
212 case PPP_LCP
: return "LCP";
215 case PPP_PAP
: return "PAP";
218 case PPP_LQR
: return "LQR";
221 case PPP_CHAP
: return "CHAP";
224 sprintf(buf
, "unknown-0x%04x\n", proto
);
229 /* print LCP frame */
231 handle_lcp(const u_char
*p
, int length
)
238 if ((x
>= LCP_MIN
) && (x
<= LCP_MAX
))
239 printf("%s", lcpcodes
[x
- 1]);
255 if ((j
= print_lcp_config_options(ptr
)) == 0)
264 printf(", Magic-Number=%u",
265 (u_int32_t
)ntohl(*(u_int32_t
*)(p
+ 8)));
277 /* LCP config options */
279 print_lcp_config_options(const u_char
*p
)
284 if ((opt
>= LCPOPT_MIN
) && (opt
<= LCPOPT_MAX
))
285 printf(", %s", lcpconfopts
[opt
]);
290 printf("=%d", (*(p
+2) << 8) + *(p
+3));
294 if (p
[2] == 0xc0 && p
[3] == 0x23)
296 else if (p
[2] == 0xc2 && p
[3] == 0x23) {
300 printf("unknown-algorithm-%u", p
[4]);
310 else if (p
[2] == 0xc2 && p
[3] == 0x27)
312 else if (p
[2] == 0xc0 && p
[3] == 0x27)
314 else if (p
[2] == 0xc1 && p
[3] == 0x23)
322 if (p
[2] == 0xc0 && p
[3] == 0x25)
330 printf("=%u", (u_int32_t
)ntohl(*(u_int32_t
*)(p
+ 2)));
344 handle_chap(const u_char
*p
, int length
)
351 if ((x
>= CHAP_CODEMIN
) && (x
<= CHAP_CODEMAX
))
352 printf("%s", chapcode
[x
- 1]);
364 x
= p
[8]; /* value size */
367 printf("%02x", *ptr
++);
368 x
= length
- p
[8] - 1;
374 printf("\\%03o", *ptr
);
383 handle_pap(const u_char
*p
, int length
)
390 if ((x
>= PAP_CODEMIN
) && (x
<= PAP_CODEMAX
))
391 printf("%s", papcode
[x
- 1]);
401 printf(", Peer-Id=");
402 x
= p
[8]; /* peerid size */
408 printf("\\%03o", *ptr
);
417 printf("\\%03o", *ptr
);
429 handle_ipcp(const u_char
*p
, int length
)
435 printf("IP-Addresses");
436 printf(", src=%s", ipaddr_string(p
+ 10));
437 printf(", drc=%s", ipaddr_string(p
+ 14));
441 printf("IP-Compression-Protocol");
445 printf("IP-Address=%s", ipaddr_string(p
+ 10));
450 /* Standard PPP printer */
452 ppp_if_print(u_char
*user
, const struct pcap_pkthdr
*h
,
453 register const u_char
*p
)
455 register u_int length
= h
->len
;
456 register u_int caplen
= h
->caplen
;
462 if (caplen
< PPP_HDRLEN
) {
468 * Some printers want to get back at the link level addresses,
469 * and/or check that they're not walking off the end of the packet.
470 * Rather than pass them all the way down, we set these globals.
472 proto
= ntohs(*(u_short
*)&p
[2]);
474 snapend
= p
+ caplen
;
477 printf("%c %4d %02x %s: ", p
[0] ? 'O' : 'I', length
,
478 p
[1], ppp_protoname(proto
));
480 length
-= PPP_HDRLEN
;
481 ip
= (struct ip
*)(p
+ PPP_HDRLEN
);
484 handle_lcp(p
, length
);
487 handle_chap(p
, length
);
490 handle_pap(p
, length
);
493 handle_ipcp(p
, length
);
495 case ETHERTYPE_IP
: /*XXX*/
497 ip_print((const u_char
*)ip
, length
);
500 case ETHERTYPE_IPV6
: /*XXX*/
504 ip6_print((const u_char
*)ip
, length
);
509 default_print((const u_char
*)ip
, caplen
- PPP_HDRLEN
);
514 struct tok ppptype2str
[] = {
518 { PPP_DECNET
, "DECNET" },
519 { PPP_APPLE
, "APPLE" },
522 { PPP_VJNC
, "VJNC" },
523 { PPP_BRPDU
, "BRPDU" },
524 { PPP_STII
, "STII" },
525 { PPP_VINES
, "VINES" },
527 { PPP_HELLO
, "HELLO" },
528 { PPP_LUXCOM
, "LUXCOM" },
530 { PPP_IPCP
, "IPCP" },
531 { PPP_OSICP
, "OSICP" },
532 { PPP_NSCP
, "NSCP" },
533 { PPP_DECNETCP
, "DECNETCP" },
534 { PPP_APPLECP
, "APPLECP" },
535 { PPP_IPXCP
, "IPXCP" },
536 { PPP_STIICP
, "STIICP" },
537 { PPP_VINESCP
, "VINESCP" },
542 { PPP_CHAP
, "CHAP" },
546 #define PPP_BSDI_HDRLEN 24
548 /* BSD/OS specific PPP printer */
550 ppp_bsdos_if_print(u_char
*user
, const struct pcap_pkthdr
*h
,
551 register const u_char
*p
)
554 register u_int length
= h
->len
;
555 register u_int caplen
= h
->caplen
;
556 register int hdrlength
;
563 if (caplen
< PPP_BSDI_HDRLEN
) {
569 * Some printers want to get back at the link level addresses,
570 * and/or check that they're not walking off the end of the packet.
571 * Rather than pass them all the way down, we set these globals.
574 snapend
= p
+ caplen
;
578 if (p
[0] == PPP_ADDRESS
&& p
[1] == PPP_CONTROL
) {
580 printf("%02x %02x ", p
[0], p
[1]);
586 printf("%d ", length
);
587 /* Retrieve the protocol type */
589 /* Compressed protocol field */
592 printf("%02x ", ptype
);
596 /* Un-compressed protocol field */
597 ptype
= ntohs(*(u_short
*)p
);
599 printf("%04x ", ptype
);
606 printf("%c ", p
[SLC_DIR
] ? 'O' : 'I');
608 /* link level header */
609 struct ppp_header
*ph
;
611 q
= p
+ SLC_BPFHDRLEN
;
612 ph
= (struct ppp_header
*)q
;
613 if (ph
->phdr_addr
== PPP_ADDRESS
614 && ph
->phdr_ctl
== PPP_CONTROL
) {
616 printf("%02x %02x ", q
[0], q
[1]);
617 ptype
= ntohs(ph
->phdr_type
);
618 if (eflag
&& (ptype
== PPP_VJC
|| ptype
== PPP_VJNC
)) {
619 printf("%s ", tok2str(ppptype2str
,
620 "proto-#%d", ptype
));
625 for (i
= 0; i
< p
[SLC_LLHL
]; i
++)
626 printf("%02x", q
[i
]);
631 printf("%d ", length
);
634 q
= p
+ SLC_BPFHDRLEN
+ p
[SLC_LLHL
];
638 ptype
= vjc_print(q
, length
- (q
- p
), ptype
);
639 hdrlength
= PPP_BSDI_HDRLEN
;
645 ptype
= vjc_print(q
, length
- (q
- p
), ptype
);
646 hdrlength
= PPP_BSDI_HDRLEN
;
654 for (i
= 0; i
< p
[SLC_LLHL
]; i
++)
655 printf("%02x", q
[i
]);
662 hdrlength
= PPP_BSDI_HDRLEN
;
671 printf("%s ", tok2str(ppptype2str
, "proto-#%d", ptype
));
675 default_print((const u_char
*)p
, caplen
- hdrlength
);
678 #endif /* __bsdi__ */