private static IPv4Packet BuildDhcpRebindMessage(DhcpOffer offer, NetworkInterface inter, ushort packetId, uint dhcpTransactionId) { var hardwareAddress = new HardwareAddress(HardwareAddressType.Ethernet, inter.GetPhysicalAddress().GetAddressBytes()); var dhcpPacket = new DhcpPacket(); dhcpPacket.Operation = DhcpOperation.Request; dhcpPacket.MessageType = DhcpMessageType.Request; dhcpPacket.TransactionId = dhcpTransactionId; dhcpPacket.HardwareAddress = hardwareAddress; dhcpPacket.ClientAddress = offer.ClientAddress; dhcpPacket.Options.Add(new DhcpClientIdentifier(hardwareAddress)); var dhcpUdpPacket = new UdpPacket(); dhcpUdpPacket.SourcePort = 68; dhcpUdpPacket.DestinationPort = 67; dhcpUdpPacket.Payload = dhcpPacket; var dhcpIpPacket = new IPv4Packet(); dhcpIpPacket.Source = offer.ClientAddress; dhcpIpPacket.Destination = offer.DhcpServer; dhcpIpPacket.Identifiation = packetId; dhcpIpPacket.Payload = dhcpUdpPacket; return(dhcpIpPacket); }
private static IPv4Packet BuildDhcpDiscoverMessage(NetworkInterface inter, ushort packetId, uint dhcpTransactionId) { var hardwareAddress = new HardwareAddress(HardwareAddressType.Ethernet, inter.GetPhysicalAddress().GetAddressBytes()); var dhcpPacket = new DhcpPacket(); dhcpPacket.Operation = DhcpOperation.Request; dhcpPacket.MessageType = DhcpMessageType.Discover; dhcpPacket.TransactionId = dhcpTransactionId; dhcpPacket.HardwareAddress = hardwareAddress; var dhcpUdpPacket = new UdpPacket(); dhcpUdpPacket.SourcePort = 68; dhcpUdpPacket.DestinationPort = 67; dhcpUdpPacket.Payload = dhcpPacket; var dhcpIpPacket = new IPv4Packet(); dhcpIpPacket.Source = IPAddress.Any; dhcpIpPacket.Destination = IPAddress.Broadcast; dhcpIpPacket.Identifiation = packetId; dhcpIpPacket.Payload = dhcpUdpPacket; return(dhcpIpPacket); }