Use getopt_long() in bin/tncd.c
This commit is contained in:
parent
535e71c472
commit
379264a956
2 changed files with 39 additions and 19 deletions
19
bin/tncd.8
19
bin/tncd.8
|
@ -6,7 +6,8 @@
|
||||||
.Nd create a KISS TNC from an AX.25 interface
|
.Nd create a KISS TNC from an AX.25 interface
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Ar patty.sock ifname
|
.Op Fl s Ar patty.sock
|
||||||
|
.Fl i Ar ifname
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm
|
.Nm
|
||||||
exposes a
|
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.
|
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.
|
In turn, each frame received by the KISS TNC is sent out to the interface.
|
||||||
.Pp
|
.Pp
|
||||||
Both arguments,
|
The
|
||||||
.Ar patty.sock ,
|
.Fl i Ar ifname
|
||||||
a Unix domain socket to a
|
flag is required and must refer to the name of an interface valid on a running
|
||||||
.Xr pattyd 8
|
.Xr pattyd 8
|
||||||
instance, and an
|
AX.25 daemon. Optionally,
|
||||||
.Ar ifname ,
|
.Op Fl s Ar patty.sock
|
||||||
an interface valid on that AX.25 daemon, are required. When a KISS TNC
|
may be given to specify another path to a Unix domain socket for that daemon.
|
||||||
device is successfully created, the pseudoterminal device name is printed to
|
When a KISS TNC device is successfully created, the pseudoterminal device name
|
||||||
standard output.
|
is printed to standard output.
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr pattyd 8 ,
|
.Xr pattyd 8 ,
|
||||||
.Xr pty 4
|
.Xr pty 4
|
||||||
|
|
39
bin/tncd.c
39
bin/tncd.c
|
@ -13,6 +13,7 @@
|
||||||
#include <sysexits.h>
|
#include <sysexits.h>
|
||||||
|
|
||||||
#include <patty/ax25.h>
|
#include <patty/ax25.h>
|
||||||
|
#include <patty/daemon.h>
|
||||||
#include <patty/print.h>
|
#include <patty/print.h>
|
||||||
|
|
||||||
#include <patty/bin/kiss.h>
|
#include <patty/bin/kiss.h>
|
||||||
|
@ -27,7 +28,7 @@ static void usage(int argc, char **argv, const char *message, ...) {
|
||||||
va_end(args);
|
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);
|
exit(EX_USAGE);
|
||||||
}
|
}
|
||||||
|
@ -158,33 +159,51 @@ error_client_write_socket_request:
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
patty_client *client;
|
||||||
|
|
||||||
struct option opts[] = {
|
struct option opts[] = {
|
||||||
{ NULL, 0, NULL, 0 }
|
{ "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;
|
int fd;
|
||||||
char pty[256];
|
char pty[256];
|
||||||
|
|
||||||
if (getopt_long(argc, argv, "", opts, NULL) >= 0) {
|
while ((ch = getopt_long(argc, argv, "s:i:", opts, &index)) >= 0) {
|
||||||
usage(argc, argv, NULL);
|
switch (ch) {
|
||||||
|
case '?':
|
||||||
|
usage(argc, argv, NULL);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 's': sock = optarg; break;
|
||||||
|
case 'i': ifname = optarg; break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < 3) {
|
if (ifname == NULL) {
|
||||||
usage(argc, argv, "Not enough arguments provided");
|
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",
|
fprintf(stderr, "%s: %s: %s\n",
|
||||||
argv[0], "patty_client_new()", strerror(errno));
|
argv[0], "patty_client_new()", strerror(errno));
|
||||||
|
|
||||||
goto error_client_new;
|
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",
|
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;
|
goto error_pty_promisc;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue