[farsight2/master] Use SO_REUSEADDR/PORT

Olivier Crête olivier.crete at collabora.co.uk
Tue Dec 23 15:21:02 PST 2008


---
 transmitters/multicast/fs-multicast-transmitter.c |   25 ++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/transmitters/multicast/fs-multicast-transmitter.c b/transmitters/multicast/fs-multicast-transmitter.c
index 728a6aa..f82e830 100644
--- a/transmitters/multicast/fs-multicast-transmitter.c
+++ b/transmitters/multicast/fs-multicast-transmitter.c
@@ -506,7 +506,8 @@ _bind_port (
   int sock = -1;
   struct sockaddr_in address;
   int retval;
-  guchar ttl = 64, loop = 0;
+  guchar ttl = 64, loop = 1;
+  int reuseaddr = 1;
 
   address.sin_family = AF_INET;
   address.sin_addr.s_addr = INADDR_ANY;
@@ -575,6 +576,28 @@ _bind_port (
         g_strerror (errno));
     goto error;
   }
+
+
+  if (setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuseaddr,
+          sizeof (reuseaddr)) < 0)
+  {
+    g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS,
+        "Error setting reuseaddr to TRUE: %s",
+        g_strerror (errno));
+    goto error;
+  }
+
+#ifdef SO_REUSEPORT
+  if (setsockopt (sock, SOL_SOCKET, SO_REUSEPORT, &reuseaddr,
+          sizeof (reuseaddr)) < 0)
+  {
+    g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS,
+        "Error setting reuseaddr to TRUE: %s",
+        g_strerror (errno));
+    goto error;
+  }
+#endif
+
   return sock;
 
  error:
-- 
1.5.6.5




More information about the farsight-commits mailing list