From 41bb0e8fd2568243020852e22a6d176bccfa60cd Mon Sep 17 00:00:00 2001 From: emax Date: Sun, 12 Oct 2003 22:04:24 +0000 Subject: Update Bluetooth code. Reviewed by: M. Warner Losh ; John Hay Approved by: M. Warner Losh (mentor) --- usr.sbin/bluetooth/l2control/l2control.c | 47 ++++++++++++++------------------ 1 file changed, 20 insertions(+), 27 deletions(-) (limited to 'usr.sbin/bluetooth/l2control/l2control.c') diff --git a/usr.sbin/bluetooth/l2control/l2control.c b/usr.sbin/bluetooth/l2control/l2control.c index a259657..585021c 100644 --- a/usr.sbin/bluetooth/l2control/l2control.c +++ b/usr.sbin/bluetooth/l2control/l2control.c @@ -25,19 +25,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: l2control.c,v 1.3 2003/04/27 19:45:34 max Exp $ + * $Id: l2control.c,v 1.6 2003/09/05 00:38:25 max Exp $ * $FreeBSD$ */ -#include -#include -#include #include +#include #include #include -#include -#include -#include #include #include #include @@ -52,6 +47,9 @@ static void print_l2cap_command (struct l2cap_command *); static void usage (void); /* Main */ + +int numeric_bdaddr = 0; + int main(int argc, char *argv[]) { @@ -61,24 +59,22 @@ main(int argc, char *argv[]) memset(&bdaddr, 0, sizeof(bdaddr)); /* Process command line arguments */ - while ((n = getopt(argc, argv, "a:h")) != -1) { + while ((n = getopt(argc, argv, "a:nh")) != -1) { switch (n) { - case 'a': { - int a0, a1, a2, a3, a4, a5; + case 'a': + if (!bt_aton(optarg, &bdaddr)) { + struct hostent *he = NULL; + + if ((he = bt_gethostbyname(optarg)) == NULL) + errx(1, "%s: %s", optarg, hstrerror(h_errno)); - if (sscanf(optarg, "%x:%x:%x:%x:%x:%x", - &a5, &a4, &a3, &a2, &a1, &a0) != 6) { - usage(); - break; + memcpy(&bdaddr, he->h_addr, sizeof(bdaddr)); } + break; - bdaddr.b[0] = (a0 & 0xff); - bdaddr.b[1] = (a1 & 0xff); - bdaddr.b[2] = (a2 & 0xff); - bdaddr.b[3] = (a3 & 0xff); - bdaddr.b[4] = (a4 & 0xff); - bdaddr.b[5] = (a5 & 0xff); - } break; + case 'n': + numeric_bdaddr = 1; + break; case 'h': default: @@ -144,10 +140,7 @@ do_l2cap_command(bdaddr_p bdaddr, int argc, char **argv) if (bind(s, (struct sockaddr *) &sa, sizeof(sa)) < 0) err(2, -"Could not bind socket, bdaddr=%x:%x:%x:%x:%x:%x", - sa.l2cap_bdaddr.b[5], sa.l2cap_bdaddr.b[4], - sa.l2cap_bdaddr.b[3], sa.l2cap_bdaddr.b[2], - sa.l2cap_bdaddr.b[1], sa.l2cap_bdaddr.b[0]); +"Could not bind socket, bdaddr=%s", bt_ntoa(&sa.l2cap_bdaddr, NULL)); e = 0x0ffff; if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &e, sizeof(e)) < 0) @@ -200,7 +193,7 @@ find_l2cap_command(char const *command, struct l2cap_command *category) return (NULL); } /* find_l2cap_command */ -/* Try to find command in specified category */ +/* Print commands in specified category */ static void print_l2cap_command(struct l2cap_command *category) { @@ -214,7 +207,7 @@ print_l2cap_command(struct l2cap_command *category) static void usage(void) { - fprintf(stdout, "Usage: l2control -a BD_ADDR [-h] cmd [p1] [..]]\n"); + fprintf(stdout, "Usage: l2control -a BD_ADDR [-n] [-h] cmd [p1] [..]]\n"); exit(255); } /* usage */ -- cgit v1.1