aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/ndp
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2014-08-19 06:50:54 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2014-08-19 06:50:54 +0000
commitee7b0571c2c18bdec848ed2044223cc88db29bd8 (patch)
treeb04f4bd7cd887f50e7d98af35f46b9834ff86c80 /usr.sbin/ndp
parentffda191e301f128a62c152fde92b692548367fca (diff)
parent15fc2873832ea5b9b639e701bbbf2e73af8b6a88 (diff)
downloadsrc-ee7b0571c2c18bdec848ed2044223cc88db29bd8.tar.gz
src-ee7b0571c2c18bdec848ed2044223cc88db29bd8.zip
Merge head from 7/28
Notes
Notes: svn path=/projects/bmake/; revision=270164
Diffstat (limited to 'usr.sbin/ndp')
-rw-r--r--usr.sbin/ndp/ndp.825
-rw-r--r--usr.sbin/ndp/ndp.c25
2 files changed, 36 insertions, 14 deletions
diff --git a/usr.sbin/ndp/ndp.8 b/usr.sbin/ndp/ndp.8
index 19da8bb6e164..c2a4c1de3e22 100644
--- a/usr.sbin/ndp/ndp.8
+++ b/usr.sbin/ndp/ndp.8
@@ -29,7 +29,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd Jan 10, 2013
+.Dd May 9, 2014
.Dt NDP 8
.Os
.\"
@@ -136,9 +136,26 @@ seconds.
Erase all the NDP entries.
.It Fl d
Delete specified NDP entry.
-.It Fl f
-Parse the file specified by
-.Ar filename .
+.It Fl f Ar filename
+Cause the file
+.Ar filename
+to be read and multiple entries to be set in the
+.Tn NDP
+table.
+Entries
+in the file should be of the form
+.Pp
+.Bd -ragged -offset indent -compact
+.Ar hostname ether_addr
+.Op Cm temp
+.Op Cm proxy
+.Ed
+.Pp
+with argument meanings as given above.
+Leading whitespace and empty lines are ignored.
+A
+.Ql #
+character will mark the rest of the line as a comment.
.It Fl H
Harmonize consistency between the routing table and the default router
list; install the top entry of the list into the kernel routing table.
diff --git a/usr.sbin/ndp/ndp.c b/usr.sbin/ndp/ndp.c
index 3888b057b857..e8960102de25 100644
--- a/usr.sbin/ndp/ndp.c
+++ b/usr.sbin/ndp/ndp.c
@@ -97,6 +97,7 @@
#include <arpa/inet.h>
+#include <ctype.h>
#include <netdb.h>
#include <errno.h>
#include <nlist.h>
@@ -126,7 +127,7 @@ char host_buf[NI_MAXHOST]; /* getnameinfo() */
char ifix_buf[IFNAMSIZ]; /* if_indextoname() */
int main(int, char **);
-int file(char *);
+static int file(char *);
void getsocket(void);
int set(int, char **);
void get(char *);
@@ -187,9 +188,10 @@ main(int argc, char **argv)
mode = ch;
arg = NULL;
break;
- case 'd':
case 'f':
- case 'i' :
+ exit(file(optarg) ? 1 : 0);
+ case 'd':
+ case 'i':
if (mode) {
usage();
/*NOTREACHED*/
@@ -312,17 +314,15 @@ main(int argc, char **argv)
/*
* Process a file to set standard ndp entries
*/
-int
+static int
file(char *name)
{
FILE *fp;
int i, retval;
- char line[100], arg[5][50], *args[5];
+ char line[100], arg[5][50], *args[5], *p;
- if ((fp = fopen(name, "r")) == NULL) {
- fprintf(stderr, "ndp: cannot open %s\n", name);
- exit(1);
- }
+ if ((fp = fopen(name, "r")) == NULL)
+ err(1, "cannot open %s", name);
args[0] = &arg[0][0];
args[1] = &arg[1][0];
args[2] = &arg[2][0];
@@ -330,10 +330,15 @@ file(char *name)
args[4] = &arg[4][0];
retval = 0;
while (fgets(line, sizeof(line), fp) != NULL) {
+ if ((p = strchr(line, '#')) != NULL)
+ *p = '\0';
+ for (p = line; isblank(*p); p++);
+ if (*p == '\n' || *p == '\0')
+ continue;
i = sscanf(line, "%49s %49s %49s %49s %49s",
arg[0], arg[1], arg[2], arg[3], arg[4]);
if (i < 2) {
- fprintf(stderr, "ndp: bad line: %s\n", line);
+ warnx("bad line: %s", line);
retval = 1;
continue;
}