---
title: llarp/layers/platform/platform_addr.hpp

---

# llarp/layers/platform/platform_addr.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |
| **[llarp::layers](Namespaces/namespacellarp_1_1layers.md)**  |
| **[llarp::layers::platform](Namespaces/namespacellarp_1_1layers_1_1platform.md)**  |
| **[std](Namespaces/namespacestd.md)** <br>STL namespace.  |

## Classes

|                | Name           |
| -------------- | -------------- |
| struct | **[llarp::layers::platform::PlatformAddr](Classes/structllarp_1_1layers_1_1platform_1_1PlatformAddr.md)** <br>a (ipv6 address, flowlabel) tuple that we use for platform layer side addressing  |
| struct | **[std::hash< llarp::layers::platform::PlatformAddr >](Classes/structstd_1_1hash_3_01llarp_1_1layers_1_1platform_1_1PlatformAddr_01_4.md)**  |




## Source code

```cpp
#pragma once

#include <llarp/net/net_int.hpp>

#include <array>
#include <numeric>
#include <string>
#include <optional>
#include <functional>

namespace llarp::layers::platform
{

  struct PlatformAddr
  {
    net::ipv6addr_t ip{};

    net::flowlabel_t flowlabel{};

    PlatformAddr() = default;
    PlatformAddr(const PlatformAddr&) = default;
    PlatformAddr(PlatformAddr&&) = default;

    PlatformAddr&
    operator=(const PlatformAddr&) = default;
    PlatformAddr&
    operator=(PlatformAddr&&) = default;

    explicit PlatformAddr(net::ipaddr_t addr);
    explicit PlatformAddr(const std::string& str);
    explicit PlatformAddr(huint128_t addr);

    std::string
    ToString() const;

    net::ipaddr_t
    as_ipaddr_t() const;

    bool
    operator==(const PlatformAddr& other) const;
    bool
    operator!=(const PlatformAddr& other) const;

    bool
    operator<(const PlatformAddr& other) const;
  };

}  // namespace llarp::layers::platform

namespace llarp
{
  template <>
  inline constexpr bool IsToStringFormattable<layers::platform::PlatformAddr> = true;
}

namespace std
{
  template <>
  struct hash<llarp::layers::platform::PlatformAddr>
  {
    size_t
    operator()(const llarp::layers::platform::PlatformAddr& addr) const
    {
      const std::array<uint64_t, 4> data{addr.ip.n.upper, addr.ip.n.lower, addr.flowlabel.n};
      int n{};
      return std::accumulate(
          data.begin(), data.end(), uint64_t{}, [&n](uint64_t lhs, uint64_t rhs) {
            return lhs ^ (rhs << (n += (n ? 2 : 1)));
          });
    }
  };
}  // namespace std
```


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

Updated on 2023-03-06 at 20:36:34 +0000
