# mtcp_getpeername

NAME
SYNOPSIS
DESCRIPTION
RETURN VALUE
ERRORS
NOTES
AUTHORS
SEE ALSO
COLOPHON

## NAME

mtcp_getpeername − get name of connected peer socket

## SYNOPSIS

#include <mtcp_api.h>

int mtcp_getpeername(mctx_t mctx, int sockfd, struct sockaddr *addr, socklen_t *addrlen);

## DESCRIPTION

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

An mtcp_getpeername() call takes an additional argument named mctx that represents the per-core mTCP context in an application (see mtcp_create_context() for details).

## RETURN VALUE

Returns zero on success; -1 on failure. In case of failure, errno is set appropriately.

## ERRORS

| EBADF |  | The argument sockfd is not a valid socket descriptor.
| EINVAL |  | addrlen argument is invalid (e.g., is negative).
| ENOTSOCK |  | The argument sockfd is pointing to an invalid mTCP socket.
| ENOTCONN |  | The socket is not connected.

## NOTES

The third argument of mtcp_getpeername() is in reality an int * (and this is what 4.x BSD and libc4 and libc5 have). Some POSIX confusion resulted in the present socklen_t , also used by glibc.

Once a mtcp_connect() has been performed, either socket can call mtcp_getpeername() to obtain the address of the peer socket. The caller of mtcp_connect() can use 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 mtcp_getpeername() on the peer socket will return no useful information (unless a mtcp_accept() was also executed on the peer).

## AUTHORS

mTCP development team <mtcp-user@list.ndsl.kaist.edu>

## SEE ALSO

mtcp_bind(), mtcp_socket() mtcp_getsockname()

## COLOPHON

This page is part of mTCP release 3.0 docs section. A description of the project, and information about reporting bugs, can be found at http://shader.kaist.edu/mtcp/.