| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #ifndef BSSL_PKI_IP_UTIL_H_ |
| 16 | #define BSSL_PKI_IP_UTIL_H_ |
| 17 |
| 18 | #include <openssl/base.h> |
| 19 |
| 20 | #include "input.h" |
| 21 |
| 22 | BSSL_NAMESPACE_BEGIN |
| 23 |
| 24 | inline constexpr size_t kIPv4AddressSize = 4; |
| 25 | inline constexpr size_t kIPv6AddressSize = 16; |
| 26 |
| 27 | // Returns whether `mask` is a valid netmask. I.e., whether it is the length of |
| 28 | // an IPv4 or IPv6 address, and is some number of ones, followed by some number |
| 29 | // of zeros. |
| 30 | OPENSSL_EXPORT bool IsValidNetmask(der::Input mask); |
| 31 |
| 32 | // Returns whether `addr1` and `addr2` are equal under the netmask `mask`. |
| 33 | OPENSSL_EXPORT bool IPAddressMatchesWithNetmask(der::Input addr1, |
| 34 | der::Input addr2, |
| 35 | der::Input mask); |
| 36 |
| 37 | BSSL_NAMESPACE_END |
| 38 |
| 39 | #endif // BSSL_PKI_IP_UTIL_H_ |
| 40 |