- sockaddr_in* sin = new sockaddr_in;
- sin->sin_family = AF_INET;
- sin->sin_port = port;
- inet_pton(AF_INET, sip, &sin->sin_addr);
- this->ip = (sockaddr*)sin;
- }
- break;
- default:
- ServerInstance->Logs->Log("USERS",DEBUG,"Uh oh, I dont know protocol %d to be set on '%s'!", protocol_family, this->nick.c_str());
- break;
- }
-}
-
-int User::GetPort()
-{
- if (this->ip == NULL)
- return 0;
-
- switch (this->GetProtocolFamily())
- {
-#ifdef SUPPORT_IP6LINKS
- case AF_INET6:
- {
- sockaddr_in6* sin = (sockaddr_in6*)this->ip;
- return sin->sin6_port;
- }
- break;
-#endif
- case AF_INET:
- {
- sockaddr_in* sin = (sockaddr_in*)this->ip;
- return sin->sin_port;
- }
- break;
- default:
- break;
- }
- return 0;
-}
-
-int User::GetProtocolFamily()
-{
- if (this->ip == NULL)
- return 0;
-
- sockaddr_in* sin = (sockaddr_in*)this->ip;
- return sin->sin_family;
-}
-
-const char* User::GetCIDRMask(int range)
-{
- static char buf[44];
-
- if (this->ip == NULL)
- return "";
-
- if (range < 0)
- throw "Negative range, sorry, no.";
-
- /*
- * Original code written by Oliver Lupton (Om).
- * Integrated by me. Thanks. :) -- w00t
- */
- switch (this->GetProtocolFamily())
- {
-#ifdef SUPPORT_IP6LINKS
- case AF_INET6:
- {
- /* unsigned char s6_addr[16]; */
- struct in6_addr v6;
- sockaddr_in6* sin;
- int i, bytestozero, extrabits;
- char buffer[40];
-
- if(range > 128)
- throw "CIDR mask width greater than address width (IPv6, 128 bit)";
-
- /* Access the user's IP structure directly */
- sin = (sockaddr_in6*)this->ip;
-
- /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
- * to zero. This means the last (128 - range) bits of the address must be set to zero.
- * Hence this number divided by 8 is the number of whole bytes from the end of the address
- * which must be set to zero.
- */
- bytestozero = (128 - range) / 8;
-
- /* Some of the least significant bits of the next most significant byte may also have to
- * be zeroed. The number of bits is the remainder of the above division.
- */
- extrabits = (128 - range) % 8;
-
- /* Populate our working struct with the parts of the user's IP which are required in the
- * final CIDR mask. Set all the subsequent bytes to zero.
- * (16 - bytestozero) is the number of bytes which must be populated with actual IP data.
- */
- for(i = 0; i < (16 - bytestozero); i++)