/*-
* Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Frank van der Linden and Eric Haszlakiewicz.
*
* 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
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
#ifndef _LINUX_SOCKET_H
#define _LINUX_SOCKET_H
/*
* Various Linux socket defines. Everything that is not re-defined here
* is the same as in NetBSD.
*
* COMPAT_43 is assumed, and the osockaddr struct is used (it is what
* Linux uses)
*/
/*
* Address families. There are fewer of them, and they're numbered
* a bit different
*/
/* "Socket"-level control message types: */
#define LINUX_SCM_RIGHTS 1 /* same as SCM_RIGHTS */
#define LINUX_SCM_CREDENTIALS 2 /* accepts ucred rather than sockcred */
#define LINUX_SCM_CONNECT 3 /* not supported in NetBSD */
#define LINUX_SCM_TIMESTAMP LINUX_SO_TIMESTAMP
/* not actually implemented in Linux 2.5.15? */
struct linux_msghdr {
void *msg_name;
int msg_namelen;
struct iovec *msg_iov;
size_t msg_iovlen;
void *msg_control;
size_t msg_controllen;
unsigned int msg_flags;
};
struct linux_mmsghdr {
struct linux_msghdr msg_hdr;
unsigned int msg_len;
};
/*
* Message flags (for sendmsg/recvmsg)
*/
#define LINUX_MSG_OOB 0x001
#define LINUX_MSG_PEEK 0x002
#define LINUX_MSG_DONTROUTE 0x004
#define LINUX_MSG_TRYHARD 0x004
#define LINUX_MSG_CTRUNC 0x008
#define LINUX_MSG_PROBE 0x010 /* Don't send, only probe path */
#define LINUX_MSG_TRUNC 0x020
#define LINUX_MSG_DONTWAIT 0x040 /* this msg should be nonblocking */
#define LINUX_MSG_EOR 0x080 /* data completes record */
#define LINUX_MSG_WAITALL 0x100 /* wait for full request or error */
#define LINUX_MSG_FIN 0x200
#define LINUX_MSG_EOF LINUX_MSG_FIN
#define LINUX_MSG_SYN 0x400
#define LINUX_MSG_CONFIRM 0x800 /* Confirm path validity */
#define LINUX_MSG_RST 0x1000
#define LINUX_MSG_ERRQUEUE 0x2000 /* fetch message from error queue */
#define LINUX_MSG_NOSIGNAL 0x4000 /* do not generate SIGPIPE */
#define LINUX_MSG_MORE 0x8000 /* Sender will send more */
/*
* Linux alignment requirement for CMSG struct manipulation.
* Linux aligns on (size_t) boundary on all architectures.
* Fortunately for linux, linux_cmsghdr is always size_t aligned !
* since no padding is added between the header and data.
* XXX: this code isn't right for the compat32 code.
*/
struct linux_cmsghdr {
size_t cmsg_len; /* NB not socklen_t */
int cmsg_level;
int cmsg_type;
/* unsigned char __cmsg_data[0]; */
};
#define LINUX_CMSG_ALIGN(n) \
(((n) + sizeof(size_t)-1) & ~(sizeof(size_t)-1))
/* Linux either uses this, or &((cmsg)->__cmsg_data) */
#define LINUX_CMSG_DATA(cmsg) \
((u_char *)((struct linux_cmsghdr *)(cmsg) + 1))
#define LINUX_CMSG_NXTHDR(mhdr, ucmsg, kcmsg) \
((((char *)(ucmsg) + LINUX_CMSG_ALIGN((kcmsg)->cmsg_len) + \
sizeof(*(ucmsg))) > \
(((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen)) ? \
(struct linux_cmsghdr *)NULL : \
(struct linux_cmsghdr *)((char *)(ucmsg) + \
LINUX_CMSG_ALIGN((kcmsg)->cmsg_len)))
/* This the number of bytes removed from each item (excl. final padding) */
#define LINUX_CMSG_ALIGN_DELTA \
(CMSG_ALIGN(sizeof(struct cmsghdr)) - sizeof(struct linux_cmsghdr))