From 5dac21bc48d27eea3ebc20362d6e16d6260b969b Mon Sep 17 00:00:00 2001 From: ruti <> Date: Mon, 12 Aug 2024 20:38:14 +0300 Subject: [PATCH] fix headers, sa_size macros, replace getopt_long_only --- Makefile | 2 +- conev.c | 1 - extend.c | 1 - extend.h | 1 - main.c | 5 +++-- mpool.c | 2 -- packets.c | 3 +-- params.h | 3 +++ proxy.c | 16 ++++++++-------- proxy.h | 5 +++++ win_service.c | 1 - win_service.h | 6 ------ 12 files changed, 21 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index 40f6708..4d96fe8 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ TARGET = ciadpi -CPPFLAGS = -D_XOPEN_SOURCE=500 +#CPPFLAGS = -D_XOPEN_SOURCE=500 CFLAGS += -I. -std=c99 -Wall -Wno-unused -O2 WIN_LDFLAGS = -lws2_32 -lmswsock diff --git a/conev.c b/conev.c index 6387775..a3f1ce0 100644 --- a/conev.c +++ b/conev.c @@ -1,4 +1,3 @@ - #include "conev.h" #include diff --git a/extend.c b/extend.c index d5d6d59..ac90b02 100644 --- a/extend.c +++ b/extend.c @@ -1,4 +1,3 @@ - #include "extend.h" #ifdef _WIN32 diff --git a/extend.h b/extend.h index 8a6ab8f..22d8ed8 100644 --- a/extend.h +++ b/extend.h @@ -3,7 +3,6 @@ #include -#include "conev.h" #include "proxy.h" int connect_hook(struct poolhd *pool, struct eval *val, diff --git a/main.c b/main.c index 19e0c2b..28a17a3 100644 --- a/main.c +++ b/main.c @@ -16,8 +16,9 @@ #include #include #include + #include #include - #include + #include #else #include #include "win_service.h" @@ -441,7 +442,7 @@ int main(int argc, char **argv) return -1; } - while (!invalid && (rez = getopt_long_only( + while (!invalid && (rez = getopt_long( argc, argv, opt, options, 0)) != -1) { switch (rez) { diff --git a/mpool.c b/mpool.c index 9d4fd42..50fe43e 100644 --- a/mpool.c +++ b/mpool.c @@ -1,11 +1,9 @@ - #include "mpool.h" #include #include - static inline int scmp(const struct elem *p, const struct elem *q) { if (p->len != q ->len) { diff --git a/packets.c b/packets.c index ebe4d39..ecc84ab 100644 --- a/packets.c +++ b/packets.c @@ -1,5 +1,3 @@ -#define _GNU_SOURCE - #include "packets.h" #include @@ -8,6 +6,7 @@ #include #include #include +#include #ifdef _WIN32 #include diff --git a/params.h b/params.h index a8ff74b..d329108 100644 --- a/params.h +++ b/params.h @@ -10,6 +10,9 @@ #include #else #include + #include + #include + #include #endif #if defined(__linux__) || defined(_WIN32) diff --git a/proxy.c b/proxy.c index c938857..88539e4 100644 --- a/proxy.c +++ b/proxy.c @@ -346,7 +346,7 @@ int create_conn(struct poolhd *pool, } } if (bind(sfd, (struct sockaddr *)¶ms.baddr, - sizeof(params.baddr)) < 0) { + SA_SIZE(¶ms.baddr)) < 0) { uniperror("bind"); close(sfd); return -1; @@ -376,7 +376,7 @@ int create_conn(struct poolhd *pool, close(sfd); return -1; } - int status = connect(sfd, &addr.sa, sizeof(addr)); + int status = connect(sfd, &addr.sa, SA_SIZE(&addr)); if (status == 0 && params.tfo) { LOG(LOG_S, "TFO supported!\n"); } @@ -432,7 +432,7 @@ int udp_associate(struct poolhd *pool, map_fix(&addr, 6); } if (bind(ufd, (struct sockaddr *)¶ms.baddr, - sizeof(params.baddr)) < 0) { + SA_SIZE(¶ms.baddr)) < 0) { uniperror("bind"); close(ufd); return -1; @@ -443,7 +443,7 @@ int udp_associate(struct poolhd *pool, return -1; } if (dst->in6.sin6_port != 0) { - if (connect(ufd, &addr.sa, sizeof(addr)) < 0) { + if (connect(ufd, &addr.sa, SA_SIZE(&addr)) < 0) { uniperror("connect"); del_event(pool, pair); return -1; @@ -465,7 +465,7 @@ int udp_associate(struct poolhd *pool, del_event(pool, pair); return -1; } - if (bind(cfd, &addr.sa, sizeof(addr)) < 0) { + if (bind(cfd, &addr.sa, SA_SIZE(&addr)) < 0) { uniperror("bind"); del_event(pool, pair); close(cfd); @@ -670,7 +670,7 @@ int on_udp_tunnel(struct eval *val, char *buffer, size_t bfsize) if (!addr_equ(&addr, (struct sockaddr_ina *)&val->in6)) { return 0; } - if (connect(val->fd, &addr.sa, sizeof(addr)) < 0) { + if (connect(val->fd, &addr.sa, SA_SIZE(&addr)) < 0) { uniperror("connect"); return -1; } @@ -691,7 +691,7 @@ int on_udp_tunnel(struct eval *val, char *buffer, size_t bfsize) if (params.baddr.sin6_family != addr.sa.sa_family) { return -1; } - if (connect(val->pair->fd, &addr.sa, sizeof(addr)) < 0) { + if (connect(val->pair->fd, &addr.sa, SA_SIZE(&addr)) < 0) { uniperror("connect"); return -1; } @@ -940,7 +940,7 @@ int listen_socket(struct sockaddr_ina *srv) close(srvfd); return -1; } - if (bind(srvfd, &srv->sa, sizeof(*srv)) < 0) { + if (bind(srvfd, &srv->sa, SA_SIZE(srv)) < 0) { uniperror("bind"); close(srvfd); return -1; diff --git a/proxy.h b/proxy.h index 43e5756..29eaee2 100644 --- a/proxy.h +++ b/proxy.h @@ -7,10 +7,15 @@ #include #else #include + #include #endif #include "conev.h" +#define SA_SIZE(s) \ + (((struct sockaddr *)s)->sa_family == AF_INET6) ? \ + sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in) + struct sockaddr_ina { union { struct sockaddr sa; diff --git a/win_service.c b/win_service.c index 8645f45..9399974 100644 --- a/win_service.c +++ b/win_service.c @@ -1,4 +1,3 @@ - #include "win_service.h" #include diff --git a/win_service.h b/win_service.h index 65b797a..104c44c 100644 --- a/win_service.h +++ b/win_service.h @@ -1,7 +1 @@ -#ifndef WIN_SERVICE_H -#define WIN_SERVICE_H - int register_winsvc(int argc, char *argv[]); - - -#endif