setsockopt: Protocol not available [Solved]


Problem code:

if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &opt, sizeof(opt))) 

perror("setsockopt"); 

exit(EXIT_FAILURE); 

}


Solution:

if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) 

perror("setsockopt"); 

exit(EXIT_FAILURE); 

}


Ref.: https://stackoverflow.com/a/59807281/4064166


This error appears when a socket option is not supported on the current platform. Here the combination of SO_REUSEADDR and SO_REUSEPORT fails because SO_REUSEPORT is unavailable, so the call returns Protocol not available.

Setting SO_REUSEADDR on its own fixes it, which is widely supported and enough for the common case of rebinding a recently used address. SO_REUSEPORT behaves differently across operating systems and is not always present.

Comments

Popular posts from this blog

[Solved] Error: No such keg: /usr/local/Cellar/gcc

[How To] Unfollow Non-followers on Instagram