save IP along with port

This commit is contained in:
ruti 2024-04-09 14:06:34 +03:00
parent 54e9947de4
commit 87d1a28893
2 changed files with 18 additions and 10 deletions

5
main.c
View File

@ -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;

23
proxy.c
View File

@ -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;