1 /* $OpenBSD: print-atm.c,v 1.8 2007/10/07 16:41:05 deraadt Exp $ */ 2 3 /* 4 * Copyright (c) 1994, 1995, 1996, 1997 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that: (1) source code distributions 9 * retain the above copyright notice and this paragraph in its entirety, (2) 10 * distributions including binary code include the above copyright notice and 11 * this paragraph in its entirety in the documentation or other materials 12 * provided with the distribution, and (3) all advertising materials mentioning 13 * features or use of this software display the following acknowledgement: 14 * ``This product includes software developed by the University of California, 15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 16 * the University nor the names of its contributors may be used to endorse 17 * or promote products derived from this software without specific prior 18 * written permission. 19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 22 */ 23 #ifndef lint 24 static const char rcsid[] = 25 "@(#) $Id: print-atm.c,v 1.8 2007/10/07 16:41:05 deraadt Exp $ (LBL)"; 26 #endif 27 28 #include <sys/param.h> 29 #include <sys/time.h> 30 #include <sys/socket.h> 31 32 struct mbuf; 33 struct rtentry; 34 #include <net/if.h> 35 36 #include <netinet/in.h> 37 #include <netinet/if_ether.h> 38 #include <netinet/in_systm.h> 39 #include <netinet/ip.h> 40 #include <netinet/ip_var.h> 41 #include <netinet/udp.h> 42 #include <netinet/udp_var.h> 43 #include <netinet/tcp.h> 44 45 #include <stdio.h> 46 #include <pcap.h> 47 48 #include "interface.h" 49 #include "addrtoname.h" 50 #include "ethertype.h" 51 52 /* 53 * This is the top level routine of the printer. 'p' is the points 54 * to the LLC/SNAP header of the packet, 'tvp' is the timestamp, 55 * 'length' is the length of the packet off the wire, and 'caplen' 56 * is the number of bytes actually captured. 57 */ 58 void 59 atm_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) 60 { 61 u_int caplen = h->caplen; 62 u_int length = h->len; 63 u_short ethertype; 64 65 ts_print(&h->ts); 66 67 if (caplen < 8) { 68 printf("[|atm]"); 69 goto out; 70 } 71 if (p[0] != 0xaa || p[1] != 0xaa || p[2] != 0x03) { 72 /*XXX assume 802.6 MAC header from fore driver */ 73 if (eflag) 74 printf("%04x%04x %04x%04x ", 75 p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3], 76 p[4] << 24 | p[5] << 16 | p[6] << 8 | p[7], 77 p[8] << 24 | p[9] << 16 | p[10] << 8 | p[11], 78 p[12] << 24 | p[13] << 16 | p[14] << 8 | p[15]); 79 p += 20; 80 length -= 20; 81 caplen -= 20; 82 } 83 ethertype = p[6] << 8 | p[7]; 84 if (eflag) 85 printf("%02x %02x %02x %02x-%02x-%02x %04x: ", 86 p[0], p[1], p[2], /* dsap/ssap/ctrl */ 87 p[3], p[4], p[5], /* manufacturer's code */ 88 ethertype); 89 90 /* 91 * Some printers want to get back at the ethernet addresses, 92 * and/or check that they're not walking off the end of the packet. 93 * Rather than pass them all the way down, we set these globals. 94 */ 95 packetp = p; 96 snapend = p + caplen; 97 98 length -= 8; 99 caplen -= 8; 100 p += 8; 101 102 switch (ethertype) { 103 104 case ETHERTYPE_IP: 105 ip_print(p, length); 106 break; 107 108 #ifdef INET6 109 case ETHERTYPE_IPV6: 110 ip6_print(p, length); 111 break; 112 #endif /*INET6*/ 113 114 /*XXX this probably isn't right */ 115 case ETHERTYPE_ARP: 116 case ETHERTYPE_REVARP: 117 arp_print(p, length, caplen); 118 break; 119 #ifdef notyet 120 case ETHERTYPE_DN: 121 decnet_print(p, length, caplen); 122 break; 123 124 case ETHERTYPE_ATALK: 125 if (vflag) 126 fputs("et1 ", stdout); 127 atalk_print(p, length); 128 break; 129 130 case ETHERTYPE_AARP: 131 aarp_print(p, length); 132 break; 133 134 case ETHERTYPE_LAT: 135 case ETHERTYPE_MOPRC: 136 case ETHERTYPE_MOPDL: 137 /* default_print for now */ 138 #endif 139 default: 140 /* ether_type not known, print raw packet */ 141 if (!eflag) 142 printf("%02x %02x %02x %02x-%02x-%02x %04x: ", 143 p[0], p[1], p[2], /* dsap/ssap/ctrl */ 144 p[3], p[4], p[5], /* manufacturer's code */ 145 ethertype); 146 if (!xflag && !qflag) 147 default_print(p, caplen); 148 } 149 if (xflag) 150 default_print(p, caplen); 151 out: 152 putchar('\n'); 153 } 154