1#include <algorithm>  // std::swap
2
3#include <boost/static_assert.hpp>
4
5#include <assert.h>
6#include <stdint.h>
7#include <string.h>
8#include <arpa/inet.h>  // inet_ntop
9#include <net/if.h>
10
11struct SocketAddr
12{
13  uint32_t saddr, daddr;
14  uint16_t sport, dport;
15
16  bool operator==(const SocketAddr& rhs) const
17  {
18    return saddr == rhs.saddr && daddr == rhs.daddr && sport == rhs.sport && dport == rhs.dport;
19  }
20
21  bool operator<(const SocketAddr& rhs) const
22  {
23    BOOST_STATIC_ASSERT(sizeof(SocketAddr) == 12);
24    return memcmp(this, &rhs, sizeof(rhs)) < 0;
25  }
26};
27
28int tun_alloc(char dev[IFNAMSIZ], bool offload = false);
29uint16_t in_checksum(const void* buf, int len);
30
31void icmp_input(int fd, const void* input, const void* payload, int len);
32