]> rtime.felk.cvut.cz Git - tiny-bt.git/blob - testf/sockfree.c
Version from David Plotek's bachelor thesis CD
[tiny-bt.git] / testf / sockfree.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/ioctl.h>
4 #include <unistd.h>
5 #include<sys/socket.h>
6 #include<asm/types.h>
7 #include "hcidriver.h"
8
9 #define BTPROTO_HCI     1
10
11
12
13 int main(void){
14         int sock,sock2;
15         sockaddr_hci address,address2;
16
17         if((sock=socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI))<0){ 
18                 printf("first socket: %d wasn't created\n",sock);       
19    
20         }
21
22         if((sock2=socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI))<0){ 
23                 printf("second socket: %d wasn't created\n",sock2);
24         }
25
26         memset(&address,0,sizeof(address));
27         address.hci_family=AF_BLUETOOTH;
28         address.dev_id=0;
29
30         memset(&address2,0,sizeof(address2));
31         address2.hci_family=AF_BLUETOOTH;
32         address2.dev_id=1;
33
34         if(bind(sock,(struct sockaddr *) &address, sizeof(address))<0){
35                 printf("Socket: %d wasn't binded\n",sock);      
36                 close(sock);
37                 return -1;
38                 }
39         printf("Socket: %d was binded\n",sock);
40         
41         if(bind(sock2,(struct sockaddr *) &address2, sizeof(address2))<0){
42                 printf("Socket: %d wasn't binded\n",sock2);     
43                 close(sock2);
44                 return -1;
45                 }
46         printf("Socket: %d was binded\n",sock2);
47
48                 
49         printf("Value of sock is now %d \n",sock);
50         printf("Value of sock2 is now %d \n",sock2);
51         close(sock);
52         printf("Socket: %d was closed\n",sock); 
53         return 0;
54 }
55