Annotation of researchv10dc/ipc/internet/route.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include <sys/param.h>
        !             3: #include <sys/stream.h>
        !             4: #include <sys/inio.h>
        !             5: 
        !             6: struct route{
        !             7:        int dst;
        !             8:        int gate;
        !             9: };
        !            10: 
        !            11: main(argc, argv)
        !            12: char *argv[];
        !            13: {
        !            14:        struct route r;
        !            15:        int fd, usage = 1;
        !            16: 
        !            17:        r.gate = 1;
        !            18:        if(argc > 1){
        !            19:                if(strcmp(argv[1], "delete") == 0) {
        !            20:                        r.gate = 0;
        !            21:                        usage = argc != 3;
        !            22:                } else if(strcmp(argv[1], "add") == 0)
        !            23:                        usage = argc != 4;
        !            24:        }
        !            25:        if(usage){
        !            26:                fprintf(stderr, "Usage: %s add dest gateway\n", argv[0]);
        !            27:                fprintf(stderr, "       %s delete dest\n", argv[0]);
        !            28:                exit(1);
        !            29:        }
        !            30:        if(strcmp(argv[2], "*") == 0) {
        !            31:                /* the default gateway */
        !            32:                r.dst = 0;
        !            33:        } else {
        !            34:                r.dst = in_address(argv[2]);
        !            35:                if(r.dst == 0 && argv[2][0] != '0'){
        !            36:                        fprintf(stderr, "%s: unknown host/net\n", argv[2]);
        !            37:                        exit(1);
        !            38:                }
        !            39:        }
        !            40:        if(r.gate != 0) {
        !            41:                r.gate = in_address(argv[3]);
        !            42:                if(r.gate == 0){
        !            43:                        fprintf(stderr, "%s: unknown host/net\n", argv[3]);
        !            44:                        exit(1);
        !            45:                }
        !            46:        }
        !            47:        fd = open("/dev/ip0", 2);
        !            48:        if(fd < 0){
        !            49:                perror("/dev/ip0");
        !            50:                exit(1);
        !            51:        }
        !            52:        if(ioctl(fd, IPIOROUTE, &r) < 0)
        !            53:                perror("IPIOROUTE");
        !            54: }

unix.superglobalmegacorp.com

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