Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/NetworkInterface/NullMacAddress.java
41149 views
1
/*
2
* Copyright (c) 2020, 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
/* @test
25
* @bug 8059309
26
* @summary Test that querrying the mac address of the loopback interface
27
* returns null and doesn't throw a SocketException.
28
* @library /test/lib
29
* @run testng/othervm NullMacAddress
30
* @run testng/othervm -Djava.net.preferIPv6Addresses=true NullMacAddress
31
* @run testng/othervm -Djava.net.preferIPv4Stack=true NullMacAddress
32
*/
33
34
import org.testng.annotations.BeforeTest;
35
import org.testng.annotations.Test;
36
import static org.testng.Assert.*;
37
38
import java.io.UncheckedIOException;
39
import java.math.BigInteger;
40
import java.net.NetworkInterface;
41
import java.net.SocketException;
42
import java.util.Locale;
43
44
import jdk.test.lib.net.IPSupport;
45
46
public class NullMacAddress {
47
48
@BeforeTest
49
void setup() {
50
IPSupport.throwSkippedExceptionIfNonOperational();
51
}
52
53
@Test
54
public void testNetworkInterfaces() throws SocketException {
55
NetworkInterface.networkInterfaces().forEach(this::testMacAddress);
56
}
57
58
private void testMacAddress(NetworkInterface ni) {
59
try {
60
var name = ni.getDisplayName();
61
System.out.println("Testing: " + name);
62
var loopback = ni.isLoopback();
63
var macAddress = ni.getHardwareAddress();
64
var hdr = macAddress == null ? "null"
65
: "0x" + new BigInteger(1, macAddress)
66
.toString(16).toUpperCase(Locale.ROOT);
67
System.out.println(" MAC address: " + hdr + (loopback ? " (loopback)" : ""));
68
if (loopback) {
69
assertNull(macAddress, "Loopback interface \""
70
+ name + "\" doesn't have a null MAC Address");
71
}
72
} catch (SocketException ex) {
73
throw new UncheckedIOException(ex);
74
}
75
}
76
}
77
78
79