init
This commit is contained in:
42
src/map/natmap.cpp
Normal file
42
src/map/natmap.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "natmap.h"
|
||||
|
||||
namespace otonat
|
||||
{
|
||||
|
||||
NatMap::NatMap(): NatMap(Tins::NetworkInterface::all())
|
||||
{
|
||||
//ctor
|
||||
}
|
||||
|
||||
NatMap::NatMap(std::vector<Tins::NetworkInterface> interfaceList) : interfaces(interfaceList)
|
||||
{
|
||||
}
|
||||
|
||||
NatMap::~NatMap()
|
||||
{
|
||||
//dtor
|
||||
}
|
||||
|
||||
NatMap::NatMap(const NatMap& other) : interfaces(other.interfaces)
|
||||
{
|
||||
//copy ctor
|
||||
}
|
||||
|
||||
NatMap& NatMap::operator=(const NatMap& rhs)
|
||||
{
|
||||
if (this == &rhs) return *this; // handle self assignment
|
||||
|
||||
interfaces = rhs.interfaces;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const Tins::IPv4Address NatMap::mapIPv4Address(const Tins::IPv4Address & ip, const Tins::NetworkInterface::Info & interfaceInfo)
|
||||
{
|
||||
const uint32_t & netmask = interfaceInfo.netmask;
|
||||
const uint32_t & interfaceIp = interfaceInfo.ip_addr;
|
||||
const uint32_t networkStartIp = interfaceIp & netmask;
|
||||
const uint32_t resultIp = (ip & ~netmask) | networkStartIp;
|
||||
return Tins::IPv4Address(resultIp);
|
||||
}
|
||||
|
||||
}
|
||||
28
src/map/natmap.h
Normal file
28
src/map/natmap.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef NATMAP_H
|
||||
#define NATMAP_H
|
||||
|
||||
#include <vector>
|
||||
#include <tins/tins.h>
|
||||
|
||||
namespace otonat
|
||||
{
|
||||
class NatMap
|
||||
{
|
||||
public:
|
||||
NatMap();
|
||||
NatMap(std::vector<Tins::NetworkInterface> interfaceList);
|
||||
virtual ~NatMap();
|
||||
NatMap(const NatMap& other);
|
||||
NatMap& operator=(const NatMap& other);
|
||||
std::vector<Tins::NetworkInterface> interfaces;
|
||||
static const Tins::IPv4Address mapIPv4Address(const Tins::IPv4Address & ip, const Tins::NetworkInterface::Info & interfaceInfo);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // NATMAP_H
|
||||
Reference in New Issue
Block a user