7 /* resource record to printable address
11 /* const char *dns_rr_to_pa(rr, hostaddr)
13 /* MAI_HOSTADDR_STR *hostaddr;
15 /* dns_rr_to_pa() converts the address in a DNS resource record
16 /* into printable form and returns a pointer to the result.
20 /* The DNS resource record.
22 /* Storage for the printable address.
24 /* The result is null in case of problems, with errno set
25 /* to indicate the nature of the problem.
29 /* The Secure Mailer license must be distributed with this software.
32 /* IBM T.J. Watson Research
34 /* Yorktown Heights, NY 10598, USA
37 /* System libraries. */
40 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <arpa/inet.h>
45 /* Utility library. */
53 /* dns_rr_to_pa - resource record to printable address */
55 const char *dns_rr_to_pa(DNS_RR
*rr
, MAI_HOSTADDR_STR
*hostaddr
)
57 if (rr
->type
== T_A
) {
58 return (inet_ntop(AF_INET
, rr
->data
, hostaddr
->buf
,
59 sizeof(hostaddr
->buf
)));
61 } else if (rr
->type
== T_AAAA
) {
62 return (inet_ntop(AF_INET6
, rr
->data
, hostaddr
->buf
,
63 sizeof(hostaddr
->buf
)));
72 * Stand-alone test program.
76 #include <myaddrinfo.h>
78 static const char *myname
;
80 static NORETURN
usage(void)
82 msg_fatal("usage: %s dnsaddrtype hostname", myname
);
85 int main(int argc
, char **argv
)
88 MAI_HOSTADDR_STR hostaddr
;
95 why
= vstring_alloc(1);
100 if ((type
= dns_type(argv
[0])) == 0)
102 if (dns_lookup(argv
[1], type
, 0, &rr
, (VSTRING
*) 0, why
) != DNS_OK
)
103 msg_fatal("%s: %s", argv
[1], vstring_str(why
));
104 if (dns_rr_to_pa(rr
, &hostaddr
) == 0)
105 msg_fatal("dns_rr_to_sa: %m");
106 vstream_printf("%s -> %s\n", argv
[1], hostaddr
.buf
);
107 vstream_fflush(VSTREAM_OUT
);