Linux平台sdp discovery编程
2016-02-12 00:47
507 查看
http://www.datenterrorist.de/devel/sdpbrowse.c
编译方法(https://people.csail.mit.edu/albert/bluez-intro/c404.html):
ubuntu安装依赖库(https://people.csail.mit.edu/albert/bluez-intro/x45.html)
运行:
![](http://img.blog.csdn.net/20160212004643946?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
/* BlueZ example code to read the services of a remote sdp server. Programmed by Bastian Ballmann http://www.geektown.de Compile with gcc -lbluetooth -lsdp <executable> <source> */ #include <bluetooth/sdp.h> #include <bluetooth/sdp_lib.h> int main(int argc, char *argv[]) { bdaddr_t bdaddr; sdp_list_t *attrid, *search, *seq; uint32_t range = 0x0000ffff; sdp_session_t *sess; struct hci_dev_info di; uuid_t root_uuid; if(argc < 2) { printf("%s <btaddr>\n", argv[0]); exit(0); } // Get local bluetooth address if(hci_devinfo(0, &di) < 0) { perror("HCI device info failed"); exit(1); } str2ba(argv[1],&bdaddr); // Connect to remote SDP server sess = sdp_connect(&di.bdaddr, &bdaddr, SDP_RETRY_IF_BUSY); if(!sess) { perror("Failed to connect to SDP server"); exit(1); } printf("Browsing %s ...\n", argv[1]); // Build linked lists sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP); attrid = sdp_list_append(0, &range); search = sdp_list_append(0, &root_uuid); // Get a linked list of services if(sdp_service_search_attr_req(sess, search, SDP_ATTR_REQ_RANGE, attrid, &seq) < 0) { perror("SDP service search"); sdp_close(sess); exit(1); } sdp_list_free(attrid, 0); sdp_list_free(search, 0); // Loop through the list of services for(; seq; seq = seq->next) { sdp_record_t *rec = (sdp_record_t *) seq->data; sdp_list_t *access = NULL; int channel; // Print the service name sdp_record_print(rec); // Print the RFCOMM channel sdp_get_access_protos(rec, &access); if(access) { channel = sdp_get_proto_port(access, RFCOMM_UUID); printf("Channel: %d\n", channel); } } free(seq); sdp_close(sess); return 0; }
编译方法(https://people.csail.mit.edu/albert/bluez-intro/c404.html):
# gcc -o sdpbrowse sdpbrowse.c -lbluetooth
ubuntu安装依赖库(https://people.csail.mit.edu/albert/bluez-intro/x45.html)
apt-get install libbluetooth-dev bluez-utils
运行:
相关文章推荐
- 一张图看清Linux 内核运行原理
- 11月18日linux服务器后,服务器向…
- Linux文件和目录的读、写、执行权限总结
- [linux] Linux的bg和fg命令简单介绍
- 安装win7和centos6.7双系统 记录
- linux 安装 percona-toolkit
- linux下使用tar命令
- linux下如何快速学习新命令之man命令完美解释
- 在 Ubuntu 15.04 / CentOS 7 上安装广告服务器 Revive Adserver
- Linux SAMBA Server setup Guid
- Linux使用命令查找定位文件
- macbook install virtulbox 共享文件夹给centos
- linux下svn的常用代码【转】
- Linux如何查看进程、杀死进程、启动进程等常用命令
- Linux服务管理命令
- Linux进程共享通信 -- mmap实现
- linux下搭建vsftp服务
- 嵌入式Linux系统的电子书阅读器项目4——Input Event System
- 从初识Linux到离不开系列(三)悠然而生
- Linux基本原则