Make sure the ping comes from the correct ip.
parent
7b0a50e7d2
commit
2e72e91f92
|
@ -4,7 +4,7 @@
|
||||||
USING: accessors byte-arrays calendar checksums
|
USING: accessors byte-arrays calendar checksums
|
||||||
checksums.internet combinators combinators.smart continuations
|
checksums.internet combinators combinators.smart continuations
|
||||||
destructors io.sockets io.sockets.icmp io.timeouts kernel pack
|
destructors io.sockets io.sockets.icmp io.timeouts kernel pack
|
||||||
random sequences ;
|
random sequences locals ;
|
||||||
|
|
||||||
IN: ping
|
IN: ping
|
||||||
|
|
||||||
|
@ -35,8 +35,12 @@ TUPLE: echo type identifier sequence data ;
|
||||||
: send-ping ( addr datagram -- )
|
: send-ping ( addr datagram -- )
|
||||||
[ 0 { } <echo> echo>byte-array ] 2dip send ;
|
[ 0 { } <echo> echo>byte-array ] 2dip send ;
|
||||||
|
|
||||||
: recv-ping ( datagram -- echo )
|
:: recv-ping ( addr datagram -- echo )
|
||||||
receive drop 20 tail byte-array>echo ;
|
datagram receive addr = [
|
||||||
|
20 tail byte-array>echo
|
||||||
|
] [
|
||||||
|
drop addr datagram recv-ping
|
||||||
|
] if ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
@ -44,7 +48,7 @@ PRIVATE>
|
||||||
<icmp> resolve-host [ icmp4? ] filter random
|
<icmp> resolve-host [ icmp4? ] filter random
|
||||||
f <icmp4> <datagram>
|
f <icmp4> <datagram>
|
||||||
1 seconds over set-timeout
|
1 seconds over set-timeout
|
||||||
[ [ send-ping ] [ recv-ping ] bi ] with-disposal ;
|
[ [ send-ping ] [ recv-ping ] 2bi ] with-disposal ;
|
||||||
|
|
||||||
: local-ping ( -- reply )
|
: local-ping ( -- reply )
|
||||||
"127.0.0.1" ping ;
|
"127.0.0.1" ping ;
|
||||||
|
@ -52,4 +56,3 @@ PRIVATE>
|
||||||
: alive? ( host -- ? )
|
: alive? ( host -- ? )
|
||||||
[ ping drop t ] [ 2drop f ] recover ;
|
[ ping drop t ] [ 2drop f ] recover ;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue