本文整理汇总了C++中ACE_INET_Addr::get_type方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_INET_Addr::get_type方法的具体用法?C++ ACE_INET_Addr::get_type怎么用?C++ ACE_INET_Addr::get_type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_INET_Addr
的用法示例。
在下文中一共展示了ACE_INET_Addr::get_type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: check_type_consistency
// Make sure that ACE_Addr::addr_type_ is the same
// as the family of the inet_addr_.
int check_type_consistency (const ACE_INET_Addr &addr)
{
int family = -1;
if (addr.get_type () == AF_INET)
{
struct sockaddr_in *sa4 = (struct sockaddr_in *)addr.get_addr();
family = sa4->sin_family;
}
#if defined (ACE_HAS_IPV6)
else if (addr.get_type () == AF_INET6)
{
struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)addr.get_addr();
family = sa6->sin6_family;
}
#endif
if (addr.get_type () != family)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Inconsistency between ACE_SOCK::addr_type_ (%d) ")
ACE_TEXT ("and the sockaddr family (%d)\n"),
addr.get_type (),
family));
return 1;
}
return 0;
}
示例2:
ACE_INET_Addr::ACE_INET_Addr (const ACE_INET_Addr &sa)
: ACE_Addr (sa.get_type (), sa.get_size())
{
ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr");
this->reset ();
this->set (sa);
}
示例3:
ssize_t
RtpsUdpSendStrategy::send_single_i(const iovec iov[], int n,
const ACE_INET_Addr& addr)
{
#ifdef ACE_HAS_IPV6
ACE_SOCK_Dgram& sock = link_->socket_for(addr.get_type());
#define USE_SOCKET sock
#else
#define USE_SOCKET link_->unicast_socket()
#endif
#ifdef ACE_LACKS_SENDMSG
char buffer[UDP_MAX_MESSAGE_SIZE];
char *iter = buffer;
for (int i = 0; i < n; ++i) {
if (iter - buffer + iov[i].iov_len > UDP_MAX_MESSAGE_SIZE) {
ACE_ERROR((LM_ERROR, "(%P|%t) RtpsUdpSendStrategy::send_single_i() - "
"message too large at index %d size %d\n", i, iov[i].iov_len));
return -1;
}
std::memcpy(iter, iov[i].iov_base, iov[i].iov_len);
iter += iov[i].iov_len;
}
const ssize_t result = USE_SOCKET.send(buffer, iter - buffer, addr);
#else
const ssize_t result = USE_SOCKET.send(iov, n, addr);
#endif
if (result < 0) {
ACE_TCHAR addr_buff[256] = {};
addr.addr_to_string(addr_buff, 256, 0);
ACE_ERROR((LM_ERROR, "(%P|%t) RtpsUdpSendStrategy::send_single_i() - "
"destination %s failed %p\n", addr_buff, ACE_TEXT("send")));
}
return result;
}
示例4:
bool
RtpsUdpTransport::map_ipv4_to_ipv6() const
{
bool map = false;
ACE_INET_Addr tmp;
link_->unicast_socket().get_local_addr(tmp);
if (tmp.get_type() != AF_INET) {
map = true;
}
return map;
}
示例5: sizeof
int
ACE_INET_Addr::set (const ACE_INET_Addr &sa)
{
ACE_TRACE ("ACE_INET_Addr::set");
if (sa.get_type () == AF_ANY)
// Ugh, this is really a base class, so don't copy it.
ACE_OS::memset (&this->inet_addr_, 0, sizeof (this->inet_addr_));
else
{
// It's ok to make the copy.
ACE_OS::memcpy (&this->inet_addr_,
&sa.inet_addr_,
sa.get_size ());
this->set_type (sa.get_type());
this->set_size (sa.get_size());
}
return 0;
}
示例6: return
bool
ACE_INET_Addr::operator == (const ACE_INET_Addr &sap) const
{
ACE_TRACE ("ACE_INET_Addr::operator ==");
if (this->get_type () != sap.get_type ()
|| this->get_size () != sap.get_size ())
return false;
return (ACE_OS::memcmp (&this->inet_addr_,
&sap.inet_addr_,
this->get_size ()) == 0);
}
示例7: defined
int
TAO_IIOP_Endpoint::set (const ACE_INET_Addr &addr,
int use_dotted_decimal_addresses)
{
char tmp_host[MAXHOSTNAMELEN + 1];
#if defined (ACE_HAS_IPV6)
this->is_ipv6_decimal_ = false; // Reset
#endif /* ACE_HAS_IPV6 */
if (use_dotted_decimal_addresses
|| addr.get_host_name (tmp_host, sizeof (tmp_host)) != 0)
{
if (use_dotted_decimal_addresses == 0 && TAO_debug_level > 5)
{
TAOLIB_DEBUG ((LM_DEBUG,
ACE_TEXT ("TAO (%P|%t) - IIOP_Endpoint::set, ")
ACE_TEXT ("%p\n"),
ACE_TEXT ("cannot determine hostname")));
}
const char *tmp = addr.get_host_addr ();
if (tmp == 0)
{
if (TAO_debug_level > 0)
{
TAOLIB_ERROR ((LM_ERROR,
ACE_TEXT ("TAO (%P|%t) - IIOP_Endpoint::set, ")
ACE_TEXT ("%p\n"),
ACE_TEXT ("cannot determine hostname and hostaddr")));
}
return -1;
}
else
{
this->host_ = tmp;
#if defined (ACE_HAS_IPV6)
if (addr.get_type () == PF_INET6)
this->is_ipv6_decimal_ = true;
#endif /* ACE_HAS_IPV6 */
}
}
else
this->host_ = CORBA::string_dup (tmp_host);
this->port_ = addr.get_port_number();
return 0;
}
示例8: defined
SimpleAddressServer::SimpleAddressServer (const ACE_INET_Addr& address) {
#if defined (ACE_HAS_IPV6)
if (address.get_type() == PF_INET6)
{
RtecUDPAdmin::UDP_Addr_v6 v6;
sockaddr_in6 *in6 =
reinterpret_cast<sockaddr_in6 *>(address.get_addr());
ACE_OS::memcpy (v6.ipaddr,&in6->sin6_addr,16);
v6.port = address.get_port_number();
this->address_.v6_addr (v6);
return;
}
#endif /* ACE_HAS_IPV6 */
RtecUDPAdmin::UDP_Addr v4;
v4.ipaddr = address.get_ip_address ();
v4.port = address.get_port_number ();
this->address_.v4_addr (v4);
}
示例9:
int
ACE_SOCK_Dgram_Mcast::open (const ACE_INET_Addr &mcast_addr,
const ACE_TCHAR *net_if,
int reuse_addr)
{
ACE_TRACE ("ACE_SOCK_Dgram_Mcast::open");
// Only perform the <open> initialization if we haven't been opened
// earlier.
// No sanity check? We should probably flag an error if the user
// makes multiple calls to open().
if (this->get_handle () != ACE_INVALID_HANDLE)
return 0;
// Invoke lower-layer ::open.
if (ACE_SOCK::open (SOCK_DGRAM,
mcast_addr.get_type (),
0, // always use 0
reuse_addr) == -1)
return -1;
return this->open_i (mcast_addr, net_if, reuse_addr);
}
示例10: defined
bool
ACE_INET_Addr::is_ip_equal (const ACE_INET_Addr &sap) const
{
if (this->get_type () != sap.get_type ()
|| this->get_size () != sap.get_size ())
return false;
#if defined (ACE_HAS_IPV6)
if (this->get_type () == PF_INET6)
{
const unsigned int *addr =
reinterpret_cast<const unsigned int*>(this->ip_addr_pointer());
const unsigned int *saddr =
reinterpret_cast<const unsigned int*>(sap.ip_addr_pointer());
return (addr[0] == saddr[0] &&
addr[1] == saddr[1] &&
addr[2] == saddr[2] &&
addr[3] == saddr[3]);
}
else
#endif /* ACE_HAS_IPV6 */
return this->get_ip_address () == sap.get_ip_address();
}
示例11: if
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
ACE_UNUSED_ARG (argc);
ACE_UNUSED_ARG (argv);
#if defined (ACE_HAS_IPV6)
int def_type = AF_UNSPEC;
#endif /* ACE_HAS_IPV6 */
// network interfaces.
ACE_INET_Addr *if_addrs = 0;
size_t if_cnt = 0;
if (ACE::get_ip_interfaces (if_cnt,
if_addrs) != 0
&& errno != ENOTSUP)
{
// In the case where errno == ENOTSUP, if_cnt and if_addrs will
// not be modified, and will each remain equal to zero. This
// causes the default interface to be used.
return -1;
}
if (if_cnt == 0 || if_addrs == 0)
{
ACE_DEBUG ((LM_WARNING,
ACE_TEXT ("TAO (%P|%t) Unable to probe network ")
ACE_TEXT ("interfaces. Using default.\n")));
if_cnt = 1; // Force the network interface count to be one.
delete [] if_addrs;
ACE_NEW_RETURN (if_addrs,
ACE_INET_Addr[if_cnt],
-1);
}
// Scan for the loopback interface since it shouldn't be included in
// the list of cached hostnames unless it is the only interface.
size_t lo_cnt = 0; // Loopback interface count
for (size_t j = 0; j < if_cnt; ++j)
if (if_addrs[j].is_loopback ())
++lo_cnt;
#if defined (ACE_HAS_IPV6)
size_t ipv4_cnt = 0;
size_t ipv4_lo_cnt = 0;
size_t ipv6_ll = 0;
bool ipv6_non_ll = false;
// Scan for IPv4 interfaces since these should not be included
// when IPv6-only is selected.
for (size_t j = 0; j < if_cnt; ++j)
if (if_addrs[j].get_type () != AF_INET6 ||
if_addrs[j].is_ipv4_mapped_ipv6 ())
{
++ipv4_cnt;
if (if_addrs[j].is_loopback ())
++ipv4_lo_cnt; // keep track of IPv4 loopback ifs
}
else if (!if_addrs[j].is_linklocal () &&
!if_addrs[j].is_loopback())
{
ipv6_non_ll = true; // we have at least 1 non-local IPv6 if
}
else if (// !orb_core->orb_params ()->use_ipv6_link_local () &&
if_addrs[j].is_linklocal ())
{
++ipv6_ll; // count link local addrs to exclude them afterwards
}
#endif /* ACE_HAS_IPV6 */
ACE_Auto_Basic_Array_Ptr<ACE_INET_Addr> safe_if_addrs (if_addrs);
#if defined (ACE_HAS_IPV6)
bool ipv4_only = def_type == AF_INET;
bool ipv6_only = (def_type == AF_INET6); // ||
// orb_core->orb_params ()->connect_ipv6_only ();
#if defined (ACE_WIN32)
if (default_address.get_type () == AF_INET)
ipv4_only = true;
else
ipv6_only = true;
#endif /* ACE_WIN32 */
// If the loopback interface is the only interface then include it
// in the list of interfaces to query for a hostname, otherwise
// exclude it from the list.
bool ignore_lo;
if (ipv6_only)
// only exclude loopback if non-local if exists
ignore_lo = ipv6_non_ll;
else if (ipv4_only)
ignore_lo = ipv4_cnt != ipv4_lo_cnt;
else
ignore_lo = if_cnt != lo_cnt;
// Adjust counts for IPv6 only if required
size_t if_ok_cnt = if_cnt;
if (ipv6_only)
{
if_ok_cnt -= ipv4_cnt;
//.........这里部分代码省略.........
示例12: bind_addy
int
ACE_SOCK_Dgram_Mcast::open_i (const ACE_INET_Addr &mcast_addr,
const ACE_TCHAR *net_if,
int reuse_addr)
{
ACE_TRACE ("ACE_SOCK_Dgram_Mcast::open_i");
// ACE_SOCK::open calls this if reuse_addr is set, so we only need to
// process port reuse option.
if (reuse_addr)
{
#if defined (SO_REUSEPORT)
int one = 1;
if (this->ACE_SOCK::set_option (SOL_SOCKET,
SO_REUSEPORT,
&one,
sizeof one) == -1)
return -1;
#endif /* SO_REUSEPORT */
}
// Create an address/port# to bind the socket to. Use mcast_addr to
// initialize bind_addy to pick up the correct protocol family. If
// OPT_BINDADDR_YES is set, then we're done. Else use mcast_addr's
// port number and use the "any" address.
ACE_INET_Addr bind_addy (mcast_addr);
if (ACE_BIT_DISABLED (this->opts_, OPT_BINDADDR_YES))
{
#if defined (ACE_HAS_IPV6)
if (mcast_addr.get_type () == PF_INET6)
{
if (bind_addy.set (mcast_addr.get_port_number (), "::",
1, AF_INET6) == -1)
return -1;
}
else
// Bind to "any" address and explicit port#.
if (bind_addy.set (mcast_addr.get_port_number ()) == -1)
return -1;
#else
// Bind to "any" address and explicit port#.
if (bind_addy.set (mcast_addr.get_port_number ()) == -1)
return -1;
#endif /* ACE_HAS_IPV6 */
}
// Bind to the address (which may be INADDR_ANY) and port# (which may be 0)
if (ACE_SOCK_Dgram::shared_open (bind_addy, bind_addy.get_type ()) == -1)
return -1;
// Cache the actual bound address (which may be INADDR_ANY)
// and the actual bound port# (which will be a valid, non-zero port#).
ACE_INET_Addr bound_addy;
if (this->get_local_addr (bound_addy) == -1)
{
// (Unexpected failure - should be bound to something)
if (bound_addy.set (bind_addy) == -1)
{
// (Shouldn't happen - bind_addy is a valid addy; punt.)
return -1;
}
}
this->send_addr_ = mcast_addr;
this->send_addr_.set_port_number (bound_addy.get_port_number ());
if (net_if)
{
#if defined (IP_MULTICAST_IF) && (IP_MULTICAST_IF != 0)
#if defined (__linux__) && defined (ACE_HAS_IPV6)
if (mcast_addr.get_type () == AF_INET6)
{
ipv6_mreq send_mreq;
if (this->make_multicast_ifaddr6 (&send_mreq,
mcast_addr,
net_if) == -1)
return -1;
if (this->ACE_SOCK::set_option
(IPPROTO_IPV6, IPV6_MULTICAST_IF,
&(send_mreq.ipv6mr_interface),
sizeof send_mreq.ipv6mr_interface) == -1)
return -1;
}
else
{
ip_mreq send_mreq;
if (this->make_multicast_ifaddr (&send_mreq,
mcast_addr,
net_if) == -1)
return -1;
if (this->ACE_SOCK::set_option (IPPROTO_IP,
IP_MULTICAST_IF,
&(send_mreq.imr_interface),
sizeof send_mreq.imr_interface) == -1)
return -1;
}
#else
ip_mreq send_mreq;
if (this->make_multicast_ifaddr (&send_mreq,
mcast_addr,
net_if) == -1)
return -1;
//.........这里部分代码省略.........
示例13: defined
int
ACE_SOCK_Dgram_Mcast::subscribe_ifs (const ACE_INET_Addr &mcast_addr,
const ACE_TCHAR *net_if,
int reuse_addr)
{
ACE_TRACE ("ACE_SOCK_Dgram_Mcast::subscribe_ifs");
if (ACE_BIT_ENABLED (this->opts_, OPT_NULLIFACE_ALL)
&& net_if == 0)
{
#if defined (__linux__) && defined (ACE_HAS_IPV6)
if (mcast_addr.get_type () == AF_INET6)
{
struct if_nameindex *intf;
intf = ACE_OS::if_nameindex ();
if (intf == 0)
return -1;
size_t nr_subscribed = 0;
int index = 0;
while (intf[index].if_index != 0 || intf[index].if_name != 0)
{
if (this->join (mcast_addr, reuse_addr,
ACE_TEXT_CHAR_TO_TCHAR(intf[index].if_name)) == 0)
++nr_subscribed;
++index;
}
ACE_OS::if_freenameindex (intf);
if (nr_subscribed == 0)
{
errno = ENODEV;
return -1;
}
return 1;
}
else
{
// Subscribe on all local multicast-capable network interfaces, by
// doing recursive calls with specific interfaces.
ACE_INET_Addr *if_addrs = 0;
size_t if_cnt;
if (ACE::get_ip_interfaces (if_cnt, if_addrs) != 0)
return -1;
size_t nr_subscribed = 0;
if (if_cnt < 2)
{
if (this->subscribe (mcast_addr,
reuse_addr,
ACE_LIB_TEXT ("0.0.0.0")) == 0)
++nr_subscribed;
}
else
{
// Iterate through all the interfaces, figure out which ones
// offer multicast service, and subscribe to them.
while (if_cnt > 0)
{
--if_cnt;
// Convert to 0-based for indexing, next loop check.
if (if_addrs[if_cnt].get_ip_address () == INADDR_LOOPBACK)
continue;
if (this->subscribe (mcast_addr,
reuse_addr,
ACE_TEXT_CHAR_TO_TCHAR
(if_addrs[if_cnt].get_host_addr ())) == 0)
++nr_subscribed;
}
}
delete [] if_addrs;
if (nr_subscribed == 0)
{
errno = ENODEV;
return -1;
}
// 1 indicates a "short-circuit" return. This handles the
// recursive behavior of checking all the interfaces.
return 1;
}
#else
// Subscribe on all local multicast-capable network interfaces, by
// doing recursive calls with specific interfaces.
ACE_INET_Addr *if_addrs = 0;
size_t if_cnt;
//.........这里部分代码省略.........
示例14: if
// Attempt subscribe and return status.
int
ACE_SOCK_Dgram_Mcast::subscribe_i (const ACE_INET_Addr &mcast_addr,
int reuse_addr,
const ACE_TCHAR *net_if)
{
ACE_TRACE ("ACE_SOCK_Dgram_Mcast::subscribe_i");
ip_mreq mreq;
#if defined (__linux__) && defined (ACE_HAS_IPV6)
ipv6_mreq mreq6;
#endif /* __linux__ && ACE_HAS_IPV6 */
// Open the socket IFF this is the first ::subscribe and ::open
// was not explicitly invoked.
if (this->open (mcast_addr,
net_if,
reuse_addr) == -1)
return -1;
// Only do this if net_if == 0, i.e., INADDR_ANY
if (net_if == 0)
{
int result = this->subscribe_ifs (mcast_addr,
net_if,
reuse_addr);
// Check for error or "short-circuit" return.
if (result != 0)
return result;
}
#if defined (__linux__) && defined (ACE_HAS_IPV6)
if (mcast_addr.get_type () == AF_INET6)
{
if (this->make_multicast_ifaddr6 (&mreq6, mcast_addr, net_if) == -1)
return -1;
// Tell IP stack to pass messages sent to this group.
else if (this->ACE_SOCK::set_option (IPPROTO_IPV6,
IPV6_JOIN_GROUP,
&mreq6,
sizeof mreq6) == -1)
return -1;
}
else
{
// Create multicast addr/if struct.
if (this->make_multicast_ifaddr (&mreq, mcast_addr, net_if) == -1)
return -1;
// Tell IP stack to pass messages sent to this group.
else if (this->ACE_SOCK::set_option (IPPROTO_IP,
IP_ADD_MEMBERSHIP,
&mreq,
sizeof mreq) == -1)
return -1;
}
#else
if (this->make_multicast_ifaddr (&mreq, mcast_addr, net_if) == -1)
return -1;
// Tell IP stack to pass messages sent to this group.
// Note, this is not IPv6 compliant.
else if (this->ACE_SOCK::set_option (IPPROTO_IP,
IP_ADD_MEMBERSHIP,
&mreq,
sizeof mreq) == -1)
return -1;
#endif /* __linux__ && ACE_HAS_IPV6 */
return 0;
}
示例15: g
template <class HANDLER> int
ACE_Asynch_Acceptor<HANDLER>::open (const ACE_INET_Addr &address,
size_t bytes_to_read,
bool pass_addresses,
int backlog,
int reuse_addr,
ACE_Proactor *proactor,
bool validate_new_connection,
int reissue_accept,
int number_of_initial_accepts)
{
ACE_TRACE ("ACE_Asynch_Acceptor<>::open");
this->proactor (proactor);
this->pass_addresses_ = pass_addresses;
this->bytes_to_read_ = bytes_to_read;
this->validate_new_connection_ = validate_new_connection;
this->reissue_accept_ = reissue_accept;
this->addr_family_ = address.get_type ();
// Create the listener socket
this->listen_handle_ = ACE_OS::socket (address.get_type (), SOCK_STREAM, 0);
if (this->listen_handle_ == ACE_INVALID_HANDLE)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("ACE_OS::socket")),
-1);
// Initialize the ACE_Asynch_Accept
if (this->asynch_accept_.open (*this,
this->listen_handle_,
0,
this->proactor ()) == -1)
{
ACE_Errno_Guard g (errno);
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("ACE_Asynch_Accept::open")));
ACE_OS::closesocket (this->listen_handle_);
this->listen_handle_ = ACE_INVALID_HANDLE;
return -1;
}
if (reuse_addr)
{
// Reuse the address
int one = 1;
if (ACE_OS::setsockopt (this->listen_handle_,
SOL_SOCKET,
SO_REUSEADDR,
(const char*) &one,
sizeof one) == -1)
{
ACE_Errno_Guard g (errno);
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("ACE_OS::setsockopt")));
ACE_OS::closesocket (this->listen_handle_);
this->listen_handle_ = ACE_INVALID_HANDLE;
return -1;
}
}
// If port is not specified, bind to any port.
static ACE_INET_Addr sa (ACE_sap_any_cast (const ACE_INET_Addr &));
if (address == sa &&
ACE::bind_port (this->listen_handle_,
INADDR_ANY,
address.get_type()) == -1)
{
ACE_Errno_Guard g (errno);
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("ACE::bind_port")));
ACE_OS::closesocket (this->listen_handle_);
this->listen_handle_ = ACE_INVALID_HANDLE;
return -1;
}
// Bind to the specified port.
if (ACE_OS::bind (this->listen_handle_,
reinterpret_cast<sockaddr *> (address.get_addr ()),
address.get_size ()) == -1)
{
ACE_Errno_Guard g (errno);
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("ACE_OS::bind")));
ACE_OS::closesocket (this->listen_handle_);
this->listen_handle_ = ACE_INVALID_HANDLE;
return -1;
}
// Start listening.
if (ACE_OS::listen (this->listen_handle_, backlog) == -1)
{
ACE_Errno_Guard g (errno);
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("ACE_OS::listen")));
//.........这里部分代码省略.........