home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
glttst.exe
/
GLTTEST.C
next >
Wrap
Text File
|
1995-09-08
|
10KB
|
298 lines
/*
Copyright (c) 1992 Novell, Inc. All Rights Reserved.
THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND
TREATIES. USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE
LICENSE AGREEMENT ACCOMPANYING THE SOFTWARE DEVELOPMENT KIT (SDK)
THAT CONTAINS THIS WORK.
Pursuant to the SDK License Agreement, Novell hereby grants to
Developer a royalty-free, non-exclusive license to include the
sample code GLTTEST.C and derivative binaries in its product.
Novell grants to Developer worldwide distribution rights to market,
distribute or sell the sample code GLTTEST.C and derivative
binaries as a component of Developer's product(s). Novell shall
have no obligations to Developer or Developer's customers with
respect to this code.
DISCLAIMER:
Novell, Inc. makes no representations or warranties with respect
to the contents or use of this code, and specifically disclaims any
express or implied warranties of merchantability or fitness for any
particular purpose. Further, Novell, Inc. reserves the right to revise
this publication and to make changes to its content, at any time,
without obligation to notify any person or entity of such revisions or
changes.
Further, Novell, Inc. makes no representations or warranties with
respect to any software, and specifically disclaims any express or
implied warranties of merchantability or fitness for any particular
purpose. Further, Novell, Inc. reserves the right to make changes to
any and all parts of the software, at any time, without obligation to
notify any person or entity of such changes.
***************************************************************************
GLTTEST.C
**************************************************************************/
/**************************************************************************
** Description: This program demonstates how to properly set-up and call
** IPXGetLocalTarget() and IPXGetLocalTargetAsync(). Note:
** in order for IPXGetLocalTargetAsync() to function properly
** you must have an NWIPXSPX.DLL dated 08/25/95 or later. This
** was broken in versions of NWIPXSPX.DLL previous to this version.
** In order to ensure that testing can be done with this source the
** NWIPXSPX.DLL and *.LIB are included. These are not to be
** distributed with your application. This DLL has a beta string that
** identifies it as a beta file. When NWIPXSPX.DLL has been tested
** and found suitable for public distribution it will be available
** on CompuServe -> NOVFILES -> NWDLLSx.EXE. The header files have
** also been updated so the appropriate Windows Messages could be added.
** The following messages were added: IMMEDIATE_ADDRESS_FAILED -- 0x6666
** IMMEDIATE_ADDRESS_COMPLETE -- 0x7777. The header file effected is
** NXTW.H. (This header file is included by NWIPXSPX.H).
** A fixed version of NWIPXSPX.DLL will ship on Volume 6 of NetWare
** Client SDK.
**
** Compiler: Borland C++ v4.5
**
** Programmer : Karl Bunnell
** Date: 08/24/1995
**
*/
#include <windows.h>
#define NWWIN
//#include <nwipxspx.h> /* I'm using the fixed header file NXTW.H */
#include <mem.h>
#include "glttest.h"
#include "nxtw.h"
#include <ctype.h>
long FAR PASCAL _export WndProc(HWND, UINT, UINT, LONG);
BOOL strToHex(char *ascii, unsigned char *hex, int length);
HANDLE globalhInstance;
DWORD IPXTaskID;
/*-----------------------------------------------------------------------------
**
*/
int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
static char szAppName[] = "GLTTEST";
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
lpszCmdLine = lpszCmdLine;
if(!hPrevInstance)
{
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = DLGWINDOWEXTRA;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = COLOR_WINDOW + 1;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
RegisterClass(&wndclass);
}
globalhInstance = hInstance;
hwnd = CreateDialog(hInstance, szAppName, 0, NULL);
SendMessage(hwnd, WM_INITDIALOG, NULL, NULL);
ShowWindow(hwnd, nCmdShow);
while(GetMessage(&msg, NULL, 0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
/*-----------------------------------------------------------------------------
**
*/
long FAR PASCAL _export WndProc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
{
int i;
WORD rc;
int transportTime;
char netString[27];
char tempString[25];
static IPXAddress netAddress;
static BYTE receiveBuffer[100];
static BYTE sendBuffer[100];
static BYTE immediate[6];
static AGLT sendAGLT;
static AGLT listenAGLT;
ECB *receivedImmediate;
char temp[1024];
int strCount = 0;
switch (message)
{
case WM_INITDIALOG:
IPXTaskID=0;
IPXInitialize(&IPXTaskID,2,sizeof(IPXHeader)+546);
break;
case WM_COMMAND:
switch(wParam)
{
case IDC_PUSHBUTTON1:
SendDlgItemMessage(hwnd, IDC_EDIT1, WM_GETTEXT, 100, (LONG)(LPSTR)netString);
for(i=0; i<sizeof(netString); ++i)
{
if(netString[i] != ':')
{
tempString[strCount] = netString[i];
strCount +=1;
}
}
strToHex(tempString, (unsigned char *)&netAddress, 12);
rc = IPXGetLocalTarget( IPXTaskID,
(BYTE far *)&netAddress,
(BYTE far *)immediate,
(int *)&transportTime );
if(rc)
{
wsprintf(temp, "IPXGetLocalTarget() returned %d\n", rc);
MessageBox(NULL, temp,"Error!", MB_OK);
return(FALSE);
}
wsprintf(temp, "Immediate address: %02X%02X%02X%02X%02X%02X",
immediate[0], immediate[1], immediate[2],
immediate[3], immediate[4], immediate[5]);
MessageBox(NULL, temp,"Success!", MB_OK);
break;
case IDC_PUSHBUTTON2:
PostMessage(hwnd, WM_DESTROY, 0, 0);
break;
case IDC_PUSHBUTTON3:
SendDlgItemMessage(hwnd, IDC_EDIT1, WM_GETTEXT, 100, (LONG)(LPSTR)netString);
for(i=0; i<sizeof(netString); ++i)
{
if(netString[i] != ':')
{
tempString[strCount] = netString[i];
strCount +=1;
}
}
strToHex(tempString, (unsigned char *)&netAddress, 12);
/*-----------------------------------------------------------------------------
** Please note that the developer is responsible for setting up send and receive
** fragments of the nested ECB structure within the AGLT structure.
** The strToHex() function is used to populate the netAddress which is passed
** as the 3rd parameter to IPXGetLocalTargetAsync().
*/
memset(sendBuffer, '\0', sizeof(sendBuffer));
sendAGLT.ecb.fragmentDescriptor[0].address = sendBuffer;
sendAGLT.ecb.fragmentDescriptor[0].size = sizeof(sendBuffer);
memset(receiveBuffer, '\0', sizeof(receiveBuffer));
listenAGLT.ecb.fragmentDescriptor[0].address = receiveBuffer;
listenAGLT.ecb.fragmentDescriptor[0].size = sizeof(receiveBuffer);
sendAGLT.taskID = IPXTaskID;
sendAGLT.hWnd = hwnd;
listenAGLT.taskID = IPXTaskID;
listenAGLT.hWnd = hwnd;
IPXGetLocalTargetAsync(
/* Pointer to send AGLT */ (AGLT FAR *)&listenAGLT,
/* Pointer to rec AGLT */ (AGLT FAR *)&sendAGLT,
/* Pointer to dest. net */ (BYTE FAR *)&netAddress
);
break;
}
return(TRUE);
/*-----------------------------------------------------------------------------
** The following 2 messages IMMEDIATE_ADDRESS_FAILED and
** IMMEDIATE_ADDRESS_COMPLETE are defined in NXTW.H. Note that a pointer to
** the received ECB is passed in lparam. Simply extract the immediate address
** from the immediate address of the passed ECB. To be safe, you sould not
** allow your program to be terminated until one of the following messages
** is received by your application. Failure to allow NWIPXSPX.DLL to
** clean up after this call could compromise system stability.
*/
case IMMEDIATE_ADDRESS_FAILED:
wsprintf(temp, "IPXGetLocalTargetAsync() returned IMMEDIATE_ADDRESS_FAILED! ");
MessageBox(NULL, temp,"IPXGetLocalTargetAsync()", MB_OK);
break;
case IMMEDIATE_ADDRESS_COMPLETE:
receivedImmediate = (ECB FAR *)lParam;
memcpy(&immediate, &receivedImmediate->immediateAddress, 6);
wsprintf(temp, "Immediate address: %02X%02X%02X%02X%02X%02X",
immediate[0], immediate[1], immediate[2],
immediate[3], immediate[4], immediate[5]);
MessageBox(NULL, temp,"Success!", MB_OK);
break;
case WM_DESTROY :
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
BOOL strToHex(char *ascii, unsigned char *hex, int length)
{
int i, j;
char tmp_char;
for (i=0, j=0; i<2*length; i+=2,j++)
{
if (!isxdigit(tmp_char=toupper(ascii[i])) )
{
return 0;
}
else
hex[j] = ((tmp_char>'9') ? (tmp_char-0x37) : (tmp_char-0x30)) << 4;
if(!isxdigit(tmp_char=toupper(ascii[i+1])) )
{
return 0;
}
else
hex[j] += (tmp_char > '9') ? (tmp_char-0x37) : (tmp_char-0x30);
}
return 1;
}