Xtrans.h revision 6a3641a6
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 56#ifndef WIN32 57#include <sys/socket.h> 58#endif 59 60#ifdef __clang__ 61/* Not all clients make use of all provided statics */ 62#pragma clang diagnostic push 63#pragma clang diagnostic ignored "-Wunused-function" 64#endif 65 66/* 67 * Set the functions names according to where this code is being compiled. 68 */ 69 70#ifdef X11_t 71#define TRANS(func) _X11Trans##func 72#ifdef XTRANSDEBUG 73static const char *__xtransname = "_X11Trans"; 74#endif 75#endif /* X11_t */ 76 77#ifdef XSERV_t 78#define TRANS(func) _XSERVTrans##func 79#ifdef XTRANSDEBUG 80static const char *__xtransname = "_XSERVTrans"; 81#endif 82#define X11_t 83#endif /* XSERV_t */ 84 85#ifdef XIM_t 86#define TRANS(func) _XimXTrans##func 87#ifdef XTRANSDEBUG 88static const char *__xtransname = "_XimTrans"; 89#endif 90#endif /* XIM_t */ 91 92#ifdef FS_t 93#define TRANS(func) _FSTrans##func 94#ifdef XTRANSDEBUG 95static const char *__xtransname = "_FSTrans"; 96#endif 97#endif /* FS_t */ 98 99#ifdef FONT_t 100#define TRANS(func) _FontTrans##func 101#ifdef XTRANSDEBUG 102static const char *__xtransname = "_FontTrans"; 103#endif 104#endif /* FONT_t */ 105 106#ifdef ICE_t 107#define TRANS(func) _IceTrans##func 108#ifdef XTRANSDEBUG 109static const char *__xtransname = "_IceTrans"; 110#endif 111#endif /* ICE_t */ 112 113#ifdef TEST_t 114#define TRANS(func) _TESTTrans##func 115#ifdef XTRANSDEBUG 116static const char *__xtransname = "_TESTTrans"; 117#endif 118#endif /* TEST_t */ 119 120#ifdef LBXPROXY_t 121#define TRANS(func) _LBXPROXYTrans##func 122#define X11_t /* The server defines this - so should the LBX proxy */ 123#ifdef XTRANSDEBUG 124static const char *__xtransname = "_LBXPROXYTrans"; 125#endif 126#endif /* LBXPROXY_t */ 127 128#if !defined(TRANS) 129#define TRANS(func) _XTrans##func 130#ifdef XTRANSDEBUG 131static const char *__xtransname = "_XTrans"; 132#endif 133#endif /* !TRANS */ 134 135#ifdef __clang__ 136#pragma clang diagnostic pop 137#endif 138 139/* 140 * Create a single address structure that can be used wherever 141 * an address structure is needed. struct sockaddr is not big enough 142 * to hold a sockadd_un, so we create this definition to have a single 143 * structure that is big enough for all the structures we might need. 144 * 145 * This structure needs to be independent of the socket/TLI interface used. 146 */ 147 148#if defined(IPv6) && defined(AF_INET6) 149typedef struct sockaddr_storage Xtransaddr; 150#else 151#define XTRANS_MAX_ADDR_LEN 128 /* large enough to hold sun_path */ 152 153typedef struct { 154 unsigned char addr[XTRANS_MAX_ADDR_LEN]; 155} Xtransaddr; 156#endif 157 158#ifdef LONG64 159typedef int BytesReadable_t; 160#else 161typedef long BytesReadable_t; 162#endif 163 164 165#if defined(WIN32) || defined(USG) 166 167/* 168 * TRANS(Readv) and TRANS(Writev) use struct iovec, normally found 169 * in Berkeley systems in <sys/uio.h>. See the readv(2) and writev(2) 170 * manual pages for details. 171 */ 172 173struct iovec { 174 caddr_t iov_base; 175 int iov_len; 176}; 177 178#else 179#include <sys/uio.h> 180#endif 181 182typedef struct _XtransConnInfo *XtransConnInfo; 183 184 185/* 186 * Transport Option definitions 187 */ 188 189#define TRANS_NONBLOCKING 1 190#define TRANS_CLOSEONEXEC 2 191 192 193/* 194 * Return values of Connect (0 is success) 195 */ 196 197#define TRANS_CONNECT_FAILED -1 198#define TRANS_TRY_CONNECT_AGAIN -2 199#define TRANS_IN_PROGRESS -3 200 201 202/* 203 * Return values of CreateListener (0 is success) 204 */ 205 206#define TRANS_CREATE_LISTENER_FAILED -1 207#define TRANS_ADDR_IN_USE -2 208 209 210/* 211 * Return values of Accept (0 is success) 212 */ 213 214#define TRANS_ACCEPT_BAD_MALLOC -1 215#define TRANS_ACCEPT_FAILED -2 216#define TRANS_ACCEPT_MISC_ERROR -3 217 218 219/* 220 * ResetListener return values 221 */ 222 223#define TRANS_RESET_NOOP 1 224#define TRANS_RESET_NEW_FD 2 225#define TRANS_RESET_FAILURE 3 226 227 228/* 229 * Function prototypes for the exposed interface 230 */ 231 232void TRANS(FreeConnInfo) ( 233 XtransConnInfo /* ciptr */ 234); 235 236#ifdef TRANS_CLIENT 237 238XtransConnInfo TRANS(OpenCOTSClient)( 239 const char * /* address */ 240); 241 242#endif /* TRANS_CLIENT */ 243 244#ifdef TRANS_SERVER 245 246XtransConnInfo TRANS(OpenCOTSServer)( 247 const char * /* address */ 248); 249 250#endif /* TRANS_SERVER */ 251 252#ifdef TRANS_CLIENT 253 254XtransConnInfo TRANS(OpenCLTSClient)( 255 const char * /* address */ 256); 257 258#endif /* TRANS_CLIENT */ 259 260#ifdef TRANS_SERVER 261 262XtransConnInfo TRANS(OpenCLTSServer)( 263 const char * /* address */ 264); 265 266#endif /* TRANS_SERVER */ 267 268#ifdef TRANS_REOPEN 269 270XtransConnInfo TRANS(ReopenCOTSServer)( 271 int, /* trans_id */ 272 int, /* fd */ 273 const char * /* port */ 274); 275 276XtransConnInfo TRANS(ReopenCLTSServer)( 277 int, /* trans_id */ 278 int, /* fd */ 279 const char * /* port */ 280); 281 282int TRANS(GetReopenInfo)( 283 XtransConnInfo, /* ciptr */ 284 int *, /* trans_id */ 285 int *, /* fd */ 286 char ** /* port */ 287); 288 289#endif /* TRANS_REOPEN */ 290 291 292int TRANS(SetOption)( 293 XtransConnInfo, /* ciptr */ 294 int, /* option */ 295 int /* arg */ 296); 297 298#ifdef TRANS_SERVER 299 300int TRANS(CreateListener)( 301 XtransConnInfo, /* ciptr */ 302 const char *, /* port */ 303 unsigned int /* flags */ 304); 305 306int TRANS(Received) ( 307 const char* /* protocol*/ 308); 309 310int TRANS(NoListen) ( 311 const char* /* protocol*/ 312); 313 314int TRANS(Listen) ( 315 const char* /* protocol*/ 316); 317 318int TRANS(IsListening) ( 319 const char* /* protocol*/ 320); 321 322int TRANS(ResetListener)( 323 XtransConnInfo /* ciptr */ 324); 325 326XtransConnInfo TRANS(Accept)( 327 XtransConnInfo, /* ciptr */ 328 int * /* status */ 329); 330 331#endif /* TRANS_SERVER */ 332 333#ifdef TRANS_CLIENT 334 335int TRANS(Connect)( 336 XtransConnInfo, /* ciptr */ 337 const char * /* address */ 338); 339 340#endif /* TRANS_CLIENT */ 341 342int TRANS(BytesReadable)( 343 XtransConnInfo, /* ciptr */ 344 BytesReadable_t * /* pend */ 345); 346 347int TRANS(Read)( 348 XtransConnInfo, /* ciptr */ 349 char *, /* buf */ 350 int /* size */ 351); 352 353int TRANS(Write)( 354 XtransConnInfo, /* ciptr */ 355 char *, /* buf */ 356 int /* size */ 357); 358 359int TRANS(Readv)( 360 XtransConnInfo, /* ciptr */ 361 struct iovec *, /* buf */ 362 int /* size */ 363); 364 365int TRANS(Writev)( 366 XtransConnInfo, /* ciptr */ 367 struct iovec *, /* buf */ 368 int /* size */ 369); 370 371int TRANS(SendFd) (XtransConnInfo ciptr, int fd, int do_close); 372 373int TRANS(RecvFd) (XtransConnInfo ciptr); 374 375int TRANS(Disconnect)( 376 XtransConnInfo /* ciptr */ 377); 378 379int TRANS(Close)( 380 XtransConnInfo /* ciptr */ 381); 382 383int TRANS(CloseForCloning)( 384 XtransConnInfo /* ciptr */ 385); 386 387int TRANS(IsLocal)( 388 XtransConnInfo /* ciptr */ 389); 390 391int TRANS(GetMyAddr)( 392 XtransConnInfo, /* ciptr */ 393 int *, /* familyp */ 394 int *, /* addrlenp */ 395 Xtransaddr ** /* addrp */ 396); 397 398int TRANS(GetPeerAddr)( 399 XtransConnInfo, /* ciptr */ 400 int *, /* familyp */ 401 int *, /* addrlenp */ 402 Xtransaddr ** /* addrp */ 403); 404 405int TRANS(GetConnectionNumber)( 406 XtransConnInfo /* ciptr */ 407); 408 409#ifdef TRANS_SERVER 410 411int TRANS(MakeAllCOTSServerListeners)( 412 const char *, /* port */ 413 int *, /* partial */ 414 int *, /* count_ret */ 415 XtransConnInfo ** /* ciptrs_ret */ 416); 417 418int TRANS(MakeAllCLTSServerListeners)( 419 const char *, /* port */ 420 int *, /* partial */ 421 int *, /* count_ret */ 422 XtransConnInfo ** /* ciptrs_ret */ 423); 424 425#endif /* TRANS_SERVER */ 426 427 428/* 429 * Function Prototypes for Utility Functions. 430 */ 431 432#ifdef X11_t 433 434int TRANS(ConvertAddress)( 435 int *, /* familyp */ 436 int *, /* addrlenp */ 437 Xtransaddr ** /* addrp */ 438); 439 440#endif /* X11_t */ 441 442#ifdef ICE_t 443 444char * 445TRANS(GetMyNetworkId)( 446 XtransConnInfo /* ciptr */ 447); 448 449char * 450TRANS(GetPeerNetworkId)( 451 XtransConnInfo /* ciptr */ 452); 453 454#endif /* ICE_t */ 455 456int 457TRANS(GetHostname) ( 458 char * /* buf */, 459 int /* maxlen */ 460); 461 462#if defined(WIN32) && defined(TCPCONN) 463int TRANS(WSAStartup)(); 464#endif 465 466#endif /* _XTRANS_H_ */ 467