/**
* <summary>Constructor when creating a Dns Query</summary>
* <param name="QName">the name of resource you are looking up, IP Address
* when QType = Ptr otherwise hostname</param>
* <param name="QType"> the type of look up to perform</param>
* <param name="QClass">should always be IN</param>
*/
public Question(String QName, DnsPacket.Types QType, DnsPacket.Classes QClass)
{
this.QName = QName;
this.QType = QType;
this.QClass = QClass;
if (QType == DnsPacket.Types.A || QType == DnsPacket.Types.AAAA)
{
QNameBlob = DnsPacket.HostnameStringToMemBlock(QName);
}
else if (QType == DnsPacket.Types.Ptr)
{
QNameBlob = DnsPacket.PtrStringToMemBlock(QName);
}
else
{
throw new Exception("Invalid QType: " + QType + "!");
}
// 2 for QType + 2 for QClass
byte[] data = new byte[4];
int idx = 0;
data[idx++] = (byte)((((int)QType) >> 8) & 0xFF);
data[idx++] = (byte)(((int)QType) & 0xFF);
data[idx++] = (byte)((((int)QClass) >> 8) & 0xFF);
data[idx++] = (byte)(((int)QClass) & 0xFF);
_icpacket = new CopyList(QNameBlob, MemBlock.Reference(data));
}