home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / pascal / ipxlib / ipxutil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-01  |  6.6 KB  |  142 lines

  1. // IPXUTIL.C -- IPX utility routines
  2. // by Allen Brunson  06/01/94
  3.  
  4.  
  5. #ifdef __TURBOC__            // If a Borland compiler
  6. #include <mem.h>             // memcpy(), memset()
  7. #else                        // If a Microsoft compiler
  8. #include <memory.h>          // memcpy(), memset()
  9. #endif
  10.  
  11. #include <stdio.h>           // sprintf()
  12. #include "ipx.h"             // IPXLIB defines
  13.  
  14.  
  15. /****************************************************************************/
  16. /*                                                                          */
  17. /***  ipxAddrBrd()                                                        ***/
  18. /*                                                                          */
  19. /****************************************************************************
  20.  
  21. This procedure sets the node address and immediate address fields of an
  22. IPXADDRFULL structure to FFFFFFFFFFFFh, making it suitable for broadcasting
  23. packets to all addresses on one network segment.                            */
  24.  
  25. void ipxAddrBrd(struct IPXADDRFULL *ipxAddr)       // Begin ipxAddrBrd()
  26.   {
  27.     memset(&ipxAddr->node, 0xFF, 6);               // Set node address
  28.     memset(&ipxAddr->immedAddr, 0xFF, 6);          // Set immediate address
  29.   }                                                // End ipxAddrBrd()
  30.  
  31.  
  32. /****************************************************************************/
  33. /*                                                                          */
  34. /***  ipxAddrCmp()                                                        ***/
  35. /*                                                                          */
  36. /****************************************************************************
  37.  
  38. This procedure compares the network, node, and socket numbers of two
  39. IPXADDRFULL structures.  It returns FALSE if the two addresses are equal,
  40. -1 if the first is less than the second, or 1 if the first is greater than
  41. the second.                                                                 */
  42.  
  43. int ipxAddrCmp(struct IPXADDRFULL *ipxAddr1,       // Begin ipxAddrCmp()
  44.  struct IPXADDRFULL *ipxAddr2)
  45.   {
  46.     word i;                                        // Loop counter
  47.     byte *addr1;                                   // First pointer
  48.     byte *addr2;                                   // Second pointer
  49.  
  50.     addr1 = (byte *) ipxAddr1;                     // Point at the two
  51.     addr2 = (byte *) ipxAddr2;                     //  series of bytes
  52.  
  53.     for (i = 0; i < 12; i++)                       // Loop for each byte
  54.       {
  55.         if (addr1[i] < addr2[i]) return -1;        // If less than
  56.         if (addr1[i] > addr2[i]) return  1;        // If greater than
  57.       }
  58.  
  59.     return FALSE;                                  // All bytes were the same
  60.   }                                                // End ipxAddrCmp()
  61.  
  62.  
  63. /****************************************************************************/
  64. /*                                                                          */
  65. /***  ipxAddrCpy()                                                        ***/
  66. /*                                                                          */
  67. /****************************************************************************
  68.  
  69. This procedure copies the contents of one IPXADDRFULL structure to another. */
  70.  
  71. void ipxAddrCpy(struct IPXADDRFULL *ipxAddrDst,    // Begin ipxAddrCpy()
  72.  struct IPXADDRFULL *ipxAddrSrc)
  73.   {
  74.     memcpy(ipxAddrDst, ipxAddrSrc,                 // Copy contents
  75.      sizeof (struct IPXADDRFULL));
  76.   }                                                // End ipxAddrCpy()
  77.  
  78.  
  79. /****************************************************************************/
  80. /*                                                                          */
  81. /***  ipxAddrStr()                                                        ***/
  82. /*                                                                          */
  83. /****************************************************************************
  84.  
  85. This procedure accepts a pointer to an IPXADDRFULL structure and a pointer
  86. to a string and fills the string with a text representation of the network
  87. and node address.  The string should contain at least 22 bytes.  It returns
  88. a pointer to the string.                                                    */
  89.  
  90. char *ipxAddrStr(char *str,                        // Begin ipxAddrStr()
  91.  struct IPXADDRFULL *ipxAddr)
  92.   {
  93.     sprintf(str,                                   // Format output string
  94.  
  95.      "%02X%02X%02X%02X:%02X%02X%02X%02X%02X%02X",  // Format string
  96.  
  97.      ipxAddr->net[0], ipxAddr->net[1],             // Net address
  98.      ipxAddr->net[2], ipxAddr->net[3],
  99.  
  100.      ipxAddr->node[0], ipxAddr->node[1],           // Node address
  101.      ipxAddr->node[2], ipxAddr->node[3],
  102.      ipxAddr->node[4], ipxAddr->node[5]);
  103.  
  104.     return str;                                    // Return string pointer
  105.   }                                                // End ipxAddrStr()
  106.  
  107.  
  108. /****************************************************************************/
  109. /*                                                                          */
  110. /***  ipxAddrStrLong()                                                    ***/
  111. /*                                                                          */
  112. /****************************************************************************
  113.  
  114. This procedure accepts a pointer to an IPXADDRFULL structure and a string
  115. and fills the string with a text representation of all four components of
  116. the address.  The string should contain at least 40 bytes.                  */
  117.  
  118. char *ipxAddrStrLong(char *str,                    // Begin ipxAddrStrLong()
  119.  struct IPXADDRFULL *ipxAddr)
  120.   {
  121.     sprintf(str,                                   // Format output string
  122.  
  123.      "%02X%02X%02X%02X:%02X%02X%02X%02X%02X%02X:"  // Format string
  124.      "%02X%02X:%02X%02X%02X%02X%02X%02X",
  125.  
  126.      ipxAddr->net[0], ipxAddr->net[1],             // Net address
  127.      ipxAddr->net[2], ipxAddr->net[3],
  128.  
  129.      ipxAddr->node[0], ipxAddr->node[1],           // Node address
  130.      ipxAddr->node[2], ipxAddr->node[3],
  131.      ipxAddr->node[4], ipxAddr->node[5],
  132.  
  133.      ipxAddr->socket & 0x00FF,                     // Socket, swapped from
  134.      ipxAddr->socket >> 8,                         //  hi-lo order
  135.  
  136.      ipxAddr->immedAddr[0], ipxAddr->immedAddr[1], // Immediate address
  137.      ipxAddr->immedAddr[2], ipxAddr->immedAddr[3],
  138.      ipxAddr->immedAddr[4], ipxAddr->immedAddr[5]);
  139.  
  140.     return str;                                    // Return string pointer
  141.   }                                                // End ipxAddrStrLong()
  142.