/** * Return the value of the specified field as an IPv4 address. * * @param name The name of the field. * @return An {@link Ip4Network} instance. */ protected final Ip4Network getIp4Network(String name) { byte[] value = hdrFieldsMap.get(name); return (value == null) ? new Ip4Network(0) : new Ip4Network(value); }
/** * Create an Ethernet frame which contains an ARP request message to * probe the given IP address. * * @param src An {@link EtherAddress} instance to be used as the source * MAC address. * @param dst The destination MAC address. * @param addr The target IP address. * @return An Ethernet frame. {@code null} is returned if {@code addr} * is invalid. */ public Ethernet build(EtherAddress src, EtherAddress dst, InetAddress addr) { // IP address must be an IPv4 address. return (addr instanceof Inet4Address) ? build(src, dst, new Ip4Network(addr)) : null; }
/** * Create an {@link IpNetwork} instance which represents the IP network * specified by a pair of IP address and CIDR prefix. * * @param iaddr An {@link InetAddress} instance. * @param prefix Prefix length that specifies network range. * Note that zero means "no mask". So zero is treated as if * the maximum prefix length is specified. * @return An {@link IpNetwork} instance which represents the IP network * specified by the given IP address and CIDR prefix. * Note that {@code null} is returned if {@code iaddr} is * {@code null}. * @throws IllegalArgumentException * The given IP address or prefix is invalid. */ public static final IpNetwork create(InetAddress iaddr, int prefix) { if (iaddr instanceof Inet4Address) { return new Ip4Network(iaddr, prefix); } if (iaddr == null) { return null; } throw getUnsupportedAddressException(iaddr); }
/** * Create a new {@link Ip4Network} instance from the given MD-SAL * ipv4-address. * * @param ipv4 An {@link Ipv4Address} instance. * @return An {@link Ip4Network} instance on success. * {@code null} if {@code ipv4} is {@code null}. * @throws IllegalArgumentException * The given instance contains an invalid value. */ public static Ip4Network create(Ipv4Address ipv4) { Ip4Network ip4; if (ipv4 == null) { ip4 = null; } else { String addr = ipv4.getValue(); // Eliminate zone information. int idx = addr.lastIndexOf('%'); if (idx >= 0) { addr = addr.substring(0, idx); } ip4 = new Ip4Network(addr); } return ip4; }
/** * Construct a new {@link Ip4Network} instance which represents the IPv4 * network specified by the given {@link Ipv4Prefix} instance. * * @param ipp4 An {@link Ipv4Prefix} instance. * @param desc A brief description about the specified IP network. * @return An {@link Ip4Network} instance or {@code null}. * @throws RpcException * The given parameter is invalid. */ private Ip4Network getIp4Network(Ipv4Prefix ipp4, String desc) throws RpcException { if (ipp4 == null) { return null; } String value = ipp4.getValue(); if (value == null) { return null; } try { return new Ip4Network(value); } catch (RuntimeException e) { String msg = MiscUtils.joinColon(ipp4, e.getMessage()); throw invalidInetAddress(msg, desc, e); } }
src = new Ip4Network(addr); senderIp4Address = src; senderIp4Address = new Ip4Network(0);