added +int Socket::bindToIfceAddr()

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

View File

@ -76,10 +76,17 @@ public:
int shutdown (int how = 2) QSE_CPP_NOEXCEPT;
int connect (const SocketAddress& target) QSE_CPP_NOEXCEPT;
int bind (const SocketAddress& target) QSE_CPP_NOEXCEPT;
// bind to the ip address of the interface
int bindToIfceAddr (const qse_mchar_t* ifce, qse_uint16_t port) QSE_CPP_NOEXCEPT;
// bind to the ip address of the interface
int bindToIfceAddr (const qse_wchar_t* ifce, qse_uint16_t port) QSE_CPP_NOEXCEPT;
int listen (int backlog = 128) QSE_CPP_NOEXCEPT;
int accept (Socket* newsck, SocketAddress* newaddr, int traits = 0) QSE_CPP_NOEXCEPT;
// The send() functions sends data by attemping a single call to the
// underlying system calls
qse_ssize_t send (const void* buf, qse_size_t len) QSE_CPP_NOEXCEPT;

View File

@ -66,6 +66,7 @@ public:
void setIpaddr (const qse_ip4ad_t* ipaddr) QSE_CPP_NOEXCEPT;
void setIpaddr (const qse_ip6ad_t* ipaddr) QSE_CPP_NOEXCEPT;
void setIpaddr (qse_uint32_t ipaddr) QSE_CPP_NOEXCEPT;
const qse_ip4ad_t* getIp4addr () const QSE_CPP_NOEXCEPT;
const qse_ip6ad_t* getIp6addr () const QSE_CPP_NOEXCEPT;

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)