posix/socket: allow binding with sockaddr

This commit is contained in:
Danny Robson 2019-02-02 18:11:30 +11:00
parent 54df664071
commit 46ff7299bf
2 changed files with 19 additions and 7 deletions

View File

@ -134,15 +134,26 @@ socket::operator= (socket &&rhs) noexcept
///////////////////////////////////////////////////////////////////////////////
void
socket::bind (sockaddr const &addr)
{
auto const size = addr.sa_family == AF_INET ? sizeof (sockaddr_in )
: addr.sa_family == AF_INET6 ? sizeof (sockaddr_in6)
: throw std::runtime_error ("Unhandled sockaddr type");
cruft::posix::error::try_call (
::bind,
native (),
&addr,
size
);
}
//-----------------------------------------------------------------------------
void
socket::bind (sockaddr_in const &addr)
{
cruft::posix::error::try_code (
::bind (
native (),
reinterpret_cast<sockaddr const*> (&addr),
sizeof (addr)
)
);
return bind (reinterpret_cast<sockaddr const&> (addr));
}

View File

@ -44,6 +44,7 @@ namespace cruft::posix {
// because windows...
~socket ();
void bind (::sockaddr const&);
void bind (::sockaddr_in const&);
void connect (::sockaddr_in const&);