private void checkMulticastAddress(InetAddress multicastAddress) { if (!multicastAddress.isMulticastAddress()) { String message = "Invalid multicast address " + multicastAddress; if (!(multicastAddress instanceof Inet4Address)) { throw new IllegalArgumentException(message + ", " + "ipv4 multicast address scope: 224.0.0.0 - 239.255.255.255."); } else { throw new IllegalArgumentException(message + ", " + "ipv6 multicast address must start with ff, " + "for example: ff01::1"); } } }
private void checkMulticastAddress(InetAddress multicastAddress) { if (!multicastAddress.isMulticastAddress()) { String message = "Invalid multicast address " + multicastAddress; if (!(multicastAddress instanceof Inet4Address)) { throw new IllegalArgumentException(message + ", " + "ipv4 multicast address scope: 224.0.0.0 - 239.255.255.255."); } else { throw new IllegalArgumentException(message + ", " + "ipv6 multicast address must start with ff, " + "for example: ff01::1"); } } }
/** Returns true if this is a multicast address:port */ public boolean isMcastId() { return this.host.isMulticastAddress(); }
private static int scoreAddress(InetAddress addr) { if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) { return 0; } if (addr.isMulticastAddress()) { return 1; } if (addr.isLinkLocalAddress()) { return 2; } if (addr.isSiteLocalAddress()) { return 3; } return 4; }
public UDPChannelHandler setMulticastAddress(InetAddress multicastAddress) { if (!multicastAddress.isMulticastAddress()) { throw new IllegalArgumentException(multicastAddress + "not a multicastAddress"); } this.multicastAddress = multicastAddress; return this; }
private static int scoreAddress(InetAddress addr) { if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) { return 0; } if (addr.isMulticastAddress()) { return 1; } if (addr.isLinkLocalAddress()) { return 2; } if (addr.isSiteLocalAddress()) { return 3; } return 4; }
private static boolean isGoodV6Address(InetAddress address) { return address instanceof Inet6Address && !address.isAnyLocalAddress() && !address.isLoopbackAddress() && !address.isMulticastAddress(); }
private static boolean isGoodV4Address(InetAddress address) { return address instanceof Inet4Address && !address.isAnyLocalAddress() && !address.isLoopbackAddress() && !address.isMulticastAddress(); }
private String getDefaultAddress() { Enumeration<NetworkInterface> nets; try { nets = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e) { return null; } NetworkInterface netinf; while (nets.hasMoreElements()) { netinf = nets.nextElement(); Enumeration<InetAddress> addresses = netinf.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); if (!address.isAnyLocalAddress() && !address.isMulticastAddress() && !(address instanceof Inet6Address)) { return address.getHostAddress(); } } } return null; }
/** * @return Get default interface to use since the user hasn't specified one. */ protected String getDefaultAddress() { Enumeration<NetworkInterface> nets; try { nets = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e) { return null; } NetworkInterface netinf; while (nets.hasMoreElements()) { netinf = nets.nextElement(); Enumeration<InetAddress> addresses = netinf.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); if (!address.isAnyLocalAddress() && !address.isMulticastAddress() && !(address instanceof Inet6Address)) { return address.getHostAddress(); } } } return null; }
private static int scoreAddress(InetAddress addr) { if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) { return 0; } if (addr.isMulticastAddress()) { return 1; } if (addr.isLinkLocalAddress()) { return 2; } if (addr.isSiteLocalAddress()) { return 3; } return 4; }
private void checkJoinOrLeave(InetAddress groupAddr) throws IOException { checkOpen(); if (!groupAddr.isMulticastAddress()) { throw new IOException("Not a multicast group: " + groupAddr); } }
@ConfigAttributeChecker(name = MCAST_ADDRESS) protected InetAddress checkMcastAddress(InetAddress value) { if (!value.isMulticastAddress()) { throw new IllegalArgumentException( String.format("Could not set %s to %s because it was not a multicast address.", MCAST_ADDRESS, value)); } return value; }
public MulticastListener( final int numThreads, final InetSocketAddress multicastAddress, final MulticastConfiguration configuration) { if (numThreads <= 0) { throw new IllegalArgumentException("Number of threads may not be less than or equal to zero."); } else if (multicastAddress == null) { throw new IllegalArgumentException("Multicast address may not be null."); } else if (multicastAddress.getAddress().isMulticastAddress() == false) { throw new IllegalArgumentException("Multicast group must be a Class D address."); } else if (configuration == null) { throw new IllegalArgumentException("Multicast configuration may not be null."); } this.numThreads = numThreads; this.multicastAddress = multicastAddress; this.configuration = configuration; }
private void checkJoinOrLeave(SocketAddress groupAddress, NetworkInterface netInterface) throws IOException { checkOpen(); if (groupAddress == null) { throw new IllegalArgumentException("groupAddress == null"); } if (netInterface != null && !netInterface.getInetAddresses().hasMoreElements()) { throw new SocketException("No address associated with interface: " + netInterface); } if (!(groupAddress instanceof InetSocketAddress)) { throw new IllegalArgumentException("Group address not an InetSocketAddress: " + groupAddress.getClass()); } InetAddress groupAddr = ((InetSocketAddress) groupAddress).getAddress(); if (groupAddr == null) { throw new SocketException("Group address has no address: " + groupAddress); } if (!groupAddr.isMulticastAddress()) { throw new IOException("Not a multicast group: " + groupAddr); } }
public static void setDefaultValues(List<Protocol> protocols) throws Exception { if(protocols == null) return; // check InetAddress related features of stack Collection<InetAddress> addrs=getInetAddresses(protocols); StackType ip_version=Util.getIpStackType(); // 0 = n/a, 4 = IPv4, 6 = IPv6 if(!addrs.isEmpty()) { // check that all user-supplied InetAddresses have a consistent version: // 1. If an addr is IPv6 and we have an IPv4 stack --> FAIL // 2. If an address is an IPv4 class D (multicast) address and the stack is IPv6: FAIL // Else pass for(InetAddress addr : addrs) { if(addr instanceof Inet6Address && ip_version == StackType.IPv4) throw new IllegalArgumentException("found IPv6 address " + addr + " in an IPv4 stack"); if(addr instanceof Inet4Address && addr.isMulticastAddress() && ip_version == StackType.IPv6) throw new Exception("found IPv4 multicast address " + addr + " in an IPv6 stack"); } } // process default values setDefaultValues(protocols, ip_version); }
@Override public long open(DataSpec dataSpec) throws UdpDataSourceException { uri = dataSpec.uri; String host = uri.getHost(); int port = uri.getPort(); transferInitializing(dataSpec); try { address = InetAddress.getByName(host); socketAddress = new InetSocketAddress(address, port); if (address.isMulticastAddress()) { multicastSocket = new MulticastSocket(socketAddress); multicastSocket.joinGroup(address); socket = multicastSocket; } else { socket = new DatagramSocket(socketAddress); } } catch (IOException e) { throw new UdpDataSourceException(e); } try { socket.setSoTimeout(socketTimeoutMillis); } catch (SocketException e) { throw new UdpDataSourceException(e); } opened = true; transferStarted(dataSpec); return C.LENGTH_UNSET; }
/** * Sets the multicast group. * * @param group the multicast group * @return the multicast configuration * @throws ConfigurationException if the group is invalid */ public MulticastConfig setGroup(String group) { try { InetAddress address = InetAddress.getByName(group); if (!address.isMulticastAddress()) { throw new ConfigurationException("Invalid multicast group " + group); } return setGroup(address); } catch (UnknownHostException e) { throw new ConfigurationException("Failed to locate multicast group", e); } }
private void selectAddresses() { for (InetAddress current : inetAddrs) { if (!current.isMulticastAddress()) { if (current instanceof Inet4Address) { best4 = selectBestAddress(best4, current); } else if (current instanceof Inet6Address) { best6 = selectBestAddress(best6, current); } } } nameAddr = selectBestAddress(best4, best6); }
private boolean computeH2O(boolean b) { H2ONode h2o = null; if( dataLo() != 0 ) { // Dead/initial packet InetAddress inet = addrPack(); if( !inet.isMulticastAddress() ) { // Is multicast? h2o = H2ONode.intern(inet,portPack()); if( isSend() && h2o == recoH2O() ) // Another multicast indicator: sending to self h2o = null; // Flag as multicast } } _packh2o = h2o; return b; // For flow-coding }