summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authoremax <emax@FreeBSD.org>2004-09-30 21:05:17 +0000
committeremax <emax@FreeBSD.org>2004-09-30 21:05:17 +0000
commit3a45dd66e4017f4b2774688bb2985ac371ad0d28 (patch)
treefad4780d7dc0efb38d358c16c360d354bf9c41b8 /usr.bin
parente7c7f8c03c7b15f72f356908f9692cacc5d8534e (diff)
downloadFreeBSD-src-3a45dd66e4017f4b2774688bb2985ac371ad0d28.zip
FreeBSD-src-3a45dd66e4017f4b2774688bb2985ac371ad0d28.tar.gz
Make -t <tty> optional. If not specified use stdin/stdout.
Document this. These changes make it possible to write something like set device "!/usr/bin/rfcomm_sppd -a BD_ADDR" inside the /etc/ppp/ppp.conf file. Very convenient for the users :) Submitted by: Konstantin Stepanenkov <kstepanenkov AT oilspace DOT com> MFC after: 3 days
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.113
-rw-r--r--usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.c36
2 files changed, 35 insertions, 14 deletions
diff --git a/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.1 b/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.1
index 019c2cd..d4810ef 100644
--- a/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.1
+++ b/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.1
@@ -36,7 +36,7 @@
.Op Fl bh
.Fl a Ar address
.Fl c Ar channel
-.Fl t Ar tty
+.Op Fl t Ar tty
.Sh DESCRIPTION
The
.Nm
@@ -47,9 +47,12 @@ server and
.Ar channel .
Once connection is established, the
.Nm
-utility provides access to the server's remote serial port via
+utility provides access to the server's remote serial port via stdin/stdout
+or via
.Xr pty 4
-interface.
+interface if
+.Fl t
+option was specified.
.Pp
The
.Nm
@@ -87,6 +90,10 @@ the server.
Display usage message and exit.
.It Fl t Ar tty
Slave pseudo tty name.
+If not set stdin/stdout will be used.
+This option is required if
+.Fl b
+option was specified.
.El
.Sh EXAMPLES
.Dl "rfcomm_sppd -a 00:01:02:03:04:05 -c 1 -t /dev/ttyp1"
diff --git a/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.c b/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.c
index 8b811da..40ad502 100644
--- a/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.c
+++ b/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.c
@@ -70,7 +70,7 @@ main(int argc, char *argv[])
struct sigaction sa;
struct sockaddr_rfcomm ra;
bdaddr_t addr;
- int n, background, channel, s, amaster, aslave;
+ int n, background, channel, s, amaster, aslave, fd;
fd_set rfd;
char *tty = NULL, buf[SPPD_BUFFER_SIZE];
@@ -114,7 +114,7 @@ main(int argc, char *argv[])
}
/* Check if we have everything we need */
- if (tty == NULL || memcmp(&addr, NG_HCI_BDADDR_ANY, sizeof(addr)) == 0)
+ if (memcmp(&addr, NG_HCI_BDADDR_ANY, sizeof(addr)) == 0)
usage();
/* NOT REACHED */
@@ -146,8 +146,19 @@ main(int argc, char *argv[])
errx(1, "Invalid RFCOMM channel number %d", channel);
/* Open TTYs */
- if (sppd_ttys_open(tty, &amaster, &aslave) < 0)
- exit(1);
+ if (tty == NULL) {
+ if (background)
+ usage();
+
+ amaster = STDIN_FILENO;
+ fd = STDOUT_FILENO;
+ } else {
+ if (sppd_ttys_open(tty, &amaster, &aslave) < 0)
+ exit(1);
+
+ fd = amaster;
+ }
+
/* Open RFCOMM connection */
memset(&ra, 0, sizeof(ra));
@@ -186,7 +197,7 @@ main(int argc, char *argv[])
}
openlog(SPPD_IDENT, LOG_NDELAY|LOG_PERROR|LOG_PID, LOG_DAEMON);
- syslog(LOG_INFO, "Starting on %s...", tty);
+ syslog(LOG_INFO, "Starting on %s...", (tty != NULL)? tty : "stdin/stdout");
for (done = 0; !done; ) {
FD_ZERO(&rfd);
@@ -236,21 +247,24 @@ main(int argc, char *argv[])
if (n == 0)
break;
- if (sppd_write(amaster, buf, n) < 0) {
+ if (sppd_write(fd, buf, n) < 0) {
syslog(LOG_ERR, "Could not write to master " \
"pty, fd=%d, size=%d. %s",
- amaster, n, strerror(errno));
+ fd, n, strerror(errno));
exit(1);
}
}
}
- syslog(LOG_INFO, "Completed on %s", tty);
+ syslog(LOG_INFO, "Completed on %s", (tty != NULL)? tty : "stdin/stdout");
closelog();
close(s);
- close(aslave);
- close(amaster);
+
+ if (tty != NULL) {
+ close(aslave);
+ close(amaster);
+ }
return (0);
}
@@ -394,7 +408,7 @@ usage(void)
"\t-a address Address to connect to (required)\n" \
"\t-b Run in background\n" \
"\t-c channel RFCOMM channel to connect to\n" \
-"\t-t tty TTY name\n" \
+"\t-t tty TTY name (required in background mode)\n" \
"\t-h Display this message\n", SPPD_IDENT);
exit(255);
OpenPOWER on IntegriCloud