示例#1
0
 public bool Equals([AllowNull] DHCPv6LeaseOverview x, [AllowNull] DHCPv6LeaseOverview y)
 {
     if (x.Address == y.Address &&
         x.ClientIdentifier == y.ClientIdentifier &&
         x.ExpectedEnd == y.ExpectedEnd &&
         x.Id == y.Id &&
         x.Scope.Name == y.Scope.Name &&
         x.Scope.Id == y.Scope.Id &&
         x.Started == y.Started &&
         x.State == y.State &&
         ByteHelper.AreEqual(x.UniqueIdentifier, y.UniqueIdentifier) == true
         )
     {
         if (x.Prefix != null && y.Prefix != null)
         {
             return(x.Prefix.Address == y.Prefix.Address && x.Prefix.Mask == y.Prefix.Mask);
         }
         else if (x.Prefix == null && y.Prefix == null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
示例#2
0
        public Boolean IsIPv6AdressANetworkAddress(IPv6Address address)
        {
            Byte[]  andResult   = ByteHelper.AndArray(_mask, address.GetBytes());
            Boolean equalResult = ByteHelper.AreEqual(andResult, address.GetBytes());

            return(equalResult);
        }
示例#3
0
        public Boolean PacketMeetsCondition(DHCPv6Packet packet)
        {
            if (packet is DHCPv6RelayPacket == false)
            {
                return(false);
            }

            var chain = ((DHCPv6RelayPacket)packet).GetRelayPacketChain();

            if (chain.Count <= Index)
            {
                return(false);
            }

            var(RemoteOption, InterfaceOption) = GetOptions(packet);

            if (InterfaceOption == null || RemoteOption == null)
            {
                return(false);
            }

            var remoteIdentifierValueAsByte = ByteHelper.ConcatBytes(new Byte[4], GetDeviceMacAddress());

            Boolean interfaceResult        = ByteHelper.AreEqual(_interfaceIdValueAsByte, InterfaceOption.Data);
            Boolean remodeIdentifierResult = ByteHelper.AreEqual(remoteIdentifierValueAsByte, RemoteOption.Data, 4);

            return(interfaceResult && remodeIdentifierResult);
        }
示例#4
0
        public Boolean PacketMeetsCondition(DHCPv4Packet packet)
        {
            Byte[] target = ByteHelper.AndArray(Mask.GetBytes(), NetworkAddress.GetBytes());
            Byte[] actual = ByteHelper.AndArray(Mask.GetBytes(), packet.GatewayIPAdress.GetBytes());

            Boolean result = ByteHelper.AreEqual(target, actual);

            return(result);
        }
示例#5
0
        public Boolean MatchesUniqueIdentiifer(byte[] value)
        {
            if (UniqueIdentifier == null || UniqueIdentifier.Length == 0)
            {
                return(false);
            }

            return(ByteHelper.AreEqual(value, UniqueIdentifier));
        }
示例#6
0
 public bool Equals([AllowNull] DHCPv4LeaseOverview x, [AllowNull] DHCPv4LeaseOverview y) =>
 x.Address == y.Address &&
 ByteHelper.AreEqual(x.MacAddress, y.MacAddress) == true &&
 x.ExpectedEnd == y.ExpectedEnd &&
 x.Id == y.Id &&
 x.Scope.Name == y.Scope.Name &&
 x.Scope.Id == y.Scope.Id &&
 x.Started == y.Started &&
 x.State == y.State &&
 ByteHelper.AreEqual(x.UniqueIdentifier, y.UniqueIdentifier) == true;
示例#7
0
        public Boolean OpenListener(TListeners listener)
        {
            if (_activeSockets.ContainsKey(listener) == true)
            {
                _logger.LogInformation("a socket to {address} is already listening", listener);
                return(false);
            }

            NetworkInterface nic = NetworkInterface.GetAllNetworkInterfaces()
                                   .FirstOrDefault(x => x.Id == listener.PhysicalInterfaceId);

            if (nic == null)
            {
                _logger.LogError("no network interface card with {address} found", listener);
                return(false);
            }

            var properties = nic.GetIPProperties();

            if (properties == null)
            {
                _logger.LogError("the nic {nic} is not configured for ip", nic);
                return(false);
            }

            var unicastAddress = properties.UnicastAddresses.FirstOrDefault(x =>
                                                                            ByteHelper.AreEqual(x.Address.GetAddressBytes(), listener.Address.GetBytes()));

            if (unicastAddress == null)
            {
                _logger.LogError("the nic {nic} is has no {address} configured", nic, listener);
                return(false);
            }

            _logger.LogDebug("initilaizing server for {addresss}", listener);

            TServer server = _serverFactory(listener);
            Boolean result = server.Start();

            if (result == true)
            {
                _activeSockets.Add(listener, server);
                _addressSocketMapper.Add(listener.Address, server);
                server.SocketErrorOccured += Server_SocketErrorOccured;

                _logger.LogDebug("server is now listing on {address}", listener.Address.ToString());
            }
            else
            {
                _logger.LogError("unable to start the dhcpv6 server. No packets will be received");
            }

            return(result);
        }
示例#8
0
        public bool Equals(DHCPv6PacketSuboption other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                (this.Code == other.Code &&
                 ByteHelper.AreEqual(this.Data, other.Data) == true);
        }
示例#9
0
        public bool Equals(DHCPv4PacketOption other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                (this.OptionType == other.OptionType &&
                 ByteHelper.AreEqual(this.OptionData, other.OptionData) == true);
        }
示例#10
0
        public void AreEqual_True()
        {
            Random random = new Random();

            Byte[] input = new Byte[1024];
            Byte[] copy  = new Byte[1024];
            random.NextBytes(input);

            for (int i = 0; i < input.Length; i++)
            {
                copy[i] = input[i];
            }

            Boolean result = ByteHelper.AreEqual(input, copy);

            Assert.True(result);
        }
示例#11
0
        public Boolean PacketMeetsCondition(DHCPv6Packet packet)
        {
            if (packet is DHCPv6RelayPacket == false)
            {
                return(false);
            }

            var chain = ((DHCPv6RelayPacket)packet).GetRelayPacketChain();

            if (chain.Count <= Index)
            {
                return(false);
            }

            var relayedPacket = chain[Index];

            var option = relayedPacket.GetOption <DHCPv6PacketRemoteIdentifierOption>(DHCPv6PacketOptionTypes.RemoteIdentifier);

            if (option == null)
            {
                return(false);
            }

            Boolean casesenstiveMatch = ByteHelper.AreEqual(_valueAsByte, option.Value);

            if (casesenstiveMatch == true)
            {
                return(true);
            }

            if (IsCaseSenstiveMatch == true)
            {
                return(false);
            }

            String content = _encoding.GetString(option.Value);

            return(String.Compare(Value, content, true) == 0);
        }
示例#12
0
        protected void CheckPacketOptions(Guid scopeId, DHCPv4RootScope rootScope, DHCPv4Packet result)
        {
            var scope = rootScope.GetScopeById(scopeId);

            if (scope.Properties != null)
            {
                foreach (var item in scope.Properties.Properties)
                {
                }
            }

            var subnetOption = result.GetOptionByIdentifier((Byte)DHCPv4OptionTypes.SubnetMask) as DHCPv4PacketAddressOption;

            if (result.YourIPAdress == IPv4Address.Empty)
            {
                Assert.Null(subnetOption);
            }
            else
            {
                Assert.NotNull(subnetOption);
                Assert.True(ByteHelper.AreEqual(subnetOption.Address.GetBytes(), scope.AddressRelatedProperties.Mask.GetBytes()));
            }
        }
示例#13
0
        public Boolean PacketMeetsCondition(DHCPv4Packet packet)
        {
            Byte[] rawData = GetUniqueIdentifier(packet);

            return(ByteHelper.AreEqual(rawData, ValueGetter() ?? Value));
        }
示例#14
0
        private static bool IsEndOfSequenceItemBigEndian(DICOMBinaryReader dr)
        {
            var bytes = dr.ReadBytes(8);

            return(ByteHelper.AreEqual(bytes, _endOfSequenceItem_BE));
        }
示例#15
0
 private static bool IsEndOfSequenceItemLittleEndian(DICOMBinaryReader dr)
 {
     byte[] bytes = dr.ReadBytes(8);
     return(ByteHelper.AreEqual(bytes, _endOfSequenceItem_LE));
 }
示例#16
0
 public Boolean IsAddressInSubnet(IPv6Address networkAddress, IPv6Address address)
 {
     Byte[] and = ByteHelper.AndArray(address.GetBytes(), _mask);
     return(ByteHelper.AreEqual(networkAddress.GetBytes(), and));
 }
示例#17
0
        public static DHCPv4Packet FromByteArray(Byte[] rawData, IPv4Address source, IPv4Address destionation)
        {
            try
            {
                DHCPv4Packet packet = new DHCPv4Packet
                {
                    OpCode                = (DHCPv4PacketOperationCodes)rawData[0],
                    HardwareType          = (DHCPv4PacketHardwareAddressTypes)rawData[1],
                    HardwareAddressLength = rawData[2],
                    Hops            = rawData[3],
                    TransactionId   = ByteHelper.ConvertToUInt32FromByte(rawData, 4),
                    SecondsElapsed  = ByteHelper.ConvertToUInt16FromByte(rawData, 8),
                    Flags           = (DHCPv4PacketFlags)ByteHelper.ConvertToUInt16FromByte(rawData, 10),
                    ClientIPAdress  = IPv4Address.FromByteArray(rawData, 12),
                    YourIPAdress    = IPv4Address.FromByteArray(rawData, 16),
                    ServerIPAdress  = IPv4Address.FromByteArray(rawData, 20),
                    GatewayIPAdress = IPv4Address.FromByteArray(rawData, 24)
                };

                packet.Header = new IPv4HeaderInformation(source, destionation);

                packet.ClientHardwareAddress = ByteHelper.CopyData(rawData, 28, packet.HardwareAddressLength);
                Boolean serverhostnameFound = false;
                for (int i = 40; i < 40 + 64; i++)
                {
                    if (rawData[i] != 0)
                    {
                        serverhostnameFound = true;
                        break;
                    }
                }
                if (serverhostnameFound == true)
                {
                    packet.ServerHostname = new String(_textEncoding.GetChars(rawData, 40, 64));
                }
                else
                {
                    packet.ServerHostname = String.Empty;
                }

                Boolean fileNameFound = false;
                for (int i = 104; i < 104 + 128; i++)
                {
                    if (rawData[i] != 0)
                    {
                        fileNameFound = true;
                        break;
                    }
                }
                if (fileNameFound == true)
                {
                    packet.FileName = new String(_textEncoding.GetChars(rawData, 104, 128));
                }
                else
                {
                    packet.FileName = String.Empty;
                }

                Byte[] actualCookie = new Byte[] { rawData[236], rawData[237], rawData[238], rawData[239] };
                if (ByteHelper.AreEqual(_magicCookie, actualCookie) == false)
                {
                    throw new ArgumentException();
                }

                Int32 index = 240;
                while (index < rawData.Length)
                {
                    Byte optionCode = rawData[index];
                    if (optionCode == 255)
                    {
                        break;
                    }
                    Byte length = rawData[index + 1];

                    Byte[]             optionData = ByteHelper.CopyData(rawData, index, length + 2);
                    DHCPv4PacketOption option     = DHCPv4PacketOptionFactory.GetOption(optionCode, optionData);

                    packet.AddOption(option);


                    index += 2 + length;
                }

                packet._isValid = true;

                packet.SetClientIdentifier();

                packet._byteRepresentation = rawData;

                return(packet);
            }
            catch (Exception)
            {
                return(DHCPv4Packet.Invalid);
            }
        }