📄 uip_arp.lst
字号:
C51 COMPILER V8.15 UIP_ARP 08/11/2009 15:07:53 PAGE 1
C51 COMPILER V8.15, COMPILATION OF MODULE UIP_ARP
OBJECT MODULE PLACED IN .\debug\uip_arp.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE uip_arp.c LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.\debug\uip_arp.lst) OBJECT
-(.\debug\uip_arp.obj)
line level source
1 /**
2 * \addtogroup uip
3 * @{
4 */
5
6 /**
7 * \defgroup uiparp uIP Address Resolution Protocol
8 * @{
9 *
10 * The Address Resolution Protocol ARP is used for mapping between IP
11 * addresses and link level addresses such as the Ethernet MAC
12 * addresses. ARP uses broadcast queries to ask for the link level
13 * address of a known IP address and the host which is configured with
14 * the IP address for which the query was meant, will respond with its
15 * link level address.
16 *
17 * \note This ARP implementation only supports Ethernet.
18 */
19
20 /**
21 * \file
22 * Implementation of the ARP Address Resolution Protocol.
23 * \author Adam Dunkels <adam@dunkels.com>
24 *
25 */
26
27 /*
28 * Copyright (c) 2001-2003, Adam Dunkels.
29 * All rights reserved.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. The name of the author may not be used to endorse or promote
40 * products derived from this software without specific prior
41 * written permission.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
44 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
45 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
47 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
49 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
50 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
51 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
52 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
53 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 *
C51 COMPILER V8.15 UIP_ARP 08/11/2009 15:07:53 PAGE 2
55 * This file is part of the uIP TCP/IP stack.
56 *
57 * $Id: uip_arp.c,v 1.7.2.3 2003/10/06 22:42:30 adam Exp $
58 *
59 */
60
61
62 #include "uip_arp.h"
63
64
65 #include <string.h>
66
67 struct arp_hdr {
68 struct uip_eth_hdr ethhdr;
69 u16_t hwtype;
70 u16_t protocol;
71 u8_t hwlen;
72 u8_t protolen;
73 u16_t opcode;
74 struct uip_eth_addr shwaddr;
75 u16_t sipaddr[2];
76 struct uip_eth_addr dhwaddr;
77 u16_t dipaddr[2];
78 };
79
80 struct ethip_hdr {
81 struct uip_eth_hdr ethhdr;
82 /* IP header. */
83 u8_t vhl,
84 tos,
85 len[2],
86 ipid[2],
87 ipoffset[2],
88 ttl,
89 proto;
90 u16_t ipchksum;
91 u16_t srcipaddr[2],
92 destipaddr[2];
93 };
94
95 #define ARP_REQUEST 1
96 #define ARP_REPLY 2
97
98 #define ARP_HWTYPE_ETH 1
99
100 struct arp_entry {
101 u16_t ipaddr[2];
102 struct uip_eth_addr ethaddr;
103 u8_t time;
104 };
105
106 struct uip_eth_addr uip_ethaddr = {{UIP_ETHADDR0,
107 UIP_ETHADDR1,
108 UIP_ETHADDR2,
109 UIP_ETHADDR3,
110 UIP_ETHADDR4,
111 UIP_ETHADDR5}};
112
113 static struct arp_entry arp_table[UIP_ARPTAB_SIZE];
114 static u16_t ipaddr[2];
115 static u8_t i, c;
116
C51 COMPILER V8.15 UIP_ARP 08/11/2009 15:07:53 PAGE 3
117 static u8_t arptime;
118 static u8_t tmpage;
119
120 #define BUF ((struct arp_hdr *)&uip_buf[0])
121 #define IPBUF ((struct ethip_hdr *)&uip_buf[0])
122 /*-----------------------------------------------------------------------------------*/
123 /**
124 * Initialize the ARP module.
125 *
126 */
127 /*-----------------------------------------------------------------------------------*/
128 void
129 uip_arp_init(void)
130 {
131 1 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
132 2 memset(arp_table[i].ipaddr, 0, 4);
133 2 }
134 1 }
135 /*-----------------------------------------------------------------------------------*/
136 /**
137 * Periodic ARP processing function.
138 *
139 * This function performs periodic timer processing in the ARP module
140 * and should be called at regular intervals. The recommended interval
141 * is 10 seconds between the calls.
142 *
143 */
144 /*-----------------------------------------------------------------------------------*/
145 void
146 uip_arp_timer(void)
147 {
148 1 struct arp_entry *tabptr;
149 1
150 1 ++arptime;
151 1 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
152 2 tabptr = &arp_table[i];
153 2 if((tabptr->ipaddr[0] | tabptr->ipaddr[1]) != 0 &&
154 2 arptime - tabptr->time >= UIP_ARP_MAXAGE) {
155 3 memset(tabptr->ipaddr, 0, 4);
156 3 }
157 2 }
158 1
159 1 }
160 /*-----------------------------------------------------------------------------------*/
161 static void
162 uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)
163 {
164 1 register struct arp_entry *tabptr;
165 1 /* Walk through the ARP mapping table and try to find an entry to
166 1 update. If none is found, the IP -> MAC address mapping is
167 1 inserted in the ARP table. */
168 1 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
169 2
170 2 tabptr = &arp_table[i];
171 2 /* Only check those entries that are actually in use. */
172 2 if(tabptr->ipaddr[0] != 0 &&
173 2 tabptr->ipaddr[1] != 0) {
174 3
175 3 /* Check if the source IP address of the incoming packet matches
176 3 the IP address in this ARP table entry. */
177 3 if(ipaddr[0] == tabptr->ipaddr[0] &&
178 3 ipaddr[1] == tabptr->ipaddr[1]) {
C51 COMPILER V8.15 UIP_ARP 08/11/2009 15:07:53 PAGE 4
179 4
180 4 /* An old entry found, update this and return. */
181 4 memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
182 4 tabptr->time = arptime;
183 4
184 4 return;
185 4 }
186 3 }
187 2 }
188 1
189 1 /* If we get here, no existing ARP table entry was found, so we
190 1 create one. */
191 1
192 1 /* First, we try to find an unused entry in the ARP table. */
193 1 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
194 2 tabptr = &arp_table[i];
195 2 if(tabptr->ipaddr[0] == 0 &&
196 2 tabptr->ipaddr[1] == 0) {
197 3 break;
198 3 }
199 2 }
200 1
201 1 /* If no unused entry is found, we try to find the oldest entry and
202 1 throw it away. */
203 1 if(i == UIP_ARPTAB_SIZE) {
204 2 tmpage = 0;
205 2 c = 0;
206 2 for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
207 3 tabptr = &arp_table[i];
208 3 if(arptime - tabptr->time > tmpage) {
209 4 tmpage = arptime - tabptr->time;
210 4 c = i;
211 4 }
212 3 }
213 2 i = c;
214 2 }
215 1
216 1 /* Now, i is the ARP table entry which we will fill with the new
217 1 information. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -