mirror of
https://github.com/nmap/nmap.git
synced 2025-12-10 07:31:33 +00:00
Formatting in TargetGroup.{cc,h}.
astyle -a -p -H -s2 -m2 TargetGroup.cc TargetGroup.h
This commit is contained in:
@@ -166,7 +166,7 @@ int TargetGroup::parse_expr(const char *target_expr, int af) {
|
|||||||
} else
|
} else
|
||||||
netmask = 32;
|
netmask = 32;
|
||||||
resolvedname = hostexp;
|
resolvedname = hostexp;
|
||||||
for(i=0; hostexp[i] != '\0'; i++)
|
for (i = 0; hostexp[i]; i++)
|
||||||
if (isupper((int) (unsigned char) hostexp[i]) ||
|
if (isupper((int) (unsigned char) hostexp[i]) ||
|
||||||
islower((int) (unsigned char) hostexp[i])) {
|
islower((int) (unsigned char) hostexp[i])) {
|
||||||
namedhost = 1;
|
namedhost = 1;
|
||||||
@@ -223,8 +223,7 @@ int TargetGroup::parse_expr(const char *target_expr, int af) {
|
|||||||
fprintf(stderr, "Host specification invalid");
|
fprintf(stderr, "Host specification invalid");
|
||||||
free(hostexp);
|
free(hostexp);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
targets_type = IPV4_RANGES;
|
targets_type = IPV4_RANGES;
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
@@ -232,8 +231,7 @@ int TargetGroup::parse_expr(const char *target_expr, int af) {
|
|||||||
if (*r == '.' && ++i < 4) {
|
if (*r == '.' && ++i < 4) {
|
||||||
*r = '\0';
|
*r = '\0';
|
||||||
addy[i] = r + 1;
|
addy[i] = r + 1;
|
||||||
}
|
} else if (*r != '*' && *r != ',' && *r != '-' && !isdigit((int) (unsigned char) *r)) {
|
||||||
else if (*r != '*' && *r != ',' && *r != '-' && !isdigit((int) (unsigned char) *r)) {
|
|
||||||
error("Invalid character in host specification: %s. Note in particular that square brackets [] are no longer allowed. They were redundant and can simply be removed.", target_expr);
|
error("Invalid character in host specification: %s. Note in particular that square brackets [] are no longer allowed. They were redundant and can simply be removed.", target_expr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -249,13 +247,14 @@ int TargetGroup::parse_expr(const char *target_expr, int af) {
|
|||||||
do {
|
do {
|
||||||
s = strchr(addy[i], ',');
|
s = strchr(addy[i], ',');
|
||||||
if (s) *s = '\0';
|
if (s) *s = '\0';
|
||||||
if (*addy[i] == '*') { start = 0; end = 255; }
|
if (*addy[i] == '*') {
|
||||||
else if (*addy[i] == '-') {
|
start = 0;
|
||||||
|
end = 255;
|
||||||
|
} else if (*addy[i] == '-') {
|
||||||
start = 0;
|
start = 0;
|
||||||
if (*(addy[i] + 1) == '\0') end = 255;
|
if (*(addy[i] + 1) == '\0') end = 255;
|
||||||
else end = atoi(addy[i] + 1);
|
else end = atoi(addy[i] + 1);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
start = end = atoi(addy[i]);
|
start = end = atoi(addy[i]);
|
||||||
if ((r = strchr(addy[i], '-')) && *(r + 1) ) end = atoi(r + 1);
|
if ((r = strchr(addy[i], '-')) && *(r + 1) ) end = atoi(r + 1);
|
||||||
else if (r && !*(r + 1)) end = 255;
|
else if (r && !*(r + 1)) end = 255;
|
||||||
@@ -282,8 +281,7 @@ int TargetGroup::parse_expr(const char *target_expr, int af) {
|
|||||||
(unsigned long long) (last[1] + 1) *
|
(unsigned long long) (last[1] + 1) *
|
||||||
(unsigned long long) (last[2] + 1) *
|
(unsigned long long) (last[2] + 1) *
|
||||||
(unsigned long long) (last[3] + 1);
|
(unsigned long long) (last[3] + 1);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
#if HAVE_IPV6
|
#if HAVE_IPV6
|
||||||
struct addrinfo *addrs, *addr;
|
struct addrinfo *addrs, *addr;
|
||||||
struct sockaddr_storage ss;
|
struct sockaddr_storage ss;
|
||||||
@@ -383,8 +381,7 @@ int TargetGroup::skip_range(_octet_nums octet) {
|
|||||||
if (current[i] < last[i]) {
|
if (current[i] < last[i]) {
|
||||||
current[i]++;
|
current[i]++;
|
||||||
break;
|
break;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
current[i] = 0;
|
current[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,8 +443,7 @@ int TargetGroup::get_next_host(struct sockaddr_storage *ss, size_t *sslen) {
|
|||||||
ipsleft = 0;
|
ipsleft = 0;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
} else if (targets_type == IPV4_RANGES) {
|
||||||
else if (targets_type == IPV4_RANGES) {
|
|
||||||
memset(sin, 0, sizeof(struct sockaddr_in));
|
memset(sin, 0, sizeof(struct sockaddr_in));
|
||||||
sin->sin_family = AF_INET;
|
sin->sin_family = AF_INET;
|
||||||
*sslen = sizeof(struct sockaddr_in);
|
*sslen = sizeof(struct sockaddr_in);
|
||||||
@@ -479,8 +475,10 @@ int TargetGroup::get_next_host(struct sockaddr_storage *ss, size_t *sslen) {
|
|||||||
assert(ipsleft == 1);
|
assert(ipsleft == 1);
|
||||||
/* So I set current to last with the very final octet up one ... */
|
/* So I set current to last with the very final octet up one ... */
|
||||||
/* Note that this may make current[3] == 256 */
|
/* Note that this may make current[3] == 256 */
|
||||||
current[0] = last[0]; current[1] = last[1];
|
current[0] = last[0];
|
||||||
current[2] = last[2]; current[3] = last[3] + 1;
|
current[1] = last[1];
|
||||||
|
current[2] = last[2];
|
||||||
|
current[3] = last[3] + 1;
|
||||||
} else {
|
} else {
|
||||||
assert(ipsleft > 1); /* There must be at least one more IP left */
|
assert(ipsleft > 1); /* There must be at least one more IP left */
|
||||||
}
|
}
|
||||||
@@ -549,8 +547,7 @@ int TargetGroup::return_last_host() {
|
|||||||
/* Returns true iff the given address is the one that was resolved to create
|
/* 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
|
this target group; i.e., not one of the addresses derived from it with a
|
||||||
netmask. */
|
netmask. */
|
||||||
bool TargetGroup::is_resolved_address(const struct sockaddr_storage *ss)
|
bool TargetGroup::is_resolved_address(const struct sockaddr_storage *ss) {
|
||||||
{
|
|
||||||
struct sockaddr_storage resolvedaddr;
|
struct sockaddr_storage resolvedaddr;
|
||||||
|
|
||||||
if (resolvedaddrs.empty())
|
if (resolvedaddrs.empty())
|
||||||
@@ -565,15 +562,13 @@ bool TargetGroup::is_resolved_address(const struct sockaddr_storage *ss)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Return a string of the name or address that was resolved for this group. */
|
/* Return a string of the name or address that was resolved for this group. */
|
||||||
const char *TargetGroup::get_resolved_name(void)
|
const char *TargetGroup::get_resolved_name(void) {
|
||||||
{
|
|
||||||
return resolvedname.c_str();
|
return resolvedname.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the list of addresses that the name for this group resolved to, if
|
/* Return the list of addresses that the name for this group resolved to, if
|
||||||
it came from a name resolution. */
|
it came from a name resolution. */
|
||||||
const std::list<struct sockaddr_storage> &TargetGroup::get_resolved_addrs(void)
|
const std::list<struct sockaddr_storage> &TargetGroup::get_resolved_addrs(void) {
|
||||||
{
|
|
||||||
return resolvedaddrs;
|
return resolvedaddrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -611,12 +606,10 @@ unsigned long NewTargets::push (const char *target) {
|
|||||||
queue.push(tg);
|
queue.push(tg);
|
||||||
|
|
||||||
if (o.debugging > 2)
|
if (o.debugging > 2)
|
||||||
log_write(LOG_PLAIN, "New Targets: target %s pushed onto the queue.\n",
|
log_write(LOG_PLAIN, "New Targets: target %s pushed onto the queue.\n", tg.c_str());
|
||||||
tg.c_str());
|
|
||||||
} else {
|
} else {
|
||||||
if (o.debugging > 2)
|
if (o.debugging > 2)
|
||||||
log_write(LOG_PLAIN, "New Targets: target %s is already in the queue.\n",
|
log_write(LOG_PLAIN, "New Targets: target %s is already in the queue.\n", tg.c_str());
|
||||||
tg.c_str());
|
|
||||||
/* Return 1 when the target is already in the history cache,
|
/* Return 1 when the target is already in the history cache,
|
||||||
* this will prevent returning 0 when the target queue is
|
* this will prevent returning 0 when the target queue is
|
||||||
* empty since no target was added. */
|
* empty since no target was added. */
|
||||||
|
|||||||
@@ -136,11 +136,17 @@ class TargetGroup {
|
|||||||
it came from a name resolution. */
|
it came from a name resolution. */
|
||||||
const std::list<struct sockaddr_storage> &get_resolved_addrs(void);
|
const std::list<struct sockaddr_storage> &get_resolved_addrs(void);
|
||||||
/* return the target type */
|
/* return the target type */
|
||||||
char get_targets_type() {return targets_type;};
|
char get_targets_type() {
|
||||||
|
return targets_type;
|
||||||
|
};
|
||||||
/* get the netmask */
|
/* get the netmask */
|
||||||
int get_mask() {return netmask;};
|
int get_mask() {
|
||||||
|
return netmask;
|
||||||
|
};
|
||||||
/* is the current expression a named host */
|
/* is the current expression a named host */
|
||||||
int get_namedhost() {return namedhost;};
|
int get_namedhost() {
|
||||||
|
return namedhost;
|
||||||
|
};
|
||||||
/* Skip an octet in the range array */
|
/* Skip an octet in the range array */
|
||||||
int skip_range(_octet_nums octet);
|
int skip_range(_octet_nums octet);
|
||||||
private:
|
private:
|
||||||
@@ -166,11 +172,11 @@ class TargetGroup {
|
|||||||
unsigned int current[4];
|
unsigned int current[4];
|
||||||
u8 last[4];
|
u8 last[4];
|
||||||
|
|
||||||
/* Number of IPs left in this structure -- set to 0 if
|
/* Number of IPs left in this structure -- set to 0 if the fields are not
|
||||||
the fields are not valid */
|
valid */
|
||||||
unsigned long long ipsleft;
|
unsigned long long ipsleft;
|
||||||
|
|
||||||
// is the current target expression a named host
|
/* is the current target expression a named host? */
|
||||||
int namedhost;
|
int namedhost;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user