13 #ifndef DEFAULT_RESOLVER_IP
14 # define DEFAULT_RESOLVER_IP "208.67.220.220"
17 static struct option getopt_long_options
[] = {
18 { "ipv6", 0, NULL
, '6' },
19 { "help", 0, NULL
, 'h' },
20 { "resolver-address", 1, NULL
, 'r' },
21 { "version", 0, NULL
, 'V' },
24 static const char *getopt_options
= "6hr:V";
29 puts("hostip v" PACKAGE_VERSION
"\n"
30 "Copyright (C) 2012 OpenDNS, Inc.");
36 puts("Usage: hostip [-6] [-r resolver_ip[:port]] host_name\n"
37 " -6, --ipv6: ask for AAAA records\n"
38 " -h, --help: show usage\n"
39 " -r, --resolver-address=<ip>: the resolver IP address (default: OpenDNS)\n"
40 " -V, --version: show version number\n"
42 "Example: hostip -r 208.67.222.222 www.example.com\n");
46 void options_init_with_default(AppContext
* const app_context
)
48 app_context
->host_name
= NULL
;
49 app_context
->resolver_ip
= DEFAULT_RESOLVER_IP
;
50 app_context
->want_ipv6
= 0;
54 options_apply(AppContext
* const app_context
)
56 if (app_context
->resolver_ip
== NULL
) {
64 options_parse(AppContext
* const app_context
, int argc
, char *argv
[])
69 options_init_with_default(app_context
);
70 while ((opt_flag
= getopt_long(argc
, argv
,
71 getopt_options
, getopt_long_options
,
72 &option_index
)) != -1) {
75 app_context
->want_ipv6
= 1;
81 app_context
->resolver_ip
= optarg
;
93 if (argc
!= 1 || *argv
== NULL
) {
97 app_context
->host_name
= *argv
;
98 options_apply(app_context
);