author | jjg |
Wed, 04 Jan 2017 18:33:20 -0800 | |
changeset 43029 | 1cd1c816581e |
parent 30810 | cbb29036f026 |
child 45122 | 8cfb711b103b |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 4742177 |
|
27 |
* @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code |
|
28 |
*/ |
|
29 |
import java.net.*; |
|
30 |
import java.util.*; |
|
31 |
||
32 |
||
33 |
public class SetOutgoingIf { |
|
34 |
private static int PORT = 9001; |
|
35 |
private static String osname; |
|
36 |
||
37 |
static boolean isWindows() { |
|
38 |
if (osname == null) |
|
39 |
osname = System.getProperty("os.name"); |
|
40 |
return osname.contains("Windows"); |
|
41 |
} |
|
42 |
||
43 |
private static boolean hasIPv6() throws Exception { |
|
44 |
List<NetworkInterface> nics = Collections.list( |
|
45 |
NetworkInterface.getNetworkInterfaces()); |
|
46 |
for (NetworkInterface nic : nics) { |
|
47 |
List<InetAddress> addrs = Collections.list(nic.getInetAddresses()); |
|
48 |
for (InetAddress addr : addrs) { |
|
49 |
if (addr instanceof Inet6Address) |
|
50 |
return true; |
|
51 |
} |
|
52 |
} |
|
53 |
||
54 |
return false; |
|
55 |
} |
|
56 |
||
57 |
public static void main(String[] args) throws Exception { |
|
58 |
if (isWindows()) { |
|
59 |
System.out.println("The test only run on non-Windows OS. Bye."); |
|
60 |
return; |
|
61 |
} |
|
62 |
||
63 |
if (!hasIPv6()) { |
|
64 |
System.out.println("No IPv6 available. Bye."); |
|
65 |
return; |
|
66 |
} |
|
67 |
||
68 |
// We need 2 or more network interfaces to run the test |
|
69 |
// |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
70 |
List<NetIf> netIfs = new ArrayList<NetIf>(); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
71 |
int index = 1; |
2 | 72 |
for (NetworkInterface nic : Collections.list(NetworkInterface.getNetworkInterfaces())) { |
3945 | 73 |
// we should use only network interfaces with multicast support which are in "up" state |
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
74 |
if (!nic.isLoopback() && nic.supportsMulticast() && nic.isUp()) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
75 |
NetIf netIf = NetIf.create(nic); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
76 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
77 |
// now determine what (if any) type of addresses are assigned to this interface |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
78 |
for (InetAddress addr : Collections.list(nic.getInetAddresses())) { |
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
79 |
if (addr.isAnyLocalAddress()) |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
80 |
continue; |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
81 |
|
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
82 |
System.out.println(" addr " + addr); |
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
83 |
if (addr instanceof Inet4Address) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
84 |
netIf.ipv4Address(true); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
85 |
} else if (addr instanceof Inet6Address) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
86 |
netIf.ipv6Address(true); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
87 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
88 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
89 |
if (netIf.ipv4Address() || netIf.ipv6Address()) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
90 |
netIf.index(index++); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
91 |
netIfs.add(netIf); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
92 |
debug("Using: " + nic); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
93 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
94 |
} |
2 | 95 |
} |
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
96 |
if (netIfs.size() <= 1) { |
2 | 97 |
System.out.println("Need 2 or more network interfaces to run. Bye."); |
98 |
return; |
|
99 |
} |
|
100 |
||
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
101 |
// We will send packets to one ipv4, and one ipv6 |
2 | 102 |
// multicast group using each network interface :- |
103 |
// 224.1.1.1 --| |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
104 |
// ff02::1:1 --|--> using network interface #1 |
2 | 105 |
// 224.1.2.1 --| |
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
106 |
// ff02::1:2 --|--> using network interface #2 |
2 | 107 |
// and so on. |
108 |
// |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
109 |
for (NetIf netIf : netIfs) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
110 |
int NetIfIndex = netIf.index(); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
111 |
List<InetAddress> groups = new ArrayList<InetAddress>(); |
2 | 112 |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
113 |
if (netIf.ipv4Address()) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
114 |
InetAddress groupv4 = InetAddress.getByName("224.1." + NetIfIndex + ".1"); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
115 |
groups.add(groupv4); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
116 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
117 |
if (netIf.ipv6Address()) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
118 |
InetAddress groupv6 = InetAddress.getByName("ff02::1:" + NetIfIndex); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
119 |
groups.add(groupv6); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
120 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
121 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
122 |
debug("Adding " + groups + " groups for " + netIf.nic().getName()); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
123 |
netIf.groups(groups); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
124 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
125 |
// use a separated thread to send to those 2 groups |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
126 |
Thread sender = new Thread(new Sender(netIf, |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
127 |
groups, |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
128 |
PORT)); |
2 | 129 |
sender.setDaemon(true); // we want sender to stop when main thread exits |
130 |
sender.start(); |
|
131 |
} |
|
132 |
||
133 |
// try to receive on each group, then check if the packet comes |
|
134 |
// from the expected network interface |
|
135 |
// |
|
136 |
byte[] buf = new byte[1024]; |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
137 |
for (NetIf netIf : netIfs) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
138 |
NetworkInterface nic = netIf.nic(); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
139 |
for (InetAddress group : netIf.groups()) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
140 |
MulticastSocket mcastsock = new MulticastSocket(PORT); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
141 |
mcastsock.setSoTimeout(5000); // 5 second |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
142 |
DatagramPacket packet = new DatagramPacket(buf, 0, buf.length); |
2 | 143 |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
144 |
// the interface supports the IP multicast group |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
145 |
debug("Joining " + group + " on " + nic.getName()); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
146 |
mcastsock.joinGroup(new InetSocketAddress(group, PORT), nic); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
147 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
148 |
try { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
149 |
mcastsock.receive(packet); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
150 |
debug("received packet on " + packet.getAddress()); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
151 |
} catch (Exception e) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
152 |
// test failed if any exception |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
153 |
throw new RuntimeException(e); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
154 |
} |
2 | 155 |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
156 |
// now check which network interface this packet comes from |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
157 |
NetworkInterface from = NetworkInterface.getByInetAddress(packet.getAddress()); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
158 |
NetworkInterface shouldbe = nic; |
30810
cbb29036f026
8077377: java/net/MulticastSocket/SetOutgoingIf.java fails intermittently with NullPointerException
msheppar
parents:
7668
diff
changeset
|
159 |
if (from != null) { |
cbb29036f026
8077377: java/net/MulticastSocket/SetOutgoingIf.java fails intermittently with NullPointerException
msheppar
parents:
7668
diff
changeset
|
160 |
if (!from.equals(shouldbe)) { |
cbb29036f026
8077377: java/net/MulticastSocket/SetOutgoingIf.java fails intermittently with NullPointerException
msheppar
parents:
7668
diff
changeset
|
161 |
System.out.println("Packets on group " |
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
162 |
+ group + " should come from " |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
163 |
+ shouldbe.getName() + ", but came from " |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
164 |
+ from.getName()); |
30810
cbb29036f026
8077377: java/net/MulticastSocket/SetOutgoingIf.java fails intermittently with NullPointerException
msheppar
parents:
7668
diff
changeset
|
165 |
} |
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
166 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
167 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
168 |
mcastsock.leaveGroup(new InetSocketAddress(group, PORT), nic); |
2 | 169 |
} |
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
170 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
171 |
} |
2 | 172 |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
173 |
private static boolean debug = true; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
174 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
175 |
static void debug(String message) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
176 |
if (debug) |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
177 |
System.out.println(message); |
2 | 178 |
} |
179 |
} |
|
180 |
||
181 |
class Sender implements Runnable { |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
182 |
private NetIf netIf; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
183 |
private List<InetAddress> groups; |
2 | 184 |
private int port; |
185 |
||
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
186 |
public Sender(NetIf netIf, |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
187 |
List<InetAddress> groups, |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
188 |
int port) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
189 |
this.netIf = netIf; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
190 |
this.groups = groups; |
2 | 191 |
this.port = port; |
192 |
} |
|
193 |
||
194 |
public void run() { |
|
195 |
try { |
|
196 |
MulticastSocket mcastsock = new MulticastSocket(); |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
197 |
mcastsock.setNetworkInterface(netIf.nic()); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
198 |
List<DatagramPacket> packets = new LinkedList<DatagramPacket>(); |
2 | 199 |
|
200 |
byte[] buf = "hello world".getBytes(); |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
201 |
for (InetAddress group : groups) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
202 |
packets.add(new DatagramPacket(buf, buf.length, new InetSocketAddress(group, port))); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
203 |
} |
2 | 204 |
|
205 |
for (;;) { |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
206 |
for (DatagramPacket packet : packets) |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
207 |
mcastsock.send(packet); |
2 | 208 |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
209 |
Thread.sleep(1000); // sleep 1 second |
2 | 210 |
} |
211 |
} catch (Exception e) { |
|
212 |
throw new RuntimeException(e); |
|
213 |
} |
|
214 |
} |
|
215 |
} |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
216 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
217 |
@SuppressWarnings("unchecked") |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
218 |
class NetIf { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
219 |
private boolean ipv4Address; //false |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
220 |
private boolean ipv6Address; //false |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
221 |
private int index; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
222 |
List<InetAddress> groups = Collections.EMPTY_LIST; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
223 |
private final NetworkInterface nic; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
224 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
225 |
private NetIf(NetworkInterface nic) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
226 |
this.nic = nic; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
227 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
228 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
229 |
static NetIf create(NetworkInterface nic) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
230 |
return new NetIf(nic); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
231 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
232 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
233 |
NetworkInterface nic() { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
234 |
return nic; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
235 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
236 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
237 |
boolean ipv4Address() { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
238 |
return ipv4Address; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
239 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
240 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
241 |
void ipv4Address(boolean ipv4Address) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
242 |
this.ipv4Address = ipv4Address; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
243 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
244 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
245 |
boolean ipv6Address() { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
246 |
return ipv6Address; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
247 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
248 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
249 |
void ipv6Address(boolean ipv6Address) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
250 |
this.ipv6Address = ipv6Address; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
251 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
252 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
253 |
int index() { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
254 |
return index; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
255 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
256 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
257 |
void index(int index) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
258 |
this.index = index; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
259 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
260 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
261 |
List<InetAddress> groups() { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
262 |
return groups; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
263 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
264 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
265 |
void groups(List<InetAddress> groups) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
266 |
this.groups = groups; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
267 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
268 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
269 |