1<!-- Creator : groff version 1.22.3 --> 2<!-- CreationDate: Sat Aug 26 16:40:01 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_sendpkt</title> 17<link rel="stylesheet" href="./common.css"> 18</head> 19<body> 20<div class="main"> 21<h1 align="center">mtcp_sendpkt</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<p style="margin-left:11%; margin-top: 1em">mtcp_sendpkt 41− Sends a self-constructed TCP packet to network</p> 42 43<h2>SYNOPSIS 44<a name="SYNOPSIS"></a> 45</h2> 46 47 48<p style="margin-left:11%; margin-top: 1em"><b>#include 49<mos_api.h></b></p> 50 51<p style="margin-left:11%; margin-top: 1em"><b>int 52mtcp_sendpkt(mctx_t</b> <i>mctx</i><b>, int</b> 53<i>sockid</i><b>, struct pkt_info 54*</b><i>pinfo</i><b>);</b></p> 55 56<h2>DESCRIPTION 57<a name="DESCRIPTION"></a> 58</h2> 59 60 61 62<p style="margin-left:11%; margin-top: 1em"><b>mtcp_sendpkt</b>() 63sends a self-constructed TCP packet for a given flow to 64network. The user can select the socket descriptor using 65<i>sockid</i> and the <i>pinfo</i> points to an instance of 66<b>struct</b> pkt_info that is allocated and filled by the 67user via mtcp_getlastpkt() function. 68It is the user's responsibility to allocate the <i>pkt_info </i> 69structure before the function call, and free the 70<i>pkt_info</i> after the function call. The structure is 71defined as:</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</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</p></td></tr> 99<tr valign="top" align="left"> 100<td width="8%"></td> 101<td width="7%"></td> 102<td width="85%"> 103 104 105<p>uint16_t eth_len;</p></td></tr> 106<tr valign="top" align="left"> 107<td width="8%"></td> 108<td width="7%"></td> 109<td width="85%"> 110 111 112<p>// IP</p></td></tr> 113<tr valign="top" align="left"> 114<td width="8%"></td> 115<td width="7%"></td> 116<td width="85%"> 117 118 119<p>uint16_t ip_len;</p></td></tr> 120<tr valign="top" align="left"> 121<td width="8%"></td> 122<td width="7%"></td> 123<td width="85%"> 124 125 126<p>//TCP</p></td></tr> 127<tr valign="top" align="left"> 128<td width="8%"></td> 129<td width="7%"></td> 130<td width="85%"> 131 132 133<p>uint64_t offset; // TCP recv buffer offset</p></td></tr> 134<tr valign="top" align="left"> 135<td width="8%"></td> 136<td width="7%"></td> 137<td width="85%"> 138 139 140<p>uint16_t payloadlen;</p></td></tr> 141<tr valign="top" align="left"> 142<td width="8%"></td> 143<td width="7%"></td> 144<td width="85%"> 145 146 147<p>uint32_t seq;</p></td></tr> 148<tr valign="top" align="left"> 149<td width="8%"></td> 150<td width="7%"></td> 151<td width="85%"> 152 153 154<p>uint32_t ack_seq;</p></td></tr> 155<tr valign="top" align="left"> 156<td width="8%"></td> 157<td width="7%"></td> 158<td width="85%"> 159 160 161<p>uint16_t window;</p></td></tr> 162<tr valign="top" align="left"> 163<td width="8%"></td> 164<td width="7%"></td> 165<td width="85%"> 166 167 168<p>struct ethhdr *ethh;</p></td></tr> 169<tr valign="top" align="left"> 170<td width="8%"></td> 171<td width="7%"></td> 172<td width="85%"> 173 174 175<p>struct iphdr *iph;</p></td></tr> 176<tr valign="top" align="left"> 177<td width="8%"></td> 178<td width="7%"></td> 179<td width="85%"> 180 181 182<p>struct tcphdr *tcph;</p></td></tr> 183<tr valign="top" align="left"> 184<td width="8%"></td> 185<td width="7%"></td> 186<td width="85%"> 187 188 189<p>uint8_t *payload;</p></td></tr> 190</table> 191 192<p style="margin-left:11%;">}</p> 193 194<p style="margin-left:11%; margin-top: 1em">A successful 195call to <b>mtcp_sendpkt()</b> constructs a TCP packet based 196on the given packet information <i>pinfo</i> and send the 197packet to the network.</p> 198 199<p style="margin-left:11%; margin-top: 1em">An 200<b>mtcp_sendpkt</b>() call takes an additional argument 201named <i>mctx</i> that represents the per-core mTCP context 202in an application (see <b>mtcp_create_context()</b> for 203details).</p> 204 205<h2>RETURN VALUE 206<a name="RETURN VALUE"></a> 207</h2> 208 209 210<p style="margin-left:11%; margin-top: 1em">Returns 0 on 211success; -1 on failure. In case of failure, <i>errno</i> is 212set appropriately.</p> 213 214<h2>ERRORS 215<a name="ERRORS"></a> 216</h2> 217 218 219<table width="100%" border="0" rules="none" frame="void" 220 cellspacing="0" cellpadding="0"> 221<tr valign="top" align="left"> 222<td width="11%"></td> 223<td width="11%"> 224 225 226<p style="margin-top: 1em"><b>EACCES</b></p></td> 227<td width="12%"></td> 228<td width="66%"> 229 230 231<p style="margin-top: 1em"><i>mctx</i> is invalid, or 232<i>pinfo</i> is NULL.</p></td></tr> 233<tr valign="top" align="left"> 234<td width="11%"></td> 235<td width="11%"> 236 237 238<p><b>ENODATA</b></p></td> 239<td width="12%"></td> 240<td width="66%"> 241 242 243<p>The packet information does not contain a valid IP 244header or TCP header information. This normally does not 245occur when we put the result of the <b>mtcp_sendpkt()</b> 246function. Therefore, it means that the user modified the 247packet information inappropriately.</p></td></tr> 248</table> 249 250<h2>AUTHORS 251<a name="AUTHORS"></a> 252</h2> 253 254 255<p style="margin-left:11%; margin-top: 1em">mOS development 256team <[email protected]></p> 257 258<h2>SEE ALSO 259<a name="SEE ALSO"></a> 260</h2> 261 262 263 264<p style="margin-left:11%; margin-top: 1em"><b>mtcp_create_context</b>(), 265<b>mtcp_setlastpkt</b>(), <b>mtcp_socket</b>(),</p> 266 267<h2>COLOPHON 268<a name="COLOPHON"></a> 269</h2> 270 271 272<p style="margin-left:11%; margin-top: 1em">This page is 273part of mOS release 0.3 <i>docs</i> section. A description 274of the project, and information about reporting bugs, can be 275found at http://mos.kaist.edu/.</p> 276<hr> 277<div class="footer"> 278 <img src="back-arrow.jpg" width="2%" height="2%"><a href="http://mos.kaist.edu/index_man.html">Back to Index</a> 279</div> 280</div> 281</body> 282</html> 283