(file) Return to IPPEp.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Clients / ipinfo

  1 martin 1.10 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.11 //
  3 martin 1.10 // Licensed to The Open Group (TOG) under one or more contributor license
  4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5             // this work for additional information regarding copyright ownership.
  6             // Each contributor licenses this file to you under the OpenPegasus Open
  7             // Source License; you may not use this file except in compliance with the
  8             // License.
  9 martin 1.11 //
 10 martin 1.10 // Permission is hereby granted, free of charge, to any person obtaining a
 11             // copy of this software and associated documentation files (the "Software"),
 12             // to deal in the Software without restriction, including without limitation
 13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14             // and/or sell copies of the Software, and to permit persons to whom the
 15             // Software is furnished to do so, subject to the following conditions:
 16 martin 1.11 //
 17 martin 1.10 // The above copyright notice and this permission notice shall be included
 18             // in all copies or substantial portions of the Software.
 19 martin 1.11 //
 20 martin 1.10 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.11 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.10 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.11 //
 28 martin 1.10 //////////////////////////////////////////////////////////////////////////
 29 kumpf  1.2  //
 30             //
 31             //%/////////////////////////////////////////////////////////////////////////////
 32             
 33             #include "IPInfo.h"
 34             
 35             PEGASUS_USING_PEGASUS;
 36             PEGASUS_USING_STD;
 37             
 38             static const CIMName          CLASS_NAME = CIMName ("CIM_IPProtocolEndpoint");
 39             static const CIMNamespaceName NAMESPACE  = CIMNamespaceName ("root/cimv2");
 40             #define HeaderFormat "%-16s %-10s %-10s %-16s %-16s"
 41             
 42             
 43             ////////////////////////////////////////////////////////////////////////////////
 44             //  Constructor for IP Protocol Endpoint Info
 45             ////////////////////////////////////////////////////////////////////////////////
 46             IPPEpInfo::IPPEpInfo(CIMClient &client, Boolean enableDebug,
 47                            ostream& outPrintWriter, ostream& errPrintWriter)
 48             {
 49             
 50 kumpf  1.2      _enableDebug = enableDebug;
 51             
 52                 try
 53                 {
 54                     Boolean deepInheritance = true;
 55 karl   1.8          Boolean localOnly = true;
 56                     Boolean includeQualifiers = false;
 57                     Boolean includeClassOrigin = false;
 58 kumpf  1.12 
 59                     Array<CIMInstance> cimInstances =
 60 karl   1.8                  client.enumerateInstances(NAMESPACE, CLASS_NAME,
 61                                 deepInheritance, localOnly, includeQualifiers,
 62                                 includeClassOrigin);
 63 kumpf  1.12 
 64 karl   1.8          Uint32 numberInstances = cimInstances.size();
 65             
 66                     if (_enableDebug)
 67                 {
 68                     outPrintWriter << numberInstances << " instances of " <<
 69                              CLASS_NAME.getString() << endl;
 70                 }
 71             
 72                 if (numberInstances > 0)
 73                 {
 74                     _gatherProperties(cimInstances[0]);
 75                     _outputHeader(outPrintWriter);
 76             
 77                     for (Uint32 i = 0; i < numberInstances; i++)
 78                     {
 79                         _gatherProperties(cimInstances[i]);
 80                         _outputInstance(outPrintWriter);
 81 kumpf  1.2  
 82 karl   1.8          }   // end for looping through instances
 83                 }
 84 kumpf  1.2          else
 85 karl   1.8      {
 86 kumpf  1.12          outPrintWriter << "No instances of class "
 87 karl   1.8                          << CLASS_NAME.getString() << endl;
 88                 }
 89 kumpf  1.2  
 90 kumpf  1.12     }  // end try
 91             
 92 kumpf  1.7      catch(Exception&)
 93 kumpf  1.2      {
 94                     errPrintWriter << "Error getting instances of class " <<
 95                          CLASS_NAME.getString() << endl;
 96                 }
 97             }
 98             
 99             ////////////////////////////////////////////////////////////////////////////////
100             //  Destructor for IP Protocol Endpoint Info
101             ////////////////////////////////////////////////////////////////////////////////
102             IPPEpInfo::~IPPEpInfo(void)
103             {
104             }
105             
106             ////////////////////////////////////////////////////////////////////////////////
107             //  Gather Properities for IP Protocol Endpoint Info
108             ////////////////////////////////////////////////////////////////////////////////
109             void IPPEpInfo::_gatherProperties(CIMInstance &inst)
110             {
111                 _ipSCCN             = String::EMPTY;
112                 _ipSN               = String::EMPTY;
113                 _ipCCN              = String::EMPTY;
114 kumpf  1.2      _ipName             = String::EMPTY;
115             
116                 _ipCaption          = String::EMPTY;
117                 _ipDescription      = String::EMPTY;
118                 _ipNameFormat       = String::EMPTY;
119                 _ipProtocolType     = 0;  // Unknown
120                 _ipAddress          = String::EMPTY;
121                 _ipSubnetMask       = String::EMPTY;
122                 _ipAddrType         = 0;  // Unknown
123                 _ipIPVersionSupport = 0;  // Unknown
124             
125                 for (Uint32 j=0; j < inst.getPropertyCount(); j++)
126                 {
127 karl   1.8          CIMName propertyName = inst.getProperty(j).getName();
128 kumpf  1.2  
129                     // Properties that are also keys
130 karl   1.8          if (propertyName.equal("SystemCreationClassName"))
131                         inst.getProperty(j).getValue().get(_ipSCCN);
132 kumpf  1.2  
133 karl   1.8          else if (propertyName.equal("SystemName"))
134                         inst.getProperty(j).getValue().get(_ipSN);
135 kumpf  1.2  
136 karl   1.8          else if (propertyName.equal("CreationClassName"))
137                         inst.getProperty(j).getValue().get(_ipCCN);
138 kumpf  1.2  
139 karl   1.8          else if (propertyName.equal("Name"))
140                         inst.getProperty(j).getValue().get(_ipName);
141 kumpf  1.2  
142                     // Other properties
143 karl   1.8          else if (propertyName.equal("Caption"))
144 kumpf  1.12             inst.getProperty(j).getValue().get(_ipCaption);
145 kumpf  1.2  
146 karl   1.8          else if (propertyName.equal("Description"))
147 kumpf  1.12             inst.getProperty(j).getValue().get(_ipDescription);
148 kumpf  1.2  
149 karl   1.8          else if (propertyName.equal("NameFormat"))
150 kumpf  1.12             inst.getProperty(j).getValue().get(_ipNameFormat);
151 kumpf  1.2  
152 karl   1.8          else if (propertyName.equal("ProtocolType"))
153 kumpf  1.12             inst.getProperty(j).getValue().get(_ipProtocolType);
154 kumpf  1.2  
155 karl   1.8          else if (propertyName.equal("Address"))
156 kumpf  1.12             inst.getProperty(j).getValue().get(_ipAddress);
157 kumpf  1.2  
158 mateus.baur 1.9          else if (propertyName.equal("IPv6Address"))
159 kumpf       1.12             inst.getProperty(j).getValue().get(_ipIPv6Address);
160 mateus.baur 1.9  
161                          else if (propertyName.equal("IPv4Address"))
162 kumpf       1.12             inst.getProperty(j).getValue().get(_ipIPv4Address);
163 mateus.baur 1.9  
164 karl        1.8          else if (propertyName.equal("SubnetMask"))
165 kumpf       1.12             inst.getProperty(j).getValue().get(_ipSubnetMask);
166 kumpf       1.2  
167 mateus.baur 1.9          else if (propertyName.equal("PrefixLength"))
168 kumpf       1.12             inst.getProperty(j).getValue().get(_ipPrefixLength);
169 mateus.baur 1.9  
170 karl        1.8          else if (propertyName.equal("AddressType"))
171 kumpf       1.12             inst.getProperty(j).getValue().get(_ipAddrType);
172 kumpf       1.2  
173 karl        1.8          else if (propertyName.equal("IPVersionSupport"))
174 kumpf       1.12             inst.getProperty(j).getValue().get(_ipIPVersionSupport);
175 kumpf       1.2  
176 mateus.baur 1.9          else if (propertyName.equal("ProtocolIFType"))
177 kumpf       1.12             inst.getProperty(j).getValue().get(_ipProtocolIFType);
178 mateus.baur 1.9  
179 kumpf       1.2     } // end for loop through properties
180                  
181                  }
182                  
183                  
184                  ////////////////////////////////////////////////////////////////////////////////
185                  //  Header Section for IP Protocol Endpoint Info
186                  ////////////////////////////////////////////////////////////////////////////////
187                  void IPPEpInfo::_outputHeader(ostream &outPrintWriter)
188                  {
189                  
190                      outPrintWriter << endl << ">>>> IP Protocol Endpoint Information <<<<" <<
191                           endl << endl;
192                  
193                      if (_ipSCCN.size() > 0)
194                          outPrintWriter << "System Creation Class Name  : " << _ipSCCN << endl;
195                  
196                      if (_ipSN.size() > 0)
197                          outPrintWriter << "System Name                 : " << _ipSN << endl;
198                  
199                      if (_ipCCN.size() > 0)
200 kumpf       1.2          outPrintWriter << "Creation Class Name         : " << _ipCCN << endl;
201                  
202                      if (_ipNameFormat.size() > 0)
203 kumpf       1.12         outPrintWriter << "Name Format                 : "
204 karl        1.8          << _ipNameFormat << endl;
205 kumpf       1.2  
206 mateus.baur 1.9  /*
207 kumpf       1.2      outPrintWriter << "IP Version Support          : ";
208                      if (_ipIPVersionSupport == 1)
209 karl        1.8          outPrintWriter << "IPv4 Only" << endl;
210 kumpf       1.2      else if (_ipIPVersionSupport == 2)
211 karl        1.8          outPrintWriter << "IPv6 Only" << endl;
212 mateus.baur 1.9      else if (_ipIPVersionSupport == 3)
213                          outPrintWriter << "Both IPv4 and IPv6" << endl;
214 kumpf       1.2      else
215 karl        1.8          outPrintWriter << "Unknown" << endl;
216 mateus.baur 1.9  */
217 kumpf       1.2  
218                      char header[81];
219                  
220                      sprintf(header, HeaderFormat, "Endpoint", "AddrType", "Protocol",
221 mateus.baur 1.9          "Address", "SubnetMask/PrefixLength");
222 kumpf       1.2  
223                      outPrintWriter << endl << header << endl;
224 kumpf       1.12 
225 kumpf       1.2  }
226                  
227                  ////////////////////////////////////////////////////////////////////////////////
228                  //  Output an instance of an IP Protocol Endpoint Info
229                  ////////////////////////////////////////////////////////////////////////////////
230                  void IPPEpInfo::_outputInstance(ostream &outPrintWriter)
231                  {
232                      String _ipAT,  // Address Type
233 mateus.baur 1.9          _ipPT;  // Protocol Type
234 kumpf       1.2  
235                      if (_ipProtocolType == 0)
236 mateus.baur 1.9      {
237 karl        1.8          _ipPT = "Unknown";
238 mateus.baur 1.9      }
239 kumpf       1.12     else
240 mateus.baur 1.9      {
241                          if (_ipProtocolType == 2)
242                          {
243                              _ipPT = "IPv4";
244                          }
245 kumpf       1.12         else
246 mateus.baur 1.9          {
247                              if (_ipProtocolType == 3)
248                              {
249                                  _ipPT = "IPv6";
250                              }
251                              else
252                              {
253                                  _ipPT = "Unk";
254                              }
255                          }
256                      }
257 kumpf       1.2  
258                      char row[81];
259                  
260 mateus.baur 1.9      if (_ipAddrType == 1)
261                      {
262                          sprintf(
263 kumpf       1.12             row,
264                              HeaderFormat,
265 mateus.baur 1.9              (const char *)_ipName.getCString(),
266                              "IPv4",
267                              (const char *)_ipPT.getCString(),
268                              (const char *)_ipAddress.getCString(),
269                              (const char *)_ipSubnetMask.getCString());
270                      }
271 kumpf       1.12     else
272 mateus.baur 1.9      {
273                          if (_ipAddrType == 2)
274                          {
275                              _ipAT = "IPv6";
276                  
277                              char _pl[10];
278                              sprintf(_pl,"%d",_ipPrefixLength);
279                  
280                              if (_ipAddress.size() > 15)
281                              {
282                                  sprintf(
283 kumpf       1.12                     row,
284                                      HeaderFormat,
285 mateus.baur 1.9                      (const char *)_ipName.getCString(),
286                                      (const char *)_ipAT.getCString(),
287                                      (const char *)_ipPT.getCString(),
288                                      (const char *)_ipAddress.getCString(),
289                                      "");
290                                  outPrintWriter << row << endl;
291 kumpf       1.12 
292 mateus.baur 1.9                  _ipName.clear();
293                                  _ipPT.clear();
294                                  _ipAT.clear();
295                                  _ipAddress.clear();
296                              }
297                  
298                              sprintf(
299                                  row,
300                                  HeaderFormat,
301                                  (const char *)_ipName.getCString(),
302                                  (const char *)_ipAT.getCString(),
303                                  (const char *)_ipPT.getCString(),
304                                  (const char *)_ipAddress.getCString(),
305                                  _pl);
306                          }
307                          else
308                          {
309                              sprintf(
310                                  row,
311                                  HeaderFormat,
312                                  (const char *)_ipName.getCString(),
313 mateus.baur 1.9                  "Unk",
314                                  (const char *)_ipPT.getCString(),
315                                  (const char *)_ipAddress.getCString(),
316                                  (const char *)_ipSubnetMask.getCString());
317                          }
318                      }
319                  
320 kumpf       1.2      outPrintWriter << row << endl;
321 kumpf       1.12 
322 kumpf       1.2  }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2