Winsock2 call : gethostbyname() in Visual Basic

the socket call gethostbyname() have the following
structure:

/********************************/
struct hostent FAR *
gethostbyname(
    const char FAR * name
    );
/*******************************/
so it involves returning a pointer to a UDT, how do I do this in Visual Basic?
I can return the value as BYTE, that doesn't seem to get
me anymore.
any code will be appreciated.
platiumstarAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
yowkeeConnect With a Mentor Commented:
You need to use API RtlMoveMemory to copy the pointer
to structure into UDT in VB:

--
Public Type HOSTENT
    hName As Long
    hAliases As Long
    hAddrType As Integer
    hLength As Integer
    hAddrList As Long
End Type
 
Public Declare Function gethostbyname Lib _
    "WSOCK32.DLL" (ByVal hostname$) As Long
Public Declare Sub RtlMoveMemory Lib _
    "KERNEL32" (hpvDest As Any, ByVal hpvSource&, ByVal cbCopy&)


    Dim hostname As String * 256
    Dim hostent_addr As Long
    Dim host As HOSTENT
    Dim hostip_addr As Long
    Dim temp_ip_address() As Byte
    Dim i As Integer
    Dim ip_address As String

    :   ' Getting host name
    :
    :

    hostent_addr = gethostbyname(hostname)
    If hostent_addr = 0 Then
        MsgBox "Winsock.dll is not responding."
        Exit Sub
    End If

    ' Copy to HOSTENT structure
    RtlMoveMemory host, hostent_addr, LenB(host)
    RtlMoveMemory hostip_addr, host.hAddrList, 4
    ReDim temp_ip_address(1 To host.hLength)
    RtlMoveMemory temp_ip_address(1), hostip_addr, host.hLength
    For i = 1 To host.hLength
        ip_address = ip_address & temp_ip_address(i) & "."
    Next
    ip_address = Left$(ip_address, Len(ip_address) - 1)
    MsgBox ip_address
    :
    :

----

Regards.
0
 
clifABBCommented:
Check out MSKB #Q160215 located at:
http://support.microsoft.com/support/kb/articles/q160/2/15.asp

Basically here's the declares and calls:
Private Declare Function gethostname Lib "WSOCK32.DLL" (ByVal hostname$, HostLen&) As Long
Private Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal hostname$) As Long

   Dim hostname As String * 256
   Dim hostent_addr As Long
  If gethostname(hostname, 256) = SOCKET_ERROR Then
    MsgBox "Windows Sockets error " & Str(WSAGetLastError())
    Exit Sub
  Else
    hostname = Trim$(hostname)
  End If
  hostent_addr = gethostbyname(hostname)

0
 
platiumstarAuthor Commented:
You're returning a long, where does that get me? I want the HOSTENT structure it returned. Maybe You misunderstood the question.

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
alamoCommented:
He had it right, but the pasted text from that article got cut. Rather than me just repaste it here, you should go to the URL clifABB gave, it has an entire example program that does precisely what you want. hostent_addr is a long which holds a pointer to the HOSTENT structure which is then passed to  RtlMoveMemory to copy the structure returned from gethostbyname() into a UDT.

0
 
platiumstarAuthor Commented:
ohhh, ok, stupid me. I guess ClifABB deserve some points. But I like alamo's comment better, explain things. oh well. more points next time.
0
 
platiumstarAuthor Commented:
ohhh, ok, stupid me. I guess ClifABB deserve some points. But I like alamo's comment better, explain things. oh well. more points next time. Thanks to all.
0
All Courses

From novice to tech pro — start learning today.