[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "nat-traversal" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Jun 20 07:55:46 CDT 2011


branch "nat-traversal" has been updated
       via  a12a3505915e4663768beee0617fedaa886ed77c (commit)
      from  a288dc0ebc65a1622042c1e7223d603c7b892a26 (commit)

Summary of changes:
 include/AsteriskSCF/Helpers/Network.h |    2 +
 src/Helpers/Network.cpp               |   36 +++++++++++++++++++++++++++++---
 2 files changed, 34 insertions(+), 4 deletions(-)


- Log -----------------------------------------------------------------
commit a12a3505915e4663768beee0617fedaa886ed77c
Author: Brent Eagles <beagles at digium.com>
Date:   Mon Jun 20 10:23:17 2011 -0230

    Modified the network helper to conditionally perform a DNS lookup if an
    address-translation fails.  NOTE: I'm not sure if I really like this addition,
    but I'm going to add it for the time being because it makes working with
    hostnames in testing a easier and it doesn't feel right to have something
    other than the "address" care about whether or not a DNS lookup is
    required.

diff --git a/include/AsteriskSCF/Helpers/Network.h b/include/AsteriskSCF/Helpers/Network.h
index b3bfaed..2ff39f9 100644
--- a/include/AsteriskSCF/Helpers/Network.h
+++ b/include/AsteriskSCF/Helpers/Network.h
@@ -49,6 +49,7 @@ public:
 
     unsigned port() const;
     std::string hostname() const;
+    std::string address() const;
 
     bool isIPV6();
 
@@ -56,6 +57,7 @@ public:
     
 private:
     std::string mHostname;
+    std::string mAddress;
     unsigned mPort;
 
     bool mIsIPV6;
diff --git a/src/Helpers/Network.cpp b/src/Helpers/Network.cpp
index 5ba1334..c152708 100644
--- a/src/Helpers/Network.cpp
+++ b/src/Helpers/Network.cpp
@@ -18,6 +18,7 @@
 #include <boost/asio.hpp>
 #include <boost/lexical_cast.hpp>
 #include <sstream>
+#include <iostream>
 
 using namespace std;
 using namespace AsteriskSCF::Helpers;
@@ -25,10 +26,25 @@ using namespace boost::asio::ip;
 
 Address::Address(const string& host, unsigned p) :
     mHostname(host),
-    mPort(p)
+    mPort(p),
+    mIsIPV6(false)
 {
-    address a(address::from_string(host));
-    mIsIPV6 = a.is_v6();
+    try
+    {
+        boost::asio::ip::address a(address::from_string(mHostname));
+        mAddress = host;
+        mIsIPV6 = a.is_v6();
+    }
+    catch (const exception&)
+    {
+        DNSQueryPtr q = DNSQuery::create(mHostname, 0);
+        AddressSeq results = q->execute();
+        if (!results.empty())
+        {
+            mIsIPV6 = results[0]->isIPV6();
+            mAddress = results[0]->address();
+        }
+    }
 }
     
 unsigned Address::port() const
@@ -41,6 +57,11 @@ string Address::hostname() const
     return mHostname;
 }
 
+string Address::address() const
+{
+    return mAddress;
+}
+
 bool Address::isIPV6()
 {
     return mIsIPV6;
@@ -49,7 +70,14 @@ bool Address::isIPV6()
 string Address::toString() const
 {
     stringstream os;
-    os << mHostname << ':' << mPort;
+    if (mHostname == mAddress)
+    {
+        os << mHostname << ':' << mPort;
+    }
+    else
+    {
+        os << mHostname << '/' << mAddress << ':' << mPort;
+    }
     return os.str();
 }
 

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/ice-util-cpp.git



More information about the asterisk-scf-commits mailing list