私のネットワークには、IPアドレスが10.0.0.15のサーバーがあります。偶然、次のコマンドが見つかりました。ping 10.0.15
結果は次のとおりです。
64 bytes from 10.0.0.15: icmp_seq=1 ttl=64 time=9.09 ms
...それで、正しいサーバーがpingに応答します。試してもping 10.15
同様の結果が表示されます。また、一部のアドレスへのリモートログインは期待どおりに機能します。しかし、SSHは失敗します。部分アドレスに送信されたパケットが正しいサーバーに到達するのはなぜですか?
ベストアンサー1
inet_aton(3)
関数文書によると、許容される形式は次のとおりです。
DESCRIPTION
inet_aton() converts the Internet host address cp from the IPv4 num‐
bers-and-dots notation into binary form (in network byte order) and
stores it in the structure that inp points to. inet_aton() returns
nonzero if the address is valid, zero if not. The address supplied in
cp can have one of the following forms:
a.b.c.d Each of the four numeric parts specifies a byte of the
address; the bytes are assigned in left-to-right order to
produce the binary address.
a.b.c Parts a and b specify the first two bytes of the binary
address. Part c is interpreted as a 16-bit value that
defines the rightmost two bytes of the binary address. This
notation is suitable for specifying (outmoded) Class B net‐
work addresses.
a.b Part a specifies the first byte of the binary address. Part
b is interpreted as a 24-bit value that defines the rightmost
three bytes of the binary address. This notation is suitable
for specifying (outmoded) Class C network addresses.
a The value a is interpreted as a 32-bit value that is stored
directly into the binary address without any byte rearrange‐
ment.
例えば
$ perl -MSocket=inet_aton,inet_ntoa -E 'say inet_ntoa(inet_aton("10.0.15"))'
10.0.0.15
$ perl -MSocket=inet_aton,inet_ntoa -E 'say inet_ntoa(inet_aton("10.15"))'
10.0.0.15
$
ただし、今はIPv6サポートに切り替えるgetaddrinfo
かinet_ntop
、IPv6サポートを要求する方が良いです。 「クラスB」のエントリーは1994年頃にレガシーになりました/24
。
ねえ、あなたもそれに大きな整数を与えることができます。 (でもそうではありません)
$ perl -MSocket=inet_aton,inet_ntoa -E 'say inet_ntoa(inet_aton("2130706433"))'
127.0.0.1
$ getent hosts 2130706433
127.0.0.1 2130706433
$ ssh 2130706433
The authenticity of host '2130706433 (127.0.0.1)' can't be established.
...
(これは他のUnixに移植されない可能性があります。特にOpenBSDは2130706433を確認できません...)