3
Vote

Bug and fix

description

The ParseText method in DnsRecordBase (BaseDnaRecord.cs) gives up too easily so fails to retrieve the content of longer records. The current implementation is:
 
StringBuilder sb = new StringBuilder();

// The problem here is that the length reported may not be all the available data
int len = ms.ReadByte();
byte[] buffer = new byte[len];
ms.Read(buffer, 0, len);
sb.Append(Encoding.ASCII.GetString(buffer));
 
This only retrieves the first iLen bytes. However some servers (yahoo) create continuation records. NSLOOKUP reports these as two separate text line. Unless the stream is positioned at the end, the trick is to read the next byte, treat it as the length byte of the continuation record and read the next iLen bytes. An implementation might be like:
 
StringBuilder sb = new StringBuilder();

// The problem here is that the length reported may not be all the available data
while (ms.Length > ms.Position)
{
    int len = ms.ReadByte();
    byte[] buffer = new byte[len];
    ms.Read(buffer, 0, len);
    sb.Append(Encoding.ASCII.GetString(buffer));
}

comments