using System;
using Cosmos.HAL.Network;
using Cosmos.System.Network.ARP;
using Sys = System;
namespace Cosmos.System.Network.IPv4
{
///
/// ARPPacket_Ethernet abstract class. See also:
///
internal abstract class ARPPacket_Ethernet : ARPPacket
{
///
/// Sender MAC address.
///
protected MACAddress mSenderMAC;
///
/// Target MAC address.
///
protected MACAddress mTargetMAC;
///
/// Sender IP address.
///
protected Address mSenderIP;
///
/// Target IP address.
///
protected Address mTargetIP;
///
/// Create new inctanse of the class.
///
internal ARPPacket_Ethernet()
: base()
{ }
///
/// Create new inctanse of the class.
///
/// Raw data.
internal ARPPacket_Ethernet(byte[] rawData)
: base(rawData)
{ }
///
/// Init ARPPacket_Ethernet fields.
///
/// Thrown if RawData is invalid or null.
protected override void initFields()
{
base.initFields();
mSenderMAC = new MACAddress(RawData, 22);
mSenderIP = new Address(RawData, 28);
if (SenderIP == null)
{
NetworkStack.debugger.Send("But its already null again");
}
mTargetMAC = new MACAddress(RawData, 32);
mTargetIP = new Address(RawData, 38);
}
///
/// Create new inctanse of the class.
///
/// Operation.
/// Source MAC address.
/// Source IP address.
/// Destination MAC address.
/// Destination IP address.
/// Packet size.
/// ARP destination MAC address.
/// Thrown if RawData is invalid or null.
protected ARPPacket_Ethernet(UInt16 operation, MACAddress senderMAC, Address senderIP,
MACAddress targetMAC, Address targetIP, int packet_size, MACAddress arpTargetMAC)
: base(targetMAC, senderMAC, 1, 0x0800, 6, 4, operation, packet_size)
{
for (int i = 0; i < 6; i++)
{
RawData[22 + i] = senderMAC.bytes[i];
RawData[32 + i] = arpTargetMAC.bytes[i];
}
for (int i = 0; i < 4; i++)
{
RawData[28 + i] = senderIP.address[i];
RawData[38 + i] = targetIP.address[i];
}
initFields();
}
///
/// Get sender MAC.
///
internal MACAddress SenderMAC
{
get { return this.mSenderMAC; }
}
///
/// Get target MAC.
///
internal MACAddress TargetMAC
{
get { return this.mTargetMAC; }
}
///
/// Get sender IP.
///
internal Address SenderIP
{
get { return this.mSenderIP; }
}
///
/// Get target IP.
///
internal Address TargetIP
{
get { return this.mTargetIP; }
}
///
/// To string.
///
/// string value.
public override string ToString()
{
return "IPv4 Ethernet ARP Packet SenderMAC=" + mSenderMAC + ", TargetMAC=" + mTargetMAC + ", SenderIP=" + mSenderIP +
", TargetIP=" + mTargetIP + ", Operation=" + aOperation;
}
}
///
/// ARPRequest_Ethernet class. See also: .
///
internal class ARPReply_Ethernet : ARPPacket_Ethernet
{
///
/// Work around to make VMT scanner include the initFields method
///
public new static void VMTInclude()
{
new ARPReply_Ethernet();
}
///
/// Create new inctanse of the class.
///
internal ARPReply_Ethernet()
: base()
{ }
///
/// Create new inctanse of the class.
///
/// Raw data.
internal ARPReply_Ethernet(byte[] rawData)
: base(rawData)
{ }
///
/// Create new inctanse of the class.
///
/// Source MAC address.
/// Source IP address.
/// Destination MAC address.
/// Destination IP address.
/// Thrown if RawData is invalid or null.
internal ARPReply_Ethernet(MACAddress ourMAC, Address ourIP, MACAddress targetMAC, Address targetIP)
: base(2, ourMAC, ourIP, targetMAC, targetIP, 42, MACAddress.None)
{ }
///
/// To string.
///
/// string value.
public override string ToString()
{
return "ARP Reply Src=" + srcMAC + ", Dest=" + destMAC + ", Sender=" + mSenderIP + ", Target=" + mTargetIP;
}
}
///
/// ARPRequest_Ethernet class. See also: .
///
internal class ARPRequest_Ethernet : ARPPacket_Ethernet
{
///
/// Work around to make VMT scanner include the initFields method
///
public new static void VMTInclude()
{
new ARPRequest_Ethernet();
}
///
/// Create new inctanse of the class.
///
internal ARPRequest_Ethernet()
: base()
{ }
///
/// Create new inctanse of the class.
///
/// Raw data.
internal ARPRequest_Ethernet(byte[] rawData)
: base(rawData)
{
if (SenderIP == null)
{
NetworkStack.debugger.Send("In ARPRequest_Ethernet, SenderIP is null!");
}
}
///
/// Create new inctanse of the class.
///
/// Source MAC address.
/// Source IP address.
/// Destination MAC address.
/// Destination IP address.
/// ARP destination MAC address.
/// Thrown if RawData is invalid or null.
internal ARPRequest_Ethernet(MACAddress ourMAC, Address ourIP, MACAddress targetMAC, Address targetIP, MACAddress arpTargetMAC)
: base(1, ourMAC, ourIP, targetMAC, targetIP, 42, arpTargetMAC)
{ }
///
/// To string.
///
/// string value.
public override string ToString()
{
return "ARP Request Src=" + srcMAC + ", Dest=" + destMAC + ", Sender=" + mSenderIP + ", Target=" + mTargetIP;
}
}
}