mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
network.h:
- IP: add in_addr_t as part of the union - IP: rename IP to IP4
This commit is contained in:
parent
a128e3ff8f
commit
29d777ef67
|
@ -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);
|
||||
|
|
|
@ -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)));
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -657,7 +657,7 @@ Messenger *initMessenger(void)
|
|||
if ( ! m )
|
||||
return NULL;
|
||||
|
||||
IP ip;
|
||||
IP4 ip;
|
||||
ip.uint32 = 0;
|
||||
m->net = new_networking(ip, PORT);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user