Add unit test for socket-validity code

To allow for testing of Win32 platform on Unix, I've created
semi-hidden platform specific versions of each function.

The visible functions use #ifdefs to select the proper implementation
depending on the platform on which they are compiled.