From: michael Date: Fri, 26 Dec 2014 20:53:32 +0000 (+0000) Subject: - Continue to use inet_pton() until we add full ipv6 support, but at least X-Git-Tag: 1.0.0beta2~35 X-Git-Url: http://git.serene-ircd.net/?a=commitdiff_plain;h=89aa7282bc11fe38b9429c440fbca6ad6363366e;p=hopm.git - Continue to use inet_pton() until we add full ipv6 support, but at least replace all occurrences of inet_aton() with inet_pton() git-svn-id: svn://svn.ircd-hybrid.org/svnroot/hopm/branches/1.0.x@5171 82007160-df01-0410-b94d-b575c5fd34c7 --- diff --git a/src/compat.c b/src/compat.c index 3686f82..c2bc98c 100644 --- a/src/compat.c +++ b/src/compat.c @@ -27,42 +27,8 @@ along with this program; if not, write to the # include #endif -#ifndef HAVE_INET_ATON -# include -#endif - #include "compat.h" -#ifndef HAVE_INET_ATON -int bopm_inet_aton(const char *cp, struct in_addr *inp) -{ - unsigned int a1, a2, a3, a4; - unsigned long ret; - - if (strcmp(cp, "255.255.255.255") == 0) - { - inp->s_addr = (unsigned) -1; - return 0; - } - - if (sscanf(cp, "%u.%u.%u.%u", &a1, &a2, &a3, &a4) != 4 || - a1 > 255 || a2 > 255 || a3 > 255 || a4 > 255) - { - return 0; - } - - ret = (a1 << 24) | (a2 << 16) | (a3 << 8) | a4; - - inp->s_addr = htonl(ret); - - if (inp->s_addr == (unsigned) -1) - { - return 0; - } - return 1; -} -#endif - /* * strlcat and strlcpy were ripped from openssh 2.5.1p2 * They had the following Copyright info: diff --git a/src/compat.h b/src/compat.h index 799dabd..e45947e 100644 --- a/src/compat.h +++ b/src/compat.h @@ -1,16 +1,6 @@ #ifndef COMPAT_H #define COMPAT_H -#ifndef INADDR_NONE -#define INADDR_NONE 0xffffffff -#endif - -#ifndef HAVE_INET_ATON -#undef inet_aton -#define inet_aton bopm_inet_aton -extern int bopm_inet_aton(const char *cp, struct in_addr *inp); -#endif - #ifndef HAVE_STRLCPY extern size_t strlcpy(char *, const char *, size_t); #endif diff --git a/src/dnsbl.c b/src/dnsbl.c index b66e590..a4b0cd1 100644 --- a/src/dnsbl.c +++ b/src/dnsbl.c @@ -63,7 +63,7 @@ dnsbl_add(struct scan_struct *ss) struct dnsbl_scan *ds; - if (!inet_aton(ss->ip, &in)) + if (inet_pton(AF_INET, ss->ip, &in) <= 0) { log_printf("DNSBL -> Invalid address '%s', ignoring.", ss->ip); return; diff --git a/src/firedns.c b/src/firedns.c index 620516e..a239b94 100644 --- a/src/firedns.c +++ b/src/firedns.c @@ -26,7 +26,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include #include #include -#include #include #include #include @@ -205,7 +204,7 @@ void firedns_init(void) /* glibc /etc/resolv.conf seems to allow ipv6 server names */ if (i6 < FDNS_MAX) { - if (inet_pton6(&buf[i], (char *)&addr6) != NULL) + if (inet_pton(AF_INET6, &buf[i], &addr6) > 0) { memcpy(&servers6[i6++],&addr6,sizeof(struct in6_addr)); continue; @@ -214,18 +213,8 @@ void firedns_init(void) #endif if (i4 < FDNS_MAX) { - struct addrinfo hints, *res; - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; - - if (!getaddrinfo(&buf[i], NULL, &hints, &res)) - { - memcpy(&servers4[i4++], &((struct sockaddr_in *)res->ai_addr)->sin_addr, sizeof(struct in_addr)); - freeaddrinfo(res); - } + if (inet_pton(AF_INET, &buf[i], &addr4) > 0) + memcpy(&servers4[i4++],&addr4,sizeof(struct in_addr)); } } } @@ -239,7 +228,7 @@ void firedns_init(void) #ifdef IPV6 if (i6 < FDNS_MAX) { - if (inet_pton(AF_INET6, buf, (char *)&addr6)) + if (inet_pton(AF_INET6, buf, &addr6) > 0) { memcpy(&servers6[i6++], &addr6, sizeof(struct in6_addr)); continue; @@ -248,18 +237,8 @@ void firedns_init(void) #endif if (i4 < FDNS_MAX) { - struct addrinfo hints, *res; - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; - - if (!getaddrinfo(&buf[i], NULL, &hints, &res)) - { - memcpy(&servers4[i4++], &((struct sockaddr_in *)res->ai_addr)->sin_addr, sizeof(struct in_addr)); - freeaddrinfo(res); - } + if (inet_pton(AF_INET, buf, &addr4) > 0) + memcpy(&servers4[i4++],&addr4,sizeof(struct in_addr)); } } } @@ -280,7 +259,7 @@ struct in_addr *firedns_resolveip4(const char * const name) { /* immediate A query */ static struct in_addr addr; - if(inet_aton(name, &addr)) + if (inet_pton(AF_INET, name, &addr) > 0) return &addr; return (struct in_addr *) firedns_resolveip(FDNS_QRY_A, name); diff --git a/src/irc.c b/src/irc.c index f91b650..f3065d9 100644 --- a/src/irc.c +++ b/src/irc.c @@ -39,7 +39,6 @@ #include #include #include -#include #ifdef TIME_WITH_SYS_TIME # include @@ -259,23 +258,14 @@ irc_init(void) /* Bind */ if (!EmptyString(IRCItem->vhost)) { - struct addrinfo hints, *res; int bindret = 0; - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; - - if (getaddrinfo(IRCItem->vhost, NULL, &hints, &res)) + if (inet_pton(AF_INET, IRCItem->vhost, &(IRC_LOCAL.in4.s_addr)) <= 0) { log_printf("IRC -> bind(): %s is an invalid address", IRCItem->vhost); exit(EXIT_FAILURE); } - memcpy(&IRC_LOCAL.in4.s_addr, &((struct sockaddr_in *)res->ai_addr)->sin_addr, sizeof(struct in_addr)); - freeaddrinfo(res); - bsaddr.sa4.sin_addr.s_addr = IRC_LOCAL.in4.s_addr; bsaddr.sa4.sin_family = AF_INET; bsaddr.sa4.sin_port = htons(0); diff --git a/src/libopm/src/compat.c b/src/libopm/src/compat.c index 681bb15..a433369 100644 --- a/src/libopm/src/compat.c +++ b/src/libopm/src/compat.c @@ -27,41 +27,5 @@ # include #endif -#ifndef HAVE_INET_ATON -# include -#endif - #include "compat.h" #include "opm.h" - - -#ifndef HAVE_INET_ATON -/* - * An implementation of inet_aton for those systems that don't have it - * (Solaris, ...) - */ -int libopm_inet_aton(const char *cp, struct in_addr *inp) -{ - unsigned int a1, a2, a3, a4; - unsigned long ret; - - if (strcmp(cp, "255.255.255.255") == 0) { - inp->s_addr = (unsigned) -1; - return 0; - } - - if (sscanf(cp, "%u.%u.%u.%u", &a1, &a2, &a3, &a4) != 4 || - a1 > 255 || a2 > 255 || a3 > 255 || a4 > 255) { - return 0; - } - - ret = (a1 << 24) | (a2 << 16) | (a3 << 8) | a4; - - inp->s_addr = htonl(ret); - - if (inp->s_addr == (unsigned) -1) { - return 0; - } - return 1; -} -#endif diff --git a/src/libopm/src/compat.h b/src/libopm/src/compat.h index 95bd4b7..d7de8ad 100644 --- a/src/libopm/src/compat.h +++ b/src/libopm/src/compat.h @@ -1,13 +1,4 @@ #ifndef COMPAT_H #define COMPAT_H -#ifndef INADDR_NONE -#define INADDR_NONE 0xffffffff -#endif - -#ifndef HAVE_INET_ATON -#undef inet_aton -#define inet_aton libopm_inet_aton -extern int libopm_inet_aton(const char *cp, struct in_addr *inp); -#endif #endif diff --git a/src/libopm/src/config.c b/src/libopm/src/config.c index f68c3e8..12f3fa8 100644 --- a/src/libopm/src/config.c +++ b/src/libopm/src/config.c @@ -195,21 +195,10 @@ OPM_ERR_T libopm_config_set(OPM_CONFIG_T *config, int key, const void *value) break; case OPM_TYPE_ADDRESS: - { - struct addrinfo hints, *res; - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; - - if (getaddrinfo(value, NULL, &hints, &res)) + if (inet_pton(AF_INET, value, &(((opm_sockaddr *)config->vars[key])->sa4.sin_addr)) <= 0) return OPM_ERR_BADVALUE; /* return appropriate err code */ - memcpy(&(((opm_sockaddr *)config->vars[key])->sa4.sin_addr), &((struct sockaddr_in *)res->ai_addr)->sin_addr, sizeof(struct in_addr)); - freeaddrinfo(res); break; - } case OPM_TYPE_STRINGLIST: node = libopm_node_create(libopm_xstrdup(value)); diff --git a/src/libopm/src/proxy.c b/src/libopm/src/proxy.c index 2078915..0d34645 100644 --- a/src/libopm/src/proxy.c +++ b/src/libopm/src/proxy.c @@ -75,7 +75,7 @@ int libopm_proxy_socks4_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP); scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT); - if (inet_aton(scan_ip, &addr) == 0) + if (inet_pton(AF_INET, scan_ip, &addr) <= 0) ; /* handle error */ laddr = htonl(addr.s_addr); @@ -142,7 +142,7 @@ int libopm_proxy_socks5_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP); scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT); - if (inet_aton(scan_ip, &addr) == 0) + if (inet_pton(AF_INET, scan_ip, &addr) <= 0) ; /* handle error */ laddr = htonl(addr.s_addr); diff --git a/src/negcache.c b/src/negcache.c index 8335807..8ce19c1 100644 --- a/src/negcache.c +++ b/src/negcache.c @@ -45,7 +45,6 @@ along with this program; if not, write to: #ifdef STDC_HEADERS #include #endif -#include #ifdef TIME_WITH_SYS_TIME #include @@ -58,10 +57,6 @@ along with this program; if not, write to: # endif #endif -#include -#include -#include - #include "inet.h" #include "irc.h" #include "negcache.h" @@ -215,22 +210,13 @@ void negcache_insert(const char *ipstr) { struct bopm_sockaddr ip; struct cnode *n; - struct addrinfo hints, *res; - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; - if (getaddrinfo(ipstr, NULL, &hints, &res)) + if (!inet_pton(AF_INET, ipstr, &(ip.sa4.sin_addr))) { log_printf("NEGCACHE -> Invalid IPv4 address '%s'", ipstr); return; } - memcpy(&ip.sa4.sin_addr, &((struct sockaddr_in *)res->ai_addr)->sin_addr, sizeof(struct in_addr)); - freeaddrinfo(res); - n = nc_insert(nc_head, ip.sa4.sin_addr.s_addr); if (n) diff --git a/src/scan.c b/src/scan.c index 701c005..dc8c534 100644 --- a/src/scan.c +++ b/src/scan.c @@ -46,10 +46,6 @@ #include #include -#include -#include -#include - #ifdef HAVE_SYS_POLL_H # include #endif @@ -345,23 +341,13 @@ scan_connect(char **user, char *msg) /* Check negcache before anything */ if (OptionsItem->negcache > 0) { - struct addrinfo hints, *res; - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; - - if (getaddrinfo(user[3], NULL, &hints, &res)) + if (inet_pton(AF_INET, user[3], &(ip.sa4.sin_addr)) <= 0) { log_printf("SCAN -> Invalid IPv4 address '%s'!", user[3]); return; } else { - memcpy(&ip.sa4.sin_addr, &((struct sockaddr_in *)res->ai_addr)->sin_addr, sizeof(struct in_addr)); - freeaddrinfo(res); - if (check_neg_cache(ip.sa4.sin_addr.s_addr)) { if (OPT_DEBUG)