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 - IP or DN
Author:Arkon
Category:Internet & Networks
File Size:594 Bytes
Uploaded at:23-Apr-03 11:17:16 am
Description:
  This snippet shows how to convert an IP address or a domain name (given in a char*) to an IP address so it would fit in the SOCKADDR_IN structure...
  
char* address = "<DN | IP>";
// Address can be both "ragestorm.net" or "216.118.76.209"

SOCKADDR_IN server_info = {0};

// First try interpreting the address as IP
server_info.sin_addr.s_addr = inet_addr(address);
if (server_info.sin_addr.s_addr == INADDR_NONE) { // Uh ho
// Now it's might be an address, DNS is coming in...
hostent* server_host = gethostbyname(address);
if (server_host != NULL) {
server_info.sin_addr = *(in_addr *)server_host->h_addr;
} else {
MessageBox(NULL, "Given host is not found!", NULL, MB_OK);
// Exit?
}
}

// Fill in other fields...
User Contributed Comments(None)
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[117074]
2D Rotated Rectangles Collision Detection[88996]
Keyboard Hook[77341]
UDP[65890]
HTTP Proxy[41226]

::Top 5 Samples::
2D ColDet Rotated Rectangles[11562]
PS2 Mouse Driver[6960]
Wave Format Player[5793]
Reading FAT12[5621]
CodeGuru[5361]


All rights reserved to RageStorm © 2009