Returns the Teredo information embedded in a Teredo address. @param ip Inet6Address to be examined for embedded Teredo information @return extracted TeredoInfo @throws IllegalArgumentException if the argument is not a valid IPv6 Teredo address
(Inet6Address ip)
| 684 | |
| 685 | |
| 686 | public static TeredoInfo getTeredoInfo(Inet6Address ip) { |
| 687 | Preconditions.checkArgument(isTeredoAddress(ip), "Address '%s' is not a Teredo address.", toAddrString(ip)); |
| 688 | byte[] bytes = ip.getAddress(); |
| 689 | Inet4Address server = getInet4Address(Arrays.copyOfRange(bytes, 4, 8)); |
| 690 | int flags = ByteStreams.newDataInput(bytes, 8).readShort() & 0xffff; |
| 691 | |
| 692 | // Teredo obfuscates the mapped client port, per section 4 of the RFC. |
| 693 | int port = ~ByteStreams.newDataInput(bytes, 10).readShort() & 0xffff; |
| 694 | byte[] clientBytes = Arrays.copyOfRange(bytes, 12, 16); |
| 695 | for (int i = 0; i < clientBytes.length; i++) { |
| 696 | // Teredo obfuscates the mapped client IP, per section 4 of the RFC. |
| 697 | clientBytes[i] = (byte) ~ clientBytes[i]; |
| 698 | } |
| 699 | Inet4Address client = getInet4Address(clientBytes); |
| 700 | return new TeredoInfo(server, client, port, flags); |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * Evaluates whether the argument is an ISATAP address. |
no test coverage detected