.TH mtcp_getpeername 2 2016-05-02 "Linux" "mTCP Programmer's Manual"
.SH NAME
mtcp_getpeername \- get name of connected peer socket
.SH SYNOPSIS
.B #include <mtcp_api.h>
.sp
.BI "int mtcp_getpeername(mctx_t " mctx ", int " sockfd ", struct sockaddr *" addr ", socklen_t *" addrlen );

.SH DESCRIPTION
.BR mtcp_getpeername () 
returns the address of the peer connected to the socket
.I "sockfd"
in the buffer pointed to by
.I "addr."
The
.I "addrlen"
argument should be initialized to indicate the amount of space
(in bytes) pointed to by
.I "addr."
On return it contains the actual size of the name returned.

An 
.BR mtcp_getpeername ()
call takes an additional argument named 
.I "mctx"
that represents the per-core mTCP context in an application
(see
.BR mtcp_create_context()
for details).
.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.SH RETURN VALUE
Returns zero on success; -1 on failure. In case
of failure,
.I "errno"
is set appropriately.
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.SH ERRORS
.TP 10
.B "EBADF"
The argument
.I "sockfd"
is not a valid socket descriptor.

.TP 10
.B "EINVAL"
.I "addrlen"
argument is invalid (e.g., is negative).

.TP 10
.B "ENOTSOCK"
The argument
.I "sockfd"
is pointing to an invalid mTCP socket.

.TP 10
.B "ENOTCONN"
The socket is not connected.

.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.\""""".SH CONFORMING TO
.\"""""POSIX.1-2001.
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.SH NOTES
The third argument of 
.BR mtcp_getpeername()
is in reality an
.I "int *"
(and this is what 4.x BSD and libc4 and libc5 have). Some
POSIX confusion resulted in the present
.I "socklen_t",
also used by glibc.

Once a
.BR mtcp_connect()
has been performed, either socket can call
.BR mtcp_getpeername()
to obtain the address of the peer socket. The caller of
.BR mtcp_connect()
can use
.BR mtcp_getpeername()
to obtain the peer address that it earlier set for the socket.
However, the peer socket is unaware of this information, and
calling
.BR mtcp_getpeername()
on the peer socket will return no useful information (unless a
.BR mtcp_accept()
was also executed on the peer).
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.SH AUTHORS
mTCP development team <mtcp-user@list.ndsl.kaist.edu>
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.SH SEE ALSO
.BR mtcp_bind (),
.BR mtcp_socket ()
.BR mtcp_getsockname ()
.\""""""""""""""""""""""""""""""""""""""""""""""""""""""
.SH COLOPHON
This page is part of mTCP release 3.0
.I "docs"
section. A description of the project, and information
about reporting bugs, can be found at
\%http://shader.kaist.edu/mtcp/.
.\""""""""""""""""""""""""""""""""""""""""""""""""""""""
