home *** CD-ROM | disk | FTP | other *** search
- ;;*****************************************************************************
- ;; arptab.inc arptab.inc
- ;;*****************************************************************************
- ;;
- ;; Copyright (C) 1989 Northwestern University, Vance Morrison
- ;;
- ;;
- ;; Permission to view, compile, and modify for LOCAL (intra-organization)
- ;; USE ONLY is hereby granted, provided that this copyright and permission
- ;; notice appear on all copies. Any other use by permission only.
- ;;
- ;; Northwestern University makes no representations about the suitability
- ;; of this software for any purpose. It is provided "as is" without expressed
- ;; or implied warranty. See the copywrite notice file for complete details.
- ;;
- ;; Rewritten by Ruediger Helsch to keep addresses in LRU chain and to
- ;; allow for 32-bit IP addresses.
- ;;
- ;;*****************************************************************************
- ;;
- ;; The functions provided by this file are
- ;;
- ;; ARP_TAB_DECLARE name
- ;; ARP_TAB_DEFINE name
- ;; ARP_TAB_GET_in_AX_BX_out_SI_const_AX_BX_CX_BP_DI_ES name
- ;; ARP_TAB_ADD_in_AX_DX_BX_ES_out_SI_const_BX_DX_BP_DI_ES name
- ;; ARP_TAB_ADD_FIXED_in_AX_DX_BX_ES_out_SI_const_BX_DX_BP_DI_ES name
- ;; ARP_TAB_GET_FIXED_in_AX_BX_out_SI_const_AX_BX_CX_DX_BP_DI_ES name
- ;;
- ;;*****************************************************************************
- ;; arp table stuff. only the routines below use this stuff
-
- arp_entry STRUC ;; an entry in the arp table
- arp_ent_haddr DW 3 dup (0)
- arp_ent_ipaddr DW 2 dup (0)
- arp_ent_next DW ?
- arp_ent_previous DW ?
- arp_entry ENDS
-
-
- ;;******************************************************************************
- ;; ARP_TAB_DECLARE declares external data structures for the arp table
- ;;
- ARP_TAB_DECLARE MACRO name
- .DATA
- arp_&name&_table_size = 512
- global arp_&name&_tseg:word
- global arp_&name&_lentry:arp_entry
- .CODE
- global arp_&name&_data_seg:word
- ENDM
-
- ;;******************************************************************************
- ;; ARP_TAB_DEFINE defines and initilizes the arp table
- ;;
- ARP_TAB_DEFINE MACRO name
- local loop, around
- .errb <name>
-
- .DATA
- arp_&name&_tseg DW ?
- arp_&name&_lentry arp_entry <>
-
- .FARDATA? arp_&name&_bseg
- arp_&name&_fixed DW ?
- arp_&name&_table arp_entry arp_&name&_table_size dup (<>)
-
- .CODE
- jmp around
- arp_&name&_data_seg DW ?
-
- around:
- mov word ptr CS:arp_&name&_data_seg, DS
- mov word ptr arp_&name&_tseg, SEG arp_&name&_fixed
- mov DI, offset arp_&name&_lentry
- mov word ptr [DI+arp_ent_next], 0
- mov word ptr [DI+arp_ent_previous], 0
- mov CX, arp_&name&_table_size
- mov DI, offset arp_&name&_table
- mov ES, word ptr arp_&name&_tseg
- loop:
- xor AX, AX ;; initialize the table
- stosw
- stosw
- stosw
- stosw
- stosw
- mov AX, DI
- add AX, (size arp_entry) - arp_ent_next
- stosw
- sub AX, 2 * (size arp_entry)
- stosw
- dec CX
- or CX, CX
- jnz loop
- sub DI, 4
- mov AX, offset arp_&name&_table
- stosw
- mov AX, DI
- sub AX, arp_ent_previous
- mov DI, offset arp_&name&_table + arp_ent_previous
- stosw
- mov word ptr ES:arp_&name&_fixed, 0
- ENDM
-
-
- ;;******************************************************************************
- ;; ARP_TAB_GET returns in SI a pointer to the harware address for the computer
- ;; that has an IP AX:BX. The zero flag is set if the routine was successful
-
- ARP_TAB_GET_in_AX_BX_out_SI_const_AX_BX_CX_BP_DI_ES MACRO name
- local fail
- .errb <name>
-
- mov DS, word ptr arp_&name&_tseg
- assume DS:NOTHING
- ARP_TAB_GET_ENTRY_in_AX_BX_DS_out_SI_const_AX_BX_CX_DX_BP_DI_DS_ES name
- ARP_TAB_COPY_ENTRY_in_SI_DS_out_SI_DS_const_AX_BX_CX_DX_BP_DI_ES name
- cmp AX, [SI+arp_ent_ipaddr]
- jne fail
- cmp BX, [SI+arp_ent_ipaddr+2]
- fail:
- ENDM
-
-
- ;;******************************************************************************
- ;; ARP_TAB_ADD_in_AX_DX_BX_ES adds the hardware address pointed to by BX:ES
- ;; to the table 'name' for the computer whose IP address is in AX:DX.
- ;; SI:DS points to the hardware address of the new entry.
- ;;
- ARP_TAB_ADD_in_AX_DX_BX_ES_out_SI_const_BX_DX_BP_DI_ES MACRO name
- local done
- .errb <name>
-
- mov DS, word ptr arp_&name&_tseg
- assume DS:NOTHING
- xchg BX, DX
- ARP_TAB_GET_ENTRY_in_AX_BX_DS_out_SI_const_AX_BX_CX_DX_BP_DI_DS_ES name
- xchg DX, BX
-
- cmp word ptr [SI+arp_ent_previous], 0
- je done ; Dont modify fixed ARP entry
- mov [SI+arp_ent_ipaddr], AX
- mov [SI+arp_ent_ipaddr+2], DX
- mov AX, ES:[BX] ;; copy the hardware address
- mov [SI+arp_ent_haddr], AX
- mov AX, ES:[BX+2]
- mov [SI+arp_ent_haddr+2], AX
- mov AX, ES:[BX+4]
- mov [SI+arp_ent_haddr+4], AX
- mov AX, [SI+arp_ent_next] ; Unlink entry just found
- mov SI, [SI+arp_ent_previous]
- xchg AX, [SI+arp_ent_next]
- mov SI, AX
- mov AX, [SI+arp_ent_previous]
- mov SI, [SI+arp_ent_next]
- xchg AX, [SI+arp_ent_previous]
- mov SI, word ptr DS:arp_&name&_table + arp_ent_next ; Relink at head
- mov [SI+arp_ent_previous], AX ;
- xchg AX, SI ;
- mov [SI+arp_ent_next], AX ;
- mov word ptr DS:arp_&name&_table + arp_ent_next, SI
- mov AX, offset arp_&name&_table ;
- mov [SI+arp_ent_previous], AX ;
- mov AX, [SI+arp_ent_ipaddr+2] ; Restore AX
- done:
- ARP_TAB_COPY_ENTRY_in_SI_DS_out_SI_DS_const_AX_BX_CX_DX_BP_DI_ES name
- ENDM
-
-
- ;;******************************************************************************
- ;; ARP_TAB_ADD_FIXED_in_AX_BX_ES adds the fixed hardware address pointed to
- ;; by BX:ES to the table 'name' for the computer whose IP address is in AX:DX.
- ;; SI:DS points to the hardware address of the new entry.
- ;;
- ARP_TAB_ADD_FIXED_in_AX_DX_BX_ES_out_SI_const_BX_DX_BP_DI_ES MACRO name
- local done
- .errb <name>
-
- mov DS, word ptr arp_&name&_tseg
- assume DS:NOTHING
- xchg BX, DX
- ARP_TAB_GET_ENTRY_in_AX_BX_DS_out_SI_const_AX_BX_CX_DX_BP_DI_DS_ES name
- xchg BX, DX
-
- mov [SI+arp_ent_ipaddr], AX
- mov [SI+arp_ent_ipaddr+2], DX
- mov AX, ES:[BX] ;; copy the hardware address
- mov [SI+arp_ent_haddr], AX
- mov AX, ES:[BX+2]
- mov [SI+arp_ent_haddr+2], AX
- mov AX, ES:[BX+4]
- mov [SI+arp_ent_haddr+4], AX
- mov AX, [SI+arp_ent_previous]
- or AX, AX
- jz done
- mov AX, [SI+arp_ent_next] ; Unlink entry just found
- mov SI, [SI+arp_ent_previous]
- xchg AX, [SI+arp_ent_next]
- mov SI, AX
- mov AX, [SI+arp_ent_previous]
- mov SI, [SI+arp_ent_next]
- xchg AX, [SI+arp_ent_previous]
- mov SI, AX
- mov AX, word ptr DS:arp_&name&_fixed ; Relink into fixed ARP list
- mov [SI+arp_ent_next], AX
- mov word ptr DS:arp_&name&_fixed, SI
- xor AX, AX ; Zero backward link
- mov [SI+arp_ent_previous], AX
- done:
- ARP_TAB_COPY_ENTRY_in_SI_DS_out_SI_DS_const_AX_BX_CX_DX_BP_DI_ES name
- ENDM
-
-
- ;;******************************************************************************
- ;; ARP_TAB_GET_ENTRY_returns in SI a pointer to the hardware address for the
- ;; computer that has the IP address in AX:BX.
-
- ARP_TAB_GET_ENTRY_in_AX_BX_DS_out_SI_const_AX_BX_CX_DX_BP_DI_DS_ES MACRO name
- local fixed_loop, fixed_loop_entry, not_fixed, loop, fail, done
- .errb <name>
-
- mov SI, word ptr DS:arp_&name&_fixed ; Check fixed entries first,
- jmp fixed_loop_entry ; because this list should be short
- fixed_loop: ;
- mov SI, [SI+arp_ent_next] ;
- fixed_loop_entry: ;
- or SI, SI ;
- jz not_fixed ;
- cmp BX, [SI+arp_ent_ipaddr+2] ;
- jne fixed_loop ;
- cmp AX, [SI+arp_ent_ipaddr] ;
- jne fixed_loop ;
- jmp done ; Found fixed entry
- fail: ;
- mov SI, word ptr DS:arp_&name&_table + arp_ent_previous ;
- jmp done ;
- not_fixed: ;
- mov SI, word ptr DS:arp_&name&_table + arp_ent_next ; Start of table
- cmp AX, [SI+arp_ent_ipaddr] ; If at start of table,
- jne loop ;
- cmp BX, [SI+arp_ent_ipaddr+2] ;
- je done ; then done
- loop: ;
- mov SI, [SI+arp_ent_next] ; Advance SI
- cmp SI, offset arp_&name&_table ; or
- je fail ; fail (and return last entry)
- cmp BX, [SI+arp_ent_ipaddr+2] ; If not the searched one,
- jne loop ; then go on
- cmp AX, [SI+arp_ent_ipaddr] ; If not the searched one,
- jne loop ; then go on
- mov BX, [SI+arp_ent_next] ;
- mov AX, [SI+arp_ent_previous] ;
- mov [BX+arp_ent_previous], AX ;
- xchg AX, BX ;
- mov [BX+arp_ent_next], AX ;
- mov BX, word ptr DS:arp_&name&_table + arp_ent_next ; Relink at head
- mov AX, SI ;
- mov [BX+arp_ent_previous], AX ;
- mov word ptr DS:arp_&name&_table + arp_ent_next, AX
- mov AX, offset arp_&name&_table ;
- mov [SI+arp_ent_previous], AX ;
- mov [SI+arp_ent_next], BX ;
- mov AX, [SI+arp_ent_ipaddr] ; Restore AX
- mov BX, [SI+arp_ent_ipaddr+2] ; Restore BX
- done:
- ENDM
-
-
- ;;******************************************************************************
- ;; ARP_TAB_GET_FIXED_returns in SI a pointer to the ethernet address
- ;; associated with the fixed IP address in AX:BX or zero if no entry
- ;; matched.
-
- ARP_TAB_GET_FIXED_in_AX_BX_out_SI_const_AX_BX_CX_DX_BP_DI_ES MACRO name
- local loop, loop_entry, fail, done
- .errb <name>
-
- mov DS, word ptr arp_&name&_tseg
- assume DS:NOTHING
- mov SI, word ptr arp_&name&_fixed
- jmp loop_entry
-
- fail:
- mov DS, word ptr CS:arp_&name&_data_seg
- jmp done
-
- loop:
- mov SI, [SI+arp_ent_next]
- loop_entry:
- or SI, SI
- jz fail
- cmp BX, [SI+arp_ent_ipaddr+2]
- jne loop
- cmp AX, [SI+arp_ent_ipaddr]
- jne loop
- ARP_TAB_COPY_ENTRY_in_SI_DS_out_SI_DS_const_AX_BX_CX_DX_BP_DI_ES name
- done:
- ENDM
-
-
- ;;******************************************************************************
- ;; ARP_TAB_COPY_ENTRY returns in SI:DS a pointer to a copy of the ARP TAB
- ;; entry pointed to by SI:DS. DS on exit is set to the regular data segment
- ;; while on entry it may point to any segment.
-
- ARP_TAB_COPY_ENTRY_in_SI_DS_out_SI_DS_const_AX_BX_CX_DX_BP_DI_ES MACRO name
- .errb <name>
-
- push ES
- push DI
- mov ES, word ptr CS:arp_&name&_data_seg
- mov DI, offset arp_&name&_lentry
- movsw
- movsw
- movsw
- movsw
- movsw
- mov DS, word ptr CS:arp_&name&_data_seg
- assume DS:@data
- mov SI, offset arp_&name&_lentry
- pop DI
- pop ES
- ENDM
-