summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2016-12-05 16:32:38 +0100
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2016-12-09 18:24:59 +0100
commit1aff508dd9713abf0db0d0436fa7f7c4788c5a4a (patch)
treed3213c170d4e6aa90bf0bf2e62673728f2cac58c /platform
parenta77a0118f6b0d0878a53e2c963d91763b311163d (diff)
IP_Address now handle IPv4 and IPv6 transparently
IP_Address changes: - Converts to and from String transparently while handling IPv4 as IPv6 mapped (::ffff:[IP]) address internally. - Completely remove AddrType enum. - Setting/Getting of ip array is now only possible through dedicated functions (ie. set_ipv4, get_ipv4, set_ipv6, get_ipv6) - Add function to know if the address is a valid IPv4 (for IP implementation and enet)
Diffstat (limited to 'platform')
-rw-r--r--platform/windows/packet_peer_udp_winsock.cpp18
-rw-r--r--platform/windows/stream_peer_winsock.cpp2
2 files changed, 11 insertions, 9 deletions
diff --git a/platform/windows/packet_peer_udp_winsock.cpp b/platform/windows/packet_peer_udp_winsock.cpp
index 53524f807f..bad967eedd 100644
--- a/platform/windows/packet_peer_udp_winsock.cpp
+++ b/platform/windows/packet_peer_udp_winsock.cpp
@@ -53,12 +53,14 @@ Error PacketPeerUDPWinsock::get_packet(const uint8_t **r_buffer,int &r_buffer_si
uint32_t size;
uint8_t type;
rb.read(&type, 1, true);
- if (type == IP_Address::TYPE_IPV4) {
- rb.read((uint8_t*)&packet_ip.field8,4,true);
- packet_ip.type = IP_Address::TYPE_IPV4;
+ if (type == IP::TYPE_IPV4) {
+ uint8_t ip[4];
+ rb.read(ip,4,true);
+ packet_ip.set_ipv4(ip);
} else {
- rb.read((uint8_t*)&packet_ip.field8,16,true);
- packet_ip.type = IP_Address::TYPE_IPV6;
+ uint8_t ip[16];
+ rb.read(ip,16,true);
+ packet_ip.set_ipv6(ip);
};
rb.read((uint8_t*)&packet_port,4,true);
rb.read((uint8_t*)&size,4,true);
@@ -162,7 +164,7 @@ Error PacketPeerUDPWinsock::_poll(bool p_wait) {
uint32_t port = 0;
if (from.ss_family == AF_INET) {
- uint8_t type = (uint8_t)IP_Address::TYPE_IPV4;
+ uint8_t type = (uint8_t)IP::TYPE_IPV4;
rb.write(&type, 1);
struct sockaddr_in* sin_from = (struct sockaddr_in*)&from;
rb.write((uint8_t*)&sin_from->sin_addr, 4);
@@ -170,7 +172,7 @@ Error PacketPeerUDPWinsock::_poll(bool p_wait) {
} else if (from.ss_family == AF_INET6) {
- uint8_t type = (uint8_t)IP_Address::TYPE_IPV6;
+ uint8_t type = (uint8_t)IP::TYPE_IPV6;
rb.write(&type, 1);
struct sockaddr_in6* s6_from = (struct sockaddr_in6*)&from;
@@ -180,7 +182,7 @@ Error PacketPeerUDPWinsock::_poll(bool p_wait) {
} else {
// WARN_PRINT("Ignoring packet with unknown address family");
- uint8_t type = (uint8_t)IP_Address::TYPE_NONE;
+ uint8_t type = (uint8_t)IP::TYPE_NONE;
rb.write(&type, 1);
};
diff --git a/platform/windows/stream_peer_winsock.cpp b/platform/windows/stream_peer_winsock.cpp
index d40504b2d4..e9a017a0fa 100644
--- a/platform/windows/stream_peer_winsock.cpp
+++ b/platform/windows/stream_peer_winsock.cpp
@@ -300,7 +300,7 @@ void StreamPeerWinsock::set_socket(int p_sockfd, IP_Address p_host, int p_port,
Error StreamPeerWinsock::connect(const IP_Address& p_host, uint16_t p_port) {
- ERR_FAIL_COND_V( p_host.type == IP_Address::TYPE_NONE, ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V( p_host == IP_Address(), ERR_INVALID_PARAMETER);
sockfd = _socket_create(ip_type, SOCK_STREAM, IPPROTO_TCP);
if (sockfd == INVALID_SOCKET) {