home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / sapit.exe / SAPQ.C < prev   
Text File  |  1994-07-29  |  4KB  |  120 lines

  1. /****************************************************************************
  2. **    File:    SAPQ.C
  3. **
  4. **    Desc:    Sample SAP QUERY
  5. **
  6. **        This program simply issues a SAP query for a specific server type.
  7. **
  8. **
  9. **        DISCLAIMER  
  10. **  
  11. **    Novell, Inc. makes no representations or warranties with respect to
  12. **    any NetWare software, and specifically disclaims any express or
  13. **    implied warranties of merchantability, title, or fitness for a
  14. **    particular purpose.  
  15. **
  16. **    Distribution of any NetWare software is forbidden without the
  17. **    express written consent of Novell, Inc.  Further, Novell reserves
  18. **    the right to discontinue distribution of any NetWare software.
  19. **    
  20. **    Novell is not responsible for lost profits or revenue, loss of use
  21. **    of the software, loss of data, costs of re-creating lost data, the
  22. **    cost of any substitute equipment or program, or claims by any party
  23. **    other than you.  Novell strongly recommends a backup be made before
  24. **    any software is installed.   Technical support for this software
  25. **    may be provided at the discretion of Novell.
  26. **
  27. **    Programmers:
  28. **
  29. **        Ini    Who                        Firm
  30. **        -----------------------------------------------------------------------
  31. **        KLB    Karl L Bunnell                Novell Developer Support.
  32. **
  33. **    History:
  34. **
  35. **        When        Who    What
  36. **        -----------------------------------------------------------------------
  37. **        09-14-94    KLB    First code.
  38. */
  39.  
  40. /****************************************************************************
  41. **    Include headers, macros, function prototypes, etc.
  42. */
  43.  
  44.     /*------------------------------------------------------------------------
  45.     **    ANSI
  46.     */
  47.     #include <stdio.h>
  48.  
  49.     /*------------------------------------------------------------------------
  50.     **    SAP and NetWare 
  51.     */
  52.     #include <sap.h>
  53.     #include <nwmisc.h>
  54.  
  55. /****************************************************************************
  56. **    This function is the entire program.
  57. **    Simply run SAPQ from the command line. This code will strip out the
  58. ** Network:Node:Socket for the Advertising server and build an IPX packet
  59. ** with each keystroke that is entered and send it to the server machine
  60. ** running SAPIT and diplay the keystroke on the screen.    Pressing the tilde
  61. ** '~' key will terminate the session on both ends.
  62. */
  63.  
  64.  
  65. main()
  66. {
  67.     WORD             sType, qType, rSize, Socket = 0x9000;
  68.     SAP            sBuf;
  69.     int            ccode;
  70.     char            msg, c='\0';
  71.     IPXHeader    sHeader;
  72.     ECB            sECB;
  73.  
  74.     sType = 0x9001;
  75.     qType = 0x3;
  76.     rSize = 96;
  77.  
  78.     /*------------------------------------------------------------------------
  79.     **    Query services and build IPX packets to send key stroke characters.
  80.     */
  81.  
  82.     ccode = QueryServices (qType, sType, rSize, &sBuf);
  83.  
  84.     printf("Server Type is: %2X\n", IntSwap(sBuf.ServerType));
  85.     printf("Server name is: %s\n", sBuf.ServerName);
  86.     
  87.     ccode = IPXInitialize();
  88.  
  89.     memcpy(sHeader.destination.network, sBuf.Network, 4);
  90.     memcpy(sHeader.destination.node, sBuf.Node,6);
  91.     memcpy(sHeader.destination.socket, sBuf.Socket, 2);
  92.     sHeader.length = IntSwap(sizeof(IPXHeader));
  93.     sHeader.packetType = 4;
  94.  
  95.     sECB.ESRAddress = 0;
  96.     sECB.inUseFlag = 0;
  97.     sECB.fragmentCount = 2;
  98.     sECB.socketNumber = Socket;
  99.     memcpy(sECB.immediateAddress, sBuf.Node, 6);
  100.     sECB.fragmentDescriptor[0].address = (&sHeader);
  101.     sECB.fragmentDescriptor[0].size = sizeof(IPXHeader);
  102.     sECB.fragmentDescriptor[1].address = (&msg);
  103.     sECB.fragmentDescriptor[1].size = sizeof(char);
  104.  
  105.     /*------------------------------------------------------------------------
  106.     **    Remain in Send Loop until a '~' key is pressed.
  107.     */
  108.  
  109.     while(c != '~')
  110.         {
  111.         c=getch();
  112.         msg=(char)c;
  113.         IPXSendPacket(&sECB);
  114.         while(sECB.inUseFlag)
  115.             IPXRelinquishControl();
  116.         }
  117.  
  118.     IPXCloseSocket(Socket);
  119. }
  120.