1e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes/*
2e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
3e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *	The Regents of the University of California.  All rights reserved.
4e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *
5e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * Redistribution and use in source and binary forms, with or without
6e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * modification, are permitted provided that: (1) source code distributions
7e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * retain the above copyright notice and this paragraph in its entirety, (2)
8e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * distributions including binary code include the above copyright notice and
9e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * this paragraph in its entirety in the documentation or other materials
10e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * provided with the distribution, and (3) all advertising materials mentioning
11e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * features or use of this software display the following acknowledgement:
12e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * ``This product includes software developed by the University of California,
13e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * the University nor the names of its contributors may be used to endorse
15e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * or promote products derived from this software without specific prior
16e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * written permission.
17e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *
21e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * Support for splitting captures into multiple files with a maximum
22e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * file size:
23e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *
24e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * Copyright (c) 2001
25e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes *	Seth Webster <swebster@sst.ll.mit.edu>
26e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes */
27e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
28e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef HAVE_CONFIG_H
29e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#include "config.h"
30e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
31e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
32e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#include <stdlib.h>
33e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#include <string.h>
34e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
35e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#include <netdissect-stdinc.h>
36e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
37e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#include "netdissect.h"
38e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#include "addrtoname.h"
39e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#include "print.h"
40e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
41e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstruct printer {
42e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if_printer f;
43e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	int type;
44e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes};
45e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
46e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic const struct printer printers[] = {
47e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ ether_if_print,	DLT_EN10MB },
48e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_IPNET
49e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ ipnet_if_print,	DLT_IPNET },
50e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
51e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_IEEE802_15_4
52e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ ieee802_15_4_if_print, DLT_IEEE802_15_4 },
53e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
54e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_IEEE802_15_4_NOFCS
55e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ ieee802_15_4_if_print, DLT_IEEE802_15_4_NOFCS },
56e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
57e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_PPI
58e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ ppi_if_print,		DLT_PPI },
59e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
60e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_NETANALYZER
61e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ netanalyzer_if_print, DLT_NETANALYZER },
62e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
63e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_NETANALYZER_TRANSPARENT
64e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ netanalyzer_transparent_if_print, DLT_NETANALYZER_TRANSPARENT },
65e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
66e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#if defined(DLT_NFLOG) && defined(HAVE_PCAP_NFLOG_H)
67e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ nflog_if_print,	DLT_NFLOG},
68e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
69e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_CIP
70e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ cip_if_print,         DLT_CIP },
71e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
72e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_ATM_CLIP
73e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ cip_if_print,		DLT_ATM_CLIP },
74e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
75e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_IP_OVER_FC
76e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ ipfc_if_print,	DLT_IP_OVER_FC },
77e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
78e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ null_if_print,	DLT_NULL },
79e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_LOOP
80e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ null_if_print,	DLT_LOOP },
81e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
82e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_APPLE_IP_OVER_IEEE1394
83e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ ap1394_if_print,	DLT_APPLE_IP_OVER_IEEE1394 },
84e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
85e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#if defined(DLT_BLUETOOTH_HCI_H4_WITH_PHDR) && defined(HAVE_PCAP_BLUETOOTH_H)
86e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ bt_if_print,		DLT_BLUETOOTH_HCI_H4_WITH_PHDR},
87e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
88e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_LANE8023
89e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ lane_if_print,        DLT_LANE8023 },
90e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
91e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ arcnet_if_print,	DLT_ARCNET },
92e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_ARCNET_LINUX
93e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ arcnet_linux_if_print, DLT_ARCNET_LINUX },
94e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
95e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ raw_if_print,		DLT_RAW },
96e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_IPV4
97e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ raw_if_print,		DLT_IPV4 },
98e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
99e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_IPV6
100e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ raw_if_print,		DLT_IPV6 },
101e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
102e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef HAVE_PCAP_USB_H
103e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_USB_LINUX
104e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ usb_linux_48_byte_print, DLT_USB_LINUX},
105e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif /* DLT_USB_LINUX */
106e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_USB_LINUX_MMAPPED
107e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ usb_linux_64_byte_print, DLT_USB_LINUX_MMAPPED},
108e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif /* DLT_USB_LINUX_MMAPPED */
109e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif /* HAVE_PCAP_USB_H */
110e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_SYMANTEC_FIREWALL
111e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ symantec_if_print,	DLT_SYMANTEC_FIREWALL },
112e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
113e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_C_HDLC
114e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ chdlc_if_print,	DLT_C_HDLC },
115e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
116e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_HDLC
117e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ chdlc_if_print,	DLT_HDLC },
118e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
119e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_PPP_ETHER
120e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ pppoe_if_print,	DLT_PPP_ETHER },
121e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
122e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#if defined(DLT_PFLOG) && defined(HAVE_NET_IF_PFLOG_H)
123e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ pflog_if_print,	DLT_PFLOG },
124e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
125e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ token_if_print,	DLT_IEEE802 },
126e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ fddi_if_print,	DLT_FDDI },
127e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_LINUX_SLL
128e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ sll_if_print,		DLT_LINUX_SLL },
129e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
130e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_FR
131e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ fr_if_print,		DLT_FR },
132e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
133e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_FRELAY
134e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ fr_if_print,		DLT_FRELAY },
135e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
136e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_MFR
137e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ mfr_if_print,		DLT_MFR },
138e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
139e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ atm_if_print,		DLT_ATM_RFC1483 },
140e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_SUNATM
141e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ sunatm_if_print,	DLT_SUNATM },
142e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
143e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_ENC
144e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ enc_if_print,		DLT_ENC },
145e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
146e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ sl_if_print,		DLT_SLIP },
147e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_SLIP_BSDOS
148e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ sl_bsdos_if_print,	DLT_SLIP_BSDOS },
149e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
150e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_LTALK
151e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ ltalk_if_print,	DLT_LTALK },
152e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
153e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_JUNIPER_ATM1
154e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ juniper_atm1_print,	DLT_JUNIPER_ATM1 },
155e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
156e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_JUNIPER_ATM2
157e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ juniper_atm2_print,	DLT_JUNIPER_ATM2 },
158e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
159e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_JUNIPER_MFR
160e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ juniper_mfr_print,	DLT_JUNIPER_MFR },
161e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
162e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_JUNIPER_MLFR
163e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ juniper_mlfr_print,	DLT_JUNIPER_MLFR },
164e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
165e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_JUNIPER_MLPPP
166e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ juniper_mlppp_print,	DLT_JUNIPER_MLPPP },
167e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
168e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_JUNIPER_PPPOE
169e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ juniper_pppoe_print,	DLT_JUNIPER_PPPOE },
170e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
171e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_JUNIPER_PPPOE_ATM
172e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ juniper_pppoe_atm_print, DLT_JUNIPER_PPPOE_ATM },
173e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
174e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_JUNIPER_GGSN
175e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ juniper_ggsn_print,	DLT_JUNIPER_GGSN },
176e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
177e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_JUNIPER_ES
178e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ juniper_es_print,	DLT_JUNIPER_ES },
179e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
180e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_JUNIPER_MONITOR
181e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ juniper_monitor_print, DLT_JUNIPER_MONITOR },
182e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
183e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_JUNIPER_SERVICES
184e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ juniper_services_print, DLT_JUNIPER_SERVICES },
185e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
186e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_JUNIPER_ETHER
187e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ juniper_ether_print,	DLT_JUNIPER_ETHER },
188e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
189e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_JUNIPER_PPP
190e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ juniper_ppp_print,	DLT_JUNIPER_PPP },
191e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
192e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_JUNIPER_FRELAY
193e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ juniper_frelay_print,	DLT_JUNIPER_FRELAY },
194e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
195e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_JUNIPER_CHDLC
196e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ juniper_chdlc_print,	DLT_JUNIPER_CHDLC },
197e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
198e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_PKTAP
199e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ pktap_if_print,	DLT_PKTAP },
200e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
201e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_IEEE802_11_RADIO
202e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ ieee802_11_radio_if_print,	DLT_IEEE802_11_RADIO },
203e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
204e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_IEEE802_11
205e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ ieee802_11_if_print,	DLT_IEEE802_11},
206e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
207e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_IEEE802_11_RADIO_AVS
208e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ ieee802_11_radio_avs_if_print,	DLT_IEEE802_11_RADIO_AVS },
209e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
210e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_PRISM_HEADER
211e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ prism_if_print,	DLT_PRISM_HEADER },
212e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
213e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ ppp_if_print,		DLT_PPP },
214e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_PPP_WITHDIRECTION
215e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ ppp_if_print,		DLT_PPP_WITHDIRECTION },
216e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
217e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_PPP_BSDOS
218e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ ppp_bsdos_if_print,	DLT_PPP_BSDOS },
219e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
220e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef DLT_PPP_SERIAL
221e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ ppp_hdlc_if_print,	DLT_PPP_SERIAL },
222e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
223e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	{ NULL,			0 },
224e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes};
225e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
226e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic void	ndo_default_print(netdissect_options *ndo, const u_char *bp,
227e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		    u_int length);
228e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
229e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic void	ndo_error(netdissect_options *ndo, const char *fmt, ...)
230e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		    __attribute__((noreturn))
231e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef __ATTRIBUTE___FORMAT_OK
232e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		    __attribute__((format (printf, 2, 3)))
233e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif /* __ATTRIBUTE___FORMAT_OK */
234e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		    ;
235e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic void	ndo_warning(netdissect_options *ndo, const char *fmt, ...)
236e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef __ATTRIBUTE___FORMAT_OK
237e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		    __attribute__((format (printf, 2, 3)))
238e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif /* __ATTRIBUTE___FORMAT_OK */
239e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		    ;
240e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
241e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic int	ndo_printf(netdissect_options *ndo, const char *fmt, ...)
242e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#ifdef __ATTRIBUTE___FORMAT_OK
243e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		     __attribute ((format (printf, 2, 3)))
244e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif /* __ATTRIBUTE___FORMAT_OK */
245e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		     ;
246e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
247e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesvoid
248e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesinit_print(netdissect_options *ndo, uint32_t localnet, uint32_t mask,
249e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes    uint32_t timezone_offset)
250e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes{
251e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
252e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	thiszone = timezone_offset;
253e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	init_addrtoname(ndo, localnet, mask);
254e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	init_checksum();
255e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes}
256e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
257e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesif_printer
258e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hugheslookup_printer(int type)
259e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes{
260e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	const struct printer *p;
261e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
262e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	for (p = printers; p->f; ++p)
263e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		if (type == p->type)
264e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			return p->f;
265e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
266e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#if defined(DLT_USER2) && defined(DLT_PKTAP)
267e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	/*
268e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * Apple incorrectly chose to use DLT_USER2 for their PKTAP
269e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * header.
270e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 *
271e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * We map DLT_PKTAP, whether it's DLT_USER2 as it is on Darwin-
272e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * based OSes or the same value as LINKTYPE_PKTAP as it is on
273e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * other OSes, to LINKTYPE_PKTAP, so files written with
274e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * this version of libpcap for a DLT_PKTAP capture have a link-
275e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * layer header type of LINKTYPE_PKTAP.
276e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 *
277e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * However, files written on OS X Mavericks for a DLT_PKTAP
278e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * capture have a link-layer header type of LINKTYPE_USER2.
279e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * If we don't have a printer for DLT_USER2, and type is
280e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * DLT_USER2, we look up the printer for DLT_PKTAP and use
281e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * that.
282e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 */
283e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if (type == DLT_USER2) {
284e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		for (p = printers; p->f; ++p)
285e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			if (DLT_PKTAP == p->type)
286e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				return p->f;
287e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	}
288e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes#endif
289e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
290e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	return NULL;
291e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	/* NOTREACHED */
292e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes}
293e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
294e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesint
295e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hugheshas_printer(int type)
296e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes{
297e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	return (lookup_printer(type) != NULL);
298e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes}
299e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
300e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesif_printer
301e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesget_if_printer(netdissect_options *ndo, int type)
302e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes{
303e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	const char *dltname;
304e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if_printer printer;
305e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
306e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	printer = lookup_printer(type);
307e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if (printer == NULL) {
308e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		dltname = pcap_datalink_val_to_name(type);
309e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		if (dltname != NULL)
310e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			(*ndo->ndo_error)(ndo,
311e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes					  "packet printing is not supported for link type %s: use -w",
312e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes					  dltname);
313e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		else
314e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			(*ndo->ndo_error)(ndo,
315e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes					  "packet printing is not supported for link type %d: use -w", type);
316e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	}
317e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	return printer;
318e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes}
319e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
320e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesvoid
321e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughespretty_print_packet(netdissect_options *ndo, const struct pcap_pkthdr *h,
322e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes    const u_char *sp, u_int packets_captured)
323e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes{
324e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	u_int hdrlen;
325e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
326e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if(ndo->ndo_packet_number)
327e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		ND_PRINT((ndo, "%5u  ", packets_captured));
328e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
329e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	ts_print(ndo, &h->ts);
330e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
331e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	/*
332e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * Some printers want to check that they're not walking off the
333e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * end of the packet.
334e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * Rather than pass it all the way down, we set this member
335e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * of the netdissect_options structure.
336e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 */
337e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	ndo->ndo_snapend = sp + h->caplen;
338e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
339e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes        hdrlen = (ndo->ndo_if_printer)(ndo, h, sp);
340e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
341e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	/*
342e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * Restore the original snapend, as a printer might have
343e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 * changed it.
344e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	 */
345e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	ndo->ndo_snapend = sp + h->caplen;
346e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if (ndo->ndo_Xflag) {
347e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		/*
348e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		 * Print the raw packet data in hex and ASCII.
349e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		 */
350e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		if (ndo->ndo_Xflag > 1) {
351e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			/*
352e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 * Include the link-layer header.
353e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 */
354e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			hex_and_ascii_print(ndo, "\n\t", sp, h->caplen);
355e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		} else {
356e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			/*
357e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 * Don't include the link-layer header - and if
358e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 * we have nothing past the link-layer header,
359e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 * print nothing.
360e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 */
361e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			if (h->caplen > hdrlen)
362e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				hex_and_ascii_print(ndo, "\n\t", sp + hdrlen,
363e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				    h->caplen - hdrlen);
364e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		}
365e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	} else if (ndo->ndo_xflag) {
366e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		/*
367e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		 * Print the raw packet data in hex.
368e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		 */
369e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		if (ndo->ndo_xflag > 1) {
370e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			/*
371e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 * Include the link-layer header.
372e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 */
373e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes                        hex_print(ndo, "\n\t", sp, h->caplen);
374e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		} else {
375e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			/*
376e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 * Don't include the link-layer header - and if
377e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 * we have nothing past the link-layer header,
378e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 * print nothing.
379e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 */
380e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			if (h->caplen > hdrlen)
381e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				hex_print(ndo, "\n\t", sp + hdrlen,
382e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes                                          h->caplen - hdrlen);
383e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		}
384e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	} else if (ndo->ndo_Aflag) {
385e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		/*
386e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		 * Print the raw packet data in ASCII.
387e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		 */
388e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		if (ndo->ndo_Aflag > 1) {
389e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			/*
390e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 * Include the link-layer header.
391e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 */
392e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			ascii_print(ndo, sp, h->caplen);
393e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		} else {
394e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			/*
395e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 * Don't include the link-layer header - and if
396e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 * we have nothing past the link-layer header,
397e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 * print nothing.
398e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			 */
399e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			if (h->caplen > hdrlen)
400e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes				ascii_print(ndo, sp + hdrlen, h->caplen - hdrlen);
401e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		}
402e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	}
403e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
404e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	ND_PRINT((ndo, "\n"));
405e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes}
406e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
407e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes/*
408e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * By default, print the specified data out in hex and ASCII.
409e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes */
410e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic void
411e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesndo_default_print(netdissect_options *ndo, const u_char *bp, u_int length)
412e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes{
413e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	hex_and_ascii_print(ndo, "\n\t", bp, length); /* pass on lf and indentation string */
414e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes}
415e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
416e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes/* VARARGS */
417e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic void
418e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesndo_error(netdissect_options *ndo, const char *fmt, ...)
419e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes{
420e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	va_list ap;
421e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
422e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if(ndo->program_name)
423e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		(void)fprintf(stderr, "%s: ", ndo->program_name);
424e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	va_start(ap, fmt);
425e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	(void)vfprintf(stderr, fmt, ap);
426e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	va_end(ap);
427e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if (*fmt) {
428e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		fmt += strlen(fmt);
429e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		if (fmt[-1] != '\n')
430e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			(void)fputc('\n', stderr);
431e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	}
432e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	nd_cleanup();
433e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	exit(1);
434e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	/* NOTREACHED */
435e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes}
436e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
437e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes/* VARARGS */
438e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic void
439e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesndo_warning(netdissect_options *ndo, const char *fmt, ...)
440e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes{
441e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	va_list ap;
442e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
443e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if(ndo->program_name)
444e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		(void)fprintf(stderr, "%s: ", ndo->program_name);
445e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	(void)fprintf(stderr, "WARNING: ");
446e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	va_start(ap, fmt);
447e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	(void)vfprintf(stderr, fmt, ap);
448e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	va_end(ap);
449e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if (*fmt) {
450e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		fmt += strlen(fmt);
451e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		if (fmt[-1] != '\n')
452e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes			(void)fputc('\n', stderr);
453e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	}
454e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes}
455e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
456e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesstatic int
457e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesndo_printf(netdissect_options *ndo, const char *fmt, ...)
458e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes{
459e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	va_list args;
460e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	int ret;
461e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
462e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	va_start(args, fmt);
463e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	ret = vfprintf(stdout, fmt, args);
464e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	va_end(args);
465e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
466e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	if (ret < 0)
467e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes		ndo_error(ndo, "Unable to write output: %s", pcap_strerror(errno));
468e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	return (ret);
469e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes}
470e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes
471e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesvoid
472e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughesndo_set_function_pointers(netdissect_options *ndo)
473e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes{
474e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	ndo->ndo_default_print=ndo_default_print;
475e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	ndo->ndo_printf=ndo_printf;
476e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	ndo->ndo_error=ndo_error;
477e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes	ndo->ndo_warning=ndo_warning;
478e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes}
479e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes/*
480e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * Local Variables:
481e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * c-style: whitesmith
482e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * c-basic-offset: 8
483e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes * End:
484e2e3bd11bd7561bc9d6686283a668fa94e1206b7Elliott Hughes */
485