Use getopt_long() in bin/tncd.c

This commit is contained in:
XANTRONIX Development 2020-10-05 14:53:56 -04:00 committed by XANTRONIX Industrial
parent 535e71c472
commit 379264a956
2 changed files with 39 additions and 19 deletions

View file

@ -6,7 +6,8 @@
.Nd create a KISS TNC from an AX.25 interface
.Sh SYNOPSIS
.Nm
.Ar patty.sock ifname
.Op Fl s Ar patty.sock
.Fl i Ar ifname
.Sh DESCRIPTION
.Nm
exposes a
@ -19,15 +20,15 @@ can be attached to an interface simultaneously. Each frame sent out to the
interface, or received by the interface, is written to the KISS TNC device.
In turn, each frame received by the KISS TNC is sent out to the interface.
.Pp
Both arguments,
.Ar patty.sock ,
a Unix domain socket to a
The
.Fl i Ar ifname
flag is required and must refer to the name of an interface valid on a running
.Xr pattyd 8
instance, and an
.Ar ifname ,
an interface valid on that AX.25 daemon, are required. When a KISS TNC
device is successfully created, the pseudoterminal device name is printed to
standard output.
AX.25 daemon. Optionally,
.Op Fl s Ar patty.sock
may be given to specify another path to a Unix domain socket for that daemon.
When a KISS TNC device is successfully created, the pseudoterminal device name
is printed to standard output.
.Sh SEE ALSO
.Xr pattyd 8 ,
.Xr pty 4

View file

@ -13,6 +13,7 @@
#include <sysexits.h>
#include <patty/ax25.h>
#include <patty/daemon.h>
#include <patty/print.h>
#include <patty/bin/kiss.h>
@ -27,7 +28,7 @@ static void usage(int argc, char **argv, const char *message, ...) {
va_end(args);
}
fprintf(stderr, "usage: %s /var/run/patty.sock ifname\n", argv[0]);
fprintf(stderr, "usage: %s [-s patty.sock] -i ifname\n", argv[0]);
exit(EX_USAGE);
}
@ -158,33 +159,51 @@ error_client_write_socket_request:
}
int main(int argc, char **argv) {
patty_client *client;
struct option opts[] = {
{ "sock", required_argument, NULL, 's' },
{ "if", required_argument, NULL, 'i' },
{ NULL, 0, NULL, 0 }
};
patty_client *client;
char *sock = PATTY_DAEMON_DEFAULT_SOCK,
*ifname = NULL;
int ch,
index;
int fd;
char pty[256];
if (getopt_long(argc, argv, "", opts, NULL) >= 0) {
while ((ch = getopt_long(argc, argv, "s:i:", opts, &index)) >= 0) {
switch (ch) {
case '?':
usage(argc, argv, NULL);
break;
case 's': sock = optarg; break;
case 'i': ifname = optarg; break;
default:
break;
}
}
if (argc < 3) {
usage(argc, argv, "Not enough arguments provided");
if (ifname == NULL) {
usage(argc, argv, "No interface name provided");
}
if ((client = patty_client_new(argv[1])) == NULL) {
if ((client = patty_client_new(sock)) == NULL) {
fprintf(stderr, "%s: %s: %s\n",
argv[0], "patty_client_new()", strerror(errno));
goto error_client_new;
}
if ((fd = pty_promisc(client, argv[2], pty, sizeof(pty))) < 0) {
if ((fd = pty_promisc(client, ifname, pty, sizeof(pty))) < 0) {
fprintf(stderr, "%s: %s: %s: %s\n",
argv[0], "pty_promisc()", argv[2], strerror(errno));
argv[0], "pty_promisc()", ifname, strerror(errno));
goto error_pty_promisc;
}