Commit: ae768603f30db58e3380f64f351cf96aa9cfbb5d
Parent: a7afa5beca1584254655462eaff18b22701f8b6c
Author: opask
Date: Thu, 30 Aug 2018 16:48:37 -0600
dns.c: cleanup types in numeric_ip*_address() and get_addr_byte()
Diffstat:
6 files changed, 43 insertions(+), 44 deletions(-)
diff --git a/bfu.c b/bfu.c
@@ -1586,9 +1586,9 @@ static int check_local_ip_address_internal(struct dialog_data *dlg, struct dialo
return 0;
}
if (pf == PF_INET6)
- rs = numeric_ipv6_address(p, NULL, NULL);
+ rs = numeric_ipv6_address((char *)p, NULL, NULL);
else
- rs = numeric_ip_address(p, NULL);
+ rs = numeric_ip_address((char *)p, NULL);
if (rs) {
msg_box(dlg->win->term, NULL, TEXT_(T_BAD_IP_ADDRESS), AL_CENTER, TEXT_(T_INVALID_IP_ADDRESS_SYNTAX), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
return 1;
diff --git a/connect.c b/connect.c
@@ -36,7 +36,7 @@ int socket_and_bind(int pf, unsigned char *address)
case PF_INET: {
struct sockaddr_in sa;
unsigned char addr[4];
- if (numeric_ip_address(address, addr) == -1) {
+ if (numeric_ip_address((char *)address, (char *)addr) == -1) {
EINTRLOOP(rs, close(s));
errno = EINVAL;
return -1;
@@ -58,7 +58,7 @@ int socket_and_bind(int pf, unsigned char *address)
struct sockaddr_in6 sa;
unsigned char addr[16];
unsigned scope;
- if (numeric_ipv6_address(address, addr, &scope) == -1) {
+ if (numeric_ipv6_address((char *)address, (char *)addr, &scope) == -1) {
EINTRLOOP(rs, close(s));
errno = EINVAL;
return -1;
@@ -654,8 +654,8 @@ static void connected(void *c_)
SSL_set_fd(c->ssl->ssl, *b->sock);
ssl_setup_downgrade(c);
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
- if (h[0] == '[' || !numeric_ip_address(h, NULL)
- || !numeric_ipv6_address(h, NULL, NULL)
+ if (h[0] == '[' || !numeric_ip_address((char *)h, NULL)
+ || !numeric_ipv6_address((char *)h, NULL, NULL)
) goto skip_numeric_address;
SSL_set_tlsext_host_name(c->ssl->ssl, h);
skip_numeric_address:
diff --git a/dns.c b/dns.c
@@ -31,38 +31,37 @@ static struct list_head dns_cache = {&dns_cache, &dns_cache};
static void end_dns_lookup(struct dnsquery *q, int a);
static int shrink_dns_cache(int u);
-static int get_addr_byte(unsigned char **ptr, unsigned char *res, unsigned char stp)
+static int get_addr_byte(const char *p, char *res, const char stp)
{
- unsigned u = 0;
- if (!(**ptr >= '0' && **ptr <= '9')) return -1;
- while (**ptr >= '0' && **ptr <= '9') {
- u = u * 10 + **ptr - '0';
- if (u >= 256) return -1;
- (*ptr)++;
+ char u = 0;
+ if (!(*p >= '0' && *p <= '9'))
+ return -1;
+ while (*p >= '0' && *p <= '9') {
+ u = u * 10 + *p - '0';
+ if (u >= 256)
+ return -1;
+ p++;
}
- if (stp != 255 && **ptr != stp) return -1;
- (*ptr)++;
- *res = (unsigned char)u;
+ if (stp != 255 && *p != stp) return -1;
+ p++;
+ *res = u;
return 0;
}
-int numeric_ip_address(unsigned char *name, unsigned char address[4])
+int numeric_ip_address(const char *name, char address[4])
{
- unsigned char dummy[4];
+ char dummy[4];
if (!address)
address = dummy;
- if (get_addr_byte(&name, address + 0, '.'))
- return -1;
- if (get_addr_byte(&name, address + 1, '.'))
- return -1;
- if (get_addr_byte(&name, address + 2, '.'))
- return -1;
- if (get_addr_byte(&name, address + 3, 0))
+ if (get_addr_byte(name, address + 0, '.')
+ || get_addr_byte(name, address + 1, '.')
+ || get_addr_byte(name, address + 2, '.')
+ || get_addr_byte(name, address + 3, 0))
return -1;
return 0;
}
-static int extract_ipv6_address(struct addrinfo *p, unsigned char address[16], unsigned *scope_id)
+static int extract_ipv6_address(struct addrinfo *p, char address[16], unsigned *scope_id)
{
if (p->ai_family == AF_INET6
&& (socklen_t)p->ai_addrlen >= (socklen_t)sizeof(struct sockaddr_in6)
@@ -74,9 +73,9 @@ static int extract_ipv6_address(struct addrinfo *p, unsigned char address[16], u
return -1;
}
-int numeric_ipv6_address(unsigned char *name, unsigned char address[16], unsigned *scope_id)
+int numeric_ipv6_address(const char *name, char address[16], unsigned *scope_id)
{
- unsigned char dummy_a[16];
+ char dummy_a[16];
unsigned dummy_s;
int r;
struct in6_addr i6a;
@@ -86,7 +85,7 @@ int numeric_ipv6_address(unsigned char *name, unsigned char address[16], unsigne
if (!scope_id)
scope_id = &dummy_s;
- if (inet_pton(AF_INET6, cast_const_char name, &i6a) == 1) {
+ if (inet_pton(AF_INET6, name, &i6a) == 1) {
memcpy(address, &i6a, 16);
*scope_id = 0;
return 0;
@@ -97,7 +96,7 @@ int numeric_ipv6_address(unsigned char *name, unsigned char address[16], unsigne
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET6;
hints.ai_flags = AI_NUMERICHOST;
- if (getaddrinfo(cast_const_char name, NULL, &hints, &res))
+ if (getaddrinfo(name, NULL, &hints, &res))
return -1;
r = extract_ipv6_address(res, address, scope_id);
freeaddrinfo(res);
@@ -168,7 +167,7 @@ static int use_getaddrinfo(unsigned char *name, struct addrinfo *hints, int pref
{
unsigned char address[16];
unsigned scope_id;
- if (!extract_ipv6_address(p, address, &scope_id)) {
+ if (!extract_ipv6_address(p, (char *)address, &scope_id)) {
add_address(host, AF_INET6, address, scope_id,
preference);
continue;
@@ -222,7 +221,7 @@ void do_real_lookup(unsigned char *name, int preference, struct lookup_result *h
if (!support_ipv6)
preference = ADDR_PREFERENCE_IPV4_ONLY;
- if (!numeric_ip_address(name, address)) {
+ if (!numeric_ip_address((char *)name, (char *)address)) {
add_address(host, AF_INET, address, 0, preference);
goto ret;
}
@@ -232,7 +231,7 @@ void do_real_lookup(unsigned char *name, int preference, struct lookup_result *h
if (n2) {
unsigned scope_id;
n2[nl - 2] = 0;
- if (!numeric_ipv6_address(n2, address, &scope_id)) {
+ if (!numeric_ipv6_address((char *)n2, (char *)address, &scope_id)) {
free(n2);
add_address(host, AF_INET6, address, scope_id, preference);
goto ret;
@@ -241,7 +240,7 @@ void do_real_lookup(unsigned char *name, int preference, struct lookup_result *h
}
} else {
unsigned scope_id;
- if (!numeric_ipv6_address(name, address, &scope_id)) {
+ if (!numeric_ipv6_address((char *)name, (char *)address, &scope_id)) {
add_address(host, AF_INET6, address, scope_id, preference);
goto ret;
}
diff --git a/https.c b/https.c
@@ -101,13 +101,13 @@ void https_func(struct connection *c)
static int verify_ssl_host_name(X509 *server_cert, char *host)
{
int v;
- unsigned char ipv4_address[4];
- unsigned char ipv6_address[16];
+ char ipv4_address[4];
+ char ipv6_address[16];
- if (!numeric_ip_address((unsigned char *)host, ipv4_address))
- v = X509_check_ip(server_cert, ipv4_address, 4, 0);
- else if (!numeric_ipv6_address((unsigned char *)host, ipv6_address, NULL))
- v = X509_check_ip(server_cert, ipv6_address, 16, 0);
+ if (!numeric_ip_address(host, ipv4_address))
+ v = X509_check_ip(server_cert, (unsigned char *)ipv4_address, 4, 0);
+ else if (!numeric_ipv6_address(host, ipv6_address, NULL))
+ v = X509_check_ip(server_cert, (unsigned char *)ipv6_address, 16, 0);
else
v = X509_check_host(server_cert, host, strlen(host), 0, NULL);
diff --git a/links.h b/links.h
@@ -490,8 +490,8 @@ struct lookup_state {
extern int support_ipv6;
-int numeric_ip_address(unsigned char *name, unsigned char address[4]);
-int numeric_ipv6_address(unsigned char *name, unsigned char address[16], unsigned *scope_id);
+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 *);
void do_real_lookup(unsigned char *, int, struct lookup_result *);
int find_host(unsigned char *, struct lookup_result *, void **, void (*)(void *, int), void *);
diff --git a/suffix.c b/suffix.c
@@ -60,9 +60,9 @@ int allow_cookie_domain(unsigned char *server, unsigned char *domain)
return 0;
if (dl == sl)
return 1;
- if (!numeric_ip_address(server, NULL))
+ if (!numeric_ip_address((char *)server, NULL))
return 0;
- if (!numeric_ipv6_address(server, NULL, NULL))
+ if (!numeric_ipv6_address((char *)server, NULL, NULL))
return 0;
if (server[sl - dl - 1] != '.')
return 0;