1<!-- Creator : groff version 1.22.2 --> 2<!-- CreationDate: Sat Feb 4 18:19:20 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<link rel="stylesheet" href="./common.css"> 18</head> 19<body> 20<div class="main"> 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<hr> 32--> 33 34<h2>NAME 35<a name="NAME"></a> 36</h2> 37 38 39 40<p style="margin-left:11%; margin-top: 1em">mtcp_getlastpkt 41− Retrieves the last Ethernet frame of a monitoring 42flow</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<mos_api.h></b></p> 51 52<p style="margin-left:11%; margin-top: 1em"><b>int 53mtcp_getlastpkt(mctx_t</b> <i>mctx</i><b>, int</b> 54<i>sockid</i><b>, int</b> <i>side</i><b>, struct pkt_info 55*</b><i>pinfo</i><b>);</b></p> 56 57<h2>DESCRIPTION 58<a name="DESCRIPTION"></a> 59</h2> 60 61 62 63<p style="margin-left:11%; margin-top: 1em"><b>mtcp_getlastpkt</b>() 64fetches a copy of the last Ethernet frame for a given flow 65observed by the stack. The user can select the socket 66descriptor using <i>sockid</i> and the <i>side</i> argument 67(MOS_SIDE_CLI or MOS_SIDE_SVR) to fetch the Ethernet frame 68of her choosing. <i>pinfo</i> points to an instance of 69<b>struct</b> pkt_info that should be allocated by the user 70before calling the function. The structure is defined 71as:</p> 72 73<p style="margin-left:11%; margin-top: 1em">struct pkt_info 74{</p> 75 76<table width="100%" border="0" rules="none" frame="void" 77 cellspacing="0" cellpadding="0"> 78<tr valign="top" align="left"> 79<td width="8%"></td> 80<td width="7%"></td> 81<td width="85%"> 82 83 84<p>// pkt recving time<br>uint32_t cur_ts;</p></td></tr> 85<!--<tr valign="top" align="left"> 86<td width="8%"></td> 87<td width="7%"></td> 88<td width="85%"> 89 90 91<p>uint32_t cur_ts;</p></td></tr>--> 92<tr valign="top" align="left"> 93<td width="8%"></td> 94<td width="7%"></td> 95<td width="85%"> 96 97 98<p>// ETH<br>uint16_t eth_len;</p></td></tr> 99<!-- 100<tr valign="top" align="left"> 101<td width="8%"></td> 102<td width="7%"></td> 103<td width="85%"> 104 105 106<p></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<br>uint16_t ip_len;</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></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<br>uint64_t offset; // TCP recv buffer offset<br>uint16_t payloadlen;<br>uint32_t seq;<br>uint32_t ack_seq;<br>uint16_t window;</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></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></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></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></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></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;<br>struct iphdr *iph;<br>struct tcphdr *tcph;<br>uint8_t *payload;</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></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></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></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 byte order). The last 198four fields of <i>pinfo</i> (ethh, iph, tcph and payload) 199point to the copied frame at the appropriate offsets. Please 200note that the packet buffer that contains the copied frame 201is reused for future invocations of 202<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 <[email protected]></p> 282 283<!-----------------------------------------------------------> 284<h2>EXAMPLES 285 <a name="EXAMPLES"></a> 286</h2> 287 288<p style="margin-left:11%; margin-top: 1em"> 289 <a href="http://mos.kaist.edu/guide/programmer/05_api_example.html#monitoring-packet-metadata-and-payload"> 290 http://mos.kaist.edu/guide/programmer/05_api_example.html#monitoring-packet-metadata-and-payload 291 </a> 292</p> 293<p style="margin-left:11%; margin-top: 1em"> 294 <a href="http://mos.kaist.edu/guide/programmer/05_api_example.html#generating-and-sending-a-packet"> 295 http://mos.kaist.edu/guide/programmer/05_api_example.html#generating-and-sending-a-packet 296 </a> 297</p> 298<!-----------------------------------------------------------> 299 300 301 302<h2>SEE ALSO 303<a name="SEE ALSO"></a> 304</h2> 305 306 307 308<p style="margin-left:11%; margin-top: 1em"><b>mtcp_create_context</b>(), 309<b>mtcp_setlastpkt</b>(), <b>mtcp_socket</b>(),</p> 310 311<h2>COLOPHON 312<a name="COLOPHON"></a> 313</h2> 314 315 316<p style="margin-left:11%; margin-top: 1em">This page is 317part of mOS release 0.3 <i>docs</i> section. A description 318of the project, and information about reporting bugs, can be 319found at http://mos.kaist.edu/.</p> 320<!-- <hr> --> 321<br> 322<div class="footer"> 323 <img src="back-arrow.jpg" width="2%" height="2%"><a href="http://mos.kaist.edu/index_man.html">Back to Index</a> 324</div> 325</div> 326</body> 327</html> 328