2013-08-06 03:51:58 +08:00
|
|
|
/*
|
|
|
|
* util.c -- Utilities.
|
|
|
|
*
|
|
|
|
* This file is donated to the Tox Project.
|
|
|
|
* Copyright 2013 plutooo
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include "network.h"
|
|
|
|
|
2013-08-06 08:35:47 +08:00
|
|
|
uint64_t now()
|
|
|
|
{
|
|
|
|
return time(NULL);
|
2013-08-06 03:51:58 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 08:35:47 +08:00
|
|
|
uint64_t random_64b()
|
|
|
|
{
|
|
|
|
uint64_t r;
|
2013-08-06 03:51:58 +08:00
|
|
|
|
2013-08-06 08:35:47 +08:00
|
|
|
// This is probably not random enough?
|
|
|
|
r = random_int();
|
|
|
|
r <<= 32;
|
|
|
|
r |= random_int();
|
2013-08-06 03:51:58 +08:00
|
|
|
|
2013-08-06 08:35:47 +08:00
|
|
|
return r;
|
2013-08-06 03:51:58 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 08:35:47 +08:00
|
|
|
bool ipp_eq(IP_Port a, IP_Port b)
|
|
|
|
{
|
|
|
|
return (a.ip.i == b.ip.i) && (a.port == b.port);
|
2013-08-06 03:51:58 +08:00
|
|
|
}
|