Home | History | Annotate | Line # | Download | only in common
linux_socket.h revision 1.21.12.1
      1  1.21.12.1       tls /*	$NetBSD: linux_socket.h,v 1.21.12.1 2014/08/20 00:03:32 tls Exp $	*/
      2        1.4       erh 
      3        1.4       erh /*-
      4        1.6      fvdl  * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
      5        1.4       erh  * All rights reserved.
      6        1.4       erh  *
      7        1.4       erh  * This code is derived from software contributed to The NetBSD Foundation
      8        1.6      fvdl  * by Frank van der Linden and Eric Haszlakiewicz.
      9        1.4       erh  *
     10        1.4       erh  * Redistribution and use in source and binary forms, with or without
     11        1.4       erh  * modification, are permitted provided that the following conditions
     12        1.4       erh  * are met:
     13        1.4       erh  * 1. Redistributions of source code must retain the above copyright
     14        1.4       erh  *    notice, this list of conditions and the following disclaimer.
     15        1.4       erh  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.4       erh  *    notice, this list of conditions and the following disclaimer in the
     17        1.4       erh  *    documentation and/or other materials provided with the distribution.
     18        1.4       erh  *
     19        1.4       erh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.4       erh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.4       erh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.4       erh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.4       erh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.4       erh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.4       erh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.4       erh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.4       erh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.4       erh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.4       erh  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1      fvdl  */
     31        1.1      fvdl 
     32        1.5  christos #ifndef _LINUX_SOCKET_H
     33        1.5  christos #define _LINUX_SOCKET_H
     34        1.1      fvdl 
     35        1.1      fvdl /*
     36        1.1      fvdl  * Various Linux socket defines. Everything that is not re-defined here
     37        1.1      fvdl  * is the same as in NetBSD.
     38        1.1      fvdl  *
     39        1.1      fvdl  * COMPAT_43 is assumed, and the osockaddr struct is used (it is what
     40        1.1      fvdl  * Linux uses)
     41        1.1      fvdl  */
     42        1.1      fvdl 
     43        1.1      fvdl /*
     44        1.1      fvdl  * Address families. There are fewer of them, and they're numbered
     45        1.1      fvdl  * a bit different
     46        1.1      fvdl  */
     47        1.1      fvdl 
     48        1.1      fvdl #define LINUX_AF_UNSPEC		0
     49        1.1      fvdl #define LINUX_AF_UNIX		1
     50        1.1      fvdl #define LINUX_AF_INET		2
     51        1.1      fvdl #define LINUX_AF_AX25		3
     52        1.1      fvdl #define LINUX_AF_IPX		4
     53        1.1      fvdl #define LINUX_AF_APPLETALK	5
     54        1.4       erh #define LINUX_AF_NETROM		6
     55        1.4       erh #define LINUX_AF_BRIDGE		7
     56        1.4       erh #define LINUX_AF_ATMPVC		8
     57        1.4       erh #define LINUX_AF_X25		9
     58        1.4       erh #define LINUX_AF_INET6		10
     59        1.4       erh #define LINUX_AF_ROSE		11
     60        1.4       erh #define LINUX_AF_DECnet		12
     61        1.4       erh #define LINUX_AF_NETBEUI	13
     62        1.4       erh #define LINUX_AF_SECURITY	14
     63        1.4       erh #define LINUX_pseudo_AF_KEY	15
     64        1.4       erh #define LINUX_AF_NETLINK	16
     65        1.4       erh #define LINUX_AF_PACKET		17
     66        1.4       erh #define LINUX_AF_ASH		18
     67        1.4       erh #define LINUX_AF_ECONET		19
     68        1.4       erh #define	LINUX_AF_ATMSVC		20
     69        1.4       erh #define	LINUX_AF_SNA		22
     70        1.4       erh #define LINUX_AF_MAX		32
     71        1.1      fvdl 
     72        1.1      fvdl /*
     73        1.1      fvdl  * Option levels for [gs]etsockopt(2). Only SOL_SOCKET is different,
     74        1.1      fvdl  * the rest matches IPPROTO_XXX
     75        1.1      fvdl  */
     76        1.1      fvdl 
     77       1.21       wiz /* SOL_SOCKET is machine dependent on Linux */
     78        1.1      fvdl #define LINUX_SOL_IP		0
     79        1.4       erh #define LINUX_SOL_TCP		6
     80        1.4       erh #define LINUX_SOL_UDP		17
     81        1.4       erh #define LINUX_SOL_IPV6		41
     82  1.21.12.1       tls /* Unused for now: */
     83        1.4       erh #define LINUX_SOL_ICMPV6	58
     84        1.4       erh #define LINUX_SOL_RAW		255
     85        1.1      fvdl #define LINUX_SOL_IPX		256
     86        1.1      fvdl #define LINUX_SOL_AX25		257
     87        1.4       erh #define LINUX_SOL_ATALK		258
     88        1.4       erh #define LINUX_SOL_NETROM	259
     89        1.4       erh #define LINUX_SOL_ROSE		260
     90        1.4       erh #define LINUX_SOL_DECNET	261
     91        1.4       erh #define LINUX_SOL_X25		262
     92        1.4       erh #define LINUX_SOL_PACKET	263
     93        1.4       erh #define LINUX_SOL_ATM		264
     94        1.4       erh #define LINUX_SOL_AAL		265
     95        1.1      fvdl 
     96        1.1      fvdl /*
     97       1.21       wiz  * Options for [gs]etsockopt(2), socket level are machine dependent.
     98        1.1      fvdl  */
     99        1.1      fvdl 
    100        1.1      fvdl /*
    101        1.4       erh  * Options for [gs]etsockopt(2), IP level.
    102        1.1      fvdl  */
    103        1.1      fvdl 
    104        1.2   mycroft #define LINUX_IP_TOS		1
    105        1.2   mycroft #define LINUX_IP_TTL		2
    106       1.19       dsl #define LINUX_IP_HDRINCL	3
    107        1.2   mycroft #define	LINUX_IP_MULTICAST_IF	32
    108        1.2   mycroft #define	LINUX_IP_MULTICAST_TTL	33
    109        1.2   mycroft #define	LINUX_IP_MULTICAST_LOOP	34
    110        1.2   mycroft #define	LINUX_IP_ADD_MEMBERSHIP	35
    111        1.2   mycroft #define	LINUX_IP_DROP_MEMBERSHIP 36
    112        1.3   mycroft 
    113        1.3   mycroft /*
    114  1.21.12.1       tls  * Options for [gs]etsockopt(2), IPV6 level.
    115  1.21.12.1       tls  */
    116  1.21.12.1       tls 
    117  1.21.12.1       tls #define LINUX_IPV6_V6ONLY		26
    118  1.21.12.1       tls 
    119  1.21.12.1       tls /*
    120        1.4       erh  * Options for [gs]etsockopt(2), TCP level.
    121        1.3   mycroft  */
    122        1.3   mycroft 
    123        1.3   mycroft #define	LINUX_TCP_NODELAY	1
    124        1.3   mycroft #define	LINUX_TCP_MAXSEG	2
    125        1.1      fvdl 
    126       1.11  jdolecek /* "Socket"-level control message types: */
    127       1.11  jdolecek #define LINUX_SCM_RIGHTS	1	/* same as SCM_RIGHTS */
    128       1.11  jdolecek #define LINUX_SCM_CREDENTIALS	2	/* accepts ucred rather than sockcred */
    129       1.11  jdolecek #define LINUX_SCM_CONNECT	3	/* not supported in NetBSD */
    130       1.11  jdolecek #define LINUX_SCM_TIMESTAMP	LINUX_SO_TIMESTAMP
    131       1.11  jdolecek 				/* not actually implemented in Linux 2.5.15? */
    132       1.11  jdolecek 
    133       1.18     njoly struct linux_msghdr {
    134       1.18     njoly 	void		*msg_name;
    135       1.18     njoly 	int		msg_namelen;
    136       1.18     njoly 	struct iovec	*msg_iov;
    137       1.18     njoly 	size_t		msg_iovlen;
    138       1.18     njoly 	void		*msg_control;
    139       1.18     njoly 	size_t		msg_controllen;
    140       1.18     njoly 	unsigned int	msg_flags;
    141       1.18     njoly };
    142       1.18     njoly 
    143       1.11  jdolecek /*
    144       1.11  jdolecek  * Message flags (for sendmsg/recvmsg)
    145       1.11  jdolecek  */
    146       1.11  jdolecek #define LINUX_MSG_OOB		0x001
    147       1.11  jdolecek #define LINUX_MSG_PEEK		0x002
    148       1.11  jdolecek #define LINUX_MSG_DONTROUTE	0x004
    149       1.11  jdolecek #define LINUX_MSG_TRYHARD	0x004
    150       1.11  jdolecek #define LINUX_MSG_CTRUNC	0x008
    151       1.11  jdolecek #define LINUX_MSG_PROBE		0x010	/* Don't send, only probe path */
    152       1.11  jdolecek #define LINUX_MSG_TRUNC		0x020
    153       1.11  jdolecek #define LINUX_MSG_DONTWAIT	0x040	/* this msg should be nonblocking */
    154       1.11  jdolecek #define LINUX_MSG_EOR		0x080	/* data completes record */
    155       1.11  jdolecek #define LINUX_MSG_WAITALL	0x100	/* wait for full request or error */
    156       1.11  jdolecek #define LINUX_MSG_FIN		0x200
    157       1.11  jdolecek #define LINUX_MSG_EOF		LINUX_MSG_FIN
    158       1.11  jdolecek #define LINUX_MSG_SYN		0x400
    159       1.11  jdolecek #define LINUX_MSG_CONFIRM	0x800	/* Confirm path validity */
    160       1.11  jdolecek #define LINUX_MSG_RST		0x1000
    161       1.11  jdolecek #define LINUX_MSG_ERRQUEUE	0x2000	/* fetch message from error queue */
    162       1.11  jdolecek #define LINUX_MSG_NOSIGNAL	0x4000	/* do not generate SIGPIPE */
    163       1.11  jdolecek #define LINUX_MSG_MORE		0x8000	/* Sender will send more */
    164       1.11  jdolecek 
    165       1.11  jdolecek /*
    166       1.11  jdolecek  * Linux alignment requirement for CMSG struct manipulation.
    167       1.15       dsl  * Linux aligns on (size_t) boundary on all architectures.
    168       1.15       dsl  * Fortunately for linux, linux_cmsghdr is always size_t aligned !
    169       1.15       dsl  * since no padding is added between the header and data.
    170       1.15       dsl  * XXX: this code isn't right for the compat32 code.
    171       1.15       dsl  */
    172       1.15       dsl struct linux_cmsghdr {
    173       1.15       dsl 	size_t	cmsg_len;	/* NB not socklen_t */
    174       1.15       dsl 	int	cmsg_level;
    175       1.15       dsl 	int	cmsg_type;
    176       1.15       dsl     /*	unsigned char __cmsg_data[0]; */
    177       1.15       dsl };
    178       1.15       dsl 
    179       1.11  jdolecek #define LINUX_CMSG_ALIGN(n)	\
    180       1.15       dsl 	(((n) + sizeof(size_t)-1) & ~(sizeof(size_t)-1))
    181       1.15       dsl /* Linux either uses this, or  &((cmsg)->__cmsg_data) */
    182       1.11  jdolecek #define LINUX_CMSG_DATA(cmsg)	\
    183       1.15       dsl 	((u_char *)((struct linux_cmsghdr *)(cmsg) + 1))
    184       1.11  jdolecek #define	LINUX_CMSG_NXTHDR(mhdr, cmsg)	\
    185       1.15       dsl 	((((char *)(cmsg) + LINUX_CMSG_ALIGN((cmsg)->cmsg_len) + \
    186       1.15       dsl 			    sizeof(*(cmsg))) > \
    187       1.14  christos 	    (((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen)) ? \
    188       1.15       dsl 	    (struct linux_cmsghdr *)NULL : \
    189       1.15       dsl 	    (struct linux_cmsghdr *)((char *)(cmsg) + \
    190       1.11  jdolecek 	        LINUX_CMSG_ALIGN((cmsg)->cmsg_len)))
    191       1.15       dsl /* This the number of bytes removed from each item (excl. final padding) */
    192       1.15       dsl #define LINUX_CMSG_ALIGN_DELTA	\
    193       1.15       dsl 	(CMSG_ALIGN(sizeof(struct cmsghdr)) - sizeof(struct linux_cmsghdr))
    194       1.15       dsl 
    195       1.15       dsl #define LINUX_CMSG_FIRSTHDR(mhdr) \
    196       1.15       dsl 	((mhdr)->msg_controllen >= sizeof(struct linux_cmsghdr) ? \
    197       1.15       dsl 	(struct linux_cmsghdr *)(mhdr)->msg_control : NULL)
    198       1.15       dsl 
    199       1.17     njoly #define LINUX_CMSG_SPACE(l) \
    200       1.17     njoly 	(sizeof(struct linux_cmsghdr) + LINUX_CMSG_ALIGN(l))
    201       1.17     njoly #define LINUX_CMSG_LEN(l) \
    202       1.17     njoly 	(sizeof(struct linux_cmsghdr) + (l))
    203       1.11  jdolecek 
    204       1.11  jdolecek /*
    205       1.11  jdolecek  * Machine specific definitions.
    206       1.11  jdolecek  */
    207        1.5  christos #if defined(__i386__)
    208        1.5  christos #include <compat/linux/arch/i386/linux_socket.h>
    209        1.7     itohy #elif defined(__m68k__)
    210        1.7     itohy #include <compat/linux/arch/m68k/linux_socket.h>
    211        1.5  christos #elif defined(__alpha__)
    212        1.5  christos #include <compat/linux/arch/alpha/linux_socket.h>
    213        1.8      manu #elif defined(__powerpc__)
    214        1.8      manu #include <compat/linux/arch/powerpc/linux_socket.h>
    215        1.9      manu #elif defined(__mips__)
    216        1.9      manu #include <compat/linux/arch/mips/linux_socket.h>
    217       1.10     bjh21 #elif defined(__arm__)
    218       1.10     bjh21 #include <compat/linux/arch/arm/linux_socket.h>
    219       1.12      manu #elif defined(__amd64__)
    220       1.12      manu #include <compat/linux/arch/amd64/linux_socket.h>
    221        1.5  christos #else
    222        1.5  christos #error Undefined linux_socket.h machine type.
    223        1.5  christos #endif
    224        1.5  christos 
    225       1.20       chs /*
    226       1.20       chs  * Flags for socket().
    227       1.20       chs  * These are provided in the "type" parameter.
    228       1.20       chs  */
    229       1.20       chs 
    230       1.20       chs #define LINUX_SOCK_TYPE_MASK	0xf
    231       1.20       chs #define LINUX_SOCK_CLOEXEC	LINUX_O_CLOEXEC
    232       1.20       chs #ifndef LINUX_SOCK_NONBLOCK
    233       1.20       chs #define LINUX_SOCK_NONBLOCK	LINUX_O_NONBLOCK
    234       1.20       chs #endif
    235       1.20       chs 
    236        1.5  christos #endif /* !_LINUX_SOCKET_H */
    237