Commit: 38aa1cffa67bffc0dfa1353e54c673956147e204
Parent: 8dc35a9249df2fb0be0b566d2e1fe6efdd5c389c
Author: Randy Palamar
Date: Thu, 26 Aug 2021 17:23:12 -0600
cleanup some casting spaghetti in dns.c and connect.c
Diffstat:
3 files changed, 22 insertions(+), 23 deletions(-)
diff --git a/connect.c b/connect.c
@@ -99,17 +99,16 @@ void make_connection(struct connection *c, int port, int *sock, void (*func)(str
{
int socks_port = -1;
int as;
- unsigned char *host;
- char *p;
+ char *p, *host;
size_t sl;
struct conn_info *b;
if (*c->socks_proxy) {
p = strchr(c->socks_proxy, '@');
if (p) p++;
else p = c->socks_proxy;
- host = (unsigned char *)strdup(p);
+ host = strdup(p);
socks_port = 1080;
- if ((p = strchr(cast_const_char host, ':'))) {
+ if ((p = strchr(host, ':'))) {
long lp;
*p++ = 0;
if (!*p) goto badu;
@@ -123,21 +122,21 @@ void make_connection(struct connection *c, int port, int *sock, void (*func)(str
}
socks_port = (int)lp;
}
- } else if (!(host = get_host_name(c->url))) {
+ } else if (!(host = (char *)get_host_name(c->url))) {
setcstate(c, S_INTERNAL);
abort_connection(c);
return;
}
if (c->newconn)
internal("already making a connection");
- sl = strlen(cast_const_char host);
+ sl = strlen(host);
if (sl > INT_MAX - sizeof(struct conn_info)) overalloc();
b = mem_calloc(sizeof(struct conn_info) + sl);
b->func = func;
b->sock = sock;
b->l.socks_port = socks_port;
b->l.target_port = port;
- strcpy(b->host, cast_const_char host);
+ strcpy(b->host, host);
c->newconn = b;
if (c->last_lookup_state.addr_index < c->last_lookup_state.addr.n) {
b->l.addr = c->last_lookup_state.addr;
@@ -481,7 +480,7 @@ void retry_connect(struct connection *c, int err, int ssl_downgrade)
} else
#endif
{
- dns_clear_host((unsigned char *)b->host);
+ dns_clear_host(b->host);
setcstate(c, b->first_error);
retry_connection(c);
}
@@ -667,8 +666,8 @@ static void update_dns_priority(struct connection *c)
if (b->l.addr_index) {
int i;
for (i = 0; i < b->l.addr_index; i++)
- dns_set_priority((unsigned char *)b->host, &b->l.addr.a[i], 0);
- dns_set_priority((unsigned char *)b->host, &b->l.addr.a[i], 1);
+ dns_set_priority(b->host, &b->l.addr.a[i], 0);
+ dns_set_priority(b->host, &b->l.addr.a[i], 1);
}
b->l.dont_try_more_servers = 1;
}
diff --git a/dns.c b/dns.c
@@ -279,13 +279,13 @@ static void check_dns_cache_addr_preference(void)
}
}
-static int find_in_dns_cache(unsigned char *name, struct dnsentry **dnsentry)
+static int find_in_dns_cache(char *name, struct dnsentry **dnsentry)
{
struct dnsentry *e = NULL;
struct list_head *le;
check_dns_cache_addr_preference();
foreach(struct dnsentry, e, le, dns_cache)
- if (!casestrcmp((unsigned char *)e->name, name)) {
+ if (!strcasecmp(e->name, name)) {
del_from_list(e);
add_to_list(dns_cache, e);
*dnsentry = e;
@@ -309,7 +309,7 @@ static void end_dns_lookup(struct dnsquery *q, int a)
free(q);
return;
}
- if (!find_in_dns_cache((unsigned char *)q->name, &dnsentry)) {
+ if (!find_in_dns_cache(q->name, &dnsentry)) {
if (a) {
memcpy(q->addr, &dnsentry->addr, sizeof(struct lookup_result));
a = 0;
@@ -336,22 +336,22 @@ e:
fn(data, a);
}
-int find_host_no_cache(unsigned char *name, struct lookup_result *addr, void **qp, void (*fn)(void *, int), void *data)
+int find_host_no_cache(char *name, struct lookup_result *addr, void **qp, void (*fn)(void *, int), void *data)
{
struct dnsquery *q;
- q = xmalloc(sizeof(struct dnsquery) + strlen(cast_const_char name));
+ q = xmalloc(sizeof(struct dnsquery) + strlen(name));
q->fn = fn;
q->data = data;
q->s = (struct dnsquery **)qp;
q->addr = addr;
q->addr_preference = ipv6_options.addr_preference;
- strcpy(q->name, (char *)name);
+ strcpy(q->name, name);
if (qp)
*qp = q;
return do_lookup(q);
}
-int find_host(unsigned char *name, struct lookup_result *addr, void **qp, void (*fn)(void *, int), void *data)
+int find_host(char *name, struct lookup_result *addr, void **qp, void (*fn)(void *, int), void *data)
{
struct dnsentry *dnsentry;
if (qp)
@@ -375,7 +375,7 @@ void kill_dns_request(void **qp)
}
#if MAX_ADDRESSES > 1
-void dns_set_priority(unsigned char *name, struct host_address *address, int prefer)
+void dns_set_priority(char *name, struct host_address *address, int prefer)
{
int i;
struct dnsentry *dnsentry;
@@ -398,7 +398,7 @@ found_it:
}
#endif
-void dns_clear_host(unsigned char *name)
+void dns_clear_host(char *name)
{
struct dnsentry *dnsentry;
if (find_in_dns_cache(name, &dnsentry))
diff --git a/links.h b/links.h
@@ -420,13 +420,13 @@ struct lookup_state {
int numeric_ip_address(const char *name, char address[4]);
int numeric_ipv6_address(const char *name, char address[16], unsigned *scope_id);
void rotate_addresses(struct lookup_result *);
-int find_host(unsigned char *, struct lookup_result *, void **, void (*)(void *, int), void *);
-int find_host_no_cache(unsigned char *, struct lookup_result *, void **, void (*)(void *, int), void *);
+int find_host(char *, struct lookup_result *, void **, void (*)(void *, int), void *);
+int find_host_no_cache(char *, struct lookup_result *, void **, void (*)(void *, int), void *);
void kill_dns_request(void **);
#if MAX_ADDRESSES > 1
-void dns_set_priority(unsigned char *, struct host_address *, int);
+void dns_set_priority(char *, struct host_address *, int);
#endif
-void dns_clear_host(unsigned char *);
+void dns_clear_host(char *);
unsigned long dns_info(int type);
unsigned char *print_address(struct host_address *);
int ipv6_full_access(void);