\doxysection{src/datagram.c File Reference} \label{datagram_8c}\index{src/datagram.c@{src/datagram.c}} Osmocom datagram socket helpers. {\ttfamily \#include $<$stdio.\+h$>$}\newline {\ttfamily \#include $<$unistd.\+h$>$}\newline {\ttfamily \#include $<$stdlib.\+h$>$}\newline {\ttfamily \#include $<$errno.\+h$>$}\newline {\ttfamily \#include $<$string.\+h$>$}\newline {\ttfamily \#include $<$time.\+h$>$}\newline {\ttfamily \#include $<$sys/fcntl.\+h$>$}\newline {\ttfamily \#include $<$sys/socket.\+h$>$}\newline {\ttfamily \#include $<$sys/ioctl.\+h$>$}\newline {\ttfamily \#include $<$arpa/inet.\+h$>$}\newline {\ttfamily \#include $<$netinet/in.\+h$>$}\newline {\ttfamily \#include $<$osmocom/core/linuxlist.\+h$>$}\newline {\ttfamily \#include $<$osmocom/core/select.\+h$>$}\newline {\ttfamily \#include $<$osmocom/core/utils.\+h$>$}\newline {\ttfamily \#include $<$osmocom/gsm/tlv.\+h$>$}\newline {\ttfamily \#include $<$osmocom/core/msgb.\+h$>$}\newline {\ttfamily \#include $<$osmocom/core/logging.\+h$>$}\newline {\ttfamily \#include $<$osmocom/core/talloc.\+h$>$}\newline {\ttfamily \#include $<$osmocom/core/socket.\+h$>$}\newline {\ttfamily \#include $<$osmocom/netif/datagram.\+h$>$}\newline \doxysubsection*{Data Structures} \begin{DoxyCompactItemize} \item struct \textbf{ osmo\+\_\+dgram\+\_\+tx} \item struct \textbf{ osmo\+\_\+dgram\+\_\+rx} \item struct \textbf{ osmo\+\_\+dgram} \end{DoxyCompactItemize} \doxysubsection*{Macros} \begin{DoxyCompactItemize} \item \#define {\bfseries OSMO\+\_\+\+DGRAM\+\_\+\+CLI\+\_\+\+F\+\_\+\+RECONF}~(1 $<$$<$ 0) \item \#define {\bfseries OSMO\+\_\+\+DGRAM\+\_\+\+RX\+\_\+\+F\+\_\+\+RECONF}~(1 $<$$<$ 0) \end{DoxyCompactItemize} \doxysubsection*{Functions} \begin{DoxyCompactItemize} \item void \textbf{ osmo\+\_\+dgram\+\_\+tx\+\_\+close} (struct \textbf{ osmo\+\_\+dgram\+\_\+tx} $\ast$conn) \begin{DoxyCompactList}\small\item\em Close an Osmocom Datagram Transmitter. \end{DoxyCompactList}\item static int {\bfseries osmo\+\_\+dgram\+\_\+tx\+\_\+write} (struct \textbf{ osmo\+\_\+dgram\+\_\+tx} $\ast$conn) \item static int {\bfseries osmo\+\_\+dgram\+\_\+tx\+\_\+fd\+\_\+cb} (struct osmo\+\_\+fd $\ast$ofd, unsigned int what) \item struct \textbf{ osmo\+\_\+dgram\+\_\+tx} $\ast$ \textbf{ osmo\+\_\+dgram\+\_\+tx\+\_\+create} (void $\ast$ctx) \begin{DoxyCompactList}\small\item\em Create an Osmocom datagram transmitter. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+tx\+\_\+set\+\_\+addr} (struct \textbf{ osmo\+\_\+dgram\+\_\+tx} $\ast$conn, const char $\ast$addr) \begin{DoxyCompactList}\small\item\em Set the remote address to which we transmit. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+tx\+\_\+set\+\_\+port} (struct \textbf{ osmo\+\_\+dgram\+\_\+tx} $\ast$conn, uint16\+\_\+t port) \begin{DoxyCompactList}\small\item\em Set the remote port to which we transmit. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+tx\+\_\+set\+\_\+local\+\_\+addr} (struct \textbf{ osmo\+\_\+dgram\+\_\+tx} $\ast$conn, const char $\ast$addr) \begin{DoxyCompactList}\small\item\em Set the local address from which we transmit. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+tx\+\_\+set\+\_\+local\+\_\+port} (struct \textbf{ osmo\+\_\+dgram\+\_\+tx} $\ast$conn, uint16\+\_\+t port) \begin{DoxyCompactList}\small\item\em Set the local port from which we transmit. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+tx\+\_\+set\+\_\+data} (struct \textbf{ osmo\+\_\+dgram\+\_\+tx} $\ast$conn, void $\ast$data) \begin{DoxyCompactList}\small\item\em Set application private data of the datagram transmitter. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+tx\+\_\+destroy} (struct \textbf{ osmo\+\_\+dgram\+\_\+tx} $\ast$conn) \begin{DoxyCompactList}\small\item\em Destroy a Osmocom datagram transmitter. \end{DoxyCompactList}\item int \textbf{ osmo\+\_\+dgram\+\_\+tx\+\_\+open} (struct \textbf{ osmo\+\_\+dgram\+\_\+tx} $\ast$conn) \begin{DoxyCompactList}\small\item\em Open connection of an Osmocom datagram transmitter. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+tx\+\_\+send} (struct \textbf{ osmo\+\_\+dgram\+\_\+tx} $\ast$conn, struct msgb $\ast$msg) \begin{DoxyCompactList}\small\item\em Enqueue data to be sent via an Osmocom datagram transmitter. \end{DoxyCompactList}\item int \textbf{ osmo\+\_\+dgram\+\_\+rx\+\_\+recv} (struct \textbf{ osmo\+\_\+dgram\+\_\+rx} $\ast$conn, struct msgb $\ast$msg) \begin{DoxyCompactList}\small\item\em Receive data via Osmocom datagram receiver. \end{DoxyCompactList}\item static void {\bfseries osmo\+\_\+dgram\+\_\+rx\+\_\+read} (struct \textbf{ osmo\+\_\+dgram\+\_\+rx} $\ast$conn) \item static int {\bfseries osmo\+\_\+dgram\+\_\+rx\+\_\+cb} (struct osmo\+\_\+fd $\ast$ofd, unsigned int what) \item struct \textbf{ osmo\+\_\+dgram\+\_\+rx} $\ast$ \textbf{ osmo\+\_\+dgram\+\_\+rx\+\_\+create} (void $\ast$ctx) \begin{DoxyCompactList}\small\item\em Create an Osmocom datagram receiver. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+rx\+\_\+set\+\_\+addr} (struct \textbf{ osmo\+\_\+dgram\+\_\+rx} $\ast$conn, const char $\ast$addr) \begin{DoxyCompactList}\small\item\em Set the local address to which we bind. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+rx\+\_\+set\+\_\+port} (struct \textbf{ osmo\+\_\+dgram\+\_\+rx} $\ast$conn, uint16\+\_\+t port) \begin{DoxyCompactList}\small\item\em Set the local port to which we bind. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+rx\+\_\+set\+\_\+read\+\_\+cb} (struct \textbf{ osmo\+\_\+dgram\+\_\+rx} $\ast$conn, int($\ast$read\+\_\+cb)(struct \textbf{ osmo\+\_\+dgram\+\_\+rx} $\ast$conn)) \begin{DoxyCompactList}\small\item\em Set the read() call-\/back of the datagram receiver. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+rx\+\_\+destroy} (struct \textbf{ osmo\+\_\+dgram\+\_\+rx} $\ast$conn) \begin{DoxyCompactList}\small\item\em Destroy the datagram receiver. Releases Memory. \end{DoxyCompactList}\item int \textbf{ osmo\+\_\+dgram\+\_\+rx\+\_\+open} (struct \textbf{ osmo\+\_\+dgram\+\_\+rx} $\ast$conn) \begin{DoxyCompactList}\small\item\em Open the datagram receiver. This actually initializes the underlying socket and binds it to the configured ip/port. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+rx\+\_\+close} (struct \textbf{ osmo\+\_\+dgram\+\_\+rx} $\ast$conn) \begin{DoxyCompactList}\small\item\em Close the datagram receiver and unregister from select loop Does not destroy the datagram receiver, merely closes it! \end{DoxyCompactList}\item static int {\bfseries dgram\+\_\+rx\+\_\+cb} (struct \textbf{ osmo\+\_\+dgram\+\_\+rx} $\ast$rx) \item struct \textbf{ osmo\+\_\+dgram} $\ast$ \textbf{ osmo\+\_\+dgram\+\_\+create} (void $\ast$ctx) \begin{DoxyCompactList}\small\item\em Create an Osmocom datagram transceiver (bidirectional) \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+destroy} (struct \textbf{ osmo\+\_\+dgram} $\ast$conn) \begin{DoxyCompactList}\small\item\em Destroy a Osmocom datagram transceiver. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+set\+\_\+local\+\_\+addr} (struct \textbf{ osmo\+\_\+dgram} $\ast$conn, const char $\ast$addr) \begin{DoxyCompactList}\small\item\em Set the local address to which we bind. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+set\+\_\+remote\+\_\+addr} (struct \textbf{ osmo\+\_\+dgram} $\ast$conn, const char $\ast$addr) \begin{DoxyCompactList}\small\item\em Set the remote address to which we transmit/connect. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+set\+\_\+local\+\_\+port} (struct \textbf{ osmo\+\_\+dgram} $\ast$conn, uint16\+\_\+t port) \begin{DoxyCompactList}\small\item\em Set the local port to which we bind. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+set\+\_\+remote\+\_\+port} (struct \textbf{ osmo\+\_\+dgram} $\ast$conn, uint16\+\_\+t port) \begin{DoxyCompactList}\small\item\em Set the remote port to which we transmit. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+set\+\_\+read\+\_\+cb} (struct \textbf{ osmo\+\_\+dgram} $\ast$conn, int($\ast$read\+\_\+cb)(struct \textbf{ osmo\+\_\+dgram} $\ast$conn)) \begin{DoxyCompactList}\small\item\em Set the read() call-\/back of the datagram receiver. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+set\+\_\+data} (struct \textbf{ osmo\+\_\+dgram} $\ast$conn, void $\ast$data) \begin{DoxyCompactList}\small\item\em Set application private data of the datagram transmitter. \end{DoxyCompactList}\item void $\ast$ \textbf{ osmo\+\_\+dgram\+\_\+get\+\_\+data} (struct \textbf{ osmo\+\_\+dgram} $\ast$conn) \begin{DoxyCompactList}\small\item\em Get application private data of the datagram transceiver. \end{DoxyCompactList}\item int \textbf{ osmo\+\_\+dgram\+\_\+open} (struct \textbf{ osmo\+\_\+dgram} $\ast$conn) \begin{DoxyCompactList}\small\item\em Open the datagram transceiver. This actually initializes the underlying sockets and binds/connects them to the configured ips/ports. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+close} (struct \textbf{ osmo\+\_\+dgram} $\ast$conn) \begin{DoxyCompactList}\small\item\em Close an Osmocom Datagram Transceiver. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+dgram\+\_\+send} (struct \textbf{ osmo\+\_\+dgram} $\ast$conn, struct msgb $\ast$msg) \begin{DoxyCompactList}\small\item\em Enqueue data to be sent via an Osmocom datagram transceiver. \end{DoxyCompactList}\item int \textbf{ osmo\+\_\+dgram\+\_\+recv} (struct \textbf{ osmo\+\_\+dgram} $\ast$conn, struct msgb $\ast$msg) \begin{DoxyCompactList}\small\item\em Receive data via Osmocom datagram transceiver. \end{DoxyCompactList}\end{DoxyCompactItemize} \doxysubsection{Detailed Description} Osmocom datagram socket helpers.