1<!-- Creator     : groff version 1.22.2 -->
2<!-- CreationDate: Sat Feb  4 18:32:18 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_getlastpkt</title>
17
18</head>
19<body>
20
21<h1 align="center">mtcp_getlastpkt</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_getlastpkt
42&minus; Retrieves the last Ethernet frame of a monitoring
43flow</p>
44
45<h2>SYNOPSIS
46<a name="SYNOPSIS"></a>
47</h2>
48
49
50<p style="margin-left:11%; margin-top: 1em"><b>#include
51&lt;mos_api.h&gt;</b></p>
52
53<p style="margin-left:11%; margin-top: 1em"><b>int
54mtcp_getlastpkt(mctx_t</b> <i>mctx</i><b>, int</b>
55<i>sockid</i><b>, int</b> <i>side</i><b>, struct pkt_info
56*</b><i>pinfo</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_getlastpkt</b>()
65fetches a copy of the last Ethernet frame for a given flow
66observed by the stack. The user can select the socket
67descriptor using <i>sockid</i> and the <i>side</i> argument
68(MOS_SIDE_CLI or MOS_SIDE_SVR) to fetch the Ethernet frame
69of her choosing. <i>pinfo</i> points to an instance of
70<b>struct</b> pkt_info that should be allocated by the user
71before calling the function. The structure is defined
72as:</p>
73
74<p style="margin-left:11%; margin-top: 1em">struct pkt_info
75{</p>
76
77<table width="100%" border="0" rules="none" frame="void"
78       cellspacing="0" cellpadding="0">
79<tr valign="top" align="left">
80<td width="8%"></td>
81<td width="7%"></td>
82<td width="85%">
83
84
85<p>// pkt recving time</p></td></tr>
86<tr valign="top" align="left">
87<td width="8%"></td>
88<td width="7%"></td>
89<td width="85%">
90
91
92<p>uint32_t cur_ts;</p></td></tr>
93<tr valign="top" align="left">
94<td width="8%"></td>
95<td width="7%"></td>
96<td width="85%">
97
98
99<p>// ETH</p></td></tr>
100<tr valign="top" align="left">
101<td width="8%"></td>
102<td width="7%"></td>
103<td width="85%">
104
105
106<p>uint16_t eth_len;</p></td></tr>
107<tr valign="top" align="left">
108<td width="8%"></td>
109<td width="7%"></td>
110<td width="85%">
111
112
113<p>// IP</p></td></tr>
114<tr valign="top" align="left">
115<td width="8%"></td>
116<td width="7%"></td>
117<td width="85%">
118
119
120<p>uint16_t ip_len;</p></td></tr>
121<tr valign="top" align="left">
122<td width="8%"></td>
123<td width="7%"></td>
124<td width="85%">
125
126
127<p>//TCP</p></td></tr>
128<tr valign="top" align="left">
129<td width="8%"></td>
130<td width="7%"></td>
131<td width="85%">
132
133
134<p>uint64_t offset; // TCP recv buffer offset</p></td></tr>
135<tr valign="top" align="left">
136<td width="8%"></td>
137<td width="7%"></td>
138<td width="85%">
139
140
141<p>uint16_t payloadlen;</p></td></tr>
142<tr valign="top" align="left">
143<td width="8%"></td>
144<td width="7%"></td>
145<td width="85%">
146
147
148<p>uint32_t seq;</p></td></tr>
149<tr valign="top" align="left">
150<td width="8%"></td>
151<td width="7%"></td>
152<td width="85%">
153
154
155<p>uint32_t ack_seq;</p></td></tr>
156<tr valign="top" align="left">
157<td width="8%"></td>
158<td width="7%"></td>
159<td width="85%">
160
161
162<p>uint16_t window;</p></td></tr>
163<tr valign="top" align="left">
164<td width="8%"></td>
165<td width="7%"></td>
166<td width="85%">
167
168
169<p>struct ethhdr *ethh;</p></td></tr>
170<tr valign="top" align="left">
171<td width="8%"></td>
172<td width="7%"></td>
173<td width="85%">
174
175
176<p>struct iphdr *iph;</p></td></tr>
177<tr valign="top" align="left">
178<td width="8%"></td>
179<td width="7%"></td>
180<td width="85%">
181
182
183<p>struct tcphdr *tcph;</p></td></tr>
184<tr valign="top" align="left">
185<td width="8%"></td>
186<td width="7%"></td>
187<td width="85%">
188
189
190<p>uint8_t *payload;</p></td></tr>
191</table>
192
193<p style="margin-left:11%;">}</p>
194
195<p style="margin-left:11%; margin-top: 1em">A successful
196call to <b>mtcp_getlastpkt()</b> creates a copy of the last
197recorded Ethernet frame and appends its meta-data (in host
198byte order). The last four fields of <i>pinfo</i> (ethh,
199iph, tcph and payload) point to the copied frame at the
200appropriate offsets. Please note that the packet buffer that
201contains the copied frame is reused for future invocations
202of <b>mtcp_getlastpkt().</b></p>
203
204<p style="margin-left:11%; margin-top: 1em">An
205<b>mtcp_getlastpkt</b>() call takes an additional argument
206named <i>mctx</i> that represents the per-core mTCP context
207in an application (see <b>mtcp_create_context()</b> for
208details).</p>
209
210<h2>RETURN VALUE
211<a name="RETURN VALUE"></a>
212</h2>
213
214
215<p style="margin-left:11%; margin-top: 1em">Returns 0 on
216success; -1 on failure. In case of failure, <i>errno</i> is
217set appropriately.</p>
218
219<h2>ERRORS
220<a name="ERRORS"></a>
221</h2>
222
223
224<table width="100%" border="0" rules="none" frame="void"
225       cellspacing="0" cellpadding="0">
226<tr valign="top" align="left">
227<td width="11%"></td>
228<td width="11%">
229
230
231<p style="margin-top: 1em"><b>EACCES</b></p></td>
232<td width="12%"></td>
233<td width="66%">
234
235
236<p style="margin-top: 1em"><i>mctx</i> is invalid.</p></td></tr>
237<tr valign="top" align="left">
238<td width="11%"></td>
239<td width="11%">
240
241
242<p><b>EPERM</b></p></td>
243<td width="12%"></td>
244<td width="66%">
245
246
247<p>Permission denied.</p></td></tr>
248<tr valign="top" align="left">
249<td width="11%"></td>
250<td width="11%">
251
252
253<p><b>ENODATA</b></p></td>
254<td width="12%"></td>
255<td width="66%">
256
257
258<p>The last captured Ethernet frame for this flow does not
259exist. This can occur if <b>mtcp_getlastpkt()</b> is called
260during e.g. connection initiation.</p></td></tr>
261<tr valign="top" align="left">
262<td width="11%"></td>
263<td width="11%">
264
265
266<p><b>EBADF</b></p></td>
267<td width="12%"></td>
268<td width="66%">
269
270
271<p><i>sockid</i> is not a valid socket descriptor for
272creating a connection.</p></td></tr>
273</table>
274
275<h2>AUTHORS
276<a name="AUTHORS"></a>
277</h2>
278
279
280<p style="margin-left:11%; margin-top: 1em">mOS development
281team &lt;[email protected]&gt;</p>
282
283<h2>SEE ALSO
284<a name="SEE ALSO"></a>
285</h2>
286
287
288
289<p style="margin-left:11%; margin-top: 1em"><b>mtcp_create_context</b>(),
290<b>mtcp_setlastpkt</b>(), <b>mtcp_socket</b>(),</p>
291
292<h2>COLOPHON
293<a name="COLOPHON"></a>
294</h2>
295
296
297<p style="margin-left:11%; margin-top: 1em">This page is
298part of mOS release 0.3 <i>docs</i> section. A description
299of the project, and information about reporting bugs, can be
300found at http://mos.kaist.edu/.</p>
301<hr>
302</body>
303</html>
304