… | |
… | |
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 | |
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 | }; |
|
|
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 | [ [ |
108 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1", |
121 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1", |