Tip: Get IP of a peer
Posted: Wed Sep 11, 2002 2:04 pm
Restored from previous forum. Originally posted by tranquil.
Finaly I found it!
After some weeks of damn search through the MSDN. The following code tells your app which IP is connected to the socket you specified. Put it in your code where you check for incomming connections (networkserverevent=1)
Hope it may help the one or other ppl. 
Mike
Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
Finaly I found it!

After some weeks of damn search through the MSDN. The following code tells your app which IP is connected to the socket you specified. Put it in your code where you check for incomming connections (networkserverevent=1)
Code: Select all
bufferlength.b=255
*buffer=GlobalAlloc_(#GMEM_FIXED|#GMEM_ZEROINIT, 255)
res=getpeername_(YOUR SOCKET HERE,*buffer,@bufferlength)
If res=0 ; All okay
val1.b=PeekB(*buffer+4)
val2.b=PeekB(*buffer+5)
val3.b=PeekB(*buffer+6)
val4.b=PeekB(*buffer+7)
ip$=StrU(val1,#Byte)+"."+StrU(val2,#Byte)+"."+StrU(val3,#Byte)+"."+StrU(val4,#Byte)
else
error=wsagetlasterror()
;errorhandling here
endif
globalfree_(*buffer)

Mike
Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User