home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
sapit.exe
/
SAPIT.C
next >
Wrap
Text File
|
1994-07-29
|
4KB
|
144 lines
/****************************************************************************
** File: SAPIT.C
**
** Desc: Sample SAP Advertise
**
** This is a Partner program with SAPQ.EXE. This program must be run first.
** This program simply advertises itself as a specific SAP server type
** and then drops in the a "listen loop" receiving IPX packets from a
** client node. The data is then removed from the packet and displayed
** 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 L Bunnell Novell Developer Support.
**
** History:
**
** When Who What
** -----------------------------------------------------------------------
** 09-14-94 KLB First code.
*/
/****************************************************************************
** Include headers, macros, function prototypes, etc.
*/
/*------------------------------------------------------------------------
** ANSI
*/
#include <stdio.h>
#include <conio.h>
/*------------------------------------------------------------------------
** SAP and NetWare
*/
#include <sap.h>
#include <nit.h>
/****************************************************************************
** This function is the entire program.
** Simply run SAPIT from the command line. This code advertises a service
** and then drops into a listen loop waiting for a client to connect.
** Once a client begins sending IPX packets to this node, the data portion
** of the IPX packet is stripped out and displayed on the screen.
**
*/
main()
{
WORD sType, Socket = 0x9000;
char sName[48];
BYTE sSocket[2];
int ccode;
char c, *cPtr, character='\0';
char *msg;
ECB *rECB;
IPXHeader *rHeader;
int i;
/*------------------------------------------------------------------------
** Set up and Advertise service
*/
sType = 0x9001;
strcpy(sName,"SAP_ServerName");
*(WORD *)&sSocket[0] = 0x9000;
ccode = AdvertiseService(sType, sName, sSocket);
printf("Completion code was %02X", ccode);
c=getch();
ccode = IPXInitialize();
if(ccode)
printf("IPX is not loaded");
IPXOpenSocket((BYTE *)&sSocket, (BYTE)0);
if((rECB = (ECB *)malloc(sizeof(ECB))) == (ECB *)NULL)
printf("Out of memory1");
printf("\nsize = %d\n",sizeof(IPXHeader));
rHeader=(IPXHeader *)malloc(sizeof(IPXHeader));
if((msg = (char *)malloc(sizeof(char))) == (ECB *)NULL)
printf("Out of memory3");
rHeader->packetType = (char)4;
rHeader->length = IntSwap(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 = msg;
rECB->fragmentDescriptor[1].size = sizeof(char);
/*------------------------------------------------------------------------
** Wait in listen loop receiving packets until a '~' character is received.
*/
IPXListenForPacket(rECB);
printf("\n Waiting for packet: \n");
while(character != '~')
{
while(rECB->inUseFlag)
IPXRelinquishControl();
cPtr = (char *)(rECB->fragmentDescriptor[1].address);
memcpy(&character, cPtr, 1);
printf("%c",character);
IPXListenForPacket(rECB);
}
printf("\nClosing Socket and shutting down SAP\n");
IPXCloseSocket(Socket);
ccode = ShutdownSAP();
}