xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

INetGetHosts()

Queries IP addresses associated with a name.

Syntax

INetGetHosts( <cHostName> ) --> aIPAddresses

Arguments

<cHostName>
This is a character string holding either the URL (DNS name) of the host to query, or its IP address in dotted notation (e.g. "192.168.1.145").

Return

The function returns an array filled with character strings holding IP addresses in dotted notation. If a network error occurs, the function returns NIL.

Description

Function INetGetHosts() is used to resolve IP addresses from a host name. The IP addresses associated with a host name are collected in an array which is returned. The IP addresses are stored as character strings in dotted notation. These strings can be passed to INetConnectIP() for establishing a connection to a host.

Note:  INetGetHosts() function is not thread safe by design. A programmer must be sure not to call it simultaneousley at the same time in two different threads, and not to use it at the same time as InetConnect(). If such a simultaneous call cannot be avoided. a call to INetGetHosts() and/or INetConnect() must be protected with a mutex.

Info

See also:INetAddress(), INetConnect(), INetGetAlias()
Category: Internet functions , Sockets functions , xHarbour extensions
Source:vm\INet.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example dispays the IP addresses of a local and a remote host.

   PROCEDURE Main
      LOCAL aIP

      INetInit()

      aIP := INetGetAlias( "www.xHarbour.com" )

      ? ValToPrg( aIP )          // result: { "193.239.210.10" }

      aIP := INetGetAlias( "localhost" )

      ? ValToPrg( aIP )          // result: { "127.0.0.1" }

      INetCleanUp()
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe