diff --git a/ChangeLog b/ChangeLog index 42cded54ec..b901e3cb45 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Dec 31 05:56:38 2009 Nobuyoshi Nakada + + * 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 * thread_win32.c (native_thread_destroy): decreased the probability of diff --git a/ext/socket/addrinfo.h b/ext/socket/addrinfo.h index 171d3c2ce7..806b00e368 100644 --- a/ext/socket/addrinfo.h +++ b/ext/socket/addrinfo.h @@ -29,7 +29,6 @@ #ifndef ADDR_INFO_H #define ADDR_INFO_H -#ifndef HAVE_GETADDRINFO /* special compatibility hack */ #undef EAI_ADDRFAMILY @@ -62,17 +61,6 @@ #undef NI_NUMERICSERV #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 # ifdef HAVE_PROTOTYPES # define __P(args) args @@ -111,6 +99,7 @@ #define AI_NUMERICSERV 0x00000008 /* prevent service name resolution */ /* valid flags for addrinfo */ #ifndef __HAIKU__ +#undef AI_MASK #define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV) #endif @@ -138,6 +127,7 @@ #define NI_NUMERICSERV 0x00000008 #define NI_DGRAM 0x00000010 +#ifndef HAVE_TYPE_STRUCT_ADDRINFO struct addrinfo { int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ int ai_family; /* PF_xxx */ @@ -148,6 +138,24 @@ struct addrinfo { struct sockaddr *ai_addr; /* binary address */ 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(( const char *hostname, const char *servname, @@ -156,21 +164,20 @@ extern int getaddrinfo __P(( extern int getnameinfo __P(( const struct sockaddr *sa, - size_t salen, + socklen_t salen, char *host, - size_t hostlen, + socklen_t hostlen, char *serv, - size_t servlen, + socklen_t servlen, int flags)); extern void freehostent __P((struct hostent *)); extern void freeaddrinfo __P((struct addrinfo *)); -#if defined __UCLIBC__ +extern +#ifdef GAI_STRERROR_CONST const #endif -#ifndef __HAIKU__ -extern char *gai_strerror __P((int)); -#endif +char *gai_strerror __P((int)); /* In case there is no definition of offsetof() provided - though any proper Standard C system should have one. */ @@ -180,4 +187,3 @@ Standard C system should have one. */ #endif #endif -#endif diff --git a/ext/socket/depend b/ext/socket/depend index 000a013c5f..f870b9f834 100644 --- a/ext/socket/depend +++ b/ext/socket/depend @@ -1,6 +1,6 @@ SOCK_HEADERS = $(srcdir)/rubysocket.h $(hdrdir)/ruby/ruby.h $(arch_hdrdir)/ruby/config.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) constants.o: constants.c constdefs.c $(SOCK_HEADERS) diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb index 8b0f2eb110..7b744b4242 100644 --- a/ext/socket/extconf.rb +++ b/ext/socket/extconf.rb @@ -115,8 +115,8 @@ if have_func("sendmsg") | have_func("recvmsg") have_struct_member('struct msghdr', 'msg_accrights', ['sys/types.h', 'sys/socket.h']) end -getaddr_info_ok = enable_config("wide-getaddrinfo") do - checking_for("wide getaddrinfo") {try_run(< @@ -224,7 +224,6 @@ main() exit(EXIT_FAILURE); } EOF -end if ipv6 and not getaddr_info_ok abort < +void +conftest_gai_strerror_is_const() +{ + *gai_strerror(0) = 0; +} +EOF + $defs << "-DGAI_STRERROR_CONST" + end +end + $objs = [ "init.#{$OBJEXT}", "constants.#{$OBJEXT}", @@ -266,9 +282,13 @@ $objs = [ "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) - $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 $CPPFLAGS="-I. "+$CPPFLAGS $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_pton") or have_func("inet_aton") have_func("getservbyport") - if have_func("gai_strerror") - unless checking_for("gai_strerror() returns const pointer") {!try_compile(< -void -conftest_gai_strerror_is_const() -{ - *gai_strerror(0) = 0; -} -EOF - $defs << "-DGAI_STRERROR_CONST" - end - end have_header("arpa/nameser.h") have_header("resolv.h") end diff --git a/ext/socket/getaddrinfo.c b/ext/socket/getaddrinfo.c index 53656b4c02..d5ef517943 100644 --- a/ext/socket/getaddrinfo.c +++ b/ext/socket/getaddrinfo.c @@ -83,10 +83,6 @@ #include "addrinfo.h" #include "sockport.h" -#if defined(__KAME__) && defined(INET6) -# define FAITH -#endif - #define SUCCESS 0 #define ANY 0 #define YES 1 @@ -482,11 +478,7 @@ getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *h break; #ifdef INET6 case AF_INET6: -#ifdef HAVE_ADDR8 - pfx = ((struct in6_addr *)pton)->s6_addr8[0]; -#else pfx = ((struct in6_addr *)pton)->s6_addr[0]; -#endif if (pfx == 0 || pfx == 0xfe || pfx == 0xff) pai->ai_flags &= ~AI_CANONNAME; 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); in6 = &((struct sockaddr_in6 *)cur->ai_next->ai_addr)->sin6_addr; - memcpy(&in6->s6_addr32[0], &faith_prefix, - sizeof(struct in6_addr) - sizeof(struct in_addr)); - memcpy(&in6->s6_addr32[3], ap, sizeof(struct in_addr)); + memcpy(&in6->s6_addr, &faith_prefix, + sizeof(struct in6_addr) - sizeof(struct in_addr)); + memcpy(&in6->s6_addr + sizeof(struct in_addr), ap, + sizeof(struct in_addr)); } else #endif /* FAITH */ GET_AI(cur->ai_next, afd, ap, port); diff --git a/ext/socket/getnameinfo.c b/ext/socket/getnameinfo.c index 62a14ac555..7f090e9655 100644 --- a/ext/socket/getnameinfo.c +++ b/ext/socket/getnameinfo.c @@ -136,7 +136,7 @@ inet_ntop(int af, const void *addr, char *numaddr, size_t numaddr_len) #endif 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 hostent *hp; diff --git a/ext/socket/rubysocket.h b/ext/socket/rubysocket.h index 27980c3874..9f1bd6a62a 100644 --- a/ext/socket/rubysocket.h +++ b/ext/socket/rubysocket.h @@ -97,9 +97,7 @@ */ #define pseudo_AF_FTIP pseudo_AF_RTIP -#ifndef HAVE_GETADDRINFO -# include "addrinfo.h" -#endif +#include "addrinfo.h" #include "sockport.h" #ifndef NI_MAXHOST diff --git a/ext/socket/socket.c b/ext/socket/socket.c index bdc6d16d1c..f45880e366 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -904,7 +904,7 @@ sock_sockaddr(struct sockaddr *addr, size_t len) ptr = (char*)&((struct sockaddr_in*)addr)->sin_addr.s_addr; len = sizeof(((struct sockaddr_in*)addr)->sin_addr.s_addr); break; -#ifdef INET6 +#ifdef AF_INET6 case AF_INET6: ptr = (char*)&((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 sockaddr_obj(struct sockaddr *addr) { - socklen_t len; + size_t len; #if defined(AF_INET6) && defined(__KAME__) struct sockaddr_in6 addr6; #endif