mirror of https://github.com/GNOME/gimp.git
script-fu: make server strict-aliasing friendly
use union of struct sockaddr* types instead of direct casts
This commit is contained in:
parent
6cdc64756e
commit
521cf89006
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue