Thank you to Florent Guillaume for providing a no-iterative rotation algorithm. :-)

This version should fix the problem with the CNAME record
This patch only rotate A record.

This code is copyright (C) 2000-2001 by Thomas Mangin <thomas.mangin@free.fr>
This code is under the same licence than the code it modify.
--

diff -uP djbdns-1.05.orig/Makefile djbdns-1.05.modified/Makefile
--- djbdns-1.05.orig/Makefile	Sun Feb 11 16:11:45 2001
+++ djbdns-1.05.modified/Makefile	Sun Jun 10 12:21:12 2001
@@ -155,7 +155,7 @@
 cachetest: \
 load cachetest.o cache.o libtai.a buffer.a alloc.a unix.a byte.a
 	./load cachetest cache.o libtai.a buffer.a alloc.a unix.a \
-	byte.a 
+	byte.a dns.a
 
 cachetest.o: \
 compile cachetest.c buffer.h exit.h cache.h uint32.h uint64.h str.h
@@ -228,11 +228,11 @@
 dns.a: \
 makelib dns_dfd.o dns_domain.o dns_dtda.o dns_ip.o dns_ipq.o dns_mx.o \
 dns_name.o dns_nd.o dns_packet.o dns_random.o dns_rcip.o dns_rcrw.o \
-dns_resolve.o dns_sortip.o dns_transmit.o dns_txt.o
+dns_resolve.o dns_rotateip.o dns_sortip.o dns_transmit.o dns_txt.o
 	./makelib dns.a dns_dfd.o dns_domain.o dns_dtda.o dns_ip.o \
 	dns_ipq.o dns_mx.o dns_name.o dns_nd.o dns_packet.o \
 	dns_random.o dns_rcip.o dns_rcrw.o dns_resolve.o \
-	dns_sortip.o dns_transmit.o dns_txt.o
+	dns_rotateip.o dns_sortip.o dns_transmit.o dns_txt.o
 
 dns_dfd.o: \
 compile dns_dfd.c error.h alloc.h byte.h dns.h stralloc.h gen_alloc.h \
@@ -300,6 +300,10 @@
 compile dns_resolve.c iopause.h taia.h tai.h uint64.h taia.h byte.h \
 dns.h stralloc.h gen_alloc.h iopause.h taia.h
 	./compile dns_resolve.c
+
+dns_rotateip.o: \
+compile dns_rotateip.c byte.h dns.h stralloc.h gen_alloc.h
+	./compile dns_rotateip.c
 
 dns_sortip.o: \
 compile dns_sortip.c byte.h dns.h stralloc.h gen_alloc.h iopause.h \
diff -uP djbdns-1.05.orig/cache.c djbdns-1.05.modified/cache.c
--- djbdns-1.05.orig/cache.c	Sun Feb 11 16:11:45 2001
+++ djbdns-1.05.modified/cache.c	Sun Jun 10 12:13:30 2001
@@ -4,7 +4,7 @@
 #include "exit.h"
 #include "tai.h"
 #include "cache.h"
-
+#include "dns.h"
 uint64 cache_motion = 0;
 
 static char *x = 0;
@@ -111,7 +111,7 @@
         u = get4(pos + 8);
         if (u > size - pos - 20 - keylen) cache_impossible();
         *datalen = u;
-
+	if byte_equal(key,2,DNS_T_A)   dns_rotateip(x + pos + 20 + keylen,u);
         return x + pos + 20 + keylen;
       }
     }
Only in djbdns-1.05.orig/: djbdns-1.05
diff -uP djbdns-1.05.orig/dns.h djbdns-1.05.modified/dns.h
--- djbdns-1.05.orig/dns.h	Sun Feb 11 16:11:45 2001
+++ djbdns-1.05.modified/dns.h	Sun Jun 10 12:08:39 2001
@@ -43,6 +43,7 @@
 extern unsigned int dns_random(unsigned int);
 
 extern void dns_sortip(char *,unsigned int);
+extern void dns_rotateip(char *,unsigned int);
 
 extern void dns_domain_free(char **);
 extern int dns_domain_copy(char **,const char *);
diff -uP djbdns-1.05.orig/dns_rotateip.c djbdns-1.05.modified/dns_rotateip.c
--- djbdns-1.05.orig/dns_rotateip.c	Wed Dec 31 19:00:00 1969
+++ djbdns-1.05.modified/dns_rotateip.c	Sun Jun 10 12:07:41 2001
@@ -0,0 +1,12 @@
+#include "byte.h"
+
+void dns_rotateip(char *s, unsigned int n)
+{
+  char tmp[4];
+
+  if (n > 4) { 
+    byte_copy(tmp,4,s);
+    byte_copy(s,n-4,s+4);
+    byte_copy(s+n-4,4,tmp);
+  }
+}
