mirror of
https://bitbucket.org/King_DuckZ/keepupnpup.git
synced 2024-11-07 21:29:00 +00:00
Add external IP retrieval.
This commit is contained in:
parent
4b61da0d90
commit
74c8be9309
1 changed files with 25 additions and 13 deletions
38
src/main.cpp
38
src/main.cpp
|
@ -8,6 +8,7 @@
|
|||
#include <ciso646>
|
||||
#include <cstdint>
|
||||
#include <strings.h>
|
||||
#include <array>
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
# define KUU_VERBOSE
|
||||
|
@ -31,24 +32,32 @@ namespace {
|
|||
};
|
||||
|
||||
explicit UPNPUrlsResource (struct UPNPDev* parDevList) :
|
||||
m_lanaddr(64, ' '),
|
||||
m_lanaddr(),
|
||||
m_externaladdr(),
|
||||
m_igd_reply(IGDNone)
|
||||
{
|
||||
const auto i = UPNP_GetValidIGD(parDevList, &m_urls, &m_data, &m_lanaddr[0], m_lanaddr.size());
|
||||
{
|
||||
std::array<char, 64> lanaddr;
|
||||
const auto i = UPNP_GetValidIGD(parDevList, &m_urls, &m_data, lanaddr.data(), lanaddr.size());
|
||||
|
||||
switch (i) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
m_igd_reply = static_cast<IGDReply>(i);
|
||||
break;
|
||||
default:
|
||||
m_igd_reply = IGDNotSure;
|
||||
switch (i) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
m_igd_reply = static_cast<IGDReply>(i);
|
||||
break;
|
||||
default:
|
||||
m_igd_reply = IGDNotSure;
|
||||
}
|
||||
|
||||
m_lanaddr = lanaddr.data();
|
||||
}
|
||||
|
||||
const auto idx = m_lanaddr.find('\0');
|
||||
if (idx != m_lanaddr.npos)
|
||||
m_lanaddr.resize(idx);
|
||||
{
|
||||
std::array<char, 64> externaladdr;
|
||||
const auto r = UPNP_GetExternalIPAddress(m_urls.controlURL, m_data.first.servicetype, externaladdr.data());
|
||||
m_externaladdr = externaladdr.data();
|
||||
}
|
||||
}
|
||||
|
||||
~UPNPUrlsResource() noexcept {
|
||||
|
@ -62,9 +71,11 @@ namespace {
|
|||
const struct IGDdatas* data() const { return &m_data; }
|
||||
IGDReply igd_reply() const { return m_igd_reply; }
|
||||
const std::string& lanaddr() const { return m_lanaddr; }
|
||||
const std::string& externaladdr() const { return m_externaladdr; }
|
||||
|
||||
private:
|
||||
std::string m_lanaddr;
|
||||
std::string m_externaladdr;
|
||||
struct UPNPUrls m_urls;
|
||||
struct IGDdatas m_data;
|
||||
IGDReply m_igd_reply;
|
||||
|
@ -212,6 +223,7 @@ int main() {
|
|||
}
|
||||
|
||||
std::cout << "Local LAN ip address: " << urls.lanaddr() << '\n';
|
||||
std::cout << "External ip address: " << urls.externaladdr() << '\n';
|
||||
#endif
|
||||
|
||||
const auto redirs = get_redirections(urls);
|
||||
|
|
Loading…
Reference in a new issue