New developer version 0.6.8; added select () function; added demonstrating example...
[ZeXOS.git] / kernel / include / net / socket.h
blob8019972ea235f177b9cf57735c8583d511abc4cc
1 /*
2 * ZeX/OS
3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2010 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef _SOCKET_H
21 #define _SOCKET_H
23 #include <_size_t.h>
25 /* Supported address families. */
26 #define AF_UNSPEC 0
27 #define AF_UNIX 1 /* Unix domain sockets */
28 #define AF_LOCAL 1 /* POSIX name for AF_UNIX */
29 #define AF_INET 2 /* Internet IP Protocol */
30 #define AF_AX25 3 /* Amateur Radio AX.25 */
31 #define AF_IPX 4 /* Novell IPX */
32 #define AF_APPLETALK 5 /* AppleTalk DDP */
33 #define AF_NETROM 6 /* Amateur Radio NET/ROM */
34 #define AF_BRIDGE 7 /* Multiprotocol bridge */
35 #define AF_ATMPVC 8 /* ATM PVCs */
36 #define AF_X25 9 /* Reserved for X.25 project */
37 #define AF_INET6 10 /* IP version 6 */
38 #define AF_ROSE 11 /* Amateur Radio X.25 PLP */
39 #define AF_DECnet 12 /* Reserved for DECnet project */
40 #define AF_NETBEUI 13 /* Reserved for 802.2LLC project*/
41 #define AF_SECURITY 14 /* Security callback pseudo AF */
42 #define AF_KEY 15 /* PF_KEY key management API */
43 #define AF_NETLINK 16
44 #define AF_ROUTE AF_NETLINK /* Alias to emulate 4.4BSD */
45 #define AF_PACKET 17 /* Packet family */
46 #define AF_ASH 18 /* Ash */
47 #define AF_ECONET 19 /* Acorn Econet */
48 #define AF_ATMSVC 20 /* ATM SVCs */
49 #define AF_SNA 22 /* Linux SNA Project (nutters!) */
50 #define AF_IRDA 23 /* IRDA sockets */
51 #define AF_PPPOX 24 /* PPPoX sockets */
52 #define AF_WANPIPE 25 /* Wanpipe API Sockets */
53 #define AF_LLC 26 /* Linux LLC */
54 #define AF_TIPC 30 /* TIPC sockets */
55 #define AF_BLUETOOTH 31 /* Bluetooth sockets */
56 #define AF_IUCV 32 /* IUCV sockets */
57 #define AF_RXRPC 33 /* RxRPC sockets */
58 #define AF_MAX 34 /* For now.. */
59 #define AF_RS232 35 /* Serial socket (NEW!) */
61 /* Protocol families, same as address families. */
62 #define PF_UNSPEC AF_UNSPEC
63 #define PF_UNIX AF_UNIX
64 #define PF_LOCAL AF_LOCAL
65 #define PF_INET AF_INET
66 #define PF_AX25 AF_AX25
67 #define PF_IPX AF_IPX
68 #define PF_APPLETALK AF_APPLETALK
69 #define PF_NETROM AF_NETROM
70 #define PF_BRIDGE AF_BRIDGE
71 #define PF_ATMPVC AF_ATMPVC
72 #define PF_X25 AF_X25
73 #define PF_INET6 AF_INET6
74 #define PF_ROSE AF_ROSE
75 #define PF_DECnet AF_DECnet
76 #define PF_NETBEUI AF_NETBEUI
77 #define PF_SECURITY AF_SECURITY
78 #define PF_KEY AF_KEY
79 #define PF_NETLINK AF_NETLINK
80 #define PF_ROUTE AF_ROUTE
81 #define PF_PACKET AF_PACKET
82 #define PF_ASH AF_ASH
83 #define PF_ECONET AF_ECONET
84 #define PF_ATMSVC AF_ATMSVC
85 #define PF_SNA AF_SNA
86 #define PF_IRDA AF_IRDA
87 #define PF_PPPOX AF_PPPOX
88 #define PF_WANPIPE AF_WANPIPE
89 #define PF_LLC AF_LLC
90 #define PF_TIPC AF_TIPC
91 #define PF_BLUETOOTH AF_BLUETOOTH
92 #define PF_IUCV AF_IUCV
93 #define PF_RXRPC AF_RXRPC
94 #define PF_MAX AF_MAX
95 #define PF_RS232 AF_RS232
97 /* Maximum queue length specifiable by listen. */
98 #define SOMAXCONN 128
100 /* Flags we can use with send/ and recv.
101 Added those for 1003.1g not all are supported yet
104 #define MSG_OOB 1
105 #define MSG_PEEK 2
106 #define MSG_DONTROUTE 4
107 #define MSG_TRYHARD 4 /* Synonym for MSG_DONTROUTE for DECnet */
108 #define MSG_CTRUNC 8
109 #define MSG_PROBE 0x10 /* Do not send. Only probe path f.e. for MTU */
110 #define MSG_TRUNC 0x20
111 #define MSG_DONTWAIT 0x40 /* Nonblocking io */
112 #define MSG_EOR 0x80 /* End of record */
113 #define MSG_WAITALL 0x100 /* Wait for a full request */
114 #define MSG_FIN 0x200
115 #define MSG_SYN 0x400
116 #define MSG_CONFIRM 0x800 /* Confirm path validity */
117 #define MSG_RST 0x1000
118 #define MSG_ERRQUEUE 0x2000 /* Fetch message from error queue */
119 #define MSG_NOSIGNAL 0x4000 /* Do not generate SIGPIPE */
120 #define MSG_MORE 0x8000 /* Sender will send more */
122 #define MSG_EOF MSG_FIN
124 #if defined(CONFIG_COMPAT)
125 #define MSG_CMSG_COMPAT 0x80000000 /* This message needs 32 bit fixups */
126 #else
127 #define MSG_CMSG_COMPAT 0 /* We never have 32 bit fixups */
128 #endif
131 /* Setsockoptions(2) level. Thanks to BSD these must match IPPROTO_xxx */
132 #define SOL_IP 0
133 /* #define SOL_ICMP 1 No-no-no! Due to Linux :-) we cannot use SOL_ICMP=1 */
134 #define SOL_TCP 6
135 #define SOL_UDP 17
136 #define SOL_IPV6 41
137 #define SOL_ICMPV6 58
138 #define SOL_SCTP 132
139 #define SOL_UDPLITE 136 /* UDP-Lite (RFC 3828) */
140 #define SOL_RAW 255
141 #define SOL_IPX 256
142 #define SOL_AX25 257
143 #define SOL_ATALK 258
144 #define SOL_NETROM 259
145 #define SOL_ROSE 260
146 #define SOL_DECNET 261
147 #define SOL_X25 262
148 #define SOL_PACKET 263
149 #define SOL_ATM 264 /* ATM layer (cell level) */
150 #define SOL_AAL 265 /* ATM Adaption Layer (packet level) */
151 #define SOL_IRDA 266
152 #define SOL_NETBEUI 267
153 #define SOL_LLC 268
154 #define SOL_DCCP 269
155 #define SOL_NETLINK 270
156 #define SOL_TIPC 271
157 #define SOL_RXRPC 272
159 /* IPX options */
160 #define IPX_TYPE 1
162 /* Sock types */
163 #define SOCK_STREAM 1 /* stream (connection) socket */
164 #define SOCK_DGRAM 2 /* datagram (conn.less) socket */
165 #define SOCK_RAW 3 /* raw socket */
166 #define SOCK_RDM 4 /* reliably-delivered message */
167 #define SOCK_SEQPACKET 5 /* sequential packet socket */
168 #define SOCK_PACKET 10 /* linux specified */
170 #define _NETINET_IN_H_
171 #define IPPROTO_IP 0 // Dummy for IP.
172 #define IPPROTO_ICMP 1 // Control message protocol.
173 #define IPPROTO_IGMP 2 // Group management protocol.
174 #define IPPROTO_TCP 6 // Transmission control protocol.
175 #define IPPROTO_UDP 17 // User datagram protocol.
176 #define IPPROTO_RAW 255 // Raw IP packet.
177 #define IPPROTO_MAX 256 // Maximum protocol identifier.
178 #define IPPORT_RESERVED 1024 // Last reserved port number.
179 #define IPPORT_USERRESERVED 5000 // User reserved port number.
180 #define INADDR_ANY 0x00000000 // Any IP address.
181 #define INADDR_BROADCAST 0xffffffff // Broadcast IP address.
183 #define FD_SOCK 0x100
185 typedef unsigned socklen_t;
187 /* Device structure */
188 typedef struct socket_context {
189 struct socket_context *next, *prev;
191 unsigned fd;
192 int family;
193 int type;
194 int protocol;
195 } socket_t;
197 typedef struct {
198 unsigned short s6_addr[8]; /* IPv6 address */
199 } in6_addr;
201 typedef struct {
202 unsigned short sa_family;
203 char sa_data[14];
204 } sockaddr;
206 typedef struct
208 int sin_family;
209 int sin_port;
210 unsigned sin_addr;
211 } sockaddr_in;
213 typedef struct {
214 unsigned char sin6_len; /* length of this structure */
215 unsigned char sin6_family; /* AF_INET6 */
216 unsigned short sin6_port; /* Transport layer port # */
217 unsigned sin6_flowinfo; /* IPv6 flow information */
218 unsigned short sin6_addr[8]; /* IPv6 address */
219 } sockaddr_in6;
221 typedef struct {
222 unsigned short sun_family; /* AF_UNIX */
223 char sun_path[108];
224 } sockaddr_un;
226 typedef struct {
227 char *h_name;
228 char **h_aliases;
229 int h_addrtype;
230 unsigned h_length;
231 char **h_addr_list;
232 char *h_addr;
233 } hostent;
235 //extern int htons (int port);
236 extern hostent *gethostbyname (char *hostname);
237 extern int socket (int family, int type, int protocol);
238 extern int connect (int fd, sockaddr *addr, socklen_t len);
239 extern int send (int fd, char *msg, size_t size, int flags);
240 extern int recv (int fd, char *msg, size_t size, int flags);
241 extern int bind (int fd, sockaddr *addr, socklen_t len);
242 extern int sclose (int fd);
243 extern int sfcntl (int fd, int cmd, long arg);
244 extern int sselect (int readfd, int writefd, int exceptfd);
245 extern unsigned int init_socket ();
247 #endif