1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-23 22:59:20 +00:00

Simplify get_next_host and name resolution.

This commit is contained in:
dmiller
2017-08-04 02:05:20 +00:00
parent 0bc76dea8e
commit cde6853481
3 changed files with 14 additions and 12 deletions

View File

@@ -628,7 +628,7 @@ std::string NetBlockIPv6Netmask::str() const {
return result.str();
}
NetBlock *NetBlockHostname::resolve() const {
NetBlock *NetBlockHostname::resolve() {
struct addrinfo *addrs, *addr;
std::list<struct sockaddr_storage> resolvedaddrs;
NetBlock *netblock;

View File

@@ -162,6 +162,11 @@ public:
bool is_resolved_address(const struct sockaddr_storage *ss) const;
/* For NetBlock subclasses that need to "resolve" themselves into a different
* NetBlock subclass, override this method. Otherwise, it's safe to reassign
* the return value to the pointer that this method was called through.
* On error, return NULL. */
virtual NetBlock *resolve() { return this; }
virtual bool next(struct sockaddr_storage *ss, size_t *sslen) = 0;
virtual void apply_netmask(int bits) = 0;
virtual std::string str() const = 0;
@@ -203,7 +208,7 @@ public:
int af;
int bits;
NetBlock *resolve() const;
NetBlock *resolve();
bool next(struct sockaddr_storage *ss, size_t *sslen);
void apply_netmask(int bits);

View File

@@ -383,16 +383,13 @@ int TargetGroup::get_next_host(struct sockaddr_storage *ss, size_t *sslen) {
hostname, without doing local DNS resolution (like with a proxy scan), this
has to be made conditional (and perhaps an error if the netmask doesn't
limit it to exactly one address). */
NetBlockHostname *netblock_hostname;
netblock_hostname = dynamic_cast<NetBlockHostname *>(this->netblock);
if (netblock_hostname != NULL) {
this->netblock = netblock_hostname->resolve();
if (this->netblock == NULL) {
error("Failed to resolve \"%s\".", netblock_hostname->hostname.c_str());
delete netblock_hostname;
return -1;
}
delete netblock_hostname;
NetBlock *netblock_resolved = this->netblock->resolve();
if (netblock_resolved != NULL) {
this->netblock = netblock_resolved;
}
else {
error("Failed to resolve \"%s\".", this->netblock->hostname.c_str());
return -1;
}
if (this->netblock->next(ss, sslen))