Module org.jnetpcap
Package org.jnetpcap

Class SockAddr

java.lang.Object
org.jnetpcap.SockAddr
Direct Known Subclasses:
SockAddr.Inet6SockAddr, SockAddr.InetSockAddr, SockAddr.IpxSockAddr, SockAddr.IrdaSockAddr, SockAddr.LinkSockAddr, SockAddr.PacketSockAddr

public class SockAddr extends Object
The low level sockaddr structure containing an address of different types, depending on the protocol family value. The class is extended by specific subclasses which provide additional fields relating to each protocol address family (AF).

BSD style structure

 
 struct sockaddr {
    u_char sa_len;     // Total length of the structure
    u_char sa_family;  // Address family (e.g., AF_INET for IPv4)
    char   sa_data[14]; // Address data (actual size may vary)
   };
 
 

POSIX style structure

 
 struct sockaddr {
    u_short sa_family;  // Address family (e.g., AF_INET for IPv4)
    char    sa_data[14]; // Address data (actual size may vary)
   };
 
 
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    The structure of sockaddr_in6, used for IPv6 sockets.
    static final class 
    The structure of sockaddr_in, used for IPv4 sockets.
    static final class 
    The structure of sockaddr_ipx, used for AF_IPX sockets.
    static final class 
    The structure of sockaddr_irda, used with AF_IRDA sockets on windows (winsock2.h) to access link-layer information.
    static final class 
    The structure of sockaddr_dl, used with AF_LINK sockets on macOS to access link-layer information.
    static final class 
    The structure of sockaddr_ll, used with AF_PACKET sockets for raw packet access on Linux.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    Socket Address data (actual size may vary).
    int
    Address family (e.g., INET for IPv4)
    Gets the AF family value as a constant.
    boolean
    Checks if this AF address is of specifc family type.
    String representation of the structure field values.
    The total length of the socket address structure in bytes.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Method Details

    • data

      public byte[] data()
      Socket Address data (actual size may vary).
      Returns:
      the byte array containing socket raw data
    • family

      public int family()
      Address family (e.g., INET for IPv4)
      Returns:
      8 (BSD sockets) or 16 (Posix sockets) bit address family value
    • familyConstant

      public Optional<SockAddrFamily> familyConstant()
      Gets the AF family value as a constant.
      Returns:
      the socket address family constant
      Throws:
      IllegalArgumentException - thrown if the constant for the family value is not found.
    • isFamily

      public boolean isFamily(SockAddrFamily family)
      Checks if this AF address is of specifc family type.
      Parameters:
      family - the AF family type
      Returns:
      true, if address is of AF type specified
    • toString

      public String toString()
      String representation of the structure field values.
      Overrides:
      toString in class Object
      Returns:
      the string
      See Also:
    • totalLength

      public OptionalInt totalLength()
      The total length of the socket address structure in bytes. The value is only returned on certain platforms (BSD style sockets)..
      Returns:
      the length of the address structure if available on this particular platform