SFML 3.0.2
Loading...
Searching...
No Matches
IpAddress.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2025 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
28// Headers
30#include <SFML/Network/Export.hpp>
31
32#include <SFML/System/Time.hpp>
33
34#include <iosfwd>
35#include <optional>
36#include <string>
37#include <string_view>
38
39#include <cstdint>
40
41
42 namespace sf
43{
48 class SFML_NETWORK_API IpAddress
49{
50 public:
62 [[nodiscard]] static std::optional<IpAddress> resolve(std::string_view address);
63
77 IpAddress(std::uint8_t byte0, std::uint8_t byte1, std::uint8_t byte2, std::uint8_t byte3);
78
92 explicit IpAddress(std::uint32_t address);
93
106 [[nodiscard]] std::string toString() const;
107
122 [[nodiscard]] std::uint32_t toInteger() const;
123
138 [[nodiscard]] static std::optional<IpAddress> getLocalAddress();
139
162 [[nodiscard]] static std::optional<IpAddress> getPublicAddress(Time timeout = Time::Zero);
163
165 // Static member data
167 // NOLINTBEGIN(readability-identifier-naming)
168 static const IpAddress Any;
169 static const IpAddress LocalHost;
170 static const IpAddress Broadcast;
171 // NOLINTEND(readability-identifier-naming)
172
173 private:
174 friend SFML_NETWORK_API bool operator<(IpAddress left, IpAddress right);
175
177 // Member data
179 std::uint32_t m_address;
180};
181
191[[nodiscard]] SFML_NETWORK_API bool operator==(IpAddress left, IpAddress right);
192
202[[nodiscard]] SFML_NETWORK_API bool operator!=(IpAddress left, IpAddress right);
203
213[[nodiscard]] SFML_NETWORK_API bool operator<(IpAddress left, IpAddress right);
214
224[[nodiscard]] SFML_NETWORK_API bool operator>(IpAddress left, IpAddress right);
225
235[[nodiscard]] SFML_NETWORK_API bool operator<=(IpAddress left, IpAddress right);
236
246[[nodiscard]] SFML_NETWORK_API bool operator>=(IpAddress left, IpAddress right);
247
257 SFML_NETWORK_API std::istream& operator>>(std::istream& stream, std::optional<IpAddress>& address);
258
268 SFML_NETWORK_API std::ostream& operator<<(std::ostream& stream, IpAddress address);
269
270} // namespace sf
271
272
Export.hpp
SFML_NETWORK_API
#define SFML_NETWORK_API
Definition Network/Export.hpp:42
Time.hpp
sf::IpAddress
Encapsulate an IPv4 network address.
Definition IpAddress.hpp:49
sf::IpAddress::getLocalAddress
static std::optional< IpAddress > getLocalAddress()
Get the computer's local address.
sf::IpAddress::getPublicAddress
static std::optional< IpAddress > getPublicAddress(Time timeout=Time::Zero)
Get the computer's public address.
sf::IpAddress::Any
static const IpAddress Any
Value representing any address (0.0.0.0).
Definition IpAddress.hpp:168
sf::IpAddress::resolve
static std::optional< IpAddress > resolve(std::string_view address)
Construct the address from a null-terminated string view.
sf::IpAddress::toInteger
std::uint32_t toInteger() const
Get an integer representation of the address.
sf::IpAddress::IpAddress
IpAddress(std::uint32_t address)
Construct the address from a 32-bits integer.
sf::IpAddress::LocalHost
static const IpAddress LocalHost
The "localhost" address (for connecting a computer to itself locally).
Definition IpAddress.hpp:169
sf::IpAddress::toString
std::string toString() const
Get a string representation of the address.
sf::IpAddress::Broadcast
static const IpAddress Broadcast
The "broadcast" address (for sending UDP messages to everyone on a local network).
Definition IpAddress.hpp:170
sf::IpAddress::operator<
friend bool operator<(IpAddress left, IpAddress right)
Overload of operator< to compare two IP addresses.
sf::IpAddress::IpAddress
IpAddress(std::uint8_t byte0, std::uint8_t byte1, std::uint8_t byte2, std::uint8_t byte3)
Construct the address from 4 bytes.
sf::Time
Represents a time value.
Definition Time.hpp:42
sf::Time::Zero
static const Time Zero
Predefined "zero" time value.
Definition Time.hpp:110
sf
Definition AudioResource.hpp:36
sf::operator!=
bool operator!=(IpAddress left, IpAddress right)
Overload of operator!= to compare two IP addresses.
sf::operator<
bool operator<(IpAddress left, IpAddress right)
Overload of operator< to compare two IP addresses.
sf::operator==
bool operator==(IpAddress left, IpAddress right)
Overload of operator== to compare two IP addresses.
sf::operator>
bool operator>(IpAddress left, IpAddress right)
Overload of operator> to compare two IP addresses.
sf::operator>=
bool operator>=(IpAddress left, IpAddress right)
Overload of operator>= to compare two IP addresses.
sf::operator>>
std::istream & operator>>(std::istream &stream, std::optional< IpAddress > &address)
Overload of operator>> to extract an IP address from an input stream.
sf::operator<=
bool operator<=(IpAddress left, IpAddress right)
Overload of operator<= to compare two IP addresses.
sf::operator<<
std::ostream & operator<<(std::ostream &stream, IpAddress address)
Overload of operator<< to print an IP address to an output stream.