Hi! Has anyone experience with calling gethostbyname? I dunno why but I don't get correct results. (function always fails == HOST NOT found) Then I coded it in C and it worked! i called the function in this way: call @@1 smtpserver db 'mail.cso.co.at',0 @@1: call gethostbyname test eax,eax jz err_exit ; always got there :) Does anyone know why this works not properly??
Posted on 2001-05-07 17:02:00 by MikeW

call @@1
smtpserver db 'mail.cso.co.at',0
@@1:
call gethostbyname
Here there are several errors... call @@1 - you probably mean jump @@1 as you define in line 2 a string. Then you need to push the string so that gethostbyname knows what to check for ;)
Posted on 2001-05-08 05:42:00 by JimmyClif
That's a very funny way to call a function ! The only reasons that may not work i found : - you forget to call WSAStartup ( it happens :) - mail.cso.co.at doesn't exist ( try with "localhost" ) ? - you aren't connected... Also think to check WSAGetLastError code. But your code works with my computer.
Posted on 2001-05-08 16:44:00 by BJZ
I didn't forget to call WSAStartup correctly, the host isn't down and i was connected. At a friends PC it also didn't work correctly. Then I sent the sample to other coders and it worked! My computer must be dammed! Anyways 10x for your help! PS: JimmyClif: this works, really!
Posted on 2001-05-11 03:10:00 by MikeW
It somehow doesn't work at your puter tho, right ;) Well, it's somehow against my own logic to accept this as working code... it may work, if you say so... but I'd treat this line as error whereever I'd see it inside code... Could someone explain to me why this is working code? How does gethostbyname know where this server string is located?
Posted on 2001-05-11 06:09:00 by JimmyClif
When you made a call, the return adress is pushed on the stack so the code :

call @@2
@@1:
...
@@2:
is equivalent to :

push @@1
jmp @@2
@@1:
...
@@2:
So with the call it pushes the param then he calls normally gethostbyname. Have you tried a minimal implementation of gethostbyname ? A thing like :

.data
  WSAData    WSADATA<>
.code
Start:
invoke WSAStartup,101h,addr WSAData
call @@1
db "localhost",0
@@1:
call gethostbyname
invoke ExitProcess,eax
end Start
This message was edited by BJZ, on 5/11/2001 9:35:05 AM This message was edited by BJZ, on 5/11/2001 9:35:48 AM
Posted on 2001-05-11 09:34:00 by BJZ
Ah.. I see.. ;) the famous push for the ret? which happens to point at the server string and the call to gethostbyname pops it of the stack so that it can go on as no call ever happened... Gee... what's the point doing this tho? One/Two bytes less in the code section?
Posted on 2001-05-11 09:47:00 by JimmyClif
I use this method coz it is very fast to code. dont have to step up in the .data section with 100 times cursor_up page_up! and it looks cool, i think! btw, i'll try to use the asynchronus function of gethostbyname or i'll kick the puter
Posted on 2001-05-11 12:52:00 by MikeW