forked from ginhom/dnscrypt-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce hostip(8), a tool for resolving a name before dnscrypt-prox…
…y starts. It should help fighting the chicken-and-egg issue seen on routers, where dnscrypt-proxy requires a working NTP server, but the NTP server requires a working resolver.
- Loading branch information
Showing
16 changed files
with
436 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
man_MANS = \ | ||
dnscrypt-proxy.8 | ||
dnscrypt-proxy.8 \ | ||
hostip.8 | ||
|
||
EXTRA_DIST= \ | ||
dnscrypt-proxy.8 \ | ||
dnscrypt-proxy.8.markdown | ||
dnscrypt-proxy.8.markdown \ | ||
hostip.8 \ | ||
hostip.8.markdown | ||
|
||
dnscrypt-proxy.8: dnscrypt-proxy.8.markdown | ||
@RONN@ dnscrypt-proxy.8.markdown | ||
|
||
hostip.8: hostip.8.markdown | ||
@RONN@ hostip.8.markdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
.\" generated with Ronn/v0.7.3 | ||
.\" http://github.com/rtomayko/ronn/tree/0.7.3 | ||
. | ||
.TH "HOSTIP" "8" "July 2012" "" "" | ||
. | ||
.SH "NAME" | ||
\fBhostip\fR \- Resolve a host name to an IP address | ||
. | ||
.SH "SYNOPSIS" | ||
\fBhostip\fR [\fIoptions\fR] host_name | ||
. | ||
.SH "DESCRIPTION" | ||
\fBhostip\fR sends a DNS query to a resolver, and prints the IP addresses for the given host name\. | ||
. | ||
.P | ||
It can be useful in order to retrieve IP addresses before dnscrypt\-proxy(8) is started\. | ||
. | ||
.SH "OPTIONS" | ||
. | ||
.IP "\(bu" 4 | ||
\fB\-6\fR, \fB\-\-ipv6\fR: ask for AAAA records\. | ||
. | ||
.IP "\(bu" 4 | ||
\fB\-h\fR, \fB\-\-help\fR: show usage\. | ||
. | ||
.IP "\(bu" 4 | ||
\fB\-r\fR, \fB\-\-resolver\-address=<ip>\fR: the resolver IP address (default: 208\.67\.222\.222, OpenDNS)\. | ||
. | ||
.IP "\(bu" 4 | ||
\fB\-V\fR, \fB\-\-version\fR: show version number\. | ||
. | ||
.IP "" 0 | ||
. | ||
.SH "SIMPLE USAGE EXAMPLE" | ||
. | ||
.nf | ||
|
||
$ hostip www\.example\.com | ||
. | ||
.fi | ||
. | ||
.SH "ADVANCED USAGE EXAMPLE" | ||
. | ||
.nf | ||
|
||
$ hostip \-6 \-r 213\.154\.224\.3 www\.google\.com | ||
. | ||
.fi | ||
. | ||
.SH "EXIT STATUS" | ||
The \fBhostip\fR utility exits 0 on success, and > 0 if an error occurs\. | ||
. | ||
.SH "SEE ALSO" | ||
dnscrypt\-proxy(8) | ||
. | ||
.SH "COPYRIGHT" | ||
hostip is Copyright (C) 2012 OpenDNS, Inc\. \fBhttp://www\.opendns\.com/\fR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
hostip(8) -- Resolve a host name to an IP address | ||
================================================= | ||
|
||
## SYNOPSIS | ||
|
||
`hostip` [<options>] host_name | ||
|
||
## DESCRIPTION | ||
|
||
**hostip** sends a DNS query to a resolver, and prints the IP | ||
addresses for the given host name. | ||
|
||
It can be useful in order to retrieve IP addresses before | ||
dnscrypt-proxy(8) is started. | ||
|
||
## OPTIONS | ||
|
||
* `-6`, `--ipv6`: ask for AAAA records. | ||
|
||
* `-h`, `--help`: show usage. | ||
|
||
* `-r`, `--resolver-address=<ip>`: the resolver IP address (default: | ||
208.67.222.222, OpenDNS). | ||
|
||
* `-V`, `--version`: show version number. | ||
|
||
## SIMPLE USAGE EXAMPLE | ||
|
||
$ hostip www.example.com | ||
|
||
## ADVANCED USAGE EXAMPLE | ||
|
||
$ hostip -6 -r 213.154.224.3 www.google.com | ||
|
||
## EXIT STATUS | ||
|
||
The `hostip` utility exits 0 on success, and > 0 if an error occurs. | ||
|
||
## SEE ALSO | ||
|
||
dnscrypt-proxy(8) | ||
|
||
## COPYRIGHT | ||
|
||
hostip is Copyright (C) 2012 OpenDNS, Inc. | ||
`http://www.opendns.com/` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
|
||
SUBDIRS = \ | ||
ext \ | ||
hostip \ | ||
libevent \ | ||
libnacl \ | ||
dnscrypt-proxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
bin_PROGRAMS = \ | ||
hostip | ||
|
||
hostip_SOURCES = \ | ||
app.c \ | ||
app.h \ | ||
options.c \ | ||
options.h | ||
|
||
AM_CFLAGS = @CWFLAGS@ | ||
|
||
AM_CPPFLAGS = \ | ||
-I../libevent/include | ||
|
||
hostip_LDADD = \ | ||
../libevent/libevent_extra.la \ | ||
../libevent/libevent_core.la |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
|
||
#include <config.h> | ||
#include <sys/types.h> | ||
#ifdef _WIN32 | ||
# include <winsock2.h> | ||
#else | ||
# include <sys/socket.h> | ||
# include <netinet/in.h> | ||
# include <arpa/inet.h> | ||
#endif | ||
#include <assert.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include <event2/event.h> | ||
#include <event2/dns.h> | ||
#include <event2/util.h> | ||
|
||
#include "app.h" | ||
#include "options.h" | ||
|
||
static AppContext app_context; | ||
|
||
#ifndef INET6_ADDRSTRLEN | ||
# define INET6_ADDRSTRLEN 46U | ||
#endif | ||
|
||
static void | ||
query_cb_err_print(const int err) | ||
{ | ||
fprintf(stderr, "[%s]\n", evdns_err_to_string(err)); | ||
exit(1); | ||
} | ||
|
||
static void | ||
ipv4_query_cb(int result, char type, int count, int ttl, | ||
void * const ips_, void * const app_context_) | ||
{ | ||
char ip_s_buf[INET6_ADDRSTRLEN + 1U]; | ||
AppContext *app_context = app_context_; | ||
struct in_addr *ips = ips_; | ||
const char *ip_s; | ||
int i = 0; | ||
|
||
(void) ttl; | ||
if (result != DNS_ERR_NONE) { | ||
query_cb_err_print(result); | ||
} | ||
assert(type == DNS_IPv4_A); | ||
assert(count >= 0); | ||
while (i < count) { | ||
ip_s = evutil_inet_ntop(AF_INET, &ips[i], ip_s_buf, sizeof ip_s_buf); | ||
if (ip_s != NULL) { | ||
puts(ip_s); | ||
} | ||
i++; | ||
} | ||
event_base_loopexit(app_context->event_loop, NULL); | ||
} | ||
|
||
static void | ||
ipv6_query_cb(int result, char type, int count, int ttl, | ||
void * const ips_, void * const app_context_) | ||
{ | ||
char ip_s_buf[INET6_ADDRSTRLEN + 1U]; | ||
AppContext *app_context = app_context_; | ||
struct in6_addr *ips = ips_; | ||
const char *ip_s; | ||
int i = 0; | ||
|
||
(void) ttl; | ||
if (result != DNS_ERR_NONE) { | ||
query_cb_err_print(result); | ||
} | ||
assert(type == DNS_IPv6_AAAA); | ||
assert(count >= 0); | ||
while (i < count) { | ||
ip_s = evutil_inet_ntop(AF_INET6, &ips[i], ip_s_buf, sizeof ip_s_buf); | ||
if (ip_s != NULL) { | ||
puts(ip_s); | ||
} | ||
i++; | ||
} | ||
event_base_loopexit(app_context->event_loop, NULL); | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
struct evdns_base *evdns_base; | ||
|
||
if (options_parse(&app_context, argc, argv) != 0) { | ||
return 1; | ||
} | ||
#ifdef _WIN32 | ||
WSADATA wsa_data; | ||
WSAStartup(MAKEWORD(2, 2), &wsa_data); | ||
#endif | ||
if ((app_context.event_loop = event_base_new()) == NULL) { | ||
perror("event_base_new"); | ||
return 1; | ||
} | ||
if ((evdns_base = evdns_base_new(app_context.event_loop, 0)) == NULL) { | ||
perror("evdns_base"); | ||
return 1; | ||
} | ||
if (evdns_base_nameserver_ip_add(evdns_base, | ||
app_context.resolver_ip) != 0) { | ||
fprintf(stderr, "Unable to use [%s] as a resolver\n", | ||
app_context.resolver_ip); | ||
return 1; | ||
} | ||
if (app_context.want_ipv6 != 0) { | ||
evdns_base_resolve_ipv6(evdns_base, app_context.host_name, | ||
DNS_QUERY_NO_SEARCH, | ||
ipv6_query_cb, &app_context); | ||
} else { | ||
evdns_base_resolve_ipv4(evdns_base, app_context.host_name, | ||
DNS_QUERY_NO_SEARCH, | ||
ipv4_query_cb, &app_context); | ||
} | ||
event_base_dispatch(app_context.event_loop); | ||
event_base_free(app_context.event_loop); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.