7 /* DNS lookup test program
9 /* test_dns_lookup query-type domain-name
11 /* test_dns_lookup performs a DNS query of the specified resource
12 /* type for the specified resource name.
14 /* Problems are reported to the standard error stream.
18 /* The Secure Mailer license must be distributed with this software.
21 /* IBM T.J. Watson Research
23 /* Yorktown Heights, NY 10598, USA
29 #include <netinet/in.h>
30 #include <arpa/inet.h>
33 /* Utility library. */
37 #include <msg_vstream.h>
41 /* Application-specific. */
45 static void print_rr(DNS_RR
*rr
)
47 MAI_HOSTADDR_STR host
;
50 printf("%s: ttl: %9d ", rr
->rname
, rr
->ttl
);
56 if (dns_rr_to_pa(rr
, &host
) == 0)
57 msg_fatal("conversion error for resource record type %s: %m",
58 dns_strtype(rr
->type
));
59 printf("%s: %s\n", dns_strtype(rr
->type
), host
.buf
);
68 printf("%s: %s\n", dns_strtype(rr
->type
), rr
->data
);
71 printf("pref: %d %s: %s\n",
72 rr
->pref
, dns_strtype(rr
->type
), rr
->data
);
75 msg_fatal("print_rr: don't know how to print type %s",
76 dns_strtype(rr
->type
));
82 int main(int argc
, char **argv
)
87 VSTRING
*fqdn
= vstring_alloc(100);
88 VSTRING
*why
= vstring_alloc(100);
92 msg_vstream_init(argv
[0], VSTREAM_ERR
);
94 msg_fatal("usage: %s types name", argv
[0]);
95 types_argv
= argv_split(argv
[1], ", \t\r\n");
96 types
= (int *) mymalloc(sizeof(*types
) * (types_argv
->argc
+ 1));
97 for (i
= 0; i
< types_argv
->argc
; i
++)
98 if ((types
[i
] = dns_type(types_argv
->argv
[i
])) == 0)
99 msg_fatal("invalid query type: %s", types_argv
->argv
[i
]);
101 argv_free(types_argv
);
104 switch (dns_lookup_v(name
, RES_DEFNAMES
| RES_DEBUG
, &rr
, fqdn
, why
,
105 DNS_REQ_FLAG_NONE
, types
)) {
107 msg_fatal("%s", vstring_str(why
));
109 printf("%s: fqdn: %s\n", name
, vstring_str(fqdn
));
113 myfree((char *) types
);