FreeCalypso > hg > themwi-system-sw
comparison mtctest/main.c @ 21:cc0e1c6e33c3
themwi-test-mtc utility written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 28 Jun 2022 18:25:28 -0800 |
parents | |
children | e8e82a4bf12b |
comparison
equal
deleted
inserted
replaced
20:b13acb024fc6 | 21:cc0e1c6e33c3 |
---|---|
1 /* | |
2 * Main module for ThemWi test MT call generator. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <sys/errno.h> | |
7 #include <stdio.h> | |
8 #include <stdint.h> | |
9 #include <stdlib.h> | |
10 #include <syslog.h> | |
11 #include <unistd.h> | |
12 | |
13 extern int mtc_socket; | |
14 extern int disconnect_mode; | |
15 | |
16 main(argc, argv) | |
17 char **argv; | |
18 { | |
19 extern int optind; | |
20 extern char *optarg; | |
21 char *from; | |
22 fd_set fds; | |
23 int c; | |
24 | |
25 from = 0; | |
26 while ((c = getopt(argc, argv, "f:")) != EOF) { | |
27 switch (c) { | |
28 case 'f': | |
29 from = optarg; | |
30 continue; | |
31 default: | |
32 usage: | |
33 fprintf(stderr, | |
34 "usage: %s [-f from-number] to-number\n", | |
35 argv[0]); | |
36 exit(1); | |
37 } | |
38 } | |
39 if (argc != optind + 1) | |
40 goto usage; | |
41 openlog("themwi-test-mtc", 0, LOG_LOCAL5); | |
42 init_setup_msg(from, argv[optind]); | |
43 connect_mtc_socket(); | |
44 send_setup_msg(); | |
45 /* main select loop */ | |
46 for (;;) { | |
47 FD_ZERO(&fds); | |
48 FD_SET(mtc_socket, &fds); | |
49 if (!disconnect_mode) | |
50 FD_SET(0, &fds); | |
51 c = select(mtc_socket+1, &fds, 0, 0, 0); | |
52 if (c < 0) { | |
53 if (errno == EINTR) | |
54 continue; | |
55 perror("select"); | |
56 exit(1); | |
57 } | |
58 if (FD_ISSET(mtc_socket, &fds)) | |
59 mtc_socket_select(); | |
60 if (!disconnect_mode && FD_ISSET(0, &fds)) | |
61 send_disconnect_req(); | |
62 } | |
63 } |