1/* 2 * Copyright (c) 2010 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of Apple Inc. ("Apple") nor the names of its 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * 30 * Portions of this software have been released under the following terms: 31 * 32 * (c) Copyright 1989-1993 OPEN SOFTWARE FOUNDATION, INC. 33 * (c) Copyright 1989-1993 HEWLETT-PACKARD COMPANY 34 * (c) Copyright 1989-1993 DIGITAL EQUIPMENT CORPORATION 35 * 36 * To anyone who acknowledges that this file is provided "AS IS" 37 * without any express or implied warranty: 38 * permission to use, copy, modify, and distribute this file for any 39 * purpose is hereby granted without fee, provided that the above 40 * copyright notices and this notice appears in all source code copies, 41 * and that none of the names of Open Software Foundation, Inc., Hewlett- 42 * Packard Company or Digital Equipment Corporation be used 43 * in advertising or publicity pertaining to distribution of the software 44 * without specific, written prior permission. Neither Open Software 45 * Foundation, Inc., Hewlett-Packard Company nor Digital 46 * Equipment Corporation makes any representations about the suitability 47 * of this software for any purpose. 48 * 49 * Copyright (c) 2007, Novell, Inc. All rights reserved. 50 * Redistribution and use in source and binary forms, with or without 51 * modification, are permitted provided that the following conditions 52 * are met: 53 * 54 * 1. Redistributions of source code must retain the above copyright 55 * notice, this list of conditions and the following disclaimer. 56 * 2. Redistributions in binary form must reproduce the above copyright 57 * notice, this list of conditions and the following disclaimer in the 58 * documentation and/or other materials provided with the distribution. 59 * 3. Neither the name of Novell Inc. nor the names of its contributors 60 * may be used to endorse or promote products derived from this 61 * this software without specific prior written permission. 62 * 63 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 64 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 65 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 66 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY 67 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 68 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 69 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 70 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 71 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 72 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 73 * 74 * @APPLE_LICENSE_HEADER_END@ 75 */ 76 77/* 78** 79** NAME: 80** 81** comsoc.h 82** 83** FACILITY: 84** 85** Remote Procedure Call (RPC) 86** 87** ABSTRACT: 88** 89** The internal network "socket" object interface. A very thin veneer 90** over the BSD socket abstraction interfaces. This makes life a little 91** easier when porting to different environments. 92** 93** All operations return a standard error value of type 94** rpc_socket_error_t, operate on socket handles of type rpc_socket_t 95** and socket addresses of type rpc_socket_addr_t. These are the types 96** that one should use when coding. 97** 98** Note that there is a distinction between local runtime internal 99** representations of socket addresses and architected (on-the-wire) 100** representations used by location services. This interface specifies 101** the local runtime internal representation. 102** 103** Operations that return an error value always set the value 104** appropriately. A value other than rpc_c_socket_ok indicates failure; 105** the values of additional output parameters are undefined. Other 106** error values are system dependent. 107** 108** 109*/ 110 111#ifndef _COMSOC_H 112#define _COMSOC_H 1 113 114/* 115 * Include platform-specific socket definitions 116 */ 117 118/* 119 * The maximum number of iov elements which can be sent through 120 * sendmsg is MSG_IOVLEN-1. 121 */ 122#define RPC_C_MAX_IOVEC_LEN ( MSG_MAXIOVLEN - 1) 123 124/* 125 * The maximum number of connections which can be queued on a socket. 126 */ 127#define RPC_C_LISTEN_BACKLOG SOMAXCONN 128 129/* 130 * Changing anything below will affect other portions of the runtime. 131 */ 132 133typedef struct iovec rpc_socket_iovec_t; 134typedef struct iovec *rpc_socket_iovec_p_t; 135typedef int rpc_socket_error_t; 136 137/* 138 * bkoropoff // Likewise 139 * 140 * New types that allow for socket handles that are more abstract than just a file descriptor 141 */ 142 143typedef boolean (*rpc_socket_enum_iface_fn_p_t) ( 144 rpc_socket_t sock, 145 rpc_addr_p_t ip_addr, 146 rpc_addr_p_t netmask_addr, 147 rpc_addr_p_t broadcast_addr 148 ); 149 150typedef struct rpc_cn_assoc_s_t rpc_cn_assoc_t, *rpc_cn_assoc_p_t; 151 152typedef struct rpc_socket_vtbl_s 153{ 154 /* Used when wrapping a native descriptor in a rpc_socket_t */ 155 rpc_socket_error_t 156 (*socket_duplicate) ( 157 rpc_socket_t sock, 158 rpc_protseq_id_t pseq_id, 159 const void * sockrep 160 ); 161 /* Used when opening a socket */ 162 rpc_socket_error_t 163 (*socket_construct) ( 164 rpc_socket_t sock, 165 rpc_protseq_id_t pseq_id, 166 rpc_transport_info_handle_t info 167 ); 168 /* Used when closing a socket */ 169 rpc_socket_error_t 170 (*socket_destruct) ( 171 rpc_socket_t sock 172 ); 173 /* Bind the socket */ 174 rpc_socket_error_t 175 (*socket_bind) ( 176 rpc_socket_t sock, 177 rpc_addr_p_t addr 178 ); 179 /* Connect the socket */ 180 rpc_socket_error_t 181 (*socket_connect) ( 182 rpc_socket_t sock, 183 rpc_addr_p_t addr, 184 rpc_cn_assoc_t* assoc 185 ); 186 /* Accept a connection on a listen socket */ 187 rpc_socket_error_t 188 (*socket_accept) ( 189 rpc_socket_t sock, 190 rpc_addr_p_t addr, 191 rpc_socket_t* newsock 192 ); 193 /* Begin listening for connections on a socket */ 194 rpc_socket_error_t 195 (*socket_listen) ( 196 rpc_socket_t sock, 197 int backlog 198 ); 199 /* Send a message over the socket */ 200 rpc_socket_error_t 201 (*socket_sendmsg) ( 202 rpc_socket_t sock, 203 rpc_socket_iovec_p_t iov, 204 int iov_len, 205 rpc_addr_p_t addr, 206 size_t * cc 207 ); 208 /* Receive data from the socket */ 209 rpc_socket_error_t 210 (*socket_recvfrom) ( 211 rpc_socket_t sock, 212 byte_p_t buf, 213 int len, 214 rpc_addr_p_t from, 215 size_t *cc 216 ); 217 /* Receive a message from the socket */ 218 rpc_socket_error_t 219 (*socket_recvmsg) ( 220 rpc_socket_t sock, 221 rpc_socket_iovec_p_t iov, 222 int iov_len, 223 rpc_addr_p_t addr, 224 size_t * cc 225 ); 226 /* Inquire local socket endpoint */ 227 rpc_socket_error_t 228 (*socket_inq_endpoint) ( 229 rpc_socket_t sock, 230 rpc_addr_p_t addr 231 ); 232 /* Enabled broadcasting on datagram socket */ 233 rpc_socket_error_t 234 (*socket_set_broadcast) ( 235 rpc_socket_t sock 236 ); 237 /* Set socket buffer sizes */ 238 rpc_socket_error_t 239 (*socket_set_bufs) ( 240 rpc_socket_t sock, 241 unsigned32 txsize, 242 unsigned32 rxsize, 243 unsigned32* ntxsize, 244 unsigned32* nrxsize 245 ); 246 /* Set socket as non-blocking */ 247 rpc_socket_error_t 248 (*socket_set_nbio) ( 249 rpc_socket_t sock 250 ); 251 /* Set socket to close automatically when the process loads a new executable */ 252 rpc_socket_error_t 253 (*socket_set_close_on_exec) ( 254 rpc_socket_t sock 255 ); 256 /* Get peer address */ 257 rpc_socket_error_t 258 (*socket_getpeername) ( 259 rpc_socket_t sock, 260 rpc_addr_p_t addr 261 ); 262 /* Get socket network interface */ 263 rpc_socket_error_t 264 (*socket_get_if_id) ( 265 rpc_socket_t sock, 266 rpc_network_if_id_t* network_if_id 267 ); 268 /* Set socket as keep-alive */ 269 rpc_socket_error_t 270 (*socket_set_keepalive) ( 271 rpc_socket_t sock 272 ); 273 /* Block for the specified period of time until the socket is ready for writing */ 274 rpc_socket_error_t 275 (*socket_nowriteblock_wait) ( 276 rpc_socket_t sock, 277 struct timeval *tmo 278 ); 279 /* Set socket receive timeout */ 280 rpc_socket_error_t 281 (*socket_set_rcvtimeo) ( 282 rpc_socket_t sock, 283 struct timeval *tmo 284 ); 285 /* Get peer credentials for local connection */ 286 rpc_socket_error_t 287 (*socket_getpeereid) ( 288 rpc_socket_t sock, 289 uid_t* uid, 290 gid_t* gid 291 ); 292 /* Get a file descriptor suitable for using select() to decide when data is readable */ 293 int 294 (*socket_get_select_desc) ( 295 rpc_socket_t sock 296 ); 297 /* Enumerate available network interfaces for the socket */ 298 rpc_socket_error_t 299 (*socket_enum_ifaces) ( 300 rpc_socket_t sock, 301 rpc_socket_enum_iface_fn_p_t efun, 302 rpc_addr_vector_p_t *rpc_addr_vec, 303 rpc_addr_vector_p_t *netmask_addr_vec, 304 rpc_addr_vector_p_t *broadcast_addr_vec 305 ); 306 /* Inquire transport-level info */ 307 rpc_socket_error_t 308 (*socket_inq_transport_info) ( 309 rpc_socket_t sock, 310 rpc_transport_info_handle_t* info 311 ); 312 /* Free transport-level info */ 313 void 314 (*transport_info_free) ( 315 rpc_transport_info_handle_t info 316 ); 317 318 boolean 319 (*transport_info_equal) ( 320 rpc_transport_info_handle_t info1, 321 rpc_transport_info_handle_t info2 322 ); 323 324 /* Inquire for access token */ 325 rpc_socket_error_t 326 (*transport_inq_access_token) ( 327 rpc_transport_info_handle_t info, 328 rpc_access_token_p_t* token 329 ); 330} rpc_socket_vtbl_t, *rpc_socket_vtbl_p_t; 331 332typedef struct rpc_socket_handle_s 333{ 334 const rpc_socket_vtbl_t* vtbl; 335 rpc_protseq_id_t pseq_id; 336 union 337 { 338 ssize_t word; 339 void* pointer; 340 } data; 341} rpc_socket_handle_t, *rpc_socket_handle_p_t; 342 343typedef int rpc_socket_basic_t; 344 345#include <comsoc_sys.h> 346#include <comnaf.h> 347#include <ipnaf.h> 348#include <cnp.h> 349 350#ifdef __cplusplus 351extern "C" { 352#endif 353 354/* 355 * R P C _ _ S O C K E T _ W R A P 356 * 357 * Take an existing native socket descriptor and wrap it in 358 * a rpc_socket_t. 359 */ 360 361PRIVATE rpc_socket_error_t rpc__socket_wrap ( 362 rpc_protseq_id_t pseq_id, 363 const void * sockrep, 364 rpc_socket_t * sock 365 ); 366 367/* 368 * R P C _ _ S O C K E T _ O P E N 369 * 370 * Create a new socket for the specified Protocol Sequence. 371 * The new socket has blocking IO semantics. 372 * 373 * (see BSD UNIX socket(2)). 374 */ 375 376PRIVATE rpc_socket_error_t rpc__socket_open ( 377 rpc_protseq_id_t pseq_id, 378 rpc_transport_info_handle_t info, 379 rpc_socket_t * sock 380 ); 381 382/* 383 * R P C _ _ S O C K E T _ O P E N _ B A S I C 384 * 385 * A special version of socket_open that is used *only* by 386 * the low level initialization code when it is trying to 387 * determine what network services are supported by the host OS. 388 */ 389 390PRIVATE rpc_socket_error_t rpc__socket_open_basic ( 391 rpc_naf_id_t /*naf*/, 392 rpc_network_if_id_t /*net_if*/, 393 rpc_network_protocol_id_t /*net_prot*/, 394 rpc_socket_basic_t * /*sock*/ 395 ); 396 397/* 398 * R P C _ _ S O C K E T _ C L O S E 399 * 400 * Close (destroy) a socket. 401 * 402 * (see BSD UNIX close(2)). 403 */ 404 405PRIVATE rpc_socket_error_t rpc__socket_close ( 406 rpc_socket_t /*sock*/ 407 ); 408 409/* 410 * R P C _ _ S O C K E T _ C L O S E _ B A S I C 411 * 412 * Close (destroy) a basic socket. 413 * 414 * (see BSD UNIX close(2)). 415 */ 416 417PRIVATE rpc_socket_error_t rpc__socket_close_basic ( 418 rpc_socket_basic_t /*sock*/ 419 ); 420 421/* 422 * R P C _ _ S O C K E T _ B I N D 423 * 424 * Bind a socket to a specified local address. 425 * 426 * (see BSD UNIX bind(2)). 427 */ 428 429PRIVATE rpc_socket_error_t rpc__socket_bind ( 430 rpc_socket_t /*sock*/, 431 rpc_addr_p_t /*addr*/ 432 ); 433 434/* 435 * R P C _ _ S O C K E T _ C O N N E C T 436 * 437 * Connect a socket to a specified peer's address. 438 * This is used only by Connection oriented Protocol Services. 439 * 440 * (see BSD UNIX connect(2)). 441 */ 442 443PRIVATE rpc_socket_error_t rpc__socket_connect ( 444 rpc_socket_t /*sock*/, 445 rpc_addr_p_t /*addr*/, 446 rpc_cn_assoc_t* /*assoc*/ 447 ); 448 449/* 450 * R P C _ _ S O C K E T _ A C C E P T 451 * 452 * Accept a connection on a socket, creating a new socket for the new 453 * connection. A rpc_addr_t appropriate for the NAF corresponding to 454 * this socket must be provided. addr.len must set to the actual size 455 * of addr.sa. This operation fills in addr.sa and sets addr.len to 456 * the new size of the field. This is used only by Connection oriented 457 * Protocol Services. 458 * 459 * (see BSD UNIX accept(2)). 460 */ 461 462PRIVATE rpc_socket_error_t rpc__socket_accept ( 463 rpc_socket_t /*sock*/, 464 rpc_addr_p_t /*addr*/, 465 rpc_socket_t * /*newsock*/ 466 ); 467 468/* 469 * R P C _ _ S O C K E T _ L I S T E N 470 * 471 * Listen for a connection on a socket. 472 * This is used only by Connection oriented Protocol Services. 473 * 474 * (see BSD UNIX listen(2)). 475 */ 476 477PRIVATE rpc_socket_error_t rpc__socket_listen ( 478 rpc_socket_t /*sock*/, 479 int /*backlog*/ 480 ); 481 482/* 483 * R P C _ _ S O C K E T _ S E N D M S G 484 * 485 * Send a message over a given socket. An error code as well as the 486 * actual number of bytes sent are returned. 487 * 488 * (see BSD UNIX sendmsg(2)). 489 */ 490 491PRIVATE rpc_socket_error_t rpc__socket_sendmsg ( 492 rpc_socket_t /*sock*/, 493 rpc_socket_iovec_p_t /*iov*/, /* array of bufs of data to send */ 494 int /*iov_len*/, /* number of bufs */ 495 rpc_addr_p_t /*addr*/, /* addr of receiver */ 496 size_t * /*cc*/ /* returned number of bytes actually sent */ 497 ); 498 499/* 500 * R P C _ _ S O C K E T _ R E C V F R O M 501 * 502 * Recieve the next buffer worth of information from a socket. A 503 * rpc_addr_t appropriate for the NAF corresponding to this socket must 504 * be provided. addr.len must set to the actual size of addr.sa. This 505 * operation fills in addr.sa and sets addr.len to the new size of the 506 * field. An error status as well as the actual number of bytes received 507 * are also returned. 508 * 509 * (see BSD UNIX recvfrom(2)). 510 */ 511 512PRIVATE rpc_socket_error_t rpc__socket_recvfrom ( 513 rpc_socket_t /*sock*/, 514 byte_p_t /*buf*/, /* buf for rcvd data */ 515 int /*len*/, /* len of above buf */ 516 rpc_addr_p_t /*from*/, /* addr of sender */ 517 size_t * /*cc*/ /* returned number of bytes actually rcvd */ 518 ); 519 520/* 521 * R P C _ _ S O C K E T _ R E C V M S G 522 * 523 * Receive a message over a given socket. A rpc_addr_t appropriate for 524 * the NAF corresponding to this socket must be provided. addr.len must 525 * set to the actual size of addr.sa. This operation fills in addr.sa 526 * and sets addr.len to the new size of the field. An error code as 527 * well as the actual number of bytes received are also returned. 528 * 529 * (see BSD UNIX recvmsg(2)). 530 */ 531 532PRIVATE rpc_socket_error_t rpc__socket_recvmsg ( 533 rpc_socket_t /*sock*/, 534 rpc_socket_iovec_p_t /*iov*/, /* array of bufs for rcvd data */ 535 int /*iov_len*/, /* number of bufs */ 536 rpc_addr_p_t /*addr*/, /* addr of sender */ 537 size_t * /*cc*/ /* returned number of bytes actually rcvd */ 538 ); 539 540/* 541 * R P C _ _ S O C K E T _ I N Q _ A D D R 542 * 543 * Return the local address associated with a socket. A rpc_addr_t 544 * appropriate for the NAF corresponding to this socket must be provided. 545 * addr.len must set to the actual size of addr.sa. This operation fills 546 * in addr.sa and sets addr.len to the new size of the field. 547 * 548 * !!! NOTE: You should use rpc__naf_desc_inq_addr() !!! 549 * 550 * This routine is indended for use only by the internal routine: 551 * rpc__naf_desc_inq_addr(). rpc__socket_inq_endpoint() only has the 552 * functionality of BSD UNIX getsockname() which doesn't (at least not 553 * on all systems) return the local network portion of a socket's address. 554 * rpc__naf_desc_inq_addr() returns the complete address for a socket. 555 * 556 * (see BSD UNIX getsockname(2)). 557 */ 558 559PRIVATE rpc_socket_error_t rpc__socket_inq_endpoint ( 560 rpc_socket_t /*sock*/, 561 rpc_addr_p_t /*addr*/ 562 ); 563 564/* 565 * R P C _ _ S O C K E T _ I N Q _ P E E R _ E N D P O I N T 566 * 567 * Return the local address associated with a socket. A rpc_addr_t 568 * appropriate for the NAF corresponding to this socket must be provided. 569 * addr.len must set to the actual size of addr.sa. This operation fills 570 * in addr.sa and sets addr.len to the new size of the field. 571 * 572 * !!! NOTE: You should use rpc__naf_desc_inq_addr() !!! 573 * 574 * This routine is indended for use only by the internal routine: 575 * rpc__naf_desc_inq_addr(). rpc__socket_inq_endpoint() only has the 576 * functionality of BSD UNIX getsockname() which doesn't (at least not 577 * on all systems) return the local network portion of a socket's address. 578 * rpc__naf_desc_inq_addr() returns the complete address for a socket. 579 * 580 * (see BSD UNIX getsockname(2)). 581 */ 582 583PRIVATE rpc_socket_error_t rpc__socket_inq_peer_endpoint ( 584 rpc_socket_t /*sock*/, 585 rpc_addr_p_t /*addr*/ 586 ); 587 588/* 589 * R P C _ _ S O C K E T _ S E T _ B R O A D C A S T 590 * 591 * Enable broadcasting for the socket (as best it can). 592 * Used only by Datagram based Protocol Services. 593 */ 594 595PRIVATE rpc_socket_error_t rpc__socket_set_broadcast ( 596 rpc_socket_t /*sock*/ 597 ); 598 599/* 600 * R P C _ _ S O C K E T _ S E T _ B U F S 601 * 602 * Set the socket's send and receive buffer sizes and return the new 603 * values. 604 * 605 * (similar to BSD UNIX setsockopt()). 606 */ 607 608PRIVATE rpc_socket_error_t rpc__socket_set_bufs ( 609 rpc_socket_t /*sock*/, 610 unsigned32 /*txsize*/, 611 unsigned32 /*rxsize*/, 612 unsigned32 * /*ntxsize*/, 613 unsigned32 * /*nrxsize*/ 614 ); 615 616/* 617 * R P C _ _ S O C K E T _ S E T _ N B I O 618 * 619 * Set a socket to non-blocking mode. 620 * 621 * (see BSD UNIX fcntl(sock, F_SETFL, O_NDELAY)) 622 */ 623 624PRIVATE rpc_socket_error_t rpc__socket_set_nbio ( 625 rpc_socket_t /*sock*/ 626 ); 627 628/* 629 * R P C _ _ S O C K E T _ S E T _ C L O S E _ O N _ E X E C 630 * 631 * Set a socket to a mode whereby it is not inherited by a spawned process 632 * executing some new image. This is possibly a no-op on some systems. 633 * 634 * (see BSD UNIX fcntl(sock, F_SETFD, 1)) 635 */ 636 637PRIVATE rpc_socket_error_t rpc__socket_set_close_on_exec ( 638 rpc_socket_t /*sock*/ 639 ); 640 641/* 642 * R P C _ _ S O C K E T _ D U P L I C A T E 643 * 644 * Create a new rpc_socket_t that is a duplicate of an existing platform-native 645 * socket type. 646 */ 647PRIVATE rpc_socket_error_t rpc__socket_duplicate ( 648 rpc_protseq_id_t /* [in] socket protoseq */, 649 const void * sockrep /* [in] native socket representation */, 650 rpc_socket_t * /* [out] RPC socket */ 651 ); 652 653/* 654 * R P C _ _ S O C K E T _ G E T P E E R N A M E 655 * 656 * Get name of connected peer. 657 * This is used only by Connection oriented Protocol Services. 658 * 659 * (see BSD UNIX getpeername(2)). 660 */ 661 662PRIVATE rpc_socket_error_t rpc__socket_getpeername ( 663 rpc_socket_t /*sock*/, 664 rpc_addr_p_t /*addr*/ 665 ); 666 667/* 668 * R P C _ _ S O C K E T _ G E T _ I F _ I D 669 * 670 * Get socket network interface id (socket type). 671 * 672 * (see BSD UNIX getsockopt(2)). 673 */ 674 675PRIVATE rpc_socket_error_t rpc__socket_get_if_id ( 676 rpc_socket_t /*sock*/, 677 rpc_network_if_id_t * /*network_if_id*/ 678 ); 679 680/* 681 * R P C _ _ S O C K E T _ S E T _ K E E P A L I V E. 682 * 683 * Set keepalive option for connection. 684 * Used only by Connection based Protocol Services. 685 * 686 * (see BSD UNIX setsockopt(2)). 687 */ 688 689PRIVATE rpc_socket_error_t rpc__socket_set_keepalive ( 690 rpc_socket_t /*sock*/ 691 ); 692 693/* 694 * R P C _ _ S O C K E T _ N O W R I T E B L O C K _ W A I T 695 * 696 * Wait until the a write on the socket should succede without 697 * blocking. If tmo is NULL, the wait is unbounded, otherwise 698 * tmo specifies the max time to wait. rpc_c_socket_etimedout 699 * if a timeout occurs. This operation in not cancellable. 700 */ 701 702PRIVATE rpc_socket_error_t rpc__socket_nowriteblock_wait ( 703 rpc_socket_t /*sock*/, 704 struct timeval * /*tmo*/ 705 ); 706 707/* 708 * R P C _ _ S O C K E T _ S E T _ R C V T I M E O 709 * 710 * Set receive timeout option for connection. 711 * Used only by Connection based Protocol Services. 712 * 713 * (see BSD UNIX setsockopt(2)). 714 */ 715 716PRIVATE rpc_socket_error_t rpc__socket_set_rcvtimeo ( 717 rpc_socket_t, /*sock*/ 718 struct timeval * /*tmo*/ 719 ); 720 721/* 722 * R P C _ _ S O C K E T _ G E T P E E R E I D 723 * 724 * Get UNIX domain socket peer credentials 725 */ 726 727PRIVATE rpc_socket_error_t rpc__socket_getpeereid ( 728 rpc_socket_t, /*sock*/ 729 uid_t *, 730 gid_t * 731 ); 732 733PRIVATE int 734rpc__socket_get_select_desc( 735 rpc_socket_t sock 736 ); 737 738PRIVATE rpc_socket_error_t 739rpc__socket_enum_ifaces ( 740 rpc_socket_t sock, 741 rpc_socket_enum_iface_fn_p_t efun, 742 rpc_addr_vector_p_t *rpc_addr_vec, 743 rpc_addr_vector_p_t *netmask_addr_vec, 744 rpc_addr_vector_p_t *broadcast_addr_vec 745 ); 746 747PRIVATE rpc_socket_error_t 748rpc__socket_inq_transport_info( 749 rpc_socket_t sock, 750 rpc_transport_info_p_t* info 751 ); 752 753PRIVATE rpc_socket_error_t 754rpc__transport_info_create( 755 rpc_protseq_id_t protseq, 756 rpc_transport_info_handle_t handle, 757 rpc_transport_info_p_t* info 758 ); 759 760PRIVATE void 761rpc__transport_info_retain( 762 rpc_transport_info_p_t info 763 ); 764 765PRIVATE void 766rpc__transport_info_release( 767 rpc_transport_info_p_t info 768 ); 769 770PRIVATE boolean 771rpc__transport_info_equal( 772 rpc_transport_info_p_t info1, 773 rpc_transport_info_p_t info2 774 ); 775 776/* 777 * Public error constants and functions for comparing errors. 778 * The _ETOI_ (error-to-int) function converts a socket error to a simple 779 * integer value that can be used in error mesages. 780 */ 781 782#define RPC_C_SOCKET_OK 0 /* a successful error value */ 783#define RPC_C_SOCKET_EWOULDBLOCK EWOULDBLOCK /* operation would block */ 784#define RPC_C_SOCKET_EINTR EINTR /* operation was interrupted */ 785#define RPC_C_SOCKET_EIO EIO /* I/O error */ 786#define RPC_C_SOCKET_EADDRINUSE EADDRINUSE /* address was in use (see bind) */ 787#define RPC_C_SOCKET_ECONNRESET ECONNRESET /* connection reset by peer */ 788#define RPC_C_SOCKET_ETIMEDOUT ETIMEDOUT /* connection request timed out*/ 789#define RPC_C_SOCKET_ECONNREFUSED ECONNREFUSED /* connection request refused */ 790#define RPC_C_SOCKET_ENOTSOCK ENOTSOCK /* descriptor was not a socket */ 791#define RPC_C_SOCKET_ENETUNREACH ENETUNREACH /* network is unreachable*/ 792#define RPC_C_SOCKET_ENOSPC ENOSPC /* no local or remote resources */ 793#define RPC_C_SOCKET_ENETDOWN ENETDOWN /* network is down */ 794#define RPC_C_SOCKET_ETOOMANYREFS ETOOMANYREFS /* too many remote connections */ 795#define RPC_C_SOCKET_ESRCH ESRCH /* remote endpoint not found */ 796#define RPC_C_SOCKET_EHOSTDOWN EHOSTDOWN /* remote host is down */ 797#define RPC_C_SOCKET_EHOSTUNREACH EHOSTUNREACH /* remote host is unreachable */ 798#define RPC_C_SOCKET_ECONNABORTED ECONNABORTED /* local host aborted connect */ 799#define RPC_C_SOCKET_ECONNRESET ECONNRESET /* remote host reset connection */ 800#define RPC_C_SOCKET_ENETRESET ENETRESET /* remote host crashed */ 801#define RPC_C_SOCKET_ENOEXEC ENOEXEC /* invalid endpoint format for remote */ 802#define RPC_C_SOCKET_EACCESS EACCES /* access control information */ 803 /* invalid at remote node */ 804#define RPC_C_SOCKET_EPIPE EPIPE /* a write on a pipe */ 805 /* or socket for which there */ 806 /* is no process to */ 807 /* read the data. */ 808#define RPC_C_SOCKET_EAGAIN EAGAIN /* no more processes */ 809#define RPC_C_SOCKET_EALREADY EALREADY /* operation already */ 810 /* in progress */ 811#define RPC_C_SOCKET_EDEADLK EDEADLK /* resource deadlock */ 812 /* would occur */ 813#define RPC_C_SOCKET_EINPROGRESS EINPROGRESS /* operation now in */ 814 /* progress */ 815#define RPC_C_SOCKET_EISCONN EISCONN /* socket is already */ 816 /* connected */ 817#define RPC_C_SOCKET_ENOTSUP ENOTSUP /* operation not supported */ 818#define RPC_C_SOCKET_ENOMEM ENOMEM /* out of memory */ 819#define RPC_C_SOCKET_EINVAL EINVAL /* invalid parameter */ 820#define RPC_C_SOCKET_EAUTH EAUTH /* authentication error */ 821#define RPC_C_SOCKET_ENOENT ENOENT /* no such file or directory */ 822#define RPC_C_SOCKET_EMSGSIZE EMSGSIZE /* message too long */ 823 824#ifdef ETIME 825#define RPC_C_SOCKET_ETIME ETIME /* A time skew occurred */ 826#else 827#define RPC_C_SOCKET_ETIME (ELAST + 1) /* A time skew occurred */ 828#endif 829 830/* 831 * A macro to determine if an socket error can be recovered from by 832 * retrying. 833 */ 834#define RPC_SOCKET_ERR_IS_BLOCKING(s) \ 835 ((s == RPC_C_SOCKET_EAGAIN) || (s == RPC_C_SOCKET_EWOULDBLOCK) || (s == RPC_C_SOCKET_EINPROGRESS) || \ 836 (s == RPC_C_SOCKET_EALREADY) || (s == RPC_C_SOCKET_EDEADLK)) 837 838#define RPC_SOCKET_ERR_EQ(serr, e) ((serr) == e) 839 840#define RPC_SOCKET_IS_ERR(serr) (! RPC_SOCKET_ERR_EQ(serr, RPC_C_SOCKET_OK)) 841 842#define RPC_SOCKET_ETOI(serr) (serr) 843 844#define RPC_SOCKET_CLOSE(s) \ 845 ({ int __err = rpc__socket_close(s); s = NULL; __err; }) 846 847#endif /* _COMSOC_H */ 848