ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-FastPing/FPing.xs
(Generate patch)

Comparing AnyEvent-FastPing/FPing.xs (file contents):
Revision 1.6 by root, Fri May 4 15:44:06 2007 UTC vs.
Revision 1.7 by root, Fri May 4 16:17:25 2007 UTC

103 uint8_t dst[16]; 103 uint8_t dst[16];
104} IP6HDR; 104} IP6HDR;
105 105
106#define MAGIC 0xca4c 106#define MAGIC 0xca4c
107 107
108static uint16_t magic;
109
108typedef struct { 110typedef struct {
109 uint8_t type, code; 111 uint8_t type, code;
110 uint16_t cksum; 112 uint16_t cksum;
111 uint16_t id, seq; 113 uint16_t id, seq;
112 uint32_t payload; 114 uint32_t payload;
190 } 192 }
191 193
192 //TODO: bind to source address 194 //TODO: bind to source address
193 195
194 pkt.code = 0; 196 pkt.code = 0;
195 pkt.id = (uint16_t)MAGIC; 197 pkt.id = (uint16_t)magic;
196 pkt.seq = (uint16_t)~MAGIC; 198 pkt.seq = (uint16_t)~magic;
197 pkt.payload = req->payload; 199 pkt.payload = req->payload;
198 200
199 tstamp now = NOW (); 201 tstamp now = NOW ();
200 tstamp next = now; 202 tstamp next = now;
201 203
405BOOT: 407BOOT:
406{ 408{
407 HV *stash = gv_stashpv ("Net::FPing", 1); 409 HV *stash = gv_stashpv ("Net::FPing", 1);
408 410
409 cbs = get_av ("Net::FPing::CB", 1); 411 cbs = get_av ("Net::FPing::CB", 1);
412 magic = getpid () ^ MAGIC;
410 413
411 boot (); 414 boot ();
412 415
413 newCONSTSUB (stash, "ipv4_supported", newSViv (icmp4_fd >= 0)); 416 newCONSTSUB (stash, "ipv4_supported", newSViv (icmp4_fd >= 0));
414 newCONSTSUB (stash, "ipv6_supported", newSViv (icmp6_fd >= 0)); 417 newCONSTSUB (stash, "ipv6_supported", newSViv (icmp6_fd >= 0));
565 continue; 568 continue;
566 569
567 PKT *pkt = (PKT *)(buf + hdrlen); 570 PKT *pkt = (PKT *)(buf + hdrlen);
568 571
569 if (pkt->type != ICMP4_ECHO_REPLY 572 if (pkt->type != ICMP4_ECHO_REPLY
570 || pkt->id != (uint16_t) MAGIC 573 || pkt->id != (uint16_t) magic
571 || pkt->seq != (uint16_t)~MAGIC 574 || pkt->seq != (uint16_t)~magic
572 || !isnormal (pkt->stamp)) 575 || !isnormal (pkt->stamp))
573 continue; 576 continue;
574 577
575 AV *av = newAV (); 578 AV *av = newAV ();
576 av_push (av, newSVpvn ((char *)&sa.sin_addr, 4)); 579 av_push (av, newSVpvn ((char *)&sa.sin_addr, 4));
601 if (len != sizeof (PKT)) 604 if (len != sizeof (PKT))
602 break; 605 break;
603 606
604 if (!res_av 607 if (!res_av
605 || pkt.type != ICMP6_ECHO_REPLY 608 || pkt.type != ICMP6_ECHO_REPLY
606 || pkt.id != (uint16_t) MAGIC 609 || pkt.id != (uint16_t) magic
607 || pkt.seq != (uint16_t)~MAGIC 610 || pkt.seq != (uint16_t)~magic
608 || !isnormal (pkt.stamp)) 611 || !isnormal (pkt.stamp))
609 continue; 612 continue;
610 613
611 AV *av = newAV (); 614 AV *av = newAV ();
612 av_push (av, newSVpvn ((char *)&sa.sin6_addr, 16)); 615 av_push (av, newSVpvn ((char *)&sa.sin6_addr, 16));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines