[gimp/gimp-2-6] script-fu: make server strict-aliasing friendly



commit 4f3754eb7adeb5aaaae158951449dfc8c93240e9
Author: Nils Philippsen <nils redhat com>
Date:   Fri Jul 9 12:49:58 2010 +0200

    script-fu: make server strict-aliasing friendly
    
    use union of struct sockaddr* types instead of direct casts
    (cherry picked from commit 521cf890064009f3b97336e97dd189746ff9f1e2)

 plug-ins/script-fu/script-fu-server.c |   29 +++++++++++++++++------------
 1 files changed, 17 insertions(+), 12 deletions(-)
---
diff --git a/plug-ins/script-fu/script-fu-server.c b/plug-ins/script-fu/script-fu-server.c
index c4776a2..af2b296 100644
--- a/plug-ins/script-fu/script-fu-server.c
+++ b/plug-ins/script-fu/script-fu-server.c
@@ -108,7 +108,7 @@
 #define RSP_LEN_L_BYTE  3
 
 /*
- *  Local Structures
+ *  Local Types
  */
 
 typedef struct
@@ -129,6 +129,15 @@ typedef struct
   gboolean   run;
 } ServerInterface;
 
+typedef union
+{
+  sa_family_t              family;
+  struct sockaddr_storage  ss;
+  struct sockaddr          sa;
+  struct sockaddr_in       sa_in;
+  struct sockaddr_in6      sa_in6;
+} sa_union;
+
 /*
  *  Local Functions
  */
@@ -318,9 +327,7 @@ script_fu_server_listen (gint timeout)
   /* Service the server sockets if any has input pending. */
   for (sockno = 0; sockno < server_socks_used; sockno++)
     {
-      struct sockaddr_storage  client;
-      struct sockaddr_in      *client_in;
-      struct sockaddr_in6     *client_in6;
+      sa_union                 client;
       gchar                    clientname[NI_MAXHOST];
 
       /* Connection request on original socket. */
@@ -333,7 +340,7 @@ script_fu_server_listen (gint timeout)
           continue;
         }
 
-      new = accept (server_socks[sockno], (struct sockaddr *) &client, &size);
+      new = accept (server_socks[sockno], &(client.sa), &size);
 
       if (new < 0)
         {
@@ -347,22 +354,20 @@ script_fu_server_listen (gint timeout)
       strncpy (clientname, "(error during host address lookup)", NI_MAXHOST-1);
 
       /* Lookup address */
-      (void) getnameinfo ((struct sockaddr *) &client, size, clientname,
-                          sizeof (clientname), NULL, 0, NI_NUMERICHOST);
+      (void) getnameinfo (&(client.sa), size, clientname, sizeof (clientname),
+                          NULL, 0, NI_NUMERICHOST);
 
       g_hash_table_insert (clients, GINT_TO_POINTER (new),
                            g_strdup (clientname));
 
       /* Determine port number */
-      switch (client.ss_family)
+      switch (client.family)
         {
           case AF_INET:
-            client_in = (struct sockaddr_in *) &client;
-            portno = (guint) g_ntohs (client_in->sin_port);
+            portno = (guint) g_ntohs (client.sa_in.sin_port);
             break;
           case AF_INET6:
-            client_in6 = (struct sockaddr_in6 *) &client;
-            portno = (guint) g_ntohs (client_in6->sin6_port);
+            portno = (guint) g_ntohs (client.sa_in6.sin6_port);
             break;
           default:
             portno = 0;



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