1 /* vi: set sw=4 ts=4: */
3 * static_leases.c -- Couple of functions to assist with storing and
4 * retrieving data for static leases
6 * Wade Berrier <wberrier@myrealbox.com> September 2004
15 #include "static_leases.h"
18 /* Takes the address of the pointer to the static_leases linked list,
19 * Address to a 6 byte mac address
20 * Address to a 4 byte ip address */
21 int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip)
24 struct static_lease *cur;
25 struct static_lease *new_static_lease;
28 new_static_lease = xmalloc(sizeof(struct static_lease));
29 new_static_lease->mac = mac;
30 new_static_lease->ip = ip;
31 new_static_lease->next = NULL;
33 /* If it's the first node to be added... */
34 if(*lease_struct == NULL)
36 *lease_struct = new_static_lease;
41 while(cur->next != NULL)
46 cur->next = new_static_lease;
53 /* Check to see if a mac has an associated static lease */
54 uint32_t getIpByMac(struct static_lease *lease_struct, void *arg)
57 struct static_lease *cur = lease_struct;
64 /* If the client has the correct mac */
65 if(memcmp(cur->mac, mac, 6) == 0)
67 return_ip = *(cur->ip);
77 /* Check to see if an ip is reserved as a static ip */
78 uint32_t reservedIp(struct static_lease *lease_struct, uint32_t ip)
80 struct static_lease *cur = lease_struct;
82 uint32_t return_val = 0;
86 /* If the client has the correct ip */
97 #ifdef CONFIG_FEATURE_UDHCP_DEBUG
98 /* Print out static leases just to check what's going on */
99 /* Takes the address of the pointer to the static_leases linked list */
100 void printStaticLeases(struct static_lease **arg)
102 /* Get a pointer to the linked list */
103 struct static_lease *cur = *arg;
107 /* printf("PrintStaticLeases: Lease mac Address: %x\n", cur->mac); */
108 printf("PrintStaticLeases: Lease mac Value: %x\n", *(cur->mac));
109 /* printf("PrintStaticLeases: Lease ip Address: %x\n", cur->ip); */
110 printf("PrintStaticLeases: Lease ip Value: %x\n", *(cur->ip));