diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2017-08-03 19:21:28 +0900 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2017-08-03 19:21:28 +0900 |
commit | 02c92c69ab4193b81ac6f90b52fecb40b94b9208 (patch) | |
tree | 0cbbfc249451abd23b238a811f42015df95bbe2a /src/util | |
parent | b6755fe23d258a4dc971d8fabc3fae1873e31271 (diff) | |
parent | 6bcc73a1cbb1d4a609884762eab1b6de761ad1d9 (diff) | |
download | gnunet-02c92c69ab4193b81ac6f90b52fecb40b94b9208.tar.gz gnunet-02c92c69ab4193b81ac6f90b52fecb40b94b9208.zip |
Merge remote-tracking branch 'origin/master' into identity_abe
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/Makefile.am | 8 | ||||
-rw-r--r-- | src/util/common_logging.c | 21 | ||||
-rw-r--r-- | src/util/resolver_api.c | 85 |
3 files changed, 79 insertions, 35 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 62cf03684..cc9ff4745 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am | |||
@@ -347,10 +347,10 @@ test_client_unix_nc_SOURCES = \ | |||
347 | test_client_unix_nc_LDADD = \ | 347 | test_client_unix_nc_LDADD = \ |
348 | libgnunetutil.la | 348 | libgnunetutil.la |
349 | 349 | ||
350 | test_socks_nc_SOURCES = \ | 350 | #test_socks_nc_SOURCES = \ |
351 | test_socks.c | 351 | # test_socks.c |
352 | test_socks_nc_LDADD = \ | 352 | #test_socks_nc_LDADD = \ |
353 | libgnunetutil.la | 353 | # libgnunetutil.la |
354 | 354 | ||
355 | test_common_allocation_SOURCES = \ | 355 | test_common_allocation_SOURCES = \ |
356 | test_common_allocation.c | 356 | test_common_allocation.c |
diff --git a/src/util/common_logging.c b/src/util/common_logging.c index 34481fe13..3e71fa476 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c | |||
@@ -1156,6 +1156,27 @@ GNUNET_h2s (const struct GNUNET_HashCode * hc) | |||
1156 | 1156 | ||
1157 | 1157 | ||
1158 | /** | 1158 | /** |
1159 | * Convert a hash to a string (for printing debug messages). | ||
1160 | * This is one of the very few calls in the entire API that is | ||
1161 | * NOT reentrant! Identical to #GNUNET_h2s(), except that another | ||
1162 | * buffer is used so both #GNUNET_h2s() and #GNUNET_h2s2() can be | ||
1163 | * used within the same log statement. | ||
1164 | * | ||
1165 | * @param hc the hash code | ||
1166 | * @return string form; will be overwritten by next call to GNUNET_h2s. | ||
1167 | */ | ||
1168 | const char * | ||
1169 | GNUNET_h2s2 (const struct GNUNET_HashCode * hc) | ||
1170 | { | ||
1171 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; | ||
1172 | |||
1173 | GNUNET_CRYPTO_hash_to_enc (hc, &ret); | ||
1174 | ret.encoding[8] = '\0'; | ||
1175 | return (const char *) ret.encoding; | ||
1176 | } | ||
1177 | |||
1178 | |||
1179 | /** | ||
1159 | * @ingroup logging | 1180 | * @ingroup logging |
1160 | * Convert a short hash value to a string (for printing debug messages). | 1181 | * Convert a short hash value to a string (for printing debug messages). |
1161 | * This is one of the very few calls in the entire API that is | 1182 | * This is one of the very few calls in the entire API that is |
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index e7bba3000..33a340729 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c | |||
@@ -179,7 +179,6 @@ static int | |||
179 | check_config () | 179 | check_config () |
180 | { | 180 | { |
181 | char *hostname; | 181 | char *hostname; |
182 | unsigned int i; | ||
183 | struct sockaddr_in v4; | 182 | struct sockaddr_in v4; |
184 | struct sockaddr_in6 v6; | 183 | struct sockaddr_in6 v6; |
185 | 184 | ||
@@ -206,15 +205,16 @@ check_config () | |||
206 | "resolver"); | 205 | "resolver"); |
207 | return GNUNET_SYSERR; | 206 | return GNUNET_SYSERR; |
208 | } | 207 | } |
209 | if ((1 == inet_pton (AF_INET, hostname, &v4)) || | 208 | if ( (1 == inet_pton (AF_INET, hostname, &v4)) || |
210 | (1 == inet_pton (AF_INET6, hostname, &v6))) | 209 | (1 == inet_pton (AF_INET6, hostname, &v6)) ) |
211 | { | 210 | { |
212 | GNUNET_free (hostname); | 211 | GNUNET_free (hostname); |
213 | return GNUNET_OK; | 212 | return GNUNET_OK; |
214 | } | 213 | } |
215 | i = 0; | 214 | for (unsigned int i = 0; |
216 | while (NULL != loopback[i]) | 215 | NULL != loopback[i]; |
217 | if (0 == strcasecmp (loopback[i++], hostname)) | 216 | i++) |
217 | if (0 == strcasecmp (loopback[i], hostname)) | ||
218 | { | 218 | { |
219 | GNUNET_free (hostname); | 219 | GNUNET_free (hostname); |
220 | return GNUNET_OK; | 220 | return GNUNET_OK; |
@@ -297,9 +297,9 @@ shutdown_task (void *cls) | |||
297 | static void | 297 | static void |
298 | check_disconnect () | 298 | check_disconnect () |
299 | { | 299 | { |
300 | struct GNUNET_RESOLVER_RequestHandle *rh; | 300 | for (struct GNUNET_RESOLVER_RequestHandle *rh = req_head; |
301 | 301 | NULL != rh; | |
302 | for (rh = req_head; NULL != rh; rh = rh->next) | 302 | rh = rh->next) |
303 | if (GNUNET_SYSERR != rh->was_transmitted) | 303 | if (GNUNET_SYSERR != rh->was_transmitted) |
304 | return; | 304 | return; |
305 | if (NULL != r_task) | 305 | if (NULL != r_task) |
@@ -336,7 +336,10 @@ no_resolve (int af, | |||
336 | if (ip_len != sizeof (struct in_addr)) | 336 | if (ip_len != sizeof (struct in_addr)) |
337 | return NULL; | 337 | return NULL; |
338 | if (NULL == | 338 | if (NULL == |
339 | inet_ntop (AF_INET, ip, buf, sizeof (buf))) | 339 | inet_ntop (AF_INET, |
340 | ip, | ||
341 | buf, | ||
342 | sizeof (buf))) | ||
340 | { | 343 | { |
341 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, | 344 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, |
342 | "inet_ntop"); | 345 | "inet_ntop"); |
@@ -347,7 +350,10 @@ no_resolve (int af, | |||
347 | if (ip_len != sizeof (struct in6_addr)) | 350 | if (ip_len != sizeof (struct in6_addr)) |
348 | return NULL; | 351 | return NULL; |
349 | if (NULL == | 352 | if (NULL == |
350 | inet_ntop (AF_INET6, ip, buf, sizeof (buf))) | 353 | inet_ntop (AF_INET6, |
354 | ip, | ||
355 | buf, | ||
356 | sizeof (buf))) | ||
351 | { | 357 | { |
352 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, | 358 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, |
353 | "inet_ntop"); | 359 | "inet_ntop"); |
@@ -422,8 +428,8 @@ process_requests () | |||
422 | msg->direction = htonl (rh->direction); | 428 | msg->direction = htonl (rh->direction); |
423 | msg->af = htonl (rh->af); | 429 | msg->af = htonl (rh->af); |
424 | GNUNET_memcpy (&msg[1], | 430 | GNUNET_memcpy (&msg[1], |
425 | &rh[1], | 431 | &rh[1], |
426 | rh->data_len); | 432 | rh->data_len); |
427 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 433 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
428 | "Transmitting DNS resolution request to DNS service\n"); | 434 | "Transmitting DNS resolution request to DNS service\n"); |
429 | GNUNET_MQ_send (mq, | 435 | GNUNET_MQ_send (mq, |
@@ -611,14 +617,19 @@ numeric_resolution (void *cls) | |||
611 | v6.sin6_len = sizeof (v6); | 617 | v6.sin6_len = sizeof (v6); |
612 | #endif | 618 | #endif |
613 | hostname = (const char *) &rh[1]; | 619 | hostname = (const char *) &rh[1]; |
614 | if (((rh->af == AF_UNSPEC) || (rh->af == AF_INET)) && | 620 | if ( ( (rh->af == AF_UNSPEC) || |
615 | (1 == inet_pton (AF_INET, hostname, &v4.sin_addr))) | 621 | (rh->af == AF_INET) ) && |
622 | (1 == inet_pton (AF_INET, | ||
623 | hostname, | ||
624 | &v4.sin_addr)) ) | ||
616 | { | 625 | { |
617 | rh->addr_callback (rh->cls, | 626 | rh->addr_callback (rh->cls, |
618 | (const struct sockaddr *) &v4, | 627 | (const struct sockaddr *) &v4, |
619 | sizeof (v4)); | 628 | sizeof (v4)); |
620 | if ((rh->af == AF_UNSPEC) && | 629 | if ( (rh->af == AF_UNSPEC) && |
621 | (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr))) | 630 | (1 == inet_pton (AF_INET6, |
631 | hostname, | ||
632 | &v6.sin6_addr)) ) | ||
622 | { | 633 | { |
623 | /* this can happen on some systems IF "hostname" is "localhost" */ | 634 | /* this can happen on some systems IF "hostname" is "localhost" */ |
624 | rh->addr_callback (rh->cls, | 635 | rh->addr_callback (rh->cls, |
@@ -872,7 +883,6 @@ GNUNET_RESOLVER_ip_get (const char *hostname, | |||
872 | { | 883 | { |
873 | struct GNUNET_RESOLVER_RequestHandle *rh; | 884 | struct GNUNET_RESOLVER_RequestHandle *rh; |
874 | size_t slen; | 885 | size_t slen; |
875 | unsigned int i; | ||
876 | struct in_addr v4; | 886 | struct in_addr v4; |
877 | struct in6_addr v6; | 887 | struct in6_addr v6; |
878 | 888 | ||
@@ -897,19 +907,26 @@ GNUNET_RESOLVER_ip_get (const char *hostname, | |||
897 | rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 907 | rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
898 | rh->direction = GNUNET_NO; | 908 | rh->direction = GNUNET_NO; |
899 | /* first, check if this is a numeric address */ | 909 | /* first, check if this is a numeric address */ |
900 | if (((1 == inet_pton (AF_INET, hostname, &v4)) && | 910 | if ( ( (1 == inet_pton (AF_INET, |
901 | ((af == AF_INET) || (af == AF_UNSPEC))) || | 911 | hostname, |
902 | ((1 == inet_pton (AF_INET6, hostname, &v6)) && | 912 | &v4)) && |
903 | ((af == AF_INET6) || (af == AF_UNSPEC)))) | 913 | ( (af == AF_INET) || |
914 | (af == AF_UNSPEC) ) ) || | ||
915 | ( (1 == inet_pton (AF_INET6, | ||
916 | hostname, | ||
917 | &v6)) && | ||
918 | ( (af == AF_INET6) || | ||
919 | (af == AF_UNSPEC)) ) ) | ||
904 | { | 920 | { |
905 | rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, | 921 | rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, |
906 | rh); | 922 | rh); |
907 | return rh; | 923 | return rh; |
908 | } | 924 | } |
909 | /* then, check if this is a loopback address */ | 925 | /* then, check if this is a loopback address */ |
910 | i = 0; | 926 | for (unsigned int i = 0; |
911 | while (NULL != loopback[i]) | 927 | NULL != loopback[i]; |
912 | if (0 == strcasecmp (loopback[i++], | 928 | i++) |
929 | if (0 == strcasecmp (loopback[i], | ||
913 | hostname)) | 930 | hostname)) |
914 | { | 931 | { |
915 | rh->task = GNUNET_SCHEDULER_add_now (&loopback_resolution, | 932 | rh->task = GNUNET_SCHEDULER_add_now (&loopback_resolution, |
@@ -1029,8 +1046,8 @@ GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, | |||
1029 | rh->af = sa->sa_family; | 1046 | rh->af = sa->sa_family; |
1030 | rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1047 | rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1031 | GNUNET_memcpy (&rh[1], | 1048 | GNUNET_memcpy (&rh[1], |
1032 | ip, | 1049 | ip, |
1033 | ip_len); | 1050 | ip_len); |
1034 | rh->data_len = ip_len; | 1051 | rh->data_len = ip_len; |
1035 | rh->direction = GNUNET_YES; | 1052 | rh->direction = GNUNET_YES; |
1036 | rh->received_response = GNUNET_NO; | 1053 | rh->received_response = GNUNET_NO; |
@@ -1067,7 +1084,8 @@ GNUNET_RESOLVER_local_fqdn_get () | |||
1067 | { | 1084 | { |
1068 | char hostname[GNUNET_OS_get_hostname_max_length () + 1]; | 1085 | char hostname[GNUNET_OS_get_hostname_max_length () + 1]; |
1069 | 1086 | ||
1070 | if (0 != gethostname (hostname, sizeof (hostname) - 1)) | 1087 | if (0 != gethostname (hostname, |
1088 | sizeof (hostname) - 1)) | ||
1071 | { | 1089 | { |
1072 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1090 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1073 | "gethostname"); | 1091 | "gethostname"); |
@@ -1082,7 +1100,10 @@ GNUNET_RESOLVER_local_fqdn_get () | |||
1082 | int ret; | 1100 | int ret; |
1083 | char *rval; | 1101 | char *rval; |
1084 | 1102 | ||
1085 | if (0 != (ret = getaddrinfo (hostname, NULL, NULL, &ai))) | 1103 | if (0 != (ret = getaddrinfo (hostname, |
1104 | NULL, | ||
1105 | NULL, | ||
1106 | &ai))) | ||
1086 | { | 1107 | { |
1087 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1108 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1088 | _("Could not resolve our FQDN: %s\n"), | 1109 | _("Could not resolve our FQDN: %s\n"), |
@@ -1100,9 +1121,11 @@ GNUNET_RESOLVER_local_fqdn_get () | |||
1100 | { | 1121 | { |
1101 | struct hostent *host; | 1122 | struct hostent *host; |
1102 | 1123 | ||
1103 | host = gethostbyname2 (hostname, AF_INET); | 1124 | host = gethostbyname2 (hostname, |
1125 | AF_INET); | ||
1104 | if (NULL == host) | 1126 | if (NULL == host) |
1105 | host = gethostbyname2 (hostname, AF_INET6); | 1127 | host = gethostbyname2 (hostname, |
1128 | AF_INET6); | ||
1106 | if (NULL == host) | 1129 | if (NULL == host) |
1107 | { | 1130 | { |
1108 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1131 | LOG (GNUNET_ERROR_TYPE_ERROR, |