\section{libcomm.c File Reference}
\label{libcomm_8c}\index{libcomm.c@{libcomm.c}}
Main part of libcomm. 


{\tt \#include $<$stdio.h$>$}\par
{\tt \#include $<$stdlib.h$>$}\par
{\tt \#include $<$sys/types.h$>$}\par
{\tt \#include $<$sys/socket.h$>$}\par
{\tt \#include $<$sys/time.h$>$}\par
{\tt \#include $<$unistd.h$>$}\par
{\tt \#include $<$sys/poll.h$>$}\par
{\tt \#include $<$string.h$>$}\par
{\tt \#include \char`\"{}libcomm.h\char`\"{}}\par
{\tt \#include \char`\"{}md5.h\char`\"{}}\par
{\tt \#include $<$pthread.h$>$}\par
{\tt \#include $<$netinet/in.h$>$}\par
{\tt \#include $<$netdb.h$>$}\par
{\tt \#include $<$arpa/inet.h$>$}\par
\subsection*{Functions}
\begin{CompactItemize}
\item 
void {\bf socket\_\-accept\_\-thread} (struct {\bf LIBCOMMPTHREADP} $\ast$libcommpthreadp)
\begin{CompactList}\small\item\em This is a part of {\bf socket\_\-accept}() {\rm (p.\,\pageref{libcomm_8c_a1})} and must not called from the user.\item\end{CompactList}\item 
int {\bf socket\_\-accept} (int sockport, int id, void($\ast$socket\_\-accept\_\-do)(int fd, int id, char $\ast$pip, struct sockaddr\_\-in their\_\-addr))
\begin{CompactList}\small\item\em Start a new thread, wait for connections and start socket\_\-accept\_\-do() when someone connects.\item\end{CompactList}\item 
int {\bf socket\_\-bind} (int port, int cqueue)
\begin{CompactList}\small\item\em Bind a socket to a port (Server side).\item\end{CompactList}\item 
int {\bf socket\_\-connect} (char $\ast$host, int port)
\begin{CompactList}\small\item\em Connect a TCP-stream to a server (Client side).\item\end{CompactList}\item 
char $\ast$ {\bf block\_\-random} (char $\ast$buf, int size)
\begin{CompactList}\small\item\em Get random numbers/bytes.\item\end{CompactList}\item 
void {\bf thread1} (struct {\bf LIBCOMMPTHREADS} $\ast$libcommpthreads)
\begin{CompactList}\small\item\em This is a part of {\bf block\_\-call}() {\rm (p.\,\pageref{libcomm_8c_a6})} and must not called from the user.\item\end{CompactList}\item 
int {\bf block\_\-call} (int fd, int id, int term, void($\ast$block\_\-call\_\-do)(int fd, int id, unsigned int type, char $\ast$buf, unsigned int size, int term), void($\ast$block\_\-call\_\-term)(int fd, int id))
\begin{CompactList}\small\item\em Waits in a new thread for a datablock to be received and calls the function block\_\-call\_\-do() if this event occurs or block\_\-call\_\-term() when the connection terminates.\item\end{CompactList}\item 
int {\bf block\_\-ifdata} (int fd)
\begin{CompactList}\small\item\em This function tests if new data is available to read on a stream.\item\end{CompactList}\item 
char $\ast$ {\bf block\_\-receive\_\-poll} (int fd, unsigned int $\ast$type, char $\ast$buf, unsigned int $\ast$size, unsigned int maxsize, int term)
\begin{CompactList}\small\item\em Test if is there data available on the socket's input buffer and starts receiving a block if there is.\item\end{CompactList}\item 
char $\ast$ {\bf block\_\-receive} (int fd, unsigned int $\ast$type, char $\ast$buf, unsigned int $\ast$size, unsigned int maxsize, int term)
\begin{CompactList}\small\item\em Receive a block (composition of: type, size of datablock and datablock) from a socket.\item\end{CompactList}\item 
int {\bf block\_\-receive\_\-integer} (int fd, unsigned int $\ast$recvi)
\begin{CompactList}\small\item\em Receive an integer (two bytes; 16Bit) from the socket.\item\end{CompactList}\item 
int {\bf block\_\-receive\_\-nbytes} (int fd, char $\ast$buf, int n)
\begin{CompactList}\small\item\em Receive n bytes from socket.\item\end{CompactList}\item 
int {\bf block\_\-send} (int fd, unsigned int type, char $\ast$buf, unsigned int size)
\begin{CompactList}\small\item\em Send a block (composition of: type, size of datablock and datablock (buf)) to a socket.\item\end{CompactList}\item 
void {\bf free\_\-authinfo} (struct {\bf AUTHINFO} $\ast$destroy)
\begin{CompactList}\small\item\em Free the memory space which is used by an {\bf AUTHINFO} {\rm (p.\,\pageref{structAUTHINFO})} structure.\item\end{CompactList}\item 
int {\bf socket\_\-md5auth} (int fd, char $\ast$netname, char $\ast$name, struct {\bf AUTHINFO} $\ast$$\ast$plocallogin, struct {\bf AUTHINFO} $\ast$$\ast$premotelogin)
\begin{CompactList}\small\item\em Do both side authentification.\item\end{CompactList}\item 
{\bf AUTHINFO} $\ast$ {\bf getauthinfo} (char $\ast$netname, char $\ast$name)
\begin{CompactList}\small\item\em Load authentication informations (netname, name, passwd, keyencrypt, keydecrypt) from authfile.\item\end{CompactList}\item 
void {\bf linemonitor\_\-server\_\-thread} (struct {\bf LINEMONITOR\_\-THREAD\_\-DATA} $\ast$linemonitor\_\-thread\_\-data)
\begin{CompactList}\small\item\em Thread used by {\bf linemonitor\_\-server}() {\rm (p.\,\pageref{libcomm_8c_a17})} NOT for direct usage.\item\end{CompactList}\item 
int {\bf linemonitor\_\-server} (int port, int {\bf soft\_\-msec}, int {\bf hard\_\-msec}, int {\bf wait\_\-msec}, void($\ast$linemonitor\_\-exception)(char $\ast$server, int port, int type))
\begin{CompactList}\small\item\em Monitor if the \char`\"{}line\char`\"{} is fast enough: Server Application.\item\end{CompactList}\item 
void {\bf linemonitor\_\-emergencystop} (int {\bf sock})
\begin{CompactList}\small\item\em Sends an \char`\"{}Emergency Stop\char`\"{} to the client's side, {\bf linemonitor}() {\rm (p.\,\pageref{libcomm_8c_a20})} will produce an \char`\"{}Emergency Stop\char`\"{} exception (type 4).\item\end{CompactList}\item 
int {\bf linemonitor\_\-thread} (struct {\bf LINEMONITOR\_\-THREAD\_\-DATA} $\ast$linemonitor\_\-thread\_\-data)
\begin{CompactList}\small\item\em Thread used by {\bf linemonitor}() {\rm (p.\,\pageref{libcomm_8c_a20})} NOT for direct usage.\item\end{CompactList}\item 
int {\bf linemonitor} (char $\ast$server, int port, int {\bf soft\_\-msec}, int {\bf hard\_\-msec}, int {\bf wait\_\-msec}, void($\ast$linemonitor\_\-exception)(char $\ast$server, int port, int type))
\begin{CompactList}\small\item\em Monitor if the \char`\"{}line\char`\"{} is fast enough: Client/Robot Application.\item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Main part of libcomm.





\subsection{Function Documentation}
\index{libcomm.c@{libcomm.c}!block_call@{block\_\-call}}
\index{block_call@{block\_\-call}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int block\_\-call (int {\em fd}, int {\em id}, int {\em term}, void($\ast$ {\em block\_\-call\_\-do})(int fd, int id, unsigned int type, char $\ast$buf, unsigned int size, int term), void($\ast$ {\em block\_\-call\_\-term})(int fd, int id))}\label{libcomm_8c_a6}


Waits in a new thread for a datablock to be received and calls the function block\_\-call\_\-do() if this event occurs or block\_\-call\_\-term() when the connection terminates.

\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
fd}](int) descriptor of socket\item[{\em 
id}](int) arbitrary id of background process / thread\item[{\em 
term}](int) 0: do not terminate the buffer, 1: terminate the buffer by appending a 0x00.\item[{\em 
block\_\-call\_\-do}](int fd, int id, unsigned int type, char $\ast$buf, unsigned int size, int term) (function) this function is called if a datablock was received. fd, id and term are the same as in {\bf block\_\-call}() {\rm (p.\,\pageref{libcomm_8c_a6})}. type describes the type of the received datablock, buf is a pointer to this datablock and size is the number of bytes of the datablock\item[{\em 
block\_\-call\_\-term}](int fd, int id) (function) this function is called if the connection terminates. fd and id are the same as in {\bf block\_\-call}() {\rm (p.\,\pageref{libcomm_8c_a6})}.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
If all right zero otherwise non zero. \end{Desc}
\index{libcomm.c@{libcomm.c}!block_ifdata@{block\_\-ifdata}}
\index{block_ifdata@{block\_\-ifdata}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int block\_\-ifdata (int {\em fd})}\label{libcomm_8c_a7}


This function tests if new data is available to read on a stream.

\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
fd}](int) discriptor of stream to test\end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
(int) 1: Data to read; 0: No data to read \end{Desc}
\index{libcomm.c@{libcomm.c}!block_random@{block\_\-random}}
\index{block_random@{block\_\-random}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}char$\ast$ block\_\-random (char $\ast$ {\em buf}, int {\em size})}\label{libcomm_8c_a4}


Get random numbers/bytes.

This function reads random numbers/bytes from /dev/urandom and stores this bytes in a buffer.\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
buf}](char $\ast$) in which the bytes will be stored. If this parameter is equal to NULL dynamic memory will be allocated.\item[{\em 
size}]an integer, specifies ths size of the buffer (the number of the random bytes). WARNING: If buf is not equal to null, n$\ast$(size) bytes will be stored in this buffer without any check of ths size of this buf.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
(char $\ast$) a pointer to the buffer in which the random bytes are stored. \end{Desc}
\index{libcomm.c@{libcomm.c}!block_receive@{block\_\-receive}}
\index{block_receive@{block\_\-receive}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}char$\ast$ block\_\-receive (int {\em fd}, unsigned int $\ast$ {\em type}, char $\ast$ {\em buf}, unsigned int $\ast$ {\em size}, unsigned int {\em maxsize}, int {\em term})}\label{libcomm_8c_a9}


Receive a block (composition of: type, size of datablock and datablock) from a socket.

Waits for a block to be received completely. WARNING: The integers (type and size; excluding fd) are only 16 bit values (0 - 65535).\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
fd}](int) descriptor of socket\item[{\em 
type}](unsigned int $\ast$) pointer to integer, this value can be used as buyer's option\item[{\em 
buf}](char $\ast$) buffer for datablock. Memory will be allocated if this parameter is equal to null.\item[{\em 
size}](unsigned int $\ast$) pointer to integer in which the size of the received datablock is saved.\item[{\em 
maxsize}](unsigned int $\ast$) describes size of buf. This parameter will be ignored if buf is equal to null.\item[{\em 
term}](int) 0: do not terminate the buffer, 1: terminate the buffer by appending a 0x00.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
(char $\ast$) pointer to buffer which contains the received datablock; NULL if fail. \end{Desc}
\index{libcomm.c@{libcomm.c}!block_receive_integer@{block\_\-receive\_\-integer}}
\index{block_receive_integer@{block\_\-receive\_\-integer}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int block\_\-receive\_\-integer (int {\em fd}, unsigned int $\ast$ {\em recvi})}\label{libcomm_8c_a10}


Receive an integer (two bytes; 16Bit) from the socket.

\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
fd}](int) descriptor of socket\item[{\em 
recvi}](unsigned int $\ast$) pointer to integer in which the received integer is saved.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
(int) 2: OK; -1: fail \end{Desc}
\index{libcomm.c@{libcomm.c}!block_receive_nbytes@{block\_\-receive\_\-nbytes}}
\index{block_receive_nbytes@{block\_\-receive\_\-nbytes}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int block\_\-receive\_\-nbytes (int {\em fd}, char $\ast$ {\em buf}, int {\em n})}\label{libcomm_8c_a11}


Receive n bytes from socket.

\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
fd}](integer) descriptor of socket\item[{\em 
buf}](char $\ast$) buffer for saving the received bytes\item[{\em 
n}](integer) number of bytes to receive\end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
(integer) n: OK; -1 fial \end{Desc}
\index{libcomm.c@{libcomm.c}!block_receive_poll@{block\_\-receive\_\-poll}}
\index{block_receive_poll@{block\_\-receive\_\-poll}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}char$\ast$ block\_\-receive\_\-poll (int {\em fd}, unsigned int $\ast$ {\em type}, char $\ast$ {\em buf}, unsigned int $\ast$ {\em size}, unsigned int {\em maxsize}, int {\em term})}\label{libcomm_8c_a8}


Test if is there data available on the socket's input buffer and starts receiving a block if there is.

WARNING: The integers (type and size; excluding fd) are only 16 bit values (0 - 65535).\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
fd}](int) descriptor of socket\item[{\em 
type}](unsigned int $\ast$) pointer to integer, this value can be used as buyer's option\item[{\em 
buf}](char $\ast$) buffer for datablock. Memory will be allocated if this parameter is equal to null.\item[{\em 
size}](unsigned int $\ast$) pointer to integer in which the size of the received datablock is saved.\item[{\em 
maxsize}](unsigned int $\ast$) describes size of buf. This parameter will be ignored if buf is equal to null.\item[{\em 
term}](int) 0: do not terminate the buffer, 1: terminate the buffer by appending a 0x00.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
(char $\ast$) pointer to buffer which contains the received datablock; NULL if fail; 1 if no data available. \end{Desc}
\index{libcomm.c@{libcomm.c}!block_send@{block\_\-send}}
\index{block_send@{block\_\-send}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int block\_\-send (int {\em fd}, unsigned int {\em type}, char $\ast$ {\em buf}, unsigned int {\em size})}\label{libcomm_8c_a12}


Send a block (composition of: type, size of datablock and datablock (buf)) to a socket.

The function blocks until the whole block is transfered to the buffer. If the buffer is full, data has to be sent first. WARNING: The integers (type and size; excluding fd) are only 16 bit values (0 - 65535).\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
fd}](int) descriptor of the socket to which buf should send\item[{\em 
type}](unsigned int) This value can be used as buyer's option\item[{\em 
buf}](char $\ast$) which should be send\end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
number of sent bytes, -1 if an error is occurt. \end{Desc}
\index{libcomm.c@{libcomm.c}!free_authinfo@{free\_\-authinfo}}
\index{free_authinfo@{free\_\-authinfo}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void free\_\-authinfo (struct {\bf AUTHINFO} $\ast$ {\em destroy})}\label{libcomm_8c_a13}


Free the memory space which is used by an {\bf AUTHINFO} {\rm (p.\,\pageref{structAUTHINFO})} structure.

\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
struct}]{\bf AUTHINFO} {\rm (p.\,\pageref{structAUTHINFO})} $\ast$) pointer to structure to destroy. \end{description}
\end{Desc}
\index{libcomm.c@{libcomm.c}!getauthinfo@{getauthinfo}}
\index{getauthinfo@{getauthinfo}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}struct {\bf AUTHINFO}$\ast$ getauthinfo (char $\ast$ {\em netname}, char $\ast$ {\em name})}\label{libcomm_8c_a15}


Load authentication informations (netname, name, passwd, keyencrypt, keydecrypt) from authfile.

\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
netname}](char $\ast$) specify the network name (may IP). NULL not specified.\item[{\em 
name}](char $\ast$) specity the login name. NULL not specified.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
(struct {\bf AUTHINFO} {\rm (p.\,\pageref{structAUTHINFO})} $\ast$) the first entry from authfile which matches network name OR login name. If both values are NULL, the first entry of the authfile is given back. \end{Desc}
\index{libcomm.c@{libcomm.c}!linemonitor@{linemonitor}}
\index{linemonitor@{linemonitor}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int linemonitor (char $\ast$ {\em server}, int {\em port}, int {\em soft\_\-msec}, int {\em hard\_\-msec}, int {\em wait\_\-msec}, void($\ast$ {\em linemonitor\_\-exception})(char $\ast$server, int port, int type))}\label{libcomm_8c_a20}


Monitor if the \char`\"{}line\char`\"{} is fast enough: Client/Robot Application.

This function opens a socket stream, sents pings/bytes and wait for them to come back. The soft-timeout will called after soft\_\-msec is timeouted. The hard-timeout will called after soft-timeout was called AND hard\_\-msec is timeouted. wait\_\-msec specifies the time which is waited after a ping is received befor the next one will be launched.\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
server}](char $\ast$) server to be connected\item[{\em 
port}](int) port to be connected\item[{\em 
soft\_\-msec}](int) timeout in milliseconds which causes soft-real-time exception.\item[{\em 
hard\_\-msec}](int) timeout in milliseconds which causes hard-real-time exception.\item[{\em 
wait\_\-msec}](int) timeout for resent -- sending of the next ping.\item[{\em 
linemonitor\_\-exception}](pointer to function) This function will be called if an exception occurs. It becomes the following parameters: server name (char $\ast$) which is always null, port (int): listend port and type (int) of exception which can be: 0: Connicion Fault, 1: Soft Real Time Exception, 2: HARD Real Time Exception, 3: Transmission Fault, 4: Emergency Stop. \end{description}
\end{Desc}
\index{libcomm.c@{libcomm.c}!linemonitor_emergencystop@{linemonitor\_\-emergencystop}}
\index{linemonitor_emergencystop@{linemonitor\_\-emergencystop}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void linemonitor\_\-emergencystop (int {\em sock})}\label{libcomm_8c_a18}


Sends an \char`\"{}Emergency Stop\char`\"{} to the client's side, {\bf linemonitor}() {\rm (p.\,\pageref{libcomm_8c_a20})} will produce an \char`\"{}Emergency Stop\char`\"{} exception (type 4).

\index{libcomm.c@{libcomm.c}!linemonitor_server@{linemonitor\_\-server}}
\index{linemonitor_server@{linemonitor\_\-server}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int linemonitor\_\-server (int {\em port}, int {\em soft\_\-msec}, int {\em hard\_\-msec}, int {\em wait\_\-msec}, void($\ast$ {\em linemonitor\_\-exception})(char $\ast$server, int port, int type))}\label{libcomm_8c_a17}


Monitor if the \char`\"{}line\char`\"{} is fast enough: Server Application.

This function opens a port and wait for the first connection on this port. All data/pings which is sent by this first connection will be sent back. The soft-timeout will called after wait\_\-msec AND soft\_\-msec is timeouted. The hard-timeout will called after soft-timeout was called AND hard\_\-msec is timeouted.\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
port}](int) port which should be listend\item[{\em 
soft\_\-msec}](int) timeout in milliseconds which causes soft-real-time exception.\item[{\em 
hard\_\-msec}](int) timeout in milliseconds which causes hard-real-time exception.\item[{\em 
wait\_\-msec}](int) timeout for resent -- sending of the next ping.\item[{\em 
linemonitor\_\-exception}](pointer to function) This function will be called if an exception occurs. It becomes the following parameters: server name (char $\ast$) which is always null, port (int): listend port and type (int) of exception which can be: 0: Connicion Fault, 1: Soft Real Time Exception, 2: HARD Real Time Exception.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
(int) Filediscriptor to the used socket. Only for usage with {\bf linemonitor\_\-emergencystop}() {\rm (p.\,\pageref{libcomm_8c_a18})}. \end{Desc}
\index{libcomm.c@{libcomm.c}!linemonitor_server_thread@{linemonitor\_\-server\_\-thread}}
\index{linemonitor_server_thread@{linemonitor\_\-server\_\-thread}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void linemonitor\_\-server\_\-thread (struct {\bf LINEMONITOR\_\-THREAD\_\-DATA} $\ast$ {\em linemonitor\_\-thread\_\-data})}\label{libcomm_8c_a16}


Thread used by {\bf linemonitor\_\-server}() {\rm (p.\,\pageref{libcomm_8c_a17})} NOT for direct usage.

\index{libcomm.c@{libcomm.c}!linemonitor_thread@{linemonitor\_\-thread}}
\index{linemonitor_thread@{linemonitor\_\-thread}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int linemonitor\_\-thread (struct {\bf LINEMONITOR\_\-THREAD\_\-DATA} $\ast$ {\em linemonitor\_\-thread\_\-data})}\label{libcomm_8c_a19}


Thread used by {\bf linemonitor}() {\rm (p.\,\pageref{libcomm_8c_a20})} NOT for direct usage.

\index{libcomm.c@{libcomm.c}!socket_accept@{socket\_\-accept}}
\index{socket_accept@{socket\_\-accept}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int socket\_\-accept (int {\em sockport}, int {\em id}, void($\ast$ {\em socket\_\-accept\_\-do})(int fd, int id, char $\ast$pip, struct sockaddr\_\-in their\_\-addr))}\label{libcomm_8c_a1}


Start a new thread, wait for connections and start socket\_\-accept\_\-do() when someone connects.

\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
sockport}](int) descriptor of a tcp socket/port from {\bf socket\_\-bind}() {\rm (p.\,\pageref{libcomm_8c_a2})}\item[{\em 
id}](int) arbitrary id of background process / thread. (May be it is a good idea to use the portnumber.)\item[{\em 
aocket\_\-accept\_\-do}](int fd, int id, char $\ast$pip, struct sockaddr\_\-in their\_\-addr) (function) this function is called if somebody connects. fd is the descriptor of the new socket to the connected tcp-tream. id is the same as in {\bf socket\_\-accept}() {\rm (p.\,\pageref{libcomm_8c_a1})}. pip contains the ip-address of the connected client. The structure their\_\-addr contails all known information about the connected client.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
If all right zero otherwise non zero. \end{Desc}
\index{libcomm.c@{libcomm.c}!socket_accept_thread@{socket\_\-accept\_\-thread}}
\index{socket_accept_thread@{socket\_\-accept\_\-thread}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void socket\_\-accept\_\-thread (struct {\bf LIBCOMMPTHREADP} $\ast$ {\em libcommpthreadp})}\label{libcomm_8c_a0}


This is a part of {\bf socket\_\-accept}() {\rm (p.\,\pageref{libcomm_8c_a1})} and must not called from the user.

This function is the thread which is started from {\bf socket\_\-accept}() {\rm (p.\,\pageref{libcomm_8c_a1})} and runs in background. \index{libcomm.c@{libcomm.c}!socket_bind@{socket\_\-bind}}
\index{socket_bind@{socket\_\-bind}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int socket\_\-bind (int {\em port}, int {\em cqueue})}\label{libcomm_8c_a2}


Bind a socket to a port (Server side).

This function creates a socket and binds it to a local port.\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
port}]an integer which specifies the port\item[{\em 
cqueue}]an integer how many pending connections queue will hold in the waiting queue.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
The File Descriptor (FD) which allows access to the bound port. \end{Desc}
\index{libcomm.c@{libcomm.c}!socket_connect@{socket\_\-connect}}
\index{socket_connect@{socket\_\-connect}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int socket\_\-connect (char $\ast$ {\em host}, int {\em port})}\label{libcomm_8c_a3}


Connect a TCP-stream to a server (Client side).

Creates a socket and connect it over a TCP-stream to the specified port on the specified server.\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
host}]a string (char $\ast$) which specifies the name or the IP-address of the server.\item[{\em 
port}]an integer which specifies the port on the server.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
The File Descriptor (FD) which allows access to the TCP-stream-socket or -1 if the connection fails. \end{Desc}
\index{libcomm.c@{libcomm.c}!socket_md5auth@{socket\_\-md5auth}}
\index{socket_md5auth@{socket\_\-md5auth}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int socket\_\-md5auth (int {\em fd}, char $\ast$ {\em netname}, char $\ast$ {\em name}, struct {\bf AUTHINFO} $\ast$$\ast$ {\em plocallogin}, struct {\bf AUTHINFO} $\ast$$\ast$ {\em premotelogin})}\label{libcomm_8c_a14}


Do both side authentification.

This function is usually called just after a socket stream is established. The function must be called on both sides.

WARNING: This authentication can be bypassed simply by using the multiple session attack if multiple session are allowd and the same password is used for both sides.

Both sides following these steps:

1. get auth info ([login] name, passwd) by using {\bf getauthinfo}() {\rm (p.\,\pageref{libcomm_8c_a15})} from name or netname for remote login

2. generate random numbers

3. exchange (first send, then receive) login names

4. exchange random numbers

5. calculate md5 checksum over the random numbers (received from other side) and the remote passwd.

6. exchange md5 checksums

7. get auth info from name (received from other side) for local login

8. calculate md5 checksum over the local random numbers and the local passwd.

9. check login -- compare the received md5sum (6.) with the generated one (8.); send acknowledgement

10. receive remote acknowledgement

11. return suitable values\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
fd}](int) describes the socket on which the authentication has to be done\item[{\em 
netname}](char $\ast$) use netname to resolve [login] name and passwd of the remote machine (NULL: not specified)\item[{\em 
netname}](char $\ast$) use [login] name to resolve passwd of the remote machine (NULL: not specified; both NULL use first entry in file, see {\bf getauthinfo}() {\rm (p.\,\pageref{libcomm_8c_a15})})\item[{\em 
plocallogin}](struct {\bf AUTHINFO} {\rm (p.\,\pageref{structAUTHINFO})} $\ast$$\ast$) (pointer to pointer to an {\bf AUTHINFO} {\rm (p.\,\pageref{structAUTHINFO})} struct) in this (double pointed) struct the local authinfo will be loaded, if the parameter is not null.\item[{\em 
premotelogin}](struct {\bf AUTHINFO} {\rm (p.\,\pageref{structAUTHINFO})} $\ast$$\ast$) in this (double pointed) struct the remote authinfo will be loaded, if the parameter is not null.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
(int) 0: Authentication/Login OK; -1: remote login error; -2: login error on both sides; -3: local login error; -4: other (network) error; -5: cannot load remote auth info; -6: cannot load local auth info; \end{Desc}
\index{libcomm.c@{libcomm.c}!thread1@{thread1}}
\index{thread1@{thread1}!libcomm.c@{libcomm.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void thread1 (struct {\bf LIBCOMMPTHREADS} $\ast$ {\em libcommpthreads})}\label{libcomm_8c_a5}


This is a part of {\bf block\_\-call}() {\rm (p.\,\pageref{libcomm_8c_a6})} and must not called from the user.

This function is the thread which is started from {\bf block\_\-call}() {\rm (p.\,\pageref{libcomm_8c_a6})} and runs in background.\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
libcommpthreads}](struct {\bf LIBCOMMPTHREADS} {\rm (p.\,\pageref{structLIBCOMMPTHREADS})} $\ast$) holds pointers to the functions to be call, fd (socket discriptor) and id. \end{description}
\end{Desc}
