aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/files.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/files.c')
-rw-r--r--networking/udhcp/files.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c
index 89287ca2d..73a3bbc6e 100644
--- a/networking/udhcp/files.c
+++ b/networking/udhcp/files.c
@@ -11,6 +11,9 @@
11#include <ctype.h> 11#include <ctype.h>
12#include <netdb.h> 12#include <netdb.h>
13 13
14#include <netinet/ether.h>
15#include "static_leases.h"
16
14#include "dhcpd.h" 17#include "dhcpd.h"
15#include "files.h" 18#include "files.h"
16#include "options.h" 19#include "options.h"
@@ -38,6 +41,22 @@ static int read_ip(const char *line, void *arg)
38 return retval; 41 return retval;
39} 42}
40 43
44static int read_mac(const char *line, void *arg)
45{
46 uint8_t *mac_bytes = arg;
47 struct ether_addr *temp_ether_addr;
48 int retval = 1;
49
50 temp_ether_addr = ether_aton(line);
51
52 if(temp_ether_addr == NULL)
53 retval = 0;
54 else
55 memcpy(mac_bytes, temp_ether_addr, 6);
56
57 return retval;
58}
59
41 60
42static int read_str(const char *line, void *arg) 61static int read_str(const char *line, void *arg)
43{ 62{
@@ -150,6 +169,39 @@ static int read_opt(const char *const_line, void *arg)
150 return retval; 169 return retval;
151} 170}
152 171
172static int read_staticlease(const char *const_line, void *arg)
173{
174
175 char *line;
176 char *mac_string;
177 char *ip_string;
178 uint8_t *mac_bytes;
179 uint32_t *ip;
180
181
182 /* Allocate memory for addresses */
183 mac_bytes = xmalloc(sizeof(unsigned char) * 8);
184 ip = xmalloc(sizeof(uint32_t));
185
186 /* Read mac */
187 line = (char *) const_line;
188 mac_string = strtok(line, " \t");
189 read_mac(mac_string, mac_bytes);
190
191 /* Read ip */
192 ip_string = strtok(NULL, " \t");
193 read_ip(ip_string, ip);
194
195 addStaticLease(arg, mac_bytes, ip);
196
197#ifdef UDHCP_DEBUG
198 printStaticLeases(arg);
199#endif
200
201 return 1;
202
203}
204
153 205
154static const struct config_keyword keywords[] = { 206static const struct config_keyword keywords[] = {
155 /* keyword handler variable address default */ 207 /* keyword handler variable address default */
@@ -171,6 +223,7 @@ static const struct config_keyword keywords[] = {
171 {"siaddr", read_ip, &(server_config.siaddr), "0.0.0.0"}, 223 {"siaddr", read_ip, &(server_config.siaddr), "0.0.0.0"},
172 {"sname", read_str, &(server_config.sname), ""}, 224 {"sname", read_str, &(server_config.sname), ""},
173 {"boot_file", read_str, &(server_config.boot_file), ""}, 225 {"boot_file", read_str, &(server_config.boot_file), ""},
226 {"static_lease",read_staticlease, &(server_config.static_leases), ""},
174 /*ADDME: static lease */ 227 /*ADDME: static lease */
175 {"", NULL, NULL, ""} 228 {"", NULL, NULL, ""}
176}; 229};