Skip to content

Commit

Permalink
Merge pull request #1 from adriangranados/master
Browse files Browse the repository at this point in the history
Adds macOS support
  • Loading branch information
homewsn committed Feb 14, 2019
2 parents f195007 + 2ba883b commit 920e107
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
7 changes: 6 additions & 1 deletion Makefile
Expand Up @@ -21,7 +21,12 @@ OBJECTS = $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
DEPS = $(HEADERS)

INCLPATH = -I.
LIBS = -lusb-1.0 -lrt
LIBS = -lusb-1.0

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
LIBS += -lrt
endif

# Installation directories by convention
# http://www.gnu.org/prep/standards/html_node/Directory-Variables.html
Expand Down
17 changes: 15 additions & 2 deletions ReadMe.md
Expand Up @@ -23,6 +23,19 @@ $ make
$ sudo make install
```

##### Building (macOS)

* Install `libusb` via [Homebrew](https://brew.sh) (or your preferred package manager):
```sh
$ brew install libusb
```
* Download [the latest release](https://github.com/homewsn/whsniff/releases) in tarball from github and untar it. Then build and install whsniff.
```sh
$ curl -L https://github.com/homewsn/whsniff/archive/v1.1.tar.gz | tar zx
$ cd whsniff-1.1
$ make
$ sudo make install
```

##### Building (OpenWrt)

Expand All @@ -41,7 +54,7 @@ $ ./scripts/feeds install -a -p homewsn

##### How to use (Locally)

* Connect CC2531 USB dongle to your Linux PC.
* Connect CC2531 USB dongle to your Linux or macOS computer.
* Open a terminal session on the desktop where you have Wireshark installed and enter the following commands:
```sh
$ wireshark -k -i <( path/to/whsniff -c channel_number )
Expand Down Expand Up @@ -77,4 +90,4 @@ where `password` is a root password, `192.168.1.202` is an IP address of the com

##### License

[GNU GPL v 2.0](http://www.gnu.org/licenses/gpl-2.0.html)
[GNU GPL v 2.0](http://www.gnu.org/licenses/gpl-2.0.html)
20 changes: 19 additions & 1 deletion src/whsniff.c
Expand Up @@ -16,10 +16,24 @@
#include <stdio.h> /* printf */
#include <signal.h> /* signal_handler */
#include <string.h> /* memset */
#include <endian.h> /* htole16, htole32, le32toh */
#include <unistd.h> /* getopt, optarg */
#include <libusb-1.0/libusb.h>

#ifndef _BSD_SOURCE
#define _BSD_SOURCE
#endif

#if defined(__APPLE__)
#include <libkern/OSByteOrder.h>
#include <machine/endian.h>
#define htole16(x) OSSwapHostToLittleInt16(x)
#define htole32(x) OSSwapHostToLittleInt32(x)
#define le16toh(x) OSSwapLittleToHostInt16(x)
#define le32toh(x) OSSwapLittleToHostInt32(x)
#else
#include <endian.h> /* htole16, htole32, le32toh */
#endif

#define BUF_SIZE 256 // buffers size
#define TIMEOUT 200 // USB timeout in ms

Expand Down Expand Up @@ -233,7 +247,11 @@ int main(int argc, char *argv[])
printf("ERROR: Could not initialize libusb.\n");
exit(EXIT_FAILURE);
}
#if LIBUSB_API_VERSION >= 0x01000106
libusb_set_option(NULL, LIBUSB_OPTION_LOG_LEVEL, 3);
#else
libusb_set_debug(NULL, 3);
#endif
handle = libusb_open_device_with_vid_pid(NULL, 0x0451, 0x16ae);
if (handle == NULL)
{
Expand Down

0 comments on commit 920e107

Please sign in to comment.