Skip to content

Commit

Permalink
Minor updates to compile IPv6 and socket options under Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
fpagliughi committed Jun 30, 2019
1 parent 505a93a commit c51b35f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
8 changes: 2 additions & 6 deletions include/sockpp/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,7 @@ class socket
* @return bool @em true if the value was retrieved, @em false if an error
* occurred.
*/
bool get_option(int level, int optname, void* optval, socklen_t* optlen) {
return check_ret_bool(::getsockopt(handle_, level, optname, optval, optlen));
}
bool get_option(int level, int optname, void* optval, socklen_t* optlen);
/**
* Sets the value of a socket option.
*
Expand All @@ -276,9 +274,7 @@ class socket
* @return bool @em true if the value was set, @em false if an error
* occurred.
*/
bool set_option(int level, int optname, void* optval, socklen_t optlen) {
return check_ret_bool(::setsockopt(handle_, level, optname, optval, optlen));
}
bool set_option(int level, int optname, void* optval, socklen_t optlen);
/**
* Gets a string describing the specified error.
* This is typically the returned message from the system strerror().
Expand Down
6 changes: 4 additions & 2 deletions src/inet6_address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ void inet6_address::create(const string& saddr, in_port_t port)
string inet6_address::to_string() const
{
char buf[INET6_ADDRSTRLEN];
auto str = inet_ntop(AF_INET6, &this->sin6_addr, buf, INET6_ADDRSTRLEN);
auto str = inet_ntop(AF_INET6, (void*) &this->sin6_addr,
buf, INET6_ADDRSTRLEN);
return std::string("[") + std::string(str ? str : "<unknown>")
+ "]:" + std::to_string(unsigned(port()));
}
Expand All @@ -115,7 +116,8 @@ string inet6_address::to_string() const
ostream& operator<<(ostream& os, const inet6_address& addr)
{
char buf[INET6_ADDRSTRLEN];
auto str = inet_ntop(AF_INET6, &addr.sin6_addr, buf, INET6_ADDRSTRLEN);
auto str = inet_ntop(AF_INET6, (void*) &addr.sin6_addr,
buf, INET6_ADDRSTRLEN);
os << "[" << (str ? str : "<unknown>") << "]:" << unsigned(addr.port());
return os;
}
Expand Down
23 changes: 21 additions & 2 deletions src/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,30 @@ sock_address socket::peer_address() const

// --------------------------------------------------------------------------

//bool socket::get_option(int level, int optname, void* optval, socklen_t* optlen)
bool socket::get_option(int level, int optname, void* optval, socklen_t* optlen)
{
#if defined(WIN32)
int len = static_cast<int>(*optlen);
return check_ret_bool(::getsockopt(handle_, level, optname,
static_cast<char*>(optval), &len));
*optlen = static_cast<socklen_t>(len);
#else
return check_ret_bool(::getsockopt(handle_, level, optname, optval, optlen));
#endif
}

// --------------------------------------------------------------------------

//bool socket::set_option(int level, int optname, void* optval, socklen_t optlen)
bool socket::set_option(int level, int optname, void* optval, socklen_t optlen)
{
#if defined(WIN32)
return check_ret_bool(::setsockopt(handle_, level, optname,
static_cast<const char*>(optval),
static_cast<int>(optlen)));
#else
return check_ret_bool(::setsockopt(handle_, level, optname, optval, optlen));
#endif
}

// --------------------------------------------------------------------------
// Gets a description of the last error encountered.
Expand Down

0 comments on commit c51b35f

Please sign in to comment.