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:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
17
targets.cc
17
targets.cc
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user