diff options
Diffstat (limited to 'sys/netinet')
-rw-r--r-- | sys/netinet/if_ether.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/sys/netinet/if_ether.c b/sys/netinet/if_ether.c index 0c458a4..db1d6d4 100644 --- a/sys/netinet/if_ether.c +++ b/sys/netinet/if_ether.c @@ -40,19 +40,6 @@ struct arp_pkt { struct ether_arp payload; }; -static void -set_hwaddr(struct netif_addr *addrp, char addr[ETHER_ADDR_LEN]) -{ - uint16_t *psrc, *p; - - psrc = (uint16_t *)&addrp->data[0]; - p = (uint16_t *)addr; - - p[0] = swap16(psrc[0]); - p[1] = swap16(psrc[1]); - p[2] = swap16(psrc[2]); -} - static struct arp_pkt * arp_create(struct netif *nifp, uint32_t *sproto, uint32_t *tproto, uint16_t op) { @@ -71,7 +58,7 @@ arp_create(struct netif *nifp, uint32_t *sproto, uint32_t *tproto, uint16_t op) hdrp = &payload->hdr; /* Ethernet frame, from source to all */ - set_hwaddr(&nifp->addr, frp->ether_saddr); + memcpy(frp->ether_saddr, &nifp->addr, ETHER_ADDR_LEN); memset(frp->ether_daddr, 0xFF, ETHER_ADDR_LEN); frp->ether_type = swap16(ETHERTYPE_ARP); @@ -91,8 +78,8 @@ arp_create(struct netif *nifp, uint32_t *sproto, uint32_t *tproto, uint16_t op) return packet; } -int -arp_request(struct netif *nifp, uint8_t *sproto, uint8_t *tproto) +static int +arp_send(struct netif *nifp, uint8_t *sproto, uint8_t *tproto, uint16_t op) { struct arp_pkt *packet; struct netbuf nb; @@ -108,7 +95,7 @@ arp_request(struct netif *nifp, uint8_t *sproto, uint8_t *tproto) src_tmp = (uint32_t *)sproto; targ_tmp = (uint32_t *)tproto; - packet = arp_create(nifp, src_tmp, targ_tmp, ARP_REQUEST); + packet = arp_create(nifp, src_tmp, targ_tmp, op); if (packet == NULL) { return -ENOMEM; } @@ -121,3 +108,15 @@ arp_request(struct netif *nifp, uint8_t *sproto, uint8_t *tproto) dynfree(packet); return 0; } + +int +arp_request(struct netif *nifp, uint8_t *sproto, uint8_t *tproto) +{ + return arp_send(nifp, sproto, tproto, ARP_REQUEST); +} + +int +arp_reply(struct netif *nifp, uint8_t *sproto, uint8_t *tproto) +{ + return arp_send(nifp, sproto, tproto, ARP_REPLY); +} |