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 assocated 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 assocated 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 macro for 303 use as the level argument of setsockopt() and getsockopt(). 304 305 SOL_SOCKET Options to be accessed at socket level, not 306 protocol level. 307 308 309 310 The <sys/socket.h> header defines the following macros for 311 use as the option_name argument in getsockopt() or set- 312 sockopt() calls: 313 314 SO_DEBUG Debugging information is being recorded. 315 316 317 SO_ACCEPTCONN Socket is accepting connections. 318 319 320 321 322 323 324 SunOS 5.11 Last change: 03 Aug 2006 5 325 326 327 328 329 330 331 Headers socket.h(3HEAD) 332 333 334 335 SO_BROADCAST Transmission of broadcast messages is sup- 336 ported. 337 338 339 SO_REUSEADDR Reuse of local addresses is supported. 340 341 342 SO_KEEPALIVE Connections are kept alive with periodic 343 messages. 344 345 346 SO_LINGER Socket lingers on close. 347 348 349 SO_OOBINLINE Out-of-band data is transmitted in line. 350 351 352 SO_SNDBUF Send buffer size. 353 354 355 SO_RCVBUF Receive buffer size. 356 357 358 SO_ERROR Socket error status. 359 360 361 SO_TYPE Socket type. 362 363 364 SO_RECVUCRED Request the reception of user credential 365 ancillary data. This is a Sun-specific, 366 Evolving interface. See ucred_get(3C). 367 368 369 SO_MAC_EXEMPT Mandatory Access Control (MAC) exemption 370 for unlabeled peers. This option is avail- 371 able only if the system is configured with 372 Trusted Extensions. 373 374 375 SO_ALLZONES Bypass zone boundaries (privileged). 376 377 378 379 The <sys/socket.h> header defines the following macros for 380 use as the valid values for the msg_flags field in the 381 msghdr structure, or the flags parameter in recvfrom(), 382 recvmsg(), sendto(), or sendmsg() calls: 383 384 MSG_CTRUNC Control data truncated. 385 386 387 388 389 390 SunOS 5.11 Last change: 03 Aug 2006 6 391 392 393 394 395 396 397 Headers socket.h(3HEAD) 398 399 400 401 MSG_EOR Terminates a record (if supported by the pro- 402 tocol). 403 404 405 MSG_OOB Out-of-band data. 406 407 408 MSG_PEEK Leave received data in queue. 409 410 411 MSG_TRUNC Normal data truncated. 412 413 414 MSG_WAITALL Wait for complete message. 415 416 417 418 The <sys/socket.h> header defines the following macros: 419 420 AF_UNIX UNIX domain sockets 421 422 423 AF_INET Internet domain sockets 424 425 426 427 The <sys/socket.h> header defines the following macros: 428 429 SHUT_RD Disables further receive operations. 430 431 432 SHUT_WR Disables further send operations. 433 434 435 SHUT_RDWR Disables further send and receive operations. 436 437 438 libsocket Interfaces 439 The <sys/socket.h> header defines the msghdr structure for 440 libsocket interfaces that includes the following members: 441 442 void *msg_name /* optional address */ 443 socklen_t msg_namelen /* size of address */ 444 struct iovec *msg_iov /* scatter/gather array */ 445 int msg_iovlen /* # elements in msg_iov */ 446 caddr_t msg_accrights /* access rights sent/received */ 447 448 449 450 The msg_name and msg_namelen parameters specify the destina- 451 tion address when the socket is unconnected The msg_name can 452 be specified as a NULL pointer if no names are desired or 453 454 455 456 SunOS 5.11 Last change: 03 Aug 2006 7 457 458 459 460 461 462 463 Headers socket.h(3HEAD) 464 465 466 467 required. The msg_iov and msg_iovlen parameters describe 468 the scatter-gather locations, as described in read(2). The 469 msg_accrights parameter specifies the buffer in which access 470 rights sent along with the message are received. The 471 msg_accrightslen specifies the length of the buffer. 472 473 ATTRIBUTES 474 See attributes(5) for descriptions of the following attri- 475 butes: 476 477 478 479 ____________________________________________________________ 480 | ATTRIBUTE TYPE | ATTRIBUTE VALUE | 481 |_____________________________|_____________________________| 482 | Interface Stability | Standard | 483 |_____________________________|_____________________________| 484 485 486 SEE ALSO 487 accept(3SOCKET), accept(3XNET), bind(3SOCKET), bind(3XNET), 488 connect(3SOCKET), connect(3XNET), getpeername(3SOCKET), 489 getpeername(3XNET), getpeerucred(3C), getsockname(3SOCKET), 490 getsockname(3XNET), getsockopt(3SOCKET), getsockopt(3XNET), 491 libsocket(3LIB), listen(3SOCKET), listen(3XNET), 492 recv(3SOCKET), recv(3XNET), recvfrom(3SOCKET), 493 recvfrom(3XNET), recvmsg(3SOCKET), recvmsg(3XNET), 494 send(3SOCKET), send(3XNET), sendmsg(3SOCKET), 495 sendmsg(3XNET), sendto(3SOCKET), sendto(3XNET), 496 setsockopt(3SOCKET), setsockopt(3XNET), shutdown(3SOCKET), 497 shutdown(3XNET), socket(3SOCKET), socket(3XNET), 498 socketpair(3SOCKET) socketpair(3XNET), 499 ucred_get(3C)attributes(5), standards(5) 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 SunOS 5.11 Last change: 03 Aug 2006 8 523 524 525