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 >
Text File  |  1995-09-08  |  10KB  |  298 lines

  1. /*
  2.  
  3. Copyright (c) 1992 Novell, Inc.  All Rights Reserved.
  4.  
  5. THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND
  6. TREATIES.  USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE
  7. LICENSE AGREEMENT ACCOMPANYING THE SOFTWARE DEVELOPMENT KIT (SDK)
  8. THAT CONTAINS THIS WORK.
  9.  
  10. Pursuant to the SDK License Agreement, Novell hereby grants to
  11. Developer a royalty-free, non-exclusive license to include the
  12. sample code GLTTEST.C and derivative binaries in its product.
  13. Novell grants to Developer worldwide distribution rights to market,
  14. distribute or sell the sample code GLTTEST.C and derivative
  15. binaries as a component of Developer's product(s).  Novell shall
  16. have no obligations to Developer or Developer's customers with
  17. respect to this code.
  18.  
  19. DISCLAIMER:
  20.  
  21.     Novell, Inc. makes no representations or warranties with respect
  22. to the contents or use of this code, and specifically disclaims any
  23. express or implied warranties of merchantability or fitness for any
  24. particular purpose.  Further, Novell, Inc. reserves the right to revise
  25. this publication and to make changes to its content, at any time,
  26. without obligation to notify any person or entity of such revisions or
  27. changes.
  28.  
  29.     Further, Novell, Inc. makes no representations or warranties with
  30. respect to any software, and specifically disclaims any express or
  31. implied warranties of merchantability or fitness for any particular
  32. purpose.  Further, Novell, Inc. reserves the right to make changes to
  33. any and all parts of the software, at any time, without obligation to
  34. notify any person or entity of such changes.
  35.  
  36. ***************************************************************************
  37.     GLTTEST.C
  38. **************************************************************************/
  39.  
  40. /**************************************************************************
  41. ** Description: This program demonstates how to properly set-up and call 
  42. **                  IPXGetLocalTarget() and IPXGetLocalTargetAsync(). Note:
  43. **              in order for IPXGetLocalTargetAsync() to function properly
  44. **              you must have an NWIPXSPX.DLL dated 08/25/95 or later. This
  45. **                 was broken in versions of NWIPXSPX.DLL previous to this version.
  46. **              In order to ensure that testing can be done with this source the
  47. **              NWIPXSPX.DLL and *.LIB are included. These are not to be 
  48. **              distributed with your application. This DLL has a beta string that
  49. **              identifies it as a beta file. When NWIPXSPX.DLL has been tested
  50. **              and found suitable for public distribution it will be available
  51. **              on CompuServe -> NOVFILES -> NWDLLSx.EXE. The header files have
  52. **              also been updated so the appropriate Windows Messages could be added.
  53. **              The following messages were added: IMMEDIATE_ADDRESS_FAILED -- 0x6666
  54. **              IMMEDIATE_ADDRESS_COMPLETE -- 0x7777. The header file effected is
  55. **              NXTW.H. (This header file is included by NWIPXSPX.H).
  56. **              A fixed version of NWIPXSPX.DLL will ship on Volume 6 of NetWare
  57. **              Client SDK. 
  58. **               
  59. ** Compiler:     Borland C++ v4.5
  60. **
  61. ** Programmer :  Karl Bunnell
  62. ** Date:         08/24/1995
  63. **
  64. */
  65.  
  66. #include <windows.h>
  67. #define NWWIN
  68. //#include <nwipxspx.h>     /* I'm using the fixed header file NXTW.H */
  69. #include <mem.h>
  70. #include "glttest.h"
  71. #include "nxtw.h"
  72. #include <ctype.h>
  73.  
  74. long FAR PASCAL _export WndProc(HWND, UINT, UINT, LONG);
  75.  
  76. BOOL strToHex(char *ascii, unsigned char *hex, int length);
  77. HANDLE globalhInstance;
  78. DWORD IPXTaskID;
  79.  
  80. /*-----------------------------------------------------------------------------
  81. **
  82. */
  83. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  84.                                         LPSTR lpszCmdLine, int nCmdShow)
  85.  
  86. {
  87.     static char    szAppName[] = "GLTTEST";
  88.     HWND                hwnd;
  89.     MSG                    msg;
  90.     WNDCLASS        wndclass; 
  91.     lpszCmdLine = lpszCmdLine;
  92.  
  93.     if(!hPrevInstance)
  94.     {
  95.         wndclass.style                    = CS_HREDRAW | CS_VREDRAW;
  96.  
  97.         wndclass.lpfnWndProc        =    WndProc;
  98.         wndclass.cbClsExtra            =    0;
  99.         wndclass.cbWndExtra            =    DLGWINDOWEXTRA;
  100.         wndclass.hInstance            =    hInstance;
  101.         wndclass.hIcon                    =    LoadIcon(NULL, IDI_APPLICATION);
  102.         wndclass.hCursor                = LoadCursor(NULL, IDC_ARROW);
  103.         wndclass.hbrBackground    = COLOR_WINDOW + 1;
  104.         wndclass.lpszMenuName        =    NULL;
  105.         wndclass.lpszClassName    = szAppName;
  106.  
  107.         RegisterClass(&wndclass);
  108.     }
  109.     globalhInstance = hInstance;
  110.     hwnd = CreateDialog(hInstance, szAppName, 0, NULL);
  111.     SendMessage(hwnd, WM_INITDIALOG, NULL, NULL);
  112.     ShowWindow(hwnd, nCmdShow);
  113.     while(GetMessage(&msg, NULL, 0,0))
  114.     {
  115.         TranslateMessage(&msg);
  116.         DispatchMessage(&msg);
  117.     }
  118.     return msg.wParam;
  119.  
  120. }
  121. /*-----------------------------------------------------------------------------
  122. **
  123. */
  124.  
  125. long FAR PASCAL _export WndProc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
  126. {
  127.      int i;
  128.      WORD  rc;
  129.      int transportTime;
  130.      char     netString[27];
  131.      char  tempString[25];
  132.      static     IPXAddress    netAddress;
  133.      static     BYTE receiveBuffer[100];
  134.      static     BYTE sendBuffer[100];
  135.      static     BYTE immediate[6];
  136.      static     AGLT    sendAGLT;
  137.      static     AGLT listenAGLT;
  138.      ECB *receivedImmediate;
  139.      char    temp[1024];
  140.      int strCount = 0;
  141.  
  142.      switch (message)
  143.      {
  144.           case WM_INITDIALOG:
  145.                 IPXTaskID=0;
  146.                 IPXInitialize(&IPXTaskID,2,sizeof(IPXHeader)+546);
  147.  
  148.                 break;
  149.           case WM_COMMAND:
  150.                 switch(wParam)
  151.                 {
  152.                      case IDC_PUSHBUTTON1:
  153.  
  154.                      SendDlgItemMessage(hwnd, IDC_EDIT1, WM_GETTEXT, 100, (LONG)(LPSTR)netString);
  155.  
  156.                     for(i=0; i<sizeof(netString); ++i)
  157.                         {
  158.                         if(netString[i] != ':')
  159.                             {
  160.                             tempString[strCount] = netString[i];
  161.                             strCount +=1;
  162.                             }
  163.                         }
  164.  
  165.                     strToHex(tempString, (unsigned char *)&netAddress, 12);
  166.  
  167.                      rc = IPXGetLocalTarget( IPXTaskID,
  168.                                         (BYTE far *)&netAddress,
  169.                                         (BYTE far *)immediate,
  170.                                         (int *)&transportTime ); 
  171.  
  172.                      if(rc)
  173.                         {
  174.                         wsprintf(temp, "IPXGetLocalTarget() returned %d\n", rc);
  175.                         MessageBox(NULL, temp,"Error!", MB_OK);
  176.                         return(FALSE);
  177.                         }    
  178.  
  179.                      
  180.                      wsprintf(temp, "Immediate address: %02X%02X%02X%02X%02X%02X", 
  181.                                             immediate[0], immediate[1], immediate[2],
  182.                                             immediate[3], immediate[4], immediate[5]);
  183.  
  184.                      MessageBox(NULL, temp,"Success!", MB_OK);
  185.                      
  186.                         
  187.                       break;
  188.  
  189.                      case IDC_PUSHBUTTON2:
  190.                             PostMessage(hwnd, WM_DESTROY, 0, 0);
  191.                             break;
  192.  
  193.                      case IDC_PUSHBUTTON3:
  194.  
  195.                      SendDlgItemMessage(hwnd, IDC_EDIT1, WM_GETTEXT, 100, (LONG)(LPSTR)netString);
  196.                      for(i=0; i<sizeof(netString); ++i)
  197.                         {
  198.                         if(netString[i] != ':')
  199.                             {
  200.                             tempString[strCount] = netString[i];
  201.                             strCount +=1;
  202.                             }
  203.                         }
  204.  
  205.                      strToHex(tempString, (unsigned char *)&netAddress, 12);
  206.  
  207.                   /*-----------------------------------------------------------------------------
  208.                   ** Please note that the developer is responsible for setting up send and receive
  209.                   ** fragments of the nested ECB structure within the AGLT structure.
  210.                   ** The strToHex() function is used to populate the netAddress which is passed 
  211.                   ** as the 3rd parameter to IPXGetLocalTargetAsync().
  212.                   */
  213.  
  214.                      memset(sendBuffer, '\0', sizeof(sendBuffer));
  215.                      sendAGLT.ecb.fragmentDescriptor[0].address = sendBuffer;
  216.                      sendAGLT.ecb.fragmentDescriptor[0].size = sizeof(sendBuffer);
  217.  
  218.                      memset(receiveBuffer, '\0', sizeof(receiveBuffer));
  219.                      listenAGLT.ecb.fragmentDescriptor[0].address = receiveBuffer;
  220.                      listenAGLT.ecb.fragmentDescriptor[0].size = sizeof(receiveBuffer);
  221.                                                                                                     
  222.                      sendAGLT.taskID = IPXTaskID;
  223.                      sendAGLT.hWnd = hwnd;
  224.                      listenAGLT.taskID = IPXTaskID;
  225.                      listenAGLT.hWnd = hwnd;
  226.  
  227.                      IPXGetLocalTargetAsync(
  228.                         /* Pointer to send AGLT */ (AGLT FAR *)&listenAGLT,
  229.                         /* Pointer to rec AGLT  */ (AGLT FAR *)&sendAGLT,
  230.                         /* Pointer to dest. net */ (BYTE FAR *)&netAddress
  231.                         );
  232.  
  233.                      break;
  234.         
  235.                 }
  236.                 return(TRUE);
  237.  
  238.           /*-----------------------------------------------------------------------------
  239.           ** The following 2 messages IMMEDIATE_ADDRESS_FAILED and 
  240.           ** IMMEDIATE_ADDRESS_COMPLETE are defined in NXTW.H. Note that a pointer to
  241.           ** the received ECB is passed in lparam. Simply extract the immediate address
  242.           ** from the immediate address of the passed ECB. To be safe, you sould not
  243.           ** allow your program to be terminated until one of the following messages 
  244.           ** is received by your application. Failure to allow NWIPXSPX.DLL to 
  245.           ** clean up after this call could compromise system stability.
  246.           */
  247.  
  248.           case IMMEDIATE_ADDRESS_FAILED:
  249.                 wsprintf(temp, "IPXGetLocalTargetAsync() returned IMMEDIATE_ADDRESS_FAILED! ");
  250.                 MessageBox(NULL, temp,"IPXGetLocalTargetAsync()", MB_OK);
  251.                 break;
  252.                             
  253.           case IMMEDIATE_ADDRESS_COMPLETE:
  254.                 receivedImmediate = (ECB FAR *)lParam;
  255.                 memcpy(&immediate, &receivedImmediate->immediateAddress, 6);
  256.                 wsprintf(temp, "Immediate address: %02X%02X%02X%02X%02X%02X", 
  257.                                         immediate[0], immediate[1], immediate[2],
  258.                                         immediate[3], immediate[4], immediate[5]);
  259.  
  260.                 MessageBox(NULL, temp,"Success!", MB_OK);
  261.  
  262.                 break;
  263.  
  264.             case WM_DESTROY :
  265.                 PostQuitMessage(0);
  266.                 return 0;
  267.     }
  268.     return DefWindowProc(hwnd, message, wParam, lParam);
  269.  
  270. }
  271.  
  272.  
  273. BOOL strToHex(char *ascii, unsigned char *hex, int length)
  274. {
  275.     int      i, j;
  276.     char     tmp_char;
  277.  
  278.     for (i=0, j=0; i<2*length; i+=2,j++)
  279.         {
  280.         if (!isxdigit(tmp_char=toupper(ascii[i])) )
  281.             {
  282.             return 0;
  283.             }
  284.         else
  285.             hex[j] = ((tmp_char>'9') ? (tmp_char-0x37) : (tmp_char-0x30)) << 4;
  286.  
  287.         if(!isxdigit(tmp_char=toupper(ascii[i+1])) )
  288.             {
  289.             return 0;
  290.             }
  291.         else
  292.             hex[j] += (tmp_char > '9') ? (tmp_char-0x37) : (tmp_char-0x30);
  293.  
  294.         }
  295.     return 1;
  296. }
  297.  
  298.