mirror of
https://github.com/bol-van/zapret2.git
synced 2026-03-14 06:13:09 +00:00
nfqws2: compile compat
This commit is contained in:
@@ -216,7 +216,7 @@ static void ConntrackFeedPacket(t_ctrack *t, bool bReverse, const struct dissect
|
|||||||
ConntrackApplyPos(t, bReverse, dis);
|
ConntrackApplyPos(t, bReverse, dis);
|
||||||
}
|
}
|
||||||
|
|
||||||
clock_gettime(CLOCK_BOOTTIME, &t->pos.t_last);
|
clock_gettime(CLOCK_BOOT_OR_UPTIME, &t->pos.t_last);
|
||||||
// make sure t_start gets exactly the same value as first t_last
|
// make sure t_start gets exactly the same value as first t_last
|
||||||
if (!t->t_start.tv_sec) t->t_start = t->pos.t_last;
|
if (!t->t_start.tv_sec) t->t_start = t->pos.t_last;
|
||||||
}
|
}
|
||||||
@@ -346,10 +346,10 @@ static void taddr2str(uint8_t l3proto, const t_addr *a, char *buf, size_t bufsiz
|
|||||||
void ConntrackPoolDump(const t_conntrack *p)
|
void ConntrackPoolDump(const t_conntrack *p)
|
||||||
{
|
{
|
||||||
t_conntrack_pool *t, *tmp;
|
t_conntrack_pool *t, *tmp;
|
||||||
struct timespec tnow;
|
time_t tnow;
|
||||||
char sa1[40], sa2[40];
|
char sa1[40], sa2[40];
|
||||||
|
|
||||||
if (clock_gettime(CLOCK_BOOTTIME, &tnow)) return;
|
if (!(tnow=boottime())) return;
|
||||||
HASH_ITER(hh, p->pool, t, tmp) {
|
HASH_ITER(hh, p->pool, t, tmp) {
|
||||||
taddr2str(t->conn.l3proto, &t->conn.src, sa1, sizeof(sa1));
|
taddr2str(t->conn.l3proto, &t->conn.src, sa1, sizeof(sa1));
|
||||||
taddr2str(t->conn.l3proto, &t->conn.dst, sa2, sizeof(sa2));
|
taddr2str(t->conn.l3proto, &t->conn.dst, sa2, sizeof(sa2));
|
||||||
@@ -357,7 +357,7 @@ void ConntrackPoolDump(const t_conntrack *p)
|
|||||||
proto_name(t->conn.l4proto),
|
proto_name(t->conn.l4proto),
|
||||||
sa1, t->conn.sport, sa2, t->conn.dport,
|
sa1, t->conn.sport, sa2, t->conn.dport,
|
||||||
t->conn.l4proto == IPPROTO_TCP ? connstate_s[t->track.pos.state] : "-",
|
t->conn.l4proto == IPPROTO_TCP ? connstate_s[t->track.pos.state] : "-",
|
||||||
(unsigned long long)t->track.t_start.tv_sec, (unsigned long long)(t->track.pos.t_last.tv_sec - t->track.t_start.tv_sec), (unsigned long long)(tnow.tv_sec - t->track.pos.t_last.tv_sec),
|
(unsigned long long)t->track.t_start.tv_sec, (unsigned long long)(t->track.pos.t_last.tv_sec - t->track.t_start.tv_sec), (unsigned long long)(tnow - t->track.pos.t_last.tv_sec),
|
||||||
(unsigned long long)t->track.pos.client.pdcounter, (unsigned long long)t->track.pos.client.pcounter, (unsigned long long)t->track.pos.client.pbcounter,
|
(unsigned long long)t->track.pos.client.pdcounter, (unsigned long long)t->track.pos.client.pcounter, (unsigned long long)t->track.pos.client.pbcounter,
|
||||||
(unsigned long long)t->track.pos.server.pdcounter, (unsigned long long)t->track.pos.server.pcounter, (unsigned long long)t->track.pos.server.pbcounter);
|
(unsigned long long)t->track.pos.server.pdcounter, (unsigned long long)t->track.pos.server.pcounter, (unsigned long long)t->track.pos.server.pbcounter);
|
||||||
if (t->conn.l4proto == IPPROTO_TCP)
|
if (t->conn.l4proto == IPPROTO_TCP)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
#include "random.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -11,12 +12,6 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
|
||||||
#include "andr/random.h"
|
|
||||||
#elif defined(__linux__) || defined(__CYGWIN__)
|
|
||||||
#include <sys/random.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define UNIQ_SORT \
|
#define UNIQ_SORT \
|
||||||
{ \
|
{ \
|
||||||
size_t i, j, u; \
|
size_t i, j, u; \
|
||||||
@@ -479,6 +474,30 @@ void fill_random_az09(uint8_t *p,size_t sz)
|
|||||||
p[k] = rnd<10 ? rnd+'0' : 'a'+rnd-10;
|
p[k] = rnd<10 ? rnd+'0' : 'a'+rnd-10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if defined(__FreeBSD__) && __FreeBSD_version <= 1200000
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
int getentropy(void *buf, size_t len)
|
||||||
|
{
|
||||||
|
int mib[2];
|
||||||
|
size_t size = len;
|
||||||
|
|
||||||
|
// Check for reasonable length (getentropy limits to 256)
|
||||||
|
if (len > 256) {
|
||||||
|
errno = EIO;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
mib[0] = CTL_KERN;
|
||||||
|
mib[1] = KERN_ARND;
|
||||||
|
|
||||||
|
if (sysctl(mib, 2, buf, &size, NULL, 0) == -1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (size == len) ? 0 : -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool fill_crypto_random_bytes(uint8_t *p,size_t sz)
|
bool fill_crypto_random_bytes(uint8_t *p,size_t sz)
|
||||||
{
|
{
|
||||||
ssize_t rd;
|
ssize_t rd;
|
||||||
@@ -626,5 +645,5 @@ const struct in6_addr *mask_from_bitcount6(uint32_t zct)
|
|||||||
time_t boottime(void)
|
time_t boottime(void)
|
||||||
{
|
{
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
return clock_gettime(CLOCK_BOOTTIME, &ts) ? 0 : ts.tv_sec;
|
return clock_gettime(CLOCK_BOOT_OR_UPTIME, &ts) ? 0 : ts.tv_sec;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,10 @@ time_t file_mod_time(const char *filename);
|
|||||||
bool file_size(const char *filename, off_t *size);
|
bool file_size(const char *filename, off_t *size);
|
||||||
bool file_open_test(const char *filename, int flags);
|
bool file_open_test(const char *filename, int flags);
|
||||||
|
|
||||||
|
#if defined(__FreeBSD__) && __FreeBSD_version <= 1200000
|
||||||
|
int getentropy(void *buf, size_t len);
|
||||||
|
#endif
|
||||||
|
|
||||||
void fill_random_bytes(uint8_t *p,size_t sz);
|
void fill_random_bytes(uint8_t *p,size_t sz);
|
||||||
void fill_random_az(uint8_t *p,size_t sz);
|
void fill_random_az(uint8_t *p,size_t sz);
|
||||||
void fill_random_az09(uint8_t *p,size_t sz);
|
void fill_random_az09(uint8_t *p,size_t sz);
|
||||||
@@ -105,4 +109,12 @@ uint32_t mask_from_bitcount(uint32_t zct);
|
|||||||
void mask_from_bitcount6_prepare(void);
|
void mask_from_bitcount6_prepare(void);
|
||||||
const struct in6_addr *mask_from_bitcount6(uint32_t zct);
|
const struct in6_addr *mask_from_bitcount6(uint32_t zct);
|
||||||
|
|
||||||
|
#ifdef CLOCK_BOOTTIME
|
||||||
|
#define CLOCK_BOOT_OR_UPTIME CLOCK_BOOTTIME
|
||||||
|
#elif defined(CLOCK_UPTIME)
|
||||||
|
#define CLOCK_BOOT_OR_UPTIME CLOCK_UPTIME
|
||||||
|
#else
|
||||||
|
#define CLOCK_BOOT_OR_UPTIME CLOCK_MONOTINIC
|
||||||
|
#endif
|
||||||
|
|
||||||
time_t boottime(void);
|
time_t boottime(void);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#if __ANDROID_API__ < 28
|
|
||||||
|
|
||||||
#include "random.h"
|
#include "random.h"
|
||||||
|
|
||||||
|
#ifdef NEED_GETRANDOM
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/syscall.h>
|
|
||||||
|
|
||||||
#ifndef SYS_getrandom
|
#ifndef SYS_getrandom
|
||||||
|
|
||||||
@@ -19,6 +19,9 @@
|
|||||||
#elif defined(__i386__)
|
#elif defined(__i386__)
|
||||||
#define SYS_getrandom 355
|
#define SYS_getrandom 355
|
||||||
|
|
||||||
|
#elif defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32
|
||||||
|
#define SYS_getrandom 4353
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#error "Unsupported architecture: SYS_getrandom not defined"
|
#error "Unsupported architecture: SYS_getrandom not defined"
|
||||||
#endif
|
#endif
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if __ANDROID_API__ < 28
|
// shim for old NDK and old gcc linux compilers
|
||||||
|
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
|
||||||
|
#if defined(__linux__)
|
||||||
|
|
||||||
|
#if defined(__ANDROID__) && __ANDROID_API__ < 28 || !defined(SYS_getrandom)
|
||||||
|
|
||||||
|
#define NEED_GETRANDOM
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
@@ -15,3 +23,5 @@ ssize_t getrandom(void *ptr, size_t len, unsigned int flags);
|
|||||||
#include <sys/random.h>
|
#include <sys/random.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user