summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-03-17 02:23:37 -0700
committerGuy Harris <gharris@sonic.net>2021-03-17 02:23:37 -0700
commit8b6b13d4cbb685db047af04c49817ed81fff7c35 (patch)
tree7ba565e6cfa2a8e0f25952bc720c389512255170
parentbb02779a37fdf815da58e8828eb4ce99a4f86580 (diff)
downloadlibpcap-8b6b13d4cbb685db047af04c49817ed81fff7c35.tar.gz
Don't wrap chunks of headers with extern "C" { ... }.
Instead, explictly flag individual functions with extern "C" by adding it to the tag we're already using for exported functions, and creating a new tag to use for non-exported functions. Rename those tags, and the tags used for exported data, to say what they do, rather than saying "this is an API" (we may export things we don't want to be treated as part of the API, but that we have to export because some programs use them).
-rw-r--r--CMakeLists.txt4
-rw-r--r--aclocal.m49
-rwxr-xr-xconfigure9
-rw-r--r--dlpisubs.h21
-rw-r--r--fmtutils.h14
-rw-r--r--nametoaddr.c4
-rw-r--r--nametoaddr.h14
-rw-r--r--optimize.c4
-rw-r--r--pcap-int.h84
-rw-r--r--pcap.c8
-rw-r--r--pcap/bpf.h16
-rw-r--r--pcap/funcattrs.h67
-rw-r--r--pcap/namedb.h30
-rw-r--r--pcap/pcap.h234
-rw-r--r--portability.h18
-rw-r--r--sockutils.h65
-rw-r--r--testprogs/filtertest.c4
17 files changed, 294 insertions, 311 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 67fefb31..3824897f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1987,8 +1987,8 @@ file(GLOB PROJECT_SOURCE_LIST_H
#
# Try to have the compiler default to hiding symbols, so that only
-# symbols explicitly exported with PCAP_API will be visible outside
-# (shared) libraries.
+# symbols explicitly exported with PCAP_EXPORTED_C_FUNC or
+# PCAP_EXPORTED_DATA will be visible outside (shared) libraries.
#
# Not necessary with MSVC, as that's the default.
#
diff --git a/aclocal.m4 b/aclocal.m4
index 786423bf..56bb418f 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -106,7 +106,8 @@ AC_DEFUN(AC_LBL_C_INIT,
#
# Try to have the compiler default to hiding symbols,
# so that only symbols explicitly exported with
- # PCAP_API will be visible outside (shared) libraries.
+ # PCAP_EXPORTED_C_FUNC or PCAP_EXPORTED_DATA will
+ # be visible outside (shared) libraries.
#
AC_LBL_CHECK_COMPILER_OPT($1, -fvisibility=hidden)
else
@@ -125,7 +126,8 @@ AC_DEFUN(AC_LBL_C_INIT,
#
# Try to have the compiler default to hiding symbols,
# so that only symbols explicitly exported with
- # PCAP_API will be visible outside (shared) libraries.
+ # PCAP_EXPORTED_C_FUNC or PCAP_EXPORTED_DATA will
+ # be visible outside (shared) libraries.
#
AC_LBL_CHECK_COMPILER_OPT($1, -fvisibility=hidden)
;;
@@ -206,7 +208,8 @@ AC_DEFUN(AC_LBL_C_INIT,
#
# Try to have the compiler default to hiding symbols,
# so that only symbols explicitly exported with
- # PCAP_API will be visible outside (shared) libraries.
+ # PCAP_EXPORTED_C_FUNC or PCAP_EXPORTED_DATA will
+ # be visible outside (shared) libraries.
#
AC_LBL_CHECK_COMPILER_OPT($1, -xldscope=hidden)
;;
diff --git a/configure b/configure
index 8692ac59..0333104d 100755
--- a/configure
+++ b/configure
@@ -3895,7 +3895,8 @@ esac
#
# Try to have the compiler default to hiding symbols,
# so that only symbols explicitly exported with
- # PCAP_API will be visible outside (shared) libraries.
+ # PCAP_EXPORTED_C_FUNC or PCAP_EXPORTED_DATA will
+ # be visible outside (shared) libraries.
#
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -fvisibility=hidden option" >&5
@@ -3995,7 +3996,8 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
#
# Try to have the compiler default to hiding symbols,
# so that only symbols explicitly exported with
- # PCAP_API will be visible outside (shared) libraries.
+ # PCAP_EXPORTED_C_FUNC or PCAP_EXPORTED_DATA will
+ # be visible outside (shared) libraries.
#
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -fvisibility=hidden option" >&5
@@ -4157,7 +4159,8 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
#
# Try to have the compiler default to hiding symbols,
# so that only symbols explicitly exported with
- # PCAP_API will be visible outside (shared) libraries.
+ # PCAP_EXPORTED_C_FUNC or PCAP_EXPORTED_DATA will
+ # be visible outside (shared) libraries.
#
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -xldscope=hidden option" >&5
diff --git a/dlpisubs.h b/dlpisubs.h
index cdc531c1..df417638 100644
--- a/dlpisubs.h
+++ b/dlpisubs.h
@@ -1,10 +1,6 @@
#ifndef dlpisubs_h
#define dlpisubs_h
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* Private data for capturing on DLPI devices.
*/
@@ -22,17 +18,14 @@ struct pcap_dlpi {
/*
* Functions defined by dlpisubs.c.
*/
-int pcap_stats_dlpi(pcap_t *, struct pcap_stat *);
-int pcap_process_pkts(pcap_t *, pcap_handler, u_char *, int, u_char *, int);
-int pcap_process_mactype(pcap_t *, u_int);
+PCAP_UNEXPORTED_C_FUNC int pcap_stats_dlpi(pcap_t *, struct pcap_stat *);
+PCAP_UNEXPORTED_C_FUNC int pcap_process_pkts(pcap_t *, pcap_handler, u_char *, int,
+ u_char *, int);
+PCAP_UNEXPORTED_C_FUNC int pcap_process_mactype(pcap_t *, u_int);
#ifdef HAVE_SYS_BUFMOD_H
-int pcap_conf_bufmod(pcap_t *, int);
-#endif
-int pcap_alloc_databuf(pcap_t *);
-int strioctl(int, int, int, char *);
-
-#ifdef __cplusplus
-}
+PCAP_UNEXPORTED_C_FUNC int pcap_conf_bufmod(pcap_t *, int);
#endif
+PCAP_UNEXPORTED_C_FUNC int pcap_alloc_databuf(pcap_t *);
+PCAP_UNEXPORTED_C_FUNC int strioctl(int, int, int, char *);
#endif
diff --git a/fmtutils.h b/fmtutils.h
index ba0f66ca..ecbe6610 100644
--- a/fmtutils.h
+++ b/fmtutils.h
@@ -36,22 +36,14 @@
#include "pcap/funcattrs.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void pcap_fmt_set_encoding(unsigned int);
+PCAP_UNEXPORTED_C_FUNC void pcap_fmt_set_encoding(unsigned int);
-void pcap_fmt_errmsg_for_errno(char *, size_t, int,
+PCAP_UNEXPORTED_C_FUNC void pcap_fmt_errmsg_for_errno(char *, size_t, int,
PCAP_FORMAT_STRING(const char *), ...) PCAP_PRINTFLIKE(4, 5);
#ifdef _WIN32
-void pcap_fmt_errmsg_for_win32_err(char *, size_t, DWORD,
+PCAP_UNEXPORTED_C_FUNC void pcap_fmt_errmsg_for_win32_err(char *, size_t, DWORD,
PCAP_FORMAT_STRING(const char *), ...) PCAP_PRINTFLIKE(4, 5);
#endif
-#ifdef __cplusplus
-}
-#endif
-
#endif
diff --git a/nametoaddr.c b/nametoaddr.c
index c944ad36..a8aa827f 100644
--- a/nametoaddr.c
+++ b/nametoaddr.c
@@ -588,8 +588,8 @@ struct eproto {
* warnings we might get from compilers about the lack of a
* declaration.
*/
-PCAP_API struct eproto eproto_db[];
-PCAP_API_DEF struct eproto eproto_db[] = {
+PCAP_EXPORTED_DATA struct eproto eproto_db[];
+PCAP_EXPORTED_DATA_DEF struct eproto eproto_db[] = {
{ "aarp", ETHERTYPE_AARP },
{ "arp", ETHERTYPE_ARP },
{ "atalk", ETHERTYPE_ATALK },
diff --git a/nametoaddr.h b/nametoaddr.h
index fd6b7e10..df21c909 100644
--- a/nametoaddr.h
+++ b/nametoaddr.h
@@ -31,18 +31,10 @@
* SUCH DAMAGE.
*/
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* Routines used for name-or-address-string-to-address resolution
* that are *not* exported to code using libpcap.
*/
-int __pcap_atodn(const char *, bpf_u_int32 *);
-int __pcap_atoin(const char *, bpf_u_int32 *);
-int __pcap_nametodnaddr(const char *, u_short *);
-
-#ifdef __cplusplus
-}
-#endif
+PCAP_UNEXPORTED_C_FUNC int __pcap_atodn(const char *, bpf_u_int32 *);
+PCAP_UNEXPORTED_C_FUNC int __pcap_atoin(const char *, bpf_u_int32 *);
+PCAP_UNEXPORTED_C_FUNC int __pcap_nametodnaddr(const char *, u_short *);
diff --git a/optimize.c b/optimize.c
index 610a0303..97894d02 100644
--- a/optimize.c
+++ b/optimize.c
@@ -62,7 +62,7 @@ static int pcap_optimizer_debug;
* it's not declared in any header file, and won't be declared in any
* header file provided by libpcap.
*/
-PCAP_API void pcap_set_optimizer_debug(int value);
+PCAP_EXPORTED_C_FUNC void pcap_set_optimizer_debug(int value);
PCAP_API_DEF void
pcap_set_optimizer_debug(int value)
@@ -87,7 +87,7 @@ static int pcap_print_dot_graph;
* it's not declared in any header file, and won't be declared in any
* header file provided by libpcap.
*/
-PCAP_API void pcap_set_print_dot_graph(int value);
+PCAP_EXPORTED_C_FUNC void pcap_set_print_dot_graph(int value);
PCAP_API_DEF void
pcap_set_print_dot_graph(int value)
diff --git a/pcap-int.h b/pcap-int.h
index febac031..5a263999 100644
--- a/pcap-int.h
+++ b/pcap-int.h
@@ -49,10 +49,6 @@
*/
#define PCAP_VERSION_STRING "libpcap version " PACKAGE_VERSION
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* If pcap_new_api is set, we disable pcap_lookupdev(), because:
*
@@ -431,7 +427,7 @@ struct oneshot_userdata {
#define min(a, b) ((a) > (b) ? (b) : (a))
#endif
-int pcap_offline_read(pcap_t *, int, pcap_handler, u_char *);
+PCAP_UNEXPORTED_C_FUNC int pcap_offline_read(pcap_t *, int, pcap_handler, u_char *);
#include <stdarg.h>
@@ -447,8 +443,8 @@ 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);
+PCAP_UNEXPORTED_C_FUNC int pcap_getnonblock_fd(pcap_t *);
+PCAP_UNEXPORTED_C_FUNC int pcap_setnonblock_fd(pcap_t *p, int);
#endif
/*
@@ -462,7 +458,7 @@ int pcap_setnonblock_fd(pcap_t *p, int);
* "pcap_create_common()" allocates and fills in a pcap_t, for use
* by pcap_create routines.
*/
-pcap_t *pcap_create_interface(const char *, char *);
+PCAP_UNEXPORTED_C_FUNC pcap_t *pcap_create_interface(const char *, char *);
/*
* This wrapper takes an error buffer pointer and a type to use for the
@@ -475,13 +471,13 @@ pcap_t *pcap_create_interface(const char *, char *);
pcap_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_UNEXPORTED_C_FUNC pcap_t *pcap_create_common(char *, size_t, size_t);
+PCAP_UNEXPORTED_C_FUNC int pcap_do_addexit(pcap_t *);
+PCAP_UNEXPORTED_C_FUNC void pcap_add_to_pcaps_to_close(pcap_t *);
+PCAP_UNEXPORTED_C_FUNC void pcap_remove_from_pcaps_to_close(pcap_t *);
+PCAP_UNEXPORTED_C_FUNC void pcap_cleanup_live_common(pcap_t *);
+PCAP_UNEXPORTED_C_FUNC int pcap_check_activated(pcap_t *);
+PCAP_UNEXPORTED_C_FUNC void pcap_breakloop_common(pcap_t *);
/*
* Internal interfaces for "pcap_findalldevs()".
@@ -507,23 +503,23 @@ void pcap_breakloop_common(pcap_t *);
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 *);
+PCAP_UNEXPORTED_C_FUNC int pcap_platform_finddevs(pcap_if_list_t *, char *);
#if !defined(_WIN32) && !defined(MSDOS)
-int pcap_findalldevs_interfaces(pcap_if_list_t *, char *,
+PCAP_UNEXPORTED_C_FUNC int pcap_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,
- 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_UNEXPORTED_C_FUNC pcap_if_t *find_or_add_dev(pcap_if_list_t *, const char *,
+ bpf_u_int32, get_if_flags_func, const char *, char *);
+PCAP_UNEXPORTED_C_FUNC pcap_if_t *find_dev(pcap_if_list_t *, const char *);
+PCAP_UNEXPORTED_C_FUNC pcap_if_t *add_dev(pcap_if_list_t *, const char *, bpf_u_int32,
+ const char *, char *);
+PCAP_UNEXPORTED_C_FUNC int 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,
- get_if_flags_func, char *);
-int add_addr_to_if(pcap_if_list_t *, const char *, bpf_u_int32,
+PCAP_UNEXPORTED_C_FUNC pcap_if_t *find_or_add_if(pcap_if_list_t *, const char *,
+ bpf_u_int32, get_if_flags_func, char *);
+PCAP_UNEXPORTED_C_FUNC int add_addr_to_if(pcap_if_list_t *, const char *, bpf_u_int32,
get_if_flags_func,
struct sockaddr *, size_t, struct sockaddr *, size_t,
struct sockaddr *, size_t, struct sockaddr *, size_t, char *);
@@ -559,12 +555,13 @@ int add_addr_to_if(pcap_if_list_t *, const char *, bpf_u_int32,
pcap_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_UNEXPORTED_C_FUNC pcap_t *pcap_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);
+PCAP_UNEXPORTED_C_FUNC bpf_u_int32 pcap_adjust_snapshot(bpf_u_int32 linktype,
+ bpf_u_int32 snaplen);
+PCAP_UNEXPORTED_C_FUNC void sf_cleanup(pcap_t *p);
#ifdef _WIN32
-FILE *charset_fopen(const char *path, const char *mode);
+PCAP_UNEXPORTED_C_FUNC FILE *charset_fopen(const char *path, const char *mode);
#else
/*
* On other OSes, just use Boring Old fopen().
@@ -579,8 +576,9 @@ 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_UNEXPORTED_C_FUNC pcap_code_handle_t pcap_load_code(const char *);
+PCAP_UNEXPORTED_C_FUNC pcap_funcptr_t pcap_find_function(pcap_code_handle_t,
+ const char *);
#endif
/*
@@ -601,18 +599,19 @@ 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 *,
+PCAP_UNEXPORTED_C_FUNC u_int pcap_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);
+PCAP_UNEXPORTED_C_FUNC u_int pcap_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);
+PCAP_UNEXPORTED_C_FUNC int pcap_validate_filter(const struct bpf_insn *, int);
/*
* Internal interfaces for both "pcap_create()" and routines that
@@ -621,28 +620,25 @@ int pcap_validate_filter(const struct bpf_insn *, int);
* "pcap_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 *);
+PCAP_UNEXPORTED_C_FUNC void pcap_oneshot(u_char *, const struct pcap_pkthdr *,
+ const u_char *);
-int install_bpf_program(pcap_t *, struct bpf_program *);
+PCAP_UNEXPORTED_C_FUNC int install_bpf_program(pcap_t *, struct bpf_program *);
-int pcap_strcasecmp(const char *, const char *);
+PCAP_UNEXPORTED_C_FUNC int pcap_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 *,
+PCAP_UNEXPORTED_C_FUNC int pcap_createsrcstr_ex(char *, int, const char *, const char *,
const char *, unsigned char, char *);
-int pcap_parsesrcstr_ex(const char *, int *, char *, char *,
+PCAP_UNEXPORTED_C_FUNC int pcap_parsesrcstr_ex(const char *, int *, char *, char *,
char *, unsigned char *, char *);
#ifdef YYDEBUG
extern int pcap_debug;
#endif
-#ifdef __cplusplus
-}
-#endif
-
#endif
diff --git a/pcap.c b/pcap.c
index b8b8af2a..aabd51f6 100644
--- a/pcap.c
+++ b/pcap.c
@@ -318,15 +318,15 @@ pcap_init(unsigned int opts, char *errbuf)
/*
* String containing the library version.
* Not explicitly exported via a header file - the right API to use
- * is pcap_lib_version() - but some programs included it, so we
+ * is pcap_lib_version() - but some programs referred to it, so we
* provide it.
*
* We declare it here, right before defining it, to squelch any
* warnings we might get from compilers about the lack of a
* declaration.
*/
-PCAP_API char pcap_version[];
-PCAP_API_DEF char pcap_version[] = PACKAGE_VERSION;
+PCAP_EXPORTED_DATA char pcap_version[];
+PCAP_EXPORTED_DATA_DEF char pcap_version[] = PACKAGE_VERSION;
static void
pcap_set_not_initialized_message(pcap_t *pcap)
@@ -4425,7 +4425,7 @@ pcap_open_dead(int linktype, int snaplen)
* it's not declared in any header file, and won't be declared in any
* header file provided by libpcap.
*/
-PCAP_API void pcap_set_parser_debug(int value);
+PCAP_EXPORTED_C_FUNC void pcap_set_parser_debug(int value);
PCAP_API_DEF void
pcap_set_parser_debug(int value)
diff --git a/pcap/bpf.h b/pcap/bpf.h
index bfc60d2c..8b0412dc 100644
--- a/pcap/bpf.h
+++ b/pcap/bpf.h
@@ -81,10 +81,6 @@
#include <pcap/funcattrs.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/* BSD style release date */
#define BPF_RELEASE 199606
@@ -269,24 +265,20 @@ struct bpf_insn {
#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
PCAP_AVAILABLE_0_4
-PCAP_API u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
+PCAP_EXPORTED_C_FUNC u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
PCAP_AVAILABLE_0_6
-PCAP_API int bpf_validate(const struct bpf_insn *f, int len);
+PCAP_EXPORTED_C_FUNC int bpf_validate(const struct bpf_insn *f, int len);
PCAP_AVAILABLE_0_4
-PCAP_API char *bpf_image(const struct bpf_insn *, int);
+PCAP_EXPORTED_C_FUNC char *bpf_image(const struct bpf_insn *, int);
PCAP_AVAILABLE_0_6
-PCAP_API void bpf_dump(const struct bpf_program *, int);
+PCAP_EXPORTED_C_FUNC void bpf_dump(const struct bpf_program *, int);
/*
* Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
*/
#define BPF_MEMWORDS 16
-#ifdef __cplusplus
-}
-#endif
-
#endif /* !defined(_NET_BPF_H_) && !defined(_BPF_H_) && !defined(_H_BPF) && !defined(lib_pcap_bpf_h) */
diff --git a/pcap/funcattrs.h b/pcap/funcattrs.h
index cdc083d8..d9313fb1 100644
--- a/pcap/funcattrs.h
+++ b/pcap/funcattrs.h
@@ -43,13 +43,14 @@
*/
/*
- * PCAP_API_DEF must be used when defining *data* exported from
- * libpcap. It can be used when defining *functions* exported
- * from libpcap, but it doesn't have to be used there. It
- * should not be used in declarations in headers.
+ * PCAP_EXPORTED_DATA_DEF must be used when defining *data* exported from
+ * libpcap. It should not be used in data declarations in headers.
*
- * PCAP_API must be used when *declaring* data or functions
- * exported from libpcap; PCAP_API_DEF won't work on all platforms.
+ * PCAP_EXPORTED_C_FUNC must be used when *declaring* functions exported from
+ * libpcap; PCAP_API_DEF won't work on all platforms.
+ *
+ * PCAP_EXPORTED_DATA must be used when *declaring* data exported from
+ * libpcap; PCAP_EXPORTED_DATA_DEF won't work on all platforms.
*/
#if defined(_WIN32)
@@ -75,26 +76,26 @@
*
* So:
*
- * if pcap_EXPORTS is defined, we define PCAP_API_DEF as
+ * if pcap_EXPORTS is defined, we define PCAP_EXPORTED as
* __declspec(dllexport);
*
- * if PCAP_DLL is defined, we define PCAP_API_DEF as
+ * if PCAP_DLL is defined, we define PCAP_EXPORTED as
* __declspec(dllimport);
*
- * otherwise, we define PCAP_API_DEF as nothing.
+ * otherwise, we define PCAP_EXPORTED as nothing.
*/
#if defined(pcap_EXPORTS)
/*
* We're compiling libpcap as a DLL, so we should export functions
* in our API.
*/
- #define PCAP_API_DEF __declspec(dllexport)
+ #define PCAP_EXPORTED __declspec(dllexport)
#elif defined(PCAP_DLL)
/*
* We're using libpcap as a DLL, so the calls will be a little more
* efficient if we explicitly import the functions.
*/
- #define PCAP_API_DEF __declspec(dllimport)
+ #define PCAP_EXPORTED __declspec(dllimport)
#else
/*
* Either we're building libpcap as a static library, or we're using
@@ -102,11 +103,11 @@
* using it as a dynamic library, so neither import nor export the
* functions explicitly.
*/
- #define PCAP_API_DEF
+ #define PCAP_EXPORTED
#endif
#elif defined(MSDOS)
/* XXX - does this need special treatment? */
- #define PCAP_API_DEF
+ #define PCAP_EXPORTED
#else /* UN*X */
#ifdef pcap_EXPORTS
/*
@@ -122,29 +123,59 @@
* GCC 3.4 or later, or XL C 13.0 or later, so we have
* __attribute__((visibility()).
*/
- #define PCAP_API_DEF __attribute__((visibility("default")))
+ #define PCAP_EXPORTED __attribute__((visibility("default")))
#elif PCAP_IS_AT_LEAST_SUNC_VERSION(5,5)
/*
* Sun C 5.5 or later, so we have __global.
* (Sun C 5.9 and later also have __attribute__((visibility()),
* but there's no reason to prefer it with Sun C.)
*/
- #define PCAP_API_DEF __global
+ #define PCAP_EXPORTED __global
#else
/*
* We don't have anything to say.
*/
- #define PCAP_API_DEF
+ #define PCAP_EXPORTED
#endif
#else
/*
* We're not building libpcap.
*/
- #define PCAP_API_DEF
+ #define PCAP_EXPORTED
#endif
#endif /* _WIN32/MSDOS/UN*X */
-#define PCAP_API PCAP_API_DEF extern
+/*
+ * If we're compiling C++ code, flag a function as having C linkage.
+ */
+#ifdef __cplusplus
+#define PCAP_C_LINKAGE "C"
+#else
+#define PCAP_C_LINKAGE
+#endif
+
+/*
+ * Declare a C function used internally in libpcap but *not* exported
+ * from libpcap.
+ */
+#define PCAP_UNEXPORTED_C_FUNC extern PCAP_C_LINKAGE
+
+/*
+ * Declare a C function exported from libpcap.
+ */
+#define PCAP_EXPORTED_C_FUNC PCAP_EXPORTED extern PCAP_C_LINKAGE
+
+/*
+ * Declare a variable exported from libpcap.
+ */
+#define PCAP_EXPORTED_DATA PCAP_EXPORTED extern
+
+/*
+ * Define a variable exported from libpcap.
+ *
+ * No definition macro is needed for functions exported from libpcap.
+ */
+#define PCAP_EXPORTED_DATA_DEF PCAP_EXPORTED
/*
* Definitions to 1) indicate what version of libpcap first had a given
diff --git a/pcap/namedb.h b/pcap/namedb.h
index 34a0ae7e..1c7c8847 100644
--- a/pcap/namedb.h
+++ b/pcap/namedb.h
@@ -34,10 +34,6 @@
#ifndef lib_pcap_namedb_h
#define lib_pcap_namedb_h
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* As returned by the pcap_next_etherent()
* XXX this stuff doesn't belong in this interface, but this
@@ -55,20 +51,20 @@ struct pcap_etherent {
#ifndef PCAP_ETHERS_FILE
#define PCAP_ETHERS_FILE "/etc/ethers"
#endif
-PCAP_API struct pcap_etherent *pcap_next_etherent(FILE *);
-PCAP_API u_char *pcap_ether_hostton(const char*);
-PCAP_API u_char *pcap_ether_aton(const char *);
+PCAP_EXPORTED_C_FUNC struct pcap_etherent *pcap_next_etherent(FILE *);
+PCAP_EXPORTED_C_FUNC u_char *pcap_ether_hostton(const char*);
+PCAP_EXPORTED_C_FUNC u_char *pcap_ether_aton(const char *);
-PCAP_API bpf_u_int32 **pcap_nametoaddr(const char *)
+PCAP_EXPORTED_C_FUNC bpf_u_int32 **pcap_nametoaddr(const char *)
PCAP_DEPRECATED(pcap_nametoaddr, "this is not reentrant; use 'pcap_nametoaddrinfo' instead");
-PCAP_API struct addrinfo *pcap_nametoaddrinfo(const char *);
-PCAP_API bpf_u_int32 pcap_nametonetaddr(const char *);
+PCAP_EXPORTED_C_FUNC struct addrinfo *pcap_nametoaddrinfo(const char *);
+PCAP_EXPORTED_C_FUNC bpf_u_int32 pcap_nametonetaddr(const char *);
-PCAP_API int pcap_nametoport(const char *, int *, int *);
-PCAP_API int pcap_nametoportrange(const char *, int *, int *, int *);
-PCAP_API int pcap_nametoproto(const char *);
-PCAP_API int pcap_nametoeproto(const char *);
-PCAP_API int pcap_nametollc(const char *);
+PCAP_EXPORTED_C_FUNC int pcap_nametoport(const char *, int *, int *);
+PCAP_EXPORTED_C_FUNC int pcap_nametoportrange(const char *, int *, int *, int *);
+PCAP_EXPORTED_C_FUNC int pcap_nametoproto(const char *);
+PCAP_EXPORTED_C_FUNC int pcap_nametoeproto(const char *);
+PCAP_EXPORTED_C_FUNC int pcap_nametollc(const char *);
/*
* If a protocol is unknown, PROTO_UNDEF is returned.
* Also, pcap_nametoport() returns the protocol along with the port number.
@@ -77,8 +73,4 @@ PCAP_API int pcap_nametollc(const char *);
*/
#define PROTO_UNDEF -1
-#ifdef __cplusplus
-}
-#endif
-
#endif
diff --git a/pcap/pcap.h b/pcap/pcap.h
index 8182bef4..5bbbc6f9 100644
--- a/pcap/pcap.h
+++ b/pcap/pcap.h
@@ -135,10 +135,6 @@
#include <stdio.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* Version number of the current version of the pcap file format.
*
@@ -383,7 +379,7 @@ typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,
#define PCAP_CHAR_ENC_UTF_8 0x00000001U /* strings are in UTF-8 */
PCAP_AVAILABLE_1_10
-PCAP_API int pcap_init(unsigned int, char *);
+PCAP_EXPORTED_C_FUNC int pcap_init(unsigned int, char *);
/*
* We're deprecating pcap_lookupdev() for various reasons (not
@@ -391,66 +387,66 @@ PCAP_API int pcap_init(unsigned int, char *);
* should use pcap_findalldevs() and use the first device.
*/
PCAP_AVAILABLE_0_4
-PCAP_API char *pcap_lookupdev(char *)
+PCAP_EXPORTED_C_FUNC char *pcap_lookupdev(char *)
PCAP_DEPRECATED(pcap_lookupdev, "use 'pcap_findalldevs' and use the first device");
PCAP_AVAILABLE_0_4
-PCAP_API int pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *);
+PCAP_EXPORTED_C_FUNC int pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *);
PCAP_AVAILABLE_1_0
-PCAP_API pcap_t *pcap_create(const char *, char *);
+PCAP_EXPORTED_C_FUNC pcap_t *pcap_create(const char *, char *);
PCAP_AVAILABLE_1_0
-PCAP_API int pcap_set_snaplen(pcap_t *, int);
+PCAP_EXPORTED_C_FUNC int pcap_set_snaplen(pcap_t *, int);
PCAP_AVAILABLE_1_0
-PCAP_API int pcap_set_promisc(pcap_t *, int);
+PCAP_EXPORTED_C_FUNC int pcap_set_promisc(pcap_t *, int);
PCAP_AVAILABLE_1_0
-PCAP_API int pcap_can_set_rfmon(pcap_t *);
+PCAP_EXPORTED_C_FUNC int pcap_can_set_rfmon(pcap_t *);
PCAP_AVAILABLE_1_0
-PCAP_API int pcap_set_rfmon(pcap_t *, int);
+PCAP_EXPORTED_C_FUNC int pcap_set_rfmon(pcap_t *, int);
PCAP_AVAILABLE_1_0
-PCAP_API int pcap_set_timeout(pcap_t *, int);
+PCAP_EXPORTED_C_FUNC int pcap_set_timeout(pcap_t *, int);
PCAP_AVAILABLE_1_2
-PCAP_API int pcap_set_tstamp_type(pcap_t *, int);
+PCAP_EXPORTED_C_FUNC int pcap_set_tstamp_type(pcap_t *, int);
PCAP_AVAILABLE_1_5
-PCAP_API int pcap_set_immediate_mode(pcap_t *, int);
+PCAP_EXPORTED_C_FUNC int pcap_set_immediate_mode(pcap_t *, int);
PCAP_AVAILABLE_1_0
-PCAP_API int pcap_set_buffer_size(pcap_t *, int);
+PCAP_EXPORTED_C_FUNC int pcap_set_buffer_size(pcap_t *, int);
PCAP_AVAILABLE_1_5
-PCAP_API int pcap_set_tstamp_precision(pcap_t *, int);
+PCAP_EXPORTED_C_FUNC int pcap_set_tstamp_precision(pcap_t *, int);
PCAP_AVAILABLE_1_5
-PCAP_API int pcap_get_tstamp_precision(pcap_t *);
+PCAP_EXPORTED_C_FUNC int pcap_get_tstamp_precision(pcap_t *);
PCAP_AVAILABLE_1_0
-PCAP_API int pcap_activate(pcap_t *);
+PCAP_EXPORTED_C_FUNC int pcap_activate(pcap_t *);
PCAP_AVAILABLE_1_2
-PCAP_API int pcap_list_tstamp_types(pcap_t *, int **);
+PCAP_EXPORTED_C_FUNC int pcap_list_tstamp_types(pcap_t *, int **);
PCAP_AVAILABLE_1_2
-PCAP_API void pcap_free_tstamp_types(int *);
+PCAP_EXPORTED_C_FUNC void pcap_free_tstamp_types(int *);
PCAP_AVAILABLE_1_2
-PCAP_API int pcap_tstamp_type_name_to_val(const char *);
+PCAP_EXPORTED_C_FUNC int pcap_tstamp_type_name_to_val(const char *);
PCAP_AVAILABLE_1_2
-PCAP_API const char *pcap_tstamp_type_val_to_name(int);
+PCAP_EXPORTED_C_FUNC const char *pcap_tstamp_type_val_to_name(int);
PCAP_AVAILABLE_1_2
-PCAP_API const char *pcap_tstamp_type_val_to_description(int);
+PCAP_EXPORTED_C_FUNC const char *pcap_tstamp_type_val_to_description(int);
#ifdef __linux__
PCAP_AVAILABLE_1_9
-PCAP_API int pcap_set_protocol_linux(pcap_t *, int);
+PCAP_EXPORTED_C_FUNC int pcap_set_protocol_linux(pcap_t *, int);
#endif
/*
@@ -512,25 +508,25 @@ PCAP_API int pcap_set_protocol_linux(pcap_t *, int);
#define PCAP_TSTAMP_PRECISION_NANO 1 /* use timestamps with nanosecond precision */
PCAP_AVAILABLE_0_4
-PCAP_API pcap_t *pcap_open_live(const char *, int, int, int, char *);
+PCAP_EXPORTED_C_FUNC pcap_t *pcap_open_live(const char *, int, int, int, char *);
PCAP_AVAILABLE_0_6
-PCAP_API pcap_t *pcap_open_dead(int, int);
+PCAP_EXPORTED_C_FUNC pcap_t *pcap_open_dead(int, int);
PCAP_AVAILABLE_1_5
-PCAP_API pcap_t *pcap_open_dead_with_tstamp_precision(int, int, u_int);
+PCAP_EXPORTED_C_FUNC pcap_t *pcap_open_dead_with_tstamp_precision(int, int, u_int);
PCAP_AVAILABLE_1_5
-PCAP_API pcap_t *pcap_open_offline_with_tstamp_precision(const char *, u_int, char *);
+PCAP_EXPORTED_C_FUNC pcap_t *pcap_open_offline_with_tstamp_precision(const char *, u_int, char *);
PCAP_AVAILABLE_0_4
-PCAP_API pcap_t *pcap_open_offline(const char *, char *);
+PCAP_EXPORTED_C_FUNC pcap_t *pcap_open_offline(const char *, char *);
#ifdef _WIN32
PCAP_AVAILABLE_1_5
- PCAP_API pcap_t *pcap_hopen_offline_with_tstamp_precision(intptr_t, u_int, char *);
+ PCAP_EXPORTED_C_FUNC pcap_t *pcap_hopen_offline_with_tstamp_precision(intptr_t, u_int, char *);
- PCAP_API pcap_t *pcap_hopen_offline(intptr_t, char *);
+ PCAP_EXPORTED_C_FUNC pcap_t *pcap_hopen_offline(intptr_t, char *);
/*
* If we're building libpcap, these are internal routines in savefile.c,
* so we must not define them as macros.
@@ -552,124 +548,124 @@ PCAP_API pcap_t *pcap_open_offline(const char *, char *);
#endif
#else /*_WIN32*/
PCAP_AVAILABLE_1_5
- PCAP_API pcap_t *pcap_fopen_offline_with_tstamp_precision(FILE *, u_int, char *);
+ PCAP_EXPORTED_C_FUNC pcap_t *pcap_fopen_offline_with_tstamp_precision(FILE *, u_int, char *);
PCAP_AVAILABLE_0_9
- PCAP_API pcap_t *pcap_fopen_offline(FILE *, char *);
+ PCAP_EXPORTED_C_FUNC pcap_t *pcap_fopen_offline(FILE *, char *);
#endif /*_WIN32*/
PCAP_AVAILABLE_0_4
-PCAP_API void pcap_close(pcap_t *);
+PCAP_EXPORTED_C_FUNC void pcap_close(pcap_t *);
PCAP_AVAILABLE_0_4
-PCAP_API int pcap_loop(pcap_t *, int, pcap_handler, u_char *);
+PCAP_EXPORTED_C_FUNC int pcap_loop(pcap_t *, int, pcap_handler, u_char *);
PCAP_AVAILABLE_0_4
-PCAP_API int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *);
+PCAP_EXPORTED_C_FUNC int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *);
PCAP_AVAILABLE_0_4
-PCAP_API const u_char *pcap_next(pcap_t *, struct pcap_pkthdr *);
+PCAP_EXPORTED_C_FUNC const u_char *pcap_next(pcap_t *, struct pcap_pkthdr *);
PCAP_AVAILABLE_0_8
-PCAP_API int pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **);
+PCAP_EXPORTED_C_FUNC int pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **);
PCAP_AVAILABLE_0_8
-PCAP_API void pcap_breakloop(pcap_t *);
+PCAP_EXPORTED_C_FUNC void pcap_breakloop(pcap_t *);
PCAP_AVAILABLE_0_4
-PCAP_API int pcap_stats(pcap_t *, struct pcap_stat *);
+PCAP_EXPORTED_C_FUNC int pcap_stats(pcap_t *, struct pcap_stat *);
PCAP_AVAILABLE_0_4
-PCAP_API int pcap_setfilter(pcap_t *, struct bpf_program *);
+PCAP_EXPORTED_C_FUNC int pcap_setfilter(pcap_t *, struct bpf_program *);
PCAP_AVAILABLE_0_9
-PCAP_API int pcap_setdirection(pcap_t *, pcap_direction_t);
+PCAP_EXPORTED_C_FUNC int pcap_setdirection(pcap_t *, pcap_direction_t);
PCAP_AVAILABLE_0_7
-PCAP_API int pcap_getnonblock(pcap_t *, char *);
+PCAP_EXPORTED_C_FUNC int pcap_getnonblock(pcap_t *, char *);
PCAP_AVAILABLE_0_7
-PCAP_API int pcap_setnonblock(pcap_t *, int, char *);
+PCAP_EXPORTED_C_FUNC int pcap_setnonblock(pcap_t *, int, char *);
PCAP_AVAILABLE_0_9
-PCAP_API int pcap_inject(pcap_t *, const void *, size_t);
+PCAP_EXPORTED_C_FUNC int pcap_inject(pcap_t *, const void *, size_t);
PCAP_AVAILABLE_0_8
-PCAP_API int pcap_sendpacket(pcap_t *, const u_char *, int);
+PCAP_EXPORTED_C_FUNC int pcap_sendpacket(pcap_t *, const u_char *, int);
PCAP_AVAILABLE_1_0
-PCAP_API const char *pcap_statustostr(int);
+PCAP_EXPORTED_C_FUNC const char *pcap_statustostr(int);
PCAP_AVAILABLE_0_4
-PCAP_API const char *pcap_strerror(int);
+PCAP_EXPORTED_C_FUNC const char *pcap_strerror(int);
PCAP_AVAILABLE_0_4
-PCAP_API char *pcap_geterr(pcap_t *);
+PCAP_EXPORTED_C_FUNC char *pcap_geterr(pcap_t *);
PCAP_AVAILABLE_0_4
-PCAP_API void pcap_perror(pcap_t *, const char *);
+PCAP_EXPORTED_C_FUNC void pcap_perror(pcap_t *, const char *);
PCAP_AVAILABLE_0_4
-PCAP_API int pcap_compile(pcap_t *, struct bpf_program *, const char *, int,
+PCAP_EXPORTED_C_FUNC int pcap_compile(pcap_t *, struct bpf_program *, const char *, int,
bpf_u_int32);
PCAP_AVAILABLE_0_5
-PCAP_API int pcap_compile_nopcap(int, int, struct bpf_program *,
+PCAP_EXPORTED_C_FUNC int pcap_compile_nopcap(int, int, struct bpf_program *,
const char *, int, bpf_u_int32);
/* XXX - this took two arguments in 0.4 and 0.5 */
PCAP_AVAILABLE_0_6
-PCAP_API void pcap_freecode(struct bpf_program *);
+PCAP_EXPORTED_C_FUNC void pcap_freecode(struct bpf_program *);
PCAP_AVAILABLE_1_0
-PCAP_API int pcap_offline_filter(const struct bpf_program *,
+PCAP_EXPORTED_C_FUNC int pcap_offline_filter(const struct bpf_program *,
const struct pcap_pkthdr *, const u_char *);
PCAP_AVAILABLE_0_4
-PCAP_API int pcap_datalink(pcap_t *);
+PCAP_EXPORTED_C_FUNC int pcap_datalink(pcap_t *);
PCAP_AVAILABLE_1_0
-PCAP_API int pcap_datalink_ext(pcap_t *);
+PCAP_EXPORTED_C_FUNC int pcap_datalink_ext(pcap_t *);
PCAP_AVAILABLE_0_8
-PCAP_API int pcap_list_datalinks(pcap_t *, int **);
+PCAP_EXPORTED_C_FUNC int pcap_list_datalinks(pcap_t *, int **);
PCAP_AVAILABLE_0_8
-PCAP_API int pcap_set_datalink(pcap_t *, int);
+PCAP_EXPORTED_C_FUNC int pcap_set_datalink(pcap_t *, int);
PCAP_AVAILABLE_0_8
-PCAP_API void pcap_free_datalinks(int *);
+PCAP_EXPORTED_C_FUNC void pcap_free_datalinks(int *);
PCAP_AVAILABLE_0_8
-PCAP_API int pcap_datalink_name_to_val(const char *);
+PCAP_EXPORTED_C_FUNC int pcap_datalink_name_to_val(const char *);
PCAP_AVAILABLE_0_8
-PCAP_API const char *pcap_datalink_val_to_name(int);
+PCAP_EXPORTED_C_FUNC const char *pcap_datalink_val_to_name(int);
PCAP_AVAILABLE_0_8
-PCAP_API const char *pcap_datalink_val_to_description(int);
+PCAP_EXPORTED_C_FUNC const char *pcap_datalink_val_to_description(int);
PCAP_AVAILABLE_1_10
-PCAP_API const char *pcap_datalink_val_to_description_or_dlt(int);
+PCAP_EXPORTED_C_FUNC const char *pcap_datalink_val_to_description_or_dlt(int);
PCAP_AVAILABLE_0_4
-PCAP_API int pcap_snapshot(pcap_t *);
+PCAP_EXPORTED_C_FUNC int pcap_snapshot(pcap_t *);
PCAP_AVAILABLE_0_4
-PCAP_API int pcap_is_swapped(pcap_t *);
+PCAP_EXPORTED_C_FUNC int pcap_is_swapped(pcap_t *);
PCAP_AVAILABLE_0_4
-PCAP_API int pcap_major_version(pcap_t *);
+PCAP_EXPORTED_C_FUNC int pcap_major_version(pcap_t *);
PCAP_AVAILABLE_0_4
-PCAP_API int pcap_minor_version(pcap_t *);
+PCAP_EXPORTED_C_FUNC int pcap_minor_version(pcap_t *);
PCAP_AVAILABLE_1_9
-PCAP_API int pcap_bufsize(pcap_t *);
+PCAP_EXPORTED_C_FUNC int pcap_bufsize(pcap_t *);
/* XXX */
PCAP_AVAILABLE_0_4
-PCAP_API FILE *pcap_file(pcap_t *);
+PCAP_EXPORTED_C_FUNC FILE *pcap_file(pcap_t *);
#ifdef _WIN32
/*
@@ -680,23 +676,23 @@ PCAP_API FILE *pcap_file(pcap_t *);
* a Windows-only pcap_handle() API that returns the HANDLE.
*/
PCAP_AVAILABLE_0_4
-PCAP_API int pcap_fileno(pcap_t *)
+PCAP_EXPORTED_C_FUNC int pcap_fileno(pcap_t *)
PCAP_DEPRECATED(pcap_fileno, "use 'pcap_handle'");
#else /* _WIN32 */
PCAP_AVAILABLE_0_4
-PCAP_API int pcap_fileno(pcap_t *);
+PCAP_EXPORTED_C_FUNC int pcap_fileno(pcap_t *);
#endif /* _WIN32 */
#ifdef _WIN32
- PCAP_API int pcap_wsockinit(void);
+ PCAP_EXPORTED_C_FUNC int pcap_wsockinit(void);
#endif
PCAP_AVAILABLE_0_4
-PCAP_API pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);
+PCAP_EXPORTED_C_FUNC pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);
#ifdef _WIN32
PCAP_AVAILABLE_0_9
- PCAP_API pcap_dumper_t *pcap_dump_hopen(pcap_t *, intptr_t);
+ PCAP_EXPORTED_C_FUNC pcap_dumper_t *pcap_dump_hopen(pcap_t *, intptr_t);
/*
* If we're building libpcap, this is an internal routine in sf-pcap.c, so
@@ -717,35 +713,35 @@ PCAP_API pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);
#endif
#else /*_WIN32*/
PCAP_AVAILABLE_0_9
- PCAP_API pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp);
+ PCAP_EXPORTED_C_FUNC pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp);
#endif /*_WIN32*/
PCAP_AVAILABLE_1_7
-PCAP_API pcap_dumper_t *pcap_dump_open_append(pcap_t *, const char *);
+PCAP_EXPORTED_C_FUNC pcap_dumper_t *pcap_dump_open_append(pcap_t *, const char *);
PCAP_AVAILABLE_0_8
-PCAP_API FILE *pcap_dump_file(pcap_dumper_t *);
+PCAP_EXPORTED_C_FUNC FILE *pcap_dump_file(pcap_dumper_t *);
PCAP_AVAILABLE_0_9
-PCAP_API long pcap_dump_ftell(pcap_dumper_t *);
+PCAP_EXPORTED_C_FUNC long pcap_dump_ftell(pcap_dumper_t *);
PCAP_AVAILABLE_1_9
-PCAP_API int64_t pcap_dump_ftell64(pcap_dumper_t *);
+PCAP_EXPORTED_C_FUNC int64_t pcap_dump_ftell64(pcap_dumper_t *);
PCAP_AVAILABLE_0_8
-PCAP_API int pcap_dump_flush(pcap_dumper_t *);
+PCAP_EXPORTED_C_FUNC int pcap_dump_flush(pcap_dumper_t *);
PCAP_AVAILABLE_0_4
-PCAP_API void pcap_dump_close(pcap_dumper_t *);
+PCAP_EXPORTED_C_FUNC void pcap_dump_close(pcap_dumper_t *);
PCAP_AVAILABLE_0_4
-PCAP_API void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
+PCAP_EXPORTED_C_FUNC void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
PCAP_AVAILABLE_0_7
-PCAP_API int pcap_findalldevs(pcap_if_t **, char *);
+PCAP_EXPORTED_C_FUNC int pcap_findalldevs(pcap_if_t **, char *);
PCAP_AVAILABLE_0_7
-PCAP_API void pcap_freealldevs(pcap_if_t *);
+PCAP_EXPORTED_C_FUNC void pcap_freealldevs(pcap_if_t *);
/*
* We return a pointer to the version string, rather than exporting the
@@ -763,7 +759,7 @@ PCAP_API void pcap_freealldevs(pcap_if_t *);
* On Windows, the string is constructed at run time.
*/
PCAP_AVAILABLE_0_8
-PCAP_API const char *pcap_lib_version(void);
+PCAP_EXPORTED_C_FUNC const char *pcap_lib_version(void);
#if defined(_WIN32)
@@ -792,37 +788,37 @@ PCAP_API const char *pcap_lib_version(void);
typedef struct _AirpcapHandle *PAirpcapHandle;
#endif
- PCAP_API int pcap_setbuff(pcap_t *p, int dim);
- PCAP_API int pcap_setmode(pcap_t *p, int mode);
- PCAP_API int pcap_setmintocopy(pcap_t *p, int size);
+ PCAP_EXPORTED_C_FUNC int pcap_setbuff(pcap_t *p, int dim);
+ PCAP_EXPORTED_C_FUNC int pcap_setmode(pcap_t *p, int mode);
+ PCAP_EXPORTED_C_FUNC int pcap_setmintocopy(pcap_t *p, int size);
- PCAP_API HANDLE pcap_getevent(pcap_t *p);
+ PCAP_EXPORTED_C_FUNC HANDLE pcap_getevent(pcap_t *p);
PCAP_AVAILABLE_1_8
- PCAP_API int pcap_oid_get_request(pcap_t *, bpf_u_int32, void *, size_t *);
+ PCAP_EXPORTED_C_FUNC int pcap_oid_get_request(pcap_t *, bpf_u_int32, void *, size_t *);
PCAP_AVAILABLE_1_8
- PCAP_API int pcap_oid_set_request(pcap_t *, bpf_u_int32, const void *, size_t *);
+ PCAP_EXPORTED_C_FUNC int pcap_oid_set_request(pcap_t *, bpf_u_int32, const void *, size_t *);
- PCAP_API pcap_send_queue* pcap_sendqueue_alloc(u_int memsize);
+ PCAP_EXPORTED_C_FUNC pcap_send_queue* pcap_sendqueue_alloc(u_int memsize);
- PCAP_API void pcap_sendqueue_destroy(pcap_send_queue* queue);
+ PCAP_EXPORTED_C_FUNC void pcap_sendqueue_destroy(pcap_send_queue* queue);
- PCAP_API int pcap_sendqueue_queue(pcap_send_queue* queue, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data);
+ PCAP_EXPORTED_C_FUNC int pcap_sendqueue_queue(pcap_send_queue* queue, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data);
- PCAP_API u_int pcap_sendqueue_transmit(pcap_t *p, pcap_send_queue* queue, int sync);
+ PCAP_EXPORTED_C_FUNC u_int pcap_sendqueue_transmit(pcap_t *p, pcap_send_queue* queue, int sync);
- PCAP_API struct pcap_stat *pcap_stats_ex(pcap_t *p, int *pcap_stat_size);
+ PCAP_EXPORTED_C_FUNC struct pcap_stat *pcap_stats_ex(pcap_t *p, int *pcap_stat_size);
- PCAP_API int pcap_setuserbuffer(pcap_t *p, int size);
+ PCAP_EXPORTED_C_FUNC int pcap_setuserbuffer(pcap_t *p, int size);
- PCAP_API int pcap_live_dump(pcap_t *p, char *filename, int maxsize, int maxpacks);
+ PCAP_EXPORTED_C_FUNC int pcap_live_dump(pcap_t *p, char *filename, int maxsize, int maxpacks);
- PCAP_API int pcap_live_dump_ended(pcap_t *p, int sync);
+ PCAP_EXPORTED_C_FUNC int pcap_live_dump_ended(pcap_t *p, int sync);
- PCAP_API int pcap_start_oem(char* err_str, int flags);
+ PCAP_EXPORTED_C_FUNC int pcap_start_oem(char* err_str, int flags);
- PCAP_API PAirpcapHandle pcap_get_airpcap_handle(pcap_t *p);
+ PCAP_EXPORTED_C_FUNC PAirpcapHandle pcap_get_airpcap_handle(pcap_t *p);
#define MODE_CAPT 0
#define MODE_STAT 1
@@ -834,9 +830,9 @@ PCAP_API const char *pcap_lib_version(void);
* MS-DOS definitions
*/
- PCAP_API int pcap_stats_ex (pcap_t *, struct pcap_stat_ex *);
- PCAP_API void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait);
- PCAP_API u_long pcap_mac_packets (void);
+ PCAP_EXPORTED_C_FUNC int pcap_stats_ex (pcap_t *, struct pcap_stat_ex *);
+ PCAP_EXPORTED_C_FUNC void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait);
+ PCAP_EXPORTED_C_FUNC u_long pcap_mac_packets (void);
#else /* UN*X */
@@ -845,10 +841,10 @@ PCAP_API const char *pcap_lib_version(void);
*/
PCAP_AVAILABLE_0_8
- PCAP_API int pcap_get_selectable_fd(pcap_t *);
+ PCAP_EXPORTED_C_FUNC int pcap_get_selectable_fd(pcap_t *);
PCAP_AVAILABLE_1_9
- PCAP_API const struct timeval *pcap_get_required_select_timeout(pcap_t *);
+ PCAP_EXPORTED_C_FUNC const struct timeval *pcap_get_required_select_timeout(pcap_t *);
#endif /* _WIN32/MSDOS/UN*X */
@@ -1081,15 +1077,15 @@ struct pcap_rmtauth
* API available.
*/
PCAP_AVAILABLE_1_9
-PCAP_API pcap_t *pcap_open(const char *source, int snaplen, int flags,
+PCAP_EXPORTED_C_FUNC pcap_t *pcap_open(const char *source, int snaplen, int flags,
int read_timeout, struct pcap_rmtauth *auth, char *errbuf);
PCAP_AVAILABLE_1_9
-PCAP_API int pcap_createsrcstr(char *source, int type, const char *host,
+PCAP_EXPORTED_C_FUNC int pcap_createsrcstr(char *source, int type, const char *host,
const char *port, const char *name, char *errbuf);
PCAP_AVAILABLE_1_9
-PCAP_API int pcap_parsesrcstr(const char *source, int *type, char *host,
+PCAP_EXPORTED_C_FUNC int pcap_parsesrcstr(const char *source, int *type, char *host,
char *port, char *name, char *errbuf);
/*
@@ -1112,7 +1108,7 @@ PCAP_API int pcap_parsesrcstr(const char *source, int *type, char *host,
* the only API available.
*/
PCAP_AVAILABLE_1_9
-PCAP_API int pcap_findalldevs_ex(const char *source,
+PCAP_EXPORTED_C_FUNC int pcap_findalldevs_ex(const char *source,
struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf);
/*
@@ -1183,7 +1179,7 @@ struct pcap_samp
* New functions.
*/
PCAP_AVAILABLE_1_9
-PCAP_API struct pcap_samp *pcap_setsampling(pcap_t *p);
+PCAP_EXPORTED_C_FUNC struct pcap_samp *pcap_setsampling(pcap_t *p);
/*
* RPCAP active mode.
@@ -1193,27 +1189,23 @@ PCAP_API struct pcap_samp *pcap_setsampling(pcap_t *p);
#define RPCAP_HOSTLIST_SIZE 1024
PCAP_AVAILABLE_1_9
-PCAP_API SOCKET pcap_remoteact_accept(const char *address, const char *port,
+PCAP_EXPORTED_C_FUNC SOCKET pcap_remoteact_accept(const char *address, const char *port,
const char *hostlist, char *connectinghost,
struct pcap_rmtauth *auth, char *errbuf);
PCAP_AVAILABLE_1_10
-PCAP_API SOCKET pcap_remoteact_accept_ex(const char *address, const char *port,
+PCAP_EXPORTED_C_FUNC SOCKET pcap_remoteact_accept_ex(const char *address, const char *port,
const char *hostlist, char *connectinghost,
struct pcap_rmtauth *auth, int uses_ssl, char *errbuf);
PCAP_AVAILABLE_1_9
-PCAP_API int pcap_remoteact_list(char *hostlist, char sep, int size,
+PCAP_EXPORTED_C_FUNC int pcap_remoteact_list(char *hostlist, char sep, int size,
char *errbuf);
PCAP_AVAILABLE_1_9
-PCAP_API int pcap_remoteact_close(const char *host, char *errbuf);
+PCAP_EXPORTED_C_FUNC int pcap_remoteact_close(const char *host, char *errbuf);
PCAP_AVAILABLE_1_9
-PCAP_API void pcap_remoteact_cleanup(void);
-
-#ifdef __cplusplus
-}
-#endif
+PCAP_EXPORTED_C_FUNC void pcap_remoteact_cleanup(void);
#endif /* lib_pcap_pcap_h */
diff --git a/portability.h b/portability.h
index d606368d..a600e788 100644
--- a/portability.h
+++ b/portability.h
@@ -42,10 +42,6 @@
#include "pcap/funcattrs.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#ifdef HAVE_STRLCAT
#define pcap_strlcat strlcat
#else
@@ -60,7 +56,7 @@ extern "C" {
/*
* Define it ourselves.
*/
- extern size_t pcap_strlcat(char * restrict dst, const char * restrict src, size_t dstsize);
+ PCAP_UNEXPORTED_C_FUNC size_t pcap_strlcat(char * restrict dst, const char * restrict src, size_t dstsize);
#endif
#endif
@@ -78,7 +74,7 @@ extern "C" {
/*
* Define it ourselves.
*/
- extern size_t pcap_strlcpy(char * restrict dst, const char * restrict src, size_t dstsize);
+ PCAP_UNEXPORTED_C_FUNC size_t pcap_strlcpy(char * restrict dst, const char * restrict src, size_t dstsize);
#endif
#endif
@@ -102,14 +98,14 @@ extern "C" {
#ifdef HAVE_ASPRINTF
#define pcap_asprintf asprintf
#else
-extern int pcap_asprintf(char **, PCAP_FORMAT_STRING(const char *), ...)
+PCAP_UNEXPORTED_C_FUNC int pcap_asprintf(char **, PCAP_FORMAT_STRING(const char *), ...)
PCAP_PRINTFLIKE(2, 3);
#endif
#ifdef HAVE_VASPRINTF
#define pcap_vasprintf vasprintf
#else
-extern int pcap_vasprintf(char **, const char *, va_list ap);
+PCAP_UNEXPORTED_C_FUNC int pcap_vasprintf(char **, const char *, va_list ap);
#endif
#ifdef HAVE_STRTOK_R
@@ -124,7 +120,7 @@ extern int pcap_vasprintf(char **, const char *, va_list ap);
/*
* Define it ourselves.
*/
- extern char *pcap_strtok_r(char *, const char *, char **);
+ PCAP_UNEXPORTED_C_FUNC char *pcap_strtok_r(char *, const char *, char **);
#endif
#endif /* HAVE_STRTOK_R */
@@ -134,8 +130,4 @@ extern int pcap_vasprintf(char **, const char *, va_list ap);
#endif
#endif /* _WIN32 */
-#ifdef __cplusplus
-}
-#endif
-
#endif
diff --git a/sockutils.h b/sockutils.h
index e748662e..f39ad000 100644
--- a/sockutils.h
+++ b/sockutils.h
@@ -38,6 +38,7 @@
#endif
#include "pcap/socket.h"
+#include "pcap/funcattrs.h"
#ifndef _WIN32
/* UN*X */
@@ -59,8 +60,8 @@
* MSDN states that this function is available for most versions on Windows.
*/
#if ((defined(__MINGW32__)) && (_WIN32_WINNT < 0x0501))
-int WSAAPI getnameinfo(const struct sockaddr*,socklen_t,char*,DWORD,
- char*,DWORD,int);
+PCAP_UNEXPORTED_C_FUNC int WSAAPI getnameinfo(const struct sockaddr*, socklen_t, char*,
+ DWORD, char*, DWORD, int);
#endif
/*
@@ -112,10 +113,6 @@ int WSAAPI getnameinfo(const struct sockaddr*,socklen_t,char*,DWORD,
* \}
*/
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* \defgroup ExportedFunc Exported Functions
*/
@@ -125,35 +122,43 @@ extern "C" {
* \{
*/
-int sock_init(char *errbuf, int errbuflen);
-void sock_cleanup(void);
-void sock_fmterror(const char *caller, int errcode, char *errbuf, int errbuflen);
-void sock_geterror(const char *caller, char *errbuf, int errbufsize);
-int sock_initaddress(const char *address, const char *port,
+PCAP_UNEXPORTED_C_FUNC int sock_init(char *errbuf, int errbuflen);
+PCAP_UNEXPORTED_C_FUNC void sock_cleanup(void);
+PCAP_UNEXPORTED_C_FUNC void sock_fmterror(const char *caller, int errcode, char *errbuf,
+ int errbuflen);
+PCAP_UNEXPORTED_C_FUNC void sock_geterror(const char *caller, char *errbuf,
+ int errbufsize);
+PCAP_UNEXPORTED_C_FUNC int sock_initaddress(const char *address, const char *port,
struct addrinfo *hints, struct addrinfo **addrinfo,
char *errbuf, int errbuflen);
-int sock_recv(SOCKET sock, SSL *, void *buffer, size_t size, int receiveall,
+PCAP_UNEXPORTED_C_FUNC int sock_recv(SOCKET sock, SSL *, void *buffer, size_t size,
+ int receiveall, char *errbuf, int errbuflen);
+PCAP_UNEXPORTED_C_FUNC int sock_recv_dgram(SOCKET sock, SSL *, void *buffer, size_t size,
char *errbuf, int errbuflen);
-int sock_recv_dgram(SOCKET sock, SSL *, void *buffer, size_t size,
- char *errbuf, int errbuflen);
-SOCKET sock_open(struct addrinfo *addrinfo, int server, int nconn, char *errbuf, int errbuflen);
-int sock_close(SOCKET sock, char *errbuf, int errbuflen);
+PCAP_UNEXPORTED_C_FUNC SOCKET sock_open(struct addrinfo *addrinfo, int server,
+ int nconn, char *errbuf, int errbuflen);
+PCAP_UNEXPORTED_C_FUNC int sock_close(SOCKET sock, char *errbuf, int errbuflen);
-int sock_send(SOCKET sock, SSL *, const char *buffer, size_t size,
+PCAP_UNEXPORTED_C_FUNC int sock_send(SOCKET sock, SSL *, const char *buffer, size_t size,
char *errbuf, int errbuflen);
-int sock_bufferize(const char *buffer, int size, char *tempbuf, int *offset, int totsize, int checkonly, char *errbuf, int errbuflen);
-int sock_discard(SOCKET sock, SSL *, int size, char *errbuf, int errbuflen);
-int sock_check_hostlist(char *hostlist, const char *sep, struct sockaddr_storage *from, char *errbuf, int errbuflen);
-int sock_cmpaddr(struct sockaddr_storage *first, struct sockaddr_storage *second);
-
-int sock_getmyinfo(SOCKET sock, char *address, int addrlen, char *port, int portlen, int flags, char *errbuf, int errbuflen);
-
-int sock_getascii_addrport(const struct sockaddr_storage *sockaddr, char *address, int addrlen, char *port, int portlen, int flags, char *errbuf, int errbuflen);
-int sock_present2network(const char *address, struct sockaddr_storage *sockaddr, int addr_family, char *errbuf, int errbuflen);
-
-#ifdef __cplusplus
-}
-#endif
+PCAP_UNEXPORTED_C_FUNC int sock_bufferize(const char *buffer, int size, char *tempbuf,
+ int *offset, int totsize, int checkonly, char *errbuf, int errbuflen);
+PCAP_UNEXPORTED_C_FUNC int sock_discard(SOCKET sock, SSL *, int size, char *errbuf,
+ int errbuflen);
+PCAP_UNEXPORTED_C_FUNC int sock_check_hostlist(char *hostlist, const char *sep,
+ struct sockaddr_storage *from, char *errbuf, int errbuflen);
+PCAP_UNEXPORTED_C_FUNC int sock_cmpaddr(struct sockaddr_storage *first,
+ struct sockaddr_storage *second);
+
+PCAP_UNEXPORTED_C_FUNC int sock_getmyinfo(SOCKET sock, char *address, int addrlen,
+ char *port, int portlen, int flags, char *errbuf, int errbuflen);
+
+PCAP_UNEXPORTED_C_FUNC int sock_getascii_addrport(const struct sockaddr_storage *sockaddr,
+ char *address, int addrlen, char *port, int portlen, int flags,
+ char *errbuf, int errbuflen);
+PCAP_UNEXPORTED_C_FUNC int sock_present2network(const char *address,
+ struct sockaddr_storage *sockaddr, int addr_family, char *errbuf,
+ int errbuflen);
/*
* \}
diff --git a/testprogs/filtertest.c b/testprogs/filtertest.c
index 440b550d..adc00f2a 100644
--- a/testprogs/filtertest.c
+++ b/testprogs/filtertest.c
@@ -67,8 +67,8 @@ The Regents of the University of California. All rights reserved.\n";
* to include them, and only intended for use by libpcap developers trying
* to debug the optimizer for filter expressions).
*/
-PCAP_API void pcap_set_optimizer_debug(int);
-PCAP_API void pcap_set_print_dot_graph(int);
+PCAP_EXPORTED_C_FUNC void pcap_set_optimizer_debug(int);
+PCAP_EXPORTED_C_FUNC void pcap_set_print_dot_graph(int);
#endif
static char *program_name;