* software for any purpose. It is provided "as is" without express or
* implied warranty.
*
- * $Revision: 1.18 $
+ * $Revision: 1.20 $
*
* Version 1.0 April 27, 1998.
* - Initial version
# 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
typedef struct ping_target {
char *name; /* The name of the target */
+#ifdef HAVE_PING
struct sockaddr address; /* The address of the target */
+#endif /* HAVE_PING */
struct ping_target *next; /* The next one in the list */
} ping_target;
char *name;
struct sigaction sa;
struct itimerval it;
+ fd_set rfds;
+ struct timeval tv;
/* Set up a signal to interupt our wait for a packet */
/* Wait for a result packet */
fromlen = sizeof(from);
- while (! timer_expired &&
- (result = recvfrom(pi->icmpsock, packet, sizeof(packet),
- 0, &from, &fromlen)) > 0) {
+ while (! timer_expired) {
+ tv.tv_usec=pi->timeout;
+ tv.tv_sec=0;
+ FD_ZERO(&rfds);
+ FD_SET(pi->icmpsock,&rfds);
+ /* only wait a little while, in case we raced with the timer expiration.
+ From Valentijn Sessink <valentyn@openoffice.nl> */
+ if (select(pi->icmpsock+1, &rfds, NULL, NULL, &tv) >0) {
+ result = recvfrom(pi->icmpsock, packet, sizeof(packet),
+ 0, &from, &fromlen);
/* Check the packet */
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?? */
new->distance = delta(then, &now) / 100;
if (new->distance == 0)
new->distance = 2; /* HACK */
+ }
}
/* Done */
/* 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
while (token < end)
{
char *next;
+# ifdef HAVE_PING
ping_target *new;
struct stat st;
unsigned int n0=0, n1=0, n2=0, n3=0, m=0;
char d;
+# endif /* HAVE_PING */
for (next = token;
*next != ',' && *next != ' ' && *next != '\t' && *next != '\n';
return 0;
}
+#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)))
{
sensor = ping;
}
+#endif /* HAVE_PING */
token = next + 1;
while (token < end &&
debug_p = get_boolean_resource ("debug", "Debug");
sensor = 0;
+# ifdef HAVE_PING
sensor_info = (void *) init_ping();
+# else /* !HAVE_PING */
+ sensor_info = 0;
+ parse_mode (0); /* just to check argument syntax */
+# endif /* !HAVE_PING */
if (sensor == 0)
{