Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: nestat problem  (Read 2118 times)

0 Members and 1 Guest are viewing this topic.

Snow

  • Guest
nestat problem
« on: December 07, 2007, 11:03:30 AM »
use netstat -a to list all the tcp/ip ports but I always have one port not showing up although through other test I know it's in use because I got 10048 (port in use) error with that port. is there anybody can help me with this?
Thanks very much

Anodoin



    Intermediate

    Re: nestat problem
    « Reply #1 on: December 08, 2007, 07:16:26 AM »
    What "other tests" are you running to show you that that port is in use?

    Snow

    • Guest
    Re: nestat problem
    « Reply #2 on: December 10, 2007, 03:13:39 PM »
    the segment code I used to test the ports is the following:
    bool CFmtCGeneratorDlg::PortBusy(short Port)
    {
       TRACE(0, "CFmtCGeneratorDlg::PortBusy: start");
       short  CountRead = 0;
       struct sockaddr_in SockAddrStr;
       int m_TestSocket = 0;
       //char PortStr[10];
     
       //_itoa(Port, PortStr,10);
       //TRACE(0, "port = " << PortStr);
       // Create the test socket
       if ((m_TestSocket = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
       {
          ERROR("CFmtCGeneratorDlg::PortBusy: Test socket create error. Error = " << WSAGetLastError ());
         TRACE(0, "CFmtCGeneratorDlg::PortBusy: done - returning true");
          return true;   // Can't verify so we must assume it's in use
       }
     
       // Bind the listening socket to see if it is already in use
       SockAddrStr.sin_family        = AF_INET;
       SockAddrStr.sin_addr.s_addr   = INADDR_ANY;
       SockAddrStr.sin_port          = htons(Port);
       if (bind (m_TestSocket, (struct sockaddr*)&SockAddrStr, sizeof(SockAddrStr)) == SOCKET_ERROR)
       {
          ERROR("CFmtCGeneratorDlg::PortBusy: Test socket bind Error = " << WSAGetLastError () << " on Port " << Port);
          TRACE(0, "CFmtCGeneratorDlg::PortBusy: done - returning true");
          return true;
       }
       else
       {
           // We verified that the port is not already in use so lets close it
          if (closesocket(m_TestSocket) == SOCKET_ERROR)
          {
             ERROR("CFmtCGeneratorDlg::PortBusy: closesocket error = " << WSAGetLastError () << "return true");   
             TRACE(0, "CFmtCGeneratorDlg::PortBusy: done - returning true");
             return true;
          }      
       } 

       TRACE(0, "CFmtCGeneratorDlg::PortBusy: done - returning false");
       return false;
    }

    and the result is the following:
    CFmtCGeneratorDlg::PortBusy: Test socket bind Error = 10048 on Port 1063
    but 1063 was not on the list when I used netstat -a

    Thanks for the help very much