http://ftp.ksu.edu.tw/FTP/FreeBSD/distfiles/xscreensaver-4.24.tar.gz
[xscreensaver] / hacks / sonar.c
index e2ebf15472978a2523f9d17aba599c6ee2fc2b7b..2b0171d9abd6a9081151c58642a81c5287e17ba5 100644 (file)
@@ -38,7 +38,7 @@
  * software for any purpose.  It is provided "as is" without express or 
  * implied warranty.
  *
- * $Revision: 1.38 $
+ * $Revision: 1.39 $
  *
  * Version 1.0 April 27, 1998.
  * - Initial version
@@ -537,8 +537,9 @@ lookupHost(ping_target *target)
       hent = gethostbyname (target->name);
       if (!hent)
         {
-          fprintf (stderr, "%s: could not resolve host:  %s\n",
-                   progname, target->name);
+          if (debug_p)
+            fprintf (stderr, "%s: could not resolve host:  %s\n",
+                     progname, target->name);
           return 0;
         }
 
@@ -608,7 +609,7 @@ newHost(char *name)
       struct sockaddr_in *iaddr = (struct sockaddr_in *) &(target->address);
       unsigned long ip = iaddr->sin_addr.s_addr;
 
-      if ((ntohl (ip) & 0xFFFFFF00L) == 0x7f000000L)  /* 127.0.0 */
+      if ((ntohl (ip) & 0xFFFFFF00L) == 0x7f000000L)  /* 127.0.0.x */
         {
           if (debug_p)
             fprintf (stderr, "%s:   ignoring loopback host %s\n",
@@ -617,6 +618,19 @@ newHost(char *name)
         }
     }
 
+    /* Don't ever use broadcast (255.x.x.x) hosts */
+    {
+      struct sockaddr_in *iaddr = (struct sockaddr_in *) &(target->address);
+      unsigned long ip = iaddr->sin_addr.s_addr;
+      if ((ntohl (ip) & 0xFF000000L) == 0xFF000000L)  /* 255.x.x.x */
+        {
+          if (debug_p)
+            fprintf (stderr, "%s:   ignoring broadcast host %s\n",
+                     progname, target->name);
+          goto target_init_error;
+        }
+    }
+
     /* Done */
 
     if (debug_p)
@@ -2157,7 +2171,14 @@ screenhack(Display *dpy, Window win)
 
     sensor = 0;
 # ifdef HAVE_PING
-    sensor_info = (void *) init_ping();
+    /* init_ping() will fail if not root, so checking the effective uid
+       isn't necessary -- except that on some systems, it makes some
+       SELinux bullshit show up in syslog, which gets people's panties
+       in a bunch. */
+    if (geteuid () == 0)
+      sensor_info = (void *) init_ping();
+    else
+      sensor_info = 0;
 # else  /* !HAVE_PING */
     sensor_info = 0;
     parse_mode (0);  /* just to check argument syntax */