AN_GETPEERNAME(3)

NAME

an_getpeername - fetch the public address of the remote client

SYNOPSIS

#include <antinat.h>

int an_getpeername(ANCONN s, struct sockaddr *address, int length);

DESCRIPTION

The an_getpeername(3) function is used retrieve the public address of the remote client. Be careful when using this function; proxy-aware applications have an additional set of considerations over BSD-socket applications. Firstly, in order to have a peer address, the socket must be connected to a remote host (via an_connect_tohostname(3), an_connect_tosockaddr(3) or an_accept(3).) Secondly, when using an_connect_tohostname(3) the public address may not be known to the client library. On the basis that wrong information is worse than none, in these cases the function will fail. Whether or not an address is available is dependent on the proxy protocol; do not make assumptions about whether one will be available.

s is a socket previously created with an_new_connection(3) call, placed in the accepted or connected state with one of an_accept(3), an_connect_tohostname(3) or an_connect_tosockaddr(3)

address is a sockaddr structure, which will be filled with address family, address, and port that the remote host is using for the connection. This can also be a typecast sockaddr_in6 structure, if Antinat has been compiled with IPv6 support.

length is the length of the sockaddr structure, as determined by sizeof.

NOTES

Do not call this function without firstly having a connected or accepted socket; and do not assume that an address will be available if the connection was made with an_connect_tohostname(3).

RETURN VALUE

This call returns AN_ERROR_SUCCESS to indicate successful completion.

ERRORS

AN_ERROR_INVALIDARG
    The socket handle or sockaddr structure is invalid; or structures of this length are not supported by the library.

AN_ERROR_NETWORK
    This information is not available with this network configuration.

AN_ERROR_NOMEM
    The socket information required more space than the length parameter indicated the address parameter has.

AN_ERROR_NOTSUPPORTED
    This call cannot be made on the type of socket, such as the proxy type does not support the retrieval of this type of information.

AN_ERROR_ORDER
    This call must be called after a connection or an accepted incoming connection.

SEE ALSO

an_accept(3), an_connect_tohostname(3), an_connect_tosockaddr(3), an_getsockname(3), an_new_connection(3)

AUTHOR

Malcolm Smith <malxau@users.sourceforge.net>