支持BGP 4-octets AS Num,EDIT对话框支持两种输入方式,一种是输入四字节整型,另一种是点分类型输入,这就需要
类型转换。
/*****************************************************************************
【功能】把字符串转换为整型,如果大于65535则说明用户按ASPLAIN输入
******************************************************************************/
ULONG ConvertCStringToInterger(CString str)
{
char *temp;
unsigned long ulAs = 0;
unsigned int AS[2] = {0};
char a[100];
memset(a, 0, 100);
strncpy(a,(LPCTSTR)str,sizeof(a));
temp = strtok(a, ".");
int i = 0;
while ((temp != NULL)&&(i < 2))
{
AS[i] = atoi(temp);
temp = strtok(NULL, ".");
i++;
}
if (i == 1) {
ulAs = AS[0];
}
else {
if (AS[0] > 65535) {
AS[0] = 65535;
}
ulAs = AS[0];
if (AS[1] > 65535) {
AS[1] = 65535;
}
ulAs = (((ulAs << 16) & 0xffff0000) | (AS[1] & 0xffff));
}
return ulAs;
}
/*************************************************************
【功能】把整型转换为CString类,此处统一转换为点分形式表示
**************************************************************/
CString ConvertIntergerToCString(ULONG ulAs)
{
CString strAS;
CString strAsHi, strAsLow;
if (ulAs <= 65535)
{
strAS.Format("%u", ulAs);
}
else
{
strAsHi.Format("%u.", ulAs >> 16);
strAsLow.Format("%u", ulAs & 0xffff);
strAS = strAsHi + strAsLow;
}
return strAS;
}