My application needs to bind a socket on the same port with the same IPv6 address. I am using the code below to achieve the same. However second bind throws an error \'Address a
From the socket(7)
man page:
SO_REUSEADDR
- Indicates that the rules used in validating addresses supplied in abind(2)
call should allow reuse of local addresses. ForAF_INET
sockets this means that a socket may bind, except when there is an active listening socket bound to the address. When the listening socket is bound toINADDR_ANY
with a specific port then it is not possible to bind to this port for any local address. Argument is an integer boolean flag.
(emphasis mine)
Your first socket is bound to port 143 on the IPv6 equivalent of INADDR_ANY
, then it's put in listening state. Thus no other socket could be bound on port 143 as long as the first socket remains open.