Fix headers and linking for network tests

This commit is contained in:
Danny Robson 2013-08-05 16:43:52 +10:00
parent 798ea55ec9
commit 0c4f9cb275
3 changed files with 28 additions and 7 deletions

View File

@ -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

View File

@ -2,10 +2,15 @@
#include "../endian.hpp"
#include "../debug.hpp"
#include "../platform.hpp"
#include <cstdlib>
#if defined(PLATFORM_WIN32)
#include <winsock2.h>
#else
#include <arpa/inet.h>
#include <netinet/in.h>
#endif
using namespace std;

View File

@ -2,11 +2,17 @@
#include "../ip.hpp"
#include "../debug.hpp"
#include "../platform.hpp"
#include "../types.hpp"
#include <arpa/inet.h>
#include <cstdlib>
#if defined(PLATFORM_WIN32)
#include <ws2tcpip.h>
#else
#include <arpa/inet.h>
#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<sockaddr_in*> (theirs)->sin_addr.s_addr);
//CHECK_HARD (inet_pton (AF_INET, data[i].str, &theirs) == 1);
//CHECK_HARD (theirs == mine);
}
return EXIT_SUCCESS;