Commit | Line | Data |
---|---|---|
dc0d77d7 CE |
1 | #include "dns.h" |
2 | #include "dd.h" | |
3 | ||
4 | int dd(const char *q,const char *base,char ip[4]) | |
5 | { | |
6 | int j; | |
7 | unsigned int x; | |
8 | ||
9 | for (j = 0;;++j) { | |
10 | if (dns_domain_equal(q,base)) return j; | |
11 | if (j >= 4) return -1; | |
12 | ||
13 | if (*q <= 0) return -1; | |
14 | if (*q >= 4) return -1; | |
15 | if ((q[1] < '0') || (q[1] > '9')) return -1; | |
16 | x = q[1] - '0'; | |
17 | if (*q == 1) { | |
18 | ip[j] = x; | |
19 | q += 2; | |
20 | continue; | |
21 | } | |
22 | if (!x) return -1; | |
23 | if ((q[2] < '0') || (q[2] > '9')) return -1; | |
24 | x = x * 10 + (q[2] - '0'); | |
25 | if (*q == 2) { | |
26 | ip[j] = x; | |
27 | q += 3; | |
28 | continue; | |
29 | } | |
30 | if ((q[3] < '0') || (q[3] > '9')) return -1; | |
31 | x = x * 10 + (q[3] - '0'); | |
32 | if (x > 255) return -1; | |
33 | ip[j] = x; | |
34 | q += 4; | |
35 | } | |
36 | } |