1<!-- Creator     : groff version 1.22.2 -->
2<!-- CreationDate: Wed Feb  1 22:24:31 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_bind</title>
17<link rel="stylesheet" href="./common.css">
18</head>
19<body>
20<div class="main">
21<h1 align="center">mtcp_bind</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<p style="margin-left:11%; margin-top: 1em">mtcp_bind
40&minus; bind an IP address to an mTCP socket</p>
41
42<h2>SYNOPSIS
43<a name="SYNOPSIS"></a>
44</h2>
45
46
47<p style="margin-left:11%; margin-top: 1em"><b>#include
48&lt;mtcp_api.h&gt;</b></p>
49
50<p style="margin-left:11%; margin-top: 1em"><b>int
51mtcp_bind(mctx_t</b> <i>mctx</i><b>, int</b>
52<i>sockid</i><b>, const struct sockaddr *</b><i>addr</i><b>,
53socklen_t</b> <i>addrlen</i><b>);</b></p>
54
55<h2>DESCRIPTION
56<a name="DESCRIPTION"></a>
57</h2>
58
59
60
61<p style="margin-left:11%; margin-top: 1em"><b>mtcp_bind</b>()
62can be used to bind an IPv4 address (assigning a name) to an
63mTCP socket. This socket is referred to by the <i>sockid</i>
64argument. The <i>addr</i> structure contains the address and
65the port number (both in network byte order) to be bound
66while the <i>addrlen</i> specifies the size of the address
67structure pointing to <i>addr.</i> The actual structure
68passed for the <i>addr</i> argument is defined as:</p>
69
70<p style="margin-left:17%; margin-top: 1em">struct sockaddr
71{ <br>
72sa_family_t sa_family; /* AF_INET */ <br>
73char sa_data[14]; /* IPv4 address + TCP port */ <br>
74}</p>
75
76<p style="margin-left:11%; margin-top: 1em">It is necessary
77to assign a local address using <b>mtcp_bind()</b> on a
78passive socket before it can be used to receive connections
79using <b>mtcp_accept().</b></p>
80
81<p style="margin-left:11%; margin-top: 1em">The
82<b>mtcp_bind</b>() call takes an additional argument named
83<i>mctx</i> that represents the per-core mTCP context in an
84application (see <b>mtcp_create_context()</b> for
85details).</p>
86
87<h2>RETURN VALUE
88<a name="RETURN VALUE"></a>
89</h2>
90
91
92<p style="margin-left:11%; margin-top: 1em">Returns 0 on
93success; -1 on failure. In case of failure, <i>errno</i> is
94set appropriately.</p>
95
96<h2>ERRORS
97<a name="ERRORS"></a>
98</h2>
99
100
101<table width="100%" border="0" rules="none" frame="void"
102       cellspacing="0" cellpadding="0">
103<tr valign="top" align="left">
104<td width="11%"></td>
105<td width="12%">
106
107
108<p style="margin-top: 1em"><b>EBADF</b></p></td>
109<td width="3%"></td>
110<td width="74%">
111
112
113<p style="margin-top: 1em"><i>sockid</i> is not a valid
114socket descriptor for binding to an address.</p></td></tr>
115<tr valign="top" align="left">
116<td width="11%"></td>
117<td width="12%">
118
119
120<p><b>EINVAL</b></p></td>
121<td width="3%"></td>
122<td width="74%">
123
124
125<p>The <i>addr</i> argument is NULL. This may also mean
126that an address is already bound to the current
127<i>sockid</i> descriptor.</p></td></tr>
128<tr valign="top" align="left">
129<td width="11%"></td>
130<td width="12%">
131
132
133<p><b>ENOTSOCK</b></p></td>
134<td width="3%"></td>
135<td width="74%">
136
137
138<p>The socket referred to by <i>sockid</i> has an invalid
139type.</p> </td></tr>
140</table>
141
142<h2>AUTHORS
143<a name="AUTHORS"></a>
144</h2>
145
146
147<p style="margin-left:11%; margin-top: 1em">mOS
148development team &lt;[email protected]&gt;</p>
149
150<h2>SEE ALSO
151<a name="SEE ALSO"></a>
152</h2>
153
154
155
156<p style="margin-left:11%; margin-top: 1em"><b>mtcp_socket</b>(),
157<b>mtcp_listen</b>(), <b>mtcp_accept</b>(),
158<b>mtcp_connect</b>(), <b>mtcp_read</b>(),
159<b>mtcp_write</b>()</p>
160
161<h2>COLOPHON
162<a name="COLOPHON"></a>
163</h2>
164
165
166<p style="margin-left:11%; margin-top: 1em">This page is
167part of mOS release 0.3 <i>docs</i> section. A description
168of the project, and information about reporting bugs, can be
169found at http://mos.kaist.edu/.</p>
170<!--<hr>-->
171<br>
172<div class="footer">
173  <img src="back-arrow.jpg" width="2%" height="2%"><a href="http://mos.kaist.edu/index_man.html">Back to Index</a>
174</div>
175</div>
176</body>
177</html>
178