-/**
- * Establish a tcp connection.
- *
- * \param host Hostname or IPv4 address.
- * \param port The tcp port.
- *
- * \return Negative on errors, a valid file descriptor on success.
- */
-int tcp_connect(char *host, int port)
-{
- struct sockaddr_in addr;
- struct hostent *he;
- int ret, fd;
-
- PARA_INFO_LOG("getting host info of %s\n", host);
- /* FIXME: gethostbyname() is obsolete */
- he = gethostbyname(host);
- if (!he)
- return -ERRNO_TO_PARA_ERROR(h_errno);
- init_sockaddr(&addr, port, he);
- ret = get_stream_socket(AF_INET);
- if (ret < 0)
- return ret;
- fd = ret;
- ret = PARA_CONNECT(fd, &addr);
- if (ret >= 0)
- return fd;
- close(fd);
- return ret;
-}
-
-/**
- * A wrapper around socket(2).
- *
- * \param domain The communication domain that selects the protocol family.
- *
- * Create an IPv4 socket for sequenced, reliable, two-way, connection-based
- * byte streams.
- *
- * \return The socket fd on success, negative on errors.
- *
- * \sa socket(2).
- */
-int get_stream_socket(int domain)
-{
- int fd = socket(domain, SOCK_STREAM, 0);
-
- if (fd < 0)
- return -ERRNO_TO_PARA_ERROR(errno);
- return fd;
-}
-