1 #include "poc_test.h"
2 
3 #include <errno.h>
4 #include <fcntl.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <sys/socket.h>
8 #include <unistd.h>
9 
main(int argc,char * argv[])10 int main(int argc, char* argv[]) {
11   VtsHostInput host_input = ParseVtsHostFlags(argc, argv);
12   struct sockaddr sa;
13   socklen_t len, i;
14   int fd;
15 
16   fd = socket(AF_BLUETOOTH, SOCK_STREAM, 3);
17   if (fd == -1) {
18     printf("[-] can't create socket: %s\n", strerror(errno));
19     return POC_TEST_SKIP;
20   }
21 
22   memset(&sa, 0, sizeof(sa));
23   sa.sa_family = AF_BLUETOOTH;
24 
25   if (bind(fd, &sa, 2)) {
26     printf("[-] can't bind socket: %s\n", strerror(errno));
27     close(fd);
28     return POC_TEST_SKIP;
29   }
30 
31   len = sizeof(sa);
32   if (getsockname(fd, &sa, &len)) {
33     printf("[-] can't getsockname for socket: %s\n", strerror(errno));
34     close(fd);
35     return POC_TEST_SKIP;
36   } else {
37     printf("[+] getsockname return len = %d\n", len);
38   }
39 
40   for (i = 0; i < len; i++) {
41     printf("%02x ", ((unsigned char*)&sa)[i]);
42   }
43   printf("\n");
44 
45   for (i = 1; i < len; i++) {
46     if (((unsigned char*)&sa)[i] != 0) {
47       return POC_TEST_FAIL;
48     }
49   }
50 
51   close(fd);
52   return POC_TEST_PASS;
53 }
54