gnu ip address

How to convert an string to ip address in GNU C++?

My task is to pass a parameter to my C++ program, which describes an ip address. after that, I need to convert the passed in ip address string to corresponding id address, which will be assigned to sockaddr_in.sin_addr.s_addr.

For example, my program accepts a parameter called ip, it is string.

when I set up a server socket, I need to specify the address from where my server will listend for incoming connections. normally we set the address to htonl(INADDR_ANY), so the address structure is like:
1
2
3
4
5
6
7
struct sockaddr_in servaddr;

servaddr.sin_family = AF_INET; 

servaddr.sin_addr.s_addr = htonl(INADDR_ANY); 

servaddr.sin_port = htons(DAYTIME_SERVER_PORT);


but this time I need to assign a specific ip address, represented by the string ip passed in as my server program parameter. then how to assign this ip string to servaddr.sin_addr.s_addr ?

thanks alot
Topic archived. No new replies allowed.