get rid of ip_type.c

pull/348/head
rofl0r 2020-09-23 17:00:16 +01:00
parent 1221c5e93a
commit 1e00b9ac1e
7 changed files with 15 additions and 18 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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