home *** CD-ROM | disk | FTP | other *** search
/ PC Press: Internet / PC_PRESS.ISO / software / dos / misc / inar-100.exe / SRC / PCROUTE / ARPTAB.INC < prev    next >
Encoding:
Text File  |  1995-05-21  |  10.0 KB  |  325 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. ;; Rewritten by Ruediger Helsch to keep addresses in LRU chain and to
  17. ;; allow for 32-bit IP addresses.
  18. ;;
  19. ;;*****************************************************************************
  20. ;;
  21. ;; The functions provided by this file are
  22. ;;
  23. ;;      ARP_TAB_DECLARE name
  24. ;;      ARP_TAB_DEFINE name
  25. ;;      ARP_TAB_GET_in_AX_BX_out_SI_const_AX_BX_CX_BP_DI_ES name
  26. ;;      ARP_TAB_ADD_in_AX_DX_BX_ES_out_SI_const_BX_DX_BP_DI_ES name
  27. ;;    ARP_TAB_ADD_FIXED_in_AX_DX_BX_ES_out_SI_const_BX_DX_BP_DI_ES name
  28. ;;    ARP_TAB_GET_FIXED_in_AX_BX_out_SI_const_AX_BX_CX_DX_BP_DI_ES name
  29. ;;      
  30. ;;*****************************************************************************
  31. ;; arp table stuff.  only the routines below use this stuff
  32.  
  33. arp_entry STRUC                     ;; an entry in the arp table
  34.     arp_ent_haddr   DW 3 dup (0)
  35.     arp_ent_ipaddr  DW 2 dup (0)
  36.     arp_ent_next    DW ?
  37.     arp_ent_previous DW ?
  38. arp_entry ENDS
  39.  
  40.  
  41. ;;******************************************************************************
  42. ;; ARP_TAB_DECLARE declares external data structures for the arp table
  43. ;;
  44. ARP_TAB_DECLARE MACRO name
  45.     .DATA
  46.     arp_&name&_table_size = 512
  47.     global arp_&name&_tseg:word
  48.     global arp_&name&_lentry:arp_entry
  49.     .CODE
  50.     global arp_&name&_data_seg:word
  51. ENDM
  52.  
  53. ;;******************************************************************************
  54. ;; ARP_TAB_DEFINE defines and initilizes the arp table 
  55. ;;
  56. ARP_TAB_DEFINE MACRO name
  57.     local loop, around
  58.     .errb <name>
  59.  
  60.     .DATA
  61.     arp_&name&_tseg    DW ?
  62.     arp_&name&_lentry    arp_entry <>
  63.  
  64.     .FARDATA? arp_&name&_bseg
  65.     arp_&name&_fixed    DW ?
  66.     arp_&name&_table    arp_entry arp_&name&_table_size dup (<>)
  67.  
  68.     .CODE
  69.     jmp around
  70.     arp_&name&_data_seg    DW ?
  71.  
  72.   around:
  73.     mov word ptr CS:arp_&name&_data_seg, DS
  74.     mov word ptr arp_&name&_tseg, SEG arp_&name&_fixed
  75.     mov DI, offset arp_&name&_lentry
  76.     mov word ptr [DI+arp_ent_next], 0
  77.     mov word ptr [DI+arp_ent_previous], 0
  78.     mov CX, arp_&name&_table_size
  79.     mov DI, offset arp_&name&_table
  80.     mov ES, word ptr arp_&name&_tseg
  81.     loop:
  82.         xor AX, AX                          ;; initialize the table
  83.         stosw
  84.         stosw
  85.         stosw
  86.         stosw
  87.     stosw
  88.         mov AX, DI
  89.     add AX, (size arp_entry) - arp_ent_next
  90.     stosw
  91.     sub AX, 2 * (size arp_entry)
  92.     stosw
  93.     dec CX
  94.     or CX, CX
  95.     jnz loop
  96.     sub DI, 4
  97.     mov AX, offset arp_&name&_table
  98.     stosw
  99.     mov AX, DI
  100.     sub AX, arp_ent_previous
  101.     mov DI, offset arp_&name&_table + arp_ent_previous
  102.     stosw
  103.     mov word ptr ES:arp_&name&_fixed, 0
  104. ENDM
  105.  
  106.  
  107. ;;******************************************************************************
  108. ;; ARP_TAB_GET returns in SI a pointer to the harware address for the computer 
  109. ;; that has an IP AX:BX.   The zero flag is set if the routine was successful
  110.  
  111. ARP_TAB_GET_in_AX_BX_out_SI_const_AX_BX_CX_BP_DI_ES MACRO name
  112.     local fail
  113.     .errb <name>
  114.  
  115.     mov DS, word ptr arp_&name&_tseg
  116.     assume DS:NOTHING
  117.     ARP_TAB_GET_ENTRY_in_AX_BX_DS_out_SI_const_AX_BX_CX_DX_BP_DI_DS_ES name
  118.     ARP_TAB_COPY_ENTRY_in_SI_DS_out_SI_DS_const_AX_BX_CX_DX_BP_DI_ES name
  119.     cmp AX, [SI+arp_ent_ipaddr]
  120.     jne fail
  121.     cmp BX, [SI+arp_ent_ipaddr+2]
  122.     fail:
  123. ENDM
  124.  
  125.  
  126. ;;******************************************************************************
  127. ;; ARP_TAB_ADD_in_AX_DX_BX_ES adds the hardware address pointed to by BX:ES
  128. ;; to the table 'name' for the computer whose IP address is in AX:DX.
  129. ;; SI:DS points to the hardware address of the new entry.
  130. ;;
  131. ARP_TAB_ADD_in_AX_DX_BX_ES_out_SI_const_BX_DX_BP_DI_ES MACRO name
  132.     local done
  133.     .errb <name>
  134.  
  135.     mov DS, word ptr arp_&name&_tseg
  136.     assume DS:NOTHING
  137.     xchg BX, DX
  138.     ARP_TAB_GET_ENTRY_in_AX_BX_DS_out_SI_const_AX_BX_CX_DX_BP_DI_DS_ES name
  139.     xchg DX, BX
  140.  
  141.     cmp word ptr [SI+arp_ent_previous], 0
  142.     je done                ; Dont modify fixed ARP entry
  143.     mov [SI+arp_ent_ipaddr], AX
  144.     mov [SI+arp_ent_ipaddr+2], DX
  145.     mov AX, ES:[BX]                 ;; copy the hardware address
  146.     mov [SI+arp_ent_haddr], AX
  147.     mov AX, ES:[BX+2]
  148.     mov [SI+arp_ent_haddr+2], AX
  149.     mov AX, ES:[BX+4]
  150.     mov [SI+arp_ent_haddr+4], AX
  151.     mov AX, [SI+arp_ent_next]    ; Unlink entry just found
  152.     mov SI, [SI+arp_ent_previous]
  153.     xchg AX, [SI+arp_ent_next]
  154.     mov SI, AX
  155.     mov AX, [SI+arp_ent_previous]
  156.     mov SI, [SI+arp_ent_next]
  157.     xchg AX, [SI+arp_ent_previous]
  158.     mov SI, word ptr DS:arp_&name&_table + arp_ent_next ; Relink at head
  159.     mov [SI+arp_ent_previous], AX    ;
  160.     xchg AX, SI            ;
  161.     mov [SI+arp_ent_next], AX    ;
  162.     mov word ptr DS:arp_&name&_table + arp_ent_next, SI
  163.     mov AX, offset arp_&name&_table    ;
  164.     mov [SI+arp_ent_previous], AX    ;
  165.     mov AX, [SI+arp_ent_ipaddr+2]    ; Restore AX
  166.     done:
  167.     ARP_TAB_COPY_ENTRY_in_SI_DS_out_SI_DS_const_AX_BX_CX_DX_BP_DI_ES name
  168. ENDM
  169.  
  170.  
  171. ;;******************************************************************************
  172. ;; ARP_TAB_ADD_FIXED_in_AX_BX_ES adds the fixed hardware address pointed to
  173. ;; by BX:ES to the table 'name' for the computer whose IP address is in AX:DX.
  174. ;; SI:DS points to the hardware address of the new entry.
  175. ;;
  176. ARP_TAB_ADD_FIXED_in_AX_DX_BX_ES_out_SI_const_BX_DX_BP_DI_ES MACRO name
  177.     local done
  178.     .errb <name>
  179.  
  180.     mov DS, word ptr arp_&name&_tseg
  181.     assume DS:NOTHING
  182.     xchg BX, DX
  183.     ARP_TAB_GET_ENTRY_in_AX_BX_DS_out_SI_const_AX_BX_CX_DX_BP_DI_DS_ES name
  184.     xchg BX, DX
  185.  
  186.     mov [SI+arp_ent_ipaddr], AX
  187.     mov [SI+arp_ent_ipaddr+2], DX
  188.     mov AX, ES:[BX]                 ;; copy the hardware address
  189.     mov [SI+arp_ent_haddr], AX
  190.     mov AX, ES:[BX+2]
  191.     mov [SI+arp_ent_haddr+2], AX
  192.     mov AX, ES:[BX+4]
  193.     mov [SI+arp_ent_haddr+4], AX
  194.     mov AX, [SI+arp_ent_previous]
  195.     or AX, AX
  196.     jz done
  197.     mov AX, [SI+arp_ent_next]    ; Unlink entry just found
  198.     mov SI, [SI+arp_ent_previous]
  199.     xchg AX, [SI+arp_ent_next]
  200.     mov SI, AX
  201.     mov AX, [SI+arp_ent_previous]
  202.     mov SI, [SI+arp_ent_next]
  203.     xchg AX, [SI+arp_ent_previous]
  204.     mov SI, AX
  205.     mov AX, word ptr DS:arp_&name&_fixed ; Relink into fixed ARP list
  206.     mov [SI+arp_ent_next], AX
  207.     mov word ptr DS:arp_&name&_fixed, SI
  208.     xor AX, AX            ; Zero backward link
  209.     mov [SI+arp_ent_previous], AX
  210.     done:
  211.     ARP_TAB_COPY_ENTRY_in_SI_DS_out_SI_DS_const_AX_BX_CX_DX_BP_DI_ES name
  212. ENDM
  213.  
  214.  
  215. ;;******************************************************************************
  216. ;; ARP_TAB_GET_ENTRY_returns in SI a pointer to the hardware address for the 
  217. ;; computer that has the IP address in AX:BX.
  218.  
  219. ARP_TAB_GET_ENTRY_in_AX_BX_DS_out_SI_const_AX_BX_CX_DX_BP_DI_DS_ES MACRO name
  220.     local fixed_loop, fixed_loop_entry, not_fixed, loop, fail, done
  221.     .errb <name>
  222.  
  223.     mov SI, word ptr DS:arp_&name&_fixed ; Check fixed entries first,
  224.     jmp fixed_loop_entry        ;   because this list should be short
  225.     fixed_loop:                ;
  226.     mov SI, [SI+arp_ent_next]    ;
  227.     fixed_loop_entry:            ;
  228.     or SI, SI            ;
  229.     jz not_fixed            ;
  230.     cmp BX, [SI+arp_ent_ipaddr+2]    ;
  231.     jne fixed_loop            ;
  232.     cmp AX, [SI+arp_ent_ipaddr]    ;
  233.     jne fixed_loop            ;
  234.     jmp done                ; Found fixed entry
  235.   fail:                    ;
  236.     mov SI, word ptr DS:arp_&name&_table + arp_ent_previous ;
  237.     jmp done                ;
  238.   not_fixed:                ;
  239.     mov SI, word ptr DS:arp_&name&_table + arp_ent_next ; Start of table
  240.     cmp AX, [SI+arp_ent_ipaddr]        ; If at start of table,
  241.     jne loop                ;
  242.     cmp BX, [SI+arp_ent_ipaddr+2]    ;
  243.     je done                ;   then done
  244.         loop:                ;
  245.         mov SI, [SI+arp_ent_next]    ; Advance SI
  246.         cmp SI, offset arp_&name&_table ;   or
  247.         je fail            ;     fail (and return last entry)
  248.         cmp BX, [SI+arp_ent_ipaddr+2] ; If not the searched one,
  249.         jne loop            ;   then go on
  250.         cmp AX, [SI+arp_ent_ipaddr] ; If not the searched one,
  251.         jne loop            ;   then go on
  252.     mov BX, [SI+arp_ent_next]    ;
  253.     mov AX, [SI+arp_ent_previous]    ;
  254.     mov [BX+arp_ent_previous], AX    ;
  255.     xchg AX, BX            ;
  256.     mov [BX+arp_ent_next], AX    ;
  257.     mov BX, word ptr DS:arp_&name&_table + arp_ent_next ; Relink at head
  258.     mov AX, SI            ;
  259.     mov [BX+arp_ent_previous], AX    ;
  260.     mov word ptr DS:arp_&name&_table + arp_ent_next, AX
  261.     mov AX, offset arp_&name&_table    ;
  262.     mov [SI+arp_ent_previous], AX    ;
  263.     mov [SI+arp_ent_next], BX    ;
  264.     mov AX, [SI+arp_ent_ipaddr]    ; Restore AX
  265.     mov BX, [SI+arp_ent_ipaddr+2]    ; Restore BX
  266.     done:
  267. ENDM
  268.  
  269.  
  270. ;;******************************************************************************
  271. ;; ARP_TAB_GET_FIXED_returns in SI a pointer to the ethernet address
  272. ;; associated with the fixed IP address in AX:BX or zero if no entry
  273. ;; matched.
  274.  
  275. ARP_TAB_GET_FIXED_in_AX_BX_out_SI_const_AX_BX_CX_DX_BP_DI_ES MACRO name
  276.     local loop, loop_entry, fail, done
  277.     .errb <name>
  278.  
  279.     mov DS, word ptr arp_&name&_tseg
  280.     assume DS:NOTHING
  281.     mov SI, word ptr arp_&name&_fixed
  282.     jmp loop_entry
  283.  
  284.     fail:
  285.       mov DS, word ptr CS:arp_&name&_data_seg
  286.       jmp done
  287.  
  288.     loop:
  289.       mov SI, [SI+arp_ent_next]
  290.     loop_entry:
  291.       or SI, SI
  292.       jz fail
  293.       cmp BX, [SI+arp_ent_ipaddr+2]
  294.       jne loop
  295.       cmp AX, [SI+arp_ent_ipaddr]
  296.       jne loop
  297.       ARP_TAB_COPY_ENTRY_in_SI_DS_out_SI_DS_const_AX_BX_CX_DX_BP_DI_ES name
  298.     done:
  299. ENDM
  300.  
  301.  
  302. ;;******************************************************************************
  303. ;; ARP_TAB_COPY_ENTRY returns in SI:DS a pointer to a copy of the ARP TAB
  304. ;; entry pointed to by SI:DS. DS on exit is set to the regular data segment
  305. ;; while on entry it may point to any segment.
  306.  
  307. ARP_TAB_COPY_ENTRY_in_SI_DS_out_SI_DS_const_AX_BX_CX_DX_BP_DI_ES MACRO name
  308.     .errb <name>
  309.  
  310.     push ES
  311.     push DI
  312.     mov ES, word ptr CS:arp_&name&_data_seg
  313.     mov DI, offset arp_&name&_lentry
  314.     movsw
  315.     movsw
  316.     movsw
  317.     movsw
  318.     movsw
  319.     mov DS, word ptr CS:arp_&name&_data_seg
  320.     assume DS:@data
  321.     mov SI, offset arp_&name&_lentry
  322.     pop DI
  323.     pop ES
  324. ENDM
  325.