Annotation of researchv10no/cmd/ether/netconfig.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *            N E T  C O N F I G
        !             3:  *
        !             4:  * Ethernet network setup procedure.
        !             5:  *
        !             6:  * Usage: netconfig device unit { protocol }
        !             7:  *
        !             8:  *       where     device is the ethernet device type (ec, il, etc.)
        !             9:  *                 unit is the physical unit number of the device
        !            10:  *                 protocol is a protocol name (ip, chaos, arp, etc.),
        !            11:  *                      optionally followed by protocol-specific arguments
        !            12:  *
        !            13:  *
        !            14:  * (c) Copyright 1985  Nirvonics, Inc.
        !            15:  *
        !            16:  * Written by Kurt Gollhardt
        !            17:  * Last update Thu Mar 14 11:40:10 1985
        !            18:  *
        !            19:  * This software is the property of Nirvonics, Inc.
        !            20:  * All rights reserved.
        !            21:  *
        !            22:  */
        !            23: 
        !            24: #include <stdio.h>
        !            25: #include <ctype.h>
        !            26: #include <signal.h>
        !            27: #include <sys/types.h>
        !            28: #include <sys/ioctl.h>
        !            29: #include <sys/ethernet.h>
        !            30: 
        !            31: #define CONFIG_DIR  "/usr/ether"
        !            32: 
        !            33: extern int dump_ld;
        !            34: 
        !            35: #define MAX_ARGS 10
        !            36: 
        !            37: char *argv[MAX_ARGS];
        !            38: 
        !            39: 
        !            40: main(ac,av)
        !            41:      char **av;
        !            42: {
        !            43:      int       fd, unit, min_minor, max_minor, c, usage, dumping;
        !            44:      char      *dev, devfile[40], prog[40], name[40];
        !            45:      extern int            optind;
        !            46:      extern char    *optarg;
        !            47: 
        !            48:      while ((c = getopt(ac, av, "d")) != EOF)
        !            49:          switch (c) {
        !            50:               case 'd':
        !            51:                    dumping++;
        !            52:                    break;
        !            53:               case '?':
        !            54:                    usage++;
        !            55:                    break;
        !            56:          }
        !            57: 
        !            58:      if (ac - optind < 3)
        !            59:          usage++;
        !            60: 
        !            61:      if (usage) {
        !            62:          fprintf(stderr,
        !            63:               "Usage: netconfig [-options] ether_device unit {protocol}\n",
        !            64:               av[0]);
        !            65:          fprintf(stderr,
        !            66:               "Options: -d: insert a dump line-discipline\n");
        !            67:          exit(1);
        !            68:      }
        !            69: 
        !            70:      dev = av[optind++];
        !            71:      if (strncmp(dev, "/dev/", 5) == 0)
        !            72:          dev += 5;
        !            73:      sprintf(devfile, "/dev/%s", dev);
        !            74:      unit = atoi(av[optind++]);
        !            75:      min_minor = unit * CHANS_PER_UNIT;
        !            76:      max_minor = min_minor + CHANS_PER_UNIT - 1;
        !            77: 
        !            78:      signal(SIGHUP, SIG_IGN);
        !            79: 
        !            80:      while (optind < ac) {
        !            81:          if ((fd = findslot(devfile, min_minor, max_minor, 2)) < 0) {
        !            82:               fprintf(stderr,
        !            83:                         "Can't open %s unit %d for address resolution\n",
        !            84:                         devfile, unit);
        !            85:               exit(1);
        !            86:          }
        !            87:          dup2(fd, 0);
        !            88:          close(fd);
        !            89: 
        !            90:          if (dumping && ioctl(0, FIOPUSHLD, &dump_ld) < 0)
        !            91:                    fprintf(stderr, "Can't push dump line discipline\n");
        !            92: 
        !            93:          makeargv(av[optind++]);
        !            94:          sprintf(prog, "%s/%sconfig", CONFIG_DIR, argv[0]);
        !            95:          sprintf(name, "%s %s%d", argv[0], dev, unit);
        !            96:          argv[0] = name;
        !            97: 
        !            98:          switch (fork()) {
        !            99:               case -1:
        !           100:                    fprintf(stderr, "netconfig: fork failed\n");
        !           101:                    exit(1);
        !           102:               case 0:
        !           103:                    break;
        !           104:               default:  /* child */
        !           105:                    execv(prog, argv);
        !           106:                    fprintf(stderr, "%s: exec failed\n", prog);
        !           107:                    _exit(1);
        !           108:          }
        !           109:      }
        !           110: }
        !           111: 
        !           112: 
        !           113: makeargv(s)
        !           114:      char *s;
        !           115: {
        !           116:      register int   argc;
        !           117: 
        !           118:      for (argc = 0; *s && argc < MAX_ARGS-1; ++argc) {
        !           119:          argv[argc] = s;
        !           120:          while (*s && !isspace(*s))
        !           121:               ++s;
        !           122:          if (*s)
        !           123:               *s++ = '\0';
        !           124:          while (*s && isspace(*s))
        !           125:               ++s;
        !           126:      }
        !           127: 
        !           128:      argv[argc] = 0;
        !           129: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.