2 #include "openreadclose.h"
8 static stralloc data
= {0};
10 static int init(char ip
[64])
17 x
= env_get("DNSCACHEIP");
23 i
= ip4_scan(x
,ip
+ iplen
);
31 i
= openreadclose("/etc/resolv.conf",&data
,64);
32 if (i
== -1) return -1;
34 if (!stralloc_append(&data
,"\n")) return -1;
36 for (j
= 0;j
< data
.len
;++j
)
37 if (data
.s
[j
] == '\n') {
38 if (byte_equal("nameserver ",11,data
.s
+ i
) || byte_equal("nameserver\t",11,data
.s
+ i
)) {
40 while ((data
.s
[i
] == ' ') || (data
.s
[i
] == '\t'))
43 if (ip4_scan(data
.s
+ i
,ip
+ iplen
)) {
44 if (byte_equal(ip
+ iplen
,4,"\0\0\0\0"))
45 byte_copy(ip
+ iplen
,4,"\177\0\0\1");
55 byte_copy(ip
,4,"\177\0\0\1");
58 byte_zero(ip
+ iplen
,64 - iplen
);
63 static unsigned int uses
;
64 static struct taia deadline
;
65 static char ip
[64]; /* defined if ok */
67 int dns_resolvconfip(char s
[64])
72 if (taia_less(&deadline
,&now
)) ok
= 0;
76 if (init(ip
) == -1) return -1;
77 taia_uint(&deadline
,600);
78 taia_add(&deadline
,&now
,&deadline
);