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> 33*0a7e5f1fSJoseph Mingrone #include <time.h> 34ee67461eSJoseph Mingrone #include "status-exit-codes.h" 35ee67461eSJoseph Mingrone #include "funcattrs.h" /* for PRINTFLIKE_FUNCPTR() */ 36ee67461eSJoseph Mingrone #include "diag-control.h" /* for ND_UNREACHABLE */ 371de50e9fSSam Leffler 383340d773SGleb Smirnoff /* 393340d773SGleb Smirnoff * Data types corresponding to multi-byte integral values within data 403340d773SGleb Smirnoff * structures. These are defined as arrays of octets, so that they're 413340d773SGleb Smirnoff * not aligned on their "natural" boundaries, and so that you *must* 423340d773SGleb Smirnoff * use the EXTRACT_ macros to extract them (which you should be doing 433340d773SGleb Smirnoff * *anyway*, so as not to assume a particular byte order or alignment 443340d773SGleb Smirnoff * in your code). 45ee67461eSJoseph Mingrone * 46ee67461eSJoseph Mingrone * We even want EXTRACT_U_1 used for 8-bit integral values, so we 47ee67461eSJoseph Mingrone * define nd_uint8_t and nd_int8_t as arrays as well. 483340d773SGleb Smirnoff */ 49ee67461eSJoseph Mingrone typedef unsigned char nd_uint8_t[1]; 503340d773SGleb Smirnoff typedef unsigned char nd_uint16_t[2]; 513340d773SGleb Smirnoff typedef unsigned char nd_uint24_t[3]; 523340d773SGleb Smirnoff typedef unsigned char nd_uint32_t[4]; 533340d773SGleb Smirnoff typedef unsigned char nd_uint40_t[5]; 543340d773SGleb Smirnoff typedef unsigned char nd_uint48_t[6]; 553340d773SGleb Smirnoff typedef unsigned char nd_uint56_t[7]; 563340d773SGleb Smirnoff typedef unsigned char nd_uint64_t[8]; 573340d773SGleb Smirnoff 58ee67461eSJoseph Mingrone typedef signed char nd_int8_t[1]; 593340d773SGleb Smirnoff 603340d773SGleb Smirnoff /* 61ee67461eSJoseph Mingrone * "unsigned char" so that sign extension isn't done on the 62*0a7e5f1fSJoseph Mingrone * individual bytes while they're being assembled. Use 63*0a7e5f1fSJoseph Mingrone * GET_S_BE_n() and GET_S_LE_n() macros to extract the value 64*0a7e5f1fSJoseph Mingrone * as a signed integer. 653340d773SGleb Smirnoff */ 66*0a7e5f1fSJoseph Mingrone typedef unsigned char nd_int16_t[2]; 67*0a7e5f1fSJoseph Mingrone typedef unsigned char nd_int24_t[3]; 68ee67461eSJoseph Mingrone typedef unsigned char nd_int32_t[4]; 69*0a7e5f1fSJoseph Mingrone typedef unsigned char nd_int40_t[5]; 70*0a7e5f1fSJoseph Mingrone typedef unsigned char nd_int48_t[6]; 71*0a7e5f1fSJoseph Mingrone typedef unsigned char nd_int56_t[7]; 72ee67461eSJoseph Mingrone typedef unsigned char nd_int64_t[8]; 733340d773SGleb Smirnoff 74ee67461eSJoseph Mingrone #define FMAXINT (4294967296.0) /* floating point rep. of MAXINT */ 75ee67461eSJoseph Mingrone 76ee67461eSJoseph Mingrone /* 77ee67461eSJoseph Mingrone * Use this for IPv4 addresses and netmasks. 78ee67461eSJoseph Mingrone * 79ee67461eSJoseph Mingrone * It's defined as an array of octets, so that it's not guaranteed to 80ee67461eSJoseph Mingrone * be aligned on its "natural" boundary (in some packet formats, it 81ee67461eSJoseph Mingrone * *isn't* so aligned). We have separate EXTRACT_ calls for them; 82ee67461eSJoseph Mingrone * sometimes you want the host-byte-order value, other times you want 83ee67461eSJoseph Mingrone * the network-byte-order value. 84ee67461eSJoseph Mingrone * 85ee67461eSJoseph Mingrone * Don't use EXTRACT_BE_U_4() on them, use EXTRACT_IPV4_TO_HOST_ORDER() 86ee67461eSJoseph Mingrone * if you want them in host byte order and EXTRACT_IPV4_TO_NETWORK_ORDER() 87ee67461eSJoseph Mingrone * if you want them in network byte order (which you want with system APIs 88ee67461eSJoseph Mingrone * that expect network-order IPv4 addresses, such as inet_ntop()). 89ee67461eSJoseph Mingrone * 90ee67461eSJoseph Mingrone * If, on your little-endian machine (e.g., an "IBM-compatible PC", no matter 91ee67461eSJoseph Mingrone * what the OS, or an Intel Mac, no matter what the OS), you get the wrong 92ee67461eSJoseph Mingrone * answer, and you've used EXTRACT_BE_U_4(), do *N*O*T* "fix" this by using 93ee67461eSJoseph Mingrone * EXTRACT_LE_U_4(), fix it by using EXTRACT_IPV4_TO_NETWORK_ORDER(), 94ee67461eSJoseph Mingrone * otherwise you're breaking the result on big-endian machines (e.g., 95ee67461eSJoseph Mingrone * most PowerPC/Power ISA machines, System/390 and z/Architecture, SPARC, 96ee67461eSJoseph Mingrone * etc.). 97ee67461eSJoseph Mingrone * 98ee67461eSJoseph Mingrone * Yes, people do this; that's why Wireshark has tvb_get_ipv4(), to extract 99ee67461eSJoseph Mingrone * an IPv4 address from a packet data buffer; it was introduced in reaction 100ee67461eSJoseph Mingrone * to somebody who *had* done that. 101ee67461eSJoseph Mingrone */ 102ee67461eSJoseph Mingrone typedef unsigned char nd_ipv4[4]; 103ee67461eSJoseph Mingrone 104ee67461eSJoseph Mingrone /* 105ee67461eSJoseph Mingrone * Use this for IPv6 addresses and netmasks. 106ee67461eSJoseph Mingrone */ 107ee67461eSJoseph Mingrone typedef unsigned char nd_ipv6[16]; 108ee67461eSJoseph Mingrone 109ee67461eSJoseph Mingrone /* 110ee67461eSJoseph Mingrone * Use this for MAC addresses. 111ee67461eSJoseph Mingrone */ 112ee67461eSJoseph Mingrone #define MAC_ADDR_LEN 6U /* length of MAC addresses */ 113ee67461eSJoseph Mingrone typedef unsigned char nd_mac_addr[MAC_ADDR_LEN]; 114ee67461eSJoseph Mingrone 115ee67461eSJoseph Mingrone /* 116ee67461eSJoseph Mingrone * Use this for blobs of bytes; make them arrays of nd_byte. 117ee67461eSJoseph Mingrone */ 118ee67461eSJoseph Mingrone typedef unsigned char nd_byte; 119ee67461eSJoseph Mingrone 120ee67461eSJoseph Mingrone /* 121ee67461eSJoseph Mingrone * Round up x to a multiple of y; y must be a power of 2. 122ee67461eSJoseph Mingrone */ 123ee67461eSJoseph Mingrone #ifndef roundup2 124ee67461eSJoseph Mingrone #define roundup2(x, y) (((x)+((u_int)((y)-1)))&(~((u_int)((y)-1)))) 125ee67461eSJoseph Mingrone #endif 1261de50e9fSSam Leffler 1271de50e9fSSam Leffler #include <stdarg.h> 1283340d773SGleb Smirnoff #include <pcap.h> 1291de50e9fSSam Leffler 1303c602fabSXin LI #include "ip.h" /* struct ip for nextproto4_cksum() */ 1313340d773SGleb Smirnoff #include "ip6.h" /* struct ip6 for nextproto6_cksum() */ 1323340d773SGleb Smirnoff 1331de50e9fSSam Leffler #ifndef HAVE_STRLCAT 1341de50e9fSSam Leffler extern size_t strlcat (char *, const char *, size_t); 1351de50e9fSSam Leffler #endif 1361de50e9fSSam Leffler #ifndef HAVE_STRLCPY 1371de50e9fSSam Leffler extern size_t strlcpy (char *, const char *, size_t); 1381de50e9fSSam Leffler #endif 1391de50e9fSSam Leffler 1401de50e9fSSam Leffler #ifndef HAVE_STRDUP 1411de50e9fSSam Leffler extern char *strdup (const char *str); 1421de50e9fSSam Leffler #endif 1431de50e9fSSam Leffler 1441de50e9fSSam Leffler #ifndef HAVE_STRSEP 1451de50e9fSSam Leffler extern char *strsep(char **, const char *); 1461de50e9fSSam Leffler #endif 1471de50e9fSSam Leffler 1481de50e9fSSam Leffler struct tok { 1493c602fabSXin LI u_int v; /* value */ 1501de50e9fSSam Leffler const char *s; /* string */ 1511de50e9fSSam Leffler }; 1521de50e9fSSam Leffler 1531de50e9fSSam Leffler /* tok2str is deprecated */ 1548bdc5a62SPatrick Kelsey extern const char *tok2str(const struct tok *, const char *, u_int); 1558bdc5a62SPatrick Kelsey extern char *bittok2str(const struct tok *, const char *, u_int); 1568bdc5a62SPatrick Kelsey extern char *bittok2str_nosep(const struct tok *, const char *, u_int); 1571de50e9fSSam Leffler 1583340d773SGleb Smirnoff /* Initialize netdissect. */ 1593340d773SGleb Smirnoff extern int nd_init(char *, size_t); 1603340d773SGleb Smirnoff /* Clean up netdissect. */ 1613340d773SGleb Smirnoff extern void nd_cleanup(void); 1623340d773SGleb Smirnoff 1633340d773SGleb Smirnoff /* Do we have libsmi support? */ 1643340d773SGleb Smirnoff extern int nd_have_smi_support(void); 1653340d773SGleb Smirnoff /* Load an SMI module. */ 1663340d773SGleb Smirnoff extern int nd_load_smi_module(const char *, char *, size_t); 1673340d773SGleb Smirnoff /* Flag indicating whether an SMI module has been loaded. */ 1683340d773SGleb Smirnoff extern int nd_smi_module_loaded; 1693340d773SGleb Smirnoff /* Version number of the SMI library, or NULL if we don't have libsmi support. */ 1703340d773SGleb Smirnoff extern const char *nd_smi_version_string(void); 1711de50e9fSSam Leffler 1721de50e9fSSam Leffler typedef struct netdissect_options netdissect_options; 1731de50e9fSSam Leffler 1743340d773SGleb Smirnoff #define IF_PRINTER_ARGS (netdissect_options *, const struct pcap_pkthdr *, const u_char *) 1753340d773SGleb Smirnoff 176ee67461eSJoseph Mingrone typedef void (*if_printer) IF_PRINTER_ARGS; 177ee67461eSJoseph Mingrone 178ee67461eSJoseph Mingrone /* 179ee67461eSJoseph Mingrone * In case the data in a buffer needs to be processed by being decrypted, 180ee67461eSJoseph Mingrone * decompressed, etc. before it's dissected, we can't process it in place, 181ee67461eSJoseph Mingrone * we have to allocate a new buffer for the processed data. 182ee67461eSJoseph Mingrone * 183ee67461eSJoseph Mingrone * We keep a stack of those buffers; when we allocate a new buffer, we 184ee67461eSJoseph Mingrone * push the current one onto a stack, and when we're done with the new 185ee67461eSJoseph Mingrone * buffer, we free the current buffer and pop the previous one off the 186ee67461eSJoseph Mingrone * stack. 187ee67461eSJoseph Mingrone * 188ee67461eSJoseph Mingrone * A buffer has a beginning and end pointer, and a link to the previous 189ee67461eSJoseph Mingrone * buffer on the stack. 190ee67461eSJoseph Mingrone * 191ee67461eSJoseph Mingrone * In other cases, we temporarily adjust the snapshot end to reflect a 192ee67461eSJoseph Mingrone * packet-length field in the packet data and, when finished dissecting 193ee67461eSJoseph Mingrone * that part of the packet, restore the old snapshot end. We keep that 194ee67461eSJoseph Mingrone * on the stack with null buffer pointer, meaning there's nothing to 195ee67461eSJoseph Mingrone * free. 196ee67461eSJoseph Mingrone */ 197ee67461eSJoseph Mingrone struct netdissect_saved_packet_info { 198ee67461eSJoseph Mingrone u_char *ndspi_buffer; /* pointer to allocated buffer data */ 199ee67461eSJoseph Mingrone const u_char *ndspi_packetp; /* saved beginning of data */ 200ee67461eSJoseph Mingrone const u_char *ndspi_snapend; /* saved end of data */ 201ee67461eSJoseph Mingrone struct netdissect_saved_packet_info *ndspi_prev; /* previous buffer on the stack */ 202ee67461eSJoseph Mingrone }; 203ee67461eSJoseph Mingrone 204ee67461eSJoseph Mingrone /* 'val' value(s) for longjmp */ 205ee67461eSJoseph Mingrone #define ND_TRUNCATED 1 2063340d773SGleb Smirnoff 2071de50e9fSSam Leffler struct netdissect_options { 20827df3f5dSRui Paulo int ndo_bflag; /* print 4 byte ASes in ASDOT notation */ 2091de50e9fSSam Leffler int ndo_eflag; /* print ethernet header */ 2101de50e9fSSam Leffler int ndo_fflag; /* don't translate "foreign" IP address */ 211ee67461eSJoseph Mingrone int ndo_Kflag; /* don't check IP, TCP or UDP checksums */ 2121de50e9fSSam Leffler int ndo_nflag; /* leave addresses as numbers */ 2131de50e9fSSam Leffler int ndo_Nflag; /* remove domains from printed host names */ 2141de50e9fSSam Leffler int ndo_qflag; /* quick (shorter) output */ 2151de50e9fSSam Leffler int ndo_Sflag; /* print raw TCP sequence numbers */ 2161de50e9fSSam Leffler int ndo_tflag; /* print packet arrival time */ 2171de50e9fSSam Leffler int ndo_uflag; /* Print undecoded NFS handles */ 2183340d773SGleb Smirnoff int ndo_vflag; /* verbosity level */ 2191de50e9fSSam Leffler int ndo_xflag; /* print packet in hex */ 220ee67461eSJoseph Mingrone int ndo_Xflag; /* print packet in hex/ASCII */ 221ee67461eSJoseph Mingrone int ndo_Aflag; /* print packet only in ASCII observing TAB, 2221de50e9fSSam Leffler * LF, CR and SPACE as graphical chars 2231de50e9fSSam Leffler */ 224cac3dcd5SXin LI int ndo_Hflag; /* dissect 802.11s draft mesh standard */ 225ee67461eSJoseph Mingrone const char *ndo_protocol; /* protocol */ 226ee67461eSJoseph Mingrone jmp_buf ndo_early_end; /* jmp_buf for setjmp()/longjmp() */ 227ee67461eSJoseph Mingrone void *ndo_last_mem_p; /* pointer to the last allocated memory chunk */ 2283c602fabSXin LI int ndo_packet_number; /* print a packet number in the beginning of line */ 2292ebc47dbSSam Leffler int ndo_suppress_default_print; /* don't use default_print() for unknown packet types */ 2303c602fabSXin LI int ndo_tstamp_precision; /* requested time stamp precision */ 2313340d773SGleb Smirnoff const char *program_name; /* Name of the program using the library */ 2321de50e9fSSam Leffler 2331de50e9fSSam Leffler char *ndo_espsecret; 2341de50e9fSSam Leffler struct sa_list *ndo_sa_list_head; /* used by print-esp.c */ 2351de50e9fSSam Leffler struct sa_list *ndo_sa_default; 2361de50e9fSSam Leffler 23727df3f5dSRui Paulo char *ndo_sigsecret; /* Signature verification secret key */ 2381de50e9fSSam Leffler 2391de50e9fSSam Leffler int ndo_packettype; /* as specified by -T */ 2401de50e9fSSam Leffler 2411de50e9fSSam Leffler int ndo_snaplen; 242ee67461eSJoseph Mingrone int ndo_ll_hdr_len; /* link-layer header length */ 2431de50e9fSSam Leffler 2441de50e9fSSam Leffler /*global pointers to beginning and end of current packet (during printing) */ 2451de50e9fSSam Leffler const u_char *ndo_packetp; 2461de50e9fSSam Leffler const u_char *ndo_snapend; 2471de50e9fSSam Leffler 248ee67461eSJoseph Mingrone /* stack of saved packet boundary and buffer information */ 249ee67461eSJoseph Mingrone struct netdissect_saved_packet_info *ndo_packet_info_stack; 250ee67461eSJoseph Mingrone 2513340d773SGleb Smirnoff /* pointer to the if_printer function */ 2523340d773SGleb Smirnoff if_printer ndo_if_printer; 2531de50e9fSSam Leffler 2541de50e9fSSam Leffler /* pointer to void function to output stuff */ 2551de50e9fSSam Leffler void (*ndo_default_print)(netdissect_options *, 256ee67461eSJoseph Mingrone const u_char *bp, u_int length); 2578bdc5a62SPatrick Kelsey 2588bdc5a62SPatrick Kelsey /* pointer to function to do regular output */ 2591de50e9fSSam Leffler int (*ndo_printf)(netdissect_options *, 26027df3f5dSRui Paulo const char *fmt, ...) 261ee67461eSJoseph Mingrone PRINTFLIKE_FUNCPTR(2, 3); 2628bdc5a62SPatrick Kelsey /* pointer to function to output errors */ 263ee67461eSJoseph Mingrone void NORETURN_FUNCPTR (*ndo_error)(netdissect_options *, 264ee67461eSJoseph Mingrone status_exit_codes_t status, 26527df3f5dSRui Paulo const char *fmt, ...) 266ee67461eSJoseph Mingrone PRINTFLIKE_FUNCPTR(3, 4); 2678bdc5a62SPatrick Kelsey /* pointer to function to output warnings */ 2681de50e9fSSam Leffler void (*ndo_warning)(netdissect_options *, 26927df3f5dSRui Paulo const char *fmt, ...) 270ee67461eSJoseph Mingrone PRINTFLIKE_FUNCPTR(2, 3); 2711de50e9fSSam Leffler }; 2721de50e9fSSam Leffler 273ee67461eSJoseph Mingrone extern WARN_UNUSED_RESULT int nd_push_buffer(netdissect_options *, u_char *, const u_char *, const u_int); 274ee67461eSJoseph Mingrone extern WARN_UNUSED_RESULT int nd_push_snaplen(netdissect_options *, const u_char *, const u_int); 275ee67461eSJoseph Mingrone extern void nd_change_snaplen(netdissect_options *, const u_char *, const u_int); 276ee67461eSJoseph Mingrone extern void nd_pop_packet_info(netdissect_options *); 277ee67461eSJoseph Mingrone extern void nd_pop_all_packet_info(netdissect_options *); 278ee67461eSJoseph Mingrone 279ee67461eSJoseph Mingrone /* 280*0a7e5f1fSJoseph Mingrone * Report a packet truncation with a longjmp(). 281ee67461eSJoseph Mingrone */ 282*0a7e5f1fSJoseph Mingrone NORETURN void nd_trunc_longjmp(netdissect_options *ndo); 283ee67461eSJoseph Mingrone 2841de50e9fSSam Leffler #define PT_VAT 1 /* Visual Audio Tool */ 2851de50e9fSSam Leffler #define PT_WB 2 /* distributed White Board */ 2861de50e9fSSam Leffler #define PT_RPC 3 /* Remote Procedure Call */ 2871de50e9fSSam Leffler #define PT_RTP 4 /* Real-Time Applications protocol */ 2881de50e9fSSam Leffler #define PT_RTCP 5 /* Real-Time Applications control protocol */ 2891de50e9fSSam Leffler #define PT_SNMP 6 /* Simple Network Management Protocol */ 2901de50e9fSSam Leffler #define PT_CNFP 7 /* Cisco NetFlow protocol */ 291d03c0883SXin LI #define PT_TFTP 8 /* trivial file transfer protocol */ 292d03c0883SXin LI #define PT_AODV 9 /* Ad-hoc On-demand Distance Vector Protocol */ 293d03c0883SXin LI #define PT_CARP 10 /* Common Address Redundancy Protocol */ 294d03c0883SXin LI #define PT_RADIUS 11 /* RADIUS authentication Protocol */ 295d03c0883SXin LI #define PT_ZMTP1 12 /* ZeroMQ Message Transport Protocol 1.0 */ 296d03c0883SXin LI #define PT_VXLAN 13 /* Virtual eXtensible Local Area Network */ 2973c602fabSXin LI #define PT_PGM 14 /* [UDP-encapsulated] Pragmatic General Multicast */ 2983c602fabSXin LI #define PT_PGM_ZMTP1 15 /* ZMTP/1.0 inside PGM (native or UDP-encapsulated) */ 2993c602fabSXin LI #define PT_LMP 16 /* Link Management Protocol */ 3003340d773SGleb Smirnoff #define PT_RESP 17 /* RESP */ 301ee67461eSJoseph Mingrone #define PT_PTP 18 /* PTP */ 302ee67461eSJoseph Mingrone #define PT_SOMEIP 19 /* Autosar SOME/IP Protocol */ 303ee67461eSJoseph Mingrone #define PT_DOMAIN 20 /* Domain Name System (DNS) */ 3041de50e9fSSam Leffler 305ee67461eSJoseph Mingrone #define ND_MIN(a,b) ((a)>(b)?(b):(a)) 306ee67461eSJoseph Mingrone #define ND_MAX(a,b) ((b)>(a)?(b):(a)) 3071de50e9fSSam Leffler 3083340d773SGleb Smirnoff /* For source or destination ports tests (UDP, TCP, ...) */ 3093340d773SGleb Smirnoff #define IS_SRC_OR_DST_PORT(p) (sport == (p) || dport == (p)) 3103340d773SGleb Smirnoff 3111de50e9fSSam Leffler /* 31227df3f5dSRui Paulo * Maximum snapshot length. This should be enough to capture the full 31327df3f5dSRui Paulo * packet on most network interfaces. 31427df3f5dSRui Paulo * 3153c602fabSXin LI * 3163c602fabSXin LI * Somewhat arbitrary, but chosen to be: 3173c602fabSXin LI * 3183c602fabSXin LI * 1) big enough for maximum-size Linux loopback packets (65549) 3193c602fabSXin LI * and some USB packets captured with USBPcap: 3203c602fabSXin LI * 321ee67461eSJoseph Mingrone * https://desowin.org/usbpcap/ 3223c602fabSXin LI * 3233c602fabSXin LI * (> 131072, < 262144) 3243c602fabSXin LI * 3253c602fabSXin LI * and 3263c602fabSXin LI * 3273c602fabSXin LI * 2) small enough not to cause attempts to allocate huge amounts of 3283c602fabSXin LI * memory; some applications might use the snapshot length in a 3293c602fabSXin LI * savefile header to control the size of the buffer they allocate, 3303c602fabSXin LI * so a size of, say, 2^31-1 might not work well. 3313c602fabSXin LI * 332ee67461eSJoseph Mingrone * XXX - does it need to be bigger still? Note that, for versions of 333ee67461eSJoseph Mingrone * libpcap with pcap_create()/pcap_activate(), if no -s flag is specified 334ee67461eSJoseph Mingrone * or -s 0 is specified, we won't set the snapshot length at all, and will 335ee67461eSJoseph Mingrone * let libpcap choose a snapshot length; newer versions may choose a bigger 336ee67461eSJoseph Mingrone * value than 262144 for D-Bus, for example. 3371de50e9fSSam Leffler */ 3383c602fabSXin LI #define MAXIMUM_SNAPLEN 262144 3391de50e9fSSam Leffler 34027df3f5dSRui Paulo /* 341ee67461eSJoseph Mingrone * True if "l" bytes from "p" were captured. 3421de50e9fSSam Leffler * 3431de50e9fSSam Leffler * The "ndo->ndo_snapend - (l) <= ndo->ndo_snapend" checks to make sure 3441de50e9fSSam Leffler * "l" isn't so large that "ndo->ndo_snapend - (l)" underflows. 3451de50e9fSSam Leffler * 3461de50e9fSSam Leffler * The check is for <= rather than < because "l" might be 0. 3478bdc5a62SPatrick Kelsey * 3488bdc5a62SPatrick Kelsey * We cast the pointers to uintptr_t to make sure that the compiler 3498bdc5a62SPatrick Kelsey * doesn't optimize away any of these tests (which it is allowed to 3508bdc5a62SPatrick Kelsey * do, as adding an integer to, or subtracting an integer from, a 3518bdc5a62SPatrick Kelsey * pointer assumes that the pointer is a pointer to an element of an 3528bdc5a62SPatrick Kelsey * array and that the result of the addition or subtraction yields a 3538bdc5a62SPatrick Kelsey * pointer to another member of the array, so that, for example, if 3548bdc5a62SPatrick Kelsey * you subtract a positive integer from a pointer, the result is 3558bdc5a62SPatrick Kelsey * guaranteed to be less than the original pointer value). See 3568bdc5a62SPatrick Kelsey * 357ee67461eSJoseph Mingrone * https://www.kb.cert.org/vuls/id/162289 3581de50e9fSSam Leffler */ 359358fd7daSPatrick Kelsey 3603340d773SGleb Smirnoff /* 3613340d773SGleb Smirnoff * Test in two parts to avoid these warnings: 3623340d773SGleb Smirnoff * comparison of unsigned expression >= 0 is always true [-Wtype-limits], 3633340d773SGleb Smirnoff * comparison is always true due to limited range of data type [-Wtype-limits]. 3643340d773SGleb Smirnoff */ 365358fd7daSPatrick Kelsey #define IS_NOT_NEGATIVE(x) (((x) > 0) || ((x) == 0)) 366358fd7daSPatrick Kelsey 367ee67461eSJoseph Mingrone #define ND_TTEST_LEN(p, l) \ 368358fd7daSPatrick Kelsey (IS_NOT_NEGATIVE(l) && \ 3698bdc5a62SPatrick Kelsey ((uintptr_t)ndo->ndo_snapend - (l) <= (uintptr_t)ndo->ndo_snapend && \ 370ee67461eSJoseph Mingrone (uintptr_t)(p) <= (uintptr_t)ndo->ndo_snapend - (l))) 3711de50e9fSSam Leffler 372ee67461eSJoseph Mingrone /* True if "*(p)" was captured */ 373ee67461eSJoseph Mingrone #define ND_TTEST_SIZE(p) ND_TTEST_LEN(p, sizeof(*(p))) 3741de50e9fSSam Leffler 375ee67461eSJoseph Mingrone /* Bail out if "l" bytes from "p" were not captured */ 376ee67461eSJoseph Mingrone #ifdef ND_LONGJMP_FROM_TCHECK 377ee67461eSJoseph Mingrone #define ND_TCHECK_LEN(p, l) if (!ND_TTEST_LEN(p, l)) nd_trunc_longjmp(ndo) 378ee67461eSJoseph Mingrone #else 379ee67461eSJoseph Mingrone #define ND_TCHECK_LEN(p, l) if (!ND_TTEST_LEN(p, l)) goto trunc 380ee67461eSJoseph Mingrone #endif 3811de50e9fSSam Leffler 382ee67461eSJoseph Mingrone /* Bail out if "*(p)" was not captured */ 383ee67461eSJoseph Mingrone #define ND_TCHECK_SIZE(p) ND_TCHECK_LEN(p, sizeof(*(p))) 3841de50e9fSSam Leffler 385ee67461eSJoseph Mingrone /* 386ee67461eSJoseph Mingrone * Number of bytes between two pointers. 387ee67461eSJoseph Mingrone */ 388*0a7e5f1fSJoseph Mingrone #define ND_BYTES_BETWEEN(p1, p2) ((const u_char *)(p1) >= (const u_char *)(p2) ? 0 : ((u_int)(((const u_char *)(p2)) - (const u_char *)(p1)))) 389ee67461eSJoseph Mingrone 390ee67461eSJoseph Mingrone /* 391ee67461eSJoseph Mingrone * Number of bytes remaining in the captured data, starting at the 392ee67461eSJoseph Mingrone * byte pointed to by the argument. 393ee67461eSJoseph Mingrone */ 394*0a7e5f1fSJoseph Mingrone #define ND_BYTES_AVAILABLE_AFTER(p) ((const u_char *)(p) < ndo->ndo_packetp ? 0 : ND_BYTES_BETWEEN((p), ndo->ndo_snapend)) 395ee67461eSJoseph Mingrone 396*0a7e5f1fSJoseph Mingrone /* 397*0a7e5f1fSJoseph Mingrone * Check (expression_1 operator expression_2) for invalid packet with 398*0a7e5f1fSJoseph Mingrone * a custom message, format %u 399*0a7e5f1fSJoseph Mingrone */ 400*0a7e5f1fSJoseph Mingrone #define ND_ICHECKMSG_U(message, expression_1, operator, expression_2) \ 401*0a7e5f1fSJoseph Mingrone if ((expression_1) operator (expression_2)) { \ 402*0a7e5f1fSJoseph Mingrone ND_PRINT(" [%s %u %s %u]", (message), (expression_1), (#operator), (expression_2)); \ 403ee67461eSJoseph Mingrone goto invalid; \ 404ee67461eSJoseph Mingrone } 405ee67461eSJoseph Mingrone 406*0a7e5f1fSJoseph Mingrone /* 407*0a7e5f1fSJoseph Mingrone * Check (expression_1 operator expression_2) for invalid packet with 408*0a7e5f1fSJoseph Mingrone * "expression_1" message, format %u 409*0a7e5f1fSJoseph Mingrone */ 410*0a7e5f1fSJoseph Mingrone #define ND_ICHECK_U(expression_1, operator, expression_2) \ 411*0a7e5f1fSJoseph Mingrone ND_ICHECKMSG_U((#expression_1), (expression_1), operator, (expression_2)) 412ee67461eSJoseph Mingrone 413*0a7e5f1fSJoseph Mingrone /* 414*0a7e5f1fSJoseph Mingrone * Check (expression_1 operator expression_2) for invalid packet with 415*0a7e5f1fSJoseph Mingrone * a custom message, format %zu 416*0a7e5f1fSJoseph Mingrone */ 417*0a7e5f1fSJoseph Mingrone #define ND_ICHECKMSG_ZU(message, expression_1, operator, expression_2) \ 418*0a7e5f1fSJoseph Mingrone if ((expression_1) operator (expression_2)) { \ 419*0a7e5f1fSJoseph Mingrone ND_PRINT(" [%s %u %s %zu]", (message), (expression_1), (#operator), (expression_2)); \ 420ee67461eSJoseph Mingrone goto invalid; \ 421ee67461eSJoseph Mingrone } 422ee67461eSJoseph Mingrone 423*0a7e5f1fSJoseph Mingrone /* 424*0a7e5f1fSJoseph Mingrone * Check (expression_1 operator expression_2) for invalid packet with 425*0a7e5f1fSJoseph Mingrone * "expression_1" message, format %zu 426*0a7e5f1fSJoseph Mingrone */ 427*0a7e5f1fSJoseph Mingrone #define ND_ICHECK_ZU(expression_1, operator, expression_2) \ 428*0a7e5f1fSJoseph Mingrone ND_ICHECKMSG_ZU((#expression_1), (expression_1), operator, (expression_2)) 429ee67461eSJoseph Mingrone 430ee67461eSJoseph Mingrone #define ND_PRINT(...) (ndo->ndo_printf)(ndo, __VA_ARGS__) 4311de50e9fSSam Leffler #define ND_DEFAULTPRINT(ap, length) (*ndo->ndo_default_print)(ndo, ap, length) 4321de50e9fSSam Leffler 4333c602fabSXin LI extern void ts_print(netdissect_options *, const struct timeval *); 4343340d773SGleb Smirnoff extern void signed_relts_print(netdissect_options *, int32_t); 4353340d773SGleb Smirnoff extern void unsigned_relts_print(netdissect_options *, uint32_t); 4361de50e9fSSam Leffler 437ee67461eSJoseph Mingrone extern const char *nd_format_time(char *buf, size_t bufsize, 438ee67461eSJoseph Mingrone const char *format, const struct tm *timeptr); 439ee67461eSJoseph Mingrone 4403340d773SGleb Smirnoff extern void fn_print_char(netdissect_options *, u_char); 441ee67461eSJoseph Mingrone extern void fn_print_str(netdissect_options *, const u_char *); 442ee67461eSJoseph Mingrone extern u_int nd_printztn(netdissect_options *, const u_char *, u_int, const u_char *); 443ee67461eSJoseph Mingrone extern int nd_printn(netdissect_options *, const u_char *, u_int, const u_char *); 444*0a7e5f1fSJoseph Mingrone extern void nd_printjn(netdissect_options *, const u_char *, u_int); 445ee67461eSJoseph Mingrone extern void nd_printjnp(netdissect_options *, const u_char *, u_int); 4468bdc5a62SPatrick Kelsey 4478bdc5a62SPatrick Kelsey /* 4488bdc5a62SPatrick Kelsey * Flags for txtproto_print(). 4498bdc5a62SPatrick Kelsey */ 4508bdc5a62SPatrick Kelsey #define RESP_CODE_SECOND_TOKEN 0x00000001 /* response code is second token in response line */ 4518bdc5a62SPatrick Kelsey 4528bdc5a62SPatrick Kelsey extern void txtproto_print(netdissect_options *, const u_char *, u_int, 453ee67461eSJoseph Mingrone const char **, u_int); 4541de50e9fSSam Leffler 455ee67461eSJoseph Mingrone #if (defined(__i386__) || defined(_M_IX86) || defined(__X86__) || defined(__x86_64__) || defined(_M_X64)) || \ 456ee67461eSJoseph Mingrone (defined(__arm__) || defined(_M_ARM) || defined(__aarch64__)) || \ 457ee67461eSJoseph Mingrone (defined(__m68k__) && (!defined(__mc68000__) && !defined(__mc68010__))) || \ 458ee67461eSJoseph Mingrone (defined(__ppc__) || defined(__ppc64__) || defined(_M_PPC) || defined(_ARCH_PPC) || defined(_ARCH_PPC64)) || \ 459ee67461eSJoseph Mingrone (defined(__s390__) || defined(__s390x__) || defined(__zarch__)) || \ 460ee67461eSJoseph Mingrone defined(__vax__) 4613c602fabSXin LI /* 462ee67461eSJoseph Mingrone * The processor natively handles unaligned loads, so just use memcpy() 463ee67461eSJoseph Mingrone * and memcmp(), to enable those optimizations. 464ee67461eSJoseph Mingrone * 465ee67461eSJoseph Mingrone * XXX - are those all the x86 tests we need? 466ee67461eSJoseph Mingrone * XXX - do we need to worry about ARMv1 through ARMv5, which didn't 467ee67461eSJoseph Mingrone * support unaligned loads, and, if so, do we need to worry about all 468ee67461eSJoseph Mingrone * of them, or just some of them, e.g. ARMv5? 469ee67461eSJoseph Mingrone * XXX - are those the only 68k tests we need not to generated 470ee67461eSJoseph Mingrone * unaligned accesses if the target is the 68000 or 68010? 471ee67461eSJoseph Mingrone * XXX - are there any tests we don't need, because some definitions are for 472ee67461eSJoseph Mingrone * compilers that also predefine the GCC symbols? 473ee67461eSJoseph Mingrone * XXX - do we need to test for both 32-bit and 64-bit versions of those 474ee67461eSJoseph Mingrone * architectures in all cases? 4753c602fabSXin LI */ 476ee67461eSJoseph Mingrone #define UNALIGNED_MEMCPY(p, q, l) memcpy((p), (q), (l)) 477ee67461eSJoseph Mingrone #define UNALIGNED_MEMCMP(p, q, l) memcmp((p), (q), (l)) 478ee67461eSJoseph Mingrone #else 4793c602fabSXin LI /* 4803c602fabSXin LI * The processor doesn't natively handle unaligned loads, 4813c602fabSXin LI * and the compiler might "helpfully" optimize memcpy() 4823c602fabSXin LI * and memcmp(), when handed pointers that would normally 4833c602fabSXin LI * be properly aligned, into sequences that assume proper 4843c602fabSXin LI * alignment. 4853c602fabSXin LI * 4863c602fabSXin LI * Do copies and compares of possibly-unaligned data by 4873c602fabSXin LI * calling routines that wrap memcpy() and memcmp(), to 4883c602fabSXin LI * prevent that optimization. 4893c602fabSXin LI */ 4903c602fabSXin LI extern void unaligned_memcpy(void *, const void *, size_t); 4913c602fabSXin LI extern int unaligned_memcmp(const void *, const void *, size_t); 4923c602fabSXin LI #define UNALIGNED_MEMCPY(p, q, l) unaligned_memcpy((p), (q), (l)) 4933c602fabSXin LI #define UNALIGNED_MEMCMP(p, q, l) unaligned_memcmp((p), (q), (l)) 4943c602fabSXin LI #endif 4951de50e9fSSam Leffler 496cac3dcd5SXin LI #define PLURAL_SUFFIX(n) \ 497cac3dcd5SXin LI (((n) != 1) ? "s" : "") 498cac3dcd5SXin LI 4993340d773SGleb Smirnoff extern const char *tok2strary_internal(const char **, int, const char *, int); 5003340d773SGleb Smirnoff #define tok2strary(a,f,i) tok2strary_internal(a, sizeof(a)/sizeof(a[0]),f,i) 5013340d773SGleb Smirnoff 502ee67461eSJoseph Mingrone struct uint_tokary 503ee67461eSJoseph Mingrone { 504ee67461eSJoseph Mingrone u_int uintval; 505ee67461eSJoseph Mingrone const struct tok *tokary; 506ee67461eSJoseph Mingrone }; 507ee67461eSJoseph Mingrone 508ee67461eSJoseph Mingrone extern const struct tok *uint2tokary_internal(const struct uint_tokary[], const size_t, const u_int); 509ee67461eSJoseph Mingrone #define uint2tokary(a, i) uint2tokary_internal(a, sizeof(a)/sizeof(a[0]), i) 510ee67461eSJoseph Mingrone 5113340d773SGleb Smirnoff extern if_printer lookup_printer(int); 5123340d773SGleb Smirnoff 513ee67461eSJoseph Mingrone #define ND_DEBUG {printf(" [%s:%d %s] ", __FILE__, __LINE__, __func__); fflush(stdout);} 514ee67461eSJoseph Mingrone 5153340d773SGleb Smirnoff /* The DLT printer routines */ 5163340d773SGleb Smirnoff 517ee67461eSJoseph Mingrone extern void ap1394_if_print IF_PRINTER_ARGS; 518ee67461eSJoseph Mingrone extern void arcnet_if_print IF_PRINTER_ARGS; 519ee67461eSJoseph Mingrone extern void arcnet_linux_if_print IF_PRINTER_ARGS; 520ee67461eSJoseph Mingrone extern void atm_if_print IF_PRINTER_ARGS; 521ee67461eSJoseph Mingrone extern void brcm_tag_if_print IF_PRINTER_ARGS; 522ee67461eSJoseph Mingrone extern void brcm_tag_prepend_if_print IF_PRINTER_ARGS; 523ee67461eSJoseph Mingrone extern void bt_if_print IF_PRINTER_ARGS; 524ee67461eSJoseph Mingrone extern void chdlc_if_print IF_PRINTER_ARGS; 525ee67461eSJoseph Mingrone extern void cip_if_print IF_PRINTER_ARGS; 526ee67461eSJoseph Mingrone extern void dsa_if_print IF_PRINTER_ARGS; 527ee67461eSJoseph Mingrone extern void edsa_if_print IF_PRINTER_ARGS; 528ee67461eSJoseph Mingrone extern void enc_if_print IF_PRINTER_ARGS; 529ee67461eSJoseph Mingrone extern void ether_if_print IF_PRINTER_ARGS; 530ee67461eSJoseph Mingrone extern void fddi_if_print IF_PRINTER_ARGS; 531ee67461eSJoseph Mingrone extern void fr_if_print IF_PRINTER_ARGS; 532ee67461eSJoseph Mingrone extern void ieee802_11_if_print IF_PRINTER_ARGS; 533ee67461eSJoseph Mingrone extern void ieee802_11_radio_avs_if_print IF_PRINTER_ARGS; 534ee67461eSJoseph Mingrone extern void ieee802_11_radio_if_print IF_PRINTER_ARGS; 535ee67461eSJoseph Mingrone extern void ieee802_15_4_if_print IF_PRINTER_ARGS; 536ee67461eSJoseph Mingrone extern void ieee802_15_4_tap_if_print IF_PRINTER_ARGS; 537ee67461eSJoseph Mingrone extern void ipfc_if_print IF_PRINTER_ARGS; 538ee67461eSJoseph Mingrone extern void ipnet_if_print IF_PRINTER_ARGS; 539ee67461eSJoseph Mingrone extern void ipoib_if_print IF_PRINTER_ARGS; 540ee67461eSJoseph Mingrone extern void juniper_atm1_if_print IF_PRINTER_ARGS; 541ee67461eSJoseph Mingrone extern void juniper_atm2_if_print IF_PRINTER_ARGS; 542ee67461eSJoseph Mingrone extern void juniper_chdlc_if_print IF_PRINTER_ARGS; 543ee67461eSJoseph Mingrone extern void juniper_es_if_print IF_PRINTER_ARGS; 544ee67461eSJoseph Mingrone extern void juniper_ether_if_print IF_PRINTER_ARGS; 545ee67461eSJoseph Mingrone extern void juniper_frelay_if_print IF_PRINTER_ARGS; 546ee67461eSJoseph Mingrone extern void juniper_ggsn_if_print IF_PRINTER_ARGS; 547ee67461eSJoseph Mingrone extern void juniper_mfr_if_print IF_PRINTER_ARGS; 548ee67461eSJoseph Mingrone extern void juniper_mlfr_if_print IF_PRINTER_ARGS; 549ee67461eSJoseph Mingrone extern void juniper_mlppp_if_print IF_PRINTER_ARGS; 550ee67461eSJoseph Mingrone extern void juniper_monitor_if_print IF_PRINTER_ARGS; 551ee67461eSJoseph Mingrone extern void juniper_ppp_if_print IF_PRINTER_ARGS; 552ee67461eSJoseph Mingrone extern void juniper_pppoe_atm_if_print IF_PRINTER_ARGS; 553ee67461eSJoseph Mingrone extern void juniper_pppoe_if_print IF_PRINTER_ARGS; 554ee67461eSJoseph Mingrone extern void juniper_services_if_print IF_PRINTER_ARGS; 555ee67461eSJoseph Mingrone extern void ltalk_if_print IF_PRINTER_ARGS; 556ee67461eSJoseph Mingrone extern void mfr_if_print IF_PRINTER_ARGS; 557ee67461eSJoseph Mingrone extern void netanalyzer_if_print IF_PRINTER_ARGS; 558ee67461eSJoseph Mingrone extern void netanalyzer_transparent_if_print IF_PRINTER_ARGS; 559ee67461eSJoseph Mingrone extern void nflog_if_print IF_PRINTER_ARGS; 560ee67461eSJoseph Mingrone extern void null_if_print IF_PRINTER_ARGS; 561ee67461eSJoseph Mingrone extern void pflog_if_print IF_PRINTER_ARGS; 562ee67461eSJoseph Mingrone extern void pktap_if_print IF_PRINTER_ARGS; 563ee67461eSJoseph Mingrone extern void ppi_if_print IF_PRINTER_ARGS; 564ee67461eSJoseph Mingrone extern void ppp_bsdos_if_print IF_PRINTER_ARGS; 565ee67461eSJoseph Mingrone extern void ppp_hdlc_if_print IF_PRINTER_ARGS; 566ee67461eSJoseph Mingrone extern void ppp_if_print IF_PRINTER_ARGS; 567ee67461eSJoseph Mingrone extern void pppoe_if_print IF_PRINTER_ARGS; 568ee67461eSJoseph Mingrone extern void prism_if_print IF_PRINTER_ARGS; 569ee67461eSJoseph Mingrone extern void raw_if_print IF_PRINTER_ARGS; 570ee67461eSJoseph Mingrone extern void sl_bsdos_if_print IF_PRINTER_ARGS; 571ee67461eSJoseph Mingrone extern void sl_if_print IF_PRINTER_ARGS; 572ee67461eSJoseph Mingrone extern void sll2_if_print IF_PRINTER_ARGS; 573ee67461eSJoseph Mingrone extern void sll_if_print IF_PRINTER_ARGS; 574ee67461eSJoseph Mingrone extern void sunatm_if_print IF_PRINTER_ARGS; 575ee67461eSJoseph Mingrone extern void symantec_if_print IF_PRINTER_ARGS; 576ee67461eSJoseph Mingrone extern void token_if_print IF_PRINTER_ARGS; 577ee67461eSJoseph Mingrone extern void unsupported_if_print IF_PRINTER_ARGS; 578ee67461eSJoseph Mingrone extern void usb_linux_48_byte_if_print IF_PRINTER_ARGS; 579ee67461eSJoseph Mingrone extern void usb_linux_64_byte_if_print IF_PRINTER_ARGS; 580ee67461eSJoseph Mingrone extern void vsock_if_print IF_PRINTER_ARGS; 5813340d773SGleb Smirnoff 5823340d773SGleb Smirnoff /* 5833340d773SGleb Smirnoff * Structure passed to some printers to allow them to print 5843340d773SGleb Smirnoff * link-layer address information if ndo_eflag isn't set 5853340d773SGleb Smirnoff * (because they are for protocols that don't have their 5863340d773SGleb Smirnoff * own addresses, so that we'd want to report link-layer 5873340d773SGleb Smirnoff * address information). 5883340d773SGleb Smirnoff * 5893340d773SGleb Smirnoff * This contains a pointer to an address and a pointer to a routine 5903340d773SGleb Smirnoff * to which we pass that pointer in order to get a string. 5913340d773SGleb Smirnoff */ 5923340d773SGleb Smirnoff struct lladdr_info { 5933340d773SGleb Smirnoff const char *(*addr_string)(netdissect_options *, const u_char *); 5943340d773SGleb Smirnoff const u_char *addr; 5953340d773SGleb Smirnoff }; 5961de50e9fSSam Leffler 5971de50e9fSSam Leffler /* The printer routines. */ 5981de50e9fSSam Leffler 5993340d773SGleb Smirnoff extern void aarp_print(netdissect_options *, const u_char *, u_int); 600ee67461eSJoseph Mingrone extern int ah_print(netdissect_options *, const u_char *); 601ee67461eSJoseph Mingrone extern void ahcp_print(netdissect_options *, const u_char *, u_int); 6023c602fabSXin LI extern void aodv_print(netdissect_options *, const u_char *, u_int, int); 6033340d773SGleb Smirnoff extern void aoe_print(netdissect_options *, const u_char *, const u_int); 604ee67461eSJoseph Mingrone extern int arista_ethertype_print(netdissect_options *,const u_char *, u_int); 6053340d773SGleb Smirnoff extern void arp_print(netdissect_options *, const u_char *, u_int, u_int); 6063340d773SGleb Smirnoff extern void ascii_print(netdissect_options *, const u_char *, u_int); 6073340d773SGleb Smirnoff extern void atalk_print(netdissect_options *, const u_char *, u_int); 6083340d773SGleb Smirnoff extern void atm_print(netdissect_options *, u_int, u_int, u_int, const u_char *, u_int, u_int); 6093340d773SGleb Smirnoff extern void babel_print(netdissect_options *, const u_char *, u_int); 610ee67461eSJoseph Mingrone extern void bcm_li_print(netdissect_options *, const u_char *, u_int); 6113340d773SGleb Smirnoff extern void beep_print(netdissect_options *, const u_char *, u_int); 6123340d773SGleb Smirnoff extern void bfd_print(netdissect_options *, const u_char *, u_int, u_int); 613ee67461eSJoseph Mingrone extern void bgp_print(netdissect_options *, const u_char *, u_int); 614ee67461eSJoseph Mingrone extern const char *bgp_vpn_rd_print(netdissect_options *, const u_char *); 6153340d773SGleb Smirnoff extern void bootp_print(netdissect_options *, const u_char *, u_int); 6163340d773SGleb Smirnoff extern void calm_fast_print(netdissect_options *, const u_char *, u_int, const struct lladdr_info *); 617ee67461eSJoseph Mingrone extern void carp_print(netdissect_options *, const u_char *, u_int, u_int); 618ee67461eSJoseph Mingrone extern void cdp_print(netdissect_options *, const u_char *, u_int); 6193340d773SGleb Smirnoff extern void cfm_print(netdissect_options *, const u_char *, u_int); 620ee67461eSJoseph Mingrone extern u_int chdlc_print(netdissect_options *, const u_char *, u_int); 6213340d773SGleb Smirnoff extern void cisco_autorp_print(netdissect_options *, const u_char *, u_int); 6223340d773SGleb Smirnoff extern void cnfp_print(netdissect_options *, const u_char *); 6233340d773SGleb Smirnoff extern void dccp_print(netdissect_options *, const u_char *, const u_char *, u_int); 6243340d773SGleb Smirnoff extern void decnet_print(netdissect_options *, const u_char *, u_int, u_int); 6253340d773SGleb Smirnoff extern void dhcp6_print(netdissect_options *, const u_char *, u_int); 626ee67461eSJoseph Mingrone extern int dstopt_process(netdissect_options *, const u_char *); 6273340d773SGleb Smirnoff extern void dtp_print(netdissect_options *, const u_char *, u_int); 6283340d773SGleb Smirnoff extern void dvmrp_print(netdissect_options *, const u_char *, u_int); 6293340d773SGleb Smirnoff extern void eap_print(netdissect_options *, const u_char *, u_int); 630ee67461eSJoseph Mingrone extern void eapol_print(netdissect_options *, const u_char *); 6313340d773SGleb Smirnoff extern void egp_print(netdissect_options *, const u_char *, u_int); 6323340d773SGleb Smirnoff extern void eigrp_print(netdissect_options *, const u_char *, u_int); 633ee67461eSJoseph Mingrone extern void esp_print(netdissect_options *, const u_char *, u_int, const u_char *, u_int, int, u_int); 6343340d773SGleb Smirnoff extern u_int ether_print(netdissect_options *, const u_char *, u_int, u_int, void (*)(netdissect_options *, const u_char *), const u_char *); 635ee67461eSJoseph 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); 6363340d773SGleb Smirnoff extern int ethertype_print(netdissect_options *, u_short, const u_char *, u_int, u_int, const struct lladdr_info *, const struct lladdr_info *); 6373340d773SGleb Smirnoff extern u_int fddi_print(netdissect_options *, const u_char *, u_int, u_int); 6383c602fabSXin LI extern void forces_print(netdissect_options *, const u_char *, u_int); 639ee67461eSJoseph Mingrone extern u_int fr_print(netdissect_options *, const u_char *, u_int); 6403340d773SGleb Smirnoff extern int frag6_print(netdissect_options *, const u_char *, const u_char *); 6413340d773SGleb Smirnoff extern void ftp_print(netdissect_options *, const u_char *, u_int); 6423340d773SGleb Smirnoff extern void geneve_print(netdissect_options *, const u_char *, u_int); 6433340d773SGleb Smirnoff extern void geonet_print(netdissect_options *, const u_char *, u_int, const struct lladdr_info *); 6443340d773SGleb Smirnoff extern void gre_print(netdissect_options *, const u_char *, u_int); 645ee67461eSJoseph Mingrone extern int hbhopt_process(netdissect_options *, const u_char *, int *, uint32_t *); 6463340d773SGleb Smirnoff extern void hex_and_ascii_print(netdissect_options *, const char *, const u_char *, u_int); 6473340d773SGleb Smirnoff extern void hex_print(netdissect_options *, const char *ident, const u_char *cp, u_int); 6483340d773SGleb Smirnoff extern void hex_print_with_offset(netdissect_options *, const char *ident, const u_char *cp, u_int, u_int); 6493340d773SGleb Smirnoff extern void hncp_print(netdissect_options *, const u_char *, u_int); 6503340d773SGleb Smirnoff extern void hsrp_print(netdissect_options *, const u_char *, u_int); 6513340d773SGleb Smirnoff extern void http_print(netdissect_options *, const u_char *, u_int); 6523340d773SGleb Smirnoff extern void icmp6_print(netdissect_options *, const u_char *, u_int, const u_char *, int); 6533340d773SGleb Smirnoff extern void icmp_print(netdissect_options *, const u_char *, u_int, const u_char *, int); 654ee67461eSJoseph Mingrone extern u_int ieee802_15_4_print(netdissect_options *, const u_char *, u_int); 65539e421e8SCy Schubert extern u_int ieee802_11_radio_print(netdissect_options *, const u_char *, u_int, u_int); 6563340d773SGleb Smirnoff extern void igmp_print(netdissect_options *, const u_char *, u_int); 6573340d773SGleb Smirnoff extern void igrp_print(netdissect_options *, const u_char *, u_int); 6583340d773SGleb Smirnoff extern void ip6_print(netdissect_options *, const u_char *, u_int); 6593340d773SGleb Smirnoff extern void ipN_print(netdissect_options *, const u_char *, u_int); 660*0a7e5f1fSJoseph Mingrone extern void ip_print(netdissect_options *, const u_char *, const u_int); 661ee67461eSJoseph Mingrone extern void ipcomp_print(netdissect_options *, const u_char *); 6623340d773SGleb Smirnoff extern void ipx_netbios_print(netdissect_options *, const u_char *, u_int); 6633340d773SGleb Smirnoff extern void ipx_print(netdissect_options *, const u_char *, u_int); 6643340d773SGleb Smirnoff extern void isakmp_print(netdissect_options *, const u_char *, u_int, const u_char *); 665ee67461eSJoseph Mingrone extern void isakmp_rfc3948_print(netdissect_options *, const u_char *, u_int, const u_char *, int, int, u_int); 6660bff6a5aSEd Maste extern void isoclns_print(netdissect_options *, const u_char *, u_int); 6673c602fabSXin LI extern void krb_print(netdissect_options *, const u_char *); 6683340d773SGleb Smirnoff extern void l2tp_print(netdissect_options *, const u_char *, u_int); 6693340d773SGleb Smirnoff extern void lane_print(netdissect_options *, const u_char *, u_int, u_int); 6703340d773SGleb Smirnoff extern void ldp_print(netdissect_options *, const u_char *, u_int); 6713340d773SGleb Smirnoff extern void lisp_print(netdissect_options *, const u_char *, u_int); 6723c602fabSXin LI extern u_int llap_print(netdissect_options *, const u_char *, u_int); 6733340d773SGleb Smirnoff extern int llc_print(netdissect_options *, const u_char *, u_int, u_int, const struct lladdr_info *, const struct lladdr_info *); 6743340d773SGleb Smirnoff extern void lldp_print(netdissect_options *, const u_char *, u_int); 6753340d773SGleb Smirnoff extern void lmp_print(netdissect_options *, const u_char *, u_int); 676ee67461eSJoseph Mingrone extern void loopback_print(netdissect_options *, const u_char *, u_int); 6773340d773SGleb Smirnoff extern void lspping_print(netdissect_options *, const u_char *, u_int); 6783340d773SGleb Smirnoff extern void lwapp_control_print(netdissect_options *, const u_char *, u_int, int); 6793340d773SGleb Smirnoff extern void lwapp_data_print(netdissect_options *, const u_char *, u_int); 6803c602fabSXin LI extern void lwres_print(netdissect_options *, const u_char *, u_int); 6813340d773SGleb Smirnoff extern void m3ua_print(netdissect_options *, const u_char *, const u_int); 682ee67461eSJoseph Mingrone extern int macsec_print(netdissect_options *, const u_char **, 683ee67461eSJoseph Mingrone u_int *, u_int *, u_int *, const struct lladdr_info *, 684ee67461eSJoseph Mingrone const struct lladdr_info *); 685ee67461eSJoseph Mingrone extern u_int mfr_print(netdissect_options *, const u_char *, u_int); 6863340d773SGleb Smirnoff extern void mobile_print(netdissect_options *, const u_char *, u_int); 6873340d773SGleb Smirnoff extern int mobility_print(netdissect_options *, const u_char *, const u_char *); 6883340d773SGleb Smirnoff extern void mpcp_print(netdissect_options *, const u_char *, u_int); 6893340d773SGleb Smirnoff extern void mpls_print(netdissect_options *, const u_char *, u_int); 6903340d773SGleb Smirnoff extern int mptcp_print(netdissect_options *, const u_char *, u_int, u_char); 6913340d773SGleb Smirnoff extern void msdp_print(netdissect_options *, const u_char *, u_int); 6923340d773SGleb Smirnoff extern void msnlb_print(netdissect_options *, const u_char *); 693ee67461eSJoseph Mingrone extern void nbt_tcp_print(netdissect_options *, const u_char *, u_int); 694ee67461eSJoseph Mingrone extern void nbt_udp137_print(netdissect_options *, const u_char *, u_int); 695ee67461eSJoseph Mingrone extern void nbt_udp138_print(netdissect_options *, const u_char *, u_int); 696ee67461eSJoseph Mingrone extern void netbeui_print(netdissect_options *, u_short, const u_char *, u_int); 6973340d773SGleb Smirnoff extern void nfsreply_print(netdissect_options *, const u_char *, u_int, const u_char *); 698ee67461eSJoseph Mingrone extern void nfsreply_noaddr_print(netdissect_options *, const u_char *, u_int, const u_char *); 699ee67461eSJoseph Mingrone extern void nfsreq_noaddr_print(netdissect_options *, const u_char *, u_int, const u_char *); 700ee67461eSJoseph Mingrone extern const u_char *fqdn_print(netdissect_options *, const u_char *, const u_char *); 701ee67461eSJoseph Mingrone extern void domain_print(netdissect_options *, const u_char *, u_int, int, int); 702ee67461eSJoseph Mingrone extern void nsh_print(netdissect_options *, const u_char *, u_int); 7033340d773SGleb Smirnoff extern void ntp_print(netdissect_options *, const u_char *, u_int); 7043340d773SGleb Smirnoff extern void oam_print(netdissect_options *, const u_char *, u_int, u_int); 7053340d773SGleb Smirnoff extern void olsr_print(netdissect_options *, const u_char *, u_int, int); 706ee67461eSJoseph Mingrone extern void openflow_print(netdissect_options *, const u_char *, u_int); 7071de50e9fSSam Leffler extern void ospf6_print(netdissect_options *, const u_char *, u_int); 7083340d773SGleb Smirnoff extern void ospf_print(netdissect_options *, const u_char *, u_int, const u_char *); 709ee67461eSJoseph Mingrone extern int ospf_grace_lsa_print(netdissect_options *, const u_char *, u_int); 710ee67461eSJoseph Mingrone extern int ospf_te_lsa_print(netdissect_options *, const u_char *, u_int); 7113340d773SGleb Smirnoff extern void otv_print(netdissect_options *, const u_char *, u_int); 7123340d773SGleb Smirnoff extern void pfsync_ip_print(netdissect_options *, const u_char *, u_int); 7131ad8d2eeSJoseph Mingrone extern void pfsync_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *); 7143340d773SGleb Smirnoff extern void pgm_print(netdissect_options *, const u_char *, u_int, const u_char *); 7153340d773SGleb Smirnoff extern void pim_print(netdissect_options *, const u_char *, u_int, const u_char *); 7163340d773SGleb Smirnoff extern void pimv1_print(netdissect_options *, const u_char *, u_int); 717ee67461eSJoseph Mingrone extern u_int ppp_print(netdissect_options *, const u_char *, u_int); 7183340d773SGleb Smirnoff extern u_int pppoe_print(netdissect_options *, const u_char *, u_int); 7193340d773SGleb Smirnoff extern void pptp_print(netdissect_options *, const u_char *); 720ee67461eSJoseph Mingrone extern void ptp_print(netdissect_options *, const u_char *, u_int); 721ee67461eSJoseph Mingrone extern int print_unknown_data(netdissect_options *, const u_char *, const char *, u_int); 722ee67461eSJoseph Mingrone extern const char *q922_string(netdissect_options *, const u_char *, u_int); 7233340d773SGleb Smirnoff extern void q933_print(netdissect_options *, const u_char *, u_int); 7243340d773SGleb Smirnoff extern void radius_print(netdissect_options *, const u_char *, u_int); 7253340d773SGleb Smirnoff extern void resp_print(netdissect_options *, const u_char *, u_int); 7263340d773SGleb Smirnoff extern void rip_print(netdissect_options *, const u_char *, u_int); 7273340d773SGleb Smirnoff extern void ripng_print(netdissect_options *, const u_char *, unsigned int); 7283340d773SGleb Smirnoff extern void rpki_rtr_print(netdissect_options *, const u_char *, u_int); 7293340d773SGleb Smirnoff extern void rsvp_print(netdissect_options *, const u_char *, u_int); 7303340d773SGleb Smirnoff extern int rt6_print(netdissect_options *, const u_char *, const u_char *); 731ee67461eSJoseph Mingrone extern void rtl_print(netdissect_options *, const u_char *, u_int, const struct lladdr_info *, const struct lladdr_info *); 7323340d773SGleb Smirnoff extern void rtsp_print(netdissect_options *, const u_char *, u_int); 733ee67461eSJoseph Mingrone extern void rx_print(netdissect_options *, const u_char *, u_int, uint16_t, uint16_t, const u_char *); 7343340d773SGleb Smirnoff extern void sctp_print(netdissect_options *, const u_char *, const u_char *, u_int); 7353340d773SGleb Smirnoff extern void sflow_print(netdissect_options *, const u_char *, u_int); 736ee67461eSJoseph Mingrone extern void ssh_print(netdissect_options *, const u_char *, u_int); 7373340d773SGleb Smirnoff extern void sip_print(netdissect_options *, const u_char *, u_int); 7383340d773SGleb Smirnoff extern void slow_print(netdissect_options *, const u_char *, u_int); 739ee67461eSJoseph Mingrone extern void smb_tcp_print(netdissect_options *, const u_char *, u_int); 7403340d773SGleb Smirnoff extern void smtp_print(netdissect_options *, const u_char *, u_int); 7413340d773SGleb Smirnoff extern int snap_print(netdissect_options *, const u_char *, u_int, u_int, const struct lladdr_info *, const struct lladdr_info *, u_int); 7423340d773SGleb Smirnoff extern void snmp_print(netdissect_options *, const u_char *, u_int); 7433340d773SGleb Smirnoff extern void stp_print(netdissect_options *, const u_char *, u_int); 744ee67461eSJoseph Mingrone extern void sunrpc_print(netdissect_options *, const u_char *, u_int, const u_char *); 7453340d773SGleb Smirnoff extern void syslog_print(netdissect_options *, const u_char *, u_int); 7463340d773SGleb Smirnoff extern void tcp_print(netdissect_options *, const u_char *, u_int, const u_char *, int); 7473340d773SGleb Smirnoff extern void telnet_print(netdissect_options *, const u_char *, u_int); 7483340d773SGleb Smirnoff extern void tftp_print(netdissect_options *, const u_char *, u_int); 7493340d773SGleb Smirnoff extern void timed_print(netdissect_options *, const u_char *); 7503340d773SGleb Smirnoff extern void tipc_print(netdissect_options *, const u_char *, u_int, u_int); 7513340d773SGleb Smirnoff extern u_int token_print(netdissect_options *, const u_char *, u_int, u_int); 7523340d773SGleb Smirnoff extern void udld_print(netdissect_options *, const u_char *, u_int); 753ee67461eSJoseph Mingrone extern void udp_print(netdissect_options *, const u_char *, u_int, const u_char *, int, u_int); 754ee67461eSJoseph Mingrone extern int vjc_print(netdissect_options *, const u_char *, u_short); 755ee67461eSJoseph Mingrone extern void vqp_print(netdissect_options *, const u_char *, u_int); 756ee67461eSJoseph Mingrone extern void vrrp_print(netdissect_options *, const u_char *, u_int, const u_char *, int, int); 757ee67461eSJoseph Mingrone extern void vtp_print(netdissect_options *, const u_char *, const u_int); 758ee67461eSJoseph Mingrone extern void vxlan_gpe_print(netdissect_options *, const u_char *, u_int); 7593340d773SGleb Smirnoff extern void vxlan_print(netdissect_options *, const u_char *, u_int); 760ee67461eSJoseph Mingrone extern void wb_print(netdissect_options *, const u_char *, u_int); 761ee67461eSJoseph Mingrone extern void whois_print(netdissect_options *, const u_char *, u_int); 762ee67461eSJoseph Mingrone extern void zep_print(netdissect_options *, const u_char *, u_int); 763ee67461eSJoseph Mingrone extern void zephyr_print(netdissect_options *, const u_char *, u_int); 7643340d773SGleb Smirnoff extern void zmtp1_print(netdissect_options *, const u_char *, u_int); 765ee67461eSJoseph Mingrone extern void zmtp1_datagram_print(netdissect_options *, const u_char *, const u_int); 766ee67461eSJoseph Mingrone extern void someip_print(netdissect_options *, const u_char *, const u_int); 7671de50e9fSSam Leffler 7683340d773SGleb Smirnoff /* checksum routines */ 7693340d773SGleb Smirnoff extern uint16_t verify_crc10_cksum(uint16_t, const u_char *, int); 7703340d773SGleb Smirnoff extern uint16_t create_osi_cksum(const uint8_t *, int, int); 7713340d773SGleb Smirnoff 772cac3dcd5SXin LI struct cksum_vec { 7733c602fabSXin LI const uint8_t *ptr; 774cac3dcd5SXin LI int len; 775cac3dcd5SXin LI }; 7763c602fabSXin LI extern uint16_t in_cksum(const struct cksum_vec *, int); 7773c602fabSXin LI extern uint16_t in_cksum_shouldbe(uint16_t, uint16_t); 7781de50e9fSSam Leffler 779ee67461eSJoseph Mingrone /* IP protocol demuxing routines */ 780ee67461eSJoseph Mingrone extern void ip_demux_print(netdissect_options *, const u_char *, u_int, u_int, int, u_int, uint8_t, const u_char *); 781ee67461eSJoseph Mingrone 782ee67461eSJoseph Mingrone extern uint16_t nextproto4_cksum(netdissect_options *, const struct ip *, const uint8_t *, u_int, u_int, uint8_t); 7833340d773SGleb Smirnoff 7843340d773SGleb Smirnoff /* in print-ip6.c */ 785ee67461eSJoseph Mingrone extern uint16_t nextproto6_cksum(netdissect_options *, const struct ip6_hdr *, const uint8_t *, u_int, u_int, uint8_t); 7863340d773SGleb Smirnoff 7873340d773SGleb Smirnoff /* Utilities */ 788ee67461eSJoseph Mingrone extern void nd_print_trunc(netdissect_options *); 789ee67461eSJoseph Mingrone extern void nd_print_protocol(netdissect_options *); 790ee67461eSJoseph Mingrone extern void nd_print_protocol_caps(netdissect_options *); 791ee67461eSJoseph Mingrone extern void nd_print_invalid(netdissect_options *); 792ee67461eSJoseph Mingrone 7933340d773SGleb Smirnoff extern int mask2plen(uint32_t); 7943340d773SGleb Smirnoff extern int mask62plen(const u_char *); 7953340d773SGleb Smirnoff 7963340d773SGleb Smirnoff extern const char *dnnum_string(netdissect_options *, u_short); 7973340d773SGleb Smirnoff 798ee67461eSJoseph Mingrone extern int decode_prefix4(netdissect_options *, const u_char *, u_int, char *, size_t); 799ee67461eSJoseph Mingrone extern int decode_prefix6(netdissect_options *, const u_char *, u_int, char *, size_t); 8003340d773SGleb Smirnoff 801ee67461eSJoseph Mingrone extern void esp_decodesecret_print(netdissect_options *); 802ee67461eSJoseph Mingrone extern int esp_decrypt_buffer_by_ikev2_print(netdissect_options *, int, 803ee67461eSJoseph Mingrone const u_char spii[8], 804ee67461eSJoseph Mingrone const u_char spir[8], 8053340d773SGleb Smirnoff const u_char *, const u_char *); 8063c602fabSXin LI 8071de50e9fSSam Leffler #endif /* netdissect_h */ 808