wut  1.0.0-beta9
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_TCPSACK 0x0200 // set tcp selective acknowledgment
56 #define SO_WINSCALE 0x0400 // set tcp window scaling
57 #define SO_SNDBUF 0x1001 // send buffer size
58 #define SO_RCVBUF 0x1002 // receive buffer size
59 #define SO_SNDLOWAT 0x1003 // send low-water mark (no effect?)
60 #define SO_RCVLOWAT 0x1004 // receive low-water mark
61 #define SO_TYPE 0x1008 // get socket type
62 #define SO_ERROR 0x1009 // get socket error
63 #define SO_NBIO 0x1014 // set socket to NON-blocking mode
64 #define SO_BIO 0x1015 // set socket to blocking mode
65 #define SO_NONBLOCK 0x1016 // set/get blocking mode via optval param
66 
67 /*
68  * Errors returned by nsysnet socket functions
69  * WARNING: these do not match with sys/errno.h (where EAGAIN is 11 for example).
70  */
71 #define NSN_EAGAIN 6
72 #define NSN_EWOULDBLOCK 6
73 
74 typedef uint32_t socklen_t;
75 typedef uint16_t sa_family_t;
76 
77 struct sockaddr
78 {
80  char sa_data[];
81 };
82 
84 {
86  char ss_padding[14];
87 };
88 
89 struct linger
90 {
91  int l_onoff;
92  int l_linger;
93 };
94 
95 struct in_addr
96 {
97  unsigned int s_addr;
98 };
99 
101 {
102  unsigned short sin_family;
103  unsigned short sin_port;
105  char sin_zero[8];
106 };
107 
108 void
110 
111 void
113 
114 int
115 accept(int sockfd,
116  struct sockaddr *addr,
117  socklen_t *addrlen);
118 
119 int
120 bind(int sockfd,
121  const struct sockaddr *addr,
122  socklen_t addrlen);
123 
124 int
125 socketclose(int sockfd);
126 
127 int
128 connect(int sockfd,
129  const struct sockaddr *addr,
130  socklen_t addrlen);
131 
132 int
133 getpeername(int sockfd,
134  struct sockaddr *addr,
135  socklen_t *addrlen);
136 
137 int
138 getsockname(int sockfd,
139  struct sockaddr *addr,
140  socklen_t *addrlen);
141 
142 int
143 getsockopt(int sockfd,
144  int level,
145  int optname,
146  void *optval,
147  socklen_t *optlen);
148 
149 int
150 listen(int sockfd,
151  int backlog);
152 
153 int
154 recv(int sockfd,
155  void *buf,
156  size_t len,
157  int flags);
158 
159 int
160 recvfrom(int sockfd,
161  void *buf,
162  size_t len,
163  int flags,
164  struct sockaddr *src_addr,
165  socklen_t *addrlen);
166 
167 int
168 send(int sockfd,
169  const void *buf,
170  size_t len,
171  int flags);
172 
173 int
174 sendto(int sockfd,
175  const void *buf,
176  size_t len,
177  int flags,
178  const struct sockaddr *dest_addr,
179  socklen_t addrlen);
180 
181 int
182 setsockopt(int sockfd,
183  int level,
184  int optname,
185  const void *optval,
186  socklen_t optlen);
187 
188 int
189 shutdown(int sockfd,
190  int how);
191 
192 int
193 socket(int domain,
194  int type,
195  int protocol);
196 
197 int
198 select(int nfds,
199  fd_set *readfds,
200  fd_set *writefds,
201  fd_set *exceptfds,
202  struct timeval *timeout);
203 
204 const char *
205 inet_ntoa(struct in_addr in);
206 
207 int
208 inet_aton(const char *cp, struct in_addr *inp);
209 
210 int
211 socketlasterr();
212 
213 uint32_t
214 htonl(uint32_t val);
215 
216 uint16_t
217 htons(uint16_t val);
218 
219 uint32_t
220 ntohl(uint32_t val);
221 
222 uint16_t
223 ntohs(uint16_t val);
224 
225 #ifdef __cplusplus
226 }
227 #endif
228 
sockaddr_storage
Definition: socket.h:83
linger
Definition: socket.h:89
sa_family_t
uint16_t sa_family_t
Definition: socket.h:75
sockaddr_in
Definition: socket.h:100
sockaddr
Definition: socket.h:77
recvfrom
int recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen)
linger::l_onoff
int l_onoff
Definition: socket.h:91
sockaddr_in::sin_zero
char sin_zero[8]
Definition: socket.h:105
socketclose
int socketclose(int sockfd)
linger::l_linger
int l_linger
Definition: socket.h:92
sockaddr::sa_family
sa_family_t sa_family
Definition: socket.h:79
shutdown
int shutdown(int sockfd, int how)
getsockname
int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
wut.h
sockaddr::sa_data
char sa_data[]
Definition: socket.h:80
send
int send(int sockfd, const void *buf, size_t len, int flags)
sockaddr_in::sin_family
unsigned short sin_family
Definition: socket.h:102
select
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
socklen_t
uint32_t socklen_t
Definition: socket.h:74
sockaddr_storage::ss_padding
char ss_padding[14]
Definition: socket.h:86
inet_ntoa
const char * inet_ntoa(struct in_addr in)
accept
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
connect
int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
setsockopt
int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen)
getpeername
int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
in_addr::s_addr
unsigned int s_addr
Definition: socket.h:97
socketlasterr
int socketlasterr()
listen
int listen(int sockfd, int backlog)
socket_lib_init
void socket_lib_init()
inet_aton
int inet_aton(const char *cp, struct in_addr *inp)
socket_lib_finish
void socket_lib_finish()
sockaddr_in::sin_addr
struct in_addr sin_addr
Definition: socket.h:104
ntohs
uint16_t ntohs(uint16_t val)
getsockopt
int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen)
sockaddr_storage::ss_family
sa_family_t ss_family
Definition: socket.h:85
socket
int socket(int domain, int type, int protocol)
htonl
uint32_t htonl(uint32_t val)
sockaddr_in::sin_port
unsigned short sin_port
Definition: socket.h:103
bind
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
ntohl
uint32_t ntohl(uint32_t val)
htons
uint16_t htons(uint16_t val)
recv
int recv(int sockfd, void *buf, size_t len, int flags)
sendto
int sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
in_addr
Definition: socket.h:95