1. DNS Lookup
- Posted by "Thomas Parslow (PatRat)" <patrat at INAME.COM>
Apr 28, 2000
-
Last edited Apr 29, 2000
Hi,
I'm trying to do a DNS lookup using the winsock function GetHostByName, in
Visual Basic the following works:
Declare Function GetHostByName Lib "wsock32.dll" Alias "gethostbyname"
(ByVal sHostName As String) As Long
In Euphoria I tried this:
constant WSOCK32 = open_dll("wsock32.dll")
atom gethostbyname
gethostbyname = define_c_func(WSOCK32,"gethostbyname",{C_LONG},C_LONG)
memDNS = allocate_string("www.infoseek.com")
? c_func(dllgethostbyname,{memDNS})
free(memDNS)
But it just returns 0, can any one see what I'm doing wrong here?
Thomas Parslow (PatRat) ICQ #:26359483
Rat Software
http://www.ratsoft.freeserve.co.uk/
Get paid to surf the web!
http://members.tripod.co.uk/paid2surf/
2. Re: DNS Lookup
On Fri, 28 Apr 2000 21:33:10 +0100, Thomas Parslow (PatRat)
<patrat at INAME.COM> wrote:
>constant WSOCK32 = open_dll("wsock32.dll")
>atom gethostbyname
>gethostbyname = define_c_func(WSOCK32,"gethostbyname",{C_LONG},C_LONG)
>memDNS = allocate_string("www.infoseek.com")
>? c_func(dllgethostbyname,{memDNS})
>free(memDNS)
>
>? c_func(dllgethostbyname,{memDNS})
shouldn't this be c_func(gethostbyname,{memDNS})
3. Re: DNS Lookup
- Posted by "Thomas Parslow (PatRat)" <patrat at INAME.COM>
Apr 28, 2000
-
Last edited Apr 29, 2000
Whoops! I changed a few variable names before I posted it to make it more
readable.
Thomas Parslow (PatRat) ICQ #:26359483
Rat Software
http://www.ratsoft.freeserve.co.uk/
Get paid to surf the web!
http://members.tripod.co.uk/paid2surf/
----- Original Message -----
From: Bernie Ryan <xotron at BUFFNET.NET>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Friday, April 28, 2000 9:18 PM
Subject: Re: DNS Lookup
> On Fri, 28 Apr 2000 21:33:10 +0100, Thomas Parslow (PatRat)
> <patrat at INAME.COM> wrote:
>
> >constant WSOCK32 = open_dll("wsock32.dll")
> >atom gethostbyname
> >gethostbyname = define_c_func(WSOCK32,"gethostbyname",{C_LONG},C_LONG)
> >memDNS = allocate_string("www.infoseek.com")
> >? c_func(dllgethostbyname,{memDNS})
> >free(memDNS)
> >
>
> >? c_func(dllgethostbyname,{memDNS})
>
> shouldn't this be c_func(gethostbyname,{memDNS})
>
4. Re: DNS Lookup
Hi Thomas
A check of the function says that it returns a pointer.
The Euphoria doc's say
"However the distinction between signed and unsigned may be important
when you specify the return type of a function."
The Eu doc's define C_POINTER = C_ULONG
Perhaps you could try changing the type returned by the c function in your
defininition to C_POINTER or C_ULONG??
eg
gethostbyname = define_c_func(WSOCK32,"gethostbyname",{C_LONG},C_POINTER)
Cheers
Mark
> I'm trying to do a DNS lookup using the winsock function GetHostByName, in
> Visual Basic the following works:
>
> Declare Function GetHostByName Lib "wsock32.dll" Alias "gethostbyname"
> (ByVal sHostName As String) As Long
>
> In Euphoria I tried this:
>
> constant WSOCK32 = open_dll("wsock32.dll")
> atom gethostbyname
> gethostbyname = define_c_func(WSOCK32,"gethostbyname",{C_LONG},C_LONG)
> memDNS = allocate_string("www.infoseek.com")
> ? c_func(gethostbyname,{memDNS})
> free(memDNS)
>
> But it just returns 0, can any one see what I'm doing wrong here?
> Thomas Parslow (PatRat) ICQ #:26359483
> Rat Software
> http://www.ratsoft.freeserve.co.uk/
>
> Get paid to surf the web!
> http://members.tripod.co.uk/paid2surf/
5. Re: DNS Lookup
Hi again Thomas,
I just had a bit more of a look at this.
Is this all of your code or do you have some additional initialisation
code that you haven't supplied?
The example I just read says that you must call WSAStartup() first
to use windows sockets
The example was at http://www.xyzt.way.com/inetprog/index.html
It goes one step at a time and might help.
Also, there seem to be a lot of good code in the Euphoria
archive at RDS, in particular the windows sockets project
by Jesus Consuegra and Greg Harris.
Good luck
Mark
PS. The input to your c function should probably be a C_POINTER
rather than C_LONG
ie
gethostbyname =
----- Original Message -----
From: Thomas Parslow (PatRat) <patrat at INAME.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Saturday, April 29, 2000 6:03
Subject: DNS Lookup
> Hi,
> I'm trying to do a DNS lookup using the winsock function GetHostByName, in
> Visual Basic the following works:
>
> Declare Function GetHostByName Lib "wsock32.dll" Alias "gethostbyname"
> (ByVal sHostName As String) As Long
>
> In Euphoria I tried this:
>
> constant WSOCK32 = open_dll("wsock32.dll")
> atom gethostbyname
> gethostbyname = define_c_func(WSOCK32,"gethostbyname",{C_LONG},C_LONG)
> memDNS = allocate_string("www.infoseek.com")
> ? c_func(dllgethostbyname,{memDNS})
> free(memDNS)
>
> But it just returns 0, can any one see what I'm doing wrong here?
> Thomas Parslow (PatRat) ICQ #:26359483
> Rat Software
> http://www.ratsoft.freeserve.co.uk/
>
> Get paid to surf the web!
> http://members.tripod.co.uk/paid2surf/