Linux平台sdp discovery编程
来源:互联网 发布:104cm肛塞淘宝 编辑:程序博客网 时间:2024/04/24 04:08
http://www.datenterrorist.de/devel/sdpbrowse.c
/* 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
运行:
0 0
- Linux平台sdp discovery编程
- Linux Bluetooth编程(九) SDP层编程
- 实战Linux Bluetooth编程 (七) SDP协议
- 实战Linux Bluetooth编程 (七) SDP协议
- 实战Linux Bluetooth编程 (七) SDP协议
- 实战Linux Bluetooth编程 (七) SDP协议
- 实战Linux Bluetooth编程 (七) SDP协议
- Linux Bluetooth编程 (七) SDP协议
- 实战Linux Bluetooth编程 (七) SDP协议
- 实战Linux Bluetooth编程 (七) SDP协议
- 实战Linux Bluetooth编程 (七) SDP协议
- 实战Linux Bluetooth编程 (九) SDP层编程
- linux下bluetooth编程(八)SDP层编程
- 实战Linux Bluetooth编程(九) SDP层编程
- linux下bluetooth编程(八)SDP层编程
- 实战Linux Bluetooth编程(九) SDP层编程
- 实战Linux Bluetooth编程 (九) SDP层编程
- linux下bluetooth编程(八)SDP层编程
- java学习笔记之枚举类enum(转载)
- jsp/servlet/struts/hibernate/spring内部实现机制
- Fliptile POJ 3279(开关问题)
- 70. Climbing Stairs
- 83. Remove Duplicates from Sorted List
- Linux平台sdp discovery编程
- 263. Ugly Number
- C语言,设计出租车计价器,不能计算夜间加费用的版本
- 算法之美_源代码发布(9)
- 202. Happy Number
- shfit+alt+s用于eclipse
- c++多线程编程
- C++格式化时间
- 关于安装三星手机S6edga的过程,救砖过程