1<!-- Creator     : groff version 1.22.3 -->
2<!-- CreationDate: Mon Aug 28 02:48:48 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_getpeername</title>
17<link rel="stylesheet" href="./common.css">
18</head>
19<body>
20<div class="main">
21<h1 align="center">mtcp_getpeername</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="#NOTES">NOTES</a><br>
29<a href="#AUTHORS">AUTHORS</a><br>
30<a href="#SEE ALSO">SEE ALSO</a><br>
31<a href="#COLOPHON">COLOPHON</a><br>
32
33<hr>
34-->
35
36
37<h2>NAME
38<a name="NAME"></a>
39</h2>
40
41
42
43<p style="margin-left:11%; margin-top: 1em">mtcp_getpeername
44&minus; get name of end hosts being monitored by mOS</p>
45
46<h2>SYNOPSIS
47<a name="SYNOPSIS"></a>
48</h2>
49
50
51<p style="margin-left:11%; margin-top: 1em"><b>#include
52&lt;mos_api.h&gt;</b></p>
53
54<p style="margin-left:11%; margin-top: 1em"><b>int
55mtcp_getpeername(mctx_t</b> <i>mctx</i><b>, int</b>
56<i>sockfd</i><b>, struct sockaddr *</b><i>addr</i><b>,
57socklen_t *</b><i>addrlen,</i><b>int</b> <i>side</i>
58<b>);</b></p>
59
60<h2>DESCRIPTION
61<a name="DESCRIPTION"></a>
62</h2>
63
64
65
66<p style="margin-left:11%; margin-top: 1em"><b>mtcp_getpeername</b>()
67returns the address of the end hosts that is being monitored by the
68socket <i>sockfd</i> , in the buffer pointed to by
69<i>addr.</i> The <i>addrlen</i> argument should be
70initialized to indicate the amount of space (in bytes)
71pointed to by <i>addr.</i> On return it contains the actual
72size of the socket address.</p>
73
74<p style="margin-left:11%; margin-top: 1em"><i>side</i>
75  variable should be properly set to specify on which side
76  this function is interested in.</p>
77
78<p style="margin-left:11%; margin-top: 1em">If <i>side</i>
79  argument is set to have <i>MOS_SIDE_CLI</i> or <i>MOS_SIDE_SVR</i>,
80  <i>addrlen</i> should be <i>sizeof(struct sockaddr)</i>, and
81  it will fill up the address buffer at <i>addr</i>
82  with the address of the corresponding side.
83
84<p style="margin-left:11%; margin-top: 1em">
85  If <i>side</i> argument is set to have <i>MOS_SIDE_BOTH</i>,
86  <i>addrlen</i> should be <i>2 * sizeof(struct sockaddr)</i>
87  , and it will fill up the address buffer at <i>addr</i>
88  with the address of the corresponding side.
89  The client-side address can be referred as <i>addr[MOS_SIDE_CLI]</i>,
90  and the server-side can be referred as <i>addr[MOS_SIDE_SVR]</i>.
91</p>
92
93<p style="margin-left:11%; margin-top: 1em">An
94<b>mtcp_getpeername</b>() call takes an additional argument
95named <i>mctx</i> that represents the per-core mTCP context
96in an application (see <b>mtcp_create_context()</b> for
97details).</p>
98
99<h2>RETURN VALUE
100<a name="RETURN VALUE"></a>
101</h2>
102
103
104<p style="margin-left:11%; margin-top: 1em">Returns zero on
105success; -1 on failure. In case of failure, <i>errno</i> is
106set appropriately.</p>
107
108<h2>ERRORS
109<a name="ERRORS"></a>
110</h2>
111
112
113<table width="100%" border="0" rules="none" frame="void"
114       cellspacing="0" cellpadding="0">
115<tr valign="top" align="left">
116<td width="11%"></td>
117<td width="12%">
118
119
120<p style="margin-top: 1em"><b>EBADF</b></p></td>
121<td width="3%"></td>
122<td width="74%">
123
124
125<p style="margin-top: 1em">The argument <i>sockfd</i> is
126not a valid socket descriptor.</p></td></tr>
127<tr valign="top" align="left">
128<td width="11%"></td>
129<td width="12%">
130
131
132<p><b>EINVAL</b></p></td>
133<td width="3%"></td>
134<td width="74%">
135
136
137<p><i>addrlen</i> argument is invalid (e.g., is
138negative).</p> </td></tr>
139<tr valign="top" align="left">
140<td width="11%"></td>
141<td width="12%">
142
143
144<p><b>ENOTCONN</b></p></td>
145<td width="3%"></td>
146<td width="74%">
147
148
149<p>The argument <i>sockfd</i> is pointing to a mOS socket
150which has no corresponding stream that is being
151monitored.</p> </td></tr>
152</table>
153
154<h2>NOTES
155<a name="NOTES"></a>
156</h2>
157
158
159<p style="margin-left:11%; margin-top: 1em">The third
160argument of <b>mtcp_getpeername()</b> is in reality an
161<i>int *</i> (and this is what 4.x BSD and libc4 and libc5
162have). Some POSIX confusion resulted in the present
163<i>socklen_t ,</i> also used by glibc.</p>
164
165<h2>AUTHORS
166<a name="AUTHORS"></a>
167</h2>
168
169
170<p style="margin-left:11%; margin-top: 1em">mOS development
171team &lt;[email protected]&gt;</p>
172
173<!----------------------------------------------------------->
174<h2>EXAMPLES
175<a name="EXAMPLES"></a>
176</h2>
177
178<p style="margin-left:11%; margin-top: 1em">
179  <a href="http://mos.kaist.edu/guide/programmer/05_api_example.html#querying-end-point-host-address">
180	http://mos.kaist.edu/guide/programmer/05_api_example.html#querying-end-point-host-address
181	</a>
182</p>
183<!----------------------------------------------------------->
184
185<h2>SEE ALSO
186<a name="SEE ALSO"></a>
187</h2>
188
189
190
191<p style="margin-left:11%; margin-top: 1em"><b>mtcp_bind</b>(),
192<b>mtcp_socket</b>()</p>
193
194<h2>COLOPHON
195<a name="COLOPHON"></a>
196</h2>
197
198
199<p style="margin-left:11%; margin-top: 1em">This page is
200part of mOS release 0.3 <i>docs</i> section. A description
201of the project, and information about reporting bugs, can be
202found at http://mos.kaist.edu/.</p>
203<hr>
204<div class="footer">
205  <img src="back-arrow.jpg" width="2%" height="2%"><a href="http://mos.kaist.edu/index_man.html">Back to Index</a>
206</div>
207</div>
208</body>
209</html>
210