summaryrefslogtreecommitdiff
path: root/networking/udhcp/files.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2004-03-15 08:29:22 +0000
committerEric Andersen <andersen@codepoet.org>2004-03-15 08:29:22 +0000
commitc7bda1ce659294d6e22c06e087f6f265983c7578 (patch)
tree4c6d2217f4d8306c59cf1096f8664e1cfd167213 /networking/udhcp/files.c
parent8854004b41065b3d081af7f3df13a100b0c8bfbe (diff)
downloadbusybox-w32-c7bda1ce659294d6e22c06e087f6f265983c7578.tar.gz
busybox-w32-c7bda1ce659294d6e22c06e087f6f265983c7578.tar.bz2
busybox-w32-c7bda1ce659294d6e22c06e087f6f265983c7578.zip
Remove trailing whitespace. Update copyright to include 2004.
Diffstat (limited to 'networking/udhcp/files.c')
-rw-r--r--networking/udhcp/files.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c
index 0802bb316..89287ca2d 100644
--- a/networking/udhcp/files.c
+++ b/networking/udhcp/files.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * files.c -- DHCP server file manipulation * 2 * files.c -- DHCP server file manipulation *
3 * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001 3 * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001
4 */ 4 */
5 5
6#include <sys/socket.h> 6#include <sys/socket.h>
7#include <arpa/inet.h> 7#include <arpa/inet.h>
8#include <string.h> 8#include <string.h>
@@ -16,7 +16,7 @@
16#include "options.h" 16#include "options.h"
17#include "common.h" 17#include "common.h"
18 18
19/* 19/*
20 * Domain names may have 254 chars, and string options can be 254 20 * Domain names may have 254 chars, and string options can be 254
21 * chars long. However, 80 bytes will be enough for most, and won't 21 * chars long. However, 80 bytes will be enough for most, and won't
22 * hog up memory. If you have a special application, change it 22 * hog up memory. If you have a special application, change it
@@ -31,7 +31,7 @@ static int read_ip(const char *line, void *arg)
31 int retval = 1; 31 int retval = 1;
32 32
33 if (!inet_aton(line, addr)) { 33 if (!inet_aton(line, addr)) {
34 if ((host = gethostbyname(line))) 34 if ((host = gethostbyname(line)))
35 addr->s_addr = *((unsigned long *) host->h_addr_list[0]); 35 addr->s_addr = *((unsigned long *) host->h_addr_list[0]);
36 else retval = 0; 36 else retval = 0;
37 } 37 }
@@ -42,10 +42,10 @@ static int read_ip(const char *line, void *arg)
42static int read_str(const char *line, void *arg) 42static int read_str(const char *line, void *arg)
43{ 43{
44 char **dest = arg; 44 char **dest = arg;
45 45
46 if (*dest) free(*dest); 46 if (*dest) free(*dest);
47 *dest = strdup(line); 47 *dest = strdup(line);
48 48
49 return 1; 49 return 1;
50} 50}
51 51
@@ -69,7 +69,7 @@ static int read_yn(const char *line, void *arg)
69 else if (!strcasecmp("no", line)) 69 else if (!strcasecmp("no", line))
70 *dest = 0; 70 *dest = 0;
71 else retval = 0; 71 else retval = 0;
72 72
73 return retval; 73 return retval;
74} 74}
75 75
@@ -89,11 +89,11 @@ static int read_opt(const char *const_line, void *arg)
89 /* Cheat, the only const line we'll actually get is "" */ 89 /* Cheat, the only const line we'll actually get is "" */
90 line = (char *) const_line; 90 line = (char *) const_line;
91 if (!(opt = strtok(line, " \t="))) return 0; 91 if (!(opt = strtok(line, " \t="))) return 0;
92 92
93 for (option = dhcp_options; option->code; option++) 93 for (option = dhcp_options; option->code; option++)
94 if (!strcasecmp(option->name, opt)) 94 if (!strcasecmp(option->name, opt))
95 break; 95 break;
96 96
97 if (!option->code) return 0; 97 if (!option->code) return 0;
98 98
99 do { 99 do {
@@ -134,17 +134,17 @@ static int read_opt(const char *const_line, void *arg)
134 retval = (endptr[0] == '\0'); 134 retval = (endptr[0] == '\0');
135 break; 135 break;
136 case OPTION_U32: 136 case OPTION_U32:
137 *result_u32 = htonl(strtoul(val, &endptr, 0)); 137 *result_u32 = htonl(strtoul(val, &endptr, 0));
138 retval = (endptr[0] == '\0'); 138 retval = (endptr[0] == '\0');
139 break; 139 break;
140 case OPTION_S32: 140 case OPTION_S32:
141 *result_u32 = htonl(strtol(val, &endptr, 0)); 141 *result_u32 = htonl(strtol(val, &endptr, 0));
142 retval = (endptr[0] == '\0'); 142 retval = (endptr[0] == '\0');
143 break; 143 break;
144 default: 144 default:
145 break; 145 break;
146 } 146 }
147 if (retval) 147 if (retval)
148 attach_option(opt_list, option, opt, length); 148 attach_option(opt_list, option, opt, length);
149 } while (retval && option->flags & OPTION_LIST); 149 } while (retval && option->flags & OPTION_LIST);
150 return retval; 150 return retval;
@@ -193,7 +193,7 @@ int read_config(const char *file)
193 LOG(LOG_ERR, "unable to open config file: %s", file); 193 LOG(LOG_ERR, "unable to open config file: %s", file);
194 return 0; 194 return 0;
195 } 195 }
196 196
197 while (fgets(buffer, READ_CONFIG_BUF_SIZE, in)) { 197 while (fgets(buffer, READ_CONFIG_BUF_SIZE, in)) {
198 lm++; 198 lm++;
199 if (strchr(buffer, '\n')) *(strchr(buffer, '\n')) = '\0'; 199 if (strchr(buffer, '\n')) *(strchr(buffer, '\n')) = '\0';
@@ -203,14 +203,14 @@ int read_config(const char *file)
203 if (strchr(buffer, '#')) *(strchr(buffer, '#')) = '\0'; 203 if (strchr(buffer, '#')) *(strchr(buffer, '#')) = '\0';
204 204
205 if (!(token = strtok(buffer, " \t"))) continue; 205 if (!(token = strtok(buffer, " \t"))) continue;
206 if (!(line = strtok(NULL, ""))) continue; 206 if (!(line = strtok(NULL, ""))) continue;
207 207
208 /* eat leading whitespace */ 208 /* eat leading whitespace */
209 line = line + strspn(line, " \t="); 209 line = line + strspn(line, " \t=");
210 /* eat trailing whitespace */ 210 /* eat trailing whitespace */
211 for (i = strlen(line); i > 0 && isspace(line[i - 1]); i--); 211 for (i = strlen(line); i > 0 && isspace(line[i - 1]); i--);
212 line[i] = '\0'; 212 line[i] = '\0';
213 213
214 for (i = 0; keywords[i].keyword[0]; i++) 214 for (i = 0; keywords[i].keyword[0]; i++)
215 if (!strcasecmp(token, keywords[i].keyword)) 215 if (!strcasecmp(token, keywords[i].keyword))
216 if (!keywords[i].handler(line, keywords[i].var)) { 216 if (!keywords[i].handler(line, keywords[i].var)) {
@@ -232,12 +232,12 @@ void write_leases(void)
232 char buf[255]; 232 char buf[255];
233 time_t curr = time(0); 233 time_t curr = time(0);
234 unsigned long tmp_time; 234 unsigned long tmp_time;
235 235
236 if (!(fp = fopen(server_config.lease_file, "w"))) { 236 if (!(fp = fopen(server_config.lease_file, "w"))) {
237 LOG(LOG_ERR, "Unable to open %s for writing", server_config.lease_file); 237 LOG(LOG_ERR, "Unable to open %s for writing", server_config.lease_file);
238 return; 238 return;
239 } 239 }
240 240
241 for (i = 0; i < server_config.max_leases; i++) { 241 for (i = 0; i < server_config.max_leases; i++) {
242 if (leases[i].yiaddr != 0) { 242 if (leases[i].yiaddr != 0) {
243 243
@@ -257,7 +257,7 @@ void write_leases(void)
257 } 257 }
258 } 258 }
259 fclose(fp); 259 fclose(fp);
260 260
261 if (server_config.notify_file) { 261 if (server_config.notify_file) {
262 sprintf(buf, "%s %s", server_config.notify_file, server_config.lease_file); 262 sprintf(buf, "%s %s", server_config.notify_file, server_config.lease_file);
263 system(buf); 263 system(buf);
@@ -270,12 +270,12 @@ void read_leases(const char *file)
270 FILE *fp; 270 FILE *fp;
271 unsigned int i = 0; 271 unsigned int i = 0;
272 struct dhcpOfferedAddr lease; 272 struct dhcpOfferedAddr lease;
273 273
274 if (!(fp = fopen(file, "r"))) { 274 if (!(fp = fopen(file, "r"))) {
275 LOG(LOG_ERR, "Unable to open %s for reading", file); 275 LOG(LOG_ERR, "Unable to open %s for reading", file);
276 return; 276 return;
277 } 277 }
278 278
279 while (i < server_config.max_leases && (fread(&lease, sizeof lease, 1, fp) == 1)) { 279 while (i < server_config.max_leases && (fread(&lease, sizeof lease, 1, fp) == 1)) {
280 /* ADDME: is it a static lease */ 280 /* ADDME: is it a static lease */
281 if (lease.yiaddr >= server_config.start && lease.yiaddr <= server_config.end) { 281 if (lease.yiaddr >= server_config.start && lease.yiaddr <= server_config.end) {
@@ -284,7 +284,7 @@ void read_leases(const char *file)
284 if (!(add_lease(lease.chaddr, lease.yiaddr, lease.expires))) { 284 if (!(add_lease(lease.chaddr, lease.yiaddr, lease.expires))) {
285 LOG(LOG_WARNING, "Too many leases while loading %s\n", file); 285 LOG(LOG_WARNING, "Too many leases while loading %s\n", file);
286 break; 286 break;
287 } 287 }
288 i++; 288 i++;
289 } 289 }
290 } 290 }