1/* 2 3Copyright 1993, 1994, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included 12in all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20OTHER DEALINGS IN THE SOFTWARE. 21 22Except as contained in this notice, the name of The Open Group shall 23not be used in advertising or otherwise to promote the sale, use or 24other dealings in this Software without prior written authorization 25from The Open Group. 26 27 * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA 28 * 29 * All Rights Reserved 30 * 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. 40 * 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. 48 */ 49 50#ifndef _XTRANS_H_ 51#define _XTRANS_H_ 52 53#include <X11/Xfuncproto.h> 54#include <X11/Xos.h> 55#include <X11/Xmd.h> 56 57#ifndef WIN32 58#include <sys/socket.h> 59#endif 60 61#ifdef __clang__ 62/* Not all clients make use of all provided statics */ 63#pragma clang diagnostic push 64#pragma clang diagnostic ignored "-Wunused-function" 65#endif 66 67/* 68 * Set the functions names according to where this code is being compiled. 69 */ 70 71#ifdef X11_t 72#define TRANS(func) _X11Trans##func 73#ifdef XTRANSDEBUG 74static const char *__xtransname = "_X11Trans"; 75#endif 76#endif /* X11_t */ 77 78#ifdef XSERV_t 79#define TRANS(func) _XSERVTrans##func 80#ifdef XTRANSDEBUG 81static const char *__xtransname = "_XSERVTrans"; 82#endif 83#define X11_t 84#endif /* XSERV_t */ 85 86#ifdef XIM_t 87#define TRANS(func) _XimXTrans##func 88#ifdef XTRANSDEBUG 89static const char *__xtransname = "_XimTrans"; 90#endif 91#endif /* XIM_t */ 92 93#ifdef FS_t 94#define TRANS(func) _FSTrans##func 95#ifdef XTRANSDEBUG 96static const char *__xtransname = "_FSTrans"; 97#endif 98#endif /* FS_t */ 99 100#ifdef FONT_t 101#define TRANS(func) _FontTrans##func 102#ifdef XTRANSDEBUG 103static const char *__xtransname = "_FontTrans"; 104#endif 105#endif /* FONT_t */ 106 107#ifdef ICE_t 108#define TRANS(func) _IceTrans##func 109#ifdef XTRANSDEBUG 110static const char *__xtransname = "_IceTrans"; 111#endif 112#endif /* ICE_t */ 113 114#if !defined(TRANS) 115#define TRANS(func) _XTrans##func 116#ifdef XTRANSDEBUG 117static const char *__xtransname = "_XTrans"; 118#endif 119#endif /* !TRANS */ 120 121#ifdef __clang__ 122#pragma clang diagnostic pop 123#endif 124 125/* 126 * Create a single address structure that can be used wherever 127 * an address structure is needed. struct sockaddr is not big enough 128 * to hold a sockadd_un, so we create this definition to have a single 129 * structure that is big enough for all the structures we might need. 130 * 131 * This structure needs to be independent of the socket/TLI interface used. 132 */ 133 134/* Temporary workaround for consumers whose configure scripts were 135 generated with pre-1.6 versions of xtrans.m4 */ 136#if defined(IPv6) && !defined(HAVE_STRUCT_SOCKADDR_STORAGE) 137#define HAVE_STRUCT_SOCKADDR_STORAGE 138#endif 139 140#ifdef HAVE_STRUCT_SOCKADDR_STORAGE 141typedef struct sockaddr_storage Xtransaddr; 142#else 143#define XTRANS_MAX_ADDR_LEN 128 /* large enough to hold sun_path */ 144 145typedef struct { 146 unsigned char addr[XTRANS_MAX_ADDR_LEN]; 147} Xtransaddr; 148#endif 149 150#ifdef LONG64 151typedef int BytesReadable_t; 152#else 153typedef long BytesReadable_t; 154#endif 155 156 157#if defined(WIN32) 158 159/* 160 * TRANS(Readv) and TRANS(Writev) use struct iovec, normally found 161 * in Berkeley systems in <sys/uio.h>. See the readv(2) and writev(2) 162 * manual pages for details. 163 */ 164 165struct iovec { 166 caddr_t iov_base; 167 int iov_len; 168}; 169 170#else 171#include <sys/uio.h> 172#endif 173 174typedef struct _XtransConnInfo *XtransConnInfo; 175 176 177/* 178 * Transport Option definitions 179 */ 180 181#define TRANS_NONBLOCKING 1 182#define TRANS_CLOSEONEXEC 2 183 184 185/* 186 * Return values of Connect (0 is success) 187 */ 188 189#define TRANS_CONNECT_FAILED -1 190#define TRANS_TRY_CONNECT_AGAIN -2 191#define TRANS_IN_PROGRESS -3 192 193 194/* 195 * Return values of CreateListener (0 is success) 196 */ 197 198#define TRANS_CREATE_LISTENER_FAILED -1 199#define TRANS_ADDR_IN_USE -2 200 201 202/* 203 * Return values of Accept (0 is success) 204 */ 205 206#define TRANS_ACCEPT_BAD_MALLOC -1 207#define TRANS_ACCEPT_FAILED -2 208#define TRANS_ACCEPT_MISC_ERROR -3 209 210 211/* 212 * ResetListener return values 213 */ 214 215#define TRANS_RESET_NOOP 1 216#define TRANS_RESET_NEW_FD 2 217#define TRANS_RESET_FAILURE 3 218 219 220/* 221 * Function prototypes for the exposed interface 222 */ 223 224void TRANS(FreeConnInfo) ( 225 XtransConnInfo /* ciptr */ 226); 227 228#ifdef TRANS_CLIENT 229 230XtransConnInfo TRANS(OpenCOTSClient)( 231 const char * /* address */ 232); 233 234#endif /* TRANS_CLIENT */ 235 236#ifdef TRANS_SERVER 237 238XtransConnInfo TRANS(OpenCOTSServer)( 239 const char * /* address */ 240); 241 242#endif /* TRANS_SERVER */ 243 244#ifdef TRANS_REOPEN 245 246XtransConnInfo TRANS(ReopenCOTSServer)( 247 int, /* trans_id */ 248 int, /* fd */ 249 const char * /* port */ 250); 251 252int TRANS(GetReopenInfo)( 253 XtransConnInfo, /* ciptr */ 254 int *, /* trans_id */ 255 int *, /* fd */ 256 char ** /* port */ 257); 258 259#endif /* TRANS_REOPEN */ 260 261 262int TRANS(SetOption)( 263 XtransConnInfo, /* ciptr */ 264 int, /* option */ 265 int /* arg */ 266); 267 268#ifdef TRANS_SERVER 269 270int TRANS(CreateListener)( 271 XtransConnInfo, /* ciptr */ 272 const char *, /* port */ 273 unsigned int /* flags */ 274); 275 276int TRANS(Received) ( 277 const char* /* protocol*/ 278); 279 280int TRANS(NoListen) ( 281 const char* /* protocol*/ 282); 283 284int TRANS(Listen) ( 285 const char* /* protocol*/ 286); 287 288int TRANS(IsListening) ( 289 const char* /* protocol*/ 290); 291 292int TRANS(ResetListener)( 293 XtransConnInfo /* ciptr */ 294); 295 296XtransConnInfo TRANS(Accept)( 297 XtransConnInfo, /* ciptr */ 298 int * /* status */ 299); 300 301#endif /* TRANS_SERVER */ 302 303#ifdef TRANS_CLIENT 304 305int TRANS(Connect)( 306 XtransConnInfo, /* ciptr */ 307 const char * /* address */ 308); 309 310#endif /* TRANS_CLIENT */ 311 312int TRANS(BytesReadable)( 313 XtransConnInfo, /* ciptr */ 314 BytesReadable_t * /* pend */ 315); 316 317int TRANS(Read)( 318 XtransConnInfo, /* ciptr */ 319 char *, /* buf */ 320 int /* size */ 321); 322 323int TRANS(Write)( 324 XtransConnInfo, /* ciptr */ 325 const char *, /* buf */ 326 int /* size */ 327); 328 329int TRANS(Readv)( 330 XtransConnInfo, /* ciptr */ 331 struct iovec *, /* buf */ 332 int /* size */ 333); 334 335int TRANS(Writev)( 336 XtransConnInfo, /* ciptr */ 337 struct iovec *, /* buf */ 338 int /* size */ 339); 340 341int TRANS(SendFd) (XtransConnInfo ciptr, int fd, int do_close); 342 343int TRANS(RecvFd) (XtransConnInfo ciptr); 344 345int TRANS(Disconnect)( 346 XtransConnInfo /* ciptr */ 347); 348 349int TRANS(Close)( 350 XtransConnInfo /* ciptr */ 351); 352 353int TRANS(CloseForCloning)( 354 XtransConnInfo /* ciptr */ 355); 356 357int TRANS(IsLocal)( 358 XtransConnInfo /* ciptr */ 359); 360 361int TRANS(GetPeerAddr)( 362 XtransConnInfo, /* ciptr */ 363 int *, /* familyp */ 364 int *, /* addrlenp */ 365 Xtransaddr ** /* addrp */ 366); 367 368int TRANS(GetConnectionNumber)( 369 XtransConnInfo /* ciptr */ 370); 371 372#ifdef TRANS_SERVER 373 374int TRANS(MakeAllCOTSServerListeners)( 375 const char *, /* port */ 376 int *, /* partial */ 377 int *, /* count_ret */ 378 XtransConnInfo ** /* ciptrs_ret */ 379); 380 381#endif /* TRANS_SERVER */ 382 383 384/* 385 * Function Prototypes for Utility Functions. 386 */ 387 388#ifdef X11_t 389 390int TRANS(ConvertAddress)( 391 int *, /* familyp */ 392 int *, /* addrlenp */ 393 Xtransaddr ** /* addrp */ 394); 395 396#endif /* X11_t */ 397 398#ifdef ICE_t 399 400char * 401TRANS(GetMyNetworkId)( 402 XtransConnInfo /* ciptr */ 403); 404 405char * 406TRANS(GetPeerNetworkId)( 407 XtransConnInfo /* ciptr */ 408); 409 410#endif /* ICE_t */ 411 412int 413TRANS(GetHostname) ( 414 char * /* buf */, 415 int /* maxlen */ 416); 417 418#if defined(WIN32) && defined(TCPCONN) 419int TRANS(WSAStartup)(); 420#endif 421 422#endif /* _XTRANS_H_ */ 423