From: Ralph Ronnquist Date: Fri, 22 Jul 2022 22:42:40 +0000 (+1000) Subject: diy DNS lookup tool X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=e411c193f38430e0f3eef487c5ef85f99f96bf2c;p=rrq%2Frrqmisc.git diy DNS lookup tool --- diff --git a/dns/dnsq.c b/dns/dnsq.c new file mode 100644 index 0000000..d9c94e5 --- /dev/null +++ b/dns/dnsq.c @@ -0,0 +1,49 @@ +#include +#include + +static char *a2c(char *ap,int af) { + static char data[1000]; + char *dp = data; + int n; + unsigned char *bp = (unsigned char*) ap; + unsigned short *sp = (unsigned short *)ap; + if ( af == AF_INET ) { + for ( n = 0; n < 4; n++ ) { + sprintf( dp, ".%d", bp[n] ); + while ( *(++dp) ); + } + } else { + int pack = 0; + for ( n = 0; n < 8; n++ ) { + if ( pack < 2 && sp[n] == 0 ) { + if ( pack == 0 ) { + *(dp++) = ':'; + pack = 1; + } + } else { + sprintf( dp, ":%x", ntohs( sp[n] ) ); + while ( *(++dp) ); + } + } + } + return data + 1; +} + +static void checkname(char *name,int af) { + struct hostent *hp = gethostbyname2( name, af ); + int i; + if ( hp && hp->h_addr_list ) { + for ( i = 0; hp->h_addr_list[i]; i++ ) { + fprintf( stdout, "%s\n", a2c( hp->h_addr_list[i], af ) ); + } + } +} + +int main(int argc,char *argv[]) { + int i; + for ( i = 1; i < argc; i++ ) { + checkname( argv[i], AF_INET ); + checkname( argv[i], AF_INET6 ); + } + return 0; +}