Port 0 is invalid. Upon creation, a UDP socket has the local address 0.0.0.0:0 and remote address 0.0.0.0:0. (Likewise with IPv6). 9/
-
Show this thread
-
getsockname(2) gives the local address and getpeername(2) gives the remote address. UDP sockets are unbounded and unremoted on creation. 10/
1 reply 0 retweets 0 likesShow this thread -
You can bind to a particular local address and port using bind(2), but you can only bind once. 11/
2 replies 0 retweets 0 likesShow this thread -
The address must be the address of any network interface, or the any address (0.0.0.0, ::) to say you are OK with whatever interface. 12/
2 replies 0 retweets 0 likesShow this thread -
Binding to port 0 will instead bind to an available port. getsockname(2) can be used to find out which one that was. 13/
1 reply 0 retweets 0 likesShow this thread -
If you haven't bound the UDP socket, it will be bound on the first connect or send operation. 14/
1 reply 0 retweets 0 likesShow this thread -
Receiving will however not bind the socket (and never complete since 0.0.0.0:0 can't be sent to). 15/
1 reply 0 retweets 0 likesShow this thread -
You can set the remote address with connect(2) (once only). For UDP, this will not send a handshake. 16/
2 replies 0 retweets 0 likesShow this thread -
Replying to @sortiecat
But it will do something very useful: it tells you (by success/failure) if the remote address is routable.
1 reply 0 retweets 1 like -
Replying to @RichFelker
Cool - connect binding to an interface was the next thing for me to implement, hadn't yet thought of what to do if there is no route.
1 reply 0 retweets 0 likes
Note that musl's getaddrinfo depends on this behavior to implement (essentially) RFC 3484 (routability as part of sort key).
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.