I am having problem with inet_aton
to convert a network address. The code below works fine to convert the address 10.0.0.1
char *x1;
struct sockaddr_in si_other;
inet_aton("10.0.0.1", &si_other.sin_addr);
printf("si_other.sin_addr =%lu\n",si_other.sin_addr);
x1 = inet_ntoa(si_other.sin_addr);
printf("x1=%s\n",x1);
It outputs:
si_other.sin_addr =16777226
x1=10.0.0.01
No problem so far. However, the function works weird when 010.000.000.001
is passed
char *x2;
struct sockaddr_in si_other2;
inet_aton("010.000.000.001", &si_other2.sin_addr);
printf("si_other2.sin_addr =%lu\n",si_other2.sin_addr);
x2 = inet_ntoa(si_other2.sin_addr);
printf("x2=%s\n",x2);
outputs:
si_other.sin_addr2 =16777224
x2=8.0.0.01
The function works fine when 192.168.0.1
and 192.168.000.001
are passed.
Can anyone explain me what is the problem and how I can fix the problem? (note: I need to pass the IP address as 010.000.000.001
in my code)