djbdnscurve6  38
djbdnscurve6
dd.c
Go to the documentation of this file.
1 #include "dns.h"
2 #include "dd.h"
3 #include "ip.h"
4 #include "scan.h"
5 #include "dns.h"
6 
7 int dd4(const char *q,const char *base,char ip[4])
8 {
9  int j;
10  unsigned int x;
11 
12  for (j = 0;; ++j) {
13  if (dns_domain_equal(q,base)) return j;
14  if (j >= 4) return -1;
15 
16  if (*q <= 0) return -1;
17  if (*q >= 4) return -1;
18  if ((q[1] < '0') || (q[1] > '9')) return -1;
19  x = q[1] - '0';
20  if (*q == 1) {
21  ip[j] = x;
22  q += 2;
23  continue;
24  }
25  if (!x) return -1;
26  if ((q[2] < '0') || (q[2] > '9')) return -1;
27  x = x * 10 + (q[2] - '0');
28  if (*q == 2) {
29  ip[j] = x;
30  q += 3;
31  continue;
32  }
33  if ((q[3] < '0') || (q[3] > '9')) return -1;
34  x = x * 10 + (q[3] - '0');
35  if (x > 255) return -1;
36  ip[j] = x;
37  q += 4;
38  }
39 }
40 int dd6(const char *q,const char *base,char ip[16])
41 {
42  int j;
43  int i;
44  unsigned int x;
45 
46  for (j = 0 ;; ++j) {
47  if (dns_domain_equal(q,base)) return j;
48  if (j > 15) return -1;
49 
50  i = scan_xint(q++,&x);
51  if (!i) { --j; continue; }
52  if (x > 15) return -1;
53  ip[j] = x << 4;
54  q += i;
55  i = scan_xint(q++,&x);
56  if (!i) continue;
57  if (x > 15) return -1;
58  ip[j] += x;
59  q += i;
60  if (j == 15) q--; /* last character seen */
61  }
62 }
char ip[16]
Definition: axfrdns.c:126
int dd6(const char *q, const char *base, char ip[16])
Definition: dd.c:40
int dd4(const char *q, const char *base, char ip[4])
Definition: dd.c:7
int dns_domain_equal(const char *, const char *)
Definition: dns_domain.c:39
struct line * x
char * base
Definition: rbldns-conf.c:20