comparison smpp-trx-sa/main.c @ 222:9d6e8d99d2b1

smpp-trx-sa: new program
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 03 Aug 2023 21:13:41 -0800
parents
children a375639e4190
comparison
equal deleted inserted replaced
221:e1d7db9d734c 222:9d6e8d99d2b1
1 /*
2 * This C file is the main module for smpp-trx-sa - a standalone bind_trx
3 * client (ESME role) that writes all incoming messages into a log file
4 * and also allows outgoing messages to be sent via a UNIX domain local
5 * socket (datagram).
6 */
7
8 #include <sys/types.h>
9 #include <sys/socket.h>
10 #include <sys/errno.h>
11 #include <netinet/in.h>
12 #include <arpa/inet.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <strings.h>
17 #include <time.h>
18 #include <unistd.h>
19
20 extern int tcpsock, localsock;
21
22 FILE *logF;
23 time_t curtime;
24 int init_done;
25
26 main(argc, argv)
27 char **argv;
28 {
29 struct sockaddr_in server_sin;
30 fd_set fds;
31 int max_fd, rc;
32
33 if (argc != 6) {
34 fprintf(stderr,
35 "usage: %s server-ip system-id password log-file socket-pathname\n",
36 argv[0]);
37 exit(1);
38 }
39 server_sin.sin_family = AF_INET;
40 server_sin.sin_addr.s_addr = inet_addr(argv[1]);
41 if (server_sin.sin_addr.s_addr == INADDR_NONE) {
42 fprintf(stderr, "error: invalid IP address argument \"%s\"\n",
43 argv[1]);
44 exit(1);
45 }
46 server_sin.sin_port = htons(2775);
47 if (strlen(argv[2]) > 15) {
48 fprintf(stderr, "error: system-id string is too long\n");
49 exit(1);
50 }
51 if (strlen(argv[3]) > 8) {
52 fprintf(stderr, "error: password string is too long\n");
53 exit(1);
54 }
55 logF = fopen(argv[4], "a");
56 if (!logF) {
57 perror(argv[4]);
58 exit(1);
59 }
60 create_local_socket(argv[5]);
61 max_fd = localsock;
62 open_tcp_conn(&server_sin);
63 if (tcpsock > max_fd)
64 max_fd = tcpsock;
65 time(&curtime);
66 send_bind_req(argv[2], argv[3]);
67 init_done = 1;
68 /* main select loop */
69 for (;;) {
70 FD_ZERO(&fds);
71 FD_SET(tcpsock, &fds);
72 FD_SET(localsock, &fds);
73 rc = select(max_fd+1, &fds, 0, 0, 0);
74 if (rc < 0) {
75 if (errno == EINTR)
76 continue;
77 perror("select");
78 log_fatal_error("select syscall error");
79 exit(1);
80 }
81 time(&curtime);
82 if (FD_ISSET(tcpsock, &fds))
83 tcpsock_select_handler();
84 if (FD_ISSET(localsock, &fds))
85 localsock_select_handler();
86 fflush(logF);
87 }
88 }