Home
Tutorials
Code Snippets
Code Samples
Downloads
Links

The Blog
Our Projects
About
Contact

::Add RageStorm to Favorites!::

The Blog | Our Projects | Guest Book | About | Contact

 
Code Snippet - Socket to IP
Author:Arkon
Category:Internet & Networks
File Size:207 Bytes
Uploaded at:25-Apr-03 12:20:03 pm
Description:
  Get the IP a socket connected to.
  
// Don't forget to init the sockets DLL!
char* SocktoIP(SOCKET s)
{
 SOCKADDR_IN saddr;
 int so = sizeof(saddr);
 getsockname(s, (SOCKADDR*)&saddr, &so);
 return(inet_ntoa((in_addr)saddr.sin_addr));
}
User Contributed Comments(1)
 [1] Simon | 2010-07-27 09:12:18

Not sure that would work, The saddr object gets destroyed when the function returns, so the char* will be pointing to something that doesn't exist.

It might be better to pass a char point to the function and copy the string into it.
NOTE:
Comments that will hurt anyone in any way will be deleted.
Don't ask for features, advertise or curse.
If you want to leave a message to the author use the contacts,
if you have any question in relation to your comments please use the forum.
Comments which violate any of these requests will be deleted without further
notice. Use the comment system decently.

Post your comment:
Name:
email:
Comment:
::Top 5 Tutorials::
Embedded Python[105776]
2D Rotated Rectangles Collision Detection[79024]
Keyboard Hook[68594]
UDP[52667]
HTTP Proxy[35944]

::Top 5 Samples::
2D ColDet Rotated Rectangles[10589]
PS2 Mouse Driver[6083]
Wave Format Player[4968]
Reading FAT12[4855]
CodeGuru[4543]


All rights reserved to RageStorm © 2009