Add Book to My BookshelfPurchase This Book Online

Chapter 15 - Networking with TLI

UNIX Systems Programming for SVR4
David A. Curry
 Copyright © 1996 O'Reilly & Associates, Inc.

Other Functions
Other useful functions provided in the TLI are described below.
Transport Endpoint Names
The t_getname function is used to obtain the address bound to the local or remote side of a connection. (Through an oversight, this function is not documented in SVR4.)
    #include <tiuser.h>
    int t_getname(int fd, struct netbuf *namep, int type);
The fd parameter is the transport endpoint. In the struct netbuf structure pointed to by namep, the buf and maxlen fields should be set accordingly. The type parameter may take on one of two values:
LOCALNAME
Return the address bound to the local transport endpoint.
REMOTENAME
Return the address bound to the remote transport endpoint.
The t_getname function returns 0 on success, and -1 on failure. If it fails, t_errno (and perhaps errno) will contain the error indication.
Connection State
The t_getstate function is used to obtain the current state of a transport endpoint:
    #include <tiuser.h>
    int t_getstate(int fd);
This function returns -1 if an error occurs and places the error indication in t_errno (and perhaps errno). On success, it returns one of the following constants, describing the state of the endpoint:
T_UNBND
The transport endpoint is not bound to an address.
T_IDLE
The transport endpoint is bound to an address, but is not connected to anything.
T_OUTCON
An outgoing connection request is pending on the endpoint.
T_INCON
An incoming connection request is pending on the endpoint.
T_DATAXFER
The endpoint is currently transferring data.
T_OUTREL
An orderly release has been sent on the endpoint.
T_INREL
An orderly release has been received on the endpoint.
One problem with the TLI is that the library state is lost after a call to exec. This makes it impossible to use the t_getstate function. To fix this, the t_sync function can be called to restore the library state:
    #include <tiuser.h>
    int t_sync(int fd);
On success, the current state as defined above is returned. On failure, -1 is returned and t_errno (and perhaps errno) will contain the error indication.
Asynchronous Events
A number of asynchronous events can occur on the communications channel that will cause TLI functions to return errors. Whenever they do, examine t_errno. If its value is TLOOK, then the t_look function should be called:
    #include <tiuser.h>
    int t_look(int fd);
This function returns -1 on error and stores the error indication in t_errno (and perhaps errno). On success, it returns an indication of which asynchronous event has occurred:
T_LISTEN
A connection request has arrived on the endpoint.
T_CONNECT
A connection confirmation has arrived on the endpoint.
T_DATA
Normal data has arrived on the endpoint.
T_EXDATA
Expedited data has arrived on the endpoint.
T_DISCONNECT
A disconnect indication has arrived on the endpoint.
T_UDERR
A datagram error indication has arrived on the endpoint.
T_ORDREL
An orderly release indication has arrived on the endpoint.
Address Conversion
Two functions convert between the internal representation of an address and a character string. The character string is a set of decimal byte values, separated by periods. Note that the string includes both the host address and the service port number. The functions to perform these conversions are:
    #include <netdir.h>
    char *taddr2uaddr(const struct netconfig *config,
            const struct netbuf *addr);
    struct netbuf *uaddr2taddr(const struct netconfig *config,
            const char *uaddr);
The taddr2uaddr function converts the TLI address in the struct netbuf structure pointed to by addr to a “universal address” in a character string and returns the character string. The uaddr2taddr function converts the universal address in uaddr to a TLI address and returns a pointer to it in a struct netbuf. Both functions must have the current network selection passed to them in the config parameter.
These functions are not available in HP-UX 10.x.

Previous SectionNext Section
Books24x7.com, Inc © 2000 –  Feedback