| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library mdns.src.packet; | 5 library mdns.src.packet; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:typed_data'; | 9 import 'dart:typed_data'; |
| 10 | 10 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 if (length < headerSize) return null; | 75 if (length < headerSize) return null; |
| 76 | 76 |
| 77 Uint8List data = | 77 Uint8List data = |
| 78 packet is Uint8List ? packet : new Uint8List.fromList(packet); | 78 packet is Uint8List ? packet : new Uint8List.fromList(packet); |
| 79 ByteData bd = new ByteData.view(data.buffer); | 79 ByteData bd = new ByteData.view(data.buffer); |
| 80 // Query identifier. | 80 // Query identifier. |
| 81 int id = bd.getUint16(idOffset); | 81 int id = bd.getUint16(idOffset); |
| 82 // Flags. | 82 // Flags. |
| 83 int flags = bd.getUint16(flagsOffset); | 83 int flags = bd.getUint16(flagsOffset); |
| 84 | 84 |
| 85 if (flags != responseFlags) return; | 85 if (flags != responseFlags) return null; |
| 86 // Query count. | 86 // Query count. |
| 87 int qdcount = bd.getUint16(qdcountOffset); | 87 int qdcount = bd.getUint16(qdcountOffset); |
| 88 // Number of answers. | 88 // Number of answers. |
| 89 int ancount = bd.getUint16(ancountOffset); | 89 int ancount = bd.getUint16(ancountOffset); |
| 90 // Number of name server records. | 90 // Number of name server records. |
| 91 int nscount = bd.getUint16(nscountOffset); | 91 int nscount = bd.getUint16(nscountOffset); |
| 92 // Number of resource records. | 92 // Number of resource records. |
| 93 int arcount = bd.getUint16(arcountOffset); | 93 int arcount = bd.getUint16(arcountOffset); |
| 94 int offset = headerSize; | 94 int offset = headerSize; |
| 95 | 95 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 return result; | 178 return result; |
| 179 } | 179 } |
| 180 | 180 |
| 181 /// Exceptions thrown by decoder when the packet is invalid. | 181 /// Exceptions thrown by decoder when the packet is invalid. |
| 182 class MDnsDecodeException implements Exception { | 182 class MDnsDecodeException implements Exception { |
| 183 /// Exception message. | 183 /// Exception message. |
| 184 final int offset; | 184 final int offset; |
| 185 const MDnsDecodeException(this.offset); | 185 const MDnsDecodeException(this.offset); |
| 186 String toString() => 'Decoding error at $offset'; | 186 String toString() => 'Decoding error at $offset'; |
| 187 } | 187 } |
| OLD | NEW |