summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/socket/MANIFEST4
-rw-r--r--ext/socket/addrinfo.h20
-rw-r--r--ext/socket/depend6
-rw-r--r--ext/socket/extconf.rb12
-rw-r--r--ext/socket/getaddrinfo.c9
-rw-r--r--ext/socket/getnameinfo.c1
-rw-r--r--ext/socket/socket.c27
-rw-r--r--ext/socket/sockport.h43
8 files changed, 71 insertions, 51 deletions
diff --git a/ext/socket/MANIFEST b/ext/socket/MANIFEST
index d41d9e0..616d459 100644
--- a/ext/socket/MANIFEST
+++ b/ext/socket/MANIFEST
@@ -1,4 +1,8 @@
MANIFEST
+addrinfo.h
depend
extconf.rb
+getaddrinfo.c
+getnameinfo.c
+sockport.h
socket.c
diff --git a/ext/socket/addrinfo.h b/ext/socket/addrinfo.h
index 612b941..83cc6c6 100644
--- a/ext/socket/addrinfo.h
+++ b/ext/socket/addrinfo.h
@@ -65,26 +65,6 @@
#define freehostent freehostent__compat
#define freeaddrinfo freeaddrinfo__compat
-#ifdef HAVE_SIN_LEN
-# define SIN_LEN(si) (si).sin_len
-# define SET_SIN_LEN(si,len) (si).sin_len = (len)
-#else
-# define SIN_LEN(si) sizeof(struct sockaddr_in)
-# define SET_SIN_LEN(si,len) (len)
-#endif
-
-#ifdef HAVE_SA_LEN
-#ifndef SA_LEN
-# define SA_LEN(sa) (sa).sin_len
-#endif
-#define SET_SA_LEN(sa, len) (sa).sin_len = len
-#else
-#ifndef SA_LEN
-extern int addrinfo_sockaddr_len __P((struct sockaddr*));
-# define SA_LEN(sa) addrinfo_sockaddr_len((sa))
-#endif
-#define SET_SA_LEN(sa, len) (len)
-#endif
/* special compatibility hack -- end*/
diff --git a/ext/socket/depend b/ext/socket/depend
index ee405e9..09e8514 100644
--- a/ext/socket/depend
+++ b/ext/socket/depend
@@ -1,3 +1,3 @@
-socket.o : socket.c $(hdrdir)/ruby.h $(hdrdir)/config.h $(hdrdir)/defines.h $(hdrdir)/rubyio.h $(hdrdir)/rubysig.h
-
-.PATH: $(hdrdir)/missing
+socket.o : socket.c $(hdrdir)/ruby.h $(hdrdir)/config.h $(hdrdir)/defines.h $(hdrdir)/rubyio.h $(hdrdir)/rubysig.h sockport.h
+getaddrinfo.o: getaddrinfo.c addrinfo.h sockport.h
+getnameinfo.o: getnameinfo.c addrinfo.h sockport.h
diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb
index c83c65c..0ad85c5 100644
--- a/ext/socket/extconf.rb
+++ b/ext/socket/extconf.rb
@@ -1,6 +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/
@@ -100,7 +100,7 @@ EOF
end
if $ipv6lib
- if File.directory? $ipv6libdir and File.exist? "#{$ipv6libdir}/#{ipv6lib}.a"
+ if File.directory? $ipv6libdir and File.exist? "#{$ipv6libdir}/lib#{$ipv6lib}.a"
$LDFLAGS += " -L#$ipv6libdir -l#$ipv6lib"
else
print <<EOS
@@ -236,7 +236,7 @@ end
$objs = ["socket.o"]
-if $getaddr_info_ok or not $ipv6
+if $getaddr_info_ok
if have_func("getaddrinfo") and
have_func("getnameinfo")
have_getaddrinfo = true
@@ -244,6 +244,7 @@ if $getaddr_info_ok or not $ipv6
end
if have_getaddrinfo
+ $CFLAGS="-DHAVE_GETADDRINFO "+$CFLAGS
if try_link(<<EOF)
#include <sys/types.h>
#include <netdb.h>
@@ -256,12 +257,13 @@ main()
struct sockaddr_storage storage;
struct sockaddr_storage *addr = 0;
- addr->_ss_family = &storage.__ss_family;
- addr->_ss_len = &storage.__ss_len;
+ addr->__ss_family = &storage.__ss_family;
+ addr->__ss_len = &storage.__ss_len;
return 0;
}
EOF
sockaddr_storage=true
+ $CFLAGS+=" -DHAVE_SS_LEN"
end
else
sockaddr_storage=true
diff --git a/ext/socket/getaddrinfo.c b/ext/socket/getaddrinfo.c
index 4b7592a..45657b6 100644
--- a/ext/socket/getaddrinfo.c
+++ b/ext/socket/getaddrinfo.c
@@ -54,6 +54,7 @@
#include <unistd.h>
#include "addrinfo.h"
+#include "sockport.h"
#if defined(__KAME__) && defined(INET6)
# define FAITH
@@ -605,11 +606,3 @@ get_addr(hostname, af, res, pai, port0)
*res = NULL;
return error;
}
-
-int
-addrinfo_sockaddr_len(sa)
- struct sockaddr *sa;
-{
- /* should support other protocol families */
- return sizeof(struct sockaddr_in);
-}
diff --git a/ext/socket/getnameinfo.c b/ext/socket/getnameinfo.c
index 02a2454..99404b1 100644
--- a/ext/socket/getnameinfo.c
+++ b/ext/socket/getnameinfo.c
@@ -45,6 +45,7 @@
#include <stddef.h>
#include "addrinfo.h"
+#include "sockport.h"
#define SUCCESS 0
#define ANY 0
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 067c6d3..7fb51f7 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -47,16 +47,14 @@ extern int rb_thread_select(int, fd_set*, fd_set*, fd_set*, struct timeval*); /*
#ifndef HAVE_GETADDRINFO
# include "addrinfo.h"
#endif
+#include "sockport.h"
#ifdef SOCKADDR_STORAGE
-# define ss_family __ss_family
-# define SS_LEN(ss) (ss)->__ss_len
+# define SS_LEN(ss) (ss)->ss_len
#else
# define SOCKADDR_STORAGE sockaddr
+# undef ss_family
# define ss_family sa_family
-# ifdef SA_LEN
-# define SS_LEN(ss) SA_LEN(ss)
-# endif
#endif
VALUE rb_cBasicSocket;
@@ -478,7 +476,6 @@ ipaddr(sockaddr)
return ary;
}
-
static void
setipaddr(name, addr)
char *name;
@@ -492,12 +489,12 @@ setipaddr(name, addr)
if (name[0] == 0) {
memset(sin, 0, sizeof(*sin));
sin->sin_family = AF_INET;
- SET_SIN_LEN(*sin, sizeof(*sin));
+ SET_SIN_LEN(sin, sizeof(*sin));
sin->sin_addr.s_addr = INADDR_ANY;
}
else if (name[0] == '<' && strcmp(name, "<broadcast>") == 0) {
sin->sin_family = AF_INET;
- SET_SIN_LEN(*sin, sizeof(*sin));
+ SET_SIN_LEN(sin, sizeof(*sin));
sin->sin_addr.s_addr = INADDR_BROADCAST;
}
else {
@@ -769,7 +766,7 @@ tcp_s_gethostbyname(obj, host)
struct sockaddr_in sin;
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
- SET_SIN_LEN(sin, sizeof(sin));
+ SET_SIN_LEN(&sin, sizeof(sin));
memcpy((char *) &sin.sin_addr, *pch, h->h_length);
h = gethostbyaddr((char *)&sin.sin_addr,
sizeof(sin.sin_addr),
@@ -955,7 +952,7 @@ ip_s_getaddress(obj, host)
sin = (struct sockaddr_in *)&addr;
memset(sin, 0, sizeof(*sin));
sin->sin_family = AF_INET;
- SET_SIN_LEN(*sin, sizeof(*sin));
+ SET_SIN_LEN(sin, sizeof(*sin));
sin->sin_addr.s_addr = htonl(i);
}
else {
@@ -1004,10 +1001,10 @@ udp_addrsetup(fptr, host, port)
int i = NUM2INT(host);
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
- SET_SIN_LEN(sin, sizeof(sin));
+ SET_SIN_LEN(&sin, sizeof(sin));
sin.sin_addr.s_addr = htonl(i);
- error = getnameinfo((struct sockaddr *)&sin, SIN_LEN(sin),
- hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST);
+ error = getnameinfo((struct sockaddr *)&sin, SIN_LEN(&sin),
+ hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST);
if (error) {
rb_raise(rb_eSocket, gai_strerror(error));
}
@@ -1550,7 +1547,7 @@ sock_s_gethostbyname(obj, host)
sin = (struct sockaddr_in *)&addr;
memset(sin, 0, sizeof(*sin));
sin->sin_family = AF_INET;
- SET_SIN_LEN(*sin, sizeof(*sin));
+ SET_SIN_LEN(sin, sizeof(*sin));
sin->sin_addr.s_addr = htonl(i);
}
else {
@@ -1723,7 +1720,7 @@ sock_s_getnameinfo(argc, argv)
rb_raise(rb_eTypeError, "sockaddr length too big");
}
memcpy(&ss, RSTRING(sa)->ptr, RSTRING(sa)->len);
-#ifdef SS_LEN
+#ifdef HAVE_SS_LEN
if (RSTRING(sa)->len != SS_LEN(&ss)) {
rb_raise(rb_eTypeError, "sockaddr size differs - should not happen");
}
diff --git a/ext/socket/sockport.h b/ext/socket/sockport.h
new file mode 100644
index 0000000..bb3b371
--- /dev/null
+++ b/ext/socket/sockport.h
@@ -0,0 +1,43 @@
+/************************************************
+
+ sockcomm.h -
+
+ $Author$
+ $Date$
+ created at: Fri Apr 30 23:19:34 JST 1999
+
+************************************************/
+
+#ifndef SOCKCOMM_H
+#define SOCKCOMM_H
+
+#ifndef SA_LEN
+# ifdef HAVE_SA_LEN
+# define SA_LEN(sa) (sa)->sin_len
+# else
+# ifdef INET6
+# define SA_LEN(sa) \
+ (((sa)->sa_family == AF_INET6) ? sizeof(struct sockaddr_in6) \
+ : sizeof(struct sockaddr))
+# else
+ /* by tradition, sizeof(struct sockaddr) covers most of the sockaddrs */
+# define SA_LEN(sa) (sizeof(struct sockaddr))
+# endif
+# endif
+#endif
+
+#ifdef HAVE_SA_LEN
+# define SET_SA_LEN(sa, len) (sa)->sin_len = (len)
+#else
+# define SET_SA_LEN(sa, len) (len)
+#endif
+
+#ifdef HAVE_SIN_LEN
+# define SIN_LEN(si) (si)->sin_len
+# define SET_SIN_LEN(si,len) (si)->sin_len = (len)
+#else
+# define SIN_LEN(si) sizeof(struct sockaddr_in)
+# define SET_SIN_LEN(si,len) (len)
+#endif
+
+#endif