Skip to content

Commit

Permalink
Simplify AF checking for literal IP addresses.
Browse files Browse the repository at this point in the history
  • Loading branch information
bonsaiviking committed Aug 3, 2017
1 parent a24a02b commit d5e7649
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
4 changes: 4 additions & 0 deletions TargetGroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ static NetBlock *parse_expr_without_netmask(const char *hostexp, int af) {

sslen = sizeof(ss);
if (resolve_numeric(hostexp, 0, &ss, &sslen, AF_INET6) == 0) {
if (af != AF_INET6) {
error("%s looks like an IPv6 target specification -- you have to use the -6 option.", hostexp);
return NULL;
}
NetBlockIPv6Netmask *netblock_ipv6;

netblock_ipv6 = new NetBlockIPv6Netmask();
Expand Down
14 changes: 0 additions & 14 deletions targets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -395,20 +395,6 @@ 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<NetBlockIPv6Netmask *>(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<NetBlockIPv4Ranges *>(this->netblock) == NULL) ||
(o.af() == AF_INET6 && dynamic_cast<NetBlockIPv6Netmask *>(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
Expand Down

0 comments on commit d5e7649

Please sign in to comment.