I've created a server, and i wan't to log all the IP's that visit.

I'm currently using this, but with no luck.

S_un_b0 struct ;es: 127.0.0.1
s_b1 db ? ;es: 127
s_b2 db ? ;es: 0
s_b3 db ? ;es: 0
s_b4 db ? ;es: 1
S_un_b0 ends

mov iLength,sizeof S_un_b0
INVOKE accept,hSock1,offset S_un_b0,addr iLength
invoke getpeername, hSock1, offset S_un_b0, addr iLength
mov eax,offset S_un_b0
bswap eax
mov RemoteIP,eax

But it doesn't get the IP, Can you see anything wrong with it.
Posted on 2003-04-19 09:23:12 by -=TM=-
Why not using the structure discribed in windows.inc ?




sockaddr STRUCT
sa_family WORD ?
sa_data BYTE 14 dup(?)
sockaddr ENDS
Posted on 2003-04-19 10:31:55 by Axial
I tried that.
But it just gives me some unreadable text.
Posted on 2003-04-19 10:51:23 by -=TM=-
First of all, you don't need getpeername, accept already fills a sockaddr_in structure for you. Secondly, look closely at your code, you're not printing the IP, but the swapped address of the structure:


mov eax,offset S_un_b0 ; get the address of S_un_b0
bswap eax ; swap the bytes of the address

You probably now got an IP like 18.48.64.0 or something close to that.

Instead, use sockaddr_in and read the sin_addr.S_un.S_addr member.

Thomas
Posted on 2003-04-19 11:02:40 by Thomas
It's still not working, now i'm using

SA sockaddr_in <>

mov iLength,sizeof sockaddr_in
INVOKE accept,hSock1,offset SA,addr iLength
mov eax,offset SA.sin_addr.S_un.S_addr

but i still get some data other then the IP
Posted on 2003-04-19 13:31:12 by -=TM=-

It's still not working, now i'm using

SA sockaddr_in <>

mov iLength,sizeof sockaddr_in
INVOKE accept,hSock1,offset SA,addr iLength
mov eax,offset SA.sin_addr.S_un.S_addr

but i still get some data other then the IP


Remember you need to convert the IP with inet_ntoa in order see it in plain text.



invoke inet_ntoa, addr SA.sin_addr
Posted on 2003-04-20 03:47:32 by Axial

It's still not working, now i'm using

SA sockaddr_in <>

mov iLength,sizeof sockaddr_in
INVOKE accept,hSock1,offset SA,addr iLength
mov eax,offset SA.sin_addr.S_un.S_addr

but i still get some data other then the IP

Remove the 'offset', you don't want the offset of S_addr, you want the contents..

Thomas
Posted on 2003-04-20 04:03:08 by Thomas
Thankx Thomas and Axial, youv'e been a great help.
Posted on 2003-04-21 03:47:02 by -=TM=-
After Testing, I get an IP, but's it's not mine or anyone else who connects to the server.

sad sockaddr <>

mov iLength,sizeof sockaddr
INVOKE accept,hSock1,addr sad,addr iLength
invoke inet_ntoa, addr sad

do i need to clear the sockaddr struct before a new connection.
I'm Lost, please help if you can
Posted on 2003-04-21 15:17:39 by -=TM=-
Try



invoke inet_ntoa, addr sad.sin_addr


Regards,
Axial
Posted on 2003-04-21 15:59:42 by Axial
Still not working,
I tried using getpeername just to see if it made a differnce, i also tried it without using accept or getpeer.



invoke inet_ntoa, addr SA.sin_addr


I tried it using just that, and it still gave me an IP, even though the struct is empty.
any ideas?
Posted on 2003-04-23 17:36:02 by -=TM=-
Read my post again, *don't* use 'offset' or 'addr' with inet_ntoa. It wants the address by value, not by reference.

Thomas
Posted on 2003-04-24 01:24:46 by Thomas
Ooops, my mistake !
Sorry.
Posted on 2003-04-24 08:11:24 by Axial
Sorry, I should read it more carefully,
It works now, Heres how i done it.



sad sockaddr_in <>
LOCAL iLength:DWORD

mov iLength,sizeof sockaddr_in
INVOKE accept,hSock1,addr sad,addr iLength
push sad.sin_addr
call inet_ntoa


Thankx Axial and Thomas
Posted on 2003-04-24 08:48:18 by -=TM=-