Exemplo n.º 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);
            }
Exemplo n.º 2
0
            private DhcpV4Message BuildRequestMessage(DhcpV4Message offer)
            {
                DhcpV4Message msg = new DhcpV4Message(IPAddress.Parse("0.0.0.0"), new IPEndPoint(serverAddr, serverPort));

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

                DhcpV4MsgTypeOption msgTypeOption = new DhcpV4MsgTypeOption();

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

                msg.PutDhcpOption(msgTypeOption);

                DhcpV4RequestedIpAddressOption reqIpOption = new DhcpV4RequestedIpAddressOption();

                reqIpOption.SetIpAddress(offer.GetYiAddr().ToString());
                msg.PutDhcpOption(reqIpOption);

                return(msg);
            }