[glib] GInetSocketAddress: fix the byte order of flowinfo and scope_id



commit a60014f1b6fe9b62fa37b738dfc9a97d3046a1dc
Author: Dan Winship <danw gnome org>
Date:   Wed Dec 12 16:00:26 2012 +0100

    GInetSocketAddress: fix the byte order of flowinfo and scope_id
    
    The flowinfo and scope_id fields of struct sockaddr_in6 are in host
    byte order, but the code previously assumed they were in network byte
    order. Fix that.
    
    This is an ABI-breaking change (since before you would have had to use
    g_ntohl() and g_htonl() with them to get the correct values, and now
    that would give the wrong values), but the previous behavior was
    clearly wrong, and no one ever reported it, so it is likely that no
    one was actually using it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=684404

 README.in                |    6 ++++++
 gio/ginetsocketaddress.c |    4 ++--
 gio/gsocketaddress.c     |    4 ++--
 gio/tests/socket.c       |    4 ++--
 4 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/README.in b/README.in
index 10ae606..3537b7f 100644
--- a/README.in
+++ b/README.in
@@ -86,6 +86,12 @@ Notes about GLib 2.36
   As of this version, the HOME variable is used if it is set and the
   value from /etc/passwd is only used as a fallback.
 
+* The 'flowinfo' and 'scope_id' fields of GInetSocketAddress
+  (introduced in GLib 2.32) have been fixed to be in host byte order
+  rather than network byte order. This is an incompatible change, but
+  the previous behavior was clearly broken, so it seems unlikely that
+  anyone was using it.
+
 Notes about GLib 2.34
 =====================
 
diff --git a/gio/ginetsocketaddress.c b/gio/ginetsocketaddress.c
index 8f42849..9b45aa2 100644
--- a/gio/ginetsocketaddress.c
+++ b/gio/ginetsocketaddress.c
@@ -227,8 +227,8 @@ g_inet_socket_address_to_native (GSocketAddress  *address,
       memset (sock, 0, sizeof (*sock));
       sock->sin6_family = AF_INET6;
       sock->sin6_port = g_htons (addr->priv->port);
-      sock->sin6_flowinfo = g_htonl (addr->priv->flowinfo);
-      sock->sin6_scope_id = g_htonl (addr->priv->scope_id);
+      sock->sin6_flowinfo = addr->priv->flowinfo;
+      sock->sin6_scope_id = addr->priv->scope_id;
       memcpy (&(sock->sin6_addr.s6_addr), g_inet_address_to_bytes (addr->priv->address), sizeof (sock->sin6_addr));
       return TRUE;
     }
diff --git a/gio/gsocketaddress.c b/gio/gsocketaddress.c
index 83414fc..03c8ac0 100644
--- a/gio/gsocketaddress.c
+++ b/gio/gsocketaddress.c
@@ -259,8 +259,8 @@ g_socket_address_new_from_native (gpointer native,
       sockaddr = g_object_new (G_TYPE_INET_SOCKET_ADDRESS,
 			       "address", iaddr,
 			       "port", g_ntohs (addr->sin6_port),
-			       "flowinfo", g_ntohl (addr->sin6_flowinfo),
-			       "scope_id", g_ntohl (addr->sin6_scope_id),
+			       "flowinfo", addr->sin6_flowinfo,
+			       "scope_id", addr->sin6_scope_id,
 			       NULL);
       g_object_unref (iaddr);
       return sockaddr;
diff --git a/gio/tests/socket.c b/gio/tests/socket.c
index 70bed07..8ae80a1 100644
--- a/gio/tests/socket.c
+++ b/gio/tests/socket.c
@@ -657,8 +657,8 @@ test_sockaddr (void)
   sin6.sin6_family = AF_INET6;
   sin6.sin6_addr = in6addr_loopback;
   sin6.sin6_port = g_htons (42);
-  sin6.sin6_scope_id = g_htonl (17);
-  sin6.sin6_flowinfo = g_htonl (1729);
+  sin6.sin6_scope_id = 17;
+  sin6.sin6_flowinfo = 1729;
 
   saddr = g_socket_address_new_from_native (&sin6, sizeof (sin6));
   g_assert (G_IS_INET_SOCKET_ADDRESS (saddr));



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