41 import java.net.InetAddress;
42 import java.net.NetworkInterface;
43 import java.net.UnknownHostException;
44 import java.net.SocketException;
51 private final InetAddress
group;
53 private final NetworkInterface
interf;
81 String[] components = s.split(
"@");
82 if (components.length > 2)
83 throw new IllegalArgumentException(
"At most one '@' expected");
86 String target = components[0];
87 int len = components[0].length();
88 int colon = components[0].lastIndexOf(
':');
89 if ((colon < 1) || (colon > (len-2)))
90 throw new IllegalArgumentException(
"group:port expected");
91 String groupString = target.substring(0, colon);
94 port = Integer.parseInt(target.substring(colon+1, len));
95 }
catch (NumberFormatException x) {
96 throw new IllegalArgumentException(x);
100 if (groupString.charAt(0) ==
'[') {
101 len = groupString.length();
102 if (groupString.charAt(len-1) !=
']')
103 throw new IllegalArgumentException(
"missing ']'");
104 groupString = groupString.substring(1,len-1);
105 if (groupString.length() == 0)
106 throw new IllegalArgumentException(
"missing IPv6 address");
110 InetAddress
group =
null;
112 group = InetAddress.getByName(groupString);
113 }
catch (UnknownHostException x) {
114 throw new IllegalArgumentException(x);
116 if (!
group.isMulticastAddress()) {
117 throw new IllegalArgumentException(
"'" +
group.getHostAddress() +
118 "' is not multicast address");
122 NetworkInterface
interf =
null;
123 if (components.length == 2) {
125 interf = NetworkInterface.getByName(components[1]);
126 }
catch (SocketException x) {
127 throw new IllegalArgumentException(x);
130 throw new IllegalArgumentException(
"'" + components[1] +
131 "' is not valid interface");