port from org.apache.logging.log4j.core.helpers.NetUtils, closes LOGBACK-749