コード例 #1
0
            private DhcpV4Message BuildReleaseMessage(DhcpV4Message ack)
            {
                DhcpV4Message msg = new DhcpV4Message(null, new IPEndPoint(serverAddr, serverPort));

                msg.SetOp((short)DhcpConstants.V4_OP_REQUEST);
                msg.SetTransactionId(ack.GetTransactionId());
                msg.SetHtype((short)1); // ethernet
                msg.SetHlen((byte)6);
                msg.SetChAddr(ack.GetChAddr());
                msg.SetGiAddr(clientAddr);  // look like a relay to the DHCP server
                msg.SetCiAddr(ack.GetYiAddr());

                DhcpV4MsgTypeOption msgTypeOption = new DhcpV4MsgTypeOption();

                msgTypeOption.SetUnsignedByte((short)DhcpConstants.V4MESSAGE_TYPE_RELEASE);

                msg.PutDhcpOption(msgTypeOption);

                return(msg);
            }
コード例 #2
0
ファイル: Program.cs プロジェクト: NatChung/PacketTestTools
        private static void V4Release()
        {
            var V4Message = new DhcpV4Message(IPAddress.Any,
                                              new IPEndPoint(IPAddress.Parse("192.168.61.48"), DhcpConstants.V4_SERVER_PORT));

            V4Message.SetOp((short)DhcpConstants.V4_OP_REQUEST); //V4_OP_REQUEST
            V4Message.SetGiAddr(IPAddress.Parse("192.168.101.1"));
            V4Message.SetCiAddr(IPAddress.Parse("192.168.5.126"));
            V4Message.SetChAddr(PhysicalAddress.Parse("9C-EB-E8-28-92-D4").GetAddressBytes());
            V4Message.SetHlen(6);
            V4Message.SetHtype((byte)6);
            V4Message.SetTransactionId(-1729018559);

            DhcpV4MsgTypeOption msgTypeOption = new DhcpV4MsgTypeOption();

            msgTypeOption.SetUnsignedByte((short)DhcpConstants.V4MESSAGE_TYPE_RELEASE);
            V4Message.PutDhcpOption(msgTypeOption);

            var message = DhcpV4MessageHandler.HandleMessage(
                IPAddress.Parse("192.168.61.48"), V4Message);

            Console.WriteLine(V4Message.ToString());
        }