Skip to content

Commit

Permalink
Revert "Don't wrap chunks of headers with extern "C" { ... }."
Browse files Browse the repository at this point in the history
This reverts commit 8b6b13d.

That solution allowed you to intermix declarations/definitions and
before the extern "C", so you can see what's being imported.
  • Loading branch information
guyharris committed Mar 18, 2021
1 parent 8b6b13d commit d0e5801
Show file tree
Hide file tree
Showing 17 changed files with 311 additions and 294 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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_EXPORTED_C_FUNC or
# PCAP_EXPORTED_DATA will be visible outside (shared) libraries.
# symbols explicitly exported with PCAP_API will be visible outside
# (shared) libraries.
#
# Not necessary with MSVC, as that's the default.
#
Expand Down
9 changes: 3 additions & 6 deletions aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ AC_DEFUN(AC_LBL_C_INIT,
#
# Try to have the compiler default to hiding symbols,
# so that only symbols explicitly exported with
# PCAP_EXPORTED_C_FUNC or PCAP_EXPORTED_DATA will
# be visible outside (shared) libraries.
# PCAP_API will be visible outside (shared) libraries.
#
AC_LBL_CHECK_COMPILER_OPT($1, -fvisibility=hidden)
else
Expand All @@ -126,8 +125,7 @@ AC_DEFUN(AC_LBL_C_INIT,
#
# Try to have the compiler default to hiding symbols,
# so that only symbols explicitly exported with
# PCAP_EXPORTED_C_FUNC or PCAP_EXPORTED_DATA will
# be visible outside (shared) libraries.
# PCAP_API will be visible outside (shared) libraries.
#
AC_LBL_CHECK_COMPILER_OPT($1, -fvisibility=hidden)
;;
Expand Down Expand Up @@ -208,8 +206,7 @@ AC_DEFUN(AC_LBL_C_INIT,
#
# Try to have the compiler default to hiding symbols,
# so that only symbols explicitly exported with
# PCAP_EXPORTED_C_FUNC or PCAP_EXPORTED_DATA will
# be visible outside (shared) libraries.
# PCAP_API will be visible outside (shared) libraries.
#
AC_LBL_CHECK_COMPILER_OPT($1, -xldscope=hidden)
;;
Expand Down
9 changes: 3 additions & 6 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -3895,8 +3895,7 @@ esac
#
# Try to have the compiler default to hiding symbols,
# so that only symbols explicitly exported with
# PCAP_EXPORTED_C_FUNC or PCAP_EXPORTED_DATA will
# be visible outside (shared) libraries.
# PCAP_API will be visible outside (shared) libraries.
#

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -fvisibility=hidden option" >&5
Expand Down Expand Up @@ -3996,8 +3995,7 @@ 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_EXPORTED_C_FUNC or PCAP_EXPORTED_DATA will
# be visible outside (shared) libraries.
# PCAP_API will be visible outside (shared) libraries.
#

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -fvisibility=hidden option" >&5
Expand Down Expand Up @@ -4159,8 +4157,7 @@ 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_EXPORTED_C_FUNC or PCAP_EXPORTED_DATA will
# be visible outside (shared) libraries.
# PCAP_API will be visible outside (shared) libraries.
#

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -xldscope=hidden option" >&5
Expand Down
21 changes: 14 additions & 7 deletions dlpisubs.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef dlpisubs_h
#define dlpisubs_h

#ifdef __cplusplus
extern "C" {
#endif

/*
* Private data for capturing on DLPI devices.
*/
Expand All @@ -18,14 +22,17 @@ struct pcap_dlpi {
/*
* Functions defined by dlpisubs.c.
*/
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);
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);
#ifdef HAVE_SYS_BUFMOD_H
PCAP_UNEXPORTED_C_FUNC int pcap_conf_bufmod(pcap_t *, int);
int pcap_conf_bufmod(pcap_t *, int);
#endif
int pcap_alloc_databuf(pcap_t *);
int strioctl(int, int, int, char *);

#ifdef __cplusplus
}
#endif
PCAP_UNEXPORTED_C_FUNC int pcap_alloc_databuf(pcap_t *);
PCAP_UNEXPORTED_C_FUNC int strioctl(int, int, int, char *);

#endif
14 changes: 11 additions & 3 deletions fmtutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,22 @@

#include "pcap/funcattrs.h"

PCAP_UNEXPORTED_C_FUNC void pcap_fmt_set_encoding(unsigned int);
#ifdef __cplusplus
extern "C" {
#endif

void pcap_fmt_set_encoding(unsigned int);

PCAP_UNEXPORTED_C_FUNC void pcap_fmt_errmsg_for_errno(char *, size_t, int,
void pcap_fmt_errmsg_for_errno(char *, size_t, int,
PCAP_FORMAT_STRING(const char *), ...) PCAP_PRINTFLIKE(4, 5);

#ifdef _WIN32
PCAP_UNEXPORTED_C_FUNC void pcap_fmt_errmsg_for_win32_err(char *, size_t, DWORD,
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
4 changes: 2 additions & 2 deletions nametoaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ struct eproto {
* warnings we might get from compilers about the lack of a
* declaration.
*/
PCAP_EXPORTED_DATA struct eproto eproto_db[];
PCAP_EXPORTED_DATA_DEF struct eproto eproto_db[] = {
PCAP_API struct eproto eproto_db[];
PCAP_API_DEF struct eproto eproto_db[] = {
{ "aarp", ETHERTYPE_AARP },
{ "arp", ETHERTYPE_ARP },
{ "atalk", ETHERTYPE_ATALK },
Expand Down
14 changes: 11 additions & 3 deletions nametoaddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@
* 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.
*/
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 *);
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
4 changes: 2 additions & 2 deletions optimize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_EXPORTED_C_FUNC void pcap_set_optimizer_debug(int value);
PCAP_API void pcap_set_optimizer_debug(int value);

PCAP_API_DEF void
pcap_set_optimizer_debug(int value)
Expand All @@ -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_EXPORTED_C_FUNC void pcap_set_print_dot_graph(int value);
PCAP_API void pcap_set_print_dot_graph(int value);

PCAP_API_DEF void
pcap_set_print_dot_graph(int value)
Expand Down
84 changes: 44 additions & 40 deletions pcap-int.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
*/
#define PCAP_VERSION_STRING "libpcap version " PACKAGE_VERSION

#ifdef __cplusplus
extern "C" {
#endif

/*
* If pcap_new_api is set, we disable pcap_lookupdev(), because:
*
Expand Down Expand Up @@ -427,7 +431,7 @@ struct oneshot_userdata {
#define min(a, b) ((a) > (b) ? (b) : (a))
#endif

PCAP_UNEXPORTED_C_FUNC int pcap_offline_read(pcap_t *, int, pcap_handler, u_char *);
int pcap_offline_read(pcap_t *, int, pcap_handler, u_char *);

#include <stdarg.h>

Expand All @@ -443,8 +447,8 @@ PCAP_UNEXPORTED_C_FUNC 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)
PCAP_UNEXPORTED_C_FUNC int pcap_getnonblock_fd(pcap_t *);
PCAP_UNEXPORTED_C_FUNC int pcap_setnonblock_fd(pcap_t *p, int);
int pcap_getnonblock_fd(pcap_t *);
int pcap_setnonblock_fd(pcap_t *p, int);
#endif

/*
Expand All @@ -458,7 +462,7 @@ PCAP_UNEXPORTED_C_FUNC 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_UNEXPORTED_C_FUNC pcap_t *pcap_create_interface(const char *, char *);
pcap_t *pcap_create_interface(const char *, char *);

/*
* This wrapper takes an error buffer pointer and a type to use for the
Expand All @@ -471,13 +475,13 @@ PCAP_UNEXPORTED_C_FUNC 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_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 *);
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 *);

/*
* Internal interfaces for "pcap_findalldevs()".
Expand All @@ -503,23 +507,23 @@ PCAP_UNEXPORTED_C_FUNC 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 *);
PCAP_UNEXPORTED_C_FUNC int pcap_platform_finddevs(pcap_if_list_t *, char *);
int pcap_platform_finddevs(pcap_if_list_t *, char *);
#if !defined(_WIN32) && !defined(MSDOS)
PCAP_UNEXPORTED_C_FUNC int pcap_findalldevs_interfaces(pcap_if_list_t *, char *,
int pcap_findalldevs_interfaces(pcap_if_list_t *, char *,
int (*)(const char *), get_if_flags_func);
#endif
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,
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,
struct sockaddr *, size_t, struct sockaddr *, size_t,
struct sockaddr *dstaddr, size_t, char *errbuf);
#ifndef _WIN32
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,
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,
get_if_flags_func,
struct sockaddr *, size_t, struct sockaddr *, size_t,
struct sockaddr *, size_t, struct sockaddr *, size_t, char *);
Expand Down Expand Up @@ -555,13 +559,12 @@ PCAP_UNEXPORTED_C_FUNC int add_addr_to_if(pcap_if_list_t *, const char *, bpf_u_
pcap_open_offline_common(ebuf, \
sizeof (struct { pcap_t __common; type __private; }), \
offsetof (struct { pcap_t __common; type __private; }, __private))
PCAP_UNEXPORTED_C_FUNC pcap_t *pcap_open_offline_common(char *ebuf, size_t total_size,
pcap_t *pcap_open_offline_common(char *ebuf, size_t total_size,
size_t private_data);
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);
bpf_u_int32 pcap_adjust_snapshot(bpf_u_int32 linktype, bpf_u_int32 snaplen);
void sf_cleanup(pcap_t *p);
#ifdef _WIN32
PCAP_UNEXPORTED_C_FUNC FILE *charset_fopen(const char *path, const char *mode);
FILE *charset_fopen(const char *path, const char *mode);
#else
/*
* On other OSes, just use Boring Old fopen().
Expand All @@ -576,9 +579,8 @@ PCAP_UNEXPORTED_C_FUNC FILE *charset_fopen(const char *path, const char *mode);
#define pcap_code_handle_t HMODULE
#define pcap_funcptr_t FARPROC

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 *);
pcap_code_handle_t pcap_load_code(const char *);
pcap_funcptr_t pcap_find_function(pcap_code_handle_t, const char *);
#endif

/*
Expand All @@ -599,19 +601,18 @@ struct pcap_bpf_aux_data {
* Filtering routine that takes the auxiliary data as an additional
* argument.
*/
PCAP_UNEXPORTED_C_FUNC u_int pcap_filter_with_aux_data(const struct bpf_insn *,
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.
*/
PCAP_UNEXPORTED_C_FUNC u_int pcap_filter(const struct bpf_insn *, const u_char *,
u_int, u_int);
u_int pcap_filter(const struct bpf_insn *, const u_char *, u_int, u_int);

/*
* Routine to validate a BPF program.
*/
PCAP_UNEXPORTED_C_FUNC int pcap_validate_filter(const struct bpf_insn *, int);
int pcap_validate_filter(const struct bpf_insn *, int);

/*
* Internal interfaces for both "pcap_create()" and routines that
Expand All @@ -620,25 +621,28 @@ PCAP_UNEXPORTED_C_FUNC int pcap_validate_filter(const struct bpf_insn *, int);
* "pcap_oneshot()" is the standard one-shot callback for "pcap_next()"
* and "pcap_next_ex()".
*/
PCAP_UNEXPORTED_C_FUNC void pcap_oneshot(u_char *, const struct pcap_pkthdr *,
const u_char *);
void pcap_oneshot(u_char *, const struct pcap_pkthdr *, const u_char *);

PCAP_UNEXPORTED_C_FUNC int install_bpf_program(pcap_t *, struct bpf_program *);
int install_bpf_program(pcap_t *, struct bpf_program *);

PCAP_UNEXPORTED_C_FUNC int pcap_strcasecmp(const char *, const char *);
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://).
*/
PCAP_UNEXPORTED_C_FUNC int pcap_createsrcstr_ex(char *, int, const char *, const char *,
int pcap_createsrcstr_ex(char *, int, const char *, const char *,
const char *, unsigned char, char *);
PCAP_UNEXPORTED_C_FUNC int pcap_parsesrcstr_ex(const char *, int *, char *, char *,
int pcap_parsesrcstr_ex(const char *, int *, char *, char *,
char *, unsigned char *, char *);

#ifdef YYDEBUG
extern int pcap_debug;
#endif

#ifdef __cplusplus
}
#endif

#endif
8 changes: 4 additions & 4 deletions pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 referred to it, so we
* is pcap_lib_version() - but some programs included 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_EXPORTED_DATA char pcap_version[];
PCAP_EXPORTED_DATA_DEF char pcap_version[] = PACKAGE_VERSION;
PCAP_API char pcap_version[];
PCAP_API_DEF char pcap_version[] = PACKAGE_VERSION;

static void
pcap_set_not_initialized_message(pcap_t *pcap)
Expand Down Expand Up @@ -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_EXPORTED_C_FUNC void pcap_set_parser_debug(int value);
PCAP_API void pcap_set_parser_debug(int value);

PCAP_API_DEF void
pcap_set_parser_debug(int value)
Expand Down
Loading

0 comments on commit d0e5801

Please sign in to comment.