Skip to content

Commit 3840bc0

Browse files
committed
Fix portability issues in new src/port/inet_net_ntop.c file.
1. Don't #include postgres.h in a frontend build. 2. Don't assume that the backend's symbol PGSQL_AF_INET6 has anything to do with the constant that will be used by system library functions (because, in point of fact, it usually doesn't). Fortunately, PGSQL_AF_INET is equal to AF_INET, so we can just cater for both sets of values in one case construct without fear of conflict.
1 parent 5510931 commit 3840bc0

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/port/inet_net_ntop.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,28 @@
2121
static const char rcsid[] = "Id: inet_net_ntop.c,v 1.1.2.2 2004/03/09 09:17:27 marka Exp $";
2222
#endif
2323

24+
#ifndef FRONTEND
2425
#include "postgres.h"
26+
#else
27+
#include "postgres_fe.h"
28+
#endif
2529

2630
#include <sys/types.h>
2731
#include <sys/socket.h>
2832
#include <netinet/in.h>
2933
#include <arpa/inet.h>
3034

35+
#ifndef FRONTEND
3136
#include "utils/inet.h"
37+
#else
38+
/*
39+
* In a frontend build, we can't include inet.h, but we still need to have
40+
* sensible definitions of these two constants. Note that inet_net_ntop()
41+
* assumes that PGSQL_AF_INET is equal to AF_INET.
42+
*/
43+
#define PGSQL_AF_INET (AF_INET + 0)
44+
#define PGSQL_AF_INET6 (AF_INET + 1)
45+
#endif
3246

3347

3448
#define NS_IN6ADDRSZ 16
@@ -63,11 +77,21 @@ static char *inet_net_ntop_ipv6(const u_char *src, int bits,
6377
char *
6478
inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size)
6579
{
80+
/*
81+
* We need to cover both the address family constants used by the PG
82+
* inet type (PGSQL_AF_INET and PGSQL_AF_INET6) and those used by the
83+
* system libraries (AF_INET and AF_INET6). We can safely assume
84+
* PGSQL_AF_INET == AF_INET, but the INET6 constants are very likely
85+
* to be different. If AF_INET6 isn't defined, silently ignore it.
86+
*/
6687
switch (af)
6788
{
6889
case PGSQL_AF_INET:
6990
return (inet_net_ntop_ipv4(src, bits, dst, size));
7091
case PGSQL_AF_INET6:
92+
#if defined(AF_INET6) && AF_INET6 != PGSQL_AF_INET6
93+
case AF_INET6:
94+
#endif
7195
return (inet_net_ntop_ipv6(src, bits, dst, size));
7296
default:
7397
errno = EAFNOSUPPORT;
@@ -272,4 +296,3 @@ inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size)
272296
strcpy(dst, tmp);
273297
return (dst);
274298
}
275-

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy