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 * arp.h 00034 * 00035 * Author : Adam Dunkels <adam@sics.se> 00036 * 00037 * CHANGELOG: this file has been modified by Sergio Perez Alcañiz <serpeal@disca.upv.es> 00038 * Departamento de Informática de Sistemas y Computadores 00039 * Universidad Politécnica de Valencia 00040 * Valencia (Spain) 00041 * Date: March 2003 00042 * 00043 */ 00044 00045 #ifndef __NETIF_ARP_H__ 00046 #define __NETIF_ARP_H__ 00047 00048 #include "lwip/pbuf.h" 00049 #include "lwip/ip_addr.h" 00050 #include "lwip/netif.h" 00051 00052 struct eth_addr { 00053 PACK_STRUCT_FIELD(u8_t addr[6]); 00054 } PACK_STRUCT_STRUCT; 00055 00056 struct eth_hdr { 00057 PACK_STRUCT_FIELD(struct eth_addr dest); 00058 PACK_STRUCT_FIELD(struct eth_addr src); 00059 PACK_STRUCT_FIELD(u16_t type); 00060 } PACK_STRUCT_STRUCT; 00061 00062 #define ARP_TMR_INTERVAL 10000 00063 00064 #define ETHTYPE_ARP 0x0806 00065 #define ETHTYPE_IP 0x0800 00066 00067 /* This function converts a string like "00:ff:51:7c:7a:cd" in a struct eth_addr */ 00068 void string2mac(struct eth_addr *mac, char *name); 00069 00070 /* This function converts a struct eth_addr in a string like "00:ff:51:7c:7a:cd" */ 00071 void mac2string(struct eth_addr *mac, char *name); 00072 00073 /* Initializes ARP. */ 00074 void arp_init(void); 00075 00076 /* The arp_tmr() function should be called every ARP_TMR_INTERVAL 00077 microseconds (10 seconds). This function is responsible for 00078 expiring old entries in the ARP table. */ 00079 void arp_tmr(void); 00080 00081 /* Should be called for all incoming packets of IP kind. The function 00082 does not alter the packet in any way, it just updates the ARP 00083 table. After this function has been called, the normal TCP/IP stack 00084 input function should be called. */ 00085 void arp_ip_input(struct netif *netif, struct pbuf *p); 00086 00087 /* Should be called for incoming ARP packets. The pbuf in the argument 00088 is freed by this function. If the function returns a pbuf (i.e., 00089 returns non-NULL), that pbuf constitutes an ARP reply and should be 00090 sent out on the Ethernet. */ 00091 struct pbuf *arp_arp_input(struct netif *netif, struct eth_addr *ethaddr, 00092 struct pbuf *p); 00093 00094 /* arp_loopup() is called to do an IP address -> Ethernet address 00095 translation. If the function returns NULL, there is no mapping and 00096 the arp_query() function should be called. */ 00097 struct eth_addr *arp_lookup(struct ip_addr *ipaddr); 00098 00099 /* Constructs an ARP query packet for the given IP address. The 00100 function returns a pbuf that contains the reply and that should be 00101 sent out on the Ethernet. */ 00102 struct pbuf *arp_query(struct netif *netif, struct eth_addr *ethaddr, 00103 struct ip_addr *ipaddr); 00104 00105 #endif /* __NETIF_ARP_H__ */