internal Lease(BinaryReader bR) { switch (bR.ReadByte()) { case 1: _type = (LeaseType)bR.ReadByte(); _clientIdentifier = DhcpOption.Parse(bR.BaseStream) as ClientIdentifierOption; _clientIdentifier.ParseOptionValue(); _hostName = bR.ReadShortString(); if (_hostName == "") { _hostName = null; } _hardwareAddress = bR.ReadBuffer(); _address = IPAddressExtension.Parse(bR); _leaseObtained = bR.ReadDate(); _leaseExpires = bR.ReadDate(); break; default: throw new InvalidDataException("Lease data format version not supported."); } }
public StatCounter(BinaryReader bR) { if (Encoding.ASCII.GetString(bR.ReadBytes(2)) != "SC") //format { throw new InvalidDataException("StatCounter format is invalid."); } byte version = bR.ReadByte(); switch (version) { case 1: _totalQueries = bR.ReadInt32(); _totalNoError = bR.ReadInt32(); _totalServerFailure = bR.ReadInt32(); _totalNameError = bR.ReadInt32(); _totalRefused = bR.ReadInt32(); _totalBlocked = bR.ReadInt32(); { int count = bR.ReadInt32(); for (int i = 0; i < count; i++) { _queryDomains.TryAdd(bR.ReadShortString(), new Counter(bR.ReadInt32())); } } { int count = bR.ReadInt32(); for (int i = 0; i < count; i++) { _queryBlockedDomains.TryAdd(bR.ReadShortString(), new Counter(bR.ReadInt32())); } } { int count = bR.ReadInt32(); for (int i = 0; i < count; i++) { _queryTypes.TryAdd((DnsResourceRecordType)bR.ReadUInt16(), new Counter(bR.ReadInt32())); } } { int count = bR.ReadInt32(); for (int i = 0; i < count; i++) { _clientIpAddresses.TryAdd(IPAddressExtension.Parse(bR), new Counter(bR.ReadInt32())); } } break; default: throw new InvalidDataException("StatCounter version not supported."); } _locked = true; }
public DnsProvider(BinaryReader bR) { this.Name = bR.ReadShortString(); this.Addresses = new List <IPAddress>(); int count = bR.ReadInt32(); for (int i = 0; i < count; i++) { this.Addresses.Add(IPAddressExtension.Parse(bR)); } }
internal Lease(BinaryReader bR) { byte version = bR.ReadByte(); switch (version) { case 1: case 2: _type = (LeaseType)bR.ReadByte(); _clientIdentifier = DhcpOption.Parse(bR.BaseStream) as ClientIdentifierOption; _clientIdentifier.ParseOptionValue(); _hostName = bR.ReadShortString(); if (string.IsNullOrWhiteSpace(_hostName)) { _hostName = null; } _hardwareAddress = bR.ReadBuffer(); _address = IPAddressExtension.Parse(bR); if (version >= 2) { _comments = bR.ReadShortString(); if (string.IsNullOrWhiteSpace(_comments)) { _comments = null; } } _leaseObtained = bR.ReadDateTime(); _leaseExpires = bR.ReadDateTime(); break; default: throw new InvalidDataException("Lease data format version not supported."); } }
public Scope(BinaryReader bR) { if (Encoding.ASCII.GetString(bR.ReadBytes(2)) != "SC") { throw new InvalidDataException("DhcpServer scope file format is invalid."); } switch (bR.ReadByte()) { case 1: _name = bR.ReadShortString(); _enabled = bR.ReadBoolean(); ChangeNetwork(IPAddressExtension.Parse(bR), IPAddressExtension.Parse(bR), IPAddressExtension.Parse(bR)); _leaseTimeDays = bR.ReadUInt16(); _leaseTimeHours = bR.ReadByte(); _leaseTimeMinutes = bR.ReadByte(); _offerDelayTime = bR.ReadUInt16(); _domainName = bR.ReadShortString(); if (string.IsNullOrWhiteSpace(_domainName)) { _domainName = null; } _dnsTtl = bR.ReadUInt32(); _routerAddress = IPAddressExtension.Parse(bR); if (_routerAddress.Equals(IPAddress.Any)) { _routerAddress = null; } { int count = bR.ReadByte(); if (count > 0) { if (count == 255) { _useThisDnsServer = true; FindThisDnsServerAddress(); } else { _dnsServers = new IPAddress[count]; for (int i = 0; i < count; i++) { _dnsServers[i] = IPAddressExtension.Parse(bR); } } } } { int count = bR.ReadByte(); if (count > 0) { _winsServers = new IPAddress[count]; for (int i = 0; i < count; i++) { _winsServers[i] = IPAddressExtension.Parse(bR); } } } { int count = bR.ReadByte(); if (count > 0) { _ntpServers = new IPAddress[count]; for (int i = 0; i < count; i++) { _ntpServers[i] = IPAddressExtension.Parse(bR); } } } { int count = bR.ReadByte(); if (count > 0) { _staticRoutes = new ClasslessStaticRouteOption.Route[count]; for (int i = 0; i < count; i++) { _staticRoutes[i] = new ClasslessStaticRouteOption.Route(bR.BaseStream); } } } { int count = bR.ReadByte(); if (count > 0) { _exclusions = new Exclusion[count]; for (int i = 0; i < count; i++) { _exclusions[i] = new Exclusion(IPAddressExtension.Parse(bR), IPAddressExtension.Parse(bR)); } } } { int count = bR.ReadInt32(); if (count > 0) { _reservedLeases = new Lease[count]; for (int i = 0; i < count; i++) { _reservedLeases[i] = new Lease(bR); } } _allowOnlyReservedLeases = bR.ReadBoolean(); } { int count = bR.ReadInt32(); if (count > 0) { for (int i = 0; i < count; i++) { Lease lease = new Lease(bR); _leases.TryAdd(lease.ClientIdentifier, lease); } } } break; default: throw new InvalidDataException("Scope data format version not supported."); } }
public AuthZoneInfo(BinaryReader bR) { byte version = bR.ReadByte(); switch (version) { case 1: case 2: _name = bR.ReadShortString(); _type = (AuthZoneType)bR.ReadByte(); _disabled = bR.ReadBoolean(); if (version >= 2) { { _zoneTransfer = (AuthZoneTransfer)bR.ReadByte(); int count = bR.ReadByte(); if (count > 0) { IPAddress[] nameServers = new IPAddress[count]; for (int i = 0; i < count; i++) { nameServers[i] = IPAddressExtension.Parse(bR); } _zoneTransferNameServers = nameServers; } } { _notify = (AuthZoneNotify)bR.ReadByte(); int count = bR.ReadByte(); if (count > 0) { IPAddress[] nameServers = new IPAddress[count]; for (int i = 0; i < count; i++) { nameServers[i] = IPAddressExtension.Parse(bR); } _notifyNameServers = nameServers; } } } else { switch (_type) { case AuthZoneType.Primary: _zoneTransfer = AuthZoneTransfer.AllowOnlyZoneNameServers; _notify = AuthZoneNotify.ZoneNameServers; break; default: _zoneTransfer = AuthZoneTransfer.Deny; _notify = AuthZoneNotify.None; break; } } switch (_type) { case AuthZoneType.Secondary: _expiry = bR.ReadDate(); break; case AuthZoneType.Stub: _expiry = bR.ReadDate(); break; } break; default: throw new InvalidDataException("AuthZoneInfo format version not supported."); } }
public AuthZoneInfo(BinaryReader bR) { byte version = bR.ReadByte(); switch (version) { case 1: case 2: case 3: case 4: _name = bR.ReadShortString(); _type = (AuthZoneType)bR.ReadByte(); _disabled = bR.ReadBoolean(); if (version >= 2) { { _zoneTransfer = (AuthZoneTransfer)bR.ReadByte(); int count = bR.ReadByte(); if (count > 0) { IPAddress[] nameServers = new IPAddress[count]; for (int i = 0; i < count; i++) { nameServers[i] = IPAddressExtension.Parse(bR); } _zoneTransferNameServers = nameServers; } } { _notify = (AuthZoneNotify)bR.ReadByte(); int count = bR.ReadByte(); if (count > 0) { IPAddress[] nameServers = new IPAddress[count]; for (int i = 0; i < count; i++) { nameServers[i] = IPAddressExtension.Parse(bR); } _notifyNameServers = nameServers; } } } else { switch (_type) { case AuthZoneType.Primary: _zoneTransfer = AuthZoneTransfer.AllowOnlyZoneNameServers; _notify = AuthZoneNotify.ZoneNameServers; break; default: _zoneTransfer = AuthZoneTransfer.Deny; _notify = AuthZoneNotify.None; break; } } switch (_type) { case AuthZoneType.Primary: if (version >= 3) { int count = bR.ReadInt32(); DnsResourceRecord[] zoneHistory = new DnsResourceRecord[count]; for (int i = 0; i < count; i++) { zoneHistory[i] = new DnsResourceRecord(bR.BaseStream); zoneHistory[i].Tag = new DnsResourceRecordInfo(bR, zoneHistory[i].Type == DnsResourceRecordType.SOA); } _zoneHistory = zoneHistory; } if (version >= 4) { int count = bR.ReadByte(); Dictionary <string, object> tsigKeyNames = new Dictionary <string, object>(count); for (int i = 0; i < count; i++) { tsigKeyNames.Add(bR.ReadShortString(), null); } _tsigKeyNames = tsigKeyNames; } break; case AuthZoneType.Secondary: _expiry = bR.ReadDateTime(); if (version >= 4) { int count = bR.ReadInt32(); DnsResourceRecord[] zoneHistory = new DnsResourceRecord[count]; for (int i = 0; i < count; i++) { zoneHistory[i] = new DnsResourceRecord(bR.BaseStream); zoneHistory[i].Tag = new DnsResourceRecordInfo(bR, zoneHistory[i].Type == DnsResourceRecordType.SOA); } _zoneHistory = zoneHistory; } if (version >= 4) { int count = bR.ReadByte(); Dictionary <string, object> tsigKeyNames = new Dictionary <string, object>(count); for (int i = 0; i < count; i++) { tsigKeyNames.Add(bR.ReadShortString(), null); } _tsigKeyNames = tsigKeyNames; } break; case AuthZoneType.Stub: _expiry = bR.ReadDateTime(); break; } break; default: throw new InvalidDataException("AuthZoneInfo format version not supported."); } }