Skip to content

Commit

Permalink
uwp build fix + more ivp6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
bsergean committed Jul 8, 2020
1 parent fbd1768 commit b213063
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions ixwebsocket/IXSocketServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ namespace ix
}

// Accept a connection.
// FIXME: Is this working for ipv6 ?
struct sockaddr_in client; // client address information
int clientFd; // socket connected to client
socklen_t addressLen = sizeof(client);
Expand Down Expand Up @@ -307,9 +308,44 @@ namespace ix
continue;
}

// FIXME error handling
char *remoteIp = inet_ntoa(client.sin_addr);
auto connectionInfo = std::make_unique<ConnectionInfo>(remoteIp, client.sin_port);
std::unique_ptr<ConnectionInfo> connectionInfo;

if (_addressFamily == AF_INET)
{
char remoteIp[INET_ADDRSTRLEN];
if (inet_ntop(AF_INET, &client.sin_addr, remoteIp, INET_ADDRSTRLEN) == nullptr)
{
int err = Socket::getErrno();
std::stringstream ss;
ss << "SocketServer::run() error calling inet_ntop (ipv4): " << err << ", "
<< strerror(err);
logError(ss.str());

Socket::closeSocket(clientFd);

continue;
}

connectionInfo = std::make_unique<ConnectionInfo>(remoteIp, client.sin_port);
}
else // AF_INET6
{
char remoteIp[INET6_ADDRSTRLEN];
if (inet_ntop(AF_INET6, &client.sin_addr, remoteIp, INET6_ADDRSTRLEN) == nullptr)
{
int err = Socket::getErrno();
std::stringstream ss;
ss << "SocketServer::run() error calling inet_ntop (ipv6): " << err << ", "
<< strerror(err);
logError(ss.str());

Socket::closeSocket(clientFd);

continue;
}

connectionInfo = std::make_unique<ConnectionInfo>(remoteIp, client.sin_port);
}

std::shared_ptr<ConnectionState> connectionState;
if (_connectionStateFactory)
Expand Down

0 comments on commit b213063

Please sign in to comment.