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