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

Commit1da6eb7

Browse files
committed
Whack getaddrinfo() patch around until it works, more or less, on
machines without IPv6. Or at least it works on HPUX 10.20 ...
1 parentf8a15f6 commit1da6eb7

File tree

13 files changed

+364
-95
lines changed

13 files changed

+364
-95
lines changed

‎config/c-library.m4

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Macros that test various C library quirks
2-
# $Header: /cvsroot/pgsql/config/c-library.m4,v 1.15 2003/01/28 21:57:12 petere Exp $
2+
# $Header: /cvsroot/pgsql/config/c-library.m4,v 1.16 2003/04/02 00:49:27 tgl Exp $
33

44

55
# PGAC_VAR_INT_TIMEZONE
@@ -62,6 +62,16 @@ AC_DEFUN([PGAC_STRUCT_SOCKADDR_UN],
6262
])])# PGAC_STRUCT_SOCKADDR_UN
6363

6464

65+
# PGAC_STRUCT_ADDRINFO
66+
# -----------------------
67+
# If `struct addrinfo' exists, define HAVE_STRUCT_ADDRINFO.
68+
AC_DEFUN([PGAC_STRUCT_ADDRINFO],
69+
[AC_CHECK_TYPES([struct addrinfo],[],[],
70+
[#include <sys/socket.h>
71+
#include <netdb.h>
72+
])])# PGAC_STRUCT_ADDRINFO
73+
74+
6575
# PGAC_FUNC_POSIX_SIGNALS
6676
# -----------------------
6777
# Check to see if the machine has the POSIX signal interface. Define

‎configure

Lines changed: 146 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9392,6 +9392,66 @@ cat >>confdefs.h <<_ACEOF
93929392
_ACEOF
93939393
93949394
9395+
fi
9396+
9397+
echo"$as_me:$LINENO: checking for struct addrinfo">&5
9398+
echo$ECHO_N"checking for struct addrinfo...$ECHO_C">&6
9399+
iftest"${ac_cv_type_struct_addrinfo+set}" =set;then
9400+
echo$ECHO_N"(cached)$ECHO_C">&6
9401+
else
9402+
cat>conftest.$ac_ext<<_ACEOF
9403+
#line$LINENO "configure"
9404+
#include "confdefs.h"
9405+
#include <sys/socket.h>
9406+
#include <netdb.h>
9407+
9408+
9409+
#ifdef F77_DUMMY_MAIN
9410+
# ifdef __cplusplus
9411+
extern "C"
9412+
# endif
9413+
int F77_DUMMY_MAIN() { return 1; }
9414+
#endif
9415+
int
9416+
main ()
9417+
{
9418+
if ((struct addrinfo *) 0)
9419+
return 0;
9420+
if (sizeof (struct addrinfo))
9421+
return 0;
9422+
;
9423+
return 0;
9424+
}
9425+
_ACEOF
9426+
rm -f conftest.$ac_objext
9427+
if { (evalecho"$as_me:$LINENO:\"$ac_compile\"")>&5
9428+
(eval$ac_compile)2>&5
9429+
ac_status=$?
9430+
echo"$as_me:$LINENO:\$? =$ac_status">&5
9431+
(exit$ac_status); }&&
9432+
{ ac_try='test -s conftest.$ac_objext'
9433+
{ (evalecho"$as_me:$LINENO:\"$ac_try\"")>&5
9434+
(eval$ac_try)2>&5
9435+
ac_status=$?
9436+
echo"$as_me:$LINENO:\$? =$ac_status">&5
9437+
(exit$ac_status); }; };then
9438+
ac_cv_type_struct_addrinfo=yes
9439+
else
9440+
echo"$as_me: failed program was:">&5
9441+
cat conftest.$ac_ext>&5
9442+
ac_cv_type_struct_addrinfo=no
9443+
fi
9444+
rm -f conftest.$ac_objext conftest.$ac_ext
9445+
fi
9446+
echo"$as_me:$LINENO: result:$ac_cv_type_struct_addrinfo">&5
9447+
echo"${ECHO_T}$ac_cv_type_struct_addrinfo">&6
9448+
iftest$ac_cv_type_struct_addrinfo = yes;then
9449+
9450+
cat>>confdefs.h<<_ACEOF
9451+
#define HAVE_STRUCT_ADDRINFO 1
9452+
_ACEOF
9453+
9454+
93959455
fi
93969456
93979457
@@ -10950,8 +11010,90 @@ fi
1095011010
1095111011
1095211012
11013+
forac_funcin fseeko gethostname getopt_long getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul
11014+
do
11015+
as_ac_var=`echo"ac_cv_func_$ac_func"|$as_tr_sh`
11016+
echo"$as_me:$LINENO: checking for$ac_func">&5
11017+
echo$ECHO_N"checking for$ac_func...$ECHO_C">&6
11018+
ifeval"test\"\${$as_ac_var+set}\" = set";then
11019+
echo$ECHO_N"(cached)$ECHO_C">&6
11020+
else
11021+
cat>conftest.$ac_ext<<_ACEOF
11022+
#line$LINENO "configure"
11023+
#include "confdefs.h"
11024+
/* System header to define __stub macros and hopefully few prototypes,
11025+
which can conflict with char$ac_func (); below. */
11026+
#include <assert.h>
11027+
/* Override any gcc2 internal prototype to avoid an error. */
11028+
#ifdef __cplusplus
11029+
extern "C"
11030+
#endif
11031+
/* We use char because int might match the return type of a gcc2
11032+
builtin and then its argument prototype would still apply. */
11033+
char$ac_func ();
11034+
char (*f) ();
11035+
11036+
#ifdef F77_DUMMY_MAIN
11037+
# ifdef __cplusplus
11038+
extern "C"
11039+
# endif
11040+
int F77_DUMMY_MAIN() { return 1; }
11041+
#endif
11042+
int
11043+
main ()
11044+
{
11045+
/* The GNU C library defines this for functions which it implements
11046+
to always fail with ENOSYS. Some functions are actually named
11047+
something starting with __ and the normal name is an alias. */
11048+
#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
11049+
choke me
11050+
#else
11051+
f =$ac_func;
11052+
#endif
11053+
11054+
;
11055+
return 0;
11056+
}
11057+
_ACEOF
11058+
rm -f conftest.$ac_objext conftest$ac_exeext
11059+
if { (evalecho"$as_me:$LINENO:\"$ac_link\"")>&5
11060+
(eval$ac_link)2>&5
11061+
ac_status=$?
11062+
echo"$as_me:$LINENO:\$? =$ac_status">&5
11063+
(exit$ac_status); }&&
11064+
{ ac_try='test -s conftest$ac_exeext'
11065+
{ (evalecho"$as_me:$LINENO:\"$ac_try\"")>&5
11066+
(eval$ac_try)2>&5
11067+
ac_status=$?
11068+
echo"$as_me:$LINENO:\$? =$ac_status">&5
11069+
(exit$ac_status); }; };then
11070+
eval"$as_ac_var=yes"
11071+
else
11072+
echo"$as_me: failed program was:">&5
11073+
cat conftest.$ac_ext>&5
11074+
eval"$as_ac_var=no"
11075+
fi
11076+
rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
11077+
fi
11078+
echo"$as_me:$LINENO: result:`evalecho'${'$as_ac_var'}'`">&5
11079+
echo"${ECHO_T}`evalecho'${'$as_ac_var'}'`">&6
11080+
iftest`evalecho'${'$as_ac_var'}'` = yes;then
11081+
cat>>confdefs.h<<_ACEOF
11082+
#define`echo"HAVE_$ac_func"|$as_tr_cpp` 1
11083+
_ACEOF
11084+
11085+
else
11086+
LIBOBJS="$LIBOBJS$ac_func.$ac_objext"
11087+
fi
11088+
done
11089+
11090+
11091+
11092+
# system's version of getaddrinfo(), if any, may be used only if we found
11093+
# a definition for struct addrinfo; see notes in src/include/getaddrinfo.h
11094+
iftest x"$ac_cv_type_struct_addrinfo" = xyes;then
1095311095
10954-
forac_funcinfseekogetaddrinfo gethostname getopt_long getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul
11096+
forac_funcin getaddrinfo
1095511097
do
1095611098
as_ac_var=`echo"ac_cv_func_$ac_func"|$as_tr_sh`
1095711099
echo"$as_me:$LINENO: checking for$ac_func">&5
@@ -11029,6 +11171,9 @@ fi
1102911171
done
1103011172
1103111173
11174+
else
11175+
LIBOBJS="$LIBOBJS getaddrinfo.$ac_objext"
11176+
fi
1103211177
1103311178
# BSD/OS & NetBSD use a custom fseeko/ftello built on fsetpos/fgetpos
1103411179
# We override the previous test that said fseeko/ftello didn't exist

‎configure.in

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $Header: /cvsroot/pgsql/configure.in,v 1.240 2003/03/29 11:31:51 petere Exp $
2+
dnl $Header: /cvsroot/pgsql/configure.in,v 1.241 2003/04/02 00:49:28 tgl Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -746,6 +746,7 @@ AC_C_VOLATILE
746746
AC_STRUCT_TIMEZONE
747747
PGAC_UNION_SEMUN
748748
PGAC_STRUCT_SOCKADDR_UN
749+
PGAC_STRUCT_ADDRINFO
749750

750751
AC_CHECK_TYPES([struct cmsgcred, struct fcred, struct sockcred], [], [],
751752
[#include <sys/param.h>
@@ -847,7 +848,15 @@ else
847848
AC_CHECK_FUNCS([fpclass fp_class fp_class_d class], [break])
848849
fi
849850

850-
AC_REPLACE_FUNCS([fseeko getaddrinfo gethostname getopt_long getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul])
851+
AC_REPLACE_FUNCS([fseeko gethostname getopt_long getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul])
852+
853+
# system's version of getaddrinfo(), if any, may be used only if we found
854+
# a definition for struct addrinfo; see notes in src/include/getaddrinfo.h
855+
if test x"$ac_cv_type_struct_addrinfo" = xyes ; then
856+
AC_REPLACE_FUNCS([getaddrinfo])
857+
else
858+
AC_LIBOBJ(getaddrinfo)
859+
fi
851860

852861
# BSD/OS & NetBSD use a custom fseeko/ftello built on fsetpos/fgetpos
853862
# We override the previous test that said fseeko/ftello didn't exist

‎src/backend/libpq/ip.c

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*-------------------------------------------------------------------------
22
*
33
* ip.c
4-
*HandlesIPv6
4+
* IPv6-aware network access.
55
*
66
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/libpq/ip.c,v 1.3 2003/03/29 11:31:51 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/libpq/ip.c,v 1.4 2003/04/02 00:49:28 tgl Exp $
1212
*
1313
* This file and the IPV6 implementation were initially provided by
1414
* Nigel Kukard <nkukard@lbsd.net>, Linux Based Systems Design
@@ -17,11 +17,8 @@
1717
*-------------------------------------------------------------------------
1818
*/
1919

20-
#ifndefFRONTEND
21-
#include"postgres.h"
22-
#else
23-
#include"postgres_fe.h"
24-
#endif
20+
/* This is intended to be used in both frontend and backend, so use c.h */
21+
#include"c.h"
2522

2623
#include<errno.h>
2724
#include<unistd.h>
@@ -36,18 +33,25 @@
3633
#include<arpa/inet.h>
3734
#include<sys/file.h>
3835

39-
#include"libpq/libpq.h"
40-
#include"miscadmin.h"
36+
#include"libpq/ip.h"
37+
38+
39+
staticintrangeSockAddrAF_INET(constSockAddr*addr,
40+
constSockAddr*netaddr,
41+
constSockAddr*netmask);
4142

42-
#ifdefFRONTEND
43-
#defineelog fprintf
44-
#defineLOG stderr
43+
#ifdefHAVE_IPV6
44+
staticintrangeSockAddrAF_INET6(constSockAddr*addr,
45+
constSockAddr*netaddr,
46+
constSockAddr*netmask);
47+
staticvoidconvSockAddr6to4(constSockAddr*src,SockAddr*dst);
4548
#endif
4649

47-
#if defined(HAVE_UNIX_SOCKETS)
50+
#ifdefHAVE_UNIX_SOCKETS
4851
staticintgetaddrinfo_unix(constchar*path,conststructaddrinfo*hintsp,
4952
structaddrinfo**result);
50-
#endif/* HAVE_UNIX_SOCKETS */
53+
#endif
54+
5155

5256
/*
5357
*getaddrinfo2 - get address info for Unix, IPv4 and IPv6 sockets
@@ -59,15 +63,11 @@ getaddrinfo2(const char *hostname, const char *servname,
5963
#ifdefHAVE_UNIX_SOCKETS
6064
if (hintp!=NULL&&hintp->ai_family==AF_UNIX)
6165
returngetaddrinfo_unix(servname,hintp,result);
62-
else
63-
{
64-
#endif/* HAVE_UNIX_SOCKETS */
65-
/* NULL has special meaning to getaddrinfo */
66-
returngetaddrinfo((!hostname||hostname[0]=='\0') ?NULL :hostname,
67-
servname,hintp,result);
68-
#ifdefHAVE_UNIX_SOCKETS
69-
}
70-
#endif/* HAVE_UNIX_SOCKETS */
66+
#endif
67+
68+
/* NULL has special meaning to getaddrinfo */
69+
returngetaddrinfo((!hostname||hostname[0]=='\0') ?NULL :hostname,
70+
servname,hintp,result);
7171
}
7272

7373

@@ -98,11 +98,11 @@ freeaddrinfo2(int hint_ai_family, struct addrinfo *ai)
9898

9999
#if defined(HAVE_UNIX_SOCKETS)
100100
/* -------
101-
*getaddrinfo_unix - get unix socket info using IPv6
101+
*getaddrinfo_unix - get unix socket info using IPv6-compatible API
102102
*
103103
*Bug: only one addrinfo is set even though hintsp is NULL or
104104
* ai_socktype is 0
105-
*AI_CANNONNAME does notsupport.
105+
*AI_CANONNAME is notsupported.
106106
* -------
107107
*/
108108
staticint
@@ -128,7 +128,7 @@ getaddrinfo_unix(const char *path, const struct addrinfo *hintsp,
128128

129129
if (hints.ai_family!=AF_UNIX)
130130
{
131-
elog(LOG,"hints.ai_family is invalid in getaddrinfo_unix()\n");
131+
/* shouldn't have been called */
132132
returnEAI_ADDRFAMILY;
133133
}
134134

@@ -247,8 +247,6 @@ SockAddr_pton(SockAddr *sa, const char *src)
247247
}
248248

249249

250-
251-
252250
/*
253251
*isAF_INETx - check to see if sa is AF_INET or AF_INET6
254252
*/
@@ -267,7 +265,8 @@ isAF_INETx(const int family)
267265

268266

269267
int
270-
rangeSockAddr(constSockAddr*addr,constSockAddr*netaddr,constSockAddr*netmask)
268+
rangeSockAddr(constSockAddr*addr,constSockAddr*netaddr,
269+
constSockAddr*netmask)
271270
{
272271
if (addr->sa.sa_family==AF_INET)
273272
returnrangeSockAddrAF_INET(addr,netaddr,netmask);
@@ -279,7 +278,7 @@ rangeSockAddr(const SockAddr *addr, const SockAddr *netaddr, const SockAddr *net
279278
return0;
280279
}
281280

282-
int
281+
staticint
283282
rangeSockAddrAF_INET(constSockAddr*addr,constSockAddr*netaddr,
284283
constSockAddr*netmask)
285284
{
@@ -294,8 +293,10 @@ rangeSockAddrAF_INET(const SockAddr *addr, const SockAddr *netaddr,
294293
return0;
295294
}
296295

296+
297297
#ifdefHAVE_IPV6
298-
int
298+
299+
staticint
299300
rangeSockAddrAF_INET6(constSockAddr*addr,constSockAddr*netaddr,
300301
constSockAddr*netmask)
301302
{
@@ -324,7 +325,7 @@ rangeSockAddrAF_INET6(const SockAddr *addr, const SockAddr *netaddr,
324325
return1;
325326
}
326327

327-
void
328+
staticvoid
328329
convSockAddr6to4(constSockAddr*src,SockAddr*dst)
329330
{
330331
charaddr_str[INET6_ADDRSTRLEN];
@@ -337,6 +338,8 @@ convSockAddr6to4(const SockAddr *src, SockAddr *dst)
337338
+ (src->in6.sin6_addr.s6_addr[14] <<8)
338339
+ (src->in6.sin6_addr.s6_addr[13] <<16)
339340
+ (src->in6.sin6_addr.s6_addr[12] <<24);
341+
340342
SockAddr_ntop(src,addr_str,INET6_ADDRSTRLEN,0);
341343
}
342-
#endif
344+
345+
#endif/* HAVE_IPV6 */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp