"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "base/hosts.c" between
gvm-libs-10.0.1.tar.gz and gvm-libs-11.0.0.tar.gz

About: GVM Libraries for the Greenbone Vulnerability Management (GVM-10) framework (derived from the former openvas-libraries).

hosts.c  (gvm-libs-10.0.1):hosts.c  (gvm-libs-11.0.0)
skipping to change at line 1332 skipping to change at line 1332
hosts->current = 0; hosts->current = 0;
} }
/** /**
* @brief Resolves host objects of type name in a hosts collection, replacing * @brief Resolves host objects of type name in a hosts collection, replacing
* hostnames with IPv4 values. * hostnames with IPv4 values.
* Not to be used while iterating over the single hosts as it resets the * Not to be used while iterating over the single hosts as it resets the
* iterator. * iterator.
* *
* @param[in] hosts The hosts collection from which to exclude. * @param[in] hosts The hosts collection from which to exclude.
*
* @return List of unresolved hostnames.
*/ */
void GSList *
gvm_hosts_resolve (gvm_hosts_t *hosts) gvm_hosts_resolve (gvm_hosts_t *hosts)
{ {
size_t i, new_entries = 0 , resolved = 0; size_t i, new_entries = 0, resolved = 0;
GSList *unresolved = NULL;
for (i = 0; i < hosts->count; i++) for (i = 0; i < hosts->count; i++)
{ {
GSList *list, *tmp; GSList *list, *tmp;
gvm_host_t *host = hosts->hosts[i]; gvm_host_t *host = hosts->hosts[i];
if (host->type != HOST_TYPE_NAME) if (host->type != HOST_TYPE_NAME)
continue; continue;
list = tmp = gvm_resolve_list (host->name); list = tmp = gvm_resolve_list (host->name);
skipping to change at line 1378 skipping to change at line 1381
new->vhosts = g_slist_prepend (new->vhosts, vhost); new->vhosts = g_slist_prepend (new->vhosts, vhost);
gvm_hosts_add (hosts, new); gvm_hosts_add (hosts, new);
tmp = tmp->next; tmp = tmp->next;
new_entries = 1; new_entries = 1;
} }
/* Remove hostname from list, as it was either replaced by IPs, or /* Remove hostname from list, as it was either replaced by IPs, or
* is unresolvable. */ * is unresolvable. */
hosts->hosts[i] = NULL; hosts->hosts[i] = NULL;
resolved++; resolved++;
if (!list) if (!list)
g_warning ("Couldn't resolve hostname %s", host->name); unresolved = g_slist_prepend (unresolved, g_strdup (host->name));
gvm_host_free (host); gvm_host_free (host);
g_slist_free_full (list, g_free); g_slist_free_full (list, g_free);
} }
if (resolved) if (resolved)
gvm_hosts_fill_gaps (hosts); gvm_hosts_fill_gaps (hosts);
hosts->count -= resolved; hosts->count -= resolved;
hosts->removed += resolved; hosts->removed += resolved;
if (new_entries) if (new_entries)
gvm_hosts_deduplicate (hosts); gvm_hosts_deduplicate (hosts);
hosts->current = 0; hosts->current = 0;
return unresolved;
} }
/** /**
* @brief Exclude a list of vhosts from a host's vhosts list. * @brief Exclude a list of vhosts from a host's vhosts list.
* *
* @param[in] host The host whose vhosts are to be excluded from. * @param[in] host The host whose vhosts are to be excluded from.
* @param[in] excluded_str String of hosts to exclude. * @param[in] excluded_str String of hosts to exclude.
* *
* @return Number of excluded vhosts. * @return Number of excluded vhosts.
*/ */
skipping to change at line 1544 skipping to change at line 1548
/** /**
* @brief Checks for a host object reverse dns lookup existence. * @brief Checks for a host object reverse dns lookup existence.
* *
* @param[in] host The host to reverse-lookup. * @param[in] host The host to reverse-lookup.
* *
* @return Result of look-up, NULL otherwise. * @return Result of look-up, NULL otherwise.
*/ */
char * char *
gvm_host_reverse_lookup (gvm_host_t *host) gvm_host_reverse_lookup (gvm_host_t *host)
{ {
if (host == NULL) int retry = 2;
return NULL; gchar hostname[NI_MAXHOST];
void *addr;
size_t addrlen;
struct sockaddr_in sa;
struct sockaddr_in6 sa6;
if (host->type == HOST_TYPE_NAME) if (!host)
return NULL; return NULL;
else if (host->type == HOST_TYPE_IPV4)
{
struct sockaddr_in sa;
int retry = 2;
gchar hostname[1000];
bzero (&sa, sizeof (struct sockaddr)); if (host->type == HOST_TYPE_IPV4)
{
addr = &sa;
addrlen = sizeof (sa);
memset (addr, '\0', addrlen);
sa.sin_addr = host->addr; sa.sin_addr = host->addr;
sa.sin_family = AF_INET; sa.sin_family = AF_INET;
while (retry--)
{
int ret = getnameinfo ((struct sockaddr *) &sa, sizeof (sa), hostname,
sizeof (hostname), NULL, 0, NI_NAMEREQD);
if (!ret)
return g_ascii_strdown (hostname, -1);
if (ret != EAI_AGAIN)
break;
}
return NULL;
} }
else if (host->type == HOST_TYPE_IPV6) else if (host->type == HOST_TYPE_IPV6)
{ {
struct sockaddr_in6 sa; addr = &sa6;
char hostname[1000]; addrlen = sizeof (sa6);
memset (&sa6, '\0', addrlen);
bzero (&sa, sizeof (struct sockaddr)); memcpy (&sa6.sin6_addr, &host->addr6, 16);
memcpy (&sa.sin6_addr, &host->addr6, 16); sa6.sin6_family = AF_INET6;
sa.sin6_family = AF_INET6;
if (getnameinfo ((struct sockaddr *) &sa, sizeof (sa), hostname,
sizeof (hostname), NULL, 0, NI_NAMEREQD))
return NULL;
else
return g_ascii_strdown (hostname, -1);
} }
else else
return NULL; return NULL;
while (retry--)
{
int ret = getnameinfo (addr, addrlen, hostname, sizeof (hostname), NULL,
0, NI_NAMEREQD);
if (!ret)
return g_ascii_strdown (hostname, -1);
if (ret != EAI_AGAIN)
break;
}
return NULL;
} }
/** /**
* @brief Verifies that hostname value resolves to a host's IP. * @brief Verifies that hostname value resolves to a host's IP.
* *
* @param[in] host The host whose IP is to be checked against. * @param[in] host The host whose IP is to be checked against.
* @param[in] value Hostname value to verify. * @param[in] value Hostname value to verify.
* *
* @return 0 if hostname resolves to host's IP, -1 otherwise. * @return 0 if hostname resolves to host's IP, -1 otherwise.
*/ */
 End of changes. 12 change blocks. 
34 lines changed or deleted 35 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)