WvStreams
wvresolverex.cc
1 /*
2 * A WvResolver example.
3 *
4 * Tries to look up two host names given on the command line.
5 * The expected output:
6 * resolver<Err>: 1 not in DNS.
7 * resolver<Err>: 2 not in DNS.
8 * resolver<Err>: 1 not in DNS.
9 * resolver<Err>: 2 not in DNS.
10 * resolver<Err>: 1 not in DNS.
11 * resolver<Err>: 2 not in DNS.
12 *
13 */
14
15#include "wvresolver.h"
16#include "wvlog.h"
17
18void test(WvResolver &dns, int argc, char **argv)
19{
20 WvLog log("resolver", WvLog::Info);
21 const WvIPAddr *addr;
22 int res1, res2;
23
24 res1 = res2 = -1;
25
26 while (res1 < 0 || res2 < 0)
27 {
28 if (res1 < 0)
29 {
30 res1 = dns.findaddr(100, argc > 1 ? argv[1] : "abyss.cnss.ca",
31 &addr);
32 if (res1 > 0)
33 log.print("Found address for 1: %s\n", (WvString)(*addr));
34 else if (res1 < 0)
35 log.print("[1] ");
36 else
37 log(WvLog::Error, "1 not in DNS.\n");
38 }
39
40 if (res2 < 0)
41 {
42 res2 = dns.findaddr(100, argc > 2 ? argv[2] : "frank.foxnet.net",
43 &addr);
44 if (res2 > 0)
45 log.print("Found address for 2: %s\n", (WvString)(*addr));
46 else if (res2 < 0)
47 log.print("[2] ");
48 else
49 log(WvLog::Error, "2 not in DNS.\n");
50 }
51 }
52
53}
54
55int main(int argc, char **argv)
56{
57 {
58 WvResolver dns;
59 test(dns, argc, argv);
60 test(dns, argc, argv);
61 }
62
63 {
64 WvResolver dns;
65 test(dns, argc, argv);
66 }
67
68 return 0;
69}
An IP address is made up of a "dotted quad" – four decimal numbers in the form www....
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
ASynchronous DNS resolver functions, so that we can do non-blocking lookups.
int findaddr(int msec_timeout, WvStringParm name, WvIPAddr const **addr, WvIPAddrList *addrlist=NULL)
Return -1 on timeout, or the number of addresses found, which may be 0 if the address does not exist.
WvString is an implementation of a simple and efficient printable-string class.