pkgsrc/www/analog/patches/patch-ac
2009-06-14 08:33:21 +00:00

82 lines
2.2 KiB
Text

$NetBSD: patch-ac,v 1.7 2009/06/14 08:33:21 wiz Exp $
--- alias.c.orig Sun Dec 19 22:51:30 2004
+++ alias.c
@@ -13,6 +13,10 @@
#include "anlghea3.h"
+#if defined(NI_MAXHOST) && defined(AI_NUMERICHOST) && defined(NI_NAMEREQD)
+#define IPV6 1
+#endif
+
/* Throughout this file, to avoid a buffer overflow, we must be careful when we
do any operation which can increase the length of the name. Such operations
are thankfully rare, except for user aliases in wildalias().
@@ -213,7 +217,12 @@ logical do_aliasS(char *name) {
/* DNS lookup */
#ifndef NODNS
+#ifdef IPV6
+ if (dnslevel != DNS_NONE &&
+ (ISDIGIT(name[len]) || strchr(name, ':') != NULL)) {
+#else
if (dnslevel != DNS_NONE && ISDIGIT(name[len])) {
+#endif
do_dns(name, NULL, dnslevel);
len = (int)strlen(name) - 1;
}
@@ -586,6 +595,10 @@ logical dnsresolve(char *name, choice le
volatile logical done = FALSE;
#ifndef MAC
IN_ADDR_T addr;
+#ifdef IPV6
+ struct addrinfo hints, *res;
+ char host[NI_MAXHOST];
+#endif
#ifdef VMS
char *addrp;
#else
@@ -605,6 +618,34 @@ logical dnsresolve(char *name, choice le
done = IpAddr2Name(name);
/* Doesn't currently include code to use SIGALRM */
#else
+#ifdef IPV6
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_flags = AI_NUMERICHOST;
+ res = NULL;
+#ifndef NOALARM
+ if (SETJMP(jumpbuf))
+ signal(SIGALRM, SIG_DFL);
+ /* reset to default handling in case SIGALRM is raised exogenously */
+ else {
+ signal(SIGALRM, sighandler);
+ alarm(dnstimeout);
+#endif
+ if (getaddrinfo(name, NULL, &hints, &res) == 0 && res != NULL) {
+ if (res->ai_addr != NULL && res->ai_addrlen > 0 &&
+ getnameinfo(res->ai_addr, res->ai_addrlen, host, sizeof(host),
+ NULL, 0, NI_NAMEREQD) == 0 && host[0] != '\0') {
+ strncpy(name, host, BLOCKSIZE - 1);
+ name[BLOCKSIZE - 1] = '\0';
+ done = TRUE;
+ }
+ freeaddrinfo(res);
+ }
+#ifndef NOALARM
+ alarm(0);
+ signal(SIGALRM, SIG_DFL);
+ }
+#endif
+#else
addr = inet_addr(name);
if (addr != INET_ADDR_ERR) {
addrp = (char *) &addr;
@@ -631,6 +672,7 @@ logical dnsresolve(char *name, choice le
}
#endif
}
+#endif /* not IPV6 */
#endif /* not MAC */
if (done)
debug('D', " resolved to %s", name);