Avoid conflicts with library versions of inet_net_ntop() and friends.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 18 Aug 2019 23:27:23 +0000 (19:27 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 18 Aug 2019 23:27:23 +0000 (19:27 -0400)
Prefix inet_net_ntop and sibling routines with "pg_" to ensure that
they aren't mistaken for C-library functions.  This fixes warnings
from cpluspluscheck on some platforms, and should help reduce reader
confusion everywhere, since our functions aren't exactly interchangeable
with the library versions (they may have different ideas about address
family codes).

This shouldn't be fixing any actual bugs, unless somebody's linker
is misbehaving, so no need to back-patch.

Discussion: https://postgr.es/m/20518.1559494394@sss.pgh.pa.us

src/backend/utils/adt/inet_cidr_ntop.c
src/backend/utils/adt/inet_net_pton.c
src/backend/utils/adt/network.c
src/include/port.h
src/include/utils/builtins.h
src/interfaces/libpq/fe-connect.c
src/port/getaddrinfo.c
src/port/inet_net_ntop.c

index 3000b1735d056c561b90075d02c13ba7c1548ab8..5f74c05a65db6d2168fd2d49ea6294aa49867c42 100644 (file)
@@ -44,7 +44,7 @@ static char *inet_cidr_ntop_ipv6(const u_char *src, int bits,
 
 /*
  * char *
- * inet_cidr_ntop(af, src, bits, dst, size)
+ * pg_inet_cidr_ntop(af, src, bits, dst, size)
  * convert network number from network to presentation format.
  * generates CIDR style result always.
  * return:
@@ -53,7 +53,7 @@ static char *inet_cidr_ntop_ipv6(const u_char *src, int bits,
  * Paul Vixie (ISC), July 1996
  */
 char *
-inet_cidr_ntop(int af, const void *src, int bits, char *dst, size_t size)
+pg_inet_cidr_ntop(int af, const void *src, int bits, char *dst, size_t size)
 {
    switch (af)
    {
index c28809fad68a7a4055726a0ed3f3dcb46c42f596..d3221a13139bb6547fba43ec527054bfbbedb636 100644 (file)
@@ -42,7 +42,7 @@ static int    inet_cidr_pton_ipv6(const char *src, u_char *dst, size_t size);
 
 /*
  * int
- * inet_net_pton(af, src, dst, size)
+ * pg_inet_net_pton(af, src, dst, size)
  * convert network number from presentation to network format.
  * accepts hex octets, hex strings, decimal octets, and /CIDR.
  * "size" is in bytes and describes "dst".
@@ -59,7 +59,7 @@ static int    inet_cidr_pton_ipv6(const char *src, u_char *dst, size_t size);
  *
  */
 int
-inet_net_pton(int af, const char *src, void *dst, size_t size)
+pg_inet_net_pton(int af, const char *src, void *dst, size_t size)
 {
    switch (af)
    {
@@ -241,7 +241,7 @@ emsgsize:
 
 /*
  * int
- * inet_net_pton(af, src, dst, *bits)
+ * inet_net_pton_ipv4(af, src, dst, *bits)
  * convert network address from presentation to network format.
  * accepts inet_pton()'s input for this "af" plus trailing "/CIDR".
  * "dst" is assumed large enough for its "af".  "bits" is set to the
index 6b367644f90d3d58e8c3575996d1c1f93f0281b7..3d536a16629a1d3717c617c553a6c7efa5e0d07c 100644 (file)
@@ -91,8 +91,8 @@ network_in(char *src, bool is_cidr)
    else
        ip_family(dst) = PGSQL_AF_INET;
 
-   bits = inet_net_pton(ip_family(dst), src, ip_addr(dst),
-                        is_cidr ? ip_addrsize(dst) : -1);
+   bits = pg_inet_net_pton(ip_family(dst), src, ip_addr(dst),
+                           is_cidr ? ip_addrsize(dst) : -1);
    if ((bits < 0) || (bits > ip_maxbits(dst)))
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
@@ -145,8 +145,8 @@ network_out(inet *src, bool is_cidr)
    char       *dst;
    int         len;
 
-   dst = inet_net_ntop(ip_family(src), ip_addr(src), ip_bits(src),
-                       tmp, sizeof(tmp));
+   dst = pg_inet_net_ntop(ip_family(src), ip_addr(src), ip_bits(src),
+                          tmp, sizeof(tmp));
    if (dst == NULL)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
@@ -1192,8 +1192,8 @@ network_host(PG_FUNCTION_ARGS)
    char        tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
 
    /* force display of max bits, regardless of masklen... */
-   if (inet_net_ntop(ip_family(ip), ip_addr(ip), ip_maxbits(ip),
-                     tmp, sizeof(tmp)) == NULL)
+   if (pg_inet_net_ntop(ip_family(ip), ip_addr(ip), ip_maxbits(ip),
+                        tmp, sizeof(tmp)) == NULL)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
                 errmsg("could not format inet value: %m")));
@@ -1217,8 +1217,8 @@ network_show(PG_FUNCTION_ARGS)
    int         len;
    char        tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
 
-   if (inet_net_ntop(ip_family(ip), ip_addr(ip), ip_maxbits(ip),
-                     tmp, sizeof(tmp)) == NULL)
+   if (pg_inet_net_ntop(ip_family(ip), ip_addr(ip), ip_maxbits(ip),
+                        tmp, sizeof(tmp)) == NULL)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
                 errmsg("could not format inet value: %m")));
@@ -1240,8 +1240,8 @@ inet_abbrev(PG_FUNCTION_ARGS)
    char       *dst;
    char        tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
 
-   dst = inet_net_ntop(ip_family(ip), ip_addr(ip),
-                       ip_bits(ip), tmp, sizeof(tmp));
+   dst = pg_inet_net_ntop(ip_family(ip), ip_addr(ip),
+                          ip_bits(ip), tmp, sizeof(tmp));
 
    if (dst == NULL)
        ereport(ERROR,
@@ -1258,8 +1258,8 @@ cidr_abbrev(PG_FUNCTION_ARGS)
    char       *dst;
    char        tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
 
-   dst = inet_cidr_ntop(ip_family(ip), ip_addr(ip),
-                        ip_bits(ip), tmp, sizeof(tmp));
+   dst = pg_inet_cidr_ntop(ip_family(ip), ip_addr(ip),
+                           ip_bits(ip), tmp, sizeof(tmp));
 
    if (dst == NULL)
        ereport(ERROR,
index b5c03d912b0fef4db404d33ad4122523dca385a6..ff527952ab90067708c85f0d98475c557f4f21b7 100644 (file)
@@ -503,8 +503,8 @@ extern int  pg_codepage_to_encoding(UINT cp);
 #endif
 
 /* port/inet_net_ntop.c */
-extern char *inet_net_ntop(int af, const void *src, int bits,
-                          char *dst, size_t size);
+extern char *pg_inet_net_ntop(int af, const void *src, int bits,
+                             char *dst, size_t size);
 
 /* port/pg_strong_random.c */
 extern bool pg_strong_random(void *buf, size_t len);
index a3cd7d26fae0761e339fb33777b43979cbabeb79..937ddb7ef0816d6826f6efc20f6d42ce0797921d 100644 (file)
@@ -87,12 +87,12 @@ extern void text_to_cstring_buffer(const text *src, char *dst, size_t dst_len);
 extern int xidComparator(const void *arg1, const void *arg2);
 
 /* inet_cidr_ntop.c */
-extern char *inet_cidr_ntop(int af, const void *src, int bits,
-                           char *dst, size_t size);
+extern char *pg_inet_cidr_ntop(int af, const void *src, int bits,
+                              char *dst, size_t size);
 
 /* inet_net_pton.c */
-extern int inet_net_pton(int af, const char *src,
-                         void *dst, size_t size);
+extern int pg_inet_net_pton(int af, const char *src,
+                            void *dst, size_t size);
 
 /* network.c */
 extern double convert_network_to_scalar(Datum value, Oid typid, bool *failure);
index fa5af18ffac030be0e5ef2aec1e81a6a3f998b66..7f1fd2f45eb2f1e8228cb033a33dc9de54080f73 100644 (file)
@@ -1539,19 +1539,19 @@ getHostaddr(PGconn *conn, char *host_addr, int host_addr_len)
 
    if (addr->ss_family == AF_INET)
    {
-       if (inet_net_ntop(AF_INET,
-                         &((struct sockaddr_in *) addr)->sin_addr.s_addr,
-                         32,
-                         host_addr, host_addr_len) == NULL)
+       if (pg_inet_net_ntop(AF_INET,
+                            &((struct sockaddr_in *) addr)->sin_addr.s_addr,
+                            32,
+                            host_addr, host_addr_len) == NULL)
            host_addr[0] = '\0';
    }
 #ifdef HAVE_IPV6
    else if (addr->ss_family == AF_INET6)
    {
-       if (inet_net_ntop(AF_INET6,
-                         &((struct sockaddr_in6 *) addr)->sin6_addr.s6_addr,
-                         128,
-                         host_addr, host_addr_len) == NULL)
+       if (pg_inet_net_ntop(AF_INET6,
+                            &((struct sockaddr_in6 *) addr)->sin6_addr.s6_addr,
+                            128,
+                            host_addr, host_addr_len) == NULL)
            host_addr[0] = '\0';
    }
 #endif
index 536c5f686e2aba1bc1497c486623793bbb947a4f..9e5829b6dd2f98c4459144d2c1e2f56e82aa9f7c 100644 (file)
@@ -387,9 +387,10 @@ getnameinfo(const struct sockaddr *sa, int salen,
    {
        if (sa->sa_family == AF_INET)
        {
-           if (inet_net_ntop(AF_INET, &((struct sockaddr_in *) sa)->sin_addr,
-                             sa->sa_family == AF_INET ? 32 : 128,
-                             node, nodelen) == NULL)
+           if (pg_inet_net_ntop(AF_INET,
+                                &((struct sockaddr_in *) sa)->sin_addr,
+                                sa->sa_family == AF_INET ? 32 : 128,
+                                node, nodelen) == NULL)
                return EAI_MEMORY;
        }
        else
index 67aff110da596cb95e425c963438087aaf5b0f61..b8ad69c3909473fc1d5c56a985a42ab1a5e821a4 100644 (file)
@@ -36,7 +36,7 @@ static const char rcsid[] = "Id: inet_net_ntop.c,v 1.1.2.2 2004/03/09 09:17:27 m
 #else
 /*
  * In a frontend build, we can't include inet.h, but we still need to have
- * sensible definitions of these two constants.  Note that inet_net_ntop()
+ * sensible definitions of these two constants.  Note that pg_inet_net_ntop()
  * assumes that PGSQL_AF_INET is equal to AF_INET.
  */
 #define PGSQL_AF_INET  (AF_INET + 0)
@@ -61,20 +61,20 @@ static char *inet_net_ntop_ipv6(const u_char *src, int bits,
 
 /*
  * char *
- * inet_net_ntop(af, src, bits, dst, size)
+ * pg_inet_net_ntop(af, src, bits, dst, size)
  * convert host/network address from network to presentation format.
  * "src"'s size is determined from its "af".
  * return:
  * pointer to dst, or NULL if an error occurred (check errno).
  * note:
  * 192.5.5.1/28 has a nonzero host part, which means it isn't a network
- * as called for by inet_net_pton() but it can be a host address with
+ * as called for by pg_inet_net_pton() but it can be a host address with
  * an included netmask.
  * author:
  * Paul Vixie (ISC), October 1998
  */
 char *
-inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size)
+pg_inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size)
 {
    /*
     * We need to cover both the address family constants used by the PG inet