]> The Tcpdump Group git mirrors - libpcap/commitdiff
Suppress warnings about the deprecation of gethostbyname().
authorGuy Harris <[email protected]>
Sat, 15 Sep 2018 03:07:13 +0000 (20:07 -0700)
committerGuy Harris <[email protected]>
Sat, 15 Sep 2018 03:07:13 +0000 (20:07 -0700)
Yes, we know, we shouldn't use it.  We only use it to provide a routine
that we've exported for a long time (and thus can't necessarily remove),
and which *we* now deprecate.

diag-control.h
nametoaddr.c
pcap/namedb.h

index cb5dfef84515a694a3ef84fbf7c4d3b00d2b2160..55d0da80c15d2b93dbc9b4ba17ee577ed808c386 100644 (file)
@@ -64,7 +64,8 @@
     __pragma(warning(disable:4242)) \
     __pragma(warning(disable:4244)) \
     __pragma(warning(disable:4702))
-  #define DIAG_ON_FLEX  __pragma(warning(pop))
+  #define DIAG_ON_FLEX \
+    __pragma(warning(pop))
 
   /*
    * Suppress narrowing warnings.
   #define DIAG_OFF_NARROWING \
     __pragma(warning(push)) \
     __pragma(warning(disable:4242))
-  #define DIAG_ON_NARROWING  __pragma(warning(pop))
+  #define DIAG_ON_NARROWING \
+    __pragma(warning(pop))
+
+  /*
+   * Suppress deprecation warnings.
+   */
+  #define DIAG_OFF_DEPRECATION \
+    __pragma(warning(push)) \
+    __pragma(warning(disable:4996))
+  #define DIAG_ON_DEPRECATION \
+    __pragma(warning(pop))
 #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
   /*
    * This is Clang 2.8 or later; we can use "clang diagnostic
 
   #define DIAG_ON_NARROWING \
     PCAP_DO_PRAGMA(clang diagnostic pop)
+
+  /*
+   * Suppress deprecation warnings.
+   */
+  #define DIAG_OFF_DEPRECATION \
+    PCAP_DO_PRAGMA(clang diagnostic push) \
+    PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdeprecated-declarations")
+  #define DIAG_ON_DEPRECATION \
+    PCAP_DO_PRAGMA(clang diagnostic pop)
 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
   /*
    * This is GCC 4.6 or later, or a compiler claiming to be that.
    */
   #define DIAG_OFF_NARROWING
   #define DIAG_ON_NARROWING
+
+  /*
+   * Suppress deprecation warnings.
+   */
+  #define DIAG_OFF_DEPRECATION \
+    PCAP_DO_PRAGMA(GCC diagnostic push) \
+    PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
+  #define DIAG_ON_DEPRECATION \
+    PCAP_DO_PRAGMA(GCC diagnostic pop)
 #else
   /*
    * Neither Visual Studio, nor Clang 2.8 or later, nor GCC 4.6 or later
   #define DIAG_ON_FLEX
   #define DIAG_OFF_NARROWING
   #define DIAG_ON_NARROWING
+  #define DIAG_OFF_DEPRECATION
+  #define DIAG_ON_DEPRECATION
 #endif
 
 #ifdef YYBYACC
index 194ff45b7588378b16d8eb4352687e1db4fa3768..7d65198ee3d04a19fdc2a91b5a94f8597844923c 100644 (file)
 
 #include "pcap-int.h"
 
+#include "diag-control.h"
+
 #include "gencode.h"
 #include <pcap/namedb.h>
 #include "nametoaddr.h"
@@ -162,7 +164,23 @@ pcap_nametoaddr(const char *name)
        bpf_u_int32 **p;
        struct hostent *hp;
 
+       /*
+        * gethostbyname() is deprecated on Windows, perhaps because
+        * it's not thread-safe, or because it doesn't support IPv6,
+        * or both.
+        *
+        * We deprecate pcap_nametoaddr() on all platforms because
+        * it's not thread-safe; we supply it for backwards compatibility,
+        * so suppress the deprecation warning.  We could, I guess,
+        * use getaddrinfo() and construct the array ourselves, but
+        * that's probably not worth the effort, as that wouldn't make
+        * this thread-safe - we can't change the API to require that
+        * our caller free the address array, so we still have to reuse
+        * a local array.
+        */
+DIAG_OFF_DEPRECATION
        if ((hp = gethostbyname(name)) != NULL) {
+DIAG_ON_DEPRECATION
 #ifndef h_addr
                hlist[0] = (bpf_u_int32 *)hp->h_addr;
                NTOHL(hp->h_addr);
index c66846d3451bd4b5ab0e9c4bfd651ef413dbf4d9..34a0ae7ee373d2b5c5171dab18d28fe7679a0231 100644 (file)
@@ -59,7 +59,8 @@ 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_API bpf_u_int32 **pcap_nametoaddr(const char *);
+PCAP_API 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 *);