From 93cc194db9443c59a41ca243dfe10c3a22b9c12e Mon Sep 17 00:00:00 2001 From: Gerd v. Egidy Date: Fri, 27 Aug 2004 17:33:59 +0000 Subject: [PATCH] libi2ncommon: (gerd) replace CalculateNetworkAddresses code by IP_RANGE-based inline --- src/ipfunc.cpp | 85 -------------------------------------------------------- src/ipfunc.hxx | 8 ++++- 2 files changed, 7 insertions(+), 86 deletions(-) diff --git a/src/ipfunc.cpp b/src/ipfunc.cpp index ccefe95..9783249 100644 --- a/src/ipfunc.cpp +++ b/src/ipfunc.cpp @@ -17,91 +17,6 @@ using namespace std; using namespace ip_type; -string CalculateNetworkAddresses (int mode, const string &ip, const string &netmask) -{ - int IP[4]; - int NETMASK[4]; - int OUTPUT[4]; - - string rtn; - - try { - string::size_type base = 0; - string::size_type pos = 0; - - // split ip - for (int i = 0; i < 4; i++) { - pos = ip.find(".", base); - - if (pos == string::npos) - pos = ip.length(); - if (pos != string::npos && pos-base > 0) { - // get single IP fragment and convert to integer - string ipfrag (ip, base, pos-base); - istringstream in(ipfrag); - int tmp; - if (!in.eof() && in >> tmp) - IP[i] = tmp; - } - - // fix offset to leave out the "." - base = pos+1; - } - - base = 0; - pos = 0; - - // split netmask - for (int i = 0; i < 4; i++) { - pos = netmask.find(".", base); - - if (pos == string::npos) - pos = netmask.length(); - if (pos != string::npos && pos-base > 0) { - // get single IP fragment and convert to integer - string ipfrag (netmask, base, pos-base); - istringstream in(ipfrag); - int tmp; - if (!in.eof() && in >> tmp) - NETMASK[i] = tmp; - } - - // fix offset to leave out the "." - base = pos+1; - } - } catch (...) {} - - if (mode == 0) { // get network-base-address (by ANDing ip and netmask) - for (int i = 0; i < 4; i++) - OUTPUT[i] = IP[i]&NETMASK[i]; - } else { // calculate broadcast address - /* - how it works: - -the broadcast address is an address with all host bits set - - -check all netmask bits -> if the bit is cleared -> bit is host bit - -set all host bits in the IP adress to 1 - */ - - // precopy IP to output - for (int i = 0; i < 4; i++) - OUTPUT[i] = IP[i]; - - for (int i = 0; i < 4; i++) - for (int j = 0; j < 8; j++) { - if (!(NETMASK[i]&1<