ip_hpux.cpp
来自「Pegasus is an open-source implementation」· C++ 代码 · 共 1,169 行 · 第 1/3 页
CPP
1,169 行
// for an IP Route. return false;}/*================================================================================NAME : getNameDESCRIPTION : ASSUMPTIONS : PRE-CONDITIONS :POST-CONDITIONS : NOTES : ================================================================================*/Boolean IPRoute::getName(String& s) const{ s = _destAddr; return true;}/*================================================================================NAME : getStatusDESCRIPTION : ASSUMPTIONS : PRE-CONDITIONS :POST-CONDITIONS : NOTES : ================================================================================*/Boolean IPRoute::getStatus(String& s) const{ // This property, inherited from CIM_ManagedSystemElement, // is not relevant. return false;}/*================================================================================NAME : getDestinationAddressDESCRIPTION : ASSUMPTIONS : PRE-CONDITIONS :POST-CONDITIONS : NOTES : ================================================================================*/Boolean IPRoute::getDestinationAddress(String& s) const{ s = _destAddr; return true;}/*================================================================================NAME : getDestinationMaskDESCRIPTION : ASSUMPTIONS : PRE-CONDITIONS :POST-CONDITIONS : NOTES : ================================================================================*/Boolean IPRoute::getDestinationMask(String& s) const{ s = _destMask; return true;}/*================================================================================NAME : getNextHopDESCRIPTION : ASSUMPTIONS : PRE-CONDITIONS :POST-CONDITIONS : NOTES : ================================================================================*/Boolean IPRoute::getNextHop(String& s) const{ s = _nextHop; return true;}/*================================================================================NAME : getIsStaticDESCRIPTION : ASSUMPTIONS : PRE-CONDITIONS :POST-CONDITIONS : NOTES : ================================================================================*/Boolean IPRoute::getIsStatic(Boolean& s) const{ // Don't know how to get this property. return false;}/*================================================================================NAME : getAddressTypeDESCRIPTION : ASSUMPTIONS : PRE-CONDITIONS :POST-CONDITIONS : NOTES : ================================================================================*/Boolean IPRoute::getAddressType(Uint16& i16) const{ /* From CIM v2.6.0 MOF for CIM_IPRoute.AddressType: ValueMap {"0", "1", "2"}, Values {"Unknown", "IPv4", "IPv6"} ] */ if (String::equal(_protocolType,PROTOCOL_IPV4)) { i16 = 1; // IPv4 return true; } else if (String::equal(_protocolType,PROTOCOL_IPV6)) { i16 = 2; // IPv6 return true; } else return false;}/*================================================================================NAME : set_destAddressDESCRIPTION : Platform-specific routine to set the IP Destination AddressASSUMPTIONS : NonePRE-CONDITIONS :POST-CONDITIONS : NOTES : ================================================================================*/void IPRoute::set_destAddr(const String& addr){ _destAddr = addr;}/*================================================================================NAME : set_destMaskDESCRIPTION : Platform-specific routine to set the IP Destination MaskASSUMPTIONS : NonePRE-CONDITIONS :POST-CONDITIONS : NOTES : ================================================================================*/void IPRoute::set_destMask(const String& dm){ _destMask = dm;}/*================================================================================NAME : set_nextHopDESCRIPTION : Platform-specific routine to set the Next Hop AddressASSUMPTIONS : NonePRE-CONDITIONS :POST-CONDITIONS : NOTES : ================================================================================*/void IPRoute::set_nextHop(const String& nh){ _nextHop = nh;}/*================================================================================NAME : set_protocolTypeDESCRIPTION : Platform-specific routine to set the Protocol TypeASSUMPTIONS : NonePRE-CONDITIONS :POST-CONDITIONS : NOTES : ================================================================================*/void IPRoute::set_protocolType(const String& pt){ _protocolType = pt;}/*================================================================================NAME : RouteList ConstructorDESCRIPTION : Build the list of IP RoutesASSUMPTIONS : NonePRE-CONDITIONS :POST-CONDITIONS : NOTES : ================================================================================*/RouteList::RouteList(){ int fd, // file descriptor i, // general purpose indicies count; // number of raw IP Routes struct nmparms parms; // get_mib_info() arguments mib_ipRouteEnt * route_buf; // IP Route Buffer unsigned int len; // length of get_mib_info() buffer struct in_addr t; // temporary variable for extracting // IP route buffer contents#ifdef DEBUG cout << "RouteList::RouteList()" << endl;#endif // Load the interface name structures. if ((fd = open_mib("/dev/ip", O_RDONLY, 0, 0)) < 0) { throw CIMOperationFailedException("Can't open /dev/ip: " + String(strerror(errno))); } parms.objid = ID_ipRouteNumEnt; parms.buffer = (char *) &count; len = sizeof(count); parms.len = (unsigned int *) &len; if (get_mib_info (fd, &parms) < 0) { throw CIMOperationFailedException( "Can't get ID_ipRouteNumEnt from get_mib_info(): " + String(strerror(errno))); } route_buf = (mib_ipRouteEnt *)malloc(count*sizeof(mib_ipRouteEnt)); if (route_buf == 0) { free (route_buf); throw CIMOperationFailedException( "Error in allocating space for the kernel interface table: " + String(strerror(errno))); } parms.objid = ID_ipRouteTable; parms.buffer = (char *) route_buf; len = count * sizeof(mib_ipRouteEnt); parms.len = &len; if (get_mib_info (fd, &parms) < 0) { free (route_buf); throw CIMOperationFailedException( "Can't get ID_ipRouteTable from get_mib_info(): " + String(strerror(errno))); } // Create the IP Route List entries for (i=0; i < count ; i++) { IPRoute _ipr; // check to see that this is a valid type to represent if (route_buf[i].Type == 3 || route_buf[i].Type == 4) { t.s_addr = route_buf[i].Dest; _ipr.set_destAddr(inet_ntoa(t)); t.s_addr = route_buf[i].Mask; _ipr.set_destMask(inet_ntoa(t)); t.s_addr = route_buf[i].NextHop; _ipr.set_nextHop(inet_ntoa(t)); // ATTN-LEW-2002-09-13: Enhance this to deal with IPv6 too. _ipr.set_protocolType(PROTOCOL_IPV4); _iprl.push_back(_ipr); // Add another IP Route to the list } } /* for */ close_mib(fd); free (route_buf);#ifdef DEBUG cout << "RouteList::RouteList() -- done" << endl;#endif}/*================================================================================NAME : RouteList DestructorDESCRIPTION : NoneASSUMPTIONS : NonePRE-CONDITIONS :POST-CONDITIONS : NOTES : ================================================================================*/RouteList::~RouteList(){}/*================================================================================NAME : findRouteDESCRIPTION : Find the requested IP Route based on the destination : address, destination mask, and address type.ASSUMPTIONS : NonePRE-CONDITIONS :POST-CONDITIONS : NOTES : ================================================================================*/Boolean RouteList::findRoute(const String &destAddr, const String &destMask, const Uint16 &addrType, IPRoute &ipRInst) const{ int i; for (i = 0; i < _iprl.size(); i++) { String sda, sdm; Uint16 sat; if ( _iprl[i].getDestinationAddress(sda) && String::equal(sda,destAddr) && _iprl[i].getDestinationMask(sdm) && String::equal(sdm,destMask) && _iprl[i].getAddressType(sat) && sat == addrType ) { ipRInst = _iprl[i]; return true; } }#ifdef DEBUG cout << "RouteList::findRoute(): NOT FOUND destAddr=" << destAddr << ", destMask=" << destMask << ", addrType=" << addrType << endl;#endif // IP Route not found return false;}/*================================================================================NAME : getRouteDESCRIPTION : Get an IP Route based on an index.ASSUMPTIONS : NonePRE-CONDITIONS :POST-CONDITIONS : NOTES : ================================================================================*/IPRoute RouteList::getRoute(const int index) const{ return _iprl[index];}/*================================================================================NAME : sizeDESCRIPTION : Find the size of the Route List.ASSUMPTIONS : NonePRE-CONDITIONS :POST-CONDITIONS : NOTES : ================================================================================*/int RouteList::size(void) const{ return _iprl.size();}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?