mtcp_bind

NAME

mtcp_bind − bind an IP address to an mTCP socket

SYNOPSIS

#include <mtcp_api.h>

int mtcp_bind(mctx_t mctx, int sockid, const struct sockaddr *addr, socklen_t addrlen);

DESCRIPTION

mtcp_bind() can be used to bind an IPv4 address (assigning a name) to an mTCP socket. This socket is referred to by the sockid argument. The addr structure contains the address and the port number (both in network byte order) to be bound while the addrlen specifies the size of the address structure pointing to addr. The actual structure passed for the addr argument is defined as:

struct sockaddr {
sa_family_t sa_family; /* AF_INET */
char sa_data[14]; /* IPv4 address + TCP port */
}

It is necessary to assign a local address using mtcp_bind() on a passive socket before it can be used to receive connections using mtcp_accept().

The mtcp_bind() 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 0 on success; -1 on failure. In case of failure, errno is set appropriately.

ERRORS

EBADF

sockid is not a valid socket descriptor for binding to an address.

EINVAL

The addr argument is NULL. This may also mean that an address is already bound to the current sockid descriptor.

ENOTSOCK

The socket referred to by sockid has an invalid type.

AUTHORS

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

SEE ALSO

mtcp_socket(), mtcp_listen(), mtcp_accept(), mtcp_connect(), mtcp_read(), mtcp_write()

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