Replace usage of inet_ntoa() with getnameinfo()

It's threadsafe and protocol independant.

Also removed a couple of possible silent-truncation bugs.
platform.h: put all system includes on top

Also fix some confusing indentation. And removed "#define __USE_GNU". This is
internal to glibc and should never be used, _GNU_SOURCE should be enough if
properly defined before all includes.
Include assert.h centrally in platform.h.
Added some debug messages and silenced a couple of warnings.
Simplified some braindead logic, added comments.