LIBRARY rexxsock
DO
icmp_options = "8u, 8u, 8u, 8u, 32u"
icmp_echo_reply = "32u, 32u, 32u, 16u, 16u, 32u, 8u, 8u, 8u, 8u, 32u"
FUNCDEF("IcmpCreateFile", "void", "ICMP")
FUNCDEF("IcmpCloseHandle", ", void", "ICMP")
FUNCDEF("IcmpSendEcho", "32u, void, 32u, 32u, 32u, struct ICMP_OPTIONS *, struct ICMP_ECHO_REPLY * stor, 32u, 32u", "ICMP")
CATCH FAILURE
CONDITION('M')
END
SAY "Enter host name (microsoft.com) or IP address (199.100.0.1):"
PULL NAME
err = SockGetHostByName(NAME, 'server.!')
SockInit(10, 1)
IF err == 0 THEN SockGetHostByAddr(NAME, 'server.!')
addr = VALUEIN(sockaddrconvert(server.!addr),,4,'V')
hndlfile = icmpcreatefile()
IF hndlfile \== 0 THEN DO 4
ipinfo.1 = 255
ipinfo.2 = 0
ipinfo.3 = 0
ipinfo.4 = 0
ipinfo.5 = 0
icmpsendecho(hndlfile, addr, , , ipinfo, icmpecho, 28, 5000 )
SAY "Reply from" NAME "Time=" || icmpecho.3 || "ms" "TTL=" || icmpecho.7
IF icmpecho.2 \== 0 THEN DO
SAY "Error Status=" icmpecho.2
SIGNAL done
END
END
ELSE
SAY "Can't get an ICMP echo request handle"
done:
IF hndlfile \== 0 THEN icmpclosehandle(hndlfile)
RETURN
CATCH user 10
SockPSock_Errno() |