--- AnyEvent-FastPing/FPing.xs 2007/05/04 13:50:02 1.3 +++ AnyEvent-FastPing/FPing.xs 2007/05/04 15:16:14 1.4 @@ -28,8 +28,14 @@ #include #include -#define ICMP4_ECHO 8 -#define ICMP6_ECHO 128 +#ifdef __linux +# include +#endif + +#define ICMP4_ECHO 8 +#define ICMP4_ECHO_REPLY 0 +#define ICMP6_ECHO 128 +#define ICMP6_ECHO_REPLY 129 #define DRAIN_INTERVAL .000001 // how long to wait when sendto returns ENOBUFS, in seconds #define MIN_INTERVAL .000001 // minimum packet send interval, in seconds @@ -187,7 +193,8 @@ pkt.seq = (uint16_t)~MAGIC; pkt.payload = req->payload; - tstamp next = NOW (); + tstamp now = NOW (); + tstamp next = now; while (req->nranges) { @@ -197,8 +204,6 @@ req->ranges [0] = req->ranges [--req->nranges]; else { - tstamp now = NOW (); - // ranges [0] is always the next range to ping tstamp wait = range->next - now; @@ -222,6 +227,8 @@ nanosleep (&ts, 0); } + now = NOW (); + pkt.stamp = now; pkt.cksum = 0; @@ -348,9 +355,9 @@ #ifdef ICMP_FILTER { - icmp_filter oval; - oval.data = 0xffffffff & ~(1 << ICMP4_ECHO); - setsockopt (icmpv4_fd, SOL_RAW, ICMP_FILTER, &oval, sizeof oval); + struct icmp_filter oval; + oval.data = 0xffffffff & ~(1 << ICMP4_ECHO_REPLY); + setsockopt (icmp4_fd, SOL_RAW, ICMP_FILTER, &oval, sizeof oval); } #endif @@ -389,8 +396,8 @@ newCONSTSUB (stash, "ipv4_supported", newSViv (icmp4_fd >= 0)); newCONSTSUB (stash, "ipv6_supported", newSViv (icmp6_fd >= 0)); - newCONSTSUB (stash, "ipv4_pktsize", newSViv (HDR_SIZE_IP4 + sizeof (PKT))); - newCONSTSUB (stash, "ipv6_pktsize", newSViv (HDR_SIZE_IP6 + sizeof (PKT))); + newCONSTSUB (stash, "icmp4_pktsize", newSViv (HDR_SIZE_IP4 + sizeof (PKT))); + newCONSTSUB (stash, "icmp6_pktsize", newSViv (HDR_SIZE_IP6 + sizeof (PKT))); } PROTOTYPES: DISABLE @@ -542,9 +549,9 @@ PKT *pkt = (PKT *)(buf + hdrlen); - if (pkt->id != (uint16_t)MAGIC + if (pkt->type != ICMP4_ECHO_REPLY + || pkt->id != (uint16_t) MAGIC || pkt->seq != (uint16_t)~MAGIC - || pkt->type != ICMP4_ECHO || !isnormal (pkt->stamp)) continue; @@ -576,8 +583,8 @@ if (len != sizeof (PKT)) break; - if (pkt.type != ICMP6_ECHO - || pkt.id != (uint16_t)MAGIC + if (pkt.type != ICMP6_ECHO_REPLY + || pkt.id != (uint16_t) MAGIC || pkt.seq != (uint16_t)~MAGIC || !isnormal (pkt.stamp)) continue;