\hypertarget{socket_8h}{
\section{include/socket.h File Reference}
\label{socket_8h}\index{include/socket.h@{include/socket.h}}
}
{\ttfamily \#include $<$arpa/inet.h$>$}\par
{\ttfamily \#include \char`\"{}class.h\char`\"{}}\par
{\ttfamily \#include \char`\"{}logger.h\char`\"{}}\par
Include dependency graph for socket.h:
This graph shows which files directly or indirectly include this file:
\subsection*{Classes}
\begin{DoxyCompactItemize}
\item 
struct \hyperlink{structSock}{Sock}
\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \hyperlink{socket_8h_adbfc4792c437102f20e2c86c4ee8581b}{socketConnect} (\hyperlink{structSock}{Sock} this, const char $\ast$addr)
\item 
void \hyperlink{socket_8h_a757c220e9371523ef55b1137a1efed57}{socketListen} (\hyperlink{structSock}{Sock} this, int backlog)
\item 
\hyperlink{structSock}{Sock} \hyperlink{socket_8h_a46aa6b495ccf752e844f93bf46c9edd6}{socketAccept} (\hyperlink{structSock}{Sock} this, char remoteAddr\mbox{[}16\mbox{]})
\end{DoxyCompactItemize}


\subsection{Function Documentation}
\hypertarget{socket_8h_a46aa6b495ccf752e844f93bf46c9edd6}{
\index{socket.h@{socket.h}!socketAccept@{socketAccept}}
\index{socketAccept@{socketAccept}!socket.h@{socket.h}}
\subsubsection[{socketAccept}]{\setlength{\rightskip}{0pt plus 5cm}{\bf Sock} socketAccept (
\begin{DoxyParamCaption}
\item[{{\bf Sock}}]{this, }
\item[{char}]{remoteAddr\mbox{[}16\mbox{]}}
\end{DoxyParamCaption}
)}}
\label{socket_8h_a46aa6b495ccf752e844f93bf46c9edd6}


: Uhh, this is bad. we open a new socket additionally to the one we get from the accept call. i have to change the socket constructor to be able to create the data structure without creation of a socket at all. For now i simply close the socket here.... :D

: change port to remote port on success



Definition at line 9 of file accept.c.


\begin{DoxyCode}
{
    Sock         sock;   /* Socket for client */
    unsigned int len;    /* Length of client address data structure */

    /* Set the size of the in-out parameter */
    len = sizeof(this->addr);

        sock = new(Sock, this->log, this->port);
        close(sock->handle);
    /* Wait for a client to connect */
    sock->handle = accept(this->handle, (struct sockaddr *) &(sock->addr), &len);
      
    if (-1 == sock->handle) {
        loggerLog(this->log, LOGGER_WARNING,
                "error accepting connection: %s", strerror(errno));
    } else {
        loggerLog(this->log, LOGGER_INFO,
                                "handling client %s\n", inet_ntoa((sock->addr).si
      n_addr));
    }

    return sock;
}
\end{DoxyCode}


Here is the call graph for this function:


\hypertarget{socket_8h_adbfc4792c437102f20e2c86c4ee8581b}{
\index{socket.h@{socket.h}!socketConnect@{socketConnect}}
\index{socketConnect@{socketConnect}!socket.h@{socket.h}}
\subsubsection[{socketConnect}]{\setlength{\rightskip}{0pt plus 5cm}void socketConnect (
\begin{DoxyParamCaption}
\item[{{\bf Sock}}]{this, }
\item[{const char $\ast$}]{addr}
\end{DoxyParamCaption}
)}}
\label{socket_8h_adbfc4792c437102f20e2c86c4ee8581b}


Definition at line 10 of file connect.c.


\begin{DoxyCode}
{
        inet_pton(AF_INET, addr, &((this->addr).sin_addr));
    (this->addr).sin_family = AF_INET;           /* Internet address family */
    (this->addr).sin_port   = htons(this->port); /* Local port */

        if (-1 == connect(this->handle, (struct sockaddr*) &(this->addr), sizeof(
      this->addr))) {
        loggerLog(this->log, LOGGER_CRIT,
                "error connection socket: %s - service terminated",
                strerror(errno));
        exit(EXIT_FAILURE);
    }
}
\end{DoxyCode}


Here is the call graph for this function:


\hypertarget{socket_8h_a757c220e9371523ef55b1137a1efed57}{
\index{socket.h@{socket.h}!socketListen@{socketListen}}
\index{socketListen@{socketListen}!socket.h@{socket.h}}
\subsubsection[{socketListen}]{\setlength{\rightskip}{0pt plus 5cm}void socketListen (
\begin{DoxyParamCaption}
\item[{{\bf Sock}}]{this, }
\item[{int}]{backlog}
\end{DoxyParamCaption}
)}}
\label{socket_8h_a757c220e9371523ef55b1137a1efed57}


Definition at line 10 of file listen.c.


\begin{DoxyCode}
{
    (this->addr).sin_family      = AF_INET;           /* Internet address family 
      */
    (this->addr).sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming interface *
      /
    (this->addr).sin_port        = htons(this->port); /* Local port */

    /* Bind to the local address */
    if (-1 == bind(this->handle, (struct sockaddr *) &(this->addr), sizeof(this->
      addr))) {
        loggerLog(this->log, LOGGER_CRIT,
                "error binding socket: %s - service terminated",
                strerror(errno));
        exit(EXIT_FAILURE);
    }

    /* Mark the socket so it will listen for incoming connections */
    if (-1 == listen(this->handle, backlog)) {
        loggerLog(this->log, LOGGER_CRIT,
                "error binding socket: %s - service terminated",
                strerror(errno));
        exit(EXIT_FAILURE);
    }
}
\end{DoxyCode}


Here is the call graph for this function:


