home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / rxidentd.zip / rxidentd.cmd
OS/2 REXX Batch file  |  1995-06-05  |  6KB  |  182 lines

  1. /*------------------------------------------------------------------
  2.  * rxidentd.cmd - adapted from sample code provided by
  3.  * by Patrick Mueller (pmuellr@vnet.ibm.com)
  4.  *
  5.  * This is a *very* basic identd program which satisifies the
  6.  * only IRC server I use that requires identd services. Your
  7.  * milage may vary. I created this because the very fine identd
  8.  * program written by Sophisto (IRC, #os/2) does not run in OS/2 2.1,
  9.  * and because it was an easy fix. I will fix problems as they arise,
  10.  * if I have time. No guarantees it will work for you. This is my
  11.  * gift to the world. Send Sophisto a card encouraging him to build
  12.  * his identd for 2.1 and send Patrick Mueller a card thanking him for
  13.  * RxSock - it is a great extender for REXX.
  14.  *
  15.  * usage: rxidentd userid [ > log.file ]
  16.  *
  17.  *------------------------------------------------------------------
  18.  * Dennis Peterson - (dkp, IRC, #os/2) dpeterso@inetnw.com
  19.  *------------------------------------------------------------------*/
  20.  
  21. trace off
  22. CRLF = '0d'x'0a'x
  23. parse arg userid .
  24.  
  25. /*------------------------------------------------------------------
  26.  * choose the port
  27.  *------------------------------------------------------------------*/
  28. port = 113
  29.  
  30. /*------------------------------------------------------------------
  31.  * initialize socket package
  32.  *------------------------------------------------------------------*/
  33. if RxFuncQuery("SockLoadFuncs") then
  34.    do
  35.       rc = RxFuncAdd("SockLoadFuncs","RxSock","SockLoadFuncs")
  36.       rc = SockLoadFuncs()
  37.    end
  38.  
  39. /*------------------------------------------------------------------
  40.  * create the initial socket
  41.  *------------------------------------------------------------------*/
  42. s  = SockSocket("AF_INET","SOCK_STREAM",0)
  43. if (s = -1) then
  44.    do
  45.       say "Error on SockSocket:" errno
  46.       exit
  47.    end
  48.  
  49. /*------------------------------------------------------------------
  50.  * catch breaks
  51.  *------------------------------------------------------------------*/
  52. signal on halt
  53.  
  54. /*------------------------------------------------------------------
  55.  * bind socket to port
  56.  *------------------------------------------------------------------*/
  57. server.!family = "AF_INET"
  58. server.!port   = port
  59. server.!addr   = "INADDR_ANY"
  60.  
  61. rc = SockBind(s,"server.!")
  62. if (rc = -1) then
  63.    do
  64.       say "Error on SockBind:" errno
  65.       exit
  66.    end
  67.  
  68. /*------------------------------------------------------------------
  69.  * set queue size
  70.  *------------------------------------------------------------------*/
  71. rc = SockListen(s,10)
  72. if (rc = -1) then
  73.    do
  74.       say "Error on SockListen:" errno
  75.       exit
  76.    end
  77.  
  78.  
  79. /*------------------------------------------------------------------
  80.  * infinite loop to handle requests ...
  81.  *------------------------------------------------------------------*/
  82. do forever
  83.    say "Waiting for client"
  84.  
  85.    /*---------------------------------------------------------------
  86.     * accept a connection
  87.     *---------------------------------------------------------------*/
  88.    ns = SockAccept(s,"client.!")
  89.    if (ns = -1) then
  90.       do
  91.          say "Error on SockAccept:" errno
  92.          exit
  93.       end
  94.  
  95.    /*---------------------------------------------------------------
  96.     * get clients host name
  97.     *---------------------------------------------------------------*/
  98.    if SockGetHostByAddr(client.!addr,"host.!") then
  99.       clientName = host.!name
  100.    else
  101.       clientName = "Unknown"
  102.  
  103.    say "Accepted client:" client.!addr clientName
  104.  
  105.    /*---------------------------------------------------------------
  106.     * get peer host name
  107.     *---------------------------------------------------------------*/
  108.    rc = SockGetPeerName(ns,"peer.!")
  109.    if (rc = -1) then
  110.       do
  111.          say "Error on SockGetPeerName:" errno
  112. /*       exit */
  113.       end
  114.  
  115.    say "PeerName:" peer.!addr
  116.  
  117.    /*---------------------------------------------------------------
  118.     * get socket host name
  119.     *---------------------------------------------------------------*/
  120.    rc = SockGetSockName(ns,"sock.!")
  121.    if (rc = -1) then
  122.       do
  123.          say "Error on SockGetSockName:" errno
  124. /*       exit */
  125.       end
  126.  
  127.    say "SockName:" sock.!addr
  128.  
  129.    /*---------------------------------------------------------------
  130.     * receive data from client
  131.     *---------------------------------------------------------------*/
  132.    rc = SockRecv(ns,"data",1000)
  133.    if (rc = -1) then
  134.       do
  135.          say "Error on SockRecv:" errno
  136.          exit
  137.       end
  138.  
  139.    say "Received:" data
  140.    parse var data data1 . data2 .
  141.    /*---------------------------------------------------------------
  142.     * send data back
  143.     *---------------------------------------------------------------*/
  144.    data_new = data1 || ' , ' || substr(data2,1,4) || ' : USERID : UNIX : 'userid || crlf
  145.    say data_new
  146.  
  147.    rc = SockSend(ns,data_new)
  148.    if (rc = -1) then
  149.       do
  150.          say "Error on SockSend:" errno
  151.          exit
  152.       end
  153.  
  154.    /*---------------------------------------------------------------
  155.     * close the new socket from client
  156.     *---------------------------------------------------------------*/
  157.    rc = SockSoClose(ns)
  158.    ns = ""
  159.    if (rc = -1) then
  160.       do
  161.          say "Error on SockSoClose:" errno
  162.          exit
  163.       end
  164.  
  165.    say "Closing connection"
  166.    say
  167. end
  168.  
  169. /*------------------------------------------------------------------
  170.  * handle break by closing sockets
  171.  *------------------------------------------------------------------*/
  172. halt:
  173.  
  174. say
  175. say "Quitting ..."
  176.  
  177. rc = SockSoClose(s)
  178.  
  179. if datatype(ns,"W") then
  180.    rc = SockSoClose(ns)
  181.  
  182.