1 /* 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.io.ByteArrayInputStream; 25 import java.io.ByteArrayOutputStream; 26 import java.io.FileNotFoundException; 27 import java.io.FileOutputStream; 28 import java.io.IOException; 29 import java.io.ObjectInputStream; 30 import java.io.ObjectOutputStream; 31 import java.io.PrintStream; 32 import java.net.Inet6Address; 33 import java.net.InetAddress; 34 import java.net.NetworkInterface; 35 import java.net.UnknownHostException; 36 import java.util.ArrayList; 37 import java.util.Arrays; 38 import java.util.Enumeration; 39 import java.util.List; 40 41 /** 42 * @test 43 * @bug 8007373 44 * @summary jdk7 backward compatibility serialization problem 45 */ 46 47 public class Inet6AddressSerializationTest { 48 49 static boolean failed; 50 51 public static final int LOOPBACK_SCOPE_ID = 0; 52 53 public static final byte[] IN6ADDR_ANY_INIT = { (byte) 0x00, (byte) 0x00, 54 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 55 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 56 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }; 57 58 public static final byte[] LOOPBACKIPV6ADDRESS = { (byte) 0x00, 59 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 60 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 61 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01 }; 62 63 // fe80::21b:24ff:febd:f29c 64 public static final byte[] E1000G0IPV6ADDRESS = { (byte) 0xfe, (byte) 0x80, 65 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 66 (byte) 0x00, (byte) 0x02, (byte) 0x1b, (byte) 0x24, (byte) 0xff, 67 (byte) 0xfe, (byte) 0xbd, (byte) 0xf2, (byte) 0x9c }; 68 69 public static final String E1000G0HOSTNAME = "fe80:0:0:0:21b:24ff:febd:f29c%e1000g0"; 70 71 public static final String LOCALHOSTNAME = "localhost"; 72 73 public static final String NETWORK_IF_E1000G0 = "e1000g0"; 74 75 public static final String NETWORK_IF_LO0 = "lo0"; 76 77 public static final int SCOPE_ID_E1000G0 = 2; 78 79 public static final int SCOPE_ID_LO0 = 1; 80 81 public static final int SCOPE_ID_ZERO = 0; 82 main(String[] args)83 public static void main(String[] args) throws Exception { 84 // args[0] == generate-loopback generates serial data for loopback if 85 // args[0] == generateAll generates serial data for interfaces with an 86 // IPV6 address binding 87 88 if (args.length != 0) { 89 90 if (args[0].equals("generate-loopback")) { 91 92 generateSerializedInet6AddressData(Inet6Address.getByAddress( 93 InetAddress.getLoopbackAddress().getHostName(), 94 LOOPBACKIPV6ADDRESS, LOOPBACK_SCOPE_ID), System.out, 95 true); 96 97 } else { 98 generateAllInet6AddressSerializedData(); 99 } 100 } else { 101 runTests(); 102 } 103 } 104 runTests()105 private static void runTests() throws UnknownHostException, Exception, 106 IOException { 107 byte[] thisHostIPV6Address = null; 108 int scope_id = LOOPBACK_SCOPE_ID; 109 110 System.out.println("Hostname: " 111 + InetAddress.getLocalHost().getHostName()); 112 System.out.println("LocalHost isLoopback : " 113 + InetAddress.getLocalHost().isLoopbackAddress()); 114 thisHostIPV6Address = getThisHostIPV6Address(InetAddress.getLocalHost() 115 .getHostName()); 116 117 if (thisHostIPV6Address == null) { 118 thisHostIPV6Address = IN6ADDR_ANY_INIT; 119 } 120 121 // testing JDK7 generated serialized loopback against locally generated 122 // loopback address 123 testInet6AddressSerialization(Inet6Address.getByAddress(InetAddress 124 .getLoopbackAddress().getHostName(), LOOPBACKIPV6ADDRESS, 125 scope_id), JDK7Inet6AddressSerialData); 126 // testing JDK8 generated serialized loopback against locally generated 127 // loopback address 128 testInet6AddressSerialization(Inet6Address.getByAddress(InetAddress 129 .getLoopbackAddress().getHostName(), LOOPBACKIPV6ADDRESS, 130 scope_id), JDK8Inet6AddressSerialData); 131 testInet6AddressSerialization(Inet6Address.getByAddress(InetAddress 132 .getLocalHost().getHostName(), IN6ADDR_ANY_INIT, scope_id), 133 null); 134 testInet6AddressSerialization(Inet6Address.getByAddress(InetAddress 135 .getLocalHost().getHostName(), thisHostIPV6Address, scope_id), 136 null); 137 testAllNetworkInterfaces(); 138 139 // test against lo0 140 testSerializedLo0Inet6Address(); 141 142 testSerializedE1000gInet6Address(); 143 144 if (failed) 145 throw new RuntimeException("Some tests failed, check output"); 146 } 147 getThisHostIPV6Address(String hostName)148 private static byte[] getThisHostIPV6Address(String hostName) 149 throws Exception { 150 InetAddress[] thisHostIPAddresses = null; 151 try { 152 thisHostIPAddresses = InetAddress.getAllByName(InetAddress 153 .getLocalHost().getHostName()); 154 } catch (UnknownHostException uhEx) { 155 uhEx.printStackTrace(); 156 throw uhEx; 157 } 158 byte[] thisHostIPV6Address = null; 159 for (InetAddress inetAddress : thisHostIPAddresses) { 160 if (inetAddress instanceof Inet6Address) { 161 if (inetAddress.getHostName().equals(hostName)) { 162 thisHostIPV6Address = inetAddress.getAddress(); 163 break; 164 } 165 } 166 } 167 // System.err.println("getThisHostIPV6Address: address is " 168 // + Arrays.toString(thisHostIPV6Address)); 169 return thisHostIPV6Address; 170 } 171 testAllNetworkInterfaces()172 static void testAllNetworkInterfaces() throws Exception { 173 System.err.println("\n testAllNetworkInterfaces: \n "); 174 for (Enumeration<NetworkInterface> e = NetworkInterface 175 .getNetworkInterfaces(); e.hasMoreElements();) { 176 NetworkInterface netIF = e.nextElement(); 177 for (Enumeration<InetAddress> iadrs = netIF.getInetAddresses(); iadrs 178 .hasMoreElements();) { 179 InetAddress iadr = iadrs.nextElement(); 180 if (iadr instanceof Inet6Address) { 181 System.err.println("Test NetworkInterface: " + netIF); 182 Inet6Address i6adr = (Inet6Address) iadr; 183 System.err.println("Testing with " + iadr); 184 System.err.println(" scoped iface: " 185 + i6adr.getScopedInterface()); 186 testInet6AddressSerialization(i6adr, null); 187 } 188 } 189 } 190 } 191 displayExpectedInet6Address(Inet6Address expectedInet6Address)192 static void displayExpectedInet6Address(Inet6Address expectedInet6Address) { 193 194 String expectedHostName = expectedInet6Address.getHostName(); 195 byte[] expectedAddress = expectedInet6Address.getAddress(); 196 String expectedHostAddress = expectedInet6Address.getHostAddress(); 197 int expectedScopeId = expectedInet6Address.getScopeId(); 198 NetworkInterface expectedNetIf = expectedInet6Address 199 .getScopedInterface(); 200 201 System.err.println("Excpected HostName: " + expectedHostName); 202 System.err.println("Expected Address: " 203 + Arrays.toString(expectedAddress)); 204 System.err.println("Expected HostAddress: " + expectedHostAddress); 205 System.err.println("Expected Scope Id " + expectedScopeId); 206 System.err.println("Expected NetworkInterface " + expectedNetIf); 207 System.err.println("Expected Inet6Address " + expectedInet6Address); 208 } 209 210 // test serialization deserialization of Inet6Address testInet6AddressSerialization( Inet6Address expectedInet6Address, byte[] serializedAddress)211 static void testInet6AddressSerialization( 212 Inet6Address expectedInet6Address, byte[] serializedAddress) 213 throws IOException { 214 System.err.println("\n testInet6AddressSerialization: enter \n"); 215 216 // displayExpectedInet6Address(expectedInet6Address); 217 218 byte[] serialData = serializedAddress != null ? serializedAddress 219 : generateSerializedInet6AddressData(expectedInet6Address, 220 null, false); 221 try (ByteArrayInputStream bis = new ByteArrayInputStream(serialData); 222 ObjectInputStream oin = new ObjectInputStream(bis)) { 223 Inet6Address deserializedIPV6Addr = (Inet6Address) oin.readObject(); 224 System.err.println("Deserialized Inet6Address " 225 + deserializedIPV6Addr); 226 assertHostNameEqual(expectedInet6Address.getHostName(), 227 deserializedIPV6Addr.getHostName()); 228 assertHostAddressEqual(expectedInet6Address.getHostAddress(), 229 deserializedIPV6Addr.getHostAddress()); 230 assertAddressEqual(expectedInet6Address.getAddress(), 231 deserializedIPV6Addr.getAddress()); 232 assertScopeIdEqual(expectedInet6Address.getScopeId(), 233 deserializedIPV6Addr.getScopeId()); 234 assertNetworkInterfaceEqual( 235 expectedInet6Address.getScopedInterface(), 236 deserializedIPV6Addr.getScopedInterface()); 237 } catch (Exception e) { 238 System.err.println("Exception caught during deserialization"); 239 failed = true; 240 e.printStackTrace(); 241 } 242 } 243 testSerializedE1000gInet6Address()244 static void testSerializedE1000gInet6Address() throws IOException { 245 System.err.println("\n testSerializedE1000gInet6Address: enter \n"); 246 boolean testWithNetIf = true; 247 boolean useMockInet6Address = false; 248 249 NetworkInterface testNetIf = NetworkInterface 250 .getByName(NETWORK_IF_E1000G0); 251 Inet6Address expectedInet6Address = null; 252 if (testNetIf != null) { 253 System.err 254 .println("\n testSerializedE1000gInet6Address: using netif \n"); 255 try { 256 expectedInet6Address = Inet6Address.getByAddress( 257 E1000G0HOSTNAME, E1000G0IPV6ADDRESS, testNetIf); 258 } catch (UnknownHostException ukhEx) { 259 ukhEx.printStackTrace(); 260 testWithNetIf = true; 261 useMockInet6Address = true; 262 } 263 } else { 264 System.err 265 .println("\n testSerializedE1000gInet6Address: using index \n"); 266 try { 267 expectedInet6Address = Inet6Address.getByAddress( 268 E1000G0HOSTNAME, E1000G0IPV6ADDRESS, SCOPE_ID_ZERO); 269 } catch (UnknownHostException ukhEx1) { 270 ukhEx1.printStackTrace(); 271 useMockInet6Address = true; 272 } 273 testWithNetIf = false; 274 } 275 276 byte[] serializedAddress = SerialData_ifname_e1000g0; 277 278 // displayExpectedInet6Address(expectedInet6Address); 279 280 try (ByteArrayInputStream bis = new ByteArrayInputStream( 281 serializedAddress); 282 ObjectInputStream oin = new ObjectInputStream(bis)) { 283 Inet6Address deserializedIPV6Addr = (Inet6Address) oin.readObject(); 284 System.err.println("Deserialized Inet6Address " 285 + deserializedIPV6Addr); 286 287 if (!useMockInet6Address) { 288 assertHostNameEqual(expectedInet6Address.getHostName(), 289 deserializedIPV6Addr.getHostName()); 290 if (testWithNetIf) { 291 assertHostAddressEqual( 292 expectedInet6Address.getHostAddress(), 293 deserializedIPV6Addr.getHostAddress()); 294 } else { 295 assertHostAddressEqual( 296 MockE1000g0Inet6Address.getBareHostAddress(), 297 deserializedIPV6Addr.getHostAddress()); 298 } 299 assertAddressEqual(expectedInet6Address.getAddress(), 300 deserializedIPV6Addr.getAddress()); 301 assertScopeIdEqual(expectedInet6Address.getScopeId(), 302 deserializedIPV6Addr.getScopeId()); 303 if (testWithNetIf) { 304 assertNetworkInterfaceEqual( 305 expectedInet6Address.getScopedInterface(), 306 deserializedIPV6Addr.getScopedInterface()); 307 } else { 308 assertNetworkInterfaceEqual(null, 309 deserializedIPV6Addr.getScopedInterface()); 310 } 311 } else { // use MockLo0Inet6Address 312 assertHostNameEqual(MockE1000g0Inet6Address.getHostName(), 313 deserializedIPV6Addr.getHostName()); 314 if (testWithNetIf) { 315 assertHostAddressEqual( 316 MockE1000g0Inet6Address.getHostAddress(), 317 deserializedIPV6Addr.getHostAddress()); 318 } else { 319 assertHostAddressEqual( 320 MockE1000g0Inet6Address.getHostAddressWithIndex(), 321 deserializedIPV6Addr.getHostAddress()); 322 } 323 assertAddressEqual(MockE1000g0Inet6Address.getAddress(), 324 deserializedIPV6Addr.getAddress()); 325 if (testWithNetIf) { 326 assertScopeIdEqual(MockE1000g0Inet6Address.getScopeId(), 327 deserializedIPV6Addr.getScopeId()); 328 } else { 329 assertScopeIdEqual(MockE1000g0Inet6Address.getScopeZero(), 330 deserializedIPV6Addr.getScopeId()); 331 } 332 assertNetworkInterfaceNameEqual( 333 MockE1000g0Inet6Address.getScopeIfName(), 334 deserializedIPV6Addr.getScopedInterface()); 335 } 336 } catch (Exception e) { 337 System.err.println("Exception caught during deserialization"); 338 failed = true; 339 e.printStackTrace(); 340 } 341 } 342 testSerializedLo0Inet6Address()343 static void testSerializedLo0Inet6Address() throws IOException { 344 System.err.println("\n testSerializedLo0Inet6Address: enter \n"); 345 boolean testWithNetIf = true; 346 boolean useMockInet6Address = false; 347 348 NetworkInterface testNetIf = NetworkInterface.getByName(NETWORK_IF_LO0); 349 Inet6Address expectedInet6Address = null; 350 if (testNetIf != null) { 351 System.err 352 .println("\n testSerializedLo0Inet6Address: using netif \n"); 353 try { 354 expectedInet6Address = Inet6Address.getByAddress(LOCALHOSTNAME, 355 LOOPBACKIPV6ADDRESS, testNetIf); 356 } catch (UnknownHostException ukhEx) { 357 ukhEx.printStackTrace(); 358 testWithNetIf = true; 359 useMockInet6Address = true; 360 } 361 } else { 362 System.err 363 .println("\n testSerializedLo0Inet6Address: using index \n"); 364 try { 365 expectedInet6Address = Inet6Address.getByAddress(LOCALHOSTNAME, 366 LOOPBACKIPV6ADDRESS, SCOPE_ID_ZERO); 367 } catch (UnknownHostException ukhEx1) { 368 ukhEx1.printStackTrace(); 369 useMockInet6Address = true; 370 } 371 testWithNetIf = false; 372 } 373 374 // displayExpectedInet6Address(expectedInet6Address); 375 376 byte[] serializedAddress = SerialData_ifname_lo0; 377 378 try (ByteArrayInputStream bis = new ByteArrayInputStream( 379 serializedAddress); 380 ObjectInputStream oin = new ObjectInputStream(bis)) { 381 Inet6Address deserializedIPV6Addr = (Inet6Address) oin.readObject(); 382 System.err.println("Deserialized Inet6Address " 383 + deserializedIPV6Addr); 384 if (!useMockInet6Address) { 385 assertHostNameEqual(expectedInet6Address.getHostName(), 386 deserializedIPV6Addr.getHostName()); 387 if (testWithNetIf) { 388 assertHostAddressEqual( 389 expectedInet6Address.getHostAddress(), 390 deserializedIPV6Addr.getHostAddress()); 391 } else { 392 assertHostAddressEqual( 393 MockLo0Inet6Address.getBareHostAddress(), 394 deserializedIPV6Addr.getHostAddress()); 395 } 396 assertAddressEqual(expectedInet6Address.getAddress(), 397 deserializedIPV6Addr.getAddress()); 398 assertScopeIdEqual(expectedInet6Address.getScopeId(), 399 deserializedIPV6Addr.getScopeId()); 400 if (testWithNetIf) { 401 assertNetworkInterfaceEqual( 402 expectedInet6Address.getScopedInterface(), 403 deserializedIPV6Addr.getScopedInterface()); 404 } else { 405 assertNetworkInterfaceEqual(null, 406 deserializedIPV6Addr.getScopedInterface()); 407 } 408 } else { // use MockLo0Inet6Address 409 assertHostNameEqual(MockLo0Inet6Address.getHostName(), 410 deserializedIPV6Addr.getHostName()); 411 if (testWithNetIf) { 412 assertHostAddressEqual( 413 MockLo0Inet6Address.getHostAddress(), 414 deserializedIPV6Addr.getHostAddress()); 415 } else { 416 assertHostAddressEqual( 417 MockLo0Inet6Address.getHostAddressWithIndex(), 418 deserializedIPV6Addr.getHostAddress()); 419 } 420 assertAddressEqual(MockLo0Inet6Address.getAddress(), 421 deserializedIPV6Addr.getAddress()); 422 if (testWithNetIf) { 423 assertScopeIdEqual(MockLo0Inet6Address.getScopeId(), 424 deserializedIPV6Addr.getScopeId()); 425 } else { 426 assertScopeIdEqual(MockLo0Inet6Address.getScopeZero(), 427 deserializedIPV6Addr.getScopeId()); 428 } 429 assertNetworkInterfaceNameEqual( 430 MockLo0Inet6Address.getScopeIfName(), 431 deserializedIPV6Addr.getScopedInterface()); 432 } 433 } catch (Exception e) { 434 System.err.println("Exception caught during deserialization"); 435 failed = true; 436 e.printStackTrace(); 437 } 438 } 439 getAllInet6Addresses()440 static List<Inet6Address> getAllInet6Addresses() throws Exception { 441 // System.err.println("\n getAllInet6Addresses: \n "); 442 ArrayList<Inet6Address> inet6Addresses = new ArrayList<Inet6Address>(); 443 for (Enumeration<NetworkInterface> e = NetworkInterface 444 .getNetworkInterfaces(); e.hasMoreElements();) { 445 NetworkInterface netIF = e.nextElement(); 446 for (Enumeration<InetAddress> iadrs = netIF.getInetAddresses(); iadrs 447 .hasMoreElements();) { 448 InetAddress iadr = iadrs.nextElement(); 449 if (iadr instanceof Inet6Address) { 450 System.err.println("Test NetworkInterface: " + netIF); 451 Inet6Address i6adr = (Inet6Address) iadr; 452 System.err.println(" address " + iadr); 453 System.err.println(" scoped iface: " 454 + i6adr.getScopedInterface()); 455 // using this to actually set the hostName for an 456 // InetAddress 457 // created through the NetworkInterface 458 // have found that the fabricated instances has a null 459 // hostName 460 System.err.println(" hostName: " + i6adr.getHostName()); 461 inet6Addresses.add(i6adr); 462 } 463 } 464 } 465 return inet6Addresses; 466 } 467 assertHostNameEqual(String expectedHostName, String deserializedHostName)468 static void assertHostNameEqual(String expectedHostName, 469 String deserializedHostName) { 470 System.err 471 .println("Inet6AddressSerializationTest.assertHostNameEqual:"); 472 if (expectedHostName == null) { 473 if (deserializedHostName == null) { 474 // ok, do nothing. 475 } else { 476 System.err.println("Error checking " + " HostName, expected:" 477 + expectedHostName + ", got :" + deserializedHostName); 478 failed = true; 479 } 480 } else if (!expectedHostName.equals(deserializedHostName)) { 481 System.err.println("Error checking " 482 + // versionStr + 483 " HostName, expected:" + expectedHostName + ", got :" 484 + deserializedHostName); 485 failed = true; 486 } else { 487 System.err.println("HostName equality " 488 + // versionStr + 489 " HostName, expected:" + expectedHostName + ", got :" 490 + deserializedHostName); 491 } 492 } 493 assertHostAddressEqual(String expectedHostAddress, String deserializedHostAddress)494 static void assertHostAddressEqual(String expectedHostAddress, 495 String deserializedHostAddress) { 496 System.err 497 .println("Inet6AddressSerializationTest.assertHostAddressEqual:"); 498 if (expectedHostAddress == null) { 499 if (deserializedHostAddress == null) { 500 // ok, do nothing. 501 } else { 502 System.err.println("Error checking " 503 + " HostAddress, expected: " + expectedHostAddress 504 + ", got: " + deserializedHostAddress); 505 failed = true; 506 } 507 } else if (!expectedHostAddress.equals(deserializedHostAddress)) { 508 System.err.println("Error checking " 509 + // versionStr + 510 " HostAddress, expected: " + expectedHostAddress 511 + ", got: " + deserializedHostAddress); 512 failed = true; 513 } else { 514 System.err.println("HostAddress equality " 515 + // versionStr + 516 " HostAddress, expected: " + expectedHostAddress 517 + ", got: " + deserializedHostAddress); 518 } 519 } 520 assertAddressEqual(byte[] expectedAddress, byte[] deserializedAddress)521 static void assertAddressEqual(byte[] expectedAddress, 522 byte[] deserializedAddress) { 523 System.err.println("Inet6AddressSerializationTest.assertAddressEqual:"); 524 if (expectedAddress == null) { 525 if (deserializedAddress == null) { 526 // ok, do nothing. 527 } else { 528 System.err.println("Error checking " + " Address, expected:" 529 + Arrays.toString(expectedAddress) + ", got: " 530 + Arrays.toString(deserializedAddress)); 531 failed = true; 532 } 533 } else if (!Arrays.equals(expectedAddress, deserializedAddress)) { 534 System.err.println("Error checking " 535 + // versionStr + 536 " Address, expected: " + Arrays.toString(expectedAddress) 537 + ", got: " + Arrays.toString(deserializedAddress)); 538 failed = true; 539 } else { 540 System.err.println("Address equality " 541 + // versionStr + 542 " Address, expected: " + Arrays.toString(expectedAddress) 543 + ", got: " + Arrays.toString(deserializedAddress)); 544 } 545 } 546 assertScopeIdEqual(int expectedScopeId, int deserializedScopeId)547 static void assertScopeIdEqual(int expectedScopeId, int deserializedScopeId) { 548 System.err.println("Inet6AddressSerializationTest.assertScopeIdEqual:"); 549 if (expectedScopeId != deserializedScopeId) { 550 System.err.println("Error checking " + " ScopeId, expected:" 551 + expectedScopeId + ", got: " + deserializedScopeId); 552 failed = true; 553 } else { 554 System.err.println("ScopeId equality " 555 + // versionStr + 556 " ScopeId, expected: " + expectedScopeId + ", got: " 557 + deserializedScopeId); 558 } 559 } 560 assertNetworkInterfaceNameEqual(String expectedNetworkIfName, NetworkInterface deserializedNetworkInterface)561 static void assertNetworkInterfaceNameEqual(String expectedNetworkIfName, 562 NetworkInterface deserializedNetworkInterface) { 563 564 if (deserializedNetworkInterface != null) { 565 String deserializedNetworkIfName = deserializedNetworkInterface 566 .getName(); 567 System.err 568 .println("Inet6AddressSerializationTest.assertHostNameEqual:"); 569 if (expectedNetworkIfName == null) { 570 if (deserializedNetworkIfName == null) { 571 // ok, do nothing. 572 } else { 573 System.err.println("Error checking " 574 + " NetworkIfName, expected: " 575 + expectedNetworkIfName + ", got: " 576 + deserializedNetworkIfName); 577 failed = true; 578 } 579 } else if (!expectedNetworkIfName.equals(deserializedNetworkIfName)) { 580 System.err.println("Error checking " 581 + " NetworkIfName, expected: " + expectedNetworkIfName 582 + ", got: " + deserializedNetworkIfName); 583 failed = true; 584 } else { 585 System.err.println("NetworkIfName equality " 586 + " NetworkIfName, expected: " + expectedNetworkIfName 587 + ", got: " + deserializedNetworkIfName); 588 } 589 } else { 590 System.err 591 .println("Warning " 592 + " NetworkInterface expected, but is null - ifname not relevant on deserializing host"); 593 } 594 } 595 assertNetworkInterfaceEqual( NetworkInterface expectedNetworkInterface, NetworkInterface deserializedNetworkInterface)596 static void assertNetworkInterfaceEqual( 597 NetworkInterface expectedNetworkInterface, 598 NetworkInterface deserializedNetworkInterface) { 599 System.err 600 .println("Inet6AddressSerializationTest.assertNetworkInterfaceEqual:"); 601 if (expectedNetworkInterface == null) { 602 if (deserializedNetworkInterface == null) { 603 // ok, do nothing. 604 System.err.println("Network Interface equality " 605 + " NetworkInterface, expected:" 606 + expectedNetworkInterface + ", got :" 607 + deserializedNetworkInterface); 608 } else { 609 System.err.println("Error checking " 610 + " NetworkInterface, expected:" 611 + expectedNetworkInterface + ", got :" 612 + deserializedNetworkInterface); 613 failed = true; 614 } 615 } else if (!expectedNetworkInterface 616 .equals(deserializedNetworkInterface)) { 617 System.err.println("Error checking " 618 + // versionStr + 619 " NetworkInterface, expected:" + expectedNetworkInterface 620 + ", got :" + deserializedNetworkInterface); 621 failed = true; 622 } else { 623 System.err.println("Network Interface equality " 624 + " NetworkInterface, expected:" + expectedNetworkInterface 625 + ", got :" + deserializedNetworkInterface); 626 } 627 } 628 equal(Object expected, Object got)629 static void equal(Object expected, Object got) { 630 if (expected == null) { 631 if (got == null) { 632 // ok, do nothing. 633 } else { 634 System.err.println("Error checking " 635 + " serial data, expected:" + expected + ", got :" 636 + got); 637 failed = true; 638 } 639 } else if (!expected.equals(got)) { 640 System.err.println("Error checking " + // versionStr + 641 " serial data, expected:" + expected + ", got :" + got); 642 failed = true; 643 } 644 } 645 646 // Used to generate serialData. generateSerializedInet6AddressData(Inet6Address addr, PrintStream out, boolean outputToFile)647 static byte[] generateSerializedInet6AddressData(Inet6Address addr, 648 PrintStream out, boolean outputToFile) throws IOException { 649 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 650 try (ObjectOutputStream oos = new ObjectOutputStream(bos)) { 651 oos.writeObject(addr); 652 } 653 654 String ifname = getIfName(addr); 655 byte[] ba = bos.toByteArray(); 656 if (out != null) { 657 out.format("static final byte[] SerialData" + ifname + " = {\n"); 658 for (int i = 0; i < ba.length; i++) { 659 out.format(" (byte)0x%02X", ba[i]); 660 if (i != (ba.length - 1)) 661 out.format(","); 662 if (((i + 1) % 6) == 0) 663 out.format("\n"); 664 } 665 out.format(" };\n \n"); 666 } 667 if (outputToFile) { 668 serializeInet6AddressToFile(addr); 669 } 670 return ba; 671 } 672 getIfName(Inet6Address inet6Addr)673 private static String getIfName(Inet6Address inet6Addr) { 674 String ifname; 675 if (inet6Addr.getScopedInterface() != null) { 676 ifname = "_ifname_" + inet6Addr.getScopedInterface().getName(); 677 } else { 678 ifname = "_ifname_" 679 + Integer.valueOf(inet6Addr.getScopeId()).toString(); 680 } 681 return ifname; 682 } 683 generateAllInet6AddressSerializedData()684 static void generateAllInet6AddressSerializedData() throws IOException { 685 // System.err.println("generateAllInet6AddressSerializedData: enter ...."); 686 687 List<Inet6Address> inet6Addresses; 688 689 try { 690 inet6Addresses = getAllInet6Addresses(); 691 } catch (Exception e) { 692 e.printStackTrace(); 693 throw new IOException(e); 694 } 695 696 for (Inet6Address inet6Address : inet6Addresses) { 697 generateSerializedInet6AddressData(inet6Address, System.out, true); 698 } 699 } 700 serializeInet6AddressToFile(Inet6Address inet6Addr)701 static void serializeInet6AddressToFile(Inet6Address inet6Addr) { 702 703 // System.err 704 // .println("serializeInet6AddressToIPV6AddressFile: enter ...."); 705 706 FileOutputStream fOut = null; 707 String inet6AddressOutputFilename = null; 708 inet6AddressOutputFilename = createOutputFileName(inet6Addr); 709 try { 710 fOut = new FileOutputStream(inet6AddressOutputFilename); 711 } catch (FileNotFoundException fnfEx) { 712 713 fnfEx.printStackTrace(); 714 } 715 ObjectOutputStream ooStream = null; 716 try { 717 if (fOut != null) { 718 ooStream = new ObjectOutputStream(fOut); 719 } else { 720 System.err.println("Problem initilising Object output stream "); 721 System.exit(-1); 722 } 723 724 } catch (IOException e) { 725 e.printStackTrace(); 726 System.exit(-1); 727 } 728 729 // serialise the last Inet6Address 730 /* 731 * System.err 732 * .println("serializeInet6AddressToIPV6AddressFile scoped iface: \n" + 733 * inet6Addr.getScopedInterface()); 734 */ 735 try { 736 ooStream.writeObject(inet6Addr); 737 } catch (Exception ex) { 738 ex.printStackTrace(); 739 System.exit(-1); 740 } 741 742 try { 743 ooStream.close(); 744 } catch (IOException e) { 745 e.printStackTrace(); 746 } 747 } 748 createOutputFileName(Inet6Address inet6Addr)749 private static String createOutputFileName(Inet6Address inet6Addr) { 750 String inet6AddressOutputFilename; 751 if (inet6Addr.getScopedInterface() != null) { 752 inet6AddressOutputFilename = "IPV6Address_" 753 + inet6Addr.getScopedInterface().getName() + ".out"; 754 } else { 755 inet6AddressOutputFilename = "IPV6Address_" 756 + Integer.valueOf(inet6Addr.getScopeId()).toString() 757 + ".out"; 758 } 759 return inet6AddressOutputFilename; 760 } 761 762 // --- Generated data --- 763 // JDK7 output java Inet6AddressSerializationTest generate. 764 765 // loopback lo0 interface on Solaris 10 766 767 static final byte[] JDK7Inet6AddressSerialData = { (byte) 0xAC, 768 (byte) 0xED, (byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72, 769 (byte) 0x00, (byte) 0x15, (byte) 0x6A, (byte) 0x61, (byte) 0x76, 770 (byte) 0x61, (byte) 0x2E, (byte) 0x6E, (byte) 0x65, (byte) 0x74, 771 (byte) 0x2E, (byte) 0x49, (byte) 0x6E, (byte) 0x65, (byte) 0x74, 772 (byte) 0x36, (byte) 0x41, (byte) 0x64, (byte) 0x64, (byte) 0x72, 773 (byte) 0x65, (byte) 0x73, (byte) 0x73, (byte) 0x5F, (byte) 0x7C, 774 (byte) 0x20, (byte) 0x81, (byte) 0x52, (byte) 0x2C, (byte) 0x80, 775 (byte) 0x21, (byte) 0x03, (byte) 0x00, (byte) 0x05, (byte) 0x49, 776 (byte) 0x00, (byte) 0x08, (byte) 0x73, (byte) 0x63, (byte) 0x6F, 777 (byte) 0x70, (byte) 0x65, (byte) 0x5F, (byte) 0x69, (byte) 0x64, 778 (byte) 0x5A, (byte) 0x00, (byte) 0x0C, (byte) 0x73, (byte) 0x63, 779 (byte) 0x6F, (byte) 0x70, (byte) 0x65, (byte) 0x5F, (byte) 0x69, 780 (byte) 0x64, (byte) 0x5F, (byte) 0x73, (byte) 0x65, (byte) 0x74, 781 (byte) 0x5A, (byte) 0x00, (byte) 0x10, (byte) 0x73, (byte) 0x63, 782 (byte) 0x6F, (byte) 0x70, (byte) 0x65, (byte) 0x5F, (byte) 0x69, 783 (byte) 0x66, (byte) 0x6E, (byte) 0x61, (byte) 0x6D, (byte) 0x65, 784 (byte) 0x5F, (byte) 0x73, (byte) 0x65, (byte) 0x74, (byte) 0x4C, 785 (byte) 0x00, (byte) 0x06, (byte) 0x69, (byte) 0x66, (byte) 0x6E, 786 (byte) 0x61, (byte) 0x6D, (byte) 0x65, (byte) 0x74, (byte) 0x00, 787 (byte) 0x12, (byte) 0x4C, (byte) 0x6A, (byte) 0x61, (byte) 0x76, 788 (byte) 0x61, (byte) 0x2F, (byte) 0x6C, (byte) 0x61, (byte) 0x6E, 789 (byte) 0x67, (byte) 0x2F, (byte) 0x53, (byte) 0x74, (byte) 0x72, 790 (byte) 0x69, (byte) 0x6E, (byte) 0x67, (byte) 0x3B, (byte) 0x5B, 791 (byte) 0x00, (byte) 0x09, (byte) 0x69, (byte) 0x70, (byte) 0x61, 792 (byte) 0x64, (byte) 0x64, (byte) 0x72, (byte) 0x65, (byte) 0x73, 793 (byte) 0x73, (byte) 0x74, (byte) 0x00, (byte) 0x02, (byte) 0x5B, 794 (byte) 0x42, (byte) 0x78, (byte) 0x72, (byte) 0x00, (byte) 0x14, 795 (byte) 0x6A, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2E, 796 (byte) 0x6E, (byte) 0x65, (byte) 0x74, (byte) 0x2E, (byte) 0x49, 797 (byte) 0x6E, (byte) 0x65, (byte) 0x74, (byte) 0x41, (byte) 0x64, 798 (byte) 0x64, (byte) 0x72, (byte) 0x65, (byte) 0x73, (byte) 0x73, 799 (byte) 0x2D, (byte) 0x9B, (byte) 0x57, (byte) 0xAF, (byte) 0x9F, 800 (byte) 0xE3, (byte) 0xEB, (byte) 0xDB, (byte) 0x02, (byte) 0x00, 801 (byte) 0x03, (byte) 0x49, (byte) 0x00, (byte) 0x07, (byte) 0x61, 802 (byte) 0x64, (byte) 0x64, (byte) 0x72, (byte) 0x65, (byte) 0x73, 803 (byte) 0x73, (byte) 0x49, (byte) 0x00, (byte) 0x06, (byte) 0x66, 804 (byte) 0x61, (byte) 0x6D, (byte) 0x69, (byte) 0x6C, (byte) 0x79, 805 (byte) 0x4C, (byte) 0x00, (byte) 0x08, (byte) 0x68, (byte) 0x6F, 806 (byte) 0x73, (byte) 0x74, (byte) 0x4E, (byte) 0x61, (byte) 0x6D, 807 (byte) 0x65, (byte) 0x71, (byte) 0x00, (byte) 0x7E, (byte) 0x00, 808 (byte) 0x01, (byte) 0x78, (byte) 0x70, (byte) 0x00, (byte) 0x00, 809 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 810 (byte) 0x02, (byte) 0x74, (byte) 0x00, (byte) 0x09, (byte) 0x6C, 811 (byte) 0x6F, (byte) 0x63, (byte) 0x61, (byte) 0x6C, (byte) 0x68, 812 (byte) 0x6F, (byte) 0x73, (byte) 0x74, (byte) 0x00, (byte) 0x00, 813 (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x70, 814 (byte) 0x75, (byte) 0x72, (byte) 0x00, (byte) 0x02, (byte) 0x5B, 815 (byte) 0x42, (byte) 0xAC, (byte) 0xF3, (byte) 0x17, (byte) 0xF8, 816 (byte) 0x06, (byte) 0x08, (byte) 0x54, (byte) 0xE0, (byte) 0x02, 817 (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0x70, (byte) 0x00, 818 (byte) 0x00, (byte) 0x00, (byte) 0x10, (byte) 0x00, (byte) 0x00, 819 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 820 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 821 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x78 }; 822 823 // JDK8 output java Inet6AddressSerializationTest generate. 824 // loopback lo0 interface on Solaris 10 825 826 static final byte[] JDK8Inet6AddressSerialData = { (byte) 0xAC, 827 (byte) 0xED, (byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72, 828 (byte) 0x00, (byte) 0x15, (byte) 0x6A, (byte) 0x61, (byte) 0x76, 829 (byte) 0x61, (byte) 0x2E, (byte) 0x6E, (byte) 0x65, (byte) 0x74, 830 (byte) 0x2E, (byte) 0x49, (byte) 0x6E, (byte) 0x65, (byte) 0x74, 831 (byte) 0x36, (byte) 0x41, (byte) 0x64, (byte) 0x64, (byte) 0x72, 832 (byte) 0x65, (byte) 0x73, (byte) 0x73, (byte) 0x5F, (byte) 0x7C, 833 (byte) 0x20, (byte) 0x81, (byte) 0x52, (byte) 0x2C, (byte) 0x80, 834 (byte) 0x21, (byte) 0x03, (byte) 0x00, (byte) 0x05, (byte) 0x49, 835 (byte) 0x00, (byte) 0x08, (byte) 0x73, (byte) 0x63, (byte) 0x6F, 836 (byte) 0x70, (byte) 0x65, (byte) 0x5F, (byte) 0x69, (byte) 0x64, 837 (byte) 0x5A, (byte) 0x00, (byte) 0x0C, (byte) 0x73, (byte) 0x63, 838 (byte) 0x6F, (byte) 0x70, (byte) 0x65, (byte) 0x5F, (byte) 0x69, 839 (byte) 0x64, (byte) 0x5F, (byte) 0x73, (byte) 0x65, (byte) 0x74, 840 (byte) 0x5A, (byte) 0x00, (byte) 0x10, (byte) 0x73, (byte) 0x63, 841 (byte) 0x6F, (byte) 0x70, (byte) 0x65, (byte) 0x5F, (byte) 0x69, 842 (byte) 0x66, (byte) 0x6E, (byte) 0x61, (byte) 0x6D, (byte) 0x65, 843 (byte) 0x5F, (byte) 0x73, (byte) 0x65, (byte) 0x74, (byte) 0x4C, 844 (byte) 0x00, (byte) 0x06, (byte) 0x69, (byte) 0x66, (byte) 0x6E, 845 (byte) 0x61, (byte) 0x6D, (byte) 0x65, (byte) 0x74, (byte) 0x00, 846 (byte) 0x12, (byte) 0x4C, (byte) 0x6A, (byte) 0x61, (byte) 0x76, 847 (byte) 0x61, (byte) 0x2F, (byte) 0x6C, (byte) 0x61, (byte) 0x6E, 848 (byte) 0x67, (byte) 0x2F, (byte) 0x53, (byte) 0x74, (byte) 0x72, 849 (byte) 0x69, (byte) 0x6E, (byte) 0x67, (byte) 0x3B, (byte) 0x5B, 850 (byte) 0x00, (byte) 0x09, (byte) 0x69, (byte) 0x70, (byte) 0x61, 851 (byte) 0x64, (byte) 0x64, (byte) 0x72, (byte) 0x65, (byte) 0x73, 852 (byte) 0x73, (byte) 0x74, (byte) 0x00, (byte) 0x02, (byte) 0x5B, 853 (byte) 0x42, (byte) 0x78, (byte) 0x72, (byte) 0x00, (byte) 0x14, 854 (byte) 0x6A, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2E, 855 (byte) 0x6E, (byte) 0x65, (byte) 0x74, (byte) 0x2E, (byte) 0x49, 856 (byte) 0x6E, (byte) 0x65, (byte) 0x74, (byte) 0x41, (byte) 0x64, 857 (byte) 0x64, (byte) 0x72, (byte) 0x65, (byte) 0x73, (byte) 0x73, 858 (byte) 0x2D, (byte) 0x9B, (byte) 0x57, (byte) 0xAF, (byte) 0x9F, 859 (byte) 0xE3, (byte) 0xEB, (byte) 0xDB, (byte) 0x02, (byte) 0x00, 860 (byte) 0x03, (byte) 0x49, (byte) 0x00, (byte) 0x07, (byte) 0x61, 861 (byte) 0x64, (byte) 0x64, (byte) 0x72, (byte) 0x65, (byte) 0x73, 862 (byte) 0x73, (byte) 0x49, (byte) 0x00, (byte) 0x06, (byte) 0x66, 863 (byte) 0x61, (byte) 0x6D, (byte) 0x69, (byte) 0x6C, (byte) 0x79, 864 (byte) 0x4C, (byte) 0x00, (byte) 0x08, (byte) 0x68, (byte) 0x6F, 865 (byte) 0x73, (byte) 0x74, (byte) 0x4E, (byte) 0x61, (byte) 0x6D, 866 (byte) 0x65, (byte) 0x71, (byte) 0x00, (byte) 0x7E, (byte) 0x00, 867 (byte) 0x01, (byte) 0x78, (byte) 0x70, (byte) 0x00, (byte) 0x00, 868 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 869 (byte) 0x02, (byte) 0x74, (byte) 0x00, (byte) 0x09, (byte) 0x6C, 870 (byte) 0x6F, (byte) 0x63, (byte) 0x61, (byte) 0x6C, (byte) 0x68, 871 (byte) 0x6F, (byte) 0x73, (byte) 0x74, (byte) 0x00, (byte) 0x00, 872 (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x70, 873 (byte) 0x75, (byte) 0x72, (byte) 0x00, (byte) 0x02, (byte) 0x5B, 874 (byte) 0x42, (byte) 0xAC, (byte) 0xF3, (byte) 0x17, (byte) 0xF8, 875 (byte) 0x06, (byte) 0x08, (byte) 0x54, (byte) 0xE0, (byte) 0x02, 876 (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0x70, (byte) 0x00, 877 (byte) 0x00, (byte) 0x00, (byte) 0x10, (byte) 0x00, (byte) 0x00, 878 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 879 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 880 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x78 }; 881 882 // java Inet6AddressSerializationTest generateAll produces this inet6address 883 // serial data 884 // jdk8 generated serialization of on address fe80:0:0:0:21b:24ff:febd:f29c 885 // net if e1000g0 886 887 static final byte[] SerialData_ifname_e1000g0 = { (byte) 0xAC, (byte) 0xED, 888 (byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72, (byte) 0x00, 889 (byte) 0x15, (byte) 0x6A, (byte) 0x61, (byte) 0x76, (byte) 0x61, 890 (byte) 0x2E, (byte) 0x6E, (byte) 0x65, (byte) 0x74, (byte) 0x2E, 891 (byte) 0x49, (byte) 0x6E, (byte) 0x65, (byte) 0x74, (byte) 0x36, 892 (byte) 0x41, (byte) 0x64, (byte) 0x64, (byte) 0x72, (byte) 0x65, 893 (byte) 0x73, (byte) 0x73, (byte) 0x5F, (byte) 0x7C, (byte) 0x20, 894 (byte) 0x81, (byte) 0x52, (byte) 0x2C, (byte) 0x80, (byte) 0x21, 895 (byte) 0x03, (byte) 0x00, (byte) 0x05, (byte) 0x49, (byte) 0x00, 896 (byte) 0x08, (byte) 0x73, (byte) 0x63, (byte) 0x6F, (byte) 0x70, 897 (byte) 0x65, (byte) 0x5F, (byte) 0x69, (byte) 0x64, (byte) 0x5A, 898 (byte) 0x00, (byte) 0x0C, (byte) 0x73, (byte) 0x63, (byte) 0x6F, 899 (byte) 0x70, (byte) 0x65, (byte) 0x5F, (byte) 0x69, (byte) 0x64, 900 (byte) 0x5F, (byte) 0x73, (byte) 0x65, (byte) 0x74, (byte) 0x5A, 901 (byte) 0x00, (byte) 0x10, (byte) 0x73, (byte) 0x63, (byte) 0x6F, 902 (byte) 0x70, (byte) 0x65, (byte) 0x5F, (byte) 0x69, (byte) 0x66, 903 (byte) 0x6E, (byte) 0x61, (byte) 0x6D, (byte) 0x65, (byte) 0x5F, 904 (byte) 0x73, (byte) 0x65, (byte) 0x74, (byte) 0x4C, (byte) 0x00, 905 (byte) 0x06, (byte) 0x69, (byte) 0x66, (byte) 0x6E, (byte) 0x61, 906 (byte) 0x6D, (byte) 0x65, (byte) 0x74, (byte) 0x00, (byte) 0x12, 907 (byte) 0x4C, (byte) 0x6A, (byte) 0x61, (byte) 0x76, (byte) 0x61, 908 (byte) 0x2F, (byte) 0x6C, (byte) 0x61, (byte) 0x6E, (byte) 0x67, 909 (byte) 0x2F, (byte) 0x53, (byte) 0x74, (byte) 0x72, (byte) 0x69, 910 (byte) 0x6E, (byte) 0x67, (byte) 0x3B, (byte) 0x5B, (byte) 0x00, 911 (byte) 0x09, (byte) 0x69, (byte) 0x70, (byte) 0x61, (byte) 0x64, 912 (byte) 0x64, (byte) 0x72, (byte) 0x65, (byte) 0x73, (byte) 0x73, 913 (byte) 0x74, (byte) 0x00, (byte) 0x02, (byte) 0x5B, (byte) 0x42, 914 (byte) 0x78, (byte) 0x72, (byte) 0x00, (byte) 0x14, (byte) 0x6A, 915 (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2E, (byte) 0x6E, 916 (byte) 0x65, (byte) 0x74, (byte) 0x2E, (byte) 0x49, (byte) 0x6E, 917 (byte) 0x65, (byte) 0x74, (byte) 0x41, (byte) 0x64, (byte) 0x64, 918 (byte) 0x72, (byte) 0x65, (byte) 0x73, (byte) 0x73, (byte) 0x2D, 919 (byte) 0x9B, (byte) 0x57, (byte) 0xAF, (byte) 0x9F, (byte) 0xE3, 920 (byte) 0xEB, (byte) 0xDB, (byte) 0x02, (byte) 0x00, (byte) 0x03, 921 (byte) 0x49, (byte) 0x00, (byte) 0x07, (byte) 0x61, (byte) 0x64, 922 (byte) 0x64, (byte) 0x72, (byte) 0x65, (byte) 0x73, (byte) 0x73, 923 (byte) 0x49, (byte) 0x00, (byte) 0x06, (byte) 0x66, (byte) 0x61, 924 (byte) 0x6D, (byte) 0x69, (byte) 0x6C, (byte) 0x79, (byte) 0x4C, 925 (byte) 0x00, (byte) 0x08, (byte) 0x68, (byte) 0x6F, (byte) 0x73, 926 (byte) 0x74, (byte) 0x4E, (byte) 0x61, (byte) 0x6D, (byte) 0x65, 927 (byte) 0x71, (byte) 0x00, (byte) 0x7E, (byte) 0x00, (byte) 0x01, 928 (byte) 0x78, (byte) 0x70, (byte) 0x00, (byte) 0x00, (byte) 0x00, 929 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, 930 (byte) 0x74, (byte) 0x00, (byte) 0x25, (byte) 0x66, (byte) 0x65, 931 (byte) 0x38, (byte) 0x30, (byte) 0x3A, (byte) 0x30, (byte) 0x3A, 932 (byte) 0x30, (byte) 0x3A, (byte) 0x30, (byte) 0x3A, (byte) 0x32, 933 (byte) 0x31, (byte) 0x62, (byte) 0x3A, (byte) 0x32, (byte) 0x34, 934 (byte) 0x66, (byte) 0x66, (byte) 0x3A, (byte) 0x66, (byte) 0x65, 935 (byte) 0x62, (byte) 0x64, (byte) 0x3A, (byte) 0x66, (byte) 0x32, 936 (byte) 0x39, (byte) 0x63, (byte) 0x25, (byte) 0x65, (byte) 0x31, 937 (byte) 0x30, (byte) 0x30, (byte) 0x30, (byte) 0x67, (byte) 0x30, 938 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x01, 939 (byte) 0x01, (byte) 0x74, (byte) 0x00, (byte) 0x07, (byte) 0x65, 940 (byte) 0x31, (byte) 0x30, (byte) 0x30, (byte) 0x30, (byte) 0x67, 941 (byte) 0x30, (byte) 0x75, (byte) 0x72, (byte) 0x00, (byte) 0x02, 942 (byte) 0x5B, (byte) 0x42, (byte) 0xAC, (byte) 0xF3, (byte) 0x17, 943 (byte) 0xF8, (byte) 0x06, (byte) 0x08, (byte) 0x54, (byte) 0xE0, 944 (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x78, (byte) 0x70, 945 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x10, (byte) 0xFE, 946 (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 947 (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x1B, (byte) 0x24, 948 (byte) 0xFF, (byte) 0xFE, (byte) 0xBD, (byte) 0xF2, (byte) 0x9C, 949 (byte) 0x78 }; 950 951 // jdk8 generated serialization of address 0::1 on net if lo0 hostname 952 // localhost scope_id 1 953 954 static final byte[] SerialData_ifname_lo0 = { (byte) 0xAC, (byte) 0xED, 955 (byte) 0x00, (byte) 0x05, (byte) 0x73, (byte) 0x72, (byte) 0x00, 956 (byte) 0x15, (byte) 0x6A, (byte) 0x61, (byte) 0x76, (byte) 0x61, 957 (byte) 0x2E, (byte) 0x6E, (byte) 0x65, (byte) 0x74, (byte) 0x2E, 958 (byte) 0x49, (byte) 0x6E, (byte) 0x65, (byte) 0x74, (byte) 0x36, 959 (byte) 0x41, (byte) 0x64, (byte) 0x64, (byte) 0x72, (byte) 0x65, 960 (byte) 0x73, (byte) 0x73, (byte) 0x5F, (byte) 0x7C, (byte) 0x20, 961 (byte) 0x81, (byte) 0x52, (byte) 0x2C, (byte) 0x80, (byte) 0x21, 962 (byte) 0x03, (byte) 0x00, (byte) 0x05, (byte) 0x49, (byte) 0x00, 963 (byte) 0x08, (byte) 0x73, (byte) 0x63, (byte) 0x6F, (byte) 0x70, 964 (byte) 0x65, (byte) 0x5F, (byte) 0x69, (byte) 0x64, (byte) 0x5A, 965 (byte) 0x00, (byte) 0x0C, (byte) 0x73, (byte) 0x63, (byte) 0x6F, 966 (byte) 0x70, (byte) 0x65, (byte) 0x5F, (byte) 0x69, (byte) 0x64, 967 (byte) 0x5F, (byte) 0x73, (byte) 0x65, (byte) 0x74, (byte) 0x5A, 968 (byte) 0x00, (byte) 0x10, (byte) 0x73, (byte) 0x63, (byte) 0x6F, 969 (byte) 0x70, (byte) 0x65, (byte) 0x5F, (byte) 0x69, (byte) 0x66, 970 (byte) 0x6E, (byte) 0x61, (byte) 0x6D, (byte) 0x65, (byte) 0x5F, 971 (byte) 0x73, (byte) 0x65, (byte) 0x74, (byte) 0x4C, (byte) 0x00, 972 (byte) 0x06, (byte) 0x69, (byte) 0x66, (byte) 0x6E, (byte) 0x61, 973 (byte) 0x6D, (byte) 0x65, (byte) 0x74, (byte) 0x00, (byte) 0x12, 974 (byte) 0x4C, (byte) 0x6A, (byte) 0x61, (byte) 0x76, (byte) 0x61, 975 (byte) 0x2F, (byte) 0x6C, (byte) 0x61, (byte) 0x6E, (byte) 0x67, 976 (byte) 0x2F, (byte) 0x53, (byte) 0x74, (byte) 0x72, (byte) 0x69, 977 (byte) 0x6E, (byte) 0x67, (byte) 0x3B, (byte) 0x5B, (byte) 0x00, 978 (byte) 0x09, (byte) 0x69, (byte) 0x70, (byte) 0x61, (byte) 0x64, 979 (byte) 0x64, (byte) 0x72, (byte) 0x65, (byte) 0x73, (byte) 0x73, 980 (byte) 0x74, (byte) 0x00, (byte) 0x02, (byte) 0x5B, (byte) 0x42, 981 (byte) 0x78, (byte) 0x72, (byte) 0x00, (byte) 0x14, (byte) 0x6A, 982 (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2E, (byte) 0x6E, 983 (byte) 0x65, (byte) 0x74, (byte) 0x2E, (byte) 0x49, (byte) 0x6E, 984 (byte) 0x65, (byte) 0x74, (byte) 0x41, (byte) 0x64, (byte) 0x64, 985 (byte) 0x72, (byte) 0x65, (byte) 0x73, (byte) 0x73, (byte) 0x2D, 986 (byte) 0x9B, (byte) 0x57, (byte) 0xAF, (byte) 0x9F, (byte) 0xE3, 987 (byte) 0xEB, (byte) 0xDB, (byte) 0x02, (byte) 0x00, (byte) 0x03, 988 (byte) 0x49, (byte) 0x00, (byte) 0x07, (byte) 0x61, (byte) 0x64, 989 (byte) 0x64, (byte) 0x72, (byte) 0x65, (byte) 0x73, (byte) 0x73, 990 (byte) 0x49, (byte) 0x00, (byte) 0x06, (byte) 0x66, (byte) 0x61, 991 (byte) 0x6D, (byte) 0x69, (byte) 0x6C, (byte) 0x79, (byte) 0x4C, 992 (byte) 0x00, (byte) 0x08, (byte) 0x68, (byte) 0x6F, (byte) 0x73, 993 (byte) 0x74, (byte) 0x4E, (byte) 0x61, (byte) 0x6D, (byte) 0x65, 994 (byte) 0x71, (byte) 0x00, (byte) 0x7E, (byte) 0x00, (byte) 0x01, 995 (byte) 0x78, (byte) 0x70, (byte) 0x00, (byte) 0x00, (byte) 0x00, 996 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, 997 (byte) 0x74, (byte) 0x00, (byte) 0x09, (byte) 0x6C, (byte) 0x6F, 998 (byte) 0x63, (byte) 0x61, (byte) 0x6C, (byte) 0x68, (byte) 0x6F, 999 (byte) 0x73, (byte) 0x74, (byte) 0x00, (byte) 0x00, (byte) 0x00, 1000 (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x74, (byte) 0x00, 1001 (byte) 0x03, (byte) 0x6C, (byte) 0x6F, (byte) 0x30, (byte) 0x75, 1002 (byte) 0x72, (byte) 0x00, (byte) 0x02, (byte) 0x5B, (byte) 0x42, 1003 (byte) 0xAC, (byte) 0xF3, (byte) 0x17, (byte) 0xF8, (byte) 0x06, 1004 (byte) 0x08, (byte) 0x54, (byte) 0xE0, (byte) 0x02, (byte) 0x00, 1005 (byte) 0x00, (byte) 0x78, (byte) 0x70, (byte) 0x00, (byte) 0x00, 1006 (byte) 0x00, (byte) 0x10, (byte) 0x00, (byte) 0x00, (byte) 0x00, 1007 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 1008 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 1009 (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x78 }; 1010 1011 } 1012 1013 class MockLo0Inet6Address { 1014 1015 private static final byte[] LOOPBACKIPV6ADDRESS = { (byte) 0x00, 1016 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 1017 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 1018 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01 }; 1019 1020 private static final String LOCALHOSTNAME = "localhost"; 1021 1022 private static final String LO0HOSTADDRESS = "0:0:0:0:0:0:0:1%lo0"; 1023 1024 private static final String BARE_LO0HOSTADDRESS = "0:0:0:0:0:0:0:1"; 1025 1026 private static final String LO0HOSTADDRESS_WITHINDEX = "0:0:0:0:0:0:0:1%1"; 1027 1028 private static final int SCOPE_ID_LO0 = 1; 1029 1030 private static final int SCOPE_ID_ZERO = 0; 1031 1032 public static final String NETWORK_IF_LO0 = "lo0"; 1033 getHostName()1034 static String getHostName() { 1035 return LOCALHOSTNAME; 1036 } 1037 getHostAddress()1038 static String getHostAddress() { 1039 return LO0HOSTADDRESS; 1040 } 1041 getBareHostAddress()1042 static String getBareHostAddress() { 1043 return BARE_LO0HOSTADDRESS; 1044 } 1045 getHostAddressWithIndex()1046 static String getHostAddressWithIndex() { 1047 return LO0HOSTADDRESS_WITHINDEX; 1048 } 1049 getAddress()1050 static byte[] getAddress() { 1051 return LOOPBACKIPV6ADDRESS; 1052 } 1053 getScopeId()1054 static int getScopeId() { 1055 return SCOPE_ID_LO0; 1056 } 1057 getScopeZero()1058 static int getScopeZero() { 1059 return SCOPE_ID_ZERO; 1060 } 1061 getScopeIfName()1062 static String getScopeIfName() { 1063 return NETWORK_IF_LO0; 1064 } 1065 1066 } 1067 1068 class MockE1000g0Inet6Address { 1069 1070 // fe80::21b:24ff:febd:f29c 1071 private static final byte[] E1000G0IPV6ADDRESS = { (byte) 0xfe, 1072 (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 1073 (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x1b, (byte) 0x24, 1074 (byte) 0xff, (byte) 0xfe, (byte) 0xbd, (byte) 0xf2, (byte) 0x9c }; 1075 1076 private static final String E1000G0HOSTNAME = "fe80:0:0:0:21b:24ff:febd:f29c%e1000g0"; 1077 1078 private static final String BARE_E1000G0HOSTADDRESS = "fe80:0:0:0:21b:24ff:febd:f29c"; 1079 1080 private static final String E1000G0HOSTADDRESS_WITHINDEX = "fe80:0:0:0:21b:24ff:febd:f29c%2"; 1081 1082 private static final String E1000G0HOSTADDRESS = "fe80:0:0:0:21b:24ff:febd:f29c%e1000g0"; 1083 1084 private static final String NETWORK_IF_E1000G0 = "e1000g0"; 1085 1086 private static final int SCOPE_ID_E1000G0 = 2; 1087 1088 private static final int SCOPE_ID_ZERO = 0; 1089 getHostName()1090 static String getHostName() { 1091 return E1000G0HOSTNAME; 1092 } 1093 getHostAddress()1094 static String getHostAddress() { 1095 return E1000G0HOSTADDRESS; 1096 } 1097 getHostAddressWithIndex()1098 static String getHostAddressWithIndex() { 1099 return E1000G0HOSTADDRESS_WITHINDEX; 1100 } 1101 getBareHostAddress()1102 static String getBareHostAddress() { 1103 return BARE_E1000G0HOSTADDRESS; 1104 } 1105 getAddress()1106 static byte[] getAddress() { 1107 return E1000G0IPV6ADDRESS; 1108 } 1109 getScopeId()1110 static int getScopeId() { 1111 return SCOPE_ID_E1000G0; 1112 } 1113 getScopeZero()1114 static int getScopeZero() { 1115 return SCOPE_ID_ZERO; 1116 } 1117 getScopeIfName()1118 static String getScopeIfName() { 1119 return NETWORK_IF_E1000G0; 1120 } 1121 1122 } 1123