strip extra unneeded code from libutp

This commit is contained in:
despair86 2018-09-09 14:54:26 -05:00
parent af41b7bf80
commit 8845f3ecc5
5 changed files with 15 additions and 78 deletions

View File

@ -456,9 +456,8 @@ include_directories(include)
include_directories(vendor/cppbackport-master/lib)
include_directories(${sodium_INCLUDE_DIR})
if (MSVC)
if (WIN32)
include_directories(contrib/msc/include)
link_directories(contrib/msc/lib)
endif()
set(RC_EXE rcutil)

View File

@ -42,9 +42,11 @@
// hash.cpp needs socket definitions, which is why this networking specific
// code is inclued in utypes.h
#ifdef WIN32
#if defined WIN32 || defined _WIN32
#define _CRT_SECURE_NO_DEPRECATE
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>

View File

@ -24,85 +24,24 @@
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <wspiapi.h>
#include "libutp_inet_ntop.h"
// we already have our own definition of these
// -despair
extern "C" {
const char* inet_ntop(int af, const void *src, char *dst, size_t size);
int inet_pton(int af, const char *src, void *dst);
}
//######################################################################
const char *libutp::inet_ntop(int af, const void *src, char *dest, size_t length)
{
if (af != AF_INET && af != AF_INET6)
{
return NULL;
}
SOCKADDR_STORAGE address;
DWORD address_length;
if (af == AF_INET)
{
address_length = sizeof(sockaddr_in);
sockaddr_in* ipv4_address = (sockaddr_in*)(&address);
ipv4_address->sin_family = AF_INET;
ipv4_address->sin_port = 0;
memcpy(&ipv4_address->sin_addr, src, sizeof(in_addr));
}
else // AF_INET6
{
address_length = sizeof(sockaddr_in6);
sockaddr_in6* ipv6_address = (sockaddr_in6*)(&address);
ipv6_address->sin6_family = AF_INET6;
ipv6_address->sin6_port = 0;
ipv6_address->sin6_flowinfo = 0;
// hmmm
ipv6_address->sin6_scope_id = 0;
memcpy(&ipv6_address->sin6_addr, src, sizeof(in6_addr));
}
DWORD string_length = (DWORD)(length);
int result;
result = WSAAddressToStringA((sockaddr*)(&address),
address_length, 0, dest,
&string_length);
// one common reason for this to fail is that ipv6 is not installed
return result == SOCKET_ERROR ? NULL : dest;
return inet_ntop(af, src, dest, length);
}
//######################################################################
int libutp::inet_pton(int af, const char* src, void* dest)
{
if (af != AF_INET && af != AF_INET6)
{
return -1;
}
SOCKADDR_STORAGE address;
int address_length = sizeof(SOCKADDR_STORAGE);
int result = WSAStringToAddressA((char*)(src), af, 0,
(sockaddr*)(&address),
&address_length);
if (af == AF_INET)
{
if (result != SOCKET_ERROR)
{
sockaddr_in* ipv4_address =(sockaddr_in*)(&address);
memcpy(dest, &ipv4_address->sin_addr, sizeof(in_addr));
}
else if (strcmp(src, "255.255.255.255") == 0)
{
((in_addr*)(dest))->s_addr = INADDR_NONE;
}
}
else // AF_INET6
{
if (result != SOCKET_ERROR)
{
sockaddr_in6* ipv6_address = (sockaddr_in6*)(&address);
memcpy(dest, &ipv6_address->sin6_addr, sizeof(in6_addr));
}
}
return result == SOCKET_ERROR ? -1 : 1;
return inet_pton(af, src, dest);
}

View File

@ -30,11 +30,6 @@
// ut_utils/src/sockaddr.cpp
// libutp/win32_inet_ntop.obj
//
// When we drop support for XP we can just #include <ws2tcpip.h>, and use the system functions
// For now, we will always use our functions on windows, on all builds
// The reason is: we would like the debug build to behave as much as the release build as possible
// It is much better to catch a problem in the debug build, than to link the system version
// in debug, and our version int he wild.
#if defined(_WIN32_WINNT)
#if _WIN32_WINNT >= 0x600 // Win32, post-XP

View File

@ -26,7 +26,9 @@
#include "utp_types.h"
#ifdef WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>