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

unix.superglobalmegacorp.com

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