X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fsonar.c;h=3a8cf468cf668f1ac8b4f0a709a89120bfc5bdf0;hb=c596d1306f5f92f7eab76224d3b049980a14adcb;hp=5f6510ccce553baec7a6674ad8ee3e1785ae84c5;hpb=278c59e14c53fd412b734e699bd4f314f766f804;p=xscreensaver diff --git a/hacks/sonar.c b/hacks/sonar.c index 5f6510cc..3a8cf468 100644 --- a/hacks/sonar.c +++ b/hacks/sonar.c @@ -37,7 +37,7 @@ * software for any purpose. It is provided "as is" without express or * implied warranty. * - * $Revision: 1.9 $ + * $Revision: 1.13 $ * * Version 1.0 April 27, 1998. * - Initial version @@ -116,6 +116,10 @@ #undef MY_MIN #define MY_MIN(a,b) ((a)<(b)?(a - 50):(b - 10)) +#ifndef LINE_MAX +# define LINE_MAX 2048 +#endif + /* Frigging icmp */ #if defined(HAVE_ICMP) @@ -569,12 +573,28 @@ readPingHostsFile(char *fname) else continue; + /* Check to see if the addr looks like an addr. If not, assume + the addr is a name and there is no addr. This way, we can + handle files whose lines have "xx.xx.xx.xx hostname" as their + first two tokens, and also files that have a hostname as their + first token (like .ssh/known_hosts and .rhosts.) + */ + { + int i; char c; + if (4 != sscanf(addr, "%d.%d.%d.%d%c", &i, &i, &i, &i, &c)) + { + name = addr; + addr = NULL; + } + } + printf ("\"%s\" \"%s\"\n", name, addr); + /* Create a new target using first the name then the address */ new = NULL; if (name != NULL) new = newHost(name); - if (new == NULL) + if (new == NULL && addr != NULL) new = newHost(addr); /* Add it to the list if we got one */ @@ -680,6 +700,10 @@ subnetHostsList(void) /* Construct targets for all addresses in this subnet */ + /* #### jwz: actually, this is wrong, since it assumes a + netmask of 255.255.255.0. But I'm not sure how to find + the local netmask. + */ for (i = 254; i > 0; i--) { sprintf(p, "%d", i); new = newHost(address); @@ -762,8 +786,10 @@ init_ping(void) /* Unknown source */ - fprintf(stderr, "%s: illegal pingSource: %s\n", progname, src); - goto ping_init_error; + fprintf(stderr, + "%s: pingSource must be `file', `list', or `subnet', not: %s\n", + progname, src); + exit (1); } /* Make sure there is something to ping */ @@ -982,7 +1008,13 @@ getping(sonar_info *si, ping_info *pi, int ttl) gettimeofday(&now, (struct timezone *) 0); ip = (struct ip *) packet; + iphdrlen = ip->ip_hl << 2; + /* On DEC OSF1 4.0, the preceeding line needs to be + iphdrlen = (ip->ip_vhl & 0x0F) << 2; + but I don't know how to do this portably. -- jwz. + */ + icmph = (struct ICMP *) &packet[iphdrlen]; /* Was the packet a reply?? */ @@ -1454,7 +1486,8 @@ DrawBogie(sonar_info *si, int draw, char *name, int degrees, /* Compute the coordinates of the object */ - distance = (log((double) distance) / 10.0) * si->radius; + if (distance != 0) + distance = (log((double) distance) / 10.0) * si->radius; x = ox + ((double) distance * cos(4.0 * ((double) degrees)/57.29578)); y = oy - ((double) distance * sin(4.0 * ((double) degrees)/57.29578));