UniRec 3.3.2
Loading...
Searching...
No Matches
ipAddress.hpp
Go to the documentation of this file.
1
9#pragma once
10
11#include <ostream>
12#include <string>
13
14#include <unirec/ipaddr.h>
15
16namespace Nemea {
17
22// C++ designated initializers is available with -std=c++2a
24 = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff } };
25
29struct IpAddress {
31
37
43 IpAddress(const std::string& ipAddressAsString);
44
49 bool isIpv4() const;
50
55 bool isIpv6() const;
56
62 bool operator==(const IpAddress& other) const;
63
69 IpAddress operator&(const IpAddress& other) const;
70
76 std::ostream& operator<<(std::ostream& os);
77};
78
79static_assert(sizeof(IpAddress) == sizeof(ip_addr_t), "Invalid header definition");
80
81} // namespace Nemea
Structure to store both IPv4 and IPv6 addresses and associated functions.
static const ip_addr_t EMPTY_IP_ADDRESS
Define a constant for an empty IP address 0.0.0.0 for IPv4, :: for IPv6.
Definition ipAddress.hpp:24
A struct representing an IP address with associated operations.
Definition ipAddress.hpp:29
bool operator==(const IpAddress &other) const
Equality operator to compare two IpAddress objects.
Definition ipAddress.cpp:32
bool isIpv6() const
Check if the stored IP address is an IPv6 address.
Definition ipAddress.cpp:30
IpAddress operator&(const IpAddress &other) const
Bitwise AND operator to perform a bitwise AND operation on two IpAddress objects.
Definition ipAddress.cpp:37
std::ostream & operator<<(std::ostream &os)
Output stream operator to stream an IpAddress object to an output stream.
Definition ipAddress.cpp:45
bool isIpv4() const
Check if the stored IP address is an IPv4 address.
Definition ipAddress.cpp:28
IpAddress(ip_addr_t ip=EMPTY_IP_ADDRESS)
Constructor to initialize IpAddress with an ip_addr_t value.
Definition ipAddress.cpp:15