Appendix B. IDA_FindServers Sample Program

Complete Sample Code using IDA_FindServers, IDA_OpenSession, IDA_GetVars:

/*****************************************************************************/

/* FindServ.c - find all InSight servers using multi-cast query. */

/*****************************************************************************/

 

/*****************************************************************************/

/* 'C' Includes */

/*****************************************************************************/

#include <stdio.h>

#include <string.h>

 

/*****************************************************************************/

/* QVS includes */

/*****************************************************************************/

#include <IDAApis.h>

#include <qvsdbg.h>

 

/*****************************************************************************/

/* Sockets includes (for inet_ntoa(), htons(), etc) */

/*****************************************************************************/

#if defined(_MSC_VER)

#include <windows.h>

#else

#include "types.h"

#include "sys\socket.h"

#define SOCKET int

#include "tcpip\ioctl.h"

#include "netinet\in.h"

#include "netdb.h"

#endif

 

/*****************************************************************************/

/* Global data */

/*****************************************************************************/

char pgmName[128];

char pgmVer[80];

char pgmDate[15];

char _4690Ver[32];

char storeDesc[128];

ubyte macAddr0[10] = {0}; // 4-byte len + 6-byte binary mac addr

ubyte instStr0[8]; // "2.67.67"

 

idaVarRecord_t gb[] =

{

{ IDAN_PgmName , &pgmName ,

sizeof(pgmName) , sizeof(pgmName) , NULL, 0, 0, 0 },

{ IDAN_PgmVer , &pgmVer ,

sizeof(pgmVer) , sizeof(pgmVer) , NULL, 0, 0, 0 },

{ IDAN_PgmCompileDate , &pgmDate ,

sizeof(pgmDate) , sizeof(pgmDate) , NULL, 0, 0, 0 },

{ IDAN_StoreDescription , &storeDesc,

sizeof(storeDesc), sizeof(storeDesc), NULL, 0, 0, 0 },

{ IDAN_46StoreOSVersion , &_4690Ver ,

sizeof(_4690Ver) , sizeof(_4690Ver) , NULL, 0, 0, 0 },

{ IDAV_ENDOFNONREP, 0, 0, 0, 0, 0, 0, 0 },

{ IDAV_CtlrInfo1MacAddress0, &macAddr0 ,

sizeof(macAddr0) , sizeof(macAddr0) ,

instStr0, sizeof(instStr0), sizeof(instStr0), 0 },

{ 0, 0, 0, 0, 0, 0, 0, 0 }

};

 

/*****************************************************************************/

/* Function Prototypes */

/*****************************************************************************/

int main(int argc, char *argv[]);

char *getDateString(ubyte *DateAndTime);

 

/*****************************************************************************/

/* Function Name: main() */

/* */

/* Purpose: */

/*****************************************************************************/

int main(int argc, char *argv[])

{

#define SERVLIST_SZ 100

idaServID_t servList[SERVLIST_SZ];

int rc;

uint serverCnt;

if ( (argc > 1) && !stricmp(argv[1], "-v") )

{

qDbgSetupComplete(0);

qDbgSetAsciiTrOn(); /* Turn on ASCII debug tracing */

/* will go to file ..\log\qvs1.log */

printf("\r\nDebug ON");

}

 

rc = IDA_FindServers(servList, SERVLIST_SZ, 0, 0, 0, 0, 0, 0);

 

if (rc > 0)

{

uint i;

struct in_addr in_addr;

idaServID_t sId;

ulong errIdx;

ulong errStatus;

ubyte macStr[25];

 

serverCnt = rc;

 

 

for (i = 0; i < serverCnt; i++)

{

memset(&sId, 0, sizeof(sId));

sId.in_addr = servList[i].in_addr;

 

pgmVer[0] = 0;

storeDesc[0] = 0;

rc = IDA_OpenSession(&sId);

if (rc >= 0)

{

memset(macAddr0, 0, sizeof(macAddr0));

sprintf(instStr0, "%d.%d.%d", 2, servList[i].ctlr[0],

servList[i].ctlr[1] - 1);

/* Minus 1 is because GETBULK is */

/* 'getNext' so we want to start at */

/* a value just before the one we */

/* want. We could guse GET instead */

/* but its nice to get everything */

/* in a single call. */

rc = IDA_GetVars(&sId, IDA_GET_BULK_STOP_TE, gb,

&errIdx, &errStatus);

 

logprintf(LOG_DBG, "IDA_GetBulk |rc %d|\n", rc);

IDA_CloseSession(&sId);

}

 

sprintf(macStr, "%02x-%02x-%02x-%02x-%02x-%02x",

macAddr0[4], macAddr0[5], macAddr0[6],

macAddr0[7], macAddr0[8], macAddr0[9]);

in_addr.s_addr = htonl(servList[i].in_addr);

printf("\r\n Store %04d %c%c %s MacAddr %s HostName: %s",

servList[i].store, servList[i].ctlr[0], servList[i].ctlr[1],

inet_ntoa(in_addr), macStr, "?");

if (rc >= 0)

{

char chLast = 0;

char newVerStr[32];

char *ps;

char *pd;

char *dateStr;

printf("\r\n %s", storeDesc);

 

// Re-format version getting rid of double "00" fields

ps = pgmVer;

pd = newVerStr;

while(*ps)

{

if ( (chLast != '0') || (*ps != '0') )

*pd++ = *ps;

 

chLast = *ps++;

}

*pd = 0;

 

dateStr = getDateString(pgmDate);

printf("\r\n %s Version: %s %s", pgmName, newVerStr, dateStr);

printf("\r\n 4690 Version: %s", _4690Ver);

}

}

}

else

printf("\r\n No servers found");

 

 

printf("\r\n");

 

 

qDbgSetAsciiTrOff(); /* Turn off debug tracing */

 

return(0);

} /* main() */

 

/*****************************************************************************/

/* Function Name: getDateString() */

/* */

/* Purpose: */

/*****************************************************************************/

char *getDateString(ubyte *DateAndTime)

{

struct dt_s

{

ushort y;

ubyte m;

ubyte d;

ubyte h;

ubyte min;

ubyte s;

} *dtp = (struct dt_s *)&DateAndTime[4];

 

static char dateString[30];

 

char *mnths[] =

{

{"???"},

{"Jan"},

{"Feb"},

{"Mar"},

{"Apr"},

{"May"},

{"Jun"},

{"Jul"},

{"Aug"},

{"Sep"},

{"Oct"},

{"Nov"},

{"Dec"} };

 

if (dtp->m > 12)

dtp->m = 0;

 

sprintf(dateString, "%s %d %d %d:%02d:%02d",

mnths[dtp->m], dtp->d, ntohs(dtp->y), dtp->h, dtp->min, dtp->s);

 

return(&dateString[0]);

} /* getDateString() */

 

 

 

This sample OUTPUTS:

 

Store 0007 CC 192.168.2.7 MacAddr 00-10-18-09-38-41   HostName: ?

Kingman’s 32bit Lab ctlr

InSight/4690 Controller Agent Version: 0.0.0.99 Oct 27 2005 14:33:01

4690 Version: V3R3 CD 04K1

 

Store 0075 CC 192.168.2.70 MacAddr 00-00-00-00-00-00 HostName: ?

InSight-Enabled Testlab

InSight/4690 Controller Agent Version: 0.0.0.99 Sep 23 2005 10:48:45

4690 Version: V3R3 CD 04K0

 

 

Converted from CHM to HTML with chm2web Pro 2.85 (unicode)