home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
sapgen.exe
/
SAPGEN.C
next >
Wrap
Text File
|
1994-08-08
|
8KB
|
268 lines
/****************************************************************************
** File: SAPGEN.C
**
** Desc: Sample General Service Query Program
**
** Run SAPGEN from the command line. This program sends out
** a general service query for File Servers (type 4), and
** drops in to a loop that receives the response packets and
** prints the results on the screen.
**
**
**
**
**
** DISCLAIMER
**
** Novell, Inc. makes no representations or warranties with respect to
** any NetWare software, and specifically disclaims any express or
** implied warranties of merchantability, title, or fitness for a
** particular purpose.
**
** Distribution of any NetWare software is forbidden without the
** express written consent of Novell, Inc. Further, Novell reserves
** the right to discontinue distribution of any NetWare software.
**
** Novell is not responsible for lost profits or revenue, loss of use
** of the software, loss of data, costs of re-creating lost data, the
** cost of any substitute equipment or program, or claims by any party
** other than you. Novell strongly recommends a backup be made before
** any software is installed. Technical support for this software
** may be provided at the discretion of Novell.
**
** Programmers:
**
** Ini Who Firm
** -----------------------------------------------------------------------
** KLB Karl Bunnell Novell Developer Support.
**
** History:
**
** When Who What
** -----------------------------------------------------------------------
** 08-08-94 klb First code.
*/
/****************************************************************************
** Include headers, macros, function prototypes, etc.
*/
/*------------------------------------------------------------------------
** ANSI
*/
#include <stdio.h>
/*------------------------------------------------------------------------
** NetWare
*/
#define NWDOS
#include <nwcalls.h>
/****************************************************************************
** Global Structure Definitions
*/
/*------------------------------------------------------------------------
** NetWare IPX
*/
typedef struct IPXAddress
{
BYTE network[4]; /* high-low */
BYTE node[6]; /* high-low */
BYTE socket[2]; /* high-low */
}IPXAddress;
typedef struct IPXHeader
{
WORD checkSum; /* high-low */
WORD length; /* high-low */
BYTE transportControl;
BYTE packetType;
IPXAddress destination;
IPXAddress source;
}IPXHeader;
typedef struct ECBFragment
{
void far *address;
WORD size; /* low-high */
}ECBFragment;
typedef struct ECB
{
void far *linkAddress;
void (far *ESRAddress)();
BYTE inUseFlag;
BYTE completionCode;
WORD socketNumber; /* high-low */
BYTE IPXWorkspace[4]; /* N/A */
BYTE driverWorkspace[12]; /* N/A */
BYTE immediateAddress[6]; /* high-low */
WORD fragmentCount; /* low-high */
ECBFragment fragmentDescriptor[5];
}ECB;
typedef struct
{
WORD responseType;
WORD serverType;
BYTE serverName[48];
BYTE network[4];
BYTE node[6];
WORD sock;
WORD intNetworks;
} SAP_RECORD;
typedef struct
{
WORD queryType;
WORD serverType;
} QUERY_PACKET;
/****************************************************************************
** This function is the entire program, as it is very simple.
** Prompt user for input, open a stream, make a call, close the stream.
*/
void main(void)
{
WORD Socket=0x0000;
SAP_RECORD sapInfo;
QUERY_PACKET qPacket;
int ccode, i, cnt;
IPXHeader sHeader;
ECB sECB;
ECB rECB;
IPXHeader rHeader;
char ch;
WORD sapSocket;
ccode = IPXInitialize();
/*------------------------------------------------------------------------
** Open a dynamic socket to listen on.
*/
IPXOpenSocket((BYTE *)&Socket, (BYTE)0);
printf("\nIPXOpenSocket returned : %04X\n", NWWordSwap(Socket));
/*------------------------------------------------------------------------
** Initialize fields for Receive IPX Header and Receive ECB
*/
rHeader.packetType = (char)4;
rHeader.length = NWWordSwap(sizeof(IPXHeader));
rECB.ESRAddress = (void far *)NULL;
rECB.socketNumber= Socket;
rECB.fragmentCount = 2;
rECB.fragmentDescriptor[0].address = &rHeader;
rECB.fragmentDescriptor[0].size = sizeof(IPXHeader);
rECB.fragmentDescriptor[1].address = &sapInfo;
rECB.fragmentDescriptor[1].size = sizeof(sapInfo);
/*------------------------------------------------------------------------
** Start listening before you send!
*/
IPXListenForPacket(&rECB);
/*------------------------------------------------------------------------
** Initialize Send IPX Header, Query Packet and Send ECB
*/
for (i=0; i<4; ++i)
sHeader.destination.network[i] = (BYTE)0x00;
for (i=0; i<6; ++i)
sHeader.destination.node[i] = (BYTE)0xFF;
sapSocket=NWWordSwap(0x452);
memcpy(sHeader.destination.socket, &sapSocket, 2);
/*------------------------------------------------------------------------
** Query Services Packet
*/
qPacket.queryType = NWWordSwap(0x01); // General Service Query
qPacket.serverType = NWWordSwap(0x0004); // File server type
sHeader.length = NWWordSwap(sizeof(IPXHeader));
sHeader.packetType = 4;
sECB.ESRAddress = (void far *)NULL;
sECB.inUseFlag = 0;
sECB.fragmentCount = 2;
sECB.socketNumber = Socket;
for (i=0; i<6; ++i)
sECB.immediateAddress[i] = 0xFF;
sECB.fragmentDescriptor[0].address = (&sHeader);
sECB.fragmentDescriptor[0].size = sizeof(IPXHeader);
sECB.fragmentDescriptor[1].address = (&qPacket);
sECB.fragmentDescriptor[1].size = sizeof(QUERY_PACKET);
/*------------------------------------------------------------------------
** Send out the Query Packet!
*/
IPXSendPacket(&sECB);
while(sECB.inUseFlag)
IPXRelinquishControl();
printf("\n Packet is sent!! \n");
printf("\n Waiting for packet: \n");
/*------------------------------------------------------------------------
** Drop into this loop until a key is pressed. The results are printed
** to the screen. The data from these packets could be extracted and used
** for other purposes. Also note that only one receive ECB is being posted
** to listen for packets. Depending on the circumstances this may not be
** sufficient to receive all the responses sent from servers on the LAN.
*/
while(!kbhit())
{
while(rECB.inUseFlag)
{
if(kbhit())
{
while(kbhit())
{
IPXCancelEvent(&rECB); // close shop
IPXCloseSocket(Socket);
printf("\n...Receiving of SAP responses aborted\n");
exit(1);
}
}
IPXRelinquishControl();
}
printf("\n");
printf(" Server : %-47.47s", sapInfo.serverName);
printf(" Type.. : %04X\n", NWWordSwap(sapInfo.serverType));
printf(" Address: %02X%02X%02X%02X:%02X%02X%02X%02X%02X%02X:%04X",
sapInfo.network[0],
sapInfo.network[1],
sapInfo.network[2],
sapInfo.network[3],
sapInfo.node[0],
sapInfo.node[1],
sapInfo.node[2],
sapInfo.node[3],
sapInfo.node[4],
sapInfo.node[5],
NWWordSwap(sapInfo.sock));
printf(" Hops: %d\n", NWWordSwap(sapInfo.intNetworks));
IPXListenForPacket(&rECB);
}
IPXCloseSocket(Socket); // remember to close the socket!
}