+ if (host_name && host_name[0] && lookup_ip(host_name, &sinp->sin_addr)) {
+ 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', binds to
+ * 'target', and listens for incoming connections. Parses 'target' in the same
+ * way was inet_parse_passive().
+ *
+ * 'style' should be SOCK_STREAM (for TCP) or SOCK_DGRAM (for UDP).
+ *
+ * For TCP, the socket will have SO_REUSEADDR turned on.
+ *
+ * On success, returns a non-negative file descriptor. On failure, returns a
+ * negative errno value.
+ *
+ * If 'sinp' is non-null, then on success the bound address is stored into
+ * '*sinp'. */
+int
+inet_open_passive(int style, const char *target, int default_port,
+ struct sockaddr_in *sinp)
+{
+ struct sockaddr_in sin;
+ int fd = 0, error;
+ unsigned int yes = 1;
+
+ if (!inet_parse_passive(target, default_port, &sin)) {
+ return EAFNOSUPPORT;