\doxysection{src/vty/telnet\+\_\+interface.c File Reference}
\label{telnet__interface_8c}\index{src/vty/telnet\_interface.c@{src/vty/telnet\_interface.c}}


Telnet interface towards Osmocom VTY.  


{\ttfamily \#include $<$sys/socket.\+h$>$}\newline
{\ttfamily \#include $<$netinet/in.\+h$>$}\newline
{\ttfamily \#include $<$errno.\+h$>$}\newline
{\ttfamily \#include $<$stdlib.\+h$>$}\newline
{\ttfamily \#include $<$stdio.\+h$>$}\newline
{\ttfamily \#include $<$string.\+h$>$}\newline
{\ttfamily \#include $<$unistd.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/msgb.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/socket.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/talloc.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/logging.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/signal.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/vty/telnet\+\_\+interface.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/vty/buffer.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/vty/command.\+h$>$}\newline
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
\textbf{ LLIST\+\_\+\+HEAD} (active\+\_\+connections)
\item 
static int \textbf{ telnet\+\_\+new\+\_\+connection} (struct \textbf{ osmo\+\_\+fd} $\ast$\textbf{ fd}, unsigned int what)
\item 
static int \textbf{ \+\_\+telnet\+\_\+init\+\_\+dynif} (void $\ast$tall\+\_\+ctx, void $\ast$priv, const char $\ast$ip, int port)
\item 
int \textbf{ telnet\+\_\+init} (void $\ast$tall\+\_\+ctx, void $\ast$priv, int port)
\begin{DoxyCompactList}\small\item\em Initialize telnet based VTY interface listening to 127.\+0.\+0.\+1. \end{DoxyCompactList}\item 
int \textbf{ telnet\+\_\+init\+\_\+dynif} (void $\ast$tall\+\_\+ctx, void $\ast$priv, const char $\ast$ip, int port)
\begin{DoxyCompactList}\small\item\em Initialize telnet based VTY interface. \end{DoxyCompactList}\item 
int \textbf{ telnet\+\_\+init\+\_\+default} (void $\ast$tall\+\_\+ctx, void $\ast$priv, int default\+\_\+port)
\begin{DoxyCompactList}\small\item\em Initializes telnet based VTY interface using the configured bind addr/port. \end{DoxyCompactList}\item 
int \textbf{ telnet\+\_\+close\+\_\+client} (struct \textbf{ osmo\+\_\+fd} $\ast$\textbf{ fd})
\begin{DoxyCompactList}\small\item\em close a telnet connection \end{DoxyCompactList}\item 
static int \textbf{ client\+\_\+data} (struct \textbf{ osmo\+\_\+fd} $\ast$\textbf{ fd}, unsigned int what)
\item 
bool \textbf{ vty\+\_\+is\+\_\+active} (struct \textbf{ vty} $\ast$\textbf{ vty})
\item 
void \textbf{ vty\+\_\+event} (enum \textbf{ event} \textbf{ event}, int sock, struct \textbf{ vty} $\ast$\textbf{ vty})
\begin{DoxyCompactList}\small\item\em callback from core VTY code about VTY related events \end{DoxyCompactList}\item 
void \textbf{ telnet\+\_\+exit} (void)
\begin{DoxyCompactList}\small\item\em Close all telnet connections and release the telnet socket. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
static void $\ast$ \textbf{ tall\+\_\+telnet\+\_\+ctx}
\item 
static struct \textbf{ osmo\+\_\+fd} \textbf{ server\+\_\+socket}
\item 
struct \textbf{ host} \textbf{ host}
\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
Telnet interface towards Osmocom VTY. 

This module contains the code implementing a telnet server for VTY access. This telnet server gets linked into each libosmovty-\/using process in order to enable interactive command-\/line introspection, interaction and configuration.

You typically call telnet\+\_\+init\+\_\+default once from your application code to enable this. 

\doxysubsection{Function Documentation}
\mbox{\label{telnet__interface_8c_ab348c147210588f6017797b2fcbb6a84}} 
\index{telnet\_interface.c@{telnet\_interface.c}!\_telnet\_init\_dynif@{\_telnet\_init\_dynif}}
\index{\_telnet\_init\_dynif@{\_telnet\_init\_dynif}!telnet\_interface.c@{telnet\_interface.c}}
\doxysubsubsection{\_telnet\_init\_dynif()}
{\footnotesize\ttfamily static int \+\_\+telnet\+\_\+init\+\_\+dynif (\begin{DoxyParamCaption}\item[{void $\ast$}]{tall\+\_\+ctx,  }\item[{void $\ast$}]{priv,  }\item[{const char $\ast$}]{ip,  }\item[{int}]{port }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}



References \textbf{ osmo\+\_\+fd\+::data}, \textbf{ DLGLOBAL}, \textbf{ LOGL\+\_\+\+ERROR}, \textbf{ LOGL\+\_\+\+NOTICE}, \textbf{ LOGP}, \textbf{ OSMO\+\_\+\+SOCK\+\_\+\+F\+\_\+\+BIND}, \textbf{ osmo\+\_\+sock\+\_\+init\+\_\+ofd()}, \textbf{ server\+\_\+socket}, and \textbf{ tall\+\_\+telnet\+\_\+ctx}.



Referenced by \textbf{ telnet\+\_\+init()}, \textbf{ telnet\+\_\+init\+\_\+default()}, and \textbf{ telnet\+\_\+init\+\_\+dynif()}.

\mbox{\label{telnet__interface_8c_a4da4d0bdb42b8325a7d08cc126a413ec}} 
\index{telnet\_interface.c@{telnet\_interface.c}!client\_data@{client\_data}}
\index{client\_data@{client\_data}!telnet\_interface.c@{telnet\_interface.c}}
\doxysubsubsection{client\_data()}
{\footnotesize\ttfamily static int client\+\_\+data (\begin{DoxyParamCaption}\item[{struct \textbf{ osmo\+\_\+fd} $\ast$}]{fd,  }\item[{unsigned int}]{what }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}



References \textbf{ BUFFER\+\_\+\+EMPTY}, \textbf{ buffer\+\_\+flush\+\_\+all()}, \textbf{ osmo\+\_\+fd\+::data}, \textbf{ osmo\+\_\+fd\+::fd}, \textbf{ fd}, \textbf{ telnet\+\_\+connection\+::fd}, \textbf{ vty\+::obuf}, \textbf{ OSMO\+\_\+\+FD\+\_\+\+READ}, \textbf{ OSMO\+\_\+\+FD\+\_\+\+WRITE}, \textbf{ telnet\+\_\+connection\+::vty}, \textbf{ vty\+\_\+read()}, and \textbf{ osmo\+\_\+fd\+::when}.



Referenced by \textbf{ telnet\+\_\+new\+\_\+connection()}.

\mbox{\label{telnet__interface_8c_ad1212e309a2283114654a14bf51b186b}} 
\index{telnet\_interface.c@{telnet\_interface.c}!LLIST\_HEAD@{LLIST\_HEAD}}
\index{LLIST\_HEAD@{LLIST\_HEAD}!telnet\_interface.c@{telnet\_interface.c}}
\doxysubsubsection{LLIST\_HEAD()}
{\footnotesize\ttfamily LLIST\+\_\+\+HEAD (\begin{DoxyParamCaption}\item[{active\+\_\+connections}]{ }\end{DoxyParamCaption})}

\mbox{\label{telnet__interface_8c_a82a6023d981d4e08120a124b4703deb7}} 
\index{telnet\_interface.c@{telnet\_interface.c}!telnet\_close\_client@{telnet\_close\_client}}
\index{telnet\_close\_client@{telnet\_close\_client}!telnet\_interface.c@{telnet\_interface.c}}
\doxysubsubsection{telnet\_close\_client()}
{\footnotesize\ttfamily int telnet\+\_\+close\+\_\+client (\begin{DoxyParamCaption}\item[{struct \textbf{ osmo\+\_\+fd} $\ast$}]{fd }\end{DoxyParamCaption})}



close a telnet connection 



References \textbf{ osmo\+\_\+fd\+::data}, \textbf{ telnet\+\_\+connection\+::dbg}, \textbf{ DLGLOBAL}, \textbf{ telnet\+\_\+connection\+::entry}, \textbf{ osmo\+\_\+fd\+::fd}, \textbf{ fd}, \textbf{ llist\+\_\+del()}, \textbf{ log\+\_\+del\+\_\+target()}, \textbf{ LOGL\+\_\+\+INFO}, \textbf{ LOGP}, \textbf{ osmo\+\_\+fd\+\_\+unregister()}, \textbf{ osmo\+\_\+sock\+\_\+get\+\_\+name\+\_\+buf()}, and \textbf{ OSMO\+\_\+\+SOCK\+\_\+\+NAME\+\_\+\+MAXLEN}.



Referenced by \textbf{ telnet\+\_\+exit()}, and \textbf{ vty\+\_\+event()}.

\mbox{\label{telnet__interface_8c_aea1259074602f70974186c7dde9f7d2b}} 
\index{telnet\_interface.c@{telnet\_interface.c}!telnet\_new\_connection@{telnet\_new\_connection}}
\index{telnet\_new\_connection@{telnet\_new\_connection}!telnet\_interface.c@{telnet\_interface.c}}
\doxysubsubsection{telnet\_new\_connection()}
{\footnotesize\ttfamily static int telnet\+\_\+new\+\_\+connection (\begin{DoxyParamCaption}\item[{struct \textbf{ osmo\+\_\+fd} $\ast$}]{fd,  }\item[{unsigned int}]{what }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}



References \textbf{ osmo\+\_\+fd\+::cb}, \textbf{ client\+\_\+data()}, \textbf{ osmo\+\_\+fd\+::data}, \textbf{ DLGLOBAL}, \textbf{ telnet\+\_\+connection\+::entry}, \textbf{ osmo\+\_\+fd\+::fd}, \textbf{ fd}, \textbf{ telnet\+\_\+connection\+::fd}, \textbf{ len()}, \textbf{ llist\+\_\+add\+\_\+tail()}, \textbf{ LOGL\+\_\+\+ERROR}, \textbf{ LOGL\+\_\+\+INFO}, \textbf{ LOGP}, \textbf{ OSMO\+\_\+\+FD\+\_\+\+READ}, \textbf{ osmo\+\_\+fd\+\_\+register()}, \textbf{ osmo\+\_\+sock\+\_\+get\+\_\+name\+\_\+buf()}, \textbf{ OSMO\+\_\+\+SOCK\+\_\+\+NAME\+\_\+\+MAXLEN}, \textbf{ telnet\+\_\+connection\+::priv}, \textbf{ tall\+\_\+telnet\+\_\+ctx}, \textbf{ telnet\+\_\+connection\+::vty}, \textbf{ vty\+\_\+create()}, and \textbf{ osmo\+\_\+fd\+::when}.

\mbox{\label{telnet__interface_8c_aaf9ba164ccec77fa93ab502ee8837689}} 
\index{telnet\_interface.c@{telnet\_interface.c}!vty\_event@{vty\_event}}
\index{vty\_event@{vty\_event}!telnet\_interface.c@{telnet\_interface.c}}
\doxysubsubsection{vty\_event()}
{\footnotesize\ttfamily void vty\+\_\+event (\begin{DoxyParamCaption}\item[{enum \textbf{ event} \textbf{ event} \textbf{ event}}]{,  }\item[{int}]{sock,  }\item[{struct \textbf{ vty} $\ast$}]{vty }\end{DoxyParamCaption})}



callback from core VTY code about VTY related events 



References \textbf{ vty\+\_\+signal\+\_\+data\+::event}, \textbf{ telnet\+\_\+connection\+::fd}, \textbf{ OSMO\+\_\+\+FD\+\_\+\+READ}, \textbf{ OSMO\+\_\+\+FD\+\_\+\+WRITE}, \textbf{ osmo\+\_\+signal\+\_\+dispatch()}, \textbf{ vty\+::priv}, \textbf{ S\+\_\+\+VTY\+\_\+\+EVENT}, \textbf{ vty\+\_\+signal\+\_\+data\+::sock}, \textbf{ SS\+\_\+\+L\+\_\+\+VTY}, \textbf{ telnet\+\_\+close\+\_\+client()}, \textbf{ vty\+::type}, \textbf{ vty\+\_\+signal\+\_\+data\+::vty}, \textbf{ vty}, \textbf{ VTY\+\_\+\+CLOSED}, \textbf{ VTY\+\_\+\+READ}, \textbf{ VTY\+\_\+\+TERM}, \textbf{ VTY\+\_\+\+WRITE}, and \textbf{ osmo\+\_\+fd\+::when}.



Referenced by \textbf{ vty\+\_\+close()}, \textbf{ vty\+\_\+create()}, \textbf{ vty\+\_\+out\+\_\+va()}, and \textbf{ vty\+\_\+read()}.



\doxysubsection{Variable Documentation}
\mbox{\label{telnet__interface_8c_a84b19c19fcddc4f46865dd8eae58046d}} 
\index{telnet\_interface.c@{telnet\_interface.c}!server\_socket@{server\_socket}}
\index{server\_socket@{server\_socket}!telnet\_interface.c@{telnet\_interface.c}}
\doxysubsubsection{server\_socket}
{\footnotesize\ttfamily struct \textbf{ osmo\+\_\+fd} server\+\_\+socket\hspace{0.3cm}{\ttfamily [static]}}

{\bfseries Initial value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{= \{}
\DoxyCodeLine{        .when       = OSMO\_FD\_READ,}
\DoxyCodeLine{        .cb         = telnet\_new\_connection,}
\DoxyCodeLine{        .priv\_nr    = 0,}
\DoxyCodeLine{\}}

\end{DoxyCode}


Referenced by \textbf{ \+\_\+telnet\+\_\+init\+\_\+dynif()}, and \textbf{ telnet\+\_\+exit()}.

\mbox{\label{telnet__interface_8c_a15207fec8d58e89bf9714801727db013}} 
\index{telnet\_interface.c@{telnet\_interface.c}!tall\_telnet\_ctx@{tall\_telnet\_ctx}}
\index{tall\_telnet\_ctx@{tall\_telnet\_ctx}!telnet\_interface.c@{telnet\_interface.c}}
\doxysubsubsection{tall\_telnet\_ctx}
{\footnotesize\ttfamily void$\ast$ tall\+\_\+telnet\+\_\+ctx\hspace{0.3cm}{\ttfamily [static]}}



Referenced by \textbf{ \+\_\+telnet\+\_\+init\+\_\+dynif()}, \textbf{ telnet\+\_\+exit()}, and \textbf{ telnet\+\_\+new\+\_\+connection()}.

