Esempio n. 1
0
        public DHCPv4Packet(
            IPv4HeaderInformation ipv4Header,
            Byte[] hwAddress,
            UInt32 transactionId,
            IPv4Address yourIPAddress,
            IPv4Address gwIPAddress,
            IPv4Address clientIPAddress,
            DHCPv4PacketFlags flags,
            IEnumerable <DHCPv4PacketOption> options
            ) : this()
        {
            TransactionId         = transactionId;
            ClientHardwareAddress = ByteHelper.CopyData(hwAddress);
            HardwareAddressLength = (Byte)ClientHardwareAddress.Length;
            YourIPAdress          = IPv4Address.FromByteArray(yourIPAddress.GetBytes());
            ClientIPAdress        = IPv4Address.FromByteArray(clientIPAddress.GetBytes());
            GatewayIPAdress       = IPv4Address.FromByteArray(gwIPAddress.GetBytes());
            Header = ipv4Header;
            Flags  = flags;

            _options = new List <DHCPv4PacketOption>();

            foreach (var item in options)
            {
                AddOption(item);
            }

            SetClientIdentifier();
            _isValid = true;
        }
Esempio n. 2
0
        private void SetIPHeader(DHCPv4Packet request)
        {
            IPv4Address source = IPv4Address.Empty;
            IPv4Address destionation;

            if (request.Header.Source == IPv4Address.Empty)
            {
                if ((request.Flags & DHCPv4PacketFlags.Broadcast) == DHCPv4PacketFlags.Broadcast)
                {
                    destionation = IPv4Address.Broadcast;
                }
                else
                {
                    destionation = YourIPAdress;
                }
            }
            else
            {
                destionation = IPv4Address.FromAddress(request.Header.Source);
                source       = IPv4Address.FromAddress(request.Header.Destionation);
            }

            //if (MessageType == DHCPv4MessagesTypes.NotAcknowledge && (request.ClientIPAdress != request.Header.Source))
            //{
            //    destionation = IPv4Address.Broadcast;
            //}

            Header = new IPv4HeaderInformation(source, destionation, request.Header.ListenerAddress);
        }
Esempio n. 3
0
 public DHCPv4Packet(
     IPv4HeaderInformation ipv4Header,
     Byte[] hwAddress,
     UInt32 transactionId,
     IPv4Address yourIPAddress,
     IPv4Address gwIPAddress,
     IPv4Address clientIPAddress,
     DHCPv4PacketFlags flags = DHCPv4PacketFlags.Unicast,
     params DHCPv4PacketOption[] options
     ) : this(ipv4Header, hwAddress, transactionId, yourIPAddress, gwIPAddress, clientIPAddress, flags, options.ToList())
 {
 }
Esempio n. 4
0
 public static DHCPv4Packet FromByteArray(byte[] stream, IPv4HeaderInformation header) => FromByteArray(stream, header.Source, header.Destionation);