sock_shutdown_bug_rfcomm.c revision 10d31b957a35d4ac084be33b0f136568039c9c14
1/*
2** Copyright 2009 The Android Open Source Project
3**
4** Licensed under the Apache License, Version 2.0 (the "License");
5** you may not use this file except in compliance with the License.
6** You may obtain a copy of the License at
7**
8**     http://www.apache.org/licenses/LICENSE-2.0
9**
10** Unless required by applicable law or agreed to in writing, software
11** distributed under the License is distributed on an "AS IS" BASIS,
12** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13** See the License for the specific language governing permissions and
14** limitations under the License.
15*/
16
17#include <stdio.h>
18#include <stdlib.h>
19#include <unistd.h>
20#include <sys/socket.h>
21#include <fcntl.h>
22
23#include <bluetooth/bluetooth.h>
24#include <bluetooth/rfcomm.h>
25
26int main(int argc, char **argv) {
27   int fd;
28   int ret;
29   long flags;
30   struct sockaddr_rc addr;
31
32   addr.rc_family = AF_BLUETOOTH;
33   addr.rc_channel = 19;
34   str2ba("00:17:E8:2C:A8:00", &addr.rc_bdaddr);
35
36   fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
37   flags = fcntl(fd, F_GETFL);
38   fcntl(fd, F_SETFL, flags | O_NONBLOCK);
39
40   connect(fd, (struct sockaddr *)&addr, sizeof(addr));
41
42   sleep(2);
43   shutdown(fd, SHUT_RDWR);
44   sleep(2);
45   close(fd);
46   return 0;
47}
48