mavtables
0.2.1
MAVLink router and firewall.
|
#include <MAVSubnet.hpp>
Public Member Functions | |
MAVSubnet (const MAVSubnet &other)=default | |
MAVSubnet (MAVSubnet &&other)=default | |
MAVSubnet (const MAVAddress &address, unsigned int mask=0xFFFF) | |
MAVSubnet (const MAVAddress &address, unsigned int system_mask, unsigned int component_mask) | |
MAVSubnet (std::string address) | |
bool | contains (const MAVAddress &address) const |
MAVSubnet & | operator= (const MAVSubnet &other)=default |
MAVSubnet & | operator= (MAVSubnet &&other)=default |
Friends | |
bool | operator== (const MAVSubnet &lhs, const MAVSubnet &rhs) |
bool | operator!= (const MAVSubnet &lhs, const MAVSubnet &rhs) |
std::ostream & | operator<< (std::ostream &os, const MAVSubnet &mavsubnet) |
A MAVLink subnet.
Mavlink subnets work the same as IP subnets and allow the definition of a range of addresses. This is used to allow a single firewall rule to match multiple addresses.
Definition at line 36 of file MAVSubnet.hpp.
|
default |
Copy constructor.
other | MAVLink subnet to copy from. |
|
default |
Move constructor.
other | MAVLink subnet to move from. |
MAVSubnet::MAVSubnet | ( | const MAVAddress & | address, |
unsigned int | mask = 0xFFFF |
||
) |
Construct a MAVLink subnet from a MAVLink address and mask.
address | MAVLink address of subnet. |
mask | Two byte subnet mask, where the system mask is in the MSB and the component mask is in the LSB. |
std::out_of_range | if the mask is not between 0x0000 and 0xFFFF. |
Definition at line 38 of file MAVSubnet.cpp.
MAVSubnet::MAVSubnet | ( | const MAVAddress & | address, |
unsigned int | system_mask, | ||
unsigned int | component_mask | ||
) |
Construct MAVLink subnet from an address, system mask, and component mask.
address | MAVLink address of subnet. |
system_mask | One byte subnet system mask with the bits set that must match the subnet address for a MAVLink address to be contained within the subnet. Valid range is 0 to 255. |
component_mask | One byte subnet component mask with the bits set that must match the subnet address for a MAVLink address to be contained within the subnet. Valid range is 0 to 255. |
std::out_of_range | if the system and component masks are not each between 0x00 and 0xFF. |
Definition at line 68 of file MAVSubnet.cpp.
MAVSubnet::MAVSubnet | ( | std::string | subnet | ) |
Construct a MAVLink subnet from a string.
There are four string forms of MAVLink subnets:
The first form is self explanatory, but the 2nd and 3rd are not as simple. In the 2nd case the number of bits (0 - 16) is the number of bits from the left that must match for an address to be in the subnet. The 3rd form is like the 2nd, but does not require the system ID (first octet) to match and starts with the number of bits of the component ID (0 - 8) that must match from the left for an address to be in the subnet. The last form is shorthand for "<System ID>.<Component ID>/16", that is an exact match.
Below is a table relating the slash postfix to the subnet mask in <System mask>.<Component mask> notation.
Mask with / | Mask with \ | Postfix (#bits) |
---|---|---|
255.255 | out of range | 16 |
255.254 | out of range | 15 |
255.252 | out of range | 14 |
255.248 | out of range | 13 |
255.240 | out of range | 12 |
255.224 | out of range | 11 |
255.192 | out of range | 10 |
255.128 | out of range | 9 |
255.0 | 0.255 | 8 |
254.0 | 0.254 | 7 |
252.0 | 0.252 | 6 |
248.0 | 0.248 | 5 |
240.0 | 0.240 | 4 |
224.0 | 0.224 | 3 |
192.0 | 0.192 | 2 |
128.0 | 0.128 | 1 |
0.0 | 0 | 0 |
Some examples are:
subnet | String representing the MAVLink subnet. |
std::out_of_range | if either the system ID or the component ID is out of range. |
std::out_of_range | if the mask or slash bits are out of range. |
std::invalid_argument | if the subnet string does not represent a valid MAVLink subnet. |
Definition at line 161 of file MAVSubnet.cpp.
References MAVAddress::address().
bool MAVSubnet::contains | ( | const MAVAddress & | address | ) | const |
Determine whether or not the subnet contains a given MAVLink address.
address | The MAVLink address to test. |
true | if address is part of the subnet. |
Definition at line 250 of file MAVSubnet.cpp.
References MAVAddress::address().
Assignment operator.
other | MAVLink subnet to copy from. |
Assignment operator (by move semantics).
other | MAVLink subnet to move from. |
Inequality comparison.
Compares both address and mask.
lhs | The left hand side MAVLink subnet. |
rhs | The right hand side MAVLink subnet. |
true | if lhs and rhs are not the same. |
false | if lhs and rhs are the same. |
Definition at line 282 of file MAVSubnet.cpp.
|
friend |
Print the MAVLink subnet to the given output stream.
There are three string forms of MAVLink subnets.
The slash notation is preferred. The last form is used when the mask requires all bits of a subnet to match an address.
See MAVSubnet::MAVSubnet(std::string address) for more information on the string format.
os | The output stream to print to. |
mavsubnet | The MAVLink subnet to print. |
Definition at line 311 of file MAVSubnet.cpp.
Equality comparison.
Compares both address and mask.
lhs | The left hand side MAVLink subnet. |
rhs | The right hand side MAVLink subnet. |
true | if lhs and rhs are the same. |
false | if lhs and rhs are not the same. |
Definition at line 266 of file MAVSubnet.cpp.