summaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-03-26 19:02:32 -0700
committerJosh Blum <josh@joshknows.com>2010-03-26 19:02:32 -0700
commitdd41206f2a5127871fc4c9911a748f7f4e3b6c51 (patch)
tree2389f948ae8c6d8378b0a2a76e2101e4f28d56af /host/lib
parentae02148f12615ab4f8e326dac5cf388ab976ec7f (diff)
downloaduhd-dd41206f2a5127871fc4c9911a748f7f4e3b6c51.tar.gz
uhd-dd41206f2a5127871fc4c9911a748f7f4e3b6c51.tar.bz2
uhd-dd41206f2a5127871fc4c9911a748f7f4e3b6c51.zip
tweak the ifaddrs address discovery
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/transport/if_addrs.cpp21
1 files changed, 10 insertions, 11 deletions
diff --git a/host/lib/transport/if_addrs.cpp b/host/lib/transport/if_addrs.cpp
index eb0e56b3a..5c8c8a176 100644
--- a/host/lib/transport/if_addrs.cpp
+++ b/host/lib/transport/if_addrs.cpp
@@ -16,6 +16,9 @@
//
#include <uhd/transport/if_addrs.hpp>
+#include <boost/asio/ip/address_v4.hpp>
+#include <boost/cstdint.hpp>
+#include <iostream>
uhd::transport::if_addrs_t::if_addrs_t(void){
/* NOP */
@@ -26,17 +29,11 @@ uhd::transport::if_addrs_t::if_addrs_t(void){
**********************************************************************/
#ifdef HAVE_IFADDRS_H
#include <ifaddrs.h>
-#include <boost/asio/ip/address_v4.hpp>
static boost::asio::ip::address_v4 sockaddr_to_ip_addr(sockaddr *addr){
- if (addr->sa_family == AF_INET) return boost::asio::ip::address_v4(ntohl(
+ return boost::asio::ip::address_v4(ntohl(
reinterpret_cast<sockaddr_in*>(addr)->sin_addr.s_addr
));
- return boost::asio::ip::address_v4::any();
-}
-
-static bool ifaddrs_valid(const struct ifaddrs *ifaddrs){
- return ifaddrs->ifa_addr->sa_family == AF_INET;
}
std::vector<uhd::transport::if_addrs_t> uhd::transport::get_if_addrs(void){
@@ -44,7 +41,12 @@ std::vector<uhd::transport::if_addrs_t> uhd::transport::get_if_addrs(void){
struct ifaddrs *ifap;
if (getifaddrs(&ifap) == 0){
for (struct ifaddrs *iter = ifap; iter != NULL; iter = iter->ifa_next){
- if (not ifaddrs_valid(iter)) continue;
+ //ensure that the entries are valid
+ if (iter->ifa_addr->sa_family != AF_INET) continue;
+ if (iter->ifa_netmask->sa_family != AF_INET) continue;
+ if (iter->ifa_broadaddr->sa_family != AF_INET) continue;
+
+ //append a new set of interface addresses
if_addrs_t if_addr;
if_addr.inet = sockaddr_to_ip_addr(iter->ifa_addr).to_string();
if_addr.mask = sockaddr_to_ip_addr(iter->ifa_netmask).to_string();
@@ -60,10 +62,7 @@ std::vector<uhd::transport::if_addrs_t> uhd::transport::get_if_addrs(void){
* Interface address discovery through windows api (TODO)
**********************************************************************/
#elif HAVE_WINSOCK2_H
-#include <boost/asio/ip/address_v4.hpp>
-#include <boost/cstdint.hpp>
#include <winsock2.h>
-#include <iostream>
std::vector<uhd::transport::if_addrs_t> uhd::transport::get_if_addrs(void){
std::vector<if_addrs_t> if_addrs;