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
14 /* Takes the address of the pointer to the static_leases linked list,
15 * Address to a 6 byte mac address
16 * Address to a 4 byte ip address */
17 int FAST_FUNC addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip)
19 struct static_lease *cur;
20 struct static_lease *new_static_lease;
23 new_static_lease = xmalloc(sizeof(struct static_lease));
24 new_static_lease->mac = mac;
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;
37 cur->next = new_static_lease;
43 /* Check to see if a mac has an associated static lease */
44 uint32_t FAST_FUNC getIpByMac(struct static_lease *lease_struct, void *arg)
47 struct static_lease *cur = lease_struct;
53 /* If the client has the correct mac */
54 if (memcmp(cur->mac, mac, 6) == 0) {
55 return_ip = *(cur->ip);
64 /* Check to see if an ip is reserved as a static ip */
65 uint32_t FAST_FUNC reservedIp(struct static_lease *lease_struct, uint32_t ip)
67 struct static_lease *cur = lease_struct;
69 uint32_t return_val = 0;
72 /* If the client has the correct ip */
82 #if ENABLE_FEATURE_UDHCP_DEBUG
83 /* Print out static leases just to check what's going on */
84 /* Takes the address of the pointer to the static_leases linked list */
85 void FAST_FUNC printStaticLeases(struct static_lease **arg)
87 /* Get a pointer to the linked list */
88 struct static_lease *cur = *arg;
91 /* printf("PrintStaticLeases: Lease mac Address: %x\n", cur->mac); */
92 printf("PrintStaticLeases: Lease mac Value: %x\n", *(cur->mac));
93 /* printf("PrintStaticLeases: Lease ip Address: %x\n", cur->ip); */
94 printf("PrintStaticLeases: Lease ip Value: %x\n", *(cur->ip));