Skip to content

Commit

Permalink
Networking (Windows): fix calling IPv6 server
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Sep 18, 2024
1 parent 6c8b4b2 commit 5a9a2ca
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/common/networking_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,21 @@ const char* ffNetworkingSendHttpRequest(FFNetworkingState* state, const char* ho
return "socket() failed";
}

{
//ConnectEx requires the socket to be initially bound
if(bind(state->sockfd, (SOCKADDR *) &(struct sockaddr_in) {
//ConnectEx requires the socket to be initially bound
if((state->ipv6
? bind(state->sockfd, (SOCKADDR *) &(struct sockaddr_in6) {
.sin6_family = AF_INET6,
.sin6_addr = in6addr_any,
}, sizeof(struct sockaddr_in6))
: bind(state->sockfd, (SOCKADDR *) &(struct sockaddr_in) {
.sin_family = AF_INET,
.sin_addr.s_addr = INADDR_ANY,
.sin_port = 0,
}, sizeof(struct sockaddr_in)) != 0)
{
closesocket(state->sockfd);
freeaddrinfo(addr);
state->sockfd = INVALID_SOCKET;
return "bind() failed";
}
}, sizeof(struct sockaddr_in))) != 0)
{
closesocket(state->sockfd);
freeaddrinfo(addr);
state->sockfd = INVALID_SOCKET;
return "bind() failed";
}

FF_STRBUF_AUTO_DESTROY command = ffStrbufCreateA(64);
Expand All @@ -93,7 +95,6 @@ const char* ffNetworkingSendHttpRequest(FFNetworkingState* state, const char* ho
if(!result && WSAGetLastError() != WSA_IO_PENDING)
{
closesocket(state->sockfd);
freeaddrinfo(addr);
state->sockfd = INVALID_SOCKET;
return "ConnectEx() failed";
}
Expand Down

0 comments on commit 5a9a2ca

Please sign in to comment.