summaryrefslogtreecommitdiffstats
path: root/user_call/netrom_call.c
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>1999-07-08 06:44:55 +0200
committerRalf Baechle <ralf@linux-mips.org>1999-07-08 06:44:55 +0200
commit5f5d1604492ae15967f9d86f41fbeeedcae0ae2b (patch)
treebcecfd65dc578eabfaee10b1e039c467ac89d8b5 /user_call/netrom_call.c
parent1b4023134b5ff6342301c8135b11df46546d2828 (diff)
Import ax25-tools 0.0.3 from tarballax25-tools-0.0.3
Diffstat (limited to 'user_call/netrom_call.c')
-rw-r--r--user_call/netrom_call.c97
1 files changed, 50 insertions, 47 deletions
diff --git a/user_call/netrom_call.c b/user_call/netrom_call.c
index deb877e..ca4c1c9 100644
--- a/user_call/netrom_call.c
+++ b/user_call/netrom_call.c
@@ -1,3 +1,4 @@
+#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
@@ -8,8 +9,8 @@
#include <sys/time.h>
#include <sys/types.h>
-
#include <sys/socket.h>
+
#ifdef HAVE_NETAX25_AX25_H
#include <netax25/ax25.h>
#else
@@ -30,27 +31,49 @@
#include <netax25/axconfig.h>
#include <netax25/nrconfig.h>
-void alarm_handler(int sig)
-{
-}
+#include "user_io.h"
-void err(char *message)
+void alarm_handler(int sig)
{
- write(STDOUT_FILENO, message, strlen(message));
- exit(1);
}
int main(int argc, char **argv)
{
- char buffer[512], *addr;
- fd_set read_fd;
- int n, s, addrlen = sizeof(struct full_sockaddr_ax25);
+ char buffer[256], *addr;
+ int s, addrlen = sizeof(struct full_sockaddr_ax25);
struct full_sockaddr_ax25 nrbind, nrconnect;
+ paclen_in = 236;
+ paclen_out = 236;
+
+ while ((s = getopt(argc, argv, "ci:o:")) != -1) {
+ switch (s) {
+ case 'c':
+ init_compress();
+ compression = 1;
+ break;
+ case 'i':
+ paclen_in = atoi(optarg);
+ break;
+ case 'o':
+ paclen_out = atoi(optarg);
+ break;
+ case ':':
+ case '?':
+ err("ERROR: invalid option usage\r");
+ return 1;
+ }
+ }
+
+ if (paclen_in < 1 || paclen_out < 1) {
+ err("ERROR: invalid paclen\r");
+ return 1;
+ }
+
/*
* Arguments should be "netrom_call port mycall remaddr"
*/
- if (argc != 4) {
+ if ((argc - optind) != 3) {
strcpy(buffer, "ERROR: invalid number of parameters\r");
err(buffer);
}
@@ -67,28 +90,28 @@ int main(int argc, char **argv)
nrbind.fsa_ax25.sax25_ndigis = 1;
nrconnect.fsa_ax25.sax25_ndigis = 0;
- if ((addr = nr_config_get_addr(argv[1])) == NULL) {
- sprintf(buffer, "ERROR: invalid NET/ROM port name - %s\r", argv[1]);
+ if ((addr = nr_config_get_addr(argv[optind])) == NULL) {
+ sprintf(buffer, "ERROR: invalid NET/ROM port name - %s\r", argv[optind]);
err(buffer);
}
if (ax25_aton_entry(addr, nrbind.fsa_ax25.sax25_call.ax25_call) == -1) {
- sprintf(buffer, "ERROR: invalid NET/ROM port callsign - %s\r", argv[1]);
+ sprintf(buffer, "ERROR: invalid NET/ROM port callsign - %s\r", argv[optind]);
err(buffer);
}
- if (ax25_aton_entry(argv[2], nrbind.fsa_digipeater[0].ax25_call) == -1) {
- sprintf(buffer, "ERROR: invalid callsign - %s\r", argv[2]);
+ if (ax25_aton_entry(argv[optind + 1], nrbind.fsa_digipeater[0].ax25_call) == -1) {
+ sprintf(buffer, "ERROR: invalid callsign - %s\r", argv[optind + 1]);
err(buffer);
}
- if ((addr = strchr(argv[3], ':')) == NULL)
- addr = argv[3];
+ if ((addr = strchr(argv[optind + 2], ':')) == NULL)
+ addr = argv[optind + 2];
else
addr++;
if (ax25_aton_entry(addr, nrconnect.fsa_ax25.sax25_call.ax25_call) == -1) {
- sprintf(buffer, "ERROR: invalid callsign - %s\r", argv[3]);
+ sprintf(buffer, "ERROR: invalid callsign - %s\r", argv[optind + 2]);
err(buffer);
}
@@ -108,8 +131,8 @@ int main(int argc, char **argv)
err(buffer);
}
- sprintf(buffer, "Connecting to %s ...\r", argv[3]);
- write(STDOUT_FILENO, buffer, strlen(buffer));
+ sprintf(buffer, "Connecting to %s ...\r", argv[optind + 2]);
+ user_write(STDOUT_FILENO, buffer, strlen(buffer));
/*
* If no response in 30 seconds, go away.
@@ -146,34 +169,14 @@ int main(int argc, char **argv)
alarm(0);
strcpy(buffer, "*** Connected\r");
- write(STDOUT_FILENO, buffer, strlen(buffer));
+ user_write(STDOUT_FILENO, buffer, strlen(buffer));
- /*
- * Loop until one end of the connection goes away.
- */
- for (;;) {
- FD_ZERO(&read_fd);
- FD_SET(STDIN_FILENO, &read_fd);
- FD_SET(s, &read_fd);
-
- select(s + 1, &read_fd, NULL, NULL, NULL);
-
- if (FD_ISSET(s, &read_fd)) {
- if ((n = read(s, buffer, 512)) == -1) {
- strcpy(buffer, "\r*** Disconnected\r");
- err(buffer);
- }
- write(STDOUT_FILENO, buffer, n);
- }
+ select_loop(s);
- if (FD_ISSET(STDIN_FILENO, &read_fd)) {
- if ((n = read(STDIN_FILENO, buffer, 512)) == -1) {
- close(s);
- break;
- }
- write(s, buffer, n);
- }
- }
+ strcpy(buffer, "\r*** Disconnected\r");
+ user_write(STDOUT_FILENO, buffer, strlen(buffer));
+
+ end_compress();
return 0;
}