示例#1
0
文件: Recv.c 项目: chyileon/iie_leon
void recv_departure(){
	sleep(2);
	printf("recv_departure\n");
	char tmp[200];
    char packet[MAX_PACKET_LEN];
    int len;
    int i=0;
    int j=0;
    struct sockaddr_in addr;
    size_t addrlen;
    memset(tmp,0,sizeof(tmp));
    while(1){
		if( (len=recvfrom(sockfd, packet, MAX_PACKET_LEN, 0, (struct sockaddr *)&addr, &addrlen))<0 ){
			perror("recv---recvfrom.");
			printf("errno:%d\n",errno);
		}
		else{
			strcpy(tmp, inet_ntoa(addr.sin_addr));
			if(strcmp(HOSTIP,tmp)!=0){//filter out the broadcast packets from itself.

			    int ID=0;
			    int tmplen = strlen(tmp);
			    for(i=tmplen-1,j=1; i>=0; i--){
					if(tmp[i]=='.')
					    break;
					else{
						ID=ID+(tmp[i]-'0')*j;
					}
					j=j*10;
				}

				if(ID!=0){//recv an broadcast packets
			        printf("recv---recvfrom %s:len=%d msg=%x\n",tmp,len,packet[1]);
			        pthread_mutex_lock( &recv_mutex);

			        updateRouter(ID, packet+1,len-1,neighbourRR);
                    recvCounter[ID]++;

                    pthread_mutex_unlock( &recv_mutex);
				}
			}
		}
	}
}
示例#2
0
void StandAloneUpdateRouting (DAL_RATE_MODE_ENUM rate_mode)
{
	updateRouter (stdAloneRouting, sizeof(stdAloneRouting)/sizeof(uint16));
}