c: Fix [u]int16 big endian handling
c: Workaround struct packing bug in GCC 4.7

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991
c: Fix local generator script execution
csharp: Avoid race condition during socket closing

First close all socket related objects then set them to null.
java: Reorder socket closing code

Inspired by a similar change in the C# bindings.