class IpPort
Defined at line 35 of file ../../src/lib/inet/ip_port.h
Represents an IP port number.
Ports are not treated as 16-bit integers by the network stack, meaning that,
on little-endian targets, the two bytes will be reversed. For example, the
mDNS multicast port is 5353 decimal or 14E9 hex. On arrival on a little-
endian machine, the bytes are laid down in the order 14, E9 resulting in
the integer value E914.
This class exists primarily to alleviate the confusion this causes.
The types |in_port_t| and |uint16_t| are interpreted differently, in spite
of the fact that they have the same underlying type (hence the From_*
static methods rather than constructors). |in_port_t| is assumed to be
big-endian (in network order) consistent with the way the network stack
produces and consumes port values. |uint16_t| is assumed to be host-endian.
This means that creating an |IpPort| constant from a |uint16_t| literal
should be done using |From_uint16_t|.
An |ostream| operator
<
<
overload is provided so |IpPort| values are
represented properly as text. It just writes |value.as_uint16_t()|.
Public Methods
void IpPort ()
Creates an invalid IpPort.
Defined at line 9 of file ../../src/lib/inet/ip_port.cc
void IpPort (uint8_t b0, uint8_t b1)
Creates a port from two bytes in network order.
Defined at line 11 of file ../../src/lib/inet/ip_port.cc
IpPort From_in_port_t (in_port_t port)
Creates an |IpPort| from an |in_port_t|. This assumes that the value is
big-endian (network order). Use this method when creating an |IpPort|
from |in_port_t| values produced by the network stack.
Defined at line 40 of file ../../src/lib/inet/ip_port.h
IpPort From_uint16_t (uint16_t port_as_uint16_t)
Creates an |IpPort| from a |uint16_t|. This assumes that the value is
host-endian. Use this method when creating |IpPort| from host-endian
|uint16_t| values, such as literals.
Defined at line 45 of file ../../src/lib/inet/ip_port.h
bool is_valid ()
Defined at line 55 of file ../../src/lib/inet/ip_port.h
in_port_t as_in_port_t ()
Returns an |in_port_t| value for the port. This value is big-endian
(network order), suitable for consumption by the network stack.
Defined at line 59 of file ../../src/lib/inet/ip_port.h
uint16_t as_uint16_t ()
Returns a |uint16_t| value for the port. This value is host-endian,
suitable for displaying to humans, etc.
Defined at line 63 of file ../../src/lib/inet/ip_port.h
bool operator bool ()
Defined at line 65 of file ../../src/lib/inet/ip_port.h
bool operator== (const IpPort & other)
Defined at line 67 of file ../../src/lib/inet/ip_port.h
bool operator!= (const IpPort & other)
Defined at line 69 of file ../../src/lib/inet/ip_port.h