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
8 * Licensed under GPLv2, see file LICENSE in this tarball for details.
15 /* Takes the address of the pointer to the static_leases linked list,
16 * Address to a 6 byte mac address
17 * Address to a 4 byte ip address */
18 void FAST_FUNC addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t ip)
20 struct static_lease *new_static_lease;
23 new_static_lease = xzalloc(sizeof(struct static_lease));
24 memcpy(new_static_lease->mac, mac, 6);
25 new_static_lease->ip = ip;
26 /*new_static_lease->next = NULL;*/
28 /* If it's the first node to be added... */
29 if (*lease_struct == NULL) {
30 *lease_struct = new_static_lease;
32 struct static_lease *cur = *lease_struct;
35 cur->next = new_static_lease;
39 /* Check to see if a mac has an associated static lease */
40 uint32_t FAST_FUNC getIpByMac(struct static_lease *lease_struct, void *mac)
42 while (lease_struct) {
43 if (memcmp(lease_struct->mac, mac, 6) == 0)
44 return lease_struct->ip;
45 lease_struct = lease_struct->next;
51 /* Check to see if an ip is reserved as a static ip */
52 int FAST_FUNC reservedIp(struct static_lease *lease_struct, uint32_t ip)
54 while (lease_struct) {
55 if (lease_struct->ip == ip)
57 lease_struct = lease_struct->next;
63 #if ENABLE_UDHCP_DEBUG
64 /* Print out static leases just to check what's going on */
65 /* Takes the address of the pointer to the static_leases linked list */
66 void FAST_FUNC printStaticLeases(struct static_lease **arg)
68 struct static_lease *cur = *arg;
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]
75 printf("PrintStaticLeases: Lease ip Value: %x\n", cur->ip);