home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / opennv.exe / NVIPXWS.C < prev    next >
Text File  |  1992-11-03  |  6KB  |  198 lines

  1. /*
  2. **  (C) Copyright 1992 Novell, Inc.  All rights reserved.
  3. **
  4. **  File: nvipxws.c
  5. **
  6. **  Description: This demonstrates how to send an alert NMVT to a host 
  7. **  using the Open NetView IPX socket-based API.
  8. **
  9. **  Note: This module must be linked with the NetWare C Interface for
  10. **  DOS library, xNIT.LIB and the Novell/Watcom C library, CLIBx.LIB.
  11. **
  12. **  $Logfile:   G:/cs/nma/vcs/nvipxws.c_v  $
  13. **  $Revision:   1.2  $
  14. **  $Date:   03 Nov 1992 18:28:00  $
  15. **  $Author:   RWONG  $
  16. **  $Log:   G:/cs/nma/vcs/nvipxws.c_v  $
  17. ** 
  18. **    Rev 1.2   03 Nov 1992 18:28:00   RWONG
  19. ** Change alert to open failure - token ring lobe.
  20. ** 
  21. **    Rev 1.1   16 Oct 1992 09:23:08   RWONG
  22. ** Modified to use nvipx.h
  23. ** 
  24. **    Rev 1.0   13 Oct 1992 12:15:44   RWONG
  25. ** Initial revision.
  26. */
  27.  
  28. /* many of these are included for function prototypes */
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #include <process.h>
  32. #include <string.h>
  33. //#include <nwbindry.h>
  34. #include <sys\types.h>
  35. #include <nit.h>
  36. #include <nxt.h>
  37.  
  38. #include <cstypes.h>
  39. #include <nmvtdef.h>
  40. #include <nvapi.h>
  41. #include <nvipx.h>
  42.  
  43. /* forward reference */
  44. void     fill_in_msg (void);
  45.  
  46. /*
  47. ** This is the msg data for a fully formatted alert NMVT.
  48. ** This is a OPEN FAILURE alert for a TOKEN RING LOBE
  49. **
  50. ** Generic Alert Description Code Point
  51. **    3211 - open failure
  52. **
  53. ** Probable Causes
  54. **    3702 - token ring lobe
  55. **
  56. ** Failure Causes subfields
  57. **    3320, 3711, 3434, F8E0, 33A5
  58. **
  59. ** Recommended Action subfields
  60. **    1009, 3301, 2010, 3101, 32C0, 31E0
  61. **
  62. ** LAN link connection subsystem data subvector
  63. ** supporting data correlation subfield
  64. **    03 - Local individual Mac Address
  65. */
  66.  
  67. #define NMVTDATALEN  151
  68.  
  69. u8_t  msg[NMVTDATALEN] = {
  70. 0x41,0x03,0x8d,0x00,0x00,0x00,0x00,0x00,0x00,0x8f,0x00,0x00,
  71. 0x23,0x10,0x00,0x20,0x11,0x03,0x13,0x00,0x11,0xF0,0xF3,0xF8,
  72. 0xF6,0x81,0x81,0x81,0x89,0x82,0xF3,0xF4,0xF5,0xF6,0xF4,0xF6,
  73. 0xF7,0x0A,0x0E,0xC9,0xC2,0xD4,0xE3,0xD6,0xD2,0xC5,0xD5,
  74. 0x0b,0x92,0x00,0x00,0x01,0x32,0x11,0x00,0x00,0x00,0x00,0x04,
  75. 0x93,0x37,0x02,0x47,0x96,0x0C,0x01,0x33,0x20,0x37,0x11,  
  76. 0x34,0x34,0xF8,0xE0,0x33,0xA5,0x03,0x83,0x21,0x19,0x82,0x00,
  77. 0x35,0x00,0x49,0x42,0x4D,0x20,0x54,0x4F,0x4B,0x45,0x4E,0x20,
  78. 0x52,0x49,0x4E,0x47,0x20,0x42,0x4F,0x41,0x52,0x44,0x0E,0x81,  
  79. 0x10,0x09,0x33,0x01,0x20,0x10,0x31,0x01,0x32,0xC0,0x31,0xE0,
  80. 0x06,0x82,0x91,0x61,0x01,0xFF,0x06,0x82,0x01,0x07,0x00,0xFF,
  81. 0x03,0x83,0x21,0x0A,0x51,0x08,0x03,0x01,0x02,0x03,0x04,0x05,  
  82. 0x06,0x08,0x01,0x5C,0x09,0x1B,0x0F,0x05,0x2A};
  83.  
  84. /* Buffer for name of the destination server */
  85. char     target_server[49];    
  86.  
  87. /* ECB for the outgoing alert message */
  88. ECB      ecbBuf;               
  89.  
  90. /* IPX address of the sending station */
  91. IPXAddress        source;
  92.  
  93. /*
  94. *  IPX address of the destination.  The reserved field is necessary
  95. *  because addr is obtained using the bindery API call FindPropertyValue
  96. *  which returns 128 bytes.
  97. */
  98. struct Dest_s {                
  99. IPXAddress        addr;
  100. char              reserved[116];
  101. } dest;
  102.  
  103. #define DATABUFLEN   (sizeof(NMVTEvt_t) - 1 + NMVTDATALEN)
  104.  
  105. /* Buffer for the alert and the IPX header */
  106. struct {
  107. IPXHeader      hdr;
  108. unsigned char  ipxData[DATABUFLEN];
  109. } eventBuf;
  110.  
  111.  
  112. void main (void)
  113. {
  114.    u8_t   flag = 0, more = 0;
  115.    u16_t  transport;
  116.  
  117.    if (IPXInitialize () != 0)
  118.       exit (0);
  119.  
  120.    /* get the source network/node address and local server name */
  121.    (void) IPXGetInternetworkAddress ((unsigned char *) &source);
  122.  
  123.    printf ("\r\nEnter target server name: ");
  124.    gets (target_server);
  125.  
  126.    /* convert to upper case for bindery comparison */
  127.    strupr (target_server);
  128.  
  129.    /*
  130.    ** Find the file server in the bindery with the given target name
  131.    ** and get its address.
  132.    */
  133.    if (ReadPropertyValue (target_server, OT_FILE_SERVER, "NET_ADDRESS", 1,
  134.                          (unsigned char *) &dest, &more, &flag) != 0)
  135.    {
  136.       printf("\r\nUnknown server.\r\n");
  137.       exit (0);
  138.    }
  139.  
  140.    memset ((char *) &ecbBuf, '\0', sizeof(ECB));
  141.  
  142.    /* fetch the immediate address into the ECB for the target server */
  143.    *((unsigned short *)dest.addr.socket) = NVSOCKET;
  144.    if (IPXGetLocalTarget ((BYTE *) &dest.addr, (BYTE *)ecbBuf.immediateAddress, (int *)&transport) != 0)
  145.       exit (0);
  146.  
  147.    /* 
  148.    ** Fill in remainder of the ECB, the IPX header and the 
  149.    ** message data itself.
  150.    */
  151.    fill_in_msg ();
  152.  
  153.    /* send the alert to the CE */
  154.    IPXSendPacket (&ecbBuf);
  155. }
  156.  
  157.  
  158. void fill_in_msg (void)
  159. {
  160.    NMVTEvt_t         *eventptr;
  161.  
  162.    eventptr = (NMVTEvt_t *)&(eventBuf.ipxData);
  163.  
  164.    eventptr->PrimType = NM_EVENT_NOTIFICATION;   
  165.    eventptr->InputType = NVEVENT_NMVT;
  166.    eventptr->ServerName[0] = '\0';
  167.  
  168.    eventptr->EventDataCount = 1;                   /* always 1 data vector */
  169.  
  170.    eventptr->EventData.DataType = NMVT_TYPE;       /* data vector type */
  171.    eventptr->EventData.Count = 1;                  /* always 1 */
  172.    eventptr->EventData.DataLen = NMVTDATALEN;      /* length of the alert NMVT */
  173.    (void)memcpy (eventptr->EventData.NMVTData, msg, NMVTDATALEN);
  174.  
  175.    /* finish filling in the ECB */   
  176.    ecbBuf.fragmentDescriptor[0].address = (void *)&eventBuf;
  177.    ecbBuf.fragmentCount = 1;
  178.    ecbBuf.fragmentDescriptor[0].size = sizeof(IPXHeader) + DATABUFLEN;
  179.    ecbBuf.inUseFlag = 0;
  180.    ecbBuf.completionCode = 0;
  181.    ecbBuf.ESRAddress = NULL;
  182.    ecbBuf.socketNumber = 0;
  183.  
  184.    /* fill in the IPX header */
  185.    eventBuf.hdr.packetType = 4;           /* IPX */
  186.  
  187.    memcpy (eventBuf.hdr.destination.network, dest.addr.network, 4); 
  188.    memcpy (eventBuf.hdr.destination.node, dest.addr.node, 6);
  189.    *((unsigned short *)eventBuf.hdr.destination.socket) = NVSOCKET;
  190.  
  191.    memcpy (eventBuf.hdr.source.network, source.network, 4);
  192.    memcpy (eventBuf.hdr.source.node, source.node, 6);
  193.    *((unsigned short *)eventBuf.hdr.source.socket) = 0;
  194.  
  195. }      
  196.  
  197.  
  198.