This article is a mirror article of machine translation, please click here to jump to the original article.

View: 10119|Reply: 1

IPv4 and IPv6 address lengths

[Copy link]
Posted on 3/21/2019 5:12:16 PM | | |
The binary form of IPv4 addresses is 32, and the maximum length is 15 in our commonly used dot decimal form, for example, "255.255.255.255"

Therefore, the maximum length of the IPv4 address string form defined in the <netinet/in.h> of posix is 16 bytes, and the '\0' terminator also needs to occupy 1 byte:

#define INET_ADDRSTRLEN 16

The binary form of IPv6 addresses is 128 long, and it is expressed in hexadecimal form such as "ffff:ffff:ffff:ffff", at first I thought that the maximum length of the IPv6 address string form was 128/4+7+1=40 bytes

However, looking at the IPv6 address string form defined in the <netinet/in.h> of posix, the maximum length is 46 bytes

#define INET6_ADDRSTRLEN 46

The IPv6 address originally mapped by IPv4 may have this format "ffff:ffff:ffff:ffff:255:255:255:255", which is 45 bytes, plus the closing character is 46 bytes




Previous:WebAPI implements graphical verification code function
Next:asp.net Customize 404 in MVC4
Posted on 3/22/2019 4:12:49 PM |
Prompt:Authors are banned or removed content is automatically blocked
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com