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
A Java representation of the native socket address (sockaddr) structure and its protocol-specific variants. Socket addresses are used to identify network endpoints in various networking protocols.

Platform-Specific Variants

The native sockaddr structure has two main variants:

BSD-style Structure


 struct sockaddr {
     uint8_t  sa_len;     // Total length of the structure
     uint8_t  sa_family;  // Address family (AF_*)
     char     sa_data[14];// Protocol-specific address data
 };
 

POSIX-style Structure


 struct sockaddr {
     uint16_t sa_family;  // Address family (AF_*)
     char     sa_data[14];// Protocol-specific address data
 };
 

Protocol Families

This class serves as the base for protocol-specific socket address structures:

Memory Management

This class manages native memory through the MemorySegment API. The lifetime of the native memory is controlled by the provided Arena.

Platform Detection

The class automatically detects the platform's socket address format (BSD vs POSIX) and adjusts its behavior accordingly. This detection affects how the family field is read and whether the length field is present.
See Also: