mirror of
https://github.com/mangosfour/server.git
synced 2025-12-12 01:37:00 +00:00
Some missing from merge.
Signed-off-by: Salja <salja2012@hotmail.de>
This commit is contained in:
parent
ec939a5bce
commit
f4be15a7af
1895 changed files with 160408 additions and 53601 deletions
|
|
@ -1,47 +1,30 @@
|
|||
// -*- C++ -*-
|
||||
// $Id: OS_NS_netdb.cpp 97320 2013-09-05 07:53:58Z johnnyw $
|
||||
|
||||
#include "ace/OS_NS_netdb.h"
|
||||
|
||||
#if !defined (ACE_HAS_INLINED_OSCALLS)
|
||||
# include "ace/OS_NS_netdb.inl"
|
||||
#endif /* ACE_HAS_INLINED_OSCALLS */
|
||||
|
||||
#if defined (ACE_WIN32) && defined (ACE_HAS_PHARLAP)
|
||||
# include "ace/OS_NS_stdio.h"
|
||||
#endif
|
||||
|
||||
#include "ace/os_include/net/os_if.h"
|
||||
#include "ace/Global_Macros.h"
|
||||
#include "ace/OS_NS_arpa_inet.h"
|
||||
#include "ace/OS_NS_stdlib.h"
|
||||
#include "ace/OS_NS_unistd.h"
|
||||
#if defined (ACE_WIN32) && defined (ACE_HAS_PHARLAP)
|
||||
#include "ace/OS_NS_stdio.h"
|
||||
#endif
|
||||
#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_VXWORKS
|
||||
# include "ace/os_include/sys/os_sysctl.h"
|
||||
# include <net/route.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
|
||||
|
|
@ -112,7 +95,9 @@ ACE_OS::getmacaddress (struct macaddr_node_t *node)
|
|||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
// Ethernet.
|
||||
ACE_OS::snprintf (dev_name, 16, "ether%d", i);
|
||||
ACE_OS::sprintf (dev_name,
|
||||
"ether%d",
|
||||
i);
|
||||
ip_dev = EtsTCPGetDeviceHandle (dev_name);
|
||||
if (ip_dev != 0)
|
||||
break;
|
||||
|
|
@ -220,12 +205,7 @@ 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;
|
||||
|
|
@ -367,193 +347,12 @@ ACE_OS::getmacaddress (struct macaddr_node_t *node)
|
|||
|
||||
return 0;
|
||||
|
||||
#elif defined ACE_VXWORKS
|
||||
|
||||
int name[] = {CTL_NET, AF_ROUTE, 0, 0, NET_RT_IFLIST, 0};
|
||||
static const size_t name_elts = sizeof name / sizeof name[0];
|
||||
|
||||
size_t result_sz = 0u;
|
||||
if (sysctl (name, name_elts, 0, &result_sz, 0, 0u) != 0)
|
||||
return -1;
|
||||
|
||||
# ifdef ACE_HAS_ALLOC_HOOKS
|
||||
char *const result =
|
||||
static_cast<char *> (ACE_Allocator::instance ()->malloc (result_sz));
|
||||
# define ACE_NETDB_CLEANUP ACE_Allocator::instance ()->free (result)
|
||||
# else
|
||||
char *const result = static_cast<char *> (ACE_OS::malloc (result_sz));
|
||||
# define ACE_NETDB_CLEANUP ACE_OS::free (result)
|
||||
# endif
|
||||
|
||||
if (sysctl (name, name_elts, result, &result_sz, 0, 0u) != 0)
|
||||
{
|
||||
ACE_NETDB_CLEANUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (size_t pos = 0, n; pos + sizeof (if_msghdr) < result_sz; pos += n)
|
||||
{
|
||||
if_msghdr *const hdr = reinterpret_cast<if_msghdr *> (result + pos);
|
||||
n = hdr->ifm_msglen;
|
||||
sockaddr_dl *const addr =
|
||||
reinterpret_cast<sockaddr_dl *> (result + pos + sizeof (if_msghdr));
|
||||
|
||||
if (addr->sdl_alen >= sizeof node->node)
|
||||
{
|
||||
ACE_OS::memcpy (node->node, LLADDR (addr), sizeof node->node);
|
||||
ACE_NETDB_CLEANUP;
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (pos + n < result_sz)
|
||||
{
|
||||
ifa_msghdr *const ifa =
|
||||
reinterpret_cast<ifa_msghdr *> (result + pos + n);
|
||||
if (ifa->ifam_type != RTM_NEWADDR)
|
||||
break;
|
||||
n += ifa->ifam_msglen;
|
||||
}
|
||||
}
|
||||
|
||||
ACE_NETDB_CLEANUP;
|
||||
# undef ACE_NETDB_CLEANUP
|
||||
return -1;
|
||||
|
||||
#else
|
||||
ACE_UNUSED_ARG (node);
|
||||
ACE_NOTSUP_RETURN (-1);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ACE_LACKS_GETADDRINFO
|
||||
int
|
||||
ACE_OS::getaddrinfo_emulation (const char *name, addrinfo **result)
|
||||
{
|
||||
hostent entry;
|
||||
ACE_HOSTENT_DATA buffer;
|
||||
int herr = 0;
|
||||
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;
|
||||
case ENOTSUP:
|
||||
if (ACE_OS::inet_aton (name, (in_addr *) &buffer[0]) != 0)
|
||||
{
|
||||
host = &entry;
|
||||
entry.h_length = sizeof (in_addr);
|
||||
entry.h_addr_list = (char **) (buffer + sizeof (in_addr));
|
||||
entry.h_addr_list[0] = buffer;
|
||||
entry.h_addr_list[1] = 0;
|
||||
break;
|
||||
}
|
||||
// fall-through
|
||||
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) >= size_t (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)
|
||||
|
|
@ -581,3 +380,4 @@ ACE_OS::netdb_release (void)
|
|||
ACE_END_VERSIONED_NAMESPACE_DECL
|
||||
|
||||
# endif /* defined (ACE_LACKS_NETDB_REENTRANT_FUNCTIONS) */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue