Artifact [6c5f3267b5]
Not logged in

Artifact 6c5f3267b58721a62267a741ddc028486e9ceea2:


     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
   100
   101
   102
   103
   104
   105
   106
   107
   108
   109
   110
   111
   112
   113
#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sgtty.h>
#include <sys/inet/in.h>
#include "config.h"

#define RESETTIME 15*60

static char *cmdname;
static in_addr myaddr;

catch_hup()
{
	signal(SIGHUP, catch_hup);
}

main(argc, argv)
char *argv[];
{
	int other_end, my_pid;

	cmdname = argv[0];
	switch(argc){
	case 3:
		ipconfig(0, argv[1], argv[2]);
		pause();
		break;
	case 4:
		my_pid = getpid();
		setpgrp(my_pid, my_pid);
		signal(SIGHUP, catch_hup);
		while(1) {
			other_end = callup(argv[1], argv[3], argv[2]);
			if (other_end < 0) {
				fprintf(stderr, "%s: call failed\n", cmdname);
				sleep(60);
				continue;
			}
			if (ioctl(other_end, TIOCSPGRP, 0) < 0) {
				fprintf(stderr, "%s: couldn't set pgrp\n", cmdname);
				close(other_end);
				sleep(60);
				continue;
			}
			ipconfig(other_end, argv[2], argv[3]);
			pause();
			close(other_end);
		}
		break;
	default:
		fprintf(stderr, "Usage: %s dk-address my-ip-addr his-ip-addr\n",
			cmdname);
		exit(1);
	}
}

static int
ipconfig(ipfd, me, it)
	int ipfd;
	char *me, *it;
{
	in_addr hisaddr, inaddr;
	int x;

	myaddr = in_address(me);
	if(myaddr == 0){
		fprintf(stderr, "ipconfig: unknown host %s\n", me);
		exit(1);
	}
	hisaddr = in_address(it);
	if(hisaddr == 0){
		fprintf(stderr, "ipconfig: unknown host/net %s\n", it);
		exit(1);
	}
	x = 10;		/* IP line disc # */
	if(ioctl(ipfd, FIOPUSHLD, &x) < 0){
		perror("PUSHLD");
		exit(1);
	}
	if(ioctl(ipfd, IPIOLOCAL, &myaddr) < 0){
		perror("IPIOLOCAL");
		exit(1);
	}
	if(hisaddr & 0xff){
		ioctl(ipfd, IPIOHOST, &hisaddr);
	} else {
		ioctl(ipfd, IPIONET, &hisaddr);
	}
}

static int
callup(host, a1, a2)
	char *host, *a1, *a2;
{
	char cmd[512];

	strcpy(cmd, DKIPCONFIG);
	strcat(cmd, " ");
	strcat(cmd, a1);
	strcat(cmd, " ");
	strcat(cmd, a2);
	return(tdkexec(host, cmd));
}

static int
still_there(ipfd)
	int ipfd;
{
	return ioctl(ipfd, IPIOLOCAL, &myaddr) >= 0;
}