sin_util.c
changeset 3 1223f413e054
parent 0 ae252e0fd9b8
--- a/sin_util.c	Fri Nov 16 09:28:12 2018 +0100
+++ b/sin_util.c	Mon Feb 11 11:07:01 2019 +0100
@@ -153,6 +153,10 @@
   if ((type = gettypebyname(protocol)) == SOCK_PACKET)       return -1;
   /* create the socket */
   if ((s = socket(PF_INET, type, 0)) < 0)                   {perror("socket()");  return -1;}   
+  if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof(int)) < 0) {
+      perror("setsockopt(SO_REUSEADDR) failed");
+      return -1;
+  }
   /* bind the socket */
   if (bind(s, (struct sockaddr *)&sin, sizeof (sin)) < 0)   {perror("bind()");    return -1;}