1
1
/*
2
- * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -63,9 +63,25 @@ public Object[][] positive() throws Exception {
63
63
InetAddress .getLoopbackAddress ());
64
64
List <Object []> list = new ArrayList <>();
65
65
NetworkConfiguration nc = NetworkConfiguration .probe ();
66
+ // retains only network interface whose bound addresses match
66
67
addrs .stream ().forEach (a -> nc .multicastInterfaces (true )
67
- .map (nif -> new Object [] { new InetSocketAddress (a , 0 ), nif })
68
- .forEach (list ::add ) );
68
+ .filter (nif -> nif .inetAddresses ().toList ().contains (a ))
69
+ .map (nif -> new Object [] { new InetSocketAddress (a , 0 ), nif })
70
+ .forEach (list ::add ) );
71
+ // any network interface should work with the wildcard address
72
+ nc .multicastInterfaces (true )
73
+ .map (nif -> new Object [] {new InetSocketAddress (0 ), nif })
74
+ .forEach (list ::add );
75
+ return list .stream ().toArray (Object [][]::new );
76
+ }
77
+
78
+ @ DataProvider (name = "interfaces" )
79
+ public Object [][] interfaces () throws Exception {
80
+ List <Object []> list = new ArrayList <>();
81
+ NetworkConfiguration nc = NetworkConfiguration .probe ();
82
+ nc .multicastInterfaces (true )
83
+ .map (nif -> new Object [] {nif })
84
+ .forEach (list ::add );
69
85
70
86
return list .stream ().toArray (Object [][]::new );
71
87
}
@@ -82,8 +98,8 @@ public void testSetGetInterfaceBound(InetSocketAddress bindAddr, NetworkInterfac
82
98
}
83
99
}
84
100
85
- @ Test (dataProvider = "scenarios " )
86
- public void testSetGetInterfaceUnbound (InetSocketAddress ignore , NetworkInterface nif )
101
+ @ Test (dataProvider = "interfaces " )
102
+ public void testSetGetInterfaceUnbound (NetworkInterface nif )
87
103
throws Exception
88
104
{
89
105
out .println (format ("\n \n --- testSetGetInterfaceUnbound nif=[%s]" , nif ));
@@ -106,8 +122,8 @@ public void testSetGetOptionBound(InetSocketAddress bindAddr, NetworkInterface n
106
122
}
107
123
}
108
124
109
- @ Test (dataProvider = "scenarios " )
110
- public void testSetGetOptionUnbound (InetSocketAddress ignore , NetworkInterface nif )
125
+ @ Test (dataProvider = "interfaces " )
126
+ public void testSetGetOptionUnbound (NetworkInterface nif )
111
127
throws Exception
112
128
{
113
129
out .println (format ("\n \n --- testSetGetOptionUnbound nif=[%s]" , nif ));
@@ -139,8 +155,8 @@ public void testGetInterfaceBound(InetSocketAddress bindAddr)
139
155
}
140
156
141
157
@ Test
142
- public void testGettInterfaceUnbound () throws Exception {
143
- out .println ("\n \n --- testGettInterfaceUnbound " );
158
+ public void testGetInterfaceUnbound () throws Exception {
159
+ out .println ("\n \n --- testGetInterfaceUnbound " );
144
160
try (MulticastSocket ms = new MulticastSocket ()) {
145
161
assertPlaceHolder (ms .getNetworkInterface ());
146
162
}
0 commit comments