#include using namespace std; #include class CLASSFUL { public: int mask; int leading; int netmask; CLASSFUL(){ } CLASSFUL(int mask, int leading, int netmask) { this->mask = mask; this->leading = leading; this->netmask = netmask; } }; class IPINFO { public: int a,b,c,d; int ip; int netid; IPINFO(){ } IPINFO(int a, int b, int c, int d) { this->a = a; this->b = b; this->c = c; this->d = d; pack(); } void pack() { this->ip = a*0x1000000 + b*0x10000 + c*0x100 + d; } }; class jClassful { CLASSFUL **classiIp; IPINFO **Ip; #define N 3 #define M 4 public: jClassful() { classiIp = new CLASSFUL*[N]; classiIp[0] = new CLASSFUL(0x80, 0x00, 0xFF000000); classiIp[1] = new CLASSFUL(0xC0, 0x80, 0xFFFF0000); classiIp[2] = new CLASSFUL(0xE0, 0xC0, 0xFFFFFF00); Ip = new IPINFO*[M]; Ip[0] = new IPINFO(10, 1, 0, 3); Ip[1] = new IPINFO(192, 168, 0, 3); Ip[2] = new IPINFO(137, 168, 0, 1); Ip[3] = new IPINFO(137, 168, 249, 17); } void calcola() { for(int i = 0;i < M;i++) { for(int j = 0; j < N;j++) { if ((Ip[i]->a & classiIp[j]->mask) == classiIp[j]->leading) { Ip[i]->netid = (Ip[i]->ip & classiIp[j]->netmask); printf("\n%3d.%3d.%3d.%3d",Ip[i]->a,Ip[i]->b,Ip[i]->c,Ip[i]->d); printf(" classe %c (mask: %x) e netId %08X",'A'+j, classiIp[j]->netmask, Ip[i]->netid); } } } printf("\n"); for (int i=0; i<4-1; i++) { for (int j=i+1;j<4;j++) { if (Ip[i]->netid==Ip[j]->netid) { printf("\n%d.%d.%d.%d",Ip[i]->a,Ip[i]->b,Ip[i]->c,Ip[i]->d); printf(" e %d.%d.%d.%d stessa rete",Ip[j]->a,Ip[j]->b,Ip[j]->c,Ip[j]->d); } } } } }; int main(){ jClassful *c = new jClassful(); c->calcola(); return 0; }