Fix compilation warnings and make the unit test pass.

(the compilation warnings were mainly about double-defined functions
due to a misplaced #endif.  The unit test failure was because you
reallocated ifr but didn't re-set sockaddr.)