/*
* Copyright 2004-2006 Luke Quinane and Daniel Frampton
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.Net;
using NDns.Message;
namespace NDns.Message.Records{
/// <summary>
/// A DNS Address record.
/// </summary>
public class ARecord : Record
{
/// <summary>
/// The address for this record.
/// </summary>
protected IPAddress address;
/// <summary>
/// Creates an address record using the address record.
/// </summary>
/// <param name="address">The address to create the record from.</param>
public ARecord(IPAddress address)
{
this.address = address;
}
/// <summary>
/// Creates an Address record from the given byte data.
/// </summary>
/// <param name="data">The data to create the Address record from.</param>
/// <param name="start">The position to start reading the byte array from.</param>
/// <param name="length">The number of bytes read from the byte array.</param>
/// <param name="coder">The coder to use when parsing the data.</param>
public ARecord(byte[] data, ushort start, out ushort length, DomainCoder coder)
{
// get the address
ushort position = start;
byte[] addr = new byte[4];
addr[0] = data[position++];
addr[1] = data[position++];
addr[2] = data[position++];
addr[3] = data[position++];
long addressNumber = ((long) addr[3] << 24) + ((long) addr[2] << 16) +
((long) addr[1] << 8) + addr[0];
this.address = new IPAddress(addressNumber);
this.type = QType.A;
length = (ushort) (position - start);
}
/// <summary>
/// The address for this record.
/// </summary>
public IPAddress Address
{
get
{
return this.address;
}
}
/// <summary>
/// The data associated with this record as a user readable string.
/// </summary>
public override string Data {
get {
return this.address.ToString();
}
}
}
}
|