an_getsockname - fetch the public address the local client
#include <antinat.h>
int an_getsockname(ANCONN s, struct sockaddr *address, int length);
The an_getsockname(3) function is used retrieve the public address of the local 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 an address, the socket must be connected to a remote host (via an_connect_tohostname(3) or an_connect_tosockaddr(3) ) or be bound to accept incoming connections with an_bind_tohostname(3) or an_bind_tosockaddr(3). Depending on the proxy protocol, a local address may not be available. On the basis that wrong information is worse than none, in these cases the function will fail. A bound socket should have an available address on SOCKS4 or SOCKS5; a connected socket may only have an available address on SOCKS5 (or SOCKS4, if your server is Antinat.) Given that you cannot control the proxy where your application may run, 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 bound or connected state with one of an_bind_tohostname(3), an_bind_tosockaddr(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 local server 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 bound socket; and do not assume that an address will be available on different types of proxy.
This call returns AN_ERROR_SUCCESS to indicate successful completion.
This function appeared in Antinat 0.70.
an_bind_tohostname(3), an_bind_tosockaddr(3), an_connect_tohostname(3), an_connect_tosockaddr(3), an_getpeername(3), an_new_connection(3)
Malcolm Smith <malxau@users.sourceforge.net>