Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to find and return a host from a host list. #490

Merged
merged 1 commit into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Added
- Possibility to use lcrypt with `$6$` (sha512) for authentication [484](https://github.com/greenbone/gvm-libs/pull/484)
- Add function to find and return a host from a host list. [490](https://github.com/greenbone/gvm-libs/pull/490)

### Changed
### Fixed
Expand Down
40 changes: 30 additions & 10 deletions base/hosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1932,26 +1932,24 @@ gvm_hosts_duplicated (const gvm_hosts_t *hosts)
}

/**
* @brief Returns whether a host has an equal host in a hosts collection.
* eg. 192.168.10.1 has an equal in list created from
* "192.168.10.1-5, 192.168.10.10-20" string while 192.168.10.7 doesn't.
* @brief Find the gvm_host_t from a gvm_hosts_t structure.
*
* @param[in] host The host object.
* @param[in] addr Optional pointer to ip address. Could be used so that host
* isn't resolved multiple times when type is HOST_TYPE_NAME.
* @param[in] hosts Hosts collection.
*
* @return 1 if host has equal in hosts, 0 otherwise.
* @return Pointer to host if found. NULL if error or host not found
*/
int
gvm_host_in_hosts (const gvm_host_t *host, const struct in6_addr *addr,
const gvm_hosts_t *hosts)
gvm_host_t *
gvm_host_find_in_hosts (const gvm_host_t *host, const struct in6_addr *addr,
const gvm_hosts_t *hosts)
{
char *host_str;
size_t i;

if (host == NULL || hosts == NULL)
return 0;
return NULL;

host_str = gvm_host_value_str (host);

Expand All @@ -1964,7 +1962,7 @@ gvm_host_in_hosts (const gvm_host_t *host, const struct in6_addr *addr,
{
g_free (host_str);
g_free (tmp);
return 1;
return current_host;
}
g_free (tmp);

Expand All @@ -1977,12 +1975,34 @@ gvm_host_in_hosts (const gvm_host_t *host, const struct in6_addr *addr,
if (memcmp (addr->s6_addr, &tmpaddr.s6_addr, 16) == 0)
{
g_free (host_str);
return 1;
return current_host;
}
}
}

g_free (host_str);
return NULL;
}

/**
* @brief Returns whether a host has an equal host in a hosts collection.
* eg. 192.168.10.1 has an equal in list created from
* "192.168.10.1-5, 192.168.10.10-20" string while 192.168.10.7 doesn't.
*
* @param[in] host The host object.
* @param[in] addr Optional pointer to ip address. Could be used so that host
* isn't resolved multiple times when type is HOST_TYPE_NAME.
* @param[in] hosts Hosts collection.
*
* @return 1 if host has equal in hosts, 0 otherwise.
*/
int
gvm_host_in_hosts (const gvm_host_t *host, const struct in6_addr *addr,
const gvm_hosts_t *hosts)
{
if (gvm_host_find_in_hosts (host, addr, hosts))
return 1;

return 0;
}

Expand Down
4 changes: 4 additions & 0 deletions base/hosts.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ int
gvm_host_in_hosts (const gvm_host_t *, const struct in6_addr *,
const gvm_hosts_t *);

gvm_host_t *
gvm_host_find_in_hosts (const gvm_host_t *, const struct in6_addr *,
const gvm_hosts_t *);

gchar *
gvm_host_type_str (const gvm_host_t *);

Expand Down