The Computer Oracle

How many characters can an IP address be?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT


Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5 Looping

--

Chapters
00:00 How Many Characters Can An Ip Address Be?
00:31 Accepted Answer Score 35
01:07 Answer 2 Score 3
02:12 Thank you

--

Full question
https://superuser.com/questions/381022/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#networking #ip #ipaddress

#avk47



ACCEPTED ANSWER

Score 35


An IPv6 address, at its longest, would be 8 sets of 4 characters (32 total), each set separated by a colon. That makes 39 characters.

An IPv4 address is at most 4 sets of 3 numbers (12 characters), each set separated by a dot (.). That makes 15 characters.

All of this assumes the IP addresses should be stored in human-readable form. I prefer to store IP addresses in decimal form, as you never quite know how it will be used. Your mileage may vary.




ANSWER 2

Score 3


This is not as easy as one might think.

In most cases your are safe with 45.

Normal IPv6 address

0000:0000:0000:0000:0000:0000:0000:0000

8 * 4 + 7 = 39


IPv4-mapped IPv6 address

See rfc4291

0000:0000:0000:0000:0000:ffff:192.168.100.228

(6 * 4 + 5) + 1 + (4 * 3 + 3) = 29 + 1 + 15 = 45


Header files define INET6_ADDRSTRLEN to be 46


IPv6 with scope zone

See rfc4007

Scope zone can be a number or even a string (interface name).

ff02::5678%5
ff08::9abc%interface10

The length of the interface name depends on the system. In Linux it is defined by the IFNAMSIZ constant. 16 is a common value. With the 45 chars from above:

45 + 1 + 16 = 62


Also see https://stackoverflow.com/questions/166132/maximum-length-of-the-textual-representation-of-an-ipv6-address