From 1e00b9ac1ee473b13c01010b32fc40dca8f0fb9b Mon Sep 17 00:00:00 2001 From: rofl0r Date: Wed, 23 Sep 2020 17:00:16 +0100 Subject: [PATCH] get rid of ip_type.c --- Makefile | 2 +- src/allocator_thread.c | 8 ++++---- src/core.c | 6 +++--- src/hostsreader.c | 2 +- src/ip_type.c | 5 ----- src/ip_type.h | 8 +++++--- src/libproxychains.c | 2 +- 7 files changed, 15 insertions(+), 18 deletions(-) delete mode 100644 src/ip_type.c diff --git a/Makefile b/Makefile index 2dd9e9c..31ba8db 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ SRCS = $(sort $(wildcard src/*.c)) OBJS = $(SRCS:.c=.o) LOBJS = src/nameinfo.o src/version.o \ src/core.o src/common.o src/libproxychains.o \ - src/allocator_thread.o src/ip_type.o \ + src/allocator_thread.o \ src/hostsreader.o src/hash.o src/debug.o GENH = src/version.h diff --git a/src/allocator_thread.c b/src/allocator_thread.c index ad0321f..66cf7f6 100644 --- a/src/allocator_thread.c +++ b/src/allocator_thread.c @@ -67,7 +67,7 @@ ip_type4 make_internal_ip(uint32_t index) { ip_type4 ret; index++; // so we can start at .0.0.1 if(index > 0xFFFFFF) - return ip_type_invalid.addr.v4; + return IPT4_INVALID; ret.octet[0] = remote_dns_subnet & 0xFF; ret.octet[1] = (index & 0xFF0000) >> 16; ret.octet[2] = (index & 0xFF00) >> 8; @@ -105,7 +105,7 @@ static ip_type4 ip_from_internal_list(char* name, size_t len) { } res = make_internal_ip(internal_ips->counter); - if(res.as_int == ip_type_invalid.addr.v4.as_int) + if(res.as_int == IPT4_INVALID.as_int) goto err_plus_unlock; string_hash_tuple tmp = { 0 }; @@ -134,7 +134,7 @@ static ip_type4 ip_from_internal_list(char* name, size_t len) { err_plus_unlock: PDEBUG("return err\n"); - return ip_type_invalid.addr.v4; + return IPT4_INVALID; } /* stuff for communication with the allocator thread */ @@ -276,7 +276,7 @@ ip_type4 at_get_ip_for_host(char* host, size_t len) { getmessage(ATD_CLIENT, &msg)) readbuf = msg.m.ip; else { inv: - readbuf = ip_type_invalid.addr.v4; + readbuf = IPT4_INVALID; } assert(msg.h.msgtype == ATM_GETIP); MUTEX_UNLOCK(internal_ips_lock); diff --git a/src/core.c b/src/core.c index 9dfba49..53e52d9 100644 --- a/src/core.c +++ b/src/core.c @@ -854,19 +854,19 @@ struct hostent *proxy_gethostbyname(const char *name, struct gethostbyname_data* if(!strcmp(buff, name)) { data->resolved_addr = inet_addr(buff); if(data->resolved_addr == (in_addr_t) (-1)) - data->resolved_addr = (in_addr_t) (ip_type_localhost.addr.v4.as_int); + data->resolved_addr = (in_addr_t) (IPT4_LOCALHOST.as_int); goto retname; } // this iterates over the "known hosts" db, usually /etc/hosts ip_type4 hdb_res = hostsreader_get_numeric_ip_for_name(name); - if(hdb_res.as_int != ip_type_invalid.addr.v4.as_int) { + if(hdb_res.as_int != IPT4_INVALID.as_int) { data->resolved_addr = hdb_res.as_int; goto retname; } data->resolved_addr = at_get_ip_for_host((char*) name, strlen(name)).as_int; - if(data->resolved_addr == (in_addr_t) ip_type_invalid.addr.v4.as_int) return NULL; + if(data->resolved_addr == (in_addr_t) IPT4_INVALID.as_int) return NULL; retname: diff --git a/src/hostsreader.c b/src/hostsreader.c index b2b0b07..86aeb3c 100644 --- a/src/hostsreader.c +++ b/src/hostsreader.c @@ -82,7 +82,7 @@ ip_type4 hostsreader_get_numeric_ip_for_name(const char* name) { ip_type4 res; memcpy(res.octet, &c.s_addr, 4); return res; - } else return ip_type_invalid.addr.v4; + } else return IPT4_INVALID; } #ifdef HOSTSREADER_TEST diff --git a/src/ip_type.c b/src/ip_type.c deleted file mode 100644 index cbe4815..000000000 --- a/src/ip_type.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "ip_type.h" - -const ip_type ip_type_invalid = { .addr.v4.as_int = -1 }; -const ip_type ip_type_localhost = { .addr.v4.octet = {127, 0, 0, 1} }; - diff --git a/src/ip_type.h b/src/ip_type.h index 064153e..c09400b 100644 --- a/src/ip_type.h +++ b/src/ip_type.h @@ -16,8 +16,10 @@ typedef struct { char is_v6; } ip_type; -extern const ip_type ip_type_invalid; -extern const ip_type ip_type_localhost; +#define IPT4_INT(X) (ip_type4){.as_int = (X)} +#define IPT4_INVALID IPT4_INT(-1) + +#define IPT4_BYTES(A,B,C,D) (ip_type4){.octet = {(A), (B), (C), (D)} } +#define IPT4_LOCALHOST IPT4_BYTES(127,0,0,1) -//RcB: DEP "ip_type.c" #endif diff --git a/src/libproxychains.c b/src/libproxychains.c index 8cdfbce..ca10cda 100644 --- a/src/libproxychains.c +++ b/src/libproxychains.c @@ -345,7 +345,7 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ ip_type4 internal_ip = at_get_ip_for_host(host, strlen(host)); pd[count].ip.is_v6 = 0; host_ip->addr.v4 = internal_ip; - if(internal_ip.as_int == ip_type_invalid.addr.v4.as_int) + if(internal_ip.as_int == IPT4_INVALID.as_int) goto inv_host; } else { inv_host: