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. One way works other doesn't

One way works other doesn't

Scheduled Pinned Locked Moved C / C++ / MFC
help
5 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.
  • E Offline
    E Offline
    esepich
    wrote on last edited by
    #1

    The part under the (if aorh == 0) works great :). The part in the else{} brackets dosn't and causes a fatal error in my program when I run it as well as a WSAEPROTONOSUPPORT error :(. I don't understand. I must be doing something screwy. void CSSPingDlg::Ping(LPCSTR pstrHost, int aorh) { SOCKET rawSocket; LPHOSTENT lpHost; rawSocket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); if (rawSocket == SOCKET_ERROR) { AfxMessageBox("Raw socket initialization failed.",MB_OK); return; } if (aorh == 0) { lpHost = gethostbyname(pstrHost); saDest.sin_addr.s_addr = *((u_long FAR *) (lpHost->h_addr)); saDest.sin_family = AF_INET; saDest.sin_port = 0; } else { lpHost = gethostbyaddr(pstrHost,4,AF_INET); saDest.sin_addr.s_addr = *((u_long FAR *) (lpHost->h_addr)); saDest.sin_family = AF_INET; saDest.sin_port = 0; }

    K D 2 Replies Last reply
    0
    • E esepich

      The part under the (if aorh == 0) works great :). The part in the else{} brackets dosn't and causes a fatal error in my program when I run it as well as a WSAEPROTONOSUPPORT error :(. I don't understand. I must be doing something screwy. void CSSPingDlg::Ping(LPCSTR pstrHost, int aorh) { SOCKET rawSocket; LPHOSTENT lpHost; rawSocket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); if (rawSocket == SOCKET_ERROR) { AfxMessageBox("Raw socket initialization failed.",MB_OK); return; } if (aorh == 0) { lpHost = gethostbyname(pstrHost); saDest.sin_addr.s_addr = *((u_long FAR *) (lpHost->h_addr)); saDest.sin_family = AF_INET; saDest.sin_port = 0; } else { lpHost = gethostbyaddr(pstrHost,4,AF_INET); saDest.sin_addr.s_addr = *((u_long FAR *) (lpHost->h_addr)); saDest.sin_family = AF_INET; saDest.sin_port = 0; }

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      the 'aorh' is your flag to go with gethostbyaddr but it doesn´t work. So you should check if your are allowed to use gethostbyaddr in this context/parameters. The error is poiting that you haven´t started the WSA properly to do this. X| Try this @ home. (B&B)

      D 1 Reply Last reply
      0
      • K KarstenK

        the 'aorh' is your flag to go with gethostbyaddr but it doesn´t work. So you should check if your are allowed to use gethostbyaddr in this context/parameters. The error is poiting that you haven´t started the WSA properly to do this. X| Try this @ home. (B&B)

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

        KarstenK wrote: The error is poiting that you haven´t started the WSA properly to do this. Which is what WSANOTINITIALISED is used for.


        Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

        K 1 Reply Last reply
        0
        • E esepich

          The part under the (if aorh == 0) works great :). The part in the else{} brackets dosn't and causes a fatal error in my program when I run it as well as a WSAEPROTONOSUPPORT error :(. I don't understand. I must be doing something screwy. void CSSPingDlg::Ping(LPCSTR pstrHost, int aorh) { SOCKET rawSocket; LPHOSTENT lpHost; rawSocket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); if (rawSocket == SOCKET_ERROR) { AfxMessageBox("Raw socket initialization failed.",MB_OK); return; } if (aorh == 0) { lpHost = gethostbyname(pstrHost); saDest.sin_addr.s_addr = *((u_long FAR *) (lpHost->h_addr)); saDest.sin_family = AF_INET; saDest.sin_port = 0; } else { lpHost = gethostbyaddr(pstrHost,4,AF_INET); saDest.sin_addr.s_addr = *((u_long FAR *) (lpHost->h_addr)); saDest.sin_family = AF_INET; saDest.sin_port = 0; }

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

          This should work just fine:

          ULONG ulAddr = inet_addr("192.168.200.100");
          if (INADDR_NONE != ulAddr)
          {
          LPHOSTENT hostinfo = gethostbyaddr((char *) &ulAddr, sizeof(ulAddr), AF_INET);
          if (NULL != hostinfo)
          {
          ....
          }
          }

          I'm not sure what your code is doing after assigning values to the saDest structure, but have you ruled out that as a potential problem? In other words, do you really want port 0, or should you be using a port in the range 1024–49151? You can also use 49152–65535, but no services are registered on them, which you may not even care about. What is lpHost->h_addr? Shouldn't that be lpHost->h_addr_list?


          Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

          1 Reply Last reply
          0
          • D David Crow

            KarstenK wrote: The error is poiting that you haven´t started the WSA properly to do this. Which is what WSANOTINITIALISED is used for.


            Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

            K Offline
            K Offline
            KarstenK
            wrote on last edited by
            #5

            It also can be that the startup wasn´t with the correct version, because on the other "if" side it worked. Try this @ home. (B&B)

            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