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 Details

    • MAX_SOCKET_PATH_LENGTH

      public static final int MAX_SOCKET_PATH_LENGTH
      The maximum number of bytes a Unix domain socket path may have to fit into the sun_path member of the sockaddr_un structure of the operating system, excluding the terminating NUL character. The value is the largest capacity provided by any supported platform (Linux, whose sun_path has 108 bytes), so that isValid() never rejects a path that the operating system would accept. Platforms with a smaller sun_path - macOS and the BSDs provide 104 bytes - reject accordingly shorter paths when the socket is bound or connected, with a SocketException that reports the path as being too long.
      See Also:
  • Constructor Details

    • UnixDomainAddress

      public UnixDomainAddress()
      Creates an empty UnixDomainAddress instance.
    • UnixDomainAddress

      public UnixDomainAddress(Path unixDomainAddress)
      Creates a UnixDomainAddress instance from a given Unix domain socket path.
      Parameters:
      unixDomainAddress - the Unix domain socket path.
    • UnixDomainAddress

      public UnixDomainAddress(UnixDomainSocketAddress unixDomainAddress)
      Creates a UnixDomainAddress instance from a given Unix domain socket address.
      Parameters:
      unixDomainAddress - the Unix domain socket address.
  • Method Details

    • getUnixDomainAddress

      public UnixDomainSocketAddress getUnixDomainAddress()
      Retrieves the Unix domain socket address.
      Returns:
      the Unix domain socket address.
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface org.snmp4j.smi.Variable
      Specified by:
      equals in class org.snmp4j.smi.AbstractVariable
    • compareTo

      public int compareTo(org.snmp4j.smi.Variable variable)
      Specified by:
      compareTo in interface Comparable<org.snmp4j.smi.Variable>
      Specified by:
      compareTo in interface org.snmp4j.smi.Variable
      Specified by:
      compareTo in class org.snmp4j.smi.AbstractVariable
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface org.snmp4j.smi.Variable
      Specified by:
      hashCode in class org.snmp4j.smi.AbstractVariable
    • getBERLength

      public int getBERLength()
      Specified by:
      getBERLength in interface org.snmp4j.asn1.BERSerializable
      Specified by:
      getBERLength in class org.snmp4j.smi.AbstractVariable
    • decodeBER

      public void decodeBER(org.snmp4j.asn1.BERInputStream berInputStream) throws IOException
      Specified by:
      decodeBER in interface org.snmp4j.asn1.BERSerializable
      Specified by:
      decodeBER in class org.snmp4j.smi.AbstractVariable
      Throws:
      IOException
    • encodeBER

      public void encodeBER(OutputStream outputStream) throws IOException
      Specified by:
      encodeBER in interface org.snmp4j.asn1.BERSerializable
      Specified by:
      encodeBER in class org.snmp4j.smi.AbstractVariable
      Throws:
      IOException
    • getSyntax

      public int getSyntax()
      Specified by:
      getSyntax in interface org.snmp4j.smi.Variable
      Specified by:
      getSyntax in class org.snmp4j.smi.AbstractVariable
    • toString

      public String toString()
      Specified by:
      toString in interface org.snmp4j.smi.Variable
      Specified by:
      toString in class org.snmp4j.smi.AbstractVariable
    • toInt

      public int toInt()
      Specified by:
      toInt in interface org.snmp4j.smi.Variable
      Specified by:
      toInt in class org.snmp4j.smi.AbstractVariable
    • toLong

      public long toLong()
      Specified by:
      toLong in interface org.snmp4j.smi.Variable
      Specified by:
      toLong in class org.snmp4j.smi.AbstractVariable
    • clone

      public Object clone()
      Specified by:
      clone in interface org.snmp4j.smi.Variable
      Specified by:
      clone in class org.snmp4j.smi.AbstractVariable
    • toSubIndex

      public org.snmp4j.smi.OID toSubIndex(boolean impliedLength)
      Specified by:
      toSubIndex in interface org.snmp4j.smi.Variable
      Specified by:
      toSubIndex in class org.snmp4j.smi.AbstractVariable
    • fromSubIndex

      public void fromSubIndex(org.snmp4j.smi.OID oid, boolean b)
      Specified by:
      fromSubIndex in interface org.snmp4j.smi.Variable
      Specified by:
      fromSubIndex in class org.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: use isBindable() for an address to listen on and isConnectable() for an address to send to.
      Returns:
      true if this address has a non-empty socket path whose length does not exceed MAX_SOCKET_PATH_LENGTH, false otherwise.
    • 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:
      true if this address is valid and its socket file can be created in an existing and writable directory, false otherwise.
    • 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:
      true if this address is valid and its socket file exists and is writable, false otherwise.
    • getParentDirectory

      public Path 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 null if this address has no path or its path denotes a file system root.
    • parseAddress

      public boolean parseAddress(String s)
    • setValue

      public void setValue(String s)
    • setValue

      public void setValue(byte[] bytes)
    • toByteArray

      public byte[] toByteArray()
    • getPath

      public Path getPath()
      Retrieves the Unix domain socket path.
      Returns:
      the Unix domain socket path.
    • getFamily

      public ProtocolFamily getFamily()
    • getSocketAddress

      public SocketAddress getSocketAddress()