2 libloc - A library to determine the location of someone on the Internet
4 Copyright (C) 2017 IPFire Development Team <info@ipfire.org>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
17 #include <arpa/inet.h>
21 #include <netinet/in.h>
28 #include <sys/types.h>
32 #include <loc/libloc.h>
34 #include <loc/country.h>
35 #include <loc/database.h>
36 #include <loc/format.h>
37 #include <loc/network.h>
38 #include <loc/private.h>
39 #include <loc/stringpool.h>
51 // ASes in the database
52 struct loc_database_as_v0
* as_v0
;
56 struct loc_database_network_node_v0
* network_nodes_v0
;
57 size_t network_nodes_count
;
60 struct loc_database_network_v0
* networks_v0
;
61 size_t networks_count
;
64 struct loc_database_country_v0
* countries_v0
;
65 size_t countries_count
;
67 struct loc_stringpool
* pool
;
70 #define MAX_STACK_DEPTH 256
72 struct loc_node_stack
{
74 int i
; // Is this node 0 or 1?
78 struct loc_database_enumerator
{
80 struct loc_database
* db
;
81 enum loc_database_enumerator_mode mode
;
88 enum loc_network_flags flags
;
90 // Index of the AS we are looking at
91 unsigned int as_index
;
94 struct in6_addr network_address
;
95 struct loc_node_stack network_stack
[MAX_STACK_DEPTH
];
96 int network_stack_depth
;
97 unsigned int* networks_visited
;
100 static int loc_database_read_magic(struct loc_database
* db
, FILE* f
) {
101 struct loc_database_magic magic
;
104 size_t bytes_read
= fread(&magic
, 1, sizeof(magic
), f
);
106 // Check if we have been able to read enough data
107 if (bytes_read
< sizeof(magic
)) {
108 ERROR(db
->ctx
, "Could not read enough data to validate magic bytes\n");
109 DEBUG(db
->ctx
, "Read %zu bytes, but needed %zu\n", bytes_read
, sizeof(magic
));
113 // Compare magic bytes
114 if (memcmp(LOC_DATABASE_MAGIC
, magic
.magic
, strlen(LOC_DATABASE_MAGIC
)) == 0) {
115 DEBUG(db
->ctx
, "Magic value matches\n");
118 db
->version
= be16toh(magic
.version
);
119 DEBUG(db
->ctx
, "Database version is %u\n", db
->version
);
124 ERROR(db
->ctx
, "Database format is not compatible\n");
130 static int loc_database_read_as_section_v0(struct loc_database
* db
,
131 FILE* f
, const struct loc_database_header_v0
* header
) {
132 off_t as_offset
= be32toh(header
->as_offset
);
133 size_t as_length
= be32toh(header
->as_length
);
135 DEBUG(db
->ctx
, "Reading AS section from %jd (%zu bytes)\n", as_offset
, as_length
);
138 db
->as_v0
= mmap(NULL
, as_length
, PROT_READ
,
139 MAP_SHARED
, fileno(f
), as_offset
);
141 if (db
->as_v0
== MAP_FAILED
)
145 db
->as_count
= as_length
/ sizeof(*db
->as_v0
);
147 INFO(db
->ctx
, "Read %zu ASes from the database\n", db
->as_count
);
152 static int loc_database_read_network_nodes_section_v0(struct loc_database
* db
,
153 FILE* f
, const struct loc_database_header_v0
* header
) {
154 off_t network_nodes_offset
= be32toh(header
->network_tree_offset
);
155 size_t network_nodes_length
= be32toh(header
->network_tree_length
);
157 DEBUG(db
->ctx
, "Reading network nodes section from %jd (%zu bytes)\n",
158 network_nodes_offset
, network_nodes_length
);
160 if (network_nodes_length
> 0) {
161 db
->network_nodes_v0
= mmap(NULL
, network_nodes_length
, PROT_READ
,
162 MAP_SHARED
, fileno(f
), network_nodes_offset
);
164 if (db
->network_nodes_v0
== MAP_FAILED
)
168 db
->network_nodes_count
= network_nodes_length
/ sizeof(*db
->network_nodes_v0
);
170 INFO(db
->ctx
, "Read %zu network nodes from the database\n", db
->network_nodes_count
);
175 static int loc_database_read_networks_section_v0(struct loc_database
* db
,
176 FILE* f
, const struct loc_database_header_v0
* header
) {
177 off_t networks_offset
= be32toh(header
->network_data_offset
);
178 size_t networks_length
= be32toh(header
->network_data_length
);
180 DEBUG(db
->ctx
, "Reading networks section from %jd (%zu bytes)\n",
181 networks_offset
, networks_length
);
183 if (networks_length
> 0) {
184 db
->networks_v0
= mmap(NULL
, networks_length
, PROT_READ
,
185 MAP_SHARED
, fileno(f
), networks_offset
);
187 if (db
->networks_v0
== MAP_FAILED
)
191 db
->networks_count
= networks_length
/ sizeof(*db
->networks_v0
);
193 INFO(db
->ctx
, "Read %zu networks from the database\n", db
->networks_count
);
198 static int loc_database_read_countries_section_v0(struct loc_database
* db
,
199 FILE* f
, const struct loc_database_header_v0
* header
) {
200 off_t countries_offset
= be32toh(header
->countries_offset
);
201 size_t countries_length
= be32toh(header
->countries_length
);
203 DEBUG(db
->ctx
, "Reading countries section from %jd (%zu bytes)\n",
204 countries_offset
, countries_length
);
206 if (countries_length
> 0) {
207 db
->countries_v0
= mmap(NULL
, countries_length
, PROT_READ
,
208 MAP_SHARED
, fileno(f
), countries_offset
);
210 if (db
->countries_v0
== MAP_FAILED
)
214 db
->countries_count
= countries_length
/ sizeof(*db
->countries_v0
);
216 INFO(db
->ctx
, "Read %zu countries from the database\n",
217 db
->countries_count
);
222 static int loc_database_read_header_v0(struct loc_database
* db
, FILE* f
) {
223 struct loc_database_header_v0 header
;
226 size_t size
= fread(&header
, 1, sizeof(header
), f
);
228 if (size
< sizeof(header
)) {
229 ERROR(db
->ctx
, "Could not read enough data for header\n");
234 db
->created_at
= be64toh(header
.created_at
);
235 db
->vendor
= be32toh(header
.vendor
);
236 db
->description
= be32toh(header
.description
);
237 db
->license
= be32toh(header
.license
);
240 off_t pool_offset
= be32toh(header
.pool_offset
);
241 size_t pool_length
= be32toh(header
.pool_length
);
243 int r
= loc_stringpool_open(db
->ctx
, &db
->pool
,
244 f
, pool_length
, pool_offset
);
249 r
= loc_database_read_as_section_v0(db
, f
, &header
);
254 r
= loc_database_read_network_nodes_section_v0(db
, f
, &header
);
259 r
= loc_database_read_networks_section_v0(db
, f
, &header
);
264 r
= loc_database_read_countries_section_v0(db
, f
, &header
);
271 static int loc_database_read_header(struct loc_database
* db
, FILE* f
) {
272 switch (db
->version
) {
274 return loc_database_read_header_v0(db
, f
);
277 ERROR(db
->ctx
, "Incompatible database version: %u\n", db
->version
);
282 static int loc_database_read(struct loc_database
* db
, FILE* f
) {
283 clock_t start
= clock();
286 int r
= loc_database_read_magic(db
, f
);
291 r
= loc_database_read_header(db
, f
);
295 clock_t end
= clock();
297 INFO(db
->ctx
, "Opened database in %.4fms\n",
298 (double)(end
- start
) / CLOCKS_PER_SEC
* 1000);
303 LOC_EXPORT
int loc_database_new(struct loc_ctx
* ctx
, struct loc_database
** database
, FILE* f
) {
304 // Fail on invalid file handle
308 struct loc_database
* db
= calloc(1, sizeof(*db
));
313 db
->ctx
= loc_ref(ctx
);
316 DEBUG(db
->ctx
, "Database object allocated at %p\n", db
);
318 int r
= loc_database_read(db
, f
);
320 loc_database_unref(db
);
329 LOC_EXPORT
struct loc_database
* loc_database_ref(struct loc_database
* db
) {
335 static void loc_database_free(struct loc_database
* db
) {
338 DEBUG(db
->ctx
, "Releasing database %p\n", db
);
342 r
= munmap(db
->as_v0
, db
->as_count
* sizeof(*db
->as_v0
));
344 ERROR(db
->ctx
, "Could not unmap AS section: %s\n", strerror(errno
));
347 // Remove mapped network sections
348 if (db
->networks_v0
) {
349 r
= munmap(db
->networks_v0
, db
->networks_count
* sizeof(*db
->networks_v0
));
351 ERROR(db
->ctx
, "Could not unmap networks section: %s\n", strerror(errno
));
354 // Remove mapped network nodes section
355 if (db
->network_nodes_v0
) {
356 r
= munmap(db
->network_nodes_v0
, db
->network_nodes_count
* sizeof(*db
->network_nodes_v0
));
358 ERROR(db
->ctx
, "Could not unmap network nodes section: %s\n", strerror(errno
));
361 loc_stringpool_unref(db
->pool
);
367 LOC_EXPORT
struct loc_database
* loc_database_unref(struct loc_database
* db
) {
368 if (--db
->refcount
> 0)
371 loc_database_free(db
);
375 LOC_EXPORT
time_t loc_database_created_at(struct loc_database
* db
) {
376 return db
->created_at
;
379 LOC_EXPORT
const char* loc_database_get_vendor(struct loc_database
* db
) {
380 return loc_stringpool_get(db
->pool
, db
->vendor
);
383 LOC_EXPORT
const char* loc_database_get_description(struct loc_database
* db
) {
384 return loc_stringpool_get(db
->pool
, db
->description
);
387 LOC_EXPORT
const char* loc_database_get_license(struct loc_database
* db
) {
388 return loc_stringpool_get(db
->pool
, db
->license
);
391 LOC_EXPORT
size_t loc_database_count_as(struct loc_database
* db
) {
395 // Returns the AS at position pos
396 static int loc_database_fetch_as(struct loc_database
* db
, struct loc_as
** as
, off_t pos
) {
397 if ((size_t)pos
>= db
->as_count
)
400 DEBUG(db
->ctx
, "Fetching AS at position %jd\n", pos
);
403 switch (db
->version
) {
405 r
= loc_as_new_from_database_v0(db
->ctx
, db
->pool
, as
, db
->as_v0
+ pos
);
413 DEBUG(db
->ctx
, "Got AS%u\n", loc_as_get_number(*as
));
419 // Performs a binary search to find the AS in the list
420 LOC_EXPORT
int loc_database_get_as(struct loc_database
* db
, struct loc_as
** as
, uint32_t number
) {
422 off_t hi
= db
->as_count
- 1;
425 clock_t start
= clock();
428 off_t i
= (lo
+ hi
) / 2;
430 // Fetch AS in the middle between lo and hi
431 int r
= loc_database_fetch_as(db
, as
, i
);
435 // Check if this is a match
436 uint32_t as_number
= loc_as_get_number(*as
);
437 if (as_number
== number
) {
438 clock_t end
= clock();
440 // Log how fast this has been
441 DEBUG(db
->ctx
, "Found AS%u in %.4fms\n", as_number
,
442 (double)(end
- start
) / CLOCKS_PER_SEC
* 1000);
447 // If it wasn't, we release the AS and
448 // adjust our search pointers
451 if (as_number
< number
) {
463 // Returns the network at position pos
464 static int loc_database_fetch_network(struct loc_database
* db
, struct loc_network
** network
,
465 struct in6_addr
* address
, unsigned int prefix
, off_t pos
) {
466 if ((size_t)pos
>= db
->networks_count
)
469 DEBUG(db
->ctx
, "Fetching network at position %jd\n", pos
);
472 switch (db
->version
) {
474 r
= loc_network_new_from_database_v0(db
->ctx
, network
,
475 address
, prefix
, db
->networks_v0
+ pos
);
483 char* string
= loc_network_str(*network
);
484 DEBUG(db
->ctx
, "Got network %s\n", string
);
491 static int __loc_database_node_is_leaf(const struct loc_database_network_node_v0
* node
) {
492 return (node
->network
!= htobe32(0xffffffff));
495 static int __loc_database_lookup_handle_leaf(struct loc_database
* db
, const struct in6_addr
* address
,
496 struct loc_network
** network
, struct in6_addr
* network_address
, unsigned int prefix
,
497 const struct loc_database_network_node_v0
* node
) {
498 off_t network_index
= be32toh(node
->network
);
500 DEBUG(db
->ctx
, "Handling leaf node at %jd (%jd)\n", node
- db
->network_nodes_v0
, network_index
);
503 int r
= loc_database_fetch_network(db
, network
,
504 network_address
, prefix
, network_index
);
506 ERROR(db
->ctx
, "Could not fetch network %jd from database\n", network_index
);
510 // Check if the given IP address is inside the network
511 r
= loc_network_match_address(*network
, address
);
513 DEBUG(db
->ctx
, "Searched address is not part of the network\n");
515 loc_network_unref(*network
);
520 // A network was found and the IP address matches
524 // Searches for an exact match along the path
525 static int __loc_database_lookup(struct loc_database
* db
, const struct in6_addr
* address
,
526 struct loc_network
** network
, struct in6_addr
* network_address
,
527 const struct loc_database_network_node_v0
* node
, unsigned int level
) {
532 int bit
= in6_addr_get_bit(address
, level
);
533 in6_addr_set_bit(network_address
, level
, bit
);
536 node_index
= be32toh(node
->zero
);
538 node_index
= be32toh(node
->one
);
540 // If the node index is zero, the tree ends here
541 // and we cannot descend any further
542 if (node_index
> 0) {
544 if ((size_t)node_index
>= db
->network_nodes_count
)
547 // Move on to the next node
548 r
= __loc_database_lookup(db
, address
, network
, network_address
,
549 db
->network_nodes_v0
+ node_index
, level
+ 1);
551 // End here if a result was found
559 DEBUG(db
->ctx
, "No match found below level %u\n", level
);
561 DEBUG(db
->ctx
, "Tree ended at level %u\n", level
);
564 // If this node has a leaf, we will check if it matches
565 if (__loc_database_node_is_leaf(node
)) {
566 r
= __loc_database_lookup_handle_leaf(db
, address
, network
, network_address
, level
, node
);
574 LOC_EXPORT
int loc_database_lookup(struct loc_database
* db
,
575 struct in6_addr
* address
, struct loc_network
** network
) {
576 struct in6_addr network_address
;
577 memset(&network_address
, 0, sizeof(network_address
));
582 clock_t start
= clock();
584 int r
= __loc_database_lookup(db
, address
, network
, &network_address
,
585 db
->network_nodes_v0
, 0);
587 clock_t end
= clock();
589 // Log how fast this has been
590 DEBUG(db
->ctx
, "Executed network search in %.4fms\n",
591 (double)(end
- start
) / CLOCKS_PER_SEC
* 1000);
596 LOC_EXPORT
int loc_database_lookup_from_string(struct loc_database
* db
,
597 const char* string
, struct loc_network
** network
) {
598 struct in6_addr address
;
600 int r
= loc_parse_address(db
->ctx
, string
, &address
);
604 return loc_database_lookup(db
, &address
, network
);
607 // Returns the country at position pos
608 static int loc_database_fetch_country(struct loc_database
* db
,
609 struct loc_country
** country
, off_t pos
) {
610 if ((size_t)pos
>= db
->countries_count
)
613 DEBUG(db
->ctx
, "Fetching country at position %jd\n", pos
);
616 switch (db
->version
) {
618 r
= loc_country_new_from_database_v0(db
->ctx
, db
->pool
, country
, db
->countries_v0
+ pos
);
626 DEBUG(db
->ctx
, "Got country %s\n", loc_country_get_code(*country
));
632 // Performs a binary search to find the country in the list
633 LOC_EXPORT
int loc_database_get_country(struct loc_database
* db
,
634 struct loc_country
** country
, const char* code
) {
636 off_t hi
= db
->countries_count
- 1;
639 clock_t start
= clock();
642 off_t i
= (lo
+ hi
) / 2;
644 // Fetch country in the middle between lo and hi
645 int r
= loc_database_fetch_country(db
, country
, i
);
649 // Check if this is a match
650 const char* cc
= loc_country_get_code(*country
);
651 int result
= strcmp(code
, cc
);
654 clock_t end
= clock();
656 // Log how fast this has been
657 DEBUG(db
->ctx
, "Found country %s in %.4fms\n", cc
,
658 (double)(end
- start
) / CLOCKS_PER_SEC
* 1000);
663 // If it wasn't, we release the country and
664 // adjust our search pointers
665 loc_country_unref(*country
);
681 LOC_EXPORT
int loc_database_enumerator_new(struct loc_database_enumerator
** enumerator
,
682 struct loc_database
* db
, enum loc_database_enumerator_mode mode
) {
683 struct loc_database_enumerator
* e
= calloc(1, sizeof(*e
));
688 e
->ctx
= loc_ref(db
->ctx
);
689 e
->db
= loc_database_ref(db
);
693 // Initialise graph search
694 //e->network_stack[++e->network_stack_depth] = 0;
695 e
->network_stack_depth
= 1;
696 e
->networks_visited
= calloc(db
->network_nodes_count
, sizeof(*e
->networks_visited
));
698 DEBUG(e
->ctx
, "Database enumerator object allocated at %p\n", e
);
704 LOC_EXPORT
struct loc_database_enumerator
* loc_database_enumerator_ref(struct loc_database_enumerator
* enumerator
) {
705 enumerator
->refcount
++;
710 static void loc_database_enumerator_free(struct loc_database_enumerator
* enumerator
) {
711 DEBUG(enumerator
->ctx
, "Releasing database enumerator %p\n", enumerator
);
713 // Release all references
714 loc_database_unref(enumerator
->db
);
715 loc_unref(enumerator
->ctx
);
717 if (enumerator
->string
)
718 free(enumerator
->string
);
720 // Free network search
721 free(enumerator
->networks_visited
);
726 LOC_EXPORT
struct loc_database_enumerator
* loc_database_enumerator_unref(struct loc_database_enumerator
* enumerator
) {
730 if (--enumerator
->refcount
> 0)
733 loc_database_enumerator_free(enumerator
);
737 LOC_EXPORT
int loc_database_enumerator_set_string(struct loc_database_enumerator
* enumerator
, const char* string
) {
738 enumerator
->string
= strdup(string
);
740 // Make the string lowercase
741 for (char *p
= enumerator
->string
; *p
; p
++)
747 LOC_EXPORT
int loc_database_enumerator_set_country_code(struct loc_database_enumerator
* enumerator
, const char* country_code
) {
748 // Set empty country code
749 if (!country_code
|| !*country_code
) {
750 *enumerator
->country_code
= '\0';
754 // Treat A1, A2, A3 as special country codes,
755 // but perform search for flags instead
756 if (strcmp(country_code
, "A1") == 0) {
757 return loc_database_enumerator_set_flag(enumerator
,
758 LOC_NETWORK_FLAG_ANONYMOUS_PROXY
);
759 } else if (strcmp(country_code
, "A2") == 0) {
760 return loc_database_enumerator_set_flag(enumerator
,
761 LOC_NETWORK_FLAG_SATELLITE_PROVIDER
);
762 } else if (strcmp(country_code
, "A3") == 0) {
763 return loc_database_enumerator_set_flag(enumerator
,
764 LOC_NETWORK_FLAG_ANYCAST
);
767 // Country codes must be two characters
768 if (!loc_country_code_is_valid(country_code
))
771 for (unsigned int i
= 0; i
< 3; i
++) {
772 enumerator
->country_code
[i
] = country_code
[i
];
778 LOC_EXPORT
int loc_database_enumerator_set_asn(
779 struct loc_database_enumerator
* enumerator
, unsigned int asn
) {
780 enumerator
->asn
= asn
;
785 LOC_EXPORT
int loc_database_enumerator_set_flag(
786 struct loc_database_enumerator
* enumerator
, enum loc_network_flags flag
) {
787 enumerator
->flags
|= flag
;
792 LOC_EXPORT
int loc_database_enumerator_next_as(
793 struct loc_database_enumerator
* enumerator
, struct loc_as
** as
) {
796 // Do not do anything if not in AS mode
797 if (enumerator
->mode
!= LOC_DB_ENUMERATE_ASES
)
800 struct loc_database
* db
= enumerator
->db
;
802 while (enumerator
->as_index
< db
->as_count
) {
804 int r
= loc_database_fetch_as(db
, as
, enumerator
->as_index
++);
808 r
= loc_as_match_string(*as
, enumerator
->string
);
810 DEBUG(enumerator
->ctx
, "AS%d (%s) matches %s\n",
811 loc_as_get_number(*as
), loc_as_get_name(*as
), enumerator
->string
);
822 enumerator
->as_index
= 0;
824 // We have searched through all of them
828 static int loc_database_enumerator_stack_push_node(
829 struct loc_database_enumerator
* e
, off_t offset
, int i
, int depth
) {
830 // Do not add empty nodes
834 // Check if there is any space left on the stack
835 if (e
->network_stack_depth
>= MAX_STACK_DEPTH
) {
836 ERROR(e
->ctx
, "Maximum stack size reached: %d\n", e
->network_stack_depth
);
840 // Increase stack size
841 int s
= ++e
->network_stack_depth
;
843 DEBUG(e
->ctx
, "Added node %jd to stack (%d)\n", offset
, depth
);
845 e
->network_stack
[s
].offset
= offset
;
846 e
->network_stack
[s
].i
= i
;
847 e
->network_stack
[s
].depth
= depth
;
852 LOC_EXPORT
int loc_database_enumerator_next_network(
853 struct loc_database_enumerator
* enumerator
, struct loc_network
** network
) {
857 // Do not do anything if not in network mode
858 if (enumerator
->mode
!= LOC_DB_ENUMERATE_NETWORKS
)
863 DEBUG(enumerator
->ctx
, "Called with a stack of %u nodes\n",
864 enumerator
->network_stack_depth
);
867 while (enumerator
->network_stack_depth
> 0) {
868 DEBUG(enumerator
->ctx
, "Stack depth: %u\n", enumerator
->network_stack_depth
);
870 // Get object from top of the stack
871 struct loc_node_stack
* node
= &enumerator
->network_stack
[enumerator
->network_stack_depth
];
873 // Remove the node from the stack if we have already visited it
874 if (enumerator
->networks_visited
[node
->offset
]) {
875 enumerator
->network_stack_depth
--;
879 // Mark the bits on the path correctly
880 in6_addr_set_bit(&enumerator
->network_address
,
881 (node
->depth
> 0) ? node
->depth
- 1 : 0, node
->i
);
883 DEBUG(enumerator
->ctx
, "Looking at node %jd\n", node
->offset
);
884 enumerator
->networks_visited
[node
->offset
]++;
886 // Pop node from top of the stack
887 struct loc_database_network_node_v0
* n
=
888 enumerator
->db
->network_nodes_v0
+ node
->offset
;
890 // Add edges to stack
891 r
= loc_database_enumerator_stack_push_node(enumerator
,
892 be32toh(n
->one
), 1, node
->depth
+ 1);
897 r
= loc_database_enumerator_stack_push_node(enumerator
,
898 be32toh(n
->zero
), 0, node
->depth
+ 1);
903 // Check if this node is a leaf and has a network object
904 if (__loc_database_node_is_leaf(n
)) {
905 off_t network_index
= be32toh(n
->network
);
907 DEBUG(enumerator
->ctx
, "Node has a network at %jd\n", network_index
);
909 // Fetch the network object
910 r
= loc_database_fetch_network(enumerator
->db
, network
,
911 &enumerator
->network_address
, node
->depth
, network_index
);
913 // Break on any errors
917 // Check if we are interested in this network
919 // Skip if the country code does not match
920 if (enumerator
->country_code
&&
921 !loc_network_match_country_code(*network
, enumerator
->country_code
)) {
922 loc_network_unref(*network
);
928 // Skip if the ASN does not match
929 if (enumerator
->asn
&&
930 !loc_network_match_asn(*network
, enumerator
->asn
)) {
931 loc_network_unref(*network
);
937 // Skip if flags do not match
938 if (enumerator
->flags
&&
939 !loc_network_match_flag(*network
, enumerator
->flags
)) {
940 loc_network_unref(*network
);
948 // Reached the end of the search
950 // Mark all nodes as non-visited
951 for (unsigned int i
= 0; i
< enumerator
->db
->network_nodes_count
; i
++)
952 enumerator
->networks_visited
[i
] = 0;