summaryrefslogtreecommitdiff
path: root/news/knews/patches/patch-ag
blob: 0e7aefcfbbb917ca4325e2ebf37409c40083bbd3 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
$NetBSD: patch-ag,v 1.3 2001/02/23 22:19:42 tron Exp $

--- src/sysdeps.c.orig	Tue Dec 29 11:46:52 1998
+++ src/sysdeps.c	Fri Feb 23 23:11:36 2001
@@ -20,8 +20,8 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
-#include "server.h"
 #include "sysdeps.h"
+#include "server.h"
 
 #undef  PURIFY_HACK
 /*#define PURIFY_HACK*/
@@ -96,6 +96,9 @@
 #ifdef EINPROGRESS
 	    err_no == EINPROGRESS ||
 #endif
+#ifdef EALREADY
+	    err_no == EALREADY ||
+#endif
 	    err_no == EAGAIN);
 }
 
@@ -256,10 +259,12 @@
 
 /***********************************************************************/
 
+#if !defined(USE_INET6)
 struct SERV_ADDR {
     struct in_addr	addr;
     unsigned short	port;
 };
+#endif
 
 /*
  * host:	either "hostname:port" or "ip.ip.ip.ip:port",
@@ -271,6 +276,28 @@
  */
 SERV_ADDR *get_host(char *host, unsigned short def_port, int byte_swap)
 {
+#if defined(USE_INET6)
+    char		*c, *port, buffer[6];
+    struct addrinfo	hints, *res;
+
+    port = 0;
+    c = strchr(host, ':');
+    if (c) {
+	*c = '\0';
+	if (c[1] >= '0' && c[1] <= '9')
+	    port = c + 1;
+    }
+    if (!port) {
+	sprintf(buffer, "%d", def_port);
+	port = buffer;
+    }
+
+    memset(&hints, '\0', sizeof(hints));
+    hints.ai_family = AF_UNSPEC;
+    hints.ai_socktype = SOCK_STREAM;
+    hints.ai_protocol = 0;
+    return getaddrinfo(host, port, &hints, &res) ? NULL : res;
+#else
     SERV_ADDR		*ret;
     struct in_addr	addr;
     unsigned short	port;
@@ -332,14 +359,15 @@
     ret->port = port;
 
     return ret;
+#endif
 }
 
-int open_socket(void)
+int open_socket(int family)
 {
     int	fd, tmp;
 
     do {
-	fd = socket(PF_INET, SOCK_STREAM, 0);
+	fd = socket(family, SOCK_STREAM, 0);
     } while (fd < 0 && errno == EINTR);
 
     if (fd < 0) {
@@ -372,6 +400,35 @@
 
 int connect_socket(int fd, SERV_ADDR *addr)
 {
+#ifdef USE_INET6
+    int	family;
+
+    family = AF_INET;
+    while (addr) {
+	if (family != addr->ai_family) {
+	    int	newsocket;
+
+	    newsocket = open_socket(addr->ai_family);
+	    if (newsocket < 0)
+		return -1;
+	    if (dup2(newsocket, fd) < 0)
+		close(newsocket);
+
+	    close(newsocket);
+	    family = addr->ai_family;
+	}
+
+	do {
+	    if ((connect(fd, addr->ai_addr, addr->ai_addrlen) == 0) ||
+		(errno == EISCONN))
+		return 0;
+	} while (would_block(fd, errno));
+
+	addr = addr->ai_next;
+    }
+
+    return -1;
+#else
     struct sockaddr_in	serv_addr;
     int			tmp;
 
@@ -390,6 +447,7 @@
     } while (tmp < 0 && errno == EINTR);
 
     return tmp;
+#endif
 }
 
 #if 0 /* Misc stuff for ftp routines */
@@ -548,7 +606,7 @@
 char *get_mailhostname(void)
 {
     struct utsname	  un = {{0,},};
-    char		 *host = NULL, *domain;
+    char		 *host = NULL;
 
 #ifdef PURIFY_HACK
     return NULL;