/// <summary> /// Create a new ethernet 802.3 packet. /// </summary> /// <param name="packet"> /// The ethernet packet to parse. /// </param> public Ethernet802_3(byte[] packet) { // copy out the fields Array.Copy(packet, 0, m_destinationMACAddress.Address, 0, 6); Array.Copy(packet, 6, m_sourceMACAddress.Address, 0, 6); m_networkProtocol = (NetworkLayerProtocol)BitConverter.ToInt16(packet, 12); if (packet.Length > 14) { m_data = new byte[packet.Length - 14]; Array.Copy(packet, 14, m_data, 0, m_data.Length); } }
public XsSocket(IpProtocol protocol, NetworkLayerProtocol ipVersion) : this(xsensdeviceapiPINVOKE.new_XsSocket__SWIG_0((int)protocol, (int)ipVersion), true) { }
/// <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 ethernet 802.3 packet. /// </summary> /// <param name="packet"> /// The ethernet packet to parse. /// </param> public Ethernet802_3(byte[] packet) { // copy out the fields Array.Copy (packet, 0, m_destinationMACAddress.Address, 0, 6); Array.Copy (packet, 6, m_sourceMACAddress.Address, 0, 6); m_networkProtocol = (NetworkLayerProtocol)BitConverter.ToInt16 (packet, 12); if (packet.Length > 14) { m_data = new byte[packet.Length - 14]; Array.Copy (packet, 14, m_data, 0, m_data.Length); } }
/// <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; }