char IP::calculateClass(IP p) { int tal; string adress; adress = p.getIP().substr(0, p.getIP().find(".")); //tar ut sträng mellan position 0 och första punkten. 192.168.1.1 -> 192 tal = atoi(adress.c_str()); if (tal < 128) return 'A'; else if (tal >= 128 && tal < 192) return 'B'; else if (tal >= 192 && tal < 224) return 'C'; else return 'X'; }
string IP::calculateHost(IP p) { char c = this->klass; size_t pos = -1; if (c == 'A') { return p.getIP().substr(p.getIP().find(".") + 1); } else if (c == 'B') { pos = p.getIP().find("."); //första punkten pos = p.getIP().find(".", pos + 1); //andra punkten return p.getIP().substr(pos + 1); } else if (c == 'C') { pos = p.getIP().find_last_of("."); return p.getIP().substr(pos + 1); } else return "0.0.0.0"; }