… | |
… | |
28 | #include <netinet/in.h> |
28 | #include <netinet/in.h> |
29 | #include <arpa/inet.h> |
29 | #include <arpa/inet.h> |
30 | |
30 | |
31 | #ifdef __linux |
31 | #ifdef __linux |
32 | # include <linux/icmp.h> |
32 | # include <linux/icmp.h> |
|
|
33 | #endif |
|
|
34 | #if IPV6 |
|
|
35 | # include <netinet/icmp6.h> |
33 | #endif |
36 | #endif |
34 | |
37 | |
35 | #define ICMP4_ECHO 8 |
38 | #define ICMP4_ECHO 8 |
36 | #define ICMP4_ECHO_REPLY 0 |
39 | #define ICMP4_ECHO_REPLY 0 |
37 | #define ICMP6_ECHO 128 |
40 | #define ICMP6_ECHO 128 |
… | |
… | |
194 | pkt.payload = req->payload; |
197 | pkt.payload = req->payload; |
195 | |
198 | |
196 | tstamp now = NOW (); |
199 | tstamp now = NOW (); |
197 | tstamp next = now; |
200 | tstamp next = now; |
198 | |
201 | |
|
|
202 | { |
|
|
203 | int r; |
|
|
204 | for (r = req->nranges; r--; ) |
|
|
205 | inc_addr (&req->ranges [r].hi); |
|
|
206 | } |
|
|
207 | |
199 | while (req->nranges) |
208 | while (req->nranges) |
200 | { |
209 | { |
201 | RANGE *range = req->ranges; |
210 | RANGE *range = req->ranges; |
202 | |
211 | |
203 | if (!memcmp (&range->lo, &range->hi, sizeof (addr_t))) |
212 | if (!memcmp (&range->lo, &range->hi, sizeof (addr_t))) |
… | |
… | |
347 | |
356 | |
348 | if (pipe (thr_recv) < 0) |
357 | if (pipe (thr_recv) < 0) |
349 | croak ("Net::FPing: unable to create receive pipe"); |
358 | croak ("Net::FPing: unable to create receive pipe"); |
350 | |
359 | |
351 | icmp4_fd = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); |
360 | icmp4_fd = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); |
352 | #if IPV6 |
|
|
353 | icmp6_fd = socket (AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); |
|
|
354 | #endif |
|
|
355 | |
|
|
356 | #ifdef ICMP_FILTER |
361 | #ifdef ICMP_FILTER |
357 | { |
362 | { |
358 | struct icmp_filter oval; |
363 | struct icmp_filter oval; |
359 | oval.data = 0xffffffff & ~(1 << ICMP4_ECHO_REPLY); |
364 | oval.data = 0xffffffff & ~(1 << ICMP4_ECHO_REPLY); |
360 | setsockopt (icmp4_fd, SOL_RAW, ICMP_FILTER, &oval, sizeof oval); |
365 | setsockopt (icmp4_fd, SOL_RAW, ICMP_FILTER, &oval, sizeof oval); |
361 | } |
366 | } |
|
|
367 | #endif |
|
|
368 | |
|
|
369 | #if IPV6 |
|
|
370 | icmp6_fd = socket (AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); |
|
|
371 | # ifdef ICMP6_FILTER |
|
|
372 | { |
|
|
373 | struct icmp6_filter oval; |
|
|
374 | ICMP6_FILTER_SETBLOCKALL (&oval); |
|
|
375 | ICMP6_FILTER_SETPASS (ICMP6_ECHO_REPLY, &oval); |
|
|
376 | setsockopt (icmp6_fd, IPPROTO_ICMPV6, ICMP6_FILTER, &oval, sizeof oval); |
|
|
377 | } |
|
|
378 | # endif |
362 | #endif |
379 | #endif |
363 | |
380 | |
364 | pthread_attr_init (&attr); |
381 | pthread_attr_init (&attr); |
365 | pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); |
382 | pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); |
366 | #ifdef PTHREAD_SCOPE_PROCESS |
383 | #ifdef PTHREAD_SCOPE_PROCESS |