/// <summary> /// Create a new ARP packet. /// </summary> /// <param name="data"> /// The data representing the ARP packet. /// </param> public ArpPacket(byte[] data) { int position = 0; m_hardware = (MediaType)IPAddress.NetworkToHostOrder (BitConverter.ToInt16 (data, position)); position += 2; m_protocol = (NetworkLayerProtocol)BitConverter.ToInt16 (data, position); position += 2; int macLength = data[position]; position ++; int ipLength = data[position]; position++; m_type = (ArpOpcode)IPAddress.NetworkToHostOrder (BitConverter.ToInt16 (data, position)); position += 2; // copy out source MAC byte[] sourceMac = new byte[macLength]; Array.Copy (data, position, sourceMac, 0, macLength); m_sourceMac = new MACAddress (sourceMac); position += macLength; // copy out source IP byte[] sourceIP = new byte[ipLength]; Array.Copy (data, position, sourceIP, 0, ipLength); string sIP = string.Empty; for (int i = 0; i < ipLength; i++) { sIP = string.Concat(sIP, sourceIP[i], "."); } m_sourceIP = IPAddress.Parse(sIP.Substring (0, sIP.Length - 1)); position += ipLength; // copy out destination MAC byte[] destMac = new byte[macLength]; Array.Copy (data, position, destMac, 0, macLength); m_destMac = new MACAddress (destMac); position += macLength; // copy out destination IP byte[] destIP = new byte[ipLength]; Array.Copy (data, position, destIP, 0, ipLength); sIP = string.Empty; for (int i = 0; i < ipLength; i++) { sIP = string.Concat(sIP, destIP[i], "."); } m_destIP = IPAddress.Parse(sIP.Substring (0, sIP.Length - 1)); position += ipLength; }
/// <summary> /// Create a new ARP packet. /// </summary> /// <param name="data"> /// The data representing the ARP packet. /// </param> public ArpPacket(byte[] data) { int position = 0; m_hardware = (MediaType)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, position)); position += 2; m_protocol = (NetworkLayerProtocol)BitConverter.ToInt16(data, position); position += 2; int macLength = data[position]; position++; int ipLength = data[position]; position++; m_type = (ArpOpcode)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, position)); position += 2; // copy out source MAC byte[] sourceMac = new byte[macLength]; Array.Copy(data, position, sourceMac, 0, macLength); m_sourceMac = new MACAddress(sourceMac); position += macLength; // copy out source IP byte[] sourceIP = new byte[ipLength]; Array.Copy(data, position, sourceIP, 0, ipLength); string sIP = string.Empty; for (int i = 0; i < ipLength; i++) { sIP = string.Concat(sIP, sourceIP[i], "."); } m_sourceIP = IPAddress.Parse(sIP.Substring(0, sIP.Length - 1)); position += ipLength; // copy out destination MAC byte[] destMac = new byte[macLength]; Array.Copy(data, position, destMac, 0, macLength); m_destMac = new MACAddress(destMac); position += macLength; // copy out destination IP byte[] destIP = new byte[ipLength]; Array.Copy(data, position, destIP, 0, ipLength); sIP = string.Empty; for (int i = 0; i < ipLength; i++) { sIP = string.Concat(sIP, destIP[i], "."); } m_destIP = IPAddress.Parse(sIP.Substring(0, sIP.Length - 1)); position += ipLength; }