NAME
Cnetdb - LCG netdb utilities
SYNOPSIS
#include <Cnetdb.h>
char *Cgetnetaddress(int sock, const void *sa, size_t salen, int *skey,
const char **numeric_out, const char **name_out, int flags, int
cflags);
DESCRIPTION
Cnetdb provides several netdb like functions including Cgethostbyname,
Cgethostbyaddr, Cgetservbyname, Cgetnameinfo, Cgetaddrinfo,
Cgai_strerror which behave in a somewhat similar way to their system
netdb counterparts. In addition Cnetdb provides a function called
Cgetnetaddress which is currently the only one documented here.
Cgetnetaddress returns a DNS domain name (often called a hostname)
given either a network socket, in which case the hostname corresponds
to the peer address of the socket, or a sockaddr structure. The name
will be returned as a numeric IP address and/or optionaly a DNS domain
name.
Exactly one of either sock or sa must be specified, the other should be
set to -1 or NULL respectively. If both are set the behaviour should be
considered undefined and may change in the future. If skey is NULL the
memory for pointers returned by Cgetnetaddress will be dynamically
allocated and it is the responsibility of the caller to free them when
done. If not NULL skey should point to an int which is initially set to
a value of -1. The memory used to store the results returned by
Cgetnetaddress will be allocated internally and will be reused during
subsequent calls to Cgetnetaddress from the same thread and that share
the same value of skey.
If numeric_out or name_out are not NULL the char pointer which they
reference will be reset to a pointer to a character array containig the
numeric or domain name address to be returned by the function. The
output will be NULL if the function is unable to find an IP or domain
name. flags accepts the same bitmaped flags that can be set for
getnameinfo(). cflags accepts bitmaped flags which are unique to
Cgetnetaddress.
If NI_NUMERICHOST is specified in flags no attempt is made to obtain a
domain name. If NI_NAMEREQD is specified nothing is returned unless a
domain name address can be determined. NI_NUMERICHOST and NI_NAMEREQD
are mutually exclusive. Other flags options may be set and will have
the effect described for getnameinfo().
cflags may take the bitmaped flags CNA_WANTLOOPBACK, CNA_NOFWDLOOKUP
and CNA_FWDLOOKUP.
By default if the address to be returned is determined to be the
loopback address any domain name returned will be that of the local
machine. If CNA_WANTLOOPBACK is specified any domain name returned
will be that associated with the loopback address, usually
localhost.localdomain.
A forward lookup verification of the domain name may be optionally
specified with the CNA_FWDLOOKUP flag. The forward lookup means that
one of the address to which a domain name resolves must match the
address passed to Cgetnetaddress. If the match failes the domain name
will be considered to not be available. By default, or if the option
CNA_NOFWDLOOKUP is passed in cflags, the forward lookup check is not
performed or required. The behavior if both CNA_FWDLOOKUP and
CNA_NOFWDLOOKUP are specified is undefined.
RETURN VALUE
Cgetnetaddress() returns a pointer to the domain name, if available, or
otherwise to the numeric IP address, if available. If neither is
available NULL is returned.
SEE ALSO
gethostbyname(3), gethostbyaddr(3), getservbyname(3), getnameinfo(3),
getaddrinfo(3), gai_strerror(3)
AUTHOR
LCG Grid Deployment Team and DPM Team <hep-service-dpm@cern.ch>