Skip to content

Commit

Permalink
Move some private classes to TargetGroup.cc from TargetGroup.h
Browse files Browse the repository at this point in the history
  • Loading branch information
bonsaiviking committed Aug 5, 2017
1 parent 0ef9cc7 commit f5d29c4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 52 deletions.
51 changes: 51 additions & 0 deletions TargetGroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,64 @@

#include <sstream>
#include <errno.h>
#include <limits.h> // CHAR_BIT

/* We use bit vectors to represent what values are allowed in an IPv4 octet.
Each vector is built up of an array of bitvector_t (any convenient integer
type). */
typedef unsigned long bitvector_t;
/* A 256-element bit vector, representing legal values for one octet. */
typedef bitvector_t octet_bitvector[(256 - 1) / (sizeof(unsigned long) * CHAR_BIT) + 1];

#define BITVECTOR_BITS (sizeof(bitvector_t) * CHAR_BIT)
#define BIT_SET(v, n) ((v)[(n) / BITVECTOR_BITS] |= 1UL << ((n) % BITVECTOR_BITS))
#define BIT_IS_SET(v, n) (((v)[(n) / BITVECTOR_BITS] & 1UL << ((n) % BITVECTOR_BITS)) != 0)

extern NmapOps o;

class NetBlockIPv4Ranges : public NetBlock {
public:
octet_bitvector octets[4];

NetBlockIPv4Ranges();

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

private:
unsigned int counter[4];
};

class NetBlockIPv6Netmask : public NetBlock {
public:
void set_addr(const struct sockaddr_in6 *addr);

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

private:
bool exhausted;
struct sockaddr_in6 addr;
struct in6_addr start;
struct in6_addr cur;
struct in6_addr end;
};

class NetBlockHostname : public NetBlock {
public:
NetBlockHostname(const char *hostname, int af);
int af;
int bits;

NetBlock *resolve();

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

NewTargets *NewTargets::new_targets;

/* Return a newly allocated string containing the part of expr up to the last
Expand Down
52 changes: 0 additions & 52 deletions TargetGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,11 @@
#ifndef TARGETGROUP_H
#define TARGETGROUP_H

#include <limits.h>

#include <list>
#include <queue>
#include <set>
#include <string>

/* We use bit vectors to represent what values are allowed in an IPv4 octet.
Each vector is built up of an array of bitvector_t (any convenient integer
type). */
typedef unsigned long bitvector_t;
/* A 256-element bit vector, representing legal values for one octet. */
typedef bitvector_t octet_bitvector[(256 - 1) / (sizeof(unsigned long) * CHAR_BIT) + 1];

class NetBlock {
public:
virtual ~NetBlock() {}
Expand All @@ -172,49 +163,6 @@ class NetBlock {
virtual std::string str() const = 0;
};

class NetBlockIPv4Ranges : public NetBlock {
public:
octet_bitvector octets[4];

NetBlockIPv4Ranges();

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

private:
unsigned int counter[4];
};

class NetBlockIPv6Netmask : public NetBlock {
public:
void set_addr(const struct sockaddr_in6 *addr);

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

private:
bool exhausted;
struct sockaddr_in6 addr;
struct in6_addr start;
struct in6_addr cur;
struct in6_addr end;
};

class NetBlockHostname : public NetBlock {
public:
NetBlockHostname(const char *hostname, int af);
int af;
int bits;

NetBlock *resolve();

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

/* Adding new targets is for NSE scripts */
class NewTargets {
public:
Expand Down

0 comments on commit f5d29c4

Please sign in to comment.