From: Daniel Brockman Date: 2005-08-10T19:40:52+09:00 Subject: Re: UDPSocket#bind with 0 or nil Joel, > Anyone happen know what the difference between bind(0) and > bind(nil) is? I assume you mean bind(0, foo) vs. bind(nil, foo). The former binds to all interfaces, like bind("", foo). The latter only binds to the loopback interface. > I thought they both meant the same as "", but I think > I observed different behavior in one case. The arguments to UDPSocket#bind are passed to getaddrinfo, and the socket is bound to the first returned interface. Quoting the man page for getaddrinfo(3), int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res); [...] If node is NULL, the network address in each socket structure is initialized according to the AI_PASSIVE flag, which is set in the ai_flags member of the hints parameter. In our case, this flag and all other flags are always unset. (See `udp_bind' in ext/socket/socket.c:1406.) The network address in each socket structure will be left unspecified if AI_PASSIVE flag is set. This is used by server applications, which intend to accept client connections on any network address. THE NETWORK ADDRESS WILL BE SET TO THE LOOPBACK INTERFACE ADDRESS if the AI_PASSIVE flag is not set. This is used by client applications, which intend to connect to a server running on the same network host. (Emphasis mine.) -- Daniel Brockman So really, we all have to ask ourselves: Am I waiting for RMS to do this? --TTN.