libDwm-0.6.0
DwmPingDestination.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/libDwm/tags/libDwm-0.6.0/include/DwmPingDestination.hh 8401 $
3 // @(#) $Id: DwmPingDestination.hh 8401 2016-04-17 06:44:31Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2008
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // 1. Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // 3. The names of the authors and copyright holders may not be used to
18 // endorse or promote products derived from this software without
19 // specific prior written permission.
20 //
21 // IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
22 // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
23 // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
24 // EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
25 // DAMAGE.
26 //
27 // THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
28 // DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
29 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
30 // REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
31 // IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
33 // OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
34 // TRADEMARK OR OTHER RIGHTS.
35 //===========================================================================
36 
37 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 #ifndef _DWMPINGDESTINATION_HH_
43 #define _DWMPINGDESTINATION_HH_
44 
45 #include <string>
46 
47 #include "DwmIpv4Address.hh"
48 #include "DwmSocket.hh"
49 
50 namespace Dwm {
51 
52  //--------------------------------------------------------------------------
55  //--------------------------------------------------------------------------
57  {
58  public:
59  //------------------------------------------------------------------------
61  //------------------------------------------------------------------------
63 
64  //------------------------------------------------------------------------
70  //------------------------------------------------------------------------
71  PingDestination(const std::string & destination);
72 
73  //------------------------------------------------------------------------
76  //------------------------------------------------------------------------
77  PingDestination(const Ipv4Address & addr, uint16_t port = 0);
78 
79  //------------------------------------------------------------------------
81  //------------------------------------------------------------------------
82  const Ipv4Address & Address() const;
83 
84  //------------------------------------------------------------------------
86  //------------------------------------------------------------------------
87  const Ipv4Address & Address(const Ipv4Address & address);
88 
89  //------------------------------------------------------------------------
91  //------------------------------------------------------------------------
92  uint16_t Port() const;
93 
94  //------------------------------------------------------------------------
96  //------------------------------------------------------------------------
97  const std::string & Hostname() const;
98 
99  //------------------------------------------------------------------------
101  //------------------------------------------------------------------------
102  const std::string & Hostname(const std::string & hostname);
103 
104  //------------------------------------------------------------------------
107  //------------------------------------------------------------------------
108  bool SendTo(Socket & socket, const Ipv4Address & myAddress,
109  uint16_t identifier) const;
110 
111  //------------------------------------------------------------------------
113  //------------------------------------------------------------------------
114  bool operator < (const PingDestination & pd) const;
115 
116  //------------------------------------------------------------------------
118  //------------------------------------------------------------------------
119  bool operator == (const PingDestination & pd) const;
120 
121  //------------------------------------------------------------------------
125  //------------------------------------------------------------------------
126  virtual operator std::string () const;
127 
128  //------------------------------------------------------------------------
130  //------------------------------------------------------------------------
131  friend std::ostream &
132  operator << (std::ostream & os, const PingDestination & pd);
133 
134  protected:
135  Ipv4Address _addr;
136  uint16_t _port;
137  std::string _hostname;
138  mutable bool _primed;
139  mutable uint16_t _sequenceNumber;
140 
141  void GetPacket(std::string & packet, const Ipv4Address & myAddress,
142  uint16_t identifier) const;
143  void GetIcmpPacket(std::string & packet, const Ipv4Address & myAddress,
144  uint16_t identifier) const;
145  void GetTcpPacket(std::string & packet, const Ipv4Address & myAddress,
146  uint16_t identifier) const;
147  };
148 
149 } // namespace Dwm
150 
151 #endif // _DWMPINGDESTINATION_HH_
This class abstracts a UNIX socket descriptor.
Definition: DwmSocket.hh:62
This class encapsulates an IPv4 address.
Definition: DwmIpv4Address.hh:62
friend std::ostream & operator<<(std::ostream &os, const PingDestination &pd)
Prints a PingDestination to an ostream in human-readable form.
Dwm::Socket class definition.
Common interface for an IPv4 destination we wish to ping with ICMP or TCP.
Definition: DwmPingDestination.hh:56
const Ipv4Address & Address() const
Returns the destination IP address.
uint16_t Port() const
Returns the port number (0 for ICMP).
Definition: DwmBZ2IO.hh:67
const std::string & Hostname() const
Returns the hostname (an empty string if it was not set).
Dwm::Ipv4Address class definition.
bool SendTo(Socket &socket, const Ipv4Address &myAddress, uint16_t identifier) const
Sends a &#39;ping&#39; to the destination.
bool operator==(const PingDestination &pd) const
operator ==
PingDestination()
Constructor.
bool operator<(const PingDestination &pd) const
operator <