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

Commit82a91eb

Browse files
committed
Simplify the socket handling code by supplying a replacement getaddrinfo()
function if the OS doesn't provide one.
1 parentbf7ca0a commit82a91eb

File tree

11 files changed

+283
-280
lines changed

11 files changed

+283
-280
lines changed

‎configure

Lines changed: 55 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10321,26 +10321,16 @@ fi
1032110321
1032210322
1032310323
10324-
# This exports HAVE_IPV6 to both C files and Makefiles
10325-
echo"$as_me:$LINENO: checking for getaddrinfo">&5
10326-
echo$ECHO_N"checking for getaddrinfo...$ECHO_C">&6
10327-
iftest"${ac_cv_func_getaddrinfo+set}" =set;then
10324+
echo"$as_me:$LINENO: checking for struct sockaddr_in6">&5
10325+
echo$ECHO_N"checking for struct sockaddr_in6...$ECHO_C">&6
10326+
iftest"${ac_cv_type_struct_sockaddr_in6+set}" =set;then
1032810327
echo$ECHO_N"(cached)$ECHO_C">&6
1032910328
else
1033010329
cat>conftest.$ac_ext<<_ACEOF
1033110330
#line$LINENO "configure"
1033210331
#include "confdefs.h"
10333-
/* System header to define __stub macros and hopefully few prototypes,
10334-
which can conflict with char getaddrinfo (); below. */
10335-
#include <assert.h>
10336-
/* Override any gcc2 internal prototype to avoid an error. */
10337-
#ifdef __cplusplus
10338-
extern "C"
10339-
#endif
10340-
/* We use char because int might match the return type of a gcc2
10341-
builtin and then its argument prototype would still apply. */
10342-
char getaddrinfo ();
10343-
char (*f) ();
10332+
$ac_includes_default
10333+
#include <netinet/in.h>
1034410334
1034510335
#ifdef F77_DUMMY_MAIN
1034610336
# ifdef __cplusplus
@@ -10351,52 +10341,56 @@ char (*f) ();
1035110341
int
1035210342
main ()
1035310343
{
10354-
/* The GNU C library defines this for functions which it implements
10355-
to always fail with ENOSYS. Some functions are actually named
10356-
something starting with __ and the normal name is an alias. */
10357-
#if defined (__stub_getaddrinfo) || defined (__stub___getaddrinfo)
10358-
choke me
10359-
#else
10360-
f = getaddrinfo;
10361-
#endif
10362-
10344+
if ((struct sockaddr_in6 *) 0)
10345+
return 0;
10346+
if (sizeof (struct sockaddr_in6))
10347+
return 0;
1036310348
;
1036410349
return 0;
1036510350
}
1036610351
_ACEOF
10367-
rm -f conftest.$ac_objext conftest$ac_exeext
10368-
if { (evalecho"$as_me:$LINENO:\"$ac_link\"")>&5
10369-
(eval$ac_link)2>&5
10352+
rm -f conftest.$ac_objext
10353+
if { (evalecho"$as_me:$LINENO:\"$ac_compile\"")>&5
10354+
(eval$ac_compile)2>&5
1037010355
ac_status=$?
1037110356
echo"$as_me:$LINENO:\$? =$ac_status">&5
1037210357
(exit$ac_status); }&&
10373-
{ ac_try='test -s conftest$ac_exeext'
10358+
{ ac_try='test -s conftest.$ac_objext'
1037410359
{ (evalecho"$as_me:$LINENO:\"$ac_try\"")>&5
1037510360
(eval$ac_try)2>&5
1037610361
ac_status=$?
1037710362
echo"$as_me:$LINENO:\$? =$ac_status">&5
1037810363
(exit$ac_status); }; };then
10379-
ac_cv_func_getaddrinfo=yes
10364+
ac_cv_type_struct_sockaddr_in6=yes
1038010365
else
1038110366
echo"$as_me: failed program was:">&5
1038210367
cat conftest.$ac_ext>&5
10383-
ac_cv_func_getaddrinfo=no
10368+
ac_cv_type_struct_sockaddr_in6=no
1038410369
fi
10385-
rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
10370+
rm -f conftest.$ac_objext conftest.$ac_ext
1038610371
fi
10387-
echo"$as_me:$LINENO: result:$ac_cv_func_getaddrinfo">&5
10388-
echo"${ECHO_T}$ac_cv_func_getaddrinfo">&6
10389-
iftest$ac_cv_func_getaddrinfo = yes;then
10390-
echo"$as_me:$LINENO: checking forstruct sockaddr_in6">&5
10391-
echo$ECHO_N"checking forstruct sockaddr_in6...$ECHO_C">&6
10392-
iftest"${ac_cv_type_struct_sockaddr_in6+set}" =set;then
10372+
echo"$as_me:$LINENO: result:$ac_cv_type_struct_sockaddr_in6">&5
10373+
echo"${ECHO_T}$ac_cv_type_struct_sockaddr_in6">&6
10374+
iftest$ac_cv_type_struct_sockaddr_in6 = yes;then
10375+
echo"$as_me:$LINENO: checking forinet_ntop">&5
10376+
echo$ECHO_N"checking forinet_ntop...$ECHO_C">&6
10377+
iftest"${ac_cv_func_inet_ntop+set}" =set;then
1039310378
echo$ECHO_N"(cached)$ECHO_C">&6
1039410379
else
1039510380
cat>conftest.$ac_ext<<_ACEOF
1039610381
#line$LINENO "configure"
1039710382
#include "confdefs.h"
10398-
$ac_includes_default
10399-
#include <netinet/in.h>
10383+
/* System header to define __stub macros and hopefully few prototypes,
10384+
which can conflict with char inet_ntop (); below. */
10385+
#include <assert.h>
10386+
/* Override any gcc2 internal prototype to avoid an error. */
10387+
#ifdef __cplusplus
10388+
extern "C"
10389+
#endif
10390+
/* We use char because int might match the return type of a gcc2
10391+
builtin and then its argument prototype would still apply. */
10392+
char inet_ntop ();
10393+
char (*f) ();
1040010394
1040110395
#ifdef F77_DUMMY_MAIN
1040210396
# ifdef __cplusplus
@@ -10407,38 +10401,43 @@ $ac_includes_default
1040710401
int
1040810402
main ()
1040910403
{
10410-
if ((struct sockaddr_in6 *) 0)
10411-
return 0;
10412-
if (sizeof (struct sockaddr_in6))
10413-
return 0;
10404+
/* The GNU C library defines this for functions which it implements
10405+
to always fail with ENOSYS. Some functions are actually named
10406+
something starting with __ and the normal name is an alias. */
10407+
#if defined (__stub_inet_ntop) || defined (__stub___inet_ntop)
10408+
choke me
10409+
#else
10410+
f = inet_ntop;
10411+
#endif
10412+
1041410413
;
1041510414
return 0;
1041610415
}
1041710416
_ACEOF
10418-
rm -f conftest.$ac_objext
10419-
if { (evalecho"$as_me:$LINENO:\"$ac_compile\"")>&5
10420-
(eval$ac_compile)2>&5
10417+
rm -f conftest.$ac_objext conftest$ac_exeext
10418+
if { (evalecho"$as_me:$LINENO:\"$ac_link\"")>&5
10419+
(eval$ac_link)2>&5
1042110420
ac_status=$?
1042210421
echo"$as_me:$LINENO:\$? =$ac_status">&5
1042310422
(exit$ac_status); }&&
10424-
{ ac_try='test -s conftest.$ac_objext'
10423+
{ ac_try='test -s conftest$ac_exeext'
1042510424
{ (evalecho"$as_me:$LINENO:\"$ac_try\"")>&5
1042610425
(eval$ac_try)2>&5
1042710426
ac_status=$?
1042810427
echo"$as_me:$LINENO:\$? =$ac_status">&5
1042910428
(exit$ac_status); }; };then
10430-
ac_cv_type_struct_sockaddr_in6=yes
10429+
ac_cv_func_inet_ntop=yes
1043110430
else
1043210431
echo"$as_me: failed program was:">&5
1043310432
cat conftest.$ac_ext>&5
10434-
ac_cv_type_struct_sockaddr_in6=no
10433+
ac_cv_func_inet_ntop=no
1043510434
fi
10436-
rm -f conftest.$ac_objext conftest.$ac_ext
10435+
rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
1043710436
fi
10438-
echo"$as_me:$LINENO: result:$ac_cv_type_struct_sockaddr_in6">&5
10439-
echo"${ECHO_T}$ac_cv_type_struct_sockaddr_in6">&6
10440-
iftest$ac_cv_type_struct_sockaddr_in6 = yes;then
10441-
HAVE_IPV6="yes";cat>>confdefs.h<<\_ACEOF
10437+
echo"$as_me:$LINENO: result:$ac_cv_func_inet_ntop">&5
10438+
echo"${ECHO_T}$ac_cv_func_inet_ntop">&6
10439+
iftest$ac_cv_func_inet_ntop = yes;then
10440+
cat>>confdefs.h<<\_ACEOF
1044210441
#define HAVE_IPV6 1
1044310442
_ACEOF
1044410443
@@ -10447,7 +10446,6 @@ fi
1044710446
fi
1044810447
1044910448
10450-
1045110449
echo"$as_me:$LINENO: checking for PS_STRINGS">&5
1045210450
echo$ECHO_N"checking for PS_STRINGS...$ECHO_C">&6
1045310451
iftest"${pgac_cv_var_PS_STRINGS+set}" =set;then
@@ -10952,7 +10950,8 @@ fi
1095210950
1095310951
1095410952
10955-
forac_funcin fseeko gethostname getopt_long getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul
10953+
10954+
forac_funcin fseeko getaddrinfo gethostname getopt_long getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul
1095610955
do
1095710956
as_ac_var=`echo"ac_cv_func_$ac_func"|$as_tr_sh`
1095810957
echo"$as_me:$LINENO: checking for$ac_func">&5
@@ -17013,7 +17012,6 @@ s,@python_moduleexecdir@,$python_moduleexecdir,;t t
1701317012
s,@python_includespec@,$python_includespec,;t t
1701417013
s,@python_libspec@,$python_libspec,;t t
1701517014
s,@LIBOBJS@,$LIBOBJS,;t t
17016-
s,@HAVE_IPV6@,$HAVE_IPV6,;t t
1701717015
s,@HPUXMATHLIB@,$HPUXMATHLIB,;t t
1701817016
s,@HAVE_POSIX_SIGNALS@,$HAVE_POSIX_SIGNALS,;t t
1701917017
s,@MSGFMT@,$MSGFMT,;t t

‎configure.in

Lines changed: 7 additions & 9 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.239 2003/03/21 17:18:34 petere Exp $
2+
dnl $Header: /cvsroot/pgsql/configure.in,v 1.240 2003/03/29 11:31:51 petere Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -791,14 +791,12 @@ AC_CHECK_FUNCS([cbrt dlopen fcvt fdatasync getpeereid memmove poll pstat setproc
791791

792792
AC_CHECK_DECLS(fdatasync, [], [], [#include <unistd.h>])
793793

794-
# This exports HAVE_IPV6 to both C files and Makefiles
795-
AC_CHECK_FUNC(getaddrinfo,
796-
[AC_CHECK_TYPE(struct sockaddr_in6,
797-
[HAVE_IPV6="yes"; AC_DEFINE(HAVE_IPV6, 1)],
798-
[],
794+
AC_CHECK_TYPE([struct sockaddr_in6],
795+
[AC_CHECK_FUNC(inet_ntop,
796+
[AC_DEFINE(HAVE_IPV6, 1)])],
797+
[],
799798
[$ac_includes_default
800-
#include <netinet/in.h>])])
801-
AC_SUBST(HAVE_IPV6)
799+
#include <netinet/in.h>])
802800

803801
AC_CACHE_CHECK([for PS_STRINGS], [pgac_cv_var_PS_STRINGS],
804802
[AC_TRY_LINK(
@@ -849,7 +847,7 @@ else
849847
AC_CHECK_FUNCS([fpclass fp_class fp_class_d class], [break])
850848
fi
851849

852-
AC_REPLACE_FUNCS([fseeko gethostname getopt_long getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul])
850+
AC_REPLACE_FUNCS([fseekogetaddrinfogethostname getopt_long getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul])
853851

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

‎src/Makefile.global.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*-makefile-*-
2-
# $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.159 2003/01/06 03:18:26 momjian Exp $
2+
# $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.160 2003/03/29 11:31:51 petere Exp $
33

44
#------------------------------------------------------------------------------
55
# All PostgreSQL makefiles include this file and use the variables it sets,
@@ -277,7 +277,6 @@ ifeq ($(enable_rpath), yes)
277277
LDFLAGS +=$(rpath)
278278
endif
279279

280-
HAVE_IPV6 = @HAVE_IPV6@
281280

282281
##########################################################################
283282
#

‎src/backend/libpq/ip.c

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/libpq/ip.c,v 1.2 2003/01/09 14:35:03 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/libpq/ip.c,v 1.3 2003/03/29 11:31:51 petere Exp $
1212
*
1313
* This file and the IPV6 implementation were initially provided by
1414
* Nigel Kukard <nkukard@lbsd.net>, Linux Based Systems Design
@@ -44,58 +44,27 @@
4444
#defineLOG stderr
4545
#endif
4646

47-
#if defined(HAVE_UNIX_SOCKETS)&& defined(HAVE_IPV6)
47+
#if defined(HAVE_UNIX_SOCKETS)
4848
staticintgetaddrinfo_unix(constchar*path,conststructaddrinfo*hintsp,
49-
structaddrinfo**result);
49+
structaddrinfo**result);
5050
#endif/* HAVE_UNIX_SOCKETS */
5151

5252
/*
5353
*getaddrinfo2 - get address info for Unix, IPv4 and IPv6 sockets
5454
*/
5555
int
5656
getaddrinfo2(constchar*hostname,constchar*servname,
57-
#ifdefHAVE_IPV6
5857
conststructaddrinfo*hintp,structaddrinfo**result)
59-
#else
60-
intfamily,SockAddr*result)
61-
#endif
6258
{
6359
#ifdefHAVE_UNIX_SOCKETS
64-
#ifdefHAVE_IPV6
6560
if (hintp!=NULL&&hintp->ai_family==AF_UNIX)
6661
returngetaddrinfo_unix(servname,hintp,result);
67-
#else
68-
if (family==AF_UNIX)
69-
return0;
70-
#endif
7162
else
7263
{
7364
#endif/* HAVE_UNIX_SOCKETS */
74-
#ifdefHAVE_IPV6
7565
/* NULL has special meaning to getaddrinfo */
7666
returngetaddrinfo((!hostname||hostname[0]=='\0') ?NULL :hostname,
7767
servname,hintp,result);
78-
#else
79-
if (hostname[0]=='\0')
80-
result->in.sin_addr.s_addr=htonl(INADDR_ANY);
81-
else
82-
{
83-
structhostent*hp;
84-
85-
hp=gethostbyname(hostname);
86-
if ((hp==NULL)|| (hp->h_addrtype!=AF_INET))
87-
{
88-
elog(LOG,"getaddrinfo2: gethostbyname(%s) failed\n",hostname);
89-
returnSTATUS_ERROR;
90-
}
91-
memmove((char*)&(result->in.sin_addr), (char*)hp->h_addr,
92-
hp->h_length);
93-
}
94-
95-
result->in.sin_port=htons((unsigned short)atoi(servname));
96-
return0;
97-
#endif/* HAVE_IPV6 */
98-
9968
#ifdefHAVE_UNIX_SOCKETS
10069
}
10170
#endif/* HAVE_UNIX_SOCKETS */
@@ -105,7 +74,6 @@ getaddrinfo2(const char *hostname, const char *servname,
10574
/*
10675
*freeaddrinfo2 - free IPv6 addrinfo structures
10776
*/
108-
#ifdefHAVE_IPV6
10977
void
11078
freeaddrinfo2(inthint_ai_family,structaddrinfo*ai)
11179
{
@@ -126,10 +94,9 @@ freeaddrinfo2(int hint_ai_family, struct addrinfo *ai)
12694
#endif/* HAVE_UNIX_SOCKETS */
12795
freeaddrinfo(ai);
12896
}
129-
#endif
13097

13198

132-
#if defined(HAVE_UNIX_SOCKETS)&& defined(HAVE_IPV6)
99+
#if defined(HAVE_UNIX_SOCKETS)
133100
/* -------
134101
*getaddrinfo_unix - get unix socket info using IPv6
135102
*
@@ -140,7 +107,7 @@ freeaddrinfo2(int hint_ai_family, struct addrinfo *ai)
140107
*/
141108
staticint
142109
getaddrinfo_unix(constchar*path,conststructaddrinfo*hintsp,
143-
structaddrinfo**result)
110+
structaddrinfo**result)
144111
{
145112
structaddrinfohints;
146113
structaddrinfo*aip;
@@ -159,9 +126,9 @@ getaddrinfo_unix(const char *path, const struct addrinfo *hintsp,
159126
if (hints.ai_socktype==0)
160127
hints.ai_socktype=SOCK_STREAM;
161128

162-
if (!(hints.ai_family==AF_UNIX))
129+
if (hints.ai_family!=AF_UNIX)
163130
{
164-
elog(LOG,"hints.ai_family isinvalied getaddrinfo_unix()\n");
131+
elog(LOG,"hints.ai_family isinvalid in getaddrinfo_unix()\n");
165132
returnEAI_ADDRFAMILY;
166133
}
167134

@@ -197,7 +164,7 @@ getaddrinfo_unix(const char *path, const struct addrinfo *hintsp,
197164

198165
return0;
199166
}
200-
#endif/* HAVE_UNIX_SOCKETS&& HAVE_IPV6*/
167+
#endif/* HAVE_UNIX_SOCKETS */
201168

202169
/* ----------
203170
* SockAddr_ntop - set IP address string from SockAddr

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp