From owner-svn-src-all@FreeBSD.ORG Tue Aug 26 10:35:33 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4D80E971; Tue, 26 Aug 2014 10:35:33 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 38BF43637; Tue, 26 Aug 2014 10:35:33 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7QAZXk2008043; Tue, 26 Aug 2014 10:35:33 GMT (envelope-from ae@FreeBSD.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s7QAZWU0008040; Tue, 26 Aug 2014 10:35:32 GMT (envelope-from ae@FreeBSD.org) Message-Id: <201408261035.s7QAZWU0008040@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: ae set sender to ae@FreeBSD.org using -f From: "Andrey V. Elsukov" Date: Tue, 26 Aug 2014 10:35:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r270656 - stable/9/usr.sbin/ndp X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Aug 2014 10:35:33 -0000 Author: ae Date: Tue Aug 26 10:35:32 2014 New Revision: 270656 URL: http://svnweb.freebsd.org/changeset/base/270656 Log: MFC r265778 (by melifaro): Fix ndp(8) -f flag parsing PR: bin/136661 MFC r268827 (by peter): Fix "ndp -d hostname". Modified: stable/9/usr.sbin/ndp/ndp.8 stable/9/usr.sbin/ndp/ndp.c Directory Properties: stable/9/usr.sbin/ndp/ (props changed) Modified: stable/9/usr.sbin/ndp/ndp.8 ============================================================================== --- stable/9/usr.sbin/ndp/ndp.8 Tue Aug 26 10:32:08 2014 (r270655) +++ stable/9/usr.sbin/ndp/ndp.8 Tue Aug 26 10:35:32 2014 (r270656) @@ -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. Modified: stable/9/usr.sbin/ndp/ndp.c ============================================================================== --- stable/9/usr.sbin/ndp/ndp.c Tue Aug 26 10:32:08 2014 (r270655) +++ stable/9/usr.sbin/ndp/ndp.c Tue Aug 26 10:35:32 2014 (r270656) @@ -97,6 +97,7 @@ #include +#include #include #include #include @@ -131,7 +132,7 @@ char host_buf[NI_MAXHOST]; /* getnamein 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 *); @@ -194,9 +195,10 @@ main(argc, 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*/ @@ -319,18 +321,16 @@ main(argc, argv) /* * Process a file to set standard ndp entries */ -int +static int file(name) 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]; @@ -338,10 +338,15 @@ file(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; }