View Full Version: Valid name, no data record of requested type

C++ Learning Community > win32 api C++ programming > Valid name, no data record of requested type


Title: Valid name, no data record of requested type
Description: dns problems...


C00L - August 20, 2005 07:14 AM (GMT)
I am using the gethostbyname function, and it only works like 50% of the time, the other times it gives the WSANO_DATA error. I am not sure what the problem is though. I did a few tests and here are the results of several urls i tried...

www.google.com --ok
www.netcraft.com -- WSANO_DATA
www.yahoo.com -- ok
www.slashdot.org -- WSANO_DATA

try the code out below to see what i mean... (sorry tabs are screwed up)

CODE

#include <stdio.h>
#include "winsock2.h"
#include "iostream"
using namespace std;
int main(int argc, char** argv[]){
char addres2[100];
char addres[100];
char buf[100];
char *find;
unsigned int addr;
HOSTENT *hp;
if(argc > 1)
 sprintf(addres2, "%s", argv[1]);
else{
 cout<<"Enter address: ";
 cin>>addres2;
}
if(strstr(addres2, "/")){
 find = strstr(addres2, "/");
 strncpy(addres, addres2, strlen(addres2)-strlen(find));
}else{
 sprintf(buf, "%s/", addres2);
 sprintf(addres2, "%s", buf);
 find = strstr(addres2, "/");
 strncpy(addres, addres2, strlen(addres2)-strlen(find));
}
   WSADATA wsaData;
   int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
   if(iResult != NO_ERROR)
 printf("Error at WSAStartup()\n");
   // Create a socket.
   SOCKET m_socket;
   m_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
   if(m_socket == INVALID_SOCKET){
 printf("Error at socket(): %ld\n", WSAGetLastError());
 WSACleanup();
 return 0;
}
if(addres[strlen(addres)] == '\n')
 addres[strlen(addres)] = '\0';
sockaddr_in clientService;
clientService.sin_family = AF_INET;
clientService.sin_port = htons(80);
if(inet_addr(addres)==INADDR_NONE){
 hp=gethostbyname(addres);
 if(!hp){
  switch (WSAGetLastError()){
   case WSANOTINITIALISED:
    cout<<"Error: Windows Sockets not started";
   break;
   case WSAENETDOWN:
    cout<<"Error: The network subsystem has failed.";
   break;
   case WSAHOST_NOT_FOUND:
    cout<<"Error: Authoritative answer host not found.";
   break;
   case WSATRY_AGAIN:
    cout<<"Error: Nonauthoritative host not found, or server failure.";
   break;
   case WSANO_RECOVERY:
    cout<<"Error: A nonrecoverable error occurred.";
   break;
   case WSANO_DATA:
    cout<<"Error: Valid name, no data record of requested type.";
   break;
   case WSAEINPROGRESS:
    cout<<"Error: A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.";
   break;
   case WSAEFAULT:
    cout<<"Error: The name parameter is not a valid part of the user address space.";
   break;
   case WSAEINTR:
    cout<<"Error: A blocking Windows Socket 1.1 call was canceled through WSACancelBlockingCall.";
   break;
  }
  return 0;
 }else
 clientService.sin_addr = *((LPIN_ADDR)*hp->h_addr_list);
}else
 clientService.sin_addr.s_addr = inet_addr(addres);
if(connect(m_socket, (SOCKADDR*) &clientService, sizeof(clientService)) == SOCKET_ERROR){
 printf("Failed to connect.\n");
 WSACleanup();
 return 0;
}
   return 0;
}

myork - August 20, 2005 01:25 PM (GMT)
QUOTE
The requested name is valid but does not have an IP address; this is not a temporary error.  This means that the name is known to the name server but there is no address associated with this name.  Another type of request to the name server using this domain name will result in an answer; for example, a mail-forwarder may be registered for this domain.


Sounds like if may have timed out. Try again and it may work.




* Hosted for free by InvisionFree