Exemplo n.º 1
0
        private static void V4Request()
        {
            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.Any);
            V4Message.SetChAddr(PhysicalAddress.Parse("9C-EB-E8-28-92-D4").GetAddressBytes());

            DhcpV4MsgTypeOption msgTypeOption = new DhcpV4MsgTypeOption();

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

            V4Message.PutDhcpOption(new DhcpV4RequestedIpAddressOption(
                                        new v4RequestedIpAddressOption()
            {
                code      = DhcpConstants.V4OPTION_REQUESTED_IP,
                ipAddress = "192.168.61.140"
            }));
            V4Message.SetDhcpV4ServerIdOption(
                new DhcpV4ServerIdOption(
                    new v4ServerIdOption()
            {
                code      = DhcpConstants.V4OPTION_SERVERID,
                ipAddress = "192.168.61.48"
            }));
            var message = DhcpV4MessageHandler.HandleMessage(
                IPAddress.Parse("192.168.61.48"), V4Message);

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