@@ -276,6 +276,7 @@ namespace ix
276
276
}
277
277
278
278
// Accept a connection.
279
+ // FIXME: Is this working for ipv6 ?
279
280
struct sockaddr_in client; // client address information
280
281
int clientFd; // socket connected to client
281
282
socklen_t addressLen = sizeof (client);
@@ -307,9 +308,44 @@ namespace ix
307
308
continue ;
308
309
}
309
310
310
- // FIXME error handling
311
- char *remoteIp = inet_ntoa (client.sin_addr );
312
- auto connectionInfo = std::make_unique<ConnectionInfo>(remoteIp, client.sin_port );
311
+ std::unique_ptr<ConnectionInfo> connectionInfo;
312
+
313
+ if (_addressFamily == AF_INET)
314
+ {
315
+ char remoteIp[INET_ADDRSTRLEN];
316
+ if (inet_ntop (AF_INET, &client.sin_addr , remoteIp, INET_ADDRSTRLEN) == nullptr )
317
+ {
318
+ int err = Socket::getErrno ();
319
+ std::stringstream ss;
320
+ ss << " SocketServer::run() error calling inet_ntop (ipv4): " << err << " , "
321
+ << strerror (err);
322
+ logError (ss.str ());
323
+
324
+ Socket::closeSocket (clientFd);
325
+
326
+ continue ;
327
+ }
328
+
329
+ connectionInfo = std::make_unique<ConnectionInfo>(remoteIp, client.sin_port );
330
+ }
331
+ else // AF_INET6
332
+ {
333
+ char remoteIp[INET6_ADDRSTRLEN];
334
+ if (inet_ntop (AF_INET6, &client.sin_addr , remoteIp, INET6_ADDRSTRLEN) == nullptr )
335
+ {
336
+ int err = Socket::getErrno ();
337
+ std::stringstream ss;
338
+ ss << " SocketServer::run() error calling inet_ntop (ipv6): " << err << " , "
339
+ << strerror (err);
340
+ logError (ss.str ());
341
+
342
+ Socket::closeSocket (clientFd);
343
+
344
+ continue ;
345
+ }
346
+
347
+ connectionInfo = std::make_unique<ConnectionInfo>(remoteIp, client.sin_port );
348
+ }
313
349
314
350
std::shared_ptr<ConnectionState> connectionState;
315
351
if (_connectionStateFactory)
0 commit comments