$OpenBSD: patch-src_nettool_c,v 1.3 2011/07/13 08:09:12 jasper Exp $

From da8ec778b8ea691e1043173a0e8ea5e226a429b0 Mon Sep 17 00:00:00 2001
From: Jasper Lievisse Adriaanse <jasper@humppa.nl>
Date: Thu, 19 May 2011 18:45:05 +0200
Subject: [PATCH] portability fix for systems that configure an ipv6 address
  by default, but use the ipv4 address for actual traffic.

tweak decision logic for deciding if we should use the ipv4 or ipv6 tools.
it would default to ipv6 as most interfaces have an unused ipv6 address, while
actually using the ipv4 address. this fixes ping/traceroute functionality when
using hostnames instead of ip addresses.

--- src/nettool.c.orig	Thu Dec  2 10:26:14 2010
+++ src/nettool.c	Wed May 18 15:43:49 2011
@@ -24,6 +24,7 @@
 #include <string.h>
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <netinet/in.h>
 #include <signal.h>
 #include <errno.h>
 #include <sys/wait.h>
@@ -137,21 +138,21 @@ netinfo_get_ip_version (Netinfo * netinfo)
 				   (GTK_BIN (netinfo->host)))));
 
 	if (strlen (ip) > 0) {
-		host = gethostbyname2 (ip, AF_INET6);
+		host = gethostbyname2 (ip, AF_INET);
 		if (host == NULL) {
-			host = gethostbyname2 (ip, AF_INET);
+			host = gethostbyname2 (ip, AF_INET6);
 			if (host == NULL)
 				return -1;
 			else {
 				g_free (ip);
-				return IPV4;
+				return IPV6;
 			}
 			
 			return -1;
 		}
 		else {
 			g_free (ip);
-			return IPV6;
+			return IPV4;
 		}
 
 	}
@@ -374,6 +375,10 @@ netinfo_io_text_buffer_dialog (GIOChannel * channel,
 						 	len, NULL);
 			}
 
+			g_free (text);
+
+			return TRUE;
+
 		} else if (status == G_IO_STATUS_AGAIN) {
 			char buf[1];
 
@@ -385,6 +390,8 @@ netinfo_io_text_buffer_dialog (GIOChannel * channel,
 				}
 				g_string_append_c (netinfo->command_output, buf[0]);
 			}
+			g_free (text);
+			return TRUE;
 		} else if (status == G_IO_STATUS_EOF) {
 			
 		} else if (status == G_IO_STATUS_ERROR) {
@@ -402,15 +409,15 @@ netinfo_io_text_buffer_dialog (GIOChannel * channel,
 
 			} else {
 				g_warning ("Error: %s\n", err->message);
-				g_free (text);
 				g_free (err);
 			}
 
+			g_free (text);
+			return TRUE;
+
 		}
 
 		g_free (text);
-
-		return TRUE;
 	}
 
 	/* The condition is not G_IO_HUP | G_IO_ERR | G_IO_NVAL, so
