source: MondoRescue/trunk/mindi-busybox/networking/udhcp/static_leases.c@ 904

Last change on this file since 904 was 821, checked in by Bruno Cornec, 18 years ago

Addition of busybox 1.2.1 as a mindi-busybox new package
This should avoid delivering binary files in mindi not built there (Fedora and Debian are quite serious about that)

File size: 2.3 KB
Line 
1/*
2 * static_leases.c -- Couple of functions to assist with storing and
3 * retrieving data for static leases
4 *
5 * Wade Berrier <wberrier@myrealbox.com> September 2004
6 *
7 */
8
9
10#include <stdlib.h>
11#include <stdio.h>
12#include <string.h>
13
14#include "static_leases.h"
15#include "dhcpd.h"
16
17/* Takes the address of the pointer to the static_leases linked list,
18 * Address to a 6 byte mac address
19 * Address to a 4 byte ip address */
20int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip)
21{
22
23 struct static_lease *cur;
24 struct static_lease *new_static_lease;
25
26 /* Build new node */
27 new_static_lease = xmalloc(sizeof(struct static_lease));
28 new_static_lease->mac = mac;
29 new_static_lease->ip = ip;
30 new_static_lease->next = NULL;
31
32 /* If it's the first node to be added... */
33 if(*lease_struct == NULL)
34 {
35 *lease_struct = new_static_lease;
36 }
37 else
38 {
39 cur = *lease_struct;
40 while(cur->next != NULL)
41 {
42 cur = cur->next;
43 }
44
45 cur->next = new_static_lease;
46 }
47
48 return 1;
49
50}
51
52/* Check to see if a mac has an associated static lease */
53uint32_t getIpByMac(struct static_lease *lease_struct, void *arg)
54{
55 uint32_t return_ip;
56 struct static_lease *cur = lease_struct;
57 uint8_t *mac = arg;
58
59 return_ip = 0;
60
61 while(cur != NULL)
62 {
63 /* If the client has the correct mac */
64 if(memcmp(cur->mac, mac, 6) == 0)
65 {
66 return_ip = *(cur->ip);
67 }
68
69 cur = cur->next;
70 }
71
72 return return_ip;
73
74}
75
76/* Check to see if an ip is reserved as a static ip */
77uint32_t reservedIp(struct static_lease *lease_struct, uint32_t ip)
78{
79 struct static_lease *cur = lease_struct;
80
81 uint32_t return_val = 0;
82
83 while(cur != NULL)
84 {
85 /* If the client has the correct ip */
86 if(*cur->ip == ip)
87 return_val = 1;
88
89 cur = cur->next;
90 }
91
92 return return_val;
93
94}
95
96#ifdef CONFIG_FEATURE_UDHCP_DEBUG
97/* Print out static leases just to check what's going on */
98/* Takes the address of the pointer to the static_leases linked list */
99void printStaticLeases(struct static_lease **arg)
100{
101 /* Get a pointer to the linked list */
102 struct static_lease *cur = *arg;
103
104 while(cur != NULL)
105 {
106 /* printf("PrintStaticLeases: Lease mac Address: %x\n", cur->mac); */
107 printf("PrintStaticLeases: Lease mac Value: %x\n", *(cur->mac));
108 /* printf("PrintStaticLeases: Lease ip Address: %x\n", cur->ip); */
109 printf("PrintStaticLeases: Lease ip Value: %x\n", *(cur->ip));
110
111 cur = cur->next;
112 }
113
114
115}
116#endif
117
118
119
Note: See TracBrowser for help on using the repository browser.