summaryrefslogtreecommitdiffhomepage
path: root/libs/sgi-webuci/boa-patches/220-ipv6-vs-ipv4.patch
blob: 5d0eb6a037acdbf9705b658d5c8d69b9e79fefa2 (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
diff -urN boa-0.94.13.orig/src/boa.c boa-0.94.13/src/boa.c
--- boa-0.94.13.orig/src/boa.c	2008-10-28 16:15:45.000000000 +0100
+++ boa-0.94.13/src/boa.c	2008-10-28 15:56:27.000000000 +0100
@@ -27,6 +27,12 @@
 #include <sys/resource.h>
 
 /* globals */
+
+#ifdef INET6
+int server_addr_family;
+socklen_t server_addr_len;
+#endif
+
 int backlog = SO_MAXCONN;
 time_t start_time;
 
@@ -164,14 +170,36 @@
     return 0;
 }
 
+#ifdef INET6
+sa_family_t *get_addr_family(struct sockaddr *address)
+{
+    if(server_addr_family == AF_INET6) {
+        return &(((struct sockaddr_in6 *) address)->sin6_family);
+    }
+
+    return &(((struct sockaddr_in *) address)->sin_family);
+}
+#endif
+
 static int create_server_socket(void)
 {
     int server_s;
 
-    server_s = socket(SERVER_AF, SOCK_STREAM, IPPROTO_TCP);
+#ifdef INET6
+    server_addr_family = AF_INET6;
+    server_addr_len = sizeof(struct sockaddr_in6);
+    server_s = socket(server_addr_family, SOCK_STREAM, IPPROTO_TCP);
     if (server_s == -1) {
-        DIE("unable to create socket");
+        server_addr_family = AF_INET;
+        server_addr_len = sizeof(struct sockaddr_in);
+#endif
+        server_s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+        if (server_s == -1) {
+            DIE("unable to create socket");
+        }
+#ifdef INET6
     }
+#endif
 
     /* server socket is nonblocking */
     if (set_nonblock_fd(server_s) == -1) {
diff -urN boa-0.94.13.orig/src/boa.h boa-0.94.13/src/boa.h
--- boa-0.94.13.orig/src/boa.h	2008-10-28 16:15:58.000000000 +0100
+++ boa-0.94.13/src/boa.h	2008-10-28 14:45:52.000000000 +0100
@@ -199,4 +199,12 @@
 int plugin_handle(request * req);
 struct httpd_plugin *plugin_lookup(request *req);
 
+/* IPv6 */
+
+#ifdef INET6
+extern int server_addr_family;
+extern socklen_t server_addr_len;
+sa_family_t *get_addr_family(struct sockaddr *address);
+#endif
+
 #endif
diff -urN boa-0.94.13.orig/src/compat.h boa-0.94.13/src/compat.h
--- boa-0.94.13.orig/src/compat.h	2002-06-06 07:02:28.000000000 +0200
+++ boa-0.94.13/src/compat.h	2008-10-28 15:31:16.000000000 +0100
@@ -71,11 +71,13 @@
 
 #ifdef INET6
 #define SOCKADDR sockaddr_storage
-#define S_FAMILY __s_family
-#define SERVER_AF AF_INET6
+#define SOCKADDR_LEN server_addr_len
+#define S_FAMILY(address) (*get_addr_family((struct sockaddr *) (address)))
+#define SERVER_AF server_addr_family
 #else
 #define SOCKADDR sockaddr_in
-#define S_FAMILY sin_family
+#define SOCKADDR_LEN sizeof(struct sockaddr_in)
+#define S_FAMILY(address) ((*address).sin_family)
 #define SERVER_AF AF_INET
 #endif
 
diff -urN boa-0.94.13.orig/src/ip.c boa-0.94.13/src/ip.c
--- boa-0.94.13.orig/src/ip.c	2002-01-21 03:19:16.000000000 +0100
+++ boa-0.94.13/src/ip.c	2008-10-28 15:52:05.000000000 +0100
@@ -44,52 +44,64 @@
 
 #include "boa.h"
 #include <arpa/inet.h>          /* inet_ntoa */
+#include <netinet/in.h>
 
 /* Binds to the existing server_s, based on the configuration string
    in server_ip.  IPv6 version doesn't pay attention to server_ip yet.  */
 int bind_server(int server_s, char *server_ip)
 {
+	struct sockaddr *server_sockaddr;
+    struct sockaddr_in server_sockaddr4;
+
 #ifdef INET6
-    struct sockaddr_in6 server_sockaddr;
-    server_sockaddr.sin6_family = AF_INET6;
-    memcpy(&server_sockaddr.sin6_addr, &in6addr_any, sizeof (in6addr_any));
-    server_sockaddr.sin6_port = htons(server_port);
-#else
-    struct sockaddr_in server_sockaddr;
-    memset(&server_sockaddr, 0, sizeof server_sockaddr);
+    struct sockaddr_in6 server_sockaddr6;
+    if(SERVER_AF == AF_INET6) {
+        server_sockaddr6.sin6_family = AF_INET6;
+        memcpy(&server_sockaddr6.sin6_addr, &in6addr_any, sizeof (in6addr_any));
+        server_sockaddr6.sin6_port = htons(server_port);
+        server_sockaddr = (struct sockaddr *) &server_sockaddr6;
+    } else {
+#endif
+        memset(&server_sockaddr4, 0, SOCKADDR_LEN);
 #ifdef HAVE_SIN_LEN             /* uncomment for BSDs */
-    server_sockaddr.sin_len = sizeof server_sockaddr;
+        server_sockaddr4.sin_len = SOCKADDR_LEN;
 #endif
-    server_sockaddr.sin_family = AF_INET;
-    if (server_ip != NULL) {
-        inet_aton(server_ip, &server_sockaddr.sin_addr);
-    } else {
-        server_sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);
+        server_sockaddr4.sin_family = AF_INET;
+        if (server_ip != NULL) {
+            inet_aton(server_ip, &server_sockaddr4.sin_addr);
+        } else {
+            server_sockaddr4.sin_addr.s_addr = htonl(INADDR_ANY);
+        }
+        server_sockaddr4.sin_port = htons(server_port);
+        server_sockaddr = (struct sockaddr *) &server_sockaddr4;
+#ifdef INET6
     }
-    server_sockaddr.sin_port = htons(server_port);
 #endif
 
-    return bind(server_s, (struct sockaddr *) &server_sockaddr,
-                sizeof (server_sockaddr));
+    return bind(server_s, server_sockaddr, SOCKADDR_LEN);
 }
 
 char *ascii_sockaddr(struct SOCKADDR *s, char *dest, int len)
 {
 #ifdef INET6
-    if (getnameinfo((struct sockaddr *) s,
-                    sizeof(struct SOCKADDR),
-                    dest, len, NULL, 0, NI_NUMERICHOST)) {
-        fprintf(stderr, "[IPv6] getnameinfo failed\n");
-        *dest = '\0';
-    }
+    if(SERVER_AF == AF_INET6) {
+        if (getnameinfo((struct sockaddr *) s,
+                        SOCKADDR_LEN,
+                        dest, len, NULL, 0, NI_NUMERICHOST)) {
+            fprintf(stderr, "[IPv6] getnameinfo failed\n");
+            *dest = '\0';
+        }
 #ifdef WHEN_DOES_THIS_APPLY
-    if ((s->__ss_family == AF_INET6) &&
-        IN6_IS_ADDR_V4MAPPED(&(((struct sockaddr_in6 *) s)->sin6_addr))) {
-        memmove(dest, dest+7, NI_MAXHOST);
-    }
+        if (((((struct sockaddr_in6 *) s)->sin6_family) == AF_INET6) &&
+            IN6_IS_ADDR_V4MAPPED(&(((struct sockaddr_in6 *) s)->sin6_addr))) {
+            memmove(dest, dest+7, NI_MAXHOST);
+        }
 #endif
-#else
-    memmove(dest, inet_ntoa(s->sin_addr), len);
+    } else {
+#endif
+        memmove(dest, inet_ntoa(((struct sockaddr_in *) s)->sin_addr), len);
+#ifdef INET6
+    }
 #endif
     return dest;
 }
@@ -98,17 +110,21 @@
 {
     int p = -1;
 #ifdef INET6
-    char serv[NI_MAXSERV];
+    if(SERVER_AF == AF_INET6) {
+       char serv[NI_MAXSERV];
 
-    if (getnameinfo((struct sockaddr *) s,
-                    sizeof(struct SOCKADDR),
-                    NULL, 0, serv, sizeof(serv), NI_NUMERICSERV)) {
-        fprintf(stderr, "[IPv6] getnameinfo failed\n");
+        if (getnameinfo((struct sockaddr *) s,
+                        SOCKADDR_LEN,
+                        NULL, 0, serv, sizeof(serv), NI_NUMERICSERV)) {
+            fprintf(stderr, "[IPv6] getnameinfo failed\n");
+        } else {
+            p = atoi(serv);
+        }
     } else {
-        p = atoi(serv);
+#endif
+        p = ntohs(((struct sockaddr_in *) s)->sin_port);
+#ifdef INET6
     }
-#else
-    p = ntohs(s->sin_port);
 #endif
     return p;
 }
diff -urN boa-0.94.13.orig/src/mmap_cache.c boa-0.94.13/src/mmap_cache.c
--- boa-0.94.13.orig/src/mmap_cache.c	2002-03-24 23:35:34.000000000 +0100
+++ boa-0.94.13/src/mmap_cache.c	2008-10-28 14:55:16.000000000 +0100
@@ -67,7 +67,7 @@
 
     m = mmap(0, s->st_size, PROT_READ, MAP_OPTIONS, data_fd, 0);
 
-    if ((int) m == -1) {
+    if ((ssize_t) m == -1) {
         /* boa_perror(req,"mmap"); */
         return NULL;
     }
diff -urN boa-0.94.13.orig/src/request.c boa-0.94.13/src/request.c
--- boa-0.94.13.orig/src/request.c	2008-10-28 16:16:03.000000000 +0100
+++ boa-0.94.13/src/request.c	2008-10-28 15:17:20.000000000 +0100
@@ -75,12 +75,12 @@
     int fd;                     /* socket */
     struct SOCKADDR remote_addr; /* address */
     struct SOCKADDR salocal;
-    int remote_addrlen = sizeof (struct SOCKADDR);
+    int remote_addrlen = SOCKADDR_LEN;
     request *conn;              /* connection */
-    size_t len;
+    socklen_t len;
     static int system_bufsize = 0; /* Default size of SNDBUF given by system */
 
-    remote_addr.S_FAMILY = 0xdead;
+    S_FAMILY(&remote_addr) = 0xdead;
     fd = accept(server_s, (struct sockaddr *) &remote_addr,
                 &remote_addrlen);
 
@@ -133,7 +133,7 @@
     }
 #endif
 
-    len = sizeof(salocal);
+    len = SOCKADDR_LEN;
 
     if (getsockname(fd, (struct sockaddr *) &salocal, &len) != 0) {
         WARN("getsockname");