Fixes after @adamsutton suggested using the safer
getsockname method of determining IP used for the server
Appears to work fine after other code removed