1139825Simp/*- 21541Srgrimes * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 291541Srgrimes * @(#)socket.h 8.4 (Berkeley) 2/21/94 3050477Speter * $FreeBSD: stable/11/sys/sys/socket.h 338617 2018-09-12 18:52:18Z sobomax $ 311541Srgrimes */ 321541Srgrimes 331541Srgrimes#ifndef _SYS_SOCKET_H_ 341541Srgrimes#define _SYS_SOCKET_H_ 351541Srgrimes 36104983Smike#include <sys/cdefs.h> 3795099Smike#include <sys/_types.h> 38108366Sphk#include <sys/_iovec.h> 39196994Sphk#include <machine/_align.h> 4068498Sasmodai 411541Srgrimes/* 421541Srgrimes * Definitions related to sockets: types, address families, options. 431541Srgrimes */ 441541Srgrimes 451541Srgrimes/* 4653678Sphk * Data types. 4753678Sphk */ 48104983Smike#if __BSD_VISIBLE 49104983Smike#ifndef _GID_T_DECLARED 50104983Smiketypedef __gid_t gid_t; 51104983Smike#define _GID_T_DECLARED 52104983Smike#endif 53104983Smike 54104983Smike#ifndef _OFF_T_DECLARED 55104983Smiketypedef __off_t off_t; 56104983Smike#define _OFF_T_DECLARED 57104983Smike#endif 58104983Smike 59104983Smike#ifndef _PID_T_DECLARED 60104983Smiketypedef __pid_t pid_t; 61104983Smike#define _PID_T_DECLARED 62104983Smike#endif 63104983Smike#endif 64104983Smike 65102227Smike#ifndef _SA_FAMILY_T_DECLARED 66102227Smiketypedef __sa_family_t sa_family_t; 67102227Smike#define _SA_FAMILY_T_DECLARED 6895099Smike#endif 6995099Smike 70102227Smike#ifndef _SOCKLEN_T_DECLARED 71102227Smiketypedef __socklen_t socklen_t; 72102227Smike#define _SOCKLEN_T_DECLARED 7372510Sume#endif 7453678Sphk 75104983Smike#ifndef _SSIZE_T_DECLARED 76104983Smiketypedef __ssize_t ssize_t; 77104983Smike#define _SSIZE_T_DECLARED 78104983Smike#endif 79104983Smike 80104983Smike#if __BSD_VISIBLE 81104983Smike#ifndef _UID_T_DECLARED 82104983Smiketypedef __uid_t uid_t; 83104983Smike#define _UID_T_DECLARED 84104983Smike#endif 85104983Smike#endif 86104983Smike 87260804Sadrian#ifndef _UINT32_T_DECLARED 88260804Sadriantypedef __uint32_t uint32_t; 89260804Sadrian#define _UINT32_T_DECLARED 90260804Sadrian#endif 91260804Sadrian 92260804Sadrian#ifndef _UINTPTR_T_DECLARED 93260804Sadriantypedef __uintptr_t uintptr_t; 94260804Sadrian#define _UINTPTR_T_DECLARED 95260804Sadrian#endif 96260804Sadrian 9753678Sphk/* 981541Srgrimes * Types 991541Srgrimes */ 1001541Srgrimes#define SOCK_STREAM 1 /* stream socket */ 1011541Srgrimes#define SOCK_DGRAM 2 /* datagram socket */ 1021541Srgrimes#define SOCK_RAW 3 /* raw-protocol interface */ 103104983Smike#if __BSD_VISIBLE 1041541Srgrimes#define SOCK_RDM 4 /* reliably-delivered message */ 105104983Smike#endif 1061541Srgrimes#define SOCK_SEQPACKET 5 /* sequenced packet stream */ 1071541Srgrimes 108248534Sjilles#if __BSD_VISIBLE 1091541Srgrimes/* 110248534Sjilles * Creation flags, OR'ed into socket() and socketpair() type argument. 111248534Sjilles */ 112248534Sjilles#define SOCK_CLOEXEC 0x10000000 113248534Sjilles#define SOCK_NONBLOCK 0x20000000 114248534Sjilles#endif 115248534Sjilles 116248534Sjilles/* 1171541Srgrimes * Option flags per-socket. 1181541Srgrimes */ 1191541Srgrimes#define SO_DEBUG 0x0001 /* turn on debugging info recording */ 1201541Srgrimes#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ 1211541Srgrimes#define SO_REUSEADDR 0x0004 /* allow local address reuse */ 1221541Srgrimes#define SO_KEEPALIVE 0x0008 /* keep connections alive */ 1231541Srgrimes#define SO_DONTROUTE 0x0010 /* just use interface addresses */ 1241541Srgrimes#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */ 125104983Smike#if __BSD_VISIBLE 1261541Srgrimes#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ 127104983Smike#endif 1281541Srgrimes#define SO_LINGER 0x0080 /* linger on close if data present */ 1291541Srgrimes#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ 130104983Smike#if __BSD_VISIBLE 1311541Srgrimes#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */ 13215701Swollman#define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */ 13398499Salfred#define SO_NOSIGPIPE 0x0800 /* no SIGPIPE from EPIPE */ 13461837Salfred#define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */ 135125264Sphk#define SO_BINTIME 0x2000 /* timestamp received dgram traffic */ 136104983Smike#endif 137174560Skmacy#define SO_NO_OFFLOAD 0x4000 /* socket cannot be offloaded */ 138174560Skmacy#define SO_NO_DDP 0x8000 /* disable direct data placement */ 1391541Srgrimes 1401541Srgrimes/* 1411541Srgrimes * Additional options, not kept in so_options. 1421541Srgrimes */ 14398212Srwatson#define SO_SNDBUF 0x1001 /* send buffer size */ 14498212Srwatson#define SO_RCVBUF 0x1002 /* receive buffer size */ 14598212Srwatson#define SO_SNDLOWAT 0x1003 /* send low-water mark */ 14698212Srwatson#define SO_RCVLOWAT 0x1004 /* receive low-water mark */ 14798212Srwatson#define SO_SNDTIMEO 0x1005 /* send timeout */ 14898212Srwatson#define SO_RCVTIMEO 0x1006 /* receive timeout */ 1491541Srgrimes#define SO_ERROR 0x1007 /* get error status and clear */ 1501541Srgrimes#define SO_TYPE 0x1008 /* get socket type */ 151104983Smike#if __BSD_VISIBLE 15298213Srwatson#define SO_LABEL 0x1009 /* socket's MAC label */ 15398213Srwatson#define SO_PEERLABEL 0x1010 /* socket's peer's MAC label */ 154150302Srwatson#define SO_LISTENQLIMIT 0x1011 /* socket's backlog limit */ 155150302Srwatson#define SO_LISTENQLEN 0x1012 /* socket's complete queue length */ 156150302Srwatson#define SO_LISTENINCQLEN 0x1013 /* socket's incomplete queue length */ 157178888Sjulian#define SO_SETFIB 0x1014 /* use this FIB to route */ 158215178Sluigi#define SO_USER_COOKIE 0x1015 /* user cookie (dummynet etc.) */ 159232179Skib#define SO_PROTOCOL 0x1016 /* get socket protocol (Linux name) */ 160232179Skib#define SO_PROTOTYPE SO_PROTOCOL /* alias for SO_PROTOCOL (SunOS name) */ 161338617Ssobomax#define SO_TS_CLOCK 0x1017 /* clock type used for SO_TIMESTAMP */ 162104983Smike#endif 1631541Srgrimes 164338617Ssobomax#if __BSD_VISIBLE 165338617Ssobomax#define SO_TS_REALTIME_MICRO 0 /* microsecond resolution, realtime */ 166338617Ssobomax#define SO_TS_BINTIME 1 /* sub-nanosecond resolution, realtime */ 167338617Ssobomax#define SO_TS_REALTIME 2 /* nanosecond resolution, realtime */ 168338617Ssobomax#define SO_TS_MONOTONIC 3 /* nanosecond resolution, monotonic */ 169338617Ssobomax#define SO_TS_DEFAULT SO_TS_REALTIME_MICRO 170338617Ssobomax#define SO_TS_CLOCK_MAX SO_TS_MONOTONIC 171338617Ssobomax#endif 172338617Ssobomax 1731541Srgrimes/* 174246210Sjhb * Space reserved for new socket options added by third-party vendors. 175246210Sjhb * This range applies to all socket option levels. New socket options 176246210Sjhb * in FreeBSD should always use an option value less than SO_VENDOR. 177246210Sjhb */ 178246210Sjhb#if __BSD_VISIBLE 179246210Sjhb#define SO_VENDOR 0x80000000 180246210Sjhb#endif 181246210Sjhb 182246210Sjhb/* 1831541Srgrimes * Structure used for manipulating linger option. 1841541Srgrimes */ 18583045Sobrienstruct linger { 1861541Srgrimes int l_onoff; /* option on/off */ 1871541Srgrimes int l_linger; /* linger time */ 1881541Srgrimes}; 1891541Srgrimes 190104983Smike#if __BSD_VISIBLE 19183045Sobrienstruct accept_filter_arg { 19261837Salfred char af_name[16]; 19361837Salfred char af_arg[256-16]; 19461837Salfred}; 195104983Smike#endif 19661837Salfred 1971541Srgrimes/* 1981541Srgrimes * Level number for (get/set)sockopt() to apply to socket itself. 1991541Srgrimes */ 2001541Srgrimes#define SOL_SOCKET 0xffff /* options for socket level */ 2011541Srgrimes 2021541Srgrimes/* 2031541Srgrimes * Address families. 2041541Srgrimes */ 2051541Srgrimes#define AF_UNSPEC 0 /* unspecified */ 206104983Smike#if __BSD_VISIBLE 207106847Smike#define AF_LOCAL AF_UNIX /* local to host (pipes, portals) */ 208104983Smike#endif 209106847Smike#define AF_UNIX 1 /* standardized name for AF_LOCAL */ 2101541Srgrimes#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ 211104983Smike#if __BSD_VISIBLE 2121541Srgrimes#define AF_IMPLINK 3 /* arpanet imp addresses */ 2131541Srgrimes#define AF_PUP 4 /* pup protocols: e.g. BSP */ 2141541Srgrimes#define AF_CHAOS 5 /* mit CHAOS protocols */ 215111926Speter#define AF_NETBIOS 6 /* SMB protocols */ 2161541Srgrimes#define AF_ISO 7 /* ISO protocols */ 2171541Srgrimes#define AF_OSI AF_ISO 21813765Smpp#define AF_ECMA 8 /* European computer manufacturers */ 2191541Srgrimes#define AF_DATAKIT 9 /* datakit protocols */ 2201541Srgrimes#define AF_CCITT 10 /* CCITT protocols, X.25 etc */ 2211541Srgrimes#define AF_SNA 11 /* IBM SNA */ 2221541Srgrimes#define AF_DECnet 12 /* DECnet */ 2231541Srgrimes#define AF_DLI 13 /* DEC Direct data link interface */ 2241541Srgrimes#define AF_LAT 14 /* LAT */ 2251541Srgrimes#define AF_HYLINK 15 /* NSC Hyperchannel */ 2261541Srgrimes#define AF_APPLETALK 16 /* Apple Talk */ 2271541Srgrimes#define AF_ROUTE 17 /* Internal Routing Protocol */ 2281541Srgrimes#define AF_LINK 18 /* Link layer interface */ 2291541Srgrimes#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */ 2301541Srgrimes#define AF_COIP 20 /* connection-oriented IP, aka ST II */ 2311541Srgrimes#define AF_CNT 21 /* Computer Network Technology */ 2321541Srgrimes#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */ 2331541Srgrimes#define AF_IPX 23 /* Novell Internet Protocol */ 2341541Srgrimes#define AF_SIP 24 /* Simple Internet Protocol */ 2355413Sse#define pseudo_AF_PIP 25 /* Help Identify PIP packets */ 2365413Sse#define AF_ISDN 26 /* Integrated Services Digital Network*/ 2375413Sse#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */ 23816368Swollman#define pseudo_AF_KEY 27 /* Internal key-management function */ 239104983Smike#endif 24017938Speter#define AF_INET6 28 /* IPv6 */ 241104983Smike#if __BSD_VISIBLE 24225609Skjc#define AF_NATM 29 /* native ATM access */ 24339271Sphk#define AF_ATM 30 /* ATM */ 24452248Smsmith#define pseudo_AF_HDRCMPLT 31 /* Used by BPF to not rewrite headers 24552248Smsmith * in interface output routine 24652248Smsmith */ 24752424Sjulian#define AF_NETGRAPH 32 /* Netgraph sockets */ 24875847Sgrog#define AF_SLOW 33 /* 802.3ad slow protocol */ 24975847Sgrog#define AF_SCLUSTER 34 /* Sitara cluster protocol */ 250126937Smdodd#define AF_ARP 35 251129079Semax#define AF_BLUETOOTH 36 /* Bluetooth sockets */ 252160690Ssam#define AF_IEEE80211 37 /* IEEE 802.11 protocol */ 253254122Sjeff#define AF_INET_SDP 40 /* OFED Socket Direct Protocol ipv4 */ 254254122Sjeff#define AF_INET6_SDP 42 /* OFED Socket Direct Protocol ipv6 */ 255254122Sjeff#define AF_MAX 42 256172217Salfred/* 257172217Salfred * When allocating a new AF_ constant, please only allocate 258172217Salfred * even numbered constants for FreeBSD until 134 as odd numbered AF_ 259172217Salfred * constants 39-133 are now reserved for vendors. 260172217Salfred */ 261172217Salfred#define AF_VENDOR00 39 262172217Salfred#define AF_VENDOR01 41 263172217Salfred#define AF_VENDOR02 43 264172217Salfred#define AF_VENDOR03 45 265172217Salfred#define AF_VENDOR04 47 266172217Salfred#define AF_VENDOR05 49 267172217Salfred#define AF_VENDOR06 51 268172217Salfred#define AF_VENDOR07 53 269172217Salfred#define AF_VENDOR08 55 270172217Salfred#define AF_VENDOR09 57 271172217Salfred#define AF_VENDOR10 59 272172217Salfred#define AF_VENDOR11 61 273172217Salfred#define AF_VENDOR12 63 274172217Salfred#define AF_VENDOR13 65 275172217Salfred#define AF_VENDOR14 67 276172217Salfred#define AF_VENDOR15 69 277172217Salfred#define AF_VENDOR16 71 278172217Salfred#define AF_VENDOR17 73 279172217Salfred#define AF_VENDOR18 75 280172217Salfred#define AF_VENDOR19 77 281172217Salfred#define AF_VENDOR20 79 282172217Salfred#define AF_VENDOR21 81 283172217Salfred#define AF_VENDOR22 83 284172217Salfred#define AF_VENDOR23 85 285172217Salfred#define AF_VENDOR24 87 286172217Salfred#define AF_VENDOR25 89 287172217Salfred#define AF_VENDOR26 91 288172217Salfred#define AF_VENDOR27 93 289172217Salfred#define AF_VENDOR28 95 290172217Salfred#define AF_VENDOR29 97 291172217Salfred#define AF_VENDOR30 99 292172217Salfred#define AF_VENDOR31 101 293172217Salfred#define AF_VENDOR32 103 294172217Salfred#define AF_VENDOR33 105 295172217Salfred#define AF_VENDOR34 107 296172217Salfred#define AF_VENDOR35 109 297172217Salfred#define AF_VENDOR36 111 298172217Salfred#define AF_VENDOR37 113 299172217Salfred#define AF_VENDOR38 115 300172217Salfred#define AF_VENDOR39 117 301172217Salfred#define AF_VENDOR40 119 302172217Salfred#define AF_VENDOR41 121 303172217Salfred#define AF_VENDOR42 123 304172217Salfred#define AF_VENDOR43 125 305172217Salfred#define AF_VENDOR44 127 306172217Salfred#define AF_VENDOR45 129 307172217Salfred#define AF_VENDOR46 131 308172217Salfred#define AF_VENDOR47 133 309104983Smike#endif 3101541Srgrimes 3111541Srgrimes/* 3121541Srgrimes * Structure used by kernel to store most 3131541Srgrimes * addresses. 3141541Srgrimes */ 3151541Srgrimesstruct sockaddr { 316104983Smike unsigned char sa_len; /* total length */ 31753678Sphk sa_family_t sa_family; /* address family */ 31853678Sphk char sa_data[14]; /* actually longer; address value */ 3191541Srgrimes}; 320104983Smike#if __BSD_VISIBLE 32128270Swollman#define SOCK_MAXADDRLEN 255 /* longest possible addresses */ 3221541Srgrimes 3231541Srgrimes/* 3241541Srgrimes * Structure used by kernel to pass protocol 3251541Srgrimes * information in raw sockets. 3261541Srgrimes */ 3271541Srgrimesstruct sockproto { 328104983Smike unsigned short sp_family; /* address family */ 329104983Smike unsigned short sp_protocol; /* protocol */ 3301541Srgrimes}; 331104983Smike#endif 3321541Srgrimes 333196967Sphk#include <sys/_sockaddr_storage.h> 33452904Sshin 335104983Smike#if __BSD_VISIBLE 33652904Sshin/* 3371541Srgrimes * Protocol families, same as address families for now. 3381541Srgrimes */ 3391541Srgrimes#define PF_UNSPEC AF_UNSPEC 3401541Srgrimes#define PF_LOCAL AF_LOCAL 3411541Srgrimes#define PF_UNIX PF_LOCAL /* backward compatibility */ 3421541Srgrimes#define PF_INET AF_INET 3431541Srgrimes#define PF_IMPLINK AF_IMPLINK 3441541Srgrimes#define PF_PUP AF_PUP 3451541Srgrimes#define PF_CHAOS AF_CHAOS 346111926Speter#define PF_NETBIOS AF_NETBIOS 3471541Srgrimes#define PF_ISO AF_ISO 3481541Srgrimes#define PF_OSI AF_ISO 3491541Srgrimes#define PF_ECMA AF_ECMA 3501541Srgrimes#define PF_DATAKIT AF_DATAKIT 3511541Srgrimes#define PF_CCITT AF_CCITT 3521541Srgrimes#define PF_SNA AF_SNA 3531541Srgrimes#define PF_DECnet AF_DECnet 3541541Srgrimes#define PF_DLI AF_DLI 3551541Srgrimes#define PF_LAT AF_LAT 3561541Srgrimes#define PF_HYLINK AF_HYLINK 3571541Srgrimes#define PF_APPLETALK AF_APPLETALK 3581541Srgrimes#define PF_ROUTE AF_ROUTE 3591541Srgrimes#define PF_LINK AF_LINK 3601541Srgrimes#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ 3611541Srgrimes#define PF_COIP AF_COIP 3621541Srgrimes#define PF_CNT AF_CNT 3631541Srgrimes#define PF_SIP AF_SIP 364111926Speter#define PF_IPX AF_IPX 36517603Sjdp#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */ 3661541Srgrimes#define PF_PIP pseudo_AF_PIP 3675413Sse#define PF_ISDN AF_ISDN 36816480Swollman#define PF_KEY pseudo_AF_KEY 36917938Speter#define PF_INET6 AF_INET6 37025609Skjc#define PF_NATM AF_NATM 37139271Sphk#define PF_ATM AF_ATM 37252419Sjulian#define PF_NETGRAPH AF_NETGRAPH 37375847Sgrog#define PF_SLOW AF_SLOW 37475847Sgrog#define PF_SCLUSTER AF_SCLUSTER 375126937Smdodd#define PF_ARP AF_ARP 376129079Semax#define PF_BLUETOOTH AF_BLUETOOTH 377251673Skevlo#define PF_IEEE80211 AF_IEEE80211 378254122Sjeff#define PF_INET_SDP AF_INET_SDP 379254122Sjeff#define PF_INET6_SDP AF_INET6_SDP 3801541Srgrimes 3811541Srgrimes#define PF_MAX AF_MAX 3821541Srgrimes 3831541Srgrimes/* 3841541Srgrimes * Definitions for network related sysctl, CTL_NET. 3851541Srgrimes * 3861541Srgrimes * Second level is protocol family. 3871541Srgrimes * Third level is protocol number. 3881541Srgrimes * 389262489Sjhb * Further levels are defined by the individual families. 3901541Srgrimes */ 3911541Srgrimes 3921541Srgrimes/* 3931541Srgrimes * PF_ROUTE - Routing table 3941541Srgrimes * 3951541Srgrimes * Three additional levels are defined: 3961541Srgrimes * Fourth: address family, 0 is wildcard 3971541Srgrimes * Fifth: type of info, defined below 3981541Srgrimes * Sixth: flag(s) to mask with for NET_RT_FLAGS 3991541Srgrimes */ 4001541Srgrimes#define NET_RT_DUMP 1 /* dump; may limit to a.f. */ 4011541Srgrimes#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */ 4021541Srgrimes#define NET_RT_IFLIST 3 /* survey interface list */ 403122685Sbms#define NET_RT_IFMALIST 4 /* return multicast address list */ 404231505Sbz#define NET_RT_IFLISTL 5 /* Survey interface list, using 'l'en 405231505Sbz * versions of msghdr structs. */ 406104983Smike#endif /* __BSD_VISIBLE */ 4071541Srgrimes 4081541Srgrimes/* 4091541Srgrimes * Maximum queue length specifiable by listen. 4101541Srgrimes */ 41113258Sdg#define SOMAXCONN 128 4121541Srgrimes 4131541Srgrimes/* 4141541Srgrimes * Message header for recvmsg and sendmsg calls. 4151541Srgrimes * Used value-result for recvmsg, value only for sendmsg. 4161541Srgrimes */ 4171541Srgrimesstruct msghdr { 41853678Sphk void *msg_name; /* optional address */ 41953678Sphk socklen_t msg_namelen; /* size of address */ 42053678Sphk struct iovec *msg_iov; /* scatter/gather array */ 42153678Sphk int msg_iovlen; /* # elements in msg_iov */ 42253678Sphk void *msg_control; /* ancillary data, see below */ 42353678Sphk socklen_t msg_controllen; /* ancillary data buffer len */ 42453678Sphk int msg_flags; /* flags on received message */ 4251541Srgrimes}; 4261541Srgrimes 4271541Srgrimes#define MSG_OOB 0x1 /* process out-of-band data */ 4281541Srgrimes#define MSG_PEEK 0x2 /* peek at incoming message */ 4291541Srgrimes#define MSG_DONTROUTE 0x4 /* send without using routing tables */ 4301541Srgrimes#define MSG_EOR 0x8 /* data completes record */ 4311541Srgrimes#define MSG_TRUNC 0x10 /* data discarded before delivery */ 4321541Srgrimes#define MSG_CTRUNC 0x20 /* control data lost before delivery */ 4331541Srgrimes#define MSG_WAITALL 0x40 /* wait for full request or error */ 434248932Sjilles#if __POSIX_VISIBLE >= 200809 435248932Sjilles#define MSG_NOSIGNAL 0x20000 /* do not generate SIGPIPE on EOF */ 436248932Sjilles#endif 437104983Smike#if __BSD_VISIBLE 4381541Srgrimes#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */ 4396223Swollman#define MSG_EOF 0x100 /* data completes connection */ 440248932Sjilles#define MSG_NOTIFICATION 0x2000 /* SCTP notification */ 441129911Struckman#define MSG_NBIO 0x4000 /* FIONBIO mode, used by fifofs */ 442129929Struckman#define MSG_COMPAT 0x8000 /* used in sendit() */ 443248932Sjilles#define MSG_CMSG_CLOEXEC 0x40000 /* make received fds close-on-exec */ 444295039Skib#define MSG_WAITFORONE 0x80000 /* for recvmmsg() */ 445104983Smike#endif 446138206Sps#ifdef _KERNEL 447138206Sps#define MSG_SOCALLBCK 0x10000 /* for use by socket callbacks - soreceive (TCP) */ 448313567Sjhb#define MSG_MORETOCOME 0x100000 /* additional data pending */ 449138206Sps#endif 4501541Srgrimes 4511541Srgrimes/* 4521541Srgrimes * Header for ancillary data objects in msg_control buffer. 4531541Srgrimes * Used for additional information with/about a datagram 4541541Srgrimes * not expressible by flags. The format is a sequence 4551541Srgrimes * of message elements headed by cmsghdr structures. 4561541Srgrimes */ 4571541Srgrimesstruct cmsghdr { 45853678Sphk socklen_t cmsg_len; /* data byte count, including hdr */ 45953678Sphk int cmsg_level; /* originating protocol */ 46053678Sphk int cmsg_type; /* protocol-specific type */ 4611541Srgrimes/* followed by u_char cmsg_data[]; */ 4621541Srgrimes}; 4631541Srgrimes 464104983Smike#if __BSD_VISIBLE 46524083Swpaul/* 46624083Swpaul * While we may have more groups than this, the cmsgcred struct must 467201955Sbrooks * be able to fit in an mbuf and we have historically supported a 468201955Sbrooks * maximum of 16 groups. 46924083Swpaul*/ 47024083Swpaul#define CMGROUP_MAX 16 47124083Swpaul 47224083Swpaul/* 47324083Swpaul * Credentials structure, used to verify the identity of a peer 47424083Swpaul * process that has sent us a message. This is allocated by the 47524083Swpaul * peer process but filled in by the kernel. This prevents the 47624083Swpaul * peer from lying about its identity. (Note that cmcred_groups[0] 47724083Swpaul * is the effective GID.) 47824083Swpaul */ 47924083Swpaulstruct cmsgcred { 48024083Swpaul pid_t cmcred_pid; /* PID of sending process */ 48124083Swpaul uid_t cmcred_uid; /* real UID of sending process */ 48224083Swpaul uid_t cmcred_euid; /* effective UID of sending process */ 48324083Swpaul gid_t cmcred_gid; /* real GID of sending process */ 48424083Swpaul short cmcred_ngroups; /* number or groups */ 48524083Swpaul gid_t cmcred_groups[CMGROUP_MAX]; /* groups */ 48624083Swpaul}; 487144978Smdodd 488144978Smdodd/* 489144978Smdodd * Socket credentials. 490144978Smdodd */ 491144978Smdoddstruct sockcred { 492144978Smdodd uid_t sc_uid; /* real user id */ 493144978Smdodd uid_t sc_euid; /* effective user id */ 494144978Smdodd gid_t sc_gid; /* real group id */ 495144978Smdodd gid_t sc_egid; /* effective group id */ 496144978Smdodd int sc_ngroups; /* number of supplemental groups */ 497144978Smdodd gid_t sc_groups[1]; /* variable length */ 498144978Smdodd}; 499144978Smdodd 500144978Smdodd/* 501144978Smdodd * Compute size of a sockcred structure with groups. 502144978Smdodd */ 503144978Smdodd#define SOCKCREDSIZE(ngrps) \ 504144978Smdodd (sizeof(struct sockcred) + (sizeof(gid_t) * ((ngrps) - 1))) 505144978Smdodd 506104983Smike#endif /* __BSD_VISIBLE */ 50724083Swpaul 5081541Srgrimes/* given pointer to struct cmsghdr, return pointer to data */ 509104983Smike#define CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \ 51078137Sume _ALIGN(sizeof(struct cmsghdr))) 5111541Srgrimes 5121541Srgrimes/* given pointer to struct cmsghdr, return pointer to next cmsghdr */ 5131541Srgrimes#define CMSG_NXTHDR(mhdr, cmsg) \ 514301038Sed ((char *)(cmsg) == (char *)0 ? CMSG_FIRSTHDR(mhdr) : \ 515168867Smtm ((char *)(cmsg) + _ALIGN(((struct cmsghdr *)(cmsg))->cmsg_len) + \ 51678137Sume _ALIGN(sizeof(struct cmsghdr)) > \ 517104983Smike (char *)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \ 518132258Sharti (struct cmsghdr *)0 : \ 519220742Sjilles (struct cmsghdr *)(void *)((char *)(cmsg) + \ 520168867Smtm _ALIGN(((struct cmsghdr *)(cmsg))->cmsg_len))) 5211541Srgrimes 522133478Sandre/* 523133478Sandre * RFC 2292 requires to check msg_controllen, in case that the kernel returns 524133478Sandre * an empty list for some reasons. 525133478Sandre */ 526133478Sandre#define CMSG_FIRSTHDR(mhdr) \ 527133478Sandre ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \ 528133478Sandre (struct cmsghdr *)(mhdr)->msg_control : \ 529301038Sed (struct cmsghdr *)0) 5301541Srgrimes 531104983Smike#if __BSD_VISIBLE 53266255Sasmodai/* RFC 2292 additions */ 53378137Sume#define CMSG_SPACE(l) (_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(l)) 53478137Sume#define CMSG_LEN(l) (_ALIGN(sizeof(struct cmsghdr)) + (l)) 535104983Smike#endif 53652904Sshin 53778137Sume#ifdef _KERNEL 53878137Sume#define CMSG_ALIGN(n) _ALIGN(n) 53978137Sume#endif 54078064Sume 5411541Srgrimes/* "Socket"-level control message types: */ 5421541Srgrimes#define SCM_RIGHTS 0x01 /* access rights (array of int) */ 543104983Smike#if __BSD_VISIBLE 54415701Swollman#define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */ 54524083Swpaul#define SCM_CREDS 0x03 /* process creds (struct cmsgcred) */ 546125264Sphk#define SCM_BINTIME 0x04 /* timestamp (struct bintime) */ 547338617Ssobomax#define SCM_REALTIME 0x05 /* timestamp (struct timespec) */ 548338617Ssobomax#define SCM_MONOTONIC 0x06 /* timestamp (struct timespec) */ 549104983Smike#endif 5501541Srgrimes 551104983Smike#if __BSD_VISIBLE 5521541Srgrimes/* 5531541Srgrimes * 4.3 compat sockaddr, move to compat file later 5541541Srgrimes */ 5551541Srgrimesstruct osockaddr { 556104983Smike unsigned short sa_family; /* address family */ 5571541Srgrimes char sa_data[14]; /* up to 14 bytes of direct address */ 5581541Srgrimes}; 5591541Srgrimes 5601541Srgrimes/* 5611541Srgrimes * 4.3-compat message header (move to compat file later). 5621541Srgrimes */ 5631541Srgrimesstruct omsghdr { 564104983Smike char *msg_name; /* optional address */ 5651541Srgrimes int msg_namelen; /* size of address */ 5661541Srgrimes struct iovec *msg_iov; /* scatter/gather array */ 5671541Srgrimes int msg_iovlen; /* # elements in msg_iov */ 568104983Smike char *msg_accrights; /* access rights sent/received */ 5691541Srgrimes int msg_accrightslen; 5701541Srgrimes}; 571104983Smike#endif 5721541Srgrimes 57339114Swollman/* 57439114Swollman * howto arguments for shutdown(2), specified by Posix.1g. 57539114Swollman */ 57639114Swollman#define SHUT_RD 0 /* shut down the reading side */ 57739114Swollman#define SHUT_WR 1 /* shut down the writing side */ 57839114Swollman#define SHUT_RDWR 2 /* shut down both sides */ 57939114Swollman 580248932Sjilles#if __BSD_VISIBLE 581248932Sjilles/* for SCTP */ 582178200Srrs/* we cheat and use the SHUT_XX defines for these */ 583178200Srrs#define PRU_FLUSH_RD SHUT_RD 584178200Srrs#define PRU_FLUSH_WR SHUT_WR 585178200Srrs#define PRU_FLUSH_RDWR SHUT_RDWR 586248932Sjilles#endif 587178200Srrs 588178200Srrs 589104983Smike#if __BSD_VISIBLE 59040931Sdg/* 59140931Sdg * sendfile(2) header/trailer struct 59240931Sdg */ 59340931Sdgstruct sf_hdtr { 59440931Sdg struct iovec *headers; /* pointer to an array of header struct iovec's */ 59540931Sdg int hdr_cnt; /* number of header iovec's */ 59640931Sdg struct iovec *trailers; /* pointer to an array of trailer struct iovec's */ 59740931Sdg int trl_cnt; /* number of trailer iovec's */ 59840931Sdg}; 599125586Ssilby 600125586Ssilby/* 601125586Ssilby * Sendfile-specific flag(s) 602125586Ssilby */ 603163913Sandre#define SF_NODISKIO 0x00000001 604293439Sglebius#define SF_MNOWAIT 0x00000002 /* obsolete */ 605175941Sphk#define SF_SYNC 0x00000004 606293439Sglebius#define SF_NOCACHE 0x00000010 607293439Sglebius#define SF_FLAGS(rh, flags) (((rh) << 16) | (flags)) 60840931Sdg 609254356Sglebius#ifdef _KERNEL 610293439Sglebius#define SF_READAHEAD(flags) ((flags) >> 16) 611254356Sglebius#endif /* _KERNEL */ 612295039Skib 613295039Skib/* 614295039Skib * Sendmmsg/recvmmsg specific structure(s) 615295039Skib */ 616295039Skibstruct mmsghdr { 617295039Skib struct msghdr msg_hdr; /* message header */ 618295039Skib ssize_t msg_len; /* message length */ 619295039Skib}; 620254356Sglebius#endif /* __BSD_VISIBLE */ 621254356Sglebius 62255205Speter#ifndef _KERNEL 6231541Srgrimes 6241541Srgrimes#include <sys/cdefs.h> 6251541Srgrimes 6261541Srgrimes__BEGIN_DECLS 627123811Salfredint accept(int, struct sockaddr * __restrict, socklen_t * __restrict); 62892719Salfredint bind(int, const struct sockaddr *, socklen_t); 629248932Sjillesint connect(int, const struct sockaddr *, socklen_t); 630248932Sjilles#if __BSD_VISIBLE 631250154Sjillesint accept4(int, struct sockaddr * __restrict, socklen_t * __restrict, int); 632247667Spjdint bindat(int, int, const struct sockaddr *, socklen_t); 633247667Spjdint connectat(int, int, const struct sockaddr *, socklen_t); 634248932Sjilles#endif 635123811Salfredint getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict); 636123811Salfredint getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict); 637123811Salfredint getsockopt(int, int, int, void * __restrict, socklen_t * __restrict); 63892719Salfredint listen(int, int); 63992719Salfredssize_t recv(int, void *, size_t, int); 640123811Salfredssize_t recvfrom(int, void *, size_t, int, struct sockaddr * __restrict, socklen_t * __restrict); 64192719Salfredssize_t recvmsg(int, struct msghdr *, int); 642295039Skib#if __BSD_VISIBLE 643295039Skibstruct timespec; 644295039Skibssize_t recvmmsg(int, struct mmsghdr * __restrict, size_t, int, 645295039Skib const struct timespec * __restrict); 646295039Skib#endif 64792719Salfredssize_t send(int, const void *, size_t, int); 64892719Salfredssize_t sendto(int, const void *, 64992719Salfred size_t, int, const struct sockaddr *, socklen_t); 65092719Salfredssize_t sendmsg(int, const struct msghdr *, int); 651104983Smike#if __BSD_VISIBLE 65292719Salfredint sendfile(int, int, off_t, size_t, struct sf_hdtr *, off_t *, int); 653295039Skibssize_t sendmmsg(int, struct mmsghdr * __restrict, size_t, int); 654181440Sdelphijint setfib(int); 655104983Smike#endif 65692719Salfredint setsockopt(int, int, int, const void *, socklen_t); 65792719Salfredint shutdown(int, int); 658107872Sfennerint sockatmark(int); 65992719Salfredint socket(int, int, int); 66092719Salfredint socketpair(int, int, int, int *); 6611541Srgrimes__END_DECLS 6621541Srgrimes 66355205Speter#endif /* !_KERNEL */ 66431927Sbde 665180641Skmacy#ifdef _KERNEL 666180641Skmacystruct socket; 667180641Skmacy 668180641Skmacystruct tcpcb *so_sototcpcb(struct socket *so); 669180641Skmacystruct inpcb *so_sotoinpcb(struct socket *so); 670180641Skmacystruct sockbuf *so_sockbuf_snd(struct socket *); 671180641Skmacystruct sockbuf *so_sockbuf_rcv(struct socket *); 672180641Skmacy 673180641Skmacyint so_state_get(const struct socket *); 674180641Skmacyvoid so_state_set(struct socket *, int); 675180641Skmacy 676180641Skmacyint so_options_get(const struct socket *); 677180641Skmacyvoid so_options_set(struct socket *, int); 678180641Skmacy 679180641Skmacyint so_error_get(const struct socket *); 680180641Skmacyvoid so_error_set(struct socket *, int); 681180641Skmacy 682180641Skmacyint so_linger_get(const struct socket *); 683180641Skmacyvoid so_linger_set(struct socket *, int); 684180641Skmacy 685180641Skmacystruct protosw *so_protosw_get(const struct socket *); 686180641Skmacyvoid so_protosw_set(struct socket *, struct protosw *); 687180641Skmacy 688180641Skmacyvoid so_sorwakeup_locked(struct socket *so); 689180641Skmacyvoid so_sowwakeup_locked(struct socket *so); 690180641Skmacy 691180641Skmacyvoid so_sorwakeup(struct socket *so); 692180641Skmacyvoid so_sowwakeup(struct socket *so); 693180641Skmacy 694180641Skmacyvoid so_lock(struct socket *so); 695180641Skmacyvoid so_unlock(struct socket *so); 696180641Skmacy 697180641Skmacyvoid so_listeners_apply_all(struct socket *so, void (*func)(struct socket *, void *), void *arg); 698180641Skmacy 699180641Skmacy#endif 700180641Skmacy 701180641Skmacy 7021541Srgrimes#endif /* !_SYS_SOCKET_H_ */ 703