Skip to content

Commit

Permalink
Have NetBlock::next return the socklen.
Browse files Browse the repository at this point in the history
This matters on OS X; with the wrong size, connect scans give "Invalid
argument".
Reported by Jesper Kückelhahn.
http://seclists.org/nmap-dev/2013/q1/84
  • Loading branch information
david committed Jan 26, 2013
1 parent 010969b commit 249c566
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
8 changes: 5 additions & 3 deletions TargetGroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ NetBlockIPv4Ranges::NetBlockIPv4Ranges() {
}
}

bool NetBlockIPv4Ranges::next(struct sockaddr_storage *ss) {
bool NetBlockIPv4Ranges::next(struct sockaddr_storage *ss, size_t *sslen) {
struct sockaddr_in *sin;
unsigned int i;

Expand All @@ -303,6 +303,7 @@ bool NetBlockIPv4Ranges::next(struct sockaddr_storage *ss) {
sin->sin_len = sizeof(*sin);
#endif
sin->sin_addr.s_addr = htonl((this->counter[0] << 24) | (this->counter[1] << 16) | (this->counter[2] << 8) | this->counter[3]);
*sslen = sizeof(*sin);

for (i = 0; i < 4; i++) {
bool carry;
Expand Down Expand Up @@ -451,7 +452,7 @@ static bool ipv6_equal(const struct in6_addr *a, const struct in6_addr *b) {
return memcmp(a->s6_addr, b->s6_addr, 16) == 0;
}

bool NetBlockIPv6Netmask::next(struct sockaddr_storage *ss) {
bool NetBlockIPv6Netmask::next(struct sockaddr_storage *ss, size_t *sslen) {
struct sockaddr_in6 *sin6;

if (this->exhausted)
Expand All @@ -463,6 +464,7 @@ bool NetBlockIPv6Netmask::next(struct sockaddr_storage *ss) {
#ifdef SIN_LEN
sin6->sin6_len = sizeof(*sin6);
#endif
*sslen = sizeof(*sin6);

if (this->addr.sin6_scope_id != 0)
sin6->sin6_scope_id = this->addr.sin6_scope_id;
Expand Down Expand Up @@ -631,7 +633,7 @@ NetBlockHostname::NetBlockHostname(const char *hostname, int af) {
this->bits = -1;
}

bool NetBlockHostname::next(struct sockaddr_storage *ss) {
bool NetBlockHostname::next(struct sockaddr_storage *ss, size_t *sslen) {
assert(false);
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions TargetGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class NetBlock {

bool is_resolved_address(const struct sockaddr_storage *ss) const;

virtual bool next(struct sockaddr_storage *ss) = 0;
virtual bool next(struct sockaddr_storage *ss, size_t *sslen) = 0;
virtual void apply_netmask(int bits) = 0;
virtual std::string str() const = 0;
};
Expand All @@ -137,7 +137,7 @@ class NetBlockIPv4Ranges : public NetBlock {

NetBlockIPv4Ranges();

bool next(struct sockaddr_storage *ss);
bool next(struct sockaddr_storage *ss, size_t *sslen);
void apply_netmask(int bits);
std::string str() const;

Expand All @@ -149,7 +149,7 @@ class NetBlockIPv6Netmask : public NetBlock {
public:
void set_addr(const struct sockaddr_in6 *addr);

bool next(struct sockaddr_storage *ss);
bool next(struct sockaddr_storage *ss, size_t *sslen);
void apply_netmask(int bits);
std::string str() const;

Expand All @@ -169,7 +169,7 @@ class NetBlockHostname : public NetBlock {

NetBlock *resolve() const;

bool next(struct sockaddr_storage *ss);
bool next(struct sockaddr_storage *ss, size_t *sslen);
void apply_netmask(int bits);
std::string str() const;
};
Expand Down
3 changes: 1 addition & 2 deletions targets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ int TargetGroup::get_next_host(struct sockaddr_storage *ss, size_t *sslen) {
delete netblock_hostname;
}

*sslen = sizeof(*ss);
if (this->netblock->next(ss))
if (this->netblock->next(ss, sslen))
return 0;
else
return -1;
Expand Down

0 comments on commit 249c566

Please sign in to comment.