strtok is not thread safe..used to set receiver udp ip etc to detector, fixed

This commit is contained in:
Dhanya Maliakal 2017-04-06 15:04:33 +02:00
parent 5c230e2ac5
commit 65f5e1c1ab

View File

@ -6046,8 +6046,6 @@ int slsDetector::configureMAC(){
int fnum=F_CONFIGURE_MAC,fnum2=F_RECEIVER_SHORT_FRAME; int fnum=F_CONFIGURE_MAC,fnum2=F_RECEIVER_SHORT_FRAME;
char mess[MAX_STR_LENGTH]=""; char mess[MAX_STR_LENGTH]="";
char arg[6][50]={"","","","","",""}; char arg[6][50]={"","","","","",""};
char cword[50]="", *pcword;
string sword;
int retval=-1; int retval=-1;
@ -6092,50 +6090,76 @@ int slsDetector::configureMAC(){
std::cout<< "IP/MAC Addresses valid "<< std::endl; std::cout<< "IP/MAC Addresses valid "<< std::endl;
#endif #endif
//converting IPaddress to hex.
pcword = strtok (arg[0],"."); {
while (pcword != NULL) { //converting IPaddress to hex
sprintf(arg[0],"%02x",atoi(pcword)); stringstream ss(arg[0]);
strcat(cword,arg[0]); char cword[50]="";
pcword = strtok (NULL, "."); bzero(cword, 50);
string s;
while (getline(ss, s, '.')) {
sprintf(cword,"%s%02x",cword,atoi(s.c_str()));
} }
bzero(arg[0], 50);
strcpy(arg[0],cword); strcpy(arg[0],cword);
#ifdef VERBOSE #ifdef VERBOSE
std::cout<<"receiver udp ip:"<<arg[0]<<"."<<std::endl; std::cout<<"receiver udp ip:"<<arg[0]<<"."<<std::endl;
#endif #endif
//converting MACaddress to hex. }
sword.assign(arg[1]);
strcpy(arg[1],"");
stringstream sstr(sword);
while(getline(sstr,sword,':')) {
strcat(arg[1],sword.c_str()); //converting MACaddress to hex
stringstream ss(arg[1]);
char cword[50]="";
bzero(cword, 50);
string s;
while (getline(ss, s, ':')) {
sprintf(cword,"%s%s",cword,s.c_str());
}
bzero(arg[1], 50);
strcpy(arg[1],cword);
#ifdef VERBOSE #ifdef VERBOSE
std::cout<<"receiver mac:"<<arg[1]<<"."<<std::endl; std::cout<<"receiver mac:"<<arg[1]<<"."<<std::endl;
#endif #endif
}
#ifdef VERBOSE #ifdef VERBOSE
std::cout<<"receiver udp port:"<<arg[2]<<"."<<std::endl; std::cout<<"receiver udp port:"<<arg[2]<<"."<<std::endl;
#endif #endif
//converting server MACaddress to hex.
sword.assign(arg[3]); {
strcpy(arg[3],""); stringstream ss(arg[3]);
stringstream ssstr(sword); char cword[50]="";
while(getline(ssstr,sword,':')) bzero(cword, 50);
strcat(arg[3],sword.c_str()); string s;
while (getline(ss, s, ':')) {
sprintf(cword,"%s%s",cword,s.c_str());
}
bzero(arg[3], 50);
strcpy(arg[3],cword);
#ifdef VERBOSE #ifdef VERBOSE
std::cout<<"detecotor mac:"<<arg[3]<<"."<<std::endl; std::cout<<"detecotor mac:"<<arg[3]<<"."<<std::endl;
#endif #endif
//converting IPaddress to hex.
strcpy(cword,"");
pcword = strtok (arg[4],".");
while (pcword != NULL) {
sprintf(arg[4],"%02x",atoi(pcword));
strcat(cword,arg[4]);
pcword = strtok (NULL, ".");
} }
{
//converting IPaddress to hex
stringstream ss(arg[4]);
char cword[50]="";
bzero(cword, 50);
string s;
while (getline(ss, s, '.')) {
sprintf(cword,"%s%02x",cword,atoi(s.c_str()));
}
bzero(arg[4], 50);
strcpy(arg[4],cword); strcpy(arg[4],cword);
#ifdef VERBOSE #ifdef VERBOSE
std::cout<<"detector ip:"<<arg[4]<<"."<<std::endl; std::cout<<"detector ip:"<<arg[4]<<"."<<std::endl;
#endif #endif
}
#ifdef VERBOSE #ifdef VERBOSE
std::cout<<"receiver udp port2:"<<arg[5]<<"."<<std::endl; std::cout<<"receiver udp port2:"<<arg[5]<<"."<<std::endl;
#endif #endif