kopia lustrzana https://github.com/Hamlib/Hamlib
Touch up rigctld.c and rotctld.c with astyle
Prior reformat had only been a reindent with Emacs. Now use astyle.libusb-1-0
rodzic
022ba0f48b
commit
4595f77f99
132
tests/rigctld.c
132
tests/rigctld.c
|
@ -76,15 +76,14 @@
|
|||
* TODO: add an option to read from a file
|
||||
*/
|
||||
#define SHORT_OPTIONS "m:r:p:d:P:D:s:c:T:t:C:lLuovhV"
|
||||
static struct option long_options[] =
|
||||
{
|
||||
static struct option long_options[] = {
|
||||
{"model", 1, 0, 'm'},
|
||||
{"rig-file", 1, 0, 'r'},
|
||||
{"ptt-file", 1, 0, 'p'},
|
||||
{"dcd-file", 1, 0, 'd'},
|
||||
{"ptt-type", 1, 0, 'P'},
|
||||
{"dcd-type", 1, 0, 'D'},
|
||||
{"serial-speed",1, 0, 's'},
|
||||
{"serial-speed", 1, 0, 's'},
|
||||
{"civaddr", 1, 0, 'c'},
|
||||
{"listen-addr", 1, 0, 'T'},
|
||||
{"port", 1, 0, 't'},
|
||||
|
@ -106,7 +105,7 @@ struct handle_data {
|
|||
socklen_t clilen;
|
||||
};
|
||||
|
||||
void * handle_socket(void * arg);
|
||||
void *handle_socket(void *arg);
|
||||
void usage(void);
|
||||
|
||||
int interactive = 1; /* no cmd because of daemon */
|
||||
|
@ -120,7 +119,7 @@ const char *src_addr = NULL; /* INADDR_ANY */
|
|||
|
||||
#define MAXCONFLEN 128
|
||||
|
||||
static void handle_error (enum rig_debug_level_e lvl, const char *msg)
|
||||
static void handle_error(enum rig_debug_level_e lvl, const char *msg)
|
||||
{
|
||||
int e;
|
||||
#ifdef __MINGW32__
|
||||
|
@ -128,6 +127,7 @@ static void handle_error (enum rig_debug_level_e lvl, const char *msg)
|
|||
|
||||
lpMsgBuf = (LPVOID)"Unknown error";
|
||||
e = WSAGetLastError();
|
||||
|
||||
if (FormatMessage(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
|
@ -136,18 +136,19 @@ static void handle_error (enum rig_debug_level_e lvl, const char *msg)
|
|||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
// Default language
|
||||
(LPTSTR)&lpMsgBuf, 0, NULL)) {
|
||||
rig_debug (lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf);
|
||||
rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf);
|
||||
LocalFree(lpMsgBuf);
|
||||
} else {
|
||||
rig_debug (lvl, "%s: Network error %d\n", msg, e);
|
||||
rig_debug(lvl, "%s: Network error %d\n", msg, e);
|
||||
}
|
||||
|
||||
#else
|
||||
e = errno;
|
||||
rig_debug (lvl, "%s: Network error %d: %s\n", msg, e, strerror (e));
|
||||
rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, strerror(e));
|
||||
#endif
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
RIG *my_rig; /* handle to rig (instance) */
|
||||
rig_model_t my_model = RIG_MODEL_DUMMY;
|
||||
|
@ -157,7 +158,7 @@ int main (int argc, char *argv[])
|
|||
int verbose = 0;
|
||||
int show_conf = 0;
|
||||
int dump_caps_opt = 0;
|
||||
const char *rig_file=NULL, *ptt_file=NULL, *dcd_file=NULL;
|
||||
const char *rig_file = NULL, *ptt_file = NULL, *dcd_file = NULL;
|
||||
ptt_type_t ptt_type = RIG_PTT_NONE;
|
||||
dcd_type_t dcd_type = RIG_DCD_NONE;
|
||||
int serial_rate = 0;
|
||||
|
@ -175,51 +176,63 @@ int main (int argc, char *argv[])
|
|||
int c;
|
||||
int option_index = 0;
|
||||
|
||||
c = getopt_long (argc, argv, SHORT_OPTIONS,
|
||||
long_options, &option_index);
|
||||
c = getopt_long(argc, argv, SHORT_OPTIONS,
|
||||
long_options, &option_index);
|
||||
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch(c) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
usage();
|
||||
exit(0);
|
||||
|
||||
case 'V':
|
||||
version();
|
||||
exit(0);
|
||||
|
||||
case 'm':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
my_model = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
rig_file = optarg;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ptt_file = optarg;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
dcd_file = optarg;
|
||||
break;
|
||||
|
||||
case 'P':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!strcmp(optarg, "RIG"))
|
||||
ptt_type = RIG_PTT_RIG;
|
||||
else if (!strcmp(optarg, "DTR"))
|
||||
|
@ -234,12 +247,15 @@ int main (int argc, char *argv[])
|
|||
ptt_type = RIG_PTT_NONE;
|
||||
else
|
||||
ptt_type = atoi(optarg);
|
||||
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!strcmp(optarg, "RIG"))
|
||||
dcd_type = RIG_DCD_RIG;
|
||||
else if (!strcmp(optarg, "DSR"))
|
||||
|
@ -254,59 +270,77 @@ int main (int argc, char *argv[])
|
|||
dcd_type = RIG_DCD_NONE;
|
||||
else
|
||||
dcd_type = atoi(optarg);
|
||||
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
civaddr = optarg;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
serial_rate = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (*conf_parms != '\0')
|
||||
strcat(conf_parms, ",");
|
||||
strncat(conf_parms, optarg, MAXCONFLEN-strlen(conf_parms));
|
||||
|
||||
strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms));
|
||||
break;
|
||||
|
||||
case 't':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
portno = optarg;
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
src_addr = optarg;
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
vfo_mode++;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
verbose++;
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
show_conf++;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
list_models();
|
||||
exit(0);
|
||||
|
||||
case 'u':
|
||||
dump_caps_opt++;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(); /* unknown option? */
|
||||
exit(1);
|
||||
|
@ -343,17 +377,22 @@ int main (int argc, char *argv[])
|
|||
*/
|
||||
if (ptt_type != RIG_PTT_NONE)
|
||||
my_rig->state.pttport.type.ptt = ptt_type;
|
||||
|
||||
if (dcd_type != RIG_DCD_NONE)
|
||||
my_rig->state.dcdport.type.dcd = dcd_type;
|
||||
|
||||
if (ptt_file)
|
||||
strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1);
|
||||
|
||||
if (dcd_file)
|
||||
strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN - 1);
|
||||
|
||||
/* FIXME: bound checking and port type == serial */
|
||||
if (serial_rate != 0)
|
||||
my_rig->state.rigport.parm.serial.rate = serial_rate;
|
||||
|
||||
if (civaddr)
|
||||
rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr);
|
||||
rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr);
|
||||
|
||||
/*
|
||||
* print out conf parameters
|
||||
|
@ -375,7 +414,7 @@ int main (int argc, char *argv[])
|
|||
retcode = rig_open(my_rig);
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr,"rig_open: error = %s \n", rigerror(retcode));
|
||||
fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
|
||||
|
@ -398,8 +437,9 @@ int main (int argc, char *argv[])
|
|||
# endif
|
||||
|
||||
WSADATA wsadata;
|
||||
if (WSAStartup(MAKEWORD(1,1), &wsadata) == SOCKET_ERROR) {
|
||||
fprintf(stderr,"WSAStartup socket error\n");
|
||||
|
||||
if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) {
|
||||
fprintf(stderr, "WSAStartup socket error\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -417,51 +457,57 @@ int main (int argc, char *argv[])
|
|||
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);
|
||||
}
|
||||
|
||||
saved_result = result;
|
||||
|
||||
do {
|
||||
sock_listen = socket(result->ai_family, result->ai_socktype,
|
||||
result->ai_protocol);
|
||||
|
||||
if (sock_listen < 0) {
|
||||
handle_error (RIG_DEBUG_ERR, "socket");
|
||||
handle_error(RIG_DEBUG_ERR, "socket");
|
||||
freeaddrinfo(saved_result); /* No longer needed */
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEADDR,
|
||||
(char *)&reuseaddr, sizeof(reuseaddr)) < 0) {
|
||||
handle_error (RIG_DEBUG_ERR, "setsockopt");
|
||||
handle_error(RIG_DEBUG_ERR, "setsockopt");
|
||||
freeaddrinfo(saved_result); /* No longer needed */
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef IPV6_V6ONLY
|
||||
|
||||
if (AF_INET6 == result->ai_family) {
|
||||
/* allow IPv4 mapped to IPv6 clients Windows and BSD default
|
||||
this to 1 (i.e. disallowed) and we prefer it off */
|
||||
sockopt = 0;
|
||||
|
||||
if (setsockopt(sock_listen, IPPROTO_IPV6, IPV6_V6ONLY,
|
||||
(char *)&sockopt, sizeof(sockopt)) < 0) {
|
||||
handle_error (RIG_DEBUG_ERR, "setsockopt");
|
||||
handle_error(RIG_DEBUG_ERR, "setsockopt");
|
||||
freeaddrinfo(saved_result); /* No longer needed */
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) {
|
||||
break;
|
||||
}
|
||||
|
||||
handle_error (RIG_DEBUG_WARN, "binding failed (trying next interface)");
|
||||
handle_error(RIG_DEBUG_WARN, "binding failed (trying next interface)");
|
||||
#ifdef __MINGW32__
|
||||
closesocket (sock_listen);
|
||||
closesocket(sock_listen);
|
||||
#else
|
||||
close (sock_listen);
|
||||
close(sock_listen);
|
||||
#endif
|
||||
} while ((result = result->ai_next) != NULL);
|
||||
|
||||
|
@ -469,12 +515,12 @@ int main (int argc, char *argv[])
|
|||
|
||||
if (NULL == result) {
|
||||
rig_debug(RIG_DEBUG_ERR, "bind error - no available interface\n");
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (listen(sock_listen, 4) < 0) {
|
||||
handle_error (RIG_DEBUG_ERR, "listening");
|
||||
exit (1);
|
||||
handle_error(RIG_DEBUG_ERR, "listening");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -491,21 +537,21 @@ int main (int argc, char *argv[])
|
|||
|
||||
if (!arg) {
|
||||
rig_debug(RIG_DEBUG_ERR, "malloc: %s\n", strerror(errno));
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
arg->rig = my_rig;
|
||||
arg->clilen = sizeof (arg->cli_addr);
|
||||
arg->clilen = sizeof(arg->cli_addr);
|
||||
arg->sock = accept(sock_listen, (struct sockaddr *)&arg->cli_addr, &arg->clilen);
|
||||
|
||||
if (arg->sock < 0) {
|
||||
handle_error (RIG_DEBUG_ERR, "accept");
|
||||
handle_error(RIG_DEBUG_ERR, "accept");
|
||||
break;
|
||||
}
|
||||
|
||||
if ((retcode = getnameinfo ((struct sockaddr const *)&arg->cli_addr, arg->clilen, host,
|
||||
sizeof (host), serv, sizeof (serv), NI_NOFQDN)) < 0) {
|
||||
rig_debug (RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror (retcode));
|
||||
if ((retcode = getnameinfo((struct sockaddr const *)&arg->cli_addr, arg->clilen, host,
|
||||
sizeof(host), serv, sizeof(serv), NI_NOFQDN)) < 0) {
|
||||
rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror(retcode));
|
||||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "Connection opened from %s:%s\n", host, serv);
|
||||
|
@ -520,6 +566,7 @@ int main (int argc, char *argv[])
|
|||
rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
|
||||
break;
|
||||
}
|
||||
|
||||
#else
|
||||
handle_socket(arg);
|
||||
#endif
|
||||
|
@ -539,7 +586,7 @@ int main (int argc, char *argv[])
|
|||
/*
|
||||
* This is the function run by the threads
|
||||
*/
|
||||
void * handle_socket(void *arg)
|
||||
void *handle_socket(void *arg)
|
||||
{
|
||||
struct handle_data *handle_data_arg = (struct handle_data *)arg;
|
||||
FILE *fsockin;
|
||||
|
@ -560,6 +607,7 @@ void * handle_socket(void *arg)
|
|||
#else
|
||||
fsockin = fdopen(handle_data_arg->sock, "rb");
|
||||
#endif
|
||||
|
||||
if (!fsockin) {
|
||||
rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno));
|
||||
goto handle_exit;
|
||||
|
@ -570,6 +618,7 @@ void * handle_socket(void *arg)
|
|||
#else
|
||||
fsockout = fdopen(handle_data_arg->sock, "wb");
|
||||
#endif
|
||||
|
||||
if (!fsockout) {
|
||||
rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno));
|
||||
fclose(fsockin);
|
||||
|
@ -579,14 +628,15 @@ void * handle_socket(void *arg)
|
|||
|
||||
do {
|
||||
retcode = rigctl_parse(handle_data_arg->rig, fsockin, fsockout, NULL, 0);
|
||||
|
||||
if (ferror(fsockin) || ferror(fsockout))
|
||||
retcode = 1;
|
||||
} while (retcode == 0 || retcode == 2);
|
||||
|
||||
if ((retcode = getnameinfo ((struct sockaddr const *)&handle_data_arg->cli_addr,
|
||||
handle_data_arg->clilen, host, sizeof (host),
|
||||
serv, sizeof (serv), NI_NOFQDN)) < 0) {
|
||||
rig_debug (RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror (retcode));
|
||||
if ((retcode = getnameinfo((struct sockaddr const *)&handle_data_arg->cli_addr,
|
||||
handle_data_arg->clilen, host, sizeof(host),
|
||||
serv, sizeof(serv), NI_NOFQDN)) < 0) {
|
||||
rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror(retcode));
|
||||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "Connection closed from %s:%s\n",
|
||||
|
@ -636,7 +686,7 @@ void usage(void)
|
|||
" -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 );
|
||||
portno);
|
||||
|
||||
usage_rig(stdout);
|
||||
|
||||
|
|
110
tests/rotctld.c
110
tests/rotctld.c
|
@ -72,7 +72,7 @@ struct handle_data {
|
|||
socklen_t clilen;
|
||||
};
|
||||
|
||||
void * handle_socket(void * arg);
|
||||
void *handle_socket(void *arg);
|
||||
|
||||
void usage();
|
||||
|
||||
|
@ -83,11 +83,10 @@ void usage();
|
|||
* TODO: add an option to read from a file
|
||||
*/
|
||||
#define SHORT_OPTIONS "m:r:s:C:t:T:LuvhVl"
|
||||
static struct option long_options[] =
|
||||
{
|
||||
static struct option long_options[] = {
|
||||
{"model", 1, 0, 'm'},
|
||||
{"rot-file", 1, 0, 'r'},
|
||||
{"serial-speed",1, 0, 's'},
|
||||
{"serial-speed", 1, 0, 's'},
|
||||
{"port", 1, 0, 't'},
|
||||
{"listen-addr", 1, 0, 'T'},
|
||||
{"list", 0, 0, 'l'},
|
||||
|
@ -101,7 +100,7 @@ static struct option long_options[] =
|
|||
};
|
||||
|
||||
int interactive = 1; /* no cmd because of daemon */
|
||||
int prompt= 0 ; /* Daemon mode for rigparse return string */
|
||||
int prompt = 0 ; /* Daemon mode for rigparse return string */
|
||||
|
||||
const char *portno = "4533";
|
||||
const char *src_addr = NULL; /* INADDR_ANY */
|
||||
|
@ -111,7 +110,7 @@ char send_cmd_term = '\r'; /* send_cmd termination char */
|
|||
#define MAXCONFLEN 128
|
||||
|
||||
|
||||
static void handle_error (enum rig_debug_level_e lvl, const char *msg)
|
||||
static void handle_error(enum rig_debug_level_e lvl, const char *msg)
|
||||
{
|
||||
int e;
|
||||
#ifdef __MINGW32__
|
||||
|
@ -128,18 +127,19 @@ static void handle_error (enum rig_debug_level_e lvl, const char *msg)
|
|||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
// Default language
|
||||
(LPTSTR)&lpMsgBuf, 0, NULL)) {
|
||||
rig_debug (lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf);
|
||||
rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf);
|
||||
LocalFree(lpMsgBuf);
|
||||
} else {
|
||||
rig_debug (lvl, "%s: Network error %d\n", msg, e);
|
||||
rig_debug(lvl, "%s: Network error %d\n", msg, e);
|
||||
}
|
||||
|
||||
#else
|
||||
e = errno;
|
||||
rig_debug (lvl, "%s: Network error %d: %s\n", msg, e, strerror (e));
|
||||
rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, strerror(e));
|
||||
#endif
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ROT *my_rot; /* handle to rot (instance) */
|
||||
rot_model_t my_model = ROT_MODEL_DUMMY;
|
||||
|
@ -149,7 +149,7 @@ int main (int argc, char *argv[])
|
|||
int verbose = 0;
|
||||
int show_conf = 0;
|
||||
int dump_caps_opt = 0;
|
||||
const char *rot_file=NULL;
|
||||
const char *rot_file = NULL;
|
||||
int serial_rate = 0;
|
||||
char conf_parms[MAXCONFLEN] = "";
|
||||
|
||||
|
@ -160,78 +160,98 @@ int main (int argc, char *argv[])
|
|||
char host[NI_MAXHOST];
|
||||
char serv[NI_MAXSERV];
|
||||
|
||||
while(1) {
|
||||
while (1) {
|
||||
int c;
|
||||
int option_index = 0;
|
||||
|
||||
c = getopt_long(argc, argv, SHORT_OPTIONS,
|
||||
long_options, &option_index);
|
||||
long_options, &option_index);
|
||||
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch(c) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
usage();
|
||||
exit(0);
|
||||
|
||||
case 'V':
|
||||
version();
|
||||
exit(0);
|
||||
|
||||
case 'm':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
my_model = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
rot_file = optarg;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
serial_rate = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (*conf_parms != '\0')
|
||||
strcat(conf_parms, ",");
|
||||
strncat(conf_parms, optarg, MAXCONFLEN-strlen(conf_parms));
|
||||
|
||||
strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms));
|
||||
break;
|
||||
|
||||
case 't':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
portno = optarg;
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
src_addr = optarg;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
verbose++;
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
show_conf++;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
list_models();
|
||||
exit(0);
|
||||
|
||||
case 'u':
|
||||
dump_caps_opt++;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(); /* unknown option? */
|
||||
exit(1);
|
||||
|
@ -287,7 +307,7 @@ int main (int argc, char *argv[])
|
|||
retcode = rot_open(my_rot);
|
||||
|
||||
if (retcode != RIG_OK) {
|
||||
fprintf(stderr,"rot_open: error = %s \n", rigerror(retcode));
|
||||
fprintf(stderr, "rot_open: error = %s \n", rigerror(retcode));
|
||||
exit(2);
|
||||
}
|
||||
|
||||
|
@ -311,8 +331,8 @@ int main (int argc, char *argv[])
|
|||
|
||||
WSADATA wsadata;
|
||||
|
||||
if (WSAStartup(MAKEWORD(1,1), &wsadata) == SOCKET_ERROR) {
|
||||
fprintf(stderr,"WSAStartup socket error\n");
|
||||
if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) {
|
||||
fprintf(stderr, "WSAStartup socket error\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -330,6 +350,7 @@ int main (int argc, char *argv[])
|
|||
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);
|
||||
|
@ -342,19 +363,20 @@ int main (int argc, char *argv[])
|
|||
result->ai_protocol);
|
||||
|
||||
if (sock_listen < 0) {
|
||||
handle_error (RIG_DEBUG_ERR, "socket");
|
||||
handle_error(RIG_DEBUG_ERR, "socket");
|
||||
freeaddrinfo(result); /* No longer needed */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEADDR,
|
||||
(char *)&reuseaddr,sizeof(reuseaddr)) < 0) {
|
||||
handle_error (RIG_DEBUG_ERR, "setsockopt");
|
||||
(char *)&reuseaddr, sizeof(reuseaddr)) < 0) {
|
||||
handle_error(RIG_DEBUG_ERR, "setsockopt");
|
||||
freeaddrinfo(result); /* No longer needed */
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef IPV6_V6ONLY
|
||||
|
||||
if (AF_INET6 == result->ai_family) {
|
||||
/* allow IPv4 mapped to IPv6 clients, MS & BSD default this
|
||||
to 1 i.e. disallowed */
|
||||
|
@ -362,21 +384,23 @@ int main (int argc, char *argv[])
|
|||
|
||||
if (setsockopt(sock_listen, IPPROTO_IPV6, IPV6_V6ONLY,
|
||||
(char *)&sockopt, sizeof(sockopt)) < 0) {
|
||||
handle_error (RIG_DEBUG_ERR, "setsockopt");
|
||||
handle_error(RIG_DEBUG_ERR, "setsockopt");
|
||||
freeaddrinfo(saved_result); /* No longer needed */
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) {
|
||||
break;
|
||||
}
|
||||
handle_error (RIG_DEBUG_WARN, "binding failed (trying next interface)");
|
||||
|
||||
handle_error(RIG_DEBUG_WARN, "binding failed (trying next interface)");
|
||||
#ifdef __MINGW32__
|
||||
closesocket (sock_listen);
|
||||
closesocket(sock_listen);
|
||||
#else
|
||||
close (sock_listen);
|
||||
close(sock_listen);
|
||||
#endif
|
||||
} while ((result = result->ai_next) != NULL);
|
||||
|
||||
|
@ -384,12 +408,12 @@ int main (int argc, char *argv[])
|
|||
|
||||
if (NULL == result) {
|
||||
rig_debug(RIG_DEBUG_ERR, "bind error - no available interface\n");
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (listen(sock_listen, 4) < 0) {
|
||||
handle_error (RIG_DEBUG_ERR, "listening");
|
||||
exit (1);
|
||||
handle_error(RIG_DEBUG_ERR, "listening");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -406,7 +430,7 @@ int main (int argc, char *argv[])
|
|||
|
||||
if (!arg) {
|
||||
rig_debug(RIG_DEBUG_ERR, "malloc: %s\n", strerror(errno));
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
arg->rot = my_rot;
|
||||
|
@ -415,14 +439,14 @@ int main (int argc, char *argv[])
|
|||
&arg->clilen);
|
||||
|
||||
if (arg->sock < 0) {
|
||||
handle_error (RIG_DEBUG_ERR, "accept");
|
||||
handle_error(RIG_DEBUG_ERR, "accept");
|
||||
break;
|
||||
}
|
||||
|
||||
if ((retcode = getnameinfo ((struct sockaddr const *)&arg->cli_addr, arg->clilen,
|
||||
host, sizeof (host), serv, sizeof (serv),
|
||||
NI_NOFQDN)) < 0) {
|
||||
rig_debug (RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror (retcode));
|
||||
if ((retcode = getnameinfo((struct sockaddr const *)&arg->cli_addr, arg->clilen,
|
||||
host, sizeof(host), serv, sizeof(serv),
|
||||
NI_NOFQDN)) < 0) {
|
||||
rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror(retcode));
|
||||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "Connection opened from %s:%s\n",
|
||||
|
@ -438,6 +462,7 @@ int main (int argc, char *argv[])
|
|||
rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
|
||||
break;
|
||||
}
|
||||
|
||||
#else
|
||||
handle_socket(arg);
|
||||
#endif
|
||||
|
@ -457,7 +482,7 @@ int main (int argc, char *argv[])
|
|||
/*
|
||||
* This is the function run by the threads
|
||||
*/
|
||||
void * handle_socket(void *arg)
|
||||
void *handle_socket(void *arg)
|
||||
{
|
||||
struct handle_data *handle_data_arg = (struct handle_data *)arg;
|
||||
FILE *fsockin;
|
||||
|
@ -478,6 +503,7 @@ void * handle_socket(void *arg)
|
|||
#else
|
||||
fsockin = fdopen(handle_data_arg->sock, "rb");
|
||||
#endif
|
||||
|
||||
if (!fsockin) {
|
||||
rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno));
|
||||
goto handle_exit;
|
||||
|
@ -488,6 +514,7 @@ void * handle_socket(void *arg)
|
|||
#else
|
||||
fsockout = fdopen(handle_data_arg->sock, "wb");
|
||||
#endif
|
||||
|
||||
if (!fsockout) {
|
||||
rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno));
|
||||
fclose(fsockin);
|
||||
|
@ -496,14 +523,15 @@ void * handle_socket(void *arg)
|
|||
|
||||
do {
|
||||
retcode = rotctl_parse(handle_data_arg->rot, fsockin, fsockout, NULL, 0);
|
||||
|
||||
if (ferror(fsockin) || ferror(fsockout))
|
||||
retcode = 1;
|
||||
} while (retcode == 0 || retcode == 2);
|
||||
|
||||
if ((retcode = getnameinfo ((struct sockaddr const *)&handle_data_arg->cli_addr,
|
||||
handle_data_arg->clilen, host, sizeof (host),
|
||||
serv, sizeof (serv), NI_NOFQDN)) < 0) {
|
||||
rig_debug (RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror (retcode));
|
||||
if ((retcode = getnameinfo((struct sockaddr const *)&handle_data_arg->cli_addr,
|
||||
handle_data_arg->clilen, host, sizeof(host),
|
||||
serv, sizeof(serv), NI_NOFQDN)) < 0) {
|
||||
rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror(retcode));
|
||||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "Connection closed from %s:%s\n",
|
||||
|
|
Ładowanie…
Reference in New Issue