diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-02-27 01:07:46 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-05-20 19:35:28 +0000 |
commit | 21675ce0d2581597b0e0a727ab4cf6cfb796a037 (patch) | |
tree | e1ac4ca63c5cc2b2dc78fcd5b20a8202eab98d9d /toxcore/network.h | |
parent | 4f6ab0708c85f3e3da7726f6caecc381c6d21370 (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.h | 32 |
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 @@ | |||
34 | extern "C" { | 34 | extern "C" { |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | typedef uint8_t Family; | 37 | typedef struct Family { |
38 | uint8_t value; | ||
39 | } Family; | ||
40 | |||
41 | bool net_family_is_unspec(Family family); | ||
42 | bool net_family_is_ipv4(Family family); | ||
43 | bool net_family_is_ipv6(Family family); | ||
44 | bool net_family_is_tcp_family(Family family); | ||
45 | bool net_family_is_tcp_onion(Family family); | ||
46 | bool net_family_is_tcp_ipv4(Family family); | ||
47 | bool net_family_is_tcp_ipv6(Family family); | ||
48 | bool net_family_is_tox_tcp_ipv4(Family family); | ||
49 | bool net_family_is_tox_tcp_ipv6(Family family); | ||
50 | |||
51 | extern const Family net_family_unspec; | ||
52 | extern const Family net_family_ipv4; | ||
53 | extern const Family net_family_ipv6; | ||
54 | extern const Family net_family_tcp_family; | ||
55 | extern const Family net_family_tcp_onion; | ||
56 | extern const Family net_family_tcp_ipv4; | ||
57 | extern const Family net_family_tcp_ipv6; | ||
58 | extern const Family net_family_tox_tcp_ipv4; | ||
59 | extern const Family net_family_tox_tcp_ipv6; | ||
38 | 60 | ||
39 | typedef struct Socket { | 61 | typedef 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 |
154 | typedef struct IP { | 176 | typedef 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 */ |
265 | void ip_init(IP *ip, bool ipv6enabled); | 287 | void ip_init(IP *ip, bool ipv6enabled); |
266 | /* checks if ip is valid */ | 288 | /* checks if ip is valid */ |
267 | int ip_isset(const IP *ip); | 289 | bool ip_isset(const IP *ip); |
268 | /* checks if ip is valid */ | 290 | /* checks if ip is valid */ |
269 | int ipport_isset(const IP_Port *ipport); | 291 | bool ipport_isset(const IP_Port *ipport); |
270 | /* copies an ip structure */ | 292 | /* copies an ip structure */ |
271 | void ip_copy(IP *target, const IP *source); | 293 | void 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 | */ |
399 | int bind_to_port(Socket sock, int family, uint16_t port); | 421 | int 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 | * |