inet_aton#
Turn a dotted-quad string or a hostname into a 4-byte packed IPv4 address, or undef if the name cannot be resolved.
תקציר#
my $packed = inet_aton("127.0.0.1");
my $packed = inet_aton("localhost");
מה מוחזר#
A 4-byte string in network byte order suitable as the second argument to pack_sockaddr_in, or undef on failure. To see the bytes as a human-readable address, pass the result through inet_ntoa.
דוגמאות#
my $loop = inet_aton("127.0.0.1"); # 4-byte string
print join(".", unpack("C4", $loop)); # 127.0.0.1
my $sin = pack_sockaddr_in(80, inet_aton("example.com"));
## pass $sin to connect()
מקרי קצה#
A literal IPv4 address is parsed directly - no DNS lookup.
A non-resolvable name returns
undef.IPv6 addresses are rejected here; use
inet_pton(AF_INET6, ...).
הבדלים מן ה-upstream#
Fully compatible with upstream Socket.
ראו גם#
inet_ntoa- reverse direction, packed bytes to dotted-quad string.inet_pton- same idea but parameterised by address family.pack_sockaddr_in- the immediate consumer of the packed address.getaddrinfo- richer resolver when you also need a port or IPv6.