X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fsonar.c;h=0fa608aa5b257fcd59edb3ce3dbd676a72061835;hb=3d9140a05b5272fed0883a0af0a71e30ef44d47f;hp=0608ac5bf668e94c0f92ccd4add89a4aab495cea;hpb=93f25dc6827112d98b8b855ea85c8f5eb8123086;p=xscreensaver diff --git a/hacks/sonar.c b/hacks/sonar.c index 0608ac5b..0fa608aa 100644 --- a/hacks/sonar.c +++ b/hacks/sonar.c @@ -28,7 +28,8 @@ * - plot the process table, by process size, cpu usage, or total time; * - plot the logged on users by idle time or cpu usage. * - * Copyright (C) 1998 by Stephen Martin (smartin@vanderfleet-martin.net). + * Copyright (C) 1998, 2001 + * by Stephen Martin (smartin@vanderfleet-martin.net). * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that @@ -37,7 +38,7 @@ * software for any purpose. It is provided "as is" without express or * implied warranty. * - * $Revision: 1.16 $ + * $Revision: 1.19 $ * * Version 1.0 April 27, 1998. * - Initial version @@ -143,6 +144,18 @@ # undef HAVE_PING #endif + +#ifdef HAVE_PING +# if defined(__DECC) || defined(_IP_VHL) + /* This is how you do it on DEC C, and possibly some BSD systems. */ +# define IP_HDRLEN(ip) ((ip)->ip_vhl & 0x0F) +# else + /* This is how you do it on everything else. */ +# define IP_HDRLEN(ip) ((ip)->ip_hl) +# endif +#endif /* HAVE_PING */ + + /* Forward References */ #ifdef HAVE_PING @@ -215,13 +228,14 @@ void *sensor_info; /* Information about the sensor */ * A list of targets to ping. */ -#ifdef HAVE_PING typedef struct ping_target { char *name; /* The name of the target */ struct sockaddr address; /* The address of the target */ struct ping_target *next; /* The next one in the list */ } ping_target; + +#ifdef HAVE_PING /* * Ping Information. * @@ -698,7 +712,7 @@ subnetHostsList(int base, int subnet_width) fprintf (stderr, "%s: pinging %u 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)); + progname, (1L << (32 - subnet_width)) - 1); exit (1); } else if (subnet_width > 30) @@ -1041,13 +1055,7 @@ getping(sonar_info *si, ping_info *pi) 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. - */ - + iphdrlen = IP_HDRLEN(ip) << 2; icmph = (struct ICMP *) &packet[iphdrlen]; /* Was the packet a reply?? */ @@ -1643,7 +1651,7 @@ Sonar(sonar_info *si, Bogie *bl) /* Check for expired tagets and remove them from the visable list */ prev = NULL; - for (bp = si->visable; bp != NULL; bp = bp->next) { + for (bp = si->visable; bp != NULL; bp = (bp ? bp->next : 0)) { /* * Remove it from the visable list if it's expired or we have @@ -1661,6 +1669,7 @@ Sonar(sonar_info *si, Bogie *bl) else prev->next = bp->next; freeBogie(bp); + bp = prev; } else prev = bp; }