void parse(const std::string &addr);
public:
+ /**
+ * @ingroup api_inet
+ * @{
+ */
EthAddr();
EthAddr(const uint8_t ea[ETH_ADDR_LEN]);
EthAddr(const eth_addr &ea);
EthAddr(const std::string &addr);
const EthAddr &operator=(const eth_addr &ea);
const EthAddr &operator=(const std::string &addr);
+ /** @} */ // end of api_inet
+ /**
+ * @ingroup api_inet
+ */
int size() const { return sizeof(eth_addr); }
+
+ /**
+ * @ingroup api_inet
+ * @{
+ */
const uint8_t *bytes() const { return &data[0]; }
uint8_t *bytes() { return &data[0]; }
+ /** @} */ // end of api_inet
+ /**
+ * @ingroup api_inet
+ * @{
+ */
const uint8_t *addr() const { return &data[0]; }
bool unicast() const { return !(data[0] & 0x01); }
bool multicast() const { return !unicast() && !broadcast(); }
return isBroadcast;
}
+ /** @} */ // end of api_inet
+ /**
+ * @ingroup api_inet
+ */
std::string string() const;
+ /**
+ * @ingroup api_inet
+ */
operator uint64_t() const
{
uint64_t reg = 0;
};
+/**
+ * @ingroup api_inet
+ * @{
+ */
std::ostream &operator<<(std::ostream &stream, const EthAddr &ea);
bool operator==(const EthAddr &left, const EthAddr &right);
+/** @} */ // end of api_inet
struct EthHdr : public eth_hdr
{
EthPacketPtr p;
public:
+ /**
+ * @ingroup api_inet
+ * @{
+ */
EthPtr() {}
EthPtr(const EthPacketPtr &ptr) : p(ptr) { }
+ /** @} */ // end of api_inet
EthHdr *operator->() { return (EthHdr *)p->data; }
EthHdr &operator*() { return *(EthHdr *)p->data; }
const EthHdr &operator*() const { return *(const EthHdr *)p->data; }
operator const EthHdr *() const { return (const EthHdr *)p->data; }
+ /**
+ * @ingroup api_inet
+ */
const EthPtr &operator=(const EthPacketPtr &ptr) { p = ptr; return *this; }
+ /**
+ * @ingroup api_inet
+ * @{
+ */
const EthPacketPtr packet() const { return p; }
EthPacketPtr packet() { return p; }
bool operator!() const { return !p; }
operator bool() const { return (p != nullptr); }
int off() const { return 0; }
int pstart() const { return off() + ((const EthHdr*)p->data)->size(); }
+ /** @} */ // end of api_inet
};
/*
uint32_t _ip;
public:
+ /**
+ * @ingroup api_inet
+ * @{
+ */
IpAddress() : _ip(0)
{}
IpAddress(const uint32_t __ip) : _ip(__ip)
{}
+ /** @} */ // end of api_net
+ /**
+ * @ingroup api_inet
+ */
uint32_t ip() const { return _ip; }
+ /**
+ * @ingroup api_inet
+ */
std::string string() const;
};
+/**
+ * @ingroup api_inet
+ * @{
+ */
std::ostream &operator<<(std::ostream &stream, const IpAddress &ia);
bool operator==(const IpAddress &left, const IpAddress &right);
+/** @} */ // end of api_inet
struct IpNetmask : public IpAddress
{
IpAddress(__ip), _netmask(__netmask)
{}
+ /**
+ * @ingroup api_inet
+ */
uint8_t netmask() const { return _netmask; }
std::string string() const;
};
+/**
+ * @ingroup api_inet
+ * @{
+ */
std::ostream &operator<<(std::ostream &stream, const IpNetmask &in);
bool operator==(const IpNetmask &left, const IpNetmask &right);
+/** @} */ // end of api_inet
struct IpWithPort : public IpAddress
{
IpAddress(__ip), _port(__port)
{}
+ /**
+ * @ingroup api_inet
+ */
uint8_t port() const { return _port; }
std::string string() const;
};
+/**
+ * @ingroup api_inet
+ * @{
+ */
std::ostream &operator<<(std::ostream &stream, const IpWithPort &iwp);
bool operator==(const IpWithPort &left, const IpWithPort &right);
+/** @} */ // end of api_inet
struct IpOpt;
struct IpHdr : public ip_hdr
}
public:
+ /**
+ * @ingroup api_inet
+ * @{
+ */
IpPtr() : p(0), eth_hdr_vlan(false) {}
IpPtr(const EthPacketPtr &ptr) : p(0), eth_hdr_vlan(false) { set(ptr); }
IpPtr(const EthPtr &ptr) : p(0), eth_hdr_vlan(false) { set(ptr.p); }
IpPtr(const IpPtr &ptr) : p(ptr.p), eth_hdr_vlan(ptr.eth_hdr_vlan) { }
+ /** @} */ // end of api_inet
IpHdr *get() { return (IpHdr *)(p->data + sizeof(eth_hdr) +
((eth_hdr_vlan) ? 4 : 0)); }
IpHdr *operator->() { return get(); }
IpHdr &operator*() { return *get(); }
+ /**
+ * @ingroup api_inet
+ * @{
+ */
const IpHdr *get() const
{ return (const IpHdr *)(p->data + sizeof(eth_hdr) +
((eth_hdr_vlan) ? 4 : 0)); }
const IpHdr *operator->() const { return get(); }
const IpHdr &operator*() const { return *get(); }
+ /** @} */ // end of api_inet
const IpPtr &operator=(const EthPacketPtr &ptr) { set(ptr); return *this; }
const IpPtr &operator=(const EthPtr &ptr) { set(ptr.p); return *this; }
const IpPtr &operator=(const IpPtr &ptr) { p = ptr.p; return *this; }
+ /**
+ * @ingroup api_inet
+ * @{
+ */
const EthPacketPtr packet() const { return p; }
EthPacketPtr packet() { return p; }
bool operator!() const { return !p; }
operator bool() const { return (p != nullptr); }
int off() const { return (sizeof(eth_hdr) + ((eth_hdr_vlan) ? 4 : 0)); }
int pstart() const { return (off() + get()->size()); }
+ /** @} */ // end of api_inet
};
+/**
+ * @ingroup api_inet
+ */
uint16_t cksum(const IpPtr &ptr);
struct IpOpt : public ip_opt
}
public:
+ /**
+ * @ingroup api_inet
+ * @{
+ */
Ip6Ptr() : p(0), eth_hdr_vlan(false) {}
Ip6Ptr(const EthPacketPtr &ptr) : p(0), eth_hdr_vlan(false) { set(ptr); }
Ip6Ptr(const EthPtr &ptr) : p(0), eth_hdr_vlan(false) { set(ptr.p); }
Ip6Ptr(const Ip6Ptr &ptr) : p(ptr.p), eth_hdr_vlan(ptr.eth_hdr_vlan) { }
+ /** @} */ // end of api_inet
Ip6Hdr *get() { return (Ip6Hdr *)(p->data + sizeof(eth_hdr)
+ ((eth_hdr_vlan) ? 4 : 0)); }
const Ip6Hdr *operator->() const { return get(); }
const Ip6Hdr &operator*() const { return *get(); }
+ /**
+ * @ingroup api_inet
+ * @{
+ */
const Ip6Ptr &operator=(const EthPacketPtr &ptr)
{ set(ptr); return *this; }
const Ip6Ptr &operator=(const EthPtr &ptr)
{ set(ptr.p); return *this; }
const Ip6Ptr &operator=(const Ip6Ptr &ptr)
{ p = ptr.p; return *this; }
+ /** @} */ // end of api_inet
+ /**
+ * @ingroup api_inet
+ * @{
+ */
const EthPacketPtr packet() const { return p; }
EthPacketPtr packet() { return p; }
bool operator!() const { return !p; }
operator bool() const { return (p != nullptr); }
int off() const { return sizeof(eth_hdr) + ((eth_hdr_vlan) ? 4 : 0); }
int pstart() const { return off() + get()->size(); }
+ /** @} */ // end of api_inet
};
// Dnet supplied ipv6 opt header is incomplete and
}
public:
+ /**
+ * @ingroup api_inet
+ * @{
+ */
TcpPtr() : p(0), _off(0) {}
TcpPtr(const IpPtr &ptr) : p(0), _off(0) { set(ptr); }
TcpPtr(const Ip6Ptr &ptr) : p(0), _off(0) { set(ptr); }
TcpPtr(const TcpPtr &ptr) : p(ptr.p), _off(ptr._off) {}
+ /** @} */ // end of api_inet
TcpHdr *get() { return (TcpHdr *)(p->data + _off); }
TcpHdr *operator->() { return get(); }
const TcpHdr *operator->() const { return get(); }
const TcpHdr &operator*() const { return *get(); }
+ /**
+ * @ingroup api_inet
+ * @{
+ */
const TcpPtr &operator=(const IpPtr &i)
{ set(i); return *this; }
const TcpPtr &operator=(const TcpPtr &t)
{ set(t.p, t._off); return *this; }
+ /** @} */ // end of api_inet
+ /**
+ * @ingroup api_inet
+ * @{
+ */
const EthPacketPtr packet() const { return p; }
EthPacketPtr packet() { return p; }
bool operator!() const { return !p; }
operator bool() const { return (p != nullptr); }
int off() const { return _off; }
int pstart() const { return off() + get()->size(); }
+ /** @} */ // end of api_inet
};
+/**
+ * @ingroup api_inet
+ */
uint16_t cksum(const TcpPtr &ptr);
struct TcpOpt : public tcp_opt
}
public:
+ /**
+ * @ingroup api_inet
+ */
UdpPtr() : p(0), _off(0) {}
UdpPtr(const IpPtr &ptr) : p(0), _off(0) { set(ptr); }
UdpPtr(const Ip6Ptr &ptr) : p(0), _off(0) { set(ptr); }
UdpPtr(const UdpPtr &ptr) : p(ptr.p), _off(ptr._off) {}
+ /** @} */ // end of api_inet
UdpHdr *get() { return (UdpHdr *)(p->data + _off); }
UdpHdr *operator->() { return get(); }
const UdpHdr *operator->() const { return get(); }
const UdpHdr &operator*() const { return *get(); }
+ /**
+ * @ingroup api_inet
+ * @{
+ */
const UdpPtr &operator=(const IpPtr &i) { set(i); return *this; }
const UdpPtr &operator=(const UdpPtr &t)
{ set(t.p, t._off); return *this; }
+ /** @} */ // end of api_inet
+ /**
+ * @ingroup api_inet
+ * @{
+ */
const EthPacketPtr packet() const { return p; }
EthPacketPtr packet() { return p; }
bool operator!() const { return !p; }
operator bool() const { return (p != nullptr); }
int off() const { return _off; }
int pstart() const { return off() + get()->size(); }
+ /** @} */ // end of api_inet
};
+/**
+ * @ingroup api_inet
+ * @{
+ */
uint16_t __tu_cksum6(const Ip6Ptr &ip6);
uint16_t __tu_cksum(const IpPtr &ip);
uint16_t cksum(const UdpPtr &ptr);
+/** @} */ // end of api_inet
+/**
+ * @ingroup api_inet
+ */
int hsplit(const EthPacketPtr &ptr);
} // namespace Net