---
title: llarp::net

---

# llarp::net



## Classes

|                | Name           |
| -------------- | -------------- |
| struct | **[llarp::net::InterfaceInfo](Classes/structllarp_1_1net_1_1InterfaceInfo.md)** <br>info about a network interface lokinet does not own  |
| struct | **[llarp::net::ip_header_le](Classes/structllarp_1_1net_1_1ip__header__le.md)**  |
| struct | **[llarp::net::ip_header_be](Classes/structllarp_1_1net_1_1ip__header__be.md)**  |
| struct | **[llarp::net::ipv6_header_preamble_le](Classes/structllarp_1_1net_1_1ipv6__header__preamble__le.md)**  |
| struct | **[llarp::net::ipv6_header_preamble_be](Classes/structllarp_1_1net_1_1ipv6__header__preamble__be.md)**  |
| struct | **[llarp::net::ipv6_header](Classes/structllarp_1_1net_1_1ipv6__header.md)**  |
| struct | **[llarp::net::IPPacket](Classes/structllarp_1_1net_1_1IPPacket.md)** <br>an Packet  |
| struct | **[llarp::net::IPRangeMap](Classes/structllarp_1_1net_1_1IPRangeMap.md)** <br>a container that maps an ip range to a value that allows you to lookup key by range hit  |
| class | **[llarp::net::Platform](Classes/classllarp_1_1net_1_1Platform.md)** <br>network platform (all methods virtual so it can be mocked by unit tests)  |
| struct | **[llarp::net::ProtocolInfo](Classes/structllarp_1_1net_1_1ProtocolInfo.md)** <br>information about an IP protocol  |
| struct | **[llarp::net::TrafficPolicy](Classes/structllarp_1_1net_1_1TrafficPolicy.md)** <br>information about what traffic an endpoint will carry  |

## Types

|                | Name           |
| -------------- | -------------- |
| enum class uint8_t | **[IPProtocol](Namespaces/namespacellarp_1_1net.md#enum-ipprotocol)** { ICMP = 0x01, IGMP = 0x02, IPIP = 0x04, TCP = 0x06, UDP = 0x11, GRE = 0x2F, ICMP6 = 0x3A, OSFP = 0x59, PGM = 0x71}<br>"well known" ip protocols TODO: extend this to non "well known values"  |
| using std::conditional_t< oxenc::little_endian, [ip_header_le](Classes/structllarp_1_1net_1_1ip__header__le.md), [ip_header_be](Classes/structllarp_1_1net_1_1ip__header__be.md) > | **[ip_header](Namespaces/namespacellarp_1_1net.md#using-ip-header)**  |
| using std::conditional_t< oxenc::little_endian, [ipv6_header_preamble_le](Classes/structllarp_1_1net_1_1ipv6__header__preamble__le.md), [ipv6_header_preamble_be](Classes/structllarp_1_1net_1_1ipv6__header__preamble__be.md) > | **[ipv6_header_preamble](Namespaces/namespacellarp_1_1net.md#using-ipv6-header-preamble)**  |
| using n_uint16_t | **[port_t](Namespaces/namespacellarp_1_1net.md#using-port-t)**  |
| using n_uint32_t | **[ipv4addr_t](Namespaces/namespacellarp_1_1net.md#using-ipv4addr-t)**  |
| using n_uint32_t | **[flowlabel_t](Namespaces/namespacellarp_1_1net.md#using-flowlabel-t)**  |
| using n_uint128_t | **[ipv6addr_t](Namespaces/namespacellarp_1_1net.md#using-ipv6addr-t)**  |
| using std::variant< ipv4addr_t, ipv6addr_t > | **[ipaddr_t](Namespaces/namespacellarp_1_1net.md#using-ipaddr-t)**  |

## Functions

|                | Name           |
| -------------- | -------------- |
| [huint128_t](Classes/structllarp_1_1huint__t.md) | **[In6ToHUInt](Namespaces/namespacellarp_1_1net.md#function-in6tohuint)**(in6_addr addr) |
| in6_addr | **[HUIntToIn6](Namespaces/namespacellarp_1_1net.md#function-huinttoin6)**([huint128_t](Classes/structllarp_1_1huint__t.md) x) |
| constexpr [huint128_t](Classes/structllarp_1_1huint__t.md) | **[ExpandV4](Namespaces/namespacellarp_1_1net.md#function-expandv4)**([huint32_t](Classes/structllarp_1_1huint__t.md) x) |
| constexpr [huint128_t](Classes/structllarp_1_1huint__t.md) | **[ExpandV4Lan](Namespaces/namespacellarp_1_1net.md#function-expandv4lan)**([huint32_t](Classes/structllarp_1_1huint__t.md) x) |
| constexpr [huint32_t](Classes/structllarp_1_1huint__t.md) | **[TruncateV6](Namespaces/namespacellarp_1_1net.md#function-truncatev6)**([huint128_t](Classes/structllarp_1_1huint__t.md) x) |
| std::string | **[IPProtocolName](Namespaces/namespacellarp_1_1net.md#function-ipprotocolname)**(IPProtocol proto)<br>get string representation of this protocol throws std::invalid_argument if we don't know the name of this ip protocol  |
| IPProtocol | **[ParseIPProtocol](Namespaces/namespacellarp_1_1net.md#function-parseipprotocol)**(std::string data)<br>parse a string to an ip protocol throws std::invalid_argument if cannot be parsed  |
| uint16_t | **[ipchksum](Namespaces/namespacellarp_1_1net.md#function-ipchksum)**(const byte_t * buf, size_t sz, uint32_t sum =0)<br>generate ip checksum  |
| auto | **[ipaddr_netmask_bits](Namespaces/namespacellarp_1_1net.md#function-ipaddr-netmask-bits)**(uint32_t bits, int af) |
| std::string | **[LoopbackInterfaceName](Namespaces/namespacellarp_1_1net.md#function-loopbackinterfacename)**()<br>get the name of the loopback interface  |
| std::string | **[ToString](Namespaces/namespacellarp_1_1net.md#function-tostring)**(const ipaddr_t & ip) |
| [huint16_t](Classes/structllarp_1_1huint__t.md) | **[ToHost](Namespaces/namespacellarp_1_1net.md#function-tohost)**(port_t ) |
| [huint32_t](Classes/structllarp_1_1huint__t.md) | **[ToHost](Namespaces/namespacellarp_1_1net.md#function-tohost)**(ipv4addr_t ) |
| [huint128_t](Classes/structllarp_1_1huint__t.md) | **[ToHost](Namespaces/namespacellarp_1_1net.md#function-tohost)**(ipv6addr_t ) |
| port_t | **[ToNet](Namespaces/namespacellarp_1_1net.md#function-tonet)**([huint16_t](Classes/structllarp_1_1huint__t.md) ) |
| ipv4addr_t | **[ToNet](Namespaces/namespacellarp_1_1net.md#function-tonet)**([huint32_t](Classes/structllarp_1_1huint__t.md) ) |
| ipv6addr_t | **[ToNet](Namespaces/namespacellarp_1_1net.md#function-tonet)**([huint128_t](Classes/structllarp_1_1huint__t.md) ) |

## Types Documentation

### enum IPProtocol

| Enumerator | Value | Description |
| ---------- | ----- | ----------- |
| ICMP | 0x01|   |
| IGMP | 0x02|   |
| IPIP | 0x04|   |
| TCP | 0x06|   |
| UDP | 0x11|   |
| GRE | 0x2F|   |
| ICMP6 | 0x3A|   |
| OSFP | 0x59|   |
| PGM | 0x71|   |



"well known" ip protocols TODO: extend this to non "well known values" 

### using ip_header

```cpp
using llarp::net::ip_header = typedef std::conditional_t<oxenc::little_endian, ip_header_le, ip_header_be>;
```


### using ipv6_header_preamble

```cpp
using llarp::net::ipv6_header_preamble = typedef std::conditional_t<oxenc::little_endian, ipv6_header_preamble_le, ipv6_header_preamble_be>;
```


### using port_t

```cpp
using llarp::net::port_t = typedef n_uint16_t;
```


### using ipv4addr_t

```cpp
using llarp::net::ipv4addr_t = typedef n_uint32_t;
```


### using flowlabel_t

```cpp
using llarp::net::flowlabel_t = typedef n_uint32_t;
```


### using ipv6addr_t

```cpp
using llarp::net::ipv6addr_t = typedef n_uint128_t;
```


### using ipaddr_t

```cpp
using llarp::net::ipaddr_t = typedef std::variant<ipv4addr_t, ipv6addr_t>;
```



## Functions Documentation

### function In6ToHUInt

```cpp
huint128_t In6ToHUInt(
    in6_addr addr
)
```


### function HUIntToIn6

```cpp
in6_addr HUIntToIn6(
    huint128_t x
)
```


### function ExpandV4

```cpp
constexpr huint128_t ExpandV4(
    huint32_t x
)
```


### function ExpandV4Lan

```cpp
constexpr huint128_t ExpandV4Lan(
    huint32_t x
)
```


### function TruncateV6

```cpp
constexpr huint32_t TruncateV6(
    huint128_t x
)
```


### function IPProtocolName

```cpp
std::string IPProtocolName(
    IPProtocol proto
)
```

get string representation of this protocol throws std::invalid_argument if we don't know the name of this ip protocol 

### function ParseIPProtocol

```cpp
IPProtocol ParseIPProtocol(
    std::string data
)
```

parse a string to an ip protocol throws std::invalid_argument if cannot be parsed 

### function ipchksum

```cpp
uint16_t ipchksum(
    const byte_t * buf,
    size_t sz,
    uint32_t sum =0
)
```

generate ip checksum 

### function ipaddr_netmask_bits

```cpp
inline auto ipaddr_netmask_bits(
    uint32_t bits,
    int af
)
```


### function LoopbackInterfaceName

```cpp
std::string LoopbackInterfaceName()
```

get the name of the loopback interface 

### function ToString

```cpp
std::string ToString(
    const ipaddr_t & ip
)
```


### function ToHost

```cpp
huint16_t ToHost(
    port_t 
)
```


### function ToHost

```cpp
huint32_t ToHost(
    ipv4addr_t 
)
```


### function ToHost

```cpp
huint128_t ToHost(
    ipv6addr_t 
)
```


### function ToNet

```cpp
port_t ToNet(
    huint16_t 
)
```


### function ToNet

```cpp
ipv4addr_t ToNet(
    huint32_t 
)
```


### function ToNet

```cpp
ipv6addr_t ToNet(
    huint128_t 
)
```






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

Updated on 2023-01-26 at 19:35:17 +0000