Reformatted to code style
Improved loopback detection. fixes issues 1181.

Patch by Kowalczyk Jerome, applied unmodified