wammder wammder - 20 days ago 7
C Question

c api socket SO_REUSEADDR

I try to understand a multicast code, and I don't understand the utilities of a little part :

int fd_socket = socket(AF_INET, SOCK_DGRAM, 0);
u_int yes = 1;

setsockopt(fd_socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));


I don't understand the utilities of the setsockopt function. I understand that, this function permits to modify the socket in the kernel, and
SOL_SOCKET
is because my modification is about the level of the socket and not of the level of a protocol. I don't understand
SO_REUSEADDR
.

Answer

For UDP sockets, setting the SO_REUSEADDR option allows multiple sockets to be open on the same port.

If those sockets are also joined to a multicast group, any multicast packet coming in to that group and port will be delivered to all sockets open on that port.

Comments