Class UnixDomainAddress
java.lang.Object
org.snmp4j.smi.AbstractVariable
org.snmp4j.smi.SMIAddress
org.snmp4j.transport.unix.UnixDomainAddress
- All Implemented Interfaces:
Serializable, Cloneable, Comparable<org.snmp4j.smi.Variable>, org.snmp4j.asn1.BERSerializable, org.snmp4j.smi.Address, org.snmp4j.smi.AssignableFromByteArray, org.snmp4j.smi.AssignableFromString, org.snmp4j.smi.Variable
public class UnixDomainAddress
extends org.snmp4j.smi.SMIAddress
Represents an address for communication using Unix domain sockets.
This class provides utilities for working with Unix domain socket addresses,
such as parsing, validation, and encoding/decoding in BER format.
It extends the
SMIAddress class, inheriting SNMP-related behaviors
while focusing on Unix-specific socket address functionalities.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe maximum number of bytes a Unix domain socket path may have to fit into thesun_pathmember of thesockaddr_unstructure of the operating system, excluding the terminating NUL character.Fields inherited from class org.snmp4j.smi.AbstractVariable
SMISYNTAXES_PROPERTIES -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty UnixDomainAddress instance.UnixDomainAddress(UnixDomainSocketAddress unixDomainAddress) Creates a UnixDomainAddress instance from a given Unix domain socket address.UnixDomainAddress(Path unixDomainAddress) Creates a UnixDomainAddress instance from a given Unix domain socket path. -
Method Summary
Modifier and TypeMethodDescriptionclone()intcompareTo(org.snmp4j.smi.Variable variable) voiddecodeBER(org.snmp4j.asn1.BERInputStream berInputStream) voidencodeBER(OutputStream outputStream) booleanvoidfromSubIndex(org.snmp4j.smi.OID oid, boolean b) intGets the directory that contains (or, for an address to be bound, will contain) the socket file of this address.getPath()Retrieves the Unix domain socket path.intRetrieves the Unix domain socket address.inthashCode()booleanChecks whether the current process is permitted to bind (i.e. listen on) this address.booleanChecks whether the current process is permitted to connect to this address.booleanisValid()Checks whether this address has a socket path that can be used as a Unix domain socket path.booleanvoidsetValue(byte[] bytes) voidbyte[]inttoInt()longtoLong()toString()org.snmp4j.smi.OIDtoSubIndex(boolean impliedLength) Methods inherited from class org.snmp4j.smi.AbstractVariable
createFromBER, createFromSyntax, equal, getBERPayloadLength, getSyntaxFromString, getSyntaxFromStringOrNull, getSyntaxString, getSyntaxString, isDynamic, isExceptionMethods inherited from interface org.snmp4j.smi.Address
isTransportCompatible
-
Field Details
-
MAX_SOCKET_PATH_LENGTH
public static final int MAX_SOCKET_PATH_LENGTHThe maximum number of bytes a Unix domain socket path may have to fit into thesun_pathmember of thesockaddr_unstructure of the operating system, excluding the terminating NUL character. The value is the largest capacity provided by any supported platform (Linux, whosesun_pathhas 108 bytes), so thatisValid()never rejects a path that the operating system would accept. Platforms with a smallersun_path- macOS and the BSDs provide 104 bytes - reject accordingly shorter paths when the socket is bound or connected, with aSocketExceptionthat reports the path as being too long.- See Also:
-
-
Constructor Details
-
UnixDomainAddress
public UnixDomainAddress()Creates an empty UnixDomainAddress instance. -
UnixDomainAddress
Creates a UnixDomainAddress instance from a given Unix domain socket path.- Parameters:
unixDomainAddress- the Unix domain socket path.
-
UnixDomainAddress
Creates a UnixDomainAddress instance from a given Unix domain socket address.- Parameters:
unixDomainAddress- the Unix domain socket address.
-
-
Method Details
-
getUnixDomainAddress
Retrieves the Unix domain socket address.- Returns:
- the Unix domain socket address.
-
equals
- Specified by:
equalsin interfaceorg.snmp4j.smi.Variable- Specified by:
equalsin classorg.snmp4j.smi.AbstractVariable
-
compareTo
public int compareTo(org.snmp4j.smi.Variable variable) - Specified by:
compareToin interfaceComparable<org.snmp4j.smi.Variable>- Specified by:
compareToin interfaceorg.snmp4j.smi.Variable- Specified by:
compareToin classorg.snmp4j.smi.AbstractVariable
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceorg.snmp4j.smi.Variable- Specified by:
hashCodein classorg.snmp4j.smi.AbstractVariable
-
getBERLength
public int getBERLength()- Specified by:
getBERLengthin interfaceorg.snmp4j.asn1.BERSerializable- Specified by:
getBERLengthin classorg.snmp4j.smi.AbstractVariable
-
decodeBER
- Specified by:
decodeBERin interfaceorg.snmp4j.asn1.BERSerializable- Specified by:
decodeBERin classorg.snmp4j.smi.AbstractVariable- Throws:
IOException
-
encodeBER
- Specified by:
encodeBERin interfaceorg.snmp4j.asn1.BERSerializable- Specified by:
encodeBERin classorg.snmp4j.smi.AbstractVariable- Throws:
IOException
-
getSyntax
public int getSyntax()- Specified by:
getSyntaxin interfaceorg.snmp4j.smi.Variable- Specified by:
getSyntaxin classorg.snmp4j.smi.AbstractVariable
-
toString
- Specified by:
toStringin interfaceorg.snmp4j.smi.Variable- Specified by:
toStringin classorg.snmp4j.smi.AbstractVariable
-
toInt
public int toInt()- Specified by:
toIntin interfaceorg.snmp4j.smi.Variable- Specified by:
toIntin classorg.snmp4j.smi.AbstractVariable
-
toLong
public long toLong()- Specified by:
toLongin interfaceorg.snmp4j.smi.Variable- Specified by:
toLongin classorg.snmp4j.smi.AbstractVariable
-
clone
- Specified by:
clonein interfaceorg.snmp4j.smi.Variable- Specified by:
clonein classorg.snmp4j.smi.AbstractVariable
-
toSubIndex
public org.snmp4j.smi.OID toSubIndex(boolean impliedLength) - Specified by:
toSubIndexin interfaceorg.snmp4j.smi.Variable- Specified by:
toSubIndexin classorg.snmp4j.smi.AbstractVariable
-
fromSubIndex
public void fromSubIndex(org.snmp4j.smi.OID oid, boolean b) - Specified by:
fromSubIndexin interfaceorg.snmp4j.smi.Variable- Specified by:
fromSubIndexin classorg.snmp4j.smi.AbstractVariable
-
isValid
public boolean isValid()Checks whether this address has a socket path that can be used as a Unix domain socket path. Whether the current process is permitted to use that socket is not checked here, because the necessary permissions depend on the role of the address: useisBindable()for an address to listen on andisConnectable()for an address to send to.- Returns:
trueif this address has a non-empty socket path whose length does not exceedMAX_SOCKET_PATH_LENGTH,falseotherwise.
-
isBindable
public boolean isBindable()Checks whether the current process is permitted to bind (i.e. listen on) this address. Binding creates the socket file, thus the directory that contains it needs to exist and the process needs write and search (execute) permission on it. A socket file that already exists needs to be removed before the socket can be bound, which requires the same permissions.The result is a snapshot of the current file system state and the effective permissions of the current process. It can change before the socket is actually bound, therefore a failing bind operation has to be handled regardless of the result of this method.
- Returns:
trueif this address isvalidand its socket file can be created in an existing and writable directory,falseotherwise.
-
isConnectable
public boolean isConnectable()Checks whether the current process is permitted to connect to this address. Connecting to a Unix domain socket requires write permission on the socket file itself - unlike binding it, it does not require write permission on the directory that contains the socket file. Read permission is not needed.The result is a snapshot of the current file system state and the effective permissions of the current process. It can change before the socket is actually connected, therefore a failing connect operation has to be handled regardless of the result of this method.
- Returns:
trueif this address isvalidand its socket file exists and is writable,falseotherwise.
-
getParentDirectory
Gets the directory that contains (or, for an address to be bound, will contain) the socket file of this address. A relative socket path is resolved against the current working directory of the JVM.- Returns:
- the parent directory of the socket path, or
nullif this address has no path or its path denotes a file system root.
-
parseAddress
-
setValue
-
setValue
public void setValue(byte[] bytes) -
toByteArray
public byte[] toByteArray() -
getPath
-
getFamily
-
getSocketAddress
-