00001 /* 00002 * Copyright (c) 2001, Swedish Institute of Computer Science. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. All advertising materials mentioning features or use of this software 00014 * must display the following acknowledgement: 00015 * This product includes software developed by the Swedish Institute 00016 * of Computer Science and its contributors. 00017 * 4. Neither the name of the Institute nor the names of its contributors 00018 * may be used to endorse or promote products derived from this software 00019 * without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00022 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00024 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00025 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00026 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00027 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00028 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00029 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00030 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00031 * SUCH DAMAGE. 00032 * 00033 * This file is part of the lwIP TCP/IP stack. 00034 * 00035 * Author: Adam Dunkels <adam@sics.se> 00036 * 00037 * $Id$ 00038 * 00039 */ 00040 00041 #ifndef __NETIF_ARP_H__ 00042 #define __NETIF_ARP_H__ 00043 00044 #include "net/pbuf.h" 00045 #include "net/ipv4/ip_addr.h" 00046 #include "net/netif.h" 00047 00048 struct eth_addr { 00049 PACK_STRUCT_FIELD(uInt8 addr[6]); 00050 } PACK_STRUCT_STRUCT; 00051 00052 struct eth_hdr { 00053 PACK_STRUCT_FIELD(struct eth_addr dest); 00054 PACK_STRUCT_FIELD(struct eth_addr src); 00055 PACK_STRUCT_FIELD(uInt16 type); 00056 } PACK_STRUCT_STRUCT; 00057 00058 #define ARP_TMR_INTERVAL 10000 00059 00060 #define ETHTYPE_ARP 0x0806 00061 #define ETHTYPE_IP 0x0800 00062 00063 /* Initializes ARP. */ 00064 void arp_init(void); 00065 00066 /* The arp_tmr() function should be called every ARP_TMR_INTERVAL 00067 microseconds (10 seconds). This function is responsible for 00068 expiring old entries in the ARP table. */ 00069 void arp_tmr(void); 00070 00071 /* Should be called for all incoming packets of IP kind. The function 00072 does not alter the packet in any way, it just updates the ARP 00073 table. After this function has been called, the normal TCP/IP stack 00074 input function should be called. */ 00075 void arp_ip_input(struct netif *netif, struct pbuf *p); 00076 00077 /* Should be called for incoming ARP packets. The pbuf in the argument 00078 is freed by this function. If the function returns a pbuf (i.e., 00079 returns non-NULL), that pbuf constitutes an ARP reply and should be 00080 sent out on the Ethernet. */ 00081 struct pbuf *arp_arp_input(struct netif *netif, struct eth_addr *ethaddr, 00082 struct pbuf *p); 00083 00084 /* arp_loopup() is called to do an IP address -> Ethernet address 00085 translation. If the function returns NULL, there is no mapping and 00086 the arp_query() function should be called. */ 00087 struct eth_addr *arp_lookup(struct ip_addr *ipaddr); 00088 00089 /* Constructs an ARP query packet for the given IP address. The 00090 function returns a pbuf that contains the reply and that should be 00091 sent out on the Ethernet. */ 00092 struct pbuf *arp_query(struct netif *netif, struct eth_addr *ethaddr, 00093 struct ip_addr *ipaddr); 00094 00095 #endif /* __NETIF_ARP_H__ */