зеркало из https://github.com/github/ruby.git
* ext/socket/extconf.rb: fix for wide-getaddrinfo option.
* ext/socket/addrinfo.c: rename {addr,name}info functions to ensure those are used on darwin. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26209 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
6e4df2896f
Коммит
1069e0f335
|
@ -1,3 +1,10 @@
|
||||||
|
Thu Dec 31 05:56:38 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/socket/extconf.rb: fix for wide-getaddrinfo option.
|
||||||
|
|
||||||
|
* ext/socket/addrinfo.c: rename {addr,name}info functions to ensure
|
||||||
|
those are used on darwin.
|
||||||
|
|
||||||
Thu Dec 31 03:27:53 2009 NAKAMURA Usaku <usa@ruby-lang.org>
|
Thu Dec 31 03:27:53 2009 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* thread_win32.c (native_thread_destroy): decreased the probability of
|
* thread_win32.c (native_thread_destroy): decreased the probability of
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
|
|
||||||
#ifndef ADDR_INFO_H
|
#ifndef ADDR_INFO_H
|
||||||
#define ADDR_INFO_H
|
#define ADDR_INFO_H
|
||||||
#ifndef HAVE_GETADDRINFO
|
|
||||||
|
|
||||||
/* special compatibility hack */
|
/* special compatibility hack */
|
||||||
#undef EAI_ADDRFAMILY
|
#undef EAI_ADDRFAMILY
|
||||||
|
@ -62,17 +61,6 @@
|
||||||
#undef NI_NUMERICSERV
|
#undef NI_NUMERICSERV
|
||||||
#undef NI_DGRAM
|
#undef NI_DGRAM
|
||||||
|
|
||||||
#undef addrinfo
|
|
||||||
#define addrinfo addrinfo__compat
|
|
||||||
#undef getaddrinfo
|
|
||||||
#define getaddrinfo getaddrinfo__compat
|
|
||||||
#undef getnameinfo
|
|
||||||
#define getnameinfo getnameinfo__compat
|
|
||||||
#undef freehostent
|
|
||||||
#define freehostent freehostent__compat
|
|
||||||
#undef freeaddrinfo
|
|
||||||
#define freeaddrinfo freeaddrinfo__compat
|
|
||||||
|
|
||||||
#ifndef __P
|
#ifndef __P
|
||||||
# ifdef HAVE_PROTOTYPES
|
# ifdef HAVE_PROTOTYPES
|
||||||
# define __P(args) args
|
# define __P(args) args
|
||||||
|
@ -111,6 +99,7 @@
|
||||||
#define AI_NUMERICSERV 0x00000008 /* prevent service name resolution */
|
#define AI_NUMERICSERV 0x00000008 /* prevent service name resolution */
|
||||||
/* valid flags for addrinfo */
|
/* valid flags for addrinfo */
|
||||||
#ifndef __HAIKU__
|
#ifndef __HAIKU__
|
||||||
|
#undef AI_MASK
|
||||||
#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV)
|
#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -138,6 +127,7 @@
|
||||||
#define NI_NUMERICSERV 0x00000008
|
#define NI_NUMERICSERV 0x00000008
|
||||||
#define NI_DGRAM 0x00000010
|
#define NI_DGRAM 0x00000010
|
||||||
|
|
||||||
|
#ifndef HAVE_TYPE_STRUCT_ADDRINFO
|
||||||
struct addrinfo {
|
struct addrinfo {
|
||||||
int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
|
int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
|
||||||
int ai_family; /* PF_xxx */
|
int ai_family; /* PF_xxx */
|
||||||
|
@ -148,6 +138,24 @@ struct addrinfo {
|
||||||
struct sockaddr *ai_addr; /* binary address */
|
struct sockaddr *ai_addr; /* binary address */
|
||||||
struct addrinfo *ai_next; /* next structure in linked list */
|
struct addrinfo *ai_next; /* next structure in linked list */
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_GETADDRINFO
|
||||||
|
#undef getaddrinfo
|
||||||
|
#define getaddrinfo getaddrinfo__compat
|
||||||
|
#endif
|
||||||
|
#ifndef HAVE_GETNAMEINFO
|
||||||
|
#undef getnameinfo
|
||||||
|
#define getnameinfo getnameinfo__compat
|
||||||
|
#endif
|
||||||
|
#ifndef HAVE_FREEHOSTENT
|
||||||
|
#undef freehostent
|
||||||
|
#define freehostent freehostent__compat
|
||||||
|
#endif
|
||||||
|
#ifndef HAVE_FREEADDRINFO
|
||||||
|
#undef freeaddrinfo
|
||||||
|
#define freeaddrinfo freeaddrinfo__compat
|
||||||
|
#endif
|
||||||
|
|
||||||
extern int getaddrinfo __P((
|
extern int getaddrinfo __P((
|
||||||
const char *hostname, const char *servname,
|
const char *hostname, const char *servname,
|
||||||
|
@ -156,21 +164,20 @@ extern int getaddrinfo __P((
|
||||||
|
|
||||||
extern int getnameinfo __P((
|
extern int getnameinfo __P((
|
||||||
const struct sockaddr *sa,
|
const struct sockaddr *sa,
|
||||||
size_t salen,
|
socklen_t salen,
|
||||||
char *host,
|
char *host,
|
||||||
size_t hostlen,
|
socklen_t hostlen,
|
||||||
char *serv,
|
char *serv,
|
||||||
size_t servlen,
|
socklen_t servlen,
|
||||||
int flags));
|
int flags));
|
||||||
|
|
||||||
extern void freehostent __P((struct hostent *));
|
extern void freehostent __P((struct hostent *));
|
||||||
extern void freeaddrinfo __P((struct addrinfo *));
|
extern void freeaddrinfo __P((struct addrinfo *));
|
||||||
#if defined __UCLIBC__
|
extern
|
||||||
|
#ifdef GAI_STRERROR_CONST
|
||||||
const
|
const
|
||||||
#endif
|
#endif
|
||||||
#ifndef __HAIKU__
|
char *gai_strerror __P((int));
|
||||||
extern char *gai_strerror __P((int));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* In case there is no definition of offsetof() provided - though any proper
|
/* In case there is no definition of offsetof() provided - though any proper
|
||||||
Standard C system should have one. */
|
Standard C system should have one. */
|
||||||
|
@ -180,4 +187,3 @@ Standard C system should have one. */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
SOCK_HEADERS = $(srcdir)/rubysocket.h $(hdrdir)/ruby/ruby.h $(arch_hdrdir)/ruby/config.h \
|
SOCK_HEADERS = $(srcdir)/rubysocket.h $(hdrdir)/ruby/ruby.h $(arch_hdrdir)/ruby/config.h \
|
||||||
$(hdrdir)/ruby/defines.h $(hdrdir)/ruby/io.h \
|
$(hdrdir)/ruby/defines.h $(hdrdir)/ruby/io.h \
|
||||||
$(srcdir)/sockport.h constdefs.h
|
$(srcdir)/addrinfo.h $(srcdir)/sockport.h constdefs.h
|
||||||
|
|
||||||
init.o: init.c $(SOCK_HEADERS)
|
init.o: init.c $(SOCK_HEADERS)
|
||||||
constants.o: constants.c constdefs.c $(SOCK_HEADERS)
|
constants.o: constants.c constdefs.c $(SOCK_HEADERS)
|
||||||
|
|
|
@ -115,8 +115,8 @@ if have_func("sendmsg") | have_func("recvmsg")
|
||||||
have_struct_member('struct msghdr', 'msg_accrights', ['sys/types.h', 'sys/socket.h'])
|
have_struct_member('struct msghdr', 'msg_accrights', ['sys/types.h', 'sys/socket.h'])
|
||||||
end
|
end
|
||||||
|
|
||||||
getaddr_info_ok = enable_config("wide-getaddrinfo") do
|
getaddr_info_ok = (enable_config("wide-getaddrinfo") && :wide) ||
|
||||||
checking_for("wide getaddrinfo") {try_run(<<EOF)}
|
(checking_for("wide getaddrinfo") {try_run(<<EOF)} && :os)
|
||||||
#{cpp_include(headers)}
|
#{cpp_include(headers)}
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
@ -224,7 +224,6 @@ main()
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
end
|
|
||||||
if ipv6 and not getaddr_info_ok
|
if ipv6 and not getaddr_info_ok
|
||||||
abort <<EOS
|
abort <<EOS
|
||||||
|
|
||||||
|
@ -249,6 +248,23 @@ Fatal: invalid value for --with-lookup-order-hack (expected INET, INET6 or UNSPE
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
have_type("struct addrinfo", headers)
|
||||||
|
have_func("freehostent")
|
||||||
|
have_func("freeaddrinfo")
|
||||||
|
if /haiku/ !~ RUBY_PLATFORM and have_func("gai_strerror")
|
||||||
|
if checking_for("gai_strerror() returns const pointer") {!try_compile(<<EOF)}
|
||||||
|
#{cpp_include(headers)}
|
||||||
|
#include <stdlib.h>
|
||||||
|
void
|
||||||
|
conftest_gai_strerror_is_const()
|
||||||
|
{
|
||||||
|
*gai_strerror(0) = 0;
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
$defs << "-DGAI_STRERROR_CONST"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
$objs = [
|
$objs = [
|
||||||
"init.#{$OBJEXT}",
|
"init.#{$OBJEXT}",
|
||||||
"constants.#{$OBJEXT}",
|
"constants.#{$OBJEXT}",
|
||||||
|
@ -266,9 +282,13 @@ $objs = [
|
||||||
"raddrinfo.#{$OBJEXT}"
|
"raddrinfo.#{$OBJEXT}"
|
||||||
]
|
]
|
||||||
|
|
||||||
unless getaddr_info_ok and have_func("getnameinfo", headers) and have_func("getaddrinfo", headers)
|
if getaddr_info_ok == :wide or
|
||||||
|
!have_func("getnameinfo", headers) or !have_func("getaddrinfo", headers)
|
||||||
if have_struct_member("struct in6_addr", "s6_addr8", headers)
|
if have_struct_member("struct in6_addr", "s6_addr8", headers)
|
||||||
$defs[-1] = "-DHAVE_ADDR8"
|
$defs[-1] = "s6_addr=s6_addr8"
|
||||||
|
end
|
||||||
|
if ipv6 == "kame" && have_struct_member("struct in6_addr", "s6_addr32", headers)
|
||||||
|
$defs[-1] = "-DFAITH"
|
||||||
end
|
end
|
||||||
$CPPFLAGS="-I. "+$CPPFLAGS
|
$CPPFLAGS="-I. "+$CPPFLAGS
|
||||||
$objs += ["getaddrinfo.#{$OBJEXT}"]
|
$objs += ["getaddrinfo.#{$OBJEXT}"]
|
||||||
|
@ -277,19 +297,6 @@ unless getaddr_info_ok and have_func("getnameinfo", headers) and have_func("geta
|
||||||
have_func("inet_ntop") or have_func("inet_ntoa")
|
have_func("inet_ntop") or have_func("inet_ntoa")
|
||||||
have_func("inet_pton") or have_func("inet_aton")
|
have_func("inet_pton") or have_func("inet_aton")
|
||||||
have_func("getservbyport")
|
have_func("getservbyport")
|
||||||
if have_func("gai_strerror")
|
|
||||||
unless checking_for("gai_strerror() returns const pointer") {!try_compile(<<EOF)}
|
|
||||||
#{cpp_include(headers)}
|
|
||||||
#include <stdlib.h>
|
|
||||||
void
|
|
||||||
conftest_gai_strerror_is_const()
|
|
||||||
{
|
|
||||||
*gai_strerror(0) = 0;
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
$defs << "-DGAI_STRERROR_CONST"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
have_header("arpa/nameser.h")
|
have_header("arpa/nameser.h")
|
||||||
have_header("resolv.h")
|
have_header("resolv.h")
|
||||||
end
|
end
|
||||||
|
|
|
@ -83,10 +83,6 @@
|
||||||
#include "addrinfo.h"
|
#include "addrinfo.h"
|
||||||
#include "sockport.h"
|
#include "sockport.h"
|
||||||
|
|
||||||
#if defined(__KAME__) && defined(INET6)
|
|
||||||
# define FAITH
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SUCCESS 0
|
#define SUCCESS 0
|
||||||
#define ANY 0
|
#define ANY 0
|
||||||
#define YES 1
|
#define YES 1
|
||||||
|
@ -482,11 +478,7 @@ getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *h
|
||||||
break;
|
break;
|
||||||
#ifdef INET6
|
#ifdef INET6
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
#ifdef HAVE_ADDR8
|
|
||||||
pfx = ((struct in6_addr *)pton)->s6_addr8[0];
|
|
||||||
#else
|
|
||||||
pfx = ((struct in6_addr *)pton)->s6_addr[0];
|
pfx = ((struct in6_addr *)pton)->s6_addr[0];
|
||||||
#endif
|
|
||||||
if (pfx == 0 || pfx == 0xfe || pfx == 0xff)
|
if (pfx == 0 || pfx == 0xfe || pfx == 0xff)
|
||||||
pai->ai_flags &= ~AI_CANONNAME;
|
pai->ai_flags &= ~AI_CANONNAME;
|
||||||
break;
|
break;
|
||||||
|
@ -651,9 +643,10 @@ get_addr(const char *hostname, int af, struct addrinfo **res, struct addrinfo *p
|
||||||
|
|
||||||
GET_AI(cur->ai_next, &afdl[N_INET6], ap, port);
|
GET_AI(cur->ai_next, &afdl[N_INET6], ap, port);
|
||||||
in6 = &((struct sockaddr_in6 *)cur->ai_next->ai_addr)->sin6_addr;
|
in6 = &((struct sockaddr_in6 *)cur->ai_next->ai_addr)->sin6_addr;
|
||||||
memcpy(&in6->s6_addr32[0], &faith_prefix,
|
memcpy(&in6->s6_addr, &faith_prefix,
|
||||||
sizeof(struct in6_addr) - sizeof(struct in_addr));
|
sizeof(struct in6_addr) - sizeof(struct in_addr));
|
||||||
memcpy(&in6->s6_addr32[3], ap, sizeof(struct in_addr));
|
memcpy(&in6->s6_addr + sizeof(struct in_addr), ap,
|
||||||
|
sizeof(struct in_addr));
|
||||||
} else
|
} else
|
||||||
#endif /* FAITH */
|
#endif /* FAITH */
|
||||||
GET_AI(cur->ai_next, afd, ap, port);
|
GET_AI(cur->ai_next, afd, ap, port);
|
||||||
|
|
|
@ -136,7 +136,7 @@ inet_ntop(int af, const void *addr, char *numaddr, size_t numaddr_len)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags)
|
getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags)
|
||||||
{
|
{
|
||||||
struct afd *afd;
|
struct afd *afd;
|
||||||
struct hostent *hp;
|
struct hostent *hp;
|
||||||
|
|
|
@ -97,9 +97,7 @@
|
||||||
*/
|
*/
|
||||||
#define pseudo_AF_FTIP pseudo_AF_RTIP
|
#define pseudo_AF_FTIP pseudo_AF_RTIP
|
||||||
|
|
||||||
#ifndef HAVE_GETADDRINFO
|
#include "addrinfo.h"
|
||||||
# include "addrinfo.h"
|
|
||||||
#endif
|
|
||||||
#include "sockport.h"
|
#include "sockport.h"
|
||||||
|
|
||||||
#ifndef NI_MAXHOST
|
#ifndef NI_MAXHOST
|
||||||
|
|
|
@ -904,7 +904,7 @@ sock_sockaddr(struct sockaddr *addr, size_t len)
|
||||||
ptr = (char*)&((struct sockaddr_in*)addr)->sin_addr.s_addr;
|
ptr = (char*)&((struct sockaddr_in*)addr)->sin_addr.s_addr;
|
||||||
len = sizeof(((struct sockaddr_in*)addr)->sin_addr.s_addr);
|
len = sizeof(((struct sockaddr_in*)addr)->sin_addr.s_addr);
|
||||||
break;
|
break;
|
||||||
#ifdef INET6
|
#ifdef AF_INET6
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
ptr = (char*)&((struct sockaddr_in6*)addr)->sin6_addr.s6_addr;
|
ptr = (char*)&((struct sockaddr_in6*)addr)->sin6_addr.s6_addr;
|
||||||
len = sizeof(((struct sockaddr_in6*)addr)->sin6_addr.s6_addr);
|
len = sizeof(((struct sockaddr_in6*)addr)->sin6_addr.s6_addr);
|
||||||
|
@ -1414,7 +1414,7 @@ sock_s_unpack_sockaddr_un(VALUE self, VALUE addr)
|
||||||
static VALUE
|
static VALUE
|
||||||
sockaddr_obj(struct sockaddr *addr)
|
sockaddr_obj(struct sockaddr *addr)
|
||||||
{
|
{
|
||||||
socklen_t len;
|
size_t len;
|
||||||
#if defined(AF_INET6) && defined(__KAME__)
|
#if defined(AF_INET6) && defined(__KAME__)
|
||||||
struct sockaddr_in6 addr6;
|
struct sockaddr_in6 addr6;
|
||||||
#endif
|
#endif
|
||||||
|
|
Загрузка…
Ссылка в новой задаче