socket_8h.tex
4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
\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 8 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: