xref: /freebsd/contrib/libpcap/pcap/funcattrs.h (revision afdbf109c6a661a729938f68211054a0a50d38ac)
1b00ab754SHans Petter Selasky /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
2b00ab754SHans Petter Selasky /*
3b00ab754SHans Petter Selasky  * Copyright (c) 1993, 1994, 1995, 1996, 1997
4b00ab754SHans Petter Selasky  *	The Regents of the University of California.  All rights reserved.
5b00ab754SHans Petter Selasky  *
6b00ab754SHans Petter Selasky  * Redistribution and use in source and binary forms, with or without
7b00ab754SHans Petter Selasky  * modification, are permitted provided that the following conditions
8b00ab754SHans Petter Selasky  * are met:
9b00ab754SHans Petter Selasky  * 1. Redistributions of source code must retain the above copyright
10b00ab754SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer.
11b00ab754SHans Petter Selasky  * 2. Redistributions in binary form must reproduce the above copyright
12b00ab754SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer in the
13b00ab754SHans Petter Selasky  *    documentation and/or other materials provided with the distribution.
14b00ab754SHans Petter Selasky  * 3. All advertising materials mentioning features or use of this software
15b00ab754SHans Petter Selasky  *    must display the following acknowledgement:
16b00ab754SHans Petter Selasky  *	This product includes software developed by the Computer Systems
17b00ab754SHans Petter Selasky  *	Engineering Group at Lawrence Berkeley Laboratory.
18b00ab754SHans Petter Selasky  * 4. Neither the name of the University nor of the Laboratory may be used
19b00ab754SHans Petter Selasky  *    to endorse or promote products derived from this software without
20b00ab754SHans Petter Selasky  *    specific prior written permission.
21b00ab754SHans Petter Selasky  *
22b00ab754SHans Petter Selasky  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23b00ab754SHans Petter Selasky  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24b00ab754SHans Petter Selasky  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25b00ab754SHans Petter Selasky  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26b00ab754SHans Petter Selasky  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27b00ab754SHans Petter Selasky  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28b00ab754SHans Petter Selasky  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29b00ab754SHans Petter Selasky  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30b00ab754SHans Petter Selasky  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31b00ab754SHans Petter Selasky  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32b00ab754SHans Petter Selasky  * SUCH DAMAGE.
33b00ab754SHans Petter Selasky  */
34b00ab754SHans Petter Selasky 
35b00ab754SHans Petter Selasky #ifndef lib_pcap_funcattrs_h
36b00ab754SHans Petter Selasky #define lib_pcap_funcattrs_h
37b00ab754SHans Petter Selasky 
38b00ab754SHans Petter Selasky #include <pcap/compiler-tests.h>
39b00ab754SHans Petter Selasky 
40b00ab754SHans Petter Selasky /*
41b00ab754SHans Petter Selasky  * Attributes to apply to functions and their arguments, using various
42b00ab754SHans Petter Selasky  * compiler-specific extensions.
43b00ab754SHans Petter Selasky  */
44b00ab754SHans Petter Selasky 
45b00ab754SHans Petter Selasky /*
46b00ab754SHans Petter Selasky  * PCAP_API_DEF must be used when defining *data* exported from
47b00ab754SHans Petter Selasky  * libpcap.  It can be used when defining *functions* exported
48b00ab754SHans Petter Selasky  * from libpcap, but it doesn't have to be used there.  It
49b00ab754SHans Petter Selasky  * should not be used in declarations in headers.
50b00ab754SHans Petter Selasky  *
51b00ab754SHans Petter Selasky  * PCAP_API must be used when *declaring* data or functions
52b00ab754SHans Petter Selasky  * exported from libpcap; PCAP_API_DEF won't work on all platforms.
53b00ab754SHans Petter Selasky  */
54b00ab754SHans Petter Selasky 
55b00ab754SHans Petter Selasky #if defined(_WIN32)
56b00ab754SHans Petter Selasky   /*
57b00ab754SHans Petter Selasky    * For Windows:
58b00ab754SHans Petter Selasky    *
59b00ab754SHans Petter Selasky    *    when building libpcap:
60b00ab754SHans Petter Selasky    *
61b00ab754SHans Petter Selasky    *       if we're building it as a DLL, we have to declare API
62b00ab754SHans Petter Selasky    *       functions with __declspec(dllexport);
63b00ab754SHans Petter Selasky    *
64b00ab754SHans Petter Selasky    *       if we're building it as a static library, we don't want
65b00ab754SHans Petter Selasky    *       to do so.
66b00ab754SHans Petter Selasky    *
67b00ab754SHans Petter Selasky    *    when using libpcap:
68b00ab754SHans Petter Selasky    *
69b00ab754SHans Petter Selasky    *       if we're using the DLL, calls to its functions are a
70b00ab754SHans Petter Selasky    *       little more efficient if they're declared with
71b00ab754SHans Petter Selasky    *       __declspec(dllimport);
72b00ab754SHans Petter Selasky    *
73b00ab754SHans Petter Selasky    *       if we're not using the dll, we don't want to declare
74b00ab754SHans Petter Selasky    *       them that way.
75b00ab754SHans Petter Selasky    *
76b00ab754SHans Petter Selasky    * So:
77b00ab754SHans Petter Selasky    *
78b00ab754SHans Petter Selasky    *    if pcap_EXPORTS is defined, we define PCAP_API_DEF as
79b00ab754SHans Petter Selasky    *     __declspec(dllexport);
80b00ab754SHans Petter Selasky    *
81b00ab754SHans Petter Selasky    *    if PCAP_DLL is defined, we define PCAP_API_DEF as
82b00ab754SHans Petter Selasky    *    __declspec(dllimport);
83b00ab754SHans Petter Selasky    *
84b00ab754SHans Petter Selasky    *    otherwise, we define PCAP_API_DEF as nothing.
85b00ab754SHans Petter Selasky    */
86b00ab754SHans Petter Selasky   #if defined(pcap_EXPORTS)
87b00ab754SHans Petter Selasky     /*
88b00ab754SHans Petter Selasky      * We're compiling libpcap as a DLL, so we should export functions
89b00ab754SHans Petter Selasky      * in our API.
90b00ab754SHans Petter Selasky      */
91b00ab754SHans Petter Selasky     #define PCAP_API_DEF	__declspec(dllexport)
92b00ab754SHans Petter Selasky   #elif defined(PCAP_DLL)
93b00ab754SHans Petter Selasky     /*
94b00ab754SHans Petter Selasky      * We're using libpcap as a DLL, so the calls will be a little more
95b00ab754SHans Petter Selasky      * efficient if we explicitly import the functions.
96b00ab754SHans Petter Selasky      */
97b00ab754SHans Petter Selasky     #define PCAP_API_DEF	__declspec(dllimport)
98b00ab754SHans Petter Selasky   #else
99b00ab754SHans Petter Selasky     /*
100b00ab754SHans Petter Selasky      * Either we're building libpcap as a static library, or we're using
101b00ab754SHans Petter Selasky      * it as a static library, or we don't know for certain that we're
102b00ab754SHans Petter Selasky      * using it as a dynamic library, so neither import nor export the
103b00ab754SHans Petter Selasky      * functions explicitly.
104b00ab754SHans Petter Selasky      */
105b00ab754SHans Petter Selasky     #define PCAP_API_DEF
106b00ab754SHans Petter Selasky   #endif
107b00ab754SHans Petter Selasky #elif defined(MSDOS)
108b00ab754SHans Petter Selasky   /* XXX - does this need special treatment? */
109b00ab754SHans Petter Selasky   #define PCAP_API_DEF
110b00ab754SHans Petter Selasky #else /* UN*X */
111b00ab754SHans Petter Selasky   #ifdef pcap_EXPORTS
112b00ab754SHans Petter Selasky     /*
113b00ab754SHans Petter Selasky      * We're compiling libpcap as a (dynamic) shared library, so we should
114b00ab754SHans Petter Selasky      * export functions in our API.  The compiler might be configured not
115b00ab754SHans Petter Selasky      * to export functions from a shared library by default, so we might
116b00ab754SHans Petter Selasky      * have to explicitly mark functions as exported.
117b00ab754SHans Petter Selasky      */
118b00ab754SHans Petter Selasky     #if PCAP_IS_AT_LEAST_GNUC_VERSION(3,4) \
119b00ab754SHans Petter Selasky         || PCAP_IS_AT_LEAST_XL_C_VERSION(12,0)
120b00ab754SHans Petter Selasky       /*
1216f9cba8fSJoseph Mingrone        * GCC 3.4 and later, or some compiler asserting compatibility with
1226f9cba8fSJoseph Mingrone        * GCC 3.4 and later, or XL C 13.0 and later, so we have
123b00ab754SHans Petter Selasky        * __attribute__((visibility()).
124b00ab754SHans Petter Selasky        */
125b00ab754SHans Petter Selasky       #define PCAP_API_DEF	__attribute__((visibility("default")))
126b00ab754SHans Petter Selasky     #elif PCAP_IS_AT_LEAST_SUNC_VERSION(5,5)
127b00ab754SHans Petter Selasky       /*
1286f9cba8fSJoseph Mingrone        * Sun C 5.5 and later, so we have __global.
129b00ab754SHans Petter Selasky        * (Sun C 5.9 and later also have __attribute__((visibility()),
130b00ab754SHans Petter Selasky        * but there's no reason to prefer it with Sun C.)
131b00ab754SHans Petter Selasky        */
132b00ab754SHans Petter Selasky       #define PCAP_API_DEF	__global
133b00ab754SHans Petter Selasky     #else
134b00ab754SHans Petter Selasky       /*
135b00ab754SHans Petter Selasky        * We don't have anything to say.
136b00ab754SHans Petter Selasky        */
137b00ab754SHans Petter Selasky       #define PCAP_API_DEF
138b00ab754SHans Petter Selasky     #endif
139b00ab754SHans Petter Selasky   #else
140b00ab754SHans Petter Selasky     /*
141b00ab754SHans Petter Selasky      * We're not building libpcap.
142b00ab754SHans Petter Selasky      */
143b00ab754SHans Petter Selasky     #define PCAP_API_DEF
144b00ab754SHans Petter Selasky   #endif
145b00ab754SHans Petter Selasky #endif /* _WIN32/MSDOS/UN*X */
146b00ab754SHans Petter Selasky 
147b00ab754SHans Petter Selasky #define PCAP_API	PCAP_API_DEF extern
148b00ab754SHans Petter Selasky 
149b00ab754SHans Petter Selasky /*
1506f9cba8fSJoseph Mingrone  * Definitions to 1) indicate what version of libpcap first had a given
1516f9cba8fSJoseph Mingrone  * API and 2) allow upstream providers whose build environments allow
1526f9cba8fSJoseph Mingrone  * APIs to be designated as "first available in this release" to do so
1536f9cba8fSJoseph Mingrone  * by appropriately defining them.
1546f9cba8fSJoseph Mingrone  *
155*afdbf109SJoseph Mingrone  * On macOS, Apple can tweak this to make various APIs "weakly exported
156*afdbf109SJoseph Mingrone  * symbols" to make it easier for software that's distributed in binary
157*afdbf109SJoseph Mingrone  * form and that uses libpcap to run on multiple macOS versions and use
158*afdbf109SJoseph Mingrone  * new APIs when available.  (Yes, such third-party software exists -
159*afdbf109SJoseph Mingrone  * Wireshark provides binary packages for macOS, for example.  tcpdump
160*afdbf109SJoseph Mingrone  * doesn't count, as that's provided by Apple, so each release can
161*afdbf109SJoseph Mingrone  * come with a version compiled to use the APIs present in that release.)
1626f9cba8fSJoseph Mingrone  *
163*afdbf109SJoseph Mingrone  * We don't tweak it that way ourselves because, if you're building
164*afdbf109SJoseph Mingrone  * and installing libpcap on macOS yourself, the APIs will be available
1656f9cba8fSJoseph Mingrone  * no matter what OS version you're installing it on.
1666f9cba8fSJoseph Mingrone  *
1676f9cba8fSJoseph Mingrone  * For other platforms, we don't define them, leaving it up to
1686f9cba8fSJoseph Mingrone  * others to do so based on their OS versions, if appropriate.
1696f9cba8fSJoseph Mingrone  *
1706f9cba8fSJoseph Mingrone  * We start with libpcap 0.4, as that was the last LBL release, and
1716f9cba8fSJoseph Mingrone  * I've never seen earlier releases.
1726f9cba8fSJoseph Mingrone  */
1736f9cba8fSJoseph Mingrone #ifdef __APPLE__
1746f9cba8fSJoseph Mingrone /*
175*afdbf109SJoseph Mingrone  * Apple - insert #include <os/availability.h> here, and replace the two
176*afdbf109SJoseph Mingrone  * #defines below with:
1776f9cba8fSJoseph Mingrone  *
178*afdbf109SJoseph Mingrone  *   #define PCAP_API_AVAILABLE	API_AVAILABLE
179*afdbf109SJoseph Mingrone  *
180*afdbf109SJoseph Mingrone  * and adjust availabilities as necessary, including adding information
181*afdbf109SJoseph Mingrone  * about operating systems other than macOS.
1826f9cba8fSJoseph Mingrone  */
183*afdbf109SJoseph Mingrone #define PCAP_API_AVAILABLE(...)
184*afdbf109SJoseph Mingrone #define PCAP_AVAILABLE_0_4	PCAP_API_AVAILABLE(macos(10.0))
185*afdbf109SJoseph Mingrone #define PCAP_AVAILABLE_0_5	PCAP_API_AVAILABLE(macos(10.0))
186*afdbf109SJoseph Mingrone #define PCAP_AVAILABLE_0_6	PCAP_API_AVAILABLE(macos(10.1))
187*afdbf109SJoseph Mingrone #define PCAP_AVAILABLE_0_7	PCAP_API_AVAILABLE(macos(10.4))
188*afdbf109SJoseph Mingrone #define PCAP_AVAILABLE_0_8	PCAP_API_AVAILABLE(macos(10.4))
189*afdbf109SJoseph Mingrone #define PCAP_AVAILABLE_0_9	PCAP_API_AVAILABLE(macos(10.5))
190*afdbf109SJoseph Mingrone #define PCAP_AVAILABLE_1_0	PCAP_API_AVAILABLE(macos(10.6))
1916f9cba8fSJoseph Mingrone /* #define PCAP_AVAILABLE_1_1	no routines added to the API */
192*afdbf109SJoseph Mingrone #define PCAP_AVAILABLE_1_2	PCAP_API_AVAILABLE(macos(10.9))
1936f9cba8fSJoseph Mingrone /* #define PCAP_AVAILABLE_1_3	no routines added to the API */
1946f9cba8fSJoseph Mingrone /* #define PCAP_AVAILABLE_1_4	no routines added to the API */
195*afdbf109SJoseph Mingrone #define PCAP_AVAILABLE_1_5	PCAP_API_AVAILABLE(macos(10.10))
1966f9cba8fSJoseph Mingrone /* #define PCAP_AVAILABLE_1_6	no routines added to the API */
197*afdbf109SJoseph Mingrone #define PCAP_AVAILABLE_1_7	PCAP_API_AVAILABLE(macos(10.12))
198*afdbf109SJoseph Mingrone #define PCAP_AVAILABLE_1_8	PCAP_API_AVAILABLE(macos(10.13))
199*afdbf109SJoseph Mingrone #define PCAP_AVAILABLE_1_9	PCAP_API_AVAILABLE(macos(10.13))
200*afdbf109SJoseph Mingrone /*
201*afdbf109SJoseph Mingrone  * The remote capture APIs are, in 1.9 and 1.10, usually only
202*afdbf109SJoseph Mingrone  * available in the library if the library was built with
203*afdbf109SJoseph Mingrone  * remote capture enabled.
204*afdbf109SJoseph Mingrone  *
205*afdbf109SJoseph Mingrone  * However, macOS Sonoma provides stub versions of those routine,
206*afdbf109SJoseph Mingrone  * which return an error.  This means that we need a separate
207*afdbf109SJoseph Mingrone  * availability indicator macro for those routines, so that
208*afdbf109SJoseph Mingrone  * progras built on macOS Sonoma that attempt to use weak
209*afdbf109SJoseph Mingrone  * importing and availability tests to use those routines
210*afdbf109SJoseph Mingrone  * if they're available will get those routines weakly imported,
211*afdbf109SJoseph Mingrone  * so that if they're run on releases prior to Sonoma, they
212*afdbf109SJoseph Mingrone  * won't get an error from dyld about those routines being
213*afdbf109SJoseph Mingrone  * missing in libpcap.  (If they don't use run-time availability
214*afdbf109SJoseph Mingrone  * tests, they will, instead, get crashes if they call one of
215*afdbf109SJoseph Mingrone  * those routines, as the addresses of those routines will be
216*afdbf109SJoseph Mingrone  * set to 0 by dyld, meaning the program will dereference a
217*afdbf109SJoseph Mingrone  * null pointer and crash when trying to call them.)
218*afdbf109SJoseph Mingrone  *
219*afdbf109SJoseph Mingrone  * (Not that it's useful to use those routines *anyway*, as they're
220*afdbf109SJoseph Mingrone  * stubs that always fail.  The stubs were necessary in order to
221*afdbf109SJoseph Mingrone  * support weak exporting at all.)
222*afdbf109SJoseph Mingrone  */
223*afdbf109SJoseph Mingrone #define PCAP_AVAILABLE_1_9_REMOTE	PCAP_API_AVAILABLE(macos(14.0))
224*afdbf109SJoseph Mingrone #define PCAP_AVAILABLE_1_10	PCAP_API_AVAILABLE(macos(12.1))
225*afdbf109SJoseph Mingrone #define PCAP_AVAILABLE_1_10_REMOTE	PCAP_API_AVAILABLE(macos(14.0))
2266f9cba8fSJoseph Mingrone #define PCAP_AVAILABLE_1_11	/* not released yet, so not in macOS yet */
2276f9cba8fSJoseph Mingrone #else /* __APPLE__ */
2286f9cba8fSJoseph Mingrone #define PCAP_AVAILABLE_0_4
2296f9cba8fSJoseph Mingrone #define PCAP_AVAILABLE_0_5
2306f9cba8fSJoseph Mingrone #define PCAP_AVAILABLE_0_6
2316f9cba8fSJoseph Mingrone #define PCAP_AVAILABLE_0_7
2326f9cba8fSJoseph Mingrone #define PCAP_AVAILABLE_0_8
2336f9cba8fSJoseph Mingrone #define PCAP_AVAILABLE_0_9
2346f9cba8fSJoseph Mingrone #define PCAP_AVAILABLE_1_0
2356f9cba8fSJoseph Mingrone /* #define PCAP_AVAILABLE_1_1	no routines added to the API */
2366f9cba8fSJoseph Mingrone #define PCAP_AVAILABLE_1_2
2376f9cba8fSJoseph Mingrone /* #define PCAP_AVAILABLE_1_3	no routines added to the API */
2386f9cba8fSJoseph Mingrone /* #define PCAP_AVAILABLE_1_4	no routines added to the API */
2396f9cba8fSJoseph Mingrone #define PCAP_AVAILABLE_1_5
2406f9cba8fSJoseph Mingrone /* #define PCAP_AVAILABLE_1_6	no routines added to the API */
2416f9cba8fSJoseph Mingrone #define PCAP_AVAILABLE_1_7
2426f9cba8fSJoseph Mingrone #define PCAP_AVAILABLE_1_8
2436f9cba8fSJoseph Mingrone #define PCAP_AVAILABLE_1_9
244*afdbf109SJoseph Mingrone #define PCAP_AVAILABLE_1_9_REMOTE
2456f9cba8fSJoseph Mingrone #define PCAP_AVAILABLE_1_10
246*afdbf109SJoseph Mingrone #define PCAP_AVAILABLE_1_10_REMOTE
2476f9cba8fSJoseph Mingrone #define PCAP_AVAILABLE_1_11
2486f9cba8fSJoseph Mingrone #endif /* __APPLE__ */
2496f9cba8fSJoseph Mingrone 
2506f9cba8fSJoseph Mingrone /*
251b00ab754SHans Petter Selasky  * PCAP_NORETURN, before a function declaration, means "this function
252b00ab754SHans Petter Selasky  * never returns".  (It must go before the function declaration, e.g.
253b00ab754SHans Petter Selasky  * "extern PCAP_NORETURN func(...)" rather than after the function
254b00ab754SHans Petter Selasky  * declaration, as the MSVC version has to go before the declaration.)
255b00ab754SHans Petter Selasky  *
256b00ab754SHans Petter Selasky  * PCAP_NORETURN_DEF, before a function *definition*, means "this
257b00ab754SHans Petter Selasky  * function never returns"; it would be used only for static functions
258b00ab754SHans Petter Selasky  * that are defined before any use, and thus have no declaration.
259b00ab754SHans Petter Selasky  * (MSVC doesn't support that; I guess the "decl" in "__declspec"
260b00ab754SHans Petter Selasky  * means "declaration", and __declspec doesn't work with definitions.)
261b00ab754SHans Petter Selasky  */
262b00ab754SHans Petter Selasky #if __has_attribute(noreturn) \
263b00ab754SHans Petter Selasky     || PCAP_IS_AT_LEAST_GNUC_VERSION(2,5) \
264b00ab754SHans Petter Selasky     || PCAP_IS_AT_LEAST_SUNC_VERSION(5,9) \
265*afdbf109SJoseph Mingrone     || PCAP_IS_AT_LEAST_XL_C_VERSION(7,0) \
266*afdbf109SJoseph Mingrone     || PCAP_IS_AT_LEAST_HP_C_VERSION(6,10) \
267*afdbf109SJoseph Mingrone     || __TINYC__
268b00ab754SHans Petter Selasky   /*
2696f9cba8fSJoseph Mingrone    * Compiler with support for __attribute((noreturn)), or GCC 2.5 and
2706f9cba8fSJoseph Mingrone    * later, or some compiler asserting compatibility with GCC 2.5 and
271*afdbf109SJoseph Mingrone    * later, or Solaris Studio 12 (Sun C 5.9) and later, or IBM XL C 7.0
2726f9cba8fSJoseph Mingrone    * and later (do any earlier versions of XL C support this?), or HP aCC
273*afdbf109SJoseph Mingrone    * A.06.10 and later, or current TinyCC.
274b00ab754SHans Petter Selasky    */
275b00ab754SHans Petter Selasky   #define PCAP_NORETURN __attribute((noreturn))
276b00ab754SHans Petter Selasky   #define PCAP_NORETURN_DEF __attribute((noreturn))
277b00ab754SHans Petter Selasky #elif defined(_MSC_VER)
278b00ab754SHans Petter Selasky   /*
279b00ab754SHans Petter Selasky    * MSVC.
280b00ab754SHans Petter Selasky    */
281b00ab754SHans Petter Selasky   #define PCAP_NORETURN __declspec(noreturn)
282b00ab754SHans Petter Selasky   #define PCAP_NORETURN_DEF
283b00ab754SHans Petter Selasky #else
284b00ab754SHans Petter Selasky   #define PCAP_NORETURN
285b00ab754SHans Petter Selasky   #define PCAP_NORETURN_DEF
286b00ab754SHans Petter Selasky #endif
287b00ab754SHans Petter Selasky 
288b00ab754SHans Petter Selasky /*
289b00ab754SHans Petter Selasky  * PCAP_PRINTFLIKE(x,y), after a function declaration, means "this function
290b00ab754SHans Petter Selasky  * does printf-style formatting, with the xth argument being the format
291b00ab754SHans Petter Selasky  * string and the yth argument being the first argument for the format
292b00ab754SHans Petter Selasky  * string".
293b00ab754SHans Petter Selasky  */
294b00ab754SHans Petter Selasky #if __has_attribute(__format__) \
295b00ab754SHans Petter Selasky     || PCAP_IS_AT_LEAST_GNUC_VERSION(2,3) \
296*afdbf109SJoseph Mingrone     || PCAP_IS_AT_LEAST_XL_C_VERSION(7,0) \
297b00ab754SHans Petter Selasky     || PCAP_IS_AT_LEAST_HP_C_VERSION(6,10)
298b00ab754SHans Petter Selasky   /*
2996f9cba8fSJoseph Mingrone    * Compiler with support for it, or GCC 2.3 and later, or some compiler
300*afdbf109SJoseph Mingrone    * asserting compatibility with GCC 2.3 and later, or IBM XL C 7.0
301b00ab754SHans Petter Selasky    * and later (do any earlier versions of XL C support this?),
302b00ab754SHans Petter Selasky    * or HP aCC A.06.10 and later.
303b00ab754SHans Petter Selasky    */
304b00ab754SHans Petter Selasky   #define PCAP_PRINTFLIKE(x,y) __attribute__((__format__(__printf__,x,y)))
305b00ab754SHans Petter Selasky #else
306b00ab754SHans Petter Selasky   #define PCAP_PRINTFLIKE(x,y)
307b00ab754SHans Petter Selasky #endif
308b00ab754SHans Petter Selasky 
309b00ab754SHans Petter Selasky /*
310b00ab754SHans Petter Selasky  * PCAP_DEPRECATED(func, msg), after a function declaration, marks the
311b00ab754SHans Petter Selasky  * function as deprecated.
312b00ab754SHans Petter Selasky  *
3136f9cba8fSJoseph Mingrone  * The argument is a string giving the warning message to use if the
3146f9cba8fSJoseph Mingrone  * compiler supports that.
315b00ab754SHans Petter Selasky  */
316b00ab754SHans Petter Selasky #if __has_attribute(deprecated) \
317b00ab754SHans Petter Selasky     || PCAP_IS_AT_LEAST_GNUC_VERSION(4,5) \
318b00ab754SHans Petter Selasky     || PCAP_IS_AT_LEAST_SUNC_VERSION(5,13)
319b00ab754SHans Petter Selasky   /*
320b00ab754SHans Petter Selasky    * Compiler that supports __has_attribute and __attribute__((deprecated)),
3216f9cba8fSJoseph Mingrone    * or GCC 4.5 and later, or Sun/Oracle C 12.4 (Sun C 5.13) and later.
322b00ab754SHans Petter Selasky    *
323b00ab754SHans Petter Selasky    * Those support __attribute__((deprecated(msg))) (we assume, perhaps
324b00ab754SHans Petter Selasky    * incorrectly, that anything that supports __has_attribute() is
325b00ab754SHans Petter Selasky    * recent enough to support __attribute__((deprecated(msg)))).
326b00ab754SHans Petter Selasky    */
3276f9cba8fSJoseph Mingrone   #define PCAP_DEPRECATED(msg)	__attribute__((deprecated(msg)))
328b00ab754SHans Petter Selasky #elif PCAP_IS_AT_LEAST_GNUC_VERSION(3,1)
329b00ab754SHans Petter Selasky   /*
330b00ab754SHans Petter Selasky    * GCC 3.1 through 4.4.
331b00ab754SHans Petter Selasky    *
332b00ab754SHans Petter Selasky    * Those support __attribute__((deprecated)) but not
333b00ab754SHans Petter Selasky    * __attribute__((deprecated(msg))).
334b00ab754SHans Petter Selasky    */
3356f9cba8fSJoseph Mingrone   #define PCAP_DEPRECATED(msg)	__attribute__((deprecated))
3366f9cba8fSJoseph Mingrone #elif defined(_MSC_VER) && !defined(BUILDING_PCAP)
337b00ab754SHans Petter Selasky   /*
3386f9cba8fSJoseph Mingrone    * MSVC, and we're not building libpcap itself; it's VS 2015
3396f9cba8fSJoseph Mingrone    * and later, so we have __declspec(deprecated(...)).
340b00ab754SHans Petter Selasky    *
341b00ab754SHans Petter Selasky    * If we *are* building libpcap, we don't want this, as it'll warn
342b00ab754SHans Petter Selasky    * us even if we *define* the function.
343b00ab754SHans Petter Selasky    */
3446f9cba8fSJoseph Mingrone   #define PCAP_DEPRECATED(msg)	_declspec(deprecated(msg))
345b00ab754SHans Petter Selasky #else
3466f9cba8fSJoseph Mingrone   #define PCAP_DEPRECATED(msg)
347b00ab754SHans Petter Selasky #endif
348b00ab754SHans Petter Selasky 
349b00ab754SHans Petter Selasky /*
350b00ab754SHans Petter Selasky  * For flagging arguments as format strings in MSVC.
351b00ab754SHans Petter Selasky  */
352b00ab754SHans Petter Selasky #ifdef _MSC_VER
353b00ab754SHans Petter Selasky  #include <sal.h>
354b00ab754SHans Petter Selasky  #define PCAP_FORMAT_STRING(p) _Printf_format_string_ p
355b00ab754SHans Petter Selasky #else
356b00ab754SHans Petter Selasky  #define PCAP_FORMAT_STRING(p) p
357b00ab754SHans Petter Selasky #endif
358b00ab754SHans Petter Selasky 
359b00ab754SHans Petter Selasky #endif /* lib_pcap_funcattrs_h */
360