Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

cnetdb(3) [debian man page]

CNETDB(3)						     Common Library Functions							 CNETDB(3)

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 Cgetne- taddress. 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 local- host.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> LCG
$Date: 2008/02/13 17:29:10 $ CNETDB(3)

Check Out this Related Man Page

GETNAMEINFO(3)						   BSD Library Functions Manual 					    GETNAMEINFO(3)

NAME
getnameinfo -- socket address structure to hostname and service name SYNOPSIS
#include <sys/types.h> #include <sys/socket.h> #include <netdb.h> int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags); DESCRIPTION
The getnameinfo() function is used to convert a sockaddr structure to a pair of host name and service strings. It is a replacement for and provides more flexibility than the gethostbyaddr(3) and getservbyport(3) functions and is the converse of the getaddrinfo(3) function. If a link-layer address is passed to getnameinfo(), its ASCII representation will be stored in host. The string pointed to by serv will be set to the empty string if non-NULL; flags will always be ignored. This is intended as a replacement for the legacy link_ntoa(3) function. The sockaddr structure sa should point to either a sockaddr_in, sockaddr_in6 or sockaddr_dl structure (for IPv4, IPv6 or link-layer respec- tively) that is salen bytes long. The host and service names associated with sa are stored in host and serv which have length parameters hostlen and servlen. The maximum value for hostlen is NI_MAXHOST and the maximum value for servlen is NI_MAXSERV, as defined by <netdb.h>. If a length parameter is zero, no string will be stored. Otherwise, enough space must be provided to store the host name or service string plus a byte for the NUL terminator. The flags argument is formed by OR'ing the following values: NI_NOFQDN A fully qualified domain name is not required for local hosts. The local part of the fully qualified domain name is returned instead. NI_NUMERICHOST Return the address in numeric form, as if calling inet_ntop(3), instead of a host name. NI_NAMEREQD A name is required. If the host name cannot be found in DNS and this flag is set, a non-zero error code is returned. If the host name is not found and the flag is not set, the address is returned in numeric form. NI_NUMERICSERV The service name is returned as a digit string representing the port number. NI_DGRAM Specifies that the service being looked up is a datagram service, and causes getservbyport(3) to be called with a second argument of ``udp'' instead of its default of ``tcp''. This is required for the few ports (512-514) that have different services for UDP and TCP. This implementation allows numeric IPv6 address notation with scope identifier, as documented in chapter 11 of draft-ietf-ipv6-scoping- arch-02.txt. IPv6 link-local address will appear as a string like ``fe80::1%ne0''. Refer to getaddrinfo(3) for more information. RETURN VALUES
getnameinfo() returns zero on success or one of the error codes listed in gai_strerror(3) if an error occurs. EXAMPLES
The following code tries to get a numeric host name, and service name, for a given socket address. Observe that there is no hardcoded refer- ence to a particular address family. struct sockaddr *sa; /* input */ char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) { errx(1, "could not get numeric hostname"); /*NOTREACHED*/ } printf("host=%s, serv=%s ", hbuf, sbuf); The following version checks if the socket address has a reverse address mapping: struct sockaddr *sa; /* input */ char hbuf[NI_MAXHOST]; if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), NULL, 0, NI_NAMEREQD)) { errx(1, "could not resolve hostname"); /*NOTREACHED*/ } printf("host=%s ", hbuf); SEE ALSO
gai_strerror(3), getaddrinfo(3), gethostbyaddr(3), getservbyport(3), inet_ntop(3), link_ntoa(3), resolver(3), hosts(5), resolv.conf(5), services(5), hostname(7), named(8) R. Gilligan, S. Thomson, J. Bound, and W. Stevens, Basic Socket Interface Extensions for IPv6, RFC 2553, March 1999. S. Deering, B. Haberman, T. Jinmei, E. Nordmark, and B. Zill, IPv6 Scoped Address Architecture, internet draft, draft-ietf-ipv6-scoping- arch-02.txt, work in progress material. Craig Metz, "Protocol Independence Using the Sockets API", Proceedings of the freenix track: 2000 USENIX annual technical conference, June 2000. STANDARDS
The getnameinfo() function is defined by the IEEE Std 1003.1g-2000 (``POSIX.1'') draft specification and documented in RFC 2553, ``Basic Socket Interface Extensions for IPv6''. CAVEATS
getnameinfo() can return both numeric and FQDN forms of the address specified in sa. There is no return value that indicates whether the string returned in host is a result of binary to numeric-text translation (like inet_ntop(3)), or is the result of a DNS reverse lookup. Because of this, malicious parties could set up a PTR record as follows: 1.0.0.127.in-addr.arpa. IN PTR 10.1.1.1 and trick the caller of getnameinfo() into believing that sa is 10.1.1.1 when it is actually 127.0.0.1. To prevent such attacks, the use of NI_NAMEREQD is recommended when the result of getnameinfo() is used for access control purposes: struct sockaddr *sa; socklen_t salen; char addr[NI_MAXHOST]; struct addrinfo hints, *res; int error; error = getnameinfo(sa, salen, addr, sizeof(addr), NULL, 0, NI_NAMEREQD); if (error == 0) { memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_DGRAM; /*dummy*/ hints.ai_flags = AI_NUMERICHOST; if (getaddrinfo(addr, "0", &hints, &res) == 0) { /* malicious PTR record */ freeaddrinfo(res); printf("bogus PTR record "); return -1; } /* addr is FQDN as a result of PTR lookup */ } else { /* addr is numeric string */ error = getnameinfo(sa, salen, addr, sizeof(addr), NULL, 0, NI_NUMERICHOST); } BSD
February 28, 2007 BSD
Man Page