[glib] add g_socket_speaks_ipv4()



commit f7d756f5b6c9975452e57ac6f41ff69d9f456739
Author: Ryan Lortie <desrt desrt ca>
Date:   Fri Jun 12 12:21:07 2009 -0400

    add g_socket_speaks_ipv4()
    
    Partial fix for Bug 585575.

 docs/reference/gio/gio-sections.txt |    1 +
 gio/gio.symbols                     |    1 +
 gio/gsocket.c                       |   48 +++++++++++++++++++++++++++++++++++
 gio/gsocket.h                       |    1 +
 4 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt
index aa5723b..278a9cd 100644
--- a/docs/reference/gio/gio-sections.txt
+++ b/docs/reference/gio/gio-sections.txt
@@ -1668,6 +1668,7 @@ g_socket_get_local_address
 g_socket_get_protocol
 g_socket_get_remote_address
 g_socket_get_socket_type
+g_socket_speaks_ipv4
 <SUBSECTION Standard>
 GSocketClass
 G_IS_SOCKET
diff --git a/gio/gio.symbols b/gio/gio.symbols
index 89a2e18..a0e96dd 100644
--- a/gio/gio.symbols
+++ b/gio/gio.symbols
@@ -1102,6 +1102,7 @@ g_socket_send_to
 g_socket_set_blocking
 g_socket_set_keepalive
 g_socket_set_listen_backlog
+g_socket_speaks_ipv4
 #endif
 #endif
 
diff --git a/gio/gsocket.c b/gio/gsocket.c
index 7aacf76..f352bf7 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -1278,6 +1278,54 @@ g_socket_bind (GSocket         *socket,
 }
 
 /**
+ * g_socket_speaks_ipv4:
+ * @socket: a #GSocket
+ *
+ * Checks if a socket is capable of speaking IPv4.
+ *
+ * IPv4 sockets are capable of speaking IPv4.  On some operating systems
+ * and under some combinations of circumstances IPv6 sockets are also
+ * capable of speaking IPv4.  See RFC 3493 section 3.7 for more
+ * information.
+ *
+ * No other types of sockets are currently considered as being capable
+ * of speaking IPv4.
+ *
+ * Returns: %TRUE if this socket can be used with IPv4.
+ *
+ * Since: 2.22.
+ **/
+gboolean
+g_socket_speaks_ipv4 (GSocket *socket)
+{
+  switch (socket->priv->family)
+    {
+    case G_SOCKET_FAMILY_IPV4:
+      return TRUE;
+
+    case G_SOCKET_FAMILY_IPV6:
+#if defined (IPPROTO_IPV6) && defined (IPV6_V6ONLY)
+      {
+        guint sizeof_int = sizeof (int);
+        gint v6_only;
+
+        if (getsockopt (socket->priv->fd,
+                        IPPROTO_IPV6, IPV6_V6ONLY,
+                        &v6_only, &sizeof_int) != 0)
+          return FALSE;
+
+        return !v6_only;
+      }
+#else
+      return FALSE;
+#endif
+
+    default:
+      return FALSE;
+    }
+}
+
+/**
  * g_socket_accept:
  * @socket: a #GSocket.
  * @error: #GError for error reporting, or %NULL to ignore.
diff --git a/gio/gsocket.h b/gio/gsocket.h
index 2ca90d2..05d5d37 100644
--- a/gio/gsocket.h
+++ b/gio/gsocket.h
@@ -161,6 +161,7 @@ gboolean               g_socket_is_closed               (GSocket
 GSource *              g_socket_create_source           (GSocket                 *socket,
 							 GIOCondition             condition,
 							 GCancellable            *cancellable);
+gboolean               g_socket_speaks_ipv4             (GSocket                 *socket);
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]