X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fsonar.c;h=c58f6aef69aedee357c8cabac933b2a3b893e117;hb=4cecfc89e5e889c7232693897c06168fb378bd5c;hp=1988821bd3612c32dc99aceef288711daeba2d32;hpb=8eb2873d7054e705c4e83f22d18c40946a9e2529;p=xscreensaver diff --git a/hacks/sonar.c b/hacks/sonar.c index 1988821b..c58f6aef 100644 --- a/hacks/sonar.c +++ b/hacks/sonar.c @@ -38,7 +38,7 @@ * software for any purpose. It is provided "as is" without express or * implied warranty. * - * $Revision: 1.20 $ + * $Revision: 1.23 $ * * Version 1.0 April 27, 1998. * - Initial version @@ -523,7 +523,7 @@ static void print_host (FILE *out, unsigned long ip, const char *name) { char ips[50]; - sprintf (ips, "%d.%d.%d.%d", + sprintf (ips, "%lu.%lu.%lu.%lu", (ip) & 255, (ip >> 8) & 255, (ip >> 16) & 255, @@ -787,9 +787,9 @@ subnetHostsList(int base, int subnet_width) if (subnet_width < 24) { fprintf (stderr, - "%s: pinging %u hosts is a bad idea; please use a subnet mask of 24 bits\n" + "%s: pinging %lu hosts is a bad idea; please use a subnet mask of 24 bits\n" " or more (255 hosts max.)\n", - progname, (1L << (32 - subnet_width)) - 1); + progname, (unsigned long) (1L << (32 - subnet_width)) - 1); exit (1); } else if (subnet_width > 30) @@ -860,9 +860,15 @@ subnetHostsList(int base, int subnet_width) fprintf(stderr, "%s: subnet: %s (%d.%d.%d.%d & %d.%d.%d.%d / %d)\n", progname, address, - (base>>24)&255, (base>>16)&255, (base>>8)&255, base&mask&255, - (mask>>24)&255, (mask>>16)&255, (mask>>8)&255, mask&255, - subnet_width); + (int) (base>>24)&255, + (int) (base>>16)&255, + (int) (base>> 8)&255, + (int) (base&mask&255), + (int) (mask>>24)&255, + (int) (mask>>16)&255, + (int) (mask>> 8)&255, + (int) (mask&255), + (int) subnet_width); p = address + strlen(address) + 1; sprintf(p, "%d", i); @@ -1153,7 +1159,12 @@ getping(sonar_info *si, ping_info *pi) while (! timer_expired) { tv.tv_usec=pi->timeout; tv.tv_sec=0; +#if 0 + /* This breaks on BSD, which uses bzero() in the definition of FD_ZERO */ FD_ZERO(&rfds); +#else + memset (&rfds, 0, sizeof(rfds)); +#endif FD_SET(pi->icmpsock,&rfds); /* only wait a little while, in case we raced with the timer expiration. From Valentijn Sessink */ @@ -1339,8 +1350,8 @@ init_sim(void) return NULL; } sprintf(si->teamA[i].name, "%s%03d", si->teamAID, i+1); - si->teamA[i].nexttick = (int) (90.0 * random() / RAND_MAX); - si->teamA[i].nextdist = (int) (100.0 * random() / RAND_MAX); + si->teamA[i].nexttick = random() % 90; + si->teamA[i].nextdist = random() % 100; si->teamA[i].movedonsweep = -1; } @@ -1362,8 +1373,8 @@ init_sim(void) return NULL; } sprintf(si->teamB[i].name, "%s%03d", si->teamBID, i+1); - si->teamB[i].nexttick = (int) (90.0 * random() / RAND_MAX); - si->teamB[i].nextdist = (int) (100.0 * random() / RAND_MAX); + si->teamB[i].nexttick = random() % 90; + si->teamB[i].nextdist = random() % 100; si->teamB[i].movedonsweep = -1; } @@ -1513,8 +1524,8 @@ updateLocation(sim_target *t) int xdist, xtick; - xtick = (int) (3.0 * random() / RAND_MAX) - 1; - xdist = (int) (11.0 * random() / RAND_MAX) - 5; + xtick = (int) (random() % 3) - 1; + xdist = (int) (random() % 11) - 5; if (((t->nexttick + xtick) < 90) && ((t->nexttick + xtick) >= 0)) t->nexttick += xtick; else @@ -1835,6 +1846,7 @@ parse_mode (Bool ping_works_p) { char *source = get_string_resource ("ping", "Ping"); char *token, *end; + char dummy; ping_target *hostlist = 0; @@ -1904,7 +1916,7 @@ parse_mode (Bool ping_works_p) { new = subnetHostsList(0, 24); } - else if (1 == sscanf (token, "subnet/%d %c", &m)) + else if (1 == sscanf (token, "subnet/%d %c", &m, &dummy)) { new = subnetHostsList(0, m); }