summaryrefslogtreecommitdiff
path: root/ace/Ping_Socket.h
blob: 41c50226de42ecd32a82daac438a7f54e41658cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// -*- C++ -*-

//=============================================================================
/**
 *  @file    Ping_Socket.h
 *
 *  $Id$
 *
 *  @author Robert S. Iakobashvili <roberti@go-WLAN.com> <coroberti@walla.co.il>
 *  @author Gonzalo A. Diethelm <gonzalo.diethelm@aditiva.com> made aceing
 */
//=============================================================================

#ifndef ACE_PING_SOCKET_H
#define ACE_PING_SOCKET_H

#include /**/ "ace/pre.h"

#include "ace/ACE_export.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#if defined (ACE_HAS_ICMP_SUPPORT) && (ACE_HAS_ICMP_SUPPORT == 1)

#include "ace/ICMP_Socket.h"

class ACE_INET_Addr;

namespace ACE
{
  /**
   * @class ACE_Ping_Socket
   *
   * @brief This class is useful to perform ICMP echo checks (pinging)
   * on the party of your interest.  It may be used as well to check
   * LAN-adapters against 3-rd parties.
   */
  class ACE_Export Ping_Socket : public ICMP_Socket
  {
    typedef ICMP_Socket inherited;

  public:

    // = Initialization and termination methods.

    /// Default constructor.
    Ping_Socket (void);

    Ping_Socket (ACE_Addr const & local,
                 int protocol    = IPPROTO_ICMP,
                 int reuse_addr  = 0);

    /// Destructor.
    ~Ping_Socket (void);

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

    /// @a toConnect = 1 - makes connect to remote address
    int send_echo_check (ACE_INET_Addr & remote_addr,
                         int to_connect = 0);

    /// To receive @c ICMP_ECHOREPLY. To be called after successfully
    /// sending @c ICMP_ECHO.
    int process_incoming_dgram (char * ptr, ssize_t len);

    /// @a toConnect = 1 - makes connect to remote address
    int make_echo_check (ACE_INET_Addr & remote_addr,
                         int to_connect = 0,
                         ACE_Time_Value const * timeout = &time_default_);

    char * icmp_recv_buff (void);

    /// Dump the state of an object.
    void dump (void) const;

    /// Declare the dynamic allocation hooks.
    ACE_ALLOC_HOOK_DECLARE;

  public:

    enum
      {
        PING_BUFFER_SIZE = (1024 * 2),
      };

    static ACE_Time_Value const time_default_;

  private:

    int receive_echo_reply (ACE_Time_Value const * timeout);

    /// Do not allow this function to percolate up to this interface.
    int get_remote_addr (ACE_INET_Addr &addr) const;

    char icmp_send_buff_[PING_BUFFER_SIZE];

    char icmp_recv_buff_[PING_BUFFER_SIZE];

    unsigned long sequence_number_;

    int connected_socket_;

  };

} // End namespace ACE


#if defined (__ACE_INLINE__)
# include "ace/Ping_Socket.inl"
#endif /* __ACE_INLINE__ */

#endif  /* ACE_HAS_ICMP_SUPPORT == 1 */

#include /**/ "ace/post.h"

#endif /* ACE_PING_SOCKET_H */