summaryrefslogtreecommitdiff
path: root/news/knews/patches/patch-ag
blob: cc198d555b232f3f829df4f39281ccfe77ab190f (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
138
139
140
141
$NetBSD: patch-ag,v 1.5 2001/03/10 22:05:54 tron Exp $

--- src/sysdeps.c.orig	Tue Dec 29 11:46:52 1998
+++ src/sysdeps.c	Sat Feb 24 23:31:43 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 = strrchr(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,38 @@
     ret->port = port;
 
     return ret;
+#endif
 }
 
-int open_socket(void)
+SERV_ADDR *next_addr(SERV_ADDR *addr)
+
+{
+#ifdef USE_INET6
+    return addr->ai_next;
+#else
+    return NULL;
+#endif
+}
+void free_addr(SERV_ADDR *addr)
+
+{
+#ifdef USE_INET6
+    freeaddrinfo(addr);
+#else
+    XtFree((char *)addr);
+#endif
+}
+
+int open_socket(SERV_ADDR *addr)
 {
     int	fd, tmp;
 
     do {
-	fd = socket(PF_INET, SOCK_STREAM, 0);
+#ifdef USE_INET6
+	fd = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
+#else
+	fd = socket(AF_INET, SOCK_STREAM, 0);
+#endif
     } while (fd < 0 && errno == EINTR);
 
     if (fd < 0) {
@@ -372,8 +423,15 @@
 
 int connect_socket(int fd, SERV_ADDR *addr)
 {
-    struct sockaddr_in	serv_addr;
     int			tmp;
+#ifdef USE_INET6
+    do {
+	tmp = connect(fd, addr->ai_addr, addr->ai_addrlen);
+    } while (tmp < 0 && errno == EINTR);
+
+    return tmp;
+#else
+    struct sockaddr_in	serv_addr;
 
     if (!addr) {
 	fputs("knews: connect_socket: addr is NULL!!!\n", stderr);
@@ -390,6 +448,7 @@
     } while (tmp < 0 && errno == EINTR);
 
     return tmp;
+#endif
 }
 
 #if 0 /* Misc stuff for ftp routines */
@@ -548,7 +607,7 @@
 char *get_mailhostname(void)
 {
     struct utsname	  un = {{0,},};
-    char		 *host = NULL, *domain;
+    char		 *host = NULL;
 
 #ifdef PURIFY_HACK
     return NULL;