BSD 4_4 release
[unix-history] / usr / src / sbin / ifconfig / ifconfig.c
index 8478b62..36560b9 100644 (file)
@@ -1,53 +1,92 @@
 /*
 /*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * Copyright (c) 1983, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * 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.
+ *
+ * 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.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1983 Regents of the University of California.\n\
- All rights reserved.\n";
-#endif not lint
+static char copyright[] =
+"@(#) Copyright (c) 1983, 1993\n\
      The Regents of the University of California.  All rights reserved.\n";
+#endif /* not lint */
 
 #ifndef lint
 
 #ifndef lint
-static char sccsid[] = "@(#)ifconfig.c 4.16 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)ifconfig.c 8.1 (Berkeley) 6/5/93";
+#endif /* not lint */
 
 
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 
 #include <net/if.h>
 #include <netinet/in.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 
 #include <net/if.h>
 #include <netinet/in.h>
+#include <arpa/inet.h>
 
 #define        NSIP
 #include <netns/ns.h>
 #include <netns/ns_if.h>
 
 #define        NSIP
 #include <netns/ns.h>
 #include <netns/ns_if.h>
+#include <netdb.h>
+
+#define EON
+#include <netiso/iso.h>
+#include <netiso/iso_var.h>
+#include <sys/protosw.h>
 
 
+#include <unistd.h>
 #include <stdio.h>
 #include <errno.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <errno.h>
 #include <ctype.h>
-#include <netdb.h>
+#include <stdlib.h>
+#include <string.h>
+
+struct ifreq           ifr, ridreq;
+struct ifaliasreq      addreq;
+struct iso_ifreq       iso_ridreq;
+struct iso_aliasreq    iso_addreq;
+struct sockaddr_in     netmask;
 
 
-extern int errno;
-struct ifreq ifr;
-struct sockaddr_in sin = { AF_INET };
-struct sockaddr_in broadaddr;
-struct sockaddr_in netmask = { AF_INET };
-struct sockaddr_in ipdst = { AF_INET };
 char   name[30];
 int    flags;
 int    metric;
 char   name[30];
 int    flags;
 int    metric;
+int    nsellength = 1;
 int    setaddr;
 int    setaddr;
-int    setmask;
-int    setbroadaddr;
 int    setipdst;
 int    setipdst;
+int    doalias;
+int    clearaddr;
+int    newaddr = 1;
 int    s;
 extern int errno;
 
 int    setifflags(), setifaddr(), setifdstaddr(), setifnetmask();
 int    setifmetric(), setifbroadaddr(), setifipdst();
 int    s;
 extern int errno;
 
 int    setifflags(), setifaddr(), setifdstaddr(), setifnetmask();
 int    setifmetric(), setifbroadaddr(), setifipdst();
+int    notealias(), setsnpaoffset(), setnsellength(), notrailers();
 
 #define        NEXTARG         0xffffff
 
 
 #define        NEXTARG         0xffffff
 
@@ -58,12 +97,15 @@ struct      cmd {
 } cmds[] = {
        { "up",         IFF_UP,         setifflags } ,
        { "down",       -IFF_UP,        setifflags },
 } cmds[] = {
        { "up",         IFF_UP,         setifflags } ,
        { "down",       -IFF_UP,        setifflags },
-       { "trailers",   -IFF_NOTRAILERS,setifflags },
-       { "-trailers",  IFF_NOTRAILERS, setifflags },
+       { "trailers",   -1,             notrailers },
+       { "-trailers",  1,              notrailers },
        { "arp",        -IFF_NOARP,     setifflags },
        { "-arp",       IFF_NOARP,      setifflags },
        { "debug",      IFF_DEBUG,      setifflags },
        { "-debug",     -IFF_DEBUG,     setifflags },
        { "arp",        -IFF_NOARP,     setifflags },
        { "-arp",       IFF_NOARP,      setifflags },
        { "debug",      IFF_DEBUG,      setifflags },
        { "-debug",     -IFF_DEBUG,     setifflags },
+       { "alias",      IFF_UP,         notealias },
+       { "-alias",     -IFF_UP,        notealias },
+       { "delete",     -IFF_UP,        notealias },
 #ifdef notdef
 #define        EN_SWABIPS      0x1000
        { "swabips",    EN_SWABIPS,     setifflags },
 #ifdef notdef
 #define        EN_SWABIPS      0x1000
        { "swabips",    EN_SWABIPS,     setifflags },
@@ -73,6 +115,14 @@ struct      cmd {
        { "metric",     NEXTARG,        setifmetric },
        { "broadcast",  NEXTARG,        setifbroadaddr },
        { "ipdst",      NEXTARG,        setifipdst },
        { "metric",     NEXTARG,        setifmetric },
        { "broadcast",  NEXTARG,        setifbroadaddr },
        { "ipdst",      NEXTARG,        setifipdst },
+       { "snpaoffset", NEXTARG,        setsnpaoffset },
+       { "nsellength", NEXTARG,        setnsellength },
+       { "link0",      IFF_LINK0,      setifflags } ,
+       { "-link0",     -IFF_LINK0,     setifflags } ,
+       { "link1",      IFF_LINK1,      setifflags } ,
+       { "-link1",     -IFF_LINK1,     setifflags } ,
+       { "link2",      IFF_LINK2,      setifflags } ,
+       { "-link2",     -IFF_LINK2,     setifflags } ,
        { 0,            0,              setifaddr },
        { 0,            0,              setifdstaddr },
 };
        { 0,            0,              setifaddr },
        { 0,            0,              setifdstaddr },
 };
@@ -82,9 +132,9 @@ struct       cmd {
  * code written at the University of Maryland
  * principally by James O'Toole and Chris Torek.
  */
  * code written at the University of Maryland
  * principally by James O'Toole and Chris Torek.
  */
-
 int    in_status(), in_getaddr();
 int    xns_status(), xns_getaddr();
 int    in_status(), in_getaddr();
 int    xns_status(), xns_getaddr();
+int    iso_status(), iso_getaddr();
 
 /* Known address families */
 struct afswtch {
 
 /* Known address families */
 struct afswtch {
@@ -92,10 +142,19 @@ struct afswtch {
        short af_af;
        int (*af_status)();
        int (*af_getaddr)();
        short af_af;
        int (*af_status)();
        int (*af_getaddr)();
+       int af_difaddr;
+       int af_aifaddr;
+       caddr_t af_ridreq;
+       caddr_t af_addreq;
 } afs[] = {
 } afs[] = {
-       { "inet",       AF_INET,        in_status,      in_getaddr },
-       { "ns",         AF_NS,          xns_status,     xns_getaddr },
-       { 0,            0,              0,              0 }
+#define C(x) ((caddr_t) &x)
+       { "inet", AF_INET, in_status, in_getaddr,
+            SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(addreq) },
+       { "ns", AF_NS, xns_status, xns_getaddr,
+            SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(addreq) },
+       { "iso", AF_ISO, iso_status, iso_getaddr,
+            SIOCDIFADDR_ISO, SIOCAIFADDR_ISO, C(iso_ridreq), C(iso_addreq) },
+       { 0,    0,          0,          0 }
 };
 
 struct afswtch *afp;   /*the address family being set or asked about*/
 };
 
 struct afswtch *afp;   /*the address family being set or asked about*/
@@ -105,13 +164,15 @@ main(argc, argv)
        char *argv[];
 {
        int af = AF_INET;
        char *argv[];
 {
        int af = AF_INET;
+       register struct afswtch *rafp;
+
        if (argc < 2) {
        if (argc < 2) {
-               fprintf(stderr, "usage: ifconfig interface\n%s%s%s%s",
+               fprintf(stderr, "usage: ifconfig interface\n%s%s%s%s%s",
                    "\t[ af [ address [ dest_addr ] ] [ up ] [ down ]",
                            "[ netmask mask ] ]\n",
                    "\t[ metric n ]\n",
                    "\t[ af [ address [ dest_addr ] ] [ up ] [ down ]",
                            "[ netmask mask ] ]\n",
                    "\t[ metric n ]\n",
-                   "\t[ trailers | -trailers ]\n",
-                   "\t[ arp | -arp ]\n");
+                   "\t[ arp | -arp ]\n",
+                   "\t[ link0 | -link0 ] [ link1 | -link1 ] [ link2 | -link2 ] \n");
                exit(1);
        }
        argc--, argv++;
                exit(1);
        }
        argc--, argv++;
@@ -119,14 +180,13 @@ main(argc, argv)
        strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
        argc--, argv++;
        if (argc > 0) {
        strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
        argc--, argv++;
        if (argc > 0) {
-               struct afswtch *myafp;
-               
-               for (myafp = afp = afs; myafp->af_name; myafp++)
-                       if (strcmp(myafp->af_name, *argv) == 0) {
-                               afp = myafp; argc--; argv++;
+               for (afp = rafp = afs; rafp->af_name; rafp++)
+                       if (strcmp(rafp->af_name, *argv) == 0) {
+                               afp = rafp; argc--; argv++;
                                break;
                        }
                                break;
                        }
-               af = ifr.ifr_addr.sa_family = afp->af_af;
+               rafp = afp;
+               af = ifr.ifr_addr.sa_family = rafp->af_af;
        }
        s = socket(af, SOCK_DGRAM, 0);
        if (s < 0) {
        }
        s = socket(af, SOCK_DGRAM, 0);
        if (s < 0) {
@@ -143,15 +203,6 @@ main(argc, argv)
                perror("ioctl (SIOCGIFMETRIC)");
        else
                metric = ifr.ifr_metric;
                perror("ioctl (SIOCGIFMETRIC)");
        else
                metric = ifr.ifr_metric;
-       if (af == AF_INET) {
-               if (ioctl(s, SIOCGIFNETMASK, (caddr_t)&ifr) < 0) {
-                       if (errno != EADDRNOTAVAIL)
-                               Perror("ioctl (SIOCGIFNETMASK)");
-               } else
-                       netmask.sin_addr =
-                             ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr;
-               strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
-       }
        if (argc == 0) {
                status();
                exit(0);
        if (argc == 0) {
                status();
                exit(0);
@@ -173,41 +224,39 @@ main(argc, argv)
                }
                argc--, argv++;
        }
                }
                argc--, argv++;
        }
-       if ((setmask || setaddr) && (af == AF_INET)){
-               /*
-                * If setting the address and not the mask,
-                * clear any existing mask and the kernel will then
-                * assign the default.  If setting both,
-                * set the mask first, so the address will be
-                * interpreted correctly.
-                */
-               ifr.ifr_addr = *(struct sockaddr *)&netmask;
-               if (ioctl(s, SIOCSIFNETMASK, (caddr_t)&ifr) < 0)
-                       Perror("ioctl (SIOCSIFNETMASK)");
-       }
+       if (af == AF_ISO)
+               adjust_nsellength();
        if (setipdst && af==AF_NS) {
                struct nsip_req rq;
                int size = sizeof(rq);
 
        if (setipdst && af==AF_NS) {
                struct nsip_req rq;
                int size = sizeof(rq);
 
-               rq.rq_ns = *(struct sockaddr *) &sin;
-               rq.rq_ip = *(struct sockaddr *) &ipdst;
+               rq.rq_ns = addreq.ifra_addr;
+               rq.rq_ip = addreq.ifra_dstaddr;
 
                if (setsockopt(s, 0, SO_NSIP_ROUTE, &rq, size) < 0)
                        Perror("Encapsulation Routing");
 
                if (setsockopt(s, 0, SO_NSIP_ROUTE, &rq, size) < 0)
                        Perror("Encapsulation Routing");
-               setaddr = 0;
        }
        }
-       if (setaddr) {
-               ifr.ifr_addr = *(struct sockaddr *) &sin;
-               if (ioctl(s, SIOCSIFADDR, (caddr_t)&ifr) < 0)
-                       Perror("ioctl (SIOCSIFADDR)");
+       if (clearaddr) {
+               int ret;
+               strncpy(rafp->af_ridreq, name, sizeof ifr.ifr_name);
+               if ((ret = ioctl(s, rafp->af_difaddr, rafp->af_ridreq)) < 0) {
+                       if (errno == EADDRNOTAVAIL && (doalias >= 0)) {
+                               /* means no previous address for interface */
+                       } else
+                               Perror("ioctl (SIOCDIFADDR)");
+               }
        }
        }
-       if (setbroadaddr) {
-               ifr.ifr_addr = *(struct sockaddr *)&broadaddr;
-               if (ioctl(s, SIOCSIFBRDADDR, (caddr_t)&ifr) < 0)
-                       Perror("ioctl (SIOCSIFBRDADDR)");
+       if (newaddr) {
+               strncpy(rafp->af_addreq, name, sizeof ifr.ifr_name);
+               if (ioctl(s, rafp->af_aifaddr, rafp->af_addreq) < 0)
+                       Perror("ioctl (SIOCAIFADDR)");
        }
        exit(0);
 }
        }
        exit(0);
 }
+#define RIDADDR 0
+#define ADDR   1
+#define MASK   2
+#define DSTADDR        3
 
 /*ARGSUSED*/
 setifaddr(addr, param)
 
 /*ARGSUSED*/
 setifaddr(addr, param)
@@ -220,28 +269,54 @@ setifaddr(addr, param)
         * and the flags may change when the address is set.
         */
        setaddr++;
         * and the flags may change when the address is set.
         */
        setaddr++;
-       (*afp->af_getaddr)(addr, &sin);
+       if (doalias == 0)
+               clearaddr = 1;
+       (*afp->af_getaddr)(addr, (doalias >= 0 ? ADDR : RIDADDR));
 }
 
 setifnetmask(addr)
        char *addr;
 {
 }
 
 setifnetmask(addr)
        char *addr;
 {
-       in_getaddr(addr, &netmask);
-       setmask++;
+       (*afp->af_getaddr)(addr, MASK);
 }
 
 setifbroadaddr(addr)
        char *addr;
 {
 }
 
 setifbroadaddr(addr)
        char *addr;
 {
-       (*afp->af_getaddr)(addr, &broadaddr);
-       setbroadaddr++;
+       (*afp->af_getaddr)(addr, DSTADDR);
 }
 
 setifipdst(addr)
        char *addr;
 {
 }
 
 setifipdst(addr)
        char *addr;
 {
-       in_getaddr(addr, &ipdst);
+       in_getaddr(addr, DSTADDR);
        setipdst++;
        setipdst++;
+       clearaddr = 0;
+       newaddr = 0;
+}
+#define rqtosa(x) (&(((struct ifreq *)(afp->x))->ifr_addr))
+/*ARGSUSED*/
+notealias(addr, param)
+       char *addr;
+{
+       if (setaddr && doalias == 0 && param < 0)
+               bcopy((caddr_t)rqtosa(af_addreq),
+                     (caddr_t)rqtosa(af_ridreq),
+                     rqtosa(af_addreq)->sa_len);
+       doalias = param;
+       if (param < 0) {
+               clearaddr = 1;
+               newaddr = 0;
+       } else
+               clearaddr = 0;
+}
+
+/*ARGSUSED*/
+notrailers(vname, value)
+       char *vname;
+       int value;
+{
+       printf("Note: trailers are no longer sent, but always received\n");
 }
 
 /*ARGSUSED*/
 }
 
 /*ARGSUSED*/
@@ -249,10 +324,7 @@ setifdstaddr(addr, param)
        char *addr;
        int param;
 {
        char *addr;
        int param;
 {
-
-       (*afp->af_getaddr)(addr, &ifr.ifr_addr);
-       if (ioctl(s, SIOCSIFDSTADDR, (caddr_t)&ifr) < 0)
-               Perror("ioctl (SIOCSIFDSTADDR)");
+       (*afp->af_getaddr)(addr, DSTADDR);
 }
 
 setifflags(vname, value)
 }
 
 setifflags(vname, value)
@@ -285,9 +357,15 @@ setifmetric(val)
                perror("ioctl (set metric)");
 }
 
                perror("ioctl (set metric)");
 }
 
+setsnpaoffset(val)
+       char *val;
+{
+       iso_addreq.ifra_snpaoffset = atoi(val);
+}
+
 #define        IFFBITS \
 "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6NOTRAILERS\7RUNNING\10NOARP\
 #define        IFFBITS \
 "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6NOTRAILERS\7RUNNING\10NOARP\
-"
+\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2\20MULTICAST"
 
 /*
  * Print the status of the interface.  If an address family was
 
 /*
  * Print the status of the interface.  If an address family was
@@ -304,35 +382,44 @@ status()
                printf(" metric %d", metric);
        putchar('\n');
        if ((p = afp) != NULL) {
                printf(" metric %d", metric);
        putchar('\n');
        if ((p = afp) != NULL) {
-               (*p->af_status)();
-               return;
-       }
-       for (p = afs; p->af_name; p++) {
+               (*p->af_status)(1);
+       } else for (p = afs; p->af_name; p++) {
                ifr.ifr_addr.sa_family = p->af_af;
                ifr.ifr_addr.sa_family = p->af_af;
-               (*p->af_status)();
+               (*p->af_status)(0);
        }
 }
 
        }
 }
 
-in_status()
+in_status(force)
+       int force;
 {
        struct sockaddr_in *sin;
        char *inet_ntoa();
 
 {
        struct sockaddr_in *sin;
        char *inet_ntoa();
 
+       strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
        if (ioctl(s, SIOCGIFADDR, (caddr_t)&ifr) < 0) {
        if (ioctl(s, SIOCGIFADDR, (caddr_t)&ifr) < 0) {
-               if (errno == EADDRNOTAVAIL)
+               if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
+                       if (!force)
+                               return;
                        bzero((char *)&ifr.ifr_addr, sizeof(ifr.ifr_addr));
                        bzero((char *)&ifr.ifr_addr, sizeof(ifr.ifr_addr));
-               else
-                       Perror("ioctl (SIOCGIFADDR)");
+               else
+                       perror("ioctl (SIOCGIFADDR)");
        }
        }
-       strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
        sin = (struct sockaddr_in *)&ifr.ifr_addr;
        printf("\tinet %s ", inet_ntoa(sin->sin_addr));
        sin = (struct sockaddr_in *)&ifr.ifr_addr;
        printf("\tinet %s ", inet_ntoa(sin->sin_addr));
+       strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
+       if (ioctl(s, SIOCGIFNETMASK, (caddr_t)&ifr) < 0) {
+               if (errno != EADDRNOTAVAIL)
+                       perror("ioctl (SIOCGIFNETMASK)");
+               bzero((char *)&ifr.ifr_addr, sizeof(ifr.ifr_addr));
+       } else
+               netmask.sin_addr =
+                   ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr;
        if (flags & IFF_POINTOPOINT) {
                if (ioctl(s, SIOCGIFDSTADDR, (caddr_t)&ifr) < 0) {
                        if (errno == EADDRNOTAVAIL)
                            bzero((char *)&ifr.ifr_addr, sizeof(ifr.ifr_addr));
                        else
        if (flags & IFF_POINTOPOINT) {
                if (ioctl(s, SIOCGIFDSTADDR, (caddr_t)&ifr) < 0) {
                        if (errno == EADDRNOTAVAIL)
                            bzero((char *)&ifr.ifr_addr, sizeof(ifr.ifr_addr));
                        else
-                           Perror("ioctl (SIOCGIFDSTADDR)");
+                           perror("ioctl (SIOCGIFDSTADDR)");
                }
                strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
                sin = (struct sockaddr_in *)&ifr.ifr_dstaddr;
                }
                strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
                sin = (struct sockaddr_in *)&ifr.ifr_dstaddr;
@@ -342,33 +429,39 @@ in_status()
        if (flags & IFF_BROADCAST) {
                if (ioctl(s, SIOCGIFBRDADDR, (caddr_t)&ifr) < 0) {
                        if (errno == EADDRNOTAVAIL)
        if (flags & IFF_BROADCAST) {
                if (ioctl(s, SIOCGIFBRDADDR, (caddr_t)&ifr) < 0) {
                        if (errno == EADDRNOTAVAIL)
-                               return;
-                       Perror("ioctl (SIOCGIFADDR)");
+                           bzero((char *)&ifr.ifr_addr, sizeof(ifr.ifr_addr));
+                       else
+                           perror("ioctl (SIOCGIFADDR)");
                }
                strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
                sin = (struct sockaddr_in *)&ifr.ifr_addr;
                }
                strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
                sin = (struct sockaddr_in *)&ifr.ifr_addr;
-               printf("broadcast %s", inet_ntoa(sin->sin_addr));
+               if (sin->sin_addr.s_addr != 0)
+                       printf("broadcast %s", inet_ntoa(sin->sin_addr));
        }
        putchar('\n');
 }
 
 
        }
        putchar('\n');
 }
 
 
-xns_status()
+xns_status(force)
+       int force;
 {
        struct sockaddr_ns *sns;
 
        close(s);
        s = socket(AF_NS, SOCK_DGRAM, 0);
        if (s < 0) {
 {
        struct sockaddr_ns *sns;
 
        close(s);
        s = socket(AF_NS, SOCK_DGRAM, 0);
        if (s < 0) {
-               if (errno == EAFNOSUPPORT)
+               if (errno == EPROTONOSUPPORT)
                        return;
                perror("ifconfig: socket");
                exit(1);
        }
        if (ioctl(s, SIOCGIFADDR, (caddr_t)&ifr) < 0) {
                        return;
                perror("ifconfig: socket");
                exit(1);
        }
        if (ioctl(s, SIOCGIFADDR, (caddr_t)&ifr) < 0) {
-               if (errno == EADDRNOTAVAIL || errno==EAFNOSUPPORT)
-                       return;
-               Perror("ioctl (SIOCGIFADDR)");
+               if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
+                       if (!force)
+                               return;
+                       bzero((char *)&ifr.ifr_addr, sizeof(ifr.ifr_addr));
+               } else
+                       perror("ioctl (SIOCGIFADDR)");
        }
        strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
        sns = (struct sockaddr_ns *)&ifr.ifr_addr;
        }
        strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
        sns = (struct sockaddr_ns *)&ifr.ifr_addr;
@@ -387,6 +480,55 @@ xns_status()
        putchar('\n');
 }
 
        putchar('\n');
 }
 
+iso_status(force)
+       int force;
+{
+       struct sockaddr_iso *siso;
+       struct iso_ifreq ifr;
+
+       close(s);
+       s = socket(AF_ISO, SOCK_DGRAM, 0);
+       if (s < 0) {
+               if (errno == EPROTONOSUPPORT)
+                       return;
+               perror("ifconfig: socket");
+               exit(1);
+       }
+       bzero((caddr_t)&ifr, sizeof(ifr));
+       strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+       if (ioctl(s, SIOCGIFADDR_ISO, (caddr_t)&ifr) < 0) {
+               if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
+                       if (!force)
+                               return;
+                       bzero((char *)&ifr.ifr_Addr, sizeof(ifr.ifr_Addr));
+               } else {
+                       perror("ioctl (SIOCGIFADDR_ISO)");
+                       exit(1);
+               }
+       }
+       strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
+       siso = &ifr.ifr_Addr;
+       printf("\tiso %s ", iso_ntoa(&siso->siso_addr));
+       if (ioctl(s, SIOCGIFNETMASK_ISO, (caddr_t)&ifr) < 0) {
+               if (errno != EADDRNOTAVAIL)
+                       perror("ioctl (SIOCGIFNETMASK_ISO)");
+       } else {
+               printf(" netmask %s ", iso_ntoa(&siso->siso_addr));
+       }
+       if (flags & IFF_POINTOPOINT) {
+               if (ioctl(s, SIOCGIFDSTADDR_ISO, (caddr_t)&ifr) < 0) {
+                       if (errno == EADDRNOTAVAIL)
+                           bzero((char *)&ifr.ifr_Addr, sizeof(ifr.ifr_Addr));
+                       else
+                           Perror("ioctl (SIOCGIFDSTADDR_ISO)");
+               }
+               strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
+               siso = &ifr.ifr_Addr;
+               printf("--> %s ", iso_ntoa(&siso->siso_addr));
+       }
+       putchar('\n');
+}
+
 Perror(cmd)
        char *cmd;
 {
 Perror(cmd)
        char *cmd;
 {
@@ -411,35 +553,33 @@ Perror(cmd)
 
 struct in_addr inet_makeaddr();
 
 
 struct in_addr inet_makeaddr();
 
-in_getaddr(s, saddr)
+#define SIN(x) ((struct sockaddr_in *) &(x))
+struct sockaddr_in *sintab[] = {
+SIN(ridreq.ifr_addr), SIN(addreq.ifra_addr),
+SIN(addreq.ifra_mask), SIN(addreq.ifra_broadaddr)};
+
+in_getaddr(s, which)
        char *s;
        char *s;
-       struct sockaddr *saddr;
 {
 {
-       register struct sockaddr_in *sin = (struct sockaddr_in *)saddr;
+       register struct sockaddr_in *sin = sintab[which];
        struct hostent *hp;
        struct netent *np;
        int val;
 
        struct hostent *hp;
        struct netent *np;
        int val;
 
-       sin->sin_family = AF_INET;
-       val = inet_addr(s);
-       if (val != -1) {
+       sin->sin_len = sizeof(*sin);
+       if (which != MASK)
+               sin->sin_family = AF_INET;
+
+       if ((val = inet_addr(s)) != -1)
                sin->sin_addr.s_addr = val;
                sin->sin_addr.s_addr = val;
-               return;
-       }
-       hp = gethostbyname(s);
-       if (hp) {
-               sin->sin_family = hp->h_addrtype;
+       else if (hp = gethostbyname(s))
                bcopy(hp->h_addr, (char *)&sin->sin_addr, hp->h_length);
                bcopy(hp->h_addr, (char *)&sin->sin_addr, hp->h_length);
-               return;
-       }
-       np = getnetbyname(s);
-       if (np) {
-               sin->sin_family = np->n_addrtype;
+       else if (np = getnetbyname(s))
                sin->sin_addr = inet_makeaddr(np->n_net, INADDR_ANY);
                sin->sin_addr = inet_makeaddr(np->n_net, INADDR_ANY);
-               return;
+       else {
+               fprintf(stderr, "%s: bad value\n", s);
+               exit(1);
        }
        }
-       fprintf(stderr, "%s: bad value\n", s);
-       exit(1);
 }
 
 /*
 }
 
 /*
@@ -475,12 +615,70 @@ printb(s, v, bits)
        }
 }
 
        }
 }
 
-xns_getaddr(addr, saddr)
+#define SNS(x) ((struct sockaddr_ns *) &(x))
+struct sockaddr_ns *snstab[] = {
+SNS(ridreq.ifr_addr), SNS(addreq.ifra_addr),
+SNS(addreq.ifra_mask), SNS(addreq.ifra_broadaddr)};
+
+xns_getaddr(addr, which)
 char *addr;
 char *addr;
-struct sockaddr *saddr;
 {
 {
-       struct sockaddr_ns *sns = (struct sockaddr_ns *)saddr;
+       struct sockaddr_ns *sns = snstab[which];
        struct ns_addr ns_addr();
        struct ns_addr ns_addr();
+
        sns->sns_family = AF_NS;
        sns->sns_family = AF_NS;
+       sns->sns_len = sizeof(*sns);
        sns->sns_addr = ns_addr(addr);
        sns->sns_addr = ns_addr(addr);
+       if (which == MASK)
+               printf("Attempt to set XNS netmask will be ineffectual\n");
+}
+
+#define SISO(x) ((struct sockaddr_iso *) &(x))
+struct sockaddr_iso *sisotab[] = {
+SISO(iso_ridreq.ifr_Addr), SISO(iso_addreq.ifra_addr),
+SISO(iso_addreq.ifra_mask), SISO(iso_addreq.ifra_dstaddr)};
+
+iso_getaddr(addr, which)
+char *addr;
+{
+       register struct sockaddr_iso *siso = sisotab[which];
+       struct iso_addr *iso_addr();
+       siso->siso_addr = *iso_addr(addr);
+
+       if (which == MASK) {
+               siso->siso_len = TSEL(siso) - (caddr_t)(siso);
+               siso->siso_nlen = 0;
+       } else {
+               siso->siso_len = sizeof(*siso);
+               siso->siso_family = AF_ISO;
+       }
+}
+
+setnsellength(val)
+       char *val;
+{
+       nsellength = atoi(val);
+       if (nsellength < 0) {
+               fprintf(stderr, "Negative NSEL length is absurd\n");
+               exit (1);
+       }
+       if (afp == 0 || afp->af_af != AF_ISO) {
+               fprintf(stderr, "Setting NSEL length valid only for iso\n");
+               exit (1);
+       }
+}
+
+fixnsel(s)
+register struct sockaddr_iso *s;
+{
+       if (s->siso_family == 0)
+               return;
+       s->siso_tlen = nsellength;
+}
+
+adjust_nsellength()
+{
+       fixnsel(sisotab[RIDADDR]);
+       fixnsel(sisotab[ADDR]);
+       fixnsel(sisotab[DSTADDR]);
 }
 }