sockets - casting to Arrays in Python ctypes -


I'm trying to convert a Sitiaipi array of unsigned bytes to 16 bytes of BLOB data by socket.inet_pton I am here. My data structure looks as follows:

 class in6_addr (ctypes.structure): _fields_ = (( "byte", Sitiaipisi_ubet * 16),) 

and BLOB simply:

 data = socket.inet_pton (socket.AF_INET6, "2001 :: 3") 

However, these efforts are getting errors:

 sin6 = in6_addr () # TypeError: expected c_ubyte_Array_16 example, found str sin6.Byte = data # TypeError: cast () argument must be a pointer type 2, c_ubyte_Array_16 sin6.Byte = ctypes.cast (data, ctypes.c_ubyte * 16) # TypeError: inconsistent Type, c_ubyte_Array_16 example sin6.Byte = ctypes.cast (Data, ctypes.POINTER (ctypes.c_ubyte) instead of LP_c_ubyte All codes: 

Any idea what I can be completely wrong here (and it looks a little bit complicated?)) But it works for me:

  sin6.byte = (ctypes.c_ubyte * 16) (* list (bytearray (data)))  

had to convert data I I Puarnankion Do not have a list and open them for the constructor. Should be an easy way!


Comments