Subject: pkg/19092: xsreensaver "sonar" mis-computes ping list when long is 64 bits
To: None <gnats-bugs@gnats.netbsd.org>
From: Ed Gould <ed@left.wing.org>
List: netbsd-bugs
Date: 11/17/2002 18:55:04
>Number:         19092
>Category:       pkg
>Synopsis:       xsreensaver "sonar" mis-computes ping list when long is 64 bits
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Nov 17 18:56:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Ed Gould
>Release:        NetBSD 1.6; xscreensaver-4.06 from pkgsrc
>Organization:

>Environment:
System: NetBSD scharffenberger.wing.org 1.6 NetBSD 1.6 (ALPHA-$Revision: 1.164 $) #2: Mon Nov 11 15:54:53 PST 2002 ed@scharffenberger.wing.org:/.automount/tanker/root/u/scharffenberger/src/sys/arch/alpha/compile/SCHARFFENBERGER alpha
Architecture: alpha
Machine: alpha
>Description:
	When C type long contains 64 bits (actually, when it is larger than
	an IPv4 address), the "sonar" screensaver fails to skip the
	subnet broadcast address.
>How-To-Repeat:
	Run

		/usr/pkg/libexec/xscreensaver/sonar -debug -ping subnet

	and observe the list of hosts to be pinged.  (Run as root if the
	executable has not been made set-uid root.)
>Fix:
	This patch works on Alpha, and will work on other architectures
	with the #if condition adjusted to a more suitable value.

--- sonar.c.orig        Sun Nov 17 14:31:45 2002
+++ sonar.c     Sun Nov 17 14:38:39 2002
@@ -155,6 +155,14 @@
 # endif
 #endif /* HAVE_PING */
 
+/* Machine Dependencies */
+
+#if     __alpha /* really 64-bit long */
+typedef unsigned int    ipaddr_t;
+#else
+typedef unsigned long   ipaddr_t;
+#endif
+
 
 /* Forward References */
 
@@ -520,14 +528,14 @@
 
 
 static void
-print_host (FILE *out, unsigned long ip, const char *name)
+print_host (FILE *out, ipaddr_t ip, const char *name)
 {
   char ips[50];
-  sprintf (ips, "%lu.%lu.%lu.%lu",
-           (ip)       & 255,
-           (ip >>  8) & 255,
-           (ip >> 16) & 255,
-           (ip >> 24) & 255);
+  sprintf (ips, "%u.%u.%u.%u",
+           (unsigned int)(ip)       & 255,
+           (unsigned int)(ip >>  8) & 255,
+           (unsigned int)(ip >> 16) & 255,
+           (unsigned int)(ip >> 24) & 255);
   if (!name || !*name) name = "<unknown>";
   fprintf (out, "%-16s %s\n", ips, name);
 }
@@ -570,7 +578,7 @@
     /* Don't ever use loopback (127.0.0) hosts */
     {
       struct sockaddr_in *iaddr = (struct sockaddr_in *) &(target->address);
-      unsigned long ip = iaddr->sin_addr.s_addr;
+      ipaddr_t ip = iaddr->sin_addr.s_addr;
       if ((ip         & 255) == 127 &&
           ((ip >>  8) & 255) == 0 &&
           ((ip >> 16) & 255) == 0)
@@ -587,7 +595,7 @@
     if (debug_p)
       {
         struct sockaddr_in *iaddr = (struct sockaddr_in *) &(target->address);
-        unsigned long ip = iaddr->sin_addr.s_addr;
+        ipaddr_t ip = iaddr->sin_addr.s_addr;
         fprintf (stderr, "%s:   added ", progname);
         print_host (stderr, ip, target->name);
       }
@@ -731,7 +739,7 @@
   for (rest = head; rest; rest = rest->next)
     {
       struct sockaddr_in *i1 = (struct sockaddr_in *) &(rest->address);
-      unsigned long ip1 = i1->sin_addr.s_addr;
+      ipaddr_t ip1 = i1->sin_addr.s_addr;
 
       static ping_target *rest2;
       for (rest2 = rest; rest2; rest2 = rest2->next)
@@ -740,7 +748,7 @@
             {
               struct sockaddr_in *i2 = (struct sockaddr_in *)
                 &(rest2->next->address);
-              unsigned long ip2 = i2->sin_addr.s_addr;
+              ipaddr_t ip2 = i2->sin_addr.s_addr;
 
               if (ip1 == ip2)
                 {
@@ -772,7 +780,7 @@
 static ping_target *
 subnetHostsList(int base, int subnet_width) 
 {
-    unsigned long mask;
+    ipaddr_t mask;
 
     /* Local Variables */
 
@@ -940,7 +948,7 @@
         for (t = pi->targets; t; t = t->next)
           {
             struct sockaddr_in *iaddr = (struct sockaddr_in *) &(t->address);
-            unsigned long ip = iaddr->sin_addr.s_addr;
+            ipaddr_t ip = iaddr->sin_addr.s_addr;
             fprintf (stderr, "%s:   ", progname);
             print_host (stderr, ip, t->name);
           }
@@ -1903,7 +1911,7 @@
           /* subnet: A.B.C.D/M
              subnet: A.B.C/M
            */
-          unsigned long ip = (n0 << 24) | (n1 << 16) | (n2 << 8) | n3;
+          ipaddr_t ip = (n0 << 24) | (n1 << 16) | (n2 << 8) | n3;
           new = subnetHostsList(ip, m);
         }
       else if (4 == sscanf (token, "%d.%d.%d.%d %c", &n0, &n1, &n2, &n3, &d))

>Release-Note:
>Audit-Trail:
>Unformatted:
 	<Please check that the above is correct for the bug being reported,>
 	<and append source date of snapshot, if applicable (one line).>