Windows API Guide: GetArcDirection Function


Declare Function gethostbyaddr Lib "wsock32.dll" (addr As Long, ByVal length As Long, ByVal protocol As Long) As Long

Platforms

  • Windows 95: Supported.
  • Windows 98: Supported.
  • Windows NT: Requires Windows NT 3.1 or later.
  • Windows 2000: Supported.
  • Windows CE: Requires Windows CE 1.0 or later.

Description & Usage

gethostbyaddr gets information about a host computer. The computer is identified by its network address (usually but not necessary an IP address). The information about the host is placed into a HOSTENT structure, a pointer to which is returned by the function.

Return Value

If successful, the function returns a pointer to a HOSTENT structure that contains data about the host. This pointer is only guaranteed to be valid until the next call to a Winsock function. If an error occured, the function returns zero (use WSAGetLastError to get the error code.

Visual Basic-Specific Issues

To access the returned data, use CopyMemory to copy the data referenced by the pointer into a HOSTENT structure allocated by your program. See the example for a demonstration of this.

Parameters

addr
The address of the host computer to get information about. This address must be in network byte order.
length
The length in bytes of the address. For IP addresses, this will be 4.
protocol
One of the following flags specifying the type of address specified in addr. The flag identifies the protocol in which the address is used.
AF_12844
IEEE 1284.4 WG AF Protocol.
AF_APPLETALK
Appletalk protocol.
AF_ATM
Native ATM services protocol.
AF_BAN
Banyan protocol.
AF_CCITT
One of the CCITT protocols (such as X.25).
AF_CHAOS
One of the MIT CHAOS protocols.
AF_CLUSTER
Microsoft Wolfpack protocol.
AF_DATAKIT
One of the Datakit protocols.
AF_DECnet
DECnet protocol.
AF_DLI
Direct Data Link interface.
AF_ECMA
A European Computer Manufacturers protocol.
AF_FIREFOX
A FireFox protocol.
AF_HYLINK
NSC Hyperchannel protocol.
AF_IMPLINK
Arpanet IMP address.
AF_INET
Internet or other inter-network address (such as UDP/IP or TCP/IP).
AF_INET6
Internet or other inter-network address using IPv6 addresses.
AF_IPX
One of the IPX protocols (such as IPX or SPX).
AF_ISO
One of the ISO protocols.
AF_LAT
LAT protocol.
AF_NETBIOS
NetBIOS protocol.
AF_NS
One of the Xerox NS protocols, including IPX.
AF_OSI
One of the ISO protocols. (Same as AF_ISO.)
AF_PUP
A PUP protocol address.
AF_SNA
IBM SNA protocol.
AF_UNIX
A Unix-type local-to-host pipe or portal.
AF_UNKNOWN1
An unknown protocol.
AF_VOICEVIEW
VoiceView protocol.

Constant Definitions

Const AF_12844 = 25 Const AF_APPLETALK = 16 Const AF_ATM = 22 Const AF_BAN = 21 Const AF_CCITT = 10 Const AF_CHAOS = 5 Const AF_CLUSTER = 24 Const AF_DATAKIT = 9 Const AF_DECnet = 12 Const AF_DLI = 13 Const AF_ECMA = 8 Const AF_FIREFOX = 19 Const AF_HYLINK = 15 Const AF_IMPLINK = 3 Const AF_INET = 2 Const AF_INET6 = 23 Const AF_IPX = 6 Const AF_ISO = 7 Const AF_LAT = 14 Const AF_NETBIOS = 17 Const AF_NS = 6 Const AF_OSI = 7 Const AF_PUP = 4 Const AF_SNA = 11 Const AF_UNIX = 1 Const AF_UNKNOWN1 = 20 Const AF_VOICEVIEW = 18

Example

Create an IP Address control and use it to prompt the user for an IP address. When the user clicks button cmdGetDomain, the program looks up the first domain name assigned to that address.

To use this example, place a command button named cmdGetDomain on a form window. The IP Address control is created and destroyed by invoking API functions directly and does not need to be placed on the form beforehand.

' This code is licensed according to the terms and conditions listed here. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Type WSADATA wVersion As Integer wHighVersion As Integer szDescription As String * 257 szSystemStatus As String * 129 iMaxSockets As Long iMaxUdpDg As Long lpVendorInfo As Long End Type  Public Declare Function WSAStartup Lib "wsock32.dll" (ByVal wVersionRequested As Integer, lpWSAData _ As WSADATA) As Long Public Declare Function WSACleanup Lib "wsock32.dll" () As Long Public Type HOSTENT h_name As Long h_aliases As Long h_addrtype As Integer h_length As Integer h_addr_list As Long End Type Public Const AF_INET = 2 Public Declare Function htonl Lib "wsock32.dll" (ByVal hostlong As Long) As Long Public Declare Function gethostbyaddr Lib "wsock32.dll" (addr As Long, ByVal length As Long, ByVal _ protocol As Long) As Long Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source _ As Any, ByVal length As Long) Public Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" (ByVal lpString As Any) As Long Public Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" (ByVal lpString1 As Any, ByVal _ lpString2 As Any) As Long Public Type INITCOMMONCONTROLSEX_TYPE dwSize As Long dwICC As Long End Type Public Declare Function InitCommonControlsEx Lib "comctl32.dll" (lpInitCtrls As _ INITCOMMONCONTROLSEX_TYPE) As Long Public Const ICC_INTERNET_CLASSES = &H800 Public Declare Function CreateWindowEx Lib "user32.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long, _ ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x _ As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, _ ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long Public Const WC_IPADDRESS = "SysIPAddress32" Public Const WS_CHILD = &H40000000 Public Const WS_VISIBLE = &H10000000 Public Declare Function DestroyWindow Lib "user32.dll" (ByVal hWnd As Long) As Long Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg _ As Long, wParam As Any, lParam As Any) As Long Public Const IPM_ISBLANK = &H469 Public Const IPM_GETADDRESS = &H466 ' *** Place the following code in a form window. *** Private hIPControl As Long  ' handle to the IP Address control ' When the form is initialized, create an IP Address control in the ' upper-left corner of the form. Private Sub Form_Initialize() Dim comctls As INITCOMMONCONTROLSEX_TYPE  ' identifies the control to register Dim retval As Long                        ' generic return value ' Register the IP Address control window class. With comctls .dwSize = Len(comctls) .dwICC = ICC_INTERNET_CLASSES End With retval = InitCommonControlsEx(comctls) ' Create the IP Address control in the corner of the window. hIPControl = CreateWindowEx(0, WC_IPADDRESS, "", WS_CHILD Or WS_VISIBLE, 0, 0, 125, 20, _ Me.hWnd, 0, App.hInstance, ByVal CLng(0)) End Sub ' Destroy the IP Address control when the form closes. Private Sub Form_Unload(Cancel As Integer) Dim retval As Long  ' return value retval = DestroyWindow(hIPControl) End Sub ' Look up the primary domain name of the host computer identified by the ' address in the IP Address control. Private Sub cmdGetDomain_Click() Dim ipAddress_h As Long   ' the IP address, in host byte order Dim ipAddress_n As Long   ' the IP address, in network byte order Dim sockinfo As WSADATA   ' information about the Winsock implementation Dim pHostinfo As Long     ' pointer to information about the host computer Dim hostinfo As HOSTENT   ' information about the host computer Dim domainName As String  ' the primary domain name of the host computer Dim retval As Long        ' generic return value ' Verify that an IP address was entered. retval = SendMessage(hIPControl, IPM_ISBLANK, ByVal CLng(0), ByVal CLng(0)) If retval <> 0 Then Debug.Print "No IP address was entered!" Exit Sub End If ' Get the IP address entered by the user and verify that all ' four fields in the address were entered. retval = SendMessage(hIPControl, IPM_GETADDRESS, ByVal CLng(0), ipAddress_h) If retval < 4 Then Debug.Print "An incomplete IP address was entered!" Exit Sub End If ' Open up a Winsock v2.2 session. retval = WSAStartup(&H202, sockinfo) If retval <> 0 Then Debug.Print "ERROR: Attempt to open Winsock failed: error"; retval Exit Sub End If ' Convert the IP address into network byte order. ipAddress_n = htonl(ipAddress_h) ' Get information about the host computer. pHostinfo = gethostbyaddr(ipAddress_n, 4, AF_INET) If pHostInfo = 0 Then Debug.Print "Could not find a host with the specified IP address." Else ' Copy the data into the structure. CopyMemory hostinfo, ByVal pHostinfo, Len(hostinfo) ' Copy the host domain name into a string. domainName = Space(lstrlen(hostinfo.h_name)) retval = lstrcpy(domainName, hostinfo.h_name) Debug.Print "Domain name is: "; domainName End If ' End the Winsock session. retval = WSACleanup() End Sub

See Also

gethostbyname

Category

Winsock

Back to the Function list.
Back to the Reference section.


Last Modified: October 29, 2000
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/g/gethostbyaddr.html



Windows API Guide
Windows API Guide - Reference - Volume 1: Version 3.0 For the MS-DOS and PC-DOS Operating Systems
ISBN: B001V0KQIY
EAN: N/A
Year: 1998
Pages: 610

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net