diff options
-rw-r--r-- | src/util/resolver_api.c | 32 | ||||
-rw-r--r-- | src/util/test_resolver_api.c | 46 |
2 files changed, 78 insertions, 0 deletions
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index f4844a490..6d874cce8 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c | |||
@@ -693,6 +693,38 @@ GNUNET_RESOLVER_local_hostname_get ( ) | |||
693 | } | 693 | } |
694 | 694 | ||
695 | /** | 695 | /** |
696 | * Get local fully qualified domain name | ||
697 | * @return fqdn | ||
698 | */ | ||
699 | char * | ||
700 | GNUNET_RESOLVER_local_fqdn_get ( void ) | ||
701 | { | ||
702 | struct hostent *host; | ||
703 | char hostname[GNUNET_OS_get_hostname_max_length() + 1]; | ||
704 | |||
705 | |||
706 | if (0 != gethostname (hostname, sizeof (hostname) - 1)) | ||
707 | { | ||
708 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | | ||
709 | GNUNET_ERROR_TYPE_BULK, "gethostname"); | ||
710 | return NULL; | ||
711 | } | ||
712 | #if DEBUG_RESOLVER | ||
713 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
714 | _("Resolving our FQDN `%s'\n"), hostname); | ||
715 | #endif | ||
716 | host = gethostbyname ( hostname ); | ||
717 | if ( NULL == host) | ||
718 | { | ||
719 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
720 | _("Could not resolve our FQDN : %s\n"), | ||
721 | hstrerror (h_errno)); | ||
722 | return NULL; | ||
723 | } | ||
724 | return GNUNET_strdup (host->h_name); | ||
725 | } | ||
726 | |||
727 | /** | ||
696 | * Looking our own hostname. | 728 | * Looking our own hostname. |
697 | * | 729 | * |
698 | * @param sched scheduler to use | 730 | * @param sched scheduler to use |
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c index af8ecdeec..d0831bf49 100644 --- a/src/util/test_resolver_api.c +++ b/src/util/test_resolver_api.c | |||
@@ -128,6 +128,44 @@ check_127(void *cls, const struct sockaddr *sa, socklen_t salen) | |||
128 | } | 128 | } |
129 | 129 | ||
130 | static void | 130 | static void |
131 | check_local_fqdn(void *cls, const char *gnunet_fqdn) | ||
132 | { | ||
133 | int result = 0; | ||
134 | |||
135 | struct hostent *host; | ||
136 | char hostname[GNUNET_OS_get_hostname_max_length() + 1]; | ||
137 | |||
138 | if (0 != gethostname (hostname, sizeof (hostname) - 1)) | ||
139 | { | ||
140 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | | ||
141 | GNUNET_ERROR_TYPE_BULK, "gethostname"); | ||
142 | return NULL; | ||
143 | } | ||
144 | #if DEBUG_RESOLVER | ||
145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
146 | _("Resolving our FQDN `%s'\n"), hostname); | ||
147 | #endif | ||
148 | host = gethostbyname ( hostname ); | ||
149 | if ( NULL == host) | ||
150 | { | ||
151 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
152 | _("Could not resolve our FQDN : %s %u\n"), | ||
153 | hstrerror (h_errno), h_errno); | ||
154 | return NULL; | ||
155 | } | ||
156 | |||
157 | GNUNET_assert( 0 != host); | ||
158 | |||
159 | result = strcmp(host->h_name, gnunet_fqdn); | ||
160 | if ( 0 != result ) | ||
161 | { | ||
162 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
163 | "Local resolved and resolver resolved fqdns are not equal\n"); | ||
164 | } | ||
165 | GNUNET_assert( 0 == result); | ||
166 | } | ||
167 | |||
168 | static void | ||
131 | check_local_hostname(void *cls, const char *hostname) | 169 | check_local_hostname(void *cls, const char *hostname) |
132 | { | 170 | { |
133 | int result = 0; | 171 | int result = 0; |
@@ -219,6 +257,7 @@ run(void *cls, struct GNUNET_SCHEDULER_Handle *sched, char * const *args, | |||
219 | GNUNET_TIME_UNIT_MILLISECONDS, 2500); | 257 | GNUNET_TIME_UNIT_MILLISECONDS, 2500); |
220 | int count_ips = 0; | 258 | int count_ips = 0; |
221 | char * own_hostname; | 259 | char * own_hostname; |
260 | char * own_fqdn; | ||
222 | 261 | ||
223 | memset(&sa, 0, sizeof(sa)); | 262 | memset(&sa, 0, sizeof(sa)); |
224 | sa.sin_family = AF_INET; | 263 | sa.sin_family = AF_INET; |
@@ -240,6 +279,13 @@ run(void *cls, struct GNUNET_SCHEDULER_Handle *sched, char * const *args, | |||
240 | GNUNET_free (own_hostname); | 279 | GNUNET_free (own_hostname); |
241 | 280 | ||
242 | /* | 281 | /* |
282 | * Looking up our own fqdn | ||
283 | */ | ||
284 | own_fqdn = GNUNET_RESOLVER_local_fqdn_get(); | ||
285 | check_local_fqdn( NULL, own_fqdn); | ||
286 | GNUNET_free_non_null (own_fqdn); | ||
287 | |||
288 | /* | ||
243 | * Testing non-local DNS resolution | 289 | * Testing non-local DNS resolution |
244 | * DNS rootserver to test: a.root-servers.net - 198.41.0.4 | 290 | * DNS rootserver to test: a.root-servers.net - 198.41.0.4 |
245 | */ | 291 | */ |