arp.asm


;+
; **-arp_request-generate an arp request.
;
; inputs:
;   buf  = IP address to ARP for
;
; outputs:
;   ARP request sent
;-

arp_request:
    pi2xl ETH_DEST,0xffff,0xffff 
    pi2x ETH_DEST+4,0xffff  ;       /* dest ether == BROADCAST */ 
    ps2x ETH_SRC,my_ether,6  ;      /* source ether == me */ 
    pi2x ETH_PT,ETH_PT_ARP  ;       /* protocol type == ARP */ 
    pi2xl AH_HWTYPE,ARP_HWTYPE_ETHER,ARP_PROTTYPE_IP 
    pi2xl AH_PROTALEN,ARP_PROTALEN,ARP_OPCODE_REQUEST 
    ps2x AH_SRCETH,my_ether,6 
    ps2x AH_SRCIP,my_ip,4 
    ps2x AH_DSTIP,buf,4             ; stuff in frame
    pz2x AH_DSTETH,6 
    xmit_frame AH_LEN
    pret
;+
; **-arp_reply-process an arp reply.
;
; inputs:
;   receive buffer contains a potential ARP reply frame
;
;-
    .global import_unknown_arp  ; MUST be global - otherwise no UPCALL
import_unknown_arp:
    pbegin
    pcall 1f
    pend
    ret
1:
    pr2s buf,AH_OPCODE,2        ; get opcode
    pcmpwi buf,ARP_OPCODE_REPLY
    pjumpne 99f                 ; not request or reply!  pass it on

    pr2s buf,AH_DSTIP,4         ; get destination IP
    pcmp4 buf,my_ip             ; see if we requested this
    pjumpne 99f                 ; nope - pass it on

    pr2s buf,AH_SRCIP,4
    pjump arp_test_reply        ; let user code deal with it
99:
    pret

Back