diff options
author | Yaroslav De La Peña Smirnov <yaros.rus_89@live.com.mx> | 2017-11-29 11:44:34 +0300 |
---|---|---|
committer | Yaroslav De La Peña Smirnov <yaros.rus_89@live.com.mx> | 2017-11-29 11:44:34 +0300 |
commit | 67fdec20726e48ba3a934cb25bb30d47ec4a4f29 (patch) | |
tree | 37fd9f4f0b0c20103e1646fc83021e4765de3680 /node_modules/uws/src/Socket.cpp | |
download | spanish-checkers-67fdec20726e48ba3a934cb25bb30d47ec4a4f29.tar.gz spanish-checkers-67fdec20726e48ba3a934cb25bb30d47ec4a4f29.zip |
Initial commit, version 0.5.3
Diffstat (limited to 'node_modules/uws/src/Socket.cpp')
-rw-r--r-- | node_modules/uws/src/Socket.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/node_modules/uws/src/Socket.cpp b/node_modules/uws/src/Socket.cpp new file mode 100644 index 0000000..c35bbf8 --- /dev/null +++ b/node_modules/uws/src/Socket.cpp @@ -0,0 +1,28 @@ +#include "Socket.h" + +namespace uS { + +Socket::Address Socket::getAddress() +{ + uv_os_sock_t fd = getFd(); + + sockaddr_storage addr; + socklen_t addrLength = sizeof(addr); + if (getpeername(fd, (sockaddr *) &addr, &addrLength) == -1) { + return {0, "", ""}; + } + + static __thread char buf[INET6_ADDRSTRLEN]; + + if (addr.ss_family == AF_INET) { + sockaddr_in *ipv4 = (sockaddr_in *) &addr; + inet_ntop(AF_INET, &ipv4->sin_addr, buf, sizeof(buf)); + return {ntohs(ipv4->sin_port), buf, "IPv4"}; + } else { + sockaddr_in6 *ipv6 = (sockaddr_in6 *) &addr; + inet_ntop(AF_INET6, &ipv6->sin6_addr, buf, sizeof(buf)); + return {ntohs(ipv6->sin6_port), buf, "IPv6"}; + } +} + +} |