From 812908e236e83db368dfef49b8badb9a6182e1de Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Fri, 28 Oct 2016 04:18:17 +0200 Subject: Fix windows debugger connection problems. Unify network socket creation between platform. Ensure IPV6_V6ONLY flag is not set on sockets (allow IPv4 connection in IPv6 socket, dual-stack). --- drivers/unix/packet_peer_udp_posix.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'drivers/unix/packet_peer_udp_posix.cpp') diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp index 0b172b6a51..01c26420a8 100644 --- a/drivers/unix/packet_peer_udp_posix.cpp +++ b/drivers/unix/packet_peer_udp_posix.cpp @@ -121,8 +121,6 @@ int PacketPeerUDPPosix::get_max_packet_size() const{ Error PacketPeerUDPPosix::listen(int p_port, IP_Address::AddrType p_address_type, int p_recv_buffer_size) { - ERR_FAIL_COND_V(p_address_type != IP_Address::TYPE_IPV4 && p_address_type != IP_Address::TYPE_IPV6, ERR_INVALID_PARAMETER); - close(); int sock = _get_socket(p_address_type); if (sock == -1 ) @@ -223,11 +221,7 @@ int PacketPeerUDPPosix::_get_socket(IP_Address::AddrType p_type) { if (sockfd != -1) return sockfd; - int family = p_type == IP_Address::TYPE_IPV6 ? AF_INET6 : AF_INET; - - sockfd = socket(family, SOCK_DGRAM, IPPROTO_UDP); - ERR_FAIL_COND_V( sockfd == -1, -1 ); - //fcntl(sockfd, F_SETFL, O_NONBLOCK); + sockfd = _socket_create(p_type, SOCK_DGRAM, IPPROTO_UDP); return sockfd; } -- cgit v1.2.3 From eb27e993f0f2fb3de48b7b8aa01c74cc1635a178 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Fri, 28 Oct 2016 23:11:53 +0200 Subject: TCP/UDP Listen sockets can now be set to IPv6 only --- drivers/unix/packet_peer_udp_posix.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'drivers/unix/packet_peer_udp_posix.cpp') diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp index 01c26420a8..ed295f0459 100644 --- a/drivers/unix/packet_peer_udp_posix.cpp +++ b/drivers/unix/packet_peer_udp_posix.cpp @@ -119,15 +119,24 @@ int PacketPeerUDPPosix::get_max_packet_size() const{ return 512; // uhm maybe not } -Error PacketPeerUDPPosix::listen(int p_port, IP_Address::AddrType p_address_type, int p_recv_buffer_size) { +Error PacketPeerUDPPosix::listen(int p_port, IP_Address::AddrType p_type, int p_recv_buffer_size) { close(); - int sock = _get_socket(p_address_type); + int sock = _get_socket(p_type); + if (sock == -1 ) return ERR_CANT_CREATE; + if(p_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, p_address_type, NULL); + size_t addr_size = _set_listen_sockaddr(&addr, p_port, p_type, NULL); if (bind(sock, (struct sockaddr*)&addr, addr_size) == -1 ) { close(); -- cgit v1.2.3 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/packet_peer_udp_posix.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'drivers/unix/packet_peer_udp_posix.cpp') diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp index ed295f0459..52f2c07134 100644 --- a/drivers/unix/packet_peer_udp_posix.cpp +++ b/drivers/unix/packet_peer_udp_posix.cpp @@ -96,7 +96,7 @@ 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); - int sock = _get_socket(peer_addr.type); + int sock = _get_socket(); ERR_FAIL_COND_V( sock == -1, FAILED ); struct sockaddr_storage addr; size_t addr_size = _set_sockaddr(&addr, peer_addr, peer_port); @@ -119,15 +119,15 @@ int PacketPeerUDPPosix::get_max_packet_size() const{ return 512; // uhm maybe not } -Error PacketPeerUDPPosix::listen(int p_port, IP_Address::AddrType p_type, int p_recv_buffer_size) { +Error PacketPeerUDPPosix::listen(int p_port, int p_recv_buffer_size) { close(); - int sock = _get_socket(p_type); + int sock = _get_socket(); if (sock == -1 ) return ERR_CANT_CREATE; - 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) { @@ -136,7 +136,7 @@ Error PacketPeerUDPPosix::listen(int p_port, IP_Address::AddrType p_type, int p_ } sockaddr_storage addr = {0}; - size_t addr_size = _set_listen_sockaddr(&addr, p_port, p_type, NULL); + size_t addr_size = _set_listen_sockaddr(&addr, p_port, ip_type, NULL); if (bind(sock, (struct sockaddr*)&addr, addr_size) == -1 ) { close(); @@ -225,12 +225,12 @@ int PacketPeerUDPPosix::get_packet_port() const{ return packet_port; } -int PacketPeerUDPPosix::_get_socket(IP_Address::AddrType p_type) { +int PacketPeerUDPPosix::_get_socket() { if (sockfd != -1) return sockfd; - sockfd = _socket_create(p_type, SOCK_DGRAM, IPPROTO_UDP); + sockfd = _socket_create(ip_type, SOCK_DGRAM, IPPROTO_UDP); return sockfd; } @@ -259,6 +259,7 @@ PacketPeerUDPPosix::PacketPeerUDPPosix() { packet_port=0; queue_count=0; peer_port=0; + ip_type = IP_Address::TYPE_ANY; } PacketPeerUDPPosix::~PacketPeerUDPPosix() { -- cgit v1.2.3 From 9200da58e4c2498c833d9f2505600c7049e80940 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Thu, 1 Dec 2016 04:23:57 +0100 Subject: Automatically map IPv4 address to IPv6 when needed --- drivers/unix/packet_peer_udp_posix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/unix/packet_peer_udp_posix.cpp') diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp index 52f2c07134..b1049582c4 100644 --- a/drivers/unix/packet_peer_udp_posix.cpp +++ b/drivers/unix/packet_peer_udp_posix.cpp @@ -99,7 +99,7 @@ Error PacketPeerUDPPosix::put_packet(const uint8_t *p_buffer,int p_buffer_size){ int sock = _get_socket(); ERR_FAIL_COND_V( sock == -1, FAILED ); struct sockaddr_storage addr; - size_t addr_size = _set_sockaddr(&addr, peer_addr, peer_port); + size_t addr_size = _set_sockaddr(&addr, peer_addr, peer_port, ip_type); errno = 0; int err; -- cgit v1.2.3 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 -------- 1 file changed, 8 deletions(-) (limited to 'drivers/unix/packet_peer_udp_posix.cpp') diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp index b1049582c4..44a3e65e00 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); -- cgit v1.2.3 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_ --- drivers/unix/packet_peer_udp_posix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/unix/packet_peer_udp_posix.cpp') diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp index 44a3e65e00..2b007f546f 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() { -- cgit v1.2.3 From 1aff508dd9713abf0db0d0436fa7f7c4788c5a4a Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Mon, 5 Dec 2016 16:32:38 +0100 Subject: 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) --- drivers/unix/packet_peer_udp_posix.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'drivers/unix/packet_peer_udp_posix.cpp') diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp index 2b007f546f..62290c4172 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); }; -- cgit v1.2.3 From c7bc44d5ad9aae4902280012f7654e2318cd910e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sun, 1 Jan 2017 22:01:57 +0100 Subject: Welcome in 2017, dear changelog reader! That year should bring the long-awaited OpenGL ES 3.0 compatible renderer with state-of-the-art rendering techniques tuned to work as low as middle end handheld devices - without compromising with the possibilities given for higher end desktop games of course. Great times ahead for the Godot community and the gamers that will play our games! --- drivers/unix/packet_peer_udp_posix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/unix/packet_peer_udp_posix.cpp') diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp index ed295f0459..2a2d8ba426 100644 --- a/drivers/unix/packet_peer_udp_posix.cpp +++ b/drivers/unix/packet_peer_udp_posix.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ -- cgit v1.2.3