public final class NetworkUtil extends Object
| Constructor and Description |
|---|
NetworkUtil() |
| Modifier and Type | Method and Description |
|---|---|
static ByteBuffer |
allocateDirectAlignedAndPadded(int capacity,
int alignment)
Allocate a direct
ByteBuffer that is padded at the end with at least alignment bytes. |
static NetworkInterface[] |
filterBySubnet(InetAddress address,
int subnetPrefix)
Search for a list of network interfaces that match the specified address and subnet prefix.
|
static InetAddress |
findFirstMatchingLocalAddress(InetAddress address)
Scans through to the local interfaces and returns the first bound InetAddress that matches the locally
defined address and network mask.
|
static String |
formatAddressAndPort(InetAddress address,
int port)
Format an address and port pair, so they can be used in a URI endpoint.
|
static ProtocolFamily |
getProtocolFamily(InetAddress address)
Get the
ProtocolFamily to which the address belongs. |
static boolean |
isMatchWithPrefix(byte[] candidate,
byte[] expected,
int prefixLength)
Matches to network address with the specified prefix length.
|
public static NetworkInterface[] filterBySubnet(InetAddress address, int subnetPrefix) throws SocketException
InterfaceAddress.getNetworkPrefixLength()). If no results match, then the collection
will be empty.address - to search for on the NetworkInterfaces.subnetPrefix - to limit the search.NetworkInterfaces that match the supplied criteria, ordered by the length
of the subnet prefix. Empty if none match.SocketException - if an error occurspublic static ByteBuffer allocateDirectAlignedAndPadded(int capacity, int alignment)
ByteBuffer that is padded at the end with at least alignment bytes.capacity - for the buffer.alignment - for the buffer.ByteBuffer.public static String formatAddressAndPort(InetAddress address, int port)
address - part of the endpoint.port - part of the endpoint.public static ProtocolFamily getProtocolFamily(InetAddress address)
ProtocolFamily to which the address belongs.address - to get the ProtocolFamily for.ProtocolFamily to which the address belongs.public static InetAddress findFirstMatchingLocalAddress(InetAddress address) throws SocketException
address - used to scan for a matching local addressSocketException - if an underlying SocketException is thrown, e.g. when getting the network interfaces.public static boolean isMatchWithPrefix(byte[] candidate,
byte[] expected,
int prefixLength)
candidate - address to be matchedexpected - address to match against (could be a network address - with 0s at the end)prefixLength - the number of bit required to match.Copyright © 2014-2023 Real Logic Limited. All Rights Reserved.