aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/static_leases.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/static_leases.c')
-rw-r--r--networking/udhcp/static_leases.c41
1 files changed, 10 insertions, 31 deletions
diff --git a/networking/udhcp/static_leases.c b/networking/udhcp/static_leases.c
index 0d962c56e..b53eac5a4 100644
--- a/networking/udhcp/static_leases.c
+++ b/networking/udhcp/static_leases.c
@@ -7,20 +7,15 @@
7 * 7 *
8 */ 8 */
9 9
10 10#include "common.h"
11#include <stdlib.h>
12#include <stdio.h>
13#include <string.h>
14
15#include "static_leases.h"
16#include "dhcpd.h" 11#include "dhcpd.h"
17 12
13
18/* Takes the address of the pointer to the static_leases linked list, 14/* Takes the address of the pointer to the static_leases linked list,
19 * Address to a 6 byte mac address 15 * Address to a 6 byte mac address
20 * Address to a 4 byte ip address */ 16 * Address to a 4 byte ip address */
21int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip) 17int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip)
22{ 18{
23
24 struct static_lease *cur; 19 struct static_lease *cur;
25 struct static_lease *new_static_lease; 20 struct static_lease *new_static_lease;
26 21
@@ -31,15 +26,11 @@ int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *i
31 new_static_lease->next = NULL; 26 new_static_lease->next = NULL;
32 27
33 /* If it's the first node to be added... */ 28 /* If it's the first node to be added... */
34 if(*lease_struct == NULL) 29 if (*lease_struct == NULL) {
35 {
36 *lease_struct = new_static_lease; 30 *lease_struct = new_static_lease;
37 } 31 } else {
38 else
39 {
40 cur = *lease_struct; 32 cur = *lease_struct;
41 while(cur->next != NULL) 33 while (cur->next) {
42 {
43 cur = cur->next; 34 cur = cur->next;
44 } 35 }
45 36
@@ -47,7 +38,6 @@ int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *i
47 } 38 }
48 39
49 return 1; 40 return 1;
50
51} 41}
52 42
53/* Check to see if a mac has an associated static lease */ 43/* Check to see if a mac has an associated static lease */
@@ -59,11 +49,9 @@ uint32_t getIpByMac(struct static_lease *lease_struct, void *arg)
59 49
60 return_ip = 0; 50 return_ip = 0;
61 51
62 while(cur != NULL) 52 while (cur) {
63 {
64 /* If the client has the correct mac */ 53 /* If the client has the correct mac */
65 if(memcmp(cur->mac, mac, 6) == 0) 54 if (memcmp(cur->mac, mac, 6) == 0) {
66 {
67 return_ip = *(cur->ip); 55 return_ip = *(cur->ip);
68 } 56 }
69 57
@@ -71,7 +59,6 @@ uint32_t getIpByMac(struct static_lease *lease_struct, void *arg)
71 } 59 }
72 60
73 return return_ip; 61 return return_ip;
74
75} 62}
76 63
77/* Check to see if an ip is reserved as a static ip */ 64/* Check to see if an ip is reserved as a static ip */
@@ -81,17 +68,15 @@ uint32_t reservedIp(struct static_lease *lease_struct, uint32_t ip)
81 68
82 uint32_t return_val = 0; 69 uint32_t return_val = 0;
83 70
84 while(cur != NULL) 71 while (cur) {
85 {
86 /* If the client has the correct ip */ 72 /* If the client has the correct ip */
87 if(*cur->ip == ip) 73 if (*cur->ip == ip)
88 return_val = 1; 74 return_val = 1;
89 75
90 cur = cur->next; 76 cur = cur->next;
91 } 77 }
92 78
93 return return_val; 79 return return_val;
94
95} 80}
96 81
97#ifdef CONFIG_FEATURE_UDHCP_DEBUG 82#ifdef CONFIG_FEATURE_UDHCP_DEBUG
@@ -102,8 +87,7 @@ void printStaticLeases(struct static_lease **arg)
102 /* Get a pointer to the linked list */ 87 /* Get a pointer to the linked list */
103 struct static_lease *cur = *arg; 88 struct static_lease *cur = *arg;
104 89
105 while(cur != NULL) 90 while (cur) {
106 {
107 /* printf("PrintStaticLeases: Lease mac Address: %x\n", cur->mac); */ 91 /* printf("PrintStaticLeases: Lease mac Address: %x\n", cur->mac); */
108 printf("PrintStaticLeases: Lease mac Value: %x\n", *(cur->mac)); 92 printf("PrintStaticLeases: Lease mac Value: %x\n", *(cur->mac));
109 /* printf("PrintStaticLeases: Lease ip Address: %x\n", cur->ip); */ 93 /* printf("PrintStaticLeases: Lease ip Address: %x\n", cur->ip); */
@@ -111,10 +95,5 @@ void printStaticLeases(struct static_lease **arg)
111 95
112 cur = cur->next; 96 cur = cur->next;
113 } 97 }
114
115
116} 98}
117#endif 99#endif
118
119
120