summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCoren[m] <Break@Ocean>2013-09-09 14:16:40 +0200
committerCoren[m] <Break@Ocean>2013-09-09 14:16:40 +0200
commit29d777ef67bc964229722db073a2abdd1eb737b6 (patch)
treeaaa91593de5c47199d1124456266e7da4483e2ad
parenta128e3ff8f09250757ed4ed73fcc088cb5fd15ee (diff)
network.h:
- IP: add in_addr_t as part of the union - IP: rename IP to IP4
-rw-r--r--other/DHT_bootstrap.c2
-rw-r--r--testing/DHT_test.c2
-rw-r--r--testing/Lossless_UDP_testclient.c2
-rw-r--r--testing/Lossless_UDP_testserver.c2
-rw-r--r--toxcore/DHT.c10
-rw-r--r--toxcore/LAN_discovery.c6
-rw-r--r--toxcore/Messenger.c2
-rw-r--r--toxcore/network.c2
-rw-r--r--toxcore/network.h9
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[])
83{ 83{
84 /* Initialize networking - 84 /* Initialize networking -
85 Bind to ip 0.0.0.0:PORT */ 85 Bind to ip 0.0.0.0:PORT */
86 IP ip; 86 IP4 ip;
87 ip.uint32 = 0; 87 ip.uint32 = 0;
88 DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT))); 88 DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT)));
89 manage_keys(dht); 89 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[])
141 //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); 141 //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32);
142 /* initialize networking */ 142 /* initialize networking */
143 /* bind to ip 0.0.0.0:PORT */ 143 /* bind to ip 0.0.0.0:PORT */
144 IP ip; 144 IP4 ip;
145 ip.uint32 = 0; 145 ip.uint32 = 0;
146 146
147 DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT))); 147 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[])
168 168
169 /* initialize networking */ 169 /* initialize networking */
170 /* bind to ip 0.0.0.0:PORT */ 170 /* bind to ip 0.0.0.0:PORT */
171 IP ip; 171 IP4 ip;
172 ip.uint32 = 0; 172 ip.uint32 = 0;
173 Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT)); 173 Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT));
174 perror("Initialization"); 174 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[])
163 163
164 //initialize networking 164 //initialize networking
165 //bind to ip 0.0.0.0:PORT 165 //bind to ip 0.0.0.0:PORT
166 IP ip; 166 IP4 ip;
167 ip.uint32 = 0; 167 ip.uint32 = 0;
168 Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT)); 168 Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT));
169 perror("Initialization"); 169 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,
1030 * 1030 *
1031 * return ip of 0 if failure. 1031 * return ip of 0 if failure.
1032 */ 1032 */
1033static IP NAT_commonip(IP_Port *ip_portlist, uint16_t len, uint16_t min_num) 1033static IP4 NAT_commonip(IP_Port *ip_portlist, uint16_t len, uint16_t min_num)
1034{ 1034{
1035 IP zero = {{0}}; 1035 IP4 zero = {{0}};
1036 1036
1037 if (len > MAX_FRIEND_CLIENTS) 1037 if (len > MAX_FRIEND_CLIENTS)
1038 return zero; 1038 return zero;
@@ -1059,7 +1059,7 @@ static IP NAT_commonip(IP_Port *ip_portlist, uint16_t len, uint16_t min_num)
1059 * 1059 *
1060 * return number of ports and puts the list of ports in portlist. 1060 * return number of ports and puts the list of ports in portlist.
1061 */ 1061 */
1062static uint16_t NAT_getports(uint16_t *portlist, IP_Port *ip_portlist, uint16_t len, IP ip) 1062static uint16_t NAT_getports(uint16_t *portlist, IP_Port *ip_portlist, uint16_t len, IP4 ip)
1063{ 1063{
1064 uint32_t i; 1064 uint32_t i;
1065 uint16_t num = 0; 1065 uint16_t num = 0;
@@ -1074,7 +1074,7 @@ static uint16_t NAT_getports(uint16_t *portlist, IP_Port *ip_portlist, uint16_t
1074 return num; 1074 return num;
1075} 1075}
1076 1076
1077static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, uint16_t friend_num) 1077static void punch_holes(DHT *dht, IP4 ip, uint16_t *port_list, uint16_t numports, uint16_t friend_num)
1078{ 1078{
1079 if (numports > MAX_FRIEND_CLIENTS || numports == 0) 1079 if (numports > MAX_FRIEND_CLIENTS || numports == 0)
1080 return; 1080 return;
@@ -1114,7 +1114,7 @@ static void do_NAT(DHT *dht)
1114 dht->friends_list[i].punching_timestamp + PUNCH_INTERVAL < temp_time && 1114 dht->friends_list[i].punching_timestamp + PUNCH_INTERVAL < temp_time &&
1115 dht->friends_list[i].recvNATping_timestamp + PUNCH_INTERVAL * 2 >= temp_time) { 1115 dht->friends_list[i].recvNATping_timestamp + PUNCH_INTERVAL * 2 >= temp_time) {
1116 1116
1117 IP ip = NAT_commonip(ip_list, num, MAX_FRIEND_CLIENTS / 2); 1117 IP4 ip = NAT_commonip(ip_list, num, MAX_FRIEND_CLIENTS / 2);
1118 1118
1119 if (ip.uint32 == 0) 1119 if (ip.uint32 == 0)
1120 continue; 1120 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
81#endif 81#endif
82 82
83/* Return the broadcast ip. */ 83/* Return the broadcast ip. */
84static IP broadcast_ip(void) 84static IP4 broadcast_ip(void)
85{ 85{
86 IP ip; 86 IP4 ip;
87 ip.uint32 = ~0; 87 ip.uint32 = ~0;
88 return ip; 88 return ip;
89} 89}
@@ -91,7 +91,7 @@ static IP broadcast_ip(void)
91/* return 0 if ip is a LAN ip. 91/* return 0 if ip is a LAN ip.
92 * return -1 if it is not. 92 * return -1 if it is not.
93 */ 93 */
94static int LAN_ip(IP ip) 94static int LAN_ip(IP4 ip)
95{ 95{
96 if (ip.uint8[0] == 127) /* Loopback. */ 96 if (ip.uint8[0] == 127) /* Loopback. */
97 return 0; 97 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)
657 if ( ! m ) 657 if ( ! m )
658 return NULL; 658 return NULL;
659 659
660 IP ip; 660 IP4 ip;
661 ip.uint32 = 0; 661 ip.uint32 = 0;
662 m->net = new_networking(ip, PORT); 662 m->net = new_networking(ip, PORT);
663 663
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)
156 * return Networking_Core object if no problems 156 * return Networking_Core object if no problems
157 * return NULL if there are problems. 157 * return NULL if there are problems.
158 */ 158 */
159Networking_Core *new_networking(IP ip, uint16_t port) 159Networking_Core *new_networking(IP4 ip, uint16_t port)
160{ 160{
161 if (at_startup() != 0) 161 if (at_startup() != 0)
162 return NULL; 162 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 {
86 uint8_t uint8[4]; 86 uint8_t uint8[4];
87 uint16_t uint16[2]; 87 uint16_t uint16[2];
88 uint32_t uint32; 88 uint32_t uint32;
89} IP; 89 in_addr_t in_addr;
90} IP4;
90 91
91typedef union { 92typedef union {
92 struct { 93 struct {
93 IP ip; 94 IP4 ip;
94 uint16_t port; 95 uint16_t port;
95 /* Not used for anything right now. */ 96 /* Not used for anything right now. */
96 uint16_t padding; 97 uint16_t padding;
@@ -101,7 +102,7 @@ typedef union {
101typedef struct { 102typedef struct {
102 int16_t family; 103 int16_t family;
103 uint16_t port; 104 uint16_t port;
104 IP ip; 105 IP4 ip;
105 uint8_t zeroes[8]; 106 uint8_t zeroes[8];
106#ifdef ENABLE_IPV6 107#ifdef ENABLE_IPV6
107 uint8_t zeroes2[12]; 108 uint8_t zeroes2[12];
@@ -155,7 +156,7 @@ void networking_poll(Networking_Core *net);
155 * return 0 if no problems. 156 * return 0 if no problems.
156 * return -1 if there were problems. 157 * return -1 if there were problems.
157 */ 158 */
158Networking_Core *new_networking(IP ip, uint16_t port); 159Networking_Core *new_networking(IP4 ip, uint16_t port);
159 160
160/* Function to cleanup networking stuff (doesn't do much right now). */ 161/* Function to cleanup networking stuff (doesn't do much right now). */
161void kill_networking(Networking_Core *net); 162void kill_networking(Networking_Core *net);