/** * 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)); }
/** * Determine whether the given value represents a zero short value or not. * * @param value A byte array that contains a short integer. * @return {@code true} only if the given value represents a zero. */ protected final boolean isZeroShort(byte[] value) { return (value == null || toShort(value) == 0); }
/** * Set the source port number. * * @param port A short integer value which indicates the source port. * @return An integer value which indicates the source port. */ private int setSourcePort(short port) { sourcePort = NumberUtils.getUnsigned(port); return sourcePort; }
/** * Return the MAC address to be set as a {@link MacAddress} instance. * * @return A {@link MacAddress} instance. */ public final MacAddress getMacAddress() { return address.getMacAddress(); }
/** * Create a new {@link EtherAddress} instance. * * @param mac A {@link MacAddress} instance. * @return An {@link EtherAddress} instance if {@code mac} is not * {@code null}. {@code null} if {@code mac} is {@code null}. * @throws IllegalArgumentException * The given instance contains an invalid value. */ public static EtherAddress create(MacAddress mac) { return (mac == null) ? null : new EtherAddress(mac); }
/** * Return the hash code of this object. * * @return The hash code. */ @Override public int hashCode() { return NumberUtils.hashCode(address); }
/** * Convert an integer value into an byte array. * * @param v An integer value. * @return A converted byte array. */ public static byte[] toBytes(int v) { byte[] b = new byte[NUM_OCTETS_INTEGER]; setInt(b, 0, v); return b; }
/** * Convert a short integer value into an byte array. * * @param v A short integer value. * @return A converted byte array. * @since Beryllium */ public static byte[] toBytes(short v) { byte[] b = new byte[NUM_OCTETS_SHORT]; setShort(b, 0, v); return b; }
/** * Construct a new instance. * * @param mac A byte array which represents a MAC address. * {@code null} and all-zeroed byte array are treated as * undefined value. * @param vlan VLAN ID. Only lower 12 bits in the value is used. */ public MacVlan(byte[] mac, int vlan) { this((mac == null) ? UNDEFINED : EtherAddress.toLong(mac), vlan); }
/** * Ensure that the given {@link IpNetwork} instance represents an * IPv4 address. * * @param ipn An {@link IpNetwork} instance. * @return {@code ipn} casted as {@link Ip4Network} if {@code ipn} * represents an IPv4 address. Otherwise {@code null}. */ public static Ip4Network toIp4Address(IpNetwork ipn) { return (ipn instanceof Ip4Network && ipn.isAddress()) ? (Ip4Network)ipn : null; }
/** * Construct a new 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. */ IpNetwork(int prefix) { prefixLength = (prefix == 0) ? getMaxPrefix() : prefix; }
/** * {@inheritDoc} */ @Override public int getEtherType() { return EtherTypes.IPV4.intValue(); }
/** * Return an IP protocol number assigned to this protocol. * * @param ver An {@link IpVersion} instance which describes the * IP version. * @return 6 is always returned. */ public short getInetProtocol(IpVersion ver) { return InetProtocols.TCP.shortValue(); }
/** * Set the ICMP type. * * @param value A byte integer value which indicates the ICMP type. * @return A short value which represents the given ICMP type. */ private short setType(byte value) { type = (short)NumberUtils.getUnsigned(value); return type; }
/** * Convert the given {@link EtherAddress} instance into a * {@link MacAddress} instance. * * @param ea An {@link EtherAddress} instance. * @return A {@link MacAddress} instance or null. */ private MacAddress encode(EtherAddress ea) { return (ea == null) ? null : ea.getMacAddress(); }
/** * Create a new {@link EtherAddress} instance. * * @param bytes A byte array which represents an ethernet address. * @return An {@link EtherAddress} instance if {@code bytes} is not * {@code null}. {@code null} if {@code bytes} is {@code null}. * @throws IllegalArgumentException * The length of {@code bytes} is not 6. */ public static EtherAddress create(byte[] bytes) { return (bytes == null) ? null : new EtherAddress(bytes); }
/** * Determine whether this instance represents an IP address or not. * * @return {@code true} if this instance represents an IP address. * {@code false} if this instance represents an IP network * specified by a pair of network address and prefix length. */ public final boolean isAddress() { return (prefixLength == getMaxPrefix()); }
/** * Set the destination port number. * * @param port A short integer value which indicates the destination * port. * @return An integer value which indicates the destination port. */ private int setDestinationPort(short port) { destinationPort = NumberUtils.getUnsigned(port); return destinationPort; }
/** * Construct a new instance. * * @param value A long value that indicates a datapath ID. */ public OfNode(long value) { nodeNumber = getUnsigned(value); }
/** * Set the ICMP code. * * @param value A byte integer value which indicates the ICMP code. * @return A short value which represents the given ICMP code. */ private short setCode(byte value) { code = (short)NumberUtils.getUnsigned(value); return code; }