1*8b26181fSAndroid Build Coastguard Worker /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */ 2*8b26181fSAndroid Build Coastguard Worker /* 3*8b26181fSAndroid Build Coastguard Worker * Copyright (c) 1993, 1994, 1995, 1996, 1997 4*8b26181fSAndroid Build Coastguard Worker * The Regents of the University of California. All rights reserved. 5*8b26181fSAndroid Build Coastguard Worker * 6*8b26181fSAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without 7*8b26181fSAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions 8*8b26181fSAndroid Build Coastguard Worker * are met: 9*8b26181fSAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright 10*8b26181fSAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer. 11*8b26181fSAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright 12*8b26181fSAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer in the 13*8b26181fSAndroid Build Coastguard Worker * documentation and/or other materials provided with the distribution. 14*8b26181fSAndroid Build Coastguard Worker * 3. All advertising materials mentioning features or use of this software 15*8b26181fSAndroid Build Coastguard Worker * must display the following acknowledgement: 16*8b26181fSAndroid Build Coastguard Worker * This product includes software developed by the Computer Systems 17*8b26181fSAndroid Build Coastguard Worker * Engineering Group at Lawrence Berkeley Laboratory. 18*8b26181fSAndroid Build Coastguard Worker * 4. Neither the name of the University nor of the Laboratory may be used 19*8b26181fSAndroid Build Coastguard Worker * to endorse or promote products derived from this software without 20*8b26181fSAndroid Build Coastguard Worker * specific prior written permission. 21*8b26181fSAndroid Build Coastguard Worker * 22*8b26181fSAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23*8b26181fSAndroid Build Coastguard Worker * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24*8b26181fSAndroid Build Coastguard Worker * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25*8b26181fSAndroid Build Coastguard Worker * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26*8b26181fSAndroid Build Coastguard Worker * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27*8b26181fSAndroid Build Coastguard Worker * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28*8b26181fSAndroid Build Coastguard Worker * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29*8b26181fSAndroid Build Coastguard Worker * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30*8b26181fSAndroid Build Coastguard Worker * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31*8b26181fSAndroid Build Coastguard Worker * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*8b26181fSAndroid Build Coastguard Worker * SUCH DAMAGE. 33*8b26181fSAndroid Build Coastguard Worker */ 34*8b26181fSAndroid Build Coastguard Worker 35*8b26181fSAndroid Build Coastguard Worker #ifndef lib_pcap_funcattrs_h 36*8b26181fSAndroid Build Coastguard Worker #define lib_pcap_funcattrs_h 37*8b26181fSAndroid Build Coastguard Worker 38*8b26181fSAndroid Build Coastguard Worker #include <pcap/compiler-tests.h> 39*8b26181fSAndroid Build Coastguard Worker 40*8b26181fSAndroid Build Coastguard Worker /* 41*8b26181fSAndroid Build Coastguard Worker * Attributes to apply to functions and their arguments, using various 42*8b26181fSAndroid Build Coastguard Worker * compiler-specific extensions. 43*8b26181fSAndroid Build Coastguard Worker */ 44*8b26181fSAndroid Build Coastguard Worker 45*8b26181fSAndroid Build Coastguard Worker /* 46*8b26181fSAndroid Build Coastguard Worker * PCAP_API_DEF must be used when defining *data* exported from 47*8b26181fSAndroid Build Coastguard Worker * libpcap. It can be used when defining *functions* exported 48*8b26181fSAndroid Build Coastguard Worker * from libpcap, but it doesn't have to be used there. It 49*8b26181fSAndroid Build Coastguard Worker * should not be used in declarations in headers. 50*8b26181fSAndroid Build Coastguard Worker * 51*8b26181fSAndroid Build Coastguard Worker * PCAP_API must be used when *declaring* data or functions 52*8b26181fSAndroid Build Coastguard Worker * exported from libpcap; PCAP_API_DEF won't work on all platforms. 53*8b26181fSAndroid Build Coastguard Worker */ 54*8b26181fSAndroid Build Coastguard Worker 55*8b26181fSAndroid Build Coastguard Worker #if defined(_WIN32) 56*8b26181fSAndroid Build Coastguard Worker /* 57*8b26181fSAndroid Build Coastguard Worker * For Windows: 58*8b26181fSAndroid Build Coastguard Worker * 59*8b26181fSAndroid Build Coastguard Worker * when building libpcap: 60*8b26181fSAndroid Build Coastguard Worker * 61*8b26181fSAndroid Build Coastguard Worker * if we're building it as a DLL, we have to declare API 62*8b26181fSAndroid Build Coastguard Worker * functions with __declspec(dllexport); 63*8b26181fSAndroid Build Coastguard Worker * 64*8b26181fSAndroid Build Coastguard Worker * if we're building it as a static library, we don't want 65*8b26181fSAndroid Build Coastguard Worker * to do so. 66*8b26181fSAndroid Build Coastguard Worker * 67*8b26181fSAndroid Build Coastguard Worker * when using libpcap: 68*8b26181fSAndroid Build Coastguard Worker * 69*8b26181fSAndroid Build Coastguard Worker * if we're using the DLL, calls to its functions are a 70*8b26181fSAndroid Build Coastguard Worker * little more efficient if they're declared with 71*8b26181fSAndroid Build Coastguard Worker * __declspec(dllimport); 72*8b26181fSAndroid Build Coastguard Worker * 73*8b26181fSAndroid Build Coastguard Worker * if we're not using the dll, we don't want to declare 74*8b26181fSAndroid Build Coastguard Worker * them that way. 75*8b26181fSAndroid Build Coastguard Worker * 76*8b26181fSAndroid Build Coastguard Worker * So: 77*8b26181fSAndroid Build Coastguard Worker * 78*8b26181fSAndroid Build Coastguard Worker * if pcap_EXPORTS is defined, we define PCAP_API_DEF as 79*8b26181fSAndroid Build Coastguard Worker * __declspec(dllexport); 80*8b26181fSAndroid Build Coastguard Worker * 81*8b26181fSAndroid Build Coastguard Worker * if PCAP_DLL is defined, we define PCAP_API_DEF as 82*8b26181fSAndroid Build Coastguard Worker * __declspec(dllimport); 83*8b26181fSAndroid Build Coastguard Worker * 84*8b26181fSAndroid Build Coastguard Worker * otherwise, we define PCAP_API_DEF as nothing. 85*8b26181fSAndroid Build Coastguard Worker */ 86*8b26181fSAndroid Build Coastguard Worker #if defined(pcap_EXPORTS) 87*8b26181fSAndroid Build Coastguard Worker /* 88*8b26181fSAndroid Build Coastguard Worker * We're compiling libpcap as a DLL, so we should export functions 89*8b26181fSAndroid Build Coastguard Worker * in our API. 90*8b26181fSAndroid Build Coastguard Worker */ 91*8b26181fSAndroid Build Coastguard Worker #define PCAP_API_DEF __declspec(dllexport) 92*8b26181fSAndroid Build Coastguard Worker #elif defined(PCAP_DLL) 93*8b26181fSAndroid Build Coastguard Worker /* 94*8b26181fSAndroid Build Coastguard Worker * We're using libpcap as a DLL, so the calls will be a little more 95*8b26181fSAndroid Build Coastguard Worker * efficient if we explicitly import the functions. 96*8b26181fSAndroid Build Coastguard Worker */ 97*8b26181fSAndroid Build Coastguard Worker #define PCAP_API_DEF __declspec(dllimport) 98*8b26181fSAndroid Build Coastguard Worker #else 99*8b26181fSAndroid Build Coastguard Worker /* 100*8b26181fSAndroid Build Coastguard Worker * Either we're building libpcap as a static library, or we're using 101*8b26181fSAndroid Build Coastguard Worker * it as a static library, or we don't know for certain that we're 102*8b26181fSAndroid Build Coastguard Worker * using it as a dynamic library, so neither import nor export the 103*8b26181fSAndroid Build Coastguard Worker * functions explicitly. 104*8b26181fSAndroid Build Coastguard Worker */ 105*8b26181fSAndroid Build Coastguard Worker #define PCAP_API_DEF 106*8b26181fSAndroid Build Coastguard Worker #endif 107*8b26181fSAndroid Build Coastguard Worker #elif defined(MSDOS) 108*8b26181fSAndroid Build Coastguard Worker /* XXX - does this need special treatment? */ 109*8b26181fSAndroid Build Coastguard Worker #define PCAP_API_DEF 110*8b26181fSAndroid Build Coastguard Worker #else /* UN*X */ 111*8b26181fSAndroid Build Coastguard Worker #ifdef pcap_EXPORTS 112*8b26181fSAndroid Build Coastguard Worker /* 113*8b26181fSAndroid Build Coastguard Worker * We're compiling libpcap as a (dynamic) shared library, so we should 114*8b26181fSAndroid Build Coastguard Worker * export functions in our API. The compiler might be configured not 115*8b26181fSAndroid Build Coastguard Worker * to export functions from a shared library by default, so we might 116*8b26181fSAndroid Build Coastguard Worker * have to explicitly mark functions as exported. 117*8b26181fSAndroid Build Coastguard Worker */ 118*8b26181fSAndroid Build Coastguard Worker #if PCAP_IS_AT_LEAST_GNUC_VERSION(3,4) \ 119*8b26181fSAndroid Build Coastguard Worker || PCAP_IS_AT_LEAST_XL_C_VERSION(12,0) 120*8b26181fSAndroid Build Coastguard Worker /* 121*8b26181fSAndroid Build Coastguard Worker * GCC 3.4 and later, or some compiler asserting compatibility with 122*8b26181fSAndroid Build Coastguard Worker * GCC 3.4 and later, or XL C 13.0 and later, so we have 123*8b26181fSAndroid Build Coastguard Worker * __attribute__((visibility()). 124*8b26181fSAndroid Build Coastguard Worker */ 125*8b26181fSAndroid Build Coastguard Worker #define PCAP_API_DEF __attribute__((visibility("default"))) 126*8b26181fSAndroid Build Coastguard Worker #elif PCAP_IS_AT_LEAST_SUNC_VERSION(5,5) 127*8b26181fSAndroid Build Coastguard Worker /* 128*8b26181fSAndroid Build Coastguard Worker * Sun C 5.5 and later, so we have __global. 129*8b26181fSAndroid Build Coastguard Worker * (Sun C 5.9 and later also have __attribute__((visibility()), 130*8b26181fSAndroid Build Coastguard Worker * but there's no reason to prefer it with Sun C.) 131*8b26181fSAndroid Build Coastguard Worker */ 132*8b26181fSAndroid Build Coastguard Worker #define PCAP_API_DEF __global 133*8b26181fSAndroid Build Coastguard Worker #else 134*8b26181fSAndroid Build Coastguard Worker /* 135*8b26181fSAndroid Build Coastguard Worker * We don't have anything to say. 136*8b26181fSAndroid Build Coastguard Worker */ 137*8b26181fSAndroid Build Coastguard Worker #define PCAP_API_DEF 138*8b26181fSAndroid Build Coastguard Worker #endif 139*8b26181fSAndroid Build Coastguard Worker #else 140*8b26181fSAndroid Build Coastguard Worker /* 141*8b26181fSAndroid Build Coastguard Worker * We're not building libpcap. 142*8b26181fSAndroid Build Coastguard Worker */ 143*8b26181fSAndroid Build Coastguard Worker #define PCAP_API_DEF 144*8b26181fSAndroid Build Coastguard Worker #endif 145*8b26181fSAndroid Build Coastguard Worker #endif /* _WIN32/MSDOS/UN*X */ 146*8b26181fSAndroid Build Coastguard Worker 147*8b26181fSAndroid Build Coastguard Worker #define PCAP_API PCAP_API_DEF extern 148*8b26181fSAndroid Build Coastguard Worker 149*8b26181fSAndroid Build Coastguard Worker /* 150*8b26181fSAndroid Build Coastguard Worker * Definitions to 1) indicate what version of libpcap first had a given 151*8b26181fSAndroid Build Coastguard Worker * API and 2) allow upstream providers whose build environments allow 152*8b26181fSAndroid Build Coastguard Worker * APIs to be designated as "first available in this release" to do so 153*8b26181fSAndroid Build Coastguard Worker * by appropriately defining them. 154*8b26181fSAndroid Build Coastguard Worker * 155*8b26181fSAndroid Build Coastguard Worker * Yes, that's you, Apple. :-) Please define PCAP_AVAILABLE_MACOS() 156*8b26181fSAndroid Build Coastguard Worker * as necessary to make various APIs "weak exports" to make it easier 157*8b26181fSAndroid Build Coastguard Worker * for software that's distributed in binary form and that uses libpcap 158*8b26181fSAndroid Build Coastguard Worker * to run on multiple macOS versions and use new APIs when available. 159*8b26181fSAndroid Build Coastguard Worker * (Yes, such third-party software exists - Wireshark provides binary 160*8b26181fSAndroid Build Coastguard Worker * packages for macOS, for example. tcpdump doesn't count, as that's 161*8b26181fSAndroid Build Coastguard Worker * provided by Apple, so each release can come with a version compiled 162*8b26181fSAndroid Build Coastguard Worker * to use the APIs present in that release.) 163*8b26181fSAndroid Build Coastguard Worker * 164*8b26181fSAndroid Build Coastguard Worker * The non-macOS versioning is based on 165*8b26181fSAndroid Build Coastguard Worker * 166*8b26181fSAndroid Build Coastguard Worker * https://en.wikipedia.org/wiki/Darwin_(operating_system)#Release_history 167*8b26181fSAndroid Build Coastguard Worker * 168*8b26181fSAndroid Build Coastguard Worker * If there are any corrections, please submit it upstream to the 169*8b26181fSAndroid Build Coastguard Worker * libpcap maintainers, preferably as a pull request on 170*8b26181fSAndroid Build Coastguard Worker * 171*8b26181fSAndroid Build Coastguard Worker * https://github.com/the-tcpdump-group/libpcap 172*8b26181fSAndroid Build Coastguard Worker * 173*8b26181fSAndroid Build Coastguard Worker * We don't define it ourselves because, if you're building and 174*8b26181fSAndroid Build Coastguard Worker * installing libpcap on macOS yourself, the APIs will be available 175*8b26181fSAndroid Build Coastguard Worker * no matter what OS version you're installing it on. 176*8b26181fSAndroid Build Coastguard Worker * 177*8b26181fSAndroid Build Coastguard Worker * For other platforms, we don't define them, leaving it up to 178*8b26181fSAndroid Build Coastguard Worker * others to do so based on their OS versions, if appropriate. 179*8b26181fSAndroid Build Coastguard Worker * 180*8b26181fSAndroid Build Coastguard Worker * We start with libpcap 0.4, as that was the last LBL release, and 181*8b26181fSAndroid Build Coastguard Worker * I've never seen earlier releases. 182*8b26181fSAndroid Build Coastguard Worker */ 183*8b26181fSAndroid Build Coastguard Worker #ifdef __APPLE__ 184*8b26181fSAndroid Build Coastguard Worker #include <Availability.h> 185*8b26181fSAndroid Build Coastguard Worker /* 186*8b26181fSAndroid Build Coastguard Worker * When building as part of macOS, define this as __API_AVAILABLE(__VA_ARGS__). 187*8b26181fSAndroid Build Coastguard Worker * 188*8b26181fSAndroid Build Coastguard Worker * XXX - if there's some #define to indicate that this is being built 189*8b26181fSAndroid Build Coastguard Worker * as part of the macOS build process, we could make that Just Work. 190*8b26181fSAndroid Build Coastguard Worker */ 191*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE(...) 192*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_0_4 PCAP_AVAILABLE(macos(10.0)) /* Did any version of Mac OS X ship with this? */ 193*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_0_5 PCAP_AVAILABLE(macos(10.0)) /* Did any version of Mac OS X ship with this? */ 194*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_0_6 PCAP_AVAILABLE(macos(10.1)) 195*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_0_7 PCAP_AVAILABLE(macos(10.4)) 196*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_0_8 PCAP_AVAILABLE(macos(10.4)) 197*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_0_9 PCAP_AVAILABLE(macos(10.5), ios(1.0)) 198*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_1_0 PCAP_AVAILABLE(macos(10.6), ios(4.0)) 199*8b26181fSAndroid Build Coastguard Worker /* #define PCAP_AVAILABLE_1_1 no routines added to the API */ 200*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_1_2 PCAP_AVAILABLE(macos(10.9), ios(6.0)) 201*8b26181fSAndroid Build Coastguard Worker /* #define PCAP_AVAILABLE_1_3 no routines added to the API */ 202*8b26181fSAndroid Build Coastguard Worker /* #define PCAP_AVAILABLE_1_4 no routines added to the API */ 203*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_1_5 PCAP_AVAILABLE(macos(10.10), ios(7.0), watchos(1.0)) 204*8b26181fSAndroid Build Coastguard Worker /* #define PCAP_AVAILABLE_1_6 no routines added to the API */ 205*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_1_7 PCAP_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0)) 206*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_1_8 PCAP_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0)) /* only Windows adds routines to the API; XXX - what version first had it? */ 207*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_1_9 PCAP_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0)) 208*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_1_10 /* not in macOS yet */ 209*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_1_11 /* not released yet, so not in macOS yet */ 210*8b26181fSAndroid Build Coastguard Worker #else /* __APPLE__ */ 211*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_0_4 212*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_0_5 213*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_0_6 214*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_0_7 215*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_0_8 216*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_0_9 217*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_1_0 218*8b26181fSAndroid Build Coastguard Worker /* #define PCAP_AVAILABLE_1_1 no routines added to the API */ 219*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_1_2 220*8b26181fSAndroid Build Coastguard Worker /* #define PCAP_AVAILABLE_1_3 no routines added to the API */ 221*8b26181fSAndroid Build Coastguard Worker /* #define PCAP_AVAILABLE_1_4 no routines added to the API */ 222*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_1_5 223*8b26181fSAndroid Build Coastguard Worker /* #define PCAP_AVAILABLE_1_6 no routines added to the API */ 224*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_1_7 225*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_1_8 226*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_1_9 227*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_1_10 228*8b26181fSAndroid Build Coastguard Worker #define PCAP_AVAILABLE_1_11 229*8b26181fSAndroid Build Coastguard Worker #endif /* __APPLE__ */ 230*8b26181fSAndroid Build Coastguard Worker 231*8b26181fSAndroid Build Coastguard Worker /* 232*8b26181fSAndroid Build Coastguard Worker * PCAP_NORETURN, before a function declaration, means "this function 233*8b26181fSAndroid Build Coastguard Worker * never returns". (It must go before the function declaration, e.g. 234*8b26181fSAndroid Build Coastguard Worker * "extern PCAP_NORETURN func(...)" rather than after the function 235*8b26181fSAndroid Build Coastguard Worker * declaration, as the MSVC version has to go before the declaration.) 236*8b26181fSAndroid Build Coastguard Worker * 237*8b26181fSAndroid Build Coastguard Worker * PCAP_NORETURN_DEF, before a function *definition*, means "this 238*8b26181fSAndroid Build Coastguard Worker * function never returns"; it would be used only for static functions 239*8b26181fSAndroid Build Coastguard Worker * that are defined before any use, and thus have no declaration. 240*8b26181fSAndroid Build Coastguard Worker * (MSVC doesn't support that; I guess the "decl" in "__declspec" 241*8b26181fSAndroid Build Coastguard Worker * means "declaration", and __declspec doesn't work with definitions.) 242*8b26181fSAndroid Build Coastguard Worker */ 243*8b26181fSAndroid Build Coastguard Worker #if __has_attribute(noreturn) \ 244*8b26181fSAndroid Build Coastguard Worker || PCAP_IS_AT_LEAST_GNUC_VERSION(2,5) \ 245*8b26181fSAndroid Build Coastguard Worker || PCAP_IS_AT_LEAST_SUNC_VERSION(5,9) \ 246*8b26181fSAndroid Build Coastguard Worker || PCAP_IS_AT_LEAST_XL_C_VERSION(10,1) \ 247*8b26181fSAndroid Build Coastguard Worker || PCAP_IS_AT_LEAST_HP_C_VERSION(6,10) 248*8b26181fSAndroid Build Coastguard Worker /* 249*8b26181fSAndroid Build Coastguard Worker * Compiler with support for __attribute((noreturn)), or GCC 2.5 and 250*8b26181fSAndroid Build Coastguard Worker * later, or some compiler asserting compatibility with GCC 2.5 and 251*8b26181fSAndroid Build Coastguard Worker * later, or Solaris Studio 12 (Sun C 5.9) and later, or IBM XL C 10.1 252*8b26181fSAndroid Build Coastguard Worker * and later (do any earlier versions of XL C support this?), or HP aCC 253*8b26181fSAndroid Build Coastguard Worker * A.06.10 and later. 254*8b26181fSAndroid Build Coastguard Worker */ 255*8b26181fSAndroid Build Coastguard Worker #define PCAP_NORETURN __attribute((noreturn)) 256*8b26181fSAndroid Build Coastguard Worker #define PCAP_NORETURN_DEF __attribute((noreturn)) 257*8b26181fSAndroid Build Coastguard Worker #elif defined(_MSC_VER) 258*8b26181fSAndroid Build Coastguard Worker /* 259*8b26181fSAndroid Build Coastguard Worker * MSVC. 260*8b26181fSAndroid Build Coastguard Worker */ 261*8b26181fSAndroid Build Coastguard Worker #define PCAP_NORETURN __declspec(noreturn) 262*8b26181fSAndroid Build Coastguard Worker #define PCAP_NORETURN_DEF 263*8b26181fSAndroid Build Coastguard Worker #else 264*8b26181fSAndroid Build Coastguard Worker #define PCAP_NORETURN 265*8b26181fSAndroid Build Coastguard Worker #define PCAP_NORETURN_DEF 266*8b26181fSAndroid Build Coastguard Worker #endif 267*8b26181fSAndroid Build Coastguard Worker 268*8b26181fSAndroid Build Coastguard Worker /* 269*8b26181fSAndroid Build Coastguard Worker * PCAP_PRINTFLIKE(x,y), after a function declaration, means "this function 270*8b26181fSAndroid Build Coastguard Worker * does printf-style formatting, with the xth argument being the format 271*8b26181fSAndroid Build Coastguard Worker * string and the yth argument being the first argument for the format 272*8b26181fSAndroid Build Coastguard Worker * string". 273*8b26181fSAndroid Build Coastguard Worker */ 274*8b26181fSAndroid Build Coastguard Worker #if __has_attribute(__format__) \ 275*8b26181fSAndroid Build Coastguard Worker || PCAP_IS_AT_LEAST_GNUC_VERSION(2,3) \ 276*8b26181fSAndroid Build Coastguard Worker || PCAP_IS_AT_LEAST_XL_C_VERSION(10,1) \ 277*8b26181fSAndroid Build Coastguard Worker || PCAP_IS_AT_LEAST_HP_C_VERSION(6,10) 278*8b26181fSAndroid Build Coastguard Worker /* 279*8b26181fSAndroid Build Coastguard Worker * Compiler with support for it, or GCC 2.3 and later, or some compiler 280*8b26181fSAndroid Build Coastguard Worker * asserting compatibility with GCC 2.3 and later, or IBM XL C 10.1 281*8b26181fSAndroid Build Coastguard Worker * and later (do any earlier versions of XL C support this?), 282*8b26181fSAndroid Build Coastguard Worker * or HP aCC A.06.10 and later. 283*8b26181fSAndroid Build Coastguard Worker */ 284*8b26181fSAndroid Build Coastguard Worker #define PCAP_PRINTFLIKE(x,y) __attribute__((__format__(__printf__,x,y))) 285*8b26181fSAndroid Build Coastguard Worker #else 286*8b26181fSAndroid Build Coastguard Worker #define PCAP_PRINTFLIKE(x,y) 287*8b26181fSAndroid Build Coastguard Worker #endif 288*8b26181fSAndroid Build Coastguard Worker 289*8b26181fSAndroid Build Coastguard Worker /* 290*8b26181fSAndroid Build Coastguard Worker * PCAP_DEPRECATED(func, msg), after a function declaration, marks the 291*8b26181fSAndroid Build Coastguard Worker * function as deprecated. 292*8b26181fSAndroid Build Coastguard Worker * 293*8b26181fSAndroid Build Coastguard Worker * The argument is a string giving the warning message to use if the 294*8b26181fSAndroid Build Coastguard Worker * compiler supports that. 295*8b26181fSAndroid Build Coastguard Worker */ 296*8b26181fSAndroid Build Coastguard Worker #if __has_attribute(deprecated) \ 297*8b26181fSAndroid Build Coastguard Worker || PCAP_IS_AT_LEAST_GNUC_VERSION(4,5) \ 298*8b26181fSAndroid Build Coastguard Worker || PCAP_IS_AT_LEAST_SUNC_VERSION(5,13) 299*8b26181fSAndroid Build Coastguard Worker /* 300*8b26181fSAndroid Build Coastguard Worker * Compiler that supports __has_attribute and __attribute__((deprecated)), 301*8b26181fSAndroid Build Coastguard Worker * or GCC 4.5 and later, or Sun/Oracle C 12.4 (Sun C 5.13) and later. 302*8b26181fSAndroid Build Coastguard Worker * 303*8b26181fSAndroid Build Coastguard Worker * Those support __attribute__((deprecated(msg))) (we assume, perhaps 304*8b26181fSAndroid Build Coastguard Worker * incorrectly, that anything that supports __has_attribute() is 305*8b26181fSAndroid Build Coastguard Worker * recent enough to support __attribute__((deprecated(msg)))). 306*8b26181fSAndroid Build Coastguard Worker */ 307*8b26181fSAndroid Build Coastguard Worker #define PCAP_DEPRECATED(msg) __attribute__((deprecated(msg))) 308*8b26181fSAndroid Build Coastguard Worker #elif PCAP_IS_AT_LEAST_GNUC_VERSION(3,1) 309*8b26181fSAndroid Build Coastguard Worker /* 310*8b26181fSAndroid Build Coastguard Worker * GCC 3.1 through 4.4. 311*8b26181fSAndroid Build Coastguard Worker * 312*8b26181fSAndroid Build Coastguard Worker * Those support __attribute__((deprecated)) but not 313*8b26181fSAndroid Build Coastguard Worker * __attribute__((deprecated(msg))). 314*8b26181fSAndroid Build Coastguard Worker */ 315*8b26181fSAndroid Build Coastguard Worker #define PCAP_DEPRECATED(msg) __attribute__((deprecated)) 316*8b26181fSAndroid Build Coastguard Worker #elif defined(_MSC_VER) && !defined(BUILDING_PCAP) 317*8b26181fSAndroid Build Coastguard Worker /* 318*8b26181fSAndroid Build Coastguard Worker * MSVC, and we're not building libpcap itself; it's VS 2015 319*8b26181fSAndroid Build Coastguard Worker * and later, so we have __declspec(deprecated(...)). 320*8b26181fSAndroid Build Coastguard Worker * 321*8b26181fSAndroid Build Coastguard Worker * If we *are* building libpcap, we don't want this, as it'll warn 322*8b26181fSAndroid Build Coastguard Worker * us even if we *define* the function. 323*8b26181fSAndroid Build Coastguard Worker */ 324*8b26181fSAndroid Build Coastguard Worker #define PCAP_DEPRECATED(msg) _declspec(deprecated(msg)) 325*8b26181fSAndroid Build Coastguard Worker #else 326*8b26181fSAndroid Build Coastguard Worker #define PCAP_DEPRECATED(msg) 327*8b26181fSAndroid Build Coastguard Worker #endif 328*8b26181fSAndroid Build Coastguard Worker 329*8b26181fSAndroid Build Coastguard Worker /* 330*8b26181fSAndroid Build Coastguard Worker * For flagging arguments as format strings in MSVC. 331*8b26181fSAndroid Build Coastguard Worker */ 332*8b26181fSAndroid Build Coastguard Worker #ifdef _MSC_VER 333*8b26181fSAndroid Build Coastguard Worker #include <sal.h> 334*8b26181fSAndroid Build Coastguard Worker #define PCAP_FORMAT_STRING(p) _Printf_format_string_ p 335*8b26181fSAndroid Build Coastguard Worker #else 336*8b26181fSAndroid Build Coastguard Worker #define PCAP_FORMAT_STRING(p) p 337*8b26181fSAndroid Build Coastguard Worker #endif 338*8b26181fSAndroid Build Coastguard Worker 339*8b26181fSAndroid Build Coastguard Worker #endif /* lib_pcap_funcattrs_h */ 340