9 |
#include <klibc/compiler.h> |
#include <klibc/compiler.h> |
10 |
#include <klibc/sysconfig.h> |
#include <klibc/sysconfig.h> |
11 |
#include <linux/socket.h> |
#include <linux/socket.h> |
12 |
|
#include <linux/uio.h> |
13 |
|
#include <asm/socket.h> |
14 |
#if _KLIBC_HAS_ARCHSOCKET_H |
#if _KLIBC_HAS_ARCHSOCKET_H |
15 |
#include <klibc/archsocket.h> |
#include <klibc/archsocket.h> |
16 |
#endif |
#endif |
19 |
that are hidden under #ifdef __KERNEL__... what a brilliant idea! |
that are hidden under #ifdef __KERNEL__... what a brilliant idea! |
20 |
These are the "common" definitions; if not appropriate, override |
These are the "common" definitions; if not appropriate, override |
21 |
them in <klibc/archsocket.h>. */ |
them in <klibc/archsocket.h>. */ |
22 |
|
|
23 |
#ifndef SOCK_STREAM |
#ifndef SOCK_STREAM |
24 |
# define SOCK_STREAM 1 |
# define SOCK_STREAM 1 |
25 |
# define SOCK_DGRAM 2 |
# define SOCK_DGRAM 2 |
29 |
# define SOCK_PACKET 10 |
# define SOCK_PACKET 10 |
30 |
#endif |
#endif |
31 |
|
|
32 |
|
#ifndef AF_INET |
33 |
|
#define AF_UNSPEC 0 |
34 |
|
#define AF_UNIX 1 /* Unix domain sockets */ |
35 |
|
#define AF_LOCAL 1 /* POSIX name for AF_UNIX */ |
36 |
|
#define AF_INET 2 /* Internet IP Protocol */ |
37 |
|
#define AF_AX25 3 /* Amateur Radio AX.25 */ |
38 |
|
#define AF_IPX 4 /* Novell IPX */ |
39 |
|
#define AF_APPLETALK 5 /* AppleTalk DDP */ |
40 |
|
#define AF_NETROM 6 /* Amateur Radio NET/ROM */ |
41 |
|
#define AF_BRIDGE 7 /* Multiprotocol bridge */ |
42 |
|
#define AF_ATMPVC 8 /* ATM PVCs */ |
43 |
|
#define AF_X25 9 /* Reserved for X.25 project */ |
44 |
|
#define AF_INET6 10 /* IP version 6 */ |
45 |
|
#define AF_ROSE 11 /* Amateur Radio X.25 PLP */ |
46 |
|
#define AF_DECnet 12 /* Reserved for DECnet project */ |
47 |
|
#define AF_NETBEUI 13 /* Reserved for 802.2LLC project*/ |
48 |
|
#define AF_SECURITY 14 /* Security callback pseudo AF */ |
49 |
|
#define AF_KEY 15 /* PF_KEY key management API */ |
50 |
|
#define AF_NETLINK 16 |
51 |
|
#define AF_ROUTE AF_NETLINK /* Alias to emulate 4.4BSD */ |
52 |
|
#define AF_PACKET 17 /* Packet family */ |
53 |
|
#define AF_ASH 18 /* Ash */ |
54 |
|
#define AF_ECONET 19 /* Acorn Econet */ |
55 |
|
#define AF_ATMSVC 20 /* ATM SVCs */ |
56 |
|
#define AF_RDS 21 /* RDS sockets */ |
57 |
|
#define AF_SNA 22 /* Linux SNA Project (nutters!) */ |
58 |
|
#define AF_IRDA 23 /* IRDA sockets */ |
59 |
|
#define AF_PPPOX 24 /* PPPoX sockets */ |
60 |
|
#define AF_WANPIPE 25 /* Wanpipe API Sockets */ |
61 |
|
#define AF_LLC 26 /* Linux LLC */ |
62 |
|
#define AF_CAN 29 /* Controller Area Network */ |
63 |
|
#define AF_TIPC 30 /* TIPC sockets */ |
64 |
|
#define AF_BLUETOOTH 31 /* Bluetooth sockets */ |
65 |
|
#define AF_IUCV 32 /* IUCV sockets */ |
66 |
|
#define AF_RXRPC 33 /* RxRPC sockets */ |
67 |
|
#define AF_ISDN 34 /* mISDN sockets */ |
68 |
|
#define AF_PHONET 35 /* Phonet sockets */ |
69 |
|
#define AF_IEEE802154 36 /* IEEE802154 sockets */ |
70 |
|
#define AF_MAX 37 /* For now.. */ |
71 |
|
#endif // !AF_INET |
72 |
|
|
73 |
|
#ifndef PF_UNSPEC |
74 |
|
#define PF_UNSPEC AF_UNSPEC |
75 |
|
#define PF_UNIX AF_UNIX |
76 |
|
#define PF_LOCAL AF_LOCAL |
77 |
|
#define PF_INET AF_INET |
78 |
|
#define PF_AX25 AF_AX25 |
79 |
|
#define PF_IPX AF_IPX |
80 |
|
#define PF_APPLETALK AF_APPLETALK |
81 |
|
#define PF_NETROM AF_NETROM |
82 |
|
#define PF_BRIDGE AF_BRIDGE |
83 |
|
#define PF_ATMPVC AF_ATMPVC |
84 |
|
#define PF_X25 AF_X25 |
85 |
|
#define PF_INET6 AF_INET6 |
86 |
|
#define PF_ROSE AF_ROSE |
87 |
|
#define PF_DECnet AF_DECnet |
88 |
|
#define PF_NETBEUI AF_NETBEUI |
89 |
|
#define PF_SECURITY AF_SECURITY |
90 |
|
#define PF_KEY AF_KEY |
91 |
|
#define PF_NETLINK AF_NETLINK |
92 |
|
#define PF_ROUTE AF_ROUTE |
93 |
|
#define PF_PACKET AF_PACKET |
94 |
|
#define PF_ASH AF_ASH |
95 |
|
#define PF_ECONET AF_ECONET |
96 |
|
#define PF_ATMSVC AF_ATMSVC |
97 |
|
#define PF_RDS AF_RDS |
98 |
|
#define PF_SNA AF_SNA |
99 |
|
#define PF_IRDA AF_IRDA |
100 |
|
#define PF_PPPOX AF_PPPOX |
101 |
|
#define PF_WANPIPE AF_WANPIPE |
102 |
|
#define PF_LLC AF_LLC |
103 |
|
#define PF_CAN AF_CAN |
104 |
|
#define PF_TIPC AF_TIPC |
105 |
|
#define PF_BLUETOOTH AF_BLUETOOTH |
106 |
|
#define PF_IUCV AF_IUCV |
107 |
|
#define PF_RXRPC AF_RXRPC |
108 |
|
#define PF_ISDN AF_ISDN |
109 |
|
#define PF_PHONET AF_PHONET |
110 |
|
#define PF_IEEE802154 AF_IEEE802154 |
111 |
|
#define PF_MAX AF_MAX |
112 |
|
#endif // !PF_UNSPEC |
113 |
|
|
114 |
|
#ifndef MSG_OOB |
115 |
|
#define MSG_OOB 1 |
116 |
|
#define MSG_PEEK 2 |
117 |
|
#define MSG_DONTROUTE 4 |
118 |
|
#define MSG_TRYHARD 4 /* Synonym for MSG_DONTROUTE for DECnet */ |
119 |
|
#define MSG_CTRUNC 8 |
120 |
|
#define MSG_PROBE 0x10 /* Do not send. Only probe path f.e. for MTU */ |
121 |
|
#define MSG_TRUNC 0x20 |
122 |
|
#define MSG_DONTWAIT 0x40 /* Nonblocking io */ |
123 |
|
#define MSG_EOR 0x80 /* End of record */ |
124 |
|
#define MSG_WAITALL 0x100 /* Wait for a full request */ |
125 |
|
#define MSG_FIN 0x200 |
126 |
|
#define MSG_SYN 0x400 |
127 |
|
#define MSG_CONFIRM 0x800 /* Confirm path validity */ |
128 |
|
#define MSG_RST 0x1000 |
129 |
|
#define MSG_ERRQUEUE 0x2000 /* Fetch message from error queue */ |
130 |
|
#define MSG_NOSIGNAL 0x4000 /* Do not generate SIGPIPE */ |
131 |
|
#define MSG_MORE 0x8000 /* Sender will send more */ |
132 |
|
|
133 |
|
#define MSG_EOF MSG_FIN |
134 |
|
|
135 |
|
#define MSG_CMSG_CLOEXEC 0x40000000 /* Set close_on_exit for file |
136 |
|
descriptor received through |
137 |
|
SCM_RIGHTS */ |
138 |
|
#if defined(CONFIG_COMPAT) |
139 |
|
#define MSG_CMSG_COMPAT 0x80000000 /* This message needs 32 bit fixups */ |
140 |
|
#else |
141 |
|
#define MSG_CMSG_COMPAT 0 /* We never have 32 bit fixups */ |
142 |
|
#endif |
143 |
|
#endif // !MSG_OOB |
144 |
|
|
145 |
|
/* These types is hidden under __KERNEL__ in kernel sources */ |
146 |
|
typedef unsigned short sa_family_t; |
147 |
|
struct sockaddr { |
148 |
|
sa_family_t sa_family; /* address family, AF_xxx */ |
149 |
|
char sa_data[14]; /* 14 bytes of protocol address */ |
150 |
|
}; |
151 |
typedef int socklen_t; |
typedef int socklen_t; |
152 |
|
struct msghdr { |
153 |
|
void *msg_name; |
154 |
|
int msg_namelen; |
155 |
|
struct iovec *msg_iov; |
156 |
|
size_t msg_iovlen; |
157 |
|
void *msg_control; |
158 |
|
size_t msg_controllen; |
159 |
|
unsigned msg_flags; |
160 |
|
}; |
161 |
|
|
162 |
|
/* Ancillary data structures and cmsg macros are also hidden under __KERNEL__ */ |
163 |
|
#ifndef CMSG_FIRSTHDR |
164 |
|
/* |
165 |
|
* POSIX 1003.1g - ancillary data object information |
166 |
|
* Ancillary data consits of a sequence of pairs of |
167 |
|
* (cmsghdr, cmsg_data[]) |
168 |
|
*/ |
169 |
|
|
170 |
|
struct cmsghdr { |
171 |
|
__kernel_size_t cmsg_len; /* data byte count, including hdr */ |
172 |
|
int cmsg_level; /* originating protocol */ |
173 |
|
int cmsg_type; /* protocol-specific type */ |
174 |
|
}; |
175 |
|
|
176 |
|
/* |
177 |
|
* Ancilliary data object information MACROS |
178 |
|
* Table 5-14 of POSIX 1003.1g |
179 |
|
*/ |
180 |
|
|
181 |
|
#define __CMSG_NXTHDR(ctl, len, cmsg) __cmsg_nxthdr((ctl),(len),(cmsg)) |
182 |
|
#define CMSG_NXTHDR(mhdr, cmsg) cmsg_nxthdr((mhdr), (cmsg)) |
183 |
|
|
184 |
|
#define CMSG_ALIGN(len) ( ((len)+sizeof(long)-1) & ~(sizeof(long)-1) ) |
185 |
|
|
186 |
|
#define CMSG_DATA(cmsg) ((void *)((char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr)))) |
187 |
|
#define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len)) |
188 |
|
#define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len)) |
189 |
|
|
190 |
|
#define __CMSG_FIRSTHDR(ctl,len) ((len) >= sizeof(struct cmsghdr) ? \ |
191 |
|
(struct cmsghdr *)(ctl) : \ |
192 |
|
(struct cmsghdr *)NULL) |
193 |
|
#define CMSG_FIRSTHDR(msg) __CMSG_FIRSTHDR((msg)->msg_control, (msg)->msg_controllen) |
194 |
|
#define CMSG_OK(mhdr, cmsg) ((cmsg)->cmsg_len >= sizeof(struct cmsghdr) && \ |
195 |
|
(cmsg)->cmsg_len <= (unsigned long) \ |
196 |
|
((mhdr)->msg_controllen - \ |
197 |
|
((char *)(cmsg) - (char *)(mhdr)->msg_control))) |
198 |
|
|
199 |
|
/* |
200 |
|
* Get the next cmsg header |
201 |
|
* |
202 |
|
* PLEASE, do not touch this function. If you think, that it is |
203 |
|
* incorrect, grep kernel sources and think about consequences |
204 |
|
* before trying to improve it. |
205 |
|
* |
206 |
|
* Now it always returns valid, not truncated ancillary object |
207 |
|
* HEADER. But caller still MUST check, that cmsg->cmsg_len is |
208 |
|
* inside range, given by msg->msg_controllen before using |
209 |
|
* ancillary object DATA. --ANK (980731) |
210 |
|
*/ |
211 |
|
|
212 |
|
static inline struct cmsghdr * __cmsg_nxthdr(void *__ctl, __kernel_size_t __size, |
213 |
|
struct cmsghdr *__cmsg) |
214 |
|
{ |
215 |
|
struct cmsghdr * __ptr; |
216 |
|
|
217 |
|
__ptr = (struct cmsghdr*)(((unsigned char *) __cmsg) + CMSG_ALIGN(__cmsg->cmsg_len)); |
218 |
|
if ((unsigned long)((char*)(__ptr+1) - (char *) __ctl) > __size) |
219 |
|
return (struct cmsghdr *)0; |
220 |
|
|
221 |
|
return __ptr; |
222 |
|
} |
223 |
|
|
224 |
|
static inline struct cmsghdr * cmsg_nxthdr (struct msghdr *__msg, struct cmsghdr *__cmsg) |
225 |
|
{ |
226 |
|
return __cmsg_nxthdr(__msg->msg_control, __msg->msg_controllen, __cmsg); |
227 |
|
} |
228 |
|
|
229 |
|
/* "Socket"-level control message types: */ |
230 |
|
|
231 |
|
#define SCM_RIGHTS 0x01 /* rw: access rights (array of int) */ |
232 |
|
#define SCM_CREDENTIALS 0x02 /* rw: struct ucred */ |
233 |
|
#define SCM_SECURITY 0x03 /* rw: security label */ |
234 |
|
|
235 |
|
struct ucred { |
236 |
|
__u32 pid; |
237 |
|
__u32 uid; |
238 |
|
__u32 gid; |
239 |
|
}; |
240 |
|
#endif /* CMSG_FIRSTHDR */ |
241 |
|
|
242 |
|
|
243 |
__extern int socket(int, int, int); |
__extern int socket(int, int, int); |
244 |
__extern int bind(int, struct sockaddr *, int); |
__extern int bind(int, struct sockaddr *, int); |