summaryrefslogtreecommitdiffstats
path: root/drivers/unix/tcp_server_posix.cpp
diff options
context:
space:
mode:
authorAriel Manzur <ariel@godotengine.org>2016-10-20 07:04:10 -0300
committerAriel Manzur <ariel@godotengine.org>2016-10-20 07:04:10 -0300
commit672225b710815865449e7930255468d1c085b137 (patch)
tree995f4e845e0d908fd27a2dcc583a5a2bd3dbb672 /drivers/unix/tcp_server_posix.cpp
parent1c2ac490cf157402cac7f9dbc2a293d0c922def8 (diff)
downloadredot-engine-672225b710815865449e7930255468d1c085b137.tar.gz
added windows support for ipv6, cleaned up unix code
Diffstat (limited to 'drivers/unix/tcp_server_posix.cpp')
-rw-r--r--drivers/unix/tcp_server_posix.cpp36
1 files changed, 8 insertions, 28 deletions
diff --git a/drivers/unix/tcp_server_posix.cpp b/drivers/unix/tcp_server_posix.cpp
index 03312a7538..27c5618479 100644
--- a/drivers/unix/tcp_server_posix.cpp
+++ b/drivers/unix/tcp_server_posix.cpp
@@ -56,6 +56,8 @@
#include <sys/socket.h>
#include <assert.h>
+#include "drivers/unix/socket_helpers.h"
+
TCP_Server* TCPServerPosix::_create() {
return memnew(TCPServerPosix);
@@ -84,19 +86,9 @@ Error TCPServerPosix::listen(uint16_t p_port, IP_Address::AddrType p_type, const
WARN_PRINT("REUSEADDR failed!")
}
- sockaddr_storage addr = {0};
- if (p_type == IP_Address::TYPE_IPV4) {
- struct sockaddr_in* addr4 = (struct sockaddr_in*)&addr;
- addr4->sin_family = AF_INET;
- addr4->sin_port = htons(p_port);
- addr4->sin_addr.s_addr = INADDR_ANY;
- } else {
-
- struct sockaddr_in6* addr6 = (struct sockaddr_in6*)&addr;
- addr6->sin6_family = AF_INET6;
- addr6->sin6_port = htons(p_port);
- addr6->sin6_addr = in6addr_any;
- };
+ struct sockaddr_storage addr;
+ _set_listen_sockaddr(&addr, p_port, p_type, p_accepted_hosts);
+
// automatically fill with my IP TODO: use p_accepted_hosts
if (bind(sockfd, (struct sockaddr *)&addr, sizeof addr) != -1) {
@@ -161,22 +153,10 @@ Ref<StreamPeerTCP> TCPServerPosix::take_connection() {
Ref<StreamPeerTCPPosix> conn = memnew(StreamPeerTCPPosix);
IP_Address ip;
- if (their_addr.ss_family == AF_INET) {
- ip.type = IP_Address::TYPE_IPV4;
-
- struct sockaddr_in* addr4 = (struct sockaddr_in*)&their_addr;
- ip.field32[0] = (uint32_t)addr4->sin_addr.s_addr;
- conn->set_socket(fd, ip, ntohs(addr4->sin_port));
+ int port;
+ _set_ip_addr_port(ip, port, &their_addr);
- } else if (their_addr.ss_family == AF_INET6) {
-
- ip.type = IP_Address::TYPE_IPV6;
-
- struct sockaddr_in6* addr6 = (struct sockaddr_in6*)&their_addr;
- copymem(&addr6->sin6_addr.s6_addr, ip.field8, 16);
-
- conn->set_socket(fd, ip, ntohs(addr6->sin6_port));
- };
+ conn->set_socket(fd, ip, port);
return conn;
};