summaryrefslogtreecommitdiff
path: root/dns.c
diff options
context:
space:
mode:
Diffstat (limited to 'dns.c')
-rw-r--r--dns.c96
1 files changed, 15 insertions, 81 deletions
diff --git a/dns.c b/dns.c
index af4ff03..ed42787 100644
--- a/dns.c
+++ b/dns.c
@@ -104,43 +104,6 @@ int wanttype;
return 0;
}
-static int findstring(wanttype)
-int wanttype;
-{
- unsigned short rrtype;
- unsigned short rrdlen;
- int i;
-
- if (numanswers <= 0) return 2;
- --numanswers;
- if (responsepos == responseend) return DNS_SOFT;
-
- i = dn_expand(response.buf,responseend,responsepos,name,MAXDNAME);
- if (i < 0) return DNS_SOFT;
- responsepos += i;
-
- i = responseend - responsepos;
- if (i < 4 + 3 * 2) return DNS_SOFT;
-
- rrtype = getshort(responsepos);
- rrdlen = getshort(responsepos + 8);
- responsepos += 10;
-
- if (rrtype == wanttype)
- {
- i = *responsepos;
- if (i > MAXDNAME - 1) return DNS_SOFT;
- if (responsepos + i > responseend) return DNS_SOFT;
- byte_copy(name, i, responsepos+1);
- name[i] = '\0';
- responsepos += rrdlen;
- return 1;
- }
-
- responsepos += rrdlen;
- return 0;
-}
-
static int findip(wanttype)
int wanttype;
{
@@ -256,10 +219,9 @@ stralloc *sa;
#define FMT_IAA 40
-static int iaafmt(s,ip,dom)
+static int iaafmt(s,ip)
char *s;
struct ip_address *ip;
-const char *dom;
{
unsigned int i;
unsigned int len;
@@ -271,7 +233,7 @@ const char *dom;
i = fmt_ulong(s,(unsigned long) ip->d[1]); len += i; if (s) s += i;
i = fmt_str(s,"."); len += i; if (s) s += i;
i = fmt_ulong(s,(unsigned long) ip->d[0]); len += i; if (s) s += i;
- i = fmt_str(s,dom); len += i; if (s) s += i;
+ i = fmt_str(s,".in-addr.arpa."); len += i; if (s) s += i;
return len;
}
@@ -281,8 +243,8 @@ struct ip_address *ip;
{
int r;
- if (!stralloc_ready(sa,iaafmt((char *) 0,ip,".in-addr.arpa."))) return DNS_MEM;
- sa->len = iaafmt(sa->s,ip,".in-addr.arpa.");
+ if (!stralloc_ready(sa,iaafmt((char *) 0,ip))) return DNS_MEM;
+ sa->len = iaafmt(sa->s,ip);
switch(resolve(sa,T_PTR))
{
case DNS_MEM: return DNS_MEM;
@@ -301,32 +263,6 @@ struct ip_address *ip;
return DNS_HARD;
}
-int dns_maps(sa,ip)
-stralloc *sa;
-struct ip_address *ip;
-{
- int r;
-
- if (!stralloc_ready(sa,iaafmt((char *) 0,ip,".rbl.maps.vix.com."))) return DNS_MEM;
- sa->len = iaafmt(sa->s,ip,".rbl.maps.vix.com.");
- switch(resolve(sa,T_TXT))
- {
- case DNS_MEM: return DNS_MEM;
- case DNS_SOFT: return DNS_SOFT;
- case DNS_HARD: return DNS_HARD;
- }
- while ((r = findstring(T_TXT)) != 2)
- {
- if (r == DNS_SOFT) return DNS_SOFT;
- if (r == 1)
- {
- if (!stralloc_copys(sa,name)) return DNS_MEM;
- return 0;
- }
- }
- return DNS_HARD;
-}
-
static int dns_ipplus(ia,sa,pref)
ipalloc *ia;
stralloc *sa;
@@ -335,17 +271,16 @@ int pref;
int r;
struct ip_mx ix;
- if (sa->len && (sa->s[0] == '['))
- {
- if (!stralloc_copy(&glue,sa)) return DNS_MEM;
- if (!stralloc_0(&glue)) return DNS_MEM;
+ if (!stralloc_copy(&glue,sa)) return DNS_MEM;
+ if (!stralloc_0(&glue)) return DNS_MEM;
+ if (glue.s[0]) {
ix.pref = 0;
- if (!glue.s[ip_scanbracket(glue.s,&ix.ip)])
+ if (!glue.s[ip_scan(glue.s,&ix.ip)] || !glue.s[ip_scanbracket(glue.s,&ix.ip)])
{
if (!ipalloc_append(ia,&ix)) return DNS_MEM;
return 0;
}
- }
+ }
switch(resolve(sa,T_A))
{
@@ -380,6 +315,7 @@ unsigned long random;
{
int r;
struct mx { stralloc sa; unsigned short p; } *mx;
+ struct ip_mx ix;
int nummx;
int i;
int j;
@@ -388,18 +324,16 @@ unsigned long random;
if (!ipalloc_readyplus(ia,0)) return DNS_MEM;
ia->len = 0;
- if (sa->len && (sa->s[0] == '['))
- {
- struct ip_mx ix;
- if (!stralloc_copy(&glue,sa)) return DNS_MEM;
- if (!stralloc_0(&glue)) return DNS_MEM;
+ if (!stralloc_copy(&glue,sa)) return DNS_MEM;
+ if (!stralloc_0(&glue)) return DNS_MEM;
+ if (glue.s[0]) {
ix.pref = 0;
- if (!glue.s[ip_scanbracket(glue.s,&ix.ip)])
+ if (!glue.s[ip_scan(glue.s,&ix.ip)] || !glue.s[ip_scanbracket(glue.s,&ix.ip)])
{
if (!ipalloc_append(ia,&ix)) return DNS_MEM;
return 0;
}
- }
+ }
switch(resolve(sa,T_MX))
{