From 5c6d706cea58eee18268ff4768716fb0f3b13974 Mon Sep 17 00:00:00 2001 From: ruti <> Date: Mon, 12 Jun 2023 10:01:40 +0200 Subject: [PATCH] usleep to nanosleep --- Makefile | 2 +- desync.c | 8 +++++++- main.c | 2 +- params.h | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index ebd663e..9d1bfb0 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ TARGET = ciadpi CC ?= gcc -CFLAGS += -std=c99 -O2 +CFLAGS += -std=c99 -O2 -D_XOPEN_SOURCE=500 SOURCES = packets.c main.c conev.c proxy.c desync.c all: diff --git a/desync.c b/desync.c index 361812c..a966791 100644 --- a/desync.c +++ b/desync.c @@ -1,5 +1,8 @@ #include +#include #include +#include +#include #include #include #include @@ -57,7 +60,10 @@ int fake_attack(int sfd, char *buffer, ssize_t n, int cnt, int pos) perror("sendfile"); break; } - usleep(params.sfdelay); + struct timespec delay = { + .tv_nsec = params.sfdelay * 1000 + }; + nanosleep(&delay, 0); memcpy(p, buffer, pos); if (setsockopt(sfd, IPPROTO_IP, IP_TTL, diff --git a/main.c b/main.c index 215d550..0c941d7 100644 --- a/main.c +++ b/main.c @@ -341,7 +341,7 @@ int main(int argc, char **argv) case 'w': // params.sfdelay = strtoul(optarg, &end, 0); - if (optarg == end || *end) + if (optarg == end || params.sfdelay > 1000000 || *end) invalid = 1; break; diff --git a/params.h b/params.h index e07b9ae..6f86985 100644 --- a/params.h +++ b/params.h @@ -47,4 +47,4 @@ extern struct packet fake_http; #define LOG_L 2 #define LOG(s, str, ...) \ - if (params.debug >= s) printf(str, ##__VA_ARGS__) \ No newline at end of file + if (params.debug >= s) printf(str, ##__VA_ARGS__)