---
name: "ipsec_sameaddr"
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_sameaddr"
---

# ipsec\_sameaddr(3)

do comparisons for addresses, subnets, SA IDs and address families

## NAME

ipsec\_sameaddr, ipsec\_addrcmp, ipsec\_samesubnet, ipsec\_addrinsubnet, ipsec\_subnetinsubnet, ipsec\_subnetishost, ipsec\_samesaid, ipsec\_sameaddrtype, ipsec\_samesubnettype - do comparisons for addresses, subnets, SA IDs and address families

## SYNOPSIS

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

**int sameaddr(const ip\_address \*a, const ip\_address \*b);**\
 **int addrcmp(const ip\_address \*a, const ip\_address \*b);**\
 **int samesubnet(const ip\_subnet \*a, const ip\_subnet \*b);**\
 **int addrinsubnet(const ip\_address \*a, const ip\_subnet \*s);**\
 **int subnetinsubnet(const ip\_subnet \*a, const ip\_subnet \*b);**\
 **int subnetishost(const ip\_subnet \*s);**\
 **int samesaid(const ip\_said \*a, const ip\_said \*b);**\
 **int sameaddrtype(const ip\_address \*a, const ip\_address \*b);**\
 **int samesubnettype(const ip\_subnet \*a, const ip\_subnet \*b);**

## DESCRIPTION

These functions do various comparisons and tests on the *ip\_address* type and *ip\_subnet* types.

*Sameaddr* returns non-zero if addresses *a* and *b* are identical, and **0** otherwise. Addresses of different families are never identical.

*Addrcmp* returns **-1**, **0**, or **1** respectively if address *a* is less than, equal to, or greater than *b*. If they are not of the same address family, they are never equal; the ordering reported in this case is arbitrary (and probably not useful) but consistent.

*Samesubnet* returns non-zero if subnets *a* and *b* are identical, and **0** otherwise. Subnets of different address families are never identical.

*Addrinsubnet* returns non-zero if address *a* is within subnet *s* and **0** otherwise. An address is never within a subnet of a different address family.

*Subnetinsubnet* returns non-zero if subnet *a* is a subset of subnet *b* and **0** otherwise. A subnet is deemed to be a subset of itself. A subnet is never a subset of another subnet if their address families differ.

*Subnetishost* returns non-zero if subnet *s* is in fact only a single host, and **0** otherwise.

*Samesaid* returns non-zero if SA IDs *a* and *b* are identical, and **0** otherwise.

*Sameaddrtype* returns non-zero if addresses *a* and *b* are of the same address family, and **0** otherwise.

*Samesubnettype* returns non-zero if subnets *a* and *b* are of the same address family, and **0** otherwise.

## SEE ALSO

[inet(3)](/inet/3.md), [ipsec\_initaddr(3)](/ipsec_initaddr/3.md)

## HISTORY

Written for the FreeS/WAN project by Henry Spencer.
