You can use the Computer Cabling Redundancy Socket Status API to monitor the state of all the sockets currently in use by CIMPLICITY Computer Cabling Redundancy.
The following C program prints out the status of each of the sockets.
#include <string.h>
#include <inc_path/cor.h>
#include <inc_path/redwinsock.h>
void print_sockaddr_in(struct sockaddr_in *addr);
TCHAR *socketUse[] =
{
_T("None"),
_T("Listen"),
_T("Connect"),
T("Accept"),
};
TCHAR *socketState[] =
{
_T("None"),
_T("Connecting"),
_T("Connected"),
};
int main()
{
HANDLE dwChangeHandle;
dwChangeHandle = FindFirstSocketChangeNotification();
if(dwChangeHandle == INVALID_HANDLE_VALUE)
return 0;
HANDLE objectArray[1];
WORD objectCount = 1;
objectArray[0] = dwChangeHandle;
DWORD dwWaitStatus = WAIT_OBJECT_0;
while(1)
{
time_t ltime = time(NULL);
printf("\n%s", ctime(<ime));
switch(dwWaitStatus)
{
case WAIT_OBJECT_0:
struct SocketFindData findSocketData;
if(FindFirstSocket(dwChangeHandle, &findSocketData))
{
do
{
if(findSocketData.opened)
{
printf("%-10s ", findSocketData.prcName);
printf("%-10s ", findSocketData.imageName);
printf("%-6s ", findSocketData.opened ? "Opened" :
"Closed");
printf("%-7s ", socketUse[findSocketData.socketUse]);
rintf("%-9s ", findSocketData.isRedundant ? "Redundant" :
"");
printf("%-9s ", findSocketData.connectionCompleted ?
"Completed" : "");
printf("%-10s ", findSocketData.hostName);
printf("\n");
unsigned int i;
for(i = 0; i < findSocketData.connectionCount; i++)
{
if(findSocketData.sockets[i].isOpen)
{
printf("\t%2d: %-10s ", i,
socketState[findSocketData.sockets[i].socketState]);
printf("%-9s ", findSocketData.sockets[i].hasException
? "Exception" : "");
if(findSocketData.socketUse == SOCKET_ACCEPT
|| findSocketData.socketUse == SOCKET_CONNECT)
{
print_sockaddr_in(
&findSocketData.sockets[i].partnerAddr);
}
else if(findSocketData.socketUse == SOCKET_LISTEN)
{
print_sockaddr_in(
&findSocketData.sockets[i].localAddr);
}
printf("\n");
}
}
}
} while(FindNextSocket(dwChangeHandle, &findSocketData));
printf("\n");
FindCloseSocket(dwChangeHandle);
}
break;
default:
FindCloseSocketChangeNotification(dwChangeHandle);
return 0;
}
dwWaitStatus = WaitForMultipleObjects(objectCount,
objectArray,
FALSE,
INFINITE);
if(FindNextSocketChangeNotification(dwChangeHandle) == FALSE)
{
FindCloseSocketChangeNotification(dwChangeHandle);
return 0;
}
}
return 0;
}
void print_sockaddr_in(struct sockaddr_in *addr)
{
printf(_T(" %d.%d.%d.%d %u "),
addr->sin_addr.s_net,
addr->sin_addr.s_host,
addr->sin_addr.s_lh,
addr->sin_addr.s_impno,
ntohs(addr->sin_port));
}
Computer cabling redundancy monitoring. |