aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/lib/xtrans/Xtranssock.c
diff options
context:
space:
mode:
Diffstat (limited to 'nx-X11/lib/xtrans/Xtranssock.c')
-rw-r--r--nx-X11/lib/xtrans/Xtranssock.c119
1 files changed, 60 insertions, 59 deletions
diff --git a/nx-X11/lib/xtrans/Xtranssock.c b/nx-X11/lib/xtrans/Xtranssock.c
index cdc421a1e..f87b40a87 100644
--- a/nx-X11/lib/xtrans/Xtranssock.c
+++ b/nx-X11/lib/xtrans/Xtranssock.c
@@ -115,7 +115,7 @@ from the copyright holders.
#if defined(MOTOROLA) && defined(SYSV)
#define NO_TCP_H
-#endif
+#endif
#ifndef NO_TCP_H
#if defined(__osf__) || defined(linux) || defined(__GLIBC__) || defined(AIXV5)
@@ -135,11 +135,11 @@ from the copyright holders.
#if (defined(i386) && defined(SYSV)) && !defined(SCO325) && !defined(sun)
#include <net/errno.h>
-#endif
+#endif
#if (defined(i386) && defined(SYSV)) && (!defined(ISC) || !defined(I_NREAD) || defined(SCO325)) || defined(_SEQUENT_)
#include <sys/stropts.h>
-#endif
+#endif
#include <unistd.h>
@@ -183,6 +183,7 @@ from the copyright holders.
#ifndef BACKLOG
#define BACKLOG MIN_BACKLOG
#endif
+
/*
* This is the Socket implementation of the X Transport service layer
*
@@ -191,7 +192,7 @@ from the copyright holders.
*
*/
-typedef struct _Sockettrans2dev {
+typedef struct _Sockettrans2dev {
char *transname;
int family;
int devcotsname;
@@ -382,7 +383,7 @@ static char *_NXGetUnixDir(char *dir)
_NXGetUnixDirError:
strcpy(_NXUnixDir, dir);
-
+
#ifdef NX_TRANS_TEST
fprintf(stderr, "_NXGetUnixDir: Returning default X11 Unix directory [%s].\n", _NXUnixDir);
#endif
@@ -486,7 +487,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
@@ -1100,6 +1101,7 @@ TRANS(SocketOpenCOTSClientBase) (char *transname, char *protocol,
if ((ciptr = TRANS(SocketOpen) (
i, Sockettrans2devtab[i].devcotsname)) != NULL)
break;
+ }
}
if (i < 0) {
if (i == -1)
@@ -1125,7 +1127,7 @@ TRANS(SocketOpenCOTSClientBase) (char *transname, char *protocol,
}
static XtransConnInfo
-TRANS(SocketOpenCOTSClient) (Xtransport *thistrans, char *protocol,
+TRANS(SocketOpenCOTSClient) (Xtransport *thistrans, char *protocol,
char *host, char *port)
{
return TRANS(SocketOpenCOTSClientBase)(
@@ -1139,7 +1141,7 @@ TRANS(SocketOpenCOTSClient) (Xtransport *thistrans, char *protocol,
#ifdef TRANS_SERVER
static XtransConnInfo
-TRANS(SocketOpenCOTSServer) (Xtransport *thistrans, char *protocol,
+TRANS(SocketOpenCOTSServer) (Xtransport *thistrans, char *protocol,
char *host, char *port)
{
@@ -1206,7 +1208,7 @@ TRANS(SocketOpenCOTSServer) (Xtransport *thistrans, char *protocol,
#ifdef TRANS_CLIENT
static XtransConnInfo
-TRANS(SocketOpenCLTSClient) (Xtransport *thistrans, char *protocol,
+TRANS(SocketOpenCLTSClient) (Xtransport *thistrans, char *protocol,
char *host, char *port)
{
@@ -1274,7 +1276,7 @@ TRANS(SocketOpenCLTSClient) (Xtransport *thistrans, char *protocol,
#ifdef TRANS_SERVER
static XtransConnInfo
-TRANS(SocketOpenCLTSServer) (Xtransport *thistrans, char *protocol,
+TRANS(SocketOpenCLTSServer) (Xtransport *thistrans, char *protocol,
char *host, char *port)
{
@@ -1435,7 +1437,7 @@ 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)
@@ -1468,7 +1470,7 @@ TRANS(SocketCreateListener) (XtransConnInfo ciptr,
else
return TRANS_ADDR_IN_USE;
}
-
+
if (retry-- == 0) {
PRMSG (1, "SocketCreateListener: failed to bind listener\n",
0, 0, 0);
@@ -1506,7 +1508,7 @@ TRANS(SocketCreateListener) (XtransConnInfo ciptr,
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);
@@ -1541,7 +1543,7 @@ TRANS(SocketINETCreateListener) (XtransConnInfo ciptr, char *port, unsigned int
#ifdef X11_t
char portbuf[PORTBUFSIZE];
#endif
-
+
PRMSG (2, "SocketINETCreateListener(%s)\n", port, 0, 0);
#ifdef X11_t
@@ -1582,11 +1584,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;
@@ -1776,6 +1778,7 @@ TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port,
return 0;
}
+
static int
TRANS(SocketUNIXResetListener) (XtransConnInfo ciptr)
@@ -1907,7 +1910,7 @@ 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.
*/
@@ -1990,7 +1993,6 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status)
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.
@@ -2010,7 +2012,7 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status)
*status = TRANS_ACCEPT_BAD_MALLOC;
return NULL;
}
-
+
newciptr->peeraddrlen = ciptr->addrlen;
memcpy (newciptr->peeraddr, ciptr->addr, newciptr->addrlen);
@@ -2033,7 +2035,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];
};
@@ -2135,7 +2137,7 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
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);
@@ -2145,7 +2147,7 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
resetonce = 1;
addrlist->addr = addrlist->firstaddr;
}
- }
+ }
socketaddr = addrlist->addr->ai_addr;
socketaddrlen = addrlist->addr->ai_addrlen;
@@ -2155,10 +2157,10 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
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)), 0, 0);
PRMSG (4,"SocketINETConnect() sockname.sin_port = %d\n",
- ntohs(sin->sin_port), 0, 0);
+ ntohs(sin->sin_port), 0, 0);
if (Sockettrans2devtab[ciptr->index].family == AF_INET6) {
if (strcmp(Sockettrans2devtab[ciptr->index].transname,
@@ -2193,13 +2195,13 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
}
} else if (addrlist->addr->ai_family == AF_INET6) {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) socketaddr;
-
+
PRMSG (4,"SocketINETConnect() sockname.sin6_addr = %s\n",
inet_ntop(addrlist->addr->ai_family,
&sin6->sin6_addr,ntopbuf,sizeof(ntopbuf)),
- 0, 0);
+ 0, 0);
PRMSG (4,"SocketINETConnect() sockname.sin6_port = %d\n",
- ntohs(sin6->sin6_port), 0, 0);
+ ntohs(sin6->sin6_port), 0, 0);
if (Sockettrans2devtab[ciptr->index].family == AF_INET) {
if (strcmp(Sockettrans2devtab[ciptr->index].transname,
@@ -2237,7 +2239,7 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
if (socketaddr == NULL) {
addrlist->addr = addrlist->addr->ai_next;
}
- }
+ }
} else
#endif
{
@@ -2280,8 +2282,10 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
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;
}
@@ -2356,12 +2360,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) ||
+ || (haveIPv6 && ((addrlist->addr->ai_next != NULL) ||
(addrlist->addr != addrlist->firstaddr)) &&
(olderrno == ENETUNREACH || olderrno == EAFNOSUPPORT ||
olderrno == EADDRNOTAVAIL || olderrno == ETIMEDOUT
@@ -2379,16 +2383,16 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
PRMSG (2,"SocketINETConnect: Can't connect: errno = %d\n",
olderrno,0, 0);
- 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,
@@ -2407,7 +2411,7 @@ TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port)
}
#if defined(IPv6) && defined(AF_INET6)
- if (haveIPv6 && res != 0) {
+ if (haveIPv6 && res != 0) {
addrlist->addr = addrlist->addr->ai_next;
}
#endif
@@ -2461,7 +2465,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;
@@ -2472,9 +2476,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;
@@ -2486,7 +2490,7 @@ UnixHostReallyLocal (char *host)
}
}
}
-
+
freeaddrinfo(localhostaddr);
freeaddrinfo(otherhostaddr);
return equiv;
@@ -2519,13 +2523,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++;
}
@@ -2541,17 +2545,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;
}
@@ -2578,10 +2582,8 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
abstract = ciptr->transptr->flags & TRANS_ABSTRACT;
#endif
-
-
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
@@ -2618,7 +2620,7 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
/*
* Build the socket name.
*/
-
+
sockname.sun_family = AF_UNIX;
#ifdef NX_TRANS_SOCKET
@@ -2669,11 +2671,11 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
{
int olderrno = errno;
int connected = 0;
-
+
if (!connected)
{
errno = olderrno;
-
+
/*
* If the error was ENOENT, the server may be starting up
* and we should try again.
@@ -2733,7 +2735,7 @@ SocketUNIXConnectPost:
ciptr->peeraddrlen = namelen;
memcpy (ciptr->addr, &sockname, ciptr->addrlen);
memcpy (ciptr->peeraddr, &sockname, ciptr->peeraddrlen);
-
+
return 0;
}
@@ -2779,7 +2781,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
@@ -3002,7 +3004,7 @@ TRANS(SocketDisconnect) (XtransConnInfo ciptr)
PRMSG (2,"SocketDisconnect(%p,%d)\n", ciptr, ciptr->fd, 0);
#ifdef WIN32
- {
+ {
int ret = shutdown (ciptr->fd, 2);
errno = WSAGetLastError();
return ret;
@@ -3037,7 +3039,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,
@@ -3302,7 +3303,7 @@ Xtransport TRANS(SocketLocalFuncs) = {
static char* unix_nolisten[] = { "local" , NULL };
# endif
# endif
-
+
Xtransport TRANS(SocketUNIXFuncs) = {
/* Socket Interface */
"unix",