1b0453382SBill Fenner /* maybe it should be merged into print-ppp.c */ 2b0453382SBill Fenner /* 3b0453382SBill Fenner * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997 4b0453382SBill Fenner * The Regents of the University of California. All rights reserved. 5b0453382SBill Fenner * 6b0453382SBill Fenner * Redistribution and use in source and binary forms, with or without 7b0453382SBill Fenner * modification, are permitted provided that: (1) source code distributions 8b0453382SBill Fenner * retain the above copyright notice and this paragraph in its entirety, (2) 9b0453382SBill Fenner * distributions including binary code include the above copyright notice and 10b0453382SBill Fenner * this paragraph in its entirety in the documentation or other materials 11b0453382SBill Fenner * provided with the distribution, and (3) all advertising materials mentioning 12b0453382SBill Fenner * features or use of this software display the following acknowledgement: 13b0453382SBill Fenner * ``This product includes software developed by the University of California, 14b0453382SBill Fenner * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 15b0453382SBill Fenner * the University nor the names of its contributors may be used to endorse 16b0453382SBill Fenner * or promote products derived from this software without specific prior 17b0453382SBill Fenner * written permission. 18b0453382SBill Fenner * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 19b0453382SBill Fenner * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 20b0453382SBill Fenner * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 21b0453382SBill Fenner */ 22b0453382SBill Fenner 23b0453382SBill Fenner #ifndef lint 24b0453382SBill Fenner static const char rcsid[] = 25a90e161bSBill Fenner "@(#) $Header: /tcpdump/master/tcpdump/print-chdlc.c,v 1.13 2001/09/17 21:57:57 fenner Exp $ (LBL)"; 26b0453382SBill Fenner #endif 27b0453382SBill Fenner 28b0453382SBill Fenner #ifdef HAVE_CONFIG_H 29b0453382SBill Fenner #include "config.h" 30b0453382SBill Fenner #endif 31b0453382SBill Fenner 32b0453382SBill Fenner #include <sys/param.h> 33b0453382SBill Fenner #include <sys/time.h> 34b0453382SBill Fenner 35b0453382SBill Fenner #include <netinet/in.h> 36b0453382SBill Fenner 37b0453382SBill Fenner #include <ctype.h> 38b0453382SBill Fenner #include <netdb.h> 39b0453382SBill Fenner #include <pcap.h> 40b0453382SBill Fenner #include <stdio.h> 41b0453382SBill Fenner 42b0453382SBill Fenner #include "interface.h" 43b0453382SBill Fenner #include "addrtoname.h" 44685295f4SBill Fenner #include "ethertype.h" 45a90e161bSBill Fenner #include "extract.h" 46b0453382SBill Fenner #include "ppp.h" 47685295f4SBill Fenner #include "chdlc.h" 48b0453382SBill Fenner 49b0453382SBill Fenner static void chdlc_slarp_print(const u_char *, u_int); 50b0453382SBill Fenner 51b0453382SBill Fenner /* Standard CHDLC printer */ 52b0453382SBill Fenner void 53b0453382SBill Fenner chdlc_if_print(u_char *user, const struct pcap_pkthdr *h, 54b0453382SBill Fenner register const u_char *p) 55b0453382SBill Fenner { 56b0453382SBill Fenner register u_int length = h->len; 57b0453382SBill Fenner register u_int caplen = h->caplen; 58b0453382SBill Fenner 59a90e161bSBill Fenner ++infodelay; 60b0453382SBill Fenner ts_print(&h->ts); 61b0453382SBill Fenner 62b0453382SBill Fenner /* 63b0453382SBill Fenner * Some printers want to get back at the link level addresses, 64b0453382SBill Fenner * and/or check that they're not walking off the end of the packet. 65b0453382SBill Fenner * Rather than pass them all the way down, we set these globals. 66b0453382SBill Fenner */ 67b0453382SBill Fenner packetp = p; 68b0453382SBill Fenner snapend = p + caplen; 69b0453382SBill Fenner 70a90e161bSBill Fenner chdlc_print(p, length, caplen); 71a90e161bSBill Fenner 72a90e161bSBill Fenner putchar('\n'); 73a90e161bSBill Fenner --infodelay; 74a90e161bSBill Fenner if (infoprint) 75a90e161bSBill Fenner info(0); 76a90e161bSBill Fenner } 77a90e161bSBill Fenner 78a90e161bSBill Fenner void 79a90e161bSBill Fenner chdlc_print(register const u_char *p, u_int length, u_int caplen) 80a90e161bSBill Fenner { 81a90e161bSBill Fenner const struct ip *ip; 82a90e161bSBill Fenner u_int proto; 83a90e161bSBill Fenner 84a90e161bSBill Fenner if (caplen < CHDLC_HDRLEN) { 85a90e161bSBill Fenner printf("[|chdlc]"); 86a90e161bSBill Fenner return; 87a90e161bSBill Fenner } 88a90e161bSBill Fenner 89a90e161bSBill Fenner proto = EXTRACT_16BITS(&p[2]); 90b0453382SBill Fenner if (eflag) { 91b0453382SBill Fenner switch (p[0]) { 92b0453382SBill Fenner case CHDLC_UNICAST: 93b0453382SBill Fenner printf("unicast "); 94b0453382SBill Fenner break; 95b0453382SBill Fenner case CHDLC_BCAST: 96b0453382SBill Fenner printf("bcast "); 97b0453382SBill Fenner break; 98b0453382SBill Fenner default: 99b0453382SBill Fenner printf("0x%02x ", p[0]); 100b0453382SBill Fenner break; 101b0453382SBill Fenner } 102b0453382SBill Fenner printf("%d %04x: ", length, proto); 103b0453382SBill Fenner } 104b0453382SBill Fenner 105b0453382SBill Fenner length -= CHDLC_HDRLEN; 106a90e161bSBill Fenner ip = (const struct ip *)(p + CHDLC_HDRLEN); 107b0453382SBill Fenner switch (proto) { 108b0453382SBill Fenner case ETHERTYPE_IP: 109b0453382SBill Fenner ip_print((const u_char *)ip, length); 110b0453382SBill Fenner break; 111b0453382SBill Fenner #ifdef INET6 112b0453382SBill Fenner case ETHERTYPE_IPV6: 113b0453382SBill Fenner ip6_print((const u_char *)ip, length); 114b0453382SBill Fenner break; 115b0453382SBill Fenner #endif 116b0453382SBill Fenner case CHDLC_TYPE_SLARP: 117b0453382SBill Fenner chdlc_slarp_print((const u_char *)ip, length); 118b0453382SBill Fenner break; 119b0453382SBill Fenner #if 0 120b0453382SBill Fenner case CHDLC_TYPE_CDP: 121b0453382SBill Fenner chdlc_cdp_print((const u_char *)ip, length); 122b0453382SBill Fenner break; 123b0453382SBill Fenner #endif 124b0453382SBill Fenner } 125b0453382SBill Fenner if (xflag) 126b0453382SBill Fenner default_print((const u_char *)ip, caplen - CHDLC_HDRLEN); 127b0453382SBill Fenner } 128b0453382SBill Fenner 129b0453382SBill Fenner struct cisco_slarp { 130685295f4SBill Fenner u_int32_t code; 131b0453382SBill Fenner #define SLARP_REQUEST 0 132b0453382SBill Fenner #define SLARP_REPLY 1 133b0453382SBill Fenner #define SLARP_KEEPALIVE 2 134b0453382SBill Fenner union { 135b0453382SBill Fenner struct { 136b0453382SBill Fenner struct in_addr addr; 137b0453382SBill Fenner struct in_addr mask; 138685295f4SBill Fenner u_int16_t unused[3]; 139b0453382SBill Fenner } addr; 140b0453382SBill Fenner struct { 141685295f4SBill Fenner u_int32_t myseq; 142685295f4SBill Fenner u_int32_t yourseq; 143685295f4SBill Fenner u_int16_t rel; 144685295f4SBill Fenner u_int16_t t1; 145685295f4SBill Fenner u_int16_t t2; 146b0453382SBill Fenner } keep; 147b0453382SBill Fenner } un; 148b0453382SBill Fenner }; 149b0453382SBill Fenner 150b0453382SBill Fenner #define SLARP_LEN 18 151b0453382SBill Fenner 152b0453382SBill Fenner static void 153b0453382SBill Fenner chdlc_slarp_print(const u_char *cp, u_int length) 154b0453382SBill Fenner { 155a90e161bSBill Fenner const struct cisco_slarp *slarp; 156b0453382SBill Fenner 157b0453382SBill Fenner if (length < SLARP_LEN) { 158b0453382SBill Fenner printf("[|slarp]"); 159b0453382SBill Fenner return; 160b0453382SBill Fenner } 161b0453382SBill Fenner 162a90e161bSBill Fenner slarp = (const struct cisco_slarp *)cp; 163b0453382SBill Fenner switch (ntohl(slarp->code)) { 164b0453382SBill Fenner case SLARP_REQUEST: 165b0453382SBill Fenner printf("slarp-request"); 166b0453382SBill Fenner break; 167b0453382SBill Fenner case SLARP_REPLY: 168b0453382SBill Fenner printf("slarp-reply %s/%s", 169b0453382SBill Fenner ipaddr_string(&slarp->un.addr.addr), 170b0453382SBill Fenner ipaddr_string(&slarp->un.addr.mask)); 171b0453382SBill Fenner break; 172b0453382SBill Fenner case SLARP_KEEPALIVE: 173b0453382SBill Fenner printf("slarp-keepalive my=0x%x your=0x%x ", 174b0453382SBill Fenner (u_int32_t)ntohl(slarp->un.keep.myseq), 175b0453382SBill Fenner (u_int32_t)ntohl(slarp->un.keep.yourseq)); 176b0453382SBill Fenner printf("reliability=0x%04x t1=%d.%d", 177b0453382SBill Fenner ntohs(slarp->un.keep.rel), ntohs(slarp->un.keep.t1), 178b0453382SBill Fenner ntohs(slarp->un.keep.t2)); 179b0453382SBill Fenner break; 180b0453382SBill Fenner default: 181b0453382SBill Fenner printf("slarp-0x%x unknown", (u_int32_t)ntohl(slarp->code)); 182b0453382SBill Fenner break; 183b0453382SBill Fenner } 184b0453382SBill Fenner 185b0453382SBill Fenner if (SLARP_LEN < length && vflag) 186b0453382SBill Fenner printf("(trailing junk: %d bytes)", length - SLARP_LEN); 187b0453382SBill Fenner } 188