Encapsulate an IPv4 network address. More...
#include <SFML/Network/IpAddress.hpp>
Public Member Functions | |
IpAddress () | |
Default constructor. | |
IpAddress (const std::string &address) | |
Construct the address from a string. | |
IpAddress (const char *address) | |
Construct the address from a string. | |
IpAddress (Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3) | |
Construct the address from 4 bytes. | |
IpAddress (Uint32 address) | |
Construct the address from a 32-bits integer. | |
std::string | toString () const |
Get a string representation of the address. | |
Uint32 | toInteger () const |
Get an integer representation of the address. | |
Static Public Member Functions | |
static IpAddress | getLocalAddress () |
Get the computer's local address. | |
static IpAddress | getPublicAddress (Time timeout=Time::Zero) |
Get the computer's public address. | |
Static Public Attributes | |
static const IpAddress | None |
Value representing an empty/invalid address. | |
static const IpAddress | Any |
Value representing any address (0.0.0.0) | |
static const IpAddress | LocalHost |
The "localhost" address (for connecting a computer to itself locally) | |
static const IpAddress | Broadcast |
The "broadcast" address (for sending UDP messages to everyone on a local network) | |
Friends | |
bool | operator< (const IpAddress &left, const IpAddress &right) |
Overload of < operator to compare two IP addresses. | |
Encapsulate an IPv4 network address.
sf::IpAddress is a utility class for manipulating network addresses.
It provides a set a implicit constructors and conversion functions to easily build or transform an IP address from/to various representations.
Usage example:
Note that sf::IpAddress currently doesn't support IPv6 nor other types of network addresses.
Definition at line 44 of file IpAddress.hpp.
sf::IpAddress::IpAddress | ( | ) |
Default constructor.
This constructor creates an empty (invalid) address
sf::IpAddress::IpAddress | ( | const std::string & | address | ) |
Construct the address from a string.
Here address can be either a decimal address (ex: "192.168.1.56") or a network name (ex: "localhost").
address | IP address or network name |
sf::IpAddress::IpAddress | ( | const char * | address | ) |
Construct the address from a string.
Here address can be either a decimal address (ex: "192.168.1.56") or a network name (ex: "localhost"). This is equivalent to the constructor taking a std::string parameter, it is defined for convenience so that the implicit conversions from literal strings to IpAddress work.
address | IP address or network name |
sf::IpAddress::IpAddress | ( | Uint8 | byte0, |
Uint8 | byte1, | ||
Uint8 | byte2, | ||
Uint8 | byte3 ) |
Construct the address from 4 bytes.
Calling IpAddress(a, b, c, d) is equivalent to calling IpAddress("a.b.c.d"), but safer as it doesn't have to parse a string to get the address components.
byte0 | First byte of the address |
byte1 | Second byte of the address |
byte2 | Third byte of the address |
byte3 | Fourth byte of the address |
|
explicit |
Construct the address from a 32-bits integer.
This constructor uses the internal representation of the address directly. It should be used for optimization purposes, and only if you got that representation from IpAddress::toInteger().
address | 4 bytes of the address packed into a 32-bits integer |
|
static |
Get the computer's local address.
The local address is the address of the computer from the LAN point of view, i.e. something like 192.168.1.56. It is meaningful only for communications over the local network. Unlike getPublicAddress, this function is fast and may be used safely anywhere.
|
static |
Get the computer's public address.
The public address is the address of the computer from the internet point of view, i.e. something like 89.54.1.169. It is necessary for communications over the world wide web. The only way to get a public address is to ask it to a distant website; as a consequence, this function depends on both your network connection and the server, and may be very slow. You should use it as few as possible. Because this function depends on the network connection and on a distant server, you may use a time limit if you don't want your program to be possibly stuck waiting in case there is a problem; this limit is deactivated by default.
timeout | Maximum time to wait |
Uint32 sf::IpAddress::toInteger | ( | ) | const |
Get an integer representation of the address.
The returned number is the internal representation of the address, and should be used for optimization purposes only (like sending the address through a socket). The integer produced by this function can then be converted back to a sf::IpAddress with the proper constructor.
std::string sf::IpAddress::toString | ( | ) | const |
Overload of < operator to compare two IP addresses.
left | Left operand (a IP address) |
right | Right operand (a IP address) |
|
static |
Value representing any address (0.0.0.0)
Definition at line 185 of file IpAddress.hpp.
|
static |
The "broadcast" address (for sending UDP messages to everyone on a local network)
Definition at line 187 of file IpAddress.hpp.
|
static |
The "localhost" address (for connecting a computer to itself locally)
Definition at line 186 of file IpAddress.hpp.
|
static |
Value representing an empty/invalid address.
Definition at line 184 of file IpAddress.hpp.