From: Stephen Morris Date: Fri, 17 Feb 2012 15:56:48 +0000 (+0000) Subject: [1593] Addressed (re)review points X-Git-Tag: trac2351_base~248 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2ea7c1a1fbb55f0f2ba0e42fca3b4e237c5edd16;p=thirdparty%2Fkea.git [1593] Addressed (re)review points Conversion between socket structures is now done via the templated convertSockAddr() function. --- diff --git a/src/bin/sockcreator/Makefile.am b/src/bin/sockcreator/Makefile.am index 1ac46401f2..e954c02b30 100644 --- a/src/bin/sockcreator/Makefile.am +++ b/src/bin/sockcreator/Makefile.am @@ -15,4 +15,5 @@ CLEANFILES = *.gcno *.gcda pkglibexec_PROGRAMS = b10-sockcreator b10_sockcreator_SOURCES = sockcreator.cc sockcreator.h main.cc -b10_sockcreator_LDADD = $(top_builddir)/src/lib/util/io/libutil_io.la +b10_sockcreator_LDADD = $(top_builddir)/src/lib/util/io/libutil_io.la +b10_sockcreator_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la diff --git a/src/bin/sockcreator/sockcreator.cc b/src/bin/sockcreator/sockcreator.cc index 00e0e7d9fc..0b1e763c19 100644 --- a/src/bin/sockcreator/sockcreator.cc +++ b/src/bin/sockcreator/sockcreator.cc @@ -15,6 +15,7 @@ #include "sockcreator.h" #include +#include #include #include @@ -25,6 +26,7 @@ #include using namespace isc::util::io; +using namespace isc::util::io::internal; using namespace isc::socket_creator; namespace { @@ -126,11 +128,11 @@ handleRequest(const int input_fd, const int output_fd, sockaddr_in6 addr_in6; switch (type[1]) { // The address family - // The casting to apparently incompatible types by reinterpret_cast - // is required by the C low-level interface. + // The casting to apparently incompatible types is required by the + // C low-level interface. case '4': - addr = reinterpret_cast(&addr_in); + addr = convertSockAddr(&addr_in); addr_len = sizeof(addr_in); memset(&addr_in, 0, sizeof(addr_in)); addr_in.sin_family = AF_INET; @@ -140,8 +142,8 @@ handleRequest(const int input_fd, const int output_fd, break; case '6': - addr = reinterpret_cast(&addr_in6); - addr_len = sizeof addr_in6; + addr = convertSockAddr(&addr_in6); + addr_len = sizeof(addr_in6); memset(&addr_in6, 0, sizeof(addr_in6)); addr_in6.sin6_family = AF_INET6; readMessage(input_fd, &addr_in6.sin6_port, diff --git a/src/lib/util/io/sockaddr_util.h b/src/lib/util/io/sockaddr_util.h index 4c9149efa5..3ec6cf03e7 100644 --- a/src/lib/util/io/sockaddr_util.h +++ b/src/lib/util/io/sockaddr_util.h @@ -50,6 +50,13 @@ convertSockAddr(const SAType* sa) { return (static_cast(p)); } +template +const SAType* +convertSockAddr(const struct sockaddr* sa) { + const void* p = sa; + return (static_cast(p)); +} + template struct sockaddr* convertSockAddr(SAType* sa) { @@ -57,6 +64,13 @@ convertSockAddr(SAType* sa) { return (static_cast(p)); } +template +SAType* +convertSockAddr(struct sockaddr* sa) { + void* p = sa; + return (static_cast(p)); +} + } } }