]>
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.29 1999-11-17 05:18:27 assar Exp $ (LBL)";
27 #include <sys/param.h>
29 #include <sys/socket.h>
31 #include <sys/ioctl.h>
39 #include <netinet/in.h>
40 #include <netinet/in_systm.h>
41 #include <netinet/ip.h>
42 #include <netinet/if_ether.h>
49 #include <net/slcompress.h>
50 #include <net/if_ppp.h>
53 #include "interface.h"
54 #include "addrtoname.h"
57 /* XXX This goes somewhere else. */
62 #define LCP_CONF_REQ 1
63 #define LCP_CONF_ACK 2
64 #define LCP_CONF_NAK 3
65 #define LCP_CONF_REJ 4
66 #define LCP_TERM_REQ 5
67 #define LCP_TERM_ACK 6
68 #define LCP_CODE_REJ 7
69 #define LCP_PROT_REJ 8
70 #define LCP_ECHO_REQ 9
71 #define LCP_ECHO_RPL 10
72 #define LCP_DISC_REQ 11
74 #define LCP_MIN LCP_CONF_REQ
75 #define LCP_MAX LCP_DISC_REQ
77 static char *lcpcodes
[] = {
79 * LCP code values (RFC1661, pp26)
101 #define LCPOPT_ACFC 8
104 #define LCPOPT_MAX 24
106 static char *lcpconfopts
[] = {
109 "Async-Ctrl-Char-Map",
115 "Add-Ctrl-Field-Compr",
117 "Self-Describing-Pad",
119 "Multi-Link-Procedure",
123 "Nominal-Data-Encap",
129 "Multilink-Plus-Proc",
130 "Link-Discriminator",
141 #define CHAP_CODEMIN 1
142 #define CHAP_CODEMAX 4
144 static char *chapcode
[] = {
157 #define PAP_CODEMIN 1
158 #define PAP_CODEMAX 3
160 static char *papcode
[] = {
161 "Authenticate-Request",
172 static const char *ppp_protoname
__P((int proto
));
173 static void handle_lcp
__P((const u_char
*p
, int length
));
174 static int print_lcp_config_options
__P((const u_char
*p
));
175 static void handle_chap
__P((const u_char
*p
, int length
));
176 static void handle_ipcp
__P((const u_char
*p
, int length
));
177 static void handle_pap
__P((const u_char
*p
, int length
));
180 ppp_protoname(int proto
)
185 case PPP_IP
: return "IP";
187 case PPP_XNS
: return "XNS";
190 case PPP_IPX
: return "IPX";
193 case PPP_COMP
: return "COMP";
196 case PPP_IPCP
: return "IPCP";
199 case PPP_IPV6CP
: return "IPV6CP";
202 case PPP_IPXCP
: return "IPXCP";
205 case PPP_CCP
: return "CCP";
208 case PPP_LCP
: return "LCP";
211 case PPP_PAP
: return "PAP";
214 case PPP_LQR
: return "LQR";
217 case PPP_CHAP
: return "CHAP";
220 sprintf(buf
, "unknown-0x%04x\n", proto
);
225 /* print LCP frame */
227 handle_lcp(const u_char
*p
, int length
)
234 if ((x
>= LCP_MIN
) && (x
<= LCP_MAX
))
235 printf("%s", lcpcodes
[x
- 1]);
251 if ((j
= print_lcp_config_options(ptr
)) == 0)
260 printf(", Magic-Number=%u",
261 (u_int32_t
)ntohl(*(u_int32_t
*)(p
+ 8)));
273 /* LCP config options */
275 print_lcp_config_options(const u_char
*p
)
280 if ((opt
>= LCPOPT_MIN
) && (opt
<= LCPOPT_MAX
))
281 printf(", %s", lcpconfopts
[opt
]);
286 printf("=%d", (*(p
+2) << 8) + *(p
+3));
290 if (p
[2] == 0xc0 && p
[3] == 0x23)
292 else if (p
[2] == 0xc2 && p
[3] == 0x23) {
296 printf("unknown-algorithm-%u", p
[4]);
306 else if (p
[2] == 0xc2 && p
[3] == 0x27)
308 else if (p
[2] == 0xc0 && p
[3] == 0x27)
310 else if (p
[2] == 0xc1 && p
[3] == 0x23)
318 if (p
[2] == 0xc0 && p
[3] == 0x25)
326 printf("=%u", (u_int32_t
)ntohl(*(u_int32_t
*)(p
+ 2)));
340 handle_chap(const u_char
*p
, int length
)
345 if ((x
>= CHAP_CODEMIN
) && (x
<= CHAP_CODEMAX
))
346 printf("%s", chapcode
[x
- 1]);
358 x
= p
[8]; /* value size */
361 printf("%02x", *ptr
++);
362 x
= length
- p
[8] - 1;
368 printf("\\%03o", *ptr
);
377 handle_pap(const u_char
*p
, int length
)
384 if ((x
>= PAP_CODEMIN
) && (x
<= PAP_CODEMAX
))
385 printf("%s", papcode
[x
- 1]);
395 printf(", Peer-Id=");
396 x
= p
[8]; /* peerid size */
402 printf("\\%03o", *ptr
);
411 printf("\\%03o", *ptr
);
423 handle_ipcp(const u_char
*p
, int length
)
429 printf("IP-Addresses");
430 printf(", src=%s", ipaddr_string(p
+ 10));
431 printf(", drc=%s", ipaddr_string(p
+ 14));
435 printf("IP-Compression-Protocol");
439 printf("IP-Address=%s", ipaddr_string(p
+ 10));
444 /* Standard PPP printer */
446 ppp_if_print(u_char
*user
, const struct pcap_pkthdr
*h
,
447 register const u_char
*p
)
449 register u_int length
= h
->len
;
450 register u_int caplen
= h
->caplen
;
456 if (caplen
< PPP_HDRLEN
) {
462 * Some printers want to get back at the link level addresses,
463 * and/or check that they're not walking off the end of the packet.
464 * Rather than pass them all the way down, we set these globals.
466 proto
= ntohs(*(u_short
*)&p
[2]);
468 snapend
= p
+ caplen
;
471 printf("%c %4d %02x %s: ", p
[0] ? 'O' : 'I', length
,
472 p
[1], ppp_protoname(proto
));
474 length
-= PPP_HDRLEN
;
475 ip
= (struct ip
*)(p
+ PPP_HDRLEN
);
478 handle_lcp(p
, length
);
481 handle_chap(p
, length
);
484 handle_pap(p
, length
);
487 handle_ipcp(p
, length
);
489 case ETHERTYPE_IP
: /*XXX*/
491 ip_print((const u_char
*)ip
, length
);
494 case ETHERTYPE_IPV6
: /*XXX*/
498 ip6_print((const u_char
*)ip
, length
);
503 default_print((const u_char
*)ip
, caplen
- PPP_HDRLEN
);
509 /* proto type to string mapping */
510 static struct tok ptype2str
[] = {
512 { PPP_VJNC
, "VJNC" },
515 { PPP_IPCP
, "IPCP" },
520 #define PPP_BSDI_HDRLEN 24
522 /* BSD/OS specific PPP printer */
524 ppp_bsdos_if_print(u_char
*user
, const struct pcap_pkthdr
*h
,
525 register const u_char
*p
)
528 register u_int length
= h
->len
;
529 register u_int caplen
= h
->caplen
;
530 register int hdrlength
;
537 if (caplen
< PPP_BSDI_HDRLEN
) {
543 * Some printers want to get back at the link level addresses,
544 * and/or check that they're not walking off the end of the packet.
545 * Rather than pass them all the way down, we set these globals.
548 snapend
= p
+ caplen
;
552 if (p
[0] == PPP_ADDRESS
&& p
[1] == PPP_CONTROL
) {
554 printf("%02x %02x ", p
[0], p
[1]);
560 printf("%d ", length
);
561 /* Retrieve the protocol type */
563 /* Compressed protocol field */
566 printf("%02x ", ptype
);
570 /* Un-compressed protocol field */
571 ptype
= ntohs(*(u_short
*)p
);
573 printf("%04x ", ptype
);
580 printf("%c ", p
[SLC_DIR
] ? 'O' : 'I');
582 /* link level header */
583 struct ppp_header
*ph
;
585 q
= p
+ SLC_BPFHDRLEN
;
586 ph
= (struct ppp_header
*)q
;
587 if (ph
->phdr_addr
== PPP_ADDRESS
588 && ph
->phdr_ctl
== PPP_CONTROL
) {
590 printf("%02x %02x ", q
[0], q
[1]);
591 ptype
= ntohs(ph
->phdr_type
);
592 if (eflag
&& (ptype
== PPP_VJC
|| ptype
== PPP_VJNC
)) {
593 printf("%s ", tok2str(ptype2str
,
594 "proto-#%d", ptype
));
599 for (i
= 0; i
< p
[SLC_LLHL
]; i
++)
600 printf("%02x", q
[i
]);
605 printf("%d ", length
);
608 q
= p
+ SLC_BPFHDRLEN
+ p
[SLC_LLHL
];
612 ptype
= vjc_print(q
, length
- (q
- p
), ptype
);
613 hdrlength
= PPP_BSDI_HDRLEN
;
619 ptype
= vjc_print(q
, length
- (q
- p
), ptype
);
620 hdrlength
= PPP_BSDI_HDRLEN
;
628 for (i
= 0; i
< p
[SLC_LLHL
]; i
++)
629 printf("%02x", q
[i
]);
636 hdrlength
= PPP_BSDI_HDRLEN
;
645 printf("%s ", tok2str(ptype2str
, "proto-#%d", ptype
));
649 default_print((const u_char
*)p
, caplen
- hdrlength
);
652 #endif /* __bsdi__ */