3 Copyright 1993, 1994, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall
23 not be used in advertising or otherwise to promote the sale, use or
24 other dealings in this Software without prior written authorization
27 * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
31 * Permission to use, copy, modify, and distribute this software and its
32 * documentation for any purpose and without fee is hereby granted, provided
33 * that the above copyright notice appear in all copies and that both that
34 * copyright notice and this permission notice appear in supporting
35 * documentation, and that the name NCR not be used in advertising
36 * or publicity pertaining to distribution of the software without specific,
37 * written prior permission. NCR makes no representations about the
38 * suitability of this software for any purpose. It is provided "as is"
39 * without express or implied warranty.
41 * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
42 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
43 * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
44 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
45 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
46 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
47 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
54 * XTRANSDEBUG will enable the PRMSG() macros used in the X Transport
55 * Interface code. Each use of the PRMSG macro has a level associated with
56 * it. XTRANSDEBUG is defined to be a level. If the invocation level is =<
57 * the value of XTRANSDEBUG, then the message will be printed out to stderr.
58 * Recommended levels are:
60 * XTRANSDEBUG=1 Error messages
61 * XTRANSDEBUG=2 API Function Tracing
62 * XTRANSDEBUG=3 All Function Tracing
63 * XTRANSDEBUG=4 printing of intermediate values
64 * XTRANSDEBUG=5 really detailed stuff
67 * Defining XTRANSDEBUGTIMESTAMP will cause printing timestamps with each
71 #if !defined(XTRANSDEBUG) && defined(XTRANS_TRANSPORT_C)
72 # define XTRANSDEBUG 1
76 # define _WILLWINSOCK_
81 #ifndef _X_UNUSED /* Defined in Xfuncproto.h in xproto >= 7.0.22 */
82 # define _X_UNUSED /* */
87 #endif /* XTRANSDEBUG */
92 # include <sys/socket.h>
93 # include <netinet/in.h>
94 # include <arpa/inet.h>
97 * Moved the setting of NEED_UTSNAME to this header file from Xtrans.c,
98 * to avoid a race condition. JKJ (6/5/97)
101 # if defined(_POSIX_SOURCE) || defined(USG) || defined(SVR4) || defined(__SVR4) || defined(__SCO__)
102 # ifndef NEED_UTSNAME
103 # define NEED_UTSNAME
105 # include <sys/utsname.h>
108 # define ESET(val) errno = val
109 # define EGET() errno
113 # include <limits.h> /* for USHRT_MAX */
115 # define ESET(val) WSASetLastError(val)
116 # define EGET() WSAGetLastError()
123 #define X_TCP_PORT 6000
126 struct _XtransConnInfo {
127 struct _Xtransport *transptr;
140 #define XTRANS_OPEN_COTS_CLIENT 1
141 #define XTRANS_OPEN_COTS_SERVER 2
142 #define XTRANS_OPEN_CLTS_CLIENT 3
143 #define XTRANS_OPEN_CLTS_SERVER 4
146 typedef struct _Xtransport {
147 const char *TransName;
152 XtransConnInfo (*OpenCOTSClient)(
153 struct _Xtransport *, /* transport */
154 char *, /* protocol */
159 #endif /* TRANS_CLIENT */
162 const char ** nolisten;
163 XtransConnInfo (*OpenCOTSServer)(
164 struct _Xtransport *, /* transport */
165 char *, /* protocol */
170 #endif /* TRANS_SERVER */
174 XtransConnInfo (*OpenCLTSClient)(
175 struct _Xtransport *, /* transport */
176 char *, /* protocol */
181 #endif /* TRANS_CLIENT */
185 XtransConnInfo (*OpenCLTSServer)(
186 struct _Xtransport *, /* transport */
187 char *, /* protocol */
192 #endif /* TRANS_SERVER */
197 XtransConnInfo (*ReopenCOTSServer)(
198 struct _Xtransport *, /* transport */
203 XtransConnInfo (*ReopenCLTSServer)(
204 struct _Xtransport *, /* transport */
209 #endif /* TRANS_REOPEN */
213 XtransConnInfo, /* connection */
220 # define ADDR_IN_USE_ALLOWED 1
222 int (*CreateListener)(
223 XtransConnInfo, /* connection */
225 unsigned int /* flags */
228 int (*ResetListener)(
229 XtransConnInfo /* connection */
232 XtransConnInfo (*Accept)(
233 XtransConnInfo, /* connection */
237 #endif /* TRANS_SERVER */
242 XtransConnInfo, /* connection */
247 #endif /* TRANS_CLIENT */
249 int (*BytesReadable)(
250 XtransConnInfo, /* connection */
251 BytesReadable_t * /* pend */
255 XtransConnInfo, /* connection */
261 XtransConnInfo, /* connection */
267 XtransConnInfo, /* connection */
268 struct iovec *, /* buf */
273 XtransConnInfo, /* connection */
274 struct iovec *, /* buf */
279 XtransConnInfo /* connection */
283 XtransConnInfo /* connection */
286 int (*CloseForCloning)(
287 XtransConnInfo /* connection */
293 typedef struct _Xtransport_table {
294 Xtransport *transport;
300 * Flags for the flags member of Xtransport.
303 #define TRANS_ALIAS (1<<0) /* record is an alias, don't create server */
304 #define TRANS_LOCAL (1<<1) /* local transport */
305 #define TRANS_DISABLED (1<<2) /* Don't open this one */
306 #define TRANS_NOLISTEN (1<<3) /* Don't listen on this one */
307 #define TRANS_NOUNLINK (1<<4) /* Don't unlink transport endpoints */
308 #define TRANS_ABSTRACT (1<<5) /* Use abstract sockets if available */
309 #define TRANS_NOXAUTH (1<<6) /* Don't verify authentication (because it's secure some other way at the OS layer) */
311 /* Flags to preserve when setting others */
312 #define TRANS_KEEPFLAGS (TRANS_NOUNLINK|TRANS_ABSTRACT)
314 #ifdef XTRANS_TRANSPORT_C /* only provide static function prototypes when
315 building the transport.c file that has them in */
318 /* Not all clients make use of all provided statics */
319 #pragma clang diagnostic push
320 #pragma clang diagnostic ignored "-Wunused-function"
324 * readv() and writev() don't exist or don't work correctly on some
325 * systems, so they may be emulated.
328 #if defined(SYSV) && defined(__i386__) && !defined(__SCO__) && !defined(sun) || defined(WIN32)
330 #define READV(ciptr, iov, iovcnt) TRANS(ReadV)(ciptr, iov, iovcnt)
332 static int TRANS(ReadV)(
333 XtransConnInfo, /* ciptr */
334 struct iovec *, /* iov */
340 #define READV(ciptr, iov, iovcnt) readv(ciptr->fd, iov, iovcnt)
342 #endif /* CRAY || (SYSV && __i386__) || WIN32 || __sxg__ || */
345 #if defined(SYSV) && defined(__i386__) && !defined(__SCO__) && !defined(sun) || defined(WIN32)
347 #define WRITEV(ciptr, iov, iovcnt) TRANS(WriteV)(ciptr, iov, iovcnt)
349 static int TRANS(WriteV)(
350 XtransConnInfo, /* ciptr */
351 struct iovec *, /* iov */
357 #define WRITEV(ciptr, iov, iovcnt) writev(ciptr->fd, iov, iovcnt)
359 #endif /* CRAY || WIN32 || __sxg__ */
362 static int is_numeric (
363 const char * /* str */
367 static int trans_mkdir (
368 const char *, /* path */
374 #pragma clang diagnostic pop
378 * Some XTRANSDEBUG stuff
385 * The X server provides ErrorF() & VErrorF(), for other software that uses
386 * xtrans, we provide our own simple versions.
388 # if defined(XSERV_t) && defined(TRANS_SERVER)
391 static inline void _X_ATTRIBUTE_PRINTF(1, 0)
392 VErrorF(const char *f, va_list args)
394 vfprintf(stderr, f, args);
398 static inline void _X_ATTRIBUTE_PRINTF(1, 2)
399 ErrorF(const char *f, ...)
407 # endif /* xserver */
408 #endif /* XTRANSDEBUG */
410 static inline void _X_ATTRIBUTE_PRINTF(2, 3)
411 prmsg(int lvl, const char *f, ...)
417 if (lvl <= XTRANSDEBUG) {
418 int saveerrno = errno;
420 ErrorF("%s", __xtransname);
423 # ifdef XTRANSDEBUGTIMESTAMP
426 gettimeofday(&tp, 0);
427 ErrorF("timestamp (ms): %d\n",
428 tp.tv_sec * 1000 + tp.tv_usec / 1000);
434 #endif /* XTRANSDEBUG */
437 #endif /* XTRANS_TRANSPORT_C */
439 #endif /* _XTRANSINT_H_ */