<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>buffer_read.c</filename>
    </added>
    <added>
      <filename>buffer_write.c</filename>
    </added>
    <added>
      <filename>dnstracesort.sh</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -296,3 +296,46 @@
 		dnsroots.local, then dnsroots.global.
 	ui: no longer install home/etc/dnscache.
 	version: djbdns 1.02.
+20001224
+	ui: new dnstrace output format.
+	ui: dnstrace shows all servers providing each ns/a line.
+	ui: added dnstracesort.
+20001225
+	internal: response_rstart() and response_cname() use uint32 ttl.
+	internal: added response_hidettl().
+	internal: cache_get() returns ttl.
+	internal: dnscache keeps track of ttls for aliases.
+	ui: dnscache returns ttl unless $HIDETTL is set.
+	ui: dnscache returns ttl 655360 for localhost et al.
+20001226
+	ui: dnscache supports $FORWARDONLY. tnx to several people for
+		the suggestion. tnx Dan Peterson for sample code.
+	ui: dnscache now logs sequential query numbers, not indices.
+	internal: revamped dnscache to separate udp from tcp.
+	ui: dnscache reports uactive, tactive separately.
+	ui: dnscache reports tcpopen/tcpclose by port and ip.
+	ui: dnscache artificially times out oldest UDP query if UDP
+		table is full, and oldest TCP connection if TCP table is
+		full.
+	ui: dnscache reports broken pipe when a TCP client sends FIN.
+20001228
+	ui: dnstrace supports dd.
+	ui: dnscache logs stats when it handles 1.0.0.127.in-addr.arpa.
+	ui: pickdns actively refuses queries for unknown types.
+	ui: pickdns responds to MX queries. tnx Mike Batchelor.
+	internal: added const at various places.
+	internal: removed some unused variables.
+	internal: used time_t in tai_now.c.
+	internal: used stdlib.h in alloc.c.
+	api: split dns_domain_suffix() into suffix(), suffixpos().
+	internal: switched to buffer_unix*.
+	internal: included unistd.h for various declarations.
+20010103
+	ui: increased maximum data size from 512 bytes to 32767 bytes in
+		tinydns, tinydns-get, axfrdns. allows big TXT records.
+	ui: dnsmx reformats name when it prints an artificial 0 MX.
+20010105
+	ui: increased MAXLEVEL to 5. the Internet is becoming more
+		glueless every day.
+20010106
+	version: djbdns 1.03.</diff>
      <filename>CHANGES</filename>
    </modified>
    <modified>
      <diff>@@ -45,6 +45,7 @@ random-ip.c
 dnsqr.c
 dnsq.c
 dnstrace.c
+dnstracesort.sh
 utime.c
 cachetest.c
 generic-conf.h
@@ -161,7 +162,6 @@ prot.c
 prot.h
 readclose.c
 readclose.h
-readwrite.h
 scan.h
 scan_ulong.c
 seek.h
@@ -238,3 +238,5 @@ uint32_unpack.c
 uint64.h1
 uint64.h2
 warn-shsgr
+buffer_read.c
+buffer_write.c</diff>
      <filename>FILES</filename>
    </modified>
    <modified>
      <diff>@@ -26,7 +26,7 @@ load auto-str.o buffer.a unix.a byte.a
 	./load auto-str buffer.a unix.a byte.a 
 
 auto-str.o: \
-compile auto-str.c buffer.h readwrite.h exit.h
+compile auto-str.c buffer.h exit.h
 	./compile auto-str.c
 
 auto_home.c: \
@@ -45,9 +45,9 @@ alloc.a buffer.a unix.a byte.a
 
 axfr-get.o: \
 compile axfr-get.c uint32.h uint16.h stralloc.h gen_alloc.h error.h \
-strerr.h getln.h buffer.h stralloc.h buffer.h readwrite.h exit.h \
-open.h scan.h byte.h str.h ip4.h dns.h stralloc.h iopause.h taia.h \
-tai.h uint64.h taia.h
+strerr.h getln.h buffer.h stralloc.h buffer.h exit.h open.h scan.h \
+byte.h str.h ip4.h timeoutread.h timeoutwrite.h dns.h stralloc.h \
+iopause.h taia.h tai.h uint64.h taia.h
 	./compile axfr-get.c
 
 axfrdns: \
@@ -70,10 +70,10 @@ buffer.h
 
 axfrdns.o: \
 compile axfrdns.c droproot.h exit.h env.h uint32.h uint16.h ip4.h \
-tai.h uint64.h buffer.h readwrite.h timeoutread.h timeoutwrite.h \
-open.h seek.h cdb.h uint32.h stralloc.h gen_alloc.h strerr.h str.h \
-byte.h case.h dns.h stralloc.h iopause.h taia.h tai.h taia.h \
-response.h
+tai.h uint64.h buffer.h timeoutread.h timeoutwrite.h open.h seek.h \
+cdb.h uint32.h stralloc.h gen_alloc.h strerr.h str.h byte.h case.h \
+dns.h stralloc.h iopause.h taia.h tai.h taia.h scan.h qlog.h uint16.h \
+response.h uint32.h
 	./compile axfrdns.c
 
 buffer.a: \
@@ -88,11 +88,11 @@ compile buffer.c buffer.h
 	./compile buffer.c
 
 buffer_1.o: \
-compile buffer_1.c readwrite.h buffer.h
+compile buffer_1.c buffer.h
 	./compile buffer_1.c
 
 buffer_2.o: \
-compile buffer_2.c readwrite.h buffer.h
+compile buffer_2.c buffer.h
 	./compile buffer_2.c
 
 buffer_copy.o: \
@@ -107,6 +107,14 @@ buffer_put.o: \
 compile buffer_put.c buffer.h str.h byte.h error.h
 	./compile buffer_put.c
 
+buffer_read.o: \
+compile buffer_read.c buffer.h
+	./compile buffer_read.c
+
+buffer_write.o: \
+compile buffer_write.c buffer.h
+	./compile buffer_write.c
+
 byte.a: \
 makelib byte_chr.o byte_copy.o byte_cr.o byte_diff.o byte_zero.o \
 case_diffb.o case_diffs.o case_lowerb.o fmt_ulong.o ip4_fmt.o \
@@ -141,7 +149,7 @@ compile byte_zero.c byte.h
 
 cache.o: \
 compile cache.c alloc.h byte.h uint32.h exit.h tai.h uint64.h cache.h \
-uint64.h
+uint32.h uint64.h
 	./compile cache.c
 
 cachetest: \
@@ -150,7 +158,7 @@ load cachetest.o cache.o libtai.a buffer.a alloc.a unix.a byte.a
 	byte.a 
 
 cachetest.o: \
-compile cachetest.c buffer.h exit.h cache.h uint64.h str.h
+compile cachetest.c buffer.h exit.h cache.h uint32.h uint64.h str.h
 	./compile cachetest.c
 
 case_diffb.o: \
@@ -170,7 +178,7 @@ makelib cdb.o cdb_hash.o cdb_make.o
 	./makelib cdb.a cdb.o cdb_hash.o cdb_make.o
 
 cdb.o: \
-compile cdb.c readwrite.h error.h seek.h byte.h cdb.h uint32.h
+compile cdb.c error.h seek.h byte.h cdb.h uint32.h
 	./compile cdb.c
 
 cdb_hash.o: \
@@ -178,8 +186,8 @@ compile cdb_hash.c cdb.h uint32.h
 	./compile cdb_hash.c
 
 cdb_make.o: \
-compile cdb_make.c readwrite.h seek.h error.h alloc.h cdb.h uint32.h \
-cdb_make.h buffer.h uint32.h
+compile cdb_make.c seek.h error.h alloc.h cdb.h uint32.h cdb_make.h \
+buffer.h uint32.h
 	./compile cdb_make.c
 
 check: \
@@ -300,8 +308,8 @@ taia.h tai.h uint64.h taia.h
 
 dns_transmit.o: \
 compile dns_transmit.c socket.h uint16.h alloc.h error.h byte.h \
-readwrite.h uint16.h dns.h stralloc.h gen_alloc.h iopause.h taia.h \
-tai.h uint64.h taia.h
+uint16.h dns.h stralloc.h gen_alloc.h iopause.h taia.h tai.h uint64.h \
+taia.h
 	./compile dns_transmit.c
 
 dns_txt.o: \
@@ -326,16 +334,16 @@ unix.a byte.a
 
 dnscache-conf.o: \
 compile dnscache-conf.c hasdevtcp.h strerr.h buffer.h uint32.h taia.h \
-tai.h uint64.h str.h open.h readwrite.h exit.h auto_home.h \
-generic-conf.h buffer.h
+tai.h uint64.h str.h open.h error.h exit.h auto_home.h generic-conf.h \
+buffer.h
 	./compile dnscache-conf.c
 
 dnscache.o: \
 compile dnscache.c env.h exit.h scan.h strerr.h error.h ip4.h \
-uint16.h socket.h uint16.h dns.h stralloc.h gen_alloc.h iopause.h \
-taia.h tai.h uint64.h taia.h byte.h roots.h fmt.h iopause.h query.h \
-dns.h alloc.h response.h cache.h uint64.h log.h uint64.h readwrite.h \
-okclient.h droproot.h
+uint16.h uint64.h socket.h uint16.h dns.h stralloc.h gen_alloc.h \
+iopause.h taia.h tai.h uint64.h taia.h taia.h byte.h roots.h fmt.h \
+iopause.h query.h dns.h uint32.h alloc.h response.h uint32.h cache.h \
+uint32.h uint64.h ndelay.h log.h uint64.h okclient.h droproot.h
 	./compile dnscache.c
 
 dnsfilter: \
@@ -347,8 +355,7 @@ buffer.a unix.a byte.a socket.lib
 dnsfilter.o: \
 compile dnsfilter.c strerr.h buffer.h stralloc.h gen_alloc.h alloc.h \
 dns.h stralloc.h iopause.h taia.h tai.h uint64.h taia.h ip4.h byte.h \
-scan.h taia.h sgetopt.h subgetopt.h iopause.h error.h readwrite.h \
-exit.h
+scan.h taia.h sgetopt.h subgetopt.h iopause.h error.h exit.h
 	./compile dnsfilter.c
 
 dnsip: \
@@ -380,8 +387,8 @@ byte.a socket.lib
 	buffer.a unix.a byte.a  `cat socket.lib`
 
 dnsmx.o: \
-compile dnsmx.c buffer.h exit.h strerr.h uint16.h byte.h fmt.h dns.h \
-stralloc.h gen_alloc.h iopause.h taia.h tai.h uint64.h taia.h
+compile dnsmx.c buffer.h exit.h strerr.h uint16.h byte.h str.h fmt.h \
+dns.h stralloc.h gen_alloc.h iopause.h taia.h tai.h uint64.h taia.h
 	./compile dnsmx.c
 
 dnsname: \
@@ -422,19 +429,26 @@ gen_alloc.h parsetype.h dns.h stralloc.h iopause.h taia.h
 	./compile dnsqr.c
 
 dnstrace: \
-load dnstrace.o iopause.o printrecord.o parsetype.o dns.a env.a \
+load dnstrace.o dd.o iopause.o printrecord.o parsetype.o dns.a env.a \
 libtai.a alloc.a buffer.a unix.a byte.a socket.lib
-	./load dnstrace iopause.o printrecord.o parsetype.o dns.a \
-	env.a libtai.a alloc.a buffer.a unix.a byte.a  `cat \
+	./load dnstrace dd.o iopause.o printrecord.o parsetype.o \
+	dns.a env.a libtai.a alloc.a buffer.a unix.a byte.a  `cat \
 	socket.lib`
 
 dnstrace.o: \
 compile dnstrace.c uint16.h uint32.h fmt.h str.h byte.h ip4.h \
 gen_alloc.h gen_allocdefs.h exit.h buffer.h stralloc.h gen_alloc.h \
 error.h strerr.h iopause.h taia.h tai.h uint64.h printrecord.h \
-stralloc.h parsetype.h dns.h stralloc.h iopause.h taia.h
+stralloc.h alloc.h parsetype.h dd.h dns.h stralloc.h iopause.h taia.h
 	./compile dnstrace.c
 
+dnstracesort: \
+warn-auto.sh dnstracesort.sh conf-home
+	cat warn-auto.sh dnstracesort.sh \
+	| sed s}HOME}&quot;`head -1 conf-home`&quot;}g \
+	&gt; dnstracesort
+	chmod 755 dnstracesort
+
 dnstxt: \
 load dnstxt.o iopause.o dns.a env.a libtai.a alloc.a buffer.a unix.a \
 byte.a socket.lib
@@ -471,8 +485,8 @@ compile fmt_ulong.c fmt.h
 	./compile fmt_ulong.c
 
 generic-conf.o: \
-compile generic-conf.c strerr.h buffer.h readwrite.h open.h \
-generic-conf.h buffer.h
+compile generic-conf.c strerr.h buffer.h open.h generic-conf.h \
+buffer.h
 	./compile generic-conf.c
 
 getln.o: \
@@ -509,7 +523,7 @@ load install.o hier.o auto_home.o buffer.a unix.a byte.a
 	./load install hier.o auto_home.o buffer.a unix.a byte.a 
 
 install.o: \
-compile install.c buffer.h strerr.h error.h open.h readwrite.h exit.h
+compile install.c buffer.h strerr.h error.h open.h exit.h
 	./compile install.c
 
 instcheck: \
@@ -517,7 +531,7 @@ load instcheck.o hier.o auto_home.o buffer.a unix.a byte.a
 	./load instcheck hier.o auto_home.o buffer.a unix.a byte.a 
 
 instcheck.o: \
-compile instcheck.c strerr.h error.h readwrite.h exit.h
+compile instcheck.c strerr.h error.h exit.h
 	./compile instcheck.c
 
 iopause.h: \
@@ -608,7 +622,7 @@ gen_alloc.h openreadclose.h stralloc.h
 
 parsetype.o: \
 compile parsetype.c scan.h byte.h case.h dns.h stralloc.h gen_alloc.h \
-iopause.h taia.h tai.h uint64.h taia.h parsetype.h
+iopause.h taia.h tai.h uint64.h taia.h uint16.h parsetype.h
 	./compile parsetype.c
 
 pickdns: \
@@ -634,22 +648,22 @@ load pickdns-data.o cdb.a dns.a alloc.a buffer.a unix.a byte.a
 	byte.a 
 
 pickdns-data.o: \
-compile pickdns-data.c buffer.h readwrite.h exit.h cdb_make.h \
-buffer.h uint32.h open.h alloc.h gen_allocdefs.h stralloc.h \
-gen_alloc.h getln.h buffer.h stralloc.h strerr.h str.h byte.h scan.h \
-fmt.h ip4.h dns.h stralloc.h iopause.h taia.h tai.h uint64.h taia.h
+compile pickdns-data.c buffer.h exit.h cdb_make.h buffer.h uint32.h \
+open.h alloc.h gen_allocdefs.h stralloc.h gen_alloc.h getln.h \
+buffer.h stralloc.h case.h strerr.h str.h byte.h scan.h fmt.h ip4.h \
+dns.h stralloc.h iopause.h taia.h tai.h uint64.h taia.h
 	./compile pickdns-data.c
 
 pickdns.o: \
 compile pickdns.c byte.h case.h dns.h stralloc.h gen_alloc.h \
 iopause.h taia.h tai.h uint64.h taia.h open.h cdb.h uint32.h \
-response.h
+response.h uint32.h
 	./compile pickdns.c
 
 printpacket.o: \
 compile printpacket.c uint16.h uint32.h error.h byte.h dns.h \
 stralloc.h gen_alloc.h iopause.h taia.h tai.h uint64.h taia.h \
-printpacket.h stralloc.h
+printrecord.h stralloc.h printpacket.h stralloc.h
 	./compile printpacket.c
 
 printrecord.o: \
@@ -663,7 +677,7 @@ dnscache-conf dnscache walldns-conf walldns rbldns-conf rbldns \
 rbldns-data pickdns-conf pickdns pickdns-data tinydns-conf tinydns \
 tinydns-data tinydns-get tinydns-edit axfr-get axfrdns-conf axfrdns \
 dnsip dnsipq dnsname dnstxt dnsmx dnsfilter random-ip dnsqr dnsq \
-dnstrace cachetest utime rts
+dnstrace dnstracesort cachetest utime rts
 
 prot.o: \
 compile prot.c hasshsgr.h prot.h
@@ -675,9 +689,9 @@ compile qlog.c buffer.h qlog.h uint16.h
 
 query.o: \
 compile query.c error.h roots.h log.h uint64.h case.h cache.h \
-uint64.h byte.h dns.h stralloc.h gen_alloc.h iopause.h taia.h tai.h \
-uint64.h taia.h uint64.h uint32.h uint16.h dd.h alloc.h response.h \
-query.h dns.h
+uint32.h uint64.h byte.h dns.h stralloc.h gen_alloc.h iopause.h \
+taia.h tai.h uint64.h taia.h uint64.h uint32.h uint16.h dd.h alloc.h \
+response.h uint32.h query.h dns.h uint32.h
 	./compile query.c
 
 random-ip: \
@@ -711,31 +725,30 @@ load rbldns-data.o cdb.a alloc.a buffer.a unix.a byte.a
 	./load rbldns-data cdb.a alloc.a buffer.a unix.a byte.a 
 
 rbldns-data.o: \
-compile rbldns-data.c buffer.h readwrite.h exit.h cdb_make.h buffer.h \
-uint32.h open.h stralloc.h gen_alloc.h getln.h buffer.h stralloc.h \
-strerr.h byte.h scan.h fmt.h ip4.h
+compile rbldns-data.c buffer.h exit.h cdb_make.h buffer.h uint32.h \
+open.h stralloc.h gen_alloc.h getln.h buffer.h stralloc.h strerr.h \
+byte.h scan.h fmt.h ip4.h
 	./compile rbldns-data.c
 
 rbldns.o: \
 compile rbldns.c str.h byte.h ip4.h open.h env.h cdb.h uint32.h dns.h \
 stralloc.h gen_alloc.h iopause.h taia.h tai.h uint64.h taia.h dd.h \
-strerr.h response.h
+strerr.h response.h uint32.h
 	./compile rbldns.c
 
 readclose.o: \
-compile readclose.c readwrite.h error.h readclose.h stralloc.h \
-gen_alloc.h
+compile readclose.c error.h readclose.h stralloc.h gen_alloc.h
 	./compile readclose.c
 
 response.o: \
 compile response.c dns.h stralloc.h gen_alloc.h iopause.h taia.h \
-tai.h uint64.h taia.h byte.h uint16.h response.h
+tai.h uint64.h taia.h byte.h uint16.h response.h uint32.h
 	./compile response.c
 
 roots.o: \
-compile roots.c open.h error.h str.h byte.h readwrite.h error.h \
-direntry.h ip4.h dns.h stralloc.h gen_alloc.h iopause.h taia.h tai.h \
-uint64.h taia.h openreadclose.h stralloc.h roots.h
+compile roots.c open.h error.h str.h byte.h error.h direntry.h ip4.h \
+dns.h stralloc.h gen_alloc.h iopause.h taia.h tai.h uint64.h taia.h \
+openreadclose.h stralloc.h roots.h
 	./compile roots.c
 
 rts: \
@@ -759,8 +772,8 @@ choose compile trysysel.c select.h1 select.h2
 
 server.o: \
 compile server.c byte.h case.h env.h strerr.h ip4.h uint16.h ndelay.h \
-socket.h uint16.h droproot.h qlog.h uint16.h response.h dns.h \
-stralloc.h gen_alloc.h iopause.h taia.h tai.h uint64.h taia.h
+socket.h uint16.h droproot.h qlog.h uint16.h response.h uint32.h \
+dns.h stralloc.h gen_alloc.h iopause.h taia.h tai.h uint64.h taia.h
 	./compile server.c
 
 setup: \
@@ -787,7 +800,7 @@ compile socket_bind.c byte.h socket.h uint16.h
 	./compile socket_bind.c
 
 socket_conn.o: \
-compile socket_conn.c readwrite.h byte.h socket.h uint16.h
+compile socket_conn.c byte.h socket.h uint16.h
 	./compile socket_conn.c
 
 socket_listen.o: \
@@ -951,17 +964,17 @@ compile taia_uint.c taia.h tai.h uint64.h
 tdlookup.o: \
 compile tdlookup.c uint16.h open.h tai.h uint64.h cdb.h uint32.h \
 byte.h case.h dns.h stralloc.h gen_alloc.h iopause.h taia.h tai.h \
-taia.h seek.h response.h
+taia.h seek.h response.h uint32.h
 	./compile tdlookup.c
 
 timeoutread.o: \
 compile timeoutread.c error.h iopause.h taia.h tai.h uint64.h \
-readwrite.h timeoutread.h
+timeoutread.h
 	./compile timeoutread.c
 
 timeoutwrite.o: \
 compile timeoutwrite.c error.h iopause.h taia.h tai.h uint64.h \
-readwrite.h timeoutwrite.h
+timeoutwrite.h
 	./compile timeoutwrite.c
 
 tinydns: \
@@ -989,7 +1002,7 @@ load tinydns-data.o cdb.a dns.a alloc.a buffer.a unix.a byte.a
 
 tinydns-data.o: \
 compile tinydns-data.c uint16.h uint32.h str.h byte.h fmt.h ip4.h \
-exit.h readwrite.h buffer.h strerr.h getln.h buffer.h stralloc.h \
+exit.h case.h scan.h buffer.h strerr.h getln.h buffer.h stralloc.h \
 gen_alloc.h cdb_make.h buffer.h uint32.h stralloc.h open.h dns.h \
 stralloc.h iopause.h taia.h tai.h uint64.h taia.h
 	./compile tinydns-data.c
@@ -999,9 +1012,9 @@ load tinydns-edit.o dns.a alloc.a buffer.a unix.a byte.a
 	./load tinydns-edit dns.a alloc.a buffer.a unix.a byte.a 
 
 tinydns-edit.o: \
-compile tinydns-edit.c stralloc.h gen_alloc.h buffer.h readwrite.h \
-exit.h getln.h buffer.h stralloc.h strerr.h scan.h byte.h str.h fmt.h \
-ip4.h dns.h stralloc.h iopause.h taia.h tai.h uint64.h taia.h
+compile tinydns-edit.c stralloc.h gen_alloc.h buffer.h exit.h open.h \
+getln.h buffer.h stralloc.h strerr.h scan.h byte.h str.h fmt.h ip4.h \
+dns.h stralloc.h iopause.h taia.h tai.h uint64.h taia.h
 	./compile tinydns-edit.c
 
 tinydns-get: \
@@ -1013,9 +1026,9 @@ parsetype.o libtai.a cdb.a dns.a buffer.a alloc.a unix.a byte.a
 
 tinydns-get.o: \
 compile tinydns-get.c str.h byte.h scan.h exit.h stralloc.h \
-gen_alloc.h buffer.h strerr.h uint16.h response.h printpacket.h \
-stralloc.h parsetype.h dns.h stralloc.h iopause.h taia.h tai.h \
-uint64.h taia.h
+gen_alloc.h buffer.h strerr.h uint16.h response.h uint32.h case.h \
+printpacket.h stralloc.h parsetype.h dns.h stralloc.h iopause.h \
+taia.h tai.h uint64.h taia.h
 	./compile tinydns-get.c
 
 tinydns.o: \
@@ -1053,12 +1066,12 @@ unix.a: \
 makelib error.o error_str.o ndelay_off.o ndelay_on.o open_read.o \
 open_trunc.o openreadclose.o readclose.o seek_set.o socket_accept.o \
 socket_bind.o socket_conn.o socket_listen.o socket_recv.o \
-socket_send.o socket_tcp.o socket_udp.o
+socket_send.o socket_tcp.o socket_udp.o buffer_read.o buffer_write.o
 	./makelib unix.a error.o error_str.o ndelay_off.o \
 	ndelay_on.o open_read.o open_trunc.o openreadclose.o \
 	readclose.o seek_set.o socket_accept.o socket_bind.o \
 	socket_conn.o socket_listen.o socket_recv.o socket_send.o \
-	socket_tcp.o socket_udp.o
+	socket_tcp.o socket_udp.o buffer_read.o buffer_write.o
 
 utime: \
 load utime.o byte.a
@@ -1087,5 +1100,5 @@ buffer.h
 
 walldns.o: \
 compile walldns.c byte.h dns.h stralloc.h gen_alloc.h iopause.h \
-taia.h tai.h uint64.h taia.h dd.h response.h
+taia.h tai.h uint64.h taia.h dd.h response.h uint32.h
 	./compile walldns.c</diff>
      <filename>Makefile</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
-djbdns 1.02
-20000923
-Copyright 2000
+djbdns 1.03
+20010106
+Copyright 2001
 D. J. Bernstein
 
 djbdns home page: http://cr.yp.to/djbdns.html</diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -18,6 +18,8 @@ buffer_put.o
 strerr_die.o
 strerr_sys.o
 buffer.a
+buffer_read.o
+buffer_write.o
 error.o
 error_str.o
 ndelay_off.o
@@ -197,6 +199,7 @@ dnsq.o
 dnsq
 dnstrace.o
 dnstrace
+dnstracesort
 cachetest.o
 cachetest
 utime.o</diff>
      <filename>TARGETS</filename>
    </modified>
    <modified>
      <diff>@@ -1,9 +1,13 @@
 end-to-end nym-based security
 link-level security
 
-consider dd in dnstrace
-
 try to get the root authorities to set up a secure, usable NS-list system
+have dnscache-conf keep track of copies of dnsroots.global
 incorporate automatic NS-list upgrades
 
+consider merging pickdns and tinydns
+
+consider dead-server table in dnscache
+
+IPv6 records
 DNS over IPv6</diff>
      <filename>TODO</filename>
    </modified>
    <modified>
      <diff>@@ -1 +1 @@
-djbdns 1.02
+djbdns 1.03</diff>
      <filename>VERSION</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,6 @@
+#include &lt;stdlib.h&gt;
 #include &quot;alloc.h&quot;
 #include &quot;error.h&quot;
-extern char *malloc();
-extern void free();
 
 #define ALIGNMENT 16 /* XXX: assuming that this alignment is enough */
 #define SPACE 2048 /* must be multiple of ALIGNMENT */</diff>
      <filename>alloc.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,16 +1,15 @@
 #include &quot;buffer.h&quot;
-#include &quot;readwrite.h&quot;
 #include &quot;exit.h&quot;
 
 char bspace[256];
-buffer b = BUFFER_INIT(write,1,bspace,sizeof bspace);
+buffer b = BUFFER_INIT(buffer_unixwrite,1,bspace,sizeof bspace);
 
-void puts(char *s)
+void puts(const char *s)
 {
   if (buffer_puts(&amp;b,s) == -1) _exit(111);
 }
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   char *name;
   char *value;
@@ -22,7 +21,7 @@ main(int argc,char **argv)
   value = argv[2];
   if (!value) _exit(100);
 
-  puts(&quot;char &quot;);
+  puts(&quot;const char &quot;);
   puts(name);
   puts(&quot;[] = \&quot;\\\n&quot;);
 </diff>
      <filename>auto-str.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #ifndef AUTO_HOME_H
 #define AUTO_HOME_H
 
-extern char auto_home[];
+extern const char auto_home[];
 
 #endif</diff>
      <filename>auto_home.h</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,5 @@
+#include &lt;stdio.h&gt;
+#include &lt;unistd.h&gt;
 #include &quot;uint32.h&quot;
 #include &quot;uint16.h&quot;
 #include &quot;stralloc.h&quot;
@@ -5,13 +7,14 @@
 #include &quot;strerr.h&quot;
 #include &quot;getln.h&quot;
 #include &quot;buffer.h&quot;
-#include &quot;readwrite.h&quot;
 #include &quot;exit.h&quot;
 #include &quot;open.h&quot;
 #include &quot;scan.h&quot;
 #include &quot;byte.h&quot;
 #include &quot;str.h&quot;
 #include &quot;ip4.h&quot;
+#include &quot;timeoutread.h&quot;
+#include &quot;timeoutwrite.h&quot;
 #include &quot;dns.h&quot;
 
 #define FATAL &quot;axfr-get: fatal: &quot;
@@ -249,7 +252,7 @@ unsigned int doit(char *buf,unsigned int len,unsigned int pos)
 
 stralloc packet;
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   char out[20];
   unsigned long u;
@@ -276,7 +279,7 @@ main(int argc,char **argv)
     if (errno != error_noent) die_read();
   }
   else {
-    buffer_init(&amp;b,read,fd,bspace,sizeof bspace);
+    buffer_init(&amp;b,buffer_unixread,fd,bspace,sizeof bspace);
     if (getln(&amp;b,&amp;line,&amp;match,'\n') == -1) die_read();
     if (!stralloc_0(&amp;line)) die_read();
     if (line.s[0] == '#') {
@@ -329,7 +332,7 @@ main(int argc,char **argv)
 
   fd = open_trunc(fntmp);
   if (fd == -1) die_write();
-  buffer_init(&amp;b,write,fd,bspace,sizeof bspace);
+  buffer_init(&amp;b,buffer_unixwrite,fd,bspace,sizeof bspace);
 
   if (!stralloc_copyb(&amp;packet,&quot;\0\0\0\0\0\1\0\0\0\0\0\0&quot;,12)) die_generate();
   if (!stralloc_catb(&amp;packet,zone,zonelen)) die_generate();</diff>
      <filename>axfr-get.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+#include &lt;unistd.h&gt;
 #include &lt;pwd.h&gt;
 #include &quot;strerr.h&quot;
 #include &quot;exit.h&quot;
@@ -18,7 +19,7 @@ struct passwd *pw;
 char *myip;
 char *tinydns;
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   user = argv[1];
   if (!user) usage();
@@ -49,7 +50,7 @@ main(int argc,char **argv)
 
   start(&quot;run&quot;);
   outs(&quot;#!/bin/sh\nexec 2&gt;&amp;1\nexec envdir ./env sh -c '\n  exec envuidgid &quot;); outs(user);
-  outs(&quot; softlimit -d250000 tcpserver -vDRHl0 -x tcp.cdb -- \&quot;$IP\&quot; 53 &quot;);
+  outs(&quot; softlimit -d300000 tcpserver -vDRHl0 -x tcp.cdb -- \&quot;$IP\&quot; 53 &quot;);
   outs(auto_home); outs(&quot;/bin/axfrdns\n'\n&quot;);
   finish();
   perm(0755);</diff>
      <filename>axfrdns-conf.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+#include &lt;unistd.h&gt;
 #include &quot;droproot.h&quot;
 #include &quot;exit.h&quot;
 #include &quot;env.h&quot;
@@ -6,7 +7,6 @@
 #include &quot;ip4.h&quot;
 #include &quot;tai.h&quot;
 #include &quot;buffer.h&quot;
-#include &quot;readwrite.h&quot;
 #include &quot;timeoutread.h&quot;
 #include &quot;timeoutwrite.h&quot;
 #include &quot;open.h&quot;
@@ -18,6 +18,8 @@
 #include &quot;byte.h&quot;
 #include &quot;case.h&quot;
 #include &quot;dns.h&quot;
+#include &quot;scan.h&quot;
+#include &quot;qlog.h&quot;
 #include &quot;response.h&quot;
 
 #define FATAL &quot;axfrdns: fatal: &quot;
@@ -120,7 +122,7 @@ void get(char *buf,unsigned int len)
 }
 
 struct tai now;
-char data[512];
+char data[32767];
 uint32 dlen;
 uint32 dpos;
 
@@ -140,7 +142,6 @@ void doname(stralloc *sa)
 
 int build(stralloc *sa,char *q,int flagsoa)
 {
-  static char *d1;
   unsigned int rdatapos;
   char misc[20];
   char type[2];
@@ -206,9 +207,8 @@ static char *q;
 static stralloc soa;
 static stralloc message;
 
-void doaxfr(int fdcdb)
+void doaxfr(void)
 {
-  char misc[20];
   char key[512];
   uint32 klen;
   char num[4];
@@ -234,7 +234,7 @@ void doaxfr(int fdcdb)
   print(soa.s,soa.len);
 
   seek_begin(fdcdb);
-  buffer_init(&amp;bcdb,read,fdcdb,bcdbspace,sizeof bcdbspace);
+  buffer_init(&amp;bcdb,buffer_unixread,fdcdb,bcdbspace,sizeof bcdbspace);
 
   pos = 0;
   get(num,4); pos += 4;
@@ -252,9 +252,9 @@ void doaxfr(int fdcdb)
     if (eod - pos &lt; dlen) die_cdbformat();
     pos += dlen;
 
-    if (klen &gt; 512) die_cdbformat();
+    if (klen &gt; sizeof key) die_cdbformat();
     get(key,klen);
-    if (dlen &gt; 512) die_cdbformat();
+    if (dlen &gt; sizeof data) die_cdbformat();
     get(data,dlen);
 
     if (klen &lt; 1) die_cdbformat();
@@ -286,12 +286,12 @@ char tcpheader[2];
 char buf[512];
 uint16 len;
 
-main()
+int main()
 {
   unsigned int pos;
   char header[12];
   char qtype[2];
-  char *x;
+  const char *x;
 
   droproot(FATAL);
 
@@ -327,7 +327,7 @@ main()
       case_lowerb(zone,zonelen);
       fdcdb = open_read(&quot;data.cdb&quot;);
       if (fdcdb == -1) die_cdbread();
-      doaxfr(fdcdb);
+      doaxfr();
       close(fdcdb);
     }
     else {</diff>
      <filename>axfrdns.c</filename>
    </modified>
    <modified>
      <diff>@@ -16,12 +16,12 @@ typedef struct buffer {
 extern void buffer_init(buffer *,int (*)(),int,char *,unsigned int);
 
 extern int buffer_flush(buffer *);
-extern int buffer_put(buffer *,char *,unsigned int);
-extern int buffer_putalign(buffer *,char *,unsigned int);
-extern int buffer_putflush(buffer *,char *,unsigned int);
-extern int buffer_puts(buffer *,char *);
-extern int buffer_putsalign(buffer *,char *);
-extern int buffer_putsflush(buffer *,char *);
+extern int buffer_put(buffer *,const char *,unsigned int);
+extern int buffer_putalign(buffer *,const char *,unsigned int);
+extern int buffer_putflush(buffer *,const char *,unsigned int);
+extern int buffer_puts(buffer *,const char *);
+extern int buffer_putsalign(buffer *,const char *);
+extern int buffer_putsflush(buffer *,const char *);
 
 #define buffer_PUTC(s,c) \
   ( ((s)-&gt;n != (s)-&gt;p) \
@@ -47,6 +47,9 @@ extern void buffer_seek(buffer *,unsigned int);
 
 extern int buffer_copy(buffer *,buffer *);
 
+extern int buffer_unixread(int,char *,unsigned int);
+extern int buffer_unixwrite(int,const char *,unsigned int);
+
 extern buffer *buffer_0;
 extern buffer *buffer_0small;
 extern buffer *buffer_1;</diff>
      <filename>buffer.h</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,5 @@
-#include &quot;readwrite.h&quot;
 #include &quot;buffer.h&quot;
 
 char buffer_1_space[BUFFER_OUTSIZE];
-static buffer it = BUFFER_INIT(write,1,buffer_1_space,sizeof buffer_1_space);
+static buffer it = BUFFER_INIT(buffer_unixwrite,1,buffer_1_space,sizeof buffer_1_space);
 buffer *buffer_1 = &amp;it;</diff>
      <filename>buffer_1.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,5 @@
-#include &quot;readwrite.h&quot;
 #include &quot;buffer.h&quot;
 
 char buffer_2_space[256];
-static buffer it = BUFFER_INIT(write,2,buffer_2_space,sizeof buffer_2_space);
+static buffer it = BUFFER_INIT(buffer_unixwrite,2,buffer_2_space,sizeof buffer_2_space);
 buffer *buffer_2 = &amp;it;</diff>
      <filename>buffer_2.c</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,7 @@
 #include &quot;byte.h&quot;
 #include &quot;error.h&quot;
 
-static int allwrite(int (*op)(),int fd,char *buf,unsigned int len)
+static int allwrite(int (*op)(),int fd,const char *buf,unsigned int len)
 {
   int w;
 
@@ -30,7 +30,7 @@ int buffer_flush(buffer *s)
   return allwrite(s-&gt;op,s-&gt;fd,s-&gt;x,p);
 }
 
-int buffer_putalign(buffer *s,char *buf,unsigned int len)
+int buffer_putalign(buffer *s,const char *buf,unsigned int len)
 {
   unsigned int n;
  
@@ -44,7 +44,7 @@ int buffer_putalign(buffer *s,char *buf,unsigned int len)
   return 0;
 }
 
-int buffer_put(buffer *s,char *buf,unsigned int len)
+int buffer_put(buffer *s,const char *buf,unsigned int len)
 {
   unsigned int n;
  
@@ -66,23 +66,23 @@ int buffer_put(buffer *s,char *buf,unsigned int len)
   return 0;
 }
 
-int buffer_putflush(buffer *s,char *buf,unsigned int len)
+int buffer_putflush(buffer *s,const char *buf,unsigned int len)
 {
   if (buffer_flush(s) == -1) return -1;
   return allwrite(s-&gt;op,s-&gt;fd,buf,len);
 }
 
-int buffer_putsalign(buffer *s,char *buf)
+int buffer_putsalign(buffer *s,const char *buf)
 {
   return buffer_putalign(s,buf,str_len(buf));
 }
 
-int buffer_puts(buffer *s,char *buf)
+int buffer_puts(buffer *s,const char *buf)
 {
   return buffer_put(s,buf,str_len(buf));
 }
 
-int buffer_putsflush(buffer *s,char *buf)
+int buffer_putsflush(buffer *s,const char *buf)
 {
   return buffer_putflush(s,buf,str_len(buf));
 }</diff>
      <filename>buffer_put.c</filename>
    </modified>
    <modified>
      <diff>@@ -62,7 +62,7 @@ static uint32 get4(uint32 pos)
   return result;
 }
 
-static unsigned int hash(char *key,unsigned int keylen)
+static unsigned int hash(const char *key,unsigned int keylen)
 {
   unsigned int result = 5381;
 
@@ -77,7 +77,7 @@ static unsigned int hash(char *key,unsigned int keylen)
   return result;
 }
 
-char *cache_get(char *key,unsigned int keylen,unsigned int *datalen)
+char *cache_get(const char *key,unsigned int keylen,unsigned int *datalen,uint32 *ttl)
 {
   struct tai expire;
   struct tai now;
@@ -86,6 +86,7 @@ char *cache_get(char *key,unsigned int keylen,unsigned int *datalen)
   uint32 nextpos;
   uint32 u;
   unsigned int loop;
+  double d;
 
   if (!x) return 0;
   if (keylen &gt; MAXKEYLEN) return 0;
@@ -102,9 +103,15 @@ char *cache_get(char *key,unsigned int keylen,unsigned int *datalen)
         tai_now(&amp;now);
         if (tai_less(&amp;expire,&amp;now)) return 0;
 
+        tai_sub(&amp;expire,&amp;expire,&amp;now);
+        d = tai_approx(&amp;expire);
+        if (d &gt; 604800) d = 604800;
+        *ttl = d;
+
         u = get4(pos + 8);
         if (u &gt; size - pos - 20 - keylen) cache_impossible();
         *datalen = u;
+
         return x + pos + 20 + keylen;
       }
     }
@@ -117,7 +124,7 @@ char *cache_get(char *key,unsigned int keylen,unsigned int *datalen)
   return 0;
 }
 
-void cache_set(char *key,unsigned int keylen,char *data,unsigned int datalen,unsigned int ttl)
+void cache_set(const char *key,unsigned int keylen,const char *data,unsigned int datalen,uint32 ttl)
 {
   struct tai now;
   struct tai expire;</diff>
      <filename>cache.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,11 +1,12 @@
 #ifndef CACHE_H
 #define CACHE_H
 
+#include &quot;uint32.h&quot;
 #include &quot;uint64.h&quot;
 
 extern uint64 cache_motion;
 extern int cache_init(unsigned int);
-extern void cache_set(char *,unsigned int,char *,unsigned int,unsigned int);
-extern char *cache_get(char *,unsigned int,unsigned int *);
+extern void cache_set(const char *,unsigned int,const char *,unsigned int,uint32);
+extern char *cache_get(const char *,unsigned int,unsigned int *,uint32 *);
 
 #endif</diff>
      <filename>cache.h</filename>
    </modified>
    <modified>
      <diff>@@ -3,12 +3,13 @@
 #include &quot;cache.h&quot;
 #include &quot;str.h&quot;
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   int i;
   char *x;
   char *y;
   unsigned int u;
+  uint32 ttl;
 
   if (!cache_init(200)) _exit(111);
 
@@ -19,7 +20,7 @@ main(int argc,char **argv)
     if (x[i])
       cache_set(x,i,x + i + 1,str_len(x) - i - 1,86400);
     else {
-      y = cache_get(x,i,&amp;u);
+      y = cache_get(x,i,&amp;u,&amp;ttl);
       if (y)
         buffer_put(buffer_1,y,u);
       buffer_puts(buffer_1,&quot;\n&quot;);</diff>
      <filename>cachetest.c</filename>
    </modified>
    <modified>
      <diff>@@ -3,10 +3,10 @@
 
 extern void case_lowers(char *);
 extern void case_lowerb(char *,unsigned int);
-extern int case_diffs(char *,char *);
-extern int case_diffb(char *,unsigned int,char *);
-extern int case_starts(char *,char *);
-extern int case_startb(char *,unsigned int,char *);
+extern int case_diffs(const char *,const char *);
+extern int case_diffb(const char *,unsigned int,const char *);
+extern int case_starts(const char *,const char *);
+extern int case_startb(const char *,unsigned int,const char *);
 
 #define case_equals(s,t) (!case_diffs((s),(t)))
 </diff>
      <filename>case.h</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #include &quot;case.h&quot;
 
-int case_diffb(register char *s,register unsigned int len,register char *t)
+int case_diffb(register const char *s,register unsigned int len,register const char *t)
 {
   register unsigned char x;
   register unsigned char y;</diff>
      <filename>case_diffb.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #include &quot;case.h&quot;
 
-int case_diffs(register char *s,register char *t)
+int case_diffs(register const char *s,register const char *t)
 {
   register unsigned char x;
   register unsigned char y;</diff>
      <filename>case_diffs.c</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,7 @@
 #include &lt;sys/types.h&gt;
 #include &lt;sys/stat.h&gt;
 #include &lt;sys/mman.h&gt;
-#include &quot;readwrite.h&quot;
+#include &lt;unistd.h&gt;
 #include &quot;error.h&quot;
 #include &quot;seek.h&quot;
 #include &quot;byte.h&quot;
@@ -67,7 +67,7 @@ int cdb_read(struct cdb *c,char *buf,unsigned int len,uint32 pos)
   return -1;
 }
 
-static int match(struct cdb *c,char *key,unsigned int len,uint32 pos)
+static int match(struct cdb *c,const char *key,unsigned int len,uint32 pos)
 {
   char buf[32];
   int n;
@@ -84,7 +84,7 @@ static int match(struct cdb *c,char *key,unsigned int len,uint32 pos)
   return 1;
 }
 
-int cdb_findnext(struct cdb *c,char *key,unsigned int len)
+int cdb_findnext(struct cdb *c,const char *key,unsigned int len)
 {
   char buf[8];
   uint32 pos;
@@ -129,7 +129,7 @@ int cdb_findnext(struct cdb *c,char *key,unsigned int len)
   return 0;
 }
 
-int cdb_find(struct cdb *c,char *key,unsigned int len)
+int cdb_find(struct cdb *c,const char *key,unsigned int len)
 {
   cdb_findstart(c);
   return cdb_findnext(c,key,len);</diff>
      <filename>cdb.c</filename>
    </modified>
    <modified>
      <diff>@@ -7,7 +7,7 @@
 
 #define CDB_HASHSTART 5381
 extern uint32 cdb_hashadd(uint32,unsigned char);
-extern uint32 cdb_hash(char *,unsigned int);
+extern uint32 cdb_hash(const char *,unsigned int);
 
 struct cdb {
   char *map; /* 0 if no map is available */
@@ -28,8 +28,8 @@ extern void cdb_init(struct cdb *,int fd);
 extern int cdb_read(struct cdb *,char *,unsigned int,uint32);
 
 extern void cdb_findstart(struct cdb *);
-extern int cdb_findnext(struct cdb *,char *,unsigned int);
-extern int cdb_find(struct cdb *,char *,unsigned int);
+extern int cdb_findnext(struct cdb *,const char *,unsigned int);
+extern int cdb_find(struct cdb *,const char *,unsigned int);
 
 #define cdb_datapos(c) ((c)-&gt;dpos)
 #define cdb_datalen(c) ((c)-&gt;dlen)</diff>
      <filename>cdb.h</filename>
    </modified>
    <modified>
      <diff>@@ -8,7 +8,7 @@ uint32 cdb_hashadd(uint32 h,unsigned char c)
   return h ^ c;
 }
 
-uint32 cdb_hash(char *buf,unsigned int len)
+uint32 cdb_hash(const char *buf,unsigned int len)
 {
   uint32 h;
 </diff>
      <filename>cdb_hash.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,5 @@
 /* Public domain. */
 
-#include &quot;readwrite.h&quot;
 #include &quot;seek.h&quot;
 #include &quot;error.h&quot;
 #include &quot;alloc.h&quot;
@@ -15,7 +14,7 @@ int cdb_make_start(struct cdb_make *c,int fd)
   c-&gt;numentries = 0;
   c-&gt;fd = fd;
   c-&gt;pos = sizeof c-&gt;final;
-  buffer_init(&amp;c-&gt;b,write,fd,c-&gt;bspace,sizeof c-&gt;bspace);
+  buffer_init(&amp;c-&gt;b,buffer_unixwrite,fd,c-&gt;bspace,sizeof c-&gt;bspace);
   return seek_set(fd,c-&gt;pos);
 }
 
@@ -62,7 +61,7 @@ int cdb_make_addbegin(struct cdb_make *c,unsigned int keylen,unsigned int datale
   return 0;
 }
 
-int cdb_make_add(struct cdb_make *c,char *key,unsigned int keylen,char *data,unsigned int datalen)
+int cdb_make_add(struct cdb_make *c,const char *key,unsigned int keylen,const char *data,unsigned int datalen)
 {
   if (cdb_make_addbegin(c,keylen,datalen) == -1) return -1;
   if (buffer_putalign(&amp;c-&gt;b,key,keylen) == -1) return -1;</diff>
      <filename>cdb_make.c</filename>
    </modified>
    <modified>
      <diff>@@ -33,7 +33,7 @@ struct cdb_make {
 extern int cdb_make_start(struct cdb_make *,int);
 extern int cdb_make_addbegin(struct cdb_make *,unsigned int,unsigned int);
 extern int cdb_make_addend(struct cdb_make *,unsigned int,unsigned int,uint32);
-extern int cdb_make_add(struct cdb_make *,char *,unsigned int,char *,unsigned int);
+extern int cdb_make_add(struct cdb_make *,const char *,unsigned int,const char *,unsigned int);
 extern int cdb_make_finish(struct cdb_make *);
 
 #endif</diff>
      <filename>cdb_make.h</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #include &quot;exit.h&quot;
 
-main()
+int main()
 {
   short x[4];
 </diff>
      <filename>chkshsgr.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,3 @@
-gcc -O2
+gcc -O2 -Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized -Wshadow -Wcast-qual -Wcast-align -Wwrite-strings
 
 This will be used to compile .c files.</diff>
      <filename>conf-cc</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 #include &quot;dns.h&quot;
 #include &quot;dd.h&quot;
 
-int dd(char *q,char *base,char ip[4])
+int dd(const char *q,const char *base,char ip[4])
 {
   int j;
   unsigned int x;</diff>
      <filename>dd.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #ifndef DD_H
 #define DD_H
 
-extern int dd(char *,char *,char *);
+extern int dd(const char *,const char *,char *);
 
 #endif</diff>
      <filename>dd.h</filename>
    </modified>
    <modified>
      <diff>@@ -34,51 +34,51 @@ struct dns_transmit {
   unsigned int curserver;
   struct taia deadline;
   unsigned int pos;
-  char *servers;
+  const char *servers;
   char localip[4];
   char qtype[2];
 } ;
 
-extern void dns_random_init(char *);
+extern void dns_random_init(const char *);
 extern unsigned int dns_random(unsigned int);
 
 extern void dns_sortip(char *,unsigned int);
 
 extern void dns_domain_free(char **);
-extern int dns_domain_copy(char **,char *);
-extern unsigned int dns_domain_length(char *);
-extern int dns_domain_equal(char *,char *);
-extern char *dns_domain_suffix(char *,char *);
-extern int dns_domain_fromdot(char **,char *,unsigned int);
-extern int dns_domain_todot_cat(stralloc *,char *);
+extern int dns_domain_copy(char **,const char *);
+extern unsigned int dns_domain_length(const char *);
+extern int dns_domain_equal(const char *,const char *);
+extern int dns_domain_suffix(const char *,const char *);
+extern unsigned int dns_domain_suffixpos(const char *,const char *);
+extern int dns_domain_fromdot(char **,const char *,unsigned int);
+extern int dns_domain_todot_cat(stralloc *,const char *);
 
-extern unsigned int dns_packet_copy(char *,unsigned int,unsigned int,char *,unsigned int);
-extern unsigned int dns_packet_getname(char *,unsigned int,unsigned int,char **);
-extern unsigned int dns_packet_skipname(char *,unsigned int,unsigned int);
-extern int dns_packet_nameequal(char *,unsigned int,unsigned int,char *,unsigned int,unsigned int);
+extern unsigned int dns_packet_copy(const char *,unsigned int,unsigned int,char *,unsigned int);
+extern unsigned int dns_packet_getname(const char *,unsigned int,unsigned int,char **);
+extern unsigned int dns_packet_skipname(const char *,unsigned int,unsigned int);
 
-extern int dns_transmit_start(struct dns_transmit *,char *,int,char *,char *,char *);
+extern int dns_transmit_start(struct dns_transmit *,const char *,int,const char *,const char *,const char *);
 extern void dns_transmit_free(struct dns_transmit *);
 extern void dns_transmit_io(struct dns_transmit *,iopause_fd *,struct taia *);
-extern int dns_transmit_get(struct dns_transmit *,iopause_fd *,struct taia *);
+extern int dns_transmit_get(struct dns_transmit *,const iopause_fd *,const struct taia *);
 
 extern int dns_resolvconfip(char *);
-extern int dns_resolve(char *,char *);
+extern int dns_resolve(const char *,const char *);
 extern struct dns_transmit dns_resolve_tx;
 
-extern int dns_ip4_packet(stralloc *,char *,unsigned int);
-extern int dns_ip4(stralloc *,stralloc *);
-extern int dns_name_packet(stralloc *,char *,unsigned int);
-extern void dns_name4_domain(char *,char *);
+extern int dns_ip4_packet(stralloc *,const char *,unsigned int);
+extern int dns_ip4(stralloc *,const stralloc *);
+extern int dns_name_packet(stralloc *,const char *,unsigned int);
+extern void dns_name4_domain(char *,const char *);
 #define DNS_NAME4_DOMAIN 31
-extern int dns_name4(stralloc *,char *);
-extern int dns_txt_packet(stralloc *,char *,unsigned int);
-extern int dns_txt(stralloc *,stralloc *);
-extern int dns_mx_packet(stralloc *,char *,unsigned int);
-extern int dns_mx(stralloc *,stralloc *);
+extern int dns_name4(stralloc *,const char *);
+extern int dns_txt_packet(stralloc *,const char *,unsigned int);
+extern int dns_txt(stralloc *,const stralloc *);
+extern int dns_mx_packet(stralloc *,const char *,unsigned int);
+extern int dns_mx(stralloc *,const stralloc *);
 
 extern int dns_resolvconfrewrite(stralloc *);
-extern int dns_ip4_qualify_rules(stralloc *,stralloc *,stralloc *,stralloc *);
-extern int dns_ip4_qualify(stralloc *,stralloc *,stralloc *);
+extern int dns_ip4_qualify_rules(stralloc *,stralloc *,const stralloc *,const stralloc *);
+extern int dns_ip4_qualify(stralloc *,stralloc *,const stralloc *);
 
 #endif</diff>
      <filename>dns.h</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,7 @@
 #include &quot;byte.h&quot;
 #include &quot;dns.h&quot;
 
-int dns_domain_fromdot(char **out,char *buf,unsigned int n)
+int dns_domain_fromdot(char **out,const char *buf,unsigned int n)
 {
   char label[63];
   unsigned int labellen = 0; /* &lt;= sizeof label */</diff>
      <filename>dns_dfd.c</filename>
    </modified>
    <modified>
      <diff>@@ -4,9 +4,9 @@
 #include &quot;byte.h&quot;
 #include &quot;dns.h&quot;
 
-unsigned int dns_domain_length(char *dn)
+unsigned int dns_domain_length(const char *dn)
 {
-  char *x;
+  const char *x;
   unsigned char c;
 
   x = dn;
@@ -23,7 +23,7 @@ void dns_domain_free(char **out)
   }
 }
 
-int dns_domain_copy(char **out,char *in)
+int dns_domain_copy(char **out,const char *in)
 {
   unsigned int len;
   char *x;
@@ -37,7 +37,7 @@ int dns_domain_copy(char **out,char *in)
   return 1;
 }
 
-int dns_domain_equal(char *dn1,char *dn2)
+int dns_domain_equal(const char *dn1,const char *dn2)
 {
   unsigned int len;
 
@@ -48,12 +48,25 @@ int dns_domain_equal(char *dn1,char *dn2)
   return 1;
 }
 
-char *dns_domain_suffix(char *big,char *little)
+int dns_domain_suffix(const char *big,const char *little)
+{
+  unsigned char c;
+
+  for (;;) {
+    if (dns_domain_equal(big,little)) return 1;
+    c = *big++;
+    if (!c) return 0;
+    big += c;
+  }
+}
+
+unsigned int dns_domain_suffixpos(const char *big,const char *little)
 {
+  const char *orig = big;
   unsigned char c;
 
   for (;;) {
-    if (dns_domain_equal(big,little)) return big;
+    if (dns_domain_equal(big,little)) return big - orig;
     c = *big++;
     if (!c) return 0;
     big += c;</diff>
      <filename>dns_domain.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 #include &quot;stralloc.h&quot;
 #include &quot;dns.h&quot;
 
-int dns_domain_todot_cat(stralloc *out,char *d)
+int dns_domain_todot_cat(stralloc *out,const char *d)
 {
   char ch;
   char ch2;</diff>
      <filename>dns_dtda.c</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,7 @@
 #include &quot;byte.h&quot;
 #include &quot;dns.h&quot;
 
-int dns_ip4_packet(stralloc *out,char *buf,unsigned int len)
+int dns_ip4_packet(stralloc *out,const char *buf,unsigned int len)
 {
   unsigned int pos;
   char header[12];
@@ -36,7 +36,7 @@ int dns_ip4_packet(stralloc *out,char *buf,unsigned int len)
 
 static char *q = 0;
 
-int dns_ip4(stralloc *out,stralloc *fqdn)
+int dns_ip4(stralloc *out,const stralloc *fqdn)
 {
   unsigned int i;
   char code;</diff>
      <filename>dns_ip.c</filename>
    </modified>
    <modified>
      <diff>@@ -4,7 +4,7 @@
 #include &quot;str.h&quot;
 #include &quot;dns.h&quot;
 
-static int doit(stralloc *work,char *rule)
+static int doit(stralloc *work,const char *rule)
 {
   char ch;
   unsigned int colon;
@@ -30,7 +30,7 @@ static int doit(stralloc *work,char *rule)
   return stralloc_cats(work,rule + colon + 1);
 }
 
-int dns_ip4_qualify_rules(stralloc *out,stralloc *fqdn,stralloc *in,stralloc *rules)
+int dns_ip4_qualify_rules(stralloc *out,stralloc *fqdn,const stralloc *in,const stralloc *rules)
 {
   unsigned int i;
   unsigned int j;
@@ -63,7 +63,7 @@ int dns_ip4_qualify_rules(stralloc *out,stralloc *fqdn,stralloc *in,stralloc *ru
   }
 }
 
-int dns_ip4_qualify(stralloc *out,stralloc *fqdn,stralloc *in)
+int dns_ip4_qualify(stralloc *out,stralloc *fqdn,const stralloc *in)
 {
   static stralloc rules;
   if (dns_resolvconfrewrite(&amp;rules) == -1) return -1;</diff>
      <filename>dns_ipq.c</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@
 
 static char *q = 0;
 
-int dns_mx_packet(stralloc *out,char *buf,unsigned int len)
+int dns_mx_packet(stralloc *out,const char *buf,unsigned int len)
 {
   unsigned int pos;
   char header[12];
@@ -38,7 +38,7 @@ int dns_mx_packet(stralloc *out,char *buf,unsigned int len)
   return 0;
 }
 
-int dns_mx(stralloc *out,stralloc *fqdn)
+int dns_mx(stralloc *out,const stralloc *fqdn)
 {
   if (!dns_domain_fromdot(&amp;q,fqdn-&gt;s,fqdn-&gt;len)) return -1;
   if (dns_resolve(q,DNS_T_MX) == -1) return -1;</diff>
      <filename>dns_mx.c</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@
 
 static char *q = 0;
 
-int dns_name_packet(stralloc *out,char *buf,unsigned int len)
+int dns_name_packet(stralloc *out,const char *buf,unsigned int len)
 {
   unsigned int pos;
   char header[12];
@@ -35,7 +35,7 @@ int dns_name_packet(stralloc *out,char *buf,unsigned int len)
   return 0;
 }
 
-int dns_name4(stralloc *out,char ip[4])
+int dns_name4(stralloc *out,const char ip[4])
 {
   char name[DNS_NAME4_DOMAIN];
 </diff>
      <filename>dns_name.c</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,7 @@
 #include &quot;fmt.h&quot;
 #include &quot;dns.h&quot;
 
-void dns_name4_domain(char name[DNS_NAME4_DOMAIN],char ip[4])
+void dns_name4_domain(char name[DNS_NAME4_DOMAIN],const char ip[4])
 {
   unsigned int namelen;
   unsigned int i;</diff>
      <filename>dns_nd.c</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ DNS should have used LZ77 instead of its own sophomoric compression algorithm.
 #include &quot;error.h&quot;
 #include &quot;dns.h&quot;
 
-unsigned int dns_packet_copy(char *buf,unsigned int len,unsigned int pos,char *out,unsigned int outlen)
+unsigned int dns_packet_copy(const char *buf,unsigned int len,unsigned int pos,char *out,unsigned int outlen)
 {
   while (outlen) {
     if (pos &gt;= len) { errno = error_proto; return 0; }
@@ -15,7 +15,7 @@ unsigned int dns_packet_copy(char *buf,unsigned int len,unsigned int pos,char *o
   return pos;
 }
 
-unsigned int dns_packet_skipname(char *buf,unsigned int len,unsigned int pos)
+unsigned int dns_packet_skipname(const char *buf,unsigned int len,unsigned int pos)
 {
   unsigned char ch;
 
@@ -32,7 +32,7 @@ unsigned int dns_packet_skipname(char *buf,unsigned int len,unsigned int pos)
   return 0;
 }
 
-unsigned int dns_packet_getname(char *buf,unsigned int len,unsigned int pos,char **d)
+unsigned int dns_packet_getname(const char *buf,unsigned int len,unsigned int pos,char **d)
 {
   unsigned int loop = 0;
   unsigned int state = 0;</diff>
      <filename>dns_packet.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+#include &lt;unistd.h&gt;
 #include &quot;dns.h&quot;
 #include &quot;taia.h&quot;
 #include &quot;uint32.h&quot;
@@ -29,7 +30,7 @@ static void surf(void)
   }
 }
 
-void dns_random_init(char data[128])
+void dns_random_init(const char data[128])
 {
   int i;
   struct taia t;</diff>
      <filename>dns_random.c</filename>
    </modified>
    <modified>
      <diff>@@ -16,7 +16,7 @@ static int init(char ip[64])
 
   x = env_get(&quot;DNSCACHEIP&quot;);
   if (x)
-    while (iplen &lt;= 60)
+    while (iplen &lt;= 60) {
       if (*x == '.')
 	++x;
       else {
@@ -25,6 +25,7 @@ static int init(char ip[64])
 	x += i;
 	iplen += 4;
       }
+    }
 
   if (!iplen) {
     i = openreadclose(&quot;/etc/resolv.conf&quot;,&amp;data,64);</diff>
      <filename>dns_rcip.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+#include &lt;unistd.h&gt;
 #include &quot;taia.h&quot;
 #include &quot;env.h&quot;
 #include &quot;byte.h&quot;
@@ -10,7 +11,7 @@ static stralloc data = {0};
 static int init(stralloc *rules)
 {
   char host[256];
-  char *x;
+  const char *x;
   int i;
   int j;
   int k;</diff>
      <filename>dns_rcrw.c</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@
 
 struct dns_transmit dns_resolve_tx = {0};
 
-int dns_resolve(char *q,char qtype[2])
+int dns_resolve(const char *q,const char qtype[2])
 {
   struct taia stamp;
   struct taia deadline;</diff>
      <filename>dns_resolve.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,12 +1,14 @@
+#include &lt;sys/types.h&gt;
+#include &lt;sys/socket.h&gt;
+#include &lt;unistd.h&gt;
 #include &quot;socket.h&quot;
 #include &quot;alloc.h&quot;
 #include &quot;error.h&quot;
 #include &quot;byte.h&quot;
-#include &quot;readwrite.h&quot;
 #include &quot;uint16.h&quot;
 #include &quot;dns.h&quot;
 
-static int serverwantstcp(char *buf,unsigned int len)
+static int serverwantstcp(const char *buf,unsigned int len)
 {
   char out[12];
 
@@ -15,7 +17,7 @@ static int serverwantstcp(char *buf,unsigned int len)
   return 0;
 }
 
-static int serverfailed(char *buf,unsigned int len)
+static int serverfailed(const char *buf,unsigned int len)
 {
   char out[12];
   unsigned int rcode;
@@ -27,7 +29,7 @@ static int serverfailed(char *buf,unsigned int len)
   return 0;
 }
 
-static int irrelevant(struct dns_transmit *d,char *buf,unsigned int len)
+static int irrelevant(const struct dns_transmit *d,const char *buf,unsigned int len)
 {
   char out[12];
   char *dn;
@@ -94,7 +96,7 @@ static const int timeouts[4] = { 1, 3, 11, 45 };
 
 static int thisudp(struct dns_transmit *d)
 {
-  char *ip;
+  const char *ip;
 
   socketfree(d);
 
@@ -145,7 +147,7 @@ static int nextudp(struct dns_transmit *d)
 static int thistcp(struct dns_transmit *d)
 {
   struct taia now;
-  char *ip;
+  const char *ip;
 
   socketfree(d);
   packetfree(d);
@@ -191,7 +193,7 @@ static int nexttcp(struct dns_transmit *d)
   return thistcp(d);
 }
 
-int dns_transmit_start(struct dns_transmit *d,char servers[64],int flagrecursive,char *q,char qtype[2],char localip[4])
+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])
 {
   unsigned int len;
 
@@ -236,7 +238,7 @@ void dns_transmit_io(struct dns_transmit *d,iopause_fd *x,struct taia *deadline)
     *deadline = d-&gt;deadline;
 }
 
-int dns_transmit_get(struct dns_transmit *d,iopause_fd *x,struct taia *when)
+int dns_transmit_get(struct dns_transmit *d,const iopause_fd *x,const struct taia *when)
 {
   char udpbuf[513];
   unsigned char ch;</diff>
      <filename>dns_transmit.c</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,7 @@
 #include &quot;byte.h&quot;
 #include &quot;dns.h&quot;
 
-int dns_txt_packet(stralloc *out,char *buf,unsigned int len)
+int dns_txt_packet(stralloc *out,const char *buf,unsigned int len)
 {
   unsigned int pos;
   char header[12];
@@ -48,7 +48,7 @@ int dns_txt_packet(stralloc *out,char *buf,unsigned int len)
 
 static char *q = 0;
 
-int dns_txt(stralloc *out,stralloc *fqdn)
+int dns_txt(stralloc *out,const stralloc *fqdn)
 {
   if (!dns_domain_fromdot(&amp;q,fqdn-&gt;s,fqdn-&gt;len)) return -1;
   if (dns_resolve(q,DNS_T_TXT) == -1) return -1;</diff>
      <filename>dns_txt.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+#include &lt;unistd.h&gt;
 #include &lt;sys/types.h&gt;
 #include &lt;sys/stat.h&gt;
 #include &quot;hasdevtcp.h&quot;
@@ -12,7 +13,6 @@
 #include &quot;str.h&quot;
 #include &quot;open.h&quot;
 #include &quot;error.h&quot;
-#include &quot;readwrite.h&quot;
 #include &quot;exit.h&quot;
 #include &quot;auto_home.h&quot;
 #include &quot;generic-conf.h&quot;
@@ -32,7 +32,7 @@ char *dir;
 char *user;
 char *loguser;
 struct passwd *pw;
-char *myip;
+const char *myip;
 
 uint32 seed[32];
 int seedpos = 0;
@@ -63,7 +63,7 @@ void seed_addtime(void)
     seed_adduint32(tpack[i]);
 }
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   seed_addtime();
   seed_adduint32(getpid());
@@ -138,7 +138,7 @@ main(int argc,char **argv)
   seed_addtime(); makedir(&quot;root/servers&quot;);
   seed_addtime(); perm(02755);
   seed_addtime(); start(&quot;root/servers/@&quot;);
-  buffer_init(&amp;ssrootservers,read,fdrootservers,rootserversbuf,sizeof rootserversbuf);
+  buffer_init(&amp;ssrootservers,buffer_unixread,fdrootservers,rootserversbuf,sizeof rootserversbuf);
   copyfrom(&amp;ssrootservers);
   finish();
   seed_addtime(); perm(0644);</diff>
      <filename>dnscache-conf.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+#include &lt;unistd.h&gt;
 #include &quot;env.h&quot;
 #include &quot;exit.h&quot;
 #include &quot;scan.h&quot;
@@ -5,8 +6,10 @@
 #include &quot;error.h&quot;
 #include &quot;ip4.h&quot;
 #include &quot;uint16.h&quot;
+#include &quot;uint64.h&quot;
 #include &quot;socket.h&quot;
 #include &quot;dns.h&quot;
+#include &quot;taia.h&quot;
 #include &quot;byte.h&quot;
 #include &quot;roots.h&quot;
 #include &quot;fmt.h&quot;
@@ -15,62 +18,18 @@
 #include &quot;alloc.h&quot;
 #include &quot;response.h&quot;
 #include &quot;cache.h&quot;
+#include &quot;ndelay.h&quot;
 #include &quot;log.h&quot;
-#include &quot;readwrite.h&quot;
 #include &quot;okclient.h&quot;
 #include &quot;droproot.h&quot;
 
-char myipoutgoing[4];
-char myipincoming[4];
-
-struct request {
-  struct query q;
-  struct taia timeout;
-  iopause_fd *io;
-  char ip[4]; /* send response to this address */
-  uint16 port; /* send response to this port */
-  char id[2];
-  int tcp; /* TCP socket, or -1 for UDP */
-  int tcpstate;
-  char *tcpbuf; /* dynamically allocated */
-  unsigned int tcplen;
-  unsigned int tcppos;
-} ;
-
-#define MAXTCP 20
-#define MAXREQ 200
-static struct request req[MAXREQ];
-char active[MAXREQ];
-int numactive = 0;
-int nextactive = MAXREQ - 1;
-int numtcp = 0;
-
-int udp53;
-int tcp53;
-char buf[1024];
-
-static void request_free(struct request *x)
-{
-  if (active[x - req]) {
-    active[x - req] = 0;
-    --numactive;
-  }
-}
-
-static void activate(struct request *x)
-{
-  if (!active[x - req]) {
-    active[x - req] = 1;
-    ++numactive;
-  }
-}
-
 static int packetquery(char *buf,unsigned int len,char **q,char qtype[2],char id[2])
 {
   unsigned int pos;
   char qclass[2];
   char header[12];
 
+  errno = error_proto;
   pos = dns_packet_copy(buf,len,0,header,12); if (!pos) return 0;
   if (header[2] &amp; 128) return 0; /* must not respond to responses */
   if (!(header[2] &amp; 1)) return 0; /* do not respond to non-recursive queries */
@@ -87,214 +46,249 @@ static int packetquery(char *buf,unsigned int len,char **q,char qtype[2],char id
   return 1;
 }
 
-static void udpdrop(struct request *x)
-{
-  log_querydrop(x - req);
-  request_free(x);
-}
 
-static void udprespond(struct request *x)
+static char myipoutgoing[4];
+static char myipincoming[4];
+static char buf[1024];
+uint64 numqueries = 0;
+
+
+static int udp53;
+
+#define MAXUDP 200
+static struct udpclient {
+  struct query q;
+  struct taia start;
+  uint64 active; /* query number, if active; otherwise 0 */
+  iopause_fd *io;
+  char ip[4];
+  uint16 port;
+  char id[2];
+} u[MAXUDP];
+int uactive = 0;
+
+void u_drop(int j)
 {
-  response_id(x-&gt;id);
-  if (response_len &gt; 512)
-    response_tc();
-  socket_send4(udp53,response,response_len,x-&gt;ip,x-&gt;port);
-  log_querydone(x - req,response_len);
-  request_free(x);
+  if (!u[j].active) return;
+  log_querydrop(&amp;u[j].active);
+  u[j].active = 0; --uactive;
 }
 
-static void tcpdrop(struct request *x)
+void u_respond(int j)
 {
-  log_conndrop(x - req);
-  close(x-&gt;tcp);
-  --numtcp;
-  request_free(x);
+  if (!u[j].active) return;
+  response_id(u[j].id);
+  if (response_len &gt; 512) response_tc();
+  socket_send4(udp53,response,response_len,u[j].ip,u[j].port);
+  log_querydone(&amp;u[j].active,response_len);
+  u[j].active = 0; --uactive;
 }
 
-static void handle(struct request *x,struct taia *stamp)
+void u_new(void)
 {
+  int j;
+  int i;
+  struct udpclient *x;
+  int len;
   static char *q = 0;
   char qtype[2];
-  char ch;
-  int r;
 
-  errno = error_io;
+  for (j = 0;j &lt; MAXUDP;++j)
+    if (!u[j].active)
+      break;
+
+  if (j &gt;= MAXUDP) {
+    j = 0;
+    for (i = 1;i &lt; MAXUDP;++i)
+      if (taia_less(&amp;u[i].start,&amp;u[j].start))
+	j = i;
+    errno = error_timeout;
+    u_drop(j);
+  }
 
-  if (!active[x - req]) return;
+  x = u + j;
+  taia_now(&amp;x-&gt;start);
 
-  if (x-&gt;tcp == -1) {
-    r = query_get(&amp;x-&gt;q,x-&gt;io,stamp);
-    if (r == -1) udpdrop(x);
-    if (r == 1) udprespond(x);
-    return;
-  }
+  len = socket_recv4(udp53,buf,sizeof buf,x-&gt;ip,&amp;x-&gt;port);
+  if (len == -1) return;
+  if (len &gt;= sizeof buf) return;
+  if (x-&gt;port &lt; 1024) if (x-&gt;port != 53) return;
+  if (!okclient(x-&gt;ip)) return;
 
-  if (x-&gt;io-&gt;revents) {
-    struct taia now;
-    taia_now(&amp;now);
-    taia_uint(&amp;x-&gt;timeout,10);
-    taia_add(&amp;x-&gt;timeout,&amp;x-&gt;timeout,&amp;now);
-  }
-  else
-    if (x-&gt;tcpstate)
-      if (taia_less(stamp,&amp;x-&gt;timeout))
-	return;
+  if (!packetquery(buf,len,&amp;q,qtype,x-&gt;id)) return;
 
-  switch(x-&gt;tcpstate) {
-    case 1:
-/*
-normal state at beginning of TCP connection
-*/
-      r = read(x-&gt;tcp,&amp;ch,1);
-      if (r &lt;= 0) { tcpdrop(x); return; }
-      x-&gt;tcplen = (unsigned char) ch;
-      x-&gt;tcplen &lt;&lt;= 8;
-      x-&gt;tcpstate = 2;
+  x-&gt;active = ++numqueries; ++uactive;
+  log_query(&amp;x-&gt;active,x-&gt;ip,x-&gt;port,x-&gt;id,q,qtype);
+  switch(query_start(&amp;x-&gt;q,q,qtype,myipoutgoing)) {
+    case -1:
+      u_drop(j);
       return;
+    case 1:
+      u_respond(j);
+  }
+}
 
-    case 2:
-/*
-have received one byte of TCP query packet length into x-&gt;tcplen
-*/
-      r = read(x-&gt;tcp,&amp;ch,1);
-      if (r &lt;= 0) { tcpdrop(x); return; }
-      x-&gt;tcplen += (unsigned char) ch;
-      x-&gt;tcpbuf = alloc(x-&gt;tcplen);
-      if (!x-&gt;tcpbuf) { tcpdrop(x); return; }
-      x-&gt;tcppos = 0;
-      x-&gt;tcpstate = 3;
-      return;
 
-    case 3:
-/*
-have received TCP query packet length into x-&gt;tcplen
-x-&gt;tcpbuf is dynamically allocated of length x-&gt;tcplen
-have received x-&gt;tcppos bytes of query packet
-*/
-      r = read(x-&gt;tcp,x-&gt;tcpbuf + x-&gt;tcppos,x-&gt;tcplen - x-&gt;tcppos);
-      if (r &lt;= 0) { alloc_free(x-&gt;tcpbuf); tcpdrop(x); return; }
-      x-&gt;tcppos += r;
-      if (x-&gt;tcppos == x-&gt;tcplen) {
-        if (!packetquery(x-&gt;tcpbuf,x-&gt;tcplen,&amp;q,qtype,x-&gt;id)) {
-	  alloc_free(x-&gt;tcpbuf); tcpdrop(x); return;
-	}
+static int tcp53;
 
-        log_query(x - req,x-&gt;ip,x-&gt;port,x-&gt;id,q,qtype);
-
-        switch(query_start(&amp;x-&gt;q,q,qtype,myipoutgoing)) {
-          case -1:
-	    alloc_free(x-&gt;tcpbuf);
-	    tcpdrop(x);
-	    return;
-          case 1:
-	    alloc_free(x-&gt;tcpbuf);
-	    goto HAVERESPONSE;
-	  default:
-	    alloc_free(x-&gt;tcpbuf);
-	    x-&gt;tcpstate = 0;
-	    return;
-        }
-      }
-      return;
+#define MAXTCP 20
+struct tcpclient {
+  struct query q;
+  struct taia start;
+  struct taia timeout;
+  uint64 active; /* query number or 1, if active; otherwise 0 */
+  iopause_fd *io;
+  char ip[4]; /* send response to this address */
+  uint16 port; /* send response to this port */
+  char id[2];
+  int tcp; /* open TCP socket, if active */
+  int state;
+  char *buf; /* 0, or dynamically allocated of length len */
+  unsigned int len;
+  unsigned int pos;
+} t[MAXTCP];
+int tactive = 0;
 
-    case 0:
 /*
-handling query
+state 1: buf 0; normal state at beginning of TCP connection
+state 2: buf 0; have read 1 byte of query packet length into len
+state 3: buf allocated; have read pos bytes of buf
+state 0: buf 0; handling query in q
+state -1: buf allocated; have written pos bytes
 */
-      switch(query_get(&amp;x-&gt;q,x-&gt;io,stamp)) {
-        case -1:
-	  tcpdrop(x);
-	  return;
-        case 1:
-	  HAVERESPONSE:
-	  response_id(x-&gt;id);
-	  x-&gt;tcplen = response_len + 2;
-	  x-&gt;tcpbuf = alloc(response_len + 2);
-	  if (!x-&gt;tcpbuf) { tcpdrop(x); return; }
-	  uint16_pack_big(x-&gt;tcpbuf,response_len);
-	  byte_copy(x-&gt;tcpbuf + 2,response_len,response);
-	  x-&gt;tcppos = 0;
-	  x-&gt;tcpstate = -1;
-	  return;
-      }
-      return;
 
-    case -1:
-/*
-x-&gt;tcpbuf is dynamically allocated of length x-&gt;tcplen
-have written x-&gt;tcppos bytes of buf
-*/
-      r = write(x-&gt;tcp,x-&gt;tcpbuf + x-&gt;tcppos,x-&gt;tcplen - x-&gt;tcppos);
-      if (r &lt;= 0) { alloc_free(x-&gt;tcpbuf); tcpdrop(x); return; }
-      x-&gt;tcppos += r;
-      if (x-&gt;tcppos == x-&gt;tcplen) {
-        log_querydone(x - req,x-&gt;tcplen);
-	alloc_free(x-&gt;tcpbuf);
-	x-&gt;tcpstate = 1; /* XXX: drop connection immediately? */
-      }
-      return;
-  }
+void t_free(int j)
+{
+  if (!t[j].buf) return;
+  alloc_free(t[j].buf);
+  t[j].buf = 0;
 }
 
-static void prep(struct request *x,struct taia *deadline,struct taia *stamp)
+void t_timeout(int j)
 {
-  if ((x-&gt;tcp == -1) || (x-&gt;tcpstate == 0)) {
-    query_io(&amp;x-&gt;q,x-&gt;io,deadline);
-    return;
-  }
+  struct taia now;
+  if (!t[j].active) return;
+  taia_now(&amp;now);
+  taia_uint(&amp;t[j].timeout,10);
+  taia_add(&amp;t[j].timeout,&amp;t[j].timeout,&amp;now);
+}
+
+void t_close(int j)
+{
+  if (!t[j].active) return;
+  t_free(j);
+  log_tcpclose(t[j].ip,t[j].port);
+  close(t[j].tcp);
+  t[j].active = 0; --tactive;
+}
 
-  if (taia_less(&amp;x-&gt;timeout,deadline)) *deadline = x-&gt;timeout;
+void t_drop(int j)
+{
+  log_querydrop(&amp;t[j].active);
+  errno = error_pipe;
+  t_close(j);
+}
 
-  x-&gt;io-&gt;fd = x-&gt;tcp;
-  x-&gt;io-&gt;events = (x-&gt;tcpstate &gt; 0) ? IOPAUSE_READ : IOPAUSE_WRITE;
+void t_respond(int j)
+{
+  if (!t[j].active) return;
+  log_querydone(&amp;t[j].active,response_len);
+  response_id(t[j].id);
+  t[j].len = response_len + 2;
+  t_free(j);
+  t[j].buf = alloc(response_len + 2);
+  if (!t[j].buf) { t_close(j); return; }
+  uint16_pack_big(t[j].buf,response_len);
+  byte_copy(t[j].buf + 2,response_len,response);
+  t[j].pos = 0;
+  t[j].state = -1;
 }
 
-static void udpquery(void)
+void t_rw(int j)
 {
-  struct request *x;
-  int len;
+  struct tcpclient *x;
+  char ch;
   static char *q = 0;
   char qtype[2];
+  int r;
 
-  if (numactive &gt;= MAXREQ) return;
-  do
-    if (++nextactive &gt;= MAXREQ)
-      nextactive = 0;
-  while (active[nextactive]);
-  x = req + nextactive;
+  x = t + j;
+  if (x-&gt;state == -1) {
+    r = write(x-&gt;tcp,x-&gt;buf + x-&gt;pos,x-&gt;len - x-&gt;pos);
+    if (r &lt;= 0) { t_close(j); return; }
+    x-&gt;pos += r;
+    if (x-&gt;pos == x-&gt;len) {
+      t_free(j);
+      x-&gt;state = 1; /* could drop connection immediately */
+    }
+    return;
+  }
 
-  len = socket_recv4(udp53,buf,sizeof buf,x-&gt;ip,&amp;x-&gt;port);
-  if (len == -1) return;
-  if (len &gt;= sizeof buf) return;
-  if (x-&gt;port &lt; 1024) if (x-&gt;port != 53) return;
-  if (!okclient(x-&gt;ip)) return;
-  x-&gt;tcp = -1;
+  r = read(x-&gt;tcp,&amp;ch,1);
+  if (r == 0) { errno = error_pipe; t_close(j); return; }
+  if (r &lt; 0) { t_close(j); return; }
 
-  if (!packetquery(buf,len,&amp;q,qtype,x-&gt;id)) return;
+  if (x-&gt;state == 1) {
+    x-&gt;len = (unsigned char) ch;
+    x-&gt;len &lt;&lt;= 8;
+    x-&gt;state = 2;
+    return;
+  }
+  if (x-&gt;state == 2) {
+    x-&gt;len += (unsigned char) ch;
+    if (!x-&gt;len) { errno = error_proto; t_close(j); return; }
+    x-&gt;buf = alloc(x-&gt;len);
+    if (!x-&gt;buf) { t_close(j); return; }
+    x-&gt;pos = 0;
+    x-&gt;state = 3;
+    return;
+  }
 
-  activate(x);
-  log_query(x - req,x-&gt;ip,x-&gt;port,x-&gt;id,q,qtype);
+  if (x-&gt;state != 3) return; /* impossible */
+
+  x-&gt;buf[x-&gt;pos++] = ch;
+  if (x-&gt;pos &lt; x-&gt;len) return;
+
+  if (!packetquery(x-&gt;buf,x-&gt;len,&amp;q,qtype,x-&gt;id)) { t_close(j); return; }
+
+  x-&gt;active = ++numqueries;
+  log_query(&amp;x-&gt;active,x-&gt;ip,x-&gt;port,x-&gt;id,q,qtype);
   switch(query_start(&amp;x-&gt;q,q,qtype,myipoutgoing)) {
     case -1:
-      udpdrop(x);
+      t_drop(j);
       return;
     case 1:
-      udprespond(x);
+      t_respond(j);
+      return;
   }
+  t_free(j);
+  x-&gt;state = 0;
 }
 
-static void tcpconnection(void)
+void t_new(void)
 {
-  struct request *x;
-  struct taia now;
+  int i;
+  int j;
+  struct tcpclient *x;
+
+  for (j = 0;j &lt; MAXTCP;++j)
+    if (!t[j].active)
+      break;
+
+  if (j &gt;= MAXTCP) {
+    j = 0;
+    for (i = 1;i &lt; MAXTCP;++i)
+      if (taia_less(&amp;t[i].start,&amp;t[j].start))
+	j = i;
+    errno = error_timeout;
+    if (t[j].state == 0)
+      t_drop(j);
+    else
+      t_close(j);
+  }
 
-  if (numtcp &gt;= MAXTCP) return;
-  if (numactive &gt;= MAXREQ) return;
-  do
-    if (++nextactive &gt;= MAXREQ)
-      nextactive = 0;
-  while (active[nextactive]);
-  x = req + nextactive;
+  x = t + j;
+  taia_now(&amp;x-&gt;start);
 
   x-&gt;tcp = socket_accept4(tcp53,x-&gt;ip,&amp;x-&gt;port);
   if (x-&gt;tcp == -1) return;
@@ -302,18 +296,15 @@ static void tcpconnection(void)
   if (!okclient(x-&gt;ip)) { close(x-&gt;tcp); return; }
   if (ndelay_on(x-&gt;tcp) == -1) { close(x-&gt;tcp); return; } /* Linux bug */
 
-  ++numtcp;
-  x-&gt;tcpstate = 1;
-  activate(x);
+  x-&gt;active = 1; ++tactive;
+  x-&gt;state = 1;
+  t_timeout(j);
 
-  taia_now(&amp;now);
-  taia_uint(&amp;x-&gt;timeout,10);
-  taia_add(&amp;x-&gt;timeout,&amp;x-&gt;timeout,&amp;now);
-
-  log_conn(x - req,x-&gt;ip,x-&gt;port);
+  log_tcpopen(x-&gt;ip,x-&gt;port);
 }
 
-iopause_fd io[3 + MAXREQ];
+
+iopause_fd io[3 + MAXUDP + MAXTCP];
 iopause_fd *udp53io;
 iopause_fd *tcp53io;
 
@@ -323,6 +314,7 @@ static void doit(void)
   struct taia deadline;
   struct taia stamp;
   int iolen;
+  int r;
 
   for (;;) {
     taia_now(&amp;stamp);
@@ -331,46 +323,69 @@ static void doit(void)
 
     iolen = 0;
 
-    udp53io = 0;
-    tcp53io = 0;
-    if (numactive &lt; MAXREQ) {
-      udp53io = io + iolen++;
-      udp53io-&gt;fd = udp53;
-      udp53io-&gt;events = IOPAUSE_READ;
-    }
-    if ((numactive &lt; MAXREQ) &amp;&amp; (numtcp &lt; MAXTCP)) {
-      tcp53io = io + iolen++;
-      tcp53io-&gt;fd = tcp53;
-      tcp53io-&gt;events = IOPAUSE_READ;
-    }
+    udp53io = io + iolen++;
+    udp53io-&gt;fd = udp53;
+    udp53io-&gt;events = IOPAUSE_READ;
 
-    for (j = 0;j &lt; MAXREQ;++j)
-      if (active[j]) {
-	req[j].io = io + iolen++;
-	prep(req + j,&amp;deadline,&amp;stamp);
+    tcp53io = io + iolen++;
+    tcp53io-&gt;fd = tcp53;
+    tcp53io-&gt;events = IOPAUSE_READ;
+
+    for (j = 0;j &lt; MAXUDP;++j)
+      if (u[j].active) {
+	u[j].io = io + iolen++;
+	query_io(&amp;u[j].q,u[j].io,&amp;deadline);
+      }
+    for (j = 0;j &lt; MAXTCP;++j)
+      if (t[j].active) {
+	t[j].io = io + iolen++;
+	if (t[j].state == 0)
+	  query_io(&amp;t[j].q,t[j].io,&amp;deadline);
+	else {
+	  if (taia_less(&amp;t[j].timeout,&amp;deadline)) deadline = t[j].timeout;
+	  t[j].io-&gt;fd = t[j].tcp;
+	  t[j].io-&gt;events = (t[j].state &gt; 0) ? IOPAUSE_READ : IOPAUSE_WRITE;
+	}
       }
 
     iopause(io,iolen,&amp;deadline,&amp;stamp);
 
-    for (j = 0;j &lt; MAXREQ;++j)
-      if (active[j])
-	handle(&amp;req[j],&amp;stamp);
+    for (j = 0;j &lt; MAXUDP;++j)
+      if (u[j].active) {
+	r = query_get(&amp;u[j].q,u[j].io,&amp;stamp);
+	if (r == -1) u_drop(j);
+	if (r == 1) u_respond(j);
+      }
+
+    for (j = 0;j &lt; MAXTCP;++j)
+      if (t[j].active) {
+	if (t[j].io-&gt;revents)
+	  t_timeout(j);
+	if (t[j].state == 0) {
+	  r = query_get(&amp;t[j].q,t[j].io,&amp;stamp);
+	  if (r == -1) t_drop(j);
+	  if (r == 1) t_respond(j);
+	}
+	else
+	  if (t[j].io-&gt;revents || taia_less(&amp;t[j].timeout,&amp;stamp))
+	    t_rw(j);
+      }
 
     if (udp53io)
       if (udp53io-&gt;revents)
-	udpquery();
+	u_new();
 
     if (tcp53io)
       if (tcp53io-&gt;revents)
-	tcpconnection();
+	t_new();
   }
 }
-
+  
 #define FATAL &quot;dnscache: fatal: &quot;
 
 char seed[128];
 
-main()
+int main()
 {
   char *x;
   unsigned long cachesize;
@@ -415,6 +430,11 @@ main()
   if (!cache_init(cachesize))
     strerr_die3x(111,FATAL,&quot;not enough memory for cache of size &quot;,x);
 
+  if (env_get(&quot;HIDETTL&quot;))
+    response_hidettl();
+  if (env_get(&quot;FORWARDONLY&quot;))
+    query_forwardonly();
+
   if (!roots_init())
     strerr_die2sys(111,FATAL,&quot;unable to read servers: &quot;);
 </diff>
      <filename>dnscache.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+#include &lt;unistd.h&gt;
 #include &quot;strerr.h&quot;
 #include &quot;buffer.h&quot;
 #include &quot;stralloc.h&quot;
@@ -10,7 +11,6 @@
 #include &quot;sgetopt.h&quot;
 #include &quot;iopause.h&quot;
 #include &quot;error.h&quot;
-#include &quot;readwrite.h&quot;
 #include &quot;exit.h&quot;
 
 #define FATAL &quot;dnsfilter: fatal: &quot;
@@ -59,7 +59,7 @@ void errout(int i)
       x[i].middle.s[j] = '-';
 }
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   struct taia stamp;
   struct taia deadline;</diff>
      <filename>dnsfilter.c</filename>
    </modified>
    <modified>
      <diff>@@ -12,7 +12,7 @@ static stralloc fqdn;
 static stralloc out;
 char str[IP4_FMT];
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   int i;
 </diff>
      <filename>dnsip.c</filename>
    </modified>
    <modified>
      <diff>@@ -13,7 +13,7 @@ static stralloc fqdn;
 static stralloc out;
 char str[IP4_FMT];
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   int i;
 </diff>
      <filename>dnsipq.c</filename>
    </modified>
    <modified>
      <diff>@@ -3,18 +3,25 @@
 #include &quot;strerr.h&quot;
 #include &quot;uint16.h&quot;
 #include &quot;byte.h&quot;
+#include &quot;str.h&quot;
 #include &quot;fmt.h&quot;
 #include &quot;dns.h&quot;
 
 #define FATAL &quot;dnsmx: fatal: &quot;
 
+void nomem(void)
+{
+  strerr_die2x(111,FATAL,&quot;out of memory&quot;);
+}
+
 static char seed[128];
 
 static stralloc fqdn;
+static char *q;
 static stralloc out;
 char strnum[FMT_ULONG];
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   int i;
   int j;
@@ -25,15 +32,16 @@ main(int argc,char **argv)
   if (*argv) ++argv;
 
   while (*argv) {
-    if (!stralloc_copys(&amp;fqdn,*argv))
-      strerr_die2x(111,FATAL,&quot;out of memory&quot;);
+    if (!stralloc_copys(&amp;fqdn,*argv)) nomem();
     if (dns_mx(&amp;out,&amp;fqdn) == -1)
       strerr_die4sys(111,FATAL,&quot;unable to find MX records for &quot;,*argv,&quot;: &quot;);
 
     if (!out.len) {
-      buffer_puts(buffer_1,&quot;0 &quot;);
-      buffer_puts(buffer_1,*argv);
-      buffer_puts(buffer_1,&quot;\n&quot;);
+      if (!dns_domain_fromdot(&amp;q,*argv,str_len(*argv))) nomem();
+      if (!stralloc_copys(&amp;out,&quot;0 &quot;)) nomem();
+      if (!dns_domain_todot_cat(&amp;out,q)) nomem();
+      if (!stralloc_cats(&amp;out,&quot;\n&quot;)) nomem();
+      buffer_put(buffer_1,out.s,out.len);
     }
     else {
       i = 0;</diff>
      <filename>dnsmx.c</filename>
    </modified>
    <modified>
      <diff>@@ -11,7 +11,7 @@ static char seed[128];
 char ip[4];
 static stralloc out;
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   dns_random_init(seed);
 </diff>
      <filename>dnsname.c</filename>
    </modified>
    <modified>
      <diff>@@ -58,7 +58,7 @@ static stralloc out;
 
 static char seed[128];
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   uint16 u16;
 </diff>
      <filename>dnsq.c</filename>
    </modified>
    <modified>
      <diff>@@ -28,7 +28,7 @@ static stralloc out;
 
 static char seed[128];
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   uint16 u16;
 </diff>
      <filename>dnsqr.c</filename>
    </modified>
    <modified>
      <diff>@@ -13,11 +13,12 @@
 #include &quot;strerr.h&quot;
 #include &quot;iopause.h&quot;
 #include &quot;printrecord.h&quot;
+#include &quot;alloc.h&quot;
 #include &quot;parsetype.h&quot;
+#include &quot;dd.h&quot;
 #include &quot;dns.h&quot;
 
 #define FATAL &quot;dnstrace: fatal: &quot;
-#define ALERT &quot;\tA\10AL\10LE\10ER\10RT\10T:\10: &quot;
 
 void nomem(void)
 {
@@ -28,32 +29,16 @@ void usage(void)
   strerr_die1x(100,&quot;dnstrace: usage: dnstrace type name rootip ...&quot;);
 }
 
+static stralloc querystr;
 char ipstr[IP4_FMT];
-char strnum[FMT_ULONG];
 static stralloc tmp;
 
-void printtype(char type[2])
-{
-  uint16 u16;
-  uint16_unpack_big(type,&amp;u16);
-  buffer_put(buffer_1,strnum,fmt_ulong(strnum,u16));
-}
-void printdomain(char *d)
+void printdomain(const char *d)
 {
   if (!stralloc_copys(&amp;tmp,&quot;&quot;)) nomem();
   if (!dns_domain_todot_cat(&amp;tmp,d)) nomem();
   buffer_put(buffer_1,tmp.s,tmp.len);
 }
-void printcontrol(char *d)
-{
-  int i;
-  if (!stralloc_copys(&amp;tmp,&quot;&quot;)) nomem();
-  if (!dns_domain_todot_cat(&amp;tmp,d)) nomem();
-  for (i = 0;i &lt; tmp.len;++i) {
-    buffer_put(buffer_1,&quot;_\10&quot;,2);
-    buffer_put(buffer_1,tmp.s + i,1);
-  }
-}
 
 static struct dns_transmit tx;
 
@@ -88,8 +73,8 @@ int resolve(char *q,char qtype[2],char ip[4])
   taia_sub(&amp;stamp,&amp;stamp,&amp;start);
   taia_uint(&amp;deadline,1);
   if (taia_less(&amp;deadline,&amp;stamp)) {
-    buffer_puts(buffer_1,ALERT);
-    buffer_puts(buffer_1,&quot;resolution took more than 1 second\n&quot;);
+    buffer_put(buffer_1,querystr.s,querystr.len);
+    buffer_puts(buffer_1,&quot;ALERT:took more than 1 second\n&quot;);
   }
 
   return 0;
@@ -141,7 +126,7 @@ GEN_ALLOC_append(qt_alloc,struct qt,s,len,a,i,n,x,30,qt_alloc_readyplus,qt_alloc
 
 static qt_alloc qt;
 
-void qt_add(char *q,char type[2],char *control,char ip[4])
+void qt_add(const char *q,const char type[2],const char *control,const char ip[4])
 {
   struct qt x;
   int i;
@@ -163,7 +148,7 @@ void qt_add(char *q,char type[2],char *control,char ip[4])
   if (!qt_alloc_append(&amp;qt,&amp;x)) nomem();
 }
 
-void query_add(char *owner,char type[2])
+void query_add(const char *owner,const char type[2])
 {
   struct query x;
   int i;
@@ -186,12 +171,19 @@ void query_add(char *owner,char type[2])
 	  qt_add(owner,type,ns.s[i].owner,address.s[j].ip);
 }
 
-void ns_add(char *owner,char *server)
+void ns_add(const char *owner,const char *server)
 {
   struct ns x;
   int i;
   int j;
 
+  buffer_put(buffer_1,querystr.s,querystr.len);
+  buffer_puts(buffer_1,&quot;NS:&quot;);
+  printdomain(owner);
+  buffer_puts(buffer_1,&quot;:&quot;);
+  printdomain(server);
+  buffer_puts(buffer_1,&quot;\n&quot;);
+
   for (i = 0;i &lt; ns.len;++i)
     if (dns_domain_equal(ns.s[i].owner,owner))
       if (dns_domain_equal(ns.s[i].ns,server))
@@ -199,12 +191,6 @@ void ns_add(char *owner,char *server)
 
   query_add(server,DNS_T_A);
 
-  buffer_puts(buffer_1,&quot;\t\t\t\t&quot;);
-  printdomain(owner);
-  buffer_puts(buffer_1,&quot; cache NS &quot;);
-  printdomain(server);
-  buffer_puts(buffer_1,&quot;\n&quot;);
-
   byte_zero(&amp;x,sizeof x);
   if (!dns_domain_copy(&amp;x.owner,owner)) nomem();
   if (!dns_domain_copy(&amp;x.ns,server)) nomem();
@@ -217,23 +203,24 @@ void ns_add(char *owner,char *server)
 	  qt_add(query.s[i].owner,query.s[i].type,owner,address.s[j].ip);
 }
 
-void address_add(char *owner,char ip[4])
+void address_add(const char *owner,const char ip[4])
 {
   struct address x;
   int i;
   int j;
 
+  buffer_put(buffer_1,querystr.s,querystr.len);
+  buffer_puts(buffer_1,&quot;A:&quot;);
+  printdomain(owner);
+  buffer_puts(buffer_1,&quot;:&quot;);
+  buffer_put(buffer_1,ipstr,ip4_fmt(ipstr,ip));
+  buffer_puts(buffer_1,&quot;\n&quot;);
+
   for (i = 0;i &lt; address.len;++i)
     if (dns_domain_equal(address.s[i].owner,owner))
       if (byte_equal(address.s[i].ip,4,ip))
 	return;
 
-  buffer_puts(buffer_1,&quot;\t\t\t\t&quot;);
-  printdomain(owner);
-  buffer_puts(buffer_1,&quot; cache A &quot;);
-  buffer_put(buffer_1,ipstr,ip4_fmt(ipstr,ip));
-  buffer_puts(buffer_1,&quot;\n&quot;);
-
   byte_zero(&amp;x,sizeof x);
   if (!dns_domain_copy(&amp;x.owner,owner)) nomem();
   byte_copy(x.ip,4,ip);
@@ -253,17 +240,16 @@ static char *t2;
 static char *referral;
 static char *cname;
 
-static int typematch(char rtype[2],char qtype[2])
+static int typematch(const char rtype[2],const char qtype[2])
 {
   return byte_equal(qtype,2,rtype) || byte_equal(qtype,2,DNS_T_ANY);
 }
 
-void parsepacket(char *buf,unsigned int len,char *d,char dtype[2],char *control)
+void parsepacket(const char *buf,unsigned int len,const char *d,const char dtype[2],const char *control)
 {
   char misc[20];
   char header[12];
   unsigned int pos;
-  unsigned int pos2;
   uint16 numanswers;
   unsigned int posanswers;
   uint16 numauthority;
@@ -276,9 +262,8 @@ void parsepacket(char *buf,unsigned int len,char *d,char dtype[2],char *control)
   int flagcname;
   int flagreferral;
   int flagsoa;
-  int i;
   int j;
-  char *x;
+  const char *x;
 
   pos = dns_packet_copy(buf,len,0,header,12); if (!pos) goto DIE;
   pos = dns_packet_skipname(buf,len,pos); if (!pos) goto DIE;
@@ -327,8 +312,8 @@ void parsepacket(char *buf,unsigned int len,char *d,char dtype[2],char *control)
 
   if (!flagcname &amp;&amp; !rcode &amp;&amp; !flagout &amp;&amp; flagreferral &amp;&amp; !flagsoa)
     if (dns_domain_equal(referral,control) || !dns_domain_suffix(referral,control)) {
-      buffer_puts(buffer_1,ALERT);
-      buffer_puts(buffer_1,&quot;lame server; refers to &quot;);
+      buffer_put(buffer_1,querystr.s,querystr.len);
+      buffer_puts(buffer_1,&quot;ALERT:lame server; refers to &quot;);
       printdomain(referral);
       buffer_puts(buffer_1,&quot;\n&quot;);
       return;
@@ -356,18 +341,21 @@ void parsepacket(char *buf,unsigned int len,char *d,char dtype[2],char *control)
 
   if (flagcname) {
     query_add(cname,dtype);
-    buffer_puts(buffer_1,&quot;\t\t\t\tCNAME &quot;);
+    buffer_put(buffer_1,querystr.s,querystr.len);
+    buffer_puts(buffer_1,&quot;CNAME:&quot;);
     printdomain(cname);
     buffer_puts(buffer_1,&quot;\n&quot;);
     return;
   }
   if (rcode == 3) {
-    buffer_puts(buffer_1,&quot;\t\t\t\tNXDOMAIN\n&quot;);
+    buffer_put(buffer_1,querystr.s,querystr.len);
+    buffer_puts(buffer_1,&quot;NXDOMAIN\n&quot;);
     return;
   }
   if (flagout || flagsoa || !flagreferral) {
     if (!flagout) {
-      buffer_puts(buffer_1,&quot;\t\t\t\tNODATA\n&quot;);
+      buffer_put(buffer_1,querystr.s,querystr.len);
+      buffer_puts(buffer_1,&quot;NODATA\n&quot;);
       return;
     }
     pos = posanswers;
@@ -375,27 +363,30 @@ void parsepacket(char *buf,unsigned int len,char *d,char dtype[2],char *control)
       pos = printrecord(&amp;tmp,buf,len,pos,d,dtype);
       if (!pos) goto DIE;
       if (tmp.len) {
-        buffer_puts(buffer_1,&quot;\t\t\t\t&quot;);
-        buffer_put(buffer_1,tmp.s,tmp.len);
+        buffer_put(buffer_1,querystr.s,querystr.len);
+        buffer_puts(buffer_1,&quot;answer:&quot;);
+        buffer_put(buffer_1,tmp.s,tmp.len); /* includes \n */
       }
     }
     return;
   }
 
   if (!dns_domain_suffix(d,referral)) goto DIE;
-  buffer_puts(buffer_1,&quot;\t\t\t\tsee &quot;);
+  buffer_put(buffer_1,querystr.s,querystr.len);
+  buffer_puts(buffer_1,&quot;see:&quot;);
   printdomain(referral);
   buffer_puts(buffer_1,&quot;\n&quot;);
   return;
 
   DIE:
   x = error_str(errno);
-  buffer_puts(buffer_1,ALERT);
-  buffer_puts(buffer_1,&quot;unable to parse response packet: &quot;);
+  buffer_put(buffer_1,querystr.s,querystr.len);
+  buffer_puts(buffer_1,&quot;ALERT:unable to parse response packet; &quot;);
   buffer_puts(buffer_1,x);
+  buffer_puts(buffer_1,&quot;\n&quot;);
 }
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   static stralloc out;
   static stralloc fqdn;
@@ -404,12 +395,13 @@ main(int argc,char **argv)
   char *control;
   char type[2];
   char ip[64];
-  int r;
   int i;
-  char ch;
+  uint16 u16;
 
   dns_random_init(seed);
 
+  if (!stralloc_copys(&amp;querystr,&quot;0:.:.::&quot;)) nomem();
+
   if (!address_alloc_readyplus(&amp;address,1)) nomem();
   if (!query_alloc_readyplus(&amp;query,1)) nomem();
   if (!ns_alloc_readyplus(&amp;ns,1)) nomem();
@@ -434,38 +426,47 @@ main(int argc,char **argv)
 
   for (i = 0;i &lt; qt.len;++i) {
     if (!dns_domain_copy(&amp;q,qt.s[i].owner)) nomem();
-    control = dns_domain_suffix(q,qt.s[i].control);
-    if (!control) continue;
+    control = qt.s[i].control;
+    if (!dns_domain_suffix(q,control)) continue;
     byte_copy(type,2,qt.s[i].type);
     byte_copy(ip,4,qt.s[i].ip);
 
-    printtype(type);
-    buffer_puts(buffer_1,&quot; &quot;);
-    if (control == q)
-      printcontrol(control);
-    else {
-      ch = *control;
-      *control = 0;
-      printdomain(q);
-      if (ch) {
-        *control = ch;
-        buffer_puts(buffer_1,&quot;.&quot;);
-        printcontrol(control);
-      }
-    }
-    buffer_puts(buffer_1,&quot; &quot;);
-    buffer_put(buffer_1,ipstr,ip4_fmt(ipstr,ip));
-    buffer_puts(buffer_1,&quot;\n&quot;);
+    if (!stralloc_copys(&amp;querystr,&quot;&quot;)) nomem();
+    uint16_unpack_big(type,&amp;u16);
+    if (!stralloc_catulong0(&amp;querystr,u16,0)) nomem();
+    if (!stralloc_cats(&amp;querystr,&quot;:&quot;)) nomem();
+    if (!dns_domain_todot_cat(&amp;querystr,q)) nomem();
+    if (!stralloc_cats(&amp;querystr,&quot;:&quot;)) nomem();
+    if (!dns_domain_todot_cat(&amp;querystr,control)) nomem();
+    if (!stralloc_cats(&amp;querystr,&quot;:&quot;)) nomem();
+    if (!stralloc_catb(&amp;querystr,ipstr,ip4_fmt(ipstr,ip))) nomem();
+    if (!stralloc_cats(&amp;querystr,&quot;:&quot;)) nomem();
+
+    buffer_put(buffer_1,querystr.s,querystr.len);
+    buffer_puts(buffer_1,&quot;tx\n&quot;);
     buffer_flush(buffer_1);
 
     if (resolve(q,type,ip) == -1) {
-      char *x = error_str(errno);
-      buffer_puts(buffer_1,ALERT);
+      const char *x = error_str(errno);
+      buffer_put(buffer_1,querystr.s,querystr.len);
+      buffer_puts(buffer_1,&quot;ALERT:query failed; &quot;);
       buffer_puts(buffer_1,x);
       buffer_puts(buffer_1,&quot;\n&quot;);
     }
     else
       parsepacket(tx.packet,tx.packetlen,q,type,control);
+
+    if (dns_domain_equal(q,&quot;\011localhost\0&quot;)) {
+      buffer_put(buffer_1,querystr.s,querystr.len);
+      buffer_puts(buffer_1,&quot;ALERT:some caches do not handle localhost internally\n&quot;);
+      address_add(q,&quot;\177\0\0\1&quot;);
+    }
+    if (dd(q,&quot;&quot;,ip) == 4) {
+      buffer_put(buffer_1,querystr.s,querystr.len);
+      buffer_puts(buffer_1,&quot;ALERT:some caches do not handle IP addresses internally\n&quot;);
+      address_add(q,ip);
+    }
+
     buffer_flush(buffer_1);
   }
 </diff>
      <filename>dnstrace.c</filename>
    </modified>
    <modified>
      <diff>@@ -10,7 +10,7 @@ static char seed[128];
 static stralloc fqdn;
 static stralloc out;
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   dns_random_init(seed);
 </diff>
      <filename>dnstxt.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,9 +1,10 @@
+#include &lt;unistd.h&gt;
 #include &quot;env.h&quot;
 #include &quot;scan.h&quot;
 #include &quot;prot.h&quot;
 #include &quot;strerr.h&quot;
 
-void droproot(char *fatal)
+void droproot(const char *fatal)
 {
   char *x;
   unsigned long id;</diff>
      <filename>droproot.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #ifndef DROPROOT_H
 #define DROPROOT_H
 
-extern void droproot(char *);
+extern void droproot(const char *);
 
 #endif</diff>
      <filename>droproot.h</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 #include &quot;str.h&quot;
 #include &quot;env.h&quot;
 
-extern /*@null@*/char *env_get(char *s)
+extern /*@null@*/char *env_get(const char *s)
 {
   int i;
   unsigned int len;</diff>
      <filename>env.c</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,6 @@
 
 extern char **environ;
 
-extern /*@null@*/char *env_get(char *);
+extern /*@null@*/char *env_get(const char *);
 
 #endif</diff>
      <filename>env.h</filename>
    </modified>
    <modified>
      <diff>@@ -21,7 +21,7 @@ extern int error_proto;
 extern int error_isdir;
 extern int error_connrefused;
 
-extern char *error_str(int);
+extern const char *error_str(int);
 extern int error_temp(int);
 
 #endif</diff>
      <filename>error.h</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,7 @@
 
 #define X(e,s) if (i == e) return s;
 
-char *error_str(int i)
+const char *error_str(int i)
 {
   X(0,&quot;no error&quot;)
   X(error_intr,&quot;interrupted system call&quot;)</diff>
      <filename>error_str.c</filename>
    </modified>
    <modified>
      <diff>@@ -19,7 +19,7 @@ extern unsigned int fmt_plusminus(char *,int);
 extern unsigned int fmt_minus(char *,int);
 extern unsigned int fmt_0x(char *,int);
 
-extern unsigned int fmt_str(char *,char *);
-extern unsigned int fmt_strn(char *,char *,unsigned int);
+extern unsigned int fmt_str(char *,const char *);
+extern unsigned int fmt_strn(char *,const char *,unsigned int);
 
 #endif</diff>
      <filename>fmt.h</filename>
    </modified>
    <modified>
      <diff>@@ -28,7 +28,7 @@ int ta_rplus(register ta *x,register unsigned int n) \
   return !!(x-&gt;field = (type *) alloc((x-&gt;a = n) * sizeof(type))); }
 
 #define GEN_ALLOC_append(ta,type,field,len,a,i,n,x,base,ta_rplus,ta_append) \
-int ta_append(register ta *x,register type *i) \
+int ta_append(register ta *x,register const type *i) \
 { if (!ta_rplus(x,1)) return 0; x-&gt;field[x-&gt;len++] = *i; return 1; }
 
 #endif</diff>
      <filename>gen_allocdefs.h</filename>
    </modified>
    <modified>
      <diff>@@ -1,18 +1,20 @@
+#include &lt;unistd.h&gt;
+#include &lt;sys/types.h&gt;
+#include &lt;sys/stat.h&gt;
 #include &quot;strerr.h&quot;
 #include &quot;buffer.h&quot;
-#include &quot;readwrite.h&quot;
 #include &quot;open.h&quot;
 #include &quot;generic-conf.h&quot;
 
-static char *fatal;
-static char *dir;
-static char *fn;
+static const char *fatal;
+static const char *dir;
+static const char *fn;
 
 static int fd;
 static char buf[1024];
 static buffer ss;
 
-void init(char *d,char *f)
+void init(const char *d,const char *f)
 {
   dir = d;
   fatal = f;
@@ -30,26 +32,26 @@ void fail(void)
   strerr_die6sys(111,fatal,&quot;unable to create &quot;,dir,&quot;/&quot;,fn,&quot;: &quot;);
 }
 
-void makedir(char *s)
+void makedir(const char *s)
 {
   fn = s;
   if (mkdir(fn,0700) == -1) fail();
 }
 
-void start(char *s)
+void start(const char *s)
 {
   fn = s;
   fd = open_trunc(fn);
   if (fd == -1) fail();
-  buffer_init(&amp;ss,write,fd,buf,sizeof buf);
+  buffer_init(&amp;ss,buffer_unixwrite,fd,buf,sizeof buf);
 }
 
-void outs(char *s)
+void outs(const char *s)
 {
   if (buffer_puts(&amp;ss,s) == -1) fail();
 }
 
-void out(char *s,unsigned int len)
+void out(const char *s,unsigned int len)
 {
   if (buffer_put(&amp;ss,s,len) == -1) fail();
 }
@@ -76,7 +78,7 @@ void owner(int uid,int gid)
   if (chown(fn,uid,gid) == -1) fail();
 }
 
-void makelog(char *user,int uid,int gid)
+void makelog(const char *user,int uid,int gid)
 {
   makedir(&quot;log&quot;);
   perm(02755);</diff>
      <filename>generic-conf.c</filename>
    </modified>
    <modified>
      <diff>@@ -3,18 +3,18 @@
 
 #include &quot;buffer.h&quot;
 
-extern void init(char *,char *);
+extern void init(const char *,const char *);
 
-extern void makedir(char *);
+extern void makedir(const char *);
 
-extern void start(char *);
-extern void outs(char *);
-extern void out(char *,unsigned int);
+extern void start(const char *);
+extern void outs(const char *);
+extern void out(const char *,unsigned int);
 extern void copyfrom(buffer *);
 extern void finish(void);
 
 extern void perm(int);
 extern void owner(int,int);
-extern void makelog(char *,int,int);
+extern void makelog(const char *,int,int);
 
 #endif</diff>
      <filename>generic-conf.h</filename>
    </modified>
    <modified>
      <diff>@@ -38,4 +38,5 @@ void hier()
   c(auto_home,&quot;bin&quot;,&quot;dnsqr&quot;,-1,-1,0755);
   c(auto_home,&quot;bin&quot;,&quot;dnsq&quot;,-1,-1,0755);
   c(auto_home,&quot;bin&quot;,&quot;dnstrace&quot;,-1,-1,0755);
+  c(auto_home,&quot;bin&quot;,&quot;dnstracesort&quot;,-1,-1,0755);
 }</diff>
      <filename>hier.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,10 @@
+#include &lt;unistd.h&gt;
+#include &lt;sys/types.h&gt;
+#include &lt;sys/stat.h&gt;
 #include &quot;buffer.h&quot;
 #include &quot;strerr.h&quot;
 #include &quot;error.h&quot;
 #include &quot;open.h&quot;
-#include &quot;readwrite.h&quot;
 #include &quot;exit.h&quot;
 
 extern void hier();
@@ -66,7 +68,7 @@ int mode;
   fdin = open_read(file);
   if (fdin == -1)
     strerr_die4sys(111,FATAL,&quot;unable to read &quot;,file,&quot;: &quot;);
-  buffer_init(&amp;ssin,read,fdin,inbuf,sizeof inbuf);
+  buffer_init(&amp;ssin,buffer_unixread,fdin,inbuf,sizeof inbuf);
 
   if (chdir(home) == -1)
     strerr_die4sys(111,FATAL,&quot;unable to switch to &quot;,home,&quot;: &quot;);
@@ -76,7 +78,7 @@ int mode;
   fdout = open_trunc(file);
   if (fdout == -1)
     strerr_die6sys(111,FATAL,&quot;unable to write .../&quot;,subdir,&quot;/&quot;,file,&quot;: &quot;);
-  buffer_init(&amp;ssout,write,fdout,outbuf,sizeof outbuf);
+  buffer_init(&amp;ssout,buffer_unixwrite,fdout,outbuf,sizeof outbuf);
 
   switch(buffer_copy(&amp;ssout,&amp;ssin)) {
     case -2:
@@ -118,7 +120,7 @@ int mode;
   fdout = open_trunc(file);
   if (fdout == -1)
     strerr_die6sys(111,FATAL,&quot;unable to write .../&quot;,subdir,&quot;/&quot;,file,&quot;: &quot;);
-  buffer_init(&amp;ssout,write,fdout,outbuf,sizeof outbuf);
+  buffer_init(&amp;ssout,buffer_unixwrite,fdout,outbuf,sizeof outbuf);
 
   while (len-- &gt; 0)
     if (buffer_put(&amp;ssout,&quot;&quot;,1) == -1)
@@ -137,7 +139,7 @@ int mode;
     strerr_die6sys(111,FATAL,&quot;unable to chmod .../&quot;,subdir,&quot;/&quot;,file,&quot;: &quot;);
 }
 
-main()
+int main()
 {
   fdsourcedir = open_read(&quot;.&quot;);
   if (fdsourcedir == -1)</diff>
      <filename>install.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,8 @@
 #include &lt;sys/types.h&gt;
 #include &lt;sys/stat.h&gt;
+#include &lt;unistd.h&gt;
 #include &quot;strerr.h&quot;
 #include &quot;error.h&quot;
-#include &quot;readwrite.h&quot;
 #include &quot;exit.h&quot;
 
 extern void hier();
@@ -101,7 +101,7 @@ int mode;
   perm(&quot;&quot;,home,&quot;/&quot;,file,S_IFREG,uid,gid,mode);
 }
 
-main()
+int main()
 {
   hier();
   _exit(0);</diff>
      <filename>instcheck.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,8 @@
 #ifndef IP4_H
 #define IP4_H
 
-extern unsigned int ip4_scan(char *,char *);
-extern unsigned int ip4_fmt(char *,char *);
+extern unsigned int ip4_scan(const char *,char *);
+extern unsigned int ip4_fmt(char *,const char *);
 
 #define IP4_FMT 20
 </diff>
      <filename>ip4.h</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 #include &quot;fmt.h&quot;
 #include &quot;ip4.h&quot;
 
-unsigned int ip4_fmt(char *s,char ip[4])
+unsigned int ip4_fmt(char *s,const char ip[4])
 {
   unsigned int len;
   unsigned int i;</diff>
      <filename>ip4_fmt.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 #include &quot;scan.h&quot;
 #include &quot;ip4.h&quot;
 
-unsigned int ip4_scan(char *s,char ip[4])
+unsigned int ip4_scan(const char *s,char ip[4])
 {
   unsigned int i;
   unsigned int len;</diff>
      <filename>ip4_scan.c</filename>
    </modified>
    <modified>
      <diff>@@ -29,7 +29,7 @@ static void hex(unsigned char c)
   buffer_put(buffer_2,&quot;0123456789abcdef&quot; + (c &amp; 15),1);
 }
 
-static void string(char *s)
+static void string(const char *s)
 {
   buffer_puts(buffer_2,s);
 }
@@ -45,21 +45,21 @@ static void space(void)
   string(&quot; &quot;);
 }
 
-static void ip(char ip[4])
+static void ip(const char i[4])
 {
-  hex(ip[0]);
-  hex(ip[1]);
-  hex(ip[2]);
-  hex(ip[3]);
+  hex(i[0]);
+  hex(i[1]);
+  hex(i[2]);
+  hex(i[3]);
 }
 
-static void logid(char id[2])
+static void logid(const char id[2])
 {
   hex(id[0]);
   hex(id[1]);
 }
 
-static void logtype(char type[2])
+static void logtype(const char type[2])
 {
   uint16 u;
 
@@ -67,7 +67,7 @@ static void logtype(char type[2])
   number(u);
 }
 
-static void name(char *q)
+static void name(const char *q)
 {
   char ch;
   int state;
@@ -94,48 +94,48 @@ void log_startup(void)
   line();
 }
 
-void log_query(unsigned int qnum,char client[4],unsigned int port,char id[2],char *q,char qtype[2])
+void log_query(uint64 *qnum,const char client[4],unsigned int port,const char id[2],const char *q,const char qtype[2])
 {
-  string(&quot;query &quot;); number(qnum); space();
+  string(&quot;query &quot;); number(*qnum); space();
   ip(client); string(&quot;:&quot;); hex(port &gt;&gt; 8); hex(port &amp; 255);
   string(&quot;:&quot;); logid(id); space();
   logtype(qtype); space(); name(q);
   line();
 }
 
-void log_querydone(unsigned int qnum,unsigned int len)
+void log_querydone(uint64 *qnum,unsigned int len)
 {
-  string(&quot;sent &quot;); number(qnum); space();
+  string(&quot;sent &quot;); number(*qnum); space();
   number(len);
   line();
 }
 
-void log_querydrop(unsigned int qnum)
+void log_querydrop(uint64 *qnum)
 {
-  char *x = error_str(errno);
+  const char *x = error_str(errno);
 
-  string(&quot;drop &quot;); number(qnum); space();
+  string(&quot;drop &quot;); number(*qnum); space();
   string(x);
   line();
 }
 
-void log_conn(unsigned int qnum,char client[4],unsigned int port)
+void log_tcpopen(const char client[4],unsigned int port)
 {
-  string(&quot;connection &quot;); number(qnum); space();
+  string(&quot;tcpopen &quot;);
   ip(client); string(&quot;:&quot;); hex(port &gt;&gt; 8); hex(port &amp; 255);
   line();
 }
 
-void log_conndrop(unsigned int qnum)
+void log_tcpclose(const char client[4],unsigned int port)
 {
-  char *x = error_str(errno);
-
-  string(&quot;dropconnection &quot;); number(qnum); space();
+  const char *x = error_str(errno);
+  string(&quot;tcpclose &quot;);
+  ip(client); string(&quot;:&quot;); hex(port &gt;&gt; 8); hex(port &amp; 255); space();
   string(x);
   line();
 }
 
-void log_tx(char *q,char qtype[2],char *control,char servers[64],unsigned int gluelessness)
+void log_tx(const char *q,const char qtype[2],const char *control,const char servers[64],unsigned int gluelessness)
 {
   int i;
 
@@ -150,68 +150,68 @@ void log_tx(char *q,char qtype[2],char *control,char servers[64],unsigned int gl
   line();
 }
 
-void log_cachedanswer(char *q,char type[2])
+void log_cachedanswer(const char *q,const char type[2])
 {
   string(&quot;cached &quot;); logtype(type); space();
   name(q);
   line();
 }
 
-void log_cachedcname(char *dn,char *dn2)
+void log_cachedcname(const char *dn,const char *dn2)
 {
   string(&quot;cached cname &quot;); name(dn); space(); name(dn2);
   line();
 }
 
-void log_cachedns(char *control,char *ns)
+void log_cachedns(const char *control,const char *ns)
 {
   string(&quot;cached ns &quot;); name(control); space(); name(ns);
   line();
 }
 
-void log_cachednxdomain(char *dn)
+void log_cachednxdomain(const char *dn)
 {
   string(&quot;cached nxdomain &quot;); name(dn);
   line();
 }
 
-void log_cachedservfail(char *dn)
+void log_cachedservfail(const char *dn)
 {
   string(&quot;cached servfail &quot;); name(dn);
   line();
 }
 
-void log_nxdomain(char server[4],char *q,unsigned int ttl)
+void log_nxdomain(const char server[4],const char *q,unsigned int ttl)
 {
   string(&quot;nxdomain &quot;); ip(server); space(); number(ttl); space();
   name(q);
   line();
 }
 
-void log_nodata(char server[4],char *q,char qtype[2],unsigned int ttl)
+void log_nodata(const char server[4],const char *q,const char qtype[2],unsigned int ttl)
 {
   string(&quot;nodata &quot;); ip(server); space(); number(ttl); space();
   logtype(qtype); space(); name(q);
   line();
 }
 
-void log_lame(char server[4],char *control,char *referral)
+void log_lame(const char server[4],const char *control,const char *referral)
 {
   string(&quot;lame &quot;); ip(server); space();
   name(control); space(); name(referral);
   line();
 }
 
-void log_servfail(char *dn)
+void log_servfail(const char *dn)
 {
-  char *x = error_str(errno);
+  const char *x = error_str(errno);
 
   string(&quot;servfail &quot;); name(dn); space();
   string(x);
   line();
 }
 
-void log_rr(char server[4],char *q,char type[2],char *buf,unsigned int len,unsigned int ttl)
+void log_rr(const char server[4],const char *q,const char type[2],const char *buf,unsigned int len,unsigned int ttl)
 {
   int i;
 
@@ -228,7 +228,7 @@ void log_rr(char server[4],char *q,char type[2],char *buf,unsigned int len,unsig
   line();
 }
 
-void log_rrns(char server[4],char *q,char *data,unsigned int ttl)
+void log_rrns(const char server[4],const char *q,const char *data,unsigned int ttl)
 {
   string(&quot;rr &quot;); ip(server); space(); number(ttl);
   string(&quot; ns &quot;); name(q); space();
@@ -236,7 +236,7 @@ void log_rrns(char server[4],char *q,char *data,unsigned int ttl)
   line();
 }
 
-void log_rrcname(char server[4],char *q,char *data,unsigned int ttl)
+void log_rrcname(const char server[4],const char *q,const char *data,unsigned int ttl)
 {
   string(&quot;rr &quot;); ip(server); space(); number(ttl);
   string(&quot; cname &quot;); name(q); space();
@@ -244,7 +244,7 @@ void log_rrcname(char server[4],char *q,char *data,unsigned int ttl)
   line();
 }
 
-void log_rrptr(char server[4],char *q,char *data,unsigned int ttl)
+void log_rrptr(const char server[4],const char *q,const char *data,unsigned int ttl)
 {
   string(&quot;rr &quot;); ip(server); space(); number(ttl);
   string(&quot; ptr &quot;); name(q); space();
@@ -252,7 +252,7 @@ void log_rrptr(char server[4],char *q,char *data,unsigned int ttl)
   line();
 }
 
-void log_rrmx(char server[4],char *q,char *mx,char pref[2],unsigned int ttl)
+void log_rrmx(const char server[4],const char *q,const char *mx,const char pref[2],unsigned int ttl)
 {
   uint16 u;
 
@@ -263,7 +263,7 @@ void log_rrmx(char server[4],char *q,char *mx,char pref[2],unsigned int ttl)
   line();
 }
 
-void log_rrsoa(char server[4],char *q,char *n1,char *n2,char misc[20],unsigned int ttl)
+void log_rrsoa(const char server[4],const char *q,const char *n1,const char *n2,const char misc[20],unsigned int ttl)
 {
   uint32 u;
   int i;
@@ -278,11 +278,17 @@ void log_rrsoa(char server[4],char *q,char *n1,char *n2,char misc[20],unsigned i
   line();
 }
 
-void log_stats(uint64 *queries,uint64 *motion,int *active)
+void log_stats(void)
 {
+  extern uint64 numqueries;
+  extern uint64 cache_motion;
+  extern int uactive;
+  extern int tactive;
+
   string(&quot;stats &quot;);
-  number(*queries); space();
-  number(*motion); space();
-  number(*active);
+  number(numqueries); space();
+  number(cache_motion); space();
+  number(uactive); space();
+  number(tactive);
   line();
 }</diff>
      <filename>log.c</filename>
    </modified>
    <modified>
      <diff>@@ -5,33 +5,33 @@
 
 extern void log_startup(void);
 
-extern void log_query(unsigned int,char *,unsigned int,char *,char *,char *);
-extern void log_querydrop(unsigned int);
-extern void log_querydone(unsigned int,unsigned int);
-
-extern void log_conn(unsigned int,char *,unsigned int);
-extern void log_conndrop(unsigned int);
-
-extern void log_cachedanswer(char *,char *);
-extern void log_cachedcname(char *,char *);
-extern void log_cachednxdomain(char *);
-extern void log_cachedservfail(char *);
-extern void log_cachedns(char *,char *);
-
-extern void log_tx(char *,char *,char *,char *,unsigned int);
-
-extern void log_nxdomain(char *,char *,unsigned int);
-extern void log_nodata(char *,char *,char *,unsigned int);
-extern void log_servfail(char *);
-extern void log_lame(char *,char *,char *);
-
-extern void log_rr(char *,char *,char *,char *,unsigned int,unsigned int);
-extern void log_rrns(char *,char *,char *,unsigned int);
-extern void log_rrcname(char *,char *,char *,unsigned int);
-extern void log_rrptr(char *,char *,char *,unsigned int);
-extern void log_rrmx(char *,char *,char *,char *,unsigned int);
-extern void log_rrsoa(char *,char *,char *,char *,char *,unsigned int);
-
-extern void log_stats(uint64 *,uint64 *,int *);
+extern void log_query(uint64 *,const char *,unsigned int,const char *,const char *,const char *);
+extern void log_querydrop(uint64 *);
+extern void log_querydone(uint64 *,unsigned int);
+
+extern void log_tcpopen(const char *,unsigned int);
+extern void log_tcpclose(const char *,unsigned int);
+
+extern void log_cachedanswer(const char *,const char *);
+extern void log_cachedcname(const char *,const char *);
+extern void log_cachednxdomain(const char *);
+extern void log_cachedservfail(const char *);
+extern void log_cachedns(const char *,const char *);
+
+extern void log_tx(const char *,const char *,const char *,const char *,unsigned int);
+
+extern void log_nxdomain(const char *,const char *,unsigned int);
+extern void log_nodata(const char *,const char *,const char *,unsigned int);
+extern void log_servfail(const char *);
+extern void log_lame(const char *,const char *,const char *);
+
+extern void log_rr(const char *,const char *,const char *,const char *,unsigned int,unsigned int);
+extern void log_rrns(const char *,const char *,const char *,unsigned int);
+extern void log_rrcname(const char *,const char *,const char *,unsigned int);
+extern void log_rrptr(const char *,const char *,const char *,unsigned int);
+extern void log_rrmx(const char *,const char *,const char *,const char *,unsigned int);
+extern void log_rrsoa(const char *,const char *,const char *,const char *,const char *,unsigned int);
+
+extern void log_stats(void);
 
 #endif</diff>
      <filename>log.h</filename>
    </modified>
    <modified>
      <diff>@@ -1,10 +1,10 @@
 #ifndef OPEN_H
 #define OPEN_H
 
-extern int open_read(char *);
-extern int open_excl(char *);
-extern int open_append(char *);
-extern int open_trunc(char *);
-extern int open_write(char *);
+extern int open_read(const char *);
+extern int open_excl(const char *);
+extern int open_append(const char *);
+extern int open_trunc(const char *);
+extern int open_write(const char *);
 
 #endif</diff>
      <filename>open.h</filename>
    </modified>
    <modified>
      <diff>@@ -2,5 +2,5 @@
 #include &lt;fcntl.h&gt;
 #include &quot;open.h&quot;
 
-int open_read(char *fn)
+int open_read(const char *fn)
 { return open(fn,O_RDONLY | O_NDELAY); }</diff>
      <filename>open_read.c</filename>
    </modified>
    <modified>
      <diff>@@ -2,5 +2,5 @@
 #include &lt;fcntl.h&gt;
 #include &quot;open.h&quot;
 
-int open_trunc(char *fn)
+int open_trunc(const char *fn)
 { return open(fn,O_WRONLY | O_NDELAY | O_TRUNC | O_CREAT,0644); }</diff>
      <filename>open_trunc.c</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,7 @@
 #include &quot;readclose.h&quot;
 #include &quot;openreadclose.h&quot;
 
-int openreadclose(char *fn,stralloc *sa,unsigned int bufsize)
+int openreadclose(const char *fn,stralloc *sa,unsigned int bufsize)
 {
   int fd;
   fd = open_read(fn);</diff>
      <filename>openreadclose.c</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,6 @@
 
 #include &quot;stralloc.h&quot;
 
-extern int openreadclose(char *,stralloc *,unsigned int);
+extern int openreadclose(const char *,stralloc *,unsigned int);
 
 #endif</diff>
      <filename>openreadclose.h</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,7 @@
 #include &quot;byte.h&quot;
 #include &quot;case.h&quot;
 #include &quot;dns.h&quot;
+#include &quot;uint16.h&quot;
 #include &quot;parsetype.h&quot;
 
 int parsetype(char *s,char type[2])</diff>
      <filename>parsetype.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+#include &lt;unistd.h&gt;
 #include &lt;pwd.h&gt;
 #include &quot;strerr.h&quot;
 #include &quot;exit.h&quot;
@@ -17,7 +18,7 @@ char *loguser;
 struct passwd *pw;
 char *myip;
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   user = argv[1];
   if (!user) usage();</diff>
      <filename>pickdns-conf.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,8 @@
+#include &lt;stdio.h&gt;
+#include &lt;sys/types.h&gt;
+#include &lt;sys/stat.h&gt;
+#include &lt;unistd.h&gt;
 #include &quot;buffer.h&quot;
-#include &quot;readwrite.h&quot;
 #include &quot;exit.h&quot;
 #include &quot;cdb_make.h&quot;
 #include &quot;open.h&quot;
@@ -7,6 +10,7 @@
 #include &quot;gen_allocdefs.h&quot;
 #include &quot;stralloc.h&quot;
 #include &quot;getln.h&quot;
+#include &quot;case.h&quot;
 #include &quot;strerr.h&quot;
 #include &quot;str.h&quot;
 #include &quot;byte.h&quot;
@@ -110,11 +114,9 @@ unsigned long linenum = 0;
 #define NUMFIELDS 3
 static stralloc f[NUMFIELDS];
 
-static char *d1;
-
 char strnum[FMT_ULONG];
 
-void syntaxerror(char *why)
+void syntaxerror(const char *why)
 {
   strnum[fmt_ulong(strnum,linenum)] = 0;
   strerr_die4x(111,FATAL,&quot;unable to parse data line &quot;,strnum,why);
@@ -124,7 +126,7 @@ void die_datatmp(void)
   strerr_die2sys(111,FATAL,&quot;unable to create data.tmp: &quot;);
 }
 
-main()
+int main()
 {
   struct address t;
   int i;
@@ -138,7 +140,7 @@ main()
 
   fd = open_read(&quot;data&quot;);
   if (fd == -1) strerr_die2sys(111,FATAL,&quot;unable to open data: &quot;);
-  buffer_init(&amp;b,read,fd,bspace,sizeof bspace);
+  buffer_init(&amp;b,buffer_unixread,fd,bspace,sizeof bspace);
 
   fdcdb = open_trunc(&quot;data.tmp&quot;);
   if (fdcdb == -1) die_datatmp();</diff>
      <filename>pickdns-data.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+#include &lt;unistd.h&gt;
 #include &quot;byte.h&quot;
 #include &quot;case.h&quot;
 #include &quot;dns.h&quot;
@@ -5,7 +6,7 @@
 #include &quot;cdb.h&quot;
 #include &quot;response.h&quot;
 
-char *fatal = &quot;pickdns: fatal: &quot;;
+const char *fatal = &quot;pickdns: fatal: &quot;;
 
 static char seed[128];
 
@@ -23,11 +24,16 @@ static int doit(char *q,char qtype[2],char ip[4])
   int r;
   uint32 dlen;
   unsigned int qlen;
+  int flaga;
+  int flagmx;
 
   qlen = dns_domain_length(q);
   if (qlen &gt; 255) return 0; /* impossible */
 
-  if (byte_diff(qtype,2,DNS_T_A) &amp;&amp; byte_diff(qtype,2,DNS_T_ANY)) goto REFUSE;
+  flaga = byte_equal(qtype,2,DNS_T_A);
+  flagmx = byte_equal(qtype,2,DNS_T_MX);
+  if (byte_equal(qtype,2,DNS_T_ANY)) flaga = flagmx = 1;
+  if (!flaga &amp;&amp; !flagmx) goto REFUSE;
 
   key[0] = '%';
   byte_copy(key + 1,4,ip);
@@ -58,14 +64,15 @@ static int doit(char *q,char qtype[2],char ip[4])
   if (dlen &gt; 512) dlen = 512;
   if (cdb_read(&amp;c,data,dlen,cdb_datapos(&amp;c)) == -1) return 0;
 
-  dns_sortip(data,dlen);
-
-  if (dlen &gt; 12) dlen = 12;
-  while (dlen &gt;= 4) {
-    dlen -= 4;
-    if (!response_rstart(q,DNS_T_A,&quot;\0\0\0\5&quot;)) return 0;
-    if (!response_addbytes(data + dlen,4)) return 0;
-    response_rfinish(RESPONSE_ANSWER);
+  if (flaga) {
+    dns_sortip(data,dlen);
+    if (dlen &gt; 12) dlen = 12;
+    while (dlen &gt;= 4) {
+      dlen -= 4;
+      if (!response_rstart(q,DNS_T_A,5)) return 0;
+      if (!response_addbytes(data + dlen,4)) return 0;
+      response_rfinish(RESPONSE_ANSWER);
+    }
   }
 
   return 1;</diff>
      <filename>pickdns.c</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,7 @@
 #include &quot;error.h&quot;
 #include &quot;byte.h&quot;
 #include &quot;dns.h&quot;
+#include &quot;printrecord.h&quot;
 #include &quot;printpacket.h&quot;
 
 static char *d;</diff>
      <filename>printpacket.c</filename>
    </modified>
    <modified>
      <diff>@@ -7,9 +7,9 @@
 
 static char *d;
 
-unsigned int printrecord_cat(stralloc *out,char *buf,unsigned int len,unsigned int pos,char *q,char qtype[2])
+unsigned int printrecord_cat(stralloc *out,const char *buf,unsigned int len,unsigned int pos,const char *q,const char qtype[2])
 {
-  char *x;
+  const char *x;
   char misc[20];
   uint16 datalen;
   uint16 u16;
@@ -108,7 +108,7 @@ unsigned int printrecord_cat(stralloc *out,char *buf,unsigned int len,unsigned i
   return newpos;
 }
 
-unsigned int printrecord(stralloc *out,char *buf,unsigned int len,unsigned int pos,char *q,char qtype[2])
+unsigned int printrecord(stralloc *out,const char *buf,unsigned int len,unsigned int pos,const char *q,const char qtype[2])
 {
   if (!stralloc_copys(out,&quot;&quot;)) return 0;
   return printrecord_cat(out,buf,len,pos,q,qtype);</diff>
      <filename>printrecord.c</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,7 @@
 
 #include &quot;stralloc.h&quot;
 
-extern unsigned int printrecord_cat(stralloc *,char *,unsigned int,unsigned int,char *,char *);
-extern unsigned int printrecord(stralloc *,char *,unsigned int,unsigned int,char *,char *);
+extern unsigned int printrecord_cat(stralloc *,const char *,unsigned int,unsigned int,const char *,const char *);
+extern unsigned int printrecord(stralloc *,const char *,unsigned int,unsigned int,const char *,const char *);
 
 #endif</diff>
      <filename>printrecord.h</filename>
    </modified>
    <modified>
      <diff>@@ -20,7 +20,7 @@ static void octal(unsigned char c)
   put('0' + (c &amp; 7));
 }
 
-void qlog(char ip[4],uint16 port,char id[2],char *q,char qtype[2],char *result)
+void qlog(const char ip[4],uint16 port,const char id[2],const char *q,const char qtype[2],const char *result)
 {
   char ch;
   char ch2;</diff>
      <filename>qlog.c</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,6 @@
 
 #include &quot;uint16.h&quot;
 
-extern void qlog(char *,uint16,char *,char *,char *,char *);
+extern void qlog(const char *,uint16,const char *,const char *,const char *,const char *);
 
 #endif</diff>
      <filename>qlog.h</filename>
    </modified>
    <modified>
      <diff>@@ -13,9 +13,14 @@
 #include &quot;response.h&quot;
 #include &quot;query.h&quot;
 
-extern int numactive;
+static int flagforwardonly = 0;
 
-static void cachegeneric(char type[2],char *d,char *data,unsigned int datalen,uint32 ttl)
+void query_forwardonly(void)
+{
+  flagforwardonly = 1;
+}
+
+static void cachegeneric(const char type[2],const char *d,const char *data,unsigned int datalen,uint32 ttl)
 {
   unsigned int len;
   char key[257];
@@ -40,7 +45,7 @@ static void save_start(void)
   save_ok = 1;
 }
 
-static void save_data(char *buf,unsigned int len)
+static void save_data(const char *buf,unsigned int len)
 {
   if (!save_ok) return;
   if (len &gt; (sizeof save_buf) - save_len) { save_ok = 0; return; }
@@ -48,14 +53,14 @@ static void save_data(char *buf,unsigned int len)
   save_len += len;
 }
 
-static void save_finish(char type[2],char *d,uint32 ttl)
+static void save_finish(const char type[2],const char *d,uint32 ttl)
 {
   if (!save_ok) return;
   cachegeneric(type,d,save_buf,save_len,ttl);
 }
 
 
-static int typematch(char rtype[2],char qtype[2])
+static int typematch(const char rtype[2],const char qtype[2])
 {
   return byte_equal(qtype,2,rtype) || byte_equal(qtype,2,DNS_T_ANY);
 }
@@ -94,10 +99,10 @@ static int rqa(struct query *z)
     if (z-&gt;alias[i]) {
       if (!response_query(z-&gt;alias[i],z-&gt;type)) return 0;
       while (i &gt; 0) {
-        if (!response_cname(z-&gt;alias[i],z-&gt;alias[i - 1])) return 0;
+        if (!response_cname(z-&gt;alias[i],z-&gt;alias[i - 1],z-&gt;aliasttl[i])) return 0;
         --i;
       }
-      if (!response_cname(z-&gt;alias[0],z-&gt;name[0])) return 0;
+      if (!response_cname(z-&gt;alias[0],z-&gt;name[0],z-&gt;aliasttl[0])) return 0;
       return 1;
     }
 
@@ -152,8 +157,6 @@ static int smaller(char *buf,unsigned int len,unsigned int pos1,unsigned int pos
   return 0;
 }
 
-static uint64 query_count = 0;
-
 static int doit(struct query *z,int state)
 {
   char key[257];
@@ -161,7 +164,7 @@ static int doit(struct query *z,int state)
   unsigned int cachedlen;
   char *buf;
   unsigned int len;
-  char *whichserver;
+  const char *whichserver;
   char header[12];
   char misc[20];
   unsigned int rcode;
@@ -176,7 +179,7 @@ static int doit(struct query *z,int state)
   uint16 datalen;
   char *control;
   char *d;
-  char *dtype;
+  const char *dtype;
   unsigned int dlen;
   int flagout;
   int flagcname;
@@ -184,6 +187,7 @@ static int doit(struct query *z,int state)
   int flagsoa;
   uint32 ttl;
   uint32 soattl;
+  uint32 cnamettl;
   int i;
   int j;
   int k;
@@ -216,7 +220,7 @@ static int doit(struct query *z,int state)
     }
     if (!rqa(z)) goto DIE;
     if (typematch(DNS_T_A,dtype)) {
-      if (!response_rstart(d,DNS_T_A,&quot;\0\0\0\0&quot;)) goto DIE;
+      if (!response_rstart(d,DNS_T_A,655360)) goto DIE;
       if (!response_addbytes(misc,4)) goto DIE;
       response_rfinish(RESPONSE_ANSWER);
     }
@@ -228,11 +232,12 @@ static int doit(struct query *z,int state)
     if (z-&gt;level) goto LOWERLEVEL;
     if (!rqa(z)) goto DIE;
     if (typematch(DNS_T_PTR,dtype)) {
-      if (!response_rstart(d,DNS_T_PTR,&quot;\0\0\0\0&quot;)) goto DIE;
+      if (!response_rstart(d,DNS_T_PTR,655360)) goto DIE;
       if (!response_addname(&quot;\011localhost\0&quot;)) goto DIE;
       response_rfinish(RESPONSE_ANSWER);
     }
     cleanup(z);
+    log_stats();
     return 1;
   }
 
@@ -240,26 +245,26 @@ static int doit(struct query *z,int state)
     byte_copy(key,2,DNS_T_ANY);
     byte_copy(key + 2,dlen,d);
     case_lowerb(key + 2,dlen);
-    cached = cache_get(key,dlen + 2,&amp;cachedlen);
+    cached = cache_get(key,dlen + 2,&amp;cachedlen,&amp;ttl);
     if (cached) {
       log_cachednxdomain(d);
       goto NXDOMAIN;
     }
 
     byte_copy(key,2,DNS_T_AXFR);
-    cached = cache_get(key,dlen + 2,&amp;cachedlen);
+    cached = cache_get(key,dlen + 2,&amp;cachedlen,&amp;ttl);
     if (cached) {
       log_cachedservfail(d);
       goto SERVFAIL;
     }
 
     byte_copy(key,2,DNS_T_CNAME);
-    cached = cache_get(key,dlen + 2,&amp;cachedlen);
+    cached = cache_get(key,dlen + 2,&amp;cachedlen,&amp;ttl);
     if (cached) {
       if (typematch(DNS_T_CNAME,dtype)) {
         log_cachedanswer(d,DNS_T_CNAME);
         if (!rqa(z)) goto DIE;
-	if (!response_cname(z-&gt;name[0],cached)) goto DIE;
+	if (!response_cname(z-&gt;name[0],cached,ttl)) goto DIE;
 	cleanup(z);
 	return 1;
       }
@@ -270,13 +275,13 @@ static int doit(struct query *z,int state)
 
     if (typematch(DNS_T_NS,dtype)) {
       byte_copy(key,2,DNS_T_NS);
-      cached = cache_get(key,dlen + 2,&amp;cachedlen);
+      cached = cache_get(key,dlen + 2,&amp;cachedlen,&amp;ttl);
       if (cached &amp;&amp; (cachedlen || byte_diff(dtype,2,DNS_T_ANY))) {
 	log_cachedanswer(d,DNS_T_NS);
 	if (!rqa(z)) goto DIE;
 	pos = 0;
 	while (pos = dns_packet_getname(cached,cachedlen,pos,&amp;t2)) {
-	  if (!response_rstart(d,DNS_T_NS,&quot;\0\0\0\0&quot;)) goto DIE;
+	  if (!response_rstart(d,DNS_T_NS,ttl)) goto DIE;
 	  if (!response_addname(t2)) goto DIE;
 	  response_rfinish(RESPONSE_ANSWER);
 	}
@@ -287,13 +292,13 @@ static int doit(struct query *z,int state)
 
     if (typematch(DNS_T_PTR,dtype)) {
       byte_copy(key,2,DNS_T_PTR);
-      cached = cache_get(key,dlen + 2,&amp;cachedlen);
+      cached = cache_get(key,dlen + 2,&amp;cachedlen,&amp;ttl);
       if (cached &amp;&amp; (cachedlen || byte_diff(dtype,2,DNS_T_ANY))) {
 	log_cachedanswer(d,DNS_T_PTR);
 	if (!rqa(z)) goto DIE;
 	pos = 0;
 	while (pos = dns_packet_getname(cached,cachedlen,pos,&amp;t2)) {
-	  if (!response_rstart(d,DNS_T_PTR,&quot;\0\0\0\0&quot;)) goto DIE;
+	  if (!response_rstart(d,DNS_T_PTR,ttl)) goto DIE;
 	  if (!response_addname(t2)) goto DIE;
 	  response_rfinish(RESPONSE_ANSWER);
 	}
@@ -304,7 +309,7 @@ static int doit(struct query *z,int state)
 
     if (typematch(DNS_T_MX,dtype)) {
       byte_copy(key,2,DNS_T_MX);
-      cached = cache_get(key,dlen + 2,&amp;cachedlen);
+      cached = cache_get(key,dlen + 2,&amp;cachedlen,&amp;ttl);
       if (cached &amp;&amp; (cachedlen || byte_diff(dtype,2,DNS_T_ANY))) {
 	log_cachedanswer(d,DNS_T_MX);
 	if (!rqa(z)) goto DIE;
@@ -312,7 +317,7 @@ static int doit(struct query *z,int state)
 	while (pos = dns_packet_copy(cached,cachedlen,pos,misc,2)) {
 	  pos = dns_packet_getname(cached,cachedlen,pos,&amp;t2);
 	  if (!pos) break;
-	  if (!response_rstart(d,DNS_T_MX,&quot;\0\0\0\0&quot;)) goto DIE;
+	  if (!response_rstart(d,DNS_T_MX,ttl)) goto DIE;
 	  if (!response_addbytes(misc,2)) goto DIE;
 	  if (!response_addname(t2)) goto DIE;
 	  response_rfinish(RESPONSE_ANSWER);
@@ -324,7 +329,7 @@ static int doit(struct query *z,int state)
 
     if (typematch(DNS_T_A,dtype)) {
       byte_copy(key,2,DNS_T_A);
-      cached = cache_get(key,dlen + 2,&amp;cachedlen);
+      cached = cache_get(key,dlen + 2,&amp;cachedlen,&amp;ttl);
       if (cached &amp;&amp; (cachedlen || byte_diff(dtype,2,DNS_T_ANY))) {
 	if (z-&gt;level) {
 	  log_cachedanswer(d,DNS_T_A);
@@ -343,7 +348,7 @@ static int doit(struct query *z,int state)
 	log_cachedanswer(d,DNS_T_A);
 	if (!rqa(z)) goto DIE;
 	while (cachedlen &gt;= 4) {
-	  if (!response_rstart(d,DNS_T_A,&quot;\0\0\0\0&quot;)) goto DIE;
+	  if (!response_rstart(d,DNS_T_A,ttl)) goto DIE;
 	  if (!response_addbytes(cached,4)) goto DIE;
 	  response_rfinish(RESPONSE_ANSWER);
 	  cached += 4;
@@ -356,7 +361,7 @@ static int doit(struct query *z,int state)
 
     if (!typematch(DNS_T_ANY,dtype) &amp;&amp; !typematch(DNS_T_AXFR,dtype) &amp;&amp; !typematch(DNS_T_CNAME,dtype) &amp;&amp; !typematch(DNS_T_NS,dtype) &amp;&amp; !typematch(DNS_T_PTR,dtype) &amp;&amp; !typematch(DNS_T_A,dtype) &amp;&amp; !typematch(DNS_T_MX,dtype)) {
       byte_copy(key,2,dtype);
-      cached = cache_get(key,dlen + 2,&amp;cachedlen);
+      cached = cache_get(key,dlen + 2,&amp;cachedlen,&amp;ttl);
       if (cached &amp;&amp; (cachedlen || byte_diff(dtype,2,DNS_T_ANY))) {
 	log_cachedanswer(d,dtype);
 	if (!rqa(z)) goto DIE;
@@ -365,7 +370,7 @@ static int doit(struct query *z,int state)
 	  cached += 2;
 	  cachedlen -= 2;
 	  if (datalen &gt; cachedlen) goto DIE;
-	  if (!response_rstart(d,dtype,&quot;\0\0\0\0&quot;)) goto DIE;
+	  if (!response_rstart(d,dtype,ttl)) goto DIE;
 	  if (!response_addbytes(cached,datalen)) goto DIE;
 	  response_rfinish(RESPONSE_ANSWER);
 	  cached += datalen;
@@ -385,12 +390,12 @@ static int doit(struct query *z,int state)
       break;
     }
 
-    if (z-&gt;level &lt; 2)
+    if (!flagforwardonly &amp;&amp; (z-&gt;level &lt; 2))
       if (dlen &lt; 255) {
         byte_copy(key,2,DNS_T_NS);
         byte_copy(key + 2,dlen,d);
         case_lowerb(key + 2,dlen);
-        cached = cache_get(key,dlen + 2,&amp;cachedlen);
+        cached = cache_get(key,dlen + 2,&amp;cachedlen,&amp;ttl);
         if (cached &amp;&amp; cachedlen) {
 	  z-&gt;control[z-&gt;level] = d;
           byte_zero(z-&gt;servers[z-&gt;level],64);
@@ -434,11 +439,11 @@ static int doit(struct query *z,int state)
   dns_sortip(z-&gt;servers[z-&gt;level],64);
   if (z-&gt;level) {
     log_tx(z-&gt;name[z-&gt;level],DNS_T_A,z-&gt;control[z-&gt;level],z-&gt;servers[z-&gt;level],z-&gt;level);
-    if (dns_transmit_start(&amp;z-&gt;dt,z-&gt;servers[z-&gt;level],0,z-&gt;name[z-&gt;level],DNS_T_A,z-&gt;localip) == -1) goto DIE;
+    if (dns_transmit_start(&amp;z-&gt;dt,z-&gt;servers[z-&gt;level],flagforwardonly,z-&gt;name[z-&gt;level],DNS_T_A,z-&gt;localip) == -1) goto DIE;
   }
   else {
     log_tx(z-&gt;name[0],z-&gt;type,z-&gt;control[0],z-&gt;servers[0],0);
-    if (dns_transmit_start(&amp;z-&gt;dt,z-&gt;servers[0],0,z-&gt;name[0],z-&gt;type,z-&gt;localip) == -1) goto DIE;
+    if (dns_transmit_start(&amp;z-&gt;dt,z-&gt;servers[0],flagforwardonly,z-&gt;name[0],z-&gt;type,z-&gt;localip) == -1) goto DIE;
   }
   return 0;
 
@@ -478,18 +483,21 @@ static int doit(struct query *z,int state)
   flagreferral = 0;
   flagsoa = 0;
   soattl = 0;
+  cnamettl = 0;
   for (j = 0;j &lt; numanswers;++j) {
     pos = dns_packet_getname(buf,len,pos,&amp;t1); if (!pos) goto DIE;
     pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) goto DIE;
 
     if (dns_domain_equal(t1,d))
-      if (byte_equal(header + 2,2,DNS_C_IN)) /* should always be true */
+      if (byte_equal(header + 2,2,DNS_C_IN)) { /* should always be true */
         if (typematch(header,dtype))
           flagout = 1;
         else if (typematch(header,DNS_T_CNAME)) {
           if (!dns_packet_getname(buf,len,pos,&amp;cname)) goto DIE;
           flagcname = 1;
+	  cnamettl = ttlget(header + 4);
         }
+      }
   
     uint16_unpack_big(header + 8,&amp;datalen);
     pos += datalen;
@@ -672,12 +680,16 @@ static int doit(struct query *z,int state)
 
 
   if (flagcname) {
+    ttl = cnamettl;
     CNAME:
     if (!z-&gt;level) {
       if (z-&gt;alias[QUERY_MAXALIAS - 1]) goto DIE;
       for (j = QUERY_MAXALIAS - 1;j &gt; 0;--j)
         z-&gt;alias[j] = z-&gt;alias[j - 1];
+      for (j = QUERY_MAXALIAS - 1;j &gt; 0;--j)
+        z-&gt;aliasttl[j] = z-&gt;aliasttl[j - 1];
       z-&gt;alias[0] = z-&gt;name[0];
+      z-&gt;aliasttl[0] = ttl;
       z-&gt;name[0] = 0;
     }
     if (!dns_domain_copy(&amp;z-&gt;name[z-&gt;level],cname)) goto DIE;
@@ -705,7 +717,7 @@ static int doit(struct query *z,int state)
 	  log_nodata(whichserver,d,dtype,soattl);
         }
 
-  log_stats(&amp;query_count,&amp;cache_motion,&amp;numactive);
+  log_stats();
 
 
   if (flagout || flagsoa || !flagreferral) {
@@ -735,11 +747,12 @@ static int doit(struct query *z,int state)
     for (j = 0;j &lt; numanswers;++j) {
       pos = dns_packet_getname(buf,len,pos,&amp;t1); if (!pos) goto DIE;
       pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) goto DIE;
+      ttl = ttlget(header + 4);
       uint16_unpack_big(header + 8,&amp;datalen);
       if (dns_domain_equal(t1,d))
         if (byte_equal(header + 2,2,DNS_C_IN)) /* should always be true */
           if (typematch(header,dtype)) {
-            if (!response_rstart(t1,header,&quot;\0\0\0\0&quot;)) goto DIE;
+            if (!response_rstart(t1,header,ttl)) goto DIE;
   
             if (typematch(header,DNS_T_NS) || typematch(header,DNS_T_CNAME) || typematch(header,DNS_T_PTR)) {
               if (!dns_packet_getname(buf,len,pos,&amp;t2)) goto DIE;
@@ -775,8 +788,8 @@ static int doit(struct query *z,int state)
   }
 
 
-  control = dns_domain_suffix(d,referral);
-  if (!control) goto DIE;
+  if (!dns_domain_suffix(d,referral)) goto DIE;
+  control = d + dns_domain_suffixpos(d,referral);
   z-&gt;control[z-&gt;level] = control;
   byte_zero(z-&gt;servers[z-&gt;level],64);
   for (j = 0;j &lt; QUERY_MAXNS;++j)
@@ -815,8 +828,6 @@ static int doit(struct query *z,int state)
 
 int query_start(struct query *z,char *dn,char type[2],char localip[4])
 {
-  ++query_count;
-
   if (byte_equal(type,2,DNS_T_AXFR)) { errno = error_perm; return -1; }
 
   cleanup(z);</diff>
      <filename>query.c</filename>
    </modified>
    <modified>
      <diff>@@ -2,8 +2,9 @@
 #define QUERY_H
 
 #include &quot;dns.h&quot;
+#include &quot;uint32.h&quot;
 
-#define QUERY_MAXLEVEL 4
+#define QUERY_MAXLEVEL 5
 #define QUERY_MAXALIAS 4
 #define QUERY_MAXNS 16
 
@@ -15,6 +16,7 @@ struct query {
   char *ns[QUERY_MAXLEVEL][QUERY_MAXNS];
   char servers[QUERY_MAXLEVEL][64];
   char *alias[QUERY_MAXALIAS];
+  uint32 aliasttl[QUERY_MAXALIAS];
   char localip[4];
   char type[2];
   struct dns_transmit dt;
@@ -24,4 +26,6 @@ extern int query_start(struct query *,char *,char *,char *);
 extern void query_io(struct query *,iopause_fd *,struct taia *);
 extern int query_get(struct query *,iopause_fd *,struct taia *);
 
+extern void query_forwardonly(void);
+
 #endif</diff>
      <filename>query.h</filename>
    </modified>
    <modified>
      <diff>@@ -13,7 +13,7 @@ char strnum[FMT_ULONG];
 
 char seed[128];
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   unsigned long u;
   int i;</diff>
      <filename>random-ip.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+#include &lt;unistd.h&gt;
 #include &lt;pwd.h&gt;
 #include &quot;strerr.h&quot;
 #include &quot;exit.h&quot;
@@ -18,7 +19,7 @@ struct passwd *pw;
 char *myip;
 char *base;
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   user = argv[1];
   if (!user) usage();</diff>
      <filename>rbldns-conf.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,8 @@
+#include &lt;stdio.h&gt;
+#include &lt;sys/types.h&gt;
+#include &lt;sys/stat.h&gt;
+#include &lt;unistd.h&gt;
 #include &quot;buffer.h&quot;
-#include &quot;readwrite.h&quot;
 #include &quot;exit.h&quot;
 #include &quot;cdb_make.h&quot;
 #include &quot;open.h&quot;
@@ -32,7 +35,7 @@ unsigned long linenum = 0;
 
 char strnum[FMT_ULONG];
 
-void syntaxerror(char *why)
+void syntaxerror(const char *why)
 {
   strnum[fmt_ulong(strnum,linenum)] = 0;
   strerr_die4x(111,FATAL,&quot;unable to parse data line &quot;,strnum,why);
@@ -42,10 +45,9 @@ void die_datatmp(void)
   strerr_die2sys(111,FATAL,&quot;unable to create data.tmp: &quot;);
 }
 
-main()
+int main()
 {
   char ip[4];
-  unsigned int iplen;
   unsigned long u;
   unsigned int j;
   unsigned int k;
@@ -55,7 +57,7 @@ main()
 
   fd = open_read(&quot;data&quot;);
   if (fd == -1) strerr_die2sys(111,FATAL,&quot;unable to open data: &quot;);
-  buffer_init(&amp;b,read,fd,bspace,sizeof bspace);
+  buffer_init(&amp;b,buffer_unixread,fd,bspace,sizeof bspace);
 
   fdcdb = open_trunc(&quot;data.tmp&quot;);
   if (fdcdb == -1) die_datatmp();</diff>
      <filename>rbldns-data.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+#include &lt;unistd.h&gt;
 #include &quot;str.h&quot;
 #include &quot;byte.h&quot;
 #include &quot;ip4.h&quot;
@@ -64,12 +65,12 @@ static int doit(char *q,char qtype[2])
   }
 
   if (flaga) {
-    if (!response_rstart(q,DNS_T_A,&quot;\0\0\10\0&quot;)) return 0;
+    if (!response_rstart(q,DNS_T_A,2048)) return 0;
     if (!response_addbytes(data,4)) return 0;
     response_rfinish(RESPONSE_ANSWER);
   }
   if (flagtxt) {
-    if (!response_rstart(q,DNS_T_TXT,&quot;\0\0\10\0&quot;)) return 0;
+    if (!response_rstart(q,DNS_T_TXT,2048)) return 0;
     ch = dlen - 4;
     if (!response_addbytes(&amp;ch,1)) return 0;
     if (!response_addbytes(data + 4,dlen - 4)) return 0;
@@ -100,7 +101,7 @@ int respond(char *q,char qtype[2],char ip[4])
   return result;
 }
 
-char *fatal = &quot;rbldns: fatal: &quot;;
+const char *fatal = &quot;rbldns: fatal: &quot;;
 
 void initialize(void)
 {</diff>
      <filename>rbldns.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,4 @@
-#include &quot;readwrite.h&quot;
+#include &lt;unistd.h&gt;
 #include &quot;error.h&quot;
 #include &quot;readclose.h&quot;
 </diff>
      <filename>readclose.c</filename>
    </modified>
    <modified>
      <diff>@@ -12,7 +12,7 @@ static char name[NAMES][128];
 static unsigned int name_ptr[NAMES]; /* each &lt; 16384 */
 static unsigned int name_num;
 
-int response_addbytes(char *buf,unsigned int len)
+int response_addbytes(const char *buf,unsigned int len)
 {
   if (len &gt; 65535 - response_len) return 0;
   byte_copy(response + response_len,len,buf);
@@ -20,7 +20,7 @@ int response_addbytes(char *buf,unsigned int len)
   return 1;
 }
 
-int response_addname(char *d)
+int response_addname(const char *d)
 {
   unsigned int dlen;
   unsigned int i;
@@ -49,7 +49,7 @@ int response_addname(char *d)
   return response_addbytes(d,1);
 }
 
-int response_query(char *q,char qtype[2])
+int response_query(const char *q,const char qtype[2])
 {
   response_len = 0;
   name_num = 0;
@@ -63,12 +63,22 @@ int response_query(char *q,char qtype[2])
 
 static unsigned int dpos;
 
-int response_rstart(char *d,char type[2],char ttl[4])
+static int flaghidettl = 0;
+
+void response_hidettl(void)
+{
+  flaghidettl = 1;
+}
+
+int response_rstart(const char *d,const char type[2],uint32 ttl)
 {
+  char ttlstr[4];
   if (!response_addname(d)) return 0;
   if (!response_addbytes(type,2)) return 0;
   if (!response_addbytes(DNS_C_IN,2)) return 0;
-  if (!response_addbytes(ttl,4)) return 0;
+  if (flaghidettl) ttl = 0;
+  uint32_pack_big(ttlstr,ttl);
+  if (!response_addbytes(ttlstr,4)) return 0;
   if (!response_addbytes(&quot;\0\0&quot;,2)) return 0;
   dpos = response_len;
   return 1;
@@ -80,9 +90,9 @@ void response_rfinish(int x)
   if (!++response[x + 1]) ++response[x];
 }
 
-int response_cname(char *c,char *d)
+int response_cname(const char *c,const char *d,uint32 ttl)
 {
-  if (!response_rstart(c,DNS_T_CNAME,&quot;\0\0\0\0&quot;)) return 0;
+  if (!response_rstart(c,DNS_T_CNAME,ttl)) return 0;
   if (!response_addname(d)) return 0;
   response_rfinish(RESPONSE_ANSWER);
   return 1;
@@ -99,7 +109,7 @@ void response_servfail(void)
   response[3] |= 2;
 }
 
-void response_id(char id[2])
+void response_id(const char id[2])
 {
   byte_copy(response,2,id);
 }</diff>
      <filename>response.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,24 +1,27 @@
 #ifndef RESPONSE_H
 #define RESPONSE_H
 
+#include &quot;uint32.h&quot;
+
 extern char response[];
 extern unsigned int response_len;
 
-extern int response_query(char *,char *);
+extern int response_query(const char *,const char *);
 extern void response_nxdomain(void);
 extern void response_servfail(void);
-extern void response_id(char *);
+extern void response_id(const char *);
 extern void response_tc(void);
 
-extern int response_addbytes(char *,unsigned int);
-extern int response_addname(char *);
-extern int response_rstart(char *,char *,char *);
+extern int response_addbytes(const char *,unsigned int);
+extern int response_addname(const char *);
+extern void response_hidettl(void);
+extern int response_rstart(const char *,const char *,uint32);
 extern void response_rfinish(int);
 
 #define RESPONSE_ANSWER 6
 #define RESPONSE_AUTHORITY 8
 #define RESPONSE_ADDITIONAL 10
 
-extern int response_cname(char *,char *);
+extern int response_cname(const char *,const char *,uint32);
 
 #endif</diff>
      <filename>response.h</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,8 @@
+#include &lt;unistd.h&gt;
 #include &quot;open.h&quot;
 #include &quot;error.h&quot;
 #include &quot;str.h&quot;
 #include &quot;byte.h&quot;
-#include &quot;readwrite.h&quot;
 #include &quot;error.h&quot;
 #include &quot;direntry.h&quot;
 #include &quot;ip4.h&quot;
@@ -57,7 +57,7 @@ int roots_same(char *q,char *q2)
 static int init2(DIR *dir)
 {
   direntry *d;
-  char *fqdn;
+  const char *fqdn;
   static char *q;
   static stralloc text;
   char servers[64];</diff>
      <filename>roots.c</filename>
    </modified>
    <modified>
      <diff>@@ -473,6 +473,12 @@ authority: test 259200 NS b.ns.test
 query: 16 436.test
 answer: 436.test 86400 16 \1770123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456\1777890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123\177456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789071234567890123456789012345678901234567890123456789012345
 0
+--- tinydns-data handles size-1000 TXT records
+16 1000.test:
+1047 bytes, 1+1+0+0 records, response, authoritative, noerror
+query: 16 1000.test
+answer: 1000.test 86400 16 \1770123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456\1777890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123\1774567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\1771234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567\1778901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234\1775678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901\1772345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678o901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
+0
 --- tinydns-data handles unusual characters in owner names
 1 \000\001\177\200\277\056\056\056.test:
 130 bytes, 1+1+2+3 records, response, authoritative, noerror
@@ -791,7 +797,7 @@ tinydns-edit: fatal: host name already used
 255 127.43.123.234:
 48 bytes, 1+1+0+0 records, response, noerror
 query: 255 127.43.123.234
-answer: 127.43.123.234 0 A 127.43.123.234
+answer: 127.43.123.234 655360 A 127.43.123.234
 0
 --- tinydns works
 
@@ -820,6 +826,8 @@ additional: ns.test 259200 A 127.43.0.2
 additional: a.mx.test 86400 A 127.43.0.100
 additional: b.mx.test 86400 A 127.43.0.101
 0
+--- dnscache handles large TXT records
+0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
 --- walldns handles in-addr.arpa names
 7.6.43.127.in-addr.arpa
 0
@@ -902,6 +910,9 @@ query: 255 0.0.0.4.rbl.test
 query: 255 pick.test
 answer: pick.test 5 A 127.43.0.101
 0
+--- pickdns answers MX
+0 pick.test
+0
 --- pickdns rejects queries for unknown information
 255 pick11.test:
 temporary failure
@@ -932,6 +943,7 @@ Ztest:ns.test.:hostmaster.test.:987654321:16384:2048:1048576:2560:2560
 +ns.pick2.test:127.43.0.3:259200
 &amp;rbl.test::ns.rbl.test.:259200
 +ns.rbl.test:127.43.0.5:259200
+:big.test:16:\1770123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456\1777890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123\1774567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\1771234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567\1778901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234\1775678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901\1772345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678o901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789:86400
 --- axfrdns gives authoritative answers
 255 test4:
 727 bytes, 1+12+0+0 records, response, authoritative, noerror
@@ -949,6 +961,12 @@ answer: test4 86400 16 3701234567890123456789012345678901234567890123456789
 answer: test4 86400 16 3801234567890123456789012345678901234567890123456789
 answer: test4 86400 16 3901234567890123456789012345678901234567890123456789
 0
+--- axfrdns handles size-1000 TXT records
+255 big.test:
+1046 bytes, 1+1+0+0 records, response, authoritative, noerror
+query: 255 big.test
+answer: big.test 86400 16 \1770123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456\1777890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123\1774567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\1771234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567\1778901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234\1775678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901\1772345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678o901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
+0
 --- axfr-get handles zones with wildcards
 0
 #987654321 auto axfr-get</diff>
      <filename>rts.exp</filename>
    </modified>
    <modified>
      <diff>@@ -7,6 +7,7 @@
 # dns_random works.
 # random-ip works.
 # dnstrace works.
+# dnstracesort works.
 # dns_resolvconfrewrite rereads after 10 minutes or 10000 uses.
 # dns_resolvconfip rereads after 10 minutes or 10000 uses.
 # /etc/resolv.conf is parsed properly.
@@ -39,6 +40,7 @@ echo '--- dnscache-conf works'
 dnscache-conf dnscache dnslog $service/dnscache 127.555.0.1
 echo 127.555.0.2 &gt; $service/dnscache/root/servers/tEST
 echo 127.555.0.4 &gt; $service/dnscache/root/servers/43.127.iN-aDDR.aRPA
+touch $service/dnscache/root/ip/127.43.0.1
 supervise $service/dnscache | supervise $service/dnscache/log &amp;
 
 echo '--- tinydns-conf works'
@@ -141,7 +143,7 @@ dnsmx network-surveys.cr.yp.to
 echo $?
 
 echo '--- dnsmx manufactures MX record for nonexistent.cr.yp.to'
-dnsmx nonexistent.cr.yp.to
+dnsmx NONexistent.cr.yp.to
 echo $?
 
 echo '--- dnsmx rejects overly long domain names'
@@ -346,6 +348,7 @@ echo '
 '\''430.test:0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
 '\''435.test:012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234
 '\''436.test:0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
+'\''1000.test:0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
 =\000\001\177\200\277\.\.\..test:10.5.6.7
 .7.6.5.10.in-addr.arpa:10.5.6.7
 
@@ -379,6 +382,9 @@ echo '--- tinydns-data excludes the authority section if necessary'
 ( cd rts-tmp; tinydns-get 16 435.test; echo $? )
 ( cd rts-tmp; tinydns-get 16 436.test; echo $? )
 
+echo '--- tinydns-data handles size-1000 TXT records'
+( cd rts-tmp; tinydns-get 16 1000.test; echo $? )
+
 echo '--- tinydns-data handles unusual characters in owner names'
 ( cd rts-tmp; tinydns-get A '\0\1\177\200\277\56\56\56.test'; echo $? )
 
@@ -531,9 +537,9 @@ echo '
 C*.Www.Test2:Www.Test2:5000
 =one.Test2:127.555.0.103::300000003456789a
 =two.Test2:127.555.0.104:0:500000003456789a
-.Test3:127.555.0.3
+.Test3:127.555.0.2
 =Www.Test3:127.0.0.106
-.Test4:127.555.0.4
+.Test4:127.555.0.2
 '\''Test4:001234567890123456789012345678901234567890123456789
 '\''Test4:101234567890123456789012345678901234567890123456789
 '\''Test4:201234567890123456789012345678901234567890123456789
@@ -544,6 +550,7 @@ C*.Www.Test2:Www.Test2:5000
 '\''Test4:701234567890123456789012345678901234567890123456789
 '\''Test4:801234567890123456789012345678901234567890123456789
 '\''Test4:901234567890123456789012345678901234567890123456789
+'\''Big.Test:0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
 ' &gt; $service/tinydns/root/data
 utime $service/tinydns/root/data 987654321
 ( cd $service/tinydns/root; tinydns-data )
@@ -608,6 +615,9 @@ echo $?
 dnsq Any TEST 127.555.0.2
 echo $?
 
+echo '--- dnscache handles large TXT records'
+dnstxt BIG.Test
+
 echo '--- walldns handles in-addr.arpa names'
 dnsname 127.555.6.7
 echo $?
@@ -666,6 +676,10 @@ echo $?
 dnsq 255 PICK.TEST 127.555.0.3
 echo $?
 
+echo '--- pickdns answers MX'
+dnsmx PICK.TEST
+echo $?
+
 echo '--- pickdns rejects queries for unknown information'
 dnsq 255 PICK11.TEST 127.555.0.3
 echo $?
@@ -687,6 +701,10 @@ echo '--- axfrdns gives authoritative answers'
 dnsq any Test4 127.43.0.2
 echo $?
 
+echo '--- axfrdns handles size-1000 TXT records'
+dnsq any BIG.TEST 127.43.0.2
+echo $?
+
 echo '--- axfr-get handles zones with wildcards'
 tcpclient -RHl0 127.43.0.2 53 axfr-get TEST2 rts-tmp/zone2 rts-tmp/zone2.tmp
 echo $?</diff>
      <filename>rts.tests</filename>
    </modified>
    <modified>
      <diff>@@ -1,28 +1,28 @@
 #ifndef SCAN_H
 #define SCAN_H
 
-extern unsigned int scan_uint(char *,unsigned int *);
-extern unsigned int scan_xint(char *,unsigned int *);
-extern unsigned int scan_nbbint(char *,unsigned int,unsigned int,unsigned int,unsigned int *);
-extern unsigned int scan_ushort(char *,unsigned short *);
-extern unsigned int scan_xshort(char *,unsigned short *);
-extern unsigned int scan_nbbshort(char *,unsigned int,unsigned int,unsigned int,unsigned short *);
-extern unsigned int scan_ulong(char *,unsigned long *);
-extern unsigned int scan_xlong(char *,unsigned long *);
-extern unsigned int scan_nbblong(char *,unsigned int,unsigned int,unsigned int,unsigned long *);
+extern unsigned int scan_uint(const char *,unsigned int *);
+extern unsigned int scan_xint(const char *,unsigned int *);
+extern unsigned int scan_nbbint(const char *,unsigned int,unsigned int,unsigned int,unsigned int *);
+extern unsigned int scan_ushort(const char *,unsigned short *);
+extern unsigned int scan_xshort(const char *,unsigned short *);
+extern unsigned int scan_nbbshort(const char *,unsigned int,unsigned int,unsigned int,unsigned short *);
+extern unsigned int scan_ulong(const char *,unsigned long *);
+extern unsigned int scan_xlong(const char *,unsigned long *);
+extern unsigned int scan_nbblong(const char *,unsigned int,unsigned int,unsigned int,unsigned long *);
 
-extern unsigned int scan_plusminus(char *,int *);
-extern unsigned int scan_0x(char *,unsigned int *);
+extern unsigned int scan_plusminus(const char *,int *);
+extern unsigned int scan_0x(const char *,unsigned int *);
 
-extern unsigned int scan_whitenskip(char *,unsigned int);
-extern unsigned int scan_nonwhitenskip(char *,unsigned int);
-extern unsigned int scan_charsetnskip(char *,char *,unsigned int);
-extern unsigned int scan_noncharsetnskip(char *,char *,unsigned int);
+extern unsigned int scan_whitenskip(const char *,unsigned int);
+extern unsigned int scan_nonwhitenskip(const char *,unsigned int);
+extern unsigned int scan_charsetnskip(const char *,const char *,unsigned int);
+extern unsigned int scan_noncharsetnskip(const char *,const char *,unsigned int);
 
-extern unsigned int scan_strncmp(char *,char *,unsigned int);
-extern unsigned int scan_memcmp(char *,char *,unsigned int);
+extern unsigned int scan_strncmp(const char *,const char *,unsigned int);
+extern unsigned int scan_memcmp(const char *,const char *,unsigned int);
 
-extern unsigned int scan_long(char *,long *);
-extern unsigned int scan_8long(char *,unsigned long *);
+extern unsigned int scan_long(const char *,long *);
+extern unsigned int scan_8long(const char *,unsigned long *);
 
 #endif</diff>
      <filename>scan.h</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #include &quot;scan.h&quot;
 
-unsigned int scan_ulong(register char *s,register unsigned long *u)
+unsigned int scan_ulong(register const char *s,register unsigned long *u)
 {
   register unsigned int pos = 0;
   register unsigned long result = 0;</diff>
      <filename>scan_ulong.c</filename>
    </modified>
    <modified>
      <diff>@@ -71,7 +71,7 @@ static int doit(void)
   return 0;
 }
 
-main()
+int main()
 {
   char *x;
   int udp53;</diff>
      <filename>server.c</filename>
    </modified>
    <modified>
      <diff>@@ -23,12 +23,12 @@ Documentation in sgetopt.3.
 #define optprogname sgetoptprogname
 
 int opterr = 1;
-char *optprogname = 0;
+const char *optprogname = 0;
 
-int getopt(int argc,char **argv,char *opts)
+int getopt(int argc,char **argv,const char *opts)
 {
   int c;
-  char *s;
+  const char *s;
 
   if (!optprogname) {
     optprogname = *argv;</diff>
      <filename>sgetopt.c</filename>
    </modified>
    <modified>
      <diff>@@ -14,8 +14,8 @@
 
 #include &quot;subgetopt.h&quot;
 
-extern int sgetoptmine(int,char **,char *);
+extern int sgetoptmine(int,char **,const char *);
 extern int sgetopterr;
-extern char *sgetoptprogname;
+extern const char *sgetoptprogname;
 
 #endif</diff>
      <filename>sgetopt.h</filename>
    </modified>
    <modified>
      <diff>@@ -6,14 +6,14 @@
 extern int socket_tcp(void);
 extern int socket_udp(void);
 
-extern int socket_connect4(int,char *,uint16);
+extern int socket_connect4(int,const char *,uint16);
 extern int socket_connected(int);
 extern int socket_bind4(int,char *,uint16);
 extern int socket_bind4_reuse(int,char *,uint16);
 extern int socket_listen(int,int);
 extern int socket_accept4(int,char *,uint16 *);
 extern int socket_recv4(int,char *,int,char *,uint16 *);
-extern int socket_send4(int,char *,int,char *,uint16);
+extern int socket_send4(int,const char *,int,const char *,uint16);
 extern int socket_local4(int,char *,uint16 *);
 extern int socket_remote4(int,char *,uint16 *);
 </diff>
      <filename>socket.h</filename>
    </modified>
    <modified>
      <diff>@@ -2,11 +2,11 @@
 #include &lt;sys/param.h&gt;
 #include &lt;sys/socket.h&gt;
 #include &lt;netinet/in.h&gt;
-#include &quot;readwrite.h&quot;
+#include &lt;unistd.h&gt;
 #include &quot;byte.h&quot;
 #include &quot;socket.h&quot;
 
-int socket_connect4(int s,char ip[4],uint16 port)
+int socket_connect4(int s,const char ip[4],uint16 port)
 {
   struct sockaddr_in sa;
 </diff>
      <filename>socket_conn.c</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@
 #include &quot;byte.h&quot;
 #include &quot;socket.h&quot;
 
-int socket_send4(int s,char *buf,int len,char ip[4],uint16 port)
+int socket_send4(int s,const char *buf,int len,const char ip[4],uint16 port)
 {
   struct sockaddr_in sa;
 </diff>
      <filename>socket_send.c</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,7 @@
 #include &lt;sys/param.h&gt;
 #include &lt;sys/socket.h&gt;
 #include &lt;netinet/in.h&gt;
+#include &lt;unistd.h&gt;
 #include &quot;ndelay.h&quot;
 #include &quot;socket.h&quot;
 </diff>
      <filename>socket_tcp.c</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,7 @@
 #include &lt;sys/param.h&gt;
 #include &lt;sys/socket.h&gt;
 #include &lt;netinet/in.h&gt;
+#include &lt;unistd.h&gt;
 #include &quot;ndelay.h&quot;
 #include &quot;socket.h&quot;
 </diff>
      <filename>socket_udp.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,13 +1,13 @@
 #ifndef STR_H
 #define STR_H
 
-extern unsigned int str_copy(char *,char *);
-extern int str_diff(char *,char *);
-extern int str_diffn(char *,char *,unsigned int);
-extern unsigned int str_len(char *);
-extern unsigned int str_chr(char *,int);
-extern unsigned int str_rchr(char *,int);
-extern int str_start(char *,char *);
+extern unsigned int str_copy(char *,const char *);
+extern int str_diff(const char *,const char *);
+extern int str_diffn(const char *,const char *,unsigned int);
+extern unsigned int str_len(const char *);
+extern unsigned int str_chr(const char *,int);
+extern unsigned int str_rchr(const char *,int);
+extern int str_start(const char *,const char *);
 
 #define str_equal(s,t) (!str_diff((s),(t)))
 </diff>
      <filename>str.h</filename>
    </modified>
    <modified>
      <diff>@@ -1,9 +1,9 @@
 #include &quot;str.h&quot;
 
-unsigned int str_chr(register char *s,int c)
+unsigned int str_chr(register const char *s,int c)
 {
   register char ch;
-  register char *t;
+  register const char *t;
 
   ch = c;
   t = s;</diff>
      <filename>str_chr.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #include &quot;str.h&quot;
 
-int str_diff(register char *s,register char *t)
+int str_diff(register const char *s,register const char *t)
 {
   register char x;
 </diff>
      <filename>str_diff.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,8 @@
 #include &quot;str.h&quot;
 
-unsigned int str_len(char *s)
+unsigned int str_len(const char *s)
 {
-  register char *t;
+  register const char *t;
 
   t = s;
   for (;;) {</diff>
      <filename>str_len.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,10 +1,10 @@
 #include &quot;str.h&quot;
 
-unsigned int str_rchr(register char *s,int c)
+unsigned int str_rchr(register const char *s,int c)
 {
   register char ch;
-  register char *t;
-  register char *u;
+  register const char *t;
+  register const char *u;
 
   ch = c;
   t = s;</diff>
      <filename>str_rchr.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #include &quot;str.h&quot;
 
-int str_start(register char *s,register char *t)
+int str_start(register const char *s,register const char *t)
 {
   register char x;
 </diff>
      <filename>str_start.c</filename>
    </modified>
    <modified>
      <diff>@@ -7,14 +7,14 @@ GEN_ALLOC_typedef(stralloc,char,s,len,a)
 
 extern int stralloc_ready(stralloc *,unsigned int);
 extern int stralloc_readyplus(stralloc *,unsigned int);
-extern int stralloc_copy(stralloc *,stralloc *);
-extern int stralloc_cat(stralloc *,stralloc *);
-extern int stralloc_copys(stralloc *,char *);
-extern int stralloc_cats(stralloc *,char *);
-extern int stralloc_copyb(stralloc *,char *,unsigned int);
-extern int stralloc_catb(stralloc *,char *,unsigned int);
-extern int stralloc_append(stralloc *,char *); /* beware: this takes a pointer to 1 char */
-extern int stralloc_starts(stralloc *,char *);
+extern int stralloc_copy(stralloc *,const stralloc *);
+extern int stralloc_cat(stralloc *,const stralloc *);
+extern int stralloc_copys(stralloc *,const char *);
+extern int stralloc_cats(stralloc *,const char *);
+extern int stralloc_copyb(stralloc *,const char *,unsigned int);
+extern int stralloc_catb(stralloc *,const char *,unsigned int);
+extern int stralloc_append(stralloc *,const char *); /* beware: this takes a pointer to 1 char */
+extern int stralloc_starts(stralloc *,const char *);
 
 #define stralloc_0(sa) stralloc_append(sa,&quot;&quot;)
 </diff>
      <filename>stralloc.h</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 #include &quot;byte.h&quot;
 #include &quot;stralloc.h&quot;
 
-int stralloc_cat(stralloc *sato,stralloc *safrom)
+int stralloc_cat(stralloc *sato,const stralloc *safrom)
 {
   return stralloc_catb(sato,safrom-&gt;s,safrom-&gt;len);
 }</diff>
      <filename>stralloc_cat.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 #include &quot;stralloc.h&quot;
 #include &quot;byte.h&quot;
 
-int stralloc_catb(stralloc *sa,char *s,unsigned int n)
+int stralloc_catb(stralloc *sa,const char *s,unsigned int n)
 {
   if (!sa-&gt;s) return stralloc_copyb(sa,s,n);
   if (!stralloc_readyplus(sa,n + 1)) return 0;</diff>
      <filename>stralloc_catb.c</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,7 @@
 #include &quot;str.h&quot;
 #include &quot;stralloc.h&quot;
 
-int stralloc_cats(stralloc *sa,char *s)
+int stralloc_cats(stralloc *sa,const char *s)
 {
   return stralloc_catb(sa,s,str_len(s));
 }</diff>
      <filename>stralloc_cats.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 #include &quot;byte.h&quot;
 #include &quot;stralloc.h&quot;
 
-int stralloc_copy(stralloc *sato,stralloc *safrom)
+int stralloc_copy(stralloc *sato,const stralloc *safrom)
 {
   return stralloc_copyb(sato,safrom-&gt;s,safrom-&gt;len);
 }</diff>
      <filename>stralloc_copy.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 #include &quot;stralloc.h&quot;
 #include &quot;byte.h&quot;
 
-int stralloc_copyb(stralloc *sa,char *s,unsigned int n)
+int stralloc_copyb(stralloc *sa,const char *s,unsigned int n)
 {
   if (!stralloc_ready(sa,n + 1)) return 0;
   byte_copy(sa-&gt;s,n,s);</diff>
      <filename>stralloc_opyb.c</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,7 @@
 #include &quot;str.h&quot;
 #include &quot;stralloc.h&quot;
 
-int stralloc_copys(stralloc *sa,char *s)
+int stralloc_copys(stralloc *sa,const char *s)
 {
   return stralloc_copyb(sa,s,str_len(s));
 }</diff>
      <filename>stralloc_opys.c</filename>
    </modified>
    <modified>
      <diff>@@ -3,17 +3,17 @@
 
 struct strerr {
   struct strerr *who;
-  char *x;
-  char *y;
-  char *z;
+  const char *x;
+  const char *y;
+  const char *z;
 } ;
 
 extern struct strerr strerr_sys;
 extern void strerr_sysinit(void);
 
-extern char *strerr(struct strerr *);
-extern void strerr_warn(char *,char *,char *,char *,char *,char *,struct strerr *);
-extern void strerr_die(int,char *,char *,char *,char *,char *,char *,struct strerr *);
+extern const char *strerr(const struct strerr *);
+extern void strerr_warn(const char *,const char *,const char *,const char *,const char *,const char *,const struct strerr *);
+extern void strerr_die(int,const char *,const char *,const char *,const char *,const char *,const char *,const struct strerr *);
 
 #define STRERR(r,se,a) \
 { se.who = 0; se.x = a; se.y = 0; se.z = 0; return r; }</diff>
      <filename>strerr.h</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,7 @@
 #include &quot;exit.h&quot;
 #include &quot;strerr.h&quot;
 
-void strerr_warn(char *x1,char *x2,char *x3,char *x4,char *x5,char *x6,struct strerr *se)
+void strerr_warn(const char *x1,const char *x2,const char *x3,const char *x4,const char *x5,const char *x6,const struct strerr *se)
 {
   strerr_sysinit();
  
@@ -24,7 +24,7 @@ void strerr_warn(char *x1,char *x2,char *x3,char *x4,char *x5,char *x6,struct st
   buffer_flush(buffer_2);
 }
 
-void strerr_die(int e,char *x1,char *x2,char *x3,char *x4,char *x5,char *x6,struct strerr *se)
+void strerr_die(int e,const char *x1,const char *x2,const char *x3,const char *x4,const char *x5,const char *x6,const struct strerr *se)
 {
   strerr_warn(x1,x2,x3,x4,x5,x6,se);
   _exit(e);</diff>
      <filename>strerr_die.c</filename>
    </modified>
    <modified>
      <diff>@@ -14,10 +14,10 @@ char *optarg = 0;
 int optproblem = 0;
 int optdone = SUBGETOPTDONE;
 
-int sgopt(int argc,char **argv,char *opts)
+int sgopt(int argc,char **argv,const char *opts)
 {
   int c;
-  char *s;
+  const char *s;
 
   optarg = 0;
   if (!argv || (optind &gt;= argc) || !argv[optind]) return optdone;</diff>
      <filename>subgetopt.c</filename>
    </modified>
    <modified>
      <diff>@@ -13,7 +13,7 @@
 
 #define SUBGETOPTDONE -1
 
-extern int subgetopt(int,char **,char *);
+extern int subgetopt(int,char **,const char *);
 extern char *subgetoptarg;
 extern int subgetoptind;
 extern int subgetoptpos;</diff>
      <filename>subgetopt.h</filename>
    </modified>
    <modified>
      <diff>@@ -13,13 +13,13 @@ extern void tai_now(struct tai *);
 
 #define tai_approx(t) ((double) ((t)-&gt;x))
 
-extern void tai_add(struct tai *,struct tai *,struct tai *);
-extern void tai_sub(struct tai *,struct tai *,struct tai *);
+extern void tai_add(struct tai *,const struct tai *,const struct tai *);
+extern void tai_sub(struct tai *,const struct tai *,const struct tai *);
 #define tai_less(t,u) ((t)-&gt;x &lt; (u)-&gt;x)
 
 #define TAI_PACK 8
-extern void tai_pack(char *,struct tai *);
-extern void tai_unpack(char *,struct tai *);
+extern void tai_pack(char *,const struct tai *);
+extern void tai_unpack(const char *,struct tai *);
 
 extern void tai_uint(struct tai *,unsigned int);
 </diff>
      <filename>tai.h</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #include &quot;tai.h&quot;
 
-void tai_add(struct tai *t,struct tai *u,struct tai *v)
+void tai_add(struct tai *t,const struct tai *u,const struct tai *v)
 {
   t-&gt;x = u-&gt;x + v-&gt;x;
 }</diff>
      <filename>tai_add.c</filename>
    </modified>
    <modified>
      <diff>@@ -3,5 +3,5 @@
 
 void tai_now(struct tai *t)
 {
-  tai_unix(t,time((long *) 0));
+  tai_unix(t,time((time_t *) 0));
 }</diff>
      <filename>tai_now.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #include &quot;tai.h&quot;
 
-void tai_pack(char *s,struct tai *t)
+void tai_pack(char *s,const struct tai *t)
 {
   uint64 x;
 </diff>
      <filename>tai_pack.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #include &quot;tai.h&quot;
 
-void tai_sub(struct tai *t,struct tai *u,struct tai *v)
+void tai_sub(struct tai *t,const struct tai *u,const struct tai *v)
 {
   t-&gt;x = u-&gt;x - v-&gt;x;
 }</diff>
      <filename>tai_sub.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #include &quot;tai.h&quot;
 
-void tai_unpack(char *s,struct tai *t)
+void tai_unpack(const char *s,struct tai *t)
 {
   uint64 x;
 </diff>
      <filename>tai_unpack.c</filename>
    </modified>
    <modified>
      <diff>@@ -9,24 +9,25 @@ struct taia {
   unsigned long atto; /* 0...999999999 */
 } ;
 
-extern void taia_tai(struct taia *,struct tai *);
+extern void taia_tai(const struct taia *,struct tai *);
 
 extern void taia_now(struct taia *);
 
-extern double taia_approx(struct taia *);
-extern double taia_frac(struct taia *);
+extern double taia_approx(const struct taia *);
+extern double taia_frac(const struct taia *);
 
-extern void taia_add(struct taia *,struct taia *,struct taia *);
-extern void taia_sub(struct taia *,struct taia *,struct taia *);
-extern void taia_half(struct taia *,struct taia *);
-extern int taia_less(struct taia *,struct taia *);
+extern void taia_add(struct taia *,const struct taia *,const struct taia *);
+extern void taia_addsec(struct taia *,const struct taia *,int);
+extern void taia_sub(struct taia *,const struct taia *,const struct taia *);
+extern void taia_half(struct taia *,const struct taia *);
+extern int taia_less(const struct taia *,const struct taia *);
 
 #define TAIA_PACK 16
-extern void taia_pack(char *,struct taia *);
-extern void taia_unpack(char *,struct taia *);
+extern void taia_pack(char *,const struct taia *);
+extern void taia_unpack(const char *,struct taia *);
 
 #define TAIA_FMTFRAC 19
-extern unsigned int taia_fmtfrac(char *,struct taia *);
+extern unsigned int taia_fmtfrac(char *,const struct taia *);
 
 extern void taia_uint(struct taia *,unsigned int);
 </diff>
      <filename>taia.h</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,7 @@
 
 /* XXX: breaks tai encapsulation */
 
-void taia_add(struct taia *t,struct taia *u,struct taia *v)
+void taia_add(struct taia *t,const struct taia *u,const struct taia *v)
 {
   t-&gt;sec.x = u-&gt;sec.x + v-&gt;sec.x;
   t-&gt;nano = u-&gt;nano + v-&gt;nano;</diff>
      <filename>taia_add.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #include &quot;taia.h&quot;
 
-double taia_approx(struct taia *t)
+double taia_approx(const struct taia *t)
 {
   return tai_approx(&amp;t-&gt;sec) + taia_frac(t);
 }</diff>
      <filename>taia_approx.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #include &quot;taia.h&quot;
 
-double taia_frac(struct taia *t)
+double taia_frac(const struct taia *t)
 {
   return (t-&gt;atto * 0.000000001 + t-&gt;nano) * 0.000000001;
 }</diff>
      <filename>taia_frac.c</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,7 @@
 
 /* XXX: breaks tai encapsulation */
 
-int taia_less(struct taia *t,struct taia *u)
+int taia_less(const struct taia *t,const struct taia *u)
 {
   if (t-&gt;sec.x &lt; u-&gt;sec.x) return 1;
   if (t-&gt;sec.x &gt; u-&gt;sec.x) return 0;</diff>
      <filename>taia_less.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #include &quot;taia.h&quot;
 
-void taia_pack(char *s,struct taia *t)
+void taia_pack(char *s,const struct taia *t)
 {
   unsigned long x;
 </diff>
      <filename>taia_pack.c</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,7 @@
 
 /* XXX: breaks tai encapsulation */
 
-void taia_sub(struct taia *t,struct taia *u,struct taia *v)
+void taia_sub(struct taia *t,const struct taia *u,const struct taia *v)
 {
   unsigned long unano = u-&gt;nano;
   unsigned long uatto = u-&gt;atto;</diff>
      <filename>taia_sub.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #include &quot;taia.h&quot;
 
-void taia_tai(struct taia *ta,struct tai *t)
+void taia_tai(const struct taia *ta,struct tai *t)
 {
   *t = ta-&gt;sec;
 }</diff>
      <filename>taia_tai.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+#include &lt;unistd.h&gt;
 #include &quot;uint16.h&quot;
 #include &quot;open.h&quot;
 #include &quot;tai.h&quot;
@@ -8,7 +9,7 @@
 #include &quot;seek.h&quot;
 #include &quot;response.h&quot;
 
-static int want(char *owner,char type[2])
+static int want(const char *owner,const char type[2])
 {
   unsigned int pos;
   static char *d;
@@ -34,11 +35,11 @@ static char *d1;
 
 static struct tai now;
 static struct cdb c;
-static char data[512];
+static char data[32767];
 static uint32 dlen;
 static unsigned int dpos;
 static char type[2];
-static char ttl[4];
+static uint32 ttl;
 
 static int find(char *d,int flagwild)
 {
@@ -46,6 +47,7 @@ static int find(char *d,int flagwild)
   char ch;
   struct tai cutoff;
   char ttd[8];
+  char ttlstr[4];
   double newttl;
 
   for (;;) {
@@ -57,17 +59,18 @@ static int find(char *d,int flagwild)
     dpos = dns_packet_copy(data,dlen,0,type,2); if (!dpos) return -1;
     dpos = dns_packet_copy(data,dlen,dpos,&amp;ch,1); if (!dpos) return -1;
     if (flagwild != (ch == '*')) continue;
-    dpos = dns_packet_copy(data,dlen,dpos,ttl,4); if (!dpos) return -1;
+    dpos = dns_packet_copy(data,dlen,dpos,ttlstr,4); if (!dpos) return -1;
+    uint32_unpack_big(ttlstr,&amp;ttl);
     dpos = dns_packet_copy(data,dlen,dpos,ttd,8); if (!dpos) return -1;
     if (byte_diff(ttd,8,&quot;\0\0\0\0\0\0\0\0&quot;)) {
       tai_unpack(ttd,&amp;cutoff);
-      if (byte_equal(ttl,4,&quot;\0\0\0\0&quot;)) {
+      if (ttl == 0) {
 	if (tai_less(&amp;cutoff,&amp;now)) continue;
 	tai_sub(&amp;cutoff,&amp;cutoff,&amp;now);
 	newttl = tai_approx(&amp;cutoff);
 	if (newttl &lt;= 2.0) newttl = 2.0;
 	if (newttl &gt;= 3600.0) newttl = 3600.0;
-	uint32_pack_big(ttl,(uint32) newttl);
+	ttl = newttl;
       }
       else
 	if (!tai_less(&amp;cutoff,&amp;now)) continue;</diff>
      <filename>tdlookup.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
+#include &lt;unistd.h&gt;
 #include &quot;error.h&quot;
 #include &quot;iopause.h&quot;
-#include &quot;readwrite.h&quot;
 #include &quot;timeoutread.h&quot;
 
 int timeoutread(int t,int fd,char *buf,int len)</diff>
      <filename>timeoutread.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
+#include &lt;unistd.h&gt;
 #include &quot;error.h&quot;
 #include &quot;iopause.h&quot;
-#include &quot;readwrite.h&quot;
 #include &quot;timeoutwrite.h&quot;
 
 int timeoutwrite(int t,int fd,char *buf,int len)</diff>
      <filename>timeoutwrite.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+#include &lt;unistd.h&gt;
 #include &lt;pwd.h&gt;
 #include &quot;strerr.h&quot;
 #include &quot;exit.h&quot;
@@ -17,7 +18,7 @@ char *loguser;
 struct passwd *pw;
 char *myip;
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   user = argv[1];
   if (!user) usage();
@@ -45,7 +46,7 @@ main(int argc,char **argv)
 
   start(&quot;run&quot;);
   outs(&quot;#!/bin/sh\nexec 2&gt;&amp;1\nexec envuidgid &quot;); outs(user);
-  outs(&quot; envdir ./env softlimit -d250000 &quot;);
+  outs(&quot; envdir ./env softlimit -d300000 &quot;);
   outs(auto_home); outs(&quot;/bin/tinydns\n&quot;);
   finish();
   perm(0755);</diff>
      <filename>tinydns-conf.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,5 @@
+#include &lt;stdio.h&gt;
+#include &lt;unistd.h&gt;
 #include &lt;sys/types.h&gt;
 #include &lt;sys/stat.h&gt;
 #include &quot;uint16.h&quot;
@@ -7,7 +9,8 @@
 #include &quot;fmt.h&quot;
 #include &quot;ip4.h&quot;
 #include &quot;exit.h&quot;
-#include &quot;readwrite.h&quot;
+#include &quot;case.h&quot;
+#include &quot;scan.h&quot;
 #include &quot;buffer.h&quot;
 #include &quot;strerr.h&quot;
 #include &quot;getln.h&quot;
@@ -98,15 +101,15 @@ struct cdb_make cdb;
 static stralloc key;
 static stralloc result;
 
-void rr_add(char *buf,unsigned int len)
+void rr_add(const char *buf,unsigned int len)
 {
   if (!stralloc_catb(&amp;result,buf,len)) nomem();
 }
-void rr_addname(char *d)
+void rr_addname(const char *d)
 {
   rr_add(d,dns_domain_length(d));
 }
-void rr_start(char type[2],unsigned long ttl,char ttd[8])
+void rr_start(const char type[2],unsigned long ttl,const char ttd[8])
 {
   char buf[4];
   if (!stralloc_copyb(&amp;result,type,2)) nomem();
@@ -115,7 +118,7 @@ void rr_start(char type[2],unsigned long ttl,char ttd[8])
   rr_add(buf,4);
   rr_add(ttd,8);
 }
-void rr_finish(char *owner)
+void rr_finish(const char *owner)
 {
   if (byte_equal(owner,2,&quot;\1*&quot;)) {
     owner += 2;
@@ -143,13 +146,13 @@ char dptr[DNS_NAME4_DOMAIN];
 
 char strnum[FMT_ULONG];
 
-void syntaxerror(char *why)
+void syntaxerror(const char *why)
 {
   strnum[fmt_ulong(strnum,linenum)] = 0;
   strerr_die4x(111,FATAL,&quot;unable to parse data line &quot;,strnum,why);
 }
 
-main()
+int main()
 {
   int fddata;
   int i;
@@ -171,7 +174,7 @@ main()
     strerr_die2sys(111,FATAL,&quot;unable to open data: &quot;);
   defaultsoa_init(fddata);
 
-  buffer_init(&amp;b,read,fddata,bspace,sizeof bspace);
+  buffer_init(&amp;b,buffer_unixread,fddata,bspace,sizeof bspace);
 
   fdcdb = open_trunc(&quot;data.tmp&quot;);
   if (fdcdb == -1) die_datatmp();</diff>
      <filename>tinydns-data.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,9 +1,11 @@
+#include &lt;stdio.h&gt;
+#include &lt;unistd.h&gt;
 #include &lt;sys/types.h&gt;
 #include &lt;sys/stat.h&gt;
 #include &quot;stralloc.h&quot;
 #include &quot;buffer.h&quot;
-#include &quot;readwrite.h&quot;
 #include &quot;exit.h&quot;
+#include &quot;open.h&quot;
 #include &quot;getln.h&quot;
 #include &quot;strerr.h&quot;
 #include &quot;scan.h&quot;
@@ -65,12 +67,12 @@ char strnum[FMT_ULONG];
 static char *names[26];
 static int used[26];
 
-void put(char *buf,unsigned int len)
+void put(const char *buf,unsigned int len)
 {
   if (buffer_putalign(&amp;bnew,buf,len) == -1) die_write();
 }
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   unsigned long ttl;
   struct stat st;
@@ -109,12 +111,12 @@ main(int argc,char **argv)
   fd = open_read(fn);
   if (fd == -1) die_read();
   if (fstat(fd,&amp;st) == -1) die_read();
-  buffer_init(&amp;b,read,fd,bspace,sizeof bspace);
+  buffer_init(&amp;b,buffer_unixread,fd,bspace,sizeof bspace);
 
   fdnew = open_trunc(fnnew);
   if (fdnew == -1) die_write();
   if (fchmod(fdnew,st.st_mode &amp; 0644) == -1) die_write();
-  buffer_init(&amp;bnew,write,fdnew,bnewspace,sizeof bnewspace);
+  buffer_init(&amp;bnew,buffer_unixwrite,fdnew,bnewspace,sizeof bnewspace);
 
   switch(mode) {
     case '.': case '&amp;':</diff>
      <filename>tinydns-edit.c</filename>
    </modified>
    <modified>
      <diff>@@ -7,6 +7,7 @@
 #include &quot;strerr.h&quot;
 #include &quot;uint16.h&quot;
 #include &quot;response.h&quot;
+#include &quot;case.h&quot;
 #include &quot;printpacket.h&quot;
 #include &quot;parsetype.h&quot;
 #include &quot;dns.h&quot;
@@ -27,7 +28,7 @@ static char *q;
 
 static stralloc out;
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   uint16 u16;
 </diff>
      <filename>tinydns-get.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,4 @@
-char *fatal = &quot;tinydns: fatal: &quot;;
+const char *fatal = &quot;tinydns: fatal: &quot;;
 
 void initialize(void)
 {</diff>
      <filename>tinydns.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,4 @@
-main()
+int main()
 {
 #ifdef NeXT
   printf(&quot;nextstep\n&quot;); exit(0);</diff>
      <filename>trycpp.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,4 @@
-main()
+int main()
 {
   ;
 }</diff>
      <filename>trylsock.c</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,7 @@
 #include &lt;fcntl.h&gt;
 #include &lt;poll.h&gt;
 
-main()
+int main()
 {
   struct pollfd x;
 </diff>
      <filename>trypoll.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,4 @@
-main()
+int main()
 {
   short x[4];
  </diff>
      <filename>tryshsgr.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,4 @@
-main()
+int main()
 {
   unsigned long u;
   u = 1;</diff>
      <filename>tryulong32.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,4 @@
-main()
+int main()
 {
   unsigned long u;
   u = 1;</diff>
      <filename>tryulong64.c</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ typedef unsigned short uint16;
 
 extern void uint16_pack(char *,uint16);
 extern void uint16_pack_big(char *,uint16);
-extern void uint16_unpack(char *,uint16 *);
-extern void uint16_unpack_big(char *,uint16 *);
+extern void uint16_unpack(const char *,uint16 *);
+extern void uint16_unpack_big(const char *,uint16 *);
 
 #endif</diff>
      <filename>uint16.h</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #include &quot;uint16.h&quot;
 
-void uint16_unpack(char s[2],uint16 *u)
+void uint16_unpack(const char s[2],uint16 *u)
 {
   uint16 result;
 
@@ -11,7 +11,7 @@ void uint16_unpack(char s[2],uint16 *u)
   *u = result;
 }
 
-void uint16_unpack_big(char s[2],uint16 *u)
+void uint16_unpack_big(const char s[2],uint16 *u)
 {
   uint16 result;
 </diff>
      <filename>uint16_unpack.c</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ typedef unsigned int uint32;
 
 extern void uint32_pack(char *,uint32);
 extern void uint32_pack_big(char *,uint32);
-extern void uint32_unpack(char *,uint32 *);
-extern void uint32_unpack_big(char *,uint32 *);
+extern void uint32_unpack(const char *,uint32 *);
+extern void uint32_unpack_big(const char *,uint32 *);
 
 #endif</diff>
      <filename>uint32.h1</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ typedef unsigned long uint32;
 
 extern void uint32_pack(char *,uint32);
 extern void uint32_pack_big(char *,uint32);
-extern void uint32_unpack(char *,uint32 *);
-extern void uint32_unpack_big(char *,uint32 *);
+extern void uint32_unpack(const char *,uint32 *);
+extern void uint32_unpack_big(const char *,uint32 *);
 
 #endif</diff>
      <filename>uint32.h2</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 #include &quot;uint32.h&quot;
 
-void uint32_unpack(char s[4],uint32 *u)
+void uint32_unpack(const char s[4],uint32 *u)
 {
   uint32 result;
 
@@ -15,7 +15,7 @@ void uint32_unpack(char s[4],uint32 *u)
   *u = result;
 }
 
-void uint32_unpack_big(char s[4],uint32 *u)
+void uint32_unpack_big(const char s[4],uint32 *u)
 {
   uint32 result;
 </diff>
      <filename>uint32_unpack.c</filename>
    </modified>
    <modified>
      <diff>@@ -9,7 +9,7 @@ char *ustr;
 unsigned long u;
 time_t ut[2];
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   fn = argv[1];
   if (!fn) _exit(100);</diff>
      <filename>utime.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+#include &lt;unistd.h&gt;
 #include &lt;pwd.h&gt;
 #include &quot;strerr.h&quot;
 #include &quot;exit.h&quot;
@@ -17,7 +18,7 @@ char *loguser;
 struct passwd *pw;
 char *myip;
 
-main(int argc,char **argv)
+int main(int argc,char **argv)
 {
   user = argv[1];
   if (!user) usage();</diff>
      <filename>walldns-conf.c</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,7 @@
 #include &quot;dd.h&quot;
 #include &quot;response.h&quot;
 
-char *fatal = &quot;walldns: fatal: &quot;;
+const char *fatal = &quot;walldns: fatal: &quot;;
 
 void initialize(void)
 {
@@ -24,7 +24,7 @@ int respond(char *q,char qtype[2])
   if (flaga || flagptr) {
     if (dd(q,&quot;&quot;,ip) == 4) {
       if (flaga) {
-        if (!response_rstart(q,DNS_T_A,&quot;\0\12\0\0&quot;)) return 0;
+        if (!response_rstart(q,DNS_T_A,655360)) return 0;
         if (!response_addbytes(ip,4)) return 0;
         response_rfinish(RESPONSE_ANSWER);
       }
@@ -33,7 +33,7 @@ int respond(char *q,char qtype[2])
     j = dd(q,&quot;\7in-addr\4arpa&quot;,ip);
     if (j &gt;= 0) {
       if (flaga &amp;&amp; (j == 4)) {
-        if (!response_rstart(q,DNS_T_A,&quot;\0\12\0\0&quot;)) return 0;
+        if (!response_rstart(q,DNS_T_A,655360)) return 0;
         if (!response_addbytes(ip + 3,1)) return 0;
         if (!response_addbytes(ip + 2,1)) return 0;
         if (!response_addbytes(ip + 1,1)) return 0;
@@ -41,7 +41,7 @@ int respond(char *q,char qtype[2])
         response_rfinish(RESPONSE_ANSWER);
       }
       if (flagptr) {
-        if (!response_rstart(q,DNS_T_PTR,&quot;\0\12\0\0&quot;)) return 0;
+        if (!response_rstart(q,DNS_T_PTR,655360)) return 0;
         if (!response_addname(q)) return 0;
         response_rfinish(RESPONSE_ANSWER);
       }</diff>
      <filename>walldns.c</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ void nope()
   exit(1);
 }
 
-main()
+int main()
 {
   unsigned long x[4];
   unsigned long y[4];</diff>
      <filename>x86cpuid.c</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>readwrite.h</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>6c035c66f38f19c029390b761d232673a41a1538</id>
    </parent>
  </parents>
  <author>
    <name>Nick Andrew</name>
    <email>nick@nick-andrew.net</email>
  </author>
  <url>http://github.com/nickandrew/djbdns/commit/2ba504ae479a8cb3dc2182d14db4f51f6c738b50</url>
  <id>2ba504ae479a8cb3dc2182d14db4f51f6c738b50</id>
  <committed-date>2009-06-07T05:35:12-07:00</committed-date>
  <authored-date>2009-06-07T05:35:12-07:00</authored-date>
  <message>djbdns 1.03</message>
  <tree>4126bb381b26e7df3693ade35c753529bab56ed4</tree>
  <committer>
    <name>Nick Andrew</name>
    <email>nick@nick-andrew.net</email>
  </committer>
</commit>
