diff --git a/desync.c b/desync.c index 258eac4..515ae9e 100644 --- a/desync.c +++ b/desync.c @@ -9,14 +9,12 @@ #include #include #include - #include #ifdef __linux__ #include #include #include - - #include + #include #ifdef MFD_CLOEXEC #include @@ -24,6 +22,8 @@ #else #define memfd_create(name, flags) fileno(tmpfile()) #endif + #else + #include #endif #else #include @@ -86,24 +86,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); diff --git a/desync.h b/desync.h index 89989a6..9e480e9 100644 --- a/desync.h +++ b/desync.h @@ -1,10 +1 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize, ssize_t n, ssize_t offset, struct sockaddr *dst, int dp_c); - -struct tcpi { - uint8_t state; - uint8_t r[3]; - uint32_t rr[5]; - uint32_t unacked; - uint32_t rrr[29]; - uint32_t notsent_bytes; -}; \ No newline at end of file