mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Added a function.
This commit is contained in:
parent
87633f6631
commit
3986206de8
|
@ -40,6 +40,16 @@ uint64_t current_time()
|
|||
|
||||
}
|
||||
|
||||
int random_int()
|
||||
{
|
||||
#ifdef WIN32
|
||||
//TODO replace rand with a more random windows function
|
||||
return rand();
|
||||
#else
|
||||
return random();
|
||||
#endif
|
||||
}
|
||||
|
||||
//our UDP socket, a global variable.
|
||||
static int sock;
|
||||
|
||||
|
@ -87,7 +97,11 @@ int init_networking(IP ip ,uint16_t port)
|
|||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
#else
|
||||
srandom((uint32_t)current_time());
|
||||
#endif
|
||||
srand((uint32_t)current_time());
|
||||
|
||||
//initialize our socket
|
||||
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
|
|
|
@ -79,6 +79,9 @@ typedef struct
|
|||
//returns current time in milleseconds since the epoch.
|
||||
uint64_t current_time();
|
||||
|
||||
//return a random number
|
||||
int random_int();
|
||||
|
||||
//Basic network functions:
|
||||
|
||||
//Function to send packet(data) of length length to ip_port
|
||||
|
|
|
@ -96,9 +96,6 @@ void printpacket(char * data, uint32_t length, IP_Port ip_port)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
srand(time(NULL));
|
||||
int randdomnum = rand();
|
||||
memcpy(self_client_id, &randdomnum, 4);
|
||||
//memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32);
|
||||
|
||||
if (argc < 4) {
|
||||
|
@ -107,13 +104,16 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
addfriend(argv[3]);
|
||||
|
||||
|
||||
//initialize networking
|
||||
//bind to ip 0.0.0.0:PORT
|
||||
IP ip;
|
||||
ip.i = 0;
|
||||
init_networking(ip, PORT);
|
||||
|
||||
int randdomnum = random_int();
|
||||
memcpy(self_client_id, &randdomnum, 4);
|
||||
|
||||
|
||||
perror("Initialization");
|
||||
IP_Port bootstrap_ip_port;
|
||||
bootstrap_ip_port.port = htons(atoi(argv[2]));
|
||||
|
|
Loading…
Reference in New Issue
Block a user