From 89b7b67a13ebb7965cc7f13ad0595e2194a2d34c Mon Sep 17 00:00:00 2001 From: Jannis Hoffmann Date: Wed, 3 Jul 2024 15:48:04 +0200 Subject: add sqmail-4.2.29a --- src/dnsip.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/dnsip.c (limited to 'src/dnsip.c') diff --git a/src/dnsip.c b/src/dnsip.c new file mode 100644 index 0000000..2c84d04 --- /dev/null +++ b/src/dnsip.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include "buffer.h" +#include "stralloc.h" +#include "dnsresolv.h" +#include "ip.h" +#include "exit.h" +#include "fmt.h" +#include "dns.h" +#include "logmsg.h" + +#define WHO "dnsip" + +stralloc sa = {0}; +stralloc out = {0}; + +int main(int argc, char **argv) +{ + int i; + char ip4str[IP4_FMT]; + char ip6str[IP6_FMT]; + + if (!argv[1]) + logmsg(WHO,100,USAGE,"dnsip fqdn"); + + if (!stralloc_copys(&sa,argv[1])) + logmsg(WHO,111,FATAL,"out of memory"); + + DNS_INIT + if (dns_ip6(&out,&sa) > 0) /* IPv6 first */ + for (i = 0; i + 16 <= out.len; i += 16) { + if (ip6_isv4mapped(out.s + i)) continue; + buffer_put(buffer_1,ip6str,ip6_fmt(ip6str,out.s + i)); + buffer_puts(buffer_1,"\n"); + } + + if (dns_ip4(&out,&sa) > 0) + for (i = 0; i + 4 <= out.len;i += 4) { + buffer_put(buffer_1,ip4str,ip4_fmt(ip4str,out.s + i)); + buffer_puts(buffer_1,"\n"); + } + buffer_putsflush(buffer_1,""); + + _exit(0); +} -- cgit v1.2.3