]> gitweb.michael.orlitzky.com - mjo-overlay.git/blob - net-dns/djbdns/files/ipv6-mjo.patch
Second try at ipv6 with my own ipv6 patch.
[mjo-overlay.git] / net-dns / djbdns / files / ipv6-mjo.patch
1 diff -uNr djbdns-1.05/FILES djbdns-1.05-ipv6/FILES
2 --- djbdns-1.05/FILES 2001-02-11 22:11:45.000000000 +0100
3 +++ djbdns-1.05-ipv6/FILES 2005-09-08 21:58:08.166381250 +0200
4 @@ -135,6 +135,7 @@
5 exit.h
6 fmt.h
7 fmt_ulong.c
8 +fmt_xlong.c
9 gen_alloc.h
10 gen_allocdefs.h
11 getln.c
12 @@ -151,6 +152,9 @@
13 ip4.h
14 ip4_fmt.c
15 ip4_scan.c
16 +ip6.h
17 +ip6_fmt.c
18 +ip6_scan.c
19 ndelay.h
20 ndelay_off.c
21 ndelay_on.c
22 @@ -164,6 +168,7 @@
23 readclose.c
24 readclose.h
25 scan.h
26 +scan_0x.c
27 scan_ulong.c
28 seek.h
29 seek_set.c
30 @@ -241,3 +246,9 @@
31 warn-shsgr
32 buffer_read.c
33 buffer_write.c
34 +dns_nd6.c
35 +socket_udp6.c
36 +socket_getifidx.c
37 +tryn2i.c
38 +haven2i.h1
39 +haven2i.h2
40 diff -uNr djbdns-1.05/Makefile djbdns-1.05-ipv6/Makefile
41 --- djbdns-1.05/Makefile 2001-02-11 22:11:45.000000000 +0100
42 +++ djbdns-1.05-ipv6/Makefile 2005-09-08 21:58:08.166381250 +0200
43 @@ -120,12 +120,14 @@
44 case_diffb.o case_diffs.o case_lowerb.o fmt_ulong.o ip4_fmt.o \
45 ip4_scan.o scan_ulong.o str_chr.o str_diff.o str_len.o str_rchr.o \
46 str_start.o uint16_pack.o uint16_unpack.o uint32_pack.o \
47 -uint32_unpack.o
48 +uint32_unpack.o ip6_fmt.o ip6_scan.o fmt_xlong.o \
49 +scan_xlong.o
50 ./makelib byte.a byte_chr.o byte_copy.o byte_cr.o \
51 byte_diff.o byte_zero.o case_diffb.o case_diffs.o \
52 case_lowerb.o fmt_ulong.o ip4_fmt.o ip4_scan.o scan_ulong.o \
53 str_chr.o str_diff.o str_len.o str_rchr.o str_start.o \
54 - uint16_pack.o uint16_unpack.o uint32_pack.o uint32_unpack.o
55 + uint16_pack.o uint16_unpack.o uint32_pack.o uint32_unpack.o \
56 + ip6_fmt.o ip6_scan.o fmt_xlong.o scan_xlong.o
57
58 byte_chr.o: \
59 compile byte_chr.c byte.h
60 @@ -228,11 +230,13 @@
61 dns.a: \
62 makelib dns_dfd.o dns_domain.o dns_dtda.o dns_ip.o dns_ipq.o dns_mx.o \
63 dns_name.o dns_nd.o dns_packet.o dns_random.o dns_rcip.o dns_rcrw.o \
64 -dns_resolve.o dns_sortip.o dns_transmit.o dns_txt.o
65 +dns_resolve.o dns_sortip.o dns_transmit.o dns_txt.o dns_ip6.o \
66 +dns_sortip6.o dns_nd6.o dns_ipq6.o
67 ./makelib dns.a dns_dfd.o dns_domain.o dns_dtda.o dns_ip.o \
68 dns_ipq.o dns_mx.o dns_name.o dns_nd.o dns_packet.o \
69 dns_random.o dns_rcip.o dns_rcrw.o dns_resolve.o \
70 - dns_sortip.o dns_transmit.o dns_txt.o
71 + dns_sortip.o dns_transmit.o dns_txt.o dns_ip6.o dns_sortip6.o \
72 + dns_nd6.o dns_ipq6.o
73
74 dns_dfd.o: \
75 compile dns_dfd.c error.h alloc.h byte.h dns.h stralloc.h gen_alloc.h \
76 @@ -254,11 +258,21 @@
77 stralloc.h iopause.h taia.h tai.h uint64.h taia.h
78 ./compile dns_ip.c
79
80 +dns_ip6.o: \
81 +compile dns_ip6.c stralloc.h gen_alloc.h uint16.h byte.h dns.h \
82 +stralloc.h iopause.h taia.h tai.h uint64.h taia.h
83 + ./compile dns_ip6.c
84 +
85 dns_ipq.o: \
86 compile dns_ipq.c stralloc.h gen_alloc.h case.h byte.h str.h dns.h \
87 stralloc.h iopause.h taia.h tai.h uint64.h taia.h
88 ./compile dns_ipq.c
89
90 +dns_ipq6.o: \
91 +compile dns_ipq6.c stralloc.h gen_alloc.h case.h byte.h str.h dns.h \
92 +stralloc.h iopause.h taia.h tai.h uint64.h taia.h
93 + ./compile dns_ipq6.c
94 +
95 dns_mx.o: \
96 compile dns_mx.c stralloc.h gen_alloc.h byte.h uint16.h dns.h \
97 stralloc.h iopause.h taia.h tai.h uint64.h taia.h
98 @@ -274,6 +288,11 @@
99 taia.h tai.h uint64.h taia.h
100 ./compile dns_nd.c
101
102 +dns_nd6.o: \
103 +compile dns_nd6.c byte.h fmt.h dns.h stralloc.h gen_alloc.h iopause.h \
104 +taia.h tai.h uint64.h taia.h
105 + ./compile dns_nd6.c
106 +
107 dns_packet.o: \
108 compile dns_packet.c error.h dns.h stralloc.h gen_alloc.h iopause.h \
109 taia.h tai.h uint64.h taia.h
110 @@ -306,6 +325,11 @@
111 taia.h tai.h uint64.h taia.h
112 ./compile dns_sortip.c
113
114 +dns_sortip6.o: \
115 +compile dns_sortip6.c byte.h dns.h stralloc.h gen_alloc.h iopause.h \
116 +taia.h tai.h uint64.h taia.h
117 + ./compile dns_sortip6.c
118 +
119 dns_transmit.o: \
120 compile dns_transmit.c socket.h uint16.h alloc.h error.h byte.h \
121 uint16.h dns.h stralloc.h gen_alloc.h iopause.h taia.h tai.h uint64.h \
122 @@ -369,6 +393,17 @@
123 gen_alloc.h iopause.h taia.h tai.h uint64.h taia.h
124 ./compile dnsip.c
125
126 +dnsip6: \
127 +load dnsip6.o iopause.o dns.a env.a libtai.a alloc.a buffer.a unix.a \
128 +byte.a socket.lib
129 + ./load dnsip6 iopause.o dns.a env.a libtai.a alloc.a \
130 + buffer.a unix.a byte.a `cat socket.lib`
131 +
132 +dnsip6.o: \
133 +compile dnsip6.c buffer.h exit.h strerr.h ip6.h dns.h stralloc.h \
134 +gen_alloc.h iopause.h taia.h tai.h uint64.h
135 + ./compile dnsip6.c
136 +
137 dnsipq: \
138 load dnsipq.o iopause.o dns.a env.a libtai.a alloc.a buffer.a unix.a \
139 byte.a socket.lib
140 @@ -380,6 +415,17 @@
141 gen_alloc.h iopause.h taia.h tai.h uint64.h taia.h
142 ./compile dnsipq.c
143
144 +dnsip6q: \
145 +load dnsip6q.o iopause.o dns.a env.a libtai.a alloc.a buffer.a unix.a \
146 +byte.a socket.lib
147 + ./load dnsip6q iopause.o dns.a env.a libtai.a alloc.a \
148 + buffer.a unix.a byte.a `cat socket.lib`
149 +
150 +dnsip6q.o: \
151 +compile dnsip6q.c buffer.h exit.h strerr.h ip4.h dns.h stralloc.h \
152 +gen_alloc.h iopause.h taia.h tai.h uint64.h taia.h
153 + ./compile dnsip6q.c
154 +
155 dnsmx: \
156 load dnsmx.o iopause.o dns.a env.a libtai.a alloc.a buffer.a unix.a \
157 byte.a socket.lib
158 @@ -399,7 +445,7 @@
159
160 dnsname.o: \
161 compile dnsname.c buffer.h exit.h strerr.h ip4.h dns.h stralloc.h \
162 -gen_alloc.h iopause.h taia.h tai.h uint64.h taia.h
163 +gen_alloc.h iopause.h taia.h tai.h uint64.h taia.h ip6.h
164 ./compile dnsname.c
165
166 dnsq: \
167 @@ -484,6 +530,10 @@
168 compile fmt_ulong.c fmt.h
169 ./compile fmt_ulong.c
170
171 +fmt_xlong.o: \
172 +compile fmt_xlong.c scan.h
173 + ./compile fmt_xlong.c
174 +
175 generic-conf.o: \
176 compile generic-conf.c strerr.h buffer.h open.h generic-conf.h \
177 buffer.h
178 @@ -546,10 +596,18 @@
179 compile ip4_fmt.c fmt.h ip4.h
180 ./compile ip4_fmt.c
181
182 +ip6_fmt.o: \
183 +compile ip6_fmt.c fmt.h ip6.h
184 + ./compile ip6_fmt.c
185 +
186 ip4_scan.o: \
187 compile ip4_scan.c scan.h ip4.h
188 ./compile ip4_scan.c
189
190 +ip6_scan.o: \
191 +compile ip6_scan.c scan.h ip6.h
192 + ./compile ip6_scan.c
193 +
194 it: \
195 prog install instcheck
196
197 @@ -626,9 +684,9 @@
198 ./compile parsetype.c
199
200 pickdns: \
201 -load pickdns.o server.o response.o droproot.o qlog.o prot.o dns.a \
202 +load pickdns.o server.o iopause.o response.o droproot.o qlog.o prot.o dns.a \
203 env.a libtai.a cdb.a alloc.a buffer.a unix.a byte.a socket.lib
204 - ./load pickdns server.o response.o droproot.o qlog.o \
205 + ./load pickdns server.o iopause.o response.o droproot.o qlog.o \
206 prot.o dns.a env.a libtai.a cdb.a alloc.a buffer.a unix.a \
207 byte.a `cat socket.lib`
208
209 @@ -677,7 +735,7 @@
210 rbldns-data pickdns-conf pickdns pickdns-data tinydns-conf tinydns \
211 tinydns-data tinydns-get tinydns-edit axfr-get axfrdns-conf axfrdns \
212 dnsip dnsipq dnsname dnstxt dnsmx dnsfilter random-ip dnsqr dnsq \
213 -dnstrace dnstracesort cachetest utime rts
214 +dnstrace dnstracesort cachetest utime rts dnsip6 dnsip6q
215
216 prot.o: \
217 compile prot.c hasshsgr.h prot.h
218 @@ -704,9 +762,9 @@
219 ./compile random-ip.c
220
221 rbldns: \
222 -load rbldns.o server.o response.o dd.o droproot.o qlog.o prot.o dns.a \
223 +load rbldns.o server.o iopause.o response.o dd.o droproot.o qlog.o prot.o dns.a \
224 env.a libtai.a cdb.a alloc.a buffer.a unix.a byte.a socket.lib
225 - ./load rbldns server.o response.o dd.o droproot.o qlog.o \
226 + ./load rbldns server.o iopause.o response.o dd.o droproot.o qlog.o \
227 prot.o dns.a env.a libtai.a cdb.a alloc.a buffer.a unix.a \
228 byte.a `cat socket.lib`
229
230 @@ -762,6 +820,10 @@
231 compile scan_ulong.c scan.h
232 ./compile scan_ulong.c
233
234 +scan_xlong.o: \
235 +compile scan_xlong.c scan.h
236 + ./compile scan_xlong.c
237 +
238 seek_set.o: \
239 compile seek_set.c seek.h
240 ./compile seek_set.c
241 @@ -774,7 +836,7 @@
242 compile server.c byte.h case.h env.h buffer.h strerr.h ip4.h uint16.h \
243 ndelay.h socket.h uint16.h droproot.h qlog.h uint16.h response.h \
244 uint32.h dns.h stralloc.h gen_alloc.h iopause.h taia.h tai.h uint64.h \
245 -taia.h
246 +taia.h iopause.h alloc.h str.h
247 ./compile server.c
248
249 setup: \
250 @@ -796,14 +858,26 @@
251 compile socket_accept.c byte.h socket.h uint16.h
252 ./compile socket_accept.c
253
254 +socket_accept6.o: \
255 +compile socket_accept6.c byte.h socket.h uint16.h
256 + ./compile socket_accept6.c
257 +
258 socket_bind.o: \
259 compile socket_bind.c byte.h socket.h uint16.h
260 ./compile socket_bind.c
261
262 +socket_bind6.o: \
263 +compile socket_bind6.c sockaddr_in6.h haveip6.h byte.h socket.h uint16.h uint32.h ip6.h error.h
264 + ./compile socket_bind6.c
265 +
266 socket_conn.o: \
267 compile socket_conn.c byte.h socket.h uint16.h
268 ./compile socket_conn.c
269
270 +socket_connect6.o: \
271 +compile socket_connect6.c byte.h socket.h uint16.h uint32.h
272 + ./compile socket_connect6.c
273 +
274 socket_listen.o: \
275 compile socket_listen.c socket.h uint16.h
276 ./compile socket_listen.c
277 @@ -812,18 +886,47 @@
278 compile socket_recv.c byte.h socket.h uint16.h
279 ./compile socket_recv.c
280
281 +socket_recv6.o: \
282 +compile socket_recv6.c sockaddr_in6.h haveip6.h byte.h socket.h uint16.h uint32.h ip6.h error.h
283 + ./compile socket_recv6.c
284 +
285 socket_send.o: \
286 compile socket_send.c byte.h socket.h uint16.h
287 ./compile socket_send.c
288
289 +socket_send6.o: \
290 +compile socket_send6.c byte.h socket.h uint16.h uint32.h ip6.h haveip6.h error.h
291 + ./compile socket_send6.c
292 +
293 socket_tcp.o: \
294 compile socket_tcp.c ndelay.h socket.h uint16.h
295 ./compile socket_tcp.c
296
297 +socket_tcp6.o: \
298 +compile socket_tcp6.c ndelay.h socket.h uint16.h uint32.h haveip6.h
299 + ./compile socket_tcp6.c
300 +
301 socket_udp.o: \
302 compile socket_udp.c ndelay.h socket.h uint16.h
303 ./compile socket_udp.c
304
305 +socket_udp6.o: \
306 +compile socket_udp6.c ndelay.h socket.h uint16.h uint32.h haveip6.h
307 + ./compile socket_udp6.c
308 +
309 +socket_noipv6.o: \
310 +compile socket_noipv6.c haveip6.h
311 + ./compile socket_noipv6.c
312 +
313 +socket_getifidx.o: \
314 +compile socket_getifidx.c socket.h uint16.h uint32.h haven2i.h
315 + ./compile socket_getifidx.c
316 +
317 +haven2i.h: \
318 +tryn2i.c choose compile load socket.lib haven2i.h1 haven2i.h2
319 + cp /dev/null haven2i.h
320 + ./choose cL tryn2i haven2i.h1 haven2i.h2 socket > haven2i.h
321 +
322 str_chr.o: \
323 compile str_chr.c str.h
324 ./compile str_chr.c
325 @@ -965,7 +1068,7 @@
326 tdlookup.o: \
327 compile tdlookup.c uint16.h open.h tai.h uint64.h cdb.h uint32.h \
328 byte.h case.h dns.h stralloc.h gen_alloc.h iopause.h taia.h tai.h \
329 -taia.h seek.h response.h uint32.h
330 +taia.h seek.h response.h uint32.h ip6.h
331 ./compile tdlookup.c
332
333 timeoutread.o: \
334 @@ -979,10 +1082,10 @@
335 ./compile timeoutwrite.c
336
337 tinydns: \
338 -load tinydns.o server.o droproot.o tdlookup.o response.o qlog.o \
339 +load tinydns.o server.o iopause.o droproot.o tdlookup.o response.o qlog.o \
340 prot.o dns.a libtai.a env.a cdb.a alloc.a buffer.a unix.a byte.a \
341 socket.lib
342 - ./load tinydns server.o droproot.o tdlookup.o response.o \
343 + ./load tinydns server.o iopause.o droproot.o tdlookup.o response.o \
344 qlog.o prot.o dns.a libtai.a env.a cdb.a alloc.a buffer.a \
345 unix.a byte.a `cat socket.lib`
346
347 @@ -1005,7 +1108,7 @@
348 compile tinydns-data.c uint16.h uint32.h str.h byte.h fmt.h ip4.h \
349 exit.h case.h scan.h buffer.h strerr.h getln.h buffer.h stralloc.h \
350 gen_alloc.h cdb_make.h buffer.h uint32.h stralloc.h open.h dns.h \
351 -stralloc.h iopause.h taia.h tai.h uint64.h taia.h
352 +stralloc.h iopause.h taia.h tai.h uint64.h taia.h ip6.h
353 ./compile tinydns-data.c
354
355 tinydns-edit: \
356 @@ -1068,12 +1171,18 @@
357 makelib buffer_read.o buffer_write.o error.o error_str.o ndelay_off.o \
358 ndelay_on.o open_read.o open_trunc.o openreadclose.o readclose.o \
359 seek_set.o socket_accept.o socket_bind.o socket_conn.o \
360 -socket_listen.o socket_recv.o socket_send.o socket_tcp.o socket_udp.o
361 +socket_listen.o socket_recv.o socket_send.o socket_tcp.o socket_udp.o \
362 +socket_udp6.o socket_getifidx.o socket_recv6.o socket_send6.o \
363 +socket_bind6.o socket_noipv6.o socket_tcp6.o socket_connect6.o \
364 +socket_accept6.o
365 ./makelib unix.a buffer_read.o buffer_write.o error.o \
366 error_str.o ndelay_off.o ndelay_on.o open_read.o \
367 open_trunc.o openreadclose.o readclose.o seek_set.o \
368 socket_accept.o socket_bind.o socket_conn.o socket_listen.o \
369 - socket_recv.o socket_send.o socket_tcp.o socket_udp.o
370 + socket_recv.o socket_send.o socket_tcp.o socket_udp.o \
371 + socket_udp6.o socket_getifidx.o socket_recv6.o socket_send6.o \
372 + socket_bind6.o socket_noipv6.o socket_tcp6.o socket_connect6.o \
373 + socket_accept6.o
374
375 utime: \
376 load utime.o byte.a
377 @@ -1084,10 +1193,10 @@
378 ./compile utime.c
379
380 walldns: \
381 -load walldns.o server.o response.o droproot.o qlog.o prot.o dd.o \
382 +load walldns.o server.o iopause.o response.o droproot.o qlog.o prot.o dd.o \
383 dns.a env.a cdb.a alloc.a buffer.a unix.a byte.a socket.lib
384 - ./load walldns server.o response.o droproot.o qlog.o \
385 - prot.o dd.o dns.a env.a cdb.a alloc.a buffer.a unix.a \
386 + ./load walldns server.o iopause.o response.o droproot.o qlog.o \
387 + prot.o dd.o dns.a libtai.a env.a cdb.a alloc.a buffer.a unix.a \
388 byte.a `cat socket.lib`
389
390 walldns-conf: \
391 @@ -1104,3 +1213,14 @@
392 compile walldns.c byte.h dns.h stralloc.h gen_alloc.h iopause.h \
393 taia.h tai.h uint64.h taia.h dd.h response.h uint32.h
394 ./compile walldns.c
395 +
396 +haveip6.h: \
397 +tryip6.c choose compile haveip6.h1 haveip6.h2
398 + ./choose c tryip6 haveip6.h1 haveip6.h2 > haveip6.h
399 +
400 +sockaddr_in6.h: \
401 +trysa6.c choose compile sockaddr_in6.h1 sockaddr_in6.h2 haveip6.h
402 + ./choose c trysa6 sockaddr_in6.h1 sockaddr_in6.h2 > sockaddr_in6.h
403 +
404 +clean:
405 + rm -f `cat TARGETS`
406 diff -uNr djbdns-1.05/TARGETS djbdns-1.05-ipv6/TARGETS
407 --- djbdns-1.05/TARGETS 2001-02-11 22:11:45.000000000 +0100
408 +++ djbdns-1.05-ipv6/TARGETS 2005-09-08 21:58:08.170381500 +0200
409 @@ -102,6 +102,7 @@
410 dns_dtda.o
411 dns_ip.o
412 dns_ipq.o
413 +dns_ipq6.o
414 dns_mx.o
415 dns_name.o
416 dns_nd.o
417 @@ -180,6 +181,8 @@
418 dnsip
419 dnsipq.o
420 dnsipq
421 +dnsip6q.o
422 +dnsip6q
423 dnsname.o
424 dnsname
425 dnstxt.o
426 @@ -214,3 +217,25 @@
427 it
428 setup
429 check
430 +scan_0x.o
431 +fmt_xlong.o
432 +ip6_scan.o
433 +ip6_fmt.o
434 +dnsip6.o
435 +dns_ip6.o
436 +dns_sortip6.o
437 +dnsip6
438 +dns_nd6.o
439 +socket_udp6.o
440 +socket_getifidx.o
441 +socket_bind6.o
442 +socket_noipv6.o
443 +socket_recv6.o
444 +socket_send6.o
445 +haveip6.h
446 +haven2i.h
447 +sockaddr_in6.h
448 +scan_xlong.o
449 +socket_accept6.o
450 +socket_connect6.o
451 +socket_tcp6.o
452 diff -uNr djbdns-1.05/axfr-get.c djbdns-1.05-ipv6/axfr-get.c
453 --- djbdns-1.05/axfr-get.c 2001-02-11 22:11:45.000000000 +0100
454 +++ djbdns-1.05-ipv6/axfr-get.c 2005-09-08 21:58:08.170381500 +0200
455 @@ -13,6 +13,7 @@
456 #include "byte.h"
457 #include "str.h"
458 #include "ip4.h"
459 +#include "ip6.h"
460 #include "timeoutread.h"
461 #include "timeoutwrite.h"
462 #include "dns.h"
463 @@ -217,6 +218,14 @@
464 x_copy(buf,len,pos,data,4);
465 if (!stralloc_catb(&line,ipstr,ip4_fmt(ipstr,data))) return 0;
466 }
467 + else if (byte_equal(data,2,DNS_T_AAAA)) {
468 + char ipstr[IP6_FMT];
469 + if (!stralloc_copys(&line,"3")) return 0;
470 + if (!dns_domain_todot_cat(&line,d1)) return 0;
471 + if (!stralloc_cats(&line,":")) return 0;
472 + x_copy(buf,len,pos,data,16);
473 + if (!stralloc_catb(&line,ipstr,ip6_fmt_flat(ipstr,data))) return 0;
474 + }
475 else {
476 unsigned char ch;
477 unsigned char ch2;
478 diff -uNr djbdns-1.05/dns.h djbdns-1.05-ipv6/dns.h
479 --- djbdns-1.05/dns.h 2001-02-11 22:11:45.000000000 +0100
480 +++ djbdns-1.05-ipv6/dns.h 2005-09-08 21:58:08.174381750 +0200
481 @@ -35,7 +35,8 @@
482 struct taia deadline;
483 unsigned int pos;
484 const char *servers;
485 - char localip[4];
486 + char localip[16];
487 + unsigned int scope_id;
488 char qtype[2];
489 } ;
490
491 @@ -43,6 +44,7 @@
492 extern unsigned int dns_random(unsigned int);
493
494 extern void dns_sortip(char *,unsigned int);
495 +extern void dns_sortip6(char *,unsigned int);
496
497 extern void dns_domain_free(char **);
498 extern int dns_domain_copy(char **,const char *);
499 @@ -68,10 +70,13 @@
500
501 extern int dns_ip4_packet(stralloc *,const char *,unsigned int);
502 extern int dns_ip4(stralloc *,const stralloc *);
503 +extern int dns_ip6_packet(stralloc *,char *,unsigned int);
504 +extern int dns_ip6(stralloc *,stralloc *);
505 extern int dns_name_packet(stralloc *,const char *,unsigned int);
506 extern void dns_name4_domain(char *,const char *);
507 #define DNS_NAME4_DOMAIN 31
508 extern int dns_name4(stralloc *,const char *);
509 +extern int dns_name6(stralloc *,const char *);
510 extern int dns_txt_packet(stralloc *,const char *,unsigned int);
511 extern int dns_txt(stralloc *,const stralloc *);
512 extern int dns_mx_packet(stralloc *,const char *,unsigned int);
513 @@ -80,5 +85,13 @@
514 extern int dns_resolvconfrewrite(stralloc *);
515 extern int dns_ip4_qualify_rules(stralloc *,stralloc *,const stralloc *,const stralloc *);
516 extern int dns_ip4_qualify(stralloc *,stralloc *,const stralloc *);
517 +extern int dns_ip6_qualify_rules(stralloc *,stralloc *,const stralloc *,const stralloc *);
518 +extern int dns_ip6_qualify(stralloc *,stralloc *,const stralloc *);
519 +
520 +#define DNS_IP6_INT 0
521 +#define DNS_IP6_ARPA 1
522 +
523 +extern int dns_name6_domain(char *,const char *,int);
524 +#define DNS_NAME6_DOMAIN (4*16+11)
525
526 #endif
527 diff -uNr djbdns-1.05/dns_ip6.c djbdns-1.05-ipv6/dns_ip6.c
528 --- djbdns-1.05/dns_ip6.c 1970-01-01 01:00:00.000000000 +0100
529 +++ djbdns-1.05-ipv6/dns_ip6.c 2005-09-08 21:58:08.174381750 +0200
530 @@ -0,0 +1,103 @@
531 +#include "stralloc.h"
532 +#include "uint16.h"
533 +#include "byte.h"
534 +#include "dns.h"
535 +#include "ip4.h"
536 +#include "ip6.h"
537 +
538 +static int dns_ip6_packet_add(stralloc *out,char *buf,unsigned int len)
539 +{
540 + unsigned int pos;
541 + char header[16];
542 + uint16 numanswers;
543 + uint16 datalen;
544 +
545 + pos = dns_packet_copy(buf,len,0,header,12); if (!pos) return -1;
546 + uint16_unpack_big(header + 6,&numanswers);
547 + pos = dns_packet_skipname(buf,len,pos); if (!pos) return -1;
548 + pos += 4;
549 +
550 + while (numanswers--) {
551 + pos = dns_packet_skipname(buf,len,pos); if (!pos) return -1;
552 + pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) return -1;
553 + uint16_unpack_big(header + 8,&datalen);
554 + if (byte_equal(header,2,DNS_T_AAAA)) {
555 + if (byte_equal(header + 2,2,DNS_C_IN))
556 + if (datalen == 16) {
557 + if (!dns_packet_copy(buf,len,pos,header,16)) return -1;
558 + if (!stralloc_catb(out,header,16)) return -1;
559 + }
560 + } else if (byte_equal(header,2,DNS_T_A))
561 + if (byte_equal(header + 2,2,DNS_C_IN))
562 + if (datalen == 4) {
563 + byte_copy(header,12,V4mappedprefix);
564 + if (!dns_packet_copy(buf,len,pos,header+12,4)) return -1;
565 + if (!stralloc_catb(out,header,16)) return -1;
566 + }
567 + pos += datalen;
568 + }
569 +
570 + dns_sortip6(out->s,out->len);
571 + return 0;
572 +}
573 +
574 +int dns_ip6_packet(stralloc *out,char *buf,unsigned int len) {
575 + if (!stralloc_copys(out,"")) return -1;
576 + return dns_ip6_packet_add(out,buf,len);
577 +}
578 +
579 +static char *q = 0;
580 +
581 +int dns_ip6(stralloc *out,stralloc *fqdn)
582 +{
583 + unsigned int i;
584 + char code;
585 + char ch;
586 + char ip[16];
587 +
588 + if (!stralloc_copys(out,"")) return -1;
589 + if (!stralloc_readyplus(fqdn,1)) return -1;
590 + fqdn->s[fqdn->len]=0;
591 + if ((i=ip6_scan(fqdn->s,ip))) {
592 + if (fqdn->s[i]) return -1;
593 + stralloc_copyb(out,ip,16);
594 + return 0;
595 + }
596 + code = 0;
597 + for (i = 0;i <= fqdn->len;++i) {
598 + if (i < fqdn->len)
599 + ch = fqdn->s[i];
600 + else
601 + ch = '.';
602 +
603 + if ((ch == '[') || (ch == ']')) continue;
604 + if (ch == '.') {
605 + if (!stralloc_append(out,&code)) return -1;
606 + code = 0;
607 + continue;
608 + }
609 + if ((ch >= '0') && (ch <= '9')) {
610 + code *= 10;
611 + code += ch - '0';
612 + continue;
613 + }
614 +
615 + if (!dns_domain_fromdot(&q,fqdn->s,fqdn->len)) return -1;
616 + if (!stralloc_copys(out,"")) return -1;
617 + if (dns_resolve(q,DNS_T_AAAA) != -1)
618 + if (dns_ip6_packet_add(out,dns_resolve_tx.packet,dns_resolve_tx.packetlen) != -1) {
619 + dns_transmit_free(&dns_resolve_tx);
620 + dns_domain_free(&q);
621 + }
622 + if (!dns_domain_fromdot(&q,fqdn->s,fqdn->len)) return -1;
623 + if (dns_resolve(q,DNS_T_A) != -1)
624 + if (dns_ip6_packet_add(out,dns_resolve_tx.packet,dns_resolve_tx.packetlen) != -1) {
625 + dns_transmit_free(&dns_resolve_tx);
626 + dns_domain_free(&q);
627 + }
628 + return out->a>0?0:-1;
629 + }
630 +
631 + out->len &= ~3;
632 + return 0;
633 +}
634 diff -uNr djbdns-1.05/dns_ipq6.c djbdns-1.05-ipv6/dns_ipq6.c
635 --- djbdns-1.05/dns_ipq6.c 1970-01-01 01:00:00.000000000 +0100
636 +++ djbdns-1.05-ipv6/dns_ipq6.c 2005-09-08 21:58:08.178382000 +0200
637 @@ -0,0 +1,72 @@
638 +#include "stralloc.h"
639 +#include "case.h"
640 +#include "byte.h"
641 +#include "str.h"
642 +#include "dns.h"
643 +
644 +static int doit(stralloc *work,const char *rule)
645 +{
646 + char ch;
647 + unsigned int colon;
648 + unsigned int prefixlen;
649 +
650 + ch = *rule++;
651 + if ((ch != '?') && (ch != '=') && (ch != '*') && (ch != '-')) return 1;
652 + colon = str_chr(rule,':');
653 + if (!rule[colon]) return 1;
654 +
655 + if (work->len < colon) return 1;
656 + prefixlen = work->len - colon;
657 + if ((ch == '=') && prefixlen) return 1;
658 + if (case_diffb(rule,colon,work->s + prefixlen)) return 1;
659 + if (ch == '?') {
660 + if (byte_chr(work->s,prefixlen,'.') < prefixlen) return 1;
661 + if (byte_chr(work->s,prefixlen,':') < prefixlen) return 1;
662 + if (byte_chr(work->s,prefixlen,'[') < prefixlen) return 1;
663 + if (byte_chr(work->s,prefixlen,']') < prefixlen) return 1;
664 + }
665 +
666 + work->len = prefixlen;
667 + if (ch == '-') work->len = 0;
668 + return stralloc_cats(work,rule + colon + 1);
669 +}
670 +
671 +int dns_ip6_qualify_rules(stralloc *out,stralloc *fqdn,const stralloc *in,const stralloc *rules)
672 +{
673 + unsigned int i;
674 + unsigned int j;
675 + unsigned int plus;
676 + unsigned int fqdnlen;
677 +
678 + if (!stralloc_copy(fqdn,in)) return -1;
679 +
680 + for (j = i = 0;j < rules->len;++j)
681 + if (!rules->s[j]) {
682 + if (!doit(fqdn,rules->s + i)) return -1;
683 + i = j + 1;
684 + }
685 +
686 + fqdnlen = fqdn->len;
687 + plus = byte_chr(fqdn->s,fqdnlen,'+');
688 + if (plus >= fqdnlen)
689 + return dns_ip6(out,fqdn);
690 +
691 + i = plus + 1;
692 + for (;;) {
693 + j = byte_chr(fqdn->s + i,fqdnlen - i,'+');
694 + byte_copy(fqdn->s + plus,j,fqdn->s + i);
695 + fqdn->len = plus + j;
696 + if (dns_ip6(out,fqdn) == -1) return -1;
697 + if (out->len) return 0;
698 + i += j;
699 + if (i >= fqdnlen) return 0;
700 + ++i;
701 + }
702 +}
703 +
704 +int dns_ip6_qualify(stralloc *out,stralloc *fqdn,const stralloc *in)
705 +{
706 + static stralloc rules;
707 + if (dns_resolvconfrewrite(&rules) == -1) return -1;
708 + return dns_ip6_qualify_rules(out,fqdn,in,&rules);
709 +}
710 diff -uNr djbdns-1.05/dns_name.c djbdns-1.05-ipv6/dns_name.c
711 --- djbdns-1.05/dns_name.c 2001-02-11 22:11:45.000000000 +0100
712 +++ djbdns-1.05-ipv6/dns_name.c 2005-09-08 21:58:08.178382000 +0200
713 @@ -2,6 +2,7 @@
714 #include "uint16.h"
715 #include "byte.h"
716 #include "dns.h"
717 +#include "ip6.h"
718
719 static char *q = 0;
720
721 @@ -46,3 +47,24 @@
722 dns_domain_free(&q);
723 return 0;
724 }
725 +
726 +int dns_name6_inner(stralloc *out,const char ip[16],int t)
727 +{
728 + char name[DNS_NAME6_DOMAIN];
729 +
730 + dns_name6_domain(name,ip,t);
731 + if (dns_resolve(name,DNS_T_PTR) == -1) return -1;
732 + if (dns_name_packet(out,dns_resolve_tx.packet,dns_resolve_tx.packetlen) == -1) return -1;
733 + dns_transmit_free(&dns_resolve_tx);
734 + dns_domain_free(&q);
735 + return 0;
736 +}
737 +
738 +int dns_name6(stralloc *out,const char ip[16])
739 +{
740 + if (ip6_isv4mapped(ip))
741 + return dns_name4(out,ip+12);
742 + if (dns_name6_inner(out,ip,DNS_IP6_ARPA)) return -1;
743 + if (!out->len) return dns_name6_inner(out,ip,DNS_IP6_INT);
744 + return 0;
745 +}
746 diff -uNr djbdns-1.05/dns_nd6.c djbdns-1.05-ipv6/dns_nd6.c
747 --- djbdns-1.05/dns_nd6.c 1970-01-01 01:00:00.000000000 +0100
748 +++ djbdns-1.05-ipv6/dns_nd6.c 2005-09-08 21:58:08.178382000 +0200
749 @@ -0,0 +1,35 @@
750 +#include "byte.h"
751 +#include "fmt.h"
752 +#include "dns.h"
753 +
754 +/* RFC1886:
755 + * 4321:0:1:2:3:4:567:89ab
756 + * ->
757 + * b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.IP6.INT.
758 + * b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.IP6.ARPA.
759 + */
760 +
761 +extern char tohex(char num);
762 +
763 +unsigned int mkint(unsigned char a,unsigned char b) {
764 + return ((unsigned int)a << 8) + (unsigned int)b;
765 +}
766 +
767 +int dns_name6_domain(char name[DNS_NAME6_DOMAIN],const char ip[16],int t)
768 +{
769 + unsigned int j;
770 +
771 + for (j=0; j<16; j++) {
772 + name[j*4]=1;
773 + name[j*4+1]=tohex(ip[15-j] & 15);
774 + name[j*4+2]=1;
775 + name[j*4+3]=tohex((unsigned char)ip[15-j] >> 4);
776 + }
777 + if (t==DNS_IP6_INT)
778 + byte_copy(name + 4*16,9,"\3ip6\3int\0");
779 + else if (t==DNS_IP6_ARPA)
780 + byte_copy(name + 4*16,10,"\3ip6\4arpa\0");
781 + else return 0;
782 + return 4*16+9+t;
783 +}
784 +
785 diff -uNr djbdns-1.05/dns_rcip.c djbdns-1.05-ipv6/dns_rcip.c
786 --- djbdns-1.05/dns_rcip.c 2001-02-11 22:11:45.000000000 +0100
787 +++ djbdns-1.05-ipv6/dns_rcip.c 2005-09-08 21:58:08.182382250 +0200
788 @@ -2,12 +2,13 @@
789 #include "openreadclose.h"
790 #include "byte.h"
791 #include "ip4.h"
792 +#include "ip6.h"
793 #include "env.h"
794 #include "dns.h"
795
796 static stralloc data = {0};
797
798 -static int init(char ip[64])
799 +static int init(char ip[256])
800 {
801 int i;
802 int j;
803 @@ -20,10 +21,10 @@
804 if (*x == '.')
805 ++x;
806 else {
807 - i = ip4_scan(x,ip + iplen);
808 + i = ip6_scan(x,ip + iplen);
809 if (!i) break;
810 x += i;
811 - iplen += 4;
812 + iplen += 16;
813 }
814 }
815
816 @@ -40,10 +41,8 @@
817 while ((data.s[i] == ' ') || (data.s[i] == '\t'))
818 ++i;
819 if (iplen <= 60)
820 - if (ip4_scan(data.s + i,ip + iplen)) {
821 - if (byte_equal(ip + iplen,4,"\0\0\0\0"))
822 - byte_copy(ip + iplen,4,"\177\0\0\1");
823 - iplen += 4;
824 + if (ip6_scan(data.s + i,ip + iplen)) {
825 + iplen += 16;
826 }
827 }
828 i = j + 1;
829 @@ -52,19 +51,19 @@
830 }
831
832 if (!iplen) {
833 - byte_copy(ip,4,"\177\0\0\1");
834 - iplen = 4;
835 + byte_copy(ip,16,"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1");
836 + iplen = 16;
837 }
838 - byte_zero(ip + iplen,64 - iplen);
839 + byte_zero(ip + iplen,256 - iplen);
840 return 0;
841 }
842
843 static int ok = 0;
844 static unsigned int uses;
845 static struct taia deadline;
846 -static char ip[64]; /* defined if ok */
847 +static char ip[256]; /* defined if ok */
848
849 -int dns_resolvconfip(char s[64])
850 +int dns_resolvconfip(char s[256])
851 {
852 struct taia now;
853
854 @@ -81,6 +80,6 @@
855 }
856
857 --uses;
858 - byte_copy(s,64,ip);
859 + byte_copy(s,256,ip);
860 return 0;
861 }
862 diff -uNr djbdns-1.05/dns_resolve.c djbdns-1.05-ipv6/dns_resolve.c
863 --- djbdns-1.05/dns_resolve.c 2001-02-11 22:11:45.000000000 +0100
864 +++ djbdns-1.05-ipv6/dns_resolve.c 2005-09-08 21:58:08.182382250 +0200
865 @@ -2,6 +2,7 @@
866 #include "taia.h"
867 #include "byte.h"
868 #include "dns.h"
869 +#include "ip6.h"
870
871 struct dns_transmit dns_resolve_tx = {0};
872
873 @@ -9,12 +10,12 @@
874 {
875 struct taia stamp;
876 struct taia deadline;
877 - char servers[64];
878 + char servers[256];
879 iopause_fd x[1];
880 int r;
881
882 if (dns_resolvconfip(servers) == -1) return -1;
883 - if (dns_transmit_start(&dns_resolve_tx,servers,1,q,qtype,"\0\0\0\0") == -1) return -1;
884 + if (dns_transmit_start(&dns_resolve_tx,servers,1,q,qtype,V6any) == -1) return -1;
885
886 for (;;) {
887 taia_now(&stamp);
888 diff -uNr djbdns-1.05/dns_sortip6.c djbdns-1.05-ipv6/dns_sortip6.c
889 --- djbdns-1.05/dns_sortip6.c 1970-01-01 01:00:00.000000000 +0100
890 +++ djbdns-1.05-ipv6/dns_sortip6.c 2005-09-08 21:58:08.186382500 +0200
891 @@ -0,0 +1,20 @@
892 +#include "byte.h"
893 +#include "dns.h"
894 +
895 +/* XXX: sort servers by configurable notion of closeness? */
896 +/* XXX: pay attention to competence of each server? */
897 +
898 +void dns_sortip6(char *s,unsigned int n)
899 +{
900 + unsigned int i;
901 + char tmp[16];
902 +
903 + n >>= 4;
904 + while (n > 1) {
905 + i = dns_random(n);
906 + --n;
907 + byte_copy(tmp,16,s + (i << 4));
908 + byte_copy(s + (i << 4),16,s + (n << 4));
909 + byte_copy(s + (n << 4),16,tmp);
910 + }
911 +}
912 diff -uNr djbdns-1.05/dns_transmit.c djbdns-1.05-ipv6/dns_transmit.c
913 --- djbdns-1.05/dns_transmit.c 2001-02-11 22:11:45.000000000 +0100
914 +++ djbdns-1.05-ipv6/dns_transmit.c 2005-09-08 21:58:08.186382500 +0200
915 @@ -7,6 +7,7 @@
916 #include "byte.h"
917 #include "uint16.h"
918 #include "dns.h"
919 +#include "ip6.h"
920
921 static int serverwantstcp(const char *buf,unsigned int len)
922 {
923 @@ -85,9 +86,9 @@
924 int j;
925
926 for (j = 0;j < 10;++j)
927 - if (socket_bind4(d->s1 - 1,d->localip,1025 + dns_random(64510)) == 0)
928 + if (socket_bind6(d->s1 - 1,d->localip,1025 + dns_random(64510),d->scope_id) == 0)
929 return 0;
930 - if (socket_bind4(d->s1 - 1,d->localip,0) == 0)
931 + if (socket_bind6(d->s1 - 1,d->localip,0,d->scope_id) == 0)
932 return 0;
933 return -1;
934 }
935 @@ -102,16 +103,16 @@
936
937 while (d->udploop < 4) {
938 for (;d->curserver < 16;++d->curserver) {
939 - ip = d->servers + 4 * d->curserver;
940 - if (byte_diff(ip,4,"\0\0\0\0")) {
941 + ip = d->servers + 16 * d->curserver;
942 + if (byte_diff(ip,16,V6any)) {
943 d->query[2] = dns_random(256);
944 d->query[3] = dns_random(256);
945
946 - d->s1 = 1 + socket_udp();
947 + d->s1 = 1 + socket_udp6();
948 if (!d->s1) { dns_transmit_free(d); return -1; }
949 if (randombind(d) == -1) { dns_transmit_free(d); return -1; }
950
951 - if (socket_connect4(d->s1 - 1,ip,53) == 0)
952 + if (socket_connect6(d->s1 - 1,ip,53,d->scope_id) == 0)
953 if (send(d->s1 - 1,d->query + 2,d->querylen - 2,0) == d->querylen - 2) {
954 struct taia now;
955 taia_now(&now);
956 @@ -153,19 +154,19 @@
957 packetfree(d);
958
959 for (;d->curserver < 16;++d->curserver) {
960 - ip = d->servers + 4 * d->curserver;
961 - if (byte_diff(ip,4,"\0\0\0\0")) {
962 + ip = d->servers + 16 * d->curserver;
963 + if (byte_diff(ip,16,V6any)) {
964 d->query[2] = dns_random(256);
965 d->query[3] = dns_random(256);
966
967 - d->s1 = 1 + socket_tcp();
968 + d->s1 = 1 + socket_tcp6();
969 if (!d->s1) { dns_transmit_free(d); return -1; }
970 if (randombind(d) == -1) { dns_transmit_free(d); return -1; }
971
972 taia_now(&now);
973 taia_uint(&d->deadline,10);
974 taia_add(&d->deadline,&d->deadline,&now);
975 - if (socket_connect4(d->s1 - 1,ip,53) == 0) {
976 + if (socket_connect6(d->s1 - 1,ip,53,d->scope_id) == 0) {
977 d->tcpstate = 2;
978 return 0;
979 }
980 @@ -193,7 +194,7 @@
981 return thistcp(d);
982 }
983
984 -int dns_transmit_start(struct dns_transmit *d,const char servers[64],int flagrecursive,const char *q,const char qtype[2],const char localip[4])
985 +int dns_transmit_start(struct dns_transmit *d,const char servers[256],int flagrecursive,const char *q,const char qtype[2],const char localip[16])
986 {
987 unsigned int len;
988
989 @@ -213,7 +214,7 @@
990
991 byte_copy(d->qtype,2,qtype);
992 d->servers = servers;
993 - byte_copy(d->localip,4,localip);
994 + byte_copy(d->localip,16,localip);
995
996 d->udploop = flagrecursive ? 1 : 0;
997
998 diff -uNr djbdns-1.05/dnscache.c djbdns-1.05-ipv6/dnscache.c
999 --- djbdns-1.05/dnscache.c 2001-02-11 22:11:45.000000000 +0100
1000 +++ djbdns-1.05-ipv6/dnscache.c 2005-09-08 21:58:08.190382750 +0200
1001 @@ -5,6 +5,7 @@
1002 #include "strerr.h"
1003 #include "error.h"
1004 #include "ip4.h"
1005 +#include "ip6.h"
1006 #include "uint16.h"
1007 #include "uint64.h"
1008 #include "socket.h"
1009 @@ -23,6 +24,10 @@
1010 #include "okclient.h"
1011 #include "droproot.h"
1012
1013 +long interface;
1014 +
1015 +stralloc ignoreip = {0};
1016 +
1017 static int packetquery(char *buf,unsigned int len,char **q,char qtype[2],char qclass[2],char id[2])
1018 {
1019 unsigned int pos;
1020 @@ -46,8 +51,8 @@
1021 }
1022
1023
1024 -static char myipoutgoing[4];
1025 -static char myipincoming[4];
1026 +static char myipoutgoing[16];
1027 +static char myipincoming[16];
1028 static char buf[1024];
1029 uint64 numqueries = 0;
1030
1031 @@ -60,9 +65,10 @@
1032 struct taia start;
1033 uint64 active; /* query number, if active; otherwise 0 */
1034 iopause_fd *io;
1035 - char ip[4];
1036 + char ip[16];
1037 uint16 port;
1038 char id[2];
1039 + uint32 scope_id;
1040 } u[MAXUDP];
1041 int uactive = 0;
1042
1043 @@ -78,7 +84,7 @@
1044 if (!u[j].active) return;
1045 response_id(u[j].id);
1046 if (response_len > 512) response_tc();
1047 - socket_send4(udp53,response,response_len,u[j].ip,u[j].port);
1048 + socket_send6(udp53,response,response_len,u[j].ip,u[j].port,u[j].scope_id);
1049 log_querydone(&u[j].active,response_len);
1050 u[j].active = 0; --uactive;
1051 }
1052 @@ -109,7 +115,7 @@
1053 x = u + j;
1054 taia_now(&x->start);
1055
1056 - len = socket_recv4(udp53,buf,sizeof buf,x->ip,&x->port);
1057 + len = socket_recv6(udp53,buf,sizeof buf,x->ip,&x->port,&x->scope_id);
1058 if (len == -1) return;
1059 if (len >= sizeof buf) return;
1060 if (x->port < 1024) if (x->port != 53) return;
1061 @@ -119,7 +125,7 @@
1062
1063 x->active = ++numqueries; ++uactive;
1064 log_query(&x->active,x->ip,x->port,x->id,q,qtype);
1065 - switch(query_start(&x->q,q,qtype,qclass,myipoutgoing)) {
1066 + switch(query_start(&x->q,q,qtype,qclass,myipoutgoing,interface)) {
1067 case -1:
1068 u_drop(j);
1069 return;
1070 @@ -128,7 +134,6 @@
1071 }
1072 }
1073
1074 -
1075 static int tcp53;
1076
1077 #define MAXTCP 20
1078 @@ -138,7 +143,7 @@
1079 struct taia timeout;
1080 uint64 active; /* query number or 1, if active; otherwise 0 */
1081 iopause_fd *io;
1082 - char ip[4]; /* send response to this address */
1083 + char ip[16]; /* send response to this address */
1084 uint16 port; /* send response to this port */
1085 char id[2];
1086 int tcp; /* open TCP socket, if active */
1087 @@ -146,6 +151,7 @@
1088 char *buf; /* 0, or dynamically allocated of length len */
1089 unsigned int len;
1090 unsigned int pos;
1091 + uint32 scope_id;
1092 } t[MAXTCP];
1093 int tactive = 0;
1094
1095 @@ -254,7 +260,7 @@
1096
1097 x->active = ++numqueries;
1098 log_query(&x->active,x->ip,x->port,x->id,q,qtype);
1099 - switch(query_start(&x->q,q,qtype,qclass,myipoutgoing)) {
1100 + switch(query_start(&x->q,q,qtype,qclass,myipoutgoing,interface)) {
1101 case -1:
1102 t_drop(j);
1103 return;
1104 @@ -291,7 +297,7 @@
1105 x = t + j;
1106 taia_now(&x->start);
1107
1108 - x->tcp = socket_accept4(tcp53,x->ip,&x->port);
1109 + x->tcp = socket_accept6(tcp53,x->ip,&x->port,&x->scope_id);
1110 if (x->tcp == -1) return;
1111 if (x->port < 1024) if (x->port != 53) { close(x->tcp); return; }
1112 if (!okclient(x->ip)) { close(x->tcp); return; }
1113 @@ -389,24 +395,36 @@
1114 int main()
1115 {
1116 char *x;
1117 + unsigned int i, j, k;
1118 unsigned long cachesize;
1119 + static stralloc sa = {0};
1120 +
1121 + x = env_get("INTERFACE");
1122 + if (x) scan_ulong(x,&interface);
1123
1124 x = env_get("IP");
1125 if (!x)
1126 strerr_die2x(111,FATAL,"$IP not set");
1127 - if (!ip4_scan(x,myipincoming))
1128 + if (!ip6_scan(x,myipincoming))
1129 strerr_die3x(111,FATAL,"unable to parse IP address ",x);
1130
1131 - udp53 = socket_udp();
1132 +#if 0
1133 + /* if if IP is a mapped-IPv4 address, disable IPv6 functionality */
1134 + /* this is actually a bad idea */
1135 + if (ip6_isv4mapped(myipincoming))
1136 + noipv6 = 1;
1137 +#endif
1138 +
1139 + udp53 = socket_udp6();
1140 if (udp53 == -1)
1141 strerr_die2sys(111,FATAL,"unable to create UDP socket: ");
1142 - if (socket_bind4_reuse(udp53,myipincoming,53) == -1)
1143 + if (socket_bind6_reuse(udp53,myipincoming,53,interface) == -1)
1144 strerr_die2sys(111,FATAL,"unable to bind UDP socket: ");
1145
1146 - tcp53 = socket_tcp();
1147 + tcp53 = socket_tcp6();
1148 if (tcp53 == -1)
1149 strerr_die2sys(111,FATAL,"unable to create TCP socket: ");
1150 - if (socket_bind4_reuse(tcp53,myipincoming,53) == -1)
1151 + if (socket_bind6_reuse(tcp53,myipincoming,53,interface) == -1)
1152 strerr_die2sys(111,FATAL,"unable to bind TCP socket: ");
1153
1154 droproot(FATAL);
1155 @@ -421,7 +439,7 @@
1156 x = env_get("IPSEND");
1157 if (!x)
1158 strerr_die2x(111,FATAL,"$IPSEND not set");
1159 - if (!ip4_scan(x,myipoutgoing))
1160 + if (!ip6_scan(x,myipoutgoing))
1161 strerr_die3x(111,FATAL,"unable to parse IP address ",x);
1162
1163 x = env_get("CACHESIZE");
1164 @@ -431,6 +449,20 @@
1165 if (!cache_init(cachesize))
1166 strerr_die3x(111,FATAL,"not enough memory for cache of size ",x);
1167
1168 + if (openreadclose("ignoreip",&sa,64) < 0)
1169 + strerr_die2x(111,FATAL,"trouble reading ignoreip");
1170 + for(j = k = i = 0; i < sa.len; i++)
1171 + if (sa.s[i] == '\n') {
1172 + sa.s[i] = '\0';
1173 + if (!stralloc_readyplus(&ignoreip,16))
1174 + strerr_die2x(111,FATAL,"out of memory parsing ignoreip");
1175 + if (!ip6_scan(sa.s+k,ignoreip.s+j))
1176 + strerr_die3x(111,FATAL,"unable to parse address in ignoreip ",ignoreip.s+k);
1177 + j += 16;
1178 + k = i + 1;
1179 + }
1180 + ignoreip.len = j;
1181 +
1182 if (env_get("HIDETTL"))
1183 response_hidettl();
1184 if (env_get("FORWARDONLY"))
1185 diff -uNr djbdns-1.05/dnsfilter.c djbdns-1.05-ipv6/dnsfilter.c
1186 --- djbdns-1.05/dnsfilter.c 2001-02-11 22:11:45.000000000 +0100
1187 +++ djbdns-1.05-ipv6/dnsfilter.c 2005-09-08 21:58:08.190382750 +0200
1188 @@ -12,6 +12,7 @@
1189 #include "iopause.h"
1190 #include "error.h"
1191 #include "exit.h"
1192 +#include "ip6.h"
1193
1194 #define FATAL "dnsfilter: fatal: "
1195
1196 @@ -44,7 +45,7 @@
1197 iopause_fd *io;
1198 int iolen;
1199
1200 -char servers[64];
1201 +char servers[256];
1202 char ip[4];
1203 char name[DNS_NAME4_DOMAIN];
1204
1205 @@ -191,7 +192,7 @@
1206 dns_name4_domain(name,ip);
1207 if (dns_resolvconfip(servers) == -1)
1208 strerr_die2sys(111,FATAL,"unable to read /etc/resolv.conf: ");
1209 - if (dns_transmit_start(&x[xnum].dt,servers,1,name,DNS_T_PTR,"\0\0\0\0") == -1)
1210 + if (dns_transmit_start(&x[xnum].dt,servers,1,name,DNS_T_PTR,V6any) == -1)
1211 errout(xnum);
1212 else {
1213 x[xnum].flagactive = 1;
1214 diff -uNr djbdns-1.05/dnsip6.c djbdns-1.05-ipv6/dnsip6.c
1215 --- djbdns-1.05/dnsip6.c 1970-01-01 01:00:00.000000000 +0100
1216 +++ djbdns-1.05-ipv6/dnsip6.c 2005-09-08 21:58:08.190382750 +0200
1217 @@ -0,0 +1,40 @@
1218 +#include "buffer.h"
1219 +#include "exit.h"
1220 +#include "strerr.h"
1221 +#include "ip6.h"
1222 +#include "dns.h"
1223 +
1224 +#define FATAL "dnsip: fatal: "
1225 +
1226 +static char seed[128];
1227 +
1228 +static stralloc fqdn;
1229 +static stralloc out;
1230 +char str[IP6_FMT];
1231 +
1232 +main(int argc,char **argv)
1233 +{
1234 + int i;
1235 +
1236 + dns_random_init(seed);
1237 +
1238 + if (*argv) ++argv;
1239 +
1240 + while (*argv) {
1241 + if (!stralloc_copys(&fqdn,*argv))
1242 + strerr_die2x(111,FATAL,"out of memory");
1243 + if (dns_ip6(&out,&fqdn) == -1)
1244 + strerr_die4sys(111,FATAL,"unable to find IPv6 address for ",*argv,": ");
1245 +
1246 + for (i = 0;i + 16 <= out.len;i += 16) {
1247 + buffer_put(buffer_1,str,ip6_fmt(str,out.s + i));
1248 + buffer_puts(buffer_1," ");
1249 + }
1250 + buffer_puts(buffer_1,"\n");
1251 +
1252 + ++argv;
1253 + }
1254 +
1255 + buffer_flush(buffer_1);
1256 + _exit(0);
1257 +}
1258 diff -uNr djbdns-1.05/dnsip6q.c djbdns-1.05-ipv6/dnsip6q.c
1259 --- djbdns-1.05/dnsip6q.c 1970-01-01 01:00:00.000000000 +0100
1260 +++ djbdns-1.05-ipv6/dnsip6q.c 2005-09-08 21:58:08.194383000 +0200
1261 @@ -0,0 +1,43 @@
1262 +#include "buffer.h"
1263 +#include "exit.h"
1264 +#include "strerr.h"
1265 +#include "ip6.h"
1266 +#include "dns.h"
1267 +
1268 +#define FATAL "dnsipq: fatal: "
1269 +
1270 +static char seed[128];
1271 +
1272 +static stralloc in;
1273 +static stralloc fqdn;
1274 +static stralloc out;
1275 +char str[IP6_FMT];
1276 +
1277 +int main(int argc,char **argv)
1278 +{
1279 + int i;
1280 +
1281 + dns_random_init(seed);
1282 +
1283 + if (*argv) ++argv;
1284 +
1285 + while (*argv) {
1286 + if (!stralloc_copys(&in,*argv))
1287 + strerr_die2x(111,FATAL,"out of memory");
1288 + if (dns_ip6_qualify(&out,&fqdn,&in) == -1)
1289 + strerr_die4sys(111,FATAL,"unable to find IP6 address for ",*argv,": ");
1290 +
1291 + buffer_put(buffer_1,fqdn.s,fqdn.len);
1292 + buffer_puts(buffer_1," ");
1293 + for (i = 0;i + 16 <= out.len;i += 16) {
1294 + buffer_put(buffer_1,str,ip6_fmt(str,out.s + i));
1295 + buffer_puts(buffer_1," ");
1296 + }
1297 + buffer_puts(buffer_1,"\n");
1298 +
1299 + ++argv;
1300 + }
1301 +
1302 + buffer_flush(buffer_1);
1303 + _exit(0);
1304 +}
1305 diff -uNr djbdns-1.05/dnsname.c djbdns-1.05-ipv6/dnsname.c
1306 --- djbdns-1.05/dnsname.c 2001-02-11 22:11:45.000000000 +0100
1307 +++ djbdns-1.05-ipv6/dnsname.c 2005-09-08 21:58:08.194383000 +0200
1308 @@ -2,6 +2,7 @@
1309 #include "exit.h"
1310 #include "strerr.h"
1311 #include "ip4.h"
1312 +#include "ip6.h"
1313 #include "dns.h"
1314
1315 #define FATAL "dnsname: fatal: "
1316 @@ -9,6 +10,7 @@
1317 static char seed[128];
1318
1319 char ip[4];
1320 +char ip6[16];
1321 static stralloc out;
1322
1323 int main(int argc,char **argv)
1324 @@ -18,10 +20,15 @@
1325 if (*argv) ++argv;
1326
1327 while (*argv) {
1328 - if (!ip4_scan(*argv,ip))
1329 - strerr_die3x(111,FATAL,"unable to parse IP address ",*argv);
1330 - if (dns_name4(&out,ip) == -1)
1331 - strerr_die4sys(111,FATAL,"unable to find host name for ",*argv,": ");
1332 + if (ip6_scan(*argv,ip6)) {
1333 + if (dns_name6(&out,ip6) == -1)
1334 + strerr_die4sys(111,FATAL,"unable to find host name for ",*argv,": ");
1335 + } else {
1336 + if (!ip4_scan(*argv,ip))
1337 + strerr_die3x(111,FATAL,"unable to parse IP address ",*argv);
1338 + if (dns_name4(&out,ip) == -1)
1339 + strerr_die4sys(111,FATAL,"unable to find host name for ",*argv,": ");
1340 + }
1341
1342 buffer_put(buffer_1,out.s,out.len);
1343 buffer_puts(buffer_1,"\n");
1344 diff -uNr djbdns-1.05/dnsq.c djbdns-1.05-ipv6/dnsq.c
1345 --- djbdns-1.05/dnsq.c 2001-02-11 22:11:45.000000000 +0100
1346 +++ djbdns-1.05-ipv6/dnsq.c 2005-09-08 21:58:08.198383250 +0200
1347 @@ -10,6 +10,7 @@
1348 #include "printpacket.h"
1349 #include "parsetype.h"
1350 #include "dns.h"
1351 +#include "ip6.h"
1352
1353 #define FATAL "dnsq: fatal: "
1354
1355 @@ -24,14 +25,14 @@
1356
1357 static struct dns_transmit tx;
1358
1359 -int resolve(char *q,char qtype[2],char servers[64])
1360 +int resolve(char *q,char qtype[2],char servers[256])
1361 {
1362 struct taia stamp;
1363 struct taia deadline;
1364 iopause_fd x[1];
1365 int r;
1366
1367 - if (dns_transmit_start(&tx,servers,0,q,qtype,"\0\0\0\0") == -1) return -1;
1368 + if (dns_transmit_start(&tx,servers,0,q,qtype,V6any) == -1) return -1;
1369
1370 for (;;) {
1371 taia_now(&stamp);
1372 @@ -47,7 +48,7 @@
1373 return 0;
1374 }
1375
1376 -char servers[64];
1377 +char servers[256];
1378 static stralloc ip;
1379 static stralloc fqdn;
1380
1381 @@ -73,9 +74,9 @@
1382
1383 if (!*++argv) usage();
1384 if (!stralloc_copys(&out,*argv)) oops();
1385 - if (dns_ip4_qualify(&ip,&fqdn,&out) == -1) oops();
1386 - if (ip.len >= 64) ip.len = 64;
1387 - byte_zero(servers,64);
1388 + if (dns_ip6_qualify(&ip,&fqdn,&out) == -1) oops();
1389 + if (ip.len >= 256) ip.len = 256;
1390 + byte_zero(servers,256);
1391 byte_copy(servers,ip.len,ip.s);
1392
1393 if (!stralloc_copys(&out,"")) oops();
1394 diff -uNr djbdns-1.05/dnstrace.c djbdns-1.05-ipv6/dnstrace.c
1395 --- djbdns-1.05/dnstrace.c 2001-02-11 22:11:45.000000000 +0100
1396 +++ djbdns-1.05-ipv6/dnstrace.c 2005-09-08 21:58:08.198383250 +0200
1397 @@ -4,6 +4,7 @@
1398 #include "str.h"
1399 #include "byte.h"
1400 #include "ip4.h"
1401 +#include "ip6.h"
1402 #include "gen_alloc.h"
1403 #include "gen_allocdefs.h"
1404 #include "exit.h"
1405 @@ -30,7 +31,7 @@
1406 }
1407
1408 static stralloc querystr;
1409 -char ipstr[IP4_FMT];
1410 +char ipstr[IP6_FMT];
1411 static stralloc tmp;
1412
1413 void printdomain(const char *d)
1414 @@ -42,19 +43,19 @@
1415
1416 static struct dns_transmit tx;
1417
1418 -int resolve(char *q,char qtype[2],char ip[4])
1419 +int resolve(char *q,char qtype[2],char ip[16])
1420 {
1421 struct taia start;
1422 struct taia stamp;
1423 struct taia deadline;
1424 - char servers[64];
1425 + char servers[256];
1426 iopause_fd x[1];
1427 int r;
1428
1429 taia_now(&start);
1430
1431 - byte_zero(servers,64);
1432 - byte_copy(servers,4,ip);
1433 + byte_zero(servers,256);
1434 + byte_copy(servers,16,ip);
1435
1436 if (dns_transmit_start(&tx,servers,0,q,qtype,"\0\0\0\0") == -1) return -1;
1437
1438 @@ -82,7 +83,7 @@
1439
1440 struct address {
1441 char *owner;
1442 - char ip[4];
1443 + char ip[16];
1444 } ;
1445
1446 GEN_ALLOC_typedef(address_alloc,struct address,s,len,a)
1447 @@ -117,7 +118,7 @@
1448 char *owner;
1449 char type[2];
1450 char *control;
1451 - char ip[4];
1452 + char ip[16];
1453 } ;
1454
1455 GEN_ALLOC_typedef(qt_alloc,struct qt,s,len,a)
1456 @@ -126,7 +127,7 @@
1457
1458 static qt_alloc qt;
1459
1460 -void qt_add(const char *q,const char type[2],const char *control,const char ip[4])
1461 +void qt_add(const char *q,const char type[2],const char *control,const char ip[16])
1462 {
1463 struct qt x;
1464 int i;
1465 @@ -137,14 +138,14 @@
1466 if (dns_domain_equal(qt.s[i].owner,q))
1467 if (dns_domain_equal(qt.s[i].control,control))
1468 if (byte_equal(qt.s[i].type,2,type))
1469 - if (byte_equal(qt.s[i].ip,4,ip))
1470 + if (byte_equal(qt.s[i].ip,16,ip))
1471 return;
1472
1473 byte_zero(&x,sizeof x);
1474 if (!dns_domain_copy(&x.owner,q)) nomem();
1475 if (!dns_domain_copy(&x.control,control)) nomem();
1476 byte_copy(x.type,2,type);
1477 - byte_copy(x.ip,4,ip);
1478 + byte_copy(x.ip,16,ip);
1479 if (!qt_alloc_append(&qt,&x)) nomem();
1480 }
1481
1482 @@ -203,7 +204,7 @@
1483 qt_add(query.s[i].owner,query.s[i].type,owner,address.s[j].ip);
1484 }
1485
1486 -void address_add(const char *owner,const char ip[4])
1487 +void address_add(const char *owner,const char ip[16])
1488 {
1489 struct address x;
1490 int i;
1491 @@ -213,17 +214,20 @@
1492 buffer_puts(buffer_1,"A:");
1493 printdomain(owner);
1494 buffer_puts(buffer_1,":");
1495 - buffer_put(buffer_1,ipstr,ip4_fmt(ipstr,ip));
1496 + if (ip6_isv4mapped(ip))
1497 + buffer_put(buffer_1,ipstr,ip4_fmt(ipstr,ip+12));
1498 + else
1499 + buffer_put(buffer_1,ipstr,ip6_fmt(ipstr,ip));
1500 buffer_puts(buffer_1,"\n");
1501
1502 for (i = 0;i < address.len;++i)
1503 if (dns_domain_equal(address.s[i].owner,owner))
1504 - if (byte_equal(address.s[i].ip,4,ip))
1505 + if (byte_equal(address.s[i].ip,16,ip))
1506 return;
1507
1508 byte_zero(&x,sizeof x);
1509 if (!dns_domain_copy(&x.owner,owner)) nomem();
1510 - byte_copy(x.ip,4,ip);
1511 + byte_copy(x.ip,16,ip);
1512 if (!address_alloc_append(&address,&x)) nomem();
1513
1514 for (i = 0;i < ns.len;++i)
1515 @@ -331,7 +335,12 @@
1516 ns_add(t1,t2);
1517 }
1518 else if (typematch(header,DNS_T_A) && datalen == 4) {
1519 - if (!dns_packet_copy(buf,len,pos,misc,4)) goto DIE;
1520 + if (!dns_packet_copy(buf,len,pos,misc+12,4)) goto DIE;
1521 + byte_copy(misc,12,V4mappedprefix);
1522 + address_add(t1,misc);
1523 + }
1524 + else if (typematch(header,DNS_T_AAAA) && datalen == 16) {
1525 + if (!dns_packet_copy(buf,len,pos,misc,16)) goto DIE;
1526 address_add(t1,misc);
1527 }
1528 }
1529 @@ -419,8 +428,8 @@
1530
1531 while (*++argv) {
1532 if (!stralloc_copys(&udn,*argv)) nomem();
1533 - if (dns_ip4_qualify(&out,&fqdn,&udn) == -1) nomem(); /* XXX */
1534 - for (i = 0;i + 4 <= out.len;i += 4)
1535 + if (dns_ip6_qualify(&out,&fqdn,&udn) == -1) nomem(); /* XXX */
1536 + for (i = 0;i + 16 <= out.len;i += 16)
1537 address_add("",out.s + i);
1538 }
1539
1540 @@ -429,7 +438,7 @@
1541 control = qt.s[i].control;
1542 if (!dns_domain_suffix(q,control)) continue;
1543 byte_copy(type,2,qt.s[i].type);
1544 - byte_copy(ip,4,qt.s[i].ip);
1545 + byte_copy(ip,16,qt.s[i].ip);
1546
1547 if (!stralloc_copys(&querystr,"")) nomem();
1548 uint16_unpack_big(type,&u16);
1549 @@ -439,7 +448,10 @@
1550 if (!stralloc_cats(&querystr,":")) nomem();
1551 if (!dns_domain_todot_cat(&querystr,control)) nomem();
1552 if (!stralloc_cats(&querystr,":")) nomem();
1553 - if (!stralloc_catb(&querystr,ipstr,ip4_fmt(ipstr,ip))) nomem();
1554 + if (ip6_isv4mapped(ip)) {
1555 + if (!stralloc_catb(&querystr,ipstr,ip4_fmt(ipstr,ip+12))) nomem();
1556 + } else
1557 + if (!stralloc_catb(&querystr,ipstr,ip6_fmt(ipstr,ip))) nomem();
1558 if (!stralloc_cats(&querystr,":")) nomem();
1559
1560 buffer_put(buffer_1,querystr.s,querystr.len);
1561 diff -uNr djbdns-1.05/error.h djbdns-1.05-ipv6/error.h
1562 --- djbdns-1.05/error.h 2001-02-11 22:11:45.000000000 +0100
1563 +++ djbdns-1.05-ipv6/error.h 2005-09-08 21:58:08.198383250 +0200
1564 @@ -1,7 +1,7 @@
1565 #ifndef ERROR_H
1566 #define ERROR_H
1567
1568 -extern int errno;
1569 +#include <errno.h>
1570
1571 extern int error_intr;
1572 extern int error_nomem;
1573 diff -uNr djbdns-1.05/fmt_xlong.c djbdns-1.05-ipv6/fmt_xlong.c
1574 --- djbdns-1.05/fmt_xlong.c 1970-01-01 01:00:00.000000000 +0100
1575 +++ djbdns-1.05-ipv6/fmt_xlong.c 2005-09-08 21:58:08.202383500 +0200
1576 @@ -0,0 +1,22 @@
1577 +#include "fmt.h"
1578 +
1579 +char tohex(char num) {
1580 + if (num<10)
1581 + return num+'0';
1582 + else if (num<16)
1583 + return num-10+'a';
1584 + else
1585 + return -1;
1586 +}
1587 +
1588 +unsigned int fmt_xlong(register char *s,register unsigned long u)
1589 +{
1590 + register unsigned int len; register unsigned long q;
1591 + len = 1; q = u;
1592 + while (q > 15) { ++len; q /= 16; }
1593 + if (s) {
1594 + s += len;
1595 + do { *--s = tohex(u % 16); u /= 16; } while(u); /* handles u == 0 */
1596 + }
1597 + return len;
1598 +}
1599 diff -uNr djbdns-1.05/haveip6.h1 djbdns-1.05-ipv6/haveip6.h1
1600 --- djbdns-1.05/haveip6.h1 1970-01-01 01:00:00.000000000 +0100
1601 +++ djbdns-1.05-ipv6/haveip6.h1 2005-09-08 21:58:08.202383500 +0200
1602 @@ -0,0 +1 @@
1603 +
1604 diff -uNr djbdns-1.05/haveip6.h2 djbdns-1.05-ipv6/haveip6.h2
1605 --- djbdns-1.05/haveip6.h2 1970-01-01 01:00:00.000000000 +0100
1606 +++ djbdns-1.05-ipv6/haveip6.h2 2005-09-08 21:58:08.202383500 +0200
1607 @@ -0,0 +1 @@
1608 +#define LIBC_HAS_IP6 1
1609 diff -uNr djbdns-1.05/haven2i.h1 djbdns-1.05-ipv6/haven2i.h1
1610 --- djbdns-1.05/haven2i.h1 1970-01-01 01:00:00.000000000 +0100
1611 +++ djbdns-1.05-ipv6/haven2i.h1 2005-09-08 21:58:08.206383750 +0200
1612 @@ -0,0 +1 @@
1613 +#undef HAVE_N2I
1614 diff -uNr djbdns-1.05/haven2i.h2 djbdns-1.05-ipv6/haven2i.h2
1615 --- djbdns-1.05/haven2i.h2 1970-01-01 01:00:00.000000000 +0100
1616 +++ djbdns-1.05-ipv6/haven2i.h2 2005-09-08 21:58:08.206383750 +0200
1617 @@ -0,0 +1 @@
1618 +#define HAVE_N2I
1619 diff -uNr djbdns-1.05/hier.c djbdns-1.05-ipv6/hier.c
1620 --- djbdns-1.05/hier.c 2001-02-11 22:11:45.000000000 +0100
1621 +++ djbdns-1.05-ipv6/hier.c 2005-09-08 21:58:08.206383750 +0200
1622 @@ -29,7 +29,9 @@
1623 c(auto_home,"bin","axfr-get",-1,-1,0755);
1624
1625 c(auto_home,"bin","dnsip",-1,-1,0755);
1626 + c(auto_home,"bin","dnsip6",-1,-1,0755);
1627 c(auto_home,"bin","dnsipq",-1,-1,0755);
1628 + c(auto_home,"bin","dnsip6q",-1,-1,0755);
1629 c(auto_home,"bin","dnsname",-1,-1,0755);
1630 c(auto_home,"bin","dnstxt",-1,-1,0755);
1631 c(auto_home,"bin","dnsmx",-1,-1,0755);
1632 diff -uNr djbdns-1.05/ip6.h djbdns-1.05-ipv6/ip6.h
1633 --- djbdns-1.05/ip6.h 1970-01-01 01:00:00.000000000 +0100
1634 +++ djbdns-1.05-ipv6/ip6.h 2005-09-08 21:58:08.210384000 +0200
1635 @@ -0,0 +1,28 @@
1636 +#ifndef IP6_H
1637 +#define IP6_H
1638 +
1639 +extern unsigned int ip6_scan(const char *,char *);
1640 +extern unsigned int ip6_fmt(char *,const char *);
1641 +
1642 +extern unsigned int ip6_scan_flat(const char *,char *);
1643 +extern unsigned int ip6_fmt_flat(char *,char *);
1644 +
1645 +/*
1646 + ip6 address syntax: (h = hex digit), no leading '0' required
1647 + 1. hhhh:hhhh:hhhh:hhhh:hhhh:hhhh:hhhh:hhhh
1648 + 2. any number of 0000 may be abbreviated as "::", but only once
1649 + flat ip6 address syntax:
1650 + hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
1651 + */
1652 +
1653 +#define IP6_FMT 40
1654 +
1655 +const static unsigned char V4mappedprefix[12]={0,0,0,0,0,0,0,0,0,0,0xff,0xff};
1656 +const static unsigned char V6loopback[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
1657 +const static unsigned char V6any[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
1658 +
1659 +#define ip6_isv4mapped(ip) (byte_equal(ip,12,V4mappedprefix))
1660 +
1661 +const static char ip4loopback[4] = {127,0,0,1};
1662 +
1663 +#endif
1664 diff -uNr djbdns-1.05/ip6_fmt.c djbdns-1.05-ipv6/ip6_fmt.c
1665 --- djbdns-1.05/ip6_fmt.c 1970-01-01 01:00:00.000000000 +0100
1666 +++ djbdns-1.05-ipv6/ip6_fmt.c 2005-09-08 21:58:08.210384000 +0200
1667 @@ -0,0 +1,60 @@
1668 +#include "fmt.h"
1669 +#include "byte.h"
1670 +#include "ip4.h"
1671 +#include "ip6.h"
1672 +#include <stdio.h>
1673 +
1674 +extern char tohex(char num);
1675 +
1676 +unsigned int ip6_fmt(char *s,const char ip[16])
1677 +{
1678 + unsigned int len;
1679 + unsigned int i;
1680 + unsigned int temp;
1681 + unsigned int compressing;
1682 + unsigned int compressed;
1683 + int j;
1684 +
1685 + len = 0; compressing = 0; compressed = 0;
1686 + for (j=0; j<16; j+=2) {
1687 + if (j==12 && ip6_isv4mapped(ip)) {
1688 + temp=ip4_fmt(s,ip+12);
1689 + len+=temp;
1690 + break;
1691 + }
1692 + temp = ((unsigned long) (unsigned char) ip[j] << 8) +
1693 + (unsigned long) (unsigned char) ip[j+1];
1694 + if (temp == 0 && !compressed) {
1695 + if (!compressing) {
1696 + compressing=1;
1697 + if (j==0) {
1698 + if (s) *s++=':'; ++len;
1699 + }
1700 + }
1701 + } else {
1702 + if (compressing) {
1703 + compressing=0; ++compressed;
1704 + if (s) *s++=':'; ++len;
1705 + }
1706 + i = fmt_xlong(s,temp); len += i; if (s) s += i;
1707 + if (j<14) {
1708 + if (s) *s++ = ':';
1709 + ++len;
1710 + }
1711 + }
1712 + }
1713 + if (compressing) { *s++=':'; ++len; }
1714 +
1715 +/* if (s) *s=0; */
1716 + return len;
1717 +}
1718 +
1719 +unsigned int ip6_fmt_flat(char *s,char ip[16])
1720 +{
1721 + int i;
1722 + for (i=0; i<16; i++) {
1723 + *s++=tohex((unsigned char)ip[i] >> 4);
1724 + *s++=tohex((unsigned char)ip[i] & 15);
1725 + }
1726 + return 32;
1727 +}
1728 diff -uNr djbdns-1.05/ip6_scan.c djbdns-1.05-ipv6/ip6_scan.c
1729 --- djbdns-1.05/ip6_scan.c 1970-01-01 01:00:00.000000000 +0100
1730 +++ djbdns-1.05-ipv6/ip6_scan.c 2005-09-08 21:58:08.214384250 +0200
1731 @@ -0,0 +1,115 @@
1732 +#include "scan.h"
1733 +#include "ip4.h"
1734 +#include "ip6.h"
1735 +#include "byte.h"
1736 +
1737 +/*
1738 + * IPv6 addresses are really ugly to parse.
1739 + * Syntax: (h = hex digit)
1740 + * 1. hhhh:hhhh:hhhh:hhhh:hhhh:hhhh:hhhh:hhhh
1741 + * 2. any number of 0000 may be abbreviated as "::", but only once
1742 + * 3. The last two words may be written as IPv4 address
1743 + */
1744 +
1745 +unsigned int ip6_scan(const char *s,char ip[16])
1746 +{
1747 + unsigned int i;
1748 + unsigned int len=0;
1749 + unsigned long u;
1750 +
1751 + char suffix[16];
1752 + int prefixlen=0;
1753 + int suffixlen=0;
1754 +
1755 + if ((i=ip4_scan(s,ip+12))) {
1756 + const char *c=V4mappedprefix;
1757 + if (byte_equal(ip+12,4,V6any)) c=V6any;
1758 + for (len=0; len<12; ++len) ip[len]=c[len];
1759 + return i;
1760 + }
1761 + for (i=0; i<16; i++) ip[i]=0;
1762 + for (;;) {
1763 + if (*s == ':') {
1764 + len++;
1765 + if (s[1] == ':') { /* Found "::", skip to part 2 */
1766 + s+=2;
1767 + len++;
1768 + break;
1769 + }
1770 + s++;
1771 + }
1772 + i = scan_xlong(s,&u);
1773 + if (!i) return 0;
1774 + if (prefixlen==12 && s[i]=='.') {
1775 + /* the last 4 bytes may be written as IPv4 address */
1776 + i=ip4_scan(s,ip+12);
1777 + if (i)
1778 + return i+len;
1779 + else
1780 + return 0;
1781 + }
1782 + ip[prefixlen++] = (u >> 8);
1783 + ip[prefixlen++] = (u & 255);
1784 + s += i; len += i;
1785 + if (prefixlen==16)
1786 + return len;
1787 + }
1788 +
1789 +/* part 2, after "::" */
1790 + for (;;) {
1791 + if (*s == ':') {
1792 + if (suffixlen==0)
1793 + break;
1794 + s++;
1795 + len++;
1796 + } else if (suffixlen!=0)
1797 + break;
1798 + i = scan_xlong(s,&u);
1799 + if (!i) {
1800 + len--;
1801 + break;
1802 + }
1803 + if (suffixlen+prefixlen<=12 && s[i]=='.') {
1804 + int j=ip4_scan(s,suffix+suffixlen);
1805 + if (j) {
1806 + suffixlen+=4;
1807 + len+=j;
1808 + break;
1809 + } else
1810 + prefixlen=12-suffixlen; /* make end-of-loop test true */
1811 + }
1812 + suffix[suffixlen++] = (u >> 8);
1813 + suffix[suffixlen++] = (u & 255);
1814 + s += i; len += i;
1815 + if (prefixlen+suffixlen==16)
1816 + break;
1817 + }
1818 + for (i=0; i<suffixlen; i++)
1819 + ip[16-suffixlen+i] = suffix[i];
1820 + return len;
1821 +}
1822 +
1823 +static long int fromhex(unsigned char c) {
1824 + if (c>='0' && c<='9')
1825 + return c-'0';
1826 + else if (c>='A' && c<='F')
1827 + return c-'A'+10;
1828 + else if (c>='a' && c<='f')
1829 + return c-'a'+10;
1830 + return -1;
1831 +}
1832 +
1833 +unsigned int ip6_scan_flat(const char *s,char ip[16])
1834 +{
1835 + int i;
1836 + for (i=0; i<16; i++) {
1837 + int tmp;
1838 + tmp=fromhex(*s++);
1839 + if (tmp<0) return 0;
1840 + ip[i]=tmp << 4;
1841 + tmp=fromhex(*s++);
1842 + if (tmp<0) return 0;
1843 + ip[i]+=tmp;
1844 + }
1845 + return 32;
1846 +}
1847 diff -uNr djbdns-1.05/log.c djbdns-1.05-ipv6/log.c
1848 --- djbdns-1.05/log.c 2001-02-11 22:11:45.000000000 +0100
1849 +++ djbdns-1.05-ipv6/log.c 2005-09-08 21:58:08.214384250 +0200
1850 @@ -3,6 +3,7 @@
1851 #include "uint16.h"
1852 #include "error.h"
1853 #include "byte.h"
1854 +#include "ip6.h"
1855 #include "log.h"
1856
1857 /* work around gcc 2.95.2 bug */
1858 @@ -45,12 +46,10 @@
1859 string(" ");
1860 }
1861
1862 -static void ip(const char i[4])
1863 +static void ip(const char i[16])
1864 {
1865 - hex(i[0]);
1866 - hex(i[1]);
1867 - hex(i[2]);
1868 - hex(i[3]);
1869 + int j;
1870 + for (j=0; j<16; ++j) hex(i[j]);
1871 }
1872
1873 static void logid(const char id[2])
1874 @@ -94,7 +93,7 @@
1875 line();
1876 }
1877
1878 -void log_query(uint64 *qnum,const char client[4],unsigned int port,const char id[2],const char *q,const char qtype[2])
1879 +void log_query(uint64 *qnum,const char client[16],unsigned int port,const char id[2],const char *q,const char qtype[2])
1880 {
1881 string("query "); number(*qnum); space();
1882 ip(client); string(":"); hex(port >> 8); hex(port & 255);
1883 @@ -119,14 +118,14 @@
1884 line();
1885 }
1886
1887 -void log_tcpopen(const char client[4],unsigned int port)
1888 +void log_tcpopen(const char client[16],unsigned int port)
1889 {
1890 string("tcpopen ");
1891 ip(client); string(":"); hex(port >> 8); hex(port & 255);
1892 line();
1893 }
1894
1895 -void log_tcpclose(const char client[4],unsigned int port)
1896 +void log_tcpclose(const char client[16],unsigned int port)
1897 {
1898 const char *x = error_str(errno);
1899 string("tcpclose ");
1900 @@ -135,15 +134,15 @@
1901 line();
1902 }
1903
1904 -void log_tx(const char *q,const char qtype[2],const char *control,const char servers[64],unsigned int gluelessness)
1905 +void log_tx(const char *q,const char qtype[2],const char *control,const char servers[256],unsigned int gluelessness)
1906 {
1907 int i;
1908
1909 string("tx "); number(gluelessness); space();
1910 logtype(qtype); space(); name(q); space();
1911 name(control);
1912 - for (i = 0;i < 64;i += 4)
1913 - if (byte_diff(servers + i,4,"\0\0\0\0")) {
1914 + for (i = 0;i < 256;i += 16)
1915 + if (byte_diff(servers + i,16,V6any)) {
1916 space();
1917 ip(servers + i);
1918 }
1919 @@ -175,21 +174,21 @@
1920 line();
1921 }
1922
1923 -void log_nxdomain(const char server[4],const char *q,unsigned int ttl)
1924 +void log_nxdomain(const char server[16],const char *q,unsigned int ttl)
1925 {
1926 string("nxdomain "); ip(server); space(); number(ttl); space();
1927 name(q);
1928 line();
1929 }
1930
1931 -void log_nodata(const char server[4],const char *q,const char qtype[2],unsigned int ttl)
1932 +void log_nodata(const char server[16],const char *q,const char qtype[2],unsigned int ttl)
1933 {
1934 string("nodata "); ip(server); space(); number(ttl); space();
1935 logtype(qtype); space(); name(q);
1936 line();
1937 }
1938
1939 -void log_lame(const char server[4],const char *control,const char *referral)
1940 +void log_lame(const char server[16],const char *control,const char *referral)
1941 {
1942 string("lame "); ip(server); space();
1943 name(control); space(); name(referral);
1944 @@ -205,7 +204,7 @@
1945 line();
1946 }
1947
1948 -void log_rr(const char server[4],const char *q,const char type[2],const char *buf,unsigned int len,unsigned int ttl)
1949 +void log_rr(const char server[16],const char *q,const char type[2],const char *buf,unsigned int len,unsigned int ttl)
1950 {
1951 int i;
1952
1953 @@ -222,7 +221,7 @@
1954 line();
1955 }
1956
1957 -void log_rrns(const char server[4],const char *q,const char *data,unsigned int ttl)
1958 +void log_rrns(const char server[16],const char *q,const char *data,unsigned int ttl)
1959 {
1960 string("rr "); ip(server); space(); number(ttl);
1961 string(" ns "); name(q); space();
1962 @@ -230,7 +229,7 @@
1963 line();
1964 }
1965
1966 -void log_rrcname(const char server[4],const char *q,const char *data,unsigned int ttl)
1967 +void log_rrcname(const char server[16],const char *q,const char *data,unsigned int ttl)
1968 {
1969 string("rr "); ip(server); space(); number(ttl);
1970 string(" cname "); name(q); space();
1971 @@ -238,7 +237,7 @@
1972 line();
1973 }
1974
1975 -void log_rrptr(const char server[4],const char *q,const char *data,unsigned int ttl)
1976 +void log_rrptr(const char server[16],const char *q,const char *data,unsigned int ttl)
1977 {
1978 string("rr "); ip(server); space(); number(ttl);
1979 string(" ptr "); name(q); space();
1980 @@ -246,7 +245,7 @@
1981 line();
1982 }
1983
1984 -void log_rrmx(const char server[4],const char *q,const char *mx,const char pref[2],unsigned int ttl)
1985 +void log_rrmx(const char server[16],const char *q,const char *mx,const char pref[2],unsigned int ttl)
1986 {
1987 uint16 u;
1988
1989 @@ -257,7 +256,7 @@
1990 line();
1991 }
1992
1993 -void log_rrsoa(const char server[4],const char *q,const char *n1,const char *n2,const char misc[20],unsigned int ttl)
1994 +void log_rrsoa(const char server[16],const char *q,const char *n1,const char *n2,const char misc[20],unsigned int ttl)
1995 {
1996 uint32 u;
1997 int i;
1998 diff -uNr djbdns-1.05/okclient.c djbdns-1.05-ipv6/okclient.c
1999 --- djbdns-1.05/okclient.c 2001-02-11 22:11:45.000000000 +0100
2000 +++ djbdns-1.05-ipv6/okclient.c 2005-09-08 21:58:08.214384250 +0200
2001 @@ -2,24 +2,34 @@
2002 #include <sys/stat.h>
2003 #include "str.h"
2004 #include "ip4.h"
2005 +#include "ip6.h"
2006 +#include "byte.h"
2007 #include "okclient.h"
2008
2009 -static char fn[3 + IP4_FMT];
2010 +static char fn[3 + IP6_FMT];
2011
2012 -int okclient(char ip[4])
2013 +int okclient(char ip[16])
2014 {
2015 struct stat st;
2016 int i;
2017 + char sep;
2018
2019 fn[0] = 'i';
2020 fn[1] = 'p';
2021 fn[2] = '/';
2022 - fn[3 + ip4_fmt(fn + 3,ip)] = 0;
2023 + if (byte_equal(ip,12,V4mappedprefix)) {
2024 + fn[3 + ip4_fmt(fn + 3,ip+12)] = 0;
2025 + sep='.';
2026 + } else {
2027 + fn[3 + ip6_fmt(fn + 3,ip)] = 0;
2028 + sep=':';
2029 + }
2030
2031 for (;;) {
2032 + if (!fn[3]) return 0;
2033 if (stat(fn,&st) == 0) return 1;
2034 /* treat temporary error as rejection */
2035 - i = str_rchr(fn,'.');
2036 + i = str_rchr(fn,sep);
2037 if (!fn[i]) return 0;
2038 fn[i] = 0;
2039 }
2040 diff -uNr djbdns-1.05/printrecord.c djbdns-1.05-ipv6/printrecord.c
2041 --- djbdns-1.05/printrecord.c 2001-02-11 22:11:45.000000000 +0100
2042 +++ djbdns-1.05-ipv6/printrecord.c 2005-09-08 21:58:08.218384500 +0200
2043 @@ -4,6 +4,7 @@
2044 #include "byte.h"
2045 #include "dns.h"
2046 #include "printrecord.h"
2047 +#include "ip6.h"
2048
2049 static char *d;
2050
2051 @@ -82,6 +83,15 @@
2052 if (!stralloc_catulong0(out,ch,0)) return 0;
2053 }
2054 }
2055 + else if (byte_equal(misc,2,DNS_T_AAAA)) {
2056 + char ip6str[IP6_FMT];
2057 + int stringlen;
2058 + if (datalen != 16) { errno = error_proto; return 0; }
2059 + if (!stralloc_cats(out," AAAA ")) return 0;
2060 + pos = dns_packet_copy(buf,len,pos,misc,16); if (!pos) return 0;
2061 + stringlen=ip6_fmt(ip6str,misc);
2062 + if (!stralloc_catb(out,ip6str,stringlen)) return 0;
2063 + }
2064 else {
2065 if (!stralloc_cats(out," ")) return 0;
2066 uint16_unpack_big(misc,&u16);
2067 diff -uNr djbdns-1.05/qlog.c djbdns-1.05-ipv6/qlog.c
2068 --- djbdns-1.05/qlog.c 2001-02-11 22:11:45.000000000 +0100
2069 +++ djbdns-1.05-ipv6/qlog.c 2005-09-08 21:58:08.218384500 +0200
2070 @@ -20,15 +20,15 @@
2071 put('0' + (c & 7));
2072 }
2073
2074 -void qlog(const char ip[4],uint16 port,const char id[2],const char *q,const char qtype[2],const char *result)
2075 +void qlog(const char ip[16],uint16 port,const char id[2],const char *q,const char qtype[2],const char *result)
2076 {
2077 char ch;
2078 char ch2;
2079
2080 - hex(ip[0]);
2081 - hex(ip[1]);
2082 - hex(ip[2]);
2083 - hex(ip[3]);
2084 + {
2085 + int i;
2086 + for (i=0; i<16; ++i) hex(ip[i]);
2087 + }
2088 put(':');
2089 hex(port >> 8);
2090 hex(port & 255);
2091 diff -uNr djbdns-1.05/query.c djbdns-1.05-ipv6/query.c
2092 --- djbdns-1.05/query.c 2001-02-11 22:11:45.000000000 +0100
2093 +++ djbdns-1.05-ipv6/query.c 2005-09-08 21:58:08.218384500 +0200
2094 @@ -12,6 +12,9 @@
2095 #include "alloc.h"
2096 #include "response.h"
2097 #include "query.h"
2098 +#include "ip6.h"
2099 +
2100 +extern stralloc ignoreip;
2101
2102 static int flagforwardonly = 0;
2103
2104 @@ -110,7 +113,7 @@
2105 return 1;
2106 }
2107
2108 -static int globalip(char *d,char ip[4])
2109 +static int globalip(char *d,char ip[16])
2110 {
2111 if (dns_domain_equal(d,"\011localhost\0")) {
2112 byte_copy(ip,4,"\177\0\0\1");
2113 @@ -165,7 +168,7 @@
2114 char *buf;
2115 unsigned int len;
2116 const char *whichserver;
2117 - char header[12];
2118 + char header[24];
2119 char misc[20];
2120 unsigned int rcode;
2121 unsigned int posanswers;
2122 @@ -193,6 +196,7 @@
2123 int k;
2124 int p;
2125 int q;
2126 + unsigned int ii;
2127
2128 errno = error_io;
2129 if (state == 1) goto HAVEPACKET;
2130 @@ -210,9 +214,10 @@
2131
2132 if (globalip(d,misc)) {
2133 if (z->level) {
2134 - for (k = 0;k < 64;k += 4)
2135 - if (byte_equal(z->servers[z->level - 1] + k,4,"\0\0\0\0")) {
2136 - byte_copy(z->servers[z->level - 1] + k,4,misc);
2137 + for (k = 0;k < 256;k += 16)
2138 + if (byte_equal(z->servers[z->level - 1] + k,16,V6any)) {
2139 + byte_copy(z->servers[z->level - 1] + k,12,V4mappedprefix);
2140 + byte_copy(z->servers[z->level - 1] + k + 12,4,misc);
2141 break;
2142 }
2143 goto LOWERLEVEL;
2144 @@ -227,6 +232,158 @@
2145 return 1;
2146 }
2147
2148 + if (dns_domain_equal(d,"\0011\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\003ip6\003int\0")) {
2149 + if (z->level) goto LOWERLEVEL;
2150 + if (!rqa(z)) goto DIE;
2151 + if (typematch(DNS_T_PTR,dtype)) {
2152 + if (!response_rstart(d,DNS_T_PTR,655360)) goto DIE;
2153 + if (!response_addname("\016ipv6-localhost\0")) goto DIE;
2154 + if (!response_addname("\015ipv6-loopback\0")) goto DIE;
2155 + response_rfinish(RESPONSE_ANSWER);
2156 + }
2157 + cleanup(z);
2158 + return 1;
2159 + }
2160 +
2161 + if (dns_domain_equal(d,"\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\001e\001f\003ip6\003int\0")) {
2162 + if (z->level) goto LOWERLEVEL;
2163 + if (!rqa(z)) goto DIE;
2164 + if (typematch(DNS_T_PTR,dtype)) {
2165 + if (!response_rstart(d,DNS_T_PTR,655360)) goto DIE;
2166 + if (!response_addname("\015ipv6-localnet\0")) goto DIE;
2167 + response_rfinish(RESPONSE_ANSWER);
2168 + }
2169 + cleanup(z);
2170 + return 1;
2171 + }
2172 +
2173 + if (dns_domain_equal(d,"\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\001f\001f\003ip6\003int\0")) {
2174 + if (z->level) goto LOWERLEVEL;
2175 + if (!rqa(z)) goto DIE;
2176 + if (typematch(DNS_T_PTR,dtype)) {
2177 + if (!response_rstart(d,DNS_T_PTR,655360)) goto DIE;
2178 + if (!response_addname("\020ipv6-mcastprefix\0")) goto DIE;
2179 + response_rfinish(RESPONSE_ANSWER);
2180 + }
2181 + cleanup(z);
2182 + return 1;
2183 + }
2184 +
2185 + if (dns_domain_equal(d,"\0011\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0012\0010\001f\001f\003ip6\003int\0")) {
2186 + if (z->level) goto LOWERLEVEL;
2187 + if (!rqa(z)) goto DIE;
2188 + if (typematch(DNS_T_PTR,dtype)) {
2189 + if (!response_rstart(d,DNS_T_PTR,655360)) goto DIE;
2190 + if (!response_addname("\015ipv6-allnodes\0")) goto DIE;
2191 + response_rfinish(RESPONSE_ANSWER);
2192 + }
2193 + cleanup(z);
2194 + return 1;
2195 + }
2196 +
2197 + if (dns_domain_equal(d,"\0012\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0012\0010\001f\001f\003ip6\003int\0")) {
2198 + if (z->level) goto LOWERLEVEL;
2199 + if (!rqa(z)) goto DIE;
2200 + if (typematch(DNS_T_PTR,dtype)) {
2201 + if (!response_rstart(d,DNS_T_PTR,655360)) goto DIE;
2202 + if (!response_addname("\017ipv6-allrouters\0")) goto DIE;
2203 + response_rfinish(RESPONSE_ANSWER);
2204 + }
2205 + cleanup(z);
2206 + return 1;
2207 + }
2208 +
2209 + if (dns_domain_equal(d,"\0011\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0010\0012\0010\001f\001f\003ip6\003int\0")) {
2210 + if (z->level) goto LOWERLEVEL;
2211 + if (!rqa(z)) goto DIE;
2212 + if (typematch(DNS_T_PTR,dtype)) {
2213 + if (!response_rstart(d,DNS_T_PTR,655360)) goto DIE;
2214 + if (!response_addname("\015ipv6-allhosts\0")) goto DIE;
2215 + response_rfinish(RESPONSE_ANSWER);
2216 + }
2217 + cleanup(z);
2218 + return 1;
2219 + }
2220 +
2221 + if (dns_domain_equal(d,"\016ipv6-localhost\0") ||
2222 + dns_domain_equal(d,"\015ipv6-loopback\0"))
2223 + {
2224 + if (z->level) goto LOWERLEVEL;
2225 + if (!rqa(z)) goto DIE;
2226 + if (typematch(DNS_T_AAAA,dtype)) {
2227 + if (!response_rstart(d,DNS_T_AAAA,655360)) goto DIE;
2228 + if (!response_addbytes("\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\001",16)) goto DIE;
2229 + response_rfinish(RESPONSE_ANSWER);
2230 + }
2231 + cleanup(z);
2232 + return 1;
2233 + }
2234 +
2235 + if (dns_domain_equal(d,"\015ipv6-localnet\0"))
2236 + {
2237 + if (z->level) goto LOWERLEVEL;
2238 + if (!rqa(z)) goto DIE;
2239 + if (typematch(DNS_T_AAAA,dtype)) {
2240 + if (!response_rstart(d,DNS_T_AAAA,655360)) goto DIE;
2241 + if (!response_addbytes("\376\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000",16)) goto DIE;
2242 + response_rfinish(RESPONSE_ANSWER);
2243 + }
2244 + cleanup(z);
2245 + return 1;
2246 + }
2247 +
2248 + if (dns_domain_equal(d,"\020ipv6-mcastprefix\0"))
2249 + {
2250 + if (z->level) goto LOWERLEVEL;
2251 + if (!rqa(z)) goto DIE;
2252 + if (typematch(DNS_T_AAAA,dtype)) {
2253 + if (!response_rstart(d,DNS_T_AAAA,655360)) goto DIE;
2254 + if (!response_addbytes("\377\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000",16)) goto DIE;
2255 + response_rfinish(RESPONSE_ANSWER);
2256 + }
2257 + cleanup(z);
2258 + return 1;
2259 + }
2260 +
2261 + if (dns_domain_equal(d,"\15ipv6-allnodes\0"))
2262 + {
2263 + if (z->level) goto LOWERLEVEL;
2264 + if (!rqa(z)) goto DIE;
2265 + if (typematch(DNS_T_AAAA,dtype)) {
2266 + if (!response_rstart(d,DNS_T_AAAA,655360)) goto DIE;
2267 + if (!response_addbytes("\377\002\000\000\000\000\000\000\000\000\000\000\000\000\000\001",16)) goto DIE;
2268 + response_rfinish(RESPONSE_ANSWER);
2269 + }
2270 + cleanup(z);
2271 + return 1;
2272 + }
2273 +
2274 + if (dns_domain_equal(d,"\17ipv6-allrouters\0"))
2275 + {
2276 + if (z->level) goto LOWERLEVEL;
2277 + if (!rqa(z)) goto DIE;
2278 + if (typematch(DNS_T_AAAA,dtype)) {
2279 + if (!response_rstart(d,DNS_T_AAAA,655360)) goto DIE;
2280 + if (!response_addbytes("\377\002\000\000\000\000\000\000\000\000\000\000\000\000\000\002",16)) goto DIE;
2281 + response_rfinish(RESPONSE_ANSWER);
2282 + }
2283 + cleanup(z);
2284 + return 1;
2285 + }
2286 +
2287 + if (dns_domain_equal(d,"\15ipv6-allhosts\0"))
2288 + {
2289 + if (z->level) goto LOWERLEVEL;
2290 + if (!rqa(z)) goto DIE;
2291 + if (typematch(DNS_T_AAAA,dtype)) {
2292 + if (!response_rstart(d,DNS_T_AAAA,655360)) goto DIE;
2293 + if (!response_addbytes("\377\002\000\000\000\000\000\000\000\000\000\000\000\000\000\003",16)) goto DIE;
2294 + response_rfinish(RESPONSE_ANSWER);
2295 + }
2296 + cleanup(z);
2297 + return 1;
2298 + }
2299 +
2300 if (dns_domain_equal(d,"\0011\0010\0010\003127\7in-addr\4arpa\0")) {
2301 if (z->level) goto LOWERLEVEL;
2302 if (!rqa(z)) goto DIE;
2303 @@ -326,9 +483,10 @@
2304 if (z->level) {
2305 log_cachedanswer(d,DNS_T_A);
2306 while (cachedlen >= 4) {
2307 - for (k = 0;k < 64;k += 4)
2308 - if (byte_equal(z->servers[z->level - 1] + k,4,"\0\0\0\0")) {
2309 - byte_copy(z->servers[z->level - 1] + k,4,cached);
2310 + for (k = 0;k < 256;k += 16)
2311 + if (byte_equal(z->servers[z->level - 1] + k,16,V6any)) {
2312 + byte_copy(z->servers[z->level - 1] + k,12,V4mappedprefix);
2313 + byte_copy(z->servers[z->level - 1] + k + 12,4,cached);
2314 break;
2315 }
2316 cached += 4;
2317 @@ -390,7 +580,7 @@
2318 cached = cache_get(key,dlen + 2,&cachedlen,&ttl);
2319 if (cached && cachedlen) {
2320 z->control[z->level] = d;
2321 - byte_zero(z->servers[z->level],64);
2322 + byte_zero(z->servers[z->level],256);
2323 for (j = 0;j < QUERY_MAXNS;++j)
2324 dns_domain_free(&z->ns[z->level][j]);
2325 pos = 0;
2326 @@ -519,7 +709,7 @@
2327 if (!flagcname && !rcode && !flagout && flagreferral && !flagsoa)
2328 if (dns_domain_equal(referral,control) || !dns_domain_suffix(referral,control)) {
2329 log_lame(whichserver,control,referral);
2330 - byte_zero(whichserver,4);
2331 + byte_zero(whichserver,16);
2332 goto HAVENS;
2333 }
2334
2335 @@ -643,6 +833,11 @@
2336 pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) goto DIE;
2337 if (byte_equal(header + 8,2,"\0\4")) {
2338 pos = dns_packet_copy(buf,len,pos,header,4); if (!pos) goto DIE;
2339 + if (ignoreip.len)
2340 + for(ii = 0; ii < ignoreip.len; ii+= 16) {
2341 + if (byte_equal(ignoreip.s+ii,12,V4mappedprefix) &&
2342 + byte_equal(header,4,ignoreip.s+ii+12)) goto NXDOMAIN;
2343 + }
2344 save_data(header,4);
2345 log_rr(whichserver,t1,DNS_T_A,header,4,ttl);
2346 }
2347 @@ -650,6 +845,23 @@
2348 }
2349 save_finish(DNS_T_A,t1,ttl);
2350 }
2351 + else if (byte_equal(type,2,DNS_T_AAAA)) {
2352 + save_start();
2353 + while (i < j) {
2354 + pos = dns_packet_skipname(buf,len,records[i]); if (!pos) goto DIE;
2355 + pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) goto DIE;
2356 + if (byte_equal(header + 8,2,"\0\20")) {
2357 + pos = dns_packet_copy(buf,len,pos,header,16); if (!pos) goto DIE;
2358 + if (ignoreip.len)
2359 + for(ii = 0; ii < ignoreip.len; ii+= 16)
2360 + if (byte_equal(header,16,ignoreip.s+ii)) goto NXDOMAIN;
2361 + save_data(header,16);
2362 + log_rr(whichserver,t1,DNS_T_AAAA,header,16,ttl);
2363 + }
2364 + ++i;
2365 + }
2366 + save_finish(DNS_T_AAAA,t1,ttl);
2367 + }
2368 else {
2369 save_start();
2370 while (i < j) {
2371 @@ -723,9 +935,10 @@
2372 if (typematch(header,DNS_T_A))
2373 if (byte_equal(header + 2,2,DNS_C_IN)) /* should always be true */
2374 if (datalen == 4)
2375 - for (k = 0;k < 64;k += 4)
2376 - if (byte_equal(z->servers[z->level - 1] + k,4,"\0\0\0\0")) {
2377 - if (!dns_packet_copy(buf,len,pos,z->servers[z->level - 1] + k,4)) goto DIE;
2378 + for (k = 0;k < 256;k += 16)
2379 + if (byte_equal(z->servers[z->level - 1] + k,16,V6any)) {
2380 + byte_copy(z->servers[z->level - 1] + k,12,V4mappedprefix);
2381 + if (!dns_packet_copy(buf,len,pos,z->servers[z->level - 1] + k + 12,4)) goto DIE;
2382 break;
2383 }
2384 pos += datalen;
2385 @@ -818,7 +1031,7 @@
2386 return -1;
2387 }
2388
2389 -int query_start(struct query *z,char *dn,char type[2],char class[2],char localip[4])
2390 +int query_start(struct query *z,char *dn,char type[2],char class[2],char localip[16],unsigned int scope_id)
2391 {
2392 if (byte_equal(type,2,DNS_T_AXFR)) { errno = error_perm; return -1; }
2393
2394 @@ -829,8 +1042,9 @@
2395 if (!dns_domain_copy(&z->name[0],dn)) return -1;
2396 byte_copy(z->type,2,type);
2397 byte_copy(z->class,2,class);
2398 - byte_copy(z->localip,4,localip);
2399 + byte_copy(z->localip,16,localip);
2400 + z->scope_id=scope_id;
2401
2402 return doit(z,0);
2403 }
2404
2405 diff -uNr djbdns-1.05/roots.c djbdns-1.05-ipv6/roots.c
2406 --- djbdns-1.05/roots.c 2001-02-11 22:11:45.000000000 +0100
2407 +++ djbdns-1.05-ipv6/roots.c 2005-09-08 21:58:08.222384750 +0200
2408 @@ -6,6 +6,7 @@
2409 #include "error.h"
2410 #include "direntry.h"
2411 #include "ip4.h"
2412 +#include "ip6.h"
2413 #include "dns.h"
2414 #include "openreadclose.h"
2415 #include "roots.h"
2416 @@ -22,7 +23,7 @@
2417 j = dns_domain_length(data.s + i);
2418 if (dns_domain_equal(data.s + i,q)) return i + j;
2419 i += j;
2420 - i += 64;
2421 + i += 256;
2422 }
2423 return -1;
2424 }
2425 @@ -40,12 +41,12 @@
2426 }
2427 }
2428
2429 -int roots(char servers[64],char *q)
2430 +int roots(char servers[256],char *q)
2431 {
2432 int r;
2433 r = roots_find(q);
2434 if (r == -1) return 0;
2435 - byte_copy(servers,64,data.s + r);
2436 + byte_copy(servers,256,data.s + r);
2437 return 1;
2438 }
2439
2440 @@ -60,7 +61,7 @@
2441 const char *fqdn;
2442 static char *q;
2443 static stralloc text;
2444 - char servers[64];
2445 + char servers[256];
2446 int serverslen;
2447 int i;
2448 int j;
2449 @@ -86,14 +87,14 @@
2450 for (i = 0;i < text.len;++i)
2451 if (text.s[i] == '\n') {
2452 if (serverslen <= 60)
2453 - if (ip4_scan(text.s + j,servers + serverslen))
2454 - serverslen += 4;
2455 + if (ip6_scan(text.s + j,servers + serverslen))
2456 + serverslen += 16;
2457 j = i + 1;
2458 }
2459 - byte_zero(servers + serverslen,64 - serverslen);
2460 + byte_zero(servers + serverslen,256 - serverslen);
2461
2462 if (!stralloc_catb(&data,q,dns_domain_length(q))) return 0;
2463 - if (!stralloc_catb(&data,servers,64)) return 0;
2464 + if (!stralloc_catb(&data,servers,256)) return 0;
2465 }
2466 }
2467 }
2468 diff -uNr djbdns-1.05/scan_xlong.c djbdns-1.05-ipv6/scan_xlong.c
2469 --- djbdns-1.05/scan_xlong.c 1970-01-01 01:00:00.000000000 +0100
2470 +++ djbdns-1.05-ipv6/scan_xlong.c 2005-09-08 21:58:08.222384750 +0200
2471 @@ -0,0 +1,23 @@
2472 +#include "scan.h"
2473 +
2474 +static inline int fromhex(unsigned char c) {
2475 + if (c>='0' && c<='9')
2476 + return c-'0';
2477 + else if (c>='A' && c<='F')
2478 + return c-'A'+10;
2479 + else if (c>='a' && c<='f')
2480 + return c-'a'+10;
2481 + return -1;
2482 +}
2483 +
2484 +unsigned int scan_xlong(const char *src,unsigned long *dest) {
2485 + register const char *tmp=src;
2486 + register int l=0;
2487 + register unsigned char c;
2488 + while ((c=fromhex(*tmp))<16) {
2489 + l=(l<<4)+c;
2490 + ++tmp;
2491 + }
2492 + *dest=l;
2493 + return tmp-src;
2494 +}
2495 diff -uNr djbdns-1.05/server.c djbdns-1.05-ipv6/server.c
2496 --- djbdns-1.05/server.c 2001-02-11 22:11:45.000000000 +0100
2497 +++ djbdns-1.05-ipv6/server.c 2005-09-08 21:58:08.226385000 +0200
2498 @@ -4,6 +4,7 @@
2499 #include "buffer.h"
2500 #include "strerr.h"
2501 #include "ip4.h"
2502 +#include "ip6.h"
2503 #include "uint16.h"
2504 #include "ndelay.h"
2505 #include "socket.h"
2506 @@ -11,13 +12,16 @@
2507 #include "qlog.h"
2508 #include "response.h"
2509 #include "dns.h"
2510 +#include "alloc.h"
2511 +#include "iopause.h"
2512 +#include "str.h"
2513
2514 extern char *fatal;
2515 extern char *starting;
2516 extern int respond(char *,char *,char *);
2517 extern void initialize(void);
2518
2519 -static char ip[4];
2520 +static char ip[16];
2521 static uint16 port;
2522
2523 static char buf[513];
2524 @@ -25,6 +29,11 @@
2525
2526 static char *q;
2527
2528 +void nomem()
2529 +{
2530 + strerr_die2x(111,fatal,"out of memory");
2531 +}
2532 +
2533 static int doit(void)
2534 {
2535 unsigned int pos;
2536 @@ -82,35 +91,86 @@
2537 int main()
2538 {
2539 char *x;
2540 - int udp53;
2541 + int *udp53;
2542 + unsigned int off;
2543 + unsigned int cnt;
2544 + iopause_fd *iop;
2545
2546 x = env_get("IP");
2547 if (!x)
2548 strerr_die2x(111,fatal,"$IP not set");
2549 - if (!ip4_scan(x,ip))
2550 - strerr_die3x(111,fatal,"unable to parse IP address ",x);
2551 -
2552 - udp53 = socket_udp();
2553 - if (udp53 == -1)
2554 - strerr_die2sys(111,fatal,"unable to create UDP socket: ");
2555 - if (socket_bind4_reuse(udp53,ip,53) == -1)
2556 - strerr_die2sys(111,fatal,"unable to bind UDP socket: ");
2557 -
2558 + off=cnt=0;
2559 + while (x[off]) {
2560 + unsigned int l;
2561 + char dummy[16];
2562 + l=ip6_scan(x+off,dummy);
2563 + if (!l)
2564 + strerr_die3x(111,fatal,"unable to parse IP address ",x+off);
2565 + cnt++;
2566 + if (!x[off+l]) break;
2567 + if (x[off+l]=='%')
2568 + while (x[off+l] && x[off+l]!=',') ++l;
2569 + if (x[off+l]!=',')
2570 + strerr_die3x(111,fatal,"unable to parse IP address ",x+off);
2571 + off+=l+1;
2572 + }
2573 + udp53=(int *) alloc(sizeof(int) *cnt);
2574 + if (!udp53) nomem();
2575 + iop=(iopause_fd *) alloc(sizeof(*iop) * cnt);
2576 + if (!iop) nomem();
2577 +
2578 + off=cnt=0;
2579 + while (x[off]) {
2580 + unsigned int l;
2581 + uint32 ifid=0;
2582 + l=ip6_scan(x+off,ip);
2583 + udp53[cnt] = socket_udp6();
2584 + if (udp53[cnt] == -1)
2585 + strerr_die2sys(111,fatal,"unable to create UDP socket: ");
2586 + if (x[off+l]=='%') {
2587 + char* interface=x+off+l+1;
2588 + int Len=str_chr(interface,',');
2589 + if (interface[Len]) {
2590 + interface[Len]=0;
2591 + ifid=socket_getifidx(interface);
2592 + interface[Len]=',';
2593 + } else
2594 + ifid=socket_getifidx(interface);
2595 + l+=Len;
2596 + }
2597 + if (socket_bind6_reuse(udp53[cnt],ip,53,ifid) == -1)
2598 + strerr_die2sys(111,fatal,"unable to bind UDP socket: ");
2599 + ndelay_off(udp53[cnt]);
2600 + socket_tryreservein(udp53[cnt],65536);
2601 + iop[cnt].fd=udp53[cnt];
2602 + iop[cnt].events=IOPAUSE_READ;
2603 + cnt++;
2604 + if (!x[off+l]) break;
2605 + off+=l+1;
2606 + }
2607 droproot(fatal);
2608
2609 initialize();
2610 -
2611 - ndelay_off(udp53);
2612 - socket_tryreservein(udp53,65536);
2613
2614 buffer_putsflush(buffer_2,starting);
2615
2616 for (;;) {
2617 - len = socket_recv4(udp53,buf,sizeof buf,ip,&port);
2618 - if (len < 0) continue;
2619 - if (!doit()) continue;
2620 - if (response_len > 512) response_tc();
2621 - socket_send4(udp53,response,response_len,ip,port);
2622 - /* may block for buffer space; if it fails, too bad */
2623 + struct taia stamp;
2624 + struct taia deadline;
2625 + unsigned int i;
2626 + uint32 ifid;
2627 + taia_now(&stamp);
2628 + taia_uint(&deadline,300);
2629 + taia_add(&deadline,&deadline,&stamp);
2630 + iopause(iop,cnt,&deadline,&stamp);
2631 + for (i=0;i<cnt;i++)
2632 + if (iop[i].revents) {
2633 + len = socket_recv6(udp53[i],buf,sizeof buf,ip,&port,&ifid);
2634 + if (len < 0) continue;
2635 + if (!doit()) continue;
2636 + if (response_len > 512) response_tc();
2637 + socket_send6(udp53[i],response,response_len,ip,port,ifid);
2638 + /* may block for buffer space; if it fails, too bad */
2639 + }
2640 }
2641 }
2642 diff -uNr djbdns-1.05/sockaddr_in6.h1 djbdns-1.05-ipv6/sockaddr_in6.h1
2643 --- djbdns-1.05/sockaddr_in6.h1 1970-01-01 01:00:00.000000000 +0100
2644 +++ djbdns-1.05-ipv6/sockaddr_in6.h1 2005-09-08 21:58:08.226385000 +0200
2645 @@ -0,0 +1,21 @@
2646 +#include "haveip6.h"
2647 +#ifdef LIBC_HAS_IP6
2648 +#include <sys/types.h>
2649 +#include <sys/socket.h>
2650 +#define sockaddr_in6 blub
2651 +#include <netinet/in.h>
2652 +#undef sockaddr_in6
2653 +
2654 +struct sockaddr_in6 {
2655 + sa_family_t sin6_family; /* AF_INET6 */
2656 + unsigned short sin6_port; /* transport layer port # */
2657 + uint32_t sin6_flowinfo; /* IPv6 traffic class & flow info */
2658 + struct in6_addr sin6_addr; /* IPv6 address */
2659 + uint32_t sin6_scope_id; /* set of interfaces for a scope */
2660 +};
2661 +
2662 +#else
2663 +#include <sys/types.h>
2664 +#include <sys/socket.h>
2665 +#include <netinet/in.h>
2666 +#endif
2667 diff -uNr djbdns-1.05/sockaddr_in6.h2 djbdns-1.05-ipv6/sockaddr_in6.h2
2668 --- djbdns-1.05/sockaddr_in6.h2 1970-01-01 01:00:00.000000000 +0100
2669 +++ djbdns-1.05-ipv6/sockaddr_in6.h2 2005-09-08 21:58:08.226385000 +0200
2670 @@ -0,0 +1,4 @@
2671 +#include <sys/types.h>
2672 +#include <sys/socket.h>
2673 +#include <netinet/in.h>
2674 +
2675 diff -uNr djbdns-1.05/socket.h djbdns-1.05-ipv6/socket.h
2676 --- djbdns-1.05/socket.h 2001-02-11 22:11:45.000000000 +0100
2677 +++ djbdns-1.05-ipv6/socket.h 2005-09-08 21:58:08.230385250 +0200
2678 @@ -2,21 +2,37 @@
2679 #define SOCKET_H
2680
2681 #include "uint16.h"
2682 +#include "uint32.h"
2683
2684 extern int socket_tcp(void);
2685 extern int socket_udp(void);
2686 +extern int socket_tcp6(void);
2687 +extern int socket_udp6(void);
2688
2689 extern int socket_connect4(int,const char *,uint16);
2690 +extern int socket_connect6(int s,const char ip[16],uint16 port,uint32 scope_id);
2691 extern int socket_connected(int);
2692 -extern int socket_bind4(int,char *,uint16);
2693 +extern int socket_bind4(int,const char *,uint16);
2694 extern int socket_bind4_reuse(int,char *,uint16);
2695 +extern int socket_bind6(int s,const char *ip,uint16 port,uint32 scope_id);
2696 +extern int socket_bind6_reuse(int s,const char *ip,uint16 port,uint32 scope_id);
2697 extern int socket_listen(int,int);
2698 extern int socket_accept4(int,char *,uint16 *);
2699 +extern int socket_accept6(int s,char *ip,uint16 *port,uint32 *scope_id);
2700 extern int socket_recv4(int,char *,int,char *,uint16 *);
2701 extern int socket_send4(int,const char *,int,const char *,uint16);
2702 +extern int socket_recv6(int s,char *buf,unsigned int len,char *ip,uint16 *port,uint32 *scope_id);
2703 +extern int socket_send6(int s,const char *buf,unsigned int len,const char *ip,uint16 port,uint32 scope_id);
2704 extern int socket_local4(int,char *,uint16 *);
2705 extern int socket_remote4(int,char *,uint16 *);
2706 +extern int socket_local6(int s,char *ip,uint16 *port,uint32 *scope_id);
2707 +extern int socket_remote6(int s,char *ip,uint16 *port,uint32 *scope_id);
2708
2709 extern void socket_tryreservein(int,int);
2710
2711 +extern const char* socket_getifname(uint32 interface);
2712 +extern uint32 socket_getifidx(const char *ifname);
2713 +
2714 +extern int noipv6;
2715 +
2716 #endif
2717 diff -uNr djbdns-1.05/socket_accept6.c djbdns-1.05-ipv6/socket_accept6.c
2718 --- djbdns-1.05/socket_accept6.c 1970-01-01 01:00:00.000000000 +0100
2719 +++ djbdns-1.05-ipv6/socket_accept6.c 2005-09-08 21:58:08.230385250 +0200
2720 @@ -0,0 +1,43 @@
2721 +#include <sys/param.h>
2722 +#include <sys/socket.h>
2723 +#include <netinet/in.h>
2724 +#include "byte.h"
2725 +#include "socket.h"
2726 +#include "ip6.h"
2727 +#include "haveip6.h"
2728 +#include "error.h"
2729 +
2730 +int socket_accept6(int s,char ip[16],uint16 *port,uint32 *scope_id)
2731 +{
2732 +#ifdef LIBC_HAS_IP6
2733 + struct sockaddr_in6 sa;
2734 +#else
2735 + struct sockaddr_in sa;
2736 +#endif
2737 + unsigned int dummy = sizeof sa;
2738 + int fd;
2739 +
2740 + fd = accept(s,(struct sockaddr *) &sa,&dummy);
2741 + if (fd == -1) return -1;
2742 +
2743 +#ifdef LIBC_HAS_IP6
2744 + if (sa.sin6_family==AF_INET) {
2745 + struct sockaddr_in *sa4=(struct sockaddr_in*)&sa;
2746 + byte_copy(ip,12,V4mappedprefix);
2747 + byte_copy(ip+12,4,(char *) &sa4->sin_addr);
2748 + uint16_unpack_big((char *) &sa4->sin_port,port);
2749 + return fd;
2750 + }
2751 + byte_copy(ip,16,(char *) &sa.sin6_addr);
2752 + uint16_unpack_big((char *) &sa.sin6_port,port);
2753 + if (scope_id) *scope_id=sa.sin6_scope_id;
2754 +
2755 + return fd;
2756 +#else
2757 + byte_copy(ip,12,V4mappedprefix);
2758 + byte_copy(ip+12,4,(char *) &sa.sin_addr);
2759 + uint16_unpack_big((char *) &sa.sin_port,port);
2760 + if (scope_id) *scope_id=0;
2761 + return fd;
2762 +#endif
2763 +}
2764 diff -uNr djbdns-1.05/socket_bind.c djbdns-1.05-ipv6/socket_bind.c
2765 --- djbdns-1.05/socket_bind.c 2001-02-11 22:11:45.000000000 +0100
2766 +++ djbdns-1.05-ipv6/socket_bind.c 2005-09-08 21:58:08.230385250 +0200
2767 @@ -5,7 +5,7 @@
2768 #include "byte.h"
2769 #include "socket.h"
2770
2771 -int socket_bind4(int s,char ip[4],uint16 port)
2772 +int socket_bind4(int s,const char ip[4],uint16 port)
2773 {
2774 struct sockaddr_in sa;
2775
2776 diff -uNr djbdns-1.05/socket_bind6.c djbdns-1.05-ipv6/socket_bind6.c
2777 --- djbdns-1.05/socket_bind6.c 1970-01-01 01:00:00.000000000 +0100
2778 +++ djbdns-1.05-ipv6/socket_bind6.c 2005-09-08 21:58:08.234385500 +0200
2779 @@ -0,0 +1,43 @@
2780 +#include <sys/param.h>
2781 +#include "sockaddr_in6.h"
2782 +#include "byte.h"
2783 +#include "socket.h"
2784 +#include "ip6.h"
2785 +#include "haveip6.h"
2786 +#include "error.h"
2787 +
2788 +int socket_bind6(int s,const char ip[16],uint16 port,uint32 scope_id)
2789 +{
2790 +#ifdef LIBC_HAS_IP6
2791 + struct sockaddr_in6 sa;
2792 +
2793 + if (noipv6) {
2794 +#endif
2795 + int i;
2796 + for (i=0; i<16; i++)
2797 + if (ip[i]!=0) break;
2798 + if (i==16 || ip6_isv4mapped(ip))
2799 + return socket_bind4(s,ip+12,port);
2800 +#ifdef LIBC_HAS_IP6
2801 + }
2802 + byte_zero(&sa,sizeof sa);
2803 + sa.sin6_family = AF_INET6;
2804 + uint16_pack_big((char *) &sa.sin6_port,port);
2805 +/* implicit: sa.sin6_flowinfo = 0; */
2806 + byte_copy((char *) &sa.sin6_addr,16,ip);
2807 + sa.sin6_scope_id=scope_id;
2808 +
2809 + return bind(s,(struct sockaddr *) &sa,sizeof sa);
2810 +#else
2811 + errno=error_proto;
2812 + return -1;
2813 +#endif
2814 +}
2815 +
2816 +int socket_bind6_reuse(int s,const char ip[16],uint16 port,uint32 scope_id)
2817 +{
2818 + int opt = 1;
2819 + setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof opt);
2820 + return socket_bind6(s,ip,port,scope_id);
2821 +}
2822 +
2823 diff -uNr djbdns-1.05/socket_connect6.c djbdns-1.05-ipv6/socket_connect6.c
2824 --- djbdns-1.05/socket_connect6.c 1970-01-01 01:00:00.000000000 +0100
2825 +++ djbdns-1.05-ipv6/socket_connect6.c 2005-09-08 21:58:32.871925250 +0200
2826 @@ -0,0 +1,39 @@
2827 +#include <sys/param.h>
2828 +#include <sys/types.h>
2829 +#include <sys/socket.h>
2830 +#include <netinet/in.h>
2831 +#include <errno.h>
2832 +#include "byte.h"
2833 +#include "socket.h"
2834 +#include "ip6.h"
2835 +#include "haveip6.h"
2836 +#include "error.h"
2837 +#include "uint32.h"
2838 +#include "ip4.h"
2839 +
2840 +int socket_connect6(int s,const char ip[16],uint16 port,uint32 scope_id)
2841 +{
2842 +#ifdef LIBC_HAS_IP6
2843 + struct sockaddr_in6 sa;
2844 +
2845 + if (noipv6) {
2846 +#endif
2847 + if (ip6_isv4mapped(ip))
2848 + return socket_connect4(s,ip+12,port);
2849 + if (byte_equal(ip,16,V6loopback))
2850 + return socket_connect4(s,ip4loopback,port);
2851 +#ifdef LIBC_HAS_IP6
2852 + }
2853 + byte_zero(&sa,sizeof sa);
2854 + sa.sin6_family = PF_INET6;
2855 + uint16_pack_big((char *) &sa.sin6_port,port);
2856 + sa.sin6_flowinfo = 0;
2857 + sa.sin6_scope_id = scope_id;
2858 + byte_copy((char *) &sa.sin6_addr,16,ip);
2859 +
2860 + return connect(s,(struct sockaddr *) &sa,sizeof sa);
2861 +#else
2862 + errno=error_proto;
2863 + return -1;
2864 +#endif
2865 +}
2866 diff -uNr djbdns-1.05/socket_getifidx.c djbdns-1.05-ipv6/socket_getifidx.c
2867 --- djbdns-1.05/socket_getifidx.c 1970-01-01 01:00:00.000000000 +0100
2868 +++ djbdns-1.05-ipv6/socket_getifidx.c 2005-09-08 21:58:08.234385500 +0200
2869 @@ -0,0 +1,13 @@
2870 +#include <sys/types.h>
2871 +#include <sys/socket.h>
2872 +#include <net/if.h>
2873 +#include "socket.h"
2874 +#include "haven2i.h"
2875 +
2876 +uint32 socket_getifidx(const char* ifname) {
2877 +#ifdef HAVE_N2I
2878 + return if_nametoindex(ifname);
2879 +#else
2880 + return 0;
2881 +#endif
2882 +}
2883 diff -uNr djbdns-1.05/socket_noipv6.c djbdns-1.05-ipv6/socket_noipv6.c
2884 --- djbdns-1.05/socket_noipv6.c 1970-01-01 01:00:00.000000000 +0100
2885 +++ djbdns-1.05-ipv6/socket_noipv6.c 2005-09-08 21:58:08.234385500 +0200
2886 @@ -0,0 +1,7 @@
2887 +#include "haveip6.h"
2888 +
2889 +#ifdef LIBC_HAS_IP6
2890 +int noipv6=0;
2891 +#else
2892 +int noipv6=1;
2893 +#endif
2894 diff -uNr djbdns-1.05/socket_recv6.c djbdns-1.05-ipv6/socket_recv6.c
2895 --- djbdns-1.05/socket_recv6.c 1970-01-01 01:00:00.000000000 +0100
2896 +++ djbdns-1.05-ipv6/socket_recv6.c 2005-09-08 21:58:08.238385750 +0200
2897 @@ -0,0 +1,42 @@
2898 +#include <sys/param.h>
2899 +#include "sockaddr_in6.h"
2900 +#include "byte.h"
2901 +#include "socket.h"
2902 +#include "ip6.h"
2903 +#include "haveip6.h"
2904 +#include "error.h"
2905 +
2906 +int socket_recv6(int s,char *buf,unsigned int len,char ip[16],uint16 *port,uint32 *scope_id)
2907 +{
2908 +#ifdef LIBC_HAS_IP6
2909 + struct sockaddr_in6 sa;
2910 +#else
2911 + struct sockaddr_in sa;
2912 +#endif
2913 + unsigned int dummy = sizeof sa;
2914 + int r;
2915 +
2916 + byte_zero(&sa,dummy);
2917 + r = recvfrom(s,buf,len,0,(struct sockaddr *) &sa,&dummy);
2918 + if (r == -1) return -1;
2919 +
2920 +#ifdef LIBC_HAS_IP6
2921 + if (noipv6) {
2922 + struct sockaddr_in *sa4=(struct sockaddr_in *)&sa;
2923 + byte_copy(ip,12,V4mappedprefix);
2924 + byte_copy(ip+12,4,(char *) &sa4->sin_addr);
2925 + uint16_unpack_big((char *) &sa4->sin_port,port);
2926 + return r;
2927 + }
2928 + byte_copy(ip,16,(char *) &sa.sin6_addr);
2929 + uint16_unpack_big((char *) &sa.sin6_port,port);
2930 + if (scope_id) *scope_id=sa.sin6_scope_id;
2931 +#else
2932 + byte_copy(ip,12,(char *)V4mappedprefix);
2933 + byte_copy(ip+12,4,(char *) &sa.sin_addr);
2934 + uint16_unpack_big((char *) &sa.sin_port,port);
2935 + if (scope_id) *scope_id=0;
2936 +#endif
2937 +
2938 + return r;
2939 +}
2940 diff -uNr djbdns-1.05/socket_send6.c djbdns-1.05-ipv6/socket_send6.c
2941 --- djbdns-1.05/socket_send6.c 1970-01-01 01:00:00.000000000 +0100
2942 +++ djbdns-1.05-ipv6/socket_send6.c 2005-09-08 21:58:08.238385750 +0200
2943 @@ -0,0 +1,39 @@
2944 +#include <sys/types.h>
2945 +#include <sys/param.h>
2946 +#include <sys/socket.h>
2947 +#include <netinet/in.h>
2948 +#include "byte.h"
2949 +#include "socket.h"
2950 +#include "ip6.h"
2951 +#include "haveip6.h"
2952 +#include "error.h"
2953 +
2954 +int socket_send6(int s,const char *buf,unsigned int len,const char ip[16],uint16 port,uint32 scope_id)
2955 +{
2956 +#ifdef LIBC_HAS_IP6
2957 + struct sockaddr_in6 sa;
2958 +#else
2959 + struct sockaddr_in sa;
2960 +#endif
2961 +
2962 + byte_zero(&sa,sizeof sa);
2963 +#ifdef LIBC_HAS_IP6
2964 + if (noipv6) {
2965 +#endif
2966 + if (ip6_isv4mapped(ip))
2967 + return socket_send4(s,buf,len,ip+12,port);
2968 + if (byte_equal(ip,16,V6loopback))
2969 + return socket_send4(s,buf,len,ip4loopback,port);
2970 +#ifdef LIBC_HAS_IP6
2971 + errno=error_proto;
2972 + return -1;
2973 + }
2974 + sa.sin6_family = AF_INET6;
2975 + uint16_pack_big((char *) &sa.sin6_port,port);
2976 + byte_copy((char *) &sa.sin6_addr,16,ip);
2977 + return sendto(s,buf,len,0,(struct sockaddr *) &sa,sizeof sa);
2978 +#else
2979 + errno=error_proto;
2980 + return -1;
2981 +#endif
2982 +}
2983 diff -uNr djbdns-1.05/socket_tcp6.c djbdns-1.05-ipv6/socket_tcp6.c
2984 --- djbdns-1.05/socket_tcp6.c 1970-01-01 01:00:00.000000000 +0100
2985 +++ djbdns-1.05-ipv6/socket_tcp6.c 2005-09-08 22:04:31.194319000 +0200
2986 @@ -0,0 +1,44 @@
2987 +#include <sys/types.h>
2988 +#include <sys/param.h>
2989 +#include <sys/socket.h>
2990 +#include <netinet/in.h>
2991 +#include <errno.h>
2992 +#include <unistd.h>
2993 +#include "ndelay.h"
2994 +#include "socket.h"
2995 +#include "haveip6.h"
2996 +#include "error.h"
2997 +
2998 +#ifndef EAFNOSUPPORT
2999 +#define EAFNOSUPPORT EINVAL
3000 +#endif
3001 +
3002 +int socket_tcp6(void)
3003 +{
3004 +#ifdef LIBC_HAS_IP6
3005 + int s;
3006 +
3007 + if (noipv6) goto compat;
3008 + s = socket(PF_INET6,SOCK_STREAM,0);
3009 + if (s == -1) {
3010 + if (errno == EINVAL || errno == EAFNOSUPPORT) {
3011 +compat:
3012 + s=socket(AF_INET,SOCK_STREAM,0);
3013 + noipv6=1;
3014 + if (s==-1) return -1;
3015 + } else
3016 + return -1;
3017 + }
3018 + if (ndelay_on(s) == -1) { close(s); return -1; }
3019 +#ifdef IPV6_V6ONLY
3020 + {
3021 + int zero=0;
3022 + setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&zero,sizeof(zero));
3023 + }
3024 +#endif
3025 + return s;
3026 +#else
3027 + return socket_tcp();
3028 +#endif
3029 +}
3030 +
3031 diff -uNr djbdns-1.05/socket_udp6.c djbdns-1.05-ipv6/socket_udp6.c
3032 --- djbdns-1.05/socket_udp6.c 1970-01-01 01:00:00.000000000 +0100
3033 +++ djbdns-1.05-ipv6/socket_udp6.c 2005-09-08 22:04:23.577843000 +0200
3034 @@ -0,0 +1,43 @@
3035 +#include <sys/types.h>
3036 +#include <sys/param.h>
3037 +#include <sys/socket.h>
3038 +#include <netinet/in.h>
3039 +#include <errno.h>
3040 +#include <unistd.h>
3041 +#include "ndelay.h"
3042 +#include "socket.h"
3043 +#include "haveip6.h"
3044 +#include "error.h"
3045 +
3046 +#ifndef EAFNOSUPPORT
3047 +#define EAFNOSUPPORT EINVAL
3048 +#endif
3049 +
3050 +int socket_udp6(void)
3051 +{
3052 +#ifdef LIBC_HAS_IP6
3053 + int s;
3054 +
3055 + if (noipv6) goto compat;
3056 + s = socket(PF_INET6,SOCK_DGRAM,0);
3057 + if (s == -1) {
3058 + if (errno == EINVAL || errno == EAFNOSUPPORT) {
3059 +compat:
3060 + s=socket(AF_INET,SOCK_DGRAM,0);
3061 + noipv6=1;
3062 + if (s==-1) return -1;
3063 + } else
3064 + return -1;
3065 + }
3066 + if (ndelay_on(s) == -1) { close(s); return -1; }
3067 +#ifdef IPV6_V6ONLY
3068 + {
3069 + int zero=0;
3070 + setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&zero,sizeof(zero));
3071 + }
3072 +#endif
3073 + return s;
3074 +#else
3075 + return socket_udp();
3076 +#endif
3077 +}
3078 diff -uNr djbdns-1.05/tdlookup.c djbdns-1.05-ipv6/tdlookup.c
3079 --- djbdns-1.05/tdlookup.c 2001-02-11 22:11:45.000000000 +0100
3080 +++ djbdns-1.05-ipv6/tdlookup.c 2005-09-08 21:58:08.242386000 +0200
3081 @@ -8,6 +8,7 @@
3082 #include "dns.h"
3083 #include "seek.h"
3084 #include "response.h"
3085 +#include "ip6.h"
3086
3087 static int want(const char *owner,const char type[2])
3088 {
3089 @@ -119,8 +120,9 @@
3090 char x[20];
3091 uint16 u16;
3092 char addr[8][4];
3093 - int addrnum;
3094 - uint32 addrttl;
3095 + char addr6[8][16];
3096 + int addrnum,addr6num;
3097 + uint32 addrttl,addr6ttl;
3098 int i;
3099
3100 anpos = response_len;
3101 @@ -152,8 +154,8 @@
3102 wild = q;
3103
3104 for (;;) {
3105 - addrnum = 0;
3106 - addrttl = 0;
3107 + addrnum = addr6num = 0;
3108 + addrttl = addr6ttl = 0;
3109 cdb_findstart(&c);
3110 while (r = find(wild,wild != q)) {
3111 if (r == -1) return 0;
3112 @@ -171,6 +173,17 @@
3113 if (addrnum < 1000000) ++addrnum;
3114 continue;
3115 }
3116 + if (byte_equal(type,2,DNS_T_AAAA) && (dlen - dpos == 16)) {
3117 + addr6ttl = ttl;
3118 + i = dns_random(addr6num + 1);
3119 + if (i < 8) {
3120 + if ((i < addr6num) && (addr6num < 8))
3121 + byte_copy(addr6[addr6num],16,addr6[i]);
3122 + byte_copy(addr6[i],16,data + dpos);
3123 + }
3124 + if (addr6num < 1000000) ++addr6num;
3125 + continue;
3126 + }
3127 if (!response_rstart(q,type,ttl)) return 0;
3128 if (byte_equal(type,2,DNS_T_NS) || byte_equal(type,2,DNS_T_CNAME) || byte_equal(type,2,DNS_T_PTR)) {
3129 if (!doname()) return 0;
3130 @@ -195,6 +208,12 @@
3131 if (!response_addbytes(addr[i],4)) return 0;
3132 response_rfinish(RESPONSE_ANSWER);
3133 }
3134 + for (i = 0;i < addr6num;++i)
3135 + if (i < 8) {
3136 + if (!response_rstart(q,DNS_T_AAAA,addr6ttl)) return 0;
3137 + if (!response_addbytes(addr6[i],16)) return 0;
3138 + response_rfinish(RESPONSE_ANSWER);
3139 + }
3140
3141 if (flagfound) break;
3142 if (wild == control) break;
3143 @@ -259,6 +278,11 @@
3144 if (!dobytes(4)) return 0;
3145 response_rfinish(RESPONSE_ADDITIONAL);
3146 }
3147 + else if (byte_equal(type,2,DNS_T_AAAA)) {
3148 + if (!response_rstart(d1,DNS_T_AAAA,ttl)) return 0;
3149 + if (!dobytes(16)) return 0;
3150 + response_rfinish(RESPONSE_ADDITIONAL);
3151 + }
3152 }
3153 }
3154 }
3155 @@ -278,7 +302,7 @@
3156 return 1;
3157 }
3158
3159 -int respond(char *q,char qtype[2],char ip[4])
3160 +int respond(char *q,char qtype[2],char ip[16])
3161 {
3162 int fd;
3163 int r;
3164 @@ -292,15 +316,17 @@
3165 byte_zero(clientloc,2);
3166 key[0] = 0;
3167 key[1] = '%';
3168 - byte_copy(key + 2,4,ip);
3169 - r = cdb_find(&c,key,6);
3170 - if (!r) r = cdb_find(&c,key,5);
3171 - if (!r) r = cdb_find(&c,key,4);
3172 - if (!r) r = cdb_find(&c,key,3);
3173 - if (!r) r = cdb_find(&c,key,2);
3174 - if (r == -1) return 0;
3175 - if (r && (cdb_datalen(&c) == 2))
3176 - if (cdb_read(&c,clientloc,2,cdb_datapos(&c)) == -1) return 0;
3177 + if (byte_equal(ip,12,V4mappedprefix)) {
3178 + byte_copy(key + 2,4,ip+12);
3179 + r = cdb_find(&c,key,6);
3180 + if (!r) r = cdb_find(&c,key,5);
3181 + if (!r) r = cdb_find(&c,key,4);
3182 + if (!r) r = cdb_find(&c,key,3);
3183 + if (!r) r = cdb_find(&c,key,2);
3184 + if (r == -1) return 0;
3185 + if (r && (cdb_datalen(&c) == 2))
3186 + if (cdb_read(&c,clientloc,2,cdb_datapos(&c)) == -1) return 0;
3187 + }
3188
3189 r = doit(q,qtype);
3190
3191 diff -uNr djbdns-1.05/tinydns-conf.c djbdns-1.05-ipv6/tinydns-conf.c
3192 --- djbdns-1.05/tinydns-conf.c 2001-02-11 22:11:45.000000000 +0100
3193 +++ djbdns-1.05-ipv6/tinydns-conf.c 2005-09-08 21:58:08.242386000 +0200
3194 @@ -82,6 +82,18 @@
3195 finish();
3196 perm(0755);
3197
3198 + start("root/add-host6");
3199 + outs("#!/bin/sh\nexec ");
3200 + outs(auto_home); outs("/bin/tinydns-edit data data.new add host6 ${1+\"$@\"}\n");
3201 + finish();
3202 + perm(0755);
3203 +
3204 + start("root/add-alias6");
3205 + outs("#!/bin/sh\nexec ");
3206 + outs(auto_home); outs("/bin/tinydns-edit data data.new add alias6 ${1+\"$@\"}\n");
3207 + finish();
3208 + perm(0755);
3209 +
3210 start("root/add-mx");
3211 outs("#!/bin/sh\nexec ");
3212 outs(auto_home); outs("/bin/tinydns-edit data data.new add mx ${1+\"$@\"}\n");
3213 diff -uNr djbdns-1.05/tinydns-data.c djbdns-1.05-ipv6/tinydns-data.c
3214 --- djbdns-1.05/tinydns-data.c 2001-02-11 22:11:45.000000000 +0100
3215 +++ djbdns-1.05-ipv6/tinydns-data.c 2005-09-08 21:58:08.246386250 +0200
3216 @@ -8,6 +8,7 @@
3217 #include "byte.h"
3218 #include "fmt.h"
3219 #include "ip4.h"
3220 +#include "ip6.h"
3221 #include "exit.h"
3222 #include "case.h"
3223 #include "scan.h"
3224 @@ -172,6 +173,7 @@
3225 static char *d1;
3226 static char *d2;
3227 char dptr[DNS_NAME4_DOMAIN];
3228 +char d6ptr[DNS_NAME6_DOMAIN];
3229
3230 char strnum[FMT_ULONG];
3231
3232 @@ -193,6 +195,7 @@
3233 char loc[2];
3234 unsigned long u;
3235 char ip[4];
3236 + char ip6[16];
3237 char type[2];
3238 char soa[20];
3239 char buf[4];
3240 @@ -339,6 +342,33 @@
3241 }
3242 break;
3243
3244 + case '6': case '3':
3245 + if (!dns_domain_fromdot(&d1,f[0].s,f[0].len)) nomem();
3246 + if (!stralloc_0(&f[2])) nomem();
3247 + if (!scan_ulong(f[2].s,&ttl)) ttl = TTL_POSITIVE;
3248 + ttdparse(&f[3],ttd);
3249 + locparse(&f[4],loc);
3250 +
3251 + if (!stralloc_0(&f[1])) nomem();
3252 + if (ip6_scan_flat(f[1].s,ip6)) {
3253 + rr_start(DNS_T_AAAA,ttl,ttd,loc);
3254 + rr_add(ip6,16);
3255 + rr_finish(d1);
3256 +
3257 + if (line.s[0] == '6') { /* emit both .ip6.arpa and .ip6.int */
3258 + dns_name6_domain(d6ptr,ip6,DNS_IP6_ARPA);
3259 + rr_start(DNS_T_PTR,ttl,ttd,loc);
3260 + rr_addname(d1);
3261 + rr_finish(d6ptr);
3262 +
3263 + dns_name6_domain(d6ptr,ip6,DNS_IP6_INT);
3264 + rr_start(DNS_T_PTR,ttl,ttd,loc);
3265 + rr_addname(d1);
3266 + rr_finish(d6ptr);
3267 + }
3268 + }
3269 + break;
3270 +
3271 case '@':
3272 if (!dns_domain_fromdot(&d1,f[0].s,f[0].len)) nomem();
3273 if (!stralloc_0(&f[4])) nomem();
3274 diff -uNr djbdns-1.05/tinydns-edit.c djbdns-1.05-ipv6/tinydns-edit.c
3275 --- djbdns-1.05/tinydns-edit.c 2001-02-11 22:11:45.000000000 +0100
3276 +++ djbdns-1.05-ipv6/tinydns-edit.c 2005-09-08 21:58:08.246386250 +0200
3277 @@ -13,6 +13,7 @@
3278 #include "str.h"
3279 #include "fmt.h"
3280 #include "ip4.h"
3281 +#include "ip6.h"
3282 #include "dns.h"
3283
3284 #define FATAL "tinydns-edit: fatal: "
3285 @@ -25,7 +26,8 @@
3286
3287 void die_usage()
3288 {
3289 - strerr_die1x(100,"tinydns-edit: usage: tinydns-edit data data.new add [ns|childns|host|alias|mx] domain a.b.c.d");
3290 + strerr_die1x(100,"tinydns-edit: usage: tinydns-edit data data.new add [ns|childns|host|alias|mx] domain a.b.c.d\n"
3291 + "tinydns-edit: usage: tinydns-edit data data.new add [host6|alias6] domain a:b:c:d:e:f:g:h");
3292 }
3293 void nomem()
3294 {
3295 @@ -43,6 +45,7 @@
3296 char mode;
3297 static char *target;
3298 char targetip[4];
3299 +char targetip6[16];
3300
3301 int fd;
3302 buffer b;
3303 @@ -61,7 +64,9 @@
3304 static char *d1;
3305 static char *d2;
3306 char ip[4];
3307 +char ip6[16];
3308 char ipstr[IP4_FMT];
3309 +char ip6str[IP6_FMT];
3310 char strnum[FMT_ULONG];
3311
3312 static char *names[26];
3313 @@ -96,7 +101,9 @@
3314 if (str_equal(*argv,"ns")) mode = '.';
3315 else if (str_equal(*argv,"childns")) mode = '&';
3316 else if (str_equal(*argv,"host")) mode = '=';
3317 + else if (str_equal(*argv,"host6")) mode = '6';
3318 else if (str_equal(*argv,"alias")) mode = '+';
3319 + else if (str_equal(*argv,"alias6")) mode = '3';
3320 else if (str_equal(*argv,"mx")) mode = '@';
3321 else die_usage();
3322
3323 @@ -104,7 +111,11 @@
3324 if (!dns_domain_fromdot(&target,*argv,str_len(*argv))) nomem();
3325
3326 if (!*++argv) die_usage();
3327 - if (!ip4_scan(*argv,targetip)) die_usage();
3328 + if (mode == '6' || mode == '3') {
3329 + if (!ip6_scan(*argv,targetip6)) die_usage();
3330 + } else {
3331 + if (!ip4_scan(*argv,targetip)) die_usage();
3332 + }
3333
3334 umask(077);
3335
3336 @@ -129,7 +140,7 @@
3337 if (!dns_domain_fromdot(&names[i],f[0].s,f[0].len)) nomem();
3338 }
3339 break;
3340 - case '+': case '=':
3341 + case '+': case '=': case '6': case '3':
3342 ttl = TTL_POSITIVE;
3343 break;
3344 case '@':
3345 @@ -203,6 +214,18 @@
3346 }
3347 break;
3348
3349 + case '6':
3350 + if (line.s[0] == '6') {
3351 + if (!dns_domain_fromdot(&d1,f[0].s,f[0].len)) nomem();
3352 + if (dns_domain_equal(d1,target))
3353 + strerr_die2x(100,FATAL,"host name already used");
3354 + if (!stralloc_0(&f[1])) nomem();
3355 + if (ip6_scan(f[1].s,ip6))
3356 + if (byte_equal(ip,16,targetip6))
3357 + strerr_die2x(100,FATAL,"IPv6 address already used");
3358 + }
3359 + break;
3360 +
3361 case '@':
3362 if (line.s[0] == '@') {
3363 if (!dns_domain_fromdot(&d1,f[0].s,f[0].len)) nomem();
3364 @@ -228,7 +251,11 @@
3365 if (!stralloc_copyb(&f[0],&mode,1)) nomem();
3366 if (!dns_domain_todot_cat(&f[0],target)) nomem();
3367 if (!stralloc_cats(&f[0],":")) nomem();
3368 - if (!stralloc_catb(&f[0],ipstr,ip4_fmt(ipstr,targetip))) nomem();
3369 + if (mode == '6' || mode == '3') {
3370 + if (!stralloc_catb(&f[0],ip6str,ip6_fmt_flat(ip6str,targetip6))) nomem();
3371 + } else {
3372 + if (!stralloc_catb(&f[0],ipstr,ip4_fmt(ipstr,targetip))) nomem();
3373 + }
3374 switch(mode) {
3375 case '.': case '&': case '@':
3376 for (i = 0;i < 26;++i)
3377 diff -uNr djbdns-1.05/tryip6.c djbdns-1.05-ipv6/tryip6.c
3378 --- djbdns-1.05/tryip6.c 1970-01-01 01:00:00.000000000 +0100
3379 +++ djbdns-1.05-ipv6/tryip6.c 2005-09-08 21:58:08.246386250 +0200
3380 @@ -0,0 +1,8 @@
3381 +#include <sys/types.h>
3382 +#include <sys/socket.h>
3383 +#include <netinet/in.h>
3384 +
3385 +main() {
3386 + struct sockaddr_in6 sa;
3387 + sa.sin6_family = PF_INET6;
3388 +}
3389 diff -uNr djbdns-1.05/tryn2i.c djbdns-1.05-ipv6/tryn2i.c
3390 --- djbdns-1.05/tryn2i.c 1970-01-01 01:00:00.000000000 +0100
3391 +++ djbdns-1.05-ipv6/tryn2i.c 2005-09-08 21:58:08.246386250 +0200
3392 @@ -0,0 +1,8 @@
3393 +#include <sys/types.h>
3394 +#include <sys/socket.h>
3395 +#include <net/if.h>
3396 +
3397 +int main() {
3398 + static char ifname[IFNAMSIZ];
3399 + char *tmp=if_indextoname(0,ifname);
3400 +}
3401 diff -uNr djbdns-1.05/trysa6.c djbdns-1.05-ipv6/trysa6.c
3402 --- djbdns-1.05/trysa6.c 1970-01-01 01:00:00.000000000 +0100
3403 +++ djbdns-1.05-ipv6/trysa6.c 2005-09-08 21:58:08.250386500 +0200
3404 @@ -0,0 +1,8 @@
3405 +#include <sys/types.h>
3406 +#include <sys/socket.h>
3407 +#include <netinet/in.h>
3408 +
3409 +main() {
3410 + struct sockaddr_in6 sa;
3411 + sa.sin6_scope_id = 1;
3412 +}