- /* Succeeded with ipv6, also try ipv4 in case its ipv6 only,
- but ignore errors here */
- res = TRUE;
- g_socket_listener_add_address (listener,
- address4,
- G_SOCKET_TYPE_STREAM,
- G_SOCKET_PROTOCOL_DEFAULT,
- source_object,
- NULL);
+ socket4 = g_socket_new (G_SOCKET_FAMILY_IPV4,
+ G_SOCKET_TYPE_STREAM,
+ G_SOCKET_PROTOCOL_DEFAULT,
+ error);
+
+ if (socket4 != NULL)
+ /* IPv4 is supported on this platform, so if we fail now it is
+ * a result of being unable to bind to our port. Don't fail
+ * silently as a result of this!
+ */
+ {
+ GInetAddress *inet_address;
+ GSocketAddress *address;
+ gboolean result;
+
+ inet_address = g_inet_address_new_any (G_SOCKET_FAMILY_IPV4);
+ address = g_inet_socket_address_new (inet_address, port);
+ g_object_unref (inet_address);
+
+ g_socket_set_listen_backlog (socket4,
+ listener->priv->listen_backlog);
+
+ result = g_socket_bind (socket4, address, TRUE, error) &&
+ g_socket_listen (socket4, error);
+
+ g_object_unref (address);
+
+ if (!result)
+ {
+ g_object_unref (socket4);
+
+ if (socket6 != NULL)
+ g_object_unref (socket6);
+
+ return FALSE;
+ }
+
+ if (source_object)
+ g_object_set_qdata_full (G_OBJECT (socket4), source_quark,
+ g_object_ref (source_object),
+ g_object_unref);
+ }
+ else
+ /* Ok. So IPv4 is not supported on this platform. If we
+ * succeeded at creating an IPv6 socket then that's OK, but
+ * otherwise we need to tell the user we failed.
+ */
+ {
+ if (socket6 != NULL)
+ g_clear_error (error);
+ else
+ return FALSE;
+ }