104 lines
3.5 KiB
Diff
104 lines
3.5 KiB
Diff
|
commit 859c381a9764d9d91e1ed8539a5919afbbbf2dbc
|
||
|
Author: Nils Philippsen <nils@redhat.com>
|
||
|
Date: Mon Jun 28 16:36:44 2010 +0200
|
||
|
|
||
|
patch: script-fu-ipv6
|
||
|
|
||
|
Squashed commit of the following:
|
||
|
|
||
|
commit e567516ade8ebf74598542f8b319f80eee873c65
|
||
|
Author: Nils Philippsen <nils@redhat.com>
|
||
|
Date: Mon Jun 28 16:07:01 2010 +0200
|
||
|
|
||
|
Bug 623045 - script-fu: make logging IPv6-aware
|
||
|
|
||
|
use getnameinfo() instead of inet_ntoa()
|
||
|
|
||
|
diff --git a/configure.in b/configure.in
|
||
|
index 71f031d..a99cbe4 100644
|
||
|
--- a/configure.in
|
||
|
+++ b/configure.in
|
||
|
@@ -602,14 +602,14 @@ AC_CHECK_FUNC(rint, AC_DEFINE(HAVE_RINT, 1,
|
||
|
AC_DEFINE(HAVE_RINT)])])
|
||
|
|
||
|
|
||
|
-######################################################
|
||
|
-# Check for extra libs needed for inet_ntoa and socket
|
||
|
-######################################################
|
||
|
+########################################################
|
||
|
+# Check for extra libs needed for getnameinfo and socket
|
||
|
+########################################################
|
||
|
|
||
|
gimp_save_LIBS=$LIBS
|
||
|
LIBS=""
|
||
|
|
||
|
-AC_CHECK_FUNCS(inet_ntoa, , AC_CHECK_LIB(nsl, inet_ntoa))
|
||
|
+AC_CHECK_FUNCS(getnameinfo, , AC_CHECK_LIB(nsl, getnameinfo))
|
||
|
AC_CHECK_LIB(socket, socket)
|
||
|
|
||
|
SOCKET_LIBS="$LIBS"
|
||
|
diff --git a/plug-ins/script-fu/script-fu-server.c b/plug-ins/script-fu/script-fu-server.c
|
||
|
index db1de13..8fb8a10 100644
|
||
|
--- a/plug-ins/script-fu/script-fu-server.c
|
||
|
+++ b/plug-ins/script-fu/script-fu-server.c
|
||
|
@@ -310,12 +310,16 @@ script_fu_server_listen (gint timeout)
|
||
|
/* Service the server socket if it has input pending. */
|
||
|
if (FD_ISSET (server_sock, &fds))
|
||
|
{
|
||
|
- struct sockaddr_in clientname;
|
||
|
+ struct sockaddr_storage client;
|
||
|
+ struct sockaddr_in *client_in;
|
||
|
+ struct sockaddr_in6 *client_in6;
|
||
|
+ gchar clientname[NI_MAXHOST];
|
||
|
|
||
|
/* Connection request on original socket. */
|
||
|
- guint size = sizeof (clientname);
|
||
|
+ guint size = sizeof (client);
|
||
|
gint new = accept (server_sock,
|
||
|
- (struct sockaddr *) &clientname, &size);
|
||
|
+ (struct sockaddr *) &client, &size);
|
||
|
+ guint portno;
|
||
|
|
||
|
if (new < 0)
|
||
|
{
|
||
|
@@ -324,13 +328,34 @@ script_fu_server_listen (gint timeout)
|
||
|
}
|
||
|
|
||
|
/* Associate the client address with the socket */
|
||
|
- g_hash_table_insert (clients,
|
||
|
- GINT_TO_POINTER (new),
|
||
|
- g_strdup (inet_ntoa (clientname.sin_addr)));
|
||
|
+
|
||
|
+ /* If all else fails ... */
|
||
|
+ 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);
|
||
|
+
|
||
|
+ /* Determine port number */
|
||
|
+ switch (client.ss_family)
|
||
|
+ {
|
||
|
+ case AF_INET:
|
||
|
+ client_in = (struct sockaddr_in *) &client;
|
||
|
+ portno = (guint) g_ntohs (client_in->sin_port);
|
||
|
+ break;
|
||
|
+ case AF_INET6:
|
||
|
+ client_in6 = (struct sockaddr_in6 *) &client;
|
||
|
+ portno = (guint) g_ntohs (client_in6->sin6_port);
|
||
|
+ break;
|
||
|
+ default:
|
||
|
+ portno = 0;
|
||
|
+ }
|
||
|
+
|
||
|
+ g_hash_table_insert (clients, GINT_TO_POINTER (new),
|
||
|
+ g_strdup (clientname));
|
||
|
|
||
|
server_log ("Server: connect from host %s, port %d.\n",
|
||
|
- inet_ntoa (clientname.sin_addr),
|
||
|
- (unsigned int) ntohs (clientname.sin_port));
|
||
|
+ clientname, portno);
|
||
|
}
|
||
|
|
||
|
/* Service the client sockets. */
|