home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
sapex3.exe
/
SAPQOS2.CPP
< prev
next >
Wrap
Text File
|
1995-09-14
|
8KB
|
284 lines
/****************************************************************************
** File: QUERYSAP.CPP
**
** Desc: Sample General Service Query Program
**
** Run QUERYSAP command line. This program sends out
** a general service query (or nearest service query) for some file
** type, then prints the response packet.
**
**
**
**
**
** 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
** DRS Dan Stratton Novell Developer Support
**
** History:
**
** When Who What
** -----------------------------------------------------------------------
** 08-08-94 klb First code.
** 02-06-95 DRS Modified for OS/2.
** 09-14-95 DRS Modified serverType to be consistent with DOS QueryServices.
*/
#define NWOS2
#define IS32BIT
/* For now, just allow to run with either Borland or IBM */
#if defined (__BORLANDC__)
#define BCPP
#include <mem.h>
#elif (defined (__IBMC__) || defined(__IBMCPP__))
#define CSET2
#include <memory.h>
#endif
#include <os2.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C"{
#endif
#include <nwcalls.h>
#include <ipxcalls.h>
#ifdef __cplusplus
}
#endif
/****************************************************************************
** Global Structure Definitions
*/
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;
/* **********************************************************************
Function Prototypes
********************************************************************** */
int QueryServices(WORD queryType, WORD serverType, WORD returnSize, SAP_RECORD *serviceBuffer);
/* ***********************************************************************
QueryServices
This call will query the net for servers of a specific type.
It will do general service queries or nearest service queries.
NOTE: The parameters are the same as DOS, but we're not doing
anything with returnSize right now. QueryServices is just returning
a single response. This is basic functionality. You really should
modify it for your own needs.
*********************************************************************** */
int QueryServices(WORD queryType, WORD serverType, WORD returnSize, SAP_RECORD *serviceBuffer)
{
int ccode, i;
IPX_HEADER sHeader;
IPX_ECB sECB;
IPX_ECB rECB;
IPX_HEADER rHeader;
USHORT Socket=0x0000;
SAP_RECORD sapInfo;
QUERY_PACKET qPacket;
int timeOut = 1000; /* 1 second timeout for response */
/* Pick a good value, it's up to you. */
BOOL fatalError = FALSE;
ccode = IpxOpenSocket((USHORT NWPTR)&Socket);
if(ccode)
{
printf("Error: IpxOpenSocket returned %04X",ccode);
return (1);
}
/*------------------------------------------------------------------------
** Initialize fields for Receive IPX Header and Receive ECB
*/
rHeader.packetType = (char)4;
rHeader.packetLen = NWWordSwap(sizeof(IPX_HEADER));
rECB.fragCount = 2;
rECB.fragList[0].fragAddress = &rHeader;
rECB.fragList[0].fragSize = sizeof(IPX_HEADER);
rECB.fragList[1].fragAddress = &sapInfo;
rECB.fragList[1].fragSize = sizeof(sapInfo);
sHeader.destNet=0x00; /* send to the local net */
for (i=0; i<6; ++i)
sHeader.destNode[i] = (BYTE)0xFF;
sHeader.destSocket= NWWordSwap(0x0452);
/*------------------------------------------------------------------------
** Query Services Packet
*/
if(queryType == 0x01)
qPacket.queryType = NWWordSwap(0x01); // General Service Query
else if(queryType == 0x03)
qPacket.queryType = NWWordSwap(0x03); // Nearest Service Query
else
{
printf("Invalid queryType\n");
return (1);
}
qPacket.serverType = NWWordSwap(serverType);
sHeader.packetLen = NWWordSwap(sizeof(IPX_HEADER));
sHeader.packetType = 4;
sECB.fragCount = 2;
for (i=0; i<6; ++i)
sECB.immediateAddress[i] = 0xFF;
sECB.fragList[0].fragAddress = (&sHeader);
sECB.fragList[0].fragSize = sizeof(IPX_HEADER);
sECB.fragList[1].fragAddress = (&qPacket);
sECB.fragList[1].fragSize = sizeof(QUERY_PACKET);
/*------------------------------------------------------------------------
** Send out the Query Packet!
*/
ccode = IpxSend(Socket,&sECB);
if(ccode)
{
printf("Error sending query, IpxSend returned %04X\n",ccode);
return 1;
}
ccode=IpxReceive(Socket,timeOut,&rECB);
switch(ccode)
{
case 0x0000: memcpy(serviceBuffer, &sapInfo, sizeof(SAP_RECORD));
fatalError = FALSE;
break;
case 0x9001: printf("QueryServices timed out\n");
fatalError = TRUE;
break;
case 0x8007: fatalError = TRUE;
break;
case 0x8002: printf("\nError: Bad Packet Received\n");
fatalError = TRUE;
break;
case 0x8006: printf("\nError: Receive Overflow, buffer too small.\n");
memcpy(serviceBuffer, &sapInfo, sizeof(SAP_RECORD));
fatalError = FALSE;
break;
case 0x9004: printf("Error: Socket not open.\n");
fatalError = TRUE;
break;
default: printf("Unknown error during IPXReceive. 04X",ccode);
fatalError = TRUE;
break; }
IpxCloseSocket(Socket);
if(fatalError)
return 1;
else
return 0;
}
/****************************************************************************
** This function is the entire program, as it is very simple.
**
*/
void main(void)
{
int ccode;
WORD queryType;
WORD serverType;
SAP_RECORD serviceBuffer;
queryType = 0x03; /* NSQ, queryType of 0x01 would be GSQ */
serverType = 0x0ABC; /* Type of server you are looking for */
ccode = QueryServices(queryType, serverType, sizeof(serviceBuffer), &serviceBuffer);
if(ccode ==0)
{
printf("\n");
printf(" Server : %-47.47s", serviceBuffer.serverName);
printf(" Type.. : %04X\n", NWWordSwap(serviceBuffer.serverType));
printf(" Address: %02X%02X%02X%02X:%02X%02X%02X%02X%02X%02X:%04X",
serviceBuffer.network[0],
serviceBuffer.network[1],
serviceBuffer.network[2],
serviceBuffer.network[3],
serviceBuffer.node[0],
serviceBuffer.node[1],
serviceBuffer.node[2],
serviceBuffer.node[3],
serviceBuffer.node[4],
serviceBuffer.node[5],
NWWordSwap(serviceBuffer.sock));
printf(" Hops: %d\n", NWWordSwap(serviceBuffer.intNetworks));
}
}