THE NETWORK LISTENER

     + The listener helps with connection setup

          - Introduced in SVR3

          - Enhanced in SVR4

     + A ``super-server'' that manages network addresses

     + Can only be used with connection-oriented transports

     + Does the t_open( ), t_bind( ), t_listen( ), etc. for you

     + When connection indication arrives, it accepts the connection
       and starts your application with fd 0, 1, and 2 connected into
       the transport provider

     + You simply have to start doing t_snd( ) and t_rcv( ) calls

     + You specify the address of your service in a listener database
       file

     + If desired, the listener can set up ``read/write'' mode on the
       transport provider

          - Allow you to do read( ) and write( ) calls instead of
            t_snd( ) and t_rcv( )

     + The SVR3 version of the listener worked differently

          - You connected to the listener on a well-known address

          - You sent it a value that represented a service

          - The listener read the value and started the associated
            service with fd 0, 1, and 2 connected into the transport
            provider

     + Required the client to send a message before communication
       could start


INETD

     + Helps with connection setup over TCP/IP

     + Works with both TCP and UDP

     + Does the socket( ), bind( ), etc. for you

     + When connection indication arrives over TCP, inetd accepts the
       connection and starts up your application with fd 0 and 1
       connected into TCP

     + When a datagram arrives over UDP, inetd starts up your
       application with fd 0 and 1 associated with UDP

     + Inetd get its information from the /etc/inetd.conf file

     + This file specifies:

          - Service name

          - Indication of TCP or UDP

          - A specification of the service's effective user id



PROBLEMS WITH TLI

     + The server and client must know several things:

          - Which transport provider to use

          - The server address

          - The name of the device to open

     + New features in System V Release 4.0 make this easier

NETWORK SELECTION

     + The Network Selection Facility allows applications to obtain
       information about all transport providers on the machine

          - Semantics: connection-oriented, connectionless,
            connection-oriented with orderly release

          - Protocol family (inet, osi, etc.)

          - Device to open to access the transport provider

          - Dynamic library to use to get addresses

     + Applications can loop through the transport providers on the
       system searching for specific transports (e.g., OSI
       transports) or transports with specific characteristics (e.g.,
       datagram transports)


                          TRANSPORT PROVIDER DATABASE

     + The Network Selection routines consult a database to get their
       information

     + The database is the /etc/netconfig file


                            THE /etc/netconfig FILE

       Example:

udp  tpi_clts    v   inet    udp     /dev/udp        /usr/lib/tcpip.so
tp4  tpi_cots    v   osinet  ositp4  /dev/tp4        /usr/lib/straddr.so


          + Fields:

               - Local name of the transport

               - Semantics

               - Flags

               - Protocol family name

               - Protocol name

               - Device to access the transport

               - Name-to-address mapping libraries


                                    EXAMPLE

       void *handlep;
       struct netconfig *netconfigp;
               .
               .
               .
       if ((handlep = setnetpath()) == NULL) {
               nc_perror(argv[0]);
               exit(1);
       }

       while ((netconfigp = getnetpath(handlep)) != NULL) {
               /*
                *   All information about the transport provider
                *   is in the "netconfigp" variable.
                *   At each iteration of the loop, netconfigp
                *   will point to an entry in /etc/netconfig.
                */
               process_transport(netconfigp);

       }
       endnetconfig(handlep);



       - The netconfig structure has the following elements:


       struct netconfig {
       char           *nc_netid;     /* local name of provider   */

       unsigned long   nc_semantics; /* a value specifying       *
                                      * connectionless,          *
                                      * connection oriented, or  *
                                      * connection-oriented with *
                                      * orderly release          */

       unsigned long   nc_flag;      /* flags, currently visible *
                                      * or not                   */

       char           *nc_protofmly; /* protocol family name     */

       char           *nc_proto;     /* well-known name          */

       char           *nc_device;    /* full path name to device */

       unsigned long   nc_nlookups;  /* the number of libraries  *
                                      * for address resolution   */

       char          **nc_lookups;   /* an array of the full     *
                                      * path names of address    *
                                      * lookup libraries         */
       }


                             INFLUENCING THE LOOP

     + Users can influence the loop by using the NETPATH environment
       variable

     + Example:

                            NETPATH=tp4:tcp:udp

          - This will cause the loop to return the information for
            tp4 first, then tcp, then udp


NAME-TO-ADDRESS MAPPING

     + Generic routines are available to obtain addresses of services
       on a host over a given transport provider

     + Frees the application from maintaining transport-specific
       files

     + Allows full transport provider independence


                               MAPPING ROUTINES

     + netdir_getbyname( )

          - Given a transport provider specification, hostname, and
            service, returns a list of addresses

     + netdir_getbyaddr( )

          - Given an address and a transport provider specification,
            returns hostname/service pairs

     + taddr2uaddr( )

          - Given an address and a transport provider specification,
            returns a printable string representation of the address
            (a ``universal address'')

     + uaddr2taddr( )

          - Given a universal address and a transport provider
            specification, return the local representation of the
            address

     + netdir_options( )

          - Performs transport provider specific functionality (check
            if a port is a reserved port, etc.)


                                    EXAMPLE
       #include <netconfig.h>
       #include <netdir.h>
       #include <tiuser.h>

       main(argc, argv)
       int argc;
       char *argv[];
       {
               void *handlep;
               struct netconfig *netconfigp;
               struct nd_hostserv nd_hostserv;
               struct nd_addrlist *nd_addrlistp;
               struct netbuf *netbufp;
               int i,j;

               /*
                *  Initialize the network selection routines
                */

               if ((handlep = setnetpath()) == NULL) {
                       nc_perror(argv[0]);
                       exit(1);
               }

               /*
                *  Set up the information for the name-to-address
                *  mapping routines
                */

               nd_hostserv.h_host = "frodo";
               nd_hostserv.h_serv = "database";

               /*
                *  Loop through all visible transport providers
                *  on the system
                */

               while ((netconfigp = getnetpath(handlep)) != NULL) {

                       printf("For transport %s:\n",
                                       netconfigp->nc_netid);

                       /*
                        *  Get the address of the service for the
                        *  current transport provider
                        */

                       if (netdir_getbyname(netconfigp,
                           &nd_hostserv, &nd_addrlistp) != 0) {
                               printf("No addresses found\n");
                               continue;
                       }

                       /*
                        *  Print the addresses in hex format
                        */

                       netbufp = nd_addrlistp->n_addrs;
                       for (i = 0; i < nd_addrlistp->n_cnt; i++) {
                               printf("\t\t");
                               for (j = 0; j < netbufp->len; j++) {
                                   printf("%.2x", netbufp->buf[j]);
                               }
                               printf("\n");
                               netbufp++;
                       }
               }
               endnetconfig(handlep);
       }


                                HOW IS IT DONE?

     + Each of the routines links in the dynamic library in
       /etc/netconfig for the specified transport provider

     + Once linked in, a transport specific version of the function
       is called to do the work

     + The library is linked in at run time

                                 WHAT USES IT?


     + The RPC facility uses network selection and name-to-address
       mapping

          - The rpcbind command (the new portmapper) allows
            connections on all transport providers on the system

          - Obtains the address to bind to using name-to-address
            routines

          - The NETPATH variable allows administrator to choose which
            transport provider to use if a resource is available over
            several transports

     + RPC services use network selection and name-to-address mapping

     + New network services