summaryrefslogtreecommitdiff
path: root/toxcore/network.h
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-02-27 01:07:46 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-05-20 19:35:28 +0000
commit21675ce0d2581597b0e0a727ab4cf6cfb796a037 (patch)
treee1ac4ca63c5cc2b2dc78fcd5b20a8202eab98d9d /toxcore/network.h
parent4f6ab0708c85f3e3da7726f6caecc381c6d21370 (diff)
Finish @Diadlo's network Family abstraction.
The Family stuff in toxcore is a big mess. I'm sure I saw a bunch of bugs on the way, but I'm not verifying that code now, so the bugs stay.
Diffstat (limited to 'toxcore/network.h')
-rw-r--r--toxcore/network.h32
1 files changed, 27 insertions, 5 deletions
diff --git a/toxcore/network.h b/toxcore/network.h
index bdfebd7e..8071375b 100644
--- a/toxcore/network.h
+++ b/toxcore/network.h
@@ -34,7 +34,29 @@
34extern "C" { 34extern "C" {
35#endif 35#endif
36 36
37typedef uint8_t Family; 37typedef struct Family {
38 uint8_t value;
39} Family;
40
41bool net_family_is_unspec(Family family);
42bool net_family_is_ipv4(Family family);
43bool net_family_is_ipv6(Family family);
44bool net_family_is_tcp_family(Family family);
45bool net_family_is_tcp_onion(Family family);
46bool net_family_is_tcp_ipv4(Family family);
47bool net_family_is_tcp_ipv6(Family family);
48bool net_family_is_tox_tcp_ipv4(Family family);
49bool net_family_is_tox_tcp_ipv6(Family family);
50
51extern const Family net_family_unspec;
52extern const Family net_family_ipv4;
53extern const Family net_family_ipv6;
54extern const Family net_family_tcp_family;
55extern const Family net_family_tcp_onion;
56extern const Family net_family_tcp_ipv4;
57extern const Family net_family_tcp_ipv6;
58extern const Family net_family_tox_tcp_ipv4;
59extern const Family net_family_tox_tcp_ipv6;
38 60
39typedef struct Socket { 61typedef struct Socket {
40 int socket; 62 int socket;
@@ -152,7 +174,7 @@ extern const IP6 IP6_BROADCAST;
152 174
153#define IP_DEFINED 175#define IP_DEFINED
154typedef struct IP { 176typedef struct IP {
155 uint8_t family; 177 Family family;
156 union { 178 union {
157 IP4 v4; 179 IP4 v4;
158 IP6 v6; 180 IP6 v6;
@@ -264,9 +286,9 @@ void ip_reset(IP *ip);
264/* nulls out ip, sets family according to flag */ 286/* nulls out ip, sets family according to flag */
265void ip_init(IP *ip, bool ipv6enabled); 287void ip_init(IP *ip, bool ipv6enabled);
266/* checks if ip is valid */ 288/* checks if ip is valid */
267int ip_isset(const IP *ip); 289bool ip_isset(const IP *ip);
268/* checks if ip is valid */ 290/* checks if ip is valid */
269int ipport_isset(const IP_Port *ipport); 291bool ipport_isset(const IP_Port *ipport);
270/* copies an ip structure */ 292/* copies an ip structure */
271void ip_copy(IP *target, const IP *source); 293void ip_copy(IP *target, const IP *source);
272/* copies an ip_port structure */ 294/* copies an ip_port structure */
@@ -396,7 +418,7 @@ void net_freeipport(IP_Port *ip_ports);
396/* return 1 on success 418/* return 1 on success
397 * return 0 on failure 419 * return 0 on failure
398 */ 420 */
399int bind_to_port(Socket sock, int family, uint16_t port); 421int bind_to_port(Socket sock, Family family, uint16_t port);
400 422
401/* Get the last networking error code. 423/* Get the last networking error code.
402 * 424 *