2008-09-12 22:55:10 +00:00
|
|
|
/*
|
2011-03-27 17:13:22 +00:00
|
|
|
* rotctld.c - (C) Stephane Fillod 2000-2011
|
2008-09-12 22:55:10 +00:00
|
|
|
*
|
|
|
|
* This program test/control a rotator using Hamlib.
|
|
|
|
* It takes commands from network connection.
|
|
|
|
*
|
|
|
|
*
|
2011-08-22 01:51:06 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2010-02-14 22:18:00 +00:00
|
|
|
*
|
2011-08-22 01:51:06 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2010-02-14 22:18:00 +00:00
|
|
|
*
|
2011-08-22 01:51:06 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2010-02-14 22:18:00 +00:00
|
|
|
*
|
2008-09-12 22:55:10 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <sys/types.h> /* See NOTES */
|
|
|
|
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ARPA_INET_H
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#elif HAVE_WS2TCPIP_H
|
|
|
|
#include <ws2tcpip.h>
|
2011-03-27 17:13:22 +00:00
|
|
|
#include <fcntl.h>
|
2008-09-12 22:55:10 +00:00
|
|
|
#endif
|
2010-04-16 20:50:14 +00:00
|
|
|
#ifdef HAVE_NETDB_H
|
|
|
|
#include <netdb.h>
|
|
|
|
#endif
|
2008-09-12 22:55:10 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_PTHREAD
|
|
|
|
#include <pthread.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <hamlib/rotator.h>
|
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
#include "rotctl_parse.h"
|
|
|
|
|
|
|
|
struct handle_data {
|
|
|
|
ROT *rot;
|
|
|
|
int sock;
|
|
|
|
struct sockaddr_in cli_addr;
|
|
|
|
socklen_t clilen;
|
|
|
|
};
|
|
|
|
|
|
|
|
void * handle_socket(void * arg);
|
|
|
|
|
|
|
|
void usage();
|
|
|
|
|
|
|
|
/*
|
2010-02-14 22:18:00 +00:00
|
|
|
* Reminder: when adding long options,
|
2008-09-12 22:55:10 +00:00
|
|
|
* keep up to date SHORT_OPTIONS, usage()'s output and man page. thanks.
|
|
|
|
* NB: do NOT use -W since it's reserved by POSIX.
|
|
|
|
* TODO: add an option to read from a file
|
|
|
|
*/
|
2010-02-14 22:18:00 +00:00
|
|
|
#define SHORT_OPTIONS "m:r:s:C:t:T:LuevhVl"
|
2008-09-12 22:55:10 +00:00
|
|
|
static struct option long_options[] =
|
|
|
|
{
|
2010-02-14 22:18:00 +00:00
|
|
|
{"model", 1, 0, 'm'},
|
|
|
|
{"rot-file", 1, 0, 'r'},
|
|
|
|
{"serial-speed",1, 0, 's'},
|
|
|
|
{"port", 1, 0, 't'},
|
|
|
|
{"listen-addr", 1, 0, 'T'},
|
|
|
|
{"list", 0, 0, 'l'},
|
|
|
|
{"set-conf", 1, 0, 'C'},
|
|
|
|
{"show-conf", 0, 0, 'L'},
|
|
|
|
{"dump-caps", 0, 0, 'u'},
|
|
|
|
{"end-marker", 0, 0, 'e'},
|
|
|
|
{"verbose", 0, 0, 'v'},
|
|
|
|
{"help", 0, 0, 'h'},
|
|
|
|
{"version", 0, 0, 'V'},
|
2008-09-12 22:55:10 +00:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
int interactive = 1; /* no cmd because of daemon */
|
|
|
|
int prompt= 0 ; /* Daemon mode for rigparse return string */
|
2008-10-27 22:23:36 +00:00
|
|
|
int opt_end= 0 ; /* END marker for rotctld */
|
2008-09-12 22:55:10 +00:00
|
|
|
|
2010-04-16 20:50:14 +00:00
|
|
|
const char *portno = "4533";
|
|
|
|
const char *src_addr = NULL; /* INADDR_ANY */
|
2008-09-12 22:55:10 +00:00
|
|
|
|
2009-01-04 14:49:17 +00:00
|
|
|
char send_cmd_term = '\r'; /* send_cmd termination char */
|
|
|
|
|
2008-09-12 22:55:10 +00:00
|
|
|
#define MAXCONFLEN 128
|
|
|
|
|
|
|
|
|
|
|
|
int main (int argc, char *argv[])
|
2010-02-14 22:18:00 +00:00
|
|
|
{
|
2008-09-12 22:55:10 +00:00
|
|
|
ROT *my_rot; /* handle to rot (instance) */
|
|
|
|
rot_model_t my_model = ROT_MODEL_DUMMY;
|
|
|
|
|
|
|
|
int retcode; /* generic return code from functions */
|
|
|
|
|
|
|
|
int verbose = 0;
|
|
|
|
int show_conf = 0;
|
2010-02-14 22:18:00 +00:00
|
|
|
int dump_caps_opt = 0;
|
2008-09-12 22:55:10 +00:00
|
|
|
const char *rot_file=NULL;
|
|
|
|
int serial_rate = 0;
|
|
|
|
char conf_parms[MAXCONFLEN] = "";
|
|
|
|
|
2010-04-16 20:50:14 +00:00
|
|
|
struct addrinfo hints, *result;
|
2008-09-12 22:55:10 +00:00
|
|
|
int sock_listen;
|
|
|
|
int reuseaddr = 1;
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
int c;
|
|
|
|
int option_index = 0;
|
|
|
|
|
|
|
|
c = getopt_long (argc, argv, SHORT_OPTIONS,
|
|
|
|
long_options, &option_index);
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch(c) {
|
|
|
|
case 'h':
|
2010-02-14 22:18:00 +00:00
|
|
|
usage();
|
|
|
|
exit(0);
|
2008-09-12 22:55:10 +00:00
|
|
|
case 'V':
|
2010-02-14 22:18:00 +00:00
|
|
|
version();
|
|
|
|
exit(0);
|
2008-09-12 22:55:10 +00:00
|
|
|
case 'm':
|
2010-02-14 22:18:00 +00:00
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
my_model = atoi(optarg);
|
|
|
|
break;
|
2008-09-12 22:55:10 +00:00
|
|
|
case 'r':
|
2010-02-14 22:18:00 +00:00
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
rot_file = optarg;
|
|
|
|
break;
|
2008-09-12 22:55:10 +00:00
|
|
|
case 's':
|
2010-02-14 22:18:00 +00:00
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
serial_rate = atoi(optarg);
|
|
|
|
break;
|
2008-09-12 22:55:10 +00:00
|
|
|
case 'C':
|
2010-02-14 22:18:00 +00:00
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (*conf_parms != '\0')
|
|
|
|
strcat(conf_parms, ",");
|
|
|
|
strncat(conf_parms, optarg, MAXCONFLEN-strlen(conf_parms));
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-04-16 20:50:14 +00:00
|
|
|
portno = optarg;
|
2010-02-14 22:18:00 +00:00
|
|
|
break;
|
2008-09-21 20:32:08 +00:00
|
|
|
case 'T':
|
2010-02-14 22:18:00 +00:00
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-04-16 20:50:14 +00:00
|
|
|
src_addr = optarg;
|
2010-02-14 22:18:00 +00:00
|
|
|
break;
|
2008-09-12 22:55:10 +00:00
|
|
|
case 'v':
|
2010-02-14 22:18:00 +00:00
|
|
|
verbose++;
|
|
|
|
break;
|
2008-09-12 22:55:10 +00:00
|
|
|
case 'L':
|
2010-02-14 22:18:00 +00:00
|
|
|
show_conf++;
|
|
|
|
break;
|
2008-09-12 22:55:10 +00:00
|
|
|
case 'l':
|
2010-02-14 22:18:00 +00:00
|
|
|
list_models();
|
|
|
|
exit(0);
|
|
|
|
case 'u':
|
|
|
|
dump_caps_opt++;
|
|
|
|
break;
|
2008-10-27 22:23:36 +00:00
|
|
|
case 'e':
|
2010-02-14 22:18:00 +00:00
|
|
|
opt_end = 1;
|
|
|
|
fprintf(stderr, "-e|--end-marker option is deprecated!\nPlease consider using the Extended Response protocol instead.\n");
|
|
|
|
break;
|
2008-09-12 22:55:10 +00:00
|
|
|
default:
|
2010-02-14 22:18:00 +00:00
|
|
|
usage(); /* unknown option? */
|
|
|
|
exit(1);
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-14 23:58:54 +00:00
|
|
|
rig_set_debug(verbose);
|
|
|
|
|
2008-09-12 22:55:10 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "rotctld, %s\n", hamlib_version);
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to "
|
|
|
|
"<hamlib-developer@lists.sourceforge.net>\n\n");
|
|
|
|
|
|
|
|
my_rot = rot_init(my_model);
|
|
|
|
|
|
|
|
if (!my_rot) {
|
2010-02-14 22:18:00 +00:00
|
|
|
fprintf(stderr, "Unknown rot num %d, or initialization error.\n",
|
2008-09-12 22:55:10 +00:00
|
|
|
my_model);
|
|
|
|
fprintf(stderr, "Please check with --list option.\n");
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
retcode = set_conf(my_rot, conf_parms);
|
|
|
|
if (retcode != RIG_OK) {
|
|
|
|
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rot_file)
|
2012-01-08 02:36:50 +00:00
|
|
|
strncpy(my_rot->state.rotport.pathname, rot_file, FILPATHLEN - 1);
|
2008-09-12 22:55:10 +00:00
|
|
|
|
|
|
|
/* FIXME: bound checking and port type == serial */
|
|
|
|
if (serial_rate != 0)
|
|
|
|
my_rot->state.rotport.parm.serial.rate = serial_rate;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* print out conf parameters
|
|
|
|
*/
|
|
|
|
if (show_conf) {
|
|
|
|
rot_token_foreach(my_rot, print_conf_list, (rig_ptr_t)my_rot);
|
|
|
|
}
|
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/*
|
|
|
|
* print out conf parameters, and exits immediately
|
|
|
|
* We may be interested only in only caps, and rig_open may fail.
|
|
|
|
*/
|
|
|
|
if (dump_caps_opt) {
|
|
|
|
dumpcaps_rot(my_rot, stdout);
|
2010-03-03 08:34:00 +00:00
|
|
|
rot_cleanup(my_rot); /* if you care about memory */
|
2010-02-14 22:18:00 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2008-09-12 22:55:10 +00:00
|
|
|
retcode = rot_open(my_rot);
|
|
|
|
if (retcode != RIG_OK) {
|
|
|
|
fprintf(stderr,"rot_open: error = %s \n", rigerror(retcode));
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verbose > 0)
|
|
|
|
printf("Opened rot model %d, '%s'\n", my_rot->caps->rot_model,
|
|
|
|
my_rot->caps->model_name);
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "Backend version: %s, Status: %s\n",
|
|
|
|
my_rot->caps->version, rig_strstatus(my_rot->caps->status));
|
|
|
|
|
2011-03-27 17:13:22 +00:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
# ifndef SO_OPENTYPE
|
|
|
|
# define SO_OPENTYPE 0x7008
|
|
|
|
# endif
|
|
|
|
# ifndef SO_SYNCHRONOUS_NONALERT
|
|
|
|
# define SO_SYNCHRONOUS_NONALERT 0x20
|
|
|
|
# endif
|
|
|
|
# ifndef INVALID_SOCKET
|
|
|
|
# define INVALID_SOCKET -1
|
|
|
|
# endif
|
|
|
|
|
|
|
|
WSADATA wsadata;
|
|
|
|
if (WSAStartup(MAKEWORD(1,1), &wsadata) == SOCKET_ERROR) {
|
|
|
|
fprintf(stderr,"WSAStartup socket error\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sockopt = SO_SYNCHRONOUS_NONALERT;
|
|
|
|
setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *)&sockopt, sizeof(sockopt));
|
|
|
|
#endif
|
|
|
|
|
2008-09-12 22:55:10 +00:00
|
|
|
/*
|
|
|
|
* Prepare listening socket
|
|
|
|
*/
|
2010-04-16 20:50:14 +00:00
|
|
|
memset(&hints, 0, sizeof(struct addrinfo));
|
|
|
|
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
|
|
|
|
hints.ai_socktype = SOCK_STREAM;/* TCP socket */
|
|
|
|
hints.ai_flags = AI_PASSIVE; /* For wildcard IP address */
|
|
|
|
hints.ai_protocol = 0; /* Any protocol */
|
|
|
|
|
|
|
|
retcode = getaddrinfo(src_addr, portno, &hints, &result);
|
|
|
|
if (retcode != 0) {
|
|
|
|
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode));
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
sock_listen = socket(result->ai_family, result->ai_socktype,
|
|
|
|
result->ai_protocol);
|
2008-11-02 12:39:36 +00:00
|
|
|
if (sock_listen < 0) {
|
2008-09-12 22:55:10 +00:00
|
|
|
perror("ERROR opening socket");
|
2008-11-02 12:39:36 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2008-09-12 22:55:10 +00:00
|
|
|
|
|
|
|
if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEADDR,
|
|
|
|
(char *)&reuseaddr,sizeof(reuseaddr)) < 0) {
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "setsockopt: %s\n", strerror(errno));
|
|
|
|
exit (1);
|
|
|
|
}
|
2010-04-16 20:50:14 +00:00
|
|
|
if (bind(sock_listen, result->ai_addr, result->ai_addrlen) < 0) {
|
2008-09-12 22:55:10 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR, "binding: %s\n", strerror(errno));
|
|
|
|
exit (1);
|
|
|
|
}
|
2010-04-16 20:50:14 +00:00
|
|
|
|
|
|
|
freeaddrinfo(result); /* No longer needed */
|
|
|
|
|
2008-09-12 22:55:10 +00:00
|
|
|
if (listen(sock_listen,4) < 0) {
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "listening: %s\n", strerror(errno));
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* main loop accepting connections
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
#ifdef HAVE_PTHREAD
|
|
|
|
pthread_t thread;
|
2008-09-17 20:36:34 +00:00
|
|
|
pthread_attr_t attr;
|
2008-09-12 22:55:10 +00:00
|
|
|
#endif
|
|
|
|
struct handle_data *arg;
|
|
|
|
|
|
|
|
arg = malloc(sizeof(struct handle_data));
|
|
|
|
if (!arg) {
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "malloc: %s\n", strerror(errno));
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
arg->rot = my_rot;
|
|
|
|
arg->clilen = sizeof(arg->cli_addr);
|
|
|
|
arg->sock = accept(sock_listen, (struct sockaddr *) &arg->cli_addr,
|
|
|
|
&arg->clilen);
|
|
|
|
if (arg->sock < 0) {
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "accept: %s\n", strerror(errno));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "Connection opened from %s:%d\n",
|
|
|
|
inet_ntoa(arg->cli_addr.sin_addr),
|
|
|
|
ntohs(arg->cli_addr.sin_port));
|
|
|
|
|
|
|
|
#ifdef HAVE_PTHREAD
|
2008-09-17 20:36:34 +00:00
|
|
|
pthread_attr_init(&attr);
|
|
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
|
|
|
|
|
|
|
retcode = pthread_create(&thread, &attr, handle_socket, arg);
|
2008-09-17 18:56:13 +00:00
|
|
|
if (retcode != 0) {
|
2008-09-12 22:55:10 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
handle_socket(arg);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
while (retcode == 0);
|
|
|
|
|
|
|
|
rot_close(my_rot); /* close port */
|
|
|
|
rot_cleanup(my_rot); /* if you care about memory */
|
|
|
|
|
2011-03-27 17:13:22 +00:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
WSACleanup();
|
|
|
|
#endif
|
|
|
|
|
2008-09-12 22:55:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the function run by the threads
|
|
|
|
*/
|
|
|
|
void * handle_socket(void *arg)
|
|
|
|
{
|
|
|
|
struct handle_data *handle_data_arg = (struct handle_data *)arg;
|
|
|
|
FILE *fsockin;
|
|
|
|
FILE *fsockout;
|
|
|
|
int retcode;
|
|
|
|
|
2011-03-27 17:13:22 +00:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
int sock_osfhandle = _open_osfhandle(handle_data_arg->sock, _O_RDONLY);
|
|
|
|
if (sock_osfhandle == -1) {
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "_open_osfhandle error: %s\n", strerror(errno));
|
|
|
|
goto handle_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
fsockin = _fdopen(sock_osfhandle, "rb");
|
|
|
|
#else
|
2008-09-12 22:55:10 +00:00
|
|
|
fsockin = fdopen(handle_data_arg->sock, "rb");
|
2011-03-27 17:13:22 +00:00
|
|
|
#endif
|
2008-09-12 22:55:10 +00:00
|
|
|
if (!fsockin) {
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno));
|
2011-03-27 17:13:22 +00:00
|
|
|
goto handle_exit;
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
2011-03-27 17:13:22 +00:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
fsockout = _fdopen(sock_osfhandle, "wb");
|
|
|
|
#else
|
2008-09-12 22:55:10 +00:00
|
|
|
fsockout = fdopen(handle_data_arg->sock, "wb");
|
2011-03-27 17:13:22 +00:00
|
|
|
#endif
|
2008-09-12 22:55:10 +00:00
|
|
|
if (!fsockout) {
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno));
|
2008-09-17 18:56:13 +00:00
|
|
|
fclose(fsockin);
|
2011-03-27 17:13:22 +00:00
|
|
|
goto handle_exit;
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
retcode = rotctl_parse(handle_data_arg->rot, fsockin, fsockout, NULL, 0);
|
|
|
|
if (ferror(fsockin) || ferror(fsockout))
|
|
|
|
retcode = 1;
|
|
|
|
}
|
2010-12-01 21:41:55 +00:00
|
|
|
while (retcode == 0 || retcode == 2);
|
2008-09-12 22:55:10 +00:00
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "Connection closed from %s:%d\n",
|
|
|
|
inet_ntoa(handle_data_arg->cli_addr.sin_addr),
|
|
|
|
ntohs(handle_data_arg->cli_addr.sin_port));
|
|
|
|
|
|
|
|
fclose(fsockin);
|
|
|
|
fclose(fsockout);
|
2011-03-27 17:13:22 +00:00
|
|
|
handle_exit:
|
|
|
|
#ifdef __MINGW32__
|
|
|
|
closesocket(handle_data_arg->sock);
|
|
|
|
#else
|
2008-09-12 22:55:10 +00:00
|
|
|
close(handle_data_arg->sock);
|
2011-03-27 17:13:22 +00:00
|
|
|
#endif
|
2008-09-12 22:55:10 +00:00
|
|
|
free(arg);
|
|
|
|
|
2008-09-17 18:56:13 +00:00
|
|
|
#ifdef HAVE_PTHREAD
|
|
|
|
pthread_exit(NULL);
|
|
|
|
#endif
|
2008-09-12 22:55:10 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void usage()
|
|
|
|
{
|
|
|
|
printf("Usage: rotctld [OPTION]... [COMMAND]...\n"
|
|
|
|
"Daemon serving COMMANDs to a connected antenna rotator.\n\n");
|
|
|
|
|
|
|
|
printf(
|
|
|
|
" -m, --model=ID select rotator model number. See model list\n"
|
|
|
|
" -r, --rot-file=DEVICE set device of the rotator to operate on\n"
|
|
|
|
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
|
2010-04-16 20:50:14 +00:00
|
|
|
" -t, --port=NUM set TCP listening port, default %s\n"
|
2008-09-21 20:32:08 +00:00
|
|
|
" -T, --listen-addr=IPADDR set listening IP address, default ANY\n"
|
2008-09-12 22:55:10 +00:00
|
|
|
" -C, --set-conf=PARM=VAL set config parameters\n"
|
|
|
|
" -L, --show-conf list all config parameters\n"
|
|
|
|
" -l, --list list all model numbers and exit\n"
|
2010-02-14 22:18:00 +00:00
|
|
|
" -u, --dump-caps dump capabilities and exit\n"
|
|
|
|
" -e, --end-marker use END marker in rotctld protocol (obsolete)\n"
|
2008-09-12 22:55:10 +00:00
|
|
|
" -v, --verbose set verbose mode, cumulative\n"
|
|
|
|
" -h, --help display this help and exit\n"
|
|
|
|
" -V, --version output version information and exit\n\n",
|
|
|
|
portno);
|
|
|
|
|
|
|
|
usage_rot(stdout);
|
|
|
|
|
|
|
|
printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
|
|
|
|
}
|
|
|
|
|