I have this code which is working fine:
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
struct in_addr addr;
if (argc != 2) {
fprintf(stderr, "%s <dotted-address>\n", argv[0]);
exit(EXIT_FAILURE);
}
if (inet_aton(argv[1], &addr) == 0) {
perror("inet_aton");
exit(EXIT_FAILURE);
}
printf("%s\n", inet_ntoa(addr));
exit(EXIT_SUCCESS);
}
What I want to achieve is print the value of inet_aton()
function. The description of function says that it returns a number, but when I try to print it, it says "cannot covert from address structure to decimal".
Using this instead of your last printf
worked for me:
printf("%d\n", addr.s_addr);