Ejemplo n.º 1
0
        //public static DHCPv4Packet FromRequest(DHCPv4Packet request,
        //    DHCPv4MessagesTypes responseType,
        //    IEnumerable<DHCPv4PacketOption> options)
        //{
        //    DHCPv4Packet result = new DHCPv4Packet();

        //    result._options = new List<DHCPv4PacketOption>(options);
        //    result._options.Insert(0, new DHCPv4PacketMessageTypeOption(responseType));
        //    result.MessageType = responseType;

        //    result.ClientHardwareAddress = ByteHelper.CopyData(request.ClientHardwareAddress);
        //    result.HardwareAddressLength = request.HardwareAddressLength;
        //    result.HardwareType = request.HardwareType;
        //    result.TransactionId = request.TransactionId;
        //    result.OpCode = DHCPv4PacketOperationCodes.BootReply;
        //    result.Flags = request.Flags;

        //    IPv4Address destionationAddress = null;

        //    if (request.IPv4Header.Source == IPv4Address.Empty)
        //    {
        //        if ((request.Flags & DHCPv4PacketFlags.Broadcast) == DHCPv4PacketFlags.Broadcast)
        //        {
        //            destionationAddress = IPv4Address.Broadcast;
        //        }
        //        else
        //        {
        //            destionationAddress = response.YourIPAdress;
        //        }
        //    }
        //    else
        //    {
        //        destionationAddress = IPv4Address.FromByteArray(request.IPv4Header.Source.GetBytes());
        //    }

        //    if (request.GatewayIPAdress != IPv4Address.Empty)
        //    {
        //        result.GatewayIPAdress = IPv4Address.FromByteArray(request.GatewayIPAdress.GetBytes());
        //    }

        //    IPv4Address sourceAddress = null;

        //    sourceAddress = IPv4Address.FromByteArray(request.IPv4Header.Destionation.GetBytes());


        //    //response.Options.Add(new DHCPv4ServerOption(DHCPv4OptionTypes.ServerIdentifier, response.SourceAddress));

        //    DHCPv4PacketOption clientIdentifer = request._options.FirstOrDefault(x => x.OptionType == (Byte)DHCPv4OptionTypes.ClientIdentifier);
        //    if (clientIdentifer != null)
        //    {
        //        result._options.Add(clientIdentifer);
        //    }

        //    result.IPv4Header = new IPv4HeaderInformation(sourceAddress, destionationAddress);

        //    return result;
        //}

        #endregion

        #region Methods

        private void SetClientIdentifier()
        {
            DHCPv4PacketClientIdentifierOption clientIdentifierOption = _options.OfType <DHCPv4PacketClientIdentifierOption>().FirstOrDefault();

            if (clientIdentifierOption != null)
            {
                if (clientIdentifierOption.Identifier.HasHardwareAddress() == false)
                {
                    _clientIdenfier = clientIdentifierOption.Identifier.AddHardwareAddress(ClientHardwareAddress);
                }
                else
                {
                    _clientIdenfier = clientIdentifierOption.Identifier;
                }
            }
            else
            {
                _clientIdenfier = DHCPv4ClientIdentifier.FromHwAddress((Byte)HardwareType, ClientHardwareAddress);
            }
        }
Ejemplo n.º 2
0
 internal DHCPv4PacketClientIdentifierOption GetCopy() => DHCPv4PacketClientIdentifierOption.FromByteArray(GetByteStream(), 0);
Ejemplo n.º 3
0
 static DHCPv4PacketOptionFactory()
 {
     _constructorDict = new Dictionary <Byte, Func <byte[], DHCPv4PacketOption> >
     {
         { (Byte)DHCPv4OptionTypes.SubnetMask, (data) => DHCPv4PacketAddressOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.TimeOffset, (data) => DHCPv4PacketTimeSpanOption.FromByteArray(data, 0, true) },
         { (Byte)DHCPv4OptionTypes.Router, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.TimeServer, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.NameServer, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.DNSServers, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.LogServers, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.CookieServer, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.LRPServers, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.ImpressSever, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.ResourceLocationServer, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.Hostname, (data) => DHCPv4PacketTextOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.BootFileSize, (data) => DHCPv4PacketUInt16Option.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.MaritDumpFile, (data) => DHCPv4PacketTextOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.DomainName, (data) => DHCPv4PacketTextOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.SwapServer, (data) => DHCPv4PacketAddressOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.RootPath, (data) => DHCPv4PacketTextOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.ExtentionsPath, (data) => DHCPv4PacketTextOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.IpForwardingEnabled, (data) => DHCPv4PacketBooleanOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.NonLocalSourceRouting, (data) => DHCPv4PacketBooleanOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.PolicyFilter, (data) => DHCPv4PacketRouteListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.MaximumDatagramReassembly, (data) => DHCPv4PacketUInt16Option.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.DefaultTTL, (data) => DHCPv4PacketByteOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.PathMTUAgingTimeout, (data) => DHCPv4PacketUInt32Option.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.PathMTUPlateauTable, (data) => DHCPv4PacketUInt16Option.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.InterfaceMTU, (data) => DHCPv4PacketUInt16Option.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.AllSubnetsAreLocal, (data) => DHCPv4PacketBooleanOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.BroadcastAddress, (data) => DHCPv4PacketAddressOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.PerformMaskDiscovery, (data) => DHCPv4PacketBooleanOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.MaskSupplier, (data) => DHCPv4PacketBooleanOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.PerformRouterDiscovery, (data) => DHCPv4PacketBooleanOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.RouterSolicitationAddress, (data) => DHCPv4PacketAddressOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.StaticRoute, (data) => DHCPv4PacketRouteListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.TrailerEncapsulation, (data) => DHCPv4PacketBooleanOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.ARPCacheTimeout, (data) => DHCPv4PacketTimeSpanOption.FromByteArray(data, 0, false) },
         { (Byte)DHCPv4OptionTypes.EthernetEncapsulation, (data) => DHCPv4PacketBooleanOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.TCPDefaultTTL, (data) => DHCPv4PacketByteOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.TCPKeepaliveGarbage, (data) => DHCPv4PacketBooleanOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.NetworkInformationServiceDomain, (data) => DHCPv4PacketTextOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.NetworkInformationServers, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.NetworkTimeProtocolServers, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.VendorSpecificInformation, (data) => DHCPv4PacketRawByteOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.NetBIOSoverTCP_IPNameServer, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.NetBIOSoverTCP_IPDatagramDistributionServer, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.NetBIOSoverTCP_IPNodeType, (data) => DHCPv4PacketByteOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.NetBIOSoverTCP_IPScope, (data) => DHCPv4PacketRawByteOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.XWindowSystemFontServer, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.XWindowSystemDisplayManager, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.NetworkInformationServicePlusDomain, (data) => DHCPv4PacketTextOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.NetworkInformationServicePlusServers, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.MobileIPHomeAgent, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.SMTPServers, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.POP3Servers, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.NetworkNewsTransportProtocolServer, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.WWWServers, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.DefaultFingerServer, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.IRCServer, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.StreetTalkServer, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.StreetTalkDirectoryAssistance, (data) => DHCPv4PacketAddressListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.RequestedIPAddress, (data) => DHCPv4PacketAddressOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.IPAddressLeaseTime, (data) => DHCPv4PacketTimeSpanOption.FromByteArray(data, 0, false) },
         { (Byte)DHCPv4OptionTypes.OptionOverload, (data) => DHCPv4PacketByteOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.TFTPServername, (data) => DHCPv4PacketTextOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.BootfileName, (data) => DHCPv4PacketTextOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.MessageType, (data) => DHCPv4PacketMessageTypeOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.ServerIdentifier, (data) => DHCPv4PacketAddressOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.ParamterRequestList, (data) => DHCPv4PacketParameterRequestListOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.Message, (data) => DHCPv4PacketTextOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.MaximumDHCPMessageSize, (data) => DHCPv4PacketUInt16Option.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.RenewalTimeValue, (data) => DHCPv4PacketTimeSpanOption.FromByteArray(data, 0, false) },
         { (Byte)DHCPv4OptionTypes.RebindingTimeValue, (data) => DHCPv4PacketTimeSpanOption.FromByteArray(data, 0, false) },
         { (Byte)DHCPv4OptionTypes.VendorClassIdentifier, (data) => DHCPv4PacketRawByteOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.ClientIdentifier, (data) => DHCPv4PacketClientIdentifierOption.FromByteArray(data, 0) },
         { (Byte)DHCPv4OptionTypes.Option82, (data) => DHCPv4PacketRawByteOption.FromByteArray(data, 0) },
     };
 }