1/*
| 1/*
|
2 * Copyright (c) 1989, 1990, 1991, 1993, 1994, 1995, 1996
| 2 * Copyright (c) 1989, 1990, 1991, 1993, 1994, 1995, 1996, 1997
|
3 * The Regents of the University of California. All rights reserved. 4 * 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 16 * written permission. 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. 20 */ 21 22#ifndef lint 23static const char rcsid[] =
| 3 * The Regents of the University of California. All rights reserved. 4 * 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 16 * written permission. 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. 20 */ 21 22#ifndef lint 23static const char rcsid[] =
|
24 "@(#) $Header: print-sl.c,v 1.41 96/12/10 23:19:42 leres Exp $ (LBL)";
| 24 "@(#) $Header: print-sl.c,v 1.42 97/06/12 14:21:35 leres Exp $ (LBL)";
|
25#endif 26 27#ifdef HAVE_NET_SLIP_H 28#include <sys/param.h> 29#include <sys/time.h> 30#include <sys/timeb.h> 31#include <sys/file.h> 32#include <sys/ioctl.h> 33#include <sys/mbuf.h> 34#include <sys/socket.h> 35 36#if __STDC__ 37struct rtentry; 38#endif 39#include <net/if.h> 40 41#include <netinet/in.h> 42#include <netinet/in_systm.h> 43#include <netinet/ip.h> 44#include <net/ethernet.h> 45#include <netinet/ip_var.h> 46#include <netinet/udp.h> 47#include <netinet/udp_var.h> 48#include <netinet/tcp.h> 49#include <netinet/tcpip.h> 50 51#include <net/slcompress.h> 52#include <net/slip.h> 53 54#include <ctype.h> 55#include <netdb.h> 56#include <pcap.h>
| 25#endif 26 27#ifdef HAVE_NET_SLIP_H 28#include <sys/param.h> 29#include <sys/time.h> 30#include <sys/timeb.h> 31#include <sys/file.h> 32#include <sys/ioctl.h> 33#include <sys/mbuf.h> 34#include <sys/socket.h> 35 36#if __STDC__ 37struct rtentry; 38#endif 39#include <net/if.h> 40 41#include <netinet/in.h> 42#include <netinet/in_systm.h> 43#include <netinet/ip.h> 44#include <net/ethernet.h> 45#include <netinet/ip_var.h> 46#include <netinet/udp.h> 47#include <netinet/udp_var.h> 48#include <netinet/tcp.h> 49#include <netinet/tcpip.h> 50 51#include <net/slcompress.h> 52#include <net/slip.h> 53 54#include <ctype.h> 55#include <netdb.h> 56#include <pcap.h>
|
57#include <signal.h>
| |
58#include <stdio.h> 59 60#include "interface.h" 61#include "addrtoname.h" 62#include "extract.h" /* must come after interface.h */ 63 64static u_int lastlen[2][256]; 65static u_int lastconn = 255; 66 67static void sliplink_print(const u_char *, const struct ip *, u_int); 68static void compressed_sl_print(const u_char *, const struct ip *, u_int, int); 69 70/* XXX BSD/OS 2.1 compatibility */ 71#if !defined(SLIP_HDRLEN) && defined(SLC_BPFHDR) 72#define SLIP_HDRLEN SLC_BPFHDR 73#define SLX_DIR 0 74#define SLX_CHDR (SLC_BPFHDRLEN - 1) 75#define CHDR_LEN (SLC_BPFHDR - SLC_BPFHDRLEN) 76#endif 77
| 57#include <stdio.h> 58 59#include "interface.h" 60#include "addrtoname.h" 61#include "extract.h" /* must come after interface.h */ 62 63static u_int lastlen[2][256]; 64static u_int lastconn = 255; 65 66static void sliplink_print(const u_char *, const struct ip *, u_int); 67static void compressed_sl_print(const u_char *, const struct ip *, u_int, int); 68 69/* XXX BSD/OS 2.1 compatibility */ 70#if !defined(SLIP_HDRLEN) && defined(SLC_BPFHDR) 71#define SLIP_HDRLEN SLC_BPFHDR 72#define SLX_DIR 0 73#define SLX_CHDR (SLC_BPFHDRLEN - 1) 74#define CHDR_LEN (SLC_BPFHDR - SLC_BPFHDRLEN) 75#endif 76
|
| 77/* XXX needs more hacking to work right */ 78
|
78void 79sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) 80{ 81 register u_int caplen = h->caplen; 82 register u_int length = h->len; 83 register const struct ip *ip; 84 85 ts_print(&h->ts); 86 87 if (caplen < SLIP_HDRLEN) { 88 printf("[|slip]"); 89 goto out; 90 } 91 /* 92 * Some printers want to get back at the link level addresses, 93 * and/or check that they're not walking off the end of the packet. 94 * Rather than pass them all the way down, we set these globals. 95 */ 96 packetp = p; 97 snapend = p + caplen; 98 99 length -= SLIP_HDRLEN; 100 101 ip = (struct ip *)(p + SLIP_HDRLEN); 102 103 if (eflag) 104 sliplink_print(p, ip, length); 105 106 ip_print((u_char *)ip, length); 107 108 if (xflag) 109 default_print((u_char *)ip, caplen - SLIP_HDRLEN); 110 out: 111 putchar('\n'); 112} 113
| 79void 80sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) 81{ 82 register u_int caplen = h->caplen; 83 register u_int length = h->len; 84 register const struct ip *ip; 85 86 ts_print(&h->ts); 87 88 if (caplen < SLIP_HDRLEN) { 89 printf("[|slip]"); 90 goto out; 91 } 92 /* 93 * Some printers want to get back at the link level addresses, 94 * and/or check that they're not walking off the end of the packet. 95 * Rather than pass them all the way down, we set these globals. 96 */ 97 packetp = p; 98 snapend = p + caplen; 99 100 length -= SLIP_HDRLEN; 101 102 ip = (struct ip *)(p + SLIP_HDRLEN); 103 104 if (eflag) 105 sliplink_print(p, ip, length); 106 107 ip_print((u_char *)ip, length); 108 109 if (xflag) 110 default_print((u_char *)ip, caplen - SLIP_HDRLEN); 111 out: 112 putchar('\n'); 113} 114
|
| 115 116void 117sl_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) 118{ 119 register u_int caplen = h->caplen; 120 register u_int length = h->len; 121 register const struct ip *ip; 122 123 ts_print(&h->ts); 124 125 if (caplen < SLIP_HDRLEN) { 126 printf("[|slip]"); 127 goto out; 128 } 129 /* 130 * Some printers want to get back at the link level addresses, 131 * and/or check that they're not walking off the end of the packet. 132 * Rather than pass them all the way down, we set these globals. 133 */ 134 packetp = p; 135 snapend = p + caplen; 136 137 length -= SLIP_HDRLEN; 138 139 ip = (struct ip *)(p + SLIP_HDRLEN); 140 141#ifdef notdef 142 if (eflag) 143 sliplink_print(p, ip, length); 144#endif 145 146 ip_print((u_char *)ip, length); 147 148 if (xflag) 149 default_print((u_char *)ip, caplen - SLIP_HDRLEN); 150 out: 151 putchar('\n'); 152} 153
|
114static void 115sliplink_print(register const u_char *p, register const struct ip *ip, 116 register u_int length) 117{ 118 int dir; 119 u_int hlen; 120 121 dir = p[SLX_DIR]; 122 putchar(dir == SLIPDIR_IN ? 'I' : 'O'); 123 putchar(' '); 124 125 if (nflag) { 126 /* XXX just dump the header */ 127 register int i; 128 129 for (i = SLX_CHDR; i < SLX_CHDR + CHDR_LEN - 1; ++i) 130 printf("%02x.", p[i]); 131 printf("%02x: ", p[SLX_CHDR + CHDR_LEN - 1]); 132 return; 133 } 134 switch (p[SLX_CHDR] & 0xf0) { 135 136 case TYPE_IP: 137 printf("ip %d: ", length + SLIP_HDRLEN); 138 break; 139 140 case TYPE_UNCOMPRESSED_TCP: 141 /* 142 * The connection id is stored in the IP protocol field. 143 * Get it from the link layer since sl_uncompress_tcp() 144 * has restored the IP header copy to IPPROTO_TCP. 145 */ 146 lastconn = ((struct ip *)&p[SLX_CHDR])->ip_p; 147 hlen = ip->ip_hl; 148 hlen += ((struct tcphdr *)&((int *)ip)[hlen])->th_off; 149 lastlen[dir][lastconn] = length - (hlen << 2); 150 printf("utcp %d: ", lastconn); 151 break; 152 153 default: 154 if (p[SLX_CHDR] & TYPE_COMPRESSED_TCP) { 155 compressed_sl_print(&p[SLX_CHDR], ip, 156 length, dir); 157 printf(": "); 158 } else 159 printf("slip-%d!: ", p[SLX_CHDR]); 160 } 161} 162 163static const u_char * 164print_sl_change(const char *str, register const u_char *cp) 165{ 166 register u_int i; 167 168 if ((i = *cp++) == 0) { 169 i = EXTRACT_16BITS(cp); 170 cp += 2; 171 } 172 printf(" %s%d", str, i); 173 return (cp); 174} 175 176static const u_char * 177print_sl_winchange(register const u_char *cp) 178{ 179 register short i; 180 181 if ((i = *cp++) == 0) { 182 i = EXTRACT_16BITS(cp); 183 cp += 2; 184 } 185 if (i >= 0) 186 printf(" W+%d", i); 187 else 188 printf(" W%d", i); 189 return (cp); 190} 191 192static void 193compressed_sl_print(const u_char *chdr, const struct ip *ip, 194 u_int length, int dir) 195{ 196 register const u_char *cp = chdr; 197 register u_int flags, hlen; 198 199 flags = *cp++; 200 if (flags & NEW_C) { 201 lastconn = *cp++; 202 printf("ctcp %d", lastconn); 203 } else 204 printf("ctcp *"); 205 206 /* skip tcp checksum */ 207 cp += 2; 208 209 switch (flags & SPECIALS_MASK) { 210 case SPECIAL_I: 211 printf(" *SA+%d", lastlen[dir][lastconn]); 212 break; 213 214 case SPECIAL_D: 215 printf(" *S+%d", lastlen[dir][lastconn]); 216 break; 217 218 default: 219 if (flags & NEW_U) 220 cp = print_sl_change("U=", cp); 221 if (flags & NEW_W) 222 cp = print_sl_winchange(cp); 223 if (flags & NEW_A) 224 cp = print_sl_change("A+", cp); 225 if (flags & NEW_S) 226 cp = print_sl_change("S+", cp); 227 break; 228 } 229 if (flags & NEW_I) 230 cp = print_sl_change("I+", cp); 231 232 /* 233 * 'hlen' is the length of the uncompressed TCP/IP header (in words). 234 * 'cp - chdr' is the length of the compressed header. 235 * 'length - hlen' is the amount of data in the packet. 236 */ 237 hlen = ip->ip_hl; 238 hlen += ((struct tcphdr *)&((int32_t *)ip)[hlen])->th_off; 239 lastlen[dir][lastconn] = length - (hlen << 2); 240 printf(" %d (%d)", lastlen[dir][lastconn], cp - chdr); 241} 242#else 243#include <sys/types.h> 244#include <sys/time.h> 245 246#include <pcap.h> 247#include <stdio.h> 248 249#include "interface.h"
| 154static void 155sliplink_print(register const u_char *p, register const struct ip *ip, 156 register u_int length) 157{ 158 int dir; 159 u_int hlen; 160 161 dir = p[SLX_DIR]; 162 putchar(dir == SLIPDIR_IN ? 'I' : 'O'); 163 putchar(' '); 164 165 if (nflag) { 166 /* XXX just dump the header */ 167 register int i; 168 169 for (i = SLX_CHDR; i < SLX_CHDR + CHDR_LEN - 1; ++i) 170 printf("%02x.", p[i]); 171 printf("%02x: ", p[SLX_CHDR + CHDR_LEN - 1]); 172 return; 173 } 174 switch (p[SLX_CHDR] & 0xf0) { 175 176 case TYPE_IP: 177 printf("ip %d: ", length + SLIP_HDRLEN); 178 break; 179 180 case TYPE_UNCOMPRESSED_TCP: 181 /* 182 * The connection id is stored in the IP protocol field. 183 * Get it from the link layer since sl_uncompress_tcp() 184 * has restored the IP header copy to IPPROTO_TCP. 185 */ 186 lastconn = ((struct ip *)&p[SLX_CHDR])->ip_p; 187 hlen = ip->ip_hl; 188 hlen += ((struct tcphdr *)&((int *)ip)[hlen])->th_off; 189 lastlen[dir][lastconn] = length - (hlen << 2); 190 printf("utcp %d: ", lastconn); 191 break; 192 193 default: 194 if (p[SLX_CHDR] & TYPE_COMPRESSED_TCP) { 195 compressed_sl_print(&p[SLX_CHDR], ip, 196 length, dir); 197 printf(": "); 198 } else 199 printf("slip-%d!: ", p[SLX_CHDR]); 200 } 201} 202 203static const u_char * 204print_sl_change(const char *str, register const u_char *cp) 205{ 206 register u_int i; 207 208 if ((i = *cp++) == 0) { 209 i = EXTRACT_16BITS(cp); 210 cp += 2; 211 } 212 printf(" %s%d", str, i); 213 return (cp); 214} 215 216static const u_char * 217print_sl_winchange(register const u_char *cp) 218{ 219 register short i; 220 221 if ((i = *cp++) == 0) { 222 i = EXTRACT_16BITS(cp); 223 cp += 2; 224 } 225 if (i >= 0) 226 printf(" W+%d", i); 227 else 228 printf(" W%d", i); 229 return (cp); 230} 231 232static void 233compressed_sl_print(const u_char *chdr, const struct ip *ip, 234 u_int length, int dir) 235{ 236 register const u_char *cp = chdr; 237 register u_int flags, hlen; 238 239 flags = *cp++; 240 if (flags & NEW_C) { 241 lastconn = *cp++; 242 printf("ctcp %d", lastconn); 243 } else 244 printf("ctcp *"); 245 246 /* skip tcp checksum */ 247 cp += 2; 248 249 switch (flags & SPECIALS_MASK) { 250 case SPECIAL_I: 251 printf(" *SA+%d", lastlen[dir][lastconn]); 252 break; 253 254 case SPECIAL_D: 255 printf(" *S+%d", lastlen[dir][lastconn]); 256 break; 257 258 default: 259 if (flags & NEW_U) 260 cp = print_sl_change("U=", cp); 261 if (flags & NEW_W) 262 cp = print_sl_winchange(cp); 263 if (flags & NEW_A) 264 cp = print_sl_change("A+", cp); 265 if (flags & NEW_S) 266 cp = print_sl_change("S+", cp); 267 break; 268 } 269 if (flags & NEW_I) 270 cp = print_sl_change("I+", cp); 271 272 /* 273 * 'hlen' is the length of the uncompressed TCP/IP header (in words). 274 * 'cp - chdr' is the length of the compressed header. 275 * 'length - hlen' is the amount of data in the packet. 276 */ 277 hlen = ip->ip_hl; 278 hlen += ((struct tcphdr *)&((int32_t *)ip)[hlen])->th_off; 279 lastlen[dir][lastconn] = length - (hlen << 2); 280 printf(" %d (%d)", lastlen[dir][lastconn], cp - chdr); 281} 282#else 283#include <sys/types.h> 284#include <sys/time.h> 285 286#include <pcap.h> 287#include <stdio.h> 288 289#include "interface.h"
|
| 290
|
250void 251sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) 252{ 253 254 error("not configured for slip"); 255 /* NOTREACHED */ 256}
| 291void 292sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) 293{ 294 295 error("not configured for slip"); 296 /* NOTREACHED */ 297}
|
| 298 299void 300sl_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) 301{ 302 303 error("not configured for slip"); 304 /* NOTREACHED */ 305}
|
257#endif
| 306#endif
|