diff options
author | Diadlo <polsha3@gmail.com> | 2017-01-07 11:28:53 +0300 |
---|---|---|
committer | Diadlo <polsha3@gmail.com> | 2017-02-26 23:16:16 +0300 |
commit | b19a9e54643eceaa52e71c0f38fa2ecae5a6809e (patch) | |
tree | 4c6fff0a086988ab21636e88dbf65c2e40a76a67 /toxcore/LAN_discovery.c | |
parent | b2d04eae9d9b76523b877a9e5efd5989f83b143d (diff) |
Add part of platform-independent network API implementation
socket -> net_socket
htons -> net_htons
htonl -> net_htonl
connect -> net_connect
sendto -> net_sendto_ip4
getaddrinfo -> net_getipport
sa_family_t -> Family
Diffstat (limited to 'toxcore/LAN_discovery.c')
-rw-r--r-- | toxcore/LAN_discovery.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c index e26f7eea..e685ae0e 100644 --- a/toxcore/LAN_discovery.c +++ b/toxcore/LAN_discovery.c | |||
@@ -86,9 +86,9 @@ static void fetch_broadcast_info(uint16_t port) | |||
86 | if (gateway.family == AF_INET && subnet_mask.family == AF_INET) { | 86 | if (gateway.family == AF_INET && subnet_mask.family == AF_INET) { |
87 | IP_Port *ip_port = &ip_ports[count]; | 87 | IP_Port *ip_port = &ip_ports[count]; |
88 | ip_port->ip.family = AF_INET; | 88 | ip_port->ip.family = AF_INET; |
89 | uint32_t gateway_ip = ntohl(gateway.ip4.uint32), subnet_ip = ntohl(subnet_mask.ip4.uint32); | 89 | uint32_t gateway_ip = net_ntohl(gateway.ip4.uint32), subnet_ip = net_ntohl(subnet_mask.ip4.uint32); |
90 | uint32_t broadcast_ip = gateway_ip + ~subnet_ip - 1; | 90 | uint32_t broadcast_ip = gateway_ip + ~subnet_ip - 1; |
91 | ip_port->ip.ip4.uint32 = htonl(broadcast_ip); | 91 | ip_port->ip.ip4.uint32 = net_htonl(broadcast_ip); |
92 | ip_port->port = port; | 92 | ip_port->port = port; |
93 | count++; | 93 | count++; |
94 | 94 | ||
@@ -124,7 +124,7 @@ static void fetch_broadcast_info(uint16_t port) | |||
124 | broadcast_count = 0; | 124 | broadcast_count = 0; |
125 | Socket sock = 0; | 125 | Socket sock = 0; |
126 | 126 | ||
127 | if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { | 127 | if ((sock = net_socket(TOX_AF_INET, TOX_SOCK_STREAM, 0)) < 0) { |
128 | return; | 128 | return; |
129 | } | 129 | } |
130 | 130 | ||
@@ -174,7 +174,7 @@ static void fetch_broadcast_info(uint16_t port) | |||
174 | 174 | ||
175 | IP_Port *ip_port = &ip_ports[count]; | 175 | IP_Port *ip_port = &ip_ports[count]; |
176 | ip_port->ip.family = AF_INET; | 176 | ip_port->ip.family = AF_INET; |
177 | get_ip4(&ip_port->ip.ip4, &sock4->sin_addr); | 177 | ip_port->ip.ip4.uint32 = sock4->sin_addr.s_addr; |
178 | 178 | ||
179 | if (ip_port->ip.ip4.uint32 == 0) { | 179 | if (ip_port->ip.ip4.uint32 == 0) { |
180 | continue; | 180 | continue; |
@@ -228,7 +228,7 @@ static uint32_t send_broadcasts(Networking_Core *net, uint16_t port, const uint8 | |||
228 | } | 228 | } |
229 | 229 | ||
230 | /* Return the broadcast ip. */ | 230 | /* Return the broadcast ip. */ |
231 | static IP broadcast_ip(sa_family_t family_socket, sa_family_t family_broadcast) | 231 | static IP broadcast_ip(Family family_socket, Family family_broadcast) |
232 | { | 232 | { |
233 | IP ip; | 233 | IP ip; |
234 | ip_reset(&ip); | 234 | ip_reset(&ip); |
@@ -246,7 +246,7 @@ static IP broadcast_ip(sa_family_t family_socket, sa_family_t family_broadcast) | |||
246 | ip.family = AF_INET6; | 246 | ip.family = AF_INET6; |
247 | ip.ip6.uint32[0] = 0; | 247 | ip.ip6.uint32[0] = 0; |
248 | ip.ip6.uint32[1] = 0; | 248 | ip.ip6.uint32[1] = 0; |
249 | ip.ip6.uint32[2] = htonl(0xFFFF); | 249 | ip.ip6.uint32[2] = net_htonl(0xFFFF); |
250 | ip.ip6.uint32[3] = INADDR_BROADCAST; | 250 | ip.ip6.uint32[3] = INADDR_BROADCAST; |
251 | } | 251 | } |
252 | } else if (family_socket == AF_INET) { | 252 | } else if (family_socket == AF_INET) { |
@@ -279,7 +279,7 @@ bool Local_ip(IP ip) | |||
279 | } | 279 | } |
280 | 280 | ||
281 | /* localhost in IPv6 (::1) */ | 281 | /* localhost in IPv6 (::1) */ |
282 | if (ip.ip6.uint64[0] == 0 && ip.ip6.uint32[2] == 0 && ip.ip6.uint32[3] == htonl(1)) { | 282 | if (ip.ip6.uint64[0] == 0 && ip.ip6.uint32[2] == 0 && ip.ip6.uint32[3] == net_htonl(1)) { |
283 | return 1; | 283 | return 1; |
284 | } | 284 | } |
285 | } | 285 | } |