diff options
author | Steve Huston <shuston@riverace.com> | 1997-06-17 19:27:33 +0000 |
---|---|---|
committer | Steve Huston <shuston@riverace.com> | 1997-06-17 19:27:33 +0000 |
commit | e76e14b6548259929448c63b09746997ca8344c3 (patch) | |
tree | 6e5f8b0faa34252f3a18462778e55bd745195bb3 /ace/ACE.cpp | |
parent | 5708f8e646037b35f577b0fa62124dda4705ae7a (diff) | |
download | ATCD-e76e14b6548259929448c63b09746997ca8344c3.tar.gz |
Fixed get_ip_interfaces (and associated count_interfaces) for non-SVR4
systems (such as HP-UX). Count interfaces by checking the interface name,
not the address (non-IP interfaces can have 0-valued addresses).
Diffstat (limited to 'ace/ACE.cpp')
-rw-r--r-- | ace/ACE.cpp | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/ace/ACE.cpp b/ace/ACE.cpp index 67da02a0e13..0088ca809fc 100644 --- a/ace/ACE.cpp +++ b/ace/ACE.cpp @@ -1558,7 +1558,7 @@ ACE::count_interfaces (ACE_HANDLE handle, // retrieve ifconf list of ifreq structs no SIOCGIFNUM on SunOS 4.x, // so use guess and scan algorithm - const int MAX_IF = 10; // probably hard to put this many ifs in a unix box.. + const int MAX_IF = 50; // probably hard to put this many ifs in a unix box.. int num_ifs = MAX_IF; // HACK - set to an unreasonable number struct ifconf ifcfg; struct ifreq *p_ifs = NULL; @@ -1589,13 +1589,11 @@ ACE::count_interfaces (ACE_HANDLE handle, int if_count = 0, i ; // get if address out of ifreq buffers. + // ioctl puts a blank-named interface to mark the end of the + // returned interfaces. for (i = 0; i < num_ifs; p_ifs++, i++) { - ACE_OS::memcpy ((char *)&addr, - (char *) &p_ifs->ifr_addr.sa_data + 2, - sizeof (addr)); - - if (addr == 0) // no more addrs found + if (p_ifs->ifr_name[0] == '\0') break; if_count++; } @@ -1823,19 +1821,20 @@ ACE::get_ip_interfaces (size_t &count, ACE_TRACE ("ACE::get_ip_interfaces"); size_t num_ifs; - const int FUDGE = 2; /* offset into sa_data[] for ip address on sparc */ - - ACE_HANDLE handle = get_handle(); // call specific routine as necessary + ACE_HANDLE handle = get_handle(); // call specific routine as necessary if (handle == ACE_INVALID_HANDLE) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "ACE::get_ip_interfaces:open"), -1); - + if (ACE::count_interfaces (handle, num_ifs)) { ACE_OS::close (handle); return -1; } + // ioctl likes to have an extra ifreq structure to mark the end of what it + // returned, so increase the num_ifs by one. + ++num_ifs; auto_ptr<struct ifreq> p_ifs (new struct ifreq[num_ifs]); if (p_ifs.get() == 0) @@ -1859,26 +1858,22 @@ ACE::get_ip_interfaces (size_t &count, ACE_OS::close (handle); // ------------ now create and initialize output array ------------- - count = 0; + ACE_NEW_RETURN (addrs, ACE_INET_Addr[num_ifs], -1); // caller must free struct ifreq *pcur = p_ifs.get (); - // Get if address out of ifreq buffers have yet to see a non PF_INET - // data type, but don't chance it which means allocation might be - // larger than actually used - + // Pull the address out of each INET interface. Not every interface is + // for IP, so be careful to count properly. When setting the INET_Addr, + // note that the 3rd arg (0) says to leave the byte order (already in net + // byte order from the interface structure) as is. + count = 0; for (size_t i = 0; i < num_ifs; pcur++, i++) { - ACE_UINT32 tmp_addr; - - // SPARC w/Solaris 2.x TODO: see if fudge factor can be removed. - if (pcur->ifr_addr.sa_family == PF_INET) + if (pcur->ifr_addr.sa_family == AF_INET) { - ACE_OS::memcpy ((char *) &tmp_addr, - (char *) &pcur->ifr_addr.sa_data +FUDGE, - sizeof tmp_addr); + struct sockaddr_in *_addr_ = (struct sockaddr_in *)&(pcur->ifr_addr); + addrs[count].set ((u_short)0, _addr_->sin_addr.s_addr, 0); count++; - addrs[i].set ((u_short) 0, tmp_addr, 0); // 0 = data in net byte order } } return 0; |