2 * static_leases.c -- Couple of functions to assist with storing and
3 * retrieving data for static leases
5 * Wade Berrier <wberrier@myrealbox.com> September 2004
14 #include "static_leases.h"
17 /* Takes the address of the pointer to the static_leases linked list,
18 * Address to a 6 byte mac address
19 * Address to a 4 byte ip address */
20 int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip)
23 struct static_lease *cur;
24 struct static_lease *new_static_lease;
27 new_static_lease = xmalloc(sizeof(struct static_lease));
28 new_static_lease->mac = mac;
29 new_static_lease->ip = ip;
30 new_static_lease->next = NULL;
32 /* If it's the first node to be added... */
33 if(*lease_struct == NULL)
35 *lease_struct = new_static_lease;
40 while(cur->next != NULL)
45 cur->next = new_static_lease;
52 /* Check to see if a mac has an associated static lease */
53 uint32_t getIpByMac(struct static_lease *lease_struct, void *arg)
56 struct static_lease *cur = lease_struct;
63 /* If the client has the correct mac */
64 if(memcmp(cur->mac, mac, 6) == 0)
66 return_ip = *(cur->ip);
76 /* Check to see if an ip is reserved as a static ip */
77 uint32_t reservedIp(struct static_lease *lease_struct, uint32_t ip)
79 struct static_lease *cur = lease_struct;
81 uint32_t return_val = 0;
85 /* If the client has the correct ip */
96 #ifdef CONFIG_FEATURE_UDHCP_DEBUG
97 /* Print out static leases just to check what's going on */
98 /* Takes the address of the pointer to the static_leases linked list */
99 void printStaticLeases(struct static_lease **arg)
101 /* Get a pointer to the linked list */
102 struct static_lease *cur = *arg;
106 /* printf("PrintStaticLeases: Lease mac Address: %x\n", cur->mac); */
107 printf("PrintStaticLeases: Lease mac Value: %x\n", *(cur->mac));
108 /* printf("PrintStaticLeases: Lease ip Address: %x\n", cur->ip); */
109 printf("PrintStaticLeases: Lease ip Value: %x\n", *(cur->ip));