📄 msdntest.cpp
字号:
#include <string>
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
using namespace std;
//信息判断的函数
int judgename(string str)
{
if(str.substr(0,strlen("Server"))=="Server")
{
return 1;
}
if(str.substr(0,strlen("Client"))=="Client")
{
return 2;
}
if(str.substr(0,strlen("Channel"))=="Channel")
{
return 3;
}
if(str.substr(0,strlen("OsnVolume"))=="OsnVolume")
{
return 4;
}
if(str.substr(0,strlen("CfgMapping"))=="CfgMapping")
{
return 5;
}
if(str.substr(0,strlen("Backup"))=="Backup")
{
return 6;
}
if(str.substr(0,strlen("Snapshot"))=="Snapshot")
{
return 7;
}
if(str.substr(0,strlen("Mirror"))=="Mirror")
{
return 8;
}
return 0;
}
void ReadServerCfg()
{
FILE *stream1;
char* pBuf = NULL;
int ch,len;
string str="";
string substr1,substr2,substr3,substr4,substr5,substr6,substr7,substr8;
char seps[]=",";
char *token = NULL;
/* Open file to read line from: */
if( (stream1 = fopen( "OSNServerHost.cfg", "r" )) == NULL )
{
printf("Open File Failed!\n");
exit( 0 );
}
while (!feof(stream1))
{
while(('\n' != (ch=fgetc(stream1))) && !feof(stream1))
{
str+=ch;
}
//cout<<endl<<"str:"<<str<<endl;
switch(judgename(str))
{
case 1:
//对Server的信息进行处理
substr1=str.substr(strlen("Server")+1,(strlen(str.c_str())-(strlen("Server")+1)));
len=substr1.length();
pBuf=new char[len+1];
if(NULL == pBuf)
{
printf("alloc space for pBuf failed!\n");
exit(0);
}
memset(pBuf,'\0', len+1);
substr1.copy(pBuf,len);
printf( "Server Infomation:\n\n" );
/* Establish string and get the first token: */
token = strtok( pBuf, seps );
/* While there are tokens in "string" */
printf( "Host Name: %s\n", token );
/* Get next token: */
token = strtok( NULL, seps );
printf( "Host WWN: %s\n", token );
token = strtok( NULL, seps );
printf( "Host IP Address: %s\n", token );
token = strtok( NULL, seps );
if(NULL != pBuf)
{
delete []pBuf;
pBuf = NULL;
}
printf( "\n***************************\n");
break;
case 2:
//对Client的信息进行处理
substr2=str.substr(strlen("Client")+1,(strlen(str.c_str())-(strlen("Client")+1)));
len=substr2.length();
pBuf=new char[len+1];
if(NULL == pBuf)
{
printf("alloc space for pBuf failed!\n");
exit(0);
}
memset(pBuf,'\0', len+1);
substr2.copy(pBuf,len);
printf( "Client Infomation:\n\n" );
/* Establish string and get the first token: */
token = strtok( pBuf, seps );
/* While there are tokens in "string" */
printf( "Client Name: %s\n", token );
/* Get next token: */
token = strtok( NULL, seps );
printf( "Client OS Type: %s\n", token );
token = strtok( NULL, seps );
token = strtok( NULL, seps );
printf( "Server IP Address: %s\n", token );
token = strtok( NULL, seps );
printf( "Client Type: %s\n", token );
token = strtok( NULL, seps );
if(NULL != pBuf)
{
delete []pBuf;
pBuf = NULL;
}
printf( "\n***************************\n");
break;
case 3:
//对Channel的信息进行处理
substr3=str.substr(strlen("Channel")+1,(strlen(str.c_str())-(strlen("Channel")+1)));
len=substr3.length();
pBuf=new char[len+1];
if(NULL == pBuf)
{
printf("alloc space for pBuf failed!\n");
exit(0);
}
memset(pBuf,'\0', len+1);
substr3.copy(pBuf,len);
printf( "Channel Infomation:\n\n" );
/* Establish string and get the first token: */
token = strtok( pBuf, seps );
/* While there are tokens in "string" */
printf( "Server Name: %s\n", token );
/* Get next token: */
token = strtok( NULL, seps );
token = strtok( NULL, seps );
printf( "Channel: %s\n", token );
token = strtok( NULL, seps );
printf( "WWN: %s\n", token );
token = strtok( NULL, seps );
printf( "IQN Name: %s\n", token );
token = strtok( NULL, seps );
printf( "Is FC: %s\n", token );
token = strtok( NULL, seps );
printf( "PortId: %s\n", token );
token = strtok( NULL, seps );
printf( "ScsiMode: %s\n", token );
token = strtok( NULL, seps );
printf( "Channel Type: %s\n", token );
token = strtok( NULL, seps );
if(NULL != pBuf)
{
delete []pBuf;
pBuf = NULL;
}
printf( "\n***************************\n");
break;
case 4:
//对OsnVolume的信息进行处理
substr4=str.substr(strlen("OsnVolume")+1,(strlen(str.c_str())-(strlen("OsnVolume")+1)));
len=substr4.length();
pBuf=new char[len+1];
if(NULL == pBuf)
{
printf("alloc space for pBuf failed!\n");
exit(0);
}
memset(pBuf,'\0', len+1);
substr4.copy(pBuf,len);
printf( "OsnVolume Infomation:\n\n" );
/* Establish string and get the first token: */
token = strtok( pBuf, seps );
/* While there are tokens in "string" */
printf( "Volume Name: %s\n", token );
/* Get next token: */
token = strtok( NULL, seps );
printf( "Volume ID: %s\n", token );
token = strtok( NULL, seps );
printf( "Pool ID: %s\n", token );
token = strtok( NULL, seps );
printf( "Volume Location: %s\n", token );
token = strtok( NULL, seps );
printf( "Volume Config Flag: %s\n", token );
token = strtok( NULL, seps );
ULONG usize;
usize=atoi(token);
printf( "Volume Size: %u MB\n", (usize/2048));
token = strtok( NULL, seps );
printf( "\n***************************\n");
if(NULL != pBuf)
{
delete []pBuf;
pBuf = NULL;
}
break;
case 5:
//对Mapping的信息进行处理
substr5=str.substr(strlen("CfgMapping")+1,(strlen(str.c_str())-(strlen("CfgMapping")+1)));
len=substr5.length();
pBuf=new char[len+1];
if(NULL == pBuf)
{
printf("alloc space for pBuf failed!\n");
exit(0);
}
memset(pBuf,'\0', len+1);
substr5.copy(pBuf,len);
printf( "Mapping Infomation:\n\n" );
/* Establish string and get the first token: */
token = strtok( pBuf, seps );
/* While there are tokens in "string" */
printf( "Volume ID: %s\n", token );
/* Get next token: */
token = strtok( NULL, seps );
printf( "Client Name: %s\n", token );
token = strtok( NULL, seps );
printf( "Client WWN: %s\n", token );
token = strtok( NULL, seps );
printf( "Server WWN: %s\n", token );
token = strtok( NULL, seps );
printf( "Mapping Mode: %s (0 is common mapping,16 is mirror mapping.)\n", token );
token = strtok( NULL, seps );
printf( "Server Name: %s\n", token );
token = strtok( NULL, seps );
printf( "Lun ID: %s\n", token );
token = strtok( NULL, seps );
printf( "\n***************************\n");
if(NULL != pBuf)
{
delete []pBuf;
pBuf = NULL;
}
break;
case 6:
//对Backup的信息进行处理
substr6=str.substr(strlen("Backup")+1,(strlen(str.c_str())-(strlen("Backup")+1)));
len=substr6.length();
pBuf=new char[len+1];
if(NULL == pBuf)
{
printf("alloc space for pBuf failed!\n");
exit(0);
}
memset(pBuf,'\0', len+1);
substr6.copy(pBuf,len);
printf( "Backup Infomation:\n\n" );
/* Establish string and get the first token: */
token = strtok( pBuf, seps );
/* While there are tokens in "string" */
printf( "Source Server Name: %s\n", token );
/* Get next token: */
token = strtok( NULL, seps );
printf( "Source Volume ID: %s\n", token );
token = strtok( NULL, seps );
printf( "Destination Volume ID: %s\n", token );
token = strtok( NULL, seps );
printf( "Destination Server Name: %s\n", token );
token = strtok( NULL, seps );
if(NULL != pBuf)
{
delete []pBuf;
pBuf = NULL;
}
printf( "\n***************************\n");
break;
case 7:
//对Snapshot的信息进行处理
substr7=str.substr(strlen("Snapshot")+1,(strlen(str.c_str())-(strlen("Snapshot")+1)));
len=substr7.length();
pBuf=new char[len+1];
if(NULL == pBuf)
{
printf("alloc space for pBuf failed!\n");
exit(0);
}
memset(pBuf,'\0', len+1);
substr7.copy(pBuf,len);
printf( "Snapshot Infomation:\n\n" );
/* Establish string and get the first token: */
token = strtok( pBuf, seps );
/* While there are tokens in "string" */
printf( "Source Volume ID: %s\n", token );
/* Get next token: */
token = strtok( NULL, seps );
printf( "Target Volume ID: %s\n", token );
token = strtok( NULL, seps );
token = strtok( NULL, seps );
printf( "Location: %s\n", token );
token = strtok( NULL, seps );
if(NULL != pBuf)
{
delete []pBuf;
pBuf = NULL;
}
printf( "\n***************************\n");
break;
case 8:
//对Mirror的信息进行处理
substr8=str.substr(strlen("Mirror")+1,(strlen(str.c_str())-(strlen("Mirror")+1)));
len=substr8.length();
pBuf=new char[len+1];
if(NULL == pBuf)
{
printf("alloc space for pBuf failed!\n");
exit(0);
}
memset(pBuf,'\0', len+1);
substr8.copy(pBuf,len);
printf( "Mirror Infomation:\n\n" );
/* Establish string and get the first token: */
token = strtok( pBuf, seps );
/* While there are tokens in "string" */
printf( "Primary Server Name: %s\n", token );
/* Get next token: */
token = strtok( NULL, seps );
printf( "Primary Volume Name: %s\n", token );
token = strtok( NULL, seps );
printf( "Primary Volume ID: %s\n", token );
token = strtok( NULL, seps );
printf( "Secondary Server Name: %s\n", token );
token = strtok( NULL, seps );
printf( "Secondary Volume Name: %s\n", token );
token = strtok( NULL, seps );
printf( "Secondary Volume ID: %s\n", token );
token = strtok( NULL, seps );
ULONG usize2;
usize2=atoi(token);
printf( "Mirror Size: %u MB\n", (usize2/2048));
token = strtok( NULL, seps );
printf( "Mirror Type: %s\n", token );
token = strtok( NULL, seps );
if(NULL != pBuf)
{
delete []pBuf;
pBuf = NULL;
}
printf( "\n***************************\n");
break;
default:
break;
}
str="";
}
fclose( stream1 );
}
void main()
{
ReadServerCfg();
//ReadHACfg();
//ReadBackupCfg();
getchar();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -