diff options
author | guy <guy> | 2008-04-14 20:40:58 +0000 |
---|---|---|
committer | guy <guy> | 2008-04-14 20:40:58 +0000 |
commit | 2527d1ac889ed9b6c6c36d1d312700a643beb346 (patch) | |
tree | 26a05e35cdf7c3c5aec5c65892c2a5f185a6a285 /pcap-bt-linux.c | |
parent | 0fdc174e4c2d9dfd58a11027ab8ce3b5f99874a5 (diff) |
Turn close_op into cleanup_op; the routine that handles it can also be
used to clean up after a failed pcap_activate() call. Convert the
existing close_op routines to cleanup_op routines, and use them to clean
up; rename pcap_close_common() to pcap_cleanup_live_common(), and use it
directly if there's no platform-dependent cleanup needed. That means we
don't have to write the same cleanup code twice (and possibly forget
stuff in the version done on a failed pcap_activate() call).
Have the cleanup routines do whatever is necessary to indicate that
cleanup has been done, and not do any particular cleaning up if it's
already been done (i.e., don't free something if the pointer to it is
null and null out the pointer once it's been freed, don't close an FD if
it's -1 and set it to -1 once it's been closed, etc.).
For device types/platforms where we don't support monitor mode, check
for it and return PCAP_ERROR_RFMON_NOTSUP - but do so after we've
checked whether we can open the device, so we return "no such device" or
"permission denied" rather than "that device doesn't support monitor
mode" if we can't open the device in the first place.
Fix a comment.
Diffstat (limited to 'pcap-bt-linux.c')
-rw-r--r-- | pcap-bt-linux.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/pcap-bt-linux.c b/pcap-bt-linux.c index e35181cc..d8227b44 100644 --- a/pcap-bt-linux.c +++ b/pcap-bt-linux.c @@ -33,7 +33,7 @@ */ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/pcap-bt-linux.c,v 1.12 2008-04-07 03:57:32 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/pcap-bt-linux.c,v 1.13 2008-04-14 20:40:58 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -155,6 +155,7 @@ bt_activate(pcap_t* handle) int opt; int dev_id; struct hci_filter flt; + int err = PCAP_ERROR; /* get bt interface id */ if (sscanf(handle->opt.source, BT_IFACE"%d", &dev_id) != 1) @@ -178,7 +179,6 @@ bt_activate(pcap_t* handle) handle->getnonblock_op = pcap_getnonblock_fd; handle->setnonblock_op = pcap_setnonblock_fd; handle->stats_op = bt_stats_linux; - handle->close_op = bt_close_linux; handle->md.ifindex = dev_id; /* Create HCI socket */ @@ -231,6 +231,14 @@ bt_activate(pcap_t* handle) goto close_fail; } + if (p->opt.rfmon) { + /* + * Monitor mode doesn't apply to Bluetooth devices. + */ + err = PCAP_ERROR_RFMON_NOTSUP; + goto close_fail; + } + if (handle->opt.buffer_size == 0) { /* * Set the socket buffer size to the specified value. @@ -248,8 +256,8 @@ bt_activate(pcap_t* handle) return 0; close_fail: - close(handle->fd); - return PCAP_ERROR; + pcap_cleanup_live_common(p); + return err; } static int @@ -322,14 +330,6 @@ bt_inject_linux(pcap_t *handle, const void *buf, size_t size) } -static void -bt_close_linux(pcap_t* handle) -{ - close(handle->fd); - free(handle->buffer); -} - - static int bt_stats_linux(pcap_t *handle, struct pcap_stat *stats) { |