home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / p / pcrte224.zip / SOURCE.ZIP / ARPTAB.INC < prev    next >
Text File  |  1992-06-09  |  4KB  |  116 lines

  1. ;;*****************************************************************************
  2. ;;                    arptab.inc           arptab.inc
  3. ;;*****************************************************************************
  4. ;;
  5. ;;  Copyright (C) 1989 Northwestern University, Vance Morrison
  6. ;;
  7. ;;
  8. ;; Permission to view, compile, and modify for LOCAL (intra-organization) 
  9. ;; USE ONLY is hereby granted, provided that this copyright and permission 
  10. ;; notice appear on all copies.  Any other use by permission only.
  11. ;;
  12. ;; Northwestern University makes no representations about the suitability 
  13. ;; of this software for any purpose.  It is provided "as is" without expressed 
  14. ;; or implied warranty.  See the copywrite notice file for complete details.
  15. ;;
  16. ;;*****************************************************************************
  17. ;;
  18. ;; The functions provided by this file are
  19. ;;
  20. ;;      ARP_TAB_DECLARE name
  21. ;;      ARP_TAB_DEFINE name
  22. ;;      ARP_TAB_GET_in_AX_out_SI_const_AX_BX_CX_BP_DI_ES name
  23. ;;      ARP_TAB_ADD_in_AX_BX_ES_out_SI_const_BX_DX_BP_DI_ES name
  24. ;;      
  25. ;;*****************************************************************************
  26. ;; arp table stuff.  only the routines below use this stuff
  27.  
  28. arp_entry STRUC                     ;; an entry in the arp table
  29.     arp_ent_haddr   DW 3 dup (0)
  30.     arp_ent_ipaddr  DW ?
  31. arp_entry ENDS
  32.  
  33.  
  34. ;;******************************************************************************
  35. ;; ARP_TAB_DECLARE declares external data structures for the arp table
  36. ;;
  37. ARP_TAB_DECLARE MACRO name
  38.     .DATA
  39.     global arp_&name&_table:arp_entry
  40.     .CODE
  41. ENDM
  42.  
  43. ;;******************************************************************************
  44. ;; ARP_TAB_DEFINE defines and initilizes the arp table 
  45. ;;
  46. ARP_TAB_DEFINE MACRO name
  47.     .errb <name>
  48.  
  49.     .DATA
  50. arp_&name&_table    arp_entry 256 dup (<>)
  51.  
  52.     .CODE
  53.     mov CX, (size arp_entry)*256/2
  54.     mov DI, offset arp_&name&_table
  55.     mov AX, DS
  56.     mov ES, AX
  57.     xor AX, AX                          ;; null the table
  58.     rep
  59.     stosw
  60. ENDM
  61.  
  62.  
  63. ;;******************************************************************************
  64. ;; ARP_TAB_GET returns in SI a pointer to the harware address for the computer 
  65. ;; that has an IP address whose LSB is in AX.   The zero flag is set if the 
  66. ;; routine was successful
  67.  
  68. ARP_TAB_GET_in_AX_out_SI_const_AX_BX_CX_BP_DI_ES MACRO name
  69.     .errb <name>
  70.  
  71.     mov DX, AX                                          ;; save AX
  72.     ARP_TAB_GET_ENTRY_in_AX_out_SI_const_BX_CX_DX_BP_DI_ES name
  73.     mov AX, DX
  74.     cmp AX, [SI+arp_ent_ipaddr] 
  75. ENDM
  76.  
  77.  
  78. ;;******************************************************************************
  79. ;; ARP_TAB_ADD_in_AX_BX_ES adds the hardware address pointed to by BX:ES to the 
  80. ;; table 'name' for the computer whose IP address ends in AX.  SI:DS points
  81. ;; to the hardware address of the new entry
  82. ;;
  83. ARP_TAB_ADD_in_AX_BX_ES_out_SI_const_BX_DX_BP_DI_ES MACRO name
  84.     .errb <name>
  85.  
  86.     mov CX, AX                      ;; save AX
  87.     ARP_TAB_GET_ENTRY_in_AX_out_SI_const_BX_CX_DX_BP_DI_ES name
  88.  
  89.     mov AX, ES:[BX]                 ;; copy the hardware address
  90.     mov [SI+arp_ent_haddr], AX
  91.     mov AX, ES:[BX+2]
  92.     mov [SI+arp_ent_haddr+2], AX
  93.     mov AX, ES:[BX+4]
  94.     mov [SI+arp_ent_haddr+4], AX
  95.  
  96.     mov [SI+arp_ent_ipaddr], CX
  97. ENDM
  98.  
  99.  
  100. ;;******************************************************************************
  101. ;; ARP_TAB_GET_ENTRY_returns in SI a pointer to the harware address for the 
  102. ;; computer that has an IP address whose LSB is in AX.   
  103.  
  104. ARP_TAB_GET_ENTRY_in_AX_out_SI_const_BX_CX_DX_BP_DI_ES MACRO name
  105.     .errb <name>
  106.  
  107.     mov AL, AH                      ;; byte swap
  108.     xor AH, AH
  109.     shl AX, 1                       ;; multiply by 8
  110.     shl AX, 1
  111.     shl AX, 1
  112.     mov SI, AX                      ;; put it in BX
  113.     add SI, OFFSET arp_&name&_table
  114. ENDM
  115.  
  116.