aboutsummaryrefslogtreecommitdiff
path: root/src/util/gnunet-service-resolver.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/gnunet-service-resolver.c')
-rw-r--r--src/util/gnunet-service-resolver.c392
1 files changed, 182 insertions, 210 deletions
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c
index d85885d64..0df213588 100644
--- a/src/util/gnunet-service-resolver.c
+++ b/src/util/gnunet-service-resolver.c
@@ -773,6 +773,41 @@ pack (const char *hostname,
773 return GNUNET_OK; 773 return GNUNET_OK;
774} 774}
775 775
776static void
777cache_answers(const char* name,
778 struct GNUNET_DNSPARSER_Record *records,
779 unsigned int num_records)
780{
781 struct ResolveCache *rc;
782 struct GNUNET_DNSPARSER_Record *record;
783 struct RecordListEntry *rle;
784
785 for (unsigned int i = 0; i != num_records; i++)
786 {
787 record = &records[i];
788
789 for (rc = cache_head; NULL != rc; rc = rc->next)
790 if (0 == strcasecmp (rc->hostname,
791 name))
792 break;
793 if (NULL == rc)
794 {
795 rc = GNUNET_new (struct ResolveCache);
796 rc->hostname = GNUNET_strdup (name);
797 GNUNET_CONTAINER_DLL_insert (cache_head,
798 cache_tail,
799 rc);
800 cache_size++;
801 }
802 /* TODO: ought to check first if we have this exact record
803 already in the cache! */
804 rle = GNUNET_new (struct RecordListEntry);
805 rle->record = GNUNET_DNSPARSER_duplicate_record (record);
806 GNUNET_CONTAINER_DLL_insert (rc->records_head,
807 rc->records_tail,
808 rle);
809 }
810}
776 811
777/** 812/**
778 * We got a result from DNS. Add it to the cache and 813 * We got a result from DNS. Add it to the cache and
@@ -784,39 +819,47 @@ pack (const char *hostname,
784 */ 819 */
785static void 820static void
786handle_resolve_result (void *cls, 821handle_resolve_result (void *cls,
787 const struct GNUNET_TUN_DnsHeader *dns, 822 const struct GNUNET_TUN_DnsHeader *dns,
788 size_t dns_len) 823 size_t dns_len)
789{ 824{
790 struct ActiveLookup *al = cls; 825 struct ActiveLookup *al = cls;
791 struct GNUNET_DNSPARSER_Packet *parsed; 826 struct GNUNET_DNSPARSER_Packet *parsed;
792 struct ResolveCache *rc;
793 827
794 parsed = GNUNET_DNSPARSER_parse ((const char *)dns, 828 parsed = GNUNET_DNSPARSER_parse ((const char *)dns,
795 dns_len); 829 dns_len);
796 if (NULL == parsed) 830 if (NULL == parsed)
797 { 831 {
798 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 832 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
799 "Failed to parse DNS reply (hostname %s, request ID %u)\n", 833 "Failed to parse DNS reply (hostname %s, request ID %u)\n",
800 al->hostname, 834 al->hostname,
801 al->dns_id); 835 al->dns_id);
802 return; 836 return;
803 } 837 }
804 if (al->dns_id != ntohs (parsed->id)) 838 if (al->dns_id != ntohs (parsed->id))
805 { 839 {
806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
807 "Request ID in DNS reply does not match\n"); 841 "Request ID in DNS reply does not match\n");
808 GNUNET_DNSPARSER_free_packet (parsed); 842 GNUNET_DNSPARSER_free_packet (parsed);
809 return; 843 return;
810 } 844 }
811 if (0 == parsed->num_answers + parsed->num_authority_records + parsed->num_additional_records) 845 if (0 == parsed->num_answers + parsed->num_authority_records + parsed->num_additional_records)
812 { 846 {
813 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 847 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
814 "DNS reply (hostname %s, request ID %u) contains no answers\n", 848 "DNS reply (hostname %s, request ID %u) contains no answers\n",
815 al->hostname, 849 al->hostname,
816 (unsigned int) al->client_request_id); 850 (unsigned int) al->client_request_id);
851 /* resume by trying again from cache */
852 if (GNUNET_NO ==
853 try_cache (al->hostname,
854 al->record_type,
855 al->client_request_id,
856 al->client))
857 /* cache failed, tell client we could not get an answer */
858 {
859 send_end_msg (al->client_request_id,
860 al->client);
861 }
817 GNUNET_DNSPARSER_free_packet (parsed); 862 GNUNET_DNSPARSER_free_packet (parsed);
818 send_end_msg (al->client_request_id,
819 al->client);
820 free_active_lookup (al); 863 free_active_lookup (al);
821 return; 864 return;
822 } 865 }
@@ -829,84 +872,13 @@ handle_resolve_result (void *cls,
829 al->hostname, 872 al->hostname,
830 (unsigned int) al->client_request_id); 873 (unsigned int) al->client_request_id);
831 /* add to cache */ 874 /* add to cache */
832 for (unsigned int i = 0; i != parsed->num_answers; i++) 875 cache_answers(al->hostname,
833 { 876 parsed->answers, parsed->num_answers);
834 struct GNUNET_DNSPARSER_Record *record = &parsed->answers[i]; 877 cache_answers(al->hostname,
835 struct RecordListEntry *rle; 878 parsed->authority_records, parsed->num_authority_records);
836 879 cache_answers(al->hostname,
837 for (rc = cache_head; NULL != rc; rc = rc->next) 880 parsed->additional_records, parsed->num_additional_records);
838 if (0 == strcasecmp (rc->hostname,
839 record->name))
840 break;
841 if (NULL == rc)
842 {
843 rc = GNUNET_new (struct ResolveCache);
844 rc->hostname = GNUNET_strdup (record->name);
845 GNUNET_CONTAINER_DLL_insert (cache_head,
846 cache_tail,
847 rc);
848 cache_size++;
849 }
850 /* TODO: ought to check first if we have this exact record
851 already in the cache! */
852 rle = GNUNET_new (struct RecordListEntry);
853 rle->record = GNUNET_DNSPARSER_duplicate_record (record);
854 GNUNET_CONTAINER_DLL_insert (rc->records_head,
855 rc->records_tail,
856 rle);
857 }
858 for (unsigned int i = 0; i != parsed->num_authority_records; i++)
859 {
860 struct GNUNET_DNSPARSER_Record *record = &parsed->authority_records[i];
861 struct RecordListEntry *rle;
862
863 for (rc = cache_head; NULL != rc; rc = rc->next)
864 if (0 == strcasecmp (rc->hostname,
865 record->name))
866 break;
867 if (NULL == rc)
868 {
869 rc = GNUNET_new (struct ResolveCache);
870 rc->hostname = GNUNET_strdup (record->name);
871 GNUNET_CONTAINER_DLL_insert (cache_head,
872 cache_tail,
873 rc);
874 cache_size++;
875 }
876 /* TODO: ought to check first if we have this exact record
877 already in the cache! */
878 rle = GNUNET_new (struct RecordListEntry);
879 rle->record = GNUNET_DNSPARSER_duplicate_record (record);
880 GNUNET_CONTAINER_DLL_insert (rc->records_head,
881 rc->records_tail,
882 rle);
883 }
884 for (unsigned int i = 0; i != parsed->num_additional_records; i++)
885 {
886 struct GNUNET_DNSPARSER_Record *record = &parsed->additional_records[i];
887 struct RecordListEntry *rle;
888 881
889 for (rc = cache_head; NULL != rc; rc = rc->next)
890 if (0 == strcasecmp (rc->hostname,
891 record->name))
892 break;
893 if (NULL == rc)
894 {
895 rc = GNUNET_new (struct ResolveCache);
896 rc->hostname = GNUNET_strdup (record->name);
897 GNUNET_CONTAINER_DLL_insert (cache_head,
898 cache_tail,
899 rc);
900 cache_size++;
901 }
902 /* TODO: ought to check first if we have this exact record
903 already in the cache! */
904 rle = GNUNET_new (struct RecordListEntry);
905 rle->record = GNUNET_DNSPARSER_duplicate_record (record);
906 GNUNET_CONTAINER_DLL_insert (rc->records_head,
907 rc->records_tail,
908 rle);
909 }
910 /* see if we need to do the 2nd request for AAAA records */ 882 /* see if we need to do the 2nd request for AAAA records */
911 if ( (GNUNET_DNSPARSER_TYPE_ALL == al->record_type) && 883 if ( (GNUNET_DNSPARSER_TYPE_ALL == al->record_type) &&
912 (GNUNET_NO == al->did_aaaa) ) 884 (GNUNET_NO == al->did_aaaa) )
@@ -968,7 +940,7 @@ handle_resolve_timeout (void *cls)
968 940
969 al->timeout_task = NULL; 941 al->timeout_task = NULL;
970 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 942 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
971 "DNS lookup timeout!\n"); 943 "DNS lookup timeout!\n");
972 send_end_msg (al->client_request_id, 944 send_end_msg (al->client_request_id,
973 al->client); 945 al->client);
974 free_active_lookup (al); 946 free_active_lookup (al);
@@ -987,9 +959,9 @@ handle_resolve_timeout (void *cls)
987 */ 959 */
988static int 960static int
989resolve_and_cache (const char* hostname, 961resolve_and_cache (const char* hostname,
990 uint16_t record_type, 962 uint16_t record_type,
991 uint32_t client_request_id, 963 uint32_t client_request_id,
992 struct GNUNET_SERVICE_Client *client) 964 struct GNUNET_SERVICE_Client *client)
993{ 965{
994 char *packet_buf; 966 char *packet_buf;
995 size_t packet_size; 967 size_t packet_size;
@@ -998,8 +970,8 @@ resolve_and_cache (const char* hostname,
998 uint16_t type; 970 uint16_t type;
999 971
1000 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 972 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1001 "resolve_and_cache `%s'\n", 973 "resolve_and_cache `%s'\n",
1002 hostname); 974 hostname);
1003 dns_id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 975 dns_id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
1004 UINT16_MAX); 976 UINT16_MAX);
1005 977
@@ -1015,7 +987,7 @@ resolve_and_cache (const char* hostname,
1015 &packet_size)) 987 &packet_size))
1016 { 988 {
1017 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 989 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1018 "Failed to pack query for hostname `%s'\n", 990 "Failed to pack query for hostname `%s'\n",
1019 hostname); 991 hostname);
1020 return GNUNET_SYSERR; 992 return GNUNET_SYSERR;
1021 } 993 }
@@ -1031,19 +1003,19 @@ resolve_and_cache (const char* hostname,
1031 al); 1003 al);
1032 al->resolve_handle = 1004 al->resolve_handle =
1033 GNUNET_DNSSTUB_resolve (dnsstub_ctx, 1005 GNUNET_DNSSTUB_resolve (dnsstub_ctx,
1034 packet_buf, 1006 packet_buf,
1035 packet_size, 1007 packet_size,
1036 &handle_resolve_result, 1008 &handle_resolve_result,
1037 al); 1009 al);
1038 GNUNET_free (packet_buf); 1010 GNUNET_free (packet_buf);
1039 GNUNET_CONTAINER_DLL_insert (lookup_head, 1011 GNUNET_CONTAINER_DLL_insert (lookup_head,
1040 lookup_tail, 1012 lookup_tail,
1041 al); 1013 al);
1042 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1014 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1043 "Resolving %s, client_request_id = %u, dns_id = %u\n", 1015 "Resolving %s, client_request_id = %u, dns_id = %u\n",
1044 hostname, 1016 hostname,
1045 (unsigned int) client_request_id, 1017 (unsigned int) client_request_id,
1046 (unsigned int) dns_id); 1018 (unsigned int) dns_id);
1047 return GNUNET_OK; 1019 return GNUNET_OK;
1048} 1020}
1049 1021
@@ -1059,29 +1031,29 @@ resolve_and_cache (const char* hostname,
1059 */ 1031 */
1060static void 1032static void
1061process_get (const char *hostname, 1033process_get (const char *hostname,
1062 uint16_t record_type, 1034 uint16_t record_type,
1063 uint32_t client_request_id, 1035 uint32_t client_request_id,
1064 struct GNUNET_SERVICE_Client *client) 1036 struct GNUNET_SERVICE_Client *client)
1065{ 1037{
1066 char fqdn[255]; 1038 char fqdn[255];
1067 1039
1068 if ( (NULL != my_domain) && 1040 if ( (NULL != my_domain) &&
1069 (NULL == strchr (hostname, 1041 (NULL == strchr (hostname,
1070 (unsigned char) '.')) && 1042 (unsigned char) '.')) &&
1071 (strlen (hostname) + strlen (my_domain) <= 253) ) 1043 (strlen (hostname) + strlen (my_domain) <= 253) )
1072 { 1044 {
1073 GNUNET_snprintf (fqdn, 1045 GNUNET_snprintf (fqdn,
1074 sizeof (fqdn), 1046 sizeof (fqdn),
1075 "%s.%s", 1047 "%s.%s",
1076 hostname, 1048 hostname,
1077 my_domain); 1049 my_domain);
1078 } 1050 }
1079 else if (strlen (hostname) < 255) 1051 else if (strlen (hostname) < 255)
1080 { 1052 {
1081 GNUNET_snprintf (fqdn, 1053 GNUNET_snprintf (fqdn,
1082 sizeof (fqdn), 1054 sizeof (fqdn),
1083 "%s", 1055 "%s",
1084 hostname); 1056 hostname);
1085 } 1057 }
1086 else 1058 else
1087 { 1059 {
@@ -1117,7 +1089,7 @@ process_get (const char *hostname,
1117 */ 1089 */
1118static int 1090static int
1119check_get (void *cls, 1091check_get (void *cls,
1120 const struct GNUNET_RESOLVER_GetMessage *get) 1092 const struct GNUNET_RESOLVER_GetMessage *get)
1121{ 1093{
1122 uint16_t size; 1094 uint16_t size;
1123 int direction; 1095 int direction;
@@ -1134,23 +1106,23 @@ check_get (void *cls,
1134 af = ntohl (get->af); 1106 af = ntohl (get->af);
1135 switch (af) 1107 switch (af)
1136 { 1108 {
1137 case AF_INET: 1109 case AF_INET:
1138 if (size != sizeof (struct in_addr)) 1110 if (size != sizeof (struct in_addr))
1139 { 1111 {
1140 GNUNET_break (0); 1112 GNUNET_break (0);
1141 return GNUNET_SYSERR; 1113 return GNUNET_SYSERR;
1142 } 1114 }
1143 break; 1115 break;
1144 case AF_INET6: 1116 case AF_INET6:
1145 if (size != sizeof (struct in6_addr)) 1117 if (size != sizeof (struct in6_addr))
1146 { 1118 {
1119 GNUNET_break (0);
1120 return GNUNET_SYSERR;
1121 }
1122 break;
1123 default:
1147 GNUNET_break (0); 1124 GNUNET_break (0);
1148 return GNUNET_SYSERR; 1125 return GNUNET_SYSERR;
1149 }
1150 break;
1151 default:
1152 GNUNET_break (0);
1153 return GNUNET_SYSERR;
1154 } 1126 }
1155 return GNUNET_OK; 1127 return GNUNET_OK;
1156} 1128}
@@ -1164,7 +1136,7 @@ check_get (void *cls,
1164 */ 1136 */
1165static void 1137static void
1166handle_get (void *cls, 1138handle_get (void *cls,
1167 const struct GNUNET_RESOLVER_GetMessage *msg) 1139 const struct GNUNET_RESOLVER_GetMessage *msg)
1168{ 1140{
1169 struct GNUNET_SERVICE_Client *client = cls; 1141 struct GNUNET_SERVICE_Client *client = cls;
1170 int direction; 1142 int direction;
@@ -1183,36 +1155,36 @@ handle_get (void *cls,
1183 switch (af) 1155 switch (af)
1184 { 1156 {
1185 case AF_UNSPEC: 1157 case AF_UNSPEC:
1186 { 1158 {
1187 process_get (hostname, 1159 process_get (hostname,
1188 GNUNET_DNSPARSER_TYPE_ALL, 1160 GNUNET_DNSPARSER_TYPE_ALL,
1189 client_request_id, 1161 client_request_id,
1190 client); 1162 client);
1191 break; 1163 break;
1192 } 1164 }
1193 case AF_INET: 1165 case AF_INET:
1194 { 1166 {
1195 process_get (hostname, 1167 process_get (hostname,
1196 GNUNET_DNSPARSER_TYPE_A, 1168 GNUNET_DNSPARSER_TYPE_A,
1197 client_request_id, 1169 client_request_id,
1198 client); 1170 client);
1199 break; 1171 break;
1200 } 1172 }
1201 case AF_INET6: 1173 case AF_INET6:
1202 { 1174 {
1203 process_get (hostname, 1175 process_get (hostname,
1204 GNUNET_DNSPARSER_TYPE_AAAA, 1176 GNUNET_DNSPARSER_TYPE_AAAA,
1205 client_request_id, 1177 client_request_id,
1206 client); 1178 client);
1207 break; 1179 break;
1208 } 1180 }
1209 default: 1181 default:
1210 { 1182 {
1211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1212 "got invalid af: %d\n", 1184 "got invalid af: %d\n",
1213 af); 1185 af);
1214 GNUNET_assert (0); 1186 GNUNET_assert (0);
1215 } 1187 }
1216 } 1188 }
1217 } 1189 }
1218 else 1190 else
@@ -1246,7 +1218,7 @@ shutdown_task (void *cls)
1246 while (NULL != hosts_head) 1218 while (NULL != hosts_head)
1247 free_hosts_entry (hosts_head); 1219 free_hosts_entry (hosts_head);
1248 GNUNET_DNSSTUB_stop (dnsstub_ctx); 1220 GNUNET_DNSSTUB_stop (dnsstub_ctx);
1249 GNUNET_free (my_domain); 1221 GNUNET_free_non_null (my_domain);
1250} 1222}
1251 1223
1252 1224
@@ -1261,9 +1233,9 @@ shutdown_task (void *cls)
1261 */ 1233 */
1262static void 1234static void
1263add_host (const char *hostname, 1235add_host (const char *hostname,
1264 uint16_t rec_type, 1236 uint16_t rec_type,
1265 const void *data, 1237 const void *data,
1266 size_t data_size) 1238 size_t data_size)
1267{ 1239{
1268 struct ResolveCache *rc; 1240 struct ResolveCache *rc;
1269 struct RecordListEntry *rle; 1241 struct RecordListEntry *rle;
@@ -1275,18 +1247,18 @@ add_host (const char *hostname,
1275 rec->dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; 1247 rec->dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
1276 rec->name = GNUNET_strdup (hostname); 1248 rec->name = GNUNET_strdup (hostname);
1277 rec->data.raw.data = GNUNET_memdup (data, 1249 rec->data.raw.data = GNUNET_memdup (data,
1278 data_size); 1250 data_size);
1279 rec->data.raw.data_len = data_size; 1251 rec->data.raw.data_len = data_size;
1280 rle = GNUNET_new (struct RecordListEntry); 1252 rle = GNUNET_new (struct RecordListEntry);
1281 rle->record = rec; 1253 rle->record = rec;
1282 rc = GNUNET_new (struct ResolveCache); 1254 rc = GNUNET_new (struct ResolveCache);
1283 rc->hostname = GNUNET_strdup (hostname); 1255 rc->hostname = GNUNET_strdup (hostname);
1284 GNUNET_CONTAINER_DLL_insert (rc->records_head, 1256 GNUNET_CONTAINER_DLL_insert (rc->records_head,
1285 rc->records_tail, 1257 rc->records_tail,
1286 rle); 1258 rle);
1287 GNUNET_CONTAINER_DLL_insert (hosts_head, 1259 GNUNET_CONTAINER_DLL_insert (hosts_head,
1288 hosts_tail, 1260 hosts_tail,
1289 rc); 1261 rc);
1290} 1262}
1291 1263
1292 1264
@@ -1298,7 +1270,7 @@ add_host (const char *hostname,
1298 */ 1270 */
1299static void 1271static void
1300extract_hosts (const char *line, 1272extract_hosts (const char *line,
1301 size_t line_len) 1273 size_t line_len)
1302{ 1274{
1303 const char *c; 1275 const char *c;
1304 struct in_addr v4; 1276 struct in_addr v4;
@@ -1308,19 +1280,19 @@ extract_hosts (const char *line,
1308 1280
1309 /* ignore everything after '#' */ 1281 /* ignore everything after '#' */
1310 c = memrchr (line, 1282 c = memrchr (line,
1311 (unsigned char) '#', 1283 (unsigned char) '#',
1312 line_len); 1284 line_len);
1313 if (NULL != c) 1285 if (NULL != c)
1314 line_len = c - line; 1286 line_len = c - line;
1315 /* ignore leading whitespace */ 1287 /* ignore leading whitespace */
1316 while ( (0 < line_len) && 1288 while ( (0 < line_len) &&
1317 isspace ((unsigned char) *line) ) 1289 isspace ((unsigned char) *line) )
1318 { 1290 {
1319 line++; 1291 line++;
1320 line_len--; 1292 line_len--;
1321 } 1293 }
1322 tbuf = GNUNET_strndup (line, 1294 tbuf = GNUNET_strndup (line,
1323 line_len); 1295 line_len);
1324 tok = strtok (tbuf, " \t"); 1296 tok = strtok (tbuf, " \t");
1325 if (NULL == tok) 1297 if (NULL == tok)
1326 { 1298 {
@@ -1328,24 +1300,24 @@ extract_hosts (const char *line,
1328 return; 1300 return;
1329 } 1301 }
1330 if (1 == inet_pton (AF_INET, 1302 if (1 == inet_pton (AF_INET,
1331 tok, 1303 tok,
1332 &v4)) 1304 &v4))
1333 { 1305 {
1334 while (NULL != (tok = strtok (NULL, " \t"))) 1306 while (NULL != (tok = strtok (NULL, " \t")))
1335 add_host (tok, 1307 add_host (tok,
1336 GNUNET_DNSPARSER_TYPE_A, 1308 GNUNET_DNSPARSER_TYPE_A,
1337 &v4, 1309 &v4,
1338 sizeof (struct in_addr)); 1310 sizeof (struct in_addr));
1339 } 1311 }
1340 else if (1 == inet_pton (AF_INET6, 1312 else if (1 == inet_pton (AF_INET6,
1341 tok, 1313 tok,
1342 &v6)) 1314 &v6))
1343 { 1315 {
1344 while (NULL != (tok = strtok (NULL, " \t"))) 1316 while (NULL != (tok = strtok (NULL, " \t")))
1345 add_host (tok, 1317 add_host (tok,
1346 GNUNET_DNSPARSER_TYPE_AAAA, 1318 GNUNET_DNSPARSER_TYPE_AAAA,
1347 &v6, 1319 &v6,
1348 sizeof (struct in6_addr)); 1320 sizeof (struct in6_addr));
1349 } 1321 }
1350 GNUNET_free (tbuf); 1322 GNUNET_free (tbuf);
1351} 1323}
@@ -1364,36 +1336,36 @@ load_etc_hosts (void)
1364 size_t read_offset; 1336 size_t read_offset;
1365 1337
1366 fh = GNUNET_DISK_file_open ("/etc/hosts", 1338 fh = GNUNET_DISK_file_open ("/etc/hosts",
1367 GNUNET_DISK_OPEN_READ, 1339 GNUNET_DISK_OPEN_READ,
1368 GNUNET_DISK_PERM_NONE); 1340 GNUNET_DISK_PERM_NONE);
1369 if (NULL == fh) 1341 if (NULL == fh)
1370 { 1342 {
1371 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1343 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1372 "Failed to open /etc/hosts"); 1344 "Failed to open /etc/hosts");
1373 return; 1345 return;
1374 } 1346 }
1375 if (GNUNET_OK != 1347 if (GNUNET_OK !=
1376 GNUNET_DISK_file_handle_size (fh, 1348 GNUNET_DISK_file_handle_size (fh,
1377 &bytes_read)) 1349 &bytes_read))
1378 { 1350 {
1379 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1351 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1380 "Could not determin size of /etc/hosts. " 1352 "Could not determin size of /etc/hosts. "
1381 "DNS resolution will not be possible.\n"); 1353 "DNS resolution will not be possible.\n");
1382 GNUNET_DISK_file_close (fh); 1354 GNUNET_DISK_file_close (fh);
1383 return; 1355 return;
1384 } 1356 }
1385 if ((size_t) bytes_read > SIZE_MAX) 1357 if ((size_t) bytes_read > SIZE_MAX)
1386 { 1358 {
1387 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1388 "/etc/hosts file too large to mmap. " 1360 "/etc/hosts file too large to mmap. "
1389 "DNS resolution will not be possible.\n"); 1361 "DNS resolution will not be possible.\n");
1390 GNUNET_DISK_file_close (fh); 1362 GNUNET_DISK_file_close (fh);
1391 return; 1363 return;
1392 } 1364 }
1393 buf = GNUNET_DISK_file_map (fh, 1365 buf = GNUNET_DISK_file_map (fh,
1394 &mh, 1366 &mh,
1395 GNUNET_DISK_MAP_TYPE_READ, 1367 GNUNET_DISK_MAP_TYPE_READ,
1396 (size_t) bytes_read); 1368 (size_t) bytes_read);
1397 read_offset = 0; 1369 read_offset = 0;
1398 while (read_offset < (size_t) bytes_read) 1370 while (read_offset < (size_t) bytes_read)
1399 { 1371 {
@@ -1406,7 +1378,7 @@ load_etc_hosts (void)
1406 break; 1378 break;
1407 line_len = newline - buf - read_offset; 1379 line_len = newline - buf - read_offset;
1408 extract_hosts (buf + read_offset, 1380 extract_hosts (buf + read_offset,
1409 line_len); 1381 line_len);
1410 read_offset += line_len + 1; 1382 read_offset += line_len + 1;
1411 } 1383 }
1412 GNUNET_DISK_file_unmap (mh); 1384 GNUNET_DISK_file_unmap (mh);
@@ -1423,8 +1395,8 @@ load_etc_hosts (void)
1423 */ 1395 */
1424static void 1396static void
1425init_cb (void *cls, 1397init_cb (void *cls,
1426 const struct GNUNET_CONFIGURATION_Handle *cfg, 1398 const struct GNUNET_CONFIGURATION_Handle *cfg,
1427 struct GNUNET_SERVICE_Handle *sh) 1399 struct GNUNET_SERVICE_Handle *sh)
1428{ 1400{
1429 char **dns_servers; 1401 char **dns_servers;
1430 int num_dns_servers; 1402 int num_dns_servers;
@@ -1433,23 +1405,23 @@ init_cb (void *cls,
1433 (void) sh; 1405 (void) sh;
1434 load_etc_hosts (); 1406 load_etc_hosts ();
1435 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1407 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
1436 cls); 1408 cls);
1437 dnsstub_ctx = GNUNET_DNSSTUB_start (128); 1409 dnsstub_ctx = GNUNET_DNSSTUB_start (128);
1438 dns_servers = NULL; 1410 dns_servers = NULL;
1439 num_dns_servers = lookup_dns_servers (&dns_servers); 1411 num_dns_servers = lookup_dns_servers (&dns_servers);
1440 if (0 >= num_dns_servers) 1412 if (0 >= num_dns_servers)
1441 { 1413 {
1442 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1414 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1443 _("No DNS server available. DNS resolution will not be possible.\n")); 1415 _("No DNS server available. DNS resolution will not be possible.\n"));
1444 return; 1416 return;
1445 } 1417 }
1446 for (int i = 0; i < num_dns_servers; i++) 1418 for (int i = 0; i < num_dns_servers; i++)
1447 { 1419 {
1448 int result = GNUNET_DNSSTUB_add_dns_ip (dnsstub_ctx, dns_servers[i]); 1420 int result = GNUNET_DNSSTUB_add_dns_ip (dnsstub_ctx, dns_servers[i]);
1449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1421 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1450 "Adding DNS server '%s': %s\n", 1422 "Adding DNS server '%s': %s\n",
1451 dns_servers[i], 1423 dns_servers[i],
1452 GNUNET_OK == result ? "success" : "failure"); 1424 GNUNET_OK == result ? "success" : "failure");
1453 GNUNET_free (dns_servers[i]); 1425 GNUNET_free (dns_servers[i]);
1454 } 1426 }
1455 GNUNET_free_non_null (dns_servers); 1427 GNUNET_free_non_null (dns_servers);
@@ -1466,8 +1438,8 @@ init_cb (void *cls,
1466 */ 1438 */
1467static void * 1439static void *
1468connect_cb (void *cls, 1440connect_cb (void *cls,
1469 struct GNUNET_SERVICE_Client *c, 1441 struct GNUNET_SERVICE_Client *c,
1470 struct GNUNET_MQ_Handle *mq) 1442 struct GNUNET_MQ_Handle *mq)
1471{ 1443{
1472 (void) cls; 1444 (void) cls;
1473 (void) mq; 1445 (void) mq;
@@ -1485,8 +1457,8 @@ connect_cb (void *cls,
1485 */ 1457 */
1486static void 1458static void
1487disconnect_cb (void *cls, 1459disconnect_cb (void *cls,
1488 struct GNUNET_SERVICE_Client *c, 1460 struct GNUNET_SERVICE_Client *c,
1489 void *internal_cls) 1461 void *internal_cls)
1490{ 1462{
1491 struct ActiveLookup *n; 1463 struct ActiveLookup *n;
1492 (void) cls; 1464 (void) cls;
@@ -1515,9 +1487,9 @@ GNUNET_SERVICE_MAIN
1515 &disconnect_cb, 1487 &disconnect_cb,
1516 NULL, 1488 NULL,
1517 GNUNET_MQ_hd_var_size (get, 1489 GNUNET_MQ_hd_var_size (get,
1518 GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST, 1490 GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST,
1519 struct GNUNET_RESOLVER_GetMessage, 1491 struct GNUNET_RESOLVER_GetMessage,
1520 NULL), 1492 NULL),
1521 GNUNET_MQ_handler_end ()); 1493 GNUNET_MQ_handler_end ());
1522 1494
1523 1495