Introduction


T
his book shows how to retrieve all IP addresses of the local computer. This is very useful when writing server applications. A server socket is bound to a single IP address only. But if a computer has more than one IP address the server will receive queries only if the client explicitely sends them to the bound IP. So the server should bind its service to all IP addresses of the computer.
Get all IP addresses


T
o retrieve all IP addresses this function calls "GetHostByName" from the WinAPI. This API call returns a pointer to a HostEnt structure which holds lot of interesting network information about a computer. This includes the hosts full qualified domain name, a list of its alias names, and all of its IP addresses.

'Author     : Daniel, Master Sourcerer at Kitana's Cas...
'Last change: March 15, 2004
'Email      : sourcerer@kitana.org


'Retrieves all IP addresses of the local computer

#DIM ALL

#INCLUDE "WSOCK32.INC"



'Converts an IP address to a string
FUNCTION IPTOSTR$(IP&)
  LOCAL I&,A$,X&,P&

  P&=IP&
  FOR I&=1 TO 4
    X&=P& AND 255
    P&=INT(P&/256)
    IF A$<>""THEN A$=A$+"."
    A$=A$+LTRIM$(STR$(X&))
  NEXT I&

  IPTOSTR$=A$
END FUNCTION



Arena Play Ground Throne Room Theatre Hall Library Back Print Next page Last page