From 95bdd977686005d3d813eb09aca625384f1774c1 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Wed, 30 Nov 2016 20:45:19 +0100 Subject: Use an instance variable for ip_type in raw sockets PacketPeerUDP/StreamPeerTCP/TCP_Server now uses an instance variable to store the selected ip_type (IPv4/IPv6/ANY, where ANY = dual stack). All calls to resolve addresses, sending/receving data, connecting/listening will use that socket type. --- drivers/unix/tcp_server_posix.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'drivers/unix/tcp_server_posix.cpp') diff --git a/drivers/unix/tcp_server_posix.cpp b/drivers/unix/tcp_server_posix.cpp index 7028c1a10..e6f3614cb 100644 --- a/drivers/unix/tcp_server_posix.cpp +++ b/drivers/unix/tcp_server_posix.cpp @@ -68,14 +68,14 @@ void TCPServerPosix::make_default() { TCP_Server::_create = TCPServerPosix::_create; }; -Error TCPServerPosix::listen(uint16_t p_port, IP_Address::AddrType p_type, const List *p_accepted_hosts) { +Error TCPServerPosix::listen(uint16_t p_port,const List *p_accepted_hosts) { int sockfd; - sockfd = _socket_create(p_type, SOCK_STREAM, IPPROTO_TCP); + sockfd = _socket_create(ip_type, SOCK_STREAM, IPPROTO_TCP); ERR_FAIL_COND_V(sockfd == -1, FAILED); - if(p_type == IP_Address::TYPE_IPV6) { + if(ip_type == IP_Address::TYPE_IPV6) { // Use IPv6 only socket int yes = 1; if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&yes, sizeof(yes)) != 0) { @@ -95,7 +95,7 @@ Error TCPServerPosix::listen(uint16_t p_port, IP_Address::AddrType p_type, const } struct sockaddr_storage addr; - size_t addr_size = _set_listen_sockaddr(&addr, p_port, p_type, p_accepted_hosts); + size_t addr_size = _set_listen_sockaddr(&addr, p_port, ip_type, p_accepted_hosts); // automatically fill with my IP TODO: use p_accepted_hosts @@ -164,7 +164,7 @@ Ref TCPServerPosix::take_connection() { int port; _set_ip_addr_port(ip, port, &their_addr); - conn->set_socket(fd, ip, port); + conn->set_socket(fd, ip, port, ip_type); return conn; }; @@ -183,6 +183,7 @@ void TCPServerPosix::stop() { TCPServerPosix::TCPServerPosix() { listen_sockfd = -1; + ip_type = IP_Address::TYPE_ANY; }; TCPServerPosix::~TCPServerPosix() { -- cgit v1.2.3-70-g09d2 From 4d90a4fcd5fcdca42df47062f94a1fa4e5635a94 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Thu, 1 Dec 2016 05:05:44 +0100 Subject: Move V6ONLY flag selection inside helpers --- drivers/unix/packet_peer_udp_posix.cpp | 8 -------- drivers/unix/socket_helpers.h | 8 ++++---- drivers/unix/tcp_server_posix.cpp | 7 ------- platform/windows/packet_peer_udp_winsock.cpp | 8 -------- platform/windows/tcp_server_winsock.cpp | 8 -------- 5 files changed, 4 insertions(+), 35 deletions(-) (limited to 'drivers/unix/tcp_server_posix.cpp') diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp index b1049582c..44a3e65e0 100644 --- a/drivers/unix/packet_peer_udp_posix.cpp +++ b/drivers/unix/packet_peer_udp_posix.cpp @@ -127,14 +127,6 @@ Error PacketPeerUDPPosix::listen(int p_port, int p_recv_buffer_size) { if (sock == -1 ) return ERR_CANT_CREATE; - if(ip_type == IP_Address::TYPE_IPV6) { - // Use IPv6 only socket - int yes = 1; - if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&yes, sizeof(yes)) != 0) { - WARN_PRINT("Unable to unset IPv4 address mapping over IPv6"); - } - } - sockaddr_storage addr = {0}; size_t addr_size = _set_listen_sockaddr(&addr, p_port, ip_type, NULL); diff --git a/drivers/unix/socket_helpers.h b/drivers/unix/socket_helpers.h index a860c2f80..aec4ec884 100644 --- a/drivers/unix/socket_helpers.h +++ b/drivers/unix/socket_helpers.h @@ -78,10 +78,10 @@ static int _socket_create(IP_Address::AddrType p_type, int type, int protocol) { ERR_FAIL_COND_V( sockfd == -1, -1 ); if(family == AF_INET6) { - // Ensure IPv4 over IPv6 is enabled - int no = 0; - if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&no, sizeof(no)) != 0) { - WARN_PRINT("Unable to set IPv4 address mapping over IPv6"); + // Select IPv4 over IPv6 mapping + int opt = p_type != IP_Address::TYPE_ANY; + if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&opt, sizeof(opt)) != 0) { + WARN_PRINT("Unable to set/unset IPv4 address mapping over IPv6"); } } diff --git a/drivers/unix/tcp_server_posix.cpp b/drivers/unix/tcp_server_posix.cpp index e6f3614cb..bf3b7369e 100644 --- a/drivers/unix/tcp_server_posix.cpp +++ b/drivers/unix/tcp_server_posix.cpp @@ -75,13 +75,6 @@ Error TCPServerPosix::listen(uint16_t p_port,const List *p_accepted_host ERR_FAIL_COND_V(sockfd == -1, FAILED); - if(ip_type == IP_Address::TYPE_IPV6) { - // Use IPv6 only socket - int yes = 1; - if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&yes, sizeof(yes)) != 0) { - WARN_PRINT("Unable to unset IPv4 address mapping over IPv6"); - } - } #ifndef NO_FCNTL fcntl(sockfd, F_SETFL, O_NONBLOCK); #else diff --git a/platform/windows/packet_peer_udp_winsock.cpp b/platform/windows/packet_peer_udp_winsock.cpp index 9a5f6c6a3..4201a3e86 100644 --- a/platform/windows/packet_peer_udp_winsock.cpp +++ b/platform/windows/packet_peer_udp_winsock.cpp @@ -119,14 +119,6 @@ Error PacketPeerUDPWinsock::listen(int p_port, int p_recv_buffer_size) { if (sock == -1 ) return ERR_CANT_CREATE; - if(ip_type == IP_Address::TYPE_IPV6) { - // Use IPv6 only socket - int yes = 1; - if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&yes, sizeof(yes)) != 0) { - WARN_PRINT("Unable to unset IPv4 address mapping over IPv6"); - } - } - struct sockaddr_storage addr = {0}; size_t addr_size = _set_listen_sockaddr(&addr, p_port, ip_type, NULL); diff --git a/platform/windows/tcp_server_winsock.cpp b/platform/windows/tcp_server_winsock.cpp index eed03c9b8..89460eeaa 100644 --- a/platform/windows/tcp_server_winsock.cpp +++ b/platform/windows/tcp_server_winsock.cpp @@ -69,14 +69,6 @@ Error TCPServerWinsock::listen(uint16_t p_port,const List *p_accepted_ho sockfd = _socket_create(ip_type, SOCK_STREAM, IPPROTO_TCP); ERR_FAIL_COND_V(sockfd == INVALID_SOCKET, FAILED); - if(ip_type == IP_Address::TYPE_IPV6) { - // Use IPv6 only socket - int yes = 1; - if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&yes, sizeof(yes)) != 0) { - WARN_PRINT("Unable to unset IPv4 address mapping over IPv6"); - } - } - unsigned long par = 1; if (ioctlsocket(sockfd, FIONBIO, &par)) { perror("setting non-block mode"); -- cgit v1.2.3-70-g09d2 From c18c5013f837ea7d4de2f022d36f84e0abce6439 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Thu, 1 Dec 2016 06:34:05 +0100 Subject: Migrate int.IP_TYPE_ constants to IP.TYPE_ --- core/io/http_client.cpp | 6 ++---- core/io/http_client.h | 2 +- core/io/ip.cpp | 17 +++++++++------- core/io/ip.h | 18 +++++++++-------- core/io/packet_peer_udp.cpp | 4 +--- core/io/packet_peer_udp.h | 3 ++- core/io/stream_peer_tcp.cpp | 4 +--- core/io/stream_peer_tcp.h | 2 +- core/io/tcp_server.cpp | 4 +--- core/io/tcp_server.h | 2 +- core/variant_call.cpp | 4 ---- doc/base/classes.xml | 30 ++++++++-------------------- drivers/unix/ip_unix.cpp | 6 +++--- drivers/unix/ip_unix.h | 2 +- drivers/unix/packet_peer_udp_posix.cpp | 2 +- drivers/unix/socket_helpers.h | 18 ++++++++--------- drivers/unix/stream_peer_tcp_posix.cpp | 4 ++-- drivers/unix/stream_peer_tcp_posix.h | 2 +- drivers/unix/tcp_server_posix.cpp | 2 +- platform/windows/packet_peer_udp_winsock.cpp | 2 +- platform/windows/stream_peer_winsock.cpp | 4 ++-- platform/windows/stream_peer_winsock.h | 2 +- platform/windows/tcp_server_winsock.cpp | 2 +- 23 files changed, 61 insertions(+), 81 deletions(-) (limited to 'drivers/unix/tcp_server_posix.cpp') diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index e3289b452..c9c674d4f 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -29,9 +29,7 @@ #include "http_client.h" #include "io/stream_peer_ssl.h" -VARIANT_ENUM_CAST(IP_Address::AddrType); - -Error HTTPClient::connect(const String &p_host, int p_port, bool p_ssl,bool p_verify_host, IP_Address::AddrType p_addr_type){ +Error HTTPClient::connect(const String &p_host, int p_port, bool p_ssl,bool p_verify_host, IP::Type p_addr_type){ close(); conn_port=p_port; @@ -636,7 +634,7 @@ Error HTTPClient::_get_http_data(uint8_t* p_buffer, int p_bytes,int &r_received) void HTTPClient::_bind_methods() { - ObjectTypeDB::bind_method(_MD("connect:Error","host","port","use_ssl","verify_host"),&HTTPClient::connect,DEFVAL(false),DEFVAL(true),DEFVAL(IP_Address::TYPE_ANY)); + ObjectTypeDB::bind_method(_MD("connect:Error","host","port","use_ssl","verify_host"),&HTTPClient::connect,DEFVAL(false),DEFVAL(true),DEFVAL(IP::TYPE_ANY)); ObjectTypeDB::bind_method(_MD("set_connection","connection:StreamPeer"),&HTTPClient::set_connection); ObjectTypeDB::bind_method(_MD("get_connection:StreamPeer"),&HTTPClient::get_connection); ObjectTypeDB::bind_method(_MD("request_raw","method","url","headers","body"),&HTTPClient::request_raw); diff --git a/core/io/http_client.h b/core/io/http_client.h index ba464c34c..34812616d 100644 --- a/core/io/http_client.h +++ b/core/io/http_client.h @@ -165,7 +165,7 @@ public: //Error connect_and_get(const String& p_url,bool p_verify_host=true); //connects to a full url and perform request - Error connect(const String &p_host,int p_port,bool p_ssl=false,bool p_verify_host=true, IP_Address::AddrType p_addr_type = IP_Address::TYPE_ANY); + Error connect(const String &p_host,int p_port,bool p_ssl=false,bool p_verify_host=true, IP::Type p_addr_type = IP::TYPE_ANY); void set_connection(const Ref& p_connection); Ref get_connection() const; diff --git a/core/io/ip.cpp b/core/io/ip.cpp index f0f273af1..00835c26d 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -32,7 +32,6 @@ #include "hash_map.h" VARIANT_ENUM_CAST(IP::ResolverStatus); -VARIANT_ENUM_CAST(IP_Address::AddrType); /************* RESOLVER ******************/ @@ -44,12 +43,12 @@ struct _IP_ResolverPrivate { volatile IP::ResolverStatus status; IP_Address response; String hostname; - IP_Address::AddrType type; + IP::Type type; void clear() { status = IP::RESOLVER_STATUS_NONE; response = IP_Address(); - type = IP_Address::TYPE_NONE; + type = IP::TYPE_NONE; hostname=""; }; @@ -112,7 +111,7 @@ struct _IP_ResolverPrivate { -IP_Address IP::resolve_hostname(const String& p_hostname, IP_Address::AddrType p_type) { +IP_Address IP::resolve_hostname(const String& p_hostname, IP::Type p_type) { GLOBAL_LOCK_FUNCTION; @@ -126,7 +125,7 @@ IP_Address IP::resolve_hostname(const String& p_hostname, IP_Address::AddrType p return res; } -IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname, IP_Address::AddrType p_type) { +IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname, IP::Type p_type) { GLOBAL_LOCK_FUNCTION; @@ -212,8 +211,8 @@ Array IP::_get_local_addresses() const { void IP::_bind_methods() { - ObjectTypeDB::bind_method(_MD("resolve_hostname","host","ip_type"),&IP::resolve_hostname,DEFVAL(IP_Address::TYPE_ANY)); - ObjectTypeDB::bind_method(_MD("resolve_hostname_queue_item","host","ip_type"),&IP::resolve_hostname_queue_item,DEFVAL(IP_Address::TYPE_ANY)); + ObjectTypeDB::bind_method(_MD("resolve_hostname","host","ip_type"),&IP::resolve_hostname,DEFVAL(IP::TYPE_ANY)); + ObjectTypeDB::bind_method(_MD("resolve_hostname_queue_item","host","ip_type"),&IP::resolve_hostname_queue_item,DEFVAL(IP::TYPE_ANY)); ObjectTypeDB::bind_method(_MD("get_resolve_item_status","id"),&IP::get_resolve_item_status); ObjectTypeDB::bind_method(_MD("get_resolve_item_address","id"),&IP::get_resolve_item_address); ObjectTypeDB::bind_method(_MD("erase_resolve_item","id"),&IP::erase_resolve_item); @@ -228,6 +227,10 @@ void IP::_bind_methods() { BIND_CONSTANT( RESOLVER_MAX_QUERIES ); BIND_CONSTANT( RESOLVER_INVALID_ID ); + BIND_CONSTANT( TYPE_NONE ); + BIND_CONSTANT( TYPE_IPV4 ); + BIND_CONSTANT( TYPE_IPV6 ); + BIND_CONSTANT( TYPE_ANY ); } diff --git a/core/io/ip.h b/core/io/ip.h index 742dd0e74..64360b9a7 100644 --- a/core/io/ip.h +++ b/core/io/ip.h @@ -48,12 +48,12 @@ public: RESOLVER_STATUS_ERROR, }; - enum AddressType { + enum Type { - ADDRESS_IPV4 = 1, - ADDRESS_IPV6 = 2, - - ADDRESS_ANY = 3, + TYPE_NONE = 0, + TYPE_IPV4 = 1, + TYPE_IPV6 = 2, + TYPE_ANY = 3, }; enum { @@ -73,7 +73,7 @@ protected: static IP*singleton; static void _bind_methods(); - virtual IP_Address _resolve_hostname(const String& p_hostname, IP_Address::AddrType p_type = IP_Address::TYPE_ANY)=0; + virtual IP_Address _resolve_hostname(const String& p_hostname, Type p_type = TYPE_ANY)=0; Array _get_local_addresses() const; static IP* (*_create)(); @@ -81,9 +81,9 @@ public: - IP_Address resolve_hostname(const String& p_hostname, IP_Address::AddrType p_type = IP_Address::TYPE_ANY); + IP_Address resolve_hostname(const String& p_hostname, Type p_type = TYPE_ANY); // async resolver hostname - ResolverID resolve_hostname_queue_item(const String& p_hostname, IP_Address::AddrType p_type = IP_Address::TYPE_ANY); + ResolverID resolve_hostname_queue_item(const String& p_hostname, Type p_type = TYPE_ANY); ResolverStatus get_resolve_item_status(ResolverID p_id) const; IP_Address get_resolve_item_address(ResolverID p_id) const; virtual void get_local_addresses(List *r_addresses) const=0; @@ -101,4 +101,6 @@ public: }; +VARIANT_ENUM_CAST(IP::Type); + #endif // IP_H diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp index 810664791..dadef8a6f 100644 --- a/core/io/packet_peer_udp.cpp +++ b/core/io/packet_peer_udp.cpp @@ -31,8 +31,6 @@ PacketPeerUDP* (*PacketPeerUDP::_create)()=NULL; -VARIANT_ENUM_CAST(IP_Address::AddrType); - String PacketPeerUDP::_get_packet_ip() const { return get_packet_address(); @@ -83,5 +81,5 @@ PacketPeerUDP* PacketPeerUDP::create() { PacketPeerUDP::PacketPeerUDP() { - ip_type = IP_Address::TYPE_ANY; + ip_type = IP::TYPE_ANY; } diff --git a/core/io/packet_peer_udp.h b/core/io/packet_peer_udp.h index 011e8dd9a..821007a62 100644 --- a/core/io/packet_peer_udp.h +++ b/core/io/packet_peer_udp.h @@ -30,6 +30,7 @@ #define PACKET_PEER_UDP_H +#include "io/ip.h" #include "io/packet_peer.h" class PacketPeerUDP : public PacketPeer { @@ -37,7 +38,7 @@ class PacketPeerUDP : public PacketPeer { protected: - IP_Address::AddrType ip_type; + IP::Type ip_type; static PacketPeerUDP* (*_create)(); static void _bind_methods(); diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index b18bba4d2..d374f54a8 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -30,8 +30,6 @@ StreamPeerTCP* (*StreamPeerTCP::_create)()=NULL; -VARIANT_ENUM_CAST(IP_Address::AddrType); - Error StreamPeerTCP::_connect(const String& p_address,int p_port) { IP_Address ip; @@ -79,7 +77,7 @@ StreamPeerTCP* StreamPeerTCP::create() { StreamPeerTCP::StreamPeerTCP() { - ip_type = IP_Address::TYPE_ANY; + ip_type = IP::TYPE_ANY; } StreamPeerTCP::~StreamPeerTCP() { diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h index 10e061972..f44784d2b 100644 --- a/core/io/stream_peer_tcp.h +++ b/core/io/stream_peer_tcp.h @@ -51,7 +51,7 @@ public: protected: - IP_Address::AddrType ip_type; + IP::Type ip_type; virtual Error _connect(const String& p_address, int p_port); static StreamPeerTCP* (*_create)(); diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index 29e8bd0c0..0dcec8001 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -30,8 +30,6 @@ TCP_Server* (*TCP_Server::_create)()=NULL; -VARIANT_ENUM_CAST(IP_Address::AddrType); - Ref TCP_Server::create_ref() { if (!_create) @@ -68,5 +66,5 @@ void TCP_Server::_bind_methods() { TCP_Server::TCP_Server() { - ip_type = IP_Address::TYPE_ANY; + ip_type = IP::TYPE_ANY; } diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h index c380db52d..aef62eb71 100644 --- a/core/io/tcp_server.h +++ b/core/io/tcp_server.h @@ -38,7 +38,7 @@ class TCP_Server : public Reference { OBJ_TYPE( TCP_Server, Reference ); protected: - IP_Address::AddrType ip_type; + IP::Type ip_type; static TCP_Server* (*_create)(); diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 0379ae019..99d5d1065 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -1825,10 +1825,6 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl _VariantCall::add_constant(Variant::IMAGE,"INTERPOLATE_BILINEAR",Image::INTERPOLATE_BILINEAR); _VariantCall::add_constant(Variant::IMAGE,"INTERPOLATE_CUBIC",Image::INTERPOLATE_CUBIC); - _VariantCall::add_constant(Variant::INT, "IP_TYPE_NONE", IP_Address::TYPE_NONE); - _VariantCall::add_constant(Variant::INT, "IP_TYPE_IPV4", IP_Address::TYPE_IPV4); - _VariantCall::add_constant(Variant::INT, "IP_TYPE_IPV6", IP_Address::TYPE_IPV6); - _VariantCall::add_constant(Variant::INT, "IP_TYPE_ANY", IP_Address::TYPE_ANY); } void unregister_variant_methods() { diff --git a/doc/base/classes.xml b/doc/base/classes.xml index 07e2f719f..f1809d9e2 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -16082,7 +16082,7 @@ - + Resolve a given hostname, blocking. Resolved hostname is returned as an IPv4 or IPv6 depending on "ip_type". @@ -16093,7 +16093,7 @@ - + Create a queue item for resolving a given hostname to an IPv4 or IPv6 depending on "ip_type". The queue ID is returned, or RESOLVER_INVALID_ID on error. @@ -25375,15 +25375,10 @@ - - - + - Make this [PacketPeerUDP] listen on the "port" using protocol "ip_type" and a buffer size "recv_buf_size". Listens on all available adresses. - IP_TYPE_IPV4 = IPv4 only - IP_TYPE_IPV6 = IPv6 only - IP_TYPE_ANY = Dual stack (supports both IPv6 and IPv4 connections). + Make this [PacketPeerUDP] listen on the "port" with a buffer size "recv_buf_size". Listens on all available addresses. @@ -25393,10 +25388,8 @@ - - - Set the destination address and port for sending packets and variables, a hostname will be resolved using "ip_type" (v4/v6/any) if valid. + Set the destination address and port for sending packets and variables, a hostname will be resolved using if valid. @@ -39206,10 +39199,8 @@ - - - Connect to the specified host:port pair. A hostname will be resolved using "ip_type" (v4/v6/any) if valid. Returns [OK] on success or [FAILED] on failure. + Connect to the specified host:port pair. A hostname will be resolved if valid. Returns [OK] on success or [FAILED] on failure. @@ -40532,15 +40523,10 @@ - - - + - Listen on a port using protocol "ip_type", alternatively give a white-list of accepted hosts. - IP_TYPE_IPV4 = IPv4 only - IP_TYPE_IPV6 = IPv6 only - IP_TYPE_ANY = Dual stack (supports both IPv6 and IPv4 connections). + Listen on a port using protocol, alternatively give a white-list of accepted hosts. diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp index 8b8e09c91..ad49d0dca 100644 --- a/drivers/unix/ip_unix.cpp +++ b/drivers/unix/ip_unix.cpp @@ -87,15 +87,15 @@ static IP_Address _sockaddr2ip(struct sockaddr* p_addr) { return ip; }; -IP_Address IP_Unix::_resolve_hostname(const String& p_hostname, IP_Address::AddrType p_type) { +IP_Address IP_Unix::_resolve_hostname(const String& p_hostname, Type p_type) { struct addrinfo hints; struct addrinfo* result; memset(&hints, 0, sizeof(struct addrinfo)); - if (p_type == IP_Address::TYPE_IPV4) { + if (p_type == TYPE_IPV4) { hints.ai_family = AF_INET; - } else if (p_type == IP_Address::TYPE_IPV6) { + } else if (p_type == TYPE_IPV6) { hints.ai_family = AF_INET6; hints.ai_flags = 0; } else { diff --git a/drivers/unix/ip_unix.h b/drivers/unix/ip_unix.h index d198a330e..9959d45a1 100644 --- a/drivers/unix/ip_unix.h +++ b/drivers/unix/ip_unix.h @@ -36,7 +36,7 @@ class IP_Unix : public IP { OBJ_TYPE(IP_Unix, IP); - virtual IP_Address _resolve_hostname(const String& p_hostname, IP_Address::AddrType p_type); + virtual IP_Address _resolve_hostname(const String& p_hostname, IP::Type p_type); static IP* _create_unix(); public: diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp index 44a3e65e0..2b007f546 100644 --- a/drivers/unix/packet_peer_udp_posix.cpp +++ b/drivers/unix/packet_peer_udp_posix.cpp @@ -251,7 +251,7 @@ PacketPeerUDPPosix::PacketPeerUDPPosix() { packet_port=0; queue_count=0; peer_port=0; - ip_type = IP_Address::TYPE_ANY; + ip_type = IP::TYPE_ANY; } PacketPeerUDPPosix::~PacketPeerUDPPosix() { diff --git a/drivers/unix/socket_helpers.h b/drivers/unix/socket_helpers.h index aec4ec884..ffe201594 100644 --- a/drivers/unix/socket_helpers.h +++ b/drivers/unix/socket_helpers.h @@ -16,15 +16,15 @@ // helpers for sockaddr -> IP_Address and back, should work for posix and winsock. All implementations should use this -static size_t _set_sockaddr(struct sockaddr_storage* p_addr, const IP_Address& p_ip, int p_port, IP_Address::AddrType p_sock_type = IP_Address::TYPE_ANY) { +static size_t _set_sockaddr(struct sockaddr_storage* p_addr, const IP_Address& p_ip, int p_port, IP::Type p_sock_type = IP::TYPE_ANY) { memset(p_addr, 0, sizeof(struct sockaddr_storage)); // Dual stack (ANY) or matching ip type is required - ERR_FAIL_COND_V(p_sock_type != IP_Address::TYPE_ANY && p_sock_type != p_ip.type,0); + ERR_FAIL_COND_V(p_sock_type != IP::TYPE_ANY && p_sock_type != p_ip.type,0); // IPv6 socket - if (p_sock_type == IP_Address::TYPE_IPV6 || p_sock_type == IP_Address::TYPE_ANY) { + if (p_sock_type == IP::TYPE_IPV6 || p_sock_type == IP::TYPE_ANY) { struct sockaddr_in6* addr6 = (struct sockaddr_in6*)p_addr; addr6->sin6_family = AF_INET6; @@ -49,10 +49,10 @@ static size_t _set_sockaddr(struct sockaddr_storage* p_addr, const IP_Address& p }; }; -static size_t _set_listen_sockaddr(struct sockaddr_storage* p_addr, int p_port, IP_Address::AddrType p_address_type, const List *p_accepted_hosts) { +static size_t _set_listen_sockaddr(struct sockaddr_storage* p_addr, int p_port, IP::Type p_sock_type, const List *p_accepted_hosts) { memset(p_addr, 0, sizeof(struct sockaddr_storage)); - if (p_address_type == IP_Address::TYPE_IPV4) { + if (p_sock_type == IP::TYPE_IPV4) { struct sockaddr_in* addr4 = (struct sockaddr_in*)p_addr; addr4->sin_family = AF_INET; addr4->sin_port = htons(p_port); @@ -68,18 +68,18 @@ static size_t _set_listen_sockaddr(struct sockaddr_storage* p_addr, int p_port, }; }; -static int _socket_create(IP_Address::AddrType p_type, int type, int protocol) { +static int _socket_create(IP::Type p_type, int type, int protocol) { - ERR_FAIL_COND_V(p_type > IP_Address::TYPE_ANY || p_type < IP_Address::TYPE_NONE, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(p_type > IP::TYPE_ANY || p_type < IP::TYPE_NONE, ERR_INVALID_PARAMETER); - int family = p_type == IP_Address::TYPE_IPV4 ? AF_INET : AF_INET6; + int family = p_type == IP::TYPE_IPV4 ? AF_INET : AF_INET6; int sockfd = socket(family, type, protocol); ERR_FAIL_COND_V( sockfd == -1, -1 ); if(family == AF_INET6) { // Select IPv4 over IPv6 mapping - int opt = p_type != IP_Address::TYPE_ANY; + int opt = p_type != IP::TYPE_ANY; if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&opt, sizeof(opt)) != 0) { WARN_PRINT("Unable to set/unset IPv4 address mapping over IPv6"); } diff --git a/drivers/unix/stream_peer_tcp_posix.cpp b/drivers/unix/stream_peer_tcp_posix.cpp index 8aae1e77a..fc6b08e64 100644 --- a/drivers/unix/stream_peer_tcp_posix.cpp +++ b/drivers/unix/stream_peer_tcp_posix.cpp @@ -122,7 +122,7 @@ Error StreamPeerTCPPosix::_poll_connection(bool p_block) const { return OK; }; -void StreamPeerTCPPosix::set_socket(int p_sockfd, IP_Address p_host, int p_port, IP_Address::AddrType p_ip_type) { +void StreamPeerTCPPosix::set_socket(int p_sockfd, IP_Address p_host, int p_port, IP::Type p_ip_type) { ip_type = p_ip_type; sockfd = p_sockfd; @@ -393,7 +393,7 @@ StreamPeerTCPPosix::StreamPeerTCPPosix() { sockfd = -1; status = STATUS_NONE; peer_port = 0; - ip_type = IP_Address::TYPE_ANY; + ip_type = IP::TYPE_ANY; }; StreamPeerTCPPosix::~StreamPeerTCPPosix() { diff --git a/drivers/unix/stream_peer_tcp_posix.h b/drivers/unix/stream_peer_tcp_posix.h index 1d3e94c7c..e4e912117 100644 --- a/drivers/unix/stream_peer_tcp_posix.h +++ b/drivers/unix/stream_peer_tcp_posix.h @@ -69,7 +69,7 @@ public: virtual int get_available_bytes() const; - void set_socket(int p_sockfd, IP_Address p_host, int p_port, IP_Address::AddrType p_ip_type); + void set_socket(int p_sockfd, IP_Address p_host, int p_port, IP::Type p_ip_type); virtual IP_Address get_connected_host() const; virtual uint16_t get_connected_port() const; diff --git a/drivers/unix/tcp_server_posix.cpp b/drivers/unix/tcp_server_posix.cpp index bf3b7369e..dd00e0bf7 100644 --- a/drivers/unix/tcp_server_posix.cpp +++ b/drivers/unix/tcp_server_posix.cpp @@ -176,7 +176,7 @@ void TCPServerPosix::stop() { TCPServerPosix::TCPServerPosix() { listen_sockfd = -1; - ip_type = IP_Address::TYPE_ANY; + ip_type = IP::TYPE_ANY; }; TCPServerPosix::~TCPServerPosix() { diff --git a/platform/windows/packet_peer_udp_winsock.cpp b/platform/windows/packet_peer_udp_winsock.cpp index 4201a3e86..53524f807 100644 --- a/platform/windows/packet_peer_udp_winsock.cpp +++ b/platform/windows/packet_peer_udp_winsock.cpp @@ -269,7 +269,7 @@ PacketPeerUDPWinsock::PacketPeerUDPWinsock() { packet_port=0; queue_count=0; peer_port=0; - ip_type = IP_Address::TYPE_ANY; + ip_type = IP::TYPE_ANY; } PacketPeerUDPWinsock::~PacketPeerUDPWinsock() { diff --git a/platform/windows/stream_peer_winsock.cpp b/platform/windows/stream_peer_winsock.cpp index f03ecca22..d40504b2d 100644 --- a/platform/windows/stream_peer_winsock.cpp +++ b/platform/windows/stream_peer_winsock.cpp @@ -289,7 +289,7 @@ void StreamPeerWinsock::disconnect() { peer_port = 0; }; -void StreamPeerWinsock::set_socket(int p_sockfd, IP_Address p_host, int p_port, IP_Address::AddrType p_ip_type) { +void StreamPeerWinsock::set_socket(int p_sockfd, IP_Address p_host, int p_port, IP::Type p_ip_type) { ip_type = p_ip_type; sockfd = p_sockfd; @@ -368,7 +368,7 @@ StreamPeerWinsock::StreamPeerWinsock() { sockfd = INVALID_SOCKET; status = STATUS_NONE; peer_port = 0; - ip_type = IP_Address::TYPE_ANY; + ip_type = IP::TYPE_ANY; }; StreamPeerWinsock::~StreamPeerWinsock() { diff --git a/platform/windows/stream_peer_winsock.h b/platform/windows/stream_peer_winsock.h index 7a7ceab8a..c2b63e1ff 100644 --- a/platform/windows/stream_peer_winsock.h +++ b/platform/windows/stream_peer_winsock.h @@ -68,7 +68,7 @@ public: virtual int get_available_bytes() const; - void set_socket(int p_sockfd, IP_Address p_host, int p_port, IP_Address::AddrType p_ip_type); + void set_socket(int p_sockfd, IP_Address p_host, int p_port, IP::Type p_ip_type); virtual IP_Address get_connected_host() const; virtual uint16_t get_connected_port() const; diff --git a/platform/windows/tcp_server_winsock.cpp b/platform/windows/tcp_server_winsock.cpp index 89460eeaa..ac37f80e7 100644 --- a/platform/windows/tcp_server_winsock.cpp +++ b/platform/windows/tcp_server_winsock.cpp @@ -168,7 +168,7 @@ void TCPServerWinsock::stop() { TCPServerWinsock::TCPServerWinsock() { listen_sockfd = INVALID_SOCKET; - ip_type = IP_Address::TYPE_ANY; + ip_type = IP::TYPE_ANY; }; TCPServerWinsock::~TCPServerWinsock() { -- cgit v1.2.3-70-g09d2