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
|
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <time.h>
FILE *log_fp;
void beenden() {
fprintf(log_fp, "****** Ende Ausw�hldialog\n");
fclose(log_fp);
exit(0);
}
int main(int argc, char *argv[]) {
int zustand,
flag,
drinbleib,
ch;
time_t akt_zeit;
log_fp = fopen("/var/log/modemsim.log", "a");
if(log_fp == NULL) {
fprintf(stderr, "Fehler beim �ffnen vom Log\n");
perror(argv[0]);
exit(1);
}
if(time(&akt_zeit) == (time_t)-1) {
fprintf(stderr, "Fehler beim Zeit ermitteln\n");
perror(argv[0]);
exit(1);
}
if(argc >= 2 && !strcmp(argv[1], "-t")) {
printf("NO CARRIER\r\n");
signal(SIGALRM, beenden);
alarm(10); /* 10 Sekunden sollten reichen, bis bei Windows
der Modemdialog beendet ist */
fprintf(log_fp, "****** Beginn: Ausw�hl-Modemdialog am %s"
"NO CARRIER\n", ctime(&akt_zeit));
} else {
fprintf(log_fp, "****** Beginn: Einw�hl-Modemialog am %s",
ctime(&akt_zeit));
}
fflush(log_fp);
zustand = 0;
while(zustand != 6) {
ch = getchar();
switch(zustand) {
case 0:
if(ch == 'A' || ch == 'a') {
zustand = 1;
flag = 1;
}
break;
case 1:
if(ch == 'T' || ch == 't')
zustand = 2;
else
zustand = 0;
break;
case 2:
if(ch == 'D' || ch == 'd')
zustand = 4;
else if(ch == '\r' || ch == '\n')
zustand = 5;
else
zustand = 3;
break;
case 3:
if(ch == '\r' || ch == '\n')
zustand = 5;
break;
case 4:
if(ch == '\r' || ch == '\n')
zustand = 6;
}
if(zustand == 5) {
printf("\r\nOK\r\n");
fprintf(log_fp, "\nOK\n");
fflush(log_fp);
zustand = 0;
} else if(zustand == 6) {
printf("\r\n");
sleep(3); /* �nderung 03.02.2000 */
printf("CONNECT 45333/LAPM\r\n");
fprintf(log_fp, "\nCONNECT 45333/LAPM\n");
} else if(zustand > 0) {
putchar(ch);
fputc(ch, log_fp);
fflush(log_fp);
}
}
fprintf(log_fp, "****** Ende Einw�hldialog\n");
fclose(log_fp);
return 0;
}
|