Skip to content

Gio.SocketAddress

class — extends GObject.Object, SocketConnectable

GSocketAddress is the equivalent of struct sockaddr and its subtypes in the BSD sockets API. This is an abstract class; use InetSocketAddress for internet sockets, or UnixSocketAddress for UNIX domain sockets.

Constructors

new_from_native

@classmethod
def new_from_native(cls, native: int, len: int) -> SocketAddress

Creates a SocketAddress subclass corresponding to the native struct sockaddr native.

Parameters:

  • native — a pointer to a struct sockaddr
  • len — the size of the memory location pointed to by native

Methods

get_family

def get_family(self) -> SocketFamily

Gets the socket family type of address.

get_native_size

def get_native_size(self) -> int

Gets the size of address's native struct sockaddr. You can use this to allocate memory to pass to SocketAddress.to_native.

to_native

def to_native(self, dest: int | None, destlen: int) -> bool

Converts a SocketAddress to a native struct sockaddr, which can be passed to low-level functions like connect() or bind().

If not enough space is available, a IOErrorEnum.NO_SPACE error is returned. If the address type is not known on the system then a IOErrorEnum.NOT_SUPPORTED error is returned.

Parameters:

  • dest — a pointer to a memory location that will contain the native struct sockaddr
  • destlen — the size of dest. Must be at least as large as SocketAddress.get_native_size

Virtual methods

do_get_family

def do_get_family(self) -> SocketFamily

Gets the socket family type of address.

do_get_native_size

def do_get_native_size(self) -> int

Gets the size of address's native struct sockaddr. You can use this to allocate memory to pass to SocketAddress.to_native.

do_to_native

def do_to_native(self, dest: int | None, destlen: int) -> bool

Converts a SocketAddress to a native struct sockaddr, which can be passed to low-level functions like connect() or bind().

If not enough space is available, a IOErrorEnum.NO_SPACE error is returned. If the address type is not known on the system then a IOErrorEnum.NOT_SUPPORTED error is returned.

Parameters:

  • dest — a pointer to a memory location that will contain the native struct sockaddr
  • destlen — the size of dest. Must be at least as large as SocketAddress.get_native_size

Properties

family

family: SocketFamily | int  # read-only

The family of the socket address.