{
}
-Icmpv4Type IcmpDestinationUnreachableMessage::get_type() const
+Icmpv4Type IcmpDestinationUnreachableMessage::get_type_v4() const
{
Icmpv4Type type = static_cast<Icmpv4Type>( Payload[ 0 ] );
return type;
}
-void IcmpDestinationUnreachableMessage::set_type( Icmpv4Type type )
+void IcmpDestinationUnreachableMessage::set_type_v4( const Icmpv4Type type )
+{
+ uint8_t n = static_cast<uint8_t>( type );
+
+ Payload[ 0 ] = n;
+}
+
+Icmpv6Type IcmpDestinationUnreachableMessage::get_type_v6() const
+{
+ Icmpv6Type type = static_cast<Icmpv6Type>( Payload[ 0 ] );
+
+ return type;
+}
+
+void IcmpDestinationUnreachableMessage::set_type_v6( const Icmpv6Type type )
{
uint8_t n = static_cast<uint8_t>( type );
IcmpDestinationUnreachableMessage();
virtual ~IcmpDestinationUnreachableMessage();
- Icmpv4Type get_type() const;
- void set_type( const Icmpv4Type type );
+ Icmpv4Type get_type_v4() const;
+ void set_type_v4( const Icmpv4Type type );
+
+ Icmpv6Type get_type_v6() const;
+ void set_type_v6( const Icmpv6Type type );
uint8_t get_code() const;
void set_code( const uint8_t code );
{
}
-Icmpv4Type IcmpEchoReplyMessage::get_type() const
+Icmpv4Type IcmpEchoReplyMessage::get_type_v4() const
{
Icmpv4Type type = static_cast<Icmpv4Type>( Payload[ 0 ] );
return type;
}
-void IcmpEchoReplyMessage::set_type( Icmpv4Type type )
+void IcmpEchoReplyMessage::set_type_v4( const Icmpv4Type type )
+{
+ uint8_t n = static_cast<uint8_t>( type );
+
+ Payload[ 0 ] = n;
+}
+
+Icmpv6Type IcmpEchoReplyMessage::get_type_v6() const
+{
+ Icmpv6Type type = static_cast<Icmpv6Type>( Payload[ 0 ] );
+
+ return type;
+}
+
+void IcmpEchoReplyMessage::set_type_v6( const Icmpv6Type type )
{
uint8_t n = static_cast<uint8_t>( type );
IcmpEchoReplyMessage();
virtual ~IcmpEchoReplyMessage();
- Icmpv4Type get_type() const;
- void set_type( const Icmpv4Type type );
+ Icmpv4Type get_type_v4() const;
+ void set_type_v4( const Icmpv4Type type );
+
+ Icmpv6Type get_type_v6() const;
+ void set_type_v6( const Icmpv6Type type );
uint8_t get_code() const;
void set_code( const uint8_t code );
{
}
-Icmpv4Type IcmpEchoRequestMessage::get_type() const
+Icmpv4Type IcmpEchoRequestMessage::get_type_v4() const
{
Icmpv4Type type = static_cast<Icmpv4Type>( Payload[ 0 ] );
return type;
}
-void IcmpEchoRequestMessage::set_type( Icmpv4Type type )
+void IcmpEchoRequestMessage::set_type_v4( const Icmpv4Type type )
+{
+ uint8_t n = static_cast<uint8_t>( type );
+
+ Payload[ 0 ] = n;
+}
+
+Icmpv6Type IcmpEchoRequestMessage::get_type_v6() const
+{
+ Icmpv6Type type = static_cast<Icmpv6Type>( Payload[ 0 ] );
+
+ return type;
+}
+
+void IcmpEchoRequestMessage::set_type_v6( const Icmpv6Type type )
{
uint8_t n = static_cast<uint8_t>( type );
IcmpEchoRequestMessage();
virtual ~IcmpEchoRequestMessage();
- Icmpv4Type get_type() const;
- void set_type( const Icmpv4Type type );
+ Icmpv4Type get_type_v4() const;
+ void set_type_v4( const Icmpv4Type type );
+
+ Icmpv6Type get_type_v6() const;
+ void set_type_v6( const Icmpv6Type type );
uint8_t get_code() const;
void set_code( const uint8_t code );
{
}
-Icmpv4Type IcmpGenericMessage::get_type() const
+Icmpv4Type IcmpGenericMessage::get_type_v4() const
{
return Icmpv4Type_Generic;
}
-void IcmpGenericMessage::set_type( Icmpv4Type )
+void IcmpGenericMessage::set_type_v4( const Icmpv4Type )
+{
+}
+
+Icmpv6Type IcmpGenericMessage::get_type_v6() const
+{
+ return Icmpv6Type_Generic;
+}
+
+void IcmpGenericMessage::set_type_v6( const Icmpv6Type )
{
}
IcmpGenericMessage();
virtual ~IcmpGenericMessage();
- Icmpv4Type get_type() const;
- void set_type( const Icmpv4Type type );
+ Icmpv4Type get_type_v4() const;
+ void set_type_v4( const Icmpv4Type type );
+
+ Icmpv6Type get_type_v6() const;
+ void set_type_v6( const Icmpv6Type type );
uint8_t get_code() const;
void set_code( const uint8_t code );
// virtual function. If you call virtual functions from within a
// constructor, the Base class version of methods will be called, not the
// Derived class, because the Base is constructed before the Derived class.
- set_type( type );
+ set_type_v4( type );
+ set_code( 0 );
+ set_checksum( 0 );
+ set_identifier( 0 );
+ set_sequence_number( 0 );
+}
+
+/**
+ * This method MUST be called to initialize the data member of ICMP Messages.
+ */
+void IcmpMessage::init( const Icmpv6Type type )
+{
+ // Note: this code can not be placed in the constructor, because it calls
+ // virtual function. If you call virtual functions from within a
+ // constructor, the Base class version of methods will be called, not the
+ // Derived class, because the Base is constructed before the Derived class.
+ set_type_v6( type );
set_code( 0 );
set_checksum( 0 );
set_identifier( 0 );
// IcmpMessage
//-----------------------------------------------------------------------------
+/**
+ * @brief Abstract class to which the ICMP messages are interpreted.
+ */
class IcmpMessage
{
public:
virtual ~IcmpMessage();
void init( const Icmpv4Type type );
+ void init( const Icmpv6Type type );
- virtual Icmpv4Type get_type() const = 0;
- virtual void set_type( const Icmpv4Type type ) = 0;
+ virtual Icmpv4Type get_type_v4() const = 0;
+ virtual void set_type_v4( const Icmpv4Type type ) = 0;
+
+ virtual Icmpv6Type get_type_v6() const = 0;
+ virtual void set_type_v6( const Icmpv6Type type ) = 0;
virtual uint8_t get_code() const = 0;
virtual void set_code( const uint8_t code ) = 0;
Icmpv4Type Icmpv4Header::get_type() const
{
- return get_icmp_message_format()->get_type();
+ return get_icmp_message_format()->get_type_v4();
}
void Icmpv4Header::set_type( Icmpv4Type type )
{
- get_icmp_message_format()->set_type( type );
+ get_icmp_message_format()->set_type_v4( type );
}
uint8_t Icmpv4Header::get_code() const
}
BOOST_ASSERT( MessageFormat.get() != NULL );
- BOOST_ASSERT( MessageFormat->get_type() != Icmpv4Type_InvalidLast );
+ BOOST_ASSERT( MessageFormat->get_type_v4() != Icmpv4Type_InvalidLast );
}
void Icmpv4Header::set_icmp_message_format( std::istream &is )