Skip to content

Commit

Permalink
Separate duplicated hosts from removed hosts in the hosts structure.
Browse files Browse the repository at this point in the history
Also add a function to access this variable directly.
  • Loading branch information
jjnicola committed Aug 21, 2020
1 parent a03eec1 commit b0f08d8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
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. [#287](https://github.com/greenbone/gvm-libs/pull/287)

[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

0 comments on commit b0f08d8

Please sign in to comment.