-out:
- if (local)
- freeaddrinfo(local);
- if (remote)
- freeaddrinfo(remote);
- flowopt_cleanup(fo);
-
- if (src == NULL && dst == NULL) {
- if (rc >= 0)
- rc = -E_MAKESOCK;
- PARA_ERROR_LOG("can not create %s socket %s#%s.\n",
- layer4_name(l4type), host? host : (passive?
- "[loopback]" : "[localhost]"), port);
- return rc;
+ return -E_MAKESOCK;
+}
+
+/**
+ * Resolve IPv4/IPv6 address and create a ready-to-use active or passive socket.
+ *
+ * \param l4type The layer-4 type (\p IPPROTO_xxx).
+ * \param passive Whether this is a passive or active socket.
+ * \param host Passed to \ref lookup_address().
+ * \param port_number Passed to \ref lookup_address().
+ * \param fo Passed to \ref makesock_addrinfo().
+ *
+ * This creates a ready-made IPv4/v6 socket structure after looking up the
+ * necessary parameters. The function first calls \ref lookup_address() and
+ * passes the address information to makesock_addrinfo() to create and
+ * initialize the socket.
+ *
+ * \return The newly created file descriptor on success, a negative error code
+ * on failure.
+ *
+ * \sa \ref lookup_address(), \ref makesock_addrinfo().
+ */
+int makesock(unsigned l4type, bool passive, const char *host, uint16_t port_number,
+ struct flowopts *fo)
+{
+ struct addrinfo *ai;
+ int ret = lookup_address(l4type, passive, host, port_number, &ai);
+
+ if (ret >= 0)
+ ret = makesock_addrinfo(l4type, passive, ai, fo);
+ if (ai)
+ freeaddrinfo(ai);
+ if (ret < 0) {
+ PARA_ERROR_LOG("can not create %s socket %s#%d.\n",
+ layer4_name(l4type), host? host : (passive?
+ "[loopback]" : "[localhost]"), port_number);