MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / get_ip

Function get_ip

components/net/lwip-dhcpd/dhcp_server.c:171–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169}
170
171static uint8_t get_ip(struct mac_addr_t *p_mac_addr)
172{
173 static uint8_t next_client_ip = DHCPD_CLIENT_IP_MIN;
174 static struct mac_ip_item_t mac_table[MAC_TABLE_LEN];
175 static int offset = 0;
176
177 struct mac_addr_t bad_mac;
178 int i;
179 uint8_t ip_addr_3;
180
181 rt_memset(&bad_mac, 0, sizeof(bad_mac));
182 if (!rt_memcmp(&bad_mac, p_mac_addr, sizeof(bad_mac)))
183 {
184 DEBUG_PRINTF("mac address all zero");
185 ip_addr_3 = DHCPD_CLIENT_IP_MAX;
186 goto _return;
187 }
188
189 rt_memset(&bad_mac, 0xFF, sizeof(bad_mac));
190 if (!rt_memcmp(&bad_mac, p_mac_addr, sizeof(bad_mac)))
191 {
192 DEBUG_PRINTF("mac address all one");
193 ip_addr_3 = DHCPD_CLIENT_IP_MAX;
194 goto _return;
195 }
196
197 for (i = 0; i < MAC_TABLE_LEN; i++)
198 {
199 if (!rt_memcmp(&mac_table[i].mac_addr, p_mac_addr, sizeof(bad_mac)))
200 {
201 //use old ip
202 ip_addr_3 = mac_table[i].ip_addr_3;
203 DEBUG_PRINTF("return old ip: %d\n", (int)ip_addr_3);
204 goto _return;
205 }
206 }
207
208 /* add new ip */
209 mac_table[offset].mac_addr = *p_mac_addr;
210 mac_table[offset].ip_addr_3 = next_client_ip;
211 ip_addr_3 = mac_table[offset].ip_addr_3 ;
212
213 offset++;
214 if (offset >= MAC_TABLE_LEN)
215 offset = 0;
216
217 next_client_ip++;
218 if (next_client_ip > DHCPD_CLIENT_IP_MAX)
219 next_client_ip = DHCPD_CLIENT_IP_MIN;
220
221 DEBUG_PRINTF("create new ip: %d\n", (int)ip_addr_3);
222 DEBUG_PRINTF("next_client_ip %d\n", next_client_ip);
223
224_return:
225 return ip_addr_3;
226}
227
228static void dhcpd_thread_entry(void *parameter)

Callers 2

dhcpd_thread_entryFunction · 0.85
drv_ethernet.cFile · 0.85

Calls 2

rt_memsetFunction · 0.85
rt_memcmpFunction · 0.85

Tested by

no test coverage detected