Bugs item #9061, was opened at 2007-03-06 04:28
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=9061&group_id=426

Category: Standard Library
Group: 1.8.x
>Status: Closed
Resolution: Accepted
Priority: 3
Submitted By: Bram Whillock (bramski)
Assigned to: Usaku Nakamura (usa)
Summary: Windows Vista: recvfrom causes exception

Initial Comment:
>ruby -v

ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-mswin32]

I'm also running on windows vista, but I don't know if this is an
issue on the overall mswin32-x86 platform.

I'm getting an error when trying to recvfrom on a TCP Socket.  The
code looks as follows:

listen_socket = TCPSocket.new("127.0.0.1",5000)
(data,host) = listen_socket.recvfrom( 1024 )

running this code (it's in my unit test) yields:

SocketError: getnameinfo: ai_family not supported.
    ./lib/juggernaut.rb:42:in `recvfrom'

Any idea why this might be occurring?  Is it due to something related
to IPv6 support?


----------------------------------------------------------------------

Comment By: Usaku Nakamura (usa)
Date: 2007-04-03 15:28

Message:
Hmm, this problem is not only on Vista. o
I reproduced it on XP SP2.

patch:

Index: ext/socket/socket.c
===================================================================
--- ext/socket/socket.c	(revision 12136)
+++ ext/socket/socket.c	(working copy)
@@ -625,7 +625,7 @@ s_recvfrom(sock, argc, argv, from)
 	    rb_raise(rb_eTypeError, "sockaddr size differs - should not happen");
 	}
 #endif
-	if (alen) /* OSX doesn't return a 'from' result from recvfrom for connection-oriented sockets */
+	if (alen && alen != sizeof(buf)) /* OSX doesn't return a 'from' result from recvfrom for connection-oriented sockets */
 	    return rb_assoc_new(str, ipaddr((struct sockaddr*)buf));
 	else
 	    return rb_assoc_new(str, Qnil);
@@ -691,7 +691,7 @@ s_recvfrom_nonblock(VALUE sock, int argc
 	return str;
 
       case RECV_IP:
-        if (alen) /* connection-oriented socket may not return a from result */
+        if (alen && alen != sizeof(buf)) /* connection-oriented socket may not return a from result */
             addr = ipaddr((struct sockaddr*)buf);
         break;
 


----------------------------------------------------------------------

Comment By: Bram Whillock (bramski)
Date: 2007-03-06 15:13

Message:
http://www.rubycentral.com/book/lib_network.html

Most people seem to use this in the context of (as per the
example):
t = TCPSocket.new('localhost', 'ftp')
data = t.recvfrom(30)
data

and disregard the fact that this function returns the host
(again).  This definitely works on linux, btw.

----------------------------------------------------------------------

Comment By: Bill K. (spatulasnout)
Date: 2007-03-06 15:09

Message:
Sorry if this is a dumb question; but is recvfrom supposed to work with TCP connections?  Typically I've only seen recv used with TCP, and recvfrom used with UDP.


----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=9061&group_id=426