本文整理汇总了C++中ACE_INET_Addr::get_addr方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_INET_Addr::get_addr方法的具体用法?C++ ACE_INET_Addr::get_addr怎么用?C++ ACE_INET_Addr::get_addr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_INET_Addr
的用法示例。
在下文中一共展示了ACE_INET_Addr::get_addr方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: validate_connection
int ProactorServerAcceptor::validate_connection(const ACE_Asynch_Accept::Result& Result, const ACE_INET_Addr& Remote, const ACE_INET_Addr& Local)
{
struct in_addr* remote_addr = reinterpret_cast<struct in_addr*>(Remote.get_addr());
struct in_addr* local_addr = reinterpret_cast <struct in_addr*>(Local.get_addr());
ACE_UNUSED_ARG(Result);
ACE_UNUSED_ARG(Remote);
ACE_UNUSED_ARG(Local);
return 0;
}
示例3:
// Open a RAPI QoS session [dest IP, dest port, Protocol ID].
int
ACE_RAPI_Session::open (ACE_INET_Addr dest_addr,
ACE_Protocol_ID protocol_id)
{
char buf [BUFSIZ];
dest_addr.addr_to_string (buf,
BUFSIZ);
ACELIB_DEBUG ((LM_DEBUG,
"In RAPI SESSION OPEN %s\n",
buf));
this->dest_addr_ = dest_addr;
this->protocol_id_ = protocol_id;
// Open a RAPI session. Note "this" is being passed as an argument to
// the callback function. The callback function uses this argument to
// update the QoS of this session based on the RSVP event it receives.
if ((this->session_id_ = rapi_session((struct sockaddr *) dest_addr.get_addr (),
protocol_id,
0,
rsvp_callback,
(void *) this,
&rsvp_error)) == NULL_SID)
ACELIB_ERROR_RETURN ((LM_ERROR,
"rapi_session () call fails. Error\n"),
-1);
else
ACELIB_DEBUG ((LM_DEBUG,
"rapi_session () call succeeds. "
"Session ID = %d\n",
this->session_id_));
return 0;
}
示例4: sizeof
// XXX: This will not work on any operating systems that do not support
// if_nametoindex
int
ACE_SOCK_Dgram_Mcast::make_multicast_ifaddr6 (ipv6_mreq *ret_mreq,
const ACE_INET_Addr &mcast_addr,
const ACE_TCHAR *net_if)
{
ACE_TRACE ("ACE_SOCK_Dgram_Mcast::make_multicast_ifaddr6");
ipv6_mreq lmreq; // Scratch copy.
ACE_OS::memset (&lmreq,
0,
sizeof (lmreq));
if (net_if != 0)
{
lmreq.ipv6mr_interface = ACE_OS::if_nametoindex (ACE_TEXT_ALWAYS_CHAR(net_if));
}
else
lmreq.ipv6mr_interface = 0;
// now set the multicast address
ACE_OS::memcpy (&lmreq.ipv6mr_multiaddr,
&((sockaddr_in6 *) mcast_addr.get_addr ())->sin6_addr,
sizeof (in6_addr));
// Set return info, if requested.
if (ret_mreq)
*ret_mreq = lmreq;
return 0;
}
示例5: me
void
ACE_Multihomed_INET_Addr::get_addresses(sockaddr_in6 *addrs,
size_t size) const
{
if (size == 0)
return;
// Copy primary address(es) to the first slot(s) of the user-supplied array
ACE_INET_Addr me (*this);
size_t i = 0;
for (i = 0; i < size; ++i)
{
sockaddr_in6 *in6 = reinterpret_cast<sockaddr_in6*> (me.get_addr ());
if (in6->sin6_family == AF_INET6)
{
addrs[i] = *in6;
++i;
}
if (!me.next ())
break;
}
// Copy secondary addresses to remaining slots of the user-supplied
// array. Secondary address [i] is copied to slot [i+1]
for (size_t j = 0; j < this->secondaries_.size (); ++j)
{
ACE_INET_Addr copy (this->secondaries_[j]);
for (; i < size; ++i)
{
sockaddr_in6 *in6 =
reinterpret_cast<sockaddr_in6*> (copy.get_addr ());
if (in6->sin6_family == AF_INET6)
{
addrs[i] = *in6;
++i;
}
if (!copy.next ())
break;
}
}
}
示例6: 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);
}
示例7: sizeof
int
ACE_Ping_Socket::send_echo_check (ACE_INET_Addr &remote_addr,
bool to_connect)
{
if (this->get_handle () == ACE_INVALID_HANDLE)
{
errno = EBADF;
return -1;
}
sockaddr_in *addr_connect = 0;
addr_connect = (sockaddr_in *) remote_addr.get_addr ();
/*
* Nulling port field to prevent strange behavior, when a raw
* socket is "connected" to a sockaddr_in with a non-nulled port.
*/
ACE_OS::memset ((void*) &addr_connect->sin_port,
0,
sizeof (addr_connect->sin_port));
// to connect the socket
if (to_connect && !this->connected_socket_)
{
if (ACE_OS::connect (this->get_handle (),
(sockaddr*) addr_connect,
remote_addr.get_size ()) == -1)
{
if (errno != EINTR)
return -1;
}
this->connected_socket_ = true;
}
ACE_OS::memset (this->icmp_send_buff_, 0, sizeof this->icmp_send_buff_);
int datalen = ICMP_DATA_LENGTH;
struct icmp *_icmp = 0;
_icmp = (struct icmp *) this->icmp_send_buff_;
_icmp->icmp_type = ICMP_ECHO;
_icmp->icmp_code = 0;
_icmp->icmp_id = ACE_OS::getpid () & 0xFFFF;
_icmp->icmp_seq = sequence_number_++;
#if defined (ACE_WIN32)
_icmp->icmp_data = GetTickCount ();
#else /* #if defined (ACE_WIN32) */
gettimeofday ((struct timeval *) &_icmp->icmp_data, 0);
#endif /* #if defined (ACE_WIN32) */
int length_icmp = ICMP_MIN + datalen; // checksum ICMP header and data.
_icmp->icmp_cksum = 0;
_icmp->icmp_cksum = inherited::calculate_checksum ((u_short *) _icmp,
length_icmp);
int rval_send = -1;
if ((rval_send = send ((void const *) icmp_send_buff_,
length_icmp,
remote_addr)) != length_icmp)
{
return -1;
}
return 0;
}
示例8: sizeof
int
ACE::Ping_Socket::send_echo_check (ACE_INET_Addr &remote_addr,
int to_connect)
{
if (this->get_handle () == ACE_INVALID_HANDLE)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) ACE::Ping_Socket::make_echo_check - "
"invalid descriptor."),
-1);
}
sockaddr_in *addr_connect = NULL;
addr_connect = (sockaddr_in *) remote_addr.get_addr ();
/*
* Nulling port field to prevent strange behavior, when a raw
* socket is "connected" to a sockaddr_in with a non-nulled port.
*/
ACE_OS::memset ((void*) &addr_connect->sin_port,
0,
sizeof (addr_connect->sin_port));
// to connect the socket
if (to_connect && !this->connected_socket_)
{
if (ACE_OS::connect (this->get_handle (),
(sockaddr*) addr_connect,
remote_addr.get_size ()) == -1)
{
if (errno != EINTR)
{
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n", "(%P|%t) "
"ACE::Ping_Socket::make_echo_check - "
"connect() failed."),
-1);
}
}
this->connected_socket_ = 1;
}
ACE_OS::memset (this->icmp_send_buff_, 0, sizeof this->icmp_send_buff_);
int datalen = ICMP_DATA_LENGTH;
struct icmp *_icmp;
_icmp = (struct icmp *) this->icmp_send_buff_;
_icmp->icmp_type = ICMP_ECHO;
_icmp->icmp_code = 0;
_icmp->icmp_id = getpid ();
_icmp->icmp_seq = sequence_number_++;
#if defined (ACE_WIN32)
_icmp->icmp_data = GetTickCount ();
#else /* #if defined (ACE_WIN32) */
gettimeofday ((struct timeval *) &_icmp->icmp_data, NULL);
#endif /* #if defined (ACE_WIN32) */
int length_icmp = ICMP_MIN + datalen; // checksum ICMP header and data.
_icmp->icmp_cksum = 0;
_icmp->icmp_cksum = inherited::calculate_checksum ((u_short *) _icmp,
length_icmp);
int rval_send = -1;
if ((rval_send = send ((void const *) icmp_send_buff_,
length_icmp,
remote_addr)) != length_icmp)
{
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) ACE::Ping_Socket::send_echo_check - "
"send() failed, sent %d bytes instead of %d.\n",
rval_send, length_icmp),
-1);
}
return 0;
}
示例9: 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")));
//.........这里部分代码省略.........
示例10: advance_addr
/*
* Advance the address by 1, e.g., 239.255.0.1 => 239.255.0.2
* Note that the algorithm is somewhat simplistic, but sufficient for our
* purpose.
*/
int advance_addr (ACE_INET_Addr &addr)
{
int a, b, c, d;
if (addr.get_type () == AF_INET)
{
::sscanf (addr.get_host_addr (), "%d.%d.%d.%d", &a, &b, &c, &d);
if (d < 255)
++d;
else if (c < 255)
{
d = 1;
++c;
}
else if (b < 255)
{
d = 1;
c = 0;
++b;
}
else if (a < 239)
{
d = 1;
c = 0;
b = 0;
++a;
}
else
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("advance_addr - Cannot advance multicast ")
ACE_TEXT ("group address past %s\n"),
addr.get_host_addr ()),
-1);
ACE_TCHAR buf[MAX_STRING_SIZE];
ACE_OS::sprintf (buf, ACE_TEXT ("%d.%d.%d.%d:%d"),
a, b, c, d, addr.get_port_number ());
addr.set (buf);
return 0;
}
#if defined (ACE_HAS_IPV6)
else // assume AF_INET6
{
sockaddr_in6 *saddr = reinterpret_cast<sockaddr_in6 *> (addr.get_addr ());
unsigned char *sin6_addr = reinterpret_cast<unsigned char *> (&saddr->sin6_addr);
int i = 15;
// i >= 2 is used here so that the flags and scope for the
// multicast address are not changed
while (i >= 2 && sin6_addr[i] == 0xff)
{
sin6_addr[i] = 0;
i--;
}
if (i >= 2)
{
sin6_addr[i]++;
}
else
{
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("advance_addr - Cannot advance ")
ACE_TEXT ("multicast group address past %s\n"),
addr.get_host_addr ()),
-1);
}
}
#endif /* ACE_HAS_IPV6 */
return 0;
}
示例11: defined
int
ACE_SOCK_Dgram_Mcast::join (const ACE_INET_Addr &mcast_addr,
int reuse_addr,
const ACE_TCHAR *net_if)
{
ACE_TRACE ("ACE_SOCK_Dgram_Mcast::join");
ACE_INET_Addr subscribe_addr = mcast_addr;
// If port# is 0, insert bound port# if it is set. (To satisfy lower-level
// port# validation.)
u_short def_port_number = this->send_addr_.get_port_number ();
if (subscribe_addr.get_port_number () == 0
&& def_port_number != 0)
{
subscribe_addr.set_port_number (def_port_number);
}
// Check for port# different than bound port#.
u_short sub_port_number = mcast_addr.get_port_number ();
if (sub_port_number != 0
&& def_port_number != 0
&& sub_port_number != def_port_number)
{
ACE_ERROR ((LM_ERROR,
ACE_LIB_TEXT ("Subscribed port# (%u) different than bound ")
ACE_LIB_TEXT ("port# (%u).\n"),
(u_int) sub_port_number,
(u_int) def_port_number));
errno = ENXIO;
return -1;
}
// If bind_addr_opt_ is enabled, check for address different than
// bound address.
#if defined (__linux__) && defined (ACE_HAS_IPV6)
if (ACE_BIT_ENABLED (this->opts_, OPT_BINDADDR_YES)
&& ((this->send_addr_.get_type () == AF_INET
&& this->send_addr_.get_ip_address () != INADDR_ANY
&& this->send_addr_.get_ip_address () != mcast_addr.get_ip_address ())
|| (this->send_addr_.get_type () == AF_INET6 &&
ACE_OS::memcmp
(&((sockaddr_in6 *) this->send_addr_.get_addr ())->sin6_addr,
&in6addr_any, sizeof (in6_addr)) != 0 &&
ACE_OS::memcmp
(&((sockaddr_in6 *) this->send_addr_.get_addr ())->sin6_addr,
&((sockaddr_in6 *) mcast_addr.get_addr ())->sin6_addr,
sizeof (in6_addr)) != 0)))
#else
if (ACE_BIT_ENABLED (this->opts_, OPT_BINDADDR_YES)
&& this->send_addr_.get_ip_address () != INADDR_ANY
&& this->send_addr_.get_ip_address () != mcast_addr.get_ip_address ())
#endif /* __linux__ && ACE_HAS_IPV6 */
{
ACE_TCHAR sub_addr_string[MAXNAMELEN + 1];
ACE_TCHAR bound_addr_string[MAXNAMELEN + 1];
ACE_SDM_helpers::addr_to_string (mcast_addr, sub_addr_string,
sizeof sub_addr_string, 1);
ACE_SDM_helpers::addr_to_string (this->send_addr_, bound_addr_string,
sizeof bound_addr_string, 1);
ACE_ERROR ((LM_ERROR,
ACE_LIB_TEXT ("Subscribed address (%s) different than ")
ACE_LIB_TEXT ("bound address (%s).\n"),
sub_addr_string,
bound_addr_string));
errno = ENXIO;
return -1;
}
// Attempt subscription.
int result = this->subscribe_i (subscribe_addr, reuse_addr, net_if);
#if defined (ACE_SOCK_DGRAM_MCAST_DUMPABLE)
if (result == 0)
{
// Add this addr/iface info to the list of subscriptions.
// (Assumes this is unique addr/iface combo - most systems don't allow
// re-sub to same addr/iface.)
ip_mreq *pmreq = new ip_mreq;
// (should not fail)
if (this->make_multicast_ifaddr (pmreq, subscribe_addr, net_if) != -1)
{
ACE_MT (ACE_GUARD_RETURN (ACE_SDM_LOCK, guard,
this->subscription_list_lock_, -1));
this->subscription_list_.insert_tail (pmreq);
return 0;
}
// this still isn't really right. If ACE_GUARD_RETURN fails, we leak.
// Need to add one of Chris' fancy ace auto pointers (bound?).
delete pmreq;
}
#endif /* ACE_SOCK_DGRAM_MCAST_DUMPABLE */
return result >= 0 ? 0 : result;
}