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