void IFaceWin::ApplyChanges( void ) { IFaceType_t nType = m_pcDdmType->GetCurrentString() == MSG_IFWIN_TYPE_STATIC ? Static : DHCP; bool bDefault = m_pcIFace->IsDefault(); bool bError = false; switch ( nType ) { case Static: { IPAddress_t nIP, nNM, nGW; String cError; if( !ParseIPAddress( m_pcTxtAddress->GetValue().AsString( ), &nIP ) ) { bError = true; cError = MSG_IFWIN_ERR_IP_ADDRESS; } else if( !ParseIPAddress( m_pcTxtNetmask->GetValue().AsString( ), &nNM ) ) { bError = true; cError = MSG_IFWIN_ERR_NETMASK; } else if( !ParseIPAddress( m_pcTxtGateway->GetValue().AsString( ), &nGW ) ) { bError = true; cError = MSG_IFWIN_ERR_GATEWAY; } if( bError ) { Alert *pcAlert = new Alert( MSG_IFWIN_ERR_TITLE, cError, Alert::ALERT_WARNING, 0, MSG_IFWIN_ERR_CLOSE.c_str(), NULL ); pcAlert->Go( new Invoker( new Message() ) ); } else { m_pcIFace->SetAddress( nIP ); m_pcIFace->SetNetmask( nNM ); m_pcIFace->SetGateway( nGW ); } break; } case DHCP: break; } if( !bError ) { m_pcIFace->SetType( nType ); m_pcIFace->SetEnabled( m_pcCbEnabled->GetValue().AsBool( ) ); m_pcIFace->SetDefault( bDefault ); Messenger cMsnger( m_pcParent ); cMsnger.SendMessage( new Message( ApplyInterfaceChanges ) ); } }
nsresult nsUrlClassifierUtils::CanonicalizeHostname(const nsACString & hostname, nsACString & _retval) { nsAutoCString unescaped; if (!NS_UnescapeURL(PromiseFlatCString(hostname).get(), PromiseFlatCString(hostname).Length(), 0, unescaped)) { unescaped.Assign(hostname); } nsAutoCString cleaned; CleanupHostname(unescaped, cleaned); nsAutoCString temp; ParseIPAddress(cleaned, temp); if (!temp.IsEmpty()) { cleaned.Assign(temp); } ToLowerCase(cleaned); SpecialEncode(cleaned, false, _retval); return NS_OK; }
bool IpAddress::BuildFromAddress(const char* address) { m_isValid = false; bool isIPv6; UInt8 result[16]; if (!ParseIPAddress(address, result, &m_port, &isIPv6, nullptr)) return false; m_isValid = true; if (isIPv6) { m_protocol = NetProtocol_IPv6; for (unsigned int i = 0; i < 8; ++i) m_ipv6[i] = UInt32(result[i*2]) << 8 | result[i*2 + 1]; } else { m_protocol = NetProtocol_IPv4; for (unsigned int i = 0; i < 4; ++i) m_ipv4[i] = result[i]; } return true; }
sparks::shared_ptr<INetworkListener> CListenerFactory::CreateListener( const std::string& address, sparks::shared_ptr<CThread> spThread ) { int nStartPos = 0; std::string ip; std::string type; sparks::int32 port = 0; if (ParseType(address, &nStartPos, type)) { if (ParseIPAddress(address, &nStartPos, ip)) { if (ParsePort(address, &nStartPos, port)) { // ½âÎö¸÷¸÷uri×ֶΠ} } } if (type == "tcp" && ip.length() && port != 0) { boost::asio::ip::tcp::endpoint point(boost::asio::ip::address::from_string(ip), port); return sparks::shared_ptr<INetworkListener>(new CTcpListener(spThread->GetIOService(), point)); } return sparks::shared_ptr<INetworkListener>(); }
void InterfaceManager::LoadConfig( InterfaceList_t & cInterfaces ) { ClearInterfaceList( cInterfaces ); File cFile; if( cFile.SetTo( CONFIG_FILE ) == 0 ) { StringReader cSr( &cFile ); std::vector < String >cLines; cLines.push_back( cSr.ReadLine() ); while( cSr.HasLines() ) { cLines.push_back( cSr.ReadLine() ); } String cName; String cMAC; IPAddress_t nAddress; IPAddress_t nNetmask; IPAddress_t nGateway; bool bEnabled = false; bool bDefault = false; IFaceType_t nType = Static; bool bInIFace = false; Interface *pcIFace = NULL; for( std::vector < String >::iterator i = cLines.begin(); i != cLines.end( ); i++ ) { if( *i == "interface" ) { bInIFace = true; continue; } if( *i == "" ) { if( bInIFace ) { pcIFace = new Interface( nType, cName, cMAC ); pcIFace->SetEnabled( bEnabled ); pcIFace->SetDefault( bDefault ); if( nType == Static ) { pcIFace->SetAddress( nAddress ); pcIFace->SetNetmask( nNetmask ); pcIFace->SetGateway( nGateway ); } cInterfaces.push_back( pcIFace ); } bInIFace = false; continue; } if( bInIFace ) { if( ( *i ).find( "type" ) == 0 ) { nType = ( *i ).substr( 5 ) == "Static" ? Static : DHCP; } else if( ( *i ).find( "name" ) == 0 ) { cName = ( *i ).substr( 5 ); } else if( ( *i ).find( "mac" ) == 0 ) { cMAC = ( *i ).substr( 4 ); } else if( ( *i ).find( "address" ) == 0 ) { ParseIPAddress( ( *i ).substr( 8 ), &nAddress ); } else if( ( *i ).find( "netmask" ) == 0 ) { ParseIPAddress( ( *i ).substr( 8 ), &nNetmask ); } else if( ( *i ).find( "gateway" ) == 0 ) { ParseIPAddress( ( *i ).substr( 8 ), &nGateway ); } else if( ( *i ).find( "enabled" ) == 0 ) { bEnabled = ( *i ).substr( 8 ) == "true"; } else if( ( *i ).find( "default" ) == 0 ) { bDefault = ( *i ).substr( 8 ) == "true"; } } } } }