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[] = 25b0453382SBill Fenner "@(#) $Header: /tcpdump/master/tcpdump/print-chdlc.c,v 1.2 1999/11/21 09:36:49 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 #include <sys/socket.h> 35b0453382SBill Fenner #include <sys/file.h> 36b0453382SBill Fenner #include <sys/ioctl.h> 37b0453382SBill Fenner 38b0453382SBill Fenner #if __STDC__ 39b0453382SBill Fenner struct mbuf; 40b0453382SBill Fenner struct rtentry; 41b0453382SBill Fenner #endif 42b0453382SBill Fenner #include <net/if.h> 43b0453382SBill Fenner 44b0453382SBill Fenner #include <netinet/in.h> 45b0453382SBill Fenner #include <netinet/in_systm.h> 46b0453382SBill Fenner #include <netinet/ip.h> 47b0453382SBill Fenner #include <netinet/if_ether.h> 48b0453382SBill Fenner 49b0453382SBill Fenner #include <ctype.h> 50b0453382SBill Fenner #include <netdb.h> 51b0453382SBill Fenner #include <pcap.h> 52b0453382SBill Fenner #include <stdio.h> 53b0453382SBill Fenner #ifdef __bsdi__ 54b0453382SBill Fenner #include <net/slcompress.h> 55b0453382SBill Fenner #include <net/if_ppp.h> 56b0453382SBill Fenner #endif 57b0453382SBill Fenner 58b0453382SBill Fenner #include "interface.h" 59b0453382SBill Fenner #include "addrtoname.h" 60b0453382SBill Fenner #include "ppp.h" 61b0453382SBill Fenner 62b0453382SBill Fenner /* XXX This goes somewhere else. */ 63b0453382SBill Fenner #define CHDLC_HDRLEN 4 64b0453382SBill Fenner #define CHDLC_UNICAST 0x0f 65b0453382SBill Fenner #define CHDLC_BCAST 0x8f 66b0453382SBill Fenner #define CHDLC_TYPE_SLARP 0x8035 67b0453382SBill Fenner #define CHDLC_TYPE_CDP 0x2000 68b0453382SBill Fenner 69b0453382SBill Fenner static void chdlc_slarp_print(const u_char *, u_int); 70b0453382SBill Fenner 71b0453382SBill Fenner /* Standard CHDLC printer */ 72b0453382SBill Fenner void 73b0453382SBill Fenner chdlc_if_print(u_char *user, const struct pcap_pkthdr *h, 74b0453382SBill Fenner register const u_char *p) 75b0453382SBill Fenner { 76b0453382SBill Fenner register u_int length = h->len; 77b0453382SBill Fenner register u_int caplen = h->caplen; 78b0453382SBill Fenner const struct ip *ip; 79b0453382SBill Fenner u_int proto; 80b0453382SBill Fenner 81b0453382SBill Fenner ts_print(&h->ts); 82b0453382SBill Fenner 83b0453382SBill Fenner if (caplen < CHDLC_HDRLEN) { 84b0453382SBill Fenner printf("[|chdlc]"); 85b0453382SBill Fenner goto out; 86b0453382SBill Fenner } 87b0453382SBill Fenner 88b0453382SBill Fenner /* 89b0453382SBill Fenner * Some printers want to get back at the link level addresses, 90b0453382SBill Fenner * and/or check that they're not walking off the end of the packet. 91b0453382SBill Fenner * Rather than pass them all the way down, we set these globals. 92b0453382SBill Fenner */ 93b0453382SBill Fenner proto = ntohs(*(u_short *)&p[2]); 94b0453382SBill Fenner packetp = p; 95b0453382SBill Fenner snapend = p + caplen; 96b0453382SBill Fenner 97b0453382SBill Fenner if (eflag) { 98b0453382SBill Fenner switch (p[0]) { 99b0453382SBill Fenner case CHDLC_UNICAST: 100b0453382SBill Fenner printf("unicast "); 101b0453382SBill Fenner break; 102b0453382SBill Fenner case CHDLC_BCAST: 103b0453382SBill Fenner printf("bcast "); 104b0453382SBill Fenner break; 105b0453382SBill Fenner default: 106b0453382SBill Fenner printf("0x%02x ", p[0]); 107b0453382SBill Fenner break; 108b0453382SBill Fenner } 109b0453382SBill Fenner printf("%d %04x: ", length, proto); 110b0453382SBill Fenner } 111b0453382SBill Fenner 112b0453382SBill Fenner length -= CHDLC_HDRLEN; 113b0453382SBill Fenner ip = (struct ip *)(p + CHDLC_HDRLEN); 114b0453382SBill Fenner switch(proto) { 115b0453382SBill Fenner case ETHERTYPE_IP: 116b0453382SBill Fenner ip_print((const u_char *)ip, length); 117b0453382SBill Fenner break; 118b0453382SBill Fenner #ifdef INET6 119b0453382SBill Fenner case ETHERTYPE_IPV6: 120b0453382SBill Fenner ip6_print((const u_char *)ip, length); 121b0453382SBill Fenner break; 122b0453382SBill Fenner #endif 123b0453382SBill Fenner case CHDLC_TYPE_SLARP: 124b0453382SBill Fenner chdlc_slarp_print((const u_char *)ip, length); 125b0453382SBill Fenner break; 126b0453382SBill Fenner #if 0 127b0453382SBill Fenner case CHDLC_TYPE_CDP: 128b0453382SBill Fenner chdlc_cdp_print((const u_char *)ip, length); 129b0453382SBill Fenner break; 130b0453382SBill Fenner #endif 131b0453382SBill Fenner } 132b0453382SBill Fenner if (xflag) 133b0453382SBill Fenner default_print((const u_char *)ip, caplen - CHDLC_HDRLEN); 134b0453382SBill Fenner out: 135b0453382SBill Fenner putchar('\n'); 136b0453382SBill Fenner } 137b0453382SBill Fenner 138b0453382SBill Fenner struct cisco_slarp { 139b0453382SBill Fenner long code; 140b0453382SBill Fenner #define SLARP_REQUEST 0 141b0453382SBill Fenner #define SLARP_REPLY 1 142b0453382SBill Fenner #define SLARP_KEEPALIVE 2 143b0453382SBill Fenner union { 144b0453382SBill Fenner struct { 145b0453382SBill Fenner struct in_addr addr; 146b0453382SBill Fenner struct in_addr mask; 147b0453382SBill Fenner u_short unused[3]; 148b0453382SBill Fenner } addr; 149b0453382SBill Fenner struct { 150b0453382SBill Fenner long myseq; 151b0453382SBill Fenner long yourseq; 152b0453382SBill Fenner short rel; 153b0453382SBill Fenner short t1; 154b0453382SBill Fenner short t2; 155b0453382SBill Fenner } keep; 156b0453382SBill Fenner } un; 157b0453382SBill Fenner }; 158b0453382SBill Fenner 159b0453382SBill Fenner #define SLARP_LEN 18 160b0453382SBill Fenner 161b0453382SBill Fenner static void 162b0453382SBill Fenner chdlc_slarp_print(const u_char *cp, u_int length) 163b0453382SBill Fenner { 164b0453382SBill Fenner struct cisco_slarp *slarp; 165b0453382SBill Fenner 166b0453382SBill Fenner if (length < SLARP_LEN) { 167b0453382SBill Fenner printf("[|slarp]"); 168b0453382SBill Fenner return; 169b0453382SBill Fenner } 170b0453382SBill Fenner 171b0453382SBill Fenner slarp = (struct cisco_slarp *)cp; 172b0453382SBill Fenner switch (ntohl(slarp->code)) { 173b0453382SBill Fenner case SLARP_REQUEST: 174b0453382SBill Fenner printf("slarp-request"); 175b0453382SBill Fenner break; 176b0453382SBill Fenner case SLARP_REPLY: 177b0453382SBill Fenner printf("slarp-reply %s/%s", 178b0453382SBill Fenner ipaddr_string(&slarp->un.addr.addr), 179b0453382SBill Fenner ipaddr_string(&slarp->un.addr.mask)); 180b0453382SBill Fenner break; 181b0453382SBill Fenner case SLARP_KEEPALIVE: 182b0453382SBill Fenner printf("slarp-keepalive my=0x%x your=0x%x ", 183b0453382SBill Fenner (u_int32_t)ntohl(slarp->un.keep.myseq), 184b0453382SBill Fenner (u_int32_t)ntohl(slarp->un.keep.yourseq)); 185b0453382SBill Fenner printf("reliability=0x%04x t1=%d.%d", 186b0453382SBill Fenner ntohs(slarp->un.keep.rel), ntohs(slarp->un.keep.t1), 187b0453382SBill Fenner ntohs(slarp->un.keep.t2)); 188b0453382SBill Fenner break; 189b0453382SBill Fenner default: 190b0453382SBill Fenner printf("slarp-0x%x unknown", (u_int32_t)ntohl(slarp->code)); 191b0453382SBill Fenner break; 192b0453382SBill Fenner } 193b0453382SBill Fenner 194b0453382SBill Fenner if (SLARP_LEN < length && vflag) 195b0453382SBill Fenner printf("(trailing junk: %d bytes)", length - SLARP_LEN); 196b0453382SBill Fenner } 197