… | |
… | |
3 | |
3 | |
4 | SYNOPSIS |
4 | SYNOPSIS |
5 | use AnyEvent::FastPing; |
5 | use AnyEvent::FastPing; |
6 | |
6 | |
7 | DESCRIPTION |
7 | DESCRIPTION |
8 | This module was written for a single purpose only: sending ICMP EHCO |
8 | This module was written for a single purpose only: sending ICMP ECHO |
9 | REQUEST packets as quickly as possible to a large number of hosts |
9 | REQUEST packets as quickly as possible to a large number of hosts |
10 | (thousands to millions). |
10 | (thousands to millions). |
11 | |
11 | |
12 | It employs a sending thread and is fully event-driven (using AnyEvent), |
12 | It employs a sending thread and is fully event-driven (using AnyEvent), |
13 | so you have to run an event model supported by AnyEvent to use this |
13 | so you have to run an event model supported by AnyEvent to use this |
… | |
… | |
37 | seconds between pings to the given range. If omitted, defaults to |
37 | seconds between pings to the given range. If omitted, defaults to |
38 | $send_interval. |
38 | $send_interval. |
39 | |
39 | |
40 | The $send_interval is the minimum interval between sending any two |
40 | The $send_interval is the minimum interval between sending any two |
41 | packets and is a way to make an overall rate limit. If omitted, |
41 | packets and is a way to make an overall rate limit. If omitted, |
42 | pings will be send as fast as possible. |
42 | pings will be sent as fast as possible. |
43 | |
43 | |
44 | The $payload is a 32 bit unsigned integer given as the ICMP ECHO |
44 | The $payload is a 32 bit unsigned integer given as the ICMP ECHO |
45 | REQUEST ident and sequence numbers (in unspecified order :). |
45 | REQUEST ident and sequence numbers (in unspecified order :). |
46 | |
46 | |
47 | The request will be queued and all requests will be served by a |
47 | The request will be queued and all requests will be served by a |
… | |
… | |
93 | (regardless of whether a ping is still in process or not and |
93 | (regardless of whether a ping is still in process or not and |
94 | regardless of whether the reply is actually a reply to a ping sent |
94 | regardless of whether the reply is actually a reply to a ping sent |
95 | earlier). |
95 | earlier). |
96 | |
96 | |
97 | The code reference gets a single parameter - an arrayref with an |
97 | The code reference gets a single parameter - an arrayref with an |
98 | entry for each received packet (replies are beign batched for |
98 | entry for each received packet (replies are being batched for |
99 | greater efficiency). Each packet is represented by an arrayref with |
99 | greater efficiency). Each packet is represented by an arrayref with |
100 | three members: the source address (an octet string of either 4 |
100 | three members: the source address (an octet string of either 4 |
101 | (IPv4) or 16 (IPv6) octets length), the payload as passed to |
101 | (IPv4) or 16 (IPv6) octets length), the payload as passed to |
102 | "icmp_ping" and the round trip time in seconds. |
102 | "icmp_ping" and the round trip time in seconds. |
|
|
103 | |
|
|
104 | Example: register a callback which simply dumps the received data. |
|
|
105 | Since the coderef is created on the fly via sub, it would be hard to |
|
|
106 | unregister this callback again :) |
|
|
107 | |
|
|
108 | AnyEvent::FastPing::register_cb sub { |
|
|
109 | for (@{$_[0]}) { |
|
|
110 | printf "%s %d %g\n", |
|
|
111 | (4 == length $_->[0] ? inet_ntoa $_->[0] : Socket6::inet_ntop (&AF_INET6, $_->[0])), |
|
|
112 | $_->[2], |
|
|
113 | $_->[1]; |
|
|
114 | } |
|
|
115 | }; |
103 | |
116 | |
104 | Example: a single ping reply with payload of 1 from "::1" gets |
117 | Example: a single ping reply with payload of 1 from "::1" gets |
105 | passed like this: |
118 | passed like this: |
106 | |
119 | |
107 | [ [ |
120 | [ [ |
… | |
… | |
129 | AnyEvent::FastPing::unregister_cb \&cb |
142 | AnyEvent::FastPing::unregister_cb \&cb |
130 | Unregister the callback again (make sure you pass the same |
143 | Unregister the callback again (make sure you pass the same |
131 | codereference as to "register_cb"). |
144 | codereference as to "register_cb"). |
132 | |
145 | |
133 | AUTHOR |
146 | AUTHOR |
134 | Marc Lehmann <schmorp@schmorp.de> |
147 | Marc Lehmann <schmorp@schmorp.de> |
135 | http://home.schmorp.de/ |
148 | http://home.schmorp.de/ |
136 | |
149 | |
137 | AUTHOR |
150 | LICENSE |
138 | This software is distributed under the GENERAL PUBLIC LICENSE, version 2 |
151 | This software is distributed under the GENERAL PUBLIC LICENSE, version 2 |
139 | or any later version or, at your option, the Artistic License. |
152 | or any later version or, at your option, the Artistic License. |
140 | |
153 | |