1
我试图将socket.inet_pton返回的16字节Blob数据转换为无符号字节的ctypes数组。我的数据结构是这样的:强制转换为Python ctypes数组
class in6_addr(ctypes.Structure): _fields_ = (("Byte", ctypes.c_ubyte * 16),)
而且斑点就是:
data = socket.inet_pton(socket.AF_INET6, "2001::3")
然而,这些尝试得到错误:
sin6 = in6_addr() # TypeError: expected c_ubyte_Array_16 instance, got str sin6.Byte = data # TypeError: cast() argument 2 must be a pointer type, not c_ubyte_Array_16 sin6.Byte = ctypes.cast(data, ctypes.c_ubyte * 16) # TypeError: incompatible types, LP_c_ubyte instance instead of c_ubyte_Array_16 instance sin6.Byte = ctypes.cast(data, ctypes.POINTER(ctypes.c_ubyte))
所有代码:http://codepad.org/2cjyVXBA
任何想法我需要投入什么类型?