vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
net_address.h
1#pragma once
2
3#include <cstdint>
4#include <string>
5
6namespace Vkm::Engine {
7
13struct NetAddress {
14 uint32_t ipv4 = 0;
15 uint16_t port = 0;
16
18 explicit operator bool() const { return ipv4 != 0 && port != 0; }
19
20 bool operator==(const NetAddress& other) const {
21 return ipv4 == other.ipv4 && port == other.port;
22 }
23 bool operator!=(const NetAddress& other) const { return !(*this == other); }
24
35 static NetAddress parse(const std::string& text, uint16_t fallbackPort = 0);
36
46 static bool parsePort(const std::string& text, uint16_t& port);
47
49 std::string toString() const;
50};
51
52} // namespace Vkm::Engine
Where a datagram came from, or is going to: an IPv4 host and a port.
Definition net_address.h:13
static NetAddress parse(const std::string &text, uint16_t fallbackPort=0)
Read "host:port", or "host" with fallbackPort.
uint32_t ipv4
Host byte order: 0x7F000001 is 127.0.0.1.
Definition net_address.h:14
std::string toString() const
"127.0.0.1:27015", for a log line or a readout.
static bool parsePort(const std::string &text, uint16_t &port)
Read a port: decimal digits and nothing else, 1 to 65535.