Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3840bc0

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 dowith the constant that will be used by system library functions (because,in point of fact, it usually doesn't). Fortunately, PGSQL_AF_INET is equalto AF_INET, so we can just cater for both sets of values in one caseconstruct without fear of conflict.
1 parent5510931 commit3840bc0

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
staticconstcharrcsid[]="Id: inet_net_ntop.c,v 1.1.2.2 2004/03/09 09:17:27 marka Exp $";
2222
#endif
2323

24+
#ifndefFRONTEND
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+
#ifndefFRONTEND
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+
#definePGSQL_AF_INET(AF_INET + 0)
44+
#definePGSQL_AF_INET6(AF_INET + 1)
45+
#endif
3246

3347

3448
#defineNS_IN6ADDRSZ 16
@@ -63,11 +77,21 @@ static char *inet_net_ntop_ipv6(const u_char *src, int bits,
6377
char*
6478
inet_net_ntop(intaf,constvoid*src,intbits,char*dst,size_tsize)
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
casePGSQL_AF_INET:
6990
return (inet_net_ntop_ipv4(src,bits,dst,size));
7091
casePGSQL_AF_INET6:
92+
#if defined(AF_INET6)&&AF_INET6!=PGSQL_AF_INET6
93+
caseAF_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)

[8]ページ先頭

©2009-2025 Movatter.jp