---
title: llarp::net::IPPacket
summary: an Packet 

---

# llarp::net::IPPacket



an Packet 


`#include <ip_packet.hpp>`

## Public Classes

|                | Name           |
| -------------- | -------------- |
| struct | **[CompareOrder](Classes/structllarp_1_1net_1_1IPPacket_1_1CompareOrder.md)**  |
| struct | **[CompareSize](Classes/structllarp_1_1net_1_1IPPacket_1_1CompareSize.md)**  |

## Public Functions

|                | Name           |
| -------------- | -------------- |
| | **[IPPacket](Classes/structllarp_1_1net_1_1IPPacket.md#function-ippacket)**() |
| | **[IPPacket](Classes/structllarp_1_1net_1_1IPPacket.md#function-ippacket)**(size_t sz)<br>create an ip packet buffer of all zeros of size sz  |
| | **[IPPacket](Classes/structllarp_1_1net_1_1IPPacket.md#function-ippacket)**(byte_view_t )<br>create an ip packet from a view  |
| | **[IPPacket](Classes/structllarp_1_1net_1_1IPPacket.md#function-ippacket)**(std::vector< byte_t > && )<br>create an ip packet from a vector we then own  |
| | **[~IPPacket](Classes/structllarp_1_1net_1_1IPPacket.md#function-~ippacket)**() =default |
| bool | **[Load](Classes/structllarp_1_1net_1_1IPPacket.md#function-load)**(const [llarp_buffer_t](Classes/structllarp__buffer__t.md) & buf) |
| [llarp_buffer_t](Classes/structllarp__buffer__t.md) | **[ConstBuffer](Classes/structllarp_1_1net_1_1IPPacket.md#function-constbuffer)**() const |
| std::vector< byte_t > | **[steal](Classes/structllarp_1_1net_1_1IPPacket.md#function-steal)**()<br>steal the underlying vector  |
| byte_t * | **[data](Classes/structllarp_1_1net_1_1IPPacket.md#function-data)**() |
| const byte_t * | **[data](Classes/structllarp_1_1net_1_1IPPacket.md#function-data)**() const |
| constexpr size_t | **[capacity](Classes/structllarp_1_1net_1_1IPPacket.md#function-capacity)**() const |
| size_t | **[size](Classes/structllarp_1_1net_1_1IPPacket.md#function-size)**() const |
| bool | **[empty](Classes/structllarp_1_1net_1_1IPPacket.md#function-empty)**() const |
| byte_view_t | **[view](Classes/structllarp_1_1net_1_1IPPacket.md#function-view)**() const |
| ip_header * | **[Header](Classes/structllarp_1_1net_1_1IPPacket.md#function-header)**() |
| const ip_header * | **[Header](Classes/structllarp_1_1net_1_1IPPacket.md#function-header)**() const |
| [ipv6_header](Classes/structllarp_1_1net_1_1ipv6__header.md) * | **[HeaderV6](Classes/structllarp_1_1net_1_1IPPacket.md#function-headerv6)**() |
| const [ipv6_header](Classes/structllarp_1_1net_1_1ipv6__header.md) * | **[HeaderV6](Classes/structllarp_1_1net_1_1IPPacket.md#function-headerv6)**() const |
| int | **[Version](Classes/structllarp_1_1net_1_1IPPacket.md#function-version)**() const |
| byte_t | **[protocol](Classes/structllarp_1_1net_1_1IPPacket.md#function-protocol)**() const |
| bool | **[IsV4](Classes/structllarp_1_1net_1_1IPPacket.md#function-isv4)**() const |
| bool | **[IsV6](Classes/structllarp_1_1net_1_1IPPacket.md#function-isv6)**() const |
| service::ProtocolType | **[ServiceProtocol](Classes/structllarp_1_1net_1_1IPPacket.md#function-serviceprotocol)**() const |
| [huint128_t](Classes/structllarp_1_1huint__t.md) | **[srcv6](Classes/structllarp_1_1net_1_1IPPacket.md#function-srcv6)**() const |
| [huint128_t](Classes/structllarp_1_1huint__t.md) | **[dstv6](Classes/structllarp_1_1net_1_1IPPacket.md#function-dstv6)**() const |
| [huint32_t](Classes/structllarp_1_1huint__t.md) | **[srcv4](Classes/structllarp_1_1net_1_1IPPacket.md#function-srcv4)**() const |
| [huint32_t](Classes/structllarp_1_1huint__t.md) | **[dstv4](Classes/structllarp_1_1net_1_1IPPacket.md#function-dstv4)**() const |
| [huint128_t](Classes/structllarp_1_1huint__t.md) | **[src4to6](Classes/structllarp_1_1net_1_1IPPacket.md#function-src4to6)**() const |
| [huint128_t](Classes/structllarp_1_1huint__t.md) | **[dst4to6](Classes/structllarp_1_1net_1_1IPPacket.md#function-dst4to6)**() const |
| [huint128_t](Classes/structllarp_1_1huint__t.md) | **[src4to6Lan](Classes/structllarp_1_1net_1_1IPPacket.md#function-src4to6lan)**() const |
| [huint128_t](Classes/structllarp_1_1huint__t.md) | **[dst4to6Lan](Classes/structllarp_1_1net_1_1IPPacket.md#function-dst4to6lan)**() const |
| [SockAddr](Classes/structllarp_1_1SockAddr.md) | **[src](Classes/structllarp_1_1net_1_1IPPacket.md#function-src)**() const |
| [SockAddr](Classes/structllarp_1_1SockAddr.md) | **[dst](Classes/structllarp_1_1net_1_1IPPacket.md#function-dst)**() const |
| std::optional< nuint16_t > | **[DstPort](Classes/structllarp_1_1net_1_1IPPacket.md#function-dstport)**() const<br>get destination port if applicable  |
| std::optional< nuint16_t > | **[SrcPort](Classes/structllarp_1_1net_1_1IPPacket.md#function-srcport)**() const<br>get source port if applicable  |
| std::optional< std::pair< const char *, size_t > > | **[L4Data](Classes/structllarp_1_1net_1_1IPPacket.md#function-l4data)**() const<br>get pointer and size of layer 4 data  |
| std::optional< [OwnedBuffer](Classes/structllarp_1_1OwnedBuffer.md) > | **[L4OwnedBuffer](Classes/structllarp_1_1net_1_1IPPacket.md#function-l4ownedbuffer)**() const |
| void | **[UpdateIPv4Address](Classes/structllarp_1_1net_1_1IPPacket.md#function-updateipv4address)**(nuint32_t src, nuint32_t dst) |
| void | **[UpdateIPv6Address](Classes/structllarp_1_1net_1_1IPPacket.md#function-updateipv6address)**([huint128_t](Classes/structllarp_1_1huint__t.md) src, [huint128_t](Classes/structllarp_1_1huint__t.md) dst, std::optional< nuint32_t > flowlabel =std::nullopt) |
| void | **[ZeroAddresses](Classes/structllarp_1_1net_1_1IPPacket.md#function-zeroaddresses)**(std::optional< nuint32_t > flowlabel =std::nullopt)<br>set addresses to zero and recacluate checksums  |
| void | **[ZeroSourceAddress](Classes/structllarp_1_1net_1_1IPPacket.md#function-zerosourceaddress)**(std::optional< nuint32_t > flowlabel =std::nullopt)<br>zero out source address  |
| std::optional< [IPPacket](Classes/structllarp_1_1net_1_1IPPacket.md) > | **[MakeICMPUnreachable](Classes/structllarp_1_1net_1_1IPPacket.md#function-makeicmpunreachable)**() const<br>make an icmp unreachable reply packet based of this ip packet  |
| [IPPacket](Classes/structllarp_1_1net_1_1IPPacket.md) | **[UDP](Classes/structllarp_1_1net_1_1IPPacket.md#function-udp)**(nuint32_t srcaddr, nuint16_t srcport, nuint32_t dstaddr, nuint16_t dstport, const [llarp_buffer_t](Classes/structllarp__buffer__t.md) & data) |
| [IPPacket](Classes/structllarp_1_1net_1_1IPPacket.md) | **[make_udp](Classes/structllarp_1_1net_1_1IPPacket.md#function-make-udp)**(net::ipaddr_t srcaddr, net::port_t srcport, net::ipaddr_t dstaddr, net::port_t dstport, std::vector< byte_t > udp_body) |
| [IPPacket](Classes/structllarp_1_1net_1_1IPPacket.md) | **[make_udp](Classes/structllarp_1_1net_1_1IPPacket.md#function-make-udp)**([SockAddr](Classes/structllarp_1_1SockAddr.md) src, [SockAddr](Classes/structllarp_1_1SockAddr.md) dst, std::variant< [OwnedBuffer](Classes/structllarp_1_1OwnedBuffer.md), std::vector< byte_t >> udp_body) |

## Public Attributes

|                | Name           |
| -------------- | -------------- |
| constexpr size_t | **[_max_size](Classes/structllarp_1_1net_1_1IPPacket.md#variable--max-size)**  |
| constexpr size_t | **[MaxSize](Classes/structllarp_1_1net_1_1IPPacket.md#variable-maxsize)**  |
| constexpr size_t | **[MinSize](Classes/structllarp_1_1net_1_1IPPacket.md#variable-minsize)**  |
| llarp_time_t | **[timestamp](Classes/structllarp_1_1net_1_1IPPacket.md#variable-timestamp)**  |
| std::vector< byte_t > | **[_buf](Classes/structllarp_1_1net_1_1IPPacket.md#variable--buf)**  |
| std::function< void([net::IPPacket](Classes/structllarp_1_1net_1_1IPPacket.md))> | **[reply](Classes/structllarp_1_1net_1_1IPPacket.md#variable-reply)**  |

## Public Functions Documentation

### function IPPacket

```cpp
inline IPPacket()
```


### function IPPacket

```cpp
explicit IPPacket(
    size_t sz
)
```

create an ip packet buffer of all zeros of size sz 

### function IPPacket

```cpp
explicit IPPacket(
    byte_view_t 
)
```

create an ip packet from a view 

### function IPPacket

```cpp
IPPacket(
    std::vector< byte_t > && 
)
```

create an ip packet from a vector we then own 

### function ~IPPacket

```cpp
~IPPacket() =default
```


### function Load

```cpp
inline bool Load(
    const llarp_buffer_t & buf
)
```


### function ConstBuffer

```cpp
inline llarp_buffer_t ConstBuffer() const
```


### function steal

```cpp
inline std::vector< byte_t > steal()
```

steal the underlying vector 

### function data

```cpp
inline byte_t * data()
```


### function data

```cpp
inline const byte_t * data() const
```


### function capacity

```cpp
inline constexpr size_t capacity() const
```


### function size

```cpp
inline size_t size() const
```


### function empty

```cpp
inline bool empty() const
```


### function view

```cpp
byte_view_t view() const
```


### function Header

```cpp
inline ip_header * Header()
```


### function Header

```cpp
inline const ip_header * Header() const
```


### function HeaderV6

```cpp
inline ipv6_header * HeaderV6()
```


### function HeaderV6

```cpp
inline const ipv6_header * HeaderV6() const
```


### function Version

```cpp
inline int Version() const
```


### function protocol

```cpp
inline byte_t protocol() const
```


### function IsV4

```cpp
inline bool IsV4() const
```


### function IsV6

```cpp
inline bool IsV6() const
```


### function ServiceProtocol

```cpp
inline service::ProtocolType ServiceProtocol() const
```


### function srcv6

```cpp
huint128_t srcv6() const
```


### function dstv6

```cpp
huint128_t dstv6() const
```


### function srcv4

```cpp
huint32_t srcv4() const
```


### function dstv4

```cpp
huint32_t dstv4() const
```


### function src4to6

```cpp
huint128_t src4to6() const
```


### function dst4to6

```cpp
huint128_t dst4to6() const
```


### function src4to6Lan

```cpp
huint128_t src4to6Lan() const
```


### function dst4to6Lan

```cpp
huint128_t dst4to6Lan() const
```


### function src

```cpp
SockAddr src() const
```


### function dst

```cpp
SockAddr dst() const
```


### function DstPort

```cpp
std::optional< nuint16_t > DstPort() const
```

get destination port if applicable 

### function SrcPort

```cpp
std::optional< nuint16_t > SrcPort() const
```

get source port if applicable 

### function L4Data

```cpp
std::optional< std::pair< const char *, size_t > > L4Data() const
```

get pointer and size of layer 4 data 

### function L4OwnedBuffer

```cpp
inline std::optional< OwnedBuffer > L4OwnedBuffer() const
```


### function UpdateIPv4Address

```cpp
void UpdateIPv4Address(
    nuint32_t src,
    nuint32_t dst
)
```


### function UpdateIPv6Address

```cpp
void UpdateIPv6Address(
    huint128_t src,
    huint128_t dst,
    std::optional< nuint32_t > flowlabel =std::nullopt
)
```


### function ZeroAddresses

```cpp
void ZeroAddresses(
    std::optional< nuint32_t > flowlabel =std::nullopt
)
```

set addresses to zero and recacluate checksums 

### function ZeroSourceAddress

```cpp
void ZeroSourceAddress(
    std::optional< nuint32_t > flowlabel =std::nullopt
)
```

zero out source address 

### function MakeICMPUnreachable

```cpp
std::optional< IPPacket > MakeICMPUnreachable() const
```

make an icmp unreachable reply packet based of this ip packet 

### function UDP

```cpp
static inline IPPacket UDP(
    nuint32_t srcaddr,
    nuint16_t srcport,
    nuint32_t dstaddr,
    nuint16_t dstport,
    const llarp_buffer_t & data
)
```


### function make_udp

```cpp
static IPPacket make_udp(
    net::ipaddr_t srcaddr,
    net::port_t srcport,
    net::ipaddr_t dstaddr,
    net::port_t dstport,
    std::vector< byte_t > udp_body
)
```


### function make_udp

```cpp
static inline IPPacket make_udp(
    SockAddr src,
    SockAddr dst,
    std::variant< OwnedBuffer, std::vector< byte_t >> udp_body
)
```


## Public Attributes Documentation

### variable _max_size

```cpp
static constexpr size_t _max_size = 1500;
```


### variable MaxSize

```cpp
static constexpr size_t MaxSize = _max_size;
```


### variable MinSize

```cpp
static constexpr size_t MinSize = 20;
```


### variable timestamp

```cpp
llarp_time_t timestamp;
```


### variable _buf

```cpp
std::vector< byte_t > _buf;
```


### variable reply

```cpp
std::function< void(net::IPPacket)> reply;
```


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

Updated on 2023-01-20 at 18:12:19 +0000