diff --git a/bin/tncd.8 b/bin/tncd.8 index 63f5020..1e7f543 100644 --- a/bin/tncd.8 +++ b/bin/tncd.8 @@ -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 diff --git a/bin/tncd.c b/bin/tncd.c index e5475a7..20425cb 100644 --- a/bin/tncd.c +++ b/bin/tncd.c @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -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[] = { - { 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; char pty[256]; - if (getopt_long(argc, argv, "", opts, NULL) >= 0) { - usage(argc, argv, NULL); + 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; }