FreeCalypso > hg > themwi-system-sw
view smpp-trx-sa/main.c @ 242:f86ec96cea6f
top Makefile: utils use libnumdb2 now
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 14 Aug 2023 15:44:33 -0800 |
parents | 9d6e8d99d2b1 |
children | a375639e4190 |
line wrap: on
line source
/* * This C file is the main module for smpp-trx-sa - a standalone bind_trx * client (ESME role) that writes all incoming messages into a log file * and also allows outgoing messages to be sent via a UNIX domain local * socket (datagram). */ #include <sys/types.h> #include <sys/socket.h> #include <sys/errno.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include <time.h> #include <unistd.h> extern int tcpsock, localsock; FILE *logF; time_t curtime; int init_done; main(argc, argv) char **argv; { struct sockaddr_in server_sin; fd_set fds; int max_fd, rc; if (argc != 6) { fprintf(stderr, "usage: %s server-ip system-id password log-file socket-pathname\n", argv[0]); exit(1); } server_sin.sin_family = AF_INET; server_sin.sin_addr.s_addr = inet_addr(argv[1]); if (server_sin.sin_addr.s_addr == INADDR_NONE) { fprintf(stderr, "error: invalid IP address argument \"%s\"\n", argv[1]); exit(1); } server_sin.sin_port = htons(2775); if (strlen(argv[2]) > 15) { fprintf(stderr, "error: system-id string is too long\n"); exit(1); } if (strlen(argv[3]) > 8) { fprintf(stderr, "error: password string is too long\n"); exit(1); } logF = fopen(argv[4], "a"); if (!logF) { perror(argv[4]); exit(1); } create_local_socket(argv[5]); max_fd = localsock; open_tcp_conn(&server_sin); if (tcpsock > max_fd) max_fd = tcpsock; time(&curtime); send_bind_req(argv[2], argv[3]); init_done = 1; /* main select loop */ for (;;) { FD_ZERO(&fds); FD_SET(tcpsock, &fds); FD_SET(localsock, &fds); rc = select(max_fd+1, &fds, 0, 0, 0); if (rc < 0) { if (errno == EINTR) continue; perror("select"); log_fatal_error("select syscall error"); exit(1); } time(&curtime); if (FD_ISSET(tcpsock, &fds)) tcpsock_select_handler(); if (FD_ISSET(localsock, &fds)) localsock_select_handler(); fflush(logF); } }