home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / ipxex3.exe / IPXSEND.CPP < prev   
Text File  |  1995-01-27  |  4KB  |  146 lines

  1.  
  2. /* ***************************************************************************
  3. ** File: IPXSEND.CPP
  4. **
  5. **    Description:
  6. **
  7. **         Sample OS/2 application that demonstrates setting up an IPX
  8. **         sender application.  This file goes along with IPXRECV.CPP,
  9. **         which demonstrates the receiving portion of this code.
  10. **
  11. **    Disclaimer:
  12. **
  13. **         Novell, Inc. makes no representations or warranties with respect to
  14. **         any NetWare software, and specifically disclaims any express or
  15. **         implied warranties of merchantability, title, or fitness for a
  16. **         particular purpose.
  17. **
  18. **         Distribution of any NetWare software is forbidden without the
  19. **         express written consent of Novell, Inc.  Further, Novell reserves
  20. **         the right to discontinue distribution of any NetWare software.
  21. **
  22. **         Novell is not responsible for lost profits or revenue, loss of use
  23. **         of the software, loss of data, costs of re-creating lost data, the
  24. **         cost of any substitute equipment or program, or claims by any party
  25. **         other than you.  Novell strongly recommends a backup be made before
  26. **         any software is installed.   Technical support for this software
  27. **         may be provided at the discretion of Novell.
  28. **
  29. **    Programmers:
  30. **
  31. **         Ini    Who                    Firm
  32. **         -------------------------------------------------------------------
  33. **         DRS    Dan Stratton            Novell Developer Support
  34. **
  35. **    History:
  36. **
  37. **         When        Who    What
  38. **         -------------------------------------------------------------------
  39. **         12-09-94        DRS    First code.
  40. **
  41. */
  42.  
  43.  
  44. #define NWOS2
  45. #define IS32BIT
  46.  
  47. #if defined    (__BORLANDC__)
  48.     #define BCPP
  49. #elif (defined (__IBMC__) || defined(__IBMCPP__))
  50.     #define CSET2
  51. #endif
  52.  
  53.  
  54. #include <os2.h>
  55. #include <stdio.h>
  56. #include <string.h>
  57. #include <ctype.h>
  58. #include <stdlib.h>
  59.  
  60. #ifdef __cplusplus
  61.   extern "C"{
  62. #endif
  63.  
  64. #include <nwcalls.h>
  65. #include <ipxcalls.h>
  66.  
  67. #ifdef __cplusplus
  68.   }
  69. #endif
  70.  
  71. #define MAX_BUF_SIZE        128
  72. #define IPX_DESTSOCKET    0x4545
  73. #define NUMSENDS        5
  74.  
  75.  
  76. IPX_HEADER  ipxHeader;
  77. IPX_ECB       ipxECB;
  78. BYTE           ipxBuffer[MAX_BUF_SIZE];
  79. USHORT          ipxSocket;
  80. ULONG                   transTime;
  81. NWCONN_HANDLE connectionID;
  82. NWCONN_NUM      connectionNumber;
  83. BYTE                    destAddress[11];
  84. NWNET_ADDR        NetAddr;
  85.  
  86.  
  87. void main(int argc, char *argv[])
  88. {
  89.     UINT16    ccode;
  90.     char buffChar;  /* buffer for character to send */
  91.     int i=0;
  92.  
  93.     NWCallsInit(NULL,NULL);
  94.  
  95.     if ( argc != 2 )
  96.     {
  97.         printf("\nUSAGE: IPXSend <connection #>\n");
  98.         DosExit(EXIT_PROCESS,1);
  99.     }
  100.     ccode = NWGetDefaultConnectionID(&connectionID);
  101.     connectionNumber = atoi(argv[1]);
  102.  
  103.  
  104.     ipxECB.next = NULL;
  105.     ipxECB.prev = NULL;
  106.     ipxECB.fragCount = 2;
  107.     ipxECB.fragList[0].fragAddress = &ipxHeader;
  108.     ipxECB.fragList[0].fragSize = sizeof(IPX_HEADER);
  109.     ipxECB.fragList[1].fragAddress = ipxBuffer;
  110.     ipxECB.fragList[1].fragSize = sizeof(ipxBuffer);
  111.  
  112.     ipxHeader.packetType = 0;
  113.     ipxHeader.destSocket = IPX_DESTSOCKET;
  114.     NWGetInternetAddress(connectionID,connectionNumber,(NWNET_ADDR NWPTR)&NetAddr);
  115.     memcpy(&ipxHeader.destNet,&NetAddr,10);
  116.     ccode = IpxGetLocalTarget((BYTE *)&ipxHeader.destNet,&ipxECB,&transTime);
  117.     if ( ccode )
  118.     {
  119.         printf("\nError: IpxGetLocalTarget return %4.4x\n",ccode);
  120.         DosExit(EXIT_PROCESS,1);
  121.     }
  122.  
  123.     ipxSocket = 0;
  124.     ccode = IpxOpenSocket(&ipxSocket);
  125.  
  126.     if ( ccode != 0 )
  127.     {
  128.         printf("\nError: IpxOpenSocket returned %4.4x\n",ccode);
  129.         DosExit(EXIT_PROCESS,1);
  130.     }
  131.  
  132.     buffChar = 'A';
  133.     for(i=0;i<NUMSENDS;++i)
  134.     {
  135.       memset(ipxBuffer, buffChar ,sizeof(ipxBuffer));
  136.       ccode = IpxSend(ipxSocket,&ipxECB);      if ( ccode )
  137.         printf("\nError: IpxSend returned %4.4x on packet #%d\n",ccode,i+1);
  138.       else
  139.         printf("Packet #%d was sent sucessfully.\n",i+1);
  140.       buffChar++;
  141.     }
  142.  
  143.     IpxCloseSocket(ipxSocket);
  144. }
  145.  
  146.