diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-08-26 18:41:34 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-08-26 20:58:37 +0000 |
commit | 9a70a2c1856a2b1a63aa1e938ddee56bb98308ca (patch) | |
tree | 6b66864a12e24a256194d1a64525e576e86d1b32 /toxcore/network.h | |
parent | 5352f483016949073556a1f9ac488051fe96c308 (diff) |
Use `bool` in place of 0/1 int values.
Diffstat (limited to 'toxcore/network.h')
-rw-r--r-- | toxcore/network.h | 145 |
1 files changed, 70 insertions, 75 deletions
diff --git a/toxcore/network.h b/toxcore/network.h index 08be6f10..6c5b6781 100644 --- a/toxcore/network.h +++ b/toxcore/network.h | |||
@@ -64,12 +64,12 @@ typedef struct Socket { | |||
64 | 64 | ||
65 | Socket net_socket(Family domain, int type, int protocol); | 65 | Socket net_socket(Family domain, int type, int protocol); |
66 | 66 | ||
67 | /* Check if socket is valid. | 67 | /** |
68 | * Check if socket is valid. | ||
68 | * | 69 | * |
69 | * return 1 if valid | 70 | * @return true if valid, false otherwise. |
70 | * return 0 if not valid | ||
71 | */ | 71 | */ |
72 | int sock_valid(Socket sock); | 72 | bool sock_valid(Socket sock); |
73 | 73 | ||
74 | extern const Socket net_invalid_socket; | 74 | extern const Socket net_invalid_socket; |
75 | 75 | ||
@@ -235,53 +235,49 @@ bool ipv6_ipv4_in_v6(IP6 a); | |||
235 | #define IP_NTOA_LEN 96 // TODO(irungentoo): magic number. Why not INET6_ADDRSTRLEN ? | 235 | #define IP_NTOA_LEN 96 // TODO(irungentoo): magic number. Why not INET6_ADDRSTRLEN ? |
236 | const char *ip_ntoa(const IP *ip, char *ip_str, size_t length); | 236 | const char *ip_ntoa(const IP *ip, char *ip_str, size_t length); |
237 | 237 | ||
238 | /* | 238 | /** |
239 | * ip_parse_addr | 239 | * Parses IP structure into an address string. |
240 | * parses IP structure into an address string | ||
241 | * | 240 | * |
242 | * input | 241 | * @param ip IP of TOX_AF_INET or TOX_AF_INET6 families. |
243 | * ip: ip of TOX_AF_INET or TOX_AF_INET6 families | 242 | * @param length length of the address buffer. |
244 | * length: length of the address buffer | 243 | * Must be at least TOX_INET_ADDRSTRLEN for TOX_AF_INET |
245 | * Must be at least TOX_INET_ADDRSTRLEN for TOX_AF_INET | 244 | * and TOX_INET6_ADDRSTRLEN for TOX_AF_INET6 |
246 | * and TOX_INET6_ADDRSTRLEN for TOX_AF_INET6 | ||
247 | * | 245 | * |
248 | * output | 246 | * @param address dotted notation (IPv4: quad, IPv6: 16) or colon notation (IPv6). |
249 | * address: dotted notation (IPv4: quad, IPv6: 16) or colon notation (IPv6) | ||
250 | * | 247 | * |
251 | * returns 1 on success, 0 on failure | 248 | * @return true on success, false on failure. |
252 | */ | 249 | */ |
253 | int ip_parse_addr(const IP *ip, char *address, size_t length); | 250 | bool ip_parse_addr(const IP *ip, char *address, size_t length); |
254 | 251 | ||
255 | /* | 252 | /** |
256 | * addr_parse_ip | 253 | * Directly parses the input into an IP structure. |
257 | * directly parses the input into an IP structure | ||
258 | * tries IPv4 first, then IPv6 | ||
259 | * | 254 | * |
260 | * input | 255 | * Tries IPv4 first, then IPv6. |
261 | * address: dotted notation (IPv4: quad, IPv6: 16) or colon notation (IPv6) | ||
262 | * | 256 | * |
263 | * output | 257 | * @param address dotted notation (IPv4: quad, IPv6: 16) or colon notation (IPv6). |
264 | * IP: family and the value is set on success | 258 | * @param to family and the value is set on success. |
265 | * | 259 | * |
266 | * returns 1 on success, 0 on failure | 260 | * @return true on success, false on failure. |
267 | */ | 261 | */ |
268 | int addr_parse_ip(const char *address, IP *to); | 262 | bool addr_parse_ip(const char *address, IP *to); |
269 | 263 | ||
270 | /* ip_equal | 264 | /** |
271 | * compares two IPAny structures | 265 | * Compares two IPAny structures. |
272 | * unset means unequal | ||
273 | * | 266 | * |
274 | * returns 0 when not equal or when uninitialized | 267 | * Unset means unequal. |
268 | * | ||
269 | * @return false when not equal or when uninitialized. | ||
275 | */ | 270 | */ |
276 | int ip_equal(const IP *a, const IP *b); | 271 | bool ip_equal(const IP *a, const IP *b); |
277 | 272 | ||
278 | /* ipport_equal | 273 | /** |
279 | * compares two IPAny_Port structures | 274 | * Compares two IPAny_Port structures. |
280 | * unset means unequal | 275 | * |
276 | * Unset means unequal. | ||
281 | * | 277 | * |
282 | * returns 0 when not equal or when uninitialized | 278 | * @return false when not equal or when uninitialized. |
283 | */ | 279 | */ |
284 | int ipport_equal(const IP_Port *a, const IP_Port *b); | 280 | bool ipport_equal(const IP_Port *a, const IP_Port *b); |
285 | 281 | ||
286 | /* nulls out ip */ | 282 | /* nulls out ip */ |
287 | void ip_reset(IP *ip); | 283 | void ip_reset(IP *ip); |
@@ -296,41 +292,40 @@ void ip_copy(IP *target, const IP *source); | |||
296 | /* copies an ip_port structure */ | 292 | /* copies an ip_port structure */ |
297 | void ipport_copy(IP_Port *target, const IP_Port *source); | 293 | void ipport_copy(IP_Port *target, const IP_Port *source); |
298 | 294 | ||
299 | /* | 295 | /** |
300 | * addr_resolve(): | 296 | * Uses getaddrinfo to resolve an address into an IP address. |
301 | * uses getaddrinfo to resolve an address into an IP address | ||
302 | * uses the first IPv4/IPv6 addresses returned by getaddrinfo | ||
303 | * | 297 | * |
304 | * input | 298 | * Uses the first IPv4/IPv6 addresses returned by getaddrinfo. |
305 | * address: a hostname (or something parseable to an IP address) | 299 | * |
306 | * to: to.family MUST be initialized, either set to a specific IP version | 300 | * @param address a hostname (or something parseable to an IP address) |
301 | * @param to to.family MUST be initialized, either set to a specific IP version | ||
307 | * (TOX_AF_INET/TOX_AF_INET6) or to the unspecified TOX_AF_UNSPEC (= 0), if both | 302 | * (TOX_AF_INET/TOX_AF_INET6) or to the unspecified TOX_AF_UNSPEC (= 0), if both |
308 | * IP versions are acceptable | 303 | * IP versions are acceptable |
309 | * extra can be NULL and is only set in special circumstances, see returns | 304 | * @param extra can be NULL and is only set in special circumstances, see returns |
310 | * | 305 | * |
311 | * returns in *to a valid IPAny (v4/v6), | 306 | * returns in *to a valid IPAny (v4/v6), |
312 | * prefers v6 if ip.family was TOX_AF_UNSPEC and both available | 307 | * prefers v6 if ip.family was TOX_AF_UNSPEC and both available |
313 | * returns in *extra an IPv4 address, if family was TOX_AF_UNSPEC and *to is TOX_AF_INET6 | 308 | * returns in *extra an IPv4 address, if family was TOX_AF_UNSPEC and *to is TOX_AF_INET6 |
314 | * returns 0 on failure | 309 | * |
310 | * @return 0 on failure, TOX_ADDR_RESOLVE_* on success. | ||
315 | */ | 311 | */ |
316 | int addr_resolve(const char *address, IP *to, IP *extra); | 312 | int addr_resolve(const char *address, IP *to, IP *extra); |
317 | 313 | ||
318 | /* | 314 | /** |
319 | * addr_resolve_or_parse_ip | 315 | * Resolves string into an IP address |
320 | * resolves string into an IP address | ||
321 | * | 316 | * |
322 | * address: a hostname (or something parseable to an IP address) | 317 | * @param address a hostname (or something parseable to an IP address) |
323 | * to: to.family MUST be initialized, either set to a specific IP version | 318 | * @param to to.family MUST be initialized, either set to a specific IP version |
324 | * (TOX_AF_INET/TOX_AF_INET6) or to the unspecified TOX_AF_UNSPEC (= 0), if both | 319 | * (TOX_AF_INET/TOX_AF_INET6) or to the unspecified TOX_AF_UNSPEC (= 0), if both |
325 | * IP versions are acceptable | 320 | * IP versions are acceptable |
326 | * extra can be NULL and is only set in special circumstances, see returns | 321 | * @param extra can be NULL and is only set in special circumstances, see returns |
322 | * | ||
323 | * returns in *tro a matching address (IPv6 or IPv4) | ||
324 | * returns in *extra, if not NULL, an IPv4 address, if to->family was TOX_AF_UNSPEC | ||
327 | * | 325 | * |
328 | * returns in *tro a matching address (IPv6 or IPv4) | 326 | * @return true on success, false on failure |
329 | * returns in *extra, if not NULL, an IPv4 address, if to->family was TOX_AF_UNSPEC | ||
330 | * returns 1 on success | ||
331 | * returns 0 on failure | ||
332 | */ | 327 | */ |
333 | int addr_resolve_or_parse_ip(const char *address, IP *to, IP *extra); | 328 | bool addr_resolve_or_parse_ip(const char *address, IP *to, IP *extra); |
334 | 329 | ||
335 | /* Function to receive data, ip and port of sender is put into ip_port. | 330 | /* Function to receive data, ip and port of sender is put into ip_port. |
336 | * Packet data is put into data. | 331 | * Packet data is put into data. |
@@ -354,33 +349,33 @@ int networking_at_startup(void); | |||
354 | */ | 349 | */ |
355 | void kill_sock(Socket sock); | 350 | void kill_sock(Socket sock); |
356 | 351 | ||
357 | /* Set socket as nonblocking | 352 | /** |
353 | * Set socket as nonblocking | ||
358 | * | 354 | * |
359 | * return 1 on success | 355 | * @return true on success, false on failure. |
360 | * return 0 on failure | ||
361 | */ | 356 | */ |
362 | int set_socket_nonblock(Socket sock); | 357 | bool set_socket_nonblock(Socket sock); |
363 | 358 | ||
364 | /* Set socket to not emit SIGPIPE | 359 | /** |
360 | * Set socket to not emit SIGPIPE | ||
365 | * | 361 | * |
366 | * return 1 on success | 362 | * @return true on success, false on failure. |
367 | * return 0 on failure | ||
368 | */ | 363 | */ |
369 | int set_socket_nosigpipe(Socket sock); | 364 | bool set_socket_nosigpipe(Socket sock); |
370 | 365 | ||
371 | /* Enable SO_REUSEADDR on socket. | 366 | /** |
367 | * Enable SO_REUSEADDR on socket. | ||
372 | * | 368 | * |
373 | * return 1 on success | 369 | * @return true on success, false on failure. |
374 | * return 0 on failure | ||
375 | */ | 370 | */ |
376 | int set_socket_reuseaddr(Socket sock); | 371 | bool set_socket_reuseaddr(Socket sock); |
377 | 372 | ||
378 | /* Set socket to dual (IPv4 + IPv6 socket) | 373 | /** |
374 | * Set socket to dual (IPv4 + IPv6 socket) | ||
379 | * | 375 | * |
380 | * return 1 on success | 376 | * @return true on success, false on failure. |
381 | * return 0 on failure | ||
382 | */ | 377 | */ |
383 | int set_socket_dualstack(Socket sock); | 378 | bool set_socket_dualstack(Socket sock); |
384 | 379 | ||
385 | /* Basic network functions: */ | 380 | /* Basic network functions: */ |
386 | 381 | ||
@@ -413,10 +408,10 @@ int32_t net_getipport(const char *node, IP_Port **res, int tox_type); | |||
413 | */ | 408 | */ |
414 | void net_freeipport(IP_Port *ip_ports); | 409 | void net_freeipport(IP_Port *ip_ports); |
415 | 410 | ||
416 | /* return 1 on success | 411 | /** |
417 | * return 0 on failure | 412 | * @return true on success, false on failure. |
418 | */ | 413 | */ |
419 | int bind_to_port(Socket sock, Family family, uint16_t port); | 414 | bool bind_to_port(Socket sock, Family family, uint16_t port); |
420 | 415 | ||
421 | /* Get the last networking error code. | 416 | /* Get the last networking error code. |
422 | * | 417 | * |