title: Python: Extracting data from buffer with ctypes
body: <p>I am able to successfully call a function with ctypes in Python.  I now have a buffer that is filled with Structures of data I want to extract.  What is the best strategy for this?  Anything else I should post?</p>
  
  <p>Function:</p>
  
  <pre><code>class list():
      def __init__(self):
          #[...]
  
      def getdirentries(self, path):
          self.load_c()
          self.fd = os.open(path, os.O_RDONLY)
          self.statinfo = os.fstat(self.fd)
          self.buffer = ctypes.create_string_buffer(self.statinfo.st_size)
          nbytes = self.statinfo.st_size
  
          transferred_bytes = self.libc.getdirentries(
                          self.fd,
                          ctypes.byref(self.buffer),
                          nbytes,
                          ctypes.byref(self.basep)  )
  
      #[...]
  </code></pre>
  
  <p>Structure:</p>
  
  <pre><code>class dirent(ctypes.Structure):
      _fields_ = [ ("d_fileno", ctypes.c_uint32), # /* file number of entry */
                   ("d_reclen", ctypes.c_uint16), # /* length of this record */
                   ("d_type", ctypes.c_uint8), # /* file type */
                   ("d_namlen", ctypes.c_uint8), # /* length of string in d_name */
                   ("d_name", ctypes.c_char * (MAXNAMELEN + 1) ) ]
  </code></pre>
  
  <p>Some Output:<br>
  Transferred bytes: 156<br>
  sizeof buffer: 272<br>
  Buffer: <code>&lt;ctypes.c_char_Array_272 object at 0x8c3f0&gt;</code>  </p>