added +int Socket::bindToIfceAddr()

This commit is contained in:
2018-10-18 10:37:00 +00:00
parent 05c2905a0a
commit d3ed032636
4 changed files with 34 additions and 0 deletions

View File

@ -308,6 +308,20 @@ int Socket::bind (const SocketAddress& target) QSE_CPP_NOEXCEPT
return 0;
}
int Socket::bindToIfceAddr (const qse_mchar_t* ifce, qse_uint16_t port) QSE_CPP_NOEXCEPT
{
SocketAddress addr;
if (this->getIfceAddress(ifce, &addr) <= -1) return -1;
return this->bind(addr);
}
int Socket::bindToIfceAddr (const qse_wchar_t* ifce, qse_uint16_t port) QSE_CPP_NOEXCEPT
{
SocketAddress addr;
if (this->getIfceAddress(ifce, &addr) <= -1) return -1;
return this->bind(addr);
}
int Socket::listen (int backlog) QSE_CPP_NOEXCEPT
{
QSE_ASSERT (this->handle != QSE_INVALID_SCKHND);

View File

@ -85,6 +85,7 @@
# define FAMILY(x) (-1)
#endif
#include <stdio.h>
/////////////////////////////////
QSE_BEGIN_NAMESPACE(QSE)
/////////////////////////////////
@ -128,6 +129,17 @@ void SocketAddress::setIpaddr (const qse_ip4ad_t* ipaddr) QSE_CPP_NOEXCEPT
#endif
}
void SocketAddress::setIpaddr (const qse_uint32_t ipaddr) QSE_CPP_NOEXCEPT
{
#if defined(AF_INET)
if (FAMILY(&this->skad) == AF_INET)
{
struct sockaddr_in* v4 = (struct sockaddr_in*)&this->skad;
v4->sin_addr.s_addr = ipaddr;
}
#endif
}
void SocketAddress::setIpaddr (const qse_ip6ad_t* ipaddr) QSE_CPP_NOEXCEPT
{
#if defined(AF_INET6)