7 /* socket address to resource record
11 /* DNS_RR *dns_sa_to_rr(hostname, pref, sa)
12 /* const char *hostname;
14 /* struct sockaddr *sa;
16 /* dns_sa_to_rr() converts a socket address into a DNS resource record.
20 /* The resource record host name.
22 /* The resource record MX host preference, if applicable.
26 /* The result is a null pointer in case of problems, with the
27 /* errno variable set to indicate the problem type.
31 /* The Secure Mailer license must be distributed with this software.
34 /* IBM T.J. Watson Research
36 /* Yorktown Heights, NY 10598, USA
39 /* System libraries. */
44 /* Utility library. */
52 /* dns_sa_to_rr - socket address to resource record */
54 DNS_RR
*dns_sa_to_rr(const char *hostname
, unsigned pref
, struct sockaddr
* sa
)
58 if (sa
->sa_family
== AF_INET
) {
59 return (dns_rr_create(hostname
, hostname
, T_A
, C_IN
, DUMMY_TTL
, pref
,
60 (char *) &SOCK_ADDR_IN_ADDR(sa
),
61 sizeof(SOCK_ADDR_IN_ADDR(sa
))));
63 } else if (sa
->sa_family
== AF_INET6
) {
64 return (dns_rr_create(hostname
, hostname
, T_AAAA
, C_IN
, DUMMY_TTL
, pref
,
65 (char *) &SOCK_ADDR_IN6_ADDR(sa
),
66 sizeof(SOCK_ADDR_IN6_ADDR(sa
))));
75 * Stand-alone test program.
79 #include <myaddrinfo.h>
80 #include <inet_proto.h>
82 static const char *myname
;
84 static NORETURN
usage(void)
86 msg_fatal("usage: %s hostname", myname
);
89 int main(int argc
, char **argv
)
91 MAI_HOSTADDR_STR hostaddr
;
92 struct addrinfo
*res0
;
101 inet_proto_init(argv
[0], INET_PROTO_NAME_ALL
);
104 if ((aierr
= hostname_to_sockaddr(argv
[0], (char *) 0, 0, &res0
)) != 0)
105 msg_fatal("%s: %s", argv
[0], MAI_STRERROR(aierr
));
106 for (res
= res0
; res
!= 0; res
= res
->ai_next
) {
107 if ((rr
= dns_sa_to_rr(argv
[0], 0, res
->ai_addr
)) == 0)
108 msg_fatal("dns_sa_to_rr: %m");
109 if (dns_rr_to_pa(rr
, &hostaddr
) == 0)
110 msg_fatal("dns_rr_to_pa: %m");
111 vstream_printf("%s -> %s\n", argv
[0], hostaddr
.buf
);
112 vstream_fflush(VSTREAM_OUT
);