From ef5dfd8479017ea8ca27e0a086d26b3c861b49e8 Mon Sep 17 00:00:00 2001 From: david Date: Sat, 29 Oct 2011 19:40:19 +0000 Subject: [PATCH] Compress strings of zeros in packet.toipv6. I do this just by passing the uncompressed names through nmap.resolve. Before: fe80:0000:0000:0000:0000:0000:0000:0001, 2001:0470:1f05:155e:0000:0000:0000:0003 After: fe80::1, 2001:470:1f05:155e::3 --- nselib/packet.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nselib/packet.lua b/nselib/packet.lua index 6c6d559b4..f5e998b5f 100644 --- a/nselib/packet.lua +++ b/nselib/packet.lua @@ -492,11 +492,16 @@ end -- @param raw_ipv6_addr 16-byte string. -- @return IPv6 address string. function toipv6(raw_ipv6_addr) + local long_addr_str + local status, addrs + if not raw_ipv6_addr then return nil, "IPv6 address was not specified." end - return string.format("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", - string.byte(raw_ipv6_addr,1,16)) + long_addr_str = stdnse.tohex(raw_ipv6_addr, {separator=":", group=4}) + status, addrs = nmap.resolve(long_addr_str, "inet6") + + return (status and addrs[1]) or long_addr_str end --- Generate the link-local IPv6 address from the MAC address. -- @param mac MAC address string.