diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/dbm/extconf.rb | 3 | ||||
-rw-r--r-- | ext/extmk.rb.in | 6 | ||||
-rw-r--r-- | ext/socket/addrinfo.h | 10 | ||||
-rw-r--r-- | ext/socket/extconf.rb | 40 | ||||
-rw-r--r-- | ext/socket/socket.c | 56 |
5 files changed, 76 insertions, 39 deletions
diff --git a/ext/dbm/extconf.rb b/ext/dbm/extconf.rb index c499df97ad..2f6255b50f 100644 --- a/ext/dbm/extconf.rb +++ b/ext/dbm/extconf.rb @@ -1,5 +1,8 @@ require 'mkmf' $LDFLAGS = "-L/usr/local/lib" +if dir = with_config("dbm-include") + $CFLAGS = "-I#{dir}" +end have_library("gdbm", "dbm_open") or have_library("db", "dbm_open") or have_library("dbm", "dbm_open") diff --git a/ext/extmk.rb.in b/ext/extmk.rb.in index e0b31528f7..e02194f15f 100644 --- a/ext/extmk.rb.in +++ b/ext/extmk.rb.in @@ -101,7 +101,11 @@ def try_link(src, opt="") cfile = open("conftest.c", "w") cfile.print src cfile.close - xsystem(format(LINK, $CFLAGS, $LDFLAGS, opt)) + begin + xsystem(format(LINK, $CFLAGS, $LDFLAGS, opt)) + ensure + system "rm -f conftest*" + end end def try_cpp(src, opt=$CFLAGS) diff --git a/ext/socket/addrinfo.h b/ext/socket/addrinfo.h index c6e0f7727f..612b941c65 100644 --- a/ext/socket/addrinfo.h +++ b/ext/socket/addrinfo.h @@ -48,6 +48,16 @@ #undef AI_PASSIVE #undef AI_CANONNAME #undef AI_NUMERICHOST +#undef AI_ALL +#undef AI_ADDRCONFIG +#undef AI_V4MAPPED +#undef AI_DEFAULT + +#undef NI_NOFQDN +#undef NI_NUMERICHOST +#undef NI_NAMEREQD +#undef NI_NUMERICSERV +#undef NI_DGRAM #define addrinfo addrinfo__compat #define getaddrinfo getaddrinfo__compat diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb index 5e059a425f..0fc5042b7d 100644 --- a/ext/socket/extconf.rb +++ b/ext/socket/extconf.rb @@ -1,7 +1,6 @@ require 'mkmf' $LDFLAGS = "-L/usr/local/lib" if File.directory?("/usr/local/lib") $CFLAGS ||= "" -$CFLAGS+=" -Dss_family=__ss_family -Dss_len=__ss_len" case PLATFORM when /mswin32/ @@ -28,7 +27,6 @@ if enable_config("ipv6", "yes") #include <sys/socket.h> main() { - exit(0); if (socket(AF_INET6, SOCK_STREAM, 0) < 0) exit(1); else @@ -236,17 +234,47 @@ end $objs = ["socket.o"] -if $getaddr_info_ok - have_func("getaddrinfo") - have_func("getnameinfo") +if $getaddr_info_ok or not $ipv6 + if have_func("getaddrinfo") and + have_func("getnameinfo") + have_getaddrinfo = true + end +end + +if have_getaddrinfo + if try_link(<<EOF) +#include <sys/types.h> +#include <netdb.h> +#include <string.h> +#include <sys/socket.h> +#include <netinet/in.h> +int +main() +{ + struct sockaddr_storage storage; + struct sockaddr_storage *addr; + + addr = &storage; + return 0; +} +EOF + sockaddr_storage=true + end else + sockaddr_storage=true + $CFLAGS="-I. "+$CFLAGS $objs += "getaddrinfo.o" $objs += "getnameinfo.o" end +if sockaddr_storage + $CFLAGS="-DSOCKADDR_STORAGE "+$CFLAGS +end + +p $ipv6 + have_header("sys/un.h") if have_func(test_func) - have_func("inet_aton") have_func("hsterror") unless have_func("gethostname") have_func("uname") diff --git a/ext/socket/socket.c b/ext/socket/socket.c index f8a0297ff3..840d1fad3a 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -48,6 +48,17 @@ extern int rb_thread_select(int, fd_set*, fd_set*, fd_set*, struct timeval*); /* # include "addrinfo.h" #endif +#ifdef SOCKADDR_STORAGE +# define ss_falily __ss_family +# define SS_LEN(ss) (ss)->__ss_len +#else +# define SOCKADDR_STORAGE sockaddr +# define ss_family sa_family +# ifdef SA_LEN +# define SS_LEN(ss) SA_LEN(ss) +# endif +#endif + VALUE rb_cBasicSocket; VALUE rb_cIPSocket; VALUE rb_cTCPSocket; @@ -468,27 +479,6 @@ ipaddr(sockaddr) } -#ifndef HAVE_INET_ATON -static unsigned long -inet_aton(host, inp) - char *host; - struct in_addr *inp; -{ - int d1, d2, d3, d4; - char ch; - - if (sscanf(host, "%d.%d.%d.%d%c", &d1, &d2, &d3, &d4, &ch) == 4 && - 0 <= d1 && d1 <= 255 && 0 <= d2 && d2 <= 255 && - 0 <= d3 && d3 <= 255 && 0 <= d4 && d4 <= 255) { - inp->s_addr = htonl( - ((long) d1 << 24) | ((long) d2 << 16) | - ((long) d3 << 8) | ((long) d4 << 0)); - return 1; - } - return 0; -} -#endif - static void setipaddr(name, addr) char *name; @@ -713,7 +703,7 @@ static VALUE tcp_s_gethostbyname(obj, host) VALUE obj, host; { - struct sockaddr_storage addr; + struct SOCKADDR_STORAGE addr; struct hostent *h; char **pch; VALUE ary, names; @@ -756,9 +746,9 @@ tcp_s_gethostbyname(obj, host) } if (h == NULL) { -#ifdef HAVE_HSTRERROR +#ifdef HAVE_HSTERROR extern int h_errno; - rb_raise(rb_eSocket, (char *)hstrerror(h_errno)); + rb_raise(rb_eSocket, (char *)hsterror(h_errno)); #else rb_raise(rb_eSocket, "host not found"); #endif @@ -862,7 +852,7 @@ tcp_accept(sock) VALUE sock; { OpenFile *fptr; - struct sockaddr_storage from; + struct SOCKADDR_STORAGE from; int fromlen; GetOpenFile(sock, fptr); @@ -928,7 +918,7 @@ ip_addr(sock) VALUE sock; { OpenFile *fptr; - struct sockaddr_storage addr; + struct SOCKADDR_STORAGE addr; int len = sizeof addr; GetOpenFile(sock, fptr); @@ -943,7 +933,7 @@ ip_peeraddr(sock) VALUE sock; { OpenFile *fptr; - struct sockaddr_storage addr; + struct SOCKADDR_STORAGE addr; int len = sizeof addr; GetOpenFile(sock, fptr); @@ -957,7 +947,7 @@ static VALUE ip_s_getaddress(obj, host) VALUE obj, host; { - struct sockaddr_storage addr; + struct SOCKADDR_STORAGE addr; if (rb_obj_is_kind_of(host, rb_cInteger)) { int i = NUM2INT(host); @@ -1081,7 +1071,7 @@ static VALUE udp_bind(sock, host, port) VALUE sock, host, port; { - struct sockaddr_storage addr; + struct SOCKADDR_STORAGE addr; OpenFile *fptr; struct addrinfo *res0, *res; @@ -1551,7 +1541,7 @@ static VALUE sock_s_gethostbyname(obj, host) VALUE obj, host; { - struct sockaddr_storage addr; + struct SOCKADDR_STORAGE addr; struct hostent *h; if (rb_obj_is_kind_of(host, rb_cInteger)) { @@ -1722,7 +1712,7 @@ sock_s_getnameinfo(argc, argv) int fl; struct addrinfo hints, *res = NULL; int error; - struct sockaddr_storage ss; + struct SOCKADDR_STORAGE ss; struct sockaddr *sap; sa = flags = Qnil; @@ -1733,9 +1723,11 @@ sock_s_getnameinfo(argc, argv) rb_raise(rb_eTypeError, "sockaddr length too big"); } memcpy(&ss, RSTRING(sa)->ptr, RSTRING(sa)->len); - if (RSTRING(sa)->len != ss.ss_len) { +#ifdef SS_LEN + if (RSTRING(sa)->len != SS_LEN(&ss)) { rb_raise(rb_eTypeError, "sockaddr size differs - should not happen"); } +#endif sap = (struct sockaddr *)&ss; } else if (TYPE(sa) == T_ARRAY) { |