got rid of local host because pcname works on its own

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@427 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d
2013-01-15 10:26:37 +00:00
parent 5d88f249a4
commit f6a3254c2f

View File

@ -4610,24 +4610,17 @@ int slsDetector::setUDPConnection(){
//if no udp ip given, use hostname //if no udp ip given, use hostname
if(!strcmp(thisDetector->receiverUDPIP,"none")){ if(!strcmp(thisDetector->receiverUDPIP,"none")){
if(!strcmp(thisDetector->receiver_hostname,"localhost")){ //hostname is an ip address
string temp = genericSocket::ipToName("localhost"); if(strchr(thisDetector->receiver_hostname,'.')!=NULL)
strcpy(thisDetector->receiverUDPIP,temp.c_str()); strcpy(thisDetector->receiverUDPIP,thisDetector->receiver_hostname);
temp = genericSocket::nameToMac(genericSocket::ipToName(temp)); //if hostname not ip, convert it to ip
strcpy(thisDetector->receiverUDPMAC,temp.c_str()); else{
}else{ struct hostent *he = gethostbyname(thisDetector->receiver_hostname);
//hostname is an ip address if (he == NULL){
if(strchr(thisDetector->receiver_hostname,'.')!=NULL) std::cout << "no rx_udpip given and could not convert receiver hostname to ip" << endl;
strcpy(thisDetector->receiverUDPIP,thisDetector->receiver_hostname); return FAIL;
//if hostname not ip, convert it to ip }else
else{ strcpy(thisDetector->receiverUDPIP,inet_ntoa(*(struct in_addr*)he->h_addr));
struct hostent *he = gethostbyname(thisDetector->receiver_hostname);
if (he == NULL){
std::cout << "no rx_udpip given and could not convert receiver hostname to ip" << endl;
return FAIL;
}else
strcpy(thisDetector->receiverUDPIP,inet_ntoa(*(struct in_addr*)he->h_addr));
}
} }
} }
@ -4635,39 +4628,32 @@ int slsDetector::setUDPConnection(){
//copy arguments to args[][] //copy arguments to args[][]
strcpy(args[0],thisDetector->receiverUDPIP); strcpy(args[0],thisDetector->receiverUDPIP);
sprintf(args[1],"%d",thisDetector->receiverUDPPort); sprintf(args[1],"%d",thisDetector->receiverUDPPort);
#ifdef VERBOSE
std::cout << "Receiver ip address: " << thisDetector->receiverUDPIP << std::endl;
#endif
//set up receiver for UDP Connection and get receivermac address //set up receiver for UDP Connection and get receivermac address
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "Setting up UDP Connection for Receiver " << args[0] << "\t" << args[1] << std::endl; std::cout << "Setting up UDP Connection for Receiver " << args[0] << "\t" << args[1] << std::endl;
#endif #endif
//already have mac address if localhost ret=thisReceiver->sendUDPDetails(fnum,retval,args);
if(!strcmp(thisDetector->receiver_hostname,"localhost")) if(ret!=FAIL){
ret=OK; strcpy(thisDetector->receiverUDPMAC,retval);
//get mac address from receiver
else{
ret=thisReceiver->sendUDPDetails(fnum,retval,args);
if(ret!=FAIL){
strcpy(thisDetector->receiverUDPMAC,retval);
}
if(ret==FORCE_UPDATE)
updateReceiver();
}
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "Receiver mac address: " << thisDetector->receiverUDPMAC << std::endl; std::cout << "Receiver mac address: " << thisDetector->receiverUDPMAC << std::endl;
#endif #endif
if(ret==FORCE_UPDATE)
updateReceiver();
//configure detector with udp details //configure detector with udp details
if(ret!=FAIL){ if(configureMAC()!=OK){
if(configureMAC()!=OK){ setReceiverOnline(OFFLINE_FLAG);
setReceiverOnline(OFFLINE_FLAG); std::cout << "could not configure mac" << endl;
std::cout << "could not configure mac" << endl;
}
} }
}
}else{ }else{
ret=FAIL; ret=FAIL;
std::cout << "cannot connect to receiver" << endl; std::cout << "cannot connect to receiver" << endl;
@ -4689,27 +4675,19 @@ int slsDetector::configureMAC(int adc){
//if udpip wasnt initialized in config file //if udpip wasnt initialized in config file
if(!(strcmp(thisDetector->receiverUDPIP,"none"))){ if(!(strcmp(thisDetector->receiverUDPIP,"none"))){
//if localhost //hostname is an ip address
if(!strcmp(thisDetector->receiver_hostname,"localhost")){ if(strchr(thisDetector->receiver_hostname,'.')!=NULL)
string temp = genericSocket::ipToName("localhost"); strcpy(thisDetector->receiverUDPIP,thisDetector->receiver_hostname);
strcpy(thisDetector->receiverUDPIP,temp.c_str()); //if hostname not ip, convert it to ip
temp = genericSocket::nameToMac(genericSocket::ipToName(temp)); else{
strcpy(thisDetector->receiverUDPMAC,temp.c_str()); struct hostent *he = gethostbyname(thisDetector->receiver_hostname);
}else{ if (he != NULL)
//hostname is an ip address strcpy(thisDetector->receiverUDPIP,inet_ntoa(*(struct in_addr*)he->h_addr));
if(strchr(thisDetector->receiver_hostname,'.')!=NULL) else{
strcpy(thisDetector->receiverUDPIP,thisDetector->receiver_hostname); std::cout << "no rx_udpip given and invalid receiver hostname" << endl;
//if hostname not ip, convert it to ip return FAIL;
else{ }
struct hostent *he = gethostbyname(thisDetector->receiver_hostname); }
if (he != NULL)
strcpy(thisDetector->receiverUDPIP,inet_ntoa(*(struct in_addr*)he->h_addr));
else{
std::cout << "no rx_udpip given and invalid receiver hostname" << endl;
return FAIL;
}
}
}
} }
strcpy(arg[0],thisDetector->receiverUDPIP); strcpy(arg[0],thisDetector->receiverUDPIP);
strcpy(arg[1],thisDetector->receiverUDPMAC); strcpy(arg[1],thisDetector->receiverUDPMAC);