---
name: "ipsec_portof"
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_portof"
---

# ipsec\_portof(3)

get port field of an ip\_address, set port field of an ip\_address, get pointer to internal sockaddr of an ip\_address, get length of internal sockaddr of an ip\_address

## NAME

ipsec\_portof, ipsec\_setportof, ipsec\_sockaddrof, ipsec\_sockaddrlenof - get port field of an ip\_address, set port field of an ip\_address, get pointer to internal sockaddr of an ip\_address, get length of internal sockaddr of an ip\_address

## SYNOPSIS

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

**int portof(const ip\_address \*src);**\
 **void setportof(int port, ip\_address \*dst);**\
 **struct sockaddr \*sockaddrof(ip\_address \*src);**\
 **size\_t sockaddrlenof(const ip\_address \*src);**

## DESCRIPTION

The **\<freeswan.h\>** internal type *ip\_address* contains one of the *sockaddr* types internally. *Reliance on this feature is discouraged*, but it may occasionally be necessary. These functions provide low-level tools for this purpose.

*Portof* and *setportof* respectively read and write the port-number field of the internal *sockaddr*. The values are in network byte order.

*Sockaddrof* returns a pointer to the internal *sockaddr*, for passing to other functions.

*Sockaddrlenof* reports the size of the internal *sockaddr*, for use in storage allocation.

## SEE ALSO

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

## DIAGNOSTICS

*Portof* returns **-1**, *sockaddrof* returns **NULL**, and *sockaddrlenof* returns **0** if an unknown address family is found within the *ip\_address*.

## HISTORY

Written for the FreeS/WAN project by Henry Spencer.

## BUGS

These functions all depend on low-level details of the *ip\_address* type, which are in principle subject to change. Avoid using them unless really necessary.
