Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Winsock gethostbyaddr problem

Winsock gethostbyaddr problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpcomtutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shamoon
    wrote on last edited by
    #1

    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

    R 1 Reply Last reply
    0
    • S Shamoon

      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

      R Offline
      R Offline
      Rickard Andersson20
      wrote on last edited by
      #2

      Shamoon 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++!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups