---
name: "initaddr"
section: "3"
platform: "linux"
package: "strongswan"
version: "4.2.4-5+lenny3"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://new.carta.tech/initaddr"
---

# initaddr(3)

initialize an ip\_address ipsec addrtypeof - get address type of an ip\_address ipsec addrlenof - get length of address within an ip\_address ipsec addrbytesof - get copy of address within an ip\_address ipsec addrbytesptr - get pointer to address within an ip\_address

## NAME

ipsec initaddr - initialize an ip\_address\
 ipsec addrtypeof - get address type of an ip\_address\
 ipsec addrlenof - get length of address within an ip\_address\
 ipsec addrbytesof - get copy of address within an ip\_address\
 ipsec addrbytesptr - get pointer to address within an ip\_address

## SYNOPSIS

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

**const char \*initaddr(const char \*src, size\_t srclen,** **int af, ip\_address \*dst);**\
 **int addrtypeof(const ip\_address \*src);**\
 **size\_t addrlenof(const ip\_address \*src);**\
 **size\_t addrbytesof(const ip\_address \*src,** **unsigned char \*dst, size\_t dstlen);**\
 **size\_t addrbytesptr(const ip\_address \*src,** **const unsigned char \*\*dst);**

## DESCRIPTION

The **\<freeswan.h\>** library uses an internal type *ip\_address* to contain one of the (currently two) types of IP address. These functions provide basic tools for creating and examining this type.

*Initaddr* initializes a variable *\*dst* of type *ip\_address* from an address (in network byte order, indicated by a pointer *src* and a length *srclen*) and an address family *af* (typically **AF\_INET** or **AF\_INET6**). The length must be consistent with the address family.

*Addrtypeof* returns the address type of an address, normally **AF\_INET** or **AF\_INET6**. (The **\<freeswan.h\>** header file arranges to include the necessary headers for these names to be known.)

*Addrlenof* returns the size (in bytes) of the address within an *ip\_address*, to permit storage allocation etc.

*Addrbytesof* copies the address within the *ip\_address* *src* to the buffer indicated by the pointer *dst* and the length *dstlen*, and returns the address length (in bytes). If the address will not fit, as many bytes as will fit are copied; the returned length is still the full length. It is the caller's responsibility to check the returned value to ensure that there was enough room.

*Addrbytesptr* sets *\*dst* to a pointer to the internal address within the *ip\_address*, and returns the address length (in bytes). If *dst* is **NULL**, it just returns the address length. The pointer points to **const** to discourage misuse.

*Initaddr* returns **NULL** for success and a pointer to a string-literal error message for failure; see DIAGNOSTICS.

The functions which return *size\_t* return **0** for a failure.

## SEE ALSO

[inet(3)](/inet/3.md), [ipsec\_ttoaddr(3)](/ipsec_ttoaddr/3.md)

## DIAGNOSTICS

An unknown address family is a fatal error for any of these functions except *addrtypeof*. An address-size mismatch is a fatal error for *initaddr*.

## HISTORY

Written for the FreeS/WAN project by Henry Spencer.

## BUGS

*Addrtypeof* should probably have been named *addrfamilyof*.
