/* Ping.rex * * Demonstrates an example of a Ping using RexxSock 0.2 * with Reginald REXX. */ /* Register all REXXSOCK functions */ LIBRARY rexxsock /* FUNCDEF some needed Windows functions */ 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 /* Ask user to enter the host name (ie, microsoft.com) or IP address * (199.100.0.1) */ SAY "Enter host name (microsoft.com) or IP address (199.100.0.1):" PULL NAME /* Assume he entered a host name */ err = SockGetHostByName(NAME, 'server.!') /* Tell REXXSOCK that we want it to raise USER 10 condition for any * error (besides SYNTAX errors of course). We also want SockErrNo * set (instead of ErrNo) */ SockInit(10, 1) /* If SockGetHostByName failed, then assume he entered an IP address instead */ IF err == 0 THEN SockGetHostByAddr(NAME, 'server.!') /* Get the IP address as a single numeric value */ addr = VALUEIN(sockaddrconvert(server.!addr),,4,'V') /* Get an ICMP echo request handle */ hndlfile = icmpcreatefile() IF hndlfile \== 0 THEN DO 4 ipinfo.1 = 255 ipinfo.2 = 0 ipinfo.3 = 0 ipinfo.4 = 0 ipinfo.5 = 0 /* Request an ICMP echo */ icmpsendecho(hndlfile, addr, , , ipinfo, icmpecho, 28, 5000 /* Time to wait in milliseconds */) /* Print the results */ 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 condition which we are using for REXXSOCK functions * when they report errors. We told REXXSOCK to raise the USER 10 * condition if there is ever any error (other than a SYNTAX error). * So we jump here if it is raised. So, if we're here, then some * REXXSOCK function has had an error. */ CATCH user 10 SockPSock_Errno()