当前位置:网站首页>socket inet_ pton() inet_ Ntop() function (a new network address translation function, which converts the expression format and numerical format to each other. The old ones are inet_aton(), INET_ ntoa
socket inet_ pton() inet_ Ntop() function (a new network address translation function, which converts the expression format and numerical format to each other. The old ones are inet_aton(), INET_ ntoa
2022-07-04 07:11:00 【Dontla】
New network address translation function :
Remove the buffer from CP At the beginning Internet The representation format of the number is converted to binary network format , And the interface type AF The results are stored from BUF In the start buffer .
The function of this code is similar , What's the difference ?
serv_addr.sin_addr.s_addr = inet_addr("192.168.1.116");
take Internet Host address from CP The numbers and dot symbols in are converted into binary data in network byte order .
New network address translation function inet_pton() and inet_ntop()
These two functions follow IPv6 Functions that appear , about IPv4 Address and IPv6 All addresses apply , Function p and n Each represents the expression (presentation) And numbers (numeric). The expression format of address (presentation) Usually ASCII character string , The numerical format (numeric) Is the binary value stored in the socket address structure .
#include <arpa/inet.h>
int inet_pton(int family, const char *strptr, void *addrptr); // Will be dotted decimal ip The address is converted into a numeric format for network transmission
Return value : If successful 1, If the input is not a valid expression 0, In case of error -1
const char * inet_ntop(int family, const void *addrptr, char *strptr, size_t len); // Convert numerical format to dot decimal ip Address format
Return value : If successful, a pointer to the structure , In case of error NULL
(1) Of these two functions family The parameter can be either AF_INET(ipv4) It can also be AF_INET6(ipv6). If , Take an unsupported address family as family Parameters , Both functions return an error , And will errno Set as EAFNOSUPPORT.
(2) The first function attempts to convert from strptr The string that the pointer points to , And pass addrptr The pointer holds the binary result , If successful, the return value is 1, Otherwise, if specified family The input string is not a valid expression format , So the return value is zero 0.
(3)inet_ntop Do the opposite conversion , From the numerical format (addrptr) Convert to expression (strptr).inet_ntop Functional strptr Parameter cannot be a null pointer . The caller must allocate memory for the target storage unit and specify its size , When the call succeeds , This pointer is the return value of the function .len Parameter is the size of the target storage unit , To prevent the function from overflowing its caller's buffer . If len Too small , Not enough to hold expression results , Then return a null pointer , Juxtaposition as errno by ENOSPC.
Reference article 1:inet_pton() and inet_ntop() Function details
Reference article 2:IP Address translation function :inet_pton
边栏推荐
- Electronic Association C language level 1 34, piecewise function
- what the fuck! If you can't grab it, write it yourself. Use code to realize a Bing Dwen Dwen. It's so beautiful ~!
- MySQL 45 lecture learning notes (XIII) delete half of the table data, and the table file size remains the same
- Tar source code analysis 8
- Su Weijie, a member of Qingyuan Association and an assistant professor at the University of Pennsylvania, won the first Siam Youth Award for data science, focusing on privacy data protection, etc
- 用于压缩视频感知增强的多目标网络自适应时空融合
- A new understanding of how to encrypt industrial computers: host reinforcement application
- How to buy financial products in 2022?
- Selection (023) - what are the three stages of event propagation?
- [thread pool]
猜你喜欢
The final week, I split
"Sword finger offer" 2nd Edition - force button brush question
Pangu open source: multi support and promotion, the wave of chip industry
[thread pool]
selenium驱动IE常见问题解决Message: Currently focused window has been closed.
移动适配:vw/vh
Campus network problems
用于压缩视频感知增强的多目标网络自适应时空融合
Flink memory model, network buffer, memory tuning, troubleshooting
电脑通过Putty远程连接树莓派
随机推荐
Finishing (III) - Exercise 2
Analysis of tars source code 5
Cell reports: Wei Fuwen group of the Institute of zoology, Chinese Academy of Sciences analyzes the function of seasonal changes in the intestinal flora of giant pandas
Tar source code analysis Part 7
Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and
Review of enterprise security incidents: how can enterprises do a good job in preventing source code leakage?
Knowledge payment applet dream vending machine V2
BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
flask-sqlalchemy 循环引用
Bottom problem of figure
Redis interview question set
Vulhub vulnerability recurrence 77_ zabbix
Analysis of tars source code 1
Selection (022) - what is the output of the following code?
js 常用时间处理函数
leetcode825. Age appropriate friends
移动适配:vw/vh
NLP-文献阅读总结
Since DMS is upgraded to a new version, my previous SQL is in the old version of DMS. In this case, how can I retrieve my previous SQL?
Vulhub vulnerability recurrence 76_ XXL-JOB