|
21 | 21 | static const char rcsid[] = "Id: inet_net_ntop.c,v 1.1.2.2 2004/03/09 09:17:27 marka Exp $";
|
22 | 22 | #endif
|
23 | 23 |
|
| 24 | +#ifndef FRONTEND |
24 | 25 | #include "postgres.h"
|
| 26 | +#else |
| 27 | +#include "postgres_fe.h" |
| 28 | +#endif |
25 | 29 |
|
26 | 30 | #include <sys/types.h>
|
27 | 31 | #include <sys/socket.h>
|
28 | 32 | #include <netinet/in.h>
|
29 | 33 | #include <arpa/inet.h>
|
30 | 34 |
|
| 35 | +#ifndef FRONTEND |
31 | 36 | #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 |
32 | 46 |
|
33 | 47 |
|
34 | 48 | #define NS_IN6ADDRSZ 16
|
@@ -63,11 +77,21 @@ static char *inet_net_ntop_ipv6(const u_char *src, int bits,
|
63 | 77 | char *
|
64 | 78 | inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size)
|
65 | 79 | {
|
| 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 | + */ |
66 | 87 | switch (af)
|
67 | 88 | {
|
68 | 89 | case PGSQL_AF_INET:
|
69 | 90 | return (inet_net_ntop_ipv4(src, bits, dst, size));
|
70 | 91 | case PGSQL_AF_INET6:
|
| 92 | +#if defined(AF_INET6) && AF_INET6 != PGSQL_AF_INET6 |
| 93 | + case AF_INET6: |
| 94 | +#endif |
71 | 95 | return (inet_net_ntop_ipv6(src, bits, dst, size));
|
72 | 96 | default:
|
73 | 97 | errno = EAFNOSUPPORT;
|
@@ -272,4 +296,3 @@ inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size)
|
272 | 296 | strcpy(dst, tmp);
|
273 | 297 | return (dst);
|
274 | 298 | }
|
275 |
| - |
|
0 commit comments