1.

Solve : nestat problem?

Answer»

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 muchWhat "other tests" are you running to show you that that port is in use?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



Discussion

No Comment Found