int WAsyncSocket::Connect(char *host,unsigned int port) { m_port=port; // Check to see if we need to get the ip address from the host address bool is_ip_string=false; unsigned int ip_int[4]; if(sscanf(host,"%u.%u.%u.%u",&ip_int[0],&ip_int[1],&ip_int[2],&ip_int[3])==4) { is_ip_string=true; } // If this is not an ip string we are connecting to, then resolve the hosts ip address from the DNS if(is_ip_string==false) { WSAAsyncGetHostByName(m_hwnd,WM_GOT_HOST_BY_NAME_MESSAGE,host,m_hostent_buf,sizeof(m_hostent_buf)); } else // it is just an IP { unsigned long ip_addr=inet_addr(host); WSAAsyncGetHostByAddr(m_hwnd,WM_GOT_HOST_BY_ADDRESS_MESSAGE,(char *)&ip_addr,sizeof(unsigned long),AF_INET, m_hostent_buf,sizeof(m_hostent_buf)); } return 0; }
*/ DEVICE_CMD Read_DNS(REBREQ *sock) /* ** Initiate the GetHost request and return immediately. ** Note the temporary results buffer (must be freed later). ** ***********************************************************************/ { void *host; #ifdef HAS_ASYNC_DNS HANDLE handle; #else HOSTENT *he; #endif host = OS_Make(MAXGETHOSTSTRUCT); // be sure to free it #ifdef HAS_ASYNC_DNS if (!GET_FLAG(sock->modes, RST_REVERSE)) // hostname lookup handle = WSAAsyncGetHostByName(Event_Handle, WM_DNS, sock->data, host, MAXGETHOSTSTRUCT); else handle = WSAAsyncGetHostByAddr(Event_Handle, WM_DNS, (char*)&(sock->net.remote_ip), 4, AF_INET, host, MAXGETHOSTSTRUCT); if (handle != 0) { sock->net.host_info = host; sock->handle = handle; return DR_PEND; // keep it on pending list } #else // Use old-style blocking DNS (mainly for testing purposes): if (GET_FLAG(sock->modes, RST_REVERSE)) { he = gethostbyaddr((char*)&sock->net.remote_ip, 4, AF_INET); if (he) { sock->net.host_info = host; //??? sock->data = he->h_name; SET_FLAG(sock->flags, RRF_DONE); return DR_DONE; } } else { he = gethostbyname(sock->data); if (he) { sock->net.host_info = host; // ?? who deallocs? COPY_MEM((char*)&(sock->net.remote_ip), (char *)(*he->h_addr_list), 4); //he->h_length); SET_FLAG(sock->flags, RRF_DONE); return DR_DONE; } } #endif OS_Free(host); sock->net.host_info = 0; sock->error = GET_ERROR; //Signal_Device(sock, EVT_ERROR); return DR_ERROR; // Remove it from pending list }
/* this is executed in our thread, actually */ HANDLE StartAsyncNameLookup(char *peer_addr,char *buf) { HANDLE ret_val; ret_val = WSAAsyncGetHostByAddr(hwndMain,WM_BLAK_SOCKET_NAME_LOOKUP, peer_addr,4,PF_INET,buf,MAXGETHOSTSTRUCT); if (ret_val == 0) eprintf("StartAsyncNameLookup got error %s\n",GetLastErrorStr()); return ret_val; }
*/ DEVICE_CMD Read_DNS(REBREQ *sock) /* ** Initiate the GetHost request and return immediately. ** Note the temporary results buffer (must be freed later). ** ***********************************************************************/ { char *host; #ifdef HAS_ASYNC_DNS HANDLE handle; #else HOSTENT *he; #endif host = OS_ALLOC_ARRAY(char, MAXGETHOSTSTRUCT); // be sure to free it #ifdef HAS_ASYNC_DNS if (!GET_FLAG(sock->modes, RST_REVERSE)) // hostname lookup handle = WSAAsyncGetHostByName(Event_Handle, WM_DNS, s_cast(sock->common.data), host, MAXGETHOSTSTRUCT); else handle = WSAAsyncGetHostByAddr(Event_Handle, WM_DNS, s_cast(&sock->special.net.remote_ip), 4, AF_INET, host, MAXGETHOSTSTRUCT); if (handle != 0) { sock->special.net.host_info = host; sock->requestee.handle = handle; return DR_PEND; // keep it on pending list } #else // Use old-style blocking DNS (mainly for testing purposes): if (GET_FLAG(sock->modes, RST_REVERSE)) { he = gethostbyaddr( cast(char*, &sock->special.net.remote_ip), 4, AF_INET ); if (he) { sock->special.net.host_info = host; //??? sock->common.data = b_cast(he->h_name); SET_FLAG(sock->flags, RRF_DONE); return DR_DONE; } }