/// <summary> /// Creates a new instance of this class /// </summary> public DHCPFrame() { dhtMessageType = DHCPType.BootRequest; dhtHardwareType = eExNetworkLibrary.HardwareAddressType.Ethernet; sHardwarelen = 6; sHops = 0; iTransactionID = 0; iSecs = 0; bValidIPFlag = true; ipaClientAddress = IPAddress.Any; ipaOwnAddress = IPAddress.Any; ipaServerAddress = IPAddress.Any; ipaRelayAddress = IPAddress.Any; macClientMac = MACAddress.Empty; strRequestedFile = ""; strRequestedServerName = ""; lTLVs = new List <DHCPTLVItem>(); }
/// <summary> /// Creates a new instance of this class by parsing the given data /// </summary> /// <param name="bData">The data to parse</param> public DHCPFrame(byte[] bData) { byte[] bAddressBytes = new byte[4]; byte[] bMacBytes = new byte[6]; lTLVs = new List <DHCPTLVItem>(); DHCPTLVItem dhcpItem; dhtMessageType = (DHCPType)bData[0]; dhtHardwareType = (HardwareAddressType)bData[1]; sHardwarelen = (short)bData[2]; sHops = (short)bData[3]; iTransactionID = BitConverter.ToInt32(bData, 4); iSecs = BitConverter.ToInt16(bData, 8); bValidIPFlag = (bData[10] & 0x80) == 1; for (int iC1 = 0; iC1 < 4; iC1++) { bAddressBytes[iC1] = bData[12 + iC1]; } ipaClientAddress = new IPAddress(bAddressBytes); for (int iC1 = 0; iC1 < 4; iC1++) { bAddressBytes[iC1] = bData[16 + iC1]; } ipaOwnAddress = new IPAddress(bAddressBytes); for (int iC1 = 0; iC1 < 4; iC1++) { bAddressBytes[iC1] = bData[20 + iC1]; } ipaServerAddress = new IPAddress(bAddressBytes); for (int iC1 = 0; iC1 < 4; iC1++) { bAddressBytes[iC1] = bData[24 + iC1]; } ipaRelayAddress = new IPAddress(bAddressBytes); for (int iC1 = 0; iC1 < 6; iC1++) { bMacBytes[iC1] = bData[28 + iC1]; } macClientMac = new MACAddress(bMacBytes); strRequestedServerName = Encoding.ASCII.GetString(bData, 34, 64).Trim(new char[] { '\0' }); strRequestedFile = Encoding.ASCII.GetString(bData, 98, 128).Trim(new char[] { '\0' }); if (bData[236] != 0x63 || bData[237] != 0x82 || bData[238] != 0x53 || bData[239] != 0x63) { throw new Exception("Invalid DHCP magic number"); } int iC2 = 240; while (iC2 < bData.Length) { if (bData[iC2] == (int)DHCPOptions.End) { break; } dhcpItem = new DHCPTLVItem(bData, iC2); lTLVs.Add(dhcpItem); iC2 += dhcpItem.Length; } }