Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Feb 2017 09:12:36 +0000 (UTC)
From:      Renato Botelho <garga@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r313802 - stable/11/usr.sbin/arp
Message-ID:  <201702160912.v1G9CaNj031034@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: garga (ports committer)
Date: Thu Feb 16 09:12:36 2017
New Revision: 313802
URL: https://svnweb.freebsd.org/changeset/base/313802

Log:
  MFC r313477:
  
  Cleanup on usr.sbin/arp/arp.c
  
  * 'blackhole' and 'reject' are mutually exclusive, replace printf() by errx()
    when both are selected.
  * 'trail' option is no longer supported since first import of arp from 4.4BSD.
    XXX message was added 13 years ago in r128192. I believe it's time to remove
    it.
  * Use warnx() to print some informative messages instead of printf()
  * Replace strncmp() by strcmp() when validating parameters and exit when invalid
    parameter is found
  
  Reviewed by:	allanjude, vangyzen, cem
  Approved by:	allanjude
  MFC after:	1 week
  Sponsored by:	Rubicon Communications (Netgate)
  Differential Revision:	https://reviews.freebsd.org/D9504

Modified:
  stable/11/usr.sbin/arp/arp.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/arp/arp.c
==============================================================================
--- stable/11/usr.sbin/arp/arp.c	Thu Feb 16 06:52:53 2017	(r313801)
+++ stable/11/usr.sbin/arp/arp.c	Thu Feb 16 09:12:36 2017	(r313802)
@@ -319,7 +319,7 @@ set(int argc, char **argv)
 		return (1);
 	doing_proxy = flags = expire_time = 0;
 	while (argc-- > 0) {
-		if (strncmp(argv[0], "temp", 4) == 0) {
+		if (strcmp(argv[0], "temp") == 0) {
 			struct timespec tp;
 			int max_age;
 			size_t len = sizeof(max_age);
@@ -329,10 +329,10 @@ set(int argc, char **argv)
 			    &max_age, &len, NULL, 0) != 0)
 				err(1, "sysctlbyname");
 			expire_time = tp.tv_sec + max_age;
-		} else if (strncmp(argv[0], "pub", 3) == 0) {
+		} else if (strcmp(argv[0], "pub") == 0) {
 			flags |= RTF_ANNOUNCE;
 			doing_proxy = 1;
-			if (argc && strncmp(argv[1], "only", 3) == 0) {
+			if (argc && strcmp(argv[1], "only") == 0) {
 				/*
 				 * Compatibility: in pre FreeBSD 8 times
 				 * the "only" keyword used to mean that
@@ -341,29 +341,28 @@ set(int argc, char **argv)
 				 */
 				argc--; argv++;
 			}
-		} else if (strncmp(argv[0], "blackhole", 9) == 0) {
+		} else if (strcmp(argv[0], "blackhole") == 0) {
 			if (flags & RTF_REJECT) {
-				printf("Choose one of blackhole or reject, "
+				errx(1, "Choose one of blackhole or reject, "
 				    "not both.");
 			}
 			flags |= RTF_BLACKHOLE;
-		} else if (strncmp(argv[0], "reject", 6) == 0) {
+		} else if (strcmp(argv[0], "reject") == 0) {
 			if (flags & RTF_BLACKHOLE) {
-				printf("Choose one of blackhole or reject, "
+				errx(1, "Choose one of blackhole or reject, "
 				    "not both.");
 			}
 			flags |= RTF_REJECT;
-		} else if (strncmp(argv[0], "trail", 5) == 0) {
-			/* XXX deprecated and undocumented feature */
-			printf("%s: Sending trailers is no longer supported\n",
-			    host);
+		} else {
+			warnx("Invalid parameter '%s'", argv[0]);
+			usage();
 		}
 		argv++;
 	}
 	ea = (struct ether_addr *)LLADDR(&sdl_m);
 	if (doing_proxy && !strcmp(eaddr, "auto")) {
 		if (!get_ether_addr(dst->sin_addr.s_addr, ea)) {
-			printf("no interface found for %s\n",
+			warnx("no interface found for %s",
 			       inet_ntoa(dst->sin_addr));
 			return (1);
 		}
@@ -399,7 +398,7 @@ set(int argc, char **argv)
 	if ((sdl->sdl_family != AF_LINK) ||
 	    (rtm->rtm_flags & RTF_GATEWAY) ||
 	    !valid_type(sdl->sdl_type)) {
-		printf("cannot intuit interface index and type for %s\n", host);
+		warnx("cannot intuit interface index and type for %s", host);
 		return (1);
 	}
 	sdl_m.sdl_type = sdl->sdl_type;
@@ -487,7 +486,7 @@ delete(char *host)
 		 * is a proxy-arp entry to remove.
 		 */
 		if (flags & RTF_ANNOUNCE) {
-			fprintf(stderr, "delete: cannot locate %s\n", host);
+			warnx("delete: cannot locate %s", host);
 			return (1);
 		}
 
@@ -870,9 +869,8 @@ get_ether_addr(in_addr_t ipaddr, struct 
 	 */
 	dla = (struct sockaddr_dl *) &ifr->ifr_addr;
 	memcpy(hwaddr,  LLADDR(dla), dla->sdl_alen);
-	printf("using interface %s for proxy with address ",
-		ifp->ifr_name);
-	printf("%s\n", ether_ntoa(hwaddr));
+	printf("using interface %s for proxy with address %s\n", ifp->ifr_name,
+	    ether_ntoa(hwaddr));
 	retval = dla->sdl_alen;
 done:
 	close(sock);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201702160912.v1G9CaNj031034>