PARA_ERROR(SENDMSG, "sendmsg() failed"), \
PARA_ERROR(RECVMSG, "recvmsg() failed"), \
PARA_ERROR(SCM_CREDENTIALS, "did not receive SCM credentials"), \
+ PARA_ERROR(MAKESOCK, "makesock error"), \
#define UDP_RECV_ERRORS \
const char *host, uint16_t port_number,
struct flowopts *fo)
{
- struct addrinfo *local = NULL, *src,
- *remote = NULL, *dst, hints;
+ struct addrinfo *local = NULL, *src = NULL, *remote = NULL,
+ *dst = NULL, hints;
unsigned int l3type = AF_UNSPEC;
int rc, on = 1, sockfd = -1,
socktype = sock_type(l4type);
layer4_name(l4type),
host? host : (passive? "[loopback]" : "[localhost]"),
port, gai_strerror(rc));
- return -E_ADDRESS_LOOKUP;
+ rc = -E_ADDRESS_LOOKUP;
+ goto out;
}
/* Iterate over all src/dst combination, exhausting dst first */
close(sockfd);
PARA_ERROR_LOG("can not set SO_REUSEADDR: %s\n",
strerror(rc));
- return -ERRNO_TO_PARA_ERROR(rc);
+ rc = -ERRNO_TO_PARA_ERROR(rc);
+ break;
}
flowopt_setopts(sockfd, fo);
if (src && (src = src->ai_next)) /* restart inner loop */
dst = remote;
}
+out:
if (local)
freeaddrinfo(local);
if (remote)
flowopt_cleanup(fo);
if (src == NULL && dst == NULL) {
- rc = errno;
+ 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 -ERRNO_TO_PARA_ERROR(rc);
+ return rc;
}
return sockfd;
}