我在inet_aton
转换网络地址时遇到问题。下面的代码可以很好地转换地址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);
它输出:
si_other.sin_addr =16777226
x1=10.0.0.01
到目前为止没有问题。010.000.000.001
但是,该函数在传递时工作起来很奇怪
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);
输出:
si_other.sin_addr2 =16777224
x2=8.0.0.01
该函数在192.168.0.1
和192.168.000.001
被传递时工作正常。
谁能解释我是什么问题以及如何解决问题?(注意:我需要010.000.000.001
在我的代码中传递 IP 地址)