static cmm_error_t cnt_update_dns() { int i; cnt_entry_t *node; for (i=0; i<cnt_table.nb_nodes; i++) { node = cnt_table.nodes[i]; if ( GetHostAddress( node->unix_name, RING_PORT, &(node->net_addr) ) != 1 ) { cm_trace(CM_TRACE_LEVEL_ERROR, "GetHostAddress failed for node %s", node->unix_name ); return( CMM_EOTHER ); } /* Update the addr field */ get_ip_from_hostname( node->unix_name, node->member.addr ); cm_trace(CM_TRACE_LEVEL_DEBUG, "Updated the DNS entry for %s. IP address is %s", node->unix_name, node->member.addr ); } cm_trace(CM_TRACE_LEVEL_DEBUG, "The DNS entries have been found successfully" ); return(CMM_OK); }
int set_slave_name_servers(dnsa_config_s *dc, dnsa_comm_line_s *cm, dbdata_s *data) { int retval = 0; if ((retval = get_ip_from_hostname(data)) != 0) return retval; snprintf(dc->secns, RBUFF_S, "%s", data->fields.text); snprintf(dc->prins, RBUFF_S, "%s", cm->host); return retval; }
void handle_client(int client_fd, char *ip, short port) { irc_data_t irc_channels; char buf[MAX_CLIENT_SEND_BUFF_SZ]; int retn = 0; irc_init(&irc_channels); if (0 != get_ip_from_hostname(ip, buf, sizeof(buf))) { perror("get ip from host error\n"); goto err; } printf("connect to irc server: %s[%s] %d\n", ip, buf, port); irc_channels.socket_fd = create_client_socket(buf, port); if (0 > irc_channels.socket_fd) { goto err; } if (0 != pthread_create(&irc_channels.thread_recv, NULL , thread_recv_msg_from_server, &irc_channels)) { perror("create recv thread error!"); goto err; } if (0 != pthread_create(&irc_channels.thread_send, NULL , thread_send_msg_to_server, &irc_channels)) { perror("create send thread error!"); goto err; } for(;;) { retn = recv(client_fd, buf, sizeof(buf) - 1, 0); if (retn > 0) { buf[retn - 1] = '\0'; fprintf(stdout, "[local-client]: recv: %s\n",buf); handle_msg_remove_illegal_ch(buf, retn); handle_msg_from_client(&irc_channels, buf, retn - 1); } else if (0 == retn) { fprintf(stdout, "client offline"); break; } else { fprintf(stderr, "client error"); break; } } err: close(client_fd); irc_free(&irc_channels); }
/** * Handle GET-message. * * @param cls closure * @param client identification of the client * @param message the actual message */ static void handle_get (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { uint16_t msize; const struct GNUNET_RESOLVER_GetMessage *msg; const void *ip; uint16_t size; int direction; int af; msize = ntohs (message->size); if (msize < sizeof (struct GNUNET_RESOLVER_GetMessage)) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } msg = (const struct GNUNET_RESOLVER_GetMessage *) message; size = msize - sizeof (struct GNUNET_RESOLVER_GetMessage); direction = ntohl (msg->direction); af = ntohl (msg->af); if (GNUNET_NO == direction) { /* IP from hostname */ const char *hostname; hostname = (const char *) &msg[1]; if (hostname[size - 1] != '\0') { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Resolver asked to look up `%s'.\n", hostname); get_ip_from_hostname (client, hostname, af); return; } ip = &msg[1]; switch (af) { case AF_INET: if (size != sizeof (struct in_addr)) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } break; case AF_INET6: if (size != sizeof (struct in6_addr)) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } break; default: GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } { char buf[INET6_ADDRSTRLEN]; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Resolver asked to look up IP address `%s'.\n", inet_ntop (af, ip, buf, sizeof (buf))); } get_ip_as_string (client, af, ip); }
static void call_with_tunnel_base(LinphoneTunnelMode tunnel_mode, bool_t with_sip, LinphoneMediaEncryption encryption, bool_t with_video_and_ice) { if (linphone_core_tunnel_available()){ LinphoneCoreManager *pauline = linphone_core_manager_new( "pauline_rc"); LinphoneCoreManager *marie = linphone_core_manager_new( "marie_rc"); LinphoneCall *pauline_call, *marie_call; LinphoneProxyConfig *proxy = linphone_core_get_default_proxy_config(pauline->lc); LinphoneAddress *server_addr = linphone_address_new(linphone_proxy_config_get_server_addr(proxy)); LinphoneAddress *route = linphone_address_new(linphone_proxy_config_get_route(proxy)); const char * tunnel_ip = get_ip_from_hostname("tunnel.linphone.org"); char *public_ip, *public_ip2=NULL; BC_ASSERT_TRUE(wait_for(pauline->lc,NULL,&pauline->stat.number_of_LinphoneRegistrationOk,1)); public_ip = get_public_contact_ip(pauline->lc); BC_ASSERT_STRING_NOT_EQUAL(public_ip, tunnel_ip); linphone_core_set_media_encryption(pauline->lc, encryption); if (with_video_and_ice){ /*we want to test that tunnel is able to work with long SIP message, above mtu. * Enable ICE and many codec to make the SIP message bigger*/ linphone_core_set_firewall_policy(marie->lc, LinphonePolicyUseIce); linphone_core_set_firewall_policy(pauline->lc, LinphonePolicyUseIce); linphone_core_enable_payload_type(pauline->lc, linphone_core_find_payload_type(pauline->lc, "speex", 32000, 1), TRUE); linphone_core_enable_payload_type(pauline->lc, linphone_core_find_payload_type(pauline->lc, "speex", 16000, 1), TRUE); linphone_core_enable_payload_type(pauline->lc, linphone_core_find_payload_type(pauline->lc, "G722", 8000, 1), TRUE); linphone_core_enable_payload_type(marie->lc, linphone_core_find_payload_type(marie->lc, "speex", 32000, 1), TRUE); linphone_core_enable_payload_type(marie->lc, linphone_core_find_payload_type(marie->lc, "speex", 16000, 1), TRUE); linphone_core_enable_payload_type(marie->lc, linphone_core_find_payload_type(marie->lc, "G722", 8000, 1), TRUE); } if (tunnel_mode != LinphoneTunnelModeDisable){ LinphoneTunnel *tunnel = linphone_core_get_tunnel(pauline->lc); LinphoneTunnelConfig *config = linphone_tunnel_config_new(); linphone_tunnel_config_set_host(config, "tunnel.linphone.org"); linphone_tunnel_config_set_port(config, 443); linphone_tunnel_config_set_remote_udp_mirror_port(config, 12345); linphone_tunnel_add_server(tunnel, config); linphone_tunnel_set_mode(tunnel, tunnel_mode); linphone_tunnel_enable_sip(tunnel, with_sip); /* * Enabling the tunnel with sip cause another REGISTER to be made. * In automatic mode, the udp test should conclude (assuming we have a normal network), that no * tunnel is needed. Thus the number of registrations should stay to 1. * The library is missing a notification of "tunnel connectivity test finished" to enable the * full testing of the automatic mode. */ if (tunnel_mode == LinphoneTunnelModeEnable && with_sip) { BC_ASSERT_TRUE(wait_for(pauline->lc,NULL,&pauline->stat.number_of_LinphoneRegistrationOk,2)); /* Ensure that we did use the tunnel. If so, we should see contact changed from: Contact: <sip:[email protected]>;.[...] To: Contact: <sip:[email protected]:43867>;[....] (91.121.209.194 must be tunnel.liphone.org) */ ms_free(public_ip); public_ip = get_public_contact_ip(pauline->lc); BC_ASSERT_STRING_EQUAL(public_ip, tunnel_ip); } else { public_ip2 = get_public_contact_ip(pauline->lc); BC_ASSERT_STRING_EQUAL(public_ip, public_ip2); } } BC_ASSERT_TRUE(call(pauline,marie)); pauline_call=linphone_core_get_current_call(pauline->lc); BC_ASSERT_PTR_NOT_NULL(pauline_call); if (pauline_call!=NULL){ BC_ASSERT_PTR_EQUAL(linphone_call_params_get_media_encryption(linphone_call_get_current_params(pauline_call)), encryption); } if (tunnel_mode == LinphoneTunnelModeEnable && with_sip){ /* make sure the call from pauline arrived from the tunnel by checking the contact address*/ marie_call = linphone_core_get_current_call(marie->lc); BC_ASSERT_PTR_NOT_NULL(marie_call); if (marie_call){ const char *remote_contact = linphone_call_get_remote_contact(marie_call); BC_ASSERT_PTR_NOT_NULL(remote_contact); if (remote_contact){ LinphoneAddress *tmp = linphone_address_new(remote_contact); BC_ASSERT_PTR_NOT_NULL(tmp); if (tmp){ BC_ASSERT_STRING_EQUAL(linphone_address_get_domain(tmp), tunnel_ip); linphone_address_destroy(tmp); } } } } #ifdef VIDEO_ENABLED if (with_video_and_ice){ BC_ASSERT_TRUE(add_video(pauline, marie, TRUE)); } #endif end_call(pauline,marie); ms_free(public_ip); if(public_ip2 != NULL) ms_free(public_ip2); linphone_address_destroy(server_addr); linphone_address_destroy(route); linphone_core_manager_destroy(pauline); linphone_core_manager_destroy(marie); }else{ ms_warning("Could not test %s because tunnel functionality is not available",__FUNCTION__); } }
static void call_with_transport_base(LinphoneTunnelMode tunnel_mode, bool_t with_sip, LinphoneMediaEncryption encryption) { if (linphone_core_tunnel_available()){ LinphoneCoreManager *pauline = linphone_core_manager_new( "pauline_rc"); LinphoneCoreManager *marie = linphone_core_manager_new( "marie_rc"); LinphoneCall *pauline_call; LinphoneProxyConfig *proxy = linphone_core_get_default_proxy_config(pauline->lc); LinphoneAddress *server_addr = linphone_address_new(linphone_proxy_config_get_server_addr(proxy)); LinphoneAddress *route = linphone_address_new(linphone_proxy_config_get_route(proxy)); const char * tunnel_ip = get_ip_from_hostname("tunnel.linphone.org"); char *public_ip, *public_ip2=NULL; CU_ASSERT_TRUE(wait_for(pauline->lc,NULL,&pauline->stat.number_of_LinphoneRegistrationOk,1)); public_ip = get_public_contact_ip(pauline->lc); CU_ASSERT_STRING_NOT_EQUAL(public_ip, tunnel_ip); linphone_core_set_media_encryption(pauline->lc, encryption); if (tunnel_mode != LinphoneTunnelModeDisable){ LinphoneTunnel *tunnel = linphone_core_get_tunnel(pauline->lc); LinphoneTunnelConfig *config = linphone_tunnel_config_new(); linphone_tunnel_config_set_host(config, "tunnel.linphone.org"); linphone_tunnel_config_set_port(config, 443); linphone_tunnel_config_set_remote_udp_mirror_port(config, 12345); linphone_tunnel_add_server(tunnel, config); linphone_tunnel_set_mode(tunnel, tunnel_mode); linphone_tunnel_enable_sip(tunnel, with_sip); /* * Enabling the tunnel with sip cause another REGISTER to be made. * In automatic mode, the udp test should conclude (assuming we have a normal network), that no * tunnel is needed. Thus the number of registrations should stay to 1. * The library is missing a notification of "tunnel connectivity test finished" to enable the * full testing of the automatic mode. */ if(tunnel_mode == LinphoneTunnelModeEnable && with_sip) { CU_ASSERT_TRUE(wait_for(pauline->lc,NULL,&pauline->stat.number_of_LinphoneRegistrationOk,2)); /* Ensure that we did use the tunnel. If so, we should see contact changed from: Contact: <sip:[email protected]>;.[...] To: Contact: <sip:[email protected]:43867>;[....] (91.121.209.194 must be tunnel.liphone.org) */ ms_free(public_ip); public_ip = get_public_contact_ip(pauline->lc); CU_ASSERT_STRING_EQUAL(public_ip, tunnel_ip); } else { public_ip2 = get_public_contact_ip(pauline->lc); CU_ASSERT_STRING_EQUAL(public_ip, public_ip2); } } CU_ASSERT_TRUE(call(pauline,marie)); pauline_call=linphone_core_get_current_call(pauline->lc); CU_ASSERT_PTR_NOT_NULL(pauline_call); if (pauline_call!=NULL){ CU_ASSERT_EQUAL(linphone_call_params_get_media_encryption(linphone_call_get_current_params(pauline_call)), encryption); } end_call(pauline,marie); ms_free(public_ip); if(public_ip2 != NULL) ms_free(public_ip2); linphone_address_destroy(server_addr); linphone_address_destroy(route); linphone_core_manager_destroy(pauline); linphone_core_manager_destroy(marie); }else{ ms_warning("Could not test %s because tunnel functionality is not available",__FUNCTION__); } }