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. Can not take my own IP address (Windows Server 2003)

Can not take my own IP address (Windows Server 2003)

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminwindows-adminquestion
9 Posts 4 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.
  • A Offline
    A Offline
    alejandrofuchs
    wrote on last edited by
    #1

    Hi, I cann't take my own IP address on Windows Server 2003. This is the code i'm using, it works fine in Windows 2000 (Professional and Server) and Windows XP, but DOESN'T WORK IN Windows Server 2003. I'm getting crazy, Why it doesn't work only in Windows 2003?

    int iSockErr = 0;
    HANDLE hnd = 0;
    WORD wVersionRequested = MAKEWORD(2, 2);
    WSADATA wsaData;
    try
    {
    
        //Inicializar los sockets
        if ((iSockErr = WSAStartup(wVersionRequested, &wsaData)) != 0) { throw 1; }
    
        DWORD dw;
        GUID guid = SVCID\_HOSTNAME;
        struct AUX{
            WSAQUERYSET qsRestrictions;
            BYTE byte\[500\];
        }aux;
    
        memset(&aux.qsRestrictions, 0, sizeof(WSAQUERYSET));
        aux.qsRestrictions.dwSize = sizeof(WSAQUERYSET);
        aux.qsRestrictions.lpServiceClassId = &guid;
        if (WSALookupServiceBegin(&aux.qsRestrictions, LUP\_RETURN\_ADDR, &hnd)) { throw 2; }
    
        dw = sizeof(aux);
        memset(&aux, 0, sizeof(aux));
        aux.qsRestrictions.dwSize = sizeof(WSAQUERYSET);
        while ( !WSALookupServiceNext(hnd, LUP\_RETURN\_ADDR, &dw, &aux.qsRestrictions) )
        {
    

    //IN WINDOWS 2003 aux.qsRestrictions.lpcsaBuffer IS ALWAYS NULL

            ptyIP->d0 = aux.qsRestrictions.lpcsaBuffer\[0\].RemoteAddr.lpSockaddr->sa\_data\[2\];
            ptyIP->d1 = aux.qsRestrictions.lpcsaBuffer\[0\].RemoteAddr.lpSockaddr->sa\_data\[3\];
            ptyIP->d2 = aux.qsRestrictions.lpcsaBuffer\[0\].RemoteAddr.lpSockaddr->sa\_data\[4\];
            ptyIP->d3 = aux.qsRestrictions.lpcsaBuffer\[0\].RemoteAddr.lpSockaddr->sa\_data\[5\];
        }
    
        ...
    

    Thank you very much.

    D 1 Reply Last reply
    0
    • A alejandrofuchs

      Hi, I cann't take my own IP address on Windows Server 2003. This is the code i'm using, it works fine in Windows 2000 (Professional and Server) and Windows XP, but DOESN'T WORK IN Windows Server 2003. I'm getting crazy, Why it doesn't work only in Windows 2003?

      int iSockErr = 0;
      HANDLE hnd = 0;
      WORD wVersionRequested = MAKEWORD(2, 2);
      WSADATA wsaData;
      try
      {
      
          //Inicializar los sockets
          if ((iSockErr = WSAStartup(wVersionRequested, &wsaData)) != 0) { throw 1; }
      
          DWORD dw;
          GUID guid = SVCID\_HOSTNAME;
          struct AUX{
              WSAQUERYSET qsRestrictions;
              BYTE byte\[500\];
          }aux;
      
          memset(&aux.qsRestrictions, 0, sizeof(WSAQUERYSET));
          aux.qsRestrictions.dwSize = sizeof(WSAQUERYSET);
          aux.qsRestrictions.lpServiceClassId = &guid;
          if (WSALookupServiceBegin(&aux.qsRestrictions, LUP\_RETURN\_ADDR, &hnd)) { throw 2; }
      
          dw = sizeof(aux);
          memset(&aux, 0, sizeof(aux));
          aux.qsRestrictions.dwSize = sizeof(WSAQUERYSET);
          while ( !WSALookupServiceNext(hnd, LUP\_RETURN\_ADDR, &dw, &aux.qsRestrictions) )
          {
      

      //IN WINDOWS 2003 aux.qsRestrictions.lpcsaBuffer IS ALWAYS NULL

              ptyIP->d0 = aux.qsRestrictions.lpcsaBuffer\[0\].RemoteAddr.lpSockaddr->sa\_data\[2\];
              ptyIP->d1 = aux.qsRestrictions.lpcsaBuffer\[0\].RemoteAddr.lpSockaddr->sa\_data\[3\];
              ptyIP->d2 = aux.qsRestrictions.lpcsaBuffer\[0\].RemoteAddr.lpSockaddr->sa\_data\[4\];
              ptyIP->d3 = aux.qsRestrictions.lpcsaBuffer\[0\].RemoteAddr.lpSockaddr->sa\_data\[5\];
          }
      
          ...
      

      Thank you very much.

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

      alejandrofuchs wrote:

      Why it doesn't work only in Windows 2003?

      Why don't you tell us? What does WSAGetLastError() return?


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      J A 2 Replies Last reply
      0
      • D David Crow

        alejandrofuchs wrote:

        Why it doesn't work only in Windows 2003?

        Why don't you tell us? What does WSAGetLastError() return?


        "A good athlete is the result of a good and worthy opponent." - David Crow

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        J Offline
        J Offline
        joseaxyz
        wrote on last edited by
        #3

        Thanks, It returns 0, indicating there is no error, but no data is returned. alejandrofuchs@yahoo.com

        1 Reply Last reply
        0
        • D David Crow

          alejandrofuchs wrote:

          Why it doesn't work only in Windows 2003?

          Why don't you tell us? What does WSAGetLastError() return?


          "A good athlete is the result of a good and worthy opponent." - David Crow

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          A Offline
          A Offline
          alejandrofuchs
          wrote on last edited by
          #4

          Thanks! First, i'm sorry, someone else (joseaxy) was already signed in codeproject in this machine, so my later response had that name. Second (again i'm sorry), i responded wrong, the rigth answer is: WSAGetLastError() returns 10110, WSALookupServiceNext is returning 0 the second time it is called. alejandrofuchs@yahoo.com

          D M 2 Replies Last reply
          0
          • A alejandrofuchs

            Thanks! First, i'm sorry, someone else (joseaxy) was already signed in codeproject in this machine, so my later response had that name. Second (again i'm sorry), i responded wrong, the rigth answer is: WSAGetLastError() returns 10110, WSALookupServiceNext is returning 0 the second time it is called. alejandrofuchs@yahoo.com

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

            alejandrofuchs wrote:

            WSAGetLastError() returns 10110...

            Which resolves to WSA_E_NO_MORE.


            "A good athlete is the result of a good and worthy opponent." - David Crow

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            1 Reply Last reply
            0
            • A alejandrofuchs

              Thanks! First, i'm sorry, someone else (joseaxy) was already signed in codeproject in this machine, so my later response had that name. Second (again i'm sorry), i responded wrong, the rigth answer is: WSAGetLastError() returns 10110, WSALookupServiceNext is returning 0 the second time it is called. alejandrofuchs@yahoo.com

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              alejandrofuchs wrote:

              First, i'm sorry, someone else (joseaxy) was already signed in codeproject in this machine, so my later response had that name.

              hmmm...split personality? ;P If you try getaddrinfo(), does that work on Server 2003? Something like:

              char szHostName[256];
              if (0 == ::gethostname(szHostName, sizeof(szHostName)))
              {
              char* port = "80";
              addrinfo aiHints;
              addrinfo *aiList = NULL;
              int retVal;

              memset(&aiHints, 0, sizeof(aiHints));
              aiHints.ai_family = AF_INET;
              aiHints.ai_socktype = SOCK_STREAM;
              aiHints.ai_protocol = IPPROTO_TCP;

              if ((retVal = ::getaddrinfo(szHostName, port, &aiHints, &aiList)) == 0)
              {
              addrinfo *pAddrInfo = aiList;
              while (pAddrInfo)
              {
              // examine pAddrInfo->ai_addr here for local IP address(es)

                   pAddrInfo = pAddrInfo->ai\_next;
                }
              
                `::freeaddrinfo(aiList); //*EDIT*`
              

              }
              }

              -- modified at 14:41 Friday 8th June, 2007

              "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

              A 1 Reply Last reply
              0
              • M Mark Salsbery

                alejandrofuchs wrote:

                First, i'm sorry, someone else (joseaxy) was already signed in codeproject in this machine, so my later response had that name.

                hmmm...split personality? ;P If you try getaddrinfo(), does that work on Server 2003? Something like:

                char szHostName[256];
                if (0 == ::gethostname(szHostName, sizeof(szHostName)))
                {
                char* port = "80";
                addrinfo aiHints;
                addrinfo *aiList = NULL;
                int retVal;

                memset(&aiHints, 0, sizeof(aiHints));
                aiHints.ai_family = AF_INET;
                aiHints.ai_socktype = SOCK_STREAM;
                aiHints.ai_protocol = IPPROTO_TCP;

                if ((retVal = ::getaddrinfo(szHostName, port, &aiHints, &aiList)) == 0)
                {
                addrinfo *pAddrInfo = aiList;
                while (pAddrInfo)
                {
                // examine pAddrInfo->ai_addr here for local IP address(es)

                     pAddrInfo = pAddrInfo->ai\_next;
                  }
                
                  `::freeaddrinfo(aiList); //*EDIT*`
                

                }
                }

                -- modified at 14:41 Friday 8th June, 2007

                "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                A Offline
                A Offline
                alejandrofuchs
                wrote on last edited by
                #7

                Yes, this works. I will change my code. I still have the doubt about why it doesn't work only on Windows 2003, but as this code works fine i prefer this new aproach. :)Thank you to you all for your help! PD. Only for curiosity :confused:, if somebody find out what's wrong on the original code under 2003, please write. :)alejandrofuchs@yahoo.com

                M 2 Replies Last reply
                0
                • A alejandrofuchs

                  Yes, this works. I will change my code. I still have the doubt about why it doesn't work only on Windows 2003, but as this code works fine i prefer this new aproach. :)Thank you to you all for your help! PD. Only for curiosity :confused:, if somebody find out what's wrong on the original code under 2003, please write. :)alejandrofuchs@yahoo.com

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #8

                  alejandrofuchs wrote:

                  I still have the doubt about why it doesn't work only on Windows 2003

                  I couldn't find any reason it wouldn't work in the Platform SDK for Server 2003...it's a mystery to me! :) Mark

                  "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                  1 Reply Last reply
                  0
                  • A alejandrofuchs

                    Yes, this works. I will change my code. I still have the doubt about why it doesn't work only on Windows 2003, but as this code works fine i prefer this new aproach. :)Thank you to you all for your help! PD. Only for curiosity :confused:, if somebody find out what's wrong on the original code under 2003, please write. :)alejandrofuchs@yahoo.com

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #9

                    p.s. Don't forget to call freeaddrinfo() - I left that out of the code sample. Cheers :beer: Mark

                    "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                    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