| 171 | } |
| 172 | |
| 173 | private byte[] encode(String domain) { |
| 174 | try { |
| 175 | ByteArrayOutputStream os = new ByteArrayOutputStream(); |
| 176 | DataOutputStream out = new DataOutputStream(os); |
| 177 | out.writeShort(0x666); |
| 178 | out.writeByte(0x01); // QR+Opcode+AA+TC+RD = 0000-0001b - RECURSION_DESIRED |
| 179 | out.writeByte(0x00); // RA+Z+RCode = 0000-0000b |
| 180 | out.writeShort(0x0001); // queries count |
| 181 | out.writeShort(0x0000); // answers count |
| 182 | out.writeShort(0x0000); // authority record count |
| 183 | out.writeShort(0x0000); // additions count |
| 184 | StringBuffer domains = new StringBuffer(); |
| 185 | domains.append(_srv); |
| 186 | domains.append(domain); |
| 187 | String[] res = StringUtils.explode(domains.toString(), '.'); |
| 188 | for (int i = 0; i < res.length; ++i) { |
| 189 | byte[] l = res[i].getBytes(); |
| 190 | out.writeByte(l.length); |
| 191 | out.write(l); |
| 192 | } |
| 193 | out.writeByte(0x00); |
| 194 | out.writeShort(0x0021); // type: SRV |
| 195 | out.writeShort(0x0001); // class: Internet |
| 196 | return os.toByteArray(); |
| 197 | } catch (IOException ex) { |
| 198 | return null; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | private Vector decode (byte[] response) { |
| 203 | try { |