mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-01-05 11:39:33 +00:00
MINOR: standard: Add function for converting cidr to network mask.
This commit is contained in:
parent
0e9af55700
commit
b050463375
@ -237,6 +237,11 @@ struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high, char
|
||||
*/
|
||||
int str2mask(const char *str, struct in_addr *mask);
|
||||
|
||||
/* convert <cidr> to struct in_addr <mask>. It returns 1 if the conversion
|
||||
* succeeds otherwise non-zero.
|
||||
*/
|
||||
int cidr2dotted(int cidr, struct in_addr *mask);
|
||||
|
||||
/*
|
||||
* converts <str> to two struct in_addr* which must be pre-allocated.
|
||||
* The format is "addr[/mask]", where "addr" cannot be empty, and mask
|
||||
|
@ -791,6 +791,18 @@ int str2mask(const char *str, struct in_addr *mask)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* convert <cidr> to struct in_addr <mask>. It returns 1 if the conversion
|
||||
* succeeds otherwise zero.
|
||||
*/
|
||||
int cidr2dotted(int cidr, struct in_addr *mask) {
|
||||
|
||||
if (cidr < 0 || cidr > 32)
|
||||
return 0;
|
||||
|
||||
mask->s_addr = cidr ? htonl(~0UL << (32 - cidr)) : 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* converts <str> to two struct in_addr* which must be pre-allocated.
|
||||
* The format is "addr[/mask]", where "addr" cannot be empty, and mask
|
||||
|
Loading…
Reference in New Issue
Block a user