mirror of
https://github.com/sonertari/SSLproxy
synced 2024-10-31 21:20:21 +00:00
Use clock_gettime() instead of gettimeofday(), thanks to @disaykin
This commit is contained in:
parent
b3705efe9d
commit
d7bf0bd53d
12
src/logpkt.c
12
src/logpkt.c
@ -40,6 +40,7 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef WITHOUT_MIRROR
|
||||
@ -298,11 +299,16 @@ static int
|
||||
logpkt_pcap_write(const uint8_t *pkt, size_t pktsz, int fd)
|
||||
{
|
||||
pcap_rec_hdr_t rec_hdr;
|
||||
struct timeval tv;
|
||||
struct timespec tv;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &tv) == -1)
|
||||
{
|
||||
log_err_printf("Error getting current time: %s\n",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
rec_hdr.ts_sec = tv.tv_sec;
|
||||
rec_hdr.ts_usec = tv.tv_usec;
|
||||
rec_hdr.ts_usec = tv.tv_nsec / 1000;
|
||||
rec_hdr.orig_len = rec_hdr.incl_len = pktsz;
|
||||
|
||||
if (logpkt_write_all(fd, &rec_hdr, sizeof(rec_hdr)) == -1) {
|
||||
|
@ -38,7 +38,6 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/time.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
@ -50,6 +49,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef _SC_NPROCESSORS_ONLN
|
||||
@ -1019,12 +1019,12 @@ static int sys_rand_seeded = 0;
|
||||
|
||||
static void
|
||||
sys_rand_seed(void) {
|
||||
struct timeval seed;
|
||||
struct timespec seed;
|
||||
|
||||
if (gettimeofday(&seed, NULL) == -1) {
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &seed) == -1) {
|
||||
srandom((unsigned)time(NULL));
|
||||
} else {
|
||||
srandom((unsigned)(seed.tv_sec ^ seed.tv_usec));
|
||||
srandom((unsigned)(seed.tv_sec ^ seed.tv_nsec));
|
||||
}
|
||||
sys_rand_seeded = 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user