Xtrans.h revision 3d2ed3e3
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#if defined(IPv6) && defined(AF_INET6) 135typedef struct sockaddr_storage Xtransaddr; 136#else 137#define XTRANS_MAX_ADDR_LEN 128 /* large enough to hold sun_path */ 138 139typedef struct { 140 unsigned char addr[XTRANS_MAX_ADDR_LEN]; 141} Xtransaddr; 142#endif 143 144#ifdef LONG64 145typedef int BytesReadable_t; 146#else 147typedef long BytesReadable_t; 148#endif 149 150 151#if defined(WIN32) || defined(USG) 152 153/* 154 * TRANS(Readv) and TRANS(Writev) use struct iovec, normally found 155 * in Berkeley systems in <sys/uio.h>. See the readv(2) and writev(2) 156 * manual pages for details. 157 */ 158 159struct iovec { 160 caddr_t iov_base; 161 int iov_len; 162}; 163 164#else 165#include <sys/uio.h> 166#endif 167 168typedef struct _XtransConnInfo *XtransConnInfo; 169 170 171/* 172 * Transport Option definitions 173 */ 174 175#define TRANS_NONBLOCKING 1 176#define TRANS_CLOSEONEXEC 2 177 178 179/* 180 * Return values of Connect (0 is success) 181 */ 182 183#define TRANS_CONNECT_FAILED -1 184#define TRANS_TRY_CONNECT_AGAIN -2 185#define TRANS_IN_PROGRESS -3 186 187 188/* 189 * Return values of CreateListener (0 is success) 190 */ 191 192#define TRANS_CREATE_LISTENER_FAILED -1 193#define TRANS_ADDR_IN_USE -2 194 195 196/* 197 * Return values of Accept (0 is success) 198 */ 199 200#define TRANS_ACCEPT_BAD_MALLOC -1 201#define TRANS_ACCEPT_FAILED -2 202#define TRANS_ACCEPT_MISC_ERROR -3 203 204 205/* 206 * ResetListener return values 207 */ 208 209#define TRANS_RESET_NOOP 1 210#define TRANS_RESET_NEW_FD 2 211#define TRANS_RESET_FAILURE 3 212 213 214/* 215 * Function prototypes for the exposed interface 216 */ 217 218void TRANS(FreeConnInfo) ( 219 XtransConnInfo /* ciptr */ 220); 221 222#ifdef TRANS_CLIENT 223 224XtransConnInfo TRANS(OpenCOTSClient)( 225 const char * /* address */ 226); 227 228#endif /* TRANS_CLIENT */ 229 230#ifdef TRANS_SERVER 231 232XtransConnInfo TRANS(OpenCOTSServer)( 233 const char * /* address */ 234); 235 236#endif /* TRANS_SERVER */ 237 238#ifdef TRANS_REOPEN 239 240XtransConnInfo TRANS(ReopenCOTSServer)( 241 int, /* trans_id */ 242 int, /* fd */ 243 const char * /* port */ 244); 245 246int TRANS(GetReopenInfo)( 247 XtransConnInfo, /* ciptr */ 248 int *, /* trans_id */ 249 int *, /* fd */ 250 char ** /* port */ 251); 252 253#endif /* TRANS_REOPEN */ 254 255 256int TRANS(SetOption)( 257 XtransConnInfo, /* ciptr */ 258 int, /* option */ 259 int /* arg */ 260); 261 262#ifdef TRANS_SERVER 263 264int TRANS(CreateListener)( 265 XtransConnInfo, /* ciptr */ 266 const char *, /* port */ 267 unsigned int /* flags */ 268); 269 270int TRANS(Received) ( 271 const char* /* protocol*/ 272); 273 274int TRANS(NoListen) ( 275 const char* /* protocol*/ 276); 277 278int TRANS(Listen) ( 279 const char* /* protocol*/ 280); 281 282int TRANS(IsListening) ( 283 const char* /* protocol*/ 284); 285 286int TRANS(ResetListener)( 287 XtransConnInfo /* ciptr */ 288); 289 290XtransConnInfo TRANS(Accept)( 291 XtransConnInfo, /* ciptr */ 292 int * /* status */ 293); 294 295#endif /* TRANS_SERVER */ 296 297#ifdef TRANS_CLIENT 298 299int TRANS(Connect)( 300 XtransConnInfo, /* ciptr */ 301 const char * /* address */ 302); 303 304#endif /* TRANS_CLIENT */ 305 306int TRANS(BytesReadable)( 307 XtransConnInfo, /* ciptr */ 308 BytesReadable_t * /* pend */ 309); 310 311int TRANS(Read)( 312 XtransConnInfo, /* ciptr */ 313 char *, /* buf */ 314 int /* size */ 315); 316 317int TRANS(Write)( 318 XtransConnInfo, /* ciptr */ 319 char *, /* buf */ 320 int /* size */ 321); 322 323int TRANS(Readv)( 324 XtransConnInfo, /* ciptr */ 325 struct iovec *, /* buf */ 326 int /* size */ 327); 328 329int TRANS(Writev)( 330 XtransConnInfo, /* ciptr */ 331 struct iovec *, /* buf */ 332 int /* size */ 333); 334 335int TRANS(SendFd) (XtransConnInfo ciptr, int fd, int do_close); 336 337int TRANS(RecvFd) (XtransConnInfo ciptr); 338 339int TRANS(Disconnect)( 340 XtransConnInfo /* ciptr */ 341); 342 343int TRANS(Close)( 344 XtransConnInfo /* ciptr */ 345); 346 347int TRANS(CloseForCloning)( 348 XtransConnInfo /* ciptr */ 349); 350 351int TRANS(IsLocal)( 352 XtransConnInfo /* ciptr */ 353); 354 355int TRANS(GetPeerAddr)( 356 XtransConnInfo, /* ciptr */ 357 int *, /* familyp */ 358 int *, /* addrlenp */ 359 Xtransaddr ** /* addrp */ 360); 361 362int TRANS(GetConnectionNumber)( 363 XtransConnInfo /* ciptr */ 364); 365 366#ifdef TRANS_SERVER 367 368int TRANS(MakeAllCOTSServerListeners)( 369 const char *, /* port */ 370 int *, /* partial */ 371 int *, /* count_ret */ 372 XtransConnInfo ** /* ciptrs_ret */ 373); 374 375#endif /* TRANS_SERVER */ 376 377 378/* 379 * Function Prototypes for Utility Functions. 380 */ 381 382#ifdef X11_t 383 384int TRANS(ConvertAddress)( 385 int *, /* familyp */ 386 int *, /* addrlenp */ 387 Xtransaddr ** /* addrp */ 388); 389 390#endif /* X11_t */ 391 392#ifdef ICE_t 393 394char * 395TRANS(GetMyNetworkId)( 396 XtransConnInfo /* ciptr */ 397); 398 399char * 400TRANS(GetPeerNetworkId)( 401 XtransConnInfo /* ciptr */ 402); 403 404#endif /* ICE_t */ 405 406int 407TRANS(GetHostname) ( 408 char * /* buf */, 409 int /* maxlen */ 410); 411 412#if defined(WIN32) && defined(TCPCONN) 413int TRANS(WSAStartup)(); 414#endif 415 416#endif /* _XTRANS_H_ */ 417