summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2025-01-09 09:38:06 +0100
committerMitja Felicijan <mitja.felicijan@gmail.com>2025-01-09 09:38:06 +0100
commit956db3204ad0b70424e4b834a00c785bec379a96 (patch)
treecaab1d925ac82ebeb2bf380a0f28fc28d113596d
parentddfadc840cb02530e07ca33b83138ae1a5034227 (diff)
downloadprobe-956db3204ad0b70424e4b834a00c785bec379a96.tar.gz
Added C Bluetooth scan example
-rw-r--r--c-bluetooth/connect.c47
-rw-r--r--c-bluetooth/scan.c2
2 files changed, 1 insertions, 48 deletions
diff --git a/c-bluetooth/connect.c b/c-bluetooth/connect.c
deleted file mode 100644
index 17fe433..0000000
--- a/c-bluetooth/connect.c
+++ /dev/null
@@ -1,47 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <bluetooth/bluetooth.h>
-#include <bluetooth/hci.h>
-#include <bluetooth/hci_lib.h>
-
-int main(int argc, char **argv) {
- inquiry_info *ii = NULL;
- int max_rsp, num_rsp;
- int dev_id, sock, len, flags;
- int i;
- char addr[19] = { 0 };
- char name[248] = { 0 };
-
- dev_id = hci_get_route(NULL);
- sock = hci_open_dev( dev_id );
- if (dev_id < 0 || sock < 0) {
- perror("opening socket");
- exit(1);
- }
-
- len = 8;
- max_rsp = 255;
- flags = IREQ_CACHE_FLUSH;
- ii = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info));
-
- num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
- if( num_rsp < 0 ) {
- perror("hci_inquiry");
- }
-
- for (i = 0; i < num_rsp; i++) {
- ba2str(&(ii+i)->bdaddr, addr);
- memset(name, 0, sizeof(name));
- if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name), name, 0) < 0) {
- strcpy(name, "[unknown]");
- }
- printf("%s %s\n", addr, name);
- }
-
- free(ii);
- close(sock);
- return 0;
-}
-
diff --git a/c-bluetooth/scan.c b/c-bluetooth/scan.c
index 30cfe36..17fe433 100644
--- a/c-bluetooth/scan.c
+++ b/c-bluetooth/scan.c
@@ -27,7 +27,7 @@ int main(int argc, char **argv) {
ii = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info));
num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
- if(num_rsp < 0) {
+ if( num_rsp < 0 ) {
perror("hci_inquiry");
}