home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
ipxsed.exe
/
IPXSND.C
< prev
next >
Wrap
Text File
|
1995-08-25
|
8KB
|
288 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 IPXSND.C and derivative binaries in its product.
Novell grants to Developer worldwide distribution rights to market,
distribute or sell the sample code IPXSND.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.
***************************************************************************
IPXSND.C
**************************************************************************/
/**************************************************************************
** Description: Sample code that demonstrates the how to set up to send
** an IPX packet within Windows. The partner program to this
** one is IPXREC.
** Compiler: Borland C++ v4.5
**
** Programmer : Karl Bunnell
** Date: 08/24/1995
**
*/
#define NWWIN
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <nwcalls.h>
#include <nwnet.h>
#include <nwipxspx.h>
#include <ctype.h>
#include "ipxsnd.h"
BOOL WINAPI MyPeekMessage( MSG FAR *lpMsg, HWND hWnd, UINT uFirst,
UINT uLast, UINT uCommand);
BOOL StartSendingPackets(IPXAddress *netAddress, HWND hwnd);
BOOL strToHex(char *ascii, unsigned char *hex, int length);
long FAR PASCAL _export WndProc(HWND, UINT, UINT, LONG);
HANDLE globalhInstance;
static WORD sendCount=0;
char displayBuffer[60];
int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
static char szAppName[] = "IPXSND";
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
BOOL rval=0;
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;
rval = RegisterClass(&wndclass);
}
globalhInstance = hInstance;
hwnd = CreateDialog(hInstance, szAppName, 0, NULL);
SendMessage(hwnd, WM_INITWINDOW, 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)
{
WORD ccode;
static char inetString[27];
char tempString[25];
static IPXAddress netAddress;
DWORD IPXTaskID=0L;
char displayMessage[100];
int i;
int strCount = 0;
switch(message)
{
case WM_INITWINDOW:
ccode = IPXInitialize(&IPXTaskID, 2, 576);
if(ccode)
{
wsprintf(displayMessage, "IPXInitialize returned %02X", ccode);
MessageBox(NULL, (LPSTR)displayMessage, "Error!", IDOK);
return FALSE;
}
break;
case WM_COMMAND :
switch(wParam)
{
case IDC_SEND :
SendDlgItemMessage(hwnd, IDC_NETADDR, WM_GETTEXT, sizeof(inetString),
(LONG) (LPSTR) inetString);
if(strlen(inetString) == 0)
{
MessageBox(NULL, (LPSTR)"You must enter a socket to send to!", "Error!", IDOK);
break;
}
for(i=0; i<sizeof(inetString); ++i)
{
if(inetString[i] != ':')
{
tempString[strCount] = inetString[i];
strCount +=1;
}
}
ccode = strToHex(tempString, (unsigned char *)&netAddress, 12);
StartSendingPackets(&netAddress, hwnd);
SendDlgItemMessage(hwnd, IDC_DISPLAY, WM_SETTEXT, 0,
(LONG) (LPSTR) displayBuffer);
break;
case IDC_STOP:
PostMessage(hwnd, WM_DESTROY, 0, 0);
break;
}
return 0;
case WM_DESTROY :
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
BOOL StartSendingPackets(IPXAddress *netAddress, HWND hwnd)
{
static IPXHeader sHeader;
static ECB sECB;
DWORD IPXTaskID = 0L;
int transportTime;
DISPLAYDATA displayData;
MSG msg;
memcpy(sHeader.destination.network, netAddress->network, 4);
memcpy(sHeader.destination.node, netAddress->node,6);
memcpy(sHeader.destination.socket, netAddress->socket, 2);
sHeader.length = NWWordSwap(sizeof(IPXHeader));
sHeader.packetType = 4;
sECB.ESRAddress = 0;
sECB.inUseFlag = 0;
sECB.fragmentCount = 2;
sECB.socketNumber = *(WORD *)&netAddress->socket;
IPXGetLocalTarget( IPXTaskID,
(BYTE far *)netAddress,
(BYTE far *)sECB.immediateAddress,
(int *)&transportTime );
wsprintf(displayData.displayLineOne, "Packet: ");
wsprintf(displayData.displayLineTwo, "%d", sendCount +=1);
sECB.fragmentDescriptor[0].address = (&sHeader);
sECB.fragmentDescriptor[0].size = sizeof(IPXHeader);
sECB.fragmentDescriptor[1].address = (&displayData);
sECB.fragmentDescriptor[1].size = sizeof(DISPLAYDATA);
IPXSendPacket(IPXTaskID, &sECB);
while(sECB.inUseFlag)
{
IPXRelinquishControl();
while (MyPeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
wsprintf(displayBuffer, "%s%s", displayData.displayLineOne, displayData.displayLineTwo);
return 0;
}
BOOL WINAPI MyPeekMessage( MSG FAR *lpMsg, HWND hWnd, UINT uFirst,
UINT uLast, UINT uCommand)
{
BOOL bPeek;
static BOOL bSwitch;
bPeek = PeekMessage(lpMsg, hWnd, uFirst, uLast, uCommand);
if(!bPeek)
{
if (bSwitch)
{
asm {
mov ax, 0x1689
mov bl, 1
int 0x2F
}
}
else
asm int 0x28
bSwitch = !bSwitch;
}
return bPeek;
}
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;
}