Home | History | Annotate | Line # | Download | only in dist
      1 /*	$NetBSD: pcap-int.h,v 1.10 2026/03/18 23:43:20 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994, 1995, 1996
      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 the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the Computer Systems
     18  *	Engineering Group at Lawrence Berkeley Laboratory.
     19  * 4. Neither the name of the University nor of the Laboratory may be used
     20  *    to endorse or promote products derived from this software without
     21  *    specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  */
     35 
     36 #ifndef pcap_int_h
     37 #define	pcap_int_h
     38 
     39 #include <stddef.h>
     40 
     41 #include <signal.h>
     42 
     43 #include <pcap/pcap.h>
     44 
     45 #ifdef MSDOS
     46   #include <fcntl.h>
     47   #include <io.h>
     48 #endif
     49 
     50 #include "varattrs.h"
     51 #include "fmtutils.h"
     52 
     53 #include <stdarg.h>
     54 
     55 #include "portability.h"
     56 
     57 #define PCAP_DEBUG {printf(" [%s:%d %s] ", __FILE__, __LINE__, __func__); fflush(stdout);}
     58 
     59 /*
     60  * If we're compiling with Visual Studio, make sure we have at least
     61  * VS 2015 or later, so we have sufficient C99 support.
     62  *
     63  * XXX - verify that we have at least C99 support on UN*Xes?
     64  *
     65  * What about MinGW or various DOS toolchains?  We're currently assuming
     66  * sufficient C99 support there.
     67  */
     68 #if defined(_MSC_VER)
     69   /*
     70    * Compiler is MSVC.  Make sure we have VS 2015 or later.
     71    */
     72   #if _MSC_VER < 1900
     73     #error "Building libpcap requires VS 2015 or later"
     74   #endif
     75 #endif
     76 
     77 /*
     78  * Version string trailer.
     79  * Uses SIZEOF_TIME_T from config.h.
     80  * (There's no need to announce the pointer size; if it doesn't
     81  * match the pointer size in code linked with libpcap, either
     82  * build-time linking or run-time linking will fail.)
     83  */
     84 #if SIZEOF_TIME_T == 8
     85   #define PCAP_SIZEOF_TIME_T_BITS_STRING "64"
     86 #elif SIZEOF_TIME_T == 4
     87   #define PCAP_SIZEOF_TIME_T_BITS_STRING "32"
     88 #else
     89   #error Unknown time_t size
     90 #endif
     91 
     92 /*
     93  * Version string.
     94  * Uses PACKAGE_VERSION from config.h and PCAP_SIZEOF_TIME_T_BITS_STRING.
     95  */
     96 #define PCAP_VERSION_STRING \
     97 	"libpcap version " PACKAGE_VERSION " (" PCAP_SIZEOF_TIME_T_BITS_STRING "-bit time_t)"
     98 #define PCAP_VERSION_STRING_WITH_ADDITIONAL_INFO(additional_info) \
     99 	"libpcap version " PACKAGE_VERSION " (" PCAP_SIZEOF_TIME_T_BITS_STRING "-bit time_t, " additional_info ")"
    100 
    101 #ifdef __cplusplus
    102 extern "C" {
    103 #endif
    104 
    105 /*
    106  * If pcapint_new_api is set, we disable pcap_lookupdev(), because:
    107  *
    108  *    it's not thread-safe, and is marked as deprecated, on all
    109  *    platforms;
    110  *
    111  *    on Windows, it may return UTF-16LE strings, which the program
    112  *    might then pass to pcap_create() (or to pcap_open_live(), which
    113  *    then passes them to pcap_create()), requiring pcap_create() to
    114  *    check for UTF-16LE strings using a hack, and that hack 1)
    115  *    *cannot* be 100% reliable and 2) runs the risk of going past the
    116  *    end of the string.
    117  *
    118  * We keep it around in legacy mode for compatibility.
    119  *
    120  * We also disable the aforementioned hack in pcap_create().
    121  */
    122 extern int pcapint_new_api;
    123 
    124 /*
    125  * If pcapint_utf_8_mode is set, on Windows we treat strings as UTF-8.
    126  *
    127  * On UN*Xes, we assume all strings are and should be in UTF-8, regardless
    128  * of the setting of this flag.
    129  */
    130 extern int pcapint_utf_8_mode;
    131 
    132 /*
    133  * Swap byte ordering of unsigned long long timestamp on a big endian
    134  * machine.
    135  */
    136 #define SWAPLL(ull)  ((ull & 0xff00000000000000ULL) >> 56) | \
    137                       ((ull & 0x00ff000000000000ULL) >> 40) | \
    138                       ((ull & 0x0000ff0000000000ULL) >> 24) | \
    139                       ((ull & 0x000000ff00000000ULL) >> 8)  | \
    140                       ((ull & 0x00000000ff000000ULL) << 8)  | \
    141                       ((ull & 0x0000000000ff0000ULL) << 24) | \
    142                       ((ull & 0x000000000000ff00ULL) << 40) | \
    143                       ((ull & 0x00000000000000ffULL) << 56)
    144 
    145 /*
    146  * Maximum snapshot length.
    147  *
    148  * Somewhat arbitrary, but chosen to be:
    149  *
    150  *    1) big enough for maximum-size Linux loopback packets (65549)
    151  *       and some USB packets captured with USBPcap:
    152  *
    153  *           https://desowin.org/usbpcap/
    154  *
    155  *       (> 131072, < 262144)
    156  *
    157  * and
    158  *
    159  *    2) small enough not to cause attempts to allocate huge amounts of
    160  *       memory; some applications might use the snapshot length in a
    161  *       savefile header to control the size of the buffer they allocate,
    162  *       so a size of, say, 2^31-1 might not work well.  (libpcap uses it
    163  *       as a hint, but doesn't start out allocating a buffer bigger than
    164  *       2 KiB, and grows the buffer as necessary, but not beyond the
    165  *       per-linktype maximum snapshot length.  Other code might naively
    166  *       use it; we want to avoid writing a too-large snapshot length,
    167  *       in order not to cause that code problems.)
    168  *
    169  * We don't enforce this in pcap_set_snaplen(), but we use it internally.
    170  */
    171 #define MAXIMUM_SNAPLEN		262144
    172 
    173 /*
    174  * Locale-independent macros for testing character types.
    175  * These can be passed any integral value, without worrying about, for
    176  * example, sign-extending char values, unlike the C macros.
    177  */
    178 #define PCAP_ISDIGIT(c) \
    179 	((c) >= '0' && (c) <= '9')
    180 #define PCAP_ISXDIGIT(c) \
    181 	(((c) >= '0' && (c) <= '9') || \
    182 	 ((c) >= 'A' && (c) <= 'F') || \
    183 	 ((c) >= 'a' && (c) <= 'f'))
    184 
    185 struct pcap_opt {
    186 	char	*device;
    187 	int	timeout;	/* timeout for buffering */
    188 	u_int	buffer_size;
    189 	int	promisc;
    190 	int	rfmon;		/* monitor mode */
    191 	int	immediate;	/* immediate mode - deliver packets as soon as they arrive */
    192 	int	nonblock;	/* non-blocking mode - don't wait for packets to be delivered, return "no packets available" */
    193 	int	tstamp_type;
    194 	int	tstamp_precision;
    195 
    196 	/*
    197 	 * Platform-dependent options.
    198 	 */
    199 #ifdef __linux__
    200 	int	protocol;	/* protocol to use when creating PF_PACKET socket */
    201 #endif
    202 #ifdef _WIN32
    203 	int	nocapture_local;/* disable NPF loopback */
    204 #endif
    205 };
    206 
    207 typedef int	(*activate_op_t)(pcap_t *);
    208 typedef int	(*can_set_rfmon_op_t)(pcap_t *);
    209 typedef int	(*read_op_t)(pcap_t *, int cnt, pcap_handler, u_char *);
    210 typedef int	(*next_packet_op_t)(pcap_t *, struct pcap_pkthdr *, u_char **);
    211 typedef int	(*inject_op_t)(pcap_t *, const void *, size_t);
    212 typedef void	(*save_current_filter_op_t)(pcap_t *, const char *);
    213 typedef int	(*setfilter_op_t)(pcap_t *, struct bpf_program *);
    214 typedef int	(*setdirection_op_t)(pcap_t *, pcap_direction_t);
    215 typedef int	(*set_datalink_op_t)(pcap_t *, int);
    216 typedef int	(*getnonblock_op_t)(pcap_t *);
    217 typedef int	(*setnonblock_op_t)(pcap_t *, int);
    218 typedef int	(*stats_op_t)(pcap_t *, struct pcap_stat *);
    219 typedef void	(*breakloop_op_t)(pcap_t *);
    220 #ifdef _WIN32
    221 typedef struct pcap_stat *(*stats_ex_op_t)(pcap_t *, int *);
    222 typedef int	(*setbuff_op_t)(pcap_t *, int);
    223 typedef int	(*setmode_op_t)(pcap_t *, int);
    224 typedef int	(*setmintocopy_op_t)(pcap_t *, int);
    225 typedef HANDLE	(*getevent_op_t)(pcap_t *);
    226 typedef int	(*oid_get_request_op_t)(pcap_t *, bpf_u_int32, void *, size_t *);
    227 typedef int	(*oid_set_request_op_t)(pcap_t *, bpf_u_int32, const void *, size_t *);
    228 typedef u_int	(*sendqueue_transmit_op_t)(pcap_t *, pcap_send_queue *, int);
    229 typedef int	(*setuserbuffer_op_t)(pcap_t *, int);
    230 typedef int	(*live_dump_op_t)(pcap_t *, char *, int, int);
    231 typedef int	(*live_dump_ended_op_t)(pcap_t *, int);
    232 typedef PAirpcapHandle	(*get_airpcap_handle_op_t)(pcap_t *);
    233 #endif
    234 typedef void	(*cleanup_op_t)(pcap_t *);
    235 
    236 /*
    237  * We put all the stuff used in the read code path at the beginning,
    238  * to try to keep it together in the same cache line or lines.
    239  */
    240 struct pcap {
    241 	/*
    242 	 * Method to call to read packets on a live capture.
    243 	 */
    244 	read_op_t read_op;
    245 
    246 	/*
    247 	 * Method to call to read the next packet from a savefile.
    248 	 */
    249 	next_packet_op_t next_packet_op;
    250 
    251 #ifdef _WIN32
    252 	HANDLE handle;
    253 #else
    254 	int fd;
    255 #endif /* _WIN32 */
    256 
    257 	/*
    258 	 * Read buffer.
    259 	 */
    260 	u_int bufsize;
    261 	void *buffer;
    262 	u_char *bp;
    263 	int cc;
    264 
    265 	sig_atomic_t break_loop; /* flag set to force break from packet-reading loop */
    266 
    267 	void *priv;		/* private data for methods */
    268 
    269 // #ifdef ENABLE_REMOTE
    270 	struct pcap_samp rmt_samp;	/* parameters related to the sampling process. */
    271 // #endif
    272 
    273 	int swapped;
    274 	FILE *rfile;		/* null if live capture, non-null if savefile */
    275 	u_int fddipad;
    276 	struct pcap *next;	/* list of open pcaps that need stuff cleared on close */
    277 
    278 	/*
    279 	 * File version number; meaningful only for a savefile, but we
    280 	 * keep it here so that apps that (mistakenly) ask for the
    281 	 * version numbers will get the same zero values that they
    282 	 * always did.
    283 	 */
    284 	int version_major;
    285 	int version_minor;
    286 
    287 	int snapshot;
    288 	int linktype;		/* Network linktype */
    289 	int linktype_ext;	/* Extended information stored in the linktype field of a file */
    290 	int offset;		/* offset for proper alignment */
    291 	int activated;		/* true if the capture is really started */
    292 	int oldstyle;		/* if we're opening with pcap_open_live() */
    293 
    294 	struct pcap_opt opt;
    295 
    296 	/*
    297 	 * Place holder for pcap_next().
    298 	 */
    299 	u_char *pkt;
    300 
    301 #ifdef _WIN32
    302 	struct pcap_stat stat;	/* used for pcap_stats_ex() */
    303 #endif
    304 
    305 	/* We're accepting only packets in this direction/these directions. */
    306 	pcap_direction_t direction;
    307 
    308 	/*
    309 	 * Flags to affect BPF code generation.
    310 	 */
    311 	int bpf_codegen_flags;
    312 
    313 #if !defined(_WIN32) && !defined(MSDOS)
    314 	int selectable_fd;	/* FD on which select()/poll()/epoll_wait()/kevent()/etc. can be done */
    315 
    316 	/*
    317 	 * In case there either is no selectable FD, or there is but
    318 	 * it doesn't necessarily work (e.g., if it doesn't get notified
    319 	 * if the packet capture timeout expires before the buffer
    320 	 * fills up), this points to a timeout that should be used
    321 	 * in select()/poll()/epoll_wait()/kevent() call.  The pcap_t should
    322 	 * be put into non-blocking mode, and, if the timeout expires on
    323 	 * the call, an attempt should be made to read packets from all
    324 	 * pcap_t's with a required timeout, and the code must be
    325 	 * prepared not to see any packets from the attempt.
    326 	 */
    327 	const struct timeval *required_select_timeout;
    328 #endif
    329 
    330 	/*
    331 	 * Placeholder for filter code if bpf not in kernel.
    332 	 */
    333 	struct bpf_program fcode;
    334 
    335 	char errbuf[PCAP_ERRBUF_SIZE + 1];
    336 #ifdef _WIN32
    337 	char acp_errbuf[PCAP_ERRBUF_SIZE + 1];	/* buffer for local code page error strings */
    338 #endif
    339 	int dlt_count;
    340 	u_int *dlt_list;
    341 	int tstamp_type_count;
    342 	u_int *tstamp_type_list;
    343 	int tstamp_precision_count;
    344 	u_int *tstamp_precision_list;
    345 
    346 	struct pcap_pkthdr pcap_header;	/* This is needed for the pcap_next_ex() to work */
    347 
    348 	/*
    349 	 * More methods.
    350 	 */
    351 	activate_op_t activate_op;
    352 	can_set_rfmon_op_t can_set_rfmon_op;
    353 	inject_op_t inject_op;
    354 	save_current_filter_op_t save_current_filter_op;
    355 	setfilter_op_t setfilter_op;
    356 	setdirection_op_t setdirection_op;
    357 	set_datalink_op_t set_datalink_op;
    358 	getnonblock_op_t getnonblock_op;
    359 	setnonblock_op_t setnonblock_op;
    360 	stats_op_t stats_op;
    361 	breakloop_op_t breakloop_op;
    362 
    363 	/*
    364 	 * Routine to use as callback for pcap_next()/pcap_next_ex().
    365 	 */
    366 	pcap_handler oneshot_callback;
    367 
    368 #ifdef _WIN32
    369 	/*
    370 	 * These are, at least currently, specific to the Win32 NPF
    371 	 * driver.
    372 	 */
    373 	stats_ex_op_t stats_ex_op;
    374 	setbuff_op_t setbuff_op;
    375 	setmode_op_t setmode_op;
    376 	setmintocopy_op_t setmintocopy_op;
    377 	getevent_op_t getevent_op;
    378 	oid_get_request_op_t oid_get_request_op;
    379 	oid_set_request_op_t oid_set_request_op;
    380 	sendqueue_transmit_op_t sendqueue_transmit_op;
    381 	setuserbuffer_op_t setuserbuffer_op;
    382 	live_dump_op_t live_dump_op;
    383 	live_dump_ended_op_t live_dump_ended_op;
    384 	get_airpcap_handle_op_t get_airpcap_handle_op;
    385 #endif
    386 	cleanup_op_t cleanup_op;
    387 };
    388 
    389 /*
    390  * BPF code generation flags.
    391  */
    392 #define BPF_SPECIAL_VLAN_HANDLING	0x00000001	/* special VLAN handling for Linux */
    393 
    394 /*
    395  * User data structure for the one-shot callback used for pcap_next()
    396  * and pcap_next_ex().
    397  */
    398 struct oneshot_userdata {
    399 	struct pcap_pkthdr *hdr;
    400 	const u_char **pkt;
    401 	pcap_t *pd;
    402 };
    403 
    404 #ifndef min
    405 #define min(a, b) ((a) > (b) ? (b) : (a))
    406 #endif
    407 
    408 int	pcapint_offline_read(pcap_t *, int, pcap_handler, u_char *);
    409 
    410 /*
    411  * Does the packet count argument to a module's read routine say
    412  * "supply packets until you run out of packets"?
    413  */
    414 #define PACKET_COUNT_IS_UNLIMITED(count)	((count) <= 0)
    415 
    416 /*
    417  * Routines that most pcap implementations can use for non-blocking mode.
    418  */
    419 #if !defined(_WIN32) && !defined(MSDOS)
    420 int	pcapint_getnonblock_fd(pcap_t *);
    421 int	pcapint_setnonblock_fd(pcap_t *p, int);
    422 #endif
    423 
    424 /*
    425  * Internal interfaces for "pcap_create()".
    426  *
    427  * "pcapint_create_interface()" is the routine to do a pcap_create on
    428  * a regular network interface.  There are multiple implementations
    429  * of this, one for each platform type (Linux, BPF, DLPI, etc.),
    430  * with the one used chosen by the configure script.
    431  *
    432  * "pcapint_create_common()" allocates and fills in a pcap_t, for use
    433  * by pcap_create routines.
    434  */
    435 pcap_t	*pcapint_create_interface(const char *, char *);
    436 /*
    437  * A format string for something-only libpcap builds, which use a stub
    438  * implementation of pcapint_create_interface().  It contains the substring
    439  * "No such device" (one of the standard descriptions of ENODEV) -- this way
    440  * tcpdump can detect a particular error condition even though pcap_create()
    441  * returns NULL for all errors.
    442  */
    443 #define PCAP_ENODEV_MESSAGE "No such device (this build of libpcap supports %s devices only)."
    444 
    445 /*
    446  * This wrapper takes an error buffer pointer and a type to use for the
    447  * private data, and calls pcapint_create_common(), passing it the error
    448  * buffer pointer, the size for the private data type, in bytes, and the
    449  * offset of the private data from the beginning of the structure, in
    450  * bytes.
    451  */
    452 #define PCAP_CREATE_COMMON(ebuf, type) \
    453 	pcapint_create_common(ebuf, \
    454 	    sizeof (struct { pcap_t __common; type __private; }), \
    455 	    offsetof (struct { pcap_t __common; type __private; }, __private))
    456 pcap_t	*pcapint_create_common(char *, size_t, size_t);
    457 int	pcapint_do_addexit(pcap_t *);
    458 void	pcapint_add_to_pcaps_to_close(pcap_t *);
    459 void	pcapint_remove_from_pcaps_to_close(pcap_t *);
    460 void	pcapint_cleanup_live_common(pcap_t *);
    461 int	pcapint_check_activated(pcap_t *);
    462 void	pcapint_breakloop_common(pcap_t *);
    463 
    464 /*
    465  * Internal interfaces for "pcap_findalldevs()".
    466  *
    467  * A pcap_if_list_t * is a reference to a list of devices.
    468  *
    469  * A get_if_flags_func is a platform-dependent function called to get
    470  * additional interface flags.
    471  *
    472  * "pcapint_platform_finddevs()" is the platform-dependent routine to
    473  * find local network interfaces.
    474  *
    475  * "pcapint_findalldevs_interfaces()" is a helper to find those interfaces
    476  * using the "standard" mechanisms (SIOCGIFCONF, "getifaddrs()", etc.).
    477  *
    478  * "pcapint_add_dev()" adds an entry to a pcap_if_list_t.
    479  *
    480  * "pcap_add_any_dev()" adds an entry for the "any" device to a pcap_if_list_t.
    481  *
    482  * "pcapint_find_dev()" tries to find a device, by name, in a pcap_if_list_t.
    483  *
    484  * "pcapint_find_or_add_dev()" checks whether a device is already in a
    485  * pcap_if_list_t and, if not, adds an entry for it.
    486  */
    487 struct pcap_if_list;
    488 typedef struct pcap_if_list pcap_if_list_t;
    489 typedef int (*get_if_flags_func)(const char *, bpf_u_int32 *, char *);
    490 int	pcapint_platform_finddevs(pcap_if_list_t *, char *);
    491 #if !defined(_WIN32) && !defined(MSDOS)
    492 int	pcapint_findalldevs_interfaces(pcap_if_list_t *, char *,
    493 	    int (*)(const char *), get_if_flags_func);
    494 #endif
    495 pcap_if_t *pcapint_find_or_add_dev(pcap_if_list_t *, const char *, bpf_u_int32,
    496 	    get_if_flags_func, const char *, char *);
    497 pcap_if_t *pcapint_find_dev(pcap_if_list_t *, const char *);
    498 pcap_if_t *pcapint_add_dev(pcap_if_list_t *, const char *, bpf_u_int32,
    499 	    const char *, char *);
    500 pcap_if_t *pcap_add_any_dev(pcap_if_list_t *, char *);
    501 int	pcapint_add_addr_to_dev(pcap_if_t *, struct sockaddr *, size_t,
    502 	    struct sockaddr *, size_t, struct sockaddr *, size_t,
    503 	    struct sockaddr *dstaddr, size_t, char *errbuf);
    504 #ifndef _WIN32
    505 pcap_if_t *pcapint_find_or_add_if(pcap_if_list_t *, const char *, uint64_t,
    506 	    get_if_flags_func, char *);
    507 int	pcapint_add_addr_to_if(pcap_if_list_t *, const char *, uint64_t,
    508 	    get_if_flags_func,
    509 	    struct sockaddr *, size_t, struct sockaddr *, size_t,
    510 	    struct sockaddr *, size_t, struct sockaddr *, size_t, char *);
    511 #endif
    512 
    513 /*
    514  * Internal interfaces for "pcap_open_offline()" and other savefile
    515  * I/O routines.
    516  *
    517  * "pcapint_open_offline_common()" allocates and fills in a pcap_t, for use
    518  * by pcap_open_offline routines.
    519  *
    520  * "pcapint_adjust_snapshot()" adjusts the snapshot to be non-zero and
    521  * fit within an int.
    522  *
    523  * "pcapint_sf_cleanup()" closes the file handle associated with a pcap_t, if
    524  * appropriate, and frees all data common to all modules for handling
    525  * savefile types.
    526  *
    527  * "pcapint_charset_fopen()", in UTF-8 mode on Windows, does an fopen() that
    528  * treats the pathname as being in UTF-8, rather than the local
    529  * code page, on Windows.
    530  */
    531 
    532 /*
    533  * This wrapper takes an error buffer pointer and a type to use for the
    534  * private data, and calls pcapint_create_common(), passing it the error
    535  * buffer pointer, the size for the private data type, in bytes, and the
    536  * offset of the private data from the beginning of the structure, in
    537  * bytes.
    538  */
    539 #define PCAP_OPEN_OFFLINE_COMMON(ebuf, type) \
    540 	pcapint_open_offline_common(ebuf, \
    541 	    sizeof (struct { pcap_t __common; type __private; }), \
    542 	    offsetof (struct { pcap_t __common; type __private; }, __private))
    543 pcap_t	*pcapint_open_offline_common(char *ebuf, size_t total_size,
    544     size_t private_data);
    545 bpf_u_int32 pcapint_adjust_snapshot(bpf_u_int32 linktype, bpf_u_int32 snaplen);
    546 void	pcapint_sf_cleanup(pcap_t *p);
    547 #ifdef _WIN32
    548 FILE	*pcapint_charset_fopen(const char *path, const char *mode);
    549 #else
    550 /*
    551  * On other OSes, just use Boring Old fopen().
    552  */
    553 #define pcapint_charset_fopen(path, mode)	fopen((path), (mode))
    554 #endif
    555 
    556 /*
    557  * Internal interfaces for loading code at run time.
    558  */
    559 #ifdef _WIN32
    560 #define pcap_code_handle_t	HMODULE
    561 
    562 pcap_code_handle_t	pcapint_load_code(const char *);
    563 void			*pcapint_find_function(pcap_code_handle_t, const char *);
    564 #endif
    565 
    566 /*
    567  * Internal interfaces for doing user-mode filtering of packets and
    568  * validating filter programs.
    569  */
    570 #ifndef __NetBSD__
    571 /*
    572  * Auxiliary data, for use when interpreting a filter intended for the
    573  * Linux kernel when the kernel rejects the filter (requiring us to
    574  * run it in userland).  It contains VLAN tag information.
    575  */
    576 struct pcap_bpf_aux_data {
    577 	u_short vlan_tag_present;
    578 	u_short vlan_tag;
    579 };
    580 #else
    581 #define pcap_bpf_aux_data bpf_aux_data
    582 #endif
    583 
    584 /*
    585  * Filtering routine that takes the auxiliary data as an additional
    586  * argument.
    587  */
    588 u_int	pcapint_filter_with_aux_data(const struct bpf_insn *,
    589     const u_char *, u_int, u_int, const struct pcap_bpf_aux_data *);
    590 
    591 /*
    592  * Filtering routine that doesn't.
    593  */
    594 u_int	pcapint_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
    595 
    596 /*
    597  * Routine to validate a BPF program.
    598  */
    599 int	pcapint_validate_filter(const struct bpf_insn *, int);
    600 
    601 /*
    602  * Internal interfaces for both "pcap_create()" and routines that
    603  * open savefiles.
    604  *
    605  * "pcapint_oneshot()" is the standard one-shot callback for "pcap_next()"
    606  * and "pcap_next_ex()".
    607  */
    608 void	pcapint_oneshot(u_char *, const struct pcap_pkthdr *, const u_char *);
    609 
    610 int	pcapint_install_bpf_program(pcap_t *, struct bpf_program *);
    611 
    612 int	pcapint_strcasecmp(const char *, const char *);
    613 
    614 /*
    615  * Internal interfaces for pcap_createsrcstr and pcap_parsesrcstr with
    616  * the additional bit of information regarding SSL support (rpcap:// vs.
    617  * rpcaps://).
    618  */
    619 int	pcapint_createsrcstr_ex(char *, int, const char *, const char *,
    620     const char *, unsigned char, char *);
    621 int	pcapint_parsesrcstr_ex(const char *, int *, char *, char *,
    622     char *, unsigned char *, char *);
    623 
    624 #ifdef YYDEBUG
    625 extern int pcap_debug;
    626 #endif
    627 
    628 #ifdef __cplusplus
    629 }
    630 #endif
    631 
    632 #endif
    633