- length = sizeof (client);
- incoming = accept (this->fd, (sockaddr*)&client,&length);
+ {
+ /* The [2] is required because we may write a sockaddr_in6 here, and sockaddr_in6 is larger than sockaddr, where sockaddr_in4 is not. */
+ sockaddr* client = new sockaddr[2];
+ length = sizeof (sockaddr_in);
+ std::string recvip;
+#ifdef IPV6
+ if ((!*this->host) || strchr(this->host, ':'))
+ length = sizeof(sockaddr_in6);
+#endif
+ incoming = Instance->SE->Accept(this, client, &length);
+#ifdef IPV6
+ if ((!*this->host) || strchr(this->host, ':'))
+ {
+ char buf[1024];
+ recvip = inet_ntop(AF_INET6, &((sockaddr_in6*)client)->sin6_addr, buf, sizeof(buf));
+ }
+ else
+#endif
+ {
+ // FIX: we were doing this for IPv6 connections as well, which was fucking recvip..
+ // Add brackets to make this a bit clearer. -- w00t (Jan 15, 2008)
+ recvip = inet_ntoa(((sockaddr_in*)client)->sin_addr);
+ }
+
+ Instance->SE->NonBlocking(incoming);
+
+ this->OnIncomingConnection(incoming, (char*)recvip.c_str());