added the family parameter to Socket::get_ifce_address()

This commit is contained in:
hyung-hwan 2020-08-31 16:01:02 +00:00
parent ee44b2953f
commit db0457fe73
4 changed files with 111 additions and 27 deletions

View File

@ -146,32 +146,38 @@ public:
int getIfceIndex (const qse_wchar_t* name, qse_size_t len) QSE_CPP_NOEXCEPT;
// --------------------------------------------------------------------
// the following 6 functions are provided for backward compatibility.
// the following 24 functions are provided for backward compatibility.
// it is limited to a single address and they may suffer race condition.
// for example, you call getIfceAddress() followed by getIfceNetmask().
// the network configuration information may change in between.
// the address/netmask pair may not be the valid fixed combination.
int getIfceAddress (const qse_mchar_t* name, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT;
int getIfceAddress (const qse_wchar_t* name, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT;
int getIfceAddress (const qse_mchar_t* name, SocketAddress* addr) QSE_CPP_NOEXCEPT
{
return this->getIfceAddress(name, addr, this->domain);
}
int getIfceAddress (const qse_wchar_t* name, SocketAddress* addr) QSE_CPP_NOEXCEPT
{
return this->getIfceAddress(name, addr, this->domain);
}
int getIfceAddress (const qse_mchar_t* name, SocketAddress* addr) QSE_CPP_NOEXCEPT;
int getIfceAddress (const qse_wchar_t* name, SocketAddress* addr) QSE_CPP_NOEXCEPT;
int getIfceNetmask (const qse_mchar_t* name, SocketAddress* addr) QSE_CPP_NOEXCEPT;
int getIfceNetmask (const qse_wchar_t* name, SocketAddress* addr) QSE_CPP_NOEXCEPT;
int getIfceBroadcast (const qse_mchar_t* name, SocketAddress* addr) QSE_CPP_NOEXCEPT;
int getIfceBroadcast (const qse_wchar_t* name, SocketAddress* addr) QSE_CPP_NOEXCEPT;
int getIfceAddress (const qse_mchar_t* name, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT;
int getIfceAddress (const qse_wchar_t* name, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT;
int getIfceNetmask (const qse_mchar_t* name, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT;
int getIfceNetmask (const qse_wchar_t* name, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT;
int getIfceBroadcast (const qse_mchar_t* name, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT;
int getIfceBroadcast (const qse_wchar_t* name, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT;
int getIfceAddress (const qse_mchar_t* name, qse_size_t len, SocketAddress* addr) QSE_CPP_NOEXCEPT;
int getIfceAddress (const qse_wchar_t* name, qse_size_t len, SocketAddress* addr) QSE_CPP_NOEXCEPT;
int getIfceNetmask (const qse_mchar_t* name, qse_size_t len, SocketAddress* addr) QSE_CPP_NOEXCEPT;
int getIfceNetmask (const qse_wchar_t* name, qse_size_t len, SocketAddress* addr) QSE_CPP_NOEXCEPT;
int getIfceBroadcast (const qse_mchar_t* name, qse_size_t len, SocketAddress* addr) QSE_CPP_NOEXCEPT;
int getIfceBroadcast (const qse_wchar_t* name, qse_size_t len, SocketAddress* addr) QSE_CPP_NOEXCEPT;
int getIfceAddress (const qse_mchar_t* name, qse_size_t len, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT;
int getIfceAddress (const qse_wchar_t* name, qse_size_t len, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT;
int getIfceNetmask (const qse_mchar_t* name, qse_size_t len, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT;
int getIfceNetmask (const qse_wchar_t* name, qse_size_t len, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT;
int getIfceBroadcast (const qse_mchar_t* name, qse_size_t len, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT;
int getIfceBroadcast (const qse_wchar_t* name, qse_size_t len, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT;
// --------------------------------------------------------------------
protected:
@ -179,7 +185,7 @@ protected:
int domain;
int get_ifce_index (const void* name, qse_size_t len, bool wchar);
int get_ifce_address (int cmd, const void* name, qse_size_t len, bool wchar, SocketAddress* addr);
int get_ifce_address (int cmd, const void* name, qse_size_t len, bool wchar, SocketAddress* addr, int family);
};

View File

@ -116,6 +116,18 @@ protected:
qse_skad_t skad;
};
#if 0
class IfceAddress
{
QSE::String name;
unsigned int flags;
SocketAddress addr;
SocketAddress netmask;
SocketAddress broadcast; // also used as dstaddr for a point-to-point interface
};
#endif
/////////////////////////////////
QSE_END_NAMESPACE(QSE)
/////////////////////////////////

View File

@ -1129,67 +1129,134 @@ int Socket::get_ifce_index (const void* name, qse_size_t len, bool wchar)
#endif
}
// ----------------------------------------------------------------------------
int Socket::getIfceAddress (const qse_mchar_t* name, SocketAddress* addr) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFADDR, name, qse_mbslen(name), false, addr);
return this->get_ifce_address(SIOCGIFADDR, name, qse_mbslen(name), false, addr, this->domain);
}
int Socket::getIfceAddress (const qse_wchar_t* name, SocketAddress* addr) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFADDR, name, qse_wcslen(name), true, addr);
return this->get_ifce_address(SIOCGIFADDR, name, qse_wcslen(name), true, addr, this->domain);
}
int Socket::getIfceNetmask(const qse_mchar_t* name, SocketAddress* addr) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFNETMASK, name, qse_mbslen(name), false, addr);
return this->get_ifce_address(SIOCGIFNETMASK, name, qse_mbslen(name), false, addr, this->domain);
}
int Socket::getIfceNetmask (const qse_wchar_t* name, SocketAddress* addr) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFNETMASK, name, qse_wcslen(name), true, addr);
return this->get_ifce_address(SIOCGIFNETMASK, name, qse_wcslen(name), true, addr, this->domain);
}
int Socket::getIfceBroadcast(const qse_mchar_t* name, SocketAddress* addr) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFBRDADDR, name, qse_mbslen(name), false, addr);
return this->get_ifce_address(SIOCGIFBRDADDR, name, qse_mbslen(name), false, addr, this->domain);
}
int Socket::getIfceBroadcast (const qse_wchar_t* name, SocketAddress* addr) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFBRDADDR, name, qse_wcslen(name), true, addr);
return this->get_ifce_address(SIOCGIFBRDADDR, name, qse_wcslen(name), true, addr, this->domain);
}
// ----------------------------------------------------------------------------
int Socket::getIfceAddress (const qse_mchar_t* name, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFADDR, name, qse_mbslen(name), false, addr, family);
}
int Socket::getIfceAddress (const qse_wchar_t* name, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFADDR, name, qse_wcslen(name), true, addr, family);
}
int Socket::getIfceNetmask(const qse_mchar_t* name, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFNETMASK, name, qse_mbslen(name), false, addr, family);
}
int Socket::getIfceNetmask (const qse_wchar_t* name, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFNETMASK, name, qse_wcslen(name), true, addr, family);
}
int Socket::getIfceBroadcast(const qse_mchar_t* name, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFBRDADDR, name, qse_mbslen(name), false, addr, family);
}
int Socket::getIfceBroadcast (const qse_wchar_t* name, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFBRDADDR, name, qse_wcslen(name), true, addr, family);
}
// ----------------------------------------------------------------------------
int Socket::getIfceAddress (const qse_mchar_t* name, qse_size_t len, SocketAddress* addr) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFADDR, name, len, false, addr);
return this->get_ifce_address(SIOCGIFADDR, name, len, false, addr, this->domain);
}
int Socket::getIfceAddress (const qse_wchar_t* name, qse_size_t len, SocketAddress* addr) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFADDR, name, len, true, addr);
return this->get_ifce_address(SIOCGIFADDR, name, len, true, addr, this->domain);
}
int Socket::getIfceNetmask(const qse_mchar_t* name, qse_size_t len, SocketAddress* addr) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFNETMASK, name, len, false, addr);
return this->get_ifce_address(SIOCGIFNETMASK, name, len, false, addr, this->domain);
}
int Socket::getIfceNetmask (const qse_wchar_t* name, qse_size_t len, SocketAddress* addr) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFNETMASK, name, len, true, addr);
return this->get_ifce_address(SIOCGIFNETMASK, name, len, true, addr, this->domain);
}
int Socket::getIfceBroadcast(const qse_mchar_t* name, qse_size_t len, SocketAddress* addr) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFBRDADDR, name, len, false, addr);
return this->get_ifce_address(SIOCGIFBRDADDR, name, len, false, addr, this->domain);
}
int Socket::getIfceBroadcast (const qse_wchar_t* name, qse_size_t len, SocketAddress* addr) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFBRDADDR, name, len, true, addr);
return this->get_ifce_address(SIOCGIFBRDADDR, name, len, true, addr, this->domain);
}
// ----------------------------------------------------------------------------
int Socket::getIfceAddress (const qse_mchar_t* name, qse_size_t len, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFADDR, name, len, false, addr, family);
}
int Socket::get_ifce_address (int cmd, const void* name, qse_size_t len, bool wchar, SocketAddress* addr)
int Socket::getIfceAddress (const qse_wchar_t* name, qse_size_t len, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFADDR, name, len, true, addr, family);
}
int Socket::getIfceNetmask(const qse_mchar_t* name, qse_size_t len, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFNETMASK, name, len, false, addr, family);
}
int Socket::getIfceNetmask (const qse_wchar_t* name, qse_size_t len, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFNETMASK, name, len, true, addr, family);
}
int Socket::getIfceBroadcast(const qse_mchar_t* name, qse_size_t len, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFBRDADDR, name, len, false, addr, family);
}
int Socket::getIfceBroadcast (const qse_wchar_t* name, qse_size_t len, SocketAddress* addr, int family) QSE_CPP_NOEXCEPT
{
return this->get_ifce_address(SIOCGIFBRDADDR, name, len, true, addr, family);
}
// ----------------------------------------------------------------------------
int Socket::get_ifce_address (int cmd, const void* name, qse_size_t len, bool wchar, SocketAddress* addr, int family)
{
struct ifreq ifr;
@ -1243,7 +1310,7 @@ int Socket::get_ifce_address (int cmd, const void* name, qse_size_t len, bool wc
}
if (!sa || !sa->sa_data) continue;
if (sa->sa_family != this->domain) continue; /* skip an address that doesn't match the socket's domain */
if (sa->sa_family != family) continue; /* skip an address that doesn't match given domain */
//*addr = SocketAddress((const qse_skad_t*)sa);
addr->set ((const qse_skad_t*)sa);

View File

@ -19,7 +19,6 @@ static void print_usage (const qse_cli_t* cli)
qse_fprintf (QSE_STDERR, QSE_T(" --loglevel=string specify logging levels\n"));
qse_fprintf (QSE_STDERR, QSE_T(" --gate-addresses=string\n"));
qse_fprintf (QSE_STDERR, QSE_T(" specify the control channel address\n"));
qse_fprintf (QSE_STDERR, QSE_T(" --chroot=path speficy the special root\n"));
qse_fprintf (QSE_STDERR, QSE_T("\n"));
qse_fprintf (QSE_STDERR, QSE_T("logging type string: one or more of the followings delimited by a comma:\n"));
qse_fprintf (QSE_STDERR, QSE_T(" console, file, syslog\n"));