diff options
author | Adam Mitz <mitza@ociweb.com> | 2015-11-06 17:07:11 -0600 |
---|---|---|
committer | Adam Mitz <mitza@ociweb.com> | 2015-11-06 17:07:11 -0600 |
commit | ac5e1702c9f9bee9f1f7bfce8c1a6f3847ea6b4b (patch) | |
tree | 0e70d1f51c39e688a05a6cdc2af58408222e4a0d /ACE/ace/OS_NS_netdb.cpp | |
parent | 5272b5b81f92c298cb998b5bb0b0dbca3e7f29fe (diff) | |
download | ATCD-ac5e1702c9f9bee9f1f7bfce8c1a6f3847ea6b4b.tar.gz |
Merged branch ace-face-safety (FACE Safety Profile import from OCITAO).
Diffstat (limited to 'ACE/ace/OS_NS_netdb.cpp')
-rw-r--r-- | ACE/ace/OS_NS_netdb.cpp | 144 |
1 files changed, 137 insertions, 7 deletions
diff --git a/ACE/ace/OS_NS_netdb.cpp b/ACE/ace/OS_NS_netdb.cpp index 3d5432023cc..d2600b84418 100644 --- a/ACE/ace/OS_NS_netdb.cpp +++ b/ACE/ace/OS_NS_netdb.cpp @@ -5,24 +5,37 @@ # include "ace/OS_NS_netdb.inl" #endif /* ACE_HAS_INLINED_OSCALLS */ -#include "ace/os_include/net/os_if.h" -#include "ace/OS_NS_unistd.h" #if defined (ACE_WIN32) && defined (ACE_HAS_PHARLAP) -#include "ace/OS_NS_stdio.h" +# include "ace/OS_NS_stdio.h" #endif + +#include "ace/os_include/net/os_if.h" +#include "ace/Global_Macros.h" +#include "ace/OS_NS_stdlib.h" #include "ace/OS_NS_stropts.h" #include "ace/OS_NS_sys_socket.h" +#include "ace/OS_NS_unistd.h" #if defined (ACE_LINUX) && !defined (ACE_LACKS_NETWORKING) # include "ace/os_include/os_ifaddrs.h" #endif /* ACE_LINUX && !ACE_LACKS_NETWORKING */ +#ifdef ACE_LACKS_IOCTL +#include "ace/OS_NS_devctl.h" +#endif + +#ifdef ACE_HAS_ALLOC_HOOKS +# include "ace/Malloc_Base.h" +#endif + // Include if_arp so that getmacaddr can use the // arp structure. #if defined (sun) # include /**/ <net/if_arp.h> #endif +#include <algorithm> + ACE_BEGIN_VERSIONED_NAMESPACE_DECL int @@ -93,9 +106,7 @@ ACE_OS::getmacaddress (struct macaddr_node_t *node) for (i = 0; i < 10; i++) { // Ethernet. - ACE_OS::sprintf (dev_name, - "ether%d", - i); + ACE_OS::snprintf (dev_name, 16, "ether%d", i); ip_dev = EtsTCPGetDeviceHandle (dev_name); if (ip_dev != 0) break; @@ -203,7 +214,12 @@ ACE_OS::getmacaddress (struct macaddr_node_t *node) if (handle == ACE_INVALID_HANDLE) return -1; +# ifdef ACE_LACKS_IOCTL + int info = 0; + if (ACE_OS::posix_devctl (handle, SIOCGIFHWADDR, &ifr, sizeof ifr, &info) < 0) +# else if (ACE_OS::ioctl (handle/*s*/, SIOCGIFHWADDR, &ifr) < 0) +# endif { ACE_OS::close (handle); return -1; @@ -351,6 +367,121 @@ ACE_OS::getmacaddress (struct macaddr_node_t *node) #endif } +#ifdef ACE_LACKS_GETADDRINFO +int +ACE_OS::getaddrinfo_emulation (const char *name, addrinfo **result) +{ + hostent entry; + ACE_HOSTENT_DATA buffer; + int herr; + const hostent *host = ACE_OS::gethostbyname_r (name, &entry, buffer, &herr); + + if (host == 0) + switch (herr) + { + case NO_DATA: case HOST_NOT_FOUND: + return EAI_NONAME; + case TRY_AGAIN: + return EAI_AGAIN; + case NO_RECOVERY: + return EAI_FAIL; + default: + errno = herr; + return EAI_SYSTEM; + } + + size_t n = 0; + for (char **addr = host->h_addr_list; addr; ++addr, ++n) /*empty*/; + +# ifdef ACE_HAS_ALLOC_HOOKS + ACE_Allocator *const al = ACE_Allocator::instance (); +# define ACE_ALLOC al-> +# else +# define ACE_ALLOC ACE_OS:: +# endif + + ACE_ALLOCATOR_RETURN (*result, + (addrinfo *) ACE_ALLOC calloc (n, sizeof (addrinfo)), + EAI_MEMORY); + + sockaddr_in *const addr_storage = + (sockaddr_in *) ACE_ALLOC calloc (n, sizeof (sockaddr_in)); + + if (!addr_storage) + { + ACE_ALLOC free (*result); + *result = 0; + return EAI_MEMORY; + } + + for (size_t i = 0; i < n; ++i) + { + result[i]->ai_family = AF_INET; + result[i]->ai_addrlen = sizeof (sockaddr_in); + result[i]->ai_addr = (sockaddr *) addr_storage + i; + result[i]->ai_addr->sa_family = AF_INET; + ACE_OS::memcpy (&addr_storage[i].sin_addr, host->h_addr_list[i], + (std::min) (size_t (host->h_length), sizeof (in_addr))); + if (i < n - 1) + result[i]->ai_next = result[i + 1]; + } + + return 0; +} + +void +ACE_OS::freeaddrinfo_emulation (addrinfo *result) +{ +# ifdef ACE_HAS_ALLOC_HOOKS + ACE_Allocator *const al = ACE_Allocator::instance (); + al->free (result->ai_addr); + al->free (result); +# else + ACE_OS::free (result->ai_addr); + ACE_OS::free (result); +# endif +} +#endif /* ACE_LACKS_GETADDRINFO */ + +#ifdef ACE_LACKS_GETNAMEINFO +int +ACE_OS::getnameinfo_emulation (const sockaddr *saddr, ACE_SOCKET_LEN saddr_len, + char *host, ACE_SOCKET_LEN host_len) +{ + if (saddr_len != sizeof (sockaddr_in) || saddr->sa_family != AF_INET) + return EAI_FAMILY; // IPv6 support requries actual OS-provided getnameinfo + + const void *addr = &((const sockaddr_in *) saddr)->sin_addr; + int h_error; + hostent hentry; + ACE_HOSTENT_DATA buf; + hostent *const hp = + ACE_OS::gethostbyaddr_r (static_cast<const char *> (addr), +# ifdef ACE_LACKS_IN_ADDR_T + 4, +# else + sizeof (in_addr_t), +# endif + AF_INET, &hentry, buf, &h_error); + + if (hp == 0 || hp->h_name == 0) + return EAI_NONAME; + + if (ACE_OS::strlen (hp->h_name) >= host_len) + { + if (host_len > 0) + { + ACE_OS::memcpy (host, hp->h_name, host_len - 1); + host[host_len - 1] = '\0'; + } + return EAI_OVERFLOW; + } + + ACE_OS::strcpy (host, hp->h_name); + return 0; +} +#endif /* ACE_LACKS_GETNAMEINFO */ + ACE_END_VERSIONED_NAMESPACE_DECL # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) && defined (ACE_LACKS_NETDB_REENTRANT_FUNCTIONS) @@ -378,4 +509,3 @@ ACE_OS::netdb_release (void) ACE_END_VERSIONED_NAMESPACE_DECL # endif /* defined (ACE_LACKS_NETDB_REENTRANT_FUNCTIONS) */ - |