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