ref: c5559504cd0b70d18b44c75b20912d4fea1f9511
parent: 96e511d736ca4f18b70312980591014199afeb1a
author: mischief <[email protected]>
date: Fri Jul 13 16:44:57 EDT 2018
ndb/dnsgetip: report errors when dns resolution fails
--- a/sys/src/cmd/ndb/dnsgetip.c
+++ b/sys/src/cmd/ndb/dnsgetip.c
@@ -18,27 +18,49 @@
int traceactivity = 0;
char *zonerefreshprogram;
-int aflag;
+int aflag = 0;
+int addresses = 0;
-void
+char Ebotch[] = "dns botch";
+
+char*
resolve(char *name, int type)
{
+ int status;
+ char *errmsg;
Request req;
- RR *rp;
+ RR *rr, *rp, *neg;
+ status = Rok;
+ errmsg = nil;
+
memset(&req, 0, sizeof req);
getactivity(&req, 0);
req.isslave = 1;
req.aborttime = NS2MS(nowns) + Maxreqtm;
- rp = dnresolve(name, Cin, type, &req, 0, 0, Recurse, 0, 0);
- rrremneg(&rp);
- while(rp != nil){
+ rr = dnresolve(name, Cin, type, &req, 0, 0, Recurse, 0, &status);
+ neg = rrremneg(&rr);
+ if(rr == nil || neg != nil){
+ if(neg != nil)
+ status = neg->negrcode;
+ errmsg = Ebotch;
+ if(status > 0 && status < nrname)
+ errmsg = rname[status];
+ }
+
+ rrfreelist(neg);
+
+ for(rp = rr; rp != nil; rp = rp->next){
print("%s\n", rp->ip->name);
+ addresses++;
if(!aflag)
exits(nil);
- rp = rp->next;
}
+
+ rrfreelist(rr);
+
+ return errmsg;
}
void
@@ -51,6 +73,8 @@
void
main(int argc, char **argv)
{
+ char *e4, *e6;
+
strcpy(mntpt, "/net");
cfg.inside = 1;
cfg.resolver = 1;
@@ -76,8 +100,15 @@
print("%s\n", *argv);
else {
dninit();
- resolve(*argv, Ta);
- resolve(*argv, Taaaa);
+ e4 = resolve(*argv, Ta);
+ e6 = resolve(*argv, Taaaa);
+
+ if(addresses == 0){
+ if(e4 == e6)
+ sysfatal("%s: dns failure: %s", *argv, e4);
+
+ sysfatal("%s: dns failure: v4: %s: v6: %s", *argv, e4, e6);
+ }
}
exits(nil);
}