Rexx Finger Script Print

/* Fingerd - Finger Server in REXX */
/* Author - Brian D. Jones */
/* Date - 18/04/96 */
/* Email: This email address is being protected from spambots. You need JavaScript enabled to view it. */
/* Load all rexxutil functions */
CALL rxfuncadd sysloadfuncs, rexxutil, sysloadfuncs
CALL sysloadfuncs

/* Load all TCP Socket functions */
CALL rxfuncadd "SockLoadFuncs", "rxSock", "SockLoadFuncs"
ErrCode = SockLoadFuncs()
if Not ErrCode = 0 Then Do
Say 'SockLoadFuncs() failed:' ErrCode
Return ErrCode
End

/* Setup reply file name */
etc = VALUE('ETC', , 'OS2ENVIRONMENT') /* Remove "OS2" for Windows */
MsgFile = etc'\finger.txt'
CrLf = D2C(13) || D2C(10)

/* Open a Socket... */
Socket = SockSocket("AF_INET", "SOCK_STREAM", "0" )
If Socket < 0 Then Do
Say 'SockSocket() failed:' Socket
Return Socket
End

/* Bind... */
address.family = "AF_INET"
address.port = 79 /* Standard Finger Port - could be parm */
address.addr = "INADDR_ANY"
ErrCode = SockBind( socket, "address." )
If ErrCode < 0 Then Do
Say 'SockBind() failed:' ErrCode
Return ErrCode
End

Signal On Halt Name HaltExit

/* Loop... */
Do Forever

/* Listen for a request... */
If Not SockListen( socket, 1 ) = 0 Then Do
Say 'SockListen() error.'
Return
End

/* Accept a request... */
ClientSocket = SockAccept( Socket, "Client.!" )
If ClientSocket = -1 Then Do
Say 'SockAccept() error.'
Return
End

/* Receive the message... */
Buffer = ' '
Count = SockRecv( ClientSocket, "Buffer", 200 )
If Count = -1 Then Do
Say 'SockRecv() error.'
Return
End
/* Say Client.!family
Say Client.!port
Say Client.!addr
Say Count || ',' LENGTH( Buffer ) */
Buffer = translate(Buffer,,xrange('00'x,'19'x)||xrange('80'x,'ff'x),' ')
If LENGTH( Buffer ) > 1 Then User = Word( Buffer, 1 )
Else User = ''


/* Send a reply... */
Reply = 'Welcome to Sulphide' || CrLf
ErrCode = SockSend( ClientSocket, Reply, LENGTH( Reply ) )

Size = STREAM( MsgFile, 'C', 'Query size' )
Buffer = CHARIN( MsgFile, 1, Size -1 )
ErrCode = STREAM( MsgFile, 'C', 'Close' )

ErrCode = SockSend( ClientSocket, Buffer, LENGTH( Buffer ) )

If LENGTH( User ) > 0 Then Do
Reply = User 'is fine, thank you for asking.' || CrLf
ErrCode = SockSend( ClientSocket, Reply, LENGTH( Reply ) )
End

/* Close conversation... */
ErrCode = SockClose( ClientSocket )

End

HaltExit:

/* Close Server... */
ErrCode = SockClose( Socket )

CALL SockDropFuncs

Server Response Text

===================================
This file is produced by an OS/2 REXX Procedure.

All's well today.
blocky