Remove the unused parse_addr_and_port_range

This commit is contained in:
Nick Mathewson 2013-03-01 14:35:17 -05:00
parent f6697d5b3b
commit 24fb926726
2 changed files with 0 additions and 90 deletions

View File

@ -1643,93 +1643,6 @@ parse_port_range(const char *port, uint16_t *port_min_out,
return 0;
}
/** Parse a string <b>s</b> in the format of
* (IP(/mask|/mask-bits)?|*)(:(*|port(-maxport))?)?, setting the various
* *out pointers as appropriate. Return 0 on success, -1 on failure.
*/
int
parse_addr_and_port_range(const char *s, uint32_t *addr_out,
maskbits_t *maskbits_out, uint16_t *port_min_out,
uint16_t *port_max_out)
{
char *address;
char *mask, *port, *endptr;
struct in_addr in;
int bits;
tor_assert(s);
tor_assert(addr_out);
tor_assert(maskbits_out);
tor_assert(port_min_out);
tor_assert(port_max_out);
address = tor_strdup(s);
/* Break 'address' into separate strings.
*/
mask = strchr(address,'/');
port = strchr(mask?mask:address,':');
if (mask)
*mask++ = '\0';
if (port)
*port++ = '\0';
/* Now "address" is the IP|'*' part...
* "mask" is the Mask|Maskbits part...
* and "port" is the *|port|min-max part.
*/
if (strcmp(address,"*")==0) {
*addr_out = 0;
} else if (tor_inet_aton(address, &in) != 0) {
*addr_out = ntohl(in.s_addr);
} else {
log_warn(LD_GENERAL, "Malformed IP %s in address pattern; rejecting.",
escaped(address));
goto err;
}
if (!mask) {
if (strcmp(address,"*")==0)
*maskbits_out = 0;
else
*maskbits_out = 32;
} else {
endptr = NULL;
bits = (int) strtol(mask, &endptr, 10);
if (!*endptr) {
/* strtol handled the whole mask. */
if (bits < 0 || bits > 32) {
log_warn(LD_GENERAL,
"Bad number of mask bits on address range; rejecting.");
goto err;
}
*maskbits_out = bits;
} else if (tor_inet_aton(mask, &in) != 0) {
bits = addr_mask_get_bits(ntohl(in.s_addr));
if (bits < 0) {
log_warn(LD_GENERAL,
"Mask %s on address range isn't a prefix; dropping",
escaped(mask));
goto err;
}
*maskbits_out = bits;
} else {
log_warn(LD_GENERAL,
"Malformed mask %s on address range; rejecting.",
escaped(mask));
goto err;
}
}
if (parse_port_range(port, port_min_out, port_max_out)<0)
goto err;
tor_free(address);
return 0;
err:
tor_free(address);
return -1;
}
/** Given an IPv4 in_addr struct *<b>in</b> (in network order, as usual),
* write it as a string into the <b>buf_len</b>-byte buffer in
* <b>buf</b>.

View File

@ -219,9 +219,6 @@ int addr_port_lookup(int severity, const char *addrport, char **address,
uint32_t *addr, uint16_t *port_out);
int parse_port_range(const char *port, uint16_t *port_min_out,
uint16_t *port_max_out);
int parse_addr_and_port_range(const char *s, uint32_t *addr_out,
maskbits_t *maskbits_out, uint16_t *port_min_out,
uint16_t *port_max_out);
int addr_mask_get_bits(uint32_t mask);
int addr_mask_cmp_bits(uint32_t a1, uint32_t a2, maskbits_t bits);
/** Length of a buffer to allocate to hold the results of tor_inet_ntoa.*/