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

  1. /****************************************************************************
  2. **    File:    SAPIT.C
  3. **
  4. **    Desc:    Sample SAP Advertise
  5. **
  6. **        This is a Partner program with SAPQ.EXE. This program must be run first.
  7. **        This program simply advertises itself as a specific SAP server type
  8. **        and then drops in the a "listen loop" receiving IPX packets from a
  9. **        client node. The data is then removed from the packet and displayed
  10. **     on the screen.
  11. **
  12. **        DISCLAIMER  
  13. **  
  14. **    Novell, Inc. makes no representations or warranties with respect to
  15. **    any NetWare software, and specifically disclaims any express or
  16. **    implied warranties of merchantability, title, or fitness for a
  17. **    particular purpose.  
  18. **
  19. **    Distribution of any NetWare software is forbidden without the
  20. **    express written consent of Novell, Inc.  Further, Novell reserves
  21. **    the right to discontinue distribution of any NetWare software.
  22. **    
  23. **    Novell is not responsible for lost profits or revenue, loss of use
  24. **    of the software, loss of data, costs of re-creating lost data, the
  25. **    cost of any substitute equipment or program, or claims by any party
  26. **    other than you.  Novell strongly recommends a backup be made before
  27. **    any software is installed.   Technical support for this software
  28. **    may be provided at the discretion of Novell.
  29. **
  30. **    Programmers:
  31. **
  32. **        Ini    Who                        Firm
  33. **        -----------------------------------------------------------------------
  34. **        KLB    Karl L Bunnell                Novell Developer Support.
  35. **
  36. **    History:
  37. **
  38. **        When        Who    What
  39. **        -----------------------------------------------------------------------
  40. **        09-14-94    KLB    First code.
  41. */
  42.  
  43. /****************************************************************************
  44. **    Include headers, macros, function prototypes, etc.
  45. */
  46.  
  47.     /*------------------------------------------------------------------------
  48.     **    ANSI
  49.     */
  50.     #include <stdio.h>
  51.     #include <conio.h>
  52.  
  53.     /*------------------------------------------------------------------------
  54.     **    SAP and NetWare 
  55.     */
  56.     #include <sap.h>
  57.     #include <nit.h>
  58.  
  59. /****************************************************************************
  60. **    This function is the entire program.
  61. **    Simply run SAPIT from the command line. This code advertises a service
  62. ** and then drops into a listen loop waiting for a client to connect.
  63. ** Once a client begins sending IPX packets to this node, the data portion
  64. ** of the IPX packet is stripped out and displayed on the screen.
  65. ** 
  66. */
  67.  
  68. main()
  69. {
  70.     WORD            sType, Socket = 0x9000;
  71.     char            sName[48];
  72.     BYTE            sSocket[2];
  73.     int            ccode;
  74.     char            c, *cPtr, character='\0';
  75.     char            *msg;
  76.     ECB            *rECB;
  77.     IPXHeader    *rHeader;
  78.     int            i;
  79.  
  80.     /*------------------------------------------------------------------------
  81.     **    Set up and Advertise service
  82.     */
  83.  
  84.     sType = 0x9001;
  85.     strcpy(sName,"SAP_ServerName");
  86.     *(WORD *)&sSocket[0] = 0x9000;
  87.     ccode = AdvertiseService(sType, sName, sSocket);
  88.     printf("Completion code was %02X", ccode);
  89.     c=getch();
  90.  
  91.  
  92.     ccode = IPXInitialize();
  93.     if(ccode)
  94.         printf("IPX is not loaded");
  95.  
  96.     IPXOpenSocket((BYTE *)&sSocket, (BYTE)0);
  97.  
  98.     if((rECB = (ECB *)malloc(sizeof(ECB))) == (ECB *)NULL)
  99.         printf("Out of memory1");
  100.  
  101.     printf("\nsize = %d\n",sizeof(IPXHeader));
  102.  
  103.     rHeader=(IPXHeader *)malloc(sizeof(IPXHeader));
  104.  
  105.     if((msg = (char *)malloc(sizeof(char))) == (ECB *)NULL)
  106.         printf("Out of memory3");
  107.     rHeader->packetType = (char)4;
  108.     rHeader->length = IntSwap(sizeof(IPXHeader));
  109.  
  110.     rECB->ESRAddress = (void far *)NULL;
  111.     rECB->socketNumber= Socket;
  112.     rECB->fragmentCount = 2;
  113.     rECB->fragmentDescriptor[0].address = rHeader;
  114.     rECB->fragmentDescriptor[0].size = sizeof(IPXHeader);
  115.     rECB->fragmentDescriptor[1].address = msg;
  116.     rECB->fragmentDescriptor[1].size = sizeof(char);
  117.  
  118.     /*------------------------------------------------------------------------
  119.     **    Wait in listen loop receiving packets until a '~' character is received.
  120.     */
  121.  
  122.     IPXListenForPacket(rECB);
  123.     
  124.     printf("\n Waiting for packet: \n");
  125.  
  126.     while(character != '~')
  127.         {
  128.  
  129.         while(rECB->inUseFlag)
  130.             IPXRelinquishControl();
  131.  
  132.         cPtr = (char *)(rECB->fragmentDescriptor[1].address);
  133.         memcpy(&character, cPtr, 1);
  134.  
  135.         printf("%c",character);
  136.        IPXListenForPacket(rECB);
  137.  
  138.         }
  139.     printf("\nClosing Socket and shutting down SAP\n");
  140.  
  141.     IPXCloseSocket(Socket);    
  142.     ccode = ShutdownSAP();
  143. }
  144.