 : send-ping ( addr datagram -- )
     [ 0 { } <echo> echo>byte-array ] 2dip send ;
 
-: recv-ping ( datagram -- echo )
-    receive drop 20 tail byte-array>echo ;
+:: recv-ping ( addr datagram -- echo )
+    datagram receive addr = [
+        20 tail byte-array>echo
+    ] [
+        drop addr datagram recv-ping
+    ] if ;
 
 PRIVATE>
 

: alive? ( host -- ? )
    [ ping drop t ] [ 2drop f ] recover ;



USING: accessors byte-arrays calendar checksums
checksums.internet combinators combinators.smart continuations
destructors io.sockets io.sockets.icmp io.timeouts kernel pack
random sequences locals ;

IN: ping

