an_getpeername - fetch the public address of the remote client
#include <antinat.h>
int an_getpeername(ANCONN s, struct sockaddr *address, int length);
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.
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).
This call returns AN_ERROR_SUCCESS to indicate successful completion.
This function appeared in Antinat 0.70.
an_accept(3), an_connect_tohostname(3), an_connect_tosockaddr(3), an_getsockname(3), an_new_connection(3)
Malcolm Smith <malxau@users.sourceforge.net>