ax25.socket

AX.25 Sockets

This module provides socket support for the AX.25 protocol. While Python defines the AX.25 address family, it does not implement support for it, and will fail with ‘bad family’ on any attempt to use it.

A socket class with support for AX.25 addressing is provided, as is a convenience method for sending unproto messages. Callsigns may be provided as strings or as ax25.Address instances.

Note: The receivefrom_into() method has not been implemented, because it would require the creation of a new buffer in any case, negating the benefit of using an already-existing buffer. Use receivefrom() instead.

Important

This implementation relies on the Linux AX.25 stack, and will not work on any other platform. An exception is raised if an attempt is made to use it on a non-Linux platform.

Classes

Socket

Socket support for the AX.25 address family.

Functions

send_unproto(src, dst, data[, via, port])

Convenience function for sending an unproto message.

Module Contents

class ax25.socket.Socket(sock_type=socket.SOCK_SEQPACKET)

Bases: socket.socket

Socket support for the AX.25 address family.

A subclass of the Python socket class that provides support for the AX.25 address family. The address family is hardcoded to AF_AX25 here, since this class is not designed to be used as anything other than an AX.25 socket. Those socket methods that require addresses as arguments or return addresses are overridden; other socket methods are available as normal.

Parameters:

sock_type (socket.SocketKind) – Type of socket to create. The default is socket.SOCK_SEQPACKET, which is the appropriate type for a connected session, the primary use case for this class.

accept()

Wait for an incoming connection.

Returns a new socket representing the connection, and the callsign of the client.

Returns:

A tuple of the socket and the callsign.

Return type:

(Socket, str)

bind(call, port=None)

Bind the socket to the specified callsign.

The socket must not already be bound.

Parameters:
  • call (str or Address) – Callsign to bind to.

  • port (str) – Name of the port to use when binding. Optional.

Raises:
  • ValueError – if an invalid port name is specified.

  • OSError – if a bind failure occurs.

connect(call, via=None)

Connect the socket to a remote station.

Parameters:
  • call (str or Address) – Callsign of station to connect to.

  • via (list[str] or list[Address] or None) – List of callsigns to use as Via stations. Optional.

Raises:

OSError – if a connection failure occurs.

connect_ex(call, via=None)

Connect the socket to a remote station.

Like connect(call, via) but return an error code instead of raising an exception when a connection failure occurs.

Parameters:
  • call (str or Address) – Callsign of station to connect to.

  • via (list[str] or list[Address] or None) – List of callsigns to use as Via stations. Optional.

Returns:

0 on success, or the value of errno if a connection failure occurs.

Return type:

int

recvfrom(bufsize)

Receive data from the socket.

Like recv(bufsize) but also return the sender’s callsign.

Parameters:

bufsize (int) – Maximum amount of data to be received at once.

Returns:

A tuple of the received data and the sender’s callsign.

Return type:

(bytes, str)

sendto(data, call, via=None)

Send data to the socket.

The socket should not be connected to a remote socket, since the destination is specified by the callsign.

Parameters:
  • data (bytes) – Data to be sent.

  • call (str or Address) – Callsign of destination.

  • via (list[str] or list[Address] or None) – List of callsigns to use as Via stations. Optional.

Returns:

Number of bytes sent.

Return type:

int

ax25.socket.send_unproto(src, dst, data, via=None, port=None)

Convenience function for sending an unproto message.

This function encapsulates the creation and shutdown of the socket around the sending of an unproto message.

Parameters:
  • src (str or Address) – Callsign of sender.

  • dst (str or Address) – Callsign of destination.

  • data (bytes) – Data to send.

  • via (list[str] or list[Address] or None) – List of callsigns to use as Via stations. Optional.

  • port (str) – Port to use to send this message. Optional.

Returns:

Number of bytes sent.

Return type:

int