public byte[] ToByteArray()
{
//Variable to hold the total Packet size
byte[] buffer = new byte[ICMP_PACKET_SIZE];
int index = 0;
byte[] b_type = new byte[1];
b_type[0] = (this.Type);
byte[] b_code = new byte[1];
b_code[0] = (this.SubCode);
byte[] b_cksum = BitConverter.GetBytes(this.CheckSum);
byte[] b_id = BitConverter.GetBytes(this.Identifier);
byte[] b_seq = BitConverter.GetBytes(this.SequenceNumber);
Array.Copy(b_type, 0, buffer, index, b_type.Length);
index += b_type.Length;
Array.Copy(b_code, 0, buffer, index, b_code.Length);
index += b_code.Length;
Array.Copy(b_cksum, 0, buffer, index, b_cksum.Length);
index += b_cksum.Length;
Array.Copy(b_id, 0, buffer, index, b_id.Length);
index += b_id.Length;
Array.Copy(b_seq, 0, buffer, index, b_seq.Length);
index += b_seq.Length;
// copy the data
Array.Copy(this.Data, 0, buffer, index, PING_DATA_SIZE);
index += PING_DATA_SIZE;
if (index != ICMP_PACKET_SIZE) //sizeof(IcmpPacket)
return null;
else
return buffer;
}