#include <sys.socket.h>
#include <netdb.h>
Kernighan-Ritchie-C:
struct hostent *getipnodebyaddr(addr, len, type, error_num);
char *addr;
int len;
int type;
int *error_num;
struct hostent *getipnodebyname(name, af, flags, error_num);
char *name;
int af;
int flags;
int *error_num;
ANSI-C:
struct hostent* getipnodebyaddr(char* addr, int len, int type, int* error_num);
struct hostent* getipnodebyname(char* name, int af, int flags, int* error_num);
Description
Use of the getipnodebyaddr() and getipnodebyname() functions only makes sense in the AF_INET and AF_INET6 address families. getipnodebyaddr() and getipnodebyname() are extensions of the functions gethostbyaddr() and gethostbyname() for IPv6 support.
The getipnodebyaddr() and getipnodebyname() functions return current information on all known hosts on the network by obtaining the required information (host name and host address) from a DNS server. Otherwise, i.e. only in cases where this is not successful, the information taken from the BCAM processor table (see the “BCAM Volume 1/2” manual for details).
For getipnodebyaddr(), addr is a pointer to the host address. This host address must be available in binary format with the length len. The only valid entry for type is AF_INET or AF_INET6.
For getipnodebyname(), the host name (socket host name) must be specified for name. You can specify the name
as a fully-qualified DNS name, i.e. including host name and domain part (e.g. hostname.company.com) or
as a partially-qualified DNS name (e.g. hostname) or
only as a host name (e.g. hostname).
You can also specify an IPv4 address in decimal dotted notation or an IPv6 address in hexadecimal colon notation. If you do so, the corresponding address families must be specified for af. In this case, the converted binary address is returned in the hostent return structure. If an IPv4 address in decimal dotted notation and af = AF_INET6 and flags = AI_V4MAPPED is specified, a binary IPv4-mapped IPv6 address is returned in the output structure.
The af parameter in the call is used to specify the address family (AF_INET or AF_INET6).
The flags parameter can be used to control the output of the desired address family. If flags has the value 0, an address appropriate to the address family specified in ai is returned.
In the address family af, flags can be used to specify different options (they are defined in <netdb.h>):
AI_V4MAPPED
The caller accepts IPv4-mapped addresses if no IPv6 address is available.
AI_ALL
IPv6 addresses and IPv4-mapped addresses are returned if available. af must have the value AF_INET6.
AI_ADDRCONFIG
Depending on the value of af, only an IPv6 or IPv4 address is returned if the host on which the function is called has an interface address of the same type.
AI_DEFAULT
is the same as AI_ADDRCONFIG || AI_V4MAPPED.
If af = AF_INET6 is set and the host on which the function is called has an IPv6 address, an IPv6 address is returned for the specified host name.
If the host on which the function is called has only an IPv4 interface address, an IPv4-mapped IPv6 address is returned.
The getipnodebyaddr() and getipnodebyname() functions return a pointer to an object of the hostent structure described below. Memory for this object is requested dynamically and must be released again by the caller with the freehostent() function.
The hostent structure is declared as follows:
struct hostent { char *h_name; /* socket host name */ char **h_aliases; /* alias list */ int h_addrtype; /* address type */ int h_length; /* length of the address (in bytes) */ char **h_addr_list; /* list of addresses for the host */ /* terminated with the null pointer */ }; #define h_addr h_addr_list[0]; /* first address, network byte order */
Description of hostent components:
h_name
Name of the host
h_aliases
A list of alternative names (aliases) for the host, terminated with null.
Aliases are currently not supported.
h_addrtype
Type of the returned address (always AF_INET)
h_length
Length of the address in bytes
**h_addr_list
A pointer to a null-terminated list of network addresses for the host. These addresses of length h_length are returned in network byte order.
Return value
Pointer to an object of the type struct hostent. If an error occurs, the null pointer is returned and the variable errnum is supplied with one of the following values. These values are defined in <netdb.h>.
HOST_NOT_FOUND
Host unknown.
NO_ADDRESS
No host address is available for the specified name.
NO_RECOVERY
An unrecoverable server error has occurred.
TRY_AGAIN
Access must be repeated.
Note
When DNS is not used, as a rule it makes sense not to specify a Fully Qualified Domain Name (FQDN), but only the host name in order to obtain the corresponding addresses from BCAM (e.g. host instead of host.mydomain.net).
The use of FQDNs makes sense on systems on which DNS is not used only when an FQDN file with entries exists.
The LWRESD resolver which is common to the SOCKETS(BS2000), BCAM and POSIX sockets is used to access the DNS. For more details, see the manual “BCAM Volume 1/2”.