-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fix issue #359: Bin to str conversion of IPv6 addresses #431
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6897,3 +6897,79 @@ x = f.i2repr(mp, {'*', '+', 'bit 2'}) | |
assert(re.match(r'^.*Star \(\*\).*$', x) is not None) | ||
assert(re.match(r'^.*Plus \(\+\).*$', x) is not None) | ||
assert(re.match(r'^.*bit 2.*$', x) is not None) | ||
|
||
########################################################################################################### | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tests sound good to me, but I think you should call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason for that is that I'm able to test my code and not the code of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I missed that. You're right. But maybe you could double the tests? Like that: compressed1, compressed2 = _ipv6_bin_to_str(address), inet_ntop(socket.AF_INET6, address)
assert compressed1 == compressed2 == '::' What do you think? |
||
+ Test correct conversion from binary to string of IPv6 addresses | ||
|
||
= IPv6 bin to string conversion - all zero bytes | ||
from scapy.pton_ntop import _ipv6_bin_to_str, inet_ntop | ||
import socket | ||
address=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' # All zero | ||
compressed1, compressed2 = _ipv6_bin_to_str(address), inet_ntop(socket.AF_INET6, address) | ||
assert(compressed1 == compressed2 == '::') | ||
|
||
= IPv6 bin to string conversion - non-compressable | ||
from scapy.pton_ntop import _ipv6_bin_to_str, inet_ntop | ||
import socket | ||
address=b'\x11\x11\x22\x22\x33\x33\x44\x44\x55\x55\x66\x66\x77\x77\x88\x88' # Not compressable | ||
compressed1, compressed2 = _ipv6_bin_to_str(address), inet_ntop(socket.AF_INET6, address) | ||
assert(compressed1 == compressed2 == '1111:2222:3333:4444:5555:6666:7777:8888') | ||
|
||
= IPv6 bin to string conversion - Zero-block right | ||
from scapy.pton_ntop import _ipv6_bin_to_str, inet_ntop | ||
import socket | ||
address=b'\x11\x11\x22\x22\x33\x33\x44\x44\x55\x55\x00\x00\x00\x00\x00\x00' # Zeroblock right | ||
compressed1, compressed2 = _ipv6_bin_to_str(address), inet_ntop(socket.AF_INET6, address) | ||
assert(compressed1 == compressed2 == '1111:2222:3333:4444:5555::') | ||
|
||
= IPv6 bin to string conversion - Zero-block left | ||
from scapy.pton_ntop import _ipv6_bin_to_str, inet_ntop | ||
import socket | ||
address=b'\x00\x00\x00\x00\x00\x00\x44\x44\x55\x55\x66\x66\x77\x77\x88\x88' # Zeroblock left | ||
compressed1, compressed2 = _ipv6_bin_to_str(address), inet_ntop(socket.AF_INET6, address) | ||
assert(compressed1 == compressed2 == '::4444:5555:6666:7777:8888') | ||
|
||
= IPv6 bin to string conversion - Two zero-block with different length | ||
from scapy.pton_ntop import _ipv6_bin_to_str, inet_ntop | ||
import socket | ||
address=b'\x00\x00\x00\x00\x33\x33\x44\x44\x00\x00\x00\x00\x00\x00\x88\x88' # Short and long zero block | ||
compressed1, compressed2 = _ipv6_bin_to_str(address), inet_ntop(socket.AF_INET6, address) | ||
assert(compressed1 == compressed2 == '0:0:3333:4444::8888') | ||
|
||
= IPv6 bin to string conversion - Address 1:: | ||
from scapy.pton_ntop import _ipv6_bin_to_str, inet_ntop | ||
import socket | ||
address=b'\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' # only 1 on the left | ||
compressed1, compressed2 = _ipv6_bin_to_str(address), inet_ntop(socket.AF_INET6, address) | ||
assert(compressed1 == compressed2 == '1::') | ||
|
||
= IPv6 bin to string conversion - Address ::1 | ||
from scapy.pton_ntop import _ipv6_bin_to_str, inet_ntop | ||
import socket | ||
address=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01' # loopback | ||
compressed1, compressed2 = _ipv6_bin_to_str(address), inet_ntop(socket.AF_INET6, address) | ||
assert(compressed1 == compressed2 == '::1') | ||
|
||
= IPv6 bin to string conversion - Zero-block of length 1 | ||
from scapy.pton_ntop import _ipv6_bin_to_str, inet_ntop | ||
import socket | ||
address=b'\x11\x11\x22\x22\x33\x33\x44\x44\x55\x55\x66\x66\x00\x00\x88\x88' # only one zero block | ||
compressed1, compressed2 = _ipv6_bin_to_str(address), inet_ntop(socket.AF_INET6, address) | ||
assert(compressed1 == '1111:2222:3333:4444:5555:6666:0:8888') | ||
# On Mac OS socket.inet_ntop is not fully compliant with RFC 5952 and shortens the single zero block to '::'. Still | ||
# this is a valid IPv6 address representation. | ||
assert(compressed2 in ('1111:2222:3333:4444:5555:6666:0:8888', '1111:2222:3333:4444:5555:6666::8888')) | ||
|
||
= IPv6 bin to string conversion - Two zero-blocks with equal length | ||
from scapy.pton_ntop import _ipv6_bin_to_str, inet_ntop | ||
import socket | ||
address=b'\x11\x11\x00\x00\x00\x00\x44\x44\x00\x00\x00\x00\x77\x77\x88\x88' # two zero blocks of equal length | ||
compressed1, compressed2 = _ipv6_bin_to_str(address), inet_ntop(socket.AF_INET6, address) | ||
assert(compressed1 == compressed2 == '1111::4444:0:0:7777:8888') | ||
|
||
= IPv6 bin to string conversion - Leading zero suppression | ||
from scapy.pton_ntop import _ipv6_bin_to_str, inet_ntop | ||
import socket | ||
address=b'\x10\x00\x02\x00\x00\x30\x00\x04\x00\x05\x00\x60\x07\x00\x80\x00' # Leading zero suppression | ||
compressed1, compressed2 = _ipv6_bin_to_str(address), inet_ntop(socket.AF_INET6, address) | ||
assert(compressed1 == compressed2 == '1000:200:30:4:5:60:700:8000') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch and good comment! 👍