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 :
and the test result is like that:
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
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
相关文章推荐
- This function has none of Deterministic,no sql,or reads sql data in its declaration and binary logging is enabled(you *might* want to use the less safe log_bin_trust_function_creators variable
- What is the difference between SVD and matrix factorization in context of recommendation engine?
- Linux下开发warning:"the `gets' function is dangerous and should not be used"
- linux安装问题:what is the location of the gcc program on your machine
- The Linux Staging Tree, what it is and is not.
- What is the difference between XML and C or C ?
- What is the content of J2EE EAR, WAR and JAR files?
- what is the hell of uv's tiling and offset
- what is the different between function and method in python
- The usage of the Javascript method call and apply(what is the new and object.create difference.)(What does call(null) mean?)
- [C++ Template]what is the type of instantiation of template function.
- [POST] What Is the Linux fstab File, and How Does It Work?
- What is the role of the activation function in a neural network?
- ReactJs 报错 Element type is invalid: expected a string (from built-in components) or a class/function (for composite components) but got: undefined. Check the render method of `Me`.
- What is the difference between the Linux Kernel and the Android Kernel?
- FW - check whether tree is balanced or not - find the max and min of one tree- 2013年12月18日13:12:04
- What is an intuitive explanation of the relation between PCA and SVD?
- Determine whether the product of a and b is even or odd.
- The State of Visual Analytics Views on what visual analytics is and where it is going
- What is the purpose of @SmallTest, @MediumTest, and @LargeTest annotations in Android?