djbdnscurve6 45
djbdnscurve6
Loading...
Searching...
No Matches
dns_sortip.c
Go to the documentation of this file.
1#include "byte.h"
2#include "ip.h"
3#include "dns.h"
4
5/* XXX: sort servers by configurable notion of closeness? */
6/* XXX: pay attention to competence of each server? */
7/* XXX: pay attention to qualification (DNSSec, DNSCurve) of each server? */
8/* YYY: we use a randomly sorted list of NS; not depending on answer */
9
10void dns_sortip4(char *s,unsigned int n)
11{
12 unsigned int i;
13 char tmp[4];
14
15 n >>= 2; /* 4 byte per IPv4 address */
16 while (n > 1) {
17 i = dns_random(n);
18 --n;
19 byte_copy(tmp,4,s + (i << 2));
20 byte_copy(s + (i << 2),4,s + (n << 2));
21 byte_copy(s + (n << 2),4,tmp);
22 }
23}
24
25void dns_sortip6(char *s,unsigned int n)
26{
27 unsigned int i;
28 char tmp[16];
29
30 n >>= 4; /* 16 byte per IPv4 address */
31 while (n > 1) {
32 i = dns_random(n);
33 --n;
34 byte_copy(tmp,16,s + (i << 4));
35 byte_copy(s + (i << 4),16,s + (n << 4));
36 byte_copy(s + (n << 4),16,tmp);
37 }
38}
unsigned int dns_random(unsigned int n)
Definition: dns_random.c:56
void dns_sortip4(char *s, unsigned int n)
Definition: dns_sortip.c:10
void dns_sortip6(char *s, unsigned int n)
Definition: dns_sortip.c:25
struct line tmp
Definition: dnsfilter.c:32