2 * (c) 2013 Nils Faerber, Siegen, Germany
10 #include <sys/select.h>
12 #include <sys/types.h>
13 #include <sys/socket.h>
15 #include <bluetooth/bluetooth.h>
16 #include <bluetooth/l2cap.h>
18 int main(int argc, char **argv)
20 struct sockaddr_l2 addr = { 0 };
21 int s, status, len, i;
28 fprintf(stderr, "usage: %s <bt_addr>\n", argv[0]);
32 strncpy(dest, argv[1], 18);
35 s = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
37 // set the connection parameters (who to connect to)
38 addr.l2_family = AF_BLUETOOTH;
39 addr.l2_psm = htobs(0x1001);
40 str2ba( dest, &addr.l2_bdaddr );
43 status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
47 perror("open socket");
52 fprintf(stderr, "connected\n");
54 if (fcntl(0, F_SETFL, O_NONBLOCK) != 0)
55 perror("stdin nonblock");
56 if (fcntl(s, F_SETFL, O_NONBLOCK) != 0)
57 perror("socket nonblock");
65 status = select(s+1, &infds, NULL, &efds, NULL);
66 // fprintf(stderr, "select = %d\n", status);
68 if (FD_ISSET(0, &infds)) {
69 len = read(0, buf, 240);
71 status = write(s, buf, len);
76 } else if (FD_ISSET(s, &infds)) {
77 len = read(s, buf, 240);
78 // fprintf(stderr, "read = %d\n", len);
80 fprintf(stderr, "%c", buf[i]);
81 // fprintf(stderr, "\n");
82 } else if (FD_ISSET(s, &efds)) {
83 fprintf(stderr, "e on socket\n");
85 fprintf(stderr, "hu?");