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