Java IP Address Get getIPv4MulticastGroup(int hash)

Here you can find the source of getIPv4MulticastGroup(int hash)

Description

get I Pv Multicast Group

License

Apache License

Declaration

public static InetAddress getIPv4MulticastGroup(int hash) throws UnknownHostException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.InetAddress;

import java.net.UnknownHostException;

public class Main {
    public static int[] IPV4_MULTICAST_ALLOCATION_RANGE = new int[] { /* low */ 0xE1000000, /* high */ 0xEFFFFFFF };

    public static InetAddress getIPv4MulticastGroup(int hash) throws UnknownHostException {
        return getIPv4MulticastGroup(hash, IPV4_MULTICAST_ALLOCATION_RANGE[0], IPV4_MULTICAST_ALLOCATION_RANGE[1]);
    }/*  w  ww  .j  av a 2 s  .c  o m*/

    public static InetAddress getIPv4MulticastGroup(int hash, int lowIp, int highIp) throws UnknownHostException {
        hash = hash & 0x7fffffff; // delete sign
        int port = (hash % (highIp - lowIp + 1)) + lowIp;
        byte[] ip = new byte[4];
        for (int i = 0; i < 4; i++)
            ip[i] = (byte) (port >>> ((3 - i) << 3));
        return InetAddress.getByAddress(ip);
    }
}

Related

  1. getIPs()
  2. getIPv4Address()
  3. getIPV4Address(List addresses)
  4. getIPv4Address(NetworkInterface iface)
  5. getIPV4MainAddress(NetworkInterface ni)
  6. getIPV4NetwprkOrder(String theIp)
  7. getIPV6AddrArray(String s)
  8. getIPV6AllAddresses(NetworkInterface ni)
  9. getIpv6List()