socket.h revision 199767f8919635c4928607450d9e0abb932109ce
/*-
* Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)socket.h 8.4 (Berkeley) 2/21/94
* $FreeBSD$
*/
#ifndef _SYS_SOCKET_H_
#define _SYS_SOCKET_H_
/*
* Definitions related to sockets: types, address families, options.
*/
/*
* Data types.
*/
#if __BSD_VISIBLE
#ifndef _GID_T_DECLARED
#define _GID_T_DECLARED
#endif
#ifndef _OFF_T_DECLARED
#define _OFF_T_DECLARED
#endif
#ifndef _PID_T_DECLARED
#define _PID_T_DECLARED
#endif
#endif
#ifndef _SA_FAMILY_T_DECLARED
typedef __sa_family_t sa_family_t;
#define _SA_FAMILY_T_DECLARED
#endif
#ifndef _SOCKLEN_T_DECLARED
typedef __socklen_t socklen_t;
#define _SOCKLEN_T_DECLARED
#endif
#ifndef _SSIZE_T_DECLARED
#define _SSIZE_T_DECLARED
#endif
#if __BSD_VISIBLE
#ifndef _UID_T_DECLARED
#define _UID_T_DECLARED
#endif
#endif
#ifndef _UINT32_T_DECLARED
typedef __uint32_t uint32_t;
#define _UINT32_T_DECLARED
#endif
#ifndef _UINTPTR_T_DECLARED
typedef __uintptr_t uintptr_t;
#define _UINTPTR_T_DECLARED
#endif
/*
* Types
*/
#if __BSD_VISIBLE
#endif
#if __BSD_VISIBLE
/*
* Creation flags, OR'ed into socket() and socketpair() type argument.
*/
#define SOCK_CLOEXEC 0x10000000
#define SOCK_NONBLOCK 0x20000000
#endif
/*
* Option flags per-socket.
*/
#if __BSD_VISIBLE
#endif
#if __BSD_VISIBLE
#endif
/*
* Additional options, not kept in so_options.
*/
#if __BSD_VISIBLE
#endif
/*
* Space reserved for new socket options added by third-party vendors.
* This range applies to all socket option levels. New socket options
* in FreeBSD should always use an option value less than SO_VENDOR.
*/
#if __BSD_VISIBLE
#define SO_VENDOR 0x80000000
#endif
/*
* Structure used for manipulating linger option.
*/
struct linger {
int l_linger; /* linger time */
};
#if __BSD_VISIBLE
struct accept_filter_arg {
char af_name[16];
};
#endif
/*
*/
/*
* Address families.
*/
#define AF_UNSPEC 0 /* unspecified */
#if __BSD_VISIBLE
#endif
#if __BSD_VISIBLE
#endif
#if __BSD_VISIBLE
* in interface output routine
*/
#define AF_ARP 35
#define AF_MAX 42
/*
* When allocating a new AF_ constant, please only allocate
* even numbered constants for FreeBSD until 134 as odd numbered AF_
* constants 39-133 are now reserved for vendors.
*/
#define AF_VENDOR00 39
#define AF_VENDOR01 41
#define AF_VENDOR02 43
#define AF_VENDOR03 45
#define AF_VENDOR04 47
#define AF_VENDOR05 49
#define AF_VENDOR06 51
#define AF_VENDOR07 53
#define AF_VENDOR08 55
#define AF_VENDOR09 57
#define AF_VENDOR10 59
#define AF_VENDOR11 61
#define AF_VENDOR12 63
#define AF_VENDOR13 65
#define AF_VENDOR14 67
#define AF_VENDOR15 69
#define AF_VENDOR16 71
#define AF_VENDOR17 73
#define AF_VENDOR18 75
#define AF_VENDOR19 77
#define AF_VENDOR20 79
#define AF_VENDOR21 81
#define AF_VENDOR22 83
#define AF_VENDOR23 85
#define AF_VENDOR24 87
#define AF_VENDOR25 89
#define AF_VENDOR26 91
#define AF_VENDOR27 93
#define AF_VENDOR28 95
#define AF_VENDOR29 97
#define AF_VENDOR30 99
#define AF_VENDOR31 101
#define AF_VENDOR32 103
#define AF_VENDOR33 105
#define AF_VENDOR34 107
#define AF_VENDOR35 109
#define AF_VENDOR36 111
#define AF_VENDOR37 113
#define AF_VENDOR38 115
#define AF_VENDOR39 117
#define AF_VENDOR40 119
#define AF_VENDOR41 121
#define AF_VENDOR42 123
#define AF_VENDOR43 125
#define AF_VENDOR44 127
#define AF_VENDOR45 129
#define AF_VENDOR46 131
#define AF_VENDOR47 133
#endif
/*
* Structure used by kernel to store most
* addresses.
*/
struct sockaddr {
unsigned char sa_len; /* total length */
};
#if __BSD_VISIBLE
/*
* Structure used by kernel to pass protocol
* information in raw sockets.
*/
struct sockproto {
unsigned short sp_family; /* address family */
unsigned short sp_protocol; /* protocol */
};
#endif
#include <sys/_sockaddr_storage.h>
#if __BSD_VISIBLE
/*
* Protocol families, same as address families for now.
*/
#define PF_IMPLINK AF_IMPLINK
#define PF_NETBIOS AF_NETBIOS
#define PF_DATAKIT AF_DATAKIT
#define PF_APPLETALK AF_APPLETALK
#define PF_PIP pseudo_AF_PIP
#define PF_KEY pseudo_AF_KEY
#define PF_NETGRAPH AF_NETGRAPH
#define PF_SCLUSTER AF_SCLUSTER
#define PF_BLUETOOTH AF_BLUETOOTH
#define PF_IEEE80211 AF_IEEE80211
#define PF_INET_SDP AF_INET_SDP
#define PF_INET6_SDP AF_INET6_SDP
/*
* Definitions for network related sysctl, CTL_NET.
*
* Second level is protocol family.
* Third level is protocol number.
*
* Further levels are defined by the individual families.
*/
/*
* PF_ROUTE - Routing table
*
* Three additional levels are defined:
* Fourth: address family, 0 is wildcard
* Fifth: type of info, defined below
* Sixth: flag(s) to mask with for NET_RT_FLAGS
*/
* versions of msghdr structs. */
#endif /* __BSD_VISIBLE */
/*
* Maximum queue length specifiable by listen.
*/
#define SOMAXCONN 128
/*
* Message header for recvmsg and sendmsg calls.
* Used value-result for recvmsg, value only for sendmsg.
*/
struct msghdr {
void *msg_name; /* optional address */
int msg_iovlen; /* # elements in msg_iov */
void *msg_control; /* ancillary data, see below */
int msg_flags; /* flags on received message */
};
#if __POSIX_VISIBLE >= 200809
#endif
#if __BSD_VISIBLE
#endif
#ifdef _KERNEL
#endif
/*
* Header for ancillary data objects in msg_control buffer.
* not expressible by flags. The format is a sequence
* of message elements headed by cmsghdr structures.
*/
struct cmsghdr {
int cmsg_level; /* originating protocol */
int cmsg_type; /* protocol-specific type */
/* followed by u_char cmsg_data[]; */
};
#if __BSD_VISIBLE
/*
* While we may have more groups than this, the cmsgcred struct must
* be able to fit in an mbuf and we have historically supported a
* maximum of 16 groups.
*/
#define CMGROUP_MAX 16
/*
* Credentials structure, used to verify the identity of a peer
* process that has sent us a message. This is allocated by the
* peer process but filled in by the kernel. This prevents the
* peer from lying about its identity. (Note that cmcred_groups[0]
* is the effective GID.)
*/
struct cmsgcred {
short cmcred_ngroups; /* number or groups */
};
/*
* Socket credentials.
*/
struct sockcred {
int sc_ngroups; /* number of supplemental groups */
};
/*
* Compute size of a sockcred structure with groups.
*/
#define SOCKCREDSIZE(ngrps) \
#endif /* __BSD_VISIBLE */
/* given pointer to struct cmsghdr, return pointer to data */
/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
(struct cmsghdr *)0 : \
/*
* RFC 2292 requires to check msg_controllen, in case that the kernel returns
* an empty list for some reasons.
*/
#define CMSG_FIRSTHDR(mhdr) \
#if __BSD_VISIBLE
/* RFC 2292 additions */
#endif
#ifdef _KERNEL
#define CMSG_ALIGN(n) _ALIGN(n)
#endif
/* "Socket"-level control message types: */
#if __BSD_VISIBLE
#endif
#if __BSD_VISIBLE
/*
* 4.3 compat sockaddr, move to compat file later
*/
struct osockaddr {
unsigned short sa_family; /* address family */
};
/*
* 4.3-compat message header (move to compat file later).
*/
struct omsghdr {
char *msg_name; /* optional address */
int msg_namelen; /* size of address */
int msg_iovlen; /* # elements in msg_iov */
char *msg_accrights; /* access rights sent/received */
int msg_accrightslen;
};
#endif
/*
* howto arguments for shutdown(2), specified by Posix.1g.
*/
#define SHUT_RD 0 /* shut down the reading side */
#if __BSD_VISIBLE
/* for SCTP */
/* we cheat and use the SHUT_XX defines for these */
#define PRU_FLUSH_RD SHUT_RD
#define PRU_FLUSH_WR SHUT_WR
#define PRU_FLUSH_RDWR SHUT_RDWR
#endif
#if __BSD_VISIBLE
/*
*/
struct sf_hdtr {
int hdr_cnt; /* number of header iovec's */
int trl_cnt; /* number of trailer iovec's */
};
/*
* Sendfile-specific flag(s)
*/
#define SF_NODISKIO 0x00000001
#define SF_SYNC 0x00000004
#define SF_NOCACHE 0x00000010
#ifdef _KERNEL
#define SFK_COMPAT 0x00000001
#endif /* _KERNEL */
/*
*/
struct mmsghdr {
};
#endif /* __BSD_VISIBLE */
#ifndef _KERNEL
#if __BSD_VISIBLE
#endif
int listen(int, int);
#if __BSD_VISIBLE
struct timespec;
const struct timespec * __restrict);
#endif
#if __BSD_VISIBLE
int setfib(int);
#endif
int setsockopt(int, int, int, const void *, socklen_t);
int shutdown(int, int);
int sockatmark(int);
int socket(int, int, int);
int socketpair(int, int, int, int *);
#endif /* !_KERNEL */
#ifdef _KERNEL
struct socket;
int so_state_get(const struct socket *);
void so_state_set(struct socket *, int);
int so_options_get(const struct socket *);
void so_options_set(struct socket *, int);
int so_error_get(const struct socket *);
void so_error_set(struct socket *, int);
int so_linger_get(const struct socket *);
void so_linger_set(struct socket *, int);
#endif
#endif /* !_SYS_SOCKET_H_ */