Fix the herp

Fixed bugs in format_packet() and decode_packet()
Added reentrancy
Added comprehensive test (test_runner.c and packet_test.c)