These are the pre-v12 classes, kept so existing code keeps building. New code should use the modern API — see Migration Guide: v11 to v12.
optris::IpAddress
IP address are stored in an array in the following oder: a.b.c.d => [0: a, 1: b, 2: c, 3: d]
Public functions
IpAddress
OTC_SDK_API IpAddress() noexcept
Constructor. All IP address bytes are set to 0.
IpAddress
OTC_SDK_API IpAddress(std::uint32_t address) noexcept
Constructor.
Parameters
| Name | Description |
|---|---|
address |
as an unsigned 32 bit integer in network byte order. |
IpAddress
OTC_SDK_API IpAddress(const std::string &address)
Constructor.
Parameters
| Name | Description |
|---|---|
address |
string in dot notation (a.b.c.d). |
Exceptions
| Name | Description |
|---|---|
SDKException |
if address string is invalid. |
IpAddress
OTC_SDK_API IpAddress(std::uint8_t a, std::uint8_t b, std::uint8_t c, std::uint8_t d) noexcept
Constructor.
Parameters
| Name | Description |
|---|---|
a |
byte from an a.b.c.d IP address. |
b |
byte from an a.b.c.d IP address. |
c |
byte from an a.b.c.d IP address. |
d |
byte from an a.b.c.d IP address. |
reset
OTC_SDK_API void reset()
Resets all the bytes of the IP address to 0 (0.0.0.0).
setFromUInt32
OTC_SDK_API void setFromUInt32(std::uint32_t address) noexcept
Sets the address from an unsigned 32 bit integer in network byte order.
Note: The network byte order is big-endian while many architectures like x64 or arm64 are little-endian.
Parameters
| Name | Description |
|---|---|
address |
as an unsigned 32 bit integer with the bytes in network order. |
toUInt32
OTC_SDK_API std::uint32_t toUInt32() const noexcept
Returns the address as an unsigned 32 bit integer in network byte order.
Note: The network byte order is big-endian while many architectures like x64 or arm64 are little-endian.
Returns: address as an unsigned 32 bit integer in network byte order.
setFromString
OTC_SDK_API void setFromString(const std::string &address)
Sets the address from a string in dot notation (a.b.c.d).
Parameters
| Name | Description |
|---|---|
address |
in dot notation. |
Exceptions
| Name | Description |
|---|---|
SDKException |
if the address string is invalid. |
setFromCidrString
OTC_SDK_API int setFromCidrString(const std::string &address)
Sets the address from a string in classless inter-domain routing (CIDR) notation (a.b.c.d/cidr).
Parameters
| Name | Description |
|---|---|
address |
in CIDR notation. |
Returns: CIDR part of the address representing the bit count of the network portion of the address.
Exceptions
| Name | Description |
|---|---|
SDKException |
if the address string is invalid. |
toString
OTC_SDK_API std::string toString() const noexcept
Returns the address as a string in dot notation (a.b.c.d).
Returns: the address as a string in dot notation.
toCidrString
OTC_SDK_API std::string toCidrString(int cidr) const noexcept
Returns the address as a string in classless inter-domain routing (CIDR) notation (a.b.c.d/cidr).
Parameters
| Name | Description |
|---|---|
cidr |
part of the address representing the bit count of the network portion of the address. |
Returns: the address as a string in classless inter-domain routing (CIDR) notation.
setByte
OTC_SDK_API void setByte(int index, std::uint8_t value)
Sets the value of the byte with the given index.
Parameters
| Name | Description |
|---|---|
index |
of the byte to set. |
value |
to set. |
Exceptions
| Name | Description |
|---|---|
SDKException |
if index is out of range. |
getByte
OTC_SDK_API std::uint8_t getByte(int index) const
Returns the value of the byte with the given index.
Parameters
| Name | Description |
|---|---|
index |
of the desired byte. |
Returns: value of the byte with the given index.
Exceptions
| Name | Description |
|---|---|
SDKException |
if the index is out of range. |
getNetworkPortion
OTC_SDK_API IpAddress getNetworkPortion(const IpAddress &subnetMask) const noexcept
Returns the network portion of the IP address according to the given subnet mask.
Parameters
| Name | Description |
|---|---|
subnetMask |
to apply to the IP address. |
Returns: network portion of the IP address.
getNetworkPortion
OTC_SDK_API IpAddress getNetworkPortion(int cidr) const
Returns the network portion of the IP address according to the given CIDR bit count.
Parameters
| Name | Description |
|---|---|
cidr |
part of the address representing the bit count of the network portion of the address. |
Returns: network portion of the IP address.
Exceptions
| Name | Description |
|---|---|
SDKException |
if the value of cidr is not in [0, 32]. |
getHostPortion
OTC_SDK_API IpAddress getHostPortion(const IpAddress &subnetMask) const noexcept
Returns the host portion of the IP address according to the given subnet mask.
Parameters
| Name | Description |
|---|---|
subnetMask |
to apply to the IP address. |
Returns: host portion of the IP address.
getHostPortion
OTC_SDK_API IpAddress getHostPortion(int cidr) const
Returns the host portion of the IP address according to the given CIDR bit count.
Parameters
| Name | Description |
|---|---|
cidr |
part of the address representing the bit count of the network portion of the address. |
Returns: host portion of the IP address.
Exceptions
| Name | Description |
|---|---|
SDKException |
if the value of cidr is not in [0, 32]. |
getBroadcastAddress
OTC_SDK_API IpAddress getBroadcastAddress(const IpAddress &subnetMask) const noexcept
Returns the broadcast address for this IP address with the given subnet mask.
Parameters
| Name | Description |
|---|---|
subnetMask |
to apply to the IP address. |
Returns: broadcast address for this IP address with the given subnet mask.
getBroadcastAddress
OTC_SDK_API IpAddress getBroadcastAddress(int cidr) const
Returns the broadcast address for this IP address with the given CIDR bit count.
Parameters
| Name | Description |
|---|---|
cidr |
part of the address representing the bit count of the network portion of the address. |
Returns: broadcast address for this IP address with the given CIDR bit count.
Exceptions
| Name | Description |
|---|---|
SDKException |
if the value of cidr is not in [0, 32]. |
operator==
bool operator==(const IpAddress &rhs) const noexcept
Returns whether this IP address equals the provided one.
Parameters
| Name | Description |
|---|---|
rhs |
IP address to compare this one to. |
Returns: true, if this IP address equals the provided one.
operator==
bool operator==(std::uint32_t rhs) const noexcept
Returns whether this IP address equals the provided one.
Parameters
| Name | Description |
|---|---|
rhs |
IP address as unsigned 32 bit integer in network byte order to compare this one to. |
Returns: true, if this IP address equals the provided one.
operator!=
bool operator!=(const IpAddress &rhs) const noexcept
Returns whether this IP address is different from the provided one.
Parameters
| Name | Description |
|---|---|
rhs |
IP address to compare this one to. |
Returns: true, if this IP address is different from the provided one. False otherwise.
operator<
bool operator<(const IpAddress &rhs) const noexcept
Returns whether this IP address has a smaller unsigned 32 bit integer representation than the provided one.
Parameters
| Name | Description |
|---|---|
rhs |
IP address to compare this one to. |
Returns: true, if this IP address has a smaller unsigned 32 bit integer representation than the provided one. False otherwise.