title: casting to Arrays in Python ctypes
body: <p>I'm trying to convert a 16 byte blob of data returned by socket.inet_pton into a ctypes array of unsigned bytes. My data structure looks like this:</p>
  
  <pre>
  class in6_addr(ctypes.Structure):
      _fields_ = (("Byte", ctypes.c_ubyte * 16),)
  </pre>
  
  <p>And the blob is just:</p>
  
  <pre>
  data = socket.inet_pton(socket.AF_INET6, "2001::3")
  </pre>
  
  <p>However, these attempts get errors:</p>
  
  <pre>
  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))
  </pre>
  
  <p>All of the code: <a href="http://codepad.org/2cjyVXBA" rel="nofollow noreferrer">http://codepad.org/2cjyVXBA</a></p>
  
  <p>Any ideas what type I need to cast to?</p>