libosmo-netif 1.7.0.10-3a9e Osmocom network interface library

Files | Functions
Osmocom Datagram Socket

This code is intended to abstract any use of datagram type sockets, such as UDP. More...

## Files
file | datagram.h
| Osmocom datagram socket helpers.
file | datagram.c
| Osmocom datagram socket helpers.

## Functions
struct osmo_dgram_tx * | osmo_dgram_tx_create (void *ctx)
| Create an Osmocom datagram transmitter. More...
void | osmo_dgram_tx_destroy (struct osmo_dgram_tx *conn)
| Destroy a Osmocom datagram transmitter. More...
void | osmo_dgram_tx_set_addr (struct osmo_dgram_tx *conn, const char *addr)
| Set the remote address to which we transmit. More...
void | osmo_dgram_tx_set_port (struct osmo_dgram_tx *conn, uint16_t port)
| Set the remote port to which we transmit. More...
void | osmo_dgram_tx_set_local_addr (struct osmo_dgram_tx *conn, const char *addr)
| Set the local address from which we transmit. More...
void | osmo_dgram_tx_set_local_port (struct osmo_dgram_tx *conn, uint16_t port)
| Set the local port from which we transmit. More...
void | osmo_dgram_tx_set_data (struct osmo_dgram_tx *conn, void *data)
| Set application private data of the datagram transmitter. More...
int | osmo_dgram_tx_open (struct osmo_dgram_tx *conn)
| Open connection of an Osmocom datagram transmitter. More...
void | osmo_dgram_tx_close (struct osmo_dgram_tx *conn)
| Close an Osmocom Datagram Transmitter. More...
void | osmo_dgram_tx_send (struct osmo_dgram_tx *conn, struct msgb *msg)
| Enqueue data to be sent via an Osmocom datagram transmitter. More...
struct osmo_dgram_rx * | osmo_dgram_rx_create (void *ctx)
| Create an Osmocom datagram receiver. More...
void | osmo_dgram_rx_set_addr (struct osmo_dgram_rx *conn, const char *addr)
| Set the local address to which we bind. More...
void | osmo_dgram_rx_set_port (struct osmo_dgram_rx *conn, uint16_t port)
| Set the local port to which we bind. More...
void | osmo_dgram_rx_set_read_cb (struct osmo_dgram_rx *conn, int(*read_cb)(struct osmo_dgram_rx *conn))
| Set the read() call-back of the datagram receiver. More...
void | osmo_dgram_rx_destroy (struct osmo_dgram_rx *conn)
| Destroy the datagram receiver. More...
int | osmo_dgram_rx_open (struct osmo_dgram_rx *conn)
| Open the datagram receiver. More...
void | osmo_dgram_rx_close (struct osmo_dgram_rx *conn)
| Close the datagram receiver and unregister from select loop Does not destroy the datagram receiver, merely closes it! More...
int | osmo_dgram_rx_recv (struct osmo_dgram_rx *conn, struct msgb *msg)
| Receive data via Osmocom datagram receiver. More...
struct osmo_dgram * | osmo_dgram_create (void *ctx)
| Create an Osmocom datagram transceiver (bidirectional) More...
void | osmo_dgram_destroy (struct osmo_dgram *conn)
| Destroy a Osmocom datagram transceiver. More...
int | osmo_dgram_open (struct osmo_dgram *conn)
| Open the datagram transceiver. More...
void | osmo_dgram_close (struct osmo_dgram *conn)
| Close an Osmocom Datagram Transceiver. More...
void | osmo_dgram_set_local_addr (struct osmo_dgram *conn, const char *addr)
| Set the local address to which we bind. More...
void | osmo_dgram_set_remote_addr (struct osmo_dgram *conn, const char *addr)
| Set the remote address to which we transmit/connect. More...
void | osmo_dgram_set_local_port (struct osmo_dgram *conn, uint16_t port)
| Set the local port to which we bind. More...
void | osmo_dgram_set_remote_port (struct osmo_dgram *conn, uint16_t port)
| Set the remote port to which we transmit. More...
void | osmo_dgram_set_read_cb (struct osmo_dgram *conn, int(*read_cb)(struct osmo_dgram *conn))
| Set the read() call-back of the datagram receiver. More...
void | osmo_dgram_set_data (struct osmo_dgram *conn, void *data)
| Set application private data of the datagram transmitter. More...
void * | osmo_dgram_get_data (struct osmo_dgram *conn)
| Get application private data of the datagram transceiver. More...
void | osmo_dgram_send (struct osmo_dgram *conn, struct msgb *msg)
| Enqueue data to be sent via an Osmocom datagram transceiver. More...
int | osmo_dgram_recv (struct osmo_dgram *conn, struct msgb *msg)
| Receive data via Osmocom datagram transceiver. More...

## Detailed Description

This code is intended to abstract any use of datagram type sockets, such as UDP.

It offers both transmitter and receiver side implementations, fully integrated with the libosmocore select loop abstraction.

## Function Documentation

## ◆ osmo_dgram_close()

void osmo_dgram_close | ( | struct osmo_dgram * | conn | ) |

Close an Osmocom Datagram Transceiver.

Parameters

  [in] | conn | Osmocom Datagram Transceiver to be closed We unregister the socket fds from the osmocom select() loop and close them.

References osmo_dgram_rx_close(), and osmo_dgram_tx_close().

## ◆ osmo_dgram_create()

struct osmo_dgram * osmo_dgram_create | ( | void * | ctx | ) |

Create an Osmocom datagram transceiver (bidirectional)

Parameters

  [in] | ctx | talloc context from which to allocate memory This function allocates a new osmo_dgram and initializes it with default values. Internally, the Transceiver is based on a tuple of transmitter (osmo_dgram_tx) and receiver (osmo_dgram_rx)

Returns
  Osmocom Datagram Transceiver; NULL on error

References osmo_dgram_rx_create(), and osmo_dgram_rx_set_read_cb().

## ◆ osmo_dgram_destroy()

void osmo_dgram_destroy | ( | struct osmo_dgram * | conn | ) |

Destroy a Osmocom datagram transceiver.

Parameters

  [in] | conn | Datagram Transceiver to destroy

References osmo_dgram_rx_destroy(), and osmo_dgram_tx_destroy().

## ◆ osmo_dgram_get_data()

void * osmo_dgram_get_data | ( | struct osmo_dgram * | conn | ) |

Get application private data of the datagram transceiver.

Parameters

  [in] | conn | Datagram Transceiver

Returns
  Application private data, as set by osmo_dgram_set_data()

## ◆ osmo_dgram_open()

int osmo_dgram_open | ( | struct osmo_dgram * | conn | ) |

Open the datagram transceiver.

This actually initializes the underlying sockets and binds/connects them to the configured ips/ports

Parameters

  [in] | conn | Datagram Transceiver to open

References osmo_dgram_rx_close(), osmo_dgram_rx_open(), and osmo_dgram_tx_open().

## ◆ osmo_dgram_recv()

int osmo_dgram_recv | ( | struct osmo_dgram * | conn,
|  | struct msgb * | msg
| ) |  |

Receive data via Osmocom datagram transceiver.

Parameters

  [in] | conn | Datagram Transceiver from which to receive
  | msg | pre-allocate message buffer to which received data is appended

Returns
  number of bytes read, negative on error.

References osmo_dgram_rx_recv().

## ◆ osmo_dgram_rx_close()

void osmo_dgram_rx_close | ( | struct osmo_dgram_rx * | conn | ) |

Close the datagram receiver and unregister from select loop Does not destroy the datagram receiver, merely closes it!

Parameters

  [in] | conn | Stream Server Link to close

Referenced by osmo_dgram_close(), osmo_dgram_open(), and osmo_dgram_rx_destroy().

## ◆ osmo_dgram_rx_create()

struct osmo_dgram_rx * osmo_dgram_rx_create | ( | void * | ctx | ) |

Create an Osmocom datagram receiver.

Parameters

  [in] | ctx | talloc context from which to allocate memory This function allocates a new osmo_dgram_rx and initializes it with default values

Returns
  Datagram Receiver; NULL on error

Referenced by osmo_dgram_create().

## ◆ osmo_dgram_rx_destroy()

void osmo_dgram_rx_destroy | ( | struct osmo_dgram_rx * | conn | ) |

Destroy the datagram receiver.

Releases Memory.

Parameters

  [in] | conn | Datagram Receiver

References osmo_dgram_rx_close().

Referenced by osmo_dgram_destroy().

## ◆ osmo_dgram_rx_open()

int osmo_dgram_rx_open | ( | struct osmo_dgram_rx * | conn | ) |

Open the datagram receiver.

This actually initializes the underlying socket and binds it to the configured ip/port

Parameters

  [in] | conn | Datagram Receiver to open

Referenced by osmo_dgram_open().

## ◆ osmo_dgram_rx_recv()

int osmo_dgram_rx_recv | ( | struct osmo_dgram_rx * | conn,
|  | struct msgb * | msg
| ) |  |

Receive data via Osmocom datagram receiver.

Parameters

  [in] | conn | Datagram Receiver from which to receive
  | msg | pre-allocate message buffer to which received data is appended

Returns
  number of bytes read (might be 0 for empty UDP packet), negative on error.

Referenced by osmo_dgram_recv().

## ◆ osmo_dgram_rx_set_addr()

void osmo_dgram_rx_set_addr | ( | struct osmo_dgram_rx * | conn,
|  | const char * | addr
| ) |  |

Set the local address to which we bind.

Parameters

  [in] | conn | Datagram Receiver to modify
  [in] | addr | Local IP address

Referenced by osmo_dgram_set_local_addr().

## ◆ osmo_dgram_rx_set_port()

void osmo_dgram_rx_set_port | ( | struct osmo_dgram_rx * | conn,
|  | uint16_t | port
| ) |  |

Set the local port to which we bind.

Parameters

  [in] | conn | Datagram Receiver to modify
  [in] | port | Local port number

Referenced by osmo_dgram_set_local_port().

## ◆ osmo_dgram_rx_set_read_cb()

void osmo_dgram_rx_set_read_cb | ( | struct osmo_dgram_rx * | conn,
|  | int(*)(struct osmo_dgram_rx *conn) | read_cb
| ) |  |

Set the read() call-back of the datagram receiver.

Parameters

  [in] | conn | Datagram Receiver to modify
  [in] | read_cb | Call-back function executed after read()

Referenced by osmo_dgram_create().

## ◆ osmo_dgram_send()

void osmo_dgram_send | ( | struct osmo_dgram * | conn,
|  | struct msgb * | msg
| ) |  |

Enqueue data to be sent via an Osmocom datagram transceiver.

Parameters

  [in] | conn | Datagram Transceiver through which we want to send
  [in] | msg | Message buffer to enqueue in transmit queue

References osmo_dgram_tx_send().

## ◆ osmo_dgram_set_data()

void osmo_dgram_set_data | ( | struct osmo_dgram * | conn,
|  | void * | data
| ) |  |

Set application private data of the datagram transmitter.

Parameters

  [in] | conn | Datagram Transmitter to modify
  [in] | data | User-specific data (available in call-back functions)

## ◆ osmo_dgram_set_local_addr()

void osmo_dgram_set_local_addr | ( | struct osmo_dgram * | conn,
|  | const char * | addr
| ) |  |

Set the local address to which we bind.

Parameters

  [in] | conn | Datagram Transceiver to modify
  [in] | addr | Local IP address

References osmo_dgram_rx_set_addr().

## ◆ osmo_dgram_set_local_port()

void osmo_dgram_set_local_port | ( | struct osmo_dgram * | conn,
|  | uint16_t | port
| ) |  |

Set the local port to which we bind.

Parameters

  [in] | conn | Datagram Transceiver to modify
  [in] | port | Local Port Number

References osmo_dgram_rx_set_port().

## ◆ osmo_dgram_set_read_cb()

void osmo_dgram_set_read_cb | ( | struct osmo_dgram * | conn,
|  | int(*)(struct osmo_dgram *conn) | read_cb
| ) |  |

Set the read() call-back of the datagram receiver.

Parameters

  [in] | conn | Datagram Receiver to modify
  [in] | read_cb | Call-back function executed after read()

## ◆ osmo_dgram_set_remote_addr()

void osmo_dgram_set_remote_addr | ( | struct osmo_dgram * | conn,
|  | const char * | addr
| ) |  |

Set the remote address to which we transmit/connect.

Parameters

  [in] | conn | Datagram Transceiver to modify
  [in] | addr | Remote IP address

References osmo_dgram_tx_set_addr().

## ◆ osmo_dgram_set_remote_port()

void osmo_dgram_set_remote_port | ( | struct osmo_dgram * | conn,
|  | uint16_t | port
| ) |  |

Set the remote port to which we transmit.

Parameters

  [in] | conn | Datagram Transceiver to modify
  [in] | port | Remote Port Number

References osmo_dgram_tx_set_port().

## ◆ osmo_dgram_tx_close()

void osmo_dgram_tx_close | ( | struct osmo_dgram_tx * | conn | ) |

Close an Osmocom Datagram Transmitter.

Parameters

  [in] | conn | Osmocom Datagram Transmitter to be closed We unregister the socket fd from the osmocom select() loop abstraction and close the socket

Referenced by osmo_dgram_close(), and osmo_dgram_tx_destroy().

## ◆ osmo_dgram_tx_create()

struct osmo_dgram_tx * osmo_dgram_tx_create | ( | void * | ctx | ) |

Create an Osmocom datagram transmitter.

Parameters

  [in] | ctx | talloc context from which to allocate memory This function allocates a new osmo_dgram_tx and initializes it with default values

Returns
  Osmocom Datagram Transmitter; NULL on error

## ◆ osmo_dgram_tx_destroy()

void osmo_dgram_tx_destroy | ( | struct osmo_dgram_tx * | conn | ) |

Destroy a Osmocom datagram transmitter.

Parameters

  [in] | conn | Datagram Transmitter to destroy

References osmo_dgram_tx_close().

Referenced by osmo_dgram_destroy().

## ◆ osmo_dgram_tx_open()

int osmo_dgram_tx_open | ( | struct osmo_dgram_tx * | conn | ) |

Open connection of an Osmocom datagram transmitter.

Parameters

  [in] | conn | Stream Client to connect

Returns
  0 on success; negative in case of error

Referenced by osmo_dgram_open().

## ◆ osmo_dgram_tx_send()

void osmo_dgram_tx_send | ( | struct osmo_dgram_tx * | conn,
|  | struct msgb * | msg
| ) |  |

Enqueue data to be sent via an Osmocom datagram transmitter.

Parameters

  [in] | conn | Datagram Transmitter through which we want to send
  [in] | msg | Message buffer to enqueue in transmit queue

Referenced by osmo_dgram_send().

## ◆ osmo_dgram_tx_set_addr()

void osmo_dgram_tx_set_addr | ( | struct osmo_dgram_tx * | conn,
|  | const char * | addr
| ) |  |

Set the remote address to which we transmit.

Parameters

  [in] | conn | Datagram Transmitter to modify
  [in] | addr | Remote IP address

Referenced by osmo_dgram_set_remote_addr().

## ◆ osmo_dgram_tx_set_data()

void osmo_dgram_tx_set_data | ( | struct osmo_dgram_tx * | conn,
|  | void * | data
| ) |  |

Set application private data of the datagram transmitter.

Parameters

  [in] | conn | Datagram Transmitter to modify
  [in] | data | User-specific data (available in call-back functions)

## ◆ osmo_dgram_tx_set_local_addr()

void osmo_dgram_tx_set_local_addr | ( | struct osmo_dgram_tx * | conn,
|  | const char * | addr
| ) |  |

Set the local address from which we transmit.

Parameters

  [in] | conn | Datagram Transmitter to modify
  [in] | addr | Local IP address

## ◆ osmo_dgram_tx_set_local_port()

void osmo_dgram_tx_set_local_port | ( | struct osmo_dgram_tx * | conn,
|  | uint16_t | port
| ) |  |

Set the local port from which we transmit.

Parameters

  [in] | conn | Datagram Transmitter to modify
  [in] | port | Local Port Number

## ◆ osmo_dgram_tx_set_port()

void osmo_dgram_tx_set_port | ( | struct osmo_dgram_tx * | conn,
|  | uint16_t | port
| ) |  |

Set the remote port to which we transmit.

Parameters

  [in] | conn | Datagram Transmitter to modify
  [in] | port | Remote Port Number

Referenced by osmo_dgram_set_remote_port().