Mercurial > code
changeset 449:c3d55937754f
Socket: various small fixes
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 29 Oct 2015 21:10:56 +0100 |
parents | 5310aa051568 |
children | f5b491a14a28 |
files | C++/modules/Socket/Sockets.cpp C++/modules/Socket/Sockets.h |
diffstat | 2 files changed, 20 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/C++/modules/Socket/Sockets.cpp Thu Oct 29 20:18:00 2015 +0100 +++ b/C++/modules/Socket/Sockets.cpp Thu Oct 29 21:10:56 2015 +0100 @@ -219,6 +219,7 @@ Ip::Ip(const struct sockaddr_storage *ss, socklen_t length) : m_length{length} + , m_domain{ss->ss_family} { if (ss->ss_family == AF_INET6) { std::memcpy(&m_sin6, ss, length); @@ -247,10 +248,10 @@ m_sun.sun_family = AF_UNIX; } -Local::Local(const sockaddr_storage &ss, socklen_t length) +Local::Local(const sockaddr_storage *ss, socklen_t length) { - if (ss.ss_family == AF_UNIX) { - std::memcpy(&m_sun, &ss, length); + if (ss->ss_family == AF_UNIX) { + std::memcpy(&m_sun, ss, length); m_path = reinterpret_cast<const sockaddr_un &>(m_sun).sun_path; } else { throw std::invalid_argument{"invalid domain for local constructor"};
--- a/C++/modules/Socket/Sockets.h Thu Oct 29 20:18:00 2015 +0100 +++ b/C++/modules/Socket/Sockets.h Thu Oct 29 21:10:56 2015 +0100 @@ -978,6 +978,20 @@ { return m_length; } + + /** + * Get the port. + * + * @return the port + */ + inline int port() const noexcept + { + if (m_domain == AF_INET6) { + return ntohs(m_sin6.sin6_port); + } + + return ntohs(m_sin.sin_port); + } }; /** @@ -1075,7 +1089,7 @@ * * @return AF_LOCAL */ - inline int domain() noexcept + inline int domain() const noexcept { return AF_LOCAL; } @@ -1099,7 +1113,7 @@ * @param ss the storage * @param length the length */ - Local(const sockaddr_storage &ss, socklen_t length); + Local(const sockaddr_storage *ss, socklen_t length); /** * Get the sockaddr_un.