samba-tool dns: use bytes for inet_ntop
[metze/samba/wip.git] / python / samba / netcmd / dns.py
index b7459a71acd9d5b340f167059b23c7420e1ad7f1..d9fda0b93cdc1cf58eb02f748a0f4170e52cb870 100644 (file)
@@ -26,6 +26,7 @@ from socket import inet_ntop
 from socket import AF_INET
 from socket import AF_INET6
 import shlex
+import struct
 
 from samba import remove_dc
 from samba.samdb import SamDB
@@ -153,10 +154,10 @@ def dns_addr_array_string(array):
         return ret
     for i in range(array.AddrCount):
         if array.AddrArray[i].MaxSa[0] == 0x02:
-            x = "".join([chr(b) for b in array.AddrArray[i].MaxSa])[4:8]
+            x = struct.pack('4B', *array.AddrArray[i].MaxSa[4:8])
             addr = inet_ntop(AF_INET, x)
         elif array.AddrArray[i].MaxSa[0] == 0x17:
-            x = "".join([chr(b) for b in array.AddrArray[i].MaxSa])[8:24]
+            x = struct.pack('16B', *array.AddrArray[i].MaxSa[8:24])
             addr = inet_ntop(AF_INET6, x)
         else:
             addr = 'UNKNOWN'