ACE_ICMP_Socket Class Reference

An abstract class that forms the basis for usage of the ICMP protocol (that is, support for things such as ping). More...

#include <ICMP_Socket.h>

Inheritance diagram for ACE_ICMP_Socket:

Inheritance graph
[legend]
Collaboration diagram for ACE_ICMP_Socket:

Collaboration graph
[legend]
List of all members.

Public Member Functions

int open (ACE_Addr const &local=ACE_Addr::sap_any, int protocol=IPPROTO_ICMP, int reuse_addr=0)
 Wrapper around the BSD-style socket system call (no QoS).

void dump (void) const
 Dump the state of object.

Data transfer routines.
Data transfer routines.

ssize_t send (void const *buf, size_t n, ACE_Addr const &addr, int flags=0) const
ssize_t recv (void *buf, size_t n, ACE_Addr &addr, int flags=0) const
ssize_t recv (void *buf, size_t n, int flags, ACE_Time_Value const *timeout) const
 TODO: comment.


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.


Protected Member Functions

 ACE_ICMP_Socket (void)
 Default constructor.

 ACE_ICMP_Socket (ACE_Addr const &local, int protocol=IPPROTO_ICMP, int reuse_addr=0)
 Constructor that takes a local listening address.

int shared_open (ACE_Addr const &local)
 Wrapper around BSD-style bind system call.

unsigned short calculate_checksum (unsigned short *paddress, int len)
 Calculates check-sum.


Detailed Description

An abstract class that forms the basis for usage of the ICMP protocol (that is, support for things such as ping).

Definition at line 39 of file ICMP_Socket.h.


Constructor & Destructor Documentation

ACE_ICMP_Socket::ACE_ICMP_Socket void   )  [protected]
 

Default constructor.

Definition at line 29 of file ICMP_Socket.cpp.

References ACE_TRACE.

00030 {
00031   ACE_TRACE ("ACE_ICMP_Socket::ACE_ICMP_Socket");
00032 }

ACE_ICMP_Socket::ACE_ICMP_Socket ACE_Addr const &  local,
int  protocol = IPPROTO_ICMP,
int  reuse_addr = 0
[protected]
 

Constructor that takes a local listening address.


Member Function Documentation

unsigned short ACE_ICMP_Socket::calculate_checksum unsigned short *  paddress,
int  len
[protected]
 

Calculates check-sum.

Definition at line 157 of file ICMP_Socket.cpp.

00159 {
00160   int nleft = len;
00161   int sum = 0;
00162   unsigned short * w = paddress;
00163   unsigned short answer = 0;
00164   while (nleft > 1)
00165     {
00166       sum += *w++;
00167       nleft -= 2;
00168     }
00169 
00170   if (nleft == 1)
00171     {
00172       *((unsigned char *) &answer) = *((unsigned char *) w);
00173       sum += answer;
00174     }
00175 
00176   // add back carry outs from top 16 bits to low 16 bits
00177   sum = (sum >> 16) + (sum & 0xffff); // add hi 16 to low 16
00178   sum += (sum >> 16);                 // add carry
00179   answer = ~sum;                      // truncate to 16 bits
00180 
00181   return (answer);
00182 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL void ACE_ICMP_Socket::dump void   )  const
 

Dump the state of object.

Reimplemented from ACE_SOCK.

Reimplemented in ACE_Ping_Socket.

Definition at line 24 of file ICMP_Socket.cpp.

References ACE_TRACE.

00025 {
00026   ACE_TRACE ("ACE_ICMP_Socket::dump");
00027 }

int ACE_ICMP_Socket::open ACE_Addr const &  local = ACE_Addr::sap_any,
int  protocol = IPPROTO_ICMP,
int  reuse_addr = 0
 

Wrapper around the BSD-style socket system call (no QoS).

Reimplemented in ACE_Ping_Socket.

Definition at line 86 of file ICMP_Socket.cpp.

References ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, ACE_SOCK::open(), and shared_open().

00089 {
00090   ACE_TRACE ("ACE_ICMP_Socket::open");
00091 
00092   // Check if icmp protocol is supported on this host
00093   int proto_number = -1;
00094   protoent *proto;
00095 
00096   if (! (proto = getprotobyname ("icmp")))
00097     {
00098       ACE_ERROR_RETURN
00099         ((LM_ERROR,
00100           ACE_LIB_TEXT ("(%P|%t) ACE_ICMP_Socket::open: %p; %s\n"),
00101           ACE_LIB_TEXT ("getprotobyname"),
00102           ACE_LIB_TEXT ("ICMP protocol is not properly configured ")
00103           ACE_LIB_TEXT ("or not supported.")),
00104          -1);
00105     }
00106   proto_number = proto->p_proto;
00107 
00108   if (proto_number != IPPROTO_ICMP || proto_number != protocol)
00109     {
00110       ACE_ERROR_RETURN ((LM_ERROR,
00111                          ACE_LIB_TEXT ("(%P|%t) ACE::ICMP_Socket::open - ")
00112                          ACE_LIB_TEXT ("only IPPROTO_ICMP protocol is ")
00113                          ACE_LIB_TEXT ("currently supported.\n")),
00114                         -1);
00115     }
00116 
00117   if (ACE_SOCK::open (SOCK_RAW,
00118                       AF_INET,
00119                       protocol,
00120                       reuse_addr) == -1)
00121     {
00122       return -1;
00123     }
00124 
00125   return this->shared_open (local);
00126 }

ssize_t ACE_ICMP_Socket::recv void *  buf,
size_t  n,
int  flags,
ACE_Time_Value const *  timeout
const
 

TODO: comment.

Definition at line 71 of file ICMP_Socket.cpp.

References ACE_TRACE, and ACE::recv().

00075 {
00076   ACE_TRACE ("ACE_ICMP_Socket::recv");
00077 
00078   return ACE::recv (this->get_handle (),
00079                     buf,
00080                     n,
00081                     flags,
00082                     timeout);
00083 }

ssize_t ACE_ICMP_Socket::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) ).

Definition at line 51 of file ICMP_Socket.cpp.

References ACE_TRACE, ACE_Addr::get_addr(), ACE_Addr::get_size(), ACE_OS::recvfrom(), ACE_Addr::set_size(), and ssize_t.

00055 {
00056   ACE_TRACE ("ACE_ICMP_Socket::recv");
00057 
00058   int addr_len = addr.get_size ();
00059   ssize_t status = ACE_OS::recvfrom (this->get_handle (),
00060                                      (char *) buf,
00061                                      n,
00062                                      flags,
00063                                      (sockaddr *) addr.get_addr (),
00064                                      (int*) &addr_len);
00065   addr.set_size (addr_len);
00066 
00067   return status;
00068 }

ssize_t ACE_ICMP_Socket::send void const *  buf,
size_t  n,
ACE_Addr const &  addr,
int  flags = 0
const
 

Send an n byte buf to the datagram socket (uses sendto(3) ).

Definition at line 35 of file ICMP_Socket.cpp.

References ACE_TRACE, ACE_Addr::get_addr(), ACE_Addr::get_size(), and ACE_OS::sendto().

Referenced by ACE_Ping_Socket::send_echo_check().

00039 {
00040   ACE_TRACE ("ACE_ICMP_Socket::send");
00041 
00042   return ACE_OS::sendto (this->get_handle (),
00043                          (char const *) buf,
00044                          n,
00045                          flags,
00046                          (sockaddr const *) addr.get_addr (),
00047                          addr.get_size ());
00048 }

int ACE_ICMP_Socket::shared_open ACE_Addr const &  local  )  [protected]
 

Wrapper around BSD-style bind system call.

Definition at line 129 of file ICMP_Socket.cpp.

References ACE_TRACE, ACE_OS::bind(), ACE::bind_port(), ACE_SOCK::close(), ACE_Addr::get_addr(), and ACE_Addr::get_size().

Referenced by open().

00130 {
00131   ACE_TRACE ("ACE_ICMP_Socket::shared_open");
00132 
00133   int error = 0;
00134   if (local == ACE_Addr::sap_any)
00135     {
00136       if (ACE::bind_port (this->get_handle ()) == -1)
00137         {
00138           error = 1;
00139         }
00140     }
00141   else if (ACE_OS::bind (this->get_handle (),
00142                          reinterpret_cast<sockaddr *> (local.get_addr ()),
00143                          local.get_size ()) == -1)
00144     {
00145       error = 1;
00146     }
00147 
00148   if (error != 0)
00149     {
00150       this->close ();
00151     }
00152 
00153   return error ? -1 : 0;
00154 }


Member Data Documentation

ACE_ICMP_Socket::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Reimplemented from ACE_SOCK.

Reimplemented in ACE_Ping_Socket.

Definition at line 82 of file ICMP_Socket.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:23:25 2006 for ACE by doxygen 1.3.6