[gnome-network]IPV6 fix for scan (with patch)



For some reason connect() always returns zero for IPV6 on my RedHat 9
system configured to use IPV4.  This breaks the port scan function in
gnome-netinfo.

Here is a patch that works around that and at the same time reduces the
number of system calls.

Can someone please test this on a IPV6 system?

Let me know if this is ok to commit.

Thanks,
Jon

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/ChangeLog,v
retrieving revision 1.93
diff -u -r1.93 ChangeLog
--- ChangeLog	2 Oct 2003 21:26:16 -0000	1.93
+++ ChangeLog	17 Nov 2003 22:53:27 -0000
@@ -1,3 +1,9 @@
+2003-11-17  William Jon McCann  <mccann jhu edu>
+
+	* scan.c (scan_do): Work around bug in RH9 where connect always
+	returns zero for IPV6.  Also reduces the number of system calls
+	performed.
+
 2003-10-02  Carlos García Campos <carlosgc gnome org>
 
 	* netinfo.c (get_ip_version): added a function to get the 
Index: scan.c
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/scan.c,v
retrieving revision 1.6
diff -u -r1.6 scan.c
--- scan.c	2 Oct 2003 21:26:16 -0000	1.6
+++ scan.c	17 Nov 2003 22:53:27 -0000
@@ -64,6 +64,7 @@
 	gchar buf[SIZE];
 	gchar *service_name = NULL;
 	gint ip_version, pf;
+	struct sockaddr *addr_ptr;
 
 	g_return_if_fail (netinfo != NULL);
 
@@ -123,17 +124,18 @@
 				addr.sin_family = PF_INET;
 				bcopy (hp->h_addr, &addr.sin_addr, hp->h_length);
 				addr.sin_port = htons (i);
+				addr_ptr = (struct sockaddr *) &addr;
 			}
 			else {
 				addr6.sin6_family = PF_INET6;
 				addr6.sin6_flowinfo = 0;
 				bcopy (hp->h_addr, &addr6.sin6_addr, hp->h_length);
-				addr6.sin6_port = htons(i);
+				addr6.sin6_port = htons (i);
+				addr_ptr = (struct sockaddr *) &addr6;
 			}
-
-			if ((connect (sock, (struct sockaddr *) &addr, sizeof (addr)) == 0) ||
-			    (connect (sock, (struct sockaddr *) &addr6, sizeof (addr6)) == 0)) {
-				service = getservbyport (htons(i), "tcp");
+			
+			if (connect (sock, addr_ptr, sizeof (*addr_ptr)) == 0) {
+				service = getservbyport (htons (i), "tcp");
 
 				if (service != NULL) {
 					service_name = g_strdup (service->s_name);


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