Click here to Skip to main content
15,920,053 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to make a function convert string into ipaddress in c++ or is there any inbuilt function to do this. (like atoi) plz help...
Posted

Your question is not clear since there is no default variable type in C++ which can hold an IP Address as an IP Address. However, if you have to use this IP Address for some sort of Socket communication, you will have to use a structure like sockaddr_in. If it is so, here is a solution (Taken from here[^]:

MIDL
int rc;
int s;
struct sockaddr_in myname;
/* clear the structure to be sure that the sin_zero field is clear */
memset(&myname, 0, sizeof(myname));
myname.sin_family = AF_INET;
myname.sin_addr = inet_addr("129.5.24.1");
myname.sin_port = htons(1024);
 
Share this answer
 
I think what you want is
101.22.34.55 <----> www.something.com

Well look this is work of DNS.

This link may help you: http://www.stromcode.com/2008/03/02/cwin32-dns-resolution/[^]

To know more about DNS: see http://en.wikipedia.org/wiki/Domain_Name_System[^]

Hope this might help you!!! :)
 
Share this answer
 
Don't think there's any built in solution for this (in C++ or MFC, although MFC does have an IP address control), but if you need to parse a string to an IP address, just use the '.' character to parse the octets, then check to make sure each number is between 0-255.

To use it, you'll probably end up having to put it in a structure as aamir suggested.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900