+
+ /**
+ * Checks if the passed IP address in string form is a valid v4 or v6
+ * address. The address may specify a mask at the end as "/MMM"
+ *
+ * @param cidr
+ * the v4 or v6 address as IP/MMM
+ * @return
+ */
+ public static boolean isIPAddressValid(String cidr) {
+ return NetUtils.isIPv4AddressValid(cidr) || NetUtils.isIPv6AddressValid(cidr);
+ }
+
+ /*
+ * Following utilities are useful when you need to compare or bit shift java
+ * primitive type variable which are inherently signed
+ */
+ /**
+ * Returns the unsigned value of the passed byte variable
+ *
+ * @param b
+ * the byte value
+ * @return the int variable containing the unsigned byte value
+ */
+ public static int getUnsignedByte(byte b) {
+ return (b > 0) ? (int) b : (b & 0x7F | 0x80);
+ }
+
+ /**
+ * Return the unsigned value of the passed short variable
+ *
+ * @param s
+ * the short value
+ * @return the int variable containing the unsigned short value
+ */
+ public static int getUnsignedShort(short s) {
+ return (s > 0) ? (int) s : (s & 0x7FFF | 0x8000);
+ }
+
+ /**
+ * Returns the highest v4 or v6 InetAddress
+ *
+ * @param v6
+ * true for IPv6, false for Ipv4
+ * @return The highest IPv4 or IPv6 address
+ */
+ public static InetAddress gethighestIP(boolean v6) {
+ try {
+ return (v6) ? InetAddress.getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") : InetAddress
+ .getByName("255.255.255.255");
+ } catch (UnknownHostException e) {
+ return null;
+ }
+ }
+
+ /**
+ * Returns Broadcast MAC Address
+ *
+ * @return the byte array containing broadcaset mac address
+ */
+ public static byte[] getBroadcastMACAddr() {
+ return Arrays.copyOf(BroadcastMACAddr, BroadcastMACAddr.length);
+ }
+