[gimp] script-fu: make server strict-aliasing friendly
- From: Nils Philippsen <nphilipp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] script-fu: make server strict-aliasing friendly
- Date: Fri, 9 Jul 2010 10:52:46 +0000 (UTC)
commit 521cf890064009f3b97336e97dd189746ff9f1e2
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
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 5764ffc..4b1030c 100644
--- a/plug-ins/script-fu/script-fu-server.c
+++ b/plug-ins/script-fu/script-fu-server.c
@@ -115,7 +115,7 @@
#define RSP_LEN_L_BYTE 3
/*
- * Local Structures
+ * Local Types
*/
typedef struct
@@ -136,6 +136,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
*/
@@ -325,9 +334,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. */
@@ -340,7 +347,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)
{
@@ -354,22 +361,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]