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