示例#1
0
void pthread_server(int* p_listen_fd)
{
	int conn_fd;
	pthread_t tid[T_MAX];

	DBG("\n serverThread begin!!! \n");
	int i=0;
	while(1)
	{
		struct sockaddr_in rsin;
		socklen_t address_size;
		address_size=sizeof(rsin);
		conn_fd = accept(*p_listen_fd, (struct sockaddr *)&rsin, &address_size);
		DBG("\nnew client is add!\n");
		CLIENT_NODE* new_client = (CLIENT_NODE*)malloc(sizeof(CLIENT_NODE));
		new_client->sockfd = conn_fd;
		new_client->alive = 1;		
		new_client->no_check_in = 0;
		send(conn_fd, "connect success\n", strlen("connect success\n"), 0);
		strcpy(new_client->client_name, "unname");
		new_client->next = NULL;
		client_insert(head, new_client);

		pthread_create(&tid[i], NULL, (void*)pthread_receive_from_client, new_client);
		i++;
	}
}
示例#2
0
int duplicate(struct params *p, struct ieee80211_frame *wh, int rc)
{
	struct client *c;
	int s;

	if (!frame_type(wh, IEEE80211_FC0_TYPE_DATA,
			IEEE80211_FC0_SUBTYPE_DATA))
		return 0;

	s = seqno(wh);

	c = client_find(p, wh->i_addr2);
	if (!c) {
		c = malloc(sizeof(*c));
		if (!c)
			err(1, "malloc()");

		memset(c, 0, sizeof(*c));
		memcpy(c->mac, wh->i_addr2, 6);

		c->seq = s-1;
		client_insert(p, c);
	}

	if (wh->i_fc[1] & IEEE80211_FC1_RETRY) {
		if ( (s <= c->seq) && ((c->seq - s ) < 5)) {
#if 0
			printf("Dup seq %d prev %d\n",
			       s, c->seq);
#endif
			return 1;
		}	
	}	

#if 0
	do {
		char mac[3*6];

		mac2str(mac, c->mac);
		printf("%s seq %d prev %d\n", mac, s, c->seq);
	} while (0);
#endif
	
	c->seq = s;
	return 0;
}