diff options
Diffstat (limited to 'ace/SOCK_Dgram_Bcast.cpp')
-rw-r--r-- | ace/SOCK_Dgram_Bcast.cpp | 163 |
1 files changed, 83 insertions, 80 deletions
diff --git a/ace/SOCK_Dgram_Bcast.cpp b/ace/SOCK_Dgram_Bcast.cpp index 833e89ff404..061ab9f669d 100644 --- a/ace/SOCK_Dgram_Bcast.cpp +++ b/ace/SOCK_Dgram_Bcast.cpp @@ -1,5 +1,7 @@ +// SOCK_Dgram_Bcast.cpp // $Id$ + #define ACE_BUILD_DLL #include "ace/SOCK_Dgram_Bcast.h" @@ -12,8 +14,8 @@ ACE_RCSID(ace, SOCK_Dgram_Bcast, "$Id$") ACE_ALLOC_HOOK_DEFINE(ACE_SOCK_Dgram_Bcast) ACE_Bcast_Node::ACE_Bcast_Node (ACE_INET_Addr &addr, - ACE_Bcast_Node *next) - : bcast_addr_ (addr), + ACE_Bcast_Node *next) + : bcast_addr_ (addr), next_ (next) { ACE_TRACE ("ACE_Bcast_Node::ACE_Bcast_Node"); @@ -58,12 +60,12 @@ ACE_SOCK_Dgram_Bcast::ACE_SOCK_Dgram_Bcast (void) // Here's the general-purpose constructor used by a connectionless // datagram ``server''... -ACE_SOCK_Dgram_Bcast::ACE_SOCK_Dgram_Bcast (const ACE_Addr &local, - int protocol_family, - int protocol, - int reuse_addr, +ACE_SOCK_Dgram_Bcast::ACE_SOCK_Dgram_Bcast (const ACE_Addr &local, + int protocol_family, + int protocol, + int reuse_addr, const ASYS_TCHAR *host_name) - : ACE_SOCK_Dgram (local, protocol_family, protocol, reuse_addr), + : ACE_SOCK_Dgram (local, protocol_family, protocol, reuse_addr), if_list_ (0) { ACE_TRACE ("ACE_SOCK_Dgram_Bcast::ACE_SOCK_Dgram_Bcast"); @@ -77,16 +79,16 @@ ACE_SOCK_Dgram_Bcast::ACE_SOCK_Dgram_Bcast (const ACE_Addr &local, // Here's the general-purpose open routine. int -ACE_SOCK_Dgram_Bcast::open (const ACE_Addr &local, - int protocol_family, - int protocol, - int reuse_addr, +ACE_SOCK_Dgram_Bcast::open (const ACE_Addr &local, + int protocol_family, + int protocol, + int reuse_addr, const ASYS_TCHAR *host_name) { ACE_TRACE ("ACE_SOCK_Dgram_Bcast::open"); - if (this->ACE_SOCK_Dgram::open (local, protocol_family, - protocol, reuse_addr) == -1) + if (this->ACE_SOCK_Dgram::open (local, protocol_family, + protocol, reuse_addr) == -1) return -1; return this->mk_broadcast (host_name); @@ -103,8 +105,8 @@ ACE_SOCK_Dgram_Bcast::mk_broadcast (const ASYS_TCHAR *host_name) if (ACE_OS::setsockopt (this->get_handle (), SOL_SOCKET, - SO_BROADCAST, - (char *) &one, + SO_BROADCAST, + (char *) &one, sizeof one) == -1) return -1; @@ -122,9 +124,9 @@ ACE_SOCK_Dgram_Bcast::mk_broadcast (const ASYS_TCHAR *host_name) if (ACE_OS::ioctl (s, SIOCGIFCONF, (char *) &ifc) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", - "ACE_SOCK_Dgram_Bcast::mk_broadcast: ioctl (get interface configuration)"), - ACE_INVALID_HANDLE); + ACE_ERROR_RETURN ((LM_ERROR, "%p\n", + "ACE_SOCK_Dgram_Bcast::mk_broadcast: ioctl (get interface configuration)"), + ACE_INVALID_HANDLE); struct ifreq *ifr = ifc.ifc_req; @@ -136,43 +138,44 @@ ACE_SOCK_Dgram_Bcast::mk_broadcast (const ASYS_TCHAR *host_name) hostent *hp = ACE_OS::gethostbyname (ASYS_MULTIBYTE_STRING (host_name)); if (hp == 0) - return -1; + return -1; else -#if defined(_UNICOS) +#if !defined(_UNICOS) + ACE_OS::memcpy ((char *) &host_addr.sin_addr.s_addr, + (char *) hp->h_addr, + hp->h_length); +#else /* _UNICOS */ { ACE_UINT64 haddr; // a place to put the address char * haddrp = (char *) &haddr; // convert to char pointer + haddr += 4; // adjust within the word ACE_OS::memcpy(haddrp,(char *) hp->h_addr,hp->h_length); host_addr.sin_addr.s_addr = haddr; } -#else /* ! _UNICOS */ - ACE_OS::memcpy ((char *) &host_addr.sin_addr.s_addr, - (char *) hp->h_addr, - hp->h_length); #endif /* ! _UNICOS */ } - for (int n = ifc.ifc_len / sizeof (struct ifreq) ; n > 0; n--, ifr++) + for (int n = ifc.ifc_len / sizeof (struct ifreq) ; n > 0; n--, ifr++) { // Compare host ip address with interface ip address. if (host_name) { - struct sockaddr_in if_addr; + struct sockaddr_in if_addr; ACE_OS::memcpy (&if_addr, &ifr->ifr_addr, sizeof if_addr); if (host_addr.sin_addr.s_addr != if_addr.sin_addr.s_addr) - continue; + continue; } - if (ifr->ifr_addr.sa_family != AF_INET) - { - ACE_ERROR ((LM_ERROR, "%p\n", - "ACE_SOCK_Dgram_Bcast::mk_broadcast: Not AF_INET")); - continue; - } + if (ifr->ifr_addr.sa_family != AF_INET) + { + ACE_ERROR ((LM_ERROR, "%p\n", + "ACE_SOCK_Dgram_Bcast::mk_broadcast: Not AF_INET")); + continue; + } struct ifreq flags = *ifr; struct ifreq if_req = *ifr; @@ -180,46 +183,46 @@ ACE_SOCK_Dgram_Bcast::mk_broadcast (const ASYS_TCHAR *host_name) if (ACE_OS::ioctl (s, SIOCGIFFLAGS, (char *) &flags) == -1) - { - ACE_ERROR ((LM_ERROR, "%p\n", - "ACE_SOCK_Dgram_Bcast::mk_broadcast: ioctl (get interface flags)")); - continue; - } + { + ACE_ERROR ((LM_ERROR, "%p\n", + "ACE_SOCK_Dgram_Bcast::mk_broadcast: ioctl (get interface flags)")); + continue; + } if (ACE_BIT_ENABLED (flags.ifr_flags, IFF_UP) == 0) - { - ACE_ERROR ((LM_ERROR, "%p\n", - "ACE_SOCK_Dgram_Bcast::mk_broadcast: Network interface is not up")); - continue; - } + { + ACE_ERROR ((LM_ERROR, "%p\n", + "ACE_SOCK_Dgram_Bcast::mk_broadcast: Network interface is not up")); + continue; + } if (ACE_BIT_ENABLED (flags.ifr_flags, IFF_LOOPBACK)) - continue; + continue; if (ACE_BIT_ENABLED (flags.ifr_flags, IFF_BROADCAST)) - { - if (ACE_OS::ioctl (s, + { + if (ACE_OS::ioctl (s, SIOCGIFBRDADDR, (char *) &if_req) == -1) - ACE_ERROR ((LM_ERROR, "%p\n", - "ACE_SOCK_Dgram_Bcast::mk_broadcast: ioctl (get broadaddr)")); - else - { - ACE_INET_Addr addr (ACE_reinterpret_cast (sockaddr_in *, + ACE_ERROR ((LM_ERROR, "%p\n", + "ACE_SOCK_Dgram_Bcast::mk_broadcast: ioctl (get broadaddr)")); + else + { + ACE_INET_Addr addr (ACE_reinterpret_cast (sockaddr_in *, &if_req.ifr_broadaddr), sizeof if_req.ifr_broadaddr); - ACE_NEW_RETURN (this->if_list_, + ACE_NEW_RETURN (this->if_list_, ACE_Bcast_Node (addr, this->if_list_), -1); - } - } - else - ACE_ERROR ((LM_ERROR, "%p\n", - "ACE_SOCK_Dgram_Bcast::mk_broadcast: Broadcast is not enable for this interface.")); + } + } + else + ACE_ERROR ((LM_ERROR, "%p\n", + "ACE_SOCK_Dgram_Bcast::mk_broadcast: Broadcast is not enable for this interface.")); } #else ACE_UNUSED_ARG (host_name); @@ -238,16 +241,16 @@ ACE_SOCK_Dgram_Bcast::mk_broadcast (const ASYS_TCHAR *host_name) // number of bytes sent. ssize_t -ACE_SOCK_Dgram_Bcast::send (const void *buf, - size_t n, - u_short port_number, - int flags) const +ACE_SOCK_Dgram_Bcast::send (const void *buf, + size_t n, + u_short port_number, + int flags) const { ACE_TRACE ("ACE_SOCK_Dgram_Bcast::send"); size_t iterations = 0; ssize_t total_bytes = 0; - if (this->if_list_ == 0) + if (this->if_list_ == 0) return -1; for (ACE_Bcast_Node *temp = this->if_list_; @@ -256,16 +259,16 @@ ACE_SOCK_Dgram_Bcast::send (const void *buf, { temp->bcast_addr_.set_port_number (port_number); - ssize_t bytes_sent = ACE_SOCK_Dgram::send (buf, - n, - temp->bcast_addr_, - flags); + ssize_t bytes_sent = ACE_SOCK_Dgram::send (buf, + n, + temp->bcast_addr_, + flags); if (bytes_sent == -1) - return -1; - else - total_bytes += bytes_sent; - + return -1; + else + total_bytes += bytes_sent; + iterations++; } @@ -276,21 +279,21 @@ ACE_SOCK_Dgram_Bcast::send (const void *buf, // Broadcast datagram to every interfaces. ssize_t -ACE_SOCK_Dgram_Bcast::send (const iovec iov[], - size_t n, - u_short /* port_number */, - int flags) const +ACE_SOCK_Dgram_Bcast::send (const iovec iov[], + size_t n, + u_short /* port_number */, + int flags) const { ACE_TRACE ("ACE_SOCK_Dgram_Bcast::send"); if (this->if_list_ == 0) return -1; - + // Send the message to every interface. for (ACE_Bcast_Node *temp = this->if_list_; temp != 0; - temp++) + temp++) if (ACE_SOCK_Dgram::send (iov, n, temp->bcast_addr_, @@ -304,10 +307,10 @@ ACE_SOCK_Dgram_Bcast::send (const iovec iov[], // must be preassigned to the broadcast address of the subnet...). ssize_t -ACE_SOCK_Dgram_Bcast::send (const iovec iov[], - size_t n, - const ACE_Addr &addr, - int flags) const +ACE_SOCK_Dgram_Bcast::send (const iovec iov[], + size_t n, + const ACE_Addr &addr, + int flags) const { ACE_TRACE ("ACE_SOCK_Dgram_Bcast::send"); |