---
title: llarp::SockAddr
summary: A simple SockAddr wrapper which provides a sockaddr_in (IPv4). 

---

# llarp::SockAddr



A simple [SockAddr]() wrapper which provides a sockaddr_in (IPv4).  [More...](#detailed-description)


`#include <sock_addr.hpp>`

## Public Functions

|                | Name           |
| -------------- | -------------- |
| | **[SockAddr](Classes/structllarp_1_1SockAddr.md#function-sockaddr)**() |
| | **[SockAddr](Classes/structllarp_1_1SockAddr.md#function-sockaddr)**(uint8_t a, uint8_t b, uint8_t c, uint8_t d, [huint16_t](Classes/structllarp_1_1huint__t.md) port ={0}) |
| | **[SockAddr](Classes/structllarp_1_1SockAddr.md#function-sockaddr)**(nuint32_t ip, nuint16_t port ={0}) |
| | **[SockAddr](Classes/structllarp_1_1SockAddr.md#function-sockaddr)**([huint32_t](Classes/structllarp_1_1huint__t.md) ip, [huint16_t](Classes/structllarp_1_1huint__t.md) port ={0}) |
| | **[SockAddr](Classes/structllarp_1_1SockAddr.md#function-sockaddr)**([huint128_t](Classes/structllarp_1_1huint__t.md) ip, [huint16_t](Classes/structllarp_1_1huint__t.md) port ={0}) |
| | **[SockAddr](Classes/structllarp_1_1SockAddr.md#function-sockaddr)**(nuint128_t ip, nuint16_t port ={0}) |
| | **[SockAddr](Classes/structllarp_1_1SockAddr.md#function-sockaddr)**(std::string_view addr) |
| | **[SockAddr](Classes/structllarp_1_1SockAddr.md#function-sockaddr)**(std::string_view addr, [huint16_t](Classes/structllarp_1_1huint__t.md) port) |
| | **[SockAddr](Classes/structllarp_1_1SockAddr.md#function-sockaddr)**(const [AddressInfo](Classes/structllarp_1_1AddressInfo.md) & ) |
| | **[SockAddr](Classes/structllarp_1_1SockAddr.md#function-sockaddr)**(const [SockAddr](Classes/structllarp_1_1SockAddr.md) & ) |
| [SockAddr](Classes/structllarp_1_1SockAddr.md) & | **[operator=](Classes/structllarp_1_1SockAddr.md#function-operator=)**(const [SockAddr](Classes/structllarp_1_1SockAddr.md) & ) |
| | **[SockAddr](Classes/structllarp_1_1SockAddr.md#function-sockaddr)**(const sockaddr & addr) |
| [SockAddr](Classes/structllarp_1_1SockAddr.md) & | **[operator=](Classes/structllarp_1_1SockAddr.md#function-operator=)**(const sockaddr & addr) |
| | **[SockAddr](Classes/structllarp_1_1SockAddr.md#function-sockaddr)**(const sockaddr_in & addr) |
| [SockAddr](Classes/structllarp_1_1SockAddr.md) & | **[operator=](Classes/structllarp_1_1SockAddr.md#function-operator=)**(const sockaddr_in & addr) |
| | **[SockAddr](Classes/structllarp_1_1SockAddr.md#function-sockaddr)**(const sockaddr_in6 & addr) |
| [SockAddr](Classes/structllarp_1_1SockAddr.md) & | **[operator=](Classes/structllarp_1_1SockAddr.md#function-operator=)**(const sockaddr_in6 & addr) |
| | **[SockAddr](Classes/structllarp_1_1SockAddr.md#function-sockaddr)**(const in6_addr & addr) |
| [SockAddr](Classes/structllarp_1_1SockAddr.md) & | **[operator=](Classes/structllarp_1_1SockAddr.md#function-operator=)**(const in6_addr & addr) |
| | **[operator const sockaddr *](Classes/structllarp_1_1SockAddr.md#function-operator-const-sockaddr-*)**() const |
| | **[operator const sockaddr_in *](Classes/structllarp_1_1SockAddr.md#function-operator-const-sockaddr-in-*)**() const |
| | **[operator const sockaddr_in6 *](Classes/structllarp_1_1SockAddr.md#function-operator-const-sockaddr-in6-*)**() const |
| size_t | **[sockaddr_len](Classes/structllarp_1_1SockAddr.md#function-sockaddr-len)**() const |
| bool | **[operator<](Classes/structllarp_1_1SockAddr.md#function-operator<)**(const [SockAddr](Classes/structllarp_1_1SockAddr.md) & other) const |
| bool | **[operator==](Classes/structllarp_1_1SockAddr.md#function-operator==)**(const [SockAddr](Classes/structllarp_1_1SockAddr.md) & other) const |
| bool | **[operator!=](Classes/structllarp_1_1SockAddr.md#function-operator!=)**(const [SockAddr](Classes/structllarp_1_1SockAddr.md) & other) const |
| void | **[fromString](Classes/structllarp_1_1SockAddr.md#function-fromstring)**(std::string_view str, bool allow_port =true) |
| std::string | **[ToString](Classes/structllarp_1_1SockAddr.md#function-tostring)**() const |
| std::string | **[hostString](Classes/structllarp_1_1SockAddr.md#function-hoststring)**() const |
| int | **[Family](Classes/structllarp_1_1SockAddr.md#function-family)**() const |
| bool | **[isEmpty](Classes/structllarp_1_1SockAddr.md#function-isempty)**() const<br>Returns true if this is an empty [SockAddr](Classes/structllarp_1_1SockAddr.md), defined by having no IP address set.  |
| void | **[setIPv4](Classes/structllarp_1_1SockAddr.md#function-setipv4)**(uint8_t a, uint8_t b, uint8_t c, uint8_t d) |
| void | **[setIP](Classes/structllarp_1_1SockAddr.md#function-setip)**(std::variant< nuint32_t, nuint128_t > ip) |
| void | **[setIPv4](Classes/structllarp_1_1SockAddr.md#function-setipv4)**(nuint32_t ip) |
| void | **[setIPv4](Classes/structllarp_1_1SockAddr.md#function-setipv4)**([huint32_t](Classes/structllarp_1_1huint__t.md) ip) |
| void | **[setIPv6](Classes/structllarp_1_1SockAddr.md#function-setipv6)**([huint128_t](Classes/structllarp_1_1huint__t.md) ip) |
| void | **[setIPv6](Classes/structllarp_1_1SockAddr.md#function-setipv6)**(nuint128_t ip) |
| void | **[setPort](Classes/structllarp_1_1SockAddr.md#function-setport)**([huint16_t](Classes/structllarp_1_1huint__t.md) port) |
| void | **[setPort](Classes/structllarp_1_1SockAddr.md#function-setport)**(nuint16_t port) |
| void | **[setPort](Classes/structllarp_1_1SockAddr.md#function-setport)**(uint16_t port) |
| net::port_t | **[port](Classes/structllarp_1_1SockAddr.md#function-port)**() const<br>get the port of this sockaddr in network order  |
| uint16_t | **[getPort](Classes/structllarp_1_1SockAddr.md#function-getport)**() const<br>port is always returned in host order  |
| bool | **[isIPv6](Classes/structllarp_1_1SockAddr.md#function-isipv6)**() const<br>True if this stores an IPv6 address, false if IPv4.  |
| bool | **[isIPv4](Classes/structllarp_1_1SockAddr.md#function-isipv4)**() const<br>!isIPv6()  |
| nuint128_t | **[getIPv6](Classes/structllarp_1_1SockAddr.md#function-getipv6)**() const<br>in network order  |
| nuint32_t | **[getIPv4](Classes/structllarp_1_1SockAddr.md#function-getipv4)**() const |
| std::variant< nuint32_t, nuint128_t > | **[getIP](Classes/structllarp_1_1SockAddr.md#function-getip)**() const |
| [huint128_t](Classes/structllarp_1_1huint__t.md) | **[asIPv6](Classes/structllarp_1_1SockAddr.md#function-asipv6)**() const<br>in host order  |
| [huint32_t](Classes/structllarp_1_1huint__t.md) | **[asIPv4](Classes/structllarp_1_1SockAddr.md#function-asipv4)**() const |

## Detailed Description

```cpp
struct llarp::SockAddr;
```

A simple [SockAddr]() wrapper which provides a sockaddr_in (IPv4). 

Memory management is handled in constructor and destructor (if needed) and copying is disabled. 

## Public Functions Documentation

### function SockAddr

```cpp
SockAddr()
```


### function SockAddr

```cpp
SockAddr(
    uint8_t a,
    uint8_t b,
    uint8_t c,
    uint8_t d,
    huint16_t port ={0}
)
```


### function SockAddr

```cpp
SockAddr(
    nuint32_t ip,
    nuint16_t port ={0}
)
```


### function SockAddr

```cpp
SockAddr(
    huint32_t ip,
    huint16_t port ={0}
)
```


### function SockAddr

```cpp
SockAddr(
    huint128_t ip,
    huint16_t port ={0}
)
```


### function SockAddr

```cpp
SockAddr(
    nuint128_t ip,
    nuint16_t port ={0}
)
```


### function SockAddr

```cpp
SockAddr(
    std::string_view addr
)
```


### function SockAddr

```cpp
SockAddr(
    std::string_view addr,
    huint16_t port
)
```


### function SockAddr

```cpp
SockAddr(
    const AddressInfo & 
)
```


### function SockAddr

```cpp
SockAddr(
    const SockAddr & 
)
```


### function operator=

```cpp
SockAddr & operator=(
    const SockAddr & 
)
```


### function SockAddr

```cpp
SockAddr(
    const sockaddr & addr
)
```


### function operator=

```cpp
SockAddr & operator=(
    const sockaddr & addr
)
```


### function SockAddr

```cpp
SockAddr(
    const sockaddr_in & addr
)
```


### function operator=

```cpp
SockAddr & operator=(
    const sockaddr_in & addr
)
```


### function SockAddr

```cpp
SockAddr(
    const sockaddr_in6 & addr
)
```


### function operator=

```cpp
SockAddr & operator=(
    const sockaddr_in6 & addr
)
```


### function SockAddr

```cpp
SockAddr(
    const in6_addr & addr
)
```


### function operator=

```cpp
SockAddr & operator=(
    const in6_addr & addr
)
```


### function operator const sockaddr *

```cpp
explicit operator const sockaddr *() const
```


### function operator const sockaddr_in *

```cpp
explicit operator const sockaddr_in *() const
```


### function operator const sockaddr_in6 *

```cpp
explicit operator const sockaddr_in6 *() const
```


### function sockaddr_len

```cpp
size_t sockaddr_len() const
```


### function operator<

```cpp
bool operator<(
    const SockAddr & other
) const
```


### function operator==

```cpp
bool operator==(
    const SockAddr & other
) const
```


### function operator!=

```cpp
inline bool operator!=(
    const SockAddr & other
) const
```


### function fromString

```cpp
void fromString(
    std::string_view str,
    bool allow_port =true
)
```


### function ToString

```cpp
std::string ToString() const
```


### function hostString

```cpp
std::string hostString() const
```


### function Family

```cpp
inline int Family() const
```


### function isEmpty

```cpp
bool isEmpty() const
```

Returns true if this is an empty [SockAddr](Classes/structllarp_1_1SockAddr.md), defined by having no IP address set. 

**Return**: true if this is empty, false otherwise 

An empty IP address with a valid port is still considered empty.


### function setIPv4

```cpp
void setIPv4(
    uint8_t a,
    uint8_t b,
    uint8_t c,
    uint8_t d
)
```


### function setIP

```cpp
inline void setIP(
    std::variant< nuint32_t, nuint128_t > ip
)
```


### function setIPv4

```cpp
void setIPv4(
    nuint32_t ip
)
```


### function setIPv4

```cpp
void setIPv4(
    huint32_t ip
)
```


### function setIPv6

```cpp
void setIPv6(
    huint128_t ip
)
```


### function setIPv6

```cpp
void setIPv6(
    nuint128_t ip
)
```


### function setPort

```cpp
void setPort(
    huint16_t port
)
```


### function setPort

```cpp
void setPort(
    nuint16_t port
)
```


### function setPort

```cpp
inline void setPort(
    uint16_t port
)
```


### function port

```cpp
net::port_t port() const
```

get the port of this sockaddr in network order 

### function getPort

```cpp
inline uint16_t getPort() const
```

port is always returned in host order 

### function isIPv6

```cpp
bool isIPv6() const
```

True if this stores an IPv6 address, false if IPv4. 

### function isIPv4

```cpp
bool isIPv4() const
```

!isIPv6() 

### function getIPv6

```cpp
nuint128_t getIPv6() const
```

in network order 

### function getIPv4

```cpp
nuint32_t getIPv4() const
```


### function getIP

```cpp
std::variant< nuint32_t, nuint128_t > getIP() const
```


### function asIPv6

```cpp
huint128_t asIPv6() const
```

in host order 

### function asIPv4

```cpp
huint32_t asIPv4() const
```


-------------------------------

Updated on 2023-01-24 at 18:23:42 +0000