
     D getservbyname   PR              *   ExtProc('getservbyname')
     D  service_name                   *   value options(*string)
     D  protocol_name                  *   value options(*string)

     D p_servent       S               *
     D servent         DS                  based(p_servent)
     D   s_name                        *
     D   s_aliases                     *
     D   s_port                      10I 0
     D   s_proto                       *

     D inet_addr       PR            10U 0 ExtProc('inet_addr')
     D  address_str                    *   value options(*string)

     D INADDR_NONE     C                   CONST(4294967295)

     D inet_ntoa       PR              *   ExtProc('inet_ntoa')
     D  internet_addr                10U 0 value

     D p_hostent       S               *
     D hostent         DS                  Based(p_hostent)
     D   h_name                        *
     D   h_aliases                     *
     D   h_addrtype                  10I 0
     D   h_length                    10I 0
     D   h_addr_list                   *
     D p_h_addr        S               *   Based(h_addr_list)
     D h_addr          S             10U 0 Based(p_h_addr)

     D gethostbyname   PR              *   extproc('gethostbyname')
     D   host_name                     *   value options(*string)

     D socket          PR            10I 0 ExtProc('socket')
     D  addr_family                  10I 0 value
     D  type                         10I 0 value
     D  protocol                     10I 0 value

     D AF_INET         C                   CONST(2)
     D SOCK_STREAM     C                   CONST(1)
     D IPPROTO_IP      C                   CONST(0)

     D connect         PR            10I 0 ExtProc('connect')
     D  sock_desc                    10I 0 value
     D  dest_addr                      *   value
     D  addr_len                     10I 0 value

     D p_sockaddr      S               *
     D sockaddr        DS                  based(p_sockaddr)
     D   sa_family                    5I 0
     D   sa_data                     14A
     D sockaddr_in     DS                  based(p_sockaddr)
     D   sin_family                   5I 0
     D   sin_port                     5U 0
     D   sin_addr                    10U 0
     D   sin_zero                     8A

     D send            PR            10I 0 ExtProc('send')
     D   sock_desc                   10I 0 value
     D   buffer                        *   value
     D   buffer_len                  10I 0 value
     D   flags                       10I 0 value

     D recv            PR            10I 0 ExtProc('recv')
     D   sock_desc                   10I 0 value
     D   buffer                        *   value
     D   buffer_len                  10I 0 value
     D   flags                       10I 0 value

     D close           PR            10I 0 ExtProc('close')
     D  sock_desc                    10I 0 value

     D translate       PR                  ExtPgm('QDCXLATE')
     D   length                       5P 0 const
     D   data                     32766A   options(*varsize)
     D   table                       10A   const

     D msg             S             40A
     D sock            S             10I 0
     D port            S              5U 0
     D addrlen         S             10I 0
     D ch              S              1A
     D host            s             32A
     D file            s             32A
     D IP              s             10U 0
     D p_Connto        S               *
     D RC              S             10I 0
     D Request         S           1024A
     D ReqLen          S             10I 0
     D RecBuf          S          32766A
     D RecLen          S             10I 0 Inz (%Size(RecBuf))

     D TabCol          S             10I 0
     D PafId           S             10A
     D iqtab           S             01A   INZ(x'05')
     D iqdelim         S             01A   INZ(x'05')

      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * RdLine(): This reads one "line" of text data from a socket.
      *
      *   peSock = socket to read from
      *   peLine = a pointer to a variable to put the line of text into
      *   peLength = max possible length of data to stuff into peLine
      *   peXLate = (default: *OFF) Set to *ON to translate ASCII -> EBCDIC
      *   peLF (default: x'0A') = line feed character.
      *   peCR (default: x'0D') = carriage return character.
      *
      *  returns length of data read, or -1 upon error
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D RdLine          PR            10I 0
     D   peSock                      10I 0 value
     D   peLine                        *   value
     D   peLength                    10I 0 value
     D   peXLate                      1A   const options(*nopass)
     D   peLF                         1A   const options(*nopass)
     D   peCR                         1A   const options(*nopass)

      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      *  WrLine() -- Write a line of text to a socket:
      *
      *      peSock = socket descriptor to write to
      *      peLine = line of text to write to
      *    peLength = length of line to write (before adding CRLF)
      *            you can pass -1 to have this routine calculate
      *            the length for you (which is the default!)
      *     peXlate = Pass '*ON' to have the routine translate
      *            this data to ASCII (which is the default) or *OFF
      *            to send it as-is.
      *      peEOL1 = First character to send at end-of-line
      *            (default is x'0D')
      *      peEOL2 = Second character to send at end-of-line
      *            (default is x'0A' if neither EOL1 or EOL2 is
      *            passed, or to not send a second char is EOL1
      *            is passed by itself)
      *
      * Returns length of data sent (including end of line chars)
      *    returns a short count if it couldnt send everything
      *    (if you're using a non-blocking socket) or -1 upon error
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D WrLine          PR            10I 0
     D  peSock                       10I 0 value
     D  peLine                    32766A   const
     D  peLength                     10I 0 value options(*nopass)
     D  peXLate                       1A   const options(*nopass)
     D  peEOL1                        1A   const options(*nopass)
     D  peEOL2                        1A   const options(*nopass)


      * Split Procedure

     D NSplit          PR            10I 0
     D   peLine                        *   value
     D   c                            1A   value


      *DpidToAddress Prototype
     D DpidToAddress   PR            10I 0
     D   pDpid                       10I 0 value

      * OpenPafMemId Prototype
     D OpenPafMemId    PR            10I 0
     D   pPafID                      10A   value

      * GetHintAddr Prototype
     D GetHintAddr     PR            10I 0
     D   pLocality                   30A   value
     D   pAddress                    30A   value

      * FormatAddress Prototype
     D FormatAddress   PR           200A
     D   pAddress                   200A   value
     D   pOptions                    10I 0 value

      * GetAddress Prototype
     D GetAddress      PR            10I 0
     D   peLine                        *   value

      * ValFullAddress Prototype
     D ValFullAddress  PR            10I 0
     D   peLine                        *   value
     D   peOption                     1A   value

      * Properties Prototype
     D Properties      PR            10I 0
     D   pProperty                  200A   value

      * Split input into individual fields FUNCTION
     D* GetToken        Pr              *   ExtProc('strtok')
     D*  String@                        *   Value Options(*String)
     D*  Delimiters@                    *   Value Options(*String)
     D InpString       S          32766A
     D Delimiters      S              2A
     D* Token           S             36A
     D* Token@          S               *
     D TokenCount      S              3P 0
     D* Message         S             52A
     D* Exit            C                   'Exit'
     D AskForInput     C                   'Enter dpid code'
     D AskForAddr      C                   'Search Addr (quit): '
     D AskForLocl      C                   'Search Locality: '
     D inAddress       S             30A
     D inLocality      S             30A
     D AllDone         C                   'All tokens processed'
     D* IQRC            S              1A
     D loop            S             10I 0
     D sResult         s          32766A   inz(*blanks)
     D sOut            s          32766A   inz(*blanks)
     D sResults        s          32766A   varying  DIM(100) inz(*blanks)
     D sFIELDs         s            255A   varying  DIM(60) inz(*blanks)
     D sFIELDNMs       s            255A   varying  DIM(60) inz(*blanks)
     D indata          s             10A   inz(*blanks)
     D indpid          S             10A   inz('44664340')
     D MaxResults      S             10I 0
     D iChoice         S             10I 0

