Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
NetworkAddress.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
#include "
NetworkAddress.h
"
7
8
#if PLATFORM == PLATFORM_WINDOWS
9
#include <winsock2.h>
10
#else
11
#include <arpa/inet.h>
12
#endif
13
14
#include <boost/asio/ip/address_v4.hpp>
15
#include <boost/system/error_code.hpp>
16
17
namespace
18
{
19
bool
ParseIPv4Address(std::string
const
& host, boost::asio::ip::address_v4& address)
20
{
21
boost::system::error_code error;
22
address = boost::asio::ip::make_address_v4(host, error);
23
if
(error)
24
return
false
;
25
26
if
(address.to_string() != host)
27
return
false
;
28
29
return
address.to_uint() != boost::asio::ip::address_v4::uint_type(-1);
30
}
31
}
32
33
namespace
Skyfire::Net
34
{
35
Address::Address
() :
_host
(
"0.0.0.0"
),
_port
(0) { }
36
37
Address::Address
(std::string
const
& host,
uint16
port) :
_host
(host),
_port
(port) { }
38
39
bool
IsIPv4Address
(std::string
const
& host)
40
{
41
boost::asio::ip::address_v4 address;
42
return
ParseIPv4Address(host, address);
43
}
44
45
uint32
ToIPv4NetworkOrder
(std::string
const
& host)
46
{
47
boost::asio::ip::address_v4 address;
48
if
(!ParseIPv4Address(host, address))
49
return
0;
50
51
return
htonl(
static_cast<
uint32
>
(address.to_uint()));
52
}
53
54
bool
Address::IsLoopback
()
const
55
{
56
uint32
const
ip = ntohl(
ToIPv4NetworkOrder
());
57
return
(ip & 0xFF000000) == 0x7F000000;
58
}
59
60
uint32
Address::ToIPv4NetworkOrder
()
const
61
{
62
return
Skyfire::Net::ToIPv4NetworkOrder
(
_host
);
63
}
64
}
uint32
std::uint32_t uint32
Definition
Define.h:77
uint16
std::uint16_t uint16
Definition
Define.h:78
NetworkAddress.h
Skyfire::Net::Address::_port
uint16 _port
Definition
NetworkAddress.h:32
Skyfire::Net::Address::IsLoopback
bool IsLoopback() const
Definition
NetworkAddress.cpp:54
Skyfire::Net::Address::ToIPv4NetworkOrder
uint32 ToIPv4NetworkOrder() const
Definition
NetworkAddress.cpp:60
Skyfire::Net::Address::Address
Address()
Definition
NetworkAddress.cpp:35
Skyfire::Net::Address::_host
std::string _host
Definition
NetworkAddress.h:31
Skyfire::Net
Definition
WorldSocket.h:36
Skyfire::Net::IsIPv4Address
bool IsIPv4Address(std::string const &host)
Definition
NetworkAddress.cpp:39
Skyfire::Net::ToIPv4NetworkOrder
uint32 ToIPv4NetworkOrder(std::string const &host)
Definition
NetworkAddress.cpp:45
src
server
shared
Utilities
NetworkAddress.cpp
Generated on
for Project SkyFire Core by
1.17.0