while(1){
fd_set rfd,xfd;
int sret;
+ struct timeval tv;
//wait for event
FD_ZERO(&rfd);
FD_ZERO(&xfd);
FD_SET(sockfd,&rfd);
FD_SET(sockfd,&xfd);
- sret=select(sockfd+1,&rfd,0,&xfd,0);
+ tv.tv_sec=1;tv.tv_usec=0;
+ sret=select(sockfd+1,&rfd,0,&xfd,&tv);
//check for errors
if(sret<0){
int e=errno;
if(e==EAGAIN)continue;
- td_log(LOGERROR,"Error caught: %s\n",strerror(e));
+ td_log(LOGERROR,"Error caught: %s",strerror(e));
return 1;
}
//check for event
handlemessage(msg2);
}
if(FD_ISSET(sockfd,&xfd)){
- td_log(LOGERROR,"Exception on socket caught.\n");
+ td_log(LOGERROR,"Exception on socket caught.");
return 1;
}
}
+ //check that the interface still exists
+ if(!checkiface()){
+ td_log(LOGERROR,"Interface lost, exiting.");
+ return 1;
+ }
}
/*should not be reachable*/
td_log(LOGDEBUG,"hmm, Konrad needs better coffee - this line should not be reachable");
freeifaddrs(ifa);
}
+int checkiface()
+{
+ struct ifreq ifr;
+ //sanity check
+ if(ifindex<0 || sockfd<0)return 0;
+ //try to find the iface
+ Memzero(&ifr,sizeof(ifr));
+ ifr.ifr_ifindex=ifindex;
+ if(ioctl(sockfd,SIOCGIFNAME,&ifr)<0){
+ return 0;
+ }
+ return 1;
+}
+
/*initializes the socket on port*/
void initsocket(short port,const char*dev)
{
/*joins DHCP multicast group*/
void joindhcp();
+/*checks that the interface still exists; returns true if found*/
+int checkiface();
+
/*set the server multicast as target*/
struct sockaddr_in6;
void settargetserver(struct sockaddr_in6*);