using System;
using System.Collections.Generic;
using System.Text;
namespace ProjectCarbon.Protocols
{
///
/// All protocols within the IP protocol should derive from this
/// class.
///
abstract class IpSubProtocol
{
///
/// Provides a list of properties for this protocol.
///
protected Dictionary m_protocolProperties =
new Dictionary();
///
/// Stores what protocol this handles.
///
protected Protocol m_protocol;
///
/// This will get you the protocol name.
///
protected string m_name = null;
///
/// You may optionally provide a protocol description
///
protected string m_description = null;
///
/// Creates a new protocol
///
/// The protocol this class will handle.
public IpSubProtocol(Protocol protocol, string name, string description)
{
m_protocol = protocol;
m_name = name;
m_description = description;
}
///
/// Allows you to access the properties of this protocol
///
public Dictionary Properties
{
get { return m_protocolProperties; }
}
///
/// Returns the protocol name
///
public string Name
{
get { return m_name; }
}
///
/// Returns a short description of this protocol
///
public string Description
{
get { return m_description; }
}
///
/// This must be implemented, it's the parsing routine for this protocol.
///
/// Incoming packet data
public abstract void ProcessData(byte[] bufferData);
///
/// Returns the correct processor for the protocol, but
/// it might return null if it has no processor.
///
///
/// A new instance of the protocol
public static IpSubProtocol GetProtocolInstance(Protocol protocol)
{
switch (protocol)
{
case Protocol.Tcp:
return new TcpProtocol();
case Protocol.Udp:
return new UdpProtocol();
case Protocol.Icmp:
return new IcmpProtocol();
default:
return new GenericProtocol();
}
//return null;
}
}
}