From 87d1a2889376cd4e285d4e00aafbc2d7360ef38d Mon Sep 17 00:00:00 2001 From: ruti <> Date: Tue, 9 Apr 2024 14:06:34 +0300 Subject: [PATCH] save IP along with port --- main.c | 5 +++-- proxy.c | 23 +++++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/main.c b/main.c index 99b85fa..723cc63 100644 --- a/main.c +++ b/main.c @@ -22,7 +22,8 @@ #define close(fd) closesocket(fd) #endif -#define VERSION 8 +#define VERSION "0.8.1" + #define MPOOL_INC 16 char oob_char[1] = "a"; @@ -396,7 +397,7 @@ int main(int argc, char **argv) clear_params(); return 0; case 'v': - printf("%d\n", VERSION); + printf("%s\n", VERSION); clear_params(); return 0; diff --git a/proxy.c b/proxy.c index ab1e1f6..48634cf 100644 --- a/proxy.c +++ b/proxy.c @@ -497,27 +497,34 @@ static inline int on_tunnel(struct poolhd *pool, struct eval *val, int mode_add_get(struct sockaddr_ina *dst, int m) { // m < 0: get, m > 0: set, m == 0: delete - char *data; int len; time_t t; - struct elem *val; + struct elem *val; + + struct { + uint16_t port; + union { + struct in_addr ip4; + struct in6_addr ip6; + }; + } str = { .port = dst->in.sin_port }; if (dst->sa.sa_family == AF_INET) { - data = (char *)(&dst->in.sin_addr); - len = sizeof(dst->in.sin_addr); + str.ip4 = dst->in.sin_addr; + len = sizeof(str.port) + sizeof(str.ip4); } else { - data = (char *)(&dst->in6.sin6_addr); - len = sizeof(dst->in6.sin6_addr); + str.ip6 = dst->in6.sin6_addr; + len = sizeof(str); } - int i = mem_index(params.mempool, data, len); + int i = mem_index(params.mempool, (char *)&str, len); if (m == 0 && i >= 0) { mem_delete(params.mempool, i); return 0; } else if (m > 0) { time(&t); - val = mem_add(params.mempool, data, len, i); + val = mem_add(params.mempool, (char *)&str, len, i); if (!val) { uniperror("mem_add"); return -1;