/** * {@inheritDoc} */ @Override public String getHostAddress() { String addr = networkAddress; if (addr == null) { addr = getInetAddress().getHostAddress(); networkAddress = addr; } return addr; }
/** * Create an {@link InetAddress} instance which represents the IPv4 address * specified by the given integer value. * * @param addr An integer value which represents the IPv4 address. * @return An {@link InetAddress} instance. */ public static InetAddress getInetAddress(int addr) { return getInetAddress(NumberUtils.toBytes(addr)); }
/** * Return an {@link InetAddress} instance which represents the IPv4 netmask * specified by the given prefix length. * * @param length The IPv4 prefix length. * Note that zero means "no mask". So zero is treated as if * the maximum prefix length is specified. * @return An {@link InetAddress} instance. * @throws IllegalArgumentException * The given prefix length is invalid. */ public static InetAddress getInetMask(int length) { return getInetAddress(getNetMask(length)); }
/** * {@inheritDoc} */ @Override InetAddress init(InetAddress iaddr, int prefix) { int addr = NumberUtils.toInteger(iaddr.getAddress()); int mask = getNetMask(prefix); int maskedAddr = addr & mask; address = maskedAddr; netMask = mask; return getInetAddress(maskedAddr); }
/** * Create an IPv4 network address from the given IPv4 address and * prefix length. * * @param iaddr An {@link InetAddress} instance. * @param length The IPv4 prefix length. * Note that zero means "no mask". So zero is treated as if * the maximum prefix length is specified. * @return An {@link InetAddress} instance which represents the IPv4 * network address specified by the given pair of IPv4 address and * prefix length. * @throws NullPointerException * {@code iaddr} is {@code null}. * @throws IllegalArgumentException * The given IPv4 address or prefix length is invalid. */ public static InetAddress getNetworkAddress(InetAddress iaddr, int length) { int addr = NumberUtils.toInteger(iaddr.getAddress()); int mask = getNetMask(length); return getInetAddress(addr & mask); }