1 /* $NetBSD: sdpquery.c,v 1.4 2008/07/21 14:19:26 lukem Exp $ */
4 * Copyright (c) 2006 Itronix Inc.
7 * Written by Iain Hibbert for Itronix Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of Itronix Inc. may not be used to endorse
18 * or promote products derived from this software without specific
19 * prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/cdefs.h>
35 __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc.\
36 Copyright (c) 2006 Itronix, Inc.\
37 All rights reserved.");
38 __RCSID("$NetBSD: sdpquery.c,v 1.4 2008/07/21 14:19:26 lukem Exp $");
40 #include <bluetooth.h>
51 static void usage(void);
53 const char *control_socket
;
58 bool Nflag
; /* numerical output */
59 bool Rflag
; /* uncooked output */
60 bool Xflag
; /* hex output */
62 static struct command
{
64 int (*handler
)(int, char const **);
67 { "Browse", do_sdp_browse
, "[group]" },
68 { "Record", do_sdp_record
, "handle [handle...]" },
69 { "Search", do_sdp_search
, "uuid [uuid...]" },
74 main(int argc
, char *argv
[])
79 bdaddr_copy(&local_addr
, BDADDR_ANY
);
80 bdaddr_copy(&remote_addr
, BDADDR_ANY
);
81 control_socket
= NULL
;
82 Nflag
= Rflag
= Xflag
= false;
85 while ((ch
= getopt(argc
, argv
, "a:c:d:hlNRX")) != -1) {
87 case 'a': /* remote address */
88 if (!bt_aton(optarg
, &remote_addr
)) {
89 struct hostent
*he
= NULL
;
91 if ((he
= bt_gethostbyname(optarg
)) == NULL
)
92 errx(EXIT_FAILURE
, "%s: %s",
93 optarg
, hstrerror(h_errno
));
95 bdaddr_copy(&remote_addr
, (bdaddr_t
*)he
->h_addr
);
100 control_socket
= optarg
;
103 case 'd': /* local device address */
104 if (!bt_devaddr(optarg
, &local_addr
))
105 err(EXIT_FAILURE
, "%s", optarg
);
109 case 'l': /* local sdpd */
113 case 'N': /* Numerical output */
117 case 'R': /* Raw output */
121 case 'X': /* Hex output */
139 || (bdaddr_any(&remote_addr
) && !local
)
140 || (!bdaddr_any(&remote_addr
) && local
))
143 for (cmd
= commands
; cmd
->command
!= NULL
; cmd
++) {
144 if (strcasecmp(*argv
, cmd
->command
) == 0)
145 return (*cmd
->handler
)(--argc
, (char const **)++argv
);
158 "Usage: %s [-NRX] [-d device] -a bdaddr <command> [parameters..]\n"
159 " %s [-NRX] [-c path] -l <command> [parameters..]\n"
160 "\n", getprogname(), getprogname());
164 "\t-a bdaddr remote address\n"
165 "\t-c path path to control socket\n"
166 "\t-d device local device address\n"
167 "\t-l query local SDP server daemon\n"
168 "\t-N print numerical values\n"
169 "\t-R print raw attribute values\n"
170 "\t-X print attribute values in hex\n"
174 for (cmd
= commands
; cmd
->command
!= NULL
; cmd
++)
175 fprintf(stderr
, "\t%-13s%s\n", cmd
->command
, cmd
->usage
);