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

    <icmp> resolve-host [ icmp4? ] filter random
    f <icmp4> <datagram>
        1 seconds over set-timeout
    [ [ send-ping ] [ recv-ping ] bi ] with-disposal ;

: local-ping ( -- reply )
    "127.0.0.1" ping ;

: send-ping ( addr datagram -- )
    [ 0 { } <echo> echo>byte-array ] 2dip send ;

:: recv-ping ( addr datagram -- echo )
    datagram receive addr = [
        20 tail byte-array>echo
    ] [
        drop addr datagram recv-ping
    ] if ;

PRIVATE>

