199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The Regents of the University of California. All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * are met:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 4. Neither the name of the University nor the names of its contributors
199767f8919635c4928607450d9e0abb932109ceToomas Soome * may be used to endorse or promote products derived from this software
199767f8919635c4928607450d9e0abb932109ceToomas Soome * without specific prior written permission.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * @(#)socket.h 8.4 (Berkeley) 2/21/94
199767f8919635c4928607450d9e0abb932109ceToomas Soome * $FreeBSD$
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _SYS_SOCKET_H_
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _SYS_SOCKET_H_
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/cdefs.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/_types.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/_iovec.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <machine/_align.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Definitions related to sockets: types, address families, options.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Data types.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _GID_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef __gid_t gid_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _GID_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _OFF_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef __off_t off_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _OFF_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _PID_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef __pid_t pid_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _PID_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _SA_FAMILY_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef __sa_family_t sa_family_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _SA_FAMILY_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _SOCKLEN_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef __socklen_t socklen_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _SOCKLEN_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _SSIZE_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef __ssize_t ssize_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _SSIZE_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _UID_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef __uid_t uid_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _UID_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _UINT32_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef __uint32_t uint32_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _UINT32_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _UINTPTR_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef __uintptr_t uintptr_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _UINTPTR_T_DECLARED
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Types
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SOCK_STREAM 1 /* stream socket */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SOCK_DGRAM 2 /* datagram socket */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SOCK_RAW 3 /* raw-protocol interface */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SOCK_RDM 4 /* reliably-delivered message */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SOCK_SEQPACKET 5 /* sequenced packet stream */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Creation flags, OR'ed into socket() and socketpair() type argument.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SOCK_CLOEXEC 0x10000000
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SOCK_NONBLOCK 0x20000000
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Option flags per-socket.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_DEBUG 0x0001 /* turn on debugging info recording */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_REUSEADDR 0x0004 /* allow local address reuse */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_KEEPALIVE 0x0008 /* keep connections alive */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_DONTROUTE 0x0010 /* just use interface addresses */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_LINGER 0x0080 /* linger on close if data present */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_NOSIGPIPE 0x0800 /* no SIGPIPE from EPIPE */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_BINTIME 0x2000 /* timestamp received dgram traffic */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_NO_OFFLOAD 0x4000 /* socket cannot be offloaded */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_NO_DDP 0x8000 /* disable direct data placement */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Additional options, not kept in so_options.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_SNDBUF 0x1001 /* send buffer size */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_RCVBUF 0x1002 /* receive buffer size */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_SNDLOWAT 0x1003 /* send low-water mark */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_RCVLOWAT 0x1004 /* receive low-water mark */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_SNDTIMEO 0x1005 /* send timeout */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_RCVTIMEO 0x1006 /* receive timeout */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_ERROR 0x1007 /* get error status and clear */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_TYPE 0x1008 /* get socket type */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_LABEL 0x1009 /* socket's MAC label */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_PEERLABEL 0x1010 /* socket's peer's MAC label */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_LISTENQLIMIT 0x1011 /* socket's backlog limit */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_LISTENQLEN 0x1012 /* socket's complete queue length */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_LISTENINCQLEN 0x1013 /* socket's incomplete queue length */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_SETFIB 0x1014 /* use this FIB to route */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_USER_COOKIE 0x1015 /* user cookie (dummynet etc.) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_PROTOCOL 0x1016 /* get socket protocol (Linux name) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_PROTOTYPE SO_PROTOCOL /* alias for SO_PROTOCOL (SunOS name) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Space reserved for new socket options added by third-party vendors.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This range applies to all socket option levels. New socket options
199767f8919635c4928607450d9e0abb932109ceToomas Soome * in FreeBSD should always use an option value less than SO_VENDOR.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SO_VENDOR 0x80000000
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Structure used for manipulating linger option.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct linger {
199767f8919635c4928607450d9e0abb932109ceToomas Soome int l_onoff; /* option on/off */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int l_linger; /* linger time */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct accept_filter_arg {
199767f8919635c4928607450d9e0abb932109ceToomas Soome char af_name[16];
199767f8919635c4928607450d9e0abb932109ceToomas Soome char af_arg[256-16];
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Level number for (get/set)sockopt() to apply to socket itself.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SOL_SOCKET 0xffff /* options for socket level */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Address families.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_UNSPEC 0 /* unspecified */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_LOCAL AF_UNIX /* local to host (pipes, portals) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_UNIX 1 /* standardized name for AF_LOCAL */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_IMPLINK 3 /* arpanet imp addresses */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_PUP 4 /* pup protocols: e.g. BSP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_CHAOS 5 /* mit CHAOS protocols */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_NETBIOS 6 /* SMB protocols */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_ISO 7 /* ISO protocols */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_OSI AF_ISO
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_ECMA 8 /* European computer manufacturers */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_DATAKIT 9 /* datakit protocols */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_CCITT 10 /* CCITT protocols, X.25 etc */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_SNA 11 /* IBM SNA */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_DECnet 12 /* DECnet */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_DLI 13 /* DEC Direct data link interface */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_LAT 14 /* LAT */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_HYLINK 15 /* NSC Hyperchannel */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_APPLETALK 16 /* Apple Talk */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_ROUTE 17 /* Internal Routing Protocol */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_LINK 18 /* Link layer interface */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_COIP 20 /* connection-oriented IP, aka ST II */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_CNT 21 /* Computer Network Technology */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_IPX 23 /* Novell Internet Protocol */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_SIP 24 /* Simple Internet Protocol */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define pseudo_AF_PIP 25 /* Help Identify PIP packets */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_ISDN 26 /* Integrated Services Digital Network*/
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define pseudo_AF_KEY 27 /* Internal key-management function */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_INET6 28 /* IPv6 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_NATM 29 /* native ATM access */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_ATM 30 /* ATM */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define pseudo_AF_HDRCMPLT 31 /* Used by BPF to not rewrite headers
199767f8919635c4928607450d9e0abb932109ceToomas Soome * in interface output routine
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_NETGRAPH 32 /* Netgraph sockets */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_SLOW 33 /* 802.3ad slow protocol */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_SCLUSTER 34 /* Sitara cluster protocol */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_ARP 35
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_BLUETOOTH 36 /* Bluetooth sockets */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_IEEE80211 37 /* IEEE 802.11 protocol */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_INET_SDP 40 /* OFED Socket Direct Protocol ipv4 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_INET6_SDP 42 /* OFED Socket Direct Protocol ipv6 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_MAX 42
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * When allocating a new AF_ constant, please only allocate
199767f8919635c4928607450d9e0abb932109ceToomas Soome * even numbered constants for FreeBSD until 134 as odd numbered AF_
199767f8919635c4928607450d9e0abb932109ceToomas Soome * constants 39-133 are now reserved for vendors.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR00 39
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR01 41
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR02 43
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR03 45
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR04 47
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR05 49
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR06 51
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR07 53
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR08 55
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR09 57
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR10 59
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR11 61
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR12 63
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR13 65
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR14 67
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR15 69
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR16 71
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR17 73
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR18 75
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR19 77
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR20 79
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR21 81
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR22 83
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR23 85
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR24 87
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR25 89
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR26 91
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR27 93
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR28 95
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR29 97
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR30 99
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR31 101
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR32 103
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR33 105
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR34 107
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR35 109
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR36 111
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR37 113
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR38 115
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR39 117
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR40 119
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR41 121
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR42 123
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR43 125
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR44 127
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR45 129
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR46 131
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define AF_VENDOR47 133
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Structure used by kernel to store most
199767f8919635c4928607450d9e0abb932109ceToomas Soome * addresses.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct sockaddr {
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned char sa_len; /* total length */
199767f8919635c4928607450d9e0abb932109ceToomas Soome sa_family_t sa_family; /* address family */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char sa_data[14]; /* actually longer; address value */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SOCK_MAXADDRLEN 255 /* longest possible addresses */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Structure used by kernel to pass protocol
199767f8919635c4928607450d9e0abb932109ceToomas Soome * information in raw sockets.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct sockproto {
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned short sp_family; /* address family */
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned short sp_protocol; /* protocol */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/_sockaddr_storage.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Protocol families, same as address families for now.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_UNSPEC AF_UNSPEC
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_LOCAL AF_LOCAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_UNIX PF_LOCAL /* backward compatibility */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_INET AF_INET
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_IMPLINK AF_IMPLINK
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_PUP AF_PUP
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_CHAOS AF_CHAOS
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_NETBIOS AF_NETBIOS
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_ISO AF_ISO
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_OSI AF_ISO
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_ECMA AF_ECMA
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_DATAKIT AF_DATAKIT
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_CCITT AF_CCITT
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_SNA AF_SNA
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_DECnet AF_DECnet
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_DLI AF_DLI
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_LAT AF_LAT
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_HYLINK AF_HYLINK
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_APPLETALK AF_APPLETALK
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_ROUTE AF_ROUTE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_LINK AF_LINK
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_COIP AF_COIP
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_CNT AF_CNT
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_SIP AF_SIP
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_IPX AF_IPX
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_PIP pseudo_AF_PIP
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_ISDN AF_ISDN
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_KEY pseudo_AF_KEY
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_INET6 AF_INET6
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_NATM AF_NATM
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_ATM AF_ATM
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_NETGRAPH AF_NETGRAPH
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_SLOW AF_SLOW
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_SCLUSTER AF_SCLUSTER
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_ARP AF_ARP
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_BLUETOOTH AF_BLUETOOTH
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_IEEE80211 AF_IEEE80211
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_INET_SDP AF_INET_SDP
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_INET6_SDP AF_INET6_SDP
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PF_MAX AF_MAX
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Definitions for network related sysctl, CTL_NET.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Second level is protocol family.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Third level is protocol number.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Further levels are defined by the individual families.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * PF_ROUTE - Routing table
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Three additional levels are defined:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Fourth: address family, 0 is wildcard
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Fifth: type of info, defined below
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Sixth: flag(s) to mask with for NET_RT_FLAGS
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define NET_RT_DUMP 1 /* dump; may limit to a.f. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define NET_RT_IFLIST 3 /* survey interface list */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define NET_RT_IFMALIST 4 /* return multicast address list */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define NET_RT_IFLISTL 5 /* Survey interface list, using 'l'en
199767f8919635c4928607450d9e0abb932109ceToomas Soome * versions of msghdr structs. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* __BSD_VISIBLE */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Maximum queue length specifiable by listen.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SOMAXCONN 128
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Message header for recvmsg and sendmsg calls.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Used value-result for recvmsg, value only for sendmsg.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct msghdr {
199767f8919635c4928607450d9e0abb932109ceToomas Soome void *msg_name; /* optional address */
199767f8919635c4928607450d9e0abb932109ceToomas Soome socklen_t msg_namelen; /* size of address */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct iovec *msg_iov; /* scatter/gather array */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int msg_iovlen; /* # elements in msg_iov */
199767f8919635c4928607450d9e0abb932109ceToomas Soome void *msg_control; /* ancillary data, see below */
199767f8919635c4928607450d9e0abb932109ceToomas Soome socklen_t msg_controllen; /* ancillary data buffer len */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int msg_flags; /* flags on received message */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MSG_OOB 0x1 /* process out-of-band data */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MSG_PEEK 0x2 /* peek at incoming message */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MSG_DONTROUTE 0x4 /* send without using routing tables */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MSG_EOR 0x8 /* data completes record */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MSG_TRUNC 0x10 /* data discarded before delivery */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MSG_CTRUNC 0x20 /* control data lost before delivery */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MSG_WAITALL 0x40 /* wait for full request or error */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __POSIX_VISIBLE >= 200809
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MSG_NOSIGNAL 0x20000 /* do not generate SIGPIPE on EOF */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MSG_EOF 0x100 /* data completes connection */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MSG_NOTIFICATION 0x2000 /* SCTP notification */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MSG_NBIO 0x4000 /* FIONBIO mode, used by fifofs */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MSG_COMPAT 0x8000 /* used in sendit() */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MSG_CMSG_CLOEXEC 0x40000 /* make received fds close-on-exec */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MSG_WAITFORONE 0x80000 /* for recvmmsg() */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef _KERNEL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MSG_SOCALLBCK 0x10000 /* for use by socket callbacks - soreceive (TCP) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Header for ancillary data objects in msg_control buffer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Used for additional information with/about a datagram
199767f8919635c4928607450d9e0abb932109ceToomas Soome * not expressible by flags. The format is a sequence
199767f8919635c4928607450d9e0abb932109ceToomas Soome * of message elements headed by cmsghdr structures.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct cmsghdr {
199767f8919635c4928607450d9e0abb932109ceToomas Soome socklen_t cmsg_len; /* data byte count, including hdr */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int cmsg_level; /* originating protocol */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int cmsg_type; /* protocol-specific type */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* followed by u_char cmsg_data[]; */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * While we may have more groups than this, the cmsgcred struct must
199767f8919635c4928607450d9e0abb932109ceToomas Soome * be able to fit in an mbuf and we have historically supported a
199767f8919635c4928607450d9e0abb932109ceToomas Soome * maximum of 16 groups.
199767f8919635c4928607450d9e0abb932109ceToomas Soome*/
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define CMGROUP_MAX 16
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Credentials structure, used to verify the identity of a peer
199767f8919635c4928607450d9e0abb932109ceToomas Soome * process that has sent us a message. This is allocated by the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * peer process but filled in by the kernel. This prevents the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * peer from lying about its identity. (Note that cmcred_groups[0]
199767f8919635c4928607450d9e0abb932109ceToomas Soome * is the effective GID.)
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct cmsgcred {
199767f8919635c4928607450d9e0abb932109ceToomas Soome pid_t cmcred_pid; /* PID of sending process */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uid_t cmcred_uid; /* real UID of sending process */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uid_t cmcred_euid; /* effective UID of sending process */
199767f8919635c4928607450d9e0abb932109ceToomas Soome gid_t cmcred_gid; /* real GID of sending process */
199767f8919635c4928607450d9e0abb932109ceToomas Soome short cmcred_ngroups; /* number or groups */
199767f8919635c4928607450d9e0abb932109ceToomas Soome gid_t cmcred_groups[CMGROUP_MAX]; /* groups */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Socket credentials.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct sockcred {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uid_t sc_uid; /* real user id */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uid_t sc_euid; /* effective user id */
199767f8919635c4928607450d9e0abb932109ceToomas Soome gid_t sc_gid; /* real group id */
199767f8919635c4928607450d9e0abb932109ceToomas Soome gid_t sc_egid; /* effective group id */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int sc_ngroups; /* number of supplemental groups */
199767f8919635c4928607450d9e0abb932109ceToomas Soome gid_t sc_groups[1]; /* variable length */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Compute size of a sockcred structure with groups.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SOCKCREDSIZE(ngrps) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (sizeof(struct sockcred) + (sizeof(gid_t) * ((ngrps) - 1)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* __BSD_VISIBLE */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* given pointer to struct cmsghdr, return pointer to data */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
199767f8919635c4928607450d9e0abb932109ceToomas Soome _ALIGN(sizeof(struct cmsghdr)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define CMSG_NXTHDR(mhdr, cmsg) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((char *)(cmsg) == NULL ? CMSG_FIRSTHDR(mhdr) : \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((char *)(cmsg) + _ALIGN(((struct cmsghdr *)(cmsg))->cmsg_len) + \
199767f8919635c4928607450d9e0abb932109ceToomas Soome _ALIGN(sizeof(struct cmsghdr)) > \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (char *)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (struct cmsghdr *)0 : \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (struct cmsghdr *)(void *)((char *)(cmsg) + \
199767f8919635c4928607450d9e0abb932109ceToomas Soome _ALIGN(((struct cmsghdr *)(cmsg))->cmsg_len)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * RFC 2292 requires to check msg_controllen, in case that the kernel returns
199767f8919635c4928607450d9e0abb932109ceToomas Soome * an empty list for some reasons.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define CMSG_FIRSTHDR(mhdr) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (struct cmsghdr *)(mhdr)->msg_control : \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (struct cmsghdr *)NULL)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* RFC 2292 additions */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define CMSG_SPACE(l) (_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(l))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define CMSG_LEN(l) (_ALIGN(sizeof(struct cmsghdr)) + (l))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef _KERNEL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define CMSG_ALIGN(n) _ALIGN(n)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* "Socket"-level control message types: */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SCM_RIGHTS 0x01 /* access rights (array of int) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SCM_CREDS 0x03 /* process creds (struct cmsgcred) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SCM_BINTIME 0x04 /* timestamp (struct bintime) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 4.3 compat sockaddr, move to compat file later
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct osockaddr {
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned short sa_family; /* address family */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char sa_data[14]; /* up to 14 bytes of direct address */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 4.3-compat message header (move to compat file later).
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct omsghdr {
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *msg_name; /* optional address */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int msg_namelen; /* size of address */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct iovec *msg_iov; /* scatter/gather array */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int msg_iovlen; /* # elements in msg_iov */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *msg_accrights; /* access rights sent/received */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int msg_accrightslen;
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * howto arguments for shutdown(2), specified by Posix.1g.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SHUT_RD 0 /* shut down the reading side */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SHUT_WR 1 /* shut down the writing side */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SHUT_RDWR 2 /* shut down both sides */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* for SCTP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* we cheat and use the SHUT_XX defines for these */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PRU_FLUSH_RD SHUT_RD
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PRU_FLUSH_WR SHUT_WR
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define PRU_FLUSH_RDWR SHUT_RDWR
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * sendfile(2) header/trailer struct
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct sf_hdtr {
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct iovec *headers; /* pointer to an array of header struct iovec's */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int hdr_cnt; /* number of header iovec's */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct iovec *trailers; /* pointer to an array of trailer struct iovec's */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int trl_cnt; /* number of trailer iovec's */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Sendfile-specific flag(s)
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SF_NODISKIO 0x00000001
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SF_MNOWAIT 0x00000002 /* obsolete */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SF_SYNC 0x00000004
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SF_NOCACHE 0x00000010
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SF_FLAGS(rh, flags) (((rh) << 16) | (flags))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef _KERNEL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SFK_COMPAT 0x00000001
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SF_READAHEAD(flags) ((flags) >> 16)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* _KERNEL */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Sendmmsg/recvmmsg specific structure(s)
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct mmsghdr {
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct msghdr msg_hdr; /* message header */
199767f8919635c4928607450d9e0abb932109ceToomas Soome ssize_t msg_len; /* message length */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* __BSD_VISIBLE */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _KERNEL
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/cdefs.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome__BEGIN_DECLS
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint accept(int, struct sockaddr * __restrict, socklen_t * __restrict);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint bind(int, const struct sockaddr *, socklen_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint connect(int, const struct sockaddr *, socklen_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint accept4(int, struct sockaddr * __restrict, socklen_t * __restrict, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint bindat(int, int, const struct sockaddr *, socklen_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint connectat(int, int, const struct sockaddr *, socklen_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint listen(int, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomessize_t recv(int, void *, size_t, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomessize_t recvfrom(int, void *, size_t, int, struct sockaddr * __restrict, socklen_t * __restrict);
199767f8919635c4928607450d9e0abb932109ceToomas Soomessize_t recvmsg(int, struct msghdr *, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct timespec;
199767f8919635c4928607450d9e0abb932109ceToomas Soomessize_t recvmmsg(int, struct mmsghdr * __restrict, size_t, int,
199767f8919635c4928607450d9e0abb932109ceToomas Soome const struct timespec * __restrict);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soomessize_t send(int, const void *, size_t, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomessize_t sendto(int, const void *,
199767f8919635c4928607450d9e0abb932109ceToomas Soome size_t, int, const struct sockaddr *, socklen_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soomessize_t sendmsg(int, const struct msghdr *, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __BSD_VISIBLE
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint sendfile(int, int, off_t, size_t, struct sf_hdtr *, off_t *, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomessize_t sendmmsg(int, struct mmsghdr * __restrict, size_t, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint setfib(int);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint setsockopt(int, int, int, const void *, socklen_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint shutdown(int, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint sockatmark(int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint socket(int, int, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint socketpair(int, int, int, int *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome__END_DECLS
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* !_KERNEL */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef _KERNEL
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct socket;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct tcpcb *so_sototcpcb(struct socket *so);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct inpcb *so_sotoinpcb(struct socket *so);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct sockbuf *so_sockbuf_snd(struct socket *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct sockbuf *so_sockbuf_rcv(struct socket *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint so_state_get(const struct socket *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid so_state_set(struct socket *, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint so_options_get(const struct socket *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid so_options_set(struct socket *, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint so_error_get(const struct socket *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid so_error_set(struct socket *, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint so_linger_get(const struct socket *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid so_linger_set(struct socket *, int);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct protosw *so_protosw_get(const struct socket *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid so_protosw_set(struct socket *, struct protosw *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid so_sorwakeup_locked(struct socket *so);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid so_sowwakeup_locked(struct socket *so);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid so_sorwakeup(struct socket *so);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid so_sowwakeup(struct socket *so);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid so_lock(struct socket *so);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid so_unlock(struct socket *so);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid so_listeners_apply_all(struct socket *so, void (*func)(struct socket *, void *), void *arg);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* !_SYS_SOCKET_H_ */