1 Headers                                           socket.h(3HEAD)
   2 
   3 
   4 
   5 NAME
   6      socket.h, socket - Internet Protocol family
   7 
   8 SYNOPSIS
   9      #include <sys/socket.h>
  10 
  11 
  12 DESCRIPTION
  13      The <sys/socket.h> header defines the unsigned integral type
  14      sa_family_t through typedef.
  15 
  16 
  17      The <sys/socket.h> header  defines  the  sockaddr  structure
  18      that includes the following members:
  19 
  20        sa_family_t   sa_family     /* address family */
  21        char          sa_data[]     /* socket   address (variable-length
  22                                       data) */
  23 
  24 
  25 
  26   libxnet Interfaces
  27      The <sys/socket.h> header defines the msghdr  structure  for
  28      libxnet interfaces that includes the following members:
  29 
  30        void            *msg_name         /* optional address */
  31        socklen_t       msg_namelen       /* size of address */
  32        struct iovec    *msg_iov          /* scatter/gather array */
  33        int             msg_iovlen        /* members in msg_iov */
  34        void            *msg_control      /* ancillary data, see below */
  35        socklen_t       msg_controllen    /* ancillary data buffer len */
  36        int             msg_flags         /* flags on received message */
  37 
  38 
  39 
  40      The <sys/socket.h> header defines the cmsghdr structure  for
  41      libxnet that includes the following members:
  42 
  43        socklen_t  cmsg_len      /* data byte count, including hdr */
  44        int        cmsg_level    /* originating protocol */
  45        int        cmsg_type     /* protocol-specific type */
  46 
  47 
  48 
  49      Ancillary data consists of a sequence of  pairs,  each  con-
  50      sisting of a cmsghdr structure followed by a data array. The
  51      data array contains the  ancillary  data  message,  and  the
  52      cmsghdr  structure  contains  descriptive  information  that
  53      allows an application to correctly parse the data.
  54 
  55 
  56 
  57 
  58 
  59 
  60 SunOS 5.11          Last change: 03 Aug 2006                    1
  61 
  62 
  63 
  64 
  65 
  66 
  67 Headers                                           socket.h(3HEAD)
  68 
  69 
  70 
  71      The values for cmsg_level will be legal values for the level
  72      argument to the getsockopt() and setsockopt() functions. The
  73      SCM_RIGHTS type is supported for level SOL_SOCKET.
  74 
  75 
  76      Ancillary data is also possible at  the  socket  level.  The
  77      <sys/socket.h>  header  defines the following macros for use
  78      as the cmsg_type values when cmsg_level is SOL_SOCKET.
  79 
  80      SCM_RIGHTS    Indicates that the  data  array  contains  the
  81                    access rights to be sent or received.
  82 
  83 
  84      SCM_UCRED     Indicates  that  the  data  array  contains  a
  85                    ucred_t  to  be  received.  The ucred_t is the
  86                    credential of the sending process at the  time
  87                    the  message was sent. This is a Sun-specific,
  88                    Evolving interface. See ucred_get(3C).
  89 
  90 
  91 
  92      The IPv4 data formats generally use the same values for data
  93      passed  back  in  cmsghdr  as for setsockopt() to enable the
  94      feature. The IPv4 data formats are  listed  below  with  the
  95      associated payload for each.
  96 
  97      IPPROTO_IP
  98      IP_RECVDSTADDR
  99 
 100          ipaddr_t, IP address
 101 
 102 
 103      IPPROTO_IP
 104      IP_RECVOPTS
 105 
 106          variable-length IP options, up to 40 bytes
 107 
 108 
 109      IPPROTO_IP
 110      IP_RECVIF
 111 
 112          uint_t, ifIndex number
 113 
 114 
 115      IPPROTO_IP
 116      IP_RECVSLLA
 117 
 118          struct sockaddr_dl, link layer address
 119 
 120 
 121      IPPROTO_IP
 122      IP_RECVTTL
 123 
 124 
 125 
 126 SunOS 5.11          Last change: 03 Aug 2006                    2
 127 
 128 
 129 
 130 
 131 
 132 
 133 Headers                                           socket.h(3HEAD)
 134 
 135 
 136 
 137          uint8_t
 138 
 139 
 140      SOL_SOCKET
 141      SO_RECVUCRED
 142 
 143          ucred_t   -   cmsghdr.cmsg_type   is   SCM_UCRED,    not
 144          SO_RECVUCRED
 145 
 146 
 147 
 148      The IPv6 data formats use different values for enabling  the
 149      option  and  for  passing the value back to the application.
 150      The IPv6 data formats are listed below  with  the associated
 151      payload for each.
 152 
 153      IPPROTO_IPV6
 154      IPV6_RECVPKTINFO
 155 
 156          in_pktinfo, cmsg_type IPV6_PKTINFO
 157 
 158 
 159      IPPROTO_IPV6
 160      IPV6_RECVTCLASS
 161 
 162          uint_t, cmsg_type IPV6_TCLASS
 163 
 164 
 165      IPPROTO_IPV6
 166      IPV6_RECVPATHMTU
 167 
 168          ip6_mtuinfo, cmsg_type IPV6_PATHMTU
 169 
 170 
 171      IPPROTO_IPV6
 172      IPV6_RECVHOPLIMIT
 173 
 174          uint_t, cmsg_type IPV6_HOPLIMIT
 175 
 176 
 177      IPPROTO_IPV6
 178      IPV6_RECVHOPOPTS
 179 
 180          variable-length IPv6 options, cmsg_type IPV6_HOPOPTS
 181 
 182 
 183      IPPROTO_IPV6
 184      IPV6_RECVDSTOPTS
 185 
 186          variable-length IPv6 options, cmsg_type IPV6_DSTOPTS
 187 
 188 
 189 
 190 
 191 
 192 SunOS 5.11          Last change: 03 Aug 2006                    3
 193 
 194 
 195 
 196 
 197 
 198 
 199 Headers                                           socket.h(3HEAD)
 200 
 201 
 202 
 203      IPPROTO_IPV6
 204      IPV6_RECVRTHDR
 205 
 206          variable-length IPv6 options, cmsg_type IPV6_RTHDR
 207 
 208 
 209      IPPROTO_IPV6
 210      IPV6_RECVRTHDRDSTOPTS
 211 
 212          variable-length IPv6 options, cmsg_type IPV6_DSTOPTS
 213 
 214 
 215 
 216      The <sys/socket.h> header defines the  following  macros  to
 217      gain access to the data arrays in the ancillary data associ-
 218      ated with a message header:
 219 
 220      CMSG_DATA(cmsg)
 221 
 222          If the argument is a pointer  to  a  cmsghdr  structure,
 223          this  macro returns an unsigned character pointer to the
 224          data array associated with the cmsghdr structure.
 225 
 226 
 227      CMSG_NXTHDR(mhdr, cmsg)
 228 
 229          If the first argument is a pointer to a msghdr structure
 230          and the second argument is a pointer to a cmsghdr struc-
 231          ture  in  the  ancillary  data,  pointed   to   by   the
 232          msg_control  field  of that msghdr structure, this macro
 233          returns a pointer to the next cmsghdr  structure,  or  a
 234          null  pointer  if  this structure is the last cmsghdr in
 235          the ancillary data.
 236 
 237 
 238      CMSG_FIRSTHDR(mhdr)
 239 
 240          If the argument is a pointer to a msghdr structure, this
 241          macro  returns  a pointer to the first cmsghdr structure
 242          in the ancillary data associated with this msghdr struc-
 243          ture,  or  a  null pointer if there is no ancillary data
 244          associated with the msghdr structure.
 245 
 246 
 247      CMSG_SPACE(len)
 248 
 249          Given  the  length  of   an   ancillary   data   object,
 250          CMSG_SPACE()  returns  the  space required by the object
 251          and its cmsghdr structure, including any padding  needed
 252          to  satisfy  alignment  requirements.  This macro can be
 253          used, for example, to allocate space dynamically for the
 254          ancillary  data.  This  macro  should  not  be  used  to
 255 
 256 
 257 
 258 SunOS 5.11          Last change: 03 Aug 2006                    4
 259 
 260 
 261 
 262 
 263 
 264 
 265 Headers                                           socket.h(3HEAD)
 266 
 267 
 268 
 269          initialize the cmsg_len member of a  cmsghdr  structure.
 270          Use the CMSG_LEN() macro instead.
 271 
 272 
 273      CMSG_LEN(len)
 274 
 275          Given the length of an ancillary data object, CMSG_LEN()
 276          returns the value to store in the cmsg_len member of the
 277          cmsghdr  structure,  taking  into  account  any  padding
 278          needed to satisfy alignment requirements.
 279 
 280 
 281 
 282      The <sys/socket.h> header defines the linger structure  that
 283      includes the following members:
 284 
 285        int   l_onoff   /* indicates  whether  linger option is enabled */
 286        int   l_linger  /* linger time, in seconds */
 287 
 288 
 289 
 290      The <sys/socket.h> header defines the following macros:
 291 
 292      SOCK_DGRAM        Datagram socket
 293 
 294 
 295      SOCK_STREAM       Byte-stream socket
 296 
 297 
 298      SOCK_SEQPACKET    Sequenced-packet socket
 299 
 300 
 301 
 302      The *<sys/socket.h>* header defines the following macros for
 303      use  as    the  *level*   argument   of   *setsockopt()* and
 304      getsockopt()*.
 305 
 306      *SOL_SOCKET*  Options  to be  accessed at  the socket  level,
 307                    not the protocol level.
 308 
 309      *SOL_ROUTE*   Options to be accessed  at  the routing  socket
 310                    level, not the protocol level.
 311 
 312 
 313      The <sys/socket.h> header defines the following  macros  for
 314      use  as  the  option_name  argument  in getsockopt() or set-
 315      sockopt() calls:
 316 
 317      SO_DEBUG         Debugging information is being recorded.
 318 
 319 
 320      SO_ACCEPTCONN    Socket is accepting connections.
 321 
 322 
 323 
 324 
 325 
 326 
 327 SunOS 5.11          Last change: 03 Aug 2006                    5
 328 
 329 
 330 
 331 
 332 
 333 
 334 Headers                                           socket.h(3HEAD)
 335 
 336 
 337 
 338      SO_BROADCAST     Transmission of broadcast messages is  sup-
 339                       ported.
 340 
 341 
 342      SO_REUSEADDR     Reuse of local addresses is supported.
 343 
 344 
 345      SO_KEEPALIVE     Connections are kept  alive  with  periodic
 346                       messages.
 347 
 348 
 349      SO_LINGER        Socket lingers on close.
 350 
 351 
 352      SO_OOBINLINE     Out-of-band data is transmitted in line.
 353 
 354 
 355      SO_SNDBUF        Send buffer size.
 356 
 357 
 358      SO_RCVBUF        Receive buffer size.
 359 
 360 
 361      SO_ERROR         Socket error status.
 362 
 363 
 364      SO_TYPE          Socket type.
 365 
 366 
 367      SO_RECVUCRED     Request the reception  of  user  credential
 368                       ancillary  data.  This  is  a Sun-specific,
 369                       Evolving interface. See ucred_get(3C).
 370 
 371 
 372      SO_MAC_EXEMPT    Mandatory Access  Control  (MAC)  exemption
 373                       for  unlabeled peers. This option is avail-
 374                       able only if the system is configured  with
 375                       Trusted Extensions.
 376 
 377 
 378      SO_ALLZONES      Bypass zone boundaries (privileged).
 379 
 380 
 381 
 382      The <sys/socket.h> header defines the following  macros  for
 383      use  as  the  valid  values  for  the msg_flags field in the
 384      msghdr structure, or  the  flags  parameter  in  recvfrom(),
 385      recvmsg(), sendto(), or sendmsg() calls:
 386 
 387      MSG_CTRUNC     Control data truncated.
 388 
 389 
 390 
 391 
 392 
 393 SunOS 5.11          Last change: 03 Aug 2006                    6
 394 
 395 
 396 
 397 
 398 
 399 
 400 Headers                                           socket.h(3HEAD)
 401 
 402 
 403 
 404      MSG_EOR        Terminates a record (if supported by the pro-
 405                     tocol).
 406 
 407 
 408      MSG_OOB        Out-of-band data.
 409 
 410 
 411      MSG_PEEK       Leave received data in queue.
 412 
 413 
 414      MSG_TRUNC      Normal data truncated.
 415 
 416 
 417      MSG_WAITALL    Wait for complete message.
 418 
 419 
 420 
 421      The <sys/socket.h> header defines the following macros:
 422 
 423      AF_UNIX    UNIX domain sockets
 424 
 425 
 426      AF_INET    Internet domain sockets
 427 
 428 
 429 
 430      The <sys/socket.h> header defines the following macros:
 431 
 432      SHUT_RD      Disables further receive operations.
 433 
 434 
 435      SHUT_WR      Disables further send operations.
 436 
 437 
 438      SHUT_RDWR    Disables further send and receive operations.
 439 
 440 
 441   libsocket Interfaces
 442      The <sys/socket.h> header defines the msghdr  structure  for
 443      libsocket interfaces that includes the following members:
 444 
 445        void           *msg_name        /* optional address */
 446        socklen_t      msg_namelen      /* size of address */
 447        struct iovec   *msg_iov         /* scatter/gather array */
 448        int            msg_iovlen       /* # elements in msg_iov */
 449        caddr_t        msg_accrights    /* access rights sent/received */
 450 
 451 
 452 
 453      The msg_name and msg_namelen parameters specify the destina-
 454      tion address when the socket is unconnected The msg_name can
 455      be specified as a NULL pointer if no names  are  desired  or
 456 
 457 
 458 
 459 SunOS 5.11          Last change: 03 Aug 2006                    7
 460 
 461 
 462 
 463 
 464 
 465 
 466 Headers                                           socket.h(3HEAD)
 467 
 468 
 469 
 470      required.   The  msg_iov  and msg_iovlen parameters describe
 471      the scatter-gather locations, as described in  read(2).  The
 472      msg_accrights parameter specifies the buffer in which access
 473      rights  sent  along  with  the  message  are  received.  The
 474      msg_accrightslen specifies the length of the buffer.
 475 
 476 ATTRIBUTES
 477      See attributes(5) for descriptions of the  following  attri-
 478      butes:
 479 
 480 
 481 
 482      ____________________________________________________________
 483     |       ATTRIBUTE TYPE        |       ATTRIBUTE VALUE       |
 484     |_____________________________|_____________________________|
 485     | Interface Stability         | Standard                    |
 486     |_____________________________|_____________________________|
 487 
 488 
 489 SEE ALSO
 490      accept(3SOCKET), accept(3XNET), bind(3SOCKET),  bind(3XNET),
 491      connect(3SOCKET),    connect(3XNET),   getpeername(3SOCKET),
 492      getpeername(3XNET), getpeerucred(3C),  getsockname(3SOCKET),
 493      getsockname(3XNET),  getsockopt(3SOCKET), getsockopt(3XNET),
 494      libsocket(3LIB),       listen(3SOCKET),       listen(3XNET),
 495      recv(3SOCKET),        recv(3XNET),        recvfrom(3SOCKET),
 496      recvfrom(3XNET),      recvmsg(3SOCKET),      recvmsg(3XNET),
 497      send(3SOCKET),         send(3XNET),        sendmsg(3SOCKET),
 498      sendmsg(3XNET),       sendto(3SOCKET),        sendto(3XNET),
 499      setsockopt(3SOCKET),  setsockopt(3XNET),  shutdown(3SOCKET),
 500      shutdown(3XNET),       socket(3SOCKET),       socket(3XNET),
 501      socketpair(3SOCKET)                       socketpair(3XNET),
 502      ucred_get(3C)attributes(5), standards(5)
 503 
 504 
 505 
 506 
 507 
 508 
 509 
 510 
 511 
 512 
 513 
 514 
 515 
 516 
 517 
 518 
 519 
 520 
 521 
 522 
 523 
 524 
 525 SunOS 5.11          Last change: 03 Aug 2006                    8
 526 
 527 
 528