0
0
mirror of https://github.com/hufrea/byedpi.git synced 2025-06-30 18:43:04 +00:00

Merge branch 'hufrea:main' into cmake

This commit is contained in:
Nikolay Raspopov 2024-08-21 17:56:57 +03:00 committed by GitHub
commit d4b5cac7ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 20 deletions

View File

@ -11,13 +11,12 @@
#include <sys/mman.h>
#include <arpa/inet.h>
#include <fcntl.h>
#ifndef __linux__
#include <netinet/tcp.h>
#else
#include <sys/sendfile.h>
#include <linux/tcp.h>
#include <sys/syscall.h>
#define memfd_create(name, flags) syscall(__NR_memfd_create, name, flags)
@ -84,24 +83,25 @@ static inline void delay(long ms)
void wait_send(int sfd)
{
for (int i = 0; params.wait_send && i < 500; i++) {
struct tcpi tcpi = {};
struct tcp_info tcpi = {};
socklen_t ts = sizeof(tcpi);
if (getsockopt(sfd, IPPROTO_TCP,
TCP_INFO, (char *)&tcpi, &ts) < 0) {
uniperror("getsockopt TCP_INFO");
perror("getsockopt TCP_INFO");
break;
}
if (tcpi.state != 1) {
LOG(LOG_E, "state: %d\n", tcpi.state);
if (tcpi.tcpi_state != 1) {
LOG(LOG_E, "state: %d\n", tcpi.tcpi_state);
return;
}
if (ts < sizeof(tcpi)) {
size_t s = (char *)&tcpi.tcpi_notsent_bytes - (char *)&tcpi.tcpi_state;
if (ts < s) {
LOG(LOG_E, "tcpi_notsent_bytes not provided\n");
params.wait_send = 0;
break;
}
if (tcpi.notsent_bytes == 0) {
if (tcpi.tcpi_notsent_bytes == 0) {
return;
}
LOG(LOG_S, "not sent after %d ms\n", i);

View File

@ -18,13 +18,4 @@ int get_family(struct sockaddr *dst);
int setttl(int fd, int ttl, int family);
struct tcpi {
uint8_t state;
uint8_t r[3];
uint32_t rr[5];
uint32_t unacked;
uint32_t rrr[29];
uint32_t notsent_bytes;
};
#endif

View File

@ -70,10 +70,12 @@ static inline const int unie(int e)
#endif
#define INIT_ADDR_STR(dst) \
char ADDR_STR[INET_ADDRSTRLEN + 1]; \
char ADDR_STR[INET6_ADDRSTRLEN]; \
const char *p = 0; \
if (dst.sa.sa_family == AF_INET) \
inet_ntop(AF_INET, &dst.in.sin_addr, ADDR_STR, sizeof(ADDR_STR)); \
p = inet_ntop(AF_INET, &dst.in.sin_addr, ADDR_STR, sizeof(ADDR_STR)); \
else \
inet_ntop(AF_INET6, &dst.in6.sin6_addr, ADDR_STR, sizeof(ADDR_STR));
p = inet_ntop(AF_INET6, &dst.in6.sin6_addr, ADDR_STR, sizeof(ADDR_STR)); \
if (!p) uniperror("inet_ntop");
#endif