Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 927f34c

Browse files
committed
Avoid conflicts with library versions of inet_net_ntop() and friends.
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
1 parent 232720b commit 927f34c

File tree

8 files changed

+39
-38
lines changed

8 files changed

+39
-38
lines changed

src/backend/utils/adt/inet_cidr_ntop.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static char *inet_cidr_ntop_ipv6(const u_char *src, int bits,
4444

4545
/*
4646
* char *
47-
* inet_cidr_ntop(af, src, bits, dst, size)
47+
* pg_inet_cidr_ntop(af, src, bits, dst, size)
4848
* convert network number from network to presentation format.
4949
* generates CIDR style result always.
5050
* return:
@@ -53,7 +53,7 @@ static char *inet_cidr_ntop_ipv6(const u_char *src, int bits,
5353
* Paul Vixie (ISC), July 1996
5454
*/
5555
char *
56-
inet_cidr_ntop(int af, const void *src, int bits, char *dst, size_t size)
56+
pg_inet_cidr_ntop(int af, const void *src, int bits, char *dst, size_t size)
5757
{
5858
switch (af)
5959
{

src/backend/utils/adt/inet_net_pton.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static int inet_cidr_pton_ipv6(const char *src, u_char *dst, size_t size);
4242

4343
/*
4444
* int
45-
* inet_net_pton(af, src, dst, size)
45+
* pg_inet_net_pton(af, src, dst, size)
4646
* convert network number from presentation to network format.
4747
* accepts hex octets, hex strings, decimal octets, and /CIDR.
4848
* "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);
5959
*
6060
*/
6161
int
62-
inet_net_pton(int af, const char *src, void *dst, size_t size)
62+
pg_inet_net_pton(int af, const char *src, void *dst, size_t size)
6363
{
6464
switch (af)
6565
{
@@ -241,7 +241,7 @@ inet_cidr_pton_ipv4(const char *src, u_char *dst, size_t size)
241241

242242
/*
243243
* int
244-
* inet_net_pton(af, src, dst, *bits)
244+
* inet_net_pton_ipv4(af, src, dst, *bits)
245245
* convert network address from presentation to network format.
246246
* accepts inet_pton()'s input for this "af" plus trailing "/CIDR".
247247
* "dst" is assumed large enough for its "af". "bits" is set to the

src/backend/utils/adt/network.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ network_in(char *src, bool is_cidr)
9191
else
9292
ip_family(dst) = PGSQL_AF_INET;
9393

94-
bits = inet_net_pton(ip_family(dst), src, ip_addr(dst),
95-
is_cidr ? ip_addrsize(dst) : -1);
94+
bits = pg_inet_net_pton(ip_family(dst), src, ip_addr(dst),
95+
is_cidr ? ip_addrsize(dst) : -1);
9696
if ((bits < 0) || (bits > ip_maxbits(dst)))
9797
ereport(ERROR,
9898
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
@@ -145,8 +145,8 @@ network_out(inet *src, bool is_cidr)
145145
char *dst;
146146
int len;
147147

148-
dst = inet_net_ntop(ip_family(src), ip_addr(src), ip_bits(src),
149-
tmp, sizeof(tmp));
148+
dst = pg_inet_net_ntop(ip_family(src), ip_addr(src), ip_bits(src),
149+
tmp, sizeof(tmp));
150150
if (dst == NULL)
151151
ereport(ERROR,
152152
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
@@ -1192,8 +1192,8 @@ network_host(PG_FUNCTION_ARGS)
11921192
char tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
11931193

11941194
/* force display of max bits, regardless of masklen... */
1195-
if (inet_net_ntop(ip_family(ip), ip_addr(ip), ip_maxbits(ip),
1196-
tmp, sizeof(tmp)) == NULL)
1195+
if (pg_inet_net_ntop(ip_family(ip), ip_addr(ip), ip_maxbits(ip),
1196+
tmp, sizeof(tmp)) == NULL)
11971197
ereport(ERROR,
11981198
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
11991199
errmsg("could not format inet value: %m")));
@@ -1217,8 +1217,8 @@ network_show(PG_FUNCTION_ARGS)
12171217
int len;
12181218
char tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
12191219

1220-
if (inet_net_ntop(ip_family(ip), ip_addr(ip), ip_maxbits(ip),
1221-
tmp, sizeof(tmp)) == NULL)
1220+
if (pg_inet_net_ntop(ip_family(ip), ip_addr(ip), ip_maxbits(ip),
1221+
tmp, sizeof(tmp)) == NULL)
12221222
ereport(ERROR,
12231223
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
12241224
errmsg("could not format inet value: %m")));
@@ -1240,8 +1240,8 @@ inet_abbrev(PG_FUNCTION_ARGS)
12401240
char *dst;
12411241
char tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
12421242

1243-
dst = inet_net_ntop(ip_family(ip), ip_addr(ip),
1244-
ip_bits(ip), tmp, sizeof(tmp));
1243+
dst = pg_inet_net_ntop(ip_family(ip), ip_addr(ip),
1244+
ip_bits(ip), tmp, sizeof(tmp));
12451245

12461246
if (dst == NULL)
12471247
ereport(ERROR,
@@ -1258,8 +1258,8 @@ cidr_abbrev(PG_FUNCTION_ARGS)
12581258
char *dst;
12591259
char tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
12601260

1261-
dst = inet_cidr_ntop(ip_family(ip), ip_addr(ip),
1262-
ip_bits(ip), tmp, sizeof(tmp));
1261+
dst = pg_inet_cidr_ntop(ip_family(ip), ip_addr(ip),
1262+
ip_bits(ip), tmp, sizeof(tmp));
12631263

12641264
if (dst == NULL)
12651265
ereport(ERROR,

src/include/port.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,8 @@ extern int pg_codepage_to_encoding(UINT cp);
503503
#endif
504504

505505
/* port/inet_net_ntop.c */
506-
extern char *inet_net_ntop(int af, const void *src, int bits,
507-
char *dst, size_t size);
506+
extern char *pg_inet_net_ntop(int af, const void *src, int bits,
507+
char *dst, size_t size);
508508

509509
/* port/pg_strong_random.c */
510510
extern bool pg_strong_random(void *buf, size_t len);

src/include/utils/builtins.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ extern void text_to_cstring_buffer(const text *src, char *dst, size_t dst_len);
8787
extern int xidComparator(const void *arg1, const void *arg2);
8888

8989
/* inet_cidr_ntop.c */
90-
extern char *inet_cidr_ntop(int af, const void *src, int bits,
91-
char *dst, size_t size);
90+
extern char *pg_inet_cidr_ntop(int af, const void *src, int bits,
91+
char *dst, size_t size);
9292

9393
/* inet_net_pton.c */
94-
extern int inet_net_pton(int af, const char *src,
95-
void *dst, size_t size);
94+
extern int pg_inet_net_pton(int af, const char *src,
95+
void *dst, size_t size);
9696

9797
/* network.c */
9898
extern double convert_network_to_scalar(Datum value, Oid typid, bool *failure);

src/interfaces/libpq/fe-connect.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -1539,19 +1539,19 @@ getHostaddr(PGconn *conn, char *host_addr, int host_addr_len)
15391539

15401540
if (addr->ss_family == AF_INET)
15411541
{
1542-
if (inet_net_ntop(AF_INET,
1543-
&((struct sockaddr_in *) addr)->sin_addr.s_addr,
1544-
32,
1545-
host_addr, host_addr_len) == NULL)
1542+
if (pg_inet_net_ntop(AF_INET,
1543+
&((struct sockaddr_in *) addr)->sin_addr.s_addr,
1544+
32,
1545+
host_addr, host_addr_len) == NULL)
15461546
host_addr[0] = '\0';
15471547
}
15481548
#ifdef HAVE_IPV6
15491549
else if (addr->ss_family == AF_INET6)
15501550
{
1551-
if (inet_net_ntop(AF_INET6,
1552-
&((struct sockaddr_in6 *) addr)->sin6_addr.s6_addr,
1553-
128,
1554-
host_addr, host_addr_len) == NULL)
1551+
if (pg_inet_net_ntop(AF_INET6,
1552+
&((struct sockaddr_in6 *) addr)->sin6_addr.s6_addr,
1553+
128,
1554+
host_addr, host_addr_len) == NULL)
15551555
host_addr[0] = '\0';
15561556
}
15571557
#endif

src/port/getaddrinfo.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,10 @@ getnameinfo(const struct sockaddr *sa, int salen,
387387
{
388388
if (sa->sa_family == AF_INET)
389389
{
390-
if (inet_net_ntop(AF_INET, &((struct sockaddr_in *) sa)->sin_addr,
391-
sa->sa_family == AF_INET ? 32 : 128,
392-
node, nodelen) == NULL)
390+
if (pg_inet_net_ntop(AF_INET,
391+
&((struct sockaddr_in *) sa)->sin_addr,
392+
sa->sa_family == AF_INET ? 32 : 128,
393+
node, nodelen) == NULL)
393394
return EAI_MEMORY;
394395
}
395396
else

src/port/inet_net_ntop.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -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
3636
#else
3737
/*
3838
* In a frontend build, we can't include inet.h, but we still need to have
39-
* sensible definitions of these two constants. Note that inet_net_ntop()
39+
* sensible definitions of these two constants. Note that pg_inet_net_ntop()
4040
* assumes that PGSQL_AF_INET is equal to AF_INET.
4141
*/
4242
#define PGSQL_AF_INET (AF_INET + 0)
@@ -61,20 +61,20 @@ static char *inet_net_ntop_ipv6(const u_char *src, int bits,
6161

6262
/*
6363
* char *
64-
* inet_net_ntop(af, src, bits, dst, size)
64+
* pg_inet_net_ntop(af, src, bits, dst, size)
6565
* convert host/network address from network to presentation format.
6666
* "src"'s size is determined from its "af".
6767
* return:
6868
* pointer to dst, or NULL if an error occurred (check errno).
6969
* note:
7070
* 192.5.5.1/28 has a nonzero host part, which means it isn't a network
71-
* as called for by inet_net_pton() but it can be a host address with
71+
* as called for by pg_inet_net_pton() but it can be a host address with
7272
* an included netmask.
7373
* author:
7474
* Paul Vixie (ISC), October 1998
7575
*/
7676
char *
77-
inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size)
77+
pg_inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size)
7878
{
7979
/*
8080
* We need to cover both the address family constants used by the PG inet

0 commit comments

Comments
 (0)