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
|
$NetBSD: patch-ab,v 1.1.1.1 2006/07/02 18:18:34 xtraeme Exp $
--- main.c.orig 2004-12-24 00:09:48.000000000 +0100
+++ main.c 2006-07-02 19:48:19.000000000 +0200
@@ -90,8 +90,13 @@
/* Prepare context */
memset(&context, 0, sizeof(context));
+#ifdef __NetBSD__
+ context.addr.bt_len = sizeof(context.addr.bt_len);
+ context.addr.bt_family = AF_BLUETOOTH;
+#else
context.addr.rfcomm_len = sizeof(context.addr.rfcomm_len);
context.addr.rfcomm_family = AF_BLUETOOTH;
+#endif
context.tfd = context.sfd = -1;
context.detach = 1;
@@ -148,15 +153,23 @@
while ((n = getopt(argc, argv, "a:A:cC:dDfhnr:Ssu:")) != -1) {
switch (n) {
case 'a':
+#ifdef __NetBSD__
+ if (!bt_aton(optarg, &context.addr.bt_bdaddr)) {
+#else
if (!bt_aton(optarg, &context.addr.rfcomm_bdaddr)) {
+#endif
struct hostent *he = bt_gethostbyname(optarg);
if (he == NULL)
errx(1, "%s: %s", optarg,
hstrerror(h_errno));
-
+#ifdef __NetBSD__
+ memcpy(&context.addr.bt_bdaddr, he->h_addr,
+ sizeof(context.addr.bt_bdaddr));
+#else
memcpy(&context.addr.rfcomm_bdaddr, he->h_addr,
sizeof(context.addr.rfcomm_bdaddr));
+#endif
}
break;
@@ -178,11 +191,19 @@
break;
case 'C': /* channel to listen on or connect to */
+#ifdef __NetBSD__
+ context.addr.bt_channel = strtoul(optarg, &ep, 10);
+#else
context.addr.rfcomm_channel = strtoul(optarg, &ep, 10);
+#endif
if (*ep != '\0') {
+#ifdef __NetBSD__
+ context.addr.bt_channel = 0;
+#else
context.addr.rfcomm_channel = 0;
+#endif
- switch (tolower(optarg[0])) {
+ switch (tolower((unsigned char)optarg[0])) {
case 'i': /* IrMC */
service = SDP_SERVICE_CLASS_IR_MC_SYNC;
break;
@@ -254,10 +275,25 @@
argv += optind;
if (!context.server) {
+#ifdef __NetBSD__
+ if (memcmp(&context.addr.bt_bdaddr,
+ BDADDR_ANY, sizeof(context.addr.bt_bdaddr)) == 0)
+ errx(1, "Must specify server BD_ADDR");
+
+ /* Check channel, if was not set then obtain it via SDP */
+ if (context.addr.bt_channel == 0 && service != 0) {
+ int channel;
+
+ if (rfcomm_channel_lookup(NULL,
+ &context.addr.bt_bdaddr,
+ service, &channel, &n) != 0)
+ errx(1, "Could not obtain RFCOMM channel");
+
+ context.addr.bt_channel = (u_int8_t) channel;
+#else
if (memcmp(&context.addr.rfcomm_bdaddr,
NG_HCI_BDADDR_ANY, sizeof(context.addr.rfcomm_bdaddr)) == 0)
errx(1, "Must specify server BD_ADDR");
-
/* Check channel, if was not set then obtain it via SDP */
if (context.addr.rfcomm_channel == 0 && service != 0) {
int channel;
@@ -268,13 +304,21 @@
errc(1, n, "Could not obtain RFCOMM channel");
context.addr.rfcomm_channel = (u_int8_t) channel;
+#endif
}
}
+#ifdef __NetBSD__
+ if (context.addr.bt_channel <= 0 ||
+ context.addr.bt_channel > 30)
+ errx(1, "Invalid RFCOMM channel %d",
+ context.addr.bt_channel);
+#else
if (context.addr.rfcomm_channel <= 0 ||
context.addr.rfcomm_channel > 30)
errx(1, "Invalid RFCOMM channel %d",
context.addr.rfcomm_channel);
+#endif
/* Detach server (if required) */
if (context.server && context.detach) {
|