From: Willem Toorop Date: Thu, 11 Jul 2019 14:48:57 +0000 (+0200) Subject: -I option for ldns-notify X-Git-Tag: release-1.7.1-rc1~11^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a6563a255440ffc94715c25eff3746151d361982;p=thirdparty%2Fldns.git -I option for ldns-notify from bugzilla #3394 --- diff --git a/examples/ldns-notify.1 b/examples/ldns-notify.1 index 27266c1c..04354d81 100644 --- a/examples/ldns-notify.1 +++ b/examples/ldns-notify.1 @@ -19,6 +19,10 @@ If a server already has that serial number it will disregard the message. \fB-z zone\fR The zone that is updated. +.TP +\fB-I address\fR +Source IP to send query from. + .TP \fB-h\fR Show usage and exit diff --git a/examples/ldns-notify.c b/examples/ldns-notify.c index f98931b0..2cbc2233 100644 --- a/examples/ldns-notify.c +++ b/examples/ldns-notify.c @@ -28,6 +28,7 @@ usage(void) fprintf(stderr, "Ldns notify utility\n\n"); fprintf(stderr, " Supported options:\n"); fprintf(stderr, "\t-z zone\t\tThe zone\n"); + fprintf(stderr, "\t-I
\tsource address to query from\n"); fprintf(stderr, "\t-s version\tSOA version number to include\n"); fprintf(stderr, "\t-y \tspecify named base64 tsig key" ", and optional an\n\t\t\t" @@ -173,7 +174,6 @@ main(int argc, char **argv) /* LDNS types */ ldns_pkt *notify; ldns_rr *question; - ldns_resolver *res; ldns_rdf *ldns_zone_name = NULL; ldns_status status; const char *zone_name = NULL; @@ -185,10 +185,12 @@ main(int argc, char **argv) const char *port = "53"; char *tsig_sep; const char *tsig_name = NULL, *tsig_data = NULL, *tsig_algo = NULL; + int error; + struct addrinfo from_hints, *from0 = NULL; srandom(time(NULL) ^ getpid()); - while ((c = getopt(argc, argv, "vhdp:r:s:y:z:")) != -1) { + while ((c = getopt(argc, argv, "vhdp:r:s:y:z:I:")) != -1) { switch (c) { case 'd': verbose++; @@ -260,6 +262,19 @@ main(int argc, char **argv) exit(1); } break; + case 'I': + memset(&from_hints, 0, sizeof(from_hints)); + from_hints.ai_family = AF_UNSPEC; + from_hints.ai_socktype = SOCK_DGRAM; + from_hints.ai_protocol = IPPROTO_UDP; + from_hints.ai_flags = AI_NUMERICHOST; + error = getaddrinfo(optarg, 0, &from_hints, &from0); + if (error) { + printf("bad address: %s: %s\n", optarg, + gai_strerror(error)); + exit(EXIT_FAILURE); + } + break; case 'v': version(); /* fallthrough */ @@ -278,9 +293,8 @@ main(int argc, char **argv) notify = ldns_pkt_new(); question = ldns_rr_new(); - res = ldns_resolver_new(); - if (!notify || !question || !res) { + if (!notify || !question) { /* bail out */ printf("error: cannot create ldns types\n"); exit(1); @@ -345,14 +359,13 @@ main(int argc, char **argv) for(i=0; iai_next) { - int s = socket(ai_res->ai_family, ai_res->ai_socktype, + int s; + + if (from0 && ai_res->ai_family != from0->ai_family) + continue; + + s = socket(ai_res->ai_family, ai_res->ai_socktype, ai_res->ai_protocol); if(s == -1) continue; + if (from0 && bind(s, from0->ai_addr, from0->ai_addrlen)) { + perror("Could not bind to source IP"); + exit(EXIT_FAILURE); + } /* send the notify */ notify_host(s, ai_res, wire, wiresize, argv[i]); }