BSD 4_4 release
[unix-history] / usr / src / sys / net / if.c
index 372387c..f86dbaf 100644 (file)
@@ -1,44 +1,55 @@
 /*
 /*
- * Copyright (c) 1980, 1986 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1986, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * Redistribution is only permitted until one year after the first shipment
- * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
- * binary forms are permitted provided that: (1) source distributions retain
- * this entire copyright notice and comment, and (2) distributions including
- * binaries display the following acknowledgement:  This product includes
- * software developed by the University of California, Berkeley and its
- * contributors'' in the documentation or other materials provided with the
- * distribution and in all advertising materials mentioning features or use
- * of this software.  Neither the name of the University nor the names of
- * its contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     @(#)if.c        7.13 (Berkeley) 6/28/90
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)if.c        8.1 (Berkeley) 6/29/93
  */
 
  */
 
-#include "param.h"
-#include "mbuf.h"
-#include "systm.h"
-#include "socket.h"
-#include "socketvar.h"
-#include "protosw.h"
-#include "user.h"
-#include "kernel.h"
-#include "ioctl.h"
-#include "errno.h"
-
-#include "if.h"
-#include "af.h"
-#include "if_dl.h"
-#include "if_types.h"
-
-#include "ether.h"
+#include <sys/param.h>
+#include <sys/mbuf.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/protosw.h>
+#include <sys/kernel.h>
+#include <sys/ioctl.h>
+
+#include <net/if.h>
+#include <net/af.h>
+#include <net/if_dl.h>
+#include <net/if_types.h>
 
 int    ifqmaxlen = IFQ_MAXLEN;
 
 int    ifqmaxlen = IFQ_MAXLEN;
+void   if_slowtimo __P((void *arg));
 
 /*
  * Network interface utility routines.
 
 /*
  * Network interface utility routines.
@@ -46,7 +57,7 @@ int   ifqmaxlen = IFQ_MAXLEN;
  * Routines with ifa_ifwith* names take sockaddr *'s as
  * parameters.
  */
  * Routines with ifa_ifwith* names take sockaddr *'s as
  * parameters.
  */
-
+void
 ifinit()
 {
        register struct ifnet *ifp;
 ifinit()
 {
        register struct ifnet *ifp;
@@ -54,13 +65,14 @@ ifinit()
        for (ifp = ifnet; ifp; ifp = ifp->if_next)
                if (ifp->if_snd.ifq_maxlen == 0)
                        ifp->if_snd.ifq_maxlen = ifqmaxlen;
        for (ifp = ifnet; ifp; ifp = ifp->if_next)
                if (ifp->if_snd.ifq_maxlen == 0)
                        ifp->if_snd.ifq_maxlen = ifqmaxlen;
-       if_slowtimo();
+       if_slowtimo(0);
 }
 
 #ifdef vax
 /*
  * Call each interface on a Unibus reset.
  */
 }
 
 #ifdef vax
 /*
  * Call each interface on a Unibus reset.
  */
+void
 ifubareset(uban)
        int uban;
 {
 ifubareset(uban)
        int uban;
 {
@@ -74,21 +86,24 @@ ifubareset(uban)
 
 int if_index = 0;
 struct ifaddr **ifnet_addrs;
 
 int if_index = 0;
 struct ifaddr **ifnet_addrs;
+static char *sprint_d __P((u_int, char *, int));
+
 /*
  * Attach an interface to the
  * list of "active" interfaces.
  */
 /*
  * Attach an interface to the
  * list of "active" interfaces.
  */
+void
 if_attach(ifp)
        struct ifnet *ifp;
 {
        unsigned socksize, ifasize;
 if_attach(ifp)
        struct ifnet *ifp;
 {
        unsigned socksize, ifasize;
-       int namelen, unitlen;
-       char workbuf[16];
+       int namelen, unitlen, masklen, ether_output();
+       char workbuf[12], *unitname;
        register struct ifnet **p = &ifnet;
        register struct sockaddr_dl *sdl;
        register struct ifaddr *ifa;
        static int if_indexlim = 8;
        register struct ifnet **p = &ifnet;
        register struct sockaddr_dl *sdl;
        register struct ifaddr *ifa;
        static int if_indexlim = 8;
-       extern link_rtrequest(), ether_output();
+       extern void link_rtrequest();
 
        while (*p)
                p = &((*p)->if_next);
 
        while (*p)
                p = &((*p)->if_next);
@@ -104,48 +119,46 @@ if_attach(ifp)
                }
                ifnet_addrs = q;
        }
                }
                ifnet_addrs = q;
        }
-       /* XXX -- Temporary fix before changing 10 ethernet drivers */
-       if (ifp->if_output == ether_output) {
-               ifp->if_type = IFT_ETHER;
-               ifp->if_addrlen = 6;
-               ifp->if_hdrlen = 14;
-       }
        /*
         * create a Link Level name for this device
         */
        /*
         * create a Link Level name for this device
         */
-       sprint_d(workbuf, ifp->if_unit);
+       unitname = sprint_d((u_int)ifp->if_unit, workbuf, sizeof(workbuf));
        namelen = strlen(ifp->if_name);
        namelen = strlen(ifp->if_name);
-       unitlen = strlen(workbuf);
+       unitlen = strlen(unitname);
 #define _offsetof(t, m) ((int)((caddr_t)&((t *)0)->m))
 #define _offsetof(t, m) ((int)((caddr_t)&((t *)0)->m))
-       socksize = _offsetof(struct sockaddr_dl, sdl_data[0]) +
-                              unitlen + namelen + ifp->if_addrlen;
+       masklen = _offsetof(struct sockaddr_dl, sdl_data[0]) +
+                              unitlen + namelen;
+       socksize = masklen + ifp->if_addrlen;
 #define ROUNDUP(a) (1 + (((a) - 1) | (sizeof(long) - 1)))
        socksize = ROUNDUP(socksize);
        if (socksize < sizeof(*sdl))
                socksize = sizeof(*sdl);
        ifasize = sizeof(*ifa) + 2 * socksize;
 #define ROUNDUP(a) (1 + (((a) - 1) | (sizeof(long) - 1)))
        socksize = ROUNDUP(socksize);
        if (socksize < sizeof(*sdl))
                socksize = sizeof(*sdl);
        ifasize = sizeof(*ifa) + 2 * socksize;
-       ifa = (struct ifaddr *)malloc(ifasize, M_IFADDR, M_WAITOK);
-       if (ifa == 0)
-               return;
-       ifnet_addrs[if_index - 1] = ifa;
-       bzero((caddr_t)ifa, ifasize);
-       sdl = (struct sockaddr_dl *)(ifa + 1);
-       ifa->ifa_addr = (struct sockaddr *)sdl;
-       ifa->ifa_ifp = ifp;
-       sdl->sdl_len = socksize;
-       sdl->sdl_family = AF_LINK;
-       bcopy(ifp->if_name, sdl->sdl_data, namelen);
-       bcopy((caddr_t)workbuf, namelen + (caddr_t)sdl->sdl_data, unitlen);
-       sdl->sdl_nlen = (namelen += unitlen);
-       sdl->sdl_index = ifp->if_index;
-       sdl = (struct sockaddr_dl *)(socksize + (caddr_t)sdl);
-       ifa->ifa_netmask = (struct sockaddr *)sdl;
-       sdl->sdl_len = socksize - ifp->if_addrlen;
-       while (namelen != 0)
-               sdl->sdl_data[--namelen] = 0xff;
-       ifa->ifa_next = ifp->if_addrlist;
-       ifa->ifa_rtrequest = link_rtrequest;
-       ifp->if_addrlist = ifa;
+       if (ifa = (struct ifaddr *)malloc(ifasize, M_IFADDR, M_WAITOK)) {
+               bzero((caddr_t)ifa, ifasize);
+               sdl = (struct sockaddr_dl *)(ifa + 1);
+               sdl->sdl_len = socksize;
+               sdl->sdl_family = AF_LINK;
+               bcopy(ifp->if_name, sdl->sdl_data, namelen);
+               bcopy(unitname, namelen + (caddr_t)sdl->sdl_data, unitlen);
+               sdl->sdl_nlen = (namelen += unitlen);
+               sdl->sdl_index = ifp->if_index;
+               sdl->sdl_type = ifp->if_type;
+               ifnet_addrs[if_index - 1] = ifa;
+               ifa->ifa_ifp = ifp;
+               ifa->ifa_next = ifp->if_addrlist;
+               ifa->ifa_rtrequest = link_rtrequest;
+               ifp->if_addrlist = ifa;
+               ifa->ifa_addr = (struct sockaddr *)sdl;
+               sdl = (struct sockaddr_dl *)(socksize + (caddr_t)sdl);
+               ifa->ifa_netmask = (struct sockaddr *)sdl;
+               sdl->sdl_len = masklen;
+               while (namelen != 0)
+                       sdl->sdl_data[--namelen] = 0xff;
+       }
+       /* XXX -- Temporary fix before changing 10 ethernet drivers */
+       if (ifp->if_output == ether_output)
+               ether_ifattach(ifp);
 }
 /*
  * Locate an interface based on a complete address.
 }
 /*
  * Locate an interface based on a complete address.
@@ -196,7 +209,7 @@ ifa_ifwithdstaddr(addr)
 
 /*
  * Find an interface on a specific network.  If many, choice
 
 /*
  * Find an interface on a specific network.  If many, choice
- * is first found.
+ * is most specific found.
  */
 struct ifaddr *
 ifa_ifwithnet(addr)
  */
 struct ifaddr *
 ifa_ifwithnet(addr)
@@ -204,10 +217,10 @@ ifa_ifwithnet(addr)
 {
        register struct ifnet *ifp;
        register struct ifaddr *ifa;
 {
        register struct ifnet *ifp;
        register struct ifaddr *ifa;
+       struct ifaddr *ifa_maybe = (struct ifaddr *) 0;
        u_int af = addr->sa_family;
        u_int af = addr->sa_family;
+       char *addr_data = addr->sa_data, *cplim;
 
 
-       if (af >= AF_MAX)
-               return (0);
        if (af == AF_LINK) {
            register struct sockaddr_dl *sdl = (struct sockaddr_dl *)addr;
            if (sdl->sdl_index && sdl->sdl_index <= if_index)
        if (af == AF_LINK) {
            register struct sockaddr_dl *sdl = (struct sockaddr_dl *)addr;
            if (sdl->sdl_index && sdl->sdl_index <= if_index)
@@ -216,20 +229,22 @@ ifa_ifwithnet(addr)
        for (ifp = ifnet; ifp; ifp = ifp->if_next)
            for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) {
                register char *cp, *cp2, *cp3;
        for (ifp = ifnet; ifp; ifp = ifp->if_next)
            for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) {
                register char *cp, *cp2, *cp3;
-               register char *cplim;
+
                if (ifa->ifa_addr->sa_family != af || ifa->ifa_netmask == 0)
                if (ifa->ifa_addr->sa_family != af || ifa->ifa_netmask == 0)
-                       continue;
-               cp = addr->sa_data;
+                       next: continue;
+               cp = addr_data;
                cp2 = ifa->ifa_addr->sa_data;
                cp3 = ifa->ifa_netmask->sa_data;
                cplim = ifa->ifa_netmask->sa_len + (char *)ifa->ifa_netmask;
                cp2 = ifa->ifa_addr->sa_data;
                cp3 = ifa->ifa_netmask->sa_data;
                cplim = ifa->ifa_netmask->sa_len + (char *)ifa->ifa_netmask;
-               for (; cp3 < cplim; cp3++)
-                       if ((*cp++ ^ *cp2++) & *cp3)
-                               break;
-               if (cp3 == cplim)
-                       return (ifa);
+               while (cp3 < cplim)
+                       if ((*cp++ ^ *cp2++) & *cp3++)
+                               goto next;
+               if (ifa_maybe == 0 ||
+                   rn_refines((caddr_t)ifa->ifa_netmask,
+                   (caddr_t)ifa_maybe->ifa_netmask))
+                       ifa_maybe = ifa;
            }
            }
-       return ((struct ifaddr *)0);
+       return (ifa_maybe);
 }
 
 /*
 }
 
 /*
@@ -288,15 +303,19 @@ ifaof_ifpforaddr(addr, ifp)
        }
        return (ifa_maybe);
 }
        }
        return (ifa_maybe);
 }
-#include "route.h"
+
+#include <net/route.h>
+
 /*
  * Default action when installing a route with a Link Level gateway.
  * Lookup an appropriate real ifa to point to.
  * This should be moved to /sys/net/link.c eventually.
  */
 /*
  * Default action when installing a route with a Link Level gateway.
  * Lookup an appropriate real ifa to point to.
  * This should be moved to /sys/net/link.c eventually.
  */
+void
 link_rtrequest(cmd, rt, sa)
 link_rtrequest(cmd, rt, sa)
-register struct rtentry *rt;
-struct sockaddr *sa;
+       int cmd;
+       register struct rtentry *rt;
+       struct sockaddr *sa;
 {
        register struct ifaddr *ifa;
        struct sockaddr *dst;
 {
        register struct ifaddr *ifa;
        struct sockaddr *dst;
@@ -306,7 +325,9 @@ struct sockaddr *sa;
            ((ifp = ifa->ifa_ifp) == 0) || ((dst = rt_key(rt)) == 0))
                return;
        if (ifa = ifaof_ifpforaddr(dst, ifp)) {
            ((ifp = ifa->ifa_ifp) == 0) || ((dst = rt_key(rt)) == 0))
                return;
        if (ifa = ifaof_ifpforaddr(dst, ifp)) {
+               IFAFREE(rt->rt_ifa);
                rt->rt_ifa = ifa;
                rt->rt_ifa = ifa;
+               ifa->ifa_refcnt++;
                if (ifa->ifa_rtrequest && ifa->ifa_rtrequest != link_rtrequest)
                        ifa->ifa_rtrequest(cmd, rt, sa);
        }
                if (ifa->ifa_rtrequest && ifa->ifa_rtrequest != link_rtrequest)
                        ifa->ifa_rtrequest(cmd, rt, sa);
        }
@@ -317,6 +338,7 @@ struct sockaddr *sa;
  * the transition.
  * NOTE: must be called at splnet or eqivalent.
  */
  * the transition.
  * NOTE: must be called at splnet or eqivalent.
  */
+void
 if_down(ifp)
        register struct ifnet *ifp;
 {
 if_down(ifp)
        register struct ifnet *ifp;
 {
@@ -326,11 +348,33 @@ if_down(ifp)
        for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next)
                pfctlinput(PRC_IFDOWN, ifa->ifa_addr);
        if_qflush(&ifp->if_snd);
        for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next)
                pfctlinput(PRC_IFDOWN, ifa->ifa_addr);
        if_qflush(&ifp->if_snd);
+       rt_ifmsg(ifp);
+}
+
+/*
+ * Mark an interface up and notify protocols of
+ * the transition.
+ * NOTE: must be called at splnet or eqivalent.
+ */
+void
+if_up(ifp)
+       register struct ifnet *ifp;
+{
+       register struct ifaddr *ifa;
+
+       ifp->if_flags |= IFF_UP;
+#ifdef notyet
+       /* this has no effect on IP, and will kill all iso connections XXX */
+       for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next)
+               pfctlinput(PRC_IFUP, ifa->ifa_addr);
+#endif
+       rt_ifmsg(ifp);
 }
 
 /*
  * Flush an interface queue.
  */
 }
 
 /*
  * Flush an interface queue.
  */
+void
 if_qflush(ifq)
        register struct ifqueue *ifq;
 {
 if_qflush(ifq)
        register struct ifqueue *ifq;
 {
@@ -351,7 +395,9 @@ if_qflush(ifq)
  * from softclock, we decrement timers (if set) and
  * call the appropriate interface routine on expiration.
  */
  * from softclock, we decrement timers (if set) and
  * call the appropriate interface routine on expiration.
  */
-if_slowtimo()
+void
+if_slowtimo(arg)
+       void *arg;
 {
        register struct ifnet *ifp;
        int s = splimp();
 {
        register struct ifnet *ifp;
        int s = splimp();
@@ -363,7 +409,7 @@ if_slowtimo()
                        (*ifp->if_watchdog)(ifp->if_unit);
        }
        splx(s);
                        (*ifp->if_watchdog)(ifp->if_unit);
        }
        splx(s);
-       timeout(if_slowtimo, (caddr_t)0, hz / IFNET_SLOWHZ);
+       timeout(if_slowtimo, (void *)0, hz / IFNET_SLOWHZ);
 }
 
 /*
 }
 
 /*
@@ -409,10 +455,12 @@ ifunit(name)
 /*
  * Interface ioctls.
  */
 /*
  * Interface ioctls.
  */
-ifioctl(so, cmd, data)
+int
+ifioctl(so, cmd, data, p)
        struct socket *so;
        int cmd;
        caddr_t data;
        struct socket *so;
        int cmd;
        caddr_t data;
+       struct proc *p;
 {
        register struct ifnet *ifp;
        register struct ifreq *ifr;
 {
        register struct ifnet *ifp;
        register struct ifreq *ifr;
@@ -423,17 +471,6 @@ ifioctl(so, cmd, data)
        case SIOCGIFCONF:
        case OSIOCGIFCONF:
                return (ifconf(cmd, data));
        case SIOCGIFCONF:
        case OSIOCGIFCONF:
                return (ifconf(cmd, data));
-
-#if defined(INET) && NETHER > 0
-       case SIOCSARP:
-       case SIOCDARP:
-               if (error = suser(u.u_cred, &u.u_acflag))
-                       return (error);
-               /* FALL THROUGH */
-       case SIOCGARP:
-       case OSIOCGARP:
-               return (arpioctl(cmd, data));
-#endif
        }
        ifr = (struct ifreq *)data;
        ifp = ifunit(ifr->ifr_name);
        }
        ifr = (struct ifreq *)data;
        ifp = ifunit(ifr->ifr_name);
@@ -450,13 +487,18 @@ ifioctl(so, cmd, data)
                break;
 
        case SIOCSIFFLAGS:
                break;
 
        case SIOCSIFFLAGS:
-               if (error = suser(u.u_cred, &u.u_acflag))
+               if (error = suser(p->p_ucred, &p->p_acflag))
                        return (error);
                if (ifp->if_flags & IFF_UP && (ifr->ifr_flags & IFF_UP) == 0) {
                        int s = splimp();
                        if_down(ifp);
                        splx(s);
                }
                        return (error);
                if (ifp->if_flags & IFF_UP && (ifr->ifr_flags & IFF_UP) == 0) {
                        int s = splimp();
                        if_down(ifp);
                        splx(s);
                }
+               if (ifr->ifr_flags & IFF_UP && (ifp->if_flags & IFF_UP) == 0) {
+                       int s = splimp();
+                       if_up(ifp);
+                       splx(s);
+               }
                ifp->if_flags = (ifp->if_flags & IFF_CANTCHANGE) |
                        (ifr->ifr_flags &~ IFF_CANTCHANGE);
                if (ifp->if_ioctl)
                ifp->if_flags = (ifp->if_flags & IFF_CANTCHANGE) |
                        (ifr->ifr_flags &~ IFF_CANTCHANGE);
                if (ifp->if_ioctl)
@@ -464,11 +506,19 @@ ifioctl(so, cmd, data)
                break;
 
        case SIOCSIFMETRIC:
                break;
 
        case SIOCSIFMETRIC:
-               if (error = suser(u.u_cred, &u.u_acflag))
+               if (error = suser(p->p_ucred, &p->p_acflag))
                        return (error);
                ifp->if_metric = ifr->ifr_metric;
                break;
 
                        return (error);
                ifp->if_metric = ifr->ifr_metric;
                break;
 
+       case SIOCADDMULTI:
+       case SIOCDELMULTI:
+               if (error = suser(p->p_ucred, &p->p_acflag))
+                       return (error);
+               if (ifp->if_ioctl == NULL)
+                       return (EOPNOTSUPP);
+               return ((*ifp->if_ioctl)(ifp, cmd, data));
+
        default:
                if (so->so_proto == 0)
                        return (EOPNOTSUPP);
        default:
                if (so->so_proto == 0)
                        return (EOPNOTSUPP);
@@ -537,6 +587,7 @@ ifioctl(so, cmd, data)
  * other information.
  */
 /*ARGSUSED*/
  * other information.
  */
 /*ARGSUSED*/
+int
 ifconf(cmd, data)
        int cmd;
        caddr_t data;
 ifconf(cmd, data)
        int cmd;
        caddr_t data;
@@ -551,13 +602,14 @@ ifconf(cmd, data)
        ifrp = ifc->ifc_req;
        ep = ifr.ifr_name + sizeof (ifr.ifr_name) - 2;
        for (; space > sizeof (ifr) && ifp; ifp = ifp->if_next) {
        ifrp = ifc->ifc_req;
        ep = ifr.ifr_name + sizeof (ifr.ifr_name) - 2;
        for (; space > sizeof (ifr) && ifp; ifp = ifp->if_next) {
-               bcopy(ifp->if_name, ifr.ifr_name, sizeof (ifr.ifr_name) - 2);
+               strncpy(ifr.ifr_name, ifp->if_name, sizeof (ifr.ifr_name) - 2);
                for (cp = ifr.ifr_name; cp < ep && *cp; cp++)
                for (cp = ifr.ifr_name; cp < ep && *cp; cp++)
-                       ;
+                       continue;
                *cp++ = '0' + ifp->if_unit; *cp = '\0';
                if ((ifa = ifp->if_addrlist) == 0) {
                        bzero((caddr_t)&ifr.ifr_addr, sizeof(ifr.ifr_addr));
                *cp++ = '0' + ifp->if_unit; *cp = '\0';
                if ((ifa = ifp->if_addrlist) == 0) {
                        bzero((caddr_t)&ifr.ifr_addr, sizeof(ifr.ifr_addr));
-                       error = copyout((caddr_t)&ifr, (caddr_t)ifrp, sizeof (ifr));
+                       error = copyout((caddr_t)&ifr, (caddr_t)ifrp,
+                           sizeof (ifr));
                        if (error)
                                break;
                        space -= sizeof (ifr), ifrp++;
                        if (error)
                                break;
                        space -= sizeof (ifr), ifrp++;
@@ -601,21 +653,19 @@ ifconf(cmd, data)
        return (error);
 }
 
        return (error);
 }
 
-static sprint_d(cp, n)
-register char *cp;
-u_short n;
+static char *
+sprint_d(n, buf, buflen)
+       u_int n;
+       char *buf;
+       int buflen;
 {
 {
-       register int q, m;
+       register char *cp = buf + buflen - 1;
+
+       *cp = 0;
        do {
        do {
-           if (n >= 10000) m = 10000;
-               else if (n >= 1000) m = 1000;
-               else if (n >= 100) m = 100;
-               else if (n >= 10) m = 10;
-               else m = 1;
-           q = n / m;
-           n -= m * q;
-           if (q > 9) q = 10; /* For crays with more than 100K interfaces */
-           *cp++ = "0123456789Z"[q];
-       } while (n > 0);
-       *cp++ = 0;
+               cp--;
+               *cp = "0123456789"[n % 10];
+               n /= 10;
+       } while (n != 0);
+       return (cp);
 }
 }