summaryrefslogtreecommitdiffstats
path: root/lib/libbluetooth/bluetooth.3
blob: d6adb260392f8fe3de4bce7540fba75036693f70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
.\" Copyright (c) 2003 Maksim Yevmenkin <m_evmenkin@yahoo.com>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $Id: bluetooth.3,v 1.5 2003/05/20 23:04:30 max Exp $
.\" $FreeBSD$
.\"
.Dd May 7, 2003
.Dt BLUETOOTH 3
.Os
.Sh NAME
.Nm bt_gethostbyname ,
.Nm bt_gethostbyaddr ,
.Nm bt_gethostent ,
.Nm bt_sethostent ,
.Nm bt_endhostent ,
.Nm bt_getprotobyname ,
.Nm bt_getprotobynumber ,
.Nm bt_getprotoent ,
.Nm bt_setprotoent ,
.Nm bt_endprotoent ,
.Nm bt_aton ,
.Nm bt_ntoa
.Nd Bluetooth routines
.Sh LIBRARY
.Lb libbluetooth
.Sh SYNOPSIS
.In bluetooth.h
.Ft struct hostent *
.Fn bt_gethostbyname "const char *name"
.Ft struct hostent *
.Fn bt_gethostbyaddr "const char *addr" "int len" "int type"
.Ft struct hostent *
.Fn bt_gethostent void
.Ft void
.Fn bt_sethostent "int stayopen"
.Ft void
.Fn bt_endhostent void
.Ft struct protoent *
.Fn bt_getprotobyname "const char *name"
.Ft struct protoent *
.Fn bt_getprotobynumber "int proto"
.Ft struct protoent *
.Fn bt_getprotoent void
.Ft void
.Fn bt_setprotoent "int stayopen"
.Ft void
.Fn bt_endprotoent void
.Ft int
.Fn bt_aton "const char *str" "bdaddr_t *ba"
.Ft const char *
.Fn bt_ntoa "const bdaddr_t *ba" "char *str"
.Sh DESCRIPTION
The
.Fn bt_gethostent ,
.Fn bt_gethostbyname
and
.Fn bt_gethostbyaddr
functions
each return a pointer to an object with the
.Vt hostent
structure describing a Bluetooth host
referenced by name or by address, respectively.
.Pp
The
.Fa name
argument passed to
.Fn bt_gethostbyname
should point to a
.Dv NUL Ns -terminated
hostname.
The
.Fa addr
argument passed to
.Fn bt_gethostbyaddr
should point to an address which is
.Fa len
bytes long,
in binary form
(i.e., not a Bluetooth BD_ADDR in human readable
.Tn ASCII
form).
The
.Fa type
argument specifies the address family of this address and must be set to
.Dv AF_BLUETOOTH .
.Pp
The structure returned contains the information obtained from a line in
.Pa /etc/bluetooth/hosts
file.
.Pp
The
.Fn bt_sethostent
function controls whether
.Pa /etc/bluetooth/hosts
file should stay open after each call to
.Fn bt_gethostbyname
or
.Fn bt_gethostbyaddr .
If the
.Fa stayopen
flag is non-zero, the file will not be closed.
.Pp
The
.Fn bt_endhostent
function closes the
.Pa /etc/bluetooth/hosts
file.
.Pp
The
.Fn bt_getprotoent ,
.Fn bt_getprotobyname
and
.Fn bt_getprotobynumber
functions each return a pointer to an object with the
.Vt protoent
structure describing a Bluetooth Protocol Service Multiplexor referenced
by name or number, respectively.
.Pp
The
.Fa name
argument passed to
.Fn bt_getprotobyname
should point to a
.Dv NUL Ns -terminated
Bluetooth Protocol Service Multiplexor name.
The
.Fa proto
argument passed to
.Fn bt_getprotobynumber
should have numeric value of the desired Bluetooth Protocol Service Multiplexor.
.Pp
The structure returned contains the information obtained from a line in
.Pa /etc/bluetooth/protocols
file.
.Pp
The
.Fn bt_setprotoent
function controls whether
.Pa /etc/bluetooth/protocols
file should stay open after each call to
.Fn bt_getprotobyname
or
.Fn bt_getprotobynumber .
If the
.Fa stayopen
flag is non-zero, the file will not be closed.
.Pp
The
.Fn bt_endprotoent
function closes the
.Pa /etc/bluetooth/protocols
file.
.Pp
The
.Fn bt_aton
routine interprets the specified character string as a Bluetooth address,
placing the address into the structure provided.
It returns 1 if the string was successfully interpreted,
or 0 if the string is invalid.
.Pp
The routine
.Fn bt_ntoa
takes a Bluetooth address and places an
.Tn ASCII
string representing the address into the buffer provided.
It is up to the caller to ensure that provided buffer has enough space.
If no buffer was provided then internal static buffer will be used.
.Sh FILES
.Bl -tag -width ".Pa /etc/bluetooth/hosts" -compact
.It Pa /etc/bluetooth/hosts
.It Pa /etc/bluetooth/protocols
.El
.Sh EXAMPLES
Print out the hostname associated with a specific BD_ADDR:
.Bd -literal -offset indent
const char *bdstr = "00:01:02:03:04:05";
bdaddr_t bd;
struct hostent *hp;

if (!bt_aton(bdstr, &bd))
	errx(1, "can't parse BD_ADDR %s", bdstr);

if ((hp = bt_gethostbyaddr((const char *)&bd,
    sizeof(bd), AF_BLUETOOTH)) == NULL)
	errx(1, "no name associated with %s", bdstr);

printf("name associated with %s is %s\en", bdstr, hp->h_name);
.Ed
.Sh DIAGNOSTICS
Error return status from
.Fn bt_gethostent ,
.Fn bt_gethostbyname
and
.Fn bt_gethostbyaddr
is indicated by return of a
.Dv NULL
pointer.
The external integer
.Va h_errno
may then be checked to see whether this is a temporary failure
or an invalid or unknown host.
The routine
.Xr herror 3
can be used to print an error message describing the failure.
If its argument
.Fa string
is
.Pf non- Dv NULL ,
it is printed, followed by a colon and a space.
The error message is printed with a trailing newline.
.Pp
The variable
.Va h_errno
can have the following values:
.Bl -tag -width ".Dv HOST_NOT_FOUND"
.It Dv HOST_NOT_FOUND
No such host is known.
.It Dv NO_RECOVERY
Some unexpected server failure was encountered.
This is a non-recoverable error.
.El
.Pp
The
.Fn bt_getprotoent ,
.Fn bt_getprotobyname
and
.Fn bt_getprotobynumber
return
.Dv NULL
on EOF or error.
.Sh SEE ALSO
.Xr gethostbyaddr 3 ,
.Xr gethostbyname 3 ,
.Xr getprotobyname 3 ,
.Xr getprotobynumber 3 ,
.Xr herror 3 ,
.Xr inet_aton 3 ,
.Xr inet_ntoa 3
.Sh CAVEAT
The
.Fn bt_gethostent
function reads the next line of
.Pa /etc/bluetooth/hosts ,
opening the file if necessary.
.Pp
The
.Fn bt_sethostent
function opens and/or rewinds the
.Pa /etc/bluetooth/hosts
file.
.Pp
The
.Fn bt_getprotoent
function reads the next line of
.Pa /etc/bluetooth/protocols ,
opening the file if necessary.
.Pp
The
.Fn bt_setprotoent
function opens and/or rewinds the
.Pa /etc/bluetooth/protocols
file.
.Sh AUTHORS
.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com
.Sh BUGS
These functions use static data storage;
if the data is needed for future use, it should be
copied before any subsequent calls overwrite it.
OpenPOWER on IntegriCloud