Uncommon IP notations

后端 未结 2 964
有刺的猬
有刺的猬 2021-01-14 05:06

I know that it is possible to write IPs in IPv4 as an integer e.g. 2130706433 instead of 127.0.0.1.

What is the reason for this possibility

2条回答
  •  时光说笑
    2021-01-14 05:55

    IPv4 addresses can be represented in multiple ways. For example the default loopback IP can be one of:

    • 127.0.0.1
    • 0177.0.0.1
    • 0x7f.0.0.1
    • 127.0.1
    • 127.1
    • 2130706433
    • 017700000001
    • 0x7f000001

    The first notation (full 8-bit decimal dotted) is in wide usage, the remaining ones are seldom used but allowed by the inet_addr POSIX standard function. Only the first familiar notation has been retained in the newer inet_ntop/inet_pton POSIX standard functions which process both IPv4 and IPv6 addresses.

    With IPv6, 16-bit hexadecimal dotted notation with an optional decimal dotted trailer (for embedded IPv4) and also an optional zero compression is what the standard defines.

    eg:

    • 2001:0db8:85a3:0000:0000:8a2e:9370:7334
    • 2001:0db8:85a3::8a2e:9370:7334

    There are then still multiple representations of a single address. To avoid the resulting confusion RFC 5952 recommends a canonical form that allows a unique notation.

提交回复
热议问题