1<!-- Creator     : groff version 1.22.2 -->
2<!-- CreationDate: Thu Feb  2 22:36:46 2017 -->
3<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
4"http://www.w3.org/TR/html4/loose.dtd">
5<html>
6<head>
7<meta name="generator" content="groff -Thtml, see www.gnu.org">
8<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
9<meta name="Content-Style" content="text/css">
10<style type="text/css">
11       p       { margin-top: 0; margin-bottom: 0; vertical-align: top }
12       pre     { margin-top: 0; margin-bottom: 0; vertical-align: top }
13       table   { margin-top: 0; margin-bottom: 0; vertical-align: top }
14       h1      { text-align: center }
15</style>
16<title>mtcp_getsockopt</title>
17
18</head>
19<body>
20
21<h1 align="center">mtcp_getsockopt</h1>
22
23<a href="#NAME">NAME</a><br>
24<a href="#SYNOPSIS">SYNOPSIS</a><br>
25<a href="#DESCRIPTION">DESCRIPTION</a><br>
26<a href="#RETURN VALUE">RETURN VALUE</a><br>
27<a href="#ERRORS">ERRORS</a><br>
28<a href="#AUTHORS">AUTHORS</a><br>
29<a href="#SEE ALSO">SEE ALSO</a><br>
30<a href="#COLOPHON">COLOPHON</a><br>
31
32<hr>
33
34
35<h2>NAME
36<a name="NAME"></a>
37</h2>
38
39
40
41<p style="margin-left:11%; margin-top: 1em">mtcp_getsockopt
42&minus; get options on mTCP/mOS sockets</p>
43
44<h2>SYNOPSIS
45<a name="SYNOPSIS"></a>
46</h2>
47
48
49<p style="margin-left:11%; margin-top: 1em"><b>#include
50&lt;mtcp_api.h&gt;</b></p>
51
52<p style="margin-left:11%; margin-top: 1em"><b>int
53mtcp_getsockopt(mctx_t</b> <i>mctx</i><b>, int</b>
54<i>sockid</i><b>, int</b> <i>level</i><b>, int</b>
55<i>optname</i><b>, const void *</b><i>optval</i><b>,
56socklen_t *</b><i>optlen</i><b>);</b></p>
57
58<h2>DESCRIPTION
59<a name="DESCRIPTION"></a>
60</h2>
61
62
63
64<p style="margin-left:11%; margin-top: 1em"><b>mtcp_getsockopt</b>()
65manipulate options for the socket referred to by the
66<i>sockid</i> descriptor. These options may exist at
67multiple protocol levels. When manipulating socket options,
68the level at which the options resides and the name of the
69option must be specified. A user can use <b>SOL_SOCKET</b>
70<i>level</i> to adjust these options for mTCP endpoint
71applications; while <b>SOL_MONSOCKET</b> <i>level</i> can be
72used to adjust options for monitoring sockets.</p>
73
74<p style="margin-left:11%; margin-top: 1em">For
75<b>mtcp_getsockopt()</b> <i>optval</i> identifies the buffer
76in which the value for the requested option is to be
77returned and the <i>optlen</i> argument is updated to
78indicate the actual size of the <i>optval</i> returned. It
79is the user&rsquo;s responsibility to allocate memory for
80both <i>optval</i> and <i>optlen</i> arguments.</p>
81
82<p style="margin-left:11%; margin-top: 1em">At the moment,
83mOS only provides one <i>optname</i> named <b>SO_ERROR</b>
84that can only be used for <b>mtcp_getsockopt()</b> function
85for SOL_SOCKET socket <i>level</i> with the specified option
86name returns the most recently recorded socket error for the
87particular connection (specific to the <i>sockid</i> socket
88descriptor).</p>
89
90<p style="margin-left:11%; margin-top: 1em">SOL_MONSOCKET
91socket <i>level</i> can be used by <b>mtcp_getsockopt()</b>
92to retrieve a number of socket options.</p>
93
94<table width="100%" border="0" rules="none" frame="void"
95       cellspacing="0" cellpadding="0">
96<tr valign="top" align="left">
97<td width="11%"></td>
98<td width="29%">
99
100
101<p style="margin-top: 1em">MOS_FRAGINFO_CLIBUF</p></td>
102<td width="9%"></td>
103<td width="51%">
104
105
106<p style="margin-top: 1em">Gives back offsets to fragments
107(non-contiguous data segments) currently stored in
108client&rsquo;s TCP ring buffer. The <i>optval</i> is an
109array of struct tcp_ring_fragment which is defined as:</p></td></tr>
110</table>
111
112<p style="margin-left:49%; margin-top: 1em">struct
113tcp_ring_fragment { <br>
114uint64_t offset; <br>
115uint32_t len; <br>
116}</p>
117
118<p style="margin-left:49%; margin-top: 1em">where offset
119flow data starting from client&rsquo;s TCP SYN sequence
120number, and len is the length of the tcp_ring_fragment. The
121<i>optval</i> holds the size of the array (in terms of the
122number of elements).</p>
123
124<table width="100%" border="0" rules="none" frame="void"
125       cellspacing="0" cellpadding="0">
126<tr valign="top" align="left">
127<td width="11%"></td>
128<td width="29%">
129
130
131<p style="margin-top: 1em">MOS_FRAGINFO_SVRBUF</p></td>
132<td width="9%"></td>
133<td width="51%">
134
135
136<p style="margin-top: 1em">Gives back offsets to fragments
137(non-contiguous data segments) currently stored in
138server&rsquo;s TCP ring buffer. The <i>optval</i> is the
139array of struct tcp_ring_fragment</p></td></tr>
140</table>
141
142<p style="margin-left:49%; margin-top: 1em">where offset
143flow data starting from server&rsquo;s TCP SYN sequence
144number, and len is the length of the tcp_ring_fragment. The
145<i>optlen</i> holds the size of the array (in terms of the
146number of elements).</p>
147
148<table width="100%" border="0" rules="none" frame="void"
149       cellspacing="0" cellpadding="0">
150<tr valign="top" align="left">
151<td width="11%"></td>
152<td width="23%">
153
154
155<p style="margin-top: 1em">MOS_INFO_CLIBUF</p></td>
156<td width="15%"></td>
157<td width="51%">
158
159
160<p style="margin-top: 1em">Returns meta-data regarding the
161client&rsquo;s TCP ring buffer. This information is returned
162in the form of <i>optval</i> which is passed as struct
163tcp_buf_info.</p> </td></tr>
164</table>
165
166<p style="margin-left:49%; margin-top: 1em">struct
167tcp_buf_info { <br>
168/* The initial TCP sequence number <br>
169of TCP ring buffer. */ <br>
170uint32_t tcpbi_init_seq;</p>
171
172<p style="margin-left:49%; margin-top: 1em">/* TCP sequence
173number of the &rsquo;last <br>
174byte of payload that has already <br>
175been read by the end application&rsquo; <br>
176(applies in the case of embedded <br>
177monitor setup) */ <br>
178uint32_t tcpbi_last_byte_read;</p>
179
180<p style="margin-left:49%; margin-top: 1em">/* TCP sequence
181number of the &rsquo;last <br>
182byte of the payload that is <br>
183currently buffered and needs to <br>
184be read by the end application&rsquo; <br>
185(applies in the case of embedded <br>
186monitor setup). In case of standalone <br>
187monitors, tcpbi_last_byte_read = <br>
188tcpbi_next_byte_expected */ <br>
189uint32_t tcpbi_next_byte_expected;</p>
190
191<p style="margin-left:49%; margin-top: 1em">/* TCP sequence
192number of the &rsquo;last <br>
193byte of the payload that is <br>
194currently stored&rsquo; in the TCP <br>
195ring buffer. This value may be <br>
196greater than tcpbi_next_byte_expected <br>
197if packets arrive out of order. */ <br>
198uint32_t tcpbi_last_byte_received; <br>
199}</p>
200
201<p style="margin-left:49%; margin-top: 1em">The
202<i>optlen</i> value contains the sizeof(struct
203tcp_buf_info).</p>
204
205<table width="100%" border="0" rules="none" frame="void"
206       cellspacing="0" cellpadding="0">
207<tr valign="top" align="left">
208<td width="11%"></td>
209<td width="26%">
210
211
212<p style="margin-top: 1em">MOS_INFO_SVRBUF</p></td>
213<td width="12%"></td>
214<td width="51%">
215
216
217<p style="margin-top: 1em">Returns meta-data regarding the
218server&rsquo;s TCP ring buffer. This information is returned
219in the form of <i>optval</i> which is passed as struct
220tcp_buf_info. The <i>optlen</i> value contains the
221sizeof(struct tcp_buf_info).</p></td></tr>
222<tr valign="top" align="left">
223<td width="11%"></td>
224<td width="26%">
225
226
227<p>MOS_TCP_STATE_CLI</p></td>
228<td width="12%"></td>
229<td width="51%">
230
231
232<p>Returns the current emulated state of the client. The
233<i>optval</i> argument is a pointer to an int whereas the
234<i>optlen</i> argument contains the sizeof(int). The optval
235returns a value of type enum tcpstate which can carry any
236one of the following states.</p></td></tr>
237</table>
238
239<p style="margin-left:49%; margin-top: 1em">enum tcpstate {
240<br>
241TCP_CLOSED = 0, <br>
242TCP_LISTEN, <br>
243TCP_SYN_SENT, <br>
244TCP_SYN_RCVD, <br>
245TCP_ESTABLISHED, <br>
246TCP_FIN_WAIT_1, <br>
247TCP_FINE_WAIT_2, <br>
248TCP_CLOSE_WAIT, <br>
249TCP_CLOSING, <br>
250TCP_LAST_ACK, <br>
251TCP_TIME_WAIT <br>
252}</p>
253
254<table width="100%" border="0" rules="none" frame="void"
255       cellspacing="0" cellpadding="0">
256<tr valign="top" align="left">
257<td width="11%"></td>
258<td width="26%">
259
260
261<p style="margin-top: 1em">MOS_TCP_STATE_SVR</p></td>
262<td width="12%"></td>
263<td width="51%">
264
265
266<p style="margin-top: 1em">Returns the current emulated
267state of the server. The <i>optval</i> argument is a pointer
268to an int whereas the <i>optlen</i> argument contains the
269sizeof(int). The optval returns a value of type enum
270tcpstate.</p> </td></tr>
271</table>
272
273<p style="margin-left:11%; margin-top: 1em">Both the
274functions take an additional argument named <i>mctx</i> that
275represent the per-core mTCP context in an application (see
276<b>mtcp_create_context()</b> for details).</p>
277
278<h2>RETURN VALUE
279<a name="RETURN VALUE"></a>
280</h2>
281
282
283<p style="margin-left:11%; margin-top: 1em">Returns 0 on
284success; -1 on failure. In case of failure, <i>errno</i> is
285set appropriately.</p>
286
287<h2>ERRORS
288<a name="ERRORS"></a>
289</h2>
290
291
292<table width="100%" border="0" rules="none" frame="void"
293       cellspacing="0" cellpadding="0">
294<tr valign="top" align="left">
295<td width="11%"></td>
296<td width="12%">
297
298
299<p style="margin-top: 1em"><b>EACCES</b></p></td>
300<td width="3%"></td>
301<td width="74%">
302
303
304<p style="margin-top: 1em"><i>mctx</i> is not valid.</p></td></tr>
305<tr valign="top" align="left">
306<td width="11%"></td>
307<td width="12%">
308
309
310<p><b>EBADF</b></p></td>
311<td width="3%"></td>
312<td width="74%">
313
314
315<p><i>sockid</i> is not a valid socket descriptor.</p></td></tr>
316<tr valign="top" align="left">
317<td width="11%"></td>
318<td width="12%">
319
320
321<p><b>ENOTSOCK</b></p></td>
322<td width="3%"></td>
323<td width="74%">
324
325
326<p>The socket referred to by <i>sockid</i> is not
327valid.</p> </td></tr>
328<tr valign="top" align="left">
329<td width="11%"></td>
330<td width="12%">
331
332
333<p><b>ENOSYS</b></p></td>
334<td width="3%"></td>
335<td width="74%">
336
337
338<p>Either the <i>level</i> or the <i>optname</i> is not
339implemented.</p> </td></tr>
340<tr valign="top" align="left">
341<td width="11%"></td>
342<td width="12%">
343
344
345<p><b>EPERM</b></p></td>
346<td width="3%"></td>
347<td width="74%">
348
349
350<p>Permission to access a socket option is denied.</p></td></tr>
351</table>
352
353<h2>AUTHORS
354<a name="AUTHORS"></a>
355</h2>
356
357
358<p style="margin-left:22%; margin-top: 1em">mOS development
359team &lt;[email protected]&gt;</p>
360
361<h2>SEE ALSO
362<a name="SEE ALSO"></a>
363</h2>
364
365
366
367<p style="margin-left:11%; margin-top: 1em"><b>mtcp_socket</b>(),
368<b>mtcp_setsockopt</b>()</p>
369
370<h2>COLOPHON
371<a name="COLOPHON"></a>
372</h2>
373
374
375<p style="margin-left:11%; margin-top: 1em">This page is
376part of mOS release 0.3 <i>docs</i> section. A description
377of the project, and information about reporting bugs, can be
378found at http://mos.kaist.edu/.</p>
379<hr>
380</body>
381</html>
382