diff --git a/sys/netinet/in.c b/sys/netinet/in.c --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -441,6 +441,27 @@ return (error); } +int +in_mask2len(struct in_addr *mask) +{ + int x, y; + u_char *p; + + p = (u_char *)mask; + for (x = 0; x < sizeof(*mask); x++) { + if (p[x] != 0xff) + break; + } + y = 0; + if (x < sizeof(*mask)) { + for (y = 0; y < 8; y++) { + if ((p[x] & (0x80 >> y)) == 0) + break; + } + } + return (x * 8 + y); +} + int in_control(struct socket *so, u_long cmd, void *data, struct ifnet *ifp, struct thread *td) diff --git a/sys/netinet/in_var.h b/sys/netinet/in_var.h --- a/sys/netinet/in_var.h +++ b/sys/netinet/in_var.h @@ -459,6 +459,7 @@ int in_leavegroup(struct in_multi *, /*const*/ struct in_mfilter *); int in_leavegroup_locked(struct in_multi *, /*const*/ struct in_mfilter *); +int in_mask2len(struct in_addr *); int in_control(struct socket *, u_long, void *, struct ifnet *, struct thread *); int in_control_ioctl(u_long, void *, struct ifnet *,