您的位置:首页 > 运维架构 > Linux

Linux and C[2]: What is the function of inet_aton or inet ntoa ?

2017-02-25 22:41 633 查看
What ever :inet_aton function translate ip address presentation such as “192.168.0.1” to numeric number in host.That is to say ,this function will transfer a string like ip address into a numeric ip address.

Test :

int main(){
int sockfd = socket(AF_INET,SOCK_RAW,0);
struct sockaddr_in server_sock_in;
bzero(&server_sock_in,sizeof(struct sockaddr_in));
server_sock_in.sin_family=AF_INET;

inet_aton("14.17.42.40",&(server_sock_in.sin_addr));
printf("\nThe host 14.17.42.40 after aton function:\n%X\n",server_sock_in.sin_addr.s_addr);
}


and the test result is like that:

The host 14.17.42.40 after aton function:
282A110E


According to the test above ,we can see how the function inet_aton works:

1. first , this function translate ‘14.17.42.40’ to big-endian like 0x0E 11 2A 28

2. then , this function will transfer big-endian to little endian if your system is little endian.0x 0E 11 2A 28–>0x 28 2A 11 0E
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐