+ goto exit;
+ }
+
+ ok = true;
+
+exit:
+ if (!ok) {
+ memset(sinp, 0, sizeof *sinp);
+ }
+ free(target);
+ return ok;
+}
+
+/* Opens a non-blocking IPv4 socket of the specified 'style' and connects to
+ * 'target', which should be a string in the format "<host>[:<port>]". <host>
+ * is required. If 'default_port' is nonzero then <port> is optional and
+ * defaults to 'default_port'.
+ *
+ * 'style' should be SOCK_STREAM (for TCP) or SOCK_DGRAM (for UDP).
+ *
+ * On success, returns 0 (indicating connection complete) or EAGAIN (indicating
+ * connection in progress), in which case the new file descriptor is stored
+ * into '*fdp'. On failure, returns a positive errno value other than EAGAIN
+ * and stores -1 into '*fdp'.
+ *
+ * If 'sinp' is non-null, then on success the target address is stored into
+ * '*sinp'. */
+int
+inet_open_active(int style, const char *target, uint16_t default_port,
+ struct sockaddr_in *sinp, int *fdp)
+{
+ struct sockaddr_in sin;
+ int fd = -1;
+ int error;
+
+ /* Parse. */
+ if (!inet_parse_active(target, default_port, &sin)) {