You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
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)
This commit is contained in:
@@ -75,13 +75,10 @@ static IP_Address _sockaddr2ip(struct sockaddr* p_addr) {
|
||||
IP_Address ip;
|
||||
if (p_addr->sa_family == AF_INET) {
|
||||
struct sockaddr_in* addr = (struct sockaddr_in*)p_addr;
|
||||
ip.field32[0] = *((unsigned long*)&addr->sin_addr);
|
||||
ip.type = IP_Address::TYPE_IPV4;
|
||||
ip.set_ipv4((uint8_t *)&(addr->sin_addr));
|
||||
} else {
|
||||
struct sockaddr_in6* addr6 = (struct sockaddr_in6*)p_addr;
|
||||
for (int i=0; i<16; i++)
|
||||
ip.field8[i] = addr6->sin6_addr.s6_addr[i];
|
||||
ip.type = IP_Address::TYPE_IPV6;
|
||||
ip.set_ipv6(addr6->sin6_addr.s6_addr);
|
||||
};
|
||||
|
||||
return ip;
|
||||
@@ -189,15 +186,12 @@ void IP_Unix::get_local_addresses(List<IP_Address> *r_addresses) const {
|
||||
|
||||
SOCKADDR_IN* ipv4 = reinterpret_cast<SOCKADDR_IN*>(address->Address.lpSockaddr);
|
||||
|
||||
ip.field32[0] = *((unsigned long*)&ipv4->sin_addr);
|
||||
ip.type = IP_Address::TYPE_IPV4;
|
||||
ip.set_ipv4((uint8_t *)&(ipv4->sin_addr));
|
||||
} else { // ipv6
|
||||
|
||||
SOCKADDR_IN6* ipv6 = reinterpret_cast<SOCKADDR_IN6*>(address->Address.lpSockaddr);
|
||||
for (int i=0; i<16; i++) {
|
||||
ip.field8[i] = ipv6->sin6_addr.s6_addr[i];
|
||||
};
|
||||
ip.type = IP_Address::TYPE_IPV6;
|
||||
|
||||
ip.set_ipv6(ipv6->sin6_addr.s6_addr);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user