I believe the POSIX way to do this is to call connect(), ignore the return value, then select() it for except and write. If write, it opened successfully, if except, there's an error (use getsockopt()).