GETHOSTBYNAME
Use the GETHOSTBYNAME command to resolve a host name to an IPv4 address.
This command uses a DNS server. Any trailing blanks are removed from the host name. If the host is multi-homed, then this command returns a list of the space-delimited IP addresses that are associated with the host name. If the host name is not resolved by the DNS server, then the resolver searches the local hosts tables. For information about the local host tables, see z/OS Communications Server: IP Configuration Guide.
- Use either the GETADDRINFO or GETNAMEINFO command to resolve a IPv6 address to a host name.
- You can use a resolver trace to determine why a resolver command failed. See z/OS Communications Server: IP Diagnosis Guide.
Format
Parameters
- hostname
- The name of the remote host. The parameter cannot be longer than 255 characters.
- Fully qualified hostname
- The fully qualified name of the host in the format hostname.domainname. The parameter cannot be longer than 255 characters.
Returned value
This command returns string that contains the return code and one or more space-delimited IPv4 addresses, for example, 0 1.2.3.4 5.4.3.2 1.2.3.5. The return code can be 0 or the REXX API error number. The return code 0 indicates that the requested socket command was completed successfully.
See Socket call error return codes for additional information about the numeric error codes that are returned by this command.
- 2001 EINVALIDRXSOCKETCALL
- 2005 ESUBTASKNOTACTIVE
- 2016 EHOSTNOTFOUND
- 2019 ENORECOVERY
LE C/C++ equivalent
struct hostent *gethostbyname(char *name);Code example
/* REXX EZARXR09 */
/*
* This sample demonstrates the use of the GETHOSTBYNAME
* socket command.
*/
src = socket("INITIALIZE","MYSET01");
if perror(src,"INITIALIZE") = 0 then do
Say socket("GETHOSTBYNAME", "MYCOMPANY");
Say socket("GETHOSTBYNAME", "MYCOMPANY.somewhere.com");
end;
src = socket("TERMINATE","MYSET01");
src = perror(src,"TERMINATE");
exit 0;
/* This routine returns -1 if the first word if arg 1 is not zero */
perror: if word(arg(1),1) = 0 then return 0; else
Say arg(2) "Error : "arg(1);
return -1;
