New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unsupported address family #56
Comments
hanazuki
added a commit
to hanazuki/ipaddr
that referenced
this issue
Nov 27, 2023
`IPAddr.ntop` takes a binary representation of IP address, whose length should be 4 or 16 *bytes* (not characters/codepoints). This patch fixes the bug that `IPAddr.ntop` doesn't handle Strings in a multibyte encoding correctly. Fixes: ruby#56
hanazuki
added a commit
to hanazuki/ipaddr
that referenced
this issue
Nov 27, 2023
`IPAddr.ntop` takes the binary representation of an IP address, whose length should be 4 or 16 *bytes* (not characters/codepoints). This patch fixes the bug that `IPAddr.ntop` doesn't handle Strings in a multibyte encoding correctly. Fixes: ruby#56
Actually, it is not appropriate to pass a non-binary string. A string literal written in source code is encoded in the default encoding, which is usually UTF-8. require "ipaddr"
x = IPAddr.new("172.20.222.160")
p x.hton #=> "\xAC\x14\xDE\xA0"
p x.hton.encoding #=> #<Encoding:ASCII-8BIT>
# It properly round-trips.
p IPAdd.ntoh(x.hton) #=> "172.20.222.160"
p "\xAC\x14\xDE\xA0".encoding #=> #<Encoding::UTF-8>
# ntop does not take a non-binary string
p IPAddr.ntop("\xAC\x14\xDE\xA0") rescue $! #=> #<IPAddr::AddressFamilyError: unsupported address family>
# The correct way
p IPAddr.ntop("\xAC\x14\xDE\xA0".b) #=> "172.20.222.160" |
Thanks for the explanation! |
hanazuki
added a commit
to hanazuki/ipaddr
that referenced
this issue
Nov 28, 2023
`IPAddr.ntop` takes the binary representation of an IP address, whose length should be 4 or 16 *bytes* (not characters/codepoints). The current implementation accepts strings in any encoding, but for some values in non-BINARY encoding, it fails proper length check and raises an `AddressFamilyError`. Since passing strings in a multibyte encoding has never worked correctly for years, this patch makes it an explicit error with an `InvalidAddressError`. Fixes: ruby#56
hanazuki
added a commit
to hanazuki/ipaddr
that referenced
this issue
Nov 28, 2023
`IPAddr.ntop` takes the binary representation of an IP address, whose length should be 4 or 16 *bytes* (not characters/codepoints). The current implementation accepts strings in any encoding, but for some values in non-BINARY encoding, it fails proper length check and raises an `AddressFamilyError`. Since passing strings in a multibyte encoding has never worked correctly for years, this patch makes it an explicit error with an `InvalidAddressError`. Fixes: ruby#56
hanazuki
added a commit
to hanazuki/ipaddr
that referenced
this issue
Nov 28, 2023
`IPAddr.ntop` takes the binary representation of an IP address, whose length should be 4 or 16 *bytes* (not characters/codepoints). The current implementation accepts strings in any encoding, but for some values in non-BINARY encoding, it fails proper length check and raises an `AddressFamilyError`. Since passing strings in a multibyte encoding has never worked correctly for years, this patch makes it an explicit error with an `InvalidAddressError`. Fixes: ruby#56
hanazuki
added a commit
to hanazuki/ipaddr
that referenced
this issue
Nov 28, 2023
`IPAddr.ntop` takes the binary representation of an IP address, whose length should be 4 or 16 *bytes* (not characters/codepoints). The current implementation accepts strings in any encoding, but for some values in non-BINARY encoding, it fails proper length check and raises an `AddressFamilyError`. Since passing strings in a multibyte encoding has never worked correctly for years, this patch makes it an explicit error with an `InvalidAddressError`. Fixes: ruby#56
hsbt
pushed a commit
to hsbt/ruby
that referenced
this issue
Dec 25, 2023
`IPAddr.ntop` takes the binary representation of an IP address, whose length should be 4 or 16 *bytes* (not characters/codepoints). The current implementation accepts strings in any encoding, but for some values in non-BINARY encoding, it fails proper length check and raises an `AddressFamilyError`. Since passing strings in a multibyte encoding has never worked correctly for years, this patch makes it an explicit error with an `InvalidAddressError`. Fixes: ruby/ipaddr#56 ruby/ipaddr@a33fd14d4a
hsbt
pushed a commit
to hsbt/ruby
that referenced
this issue
Dec 25, 2023
`IPAddr.ntop` takes the binary representation of an IP address, whose length should be 4 or 16 *bytes* (not characters/codepoints). The current implementation accepts strings in any encoding, but for some values in non-BINARY encoding, it fails proper length check and raises an `AddressFamilyError`. Since passing strings in a multibyte encoding has never worked correctly for years, this patch makes it an explicit error with an `InvalidAddressError`. Fixes: ruby/ipaddr#56 ruby/ipaddr@a33fd14d4a
hsbt
pushed a commit
to hsbt/ruby
that referenced
this issue
Dec 25, 2023
`IPAddr.ntop` takes the binary representation of an IP address, whose length should be 4 or 16 *bytes* (not characters/codepoints). The current implementation accepts strings in any encoding, but for some values in non-BINARY encoding, it fails proper length check and raises an `AddressFamilyError`. Since passing strings in a multibyte encoding has never worked correctly for years, this patch makes it an explicit error with an `InvalidAddressError`. Fixes: ruby/ipaddr#56 ruby/ipaddr@a33fd14d4a
hsbt
pushed a commit
to hsbt/ruby
that referenced
this issue
Dec 25, 2023
`IPAddr.ntop` takes the binary representation of an IP address, whose length should be 4 or 16 *bytes* (not characters/codepoints). The current implementation accepts strings in any encoding, but for some values in non-BINARY encoding, it fails proper length check and raises an `AddressFamilyError`. Since passing strings in a multibyte encoding has never worked correctly for years, this patch makes it an explicit error with an `InvalidAddressError`. Fixes: ruby/ipaddr#56 ruby/ipaddr@a33fd14d4a
hsbt
pushed a commit
to ruby/ruby
that referenced
this issue
Dec 25, 2023
`IPAddr.ntop` takes the binary representation of an IP address, whose length should be 4 or 16 *bytes* (not characters/codepoints). The current implementation accepts strings in any encoding, but for some values in non-BINARY encoding, it fails proper length check and raises an `AddressFamilyError`. Since passing strings in a multibyte encoding has never worked correctly for years, this patch makes it an explicit error with an `InvalidAddressError`. Fixes: ruby/ipaddr#56 ruby/ipaddr@a33fd14d4a
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I do not understand the following behavior:
If I try to pass the binary string as a string, an error is returned, but if I do not pass the string as a variable, it works.
This error also occurred when I tried to read an IP address from an MRT file. I then had the string displayed and tried it manually (see above). But I also got the same error.
The text was updated successfully, but these errors were encountered: