summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>1999-09-07 15:34:12 +0000
committerru <ru@FreeBSD.org>1999-09-07 15:34:12 +0000
commit7357a87ddfa888278fb56f4edb37429919af9539 (patch)
tree9f7420b2b4a46f4260393cb8c3c671a97646bf29 /sbin
parent2058967546d46d8ae30621016b7418b5bc6fd25f (diff)
downloadFreeBSD-src-7357a87ddfa888278fb56f4edb37429919af9539.zip
FreeBSD-src-7357a87ddfa888278fb56f4edb37429919af9539.tar.gz
Config file parser changes:
- Trailing spaces and empty lines are ignored. - A `#' sign will mark the remaining of the line as a comment. Reviewed by: Ari Suutari <ari@suutari.iki.fi>
Diffstat (limited to 'sbin')
-rw-r--r--sbin/natd/natd.86
-rw-r--r--sbin/natd/natd.c18
2 files changed, 15 insertions, 9 deletions
diff --git a/sbin/natd/natd.8 b/sbin/natd/natd.8
index 24ebce5..6ca4595 100644
--- a/sbin/natd/natd.8
+++ b/sbin/natd/natd.8
@@ -270,7 +270,11 @@ in the configuration file. For example, the line
is synonomous with
.Fl log .
-Empty lines and lines beginning with '#' are ignored.
+.Pp
+Trailing spaces and empty lines are ignored.
+A
+.Ql \&#
+sign will mark the remaining of the line as a comment.
.It Fl reverse
Reverse operation of natd. This can be useful in some
diff --git a/sbin/natd/natd.c b/sbin/natd/natd.c
index 4bea079..bde38f7 100644
--- a/sbin/natd/natd.c
+++ b/sbin/natd/natd.c
@@ -1246,7 +1246,7 @@ void ReadConfigFile (const char* fileName)
{
FILE* file;
char buf[128];
- char* ptr;
+ char *ptr, *p;
char* option;
file = fopen (fileName, "r");
@@ -1263,18 +1263,20 @@ void ReadConfigFile (const char* fileName)
errx (1, "config line too long: %s", buf);
*ptr = '\0';
- if (buf[0] == '#')
- continue;
- ptr = buf;
/*
- * Skip white space at beginning of line.
+ * Check for comments, strip off trailing spaces.
*/
- while (*ptr && isspace (*ptr))
- ++ptr;
-
+ if ((ptr = strchr(buf, '#')))
+ *ptr = '\0';
+ for (ptr = buf; isspace(*ptr); ++ptr)
+ continue;
if (*ptr == '\0')
continue;
+ for (p = strchr(buf, '\0'); isspace(*--p);)
+ continue;
+ *++p = '\0';
+
/*
* Extract option name.
*/
OpenPOWER on IntegriCloud