#include <SOCK_Dgram_Bcast.h>
Inheritance diagram for ACE_SOCK_Dgram_Bcast:


Public Member Functions | |
| ACE_SOCK_Dgram_Bcast (void) | |
| Default constructor. | |
| ACE_SOCK_Dgram_Bcast (const ACE_Addr &local, int protocol_family=PF_INET, int protocol=0, int reuse_addr=0, const ACE_TCHAR *host_name=0) | |
| ~ACE_SOCK_Dgram_Bcast (void) | |
| Default dtor. | |
| int | open (const ACE_Addr &local, int protocol_family=PF_INET, int protocol=0, int reuse_addr=0, const ACE_TCHAR *host_name=0) |
| Initiate a connectionless datagram broadcast endpoint. | |
| int | close (void) |
| Close up and release dynamically allocated resources. | |
| ssize_t | send (const void *buf, size_t n, u_short portnum, int flags=0) const |
| ssize_t | send (const iovec iov[], int n, u_short portnum, int flags=0) const |
| ssize_t | send (const void *buf, size_t n, const ACE_Addr &addr, int flags=0) const |
| ssize_t | send (const iovec iov[], int n, const ACE_Addr &addr, int flags=0) const |
| void | dump (void) const |
| Dump the state of an object. | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. | |
Private Member Functions | |
| int | mk_broadcast (const ACE_TCHAR *host_name) |
| Make broadcast available for Datagram socket. | |
| int | get_remote_addr (ACE_Addr &) const |
| Do not allow this function to percolate up to this interface... | |
Private Attributes | |
| ACE_Bcast_Node * | if_list_ |
| Points to the head of the list of broadcast interfaces. | |
Definition at line 57 of file SOCK_Dgram_Bcast.h.
|
|
Default constructor.
Definition at line 63 of file SOCK_Dgram_Bcast.cpp. References ACE_TRACE.
|
|
||||||||||||||||||||||||
|
Definition at line 72 of file SOCK_Dgram_Bcast.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TCHAR, ACE_TRACE, LM_ERROR, and mk_broadcast().
00077 : ACE_SOCK_Dgram (local, protocol_family, protocol, reuse_addr), 00078 if_list_ (0) 00079 { 00080 ACE_TRACE ("ACE_SOCK_Dgram_Bcast::ACE_SOCK_Dgram_Bcast"); 00081 00082 if (this->mk_broadcast (host_name) == -1) 00083 ACE_ERROR ((LM_ERROR, 00084 ACE_LIB_TEXT ("%p\n"), 00085 ACE_LIB_TEXT ("ACE_SOCK_Dgram_Bcast"))); 00086 } |
|
|
Default dtor.
Definition at line 15 of file SOCK_Dgram_Bcast.inl. References ACE_TRACE.
00016 {
00017 ACE_TRACE ("ACE_SOCK_Dgram_Bcast::~ACE_SOCK_Dgram_Bcast");
00018 }
|
|
|
Close up and release dynamically allocated resources.
Reimplemented from ACE_SOCK. Definition at line 41 of file SOCK_Dgram_Bcast.cpp. References ACE_TRACE, ACE_SOCK::close(), if_list_, and ACE_Bcast_Node::next_.
00042 {
00043 ACE_TRACE ("ACE_SOCK_Dgram_Bcast::close");
00044
00045 ACE_Bcast_Node *temp = this->if_list_;
00046 this->if_list_ = 0;
00047
00048 // Release the dynamically allocated memory.
00049
00050 while (temp != 0)
00051 {
00052 ACE_Bcast_Node *hold = temp->next_;
00053 delete temp;
00054 temp = hold;
00055 }
00056
00057 // Shut down the descriptor.
00058 return ACE_SOCK::close ();
00059 }
|
|
|
Dump the state of an object.
Reimplemented from ACE_SOCK_Dgram. Definition at line 31 of file SOCK_Dgram_Bcast.cpp. References ACE_TRACE.
00032 {
00033 #if defined (ACE_HAS_DUMP)
00034 ACE_TRACE ("ACE_SOCK_Dgram_Bcast::dump");
00035 #endif /* ACE_HAS_DUMP */
00036 }
|
|
|
Do not allow this function to percolate up to this interface...
Reimplemented from ACE_SOCK_Dgram. |
|
|
Make broadcast available for Datagram socket.
Definition at line 109 of file SOCK_Dgram_Bcast.cpp. References ACE_BIT_ENABLED, ACE_DEBUG, ACE_ERROR, ACE_ERROR_RETURN, ACE_NEW_RETURN, ACE_TCHAR, ACE_TEXT_ALWAYS_CHAR, ACE_TRACE, ACE_UINT64, caddr_t, ACE::debug(), ENXIO, ACE_IPC_SAP::get_handle(), ACE_OS::gethostbyname(), if_list_, ACE_OS::ioctl(), LM_DEBUG, LM_ERROR, ACE_OS::memcpy(), ACE_OS::setsockopt(), and SIOCGIFBRDADDR. Referenced by ACE_SOCK_Dgram_Bcast(), and open().
00110 {
00111 ACE_TRACE ("ACE_SOCK_Dgram_Bcast::mk_broadcast");
00112
00113 int one = 1;
00114
00115 if (ACE_OS::setsockopt (this->get_handle (),
00116 SOL_SOCKET,
00117 SO_BROADCAST,
00118 (char *) &one,
00119 sizeof one) == -1)
00120 ACE_ERROR_RETURN ((LM_ERROR, "%p\n",
00121 "ACE_SOCK_Dgram_Bcast::mk_broadcast: setsockopt failed"),
00122 -1);
00123
00124 #if !defined (ACE_WIN32) && !defined(__INTERIX)
00125 ACE_HANDLE s = this->get_handle ();
00126
00127 char buf[BUFSIZ];
00128 struct ifconf ifc;
00129
00130 ifc.ifc_len = sizeof buf;
00131 ifc.ifc_buf = buf;
00132
00133 // Get interface structure and initialize the addresses using UNIX
00134 // techniques.
00135 if (ACE_OS::ioctl (s,
00136 SIOCGIFCONF,
00137 (char *) &ifc) == -1)
00138 ACE_ERROR_RETURN ((LM_ERROR, "%p\n",
00139 "ACE_SOCK_Dgram_Bcast::mk_broadcast: ioctl (get interface configuration)"),
00140 ACE_INVALID_HANDLE);
00141
00142 struct ifreq *ifr = ifc.ifc_req;
00143
00144 struct sockaddr_in host_addr;
00145
00146 // Get host ip address
00147 if (host_name)
00148 {
00149 hostent *hp = ACE_OS::gethostbyname (ACE_TEXT_ALWAYS_CHAR (host_name));
00150
00151 if (hp == 0)
00152 return -1;
00153 else
00154 #if defined(_UNICOS)
00155 {
00156 ACE_UINT64 haddr; // a place to put the address
00157 char * haddrp = (char *) &haddr; // convert to char pointer
00158 ACE_OS::memcpy(haddrp,(char *) hp->h_addr,hp->h_length);
00159 host_addr.sin_addr.s_addr = haddr;
00160 }
00161 #else /* ! _UNICOS */
00162 ACE_OS::memcpy ((char *) &host_addr.sin_addr.s_addr,
00163 (char *) hp->h_addr,
00164 hp->h_length);
00165 #endif /* ! _UNICOS */
00166 }
00167
00168
00169 #if !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_VXWORKS) && !defined(__APPLE__)
00170 for (int n = ifc.ifc_len / sizeof (struct ifreq) ; n > 0;
00171 n--, ifr++)
00172 #else
00173 /*
00174 There are addresses longer than sizeof (struct sockaddr) eg. IPv6
00175 or QNX::links. In this case address does not fit into struct ifreq.
00176 The code below could be applied everywhere, but not every system
00177 provides sockaddr.sa_len field.
00178 */
00179 for (int nbytes = ifc.ifc_len; nbytes >= (int) sizeof (struct ifreq) &&
00180 ((ifr->ifr_addr.sa_len > sizeof (struct sockaddr)) ?
00181 (nbytes >= (int) sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len) : 1);
00182 ((ifr->ifr_addr.sa_len > sizeof (struct sockaddr)) ?
00183 (nbytes -= sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len,
00184 ifr = (struct ifreq *)
00185 ((caddr_t) &ifr->ifr_addr + ifr->ifr_addr.sa_len)) :
00186 (nbytes -= sizeof (struct ifreq), ifr++)))
00187 #endif /* !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_VXWORKS) && !defined(__APPLE__) */
00188 {
00189 #if defined (__QNX__) || defined (ACE_VXWORKS)
00190 // Silently skip link interfaces
00191 if (ifr->ifr_addr.sa_family == AF_LINK)
00192 continue;
00193 #endif /* __QNX__ */
00194 // Compare host ip address with interface ip address.
00195 if (host_name)
00196 {
00197 struct sockaddr_in if_addr;
00198
00199 ACE_OS::memcpy (&if_addr,
00200 &ifr->ifr_addr,
00201 sizeof if_addr);
00202
00203 if (host_addr.sin_addr.s_addr != if_addr.sin_addr.s_addr)
00204 continue;
00205 }
00206
00207 if (ifr->ifr_addr.sa_family != AF_INET)
00208 {
00209 // Note that some systems seem to generate 0 (AF_UNDEF) for
00210 // the sa_family, even when there are no errors! Thus, we
00211 // only print an error if this is not the case, or if we're
00212 // in "debugging" mode.
00213 if (ifr->ifr_addr.sa_family != 0
00214 || ACE::debug () > 0)
00215 ACE_DEBUG ((LM_DEBUG,
00216 "warning %p: sa_family: %d\n",
00217 "ACE_SOCK_Dgram_Bcast::mk_broadcast: Not AF_INET",
00218 ifr->ifr_addr.sa_family));
00219 continue;
00220 }
00221
00222 struct ifreq flags = *ifr;
00223 struct ifreq if_req = *ifr;
00224
00225 if (ACE_OS::ioctl (s,
00226 SIOCGIFFLAGS,
00227 (char *) &flags) == -1)
00228 {
00229 ACE_ERROR ((LM_ERROR, "%p [%s]\n",
00230 "ACE_SOCK_Dgram_Bcast::mk_broadcast: ioctl (get interface flags)",
00231 flags.ifr_name));
00232 continue;
00233 }
00234
00235 if (ACE_BIT_ENABLED (flags.ifr_flags,
00236 IFF_UP) == 0)
00237 {
00238 ACE_ERROR ((LM_ERROR, "%p [%s]\n",
00239 "ACE_SOCK_Dgram_Bcast::mk_broadcast: Network interface is not up",
00240 flags.ifr_name));
00241 continue;
00242 }
00243
00244 if (ACE_BIT_ENABLED (flags.ifr_flags,
00245 IFF_LOOPBACK))
00246 continue;
00247
00248 if (ACE_BIT_ENABLED (flags.ifr_flags,
00249 IFF_BROADCAST))
00250 {
00251 if (ACE_OS::ioctl (s,
00252 SIOCGIFBRDADDR,
00253 (char *) &if_req) == -1)
00254 ACE_ERROR ((LM_ERROR, "%p [%s]\n",
00255 "ACE_SOCK_Dgram_Bcast::mk_broadcast: ioctl (get broadaddr)",
00256 flags.ifr_name));
00257 else
00258 {
00259 ACE_INET_Addr addr (reinterpret_cast <sockaddr_in *>
00260 (&if_req.ifr_broadaddr),
00261 sizeof if_req.ifr_broadaddr);
00262 ACE_NEW_RETURN (this->if_list_,
00263 ACE_Bcast_Node (addr,
00264 this->if_list_),
00265 -1);
00266 }
00267 }
00268 else
00269 {
00270 if (host_name != 0)
00271 ACE_ERROR ((LM_ERROR, "%p [%s]\n",
00272 "ACE_SOCK_Dgram_Bcast::mk_broadcast: Broadcast is not enable for this interface.",
00273 flags.ifr_name));
00274 }
00275 }
00276 #else
00277 ACE_UNUSED_ARG (host_name);
00278
00279 ACE_INET_Addr addr (u_short (0),
00280 ACE_UINT32 (INADDR_BROADCAST));
00281 ACE_NEW_RETURN (this->if_list_,
00282 ACE_Bcast_Node (addr,
00283 this->if_list_),
00284 -1);
00285 #endif /* !ACE_WIN32 && !__INTERIX */
00286 if (this->if_list_ == 0)
00287 {
00288 errno = ENXIO;
00289 return -1;
00290 }
00291 else
00292 return 0;
00293 }
|
|
||||||||||||||||||||||||
|
Initiate a connectionless datagram broadcast endpoint.
Definition at line 91 of file SOCK_Dgram_Bcast.cpp. References ACE_TCHAR, ACE_TRACE, mk_broadcast(), and ACE_SOCK_Dgram::open().
00096 {
00097 ACE_TRACE ("ACE_SOCK_Dgram_Bcast::open");
00098
00099 if (this->ACE_SOCK_Dgram::open (local, protocol_family,
00100 protocol, reuse_addr) == -1)
00101 return -1;
00102
00103 return this->mk_broadcast (host_name);
00104 }
|
|
||||||||||||||||||||
|
Broadcast an iovec of size n to addr as a datagram (note that addr must be preassigned to the broadcast address of the subnet...) Reimplemented from ACE_SOCK_Dgram. |
|
||||||||||||||||||||
|
Broadcast an N byte datagram to ADDR (note that addr must be preassigned to the broadcast address of the subnet...). Reimplemented from ACE_SOCK_Dgram. Definition at line 24 of file SOCK_Dgram_Bcast.inl. References ACE_TRACE, ACE_Addr::get_addr(), ACE_Addr::get_size(), and ACE_OS::sendto().
00028 {
00029 ACE_TRACE ("ACE_SOCK_Dgram_Bcast::send");
00030
00031 sockaddr *saddr = (sockaddr *) addr.get_addr ();
00032 int len = addr.get_size ();
00033 return ACE_OS::sendto (this->get_handle (), (const char *) buf, n, flags,
00034 (struct sockaddr *) saddr, len);
00035 }
|
|
||||||||||||||||||||
|
Broadcast the datagrams to every interface. Returns the average number of bytes sent. |
|
||||||||||||||||||||
|
Broadcast the datagram to every interface. Returns the average number of bytes sent. Definition at line 299 of file SOCK_Dgram_Bcast.cpp. References ACE_TRACE, ACE_Bcast_Node::bcast_addr_, if_list_, ACE_Bcast_Node::next_, ACE_SOCK_Dgram::send(), ACE_INET_Addr::set_port_number(), and ssize_t.
00303 {
00304 ACE_TRACE ("ACE_SOCK_Dgram_Bcast::send");
00305 ssize_t iterations = 0;
00306 ssize_t total_bytes = 0;
00307
00308 if (this->if_list_ == 0)
00309 return -1;
00310
00311 for (ACE_Bcast_Node *temp = this->if_list_;
00312 temp != 0;
00313 temp = temp->next_)
00314 {
00315 temp->bcast_addr_.set_port_number (port_number);
00316
00317 ssize_t bytes_sent = ACE_SOCK_Dgram::send (buf,
00318 n,
00319 temp->bcast_addr_,
00320 flags);
00321
00322 if (bytes_sent == -1)
00323 return -1;
00324 else
00325 total_bytes += bytes_sent;
00326
00327 iterations++;
00328 }
00329
00330 return iterations == 0 ? 0 : total_bytes / iterations;
00331 }
|
|
|
Declare the dynamic allocation hooks.
Reimplemented from ACE_SOCK_Dgram. Definition at line 120 of file SOCK_Dgram_Bcast.h. |
|
|
Points to the head of the list of broadcast interfaces.
Definition at line 127 of file SOCK_Dgram_Bcast.h. Referenced by close(), mk_broadcast(), and send(). |
1.3.6