troubleshooting Question

C - convert IP address (dotted decimal) to long and back

Avatar of jchristn123
jchristn123 asked on
CC++
9 Comments2 Solutions19570 ViewsLast Modified:
Hello, how do I convert from IP address to network byte order and then back to IP address using char and long?

I have:

char ipaddress[15]='127.0.0.1';
long x;
x=inet_addr(ipaddress);
printf("x=%d\n",x);

but how do I do the reverse if I know x equals some value and want to convert back to a character array with the dotted decimal IP?

Thanks!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros