diff --git a/targets.cc b/targets.cc index 513adf9b5..3ccc9d4c2 100644 --- a/targets.cc +++ b/targets.cc @@ -346,6 +346,20 @@ int TargetGroup::get_next_host(struct sockaddr_storage *ss, size_t *sslen) { delete netblock_hostname; } + /* Check for proper address family. Give a specific error message for IPv6 + specifications appearing in IPv4 mode. */ + if (o.af() == AF_INET && dynamic_cast(this->netblock) != NULL) { + error("%s looks like an IPv6 target specification -- you have to use the -6 option.", + this->netblock->str().c_str()); + return -1; + } + if ((o.af() == AF_INET && dynamic_cast(this->netblock) == NULL) || + (o.af() == AF_INET6 && dynamic_cast(this->netblock) == NULL)) { + error("Address family mismatch in target specification \"%s\".", + this->netblock->str().c_str()); + return -1; + } + if (this->netblock->next(ss, sslen)) return 0; else @@ -552,6 +566,8 @@ tryagain: goto tryagain; } + assert(ss.ss_family == o.af()); + /* If we are resuming from a previous scan, we have already finished scanning up to o.resume_ip. */ if (ss.ss_family == AF_INET && o.resume_ip.s_addr) {