Gethostbyname

From Spectrum
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

gethostbyname (IXCALL 0x3E27) - get network host entry

Synopsis

Assembly language

   ld hl, STR_HOSTNAME
   ld de, BUF_ADDRESS
   ld ix, GETHOSTBYNAME
   call IXCALL

C

   #include <netdb.h>

   struct hostent *gethostbyname(char *name);

Description

The gethostbyname() call converts the string passed in name to an address. The parameter name may be a null-terminated hostname (such as 'www.worldofspectrum.org' or a null-terminated dotted decimal string representation of an IP address. If a dotted decimal address is passed, no lookup is made, and the string is converted to a 4 byte big-endian representation of the address. If a hostname is passed, the hostname is looked up using the DNS protocol, and the resolved address is returned as a 4 byte big-endian value. With the current implementation, only one address is returned on a successful lookup.

For the C function call, the pointer returned is to a statically allocated buffer. If the value returned needs to be preserved when a subsequent call to gethostbyname() is made, the value must be copied before the next call is made.

For the assembly language interface, the register pair HL points to a null-terminated string containing the hostname or dotted decimal IP address, and the DE register pair points to a location in memory with at least 4 bytes free to receive the 4 byte big-endian representation of the address.

Return values

The C interface returns a null pointer if gethostbyname() fails to resolve the address.

The assembly language interface returns with the carry flag set on error, with the A register containing the return code.