00001 // 00002 // Copyright (C) 2004 Andras Varga 00003 // Copyright (C) 2000 Institut fuer Telematik, Universitaet Karlsruhe 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with this program; if not, see <http://www.gnu.org/licenses/>. 00017 // 00018 00019 00020 // Author: Andras Varga, 2004 00021 00022 #include <stdio.h> 00023 #include <stdlib.h> 00024 #include <string.h> 00025 #include <ctype.h> 00026 00027 #include <algorithm> 00028 #include <sstream> 00029 00030 #include "IPv4InterfaceData.h" 00031 00032 00033 IPv4InterfaceData::IPv4InterfaceData() 00034 { 00035 static const IPAddress allOnes("255.255.255.255"); 00036 netmask = allOnes; 00037 00038 metric = 0; 00039 00040 // TBD add default multicast groups! 00041 } 00042 00043 std::string IPv4InterfaceData::info() const 00044 { 00045 std::stringstream out; 00046 out << "IP:{inet_addr:" << getIPAddress() << "/" << getNetmask().getNetmaskLength(); 00047 if (!getMulticastGroups().empty()) 00048 { 00049 out << " mcastgrps:"; 00050 for (unsigned int j=0; j<getMulticastGroups().size(); j++) 00051 if (!getMulticastGroups()[j].isUnspecified()) 00052 out << (j>0?",":"") << getMulticastGroups()[j]; 00053 } 00054 out << "}"; 00055 return out.str(); 00056 } 00057 00058 std::string IPv4InterfaceData::detailedInfo() const 00059 { 00060 std::stringstream out; 00061 out << "inet addr:" << getIPAddress() << "\tMask: " << getNetmask() << "\n"; 00062 00063 out << "Metric: " << getMetric() << "\n"; 00064 00065 out << "Groups:"; 00066 for (unsigned int j=0; j<getMulticastGroups().size(); j++) 00067 if (!getMulticastGroups()[j].isUnspecified()) 00068 out << " " << getMulticastGroups()[j]; 00069 out << "\n"; 00070 return out.str(); 00071 } 00072 00073 bool IPv4InterfaceData::isMemberOfMulticastGroup(const IPAddress& multicastAddress) const 00074 { 00075 int n = getMulticastGroups().size(); 00076 for (int i=0; i<n; i++) 00077 if (multicastAddress.equals(getMulticastGroups()[i])) 00078 return true; 00079 return false; 00080 } 00081