Xtrans.h revision fe567363
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 char * /* address */ 240); 241 242#endif /* TRANS_CLIENT */ 243 244#ifdef TRANS_SERVER 245 246XtransConnInfo TRANS(OpenCOTSServer)( 247 char * /* address */ 248); 249 250#endif /* TRANS_SERVER */ 251 252#ifdef TRANS_CLIENT 253 254XtransConnInfo TRANS(OpenCLTSClient)( 255 char * /* address */ 256); 257 258#endif /* TRANS_CLIENT */ 259 260#ifdef TRANS_SERVER 261 262XtransConnInfo TRANS(OpenCLTSServer)( 263 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 char * /* port */ 274); 275 276XtransConnInfo TRANS(ReopenCLTSServer)( 277 int, /* trans_id */ 278 int, /* fd */ 279 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 char *, /* port */ 303 unsigned int /* flags */ 304); 305 306int TRANS(NoListen) ( 307 const char* /* protocol*/ 308); 309 310int TRANS(ResetListener)( 311 XtransConnInfo /* ciptr */ 312); 313 314XtransConnInfo TRANS(Accept)( 315 XtransConnInfo, /* ciptr */ 316 int * /* status */ 317); 318 319#endif /* TRANS_SERVER */ 320 321#ifdef TRANS_CLIENT 322 323int TRANS(Connect)( 324 XtransConnInfo, /* ciptr */ 325 char * /* address */ 326); 327 328#endif /* TRANS_CLIENT */ 329 330int TRANS(BytesReadable)( 331 XtransConnInfo, /* ciptr */ 332 BytesReadable_t * /* pend */ 333); 334 335int TRANS(Read)( 336 XtransConnInfo, /* ciptr */ 337 char *, /* buf */ 338 int /* size */ 339); 340 341int TRANS(Write)( 342 XtransConnInfo, /* ciptr */ 343 char *, /* buf */ 344 int /* size */ 345); 346 347int TRANS(Readv)( 348 XtransConnInfo, /* ciptr */ 349 struct iovec *, /* buf */ 350 int /* size */ 351); 352 353int TRANS(Writev)( 354 XtransConnInfo, /* ciptr */ 355 struct iovec *, /* buf */ 356 int /* size */ 357); 358 359int TRANS(Disconnect)( 360 XtransConnInfo /* ciptr */ 361); 362 363int TRANS(Close)( 364 XtransConnInfo /* ciptr */ 365); 366 367int TRANS(CloseForCloning)( 368 XtransConnInfo /* ciptr */ 369); 370 371int TRANS(IsLocal)( 372 XtransConnInfo /* ciptr */ 373); 374 375int TRANS(GetMyAddr)( 376 XtransConnInfo, /* ciptr */ 377 int *, /* familyp */ 378 int *, /* addrlenp */ 379 Xtransaddr ** /* addrp */ 380); 381 382int TRANS(GetPeerAddr)( 383 XtransConnInfo, /* ciptr */ 384 int *, /* familyp */ 385 int *, /* addrlenp */ 386 Xtransaddr ** /* addrp */ 387); 388 389int TRANS(GetConnectionNumber)( 390 XtransConnInfo /* ciptr */ 391); 392 393#ifdef TRANS_SERVER 394 395int TRANS(MakeAllCOTSServerListeners)( 396 char *, /* port */ 397 int *, /* partial */ 398 int *, /* count_ret */ 399 XtransConnInfo ** /* ciptrs_ret */ 400); 401 402int TRANS(MakeAllCLTSServerListeners)( 403 char *, /* port */ 404 int *, /* partial */ 405 int *, /* count_ret */ 406 XtransConnInfo ** /* ciptrs_ret */ 407); 408 409#endif /* TRANS_SERVER */ 410 411 412/* 413 * Function Prototypes for Utility Functions. 414 */ 415 416#ifdef X11_t 417 418int TRANS(ConvertAddress)( 419 int *, /* familyp */ 420 int *, /* addrlenp */ 421 Xtransaddr ** /* addrp */ 422); 423 424#endif /* X11_t */ 425 426#ifdef ICE_t 427 428char * 429TRANS(GetMyNetworkId)( 430 XtransConnInfo /* ciptr */ 431); 432 433char * 434TRANS(GetPeerNetworkId)( 435 XtransConnInfo /* ciptr */ 436); 437 438#endif /* ICE_t */ 439 440int 441TRANS(GetHostname) ( 442 char * /* buf */, 443 int /* maxlen */ 444); 445 446#if defined(WIN32) && defined(TCPCONN) 447int TRANS(WSAStartup)(); 448#endif 449 450#endif /* _XTRANS_H_ */ 451