void belle_sip_channel_connect(belle_sip_channel_t *obj){ char ip[64]; channel_set_state(obj,BELLE_SIP_CHANNEL_CONNECTING); belle_sip_addrinfo_to_ip(obj->current_peer,ip,sizeof(ip),NULL); belle_sip_message("Trying to connect to [%s://%s:%i]",belle_sip_channel_get_transport_name(obj),ip,obj->peer_port); if(BELLE_SIP_OBJECT_VPTR(obj,belle_sip_channel_t)->connect(obj,obj->current_peer)) { belle_sip_error("Cannot connect to [%s://%s:%i]",belle_sip_channel_get_transport_name(obj),obj->peer_name,obj->peer_port); channel_set_state(obj,BELLE_SIP_CHANNEL_ERROR); } return; }
/*constructor for channels created by incoming connections*/ void belle_sip_channel_init_with_addr(belle_sip_channel_t *obj, belle_sip_stack_t *stack, const struct sockaddr *peer_addr, socklen_t addrlen){ char remoteip[64]; struct addrinfo ai; int peer_port; memset(&ai,0,sizeof(ai)); ai.ai_family=peer_addr->sa_family; ai.ai_addr=(struct sockaddr*)peer_addr; ai.ai_addrlen=addrlen; belle_sip_addrinfo_to_ip(&ai,remoteip,sizeof(remoteip),&peer_port); belle_sip_channel_init(obj,stack,NULL,0,NULL,remoteip,peer_port); obj->peer_list=obj->current_peer=belle_sip_ip_address_to_addrinfo(ai.ai_family, obj->peer_name,obj->peer_port); obj->ai_family=ai.ai_family; }
int liblinphone_tester_ipv6_available(void){ struct addrinfo *ai=belle_sip_ip_address_to_addrinfo(AF_INET6,"2a01:e00::2",53); if (ai){ struct sockaddr_storage ss; struct addrinfo src; socklen_t slen=sizeof(ss); char localip[128]; int port=0; belle_sip_get_src_addr_for(ai->ai_addr,ai->ai_addrlen,(struct sockaddr*) &ss,&slen,4444); src.ai_addr=(struct sockaddr*) &ss; src.ai_addrlen=slen; belle_sip_addrinfo_to_ip(&src,localip, sizeof(localip),&port); freeaddrinfo(ai); return strcmp(localip,"::1")!=0; } return FALSE; }
void belle_sip_channel_connect(belle_sip_channel_t *obj){ char ip[64]; int port=obj->peer_port; channel_set_state(obj,BELLE_SIP_CHANNEL_CONNECTING); belle_sip_addrinfo_to_ip(obj->current_peer,ip,sizeof(ip),&port); /* update peer_port as it may have been overriden by SRV resolution*/ if (port!=obj->peer_port){ /*the SRV resolution provided a port number that must be used*/ obj->srv_overrides_port=TRUE; obj->peer_port=port; } belle_sip_message("Trying to connect to [%s://%s:%i]",belle_sip_channel_get_transport_name(obj),ip,obj->peer_port); if(BELLE_SIP_OBJECT_VPTR(obj,belle_sip_channel_t)->connect(obj,obj->current_peer)) { belle_sip_error("Cannot connect to [%s://%s:%i]",belle_sip_channel_get_transport_name(obj),obj->peer_name,obj->peer_port); channel_set_state(obj,BELLE_SIP_CHANNEL_ERROR); } return; }