xref: /freebsd/contrib/tcpdump/netdissect.h (revision 1ad8d2ee)
11de50e9fSSam Leffler /*
21de50e9fSSam Leffler  * Copyright (c) 1988-1997
31de50e9fSSam Leffler  *	The Regents of the University of California.  All rights reserved.
41de50e9fSSam Leffler  *
5d03c0883SXin LI  * Copyright (c) 1998-2012  Michael Richardson <mcr@tcpdump.org>
61de50e9fSSam Leffler  *      The TCPDUMP project
71de50e9fSSam Leffler  *
81de50e9fSSam Leffler  * Redistribution and use in source and binary forms, with or without
91de50e9fSSam Leffler  * modification, are permitted provided that: (1) source code distributions
101de50e9fSSam Leffler  * retain the above copyright notice and this paragraph in its entirety, (2)
111de50e9fSSam Leffler  * distributions including binary code include the above copyright notice and
121de50e9fSSam Leffler  * this paragraph in its entirety in the documentation or other materials
131de50e9fSSam Leffler  * provided with the distribution, and (3) all advertising materials mentioning
141de50e9fSSam Leffler  * features or use of this software display the following acknowledgement:
151de50e9fSSam Leffler  * ``This product includes software developed by the University of California,
161de50e9fSSam Leffler  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
171de50e9fSSam Leffler  * the University nor the names of its contributors may be used to endorse
181de50e9fSSam Leffler  * or promote products derived from this software without specific prior
191de50e9fSSam Leffler  * written permission.
201de50e9fSSam Leffler  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
211de50e9fSSam Leffler  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
221de50e9fSSam Leffler  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
231de50e9fSSam Leffler  */
241de50e9fSSam Leffler 
251de50e9fSSam Leffler #ifndef netdissect_h
261de50e9fSSam Leffler #define netdissect_h
271de50e9fSSam Leffler 
281de50e9fSSam Leffler #ifdef HAVE_OS_PROTO_H
291de50e9fSSam Leffler #include "os-proto.h"
301de50e9fSSam Leffler #endif
311de50e9fSSam Leffler #include <sys/types.h>
32ee67461eSJoseph Mingrone #include <setjmp.h>
33ee67461eSJoseph Mingrone #include "status-exit-codes.h"
34ee67461eSJoseph Mingrone #include "funcattrs.h" /* for PRINTFLIKE_FUNCPTR() */
35ee67461eSJoseph Mingrone #include "diag-control.h" /* for ND_UNREACHABLE */
361de50e9fSSam Leffler 
373340d773SGleb Smirnoff /*
383340d773SGleb Smirnoff  * Data types corresponding to multi-byte integral values within data
393340d773SGleb Smirnoff  * structures.  These are defined as arrays of octets, so that they're
403340d773SGleb Smirnoff  * not aligned on their "natural" boundaries, and so that you *must*
413340d773SGleb Smirnoff  * use the EXTRACT_ macros to extract them (which you should be doing
423340d773SGleb Smirnoff  * *anyway*, so as not to assume a particular byte order or alignment
433340d773SGleb Smirnoff  * in your code).
44ee67461eSJoseph Mingrone  *
45ee67461eSJoseph Mingrone  * We even want EXTRACT_U_1 used for 8-bit integral values, so we
46ee67461eSJoseph Mingrone  * define nd_uint8_t and nd_int8_t as arrays as well.
473340d773SGleb Smirnoff  */
48ee67461eSJoseph Mingrone typedef unsigned char nd_uint8_t[1];
493340d773SGleb Smirnoff typedef unsigned char nd_uint16_t[2];
503340d773SGleb Smirnoff typedef unsigned char nd_uint24_t[3];
513340d773SGleb Smirnoff typedef unsigned char nd_uint32_t[4];
523340d773SGleb Smirnoff typedef unsigned char nd_uint40_t[5];
533340d773SGleb Smirnoff typedef unsigned char nd_uint48_t[6];
543340d773SGleb Smirnoff typedef unsigned char nd_uint56_t[7];
553340d773SGleb Smirnoff typedef unsigned char nd_uint64_t[8];
563340d773SGleb Smirnoff 
57ee67461eSJoseph Mingrone typedef signed char nd_int8_t[1];
583340d773SGleb Smirnoff 
593340d773SGleb Smirnoff /*
60ee67461eSJoseph Mingrone  * "unsigned char" so that sign extension isn't done on the
61ee67461eSJoseph Mingrone  * individual bytes while they're being assembled.
623340d773SGleb Smirnoff  */
63ee67461eSJoseph Mingrone typedef unsigned char nd_int32_t[4];
64ee67461eSJoseph Mingrone typedef unsigned char nd_int64_t[8];
653340d773SGleb Smirnoff 
66ee67461eSJoseph Mingrone #define	FMAXINT	(4294967296.0)	/* floating point rep. of MAXINT */
67ee67461eSJoseph Mingrone 
68ee67461eSJoseph Mingrone /*
69ee67461eSJoseph Mingrone  * Use this for IPv4 addresses and netmasks.
70ee67461eSJoseph Mingrone  *
71ee67461eSJoseph Mingrone  * It's defined as an array of octets, so that it's not guaranteed to
72ee67461eSJoseph Mingrone  * be aligned on its "natural" boundary (in some packet formats, it
73ee67461eSJoseph Mingrone  * *isn't* so aligned).  We have separate EXTRACT_ calls for them;
74ee67461eSJoseph Mingrone  * sometimes you want the host-byte-order value, other times you want
75ee67461eSJoseph Mingrone  * the network-byte-order value.
76ee67461eSJoseph Mingrone  *
77ee67461eSJoseph Mingrone  * Don't use EXTRACT_BE_U_4() on them, use EXTRACT_IPV4_TO_HOST_ORDER()
78ee67461eSJoseph Mingrone  * if you want them in host byte order and EXTRACT_IPV4_TO_NETWORK_ORDER()
79ee67461eSJoseph Mingrone  * if you want them in network byte order (which you want with system APIs
80ee67461eSJoseph Mingrone  * that expect network-order IPv4 addresses, such as inet_ntop()).
81ee67461eSJoseph Mingrone  *
82ee67461eSJoseph Mingrone  * If, on your little-endian machine (e.g., an "IBM-compatible PC", no matter
83ee67461eSJoseph Mingrone  * what the OS, or an Intel Mac, no matter what the OS), you get the wrong
84ee67461eSJoseph Mingrone  * answer, and you've used EXTRACT_BE_U_4(), do *N*O*T* "fix" this by using
85ee67461eSJoseph Mingrone  * EXTRACT_LE_U_4(), fix it by using EXTRACT_IPV4_TO_NETWORK_ORDER(),
86ee67461eSJoseph Mingrone  * otherwise you're breaking the result on big-endian machines (e.g.,
87ee67461eSJoseph Mingrone  * most PowerPC/Power ISA machines, System/390 and z/Architecture, SPARC,
88ee67461eSJoseph Mingrone  * etc.).
89ee67461eSJoseph Mingrone  *
90ee67461eSJoseph Mingrone  * Yes, people do this; that's why Wireshark has tvb_get_ipv4(), to extract
91ee67461eSJoseph Mingrone  * an IPv4 address from a packet data buffer; it was introduced in reaction
92ee67461eSJoseph Mingrone  * to somebody who *had* done that.
93ee67461eSJoseph Mingrone  */
94ee67461eSJoseph Mingrone typedef unsigned char nd_ipv4[4];
95ee67461eSJoseph Mingrone 
96ee67461eSJoseph Mingrone /*
97ee67461eSJoseph Mingrone  * Use this for IPv6 addresses and netmasks.
98ee67461eSJoseph Mingrone  */
99ee67461eSJoseph Mingrone typedef unsigned char nd_ipv6[16];
100ee67461eSJoseph Mingrone 
101ee67461eSJoseph Mingrone /*
102ee67461eSJoseph Mingrone  * Use this for MAC addresses.
103ee67461eSJoseph Mingrone  */
104ee67461eSJoseph Mingrone #define MAC_ADDR_LEN	6U		/* length of MAC addresses */
105ee67461eSJoseph Mingrone typedef unsigned char nd_mac_addr[MAC_ADDR_LEN];
106ee67461eSJoseph Mingrone 
107ee67461eSJoseph Mingrone /*
108ee67461eSJoseph Mingrone  * Use this for blobs of bytes; make them arrays of nd_byte.
109ee67461eSJoseph Mingrone  */
110ee67461eSJoseph Mingrone typedef unsigned char nd_byte;
111ee67461eSJoseph Mingrone 
112ee67461eSJoseph Mingrone /*
113ee67461eSJoseph Mingrone  * Round up x to a multiple of y; y must be a power of 2.
114ee67461eSJoseph Mingrone  */
115ee67461eSJoseph Mingrone #ifndef roundup2
116ee67461eSJoseph Mingrone #define	roundup2(x, y)	(((x)+((u_int)((y)-1)))&(~((u_int)((y)-1))))
117ee67461eSJoseph Mingrone #endif
1181de50e9fSSam Leffler 
1191de50e9fSSam Leffler #include <stdarg.h>
1203340d773SGleb Smirnoff #include <pcap.h>
1211de50e9fSSam Leffler 
1223c602fabSXin LI #include "ip.h" /* struct ip for nextproto4_cksum() */
1233340d773SGleb Smirnoff #include "ip6.h" /* struct ip6 for nextproto6_cksum() */
1243340d773SGleb Smirnoff 
1251de50e9fSSam Leffler #ifndef HAVE_STRLCAT
1261de50e9fSSam Leffler extern size_t strlcat (char *, const char *, size_t);
1271de50e9fSSam Leffler #endif
1281de50e9fSSam Leffler #ifndef HAVE_STRLCPY
1291de50e9fSSam Leffler extern size_t strlcpy (char *, const char *, size_t);
1301de50e9fSSam Leffler #endif
1311de50e9fSSam Leffler 
1321de50e9fSSam Leffler #ifndef HAVE_STRDUP
1331de50e9fSSam Leffler extern char *strdup (const char *str);
1341de50e9fSSam Leffler #endif
1351de50e9fSSam Leffler 
1361de50e9fSSam Leffler #ifndef HAVE_STRSEP
1371de50e9fSSam Leffler extern char *strsep(char **, const char *);
1381de50e9fSSam Leffler #endif
1391de50e9fSSam Leffler 
1401de50e9fSSam Leffler struct tok {
1413c602fabSXin LI 	u_int v;		/* value */
1421de50e9fSSam Leffler 	const char *s;		/* string */
1431de50e9fSSam Leffler };
1441de50e9fSSam Leffler 
1451de50e9fSSam Leffler /* tok2str is deprecated */
1468bdc5a62SPatrick Kelsey extern const char *tok2str(const struct tok *, const char *, u_int);
1478bdc5a62SPatrick Kelsey extern char *bittok2str(const struct tok *, const char *, u_int);
1488bdc5a62SPatrick Kelsey extern char *bittok2str_nosep(const struct tok *, const char *, u_int);
1491de50e9fSSam Leffler 
1503340d773SGleb Smirnoff /* Initialize netdissect. */
1513340d773SGleb Smirnoff extern int nd_init(char *, size_t);
1523340d773SGleb Smirnoff /* Clean up netdissect. */
1533340d773SGleb Smirnoff extern void nd_cleanup(void);
1543340d773SGleb Smirnoff 
1553340d773SGleb Smirnoff /* Do we have libsmi support? */
1563340d773SGleb Smirnoff extern int nd_have_smi_support(void);
1573340d773SGleb Smirnoff /* Load an SMI module. */
1583340d773SGleb Smirnoff extern int nd_load_smi_module(const char *, char *, size_t);
1593340d773SGleb Smirnoff /* Flag indicating whether an SMI module has been loaded. */
1603340d773SGleb Smirnoff extern int nd_smi_module_loaded;
1613340d773SGleb Smirnoff /* Version number of the SMI library, or NULL if we don't have libsmi support. */
1623340d773SGleb Smirnoff extern const char *nd_smi_version_string(void);
1631de50e9fSSam Leffler 
1641de50e9fSSam Leffler typedef struct netdissect_options netdissect_options;
1651de50e9fSSam Leffler 
1663340d773SGleb Smirnoff #define IF_PRINTER_ARGS (netdissect_options *, const struct pcap_pkthdr *, const u_char *)
1673340d773SGleb Smirnoff 
168ee67461eSJoseph Mingrone typedef void (*if_printer) IF_PRINTER_ARGS;
169ee67461eSJoseph Mingrone 
170ee67461eSJoseph Mingrone /*
171ee67461eSJoseph Mingrone  * In case the data in a buffer needs to be processed by being decrypted,
172ee67461eSJoseph Mingrone  * decompressed, etc. before it's dissected, we can't process it in place,
173ee67461eSJoseph Mingrone  * we have to allocate a new buffer for the processed data.
174ee67461eSJoseph Mingrone  *
175ee67461eSJoseph Mingrone  * We keep a stack of those buffers; when we allocate a new buffer, we
176ee67461eSJoseph Mingrone  * push the current one onto a stack, and when we're done with the new
177ee67461eSJoseph Mingrone  * buffer, we free the current buffer and pop the previous one off the
178ee67461eSJoseph Mingrone  * stack.
179ee67461eSJoseph Mingrone  *
180ee67461eSJoseph Mingrone  * A buffer has a beginning and end pointer, and a link to the previous
181ee67461eSJoseph Mingrone  * buffer on the stack.
182ee67461eSJoseph Mingrone  *
183ee67461eSJoseph Mingrone  * In other cases, we temporarily adjust the snapshot end to reflect a
184ee67461eSJoseph Mingrone  * packet-length field in the packet data and, when finished dissecting
185ee67461eSJoseph Mingrone  * that part of the packet, restore the old snapshot end.  We keep that
186ee67461eSJoseph Mingrone  * on the stack with null buffer pointer, meaning there's nothing to
187ee67461eSJoseph Mingrone  * free.
188ee67461eSJoseph Mingrone  */
189ee67461eSJoseph Mingrone struct netdissect_saved_packet_info {
190ee67461eSJoseph Mingrone   u_char *ndspi_buffer;					/* pointer to allocated buffer data */
191ee67461eSJoseph Mingrone   const u_char *ndspi_packetp;				/* saved beginning of data */
192ee67461eSJoseph Mingrone   const u_char *ndspi_snapend;				/* saved end of data */
193ee67461eSJoseph Mingrone   struct netdissect_saved_packet_info *ndspi_prev;	/* previous buffer on the stack */
194ee67461eSJoseph Mingrone };
195ee67461eSJoseph Mingrone 
196ee67461eSJoseph Mingrone /* 'val' value(s) for longjmp */
197ee67461eSJoseph Mingrone #define ND_TRUNCATED 1
1983340d773SGleb Smirnoff 
1991de50e9fSSam Leffler struct netdissect_options {
20027df3f5dSRui Paulo   int ndo_bflag;		/* print 4 byte ASes in ASDOT notation */
2011de50e9fSSam Leffler   int ndo_eflag;		/* print ethernet header */
2021de50e9fSSam Leffler   int ndo_fflag;		/* don't translate "foreign" IP address */
203ee67461eSJoseph Mingrone   int ndo_Kflag;		/* don't check IP, TCP or UDP checksums */
2041de50e9fSSam Leffler   int ndo_nflag;		/* leave addresses as numbers */
2051de50e9fSSam Leffler   int ndo_Nflag;		/* remove domains from printed host names */
2061de50e9fSSam Leffler   int ndo_qflag;		/* quick (shorter) output */
2071de50e9fSSam Leffler   int ndo_Sflag;		/* print raw TCP sequence numbers */
2081de50e9fSSam Leffler   int ndo_tflag;		/* print packet arrival time */
2091de50e9fSSam Leffler   int ndo_uflag;		/* Print undecoded NFS handles */
2103340d773SGleb Smirnoff   int ndo_vflag;		/* verbosity level */
2111de50e9fSSam Leffler   int ndo_xflag;		/* print packet in hex */
212ee67461eSJoseph Mingrone   int ndo_Xflag;		/* print packet in hex/ASCII */
213ee67461eSJoseph Mingrone   int ndo_Aflag;		/* print packet only in ASCII observing TAB,
2141de50e9fSSam Leffler 				 * LF, CR and SPACE as graphical chars
2151de50e9fSSam Leffler 				 */
216cac3dcd5SXin LI   int ndo_Hflag;		/* dissect 802.11s draft mesh standard */
217ee67461eSJoseph Mingrone   const char *ndo_protocol;	/* protocol */
218ee67461eSJoseph Mingrone   jmp_buf ndo_early_end;	/* jmp_buf for setjmp()/longjmp() */
219ee67461eSJoseph Mingrone   void *ndo_last_mem_p;		/* pointer to the last allocated memory chunk */
2203c602fabSXin LI   int ndo_packet_number;	/* print a packet number in the beginning of line */
2212ebc47dbSSam Leffler   int ndo_suppress_default_print; /* don't use default_print() for unknown packet types */
2223c602fabSXin LI   int ndo_tstamp_precision;	/* requested time stamp precision */
2233340d773SGleb Smirnoff   const char *program_name;	/* Name of the program using the library */
2241de50e9fSSam Leffler 
2251de50e9fSSam Leffler   char *ndo_espsecret;
2261de50e9fSSam Leffler   struct sa_list *ndo_sa_list_head;  /* used by print-esp.c */
2271de50e9fSSam Leffler   struct sa_list *ndo_sa_default;
2281de50e9fSSam Leffler 
22927df3f5dSRui Paulo   char *ndo_sigsecret;		/* Signature verification secret key */
2301de50e9fSSam Leffler 
2311de50e9fSSam Leffler   int   ndo_packettype;	/* as specified by -T */
2321de50e9fSSam Leffler 
2331de50e9fSSam Leffler   int   ndo_snaplen;
234ee67461eSJoseph Mingrone   int   ndo_ll_hdr_len;	/* link-layer header length */
2351de50e9fSSam Leffler 
2361de50e9fSSam Leffler   /*global pointers to beginning and end of current packet (during printing) */
2371de50e9fSSam Leffler   const u_char *ndo_packetp;
2381de50e9fSSam Leffler   const u_char *ndo_snapend;
2391de50e9fSSam Leffler 
240ee67461eSJoseph Mingrone   /* stack of saved packet boundary and buffer information */
241ee67461eSJoseph Mingrone   struct netdissect_saved_packet_info *ndo_packet_info_stack;
242ee67461eSJoseph Mingrone 
2433340d773SGleb Smirnoff   /* pointer to the if_printer function */
2443340d773SGleb Smirnoff   if_printer ndo_if_printer;
2451de50e9fSSam Leffler 
2461de50e9fSSam Leffler   /* pointer to void function to output stuff */
2471de50e9fSSam Leffler   void (*ndo_default_print)(netdissect_options *,
248ee67461eSJoseph Mingrone 			    const u_char *bp, u_int length);
2498bdc5a62SPatrick Kelsey 
2508bdc5a62SPatrick Kelsey   /* pointer to function to do regular output */
2511de50e9fSSam Leffler   int  (*ndo_printf)(netdissect_options *,
25227df3f5dSRui Paulo 		     const char *fmt, ...)
253ee67461eSJoseph Mingrone 		     PRINTFLIKE_FUNCPTR(2, 3);
2548bdc5a62SPatrick Kelsey   /* pointer to function to output errors */
255ee67461eSJoseph Mingrone   void NORETURN_FUNCPTR (*ndo_error)(netdissect_options *,
256ee67461eSJoseph Mingrone 				     status_exit_codes_t status,
25727df3f5dSRui Paulo 				     const char *fmt, ...)
258ee67461eSJoseph Mingrone 				     PRINTFLIKE_FUNCPTR(3, 4);
2598bdc5a62SPatrick Kelsey   /* pointer to function to output warnings */
2601de50e9fSSam Leffler   void (*ndo_warning)(netdissect_options *,
26127df3f5dSRui Paulo 		      const char *fmt, ...)
262ee67461eSJoseph Mingrone 		      PRINTFLIKE_FUNCPTR(2, 3);
2631de50e9fSSam Leffler };
2641de50e9fSSam Leffler 
265ee67461eSJoseph Mingrone extern WARN_UNUSED_RESULT int nd_push_buffer(netdissect_options *, u_char *, const u_char *, const u_int);
266ee67461eSJoseph Mingrone extern WARN_UNUSED_RESULT int nd_push_snaplen(netdissect_options *, const u_char *, const u_int);
267ee67461eSJoseph Mingrone extern void nd_change_snaplen(netdissect_options *, const u_char *, const u_int);
268ee67461eSJoseph Mingrone extern void nd_pop_packet_info(netdissect_options *);
269ee67461eSJoseph Mingrone extern void nd_pop_all_packet_info(netdissect_options *);
270ee67461eSJoseph Mingrone 
271ee67461eSJoseph Mingrone static inline NORETURN void
nd_trunc_longjmp(netdissect_options * ndo)272ee67461eSJoseph Mingrone nd_trunc_longjmp(netdissect_options *ndo)
273ee67461eSJoseph Mingrone {
274ee67461eSJoseph Mingrone 	longjmp(ndo->ndo_early_end, ND_TRUNCATED);
275ee67461eSJoseph Mingrone #ifdef _AIX
276ee67461eSJoseph Mingrone 	/*
277ee67461eSJoseph Mingrone 	 * In AIX <setjmp.h> decorates longjmp() with "#pragma leaves", which tells
278ee67461eSJoseph Mingrone 	 * XL C that the function is noreturn, but GCC remains unaware of that and
279ee67461eSJoseph Mingrone 	 * yields a "'noreturn' function does return" warning.
280ee67461eSJoseph Mingrone 	 */
281ee67461eSJoseph Mingrone 	ND_UNREACHABLE
282ee67461eSJoseph Mingrone #endif /* _AIX */
283ee67461eSJoseph Mingrone }
284ee67461eSJoseph Mingrone 
2851de50e9fSSam Leffler #define PT_VAT		1	/* Visual Audio Tool */
2861de50e9fSSam Leffler #define PT_WB		2	/* distributed White Board */
2871de50e9fSSam Leffler #define PT_RPC		3	/* Remote Procedure Call */
2881de50e9fSSam Leffler #define PT_RTP		4	/* Real-Time Applications protocol */
2891de50e9fSSam Leffler #define PT_RTCP		5	/* Real-Time Applications control protocol */
2901de50e9fSSam Leffler #define PT_SNMP		6	/* Simple Network Management Protocol */
2911de50e9fSSam Leffler #define PT_CNFP		7	/* Cisco NetFlow protocol */
292d03c0883SXin LI #define PT_TFTP		8	/* trivial file transfer protocol */
293d03c0883SXin LI #define PT_AODV		9	/* Ad-hoc On-demand Distance Vector Protocol */
294d03c0883SXin LI #define PT_CARP		10	/* Common Address Redundancy Protocol */
295d03c0883SXin LI #define PT_RADIUS	11	/* RADIUS authentication Protocol */
296d03c0883SXin LI #define PT_ZMTP1	12	/* ZeroMQ Message Transport Protocol 1.0 */
297d03c0883SXin LI #define PT_VXLAN	13	/* Virtual eXtensible Local Area Network */
2983c602fabSXin LI #define PT_PGM		14	/* [UDP-encapsulated] Pragmatic General Multicast */
2993c602fabSXin LI #define PT_PGM_ZMTP1	15	/* ZMTP/1.0 inside PGM (native or UDP-encapsulated) */
3003c602fabSXin LI #define PT_LMP		16	/* Link Management Protocol */
3013340d773SGleb Smirnoff #define PT_RESP		17	/* RESP */
302ee67461eSJoseph Mingrone #define PT_PTP		18	/* PTP */
303ee67461eSJoseph Mingrone #define PT_SOMEIP	19	/* Autosar SOME/IP Protocol */
304ee67461eSJoseph Mingrone #define PT_DOMAIN	20	/* Domain Name System (DNS) */
3051de50e9fSSam Leffler 
306ee67461eSJoseph Mingrone #define ND_MIN(a,b) ((a)>(b)?(b):(a))
307ee67461eSJoseph Mingrone #define ND_MAX(a,b) ((b)>(a)?(b):(a))
3081de50e9fSSam Leffler 
3093340d773SGleb Smirnoff /* For source or destination ports tests (UDP, TCP, ...) */
3103340d773SGleb Smirnoff #define IS_SRC_OR_DST_PORT(p) (sport == (p) || dport == (p))
3113340d773SGleb Smirnoff 
3121de50e9fSSam Leffler /*
31327df3f5dSRui Paulo  * Maximum snapshot length.  This should be enough to capture the full
31427df3f5dSRui Paulo  * packet on most network interfaces.
31527df3f5dSRui Paulo  *
3163c602fabSXin LI  *
3173c602fabSXin LI  * Somewhat arbitrary, but chosen to be:
3183c602fabSXin LI  *
3193c602fabSXin LI  *    1) big enough for maximum-size Linux loopback packets (65549)
3203c602fabSXin LI  *       and some USB packets captured with USBPcap:
3213c602fabSXin LI  *
322ee67461eSJoseph Mingrone  *           https://desowin.org/usbpcap/
3233c602fabSXin LI  *
3243c602fabSXin LI  *       (> 131072, < 262144)
3253c602fabSXin LI  *
3263c602fabSXin LI  * and
3273c602fabSXin LI  *
3283c602fabSXin LI  *    2) small enough not to cause attempts to allocate huge amounts of
3293c602fabSXin LI  *       memory; some applications might use the snapshot length in a
3303c602fabSXin LI  *       savefile header to control the size of the buffer they allocate,
3313c602fabSXin LI  *       so a size of, say, 2^31-1 might not work well.
3323c602fabSXin LI  *
333ee67461eSJoseph Mingrone  * XXX - does it need to be bigger still?  Note that, for versions of
334ee67461eSJoseph Mingrone  * libpcap with pcap_create()/pcap_activate(), if no -s flag is specified
335ee67461eSJoseph Mingrone  * or -s 0 is specified, we won't set the snapshot length at all, and will
336ee67461eSJoseph Mingrone  * let libpcap choose a snapshot length; newer versions may choose a bigger
337ee67461eSJoseph Mingrone  * value than 262144 for D-Bus, for example.
3381de50e9fSSam Leffler  */
3393c602fabSXin LI #define MAXIMUM_SNAPLEN	262144
3401de50e9fSSam Leffler 
34127df3f5dSRui Paulo /*
342ee67461eSJoseph Mingrone  * True if "l" bytes from "p" were captured.
3431de50e9fSSam Leffler  *
3441de50e9fSSam Leffler  * The "ndo->ndo_snapend - (l) <= ndo->ndo_snapend" checks to make sure
3451de50e9fSSam Leffler  * "l" isn't so large that "ndo->ndo_snapend - (l)" underflows.
3461de50e9fSSam Leffler  *
3471de50e9fSSam Leffler  * The check is for <= rather than < because "l" might be 0.
3488bdc5a62SPatrick Kelsey  *
3498bdc5a62SPatrick Kelsey  * We cast the pointers to uintptr_t to make sure that the compiler
3508bdc5a62SPatrick Kelsey  * doesn't optimize away any of these tests (which it is allowed to
3518bdc5a62SPatrick Kelsey  * do, as adding an integer to, or subtracting an integer from, a
3528bdc5a62SPatrick Kelsey  * pointer assumes that the pointer is a pointer to an element of an
3538bdc5a62SPatrick Kelsey  * array and that the result of the addition or subtraction yields a
3548bdc5a62SPatrick Kelsey  * pointer to another member of the array, so that, for example, if
3558bdc5a62SPatrick Kelsey  * you subtract a positive integer from a pointer, the result is
3568bdc5a62SPatrick Kelsey  * guaranteed to be less than the original pointer value). See
3578bdc5a62SPatrick Kelsey  *
358ee67461eSJoseph Mingrone  *	https://www.kb.cert.org/vuls/id/162289
3591de50e9fSSam Leffler  */
360358fd7daSPatrick Kelsey 
3613340d773SGleb Smirnoff /*
3623340d773SGleb Smirnoff  * Test in two parts to avoid these warnings:
3633340d773SGleb Smirnoff  * comparison of unsigned expression >= 0 is always true [-Wtype-limits],
3643340d773SGleb Smirnoff  * comparison is always true due to limited range of data type [-Wtype-limits].
3653340d773SGleb Smirnoff  */
366358fd7daSPatrick Kelsey #define IS_NOT_NEGATIVE(x) (((x) > 0) || ((x) == 0))
367358fd7daSPatrick Kelsey 
368ee67461eSJoseph Mingrone #define ND_TTEST_LEN(p, l) \
369358fd7daSPatrick Kelsey   (IS_NOT_NEGATIVE(l) && \
3708bdc5a62SPatrick Kelsey 	((uintptr_t)ndo->ndo_snapend - (l) <= (uintptr_t)ndo->ndo_snapend && \
371ee67461eSJoseph Mingrone          (uintptr_t)(p) <= (uintptr_t)ndo->ndo_snapend - (l)))
3721de50e9fSSam Leffler 
373ee67461eSJoseph Mingrone /* True if "*(p)" was captured */
374ee67461eSJoseph Mingrone #define ND_TTEST_SIZE(p) ND_TTEST_LEN(p, sizeof(*(p)))
3751de50e9fSSam Leffler 
376ee67461eSJoseph Mingrone /* Bail out if "l" bytes from "p" were not captured */
377ee67461eSJoseph Mingrone #ifdef ND_LONGJMP_FROM_TCHECK
378ee67461eSJoseph Mingrone #define ND_TCHECK_LEN(p, l) if (!ND_TTEST_LEN(p, l)) nd_trunc_longjmp(ndo)
379ee67461eSJoseph Mingrone #else
380ee67461eSJoseph Mingrone #define ND_TCHECK_LEN(p, l) if (!ND_TTEST_LEN(p, l)) goto trunc
381ee67461eSJoseph Mingrone #endif
3821de50e9fSSam Leffler 
383ee67461eSJoseph Mingrone /* Bail out if "*(p)" was not captured */
384ee67461eSJoseph Mingrone #define ND_TCHECK_SIZE(p) ND_TCHECK_LEN(p, sizeof(*(p)))
3851de50e9fSSam Leffler 
386ee67461eSJoseph Mingrone /*
387ee67461eSJoseph Mingrone  * Number of bytes between two pointers.
388ee67461eSJoseph Mingrone  */
389ee67461eSJoseph Mingrone #define ND_BYTES_BETWEEN(p1, p2) ((u_int)(((const uint8_t *)(p1)) - (const uint8_t *)(p2)))
390ee67461eSJoseph Mingrone 
391ee67461eSJoseph Mingrone /*
392ee67461eSJoseph Mingrone  * Number of bytes remaining in the captured data, starting at the
393ee67461eSJoseph Mingrone  * byte pointed to by the argument.
394ee67461eSJoseph Mingrone  */
395ee67461eSJoseph Mingrone #define ND_BYTES_AVAILABLE_AFTER(p) ND_BYTES_BETWEEN(ndo->ndo_snapend, (p))
396ee67461eSJoseph Mingrone 
397ee67461eSJoseph Mingrone /* Check length < minimum for invalid packet with a custom message, format %u */
398ee67461eSJoseph Mingrone #define ND_LCHECKMSG_U(length, minimum, what) \
399ee67461eSJoseph Mingrone if ((length) < (minimum)) { \
400ee67461eSJoseph Mingrone ND_PRINT(" [%s %u < %u]", (what), (length), (minimum)); \
401ee67461eSJoseph Mingrone goto invalid; \
402ee67461eSJoseph Mingrone }
403ee67461eSJoseph Mingrone 
404ee67461eSJoseph Mingrone /* Check length < minimum for invalid packet with #length message, format %u */
405ee67461eSJoseph Mingrone #define ND_LCHECK_U(length, minimum) \
406ee67461eSJoseph Mingrone ND_LCHECKMSG_U((length), (minimum), (#length))
407ee67461eSJoseph Mingrone 
408ee67461eSJoseph Mingrone /* Check length < minimum for invalid packet with a custom message, format %zu */
409ee67461eSJoseph Mingrone #define ND_LCHECKMSG_ZU(length, minimum, what) \
410ee67461eSJoseph Mingrone if ((length) < (minimum)) { \
411ee67461eSJoseph Mingrone ND_PRINT(" [%s %u < %zu]", (what), (length), (minimum)); \
412ee67461eSJoseph Mingrone goto invalid; \
413ee67461eSJoseph Mingrone }
414ee67461eSJoseph Mingrone 
415ee67461eSJoseph Mingrone /* Check length < minimum for invalid packet with #length message, format %zu */
416ee67461eSJoseph Mingrone #define ND_LCHECK_ZU(length, minimum) \
417ee67461eSJoseph Mingrone ND_LCHECKMSG_ZU((length), (minimum), (#length))
418ee67461eSJoseph Mingrone 
419ee67461eSJoseph Mingrone #define ND_PRINT(...) (ndo->ndo_printf)(ndo, __VA_ARGS__)
4201de50e9fSSam Leffler #define ND_DEFAULTPRINT(ap, length) (*ndo->ndo_default_print)(ndo, ap, length)
4211de50e9fSSam Leffler 
4223c602fabSXin LI extern void ts_print(netdissect_options *, const struct timeval *);
4233340d773SGleb Smirnoff extern void signed_relts_print(netdissect_options *, int32_t);
4243340d773SGleb Smirnoff extern void unsigned_relts_print(netdissect_options *, uint32_t);
4251de50e9fSSam Leffler 
426ee67461eSJoseph Mingrone extern const char *nd_format_time(char *buf, size_t bufsize,
427ee67461eSJoseph Mingrone     const char *format, const struct tm *timeptr);
428ee67461eSJoseph Mingrone 
4293340d773SGleb Smirnoff extern void fn_print_char(netdissect_options *, u_char);
430ee67461eSJoseph Mingrone extern void fn_print_str(netdissect_options *, const u_char *);
431ee67461eSJoseph Mingrone extern u_int nd_printztn(netdissect_options *, const u_char *, u_int, const u_char *);
432ee67461eSJoseph Mingrone extern int nd_printn(netdissect_options *, const u_char *, u_int, const u_char *);
433ee67461eSJoseph Mingrone extern void nd_printjnp(netdissect_options *, const u_char *, u_int);
4348bdc5a62SPatrick Kelsey 
4358bdc5a62SPatrick Kelsey /*
4368bdc5a62SPatrick Kelsey  * Flags for txtproto_print().
4378bdc5a62SPatrick Kelsey  */
4388bdc5a62SPatrick Kelsey #define RESP_CODE_SECOND_TOKEN	0x00000001	/* response code is second token in response line */
4398bdc5a62SPatrick Kelsey 
4408bdc5a62SPatrick Kelsey extern void txtproto_print(netdissect_options *, const u_char *, u_int,
441ee67461eSJoseph Mingrone 			   const char **, u_int);
4421de50e9fSSam Leffler 
443ee67461eSJoseph Mingrone #if (defined(__i386__) || defined(_M_IX86) || defined(__X86__) || defined(__x86_64__) || defined(_M_X64)) || \
444ee67461eSJoseph Mingrone     (defined(__arm__) || defined(_M_ARM) || defined(__aarch64__)) || \
445ee67461eSJoseph Mingrone     (defined(__m68k__) && (!defined(__mc68000__) && !defined(__mc68010__))) || \
446ee67461eSJoseph Mingrone     (defined(__ppc__) || defined(__ppc64__) || defined(_M_PPC) || defined(_ARCH_PPC) || defined(_ARCH_PPC64)) || \
447ee67461eSJoseph Mingrone     (defined(__s390__) || defined(__s390x__) || defined(__zarch__)) || \
448ee67461eSJoseph Mingrone     defined(__vax__)
4493c602fabSXin LI /*
450ee67461eSJoseph Mingrone  * The processor natively handles unaligned loads, so just use memcpy()
451ee67461eSJoseph Mingrone  * and memcmp(), to enable those optimizations.
452ee67461eSJoseph Mingrone  *
453ee67461eSJoseph Mingrone  * XXX - are those all the x86 tests we need?
454ee67461eSJoseph Mingrone  * XXX - do we need to worry about ARMv1 through ARMv5, which didn't
455ee67461eSJoseph Mingrone  * support unaligned loads, and, if so, do we need to worry about all
456ee67461eSJoseph Mingrone  * of them, or just some of them, e.g. ARMv5?
457ee67461eSJoseph Mingrone  * XXX - are those the only 68k tests we need not to generated
458ee67461eSJoseph Mingrone  * unaligned accesses if the target is the 68000 or 68010?
459ee67461eSJoseph Mingrone  * XXX - are there any tests we don't need, because some definitions are for
460ee67461eSJoseph Mingrone  * compilers that also predefine the GCC symbols?
461ee67461eSJoseph Mingrone  * XXX - do we need to test for both 32-bit and 64-bit versions of those
462ee67461eSJoseph Mingrone  * architectures in all cases?
4633c602fabSXin LI  */
464ee67461eSJoseph Mingrone #define UNALIGNED_MEMCPY(p, q, l)	memcpy((p), (q), (l))
465ee67461eSJoseph Mingrone #define UNALIGNED_MEMCMP(p, q, l)	memcmp((p), (q), (l))
466ee67461eSJoseph Mingrone #else
4673c602fabSXin LI /*
4683c602fabSXin LI  * The processor doesn't natively handle unaligned loads,
4693c602fabSXin LI  * and the compiler might "helpfully" optimize memcpy()
4703c602fabSXin LI  * and memcmp(), when handed pointers that would normally
4713c602fabSXin LI  * be properly aligned, into sequences that assume proper
4723c602fabSXin LI  * alignment.
4733c602fabSXin LI  *
4743c602fabSXin LI  * Do copies and compares of possibly-unaligned data by
4753c602fabSXin LI  * calling routines that wrap memcpy() and memcmp(), to
4763c602fabSXin LI  * prevent that optimization.
4773c602fabSXin LI  */
4783c602fabSXin LI extern void unaligned_memcpy(void *, const void *, size_t);
4793c602fabSXin LI extern int unaligned_memcmp(const void *, const void *, size_t);
4803c602fabSXin LI #define UNALIGNED_MEMCPY(p, q, l)	unaligned_memcpy((p), (q), (l))
4813c602fabSXin LI #define UNALIGNED_MEMCMP(p, q, l)	unaligned_memcmp((p), (q), (l))
4823c602fabSXin LI #endif
4831de50e9fSSam Leffler 
484cac3dcd5SXin LI #define PLURAL_SUFFIX(n) \
485cac3dcd5SXin LI 	(((n) != 1) ? "s" : "")
486cac3dcd5SXin LI 
4873340d773SGleb Smirnoff extern const char *tok2strary_internal(const char **, int, const char *, int);
4883340d773SGleb Smirnoff #define	tok2strary(a,f,i) tok2strary_internal(a, sizeof(a)/sizeof(a[0]),f,i)
4893340d773SGleb Smirnoff 
490ee67461eSJoseph Mingrone struct uint_tokary
491ee67461eSJoseph Mingrone {
492ee67461eSJoseph Mingrone 	u_int uintval;
493ee67461eSJoseph Mingrone 	const struct tok *tokary;
494ee67461eSJoseph Mingrone };
495ee67461eSJoseph Mingrone 
496ee67461eSJoseph Mingrone extern const struct tok *uint2tokary_internal(const struct uint_tokary[], const size_t, const u_int);
497ee67461eSJoseph Mingrone #define uint2tokary(a, i) uint2tokary_internal(a, sizeof(a)/sizeof(a[0]), i)
498ee67461eSJoseph Mingrone 
4993340d773SGleb Smirnoff extern if_printer lookup_printer(int);
5003340d773SGleb Smirnoff 
501ee67461eSJoseph Mingrone #define ND_DEBUG {printf(" [%s:%d %s] ", __FILE__, __LINE__, __func__); fflush(stdout);}
502ee67461eSJoseph Mingrone 
5033340d773SGleb Smirnoff /* The DLT printer routines */
5043340d773SGleb Smirnoff 
505ee67461eSJoseph Mingrone extern void ap1394_if_print IF_PRINTER_ARGS;
506ee67461eSJoseph Mingrone extern void arcnet_if_print IF_PRINTER_ARGS;
507ee67461eSJoseph Mingrone extern void arcnet_linux_if_print IF_PRINTER_ARGS;
508ee67461eSJoseph Mingrone extern void atm_if_print IF_PRINTER_ARGS;
509ee67461eSJoseph Mingrone extern void brcm_tag_if_print IF_PRINTER_ARGS;
510ee67461eSJoseph Mingrone extern void brcm_tag_prepend_if_print IF_PRINTER_ARGS;
511ee67461eSJoseph Mingrone extern void bt_if_print IF_PRINTER_ARGS;
512ee67461eSJoseph Mingrone extern void chdlc_if_print IF_PRINTER_ARGS;
513ee67461eSJoseph Mingrone extern void cip_if_print IF_PRINTER_ARGS;
514ee67461eSJoseph Mingrone extern void dsa_if_print IF_PRINTER_ARGS;
515ee67461eSJoseph Mingrone extern void edsa_if_print IF_PRINTER_ARGS;
516ee67461eSJoseph Mingrone extern void enc_if_print IF_PRINTER_ARGS;
517ee67461eSJoseph Mingrone extern void ether_if_print IF_PRINTER_ARGS;
518ee67461eSJoseph Mingrone extern void fddi_if_print IF_PRINTER_ARGS;
519ee67461eSJoseph Mingrone extern void fr_if_print IF_PRINTER_ARGS;
520ee67461eSJoseph Mingrone extern void ieee802_11_if_print IF_PRINTER_ARGS;
521ee67461eSJoseph Mingrone extern void ieee802_11_radio_avs_if_print IF_PRINTER_ARGS;
522ee67461eSJoseph Mingrone extern void ieee802_11_radio_if_print IF_PRINTER_ARGS;
523ee67461eSJoseph Mingrone extern void ieee802_15_4_if_print IF_PRINTER_ARGS;
524ee67461eSJoseph Mingrone extern void ieee802_15_4_tap_if_print IF_PRINTER_ARGS;
525ee67461eSJoseph Mingrone extern void ipfc_if_print IF_PRINTER_ARGS;
526ee67461eSJoseph Mingrone extern void ipnet_if_print IF_PRINTER_ARGS;
527ee67461eSJoseph Mingrone extern void ipoib_if_print IF_PRINTER_ARGS;
528ee67461eSJoseph Mingrone extern void juniper_atm1_if_print IF_PRINTER_ARGS;
529ee67461eSJoseph Mingrone extern void juniper_atm2_if_print IF_PRINTER_ARGS;
530ee67461eSJoseph Mingrone extern void juniper_chdlc_if_print IF_PRINTER_ARGS;
531ee67461eSJoseph Mingrone extern void juniper_es_if_print IF_PRINTER_ARGS;
532ee67461eSJoseph Mingrone extern void juniper_ether_if_print IF_PRINTER_ARGS;
533ee67461eSJoseph Mingrone extern void juniper_frelay_if_print IF_PRINTER_ARGS;
534ee67461eSJoseph Mingrone extern void juniper_ggsn_if_print IF_PRINTER_ARGS;
535ee67461eSJoseph Mingrone extern void juniper_mfr_if_print IF_PRINTER_ARGS;
536ee67461eSJoseph Mingrone extern void juniper_mlfr_if_print IF_PRINTER_ARGS;
537ee67461eSJoseph Mingrone extern void juniper_mlppp_if_print IF_PRINTER_ARGS;
538ee67461eSJoseph Mingrone extern void juniper_monitor_if_print IF_PRINTER_ARGS;
539ee67461eSJoseph Mingrone extern void juniper_ppp_if_print IF_PRINTER_ARGS;
540ee67461eSJoseph Mingrone extern void juniper_pppoe_atm_if_print IF_PRINTER_ARGS;
541ee67461eSJoseph Mingrone extern void juniper_pppoe_if_print IF_PRINTER_ARGS;
542ee67461eSJoseph Mingrone extern void juniper_services_if_print IF_PRINTER_ARGS;
543ee67461eSJoseph Mingrone extern void ltalk_if_print IF_PRINTER_ARGS;
544ee67461eSJoseph Mingrone extern void mfr_if_print IF_PRINTER_ARGS;
545ee67461eSJoseph Mingrone extern void netanalyzer_if_print IF_PRINTER_ARGS;
546ee67461eSJoseph Mingrone extern void netanalyzer_transparent_if_print IF_PRINTER_ARGS;
547ee67461eSJoseph Mingrone extern void nflog_if_print IF_PRINTER_ARGS;
548ee67461eSJoseph Mingrone extern void null_if_print IF_PRINTER_ARGS;
549ee67461eSJoseph Mingrone extern void pflog_if_print IF_PRINTER_ARGS;
550ee67461eSJoseph Mingrone extern void pktap_if_print IF_PRINTER_ARGS;
551ee67461eSJoseph Mingrone extern void ppi_if_print IF_PRINTER_ARGS;
552ee67461eSJoseph Mingrone extern void ppp_bsdos_if_print IF_PRINTER_ARGS;
553ee67461eSJoseph Mingrone extern void ppp_hdlc_if_print IF_PRINTER_ARGS;
554ee67461eSJoseph Mingrone extern void ppp_if_print IF_PRINTER_ARGS;
555ee67461eSJoseph Mingrone extern void pppoe_if_print IF_PRINTER_ARGS;
556ee67461eSJoseph Mingrone extern void prism_if_print IF_PRINTER_ARGS;
557ee67461eSJoseph Mingrone extern void raw_if_print IF_PRINTER_ARGS;
558ee67461eSJoseph Mingrone extern void sl_bsdos_if_print IF_PRINTER_ARGS;
559ee67461eSJoseph Mingrone extern void sl_if_print IF_PRINTER_ARGS;
560ee67461eSJoseph Mingrone extern void sll2_if_print IF_PRINTER_ARGS;
561ee67461eSJoseph Mingrone extern void sll_if_print IF_PRINTER_ARGS;
562ee67461eSJoseph Mingrone extern void sunatm_if_print IF_PRINTER_ARGS;
563ee67461eSJoseph Mingrone extern void symantec_if_print IF_PRINTER_ARGS;
564ee67461eSJoseph Mingrone extern void token_if_print IF_PRINTER_ARGS;
565ee67461eSJoseph Mingrone extern void unsupported_if_print IF_PRINTER_ARGS;
566ee67461eSJoseph Mingrone extern void usb_linux_48_byte_if_print IF_PRINTER_ARGS;
567ee67461eSJoseph Mingrone extern void usb_linux_64_byte_if_print IF_PRINTER_ARGS;
568ee67461eSJoseph Mingrone extern void vsock_if_print IF_PRINTER_ARGS;
5693340d773SGleb Smirnoff 
5703340d773SGleb Smirnoff /*
5713340d773SGleb Smirnoff  * Structure passed to some printers to allow them to print
5723340d773SGleb Smirnoff  * link-layer address information if ndo_eflag isn't set
5733340d773SGleb Smirnoff  * (because they are for protocols that don't have their
5743340d773SGleb Smirnoff  * own addresses, so that we'd want to report link-layer
5753340d773SGleb Smirnoff  * address information).
5763340d773SGleb Smirnoff  *
5773340d773SGleb Smirnoff  * This contains a pointer to an address and a pointer to a routine
5783340d773SGleb Smirnoff  * to which we pass that pointer in order to get a string.
5793340d773SGleb Smirnoff  */
5803340d773SGleb Smirnoff struct lladdr_info {
5813340d773SGleb Smirnoff 	const char *(*addr_string)(netdissect_options *, const u_char *);
5823340d773SGleb Smirnoff 	const u_char *addr;
5833340d773SGleb Smirnoff };
5841de50e9fSSam Leffler 
5851de50e9fSSam Leffler /* The printer routines. */
5861de50e9fSSam Leffler 
5873340d773SGleb Smirnoff extern void aarp_print(netdissect_options *, const u_char *, u_int);
588ee67461eSJoseph Mingrone extern int ah_print(netdissect_options *, const u_char *);
589ee67461eSJoseph Mingrone extern void ahcp_print(netdissect_options *, const u_char *, u_int);
5903c602fabSXin LI extern void aodv_print(netdissect_options *, const u_char *, u_int, int);
5913340d773SGleb Smirnoff extern void aoe_print(netdissect_options *, const u_char *, const u_int);
592ee67461eSJoseph Mingrone extern int  arista_ethertype_print(netdissect_options *,const u_char *, u_int);
5933340d773SGleb Smirnoff extern void arp_print(netdissect_options *, const u_char *, u_int, u_int);
5943340d773SGleb Smirnoff extern void ascii_print(netdissect_options *, const u_char *, u_int);
5953340d773SGleb Smirnoff extern void atalk_print(netdissect_options *, const u_char *, u_int);
5963340d773SGleb Smirnoff extern void atm_print(netdissect_options *, u_int, u_int, u_int, const u_char *, u_int, u_int);
5973340d773SGleb Smirnoff extern void babel_print(netdissect_options *, const u_char *, u_int);
598ee67461eSJoseph Mingrone extern void bcm_li_print(netdissect_options *, const u_char *, u_int);
5993340d773SGleb Smirnoff extern void beep_print(netdissect_options *, const u_char *, u_int);
6003340d773SGleb Smirnoff extern void bfd_print(netdissect_options *, const u_char *, u_int, u_int);
601ee67461eSJoseph Mingrone extern void bgp_print(netdissect_options *, const u_char *, u_int);
602ee67461eSJoseph Mingrone extern const char *bgp_vpn_rd_print(netdissect_options *, const u_char *);
6033340d773SGleb Smirnoff extern void bootp_print(netdissect_options *, const u_char *, u_int);
6043340d773SGleb Smirnoff extern void calm_fast_print(netdissect_options *, const u_char *, u_int, const struct lladdr_info *);
605ee67461eSJoseph Mingrone extern void carp_print(netdissect_options *, const u_char *, u_int, u_int);
606ee67461eSJoseph Mingrone extern void cdp_print(netdissect_options *, const u_char *, u_int);
6073340d773SGleb Smirnoff extern void cfm_print(netdissect_options *, const u_char *, u_int);
608ee67461eSJoseph Mingrone extern u_int chdlc_print(netdissect_options *, const u_char *, u_int);
6093340d773SGleb Smirnoff extern void cisco_autorp_print(netdissect_options *, const u_char *, u_int);
6103340d773SGleb Smirnoff extern void cnfp_print(netdissect_options *, const u_char *);
6113340d773SGleb Smirnoff extern void dccp_print(netdissect_options *, const u_char *, const u_char *, u_int);
6123340d773SGleb Smirnoff extern void decnet_print(netdissect_options *, const u_char *, u_int, u_int);
6133340d773SGleb Smirnoff extern void dhcp6_print(netdissect_options *, const u_char *, u_int);
614ee67461eSJoseph Mingrone extern int dstopt_process(netdissect_options *, const u_char *);
6153340d773SGleb Smirnoff extern void dtp_print(netdissect_options *, const u_char *, u_int);
6163340d773SGleb Smirnoff extern void dvmrp_print(netdissect_options *, const u_char *, u_int);
6173340d773SGleb Smirnoff extern void eap_print(netdissect_options *, const u_char *, u_int);
618ee67461eSJoseph Mingrone extern void eapol_print(netdissect_options *, const u_char *);
6193340d773SGleb Smirnoff extern void egp_print(netdissect_options *, const u_char *, u_int);
6203340d773SGleb Smirnoff extern void eigrp_print(netdissect_options *, const u_char *, u_int);
621ee67461eSJoseph Mingrone extern void esp_print(netdissect_options *, const u_char *, u_int, const u_char *, u_int, int, u_int);
6223340d773SGleb Smirnoff extern u_int ether_print(netdissect_options *, const u_char *, u_int, u_int, void (*)(netdissect_options *, const u_char *), const u_char *);
623ee67461eSJoseph Mingrone extern u_int ether_switch_tag_print(netdissect_options *, const u_char *, u_int, u_int, void (*)(netdissect_options *, const u_char *), u_int);
6243340d773SGleb Smirnoff extern int ethertype_print(netdissect_options *, u_short, const u_char *, u_int, u_int, const struct lladdr_info *, const struct lladdr_info *);
6253340d773SGleb Smirnoff extern u_int fddi_print(netdissect_options *, const u_char *, u_int, u_int);
6263c602fabSXin LI extern void forces_print(netdissect_options *, const u_char *, u_int);
627ee67461eSJoseph Mingrone extern u_int fr_print(netdissect_options *, const u_char *, u_int);
6283340d773SGleb Smirnoff extern int frag6_print(netdissect_options *, const u_char *, const u_char *);
6293340d773SGleb Smirnoff extern void ftp_print(netdissect_options *, const u_char *, u_int);
6303340d773SGleb Smirnoff extern void geneve_print(netdissect_options *, const u_char *, u_int);
6313340d773SGleb Smirnoff extern void geonet_print(netdissect_options *, const u_char *, u_int, const struct lladdr_info *);
6323340d773SGleb Smirnoff extern void gre_print(netdissect_options *, const u_char *, u_int);
633ee67461eSJoseph Mingrone extern int hbhopt_process(netdissect_options *, const u_char *, int *, uint32_t *);
6343340d773SGleb Smirnoff extern void hex_and_ascii_print(netdissect_options *, const char *, const u_char *, u_int);
6353340d773SGleb Smirnoff extern void hex_print(netdissect_options *, const char *ident, const u_char *cp, u_int);
6363340d773SGleb Smirnoff extern void hex_print_with_offset(netdissect_options *, const char *ident, const u_char *cp, u_int, u_int);
6373340d773SGleb Smirnoff extern void hncp_print(netdissect_options *, const u_char *, u_int);
6383340d773SGleb Smirnoff extern void hsrp_print(netdissect_options *, const u_char *, u_int);
6393340d773SGleb Smirnoff extern void http_print(netdissect_options *, const u_char *, u_int);
6403340d773SGleb Smirnoff extern void icmp6_print(netdissect_options *, const u_char *, u_int, const u_char *, int);
6413340d773SGleb Smirnoff extern void icmp_print(netdissect_options *, const u_char *, u_int, const u_char *, int);
642ee67461eSJoseph Mingrone extern u_int ieee802_15_4_print(netdissect_options *, const u_char *, u_int);
64339e421e8SCy Schubert extern u_int ieee802_11_radio_print(netdissect_options *, const u_char *, u_int, u_int);
6443340d773SGleb Smirnoff extern void igmp_print(netdissect_options *, const u_char *, u_int);
6453340d773SGleb Smirnoff extern void igrp_print(netdissect_options *, const u_char *, u_int);
6463340d773SGleb Smirnoff extern void ip6_print(netdissect_options *, const u_char *, u_int);
6473340d773SGleb Smirnoff extern void ipN_print(netdissect_options *, const u_char *, u_int);
6483340d773SGleb Smirnoff extern void ip_print(netdissect_options *, const u_char *, u_int);
649ee67461eSJoseph Mingrone extern void ipcomp_print(netdissect_options *, const u_char *);
6503340d773SGleb Smirnoff extern void ipx_netbios_print(netdissect_options *, const u_char *, u_int);
6513340d773SGleb Smirnoff extern void ipx_print(netdissect_options *, const u_char *, u_int);
6523340d773SGleb Smirnoff extern void isakmp_print(netdissect_options *, const u_char *, u_int, const u_char *);
653ee67461eSJoseph Mingrone extern void isakmp_rfc3948_print(netdissect_options *, const u_char *, u_int, const u_char *, int, int, u_int);
6540bff6a5aSEd Maste extern void isoclns_print(netdissect_options *, const u_char *, u_int);
6553c602fabSXin LI extern void krb_print(netdissect_options *, const u_char *);
6563340d773SGleb Smirnoff extern void l2tp_print(netdissect_options *, const u_char *, u_int);
6573340d773SGleb Smirnoff extern void lane_print(netdissect_options *, const u_char *, u_int, u_int);
6583340d773SGleb Smirnoff extern void ldp_print(netdissect_options *, const u_char *, u_int);
6593340d773SGleb Smirnoff extern void lisp_print(netdissect_options *, const u_char *, u_int);
6603c602fabSXin LI extern u_int llap_print(netdissect_options *, const u_char *, u_int);
6613340d773SGleb Smirnoff extern int llc_print(netdissect_options *, const u_char *, u_int, u_int, const struct lladdr_info *, const struct lladdr_info *);
6623340d773SGleb Smirnoff extern void lldp_print(netdissect_options *, const u_char *, u_int);
6633340d773SGleb Smirnoff extern void lmp_print(netdissect_options *, const u_char *, u_int);
664ee67461eSJoseph Mingrone extern void loopback_print(netdissect_options *, const u_char *, u_int);
6653340d773SGleb Smirnoff extern void lspping_print(netdissect_options *, const u_char *, u_int);
6663340d773SGleb Smirnoff extern void lwapp_control_print(netdissect_options *, const u_char *, u_int, int);
6673340d773SGleb Smirnoff extern void lwapp_data_print(netdissect_options *, const u_char *, u_int);
6683c602fabSXin LI extern void lwres_print(netdissect_options *, const u_char *, u_int);
6693340d773SGleb Smirnoff extern void m3ua_print(netdissect_options *, const u_char *, const u_int);
670ee67461eSJoseph Mingrone extern int macsec_print(netdissect_options *, const u_char **,
671ee67461eSJoseph Mingrone 			 u_int *, u_int *, u_int *, const struct lladdr_info *,
672ee67461eSJoseph Mingrone 			 const struct lladdr_info *);
673ee67461eSJoseph Mingrone extern u_int mfr_print(netdissect_options *, const u_char *, u_int);
6743340d773SGleb Smirnoff extern void mobile_print(netdissect_options *, const u_char *, u_int);
6753340d773SGleb Smirnoff extern int mobility_print(netdissect_options *, const u_char *, const u_char *);
6763340d773SGleb Smirnoff extern void mpcp_print(netdissect_options *, const u_char *, u_int);
6773340d773SGleb Smirnoff extern void mpls_print(netdissect_options *, const u_char *, u_int);
6783340d773SGleb Smirnoff extern int mptcp_print(netdissect_options *, const u_char *, u_int, u_char);
6793340d773SGleb Smirnoff extern void msdp_print(netdissect_options *, const u_char *, u_int);
6803340d773SGleb Smirnoff extern void msnlb_print(netdissect_options *, const u_char *);
681ee67461eSJoseph Mingrone extern void nbt_tcp_print(netdissect_options *, const u_char *, u_int);
682ee67461eSJoseph Mingrone extern void nbt_udp137_print(netdissect_options *, const u_char *, u_int);
683ee67461eSJoseph Mingrone extern void nbt_udp138_print(netdissect_options *, const u_char *, u_int);
684ee67461eSJoseph Mingrone extern void netbeui_print(netdissect_options *, u_short, const u_char *, u_int);
6853340d773SGleb Smirnoff extern void nfsreply_print(netdissect_options *, const u_char *, u_int, const u_char *);
686ee67461eSJoseph Mingrone extern void nfsreply_noaddr_print(netdissect_options *, const u_char *, u_int, const u_char *);
687ee67461eSJoseph Mingrone extern void nfsreq_noaddr_print(netdissect_options *, const u_char *, u_int, const u_char *);
688ee67461eSJoseph Mingrone extern const u_char *fqdn_print(netdissect_options *, const u_char *, const u_char *);
689ee67461eSJoseph Mingrone extern void domain_print(netdissect_options *, const u_char *, u_int, int, int);
690ee67461eSJoseph Mingrone extern void nsh_print(netdissect_options *, const u_char *, u_int);
6913340d773SGleb Smirnoff extern void ntp_print(netdissect_options *, const u_char *, u_int);
6923340d773SGleb Smirnoff extern void oam_print(netdissect_options *, const u_char *, u_int, u_int);
6933340d773SGleb Smirnoff extern void olsr_print(netdissect_options *, const u_char *, u_int, int);
694ee67461eSJoseph Mingrone extern void openflow_print(netdissect_options *, const u_char *, u_int);
6951de50e9fSSam Leffler extern void ospf6_print(netdissect_options *, const u_char *, u_int);
6963340d773SGleb Smirnoff extern void ospf_print(netdissect_options *, const u_char *, u_int, const u_char *);
697ee67461eSJoseph Mingrone extern int ospf_grace_lsa_print(netdissect_options *, const u_char *, u_int);
698ee67461eSJoseph Mingrone extern int ospf_te_lsa_print(netdissect_options *, const u_char *, u_int);
6993340d773SGleb Smirnoff extern void otv_print(netdissect_options *, const u_char *, u_int);
7003340d773SGleb Smirnoff extern void pfsync_ip_print(netdissect_options *, const u_char *, u_int);
7011ad8d2eeSJoseph Mingrone extern void pfsync_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *);
7023340d773SGleb Smirnoff extern void pgm_print(netdissect_options *, const u_char *, u_int, const u_char *);
7033340d773SGleb Smirnoff extern void pim_print(netdissect_options *, const u_char *, u_int, const u_char *);
7043340d773SGleb Smirnoff extern void pimv1_print(netdissect_options *, const u_char *, u_int);
705ee67461eSJoseph Mingrone extern u_int ppp_print(netdissect_options *, const u_char *, u_int);
7063340d773SGleb Smirnoff extern u_int pppoe_print(netdissect_options *, const u_char *, u_int);
7073340d773SGleb Smirnoff extern void pptp_print(netdissect_options *, const u_char *);
708ee67461eSJoseph Mingrone extern void ptp_print(netdissect_options *, const u_char *, u_int);
709ee67461eSJoseph Mingrone extern int print_unknown_data(netdissect_options *, const u_char *, const char *, u_int);
710ee67461eSJoseph Mingrone extern const char *q922_string(netdissect_options *, const u_char *, u_int);
7113340d773SGleb Smirnoff extern void q933_print(netdissect_options *, const u_char *, u_int);
7123340d773SGleb Smirnoff extern void radius_print(netdissect_options *, const u_char *, u_int);
7133340d773SGleb Smirnoff extern void resp_print(netdissect_options *, const u_char *, u_int);
7143340d773SGleb Smirnoff extern void rip_print(netdissect_options *, const u_char *, u_int);
7153340d773SGleb Smirnoff extern void ripng_print(netdissect_options *, const u_char *, unsigned int);
7163340d773SGleb Smirnoff extern void rpki_rtr_print(netdissect_options *, const u_char *, u_int);
7173340d773SGleb Smirnoff extern void rsvp_print(netdissect_options *, const u_char *, u_int);
7183340d773SGleb Smirnoff extern int rt6_print(netdissect_options *, const u_char *, const u_char *);
719ee67461eSJoseph Mingrone extern void rtl_print(netdissect_options *, const u_char *, u_int, const struct lladdr_info *, const struct lladdr_info *);
7203340d773SGleb Smirnoff extern void rtsp_print(netdissect_options *, const u_char *, u_int);
721ee67461eSJoseph Mingrone extern void rx_print(netdissect_options *, const u_char *, u_int, uint16_t, uint16_t, const u_char *);
7223340d773SGleb Smirnoff extern void sctp_print(netdissect_options *, const u_char *, const u_char *, u_int);
7233340d773SGleb Smirnoff extern void sflow_print(netdissect_options *, const u_char *, u_int);
724ee67461eSJoseph Mingrone extern void ssh_print(netdissect_options *, const u_char *, u_int);
7253340d773SGleb Smirnoff extern void sip_print(netdissect_options *, const u_char *, u_int);
7263340d773SGleb Smirnoff extern void slow_print(netdissect_options *, const u_char *, u_int);
727ee67461eSJoseph Mingrone extern void smb_tcp_print(netdissect_options *, const u_char *, u_int);
7283340d773SGleb Smirnoff extern void smtp_print(netdissect_options *, const u_char *, u_int);
7293340d773SGleb Smirnoff extern int snap_print(netdissect_options *, const u_char *, u_int, u_int, const struct lladdr_info *, const struct lladdr_info *, u_int);
7303340d773SGleb Smirnoff extern void snmp_print(netdissect_options *, const u_char *, u_int);
7313340d773SGleb Smirnoff extern void stp_print(netdissect_options *, const u_char *, u_int);
732ee67461eSJoseph Mingrone extern void sunrpc_print(netdissect_options *, const u_char *, u_int, const u_char *);
7333340d773SGleb Smirnoff extern void syslog_print(netdissect_options *, const u_char *, u_int);
7343340d773SGleb Smirnoff extern void tcp_print(netdissect_options *, const u_char *, u_int, const u_char *, int);
7353340d773SGleb Smirnoff extern void telnet_print(netdissect_options *, const u_char *, u_int);
7363340d773SGleb Smirnoff extern void tftp_print(netdissect_options *, const u_char *, u_int);
7373340d773SGleb Smirnoff extern void timed_print(netdissect_options *, const u_char *);
7383340d773SGleb Smirnoff extern void tipc_print(netdissect_options *, const u_char *, u_int, u_int);
7393340d773SGleb Smirnoff extern u_int token_print(netdissect_options *, const u_char *, u_int, u_int);
7403340d773SGleb Smirnoff extern void udld_print(netdissect_options *, const u_char *, u_int);
741ee67461eSJoseph Mingrone extern void udp_print(netdissect_options *, const u_char *, u_int, const u_char *, int, u_int);
742ee67461eSJoseph Mingrone extern int vjc_print(netdissect_options *, const u_char *, u_short);
743ee67461eSJoseph Mingrone extern void vqp_print(netdissect_options *, const u_char *, u_int);
744ee67461eSJoseph Mingrone extern void vrrp_print(netdissect_options *, const u_char *, u_int, const u_char *, int, int);
745ee67461eSJoseph Mingrone extern void vtp_print(netdissect_options *, const u_char *, const u_int);
746ee67461eSJoseph Mingrone extern void vxlan_gpe_print(netdissect_options *, const u_char *, u_int);
7473340d773SGleb Smirnoff extern void vxlan_print(netdissect_options *, const u_char *, u_int);
748ee67461eSJoseph Mingrone extern void wb_print(netdissect_options *, const u_char *, u_int);
749ee67461eSJoseph Mingrone extern void whois_print(netdissect_options *, const u_char *, u_int);
750ee67461eSJoseph Mingrone extern void zep_print(netdissect_options *, const u_char *, u_int);
751ee67461eSJoseph Mingrone extern void zephyr_print(netdissect_options *, const u_char *, u_int);
7523340d773SGleb Smirnoff extern void zmtp1_print(netdissect_options *, const u_char *, u_int);
753ee67461eSJoseph Mingrone extern void zmtp1_datagram_print(netdissect_options *, const u_char *, const u_int);
754ee67461eSJoseph Mingrone extern void someip_print(netdissect_options *, const u_char *, const u_int);
7551de50e9fSSam Leffler 
7563340d773SGleb Smirnoff /* checksum routines */
7573340d773SGleb Smirnoff extern void init_checksum(void);
7583340d773SGleb Smirnoff extern uint16_t verify_crc10_cksum(uint16_t, const u_char *, int);
7593340d773SGleb Smirnoff extern uint16_t create_osi_cksum(const uint8_t *, int, int);
7603340d773SGleb Smirnoff 
761cac3dcd5SXin LI struct cksum_vec {
7623c602fabSXin LI 	const uint8_t	*ptr;
763cac3dcd5SXin LI 	int		len;
764cac3dcd5SXin LI };
7653c602fabSXin LI extern uint16_t in_cksum(const struct cksum_vec *, int);
7663c602fabSXin LI extern uint16_t in_cksum_shouldbe(uint16_t, uint16_t);
7671de50e9fSSam Leffler 
768ee67461eSJoseph Mingrone /* IP protocol demuxing routines */
769ee67461eSJoseph Mingrone extern void ip_demux_print(netdissect_options *, const u_char *, u_int, u_int, int, u_int, uint8_t, const u_char *);
770ee67461eSJoseph Mingrone 
771ee67461eSJoseph Mingrone extern uint16_t nextproto4_cksum(netdissect_options *, const struct ip *, const uint8_t *, u_int, u_int, uint8_t);
7723340d773SGleb Smirnoff 
7733340d773SGleb Smirnoff /* in print-ip6.c */
774ee67461eSJoseph Mingrone extern uint16_t nextproto6_cksum(netdissect_options *, const struct ip6_hdr *, const uint8_t *, u_int, u_int, uint8_t);
7753340d773SGleb Smirnoff 
7763340d773SGleb Smirnoff /* Utilities */
777ee67461eSJoseph Mingrone extern void nd_print_trunc(netdissect_options *);
778ee67461eSJoseph Mingrone extern void nd_print_protocol(netdissect_options *);
779ee67461eSJoseph Mingrone extern void nd_print_protocol_caps(netdissect_options *);
780ee67461eSJoseph Mingrone extern void nd_print_invalid(netdissect_options *);
781ee67461eSJoseph Mingrone 
7823340d773SGleb Smirnoff extern int mask2plen(uint32_t);
7833340d773SGleb Smirnoff extern int mask62plen(const u_char *);
7843340d773SGleb Smirnoff 
7853340d773SGleb Smirnoff extern const char *dnnum_string(netdissect_options *, u_short);
7863340d773SGleb Smirnoff 
787ee67461eSJoseph Mingrone extern int decode_prefix4(netdissect_options *, const u_char *, u_int, char *, size_t);
788ee67461eSJoseph Mingrone extern int decode_prefix6(netdissect_options *, const u_char *, u_int, char *, size_t);
7893340d773SGleb Smirnoff 
790ee67461eSJoseph Mingrone extern void esp_decodesecret_print(netdissect_options *);
791ee67461eSJoseph Mingrone extern int esp_decrypt_buffer_by_ikev2_print(netdissect_options *, int,
792ee67461eSJoseph Mingrone 					     const u_char spii[8],
793ee67461eSJoseph Mingrone 					     const u_char spir[8],
7943340d773SGleb Smirnoff 					     const u_char *, const u_char *);
7953c602fabSXin LI 
7961de50e9fSSam Leffler #endif  /* netdissect_h */
797