mirror of
https://github.com/bol-van/zapret.git
synced 2025-05-24 22:32:58 +03:00
tpws: check for kernel version in fixseg
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <libgen.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <linux/tcp.h>
|
||||
@@ -477,6 +478,24 @@ void msleep(unsigned int ms)
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
bool socket_supports_notsent()
|
||||
{
|
||||
int sfd;
|
||||
struct tcp_info tcpi;
|
||||
|
||||
sfd = socket(AF_INET,SOCK_STREAM,0);
|
||||
if (sfd<0) return false;
|
||||
|
||||
socklen_t ts = sizeof(tcpi);
|
||||
if (getsockopt(sfd, IPPROTO_TCP, TCP_INFO, (char *)&tcpi, &ts) < 0)
|
||||
{
|
||||
close(sfd);
|
||||
return false;
|
||||
}
|
||||
close(sfd);
|
||||
|
||||
return ts>=((char *)&tcpi.tcpi_notsent_bytes - (char *)&tcpi.tcpi_state + sizeof(tcpi.tcpi_notsent_bytes));
|
||||
}
|
||||
bool socket_has_notsent(int sfd)
|
||||
{
|
||||
struct tcp_info tcpi;
|
||||
@@ -486,7 +505,7 @@ bool socket_has_notsent(int sfd)
|
||||
return false;
|
||||
if (tcpi.tcpi_state != 1) // TCP_ESTABLISHED
|
||||
return false;
|
||||
size_t s = (char *)&tcpi.tcpi_notsent_bytes - (char *)&tcpi.tcpi_state;
|
||||
size_t s = (char *)&tcpi.tcpi_notsent_bytes - (char *)&tcpi + sizeof(tcpi.tcpi_notsent_bytes);
|
||||
if (ts < s)
|
||||
// old structure version
|
||||
return false;
|
||||
|
@@ -120,6 +120,7 @@ static inline const struct in6_addr *mask_from_preflen6(uint8_t preflen)
|
||||
|
||||
void msleep(unsigned int ms);
|
||||
#ifdef __linux__
|
||||
bool socket_supports_notsent();
|
||||
bool socket_has_notsent(int sfd);
|
||||
bool socket_wait_notsent(int sfd, unsigned int delay_ms, unsigned int *wasted_ms);
|
||||
#endif
|
||||
|
@@ -1236,6 +1236,11 @@ void parse_params(int argc, char *argv[])
|
||||
}
|
||||
break;
|
||||
case 65: /* fix-seg */
|
||||
if (!socket_supports_notsent())
|
||||
{
|
||||
DLOG_ERR("--fix-seg is supported since kernel 4.6\n");
|
||||
exit_clean(1);
|
||||
}
|
||||
if (optarg)
|
||||
{
|
||||
i = atoi(optarg);
|
||||
|
Reference in New Issue
Block a user