1 .\" Copyright (c) 2003 Maksim Yevmenkin <m_evmenkin@yahoo.com>
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 .\" $Id: bluetooth.3,v 1.5 2003/05/20 23:04:30 max Exp $
32 .Nm bt_gethostbyname ,
33 .Nm bt_gethostbyaddr ,
37 .Nm bt_getprotobyname ,
38 .Nm bt_getprotobynumber ,
47 .Nd Bluetooth routines
53 .Fn bt_gethostbyname "const char *name"
55 .Fn bt_gethostbyaddr "const char *addr" "int len" "int type"
57 .Fn bt_gethostent void
59 .Fn bt_sethostent "int stayopen"
61 .Fn bt_endhostent void
63 .Fn bt_getprotobyname "const char *name"
65 .Fn bt_getprotobynumber "int proto"
67 .Fn bt_getprotoent void
69 .Fn bt_setprotoent "int stayopen"
71 .Fn bt_endprotoent void
73 .Fn bt_aton "const char *str" "bdaddr_t *ba"
75 .Fn bt_ntoa "const bdaddr_t *ba" "char *str"
77 .Fn bdaddr_same "const bdaddr_t *a" "const bdaddr_t *b"
79 .Fn bdaddr_any "const bdaddr_t *a"
81 .Fn bdaddr_copy "const bdaddr_t *dst" "const bdaddr_t *src"
89 each return a pointer to an object with the
91 structure describing a Bluetooth host
92 referenced by name or by address, respectively.
99 .Dv NUL Ns -terminated
105 should point to an address which is
109 (i.e., not a Bluetooth BD_ADDR in human readable
114 argument specifies the address family of this address and must be set to
117 The structure returned contains the information obtained from a line in
118 .Pa /etc/bluetooth/hosts
123 function controls whether
124 .Pa /etc/bluetooth/hosts
125 file should stay open after each call to
128 .Fn bt_gethostbyaddr .
131 flag is non-zero, the file will not be closed.
136 .Pa /etc/bluetooth/hosts
141 .Fn bt_getprotobyname
143 .Fn bt_getprotobynumber
144 functions each return a pointer to an object with the
146 structure describing a Bluetooth Protocol Service Multiplexor referenced
147 by name or number, respectively.
152 .Fn bt_getprotobyname
154 .Dv NUL Ns -terminated
155 Bluetooth Protocol Service Multiplexor name.
159 .Fn bt_getprotobynumber
160 should have numeric value of the desired Bluetooth Protocol Service Multiplexor.
162 The structure returned contains the information obtained from a line in
163 .Pa /etc/bluetooth/protocols
168 function controls whether
169 .Pa /etc/bluetooth/protocols
170 file should stay open after each call to
171 .Fn bt_getprotobyname
173 .Fn bt_getprotobynumber .
176 flag is non-zero, the file will not be closed.
181 .Pa /etc/bluetooth/protocols
186 routine interprets the specified character string as a Bluetooth address,
187 placing the address into the structure provided.
188 It returns 1 if the string was successfully interpreted,
189 or 0 if the string is invalid.
193 takes a Bluetooth address and places an
195 string representing the address into the buffer provided.
196 It is up to the caller to ensure that provided buffer has enough space.
197 If no buffer was provided then internal static buffer will be used.
204 are handy shorthand Bluetooth address utility functions.
207 function will test if two provided BD_ADDRs are the same.
210 function will test if provided BD_ADDR is
215 function will copy provided
217 BD_ADDR into provided
221 .Bl -tag -width ".Pa /etc/bluetooth/hosts" -compact
222 .It Pa /etc/bluetooth/hosts
223 .It Pa /etc/bluetooth/protocols
226 Print out the hostname associated with a specific BD_ADDR:
227 .Bd -literal -offset indent
228 const char *bdstr = "00:01:02:03:04:05";
232 if (!bt_aton(bdstr, &bd))
233 errx(1, "can't parse BD_ADDR %s", bdstr);
235 if ((hp = bt_gethostbyaddr((const char *)&bd,
236 sizeof(bd), AF_BLUETOOTH)) == NULL)
237 errx(1, "no name associated with %s", bdstr);
239 printf("name associated with %s is %s\en", bdstr, hp->h_name);
242 Error return status from
247 is indicated by return of a
252 may then be checked to see whether this is a temporary failure
253 or an invalid or unknown host.
256 can be used to print an error message describing the failure.
261 it is printed, followed by a colon and a space.
262 The error message is printed with a trailing newline.
266 can have the following values:
267 .Bl -tag -width ".Dv HOST_NOT_FOUND"
268 .It Dv HOST_NOT_FOUND
269 No such host is known.
271 Some unexpected server failure was encountered.
272 This is a non-recoverable error.
277 .Fn bt_getprotobyname
279 .Fn bt_getprotobynumber
284 .Xr gethostbyaddr 3 ,
285 .Xr gethostbyname 3 ,
286 .Xr getprotobyname 3 ,
287 .Xr getprotobynumber 3 ,
294 function reads the next line of
295 .Pa /etc/bluetooth/hosts ,
296 opening the file if necessary.
300 function opens and/or rewinds the
301 .Pa /etc/bluetooth/hosts
306 function reads the next line of
307 .Pa /etc/bluetooth/protocols ,
308 opening the file if necessary.
312 function opens and/or rewinds the
313 .Pa /etc/bluetooth/protocols
316 .An Maksim Yevmenkin Aq m_evmenkin@yahoo.com
318 These functions use static data storage;
319 if the data is needed for future use, it should be
320 copied before any subsequent calls overwrite it.