summaryrefslogtreecommitdiff
path: root/www/analog/patches/patch-ac
blob: 2b7d8ff259d2d1f3daa29ad1ccf17f9ac9a40101 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
$NetBSD: patch-ac,v 1.6 2007/10/19 03:51:51 taca 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) {
+	  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);