Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/rtsold KNF, bump warns, fix warnings to print the p...



details:   https://anonhg.NetBSD.org/src/rev/a6ee16179492
branches:  trunk
changeset: 327821:a6ee16179492
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Mar 18 00:16:49 2014 +0000

description:
KNF, bump warns, fix warnings to print the program name.

diffstat:

 usr.sbin/rtsold/Makefile |    3 +-
 usr.sbin/rtsold/dump.c   |   30 +++++-----
 usr.sbin/rtsold/if.c     |   49 ++++++++---------
 usr.sbin/rtsold/probe.c  |   24 ++++----
 usr.sbin/rtsold/rtsock.c |    6 +-
 usr.sbin/rtsold/rtsol.c  |   36 +++++++------
 usr.sbin/rtsold/rtsold.c |  126 +++++++++++++++++-----------------------------
 usr.sbin/rtsold/rtsold.h |   48 +++++++++--------
 8 files changed, 147 insertions(+), 175 deletions(-)

diffs (truncated from 849 to 300 lines):

diff -r 3ea8edaa164f -r a6ee16179492 usr.sbin/rtsold/Makefile
--- a/usr.sbin/rtsold/Makefile  Mon Mar 17 21:21:57 2014 +0000
+++ b/usr.sbin/rtsold/Makefile  Tue Mar 18 00:16:49 2014 +0000
@@ -1,5 +1,6 @@
-# $NetBSD: Makefile,v 1.14 2009/04/22 15:23:08 lukem Exp $
+# $NetBSD: Makefile,v 1.15 2014/03/18 00:16:49 christos Exp $
 
+WARNS?=6
 USE_FORT?= yes # network client (local server)
 
 PROG=  rtsold
diff -r 3ea8edaa164f -r a6ee16179492 usr.sbin/rtsold/dump.c
--- a/usr.sbin/rtsold/dump.c    Mon Mar 17 21:21:57 2014 +0000
+++ b/usr.sbin/rtsold/dump.c    Tue Mar 18 00:16:49 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dump.c,v 1.9 2009/04/11 07:51:59 lukem Exp $   */
+/*     $NetBSD: dump.c,v 1.10 2014/03/18 00:16:49 christos Exp $       */
 /*     $KAME: dump.c,v 1.10 2002/05/31 10:10:03 itojun Exp $   */
 
 /*
@@ -48,11 +48,11 @@
 
 static FILE *fp;
 
-extern struct ifinfo *iflist;
-
-static void dump_interface_status __P((void));
-static const char *sec2str __P((time_t));
-const char *ifstatstr[] = {"IDLE", "DELAY", "PROBE", "DOWN", "TENTATIVE"};
+static void dump_interface_status(void);
+static const char *sec2str(time_t);
+static const char *ifstatstr[] = {
+       "IDLE", "DELAY", "PROBE", "DOWN", "TENTATIVE"
+};
 
 static void
 dump_interface_status(void)
@@ -115,32 +115,32 @@
        char *ep = &result[sizeof(result)];
        int n;
 
-       days = total / 3600 / 24;
-       hours = (total / 3600) % 24;
-       mins = (total / 60) % 60;
-       secs = total % 60;
+       days = (int)(total / 3600 / 24);
+       hours = (int)((total / 3600) % 24);
+       mins = (int)((total / 60) % 60);
+       secs = (int)(total % 60);
 
        if (days) {
                first = 0;
-               n = snprintf(p, ep - p, "%dd", days);
+               n = snprintf(p, (size_t)(ep - p), "%dd", days);
                if (n < 0 || n >= ep - p)
                        return "?";
                p += n;
        }
        if (!first || hours) {
                first = 0;
-               n = snprintf(p, ep - p, "%dh", hours);
+               n = snprintf(p, (size_t)(ep - p), "%dh", hours);
                if (n < 0 || n >= ep - p)
                        return "?";
                p += n;
        }
        if (!first || mins) {
                first = 0;
-               n = snprintf(p, ep - p, "%dm", mins);
+               n = snprintf(p, (size_t)(ep - p), "%dm", mins);
                if (n < 0 || n >= ep - p)
                        return "?";
                p += n;
        }
-       snprintf(p, ep - p, "%ds", secs);
-       return(result);
+       snprintf(p, (size_t)(ep - p), "%ds", secs);
+       return result;
 }
diff -r 3ea8edaa164f -r a6ee16179492 usr.sbin/rtsold/if.c
--- a/usr.sbin/rtsold/if.c      Mon Mar 17 21:21:57 2014 +0000
+++ b/usr.sbin/rtsold/if.c      Tue Mar 18 00:16:49 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.15 2006/03/18 21:41:23 dan Exp $      */
+/*     $NetBSD: if.c,v 1.16 2014/03/18 00:16:49 christos Exp $ */
 /*     $KAME: if.c,v 1.18 2002/05/31 10:10:03 itojun Exp $     */
 
 /*
@@ -59,18 +59,17 @@
 
 #include "rtsold.h"
 
-extern int rssock;
 static int ifsock;
 
-static int get_llflag __P((const char *));
-static void get_rtaddrs __P((int, struct sockaddr *, struct sockaddr **));
+static int get_llflag(const char *);
+static void get_rtaddrs(int, struct sockaddr *, struct sockaddr **);
 
 int
 ifinit(void)
 {
        ifsock = rssock;
 
-       return(0);
+       return 0;
 }
 
 int
@@ -81,17 +80,17 @@
 
        strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
 
-       if (ioctl(ifsock, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
+       if (ioctl(ifsock, SIOCGIFFLAGS, &ifr) < 0) {
                warnmsg(LOG_WARNING, __func__, "ioctl(SIOCGIFFLAGS): %s",
                    strerror(errno));
-               return(-1);
+               return -1;
        }
        if (!(ifr.ifr_flags & IFF_UP)) {
                ifr.ifr_flags |= IFF_UP;
-               if (ioctl(ifsock, SIOCSIFFLAGS, (caddr_t)&ifr) < 0)
+               if (ioctl(ifsock, SIOCSIFFLAGS, &ifr) < 0)
                        warnmsg(LOG_ERR, __func__,
                            "ioctl(SIOCSIFFLAGS): %s", strerror(errno));
-               return(-1);
+               return -1;
        }
 
        warnmsg(LOG_DEBUG, __func__, "checking if %s is ready...", name);
@@ -105,7 +104,7 @@
 
        if (!(llflag & IN6_IFF_NOTREADY)) {
                warnmsg(LOG_DEBUG, __func__, "%s is ready", name);
-               return(0);
+               return 0;
        } else {
                if (llflag & IN6_IFF_TENTATIVE) {
                        warnmsg(LOG_DEBUG, __func__, "%s is tentative",
@@ -132,7 +131,7 @@
        if (ioctl(ifsock, SIOCGIFFLAGS, &ifr) < 0) {
                warnmsg(LOG_ERR, __func__, "ioctl(SIOCGIFFLAGS) on %s: %s",
                    ifname, strerror(errno));
-               return(-1);
+               return -1;
        }
        /*
         * if one of UP and RUNNING flags is dropped,
@@ -148,12 +147,12 @@
        memset(&ifmr, 0, sizeof(ifmr));
        strncpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
 
-       if (ioctl(ifsock, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
+       if (ioctl(ifsock, SIOCGIFMEDIA, &ifmr) < 0) {
                if (errno != EINVAL) {
                        warnmsg(LOG_DEBUG, __func__,
                            "ioctl(SIOCGIFMEDIA) on %s: %s",
                            ifname, strerror(errno));
-                       return(-1);
+                       return -1;
                }
                /*
                 * EINVAL simply means that the interface does not support
@@ -177,21 +176,21 @@
        }
 
   inactive:
-       return(0);
+       return 0;
 
   active:
-       return(1);
+       return 1;
 }
 
 #define ROUNDUP(a, size) \
        (((a) & ((size)-1)) ? (1 + ((a) | ((size)-1))) : (a))
 
 #define NEXT_SA(ap) (ap) = (struct sockaddr *) \
-       ((caddr_t)(ap) + ((ap)->sa_len ? ROUNDUP((ap)->sa_len,\
+       ((char *)(ap) + ((ap)->sa_len ? ROUNDUP((ap)->sa_len,\
        sizeof(u_long)) : sizeof(u_long)))
 #define ROUNDUP8(a) (1 + (((a) - 1) | 7))
 
-int
+size_t
 lladdropt_length(struct sockaddr_dl *sdl)
 {
        switch (sdl->sdl_type) {
@@ -199,9 +198,9 @@
 #ifdef IFT_IEEE80211
        case IFT_IEEE80211:
 #endif
-               return(ROUNDUP8(ETHER_ADDR_LEN + 2));
+               return ROUNDUP8(ETHER_ADDR_LEN + 2);
        default:
-               return(0);
+               return 0;
        }
 }
 
@@ -241,12 +240,12 @@
        struct sockaddr_dl *sdl = NULL, *ret_sdl;
 
        if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0)
-               return(NULL);
+               return NULL;
        if ((buf = malloc(len)) == NULL)
-               return(NULL);
+               return NULL;
        if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
                free(buf);
-               return(NULL);
+               return NULL;
        }
 
        lim = buf + len;
@@ -272,14 +271,14 @@
        if (next == lim || sdl == NULL) {
                /* search failed */
                free(buf);
-               return(NULL);
+               return NULL;
        }
 
        if ((ret_sdl = malloc(sdl->sdl_len)) == NULL) {
                free(buf);
-               return(NULL);
+               return NULL;
        }
-       memcpy((caddr_t)ret_sdl, (caddr_t)sdl, sdl->sdl_len);
+       memcpy(ret_sdl, sdl, sdl->sdl_len);
 
        free(buf);
        return(ret_sdl);
diff -r 3ea8edaa164f -r a6ee16179492 usr.sbin/rtsold/probe.c
--- a/usr.sbin/rtsold/probe.c   Mon Mar 17 21:21:57 2014 +0000
+++ b/usr.sbin/rtsold/probe.c   Tue Mar 18 00:16:49 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: probe.c,v 1.11 2010/01/18 04:53:10 christos Exp $      */
+/*     $NetBSD: probe.c,v 1.12 2014/03/18 00:16:49 christos Exp $      */
 /*     $KAME: probe.c,v 1.15 2002/05/31 21:22:08 itojun Exp $  */
 
 /*
@@ -58,39 +58,39 @@
 static struct msghdr sndmhdr;
 static struct iovec sndiov[2];
 static int probesock;
-static void sendprobe __P((struct in6_addr *, struct ifinfo *));
+static void sendprobe(struct in6_addr *, struct ifinfo *);
 
 int
 probe_init(void)
 {
-       int scmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
+       size_t scmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
            CMSG_SPACE(sizeof(int));
        static u_char *sndcmsgbuf = NULL;
 
        if (sndcmsgbuf == NULL &&
-           (sndcmsgbuf = (u_char *)malloc(scmsglen)) == NULL) {
+           (sndcmsgbuf = malloc(scmsglen)) == NULL) {
                warnmsg(LOG_ERR, __func__, "malloc failed");
-               return(-1);
+               return -1;
        }
 
        if ((probesock = socket(AF_INET6, SOCK_RAW, IPPROTO_NONE)) < 0) {
                warnmsg(LOG_ERR, __func__, "socket: %s", strerror(errno));
-               return(-1);
+               return -1;
        }
 
        /* make the socket send-only */
        if (shutdown(probesock, 0)) {
                warnmsg(LOG_ERR, __func__, "shutdown: %s", strerror(errno));
-               return(-1);
+               return -1;
        }
 
        /* initialize msghdr for sending packets */
        sndmhdr.msg_namelen = sizeof(struct sockaddr_in6);
        sndmhdr.msg_iov = sndiov;
        sndmhdr.msg_iovlen = 1;
-       sndmhdr.msg_control = (caddr_t)sndcmsgbuf;
-       sndmhdr.msg_controllen = scmsglen;
-       return(0);
+       sndmhdr.msg_control = sndcmsgbuf;
+       sndmhdr.msg_controllen = (socklen_t)scmsglen;
+       return 0;
 }
 
 /*
@@ -110,7 +110,7 @@
        }
        memset(&dr, 0, sizeof(dr));
        strlcpy(dr.ifname, "lo0", sizeof dr.ifname); /* dummy interface */
-       if (ioctl(s, SIOCGDRLST_IN6, (caddr_t)&dr) < 0) {



Home | Main Index | Thread Index | Old Index