Back to index

im-sdk  12.3.91
Defines | Functions | Variables
Xtrans.c File Reference
#include <ctype.h>
#include <sys/utsname.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define TRANS_TLI_INET_INDEX   1
#define TRANS_TLI_TCP_INDEX   2
#define TRANS_TLI_TLI_INDEX   3
#define TRANS_SOCKET_UNIX_INDEX   4
#define TRANS_SOCKET_LOCAL_INDEX   5
#define TRANS_SOCKET_INET_INDEX   6
#define TRANS_SOCKET_TCP_INDEX   7
#define TRANS_DNET_INDEX   8
#define TRANS_LOCAL_LOCAL_INDEX   9
#define TRANS_LOCAL_PTS_INDEX   10
#define TRANS_LOCAL_NAMED_INDEX   11
#define TRANS_LOCAL_ISC_INDEX   12
#define TRANS_LOCAL_SCO_INDEX   13
#define TRANS_AMOEBA_INDEX   14
#define NUMTRANS   (sizeof(Xtransports)/sizeof(Xtransport_table))
#define PROTOBUFSIZE   20

Functions

void TRANS() FreeConnInfo (XtransConnInfo ciptr)
static Xtransport *TRANS() SelectTransport (char *protocol)
static int TRANS() ParseAddress (char *address, char **protocol, char **host, char **port)
static XtransConnInfo TRANS() Open (int type, char *address)
int TRANS() SetOption (XtransConnInfo ciptr, int option, int arg)
int TRANS() BytesReadable (XtransConnInfo ciptr, BytesReadable_t *pend)
int TRANS() Read (XtransConnInfo ciptr, char *buf, int size)
int TRANS() Write (XtransConnInfo ciptr, char *buf, int size)
int TRANS() Readv (XtransConnInfo ciptr, struct iovec *buf, int size)
int TRANS() Writev (XtransConnInfo ciptr, struct iovec *buf, int size)
int TRANS() Disconnect (XtransConnInfo ciptr)
int TRANS() Close (XtransConnInfo ciptr)
int TRANS() CloseForCloning (XtransConnInfo ciptr)
int TRANS() IsLocal (XtransConnInfo ciptr)
int TRANS() GetMyAddr (XtransConnInfo ciptr, int *familyp, int *addrlenp, Xtransaddr **addrp)
int TRANS() GetPeerAddr (XtransConnInfo ciptr, int *familyp, int *addrlenp, Xtransaddr **addrp)
int TRANS() GetConnectionNumber (XtransConnInfo ciptr)
static int complete_network_count ()
int TRANS() GetHostname (char *buf, int maxlen)

Variables

static Xtransport_table Xtransports []

Define Documentation

#define NUMTRANS   (sizeof(Xtransports)/sizeof(Xtransport_table))

Definition at line 117 of file Xtrans.c.

#define PROTOBUFSIZE   20

Definition at line 151 of file Xtrans.c.

#define TRANS_AMOEBA_INDEX   14

Definition at line 82 of file Xtrans.c.

#define TRANS_DNET_INDEX   8

Definition at line 76 of file Xtrans.c.

#define TRANS_LOCAL_ISC_INDEX   12

Definition at line 80 of file Xtrans.c.

#define TRANS_LOCAL_LOCAL_INDEX   9

Definition at line 77 of file Xtrans.c.

#define TRANS_LOCAL_NAMED_INDEX   11

Definition at line 79 of file Xtrans.c.

#define TRANS_LOCAL_PTS_INDEX   10

Definition at line 78 of file Xtrans.c.

#define TRANS_LOCAL_SCO_INDEX   13

Definition at line 81 of file Xtrans.c.

#define TRANS_SOCKET_INET_INDEX   6

Definition at line 74 of file Xtrans.c.

#define TRANS_SOCKET_LOCAL_INDEX   5

Definition at line 73 of file Xtrans.c.

#define TRANS_SOCKET_TCP_INDEX   7

Definition at line 75 of file Xtrans.c.

#define TRANS_SOCKET_UNIX_INDEX   4

Definition at line 72 of file Xtrans.c.

#define TRANS_TLI_INET_INDEX   1

Definition at line 69 of file Xtrans.c.

#define TRANS_TLI_TCP_INDEX   2

Definition at line 70 of file Xtrans.c.

#define TRANS_TLI_TLI_INDEX   3

Definition at line 71 of file Xtrans.c.


Function Documentation

int TRANS() BytesReadable ( XtransConnInfo  ciptr,
BytesReadable_t pend 
)

Definition at line 848 of file Xtrans.c.

{
    return ciptr->transptr->BytesReadable (ciptr, pend);
}
int TRANS() Close ( XtransConnInfo  ciptr)

Definition at line 910 of file Xtrans.c.

{
    int ret;

    PRMSG (2,"TRANS(Close) (%d)\n", ciptr->fd, 0, 0);

    ret = ciptr->transptr->Close (ciptr);

    TRANS(FreeConnInfo) (ciptr);

    return ret;
}

Here is the call graph for this function:

Definition at line 927 of file Xtrans.c.

{
    int ret;

    PRMSG (2,"TRANS(CloseForCloning) (%d)\n", ciptr->fd, 0, 0);

    ret = ciptr->transptr->CloseForCloning (ciptr);

    TRANS(FreeConnInfo) (ciptr);

    return ret;
}

Here is the call graph for this function:

static int complete_network_count ( ) [static]

Definition at line 1019 of file Xtrans.c.

{
    int count = 0;
    int found_local = 0;
    int i;

    /*
     * For a complete network, we only need one LOCALCONN transport to work
     */

    for (i = 0; i < NUMTRANS; i++)
    {
       if (Xtransports[i].transport->flags & TRANS_ALIAS)
           continue;

       if (Xtransports[i].transport->flags & TRANS_LOCAL)
           found_local = 1;
       else
           count++;
    }

    return (count + found_local);
}
int TRANS() Disconnect ( XtransConnInfo  ciptr)

Definition at line 901 of file Xtrans.c.

{
    return ciptr->transptr->Disconnect (ciptr);
}
void TRANS() FreeConnInfo ( XtransConnInfo  ciptr)

Definition at line 131 of file Xtrans.c.

{
    PRMSG (3,"TRANS(FreeConnInfo) (%x)\n", ciptr, 0, 0);

    if (ciptr->addr)
       free (ciptr->addr);

    if (ciptr->peeraddr)
       free (ciptr->peeraddr);

    if (ciptr->port)
       free (ciptr->port);

    free ((char *) ciptr);
}

Here is the caller graph for this function:

Definition at line 1003 of file Xtrans.c.

{
    return ciptr->fd;
}
int TRANS() GetHostname ( char *  buf,
int  maxlen 
)

Definition at line 1389 of file Xtrans.c.

{
    int len;

#ifdef NEED_UTSNAME
    struct utsname name;

    uname (&name);
    len = strlen (name.nodename);
    if (len >= maxlen) len = maxlen - 1;
    strncpy (buf, name.nodename, len);
    buf[len] = '\0';
#else
    buf[0] = '\0';
    (void) gethostname (buf, maxlen);
    buf [maxlen - 1] = '\0';
    len = strlen(buf);
#endif /* NEED_UTSNAME */
    return len;
}

Here is the caller graph for this function:

int TRANS() GetMyAddr ( XtransConnInfo  ciptr,
int *  familyp,
int *  addrlenp,
Xtransaddr **  addrp 
)

Definition at line 954 of file Xtrans.c.

{
    PRMSG (2,"TRANS(GetMyAddr) (%d)\n", ciptr->fd, 0, 0);

    *familyp = ciptr->family;
    *addrlenp = ciptr->addrlen;

    if ((*addrp = (Xtransaddr *) malloc (ciptr->addrlen)) == NULL)
    {
       PRMSG (1,"TRANS(GetMyAddr) malloc failed\n", 0, 0, 0);
       return -1;
    }
    memcpy(*addrp, ciptr->addr, ciptr->addrlen);

    return 0;
}
int TRANS() GetPeerAddr ( XtransConnInfo  ciptr,
int *  familyp,
int *  addrlenp,
Xtransaddr **  addrp 
)

Definition at line 978 of file Xtrans.c.

{
    PRMSG (2,"TRANS(GetPeerAddr) (%d)\n", ciptr->fd, 0, 0);

    *familyp = ciptr->family;
    *addrlenp = ciptr->peeraddrlen;

    if ((*addrp = (Xtransaddr *) malloc (ciptr->peeraddrlen)) == NULL)
    {
       PRMSG (1,"TRANS(GetPeerAddr) malloc failed\n", 0, 0, 0);
       return -1;
    }
    memcpy(*addrp, ciptr->peeraddr, ciptr->peeraddrlen);

    return 0;
}
int TRANS() IsLocal ( XtransConnInfo  ciptr)

Definition at line 944 of file Xtrans.c.

{
    return (ciptr->family == AF_UNIX);
}
static XtransConnInfo TRANS() Open ( int  type,
char *  address 
) [static]

Definition at line 385 of file Xtrans.c.

{
    char             *protocol = NULL, *host = NULL, *port = NULL;
    XtransConnInfo   ciptr = NULL;
    Xtransport              *thistrans;

    PRMSG (2,"TRANS(Open) (%d,%s)\n", type, address, 0);

#if defined(WIN32) && (defined(TCPCONN) || defined(DNETCONN))
    if (TRANS(WSAStartup)())
    {
       PRMSG (1,"TRANS(Open): WSAStartup failed\n", 0, 0, 0);
       return NULL;
    }
#endif

    /* Parse the Address */

    if (TRANS(ParseAddress) (address, &protocol, &host, &port) == 0)
    {
       PRMSG (1,"TRANS(Open): Unable to Parse address %s\n", address, 0, 0);
       return NULL;
    }

    /* Determine the transport type */

    if ((thistrans = TRANS(SelectTransport) (protocol)) == NULL)
    {
       PRMSG (1,"TRANS(Open): Unable to find transport for %s\n",
              protocol, 0, 0);

       free (protocol);
       free (host);
       free (port);
       return NULL;
    }

    /* Open the transport */

    switch (type)
    {
    case XTRANS_OPEN_COTS_CLIENT:
#ifdef TRANS_CLIENT
       ciptr = thistrans->OpenCOTSClient(thistrans, protocol, host, port);
#endif /* TRANS_CLIENT */
       break;
    case XTRANS_OPEN_COTS_SERVER:
#ifdef TRANS_SERVER
       ciptr = thistrans->OpenCOTSServer(thistrans, protocol, host, port);
#endif /* TRANS_SERVER */
       break;
    case XTRANS_OPEN_CLTS_CLIENT:
#ifdef TRANS_CLIENT
       ciptr = thistrans->OpenCLTSClient(thistrans, protocol, host, port);
#endif /* TRANS_CLIENT */
       break;
    case XTRANS_OPEN_CLTS_SERVER:
#ifdef TRANS_SERVER
       ciptr = thistrans->OpenCLTSServer(thistrans, protocol, host, port);
#endif /* TRANS_SERVER */
       break;
    default:
       PRMSG (1,"TRANS(Open): Unknown Open type %d\n", type, 0, 0);
    }

    if (ciptr == NULL)
    {
       PRMSG (1,"TRANS(Open): transport open failed for %s/%s:%s\n",
              protocol, host, port);
       free (protocol);
       free (host);
       free (port);
       return NULL;
    }

    ciptr->transptr = thistrans;
    ciptr->port = port;                   /* We need this for TRANS(Reopen) */

    free (protocol);
    free (host);

    return ciptr;
}

Here is the call graph for this function:

static int TRANS() ParseAddress ( char *  address,
char **  protocol,
char **  host,
char **  port 
) [static]

Definition at line 190 of file Xtrans.c.

{
    /*
     * For the font library, the address is a string formatted
     * as "protocol/host:port[/catalogue]".  Note that the catologue
     * is optional.  At this time, the catologue info is ignored, but
     * we have to parse it anyways.
     *
     * Other than fontlib, the address is a string formatted
     * as "protocol/host:port".
     *
     * If the protocol part is missing, then assume INET.
     * If the protocol part and host part are missing, then assume local.
     * If a "::" is found then assume DNET.
     */

    char      *mybuf, *tmpptr;
    char      *_protocol, *_host, *_port;
    char      hostnamebuf[256];

    PRMSG (3,"TRANS(ParseAddress) (%s)\n", address, 0, 0);

    /* Copy the string so it can be changed */

    tmpptr = mybuf = (char *) malloc (strlen (address) + 1);
    strcpy (mybuf, address);

    /* Parse the string to get each component */
    
    /* Get the protocol part */

    _protocol = mybuf;

    if ((mybuf = strpbrk (mybuf,"/:")) == NULL)
    {
       /* adress is in a bad format */
       *protocol = NULL;
       *host = NULL;
       *port = NULL;
       free (tmpptr);
       return 0;
    }

    if (*mybuf == ':')
    {
       /*
        * If there is a hostname, then assume inet, otherwise
        * it must be local.
        */
       if (mybuf == tmpptr)
       {
           /* There is neither a protocol or host specified */
           _protocol = "local";
       }
       else
       {
           /* Ther is a hostname specified */
           _protocol = "inet";
           mybuf = tmpptr;  /* reset to the begining of the host ptr */
       }
    }
    else
    {
       /* *mybuf == '/' */

       *mybuf ++= '\0'; /* put a null at the end of the protocol */

       if (strlen(_protocol) == 0)
       {
           /*
            * If there is a hostname, then assume inet, otherwise
            * it must be local.
            */
           if (*mybuf != ':')
              _protocol = "inet";
           else
              _protocol = "local";
       }
    }

    /* Get the host part */

    _host = mybuf;

    if ((mybuf = strchr (mybuf,':')) == NULL)
    {
       *protocol = NULL;
       *host = NULL;
       *port = NULL;
       free (tmpptr);
       return 0;
    }

    *mybuf ++= '\0';

    if (strlen(_host) == 0)
    {
       TRANS(GetHostname) (hostnamebuf, sizeof (hostnamebuf));
       _host = hostnamebuf;
    }

    /* Check for DECnet */

    if (*mybuf == ':')
    {
       _protocol = "dnet";
       mybuf++;
    }

    /* Get the port */

/*
get_port:
*/

    _port = mybuf;

#if defined(FONT_t) || defined(FS_t)
    /*
     * Is there an optional catalogue list?
     */

    if ((mybuf = strchr (mybuf,'/')) != NULL)
       *mybuf ++= '\0';

    /*
     * The rest, if any, is the (currently unused) catalogue list.
     *
     * _catalogue = mybuf;
     */
#endif

    /*
     * Now that we have all of the components, allocate new
     * string space for them.
     */

    if ((*protocol = (char *) malloc(strlen (_protocol) + 1)) == NULL)
    {
       /* Malloc failed */
       *port = NULL;
       *host = NULL;
       *protocol = NULL;
       free (tmpptr);
       return 0;
    }
    else
        strcpy (*protocol, _protocol);

    if ((*host = (char *) malloc (strlen (_host) + 1)) == NULL)
    {
       /* Malloc failed */
       *port = NULL;
       *host = NULL;
       free (*protocol);
       *protocol = NULL;
       free (tmpptr);
       return 0;
       }
    else
        strcpy (*host, _host);

    if ((*port = (char *) malloc (strlen (_port) + 1)) == NULL)
    {
       /* Malloc failed */
       *port = NULL;
       free (*host);
       *host = NULL;
       free (*protocol);
       *protocol = NULL;
       free (tmpptr);
       return 0;
    }
    else
        strcpy (*port, _port);

    free (tmpptr);

    return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int TRANS() Read ( XtransConnInfo  ciptr,
char *  buf,
int  size 
)

Definition at line 858 of file Xtrans.c.

{
    return ciptr->transptr->Read (ciptr, buf, size);
}
int TRANS() Readv ( XtransConnInfo  ciptr,
struct iovec *  buf,
int  size 
)

Definition at line 880 of file Xtrans.c.

{
    return ciptr->transptr->Readv (ciptr, buf, size);
}
static Xtransport* TRANS() SelectTransport ( char *  protocol) [static]

Definition at line 154 of file Xtrans.c.

{
    char      protobuf[PROTOBUFSIZE];
    int              i;

    PRMSG (3,"TRANS(SelectTransport) (%s)\n", protocol, 0, 0);

    /*
     * Force Protocol to be lowercase as a way of doing
     * a case insensitive match.
     */

    strncpy (protobuf, protocol, PROTOBUFSIZE);

    for (i = 0; i < PROTOBUFSIZE && protobuf[i] != '\0'; i++)
       if (isupper (protobuf[i]))
           protobuf[i] = tolower (protobuf[i]);

    /* Look at all of the configured protocols */

    for (i = 0; i < NUMTRANS; i++)
    {
       if (!strcmp (protobuf, Xtransports[i].transport->TransName))
           return Xtransports[i].transport;
    }

    return NULL;
}

Here is the caller graph for this function:

int TRANS() SetOption ( XtransConnInfo  ciptr,
int  option,
int  arg 
)

Definition at line 679 of file Xtrans.c.

{
    int       fd = ciptr->fd;
    int       ret = 0;

    PRMSG (2,"TRANS(SetOption) (%d,%d,%d)\n", fd, option, arg);

    /*
     * For now, all transport type use the same stuff for setting options.
     * As long as this is true, we can put the common code here. Once a more
     * complicated transport such as shared memory or an OSI implementation
     * that uses the session and application libraries is implemented, this
     * code may have to move to a transport dependent function.
     *
     * ret = ciptr->transptr->SetOption (ciptr, option, arg);
     */

    switch (option)
    {
    case TRANS_NONBLOCKING:
       switch (arg)
       {
       case 0:
           /* Set to blocking mode */
           break;
       case 1: /* Set to non-blocking mode */
#if defined(O_NONBLOCK) && (!defined(ultrix) && !defined(hpux) && !defined(AIXV3) && !defined(uniosu))
           ret = fcntl (fd, F_SETFL, O_NONBLOCK);
#else
#ifdef FIOSNBIO
       {
           int arg;
           arg = 1;
           ret = ioctl (fd, FIOSNBIO, &arg);
       }
#else
#if (defined(AIXV3) || defined(uniosu) || defined(WIN32)) && defined(FIONBIO)
       {
           int arg;
           arg = 1;
           ret = ioctl (fd, FIONBIO, &arg);
       }
#else
#ifdef FNDELAY
           ret = fcntl (fd, F_SETFL, FNDELAY);
#else
           ret = fcntl (fd, F_SETFL, O_NDELAY);
#endif
#endif /* AIXV3  || uniosu */
#endif /* FIOSNBIO */
#endif /* O_NONBLOCK */
           break;
       default:
           /* Unknown option */
           break;
       }
       break;
    case TRANS_CLOSEONEXEC:
#ifdef F_SETFD
#ifdef FD_CLOEXEC
       ret = fcntl (fd, F_SETFD, FD_CLOEXEC);
#else
       ret = fcntl (fd, F_SETFD, 1);
#endif /* FD_CLOEXEC */
#endif /* F_SETFD */
       break;
    }
    
    return ret;
}
int TRANS() Write ( XtransConnInfo  ciptr,
char *  buf,
int  size 
)

Definition at line 869 of file Xtrans.c.

{
    return ciptr->transptr->Write (ciptr, buf, size);
}
int TRANS() Writev ( XtransConnInfo  ciptr,
struct iovec *  buf,
int  size 
)

Definition at line 890 of file Xtrans.c.

{
    return ciptr->transptr->Writev (ciptr, buf, size);
}

Variable Documentation

Initial value:
 {




 



 


 





 






 


 
}

Definition at line 86 of file Xtrans.c.