예제 #1
0
파일: misc.c 프로젝트: korobool/liblinphone
int parse_hostname_to_addr(const char *server, struct sockaddr_storage *ss, socklen_t *socklen, int default_port){
	struct addrinfo hints,*res=NULL;
	char port[6];
	char host[NI_MAXHOST];
	int port_int=default_port;
	int ret;
	
	linphone_parse_host_port(server,host,sizeof(host),&port_int);
	
	snprintf(port, sizeof(port), "%d", port_int);
	memset(&hints,0,sizeof(hints));
	hints.ai_family=AF_UNSPEC;
	hints.ai_socktype=SOCK_DGRAM;
	hints.ai_protocol=IPPROTO_UDP;
	ret=getaddrinfo(host,port,&hints,&res);
	if (ret!=0){
		ms_error("getaddrinfo() failed for %s:%s : %s",host,port,gai_strerror(ret));
		return -1;
	}
	if (!res) return -1;
	memcpy(ss,res->ai_addr,res->ai_addrlen);
	*socklen=res->ai_addrlen;
	freeaddrinfo(res);
	return 0;
}
예제 #2
0
파일: misc.c 프로젝트: korobool/liblinphone
void linphone_core_resolve_stun_server(LinphoneCore *lc){
	/*
	 * WARNING: stun server resolution only done in IPv4.
	 * TODO: use IPv6 resolution if linphone_core_ipv6_enabled()==TRUE and use V4Mapped addresses for ICE gathering.
	 */
	const char *server=lc->net_conf.stun_server;
	if (lc->sal && server){
		char host[NI_MAXHOST];
		int port=3478;
		linphone_parse_host_port(server,host,sizeof(host),&port);
		lc->net_conf.stun_res=sal_resolve_a(lc->sal,host,port,AF_INET,(SalResolverCallback)stun_server_resolved,lc);
	}
}
예제 #3
0
파일: nat_policy.c 프로젝트: 42p/linphone
void linphone_nat_policy_resolve_stun_server(LinphoneNatPolicy *policy) {
	const char *service = NULL;

	/*
	 * WARNING: stun server resolution only done in IPv4.
	 * TODO: use IPv6 resolution if linphone_core_ipv6_enabled()==TRUE and use V4Mapped addresses for ICE gathering.
	 */
	if (linphone_nat_policy_stun_server_activated(policy)
		&& (policy->lc->sal != NULL)
		&& !policy->stun_resolver_context) {
		char host[NI_MAXHOST];
		int port = 3478;
		linphone_parse_host_port(policy->stun_server, host, sizeof(host), &port);
		if (linphone_nat_policy_turn_enabled(policy)) service = "turn";
		else if (linphone_nat_policy_stun_enabled(policy)) service = "stun";
		if (service != NULL) {
			policy->stun_resolver_context = sal_resolve(policy->lc->sal, service, "udp", host, port, AF_INET, (SalResolverCallback)stun_server_resolved, policy);
		}
	}
}