version 1.7, 2023/03/27 03:31:05 |
version 1.8, 2024/04/02 09:29:31 |
|
|
#include <string.h> |
#include <string.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <stdio.h> |
|
#include <limits.h> |
|
|
#include "addr.h" |
#include "addr.h" |
|
|
|
|
addr_pton_cidr(const char *p, struct xaddr *n, u_int *l) |
addr_pton_cidr(const char *p, struct xaddr *n, u_int *l) |
{ |
{ |
struct xaddr tmp; |
struct xaddr tmp; |
long unsigned int masklen = 999; |
u_int masklen = 999; |
char addrbuf[64], *mp, *cp; |
char addrbuf[64], *mp; |
|
const char *errstr; |
|
|
/* Don't modify argument */ |
/* Don't modify argument */ |
if (p == NULL || strlcpy(addrbuf, p, sizeof(addrbuf)) >= sizeof(addrbuf)) |
if (p == NULL || strlcpy(addrbuf, p, sizeof(addrbuf)) >= sizeof(addrbuf)) |
|
|
if ((mp = strchr(addrbuf, '/')) != NULL) { |
if ((mp = strchr(addrbuf, '/')) != NULL) { |
*mp = '\0'; |
*mp = '\0'; |
mp++; |
mp++; |
masklen = strtoul(mp, &cp, 10); |
masklen = (u_int)strtonum(mp, 0, INT_MAX, &errstr); |
if (*mp < '0' || *mp > '9' || *cp != '\0' || masklen > 128) |
if (errstr) |
return -1; |
return -1; |
} |
} |
|
|