From 29d777ef67bc964229722db073a2abdd1eb737b6 Mon Sep 17 00:00:00 2001 From: "Coren[m]" Date: Mon, 9 Sep 2013 14:16:40 +0200 Subject: network.h: - IP: add in_addr_t as part of the union - IP: rename IP to IP4 --- other/DHT_bootstrap.c | 2 +- testing/DHT_test.c | 2 +- testing/Lossless_UDP_testclient.c | 2 +- testing/Lossless_UDP_testserver.c | 2 +- toxcore/DHT.c | 10 +++++----- toxcore/LAN_discovery.c | 6 +++--- toxcore/Messenger.c | 2 +- toxcore/network.c | 2 +- toxcore/network.h | 9 +++++---- 9 files changed, 19 insertions(+), 18 deletions(-) diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index a42545b1..bc0c592a 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -83,7 +83,7 @@ int main(int argc, char *argv[]) { /* Initialize networking - Bind to ip 0.0.0.0:PORT */ - IP ip; + IP4 ip; ip.uint32 = 0; DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT))); manage_keys(dht); diff --git a/testing/DHT_test.c b/testing/DHT_test.c index fce9c257..a7349a65 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c @@ -141,7 +141,7 @@ int main(int argc, char *argv[]) //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); /* initialize networking */ /* bind to ip 0.0.0.0:PORT */ - IP ip; + IP4 ip; ip.uint32 = 0; DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT))); diff --git a/testing/Lossless_UDP_testclient.c b/testing/Lossless_UDP_testclient.c index d5fb1544..4ac94b4b 100644 --- a/testing/Lossless_UDP_testclient.c +++ b/testing/Lossless_UDP_testclient.c @@ -168,7 +168,7 @@ int main(int argc, char *argv[]) /* initialize networking */ /* bind to ip 0.0.0.0:PORT */ - IP ip; + IP4 ip; ip.uint32 = 0; Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT)); perror("Initialization"); diff --git a/testing/Lossless_UDP_testserver.c b/testing/Lossless_UDP_testserver.c index eb506b3d..e0ea92bc 100644 --- a/testing/Lossless_UDP_testserver.c +++ b/testing/Lossless_UDP_testserver.c @@ -163,7 +163,7 @@ int main(int argc, char *argv[]) //initialize networking //bind to ip 0.0.0.0:PORT - IP ip; + IP4 ip; ip.uint32 = 0; Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT)); perror("Initialization"); diff --git a/toxcore/DHT.c b/toxcore/DHT.c index e664c21c..3f3aef05 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -1030,9 +1030,9 @@ static int handle_NATping(void *object, IP_Port source, uint8_t *source_pubkey, * * return ip of 0 if failure. */ -static IP NAT_commonip(IP_Port *ip_portlist, uint16_t len, uint16_t min_num) +static IP4 NAT_commonip(IP_Port *ip_portlist, uint16_t len, uint16_t min_num) { - IP zero = {{0}}; + IP4 zero = {{0}}; if (len > MAX_FRIEND_CLIENTS) return zero; @@ -1059,7 +1059,7 @@ static IP NAT_commonip(IP_Port *ip_portlist, uint16_t len, uint16_t min_num) * * return number of ports and puts the list of ports in portlist. */ -static uint16_t NAT_getports(uint16_t *portlist, IP_Port *ip_portlist, uint16_t len, IP ip) +static uint16_t NAT_getports(uint16_t *portlist, IP_Port *ip_portlist, uint16_t len, IP4 ip) { uint32_t i; uint16_t num = 0; @@ -1074,7 +1074,7 @@ static uint16_t NAT_getports(uint16_t *portlist, IP_Port *ip_portlist, uint16_t return num; } -static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, uint16_t friend_num) +static void punch_holes(DHT *dht, IP4 ip, uint16_t *port_list, uint16_t numports, uint16_t friend_num) { if (numports > MAX_FRIEND_CLIENTS || numports == 0) return; @@ -1114,7 +1114,7 @@ static void do_NAT(DHT *dht) dht->friends_list[i].punching_timestamp + PUNCH_INTERVAL < temp_time && dht->friends_list[i].recvNATping_timestamp + PUNCH_INTERVAL * 2 >= temp_time) { - IP ip = NAT_commonip(ip_list, num, MAX_FRIEND_CLIENTS / 2); + IP4 ip = NAT_commonip(ip_list, num, MAX_FRIEND_CLIENTS / 2); if (ip.uint32 == 0) continue; diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c index fe9f748b..73337539 100644 --- a/toxcore/LAN_discovery.c +++ b/toxcore/LAN_discovery.c @@ -81,9 +81,9 @@ static uint32_t send_broadcasts(Networking_Core *net, uint16_t port, uint8_t * d #endif /* Return the broadcast ip. */ -static IP broadcast_ip(void) +static IP4 broadcast_ip(void) { - IP ip; + IP4 ip; ip.uint32 = ~0; return ip; } @@ -91,7 +91,7 @@ static IP broadcast_ip(void) /* return 0 if ip is a LAN ip. * return -1 if it is not. */ -static int LAN_ip(IP ip) +static int LAN_ip(IP4 ip) { if (ip.uint8[0] == 127) /* Loopback. */ return 0; diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 07893e02..e18e9efc 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -657,7 +657,7 @@ Messenger *initMessenger(void) if ( ! m ) return NULL; - IP ip; + IP4 ip; ip.uint32 = 0; m->net = new_networking(ip, PORT); diff --git a/toxcore/network.c b/toxcore/network.c index 53b7e3b5..622a4b17 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -156,7 +156,7 @@ static void at_shutdown(void) * return Networking_Core object if no problems * return NULL if there are problems. */ -Networking_Core *new_networking(IP ip, uint16_t port) +Networking_Core *new_networking(IP4 ip, uint16_t port) { if (at_startup() != 0) return NULL; diff --git a/toxcore/network.h b/toxcore/network.h index 8d494957..9991c4a4 100644 --- a/toxcore/network.h +++ b/toxcore/network.h @@ -86,11 +86,12 @@ typedef union { uint8_t uint8[4]; uint16_t uint16[2]; uint32_t uint32; -} IP; + in_addr_t in_addr; +} IP4; typedef union { struct { - IP ip; + IP4 ip; uint16_t port; /* Not used for anything right now. */ uint16_t padding; @@ -101,7 +102,7 @@ typedef union { typedef struct { int16_t family; uint16_t port; - IP ip; + IP4 ip; uint8_t zeroes[8]; #ifdef ENABLE_IPV6 uint8_t zeroes2[12]; @@ -155,7 +156,7 @@ void networking_poll(Networking_Core *net); * return 0 if no problems. * return -1 if there were problems. */ -Networking_Core *new_networking(IP ip, uint16_t port); +Networking_Core *new_networking(IP4 ip, uint16_t port); /* Function to cleanup networking stuff (doesn't do much right now). */ void kill_networking(Networking_Core *net); -- cgit v1.2.3