summaryrefslogtreecommitdiffstats
path: root/gnu/usr.sbin/isdn/load/load.c
blob: fa9e6001e378d3cd49511fd37bc6e6da671b56de (plain)
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
114
115
116
117
static char     rcsid[] = "@(#)$Id: load.c,v 1.1 1995/01/25 14:06:18 jkr Exp jkr $";
/*******************************************************************************
 *  II - Version 0.1 $Revision: 1.1 $   $State: Exp $
 *
 * Copyright 1994 Dietmar Friede
 *******************************************************************************
 * Bug reports, patches, comments, suggestions should be sent to:
 *
 *	jkr@saarlink.de or jkrause@guug.de
 *
 *******************************************************************************
 * $Log: load.c,v $
 *
 ******************************************************************************/

#include <sys/types.h>
#undef BSD
#include <sys/param.h>
#include <machine/endian.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <time.h>
#include "../../../../sys/gnu/i386/isa/niccyreg.h"

struct head     head;
char            buf[64 * 1024];

void
main(int argc, char **argv)
{
	FILE           *f;
	int             n;
	argv++;

	if ((n = open("/dev/nic0", O_RDWR)) < 0)
	{
		perror("open");
		exit(1);
	}
	if (!*argv)
	{
		process(stdin, n);
	} else
		while (*argv)
		{
			if ((f = fopen(*argv, "r")) == NULL)
			{
				perror(*argv);
				exit(1);
			} else
			{
				process(f, n);
				fclose(f);
			}
			argv++;
		}
	exit(0);
}

stime(int f)
{
	struct tm      *t;
	time_t          tt;
	char            buf[16];

	tt = time(NULL);
	t = localtime(&tt);
	sprintf(buf, "%.2d%.2d%.2d%.2d%.2d19%.2d", t->tm_hour,
		t->tm_min, t->tm_sec, t->tm_mday, t->tm_mon + 1, t->tm_year);

	if (ioctl(f, NICCY_SET_CLOCK, buf) < 0)
	{
		perror("ioctl");
	}
}


process(FILE * f, int n)
{
	long            size;
	int             len;
	int             no = 0;

	while ((len = fread(buf, 1, 0x16, f)) == 0x16)
	{
		bcopy(buf, (char *) &head, 0x16);
		head.data = buf;
		size = ntohl(head.len);
		if ((len = fread(&buf[0x16], 1, size - 0x16, f)) != (size - 0x16))
		{
			fprintf(stderr, "Cannot read modul %.8s of length %d\n",
				head.nam, size);
			exit(1);
		}
		printf("%d\t %x %.8s %.5s %x\n",
		       size, head.sig, head.nam, head.ver, head.typ);

		head.d_len = size;
		head.status = no++;

		if (ioctl(n, NICCY_LOAD, &head) < 0)
		{
			perror("load");
			exit(1);
		}
		if (head.status)
		{
			fprintf(stderr, "Error loading %d\n", head.status);
			exit(1);
		}
	}
	printf("done\n");

	stime(n);
}
OpenPOWER on IntegriCloud