private void AssembleRequest(ref DHCPRequest DhcpRequest) { DhcpRequest.opcode = (byte)DHCPMessageType.DHCPDISCOVER; DhcpRequest.htype = 1; DhcpRequest.hlen = 6; DhcpRequest.hops = 0; DhcpRequest.secs = 0x0a00; DhcpRequest.xid = 0xe4b0b618; DhcpRequest.chaddr = m_byMAC; DhcpRequest.fill = 0; DhcpRequest.ciaddr = new byte[4]; DhcpRequest.yiaddr = new byte[4]; DhcpRequest.siaddr = new byte[4]; DhcpRequest.giaddr = new byte[4]; DhcpRequest.sname = new byte[64]; DhcpRequest.file = new byte[128]; DhcpRequest.vend = new byte[130]; int idx = 0; AddMagicCookie(ref DhcpRequest.vend, ref idx); AddDHCPMessageType(ref DhcpRequest.vend, ref idx, DHCPMessageType.DHCPREQUEST); AddMaxDHCPMessageSize(ref DhcpRequest.vend, ref idx); AddDHCPServerID(ref DhcpRequest.vend, ref idx, m_dwServerID); AddRequestedIP(ref DhcpRequest.vend, ref idx, m_dwRequestedIP); AddOptionLeaseTime(ref DhcpRequest.vend, ref idx, m_dwLeaseTime); AddParameterRequestList(ref DhcpRequest.vend, ref idx); AddVendorSpecificInfo(ref DhcpRequest.vend, ref idx); AddVendorClassID(ref DhcpRequest.vend, ref idx); AddVendorClientID(ref DhcpRequest.vend, ref idx); }
private void SendRequest() { try { m_IStatusUpdate.UpdateStatus("Assembling DHCP Request Packet"); DHCPRequest DhcpRequest = new DHCPRequest(); AssembleRequest(ref DhcpRequest); string destHwAddress = "FFFFFFFFFFFF"; var dest = System.Net.NetworkInformation.PhysicalAddress.Parse(destHwAddress); EthernetPacket packet = new EthernetPacket(m_Device.Interface.MacAddress, dest, EthernetPacketType.IpV4); packet.Type = EthernetPacketType.IpV4; var ipSourceAddress = System.Net.IPAddress.Parse("0.0.0.0"); var ipDestinationAddress = System.Net.IPAddress.Parse("255.255.255.255"); var ipPacket = new IPv4Packet(ipSourceAddress, ipDestinationAddress); UdpPacket udpPacket = new UdpPacket(67, 68); byte[] payload = StructureToByteArray(DhcpRequest); ipPacket.Version = IpVersion.IPv4; udpPacket.PayloadData = payload; ipPacket.PayloadPacket = udpPacket; packet.PayloadPacket = ipPacket; udpPacket.UpdateUDPChecksum(); ipPacket.UpdateIPChecksum(); m_IStatusUpdate.UpdateStatus("Sending DHCP Discover"); m_Device.SendPacket(packet); m_IStatusUpdate.UpdateStatus("Sent DHCP Discover"); } catch (Exception) { m_IStatusUpdate.UpdateStatus("Failed to send DHCP Request"); } }