1 //析取IP地址,如果说是合法的IP则返回true,否则返回 false
2 bool GetProxyIP( std::wstring& strIP )
3 {
4 strIP.clear();
5 LPCWSTR pszIP = GetEditBoxText( IDC_DLG_LOGIN_SETTING_EDIT_ADDRESS );
6 if( pszIP == NULL || !wcscmp( pszIP, TEXT("") ) )
7 return false;
8
9 std::wstring strTemp = pszIP;
10 std::wstring::size_type nPos1, nPos2;
11 nPos1 = nPos2 = 0;
12 int nIP[4] = {0};
13 std::wstring::size_type i = 0;
14 for( ; (i < 4) && (nPos2 != std::wstring::npos ); ++i )
15 {
16 if( nPos2 == 0 )
17 nPos1 = nPos2;
18 else
19 nPos1 = nPos2 + 1;
20
21 nPos2 = strTemp.find( TEXT('.'), nPos1);
22 std::wstring::size_type nCount = std::wstring::npos;
23 if( nPos2 != std::wstring::npos )
24 nCount = nPos2 - nPos1;
25
26 std::wstring strSub = strTemp.substr(nPos1, nCount);
27 if( strSub == TEXT("") )
28 return false;
29
30 int nValue = _wtoi( strSub.c_str() );
31 if( nValue < 0 || nValue > 255 )
32 return false;
33 nIP[i] = nValue;
34 }
35
36 if( i < 4 )
37 return false;
38 wchar_t szIP[100] = {0};
39 wsprintf( szIP, TEXT("%d.%d.%d.%d"), nIP[0], nIP[1], nIP[2], nIP[3] );
40 strIP = szIP;
41 return true;
42 }