home *** CD-ROM | disk | FTP | other *** search
- /*
- daytime udp client - Usage: daytimeudp host
- daytime/udp client, to use with dtudpserv
- or any daytime/udp server .
- */
-
- if ~open("STDERR","*","W") then STDERR="STDOUT"
-
- l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
- prg=ProgramName("NOEXT")
- if AddLibrary("rexxsupport.library","rxsocket.library")~=0 then
- call err "can't find" result,1
-
- if ~RMH_ReadArgs("HOST/A") then do
- call PrintFault()
- exit
- end
-
- remote.AddrAddr=resolve(parm.0.value)
- if remote.AddrAddr==-1 then call err "Host <"parm.0.value"> not found.",1
-
- if GetServByName("se","daytime","udp") then
- remote.AddrPort=se.ServPort
- else remote.AddrPort=13
-
- sock=socket("inet","dgram")
- if sock<0 then call err "no socket"
-
- call IOCtlSocket(sock,"fionbio",1)
- sig=2**AllocSignal()
- set.SigEventMask=sig
- call SetSocketBase("set")
- call SetSockOpt(sock,"socket","eventmask","error read")
-
- if connect(sock,"remote")<0 then call err "connect error"
-
- if send(sock,"A"x)~=1 then call err "send error"
-
- wait.read.0=sock
- wait.ex.0=sock
- res=WaitSelect("wait",10,,sig)
-
- if res<0 then call err "wait error"
- if res==0 & and(wait.signals,sig)==0 then call err "timeout",1
-
- call GetSocketEvents("events")
- if events.error then call err "can't connect to" host
-
- n=recv(sock,"buf")
- if len<0 then call "recv error"
- call WriteCH("STDOUT",buf)
- exit
-
- err:
- parse arg msg,noerr
- if noerr~=1 then msg = msg "("ErrorString()")"
- call Writeln(stderr,prg": "msg)
- exit
-