2010-11-04 12:59:18| 分类: 默认分类 | 标签: |字号大中小 订阅
//============= 根据域名获取服务器IP 地址 ====================
void web_socket_get_host_dns_event(void * inMsg)
{
app_soc_get_host_by_name_ind_struct * dns_ind;
if (inMsg)
{
dns_ind = (app_soc_get_host_by_name_ind_struct * )inMsg;
if (dns_ind->result == KAL_TRUE)
{
Gm_Meter_Debug("ngncb-> web_socket_get_host_dns_event dns_ind->request_id ",(int)dns_ind->request_id,NULL);
if (dns_ind->request_id == (kal_int32)MF_DNS_APPID)
{
ClearProtocolEventHandler(MSG_ID_APP_SOC_GET_HOST_BY_NAME_IND);
web_sock.sock_addr.addr[0] = dns_ind->addr[0];
web_sock.sock_addr.addr[1] = dns_ind->addr[1];
web_sock.sock_addr.addr[2] = dns_ind->addr[2];
web_sock.sock_addr.addr[3] = dns_ind->addr[3];
Gm_Meter_Debug("ngncb-> web_socket_get_host ip 0 ",(int)dns_ind->addr[0],NULL);
Gm_Meter_Debug("ngncb-> web_socket_get_host ip 1 ",(int)dns_ind->addr[1],NULL);
Gm_Meter_Debug("ngncb-> web_socket_get_host ip 2 ",(int)dns_ind->addr[2],NULL);
Gm_Meter_Debug("ngncb-> web_socket_get_host ip 3 ",(int)dns_ind->addr[3],NULL);
web_socket_connect();
}
}
}
}
void web_socket_get_host(void)
{
S8 ret = 0;
U8 * ptr;
static U8 addr_len = 0;
static S32 sDNSHandler = MF_DNS_APPID;
static U32 ipAddr;
static S8 server_domain[] = "www.ngncb.com";
Gm_Meter_Debug("ngncb-> web_socket_get_host ",NULL,NULL);
memset(&web_sock.sock_addr, 0, sizeof(sockaddr_struct));
web_sock.sock_addr.addr_len = 4;
web_sock.sock_addr.port = 80;
web_sock.sock_addr.sock_type = SOC_SOCK_STREAM;
ret = soc_gethostbyname(
(kal_bool)KAL_FALSE,
(module_type)MOD_MMI,
(kal_int32)sDNSHandler,
(const kal_char *)server_domain,
(kal_uint8 *)&ipAddr,
(kal_uint8 *)&addr_len,
(kal_uint8)0,
(kal_uint32)GM_METER_NWK_ACCOUNT_ID
);
if (ret == SOC_SUCCESS)
{
ptr = (kal_uint8*)&ipAddr;
//printf("web_socket_dns_event ip: %d, %d, %d, %d\n", ptr[0], ptr[1], ptr[2], ptr[3]);
Gm_Meter_Debug("ngncb-> web_socket_get_host ip 0 ",(int)ptr[0],NULL);
Gm_Meter_Debug("ngncb-> web_socket_get_host ip 1 ",(int)ptr[1],NULL);
Gm_Meter_Debug("ngncb-> web_socket_get_host ip 2 ",(int)ptr[2],NULL);
Gm_Meter_Debug("ngncb-> web_socket_get_host ip 3 ",(int)ptr[3],NULL);
web_sock.sock_addr.addr[0] = ptr[0];
web_sock.sock_addr.addr[1] = ptr[1];
web_sock.sock_addr.addr[2] = ptr[2];
web_sock.sock_addr.addr[3] = ptr[3];
web_socket_connect();
}
else if (ret == SOC_WOULDBLOCK)
{
Gm_Meter_Debug("ngncb-> web_socket_get_host SetProtocolEventHandler ",NULL,NULL);
SetProtocolEventHandler(web_socket_get_host_dns_event, MSG_ID_APP_SOC_GET_HOST_BY_NAME_IND);
}
else
{
Gm_Meter_Debug("ngncb-> web_socket_get_host do nothing",NULL,NULL);
}
}
联系客服