On Wed, May 23, 2001 at 11:18:11PM +1000, Craig Small wrote: > A programming question about IPv6. > > I got a daemon, it wants to listen to a specific TCP port (9006). > So I getaddrinfo a set of addresses. Now I need to make the socket, > bind and listen. > > OK, so i got something like: > > getaddrinfo > while(res) { > skt = socket(res->ai_family, res->ai_socktype, res->ai_protocol) > bind(skt) > listen(skt) > next res > } > is this correct? Do I need to make several socket calls to listen to > all addresses? Since this was meant as an example, I guess you want to use the following instead of plain bind(skt): bind(skt, res->ai_addr, res->ai_addrlen) Now, if you had a BSD system (I can't exactly remember which ones) the above procedure would be correct, all bind()'s would succeed and you would have one socket for each protocol family, namely IPv6 and IPv4. OTOH, in linux, if you bind an IPv6 socket to a port, you can't bind an IPv4 socket to the same port anymore, the call will fail with 'Address already in use'. Instead, the IPv6 socket would get all IPv4 packets as well. Basically you should just break out of the loop after the listen, assuming all the preceding calls succeeded. And then we have the USAGI patches for linux which, among other things, makes the bind() work like the BSD case above... I think BIND9 has addressed all this in it's documentation. Someone correct me if I'm wrong, but I think this different behaviour of bind() is the current showstopper for writing portable IPv6 applications. -- Tommi Komulainen Tommi.Komulainen@iki.fi GPG 1024D/68388EE6 6FD6 DD79 EB38 BF6F 3533 09C0 04A8 9871 6838 8EE6
Attachment:
pgpaLR1XIK5fl.pgp
Description: PGP signature