home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
ipxpng.exe
/
IPXPING.C
next >
Wrap
Text File
|
1995-01-13
|
6KB
|
241 lines
/****************************************************************************
** File: IPXPING.C
**
** Desc: Sample IPX ping program.
**
** This sample code demonstrates how to send a diagnostic
** configuration packet to a node and process the response
** that comes back. Since any node that has IPXODI loaded
** by default has the Diagnostic responder loaded, this code
** can be used to determine if a node is active. This will also
** work with Servers (they also have a diagnostic responder).
**
**
**
** 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
** -----------------------------------------------------------------------
** 01-12-95 klb First code.
*/
/****************************************************************************
** Include headers, macros, function prototypes, etc.
*/
/*------------------------------------------------------------------------
** ANSI
*/
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
/*------------------------------------------------------------------------
** NetWare
*/
#define NWDOS
#include <nwipxspx.h>
#include <nwcalls.h>
#include "ipxping.h"
/*------------------------------------------------------------------------
** Globals
*/
int IpxPing(IPXAddress *netAddress);
int PutAddress (char *string, char *buf, int hexBytes);
/****************************************************************************
** Function main(int argc, char *argv[])
*/
int main(int argc, char *argv[])
{
NWCCODE ccode;
int result, i;
IPXAddress iPXAddress;
char network[9], node[13];
if ((strlen (argv[1]) > 8) || (strlen (argv[2]) > 12) || (argc != 3))
{
printf ("Usage: NWPING <Network address> <Node address>\n");
return (3);
}
ccode = NWCallsInit (NULL,NULL);
if (ccode) return 2;
sprintf (network, "%08s", argv[1]);
strupr (network);
for (i = 0; i < 8; i++) if (network[i] == ' ') network[i] = '0';
sprintf (node, "%012s", argv[2]);
strupr (node);
for (i = 0; i < 12; i++) if (node[i] == ' ') node[i] = '0';
/*** Set up address of target ***/
result = PutAddress (network, iPXAddress.network, 4);
if (result != 1)
{
printf ("Invalid network address.\n");
return 4;
}
result = PutAddress (node, iPXAddress.node, 6);
if (result != 1)
{
printf ("Invalid node address.\n");
return 5;
}
iPXAddress.socket[0] = 0x04;
iPXAddress.socket[1] = 0x56;
result = IpxPing (&iPXAddress);
if (result == 0)
{
printf ("%s:%s is alive\n", network, node);
return 0;
}
else
{
printf ("%s:%s does not respond\n", network, node);
}
return 1;
}
/****************************************************************************
** Function : IpxPing(IPXAddress *netAddress);
** This function sends the IPX Diag. Config. Packet
** and waits for the response.
*/
int IpxPing(IPXAddress *netAddress)
{
WORD Socket=0x0000;
WORD diagSocket = 0x5604;
IPXHeader sHeader;
ECB sECB;
ECB rECB;
IPXHeader rHeader;
cReqPack cReq;
cRepPack cRep;
int ccode, garbage;
time_t baseTime;
time_t currTime;
IPXInitialize();
IPXOpenSocket((BYTE *)&Socket, (BYTE)0);
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 = &cRep;
rECB.fragmentDescriptor[1].size = sizeof(cRep);
IPXListenForPacket(&rECB);
memcpy(&sHeader.destination, netAddress, 12);
memcpy(sHeader.destination.socket, &diagSocket, 2);
cReq.eac = 0;
memcpy(cReq.ea, 0, 6);
sHeader.length = NWWordSwap(sizeof(IPXHeader));
sHeader.packetType = 4;
sECB.ESRAddress = (void far *)NULL;
sECB.inUseFlag = 0;
sECB.fragmentCount = 2;
sECB.socketNumber = Socket;
IPXGetLocalTarget(netAddress, sECB.immediateAddress, &garbage);
sECB.fragmentDescriptor[0].address = (&sHeader);
sECB.fragmentDescriptor[0].size = sizeof(IPXHeader);
sECB.fragmentDescriptor[1].address = (&cReq);
sECB.fragmentDescriptor[1].size = sizeof(cReq);
IPXSendPacket(&sECB);
while(sECB.inUseFlag)
IPXRelinquishControl();
baseTime = time(NULL);
baseTime += 5;
while(rECB.inUseFlag)
{
currTime = time(NULL);
if(currTime >= baseTime)
{
IPXCancelEvent(&rECB);
IPXCloseSocket(Socket);
return(1);
}
IPXRelinquishControl();
}
IPXCloseSocket(Socket);
return(0);
}
/****************************************************************************
** Function : PutAddress()
** This function processes the netaddress passed in on the
** command line to a format usable by the IPXPing() function.
*/
int PutAddress (char *string, char *buf, int hexBytes)
{
int i, j, value;
char c;
for (i = 0; i < hexBytes; i++)
{
value = 0;
for (j = 0; j < 2; j++)
{
value <<= 4;
if ((c = toupper (*string)) >= '0' && c <='9')
value += c - '0';
else if (c >= 'A' && c <= 'F')
value += c - 'A' + 10;
else
return 0;
string ++;
}
*buf++ = value;
}
return 1;
}