00001
00002
00003 #include "ace/Sock_Connect.h"
00004 #include "ace/INET_Addr.h"
00005 #include "ace/Log_Msg.h"
00006 #include "ace/Handle_Set.h"
00007 #include "ace/Auto_Ptr.h"
00008 #include "ace/SString.h"
00009 #include "ace/OS_Memory.h"
00010 #include "ace/OS_NS_stdio.h"
00011
00012 #if defined (sparc)
00013 # include "ace/OS_NS_fcntl.h"
00014 #endif // sparc
00015
00016 #include "ace/OS_NS_stdlib.h"
00017 #include "ace/OS_NS_string.h"
00018 #include "ace/OS_NS_sys_socket.h"
00019 #include "ace/OS_NS_netdb.h"
00020 #include "ace/OS_NS_unistd.h"
00021 #include "ace/os_include/net/os_if.h"
00022
00023 #if defined (ACE_HAS_IPV6)
00024 # include "ace/Guard_T.h"
00025 # include "ace/Recursive_Thread_Mutex.h"
00026 #endif
00027
00028 # if defined (ACE_HAS_GETIFADDRS)
00029 # if defined (ACE_VXWORKS)
00030 # include <net/ifaddrs.h>
00031 # else
00032 # include <ifaddrs.h>
00033 # endif
00034 # endif
00035
00036 #if defined (ACE_VXWORKS) && (ACE_VXWORKS < 0x600)
00037 #include <inetLib.h>
00038 #include <netinet/in_var.h>
00039 extern "C" {
00040 extern struct in_ifaddr* in_ifaddr;
00041 }
00042 #include "ace/OS_NS_stdio.h"
00043 #endif
00044
00045 #if defined (ACE_HAS_WINCE)
00046 #include <Iphlpapi.h>
00047 #endif // ACE_HAS_WINCE
00048
00049 #if defined (ACE_WIN32) && defined (ACE_HAS_PHARLAP)
00050 # include "ace/OS_NS_stdio.h"
00051 #endif
00052
00053 #if defined (ACE_HAS_IPV6)
00054 # if defined (ACE_HAS_THREADS)
00055 # include "ace/Object_Manager.h"
00056 # endif
00057
00058 namespace
00059 {
00060
00061
00062
00063
00064 int ace_ipv6_enabled = -1;
00065 }
00066 #endif
00067
00068
00069
00070
00071
00072
00073
00074 #if defined (AIX) && defined (__IBMCPP__) && (__IBMCPP__ >= 500) && (__IBMCPP__ < 700)
00075 static ACE_Auto_Array_Ptr<sockaddr> force_compiler_to_include_socket_h;
00076 #endif
00077
00078
00079 ACE_RCSID (ace,
00080 Sock_Connect,
00081 "Sock_Connect.cpp,v 1.66 2006/06/01 09:15:42 jwillemsen Exp")
00082
00083
00084 #if defined (ACE_WIN32) && \
00085 (!defined (ACE_HAS_WINSOCK2) \
00086 || (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 == 0)))
00087
00088 static int
00089 get_reg_subkeys (const ACE_TCHAR *key,
00090 ACE_TCHAR *buffer,
00091 DWORD &buf_len)
00092 {
00093 HKEY hk;
00094 LONG rc = ACE_TEXT_RegOpenKeyEx (HKEY_LOCAL_MACHINE,
00095 key,
00096 0,
00097 KEY_READ,
00098 &hk);
00099
00100 if (rc != ERROR_SUCCESS)
00101 return -1;
00102
00103 ACE_TCHAR subkeyname[ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 1];
00104 DWORD subkeyname_len = ACE_MAX_FULLY_QUALIFIED_NAME_LEN;
00105 FILETIME update_dummy;
00106
00107 DWORD total = 0;
00108
00109 for (int i = 0;
00110 (rc = ACE_TEXT_RegEnumKeyEx (hk, i,
00111 subkeyname,
00112 &subkeyname_len,
00113 0, 0, 0,
00114 &update_dummy)) != ERROR_NO_MORE_ITEMS;
00115 ++i)
00116 {
00117 if (subkeyname_len < buf_len - total)
00118 {
00119 ACE_OS::strcpy(buffer + total, subkeyname);
00120 total += subkeyname_len + 1;
00121
00122 subkeyname_len = ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 1;
00123 }
00124 else
00125 return -1;
00126 }
00127
00128 buf_len = total;
00129
00130 ::RegCloseKey (hk);
00131 return 0;
00132 }
00133
00134
00135
00136
00137
00138 static int
00139 get_reg_value (const ACE_TCHAR *key,
00140 const ACE_TCHAR *name,
00141 ACE_TCHAR *buffer,
00142 DWORD &buf_len,
00143 int all_subkeys = 0)
00144 {
00145 HKEY hk;
00146 DWORD buf_type;
00147 LONG rc = ACE_TEXT_RegOpenKeyEx (HKEY_LOCAL_MACHINE,
00148 key,
00149 0,
00150 KEY_READ,
00151 &hk);
00152
00153 if (rc != ERROR_SUCCESS)
00154
00155 return -1;
00156
00157 if (all_subkeys)
00158 {
00159 ACE_TCHAR ifname[ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 1];
00160 DWORD ifname_len = ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 1;
00161 FILETIME update_dummy;
00162
00163 DWORD total = 0;
00164 DWORD size = buf_len;
00165
00166 for (int i = 0;
00167 (rc = ACE_TEXT_RegEnumKeyEx (hk, i, ifname, &ifname_len,
00168 0, 0, 0,
00169 &update_dummy)) != ERROR_NO_MORE_ITEMS;
00170 ++i)
00171 {
00172 HKEY ifkey;
00173 if (rc != ERROR_SUCCESS
00174 || ACE_TEXT_RegOpenKeyEx (hk, ifname, 0,
00175 KEY_READ, &ifkey) != ERROR_SUCCESS)
00176 continue;
00177
00178 if (ACE_TEXT_RegQueryValueEx (ifkey, name, 0, 0,
00179 (u_char*) (buffer + total),
00180 &size) != ERROR_SUCCESS)
00181 {
00182 RegCloseKey(ifkey);
00183 continue;
00184 }
00185 else
00186 {
00187 total += size;
00188 size = buf_len - total;
00189 }
00190
00191 ifname_len = ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 1;
00192 }
00193
00194 if (total == 0)
00195 {
00196 ::RegCloseKey (hk);
00197 return -2;
00198 }
00199 else
00200 {
00201 buf_len = total;
00202 }
00203 }
00204 else
00205 {
00206
00207 rc = ACE_TEXT_RegQueryValueEx (hk,
00208 name,
00209 0,
00210 &buf_type,
00211 (u_char *) buffer,
00212 &buf_len);
00213 if (rc != ERROR_SUCCESS)
00214 {
00215
00216 RegCloseKey (hk);
00217 return -2;
00218 }
00219 }
00220
00221 ::RegCloseKey (hk);
00222 return 0;
00223 }
00224
00225 enum ACE_WINDOWS_VERSION {
00226 ACE_WINDOWS_IS_UNKNOWN,
00227 ACE_WINDOWS_IS_WIN95,
00228 ACE_WINDOWS_IS_WIN98,
00229 ACE_WINDOWS_IS_WINME,
00230 ACE_WINDOWS_IS_WINNT,
00231 ACE_WINDOWS_IS_WIN2K,
00232 ACE_WINDOWS_IS_WINCE
00233 };
00234
00235 static ACE_WINDOWS_VERSION
00236 get_windows_version()
00237 {
00238 OSVERSIONINFO vinfo;
00239 vinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
00240 if (::GetVersionEx(&vinfo) == 0)
00241 {
00242 return ACE_WINDOWS_IS_UNKNOWN;
00243 }
00244
00245 switch (vinfo.dwPlatformId)
00246 {
00247 case VER_PLATFORM_WIN32_NT:
00248 if (vinfo.dwMajorVersion <= 4)
00249 return ACE_WINDOWS_IS_WINNT;
00250 else
00251 return ACE_WINDOWS_IS_WIN2K;
00252 case VER_PLATFORM_WIN32_WINDOWS:
00253 if (vinfo.dwMajorVersion == 4)
00254 {
00255 if (vinfo.dwMinorVersion == 0)
00256 return ACE_WINDOWS_IS_WIN95;
00257 else if (vinfo.dwMinorVersion == 10)
00258 return ACE_WINDOWS_IS_WIN98;
00259 else if (vinfo.dwMinorVersion == 90)
00260 return ACE_WINDOWS_IS_WINME;
00261 }
00262 #if defined (VER_PLATFORM_WIN32_CE)
00263 case VER_PLATFORM_WIN32_CE:
00264 if (vinfo.dwMajorVersion >= 3) {
00265 return ACE_WINDOWS_IS_WINCE;
00266 }
00267 else {
00268 return ACE_WINDOWS_IS_UNKNOWN;
00269 }
00270 #endif
00271
00272 default:
00273 return ACE_WINDOWS_IS_UNKNOWN;
00274 }
00275 }
00276
00277 #endif //(ACE_WIN32) && !(ACE_HAS_WINSOCK2) || (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 == 0)
00278
00279 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00280
00281
00282
00283 int
00284 ACE::bind_port (ACE_HANDLE handle, ACE_UINT32 ip_addr, int address_family)
00285 {
00286 ACE_TRACE ("ACE::bind_port");
00287
00288 ACE_INET_Addr addr;
00289
00290 #if defined (ACE_HAS_IPV6)
00291 if (address_family != PF_INET6)
00292
00293
00294 #else
00295 ACE_UNUSED_ARG (address_family);
00296 #endif
00297 addr = ACE_INET_Addr ((u_short)0, ip_addr);
00298 #if defined (ACE_HAS_IPV6)
00299 else if (ip_addr != INADDR_ANY)
00300
00301
00302 addr.set ((u_short)0, ip_addr, 1, 1);
00303 #endif
00304
00305 #if !defined (ACE_LACKS_WILDCARD_BIND)
00306
00307 return ACE_OS::bind (handle,
00308 (sockaddr*)addr.get_addr(),
00309 addr.get_size());
00310 #else
00311 static u_short upper_limit = ACE_MAX_DEFAULT_PORT;
00312 int round_trip = upper_limit;
00313 int lower_limit = IPPORT_RESERVED;
00314
00315
00316
00317 for (;;)
00318 {
00319 addr.set((u_short)upper_limit,ip_addr);
00320
00321 if (ACE_OS::bind (handle,
00322 (sockaddr*)addr.get_addr()
00323 addr.get_size()) >= 0)
00324 {
00325 #if defined (ACE_WIN32)
00326 upper_limit--;
00327 #endif
00328 return 0;
00329 }
00330 else if (errno != EADDRINUSE)
00331 return -1;
00332 else
00333 {
00334 upper_limit--;
00335
00336
00337 if (upper_limit <= lower_limit)
00338 upper_limit = ACE_MAX_DEFAULT_PORT;
00339
00340
00341 if (upper_limit == round_trip)
00342 {
00343 errno = EAGAIN;
00344 return -1;
00345 }
00346 }
00347 }
00348 #endif
00349 }
00350
00351 int
00352 ACE::get_bcast_addr (ACE_UINT32 &bcast_addr,
00353 const ACE_TCHAR *host_name,
00354 ACE_UINT32 host_addr,
00355 ACE_HANDLE handle)
00356 {
00357 ACE_TRACE ("ACE::get_bcast_addr");
00358
00359 #if !defined(ACE_WIN32) && !defined(__INTERIX)
00360 ACE_HANDLE s = handle;
00361
00362 if (s == ACE_INVALID_HANDLE)
00363 s = ACE_OS::socket (AF_INET, SOCK_STREAM, 0);
00364
00365 if (s == ACE_INVALID_HANDLE)
00366 ACE_ERROR_RETURN ((LM_ERROR,
00367 ACE_LIB_TEXT ("%p\n"),
00368 ACE_LIB_TEXT ("ACE_OS::socket")),
00369 -1);
00370
00371 struct ifconf ifc;
00372 char buf[BUFSIZ];
00373
00374 ifc.ifc_len = sizeof buf;
00375 ifc.ifc_buf = buf;
00376
00377
00378
00379 #if defined (AIX)
00380 int cmd = CSIOCGIFCONF;
00381 #else
00382 int cmd = SIOCGIFCONF;
00383 #endif
00384 if (ACE_OS::ioctl (s, cmd, (char *) &ifc) == -1)
00385 ACE_ERROR_RETURN ((LM_ERROR,
00386 ACE_LIB_TEXT ("%p\n"),
00387 ACE_LIB_TEXT ("ACE::get_bcast_addr:")
00388 ACE_LIB_TEXT ("ioctl (get interface configuration)")),
00389 -1);
00390
00391 struct ifreq *ifr = ifc.ifc_req;
00392
00393 struct sockaddr_in ip_addr;
00394
00395
00396 if (host_name)
00397 {
00398 hostent *hp = ACE_OS::gethostbyname (ACE_TEXT_ALWAYS_CHAR (host_name));
00399
00400 if (hp == 0)
00401 return -1;
00402 else
00403 #if !defined(_UNICOS)
00404 ACE_OS::memcpy ((char *) &ip_addr.sin_addr.s_addr,
00405 (char *) hp->h_addr,
00406 hp->h_length);
00407 #else
00408 {
00409 ACE_UINT64 haddr;
00410 char * haddrp = (char *) &haddr;
00411 ACE_OS::memcpy(haddrp,(char *) hp->h_addr,hp->h_length);
00412 ip_addr.sin_addr.s_addr = haddr;
00413 }
00414 #endif
00415 }
00416 else
00417 {
00418 ACE_OS::memset ((void *) &ip_addr, 0, sizeof ip_addr);
00419 #if !defined(_UNICOS)
00420 ACE_OS::memcpy ((void *) &ip_addr.sin_addr,
00421 (void*) &host_addr,
00422 sizeof ip_addr.sin_addr);
00423 #else
00424 ip_addr.sin_addr.s_addr = host_addr;
00425 #endif
00426 }
00427
00428 #if !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__)
00429 for (int n = ifc.ifc_len / sizeof (struct ifreq) ; n > 0;
00430 n--, ifr++)
00431 #else
00432
00433 for (int nbytes = ifc.ifc_len; nbytes >= (int) sizeof (struct ifreq) &&
00434 ((ifr->ifr_addr.sa_len > sizeof (struct sockaddr)) ?
00435 (nbytes >= (int) sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len) : 1);
00436 ((ifr->ifr_addr.sa_len > sizeof (struct sockaddr)) ?
00437 (nbytes -= sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len,
00438 ifr = (struct ifreq *)
00439 ((caddr_t) &ifr->ifr_addr + ifr->ifr_addr.sa_len)) :
00440 (nbytes -= sizeof (struct ifreq), ifr++)))
00441 #endif
00442 {
00443 struct sockaddr_in if_addr;
00444
00445
00446 ACE_OS::memcpy (&if_addr,
00447 &ifr->ifr_addr,
00448 sizeof if_addr);
00449
00450 if (ip_addr.sin_addr.s_addr != if_addr.sin_addr.s_addr)
00451 continue;
00452
00453 if (ifr->ifr_addr.sa_family != AF_INET)
00454 {
00455 ACE_ERROR ((LM_ERROR,
00456 ACE_LIB_TEXT ("%p\n"),
00457 ACE_LIB_TEXT ("ACE::get_bcast_addr:")
00458 ACE_LIB_TEXT ("Not AF_INET")));
00459 continue;
00460 }
00461
00462 struct ifreq flags = *ifr;
00463 struct ifreq if_req = *ifr;
00464
00465 if (ACE_OS::ioctl (s, SIOCGIFFLAGS, (char *) &flags) == -1)
00466 {
00467 ACE_ERROR ((LM_ERROR,
00468 ACE_LIB_TEXT ("%p\n"),
00469 ACE_LIB_TEXT ("ACE::get_bcast_addr:")
00470 ACE_LIB_TEXT (" ioctl (get interface flags)")));
00471 continue;
00472 }
00473
00474 if (ACE_BIT_DISABLED (flags.ifr_flags, IFF_UP))
00475 {
00476 ACE_ERROR ((LM_ERROR,
00477 ACE_LIB_TEXT ("%p\n"),
00478 ACE_LIB_TEXT ("ACE::get_bcast_addr:")
00479 ACE_LIB_TEXT ("Network interface is not up")));
00480 continue;
00481 }
00482
00483 if (ACE_BIT_ENABLED (flags.ifr_flags, IFF_LOOPBACK))
00484 continue;
00485
00486 if (ACE_BIT_ENABLED (flags.ifr_flags, IFF_BROADCAST))
00487 {
00488 if (ACE_OS::ioctl (s,
00489 SIOCGIFBRDADDR,
00490 (char *) &if_req) == -1)
00491 ACE_ERROR ((LM_ERROR,
00492 ACE_LIB_TEXT ("%p\n"),
00493 ACE_LIB_TEXT ("ACE::get_bcast_addr:")
00494 ACE_LIB_TEXT ("ioctl (get broadaddr)")));
00495 else
00496 {
00497 ACE_OS::memcpy (reinterpret_cast<sockaddr_in *> (&ip_addr),
00498 reinterpret_cast<sockaddr_in *> (&if_req.ifr_broadaddr),
00499 sizeof if_req.ifr_broadaddr);
00500
00501 ACE_OS::memcpy ((void *) &host_addr,
00502 (void *) &ip_addr.sin_addr,
00503 sizeof host_addr);
00504
00505 if (handle == ACE_INVALID_HANDLE)
00506 ACE_OS::close (s);
00507
00508 bcast_addr = host_addr;
00509 return 0;
00510 }
00511 }
00512 else
00513 ACE_ERROR ((LM_ERROR,
00514 ACE_LIB_TEXT ("%p\n"),
00515 ACE_LIB_TEXT ("ACE::get_bcast_addr:")
00516 ACE_LIB_TEXT ("Broadcast is not enable for this interface.")));
00517
00518 if (handle == ACE_INVALID_HANDLE)
00519 ACE_OS::close (s);
00520
00521 bcast_addr = host_addr;
00522 return 0;
00523 }
00524
00525 return 0;
00526 #else
00527 ACE_UNUSED_ARG (handle);
00528 ACE_UNUSED_ARG (host_addr);
00529 ACE_UNUSED_ARG (host_name);
00530 bcast_addr = (ACE_UINT32 (INADDR_BROADCAST));
00531 return 0;
00532 #endif
00533 }
00534
00535
00536
00537
00538
00539 int
00540 ACE::get_ip_interfaces (size_t &count,
00541 ACE_INET_Addr *&addrs)
00542 {
00543 ACE_TRACE ("ACE::get_ip_interfaces");
00544
00545 count = 0;
00546 addrs = 0;
00547
00548 #if defined (ACE_WIN32)
00549
00550
00551 # if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
00552 int i, n_interfaces, status;
00553
00554 INTERFACE_INFO info[64];
00555 SOCKET sock;
00556
00557
00558 sock = socket (AF_INET, SOCK_DGRAM, 0);
00559 if (sock == INVALID_SOCKET)
00560 return -1;
00561
00562 DWORD bytes;
00563 status = WSAIoctl(sock,
00564 SIO_GET_INTERFACE_LIST,
00565 0,
00566 0,
00567 info,
00568 sizeof(info),
00569 &bytes,
00570 0,
00571 0);
00572 closesocket (sock);
00573 if (status == SOCKET_ERROR)
00574 return -1;
00575
00576 n_interfaces = bytes / sizeof(INTERFACE_INFO);
00577 if (n_interfaces == 0)
00578 return 0;
00579
00580
00581
00582
00583 # if defined (ACE_HAS_IPV6) && defined (SIO_ADDRESS_LIST_QUERY)
00584 int n_v6_interfaces = 0;
00585
00586 LPSOCKET_ADDRESS_LIST v6info;
00587 char *buffer;
00588 DWORD buflen = sizeof (SOCKET_ADDRESS_LIST) + (63 * sizeof (SOCKET_ADDRESS));
00589 ACE_NEW_RETURN (buffer,
00590 char[buflen],
00591 -1);
00592 v6info = reinterpret_cast<LPSOCKET_ADDRESS_LIST> (buffer);
00593
00594
00595
00596 sock = socket (AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
00597 if (sock == INVALID_SOCKET)
00598 {
00599 delete [] buffer;
00600 return -1;
00601 }
00602
00603 status = WSAIoctl(sock,
00604 SIO_ADDRESS_LIST_QUERY,
00605 0,
00606 0,
00607 v6info,
00608 buflen,
00609 &bytes,
00610 0,
00611 0);
00612 closesocket (sock);
00613 if (status == SOCKET_ERROR)
00614 {
00615 delete [] buffer;
00616 return -1;
00617 }
00618
00619 n_v6_interfaces = v6info->iAddressCount;
00620
00621 ACE_NEW_RETURN (addrs,
00622 ACE_INET_Addr[n_interfaces + n_v6_interfaces],
00623 -1);
00624 # else
00625 ACE_NEW_RETURN (addrs,
00626 ACE_INET_Addr[n_interfaces],
00627 -1);
00628 # endif
00629
00630
00631
00632 for (count = 0, i = 0; i < n_interfaces; ++i)
00633 {
00634 LPINTERFACE_INFO lpii;
00635 struct sockaddr_in *addrp = 0;
00636
00637 lpii = &info[i];
00638 if (!(lpii->iiFlags & IFF_UP))
00639 continue;
00640
00641
00642 addrp = reinterpret_cast<struct sockaddr_in *> (&lpii->iiAddress.AddressIn);
00643 if (addrp->sin_addr.s_addr == INADDR_ANY)
00644 continue;
00645
00646
00647 addrs[count].set(addrp, sizeof(sockaddr_in));
00648 ++count;
00649 }
00650
00651 # if defined (ACE_HAS_IPV6)
00652
00653
00654 for (i = 0; i < n_v6_interfaces; i++)
00655 {
00656 struct sockaddr_in6 *addr6p;
00657
00658 if (v6info->Address[i].lpSockaddr->sa_family != AF_INET6)
00659 continue;
00660
00661 addr6p = reinterpret_cast<struct sockaddr_in6 *> (v6info->Address[i].lpSockaddr);
00662 if (IN6_IS_ADDR_UNSPECIFIED(&addr6p->sin6_addr))
00663 continue;
00664
00665
00666 addrs[count].set(reinterpret_cast<struct sockaddr_in *> (addr6p), sizeof(sockaddr_in6));
00667 ++count;
00668 }
00669
00670 delete [] buffer;
00671 # endif
00672
00673 if (count == 0)
00674 {
00675 delete [] addrs;
00676 addrs = 0;
00677 }
00678
00679 return 0;
00680
00681 #else
00682
00683
00684
00685
00686
00687 # if defined (ACE_HAS_PHARLAP)
00688 # if !defined (ACE_HAS_PHARLAP_RT)
00689 ACE_NOTSUP_RETURN (-1);
00690 # endif
00691
00692
00693
00694
00695
00696
00697 const size_t ACE_MAX_ETS_DEVICES = 64;
00698 DEVHANDLE ip_dev[ACE_MAX_ETS_DEVICES];
00699 EK_TCPIPCFG *devp;
00700 size_t i, j;
00701 ACE_TCHAR dev_name[16];
00702
00703 count = 0;
00704 for (i = 0; count < ACE_MAX_ETS_DEVICES; i++, ++count)
00705 {
00706
00707 ACE_OS::sprintf (dev_name,
00708 "ether%d",
00709 i);
00710 ip_dev[count] = EtsTCPGetDeviceHandle (dev_name);
00711 if (ip_dev[count] == 0)
00712 break;
00713 }
00714 for (i = 0; count < ACE_MAX_ETS_DEVICES; i++, ++count)
00715 {
00716
00717 ACE_OS::sprintf (dev_name,
00718 "sl%d",
00719 i);
00720 ip_dev[count] = EtsTCPGetDeviceHandle (dev_name);
00721 if (ip_dev[count] == 0)
00722 break;
00723 }
00724 for (i = 0; count < ACE_MAX_ETS_DEVICES; i++, ++count)
00725 {
00726
00727 ACE_OS::sprintf (dev_name,
00728 "ppp%d",
00729 i);
00730 ip_dev[count] = EtsTCPGetDeviceHandle (dev_name);
00731 if (ip_dev[count] == 0)
00732 break;
00733 }
00734
00735 if (count > 0)
00736 ACE_NEW_RETURN (addrs,
00737 ACE_INET_Addr[count],
00738 -1);
00739 else
00740 addrs = 0;
00741
00742 for (i = 0, j = 0; i < count; i++)
00743 {
00744 devp = EtsTCPGetDeviceCfg (ip_dev[i]);
00745 if (devp != 0)
00746 {
00747 addrs[j].set (0,
00748 devp->nwIPAddress,
00749 0);
00750 j++;
00751 }
00752
00753 }
00754
00755 count = j;
00756 if (count == 0 && addrs != 0)
00757 {
00758 delete [] addrs;
00759 addrs = 0;
00760 }
00761
00762 return 0;
00763
00764 # else
00765
00766 # if defined (ACE_HAS_WINCE)
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777 IP_ADAPTER_INFO* adapterInfo = 0;
00778 ULONG sz = 0;
00779 DWORD result = ::GetAdaptersInfo(adapterInfo, &sz);
00780
00781 while (result != ERROR_SUCCESS)
00782 {
00783 switch (result)
00784 {
00785 case ERROR_BUFFER_OVERFLOW:
00786 adapterInfo = (PIP_ADAPTER_INFO)(new char[sz]);
00787
00788 result = ::GetAdaptersInfo(adapterInfo, &sz);
00789 if (result == ERROR_SUCCESS) {
00790 const char* invalid_IP = "0.0.0.0";
00791
00792
00793 {
00794 IP_ADAPTER_INFO* tempAdapterInfo = adapterInfo;
00795 int n_interfaces = 0;
00796 while (tempAdapterInfo != 0) {
00797 IP_ADDR_STRING* addr = &tempAdapterInfo->IpAddressList;
00798 while (addr != 0) {
00799 if (ACE_OS::strcmp(addr->IpAddress.String, invalid_IP) != 0) {
00800
00801 ++n_interfaces;
00802 }
00803 addr = addr->Next;
00804 }
00805 tempAdapterInfo = tempAdapterInfo->Next;
00806 }
00807 if (n_interfaces == 0) {
00808 ACE_ERROR_RETURN ((LM_ERROR,
00809 ACE_LIB_TEXT ("%p\nACE::get_ip_interfaces - "),
00810 ACE_LIB_TEXT ("No adapter found.")),
00811 -1);
00812 }
00813
00814 ACE_NEW_RETURN (addrs, ACE_INET_Addr[n_interfaces], -2);
00815 }
00816
00817
00818 while (adapterInfo != 0) {
00819 IP_ADDR_STRING* addr = &adapterInfo->IpAddressList;
00820 while (addr != 0) {
00821 if (ACE_OS::strcmp(addr->IpAddress.String, invalid_IP) != 0) {
00822 addrs[count++] = ACE_INET_Addr((u_short) 0, addr->IpAddress.String);
00823 }
00824 addr = addr->Next;
00825 }
00826 adapterInfo = adapterInfo->Next;
00827 }
00828 }
00829
00830 break;
00831
00832 case ERROR_NOT_SUPPORTED:
00833 ACE_ERROR_RETURN ((LM_ERROR,
00834 ACE_LIB_TEXT ("%p\nACE::get_ip_interfaces - "),
00835 ACE_LIB_TEXT ("This version of WinCE does not support GetAdapterInfo.")),
00836 -1);
00837 break;
00838
00839 case ERROR_NO_DATA:
00840 ACE_ERROR_RETURN ((LM_ERROR,
00841 ACE_LIB_TEXT ("%p\nACE::get_ip_interfaces - "),
00842 ACE_LIB_TEXT ("No network adapter installed.")),
00843 -1);
00844 break;
00845
00846 case ERROR_INVALID_PARAMETER:
00847 ACE_ERROR_RETURN ((LM_ERROR,
00848 ACE_LIB_TEXT ("%p\nACE::get_ip_interfaces - "),
00849 ACE_LIB_TEXT ("Invalid parameter.")),
00850 -1);
00851 break;
00852
00853 default:
00854 ACE_ERROR_RETURN ((LM_ERROR,
00855 ACE_LIB_TEXT ("%p\nACE::get_ip_interfaces - "),
00856 ACE_LIB_TEXT ("Adapter info access permission denied.")),
00857 -1);
00858 break;
00859 }
00860 }
00861
00862 delete [] adapterInfo;
00863 return 0;
00864
00865 # endif // ACE_HAS_WINCE
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879 const ACE_TCHAR *BASE_KEY1;
00880
00881
00882
00883
00884 const ACE_TCHAR *KEY1_NAME_ID;
00885
00886
00887
00888
00889 unsigned int s_offset;
00890 const ACE_TCHAR *PREFFIX_KEY2;
00891 const ACE_TCHAR *SUFFIX_KEY2;
00892
00893
00894
00895 int use_subkeys;
00896
00897
00898
00899
00900
00901 const ACE_TCHAR *IPADDR_NAME_ID[3] = {
00902 ACE_LIB_TEXT ("IPAddress"), 0, 0
00903 };
00904
00905
00906 const ACE_TCHAR *INVALID_TCPIP_DEVICE_ADDR = ACE_LIB_TEXT ("0.0.0.0");
00907
00908 ACE_WINDOWS_VERSION winver = get_windows_version();
00909
00910 switch (winver)
00911 {
00912 case ACE_WINDOWS_IS_WINNT:
00913 PREFFIX_KEY2 = ACE_LIB_TEXT ("SYSTEM\\CurrentControlSet\\Services\\");
00914 BASE_KEY1 =
00915 ACE_LIB_TEXT ("SYSTEM\\CurrentControlSet\\Services")
00916 ACE_LIB_TEXT ("\\Tcpip\\Linkage");
00917 SUFFIX_KEY2 = ACE_LIB_TEXT ("\\Parameters\\Tcpip");
00918 KEY1_NAME_ID = ACE_LIB_TEXT ("Bind");
00919 s_offset = 8;
00920 use_subkeys = 0;
00921 break;
00922
00923 case ACE_WINDOWS_IS_WIN2K:
00924 BASE_KEY1 =
00925 ACE_LIB_TEXT ("SYSTEM\\CurrentControlSet\\Services")
00926 ACE_LIB_TEXT ("\\Tcpip\\Parameters\\Interfaces\\");
00927 PREFFIX_KEY2 = BASE_KEY1;
00928 SUFFIX_KEY2 = ACE_LIB_TEXT ("");
00929 KEY1_NAME_ID = 0;
00930 s_offset = 0;
00931 use_subkeys = 1;
00932
00933 IPADDR_NAME_ID[1] = ACE_LIB_TEXT ("DhcpIPAddress");
00934 break;
00935
00936
00937
00938 # if !defined(ACE_HAS_WINNT4) || (ACE_HAS_WINNT4 == 0)
00939 case ACE_WINDOWS_IS_WIN95:
00940 case ACE_WINDOWS_IS_WIN98:
00941 case ACE_WINDOWS_IS_WINME:
00942 PREFFIX_KEY2 =
00943 ACE_LIB_TEXT ("SYSTEM\\CurrentControlSet\\Services\\Class\\");
00944 BASE_KEY1 = ACE_LIB_TEXT ("Enum\\Network\\MSTCP");
00945 SUFFIX_KEY2 = ACE_LIB_TEXT ("");
00946 KEY1_NAME_ID = ACE_LIB_TEXT ("Driver");
00947 use_subkeys = 1;
00948 s_offset = 0;
00949 break;
00950 # endif
00951
00952 default:
00953 return -1;
00954 }
00955
00956 ACE_TCHAR raw_buffer[ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 1];
00957 DWORD raw_buflen = ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 1;
00958
00959 if (KEY1_NAME_ID == 0)
00960 {
00961 if (::get_reg_subkeys (BASE_KEY1,
00962 raw_buffer,
00963 raw_buflen))
00964 return -1;
00965 }
00966 else
00967 {
00968 if (::get_reg_value (BASE_KEY1,
00969 KEY1_NAME_ID,
00970 raw_buffer,
00971 raw_buflen,
00972 use_subkeys))
00973 return -1;
00974 }
00975
00976
00977 ACE_Tokenizer dev_names (raw_buffer);
00978 dev_names.delimiter (ACE_LIB_TEXT ('\0'));
00979 int n_interfaces = 0;
00980
00981
00982 while (dev_names.next () != 0)
00983 ++n_interfaces;
00984
00985
00986 if (n_interfaces == 0)
00987 return 0;
00988
00989 ACE_NEW_RETURN (addrs,
00990 ACE_INET_Addr[n_interfaces],
00991 -2);
00992
00993 ACE_TCHAR buffer[ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 1];
00994 DWORD buf_len = ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 1;
00995
00996 count = 0;
00997 for (int i = 0; i < n_interfaces; i++)
00998 {
00999 for (const ACE_TCHAR **ipaddr_name_id = IPADDR_NAME_ID;
01000 *ipaddr_name_id != 0;
01001 ++ipaddr_name_id)
01002 {
01003
01004 ACE_TString ifdevkey (PREFFIX_KEY2);
01005 ACE_TString the_dev = dev_names.next ();
01006
01007 if (the_dev.length() < s_offset)
01008 {
01009 return -3;
01010 }
01011
01012
01013 the_dev = the_dev.substring (s_offset);
01014
01015 ifdevkey += the_dev;
01016 ifdevkey += SUFFIX_KEY2;
01017
01018
01019
01020 buf_len = sizeof (buffer);
01021 if (get_reg_value (ifdevkey.fast_rep (),
01022 *ipaddr_name_id,
01023 buffer,
01024 buf_len))
01025 continue;
01026
01027 if (ACE_OS::strcmp (buffer,
01028 INVALID_TCPIP_DEVICE_ADDR) == 0)
01029 continue;
01030
01031
01032 addrs[count++] =
01033 ACE_INET_Addr ((u_short) 0, buffer);
01034 }
01035 }
01036
01037 return 0;
01038 # endif
01039 # endif
01040
01041 #elif defined (ACE_HAS_GETIFADDRS)
01042
01043
01044 struct ifaddrs *ifap;
01045 struct ifaddrs *p_if;
01046
01047 if (::getifaddrs (&ifap) != 0)
01048 return -1;
01049
01050
01051 size_t num_ifs = 0;
01052 for (p_if = ifap; p_if != 0; p_if = p_if->ifa_next)
01053 ++num_ifs;
01054
01055
01056 ACE_NEW_RETURN (addrs,
01057 ACE_INET_Addr[num_ifs],
01058 -1);
01059
01060
01061
01062
01063
01064 count = 0;
01065
01066 for (p_if = ifap;
01067 p_if != 0;
01068 p_if = p_if->ifa_next)
01069 {
01070 if (p_if->ifa_addr &&
01071 p_if->ifa_addr->sa_family == AF_INET)
01072 {
01073 struct sockaddr_in *addr =
01074 reinterpret_cast<sockaddr_in *> (p_if->ifa_addr);
01075
01076
01077
01078 if (addr->sin_addr.s_addr != INADDR_ANY)
01079 {
01080 addrs[count].set ((u_short) 0,
01081 addr->sin_addr.s_addr,
01082 0);
01083 ++count;
01084 }
01085 }
01086 # if defined (ACE_HAS_IPV6)
01087 else if (p_if->ifa_addr &&
01088 p_if->ifa_addr->sa_family == AF_INET6)
01089 {
01090 struct sockaddr_in6 *addr =
01091 reinterpret_cast<sockaddr_in6 *> (p_if->ifa_addr);
01092
01093
01094 if (!IN6_IS_ADDR_UNSPECIFIED(&addr->sin6_addr))
01095 {
01096 addrs[count].set(reinterpret_cast<struct sockaddr_in *> (addr),
01097 sizeof(sockaddr_in6));
01098 ++count;
01099 }
01100 }
01101 # endif
01102 }
01103
01104 ::freeifaddrs (ifap);
01105
01106 return 0;
01107
01108 #elif defined (__unix) || defined (__unix__) || defined (__Lynx__) || defined (_AIX) || defined (ACE_OPENVMS)
01109
01110
01111 size_t num_ifs, num_ifs_found;
01112
01113
01114 ACE_HANDLE handle = get_handle();
01115
01116 if (handle == ACE_INVALID_HANDLE)
01117 ACE_ERROR_RETURN ((LM_ERROR,
01118 ACE_LIB_TEXT ("%p\n"),
01119 ACE_LIB_TEXT ("ACE::get_ip_interfaces:open")),
01120 -1);
01121 if (ACE::count_interfaces (handle, num_ifs))
01122 {
01123 ACE_OS::close (handle);
01124 return -1;
01125 }
01126
01127
01128
01129 ++num_ifs;
01130
01131 struct ifreq *ifs = 0;
01132 ACE_NEW_RETURN (ifs,
01133 struct ifreq[num_ifs],
01134 -1);
01135 ACE_OS::memset (ifs, 0, num_ifs * sizeof (struct ifreq));
01136
01137 ACE_Auto_Array_Ptr<struct ifreq> p_ifs (ifs);
01138
01139 if (p_ifs.get() == 0)
01140 {
01141 ACE_OS::close (handle);
01142 errno = ENOMEM;
01143 return -1;
01144 }
01145
01146 struct ifconf ifcfg;
01147 ACE_OS::memset (&ifcfg, 0, sizeof (struct ifconf));
01148 ifcfg.ifc_req = p_ifs.get ();
01149 ifcfg.ifc_len = num_ifs * sizeof (struct ifreq);
01150
01151 #if defined (AIX)
01152 int cmd = CSIOCGIFCONF;
01153 #else
01154 int cmd = SIOCGIFCONF;
01155 #endif
01156 if (ACE_OS::ioctl (handle,
01157 cmd,
01158 (caddr_t) &ifcfg) == -1)
01159 {
01160 ACE_OS::close (handle);
01161 ACE_ERROR_RETURN ((LM_ERROR,
01162 ACE_LIB_TEXT ("%p\n"),
01163 ACE_LIB_TEXT ("ACE::get_ip_interfaces:")
01164 ACE_LIB_TEXT ("ioctl - SIOCGIFCONF failed")),
01165 -1);
01166 }
01167
01168 ACE_OS::close (handle);
01169
01170
01171
01172 ACE_NEW_RETURN (addrs,
01173 ACE_INET_Addr[num_ifs],
01174 -1);
01175
01176 struct ifreq *pcur = p_ifs.get ();
01177 num_ifs_found = ifcfg.ifc_len / sizeof (struct ifreq);
01178
01179
01180
01181
01182
01183 count = 0;
01184
01185 for (size_t i = 0;
01186 i < num_ifs_found;
01187 i++)
01188 {
01189 if (pcur->ifr_addr.sa_family == AF_INET)
01190 {
01191 #if !defined(_UNICOS)
01192 struct sockaddr_in *addr =
01193 reinterpret_cast<sockaddr_in *> (&pcur->ifr_addr);
01194
01195
01196
01197 if (addr->sin_addr.s_addr != 0)
01198 {
01199 addrs[count].set ((u_short) 0,
01200 addr->sin_addr.s_addr,
01201 0);
01202 count++;
01203 }
01204 #else
01205
01206
01207 struct sockaddr_in inAddr;
01208
01209 inAddr.sin_len = pcur->ifr_addr.sa_len;
01210 inAddr.sin_family = pcur->ifr_addr.sa_family;
01211 memcpy((void *)&(inAddr.sin_addr),
01212 (const void *)&(pcur->ifr_addr.sa_data[8]),
01213 sizeof(struct in_addr));
01214
01215 if (inAddr.sin_addr.s_addr != 0)
01216 {
01217 addrs[count].set(&inAddr, sizeof(struct sockaddr_in));
01218 ++count;
01219 }
01220 #endif
01221 }
01222
01223 #if !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__)
01224 ++pcur;
01225 #else
01226 if (pcur->ifr_addr.sa_len <= sizeof (struct sockaddr))
01227 {
01228 ++pcur;
01229 }
01230 else
01231 {
01232 pcur = (struct ifreq *)
01233 (pcur->ifr_addr.sa_len + (caddr_t) &pcur->ifr_addr);
01234 }
01235 #endif
01236 }
01237
01238 # if defined (ACE_HAS_IPV6)
01239
01240
01241 FILE* fp;
01242 char addr_p[8][5];
01243 char s_ipaddr[64];
01244 int scopeid;
01245 struct addrinfo hints, *res0;
01246 int error;
01247
01248 ACE_OS::memset (&hints, 0, sizeof (hints));
01249 hints.ai_flags = AI_NUMERICHOST;
01250 hints.ai_family = AF_INET6;
01251
01252 if ((fp = ACE_OS::fopen (ACE_LIB_TEXT ("/proc/net/if_inet6"), ACE_LIB_TEXT ("r"))) != NULL)
01253 {
01254 while (fscanf (fp,
01255 "%4s%4s%4s%4s%4s%4s%4s%4s %02x %*02x %*02x %*02x %*8s\n",
01256 addr_p[0], addr_p[1], addr_p[2], addr_p[3],
01257 addr_p[4], addr_p[5], addr_p[6], addr_p[7], &scopeid) != EOF)
01258 {
01259
01260
01261
01262 const char* ip_fmt = "%s:%s:%s:%s:%s:%s:%s:%s%%%d";
01263 ACE_OS::sprintf (s_ipaddr,
01264 ip_fmt,
01265 addr_p[0], addr_p[1], addr_p[2], addr_p[3],
01266 addr_p[4], addr_p[5], addr_p[6], addr_p[7], scopeid);
01267
01268 error = getaddrinfo (s_ipaddr, 0, &hints, &res0);
01269 if (error)
01270 continue;
01271
01272 if (res0->ai_family == AF_INET6 &&
01273 !IN6_IS_ADDR_UNSPECIFIED (&reinterpret_cast<sockaddr_in6 *> (res0->ai_addr)->sin6_addr))
01274 {
01275 addrs[count].set(reinterpret_cast<sockaddr_in *> (res0->ai_addr), res0->ai_addrlen);
01276 ++count;
01277 }
01278 freeaddrinfo (res0);
01279
01280 }
01281 ACE_OS::fclose (fp);
01282 }
01283 # endif
01284
01285 return 0;
01286 #elif defined (ACE_VXWORKS) && (ACE_VXWORKS < 0x600)
01287 count = 0;
01288
01289 for (struct in_ifaddr* ia = in_ifaddr; ia != 0; ia = ia->ia_next)
01290 {
01291 ++count;
01292 }
01293
01294
01295 ACE_NEW_RETURN (addrs,
01296 ACE_INET_Addr[count],
01297 -1);
01298 count = 0;
01299 for (struct in_ifaddr* ia = in_ifaddr; ia != 0; ia = ia->ia_next)
01300 {
01301 struct ifnet* ifp = ia->ia_ifa.ifa_ifp;
01302 if (ifp != 0)
01303 {
01304
01305 char interface[64];
01306 ACE_OS::sprintf(interface, "%s%d", ifp->if_name, ifp->if_unit);
01307
01308
01309 char address [INET_ADDR_LEN];
01310 STATUS status = ifAddrGet(interface, address);
01311
01312 if (status == OK)
01313 {
01314
01315
01316
01317
01318
01319 ACE_OS::strcat (address, ":");
01320 addrs[count].set (address);
01321 }
01322 else
01323 {
01324 ACE_ERROR_RETURN ((LM_ERROR,
01325 ACE_LIB_TEXT ("ACE::get_ip_interface failed\n")
01326 ACE_LIB_TEXT ("Couldnt get the IP Address\n")),
01327 -1);
01328 }
01329 ++count;
01330 }
01331 }
01332 return 0;
01333 #else
01334 ACE_UNUSED_ARG (count);
01335 ACE_UNUSED_ARG (addrs);
01336 ACE_NOTSUP_RETURN (-1);
01337 #endif
01338 }
01339
01340
01341
01342
01343
01344 int
01345 ACE::count_interfaces (ACE_HANDLE handle, size_t &how_many)
01346 {
01347 #if defined (sparc) && defined (SIOCGIFNUM)
01348 int tmp_how_many;
01349 if (ACE_OS::ioctl (handle,
01350 SIOCGIFNUM,
01351 (caddr_t) &tmp_how_many) == -1)
01352 ACE_ERROR_RETURN ((LM_ERROR,
01353 ACE_LIB_TEXT ("%p\n"),
01354 ACE_LIB_TEXT ("ACE::count_interfaces:")
01355 ACE_LIB_TEXT ("ioctl - SIOCGIFNUM failed")),
01356 -1);
01357 how_many = (size_t) tmp_how_many;
01358 return 0;
01359 #elif defined (ACE_HAS_GETIFADDRS)
01360 ACE_UNUSED_ARG (handle);
01361
01362 struct ifaddrs *ifap;
01363 struct ifaddrs *p_if;
01364
01365 if (::getifaddrs (&ifap) != 0)
01366 return -1;
01367
01368
01369 size_t num_ifs = 0;
01370 for (p_if = ifap; p_if != 0; p_if = p_if->ifa_next)
01371 ++num_ifs;
01372
01373 ::freeifaddrs (ifap);
01374
01375 how_many = num_ifs;
01376 return 0;
01377 #elif defined (__unix) || defined (__unix__) || defined (__Lynx__) || defined (_AIX) || defined (ACE_OPENVMS)
01378
01379
01380
01381
01382
01383
01384 const int MAX_IF = 50;
01385
01386
01387 int num_ifs = MAX_IF;
01388
01389 struct ifconf ifcfg;
01390 size_t ifreq_size = num_ifs * sizeof (struct ifreq);
01391 struct ifreq *p_ifs =
01392 (struct ifreq *) ACE_OS::malloc (ifreq_size);
01393
01394 if (!p_ifs)
01395 {
01396 errno = ENOMEM;
01397 return -1;
01398 }
01399
01400 ACE_OS::memset (p_ifs, 0, ifreq_size);
01401 ACE_OS::memset (&ifcfg, 0, sizeof (struct ifconf));
01402
01403 ifcfg.ifc_req = p_ifs;
01404 ifcfg.ifc_len = ifreq_size;
01405
01406 #if defined (AIX)
01407 int cmd = CSIOCGIFCONF;
01408 #else
01409 int cmd = SIOCGIFCONF;
01410 #endif
01411 if (ACE_OS::ioctl (handle,
01412 cmd,
01413 (caddr_t) &ifcfg) == -1)
01414 {
01415 ACE_OS::free (ifcfg.ifc_req);
01416 ACE_ERROR_RETURN ((LM_ERROR,
01417 ACE_LIB_TEXT ("%p\n"),
01418 ACE_LIB_TEXT ("ACE::count_interfaces:")
01419 ACE_LIB_TEXT ("ioctl - SIOCGIFCONF failed")),
01420 -1);
01421 }
01422
01423 int if_count = 0, i;
01424
01425
01426
01427 for (i = 0;
01428 i < num_ifs;
01429 i++)
01430 {
01431
01432 ifcfg.ifc_len -= sizeof (struct ifreq);
01433 if (ifcfg.ifc_len < 0)
01434 break;
01435
01436 if_count++;
01437 #if !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__)
01438 p_ifs++;
01439 #else
01440 if (p_ifs->ifr_addr.sa_len <= sizeof (struct sockaddr))
01441 {
01442 p_ifs++;
01443 }
01444 else
01445 {
01446 p_ifs = (struct ifreq *)
01447 (p_ifs->ifr_addr.sa_len + (caddr_t) &p_ifs->ifr_addr);
01448 }
01449 #endif
01450 }
01451
01452 ACE_OS::free (ifcfg.ifc_req);
01453
01454 # if defined (ACE_HAS_IPV6)
01455 FILE* fp;
01456
01457 if ((fp = ACE_OS::fopen (ACE_LIB_TEXT ("/proc/net/if_inet6"), ACE_LIB_TEXT ("r"))) != NULL)
01458 {
01459
01460 while (fscanf (fp, "%*32s %*02x %*02x %*02x %*02x %*8s\n") != EOF)
01461 {
01462 if_count++;
01463 }
01464 ACE_OS::fclose (fp);
01465 }
01466 # endif
01467
01468 how_many = if_count;
01469 return 0;
01470 #else
01471 ACE_UNUSED_ARG (handle);
01472 ACE_UNUSED_ARG (how_many);
01473 ACE_NOTSUP_RETURN (-1);
01474 #endif
01475 }
01476
01477
01478
01479 ACE_HANDLE
01480 ACE::get_handle (void)
01481 {
01482
01483 ACE_HANDLE handle = ACE_INVALID_HANDLE;
01484 #if defined (sparc)
01485 handle = ACE_OS::open ("/dev/udp", O_RDONLY);
01486 #elif defined (__unix) || defined (__unix__) || defined (__Lynx__) || defined (_AIX) || (defined (ACE_VXWORKS) && (ACE_VXWORKS >= 0x600)) || defined (ACE_OPENVMS)
01487
01488
01489
01490 handle = ACE_OS::socket (PF_INET, SOCK_DGRAM, 0);
01491 #endif
01492 return handle;
01493 }
01494
01495
01496 int
01497 ACE::ipv6_enabled (void)
01498 {
01499 #if defined (ACE_HAS_IPV6)
01500 if (ace_ipv6_enabled == -1)
01501 {
01502
01503 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
01504 *ACE_Static_Object_Lock::instance (), 0));
01505
01506 if (ace_ipv6_enabled == -1)
01507 {
01508
01509
01510 ACE_HANDLE s = ACE_OS::socket (PF_INET6, SOCK_DGRAM, 0);
01511 if (s == ACE_INVALID_HANDLE)
01512 {
01513 ace_ipv6_enabled = 0;
01514 }
01515 else
01516 {
01517 ace_ipv6_enabled = 1;
01518 ACE_OS::closesocket (s);
01519 }
01520 }
01521 }
01522
01523 return ace_ipv6_enabled;
01524 #else
01525 return 0;
01526 #endif
01527 }
01528
01529 ACE_END_VERSIONED_NAMESPACE_DECL