[前][次][番号順一覧][スレッド一覧]

ruby-changes:10319

From: usa <ko1@a...>
Date: Thu, 29 Jan 2009 11:25:58 +0900 (JST)
Subject: [ruby-changes:10319] Ruby:r21863 (trunk): * ext/socket/spclet.c (socket_s_ip_address_list): support Windows XP

usa	2009-01-29 11:25:39 +0900 (Thu, 29 Jan 2009)

  New Revision: 21863

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21863

  Log:
    * ext/socket/spclet.c (socket_s_ip_address_list): support Windows XP
      or later. (Win2k or earlier is still not supported)

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/raddrinfo.c
    trunk/ext/socket/socket.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 21862)
+++ ChangeLog	(revision 21863)
@@ -1,3 +1,11 @@
+Thu Jan 29 11:22:19 2009  NAKAMURA Usaku  <usa@r...>
+
+	* ext/socket/raddrinfo.c (inspect_sockaddr): if defined AF_INET6,
+	  perhaps can inspect IPv6 addresses if not defined INET6.
+
+	* ext/socket/spclet.c (socket_s_ip_address_list): support Windows XP
+	  or later. (Win2k or earlier is still not supported)
+
 Thu Jan 29 00:24:48 2009  NAKAMURA Usaku  <usa@r...>
 
 	* ext/zlib/zlib.c (zstream_run): previous change didn't resolve the
Index: ext/socket/raddrinfo.c
===================================================================
--- ext/socket/raddrinfo.c	(revision 21862)
+++ ext/socket/raddrinfo.c	(revision 21863)
@@ -914,7 +914,7 @@
             break;
           }
 
-#ifdef INET6
+#ifdef AF_INET6
           case AF_INET6:
           {
             struct sockaddr_in6 *addr;
Index: ext/socket/socket.c
===================================================================
--- ext/socket/socket.c	(revision 21862)
+++ ext/socket/socket.c	(revision 21863)
@@ -1386,7 +1386,7 @@
 }
 #endif
 
-#if defined(HAVE_GETIFADDRS) || defined(SIOCGLIFCONF) || defined(SIOCGIFCONF)
+#if defined(HAVE_GETIFADDRS) || defined(SIOCGLIFCONF) || defined(SIOCGIFCONF) || defined(_WIN32)
 static VALUE
 sockaddr_obj(struct sockaddr *addr)
 {
@@ -1612,6 +1612,97 @@
     return list;
 
 #undef EXTRA_SPACE
+#elif defined(_WIN32)
+    typedef struct ip_adapter_unicast_address_st {
+	unsigned LONG_LONG dummy0;
+	struct ip_adapter_unicast_address_st *Next;
+	struct {
+	    struct sockaddr *lpSockaddr;
+	    int iSockaddrLength;
+	} Address;
+	int dummy1;
+	int dummy2;
+	int dummy3;
+	long dummy4;
+	long dummy5;
+	long dummy6;
+    } ip_adapter_unicast_address_t;
+    typedef struct ip_adapter_anycast_address_st {
+	unsigned LONG_LONG dummy0;
+	struct ip_adapter_anycast_address_st *Next;
+	struct {
+	    struct sockaddr *lpSockaddr;
+	    int iSockaddrLength;
+	} Address;
+    } ip_adapter_anycast_address_t;
+    typedef struct ip_adapter_addresses_st {
+	unsigned LONG_LONG dummy0;
+	struct ip_adapter_addresses_st *Next;
+	void *dummy1;
+	ip_adapter_unicast_address_t *FirstUnicastAddress;
+	ip_adapter_anycast_address_t *FirstAnycastAddress;
+	void *dummy2;
+	void *dummy3;
+	void *dummy4;
+	void *dummy5;
+	void *dummy6;
+	BYTE dummy7[8];
+	DWORD dummy8;
+	DWORD dummy9;
+	DWORD dummy10;
+	DWORD IfType;
+	int dummy11;
+	DWORD dummy12;
+	DWORD dummy13[16];
+	void *dummy14;
+    } ip_adapter_addresses_t;
+    typedef ULONG (WINAPI *GetAdaptersAddresses_t)(ULONG, ULONG, PVOID, ip_adapter_addresses_t *, PULONG);
+    HMODULE h;
+    GetAdaptersAddresses_t pGetAdaptersAddresses;
+    ULONG len;
+    DWORD ret;
+    ip_adapter_addresses_t *adapters;
+    VALUE list;
+
+    h = LoadLibrary("iphlpapi.dll");
+    if (!h)
+	rb_notimplement();
+    pGetAdaptersAddresses = (GetAdaptersAddresses_t)GetProcAddress(h, "GetAdaptersAddresses");
+    if (!pGetAdaptersAddresses) {
+	CloseHandle(h);
+	rb_notimplement();
+    }
+
+    ret = pGetAdaptersAddresses(AF_UNSPEC, 0, NULL, NULL, &len);
+    if (ret != ERROR_SUCCESS && ret != ERROR_BUFFER_OVERFLOW) {
+	errno = rb_w32_map_errno(ret);
+	CloseHandle(h);
+	rb_sys_fail("GetAdaptersAddresses");
+    }
+    adapters = (ip_adapter_addresses_t *)ALLOCA_N(BYTE, len);
+    ret = pGetAdaptersAddresses(AF_UNSPEC, 0, NULL, adapters, &len);
+    if (ret != ERROR_SUCCESS) {
+	errno = rb_w32_map_errno(ret);
+	CloseHandle(h);
+	rb_sys_fail("GetAdaptersAddresses");
+    }
+
+    list = rb_ary_new();
+    for (; adapters; adapters = adapters->Next) {
+	ip_adapter_unicast_address_t *uni;
+	ip_adapter_anycast_address_t *any;
+	for (uni = adapters->FirstUnicastAddress; uni; uni = uni->Next) {
+	    if (IS_IP_FAMILY(uni->Address.lpSockaddr->sa_family))
+		rb_ary_push(list, sockaddr_obj(uni->Address.lpSockaddr));
+	}
+	for (any = adapters->FirstAnycastAddress; any; any = any->Next) {
+	    if (IS_IP_FAMILY(any->Address.lpSockaddr->sa_family))
+		rb_ary_push(list, sockaddr_obj(any->Address.lpSockaddr));
+	}
+    }
+
+    CloseHandle(h);
+    return list;
 #else
     rb_notimplement();
 #endif

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]