2005-06-10 17:12:03 +02:00
|
|
|
/*
|
|
|
|
sys/socket.h
|
|
|
|
*/
|
|
|
|
|
2005-07-11 15:00:43 +02:00
|
|
|
#ifndef SYS_SOCKET_H
|
|
|
|
#define SYS_SOCKET_H
|
|
|
|
|
|
|
|
/* Can we include <stdint.h> here or do we need an additional header that is
|
|
|
|
* safe to include?
|
|
|
|
*/
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2010-07-15 14:48:15 +02:00
|
|
|
#include <sys/ucred.h>
|
|
|
|
|
2005-06-10 17:12:03 +02:00
|
|
|
/* Open Group Base Specifications Issue 6 (not complete) */
|
|
|
|
#include <net/gen/socket.h>
|
2005-07-11 15:00:43 +02:00
|
|
|
|
|
|
|
#define SOCK_STREAM 1
|
|
|
|
#define SOCK_DGRAM 2
|
2005-07-27 13:42:54 +02:00
|
|
|
#define SOCK_RAW 3
|
|
|
|
#define SOCK_RDM 4
|
|
|
|
#define SOCK_SEQPACKET 5
|
2005-07-11 15:00:43 +02:00
|
|
|
|
|
|
|
#define SOL_SOCKET 0xFFFF
|
|
|
|
|
2005-07-27 13:42:54 +02:00
|
|
|
#define SO_DEBUG 0x0001
|
2005-07-11 15:00:43 +02:00
|
|
|
#define SO_REUSEADDR 0x0004
|
|
|
|
#define SO_KEEPALIVE 0x0008
|
2009-12-04 08:26:56 +01:00
|
|
|
#define SO_TYPE 0x0010 /* get socket type, SOCK_STREAM or SOCK_DGRAM */
|
2005-07-11 15:00:43 +02:00
|
|
|
|
2010-07-15 14:48:15 +02:00
|
|
|
#define SO_PASSCRED 0x0012
|
|
|
|
#define SO_PEERCRED 0x0014
|
|
|
|
|
2005-09-30 14:41:25 +02:00
|
|
|
#define SO_SNDBUF 0x1001 /* send buffer size */
|
2006-02-17 14:43:50 +01:00
|
|
|
#define SO_RCVBUF 0x1002 /* receive buffer size */
|
2005-09-30 14:41:25 +02:00
|
|
|
#define SO_ERROR 0x1007 /* get and clear error status */
|
2005-07-27 13:42:54 +02:00
|
|
|
|
2005-07-11 15:00:43 +02:00
|
|
|
/* The how argument to shutdown */
|
|
|
|
#define SHUT_RD 0 /* No further reads */
|
|
|
|
#define SHUT_WR 1 /* No further writes */
|
|
|
|
#define SHUT_RDWR 2 /* No further reads and writes */
|
|
|
|
|
|
|
|
#ifndef _SA_FAMILY_T
|
|
|
|
#define _SA_FAMILY_T
|
|
|
|
typedef uint8_t sa_family_t;
|
|
|
|
#endif /* _SA_FAMILY_T */
|
|
|
|
|
|
|
|
typedef int32_t socklen_t;
|
|
|
|
|
|
|
|
struct sockaddr
|
|
|
|
{
|
|
|
|
sa_family_t sa_family;
|
2005-11-04 18:07:39 +01:00
|
|
|
char sa_data[8]; /* Big enough for sockaddr_in */
|
2005-07-11 15:00:43 +02:00
|
|
|
};
|
|
|
|
|
2010-07-15 14:48:15 +02:00
|
|
|
struct msghdr
|
|
|
|
{
|
|
|
|
void *msg_name;
|
|
|
|
socklen_t msg_namelen;
|
|
|
|
struct iovec *msg_iov;
|
|
|
|
size_t msg_iovlen;
|
|
|
|
void *msg_control;
|
|
|
|
socklen_t msg_controllen;
|
|
|
|
int msg_flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cmsghdr
|
|
|
|
{
|
|
|
|
socklen_t cmsg_len;
|
|
|
|
int cmsg_level;
|
|
|
|
int cmsg_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define CMSG_FIRSTHDR(mhdr) \
|
|
|
|
( (mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
|
|
|
|
(struct cmsghdr *)(mhdr)->msg_control : \
|
|
|
|
(struct cmsghdr *)NULL )
|
|
|
|
|
|
|
|
#define CMSG_ALIGN(len) \
|
|
|
|
( (len % sizeof(long) == 0) ? \
|
|
|
|
len : \
|
|
|
|
len + sizeof(long) - (len % sizeof(long)) )
|
|
|
|
|
|
|
|
#define CMSG_NXTHDR(mhdr, cmsg) \
|
|
|
|
( ((cmsg) == NULL) ? CMSG_FIRSTHDR(mhdr) : \
|
|
|
|
(((unsigned char *)(cmsg) + CMSG_ALIGN((cmsg)->cmsg_len) \
|
|
|
|
+ CMSG_ALIGN(sizeof(struct cmsghdr)) > \
|
|
|
|
(unsigned char *)((mhdr)->msg_control) + \
|
|
|
|
(mhdr)->msg_controllen) ? \
|
|
|
|
(struct cmsghdr *)NULL : \
|
|
|
|
(struct cmsghdr *)((unsigned char *)(cmsg) + \
|
|
|
|
CMSG_ALIGN((cmsg)->cmsg_len))) )
|
|
|
|
|
|
|
|
#define CMSG_DATA(cmsg) \
|
|
|
|
( (unsigned char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr)) )
|
|
|
|
|
|
|
|
#define SCM_RIGHTS 0x01
|
|
|
|
#define SCM_CREDENTIALS 0x02
|
|
|
|
#define SCM_SECURITY 0x04
|
|
|
|
|
2005-07-11 15:00:43 +02:00
|
|
|
_PROTOTYPE( int accept, (int _socket,
|
|
|
|
struct sockaddr *_RESTRICT _address,
|
|
|
|
socklen_t *_RESTRICT _address_len) );
|
|
|
|
_PROTOTYPE( int bind, (int _socket, const struct sockaddr *_address,
|
|
|
|
socklen_t _address_len) );
|
|
|
|
_PROTOTYPE( int connect, (int _socket, const struct sockaddr *_address,
|
|
|
|
socklen_t _address_len) );
|
|
|
|
_PROTOTYPE( int getpeername, (int _socket,
|
|
|
|
struct sockaddr *_RESTRICT _address,
|
|
|
|
socklen_t *_RESTRICT _address_len) );
|
2010-07-15 14:48:15 +02:00
|
|
|
_PROTOTYPE( int getpeereid, (int _socket, uid_t *_euid, gid_t *_egid) );
|
2005-07-11 15:00:43 +02:00
|
|
|
_PROTOTYPE( int getsockname, (int _socket,
|
|
|
|
struct sockaddr *_RESTRICT _address,
|
|
|
|
socklen_t *_RESTRICT _address_len) );
|
|
|
|
_PROTOTYPE( int setsockopt,(int _socket, int _level, int _option_name,
|
|
|
|
const void *_option_value, socklen_t _option_len) );
|
2005-12-12 11:40:29 +01:00
|
|
|
_PROTOTYPE( int getsockopt, (int _socket, int _level, int _option_name,
|
|
|
|
void *_RESTRICT _option_value, socklen_t *_RESTRICT _option_len));
|
2005-07-11 15:00:43 +02:00
|
|
|
_PROTOTYPE( int listen, (int _socket, int _backlog) );
|
2006-07-14 16:34:00 +02:00
|
|
|
_PROTOTYPE( ssize_t recv, (int _socket, void *_buffer, size_t _length,
|
|
|
|
int _flags) );
|
2005-07-11 15:00:43 +02:00
|
|
|
_PROTOTYPE( ssize_t recvfrom, (int _socket, void *_RESTRICT _buffer,
|
|
|
|
size_t _length, int _flags, struct sockaddr *_RESTRICT _address,
|
|
|
|
socklen_t *_RESTRICT _address_len) );
|
2010-07-15 14:48:15 +02:00
|
|
|
_PROTOTYPE( ssize_t recvmsg, (int _socket, struct msghdr *_msg,
|
|
|
|
int _flags) );
|
2006-07-14 16:34:00 +02:00
|
|
|
_PROTOTYPE( ssize_t send, (int _socket, const void *_buffer,
|
|
|
|
size_t _length, int _flags) );
|
2010-07-15 14:48:15 +02:00
|
|
|
_PROTOTYPE( ssize_t sendmsg, (int _socket, const struct msghdr *_msg,
|
|
|
|
int _flags) );
|
2005-07-11 15:00:43 +02:00
|
|
|
_PROTOTYPE( ssize_t sendto, (int _socket, const void *_message,
|
|
|
|
size_t _length, int _flags, const struct sockaddr *_dest_addr,
|
|
|
|
socklen_t _dest_len) );
|
|
|
|
_PROTOTYPE( int shutdown, (int _socket, int _how) );
|
|
|
|
_PROTOTYPE( int socket, (int _domain, int _type, int _protocol) );
|
2010-07-15 14:48:15 +02:00
|
|
|
_PROTOTYPE( int socketpair, (int _domain, int _type, int _protocol,
|
|
|
|
int _sv[2]) );
|
2005-07-11 15:00:43 +02:00
|
|
|
|
2007-09-17 13:35:44 +02:00
|
|
|
/* The following constants are often used in applications, but are not defined
|
|
|
|
* by POSIX.
|
|
|
|
*/
|
2010-01-22 11:45:43 +01:00
|
|
|
#define PF_INET AF_INET
|
|
|
|
#define PF_INET6 AF_INET6
|
|
|
|
#define PF_UNIX AF_UNIX
|
2010-07-15 14:48:15 +02:00
|
|
|
#define PF_LOCAL PF_UNIX
|
|
|
|
#define PF_FILE PF_UNIX
|
2010-01-22 11:45:43 +01:00
|
|
|
#define PF_UNSPEC AF_UNSPEC
|
2007-09-17 13:35:44 +02:00
|
|
|
|
2010-01-25 19:13:23 +01:00
|
|
|
/* based on http://tools.ietf.org/html/rfc2553 */
|
|
|
|
struct sockaddr_storage
|
|
|
|
{
|
2010-06-22 18:21:21 +02:00
|
|
|
sa_family_t ss_family;
|
2010-01-25 19:13:23 +01:00
|
|
|
char __ss_pad1[6];
|
|
|
|
#ifdef __LONG_LONG_SUPPORTED
|
|
|
|
int64_t __ss_align;
|
|
|
|
#else
|
|
|
|
int32_t __ss_align[2];
|
|
|
|
#endif
|
|
|
|
char __ss_pad2[112];
|
|
|
|
};
|
|
|
|
|
2005-07-11 15:00:43 +02:00
|
|
|
#endif /* SYS_SOCKET_H */
|