http://packetstormsecurity.org/UNIX/admin/xscreensaver-4.14.tar.gz
[xscreensaver] / hacks / sonar.c
index 0df716b6028b992ccb12c836ee9d556403716e27..00f7b3f6fc5e7d1a4da7ca874fe4b6b65212b83a 100644 (file)
@@ -38,7 +38,7 @@
  * software for any purpose.  It is provided "as is" without express or 
  * implied warranty.
  *
- * $Revision: 1.24 $
+ * $Revision: 1.29 $
  *
  * Version 1.0 April 27, 1998.
  * - Initial version
@@ -482,7 +482,7 @@ lookupHost(ping_target *target)
                                 (ip[2] << 16) |
                                 (ip[1] <<  8) |
                                 (ip[0]));
-      hent = gethostbyaddr (ip, 4, AF_INET);
+      hent = gethostbyaddr ((const char *) ip, 4, AF_INET);
 
       if (debug_p > 1)
         fprintf (stderr, "%s:   %s => %s\n",
@@ -1012,8 +1012,13 @@ sendping(ping_info *pi, ping_target *pt)
     ICMP_CHECKSUM(icmph) = 0;
     ICMP_ID(icmph) = pi->pid;
     ICMP_SEQ(icmph) = pi->seq++;
+# ifdef GETTIMEOFDAY_TWO_ARGS
     gettimeofday((struct timeval *) &packet[sizeof(struct ICMP)],
                 (struct timezone *) 0);
+# else
+    gettimeofday((struct timeval *) &packet[sizeof(struct ICMP)]);
+# endif
+
     strcpy((char *) &packet[sizeof(struct ICMP) + sizeof(struct timeval)],
           pt->name);
     ICMP_CHECKSUM(icmph) = checksum((u_short *)packet, pcktsiz);
@@ -1117,7 +1122,7 @@ getping(sonar_info *si, ping_info *pi)
     /* Local Variables */
 
     struct sockaddr from;
-    int fromlen;
+    unsigned int fromlen;  /* Posix says socklen_t, but that's not portable */
     int result;
     u_char packet[1024];
     struct timeval now;
@@ -1175,7 +1180,11 @@ getping(sonar_info *si, ping_info *pi)
 
        /* Check the packet */
 
+# ifdef GETTIMEOFDAY_TWO_ARGS
        gettimeofday(&now, (struct timezone *) 0);
+# else
+       gettimeofday(&now);
+# endif
        ip = (struct ip *) packet;
         iphdrlen = IP_HDRLEN(ip) << 2;
        icmph = (struct ICMP *) &packet[iphdrlen];
@@ -1904,6 +1913,7 @@ parse_mode (Bool ping_works_p)
 # endif /* HAVE_PING */
 
       for (next = token;
+           *next &&
            *next != ',' && *next != ' ' && *next != '\t' && *next != '\n';
            next++)
         ;
@@ -1926,8 +1936,8 @@ parse_mode (Bool ping_works_p)
         }
 
 #ifdef HAVE_PING
-      if ((4 == sscanf (token, "%d.%d.%d/%d %c",    &n0,&n1,&n2,    &m,&d)) ||
-          (5 == sscanf (token, "%d.%d.%d.%d/%d %c", &n0,&n1,&n2,&n3,&m,&d)))
+      if ((4 == sscanf (token, "%u.%u.%u/%u %c",    &n0,&n1,&n2,    &m,&d)) ||
+          (5 == sscanf (token, "%u.%u.%u.%u/%u %c", &n0,&n1,&n2,&n3,&m,&d)))
         {
           /* subnet: A.B.C.D/M
              subnet: A.B.C/M
@@ -1935,7 +1945,7 @@ parse_mode (Bool ping_works_p)
           unsigned long 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))
+      else if (4 == sscanf (token, "%u.%u.%u.%u %c", &n0, &n1, &n2, &n3, &d))
         {
           /* IP: A.B.C.D
            */
@@ -1945,7 +1955,7 @@ parse_mode (Bool ping_works_p)
         {
           new = subnetHostsList(0, 24);
         }
-      else if (1 == sscanf (token, "subnet/%d %c", &m, &dummy))
+      else if (1 == sscanf (token, "subnet/%u %c", &m, &dummy))
         {
           new = subnetHostsList(0, m);
         }
@@ -2032,7 +2042,11 @@ screenhack(Display *dpy, Window win)
 
        /* Call the sensor and display the results */
 
+# ifdef GETTIMEOFDAY_TWO_ARGS
        gettimeofday(&start, (struct timezone *) 0);
+# else
+       gettimeofday(&start);
+# endif
        bl = sensor(si, sensor_info);
        Sonar(si, bl);
 
@@ -2042,7 +2056,11 @@ screenhack(Display *dpy, Window win)
        if (si->current == 0)
          si->sweepnum++;
        XSync (dpy, False);
+# ifdef GETTIMEOFDAY_TWO_ARGS
        gettimeofday(&finish, (struct timezone *) 0);
+# else
+       gettimeofday(&finish);
+# endif
        sleeptime = si->delay - delta(&start, &finish);
         screenhack_handle_events (dpy);
        if (sleeptime > 0L)