1 /* $NetBSD: interface.h,v 1.6 2015/03/31 21:59:35 christos Exp $ */ 2 3 /* 4 * Copyright (c) 1988-2002 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that: (1) source code distributions 9 * retain the above copyright notice and this paragraph in its entirety, (2) 10 * distributions including binary code include the above copyright notice and 11 * this paragraph in its entirety in the documentation or other materials 12 * provided with the distribution, and (3) all advertising materials mentioning 13 * features or use of this software display the following acknowledgement: 14 * ``This product includes software developed by the University of California, 15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 16 * the University nor the names of its contributors may be used to endorse 17 * or promote products derived from this software without specific prior 18 * written permission. 19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 22 */ 23 24 #ifndef tcpdump_interface_h 25 #define tcpdump_interface_h 26 27 #ifdef HAVE_OS_PROTO_H 28 #include "os-proto.h" 29 #endif 30 31 /* snprintf et al */ 32 33 #include <stdarg.h> 34 35 #if HAVE_STDINT_H 36 #include <stdint.h> 37 #endif 38 39 #if !defined(HAVE_SNPRINTF) 40 int snprintf(char *, size_t, const char *, ...) 41 #ifdef __ATTRIBUTE___FORMAT_OK 42 __attribute__((format(printf, 3, 4))) 43 #endif /* __ATTRIBUTE___FORMAT_OK */ 44 ; 45 #endif /* !defined(HAVE_SNPRINTF) */ 46 47 #if !defined(HAVE_VSNPRINTF) 48 int vsnprintf(char *, size_t, const char *, va_list) 49 #ifdef __ATTRIBUTE___FORMAT_OK 50 __attribute__((format(printf, 3, 0))) 51 #endif /* __ATTRIBUTE___FORMAT_OK */ 52 ; 53 #endif /* !defined(HAVE_VSNPRINTF) */ 54 55 #ifndef HAVE_STRLCAT 56 extern size_t strlcat(char *, const char *, size_t); 57 #endif 58 #ifndef HAVE_STRLCPY 59 extern size_t strlcpy(char *, const char *, size_t); 60 #endif 61 62 #ifndef HAVE_STRDUP 63 extern char *strdup(const char *); 64 #endif 65 66 #ifndef HAVE_STRSEP 67 extern char *strsep(char **, const char *); 68 #endif 69 70 #define PT_VAT 1 /* Visual Audio Tool */ 71 #define PT_WB 2 /* distributed White Board */ 72 #define PT_RPC 3 /* Remote Procedure Call */ 73 #define PT_RTP 4 /* Real-Time Applications protocol */ 74 #define PT_RTCP 5 /* Real-Time Applications control protocol */ 75 #define PT_SNMP 6 /* Simple Network Management Protocol */ 76 #define PT_CNFP 7 /* Cisco NetFlow protocol */ 77 #define PT_TFTP 8 /* trivial file transfer protocol */ 78 #define PT_AODV 9 /* Ad-hoc On-demand Distance Vector Protocol */ 79 #define PT_CARP 10 /* Common Address Redundancy Protocol */ 80 #define PT_RADIUS 11 /* RADIUS authentication Protocol */ 81 #define PT_ZMTP1 12 /* ZeroMQ Message Transport Protocol 1.0 */ 82 #define PT_VXLAN 13 /* Virtual eXtensible Local Area Network */ 83 #define PT_PGM 14 /* [UDP-encapsulated] Pragmatic General Multicast */ 84 #define PT_PGM_ZMTP1 15 /* ZMTP/1.0 inside PGM (native or UDP-encapsulated) */ 85 #define PT_LMP 16 /* Link Management Protocol */ 86 87 #define ESRC(ep) ((ep)->ether_shost) 88 #define EDST(ep) ((ep)->ether_dhost) 89 90 #ifndef NTOHL 91 #define NTOHL(x) (x) = ntohl(x) 92 #define NTOHS(x) (x) = ntohs(x) 93 #define HTONL(x) (x) = htonl(x) 94 #define HTONS(x) (x) = htons(x) 95 #endif 96 #endif 97 98 extern char *program_name; /* used to generate self-identifying messages */ 99 100 extern int32_t thiszone; /* seconds offset from gmt to local time */ 101 102 /* 103 * True if "l" bytes of "var" were captured. 104 * 105 * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large 106 * that "snapend - (l)" underflows. 107 * 108 * The check is for <= rather than < because "l" might be 0. 109 * 110 * We cast the pointers to uintptr_t to make sure that the compiler 111 * doesn't optimize away any of these tests (which it is allowed to 112 * do, as adding an integer to, or subtracting an integer from, a 113 * pointer assumes that the pointer is a pointer to an element of an 114 * array and that the result of the addition or subtraction yields a 115 * pointer to another member of the array, so that, for example, if 116 * you subtract a positive integer from a pointer, the result is 117 * guaranteed to be less than the original pointer value). See 118 * 119 * http://www.kb.cert.org/vuls/id/162289 120 */ 121 #define TTEST2(var, l) \ 122 ((uintptr_t)snapend - (l) <= (uintptr_t)snapend && \ 123 (uintptr_t)&(var) <= (uintptr_t)snapend - (l)) 124 125 /* True if "var" was captured */ 126 #define TTEST(var) TTEST2(var, sizeof(var)) 127 128 /* Bail if "l" bytes of "var" were not captured */ 129 #define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc 130 131 /* Bail if "var" was not captured */ 132 #define TCHECK(var) TCHECK2(var, sizeof(var)) 133 134 extern int mask2plen(uint32_t); 135 extern const char *tok2strary_internal(const char **, int, const char *, int); 136 #define tok2strary(a,f,i) tok2strary_internal(a, sizeof(a)/sizeof(a[0]),f,i) 137 138 extern void error(const char *, ...) 139 __attribute__((noreturn)) 140 #ifdef __ATTRIBUTE___FORMAT_OK 141 __attribute__((format (printf, 1, 2))) 142 #endif /* __ATTRIBUTE___FORMAT_OK */ 143 ; 144 extern void warning(const char *, ...) 145 #ifdef __ATTRIBUTE___FORMAT_OK 146 __attribute__((format (printf, 1, 2))) 147 #endif /* __ATTRIBUTE___FORMAT_OK */ 148 ; 149 150 extern char *read_infile(char *); 151 extern char *copy_argv(char **); 152 153 extern const char *dnname_string(u_short); 154 extern const char *dnnum_string(u_short); 155 156 /* checksum routines */ 157 extern void init_checksum(void); 158 extern uint16_t verify_crc10_cksum(uint16_t, const u_char *, int); 159 extern uint16_t create_osi_cksum(const uint8_t *, int, int); 160 161 /* The printer routines. */ 162 163 #include <pcap.h> 164 165 extern char *smb_errstr(int, int); 166 extern const char *nt_errstr(uint32_t); 167 168 #ifdef INET6 169 extern int mask62plen(const u_char *); 170 #endif /*INET6*/ 171 172 struct cksum_vec { 173 const uint8_t *ptr; 174 int len; 175 }; 176 extern uint16_t in_cksum(const struct cksum_vec *, int); 177 extern uint16_t in_cksum_shouldbe(uint16_t, uint16_t); 178 179 #ifndef HAVE_BPF_DUMP 180 struct bpf_program; 181 182 extern void bpf_dump(const struct bpf_program *, int); 183 184 #endif 185 186 #include "netdissect.h" 187 188 /* forward compatibility */ 189 190 #ifndef NETDISSECT_REWORKED 191 extern netdissect_options *gndo; 192 193 #define bflag gndo->ndo_bflag 194 #define eflag gndo->ndo_eflag 195 #define fflag gndo->ndo_fflag 196 #define jflag gndo->ndo_jflag 197 #define Kflag gndo->ndo_Kflag 198 #define nflag gndo->ndo_nflag 199 #define Nflag gndo->ndo_Nflag 200 #define Oflag gndo->ndo_Oflag 201 #define pflag gndo->ndo_pflag 202 #define qflag gndo->ndo_qflag 203 #define Rflag gndo->ndo_Rflag 204 #define sflag gndo->ndo_sflag 205 #define Sflag gndo->ndo_Sflag 206 #define tflag gndo->ndo_tflag 207 #define Uflag gndo->ndo_Uflag 208 #define uflag gndo->ndo_uflag 209 #define vflag gndo->ndo_vflag 210 #define xflag gndo->ndo_xflag 211 #define Xflag gndo->ndo_Xflag 212 #define Cflag gndo->ndo_Cflag 213 #define Gflag gndo->ndo_Gflag 214 #define Aflag gndo->ndo_Aflag 215 #define Bflag gndo->ndo_Bflag 216 #define Iflag gndo->ndo_Iflag 217 #define suppress_default_print gndo->ndo_suppress_default_print 218 #define packettype gndo->ndo_packettype 219 #define sigsecret gndo->ndo_sigsecret 220 #define Wflag gndo->ndo_Wflag 221 #define WflagChars gndo->ndo_WflagChars 222 #define Cflag_count gndo->ndo_Cflag_count 223 #define Gflag_count gndo->ndo_Gflag_count 224 #define Gflag_time gndo->ndo_Gflag_time 225 #define Hflag gndo->ndo_Hflag 226 #define snaplen gndo->ndo_snaplen 227 #define snapend gndo->ndo_snapend 228 229 extern void default_print(const u_char *, u_int); 230 231 #endif 232