diff options
Diffstat (limited to 'knetworkconf/knetworkconf/kaddressvalidator.cpp')
-rw-r--r-- | knetworkconf/knetworkconf/kaddressvalidator.cpp | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/knetworkconf/knetworkconf/kaddressvalidator.cpp b/knetworkconf/knetworkconf/kaddressvalidator.cpp index c1f086a..03d21c6 100644 --- a/knetworkconf/knetworkconf/kaddressvalidator.cpp +++ b/knetworkconf/knetworkconf/kaddressvalidator.cpp @@ -123,37 +123,37 @@ bool KAddressValidator::isBroadcastValid(TQString addr){ } -/** \fn unsigned long int prefix2tqmask(int bits) - \brief creates a nettqmask from a specified number of bits +/** \fn unsigned long int prefix2mask(int bits) + \brief creates a netmask from a specified number of bits - This function converts a prefix length to a nettqmask. As CIDR (classless + This function converts a prefix length to a netmask. As CIDR (classless internet domain internet domain routing) has taken off, more an more IP addresses are being specified in the format address/prefix - (i.e. 192.168.2.3/24, with a corresponding nettqmask 255.255.255.0). If you - need to see what nettqmask corresponds to the prefix part of the address, this - is the function. See also \ref tqmask2prefix. + (i.e. 192.168.2.3/24, with a corresponding netmask 255.255.255.0). If you + need to see what netmask corresponds to the prefix part of the address, this + is the function. See also \ref mask2prefix. - \param prefix is the number of bits to create a tqmask for. - \return a network tqmask, in network byte order. + \param prefix is the number of bits to create a mask for. + \return a network mask, in network byte order. */ -unsigned long int KAddressValidator::prefix2tqmask(int prefix){ +unsigned long int KAddressValidator::prefix2mask(int prefix){ return htonl(~((2 << (31 - prefix)) - 1)); } -/** \fn int tqmask2prefix(unsigned long int tqmask) - \brief calculates the number of bits masked off by a nettqmask. +/** \fn int mask2prefix(unsigned long int mask) + \brief calculates the number of bits masked off by a netmask. This function calculates the significant bits in an IP address as specified by - a nettqmask. See also \ref prefix2tqmask. + a netmask. See also \ref prefix2mask. - \param tqmask is the nettqmask, specified as an unsigned long integer in network byte order. + \param mask is the netmask, specified as an unsigned long integer in network byte order. \return the number of significant bits. */ -int KAddressValidator::tqmask2prefix(unsigned long int tqmask){ +int KAddressValidator::mask2prefix(unsigned long int mask){ unsigned i; int count = IPBITS; for (i = 0; i < IPBITS; i++) { - if (!(ntohl(tqmask) & ((2 << i) - 1))) + if (!(ntohl(mask) & ((2 << i) - 1))) count--; } @@ -170,7 +170,7 @@ int KAddressValidator::tqmask2prefix(unsigned long int tqmask){ \return the calculated broadcast address for the network, in network byte order. */ unsigned long int KAddressValidator::calc_broadcast(unsigned long int addr, int prefix){ - return (addr & prefix2tqmask(prefix)) | ~prefix2tqmask(prefix); + return (addr & prefix2mask(prefix)) | ~prefix2mask(prefix); } /** \fn unsigned long int calc_network(unsigned long int addr, int prefix) \brief calculates the network address for a specified address and prefix. @@ -180,25 +180,25 @@ unsigned long int KAddressValidator::calc_broadcast(unsigned long int addr, int \return the base address of the network that addr is associated with, in network byte order. */ unsigned long int KAddressValidator::calc_network(unsigned long int addr, int prefix){ - return (addr & prefix2tqmask(prefix)); + return (addr & prefix2mask(prefix)); } -/** Is a wrapper function to calc_network that receives the IP address and netstqmask as TQString and +/** Is a wrapper function to calc_network that receives the IP address and netsmask as TQString and returns the network value also as a TQString, or NULL if it couldn't be calculated. */ -TQString KAddressValidator::calculateNetwork(TQString addr,TQString nettqmask){ - struct in_addr _addr, _nettqmask, _network; +TQString KAddressValidator::calculateNetwork(TQString addr,TQString netmask){ + struct in_addr _addr, _netmask, _network; int prefix = 0; TQString s; - if (addr.isNull() || nettqmask.isNull()) + if (addr.isNull() || netmask.isNull()) return NULL; //bad address if (!inet_pton(AF_INET,addr.latin1(),&_addr)) return NULL; //bad address else { - if (!inet_pton(AF_INET,nettqmask.latin1(),&_nettqmask)) + if (!inet_pton(AF_INET,netmask.latin1(),&_netmask)) return NULL; //bad address else { - prefix = tqmask2prefix(_nettqmask.s_addr); + prefix = mask2prefix(_netmask.s_addr); _network.s_addr = calc_network(_addr.s_addr, prefix); char * char_network = new char[20]; if (!inet_ntop(AF_INET,&_network,char_network,20)) @@ -210,23 +210,23 @@ TQString KAddressValidator::calculateNetwork(TQString addr,TQString nettqmask){ return s; } -/** Is a wrapper function to calc_broadcast that receives the IP address and netstqmask as TQString and +/** Is a wrapper function to calc_broadcast that receives the IP address and netsmask as TQString and returns the broadcast value also as a TQString, or NULL if it couldn't be calculated. */ -TQString KAddressValidator::calculateBroadcast(TQString addr, TQString nettqmask){ - struct in_addr _addr, _nettqmask, _network; +TQString KAddressValidator::calculateBroadcast(TQString addr, TQString netmask){ + struct in_addr _addr, _netmask, _network; int prefix = 0; TQString s; - if (addr.isNull() || nettqmask.isNull()) + if (addr.isNull() || netmask.isNull()) return NULL; //bad address if (!inet_pton(AF_INET,addr.latin1(),&_addr)) return NULL; //bad address else { - if (!inet_pton(AF_INET,nettqmask.latin1(),&_nettqmask)) + if (!inet_pton(AF_INET,netmask.latin1(),&_netmask)) return NULL; //bad address else { - prefix = tqmask2prefix(_nettqmask.s_addr); + prefix = mask2prefix(_netmask.s_addr); _network.s_addr = calc_broadcast(_addr.s_addr, prefix); char * char_network = new char[20]; if (!inet_ntop(AF_INET,&_network,char_network,20)) |