- /* If citserver is bound to a specific IP address on the host, make
- * sure we use that address for outbound connections.
- */
- memset(&egress_sin, 0, sizeof(egress_sin));
- egress_sin.sin_family = AF_INET;
- if (!IsEmptyStr(config.c_ip_addr)) {
- egress_sin.sin_addr.s_addr = inet_addr(config.c_ip_addr);
- if (egress_sin.sin_addr.s_addr == !INADDR_ANY) {
- egress_sin.sin_addr.s_addr = INADDR_ANY;
- }
-
- /* If this bind fails, no problem; we can still use INADDR_ANY */
- bind(s, (struct sockaddr *)&egress_sin, sizeof(egress_sin));
- }
-
- /* Now try to connect to the remote host. */
- if (connect(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
- CtdlLogPrintf(CTDL_ERR, "Can't connect to %s:%s: %s\n",
- host, service, strerror(errno));
- close(s);
+ rc = connect(sock, res->ai_addr, res->ai_addrlen);
+ if (rc < 0) {
+ /*
+ * Note: the res is a linked list of addresses found for server.
+ * If the connect() fails to the first one, subsequent addresses
+ * (if any) in the list could be tried if desired.
+ */
+ CtdlLogPrintf(CTDL_ERR, "connect() failed: %s\n", strerror(errno));