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. problem with gethostbyaddr

problem with gethostbyaddr

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminhelpquestionlearning
4 Posts 3 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.
  • C Offline
    C Offline
    Chernobog1
    wrote on last edited by
    #1

    Hi, ive got this problem : when i use this everything is ok : LPHOSTENT hostent; hostent = gethostbyname("localhost"); but with this : LPHOSTENT hostent; CString strIP="127.0.0.1" hostent = gethostbyaddr (strIP,strIP.GetLength (),AF_INET); i cant connect to the server (of course it does the same with other adresses then localhost :) Can u tell me plz what im doing wrong ? And the third para in gethostbyadd. Does it have to be always AF_INET or there are some choices? Thx in Advance.

    J D 2 Replies Last reply
    0
    • C Chernobog1

      Hi, ive got this problem : when i use this everything is ok : LPHOSTENT hostent; hostent = gethostbyname("localhost"); but with this : LPHOSTENT hostent; CString strIP="127.0.0.1" hostent = gethostbyaddr (strIP,strIP.GetLength (),AF_INET); i cant connect to the server (of course it does the same with other adresses then localhost :) Can u tell me plz what im doing wrong ? And the third para in gethostbyadd. Does it have to be always AF_INET or there are some choices? Thx in Advance.

      J Offline
      J Offline
      Jorgen Sigvardsson
      wrote on last edited by
      #2

      What does WSAGetLastError() return after the failed call to gethostbyaddr()? -- You're entertaining at least.

      1 Reply Last reply
      0
      • C Chernobog1

        Hi, ive got this problem : when i use this everything is ok : LPHOSTENT hostent; hostent = gethostbyname("localhost"); but with this : LPHOSTENT hostent; CString strIP="127.0.0.1" hostent = gethostbyaddr (strIP,strIP.GetLength (),AF_INET); i cant connect to the server (of course it does the same with other adresses then localhost :) Can u tell me plz what im doing wrong ? And the third para in gethostbyadd. Does it have to be always AF_INET or there are some choices? Thx in Advance.

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        unsigned long ulResult = inet_addr(strIP);
        if (INADDR_NONE != ulResult)
        {
        hostent = gethostbyaddr((char *) &ulResult, sizeof(ulResult), AF_INET);
        // now you can print hostent->h_name
        }


        A rich person is not the one who has the most, but the one that needs the least.

        C 1 Reply Last reply
        0
        • D David Crow

          unsigned long ulResult = inet_addr(strIP);
          if (INADDR_NONE != ulResult)
          {
          hostent = gethostbyaddr((char *) &ulResult, sizeof(ulResult), AF_INET);
          // now you can print hostent->h_name
          }


          A rich person is not the one who has the most, but the one that needs the least.

          C Offline
          C Offline
          Chernobog1
          wrote on last edited by
          #4

          Thanks :)

          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