aboutsummaryrefslogtreecommitdiff
path: root/sbin/route/route.c
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/route/route.c')
-rw-r--r--sbin/route/route.c53
1 files changed, 30 insertions, 23 deletions
diff --git a/sbin/route/route.c b/sbin/route/route.c
index 3913bdc9e6af..f37d23d25c2c 100644
--- a/sbin/route/route.c
+++ b/sbin/route/route.c
@@ -29,19 +29,6 @@
* SUCH DAMAGE.
*/
-#ifndef lint
-static const char copyright[] =
-"@(#) Copyright (c) 1983, 1989, 1991, 1993\n\
- The Regents of the University of California. All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)route.c 8.6 (Berkeley) 4/28/95";
-#endif
-#endif /* not lint */
-
-#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/file.h>
#include <sys/socket.h>
@@ -107,8 +94,8 @@ static u_long rtm_inits;
static uid_t uid;
static int defaultfib;
static int numfibs;
-static char domain[MAXHOSTNAMELEN + 1];
-static bool domain_initialized;
+static char domain_storage[MAXHOSTNAMELEN + 1];
+static const char *domain;
static char rt_line[NI_MAXHOST];
static char net_line[MAXHOSTNAMELEN + 1];
@@ -594,14 +581,16 @@ routename(struct sockaddr *sa)
const char *cp;
int n;
- if (!domain_initialized) {
- domain_initialized = true;
- if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
- (cp = strchr(domain, '.'))) {
- domain[MAXHOSTNAMELEN] = '\0';
- (void)strcpy(domain, cp + 1);
- } else
- domain[0] = '\0';
+ if (domain == NULL) {
+ if (gethostname(domain_storage,
+ sizeof(domain_storage) - 1) == 0 &&
+ (cp = strchr(domain_storage, '.')) != NULL) {
+ domain_storage[sizeof(domain_storage) - 1] = '\0';
+ domain = cp + 1;
+ } else {
+ domain_storage[0] = '\0';
+ domain = domain_storage;
+ }
}
/* If the address is zero-filled, use "default". */
@@ -1342,6 +1331,9 @@ getaddr(int idx, char *str, int nrflags)
q = strchr(str,'/');
if (q != NULL && idx == RTAX_DST) {
/* A.B.C.D/NUM */
+ struct sockaddr_in *mask;
+ uint32_t mask_bits;
+
*q = '\0';
if (inet_aton(str, &sin->sin_addr) == 0)
errx(EX_NOHOST, "bad address: %s", str);
@@ -1351,6 +1343,20 @@ getaddr(int idx, char *str, int nrflags)
errx(EX_NOHOST, "bad mask length: %s", q + 1);
inet_makemask((struct sockaddr_in *)&so[RTAX_NETMASK],masklen);
+
+ /*
+ * Check for bogus destination such as "10/8"; heuristic is
+ * that there are bits set in the host part, and no dot
+ * is present.
+ */
+ mask = ((struct sockaddr_in *) &so[RTAX_NETMASK]);
+ mask_bits = ntohl(mask->sin_addr.s_addr);
+ if ((ntohl(sin->sin_addr.s_addr) & ~mask_bits) != 0 &&
+ strchr(str, '.') == NULL)
+ errx(EX_NOHOST,
+ "malformed address, bits set after mask;"
+ " %s means %s",
+ str, inet_ntoa(sin->sin_addr));
return (0);
}
if (inet_aton(str, &sin->sin_addr) != 0)
@@ -1657,6 +1663,7 @@ static const char *const msgtypes[] = {
"RTM_DELMADDR: multicast group membership removed from iface",
"RTM_IFANNOUNCE: interface arrival/departure",
"RTM_IEEE80211: IEEE 802.11 wireless event",
+ "RTM_IPFWLOG: IPFW log",
};
static const char metricnames[] =