version 1.1, 2012/02/21 23:32:47
|
version 1.1.1.3, 2021/03/17 00:39:23
|
Line 16
|
Line 16
|
*/ |
*/ |
|
|
int |
int |
IpShowRoutes(Context ctx, int ac, char *av[], void *arg) | IpShowRoutes(Context ctx, int ac, const char *const av[], const void *arg) |
{ |
{ |
FILE *fp; |
FILE *fp; |
char buf[256]; |
char buf[256]; |
char *c; |
char *c; |
|
|
|
(void)ac; |
|
(void)av; |
|
(void)arg; |
|
|
if ((fp = popen(PATH_NETSTAT " -nr -f inet", "r")) == NULL) |
if ((fp = popen(PATH_NETSTAT " -nr -f inet", "r")) == NULL) |
{ |
{ |
Perror("popen"); |
Perror("popen"); |
Line 179 ParseRange(const char *s, struct u_range *range, u_cha
|
Line 183 ParseRange(const char *s, struct u_range *range, u_cha
|
*/ |
*/ |
|
|
struct sockaddr_storage * |
struct sockaddr_storage * |
ParseAddrPort(int ac, char *av[], u_char allow) | ParseAddrPort(int ac, const char *const av[], u_char allow) |
{ |
{ |
static struct sockaddr_storage ss; |
static struct sockaddr_storage ss; |
struct u_addr addr; |
struct u_addr addr; |
Line 258 char *u_rangetoa(struct u_range *range, char *dst, s
|
Line 262 char *u_rangetoa(struct u_range *range, char *dst, s
|
return dst; |
return dst; |
} |
} |
|
|
struct u_addr *u_addrcopy(const struct u_addr *src, struct u_addr *dst) | void u_addrcopy(const struct u_addr *src, struct u_addr *dst) |
{ |
{ |
return memcpy(dst,src,sizeof(struct u_addr)); | memcpy(dst,src,sizeof(struct u_addr)); |
} |
} |
|
|
struct u_addr *u_rangecopy(const struct u_range *src, struct u_range *dst) | void u_rangecopy(const struct u_range *src, struct u_range *dst) |
{ |
{ |
return memcpy(dst,src,sizeof(struct u_range)); | memcpy(dst,src,sizeof(struct u_range)); |
} |
} |
|
|
struct u_addr *u_addrclear(struct u_addr *addr) | void u_addrclear(struct u_addr *addr) |
{ |
{ |
memset(addr,0,sizeof(struct u_addr)); |
memset(addr,0,sizeof(struct u_addr)); |
return addr; |
|
} |
} |
|
|
struct u_range *u_rangeclear(struct u_range *range) | void u_rangeclear(struct u_range *range) |
{ |
{ |
memset(range,0,sizeof(struct u_range)); |
memset(range,0,sizeof(struct u_range)); |
return range; |
|
} |
} |
|
|
struct u_addr *in_addrtou_addr(const struct in_addr *src, struct u_addr *dst) | void in_addrtou_addr(const struct in_addr *src, struct u_addr *dst) |
{ |
{ |
u_addrclear(dst); |
u_addrclear(dst); |
dst->family=AF_INET; |
dst->family=AF_INET; |
dst->u.ip4=*src; |
dst->u.ip4=*src; |
return dst; |
|
} |
} |
|
|
struct u_addr *in6_addrtou_addr(const struct in6_addr *src, struct u_addr *dst) | void in6_addrtou_addr(const struct in6_addr *src, struct u_addr *dst) |
{ |
{ |
u_addrclear(dst); |
u_addrclear(dst); |
dst->family=AF_INET6; |
dst->family=AF_INET6; |
dst->u.ip6=*src; |
dst->u.ip6=*src; |
return dst; |
|
} |
} |
|
|
struct in_addr *u_addrtoin_addr(const struct u_addr *src, struct in_addr *dst) | void u_addrtoin_addr(const struct u_addr *src, struct in_addr *dst) |
{ |
{ |
*dst=src->u.ip4; |
*dst=src->u.ip4; |
return dst; |
|
} |
} |
|
|
struct in6_addr *u_addrtoin6_addr(const struct u_addr *src, struct in6_addr *dst) | void u_addrtoin6_addr(const struct u_addr *src, struct in6_addr *dst) |
{ |
{ |
*dst=src->u.ip6; |
*dst=src->u.ip6; |
return dst; |
|
} |
} |
|
|
struct u_range *in_addrtou_range(const struct in_addr *src, u_char width, struct u_range *dst) | void in_addrtou_range(const struct in_addr *src, u_char width, struct u_range *dst) |
{ |
{ |
u_rangeclear(dst); |
u_rangeclear(dst); |
in_addrtou_addr(src, &dst->addr); |
in_addrtou_addr(src, &dst->addr); |
dst->width = width; |
dst->width = width; |
return dst; |
|
} |
} |
|
|
struct u_range *in6_addrtou_range(const struct in6_addr *src, u_char width, struct u_range *dst) | void in6_addrtou_range(const struct in6_addr *src, u_char width, struct u_range *dst) |
{ |
{ |
u_rangeclear(dst); |
u_rangeclear(dst); |
in6_addrtou_addr(src, &dst->addr); |
in6_addrtou_addr(src, &dst->addr); |
dst->width = width; |
dst->width = width; |
return dst; |
|
} |
} |
|
|
int u_addrempty(struct u_addr *addr) |
int u_addrempty(struct u_addr *addr) |
Line 382 bits2mask6(int bits)
|
Line 378 bits2mask6(int bits)
|
return result; |
return result; |
} |
} |
|
|
struct sockaddr_storage *u_rangetosockaddrs(struct u_range *range, struct sockaddr_storage *dst, struct sockaddr_storage *msk) | void u_rangetosockaddrs(struct u_range *range, struct sockaddr_storage *dst, struct sockaddr_storage *msk) |
{ |
{ |
memset(dst,0,sizeof(struct sockaddr_storage)); |
memset(dst,0,sizeof(struct sockaddr_storage)); |
memset(msk,0,sizeof(struct sockaddr_storage)); |
memset(msk,0,sizeof(struct sockaddr_storage)); |
Line 404 struct sockaddr_storage *u_rangetosockaddrs(struct u_r
|
Line 400 struct sockaddr_storage *u_rangetosockaddrs(struct u_r
|
dst->ss_len=sizeof(struct sockaddr_storage); |
dst->ss_len=sizeof(struct sockaddr_storage); |
break; |
break; |
} |
} |
return dst; |
|
} |
} |
|
|
struct sockaddr_storage *u_addrtosockaddr(struct u_addr *addr, in_port_t port, struct sockaddr_storage *dst) | void u_addrtosockaddr(struct u_addr *addr, in_port_t port, struct sockaddr_storage *dst) |
{ |
{ |
memset(dst,0,sizeof(struct sockaddr_storage)); |
memset(dst,0,sizeof(struct sockaddr_storage)); |
dst->ss_family=addr->family; |
dst->ss_family=addr->family; |
Line 426 struct sockaddr_storage *u_addrtosockaddr(struct u_add
|
Line 421 struct sockaddr_storage *u_addrtosockaddr(struct u_add
|
dst->ss_len=sizeof(struct sockaddr_storage); |
dst->ss_len=sizeof(struct sockaddr_storage); |
break; |
break; |
} |
} |
return dst; |
|
} |
} |
|
|
void sockaddrtou_addr(struct sockaddr_storage *src, struct u_addr *addr, in_port_t *port) |
void sockaddrtou_addr(struct sockaddr_storage *src, struct u_addr *addr, in_port_t *port) |
Line 497 u_addrtoid(const struct u_addr *addr)
|
Line 491 u_addrtoid(const struct u_addr *addr)
|
if (addr->family==AF_INET) { |
if (addr->family==AF_INET) { |
id = ntohl(addr->u.ip4.s_addr); |
id = ntohl(addr->u.ip4.s_addr); |
} else if (addr->family==AF_INET6) { |
} else if (addr->family==AF_INET6) { |
uint32_t *a32 = (uint32_t *)(&addr->u.ip6.s6_addr[0]); | const uint32_t *a32 = (const uint32_t *)(const void *)(&addr->u.ip6.s6_addr[0]); |
id = a32[0] + a32[1] + a32[2] + a32[3]; |
id = a32[0] + a32[1] + a32[2] + a32[3]; |
} else { |
} else { |
id = 0; |
id = 0; |