Hi I am wondering about the syntax to convert the value in address.sin_addr.s_addr into readable ip value (ie reverse of inet_addr?). btw I do know we can just use address.sin_addr to get the ip, but i need to use s_addr to pass ip infos between clients

thanks in advance

Recommended Answers

All 3 Replies

You mean something like:

char *buffer;
buffer = inet_ntoa(address.sin_addr);

yeah but instead of using address.sin_addr, i need to use address.sin_addr.s_addr. Uh, this is confusing, lets see...

say, if i have an IP address userIP=110.110.110.11 and i want to connect to this ip, one way to store the ip is

....
user1.sin_addr.s_addr=inet_addr(userIP);

or just aton & ntoa combination

now i want to decode the value in user1.sin_addr.s_addr and print out the IP, is that possible to get something like 11011011011 or something similar?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.