diff options
Diffstat (limited to 'contrib/libpcap/pcap-int.h')
-rw-r--r-- | contrib/libpcap/pcap-int.h | 187 |
1 files changed, 61 insertions, 126 deletions
diff --git a/contrib/libpcap/pcap-int.h b/contrib/libpcap/pcap-int.h index 894e74afa853..ed0c682968ad 100644 --- a/contrib/libpcap/pcap-int.h +++ b/contrib/libpcap/pcap-int.h @@ -52,6 +52,8 @@ #include "portability.h" +#define PCAP_DEBUG {printf(" [%s:%d %s] ", __FILE__, __LINE__, __func__); fflush(stdout);} + /* * If we're compiling with Visual Studio, make sure we have at least * VS 2015 or later, so we have sufficient C99 support. @@ -81,7 +83,7 @@ extern "C" { #endif /* - * If pcap_new_api is set, we disable pcap_lookupdev(), because: + * If pcapint_new_api is set, we disable pcap_lookupdev(), because: * * it's not thread-safe, and is marked as deprecated, on all * platforms; @@ -97,15 +99,15 @@ extern "C" { * * We also disable the aforementioned hack in pcap_create(). */ -extern int pcap_new_api; +extern int pcapint_new_api; /* - * If pcap_utf_8_mode is set, on Windows we treat strings as UTF-8. + * If pcapint_utf_8_mode is set, on Windows we treat strings as UTF-8. * * On UN*Xes, we assume all strings are and should be in UTF-8, regardless * of the setting of this flag. */ -extern int pcap_utf_8_mode; +extern int pcapint_utf_8_mode; /* * Swap byte ordering of unsigned long long timestamp on a big endian @@ -370,76 +372,6 @@ struct pcap { #define BPF_SPECIAL_VLAN_HANDLING 0x00000001 /* special VLAN handling for Linux */ /* - * This is a timeval as stored in a savefile. - * It has to use the same types everywhere, independent of the actual - * `struct timeval'; `struct timeval' has 32-bit tv_sec values on some - * platforms and 64-bit tv_sec values on other platforms, and writing - * out native `struct timeval' values would mean files could only be - * read on systems with the same tv_sec size as the system on which - * the file was written. - */ - -struct pcap_timeval { - bpf_int32 tv_sec; /* seconds */ - bpf_int32 tv_usec; /* microseconds */ -}; - -/* - * This is a `pcap_pkthdr' as actually stored in a savefile. - * - * Do not change the format of this structure, in any way (this includes - * changes that only affect the length of fields in this structure), - * and do not make the time stamp anything other than seconds and - * microseconds (e.g., seconds and nanoseconds). Instead: - * - * introduce a new structure for the new format; - * - * send mail to "tcpdump-workers@lists.tcpdump.org", requesting - * a new magic number for your new capture file format, and, when - * you get the new magic number, put it in "savefile.c"; - * - * use that magic number for save files with the changed record - * header; - * - * make the code in "savefile.c" capable of reading files with - * the old record header as well as files with the new record header - * (using the magic number to determine the header format). - * - * Then supply the changes by forking the branch at - * - * https://github.com/the-tcpdump-group/libpcap/tree/master - * - * and issuing a pull request, so that future versions of libpcap and - * programs that use it (such as tcpdump) will be able to read your new - * capture file format. - */ - -struct pcap_sf_pkthdr { - struct pcap_timeval ts; /* time stamp */ - bpf_u_int32 caplen; /* length of portion present */ - bpf_u_int32 len; /* length of this packet (off wire) */ -}; - -/* - * How a `pcap_pkthdr' is actually stored in savefiles written - * by some patched versions of libpcap (e.g. the ones in Red - * Hat Linux 6.1 and 6.2). - * - * Do not change the format of this structure, in any way (this includes - * changes that only affect the length of fields in this structure). - * Instead, introduce a new structure, as per the above. - */ - -struct pcap_sf_patched_pkthdr { - struct pcap_timeval ts; /* time stamp */ - bpf_u_int32 caplen; /* length of portion present */ - bpf_u_int32 len; /* length of this packet (off wire) */ - int index; - unsigned short protocol; - unsigned char pkt_type; -}; - -/* * User data structure for the one-shot callback used for pcap_next() * and pcap_next_ex(). */ @@ -453,7 +385,7 @@ struct oneshot_userdata { #define min(a, b) ((a) > (b) ? (b) : (a)) #endif -int pcap_offline_read(pcap_t *, int, pcap_handler, u_char *); +int pcapint_offline_read(pcap_t *, int, pcap_handler, u_char *); /* * Does the packet count argument to a module's read routine say @@ -465,41 +397,41 @@ int pcap_offline_read(pcap_t *, int, pcap_handler, u_char *); * Routines that most pcap implementations can use for non-blocking mode. */ #if !defined(_WIN32) && !defined(MSDOS) -int pcap_getnonblock_fd(pcap_t *); -int pcap_setnonblock_fd(pcap_t *p, int); +int pcapint_getnonblock_fd(pcap_t *); +int pcapint_setnonblock_fd(pcap_t *p, int); #endif /* * Internal interfaces for "pcap_create()". * - * "pcap_create_interface()" is the routine to do a pcap_create on + * "pcapint_create_interface()" is the routine to do a pcap_create on * a regular network interface. There are multiple implementations * of this, one for each platform type (Linux, BPF, DLPI, etc.), * with the one used chosen by the configure script. * - * "pcap_create_common()" allocates and fills in a pcap_t, for use + * "pcapint_create_common()" allocates and fills in a pcap_t, for use * by pcap_create routines. */ -pcap_t *pcap_create_interface(const char *, char *); +pcap_t *pcapint_create_interface(const char *, char *); /* * This wrapper takes an error buffer pointer and a type to use for the - * private data, and calls pcap_create_common(), passing it the error + * private data, and calls pcapint_create_common(), passing it the error * buffer pointer, the size for the private data type, in bytes, and the * offset of the private data from the beginning of the structure, in * bytes. */ #define PCAP_CREATE_COMMON(ebuf, type) \ - pcap_create_common(ebuf, \ + pcapint_create_common(ebuf, \ sizeof (struct { pcap_t __common; type __private; }), \ offsetof (struct { pcap_t __common; type __private; }, __private)) -pcap_t *pcap_create_common(char *, size_t, size_t); -int pcap_do_addexit(pcap_t *); -void pcap_add_to_pcaps_to_close(pcap_t *); -void pcap_remove_from_pcaps_to_close(pcap_t *); -void pcap_cleanup_live_common(pcap_t *); -int pcap_check_activated(pcap_t *); -void pcap_breakloop_common(pcap_t *); +pcap_t *pcapint_create_common(char *, size_t, size_t); +int pcapint_do_addexit(pcap_t *); +void pcapint_add_to_pcaps_to_close(pcap_t *); +void pcapint_remove_from_pcaps_to_close(pcap_t *); +void pcapint_cleanup_live_common(pcap_t *); +int pcapint_check_activated(pcap_t *); +void pcapint_breakloop_common(pcap_t *); /* * Internal interfaces for "pcap_findalldevs()". @@ -509,39 +441,42 @@ void pcap_breakloop_common(pcap_t *); * A get_if_flags_func is a platform-dependent function called to get * additional interface flags. * - * "pcap_platform_finddevs()" is the platform-dependent routine to + * "pcapint_platform_finddevs()" is the platform-dependent routine to * find local network interfaces. * - * "pcap_findalldevs_interfaces()" is a helper to find those interfaces + * "pcapint_findalldevs_interfaces()" is a helper to find those interfaces * using the "standard" mechanisms (SIOCGIFCONF, "getifaddrs()", etc.). * - * "add_dev()" adds an entry to a pcap_if_list_t. + * "pcapint_add_dev()" adds an entry to a pcap_if_list_t. + * + * "pcap_add_any_dev()" adds an entry for the "any" device to a pcap_if_list_t. * - * "find_dev()" tries to find a device, by name, in a pcap_if_list_t. + * "pcapint_find_dev()" tries to find a device, by name, in a pcap_if_list_t. * - * "find_or_add_dev()" checks whether a device is already in a pcap_if_list_t - * and, if not, adds an entry for it. + * "pcapint_find_or_add_dev()" checks whether a device is already in a + * pcap_if_list_t and, if not, adds an entry for it. */ struct pcap_if_list; typedef struct pcap_if_list pcap_if_list_t; typedef int (*get_if_flags_func)(const char *, bpf_u_int32 *, char *); -int pcap_platform_finddevs(pcap_if_list_t *, char *); +int pcapint_platform_finddevs(pcap_if_list_t *, char *); #if !defined(_WIN32) && !defined(MSDOS) -int pcap_findalldevs_interfaces(pcap_if_list_t *, char *, +int pcapint_findalldevs_interfaces(pcap_if_list_t *, char *, int (*)(const char *), get_if_flags_func); #endif -pcap_if_t *find_or_add_dev(pcap_if_list_t *, const char *, bpf_u_int32, +pcap_if_t *pcapint_find_or_add_dev(pcap_if_list_t *, const char *, bpf_u_int32, get_if_flags_func, const char *, char *); -pcap_if_t *find_dev(pcap_if_list_t *, const char *); -pcap_if_t *add_dev(pcap_if_list_t *, const char *, bpf_u_int32, const char *, - char *); -int add_addr_to_dev(pcap_if_t *, struct sockaddr *, size_t, +pcap_if_t *pcapint_find_dev(pcap_if_list_t *, const char *); +pcap_if_t *pcapint_add_dev(pcap_if_list_t *, const char *, bpf_u_int32, + const char *, char *); +pcap_if_t *pcap_add_any_dev(pcap_if_list_t *, char *); +int pcapint_add_addr_to_dev(pcap_if_t *, struct sockaddr *, size_t, struct sockaddr *, size_t, struct sockaddr *, size_t, struct sockaddr *dstaddr, size_t, char *errbuf); #ifndef _WIN32 -pcap_if_t *find_or_add_if(pcap_if_list_t *, const char *, bpf_u_int32, +pcap_if_t *pcapint_find_or_add_if(pcap_if_list_t *, const char *, uint64_t, get_if_flags_func, char *); -int add_addr_to_if(pcap_if_list_t *, const char *, bpf_u_int32, +int pcapint_add_addr_to_if(pcap_if_list_t *, const char *, uint64_t, get_if_flags_func, struct sockaddr *, size_t, struct sockaddr *, size_t, struct sockaddr *, size_t, struct sockaddr *, size_t, char *); @@ -551,43 +486,43 @@ int add_addr_to_if(pcap_if_list_t *, const char *, bpf_u_int32, * Internal interfaces for "pcap_open_offline()" and other savefile * I/O routines. * - * "pcap_open_offline_common()" allocates and fills in a pcap_t, for use + * "pcapint_open_offline_common()" allocates and fills in a pcap_t, for use * by pcap_open_offline routines. * - * "pcap_adjust_snapshot()" adjusts the snapshot to be non-zero and + * "pcapint_adjust_snapshot()" adjusts the snapshot to be non-zero and * fit within an int. * - * "sf_cleanup()" closes the file handle associated with a pcap_t, if + * "pcapint_sf_cleanup()" closes the file handle associated with a pcap_t, if * appropriate, and frees all data common to all modules for handling * savefile types. * - * "charset_fopen()", in UTF-8 mode on Windows, does an fopen() that + * "pcapint_charset_fopen()", in UTF-8 mode on Windows, does an fopen() that * treats the pathname as being in UTF-8, rather than the local * code page, on Windows. */ /* * This wrapper takes an error buffer pointer and a type to use for the - * private data, and calls pcap_create_common(), passing it the error + * private data, and calls pcapint_create_common(), passing it the error * buffer pointer, the size for the private data type, in bytes, and the * offset of the private data from the beginning of the structure, in * bytes. */ #define PCAP_OPEN_OFFLINE_COMMON(ebuf, type) \ - pcap_open_offline_common(ebuf, \ + pcapint_open_offline_common(ebuf, \ sizeof (struct { pcap_t __common; type __private; }), \ offsetof (struct { pcap_t __common; type __private; }, __private)) -pcap_t *pcap_open_offline_common(char *ebuf, size_t total_size, +pcap_t *pcapint_open_offline_common(char *ebuf, size_t total_size, size_t private_data); -bpf_u_int32 pcap_adjust_snapshot(bpf_u_int32 linktype, bpf_u_int32 snaplen); -void sf_cleanup(pcap_t *p); +bpf_u_int32 pcapint_adjust_snapshot(bpf_u_int32 linktype, bpf_u_int32 snaplen); +void pcapint_sf_cleanup(pcap_t *p); #ifdef _WIN32 -FILE *charset_fopen(const char *path, const char *mode); +FILE *pcapint_charset_fopen(const char *path, const char *mode); #else /* * On other OSes, just use Boring Old fopen(). */ -#define charset_fopen(path, mode) fopen((path), (mode)) +#define pcapint_charset_fopen(path, mode) fopen((path), (mode)) #endif /* @@ -597,8 +532,8 @@ FILE *charset_fopen(const char *path, const char *mode); #define pcap_code_handle_t HMODULE #define pcap_funcptr_t FARPROC -pcap_code_handle_t pcap_load_code(const char *); -pcap_funcptr_t pcap_find_function(pcap_code_handle_t, const char *); +pcap_code_handle_t pcapint_load_code(const char *); +pcap_funcptr_t pcapint_find_function(pcap_code_handle_t, const char *); #endif /* @@ -619,40 +554,40 @@ struct pcap_bpf_aux_data { * Filtering routine that takes the auxiliary data as an additional * argument. */ -u_int pcap_filter_with_aux_data(const struct bpf_insn *, +u_int pcapint_filter_with_aux_data(const struct bpf_insn *, const u_char *, u_int, u_int, const struct pcap_bpf_aux_data *); /* * Filtering routine that doesn't. */ -u_int pcap_filter(const struct bpf_insn *, const u_char *, u_int, u_int); +u_int pcapint_filter(const struct bpf_insn *, const u_char *, u_int, u_int); /* * Routine to validate a BPF program. */ -int pcap_validate_filter(const struct bpf_insn *, int); +int pcapint_validate_filter(const struct bpf_insn *, int); /* * Internal interfaces for both "pcap_create()" and routines that * open savefiles. * - * "pcap_oneshot()" is the standard one-shot callback for "pcap_next()" + * "pcapint_oneshot()" is the standard one-shot callback for "pcap_next()" * and "pcap_next_ex()". */ -void pcap_oneshot(u_char *, const struct pcap_pkthdr *, const u_char *); +void pcapint_oneshot(u_char *, const struct pcap_pkthdr *, const u_char *); -int install_bpf_program(pcap_t *, struct bpf_program *); +int pcapint_install_bpf_program(pcap_t *, struct bpf_program *); -int pcap_strcasecmp(const char *, const char *); +int pcapint_strcasecmp(const char *, const char *); /* * Internal interfaces for pcap_createsrcstr and pcap_parsesrcstr with * the additional bit of information regarding SSL support (rpcap:// vs. * rpcaps://). */ -int pcap_createsrcstr_ex(char *, int, const char *, const char *, +int pcapint_createsrcstr_ex(char *, int, const char *, const char *, const char *, unsigned char, char *); -int pcap_parsesrcstr_ex(const char *, int *, char *, char *, +int pcapint_parsesrcstr_ex(const char *, int *, char *, char *, char *, unsigned char *, char *); #ifdef YYDEBUG |