home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
ibmtool.zip
/
server.c
< prev
next >
Wrap
Text File
|
1997-11-07
|
6KB
|
231 lines
/******************************************************************************/
/* */
/* FILE: SERVER.C */
/* */
/* PURPOSE: This file contains the server/workstation command processing. */
/* */
/* FUNCTIONS: TTServer */
/* TTWorkstation */
/* TTMonitor */
/* AddWorkStation */
/* DeleteWorkStation */
/* */
/* GLOBAL DATA ACCESSED */
/* USHORT LastStatus; */
/* WORD IndicationCount; */
/* SERVICESTAT MACMSS; */
/* */
/******************************************************************************/
#define INCL_SUB
#define INCL_BASE
#define INCL_DOS
#include <os2.h>
#include <stdio.h>
#include <stdarg.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "ndis.h"
#include "ibmtool.h"
int TTServer ()
{
// SERVER
// set WEDGE Response Mode to SERVER
WedgeCommon->RspMode = SERVER;
aprintf (0, 76, 0x74, "S");
return SUCCESS;
}
int TTWorkstation ()
{
// WKSTA
BOOLEAN ServerFound = FALSE;
WORD i, j, mode;
// clear the current server address
for (i=0; i<WedgeCommon->StnAdrSz; ++i)
WedgeCommon->ServerAddr[i] = 0;
// temporarily set our mode to WORKSTATION
mode = WedgeCommon->RspMode;
WedgeCommon->RspMode = WORKSTATION;
// send out a control frame to find a server
SendControlFrame (CCWKSTA);
// wait for server's response
for (i=0; i<20; ++i)
{
CheckIndications ();
// check the server address
for (j=0; j<WedgeCommon->StnAdrSz; ++j)
if (WedgeCommon->ServerAddr[j])
ServerFound = TRUE;
if (ServerFound) break;
DosSleep (100);
} /* endfor */
if (ServerFound)
{
aprintf (0, 76, 0x74, "W");
return (LastStatus = SUCCESS);
}
else
{
WedgeCommon->RspMode = mode;
LastStatus = GENERAL_FAILURE;
return TT_NO_SERVER;
}
}
int TTMonitor ()
{
// MONITOR
// tell SERVER we're no longer a WORKSTATION
if (WedgeCommon->RspMode == WORKSTATION)
SendControlFrame (CCDELWKSTA);
// reset WEDGE Response Mode to PEEPER
WedgeCommon->RspMode = PEEPER;
aprintf (0, 76, 0x74, " ");
return SUCCESS;
}
void AddWorkStation ()
{
int i;
WKSTAITEM *new, *curr = WkStaTop;
// check that workstation's address is not already in the list
while (curr != NULL)
{
for (i=0; i<MACMSC.MscStnAdrSz; ++i)
if (curr->WkstaAddr[i] != *(ControlFrame.pSrc + i))
break;
if (i == MACMSC.MscStnAdrSz) // already there
return;
else
curr = curr->next;
} /* endwhile */
// create workstation item
new = (WKSTAITEM *) calloc (1, sizeof (WKSTAITEM));
// fill in workstation item's address
new->next = NULL;
for (i=0; i<MACMSC.MscStnAdrSz; ++i)
new->WkstaAddr[i] = *(ControlFrame.pSrc + i);
new->Stressing = FALSE;
// add workstation item to the list
if (WkStaTop == NULL)
{
WkStaTop = new;
new->prev = NULL;
}
else
{
curr = WkStaTop;
while (curr->next != NULL)
curr = curr->next;
new->prev = curr;
curr->next = new;
}
}
void DeleteWorkStation ()
{
int i;
WKSTAITEM *curr = WkStaTop;
while (curr != NULL)
{
for (i=0; i<MACMSC.MscStnAdrSz; ++i)
if (curr->WkstaAddr[i] != *(ControlFrame.pSrc + i))
break;
if (i == MACMSC.MscStnAdrSz)
{
if (curr == WkStaTop)
{
free (WkStaTop);
WkStaTop = curr->next;
curr->prev = NULL;
return;
}
else if (curr != NULL)
{
curr->next->prev = curr->prev;
curr->prev->next = curr->next;
free (curr);
return;
}
}
else
curr = curr->next;
} /* endwhile */
}
USHORT QueryWorkStations ()
{
USHORT WkstaCnt = 0;
WKSTAITEM *curr = WkStaTop;
while (curr != NULL)
{
WkstaResponded = FALSE;
_fmemcpy ((void far *) ControlFrame.pSrc,
(void far *) curr->WkstaAddr,
MACMSC.MscStnAdrSz);
SendControlFrame (CCQUERYWKSTA);
DosSleep (500);
CheckIndications ();
if (WkstaResponded == FALSE)
DeleteWorkStation ();
else
{
++WkstaCnt;
curr->Stressing = TRUE;
}
curr = curr->next;
}
return WkstaCnt;
}
void StopWkStaStress ()
{
int i;
WKSTAITEM *curr = WkStaTop;
while (curr != NULL)
{
for (i=0; i<MACMSC.MscStnAdrSz; ++i)
if (curr->WkstaAddr[i] != *(ControlFrame.pSrc + i))
break;
if (i == MACMSC.MscStnAdrSz)
{
if (curr->Stressing)
{
curr->Stressing = FALSE;
--WkstaStressCnt;
}
break;
}
else
curr = curr->next;
} /* endwhile */
}