Xtrans.h revision 75ebec6d
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(Received) ( 307 const char* /* protocol*/ 308); 309 310int TRANS(NoListen) ( 311 const char* /* protocol*/ 312); 313 314int TRANS(IsListening) ( 315 const char* /* protocol*/ 316); 317 318int TRANS(ResetListener)( 319 XtransConnInfo /* ciptr */ 320); 321 322XtransConnInfo TRANS(Accept)( 323 XtransConnInfo, /* ciptr */ 324 int * /* status */ 325); 326 327#endif /* TRANS_SERVER */ 328 329#ifdef TRANS_CLIENT 330 331int TRANS(Connect)( 332 XtransConnInfo, /* ciptr */ 333 char * /* address */ 334); 335 336#endif /* TRANS_CLIENT */ 337 338int TRANS(BytesReadable)( 339 XtransConnInfo, /* ciptr */ 340 BytesReadable_t * /* pend */ 341); 342 343int TRANS(Read)( 344 XtransConnInfo, /* ciptr */ 345 char *, /* buf */ 346 int /* size */ 347); 348 349int TRANS(Write)( 350 XtransConnInfo, /* ciptr */ 351 char *, /* buf */ 352 int /* size */ 353); 354 355int TRANS(Readv)( 356 XtransConnInfo, /* ciptr */ 357 struct iovec *, /* buf */ 358 int /* size */ 359); 360 361int TRANS(Writev)( 362 XtransConnInfo, /* ciptr */ 363 struct iovec *, /* buf */ 364 int /* size */ 365); 366 367int TRANS(SendFd) (XtransConnInfo ciptr, int fd, int do_close); 368 369int TRANS(RecvFd) (XtransConnInfo ciptr); 370 371int TRANS(Disconnect)( 372 XtransConnInfo /* ciptr */ 373); 374 375int TRANS(Close)( 376 XtransConnInfo /* ciptr */ 377); 378 379int TRANS(CloseForCloning)( 380 XtransConnInfo /* ciptr */ 381); 382 383int TRANS(IsLocal)( 384 XtransConnInfo /* ciptr */ 385); 386 387int TRANS(GetMyAddr)( 388 XtransConnInfo, /* ciptr */ 389 int *, /* familyp */ 390 int *, /* addrlenp */ 391 Xtransaddr ** /* addrp */ 392); 393 394int TRANS(GetPeerAddr)( 395 XtransConnInfo, /* ciptr */ 396 int *, /* familyp */ 397 int *, /* addrlenp */ 398 Xtransaddr ** /* addrp */ 399); 400 401int TRANS(GetConnectionNumber)( 402 XtransConnInfo /* ciptr */ 403); 404 405#ifdef TRANS_SERVER 406 407int TRANS(MakeAllCOTSServerListeners)( 408 char *, /* port */ 409 int *, /* partial */ 410 int *, /* count_ret */ 411 XtransConnInfo ** /* ciptrs_ret */ 412); 413 414int TRANS(MakeAllCLTSServerListeners)( 415 char *, /* port */ 416 int *, /* partial */ 417 int *, /* count_ret */ 418 XtransConnInfo ** /* ciptrs_ret */ 419); 420 421#endif /* TRANS_SERVER */ 422 423 424/* 425 * Function Prototypes for Utility Functions. 426 */ 427 428#ifdef X11_t 429 430int TRANS(ConvertAddress)( 431 int *, /* familyp */ 432 int *, /* addrlenp */ 433 Xtransaddr ** /* addrp */ 434); 435 436#endif /* X11_t */ 437 438#ifdef ICE_t 439 440char * 441TRANS(GetMyNetworkId)( 442 XtransConnInfo /* ciptr */ 443); 444 445char * 446TRANS(GetPeerNetworkId)( 447 XtransConnInfo /* ciptr */ 448); 449 450#endif /* ICE_t */ 451 452int 453TRANS(GetHostname) ( 454 char * /* buf */, 455 int /* maxlen */ 456); 457 458#if defined(WIN32) && defined(TCPCONN) 459int TRANS(WSAStartup)(); 460#endif 461 462#endif /* _XTRANS_H_ */ 463