#include <SOCK_Dgram.h>
Inheritance diagram for ACE_SOCK_Dgram:


Public Types | |
| typedef ACE_INET_Addr | PEER_ADDR |
Public Methods | |
| ACE_SOCK_Dgram (void) | |
| Default constructor. More... | |
| ACE_SOCK_Dgram (const ACE_Addr &local, int protocol_family=ACE_PROTOCOL_FAMILY_INET, int protocol=0, int reuse_addr=0) | |
| This is a BSD-style method (i.e., no QoS) for initiating a socket dgram that will accept datagrams at the <local> address. More... | |
| ACE_SOCK_Dgram (const ACE_Addr &local, int protocol_family, int protocol, ACE_Protocol_Info *protocolinfo, ACE_SOCK_GROUP g=0, u_long flags=0, int reuse_addr=0) | |
| int | open (const ACE_Addr &local, int protocol_family=ACE_PROTOCOL_FAMILY_INET, int protocol=0, int reuse_addr=0) |
| This is a BSD-style method (i.e., no QoS) for initiating a socket dgram that will accept datagrams at the <local> address. More... | |
| int | open (const ACE_Addr &local, int protocol_family, int protocol, ACE_Protocol_Info *protocolinfo, ACE_SOCK_GROUP g=0, u_long flags=0, int reuse_addr=0) |
| ~ACE_SOCK_Dgram (void) | |
| Default dtor. More... | |
| ssize_t | send (const void *buf, size_t n, const ACE_Addr &addr, int flags=0) const |
| Send an <n> byte <buf> to the datagram socket (uses <sendto(3)>). More... | |
| ssize_t | recv (void *buf, size_t n, ACE_Addr &addr, int flags=0) const |
| Receive an <n> byte <buf> from the datagram socket (uses <recvfrom(3)>). More... | |
| ssize_t | recv (iovec *io_vec, ACE_Addr &addr, int flags=0, const ACE_Time_Value *timeout=0) const |
| ssize_t | send (const iovec iov[], int n, const ACE_Addr &addr, int flags=0) const |
| Send an <iovec> of size <n> to the datagram socket (uses <sendmsg(3)>). More... | |
| ssize_t | recv (iovec iov[], int n, ACE_Addr &addr, int flags=0) const |
| Recv an <iovec> of size <n> to the datagram socket (uses <recvmsg(3)>). More... | |
| ssize_t | recv (void *buf, size_t n, ACE_Addr &addr, int flags, const ACE_Time_Value *timeout) const |
| ssize_t | send (const void *buf, size_t n, const ACE_Addr &addr, int flags, const ACE_Time_Value *timeout) const |
| ssize_t | send (const iovec buffers[], int buffer_count, size_t &number_of_bytes_sent, int flags, const ACE_Addr &addr, ACE_OVERLAPPED *overlapped, ACE_OVERLAPPED_COMPLETION_FUNC func) const |
| Send <buffer_count> worth of <buffers> to <addr> using overlapped I/O (uses <WSASendTo>). Returns 0 on success. More... | |
| ssize_t | recv (iovec buffers[], int buffer_count, size_t &number_of_bytes_recvd, int &flags, ACE_Addr &addr, ACE_OVERLAPPED *overlapped, ACE_OVERLAPPED_COMPLETION_FUNC func) const |
| Recv <buffer_count> worth of <buffers> from <addr> using overlapped I/O (uses <WSARecvFrom>). Returns 0 on success. More... | |
| ssize_t | send (const void *buf, size_t n, const ACE_Addr &addr, int flags, ACE_OVERLAPPED *overlapped, ACE_OVERLAPPED_COMPLETION_FUNC func) const |
| Send an <n> byte <buf> to the datagram socket (uses <WSASendTo>). More... | |
| ssize_t | recv (void *buf, size_t n, ACE_Addr &addr, int flags, ACE_OVERLAPPED *overlapped, ACE_OVERLAPPED_COMPLETION_FUNC func) const |
| Receive an <n> byte <buf> from the datagram socket (uses <WSARecvFrom>). More... | |
| void | dump (void) const |
| Dump the state of an object. More... | |
| void | set_nic (const char *option_value) |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. More... | |
Protected Methods | |
| int | shared_open (const ACE_Addr &local, int protocol_family) |
| Open is shared by this and by <LSOCK_Dgram>. More... | |
Private Methods | |
| int | get_remote_addr (ACE_Addr &) const |
| Do not allow this function to percolate up to this interface... More... | |
Definition at line 33 of file SOCK_Dgram.h.
|
|
Definition at line 192 of file SOCK_Dgram.h. |
|
|
Default constructor.
Definition at line 9 of file SOCK_Dgram.i. References ACE_TRACE.
00010 {
00011 ACE_TRACE ("ACE_SOCK_Dgram::ACE_SOCK_Dgram");
00012 }
|
|
||||||||||||||||||||
|
This is a BSD-style method (i.e., no QoS) for initiating a socket dgram that will accept datagrams at the <local> address.
Definition at line 195 of file SOCK_Dgram.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, and open.
00199 {
00200 ACE_TRACE ("ACE_SOCK_Dgram::ACE_SOCK_Dgram");
00201
00202 if (this->open (local,
00203 protocol_family,
00204 protocol,
00205 reuse_addr) == -1)
00206 ACE_ERROR ((LM_ERROR,
00207 ACE_LIB_TEXT ("%p\n"),
00208 ACE_LIB_TEXT ("ACE_SOCK_Dgram")));
00209 }
|
|
||||||||||||||||||||||||||||||||
|
This is a QoS-enabed method for initiating a socket dgram that will accept datagrams at the <local> address. The <qos_params> are passed to <ACE_OS::join_leaf>. Definition at line 211 of file SOCK_Dgram.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_SOCK_GROUP, ACE_TRACE, LM_ERROR, and open.
00218 {
00219 ACE_TRACE ("ACE_SOCK_Dgram::ACE_SOCK_Dgram");
00220 if (this->open (local,
00221 protocol_family,
00222 protocol,
00223 protocolinfo,
00224 g,
00225 flags,
00226 reuse_addr) == -1)
00227 ACE_ERROR ((LM_ERROR,
00228 ACE_LIB_TEXT ("%p\n"),
00229 ACE_LIB_TEXT ("ACE_SOCK_Dgram")));
00230 }
|
|
|
Default dtor.
Definition at line 15 of file SOCK_Dgram.i. References ACE_TRACE.
00016 {
00017 ACE_TRACE ("ACE_SOCK_Dgram::~ACE_SOCK_Dgram");
00018 }
|
|
|
Dump the state of an object.
Reimplemented from ACE_SOCK. Reimplemented in ACE_LSOCK_Dgram. Definition at line 20 of file SOCK_Dgram.cpp. References ACE_TRACE. Referenced by ACE_LSOCK_Dgram::dump.
00021 {
00022 ACE_TRACE ("ACE_SOCK_Dgram::dump");
00023 }
|
|
|
Do not allow this function to percolate up to this interface...
Reimplemented from ACE_SOCK. Reimplemented in ACE_SOCK_Dgram_Bcast. |
|
||||||||||||||||||||||||||||||||
|
This is a QoS-enabed method for initiating a socket dgram that will accept datagrams at the <local> address. The <qos_params> are passed to <ACE_OS::join_leaf>. Definition at line 138 of file SOCK_Dgram.cpp. References ACE_SOCK_GROUP, ACE_SOCK::open, and shared_open.
00145 {
00146 if (ACE_SOCK::open (SOCK_DGRAM,
00147 protocol_family,
00148 protocol,
00149 protocolinfo,
00150 g,
00151 flags,
00152 reuse_addr) == -1)
00153 return -1;
00154 else if (this->shared_open (local,
00155 protocol_family) == -1)
00156 return -1;
00157 else
00158 return 0;
00159 }
|
|
||||||||||||||||||||
|
This is a BSD-style method (i.e., no QoS) for initiating a socket dgram that will accept datagrams at the <local> address.
Definition at line 164 of file SOCK_Dgram.cpp. References ACE_TRACE, ACE_Addr::get_type, ACE_Sock_Connect::ipv6_enabled, ACE_SOCK::open, ACE_Addr::sap_any, and shared_open. Referenced by ACE_SOCK_Dgram, ACE_SOCK_Dgram_Bcast::open, and ACE_LSOCK_Dgram::open.
00168 {
00169 ACE_TRACE ("ACE_SOCK_Dgram::open");
00170
00171 if (local != ACE_Addr::sap_any)
00172 protocol_family = local.get_type ();
00173 else if (protocol_family == PF_UNSPEC)
00174 {
00175 #if defined (ACE_HAS_IPV6)
00176 protocol_family = ACE_Sock_Connect::ipv6_enabled () ? PF_INET6 : PF_INET;
00177 #else
00178 protocol_family = PF_INET;
00179 #endif /* ACE_HAS_IPV6 */
00180 }
00181
00182 if (ACE_SOCK::open (SOCK_DGRAM,
00183 protocol_family,
00184 protocol,
00185 reuse_addr) == -1)
00186 return -1;
00187 else
00188 return this->shared_open (local,
00189 protocol_family);
00190 }
|
|
||||||||||||||||||||||||||||
|
Receive an <n> byte <buf> from the datagram socket (uses <WSARecvFrom>).
Definition at line 138 of file SOCK_Dgram.i. References ACE_OVERLAPPED, ACE_OVERLAPPED_COMPLETION_FUNC, ACE_TRACE, iovec::iov_base, iovec::iov_len, and recv.
00144 {
00145 ACE_TRACE ("ACE_SOCK_Dgram::recv");
00146
00147 iovec buffer[1];
00148 buffer[0].iov_len = ACE_static_cast (u_long, n); // Betting on < 4G
00149 buffer[0].iov_base = (char *) buf;
00150 size_t number_of_bytes_recvd = 0;
00151 return this->recv (buffer,
00152 1,
00153 number_of_bytes_recvd,
00154 flags,
00155 addr,
00156 overlapped,
00157 func);
00158 }
|
|
||||||||||||||||||||||||||||||||
|
Recv <buffer_count> worth of <buffers> from <addr> using overlapped I/O (uses <WSARecvFrom>). Returns 0 on success.
Definition at line 85 of file SOCK_Dgram.i. References ACE_OVERLAPPED, ACE_OVERLAPPED_COMPLETION_FUNC, ACE_TRACE, ACE_Addr::get_addr, ACE_Addr::get_size, ACE_OS::recvfrom, ACE_Addr::set_size, and ssize_t.
00092 {
00093 ACE_TRACE ("ACE_SOCK_Dgram::recv");
00094 sockaddr *saddr = (sockaddr *) addr.get_addr ();
00095 int addr_len = addr.get_size ();
00096
00097 ssize_t status = ACE_OS::recvfrom (this->get_handle (),
00098 buffers,
00099 buffer_count,
00100 number_of_bytes_recvd,
00101 flags,
00102 (sockaddr *) saddr,
00103 &addr_len,
00104 overlapped,
00105 func);
00106 addr.set_size (addr_len);
00107 return status;
00108 }
|
|
||||||||||||||||||||||||
|
Wait up to <timeout> amount of time to receive a datagram into <buf>. The <ACE_Time_Value> indicates how long to blocking trying to receive. If <timeout> == 0, the caller will block until action is possible, else will wait until the relative time specified in *<timeout> elapses). If <recv> times out a -1 is returned with <errno == ETIME>. If it succeeds the number of bytes received is returned. Definition at line 420 of file SOCK_Dgram.cpp. References ETIME, recv, ACE_Handle_Set::reset, ACE_OS::select, and ACE_Handle_Set::set_bit.
00425 {
00426 ACE_Handle_Set handle_set;
00427 handle_set.reset ();
00428 handle_set.set_bit (this->get_handle ());
00429
00430 // Check the status of the current socket.
00431 int select_width;
00432 #if defined (ACE_WIN64)
00433 // This arg is ignored on Windows and causes pointer truncation
00434 // warnings on 64-bit compiles.
00435 select_width = 0;
00436 #else
00437 select_width = int (this->get_handle ()) + 1;
00438 #endif /* ACE_WIN64 */
00439 switch (ACE_OS::select (select_width,
00440 handle_set,
00441 0,
00442 0,
00443 timeout))
00444 {
00445 case -1:
00446 return -1;
00447 /* NOTREACHED */
00448 case 0:
00449 errno = ETIME;
00450 return -1;
00451 /* NOTREACHED */
00452 default:
00453 // Goes fine, call <recv> to get data
00454 return this->recv (buf, n, addr, flags);
00455 }
00456 }
|
|
||||||||||||||||||||
|
Recv an <iovec> of size <n> to the datagram socket (uses <recvmsg(3)>).
Definition at line 360 of file SOCK_Dgram.cpp. References ACE_NEW_RETURN, ACE_TRACE, iovec::iov_len, ACE_OS_String::memcpy, recv, and ssize_t.
00364 {
00365 ACE_TRACE ("ACE_SOCK_Dgram::recv");
00366
00367 ssize_t length = 0;
00368 int i;
00369
00370 for (i = 0; i < n; i++)
00371 #if ! (defined(__BORLANDC__) && (__BORLANDC__ >= 0x0530))
00372 // The iov_len is unsigned in Borland. If we go ahead and try the
00373 // if, it will emit a warning.
00374 if (iov[i].iov_len < 0)
00375 return -1;
00376 else
00377 #endif
00378 length += iov[i].iov_len;
00379
00380 char *buf;
00381
00382 #if defined (ACE_HAS_ALLOCA)
00383 buf = alloca (length);
00384 #else
00385 ACE_NEW_RETURN (buf,
00386 char[length],
00387 -1);
00388 #endif /* !defined (ACE_HAS_ALLOCA) */
00389
00390 length = ACE_SOCK_Dgram::recv (buf, length, addr, flags);
00391
00392 if (length != -1)
00393 {
00394 char *ptr = buf;
00395 int copyn = length;
00396
00397 for (i = 0;
00398 i < n && copyn > 0;
00399 i++)
00400 {
00401 ACE_OS::memcpy (iov[i].iov_base, ptr,
00402 // iov_len is int on some platforms, size_t on others
00403 copyn > (int) iov[i].iov_len
00404 ? (size_t) iov[i].iov_len
00405 : (size_t) copyn);
00406 ptr += iov[i].iov_len;
00407 copyn -= iov[i].iov_len;
00408 }
00409 }
00410
00411 #if !defined (ACE_HAS_ALLOCA)
00412 delete [] buf;
00413 #endif /* !defined (ACE_HAS_ALLOCA) */
00414 return length;
00415 }
|
|
||||||||||||||||||||
|
Allows a client to read from a socket without having to provide a buffer to read. This method determines how much data is in the socket, allocates a buffer of this size, reads in the data, and returns the number of bytes read. The caller is responsible for deleting the member in the <iov_base> field of <io_vec> using the ``delete []'' syntax. Definition at line 31 of file SOCK_Dgram.cpp. References ACE_NEW_RETURN, ACE_TRACE, ETIME, ACE_Addr::get_addr, ACE_Addr::get_size, ACE_OS::ioctl, iovec::iov_base, iovec::iov_len, ACE_OS::recvfrom, ACE_Handle_Set::reset, ACE_OS::select, ACE_Handle_Set::set_bit, and ACE_Addr::set_size.
00035 {
00036 ACE_TRACE ("ACE_SOCK_Dgram::recv");
00037 #if defined (FIONREAD)
00038 ACE_Handle_Set handle_set;
00039 handle_set.reset ();
00040 handle_set.set_bit (this->get_handle ());
00041
00042 // Check the status of the current socket to make sure there's data
00043 // to recv (or time out).
00044 int select_width;
00045 # if defined (ACE_WIN64)
00046 // This arg is ignored on Windows and causes pointer truncation
00047 // warnings on 64-bit compiles.
00048 select_width = 0;
00049 # else
00050 select_width = int (this->get_handle ()) + 1;
00051 # endif /* ACE_WIN64 */
00052 switch (ACE_OS::select (select_width,
00053 handle_set,
00054 0, 0,
00055 timeout))
00056 {
00057 case -1:
00058 return -1;
00059 /* NOTREACHED */
00060 case 0:
00061 errno = ETIME;
00062 return -1;
00063 /* NOTREACHED */
00064 default:
00065 // Goes fine, fallthrough to get data
00066 break;
00067 }
00068
00069 sockaddr *saddr = (sockaddr *) addr.get_addr ();
00070 int addr_len = addr.get_size ();
00071 u_long inlen;
00072
00073 if (ACE_OS::ioctl (this->get_handle (),
00074 FIONREAD, (u_long *) &inlen) == -1)
00075 return -1;
00076 else if (inlen > 0)
00077 {
00078 ACE_NEW_RETURN (io_vec->iov_base,
00079 char[inlen],
00080 -1);
00081 io_vec->iov_len = ACE_OS::recvfrom (this->get_handle (),
00082 (char *) io_vec->iov_base,
00083 inlen,
00084 flags,
00085 (sockaddr *) saddr,
00086 &addr_len);
00087 addr.set_size (addr_len);
00088 return io_vec->iov_len;
00089 }
00090 else
00091 return 0;
00092 #else
00093 ACE_UNUSED_ARG (flags);
00094 ACE_UNUSED_ARG (addr);
00095 ACE_UNUSED_ARG (io_vec);
00096 ACE_UNUSED_ARG (timeout);
00097 ACE_NOTSUP_RETURN (-1);
00098 #endif /* FIONREAD */
00099 }
|
|
||||||||||||||||||||
|
Receive an <n> byte <buf> from the datagram socket (uses <recvfrom(3)>).
Definition at line 42 of file SOCK_Dgram.i. References ACE_TRACE, ACE_Addr::get_addr, ACE_Addr::get_size, ACE_OS::recvfrom, ACE_Addr::set_size, and ssize_t. Referenced by recv.
00046 {
00047 ACE_TRACE ("ACE_SOCK_Dgram::recv");
00048 sockaddr *saddr = (sockaddr *) addr.get_addr ();
00049 int addr_len = addr.get_size ();
00050
00051 ssize_t status = ACE_OS::recvfrom (this->get_handle (),
00052 (char *) buf,
00053 n,
00054 flags,
00055 (sockaddr *) saddr,
00056 &addr_len);
00057 addr.set_size (addr_len);
00058 return status;
00059 }
|
|
||||||||||||||||||||||||||||
|
Send an <n> byte <buf> to the datagram socket (uses <WSASendTo>).
Definition at line 113 of file SOCK_Dgram.i. References ACE_OVERLAPPED, ACE_OVERLAPPED_COMPLETION_FUNC, ACE_TRACE, iovec::iov_base, iovec::iov_len, and send.
00119 {
00120 ACE_TRACE ("ACE_SOCK_Dgram::send");
00121
00122 iovec buffer[1];
00123 buffer[0].iov_len = ACE_static_cast (u_long, n); // Betting on < 4G
00124 buffer[0].iov_base = (char *) buf;
00125 size_t number_of_bytes_sent = 0;
00126 return this->send (buffer,
00127 1,
00128 number_of_bytes_sent,
00129 flags,
00130 addr,
00131 overlapped,
00132 func);
00133 }
|
|
||||||||||||||||||||||||||||||||
|
Send <buffer_count> worth of <buffers> to <addr> using overlapped I/O (uses <WSASendTo>). Returns 0 on success.
Definition at line 62 of file SOCK_Dgram.i. References ACE_OVERLAPPED, ACE_OVERLAPPED_COMPLETION_FUNC, ACE_TRACE, ACE_Addr::get_addr, ACE_Addr::get_size, and ACE_OS::sendto.
00069 {
00070 ACE_TRACE ("ACE_SOCK_Dgram::send");
00071 sockaddr *saddr = (sockaddr *) addr.get_addr ();
00072 int len = addr.get_size ();
00073 return ACE_OS::sendto (this->get_handle (),
00074 buffers,
00075 buffer_count,
00076 number_of_bytes_sent,
00077 flags,
00078 (const sockaddr *) saddr,
00079 len,
00080 overlapped,
00081 func);
00082 }
|
|
||||||||||||||||||||||||
|
Wait up to <timeout> amount of time to send a datagram to <buf>. The <ACE_Time_Value> indicates how long to blocking trying to receive. If <timeout> == 0, the caller will block until action is possible, else will wait until the relative time specified in *<timeout> elapses). If <send> times out a -1 is returned with <errno == ETIME>. If it succeeds the number of bytes sent is returned. Definition at line 459 of file SOCK_Dgram.cpp. References ETIME, ACE_Handle_Set::reset, ACE_OS::select, send, and ACE_Handle_Set::set_bit.
00464 {
00465 ACE_Handle_Set handle_set;
00466 handle_set.reset ();
00467 handle_set.set_bit (this->get_handle ());
00468
00469 // Check the status of the current socket.
00470 int select_width;
00471 #if defined (ACE_WIN64)
00472 // This arg is ignored on Windows and causes pointer truncation
00473 // warnings on 64-bit compiles.
00474 select_width = 0;
00475 #else
00476 select_width = int (this->get_handle ()) + 1;
00477 #endif /* ACE_WIN64 */
00478 switch (ACE_OS::select (select_width,
00479 0,
00480 handle_set,
00481 0,
00482 timeout))
00483 {
00484 case -1:
00485 return -1;
00486 /* NOTREACHED */
00487 case 0:
00488 errno = ETIME;
00489 return -1;
00490 /* NOTREACHED */
00491 default:
00492 // Goes fine, call <send> to transmit the data.
00493 return this->send (buf, n, addr, flags);
00494 }
00495 }
|
|
||||||||||||||||||||
|
Send an <iovec> of size <n> to the datagram socket (uses <sendmsg(3)>).
Reimplemented in ACE_SOCK_Dgram_Bcast. Definition at line 310 of file SOCK_Dgram.cpp. References ACE_NEW_RETURN, ACE_TRACE, iovec::iov_len, ACE_OS_String::memcpy, send, and ssize_t.
00314 {
00315 ACE_TRACE ("ACE_SOCK_Dgram::send");
00316
00317 size_t length = 0;
00318 int i;
00319
00320 // Determine the total length of all the buffers in <iov>.
00321 for (i = 0; i < n; i++)
00322 #if ! (defined(__BORLANDC__) && (__BORLANDC__ >= 0x0530))
00323 // The iov_len is unsigned in Borland. If we go ahead and try the
00324 // if, it will emit a warning.
00325 if (iov[i].iov_len < 0)
00326 return -1;
00327 else
00328 #endif
00329 length += iov[i].iov_len;
00330
00331 char *buf;
00332
00333 #if defined (ACE_HAS_ALLOCA)
00334 buf = alloca (length);
00335 #else
00336 ACE_NEW_RETURN (buf,
00337 char[length],
00338 -1);
00339 #endif /* !defined (ACE_HAS_ALLOCA) */
00340
00341 char *ptr = buf;
00342
00343 for (i = 0; i < n; i++)
00344 {
00345 ACE_OS::memcpy (ptr, iov[i].iov_base, iov[i].iov_len);
00346 ptr += iov[i].iov_len;
00347 }
00348
00349 ssize_t result = ACE_SOCK_Dgram::send (buf, length, addr, flags);
00350 #if !defined (ACE_HAS_ALLOCA)
00351 delete [] buf;
00352 #endif /* !defined (ACE_HAS_ALLOCA) */
00353 return result;
00354 }
|
|
||||||||||||||||||||
|
Send an <n> byte <buf> to the datagram socket (uses <sendto(3)>).
Reimplemented in ACE_SOCK_Dgram_Bcast. Definition at line 23 of file SOCK_Dgram.i. References ACE_TRACE, ACE_Addr::get_addr, ACE_Addr::get_size, and ACE_OS::sendto. Referenced by ACE_SOCK_Dgram_Mcast::send, ACE_SOCK_Dgram_Bcast::send, and send.
00027 {
00028 ACE_TRACE ("ACE_SOCK_Dgram::send");
00029 sockaddr *saddr = (sockaddr *) addr.get_addr ();
00030 int len = addr.get_size ();
00031 return ACE_OS::sendto (this->get_handle (),
00032 (const char *) buf,
00033 n,
00034 flags,
00035 (struct sockaddr *) saddr,
00036 len);
00037 }
|
|
|
Definition at line 498 of file SOCK_Dgram.cpp. References ACE_OS::atoi, ACE_INET_Addr::get_ip_address, ACE_INET_Addr::get_port_number, ip_mreq::imr_interface, ACE_OS::ioctl, IP_MULTICAST_IF, ACE_INET_Addr::set, ACE_SOCK::set_option, SIOCGIFADDR, and ACE_OS_String::strcpy.
00499 {
00500 /* The first step would be to get the interface address for the
00501 nic_name specified */
00502 ip_mreq multicast_address;
00503 ACE_INET_Addr mcast_addr;
00504 #if defined (ACE_WIN32)
00505 // This port number is not necessary, just convenient
00506 ACE_INET_Addr interface_addr;
00507 if (interface_addr.set (mcast_addr.get_port_number (),
00508 option_value) == -1)
00509 return;
00510 multicast_address.imr_interface.s_addr =
00511 htonl (interface_addr.get_ip_address ());
00512 #else
00513 ifreq if_address;
00514
00515 #if defined (ACE_PSOS)
00516 // Look up the interface by number, not name.
00517 if_address.ifr_ifno = ACE_OS::atoi (option_value);
00518 #else
00519 ACE_OS::strcpy (if_address.ifr_name, option_value);
00520 #endif /* defined (ACE_PSOS) */
00521
00522 if (ACE_OS::ioctl (this->get_handle (),
00523 SIOCGIFADDR,
00524 &if_address) == -1)
00525 return;
00526
00527 /* Cast this into the required format */
00528 sockaddr_in *socket_address;
00529 socket_address = ACE_reinterpret_cast(sockaddr_in *,
00530 &if_address.ifr_addr);
00531 multicast_address.imr_interface.s_addr = socket_address->sin_addr.s_addr;
00532 #endif /* ACE_WIN32 */
00533
00534 /*
00535 * Now. I got the interface address for the 'nic' specified.
00536 * Use that to set the nic option.
00537 */
00538
00539 this->ACE_SOCK::set_option (IPPROTO_IP,
00540 IP_MULTICAST_IF,
00541 &multicast_address.imr_interface.s_addr,
00542 sizeof (struct in_addr));
00543 }
|
|
||||||||||||
|
Open is shared by this and by <LSOCK_Dgram>.
Definition at line 107 of file SOCK_Dgram.cpp. References ACE_TRACE, ACE_OS::bind, ACE_Sock_Connect::bind_port, ACE_SOCK::close, ACE_Addr::get_addr, ACE_Addr::get_size, and ACE_Addr::sap_any. Referenced by open, and ACE_SOCK_Dgram_Mcast::open_i.
00109 {
00110 ACE_TRACE ("ACE_SOCK_Dgram::shared_open");
00111 int error = 0;
00112
00113 if (local == ACE_Addr::sap_any)
00114 {
00115 if (protocol_family == PF_INET
00116 #if defined (ACE_HAS_IPV6)
00117 || protocol_family == PF_INET6
00118 #endif /* ACE_HAS_IPV6 */
00119 )
00120 {
00121 if (ACE::bind_port (this->get_handle ()) == -1)
00122 error = 1;
00123 }
00124 }
00125 else if (ACE_OS::bind (this->get_handle (),
00126 ACE_reinterpret_cast (sockaddr *,
00127 local.get_addr ()),
00128 local.get_size ()) == -1)
00129 error = 1;
00130
00131 if (error != 0)
00132 this->close ();
00133
00134 return error ? -1 : 0;
00135 }
|
|
|
Declare the dynamic allocation hooks.
Reimplemented from ACE_SOCK. Reimplemented in ACE_LSOCK_Dgram. Definition at line 200 of file SOCK_Dgram.h. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002