mirror of
https://github.com/janet-lang/janet
synced 2024-11-18 06:34:48 +00:00
Don't bind when address info doesn't exist
Simple logic issue, something overlooked.
This commit is contained in:
parent
1ce2361daf
commit
2a4bcc262f
@ -429,23 +429,25 @@ JANET_CORE_FN(cfun_net_connect,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check all addrinfos in a loop for the first that we can bind to. */
|
if (ai != NULL) {
|
||||||
struct addrinfo *rp = NULL;
|
/* Check all addrinfos in a loop for the first that we can bind to. */
|
||||||
for (rp = ai; rp != NULL; rp = rp->ai_next) {
|
struct addrinfo *rp = NULL;
|
||||||
|
for (rp = ai; rp != NULL; rp = rp->ai_next) {
|
||||||
#ifdef JANET_WINDOWS
|
#ifdef JANET_WINDOWS
|
||||||
sock = WSASocketW(rp->ai_family, rp->ai_socktype | JSOCKFLAGS, rp->ai_protocol, NULL, 0, WSA_FLAG_OVERLAPPED);
|
sock = WSASocketW(rp->ai_family, rp->ai_socktype | JSOCKFLAGS, rp->ai_protocol, NULL, 0, WSA_FLAG_OVERLAPPED);
|
||||||
#else
|
#else
|
||||||
sock = socket(rp->ai_family, rp->ai_socktype | JSOCKFLAGS, rp->ai_protocol);
|
sock = socket(rp->ai_family, rp->ai_socktype | JSOCKFLAGS, rp->ai_protocol);
|
||||||
#endif
|
#endif
|
||||||
if (!JSOCKVALID(sock)) continue;
|
if (!JSOCKVALID(sock)) continue;
|
||||||
|
|
||||||
/* Bind */
|
/* Bind */
|
||||||
if (bind(sock, rp->ai_addr, (int) rp->ai_addrlen) == 0) break;
|
if (bind(sock, rp->ai_addr, (int) rp->ai_addrlen) == 0) break;
|
||||||
JSOCKCLOSE(sock);
|
JSOCKCLOSE(sock);
|
||||||
}
|
}
|
||||||
freeaddrinfo(ai);
|
freeaddrinfo(ai);
|
||||||
if (NULL == rp) {
|
if (NULL == rp) {
|
||||||
janet_panic("could not bind outgoing address");
|
janet_panic("could not bind outgoing address");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Connect to socket */
|
/* Connect to socket */
|
||||||
|
Loading…
Reference in New Issue
Block a user