From a11b41627032ab6bb815d7a8ecc7c14f0bcc350a Mon Sep 17 00:00:00 2001 From: Thomas Flueeli Date: Thu, 28 Oct 2010 12:46:45 +0200 Subject: [PATCH 1/1] fix fd.o#24775 --- src/bytestream-socks5.c | 50 +++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/bytestream-socks5.c b/src/bytestream-socks5.c index d496463..1dd75ca 100644 --- a/src/bytestream-socks5.c +++ b/src/bytestream-socks5.c @@ -1648,12 +1648,54 @@ socks5_init_error: static GSList * get_local_interfaces_ips (void) { - /* FIXME: fd.o#24775: please implement this using ioctlsocket() and - * SIO_GET_INTERFACE_LIST, if you care about doing SOCKS5 bytestreams on - * Windows */ - return NULL; + gint sockfd; + INTERFACE_INFO iflist[32]; + gulong bytes; + gint num = 0; + gint i; + struct sockaddr_in *sa; + GSList *ips = NULL; + + /* FIXME: add IPv6 addresses */ + if ((sockfd = socket (AF_INET, SOCK_DGRAM, IPPROTO_IP)) == INVALID_SOCKET) + { + DEBUG ("Cannot open socket to retrieve interface list"); + return NULL; + } + + if (WSAIoctl (sockfd, SIO_GET_INTERFACE_LIST, 0, 0, &iflist, + sizeof (iflist), &bytes, 0, 0) == SOCKET_ERROR) + { + DEBUG ("Cannot retrieve interface list"); + return NULL; + } + + num = bytes / sizeof (INTERFACE_INFO); + + /* Loop throught the interface list and get the IP address of each IF */ + for (i=0; isin_addr))); + DEBUG ("IP Address: %s", inet_ntoa (sa->sin_addr)); + } + + closesocket (sockfd); + + return ips; } + #else /* get_local_interfaces_ips original code from Farsight 2 (function -- 1.7.2.3