… | |
… | |
96 | |
96 | |
97 | The C<$send_interval> is the minimum interval between sending any two |
97 | The C<$send_interval> is the minimum interval between sending any two |
98 | packets and is a way to make an overall rate limit. If omitted, pings will |
98 | packets and is a way to make an overall rate limit. If omitted, pings will |
99 | be send as fast as possible. |
99 | be send as fast as possible. |
100 | |
100 | |
101 | The C<$payload> is a 32 bit integer given as the ICMP ECHO REQUEST ident |
101 | The C<$payload> is a 32 bit unsigned integer given as the ICMP ECHO |
102 | and sequence numbers (in unspecified order :). |
102 | REQUEST ident and sequence numbers (in unspecified order :). |
103 | |
103 | |
104 | The request will be queued and all requests will be served by a background |
104 | The request will be queued and all requests will be served by a background |
105 | thread in order. When all ranges have been pinged, the C<callback> will be |
105 | thread in order. When all ranges have been pinged, the C<callback> will be |
106 | called. |
106 | called. |
107 | |
107 | |
… | |
… | |
144 | our $ICMP4_FH; |
144 | our $ICMP4_FH; |
145 | our $ICMP4_W = (open $ICMP4_FH, "<&=$ICMP4_FD") && AnyEvent->io (fh => $ICMP4_FH, poll => 'r', cb => \&_recv_icmp4); |
145 | our $ICMP4_W = (open $ICMP4_FH, "<&=$ICMP4_FD") && AnyEvent->io (fh => $ICMP4_FH, poll => 'r', cb => \&_recv_icmp4); |
146 | our $ICMP6_FH; |
146 | our $ICMP6_FH; |
147 | our $ICMP6_W = (open $ICMP6_FH, "<&=$ICMP6_FD") && AnyEvent->io (fh => $ICMP6_FH, poll => 'r', cb => \&_recv_icmp6); |
147 | our $ICMP6_W = (open $ICMP6_FH, "<&=$ICMP6_FD") && AnyEvent->io (fh => $ICMP6_FH, poll => 'r', cb => \&_recv_icmp6); |
148 | |
148 | |
|
|
149 | =item Net::FPing::register_cb \&cb |
|
|
150 | |
|
|
151 | Register a callback that is called for every received ping reply |
|
|
152 | (regardless of whether a ping is still in process or not and regardless of |
|
|
153 | whether the reply is actually a reply ot a ping sent earlier). |
|
|
154 | |
|
|
155 | The code reference gets a single parameter - an arrayref with an |
|
|
156 | entry for each received packet (replies are beign batched for greater |
|
|
157 | efficiency). Each packet is represented by an arrayref with three members: |
|
|
158 | the source address (an octet string of either 4 (IPv4) or 16 (IPv6) octets |
|
|
159 | length), the payload as passed to C<icmp_ping> and the round trip time in |
|
|
160 | seconds. |
|
|
161 | |
|
|
162 | Example: a single ping reply with payload of 1 from C<::1> gets passed |
|
|
163 | like this: |
|
|
164 | |
|
|
165 | [ [ |
|
|
166 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1", |
|
|
167 | "0.000280141830444336", |
|
|
168 | 1 |
|
|
169 | ] ] |
|
|
170 | |
|
|
171 | Example: ping replies for C<127.0.0.1> and C<127.0.0.2>, with a payload of |
|
|
172 | C<0x12345678>: |
|
|
173 | |
|
|
174 | [ |
|
|
175 | [ |
|
|
176 | "\177\0\0\1", |
|
|
177 | "0.00015711784362793", |
|
|
178 | 305419896 |
|
|
179 | ], |
|
|
180 | [ |
|
|
181 | "\177\0\0\2", |
|
|
182 | "0.00090184211731", |
|
|
183 | 305419896 |
|
|
184 | ] |
|
|
185 | ] |
|
|
186 | |
|
|
187 | =item Net::FPing::unregister_cb \&cb |
|
|
188 | |
|
|
189 | Unregister the callback again (make sure you pass the same codereference |
|
|
190 | as to C<register_cb>). |
|
|
191 | |
|
|
192 | =cut |
|
|
193 | |
|
|
194 | our @CB; |
|
|
195 | |
|
|
196 | sub register_cb(&) { |
|
|
197 | push @CB, $_[0]; |
|
|
198 | } |
|
|
199 | |
|
|
200 | sub unregister_cb($) { |
|
|
201 | @CB = grep $_ != $_[0], @CB; |
|
|
202 | } |
|
|
203 | |
149 | 1; |
204 | 1; |
150 | |
205 | |
151 | =back |
206 | =back |
152 | |
207 | |
153 | =head1 BUGS AND SHORTCOMINGS |
208 | =head1 BUGS AND SHORTCOMINGS |