CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2006
    Posts
    10

    Problem using Winsock 2.2 when host can't be resolved to a hostname

    EDIT: I just read you dont need to resolve an address in order to connect? is this correct? my knowledge of winsock in limited
    I’m having problems with the tutorial on Winsock over here: http://www.hal-pc.org/~johnnie2/winsock.html

    The problem I believe is that the host does not have a DNS entry (??), and therefore Winsock get confused and believes that the host is not up.

    The Winsock error I’m getting is:
    Socket error 11004 - Valid name, no data record of requested type
    Another description I found was :
    “In most cases, this error means that the specified Host cannot be resolved. Make sure Host is assigned a valid and existing host address. This error may also mean a problem with your network and/or DNS.”

    This works fine with ip address that do ping and are resolvable, any idea how to get round this problem (if possible) using Winsock 2.2?
    Code:
    		WORD sockVersion;
    	WSADATA wsaData;
    int nret;
    LPHOSTENT hostEntry;
    	sockVersion = MAKEWORD(2, 2);
    
    
    	// Initialize Winsock as before
    	WSAStartup(sockVersion, &wsaData);
    in_addr iaHost;
    iaHost.s_addr = inet_addr("38.144.194.35"); //does not work Y_Y
    //iaHost.s_addr = inet_addr("80.249.110.189"); //works
    hostEntry = gethostbyaddr((const char *)&iaHost, sizeof(struct in_addr), AF_INET);
    //hostEntry = gethostbyname("www.hal-pc.org");	
    
    		
    if (!hostEntry) {
    		nret = WSAGetLastError();
    		Log( LOG_PRINT | LOG_THISSERVER, NULL, "(SID:%i) ERROR:",nret,"gethostbyname()");
    		cout << nret << endl;
    	//	ReportError(nret, "gethostbyname()");	// Report the error as before
    //hostEntry = gethostbyaddr("211.234.61.21", sizeof(struct in_addr), AF_INET);
    	//	WSACleanup();
    		//return NETWORK_ERROR;
    	}
    Regards
    cyph
    Last edited by cypher_soundz; March 26th, 2006 at 07:15 AM.

  2. #2
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: Problem using Winsock 2.2 when host can't be resolved to a hostname

    >>The problem I believe is that the host does not have a DNS entry (??), and therefore Winsock get confused and believes that the host is not up.
    If the host is not up or does not have a valid DNS entry you cannot expect anything else but an error messages saying so.
    Kurt

  3. #3
    Join Date
    Mar 2006
    Posts
    10

    Re: Problem using Winsock 2.2 when host can't be resolved to a hostname

    No the host is up, but there is no hostname linked to it,

    it was speculation that "... therefore Winsock get confused and believes that the host is not up."

    looking here seems that the same problem occurs ? http://www.codeguru.com/forum/showth...ht=error+11004

    cyph

  4. #4
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: Problem using Winsock 2.2 when host can't be resolved to a hostname

    Allright Now I think that I understand what your saying.
    You want to connect via the ip-address and you think that fails because the ip-address cannot be resolved to a hostname.
    If that is so then you could temporarily add an entry to your hosts -file (located somewhere in yout systemdirectory/drivers/etc ) to find out if it is so.
    Kurt

  5. #5
    Join Date
    Mar 2006
    Posts
    10

    Re: Problem using Winsock 2.2 when host can't be resolved to a hostname

    Great thanks, it worked!

    Now is there any way around this? As i said in my edit above , im not up to speed with winsock

    cyph

  6. #6
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: Problem using Winsock 2.2 when host can't be resolved to a hostname

    Quote Originally Posted by cypher_soundz
    Now is there any way around this? As i said in my edit above , im not up to speed with winsock
    Sorry my knowledge about winsock is more or less non existant.
    As far as I know it is as you are saying in your edit. Usually windows doesn't have any problems to connect if you don't provide a hostname ( ip is enough ). But I usually connect to hosts via the ip-address only if I know that there is no DNS-entry at all. So this could very well be a bug in the OS and not only in winsock.
    Kurt
    Last edited by ZuK; March 26th, 2006 at 08:23 AM.

  7. #7
    Join Date
    Feb 2006
    Posts
    162

    Re: Problem using Winsock 2.2 when host can't be resolved to a hostname

    As far as I know, target i.p does not need a dns to be able to connect to it.
    I think the issue may be your use of "gethostbyaddress", if you are only wishing to connect to them, then supplying the i.p alone should be enough.
    Dns would only really matter if it were pointing to a dynamic ip address (changes) so you could continue connecting to the dns without having to update.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured