Annotation of /trunk/mkinitrd-magellan/busybox/networking/udhcp/static_leases.c
Parent Directory | Revision Log
Revision 816 -
(hide annotations)
(download)
Fri Apr 24 18:33:46 2009 UTC (15 years, 1 month ago) by niro
File MIME type: text/plain
File size: 2339 byte(s)
Fri Apr 24 18:33:46 2009 UTC (15 years, 1 month ago) by niro
File MIME type: text/plain
File size: 2339 byte(s)
-updated to busybox-1.13.4
1 | niro | 532 | /* vi: set sw=4 ts=4: */ |
2 | /* | ||
3 | * static_leases.c -- Couple of functions to assist with storing and | ||
4 | * retrieving data for static leases | ||
5 | * | ||
6 | * Wade Berrier <wberrier@myrealbox.com> September 2004 | ||
7 | * | ||
8 | */ | ||
9 | |||
10 | #include "common.h" | ||
11 | #include "dhcpd.h" | ||
12 | |||
13 | |||
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 | niro | 816 | int FAST_FUNC addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip) |
18 | niro | 532 | { |
19 | struct static_lease *cur; | ||
20 | struct static_lease *new_static_lease; | ||
21 | |||
22 | /* Build new node */ | ||
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; | ||
27 | |||
28 | /* If it's the first node to be added... */ | ||
29 | if (*lease_struct == NULL) { | ||
30 | *lease_struct = new_static_lease; | ||
31 | } else { | ||
32 | cur = *lease_struct; | ||
33 | while (cur->next) { | ||
34 | cur = cur->next; | ||
35 | } | ||
36 | |||
37 | cur->next = new_static_lease; | ||
38 | } | ||
39 | |||
40 | return 1; | ||
41 | } | ||
42 | |||
43 | /* Check to see if a mac has an associated static lease */ | ||
44 | niro | 816 | uint32_t FAST_FUNC getIpByMac(struct static_lease *lease_struct, void *arg) |
45 | niro | 532 | { |
46 | uint32_t return_ip; | ||
47 | struct static_lease *cur = lease_struct; | ||
48 | uint8_t *mac = arg; | ||
49 | |||
50 | return_ip = 0; | ||
51 | |||
52 | while (cur) { | ||
53 | /* If the client has the correct mac */ | ||
54 | if (memcmp(cur->mac, mac, 6) == 0) { | ||
55 | return_ip = *(cur->ip); | ||
56 | } | ||
57 | |||
58 | cur = cur->next; | ||
59 | } | ||
60 | |||
61 | return return_ip; | ||
62 | } | ||
63 | |||
64 | /* Check to see if an ip is reserved as a static ip */ | ||
65 | niro | 816 | uint32_t FAST_FUNC reservedIp(struct static_lease *lease_struct, uint32_t ip) |
66 | niro | 532 | { |
67 | struct static_lease *cur = lease_struct; | ||
68 | |||
69 | uint32_t return_val = 0; | ||
70 | |||
71 | while (cur) { | ||
72 | /* If the client has the correct ip */ | ||
73 | if (*cur->ip == ip) | ||
74 | return_val = 1; | ||
75 | |||
76 | cur = cur->next; | ||
77 | } | ||
78 | |||
79 | return return_val; | ||
80 | } | ||
81 | |||
82 | niro | 816 | #if ENABLE_UDHCP_DEBUG |
83 | niro | 532 | /* 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 | niro | 816 | void FAST_FUNC printStaticLeases(struct static_lease **arg) |
86 | niro | 532 | { |
87 | /* Get a pointer to the linked list */ | ||
88 | struct static_lease *cur = *arg; | ||
89 | |||
90 | while (cur) { | ||
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)); | ||
95 | |||
96 | cur = cur->next; | ||
97 | } | ||
98 | } | ||
99 | #endif |