forked from KapLex/PGE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pgeNet.h
272 lines (235 loc) · 5.83 KB
/
pgeNet.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/*
* pgeNet.h: Header for net/wifi
*
* This file is part of "Phoenix Game Engine".
*
* Copyright (C) 2008 Phoenix Game Engine
* Copyright (C) 2008 InsertWittyName <[email protected]>
* Copyright (C) 2008 MK2k <[email protected]>
*
* Phoenix Game Engine is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Phoenix Game Engine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Phoenix Game Engine. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __PGENET_H__
#define __PGENET_H__
#ifdef __cplusplus
extern "C" {
#endif
/** @defgroup pgeNet Net/Wifi Library
* @{
*/
#include <psptypes.h>
#include <psputility.h>
#include <netinet/in.h>
#ifdef __PSP__
#include <sys/fd_set.h>
#endif
#define PGE_SOCKET_TCP SOCK_STREAM /**< Stream socket */
#define PGE_SOCKET_UDP SOCK_DGRAM /**< Datagram socket */
#define PGE_LOCAL_IP 0 /**< Local IP ie. 192.168.x.x */
#define PGE_REAL_IP 1 /**< 'Real' IP */
#define PGE_MAX_CLIENTS 256 /**< Maximum clients that can connect to a server */
typedef int pgeSocket;
typedef fd_set pgeSocketSet;
/**
* Initialise the wifi
*
* @returns 1 on success else an error code.
*/
int pgeNetInit(void);
/**
* Shutdown the wifi
*
* @returns 1 on success else an error code.
*/
int pgeNetShutdown(void);
/**
* Download a file
*
* @param url - The URL of the file
*
* @param filepath - The path to save the downloaded file
*
* @returns 1 on success else an error code.
*/
int pgeNetGetFile(const char *url, const char *filepath);
/**
* Post a form
*
* @param url - The URL to post to
*
* @param data - The data to post
*
* @param response - The buffer where the response from the server will be stored
*
* @param responsesize - Size of the response buffer
*
* @returns 1 on success else an error code.
*/
int pgeNetPostForm(const char *url, char *data, char *response, unsigned int responsesize);
/**
* Get the status of the wlan switch
*
* @returns 1 if switch is up
*/
int pgeNetSwitchStatus(void);
/**
* Disconnect from an access point
*/
void pgeNetDisconnect(void);
/**
* Check if connected to an access point
*
* @returns 1 on valid connection
*/
int pgeNetIsConnected(void);
/**
* Get Local IP address
*
* @param buffer - Pointer to a buffer which will store the IP address
*
* @returns 1 on success else an error code.
*/
int pgeNetGetLocalIp(char *buffer);
/**
* Resolve a hostname
*
* @param hostname - The hostname to resolve
*
* @param resolved - Pointer to a buffer that will store the resolved hostname
*
* @returns 1 on success else an error code.
*/
int pgeNetResolveHost(char *hostname, char *resolved);
/**
* Create a socket
*
* @returns A ::pgeSocket.
*/
pgeSocket pgeNetSocketCreate(void);
/**
* Accept a connection
*
* @param socket - The socket.
*
* @returns A ::pgeSocket for the incoming connection.
*/
pgeSocket pgeNetSocketAccept(pgeSocket socket);
/**
* Bind a socket to a port
*
* @param socket - The socket.
*
* @param port - The port to bind to.
*
* @returns 1 on success, 0 on error.
*/
int pgeNetSocketBind(pgeSocket socket, unsigned short port);
/**
* Listen for connections
*
* @param socket - The socket.
*
* @param maxconn - The maximum amount of connections to listen for.
*
* @returns 1 on success, 0 on error.
*/
int pgeNetSocketListen(pgeSocket socket, unsigned int maxconn);
/**
* Connect to an IP and port
*
* @param socket - The socket.
*
* @param ip - The IP to connect to.
*
* @param port - The port to connect to.
*
* @returns 1 on success, 0 on error.
*/
int pgeNetSocketConnect(pgeSocket socket, char *ip, unsigned short port);
/**
* Send data
*
* @param socket - The socket.
*
* @param data - The data to send.
*
* @param length - The size of the data (in bytes).
*
* @returns Number of bytes sent, -1 on error.
*/
int pgeNetSocketSend(pgeSocket socket, const void *data, int length);
/**
* Receive data
*
* @param socket - The socket.
*
* @param data - Pointer to a buffer where the received data will be stored.
*
* @param length - The size of the buffer (in bytes).
*
* @returns Number of bytes received, -1 on error.
*/
int pgeNetSocketReceive(pgeSocket socket, void *data, int length);
/**
* Close a socket
*
* @param socket - The socket.
*/
void pgeNetSocketClose(pgeSocket socket);
/**
* Clear a socket set
*
* @param set - The socket set to clear.
*/
void pgeNetSocketSetClear(pgeSocketSet *set);
/**
* Add a socket to a socket set
*
* @param socket - The socket to add.
*
* @param set - The socket set to add the socket to.
*/
void pgeNetSocketSetAdd(pgeSocket socket, pgeSocketSet *set);
/**
* Remove a socket from a socket set
*
* @param socket - The socket to remove.
*
* @param set - The socket set to remove the socket from.
*/
void pgeNetSocketSetRemove(pgeSocket socket, pgeSocketSet *set);
/**
* Check if a socket is a member of a socket set
*
* @param socket - The socket to check.
*
* @param set - The socket set to check the socket is a member of.
*
* @returns 1 if the socket is a member of the set, otherwise 0.
*/
int pgeNetSocketSetIsMember(pgeSocket socket, pgeSocketSet *set);
/**
* Check if a socket is ready for reading
*
* @param maxsockets - Maximum number of sockets to check.
*
* @param set - The socket set to check.
*
* @returns Number of sockets, -1 on error.
*/
int pgeNetSocketSetSelect(unsigned int maxsockets, pgeSocketSet *set);
/** @} */
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // __PGENET_H__