[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[openap-cvs] : udhcp dhcpd.c,1.1.1.1,1.2 files.c,1.1.1.1,1.2 files.h,1.1
From: |
David Kimdon <address@hidden> |
Subject: |
[openap-cvs] : udhcp dhcpd.c,1.1.1.1,1.2 files.c,1.1.1.1,1.2 files.h,1.1.1.1,1.2 |
Date: |
Sun, 19 May 2002 23:59:48 -0400 |
Update of /cvsroot/openap/udhcp
In directory subversions:/tmp/cvs-serv3845
Modified Files:
dhcpd.c files.c files.h
Log Message:
* dhcpd.c (main): New command line option, -o, allows us to pass options
on the command line that are interpreted as lines from the config file.
* files.c (set_options): new function. This was previously in
read_config(), it takes a line from the config file and processes it.
(read_config): call set_option() on each line in the config file.
files.h: new prototype set_options()
Index: dhcpd.c
===================================================================
RCS file: /cvsroot/openap/udhcp/dhcpd.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- dhcpd.c 8 May 2002 04:41:16 -0000 1.1.1.1
+++ dhcpd.c 20 May 2002 03:59:46 -0000 1.2
@@ -33,6 +33,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
+#include <getopt.h>
#include <signal.h>
#include <errno.h>
#include <sys/ioctl.h>
@@ -55,6 +56,14 @@
struct dhcpOfferedAddr *leases;
struct server_config_t server_config;
+static void print_usage(void)
+{
+ printf(
+"Usage: udhcpd [OPTIONS]\n\n"
+" -o, --option=STRING Configuration option, overrides "
DHCPD_CONF_FILE "\n"
+ );
+}
+
/* Exit and cleanup */
static void exit_server(int retval)
@@ -93,12 +102,16 @@
struct dhcpOfferedAddr *lease;
struct sockaddr_in *sin;
int pid_fd;
+ int c;
+ static struct option options[] = {
+ {"option", required_argument, 0, 'o'},
+ {"help", no_argument, 0, 'h'},
+ };
+
/* server ip addr */
int fd = -1;
struct ifreq ifr;
-
- argc = argv[0][0]; /* get rid of some warnings */
OPEN_LOG("udhcpd");
LOG(LOG_INFO, "udhcp server (v%s) started", VERSION);
@@ -109,6 +122,23 @@
memset(&server_config, 0, sizeof(struct server_config_t));
read_config(DHCPD_CONF_FILE);
+
+ /* get options, potentially overriding DHCPD_CONF_FILE */
+ while (1) {
+ int option_index = 0;
+ c = getopt_long(argc, argv, "o:h", options, &option_index);
+ if (c == -1) break;
+
+ switch (c) {
+ case 'o':
+ set_option(optarg);
+ break;
+ case 'h':
+ print_usage();
+ return 0;
+ }
+ }
+
if ((option = find_option(server_config.options, DHCP_LEASE_TIME))) {
memcpy(&server_config.lease, option->data + 2, 4);
server_config.lease = ntohl(server_config.lease);
Index: files.c
===================================================================
RCS file: /cvsroot/openap/udhcp/files.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- files.c 8 May 2002 04:41:17 -0000 1.1.1.1
+++ files.c 20 May 2002 03:59:46 -0000 1.2
@@ -167,10 +167,32 @@
};
+void set_option(char *buffer)
+{
+ char *token, *line;
+ int i;
+
+ if (strchr(buffer, '\n')) *(strchr(buffer, '\n')) = '\0';
+ if (strchr(buffer, '#')) *(strchr(buffer, '#')) = '\0';
+ token = buffer + strspn(buffer, " \t");
+ if (*token == '\0') return;
+ line = token + strcspn(token, " \t=");
+ if (*line == '\0') return;
+ *line = '\0';
+ line++;
+ line = line + strspn(line, " \t=");
+ if (*line == '\0') return;
+
+ for (i = 0; strlen(keywords[i].keyword); i++)
+ if (!strcasecmp(token, keywords[i].keyword))
+ keywords[i].handler(line, keywords[i].var);
+}
+
+
int read_config(char *file)
{
FILE *in;
- char buffer[80], *token, *line;
+ char buffer[80];
int i;
for (i = 0; strlen(keywords[i].keyword); i++)
@@ -183,22 +205,7 @@
}
while (fgets(buffer, 80, in)) {
- if (strchr(buffer, '\n')) *(strchr(buffer, '\n')) = '\0';
- if (strchr(buffer, '#')) *(strchr(buffer, '#')) = '\0';
- token = buffer + strspn(buffer, " \t");
- if (*token == '\0') continue;
- line = token + strcspn(token, " \t=");
- if (*line == '\0') continue;
- *line = '\0';
- line++;
- line = line + strspn(line, " \t=");
- if (*line == '\0') continue;
-
-
-
- for (i = 0; strlen(keywords[i].keyword); i++)
- if (!strcasecmp(token, keywords[i].keyword))
- keywords[i].handler(line, keywords[i].var);
+ set_option(buffer);
}
fclose(in);
return 1;
Index: files.h
===================================================================
RCS file: /cvsroot/openap/udhcp/files.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- files.h 8 May 2002 04:41:17 -0000 1.1.1.1
+++ files.h 20 May 2002 03:59:46 -0000 1.2
@@ -11,6 +11,7 @@
int read_config(char *file);
+void set_option(char *buffer);
void write_leases(int dummy);
void read_leases(char *file);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [openap-cvs] : udhcp dhcpd.c,1.1.1.1,1.2 files.c,1.1.1.1,1.2 files.h,1.1.1.1,1.2,
David Kimdon <address@hidden> <=