Fix functionality on OpenBSD
authorJens Georg <mail@jensge.org>
Thu, 30 Jun 2011 19:51:11 +0000 (21:51 +0200)
committerJens Georg <mail@jensge.org>
Wed, 6 Jul 2011 16:32:57 +0000 (18:32 +0200)
libgssdp/gssdp-socket-functions.c
libgssdp/gssdp-socket-functions.h
libgssdp/gssdp-socket-source.c

index 37af2ca..6f10a9f 100644 (file)
@@ -90,8 +90,13 @@ gssdp_socket_option_set (GSocket    *socket,
 
 gboolean
 gssdp_socket_enable_loop (GSocket *socket,
-                          gboolean enable,
+                          gboolean _enable,
                           GError **error) {
+#if defined(__OpenBSD__)
+        guint8 enable = (guint8) _enable;
+#else
+        gboolean enable = _enable;
+#endif
         return gssdp_socket_option_set (socket,
                                         IPPROTO_IP,
                                         IP_MULTICAST_LOOP,
@@ -102,8 +107,13 @@ gssdp_socket_enable_loop (GSocket *socket,
 
 gboolean
 gssdp_socket_set_ttl (GSocket *socket,
-                      int      ttl,
+                      int      _ttl,
                       GError **error) {
+#if defined(__OpenBSD__)
+        guint8 ttl = (guint8) _ttl;
+#else
+        int ttl = _ttl;
+#endif
         return gssdp_socket_option_set (socket,
                                         IPPROTO_IP,
                                         IP_MULTICAST_TTL,
@@ -143,19 +153,25 @@ gssdp_socket_mcast_interface_set (GSocket      *socket,
                                         error);
 }
 
-#ifdef G_OS_WIN32
 gboolean
 gssdp_socket_reuse_address (GSocket *socket,
                             gboolean enable,
                             GError **error) {
+#if defined(G_OS_WIN32) || defined(__OpenBSD__)
         return gssdp_socket_option_set (socket,
                                         SOL_SOCKET,
+#if defined(__OpenBSD__)
+                                        SO_REUSEPORT,
+#else
                                         SO_REUSEADDR,
+#endif
+
                                         (char *) &enable,
                                         sizeof (enable),
                                         error);
-}
 #endif
+        return TRUE;
+}
 
 
 /*
index 99784d2..b9b5ca5 100644 (file)
@@ -45,10 +45,8 @@ gssdp_socket_mcast_group_join    (GSocket       *socket,
                                   GInetAddress  *group,
                                   GInetAddress  *iface,
                                   GError       **error);
-#ifdef G_OS_WIN32
 G_GNUC_INTERNAL gboolean
 gssdp_socket_reuse_address       (GSocket *socket,
                                   gboolean enable,
                                   GError **error);
 #endif
-#endif
index 14f56d3..720061e 100644 (file)
@@ -249,11 +249,10 @@ gssdp_socket_source_do_init (GInitable     *initable,
                                                           port);
         }
 
-#ifdef G_OS_WIN32
-        /* normally g_socket_bind does this, but it is disabled on
+        /* Normally g_socket_bind does this, but it is disabled on
          * windows since SO_REUSEADDR has different semantics
-         * there. Nevertheless, there's no way without for
-         * multicast sockets
+         * there, also we nees SO_REUSEPORT on OpenBSD. This is a nop
+         * everywhere else.
          */
         if (!gssdp_socket_reuse_address (self->priv->socket,
                                          TRUE,
@@ -265,7 +264,7 @@ gssdp_socket_source_do_init (GInitable     *initable,
 
                 goto error;
         }
-#endif
+
         /* Bind to requested port and address */
         if (!g_socket_bind (self->priv->socket,
                             bind_address,