@@ -53,12 +53,13 @@ internal class DnsQuestion
5353 /// </summary>
5454 public ushort QuestionOffset { get ; }
5555
56- /// <summary>
57- /// Creates a new instance of the <see cref="DnsQuestion"/> class by parsing the given byte array starting at the specified offset.
58- /// </summary>
59- /// <param name="data"></param>
60- /// <param name="offset"></param>
61- public DnsQuestion ( byte [ ] data , int offset )
56+ /// <summary>
57+ /// Creates a new instance of the <see cref="DnsQuestion"/> class by parsing the given byte array starting at the specified offset.
58+ /// </summary>
59+ /// <param name="data">The byte array containing the DNS question data.</param>
60+ /// <param name="offset">The offset in the byte array where the DNS question starts.</param>
61+ /// <exception cref="ArgumentException">Thrown when the data is invalid or cannot be parsed.</exception>
62+ public DnsQuestion ( byte [ ] data , int offset )
6263 {
6364 int terminatorIndex = - 1 ;
6465
@@ -110,17 +111,17 @@ public bool TryParseQuestion(Hashtable dnsEntries, ref DnsAnswer dnsAnswer)
110111
111112 if ( string . IsNullOrEmpty ( name ) )
112113 {
113- Logger . GlobalLogger . LogWarning ( "Failed to parse DNS question name." ) ;
114+ Logger . GlobalLogger ? . LogWarning ( "Failed to parse DNS question name." ) ;
114115
115116 return false ;
116117 }
117118
118- Logger . GlobalLogger . LogDebug ( "Parsed DNS question: Name={0}, Type={1}, Class={2} (name offset={3}, length={4})" , name , Type , Class , QuestionOffset , nameLength ) ;
119+ Logger . GlobalLogger ? . LogDebug ( "Parsed DNS question: Name={0}, Type={1}, Class={2} (name offset={3}, length={4})" , name , Type , Class , QuestionOffset , nameLength ) ;
119120
120121 // For captive portal, we'll handle A record types
121122 if ( Type != QuestionTypeA )
122123 {
123- Logger . GlobalLogger . LogWarning ( "Unsupported DNS question type: {0}. Only A (IPv4 address) records are supported." , Type ) ;
124+ Logger . GlobalLogger ? . LogWarning ( "Unsupported DNS question type: {0}. Only A (IPv4 address) records are supported." , Type ) ;
124125
125126 return false ;
126127 }
@@ -141,11 +142,11 @@ public bool TryParseQuestion(Hashtable dnsEntries, ref DnsAnswer dnsAnswer)
141142 TTL = 300
142143 } ;
143144
144- Logger . GlobalLogger . LogDebug ( "Generated DNS answer for name: {0}, Type: {1}, Address: {2}, pointer offset: 0x{3:X4}" , name , Type , ipAddress , QuestionOffset ) ;
145+ Logger . GlobalLogger ? . LogDebug ( "Generated DNS answer for name: {0}, Type: {1}, Address: {2}, pointer offset: 0x{3:X4}" , name , Type , ipAddress , QuestionOffset ) ;
145146 }
146147 else
147148 {
148- Logger . GlobalLogger . LogWarning ( "No DNS entry found for name: {0}" , name ) ;
149+ Logger . GlobalLogger ? . LogWarning ( "No DNS entry found for name: {0}" , name ) ;
149150
150151 return false ;
151152 }
@@ -184,7 +185,7 @@ private string ParseName(ref ushort nameLength)
184185 if ( ( labelLength & _DnsCompressionPointerFlag ) == _DnsCompressionPointerFlag )
185186 {
186187 // This is a pointer (first two bits are set)
187- Logger . GlobalLogger . LogWarning ( "DNS name compression (pointers) not supported in this simplified implementation" ) ;
188+ Logger . GlobalLogger ? . LogWarning ( "DNS name compression (pointers) not supported in this simplified implementation" ) ;
188189
189190 nameLength = 0 ;
190191
@@ -194,7 +195,7 @@ private string ParseName(ref ushort nameLength)
194195 // Make sure we have enough bytes for this label
195196 if ( position + labelLength > Name . Length )
196197 {
197- Logger . GlobalLogger . LogWarning ( "DNS label exceeds packet boundary" ) ;
198+ Logger . GlobalLogger ? . LogWarning ( "DNS label exceeds packet boundary" ) ;
198199
199200 nameLength = 0 ;
200201
@@ -218,7 +219,7 @@ private string ParseName(ref ushort nameLength)
218219 }
219220 catch ( Exception ex )
220221 {
221- Logger . GlobalLogger . LogError ( ex , "Exception parsing DNS name" ) ;
222+ Logger . GlobalLogger ? . LogError ( ex , "Exception parsing DNS name" ) ;
222223
223224 nameLength = 0 ;
224225
@@ -231,6 +232,7 @@ private string ParseName(ref ushort nameLength)
231232 /// Tries to find a matching DNS entry for the given name.
232233 /// </summary>
233234 /// <param name="name">The domain name to look up.</param>
235+ /// <param name="dnsEntries">The hashtable with the DNS entries.</param>
234236 /// <param name="ipAddress">The IP address if found.</param>
235237 /// <returns><see langword="true"/> if a match was found; otherwise, <see langword="false"/>.</returns>
236238 private bool TryFindDnsEntry (
@@ -261,7 +263,7 @@ private bool TryFindDnsEntry(
261263 {
262264 ipAddress = ( IPAddress ) dnsEntries [ key ] ;
263265
264- Logger . GlobalLogger . LogDebug ( "Wildcard match: '{0}' matches pattern '{1}'" , name , key ) ;
266+ Logger . GlobalLogger ? . LogDebug ( "Wildcard match: '{0}' matches pattern '{1}'" , name , key ) ;
265267
266268 return true ;
267269 }
@@ -271,9 +273,9 @@ private bool TryFindDnsEntry(
271273 return false ;
272274 }
273275
276+ /// <summary>
274277 /// Returns the byte array representation of this DNS question, suitable for network transmission.
275278 /// </summary>
276- /// <param name="none"></param>
277279 /// <returns>
278280 /// A <see cref="byte"/> array containing the DNS question in wire format.
279281 /// </returns>
0 commit comments