---
name: "ipsec_goodmask"
section: "3"
platform: "linux"
package: "openswan"
version: "1:2.6.37-3+deb7u1"
release: "Debian 7 (Wheezy)"
platforms: ["linux"]
url: "https://new.carta.tech/ipsec_goodmask"
---

# ipsec\_goodmask(3)

check if Internet subnet mask is valid, convert Internet subnet mask to bit count, convert bit count to Internet subnet mask

## NAME

ipsec\_goodmask, ipsec\_masktobits, ipsec\_bitstomask - check if Internet subnet mask is valid, convert Internet subnet mask to bit count, convert bit count to Internet subnet mask

## SYNOPSIS

**#include \<freeswan.h\>**

**int goodmask(struct in\_addr mask);**\
 **int masktobits(struct in\_addr mask);**\
 **struct in\_addr bitstomask(int n);**

## DESCRIPTION

These functions are obsolete; see [*ipsec\_masktocount*(3)](/ipsec_masktocount/3.md) for a partial replacement.

*Goodmask* reports whether the subnet *mask* is a valid one, i.e. consists of a (possibly empty) sequence of **1**s followed by a (possibly empty) sequence of **0**s. *Masktobits* takes a (valid) subnet mask and returns the number of **1** bits in it. *Bitstomask* reverses this, returning the subnet mask corresponding to bit count *n*.

All masks are in network byte order.

## SEE ALSO

[inet(3)](/inet/3.md), [ipsec\_atosubnet(3)](/ipsec_atosubnet/3.md)

## DIAGNOSTICS

*Masktobits* returns **-1** for an invalid mask. *Bitstomask* returns an all-zeros mask for a negative or out-of-range *n*.

## HISTORY

Written for the FreeS/WAN project by Henry Spencer.

## BUGS

The error-reporting convention of *bitstomask* is less than ideal; zero is sometimes a legitimate mask.
