Winsock gethostbyaddr problem
-
I know the ip address of a host and i want to know the name of that host. For this purpose i am using following code:
struct hostent *hp; unsigned int addr = inet_addr(m_strHost); hp = gethostbyaddr((char *)&addr,4,AF_INET); if (hp == NULL ) { printf("\n Failed: %d",WSAGetLastError()); } else { printf( "%s\n\n", hp->h_name ); }
It is working fine for my LAN that uses ip address of type 192.x.x.x. But the problem occurs when i give the ip address of host over internet. As such sometimes
gethostbyaddr
is successful and in most cases it fails. It fails with error 11004 (i.e A blocking Windows Socket 1.1 call was canceled through WSACancelBlockingCall) Strange that it is happening in office and not at home. Any idea ??? Or any other alternative way to determine host name when ip address is known ??? Strange that it is not failing in all cases. For example, the ipaddress of yahoo.com is: 64.58.79.230. If i give this ip address then, the program runs successful and the hostname returned as: w1.rc.vip.dcx.yahoo.com But if i give the ip address: 207.219.70.31 (which is that of codeproject.com), then i get error 11004, and gethostbyaddr returns NULL -
I know the ip address of a host and i want to know the name of that host. For this purpose i am using following code:
struct hostent *hp; unsigned int addr = inet_addr(m_strHost); hp = gethostbyaddr((char *)&addr,4,AF_INET); if (hp == NULL ) { printf("\n Failed: %d",WSAGetLastError()); } else { printf( "%s\n\n", hp->h_name ); }
It is working fine for my LAN that uses ip address of type 192.x.x.x. But the problem occurs when i give the ip address of host over internet. As such sometimes
gethostbyaddr
is successful and in most cases it fails. It fails with error 11004 (i.e A blocking Windows Socket 1.1 call was canceled through WSACancelBlockingCall) Strange that it is happening in office and not at home. Any idea ??? Or any other alternative way to determine host name when ip address is known ??? Strange that it is not failing in all cases. For example, the ipaddress of yahoo.com is: 64.58.79.230. If i give this ip address then, the program runs successful and the hostname returned as: w1.rc.vip.dcx.yahoo.com But if i give the ip address: 207.219.70.31 (which is that of codeproject.com), then i get error 11004, and gethostbyaddr returns NULLShamoon wrote: hp = gethostbyaddr((char *)&addr,4,AF_INET); Hm... better to make a
sizeof(addr)
instead of putting 4 there... Shamoon wrote: It fails with error 11004 (i.e A blocking Windows Socket 1.1 call was canceled through WSACancelBlockingCall) Hm... in my book 11004 is: 11004—WSANO_DATA No data record of the requested type found. This error is also associated with gethostbyname and gethostbyaddr. It indicates that the supplied name was valid but that no data record of the requested type was found with it. Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C#, ASP.NET and C++!