Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!asuvax!ncar!hsdndev!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.unix.questions Subject: Re: INADDR_ANY Message-ID: <20868.Jun3021.30.3391@kramden.acf.nyu.edu> Date: 30 Jun 91 21:30:33 GMT References: <739@dove.nist.gov> <1991Jun30.062127.19532@Think.COM> Organization: IR Lines: 23 In article <1991Jun30.062127.19532@Think.COM> barmar@think.com writes: [ reasons to use INADDR_ANY ] > A more important reason is that a host can have more than one address; in > fact, most network hosts have at least two IP addresses: 127.0.0.1 (the > semi-standard "localhost" address) and the addresses of each real network > interface. If the server only specifies one local address, then it will > only respond to connections sent to that specific address. It is worth noting that the addresses you get back from getsockname() and getpeername() may not provide full information about the TCP connection on some machines. If, for instance, you bind to INADDR_ANY and someone connects to the machine's IP address, getsockname() gives you INADDR_ANY (typically 0.0.0.0) on some machines and the actual IP address on others, even though INADDR_ANY is a useless, arguably incorrect answer. If someone connects to 127.1, you may get not only 127.1, but INADDR_ANY or even the machine's IP address, even though 127.1 is the only right answer. Even if you bind to 127.1 and accept from 127.1 you may end up getting the machine's IP address, for both the server and client sides. Portability can be painful. ---Dan