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