aboutsummaryrefslogtreecommitdiff
path: root/drivers/unix/packet_peer_udp_posix.cpp
diff options
context:
space:
mode:
authorFabio Alessandrelli2016-12-05 16:32:38 +0100
committerFabio Alessandrelli2017-01-04 00:46:33 +0100
commit00fdcf3cd000d0b2cf0bb1a95733ce905ca972f4 (patch)
treee6bfa1e7d1910adcab3c896ec559e24893d2c298 /drivers/unix/packet_peer_udp_posix.cpp
parent7ef71b901372eaa046479b8a946d64277fd4bf0c (diff)
downloadgodot-00fdcf3cd000d0b2cf0bb1a95733ce905ca972f4.tar.gz
godot-00fdcf3cd000d0b2cf0bb1a95733ce905ca972f4.tar.zst
godot-00fdcf3cd000d0b2cf0bb1a95733ce905ca972f4.zip
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) (cherry picked from commit 1aff508dd9713abf0db0d0436fa7f7c4788c5a4a)
Diffstat (limited to 'drivers/unix/packet_peer_udp_posix.cpp')
-rw-r--r--drivers/unix/packet_peer_udp_posix.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp
index 2b007f546..62290c417 100644
--- a/drivers/unix/packet_peer_udp_posix.cpp
+++ b/drivers/unix/packet_peer_udp_posix.cpp
@@ -76,12 +76,14 @@ Error PacketPeerUDPPosix::get_packet(const uint8_t **r_buffer,int &r_buffer_size
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 ipv6[16];
+ rb.read(ipv6,16,true);
+ packet_ip.set_ipv6(ipv6);
};
rb.read((uint8_t*)&packet_port,4,true);
rb.read((uint8_t*)&size,4,true);
@@ -94,7 +96,7 @@ Error PacketPeerUDPPosix::get_packet(const uint8_t **r_buffer,int &r_buffer_size
}
Error PacketPeerUDPPosix::put_packet(const uint8_t *p_buffer,int p_buffer_size){
- ERR_FAIL_COND_V(peer_addr.type == IP_Address::TYPE_NONE, ERR_UNCONFIGURED);
+ ERR_FAIL_COND_V(peer_addr == IP_Address(), ERR_UNCONFIGURED);
int sock = _get_socket();
ERR_FAIL_COND_V( sock == -1, FAILED );
@@ -163,7 +165,7 @@ Error PacketPeerUDPPosix::_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);
@@ -171,7 +173,7 @@ Error PacketPeerUDPPosix::_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;
@@ -181,7 +183,7 @@ Error PacketPeerUDPPosix::_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);
};