2006-11-25 11:24:24 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 1993, 1994, 1998 The Open Group
|
|
|
|
|
|
|
|
Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
the above copyright notice appear in all copies and that both that
|
|
|
|
copyright notice and this permission notice appear in supporting
|
|
|
|
documentation.
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included
|
|
|
|
in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
Except as contained in this notice, the name of The Open Group shall
|
|
|
|
not be used in advertising or otherwise to promote the sale, use or
|
|
|
|
other dealings in this Software without prior written authorization
|
|
|
|
from The Open Group.
|
|
|
|
|
2008-05-24 09:44:21 -06:00
|
|
|
* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
|
2006-11-25 11:24:24 -07:00
|
|
|
*
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software and its
|
|
|
|
* documentation for any purpose and without fee is hereby granted, provided
|
|
|
|
* that the above copyright notice appear in all copies and that both that
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
* documentation, and that the name NCR not be used in advertising
|
|
|
|
* or publicity pertaining to distribution of the software without specific,
|
|
|
|
* written prior permission. NCR makes no representations about the
|
|
|
|
* suitability of this software for any purpose. It is provided "as is"
|
|
|
|
* without express or implied warranty.
|
|
|
|
*
|
|
|
|
* NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
|
|
|
|
* NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
|
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <stropts.h>
|
|
|
|
#include <poll.h>
|
|
|
|
#include <tiuser.h>
|
|
|
|
|
|
|
|
#include <netdir.h>
|
|
|
|
#include <netconfig.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the TLI implementation of the X Transport service layer
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct _TLItrans2dev {
|
|
|
|
char *transname;
|
|
|
|
char *protofamily;
|
|
|
|
char *devcotsname;
|
|
|
|
char *devcltsname;
|
|
|
|
int family;
|
|
|
|
} TLItrans2dev;
|
|
|
|
|
|
|
|
static TLItrans2dev TLItrans2devtab[] = {
|
|
|
|
{"inet","inet","/dev/tcp","/dev/udp",AF_INET},
|
|
|
|
{"tcp","inet","/dev/tcp","/dev/udp",AF_INET},
|
|
|
|
{"tli","loopback","/dev/ticots","/dev/ticlts",AF_UNIX},
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NUMTLIFAMILIES (sizeof(TLItrans2devtab)/sizeof(TLItrans2dev))
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
/*
|
|
|
|
* The local TLI connection, is a form of a local connection, so use a
|
|
|
|
* sockaddr_un for the address so that it will be treated just like the other
|
|
|
|
* local transports such as UNIX domain sockets, pts, and named.
|
|
|
|
*/
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
#if defined(X11_t)
|
|
|
|
#define TLINODENAME "TLI:xserver"
|
|
|
|
#endif
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
#if defined(XIM_t)
|
|
|
|
#define TLINODENAME "TLI:xim"
|
|
|
|
#endif
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
#if defined(FS_t) || defined(FONT_t)
|
|
|
|
#define TLINODENAME "TLI:fontserver"
|
|
|
|
#endif
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
#if defined(ICE_t)
|
|
|
|
#define TLINODENAME "TLI:ICE"
|
|
|
|
#endif
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
#if defined(TEST_t)
|
|
|
|
#define TLINODENAME "TLI:test"
|
|
|
|
#endif
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
#ifndef PORTBUFSIZE
|
|
|
|
#ifdef TRANS_SERVER
|
|
|
|
#define PORTBUFSIZE 64
|
|
|
|
#else
|
|
|
|
#ifdef TRANS_CLIENT
|
|
|
|
#define PORTBUFSIZE 64
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These are some utility function used by the real interface function below.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLISelectFamily)(char *family)
|
|
|
|
|
|
|
|
{
|
|
|
|
int i;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(3,"TLISelectFamily(%s)\n", family);
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
for(i=0;i<NUMTLIFAMILIES;i++)
|
|
|
|
{
|
|
|
|
if( !strcmp(family,TLItrans2devtab[i].transname) )
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function gets the local address of the transport and stores it in the
|
|
|
|
* XtransConnInfo structure for the connection.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLIGetAddr)(XtransConnInfo ciptr)
|
|
|
|
|
|
|
|
{
|
|
|
|
Xtransaddr sockname;
|
|
|
|
struct netbuf netbuf;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(3,"TLIGetAddr(%x)\n", ciptr);
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
netbuf.buf=(char *)&sockname;
|
|
|
|
netbuf.len=sizeof(sockname);
|
|
|
|
netbuf.maxlen=sizeof(sockname);
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( t_getname(ciptr->fd,&netbuf,LOCALNAME) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,"TLIGetAddr: t_getname(LOCALNAME) failed: %d\n",
|
|
|
|
errno);
|
2006-11-25 11:24:24 -07:00
|
|
|
return -1;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(4,"TLIGetAddr: got family %d len %d\n",
|
|
|
|
((struct sockaddr *) &sockname)->sa_family ,netbuf.len);
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
/*
|
|
|
|
* Everything looks good: fill in the XtransConnInfo structure.
|
|
|
|
*/
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( ciptr->addr )
|
2012-04-08 08:50:52 -06:00
|
|
|
free(ciptr->addr);
|
|
|
|
|
|
|
|
if( (ciptr->addr = malloc(netbuf.len)) == NULL )
|
2006-11-25 11:24:24 -07:00
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLIGetAddr: Can't allocate space for the addr\n");
|
2006-11-25 11:24:24 -07:00
|
|
|
return -1;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
ciptr->family=((struct sockaddr *) &sockname)->sa_family;
|
|
|
|
ciptr->addrlen=netbuf.len;
|
|
|
|
memcpy(ciptr->addr,&sockname,ciptr->addrlen);
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function gets the remote address of the socket and stores it in the
|
|
|
|
* XtransConnInfo structure for the connection.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLIGetPeerAddr)(XtransConnInfo ciptr)
|
|
|
|
|
|
|
|
{
|
|
|
|
Xtransaddr sockname;
|
|
|
|
struct netbuf netbuf;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(3,"TLIGetPeerAddr(%x)\n", ciptr);
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
netbuf.buf=(char *)&sockname;
|
|
|
|
netbuf.len=sizeof(sockname);
|
|
|
|
netbuf.maxlen=sizeof(sockname);
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( t_getname(ciptr->fd,&netbuf,REMOTENAME) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,"TLIGetPeerAddr: t_getname(REMOTENAME) failed: %d\n",
|
|
|
|
errno);
|
2006-11-25 11:24:24 -07:00
|
|
|
return -1;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(4,"TLIGetPeerAddr: got family %d len %d\n",
|
|
|
|
((struct sockaddr *) &sockname)->sa_family ,netbuf.len);
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
/*
|
|
|
|
* Everything looks good: fill in the XtransConnInfo structure.
|
|
|
|
*/
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( ciptr->peeraddr )
|
2012-04-08 08:50:52 -06:00
|
|
|
free(ciptr->peeraddr);
|
|
|
|
|
|
|
|
if( (ciptr->peeraddr = malloc(netbuf.len)) == NULL )
|
2006-11-25 11:24:24 -07:00
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
|
|
|
"TLIGetPeerAddr: Can't allocate space for the addr\n");
|
2006-11-25 11:24:24 -07:00
|
|
|
return -1;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
ciptr->peeraddrlen=netbuf.len;
|
|
|
|
memcpy(ciptr->peeraddr,&sockname,ciptr->peeraddrlen);
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function will establish a local name for the transport. This function
|
|
|
|
* do extra work for the local tli connection. It must create a sockaddr_un
|
|
|
|
* format address so that it will look like an AF_UNIX connection to the
|
|
|
|
* higher layer.
|
|
|
|
*
|
|
|
|
* This function will only be called by the OPENC?TSClient() functions since
|
|
|
|
* the local address is set up in the CreateListner() for the server ends.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLITLIBindLocal)(int fd, int family, char *port)
|
|
|
|
|
|
|
|
{
|
|
|
|
struct sockaddr_un *sunaddr=NULL;
|
|
|
|
struct t_bind *req=NULL;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(2, "TLITLIBindLocal(%d,%d,%s)\n", fd, family, port);
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( family == AF_UNIX )
|
|
|
|
{
|
|
|
|
if( (req=(struct t_bind *)t_alloc(fd,T_BIND,0)) == NULL )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
|
|
|
"TLITLIBindLocal() failed to allocate a t_bind\n");
|
2006-11-25 11:24:24 -07:00
|
|
|
return -1;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (sunaddr=(struct sockaddr_un *)
|
|
|
|
malloc(sizeof(struct sockaddr_un))) == NULL )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
|
|
|
"TLITLIBindLocal: failed to allocate a sockaddr_un\n");
|
2006-11-25 11:24:24 -07:00
|
|
|
t_free((char *)req,T_BIND);
|
|
|
|
return -1;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
sunaddr->sun_family=AF_UNIX;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
#ifdef nuke
|
|
|
|
if( *port == '/' ) { /* A full pathname */
|
|
|
|
(void) strcpy(sunaddr->sun_path, port);
|
|
|
|
} else {
|
|
|
|
(void) sprintf(sunaddr->sun_path,"%s%s", TLINODENAME, port );
|
|
|
|
}
|
|
|
|
#endif /*NUKE*/
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
(void) sprintf(sunaddr->sun_path,"%s%d",
|
|
|
|
TLINODENAME, getpid()^time(NULL) );
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(4, "TLITLIBindLocal: binding to %s\n",
|
|
|
|
sunaddr->sun_path);
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
req->addr.buf=(char *)sunaddr;
|
|
|
|
req->addr.len=sizeof(*sunaddr);
|
|
|
|
req->addr.maxlen=sizeof(*sunaddr);
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( t_bind(fd, req, NULL) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIBindLocal: Unable to bind TLI device to %s\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
port);
|
2006-11-25 11:24:24 -07:00
|
|
|
if (sunaddr)
|
|
|
|
free((char *) sunaddr);
|
|
|
|
if (req)
|
|
|
|
t_free((char *)req,T_BIND);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static XtransConnInfo
|
|
|
|
TRANS(TLIOpen)(char *device)
|
|
|
|
|
|
|
|
{
|
|
|
|
XtransConnInfo ciptr;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(3,"TLIOpen(%s)\n", device);
|
|
|
|
|
|
|
|
if( (ciptr = calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
|
2006-11-25 11:24:24 -07:00
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLIOpen: calloc failed\n");
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (ciptr->fd=t_open( device, O_RDWR, NULL )) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLIOpen: t_open failed for %s\n", device);
|
2006-11-25 11:24:24 -07:00
|
|
|
free(ciptr);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return ciptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TRANS_REOPEN
|
|
|
|
|
|
|
|
static XtransConnInfo
|
|
|
|
TRANS(TLIReopen)(char *device, int fd, char *port)
|
|
|
|
|
|
|
|
{
|
|
|
|
XtransConnInfo ciptr;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(3,"TLIReopen(%s,%d, %s)\n", device, fd, port );
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if (t_sync (fd) < 0)
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLIReopen: t_sync failed\n");
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-04-08 08:50:52 -06:00
|
|
|
if( (ciptr = calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
|
2006-11-25 11:24:24 -07:00
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLIReopen: calloc failed\n");
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
ciptr->fd = fd;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return ciptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* TRANS_REOPEN */
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2012-04-08 08:50:52 -06:00
|
|
|
TRANS(TLIAddrToNetbuf)(int tlifamily, char *host, char *port,
|
2006-11-25 11:24:24 -07:00
|
|
|
struct netbuf *netbufp)
|
|
|
|
|
|
|
|
{
|
|
|
|
struct netconfig *netconfigp;
|
|
|
|
struct nd_hostserv nd_hostserv;
|
|
|
|
struct nd_addrlist *nd_addrlistp = NULL;
|
|
|
|
void *handlep;
|
|
|
|
long lport;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(3,"TLIAddrToNetbuf(%d,%s,%s)\n", tlifamily, host, port );
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (handlep=setnetconfig()) == NULL )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
lport = strtol (port, (char**)NULL, 10);
|
|
|
|
if (lport < 1024 || lport > USHRT_MAX)
|
|
|
|
return -1;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
nd_hostserv.h_host = host;
|
|
|
|
if( port && *port ) {
|
|
|
|
nd_hostserv.h_serv = port;
|
|
|
|
} else {
|
|
|
|
nd_hostserv.h_serv = NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
while( (netconfigp=getnetconfig(handlep)) != NULL )
|
|
|
|
{
|
|
|
|
if( strcmp(netconfigp->nc_protofmly,
|
|
|
|
TLItrans2devtab[tlifamily].protofamily) != 0 )
|
|
|
|
continue;
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(5,"TLIAddrToNetbuf: Trying to resolve %s.%s for %s\n",
|
2006-11-25 11:24:24 -07:00
|
|
|
host, port, TLItrans2devtab[tlifamily].protofamily );
|
|
|
|
if( netdir_getbyname(netconfigp,&nd_hostserv, &nd_addrlistp) == 0 )
|
|
|
|
{
|
|
|
|
/* we have at least one address to use */
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(5, "TLIAddrToNetbuf: found address for %s.%s\n", host, port);
|
|
|
|
prmsg(5, "TLIAddrToNetbuf: %s\n",taddr2uaddr(netconfigp,nd_addrlistp->n_addrs));
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
memcpy(netbufp->buf,nd_addrlistp->n_addrs->buf,
|
|
|
|
nd_addrlistp->n_addrs->len);
|
|
|
|
netbufp->len=nd_addrlistp->n_addrs->len;
|
|
|
|
endnetconfig(handlep);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
endnetconfig(handlep);
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These functions are the interface supplied in the Xtransport structure
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef TRANS_CLIENT
|
|
|
|
|
|
|
|
static XtransConnInfo
|
2012-04-08 08:50:52 -06:00
|
|
|
TRANS(TLIOpenCOTSClient)(Xtransport *thistrans, char *protocol,
|
2006-11-25 11:24:24 -07:00
|
|
|
char *host, char *port)
|
|
|
|
|
|
|
|
{
|
|
|
|
XtransConnInfo ciptr;
|
|
|
|
int i;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(2,"TLIOpenCOTSClient(%s,%s,%s)\n", protocol, host, port );
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,"TLIOpenCOTSClient: Unable to determine device for %s\n",
|
|
|
|
thistrans->TransName);
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (ciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcotsname)) == NULL )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,"TLIOpenCOTSClient: Unable to open device for %s\n",
|
|
|
|
thistrans->TransName);
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( TRANS(TLITLIBindLocal)(ciptr->fd,TLItrans2devtab[i].family,port) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIOpenCOTSClient: ...TLITLIBindLocal() failed: %d\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
errno);
|
2006-11-25 11:24:24 -07:00
|
|
|
t_close(ciptr->fd);
|
2012-04-08 08:50:52 -06:00
|
|
|
free(ciptr);
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( TRANS(TLIGetAddr)(ciptr) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIOpenCOTSClient: ...TLIGetAddr() failed: %d\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
errno);
|
2006-11-25 11:24:24 -07:00
|
|
|
t_close(ciptr->fd);
|
2012-04-08 08:50:52 -06:00
|
|
|
free(ciptr);
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
/* Save the TLIFamily for later use in TLIAddrToNetbuf() lookups */
|
|
|
|
ciptr->index = i;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return ciptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* TRANS_CLIENT */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TRANS_SERVER
|
|
|
|
|
|
|
|
static XtransConnInfo
|
2012-04-08 08:50:52 -06:00
|
|
|
TRANS(TLIOpenCOTSServer)(Xtransport *thistrans, char *protocol,
|
2006-11-25 11:24:24 -07:00
|
|
|
char *host, char *port)
|
|
|
|
|
|
|
|
{
|
|
|
|
XtransConnInfo ciptr;
|
|
|
|
int i;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(2,"TLIOpenCOTSServer(%s,%s,%s)\n", protocol, host, port );
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIOpenCOTSServer: Unable to determine device for %s\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
thistrans->TransName);
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (ciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcotsname)) == NULL )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIOpenCOTSServer: Unable to open device for %s\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
thistrans->TransName);
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
/* Set the family type */
|
|
|
|
|
|
|
|
ciptr->family = TLItrans2devtab[i].family;
|
|
|
|
|
|
|
|
|
|
|
|
/* Save the TLIFamily for later use in TLIAddrToNetbuf() lookups */
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
ciptr->index = i;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return ciptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* TRANS_SERVER */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TRANS_CLIENT
|
|
|
|
|
|
|
|
static XtransConnInfo
|
2012-04-08 08:50:52 -06:00
|
|
|
TRANS(TLIOpenCLTSClient)(Xtransport *thistrans, char *protocol,
|
2006-11-25 11:24:24 -07:00
|
|
|
char *host, char *port)
|
|
|
|
|
|
|
|
{
|
|
|
|
XtransConnInfo ciptr;
|
|
|
|
int i;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(2,"TLIOpenCLTSClient(%s,%s,%s)\n", protocol, host, port );
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIOpenCLTSClient: Unable to determine device for %s\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
thistrans->TransName);
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (ciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcltsname)) == NULL )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIOpenCLTSClient: Unable to open device for %s\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
thistrans->TransName);
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( TRANS(TLITLIBindLocal)(ciptr->fd,TLItrans2devtab[i].family,port) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIOpenCLTSClient: ...TLITLIBindLocal() failed: %d\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
errno);
|
2006-11-25 11:24:24 -07:00
|
|
|
t_close(ciptr->fd);
|
2012-04-08 08:50:52 -06:00
|
|
|
free(ciptr);
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( TRANS(TLIGetAddr)(ciptr) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIOpenCLTSClient: ...TLIGetPeerAddr() failed: %d\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
errno);
|
2006-11-25 11:24:24 -07:00
|
|
|
t_close(ciptr->fd);
|
2012-04-08 08:50:52 -06:00
|
|
|
free(ciptr);
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return ciptr;
|
2012-04-08 08:50:52 -06:00
|
|
|
}
|
2006-11-25 11:24:24 -07:00
|
|
|
|
|
|
|
#endif /* TRANS_CLIENT */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TRANS_SERVER
|
|
|
|
|
|
|
|
static XtransConnInfo
|
2012-04-08 08:50:52 -06:00
|
|
|
TRANS(TLIOpenCLTSServer)(Xtransport *thistrans, char *protocol,
|
2006-11-25 11:24:24 -07:00
|
|
|
char *host, char *port)
|
|
|
|
|
|
|
|
{
|
|
|
|
XtransConnInfo ciptr;
|
|
|
|
int i;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(2,"TLIOpenCLTSServer(%s,%s,%s)\n", protocol, host, port );
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIOpenCLTSServer: Unable to determine device for %s\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
thistrans->TransName);
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (ciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcltsname)) == NULL )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIOpenCLTSServer: Unable to open device for %s\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
thistrans->TransName);
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return ciptr;
|
2012-04-08 08:50:52 -06:00
|
|
|
}
|
2006-11-25 11:24:24 -07:00
|
|
|
|
|
|
|
#endif /* TRANS_SERVER */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TRANS_REOPEN
|
|
|
|
|
|
|
|
static XtransConnInfo
|
|
|
|
TRANS(TLIReopenCOTSServer)(Xtransport *thistrans, int fd, char *port)
|
|
|
|
|
|
|
|
{
|
|
|
|
XtransConnInfo ciptr;
|
|
|
|
int i;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(2,"TLIReopenCOTSServer(%d, %s)\n", fd, port);
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIReopenCOTSServer: Unable to determine device for %s\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
thistrans->TransName);
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (ciptr=TRANS(TLIReopen)(
|
|
|
|
TLItrans2devtab[i].devcotsname, fd, port)) == NULL )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIReopenCOTSServer: Unable to open device for %s\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
thistrans->TransName);
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
/* Save the TLIFamily for later use in TLIAddrToNetbuf() lookups */
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
ciptr->index = i;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return ciptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static XtransConnInfo
|
|
|
|
TRANS(TLIReopenCLTSServer)(Xtransport *thistrans, int fd, char *port)
|
|
|
|
|
|
|
|
{
|
|
|
|
XtransConnInfo ciptr;
|
|
|
|
int i;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(2,"TLIReopenCLTSServer(%d, %s)\n", fd, port);
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIReopenCLTSServer: Unable to determine device for %s\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
thistrans->TransName);
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (ciptr=TRANS(TLIReopen)(
|
|
|
|
TLItrans2devtab[i].devcltsname, fd, port)) == NULL )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIReopenCLTSServer: Unable to open device for %s\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
thistrans->TransName);
|
2006-11-25 11:24:24 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
ciptr->index = i;
|
|
|
|
|
|
|
|
return ciptr;
|
2012-04-08 08:50:52 -06:00
|
|
|
}
|
2006-11-25 11:24:24 -07:00
|
|
|
|
|
|
|
#endif /* TRANS_REOPEN */
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLISetOption)(XtransConnInfo ciptr, int option, int arg)
|
|
|
|
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(2,"TLISetOption(%d,%d,%d)\n", ciptr->fd, option, arg );
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TRANS_SERVER
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLICreateListener)(XtransConnInfo ciptr, struct t_bind *req)
|
|
|
|
|
|
|
|
{
|
|
|
|
struct t_bind *ret;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(2,"TLICreateListener(%x->%d,%x)\n", ciptr, ciptr->fd, req );
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (ret=(struct t_bind *)t_alloc(ciptr->fd,T_BIND,T_ALL)) == NULL )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLICreateListener: failed to allocate a t_bind\n");
|
2006-11-25 11:24:24 -07:00
|
|
|
t_free((char *)req,T_BIND);
|
|
|
|
return TRANS_CREATE_LISTENER_FAILED;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( t_bind(ciptr->fd, req, ret) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLICreateListener: t_bind failed\n");
|
2006-11-25 11:24:24 -07:00
|
|
|
t_free((char *)req,T_BIND);
|
|
|
|
t_free((char *)ret,T_BIND);
|
|
|
|
return TRANS_CREATE_LISTENER_FAILED;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( memcmp(req->addr.buf,ret->addr.buf,req->addr.len) != 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLICreateListener: unable to bind to %x\n",
|
|
|
|
req);
|
2006-11-25 11:24:24 -07:00
|
|
|
t_free((char *)req,T_BIND);
|
|
|
|
t_free((char *)ret,T_BIND);
|
|
|
|
return TRANS_ADDR_IN_USE;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
/*
|
|
|
|
* Everything looks good: fill in the XtransConnInfo structure.
|
|
|
|
*/
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
if( (ciptr->addr = malloc(ret->addr.len)) == NULL )
|
2006-11-25 11:24:24 -07:00
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
|
|
|
"TLICreateListener: Unable to allocate space for the address\n");
|
2006-11-25 11:24:24 -07:00
|
|
|
t_free((char *)req,T_BIND);
|
|
|
|
t_free((char *)ret, T_BIND);
|
|
|
|
return TRANS_CREATE_LISTENER_FAILED;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
ciptr->addrlen=ret->addr.len;
|
|
|
|
memcpy(ciptr->addr,ret->addr.buf,ret->addr.len);
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
t_free((char *)req,T_BIND);
|
|
|
|
t_free((char *)ret, T_BIND);
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLIINETCreateListener)(XtransConnInfo ciptr, char *port, unsigned int flags)
|
|
|
|
|
|
|
|
{
|
|
|
|
char portbuf[PORTBUFSIZE];
|
|
|
|
struct t_bind *req;
|
|
|
|
struct sockaddr_in *sinaddr;
|
|
|
|
long tmpport;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(2,"TLIINETCreateListener(%x->%d,%s)\n", ciptr,
|
2006-11-25 11:24:24 -07:00
|
|
|
ciptr->fd, port ? port : "NULL" );
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
#ifdef X11_t
|
|
|
|
/*
|
|
|
|
* X has a well known port, that is transport dependent. It is easier
|
|
|
|
* to handle it here, than try and come up with a transport independent
|
|
|
|
* representation that can be passed in and resolved the usual way.
|
|
|
|
*
|
|
|
|
* The port that is passed here is really a string containing the idisplay
|
|
|
|
* from ConnectDisplay().
|
|
|
|
*/
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if (is_numeric (port))
|
|
|
|
{
|
|
|
|
tmpport = X_TCP_PORT + strtol (port, (char**)NULL, 10);
|
|
|
|
sprintf(portbuf,"%u", tmpport);
|
|
|
|
port = portbuf;
|
|
|
|
}
|
|
|
|
#endif
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (req=(struct t_bind *)t_alloc(ciptr->fd,T_BIND,T_ALL)) == NULL )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
|
|
|
"TLIINETCreateListener: failed to allocate a t_bind\n");
|
2006-11-25 11:24:24 -07:00
|
|
|
return TRANS_CREATE_LISTENER_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( port && *port ) {
|
|
|
|
if(TRANS(TLIAddrToNetbuf)(ciptr->index,HOST_SELF,port,&(req->addr)) < 0)
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIINETCreateListener: can't resolve name:HOST_SELF.%s\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
port);
|
2006-11-25 11:24:24 -07:00
|
|
|
t_free((char *)req,T_BIND);
|
|
|
|
return TRANS_CREATE_LISTENER_FAILED;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sinaddr=(struct sockaddr_in *) req->addr.buf;
|
|
|
|
sinaddr->sin_family=AF_INET;
|
|
|
|
sinaddr->sin_port=htons(0);
|
|
|
|
sinaddr->sin_addr.s_addr=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the qlen */
|
|
|
|
|
|
|
|
req->qlen=1;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return TRANS(TLICreateListener)(ciptr, req);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLITLICreateListener)(XtransConnInfo ciptr, char *port, unsigned int flags)
|
|
|
|
|
|
|
|
{
|
|
|
|
struct t_bind *req;
|
|
|
|
struct sockaddr_un *sunaddr;
|
|
|
|
int ret_value;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(2,"TLITLICreateListener(%x->%d,%s)\n", ciptr, ciptr->fd,
|
2006-11-25 11:24:24 -07:00
|
|
|
port ? port : "NULL");
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (req=(struct t_bind *)t_alloc(ciptr->fd,T_BIND,0)) == NULL )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
|
|
|
"TLITLICreateListener: failed to allocate a t_bind\n");
|
2006-11-25 11:24:24 -07:00
|
|
|
return TRANS_CREATE_LISTENER_FAILED;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (sunaddr=(struct sockaddr_un *)
|
|
|
|
malloc(sizeof(struct sockaddr_un))) == NULL )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
|
|
|
"TLITLICreateListener: failed to allocate a sockaddr_un\n");
|
2006-11-25 11:24:24 -07:00
|
|
|
t_free((char *)req,T_BIND);
|
|
|
|
return TRANS_CREATE_LISTENER_FAILED;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
sunaddr->sun_family=AF_UNIX;
|
|
|
|
if( port && *port ) {
|
|
|
|
if( *port == '/' ) { /* A full pathname */
|
|
|
|
(void) strcpy(sunaddr->sun_path, port);
|
|
|
|
} else {
|
|
|
|
(void) sprintf(sunaddr->sun_path,"%s%s", TLINODENAME, port );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
(void) sprintf(sunaddr->sun_path,"%s%d", TLINODENAME, getpid());
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
req->addr.buf=(char *)sunaddr;
|
|
|
|
req->addr.len=sizeof(*sunaddr);
|
|
|
|
req->addr.maxlen=sizeof(*sunaddr);
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
/* Set the qlen */
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
req->qlen=1;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
ret_value = TRANS(TLICreateListener)(ciptr, req);
|
|
|
|
|
|
|
|
free((char *) sunaddr);
|
|
|
|
|
|
|
|
return ret_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static XtransConnInfo
|
|
|
|
TRANS(TLIAccept)(XtransConnInfo ciptr, int *status)
|
|
|
|
|
|
|
|
{
|
|
|
|
struct t_call *call;
|
|
|
|
XtransConnInfo newciptr;
|
|
|
|
int i;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(2,"TLIAccept(%x->%d)\n", ciptr, ciptr->fd);
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (call=(struct t_call *)t_alloc(ciptr->fd,T_CALL,T_ALL)) == NULL )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLIAccept() failed to allocate a t_call\n");
|
2006-11-25 11:24:24 -07:00
|
|
|
*status = TRANS_ACCEPT_BAD_MALLOC;
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( t_listen(ciptr->fd,call) < 0 )
|
|
|
|
{
|
|
|
|
extern char *t_errlist[];
|
|
|
|
extern int t_errno;
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLIAccept() t_listen() failed\n");
|
|
|
|
prmsg(1, "TLIAccept: %s\n", t_errlist[t_errno]);
|
2006-11-25 11:24:24 -07:00
|
|
|
t_free((char *)call,T_CALL);
|
|
|
|
*status = TRANS_ACCEPT_MISC_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
/*
|
|
|
|
* Now we need to set up the new endpoint for the incoming connection.
|
|
|
|
*/
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
i=ciptr->index; /* Makes the next line more readable */
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (newciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcotsname)) == NULL )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLIAccept() failed to open a new endpoint\n");
|
2006-11-25 11:24:24 -07:00
|
|
|
t_free((char *)call,T_CALL);
|
|
|
|
*status = TRANS_ACCEPT_MISC_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( TRANS(TLITLIBindLocal)(newciptr->fd,TLItrans2devtab[i].family,"") < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIAccept: TRANS(TLITLIBindLocal)() failed: %d\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
errno);
|
2006-11-25 11:24:24 -07:00
|
|
|
t_free((char *)call,T_CALL);
|
|
|
|
t_close(newciptr->fd);
|
2012-04-08 08:50:52 -06:00
|
|
|
free(newciptr);
|
2006-11-25 11:24:24 -07:00
|
|
|
*status = TRANS_ACCEPT_MISC_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( t_accept(ciptr->fd,newciptr->fd,call) < 0 )
|
|
|
|
{
|
|
|
|
extern char *t_errlist[];
|
|
|
|
extern int t_errno;
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLIAccept() t_accept() failed\n");
|
|
|
|
prmsg(1, "TLIAccept: %s\n", t_errlist[t_errno]);
|
2006-11-25 11:24:24 -07:00
|
|
|
if( t_errno == TLOOK )
|
|
|
|
{
|
|
|
|
int evtype = t_look(ciptr->fd);
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLIAccept() t_look() returned %d\n", evtype);
|
2006-11-25 11:24:24 -07:00
|
|
|
switch( evtype )
|
|
|
|
{
|
|
|
|
case T_DISCONNECT:
|
|
|
|
if( t_rcvdis(ciptr->fd, NULL) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLIAccept() t_rcvdis() failed\n");
|
|
|
|
prmsg(1, "TLIAccept: %s\n", t_errlist[t_errno]);
|
2006-11-25 11:24:24 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t_free((char *)call,T_CALL);
|
|
|
|
t_close(newciptr->fd);
|
|
|
|
free(newciptr);
|
|
|
|
*status = TRANS_ACCEPT_FAILED;
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
t_free((char *)call,T_CALL);
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( TRANS(TLIGetAddr)(newciptr) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIAccept: TRANS(TLIGetPeerAddr)() failed: %d\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
errno);
|
2006-11-25 11:24:24 -07:00
|
|
|
t_close(newciptr->fd);
|
2012-04-08 08:50:52 -06:00
|
|
|
free(newciptr);
|
2006-11-25 11:24:24 -07:00
|
|
|
*status = TRANS_ACCEPT_MISC_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( TRANS(TLIGetPeerAddr)(newciptr) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIAccept: TRANS(TLIGetPeerAddr)() failed: %d\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
errno);
|
2006-11-25 11:24:24 -07:00
|
|
|
t_close(newciptr->fd);
|
2012-04-08 08:50:52 -06:00
|
|
|
free(newciptr->addr);
|
|
|
|
free(newciptr);
|
2006-11-25 11:24:24 -07:00
|
|
|
*status = TRANS_ACCEPT_MISC_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( ioctl(newciptr->fd, I_POP,"timod") < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLIAccept() ioctl(I_POP, \"timod\") failed %d\n",
|
|
|
|
errno);
|
2006-11-25 11:24:24 -07:00
|
|
|
t_close(newciptr->fd);
|
2012-04-08 08:50:52 -06:00
|
|
|
free(newciptr->addr);
|
|
|
|
free(newciptr);
|
2006-11-25 11:24:24 -07:00
|
|
|
*status = TRANS_ACCEPT_MISC_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( ioctl(newciptr->fd, I_PUSH,"tirdwr") < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLIAccept() ioctl(I_PUSH,\"tirdwr\") failed %d\n",
|
|
|
|
errno);
|
2006-11-25 11:24:24 -07:00
|
|
|
t_close(newciptr->fd);
|
2012-04-08 08:50:52 -06:00
|
|
|
free(newciptr->addr);
|
|
|
|
free(newciptr);
|
2006-11-25 11:24:24 -07:00
|
|
|
*status = TRANS_ACCEPT_MISC_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
*status = 0;
|
|
|
|
|
|
|
|
return newciptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* TRANS_SERVER */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TRANS_CLIENT
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLIConnect)(XtransConnInfo ciptr, struct t_call *sndcall )
|
|
|
|
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(2, "TLIConnect(%x->%d,%x)\n", ciptr, ciptr->fd, sndcall);
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( t_connect(ciptr->fd,sndcall,NULL) < 0 )
|
|
|
|
{
|
|
|
|
extern char *t_errlist[];
|
|
|
|
extern int t_errno;
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLIConnect() t_connect() failed\n");
|
|
|
|
prmsg(1, "TLIConnect: %s\n", t_errlist[t_errno]);
|
2006-11-25 11:24:24 -07:00
|
|
|
t_free((char *)sndcall,T_CALL);
|
|
|
|
if (t_errno == TLOOK && t_look(ciptr->fd) == T_DISCONNECT)
|
|
|
|
{
|
|
|
|
t_rcvdis(ciptr->fd,NULL);
|
|
|
|
return TRANS_TRY_CONNECT_AGAIN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return TRANS_CONNECT_FAILED;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
t_free((char *)sndcall,T_CALL);
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
/*
|
|
|
|
* Sync up the address fields of ciptr.
|
|
|
|
*/
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( TRANS(TLIGetAddr)(ciptr) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIConnect: ...TLIGetAddr() failed: %d\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
errno);
|
2006-11-25 11:24:24 -07:00
|
|
|
return TRANS_CONNECT_FAILED;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( TRANS(TLIGetPeerAddr)(ciptr) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
2006-11-25 11:24:24 -07:00
|
|
|
"TLIConnect: ...TLIGetPeerAddr() failed: %d\n",
|
2012-04-08 08:50:52 -06:00
|
|
|
errno);
|
2006-11-25 11:24:24 -07:00
|
|
|
return TRANS_CONNECT_FAILED;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( ioctl(ciptr->fd, I_POP,"timod") < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLIConnect() ioctl(I_POP,\"timod\") failed %d\n",
|
|
|
|
errno);
|
2006-11-25 11:24:24 -07:00
|
|
|
return TRANS_CONNECT_FAILED;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( ioctl(ciptr->fd, I_PUSH,"tirdwr") < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLIConnect() ioctl(I_PUSH,\"tirdwr\") failed %d\n",
|
|
|
|
errno);
|
2006-11-25 11:24:24 -07:00
|
|
|
return TRANS_CONNECT_FAILED;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLIINETConnect)(XtransConnInfo ciptr, char *host, char *port)
|
|
|
|
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
char portbuf[PORTBUFSIZE];
|
2006-11-25 11:24:24 -07:00
|
|
|
struct t_call *sndcall;
|
|
|
|
long tmpport;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(2, "TLIINETConnect(%s,%s)\n", host, port);
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
#ifdef X11_t
|
|
|
|
/*
|
|
|
|
* X has a well known port, that is transport dependant. It is easier
|
|
|
|
* to handle it here, than try and come up with a transport independent
|
|
|
|
* representation that can be passed in and resolved the usual way.
|
|
|
|
*
|
|
|
|
* The port that is passed here is really a string containing the idisplay
|
|
|
|
* from ConnectDisplay().
|
|
|
|
*/
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if (is_numeric (port))
|
|
|
|
{
|
|
|
|
tmpport = X_TCP_PORT + strtol (port, (char**)NULL, 10);
|
|
|
|
sprintf(portbuf,"%u", tmpport );
|
|
|
|
port = portbuf;
|
|
|
|
}
|
|
|
|
#endif
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (sndcall=(struct t_call *)t_alloc(ciptr->fd,T_CALL,T_ALL)) == NULL )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLIINETConnect() failed to allocate a t_call\n");
|
2006-11-25 11:24:24 -07:00
|
|
|
return TRANS_CONNECT_FAILED;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( TRANS(TLIAddrToNetbuf)(ciptr->index, host, port, &(sndcall->addr) ) < 0 )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLIINETConnect() unable to resolve name:%s.%s\n",
|
|
|
|
host, port);
|
2006-11-25 11:24:24 -07:00
|
|
|
t_free((char *)sndcall,T_CALL);
|
|
|
|
return TRANS_CONNECT_FAILED;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return TRANS(TLIConnect)(ciptr, sndcall );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLITLIConnect)(XtransConnInfo ciptr, char *host, char *port)
|
|
|
|
|
|
|
|
{
|
|
|
|
struct t_call *sndcall;
|
|
|
|
struct sockaddr_un *sunaddr;
|
|
|
|
int ret_value;
|
2012-04-08 08:50:52 -06:00
|
|
|
|
|
|
|
prmsg(2, "TLITLIConnect(%s,%s)\n", host, port);
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (sndcall=(struct t_call *)t_alloc(ciptr->fd,T_CALL,T_OPT|T_UDATA)) == NULL )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1, "TLITLIConnect() failed to allocate a t_call\n");
|
2006-11-25 11:24:24 -07:00
|
|
|
return TRANS_CONNECT_FAILED;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( (sunaddr=(struct sockaddr_un *)
|
|
|
|
malloc(sizeof(struct sockaddr_un))) == NULL )
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(1,
|
|
|
|
"TLITLIConnect: failed to allocate a sockaddr_un\n");
|
2006-11-25 11:24:24 -07:00
|
|
|
t_free((char *)sndcall,T_CALL);
|
|
|
|
return TRANS_CONNECT_FAILED;
|
|
|
|
}
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
sunaddr->sun_family=AF_UNIX;
|
|
|
|
if( *port == '/' ||
|
|
|
|
strncmp (port, TLINODENAME, strlen (TLINODENAME)) == 0) {
|
|
|
|
/* Use the port as is */
|
|
|
|
(void) strcpy(sunaddr->sun_path, port);
|
|
|
|
} else {
|
|
|
|
(void) sprintf(sunaddr->sun_path,"%s%s", TLINODENAME, port );
|
|
|
|
}
|
|
|
|
|
|
|
|
sndcall->addr.buf=(char *)sunaddr;
|
|
|
|
sndcall->addr.len=sizeof(*sunaddr);
|
|
|
|
sndcall->addr.maxlen=sizeof(*sunaddr);
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
ret_value = TRANS(TLIConnect)(ciptr, sndcall );
|
|
|
|
|
|
|
|
free((char *) sunaddr);
|
|
|
|
|
|
|
|
return ret_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* TRANS_CLIENT */
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLIBytesReadable)(XtransConnInfo ciptr, BytesReadable_t *pend)
|
|
|
|
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct pollfd filedes;
|
|
|
|
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(2, "TLIByteReadable(%x->%d,%x)\n", ciptr, ciptr->fd, pend );
|
2006-11-25 11:24:24 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This function should detect hangup conditions. Use poll to check
|
|
|
|
* if no data is present. On SVR4, the M_HANGUP message sits on the
|
|
|
|
* streams head, and ioctl(N_READ) keeps returning 0 because there is
|
|
|
|
* no data available. The hangup goes undetected, and the client hangs.
|
|
|
|
*/
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
ret=ioctl(ciptr->fd, I_NREAD, (char *)pend);
|
|
|
|
|
|
|
|
if( ret != 0 )
|
|
|
|
return ret; /* Data present or error */
|
|
|
|
|
|
|
|
|
|
|
|
/* Zero data, or POLLHUP message */
|
|
|
|
|
|
|
|
filedes.fd=ciptr->fd;
|
|
|
|
filedes.events=POLLIN;
|
|
|
|
|
|
|
|
ret=poll(&filedes, 1, 0);
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
if( ret == 0 ) {
|
|
|
|
*pend=0;
|
|
|
|
return 0; /* Really, no data */
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ret < 0 )
|
|
|
|
return -1; /* just pass back the error */
|
|
|
|
|
|
|
|
if( filedes.revents & (POLLHUP|POLLERR) ) /* check for hangup */
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Should only get here if data arrived after the first ioctl() */
|
|
|
|
return ioctl(ciptr->fd, I_NREAD, (char *)pend);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLIRead)(XtransConnInfo ciptr, char *buf, int size)
|
|
|
|
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(2, "TLIRead(%d,%x,%d)\n", ciptr->fd, buf, size );
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return read(ciptr->fd,buf,size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLIWrite)(XtransConnInfo ciptr, char *buf, int size)
|
|
|
|
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(2, "TLIWrite(%d,%x,%d)\n", ciptr->fd, buf, size );
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return write(ciptr->fd,buf,size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLIReadv)(XtransConnInfo ciptr, struct iovec *buf, int size)
|
|
|
|
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(2, "TLIReadv(%d,%x,%d)\n", ciptr->fd, buf, size );
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return READV(ciptr,buf,size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLIWritev)(XtransConnInfo ciptr, struct iovec *buf, int size)
|
|
|
|
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(2, "TLIWritev(%d,%x,%d)\n", ciptr->fd, buf, size );
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return WRITEV(ciptr,buf,size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLIDisconnect)(XtransConnInfo ciptr)
|
|
|
|
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(2, "TLIDisconnect(%x->%d)\n", ciptr, ciptr->fd);
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
/*
|
|
|
|
* Restore the TLI modules so that the connection can be properly shutdown.
|
|
|
|
* This avoids the situation where a connection goes into the TIME_WAIT
|
|
|
|
* state, and the address remains unavailable for a while.
|
|
|
|
*/
|
|
|
|
ioctl(ciptr->fd, I_POP,"tirdwr");
|
|
|
|
ioctl(ciptr->fd, I_PUSH,"timod");
|
|
|
|
|
|
|
|
t_snddis(ciptr->fd,NULL);
|
2012-04-08 08:50:52 -06:00
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLIClose)(XtransConnInfo ciptr)
|
|
|
|
|
|
|
|
{
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(2, "TLIClose(%x->%d)\n", ciptr, ciptr->fd);
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
t_unbind(ciptr->fd);
|
|
|
|
|
|
|
|
return (t_close(ciptr->fd));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
TRANS(TLICloseForCloning)(XtransConnInfo ciptr)
|
|
|
|
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Don't unbind.
|
|
|
|
*/
|
|
|
|
|
2012-04-08 08:50:52 -06:00
|
|
|
prmsg(2, "TLICloseForCloning(%x->%d)\n", ciptr, ciptr->fd);
|
|
|
|
|
2006-11-25 11:24:24 -07:00
|
|
|
return (t_close(ciptr->fd));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Xtransport TRANS(TLITCPFuncs) = {
|
|
|
|
/* TLI Interface */
|
|
|
|
"tcp",
|
|
|
|
0,
|
|
|
|
#ifdef TRANS_CLIENT
|
|
|
|
TRANS(TLIOpenCOTSClient),
|
|
|
|
#endif /* TRANS_CLIENT */
|
|
|
|
#ifdef TRANS_SERVER
|
|
|
|
NULL,
|
|
|
|
TRANS(TLIOpenCOTSServer),
|
|
|
|
#endif /* TRANS_SERVER */
|
|
|
|
#ifdef TRANS_CLIENT
|
|
|
|
TRANS(TLIOpenCLTSClient),
|
|
|
|
#endif /* TRANS_CLIENT */
|
|
|
|
#ifdef TRANS_SERVER
|
|
|
|
TRANS(TLIOpenCLTSServer),
|
|
|
|
#endif /* TRANS_SERVER */
|
|
|
|
#ifdef TRANS_REOPEN
|
|
|
|
TRANS(TLIReopenCOTSServer),
|
|
|
|
TRANS(TLIReopenCLTSServer),
|
|
|
|
#endif
|
|
|
|
TRANS(TLISetOption),
|
|
|
|
#ifdef TRANS_SERVER
|
|
|
|
TRANS(TLIINETCreateListener),
|
|
|
|
NULL, /* ResetListener */
|
|
|
|
TRANS(TLIAccept),
|
|
|
|
#endif /* TRANS_SERVER */
|
|
|
|
#ifdef TRANS_CLIENT
|
|
|
|
TRANS(TLIINETConnect),
|
|
|
|
#endif /* TRANS_CLIENT */
|
|
|
|
TRANS(TLIBytesReadable),
|
|
|
|
TRANS(TLIRead),
|
|
|
|
TRANS(TLIWrite),
|
|
|
|
TRANS(TLIReadv),
|
|
|
|
TRANS(TLIWritev),
|
|
|
|
TRANS(TLIDisconnect),
|
|
|
|
TRANS(TLIClose),
|
|
|
|
TRANS(TLICloseForCloning),
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef TRANS_SERVER
|
|
|
|
static char * inet_aliases[] = { "tcp", NULL };
|
|
|
|
#endif
|
|
|
|
Xtransport TRANS(TLIINETFuncs) = {
|
|
|
|
/* TLI Interface */
|
|
|
|
"inet",
|
|
|
|
TRANS_ALIAS,
|
|
|
|
#ifdef TRANS_CLIENT
|
|
|
|
TRANS(TLIOpenCOTSClient),
|
|
|
|
#endif /* TRANS_CLIENT */
|
|
|
|
#ifdef TRANS_SERVER
|
|
|
|
inet_aliases,
|
|
|
|
TRANS(TLIOpenCOTSServer),
|
|
|
|
#endif /* TRANS_SERVER */
|
|
|
|
#ifdef TRANS_CLIENT
|
|
|
|
TRANS(TLIOpenCLTSClient),
|
|
|
|
#endif /* TRANS_CLIENT */
|
|
|
|
#ifdef TRANS_SERVER
|
|
|
|
TRANS(TLIOpenCLTSServer),
|
|
|
|
#endif /* TRANS_SERVER */
|
|
|
|
#ifdef TRANS_REOPEN
|
|
|
|
TRANS(TLIReopenCOTSServer),
|
|
|
|
TRANS(TLIReopenCLTSServer),
|
|
|
|
#endif
|
|
|
|
TRANS(TLISetOption),
|
|
|
|
#ifdef TRANS_SERVER
|
|
|
|
TRANS(TLIINETCreateListener),
|
|
|
|
NULL, /* ResetListener */
|
|
|
|
TRANS(TLIAccept),
|
|
|
|
#endif /* TRANS_SERVER */
|
|
|
|
#ifdef TRANS_CLIENT
|
|
|
|
TRANS(TLIINETConnect),
|
|
|
|
#endif /* TRANS_CLIENT */
|
|
|
|
TRANS(TLIBytesReadable),
|
|
|
|
TRANS(TLIRead),
|
|
|
|
TRANS(TLIWrite),
|
|
|
|
TRANS(TLIReadv),
|
|
|
|
TRANS(TLIWritev),
|
|
|
|
TRANS(TLIDisconnect),
|
|
|
|
TRANS(TLIClose),
|
|
|
|
TRANS(TLICloseForCloning),
|
|
|
|
};
|
|
|
|
|
|
|
|
Xtransport TRANS(TLITLIFuncs) = {
|
|
|
|
/* TLI Interface */
|
|
|
|
"tli",
|
|
|
|
0,
|
|
|
|
#ifdef TRANS_CLIENT
|
|
|
|
TRANS(TLIOpenCOTSClient),
|
|
|
|
#endif /* TRANS_CLIENT */
|
|
|
|
#ifdef TRANS_SERVER
|
|
|
|
NULL,
|
|
|
|
TRANS(TLIOpenCOTSServer),
|
|
|
|
#endif /* TRANS_SERVER */
|
|
|
|
#ifdef TRANS_CLIENT
|
|
|
|
TRANS(TLIOpenCLTSClient),
|
|
|
|
#endif /* TRANS_CLIENT */
|
|
|
|
#ifdef TRANS_SERVER
|
|
|
|
TRANS(TLIOpenCLTSServer),
|
|
|
|
#endif /* TRANS_SERVER */
|
|
|
|
#ifdef TRANS_REOPEN
|
|
|
|
TRANS(TLIReopenCOTSServer),
|
|
|
|
TRANS(TLIReopenCLTSServer),
|
|
|
|
#endif
|
|
|
|
TRANS(TLISetOption),
|
|
|
|
#ifdef TRANS_SERVER
|
|
|
|
TRANS(TLITLICreateListener),
|
|
|
|
NULL, /* ResetListener */
|
|
|
|
TRANS(TLIAccept),
|
|
|
|
#endif /* TRANS_SERVER */
|
|
|
|
#ifdef TRANS_CLIENT
|
|
|
|
TRANS(TLITLIConnect),
|
|
|
|
#endif /* TRANS_CLIENT */
|
|
|
|
TRANS(TLIBytesReadable),
|
|
|
|
TRANS(TLIRead),
|
|
|
|
TRANS(TLIWrite),
|
|
|
|
TRANS(TLIReadv),
|
|
|
|
TRANS(TLIWritev),
|
|
|
|
TRANS(TLIDisconnect),
|
|
|
|
TRANS(TLIClose),
|
|
|
|
TRANS(TLICloseForCloning),
|
|
|
|
};
|