How to convert a 32-bit integer value to an ip-address?
I am having int value=570534080
and want to convert it to 192.168.1.34
.
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(void) {
int value=570534080;
struct in_addr addr = {value};
printf( "%s", inet_ntoa( addr ) );
return 0;
}
Test: http://ideone.com/RCDgj4
For Windows use #include <winsock2.h>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With