diff options
author | Xin LI <delphij@FreeBSD.org> | 2012-05-14 05:12:56 +0000 |
---|---|---|
committer | Xin LI <delphij@FreeBSD.org> | 2012-05-14 05:12:56 +0000 |
commit | d1e8733132ce92d068898e4b3fe25ce17d634590 (patch) | |
tree | 158e6045ed438c41ac8de6cb27ac3c73cdc6643a /contrib/libpcap/pcap-bt-linux.c | |
parent | 47db53c31a5ec643382c4b08c3f68dd4ccdf79d9 (diff) | |
parent | 5a0615f5c40ce036a7e13cfffe00927f845ad563 (diff) | |
download | src-d1e8733132ce92d068898e4b3fe25ce17d634590.tar.gz src-d1e8733132ce92d068898e4b3fe25ce17d634590.zip |
Merge from vendor branch: update libpcap to 1.2.1.
MFC after: 2 weeks
Notes
Notes:
svn path=/head/; revision=235426
Diffstat (limited to 'contrib/libpcap/pcap-bt-linux.c')
-rw-r--r-- | contrib/libpcap/pcap-bt-linux.c | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/contrib/libpcap/pcap-bt-linux.c b/contrib/libpcap/pcap-bt-linux.c index a36c144d8a9f..0c6c08d199eb 100644 --- a/contrib/libpcap/pcap-bt-linux.c +++ b/contrib/libpcap/pcap-bt-linux.c @@ -67,7 +67,6 @@ static const char rcsid[] _U_ = static int bt_activate(pcap_t *); static int bt_read_linux(pcap_t *, int , pcap_handler , u_char *); static int bt_inject_linux(pcap_t *, const void *, size_t); -static int bt_setfilter_linux(pcap_t *, struct bpf_program *); static int bt_setdirection_linux(pcap_t *, pcap_direction_t); static int bt_stats_linux(pcap_t *, struct pcap_stat *); @@ -86,8 +85,8 @@ bt_platform_finddevs(pcap_if_t **alldevsp, char *err_str) /* if bluetooth is not supported this this is not fatal*/ if (errno == EAFNOSUPPORT) return 0; - snprintf(err_str, PCAP_ERRBUF_SIZE, "Can't open raw Bluetooth socket %d:%s", - errno, strerror(errno)); + snprintf(err_str, PCAP_ERRBUF_SIZE, + "Can't open raw Bluetooth socket: %s", strerror(errno)); return -1; } @@ -104,8 +103,9 @@ bt_platform_finddevs(pcap_if_t **alldevsp, char *err_str) if (ioctl(sock, HCIGETDEVLIST, (void *) dev_list) < 0) { - snprintf(err_str, PCAP_ERRBUF_SIZE, "Can't get Bluetooth device list via ioctl %d:%s", - errno, strerror(errno)); + snprintf(err_str, PCAP_ERRBUF_SIZE, + "Can't get Bluetooth device list via ioctl: %s", + strerror(errno)); ret = -1; goto free; } @@ -172,7 +172,7 @@ bt_activate(pcap_t* handle) handle->read_op = bt_read_linux; handle->inject_op = bt_inject_linux; - handle->setfilter_op = bt_setfilter_linux; + handle->setfilter_op = install_bpf_program; /* no kernel filtering */ handle->setdirection_op = bt_setdirection_linux; handle->set_datalink_op = NULL; /* can't change data link type */ handle->getnonblock_op = pcap_getnonblock_fd; @@ -183,8 +183,8 @@ bt_activate(pcap_t* handle) /* Create HCI socket */ handle->fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); if (handle->fd < 0) { - snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't create raw socket %d:%s", - errno, strerror(errno)); + snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, + "Can't create raw socket: %s", strerror(errno)); return PCAP_ERROR; } @@ -197,15 +197,15 @@ bt_activate(pcap_t* handle) opt = 1; if (setsockopt(handle->fd, SOL_HCI, HCI_DATA_DIR, &opt, sizeof(opt)) < 0) { - snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't enable data direction info %d:%s", - errno, strerror(errno)); + snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, + "Can't enable data direction info: %s", strerror(errno)); goto close_fail; } opt = 1; if (setsockopt(handle->fd, SOL_HCI, HCI_TIME_STAMP, &opt, sizeof(opt)) < 0) { - snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't enable time stamp %d:%s", - errno, strerror(errno)); + snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, + "Can't enable time stamp: %s", strerror(errno)); goto close_fail; } @@ -215,8 +215,8 @@ bt_activate(pcap_t* handle) memset((void *) &flt.type_mask, 0xff, sizeof(flt.type_mask)); memset((void *) &flt.event_mask, 0xff, sizeof(flt.event_mask)); if (setsockopt(handle->fd, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) { - snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't set filter %d:%s", - errno, strerror(errno)); + snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, + "Can't set filter: %s", strerror(errno)); goto close_fail; } @@ -225,8 +225,9 @@ bt_activate(pcap_t* handle) addr.hci_family = AF_BLUETOOTH; addr.hci_dev = handle->md.ifindex; if (bind(handle->fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { - snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't attach to device %d %d:%s", - handle->md.ifindex, errno, strerror(errno)); + snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, + "Can't attach to device %d: %s", handle->md.ifindex, + strerror(errno)); goto close_fail; } @@ -238,7 +239,7 @@ bt_activate(pcap_t* handle) goto close_fail; } - if (handle->opt.buffer_size == 0) { + if (handle->opt.buffer_size != 0) { /* * Set the socket buffer size to the specified value. */ @@ -265,6 +266,7 @@ bt_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *us struct cmsghdr *cmsg; struct msghdr msg; struct iovec iv; + ssize_t ret; struct pcap_pkthdr pkth; pcap_bluetooth_h4_header* bthdr; @@ -280,31 +282,33 @@ bt_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *us /* ignore interrupt system call error */ do { - pkth.caplen = recvmsg(handle->fd, &msg, 0); + ret = recvmsg(handle->fd, &msg, 0); if (handle->break_loop) { handle->break_loop = 0; return -2; } - } while ((pkth.caplen == -1) && (errno == EINTR)); + } while ((ret == -1) && (errno == EINTR)); - - if (pkth.caplen < 0) { - snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't receive packet %d:%s", - errno, strerror(errno)); + if (ret < 0) { + snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, + "Can't receive packet: %s", strerror(errno)); return -1; } + pkth.caplen = ret; + /* get direction and timestamp*/ cmsg = CMSG_FIRSTHDR(&msg); int in=0; while (cmsg) { switch (cmsg->cmsg_type) { case HCI_CMSG_DIR: - in = *((int *) CMSG_DATA(cmsg)); + memcpy(&in, CMSG_DATA(cmsg), sizeof in); break; case HCI_CMSG_TSTAMP: - pkth.ts = *((struct timeval *) CMSG_DATA(cmsg)); + memcpy(&pkth.ts, CMSG_DATA(cmsg), + sizeof pkth.ts); break; } cmsg = CMSG_NXTHDR(&msg, cmsg); @@ -316,8 +320,13 @@ bt_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *us bthdr->direction = htonl(in != 0); pkth.caplen+=sizeof(pcap_bluetooth_h4_header); pkth.len = pkth.caplen; - callback(user, &pkth, &handle->buffer[handle->offset]); - return 1; + if (handle->fcode.bf_insns == NULL || + bpf_filter(handle->fcode.bf_insns, &handle->buffer[handle->offset], + pkth.len, pkth.caplen)) { + callback(user, &pkth, &handle->buffer[handle->offset]); + return 1; + } + return 0; /* didn't pass filter */ } static int @@ -337,14 +346,14 @@ bt_stats_linux(pcap_t *handle, struct pcap_stat *stats) struct hci_dev_stats * s = &dev_info.stat; dev_info.dev_id = handle->md.ifindex; - /* ingnore eintr */ + /* ignore eintr */ do { ret = ioctl(handle->fd, HCIGETDEVINFO, (void *)&dev_info); } while ((ret == -1) && (errno == EINTR)); if (ret < 0) { - snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "can get stats" - " via ioctl %d:%s", errno, strerror(errno)); + snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, + "Can't get stats via ioctl: %s", strerror(errno)); return (-1); } @@ -358,13 +367,6 @@ bt_stats_linux(pcap_t *handle, struct pcap_stat *stats) } static int -bt_setfilter_linux(pcap_t *p, struct bpf_program *fp) -{ - return 0; -} - - -static int bt_setdirection_linux(pcap_t *p, pcap_direction_t d) { p->direction = d; |