Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/ifwatchd Don't invoke scripts for INADDR_ANY or INA...



details:   https://anonhg.NetBSD.org/src/rev/afe2a248b768
branches:  trunk
changeset: 818137:afe2a248b768
user:      roy <roy%NetBSD.org@localhost>
date:      Thu Sep 29 13:36:30 2016 +0000

description:
Don't invoke scripts for INADDR_ANY or INADDR_BROADCAST addresses.

diffstat:

 usr.sbin/ifwatchd/ifwatchd.c |  35 +++++++++++++++++++++++++----------
 1 files changed, 25 insertions(+), 10 deletions(-)

diffs (50 lines):

diff -r 8c3768876e95 -r afe2a248b768 usr.sbin/ifwatchd/ifwatchd.c
--- a/usr.sbin/ifwatchd/ifwatchd.c      Thu Sep 29 12:19:47 2016 +0000
+++ b/usr.sbin/ifwatchd/ifwatchd.c      Thu Sep 29 13:36:30 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ifwatchd.c,v 1.33 2016/09/21 21:07:29 roy Exp $        */
+/*     $NetBSD: ifwatchd.c,v 1.34 2016/09/29 13:36:30 roy Exp $        */
 
 /*-
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -374,16 +374,31 @@
        const char *script;
        int status;
 
-       if (sa != NULL && sa->sa_len == 0) {
-               fprintf(stderr, "illegal socket address (sa_len == 0)\n");
-               return;
-       }
-       if (sa != NULL && sa->sa_family == AF_INET6) {
-               struct sockaddr_in6 sin6;
+       if (sa != NULL) {
+               if (sa->sa_len == 0) {
+                       fprintf(stderr,
+                           "illegal socket address (sa_len == 0)\n");
+                       return;
+               }
+               switch (sa->sa_family) {
+               case AF_INET:
+               {
+                       const struct sockaddr_in *sin;
 
-               memcpy(&sin6, (const struct sockaddr_in6 *)sa, sizeof (sin6));
-               if (IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr))
-                       return;
+                       sin = (const struct sockaddr_in *)sa;
+                       if (sin->sin_addr.s_addr == INADDR_ANY ||
+                           sin->sin_addr.s_addr == INADDR_BROADCAST)
+                               return;
+               }
+               case AF_INET6:
+               {
+                       const struct sockaddr_in6 *sin6;
+
+                       sin6 = (const struct sockaddr_in6 *)sa;
+                       if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
+                               return;
+               }
+               }
        }
 
        addr[0] = daddr[0] = 0;



Home | Main Index | Thread Index | Old Index