aboutsummaryrefslogtreecommitdiff
path: root/dnsname.c
blob: ff9166d17cee1fa2ed10c7a3119718493b654b0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "buffer.h"
#include "exit.h"
#include "strerr.h"
#include "ip4.h"
#include "ip6.h"
#include "dns.h"

#define FATAL "dnsname: fatal: "

static char seed[128];

char ip[4];
char ip6[16];
static stralloc out;

int main(int argc,char **argv)
{
  dns_random_init(seed);

  if (*argv) ++argv;

  while (*argv) {
    if (ip6_scan(*argv,ip6)) {
      if (dns_name6(&out,ip6) == -1)
	strerr_die4sys(111,FATAL,"unable to find host name for ",*argv,": ");
    } else {
      if (!ip4_scan(*argv,ip))
	strerr_die3x(111,FATAL,"unable to parse IP address ",*argv);
      if (dns_name4(&out,ip) == -1)
	strerr_die4sys(111,FATAL,"unable to find host name for ",*argv,": ");
    }

    buffer_put(buffer_1,out.s,out.len);
    buffer_puts(buffer_1,"\n");

    ++argv;
  }

  buffer_flush(buffer_1);
  _exit(0);
}