From: Guilherme Maciel Ferreira Date: Sat, 13 Aug 2011 00:52:25 +0000 (-0300) Subject: Moved PingStatus enumeration to its own file, so it can be reused by both Pingers X-Git-Tag: v1.1^2~21 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=f5c0f0d06a18b0b4cc4bc531a12761addcc562a5;p=pingcheck Moved PingStatus enumeration to its own file, so it can be reused by both Pingers --- diff --git a/src/host/pingstatus.h b/src/host/pingstatus.h new file mode 100644 index 0000000..5623f68 --- /dev/null +++ b/src/host/pingstatus.h @@ -0,0 +1,32 @@ +/* +The software in this package is distributed under the GNU General +Public License version 2 (with a special exception described below). + +A copy of GNU General Public License (GPL) is included in this distribution, +in the file COPYING.GPL. + +As a special exception, if other files instantiate templates or use macros +or inline functions from this file, or you compile this file and link it +with other works to produce a work based on this file, this file +does not by itself cause the resulting work to be covered +by the GNU General Public License. + +However the source code for this file must still be made available +in accordance with section (3) of the GNU General Public License. + +This exception does not invalidate any other reasons why a work based +on this file might be covered by the GNU General Public License. +*/ + +#ifndef PING_STATUS_H +#define PING_STATUS_H + +enum PingStatus +{ + PingStatus_NotSent, + PingStatus_SuccessReply, + PingStatus_FailureTimeout, + PingStatus_FailureDestinationUnreachable +}; + +#endif /* PING_STATUS_H */ diff --git a/src/icmp/icmppinger.cpp b/src/icmp/icmppinger.cpp index 774ce54..9297601 100644 --- a/src/icmp/icmppinger.cpp +++ b/src/icmp/icmppinger.cpp @@ -247,7 +247,7 @@ void IcmpPinger::handle_receive_icmp_packet( const size_t &bytes_transferred ) // Decode the reply packet. IcmpPacket icmp_packet; - if (!(is >> icmp_packet)) + if (! (is >> icmp_packet) ) { GlobalLogger.notice() << "Warning: ignoring broken ICMP packet" << endl; @@ -256,11 +256,12 @@ void IcmpPinger::handle_receive_icmp_packet( const size_t &bytes_transferred ) // We can receive all ICMP packets received by the host, so we need to // filter out only the echo replies that match the our identifier, - // expected sequence number, and destination host address (receive just the - // ICMP packets from the host we had ping). - if ( icmp_packet.match( - IcmpType_EchoReply, Identifier, SequenceNumber, - DestinationEndpoint.address() ) ) + // expected sequence number, and destination host address (receive just + // the ICMP packets from the host we had ping). + + if ( icmp_packet.match( IcmpType_EchoReply, + Identifier, SequenceNumber, + DestinationEndpoint.address() ) ) { ReceivedReply = true; @@ -270,9 +271,9 @@ void IcmpPinger::handle_receive_icmp_packet( const size_t &bytes_transferred ) IcmpPacketReceiveTimer.cancel(); } - else if ( icmp_packet.match( - IcmpType_DestinationUnreachable, Identifier, SequenceNumber, - DestinationEndpoint.address() ) ) + else if ( icmp_packet.match( IcmpType_DestinationUnreachable, + Identifier, SequenceNumber, + DestinationEndpoint.address() ) ) { ReceivedReply = true; @@ -282,16 +283,16 @@ void IcmpPinger::handle_receive_icmp_packet( const size_t &bytes_transferred ) IcmpPacketReceiveTimer.cancel(); } + // Unknown ICMP reply, start another receive till timeout else { - // Unknown ICMP reply, start another receive till timeout start_receive(); } } catch ( ... ) { GlobalLogger.notice() << "Warning: exception during ICMP parse. " - << "Starting another recieve till timeout." << endl; + << "Starting another receive till timeout." << endl; start_receive(); } } @@ -352,7 +353,7 @@ void IcmpPinger::print_destination_unreachable( << " Destination Net Unreachable" << endl; } -void IcmpPinger::set_ping_status( IcmpPinger::PingStatus ping_status ) +void IcmpPinger::set_ping_status( PingStatus ping_status ) { PingerStatus = ping_status; } diff --git a/src/icmp/icmppinger.h b/src/icmp/icmppinger.h index 35cdef3..e8083f7 100644 --- a/src/icmp/icmppinger.h +++ b/src/icmp/icmppinger.h @@ -4,8 +4,8 @@ // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#ifndef ICMPPINGER_H -#define ICMPPINGER_H +#ifndef ICMP_PINGER_H +#define ICMP_PINGER_H #include @@ -13,6 +13,7 @@ #include #include "host/pinger.h" +#include "host/pingstatus.h" class IcmpPacket; @@ -40,15 +41,6 @@ public: ); private: - enum PingStatus - { - PingStatus_NotSent, - PingStatus_SuccessReply, - PingStatus_FailureTimeout, - PingStatus_FailureDestinationUnreachable - }; - -private: void set_destination_endpoint( const std::string &destination_ip ); void start_send(); @@ -68,7 +60,7 @@ private: const IcmpPacket &icmp_packet ) const; - void set_ping_status( IcmpPinger::PingStatus ping_status ); + void set_ping_status( PingStatus ping_status ); bool select_source_network_interface( const std::string &source_network_interface @@ -98,9 +90,9 @@ private: /// the amount of time to wait for the reply int EchoReplyTimeoutInSec; /// the status of the pinger - IcmpPinger::PingStatus PingerStatus; + PingStatus PingerStatus; /// Callback to notify when the ping is done (got reply/timeout) boost::function< void(bool) > PingDoneCallback; }; -#endif /* ICMPPINGER_H */ +#endif // ICMP_PINGER_H diff --git a/src/tcp/tcppinger.cpp b/src/tcp/tcppinger.cpp index b5247d5..138465f 100644 --- a/src/tcp/tcppinger.cpp +++ b/src/tcp/tcppinger.cpp @@ -353,7 +353,7 @@ void TcpPinger::print_rst_reply( } -void TcpPinger::set_ping_status( TcpPinger::PingStatus ping_status ) +void TcpPinger::set_ping_status( PingStatus ping_status ) { PingerStatus = ping_status; } diff --git a/src/tcp/tcppinger.h b/src/tcp/tcppinger.h index 7bb1be8..7157fb8 100644 --- a/src/tcp/tcppinger.h +++ b/src/tcp/tcppinger.h @@ -17,8 +17,8 @@ in accordance with section (3) of the GNU General Public License. This exception does not invalidate any other reasons why a work based on this file might be covered by the GNU General Public License. */ -#ifndef TCPPINGER_H -#define TCPPINGER_H +#ifndef TCP_PINGER_H +#define TCP_PINGER_H #include @@ -27,6 +27,7 @@ on this file might be covered by the GNU General Public License. #include #include "host/pinger.h" +#include "host/pingstatus.h" #include "ip/ipv4header.h" #include "tcp/tcpheader.h" @@ -54,15 +55,6 @@ public: ); private: - enum PingStatus - { - PingStatus_NotSent, - PingStatus_SuccessReply, - PingStatus_FailureTimeout, - PingStatus_FailureDestinationUnreachable - }; - -private: uint32_t get_source_address(); uint32_t get_destination_address() const; void set_destination_endpoint( const std::string &destination_ip ); @@ -85,7 +77,7 @@ private: const TcpHeader &tcp_header ) const; - void set_ping_status( TcpPinger::PingStatus ping_status ); + void set_ping_status( PingStatus ping_status ); bool select_source_network_interface( const std::string &source_network_interface_name @@ -117,9 +109,9 @@ private: /// the amount of time to wait for the reply int RstReplyTimeoutInSec; /// the status of the pinger - TcpPinger::PingStatus PingerStatus; + PingStatus PingerStatus; /// Callback to notify when the ping is done (got reply/timeout) boost::function< void(bool) > PingDoneCallback; }; -#endif /* TCPPINGER_H */ +#endif // TCP_PINGER_H