Annotation of researchv9/ipc/src/internet/dkipconfig.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: #include <errno.h>
                      3: #include <signal.h>
                      4: #include <sys/param.h>
                      5: #include <sys/types.h>
                      6: #include <sgtty.h>
                      7: #include <sys/inet/in.h>
                      8: 
                      9: #define RESETTIME 15*60
                     10: 
                     11: static char *cmdname;
                     12: static in_addr myaddr;
                     13: 
                     14: catch_hup()
                     15: {
                     16:        signal(SIGHUP, catch_hup);
                     17: }
                     18: 
                     19: main(argc, argv)
                     20: char *argv[];
                     21: {
                     22:        int other_end, my_pid;
                     23: 
                     24:        cmdname = argv[0];
                     25:        switch(argc){
                     26:        case 3:
                     27:                ipconfig(0, argv[1], argv[2]);
                     28:                pause();
                     29:                break;
                     30:        case 4:
                     31:                my_pid = getpid();
                     32:                setpgrp(my_pid, my_pid);
                     33:                signal(SIGHUP, catch_hup);
                     34:                while(1) {
                     35:                        other_end = callup(argv[1], argv[3], argv[2]);
                     36:                        if (other_end < 0) {
                     37:                                fprintf(stderr, "%s: call failed\n", cmdname);
                     38:                                sleep(60);
                     39:                                continue;
                     40:                        }
                     41:                        if (ioctl(other_end, TIOCSPGRP, 0) < 0) {
                     42:                                fprintf(stderr, "%s: couldn't set pgrp\n", cmdname);
                     43:                                close(other_end);
                     44:                                sleep(60);
                     45:                                continue;
                     46:                        }
                     47:                        ipconfig(other_end, argv[2], argv[3]);
                     48:                        pause();
                     49:                        close(other_end);
                     50:                }
                     51:                break;
                     52:        default:
                     53:                fprintf(stderr, "Usage: %s dk-address my-ip-addr his-ip-addr\n",
                     54:                        cmdname);
                     55:                exit(1);
                     56:        }
                     57: }
                     58: 
                     59: static int
                     60: ipconfig(ipfd, me, it)
                     61:        int ipfd;
                     62:        char *me, *it;
                     63: {
                     64:        in_addr hisaddr, inaddr;
                     65:        int x;
                     66: 
                     67:        myaddr = in_address(me);
                     68:        if(myaddr == 0){
                     69:                fprintf(stderr, "ipconfig: unknown host %s\n", me);
                     70:                exit(1);
                     71:        }
                     72:        hisaddr = in_address(it);
                     73:        if(hisaddr == 0){
                     74:                fprintf(stderr, "ipconfig: unknown host/net %s\n", it);
                     75:                exit(1);
                     76:        }
                     77:        x = 10;         /* IP line disc # */
                     78:        if(ioctl(ipfd, FIOPUSHLD, &x) < 0){
                     79:                perror("PUSHLD");
                     80:                exit(1);
                     81:        }
                     82:        if(ioctl(ipfd, IPIOLOCAL, &myaddr) < 0){
                     83:                perror("IPIOLOCAL");
                     84:                exit(1);
                     85:        }
                     86:        if(hisaddr & 0xff){
                     87:                ioctl(ipfd, IPIOHOST, &hisaddr);
                     88:        } else {
                     89:                ioctl(ipfd, IPIONET, &hisaddr);
                     90:        }
                     91: }
                     92: 
                     93: static int
                     94: callup(host, a1, a2)
                     95:        char *host, *a1, *a2;
                     96: {
                     97:        char cmd[512];
                     98:        int fd;
                     99: 
                    100:        strcpy(cmd, "/usr/inet/etc/dkipconfig ");
                    101:        strcat(cmd, a1);
                    102:        strcat(cmd, " ");
                    103:        strcat(cmd, a2);
                    104:        fd=tdkexec(host, cmd);
                    105:        if(fd>=0)
                    106:                return fd;
                    107:        strcpy(cmd, "/usr/ipc/mgrs/dkipconfig ");
                    108:        strcat(cmd, " ");
                    109:        strcat(cmd, a1);
                    110:        strcat(cmd, " ");
                    111:        strcat(cmd, a2);
                    112:        return(tdkexec(host, cmd));
                    113: }
                    114: 
                    115: static int
                    116: still_there(ipfd)
                    117:        int ipfd;
                    118: {
                    119:        return ioctl(ipfd, IPIOLOCAL, &myaddr) >= 0;
                    120: }

unix.superglobalmegacorp.com

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