(byte[] response)
| 200 | } |
| 201 | |
| 202 | private Vector decode (byte[] response) { |
| 203 | try { |
| 204 | ByteArrayInputStream bais = new ByteArrayInputStream(response); |
| 205 | DataInputStream in = new DataInputStream(bais); |
| 206 | short id = in.readShort(); // id |
| 207 | short flags = in.readShort(); // flags |
| 208 | short questions = in.readShort(); |
| 209 | int answers = in.readShort(); |
| 210 | in.readShort(); |
| 211 | in.readShort(); |
| 212 | for (int i = 0; i < questions; ++i) { |
| 213 | while (true) { |
| 214 | int length = in.readUnsignedByte(); |
| 215 | if (0 == length) break; |
| 216 | for (int j = 0; j < length; ++j) { |
| 217 | in.readUnsignedByte(); |
| 218 | } |
| 219 | } |
| 220 | in.readShort(); |
| 221 | in.readShort(); |
| 222 | } |
| 223 | Vector res = new Vector(); |
| 224 | for (int i = 0; i < answers; ++i) { |
| 225 | in.readUnsignedShort(); // ... |
| 226 | int type = in.readUnsignedShort(); // type |
| 227 | in.readUnsignedShort(); // class |
| 228 | int ttl = in.readInt(); // ttl |
| 229 | int rdlength = in.readUnsignedShort(); // length |
| 230 | if (type == 0x0021) { |
| 231 | // SRV |
| 232 | in.readUnsignedShort(); |
| 233 | in.readUnsignedShort(); |
| 234 | int port = in.readUnsignedShort(); // port |
| 235 | StringBuffer result = new StringBuffer(); |
| 236 | while (true) { |
| 237 | int length = in.readUnsignedByte(); |
| 238 | if (0 == length) break; |
| 239 | for (int j = 0; j < length; ++j) { |
| 240 | result.append((char) in.readUnsignedByte()); |
| 241 | } |
| 242 | result.append('.'); |
| 243 | } |
| 244 | if (443 == port) { |
| 245 | port = 5222; |
| 246 | } |
| 247 | SrvRdata item = new SrvRdata(); |
| 248 | item.host = result.toString().substring(0, result.length() - 1); |
| 249 | item.port = port; |
| 250 | item.ttl = ttl; |
| 251 | res.addElement(item); |
| 252 | } |
| 253 | } |
| 254 | return res; |
| 255 | } catch (IOException ex) { |
| 256 | return null; |
| 257 | } |
| 258 | } |
| 259 |
no test coverage detected