[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] [SCM] Gnash branch, ipv6, updated. release_0_8_9_final-14
From: |
Rob Savoye |
Subject: |
[Gnash-commit] [SCM] Gnash branch, ipv6, updated. release_0_8_9_final-1451-geb38447 |
Date: |
Thu, 12 Apr 2012 17:11:07 +0000 |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Gnash".
The branch, ipv6 has been updated
via eb38447ba426faf04fc5ddfadecd2afeef59917e (commit)
from 5878bc9de3bde31df93bed94d25ff5c11a00edc8 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit//commit/?id=eb38447ba426faf04fc5ddfadecd2afeef59917e
commit eb38447ba426faf04fc5ddfadecd2afeef59917e
Author: Rob Savoye <address@hidden>
Date: Thu Apr 12 11:10:56 2012 -0600
add private function to return string version of IPV4 or IPV6 IP number.
Ignore SOCK_GRAM sockets, we use SOCK_STREAM only.
diff --git a/libbase/Socket.cpp b/libbase/Socket.cpp
index ca921e3..4273d88 100644
--- a/libbase/Socket.cpp
+++ b/libbase/Socket.cpp
@@ -29,6 +29,7 @@
#include <csignal>
#include <boost/lexical_cast.hpp>
#include <boost/cstdint.hpp>
+#include <boost/shared_ptr.hpp>
#include "GnashSystemNetHeaders.h"
#include "GnashSystemFDHeaders.h"
@@ -153,7 +154,7 @@ Socket::connect(const std::string& hostname,
boost::uint16_t port)
struct addrinfo req, *ans;
std::memset(&req, 0, sizeof(struct addrinfo));
req.ai_family = AF_UNSPEC; // Allow IPv4 or IPv6
- req.ai_socktype = SOCK_STREAM;
+ req.ai_socktype = 0; // SOCK_STREAM;
if ((code = getaddrinfo(hostname.c_str(), 0, &req, &ans)) != 0) {
log_error(_("getaddrinfo() failed with code: #%d - %s\n"),
@@ -161,25 +162,43 @@ Socket::connect(const std::string& hostname,
boost::uint16_t port)
return false;
}
- // Multiple IPV$ and IPV6 numbers may be returned, so we try them all if
- // required
- struct addrinfo *it = ans;
- while (it) {
+ // display all the IP numbers
+ struct addrinfo *ot = ans;
+ while (ot) {
+ // We only want the SOCK_STREAM type
+ if (ot->ai_socktype == SOCK_DGRAM) {
+ // log_debug("SockType is SOCK_DGRAM");
+ ot = ot->ai_next;
+ continue;
+ }
char clienthost [NI_MAXHOST];
std::memset(&clienthost, 0, NI_MAXHOST);
char clientservice[NI_MAXSERV];
std::memset(&clientservice, 0, NI_MAXSERV);
- getnameinfo(it->ai_addr, it->ai_addrlen,
+ getnameinfo(ot->ai_addr, ot->ai_addrlen,
clienthost, sizeof(clienthost),
clientservice, sizeof(clientservice),
NI_NUMERICHOST);
+
+ boost::shared_ptr<char> straddr = getIPString(ot);
+
+ if (ot->ai_family == AF_INET6) {
+ log_debug("%s has IPV6 address of: %s", hostname, straddr.get());
+ } else if (ot->ai_family == AF_INET) {
+ log_debug("%s has IPV4 address of: %s", hostname, straddr.get());
+ }
+ ot = ot->ai_next;
+ }
- char straddr[INET6_ADDRSTRLEN];
- std::memset(&straddr, 0, INET6_ADDRSTRLEN);
- ::inet_ntop(AF_INET6, it->ai_addr, straddr,
- sizeof(straddr));
- log_debug("IPV6 address for host %s is %s", hostname, straddr);
-
+ // Multiple IPV$ and IPV6 numbers may be returned, so we try them all if
+ // required
+ struct addrinfo *it = ans;
+ while (it) {
+ // We only want a SOCK_STREAM
+ if (it->ai_socktype == SOCK_DGRAM) {
+ it = it->ai_next;
+ continue;
+ }
_socket = ::socket(it->ai_family, it->ai_socktype, it->ai_protocol);
if (_socket < 0) {
const int err = errno;
@@ -267,6 +286,27 @@ Socket::connect(const std::string& hostname,
boost::uint16_t port)
return true;
}
+// Return the string representation of the IPV4 or IPV6 number
+boost::shared_ptr<char>
+Socket::getIPString(struct addrinfo *ai)
+{
+ boost::shared_ptr<char> straddr(new char[INET6_ADDRSTRLEN]);
+ std::memset(straddr.get(), 0, INET6_ADDRSTRLEN);
+ if (ai->ai_family == AF_INET6) {
+ struct sockaddr_in6 *sock6 = reinterpret_cast<struct sockaddr_in6
*>(ai->ai_addr);
+ struct in6_addr sin6_addr = sock6->sin6_addr;
+ ::inet_ntop(AF_INET6, &sin6_addr, straddr.get(), INET6_ADDRSTRLEN);
+// log_debug("IPV6 address: %s", straddr.get());
+ } else if (ai->ai_family == AF_INET) {
+ struct sockaddr_in *sock = reinterpret_cast<struct sockaddr_in
*>(ai->ai_addr);
+ struct in_addr sin_addr = sock->sin_addr;
+ ::inet_ntop(AF_INET, &sin_addr, straddr.get(), INET_ADDRSTRLEN);
+// log_debug("IPV4 address: %s", straddr);
+ }
+
+ return straddr;
+}
+
void
Socket::fillCache()
{
diff --git a/libbase/Socket.h b/libbase/Socket.h
index b5d5e79..6bef010 100644
--- a/libbase/Socket.h
+++ b/libbase/Socket.h
@@ -23,7 +23,11 @@
#include "dsodefs.h"
#include <boost/cstdint.hpp>
+#include <boost/shared_ptr.hpp>
#include "IOChannel.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
namespace gnash {
class URL;
@@ -119,6 +123,9 @@ public:
private:
+ // Return the string representation of the IPV4 or IPV6 number
+ boost::shared_ptr<char> getIPString(struct addrinfo *ai);
+
/// Fill the cache.
void fillCache();
@@ -143,8 +150,7 @@ private:
#endif // GNASH_IOCHANNEL_H
-
// Local Variables:
// mode: C++
-// indent-tabs-mode: t
+// indent-tabs-mode: nil
// End:
-----------------------------------------------------------------------
Summary of changes:
libbase/Socket.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++---------
libbase/Socket.h | 10 ++++++-
2 files changed, 60 insertions(+), 14 deletions(-)
hooks/post-receive
--
Gnash
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] [SCM] Gnash branch, ipv6, updated. release_0_8_9_final-1451-geb38447,
Rob Savoye <=