mtcp_getpeername

NAME

mtcp_getpeername − get name of end hosts being monitored by mOS

SYNOPSIS

#include <mos_api.h>

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

DESCRIPTION

mtcp_getpeername() returns the address of the end hosts that is being monitored by 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 socket address.

side variable should be properly set to specify on which side this function is interested in.

If side argument is set to have MOS_SIDE_CLI or MOS_SIDE_SVR, addrlen should be sizeof(struct sockaddr), and it will fill up the address buffer at addr with the address of the corresponding side.

If side argument is set to have MOS_SIDE_BOTH, addrlen should be 2 * sizeof(struct sockaddr) , and it will fill up the address buffer at addr with the address of the corresponding side. The client-side address can be referred as addr[MOS_SIDE_CLI], and the server-side can be referred as addr[MOS_SIDE_SVR].

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).

ENOTCONN

The argument sockfd is pointing to a mOS socket which has no corresponding stream that is being monitored.

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.

AUTHORS

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

EXAMPLES

http://mos.kaist.edu/guide/programmer/05_api_example.html#querying-end-point-host-address

SEE ALSO

mtcp_bind(), mtcp_socket()

COLOPHON

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