12c431f66SShuo Chen#include <algorithm> // std::swap 22c431f66SShuo Chen 32c431f66SShuo Chen#include <boost/static_assert.hpp> 4cc808594SShuo Chen 5cc808594SShuo Chen#include <assert.h> 6cc808594SShuo Chen#include <stdint.h> 72c431f66SShuo Chen#include <string.h> 8cc808594SShuo Chen#include <arpa/inet.h> // inet_ntop 9cc808594SShuo Chen#include <net/if.h> 10cc808594SShuo Chen 112c431f66SShuo Chenstruct SocketAddr 122c431f66SShuo Chen{ 132c431f66SShuo Chen uint32_t saddr, daddr; 142c431f66SShuo Chen uint16_t sport, dport; 152c431f66SShuo Chen 162c431f66SShuo Chen bool operator==(const SocketAddr& rhs) const 172c431f66SShuo Chen { 182c431f66SShuo Chen return saddr == rhs.saddr && daddr == rhs.daddr && sport == rhs.sport && dport == rhs.dport; 192c431f66SShuo Chen } 202c431f66SShuo Chen 212c431f66SShuo Chen bool operator<(const SocketAddr& rhs) const 222c431f66SShuo Chen { 232c431f66SShuo Chen BOOST_STATIC_ASSERT(sizeof(SocketAddr) == 12); 242c431f66SShuo Chen return memcmp(this, &rhs, sizeof(rhs)) < 0; 252c431f66SShuo Chen } 262c431f66SShuo Chen}; 272c431f66SShuo Chen 2861cf49ddSShuo Chenint tun_alloc(char dev[IFNAMSIZ], bool offload = false); 29cc808594SShuo Chenuint16_t in_checksum(const void* buf, int len); 30cc808594SShuo Chen 31cc808594SShuo Chenvoid icmp_input(int fd, const void* input, const void* payload, int len); 32