It's taking me a while to read through this, but one initial thing... The BSD definitions use uint32_t, not "unsigned int" for the prototypes.