IPv6 support for to_native and from_native, and support
[cascardo/gnio.git] / gnio / ginetsocketaddress.c
index f636162..0bb6196 100644 (file)
@@ -67,7 +67,10 @@ g_inet_socket_address_dispose (GObject *object)
 }
 
 static void
-g_inet_socket_address_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+g_inet_socket_address_get_property (GObject    *object,
+                                    guint       prop_id,
+                                    GValue     *value,
+                                    GParamSpec *pspec)
 {
   GInetSocketAddress *address = G_INET_SOCKET_ADDRESS (object);
 
@@ -87,7 +90,10 @@ g_inet_socket_address_get_property (GObject *object, guint prop_id, GValue *valu
 }
 
 static void
-g_inet_socket_address_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+g_inet_socket_address_set_property (GObject      *object,
+                                    guint         prop_id,
+                                    const GValue *value,
+                                    GParamSpec   *pspec)
 {
   GInetSocketAddress *address = G_INET_SOCKET_ADDRESS (object);
 
@@ -124,7 +130,8 @@ g_inet_socket_address_native_size (GSocketAddress *address)
 }
 
 static gboolean
-g_inet_socket_address_to_native (GSocketAddress *address, gpointer dest)
+g_inet_socket_address_to_native (GSocketAddress *address,
+                                 gpointer        dest)
 {
   GInetSocketAddress *addr;
 
@@ -144,7 +151,12 @@ g_inet_socket_address_to_native (GSocketAddress *address, gpointer dest)
     }
   else if (G_IS_INET6_ADDRESS (addr->priv->address))
     {
-      return FALSE;
+      struct sockaddr_in6 *sock = (struct sockaddr_in6 *) dest;
+      memset (sock, 0, sizeof (sock));
+      sock->sin6_family = AF_INET6;
+      sock->sin6_port = g_htons (addr->priv->port);
+      memcpy (&(sock->sin6_addr.s6_addr), g_inet6_address_to_bytes (G_INET6_ADDRESS (addr->priv->address)), sizeof (sock->sin6_addr));
+      return TRUE;
     }
   else
     return FALSE;
@@ -196,7 +208,8 @@ g_inet_socket_address_init (GInetSocketAddress *address)
 
 
 GInetSocketAddress *
-g_inet_socket_address_new (GInetAddress *address, guint16 port)
+g_inet_socket_address_new (GInetAddress *address,
+                           guint16       port)
 {
   return G_INET_SOCKET_ADDRESS (g_object_new (G_TYPE_INET_SOCKET_ADDRESS, "address", address, "port", port, NULL));
 }