beejjorgensen / bgnet

Beej's Guide to Network Programming source
962 stars 130 forks source link

bgnet/examples/listener.c only listens to ipv4 on Linux #2

Closed MostParsingVex closed 3 years ago

MostParsingVex commented 6 years ago

talker.c appears to send udp datagrams over both ipv4 and ipv6 but listener.c appears to only listen on ipv4.

beejjorgensen commented 5 years ago

It's coded to listen on whichever it can bind to first.

Try changing this line:

hints.ai_family = AF_UNSPEC;

to hints.ai_family = AF_INET6;

Does that force it?

mkrysiak commented 4 years ago

If a reader builds listener.c and talker.c as-is, and executes them, there is a chance the message won't be received by the listener. In my case, the listener bound to IPv4 first, but the talker sent the message on IPv6. Since readers most likely have an expectation that all examples work without issue, this can be confusing. So I think it would be good to at least add a note about this behaviour.

beejjorgensen commented 3 years ago

Fixed, thanks!