Commit d8652650 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[trac999] introduced a new Client class in the server_common library.

right now it's simply constructed with an IOMessage and provides an interface
of the source endpoint/IP address.
The IPAddress class is adjusted a bit for that purpose.
parent 8d079547
......@@ -158,9 +158,13 @@ splitIPAddress(const std::string& addrmask) {
///
struct IPAddress {
explicit IPAddress(const struct sockaddr& sa);
const int family;
const uint8_t* const data;
const size_t length;
int getFamily() const { return (family); }
const uint8_t* getData() const { return (data); }
size_t getLength() const { return (length); }
private:
int family;
const uint8_t* data;
size_t length;
};
/// \brief IP Check
......
......@@ -177,9 +177,9 @@ getSockAddr(const char* const addr) {
TEST(IPAddress, constructIPv4) {
IPAddress ipaddr(getSockAddr("192.0.2.1"));
const char expected_data[4] = { 192, 0, 2, 1 };
EXPECT_EQ(AF_INET, ipaddr.family);
EXPECT_EQ(4, ipaddr.length);
EXPECT_EQ(0, memcmp(expected_data, ipaddr.data, 4));
EXPECT_EQ(AF_INET, ipaddr.getFamily());
EXPECT_EQ(4, ipaddr.getLength());
EXPECT_EQ(0, memcmp(expected_data, ipaddr.getData(), 4));
}
TEST(IPAddress, constructIPv6) {
......@@ -187,9 +187,9 @@ TEST(IPAddress, constructIPv6) {
const char expected_data[16] = { 0x20, 0x01, 0x0d, 0xb8, 0x12, 0x34, 0xab,
0xcd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x53 };
EXPECT_EQ(AF_INET6, ipaddr.family);
EXPECT_EQ(16, ipaddr.length);
EXPECT_EQ(0, memcmp(expected_data, ipaddr.data, 16));
EXPECT_EQ(AF_INET6, ipaddr.getFamily());
EXPECT_EQ(16, ipaddr.getLength());
EXPECT_EQ(0, memcmp(expected_data, ipaddr.getData(), 16));
}
TEST(IPAddress, badConstruct) {
......
......@@ -17,13 +17,15 @@ AM_CXXFLAGS += -Wno-unused-parameter
endif
lib_LTLIBRARIES = libserver_common.la
libserver_common_la_SOURCES = portconfig.h portconfig.cc
libserver_common_la_SOURCES = client.h client.cc
libserver_common_la_SOURCES += keyring.h keyring.cc
libserver_common_la_SOURCES += portconfig.h portconfig.cc
libserver_common_la_LIBADD = $(top_builddir)/src/lib/exceptions/libexceptions.la
libserver_common_la_LIBADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
libserver_common_la_LIBADD += $(top_builddir)/src/lib/cc/libcc.la
libserver_common_la_LIBADD += $(top_builddir)/src/lib/config/libcfgclient.la
libserver_common_la_LIBADD += $(top_builddir)/src/lib/log/liblog.la
libserver_common_la_LIBADD += $(top_builddir)/src/lib/acl/libacl.la
libserver_common_la_LIBADD += $(top_builddir)/src/lib/dns/libdns++.la
CLEANFILES = *.gcno *.gcda
......@@ -26,6 +26,7 @@ TESTS =
if HAVE_GTEST
TESTS += run_unittests
run_unittests_SOURCES = run_unittests.cc
run_unittests_SOURCES += client_unittest.cc
run_unittests_SOURCES += portconfig_unittest.cc
run_unittests_SOURCES += keyring_test.cc
nodist_run_unittests_SOURCES = data_path.h
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment