1
2
3
4
5
6
7
8
9
10
11#include "common.h"
12#include "dhcpd.h"
13
14
15
16
17
18void FAST_FUNC addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t ip)
19{
20 struct static_lease *new_static_lease;
21
22
23 new_static_lease = xzalloc(sizeof(struct static_lease));
24 memcpy(new_static_lease->mac, mac, 6);
25 new_static_lease->ip = ip;
26
27
28
29 if (*lease_struct == NULL) {
30 *lease_struct = new_static_lease;
31 } else {
32 struct static_lease *cur = *lease_struct;
33 while (cur->next)
34 cur = cur->next;
35 cur->next = new_static_lease;
36 }
37}
38
39
40uint32_t FAST_FUNC getIpByMac(struct static_lease *lease_struct, void *mac)
41{
42 while (lease_struct) {
43 if (memcmp(lease_struct->mac, mac, 6) == 0)
44 return lease_struct->ip;
45 lease_struct = lease_struct->next;
46 }
47
48 return 0;
49}
50
51
52int FAST_FUNC reservedIp(struct static_lease *lease_struct, uint32_t ip)
53{
54 while (lease_struct) {
55 if (lease_struct->ip == ip)
56 return 1;
57 lease_struct = lease_struct->next;
58 }
59
60 return 0;
61}
62
63#if ENABLE_UDHCP_DEBUG
64
65
66void FAST_FUNC printStaticLeases(struct static_lease **arg)
67{
68 struct static_lease *cur = *arg;
69
70 while (cur) {
71 printf("PrintStaticLeases: Lease mac Value: %02x:%02x:%02x:%02x:%02x:%02x\n",
72 cur->mac[0], cur->mac[1], cur->mac[2],
73 cur->mac[3], cur->mac[4], cur->mac[5]
74 );
75 printf("PrintStaticLeases: Lease ip Value: %x\n", cur->ip);
76 cur = cur->next;
77 }
78}
79#endif
80