metartc5_jz源码阅读-g_yang_ice_stun_receive

//收到stun服务器的返回数据
void g_yang_ice_stun_receive(char *data, int32_t size, void *user) {
	if (user == NULL)		return;
	//拿到请求的StunRequest
	YangIceStunRequest* request=(YangIceStunRequest*)user;

	//0x00或0x01为stun返回数据的起始标记。
	uint8_t bt=(uint8_t)data[0];
	if(size>0&&(bt==0x00||bt==0x01)){
		int32_t err = 0;

		//decode Stun服务器返回的data,放到response中,如果decode失败直接返回。
		YangStunPacket response;
		memset(&response,0,sizeof(YangStunPacket));
		if ((err = request->stun->decodeStunServer(&response,data, size)) != 0) {
            yang_error("decode stun packet failed");
			return;
		}

		//从response中取出ip地址和端口号,这是拿到了公网ip地址用于p2p打洞
		request->ip= yang_get_be32((uint8_t*)(&response.mapped_address));
		request->port=response.mapped_port;

		request->response=yangtrue;
		uint8_t* ip=(uint8_t*)&request->ip;
		yang_trace("\nstun ip=%u.%u.%u.%u,stun port=%d",ip[0],ip[1],ip[2],ip[3],request->port);
	}

}

你可能感兴趣的:(metartc5_jz源码阅读,音视频,c语言,p2p,实时音视频)