aboutsummaryrefslogtreecommitdiff
path: root/nx-X11
diff options
context:
space:
mode:
authorMike Gabriel <mike.gabriel@das-netzwerkteam.de>2016-11-02 19:50:24 +0100
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2016-11-02 19:50:24 +0100
commit107e72b038bc76953dc97d4ea655c9bde10e5865 (patch)
treea5c7cd9dc1857fd972683481fa39f6eba685b32e /nx-X11
parenta9b145d466f774d0a6948a493df2e9c7bff50d6f (diff)
parent6a186b9217e0e3ca10f285f90e5afcdd22dc6c2e (diff)
downloadnx-libs-107e72b038bc76953dc97d4ea655c9bde10e5865.tar.gz
nx-libs-107e72b038bc76953dc97d4ea655c9bde10e5865.tar.bz2
nx-libs-107e72b038bc76953dc97d4ea655c9bde10e5865.zip
Merge branch 'uli42-pr/upgrade_xtrans' into 3.6.x
Attributes GH PR #268: https://github.com/ArcticaProject/nx-libs/pull/268
Diffstat (limited to 'nx-X11')
-rw-r--r--nx-X11/config/cf/Imake.tmpl6
-rw-r--r--nx-X11/config/cf/README2
-rw-r--r--nx-X11/config/cf/X11.tmpl16
-rw-r--r--nx-X11/config/cf/host.def7
-rw-r--r--nx-X11/config/cf/linux.cf11
-rw-r--r--nx-X11/config/cf/xorgsite.def7
-rw-r--r--nx-X11/lib/X11/ConnDis.c53
-rw-r--r--nx-X11/lib/xtrans/Imakefile3
-rw-r--r--nx-X11/lib/xtrans/Xtrans.c606
-rw-r--r--nx-X11/lib/xtrans/Xtrans.h162
-rw-r--r--nx-X11/lib/xtrans/Xtransdnet.c666
-rw-r--r--nx-X11/lib/xtrans/Xtransint.h299
-rw-r--r--nx-X11/lib/xtrans/Xtranslcl.c1223
-rw-r--r--nx-X11/lib/xtrans/Xtransos2.c886
-rw-r--r--nx-X11/lib/xtrans/Xtranssock.c1854
-rw-r--r--nx-X11/lib/xtrans/Xtranstli.c1420
-rw-r--r--nx-X11/lib/xtrans/Xtransutil.c207
-rw-r--r--nx-X11/lib/xtrans/transport.c32
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/man/nxagent.18
-rw-r--r--nx-X11/programs/Xserver/os/access.c138
-rw-r--r--nx-X11/programs/Xserver/os/connection.c16
-rw-r--r--nx-X11/programs/Xserver/os/utils.c4
-rw-r--r--nx-X11/programs/Xserver/os/xdmauth.c2
-rw-r--r--nx-X11/programs/Xserver/os/xdmcp.c45
24 files changed, 2064 insertions, 5609 deletions
diff --git a/nx-X11/config/cf/Imake.tmpl b/nx-X11/config/cf/Imake.tmpl
index 6406fca33..5c8effee5 100644
--- a/nx-X11/config/cf/Imake.tmpl
+++ b/nx-X11/config/cf/Imake.tmpl
@@ -375,12 +375,6 @@ XCOMM the platform-specific parameters - edit site.def to change
#ifndef HasSockets
#define HasSockets YES
#endif
-#ifndef HasStreams
-#define HasStreams !HasSockets
-#endif
-#ifndef HasDECnet
-#define HasDECnet NO
-#endif
#ifndef HasPoll
#if SystemV || SystemV4
#define HasPoll YES
diff --git a/nx-X11/config/cf/README b/nx-X11/config/cf/README
index 27c2386a4..9cb2ff91e 100644
--- a/nx-X11/config/cf/README
+++ b/nx-X11/config/cf/README
@@ -53,7 +53,6 @@ Imake.tmpl provides defaults for the following variables:
HasCodeCenter boolean for system has CodeCenter
HasCookieMaker boolean for system has xauth cookie generator
HasCplusplus system has a C++ compiler?
- HasDECnet system has DECnet?
HasFortran boolean for system has Fortran compiler
HasGcc boolean for system has GNU gcc compiler
HasGcc2 boolean for system has GNU gcc 2.x compiler
@@ -78,7 +77,6 @@ Imake.tmpl provides defaults for the following variables:
HasShm boolean for System V shared memory
HasSockets boolean for system has BSD sockets
HasStrcasecmp boolean for system implements str[n]casecmp
- HasStreams use STREAMS I/O interface?
HasSymLinks boolean for system has symbolic links
HasTestCenter boolean for system has TestCenter
HasVarDirectory boolean for system has /var
diff --git a/nx-X11/config/cf/X11.tmpl b/nx-X11/config/cf/X11.tmpl
index 33d108d06..1942ca805 100644
--- a/nx-X11/config/cf/X11.tmpl
+++ b/nx-X11/config/cf/X11.tmpl
@@ -334,8 +334,7 @@ XORGRELSTRING = XorgManVersionString
* NOTE: IPv6Flags could be tacked on to either ConnectionFlags or
* ExtraConnectionDefs. Here, we choose the later in order to
* maximise exposure of the IPv6 code (a number of <OS>.def files
- * contain ConnectionFlags overrides). Mind you, this might not
- * the right thing to do when HasStreams is asserted.
+ * contain ConnectionFlags overrides).
*/
#ifndef BuildIPv6 /* If the OS also #define's AF_INET6 */
#define BuildIPv6 YES
@@ -355,19 +354,8 @@ XORGRELSTRING = XorgManVersionString
#ifndef IPv6SocketsAlsoIPv4
#define IPv6SocketsAlsoIPv4 YES
#endif
-#ifndef DECnetFlags
-#if HasDECnet
-#define DECnetFlags -DDNETCONN
-#else
-#define DECnetFlags
-#endif
-#endif
#ifndef ConnectionFlags
-#if HasStreams
-#define ConnectionFlags -DSTREAMSCONN
-#else
-#define ConnectionFlags -DTCPCONN -DUNIXCONN DECnetFlags
-#endif
+#define ConnectionFlags -DTCPCONN -DUNIXCONN
#endif
#if HasStickyDirBit
STICKY_DEFINES = -DHAS_STICKY_DIR_BIT
diff --git a/nx-X11/config/cf/host.def b/nx-X11/config/cf/host.def
index 0dccfad8b..efd1aad7c 100644
--- a/nx-X11/config/cf/host.def
+++ b/nx-X11/config/cf/host.def
@@ -430,13 +430,6 @@
#endif /* #if defined(LinuxArchitecture) */
/*
- * If you have Linux DECnet support, and want to build XFree86 with support
- * for connections over DECnet, uncomment this.
- *
-#define HasDECnet YES
- */
-
-/*
* To build static and shared libraries with debugging information, uncomment
* this. Assumes you have Gcc2.
* (If you don't have Gcc2, you can use the DebugLib{X11,...} variables
diff --git a/nx-X11/config/cf/linux.cf b/nx-X11/config/cf/linux.cf
index 9238b9e6f..c6ae58474 100644
--- a/nx-X11/config/cf/linux.cf
+++ b/nx-X11/config/cf/linux.cf
@@ -861,15 +861,8 @@ XCOMM binutils: (LinuxBinUtilsMajorVersion)
#define PamMiscLibraries -lpam_misc
#endif
-#ifndef HasDECnet
-#define HasDECnet NO
-#endif
-#if HasDECnet
-# define ConnectionFlags -DUNIXCONN -DTCPCONN -DDNETCONN
-# define ExtraLibraries -ldnet
-#else
-# define ConnectionFlags -DUNIXCONN -DTCPCONN
-#endif
+#define ConnectionFlags -DUNIXCONN -DTCPCONN
+
/* Some of these man page defaults are overriden in the above OS sections */
#ifndef ManSuffix
diff --git a/nx-X11/config/cf/xorgsite.def b/nx-X11/config/cf/xorgsite.def
index 1614fce5e..f735495f8 100644
--- a/nx-X11/config/cf/xorgsite.def
+++ b/nx-X11/config/cf/xorgsite.def
@@ -276,13 +276,6 @@
#define HasXdmAuth YES
/*
- * If you have Linux DECnet support, and want to build XFree86 with support
- * for connections over DECnet, uncomment this.
- *
-#define HasDECnet YES
- */
-
-/*
* To build static and shared libraries with debugging information, uncomment
* this. Assumes you have Gcc2.
* (If you don't have Gcc2, you can use the DebugLib{X11,...} variables
diff --git a/nx-X11/lib/X11/ConnDis.c b/nx-X11/lib/X11/ConnDis.c
index 46b71b23f..660b67645 100644
--- a/nx-X11/lib/X11/ConnDis.c
+++ b/nx-X11/lib/X11/ConnDis.c
@@ -115,7 +115,7 @@ static char *copystring (const char *src, int len)
#ifdef UNIXCONN
# define UNIX_TRANS "unix"
#endif
-#if defined(LOCALCONN) || defined(OS2PIPECONN) || defined(UNIXCONN)
+#if defined(LOCALCONN) || defined(UNIXCONN)
# define LOCAL_TRANS "local"
#endif
@@ -145,14 +145,15 @@ static char *copystring (const char *src, int len)
*
* [protocol/] [hostname] : [:] displaynumber [.screennumber]
*
- * A string with exactly two colons seperating hostname from the display
- * indicates a DECnet style name. Colons in the hostname may occur if an
- * IPv6 numeric address is used as the hostname. An IPv6 numeric address
- * may also end in a double colon, so three colons in a row indicates an
- * IPv6 address ending in :: followed by :display. To make it easier for
- * people to read, an IPv6 numeric address hostname may be surrounded by
- * [ ] in a similar fashion to the IPv6 numeric address URL syntax defined
- * by IETF RFC 2732.
+ * A string with exactly two colons seperating hostname from the
+ * display indicates a (now unsupported) DECnet style name. Colons in
+ * the hostname may occur if an IPv6 numeric address is used as the
+ * hostname. An IPv6 numeric address may also end in a double colon,
+ * so three colons in a row indicates an IPv6 address ending in ::
+ * followed by :display. To make it easier for people to read, an
+ * IPv6 numeric address hostname may be surrounded by [ ] in a similar
+ * fashion to the IPv6 numeric address URL syntax defined by IETF RFC
+ * 2732.
*
* If no hostname and no protocol is specified, the string is interpreted
* as the most efficient local connection to a server on the same machine.
@@ -188,7 +189,6 @@ _X11TransConnectDisplay (
char *phostname = NULL; /* start of host of display */
char *pdpynum = NULL; /* start of dpynum of display */
char *pscrnum = NULL; /* start of screen of display */
- Bool dnet = False; /* if true, then DECnet format */
int idisplay = 0; /* required display number */
int iscreen = 0; /* optional screen number */
/* int (*connfunc)(); */ /* method to create connection */
@@ -318,6 +318,7 @@ _X11TransConnectDisplay (
* or two colons in the case of DECnet (DECnet Phase V allows a single
* colon in the hostname). (See note above regarding IPv6 numeric
* addresses with triple colons or [] brackets.)
+ * FIXME: we do not support DECnet anymore, so maybe remove these checks?
*/
lastp = p;
@@ -335,16 +336,7 @@ _X11TransConnectDisplay (
) {
/* DECnet display specified */
-#ifndef DNETCONN
goto bad;
-#else
- dnet = True;
- /* override the protocol specified */
- if (pprotocol)
- Xfree (pprotocol);
- pprotocol = copystring ("dnet", 4);
- hostlen = lastc - 1 - lastp;
-#endif
}
else
hostlen = lastc - lastp;
@@ -482,7 +474,6 @@ _X11TransConnectDisplay (
* phostname hostname string or NULL
* idisplay display number
* iscreen screen number
- * dnet DECnet boolean
*
* We can now decide which transport to use based on the ConnectionFlags
* build parameter the hostname string. If phostname is NULL or equals
@@ -511,7 +502,7 @@ _X11TransConnectDisplay (
#endif
-#if defined(TCPCONN) || defined(UNIXCONN) || defined(LOCALCONN) || defined(MNX_TCPCONN) || defined(OS2PIPECONN)
+#if defined(TCPCONN) || defined(UNIXCONN) || defined(LOCALCONN) || defined(MNX_TCPCONN)
if (!pprotocol) {
#if defined(UNIXCONN)
if (phostname && (strcmp (phostname, "unix") == 0)) {
@@ -654,7 +645,7 @@ _X11TransConnectDisplay (
original_hostname = NULL;
}
#endif
- len = ((phostname ? strlen(phostname) : 0) + 1 + (dnet ? 1 : 0) +
+ len = ((phostname ? strlen(phostname) : 0) + 1 +
strlen(pdpynum) + 1 + (pscrnum ? strlen(pscrnum) : 1) + 1);
*fullnamep = (char *) Xmalloc (len);
if (!*fullnamep) goto bad;
@@ -663,13 +654,13 @@ _X11TransConnectDisplay (
if (phostname && strlen(phostname) > 11 && !strncmp(phostname, "/tmp/launch", 11))
sprintf (*fullnamep, "%s%s%d",
(phostname ? phostname : ""),
- (dnet ? "::" : ":"),
+ ":",
idisplay);
else
#endif
sprintf (*fullnamep, "%s%s%d.%d",
(phostname ? phostname : ""),
- (dnet ? "::" : ":"),
+ ":",
idisplay, iscreen);
*dpynump = idisplay;
@@ -855,13 +846,6 @@ _XSendClientPrefix(
}
-#ifdef STREAMSCONN
-#ifdef SVR4
-#include <tiuser.h>
-#else
-#undef HASXDMAUTH
-#endif
-#endif
#ifdef SECURE_RPC
#include <rpc/rpc.h>
@@ -1419,13 +1403,6 @@ GetAuthorization(
break;
}
#endif /* AF_UNIX */
-#ifdef AF_DECnet
- case AF_DECnet:
- /*
- * What is the defined encoding for this?
- */
- break;
-#endif /* AF_DECnet */
default:
/*
* Need to return some kind of errro status here.
diff --git a/nx-X11/lib/xtrans/Imakefile b/nx-X11/lib/xtrans/Imakefile
index b4b36685d..70716bb90 100644
--- a/nx-X11/lib/xtrans/Imakefile
+++ b/nx-X11/lib/xtrans/Imakefile
@@ -9,12 +9,9 @@ DEFINES = $(FAILDEFINES)
HEADERS = \
Xtrans.h \
Xtrans.c \
- Xtransdnet.c \
Xtransint.h \
Xtranslcl.c \
- Xtransos2.c \
Xtranssock.c \
- Xtranstli.c \
Xtransutil.c \
transport.c
diff --git a/nx-X11/lib/xtrans/Xtrans.c b/nx-X11/lib/xtrans/Xtrans.c
index d665305bb..16dd61155 100644
--- a/nx-X11/lib/xtrans/Xtrans.c
+++ b/nx-X11/lib/xtrans/Xtrans.c
@@ -24,9 +24,7 @@ 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.
-*/
-
-/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
*
* All Rights Reserved
*
@@ -50,6 +48,11 @@ from The Open Group.
*/
#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_SYSTEMD_DAEMON
+#include <systemd/sd-daemon.h>
+#endif
/*
* The transport table contains a definition for every transport (protocol)
@@ -74,18 +77,14 @@ from The Open Group.
#define TRANS_LOCAL_LOCAL_INDEX 9
#define TRANS_LOCAL_PTS_INDEX 10
#define TRANS_LOCAL_NAMED_INDEX 11
-#define TRANS_LOCAL_ISC_INDEX 12
+/* 12 used to be ISC, but that's gone. */
#define TRANS_LOCAL_SCO_INDEX 13
#define TRANS_SOCKET_INET6_INDEX 14
+#define TRANS_LOCAL_PIPE_INDEX 15
static
Xtransport_table Xtransports[] = {
-#if defined(STREAMSCONN)
- { &TRANS(TLITCPFuncs), TRANS_TLI_TCP_INDEX },
- { &TRANS(TLIINETFuncs), TRANS_TLI_INET_INDEX },
- { &TRANS(TLITLIFuncs), TRANS_TLI_TLI_INDEX },
-#endif /* STREAMSCONN */
#if defined(TCPCONN)
{ &TRANS(SocketTCPFuncs), TRANS_SOCKET_TCP_INDEX },
#if defined(IPv6) && defined(AF_INET6)
@@ -93,32 +92,26 @@ Xtransport_table Xtransports[] = {
#endif /* IPv6 */
{ &TRANS(SocketINETFuncs), TRANS_SOCKET_INET_INDEX },
#endif /* TCPCONN */
-#if defined(DNETCONN)
- { &TRANS(DNETFuncs), TRANS_DNET_INDEX },
-#endif /* DNETCONN */
#if defined(UNIXCONN)
#if !defined(LOCALCONN)
{ &TRANS(SocketLocalFuncs), TRANS_SOCKET_LOCAL_INDEX },
#endif /* !LOCALCONN */
{ &TRANS(SocketUNIXFuncs), TRANS_SOCKET_UNIX_INDEX },
#endif /* UNIXCONN */
-#if defined(OS2PIPECONN)
- { &TRANS(OS2LocalFuncs), TRANS_LOCAL_LOCAL_INDEX },
-#endif /* OS2PIPECONN */
#if defined(LOCALCONN)
{ &TRANS(LocalFuncs), TRANS_LOCAL_LOCAL_INDEX },
-#ifndef sun
+#ifndef __sun
{ &TRANS(PTSFuncs), TRANS_LOCAL_PTS_INDEX },
-#endif /* sun */
-#ifdef SVR4
+#endif /* __sun */
+#if defined(SVR4) || defined(__SVR4)
{ &TRANS(NAMEDFuncs), TRANS_LOCAL_NAMED_INDEX },
#endif
-#ifndef sun
-#if !defined(__SCO__) && !defined(__UNIXWARE__)
- { &TRANS(ISCFuncs), TRANS_LOCAL_ISC_INDEX },
-#endif
+#ifdef __sun
+ { &TRANS(PIPEFuncs), TRANS_LOCAL_PIPE_INDEX },
+#endif /* __sun */
+#if defined(__SCO__) || defined(__UNIXWARE__)
{ &TRANS(SCOFuncs), TRANS_LOCAL_SCO_INDEX },
-#endif /* sun */
+#endif /* __SCO__ || __UNIXWARE__ */
#endif /* LOCALCONN */
};
@@ -139,7 +132,7 @@ void
TRANS(FreeConnInfo) (XtransConnInfo ciptr)
{
- PRMSG (3,"FreeConnInfo(%p)\n", ciptr, 0, 0);
+ prmsg (3,"FreeConnInfo(%p)\n", ciptr);
if (ciptr->addr)
free (ciptr->addr);
@@ -150,20 +143,20 @@ TRANS(FreeConnInfo) (XtransConnInfo ciptr)
if (ciptr->port)
free (ciptr->port);
- free ((char *) ciptr);
+ free (ciptr);
}
#define PROTOBUFSIZE 20
static Xtransport *
-TRANS(SelectTransport) (char *protocol)
+TRANS(SelectTransport) (const char *protocol)
{
char protobuf[PROTOBUFSIZE];
int i;
- PRMSG (3,"SelectTransport(%s)\n", protocol, 0, 0);
+ prmsg (3,"SelectTransport(%s)\n", protocol);
/*
* Force Protocol to be lowercase as a way of doing
@@ -174,8 +167,8 @@ TRANS(SelectTransport) (char *protocol)
protobuf[PROTOBUFSIZE-1] = '\0';
for (i = 0; i < PROTOBUFSIZE && protobuf[i] != '\0'; i++)
- if (isupper (protobuf[i]))
- protobuf[i] = tolower (protobuf[i]);
+ if (isupper ((unsigned char)protobuf[i]))
+ protobuf[i] = tolower ((unsigned char)protobuf[i]);
/* Look at all of the configured protocols */
@@ -192,7 +185,8 @@ TRANS(SelectTransport) (char *protocol)
static
#endif /* TEST_t */
int
-TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
+TRANS(ParseAddress) (const char *address,
+ char **protocol, char **host, char **port)
{
/*
@@ -210,19 +204,19 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
*/
char *mybuf, *tmpptr;
- char *_protocol, *_host, *_port;
+ const char *_protocol;
+ char *_host, *_port;
char hostnamebuf[256];
int _host_len;
- PRMSG (3,"ParseAddress(%s)\n", address, 0, 0);
+ prmsg (3,"ParseAddress(%s)\n", address);
/* Copy the string so it can be changed */
- tmpptr = mybuf = (char *) malloc (strlen (address) + 1);
- strcpy (mybuf, address);
+ tmpptr = mybuf = strdup (address);
/* Parse the string to get each component */
-
+
/* Get the protocol part */
_protocol = mybuf;
@@ -289,22 +283,6 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
return 0;
}
- /* Check for DECnet */
-
- if ((mybuf != _host) && (*(mybuf - 1) == ':')
-#if defined(IPv6) && defined(AF_INET6)
- /* An IPv6 address can end in :: so three : in a row is assumed to be
- an IPv6 host and not a DECnet node with a : in it's name, unless
- DECnet is specifically requested */
- && ( ((mybuf - 1) == _host) || (*(mybuf - 2) != ':') ||
- ((_protocol != NULL) && (strcmp(_protocol, "dnet") == 0)) )
-#endif
- )
- {
- _protocol = "dnet";
- *(mybuf - 1) = '\0';
- }
-
*mybuf ++= '\0';
_host_len = strlen(_host);
@@ -315,9 +293,9 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
}
#if defined(IPv6) && defined(AF_INET6)
/* hostname in IPv6 [numeric_addr]:0 form? */
- else if ( (_host_len > 3) &&
+ else if ( (_host_len > 3) &&
((strcmp(_protocol, "tcp") == 0) || (strcmp(_protocol, "inet6") == 0))
- && (*_host == '[') && (*(_host + _host_len - 1) == ']') ) {
+ && (*_host == '[') && (*(_host + _host_len - 1) == ']') ) {
struct sockaddr_in6 sin6;
*(_host + _host_len - 1) = '\0';
@@ -354,12 +332,21 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
*/
#endif
+#ifdef HAVE_LAUNCHD
+ /* launchd sockets will look like 'local//tmp/launch-XgkNns/:0' */
+ if(address != NULL && strlen(address)>8 && (!strncmp(address,"local//",7))) {
+ _protocol="local";
+ _host="";
+ _port=address+6;
+ }
+#endif
+
/*
* Now that we have all of the components, allocate new
* string space for them.
*/
- if ((*protocol = (char *) malloc(strlen (_protocol) + 1)) == NULL)
+ if ((*protocol = strdup (_protocol)) == NULL)
{
/* Malloc failed */
*port = NULL;
@@ -368,10 +355,8 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
free (tmpptr);
return 0;
}
- else
- strcpy (*protocol, _protocol);
- if ((*host = (char *) malloc (strlen (_host) + 1)) == NULL)
+ if ((*host = strdup (_host)) == NULL)
{
/* Malloc failed */
*port = NULL;
@@ -381,10 +366,8 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
free (tmpptr);
return 0;
}
- else
- strcpy (*host, _host);
- if ((*port = (char *) malloc (strlen (_port) + 1)) == NULL)
+ if ((*port = strdup (_port)) == NULL)
{
/* Malloc failed */
*port = NULL;
@@ -395,8 +378,6 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
free (tmpptr);
return 0;
}
- else
- strcpy (*port, _port);
free (tmpptr);
@@ -411,19 +392,19 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
*/
static XtransConnInfo
-TRANS(Open) (int type, char *address)
+TRANS(Open) (int type, const char *address)
{
char *protocol = NULL, *host = NULL, *port = NULL;
XtransConnInfo ciptr = NULL;
Xtransport *thistrans;
- PRMSG (2,"Open(%d,%s)\n", type, address, 0);
+ prmsg (2,"Open(%d,%s)\n", type, address);
-#if defined(WIN32) && (defined(TCPCONN) || defined(DNETCONN))
+#if defined(WIN32) && defined(TCPCONN)
if (TRANS(WSAStartup)())
{
- PRMSG (1,"Open: WSAStartup failed\n", 0, 0, 0);
+ prmsg (1,"Open: WSAStartup failed\n");
return NULL;
}
#endif
@@ -432,7 +413,7 @@ TRANS(Open) (int type, char *address)
if (TRANS(ParseAddress) (address, &protocol, &host, &port) == 0)
{
- PRMSG (1,"Open: Unable to Parse address %s\n", address, 0, 0);
+ prmsg (1,"Open: Unable to Parse address %s\n", address);
return NULL;
}
@@ -440,8 +421,8 @@ TRANS(Open) (int type, char *address)
if ((thistrans = TRANS(SelectTransport) (protocol)) == NULL)
{
- PRMSG (1,"Open: Unable to find transport for %s\n",
- protocol, 0, 0);
+ prmsg (1,"Open: Unable to find transport for %s\n",
+ protocol);
free (protocol);
free (host);
@@ -463,25 +444,15 @@ TRANS(Open) (int type, char *address)
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,"Open: Unknown Open type %d\n", type, 0, 0);
+ prmsg (1,"Open: Unknown Open type %d\n", type);
}
if (ciptr == NULL)
{
- if (!(thistrans->flags & TRANS_DISABLED))
+ if (!(thistrans->flags & TRANS_DISABLED))
{
- PRMSG (1,"Open: transport open failed for %s/%s:%s\n",
+ prmsg (1,"Open: transport open failed for %s/%s:%s\n",
protocol, host, port);
}
free (protocol);
@@ -509,7 +480,7 @@ TRANS(Open) (int type, char *address)
*/
static XtransConnInfo
-TRANS(Reopen) (int type, int trans_id, int fd, char *port)
+TRANS(Reopen) (int type, int trans_id, int fd, const char *port)
{
XtransConnInfo ciptr = NULL;
@@ -517,7 +488,7 @@ TRANS(Reopen) (int type, int trans_id, int fd, char *port)
char *save_port;
int i;
- PRMSG (2,"Reopen(%d,%d,%s)\n", trans_id, fd, port);
+ prmsg (2,"Reopen(%d,%d,%s)\n", trans_id, fd, port);
/* Determine the transport type */
@@ -530,21 +501,19 @@ TRANS(Reopen) (int type, int trans_id, int fd, char *port)
if (thistrans == NULL)
{
- PRMSG (1,"Reopen: Unable to find transport id %d\n",
- trans_id, 0, 0);
+ prmsg (1,"Reopen: Unable to find transport id %d\n",
+ trans_id);
return NULL;
}
- if ((save_port = (char *) malloc (strlen (port) + 1)) == NULL)
+ if ((save_port = strdup (port)) == NULL)
{
- PRMSG (1,"Reopen: Unable to malloc port string\n", 0, 0, 0);
+ prmsg (1,"Reopen: Unable to malloc port string\n");
return NULL;
}
- strcpy (save_port, port);
-
/* Get a new XtransConnInfo object */
switch (type)
@@ -552,16 +521,14 @@ TRANS(Reopen) (int type, int trans_id, int fd, char *port)
case XTRANS_OPEN_COTS_SERVER:
ciptr = thistrans->ReopenCOTSServer(thistrans, fd, port);
break;
- case XTRANS_OPEN_CLTS_SERVER:
- ciptr = thistrans->ReopenCLTSServer(thistrans, fd, port);
- break;
default:
- PRMSG (1,"Reopen: Bad Open type %d\n", type, 0, 0);
+ prmsg (1,"Reopen: Bad Open type %d\n", type);
}
if (ciptr == NULL)
{
- PRMSG (1,"Reopen: transport open failed\n", 0, 0, 0);
+ prmsg (1,"Reopen: transport open failed\n");
+ free (save_port);
return NULL;
}
@@ -584,10 +551,10 @@ TRANS(Reopen) (int type, int trans_id, int fd, char *port)
#ifdef TRANS_CLIENT
XtransConnInfo
-TRANS(OpenCOTSClient) (char *address)
+TRANS(OpenCOTSClient) (const char *address)
{
- PRMSG (2,"OpenCOTSClient(%s)\n", address, 0, 0);
+ prmsg (2,"OpenCOTSClient(%s)\n", address);
return TRANS(Open) (XTRANS_OPEN_COTS_CLIENT, address);
}
@@ -597,63 +564,28 @@ TRANS(OpenCOTSClient) (char *address)
#ifdef TRANS_SERVER
XtransConnInfo
-TRANS(OpenCOTSServer) (char *address)
+TRANS(OpenCOTSServer) (const char *address)
{
- PRMSG (2,"OpenCOTSServer(%s)\n", address, 0, 0);
+ prmsg (2,"OpenCOTSServer(%s)\n", address);
return TRANS(Open) (XTRANS_OPEN_COTS_SERVER, address);
}
#endif /* TRANS_SERVER */
-#ifdef TRANS_CLIENT
-
-XtransConnInfo
-TRANS(OpenCLTSClient) (char *address)
-
-{
- PRMSG (2,"OpenCLTSClient(%s)\n", address, 0, 0);
- return TRANS(Open) (XTRANS_OPEN_CLTS_CLIENT, address);
-}
-
-#endif /* TRANS_CLIENT */
-
-
-#ifdef TRANS_SERVER
-
-XtransConnInfo
-TRANS(OpenCLTSServer) (char *address)
-
-{
- PRMSG (2,"OpenCLTSServer(%s)\n", address, 0, 0);
- return TRANS(Open) (XTRANS_OPEN_CLTS_SERVER, address);
-}
-
-#endif /* TRANS_SERVER */
-
-
#ifdef TRANS_REOPEN
XtransConnInfo
-TRANS(ReopenCOTSServer) (int trans_id, int fd, char *port)
+TRANS(ReopenCOTSServer) (int trans_id, int fd, const char *port)
{
- PRMSG (2,"ReopenCOTSServer(%d, %d, %s)\n", trans_id, fd, port);
+ prmsg (2,"ReopenCOTSServer(%d, %d, %s)\n", trans_id, fd, port);
return TRANS(Reopen) (XTRANS_OPEN_COTS_SERVER, trans_id, fd, port);
}
-XtransConnInfo
-TRANS(ReopenCLTSServer) (int trans_id, int fd, char *port)
-
-{
- PRMSG (2,"ReopenCLTSServer(%d, %d, %s)\n", trans_id, fd, port);
- return TRANS(Reopen) (XTRANS_OPEN_CLTS_SERVER, trans_id, fd, port);
-}
-
-
int
-TRANS(GetReopenInfo) (XtransConnInfo ciptr,
+TRANS(GetReopenInfo) (XtransConnInfo ciptr,
int *trans_id, int *fd, char **port)
{
@@ -665,13 +597,10 @@ TRANS(GetReopenInfo) (XtransConnInfo ciptr,
*trans_id = Xtransports[i].transport_id;
*fd = ciptr->fd;
- if ((*port = (char *) malloc (strlen (ciptr->port) + 1)) == NULL)
+ if ((*port = strdup (ciptr->port)) == NULL)
return 0;
else
- {
- strcpy (*port, ciptr->port);
return 1;
- }
}
return 0;
@@ -687,7 +616,7 @@ TRANS(SetOption) (XtransConnInfo ciptr, int option, int arg)
int fd = ciptr->fd;
int ret = 0;
- PRMSG (2,"SetOption(%d,%d,%d)\n", fd, option, arg);
+ prmsg (2,"SetOption(%d,%d,%d)\n", fd, option, arg);
/*
* For now, all transport type use the same stuff for setting options.
@@ -709,7 +638,7 @@ TRANS(SetOption) (XtransConnInfo ciptr, int option, int arg)
break;
case 1: /* Set to non-blocking mode */
-#if defined(O_NONBLOCK) && (!defined(ultrix) && !defined(hpux) && !defined(AIXV3) && !defined(uniosu) && !defined(__UNIXOS2__) && !defined(SCO325)) && !defined(__QNX__)
+#if defined(O_NONBLOCK) && !defined(SCO325)
ret = fcntl (fd, F_GETFL, 0);
if (ret != -1)
ret = fcntl (fd, F_SETFL, ret | O_NONBLOCK);
@@ -721,7 +650,7 @@ TRANS(SetOption) (XtransConnInfo ciptr, int option, int arg)
ret = ioctl (fd, FIOSNBIO, &arg);
}
#else
-#if (defined(AIXV3) || defined(uniosu) || defined(WIN32) || defined(__UNIXOS2__) || defined(__QNX__)) && defined(FIONBIO)
+#if defined(WIN32)
{
#ifdef WIN32
u_long arg;
@@ -731,11 +660,7 @@ TRANS(SetOption) (XtransConnInfo ciptr, int option, int arg)
arg = 1;
/* IBM TCP/IP understands this option too well: it causes TRANS(Read) to fail
* eventually with EWOULDBLOCK */
-#ifndef __UNIXOS2__
ret = ioctl (fd, FIONBIO, &arg);
-#else
-/* ret = ioctl(fd, FIONBIO, &arg, sizeof(int));*/
-#endif
}
#else
ret = fcntl (fd, F_GETFL, 0);
@@ -763,30 +688,58 @@ TRANS(SetOption) (XtransConnInfo ciptr, int option, int arg)
#endif /* F_SETFD */
break;
}
-
+
return ret;
}
#ifdef TRANS_SERVER
int
-TRANS(CreateListener) (XtransConnInfo ciptr, char *port, unsigned int flags)
+TRANS(CreateListener) (XtransConnInfo ciptr, const char *port, unsigned int flags)
{
return ciptr->transptr->CreateListener (ciptr, port, flags);
}
int
-TRANS(NoListen) (char * protocol)
+TRANS(Received) (const char * protocol)
+
+{
+ Xtransport *trans;
+ int i = 0, ret = 0;
+
+ prmsg (5, "Received(%s)\n", protocol);
+
+ if ((trans = TRANS(SelectTransport)(protocol)) == NULL)
+ {
+ prmsg (1,"Received: unable to find transport: %s\n",
+ protocol);
+
+ return -1;
+ }
+ if (trans->flags & TRANS_ALIAS) {
+ if (trans->nolisten)
+ while (trans->nolisten[i]) {
+ ret |= TRANS(Received)(trans->nolisten[i]);
+ i++;
+ }
+ }
+
+ trans->flags |= TRANS_RECEIVED;
+ return ret;
+}
+
+int
+TRANS(NoListen) (const char * protocol)
{
Xtransport *trans;
int i = 0, ret = 0;
-
- if ((trans = TRANS(SelectTransport)(protocol)) == NULL)
+
+ if ((trans = TRANS(SelectTransport)(protocol)) == NULL)
{
- PRMSG (1,"TransNoListen: unable to find transport: %s\n",
- protocol, 0, 0);
+ prmsg (1,"TransNoListen: unable to find transport: %s\n",
+ protocol);
return -1;
}
@@ -803,6 +756,47 @@ TRANS(NoListen) (char * protocol)
}
int
+TRANS(Listen) (const char * protocol)
+{
+ Xtransport *trans;
+ int i = 0, ret = 0;
+
+ if ((trans = TRANS(SelectTransport)(protocol)) == NULL)
+ {
+ prmsg (1,"TransListen: unable to find transport: %s\n",
+ protocol);
+
+ return -1;
+ }
+ if (trans->flags & TRANS_ALIAS) {
+ if (trans->nolisten)
+ while (trans->nolisten[i]) {
+ ret |= TRANS(Listen)(trans->nolisten[i]);
+ i++;
+ }
+ }
+
+ trans->flags &= ~TRANS_NOLISTEN;
+ return ret;
+}
+
+int
+TRANS(IsListening) (const char * protocol)
+{
+ Xtransport *trans;
+
+ if ((trans = TRANS(SelectTransport)(protocol)) == NULL)
+ {
+ prmsg (1,"TransIsListening: unable to find transport: %s\n",
+ protocol);
+
+ return 0;
+ }
+
+ return !(trans->flags & TRANS_NOLISTEN);
+}
+
+int
TRANS(ResetListener) (XtransConnInfo ciptr)
{
@@ -819,7 +813,7 @@ TRANS(Accept) (XtransConnInfo ciptr, int *status)
{
XtransConnInfo newciptr;
- PRMSG (2,"Accept(%d)\n", ciptr->fd, 0, 0);
+ prmsg (2,"Accept(%d)\n", ciptr->fd);
newciptr = ciptr->transptr->Accept (ciptr, status);
@@ -835,7 +829,7 @@ TRANS(Accept) (XtransConnInfo ciptr, int *status)
#ifdef TRANS_CLIENT
int
-TRANS(Connect) (XtransConnInfo ciptr, char *address)
+TRANS(Connect) (XtransConnInfo ciptr, const char *address)
{
char *protocol;
@@ -843,19 +837,23 @@ TRANS(Connect) (XtransConnInfo ciptr, char *address)
char *port;
int ret;
- PRMSG (2,"Connect(%d,%s)\n", ciptr->fd, address, 0);
+ prmsg (2,"Connect(%d,%s)\n", ciptr->fd, address);
if (TRANS(ParseAddress) (address, &protocol, &host, &port) == 0)
{
- PRMSG (1,"Connect: Unable to Parse address %s\n",
- address, 0, 0);
+ prmsg (1,"Connect: Unable to Parse address %s\n",
+ address);
return -1;
}
+#ifdef HAVE_LAUNCHD
+ if (!host) host=strdup("");
+#endif
+
if (!port || !*port)
{
- PRMSG (1,"Connect: Missing port specification in %s\n",
- address, 0, 0);
+ prmsg (1,"Connect: Missing port specification in %s\n",
+ address);
if (protocol) free (protocol);
if (host) free (host);
return -1;
@@ -866,7 +864,7 @@ TRANS(Connect) (XtransConnInfo ciptr, char *address)
if (protocol) free (protocol);
if (host) free (host);
if (port) free (port);
-
+
return ret;
}
@@ -908,6 +906,20 @@ TRANS(Writev) (XtransConnInfo ciptr, struct iovec *buf, int size)
return ciptr->transptr->Writev (ciptr, buf, size);
}
+#if XTRANS_SEND_FDS
+int
+TRANS(SendFd) (XtransConnInfo ciptr, int fd, int do_close)
+{
+ return ciptr->transptr->SendFd(ciptr, fd, do_close);
+}
+
+int
+TRANS(RecvFd) (XtransConnInfo ciptr)
+{
+ return ciptr->transptr->RecvFd(ciptr);
+}
+#endif
+
int
TRANS(Disconnect) (XtransConnInfo ciptr)
@@ -921,7 +933,7 @@ TRANS(Close) (XtransConnInfo ciptr)
{
int ret;
- PRMSG (2,"Close(%d)\n", ciptr->fd, 0, 0);
+ prmsg (2,"Close(%d)\n", ciptr->fd);
ret = ciptr->transptr->Close (ciptr);
@@ -936,7 +948,7 @@ TRANS(CloseForCloning) (XtransConnInfo ciptr)
{
int ret;
- PRMSG (2,"CloseForCloning(%d)\n", ciptr->fd, 0, 0);
+ prmsg (2,"CloseForCloning(%d)\n", ciptr->fd);
ret = ciptr->transptr->CloseForCloning (ciptr);
@@ -952,40 +964,42 @@ TRANS(IsLocal) (XtransConnInfo ciptr)
return (ciptr->family == AF_UNIX);
}
-
+#ifdef NX_TRANS_SOCKET
+/* this is needed for pre-xcb X11 as we have in NX */
int
-TRANS(GetMyAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp,
- Xtransaddr **addrp)
+TRANS(GetMyAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp,
+ Xtransaddr **addrp)
{
- PRMSG (2,"GetMyAddr(%d)\n", ciptr->fd, 0, 0);
+ prmsg (2,"GetMyAddr(%d)\n", ciptr->fd);
*familyp = ciptr->family;
*addrlenp = ciptr->addrlen;
if ((*addrp = (Xtransaddr *) malloc (ciptr->addrlen)) == NULL)
{
- PRMSG (1,"GetMyAddr: malloc failed\n", 0, 0, 0);
- return -1;
+ prmsg (1,"GetMyAddr: malloc failed\n");
+ return -1;
}
memcpy(*addrp, ciptr->addr, ciptr->addrlen);
return 0;
}
+#endif
int
-TRANS(GetPeerAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp,
+TRANS(GetPeerAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp,
Xtransaddr **addrp)
{
- PRMSG (2,"GetPeerAddr(%d)\n", ciptr->fd, 0, 0);
+ prmsg (2,"GetPeerAddr(%d)\n", ciptr->fd);
*familyp = ciptr->family;
*addrlenp = ciptr->peeraddrlen;
- if ((*addrp = (Xtransaddr *) malloc (ciptr->peeraddrlen)) == NULL)
+ if ((*addrp = malloc (ciptr->peeraddrlen)) == NULL)
{
- PRMSG (1,"GetPeerAddr: malloc failed\n", 0, 0, 0);
+ prmsg (1,"GetPeerAddr: malloc failed\n");
return -1;
}
memcpy(*addrp, ciptr->peeraddr, ciptr->peeraddrlen);
@@ -1038,45 +1052,138 @@ complete_network_count (void)
}
+static int
+receive_listening_fds(const char* port, XtransConnInfo* temp_ciptrs,
+ int* count_ret)
+
+{
+#ifdef HAVE_SYSTEMD_DAEMON
+ XtransConnInfo ciptr;
+ int i, systemd_listen_fds;
+
+ systemd_listen_fds = sd_listen_fds(1);
+ if (systemd_listen_fds < 0)
+ {
+ prmsg (1, "receive_listening_fds: sd_listen_fds error: %s\n",
+ strerror(-systemd_listen_fds));
+ return -1;
+ }
+
+ for (i = 0; i < systemd_listen_fds && *count_ret < NUMTRANS; i++)
+ {
+ struct sockaddr_storage a;
+ int ti;
+ const char* tn;
+ socklen_t al;
+
+ al = sizeof(a);
+ if (getsockname(i + SD_LISTEN_FDS_START, (struct sockaddr*)&a, &al) < 0) {
+ prmsg (1, "receive_listening_fds: getsockname error: %s\n",
+ strerror(errno));
+ return -1;
+ }
+
+ switch (a.ss_family)
+ {
+ case AF_UNIX:
+ ti = TRANS_SOCKET_UNIX_INDEX;
+ if (*((struct sockaddr_un*)&a)->sun_path == '\0' &&
+ al > sizeof(sa_family_t))
+ tn = "local";
+ else
+ tn = "unix";
+ break;
+ case AF_INET:
+ ti = TRANS_SOCKET_INET_INDEX;
+ tn = "inet";
+ break;
+#if defined(IPv6) && defined(AF_INET6)
+ case AF_INET6:
+ ti = TRANS_SOCKET_INET6_INDEX;
+ tn = "inet6";
+ break;
+#endif /* IPv6 */
+ default:
+ prmsg (1, "receive_listening_fds:"
+ "Got unknown socket address family\n");
+ return -1;
+ }
+
+ ciptr = TRANS(ReopenCOTSServer)(ti, i + SD_LISTEN_FDS_START, port);
+ if (!ciptr)
+ {
+ prmsg (1, "receive_listening_fds:"
+ "Got NULL while trying to reopen socket received from systemd.\n");
+ return -1;
+ }
+
+ prmsg (5, "receive_listening_fds: received listener for %s, %d\n",
+ tn, ciptr->fd);
+ temp_ciptrs[(*count_ret)++] = ciptr;
+ TRANS(Received)(tn);
+ }
+#endif /* HAVE_SYSTEMD_DAEMON */
+ return 0;
+}
+
+#ifdef XQUARTZ_EXPORTS_LAUNCHD_FD
+extern int xquartz_launchd_fd;
+#endif
int
-TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret,
- XtransConnInfo **ciptrs_ret)
+TRANS(MakeAllCOTSServerListeners) (const char *port, int *partial,
+ int *count_ret, XtransConnInfo **ciptrs_ret)
{
char buffer[256]; /* ??? What size ?? */
XtransConnInfo ciptr, temp_ciptrs[NUMTRANS];
int status, i, j;
+
#if defined(IPv6) && defined(AF_INET6)
int ipv6_succ = 0;
#endif
-
- PRMSG (2,"MakeAllCOTSServerListeners(%s,%p)\n",
- port ? port : "NULL", ciptrs_ret, 0);
+ prmsg (2,"MakeAllCOTSServerListeners(%s,%p)\n",
+ port ? port : "NULL", ciptrs_ret);
*count_ret = 0;
+#ifdef XQUARTZ_EXPORTS_LAUNCHD_FD
+ fprintf(stderr, "Launchd socket fd: %d\n", xquartz_launchd_fd);
+ if(xquartz_launchd_fd != -1) {
+ if((ciptr = TRANS(ReopenCOTSServer(TRANS_SOCKET_LOCAL_INDEX,
+ xquartz_launchd_fd, getenv("DISPLAY"))))==NULL)
+ fprintf(stderr,"Got NULL while trying to Reopen launchd port\n");
+ else
+ temp_ciptrs[(*count_ret)++] = ciptr;
+ }
+#endif
+
+ if (receive_listening_fds(port, temp_ciptrs, count_ret) < 0)
+ return -1;
+
for (i = 0; i < NUMTRANS; i++)
{
Xtransport *trans = Xtransports[i].transport;
unsigned int flags = 0;
- if (trans->flags&TRANS_ALIAS || trans->flags&TRANS_NOLISTEN)
+ if (trans->flags&TRANS_ALIAS || trans->flags&TRANS_NOLISTEN ||
+ trans->flags&TRANS_RECEIVED)
continue;
- sprintf(buffer,"%s/:%s", trans->TransName, port ? port : "");
+ snprintf(buffer, sizeof(buffer), "%s/:%s",
+ trans->TransName, port ? port : "");
- PRMSG (5,"MakeAllCOTSServerListeners: opening %s\n",
- buffer, 0, 0);
+ prmsg (5,"MakeAllCOTSServerListeners: opening %s\n",
+ buffer);
if ((ciptr = TRANS(OpenCOTSServer(buffer))) == NULL)
{
if (trans->flags & TRANS_DISABLED)
continue;
- PRMSG (1,
+ prmsg (1,
"MakeAllCOTSServerListeners: failed to open listener for %s\n",
- trans->TransName, 0, 0);
+ trans->TransName);
continue;
}
#if defined(IPv6) && defined(AF_INET6)
@@ -1095,9 +1202,8 @@ TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret,
* running at this address, and this function should fail.
*/
- PRMSG (1,
- "MakeAllCOTSServerListeners: server already running\n",
- 0, 0, 0);
+ prmsg (1,
+ "MakeAllCOTSServerListeners: server already running\n");
for (j = 0; j < *count_ret; j++)
TRANS(Close) (temp_ciptrs[j]);
@@ -1109,9 +1215,9 @@ TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret,
}
else
{
- PRMSG (1,
+ prmsg (1,
"MakeAllCOTSServerListeners: failed to create listener for %s\n",
- trans->TransName, 0, 0);
+ trans->TransName);
continue;
}
@@ -1121,10 +1227,10 @@ TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret,
if (Xtransports[i].transport_id == TRANS_SOCKET_INET6_INDEX)
ipv6_succ = 1;
#endif
-
- PRMSG (5,
+
+ prmsg (5,
"MakeAllCOTSServerListeners: opened listener for %s, %d\n",
- trans->TransName, ciptr->fd, 0);
+ trans->TransName, ciptr->fd);
temp_ciptrs[*count_ret] = ciptr;
(*count_ret)++;
@@ -1132,13 +1238,13 @@ TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret,
*partial = (*count_ret < complete_network_count());
- PRMSG (5,
+ prmsg (5,
"MakeAllCOTSServerListeners: partial=%d, actual=%d, complete=%d \n",
*partial, *count_ret, complete_network_count());
if (*count_ret > 0)
{
- if ((*ciptrs_ret = (XtransConnInfo *) malloc (
+ if ((*ciptrs_ret = malloc (
*count_ret * sizeof (XtransConnInfo))) == NULL)
{
return -1;
@@ -1151,105 +1257,7 @@ TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret,
}
else
*ciptrs_ret = NULL;
-
- return 0;
-}
-
-int
-TRANS(MakeAllCLTSServerListeners) (char *port, int *partial, int *count_ret,
- XtransConnInfo **ciptrs_ret)
-
-{
- char buffer[256]; /* ??? What size ?? */
- XtransConnInfo ciptr, temp_ciptrs[NUMTRANS];
- int status, i, j;
-
- PRMSG (2,"MakeAllCLTSServerListeners(%s,%p)\n",
- port ? port : "NULL", ciptrs_ret, 0);
-
- *count_ret = 0;
-
- for (i = 0; i < NUMTRANS; i++)
- {
- Xtransport *trans = Xtransports[i].transport;
-
- if (trans->flags&TRANS_ALIAS || trans->flags&TRANS_NOLISTEN)
- continue;
-
- sprintf(buffer,"%s/:%s", trans->TransName, port ? port : "");
- PRMSG (5,"MakeAllCLTSServerListeners: opening %s\n",
- buffer, 0, 0);
-
- if ((ciptr = TRANS(OpenCLTSServer (buffer))) == NULL)
- {
- PRMSG (1,
- "MakeAllCLTSServerListeners: failed to open listener for %s\n",
- trans->TransName, 0, 0);
- continue;
- }
-
- if ((status = TRANS(CreateListener (ciptr, port, 0))) < 0)
- {
- if (status == TRANS_ADDR_IN_USE)
- {
- /*
- * We failed to bind to the specified address because the
- * address is in use. It must be that a server is already
- * running at this address, and this function should fail.
- */
-
- PRMSG (1,
- "MakeAllCLTSServerListeners: server already running\n",
- 0, 0, 0);
-
- for (j = 0; j < *count_ret; j++)
- TRANS(Close) (temp_ciptrs[j]);
-
- *count_ret = 0;
- *ciptrs_ret = NULL;
- *partial = 0;
- return -1;
- }
- else
- {
- PRMSG (1,
- "MakeAllCLTSServerListeners: failed to create listener for %s\n",
- trans->TransName, 0, 0);
-
- continue;
- }
- }
-
- PRMSG (5,
- "MakeAllCLTSServerListeners: opened listener for %s, %d\n",
- trans->TransName, ciptr->fd, 0);
- temp_ciptrs[*count_ret] = ciptr;
- (*count_ret)++;
- }
-
- *partial = (*count_ret < complete_network_count());
-
- PRMSG (5,
- "MakeAllCLTSServerListeners: partial=%d, actual=%d, complete=%d \n",
- *partial, *count_ret, complete_network_count());
-
- if (*count_ret > 0)
- {
- if ((*ciptrs_ret = (XtransConnInfo *) malloc (
- *count_ret * sizeof (XtransConnInfo))) == NULL)
- {
- return -1;
- }
-
- for (i = 0; i < *count_ret; i++)
- {
- (*ciptrs_ret)[i] = temp_ciptrs[i];
- }
- }
- else
- *ciptrs_ret = NULL;
-
return 0;
}
@@ -1262,7 +1270,8 @@ TRANS(MakeAllCLTSServerListeners) (char *port, int *partial, int *count_ret,
* may be used by it.
*/
-#if (defined(SYSV) && defined(i386) && !defined(__SCO__)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__)
+
+#ifdef WIN32
/*
* emulate readv
@@ -1292,9 +1301,6 @@ static int TRANS(ReadV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt)
return total;
}
-#endif /* SYSV && i386 || WIN32 || __sxg__ */
-
-#if (defined(SYSV) && defined(i386) && !defined(__SCO__)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__)
/*
* emulate writev
@@ -1324,10 +1330,10 @@ static int TRANS(WriteV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt)
return total;
}
-#endif /* SYSV && i386 || WIN32 || __sxg__ */
+#endif /* WIN32 */
-#if (defined(_POSIX_SOURCE) && !defined(AIXV3) && !defined(__QNX__)) || defined(hpux) || defined(USG) || defined(SVR4) || defined(__SCO__)
+#if defined(_POSIX_SOURCE) || defined(USG) || defined(SVR4) || defined(__SVR4) || defined(__SCO__)
#ifndef NEED_UTSNAME
#define NEED_UTSNAME
#endif
diff --git a/nx-X11/lib/xtrans/Xtrans.h b/nx-X11/lib/xtrans/Xtrans.h
index 04f4138dd..54b2a1425 100644
--- a/nx-X11/lib/xtrans/Xtrans.h
+++ b/nx-X11/lib/xtrans/Xtrans.h
@@ -24,9 +24,7 @@ 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.
-*/
-
-/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
*
* All Rights Reserved
*
@@ -54,121 +52,75 @@ from The Open Group.
#include <nx-X11/Xfuncproto.h>
#include <nx-X11/Xos.h>
+#include <nx-X11/Xmd.h>
#ifndef WIN32
-#ifndef Lynx
#include <sys/socket.h>
-#else
-#include <socket.h>
-#endif
#endif
+#ifdef __clang__
+/* Not all clients make use of all provided statics */
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunused-function"
+#endif
/*
* Set the functions names according to where this code is being compiled.
*/
#ifdef X11_t
-#if !defined(UNIXCPP) || defined(ANSICPP)
#define TRANS(func) _X11Trans##func
-#else
-#define TRANS(func) _X11Trans/**/func
-#endif
#ifdef XTRANSDEBUG
-static char* __xtransname = "_X11Trans";
+static const char *__xtransname = "_X11Trans";
#endif
#endif /* X11_t */
#ifdef XSERV_t
-#if !defined(UNIXCPP) || defined(ANSICPP)
#define TRANS(func) _XSERVTrans##func
-#else
-#define TRANS(func) _XSERVTrans/**/func
-#endif
#ifdef XTRANSDEBUG
-static char* __xtransname = "_XSERVTrans";
+static const char *__xtransname = "_XSERVTrans";
#endif
#define X11_t
#endif /* XSERV_t */
#ifdef XIM_t
-#if !defined(UNIXCPP) || defined(ANSICPP)
#define TRANS(func) _XimXTrans##func
-#else
-#define TRANS(func) _XimXTrans/**/func
-#endif
#ifdef XTRANSDEBUG
-static char* __xtransname = "_XimTrans";
+static const char *__xtransname = "_XimTrans";
#endif
#endif /* XIM_t */
#ifdef FS_t
-#if !defined(UNIXCPP) || defined(ANSICPP)
#define TRANS(func) _FSTrans##func
-#else
-#define TRANS(func) _FSTrans/**/func
-#endif
#ifdef XTRANSDEBUG
-static char* __xtransname = "_FSTrans";
+static const char *__xtransname = "_FSTrans";
#endif
#endif /* FS_t */
#ifdef FONT_t
-#if !defined(UNIXCPP) || defined(ANSICPP)
#define TRANS(func) _FontTrans##func
-#else
-#define TRANS(func) _FontTrans/**/func
-#endif
#ifdef XTRANSDEBUG
-static char* __xtransname = "_FontTrans";
+static const char *__xtransname = "_FontTrans";
#endif
#endif /* FONT_t */
#ifdef ICE_t
-#if !defined(UNIXCPP) || defined(ANSICPP)
#define TRANS(func) _IceTrans##func
-#else
-#define TRANS(func) _IceTrans/**/func
-#endif
#ifdef XTRANSDEBUG
-static char* __xtransname = "_IceTrans";
+static const char *__xtransname = "_IceTrans";
#endif
#endif /* ICE_t */
-#ifdef TEST_t
-#if !defined(UNIXCPP) || defined(ANSICPP)
-#define TRANS(func) _TESTTrans##func
-#else
-#define TRANS(func) _TESTTrans/**/func
-#endif
-#ifdef XTRANSDEBUG
-static char* __xtransname = "_TESTTrans";
-#endif
-#endif /* TEST_t */
-
-#ifdef LBXPROXY_t
-#if !defined(UNIXCPP) || defined(ANSICPP)
-#define TRANS(func) _LBXPROXYTrans##func
-#else
-#define TRANS(func) _LBXPROXYTrans/**/func
-#endif
-#define X11_t /* The server defines this - so should the LBX proxy */
-#ifdef XTRANSDEBUG
-static char* __xtransname = "_LBXPROXYTrans";
-#endif
-#endif /* LBXPROXY_t */
-
#if !defined(TRANS)
-#if !defined(UNIXCPP) || defined(ANSICPP)
#define TRANS(func) _XTrans##func
-#else
-#define TRANS(func) _XTrans/**/func
-#endif
#ifdef XTRANSDEBUG
-static char* __xtransname = "_XTrans";
+static const char *__xtransname = "_XTrans";
#endif
#endif /* !TRANS */
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
/*
* Create a single address structure that can be used wherever
@@ -196,7 +148,7 @@ typedef long BytesReadable_t;
#endif
-#if defined(WIN32) || (defined(USG) && !defined(umips) && !defined(MOTOROLA) && !defined(uniosu) && !defined(__sxg__))
+#if defined(WIN32) || defined(USG)
/*
* TRANS(Readv) and TRANS(Writev) use struct iovec, normally found
@@ -210,11 +162,7 @@ struct iovec {
};
#else
-#ifndef Lynx
#include <sys/uio.h>
-#else
-#include <uio.h>
-#endif
#endif
typedef struct _XtransConnInfo *XtransConnInfo;
@@ -274,7 +222,7 @@ void TRANS(FreeConnInfo) (
#ifdef TRANS_CLIENT
XtransConnInfo TRANS(OpenCOTSClient)(
- char * /* address */
+ const char * /* address */
);
#endif /* TRANS_CLIENT */
@@ -282,23 +230,7 @@ XtransConnInfo TRANS(OpenCOTSClient)(
#ifdef TRANS_SERVER
XtransConnInfo TRANS(OpenCOTSServer)(
- char * /* address */
-);
-
-#endif /* TRANS_SERVER */
-
-#ifdef TRANS_CLIENT
-
-XtransConnInfo TRANS(OpenCLTSClient)(
- char * /* address */
-);
-
-#endif /* TRANS_CLIENT */
-
-#ifdef TRANS_SERVER
-
-XtransConnInfo TRANS(OpenCLTSServer)(
- char * /* address */
+ const char * /* address */
);
#endif /* TRANS_SERVER */
@@ -308,13 +240,7 @@ XtransConnInfo TRANS(OpenCLTSServer)(
XtransConnInfo TRANS(ReopenCOTSServer)(
int, /* trans_id */
int, /* fd */
- char * /* port */
-);
-
-XtransConnInfo TRANS(ReopenCLTSServer)(
- int, /* trans_id */
- int, /* fd */
- char * /* port */
+ const char * /* port */
);
int TRANS(GetReopenInfo)(
@@ -337,12 +263,24 @@ int TRANS(SetOption)(
int TRANS(CreateListener)(
XtransConnInfo, /* ciptr */
- char *, /* port */
+ const char *, /* port */
unsigned int /* flags */
);
+int TRANS(Received) (
+ const char* /* protocol*/
+);
+
int TRANS(NoListen) (
- char* /* protocol*/
+ const char* /* protocol*/
+);
+
+int TRANS(Listen) (
+ const char* /* protocol*/
+);
+
+int TRANS(IsListening) (
+ const char* /* protocol*/
);
int TRANS(ResetListener)(
@@ -360,7 +298,7 @@ XtransConnInfo TRANS(Accept)(
int TRANS(Connect)(
XtransConnInfo, /* ciptr */
- char * /* address */
+ const char * /* address */
);
#endif /* TRANS_CLIENT */
@@ -394,6 +332,10 @@ int TRANS(Writev)(
int /* size */
);
+int TRANS(SendFd) (XtransConnInfo ciptr, int fd, int do_close);
+
+int TRANS(RecvFd) (XtransConnInfo ciptr);
+
int TRANS(Disconnect)(
XtransConnInfo /* ciptr */
);
@@ -410,12 +352,15 @@ int TRANS(IsLocal)(
XtransConnInfo /* ciptr */
);
+#ifdef NX_TRANS_SOCKET
+/* needed for pre-xcb libX11 as we have in NX */
int TRANS(GetMyAddr)(
- XtransConnInfo, /* ciptr */
- int *, /* familyp */
- int *, /* addrlenp */
- Xtransaddr ** /* addrp */
+ XtransConnInfo, /* ciptr */
+ int *, /* familyp */
+ int *, /* addrlenp */
+ Xtransaddr ** /* addrp */
);
+#endif
int TRANS(GetPeerAddr)(
XtransConnInfo, /* ciptr */
@@ -431,14 +376,7 @@ int TRANS(GetConnectionNumber)(
#ifdef TRANS_SERVER
int TRANS(MakeAllCOTSServerListeners)(
- char *, /* port */
- int *, /* partial */
- int *, /* count_ret */
- XtransConnInfo ** /* ciptrs_ret */
-);
-
-int TRANS(MakeAllCLTSServerListeners)(
- char *, /* port */
+ const char *, /* port */
int *, /* partial */
int *, /* count_ret */
XtransConnInfo ** /* ciptrs_ret */
@@ -475,13 +413,13 @@ TRANS(GetPeerNetworkId)(
#endif /* ICE_t */
-int
+int
TRANS(GetHostname) (
char * /* buf */,
int /* maxlen */
);
-#if defined(WIN32) && (defined(TCPCONN) || defined(DNETCONN))
+#if defined(WIN32) && defined(TCPCONN)
int TRANS(WSAStartup)();
#endif
diff --git a/nx-X11/lib/xtrans/Xtransdnet.c b/nx-X11/lib/xtrans/Xtransdnet.c
deleted file mode 100644
index a4abf42a4..000000000
--- a/nx-X11/lib/xtrans/Xtransdnet.c
+++ /dev/null
@@ -1,666 +0,0 @@
-/*
-
-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.
-
-*/
-
-/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
- *
- * 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 and 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.
- */
-
-#ifndef WIN32
-#include <netdnet/dn.h>
-#include <netdnet/dnetdb.h>
-#include <sys/ioctl.h>
-#endif /* !WIN32 */
-
-#include <stdio.h>
-
-#ifdef WIN32
-#define _WILLWINSOCK_
-#define BOOL wBOOL
-#undef Status
-#define Status wStatus
-#include <prgpre.h> /* PATHWORKS header normally in %MSTOOLS%\h\pathwork */
-#undef Status
-#define Status int
-#undef BOOL
-#include <nx-X11/Xw32defs.h>
-#undef close
-#define close closesocket
-#endif /* WIN32 */
-
-
-#if defined(X11_t)
-#define DNETOBJ "X$X"
-#endif
-#if defined(XIM_t)
-#define DNETOBJ "IMSERVER$"
-#endif
-#if defined(FS_t) || defined(FONT_t)
-#define DNETOBJ "X$FONT"
-#endif
-#if defined(ICE_t)
-#define DNETOBJ ""
-#endif
-#if defined(TEST_t)
-#define DNETOBJ "X$TEST"
-#endif
-
-
-/*
- * This is the DNET implementation of the X Transport service layer
- */
-
-/*
- * This function gets the local address of the socket and stores it in the
- * XtransConnInfo structure for the connection.
- */
-
-static int
-TRANS(DNETGetAddr) (XtransConnInfo ciptr)
-
-{
- struct sockaddr_dn sockname;
- int namelen = sizeof(sockname);
-
- PRMSG (3,"DNETGetAddr(%x)\n", ciptr, 0, 0);
-
- if (getsockname (ciptr->fd, (struct sockaddr *) &sockname, &namelen) < 0)
- {
- PRMSG (1,"DNETGetAddr: getsockname() failed: %d\n",
- EGET(), 0, 0);
- return -1;
- }
-
-
- /*
- * Everything looks good: fill in the XtransConnInfo structure.
- */
-
- if ((ciptr->addr = (char *) malloc (namelen)) == NULL)
- {
- PRMSG (1, "DNETGetAddr: Can't allocate space for the addr\n",
- 0, 0, 0);
- return -1;
- }
-
- ciptr->family = sockname.sdn_family;
- ciptr->addrlen = namelen;
- memcpy (ciptr->addr, &sockname, ciptr->addrlen);
-
- return 0;
-}
-
-
-/*
- * This function gets the remote address of the socket and stores it in the
- * XtransConnInfo structure for the connection.
- */
-
-static int
-TRANS(DNETGetPeerAddr) (XtransConnInfo ciptr)
-
-{
- struct sockaddr_dn sockname;
- int namelen = sizeof(sockname);
-
- PRMSG (3,"DNETGetPeerAddr(%x)\n", ciptr, 0, 0);
-
- if (getpeername (ciptr->fd, (struct sockaddr *) &sockname, &namelen) < 0)
- {
- PRMSG (1,"DNETGetPeerAddr: getpeername() failed: %d\n",
- EGET(), 0, 0);
- return -1;
- }
-
- /*
- * Everything looks good: fill in the XtransConnInfo structure.
- */
-
- if ((ciptr->peeraddr = (char *) malloc (namelen)) == NULL)
- {
- PRMSG (1,
- "DNETGetPeerAddr: Can't allocate space for the addr\n",
- 0, 0, 0);
- return -1;
- }
-
- ciptr->peeraddrlen = namelen;
- memcpy (ciptr->peeraddr, &sockname, ciptr->peeraddrlen);
-
- return 0;
-}
-
-
-#ifdef TRANS_CLIENT
-
-static XtransConnInfo
-TRANS(DNETOpenCOTSClient) (Xtransport *thistrans, char *protocol,
- char *host, char *port)
-
-{
- XtransConnInfo ciptr;
-
- PRMSG (2,"DNETOpenCOTSClient(%s,%s,%s)\n", protocol, host, port);
-
- if ((ciptr = (XtransConnInfo) calloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
- {
- PRMSG (1, "DNETOpenCOTSClient: malloc failed\n", 0, 0, 0);
- return NULL;
- }
-
- ciptr->index = 0; /* only one form of DECnet */
-
- /* nothing else to do here */
-
- return ciptr;
-}
-
-#endif /* TRANS_CLIENT */
-
-
-#ifdef TRANS_SERVER
-
-static XtransConnInfo
-TRANS(DNETOpenCOTSServer) (Xtransport *thistrans, char *protocol,
- char *host, char *port)
-
-{
- XtransConnInfo ciptr;
-
- PRMSG (2,"DNETOpenCOTSServer(%s,%s,%s)\n", protocol, host, port);
-
- if ((ciptr = (XtransConnInfo) calloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
- {
- PRMSG (1, "DNETOpenCOTSServer: malloc failed\n", 0, 0, 0);
- return NULL;
- }
-
- if ((ciptr->fd = socket (AF_DECnet, SOCK_STREAM, 0)) < 0)
- {
- free ((char *) ciptr);
- return NULL;
- }
-
- ciptr->index = 0; /* only one form of DECnet */
-
- return (ciptr);
-}
-
-#endif /* TRANS_SERVER */
-
-
-#ifdef TRANS_CLIENT
-
-static XtransConnInfo
-TRANS(DNETOpenCLTSClient) (Xtransport *thistrans, char *protocol,
- char *host, char *port)
-
-{
- XtransConnInfo ciptr;
-
- PRMSG (2,"DNETOpenCLTSClient(%s,%s,%s)\n", protocol, host, port);
-
- if ((ciptr = (XtransConnInfo) calloc (
- 1, sizeof (struct _XtransConnInfo))) == NULL)
- {
- PRMSG (1, "DNETOpenCLTSClient: malloc failed\n", 0, 0, 0);
- return NULL;
- }
-
- ciptr->index = 0; /* only one form of DECnet */
-
- /* nothing else to do here */
-
- return ciptr;
-}
-
-#endif /* TRANS_CLIENT */
-
-
-#ifdef TRANS_SERVER
-
-static XtransConnInfo
-TRANS(DNETOpenCLTSServer) (Xtransport *thistrans, char *protocol,
- char *host, char *port)
-
-{
- /* NEED TO IMPLEMENT */
-
- PRMSG (2,"DNETOpenCLTSServer(%s,%s,%s)\n", protocol, host, port);
- return NULL;
-}
-
-#endif /* TRANS_SERVER */
-
-
-#ifdef TRANS_REOPEN
-
-static XtransConnInfo
-TRANS(DNETReopenCOTSServer) (Xtransport *thistrans, int fd, char *port)
-
-{
- XtransConnInfo ciptr;
-
- PRMSG (2,"DNETReopenCOTSServer(%d,%s)\n", fd, port, 0);
-
- if ((ciptr = (XtransConnInfo) calloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
- {
- PRMSG (1, "DNETReopenCOTSServer: malloc failed\n", 0, 0, 0);
- return NULL;
- }
-
- ciptr->fd = fd;
- ciptr->index = 0; /* only one form of DECnet */
-
- return (ciptr);
-}
-
-static XtransConnInfo
-TRANS(DNETReopenCLTSServer) (Xtransport *thistrans, int fd, char *port)
-
-{
- XtransConnInfo ciptr;
-
- PRMSG (2,"DNETReopenCLTSServer(%d,%s)\n", fd, port, 0);
-
- if ((ciptr = (XtransConnInfo) calloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
- {
- PRMSG (1, "DNETReopenCLTSServer: malloc failed\n", 0, 0, 0);
- return NULL;
- }
-
- ciptr->fd = fd;
- ciptr->index = 0; /* only one form of DECnet */
-
- return (ciptr);
-}
-
-#endif /* TRANS_REOPEN */
-
-
-static int
-TRANS(DNETSetOption) (XtransConnInfo ciptr, int option, int arg)
-
-{
- PRMSG (2,"DNETSetOption(%d,%d,%d)\n", ciptr->fd, option, arg);
-
- return -1;
-}
-
-
-#ifdef TRANS_SERVER
-
-static int
-TRANS(DNETCreateListener) (XtransConnInfo ciptr, char *port, unsigned int flags)
-
-{
- struct sockaddr_dn dnsock;
- int fd = ciptr->fd;
-
- PRMSG (3, "DNETCreateListener(%x,%d)\n", ciptr, fd, 0);
-
- bzero ((char *) &dnsock, sizeof (dnsock));
- dnsock.sdn_family = AF_DECnet;
-
- if (port && *port )
- sprintf (dnsock.sdn_objname, "%s%s", DNETOBJ, port);
- else
-#ifdef X11_t
- return -1;
-#else
- sprintf (dnsock.sdn_objname, "%s%d", DNETOBJ, getpid ());
-#endif
-
- dnsock.sdn_objnamel = strlen (dnsock.sdn_objname);
-
- if (bind (fd, (struct sockaddr *) &dnsock, sizeof (dnsock)))
- {
- close (fd);
- return -1;
- }
-
- if (listen (fd, 5))
- {
- close (fd);
- return (-1);
- }
-
-
- /* Set a flag to indicate that this connection is a listener */
-
- ciptr->flags = 1 | (ciptr->flags & TRANS_KEEPFLAGS);
-
- return 0;
-}
-
-
-static XtransConnInfo
-TRANS(DNETAccept) (XtransConnInfo ciptr, int *status)
-
-{
- XtransConnInfo newciptr;
- struct sockaddr_dn sockname;
- int namelen = sizeof(sockname);
-
- PRMSG (2, "DNETAccept(%x,%d)\n", ciptr, ciptr->fd, 0);
-
- if ((newciptr = (XtransConnInfo) calloc(
- 1, sizeof (struct _XtransConnInfo))) == NULL)
- {
- PRMSG (1, "DNETAccept: malloc failed\n", 0, 0, 0);
- *status = TRANS_ACCEPT_BAD_MALLOC;
- return NULL;
- }
-
- if((newciptr->fd = accept (ciptr->fd,
- (struct sockaddr *) &sockname, &namelen)) < 0)
- {
- PRMSG (1, "DNETAccept: accept() failed\n", 0, 0, 0);
-
- free (newciptr);
- *status = TRANS_ACCEPT_FAILED;
- return NULL;
- }
-
- /*
- * Get this address again because the transport may give a more
- * specific address now that a connection is established.
- */
-
- if (TRANS(DNETGetAddr) (newciptr) < 0)
- {
- PRMSG(1,
- "DNETAccept: ...DNETGetAddr() failed:\n", 0, 0, 0);
- close (newciptr->fd);
- free (newciptr);
- *status = TRANS_ACCEPT_MISC_ERROR;
- return NULL;
- }
-
- if (TRANS(DNETGetPeerAddr) (newciptr) < 0)
- {
- PRMSG(1,
- "DNETAccept: ...DNETGetPeerAddr() failed:\n", 0, 0, 0);
-
- close (newciptr->fd);
- if (newciptr->addr) free (newciptr->addr);
- free (newciptr);
- *status = TRANS_ACCEPT_MISC_ERROR;
- return NULL;
- }
-
- *status = 0;
-
- return newciptr;
-}
-
-#endif /* TRANS_SERVER */
-
-
-#ifdef TRANS_CLIENT
-
-#define OBJBUFSIZE 64
-
-static int
-TRANS(DNETConnect) (XtransConnInfo ciptr, char *host, char *port)
-
-{
- char objname[OBJBUFSIZE];
-
- extern int dnet_conn();
-
- PRMSG (2,"DNETConnect(%d,%s,%s)\n", ciptr->fd, host, port);
-
-#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().
- */
-
- if (is_numeric (port))
- {
- short tmpport = (short) atoi (port);
-
- sprintf (objname, "X$X%d", tmpport);
- }
- else
-#endif
- strncpy(objname, port, OBJBUFSIZE);
-
-
- /*
- * Do the connect
- */
-
- if (!host) host = "0";
-
- if ((ciptr->fd = dnet_conn (host, objname, SOCK_STREAM, 0, 0, 0, 0)) < 0)
- {
- return TRANS_CONNECT_FAILED;
- }
-
-
- /*
- * Sync up the address fields of ciptr.
- */
-
- if (TRANS(DNETGetAddr) (ciptr) < 0)
- {
- PRMSG (1,
- "DNETConnect: ...DNETGetAddr() failed:\n", 0, 0, 0);
- return TRANS_CONNECT_FAILED;
- }
-
- if (TRANS(DNETGetPeerAddr) (ciptr) < 0)
- {
- PRMSG (1,
- "DNETConnect: ...DNETGetPeerAddr() failed:\n",
- 0, 0, 0);
- return TRANS_CONNECT_FAILED;
- }
-
- return 0;
-}
-
-#endif /* TRANS_CLIENT */
-
-
-static int
-TRANS(DNETBytesReadable) (XtransConnInfo ciptr, BytesReadable_t *pend)
-
-{
- PRMSG (2,"DNETBytesReadable(%x,%d,%x)\n", ciptr, ciptr->fd, pend);
-
-#ifdef WIN32
- {
- int ret = ioctlsocket ((SOCKET) ciptr->fd, FIONREAD, (u_long *) pend);
- errno = WSAGetLastError();
- return ret;
- }
-#else
- return ioctl(ciptr->fd, FIONREAD, (char *)pend);
-#endif /* WIN32 */
-}
-
-
-static int
-TRANS(DNETRead) (XtransConnInfo ciptr, char *buf, int size)
-
-{
- PRMSG (2,"DNETRead(%d,%x,%d)\n", ciptr->fd, buf, size);
-
-#ifdef WIN32
- {
- int ret = recv ((SOCKET)ciptr->fd, buf, size, 0);
- errno = WSAGetLastError();
- return ret;
- }
-#else
- return read (ciptr->fd, buf, size);
-#endif /* WIN32 */
-}
-
-
-static int
-TRANS(DNETWrite) (XtransConnInfo ciptr, char *buf, int size)
-
-{
- PRMSG (2,"DNETWrite(%d,%x,%d)\n", ciptr->fd, buf, size);
-
-#ifdef WIN32
- {
- int ret = send ((SOCKET)ciptr->fd, buf, size, 0);
- errno = WSAGetLastError();
- return ret;
- }
-#else
- return write (ciptr->fd, buf, size);
-#endif /* WIN32 */
-}
-
-
-static int
-TRANS(DNETReadv) (XtransConnInfo ciptr, struct iovec *buf, int size)
-
-{
- PRMSG (2,"DNETReadv(%d,%x,%d)\n", ciptr->fd, buf, size);
-
- return READV (ciptr, buf, size);
-}
-
-
-static int
-TRANS(DNETWritev) (XtransConnInfo ciptr, struct iovec *buf, int size)
-
-{
- PRMSG (2,"DNETWritev(%d,%x,%d)\n", ciptr->fd, buf, size);
-
- return WRITEV (ciptr, buf, size);
-}
-
-
-static int
-TRANS(DNETDisconnect) (XtransConnInfo ciptr)
-
-{
- PRMSG (2,"DNETDisconnect(%x,%d)\n", ciptr, ciptr->fd, 0);
-
-#ifdef WIN32
- {
- int ret = shutdown (ciptr->fd, 2);
- errno = WSAGetLastError();
- return ret;
- }
-#else
- return shutdown (ciptr->fd, 2); /* disallow further sends and receives */
-#endif
-}
-
-
-static int
-TRANS(DNETClose) (XtransConnInfo ciptr)
-
-{
- PRMSG (2,"DNETClose(%x,%d)\n", ciptr, ciptr->fd, 0);
-
-#ifdef WIN32
- {
- int ret = close (ciptr->fd);
- errno = WSAGetLastError();
- return ret;
- }
-#else
- return close (ciptr->fd);
-#endif
-}
-
-
-Xtransport TRANS(DNETFuncs) = {
- /* DNET Interface */
- "dnet",
- 0,
-#ifdef TRANS_CLIENT
- TRANS(DNETOpenCOTSClient),
-#endif /* TRANS_CLIENT */
-#ifdef TRANS_SERVER
- TRANS(DNETOpenCOTSServer),
-#endif /* TRANS_SERVER */
-#ifdef TRANS_CLIENT
- TRANS(DNETOpenCLTSClient),
-#endif /* TRANS_CLIENT */
-#ifdef TRANS_SERVER
- TRANS(DNETOpenCLTSServer),
-#endif /* TRANS_SERVER */
-#ifdef TRANS_REOPEN
- TRANS(DNETReopenCOTSServer),
- TRANS(DNETReopenCLTSServer),
-#endif /* TRANS_REOPEN */
- TRANS(DNETSetOption),
-#ifdef TRANS_SERVER
- TRANS(DNETCreateListener),
- NULL, /* ResetListener */
- TRANS(DNETAccept),
-#endif /* TRANS_SERVER */
-#ifdef TRANS_CLIENT
- TRANS(DNETConnect),
-#endif /* TRANS_CLIENT */
- TRANS(DNETBytesReadable),
- TRANS(DNETRead),
- TRANS(DNETWrite),
- TRANS(DNETReadv),
- TRANS(DNETWritev),
- TRANS(DNETDisconnect),
- TRANS(DNETClose),
- TRANS(DNETClose),
-};
diff --git a/nx-X11/lib/xtrans/Xtransint.h b/nx-X11/lib/xtrans/Xtransint.h
index 196eb6fc6..2156bd52f 100644
--- a/nx-X11/lib/xtrans/Xtransint.h
+++ b/nx-X11/lib/xtrans/Xtransint.h
@@ -24,9 +24,7 @@ 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.
-*/
-
-/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
*
* All Rights Reserved
*
@@ -53,10 +51,10 @@ from The Open Group.
#define _XTRANSINT_H_
/*
- * XTRANSDEBUG will enable the PRMSG() macros used in the X Transport
- * Interface code. Each use of the PRMSG macro has a level associated with
- * it. XTRANSDEBUG is defined to be a level. If the invocation level is =<
- * the value of XTRANSDEBUG, then the message will be printed out to stderr.
+ * XTRANSDEBUG will enable the PRMSG() macros used in the X Transport
+ * Interface code. Each use of the PRMSG macro has a level associated with
+ * it. XTRANSDEBUG is defined to be a level. If the invocation level is =<
+ * the value of XTRANSDEBUG, then the message will be printed out to stderr.
* Recommended levels are:
*
* XTRANSDEBUG=1 Error messages
@@ -70,12 +68,8 @@ from The Open Group.
* message.
*/
-#ifndef XTRANSDEBUG
-# ifndef __UNIXOS2__
-# define XTRANSDEBUG 1
-# else
+#if !defined(XTRANSDEBUG) && defined(XTRANS_TRANSPORT_C)
# define XTRANSDEBUG 1
-# endif
#endif
#ifdef WIN32
@@ -84,6 +78,10 @@ from The Open Group.
#include "Xtrans.h"
+#ifndef _X_UNUSED /* Defined in Xfuncproto.h in xproto >= 7.0.22 */
+# define _X_UNUSED /* */
+#endif
+
#ifdef XTRANSDEBUG
# include <stdio.h>
#endif /* XTRANSDEBUG */
@@ -91,87 +89,23 @@ from The Open Group.
#include <errno.h>
#ifndef WIN32
-# ifndef Lynx
# include <sys/socket.h>
-# else
-# include <socket.h>
-# endif
# include <netinet/in.h>
# include <arpa/inet.h>
-# ifdef __UNIXOS2__
-# include <sys/ioctl.h>
-# endif
/*
* Moved the setting of NEED_UTSNAME to this header file from Xtrans.c,
* to avoid a race condition. JKJ (6/5/97)
*/
-# if (defined(_POSIX_SOURCE) && !defined(AIXV3) && !defined(__QNX__)) || defined(hpux) || defined(USG) || defined(SVR4) || defined(__SCO__)
+# if defined(_POSIX_SOURCE) || defined(USG) || defined(SVR4) || defined(__SVR4) || defined(__SCO__)
# ifndef NEED_UTSNAME
# define NEED_UTSNAME
# endif
# include <sys/utsname.h>
# endif
-/*
- * makedepend screws up on #undef OPEN_MAX, so we define a new symbol
- */
-
-# ifndef TRANS_OPEN_MAX
-
-# ifndef X_NOT_POSIX
-# ifdef _POSIX_SOURCE
-# include <limits.h>
-# else
-# define _POSIX_SOURCE
-# include <limits.h>
-# undef _POSIX_SOURCE
-# endif
-# endif
-# ifndef OPEN_MAX
-# if defined(_SC_OPEN_MAX) && !defined(__UNIXOS2__)
-# define OPEN_MAX (sysconf(_SC_OPEN_MAX))
-# else
-# ifdef SVR4
-# define OPEN_MAX 256
-# else
-# include <sys/param.h>
-# ifndef OPEN_MAX
-# ifdef __OSF1__
-# define OPEN_MAX 256
-# else
-# ifdef NOFILE
-# define OPEN_MAX NOFILE
-# else
-# if !defined(__UNIXOS2__) && !defined(__QNX__)
-# define OPEN_MAX NOFILES_MAX
-# else
-# define OPEN_MAX 256
-# endif
-# endif
-# endif
-# endif
-# endif
-# endif
-# endif
-# if defined(_SC_OPEN_MAX)
-# define TRANS_OPEN_MAX OPEN_MAX
-# else /* !__GNU__ */
-# if OPEN_MAX > 256
-# define TRANS_OPEN_MAX 256
-# else
-# define TRANS_OPEN_MAX OPEN_MAX
-# endif
-# endif /*__GNU__*/
-
-# endif /* TRANS_OPEN_MAX */
-
-# ifdef __UNIXOS2__
-# define ESET(val)
-# else
# define ESET(val) errno = val
-# endif
# define EGET() errno
#else /* WIN32 */
@@ -189,6 +123,16 @@ from The Open Group.
#define X_TCP_PORT 6000
#endif
+#if XTRANS_SEND_FDS
+
+struct _XtransConnFd {
+ struct _XtransConnFd *next;
+ int fd;
+ int do_close;
+};
+
+#endif
+
struct _XtransConnInfo {
struct _Xtransport *transptr;
int index;
@@ -201,75 +145,45 @@ struct _XtransConnInfo {
int addrlen;
char *peeraddr;
int peeraddrlen;
+ struct _XtransConnFd *recv_fds;
+ struct _XtransConnFd *send_fds;
};
#define XTRANS_OPEN_COTS_CLIENT 1
#define XTRANS_OPEN_COTS_SERVER 2
-#define XTRANS_OPEN_CLTS_CLIENT 3
-#define XTRANS_OPEN_CLTS_SERVER 4
-
typedef struct _Xtransport {
- char *TransName;
+ const char *TransName;
int flags;
#ifdef TRANS_CLIENT
XtransConnInfo (*OpenCOTSClient)(
struct _Xtransport *, /* transport */
- char *, /* protocol */
- char *, /* host */
- char * /* port */
+ const char *, /* protocol */
+ const char *, /* host */
+ const char * /* port */
);
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
- char ** nolisten;
+ const char ** nolisten;
XtransConnInfo (*OpenCOTSServer)(
struct _Xtransport *, /* transport */
- char *, /* protocol */
- char *, /* host */
- char * /* port */
- );
-
-#endif /* TRANS_SERVER */
-
-#ifdef TRANS_CLIENT
-
- XtransConnInfo (*OpenCLTSClient)(
- struct _Xtransport *, /* transport */
- char *, /* protocol */
- char *, /* host */
- char * /* port */
- );
-
-#endif /* TRANS_CLIENT */
-
-#ifdef TRANS_SERVER
-
- XtransConnInfo (*OpenCLTSServer)(
- struct _Xtransport *, /* transport */
- char *, /* protocol */
- char *, /* host */
- char * /* port */
+ const char *, /* protocol */
+ const char *, /* host */
+ const char * /* port */
);
#endif /* TRANS_SERVER */
-
#ifdef TRANS_REOPEN
XtransConnInfo (*ReopenCOTSServer)(
struct _Xtransport *, /* transport */
int, /* fd */
- char * /* port */
- );
-
- XtransConnInfo (*ReopenCLTSServer)(
- struct _Xtransport *, /* transport */
- int, /* fd */
- char * /* port */
+ const char * /* port */
);
#endif /* TRANS_REOPEN */
@@ -287,7 +201,7 @@ typedef struct _Xtransport {
int (*CreateListener)(
XtransConnInfo, /* connection */
- char *, /* port */
+ const char *, /* port */
unsigned int /* flags */
);
@@ -306,8 +220,8 @@ typedef struct _Xtransport {
int (*Connect)(
XtransConnInfo, /* connection */
- char *, /* host */
- char * /* port */
+ const char *, /* host */
+ const char * /* port */
);
#endif /* TRANS_CLIENT */
@@ -341,6 +255,18 @@ typedef struct _Xtransport {
int /* size */
);
+#if XTRANS_SEND_FDS
+ int (*SendFd)(
+ XtransConnInfo, /* connection */
+ int, /* fd */
+ int /* do_close */
+ );
+
+ int (*RecvFd)(
+ XtransConnInfo /* connection */
+ );
+#endif
+
int (*Disconnect)(
XtransConnInfo /* connection */
);
@@ -370,18 +296,29 @@ typedef struct _Xtransport_table {
#define TRANS_LOCAL (1<<1) /* local transport */
#define TRANS_DISABLED (1<<2) /* Don't open this one */
#define TRANS_NOLISTEN (1<<3) /* Don't listen on this one */
-#define TRANS_NOUNLINK (1<<4) /* Dont unlink transport endpoints */
+#define TRANS_NOUNLINK (1<<4) /* Don't unlink transport endpoints */
#define TRANS_ABSTRACT (1<<5) /* Use abstract sockets if available */
+#define TRANS_NOXAUTH (1<<6) /* Don't verify authentication (because it's secure some other way at the OS layer) */
+#define TRANS_RECEIVED (1<<7) /* The fd for this has already been opened by someone else. */
/* Flags to preserve when setting others */
#define TRANS_KEEPFLAGS (TRANS_NOUNLINK|TRANS_ABSTRACT)
+#ifdef XTRANS_TRANSPORT_C /* only provide static function prototypes when
+ building the transport.c file that has them in */
+
+#ifdef __clang__
+/* Not all clients make use of all provided statics */
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunused-function"
+#endif
+
/*
* readv() and writev() don't exist or don't work correctly on some
* systems, so they may be emulated.
*/
-#if (defined(SYSV) && defined(i386) && !defined(__SCO__)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__)
+#ifdef WIN32
#define READV(ciptr, iov, iovcnt) TRANS(ReadV)(ciptr, iov, iovcnt)
@@ -395,10 +332,10 @@ static int TRANS(ReadV)(
#define READV(ciptr, iov, iovcnt) readv(ciptr->fd, iov, iovcnt)
-#endif /* (SYSV && i386) || WIN32 || __sxg__ || */
+#endif /* WIN32 */
-#if (defined(SYSV) && defined(i386) && !defined(__SCO__)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__)
+#ifdef WIN32
#define WRITEV(ciptr, iov, iovcnt) TRANS(WriteV)(ciptr, iov, iovcnt)
@@ -412,72 +349,84 @@ static int TRANS(WriteV)(
#define WRITEV(ciptr, iov, iovcnt) writev(ciptr->fd, iov, iovcnt)
-#endif /* WIN32 || __sxg__ */
+#endif /* WIN32 */
static int is_numeric (
- char * /* str */
+ const char * /* str */
);
#ifdef TRANS_SERVER
static int trans_mkdir (
- char *, /* path */
+ const char *, /* path */
int /* mode */
);
#endif
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
/*
* Some XTRANSDEBUG stuff
*/
-#if defined(XTRANSDEBUG)
-/* add hack to the format string to avoid warnings about extra arguments
- * to fprintf.
+#ifdef XTRANSDEBUG
+#include <stdarg.h>
+
+/*
+ * The X server provides ErrorF() & VErrorF(), for other software that uses
+ * xtrans, we provide our own simple versions.
*/
-#ifdef XTRANSDEBUGTIMESTAMP
-#if defined(XSERV_t) && defined(TRANS_SERVER)
-/* Use ErrorF() for the X server */
-#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \
- int hack= 0, saveerrno=errno; \
- struct timeval tp;\
- gettimeofday(&tp,0); \
- ErrorF("%s",__xtransname); \
- ErrorF(x+hack,a,b,c); \
- ErrorF("timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \
- errno=saveerrno; \
- } else ((void)0)
-#else
-#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \
- int hack= 0, saveerrno=errno; \
- struct timeval tp;\
- gettimeofday(&tp,0); \
- fprintf(stderr, "%s",__xtransname); fflush(stderr); \
- fprintf(stderr, x+hack,a,b,c); fflush(stderr); \
- fprintf(stderr, "timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \
- fflush(stderr); \
- errno=saveerrno; \
- } else ((void)0)
-#endif /* XSERV_t && TRANS_SERVER */
-#else /* XTRANSDEBUGTIMESTAMP */
-#if defined(XSERV_t) && defined(TRANS_SERVER)
-/* Use ErrorF() for the X server */
-#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \
- int hack= 0, saveerrno=errno; \
- ErrorF("%s",__xtransname); \
- ErrorF(x+hack,a,b,c); \
- errno=saveerrno; \
- } else ((void)0)
-#else
-#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \
- int hack= 0, saveerrno=errno; \
- fprintf(stderr, "%s",__xtransname); fflush(stderr); \
- fprintf(stderr, x+hack,a,b,c); fflush(stderr); \
- errno=saveerrno; \
- } else ((void)0)
-#endif /* XSERV_t && TRANS_SERVER */
-#endif /* XTRANSDEBUGTIMESTAMP */
-#else
-#define PRMSG(lvl,x,a,b,c) ((void)0)
+# if defined(XSERV_t) && defined(TRANS_SERVER)
+# include "os.h"
+# else
+static inline void _X_ATTRIBUTE_PRINTF(1, 0)
+VErrorF(const char *f, va_list args)
+{
+ vfprintf(stderr, f, args);
+ fflush(stderr);
+}
+
+static inline void _X_ATTRIBUTE_PRINTF(1, 2)
+ErrorF(const char *f, ...)
+{
+ va_list args;
+
+ va_start(args, f);
+ VErrorF(f, args);
+ va_end(args);
+}
+# endif /* xserver */
+#endif /* XTRANSDEBUG */
+
+static inline void _X_ATTRIBUTE_PRINTF(2, 3)
+prmsg(int lvl, const char *f, ...)
+{
+#ifdef XTRANSDEBUG
+ va_list args;
+
+ va_start(args, f);
+ if (lvl <= XTRANSDEBUG) {
+ int saveerrno = errno;
+
+ ErrorF("%s", __xtransname);
+ VErrorF(f, args);
+
+# ifdef XTRANSDEBUGTIMESTAMP
+ {
+ struct timeval tp;
+ gettimeofday(&tp, 0);
+ ErrorF("timestamp (ms): %d\n",
+ tp.tv_sec * 1000 + tp.tv_usec / 1000);
+ }
+# endif
+ errno = saveerrno;
+ }
+ va_end(args);
#endif /* XTRANSDEBUG */
+}
+
+#endif /* XTRANS_TRANSPORT_C */
#endif /* _XTRANSINT_H_ */
diff --git a/nx-X11/lib/xtrans/Xtranslcl.c b/nx-X11/lib/xtrans/Xtranslcl.c
index f504338aa..7231d2a83 100644
--- a/nx-X11/lib/xtrans/Xtranslcl.c
+++ b/nx-X11/lib/xtrans/Xtranslcl.c
@@ -24,9 +24,7 @@ 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.
-*/
-
-/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
*
* All Rights Reserved
*
@@ -51,7 +49,7 @@ from The Open Group.
/*
*
- * The connection code/ideas in lib/X and server/os for SVR4/Intel
+ * The connection code/ideas in lib/X and server/os for SVR4/Intel
* environments was contributed by the following companies/groups:
*
* MetroLink Inc
@@ -63,12 +61,12 @@ from The Open Group.
*
* The goal is to have common connection code among all SVR4/Intel vendors.
*
- * ALL THE ABOVE COMPANIES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
- * IN NO EVENT SHALL THESE COMPANIES * 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
+ * ALL THE ABOVE COMPANIES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
+ * IN NO EVENT SHALL THESE COMPANIES * 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.
*/
@@ -77,15 +75,14 @@ from The Open Group.
#include <sys/signal.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
-#if defined(SVR4)
-#if !defined(DGUX)
+#if defined(SVR4) || defined(__SVR4)
#include <sys/filio.h>
-#else /* DGUX */
-#include <sys/stream.h>
-#include <sys/ptms.h>
-#endif
#endif
+#ifdef __sun
+# include <stropts.h>
+#else
#include <sys/stropts.h>
+#endif
#include <sys/wait.h>
#include <sys/types.h>
@@ -101,10 +98,23 @@ from The Open Group.
#include <sys/un.h>
#endif
-#if defined(ISC) && !defined(_POSIX_SOURCE)
-typedef unsigned short mode_t;
-/* POSIX needed for mode_t define in sys/types.h */
+
+/* Types of local connections supported:
+ * - PTS
+ * - named pipes
+ * - SCO
+ */
+#if !defined(__sun)
+# define LOCAL_TRANS_PTS
#endif
+#if defined(SVR4) || defined(__SVR4)
+# define LOCAL_TRANS_NAMED
+#endif
+#if defined(__SCO__) || defined(__UNIXWARE__)
+# define LOCAL_TRANS_SCO
+#endif
+
+static int TRANS(LocalClose)(XtransConnInfo ciptr);
/*
* These functions actually implement the local connection mechanisms.
@@ -113,7 +123,7 @@ typedef unsigned short mode_t;
/* Type Not Supported */
static int
-TRANS(OpenFail)(XtransConnInfo ciptr, char *port)
+TRANS(OpenFail)(XtransConnInfo ciptr _X_UNUSED, const char *port _X_UNUSED)
{
return -1;
@@ -122,7 +132,8 @@ TRANS(OpenFail)(XtransConnInfo ciptr, char *port)
#ifdef TRANS_REOPEN
static int
-TRANS(ReopenFail)(XtransConnInfo ciptr, int fd, char *port)
+TRANS(ReopenFail)(XtransConnInfo ciptr _X_UNUSED, int fd _X_UNUSED,
+ const char *port _X_UNUSED)
{
return 0;
@@ -130,10 +141,26 @@ TRANS(ReopenFail)(XtransConnInfo ciptr, int fd, char *port)
#endif /* TRANS_REOPEN */
+#if XTRANS_SEND_FDS
+static int
+TRANS(LocalRecvFdInvalid)(XtransConnInfo ciptr)
+{
+ errno = EINVAL;
+ return -1;
+}
+
+static int
+TRANS(LocalSendFdInvalid)(XtransConnInfo ciptr, int fd, int do_close)
+{
+ errno = EINVAL;
+ return -1;
+}
+#endif
static int
-TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, char *peer_sun_path)
+TRANS(FillAddrInfo)(XtransConnInfo ciptr,
+ const char *sun_path, const char *peer_sun_path)
{
struct sockaddr_un *sunaddr;
@@ -142,20 +169,21 @@ TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, char *peer_sun_path)
ciptr->family = AF_UNIX;
ciptr->addrlen = sizeof (struct sockaddr_un);
- if ((sunaddr = (struct sockaddr_un *) malloc (ciptr->addrlen)) == NULL)
+ if ((sunaddr = malloc (ciptr->addrlen)) == NULL)
{
- PRMSG(1,"FillAddrInfo: failed to allocate memory for addr\n", 0, 0, 0);
+ prmsg(1,"FillAddrInfo: failed to allocate memory for addr\n");
return 0;
}
sunaddr->sun_family = AF_UNIX;
if (strlen(sun_path) > sizeof(sunaddr->sun_path) - 1) {
- PRMSG(1, "FillAddrInfo: path too long\n", 0, 0, 0);
+ prmsg(1, "FillAddrInfo: path too long\n");
+ free((char *) sunaddr);
return 0;
}
strcpy (sunaddr->sun_path, sun_path);
-#if defined(BSD44SOCKETS) && !defined(Lynx)
+#if defined(BSD44SOCKETS)
sunaddr->sun_len = strlen (sunaddr->sun_path);
#endif
@@ -163,13 +191,11 @@ TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, char *peer_sun_path)
ciptr->peeraddrlen = sizeof (struct sockaddr_un);
- if ((p_sunaddr = (struct sockaddr_un *) malloc (
- ciptr->peeraddrlen)) == NULL)
+ if ((p_sunaddr = malloc (ciptr->peeraddrlen)) == NULL)
{
- PRMSG(1,
- "FillAddrInfo: failed to allocate memory for peer addr\n",
- 0,0,0);
- free ((char *) sunaddr);
+ prmsg(1,
+ "FillAddrInfo: failed to allocate memory for peer addr\n");
+ free (sunaddr);
ciptr->addr = NULL;
return 0;
@@ -178,11 +204,12 @@ TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, char *peer_sun_path)
p_sunaddr->sun_family = AF_UNIX;
if (strlen(peer_sun_path) > sizeof(p_sunaddr->sun_path) - 1) {
- PRMSG(1, "FillAddrInfo: peer path too long\n", 0, 0, 0);
+ prmsg(1, "FillAddrInfo: peer path too long\n");
+ free((char *) p_sunaddr);
return 0;
}
strcpy (p_sunaddr->sun_path, peer_sun_path);
-#if defined(BSD44SOCKETS) && !defined(Lynx)
+#if defined(BSD44SOCKETS)
p_sunaddr->sun_len = strlen (p_sunaddr->sun_path);
#endif
@@ -193,9 +220,10 @@ TRANS(FillAddrInfo)(XtransConnInfo ciptr, char *sun_path, char *peer_sun_path)
+#ifdef LOCAL_TRANS_PTS
/* PTS */
-#if defined(SYSV) && !defined(__SCO__) && !defined(ISC)
+#if defined(SYSV) && !defined(__SCO__)
#define SIGNAL_T int
#else
#define SIGNAL_T void
@@ -209,12 +237,13 @@ extern char *ptsname(
int
);
-static void _dummy(int sig)
+static void _dummy(int sig _X_UNUSED)
{
}
+#endif /* LOCAL_TRANS_PTS */
-#ifndef sun
+#ifndef __sun
#define X_STREAMS_DIR "/dev/X"
#define DEV_SPX "/dev/spx"
#else
@@ -225,39 +254,34 @@ static void _dummy(int sig)
#endif
#endif
-#ifdef _AIX
-#define DEV_PTMX "/dev/ptc"
-#else
#define DEV_PTMX "/dev/ptmx"
-#endif
#if defined(X11_t)
#define PTSNODENAME "/dev/X/server."
-#ifndef sun
-#define NAMEDNODENAME "/dev/X/Nserver."
-#else
+#ifdef __sun
#define NAMEDNODENAME "/tmp/.X11-pipe/X"
-#endif
-
-/*
- * ISC is only defined for X11 since they are there for
- * backwards binary compatability only.
- */
+#else
+#define NAMEDNODENAME "/dev/X/Nserver."
-#define X_ISC_DIR "/dev/X/ISCCONN"
-#define ISCDEVNODENAME "/dev/X/ISCCONN/X%s"
-#define ISCTMPNODENAME "/tmp/.X11-unix/X%s"
#define SCORNODENAME "/dev/X%1sR"
#define SCOSNODENAME "/dev/X%1sS"
+#endif /* !__sun */
#endif
#if defined(XIM_t)
+#ifdef __sun
+#define NAMEDNODENAME "/tmp/.XIM-pipe/XIM"
+#else
#define PTSNODENAME "/dev/X/XIM."
#define NAMEDNODENAME "/dev/X/NXIM."
#define SCORNODENAME "/dev/XIM.%sR"
#define SCOSNODENAME "/dev/XIM.%sS"
#endif
+#endif
#if defined(FS_t) || defined (FONT_t)
+#ifdef __sun
+#define NAMEDNODENAME "/tmp/.font-pipe/fs"
+#else
/*
* USL has already defined something here. We need to check with them
* and see if their choice is usable here.
@@ -267,13 +291,21 @@ static void _dummy(int sig)
#define SCORNODENAME "/dev/fontserver.%sR"
#define SCOSNODENAME "/dev/fontserver.%sS"
#endif
+#endif
#if defined(ICE_t)
+#ifdef __sun
+#define NAMEDNODENAME "/tmp/.ICE-pipe/"
+#else
#define PTSNODENAME "/dev/X/ICE."
#define NAMEDNODENAME "/dev/X/NICE."
#define SCORNODENAME "/dev/ICE.%sR"
#define SCOSNODENAME "/dev/ICE.%sS"
#endif
+#endif
#if defined(TEST_t)
+#ifdef __sun
+#define NAMEDNODENAME "/tmp/.Test-unix/test"
+#endif
#define PTSNODENAME "/dev/X/transtest."
#define NAMEDNODENAME "/dev/X/Ntranstest."
#define SCORNODENAME "/dev/transtest.%sR"
@@ -282,11 +314,11 @@ static void _dummy(int sig)
-#ifndef sun
+#ifdef LOCAL_TRANS_PTS
#ifdef TRANS_CLIENT
static int
-TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port)
+TRANS(PTSOpenClient)(XtransConnInfo ciptr, const char *port)
{
#ifdef PTSNODENAME
@@ -298,20 +330,22 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port)
pid_t saved_pid;
#endif
- PRMSG(2,"PTSOpenClient(%s)\n", port, 0,0 );
+ prmsg(2,"PTSOpenClient(%s)\n", port);
#if !defined(PTSNODENAME)
- PRMSG(1,"PTSOpenClient: Protocol is not supported by a pts connection\n", 0,0,0);
+ prmsg(1,"PTSOpenClient: Protocol is not supported by a pts connection\n");
return -1;
#else
if (port && *port ) {
if( *port == '/' ) { /* A full pathname */
- (void) sprintf(server_path, "%s", port);
+ snprintf(server_path, sizeof(server_path), "%s", port);
} else {
- (void) sprintf(server_path, "%s%s", PTSNODENAME, port);
+ snprintf(server_path, sizeof(server_path), "%s%s",
+ PTSNODENAME, port);
}
} else {
- (void) sprintf(server_path, "%s%d", PTSNODENAME, getpid());
+ snprintf(server_path, sizeof(server_path), "%s%d",
+ PTSNODENAME, getpid());
}
@@ -320,7 +354,7 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port)
*/
if ((server = open (server_path, O_RDWR)) < 0) {
- PRMSG(1,"PTSOpenClient: failed to open %s\n", server_path, 0,0);
+ prmsg(1,"PTSOpenClient: failed to open %s\n", server_path);
return -1;
}
@@ -330,7 +364,8 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port)
*/
if ((fd = open(DEV_PTMX, O_RDWR)) < 0) {
- PRMSG(1,"PTSOpenClient: failed to open %s\n", DEV_PTMX, 0,0);
+ prmsg(1,"PTSOpenClient: failed to open %s\n", DEV_PTMX);
+ close(server);
return(-1);
}
@@ -340,7 +375,7 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port)
slave = ptsname(fd); /* get name */
if( slave == NULL ) {
- PRMSG(1,"PTSOpenClient: failed to get ptsname()\n", 0,0,0);
+ prmsg(1,"PTSOpenClient: failed to get ptsname()\n");
close(fd);
close(server);
return -1;
@@ -373,14 +408,14 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port)
if (WIFEXITED(exitval) && WEXITSTATUS(exitval) != 0) {
close(fd);
close(server);
- PRMSG(1, "PTSOpenClient: cannot set the owner of %s\n",
- slave, 0, 0);
+ prmsg(1, "PTSOpenClient: cannot set the owner of %s\n",
+ slave);
return(-1);
}
if (chmod(slave, 0666) < 0) {
close(fd);
close(server);
- PRMSG(1,"PTSOpenClient: Cannot chmod %s\n", slave, 0,0);
+ prmsg(1,"PTSOpenClient: Cannot chmod %s\n", slave);
return(-1);
}
@@ -407,8 +442,8 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port)
(void) signal(SIGALRM, savef);
if (ret != 1) {
- PRMSG(1,
- "PTSOpenClient: failed to get acknoledgement from server\n", 0, 0, 0);
+ prmsg(1,
+ "PTSOpenClient: failed to get acknoledgement from server\n");
(void) close(fd);
fd = -1;
}
@@ -419,7 +454,7 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port)
if (TRANS(FillAddrInfo) (ciptr, slave, server_path) == 0)
{
- PRMSG(1,"PTSOpenClient: failed to fill in addr info\n", 0, 0, 0);
+ prmsg(1,"PTSOpenClient: failed to fill in addr info\n");
close(fd);
return -1;
}
@@ -435,7 +470,7 @@ TRANS(PTSOpenClient)(XtransConnInfo ciptr, char *port)
#ifdef TRANS_SERVER
static int
-TRANS(PTSOpenServer)(XtransConnInfo ciptr, char *port)
+TRANS(PTSOpenServer)(XtransConnInfo ciptr, const char *port)
{
#ifdef PTSNODENAME
@@ -444,10 +479,10 @@ TRANS(PTSOpenServer)(XtransConnInfo ciptr, char *port)
int mode;
#endif
- PRMSG(2,"PTSOpenServer(%s)\n", port, 0,0 );
+ prmsg(2,"PTSOpenServer(%s)\n", port);
#if !defined(PTSNODENAME)
- PRMSG(1,"PTSOpenServer: Protocol is not supported by a pts connection\n", 0,0,0);
+ prmsg(1,"PTSOpenServer: Protocol is not supported by a pts connection\n");
return -1;
#else
if (port && *port ) {
@@ -466,8 +501,8 @@ TRANS(PTSOpenServer)(XtransConnInfo ciptr, char *port)
mode = 0777;
#endif
if (trans_mkdir(X_STREAMS_DIR, mode) == -1) {
- PRMSG (1, "PTSOpenServer: mkdir(%s) failed, errno = %d\n",
- X_STREAMS_DIR, errno, 0);
+ prmsg (1, "PTSOpenServer: mkdir(%s) failed, errno = %d\n",
+ X_STREAMS_DIR, errno);
return(-1);
}
@@ -478,8 +513,8 @@ TRANS(PTSOpenServer)(XtransConnInfo ciptr, char *port)
* prevent clients from trying to connect to the in-use PTS (which
* is often in use by something other than another server).
*/
- PRMSG(1, "PTSOpenServer: A server is already running on port %s\n", port, 0,0 );
- PRMSG(1, "PTSOpenServer: Remove %s if this is incorrect.\n", server_path, 0,0 );
+ prmsg(1, "PTSOpenServer: A server is already running on port %s\n", port);
+ prmsg(1, "PTSOpenServer: Remove %s if this is incorrect.\n", server_path);
close(fd);
return(-1);
}
@@ -490,7 +525,7 @@ TRANS(PTSOpenServer)(XtransConnInfo ciptr, char *port)
unlink(server_path);
if( (fd=open(DEV_PTMX, O_RDWR)) < 0) {
- PRMSG(1, "PTSOpenServer: Unable to open %s\n", DEV_PTMX, 0,0 );
+ prmsg(1, "PTSOpenServer: Unable to open %s\n", DEV_PTMX);
return(-1);
}
@@ -498,25 +533,25 @@ TRANS(PTSOpenServer)(XtransConnInfo ciptr, char *port)
unlockpt(fd);
if( (slave=ptsname(fd)) == NULL) {
- PRMSG(1, "PTSOpenServer: Unable to get slave device name\n", 0,0,0 );
+ prmsg(1, "PTSOpenServer: Unable to get slave device name\n");
close(fd);
return(-1);
}
if( link(slave,server_path) < 0 ) {
- PRMSG(1, "PTSOpenServer: Unable to link %s to %s\n", slave, server_path,0 );
+ prmsg(1, "PTSOpenServer: Unable to link %s to %s\n", slave, server_path);
close(fd);
return(-1);
}
if( chmod(server_path, 0666) < 0 ) {
- PRMSG(1, "PTSOpenServer: Unable to chmod %s to 0666\n", server_path,0,0 );
+ prmsg(1, "PTSOpenServer: Unable to chmod %s to 0666\n", server_path);
close(fd);
return(-1);
}
if( (server=open(server_path, O_RDWR)) < 0 ) {
- PRMSG(1, "PTSOpenServer: Unable to open server device %s\n", server_path,0,0 );
+ prmsg(1, "PTSOpenServer: Unable to open server device %s\n", server_path);
close(fd);
return(-1);
}
@@ -529,7 +564,7 @@ TRANS(PTSOpenServer)(XtransConnInfo ciptr, char *port)
if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
{
- PRMSG(1,"PTSOpenServer: failed to fill in addr info\n", 0, 0, 0);
+ prmsg(1,"PTSOpenServer: failed to fill in addr info\n");
close(fd);
return -1;
}
@@ -549,17 +584,17 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
char buf[256];
struct sockaddr_un *sunaddr;
- PRMSG(2,"PTSAccept(%x->%d)\n",ciptr,ciptr->fd,0);
+ prmsg(2,"PTSAccept(%x->%d)\n",ciptr,ciptr->fd);
if( (in=read(ciptr->fd,&length,1)) <= 0 ){
if( !in ) {
- PRMSG(2,
- "PTSAccept: Incoming connection closed\n",0,0,0);
+ prmsg(2,
+ "PTSAccept: Incoming connection closed\n");
}
else {
- PRMSG(1,
+ prmsg(1,
"PTSAccept: Error reading incoming connection. errno=%d \n",
- errno,0,0);
+ errno);
}
*status = TRANS_ACCEPT_MISC_ERROR;
return -1;
@@ -567,13 +602,13 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
if( (in=read(ciptr->fd,buf,length)) <= 0 ){
if( !in ) {
- PRMSG(2,
- "PTSAccept: Incoming connection closed\n",0,0,0);
+ prmsg(2,
+ "PTSAccept: Incoming connection closed\n");
}
else {
- PRMSG(1,
+ prmsg(1,
"PTSAccept: Error reading device name for new connection. errno=%d \n",
- errno,0,0);
+ errno);
}
*status = TRANS_ACCEPT_MISC_ERROR;
return -1;
@@ -582,7 +617,7 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
buf[length] = '\0';
if( (newfd=open(buf,O_RDWR)) < 0 ) {
- PRMSG(1, "PTSAccept: Failed to open %s\n",buf,0,0);
+ prmsg(1, "PTSAccept: Failed to open %s\n",buf);
*status = TRANS_ACCEPT_MISC_ERROR;
return -1;
}
@@ -594,9 +629,8 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
*/
newciptr->addrlen=ciptr->addrlen;
- if( (newciptr->addr=(char *)malloc(newciptr->addrlen)) == NULL ) {
- PRMSG(1,"PTSAccept: failed to allocate memory for peer addr\n",
- 0,0,0);
+ if( (newciptr->addr = malloc(newciptr->addrlen)) == NULL ) {
+ prmsg(1,"PTSAccept: failed to allocate memory for peer addr\n");
close(newfd);
*status = TRANS_ACCEPT_BAD_MALLOC;
return -1;
@@ -605,9 +639,8 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen);
newciptr->peeraddrlen=sizeof(struct sockaddr_un);
- if( (sunaddr=(struct sockaddr_un *)malloc(newciptr->peeraddrlen)) == NULL ) {
- PRMSG(1,"PTSAccept: failed to allocate memory for peer addr\n",
- 0,0,0);
+ if( (sunaddr = malloc(newciptr->peeraddrlen)) == NULL ) {
+ prmsg(1,"PTSAccept: failed to allocate memory for peer addr\n");
free(newciptr->addr);
close(newfd);
*status = TRANS_ACCEPT_BAD_MALLOC;
@@ -616,7 +649,7 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
sunaddr->sun_family=AF_UNIX;
strcpy(sunaddr->sun_path,buf);
-#if defined(BSD44SOCKETS) && !defined(Lynx)
+#if defined(BSD44SOCKETS)
sunaddr->sun_len=strlen(sunaddr->sun_path);
#endif
@@ -628,60 +661,65 @@ TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
}
#endif /* TRANS_SERVER */
-#endif /* sun */
+#endif /* LOCAL_TRANS_PTS */
-#ifdef SVR4
+#ifdef LOCAL_TRANS_NAMED
/* NAMED */
#ifdef TRANS_CLIENT
static int
-TRANS(NAMEDOpenClient)(XtransConnInfo ciptr, char *port)
+TRANS(NAMEDOpenClient)(XtransConnInfo ciptr, const char *port)
{
#ifdef NAMEDNODENAME
int fd;
char server_path[64];
struct stat filestat;
- extern int isastream();
+# ifndef __sun
+ extern int isastream(int);
+# endif
#endif
- PRMSG(2,"NAMEDOpenClient(%s)\n", port, 0,0 );
+ prmsg(2,"NAMEDOpenClient(%s)\n", port);
#if !defined(NAMEDNODENAME)
- PRMSG(1,"NAMEDOpenClient: Protocol is not supported by a NAMED connection\n", 0,0,0);
+ prmsg(1,"NAMEDOpenClient: Protocol is not supported by a NAMED connection\n");
return -1;
#else
if ( port && *port ) {
if( *port == '/' ) { /* A full pathname */
- (void) sprintf(server_path, "%s", port);
+ (void) snprintf(server_path, sizeof(server_path), "%s", port);
} else {
- (void) sprintf(server_path, "%s%s", NAMEDNODENAME, port);
+ (void) snprintf(server_path, sizeof(server_path), "%s%s", NAMEDNODENAME, port);
}
} else {
- (void) sprintf(server_path, "%s%ld", NAMEDNODENAME, (long)getpid());
+ (void) snprintf(server_path, sizeof(server_path), "%s%ld", NAMEDNODENAME, (long)getpid());
}
- if (stat(server_path, &filestat) < 0 ) {
- PRMSG(1,"NAMEDOpenClient: No device %s for NAMED connection\n", server_path, 0,0 );
+ if ((fd = open(server_path, O_RDWR)) < 0) {
+ prmsg(1,"NAMEDOpenClient: Cannot open %s for NAMED connection\n", server_path);
return -1;
}
- if ((filestat.st_mode & S_IFMT) != S_IFIFO) {
- PRMSG(1,"NAMEDOpenClient: Device %s is not a FIFO\n", server_path, 0,0 );
- /* Is this really a failure? */
+ if (fstat(fd, &filestat) < 0 ) {
+ prmsg(1,"NAMEDOpenClient: Cannot stat %s for NAMED connection\n", server_path);
+ (void) close(fd);
return -1;
}
- if ((fd = open(server_path, O_RDWR)) < 0) {
- PRMSG(1,"NAMEDOpenClient: Cannot open %s for NAMED connection\n", server_path, 0,0 );
+ if ((filestat.st_mode & S_IFMT) != S_IFIFO) {
+ prmsg(1,"NAMEDOpenClient: Device %s is not a FIFO\n", server_path);
+ /* Is this really a failure? */
+ (void) close(fd);
return -1;
}
+
if (isastream(fd) <= 0) {
- PRMSG(1,"NAMEDOpenClient: %s is not a streams device\n", server_path, 0,0 );
+ prmsg(1,"NAMEDOpenClient: %s is not a streams device\n", server_path);
(void) close(fd);
return -1;
}
@@ -692,8 +730,7 @@ TRANS(NAMEDOpenClient)(XtransConnInfo ciptr, char *port)
if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
{
- PRMSG(1,"NAMEDOpenClient: failed to fill in addr info\n",
- 0,0,0);
+ prmsg(1,"NAMEDOpenClient: failed to fill in addr info\n");
close(fd);
return -1;
}
@@ -708,32 +745,16 @@ TRANS(NAMEDOpenClient)(XtransConnInfo ciptr, char *port)
#ifdef TRANS_SERVER
-static int
-TRANS(NAMEDOpenServer)(XtransConnInfo ciptr, char *port)
-{
#ifdef NAMEDNODENAME
+static int
+TRANS(NAMEDOpenPipe)(const char *server_path)
+{
int fd, pipefd[2];
- char server_path[64];
struct stat sbuf;
int mode;
-#endif
- PRMSG(2,"NAMEDOpenServer(%s)\n", port, 0,0 );
-
-#if !defined(NAMEDNODENAME)
- PRMSG(1,"NAMEDOpenServer: Protocol is not supported by a NAMED connection\n", 0,0,0);
- return -1;
-#else
- if ( port && *port ) {
- if( *port == '/' ) { /* A full pathname */
- (void) sprintf(server_path, "%s", port);
- } else {
- (void) sprintf(server_path, "%s%s", NAMEDNODENAME, port);
- }
- } else {
- (void) sprintf(server_path, "%s%ld", NAMEDNODENAME, (long)getpid());
- }
+ prmsg(2,"NAMEDOpenPipe(%s)\n", server_path);
#ifdef HAS_STICKY_DIR_BIT
mode = 01777;
@@ -741,72 +762,136 @@ TRANS(NAMEDOpenServer)(XtransConnInfo ciptr, char *port)
mode = 0777;
#endif
if (trans_mkdir(X_STREAMS_DIR, mode) == -1) {
- PRMSG (1, "NAMEDOpenServer: mkdir(%s) failed, errno = %d\n",
- X_STREAMS_DIR, errno, 0);
+ prmsg (1, "NAMEDOpenPipe: mkdir(%s) failed, errno = %d\n",
+ X_STREAMS_DIR, errno);
return(-1);
}
if(stat(server_path, &sbuf) != 0) {
if (errno == ENOENT) {
if ((fd = creat(server_path, (mode_t)0666)) == -1) {
- PRMSG(1, "NAMEDOpenServer: Can't open %s\n", server_path, 0,0 );
+ prmsg(1, "NAMEDOpenPipe: Can't open %s\n", server_path);
return(-1);
}
close(fd);
if (chmod(server_path, (mode_t)0666) < 0) {
- PRMSG(1, "NAMEDOpenServer: Can't open %s\n", server_path, 0,0 );
+ prmsg(1, "NAMEDOpenPipe: Can't open %s\n", server_path);
return(-1);
}
} else {
- PRMSG(1, "NAMEDOpenServer: stat on %s failed\n", server_path, 0,0 );
+ prmsg(1, "NAMEDOpenPipe: stat on %s failed\n", server_path);
return(-1);
}
}
if( pipe(pipefd) != 0) {
- PRMSG(1, "NAMEDOpenServer: pipe() failed, errno=%d\n",errno, 0,0 );
+ prmsg(1, "NAMEDOpenPipe: pipe() failed, errno=%d\n",errno);
return(-1);
}
if( ioctl(pipefd[0], I_PUSH, "connld") != 0) {
- PRMSG(1, "NAMEDOpenServer: ioctl(I_PUSH,\"connld\") failed, errno=%d\n",errno, 0,0 );
+ prmsg(1, "NAMEDOpenPipe: ioctl(I_PUSH,\"connld\") failed, errno=%d\n",errno);
close(pipefd[0]);
close(pipefd[1]);
return(-1);
}
if( fattach(pipefd[0], server_path) != 0) {
- PRMSG(1, "NAMEDOpenServer: fattach(%s) failed, errno=%d\n", server_path,errno, 0 );
+ prmsg(1, "NAMEDOpenPipe: fattach(%s) failed, errno=%d\n", server_path,errno);
close(pipefd[0]);
close(pipefd[1]);
return(-1);
}
+ return(pipefd[1]);
+}
+#endif
+
+static int
+TRANS(NAMEDOpenServer)(XtransConnInfo ciptr, const char *port)
+{
+#ifdef NAMEDNODENAME
+ int fd;
+ char server_path[64];
+#endif
+
+ prmsg(2,"NAMEDOpenServer(%s)\n", port);
+
+#if !defined(NAMEDNODENAME)
+ prmsg(1,"NAMEDOpenServer: Protocol is not supported by a NAMED connection\n");
+ return -1;
+#else
+ if ( port && *port ) {
+ if( *port == '/' ) { /* A full pathname */
+ (void) snprintf(server_path, sizeof(server_path), "%s", port);
+ } else {
+ (void) snprintf(server_path, sizeof(server_path), "%s%s",
+ NAMEDNODENAME, port);
+ }
+ } else {
+ (void) snprintf(server_path, sizeof(server_path), "%s%ld",
+ NAMEDNODENAME, (long)getpid());
+ }
+
+ fd = TRANS(NAMEDOpenPipe)(server_path);
+ if (fd < 0) {
+ return -1;
+ }
+
/*
* Everything looks good: fill in the XtransConnInfo structure.
*/
if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
{
- PRMSG(1,"NAMEDOpenServer: failed to fill in addr info\n", 0,0,0);
+ prmsg(1,"NAMEDOpenServer: failed to fill in addr info\n");
+ TRANS(LocalClose)(ciptr);
return -1;
}
- return(pipefd[1]);
+ return fd;
#endif /* !NAMEDNODENAME */
}
static int
+TRANS(NAMEDResetListener) (XtransConnInfo ciptr)
+
+{
+ struct sockaddr_un *sockname=(struct sockaddr_un *) ciptr->addr;
+ struct stat statb;
+
+ prmsg(2,"NAMEDResetListener(%p, %d)\n", ciptr, ciptr->fd);
+
+ if (ciptr->fd != -1) {
+ /*
+ * see if the pipe has disappeared
+ */
+
+ if (stat (sockname->sun_path, &statb) == -1 ||
+ (statb.st_mode & S_IFMT) != S_IFIFO) {
+ prmsg(3, "Pipe %s trashed, recreating\n", sockname->sun_path);
+ TRANS(LocalClose)(ciptr);
+ ciptr->fd = TRANS(NAMEDOpenPipe)(sockname->sun_path);
+ if (ciptr->fd >= 0)
+ return TRANS_RESET_NEW_FD;
+ else
+ return TRANS_CREATE_LISTENER_FAILED;
+ }
+ }
+ return TRANS_RESET_NOOP;
+}
+
+static int
TRANS(NAMEDAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
{
struct strrecvfd str;
- PRMSG(2,"NAMEDAccept(%x->%d)\n", ciptr, ciptr->fd, 0 );
+ prmsg(2,"NAMEDAccept(%p->%d)\n", ciptr, ciptr->fd);
if( ioctl(ciptr->fd, I_RECVFD, &str ) < 0 ) {
- PRMSG(1, "NAMEDAccept: ioctl(I_RECVFD) failed, errno=%d\n", errno, 0,0 );
+ prmsg(1, "NAMEDAccept: ioctl(I_RECVFD) failed, errno=%d\n", errno);
*status = TRANS_ACCEPT_MISC_ERROR;
return(-1);
}
@@ -814,12 +899,11 @@ TRANS(NAMEDAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
/*
* Everything looks good: fill in the XtransConnInfo structure.
*/
-
+ newciptr->family=ciptr->family;
newciptr->addrlen=ciptr->addrlen;
- if( (newciptr->addr=(char *)malloc(newciptr->addrlen)) == NULL ) {
- PRMSG(1,
- "NAMEDAccept: failed to allocate memory for peer addr\n",
- 0,0,0);
+ if( (newciptr->addr = malloc(newciptr->addrlen)) == NULL ) {
+ prmsg(1,
+ "NAMEDAccept: failed to allocate memory for pipe addr\n");
close(str.fd);
*status = TRANS_ACCEPT_BAD_MALLOC;
return -1;
@@ -828,10 +912,9 @@ TRANS(NAMEDAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen);
newciptr->peeraddrlen=newciptr->addrlen;
- if( (newciptr->peeraddr=(char *)malloc(newciptr->peeraddrlen)) == NULL ) {
- PRMSG(1,
- "NAMEDAccept: failed to allocate memory for peer addr\n",
- 0,0,0);
+ if( (newciptr->peeraddr = malloc(newciptr->peeraddrlen)) == NULL ) {
+ prmsg(1,
+ "NAMEDAccept: failed to allocate memory for peer addr\n");
free(newciptr->addr);
close(str.fd);
*status = TRANS_ACCEPT_BAD_MALLOC;
@@ -847,14 +930,14 @@ TRANS(NAMEDAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
#endif /* TRANS_SERVER */
-#endif /* SVR4 */
+#endif /* LOCAL_TRANS_NAMED */
-#ifndef sun
+#if defined(LOCAL_TRANS_SCO)
/*
- * connect_spipe is used by the SCO and ISC connection types.
+ * connect_spipe is used by the SCO connection type.
*/
static int
connect_spipe(int fd1, int fd2)
@@ -879,7 +962,7 @@ connect_spipe(int fd1, int fd2)
}
/*
- * named_spipe is used by the SCO and ISC connection types.
+ * named_spipe is used by the SCO connection type.
*/
static int
@@ -905,294 +988,12 @@ named_spipe(int fd, char *path)
return(ret);
}
-/* SCO doesnt use the ISC transport type - it causes problems */
-#if !defined(__SCO__) && !defined(__UNIXWARE__)
+#endif /* defined(LOCAL_TRANS_SCO) */
-/* ISC */
-
-#ifdef TRANS_CLIENT
-
-static int
-TRANS(ISCOpenClient)(XtransConnInfo ciptr, char *port)
-
-{
-#ifdef ISCDEVNODENAME
- int fd,fds,server;
- char server_path[64];
- char server_dev_path[64];
- struct strfdinsert buf;
- long temp;
- mode_t spmode;
- struct stat filestat;
-#endif
-
- PRMSG(2,"ISCOpenClient(%s)\n", port, 0,0 );
-
-#if !defined(ISCDEVNODENAME)
- PRMSG(1,"ISCOpenClient: Protocol is not supported by a ISC connection\n", 0,0,0);
- return -1;
-#else
- (void) sprintf(server_path, ISCTMPNODENAME, port);
- (void) sprintf(server_dev_path, ISCDEVNODENAME, port);
-
- fd = fds = server = -1;
-
- if (stat(DEV_SPX, &filestat) == -1) {
- PRMSG(1, "ISCOpenClient: stat(%s) failed, errno=%d\n", DEV_SPX, errno, 0 );
- return(-1);
- }
-
- spmode = (filestat.st_mode & S_IFMT);
-
- if (stat(server_path, &filestat) != -1) {
- if ((filestat.st_mode & S_IFMT) == spmode) {
- if ((server = open(server_path, O_RDWR)) < 0) {
- PRMSG(1,"ISCOpenClient: failed to open %s\n",
- server_path, 0,0 );
- }
- }
- }
-
- if (server < 0) {
- /* try the alternate path */
- if (stat(server_dev_path, &filestat) != -1) {
- if ((filestat.st_mode & S_IFMT) == spmode) {
- if ((server = open(server_dev_path, O_RDWR)) < 0) {
- PRMSG(1,"ISCOpenClient: failed to open %s\n",
- server_dev_path, 0,0 );
- }
- }
- }
- }
-
- if (server < 0) {
- PRMSG(1,"ISCOpenClient: can't open either device %s or %s\n",
- server_path, server_dev_path, 0 );
- return -1;
- }
-
- if ((fds = open(DEV_SPX, O_RDWR)) < 0 ||
- (fd = open(DEV_SPX, O_RDWR)) < 0) {
- /* Failed to open all of the devices */
- PRMSG(1,"ISCOpenClient: can't open %s\n", DEV_SPX, 0,0 );
- (void) close(server);
- if (fds != -1)
- (void) close(fds);
- if (fd != -1)
- (void) close(fd);
- return -1;
- }
-
- /* make a STREAMS-pipe */
-
- buf.databuf.maxlen = -1;
- buf.databuf.len = -1;
- buf.databuf.buf = NULL;
- buf.ctlbuf.maxlen = sizeof(long);
- buf.ctlbuf.len = sizeof(long);
- buf.ctlbuf.buf = (caddr_t)&temp;
- buf.offset = 0;
- buf.fildes = fd;
- buf.flags = 0;
-
- if (ioctl(fds, I_FDINSERT, &buf) < 0 ||
- ioctl(server, I_SENDFD, fds) < 0) {
- PRMSG(1,"ISCOpenClient: ioctl(I_FDINSERT or I_SENDFD) failed\n",
- 0,0,0 );
- (void) close(server);
- (void) close(fds);
- (void) close(fd);
- return -1;
- }
-
- /*
- * Everything looks good: fill in the XtransConnInfo structure.
- */
-
- if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
- {
- PRMSG(1,"ISCOpenClient: failed to fill in addr info\n", 0, 0, 0);
- close(fd);
- return -1;
- }
-
- return (fd);
-
-#endif /* !ISCDEVNODENAME */
-}
-
-#endif /* TRANS_CLIENT */
-
-
-#ifdef TRANS_SERVER
-
-static int
-TRANS(ISCOpenServer)(XtransConnInfo ciptr, char *port)
-
-{
-#ifdef ISCDEVNODENAME
- int fd = -1,fds = -1;
- char server_path[64],server_unix_path[64];
- unsigned int mode = 0;
-#endif
-
- PRMSG(2,"ISCOpenServer(%s)\n", port, 0,0 );
-
-#if !defined(ISCDEVNODENAME)
- PRMSG(1,"ISCOpenServer: Protocol is not supported by a ISC connection\n", 0,0,0);
- return -1;
-#else
- (void) sprintf(server_path, ISCDEVNODENAME, port);
- (void) sprintf(server_unix_path, ISCTMPNODENAME, port);
-
-#ifdef HAS_STICKY_DIR_BIT
- mode = 01777;
-#else
- mode = 0777;
-#endif
-
- /* "/dev/X" */
- if (trans_mkdir(X_STREAMS_DIR, mode) == -1) {
- PRMSG (1, "ISCOpenServer: mkdir(%s) failed, errno = %d\n",
- X_STREAMS_DIR, errno, 0);
- return(-1);
- }
- /* "/dev/X/ISCCONN" */
- if (trans_mkdir(X_ISC_DIR, mode) == -1) {
- PRMSG (1, "ISCOpenServer: mkdir(%s) failed, errno = %d\n",
- X_ISC_DIR, errno, 0);
- return(-1);
- }
-
- unlink(server_path);
-
- if( ((fds=open(DEV_SPX, O_RDWR)) < 0) ||
- ((fd =open(DEV_SPX, O_RDWR)) < 0)) {
- PRMSG(1,"ISCOpenServer: failed to open %s\n", DEV_SPX, 0,0 );
- return -1;
- }
-
- if( (connect_spipe(fds, fd) < 0) ||
- (named_spipe(fds, server_path) < 0)) {
- PRMSG(1,"ISCOpenServer: failed connect pipes\n", 0,0,0 );
- close(fd);
- close(fds);
- return -1;
- }
-
-#if !defined(UNIXCONN)
- /*
- * If the UNIX Domain socket transport is not being used, then link this
- * device to the path /tmp/.X11-unix/X path.
- */
-#define X_UNIX_DIR "/tmp/.X11-unix"
-
- if (trans_mkdir(X_UNIX_DIR, mode) == -1) {
- PRMSG (1, "ISCOpenServer: mkdir(%s) failed, errno = %d\n",
- X_UNIX_DIR, errno, 0);
- return(-1);
- }
-
- unlink(server_unix_path);
-
-#ifdef SVR4
- /* we prefer symbolic links because hard links can't cross file systems */
- if( symlink(server_path, server_unix_path) < 0 )
- PRMSG(1,"ISCOpenServer: failed to link %s to %s\n",
- server_path, server_unix_path, 0 );
- /*
- * Don't make this failure fatal since the listener
- * is already established, and this just for compatability
- */
-#else
-#ifdef ISC40
- /* catch SIGSYS on symlink for ISC40 compiled binaries running on ISC30 */
- signal(SIGSYS,_dummy);
-#endif
- if( link(server_path, server_unix_path) < 0 )
-#ifdef ISC40
- if( symlink(server_path, server_unix_path) < 0 )
-#endif
- PRMSG(1,"ISCOpenServer: failed to link %s to %s\n",
- server_path, server_unix_path, 0 );
- /*
- * Don't make this failure fatal since the listener
- * is already established, and this just for compatability
- */
-#endif /* SVR4 */
-#endif /* !UNIXCONN */
- /*
- * Everything looks good: fill in the XtransConnInfo structure.
- */
- if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
- {
- PRMSG(1,"ISCOpenServer: failed to fill in addr info\n", 0, 0, 0);
- close(fd);
- return -1;
- }
-
- return fd;
-
-#endif /* !ISCDEVNODENAME */
-}
-
-static int
-TRANS(ISCAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
-
-{
- struct strrecvfd str;
-
- PRMSG(2,"ISCAccept(%d)\n", ciptr->fd, 0,0 );
-
- while (ioctl(ciptr->fd, I_RECVFD, &str) < 0) {
- if (errno != EAGAIN) {
- PRMSG(1,"ISCAccept: Can't read fildes", 0,0,0 );
- *status = TRANS_ACCEPT_MISC_ERROR;
- return(-1);
- }
- }
-
- /*
- * Everything looks good: fill in the XtransConnInfo structure.
- */
-
- newciptr->addrlen=ciptr->addrlen;
- if( (newciptr->addr=(char *)malloc(newciptr->addrlen)) == NULL ) {
- PRMSG(1,
- "ISCAccept: failed to allocate memory for peer addr\n",
- 0,0,0);
- close(str.fd);
- *status = TRANS_ACCEPT_BAD_MALLOC;
- return -1;
- }
-
- memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen);
-
- newciptr->peeraddrlen=newciptr->addrlen;
- if( (newciptr->peeraddr=(char *)malloc(newciptr->peeraddrlen)) == NULL ) {
- PRMSG(1,
- "ISCAccept: failed to allocate memory for peer addr\n",
- 0,0,0);
- free(newciptr->addr);
- close(str.fd);
- *status = TRANS_ACCEPT_BAD_MALLOC;
- return -1;
- }
-
- memcpy(newciptr->peeraddr,newciptr->addr,newciptr->peeraddrlen);
-
- *status = 0;
-
- return(str.fd);
-}
-
-#endif /* TRANS_SERVER */
-#endif /* !__SCO__ && !__UNIXWARE__ */
-
-
+#ifdef LOCAL_TRANS_SCO
/* SCO */
/*
@@ -1213,7 +1014,7 @@ TRANS(ISCAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
#ifdef TRANS_CLIENT
static int
-TRANS(SCOOpenClient)(XtransConnInfo ciptr, char *port)
+TRANS(SCOOpenClient)(XtransConnInfo ciptr, const char *port)
{
#ifdef SCORNODENAME
int fd, server, fl, ret;
@@ -1225,23 +1026,23 @@ TRANS(SCOOpenClient)(XtransConnInfo ciptr, char *port)
extern int getmsg(), putmsg();
#endif
- PRMSG(2,"SCOOpenClient(%s)\n", port, 0,0 );
+ prmsg(2,"SCOOpenClient(%s)\n", port);
if (!port || !port[0])
port = "0";
#if !defined(SCORNODENAME)
- PRMSG(2,"SCOOpenClient: Protocol is not supported by a SCO connection\n", 0,0,0);
+ prmsg(2,"SCOOpenClient: Protocol is not supported by a SCO connection\n");
return -1;
#else
(void) sprintf(server_path, SCORNODENAME, port);
if ((server = open(server_path, O_RDWR)) < 0) {
- PRMSG(1,"SCOOpenClient: failed to open %s\n", server_path, 0,0 );
+ prmsg(1,"SCOOpenClient: failed to open %s\n", server_path);
return -1;
}
if ((fd = open(DEV_SPX, O_RDWR)) < 0) {
- PRMSG(1,"SCOOpenClient: failed to open %s\n", DEV_SPX, 0,0 );
+ prmsg(1,"SCOOpenClient: failed to open %s\n", DEV_SPX);
close(server);
return -1;
}
@@ -1261,7 +1062,7 @@ TRANS(SCOOpenClient)(XtransConnInfo ciptr, char *port)
(void) signal(SIGALRM, savef);
if (ret < 0) {
- PRMSG(1,"SCOOpenClient: error from getmsg\n", 0,0,0 );
+ prmsg(1,"SCOOpenClient: error from getmsg\n");
close(fd);
close(server);
return -1;
@@ -1285,7 +1086,7 @@ TRANS(SCOOpenClient)(XtransConnInfo ciptr, char *port)
#endif
if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
{
- PRMSG(1,"SCOOpenClient: failed to fill addr info\n", 0, 0, 0);
+ prmsg(1,"SCOOpenClient: failed to fill addr info\n");
close(fd);
return -1;
}
@@ -1301,7 +1102,7 @@ TRANS(SCOOpenClient)(XtransConnInfo ciptr, char *port)
#ifdef TRANS_SERVER
static int
-TRANS(SCOOpenServer)(XtransConnInfo ciptr, char *port)
+TRANS(SCOOpenServer)(XtransConnInfo ciptr, const char *port)
{
#ifdef SCORNODENAME
char serverR_path[64];
@@ -1311,12 +1112,12 @@ TRANS(SCOOpenServer)(XtransConnInfo ciptr, char *port)
int fds = -1;
#endif
- PRMSG(2,"SCOOpenServer(%s)\n", port, 0,0 );
+ prmsg(2,"SCOOpenServer(%s)\n", port);
if (!port || !port[0])
port = "0";
#if !defined(SCORNODENAME)
- PRMSG(1,"SCOOpenServer: Protocol is not supported by a SCO connection\n", 0,0,0);
+ prmsg(1,"SCOOpenServer: Protocol is not supported by a SCO connection\n");
return -1;
#else
(void) sprintf(serverR_path, SCORNODENAME, port);
@@ -1328,19 +1129,23 @@ TRANS(SCOOpenServer)(XtransConnInfo ciptr, char *port)
if ((fds = open(DEV_SPX, O_RDWR)) < 0 ||
(fdr = open(DEV_SPX, O_RDWR)) < 0 ) {
- PRMSG(1,"SCOOpenServer: failed to open %s\n", DEV_SPX, 0,0 );
+ prmsg(1,"SCOOpenServer: failed to open %s\n", DEV_SPX);
+ if (fds >= 0)
+ close(fds);
+ if (fdr >= 0)
+ close(fdr);
return -1;
}
if (named_spipe (fds, serverS_path) == -1) {
- PRMSG(1,"SCOOpenServer: failed to create %s\n", serverS_path, 0, 0);
+ prmsg(1,"SCOOpenServer: failed to create %s\n", serverS_path);
close (fdr);
close (fds);
return -1;
}
if (named_spipe (fdr, serverR_path) == -1) {
- PRMSG(1,"SCOOpenServer: failed to create %s\n", serverR_path, 0, 0);
+ prmsg(1,"SCOOpenServer: failed to create %s\n", serverR_path);
close (fdr);
close (fds);
return -1;
@@ -1349,7 +1154,7 @@ TRANS(SCOOpenServer)(XtransConnInfo ciptr, char *port)
fds = open (serverS_path, O_RDWR | O_NDELAY);
if (fds < 0) {
- PRMSG(1,"SCOOpenServer: failed to open %s\n", serverS_path, 0, 0);
+ prmsg(1,"SCOOpenServer: failed to open %s\n", serverS_path);
return -1;
}
@@ -1362,22 +1167,22 @@ TRANS(SCOOpenServer)(XtransConnInfo ciptr, char *port)
mylock.l_start = 0;
mylock.l_len = 0;
if (fcntl (fds, F_SETLK, &mylock) < 0) {
- PRMSG(1,"SCOOpenServer: failed to lock %s\n", serverS_path, 0, 0);
+ prmsg(1,"SCOOpenServer: failed to lock %s\n", serverS_path);
close (fds);
return -1;
}
fdr = open (serverR_path, O_RDWR | O_NDELAY);
- if (fds < 0) {
- PRMSG(1,"SCOOpenServer: failed to open %s\n", serverR_path, 0, 0);
+ if (fdr < 0) {
+ prmsg(1,"SCOOpenServer: failed to open %s\n", serverR_path);
close (fds);
return -1;
}
#endif /* X11_t */
if (connect_spipe(fds, fdr)) {
- PRMSG(1,"SCOOpenServer: ioctl(I_FDINSERT) failed on %s\n",
- serverS_path, 0, 0);
+ prmsg(1,"SCOOpenServer: ioctl(I_FDINSERT) failed on %s\n",
+ serverS_path);
close (fdr);
close (fds);
return -1;
@@ -1391,7 +1196,7 @@ TRANS(SCOOpenServer)(XtransConnInfo ciptr, char *port)
ciptr->flags |= TRANS_NOUNLINK;
#endif
if (TRANS(FillAddrInfo) (ciptr, serverS_path, serverR_path) == 0) {
- PRMSG(1,"SCOOpenServer: failed to fill in addr info\n", 0,0,0);
+ prmsg(1,"SCOOpenServer: failed to fill in addr info\n");
close(fds);
close(fdr);
return -1;
@@ -1408,22 +1213,22 @@ TRANS(SCOAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
char c;
int fd;
- PRMSG(2,"SCOAccept(%d)\n", ciptr->fd, 0,0 );
+ prmsg(2,"SCOAccept(%d)\n", ciptr->fd);
if (read(ciptr->fd, &c, 1) < 0) {
- PRMSG(1,"SCOAccept: can't read from client\n",0,0,0);
+ prmsg(1,"SCOAccept: can't read from client\n");
*status = TRANS_ACCEPT_MISC_ERROR;
return(-1);
}
if( (fd = open(DEV_SPX, O_RDWR)) < 0 ) {
- PRMSG(1,"SCOAccept: can't open \"%s\"\n",DEV_SPX, 0,0 );
+ prmsg(1,"SCOAccept: can't open \"%s\"\n",DEV_SPX);
*status = TRANS_ACCEPT_MISC_ERROR;
return(-1);
}
if (connect_spipe (ciptr->fd, fd) < 0) {
- PRMSG(1,"SCOAccept: ioctl(I_FDINSERT) failed\n", 0, 0, 0);
+ prmsg(1,"SCOAccept: ioctl(I_FDINSERT) failed\n");
close (fd);
*status = TRANS_ACCEPT_MISC_ERROR;
return -1;
@@ -1434,10 +1239,9 @@ TRANS(SCOAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
*/
newciptr->addrlen=ciptr->addrlen;
- if( (newciptr->addr=(char *)malloc(newciptr->addrlen)) == NULL ) {
- PRMSG(1,
- "SCOAccept: failed to allocate memory for peer addr\n",
- 0,0,0);
+ if( (newciptr->addr = malloc(newciptr->addrlen)) == NULL ) {
+ prmsg(1,
+ "SCOAccept: failed to allocate memory for peer addr\n");
close(fd);
*status = TRANS_ACCEPT_BAD_MALLOC;
return -1;
@@ -1449,10 +1253,9 @@ TRANS(SCOAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
#endif
newciptr->peeraddrlen=newciptr->addrlen;
- if( (newciptr->peeraddr=(char *)malloc(newciptr->peeraddrlen)) == NULL ) {
- PRMSG(1,
- "SCOAccept: failed to allocate memory for peer addr\n",
- 0,0,0);
+ if( (newciptr->peeraddr = malloc(newciptr->peeraddrlen)) == NULL ) {
+ prmsg(1,
+ "SCOAccept: failed to allocate memory for peer addr\n");
free(newciptr->addr);
close(fd);
*status = TRANS_ACCEPT_BAD_MALLOC;
@@ -1467,41 +1270,42 @@ TRANS(SCOAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
}
#endif /* TRANS_SERVER */
-#endif /* sun */
+#endif /* LOCAL_TRANS_SCO */
#ifdef TRANS_REOPEN
-#ifndef sun
+#ifdef LOCAL_TRANS_PTS
static int
-TRANS(PTSReopenServer)(XtransConnInfo ciptr, int fd, char *port)
+TRANS(PTSReopenServer)(XtransConnInfo ciptr, int fd, const char *port)
{
#ifdef PTSNODENAME
char server_path[64];
#endif
- PRMSG(2,"PTSReopenServer(%d,%s)\n", fd, port, 0 );
+ prmsg(2,"PTSReopenServer(%d,%s)\n", fd, port);
#if !defined(PTSNODENAME)
- PRMSG(1,"PTSReopenServer: Protocol is not supported by a pts connection\n", 0,0,0);
+ prmsg(1,"PTSReopenServer: Protocol is not supported by a pts connection\n");
return 0;
#else
if (port && *port ) {
if( *port == '/' ) { /* A full pathname */
- (void) sprintf(server_path, "%s", port);
+ snprintf(server_path, sizeof(server_path), "%s", port);
} else {
- (void) sprintf(server_path, "%s%s", PTSNODENAME, port);
+ snprintf(server_path, sizeof(server_path), "%s%s",
+ PTSNODENAME, port);
}
} else {
- (void) sprintf(server_path, "%s%ld", PTSNODENAME, (long)getpid());
+ snprintf(server_path, sizeof(server_path), "%s%ld",
+ PTSNODENAME, (long)getpid());
}
if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
{
- PRMSG(1,"PTSReopenServer: failed to fill in addr info\n",
- 0,0,0);
+ prmsg(1,"PTSReopenServer: failed to fill in addr info\n");
return 0;
}
@@ -1510,36 +1314,39 @@ TRANS(PTSReopenServer)(XtransConnInfo ciptr, int fd, char *port)
#endif /* !PTSNODENAME */
}
-#endif /* !sun */
+#endif /* LOCAL_TRANS_PTS */
+
+#ifdef LOCAL_TRANS_NAMED
static int
-TRANS(NAMEDReopenServer)(XtransConnInfo ciptr, int fd, char *port)
+TRANS(NAMEDReopenServer)(XtransConnInfo ciptr, int fd _X_UNUSED, const char *port)
{
#ifdef NAMEDNODENAME
char server_path[64];
#endif
- PRMSG(2,"NAMEDReopenServer(%s)\n", port, 0,0 );
+ prmsg(2,"NAMEDReopenServer(%s)\n", port);
#if !defined(NAMEDNODENAME)
- PRMSG(1,"NAMEDReopenServer: Protocol is not supported by a NAMED connection\n", 0,0,0);
+ prmsg(1,"NAMEDReopenServer: Protocol is not supported by a NAMED connection\n");
return 0;
#else
if ( port && *port ) {
if( *port == '/' ) { /* A full pathname */
- (void) sprintf(server_path, "%s", port);
+ snprintf(server_path, sizeof(server_path),"%s", port);
} else {
- (void) sprintf(server_path, "%s%s", NAMEDNODENAME, port);
+ snprintf(server_path, sizeof(server_path), "%s%s",
+ NAMEDNODENAME, port);
}
} else {
- (void) sprintf(server_path, "%s%ld", NAMEDNODENAME, (long)getpid());
+ snprintf(server_path, sizeof(server_path), "%s%ld",
+ NAMEDNODENAME, (long)getpid());
}
if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
{
- PRMSG(1,"NAMEDReopenServer: failed to fill in addr info\n",
- 0,0,0);
+ prmsg(1,"NAMEDReopenServer: failed to fill in addr info\n");
return 0;
}
@@ -1548,51 +1355,24 @@ TRANS(NAMEDReopenServer)(XtransConnInfo ciptr, int fd, char *port)
#endif /* !NAMEDNODENAME */
}
-#ifndef sun
-#if !defined(__SCO__) && !defined(__UNIXWARE__)
-static int
-TRANS(ISCReopenServer)(XtransConnInfo ciptr, int fd, char *port)
-
-{
-#ifdef ISCDEVNODENAME
- char server_path[64], server_unix_path[64];
-#endif
-
- PRMSG(2,"ISCReopenServer(%s)\n", port, 0,0 );
+#endif /* LOCAL_TRANS_NAMED */
-#if !defined(ISCDEVNODENAME)
- PRMSG(1,"ISCReopenServer: Protocol is not supported by a ISC connection\n", 0,0,0);
- return 0;
-#else
- (void) sprintf(server_path, ISCDEVNODENAME, port);
- (void) sprintf(server_unix_path, ISCTMPNODENAME, port);
-
- if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
- {
- PRMSG(1, "ISCReopenServer: failed to fill in addr info\n", 0,0,0);
- return 0;
- }
-
- return 1;
-
-#endif /* !ISCDEVNODENAME */
-}
-#endif /* !__SCO__ && !__UNIXWARE__ */
+#ifdef LOCAL_TRANS_SCO
static int
-TRANS(SCOReopenServer)(XtransConnInfo ciptr, int fd, char *port)
+TRANS(SCOReopenServer)(XtransConnInfo ciptr, int fd, const char *port)
{
#ifdef SCORNODENAME
char serverR_path[64], serverS_path[64];
#endif
- PRMSG(2,"SCOReopenServer(%s)\n", port, 0,0 );
+ prmsg(2,"SCOReopenServer(%s)\n", port);
if (!port || !port[0])
port = "0";
#if !defined(SCORNODENAME)
- PRMSG(2,"SCOReopenServer: Protocol is not supported by a SCO connection\n", 0,0,0);
+ prmsg(2,"SCOReopenServer: Protocol is not supported by a SCO connection\n");
return 0;
#else
(void) sprintf(serverR_path, SCORNODENAME, port);
@@ -1603,7 +1383,7 @@ TRANS(SCOReopenServer)(XtransConnInfo ciptr, int fd, char *port)
#endif
if (TRANS(FillAddrInfo) (ciptr, serverS_path, serverR_path) == 0)
{
- PRMSG(1, "SCOReopenServer: failed to fill in addr info\n", 0,0,0);
+ prmsg(1, "SCOReopenServer: failed to fill in addr info\n");
return 0;
}
@@ -1612,7 +1392,7 @@ TRANS(SCOReopenServer)(XtransConnInfo ciptr, int fd, char *port)
#endif /* SCORNODENAME */
}
-#endif /* !sun */
+#endif /* LOCAL_TRANS_SCO */
#endif /* TRANS_REOPEN */
@@ -1624,12 +1404,12 @@ TRANS(SCOReopenServer)(XtransConnInfo ciptr, int fd, char *port)
*/
typedef struct _LOCALtrans2dev {
- char *transname;
+ const char *transname;
#ifdef TRANS_CLIENT
int (*devcotsopenclient)(
- XtransConnInfo, char * /*port*/
+ XtransConnInfo, const char * /*port*/
);
#endif /* TRANS_CLIENT */
@@ -1637,7 +1417,7 @@ typedef struct _LOCALtrans2dev {
#ifdef TRANS_SERVER
int (*devcotsopenserver)(
- XtransConnInfo, char * /*port*/
+ XtransConnInfo, const char * /*port*/
);
#endif /* TRANS_SERVER */
@@ -1645,7 +1425,7 @@ typedef struct _LOCALtrans2dev {
#ifdef TRANS_CLIENT
int (*devcltsopenclient)(
- XtransConnInfo, char * /*port*/
+ XtransConnInfo, const char * /*port*/
);
#endif /* TRANS_CLIENT */
@@ -1653,7 +1433,7 @@ typedef struct _LOCALtrans2dev {
#ifdef TRANS_SERVER
int (*devcltsopenserver)(
- XtransConnInfo, char * /*port*/
+ XtransConnInfo, const char * /*port*/
);
#endif /* TRANS_SERVER */
@@ -1663,19 +1443,23 @@ typedef struct _LOCALtrans2dev {
int (*devcotsreopenserver)(
XtransConnInfo,
int, /* fd */
- char * /* port */
+ const char * /* port */
);
int (*devcltsreopenserver)(
XtransConnInfo,
int, /* fd */
- char * /* port */
+ const char * /* port */
);
#endif /* TRANS_REOPEN */
#ifdef TRANS_SERVER
+ int (*devreset)(
+ XtransConnInfo /* ciptr */
+);
+
int (*devaccept)(
XtransConnInfo, XtransConnInfo, int *
);
@@ -1685,7 +1469,7 @@ typedef struct _LOCALtrans2dev {
} LOCALtrans2dev;
static LOCALtrans2dev LOCALtrans2devtab[] = {
-#ifndef sun
+#ifdef LOCAL_TRANS_PTS
{"",
#ifdef TRANS_CLIENT
TRANS(PTSOpenClient),
@@ -1704,6 +1488,7 @@ static LOCALtrans2dev LOCALtrans2devtab[] = {
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
+ NULL, /* ResetListener */
TRANS(PTSAccept)
#endif /* TRANS_SERVER */
},
@@ -1726,6 +1511,7 @@ static LOCALtrans2dev LOCALtrans2devtab[] = {
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
+ NULL, /* ResetListener */
TRANS(PTSAccept)
#endif /* TRANS_SERVER */
},
@@ -1748,10 +1534,11 @@ static LOCALtrans2dev LOCALtrans2devtab[] = {
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
+ NULL, /* ResetListener */
TRANS(PTSAccept)
#endif /* TRANS_SERVER */
},
-#else /* sun */
+#else /* !LOCAL_TRANS_PTS */
{"",
#ifdef TRANS_CLIENT
TRANS(NAMEDOpenClient),
@@ -1770,6 +1557,7 @@ static LOCALtrans2dev LOCALtrans2devtab[] = {
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
+ TRANS(NAMEDResetListener),
TRANS(NAMEDAccept)
#endif /* TRANS_SERVER */
},
@@ -1792,12 +1580,13 @@ static LOCALtrans2dev LOCALtrans2devtab[] = {
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
+ TRANS(NAMEDResetListener),
TRANS(NAMEDAccept)
#endif /* TRANS_SERVER */
},
-#endif /* sun */
+#endif /* !LOCAL_TRANS_PTS */
-#ifdef SVR4
+#ifdef LOCAL_TRANS_NAMED
{"named",
#ifdef TRANS_CLIENT
TRANS(NAMEDOpenClient),
@@ -1816,19 +1605,18 @@ static LOCALtrans2dev LOCALtrans2devtab[] = {
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
+ TRANS(NAMEDResetListener),
TRANS(NAMEDAccept)
#endif /* TRANS_SERVER */
},
-#endif /* SVR4 */
-#ifndef sun
-#if !defined(__SCO__) && !defined(__UNIXWARE__)
-{"isc",
+#ifdef __sun /* Alias "pipe" to named, since that's what Solaris called it */
+{"pipe",
#ifdef TRANS_CLIENT
- TRANS(ISCOpenClient),
+ TRANS(NAMEDOpenClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
- TRANS(ISCOpenServer),
+ TRANS(NAMEDOpenServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(OpenFail),
@@ -1837,15 +1625,19 @@ static LOCALtrans2dev LOCALtrans2devtab[] = {
TRANS(OpenFail),
#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
- TRANS(ISCReopenServer),
+ TRANS(NAMEDReopenServer),
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
- TRANS(ISCAccept)
+ TRANS(NAMEDResetListener),
+ TRANS(NAMEDAccept)
#endif /* TRANS_SERVER */
},
-#endif /* !__SCO__ && !__UNIXWARE__ */
+#endif /* __sun */
+#endif /* LOCAL_TRANS_NAMED */
+
+#ifdef LOCAL_TRANS_SCO
{"sco",
#ifdef TRANS_CLIENT
TRANS(SCOOpenClient),
@@ -1864,15 +1656,16 @@ static LOCALtrans2dev LOCALtrans2devtab[] = {
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
+ NULL, /* ResetListener */
TRANS(SCOAccept)
#endif /* TRANS_SERVER */
},
-#endif /* sun */
+#endif /* LOCAL_TRANS_SCO */
};
#define NUMTRANSPORTS (sizeof(LOCALtrans2devtab)/sizeof(LOCALtrans2dev))
-static char *XLOCAL=NULL;
+static const char *XLOCAL=NULL;
static char *workingXLOCAL=NULL;
static char *freeXLOCAL=NULL;
@@ -1880,29 +1673,27 @@ static char *freeXLOCAL=NULL;
#define DEF_XLOCAL "SCO:UNIX:PTS"
#elif defined(__UNIXWARE__)
#define DEF_XLOCAL "UNIX:PTS:NAMED:SCO"
+#elif defined(__sun)
+#define DEF_XLOCAL "UNIX:NAMED"
#else
-#define DEF_XLOCAL "UNIX:PTS:NAMED:ISC:SCO"
+#define DEF_XLOCAL "UNIX:PTS:NAMED:SCO"
#endif
static void
-TRANS(LocalInitTransports)(char *protocol)
+TRANS(LocalInitTransports)(const char *protocol)
{
- PRMSG(3,"LocalInitTransports(%s)\n", protocol, 0,0 );
+ prmsg(3,"LocalInitTransports(%s)\n", protocol);
if( strcmp(protocol,"local") && strcmp(protocol,"LOCAL") )
{
- workingXLOCAL=freeXLOCAL=(char *)malloc (strlen (protocol) + 1);
- if (workingXLOCAL)
- strcpy (workingXLOCAL, protocol);
+ workingXLOCAL = freeXLOCAL = strdup (protocol);
}
else {
XLOCAL=(char *)getenv("XLOCAL");
if(XLOCAL==NULL)
XLOCAL=DEF_XLOCAL;
- workingXLOCAL=freeXLOCAL=(char *)malloc (strlen (XLOCAL) + 1);
- if (workingXLOCAL)
- strcpy (workingXLOCAL, XLOCAL);
+ workingXLOCAL = freeXLOCAL = strdup (XLOCAL);
}
}
@@ -1910,7 +1701,7 @@ static void
TRANS(LocalEndTransports)(void)
{
- PRMSG(3,"LocalEndTransports()\n", 0,0,0 );
+ prmsg(3,"LocalEndTransports()\n");
free(freeXLOCAL);
}
@@ -1925,7 +1716,7 @@ TRANS(LocalGetNextTransport)(void)
int i,j;
char *typetocheck;
char typebuf[TYPEBUFSIZE];
- PRMSG(3,"LocalGetNextTransport()\n", 0,0,0 );
+ prmsg(3,"LocalGetNextTransport()\n");
while(1)
{
@@ -1940,7 +1731,7 @@ TRANS(LocalGetNextTransport)(void)
for(i=0;i<NUMTRANSPORTS;i++)
{
/*
- * This is equivilent to a case insensitive strcmp(),
+ * This is equivalent to a case insensitive strcmp(),
* but should be more portable.
*/
strncpy(typebuf,typetocheck,TYPEBUFSIZE);
@@ -1968,7 +1759,7 @@ TRANS(LocalGetNextTransport)(void)
*/
static int
-HostReallyLocal (char *host)
+HostReallyLocal (const char *host)
{
/*
@@ -1998,14 +1789,15 @@ HostReallyLocal (char *host)
static XtransConnInfo
-TRANS(LocalOpenClient)(int type, char *protocol, char *host, char *port)
+TRANS(LocalOpenClient)(int type, const char *protocol,
+ const char *host, const char *port)
{
LOCALtrans2dev *transptr;
XtransConnInfo ciptr;
int index;
- PRMSG(3,"LocalOpenClient()\n", 0,0,0 );
+ prmsg(3,"LocalOpenClient()\n");
/*
* Make sure 'host' is really local. If not, we return failure.
@@ -2017,9 +1809,9 @@ TRANS(LocalOpenClient)(int type, char *protocol, char *host, char *port)
if (strcmp (host, "unix") != 0 && !HostReallyLocal (host))
{
- PRMSG (1,
+ prmsg (1,
"LocalOpenClient: Cannot connect to non-local host %s\n",
- host, 0, 0);
+ host);
return NULL;
}
@@ -2036,10 +1828,10 @@ TRANS(LocalOpenClient)(int type, char *protocol, char *host, char *port)
*/
#endif /* X11_t */
- if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
+ if( (ciptr = calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
{
- PRMSG(1,"LocalOpenClient: calloc(1,%d) failed\n",
- sizeof(struct _XtransConnInfo),0,0 );
+ prmsg(1,"LocalOpenClient: calloc(1,%lu) failed\n",
+ sizeof(struct _XtransConnInfo));
return NULL;
}
@@ -2056,19 +1848,14 @@ TRANS(LocalOpenClient)(int type, char *protocol, char *host, char *port)
case XTRANS_OPEN_COTS_CLIENT:
ciptr->fd=transptr->devcotsopenclient(ciptr,port);
break;
- case XTRANS_OPEN_CLTS_CLIENT:
- ciptr->fd=transptr->devcltsopenclient(ciptr,port);
- break;
case XTRANS_OPEN_COTS_SERVER:
- case XTRANS_OPEN_CLTS_SERVER:
- PRMSG(1,
- "LocalOpenClient: Should not be opening a server with this function\n",
- 0,0,0);
+ prmsg(1,
+ "LocalOpenClient: Should not be opening a server with this function\n");
break;
default:
- PRMSG(1,
+ prmsg(1,
"LocalOpenClient: Unknown Open type %d\n",
- type, 0,0 );
+ type);
}
if( ciptr->fd >= 0 )
break;
@@ -2094,13 +1881,14 @@ TRANS(LocalOpenClient)(int type, char *protocol, char *host, char *port)
#ifdef TRANS_SERVER
static XtransConnInfo
-TRANS(LocalOpenServer)(int type, char *protocol, char *host, char *port)
+TRANS(LocalOpenServer)(int type, const char *protocol,
+ const char *host _X_UNUSED, const char *port)
{
int i;
XtransConnInfo ciptr;
- PRMSG(2,"LocalOpenServer(%d,%s,%s)\n", type, protocol, port);
+ prmsg(2,"LocalOpenServer(%d,%s,%s)\n", type, protocol, port);
#if defined(X11_t)
/*
@@ -2111,10 +1899,10 @@ TRANS(LocalOpenServer)(int type, char *protocol, char *host, char *port)
*/
#endif /* X11_t */
- if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
+ if( (ciptr = calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
{
- PRMSG(1,"LocalOpenServer: calloc(1,%d) failed\n",
- sizeof(struct _XtransConnInfo),0,0 );
+ prmsg(1,"LocalOpenServer: calloc(1,%lu) failed\n",
+ sizeof(struct _XtransConnInfo));
return NULL;
}
@@ -2125,20 +1913,15 @@ TRANS(LocalOpenServer)(int type, char *protocol, char *host, char *port)
switch( type )
{
case XTRANS_OPEN_COTS_CLIENT:
- case XTRANS_OPEN_CLTS_CLIENT:
- PRMSG(1,
- "LocalOpenServer: Should not be opening a client with this function\n",
- 0,0,0);
+ prmsg(1,
+ "LocalOpenServer: Should not be opening a client with this function\n");
break;
case XTRANS_OPEN_COTS_SERVER:
ciptr->fd=LOCALtrans2devtab[i].devcotsopenserver(ciptr,port);
break;
- case XTRANS_OPEN_CLTS_SERVER:
- ciptr->fd=LOCALtrans2devtab[i].devcltsopenserver(ciptr,port);
- break;
default:
- PRMSG(1,"LocalOpenServer: Unknown Open type %d\n",
- type ,0,0);
+ prmsg(1,"LocalOpenServer: Unknown Open type %d\n",
+ type );
}
if( ciptr->fd >= 0 ) {
ciptr->priv=(char *)&LOCALtrans2devtab[i];
@@ -2158,18 +1941,18 @@ TRANS(LocalOpenServer)(int type, char *protocol, char *host, char *port)
#ifdef TRANS_REOPEN
static XtransConnInfo
-TRANS(LocalReopenServer)(int type, int index, int fd, char *port)
+TRANS(LocalReopenServer)(int type, int index, int fd, const char *port)
{
XtransConnInfo ciptr;
int stat = 0;
- PRMSG(2,"LocalReopenServer(%d,%d,%d)\n", type, index, fd);
+ prmsg(2,"LocalReopenServer(%d,%d,%d)\n", type, index, fd);
- if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
+ if( (ciptr = calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
{
- PRMSG(1,"LocalReopenServer: calloc(1,%d) failed\n",
- sizeof(struct _XtransConnInfo),0,0 );
+ prmsg(1,"LocalReopenServer: calloc(1,%lu) failed\n",
+ sizeof(struct _XtransConnInfo));
return NULL;
}
@@ -2180,12 +1963,9 @@ TRANS(LocalReopenServer)(int type, int index, int fd, char *port)
case XTRANS_OPEN_COTS_SERVER:
stat = LOCALtrans2devtab[index].devcotsreopenserver(ciptr,fd,port);
break;
- case XTRANS_OPEN_CLTS_SERVER:
- stat = LOCALtrans2devtab[index].devcltsreopenserver(ciptr,fd,port);
- break;
- default:
- PRMSG(1,"LocalReopenServer: Unknown Open type %d\n",
- type ,0,0);
+ default:
+ prmsg(1,"LocalReopenServer: Unknown Open type %d\n",
+ type );
}
if( stat > 0 ) {
@@ -2210,11 +1990,11 @@ TRANS(LocalReopenServer)(int type, int index, int fd, char *port)
#ifdef TRANS_CLIENT
static XtransConnInfo
-TRANS(LocalOpenCOTSClient)(Xtransport *thistrans, char *protocol,
- char *host, char *port)
+TRANS(LocalOpenCOTSClient)(Xtransport *thistrans _X_UNUSED, const char *protocol,
+ const char *host, const char *port)
{
- PRMSG(2,"LocalOpenCOTSClient(%s,%s,%s)\n",protocol,host,port);
+ prmsg(2,"LocalOpenCOTSClient(%s,%s,%s)\n",protocol,host,port);
return TRANS(LocalOpenClient)(XTRANS_OPEN_COTS_CLIENT, protocol, host, port);
}
@@ -2225,15 +2005,15 @@ TRANS(LocalOpenCOTSClient)(Xtransport *thistrans, char *protocol,
#ifdef TRANS_SERVER
static XtransConnInfo
-TRANS(LocalOpenCOTSServer)(Xtransport *thistrans, char *protocol,
- char *host, char *port)
+TRANS(LocalOpenCOTSServer)(Xtransport *thistrans, const char *protocol,
+ const char *host, const char *port)
{
char *typetocheck = NULL;
int found = 0;
char typebuf[TYPEBUFSIZE];
- PRMSG(2,"LocalOpenCOTSServer(%s,%s,%s)\n",protocol,host,port);
+ prmsg(2,"LocalOpenCOTSServer(%s,%s,%s)\n",protocol,host,port);
/* Check if this local type is in the XLOCAL list */
TRANS(LocalInitTransports)("local");
@@ -2255,7 +2035,7 @@ TRANS(LocalOpenCOTSServer)(Xtransport *thistrans, char *protocol,
TRANS(LocalEndTransports)();
if (!found) {
- PRMSG(3,"LocalOpenCOTSServer: disabling %s\n",thistrans->TransName,0,0);
+ prmsg(3,"LocalOpenCOTSServer: disabling %s\n",thistrans->TransName);
thistrans->flags |= TRANS_DISABLED;
return NULL;
}
@@ -2265,46 +2045,15 @@ TRANS(LocalOpenCOTSServer)(Xtransport *thistrans, char *protocol,
#endif /* TRANS_SERVER */
-
-#ifdef TRANS_CLIENT
-
-static XtransConnInfo
-TRANS(LocalOpenCLTSClient)(Xtransport *thistrans, char *protocol,
- char *host, char *port)
-
-{
- PRMSG(2,"LocalOpenCLTSClient(%s,%s,%s)\n",protocol,host,port);
-
- return TRANS(LocalOpenClient)(XTRANS_OPEN_CLTS_CLIENT, protocol, host, port);
-}
-
-#endif /* TRANS_CLIENT */
-
-
-#ifdef TRANS_SERVER
-
-static XtransConnInfo
-TRANS(LocalOpenCLTSServer)(Xtransport *thistrans, char *protocol,
- char *host, char *port)
-
-{
- PRMSG(2,"LocalOpenCLTSServer(%s,%s,%s)\n",protocol,host,port);
-
- return TRANS(LocalOpenServer)(XTRANS_OPEN_CLTS_SERVER, protocol, host, port);
-}
-
-#endif /* TRANS_SERVER */
-
-
#ifdef TRANS_REOPEN
static XtransConnInfo
-TRANS(LocalReopenCOTSServer)(Xtransport *thistrans, int fd, char *port)
+TRANS(LocalReopenCOTSServer)(Xtransport *thistrans, int fd, const char *port)
{
int index;
- PRMSG(2,"LocalReopenCOTSServer(%d,%s)\n", fd, port, 0);
+ prmsg(2,"LocalReopenCOTSServer(%d,%s)\n", fd, port);
for(index=1;index<NUMTRANSPORTS;index++)
{
@@ -2322,30 +2071,6 @@ TRANS(LocalReopenCOTSServer)(Xtransport *thistrans, int fd, char *port)
index, fd, port);
}
-static XtransConnInfo
-TRANS(LocalReopenCLTSServer)(Xtransport *thistrans, int fd, char *port)
-
-{
- int index;
-
- PRMSG(2,"LocalReopenCLTSServer(%d,%s)\n", fd, port, 0);
-
- for(index=1;index<NUMTRANSPORTS;index++)
- {
- if( strcmp(thistrans->TransName,
- LOCALtrans2devtab[index].transname) == 0 )
- break;
- }
-
- if (index >= NUMTRANSPORTS)
- {
- return (NULL);
- }
-
- return TRANS(LocalReopenServer)(XTRANS_OPEN_CLTS_SERVER,
- index, fd, port);
-}
-
#endif /* TRANS_REOPEN */
@@ -2354,7 +2079,7 @@ static int
TRANS(LocalSetOption)(XtransConnInfo ciptr, int option, int arg)
{
- PRMSG(2,"LocalSetOption(%d,%d,%d)\n",ciptr->fd,option,arg);
+ prmsg(2,"LocalSetOption(%d,%d,%d)\n",ciptr->fd,option,arg);
return -1;
}
@@ -2363,14 +2088,31 @@ TRANS(LocalSetOption)(XtransConnInfo ciptr, int option, int arg)
#ifdef TRANS_SERVER
static int
-TRANS(LocalCreateListener)(XtransConnInfo ciptr, char *port, unsigned int flags)
+TRANS(LocalCreateListener)(XtransConnInfo ciptr, const char *port,
+ unsigned int flags _X_UNUSED)
{
- PRMSG(2,"LocalCreateListener(%x->%d,%s)\n",ciptr,ciptr->fd,port);
+ prmsg(2,"LocalCreateListener(%p->%d,%s)\n",ciptr,ciptr->fd,port);
return 0;
}
+static int
+TRANS(LocalResetListener)(XtransConnInfo ciptr)
+
+{
+ LOCALtrans2dev *transptr;
+
+ prmsg(2,"LocalResetListener(%p)\n",ciptr);
+
+ transptr=(LOCALtrans2dev *)ciptr->priv;
+ if (transptr->devreset != NULL) {
+ return transptr->devreset(ciptr);
+ }
+ return TRANS_RESET_NOOP;
+}
+
+
static XtransConnInfo
TRANS(LocalAccept)(XtransConnInfo ciptr, int *status)
@@ -2378,14 +2120,14 @@ TRANS(LocalAccept)(XtransConnInfo ciptr, int *status)
XtransConnInfo newciptr;
LOCALtrans2dev *transptr;
- PRMSG(2,"LocalAccept(%x->%d)\n", ciptr, ciptr->fd,0);
+ prmsg(2,"LocalAccept(%p->%d)\n", ciptr, ciptr->fd);
transptr=(LOCALtrans2dev *)ciptr->priv;
- if( (newciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo)))==NULL )
+ if( (newciptr = calloc(1,sizeof(struct _XtransConnInfo)))==NULL )
{
- PRMSG(1,"LocalAccept: calloc(1,%d) failed\n",
- sizeof(struct _XtransConnInfo),0,0 );
+ prmsg(1,"LocalAccept: calloc(1,%lu) failed\n",
+ sizeof(struct _XtransConnInfo));
*status = TRANS_ACCEPT_BAD_MALLOC;
return NULL;
}
@@ -2412,10 +2154,11 @@ TRANS(LocalAccept)(XtransConnInfo ciptr, int *status)
#ifdef TRANS_CLIENT
static int
-TRANS(LocalConnect)(XtransConnInfo ciptr, char *host, char *port)
+TRANS(LocalConnect)(XtransConnInfo ciptr,
+ const char *host _X_UNUSED, const char *port)
{
- PRMSG(2,"LocalConnect(%x->%d,%s)\n", ciptr, ciptr->fd, port);
+ prmsg(2,"LocalConnect(%p->%d,%s)\n", ciptr, ciptr->fd, port);
return 0;
}
@@ -2427,9 +2170,9 @@ static int
TRANS(LocalBytesReadable)(XtransConnInfo ciptr, BytesReadable_t *pend )
{
- PRMSG(2,"LocalBytesReadable(%x->%d,%x)\n", ciptr, ciptr->fd, pend);
+ prmsg(2,"LocalBytesReadable(%p->%d,%p)\n", ciptr, ciptr->fd, pend);
-#if defined(ISC) || defined(SCO325)
+#if defined(SCO325)
return ioctl(ciptr->fd, I_NREAD, (char *)pend);
#else
return ioctl(ciptr->fd, FIONREAD, (char *)pend);
@@ -2440,7 +2183,7 @@ static int
TRANS(LocalRead)(XtransConnInfo ciptr, char *buf, int size)
{
- PRMSG(2,"LocalRead(%d,%x,%d)\n", ciptr->fd, buf, size );
+ prmsg(2,"LocalRead(%d,%p,%d)\n", ciptr->fd, buf, size );
return read(ciptr->fd,buf,size);
}
@@ -2449,7 +2192,7 @@ static int
TRANS(LocalWrite)(XtransConnInfo ciptr, char *buf, int size)
{
- PRMSG(2,"LocalWrite(%d,%x,%d)\n", ciptr->fd, buf, size );
+ prmsg(2,"LocalWrite(%d,%p,%d)\n", ciptr->fd, buf, size );
return write(ciptr->fd,buf,size);
}
@@ -2458,7 +2201,7 @@ static int
TRANS(LocalReadv)(XtransConnInfo ciptr, struct iovec *buf, int size)
{
- PRMSG(2,"LocalReadv(%d,%x,%d)\n", ciptr->fd, buf, size );
+ prmsg(2,"LocalReadv(%d,%p,%d)\n", ciptr->fd, buf, size );
return READV(ciptr,buf,size);
}
@@ -2467,7 +2210,7 @@ static int
TRANS(LocalWritev)(XtransConnInfo ciptr, struct iovec *buf, int size)
{
- PRMSG(2,"LocalWritev(%d,%x,%d)\n", ciptr->fd, buf, size );
+ prmsg(2,"LocalWritev(%d,%p,%d)\n", ciptr->fd, buf, size );
return WRITEV(ciptr,buf,size);
}
@@ -2476,7 +2219,7 @@ static int
TRANS(LocalDisconnect)(XtransConnInfo ciptr)
{
- PRMSG(2,"LocalDisconnect(%x->%d)\n", ciptr, ciptr->fd, 0);
+ prmsg(2,"LocalDisconnect(%p->%d)\n", ciptr, ciptr->fd);
return 0;
}
@@ -2488,7 +2231,7 @@ TRANS(LocalClose)(XtransConnInfo ciptr)
struct sockaddr_un *sockname=(struct sockaddr_un *) ciptr->addr;
int ret;
- PRMSG(2,"LocalClose(%x->%d)\n", ciptr, ciptr->fd ,0);
+ prmsg(2,"LocalClose(%p->%d)\n", ciptr, ciptr->fd );
ret=close(ciptr->fd);
@@ -2510,7 +2253,7 @@ TRANS(LocalCloseForCloning)(XtransConnInfo ciptr)
{
int ret;
- PRMSG(2,"LocalCloseForCloning(%x->%d)\n", ciptr, ciptr->fd ,0);
+ prmsg(2,"LocalCloseForCloning(%p->%d)\n", ciptr, ciptr->fd );
/* Don't unlink path */
@@ -2524,22 +2267,22 @@ TRANS(LocalCloseForCloning)(XtransConnInfo ciptr)
* MakeAllCOTSServerListeners() will go through the entire Xtransports[]
* array defined in Xtrans.c and try to OpenCOTSServer() for each entry.
* We will add duplicate entries to that table so that the OpenCOTSServer()
- * function will get called once for each type of local transport.
+ * function will get called once for each type of local transport.
*
* The TransName is in lowercase, so it will never match during a normal
* call to SelectTransport() in Xtrans.c.
*/
#ifdef TRANS_SERVER
-static char * local_aliases[] = {
-# ifndef sun
+static const char * local_aliases[] = {
+# ifdef LOCAL_TRANS_PTS
"pts",
# endif
"named",
-# ifndef sun
-# if !defined(__SCO__) && !defined(__UNIXWARE__)
- "isc",
+# ifdef __sun
+ "pipe", /* compatibility with Solaris Xlib */
# endif
+# ifdef LOCAL_TRANS_SCO
"sco",
# endif
NULL };
@@ -2556,20 +2299,13 @@ Xtransport TRANS(LocalFuncs) = {
local_aliases,
TRANS(LocalOpenCOTSServer),
#endif /* TRANS_SERVER */
-#ifdef TRANS_CLIENT
- TRANS(LocalOpenCLTSClient),
-#endif /* TRANS_CLIENT */
-#ifdef TRANS_SERVER
- TRANS(LocalOpenCLTSServer),
-#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(LocalReopenCOTSServer),
- TRANS(LocalReopenCLTSServer),
#endif
TRANS(LocalSetOption),
#ifdef TRANS_SERVER
TRANS(LocalCreateListener),
- NULL, /* ResetListener */
+ TRANS(LocalResetListener),
TRANS(LocalAccept),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
@@ -2580,12 +2316,16 @@ Xtransport TRANS(LocalFuncs) = {
TRANS(LocalWrite),
TRANS(LocalReadv),
TRANS(LocalWritev),
+#if XTRANS_SEND_FDS
+ TRANS(LocalSendFdInvalid),
+ TRANS(LocalRecvFdInvalid),
+#endif
TRANS(LocalDisconnect),
TRANS(LocalClose),
TRANS(LocalCloseForCloning),
};
-#ifndef sun
+#ifdef LOCAL_TRANS_PTS
Xtransport TRANS(PTSFuncs) = {
/* Local Interface */
@@ -2598,20 +2338,13 @@ Xtransport TRANS(PTSFuncs) = {
NULL,
TRANS(LocalOpenCOTSServer),
#endif /* TRANS_SERVER */
-#ifdef TRANS_CLIENT
- TRANS(LocalOpenCLTSClient),
-#endif /* TRANS_CLIENT */
-#ifdef TRANS_SERVER
- TRANS(LocalOpenCLTSServer),
-#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(LocalReopenCOTSServer),
- TRANS(LocalReopenCLTSServer),
#endif
TRANS(LocalSetOption),
#ifdef TRANS_SERVER
TRANS(LocalCreateListener),
- NULL, /* ResetListener */
+ TRANS(LocalResetListener),
TRANS(LocalAccept),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
@@ -2622,12 +2355,18 @@ Xtransport TRANS(PTSFuncs) = {
TRANS(LocalWrite),
TRANS(LocalReadv),
TRANS(LocalWritev),
+#if XTRANS_SEND_FDS
+ TRANS(LocalSendFdInvalid),
+ TRANS(LocalRecvFdInvalid),
+#endif
TRANS(LocalDisconnect),
TRANS(LocalClose),
TRANS(LocalCloseForCloning),
};
-#endif /* sun */
+#endif /* LOCAL_TRANS_PTS */
+
+#ifdef LOCAL_TRANS_NAMED
Xtransport TRANS(NAMEDFuncs) = {
/* Local Interface */
@@ -2640,20 +2379,13 @@ Xtransport TRANS(NAMEDFuncs) = {
NULL,
TRANS(LocalOpenCOTSServer),
#endif /* TRANS_SERVER */
-#ifdef TRANS_CLIENT
- TRANS(LocalOpenCLTSClient),
-#endif /* TRANS_CLIENT */
-#ifdef TRANS_SERVER
- TRANS(LocalOpenCLTSServer),
-#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(LocalReopenCOTSServer),
- TRANS(LocalReopenCLTSServer),
#endif
TRANS(LocalSetOption),
#ifdef TRANS_SERVER
TRANS(LocalCreateListener),
- NULL, /* ResetListener */
+ TRANS(LocalResetListener),
TRANS(LocalAccept),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
@@ -2664,17 +2396,20 @@ Xtransport TRANS(NAMEDFuncs) = {
TRANS(LocalWrite),
TRANS(LocalReadv),
TRANS(LocalWritev),
+#if XTRANS_SEND_FDS
+ TRANS(LocalSendFdInvalid),
+ TRANS(LocalRecvFdInvalid),
+#endif
TRANS(LocalDisconnect),
TRANS(LocalClose),
TRANS(LocalCloseForCloning),
};
-#ifndef sun
-#if !defined(__SCO__) && !defined(__UNIXWARE__)
-Xtransport TRANS(ISCFuncs) = {
+#ifdef __sun
+Xtransport TRANS(PIPEFuncs) = {
/* Local Interface */
- "isc",
- TRANS_LOCAL,
+ "pipe",
+ TRANS_ALIAS | TRANS_LOCAL,
#ifdef TRANS_CLIENT
TRANS(LocalOpenCOTSClient),
#endif /* TRANS_CLIENT */
@@ -2682,20 +2417,13 @@ Xtransport TRANS(ISCFuncs) = {
NULL,
TRANS(LocalOpenCOTSServer),
#endif /* TRANS_SERVER */
-#ifdef TRANS_CLIENT
- TRANS(LocalOpenCLTSClient),
-#endif /* TRANS_CLIENT */
-#ifdef TRANS_SERVER
- TRANS(LocalOpenCLTSServer),
-#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(LocalReopenCOTSServer),
- TRANS(LocalReopenCLTSServer),
#endif
TRANS(LocalSetOption),
#ifdef TRANS_SERVER
TRANS(LocalCreateListener),
- NULL, /* ResetListener */
+ TRANS(LocalResetListener),
TRANS(LocalAccept),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
@@ -2706,11 +2434,19 @@ Xtransport TRANS(ISCFuncs) = {
TRANS(LocalWrite),
TRANS(LocalReadv),
TRANS(LocalWritev),
+#if XTRANS_SEND_FDS
+ TRANS(LocalSendFdInvalid),
+ TRANS(LocalRecvFdInvalid),
+#endif
TRANS(LocalDisconnect),
TRANS(LocalClose),
TRANS(LocalCloseForCloning),
};
-#endif /* !__SCO__ && !__UNIXWARE__ */
+#endif /* __sun */
+#endif /* LOCAL_TRANS_NAMED */
+
+
+#ifdef LOCAL_TRANS_SCO
Xtransport TRANS(SCOFuncs) = {
/* Local Interface */
"sco",
@@ -2722,20 +2458,13 @@ Xtransport TRANS(SCOFuncs) = {
NULL,
TRANS(LocalOpenCOTSServer),
#endif /* TRANS_SERVER */
-#ifdef TRANS_CLIENT
- TRANS(LocalOpenCLTSClient),
-#endif /* TRANS_CLIENT */
-#ifdef TRANS_SERVER
- TRANS(LocalOpenCLTSServer),
-#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(LocalReopenCOTSServer),
- TRANS(LocalReopenCLTSServer),
#endif
TRANS(LocalSetOption),
#ifdef TRANS_SERVER
TRANS(LocalCreateListener),
- NULL, /* ResetListener */
+ TRANS(LocalResetListener),
TRANS(LocalAccept),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
@@ -2746,8 +2475,12 @@ Xtransport TRANS(SCOFuncs) = {
TRANS(LocalWrite),
TRANS(LocalReadv),
TRANS(LocalWritev),
+#if XTRANS_SEND_FDS
+ TRANS(LocalSendFdInvalid),
+ TRANS(LocalRecvFdInvalid),
+#endif
TRANS(LocalDisconnect),
TRANS(LocalClose),
TRANS(LocalCloseForCloning),
};
-#endif /* sun */
+#endif /* LOCAL_TRANS_SCO */
diff --git a/nx-X11/lib/xtrans/Xtransos2.c b/nx-X11/lib/xtrans/Xtransos2.c
deleted file mode 100644
index 6d9dcb675..000000000
--- a/nx-X11/lib/xtrans/Xtransos2.c
+++ /dev/null
@@ -1,886 +0,0 @@
-
-/*
- * (c) Copyright 1996 by Sebastien Marineau and Holger Veit
- * <marineau@genie.uottawa.ca>
- * <Holger.Veit@gmd.de>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * 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
- * HOLGER VEIT 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 Sebastien Marineau or Holger Veit shall not be
- * used in advertising or otherwise to promote the sale, use or other dealings
- * in this Software without prior written authorization from Holger Veit or Sebastien Marineau.
- *
- */
-
-/* Implementation of the OS/2 local pipe transport layer */
-
-#define INCL_DOSNMPIPES
-#define INCL_DOSPROCESS
-#define INCL_DOSERRORS
-#define INCL_DOSFILEMGR
-#undef BYTE
-#undef BOOL
-#include <os2.h>
-
-#ifdef XSERV_t
-extern HEV hPipeSem;
-BOOL init_server_pipes();
-#endif
-
-/*************************************************************************
- * Independent Layer
- *************************************************************************/
-#ifdef TRANS_CLIENT
-
-static XtransConnInfo
-TRANS(Os2OpenClient)(Xtransport *thistrans, char *protocol,
- char *host, char *port)
-{
- APIRET rc;
- HFILE hfd,hServer;
- ULONG action,byteWritten,State;
- char pipename[256],clientname[256];
- char server_string[256];
- struct sockaddr *addr_name;
- unsigned char pipe_len;
- XtransConnInfo ciptr;
- static int unique_id=0;
- int i,namelen,try;
-
- PRMSG(2,"Os2OpenClient(%s,%s,%s)\n",protocol,host,port);
-
- /* test, whether the host is really local, i.e. either
- * "os2" or "local"
- */
- if (strcmp(protocol,"os2") && strcmp(protocol,"local")) {
- PRMSG (1,
- "Os2OpenClient: Cannot connect to non-local host %s\n",
- host, 0, 0);
- return NULL;
- }
-
- /* make the pipename */
-
- if (port && *port ) {
- if( *port == '/' ) { /* A full pathname */
- (void) sprintf(pipename, "\\PIPE\\X\\%s,", port);
- } else {
- (void) sprintf(pipename, "%s%s", "\\PIPE\\X\\xf86.", port);
- }
- } else {
- (void) sprintf(pipename, "\\PIPE\\X\\xfree86"); }
-
- PRMSG(5, "Os2OpenClient: Creating pipe %s\n",pipename, 0,0 );
-
- /* make a connection entry */
- if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL ) {
- PRMSG(1,"Os2OpenClient: calloc(1,%d) failed\n",
- sizeof(struct _XtransConnInfo),0,0 );
- return NULL;
- }
-
- /* open the pipe. Try ten times before giving up at 500ms intervals*/
- try = 0;
- do {
- rc = DosOpen(pipename,&hServer, &action, 0,
- FILE_NORMAL, FILE_OPEN,
- OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYWRITE,
- (PEAOP2)NULL);
- if(rc == 0) break;
- if (try >=10) {
- PRMSG(1,"Os2OpenClient: Open server pipe %s failed, rc=%d\n",
- pipename,rc,0 );
- PRMSG(1,"\tProbable causes: either the XServer is not running, or has not started properly,\n",
- 0,0,0 );
- PRMSG(1,"\tor the DISPLAY variable is set incorrectly.\n",
- 0,0,0 );
- free(ciptr);
- return NULL;
- }
- try ++;
- DosSleep(500);
- } while (rc != 0);
-
-/* OK, now we are talking to the server. Generate a unique pipe name and pass it to
- * the server. Make the pipe and wait for server to connect */
-
- sprintf(clientname,"\\PIPE\\X\\%d.%d",getpid(),unique_id++);
-
- rc = DosCreateNPipe (clientname, &hfd,
- NP_NOINHERIT | NP_ACCESS_DUPLEX,
- 1 | NP_NOWAIT | NP_TYPE_BYTE | NP_READMODE_BYTE,
- 16384, 16384, 0);
- if (rc != 0){
- PRMSG(1, "Os2OpenClient: Unable to create pipe %s\n", pipename,0,0 );
- DosClose(hfd);
- pipe_len=0;
- DosWrite(hServer,&pipe_len,1,&byteWritten);
- DosClose(hServer);
- free(ciptr);
- return(NULL);
- }
-
- /* Connect to the pipe. */
-
- rc = DosConnectNPipe (hfd);
- if (rc != 0 && rc != ERROR_PIPE_NOT_CONNECTED)
- {
- PRMSG(1, "Os2OpenClient: Unable to connect to pipe %s\n", pipename,0,0 );
- DosClose (hfd);
- DosClose(hServer);
- free(ciptr);
- return (NULL);
- }
-
-/* Now write name to server on hServer */
- server_string[0]=(char) strlen(clientname)+1;
- strcpy(&server_string[1],clientname);
- rc = DosWrite(hServer,server_string,(ULONG)server_string[0]+1,&byteWritten);
- if(rc != 0){ /* Could not write to server pipe? */
- PRMSG(1, "Os2OpenClient: Error writing to server pipe, handle=%d, rc=%d, w=%d\n",
- hServer,rc,byteWritten );
- DosClose(hServer);
- DosClose(hfd);
- free(ciptr);
- return(NULL);
- }
-
- PRMSG (5, "Os2OpenCLient: Wrote pipename %s to server; len %d written %d \n",
- &server_string[1],server_string[0]+1,byteWritten);
-
-
-/* The server will respond by opening the pipe. Wait for that for 30 secs */
-
- i=0;
- DosSleep(50); /* Give it time to catch up but minimize race condition*/
- rc = DosConnectNPipe(hfd);
- while((rc == ERROR_PIPE_NOT_CONNECTED)&&(i++<60)) {
- DosSleep(500);
- rc = DosConnectNPipe(hfd);
- }
-
- if(rc != 0){ /* Server has not responded! */
- PRMSG(1, "Os2OpenClient: Timeout on wait for server response, handle=%d, rc=%d\n",hServer,rc,0 );
- PRMSG(1, "\tProbable cause: the XServer has exited or crashed while the connection was being established\n",0,0,0 );
- PRMSG(1, "\tor the XServer is too busy to respond.\n",0,0,0 );
- DosClose(hServer);
- DosClose(hfd);
- free(ciptr);
- return(NULL);
- }
-
-/* OK, the server has connected! Fill-in the info and return */
-
- DosClose(hServer);
-
-/* Last check: make sure client is connected! */
-
- rc = DosQueryNPHState(hfd,&State);
- if(rc != 0){ /* Client is not connected! */
- PRMSG(1, "Os2OpenClient: Client pipe does not appear connected. rc=%d, h=%d\n",rc,hfd,0 );
- PRMSG(1, "\tProbable cause: the XServer has just exited.\n",0,0,0 );
- DosClose(hfd);
- free(ciptr);
- return(NULL);
- }
-
- namelen=sizeof(struct sockaddr);
- if ((ciptr->addr = (char *) malloc (namelen)) == NULL)
- {
- PRMSG (1, "Os2OpenClient: Can't allocate space for the addr\n",
- 0, 0, 0);
- DosClose(hfd);
- free(ciptr);
- return(NULL);
- }
- ciptr->addrlen = namelen;
- ((struct sockaddr *)ciptr->addr)->sa_family = AF_UNIX;
- strcpy(((struct sockaddr *)ciptr->addr)->sa_data, "local");
-
- if ((ciptr->peeraddr = (char *) malloc (namelen)) == NULL)
- {
- PRMSG (1, "Os2OpenCLient: Can't allocate space for the addr\n",
- 0, 0, 0);
- DosClose(hfd);
- free(ciptr->addr);
- free(ciptr);
- return(NULL);
- }
- ciptr->peeraddrlen = namelen;
- ((struct sockaddr *)ciptr->peeraddr)->sa_family = AF_UNIX;
- strcpy (((struct sockaddr *)ciptr->peeraddr)->sa_data,"local");
-
- PRMSG (5, "Os2OpenCLient: Filled in struct: len %d %d name %s\n",
- ciptr->addrlen,ciptr->peeraddrlen,((struct sockaddr *)ciptr->peeraddr)->sa_data);
-
-
- ciptr->index=hfd;
- ciptr->family=AF_UNIX;
- if((ciptr->fd=_imphandle(hfd))<0){
- PRMSG(1, "Os2OpenClient: Could not import the pipe handle into EMX\n",0,0,0 );
- PRMSG(1, "\tProbable cause: EMX has run out of free file handles.\n",0,0,0 );
- DosClose(hfd);
- free(ciptr->addr);
- free(ciptr->peeraddr);
- free(ciptr);
- return(NULL);
- }
- PRMSG(5, "Os2OpenClient: pipe handle %d EMX handle %d\n",ciptr->index,ciptr->fd,0 );
- fcntl(ciptr->fd,F_SETFL,O_NDELAY);
- fcntl(ciptr->fd,F_SETFD,FD_CLOEXEC);
- return ciptr;
-}
-#endif /* TRANS_CLIENT */
-
-#ifdef TRANS_SERVER
-static XtransConnInfo
-TRANS(Os2OpenServer)(Xtransport *thistrans, char *protocol,
- char *host, char *port)
-{
- APIRET rc;
- HFILE hfd;
- ULONG action;
- char pipename[256];
- struct sockaddr *addr_name;
- XtransConnInfo ciptr;
- int namelen;
-
-#ifdef XSERV_t
- if (! init_server_pipes()) return(NULL);
-#endif
-
- PRMSG(2,"Os2OpenServer(%s,%s,%s)\n",protocol,host,port);
-
- if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
- {
- PRMSG(1,"Os2OpenServer: calloc(1,%d) failed\n",
- sizeof(struct _XtransConnInfo),0,0 );
- return NULL;
- }
-
-
- if (port && *port ) {
- if( *port == '/' ) { /* A full pathname */
- (void) sprintf(pipename, "\\PIPE\\X\\%s", port);
- } else {
- (void) sprintf(pipename, "%s%s", "\\PIPE\\X\\xf86.", port);
- }
- } else {
- (void) sprintf(pipename, "\\PIPE\\X\\xfree86");
- }
-
- PRMSG(5, "Os2OpenServer: Creating pipe %s\n",pipename, 0,0 );
-
- rc = DosCreateNPipe (pipename, &hfd,
- NP_NOINHERIT | NP_ACCESS_INBOUND,
- 1 | NP_NOWAIT | NP_TYPE_BYTE | NP_READMODE_BYTE,
- 0, 8192, 0);
- if (rc != 0){
- PRMSG(1, "Os2OpenServer: Unable to create pipe %s, rc=%d\n", pipename,rc,0 );
- PRMSG(1, "\tProbable cause: there is already another XServer running on display :%s\n",port,0,0 );
- DosClose(hfd);
- free(ciptr);
- return(NULL);
- }
-
- /* Connect to the pipe. */
-
- rc = DosConnectNPipe (hfd);
- if (rc != 0 && rc != ERROR_PIPE_NOT_CONNECTED)
- {
- PRMSG(1, "Os2OpenServer: Unable to connect to pipe %s\n", pipename,0,0 );
- DosClose (hfd);
- free(ciptr);
- return (NULL);
- }
-
-/* Pipe is now connected and waiting for client connect */
-
-/*** Put in info ***/
-
- namelen=sizeof(struct sockaddr);
- if ((ciptr->addr = (char *) malloc (namelen)) == NULL)
- {
- PRMSG (1, "Os2OpenServer: Can't allocate space for the addr\n",
- 0, 0, 0);
- DosClose(hfd);
- free(ciptr);
- return(NULL);
- }
- ciptr->addrlen = namelen;
- ((struct sockaddr *)ciptr->addr)->sa_family = AF_UNIX;
- strcpy (((struct sockaddr *)ciptr->addr)->sa_data, "local");
-
- if ((ciptr->peeraddr = (char *) malloc (namelen)) == NULL)
- {
- PRMSG (1, "Os2OpenServer: Can't allocate space for the addr\n",
- 0, 0, 0);
- DosClose(hfd);
- free(ciptr->addr);
- free(ciptr);
- return(NULL);
- }
-
- ciptr->peeraddrlen = namelen;
- ((struct sockaddr *)ciptr->peeraddr)->sa_family = AF_UNIX;
- strcpy(((struct sockaddr *)ciptr->peeraddr)->sa_data,"local");
-
- PRMSG (5, "Os2OpenServer: Filled in struct: len %d %d name %s\n",
- ciptr->addrlen,ciptr->peeraddrlen,((struct sockaddr *)ciptr->peeraddr)->sa_data);
-
- ciptr->index=hfd; /* Save this for later use in this unused member of struct */
- ciptr->flags=1; /* Listener */
- ciptr->family=AF_UNIX;
-
- if((ciptr->fd=_imphandle(hfd))<0){
- DosClose(hfd);
- free(ciptr->addr);
- free(ciptr->peeraddr);
- free(ciptr);
- return(NULL);
- }
- PRMSG(5, "Os2OpenServer: Pipe handle %d EMX handle %d",ciptr->index,ciptr->fd,0 );
-
-#ifdef XSERV_t
-/* Attach the pipe sem to the pipe. Use handle index as key */
- rc = DosSetNPipeSem(ciptr->fd, (HSEM)hPipeSem, ciptr->fd);
- if (rc){
- PRMSG(1, "Os2OpenCOTSServer: Could not attach sem %d to pipe %d, rc=%d\n",
- hPipeSem,ciptr->fd,rc);
- DosClose(ciptr->fd);
- free(ciptr->addr);
- free(ciptr->peeraddr);
- free(ciptr);
- return(NULL);
- }
-#endif
-
- fcntl(ciptr->fd,F_SETFL,O_NDELAY);
- fcntl(ciptr->fd,F_SETFD,FD_CLOEXEC);
- return(ciptr);
-}
-#endif /* TRANS_SERVER */
-
-#ifdef TRANS_CLIENT
-static XtransConnInfo
-TRANS(Os2OpenCLTSClient)(Xtransport *thistrans, char *protocol,
- char *host, char *port)
-{
- PRMSG(2,"Os2OpenCLTSClient(%s,%s,%s)\n",protocol,host,port);
- return TRANS(Os2OpenClient)(thistrans, protocol, host, port);
-}
-#endif /* TRANS_CLIENT */
-
-#ifdef TRANS_CLIENT
-static XtransConnInfo
-TRANS(Os2OpenCOTSClient)(Xtransport *thistrans, char *protocol,
- char *host, char *port)
-{
- PRMSG(2,"Os2OpenCOTSClient(%s,%s,%s)\n",protocol,host,port);
- return TRANS(Os2OpenClient)(thistrans, protocol, host, port);
-}
-#endif /* TRANS_CLIENT */
-
-
-#ifdef TRANS_SERVER
-static XtransConnInfo
-TRANS(Os2OpenCLTSServer)(Xtransport *thistrans, char *protocol,
- char *host, char *port)
-{
- PRMSG(2,"Os2OpenCLTSServer(%s,%s,%s)\n",protocol,host,port);
- return TRANS(Os2OpenServer)(thistrans, protocol, host, port);
-}
-#endif /* TRANS_SERVER */
-
-
-#ifdef TRANS_SERVER
-static XtransConnInfo
-TRANS(Os2OpenCOTSServer)(Xtransport *thistrans, char *protocol,
- char *host, char *port)
-{
- PRMSG(2,"Os2OpenCOTSServer(%s,%s,%s)\n",protocol,host,port);
- return TRANS(Os2OpenServer)(thistrans, protocol, host, port);
-}
-#endif /* TRANS_SERVER */
-
-
-#ifdef TRANS_REOPEN
-static XtransConnInfo
-TRANS(Os2ReopenCOTSServer)(Xtransport *thistrans, int fd, char *port)
-{
-
- XtransConnInfo ciptr;
- char addr_name[256];
- int namelen;
-
- PRMSG(2,"Os2ReopenCOTSServer(%d,%s)\n", fd, port, 0);
-
- if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
- {
- PRMSG(1,"Os2ReopenCOTSServer: calloc(1,%d) failed\n",
- sizeof(struct _XtransConnInfo),0,0 );
- return NULL;
- }
-
- strcpy(addr_name,"local");
- namelen=sizeof(addr_name);
- if ((ciptr->addr = (char *) malloc (namelen)) == NULL)
- {
- PRMSG (1, "Os2ReopenCOTSServer: Can't allocate space for the addr\n",
- 0, 0, 0);
- free(ciptr);
- return(NULL);
- }
-
- ciptr->addrlen = namelen;
- memcpy (ciptr->addr, addr_name, ciptr->addrlen);
- if ((ciptr->peeraddr = (char *) malloc (namelen)) == NULL)
- {
- PRMSG (1, "Os2ReopenCOTSServer: Can't allocate space for the addr\n",
- 0, 0, 0);
- free(ciptr);
- return(NULL);
- }
-
- ciptr->peeraddrlen = namelen;
- memcpy (ciptr->peeraddr,addr_name, ciptr->addrlen);
-
- ciptr->fd = fd;
- ciptr->family=AF_UNIX;
- ciptr->flags=1;
- PRMSG(1,"Os2ReopenCOTSServer: Filled-in info for handle %d on port %s.\n", fd, port, 0);
-
- return(ciptr);
-}
-
-static XtransConnInfo
-TRANS(Os2ReopenCLTSServer)(Xtransport *thistrans, int fd, char *port)
-{
- PRMSG(2,"Os2ReopenCLTSServer(%d,%s)\n", fd, port, 0);
- return TRANS(Os2ReopenCOTSServer)(thistrans, fd, port);
-}
-#endif
-
-static
-TRANS(Os2SetOption)(XtransConnInfo ciptr, int option, int arg)
-{
- PRMSG(2,"Os2SetOption(%d,%d,%d)\n",ciptr->fd,option,arg);
- return -1;
-}
-
-#ifdef TRANS_SERVER
-
-static
-TRANS(Os2CreateListener)(XtransConnInfo ciptr, char *port, unsigned int flags)
-{
- PRMSG(2,"Os2CreateListener(%x->%d,%s)\n",ciptr,ciptr->fd,port);
- return 0;
-}
-
-static XtransConnInfo
-TRANS(Os2Accept)(XtransConnInfo ciptr, int *status)
-{
- XtransConnInfo newciptr;
- HFILE hClient;
- unsigned char length;
- ULONG action;
- char clientname[256];
- struct sockaddr *addr_name;
- int in,namelen;
- APIRET rc;
-
-
- PRMSG(2,"Os2Accept(%x->%d)\n", ciptr, ciptr->fd,0);
- if( (newciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo)))==NULL )
- {
- PRMSG(1,"Os2Accept: calloc(1,%d) failed\n",
- sizeof(struct _XtransConnInfo),0,0 );
- *status = TRANS_ACCEPT_BAD_MALLOC;
- return NULL;
- }
-
-/* Read in length of client pipe name. If fails, then reset server pipe */
- if((in=read(ciptr->fd,&length,1))<=0){
- PRMSG(2,"Os2Accept: Error reading incoming connection, in=%d, error=%d\n",
- in,errno,0 );
- *status = TRANS_ACCEPT_MISC_ERROR;
- free(newciptr);
- rc = DosDisConnectNPipe(ciptr->fd);
- rc = DosConnectNPipe (ciptr->fd);
- if (rc != 0 && rc != ERROR_PIPE_NOT_CONNECTED)
- {
- PRMSG(1, "Os2Accept: Unable to reconnect server pipe %d\n", ciptr->fd,0,0 );
- }
- return NULL;
- }
- PRMSG(5, "Os2Accept: Bytes to read for name: %d\n",length,0,0 );
-
-
-/* Check length for valid length ?? */
-
-/* Now read in length bytes from pipe for client pipe name */
- if((in=read(ciptr->fd,clientname,length))<=0){
- PRMSG(2,"Os2Accept: Error reading incoming connection, in=%d, error=%d\n",
- in,errno,0 );
- *status = TRANS_ACCEPT_MISC_ERROR;
- free(newciptr);
- rc = DosDisConnectNPipe(ciptr->fd);
- rc = DosConnectNPipe (ciptr->fd);
- if (rc != 0 && rc != ERROR_PIPE_NOT_CONNECTED)
- {
- PRMSG(1, "Os2Accept: Unable to reconnect server pipe %d\n", ciptr->fd,0,0 );
- }
- return NULL;
- }
- clientname[length]='\0';
- PRMSG(5, "Os2Accept: Server name %s length %d\n",clientname,length,0 );
-
-
-/* Now we have the client pipe name. Open it with DosOpen */
-
- rc = DosOpen(clientname,&hClient, &action, 0,
- FILE_NORMAL, FILE_OPEN,
- OPEN_FLAGS_NOINHERIT | OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYREADWRITE,
- (PEAOP2)NULL);
-
- PRMSG(5, "Os2Accept: Open pipe %s, handle = %d, rc=%d\n",clientname,hClient,rc );
-
- if (rc) {
- PRMSG(1,"Os2Accept: Open pipe %s to client failed, rc=%d\n",
- clientname,rc,0 );
- PRMSG(1, "\tProbable cause: the client has exited or timed-out.\n",0,0,0 );
- free(newciptr);
- rc = DosDisConnectNPipe(ciptr->fd);
- rc = DosConnectNPipe (ciptr->fd);
- if (rc != 0 && rc != ERROR_PIPE_NOT_CONNECTED)
- {
- PRMSG(1, "Os2Accept: Unable to reconnect server pipe %d\n", ciptr->fd,0,0 );
- }
- return NULL;
- }
-
- rc = DosSetNPHState (hClient, NP_NOWAIT | NP_READMODE_BYTE);
- if (rc != 0)
- {
- PRMSG(1,"Os2Accept: Could not set pipe %s to non-blocking mode, rc=%d\n",
- hClient,rc,0 );
- free(newciptr);
- rc = DosDisConnectNPipe(ciptr->fd);
- rc = DosConnectNPipe (ciptr->fd);
- if (rc != 0 && rc != ERROR_PIPE_NOT_CONNECTED)
- {
- PRMSG(1, "Os2Accept: Unable to reconnect server pipe %d\n", ciptr->fd,0,0 );
- }
- return NULL;
- }
-
-/* OK, we seem to be well connected to client. Now disconnect server pipe and put again in listen */
-
- rc = DosDisConnectNPipe(ciptr->fd);
- rc = DosConnectNPipe (ciptr->fd);
- PRMSG(5, "Os2Accept: Reconnecting server pipe %d, rc = %d\n",ciptr->fd,rc,0 );
-
- if (rc != 0 && rc != ERROR_PIPE_NOT_CONNECTED)
- {
- PRMSG(1, "Os2Accept: Unable to reconnect server pipe %d\n", ciptr->fd,0,0 );
- } /* Consider this non-fatal for present connection */
-
-/* And finally fill-in info in newciptr */
-
- namelen=sizeof(struct sockaddr);
- if ((newciptr->addr = (char *) malloc (namelen)) == NULL)
- {
- PRMSG (1, "Os2Accept: Can't allocate space for the addr\n",
- 0, 0, 0);
- DosClose(hClient);
- free(newciptr);
- return(NULL);
- }
-
- newciptr->addrlen = namelen;
- ((struct sockaddr *)newciptr->addr)->sa_family = AF_UNIX;
- strcpy (((struct sockaddr *)newciptr->addr)->sa_data, "local");
-
- if ((newciptr->peeraddr = (char *) malloc (namelen)) == NULL)
- {
- PRMSG (1, "Os2Accept: Can't allocate space for the addr\n",
- 0, 0, 0);
- DosClose(hClient);
- free(ciptr->addr);
- free(newciptr);
- return(NULL);
- }
-
- newciptr->peeraddrlen = namelen;
- ((struct sockaddr *)newciptr->peeraddr)->sa_family = AF_UNIX;
- strcpy (((struct sockaddr *)newciptr->peeraddr)->sa_data, "local");
-
- PRMSG (5, "Os2Accept: Filled in struct: len %d %d name %s\n",
- newciptr->addrlen,newciptr->peeraddrlen,newciptr->peeraddr);
-
-
- newciptr->index=hClient;
- newciptr->family=AF_UNIX;
- if((newciptr->fd=_imphandle(hClient))<0){
- PRMSG(1,"Os2Accept: Could not import pipe %d into EMX, errno=%d\n",
- hClient,errno,0 );
- PRMSG(1, "\tProbable cause: EMX has run out of file handles.\n",0,0,0 );
- DosClose(hClient);
- free(newciptr->addr);
- free(newciptr->peeraddr);
- free(newciptr);
- return(NULL);
- }
- PRMSG(5, "Os2Accept: Pipe handle %d EMX handle %d",newciptr->index,newciptr->fd,0 );
-
-#ifdef XSERV_t
-/* Attach the pipe sem to the pipe. Use handle index as key */
- rc = DosSetNPipeSem(newciptr->fd, (HSEM)hPipeSem, newciptr->fd);
- if (rc){
- PRMSG(1, "Os2OpenCOTSServer: Could not attach sem %d to pipe %d, rc=%d\n",
- hPipeSem,newciptr->fd,rc);
- DosClose(newciptr->fd);
- free(newciptr->addr);
- free(newciptr->peeraddr);
- free(newciptr);
- return(NULL);
- }
-#endif
-
- fcntl(ciptr->fd,F_SETFL,O_NDELAY);
- fcntl(ciptr->fd,F_SETFD,FD_CLOEXEC);
- *status=0;
- return newciptr;
-}
-
-#endif /* TRANS_SERVER */
-
-#ifdef TRANS_CLIENT
-
-static
-TRANS(Os2Connect)(XtransConnInfo ciptr, char *host, char *port)
-{
- PRMSG(2,"Os2Connect(%x->%d,%s)\n", ciptr, ciptr->fd, port);
- return 0;
-}
-
-#endif /* TRANS_CLIENT */
-
-static int
-TRANS(Os2BytesReadable)(XtransConnInfo ciptr, BytesReadable_t *pend )
-{
- ULONG rc, state, nread;
- AVAILDATA avail;
- char buffer;
-
- PRMSG(2,"Os2BytesReadable(%x->%d,%x)\n", ciptr, ciptr->fd, pend);
-
- rc = DosPeekNPipe (ciptr->fd, &buffer, 0, &nread, &avail, &state);
- if (rc != 0)
- {
- errno = EPIPE;
- *pend = 0;
- return -1;
- }
- if (state == NP_STATE_CLOSING)
- {
- errno = EPIPE;
- *pend = 0;
- return -1;
- }
- errno = 0;
- *pend = avail.cbpipe;
- return 0;
-}
-
-static int
-TRANS(Os2Read)(XtransConnInfo ciptr, char *buf, int size)
-{
- int ret;
- APIRET rc;
- ULONG ulRead;
- PRMSG(2,"Os2Read(%d,%x,%d)\n", ciptr->fd, buf, size );
- errno = 0;
- rc = DosRead(ciptr->fd, buf, size, &ulRead);
- if (rc == 0){
- ret = ulRead;
- }
- else if ((rc == 232) || (rc == 231)){
- errno = EAGAIN;
- ret = -1;
- }
- else if (rc == 6){
- errno = EBADF;
- ret = -1;
- }
- else if ((rc == 109) || (rc == 230) || (rc == 233)){
- errno = EPIPE;
- ret = -1;
- }
- else {
- PRMSG(2,"Os2Read: Unknown return code from DosRead, fd %d rc=%d\n", ciptr->fd,rc,0 );
- errno = EINVAL;
- ret = -1;
- }
- return (ret);
-}
-
-static int
-TRANS(Os2Write)(XtransConnInfo ciptr, char *buf, int size)
-{
- int ret;
- APIRET rc;
- ULONG nWritten;
- PRMSG(2,"Os2Write(%d,%x,%d)\n", ciptr->fd, buf, size );
- rc = DosWrite(ciptr->fd, buf, size, &nWritten);
- if (rc == 0){
- ret = nWritten;
- if(nWritten == 0) {
- errno=EAGAIN;
- ret = -1;
- }
- }
- else if ((rc == 39) || (rc == 112)){
- errno = EAGAIN;
- ret = -1;
- }
- else if ((rc == 109) || (rc == 230) || (rc == 233)){
- errno = EPIPE;
- ret = -1;
- }
- else if (rc == 6){
- errno=EBADF;
- ret = -1;
- }
- else {
- PRMSG(2,"(Os2Write)Unknown return code from DosWrite, fd %d rc=%d\n", ciptr->fd,rc,0 );
- errno = EINVAL;
- ret = -1;
- }
- return (ret);
-}
-
-static int
-TRANS(Os2Readv)(XtransConnInfo ciptr, struct iovec *buf, int size)
-{
- int ret;
- PRMSG(2,"Os2Readv(%d,%x,%d)\n", ciptr->fd, buf, size );
- ret = READV(ciptr,buf,size);
- if ((ret <0) && (errno == EINVAL)) errno = EPIPE;
- return (ret);
-}
-
-static int
-TRANS(Os2Writev)(XtransConnInfo ciptr, struct iovec *buf, int size)
-{
- int ret;
- PRMSG(2,"Os2Writev(%d,%x,%d)\n", ciptr->fd, buf, size );
- ret = WRITEV(ciptr,buf,size);
- if ((ret <0) && (errno == EINVAL)) errno = EPIPE;
- if ((ret <0) && (errno == ENOSPC)) errno = EAGAIN;
- return (ret);
-}
-
-static int
-TRANS(Os2Disconnect)(XtransConnInfo ciptr)
-{
- PRMSG(2,"Os2Disconnect(%x->%d)\n", ciptr, ciptr->fd, 0);
- return 0;
-}
-
-static int
-TRANS(Os2Close)(XtransConnInfo ciptr)
-{
- int ret;
- PRMSG(2,"Os2Close(%x->%d)\n", ciptr, ciptr->fd ,0);
- ret=close(ciptr->fd);
- return ret;
-}
-
-static int
-TRANS(Os2CloseForCloning)(XtransConnInfo ciptr)
-{
- int ret;
-
- PRMSG(2,"Os2CloseForCloning(%x->%d)\n", ciptr, ciptr->fd ,0);
- ret=close(ciptr->fd);
- return ret;
-}
-
-
-Xtransport TRANS(OS2LocalFuncs) = {
- /* Local Interface */
- "local",
- TRANS_LOCAL,
-#ifdef TRANS_CLIENT
- TRANS(Os2OpenCOTSClient),
-#endif /* TRANS_CLIENT */
-#ifdef TRANS_SERVER
- NULL,
- TRANS(Os2OpenCOTSServer),
-#endif /* TRANS_SERVER */
-#ifdef TRANS_CLIENT
- TRANS(Os2OpenCLTSClient),
-#endif /* TRANS_CLIENT */
-#ifdef TRANS_SERVER
- TRANS(Os2OpenCLTSServer),
-#endif /* TRANS_SERVER */
-#ifdef TRANS_REOPEN
- TRANS(Os2ReopenCOTSServer),
- TRANS(Os2ReopenCLTSServer),
-#endif
- TRANS(Os2SetOption),
-#ifdef TRANS_SERVER
- TRANS(Os2CreateListener),
- NULL, /* ResetListener */
- TRANS(Os2Accept),
-#endif /* TRANS_SERVER */
-#ifdef TRANS_CLIENT
- TRANS(Os2Connect),
-#endif /* TRANS_CLIENT */
- TRANS(Os2BytesReadable),
- TRANS(Os2Read),
- TRANS(Os2Write),
- TRANS(Os2Readv),
- TRANS(Os2Writev),
- TRANS(Os2Disconnect),
- TRANS(Os2Close),
- TRANS(Os2CloseForCloning),
-};
-
-#ifdef XSERV_t
-/* This function is used in the server to initialize the semaphore used with pipes */
-
-BOOL init_server_pipes()
-{
- static BOOL first_time=TRUE;
- ULONG rc;
-
- if(first_time){
- rc = DosCreateEventSem(NULL, &hPipeSem,DC_SEM_SHARED,FALSE);
- if (rc){
- PRMSG(1,"Os2OpenListener (init_server_pipes): Could not create pipe semaphore, rc=%d\n",
- rc,0,0);
- return(FALSE);
- }
- first_time=FALSE;
- }
-return(TRUE);
-}
-#endif /* XSERV_t */
diff --git a/nx-X11/lib/xtrans/Xtranssock.c b/nx-X11/lib/xtrans/Xtranssock.c
index 06c7719bf..62bfca734 100644
--- a/nx-X11/lib/xtrans/Xtranssock.c
+++ b/nx-X11/lib/xtrans/Xtranssock.c
@@ -24,9 +24,30 @@
/**************************************************************************/
/*
+ * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+/*
Copyright 1993, 1994, 1998 The Open Group
-Copyright 2002 Sun Microsystems, Inc. All rights reserved.
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
@@ -50,9 +71,7 @@ not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from the copyright holders.
-*/
-
-/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
*
* All Rights Reserved
*
@@ -108,21 +127,14 @@ from the copyright holders.
#ifdef UNIXCONN
#ifndef X_NO_SYS_UN
-#ifndef Lynx
#include <sys/un.h>
-#else
-#include <un.h>
-#endif
#endif
#include <sys/stat.h>
#endif
-#if defined(hpux) || (defined(MOTOROLA) && defined(SYSV))
-#define NO_TCP_H
-#endif
#ifndef NO_TCP_H
-#if defined(__osf__) || defined(linux) || defined(__GLIBC__) || defined(AIXV5)
+#if defined(linux) || defined(__GLIBC__)
#include <sys/param.h>
#endif /* osf */
#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
@@ -133,17 +145,11 @@ from the copyright holders.
#endif /* !NO_TCP_H */
#include <sys/ioctl.h>
-#if defined(SVR4) && !defined(DGUX) && !defined(_SEQUENT_)
+#if defined(SVR4) || defined(__SVR4)
#include <sys/filio.h>
#endif
-#if (defined(i386) && defined(SYSV)) && !defined(SCO325) && !defined(sun)
-#include <net/errno.h>
-#endif
-
-#if (defined(i386) && defined(SYSV)) && (!defined(ISC) || !defined(I_NREAD) || defined(SCO325)) || defined(_SEQUENT_)
-#include <sys/stropts.h>
-#endif
+#include <unistd.h>
#else /* !WIN32 */
@@ -169,37 +175,10 @@ from the copyright holders.
#undef SO_DONTLINGER
#endif
-#if defined(__UNIXOS2__)
-#if defined(NOT_EMX09A)
-static int IBMsockInit = 0;
-#define SocketInitOnce()\
- if (!IBMsockInit) {\
- sock_init();\
- IBMsockInit = 1;\
- }
-
-
-#undef EINTR
-#define EINTR SOCEINTR
-#undef EINVAL
-#define EINVAL SOCEINVAL
-#undef errno
-#define errno sock_errno()
-#undef close
-#define close soclose
-#undef ioctl
-#define ioctl sockioctl
-#else
-#define SocketInitOnce() /**/
-#endif
-/* this is still not there */
-#define SOCKET int
-#else
/* others don't need this */
#define SocketInitOnce() /**/
-#endif
-#if defined(linux)
+#ifdef linux
#define HAVE_ABSTRACT_SOCKETS
#endif
@@ -212,6 +191,7 @@ static int IBMsockInit = 0;
#ifndef BACKLOG
#define BACKLOG MIN_BACKLOG
#endif
+
/*
* This is the Socket implementation of the X Transport service layer
*
@@ -220,8 +200,8 @@ static int IBMsockInit = 0;
*
*/
-typedef struct _Sockettrans2dev {
- char *transname;
+typedef struct _Sockettrans2dev {
+ const char *transname;
int family;
int devcotsname;
int devcltsname;
@@ -255,36 +235,6 @@ static int TRANS(SocketINETClose) (XtransConnInfo ciptr);
#ifdef UNIXCONN
-#ifdef hpux
-
-#if defined(X11_t)
-#define UNIX_PATH "/usr/spool/sockets/X11/"
-#define UNIX_DIR "/usr/spool/sockets/X11"
-#define OLD_UNIX_PATH "/tmp/.X11-unix/X"
-#endif /* X11_t */
-#if defined(XIM_t)
-#define UNIX_PATH "/usr/spool/sockets/XIM/"
-#define UNIX_DIR "/usr/spool/sockets/XIM"
-#define OLD_UNIX_PATH "/tmp/.XIM-unix/XIM"
-#endif /* XIM_t */
-#if defined(FS_t) || defined(FONT_t)
-#define UNIX_PATH "/usr/spool/sockets/fontserv/"
-#define UNIX_DIR "/usr/spool/sockets/fontserv"
-#endif /* FS_t || FONT_t */
-#if defined(ICE_t)
-#define UNIX_PATH "/usr/spool/sockets/ICE/"
-#define UNIX_DIR "/usr/spool/sockets/ICE"
-#endif /* ICE_t */
-#if defined(TEST_t)
-#define UNIX_PATH "/usr/spool/sockets/xtrans_test/"
-#define UNIX_DIR "/usr/spool/sockets/xtrans_test"
-#endif
-#if defined(LBXPROXY_t)
-#define UNIX_PATH "/usr/spool/sockets/X11/"
-#define UNIX_DIR "/usr/spool/sockets/X11"
-#endif
-
-#else /* !hpux */
#if defined(X11_t)
#define UNIX_PATH "/tmp/.X11-unix/X"
@@ -302,16 +252,7 @@ static int TRANS(SocketINETClose) (XtransConnInfo ciptr);
#define UNIX_PATH "/tmp/.ICE-unix/"
#define UNIX_DIR "/tmp/.ICE-unix"
#endif /* ICE_t */
-#if defined(TEST_t)
-#define UNIX_PATH "/tmp/.Test-unix/test"
-#define UNIX_DIR "/tmp/.Test-unix"
-#endif
-#if defined(LBXPROXY_t)
-#define UNIX_PATH "/tmp/.X11-unix/X"
-#define UNIX_DIR "/tmp/.X11-unix"
-#endif
-#endif /* hpux */
#endif /* UNIXCONN */
@@ -321,17 +262,12 @@ static int TRANS(SocketINETClose) (XtransConnInfo ciptr);
#define MAXHOSTNAMELEN 255
#endif
-/*
- * This provides compatibility for apps linked against system libraries
- * that don't have IPv6 support.
- */
-#if defined(IPv6) && defined(AF_INET6)
-static const struct in6_addr local_in6addr_any = IN6ADDR_ANY_INIT;
-#pragma weak in6addr_any = local_in6addr_any
-#ifndef __USLC__
-#pragma weak getaddrinfo
-#endif
-static int haveIPv6 = 1;
+#if defined HAVE_SOCKLEN_T || (defined(IPv6) && defined(AF_INET6))
+# define SOCKLEN_T socklen_t
+#elif defined(SVR4) || defined(__SVR4) || defined(__SCO__)
+# define SOCKLEN_T size_t
+#else
+# define SOCKLEN_T int
#endif
#ifndef X11_t
@@ -347,6 +283,10 @@ static int haveIPv6 = 1;
#ifdef NX_TRANS_SOCKET
+#ifdef XTRANS_SEND_FDS
+ #error XTRANS_SEND_FDS is unsupported for NX!
+#endif
+
#ifdef TRANS_CLIENT
#include <nx/NX.h>
@@ -366,172 +306,8 @@ static _NXProxyConnInfo *_NXProxyConnInfoTab[NX_PROXY_CONN_LIMIT];
#endif /* #ifdef TRANS_CLIENT */
-/*
- * Override the UNIX_DIR and UNIX_PATH settings and
- * make them configurable, based on the NX_TEMP or
- * the TEMP environment.
- *
- * We must be careful as the same defines are used
- * for different directories, based on the subsystem
- * that is compiling this, while we want to override
- * only the '/tmp/.X11-unix' and '/tmp/.X11-unix/X'
- * settings.
- */
-
-static char _NXUnixDir[1024];
-static char _NXUnixPath[1024];
-
-static char *_NXGetUnixDir(char *dir)
-{
- const char *tempDir;
-
- PRMSG (3, "_NXGetUnixDir(%s)\n", dir, 0, 0);
-
- if (strcmp(dir, UNIX_DIR) != 0)
- {
-#ifdef NX_TRANS_TEST
- fprintf(stderr, "_NXGetUnixDir: Returning other Unix directory [%s].\n", dir);
-#endif
- return dir;
- }
-
- /*
- * Check the environment only once.
- */
-
- if (*_NXUnixDir != '\0')
- {
- return _NXUnixDir;
- }
-
-#ifdef NX_TRANS_TEST
- fprintf(stderr, "_NXGetUnixDir: Trying with the NX_TEMP environment.\n");
-#endif
-
- tempDir = getenv("NX_TEMP");
-
- if (tempDir == NULL || *tempDir == '\0')
- {
-#ifdef NX_TRANS_TEST
- fprintf(stderr, "_NXGetUnixDir: Trying with the TEMP environment.\n");
-#endif
-
- tempDir = getenv("TEMP");
- }
-
- if (tempDir != NULL && *tempDir != '\0')
- {
- if (strlen(tempDir) + strlen("/.X11-unix") + 1 > 1024)
- {
-#ifdef NX_TRANS_TEST
- fprintf(stderr, "_NXGetUnixDir: WARNING! Maximum length of X11 Unix directory exceeded.\n");
-#endif
- goto _NXGetUnixDirError;
- }
-
- strcpy(_NXUnixDir, tempDir);
- strcat(_NXUnixDir, "/.X11-unix");
-
-#ifdef NX_TRANS_TEST
- fprintf(stderr, "_NXGetUnixDir: Using X11 Unix directory [%s].\n", _NXUnixDir);
-#endif
-
- return _NXUnixDir;
- }
-
-_NXGetUnixDirError:
-
- strcpy(_NXUnixDir, dir);
-
-#ifdef NX_TRANS_TEST
- fprintf(stderr, "_NXGetUnixDir: Returning default X11 Unix directory [%s].\n", _NXUnixDir);
-#endif
-
- return _NXUnixDir;
-}
-
-static char *_NXGetUnixPath(char *path)
-{
- const char *unixDir;
-
- PRMSG (3, "_NXGetUnixPath(%s)\n", path, 0, 0);
-
- if (strcmp(path, UNIX_PATH) != 0)
- {
-#ifdef NX_TRANS_TEST
- fprintf(stderr, "_NXGetUnixPath: Returning other X11 Unix path [%s].\n", path);
-#endif
- return path;
- }
-
- /*
- * Check the environment only once.
- */
-
- if (*_NXUnixPath != '\0')
- {
- return _NXUnixPath;
- }
-
- unixDir = _NXGetUnixDir(UNIX_DIR);
-
-#ifdef NX_TRANS_TEST
- fprintf(stderr, "_NXGetUnixPath: Got X11 Unix directory [%s].\n", unixDir);
-#endif
-
- if (strlen(unixDir) + strlen("/X") + 1 > 1024)
- {
-#ifdef NX_TRANS_TEST
- fprintf(stderr, "_NXGetUnixPath: WARNING! Maximum length of X11 Unix path exceeded.\n");
-#endif
-
- goto _NXGetUnixPathError;
- }
-
- strcpy(_NXUnixPath, unixDir);
- strcat(_NXUnixPath, "/X");
-
-#ifdef NX_TRANS_TEST
- fprintf(stderr, "_NXGetUnixPath: Returning X11 Unix path [%s].\n", _NXUnixPath);
-#endif
-
- return _NXUnixPath;
-
-_NXGetUnixPathError:
-
- strcpy(_NXUnixPath, path);
-
-#ifdef NX_TRANS_TEST
- fprintf(stderr, "_NXGetUnixPath: Returning default X11 Unix path [%s].\n", _NXUnixPath);
-#endif
-
- return _NXUnixPath;
-}
-
-#ifdef hpux
-
-static char *_NXGetOldUnixPath(char *path)
-{
- PRMSG (3, "_NXGetOldUnixPath(%s)\n", path, 0, 0);
-
- if (strcmp(path, OLD_UNIX_PATH) == 0)
- {
-#ifdef NX_TRANS_TEST
- fprintf(stderr, "_NXGetOldUnixPath: Returning X11 Unix path [%s].\n",
- _NXGetUnixPath(path));
-#endif
-
- return _NXGetUnixPath(path);
- }
-
-#ifdef NX_TRANS_TEST
- fprintf(stderr, "_NXGetOldUnixPath: Returning other old X11 Unix path [%s].\n", path);
-#endif
-
- return path;
-}
-
-#endif /* #ifdef hpux */
+static char *_NXGetUnixDir(char *dir);
+static char *_NXGetUnixPath(char *path);
/*
* Forcibly close any connection attempt on the
@@ -549,7 +325,7 @@ void TRANS(SocketRejectConnection) (XtransConnInfo ciptr)
struct timeval t;
int f;
- PRMSG (3, "SocketRejectConnection(%x)\n", ciptr, 0, 0);
+ prmsg (3, "SocketRejectConnection(%p)\n", ciptr);
FD_ZERO(&fs);
FD_SET(ciptr -> fd, &fs);
@@ -570,7 +346,7 @@ void TRANS(SocketRejectConnection) (XtransConnInfo ciptr)
/*
* If there is one, close it.
*/
-
+
if ((f = accept(ciptr -> fd, &sa, &sa_l)) >= 0)
{
#ifdef NX_TRANS_TEST
@@ -608,7 +384,7 @@ static XtransConnInfo TRANS(SocketCreateConnInfo) ()
if ((ciptr = (XtransConnInfo) calloc (1, sizeof(struct _XtransConnInfo))) == NULL)
{
- PRMSG (1, "SocketCreateConnInfo: malloc failed\n", 0, 0, 0);
+ prmsg (1, "SocketCreateConnInfo: malloc failed\n");
return NULL;
}
@@ -623,7 +399,7 @@ static XtransConnInfo TRANS(SocketCreateConnInfo) ()
if (socketpair(PF_LOCAL, SOCK_STREAM, 0, fds) < 0)
{
- PRMSG (1, "SocketCreateConnInfo: socketpair() failed.\n", 0, 0, 0);
+ prmsg (1, "SocketCreateConnInfo: socketpair() failed.\n");
free ((char *) ciptr);
return NULL;
}
@@ -646,15 +422,15 @@ static XtransConnInfo TRANS(SocketCreateConnInfo) ()
if (ciptr->fd >= NX_PROXY_CONN_LIMIT)
{
- PRMSG (1, "SocketCreateConnInfo: No space for a new _NXProxyConnInfo for [%d].\n",
- ciptr->fd, 0, 0);
+ prmsg (1, "SocketCreateConnInfo: No space for a new _NXProxyConnInfo for [%d].\n",
+ ciptr->fd);
free ((char *) ciptr);
return NULL;
}
else if (_NXProxyConnInfoTab[ciptr->fd] != NULL)
{
- PRMSG (1, "SocketCreateConnInfo: _NXProxyConnInfo for [%d] is not NULL. Exiting.\n",
- ciptr->fd, 0, 0);
+ prmsg (1, "SocketCreateConnInfo: _NXProxyConnInfo for [%d] is not NULL. Exiting.\n",
+ ciptr->fd);
exit(1);
}
@@ -662,7 +438,7 @@ static XtransConnInfo TRANS(SocketCreateConnInfo) ()
if (_NXProxyConnInfoTab[ciptr->fd] == NULL)
{
- PRMSG (1, "SocketCreateConnInfo: Alloc of _NXProxyConnInfo failed.\n", 0, 0, 0);
+ prmsg (1, "SocketCreateConnInfo: Alloc of _NXProxyConnInfo failed.\n");
free ((char *) ciptr);
return NULL;
}
@@ -702,21 +478,20 @@ static int TRANS(SocketConnectConnInfo) (XtransConnInfo ciptr, char *host, char
if (proxy_conn == NULL)
{
- PRMSG (1, "SocketConnectConnInfo: Pointer to _NXProxyConnInfo is NULL. Exiting.\n", 0, 0, 0);
+ prmsg (1, "SocketConnectConnInfo: Pointer to _NXProxyConnInfo is NULL. Exiting.\n");
exit(1);
}
else if (_NXProxyConnInfoTab[ciptr->fd] != (_NXProxyConnInfo *) ciptr->priv)
{
- PRMSG (1, "SocketConnectConnInfo: Can't find _NXProxyConnInfo in table. Exiting.\n",
- 0, 0, 0);
+ prmsg (1, "SocketConnectConnInfo: Can't find _NXProxyConnInfo in table. Exiting.\n");
exit(1);
}
if (strlen(host) + strlen(port) + 1 >= 1023)
{
- PRMSG (1, "SocketConnectConnInfo: Length of NX display string '%s:%s' would exceed %d characters.\n",
+ prmsg (1, "SocketConnectConnInfo: Length of NX display string '%s:%s' would exceed %d characters.\n",
host, port, 1023);
return TRANS_CONNECT_FAILED;
@@ -737,8 +512,8 @@ static int TRANS(SocketConnectConnInfo) (XtransConnInfo ciptr, char *host, char
#endif
#endif
{
- PRMSG (1, "SocketConnectConnInfo: Cannot set close-on-exec on local NX descriptor [%d].\n",
- proxy_conn -> local, 0, 0);
+ prmsg (1, "SocketConnectConnInfo: Cannot set close-on-exec on local NX descriptor [%d].\n",
+ proxy_conn -> local);
return TRANS_CONNECT_FAILED;
}
@@ -750,8 +525,7 @@ static int TRANS(SocketConnectConnInfo) (XtransConnInfo ciptr, char *host, char
if (NXTransCreate(NX_FD_ANY, NX_MODE_CLIENT, display) < 0)
{
- PRMSG (1, "SocketConnectConnInfo: Cannot create the NX transport.\n",
- 0, 0, 0);
+ prmsg (1, "SocketConnectConnInfo: Cannot create the NX transport.\n");
return TRANS_CONNECT_FAILED;
}
@@ -781,28 +555,27 @@ static void TRANS(SocketCloseConnInfo) (XtransConnInfo ciptr)
if (proxy_conn == NULL)
{
- PRMSG (1, "SocketCloseConnInfo: Pointer to _NXProxyConnInfo is NULL. Exiting.\n", 0, 0, 0);
+ prmsg (1, "SocketCloseConnInfo: Pointer to _NXProxyConnInfo is NULL. Exiting.\n");
exit(1);
}
else if (ciptr->fd >= NX_PROXY_CONN_LIMIT ||
_NXProxyConnInfoTab[ciptr->fd] != (_NXProxyConnInfo *) ciptr->priv)
{
- PRMSG (1, "SocketCloseConnInfo: Can't find _NXProxyConnInfo in table. Exiting.\n",
- 0, 0, 0);
+ prmsg (1, "SocketCloseConnInfo: Can't find _NXProxyConnInfo in table. Exiting.\n");
exit(1);
}
else if (_NXProxyConnInfoTab[ciptr->fd] -> info != ciptr ||
_NXProxyConnInfoTab[ciptr->fd] -> local != ciptr->fd)
{
- PRMSG (1, "SocketCloseConnInfo: Invalid _NXProxyConnInfo structure for [%d]. Exiting.\n",
- ciptr->fd, 0, 0);
+ prmsg (1, "SocketCloseConnInfo: Invalid _NXProxyConnInfo structure for [%d]. Exiting.\n",
+ ciptr->fd);
exit(1);
}
else if (proxy_conn->local < 0 || proxy_conn->remote < 0)
{
- PRMSG (1, "SocketCloseConnInfo: Invalid socket pair in NX connection for [%d]. Exiting.\n",
- ciptr->fd, 0, 0);
+ prmsg (1, "SocketCloseConnInfo: Invalid socket pair in NX connection for [%d]. Exiting.\n",
+ ciptr->fd);
exit(1);
}
@@ -846,7 +619,7 @@ int TRANS(SocketCongestionChange) (XtransConnInfo ciptr, int *state)
_NXProxyConnInfo *proxy_conn;
- PRMSG (3, "SocketCongestionChange(%x)\n", ciptr, 0, 0);
+ prmsg (3, "SocketCongestionChange(%p)\n", ciptr);
proxy_conn = (_NXProxyConnInfo *) ciptr->priv;
@@ -893,12 +666,12 @@ int TRANS(SocketCongestionChange) (XtransConnInfo ciptr, int *state)
*/
static int
-TRANS(SocketSelectFamily) (int first, char *family)
+TRANS(SocketSelectFamily) (int first, const char *family)
{
int i;
- PRMSG (3,"SocketSelectFamily(%s)\n", family, 0, 0);
+ prmsg (3,"SocketSelectFamily(%s)\n", family);
for (i = first + 1; i < NUMSOCKETFAMILIES;i++)
{
@@ -921,40 +694,32 @@ TRANS(SocketINETGetAddr) (XtransConnInfo ciptr)
{
#if defined(IPv6) && defined(AF_INET6)
struct sockaddr_storage socknamev6;
-#endif
- struct sockaddr_in socknamev4;
- void *socknamePtr;
-#if defined(SVR4) || defined(__SCO__)
-# define SOCKLEN_T_PTR void*
- size_t namelen;
#else
-# define SOCKLEN_T_PTR socklen_t*
- socklen_t namelen;
+ struct sockaddr_in socknamev4;
#endif
+ void *socknamePtr;
+ SOCKLEN_T namelen;
- PRMSG (3,"SocketINETGetAddr(%p)\n", ciptr, 0, 0);
+ prmsg (3,"SocketINETGetAddr(%p)\n", ciptr);
#if defined(IPv6) && defined(AF_INET6)
- if (haveIPv6)
- {
namelen = sizeof(socknamev6);
socknamePtr = &socknamev6;
- }
- else
-#endif
- {
+#else
namelen = sizeof(socknamev4);
socknamePtr = &socknamev4;
- }
+#endif
+
+ bzero(socknamePtr, namelen);
if (getsockname (ciptr->fd,(struct sockaddr *) socknamePtr,
- (SOCKLEN_T_PTR)&namelen) < 0)
+ (void *)&namelen) < 0)
{
#ifdef WIN32
errno = WSAGetLastError();
#endif
- PRMSG (1,"SocketINETGetAddr: getsockname() failed: %d\n",
- EGET(),0, 0);
+ prmsg (1,"SocketINETGetAddr: getsockname() failed: %d\n",
+ EGET());
return -1;
}
@@ -962,24 +727,18 @@ TRANS(SocketINETGetAddr) (XtransConnInfo ciptr)
* Everything looks good: fill in the XtransConnInfo structure.
*/
- if ((ciptr->addr = (char *) malloc (namelen)) == NULL)
+ if ((ciptr->addr = malloc (namelen)) == NULL)
{
- PRMSG (1,
- "SocketINETGetAddr: Can't allocate space for the addr\n",
- 0, 0, 0);
+ prmsg (1,
+ "SocketINETGetAddr: Can't allocate space for the addr\n");
return -1;
}
#if defined(IPv6) && defined(AF_INET6)
- if (haveIPv6)
- {
ciptr->family = ((struct sockaddr *)socknamePtr)->sa_family;
- }
- else
-#endif
- {
+#else
ciptr->family = socknamev4.sin_family;
- }
+#endif
ciptr->addrlen = namelen;
memcpy (ciptr->addr, socknamePtr, ciptr->addrlen);
@@ -1001,14 +760,10 @@ TRANS(SocketINETGetPeerAddr) (XtransConnInfo ciptr)
#endif
struct sockaddr_in socknamev4;
void *socknamePtr;
-#if defined(SVR4) || defined(__SCO__)
- size_t namelen;
-#else
- int namelen;
-#endif
+ SOCKLEN_T namelen;
#if defined(IPv6) && defined(AF_INET6)
- if (haveIPv6 && ciptr->family == AF_INET6)
+ if (ciptr->family == AF_INET6)
{
namelen = sizeof(socknamev6);
socknamePtr = &socknamev6;
@@ -1020,7 +775,9 @@ TRANS(SocketINETGetPeerAddr) (XtransConnInfo ciptr)
socknamePtr = &socknamev4;
}
- PRMSG (3,"SocketINETGetPeerAddr(%p)\n", ciptr, 0, 0);
+ bzero(socknamePtr, namelen);
+
+ prmsg (3,"SocketINETGetPeerAddr(%p)\n", ciptr);
if (getpeername (ciptr->fd, (struct sockaddr *) socknamePtr,
(void *)&namelen) < 0)
@@ -1028,8 +785,8 @@ TRANS(SocketINETGetPeerAddr) (XtransConnInfo ciptr)
#ifdef WIN32
errno = WSAGetLastError();
#endif
- PRMSG (1,"SocketINETGetPeerAddr: getpeername() failed: %d\n",
- EGET(), 0, 0);
+ prmsg (1,"SocketINETGetPeerAddr: getpeername() failed: %d\n",
+ EGET());
return -1;
}
@@ -1037,11 +794,10 @@ TRANS(SocketINETGetPeerAddr) (XtransConnInfo ciptr)
* Everything looks good: fill in the XtransConnInfo structure.
*/
- if ((ciptr->peeraddr = (char *) malloc (namelen)) == NULL)
+ if ((ciptr->peeraddr = malloc (namelen)) == NULL)
{
- PRMSG (1,
- "SocketINETGetPeerAddr: Can't allocate space for the addr\n",
- 0, 0, 0);
+ prmsg (1,
+ "SocketINETGetPeerAddr: Can't allocate space for the addr\n");
return -1;
}
@@ -1058,20 +814,11 @@ TRANS(SocketOpen) (int i, int type)
{
XtransConnInfo ciptr;
- PRMSG (3,"SocketOpen(%d,%d)\n", i, type, 0);
-
-#if defined(IPv6) && defined(AF_INET6)
- if (getaddrinfo == NULL)
- haveIPv6 = 0;
-
- if (!haveIPv6 && Sockettrans2devtab[i].family == AF_INET6)
- return NULL;
-#endif
+ prmsg (3,"SocketOpen(%d,%d)\n", i, type);
- if ((ciptr = (XtransConnInfo) calloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
+ if ((ciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL)
{
- PRMSG (1, "SocketOpen: malloc failed\n", 0, 0, 0);
+ prmsg (1, "SocketOpen: malloc failed\n");
return NULL;
}
@@ -1079,17 +826,17 @@ TRANS(SocketOpen) (int i, int type)
Sockettrans2devtab[i].protocol)) < 0
#ifndef WIN32
#if (defined(X11_t) && !defined(USE_POLL)) || defined(FS_t) || defined(FONT_t)
- || ciptr->fd >= TRANS_OPEN_MAX
+ || ciptr->fd >= sysconf(_SC_OPEN_MAX)
#endif
#endif
) {
#ifdef WIN32
errno = WSAGetLastError();
#endif
- PRMSG (2, "SocketOpen: socket() failed for %s\n",
- Sockettrans2devtab[i].transname, 0, 0);
+ prmsg (2, "SocketOpen: socket() failed for %s\n",
+ Sockettrans2devtab[i].transname);
- free ((char *) ciptr);
+ free (ciptr);
return NULL;
}
@@ -1110,6 +857,27 @@ TRANS(SocketOpen) (int i, int type)
}
#endif
+ /*
+ * Some systems provide a really small default buffer size for
+ * UNIX sockets. Bump it up a bit such that large transfers don't
+ * proceed at glacial speed.
+ */
+#ifdef SO_SNDBUF
+ if (Sockettrans2devtab[i].family == AF_UNIX)
+ {
+ SOCKLEN_T len = sizeof (int);
+ int val;
+
+ if (getsockopt (ciptr->fd, SOL_SOCKET, SO_SNDBUF,
+ (char *) &val, &len) == 0 && val < 64 * 1024)
+ {
+ val = 64 * 1024;
+ setsockopt (ciptr->fd, SOL_SOCKET, SO_SNDBUF,
+ (char *) &val, sizeof (int));
+ }
+ }
+#endif
+
return ciptr;
}
@@ -1117,22 +885,82 @@ TRANS(SocketOpen) (int i, int type)
#ifdef TRANS_REOPEN
static XtransConnInfo
-TRANS(SocketReopen) (int i, int type, int fd, char *port)
+TRANS(SocketReopen) (int i _X_UNUSED, int type, int fd, const char *port)
{
XtransConnInfo ciptr;
+ int portlen;
+ struct sockaddr *addr;
+ size_t addrlen;
- PRMSG (3,"SocketReopen(%d,%d,%s)\n", type, fd, port);
+ prmsg (3,"SocketReopen(%d,%d,%s)\n", type, fd, port);
- if ((ciptr = (XtransConnInfo) calloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
+ if (port == NULL) {
+ prmsg (1, "SocketReopen: port was null!\n");
+ return NULL;
+ }
+
+ portlen = strlen(port) + 1; // include space for trailing null
+#ifdef SOCK_MAXADDRLEN
+ if (portlen < 0 || portlen > (SOCK_MAXADDRLEN + 2)) {
+ prmsg (1, "SocketReopen: invalid portlen %d\n", portlen);
+ return NULL;
+ }
+ if (portlen < 14) portlen = 14;
+#else
+ if (portlen < 0 || portlen > 14) {
+ prmsg (1, "SocketReopen: invalid portlen %d\n", portlen);
+ return NULL;
+ }
+#endif /*SOCK_MAXADDRLEN*/
+
+ if ((ciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL)
{
- PRMSG (1, "SocketReopen: malloc failed\n", 0, 0, 0);
+ prmsg (1, "SocketReopen: malloc(ciptr) failed\n");
return NULL;
}
ciptr->fd = fd;
+ addrlen = portlen + offsetof(struct sockaddr, sa_data);
+ if ((addr = calloc (1, addrlen)) == NULL) {
+ prmsg (1, "SocketReopen: malloc(addr) failed\n");
+ free (ciptr);
+ return NULL;
+ }
+ ciptr->addr = (char *) addr;
+ ciptr->addrlen = addrlen;
+
+ if ((ciptr->peeraddr = calloc (1, addrlen)) == NULL) {
+ prmsg (1, "SocketReopen: malloc(portaddr) failed\n");
+ free (addr);
+ free (ciptr);
+ return NULL;
+ }
+ ciptr->peeraddrlen = addrlen;
+
+ /* Initialize ciptr structure as if it were a normally-opened unix socket */
+ ciptr->flags = TRANS_LOCAL | TRANS_NOUNLINK;
+#ifdef BSD44SOCKETS
+ addr->sa_len = addrlen;
+#endif
+ addr->sa_family = AF_UNIX;
+#if defined(HAVE_STRLCPY) || defined(HAS_STRLCPY)
+ strlcpy(addr->sa_data, port, portlen);
+#else
+ strncpy(addr->sa_data, port, portlen);
+#endif
+ ciptr->family = AF_UNIX;
+ memcpy(ciptr->peeraddr, ciptr->addr, addrlen);
+ ciptr->port = rindex(addr->sa_data, ':');
+ if (ciptr->port == NULL) {
+ if (is_numeric(addr->sa_data)) {
+ ciptr->port = addr->sa_data;
+ }
+ } else if (ciptr->port[0] == ':') {
+ ciptr->port++;
+ }
+ /* port should now point to portnum or NULL */
return ciptr;
}
@@ -1146,13 +974,13 @@ TRANS(SocketReopen) (int i, int type, int fd, char *port)
#ifdef TRANS_CLIENT
static XtransConnInfo
-TRANS(SocketOpenCOTSClientBase) (char *transname, char *protocol,
- char *host, char *port, int previndex)
+TRANS(SocketOpenCOTSClientBase) (const char *transname, const char *protocol,
+ const char *host, const char *port, int previndex)
{
XtransConnInfo ciptr;
int i = previndex;
- PRMSG (2, "SocketOpenCOTSClient(%s,%s,%s)\n",
+ prmsg (2, "SocketOpenCOTSClient(%s,%s,%s)\n",
protocol, host, port);
SocketInitOnce();
@@ -1168,8 +996,8 @@ TRANS(SocketOpenCOTSClientBase) (char *transname, char *protocol,
if (ciptr == NULL)
{
- PRMSG (1, "SocketOpenCOTSClient: Unable to create the NX connection info for %s.\n",
- transname, 0, 0);
+ prmsg (1, "SocketOpenCOTSClient: Unable to create the NX connection info for %s.\n",
+ transname);
return NULL;
}
@@ -1182,16 +1010,20 @@ TRANS(SocketOpenCOTSClientBase) (char *transname, char *protocol,
#endif /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
if ((ciptr = TRANS(SocketOpen) (
- i, Sockettrans2devtab[i].devcotsname)) != NULL)
+ i, Sockettrans2devtab[i].devcotsname)) != NULL) {
+ /* Save the index for later use */
+
+ ciptr->index = i;
break;
+ }
}
if (i < 0) {
if (i == -1)
- PRMSG (1,"SocketOpenCOTSClient: Unable to open socket for %s\n",
- transname, 0, 0);
+ prmsg (1,"SocketOpenCOTSClient: Unable to open socket for %s\n",
+ transname);
else
- PRMSG (1,"SocketOpenCOTSClient: Unable to determine socket type for %s\n",
- transname, 0, 0);
+ prmsg (1,"SocketOpenCOTSClient: Unable to determine socket type for %s\n",
+ transname);
return NULL;
}
@@ -1201,16 +1033,12 @@ TRANS(SocketOpenCOTSClientBase) (char *transname, char *protocol,
#endif
- /* Save the index for later use */
-
- ciptr->index = i;
-
return ciptr;
}
static XtransConnInfo
-TRANS(SocketOpenCOTSClient) (Xtransport *thistrans, char *protocol,
- char *host, char *port)
+TRANS(SocketOpenCOTSClient) (Xtransport *thistrans, const char *protocol,
+ const char *host, const char *port)
{
return TRANS(SocketOpenCOTSClientBase)(
thistrans->TransName, protocol, host, port, -1);
@@ -1223,14 +1051,14 @@ TRANS(SocketOpenCOTSClient) (Xtransport *thistrans, char *protocol,
#ifdef TRANS_SERVER
static XtransConnInfo
-TRANS(SocketOpenCOTSServer) (Xtransport *thistrans, char *protocol,
- char *host, char *port)
+TRANS(SocketOpenCOTSServer) (Xtransport *thistrans, const char *protocol,
+ const char *host, const char *port)
{
XtransConnInfo ciptr;
int i = -1;
- PRMSG (2,"SocketOpenCOTSServer(%s,%s,%s)\n", protocol, host, port);
+ prmsg (2,"SocketOpenCOTSServer(%s,%s,%s)\n", protocol, host, port);
SocketInitOnce();
@@ -1241,11 +1069,11 @@ TRANS(SocketOpenCOTSServer) (Xtransport *thistrans, char *protocol,
}
if (i < 0) {
if (i == -1)
- PRMSG (1,"SocketOpenCOTSServer: Unable to open socket for %s\n",
- thistrans->TransName, 0, 0);
+ prmsg (1,"SocketOpenCOTSServer: Unable to open socket for %s\n",
+ thistrans->TransName);
else
- PRMSG (1,"SocketOpenCOTSServer: Unable to determine socket type for %s\n",
- thistrans->TransName, 0, 0);
+ prmsg (1,"SocketOpenCOTSServer: Unable to determine socket type for %s\n",
+ thistrans->TransName);
return NULL;
}
@@ -1287,165 +1115,17 @@ TRANS(SocketOpenCOTSServer) (Xtransport *thistrans, char *protocol,
#endif /* TRANS_SERVER */
-#ifdef TRANS_CLIENT
-
-static XtransConnInfo
-TRANS(SocketOpenCLTSClient) (Xtransport *thistrans, char *protocol,
- char *host, char *port)
-
-{
- XtransConnInfo ciptr;
- int i = -1;
-
- PRMSG (2,"SocketOpenCLTSClient(%s,%s,%s)\n", protocol, host, port);
-
- SocketInitOnce();
-
- while ((i = TRANS(SocketSelectFamily) (i, thistrans->TransName)) >= 0) {
-
-#if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT)
-
- if ((!strcmp(protocol, "local") || !strcmp(protocol, "nx")) &&
- (!strcasecmp(host, "nx") || !strncasecmp(host, "nx,", 3)))
- {
- ciptr = TRANS(SocketCreateConnInfo) ();
-
- if (ciptr == NULL)
- {
- PRMSG (1, "SocketOpenCLTSClient: Unable to create the NX connection info for %s.\n",
- thistrans->TransName, 0, 0);
-
- return NULL;
- }
-
- ciptr->index = i;
-
- return ciptr;
- }
-
-#endif /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
-
- if ((ciptr = TRANS(SocketOpen) (
- i, Sockettrans2devtab[i].devcotsname)) != NULL)
- break;
- }
- if (i < 0) {
- if (i == -1)
- PRMSG (1,"SocketOpenCLTSClient: Unable to open socket for %s\n",
- thistrans->TransName, 0, 0);
- else
- PRMSG (1,"SocketOpenCLTSClient: Unable to determine socket type for %s\n",
- thistrans->TransName, 0, 0);
- return NULL;
- }
-
-#if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT)
-
- ciptr->priv = NULL;
-
-#endif /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
-
- /* Save the index for later use */
-
- ciptr->index = i;
-
- return ciptr;
-}
-
-#endif /* TRANS_CLIENT */
-
-
-#ifdef TRANS_SERVER
-
-static XtransConnInfo
-TRANS(SocketOpenCLTSServer) (Xtransport *thistrans, char *protocol,
- char *host, char *port)
-
-{
- XtransConnInfo ciptr;
- int i = -1;
-
- PRMSG (2,"SocketOpenCLTSServer(%s,%s,%s)\n", protocol, host, port);
-
- SocketInitOnce();
-
- while ((i = TRANS(SocketSelectFamily) (i, thistrans->TransName)) >= 0) {
- if ((ciptr = TRANS(SocketOpen) (
- i, Sockettrans2devtab[i].devcotsname)) != NULL)
- break;
- }
- if (i < 0) {
- if (i == -1)
- PRMSG (1,"SocketOpenCLTSServer: Unable to open socket for %s\n",
- thistrans->TransName, 0, 0);
- else
- PRMSG (1,"SocketOpenCLTSServer: Unable to determine socket type for %s\n",
- thistrans->TransName, 0, 0);
- return NULL;
- }
-
-#ifdef IPV6_V6ONLY
- if (Sockettrans2devtab[i].family == AF_INET6)
- {
- int one = 1;
- setsockopt(ciptr->fd, IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof(int));
- }
-#endif
- /* Save the index for later use */
-
- ciptr->index = i;
-
- return ciptr;
-}
-
-#endif /* TRANS_SERVER */
-
-
#ifdef TRANS_REOPEN
static XtransConnInfo
-TRANS(SocketReopenCOTSServer) (Xtransport *thistrans, int fd, char *port)
-
-{
- XtransConnInfo ciptr;
- int i = -1;
-
- PRMSG (2,
- "SocketReopenCOTSServer(%d, %s)\n", fd, port, 0);
-
- SocketInitOnce();
-
- while ((i = TRANS(SocketSelectFamily) (i, thistrans->TransName)) >= 0) {
- if ((ciptr = TRANS(SocketReopen) (
- i, Sockettrans2devtab[i].devcotsname, fd, port)) != NULL)
- break;
- }
- if (i < 0) {
- if (i == -1)
- PRMSG (1,"SocketReopenCOTSServer: Unable to open socket for %s\n",
- thistrans->TransName, 0, 0);
- else
- PRMSG (1,"SocketReopenCOTSServer: Unable to determine socket type for %s\n",
- thistrans->TransName, 0, 0);
- return NULL;
- }
-
- /* Save the index for later use */
-
- ciptr->index = i;
-
- return ciptr;
-}
-
-static XtransConnInfo
-TRANS(SocketReopenCLTSServer) (Xtransport *thistrans, int fd, char *port)
+TRANS(SocketReopenCOTSServer) (Xtransport *thistrans, int fd, const char *port)
{
XtransConnInfo ciptr;
int i = -1;
- PRMSG (2,
- "SocketReopenCLTSServer(%d, %s)\n", fd, port, 0);
+ prmsg (2,
+ "SocketReopenCOTSServer(%d, %s)\n", fd, port);
SocketInitOnce();
@@ -1456,11 +1136,11 @@ TRANS(SocketReopenCLTSServer) (Xtransport *thistrans, int fd, char *port)
}
if (i < 0) {
if (i == -1)
- PRMSG (1,"SocketReopenCLTSServer: Unable to open socket for %s\n",
- thistrans->TransName, 0, 0);
+ prmsg (1,"SocketReopenCOTSServer: Unable to open socket for %s\n",
+ thistrans->TransName);
else
- PRMSG (1,"SocketReopenCLTSServer: Unable to determine socket type for %s\n",
- thistrans->TransName, 0, 0);
+ prmsg (1,"SocketReopenCOTSServer: Unable to determine socket type for %s\n",
+ thistrans->TransName);
return NULL;
}
@@ -1478,7 +1158,7 @@ static int
TRANS(SocketSetOption) (XtransConnInfo ciptr, int option, int arg)
{
- PRMSG (2,"SocketSetOption(%d,%d,%d)\n", ciptr->fd, option, arg);
+ prmsg (2,"SocketSetOption(%d,%d,%d)\n", ciptr->fd, option, arg);
#ifdef NX_TRANS_TEST
fprintf(stderr, "SocketSetOption: WARNING! Not setting option [%d] with value [%d] on descriptor [%d].\n",
@@ -1519,16 +1199,16 @@ set_sun_path(const char *port, const char *upath, char *path, int abstract)
#ifdef TRANS_SERVER
static int
-TRANS(SocketCreateListener) (XtransConnInfo ciptr,
+TRANS(SocketCreateListener) (XtransConnInfo ciptr,
struct sockaddr *sockname,
int socknamelen, unsigned int flags)
{
- int namelen = socknamelen;
+ SOCKLEN_T namelen = socknamelen;
int fd = ciptr->fd;
int retry;
- PRMSG (3, "SocketCreateListener(%x,%p)\n", ciptr, fd, 0);
+ prmsg (3, "SocketCreateListener(%p,%d)\n", ciptr, fd);
if (Sockettrans2devtab[ciptr->index].family == AF_INET
#if defined(IPv6) && defined(AF_INET6)
@@ -1552,10 +1232,9 @@ TRANS(SocketCreateListener) (XtransConnInfo ciptr,
else
return TRANS_ADDR_IN_USE;
}
-
+
if (retry-- == 0) {
- PRMSG (1, "SocketCreateListener: failed to bind listener\n",
- 0, 0, 0);
+ prmsg (1, "SocketCreateListener: failed to bind listener\n");
close (fd);
return TRANS_CREATE_LISTENER_FAILED;
}
@@ -1586,11 +1265,11 @@ TRANS(SocketCreateListener) (XtransConnInfo ciptr,
if (listen (fd, BACKLOG) < 0)
{
- PRMSG (1, "SocketCreateListener: listen() failed\n", 0, 0, 0);
+ prmsg (1, "SocketCreateListener: listen() failed\n");
close (fd);
return TRANS_CREATE_LISTENER_FAILED;
}
-
+
/* Set a flag to indicate that this connection is a listener */
ciptr->flags = 1 | (ciptr->flags & TRANS_KEEPFLAGS);
@@ -1605,7 +1284,8 @@ TRANS(SocketCreateListener) (XtransConnInfo ciptr,
#ifdef TCPCONN
static int
-TRANS(SocketINETCreateListener) (XtransConnInfo ciptr, char *port, unsigned int flags)
+TRANS(SocketINETCreateListener) (XtransConnInfo ciptr, const char *port,
+ unsigned int flags)
{
#if defined(IPv6) && defined(AF_INET6)
@@ -1614,7 +1294,7 @@ TRANS(SocketINETCreateListener) (XtransConnInfo ciptr, char *port, unsigned int
struct sockaddr_in sockname;
#endif
unsigned short sport;
- int namelen = sizeof(sockname);
+ SOCKLEN_T namelen = sizeof(sockname);
int status;
long tmpport;
#ifdef XTHREADS_NEEDS_BYNAMEPARAMS
@@ -1625,8 +1305,8 @@ TRANS(SocketINETCreateListener) (XtransConnInfo ciptr, char *port, unsigned int
#ifdef X11_t
char portbuf[PORTBUFSIZE];
#endif
-
- PRMSG (2, "SocketINETCreateListener(%s)\n", port, 0, 0);
+
+ prmsg (2, "SocketINETCreateListener(%s)\n", port);
#ifdef X11_t
/*
@@ -1642,7 +1322,7 @@ TRANS(SocketINETCreateListener) (XtransConnInfo ciptr, char *port, unsigned int
{
/* fixup the server port address */
tmpport = X_TCP_PORT + strtol (port, (char**)NULL, 10);
- sprintf (portbuf,"%lu", tmpport);
+ snprintf (portbuf, sizeof(portbuf), "%lu", tmpport);
port = portbuf;
}
#endif
@@ -1655,9 +1335,9 @@ TRANS(SocketINETCreateListener) (XtransConnInfo ciptr, char *port, unsigned int
{
if ((servp = _XGetservbyname (port,"tcp",sparams)) == NULL)
{
- PRMSG (1,
+ prmsg (1,
"SocketINETCreateListener: Unable to get service for %s\n",
- port, 0, 0);
+ port);
return TRANS_CREATE_LISTENER_FAILED;
}
/* we trust getservbyname to return a valid number */
@@ -1666,11 +1346,11 @@ TRANS(SocketINETCreateListener) (XtransConnInfo ciptr, char *port, unsigned int
else
{
tmpport = strtol (port, (char**)NULL, 10);
- /*
+ /*
* check that somehow the port address isn't negative or in
* the range of reserved port addresses. This can happen and
- * be very bad if the server is suid-root and the user does
- * something (dumb) like `X :60049`.
+ * be very bad if the server is suid-root and the user does
+ * something (dumb) like `X :60049`.
*/
if (tmpport < 1024 || tmpport > USHRT_MAX)
return TRANS_CREATE_LISTENER_FAILED;
@@ -1712,30 +1392,28 @@ TRANS(SocketINETCreateListener) (XtransConnInfo ciptr, char *port, unsigned int
if ((status = TRANS(SocketCreateListener) (ciptr,
(struct sockaddr *) &sockname, namelen, flags)) < 0)
{
- PRMSG (1,
- "SocketINETCreateListener: ...SocketCreateListener() failed\n",
- 0, 0, 0);
+ prmsg (1,
+ "SocketINETCreateListener: ...SocketCreateListener() failed\n");
return status;
}
if (TRANS(SocketINETGetAddr) (ciptr) < 0)
{
- PRMSG (1,
- "SocketINETCreateListener: ...SocketINETGetAddr() failed\n",
- 0, 0, 0);
+ prmsg (1,
+ "SocketINETCreateListener: ...SocketINETGetAddr() failed\n");
return TRANS_CREATE_LISTENER_FAILED;
}
return 0;
}
-#endif /* SOCKCONN */
+#endif /* TCPCONN */
#ifdef UNIXCONN
static int
-TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port,
+TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, const char *port,
unsigned int flags)
{
@@ -1751,8 +1429,8 @@ TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port,
abstract = ciptr->transptr->flags & TRANS_ABSTRACT;
#endif
- PRMSG (2, "SocketUNIXCreateListener(%s)\n",
- port ? port : "NULL", 0, 0);
+ prmsg (2, "SocketUNIXCreateListener(%s)\n",
+ port ? port : "NULL");
/* Make sure the directory is created */
@@ -1766,12 +1444,12 @@ TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port,
#endif
#ifdef NX_TRANS_SOCKET
if (!abstract && trans_mkdir(_NXGetUnixDir(UNIX_DIR), mode) == -1) {
- PRMSG (1, "SocketUNIXCreateListener: mkdir(%s) failed, errno = %d\n",
- _NXGetUnixDir(UNIX_DIR), errno, 0);
+ prmsg (1, "SocketUNIXCreateListener: mkdir(%s) failed, errno = %d\n",
+ _NXGetUnixDir(UNIX_DIR), errno);
#else
if (!abstract && trans_mkdir(UNIX_DIR, mode) == -1) {
- PRMSG (1, "SocketUNIXCreateListener: mkdir(%s) failed, errno = %d\n",
- UNIX_DIR, errno, 0);
+ prmsg (1, "SocketUNIXCreateListener: mkdir(%s) failed, errno = %d\n",
+ UNIX_DIR, errno);
#endif
(void) umask (oldUmask);
return TRANS_CREATE_LISTENER_FAILED;
@@ -1785,28 +1463,23 @@ TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port,
snprintf (tmpport, sizeof(tmpport), "%s%ld", UNIX_PATH, (long)getpid());
port = tmpport;
}
- if (port && *port) {
#ifdef NX_TRANS_SOCKET
- if (set_sun_path(port, _NXGetUnixPath(UNIX_PATH), sockname.sun_path, abstract) != 0) {
+ if (set_sun_path(port, _NXGetUnixPath(UNIX_PATH), sockname.sun_path, abstract) != 0) {
#else
if (set_sun_path(port, UNIX_PATH, sockname.sun_path, abstract) != 0) {
#endif
- PRMSG (1, "SocketUNIXCreateListener: path too long\n", 0, 0, 0);
+ prmsg (1, "SocketUNIXCreateListener: path too long\n");
return TRANS_CREATE_LISTENER_FAILED;
}
- } else {
-#ifdef NX_TRANS_SOCKET
- sprintf (sockname.sun_path, "%s%ld", _NXGetUnixPath(UNIX_PATH), (long)getpid());
-#else
- sprintf (sockname.sun_path, "%s%ld", UNIX_PATH, (long)getpid());
-#endif
- }
-#if (defined(BSD44SOCKETS) || defined(__UNIXWARE__)) && !defined(Lynx)
+#if (defined(BSD44SOCKETS) || defined(__UNIXWARE__))
sockname.sun_len = strlen(sockname.sun_path);
+#endif
+
+#if defined(BSD44SOCKETS) || defined(SUN_LEN)
namelen = SUN_LEN(&sockname);
#else
- namelen = strlen(sockname.sun_path) + sizeof(sockname.sun_family);
+ namelen = strlen(sockname.sun_path) + offsetof(struct sockaddr_un, sun_path);
#endif
#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
@@ -1823,9 +1496,8 @@ TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port,
if ((status = TRANS(SocketCreateListener) (ciptr,
(struct sockaddr *) &sockname, namelen, flags)) < 0)
{
- PRMSG (1,
- "SocketUNIXCreateListener: ...SocketCreateListener() failed\n",
- 0, 0, 0);
+ prmsg (1,
+ "SocketUNIXCreateListener: ...SocketCreateListener() failed\n");
(void) umask (oldUmask);
return status;
}
@@ -1839,11 +1511,10 @@ TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port,
namelen = sizeof (sockname); /* this will always make it the same size */
- if ((ciptr->addr = (char *) malloc (namelen)) == NULL)
+ if ((ciptr->addr = malloc (namelen)) == NULL)
{
- PRMSG (1,
- "SocketUNIXCreateListener: Can't allocate space for the addr\n",
- 0, 0, 0);
+ prmsg (1,
+ "SocketUNIXCreateListener: Can't allocate space for the addr\n");
(void) umask (oldUmask);
return TRANS_CREATE_LISTENER_FAILED;
}
@@ -1860,6 +1531,7 @@ TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port,
return 0;
}
+
static int
TRANS(SocketUNIXResetListener) (XtransConnInfo ciptr)
@@ -1877,16 +1549,17 @@ TRANS(SocketUNIXResetListener) (XtransConnInfo ciptr)
abstract = ciptr->transptr->flags & TRANS_ABSTRACT;
#endif
- PRMSG (3, "SocketUNIXResetListener(%p,%d)\n", ciptr, ciptr->fd, 0);
+ prmsg (3, "SocketUNIXResetListener(%p,%d)\n", ciptr, ciptr->fd);
if (!abstract && (
stat (unsock->sun_path, &statb) == -1 ||
((statb.st_mode & S_IFMT) !=
-#if (defined (sun) && defined(SVR4)) || defined(NCR) || defined(SCO325) || !defined(S_IFSOCK)
- S_IFIFO))
+#if defined(NCR) || defined(SCO325) || !defined(S_IFSOCK)
+ S_IFIFO
#else
- S_IFSOCK)))
+ S_IFSOCK
#endif
+ )))
{
int oldUmask = umask (0);
@@ -1898,12 +1571,12 @@ TRANS(SocketUNIXResetListener) (XtransConnInfo ciptr)
#endif
#ifdef NX_TRANS_SOCKET
if (trans_mkdir(_NXGetUnixDir(UNIX_DIR), mode) == -1) {
- PRMSG (1, "SocketUNIXResetListener: mkdir(%s) failed, errno = %d\n",
- _NXGetUnixDir(UNIX_DIR), errno, 0);
+ prmsg (1, "SocketUNIXResetListener: mkdir(%s) failed, errno = %d\n",
+ _NXGetUnixDir(UNIX_DIR), errno);
#else
if (trans_mkdir(UNIX_DIR, mode) == -1) {
- PRMSG (1, "SocketUNIXResetListener: mkdir(%s) failed, errno = %d\n",
- UNIX_DIR, errno, 0);
+ prmsg (1, "SocketUNIXResetListener: mkdir(%s) failed, errno = %d\n",
+ UNIX_DIR, errno);
#endif
(void) umask (oldUmask);
return TRANS_RESET_FAILURE;
@@ -1954,14 +1627,13 @@ TRANS(SocketINETAccept) (XtransConnInfo ciptr, int *status)
{
XtransConnInfo newciptr;
struct sockaddr_in sockname;
- int namelen = sizeof(sockname);
+ SOCKLEN_T namelen = sizeof(sockname);
- PRMSG (2, "SocketINETAccept(%p,%d)\n", ciptr, ciptr->fd, 0);
+ prmsg (2, "SocketINETAccept(%p,%d)\n", ciptr, ciptr->fd);
- if ((newciptr = (XtransConnInfo) calloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
+ if ((newciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL)
{
- PRMSG (1, "SocketINETAccept: malloc failed\n", 0, 0, 0);
+ prmsg (1, "SocketINETAccept: malloc failed\n");
*status = TRANS_ACCEPT_BAD_MALLOC;
return NULL;
}
@@ -1972,7 +1644,7 @@ TRANS(SocketINETAccept) (XtransConnInfo ciptr, int *status)
#ifdef WIN32
errno = WSAGetLastError();
#endif
- PRMSG (1, "SocketINETAccept: accept() failed\n", 0, 0, 0);
+ prmsg (1, "SocketINETAccept: accept() failed\n");
free (newciptr);
*status = TRANS_ACCEPT_FAILED;
return NULL;
@@ -1991,15 +1663,14 @@ TRANS(SocketINETAccept) (XtransConnInfo ciptr, int *status)
#endif
/*
- * Get this address again because the transport may give a more
+ * Get this address again because the transport may give a more
* specific address now that a connection is established.
*/
if (TRANS(SocketINETGetAddr) (newciptr) < 0)
{
- PRMSG (1,
- "SocketINETAccept: ...SocketINETGetAddr() failed:\n",
- 0, 0, 0);
+ prmsg (1,
+ "SocketINETAccept: ...SocketINETGetAddr() failed:\n");
close (newciptr->fd);
free (newciptr);
*status = TRANS_ACCEPT_MISC_ERROR;
@@ -2008,9 +1679,8 @@ TRANS(SocketINETAccept) (XtransConnInfo ciptr, int *status)
if (TRANS(SocketINETGetPeerAddr) (newciptr) < 0)
{
- PRMSG (1,
- "SocketINETAccept: ...SocketINETGetPeerAddr() failed:\n",
- 0, 0, 0);
+ prmsg (1,
+ "SocketINETAccept: ...SocketINETGetPeerAddr() failed:\n");
close (newciptr->fd);
if (newciptr->addr) free (newciptr->addr);
free (newciptr);
@@ -2033,18 +1703,13 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status)
{
XtransConnInfo newciptr;
struct sockaddr_un sockname;
-#if defined(SVR4) || defined(__SCO__)
- size_t namelen = sizeof sockname;
-#else
- int namelen = sizeof sockname;
-#endif
+ SOCKLEN_T namelen = sizeof sockname;
- PRMSG (2, "SocketUNIXAccept(%p,%d)\n", ciptr, ciptr->fd, 0);
+ prmsg (2, "SocketUNIXAccept(%p,%d)\n", ciptr, ciptr->fd);
- if ((newciptr = (XtransConnInfo) calloc (
- 1, sizeof(struct _XtransConnInfo))) == NULL)
+ if ((newciptr = calloc (1, sizeof(struct _XtransConnInfo))) == NULL)
{
- PRMSG (1, "SocketUNIXAccept: malloc() failed\n", 0, 0, 0);
+ prmsg (1, "SocketUNIXAccept: malloc() failed\n");
*status = TRANS_ACCEPT_BAD_MALLOC;
return NULL;
}
@@ -2052,29 +1717,28 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status)
if ((newciptr->fd = accept (ciptr->fd,
(struct sockaddr *) &sockname, (void *)&namelen)) < 0)
{
- PRMSG (1, "SocketUNIXAccept: accept() failed\n", 0, 0, 0);
+ prmsg (1, "SocketUNIXAccept: accept() failed\n");
free (newciptr);
*status = TRANS_ACCEPT_FAILED;
return NULL;
}
+ ciptr->addrlen = namelen;
/*
* Get the socket name and the peer name from the listener socket,
* since this is unix domain.
*/
- if ((newciptr->addr = (char *) malloc (ciptr->addrlen)) == NULL)
+ if ((newciptr->addr = malloc (ciptr->addrlen)) == NULL)
{
- PRMSG (1,
- "SocketUNIXAccept: Can't allocate space for the addr\n",
- 0, 0, 0);
+ prmsg (1,
+ "SocketUNIXAccept: Can't allocate space for the addr\n");
close (newciptr->fd);
free (newciptr);
*status = TRANS_ACCEPT_BAD_MALLOC;
return NULL;
}
-
/*
* if the socket is abstract, we already modified the address to have a
* @ instead of the initial NUL, so no need to do that again here.
@@ -2083,18 +1747,17 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status)
newciptr->addrlen = ciptr->addrlen;
memcpy (newciptr->addr, ciptr->addr, newciptr->addrlen);
- if ((newciptr->peeraddr = (char *) malloc (ciptr->addrlen)) == NULL)
+ if ((newciptr->peeraddr = malloc (ciptr->addrlen)) == NULL)
{
- PRMSG (1,
- "SocketUNIXAccept: Can't allocate space for the addr\n",
- 0, 0, 0);
+ prmsg (1,
+ "SocketUNIXAccept: Can't allocate space for the addr\n");
close (newciptr->fd);
if (newciptr->addr) free (newciptr->addr);
free (newciptr);
*status = TRANS_ACCEPT_BAD_MALLOC;
return NULL;
}
-
+
newciptr->peeraddrlen = ciptr->addrlen;
memcpy (newciptr->peeraddr, ciptr->addr, newciptr->addrlen);
@@ -2117,7 +1780,7 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status)
#if defined(IPv6) && defined(AF_INET6)
struct addrlist {
struct addrinfo * addr;
- struct addrinfo * firstaddr;
+ struct addrinfo * firstaddr;
char port[PORTBUFSIZE];
char host[MAXHOSTNAMELEN];
};
@@ -2126,7 +1789,8 @@ static struct addrlist *addrlist = NULL;
static int
-TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
+TRANS(SocketINETConnect) (XtransConnInfo ciptr,
+ const char *host, const char *port)
{
struct sockaddr * socketaddr = NULL;
@@ -2136,23 +1800,23 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
struct addrinfo hints;
char ntopbuf[INET6_ADDRSTRLEN];
int resetonce = 0;
-#endif
+#else
struct sockaddr_in sockname;
+ struct hostent *hostp;
+ struct servent *servp;
+ unsigned long tmpaddr;
+#endif
#ifdef XTHREADS_NEEDS_BYNAMEPARAMS
_Xgethostbynameparams hparams;
_Xgetservbynameparams sparams;
#endif
- struct hostent *hostp;
- struct servent *servp;
- unsigned long tmpaddr;
#ifdef X11_t
char portbuf[PORTBUFSIZE];
#endif
- long tmpport;
char hostnamebuf[256]; /* tmp space */
- PRMSG (2,"SocketINETConnect(%d,%s,%s)\n", ciptr->fd, host, port);
+ prmsg (2,"SocketINETConnect(%d,%s,%s)\n", ciptr->fd, host, port);
if (!host)
{
@@ -2173,14 +1837,14 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
if (is_numeric (port))
{
- tmpport = X_TCP_PORT + strtol (port, (char**)NULL, 10);
- sprintf (portbuf, "%lu", tmpport);
+ long tmpport = X_TCP_PORT + strtol (port, (char**)NULL, 10);
+ snprintf (portbuf, sizeof(portbuf), "%lu", tmpport);
port = portbuf;
}
#endif
#if defined(IPv6) && defined(AF_INET6)
- if (haveIPv6) {
+ {
if (addrlist != NULL) {
if (strcmp(host,addrlist->host) || strcmp(port,addrlist->port)) {
if (addrlist->firstaddr)
@@ -2203,7 +1867,7 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
res = getaddrinfo(host,port,&hints,&addrlist->firstaddr);
if (res != 0) {
- PRMSG (1, "SocketINETConnect() can't get address "
+ prmsg (1, "SocketINETConnect() can't get address "
"for %s:%s: %s\n", host, port, gai_strerror(res));
ESET(EINVAL);
return TRANS_CONNECT_FAILED;
@@ -2212,24 +1876,24 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
addrlist->addr ; res++) {
addrlist->addr = addrlist->addr->ai_next;
}
- PRMSG(4,"Got New Address list with %d addresses\n", res, 0, 0);
+ prmsg(4,"Got New Address list with %d addresses\n", res);
res = 0;
addrlist->addr = NULL;
}
while (socketaddr == NULL) {
if (addrlist->addr == NULL) {
- if (resetonce) {
+ if (resetonce) {
/* Already checked entire list - no usable addresses */
- PRMSG (1, "SocketINETConnect() no usable address "
- "for %s:%s\n", host, port, 0);
+ prmsg (1, "SocketINETConnect() no usable address "
+ "for %s:%s\n", host, port);
return TRANS_CONNECT_FAILED;
} else {
/* Go back to beginning of list */
resetonce = 1;
addrlist->addr = addrlist->firstaddr;
}
- }
+ }
socketaddr = addrlist->addr->ai_addr;
socketaddrlen = addrlist->addr->ai_addrlen;
@@ -2237,12 +1901,12 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
if (addrlist->addr->ai_family == AF_INET) {
struct sockaddr_in *sin = (struct sockaddr_in *) socketaddr;
- PRMSG (4,"SocketINETConnect() sockname.sin_addr = %s\n",
+ prmsg (4,"SocketINETConnect() sockname.sin_addr = %s\n",
inet_ntop(addrlist->addr->ai_family,&sin->sin_addr,
- ntopbuf,sizeof(ntopbuf)), 0, 0);
+ ntopbuf,sizeof(ntopbuf)));
- PRMSG (4,"SocketINETConnect() sockname.sin_port = %d\n",
- ntohs(sin->sin_port), 0, 0);
+ prmsg (4,"SocketINETConnect() sockname.sin_port = %d\n",
+ ntohs(sin->sin_port));
if (Sockettrans2devtab[ciptr->index].family == AF_INET6) {
if (strcmp(Sockettrans2devtab[ciptr->index].transname,
@@ -2264,26 +1928,24 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
Sockettrans2devtab[newciptr->index].family !=
AF_INET) {
socketaddr = NULL;
- PRMSG (4,"SocketINETConnect() Cannot get IPv4 "
- " socketfor IPv4 address\n", 0,0,0);
+ prmsg (4,"SocketINETConnect() Cannot get IPv4 "
+ " socketfor IPv4 address\n");
}
if (newciptr)
free(newciptr);
} else {
socketaddr = NULL;
- PRMSG (4,"SocketINETConnect Skipping IPv4 address\n",
- 0,0,0);
+ prmsg (4,"SocketINETConnect Skipping IPv4 address\n");
}
}
} else if (addrlist->addr->ai_family == AF_INET6) {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) socketaddr;
-
- PRMSG (4,"SocketINETConnect() sockname.sin6_addr = %s\n",
+
+ prmsg (4,"SocketINETConnect() sockname.sin6_addr = %s\n",
inet_ntop(addrlist->addr->ai_family,
- &sin6->sin6_addr,ntopbuf,sizeof(ntopbuf)),
- 0, 0);
- PRMSG (4,"SocketINETConnect() sockname.sin6_port = %d\n",
- ntohs(sin6->sin6_port), 0, 0);
+ &sin6->sin6_addr,ntopbuf,sizeof(ntopbuf)));
+ prmsg (4,"SocketINETConnect() sockname.sin6_port = %d\n",
+ ntohs(sin6->sin6_port));
if (Sockettrans2devtab[ciptr->index].family == AF_INET) {
if (strcmp(Sockettrans2devtab[ciptr->index].transname,
@@ -2302,8 +1964,8 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
Sockettrans2devtab[newciptr->index].family !=
AF_INET6) {
socketaddr = NULL;
- PRMSG (4,"SocketINETConnect() Cannot get IPv6 "
- "socket for IPv6 address\n", 0,0,0);
+ prmsg (4,"SocketINETConnect() Cannot get IPv6 "
+ "socket for IPv6 address\n");
}
if (newciptr)
free(newciptr);
@@ -2311,8 +1973,7 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
else
{
socketaddr = NULL;
- PRMSG (4,"SocketINETConnect() Skipping IPv6 address\n",
- 0,0,0);
+ prmsg (4,"SocketINETConnect() Skipping IPv6 address\n");
}
}
} else {
@@ -2321,9 +1982,9 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
if (socketaddr == NULL) {
addrlist->addr = addrlist->addr->ai_next;
}
- }
- } else
-#endif
+ }
+ }
+#else
{
/*
* Build the socket name.
@@ -2350,22 +2011,24 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
tmpaddr = INADDR_NONE;
}
- PRMSG (4,"SocketINETConnect() inet_addr(%s) = %x\n", host, tmpaddr, 0);
+ prmsg (4,"SocketINETConnect() inet_addr(%s) = %x\n", host, tmpaddr);
if (tmpaddr == INADDR_NONE) {
if ((hostp = _XGethostbyname(host,hparams)) == NULL) {
- PRMSG (1,"SocketINETConnect: Can't get address for %s\n",
- host, 0, 0);
+ prmsg (1,"SocketINETConnect: Can't get address for %s\n",
+ host);
ESET(EINVAL);
return TRANS_CONNECT_FAILED;
}
if (hostp->h_addrtype != AF_INET) { /* is IP host? */
- PRMSG (1,"SocketINETConnect: not INET host%s\n", host, 0, 0);
+ prmsg (1,"SocketINETConnect: not INET host%s\n", host);
ESET(EPROTOTYPE);
return TRANS_CONNECT_FAILED;
}
+
memcpy ((char *) &sockname.sin_addr, (char *) hostp->h_addr,
sizeof (sockname.sin_addr));
+
} else {
sockname.sin_addr.s_addr = tmpaddr;
}
@@ -2378,23 +2041,24 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
if (!is_numeric (port)) {
if ((servp = _XGetservbyname (port,"tcp",sparams)) == NULL) {
- PRMSG (1,"SocketINETConnect: can't get service for %s\n",
- port, 0, 0);
+ prmsg (1,"SocketINETConnect: can't get service for %s\n",
+ port);
return TRANS_CONNECT_FAILED;
}
sockname.sin_port = htons (servp->s_port);
} else {
- tmpport = strtol (port, (char**)NULL, 10);
+ long tmpport = strtol (port, (char**)NULL, 10);
if (tmpport < 1024 || tmpport > USHRT_MAX)
return TRANS_CONNECT_FAILED;
sockname.sin_port = htons (((unsigned short) tmpport));
}
- PRMSG (4,"SocketINETConnect: sockname.sin_port = %d\n",
- ntohs(sockname.sin_port), 0, 0);
+ prmsg (4,"SocketINETConnect: sockname.sin_port = %d\n",
+ ntohs(sockname.sin_port));
socketaddr = (struct sockaddr *) &sockname;
socketaddrlen = sizeof(sockname);
}
+#endif
/*
* Turn on socket keepalive so the client process will eventually
@@ -2440,12 +2104,12 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
* number of errors that made us quit before, since those
* could be caused by trying to use an IPv6 address to contact
* a machine with an IPv4-only server or other reasons that
- * only affect one of a set of addresses.
+ * only affect one of a set of addresses.
*/
if (olderrno == ECONNREFUSED || olderrno == EINTR
#if defined(IPv6) && defined(AF_INET6)
- || (haveIPv6 && ((addrlist->addr->ai_next != NULL) ||
+ || (((addrlist->addr->ai_next != NULL) ||
(addrlist->addr != addrlist->firstaddr)) &&
(olderrno == ENETUNREACH || olderrno == EAFNOSUPPORT ||
olderrno == EADDRNOTAVAIL || olderrno == ETIMEDOUT
@@ -2460,38 +2124,36 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
res = TRANS_IN_PROGRESS;
else
{
- PRMSG (2,"SocketINETConnect: Can't connect: errno = %d\n",
- olderrno,0, 0);
+ prmsg (2,"SocketINETConnect: Can't connect: errno = %d\n",
+ olderrno);
- res = TRANS_CONNECT_FAILED;
+ res = TRANS_CONNECT_FAILED;
}
} else {
res = 0;
-
+
/*
* Sync up the address fields of ciptr.
*/
-
+
if (TRANS(SocketINETGetAddr) (ciptr) < 0)
{
- PRMSG (1,
- "SocketINETConnect: ...SocketINETGetAddr() failed:\n",
- 0, 0, 0);
+ prmsg (1,
+ "SocketINETConnect: ...SocketINETGetAddr() failed:\n");
res = TRANS_CONNECT_FAILED;
}
else if (TRANS(SocketINETGetPeerAddr) (ciptr) < 0)
{
- PRMSG (1,
- "SocketINETConnect: ...SocketINETGetPeerAddr() failed:\n",
- 0, 0, 0);
+ prmsg (1,
+ "SocketINETConnect: ...SocketINETGetPeerAddr() failed:\n");
res = TRANS_CONNECT_FAILED;
}
}
#if defined(IPv6) && defined(AF_INET6)
- if (haveIPv6 && res != 0) {
+ if (res != 0) {
addrlist->addr = addrlist->addr->ai_next;
}
#endif
@@ -2510,25 +2172,18 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
*/
static int
-UnixHostReallyLocal (char *host)
+UnixHostReallyLocal (const char *host)
{
char hostnamebuf[256];
-#if defined(IPv6) && defined(AF_INET6)
- if (getaddrinfo == NULL)
- haveIPv6 = 0;
-#endif
-
TRANS(GetHostname) (hostnamebuf, sizeof (hostnamebuf));
if (strcmp (hostnamebuf, host) == 0)
{
return (1);
- }
+ } else {
#if defined(IPv6) && defined(AF_INET6)
- else if (haveIPv6)
- {
struct addrinfo *localhostaddr;
struct addrinfo *otherhostaddr;
struct addrinfo *i, *j;
@@ -2545,7 +2200,7 @@ UnixHostReallyLocal (char *host)
for (j = otherhostaddr; j != NULL && equiv == 0; j = j->ai_next) {
if (i->ai_family == j->ai_family) {
if (i->ai_family == AF_INET) {
- struct sockaddr_in *sinA
+ struct sockaddr_in *sinA
= (struct sockaddr_in *) i->ai_addr;
struct sockaddr_in *sinB
= (struct sockaddr_in *) j->ai_addr;
@@ -2556,9 +2211,9 @@ UnixHostReallyLocal (char *host)
equiv = 1;
}
} else if (i->ai_family == AF_INET6) {
- struct sockaddr_in6 *sinA
+ struct sockaddr_in6 *sinA
= (struct sockaddr_in6 *) i->ai_addr;
- struct sockaddr_in6 *sinB
+ struct sockaddr_in6 *sinB
= (struct sockaddr_in6 *) j->ai_addr;
struct in6_addr *A = &sinA->sin6_addr;
struct in6_addr *B = &sinB->sin6_addr;
@@ -2570,14 +2225,11 @@ UnixHostReallyLocal (char *host)
}
}
}
-
+
freeaddrinfo(localhostaddr);
freeaddrinfo(otherhostaddr);
return equiv;
- }
-#endif
- else
- {
+#else
/*
* A host may have more than one network address. If any of the
* network addresses of 'host' (specified to the connect call)
@@ -2603,13 +2255,13 @@ UnixHostReallyLocal (char *host)
* from the 1st call, so we must save the address list.
*/
- specified_local_addr_list[scount][0] =
+ specified_local_addr_list[scount][0] =
hostp->h_addr_list[scount][0];
- specified_local_addr_list[scount][1] =
+ specified_local_addr_list[scount][1] =
hostp->h_addr_list[scount][1];
- specified_local_addr_list[scount][2] =
+ specified_local_addr_list[scount][2] =
hostp->h_addr_list[scount][2];
- specified_local_addr_list[scount][3] =
+ specified_local_addr_list[scount][3] =
hostp->h_addr_list[scount][3];
scount++;
}
@@ -2625,17 +2277,17 @@ UnixHostReallyLocal (char *host)
while (hostp->h_addr_list[j])
{
- if ((specified_local_addr_list[i][0] ==
+ if ((specified_local_addr_list[i][0] ==
hostp->h_addr_list[j][0]) &&
- (specified_local_addr_list[i][1] ==
+ (specified_local_addr_list[i][1] ==
hostp->h_addr_list[j][1]) &&
- (specified_local_addr_list[i][2] ==
+ (specified_local_addr_list[i][2] ==
hostp->h_addr_list[j][2]) &&
- (specified_local_addr_list[i][3] ==
+ (specified_local_addr_list[i][3] ==
hostp->h_addr_list[j][3]))
{
/* They're equal, so we're done */
-
+
equiv = 1;
break;
}
@@ -2646,15 +2298,17 @@ UnixHostReallyLocal (char *host)
i++;
}
return (equiv);
+#endif
}
}
static int
-TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
+TRANS(SocketUNIXConnect) (XtransConnInfo ciptr,
+ const char *host, const char *port)
{
struct sockaddr_un sockname;
- int namelen;
+ SOCKLEN_T namelen;
int abstract = 0;
@@ -2662,14 +2316,8 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
abstract = ciptr->transptr->flags & TRANS_ABSTRACT;
#endif
-#if defined(hpux) && defined(X11_t)
- struct sockaddr_un old_sockname;
- int old_namelen;
-#endif
-
+ prmsg (2,"SocketUNIXConnect(%d,%s,%s)\n", ciptr->fd, host, port);
- PRMSG (2,"SocketUNIXConnect(%d,%s,%s)\n", ciptr->fd, host, port);
-
/*
* Make sure 'host' is really local. If not, we return failure.
* The reason we make this check is because a process may advertise
@@ -2679,15 +2327,15 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
*/
#if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT)
- if (strcmp(host, "unix") != 0 && strcasecmp(host, "nx") != 0 &&
+ if (host && *host && host[0]!='/' && strcmp(host, "unix") != 0 && strcasecmp(host, "nx") != 0 &&
strncasecmp(host, "nx,", 3) != 0 && !UnixHostReallyLocal (host))
#else
- if (strcmp (host, "unix") != 0 && !UnixHostReallyLocal (host))
+ if (host && *host && host[0]!='/' && strcmp (host, "unix") != 0 && !UnixHostReallyLocal (host))
#endif
{
- PRMSG (1,
+ prmsg (1,
"SocketUNIXConnect: Cannot connect to non-local host %s\n",
- host, 0, 0);
+ host);
return TRANS_CONNECT_FAILED;
}
@@ -2698,15 +2346,14 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
if (!port || !*port)
{
- PRMSG (1,"SocketUNIXConnect: Missing port specification\n",
- 0, 0, 0);
+ prmsg (1,"SocketUNIXConnect: Missing port specification\n");
return TRANS_CONNECT_FAILED;
}
/*
* Build the socket name.
*/
-
+
sockname.sun_family = AF_UNIX;
#ifdef NX_TRANS_SOCKET
@@ -2714,34 +2361,21 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
#else
if (set_sun_path(port, UNIX_PATH, sockname.sun_path, abstract) != 0) {
#endif
- PRMSG (1, "SocketUNIXConnect: path too long\n", 0, 0, 0);
+ prmsg (1, "SocketUNIXConnect: path too long\n");
return TRANS_CONNECT_FAILED;
}
-#if (defined(BSD44SOCKETS) || defined(__UNIXWARE__)) && !defined(Lynx)
+#if (defined(BSD44SOCKETS) || defined(__UNIXWARE__))
sockname.sun_len = strlen (sockname.sun_path);
+#endif
+
+#if defined(BSD44SOCKETS) || defined(SUN_LEN)
namelen = SUN_LEN (&sockname);
#else
- namelen = strlen (sockname.sun_path) + sizeof (sockname.sun_family);
+ namelen = strlen (sockname.sun_path) + offsetof(struct sockaddr_un, sun_path);
#endif
-#if defined(hpux) && defined(X11_t)
- /*
- * This is gross, but it was in Xlib
- */
- old_sockname.sun_family = AF_UNIX;
-#ifdef NX_TRANS_SOCKET
- if (set_sun_path(port, _NXGetOldUnixPath(OLD_UNIX_PATH), old_sockname.sun_path) != 0) {
-#else
- if (set_sun_path(port, OLD_UNIX_PATH, old_sockname.sun_path) != 0) {
-#endif
- PRMSG (1, "SocketUNIXConnect: path too long\n", 0, 0, 0);
- return TRANS_CONNECT_FAILED;
- }
- old_namelen = strlen (old_sockname.sun_path) +
- sizeof (old_sockname.sun_family);
-#endif
#if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT)
@@ -2762,8 +2396,9 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
* Done here because otherwise all the strlen() calls above would fail.
*/
- if (abstract)
+ if (abstract) {
sockname.sun_path[0] = '\0';
+ }
/*
* Do the connect()
@@ -2773,26 +2408,19 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
{
int olderrno = errno;
int connected = 0;
-
-#if defined(hpux) && defined(X11_t)
- if (olderrno == ENOENT)
- {
- if (connect (ciptr->fd,
- (struct sockaddr *) &old_sockname, old_namelen) >= 0)
- {
- connected = 1;
- }
- else
- olderrno = errno;
- }
-#endif
+
if (!connected)
{
errno = olderrno;
-
+
/*
- * If the error was ENOENT, the server may be starting up
- * and we should try again.
+ * If the error was ENOENT, the server may be starting up; we used
+ * to suggest to try again in this case with
+ * TRANS_TRY_CONNECT_AGAIN, but this introduced problems for
+ * processes still referencing stale sockets in their environment.
+ * Hence, we now return a hard error, TRANS_CONNECT_FAILED, and it
+ * is suggested that higher level stacks handle retries on their
+ * level when they face a slow starting server.
*
* If the error was EWOULDBLOCK or EINPROGRESS then the socket
* was non-blocking and we should poll using select
@@ -2805,16 +2433,17 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
return TRANS_IN_PROGRESS;
else if (olderrno == EINTR)
return TRANS_TRY_CONNECT_AGAIN;
- else if (olderrno == ENOENT || olderrno == ECONNREFUSED)
- /* If opening as abstract failed, try again normally */
+ else if (olderrno == ENOENT || olderrno == ECONNREFUSED) {
+ /* If opening as abstract socket failed, try again normally */
if (abstract) {
ciptr->transptr->flags &= ~(TRANS_ABSTRACT);
return TRANS_TRY_CONNECT_AGAIN;
} else {
return TRANS_CONNECT_FAILED;
+ }
} else {
- PRMSG (2,"SocketUNIXConnect: Can't connect: errno = %d\n",
- EGET(),0, 0);
+ prmsg (2,"SocketUNIXConnect: Can't connect: errno = %d\n",
+ EGET());
return TRANS_CONNECT_FAILED;
}
@@ -2832,12 +2461,11 @@ SocketUNIXConnectPost:
* since this is unix domain.
*/
- if ((ciptr->addr = (char *) malloc(namelen)) == NULL ||
- (ciptr->peeraddr = (char *) malloc(namelen)) == NULL)
+ if ((ciptr->addr = malloc(namelen)) == NULL ||
+ (ciptr->peeraddr = malloc(namelen)) == NULL)
{
- PRMSG (1,
- "SocketUNIXCreateListener: Can't allocate space for the addr\n",
- 0, 0, 0);
+ prmsg (1,
+ "SocketUNIXCreateListener: Can't allocate space for the addr\n");
return TRANS_CONNECT_FAILED;
}
@@ -2849,7 +2477,7 @@ SocketUNIXConnectPost:
ciptr->peeraddrlen = namelen;
memcpy (ciptr->addr, &sockname, ciptr->addrlen);
memcpy (ciptr->peeraddr, &sockname, ciptr->peeraddrlen);
-
+
return 0;
}
@@ -2862,7 +2490,7 @@ static int
TRANS(SocketBytesReadable) (XtransConnInfo ciptr, BytesReadable_t *pend)
{
- PRMSG (2,"SocketBytesReadable(%p,%d,%p)\n",
+ prmsg (2,"SocketBytesReadable(%p,%d,%p)\n",
ciptr, ciptr->fd, pend);
#if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT)
@@ -2895,7 +2523,7 @@ TRANS(SocketBytesReadable) (XtransConnInfo ciptr, BytesReadable_t *pend)
* NX _XSelect(), so it is generally possible to let the client
* yield the control to NX and let it handle the I/O on the proxy
* descriptors even if the application is not explicitly designed
- * to work as a NX agent.
+ * to work as a NX agent.
*/
#ifdef NX_TRANS_DEBUG
@@ -2916,34 +2544,129 @@ TRANS(SocketBytesReadable) (XtransConnInfo ciptr, BytesReadable_t *pend)
#endif /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
-#if defined(QNX4)
- *pend = 0L; /* FIONREAD only returns a short. Zero out upper bits */
-#endif
#ifdef WIN32
{
int ret = ioctlsocket ((SOCKET) ciptr->fd, FIONREAD, (u_long *) pend);
- errno = WSAGetLastError();
+ if (ret == SOCKET_ERROR) errno = WSAGetLastError();
return ret;
}
#else
-#if (defined(i386) && defined(SYSV) && !defined(SCO325)) || (defined(_SEQUENT_) && _SOCKET_VERSION == 1)
- return ioctl (ciptr->fd, I_NREAD, (char *) pend);
-#else
-#if defined(__UNIXOS2__)
- return ioctl (ciptr->fd, FIONREAD, (char*) pend, sizeof(int));
-#else
return ioctl (ciptr->fd, FIONREAD, (char *) pend);
-#endif /* __UNIXOS2__ */
-#endif /* i386 && SYSV || _SEQUENT_ && _SOCKET_VERSION == 1 */
#endif /* WIN32 */
}
+#if XTRANS_SEND_FDS
+
+static void
+appendFd(struct _XtransConnFd **prev, int fd, int do_close)
+{
+ struct _XtransConnFd *cf, *new;
+
+ new = malloc (sizeof (struct _XtransConnFd));
+ if (!new) {
+ /* XXX mark connection as broken */
+ close(fd);
+ return;
+ }
+ new->next = 0;
+ new->fd = fd;
+ new->do_close = do_close;
+ /* search to end of list */
+ for (; (cf = *prev); prev = &(cf->next));
+ *prev = new;
+}
+
+static int
+removeFd(struct _XtransConnFd **prev)
+{
+ struct _XtransConnFd *cf;
+ int fd;
+
+ if ((cf = *prev)) {
+ *prev = cf->next;
+ fd = cf->fd;
+ free(cf);
+ } else
+ fd = -1;
+ return fd;
+}
+
+static void
+discardFd(struct _XtransConnFd **prev, struct _XtransConnFd *upto, int do_close)
+{
+ struct _XtransConnFd *cf, *next;
+
+ for (cf = *prev; cf != upto; cf = next) {
+ next = cf->next;
+ if (do_close || cf->do_close)
+ close(cf->fd);
+ free(cf);
+ }
+ *prev = upto;
+}
+
+static void
+cleanupFds(XtransConnInfo ciptr)
+{
+ /* Clean up the send list but don't close the fds */
+ discardFd(&ciptr->send_fds, NULL, 0);
+ /* Clean up the recv list and *do* close the fds */
+ discardFd(&ciptr->recv_fds, NULL, 1);
+}
+
+static int
+nFd(struct _XtransConnFd **prev)
+{
+ struct _XtransConnFd *cf;
+ int n = 0;
+
+ for (cf = *prev; cf; cf = cf->next)
+ n++;
+ return n;
+}
+
+static int
+TRANS(SocketRecvFd) (XtransConnInfo ciptr)
+{
+ prmsg (2, "SocketRecvFd(%d)\n", ciptr->fd);
+ return removeFd(&ciptr->recv_fds);
+}
+
+static int
+TRANS(SocketSendFd) (XtransConnInfo ciptr, int fd, int do_close)
+{
+ appendFd(&ciptr->send_fds, fd, do_close);
+ return 0;
+}
+
+static int
+TRANS(SocketRecvFdInvalid)(XtransConnInfo ciptr)
+{
+ errno = EINVAL;
+ return -1;
+}
+
+static int
+TRANS(SocketSendFdInvalid)(XtransConnInfo ciptr, int fd, int do_close)
+{
+ errno = EINVAL;
+ return -1;
+}
+
+#define MAX_FDS 128
+
+union fd_pass {
+ struct cmsghdr cmsghdr;
+ char buf[CMSG_SPACE(MAX_FDS * sizeof(int))];
+};
+
+#endif /* XTRANS_SEND_FDS */
static int
TRANS(SocketRead) (XtransConnInfo ciptr, char *buf, int size)
{
- PRMSG (2,"SocketRead(%d,%p,%d)\n", ciptr->fd, buf, size);
+ prmsg (2,"SocketRead(%d,%p,%d)\n", ciptr->fd, buf, size);
#if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT)
@@ -2975,156 +2698,376 @@ TRANS(SocketRead) (XtransConnInfo ciptr, char *buf, int size)
}
else
{
+ /* FIXME: same code as below, should be possible without duplication */
+#if XTRANS_SEND_FDS
+ struct iovec iov = {
+ .iov_base = buf,
+ .iov_len = size
+ };
+ union fd_pass cmsgbuf;
+ struct msghdr msg = {
+ .msg_name = NULL,
+ .msg_namelen = 0,
+ .msg_iov = &iov,
+ .msg_iovlen = 1,
+ .msg_control = cmsgbuf.buf,
+ .msg_controllen = CMSG_LEN(MAX_FDS * sizeof(int))
+ };
+
+ size = recvmsg(ciptr->fd, &msg, 0);
+ if (size >= 0) {
+ struct cmsghdr *hdr;
+
+ for (hdr = CMSG_FIRSTHDR(&msg); hdr; hdr = CMSG_NXTHDR(&msg, hdr)) {
+ if (hdr->cmsg_level == SOL_SOCKET && hdr->cmsg_type == SCM_RIGHTS) {
+ int nfd = (hdr->cmsg_len - CMSG_LEN(0)) / sizeof (int);
+ int i;
+ int *fd = (int *) CMSG_DATA(hdr);
+
+ for (i = 0; i < nfd; i++)
+ appendFd(&ciptr->recv_fds, fd[i], 0);
+ }
+ }
+ }
+ return size;
+#else
return read (ciptr->fd, buf, size);
+#endif /* XTRANS_SEND_FDS */
}
#else /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
-#if defined(WIN32) || defined(__UNIXOS2__)
+#if defined(WIN32)
{
int ret = recv ((SOCKET)ciptr->fd, buf, size, 0);
#ifdef WIN32
- errno = WSAGetLastError();
+ if (ret == SOCKET_ERROR) errno = WSAGetLastError();
#endif
return ret;
}
#else
+#if XTRANS_SEND_FDS
+ {
+ struct iovec iov = {
+ .iov_base = buf,
+ .iov_len = size
+ };
+ union fd_pass cmsgbuf;
+ struct msghdr msg = {
+ .msg_name = NULL,
+ .msg_namelen = 0,
+ .msg_iov = &iov,
+ .msg_iovlen = 1,
+ .msg_control = cmsgbuf.buf,
+ .msg_controllen = CMSG_LEN(MAX_FDS * sizeof(int))
+ };
+
+ size = recvmsg(ciptr->fd, &msg, 0);
+ if (size >= 0) {
+ struct cmsghdr *hdr;
+
+ for (hdr = CMSG_FIRSTHDR(&msg); hdr; hdr = CMSG_NXTHDR(&msg, hdr)) {
+ if (hdr->cmsg_level == SOL_SOCKET && hdr->cmsg_type == SCM_RIGHTS) {
+ int nfd = (hdr->cmsg_len - CMSG_LEN(0)) / sizeof (int);
+ int i;
+ int *fd = (int *) CMSG_DATA(hdr);
+
+ for (i = 0; i < nfd; i++)
+ appendFd(&ciptr->recv_fds, fd[i], 0);
+ }
+ }
+ }
+ return size;
+ }
+#else
return read (ciptr->fd, buf, size);
+#endif /* XTRANS_SEND_FDS */
#endif /* WIN32 */
#endif /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
}
-
static int
-TRANS(SocketWrite) (XtransConnInfo ciptr, char *buf, int size)
+TRANS(SocketReadv) (XtransConnInfo ciptr, struct iovec *buf, int size)
{
- PRMSG (2,"SocketWrite(%d,%p,%d)\n", ciptr->fd, buf, size);
+ prmsg (2,"SocketReadv(%d,%p,%d)\n", ciptr->fd, buf, size);
#if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT)
/*
* If we have a valid priv pointer then this
* is an internal connection to the proxy.
- * In this case we should emulate the write.
+ * In this case we should emulate the readv.
*/
if (ciptr->priv)
{
- int result;
-
- result = NXTransWrite(ciptr->fd, buf, size);
-
-#ifdef NX_TRANS_DEBUG
- if (result < 0 && EGET() == EAGAIN)
- {
- fprintf(stderr, "SocketWrite: Write on descriptor [%d] would block.\n",
- ciptr->fd);
- }
- else
- {
- fprintf(stderr, "SocketWrite: Written [%d] bytes on descriptor [%d].\n",
- result, ciptr->fd);
- }
-#endif
- return result;
+ return NXTransReadVector(ciptr->fd, buf, size);
}
else
{
- return write (ciptr->fd, buf, size);
+ /* FIXME: same code as below, should be possible without duplication */
+#if XTRANS_SEND_FDS
+ union fd_pass cmsgbuf;
+ struct msghdr msg = {
+ .msg_name = NULL,
+ .msg_namelen = 0,
+ .msg_iov = buf,
+ .msg_iovlen = size,
+ .msg_control = cmsgbuf.buf,
+ .msg_controllen = CMSG_LEN(MAX_FDS * sizeof(int))
+ };
+
+ size = recvmsg(ciptr->fd, &msg, 0);
+ if (size >= 0) {
+ struct cmsghdr *hdr;
+
+ for (hdr = CMSG_FIRSTHDR(&msg); hdr; hdr = CMSG_NXTHDR(&msg, hdr)) {
+ if (hdr->cmsg_level == SOL_SOCKET && hdr->cmsg_type == SCM_RIGHTS) {
+ int nfd = (hdr->cmsg_len - CMSG_LEN(0)) / sizeof (int);
+ int i;
+ int *fd = (int *) CMSG_DATA(hdr);
+
+ for (i = 0; i < nfd; i++)
+ appendFd(&ciptr->recv_fds, fd[i], 0);
+ }
+ }
+ }
+ return size;
+#else
+ return READV (ciptr, buf, size);
+#endif
}
#else /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
-#if defined(WIN32) || defined(__UNIXOS2__)
- {
- int ret = send ((SOCKET)ciptr->fd, buf, size, 0);
-#ifdef WIN32
- errno = WSAGetLastError();
-#endif
- return ret;
+#if XTRANS_SEND_FDS
+ {
+ union fd_pass cmsgbuf;
+ struct msghdr msg = {
+ .msg_name = NULL,
+ .msg_namelen = 0,
+ .msg_iov = buf,
+ .msg_iovlen = size,
+ .msg_control = cmsgbuf.buf,
+ .msg_controllen = CMSG_LEN(MAX_FDS * sizeof(int))
+ };
+
+ size = recvmsg(ciptr->fd, &msg, 0);
+ if (size >= 0) {
+ struct cmsghdr *hdr;
+
+ for (hdr = CMSG_FIRSTHDR(&msg); hdr; hdr = CMSG_NXTHDR(&msg, hdr)) {
+ if (hdr->cmsg_level == SOL_SOCKET && hdr->cmsg_type == SCM_RIGHTS) {
+ int nfd = (hdr->cmsg_len - CMSG_LEN(0)) / sizeof (int);
+ int i;
+ int *fd = (int *) CMSG_DATA(hdr);
+
+ for (i = 0; i < nfd; i++)
+ appendFd(&ciptr->recv_fds, fd[i], 0);
+ }
+ }
+ }
+ return size;
}
#else
- return write (ciptr->fd, buf, size);
-#endif /* WIN32 */
+ return READV (ciptr, buf, size);
+#endif
#endif /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
}
static int
-TRANS(SocketReadv) (XtransConnInfo ciptr, struct iovec *buf, int size)
+TRANS(SocketWritev) (XtransConnInfo ciptr, struct iovec *buf, int size)
{
- PRMSG (2,"SocketReadv(%d,%p,%d)\n", ciptr->fd, buf, size);
+ prmsg (2,"SocketWritev(%d,%p,%d)\n", ciptr->fd, buf, size);
#if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT)
/*
* If we have a valid priv pointer then this
* is an internal connection to the proxy.
- * In this case we should emulate the readv.
+ * In this case we should emulate the writev.
*/
if (ciptr->priv)
{
- return NXTransReadVector(ciptr->fd, buf, size);
+ return NXTransWriteVector(ciptr->fd, buf, size);
}
else
{
- return READV (ciptr, buf, size);
+ /* FIXME: same code as below, should be possible without duplication */
+#if XTRANS_SEND_FDS
+ if (ciptr->send_fds)
+ {
+ union fd_pass cmsgbuf;
+ int nfd = nFd(&ciptr->send_fds);
+ struct _XtransConnFd *cf = ciptr->send_fds;
+ struct msghdr msg = {
+ .msg_name = NULL,
+ .msg_namelen = 0,
+ .msg_iov = buf,
+ .msg_iovlen = size,
+ .msg_control = cmsgbuf.buf,
+ .msg_controllen = CMSG_LEN(nfd * sizeof(int))
+ };
+ struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg);
+ int i;
+ int *fds;
+
+ hdr->cmsg_len = msg.msg_controllen;
+ hdr->cmsg_level = SOL_SOCKET;
+ hdr->cmsg_type = SCM_RIGHTS;
+
+ fds = (int *) CMSG_DATA(hdr);
+ /* Set up fds */
+ for (i = 0; i < nfd; i++) {
+ fds[i] = cf->fd;
+ cf = cf->next;
+ }
+
+ i = sendmsg(ciptr->fd, &msg, 0);
+ if (i > 0)
+ discardFd(&ciptr->send_fds, cf, 0);
+ return i;
+ }
+#endif
+ return WRITEV (ciptr, buf, size);
}
#else /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
- return READV (ciptr, buf, size);
+#if XTRANS_SEND_FDS
+ if (ciptr->send_fds)
+ {
+ union fd_pass cmsgbuf;
+ int nfd = nFd(&ciptr->send_fds);
+ struct _XtransConnFd *cf = ciptr->send_fds;
+ struct msghdr msg = {
+ .msg_name = NULL,
+ .msg_namelen = 0,
+ .msg_iov = buf,
+ .msg_iovlen = size,
+ .msg_control = cmsgbuf.buf,
+ .msg_controllen = CMSG_LEN(nfd * sizeof(int))
+ };
+ struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg);
+ int i;
+ int *fds;
+
+ hdr->cmsg_len = msg.msg_controllen;
+ hdr->cmsg_level = SOL_SOCKET;
+ hdr->cmsg_type = SCM_RIGHTS;
+
+ fds = (int *) CMSG_DATA(hdr);
+ /* Set up fds */
+ for (i = 0; i < nfd; i++) {
+ fds[i] = cf->fd;
+ cf = cf->next;
+ }
+
+ i = sendmsg(ciptr->fd, &msg, 0);
+ if (i > 0)
+ discardFd(&ciptr->send_fds, cf, 0);
+ return i;
+ }
+#endif
+ return WRITEV (ciptr, buf, size);
#endif /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
}
static int
-TRANS(SocketWritev) (XtransConnInfo ciptr, struct iovec *buf, int size)
+TRANS(SocketWrite) (XtransConnInfo ciptr, char *buf, int size)
{
- PRMSG (2,"SocketWritev(%d,%p,%d)\n", ciptr->fd, buf, size);
+ prmsg (2,"SocketWrite(%d,%p,%d)\n", ciptr->fd, buf, size);
#if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT)
/*
* If we have a valid priv pointer then this
* is an internal connection to the proxy.
- * In this case we should emulate the writev.
+ * In this case we should emulate the write.
*/
if (ciptr->priv)
{
- return NXTransWriteVector(ciptr->fd, buf, size);
+ int result;
+
+ result = NXTransWrite(ciptr->fd, buf, size);
+
+#ifdef NX_TRANS_DEBUG
+ if (result < 0 && EGET() == EAGAIN)
+ {
+ fprintf(stderr, "SocketWrite: Write on descriptor [%d] would block.\n",
+ ciptr->fd);
+ }
+ else
+ {
+ fprintf(stderr, "SocketWrite: Written [%d] bytes on descriptor [%d].\n",
+ result, ciptr->fd);
+ }
+#endif
+ return result;
}
else
{
- return WRITEV (ciptr, buf, size);
+ /* FIXME: same code as below, should be possible without duplication */
+#if XTRANS_SEND_FDS
+ if (ciptr->send_fds)
+ {
+ struct iovec iov;
+
+ iov.iov_base = buf;
+ iov.iov_len = size;
+ return TRANS(SocketWritev)(ciptr, &iov, 1);
+ }
+#endif /* XTRANS_SEND_FDS */
+ return write (ciptr->fd, buf, size);
}
#else /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
- return WRITEV (ciptr, buf, size);
+#if defined(WIN32)
+ {
+ int ret = send ((SOCKET)ciptr->fd, buf, size, 0);
+#ifdef WIN32
+ if (ret == SOCKET_ERROR) errno = WSAGetLastError();
+#endif
+ return ret;
+ }
+#else
+#if XTRANS_SEND_FDS
+ if (ciptr->send_fds)
+ {
+ struct iovec iov;
+
+ iov.iov_base = buf;
+ iov.iov_len = size;
+ return TRANS(SocketWritev)(ciptr, &iov, 1);
+ }
+#endif /* XTRANS_SEND_FDS */
+ return write (ciptr->fd, buf, size);
+#endif /* WIN32 */
#endif /* #if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT) */
}
-
static int
TRANS(SocketDisconnect) (XtransConnInfo ciptr)
{
- PRMSG (2,"SocketDisconnect(%p,%d)\n", ciptr, ciptr->fd, 0);
+ prmsg (2,"SocketDisconnect(%p,%d)\n", ciptr, ciptr->fd);
#ifdef WIN32
- {
+ {
int ret = shutdown (ciptr->fd, 2);
- errno = WSAGetLastError();
+ if (ret == SOCKET_ERROR) errno = WSAGetLastError();
return ret;
}
#else
@@ -3138,12 +3081,12 @@ static int
TRANS(SocketINETClose) (XtransConnInfo ciptr)
{
- PRMSG (2,"SocketINETClose(%p,%d)\n", ciptr, ciptr->fd, 0);
+ prmsg (2,"SocketINETClose(%p,%d)\n", ciptr, ciptr->fd);
#ifdef WIN32
{
int ret = close (ciptr->fd);
- errno = WSAGetLastError();
+ if (ret == SOCKET_ERROR) errno = WSAGetLastError();
return ret;
}
#else
@@ -3157,7 +3100,6 @@ TRANS(SocketINETClose) (XtransConnInfo ciptr)
#ifdef UNIXCONN
static int
TRANS(SocketUNIXClose) (XtransConnInfo ciptr)
-
{
/*
* If this is the server side, then once the socket is closed,
@@ -3167,7 +3109,7 @@ TRANS(SocketUNIXClose) (XtransConnInfo ciptr)
struct sockaddr_un *sockname = (struct sockaddr_un *) ciptr->addr;
int ret;
- PRMSG (2,"SocketUNIXClose(%x,%d)\n", ciptr, ciptr->fd, 0);
+ prmsg (2,"SocketUNIXClose(%p,%d)\n", ciptr, ciptr->fd);
#if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT)
@@ -3178,6 +3120,9 @@ TRANS(SocketUNIXClose) (XtransConnInfo ciptr)
#endif
+#if XTRANS_SEND_FDS
+ cleanupFds(ciptr);
+#endif
ret = close(ciptr->fd);
#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
@@ -3192,14 +3137,16 @@ TRANS(SocketUNIXClose) (XtransConnInfo ciptr)
&& sockname->sun_path[0])
{
#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
- if (!(ciptr->flags & TRANS_NOUNLINK))
+ if (!(ciptr->flags & TRANS_NOUNLINK
+ || ciptr->transptr->flags & TRANS_ABSTRACT))
{
fprintf(stderr, "SocketUNIXClose: Unlinking path [%s] for ciptr at [%p].\n",
sockname->sun_path, (void *) ciptr);
unlink (sockname->sun_path);
}
#else
- if (!(ciptr->flags & TRANS_NOUNLINK))
+ if (!(ciptr->flags & TRANS_NOUNLINK
+ || ciptr->transptr->flags & TRANS_ABSTRACT))
unlink (sockname->sun_path);
#endif
}
@@ -3217,8 +3164,8 @@ TRANS(SocketUNIXCloseForCloning) (XtransConnInfo ciptr)
int ret;
- PRMSG (2,"SocketUNIXCloseForCloning(%p,%d)\n",
- ciptr, ciptr->fd, 0);
+ prmsg (2,"SocketUNIXCloseForCloning(%p,%d)\n",
+ ciptr, ciptr->fd);
#if defined(NX_TRANS_SOCKET) && defined(TRANS_CLIENT)
@@ -3229,6 +3176,9 @@ TRANS(SocketUNIXCloseForCloning) (XtransConnInfo ciptr)
#endif
+#if XTRANS_SEND_FDS
+ cleanupFds(ciptr);
+#endif
ret = close(ciptr->fd);
return ret;
@@ -3239,7 +3189,7 @@ TRANS(SocketUNIXCloseForCloning) (XtransConnInfo ciptr)
#ifdef TCPCONN
# ifdef TRANS_SERVER
-static char* tcp_nolisten[] = {
+static const char* tcp_nolisten[] = {
"inet",
#if defined(IPv6) && defined(AF_INET6)
"inet6",
@@ -3259,15 +3209,8 @@ Xtransport TRANS(SocketTCPFuncs) = {
tcp_nolisten,
TRANS(SocketOpenCOTSServer),
#endif /* TRANS_SERVER */
-#ifdef TRANS_CLIENT
- TRANS(SocketOpenCLTSClient),
-#endif /* TRANS_CLIENT */
-#ifdef TRANS_SERVER
- TRANS(SocketOpenCLTSServer),
-#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(SocketReopenCOTSServer),
- TRANS(SocketReopenCLTSServer),
#endif
TRANS(SocketSetOption),
#ifdef TRANS_SERVER
@@ -3283,6 +3226,10 @@ Xtransport TRANS(SocketTCPFuncs) = {
TRANS(SocketWrite),
TRANS(SocketReadv),
TRANS(SocketWritev),
+#if XTRANS_SEND_FDS
+ TRANS(SocketSendFdInvalid),
+ TRANS(SocketRecvFdInvalid),
+#endif
TRANS(SocketDisconnect),
TRANS(SocketINETClose),
TRANS(SocketINETClose),
@@ -3299,15 +3246,8 @@ Xtransport TRANS(SocketINETFuncs) = {
NULL,
TRANS(SocketOpenCOTSServer),
#endif /* TRANS_SERVER */
-#ifdef TRANS_CLIENT
- TRANS(SocketOpenCLTSClient),
-#endif /* TRANS_CLIENT */
-#ifdef TRANS_SERVER
- TRANS(SocketOpenCLTSServer),
-#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(SocketReopenCOTSServer),
- TRANS(SocketReopenCLTSServer),
#endif
TRANS(SocketSetOption),
#ifdef TRANS_SERVER
@@ -3323,6 +3263,10 @@ Xtransport TRANS(SocketINETFuncs) = {
TRANS(SocketWrite),
TRANS(SocketReadv),
TRANS(SocketWritev),
+#if XTRANS_SEND_FDS
+ TRANS(SocketSendFdInvalid),
+ TRANS(SocketRecvFdInvalid),
+#endif
TRANS(SocketDisconnect),
TRANS(SocketINETClose),
TRANS(SocketINETClose),
@@ -3340,15 +3284,8 @@ Xtransport TRANS(SocketINET6Funcs) = {
NULL,
TRANS(SocketOpenCOTSServer),
#endif /* TRANS_SERVER */
-#ifdef TRANS_CLIENT
- TRANS(SocketOpenCLTSClient),
-#endif /* TRANS_CLIENT */
-#ifdef TRANS_SERVER
- TRANS(SocketOpenCLTSServer),
-#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(SocketReopenCOTSServer),
- TRANS(SocketReopenCLTSServer),
#endif
TRANS(SocketSetOption),
#ifdef TRANS_SERVER
@@ -3364,6 +3301,10 @@ Xtransport TRANS(SocketINET6Funcs) = {
TRANS(SocketWrite),
TRANS(SocketReadv),
TRANS(SocketWritev),
+#if XTRANS_SEND_FDS
+ TRANS(SocketSendFdInvalid),
+ TRANS(SocketRecvFdInvalid),
+#endif
TRANS(SocketDisconnect),
TRANS(SocketINETClose),
TRANS(SocketINETClose),
@@ -3388,15 +3329,8 @@ Xtransport TRANS(SocketLocalFuncs) = {
NULL,
TRANS(SocketOpenCOTSServer),
#endif /* TRANS_SERVER */
-#ifdef TRANS_CLIENT
- TRANS(SocketOpenCLTSClient),
-#endif /* TRANS_CLIENT */
-#ifdef TRANS_SERVER
- TRANS(SocketOpenCLTSServer),
-#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(SocketReopenCOTSServer),
- TRANS(SocketReopenCLTSServer),
#endif
TRANS(SocketSetOption),
#ifdef TRANS_SERVER
@@ -3412,6 +3346,10 @@ Xtransport TRANS(SocketLocalFuncs) = {
TRANS(SocketWrite),
TRANS(SocketReadv),
TRANS(SocketWritev),
+#if XTRANS_SEND_FDS
+ TRANS(SocketSendFd),
+ TRANS(SocketRecvFd),
+#endif
TRANS(SocketDisconnect),
TRANS(SocketUNIXClose),
TRANS(SocketUNIXCloseForCloning),
@@ -3419,10 +3357,10 @@ Xtransport TRANS(SocketLocalFuncs) = {
#endif /* !LOCALCONN */
# ifdef TRANS_SERVER
# if !defined(LOCALCONN)
-static char* unix_nolisten[] = { "local" , NULL };
+static const char* unix_nolisten[] = { "local" , NULL };
# endif
# endif
-
+
Xtransport TRANS(SocketUNIXFuncs) = {
/* Socket Interface */
"unix",
@@ -3442,15 +3380,8 @@ Xtransport TRANS(SocketUNIXFuncs) = {
#endif
TRANS(SocketOpenCOTSServer),
#endif /* TRANS_SERVER */
-#ifdef TRANS_CLIENT
- TRANS(SocketOpenCLTSClient),
-#endif /* TRANS_CLIENT */
-#ifdef TRANS_SERVER
- TRANS(SocketOpenCLTSServer),
-#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(SocketReopenCOTSServer),
- TRANS(SocketReopenCLTSServer),
#endif
TRANS(SocketSetOption),
#ifdef TRANS_SERVER
@@ -3466,9 +3397,158 @@ Xtransport TRANS(SocketUNIXFuncs) = {
TRANS(SocketWrite),
TRANS(SocketReadv),
TRANS(SocketWritev),
+#if XTRANS_SEND_FDS
+ TRANS(SocketSendFd),
+ TRANS(SocketRecvFd),
+#endif
TRANS(SocketDisconnect),
TRANS(SocketUNIXClose),
TRANS(SocketUNIXCloseForCloning),
};
#endif /* UNIXCONN */
+
+#ifdef NX_TRANS_SOCKET
+/*
+ * Override the UNIX_DIR and UNIX_PATH settings and
+ * make them configurable, based on the NX_TEMP or
+ * the TEMP environment.
+ *
+ * We must be careful as the same defines are used
+ * for different directories, based on the subsystem
+ * that is compiling this, while we want to override
+ * only the '/tmp/.X11-unix' and '/tmp/.X11-unix/X'
+ * settings.
+ */
+
+static char _NXUnixDir[1024];
+static char _NXUnixPath[1024];
+
+static char *_NXGetUnixDir(char *dir)
+{
+ const char *tempDir;
+
+ prmsg (3, "_NXGetUnixDir(%s)\n", dir);
+
+ if (strcmp(dir, UNIX_DIR) != 0)
+ {
+#ifdef NX_TRANS_TEST
+ fprintf(stderr, "_NXGetUnixDir: Returning other Unix directory [%s].\n", dir);
+#endif
+ return dir;
+ }
+
+ /*
+ * Check the environment only once.
+ */
+
+ if (*_NXUnixDir != '\0')
+ {
+ return _NXUnixDir;
+ }
+
+#ifdef NX_TRANS_TEST
+ fprintf(stderr, "_NXGetUnixDir: Trying with the NX_TEMP environment.\n");
+#endif
+
+ tempDir = getenv("NX_TEMP");
+
+ if (tempDir == NULL || *tempDir == '\0')
+ {
+#ifdef NX_TRANS_TEST
+ fprintf(stderr, "_NXGetUnixDir: Trying with the TEMP environment.\n");
+#endif
+
+ tempDir = getenv("TEMP");
+ }
+
+ if (tempDir != NULL && *tempDir != '\0')
+ {
+ if (strlen(tempDir) + strlen("/.X11-unix") + 1 > 1024)
+ {
+#ifdef NX_TRANS_TEST
+ fprintf(stderr, "_NXGetUnixDir: WARNING! Maximum length of X11 Unix directory exceeded.\n");
+#endif
+ goto _NXGetUnixDirError;
+ }
+
+ strcpy(_NXUnixDir, tempDir);
+ strcat(_NXUnixDir, "/.X11-unix");
+
+#ifdef NX_TRANS_TEST
+ fprintf(stderr, "_NXGetUnixDir: Using X11 Unix directory [%s].\n", _NXUnixDir);
+#endif
+
+ return _NXUnixDir;
+ }
+
+_NXGetUnixDirError:
+
+ strcpy(_NXUnixDir, dir);
+
+#ifdef NX_TRANS_TEST
+ fprintf(stderr, "_NXGetUnixDir: Returning default X11 Unix directory [%s].\n", _NXUnixDir);
+#endif
+
+ return _NXUnixDir;
+}
+
+static char *_NXGetUnixPath(char *path)
+{
+ const char *unixDir;
+
+ prmsg (3, "_NXGetUnixPath(%s)\n", path);
+
+ if (strcmp(path, UNIX_PATH) != 0)
+ {
+#ifdef NX_TRANS_TEST
+ fprintf(stderr, "_NXGetUnixPath: Returning other X11 Unix path [%s].\n", path);
+#endif
+ return path;
+ }
+
+ /*
+ * Check the environment only once.
+ */
+
+ if (*_NXUnixPath != '\0')
+ {
+ return _NXUnixPath;
+ }
+
+ unixDir = _NXGetUnixDir(UNIX_DIR);
+
+#ifdef NX_TRANS_TEST
+ fprintf(stderr, "_NXGetUnixPath: Got X11 Unix directory [%s].\n", unixDir);
+#endif
+
+ if (strlen(unixDir) + strlen("/X") + 1 > 1024)
+ {
+#ifdef NX_TRANS_TEST
+ fprintf(stderr, "_NXGetUnixPath: WARNING! Maximum length of X11 Unix path exceeded.\n");
+#endif
+
+ goto _NXGetUnixPathError;
+ }
+
+ strcpy(_NXUnixPath, unixDir);
+ strcat(_NXUnixPath, "/X");
+
+#ifdef NX_TRANS_TEST
+ fprintf(stderr, "_NXGetUnixPath: Returning X11 Unix path [%s].\n", _NXUnixPath);
+#endif
+
+ return _NXUnixPath;
+
+_NXGetUnixPathError:
+
+ strcpy(_NXUnixPath, path);
+
+#ifdef NX_TRANS_TEST
+ fprintf(stderr, "_NXGetUnixPath: Returning default X11 Unix path [%s].\n", _NXUnixPath);
+#endif
+
+ return _NXUnixPath;
+}
+
+#endif /* NX_TRANS_SOCKET */
diff --git a/nx-X11/lib/xtrans/Xtranstli.c b/nx-X11/lib/xtrans/Xtranstli.c
deleted file mode 100644
index 839498658..000000000
--- a/nx-X11/lib/xtrans/Xtranstli.c
+++ /dev/null
@@ -1,1420 +0,0 @@
-/*
-
-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.
-
-*/
-
-/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
- *
- * 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))
-
-/*
- * 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.
- */
-
-#if defined(X11_t)
-#define TLINODENAME "TLI:xserver"
-#endif
-
-#if defined(XIM_t)
-#define TLINODENAME "TLI:xim"
-#endif
-
-#if defined(FS_t) || defined(FONT_t)
-#define TLINODENAME "TLI:fontserver"
-#endif
-
-#if defined(ICE_t)
-#define TLINODENAME "TLI:ICE"
-#endif
-
-#if defined(TEST_t)
-#define TLINODENAME "TLI:test"
-#endif
-
-#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;
-
- PRMSG(3,"TLISelectFamily(%s)\n", family, 0,0 );
-
- 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;
-
- PRMSG(3,"TLIGetAddr(%x)\n", ciptr, 0,0 );
-
- netbuf.buf=(char *)&sockname;
- netbuf.len=sizeof(sockname);
- netbuf.maxlen=sizeof(sockname);
-
- if( t_getname(ciptr->fd,&netbuf,LOCALNAME) < 0 )
- {
- PRMSG(1,"TLIGetAddr: t_getname(LOCALNAME) failed: %d\n",
- errno, 0,0 );
- return -1;
- }
-
- PRMSG(4,"TLIGetAddr: got family %d len %d\n",
- ((struct sockaddr *) &sockname)->sa_family ,netbuf.len, 0 );
-
- /*
- * Everything looks good: fill in the XtransConnInfo structure.
- */
-
- if( ciptr->addr )
- free(ciptr->addr);
-
- if( (ciptr->addr=(char *)malloc(netbuf.len)) == NULL )
- {
- PRMSG(1, "TLIGetAddr: Can't allocate space for the addr\n",
- 0,0,0);
- return -1;
- }
-
- ciptr->family=((struct sockaddr *) &sockname)->sa_family;
- ciptr->addrlen=netbuf.len;
- memcpy(ciptr->addr,&sockname,ciptr->addrlen);
-
- 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;
-
- PRMSG(3,"TLIGetPeerAddr(%x)\n", ciptr, 0,0 );
-
- netbuf.buf=(char *)&sockname;
- netbuf.len=sizeof(sockname);
- netbuf.maxlen=sizeof(sockname);
-
- if( t_getname(ciptr->fd,&netbuf,REMOTENAME) < 0 )
- {
- PRMSG(1,"TLIGetPeerAddr: t_getname(REMOTENAME) failed: %d\n",
- errno, 0,0 );
- return -1;
- }
-
- PRMSG(4,"TLIGetPeerAddr: got family %d len %d\n",
- ((struct sockaddr *) &sockname)->sa_family ,netbuf.len, 0 );
-
- /*
- * Everything looks good: fill in the XtransConnInfo structure.
- */
-
- if( ciptr->peeraddr )
- free(ciptr->peeraddr);
-
- if( (ciptr->peeraddr=(char *)malloc(netbuf.len)) == NULL )
- {
- PRMSG(1,
- "TLIGetPeerAddr: Can't allocate space for the addr\n",
- 0,0,0);
- return -1;
- }
-
- ciptr->peeraddrlen=netbuf.len;
- memcpy(ciptr->peeraddr,&sockname,ciptr->peeraddrlen);
-
- 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;
-
- PRMSG(2, "TLITLIBindLocal(%d,%d,%s)\n", fd, family, port);
-
- if( family == AF_UNIX )
- {
- if( (req=(struct t_bind *)t_alloc(fd,T_BIND,0)) == NULL )
- {
- PRMSG(1,
- "TLITLIBindLocal() failed to allocate a t_bind\n",
- 0,0,0 );
- return -1;
- }
-
- if( (sunaddr=(struct sockaddr_un *)
- malloc(sizeof(struct sockaddr_un))) == NULL )
- {
- PRMSG(1,
- "TLITLIBindLocal: failed to allocate a sockaddr_un\n",
- 0,0,0 );
- t_free((char *)req,T_BIND);
- return -1;
- }
-
- sunaddr->sun_family=AF_UNIX;
-
-#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*/
-
- (void) sprintf(sunaddr->sun_path,"%s%d",
- TLINODENAME, getpid()^time(NULL) );
-
- PRMSG(4, "TLITLIBindLocal: binding to %s\n",
- sunaddr->sun_path, 0,0);
-
- req->addr.buf=(char *)sunaddr;
- req->addr.len=sizeof(*sunaddr);
- req->addr.maxlen=sizeof(*sunaddr);
- }
-
- if( t_bind(fd, req, NULL) < 0 )
- {
- PRMSG(1,
- "TLIBindLocal: Unable to bind TLI device to %s\n",
- port, 0,0 );
- 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;
-
- PRMSG(3,"TLIOpen(%s)\n", device, 0,0 );
-
- if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
- {
- PRMSG(1, "TLIOpen: calloc failed\n", 0,0,0 );
- return NULL;
- }
-
- if( (ciptr->fd=t_open( device, O_RDWR, NULL )) < 0 )
- {
- PRMSG(1, "TLIOpen: t_open failed for %s\n", device, 0,0 );
- free(ciptr);
- return NULL;
- }
-
- return ciptr;
-}
-
-
-#ifdef TRANS_REOPEN
-
-static XtransConnInfo
-TRANS(TLIReopen)(char *device, int fd, char *port)
-
-{
- XtransConnInfo ciptr;
-
- PRMSG(3,"TLIReopen(%s,%d, %s)\n", device, fd, port );
-
- if (t_sync (fd) < 0)
- {
- PRMSG(1, "TLIReopen: t_sync failed\n", 0,0,0 );
- return NULL;
- }
-
- if( (ciptr=(XtransConnInfo)calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
- {
- PRMSG(1, "TLIReopen: calloc failed\n", 0,0,0 );
- return NULL;
- }
-
- ciptr->fd = fd;
-
- return ciptr;
-}
-
-#endif /* TRANS_REOPEN */
-
-
-static int
-TRANS(TLIAddrToNetbuf)(int tlifamily, char *host, char *port,
- struct netbuf *netbufp)
-
-{
- struct netconfig *netconfigp;
- struct nd_hostserv nd_hostserv;
- struct nd_addrlist *nd_addrlistp = NULL;
- void *handlep;
- long lport;
-
- PRMSG(3,"TLIAddrToNetbuf(%d,%s,%s)\n", tlifamily, host, port );
-
- if( (handlep=setnetconfig()) == NULL )
- return -1;
-
- lport = strtol (port, (char**)NULL, 10);
- if (lport < 1024 || lport > USHRT_MAX)
- return -1;
-
- nd_hostserv.h_host = host;
- if( port && *port ) {
- nd_hostserv.h_serv = port;
- } else {
- nd_hostserv.h_serv = NULL;
- }
-
- while( (netconfigp=getnetconfig(handlep)) != NULL )
- {
- if( strcmp(netconfigp->nc_protofmly,
- TLItrans2devtab[tlifamily].protofamily) != 0 )
- continue;
- PRMSG(5,"TLIAddrToNetbuf: Trying to resolve %s.%s for %s\n",
- host, port, TLItrans2devtab[tlifamily].protofamily );
- if( netdir_getbyname(netconfigp,&nd_hostserv, &nd_addrlistp) == 0 )
- {
- /* we have at least one address to use */
-
- PRMSG(5, "TLIAddrToNetbuf: found address for %s.%s\n", host, port, 0 );
- PRMSG(5, "TLIAddrToNetbuf: %s\n",taddr2uaddr(netconfigp,nd_addrlistp->n_addrs),
- 0,0 );
-
- 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);
-
- return -1;
-}
-
-/*
- * These functions are the interface supplied in the Xtransport structure
- */
-
-#ifdef TRANS_CLIENT
-
-static XtransConnInfo
-TRANS(TLIOpenCOTSClient)(Xtransport *thistrans, char *protocol,
- char *host, char *port)
-
-{
- XtransConnInfo ciptr;
- int i;
-
- PRMSG(2,"TLIOpenCOTSClient(%s,%s,%s)\n", protocol, host, port );
-
- if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 )
- {
- PRMSG(1,"TLIOpenCOTSClient: Unable to determine device for %s\n",
- thistrans->TransName, 0,0 );
- return NULL;
- }
-
- if( (ciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcotsname)) == NULL )
- {
- PRMSG(1,"TLIOpenCOTSClient: Unable to open device for %s\n",
- thistrans->TransName, 0,0 );
- return NULL;
- }
-
- if( TRANS(TLITLIBindLocal)(ciptr->fd,TLItrans2devtab[i].family,port) < 0 )
- {
- PRMSG(1,
- "TLIOpenCOTSClient: ...TLITLIBindLocal() failed: %d\n",
- errno, 0,0 );
- t_close(ciptr->fd);
- free(ciptr);
- return NULL;
- }
-
- if( TRANS(TLIGetAddr)(ciptr) < 0 )
- {
- PRMSG(1,
- "TLIOpenCOTSClient: ...TLIGetAddr() failed: %d\n",
- errno, 0,0 );
- t_close(ciptr->fd);
- free(ciptr);
- return NULL;
- }
-
- /* Save the TLIFamily for later use in TLIAddrToNetbuf() lookups */
- ciptr->index = i;
-
- return ciptr;
-}
-
-#endif /* TRANS_CLIENT */
-
-
-#ifdef TRANS_SERVER
-
-static XtransConnInfo
-TRANS(TLIOpenCOTSServer)(Xtransport *thistrans, char *protocol,
- char *host, char *port)
-
-{
- XtransConnInfo ciptr;
- int i;
-
- PRMSG(2,"TLIOpenCOTSServer(%s,%s,%s)\n", protocol, host, port );
-
- if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 )
- {
- PRMSG(1,
- "TLIOpenCOTSServer: Unable to determine device for %s\n",
- thistrans->TransName, 0,0 );
- return NULL;
- }
-
- if( (ciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcotsname)) == NULL )
- {
- PRMSG(1,
- "TLIOpenCOTSServer: Unable to open device for %s\n",
- thistrans->TransName, 0,0 );
- return NULL;
- }
-
- /* Set the family type */
-
- ciptr->family = TLItrans2devtab[i].family;
-
-
- /* Save the TLIFamily for later use in TLIAddrToNetbuf() lookups */
-
- ciptr->index = i;
-
- return ciptr;
-}
-
-#endif /* TRANS_SERVER */
-
-
-#ifdef TRANS_CLIENT
-
-static XtransConnInfo
-TRANS(TLIOpenCLTSClient)(Xtransport *thistrans, char *protocol,
- char *host, char *port)
-
-{
- XtransConnInfo ciptr;
- int i;
-
- PRMSG(2,"TLIOpenCLTSClient(%s,%s,%s)\n", protocol, host, port );
-
- if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 )
- {
- PRMSG(1,
- "TLIOpenCLTSClient: Unable to determine device for %s\n",
- thistrans->TransName, 0,0 );
- return NULL;
- }
-
- if( (ciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcltsname)) == NULL )
- {
- PRMSG(1,
- "TLIOpenCLTSClient: Unable to open device for %s\n",
- thistrans->TransName, 0,0 );
- return NULL;
- }
-
- if( TRANS(TLITLIBindLocal)(ciptr->fd,TLItrans2devtab[i].family,port) < 0 )
- {
- PRMSG(1,
- "TLIOpenCLTSClient: ...TLITLIBindLocal() failed: %d\n",
- errno, 0,0 );
- t_close(ciptr->fd);
- free(ciptr);
- return NULL;
- }
-
- if( TRANS(TLIGetAddr)(ciptr) < 0 )
- {
- PRMSG(1,
- "TLIOpenCLTSClient: ...TLIGetPeerAddr() failed: %d\n",
- errno, 0,0 );
- t_close(ciptr->fd);
- free(ciptr);
- return NULL;
- }
-
- return ciptr;
-}
-
-#endif /* TRANS_CLIENT */
-
-
-#ifdef TRANS_SERVER
-
-static XtransConnInfo
-TRANS(TLIOpenCLTSServer)(Xtransport *thistrans, char *protocol,
- char *host, char *port)
-
-{
- XtransConnInfo ciptr;
- int i;
-
- PRMSG(2,"TLIOpenCLTSServer(%s,%s,%s)\n", protocol, host, port );
-
- if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 )
- {
- PRMSG(1,
- "TLIOpenCLTSServer: Unable to determine device for %s\n",
- thistrans->TransName, 0,0 );
- return NULL;
- }
-
- if( (ciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcltsname)) == NULL )
- {
- PRMSG(1,
- "TLIOpenCLTSServer: Unable to open device for %s\n",
- thistrans->TransName, 0,0 );
- return NULL;
- }
-
- return ciptr;
-}
-
-#endif /* TRANS_SERVER */
-
-
-#ifdef TRANS_REOPEN
-
-static XtransConnInfo
-TRANS(TLIReopenCOTSServer)(Xtransport *thistrans, int fd, char *port)
-
-{
- XtransConnInfo ciptr;
- int i;
-
- PRMSG(2,"TLIReopenCOTSServer(%d, %s)\n", fd, port, 0 );
-
- if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 )
- {
- PRMSG(1,
- "TLIReopenCOTSServer: Unable to determine device for %s\n",
- thistrans->TransName, 0,0 );
- return NULL;
- }
-
- if( (ciptr=TRANS(TLIReopen)(
- TLItrans2devtab[i].devcotsname, fd, port)) == NULL )
- {
- PRMSG(1,
- "TLIReopenCOTSServer: Unable to open device for %s\n",
- thistrans->TransName, 0,0 );
- return NULL;
- }
-
- /* Save the TLIFamily for later use in TLIAddrToNetbuf() lookups */
-
- ciptr->index = i;
-
- return ciptr;
-}
-
-
-static XtransConnInfo
-TRANS(TLIReopenCLTSServer)(Xtransport *thistrans, int fd, char *port)
-
-{
- XtransConnInfo ciptr;
- int i;
-
- PRMSG(2,"TLIReopenCLTSServer(%d, %s)\n", fd, port, 0 );
-
- if( (i=TRANS(TLISelectFamily)(thistrans->TransName)) < 0 )
- {
- PRMSG(1,
- "TLIReopenCLTSServer: Unable to determine device for %s\n",
- thistrans->TransName, 0,0 );
- return NULL;
- }
-
- if( (ciptr=TRANS(TLIReopen)(
- TLItrans2devtab[i].devcltsname, fd, port)) == NULL )
- {
- PRMSG(1,
- "TLIReopenCLTSServer: Unable to open device for %s\n",
- thistrans->TransName, 0,0 );
- return NULL;
- }
-
- ciptr->index = i;
-
- return ciptr;
-}
-
-#endif /* TRANS_REOPEN */
-
-
-static int
-TRANS(TLISetOption)(XtransConnInfo ciptr, int option, int arg)
-
-{
- PRMSG(2,"TLISetOption(%d,%d,%d)\n", ciptr->fd, option, arg );
-
- return -1;
-}
-
-
-#ifdef TRANS_SERVER
-
-static int
-TRANS(TLICreateListener)(XtransConnInfo ciptr, struct t_bind *req)
-
-{
- struct t_bind *ret;
-
- PRMSG(2,"TLICreateListener(%x->%d,%x)\n", ciptr, ciptr->fd, req );
-
- if( (ret=(struct t_bind *)t_alloc(ciptr->fd,T_BIND,T_ALL)) == NULL )
- {
- PRMSG(1, "TLICreateListener: failed to allocate a t_bind\n",
- 0,0,0 );
- t_free((char *)req,T_BIND);
- return TRANS_CREATE_LISTENER_FAILED;
- }
-
- if( t_bind(ciptr->fd, req, ret) < 0 )
- {
- PRMSG(1, "TLICreateListener: t_bind failed\n", 0,0,0 );
- t_free((char *)req,T_BIND);
- t_free((char *)ret,T_BIND);
- return TRANS_CREATE_LISTENER_FAILED;
- }
-
- if( memcmp(req->addr.buf,ret->addr.buf,req->addr.len) != 0 )
- {
- PRMSG(1, "TLICreateListener: unable to bind to %x\n",
- req, 0,0 );
- t_free((char *)req,T_BIND);
- t_free((char *)ret,T_BIND);
- return TRANS_ADDR_IN_USE;
- }
-
- /*
- * Everything looks good: fill in the XtransConnInfo structure.
- */
-
- if( (ciptr->addr=(char *)malloc(ret->addr.len)) == NULL )
- {
- PRMSG(1,
- "TLICreateListener: Unable to allocate space for the address\n",
- 0,0,0 );
- t_free((char *)req,T_BIND);
- t_free((char *)ret, T_BIND);
- return TRANS_CREATE_LISTENER_FAILED;
- }
-
- ciptr->addrlen=ret->addr.len;
- memcpy(ciptr->addr,ret->addr.buf,ret->addr.len);
-
- t_free((char *)req,T_BIND);
- t_free((char *)ret, T_BIND);
-
- 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;
-
- PRMSG(2,"TLIINETCreateListener(%x->%d,%s)\n", ciptr,
- ciptr->fd, port ? port : "NULL" );
-
-#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().
- */
-
- if (is_numeric (port))
- {
- tmpport = X_TCP_PORT + strtol (port, (char**)NULL, 10);
- sprintf(portbuf,"%u", tmpport);
- port = portbuf;
- }
-#endif
-
- if( (req=(struct t_bind *)t_alloc(ciptr->fd,T_BIND,T_ALL)) == NULL )
- {
- PRMSG(1,
- "TLIINETCreateListener: failed to allocate a t_bind\n",
- 0,0,0 );
- return TRANS_CREATE_LISTENER_FAILED;
- }
-
- if( port && *port ) {
- if(TRANS(TLIAddrToNetbuf)(ciptr->index,HOST_SELF,port,&(req->addr)) < 0)
- {
- PRMSG(1,
- "TLIINETCreateListener: can't resolve name:HOST_SELF.%s\n",
- port, 0,0 );
- 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;
-
- 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;
-
- PRMSG(2,"TLITLICreateListener(%x->%d,%s)\n", ciptr, ciptr->fd,
- port ? port : "NULL");
-
- if( (req=(struct t_bind *)t_alloc(ciptr->fd,T_BIND,0)) == NULL )
- {
- PRMSG(1,
- "TLITLICreateListener: failed to allocate a t_bind\n",
- 0,0,0 );
- return TRANS_CREATE_LISTENER_FAILED;
- }
-
- if( (sunaddr=(struct sockaddr_un *)
- malloc(sizeof(struct sockaddr_un))) == NULL )
- {
- PRMSG(1,
- "TLITLICreateListener: failed to allocate a sockaddr_un\n",
- 0,0,0 );
- t_free((char *)req,T_BIND);
- return TRANS_CREATE_LISTENER_FAILED;
- }
-
- 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());
- }
-
- req->addr.buf=(char *)sunaddr;
- req->addr.len=sizeof(*sunaddr);
- req->addr.maxlen=sizeof(*sunaddr);
-
- /* Set the qlen */
-
- req->qlen=1;
-
- 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;
-
- PRMSG(2,"TLIAccept(%x->%d)\n", ciptr, ciptr->fd, 0 );
-
- if( (call=(struct t_call *)t_alloc(ciptr->fd,T_CALL,T_ALL)) == NULL )
- {
- PRMSG(1, "TLIAccept() failed to allocate a t_call\n", 0,0,0 );
- *status = TRANS_ACCEPT_BAD_MALLOC;
- return NULL;
- }
-
- if( t_listen(ciptr->fd,call) < 0 )
- {
- extern char *t_errlist[];
- extern int t_errno;
- PRMSG(1, "TLIAccept() t_listen() failed\n", 0,0,0 );
- PRMSG(1, "TLIAccept: %s\n", t_errlist[t_errno], 0,0 );
- t_free((char *)call,T_CALL);
- *status = TRANS_ACCEPT_MISC_ERROR;
- return NULL;
- }
-
- /*
- * Now we need to set up the new endpoint for the incoming connection.
- */
-
- i=ciptr->index; /* Makes the next line more readable */
-
- if( (newciptr=TRANS(TLIOpen)(TLItrans2devtab[i].devcotsname)) == NULL )
- {
- PRMSG(1, "TLIAccept() failed to open a new endpoint\n", 0,0,0 );
- t_free((char *)call,T_CALL);
- *status = TRANS_ACCEPT_MISC_ERROR;
- return NULL;
- }
-
- if( TRANS(TLITLIBindLocal)(newciptr->fd,TLItrans2devtab[i].family,"") < 0 )
- {
- PRMSG(1,
- "TLIAccept: TRANS(TLITLIBindLocal)() failed: %d\n",
- errno, 0,0 );
- t_free((char *)call,T_CALL);
- t_close(newciptr->fd);
- free(newciptr);
- *status = TRANS_ACCEPT_MISC_ERROR;
- return NULL;
- }
-
-
- if( t_accept(ciptr->fd,newciptr->fd,call) < 0 )
- {
- extern char *t_errlist[];
- extern int t_errno;
- PRMSG(1, "TLIAccept() t_accept() failed\n", 0,0,0 );
- PRMSG(1, "TLIAccept: %s\n", t_errlist[t_errno], 0,0 );
- if( t_errno == TLOOK )
- {
- int evtype = t_look(ciptr->fd);
- PRMSG(1, "TLIAccept() t_look() returned %d\n", evtype,0,0 );
- switch( evtype )
- {
- case T_DISCONNECT:
- if( t_rcvdis(ciptr->fd, NULL) < 0 )
- {
- PRMSG(1, "TLIAccept() t_rcvdis() failed\n", 0,0,0 );
- PRMSG(1, "TLIAccept: %s\n", t_errlist[t_errno], 0,0 );
- }
- break;
- default:
- break;
- }
- }
- t_free((char *)call,T_CALL);
- t_close(newciptr->fd);
- free(newciptr);
- *status = TRANS_ACCEPT_FAILED;
- return NULL;
- }
-
- t_free((char *)call,T_CALL);
-
- if( TRANS(TLIGetAddr)(newciptr) < 0 )
- {
- PRMSG(1,
- "TLIAccept: TRANS(TLIGetPeerAddr)() failed: %d\n",
- errno, 0,0 );
- t_close(newciptr->fd);
- free(newciptr);
- *status = TRANS_ACCEPT_MISC_ERROR;
- return NULL;
- }
-
- if( TRANS(TLIGetPeerAddr)(newciptr) < 0 )
- {
- PRMSG(1,
- "TLIAccept: TRANS(TLIGetPeerAddr)() failed: %d\n",
- errno, 0,0 );
- t_close(newciptr->fd);
- free(newciptr->addr);
- free(newciptr);
- *status = TRANS_ACCEPT_MISC_ERROR;
- return NULL;
- }
-
- if( ioctl(newciptr->fd, I_POP,"timod") < 0 )
- {
- PRMSG(1, "TLIAccept() ioctl(I_POP, \"timod\") failed %d\n",
- errno,0,0 );
- t_close(newciptr->fd);
- free(newciptr->addr);
- free(newciptr);
- *status = TRANS_ACCEPT_MISC_ERROR;
- return NULL;
- }
-
- if( ioctl(newciptr->fd, I_PUSH,"tirdwr") < 0 )
- {
- PRMSG(1, "TLIAccept() ioctl(I_PUSH,\"tirdwr\") failed %d\n",
- errno,0,0 );
- t_close(newciptr->fd);
- free(newciptr->addr);
- free(newciptr);
- *status = TRANS_ACCEPT_MISC_ERROR;
- return NULL;
- }
-
- *status = 0;
-
- return newciptr;
-}
-
-#endif /* TRANS_SERVER */
-
-
-#ifdef TRANS_CLIENT
-
-static int
-TRANS(TLIConnect)(XtransConnInfo ciptr, struct t_call *sndcall )
-
-{
- PRMSG(2, "TLIConnect(%x->%d,%x)\n", ciptr, ciptr->fd, sndcall);
-
- if( t_connect(ciptr->fd,sndcall,NULL) < 0 )
- {
- extern char *t_errlist[];
- extern int t_errno;
- PRMSG(1, "TLIConnect() t_connect() failed\n", 0,0,0 );
- PRMSG(1, "TLIConnect: %s\n", t_errlist[t_errno], 0,0 );
- 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;
- }
-
- t_free((char *)sndcall,T_CALL);
-
- /*
- * Sync up the address fields of ciptr.
- */
-
- if( TRANS(TLIGetAddr)(ciptr) < 0 )
- {
- PRMSG(1,
- "TLIConnect: ...TLIGetAddr() failed: %d\n",
- errno, 0,0 );
- return TRANS_CONNECT_FAILED;
- }
-
- if( TRANS(TLIGetPeerAddr)(ciptr) < 0 )
- {
- PRMSG(1,
- "TLIConnect: ...TLIGetPeerAddr() failed: %d\n",
- errno, 0,0 );
- return TRANS_CONNECT_FAILED;
- }
-
- if( ioctl(ciptr->fd, I_POP,"timod") < 0 )
- {
- PRMSG(1, "TLIConnect() ioctl(I_POP,\"timod\") failed %d\n",
- errno,0,0 );
- return TRANS_CONNECT_FAILED;
- }
-
- if( ioctl(ciptr->fd, I_PUSH,"tirdwr") < 0 )
- {
- PRMSG(1, "TLIConnect() ioctl(I_PUSH,\"tirdwr\") failed %d\n",
- errno,0,0 );
- return TRANS_CONNECT_FAILED;
- }
-
- return 0;
-}
-
-
-static int
-TRANS(TLIINETConnect)(XtransConnInfo ciptr, char *host, char *port)
-
-{
- char portbuf[PORTBUFSIZE];
- struct t_call *sndcall;
- long tmpport;
-
- PRMSG(2, "TLIINETConnect(%s,%s)\n", host, port, 0);
-
-#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().
- */
-
- if (is_numeric (port))
- {
- tmpport = X_TCP_PORT + strtol (port, (char**)NULL, 10);
- sprintf(portbuf,"%u", tmpport );
- port = portbuf;
- }
-#endif
-
- if( (sndcall=(struct t_call *)t_alloc(ciptr->fd,T_CALL,T_ALL)) == NULL )
- {
- PRMSG(1, "TLIINETConnect() failed to allocate a t_call\n", 0,0,0 );
- return TRANS_CONNECT_FAILED;
- }
-
- if( TRANS(TLIAddrToNetbuf)(ciptr->index, host, port, &(sndcall->addr) ) < 0 )
- {
- PRMSG(1, "TLIINETConnect() unable to resolve name:%s.%s\n",
- host, port, 0 );
- t_free((char *)sndcall,T_CALL);
- return TRANS_CONNECT_FAILED;
- }
-
- 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;
-
- PRMSG(2, "TLITLIConnect(%s,%s)\n", host, port, 0);
-
- if( (sndcall=(struct t_call *)t_alloc(ciptr->fd,T_CALL,T_OPT|T_UDATA)) == NULL )
- {
- PRMSG(1, "TLITLIConnect() failed to allocate a t_call\n", 0,0,0 );
- return TRANS_CONNECT_FAILED;
- }
-
- if( (sunaddr=(struct sockaddr_un *)
- malloc(sizeof(struct sockaddr_un))) == NULL )
- {
- PRMSG(1,
- "TLITLIConnect: failed to allocate a sockaddr_un\n",
- 0,0,0 );
- t_free((char *)sndcall,T_CALL);
- return TRANS_CONNECT_FAILED;
- }
-
- 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);
-
- 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;
-
- PRMSG(2, "TLIByteReadable(%x->%d,%x)\n", ciptr, ciptr->fd, pend );
-
- /*
- * 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.
- */
-
- 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);
-
- 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)
-
-{
- PRMSG(2, "TLIRead(%d,%x,%d)\n", ciptr->fd, buf, size );
-
- return read(ciptr->fd,buf,size);
-}
-
-
-static int
-TRANS(TLIWrite)(XtransConnInfo ciptr, char *buf, int size)
-
-{
- PRMSG(2, "TLIWrite(%d,%x,%d)\n", ciptr->fd, buf, size );
-
- return write(ciptr->fd,buf,size);
-}
-
-
-static int
-TRANS(TLIReadv)(XtransConnInfo ciptr, struct iovec *buf, int size)
-
-{
- PRMSG(2, "TLIReadv(%d,%x,%d)\n", ciptr->fd, buf, size );
-
- return READV(ciptr,buf,size);
-}
-
-
-static int
-TRANS(TLIWritev)(XtransConnInfo ciptr, struct iovec *buf, int size)
-
-{
- PRMSG(2, "TLIWritev(%d,%x,%d)\n", ciptr->fd, buf, size );
-
- return WRITEV(ciptr,buf,size);
-}
-
-
-static int
-TRANS(TLIDisconnect)(XtransConnInfo ciptr)
-
-{
- PRMSG(2, "TLIDisconnect(%x->%d)\n", ciptr, ciptr->fd, 0 );
-
- /*
- * 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);
-
- return 0;
-}
-
-
-static int
-TRANS(TLIClose)(XtransConnInfo ciptr)
-
-{
- PRMSG(2, "TLIClose(%x->%d)\n", ciptr, ciptr->fd, 0 );
-
- t_unbind(ciptr->fd);
-
- return (t_close(ciptr->fd));
-}
-
-
-static int
-TRANS(TLICloseForCloning)(XtransConnInfo ciptr)
-
-{
- /*
- * Don't unbind.
- */
-
- PRMSG(2, "TLICloseForCloning(%x->%d)\n", ciptr, ciptr->fd, 0 );
-
- 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),
-};
diff --git a/nx-X11/lib/xtrans/Xtransutil.c b/nx-X11/lib/xtrans/Xtransutil.c
index 03bbce188..63f0fc355 100644
--- a/nx-X11/lib/xtrans/Xtransutil.c
+++ b/nx-X11/lib/xtrans/Xtransutil.c
@@ -24,9 +24,7 @@ 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.
-*/
-
-/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
*
* All Rights Reserved
*
@@ -57,7 +55,11 @@ from The Open Group.
*/
#ifdef XTHREADS
-#include <nx-X11/Xthreads.h>
+#include <X11/Xthreads.h>
+#endif
+#ifdef WIN32
+#include <X11/Xlibint.h>
+#include <X11/Xwinsock.h>
#endif
#ifdef X11_t
@@ -89,11 +91,11 @@ TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp)
{
- PRMSG(2,"ConvertAddress(%d,%d,%x)\n",*familyp,*addrlenp,*addrp);
+ prmsg(2,"ConvertAddress(%d,%d,%p)\n",*familyp,*addrlenp,*addrp);
switch( *familyp )
{
-#if defined(TCPCONN) || defined(STREAMSCONN)
+#if defined(TCPCONN)
case AF_INET:
{
/*
@@ -140,7 +142,7 @@ TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp)
{
*familyp=FamilyLocal;
}
- else
+ else
{
*familyp=FamilyInternet;
*addrlenp = sizeof (struct in_addr);
@@ -156,30 +158,16 @@ TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp)
break;
}
#endif /* IPv6 */
-#endif /* defined(TCPCONN) || defined(STREAMSCONN) */
-
-#if defined(DNETCONN)
- case AF_DECnet:
- {
- struct sockaddr_dn saddr;
-
- memcpy (&saddr, *addrp, sizeof (struct sockaddr_dn));
+#endif /* defined(TCPCONN) */
- *familyp=FamilyDECnet;
- *addrlenp=sizeof(struct dn_naddr);
- memcpy(*addrp,&saddr.sdn_add,*addrlenp);
- break;
- }
-#endif /* defined(DNETCONN) */
-
-#if defined(UNIXCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)
+#if defined(UNIXCONN) || defined(LOCALCONN)
case AF_UNIX:
{
*familyp=FamilyLocal;
break;
}
-#endif /* defined(UNIXCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)*/
+#endif /* defined(UNIXCONN) || defined(LOCALCONN) */
#if (defined(__SCO__) || defined(__UNIXWARE__)) && defined(LOCALCONN)
case 0:
@@ -190,8 +178,8 @@ TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp)
#endif
default:
- PRMSG(1,"ConvertAddress: Unknown family type %d\n",
- *familyp, 0,0 );
+ prmsg(1,"ConvertAddress: Unknown family type %d\n",
+ *familyp);
return -1;
}
@@ -202,18 +190,18 @@ TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp)
* In the case of a local connection, we need to get the
* host name for authentication.
*/
-
+
char hostnamebuf[256];
int len = TRANS(GetHostname) (hostnamebuf, sizeof hostnamebuf);
if (len > 0) {
if (*addrp && *addrlenp < (len + 1))
{
- free ((char *) *addrp);
+ free (*addrp);
*addrp = NULL;
}
if (!*addrp)
- *addrp = (Xtransaddr *) malloc (len + 1);
+ *addrp = malloc (len + 1);
if (*addrp) {
strcpy ((char *) *addrp, hostnamebuf);
*addrlenp = len;
@@ -224,7 +212,7 @@ TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp)
else
{
if (*addrp)
- free ((char *) *addrp);
+ free (*addrp);
*addrp = NULL;
*addrlenp = 0;
}
@@ -237,6 +225,13 @@ TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp)
#ifdef ICE_t
+/* Needed for _XGethostbyaddr usage in TRANS(GetPeerNetworkId) */
+# if defined(TCPCONN) || defined(UNIXCONN)
+# define X_INCLUDE_NETDB_H
+# define XOS_USE_NO_LOCKING
+# include <X11/Xos_r.h>
+# endif
+
#include <signal.h>
char *
@@ -247,7 +242,7 @@ TRANS(GetMyNetworkId) (XtransConnInfo ciptr)
char *addr = ciptr->addr;
char hostnamebuf[256];
char *networkId = NULL;
- char *transName = ciptr->transptr->TransName;
+ const char *transName = ciptr->transptr->TransName;
if (gethostname (hostnamebuf, sizeof (hostnamebuf)) < 0)
{
@@ -256,19 +251,19 @@ TRANS(GetMyNetworkId) (XtransConnInfo ciptr)
switch (family)
{
-#if defined(UNIXCONN) || defined(STREAMSCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)
+#if defined(UNIXCONN) || defined(LOCALCONN)
case AF_UNIX:
{
struct sockaddr_un *saddr = (struct sockaddr_un *) addr;
- networkId = (char *) malloc (3 + strlen (transName) +
+ networkId = malloc (3 + strlen (transName) +
strlen (hostnamebuf) + strlen (saddr->sun_path));
sprintf (networkId, "%s/%s:%s", transName,
hostnamebuf, saddr->sun_path);
break;
}
-#endif /* defined(UNIXCONN) || defined(STREAMSCONN) || defined(LOCALCONN) || defined(OS2PIPECONN) */
+#endif /* defined(UNIXCONN) || defined(LOCALCONN) */
-#if defined(TCPCONN) || defined(STREAMSCONN)
+#if defined(TCPCONN)
case AF_INET:
#if defined(IPv6) && defined(AF_INET6)
case AF_INET6:
@@ -289,26 +284,14 @@ TRANS(GetMyNetworkId) (XtransConnInfo ciptr)
#endif
portnum = ntohs (saddr->sin_port);
- sprintf (portnumbuf, "%d", portnum);
- networkId = (char *) malloc (3 + strlen (transName) +
+ snprintf (portnumbuf, sizeof(portnumbuf), "%d", portnum);
+ networkId = malloc (3 + strlen (transName) +
strlen (hostnamebuf) + strlen (portnumbuf));
sprintf (networkId, "%s/%s:%s", transName, hostnamebuf, portnumbuf);
break;
}
-#endif /* defined(TCPCONN) || defined(STREAMSCONN) */
-
-#if defined(DNETCONN)
- case AF_DECnet:
- {
- struct sockaddr_dn *saddr = (struct sockaddr_dn *) addr;
+#endif /* defined(TCPCONN) */
- networkId = (char *) malloc (
- 13 + strlen (hostnamebuf) + saddr->sdn_objnamel);
- sprintf (networkId, "dnet/%s::%s",
- hostnamebuf, saddr->sdn_objname);
- break;
- }
-#endif /* defined(DNETCONN) */
default:
break;
@@ -323,24 +306,12 @@ static jmp_buf env;
#ifdef SIGALRM
static volatile int nameserver_timedout = 0;
-static
-#ifdef RETSIGTYPE /* set by autoconf AC_TYPE_SIGNAL */
-RETSIGTYPE
-#else /* Imake */
-#ifdef SIGNALRETURNSINT
-int
-#else
-void
-#endif
-#endif
-nameserver_lost(int sig)
+static void
+nameserver_lost(int sig _X_UNUSED)
{
nameserver_timedout = 1;
longjmp (env, -1);
/* NOTREACHED */
-#ifdef SIGNALRETURNSINT
- return -1; /* for picky compilers */
-#endif
}
#endif /* SIGALARM */
@@ -358,16 +329,16 @@ TRANS(GetPeerNetworkId) (XtransConnInfo ciptr)
switch (family)
{
case AF_UNSPEC:
-#if defined(UNIXCONN) || defined(STREAMSCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)
+#if defined(UNIXCONN) || defined(LOCALCONN)
case AF_UNIX:
{
if (gethostname (addrbuf, sizeof (addrbuf)) == 0)
addr = addrbuf;
break;
}
-#endif /* defined(UNIXCONN) || defined(STREAMSCONN) || defined(LOCALCONN) || defined(OS2PIPECONN) */
+#endif /* defined(UNIXCONN) || defined(LOCALCONN) */
-#if defined(TCPCONN) || defined(STREAMSCONN)
+#if defined(TCPCONN)
case AF_INET:
#if defined(IPv6) && defined(AF_INET6)
case AF_INET6:
@@ -403,7 +374,7 @@ TRANS(GetPeerNetworkId) (XtransConnInfo ciptr)
* Assume that if it does not respond in NAMESERVER_TIMEOUT seconds
* that something is wrong and do not make the user wait.
* gethostbyaddr will continue after a signal, so we have to
- * jump out of it.
+ * jump out of it.
*/
nameserver_timedout = 0;
@@ -427,32 +398,15 @@ TRANS(GetPeerNetworkId) (XtransConnInfo ciptr)
break;
}
-#endif /* defined(TCPCONN) || defined(STREAMSCONN) */
+#endif /* defined(TCPCONN) */
-#if defined(DNETCONN)
- case AF_DECnet:
- {
- struct sockaddr_dn *saddr = (struct sockaddr_dn *) peer_addr;
- struct nodeent *np;
-
- if (np = getnodebyaddr(saddr->sdn_add.a_addr,
- saddr->sdn_add.a_len, AF_DECnet)) {
- sprintf(addrbuf, "%s:", np->n_name);
- } else {
- sprintf(addrbuf, "%s:", dnet_htoa(&saddr->sdn_add));
- }
- addr = addrbuf;
- break;
- }
-#endif /* defined(DNETCONN) */
default:
return (NULL);
}
- hostname = (char *) malloc (
- strlen (ciptr->transptr->TransName) + strlen (addr) + 2);
+ hostname = malloc (strlen (ciptr->transptr->TransName) + strlen (addr) + 2);
strcpy (hostname, ciptr->transptr->TransName);
strcat (hostname, "/");
if (addr)
@@ -464,24 +418,24 @@ TRANS(GetPeerNetworkId) (XtransConnInfo ciptr)
#endif /* ICE_t */
-#if defined(WIN32) && (defined(TCPCONN) || defined(DNETCONN))
+#if defined(WIN32) && defined(TCPCONN)
int
TRANS(WSAStartup) (void)
{
static WSADATA wsadata;
- PRMSG (2,"WSAStartup()\n", 0, 0, 0);
+ prmsg (2,"WSAStartup()\n");
- if (!wsadata.wVersion && WSAStartup(0x0101, &wsadata))
+ if (!wsadata.wVersion && WSAStartup(MAKEWORD(2,2), &wsadata))
return 1;
return 0;
}
#endif
+#include <ctype.h>
static int
-is_numeric (char *str)
-
+is_numeric (const char *str)
{
int i;
@@ -511,20 +465,20 @@ is_numeric (char *str)
* it's not save if the directory has non-root ownership or the sticky
* bit cannot be set and fail.
*/
-static int
-trans_mkdir(char *path, int mode)
+static int
+trans_mkdir(const char *path, int mode)
{
struct stat buf;
if (lstat(path, &buf) != 0) {
if (errno != ENOENT) {
- PRMSG(1, "mkdir: ERROR: (l)stat failed for %s (%d)\n",
- path, errno, 0);
+ prmsg(1, "mkdir: ERROR: (l)stat failed for %s (%d)\n",
+ path, errno);
return -1;
}
/* Dir doesn't exist. Try to create it */
-#ifndef WIN32
+#if !defined(WIN32) && !defined(__CYGWIN__)
/*
* 'sticky' bit requested: assume application makes
* certain security implications. If effective user ID
@@ -532,15 +486,15 @@ trans_mkdir(char *path, int mode)
*/
if (geteuid() != 0) {
if (mode & 01000) {
- PRMSG(1, "mkdir: ERROR: euid != 0,"
+ prmsg(1, "mkdir: ERROR: euid != 0,"
"directory %s will not be created.\n",
- path, 0, 0);
+ path);
#ifdef FAIL_HARD
return -1;
#endif
} else {
- PRMSG(1, "mkdir: Cannot create %s with root ownership\n",
- path, 0, 0);
+ prmsg(1, "mkdir: Cannot create %s with root ownership\n",
+ path);
}
}
#endif
@@ -548,8 +502,8 @@ trans_mkdir(char *path, int mode)
#ifndef WIN32
if (mkdir(path, mode) == 0) {
if (chmod(path, mode)) {
- PRMSG(1, "mkdir: ERROR: Mode of %s should be set to %04o\n",
- path, mode, 0);
+ prmsg(1, "mkdir: ERROR: Mode of %s should be set to %04o\n",
+ path, mode);
#ifdef FAIL_HARD
return -1;
#endif
@@ -558,13 +512,13 @@ trans_mkdir(char *path, int mode)
if (mkdir(path) == 0) {
#endif
} else {
- PRMSG(1, "mkdir: ERROR: Cannot create %s\n",
- path, 0, 0);
+ prmsg(1, "mkdir: ERROR: Cannot create %s\n",
+ path);
return -1;
}
return 0;
-
+
} else {
if (S_ISDIR(buf.st_mode)) {
int updateOwner = 0;
@@ -583,7 +537,7 @@ trans_mkdir(char *path, int mode)
*/
if ((~mode) & 0077 & buf.st_mode)
updateMode = 1;
-
+
/*
* If the directory is not writeable not everybody may
* be able to create sockets. Therefore warn if mode
@@ -593,7 +547,7 @@ trans_mkdir(char *path, int mode)
updateMode = 1;
status |= WARN_NO_ACCESS;
}
-
+
/*
* If 'sticky' bit is requested fail if owner isn't root
* as we assume the caller makes certain security implications
@@ -605,7 +559,7 @@ trans_mkdir(char *path, int mode)
updateMode = 1;
}
}
-
+
#ifdef HAS_FCHOWN
/*
* If fchown(2) and fchmod(2) are available, try to correct the
@@ -617,8 +571,9 @@ trans_mkdir(char *path, int mode)
struct stat fbuf;
if ((fd = open(path, O_RDONLY)) != -1) {
if (fstat(fd, &fbuf) == -1) {
- PRMSG(1, "mkdir: ERROR: fstat failed for %s (%d)\n",
- path, errno, 0);
+ prmsg(1, "mkdir: ERROR: fstat failed for %s (%d)\n",
+ path, errno);
+ close(fd);
return -1;
}
/*
@@ -628,8 +583,9 @@ trans_mkdir(char *path, int mode)
if (!S_ISDIR(fbuf.st_mode) ||
buf.st_dev != fbuf.st_dev ||
buf.st_ino != fbuf.st_ino) {
- PRMSG(1, "mkdir: ERROR: inode for %s changed\n",
- path, 0, 0);
+ prmsg(1, "mkdir: ERROR: inode for %s changed\n",
+ path);
+ close(fd);
return -1;
}
if (updateOwner && fchown(fd, 0, 0) == 0)
@@ -640,32 +596,33 @@ trans_mkdir(char *path, int mode)
}
}
#endif
-
+
if (updateOwner && !updatedOwner) {
#ifdef FAIL_HARD
if (status & FAIL_IF_NOT_ROOT) {
- PRMSG(1, "mkdir: ERROR: Owner of %s must be set to root\n",
- path, 0, 0);
+ prmsg(1, "mkdir: ERROR: Owner of %s must be set to root\n",
+ path);
return -1;
}
#endif
- PRMSG(1, "mkdir: Owner of %s should be set to root\n",
- path, 0, 0);
+#if !defined(__APPLE_CC__) && !defined(__CYGWIN__)
+ prmsg(1, "mkdir: Owner of %s should be set to root\n",
+ path);
+#endif
}
-
+
if (updateMode && !updatedMode) {
#ifdef FAIL_HARD
if (status & FAIL_IF_NOMODE) {
- PRMSG(1, "mkdir: ERROR: Mode of %s must be set to %04o\n",
- path, mode, 0);
+ prmsg(1, "mkdir: ERROR: Mode of %s must be set to %04o\n",
+ path, mode);
return -1;
}
#endif
- PRMSG(1, "mkdir: Mode of %s should be set to %04o\n",
- path, mode, 0);
+ prmsg(1, "mkdir: Mode of %s should be set to %04o\n",
+ path, mode);
if (status & WARN_NO_ACCESS) {
- PRMSG(1, "mkdir: this may cause subsequent errors\n",
- 0, 0, 0);
+ prmsg(1, "mkdir: this may cause subsequent errors\n");
}
}
return 0;
diff --git a/nx-X11/lib/xtrans/transport.c b/nx-X11/lib/xtrans/transport.c
index e1a8b45ec..b62fc7b64 100644
--- a/nx-X11/lib/xtrans/transport.c
+++ b/nx-X11/lib/xtrans/transport.c
@@ -24,9 +24,7 @@ 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.
-*/
-
-/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
*
* All Rights Reserved
*
@@ -49,32 +47,28 @@ from The Open Group.
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifdef __UNIXOS2__
-#define I_NEED_OS2_H
-#endif
-
-#ifdef XSERV_t
-#include "os.h"
-#else
#include <stdlib.h>
-#endif
+
+#define XTRANS_TRANSPORT_C /* used to flag Xtransint.h that it's being used
+ here, not just #included in another file */
#include "Xtransint.h"
-#ifdef DNETCONN
-#include "Xtransdnet.c"
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
+
#ifdef LOCALCONN
#include "Xtranslcl.c"
#endif
-#ifdef OS2PIPECONN
-#include "Xtransos2.c"
-#endif
#if defined(TCPCONN) || defined(UNIXCONN)
#include "Xtranssock.c"
#endif
-#ifdef STREAMSCONN
-#include "Xtranstli.c"
-#endif
#include "Xtrans.c"
#include "Xtransutil.c"
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
diff --git a/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 b/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1
index 03c5de3b5..769367c54 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1
+++ b/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1
@@ -852,7 +852,7 @@ property Woo-Hoo OhBoy = "*son" ad
.fi
.SH "NETWORK CONNECTIONS"
The X server supports client connections via a platform-dependent subset of
-the following transport types: TCP\/IP, Unix Domain sockets, DECnet,
+the following transport types: TCP\/IP, Unix Domain sockets
and several varieties of SVR4 local connections. See the DISPLAY
NAMES section of the \fIX\fP(__miscmansuffix__) manual page to learn how to
specify which transport type clients should try to use.
@@ -882,9 +882,9 @@ If no other authorization mechanism is being used,
this list initially consists of the host on which the server is running as
well as any machines listed in the file \fI/etc/X\fBn\fI.hosts\fR, where
\fBn\fP is the display number of the server. Each line of the file should
-contain either an Internet hostname (e.g. expo.lcs.mit.edu) or a DECnet
-hostname in double colon format (e.g. hydra::) or a complete name in the format
-\fIfamily\fP:\fIname\fP as described in the \fIxhost\fP(1) manual page.
+contain either an Internet hostname (e.g. expo.lcs.mit.edu) or a complete
+name in the format \fIfamily\fP:\fIname\fP as described in the
+\fIxhost\fP(1) manual page.
There should be no leading or trailing spaces on any lines. For example:
.sp
.in +8
diff --git a/nx-X11/programs/Xserver/os/access.c b/nx-X11/programs/Xserver/os/access.c
index 532e32f68..5735fd556 100644
--- a/nx-X11/programs/Xserver/os/access.c
+++ b/nx-X11/programs/Xserver/os/access.c
@@ -84,13 +84,9 @@ SOFTWARE.
#include <sys/ioctl.h>
#include <ctype.h>
-#if defined(TCPCONN) || defined(STREAMSCONN) || defined(ISC) || defined(__SCO__)
+#if defined(TCPCONN) || defined(ISC) || defined(__SCO__)
#include <netinet/in.h>
-#endif /* TCPCONN || STREAMSCONN || ISC || __SCO__ */
-#ifdef DNETCONN
-#include <netdnet/dn.h>
-#include <netdnet/dnetdb.h>
-#endif
+#endif /* TCPCONN || ISC || __SCO__ */
#ifdef HAS_GETPEERUCRED
# include <ucred.h>
@@ -529,7 +525,7 @@ DefineSelf (int fd)
void
DefineSelf (int fd)
{
-#if !defined(TCPCONN) && !defined(STREAMSCONN) && !defined(UNIXCONN) && !defined(MNX_TCPCONN)
+#if !defined(TCPCONN) && !defined(UNIXCONN) && !defined(MNX_TCPCONN)
return;
#else
register int n;
@@ -672,7 +668,7 @@ DefineLocalHost:
selfhosts = host;
}
}
-#endif /* !TCPCONN && !STREAMSCONN && !UNIXCONN && !MNX_TCPCONN */
+#endif /* !TCPCONN && !UNIXCONN && !MNX_TCPCONN */
}
#else
@@ -740,35 +736,6 @@ DefineSelf (int fd)
int family;
register HOST *host;
-#ifdef DNETCONN
- struct dn_naddr *dnaddr = getnodeadd();
- /*
- * AF_DECnet may not be listed in the interface list. Instead use
- * the supported library call to find out the local address (if any).
- */
- if (dnaddr)
- {
- addr = (unsigned char *) dnaddr;
- len = dnaddr->a_len + sizeof(dnaddr->a_len);
- family = FamilyDECnet;
- for (host = selfhosts;
- host && !addrEqual (family, addr, len, host);
- host = host->next)
- ;
- if (!host)
- {
- MakeHost(host,len)
- if (host)
- {
- host->family = family;
- host->len = len;
- acopy(addr, host->addr, len);
- host->next = selfhosts;
- selfhosts = host;
- }
- }
- }
-#endif /* DNETCONN */
#ifndef HAS_GETIFADDRS
len = sizeof(buf);
@@ -823,13 +790,6 @@ DefineSelf (int fd)
len = ifraddr_size (IFR_IFR_ADDR);
family = ConvertAddr ((struct sockaddr *) &IFR_IFR_ADDR,
&len, (void **)&addr);
-#ifdef DNETCONN
- /*
- * DECnet was handled up above.
- */
- if (family == AF_DECnet)
- continue;
-#endif /* DNETCONN */
if (family == -1 || family == FamilyLocal)
continue;
#if defined(IPv6) && defined(AF_INET6)
@@ -975,10 +935,6 @@ DefineSelf (int fd)
return;
}
for (ifr = ifap; ifr != NULL; ifr = ifr->ifa_next) {
-#ifdef DNETCONN
- if (ifr->ifa_addr.sa_family == AF_DECnet)
- continue;
-#endif /* DNETCONN */
len = sizeof(*(ifr->ifa_addr));
family = ConvertAddr(ifr->ifa_addr, &len, (void **)&addr);
if (family == -1 || family == FamilyLocal)
@@ -1154,22 +1110,15 @@ ResetHosts (char *display)
FILE *fd;
char *ptr;
int i, hostlen;
-#if ((defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)) && \
- (!defined(IPv6) || !defined(AF_INET6))) || defined(DNETCONN)
+#if ((defined(TCPCONN) || defined(MNX_TCPCONN)) && \
+ (!defined(IPv6) || !defined(AF_INET6)))
union {
struct sockaddr sa;
-#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)
+#if defined(TCPCONN) || defined(MNX_TCPCONN)
struct sockaddr_in in;
-#endif /* TCPCONN || STREAMSCONN */
-#ifdef DNETCONN
- struct sockaddr_dn dn;
-#endif
+#endif /* TCPCONN */
} saddr;
#endif
-#ifdef DNETCONN
- struct nodeent *np;
- struct dn_naddr dnaddr, *dnaddrp, *dnet_addr();
-#endif
int family = 0;
void *addr = NULL;
int len;
@@ -1217,7 +1166,7 @@ ResetHosts (char *display)
NewHost(family, "", 0, FALSE);
LocalHostRequested = TRUE; /* Fix for XFree86 bug #156 */
}
-#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)
+#if defined(TCPCONN) || defined(MNX_TCPCONN)
else if (!strncmp("inet:", lhostname, 5))
{
family = FamilyInternet;
@@ -1231,13 +1180,6 @@ ResetHosts (char *display)
}
#endif
#endif
-#ifdef DNETCONN
- else if (!strncmp("dnet:", lhostname, 5))
- {
- family = FamilyDECnet;
- hostname = ohostname + 5;
- }
-#endif
#ifdef SECURE_RPC
else if (!strncmp("nis:", lhostname, 4))
{
@@ -1261,32 +1203,6 @@ ResetHosts (char *display)
}
}
else
-#ifdef DNETCONN
- if ((family == FamilyDECnet) || ((family == FamilyWild) &&
- (ptr = strchr(hostname, ':')) && (*(ptr + 1) == ':') &&
- !(*ptr = '\0'))) /* bash trailing colons if necessary */
- {
- /* node name (DECnet names end in "::") */
- dnaddrp = dnet_addr(hostname);
- if (!dnaddrp && (np = getnodebyname (hostname)))
- {
- /* node was specified by name */
- saddr.sa.sa_family = np->n_addrtype;
- len = sizeof(saddr.sa);
- if (ConvertAddr (&saddr.sa, &len, (void **)&addr) == FamilyDECnet)
- {
- bzero ((char *) &dnaddr, sizeof (dnaddr));
- dnaddr.a_len = np->n_length;
- acopy (np->n_addr, dnaddr.a_addr, np->n_length);
- dnaddrp = &dnaddr;
- }
- }
- if (dnaddrp)
- (void) NewHost(FamilyDECnet, (void *)dnaddrp,
- (int)(dnaddrp->a_len + sizeof(dnaddrp->a_len)), FALSE);
- }
- else
-#endif /* DNETCONN */
#ifdef SECURE_RPC
if ((family == FamilyNetname) || (strchr(hostname, '@')))
{
@@ -1295,7 +1211,7 @@ ResetHosts (char *display)
}
else
#endif /* SECURE_RPC */
-#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)
+#if defined(TCPCONN) || defined(MNX_TCPCONN)
{
#if defined(IPv6) && defined(AF_INET6)
if ( (family == FamilyInternet) || (family == FamilyInternet6) ||
@@ -1345,7 +1261,7 @@ ResetHosts (char *display)
}
#endif /* IPv6 */
}
-#endif /* TCPCONN || STREAMSCONN */
+#endif /* TCPCONN */
family = FamilyWild;
}
fclose (fd);
@@ -1542,7 +1458,6 @@ AddHost (ClientPtr client,
#if defined(IPv6) && defined(AF_INET6)
case FamilyInternet6:
#endif
- case FamilyDECnet:
case FamilyChaos:
case FamilyServerInterpreted:
if ((len = CheckAddr (family, pAddr, length)) < 0)
@@ -1639,7 +1554,6 @@ RemoveHost (
#if defined(IPv6) && defined(AF_INET6)
case FamilyInternet6:
#endif
- case FamilyDECnet:
case FamilyChaos:
case FamilyServerInterpreted:
if ((len = CheckAddr (family, pAddr, length)) < 0)
@@ -1728,7 +1642,7 @@ CheckAddr (
switch (family)
{
-#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)
+#if defined(TCPCONN) || defined(MNX_TCPCONN)
case FamilyInternet:
if (length == sizeof (struct in_addr))
len = length;
@@ -1744,21 +1658,6 @@ CheckAddr (
break;
#endif
#endif
-#ifdef DNETCONN
- case FamilyDECnet:
- {
- struct dn_naddr *dnaddr = (struct dn_naddr *) pAddr;
-
- if ((length < sizeof(dnaddr->a_len)) ||
- (length < dnaddr->a_len + sizeof(dnaddr->a_len)))
- len = -1;
- else
- len = dnaddr->a_len + sizeof(dnaddr->a_len);
- if (len > sizeof(struct dn_naddr))
- len = -1;
- }
- break;
-#endif
case FamilyServerInterpreted:
len = siCheckAddr(pAddr, length);
break;
@@ -1832,11 +1731,11 @@ ConvertAddr (
switch (saddr->sa_family)
{
case AF_UNSPEC:
-#if defined(UNIXCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)
+#if defined(UNIXCONN) || defined(LOCALCONN)
case AF_UNIX:
#endif
return FamilyLocal;
-#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)
+#if defined(TCPCONN) || defined(MNX_TCPCONN)
case AF_INET:
#ifdef WIN32
if (16777343 == *(long*)&((struct sockaddr_in *) saddr)->sin_addr)
@@ -1861,15 +1760,6 @@ ConvertAddr (
}
#endif
#endif
-#ifdef DNETCONN
- case AF_DECnet:
- {
- struct sockaddr_dn *sdn = (struct sockaddr_dn *) saddr;
- *len = sdn->sdn_nodeaddrl + sizeof(sdn->sdn_nodeaddrl);
- *addr = (void *) &(sdn->sdn_add);
- }
- return FamilyDECnet;
-#endif
#ifdef CHAOSCONN
case AF_CHAOS:
{
diff --git a/nx-X11/programs/Xserver/os/connection.c b/nx-X11/programs/Xserver/os/connection.c
index 9cba17864..9681ced38 100644
--- a/nx-X11/programs/Xserver/os/connection.c
+++ b/nx-X11/programs/Xserver/os/connection.c
@@ -112,7 +112,7 @@ SOFTWARE.
extern __const__ int _nfiles;
#endif
-#if defined(TCPCONN) || defined(STREAMSCONN)
+#if defined(TCPCONN)
# include <netinet/in.h>
# include <arpa/inet.h>
# if !defined(hpux)
@@ -156,10 +156,6 @@ extern __const__ int _nfiles;
#define Pid_t pid_t
#endif
-#ifdef DNETCONN
-#include <netdnet/dn.h>
-#endif /* DNETCONN */
-
int lastfdesc; /* maximum file descriptor */
fd_set WellKnownConnections; /* Listener mask */
@@ -600,12 +596,12 @@ AuthAudit (ClientPtr client, Bool letin,
switch (saddr->sa_family)
{
case AF_UNSPEC:
-#if defined(UNIXCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)
+#if defined(UNIXCONN) || defined(LOCALCONN)
case AF_UNIX:
#endif
strcpy(out, "local host");
break;
-#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)
+#if defined(TCPCONN) || defined(MNX_TCPCONN)
case AF_INET:
sprintf(out, "IP %s",
inet_ntoa(((struct sockaddr_in *) saddr)->sin_addr));
@@ -620,12 +616,6 @@ AuthAudit (ClientPtr client, Bool letin,
break;
#endif
#endif
-#ifdef DNETCONN
- case AF_DECnet:
- sprintf(out, "DN %s",
- dnet_ntoa(&((struct sockaddr_dn *) saddr)->sdn_add));
- break;
-#endif
default:
strcpy(out, "unknown address");
}
diff --git a/nx-X11/programs/Xserver/os/utils.c b/nx-X11/programs/Xserver/os/utils.c
index 8c69b1346..9584dadd3 100644
--- a/nx-X11/programs/Xserver/os/utils.c
+++ b/nx-X11/programs/Xserver/os/utils.c
@@ -131,7 +131,7 @@ OR PERFORMANCE OF THIS SOFTWARE.
#include <stdlib.h> /* for malloc() */
-#if defined(TCPCONN) || defined(STREAMSCONN)
+#if defined(TCPCONN)
# ifndef WIN32
# include <netdb.h>
# endif
@@ -1285,7 +1285,7 @@ int
set_font_authorizations(char **authorizations, int *authlen, void * client)
{
#define AUTHORIZATION_NAME "hp-hostname-1"
-#if defined(TCPCONN) || defined(STREAMSCONN)
+#if defined(TCPCONN)
static char *result = NULL;
static char *p = NULL;
diff --git a/nx-X11/programs/Xserver/os/xdmauth.c b/nx-X11/programs/Xserver/os/xdmauth.c
index 48e1da6df..4a59b48f2 100644
--- a/nx-X11/programs/Xserver/os/xdmauth.c
+++ b/nx-X11/programs/Xserver/os/xdmauth.c
@@ -284,7 +284,7 @@ XdmAuthorizationValidate (unsigned char *plain, int length,
if (_XSERVTransGetPeerAddr(((OsCommPtr)xclient->osPrivate)->trans_conn,
&family, &addr_len, &addr) == 0
&& _XSERVTransConvertAddress(&family, &addr_len, &addr) == 0) {
-#if defined(TCPCONN) || defined(STREAMSCONN)
+#if defined(TCPCONN)
if (family == FamilyInternet &&
memcmp((char *)addr, client->client, 4) != 0) {
free (client);
diff --git a/nx-X11/programs/Xserver/os/xdmcp.c b/nx-X11/programs/Xserver/os/xdmcp.c
index d84fe2906..5daf1cbbf 100644
--- a/nx-X11/programs/Xserver/os/xdmcp.c
+++ b/nx-X11/programs/Xserver/os/xdmcp.c
@@ -54,11 +54,6 @@
#include <sys/ioctl.h>
#endif
-#ifdef STREAMSCONN
-#include <tiuser.h>
-#include <netconfig.h>
-#include <netdir.h>
-#endif
#ifndef NX_TRANS_SOCKET
@@ -1029,43 +1024,6 @@ XdmcpAddAuthorization (
static void
get_xdmcp_sock(void)
{
-#ifdef STREAMSCONN
- struct netconfig *nconf;
-
- if ((xdmcpSocket = t_open("/dev/udp", O_RDWR, 0)) < 0) {
- XdmcpWarning("t_open() of /dev/udp failed");
- return;
- }
-
- if( t_bind(xdmcpSocket,NULL,NULL) < 0 ) {
- XdmcpWarning("UDP socket creation failed");
- t_error("t_bind(xdmcpSocket) failed" );
- t_close(xdmcpSocket);
- return;
- }
-
- /*
- * This part of the code looks contrived. It will actually fit in nicely
- * when the CLTS part of Xtrans is implemented.
- */
-
- if( (nconf=getnetconfigent("udp")) == NULL ) {
- XdmcpWarning("UDP socket creation failed: getnetconfigent()");
- t_unbind(xdmcpSocket);
- t_close(xdmcpSocket);
- return;
- }
-
- if( netdir_options(nconf, ND_SET_BROADCAST, xdmcpSocket, NULL) ) {
- XdmcpWarning("UDP set broadcast option failed: netdir_options()");
- freenetconfigent(nconf);
- t_unbind(xdmcpSocket);
- t_close(xdmcpSocket);
- return;
- }
-
- freenetconfigent(nconf);
-#else
int soopts = 1;
#if defined(IPv6) && defined(AF_INET6)
@@ -1085,7 +1043,6 @@ get_xdmcp_sock(void)
FatalError("Xserver: failed to bind to -from address: %s\n", xdm_from);
}
}
-#endif /* STREAMSCONN */
}
static void
@@ -1572,7 +1529,7 @@ get_addr_by_name(
#ifdef XTHREADS_NEEDS_BYNAMEPARAMS
_Xgethostbynameparams hparams;
#endif
-#if defined(WIN32) && (defined(TCPCONN) || defined(DNETCONN))
+#if defined(WIN32) && defined(TCPCONN)
_XSERVTransWSAStartup();
#endif
if (!(hep = _XGethostbyname(namestr, hparams)))