wut  1.0.0-alpha
Wii U Toolchain
socket.h
Go to the documentation of this file.
1 #pragma once
2 #include <wut.h>
3 #include <stdint.h>
4 
5 #define FD_SETSIZE 32
6 #include <sys/time.h>
7 #include <sys/types.h>
8 #include <sys/select.h>
9 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 #define SOL_SOCKET -1
20 
21 #define INADDR_ANY 0
22 #define INADDR_BROADCAST 0xFFFFFFFF
23 
24 #define PF_UNSPEC 0
25 #define PF_INET 2
26 #define PF_INET6 23
27 
28 #define AF_UNSPEC PF_UNSPEC
29 #define AF_INET PF_INET
30 #define AF_INET6 PF_INET6
31 
32 #define SOCK_STREAM 1
33 #define SOCK_DGRAM 2
34 
35 #define MSG_OOB 0x0001
36 #define MSG_PEEK 0x0002
37 #define MSG_DONTROUTE 0x0004
38 #define MSG_DONTWAIT 0x0020
39 
40 #define SHUT_RD 0
41 #define SHUT_WR 1
42 #define SHUT_RDWR 2
43 
44 #define IPPROTO_IP 0
45 #define IPPROTO_TCP 6
46 #define IPPROTO_UDP 17
47 
48 /*
49  * SOL_SOCKET options
50  */
51 #define SO_REUSEADDR 0x0004 // reuse address
52 #define SO_BROADCAST 0x0020 // broadcast
53 #define SO_LINGER 0x0080 // linger (no effect?)
54 #define SO_OOBINLINE 0x0100 // out-of-band data inline (no effect?)
55 #define SO_SNDBUF 0x1001 // send buffer size
56 #define SO_RCVBUF 0x1002 // receive buffer size
57 #define SO_SNDLOWAT 0x1003 // send low-water mark (no effect?)
58 #define SO_RCVLOWAT 0x1004 // receive low-water mark
59 #define SO_TYPE 0x1008 // get socket type
60 #define SO_ERROR 0x1009 // get socket error
61 #define SO_NBIO 0x1014 // set socket to NON-blocking mode
62 #define SO_BIO 0x1015 // set socket to blocking mode
63 #define SO_NONBLOCK 0x1016 // set/get blocking mode via optval param
64 
65 /*
66  * Errors returned by nsysnet socket functions
67  * WARNING: these do not match with sys/errno.h (where EAGAIN is 11 for example).
68  */
69 #define NSN_EAGAIN 6
70 #define NSN_EWOULDBLOCK 6
71 
72 typedef uint32_t socklen_t;
73 typedef uint16_t sa_family_t;
74 
75 struct sockaddr
76 {
78  char sa_data[];
79 };
80 
82 {
84  char __ss_padding[32];
85 };
86 
87 struct linger
88 {
89  int l_onoff;
90  int l_linger;
91 };
92 
93 struct in_addr
94 {
95  unsigned int s_addr;
96 };
97 
99 {
100  unsigned short sin_family;
101  unsigned short sin_port;
103  char sin_zero[8];
104 };
105 
106 void
108 
109 void
111 
112 int
113 accept(int sockfd,
114  struct sockaddr *addr,
115  socklen_t *addrlen);
116 
117 int
118 bind(int sockfd,
119  const struct sockaddr *addr,
120  socklen_t addrlen);
121 
122 int
123 socketclose(int sockfd);
124 
125 int
126 connect(int sockfd,
127  const struct sockaddr *addr,
128  socklen_t addrlen);
129 
130 int
131 getpeername(int sockfd,
132  struct sockaddr *addr,
133  socklen_t *addrlen);
134 
135 int
136 getsockname(int sockfd,
137  struct sockaddr *addr,
138  socklen_t *addrlen);
139 
140 int
141 getsockopt(int sockfd,
142  int level,
143  int optname,
144  void *optval,
145  socklen_t *optlen);
146 
147 int
148 listen(int sockfd,
149  int backlog);
150 
151 int
152 recv(int sockfd,
153  void *buf,
154  size_t len,
155  int flags);
156 
157 int
158 recvfrom(int sockfd,
159  void *buf,
160  size_t len,
161  int flags,
162  struct sockaddr *src_addr,
163  socklen_t *addrlen);
164 
165 int
166 send(int sockfd,
167  const void *buf,
168  size_t len,
169  int flags);
170 
171 int
172 sendto(int sockfd,
173  const void *buf,
174  size_t len,
175  int flags,
176  const struct sockaddr *dest_addr,
177  socklen_t addrlen);
178 
179 int
180 setsockopt(int sockfd,
181  int level,
182  int optname,
183  const void *optval,
184  socklen_t optlen);
185 
186 int
187 shutdown(int sockfd,
188  int how);
189 
190 int
191 socket(int domain,
192  int type,
193  int protocol);
194 
195 int
196 select(int nfds,
197  fd_set *readfds,
198  fd_set *writefds,
199  fd_set *exceptfds,
200  struct timeval *timeout);
201 
202 const char *
203 inet_ntoa(struct in_addr in);
204 
205 int
206 inet_aton(const char *cp, struct in_addr *inp);
207 
208 int
209 socketlasterr();
210 
211 uint32_t
212 htonl(uint32_t val);
213 
214 uint16_t
215 htons(uint16_t val);
216 
217 uint32_t
218 ntohl(uint32_t val);
219 
220 uint16_t
221 ntohs(uint16_t val);
222 
223 #ifdef __cplusplus
224 }
225 #endif
226 
int recv(int sockfd, void *buf, size_t len, int flags)
const char * inet_ntoa(struct in_addr in)
unsigned short sin_port
Definition: socket.h:101
int listen(int sockfd, int backlog)
int l_linger
Definition: socket.h:90
sa_family_t sa_family
Definition: socket.h:77
void socket_lib_finish()
int socketlasterr()
sa_family_t ss_family
Definition: socket.h:83
struct in_addr sin_addr
Definition: socket.h:102
uint16_t ntohs(uint16_t val)
int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
char sin_zero[8]
Definition: socket.h:103
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
uint32_t ntohl(uint32_t val)
int recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen)
uint16_t sa_family_t
Definition: socket.h:73
int inet_aton(const char *cp, struct in_addr *inp)
int send(int sockfd, const void *buf, size_t len, int flags)
int socket(int domain, int type, int protocol)
char sa_data[]
Definition: socket.h:78
void socket_lib_init()
char __ss_padding[32]
Definition: socket.h:84
int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen)
int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
uint16_t htons(uint16_t val)
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
int l_onoff
Definition: socket.h:89
unsigned short sin_family
Definition: socket.h:100
int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen)
int sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
Definition: socket.h:93
uint32_t socklen_t
Definition: socket.h:72
unsigned int s_addr
Definition: socket.h:95
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
int socketclose(int sockfd)
int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
uint32_t htonl(uint32_t val)
int shutdown(int sockfd, int how)
Definition: socket.h:87