diff options
author | Coren[m] <Break@Ocean> | 2013-09-10 16:36:20 +0200 |
---|---|---|
committer | Coren[m] <Break@Ocean> | 2013-09-10 16:36:20 +0200 |
commit | bcb283cf4512f36b189ce2d49eb040c205cbc778 (patch) | |
tree | b0678f9acf245e5620d21c046265a7b3ad98c561 /toxcore/network.h | |
parent | bcf251ac3190db4230d42be97b539e4df3af736f (diff) |
big push, putting all the infrastructure in place behind TOX_ENABLE_IPV6
Diffstat (limited to 'toxcore/network.h')
-rw-r--r-- | toxcore/network.h | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/toxcore/network.h b/toxcore/network.h index 913763ee..0d31ffac 100644 --- a/toxcore/network.h +++ b/toxcore/network.h | |||
@@ -101,12 +101,6 @@ typedef struct { | |||
101 | }; | 101 | }; |
102 | } IPAny; | 102 | } IPAny; |
103 | 103 | ||
104 | /* ipany_ntoa | ||
105 | * converts ip into a string | ||
106 | * uses a static buffer, so mustn't used multiple times in the same output | ||
107 | */ | ||
108 | const char *ipany_ntoa(IPAny *ip); | ||
109 | |||
110 | typedef union { | 104 | typedef union { |
111 | struct { | 105 | struct { |
112 | IP4 ip; | 106 | IP4 ip; |
@@ -124,29 +118,43 @@ typedef struct { | |||
124 | uint16_t port; | 118 | uint16_t port; |
125 | } IPAny_Port; | 119 | } IPAny_Port; |
126 | 120 | ||
127 | #ifdef NETWORK_IP_PORT_IS_IPV6 | 121 | #undef TOX_ENABLE_IPV6 |
122 | #ifdef TOX_ENABLE_IPV6 | ||
123 | #define TOX_ENABLE_IPV6_DEFAULT 1 | ||
124 | typedef IPAny IP; | ||
128 | typedef IPAny_Port IP_Port; | 125 | typedef IPAny_Port IP_Port; |
129 | #else | 126 | #else |
127 | #define TOX_ENABLE_IPV6_DEFAULT 0 | ||
128 | typedef IP4 IP; | ||
130 | typedef IP4_Port IP_Port; | 129 | typedef IP4_Port IP_Port; |
131 | #endif | 130 | #endif |
132 | 131 | ||
132 | /* ip_ntoa | ||
133 | * converts ip into a string | ||
134 | * uses a static buffer, so mustn't used multiple times in the same output | ||
135 | */ | ||
136 | const char *ip_ntoa(IP *ip); | ||
137 | |||
133 | /* ipport_equal | 138 | /* ipport_equal |
134 | * compares two IPAny_Port structures | 139 | * compares two IPAny_Port structures |
135 | * unset means unequal | 140 | * unset means unequal |
136 | * | 141 | * |
137 | * returns 0 when not equal or when uninitialized | 142 | * returns 0 when not equal or when uninitialized |
138 | */ | 143 | */ |
139 | int ipport_equal(IPAny_Port *a, IPAny_Port *b); | 144 | int ipport_equal(IP_Port *a, IP_Port *b); |
140 | 145 | ||
141 | typedef struct { | 146 | /* nulls out ip */ |
142 | int16_t family; | 147 | void ip_reset(IP *ip); |
143 | uint16_t port; | 148 | /* nulls out ip, sets family according to flag */ |
144 | IP4 ip; | 149 | void ip_init(IP *ip, uint8_t ipv6enabled); |
145 | uint8_t zeroes[8]; | 150 | /* checks if ip is valid */ |
146 | #ifdef ENABLE_IPV6 | 151 | int ip_isset(IP *ip); |
147 | uint8_t zeroes2[12]; | 152 | /* checks if ip is valid */ |
148 | #endif | 153 | int ipport_isset(IP_Port *ipport); |
149 | } ADDR; | 154 | /* copies an ip structure */ |
155 | void ip_copy(IP *target, IP *source); | ||
156 | /* copies an ip_port structure */ | ||
157 | void ipport_copy(IP_Port *target, IP_Port *source); | ||
150 | 158 | ||
151 | /* | 159 | /* |
152 | * addr_resolve_or_parse_ip | 160 | * addr_resolve_or_parse_ip |
@@ -155,7 +163,7 @@ typedef struct { | |||
155 | * to->family MUST be set (AF_UNSPEC, AF_INET, AF_INET6) | 163 | * to->family MUST be set (AF_UNSPEC, AF_INET, AF_INET6) |
156 | * returns 1 on success, 0 on failure | 164 | * returns 1 on success, 0 on failure |
157 | */ | 165 | */ |
158 | int addr_resolve_or_parse_ip(const char *address, IPAny *to); | 166 | int addr_resolve_or_parse_ip(const char *address, IP *to); |
159 | 167 | ||
160 | /* Function to receive data, ip and port of sender is put into ip_port. | 168 | /* Function to receive data, ip and port of sender is put into ip_port. |
161 | * Packet data is put into data. | 169 | * Packet data is put into data. |
@@ -204,7 +212,7 @@ void networking_poll(Networking_Core *net); | |||
204 | * return 0 if no problems. | 212 | * return 0 if no problems. |
205 | * return -1 if there were problems. | 213 | * return -1 if there were problems. |
206 | */ | 214 | */ |
207 | Networking_Core *new_networking(IP4 ip, uint16_t port); | 215 | Networking_Core *new_networking(IP ip, uint16_t port); |
208 | 216 | ||
209 | /* Function to cleanup networking stuff (doesn't do much right now). */ | 217 | /* Function to cleanup networking stuff (doesn't do much right now). */ |
210 | void kill_networking(Networking_Core *net); | 218 | void kill_networking(Networking_Core *net); |