| 24 | |
| 25 | |
| 26 | class CNetBan |
| 27 | { |
| 28 | protected: |
| 29 | bool NetMatch(const NETADDR *pAddr1, const NETADDR *pAddr2) const |
| 30 | { |
| 31 | return NetComp(pAddr1, pAddr2) == 0; |
| 32 | } |
| 33 | |
| 34 | bool NetMatch(const CNetRange *pRange, const NETADDR *pAddr, int Start, int Length) const |
| 35 | { |
| 36 | return pRange->m_LB.type == pAddr->type && (Start == 0 || mem_comp(&pRange->m_LB.ip[0], &pAddr->ip[0], Start) == 0) && |
| 37 | mem_comp(&pRange->m_LB.ip[Start], &pAddr->ip[Start], Length-Start) <= 0 && mem_comp(&pRange->m_UB.ip[Start], &pAddr->ip[Start], Length-Start) >= 0; |
| 38 | } |
| 39 | |
| 40 | bool NetMatch(const CNetRange *pRange, const NETADDR *pAddr) const |
| 41 | { |
| 42 | return NetMatch(pRange, pAddr, 0, pRange->m_LB.type==NETTYPE_IPV4 ? 4 : 16); |
| 43 | } |
| 44 | |
| 45 | const char *NetToString(const NETADDR *pData, char *pBuffer, unsigned BufferSize) const |
| 46 | { |
| 47 | char aAddrStr[NETADDR_MAXSTRSIZE]; |
| 48 | net_addr_str(pData, aAddrStr, sizeof(aAddrStr), false); |
| 49 | str_format(pBuffer, BufferSize, "'%s'", aAddrStr); |
| 50 | return pBuffer; |
| 51 | } |
| 52 | |
| 53 | const char *NetToString(const CNetRange *pData, char *pBuffer, unsigned BufferSize) const |
| 54 | { |
| 55 | char aAddrStr1[NETADDR_MAXSTRSIZE], aAddrStr2[NETADDR_MAXSTRSIZE]; |
| 56 | net_addr_str(&pData->m_LB, aAddrStr1, sizeof(aAddrStr1), false); |
| 57 | net_addr_str(&pData->m_UB, aAddrStr2, sizeof(aAddrStr2), false); |
| 58 | str_format(pBuffer, BufferSize, "'%s' - '%s'", aAddrStr1, aAddrStr2); |
| 59 | return pBuffer; |
| 60 | } |
| 61 | |
| 62 | // todo: move? |
| 63 | static bool StrAllnum(const char *pStr); |
| 64 | |
| 65 | class CNetHash |
| 66 | { |
| 67 | public: |
| 68 | int m_Hash; |
| 69 | int m_HashIndex; // matching parts for ranges, 0 for addr |
| 70 | |
| 71 | CNetHash() {} |
| 72 | CNetHash(const NETADDR *pAddr); |
| 73 | CNetHash(const CNetRange *pRange); |
| 74 | |
| 75 | static int MakeHashArray(const NETADDR *pAddr, CNetHash aHash[17]); |
| 76 | }; |
| 77 | |
| 78 | struct CBanInfo |
| 79 | { |
| 80 | enum |
| 81 | { |
| 82 | EXPIRES_NEVER=-1, |
| 83 | REASON_LENGTH=64, |
nothing calls this directly
no outgoing calls
no test coverage detected