1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* 31*7c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 32*7c478bd9Sstevel@tonic-gate * The Regents of the University of California 33*7c478bd9Sstevel@tonic-gate * All Rights Reserved 34*7c478bd9Sstevel@tonic-gate * 35*7c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 36*7c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 37*7c478bd9Sstevel@tonic-gate * contributors. 38*7c478bd9Sstevel@tonic-gate */ 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #ifndef _SYS_SOCKET_H 41*7c478bd9Sstevel@tonic-gate #define _SYS_SOCKET_H 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 46*7c478bd9Sstevel@tonic-gate #include <sys/uio.h> 47*7c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h> 48*7c478bd9Sstevel@tonic-gate #include <sys/socket_impl.h> 49*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 50*7c478bd9Sstevel@tonic-gate #ifndef _KERNEL 51*7c478bd9Sstevel@tonic-gate #include <sys/netconfig.h> 52*7c478bd9Sstevel@tonic-gate #endif /* !_KERNEL */ 53*7c478bd9Sstevel@tonic-gate #include <netinet/in.h> 54*7c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 57*7c478bd9Sstevel@tonic-gate extern "C" { 58*7c478bd9Sstevel@tonic-gate #endif 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate #ifndef _SOCKLEN_T 61*7c478bd9Sstevel@tonic-gate #define _SOCKLEN_T 62*7c478bd9Sstevel@tonic-gate 63*7c478bd9Sstevel@tonic-gate /* 64*7c478bd9Sstevel@tonic-gate * The socklen definitions are reproduced in netinet/in.h for the inet6_ 65*7c478bd9Sstevel@tonic-gate * functions. Exposing all of sys/socket.h via netinet/in.h breaks existing 66*7c478bd9Sstevel@tonic-gate * applications and is not required by austin. 67*7c478bd9Sstevel@tonic-gate */ 68*7c478bd9Sstevel@tonic-gate #if defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64) 69*7c478bd9Sstevel@tonic-gate typedef size_t socklen_t; 70*7c478bd9Sstevel@tonic-gate #else 71*7c478bd9Sstevel@tonic-gate typedef uint32_t socklen_t; 72*7c478bd9Sstevel@tonic-gate #endif /* defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64) */ 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate #if defined(_XPG4_2) || defined(_BOOT) 75*7c478bd9Sstevel@tonic-gate typedef socklen_t *_RESTRICT_KYWD Psocklen_t; 76*7c478bd9Sstevel@tonic-gate #else 77*7c478bd9Sstevel@tonic-gate typedef void *_RESTRICT_KYWD Psocklen_t; 78*7c478bd9Sstevel@tonic-gate #endif /* defined(_XPG4_2) || defined(_BOOT) */ 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate #endif /* _SOCKLEN_T */ 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate /* 83*7c478bd9Sstevel@tonic-gate * Definitions related to sockets: types, address families, options. 84*7c478bd9Sstevel@tonic-gate */ 85*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 86*7c478bd9Sstevel@tonic-gate #ifndef NC_TPI_CLTS 87*7c478bd9Sstevel@tonic-gate #define NC_TPI_CLTS 1 /* must agree with netconfig.h */ 88*7c478bd9Sstevel@tonic-gate #define NC_TPI_COTS 2 /* must agree with netconfig.h */ 89*7c478bd9Sstevel@tonic-gate #define NC_TPI_COTS_ORD 3 /* must agree with netconfig.h */ 90*7c478bd9Sstevel@tonic-gate #define NC_TPI_RAW 4 /* must agree with netconfig.h */ 91*7c478bd9Sstevel@tonic-gate #endif /* !NC_TPI_CLTS */ 92*7c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate /* 95*7c478bd9Sstevel@tonic-gate * Types 96*7c478bd9Sstevel@tonic-gate */ 97*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 98*7c478bd9Sstevel@tonic-gate #define SOCK_STREAM NC_TPI_COTS /* stream socket */ 99*7c478bd9Sstevel@tonic-gate #define SOCK_DGRAM NC_TPI_CLTS /* datagram socket */ 100*7c478bd9Sstevel@tonic-gate #define SOCK_RAW NC_TPI_RAW /* raw-protocol interface */ 101*7c478bd9Sstevel@tonic-gate #else 102*7c478bd9Sstevel@tonic-gate #define SOCK_STREAM 2 /* stream socket */ 103*7c478bd9Sstevel@tonic-gate #define SOCK_DGRAM 1 /* datagram socket */ 104*7c478bd9Sstevel@tonic-gate #define SOCK_RAW 4 /* raw-protocol interface */ 105*7c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 106*7c478bd9Sstevel@tonic-gate #define SOCK_RDM 5 /* reliably-delivered message */ 107*7c478bd9Sstevel@tonic-gate #define SOCK_SEQPACKET 6 /* sequenced packet stream */ 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate /* 110*7c478bd9Sstevel@tonic-gate * Option flags per-socket. 111*7c478bd9Sstevel@tonic-gate */ 112*7c478bd9Sstevel@tonic-gate #define SO_DEBUG 0x0001 /* turn on debugging info recording */ 113*7c478bd9Sstevel@tonic-gate #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ 114*7c478bd9Sstevel@tonic-gate #define SO_REUSEADDR 0x0004 /* allow local address reuse */ 115*7c478bd9Sstevel@tonic-gate #define SO_KEEPALIVE 0x0008 /* keep connections alive */ 116*7c478bd9Sstevel@tonic-gate #define SO_DONTROUTE 0x0010 /* just use interface addresses */ 117*7c478bd9Sstevel@tonic-gate #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */ 118*7c478bd9Sstevel@tonic-gate #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ 119*7c478bd9Sstevel@tonic-gate #define SO_LINGER 0x0080 /* linger on close if data present */ 120*7c478bd9Sstevel@tonic-gate #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ 121*7c478bd9Sstevel@tonic-gate #define SO_DGRAM_ERRIND 0x0200 /* Application wants delayed error */ 122*7c478bd9Sstevel@tonic-gate #define SO_RECVUCRED 0x0400 /* Application wants ucred of sender */ 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL 125*7c478bd9Sstevel@tonic-gate #define SO_SND_COPYAVOID 0x0800 /* Internal: use zero-copy */ 126*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate /* 129*7c478bd9Sstevel@tonic-gate * N.B.: The following definition is present only for compatibility 130*7c478bd9Sstevel@tonic-gate * with release 3.0. It will disappear in later releases. 131*7c478bd9Sstevel@tonic-gate */ 132*7c478bd9Sstevel@tonic-gate #define SO_DONTLINGER (~SO_LINGER) /* ~SO_LINGER */ 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate /* 135*7c478bd9Sstevel@tonic-gate * Additional options, not kept in so_options. 136*7c478bd9Sstevel@tonic-gate */ 137*7c478bd9Sstevel@tonic-gate #define SO_SNDBUF 0x1001 /* send buffer size */ 138*7c478bd9Sstevel@tonic-gate #define SO_RCVBUF 0x1002 /* receive buffer size */ 139*7c478bd9Sstevel@tonic-gate #define SO_SNDLOWAT 0x1003 /* send low-water mark */ 140*7c478bd9Sstevel@tonic-gate #define SO_RCVLOWAT 0x1004 /* receive low-water mark */ 141*7c478bd9Sstevel@tonic-gate #define SO_SNDTIMEO 0x1005 /* send timeout */ 142*7c478bd9Sstevel@tonic-gate #define SO_RCVTIMEO 0x1006 /* receive timeout */ 143*7c478bd9Sstevel@tonic-gate #define SO_ERROR 0x1007 /* get error status and clear */ 144*7c478bd9Sstevel@tonic-gate #define SO_TYPE 0x1008 /* get socket type */ 145*7c478bd9Sstevel@tonic-gate #define SO_PROTOTYPE 0x1009 /* get/set protocol type */ 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate /* "Socket"-level control message types: */ 148*7c478bd9Sstevel@tonic-gate #define SCM_RIGHTS 0x1010 /* access rights (array of int) */ 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate #define SO_SECATTR 0x1011 /* socket's security attributes */ 151*7c478bd9Sstevel@tonic-gate #define SCM_UCRED 0x1012 /* sender's ucred */ 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL 154*7c478bd9Sstevel@tonic-gate #define SO_SRCADDR 0x2001 /* Internal: AF_UNIX source address */ 155*7c478bd9Sstevel@tonic-gate #define SO_FILEP 0x2002 /* Internal: AF_UNIX file pointer */ 156*7c478bd9Sstevel@tonic-gate #define SO_UNIX_CLOSE 0x2003 /* Internal: AF_UNIX peer closed */ 157*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL 160*7c478bd9Sstevel@tonic-gate /* 161*7c478bd9Sstevel@tonic-gate * new socket open flags to identify socket and acceptor streams 162*7c478bd9Sstevel@tonic-gate */ 163*7c478bd9Sstevel@tonic-gate #define SO_ACCEPTOR 0x20000 /* acceptor socket */ 164*7c478bd9Sstevel@tonic-gate #define SO_SOCKSTR 0x40000 /* normal socket stream */ 165*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 166*7c478bd9Sstevel@tonic-gate 167*7c478bd9Sstevel@tonic-gate /* 168*7c478bd9Sstevel@tonic-gate * Structure used for manipulating linger option. 169*7c478bd9Sstevel@tonic-gate */ 170*7c478bd9Sstevel@tonic-gate struct linger { 171*7c478bd9Sstevel@tonic-gate int l_onoff; /* option on/off */ 172*7c478bd9Sstevel@tonic-gate int l_linger; /* linger time */ 173*7c478bd9Sstevel@tonic-gate }; 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate /* 176*7c478bd9Sstevel@tonic-gate * Level number for (get/set)sockopt() to apply to socket itself. 177*7c478bd9Sstevel@tonic-gate */ 178*7c478bd9Sstevel@tonic-gate #define SOL_SOCKET 0xffff /* options for socket level */ 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate /* 181*7c478bd9Sstevel@tonic-gate * Address families. 182*7c478bd9Sstevel@tonic-gate */ 183*7c478bd9Sstevel@tonic-gate #define AF_UNSPEC 0 /* unspecified */ 184*7c478bd9Sstevel@tonic-gate #define AF_UNIX 1 /* local to host (pipes, portals) */ 185*7c478bd9Sstevel@tonic-gate #define AF_INET 2 /* internetwork: UDP, TCP, etc. */ 186*7c478bd9Sstevel@tonic-gate #define AF_IMPLINK 3 /* arpanet imp addresses */ 187*7c478bd9Sstevel@tonic-gate #define AF_PUP 4 /* pup protocols: e.g. BSP */ 188*7c478bd9Sstevel@tonic-gate #define AF_CHAOS 5 /* mit CHAOS protocols */ 189*7c478bd9Sstevel@tonic-gate #define AF_NS 6 /* XEROX NS protocols */ 190*7c478bd9Sstevel@tonic-gate #define AF_NBS 7 /* nbs protocols */ 191*7c478bd9Sstevel@tonic-gate #define AF_ECMA 8 /* european computer manufacturers */ 192*7c478bd9Sstevel@tonic-gate #define AF_DATAKIT 9 /* datakit protocols */ 193*7c478bd9Sstevel@tonic-gate #define AF_CCITT 10 /* CCITT protocols, X.25 etc */ 194*7c478bd9Sstevel@tonic-gate #define AF_SNA 11 /* IBM SNA */ 195*7c478bd9Sstevel@tonic-gate #define AF_DECnet 12 /* DECnet */ 196*7c478bd9Sstevel@tonic-gate #define AF_DLI 13 /* Direct data link interface */ 197*7c478bd9Sstevel@tonic-gate #define AF_LAT 14 /* LAT */ 198*7c478bd9Sstevel@tonic-gate #define AF_HYLINK 15 /* NSC Hyperchannel */ 199*7c478bd9Sstevel@tonic-gate #define AF_APPLETALK 16 /* Apple Talk */ 200*7c478bd9Sstevel@tonic-gate #define AF_NIT 17 /* Network Interface Tap */ 201*7c478bd9Sstevel@tonic-gate #define AF_802 18 /* IEEE 802.2, also ISO 8802 */ 202*7c478bd9Sstevel@tonic-gate #define AF_OSI 19 /* umbrella for all families used */ 203*7c478bd9Sstevel@tonic-gate #define AF_X25 20 /* CCITT X.25 in particular */ 204*7c478bd9Sstevel@tonic-gate #define AF_OSINET 21 /* AFI = 47, IDI = 4 */ 205*7c478bd9Sstevel@tonic-gate #define AF_GOSIP 22 /* U.S. Government OSI */ 206*7c478bd9Sstevel@tonic-gate #define AF_IPX 23 /* Novell Internet Protocol */ 207*7c478bd9Sstevel@tonic-gate #define AF_ROUTE 24 /* Internal Routing Protocol */ 208*7c478bd9Sstevel@tonic-gate #define AF_LINK 25 /* Link-layer interface */ 209*7c478bd9Sstevel@tonic-gate #define AF_INET6 26 /* Internet Protocol, Version 6 */ 210*7c478bd9Sstevel@tonic-gate #define AF_KEY 27 /* Security Association DB socket */ 211*7c478bd9Sstevel@tonic-gate #define AF_NCA 28 /* NCA socket */ 212*7c478bd9Sstevel@tonic-gate #define AF_POLICY 29 /* Security Policy DB socket */ 213*7c478bd9Sstevel@tonic-gate 214*7c478bd9Sstevel@tonic-gate #define AF_MAX 29 215*7c478bd9Sstevel@tonic-gate 216*7c478bd9Sstevel@tonic-gate /* 217*7c478bd9Sstevel@tonic-gate * Protocol families, same as address families for now. 218*7c478bd9Sstevel@tonic-gate */ 219*7c478bd9Sstevel@tonic-gate #define PF_UNSPEC AF_UNSPEC 220*7c478bd9Sstevel@tonic-gate #define PF_UNIX AF_UNIX 221*7c478bd9Sstevel@tonic-gate #define PF_INET AF_INET 222*7c478bd9Sstevel@tonic-gate #define PF_IMPLINK AF_IMPLINK 223*7c478bd9Sstevel@tonic-gate #define PF_PUP AF_PUP 224*7c478bd9Sstevel@tonic-gate #define PF_CHAOS AF_CHAOS 225*7c478bd9Sstevel@tonic-gate #define PF_NS AF_NS 226*7c478bd9Sstevel@tonic-gate #define PF_NBS AF_NBS 227*7c478bd9Sstevel@tonic-gate #define PF_ECMA AF_ECMA 228*7c478bd9Sstevel@tonic-gate #define PF_DATAKIT AF_DATAKIT 229*7c478bd9Sstevel@tonic-gate #define PF_CCITT AF_CCITT 230*7c478bd9Sstevel@tonic-gate #define PF_SNA AF_SNA 231*7c478bd9Sstevel@tonic-gate #define PF_DECnet AF_DECnet 232*7c478bd9Sstevel@tonic-gate #define PF_DLI AF_DLI 233*7c478bd9Sstevel@tonic-gate #define PF_LAT AF_LAT 234*7c478bd9Sstevel@tonic-gate #define PF_HYLINK AF_HYLINK 235*7c478bd9Sstevel@tonic-gate #define PF_APPLETALK AF_APPLETALK 236*7c478bd9Sstevel@tonic-gate #define PF_NIT AF_NIT 237*7c478bd9Sstevel@tonic-gate #define PF_802 AF_802 238*7c478bd9Sstevel@tonic-gate #define PF_OSI AF_OSI 239*7c478bd9Sstevel@tonic-gate #define PF_X25 AF_X25 240*7c478bd9Sstevel@tonic-gate #define PF_OSINET AF_OSINET 241*7c478bd9Sstevel@tonic-gate #define PF_GOSIP AF_GOSIP 242*7c478bd9Sstevel@tonic-gate #define PF_IPX AF_IPX 243*7c478bd9Sstevel@tonic-gate #define PF_ROUTE AF_ROUTE 244*7c478bd9Sstevel@tonic-gate #define PF_LINK AF_LINK 245*7c478bd9Sstevel@tonic-gate #define PF_INET6 AF_INET6 246*7c478bd9Sstevel@tonic-gate #define PF_KEY AF_KEY 247*7c478bd9Sstevel@tonic-gate #define PF_NCA AF_NCA 248*7c478bd9Sstevel@tonic-gate #define PF_POLICY AF_POLICY 249*7c478bd9Sstevel@tonic-gate 250*7c478bd9Sstevel@tonic-gate #define PF_MAX AF_MAX 251*7c478bd9Sstevel@tonic-gate 252*7c478bd9Sstevel@tonic-gate /* 253*7c478bd9Sstevel@tonic-gate * Maximum queue length specifiable by listen. 254*7c478bd9Sstevel@tonic-gate */ 255*7c478bd9Sstevel@tonic-gate #define SOMAXCONN 128 256*7c478bd9Sstevel@tonic-gate 257*7c478bd9Sstevel@tonic-gate /* 258*7c478bd9Sstevel@tonic-gate * Message header for recvmsg and sendmsg calls. 259*7c478bd9Sstevel@tonic-gate */ 260*7c478bd9Sstevel@tonic-gate struct msghdr { 261*7c478bd9Sstevel@tonic-gate void *msg_name; /* optional address */ 262*7c478bd9Sstevel@tonic-gate socklen_t msg_namelen; /* size of address */ 263*7c478bd9Sstevel@tonic-gate struct iovec *msg_iov; /* scatter/gather array */ 264*7c478bd9Sstevel@tonic-gate int msg_iovlen; /* # elements in msg_iov */ 265*7c478bd9Sstevel@tonic-gate 266*7c478bd9Sstevel@tonic-gate #if defined(_XPG4_2) || defined(_KERNEL) 267*7c478bd9Sstevel@tonic-gate void *msg_control; /* ancillary data */ 268*7c478bd9Sstevel@tonic-gate socklen_t msg_controllen; /* ancillary data buffer len */ 269*7c478bd9Sstevel@tonic-gate int msg_flags; /* flags on received message */ 270*7c478bd9Sstevel@tonic-gate #else 271*7c478bd9Sstevel@tonic-gate caddr_t msg_accrights; /* access rights sent/received */ 272*7c478bd9Sstevel@tonic-gate int msg_accrightslen; 273*7c478bd9Sstevel@tonic-gate #endif /* defined(_XPG4_2) || defined(_KERNEL) */ 274*7c478bd9Sstevel@tonic-gate }; 275*7c478bd9Sstevel@tonic-gate 276*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) 277*7c478bd9Sstevel@tonic-gate 278*7c478bd9Sstevel@tonic-gate /* 279*7c478bd9Sstevel@tonic-gate * N.B.: we assume that omsghdr and nmsghdr are isomorphic, with 280*7c478bd9Sstevel@tonic-gate * the sole exception that nmsghdr has the additional msg_flags 281*7c478bd9Sstevel@tonic-gate * field at the end. 282*7c478bd9Sstevel@tonic-gate */ 283*7c478bd9Sstevel@tonic-gate struct omsghdr { 284*7c478bd9Sstevel@tonic-gate void *msg_name; /* optional address */ 285*7c478bd9Sstevel@tonic-gate socklen_t msg_namelen; /* size of address */ 286*7c478bd9Sstevel@tonic-gate struct iovec *msg_iov; /* scatter/gather array */ 287*7c478bd9Sstevel@tonic-gate int msg_iovlen; /* # elements in msg_iov */ 288*7c478bd9Sstevel@tonic-gate caddr_t msg_accrights; /* access rights sent/received */ 289*7c478bd9Sstevel@tonic-gate int msg_accrightslen; 290*7c478bd9Sstevel@tonic-gate }; 291*7c478bd9Sstevel@tonic-gate 292*7c478bd9Sstevel@tonic-gate #define nmsghdr msghdr 293*7c478bd9Sstevel@tonic-gate 294*7c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32) 295*7c478bd9Sstevel@tonic-gate 296*7c478bd9Sstevel@tonic-gate struct omsghdr32 { 297*7c478bd9Sstevel@tonic-gate caddr32_t msg_name; /* optional address */ 298*7c478bd9Sstevel@tonic-gate uint32_t msg_namelen; /* size of address */ 299*7c478bd9Sstevel@tonic-gate caddr32_t msg_iov; /* scatter/gather array */ 300*7c478bd9Sstevel@tonic-gate int32_t msg_iovlen; /* # elements in msg_iov */ 301*7c478bd9Sstevel@tonic-gate caddr32_t msg_accrights; /* access rights sent/received */ 302*7c478bd9Sstevel@tonic-gate uint32_t msg_accrightslen; 303*7c478bd9Sstevel@tonic-gate }; 304*7c478bd9Sstevel@tonic-gate 305*7c478bd9Sstevel@tonic-gate struct msghdr32 { 306*7c478bd9Sstevel@tonic-gate caddr32_t msg_name; /* optional address */ 307*7c478bd9Sstevel@tonic-gate uint32_t msg_namelen; /* size of address */ 308*7c478bd9Sstevel@tonic-gate caddr32_t msg_iov; /* scatter/gather array */ 309*7c478bd9Sstevel@tonic-gate int32_t msg_iovlen; /* # elements in msg_iov */ 310*7c478bd9Sstevel@tonic-gate caddr32_t msg_control; /* ancillary data */ 311*7c478bd9Sstevel@tonic-gate uint32_t msg_controllen; /* ancillary data buffer len */ 312*7c478bd9Sstevel@tonic-gate int32_t msg_flags; /* flags on received message */ 313*7c478bd9Sstevel@tonic-gate }; 314*7c478bd9Sstevel@tonic-gate 315*7c478bd9Sstevel@tonic-gate #define nmsghdr32 msghdr32 316*7c478bd9Sstevel@tonic-gate 317*7c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 318*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 319*7c478bd9Sstevel@tonic-gate 320*7c478bd9Sstevel@tonic-gate #define MSG_OOB 0x1 /* process out-of-band data */ 321*7c478bd9Sstevel@tonic-gate #define MSG_PEEK 0x2 /* peek at incoming message */ 322*7c478bd9Sstevel@tonic-gate #define MSG_DONTROUTE 0x4 /* send without using routing tables */ 323*7c478bd9Sstevel@tonic-gate /* Added for XPGv2 compliance */ 324*7c478bd9Sstevel@tonic-gate #define MSG_EOR 0x8 /* Terminates a record */ 325*7c478bd9Sstevel@tonic-gate #define MSG_CTRUNC 0x10 /* Control data truncated */ 326*7c478bd9Sstevel@tonic-gate #define MSG_TRUNC 0x20 /* Normal data truncated */ 327*7c478bd9Sstevel@tonic-gate #define MSG_WAITALL 0x40 /* Wait for complete recv or error */ 328*7c478bd9Sstevel@tonic-gate /* End of XPGv2 compliance */ 329*7c478bd9Sstevel@tonic-gate #define MSG_DONTWAIT 0x80 /* Don't block for this recv */ 330*7c478bd9Sstevel@tonic-gate #define MSG_NOTIFICATION 0x100 /* Notification, not data */ 331*7c478bd9Sstevel@tonic-gate #define MSG_XPG4_2 0x8000 /* Private: XPG4.2 flag */ 332*7c478bd9Sstevel@tonic-gate 333*7c478bd9Sstevel@tonic-gate #define MSG_MAXIOVLEN 16 334*7c478bd9Sstevel@tonic-gate 335*7c478bd9Sstevel@tonic-gate /* Added for XPGv2 compliance */ 336*7c478bd9Sstevel@tonic-gate #define SHUT_RD 0 337*7c478bd9Sstevel@tonic-gate #define SHUT_WR 1 338*7c478bd9Sstevel@tonic-gate #define SHUT_RDWR 2 339*7c478bd9Sstevel@tonic-gate 340*7c478bd9Sstevel@tonic-gate struct cmsghdr { 341*7c478bd9Sstevel@tonic-gate socklen_t cmsg_len; /* data byte count, including hdr */ 342*7c478bd9Sstevel@tonic-gate int cmsg_level; /* originating protocol */ 343*7c478bd9Sstevel@tonic-gate int cmsg_type; /* protocol-specific type */ 344*7c478bd9Sstevel@tonic-gate }; 345*7c478bd9Sstevel@tonic-gate 346*7c478bd9Sstevel@tonic-gate #if defined(_XPG4_2) || defined(_KERNEL) 347*7c478bd9Sstevel@tonic-gate #if defined(__sparc) 348*7c478bd9Sstevel@tonic-gate /* To maintain backward compatibility, alignment needs to be 8 on sparc. */ 349*7c478bd9Sstevel@tonic-gate #define _CMSG_HDR_ALIGNMENT 8 350*7c478bd9Sstevel@tonic-gate #else 351*7c478bd9Sstevel@tonic-gate /* for __i386 (and other future architectures) */ 352*7c478bd9Sstevel@tonic-gate #define _CMSG_HDR_ALIGNMENT 4 353*7c478bd9Sstevel@tonic-gate #endif /* defined(__sparc) */ 354*7c478bd9Sstevel@tonic-gate #endif /* defined(_XPG4_2) || defined(_KERNEL) */ 355*7c478bd9Sstevel@tonic-gate 356*7c478bd9Sstevel@tonic-gate #if defined(_XPG4_2) 357*7c478bd9Sstevel@tonic-gate /* 358*7c478bd9Sstevel@tonic-gate * The cmsg headers (and macros dealing with them) were made available as 359*7c478bd9Sstevel@tonic-gate * part of UNIX95 and hence need to be protected with a _XPG4_2 define. 360*7c478bd9Sstevel@tonic-gate */ 361*7c478bd9Sstevel@tonic-gate #define _CMSG_DATA_ALIGNMENT (sizeof (int)) 362*7c478bd9Sstevel@tonic-gate #define _CMSG_HDR_ALIGN(x) (((uintptr_t)(x) + _CMSG_HDR_ALIGNMENT - 1) & \ 363*7c478bd9Sstevel@tonic-gate ~(_CMSG_HDR_ALIGNMENT - 1)) 364*7c478bd9Sstevel@tonic-gate #define _CMSG_DATA_ALIGN(x) (((uintptr_t)(x) + _CMSG_DATA_ALIGNMENT - 1) & \ 365*7c478bd9Sstevel@tonic-gate ~(_CMSG_DATA_ALIGNMENT - 1)) 366*7c478bd9Sstevel@tonic-gate #define CMSG_DATA(c) \ 367*7c478bd9Sstevel@tonic-gate ((unsigned char *)_CMSG_DATA_ALIGN((struct cmsghdr *)(c) + 1)) 368*7c478bd9Sstevel@tonic-gate 369*7c478bd9Sstevel@tonic-gate #define CMSG_FIRSTHDR(m) \ 370*7c478bd9Sstevel@tonic-gate (((m)->msg_controllen < sizeof (struct cmsghdr)) ? \ 371*7c478bd9Sstevel@tonic-gate (struct cmsghdr *)0 : (struct cmsghdr *)((m)->msg_control)) 372*7c478bd9Sstevel@tonic-gate 373*7c478bd9Sstevel@tonic-gate #define CMSG_NXTHDR(m, c) \ 374*7c478bd9Sstevel@tonic-gate (((c) == 0) ? CMSG_FIRSTHDR(m) : \ 375*7c478bd9Sstevel@tonic-gate ((((uintptr_t)_CMSG_HDR_ALIGN((char *)(c) + \ 376*7c478bd9Sstevel@tonic-gate ((struct cmsghdr *)(c))->cmsg_len) + sizeof (struct cmsghdr)) > \ 377*7c478bd9Sstevel@tonic-gate (((uintptr_t)((struct msghdr *)(m))->msg_control) + \ 378*7c478bd9Sstevel@tonic-gate ((uintptr_t)((struct msghdr *)(m))->msg_controllen))) ? \ 379*7c478bd9Sstevel@tonic-gate ((struct cmsghdr *)0) : \ 380*7c478bd9Sstevel@tonic-gate ((struct cmsghdr *)_CMSG_HDR_ALIGN((char *)(c) + \ 381*7c478bd9Sstevel@tonic-gate ((struct cmsghdr *)(c))->cmsg_len)))) 382*7c478bd9Sstevel@tonic-gate 383*7c478bd9Sstevel@tonic-gate /* Amount of space + padding needed for a message of length l */ 384*7c478bd9Sstevel@tonic-gate #define CMSG_SPACE(l) \ 385*7c478bd9Sstevel@tonic-gate ((unsigned int)_CMSG_HDR_ALIGN(sizeof (struct cmsghdr) + (l))) 386*7c478bd9Sstevel@tonic-gate 387*7c478bd9Sstevel@tonic-gate /* Value to be used in cmsg_len, does not include trailing padding */ 388*7c478bd9Sstevel@tonic-gate #define CMSG_LEN(l) \ 389*7c478bd9Sstevel@tonic-gate ((unsigned int)_CMSG_DATA_ALIGN(sizeof (struct cmsghdr)) + (l)) 390*7c478bd9Sstevel@tonic-gate 391*7c478bd9Sstevel@tonic-gate #endif /* _XPG4_2 */ 392*7c478bd9Sstevel@tonic-gate 393*7c478bd9Sstevel@tonic-gate #ifdef _XPG4_2 394*7c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME 395*7c478bd9Sstevel@tonic-gate #pragma redefine_extname bind __xnet_bind 396*7c478bd9Sstevel@tonic-gate #pragma redefine_extname connect __xnet_connect 397*7c478bd9Sstevel@tonic-gate #pragma redefine_extname recvmsg __xnet_recvmsg 398*7c478bd9Sstevel@tonic-gate #pragma redefine_extname sendmsg __xnet_sendmsg 399*7c478bd9Sstevel@tonic-gate #pragma redefine_extname sendto __xnet_sendto 400*7c478bd9Sstevel@tonic-gate #pragma redefine_extname socket __xnet_socket 401*7c478bd9Sstevel@tonic-gate #pragma redefine_extname socketpair __xnet_socketpair 402*7c478bd9Sstevel@tonic-gate #pragma redefine_extname getsockopt __xnet_getsockopt 403*7c478bd9Sstevel@tonic-gate #else /* __PRAGMA_REDEFINE_EXTNAME */ 404*7c478bd9Sstevel@tonic-gate #define bind __xnet_bind 405*7c478bd9Sstevel@tonic-gate #define connect __xnet_connect 406*7c478bd9Sstevel@tonic-gate #define recvmsg __xnet_recvmsg 407*7c478bd9Sstevel@tonic-gate #define sendmsg __xnet_sendmsg 408*7c478bd9Sstevel@tonic-gate #define sendto __xnet_sendto 409*7c478bd9Sstevel@tonic-gate #define socket __xnet_socket 410*7c478bd9Sstevel@tonic-gate #define socketpair __xnet_socketpair 411*7c478bd9Sstevel@tonic-gate #define getsockopt __xnet_getsockopt 412*7c478bd9Sstevel@tonic-gate #endif /* __PRAGMA_REDEFINE_EXTNAME */ 413*7c478bd9Sstevel@tonic-gate 414*7c478bd9Sstevel@tonic-gate #endif /* _XPG4_2 */ 415*7c478bd9Sstevel@tonic-gate 416*7c478bd9Sstevel@tonic-gate #if defined(_XPG4_2) && !defined(_XPG5) 417*7c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME 418*7c478bd9Sstevel@tonic-gate #pragma redefine_extname listen __xnet_listen 419*7c478bd9Sstevel@tonic-gate #else /* __PRAGMA_REDEFINE_EXTNAME */ 420*7c478bd9Sstevel@tonic-gate #define listen __xnet_listen 421*7c478bd9Sstevel@tonic-gate #endif /* __PRAGMA_REDEFINE_EXTNAME */ 422*7c478bd9Sstevel@tonic-gate #endif /* (_XPG4_2) && !defined(_XPG5) */ 423*7c478bd9Sstevel@tonic-gate 424*7c478bd9Sstevel@tonic-gate #if !defined(_KERNEL) || defined(_BOOT) 425*7c478bd9Sstevel@tonic-gate #ifdef __STDC__ 426*7c478bd9Sstevel@tonic-gate extern int accept(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t); 427*7c478bd9Sstevel@tonic-gate extern int bind(int, const struct sockaddr *, socklen_t); 428*7c478bd9Sstevel@tonic-gate extern int connect(int, const struct sockaddr *, socklen_t); 429*7c478bd9Sstevel@tonic-gate extern int getpeername(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t); 430*7c478bd9Sstevel@tonic-gate extern int getsockname(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t); 431*7c478bd9Sstevel@tonic-gate extern int getsockopt(int, int, int, void *_RESTRICT_KYWD, Psocklen_t); 432*7c478bd9Sstevel@tonic-gate extern int listen(int, int); /* XXX - fixme??? where do I go */ 433*7c478bd9Sstevel@tonic-gate extern int socketpair(int, int, int, int *); 434*7c478bd9Sstevel@tonic-gate extern ssize_t recv(int, void *, size_t, int); 435*7c478bd9Sstevel@tonic-gate extern ssize_t recvfrom(int, void *_RESTRICT_KYWD, size_t, int, 436*7c478bd9Sstevel@tonic-gate struct sockaddr *_RESTRICT_KYWD, Psocklen_t); 437*7c478bd9Sstevel@tonic-gate extern ssize_t recvmsg(int, struct msghdr *, int); 438*7c478bd9Sstevel@tonic-gate extern ssize_t send(int, const void *, size_t, int); 439*7c478bd9Sstevel@tonic-gate extern ssize_t sendmsg(int, const struct msghdr *, int); 440*7c478bd9Sstevel@tonic-gate extern ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *, 441*7c478bd9Sstevel@tonic-gate socklen_t); 442*7c478bd9Sstevel@tonic-gate extern int setsockopt(int, int, int, const void *, socklen_t); 443*7c478bd9Sstevel@tonic-gate extern int shutdown(int, int); 444*7c478bd9Sstevel@tonic-gate extern int socket(int, int, int); 445*7c478bd9Sstevel@tonic-gate 446*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) 447*7c478bd9Sstevel@tonic-gate extern int sockatmark(int); 448*7c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */ 449*7c478bd9Sstevel@tonic-gate #else /* __STDC__ */ 450*7c478bd9Sstevel@tonic-gate extern int accept(); 451*7c478bd9Sstevel@tonic-gate extern int bind(); 452*7c478bd9Sstevel@tonic-gate extern int connect(); 453*7c478bd9Sstevel@tonic-gate extern int getpeername(); 454*7c478bd9Sstevel@tonic-gate extern int getsockname(); 455*7c478bd9Sstevel@tonic-gate extern int getsockopt(); 456*7c478bd9Sstevel@tonic-gate extern int listen(); 457*7c478bd9Sstevel@tonic-gate extern int recv(); 458*7c478bd9Sstevel@tonic-gate extern int recvfrom(); 459*7c478bd9Sstevel@tonic-gate extern int send(); 460*7c478bd9Sstevel@tonic-gate extern int sendto(); 461*7c478bd9Sstevel@tonic-gate extern int setsockopt(); 462*7c478bd9Sstevel@tonic-gate extern int sockatmark(); 463*7c478bd9Sstevel@tonic-gate extern int socket(); 464*7c478bd9Sstevel@tonic-gate extern int recvmsg(); 465*7c478bd9Sstevel@tonic-gate extern int sendmsg(); 466*7c478bd9Sstevel@tonic-gate extern int shutdown(); 467*7c478bd9Sstevel@tonic-gate extern int socketpair(); 468*7c478bd9Sstevel@tonic-gate #endif /* __STDC__ */ 469*7c478bd9Sstevel@tonic-gate #endif /* !defined(_KERNEL) || defined(_BOOT) */ 470*7c478bd9Sstevel@tonic-gate 471*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 472*7c478bd9Sstevel@tonic-gate } 473*7c478bd9Sstevel@tonic-gate #endif 474*7c478bd9Sstevel@tonic-gate 475*7c478bd9Sstevel@tonic-gate #endif /* _SYS_SOCKET_H */ 476