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

Separate duplicated hosts from removed hosts in the hosts structure. #387

Merged
merged 1 commit into from
Aug 24, 2020
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [20.8.1] (unreleased)

### Added
- Add function to get duplicated hosts from the hosts list. [#387](https://github.com/greenbone/gvm-libs/pull/387)

[20.8.1]: https://github.com/greenbone/gvm-libs/compare/v20.8.0...gvm-libs-20.08

## [20.8.0] (2020-08-12)

### Added
Expand Down
16 changes: 15 additions & 1 deletion base/hosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ gvm_hosts_deduplicate (gvm_hosts_t *hosts)
gvm_hosts_fill_gaps (hosts);
g_hash_table_destroy (name_table);
hosts->count -= duplicates;
hosts->removed += duplicates;
hosts->duplicated += duplicates;
hosts->current = 0;
malloc_trim (0);
}
Expand Down Expand Up @@ -1884,6 +1884,20 @@ gvm_hosts_removed (const gvm_hosts_t *hosts)
return hosts ? hosts->removed : 0;
}

/**
* @brief Gets the count of single values in hosts string that were duplicated
* and therefore removed from the list
*
* @param[in] hosts The hosts collection.
*
* @return The number of duplicated values.
*/
unsigned int
gvm_hosts_duplicated (const gvm_hosts_t *hosts)
{
return hosts ? hosts->duplicated : 0;
}

/**
* @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
Expand Down
4 changes: 4 additions & 0 deletions base/hosts.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ struct gvm_hosts
size_t current; /**< Current host index in iteration. */
size_t count; /**< Number of single host objects in hosts list. */
size_t removed; /**< Number of duplicate/excluded values. */
size_t duplicated; /**< Number of duplicated values. */
};

/* Function prototypes. */
Expand Down Expand Up @@ -149,6 +150,9 @@ gvm_hosts_count (const gvm_hosts_t *);
unsigned int
gvm_hosts_removed (const gvm_hosts_t *);

unsigned int
gvm_hosts_duplicated (const gvm_hosts_t *);

/* gvm_host_t related */

gvm_host_t *
Expand Down