1 /* $NetBSD: sdpquery.c,v 1.3 2007/03/30 21:25:00 plunky Exp $ */
2 /* $DragonFly: src/usr.bin/sdpquery/sdpquery.c,v 1.1 2008/02/08 14:06:25 hasso Exp $ */
5 * Copyright (c) 2006 Itronix Inc.
8 * Written by Iain Hibbert for Itronix Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of Itronix Inc. may not be used to endorse
19 * or promote products derived from this software without specific
20 * prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
26 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 * ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
36 #include <bluetooth.h>
47 static void usage(void);
49 const char *control_socket
;
51 static struct command
{
53 int (*handler
)(bdaddr_t
*, bdaddr_t
*, int, char const **);
56 { "Browse", do_sdp_browse
, "[UUID]" },
57 { "Search", do_sdp_search
, "<service>" },
62 main(int argc
, char *argv
[])
64 bdaddr_t laddr
, raddr
;
68 bdaddr_copy(&laddr
, BDADDR_ANY
);
69 bdaddr_copy(&raddr
, BDADDR_ANY
);
70 control_socket
= NULL
;
73 while ((ch
= getopt(argc
, argv
, "a:c:d:hl")) != -1) {
75 case 'a': /* remote address */
76 if (!bt_aton(optarg
, &raddr
)) {
77 struct hostent
*he
= NULL
;
79 if ((he
= bt_gethostbyname(optarg
)) == NULL
)
80 errx(EXIT_FAILURE
, "%s: %s",
81 optarg
, hstrerror(h_errno
));
83 bdaddr_copy(&raddr
, (bdaddr_t
*)he
->h_addr
);
88 control_socket
= optarg
;
91 case 'd': /* local device address */
92 if (!bt_devaddr(optarg
, &laddr
))
93 err(EXIT_FAILURE
, "%s", optarg
);
97 case 'l': /* local sdpd */
115 || (bdaddr_any(&raddr
) && !local
)
116 || (!bdaddr_any(&raddr
) && local
))
119 for (cmd
= commands
; cmd
->command
!= NULL
; cmd
++) {
120 if (strcasecmp(*argv
, cmd
->command
) == 0)
121 return (*cmd
->handler
)(&laddr
, &raddr
, --argc
, (char const **)++argv
);
124 errx(EXIT_FAILURE
, "%s: Unknown Command", *argv
);
134 "Usage: %s [-d device] -a bdaddr <command> [parameters..]\n"
135 " %s [-c path] -l <command> [parameters..]\n"
136 "\n", getprogname(), getprogname());
140 "\t-a bdaddr remote address\n"
141 "\t-c path path to control socket\n"
142 "\t-d device local device address\n"
143 "\t-l connect to the local SDP server via control socket\n"
144 "\t-h display usage and quit\n"
148 for (cmd
= commands
; cmd
->command
!= NULL
; cmd
++)
149 fprintf(stderr
, "\t%-13s%s\n", cmd
->command
, cmd
->usage
);