summaryrefslogtreecommitdiff
path: root/src/dnsstub/dns_sortip.c
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-07-09 13:58:20 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-07-09 13:58:20 +0200
commit249866e3d1e11dc72eaa1305f4bb479ded92ef38 (patch)
tree7118c5f58e29fe61c100e4d067bb90ba8d52589e /src/dnsstub/dns_sortip.c
parent96cf8dffe4f7b0b910f790066ae622dc429eb522 (diff)
reorganized file structure
Moved c files into src/. Corrected VERSION file. Removed BUILD and FILES.
Diffstat (limited to 'src/dnsstub/dns_sortip.c')
-rw-r--r--src/dnsstub/dns_sortip.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/dnsstub/dns_sortip.c b/src/dnsstub/dns_sortip.c
new file mode 100644
index 0000000..56742e0
--- /dev/null
+++ b/src/dnsstub/dns_sortip.c
@@ -0,0 +1,45 @@
+#include "byte.h"
+#include "ip.h"
+#include "dnsresolv.h"
+
+/**
+ @file dns_sortip.c
+ @authors djb, fefe, feh
+ @source ucspi-tcp6
+ @brief random sort of DNS servers per IP
+*/
+
+/* XXX: sort servers by configurable notion of closeness? */
+/* XXX: pay attention to competence of each server? */
+/* XXX: pay attention to qualification (DNSSec, DNSCurve) of each server? */
+/* YYY: we use a randomly sorted list of NS; not depending on answer */
+
+void dns_sortip4(char *s,unsigned int n)
+{
+ unsigned int i;
+ char tmp[4];
+
+ n >>= 2; /* 4 byte per IPv4 address */
+ while (n > 1) {
+ i = dns_random(n);
+ --n;
+ byte_copy(tmp,4,s + (i << 2));
+ byte_copy(s + (i << 2),4,s + (n << 2));
+ byte_copy(s + (n << 2),4,tmp);
+ }
+}
+
+void dns_sortip6(char *s,unsigned int n)
+{
+ unsigned int i;
+ char tmp[16];
+
+ n >>= 4; /* 16 byte per IPv4 address */
+ while (n > 1) {
+ i = dns_random(n);
+ --n;
+ byte_copy(tmp,16,s + (i << 4));
+ byte_copy(s + (i << 4),16,s + (n << 4));
+ byte_copy(s + (n << 4),16,tmp);
+ }
+}