1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Merge r30416:30527 from /nmap-exp/david/ipv6-ranges.

This is a refactoring of target parsing that stores different types of
target specifications as different classes. The eventual intention is to
allow easy iteration over each specification for the purpose of IPv6
multicast host discovery.
This commit is contained in:
david
2013-01-22 00:01:08 +00:00
parent d04f16eb32
commit e1fba2d663
8 changed files with 813 additions and 652 deletions

View File

@@ -118,8 +118,66 @@
#include "nmap.h"
#include "global_structures.h"
#include "TargetGroup.h"
class HostGroupState;
class TargetGroup {
public:
NetBlock *netblock;
struct sockaddr_storage pushback;
TargetGroup() {
this->netblock = NULL;
this->pushback.ss_family = AF_UNSPEC;
}
~TargetGroup() {
if (this->netblock != NULL)
delete this->netblock;
}
/* Initializes (or reinitializes) the object with a new expression,
such as 192.168.0.0/16 , 10.1.0-5.1-254 , or
fe80::202:e3ff:fe14:1102 . The af parameter is AF_INET or
AF_INET6 Returns 0 for success */
int parse_expr(const char *target_expr, int af);
/* Grab the next host from this expression (if any). Returns 0 and
fills in ss if successful. ss must point to a pre-allocated
sockaddr_storage structure */
int get_next_host(struct sockaddr_storage *ss, size_t *sslen);
/* Returns the given host, so that it will be given the next time
get_next_host is called. Does nothing if ss is NULL. */
void return_host(const struct sockaddr_storage *ss);
/* Returns true iff the given address is the one that was resolved to create
this target group; i.e., not one of the addresses derived from it with a
netmask. */
bool is_resolved_address(const struct sockaddr_storage *ss) const;
/* Return a string of the name or address that was resolved for this group. */
const char *get_resolved_name(void) const;
/* Return the list of addresses that the name for this group resolved to, if
it came from a name resolution. */
const std::list<struct sockaddr_storage> &get_resolved_addrs(void) const;
/* is the current expression a named host */
int get_namedhost() const;
};
class HostGroupState {
public:
HostGroupState(int lookahead, int randomize, int argc, const char *argv[]);
~HostGroupState();
Target **hostbatch;
int argc;
const char **argv;
int max_batch_sz; /* The size of the hostbatch[] array */
int current_batch_sz; /* The number of VALID members of hostbatch[] */
int next_batch_no; /* The index of the next hostbatch[] member to be given
back to the user */
int randomize; /* Whether each batch should be "shuffled" prior to the ping
scan (they will also be out of order when given back one
at a time to the client program */
TargetGroup current_group; /* For batch chunking -- targets in queue */
const char *next_expression();
};
/* Ports is the list of ports the user asked to be scanned (0 terminated),
you can just pass NULL (it is only a stupid optimization that needs it) */