static void setConfig(void) { FILE *fp; char buf[4096]; char *p; int i,len; static char name[32]; static char password[32]; static char nic[32]; static char fakeAddress[32]; int intelligentReconnect=-1; int echoInterval=-1; int authenticationMode=-1;
//the check and anylysis against Dot1xClient.conf *don't* work perfectly. //this may be improved in the later version. if( (fp=fopen("Dot1xClient.conf","r"))==NULL ) err_quit("cannot open file Dot1xClient.conf ! check it.\n"); while(fgets(buf,sizeof(buf),fp)!=NULL)//fgets遇到换行或EOF会结束 { if( (buf[0]=='#') || (buf[0]=='\n') ) continue;//继续下一循环 len=strlen(buf); if(buf[len-1]=='\n') buf[len-1]='\0';//in order to form a string if( ( (p=strchr(buf,'=')) == NULL) || (p==buf) )//if not find = continue; //the code above doesn't detect ALL the errors!! it should be improved in future.
*p='\0';//break the string into 2 parts. p++;//p ponit to the value now
if((m_name==NULL)||(m_name[0]==0)) err_quit("invalid name found in Dot1xClient.conf!\n"); if((m_password==NULL)||(m_password[0]==0)) err_quit("invalid password found in Dot1xClient.conf!\n"); if((m_authenticationMode<0)||(m_authenticationMode>1)) err_quit("invalid authenticationMode found in Dot1xClient.conf!\n"); if( (m_nic==NULL) || (strcmp(m_nic,"")==0) || (strcmp(m_nic,"any")==0) ) err_quit("invalid nic found in Dot1xClient.conf!\n"); if((m_echoInterval<0)||(m_echoInterval>100)) err_quit("invalid echo interval found in Dot1xClient.conf!\n" ); if((m_intelligentReconnect<0)||(m_intelligentReconnect>1)) err_quit("invalid intelligentReconnect found in Dot1xClient.conf!\n");
文章评论(0条评论)
登录后参与讨论