2009-03-04 04:28:35 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * 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 COPYRIGHT HOLDERS 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
|
|
|
|
* COPYRIGHT OWNER 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.
|
|
|
|
*/
|
2013-10-14 15:48:26 +02:00
|
|
|
|
2009-03-04 04:28:35 +01:00
|
|
|
#ifndef _SYS_SOCKET_H_
|
|
|
|
#define _SYS_SOCKET_H_
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <linux/socket.h>
|
|
|
|
|
2013-10-14 15:48:26 +02:00
|
|
|
#include <asm/fcntl.h>
|
2012-09-12 04:03:02 +02:00
|
|
|
#include <asm/socket.h>
|
|
|
|
#include <linux/sockios.h>
|
|
|
|
#include <linux/uio.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/compiler.h>
|
|
|
|
|
2016-07-22 01:38:43 +02:00
|
|
|
#include <bits/sa_family_t.h>
|
|
|
|
|
2009-03-04 04:28:35 +01:00
|
|
|
__BEGIN_DECLS
|
|
|
|
|
2012-09-12 04:03:02 +02:00
|
|
|
#define sockaddr_storage __kernel_sockaddr_storage
|
|
|
|
|
2014-03-01 02:59:29 +01:00
|
|
|
struct timespec;
|
|
|
|
|
2012-08-03 01:50:10 +02:00
|
|
|
#ifdef __mips__
|
|
|
|
#define SOCK_DGRAM 1
|
|
|
|
#define SOCK_STREAM 2
|
2015-08-26 02:45:46 +02:00
|
|
|
#else
|
|
|
|
#define SOCK_STREAM 1
|
|
|
|
#define SOCK_DGRAM 2
|
|
|
|
#endif
|
2012-08-03 01:50:10 +02:00
|
|
|
#define SOCK_RAW 3
|
|
|
|
#define SOCK_RDM 4
|
|
|
|
#define SOCK_SEQPACKET 5
|
|
|
|
#define SOCK_DCCP 6
|
|
|
|
#define SOCK_PACKET 10
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2013-10-14 15:48:26 +02:00
|
|
|
#define SOCK_CLOEXEC O_CLOEXEC
|
|
|
|
#define SOCK_NONBLOCK O_NONBLOCK
|
|
|
|
|
2009-03-04 04:28:35 +01:00
|
|
|
enum {
|
2013-10-14 15:48:26 +02:00
|
|
|
SHUT_RD = 0,
|
2009-03-04 04:28:35 +01:00
|
|
|
#define SHUT_RD SHUT_RD
|
2013-10-14 15:48:26 +02:00
|
|
|
SHUT_WR,
|
2009-03-04 04:28:35 +01:00
|
|
|
#define SHUT_WR SHUT_WR
|
2013-10-14 15:48:26 +02:00
|
|
|
SHUT_RDWR
|
2009-03-04 04:28:35 +01:00
|
|
|
#define SHUT_RDWR SHUT_RDWR
|
|
|
|
};
|
|
|
|
|
2012-09-12 04:03:02 +02:00
|
|
|
struct sockaddr {
|
2014-02-10 13:11:29 +01:00
|
|
|
sa_family_t sa_family;
|
|
|
|
char sa_data[14];
|
2012-09-12 04:03:02 +02:00
|
|
|
};
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2012-09-12 04:03:02 +02:00
|
|
|
struct linger {
|
2014-02-10 13:11:29 +01:00
|
|
|
int l_onoff;
|
|
|
|
int l_linger;
|
2012-09-12 04:03:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct msghdr {
|
2014-02-10 13:11:29 +01:00
|
|
|
void* msg_name;
|
|
|
|
socklen_t msg_namelen;
|
|
|
|
struct iovec* msg_iov;
|
|
|
|
size_t msg_iovlen;
|
|
|
|
void* msg_control;
|
|
|
|
size_t msg_controllen;
|
|
|
|
int msg_flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mmsghdr {
|
|
|
|
struct msghdr msg_hdr;
|
|
|
|
unsigned int msg_len;
|
2012-09-12 04:03:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cmsghdr {
|
2014-02-10 13:11:29 +01:00
|
|
|
size_t cmsg_len;
|
|
|
|
int cmsg_level;
|
|
|
|
int cmsg_type;
|
2012-09-12 04:03:02 +02:00
|
|
|
};
|
|
|
|
|
2014-06-19 19:16:17 +02:00
|
|
|
#define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr((mhdr), (cmsg))
|
2012-09-12 04:03:02 +02:00
|
|
|
#define CMSG_ALIGN(len) ( ((len)+sizeof(long)-1) & ~(sizeof(long)-1) )
|
2015-09-11 18:47:27 +02:00
|
|
|
#define CMSG_DATA(cmsg) (((unsigned char*)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr))))
|
2012-09-12 04:03:02 +02:00
|
|
|
#define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len))
|
|
|
|
#define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))
|
2014-03-19 18:40:23 +01:00
|
|
|
#define CMSG_FIRSTHDR(msg) \
|
|
|
|
((msg)->msg_controllen >= sizeof(struct cmsghdr) \
|
|
|
|
? (struct cmsghdr*) (msg)->msg_control : (struct cmsghdr*) NULL)
|
2014-02-10 13:11:29 +01:00
|
|
|
#define CMSG_OK(mhdr, cmsg) ((cmsg)->cmsg_len >= sizeof(struct cmsghdr) && (cmsg)->cmsg_len <= (unsigned long) ((mhdr)->msg_controllen - ((char*)(cmsg) - (char*)(mhdr)->msg_control)))
|
2012-09-12 04:03:02 +02:00
|
|
|
|
2016-11-16 20:35:43 +01:00
|
|
|
#if __ANDROID_API__ >= __ANDROID_API_L__
|
2017-08-17 20:29:54 +02:00
|
|
|
struct cmsghdr* __cmsg_nxthdr(struct msghdr*, struct cmsghdr*) __INTRODUCED_IN(21);
|
2016-09-09 01:12:09 +02:00
|
|
|
#else
|
|
|
|
/* TODO(danalbert): Move this into libandroid_support. */
|
|
|
|
static inline struct cmsghdr* __cmsg_nxthdr(struct msghdr* msg, struct cmsghdr* cmsg) {
|
|
|
|
struct cmsghdr* ptr =
|
|
|
|
__BIONIC_CAST(reinterpret_cast, struct cmsghdr*,
|
|
|
|
(__BIONIC_CAST(reinterpret_cast, char*, cmsg) + CMSG_ALIGN(cmsg->cmsg_len)));
|
|
|
|
size_t len = __BIONIC_CAST(reinterpret_cast, char*, ptr + 1) -
|
|
|
|
__BIONIC_CAST(reinterpret_cast, char*, msg->msg_control);
|
|
|
|
if (len > msg->msg_controllen) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
}
|
2016-11-16 20:35:43 +01:00
|
|
|
#endif /* __ANDROID_API__ >= __ANDROID_API_L__ */
|
2012-09-12 04:03:02 +02:00
|
|
|
|
|
|
|
#define SCM_RIGHTS 0x01
|
|
|
|
#define SCM_CREDENTIALS 0x02
|
|
|
|
#define SCM_SECURITY 0x03
|
|
|
|
|
|
|
|
struct ucred {
|
2014-02-10 13:11:29 +01:00
|
|
|
pid_t pid;
|
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
2012-09-12 04:03:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define AF_UNSPEC 0
|
|
|
|
#define AF_UNIX 1
|
|
|
|
#define AF_LOCAL 1
|
|
|
|
#define AF_INET 2
|
|
|
|
#define AF_AX25 3
|
|
|
|
#define AF_IPX 4
|
|
|
|
#define AF_APPLETALK 5
|
|
|
|
#define AF_NETROM 6
|
|
|
|
#define AF_BRIDGE 7
|
|
|
|
#define AF_ATMPVC 8
|
|
|
|
#define AF_X25 9
|
|
|
|
#define AF_INET6 10
|
|
|
|
#define AF_ROSE 11
|
|
|
|
#define AF_DECnet 12
|
|
|
|
#define AF_NETBEUI 13
|
|
|
|
#define AF_SECURITY 14
|
|
|
|
#define AF_KEY 15
|
|
|
|
#define AF_NETLINK 16
|
|
|
|
#define AF_ROUTE AF_NETLINK
|
|
|
|
#define AF_PACKET 17
|
|
|
|
#define AF_ASH 18
|
|
|
|
#define AF_ECONET 19
|
|
|
|
#define AF_ATMSVC 20
|
2013-01-04 01:25:47 +01:00
|
|
|
#define AF_RDS 21
|
2012-09-12 04:03:02 +02:00
|
|
|
#define AF_SNA 22
|
|
|
|
#define AF_IRDA 23
|
|
|
|
#define AF_PPPOX 24
|
|
|
|
#define AF_WANPIPE 25
|
|
|
|
#define AF_LLC 26
|
2013-01-04 01:25:47 +01:00
|
|
|
#define AF_CAN 29
|
2012-09-12 04:03:02 +02:00
|
|
|
#define AF_TIPC 30
|
|
|
|
#define AF_BLUETOOTH 31
|
2013-01-04 01:25:47 +01:00
|
|
|
#define AF_IUCV 32
|
|
|
|
#define AF_RXRPC 33
|
|
|
|
#define AF_ISDN 34
|
|
|
|
#define AF_PHONET 35
|
|
|
|
#define AF_IEEE802154 36
|
|
|
|
#define AF_CAIF 37
|
|
|
|
#define AF_ALG 38
|
2016-01-28 20:07:26 +01:00
|
|
|
#define AF_NFC 39
|
|
|
|
#define AF_VSOCK 40
|
2016-12-14 00:29:58 +01:00
|
|
|
#define AF_KCM 41
|
|
|
|
#define AF_QIPCRTR 42
|
|
|
|
#define AF_MAX 43
|
2012-09-12 04:03:02 +02:00
|
|
|
|
|
|
|
#define PF_UNSPEC AF_UNSPEC
|
|
|
|
#define PF_UNIX AF_UNIX
|
|
|
|
#define PF_LOCAL AF_LOCAL
|
|
|
|
#define PF_INET AF_INET
|
|
|
|
#define PF_AX25 AF_AX25
|
|
|
|
#define PF_IPX AF_IPX
|
|
|
|
#define PF_APPLETALK AF_APPLETALK
|
|
|
|
#define PF_NETROM AF_NETROM
|
|
|
|
#define PF_BRIDGE AF_BRIDGE
|
|
|
|
#define PF_ATMPVC AF_ATMPVC
|
|
|
|
#define PF_X25 AF_X25
|
|
|
|
#define PF_INET6 AF_INET6
|
|
|
|
#define PF_ROSE AF_ROSE
|
|
|
|
#define PF_DECnet AF_DECnet
|
|
|
|
#define PF_NETBEUI AF_NETBEUI
|
|
|
|
#define PF_SECURITY AF_SECURITY
|
|
|
|
#define PF_KEY AF_KEY
|
|
|
|
#define PF_NETLINK AF_NETLINK
|
|
|
|
#define PF_ROUTE AF_ROUTE
|
|
|
|
#define PF_PACKET AF_PACKET
|
|
|
|
#define PF_ASH AF_ASH
|
|
|
|
#define PF_ECONET AF_ECONET
|
|
|
|
#define PF_ATMSVC AF_ATMSVC
|
2013-01-04 01:25:47 +01:00
|
|
|
#define PF_RDS AF_RDS
|
2012-09-12 04:03:02 +02:00
|
|
|
#define PF_SNA AF_SNA
|
|
|
|
#define PF_IRDA AF_IRDA
|
|
|
|
#define PF_PPPOX AF_PPPOX
|
|
|
|
#define PF_WANPIPE AF_WANPIPE
|
|
|
|
#define PF_LLC AF_LLC
|
2013-01-04 01:25:47 +01:00
|
|
|
#define PF_CAN AF_CAN
|
2012-09-12 04:03:02 +02:00
|
|
|
#define PF_TIPC AF_TIPC
|
|
|
|
#define PF_BLUETOOTH AF_BLUETOOTH
|
2013-01-04 01:25:47 +01:00
|
|
|
#define PF_IUCV AF_IUCV
|
|
|
|
#define PF_RXRPC AF_RXRPC
|
|
|
|
#define PF_ISDN AF_ISDN
|
|
|
|
#define PF_PHONET AF_PHONET
|
|
|
|
#define PF_IEEE802154 AF_IEEE802154
|
2012-09-12 04:03:02 +02:00
|
|
|
#define PF_CAIF AF_CAIF
|
2013-01-04 01:25:47 +01:00
|
|
|
#define PF_ALG AF_ALG
|
2016-01-28 20:07:26 +01:00
|
|
|
#define PF_NFC AF_NFC
|
|
|
|
#define PF_VSOCK AF_VSOCK
|
2016-12-14 00:29:58 +01:00
|
|
|
#define PF_KCM AF_KCM
|
|
|
|
#define PF_QIPCRTR AF_QIPCRTR
|
2012-09-12 04:03:02 +02:00
|
|
|
#define PF_MAX AF_MAX
|
|
|
|
|
|
|
|
#define SOMAXCONN 128
|
|
|
|
|
|
|
|
#define MSG_OOB 1
|
|
|
|
#define MSG_PEEK 2
|
|
|
|
#define MSG_DONTROUTE 4
|
|
|
|
#define MSG_TRYHARD 4
|
|
|
|
#define MSG_CTRUNC 8
|
|
|
|
#define MSG_PROBE 0x10
|
|
|
|
#define MSG_TRUNC 0x20
|
|
|
|
#define MSG_DONTWAIT 0x40
|
|
|
|
#define MSG_EOR 0x80
|
|
|
|
#define MSG_WAITALL 0x100
|
|
|
|
#define MSG_FIN 0x200
|
|
|
|
#define MSG_SYN 0x400
|
|
|
|
#define MSG_CONFIRM 0x800
|
|
|
|
#define MSG_RST 0x1000
|
|
|
|
#define MSG_ERRQUEUE 0x2000
|
|
|
|
#define MSG_NOSIGNAL 0x4000
|
|
|
|
#define MSG_MORE 0x8000
|
2014-02-10 13:11:29 +01:00
|
|
|
#define MSG_WAITFORONE 0x10000
|
2016-12-14 00:29:58 +01:00
|
|
|
#define MSG_BATCH 0x40000
|
2014-02-10 13:11:29 +01:00
|
|
|
#define MSG_FASTOPEN 0x20000000
|
|
|
|
#define MSG_CMSG_CLOEXEC 0x40000000
|
2012-09-12 04:03:02 +02:00
|
|
|
#define MSG_EOF MSG_FIN
|
|
|
|
#define MSG_CMSG_COMPAT 0
|
|
|
|
|
|
|
|
#define SOL_IP 0
|
|
|
|
#define SOL_TCP 6
|
|
|
|
#define SOL_UDP 17
|
|
|
|
#define SOL_IPV6 41
|
|
|
|
#define SOL_ICMPV6 58
|
|
|
|
#define SOL_SCTP 132
|
|
|
|
#define SOL_RAW 255
|
|
|
|
#define SOL_IPX 256
|
|
|
|
#define SOL_AX25 257
|
|
|
|
#define SOL_ATALK 258
|
|
|
|
#define SOL_NETROM 259
|
|
|
|
#define SOL_ROSE 260
|
|
|
|
#define SOL_DECNET 261
|
|
|
|
#define SOL_X25 262
|
|
|
|
#define SOL_PACKET 263
|
|
|
|
#define SOL_ATM 264
|
|
|
|
#define SOL_AAL 265
|
|
|
|
#define SOL_IRDA 266
|
|
|
|
#define SOL_NETBEUI 267
|
|
|
|
#define SOL_LLC 268
|
|
|
|
#define SOL_DCCP 269
|
|
|
|
#define SOL_NETLINK 270
|
|
|
|
#define SOL_TIPC 271
|
2016-12-14 00:29:58 +01:00
|
|
|
#define SOL_RXRPC 272
|
|
|
|
#define SOL_PPPOL2TP 273
|
|
|
|
#define SOL_BLUETOOTH 274
|
|
|
|
#define SOL_PNPIPE 275
|
|
|
|
#define SOL_RDS 276
|
|
|
|
#define SOL_IUCV 277
|
|
|
|
#define SOL_CAIF 278
|
|
|
|
#define SOL_ALG 279
|
|
|
|
#define SOL_NFC 280
|
|
|
|
#define SOL_KCM 281
|
2012-09-12 04:03:02 +02:00
|
|
|
|
|
|
|
#define IPX_TYPE 1
|
|
|
|
|
|
|
|
#ifdef __i386__
|
|
|
|
# define __socketcall extern __attribute__((__cdecl__))
|
|
|
|
#else
|
|
|
|
# define __socketcall extern
|
|
|
|
#endif
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2017-08-17 20:29:54 +02:00
|
|
|
__socketcall int accept(int, struct sockaddr*, socklen_t*);
|
|
|
|
__socketcall int accept4(int, struct sockaddr*, socklen_t*, int) __INTRODUCED_IN(21);
|
|
|
|
__socketcall int bind(int, const struct sockaddr*, socklen_t);
|
|
|
|
__socketcall int connect(int, const struct sockaddr*, socklen_t);
|
|
|
|
__socketcall int getpeername(int, struct sockaddr*, socklen_t*);
|
|
|
|
__socketcall int getsockname(int, struct sockaddr*, socklen_t*);
|
|
|
|
__socketcall int getsockopt(int, int, int, void*, socklen_t*);
|
|
|
|
__socketcall int listen(int, int);
|
|
|
|
__socketcall int recvmmsg(int, struct mmsghdr*, unsigned int, int, const struct timespec*)
|
2016-04-29 21:00:55 +02:00
|
|
|
__INTRODUCED_IN(21);
|
2017-08-17 20:29:54 +02:00
|
|
|
__socketcall ssize_t recvmsg(int, struct msghdr*, int);
|
|
|
|
__socketcall int sendmmsg(int, const struct mmsghdr*, unsigned int, int) __INTRODUCED_IN(21);
|
|
|
|
__socketcall ssize_t sendmsg(int, const struct msghdr*, int);
|
|
|
|
__socketcall int setsockopt(int, int, int, const void*, socklen_t);
|
|
|
|
__socketcall int shutdown(int, int);
|
|
|
|
__socketcall int socket(int, int, int);
|
|
|
|
__socketcall int socketpair(int, int, int, int*);
|
|
|
|
|
|
|
|
ssize_t recv(int, void*, size_t, int) __overloadable __RENAME_CLANG(recv);
|
|
|
|
ssize_t send(int, const void*, size_t, int) __overloadable __RENAME_CLANG(send);
|
|
|
|
|
|
|
|
__socketcall ssize_t sendto(int, const void*, size_t, int, const struct sockaddr*, socklen_t)
|
2017-02-14 02:27:59 +01:00
|
|
|
__overloadable __RENAME_CLANG(sendto);
|
2017-08-17 20:29:54 +02:00
|
|
|
__socketcall ssize_t recvfrom(int, void*, size_t, int, struct sockaddr*,
|
|
|
|
socklen_t*) __overloadable __RENAME_CLANG(recvfrom);
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2017-07-25 00:05:05 +02:00
|
|
|
#if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
|
|
|
|
#include <bits/fortify/socket.h>
|
|
|
|
#endif
|
2013-09-25 01:32:07 +02:00
|
|
|
|
2009-03-04 04:28:35 +01:00
|
|
|
#undef __socketcall
|
|
|
|
|
|
|
|
__END_DECLS
|
|
|
|
|
2017-08-17 20:29:54 +02:00
|
|
|
#endif /* _SYS_SOCKET_H */
|