From 0c4f9cb275de9eaf0fbcd3e452d744441daed9d0 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 5 Aug 2013 16:43:52 +1000 Subject: [PATCH] Fix headers and linking for network tests --- test/Makefile.am | 3 +++ test/hton.cpp | 9 +++++++-- test/ip.cpp | 23 ++++++++++++++++++----- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/test/Makefile.am b/test/Makefile.am index 93e160d3..4f903a83 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -32,6 +32,9 @@ TEST_BIN = \ AM_DEFAULT_SOURCE_EXT = .cpp LDADD = $(builddir)/../libutil.la +hton_LDFLAGS = -lws2_32 +ip_LDFLAGS = -lws2_32 + TESTS = $(TEST_BIN) json.pl check_PROGRAMS = $(TEST_BIN) EXTRA_DIST = json.pl diff --git a/test/hton.cpp b/test/hton.cpp index 46935167..aeed4113 100644 --- a/test/hton.cpp +++ b/test/hton.cpp @@ -2,10 +2,15 @@ #include "../endian.hpp" #include "../debug.hpp" +#include "../platform.hpp" #include -#include -#include +#if defined(PLATFORM_WIN32) + #include +#else + #include + #include +#endif using namespace std; diff --git a/test/ip.cpp b/test/ip.cpp index 38ecb498..d9ae5b8a 100644 --- a/test/ip.cpp +++ b/test/ip.cpp @@ -2,11 +2,17 @@ #include "../ip.hpp" #include "../debug.hpp" +#include "../platform.hpp" #include "../types.hpp" -#include #include +#if defined(PLATFORM_WIN32) + #include +#else + #include +#endif + using namespace std; @@ -26,10 +32,17 @@ main (int, char **) { ipv4::ip parsed (ipv4::ip::parse (data[i].str)); CHECK_HARD (parsed == data[i].ip); - uint32_t mine = *(uint32_t*)(parsed.m_octets), - theirs; - CHECK_HARD (inet_pton (AF_INET, data[i].str, &theirs) == 1); - CHECK_HARD (theirs == mine); + uint32_t mine = *(uint32_t*)(parsed.m_octets); + + struct addrinfo *theirs; + + int err = getaddrinfo (data[i].str, nullptr, nullptr, &theirs); + CHECK_EQ (err, 0); + + CHECK_EQ (mine, reinterpret_cast (theirs)->sin_addr.s_addr); + + //CHECK_HARD (inet_pton (AF_INET, data[i].str, &theirs) == 1); + //CHECK_HARD (theirs == mine); } return EXIT_SUCCESS;