Skip to content

Commit

Permalink
- libusipp: fixing some 802.11 defines and config script
Browse files Browse the repository at this point in the history
  • Loading branch information
stealth committed Oct 1, 2016
1 parent 8b74bba commit 692f836
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -27,11 +27,20 @@ Since USI++ is GPL there is ABSOLUTELY NO WARRANTY. YOU USE IT AT YOUR OWN RISK.
----------


$ cd src
$ autoconf
$ ./configure
$ make
# make install

Please note, if you have multiple `libpcap` installs for testing, the generated `Makefile` is
just a proposal. The configure script actually cannot know which include or lib path
you prefer. In such case, you have to edit the generated `Makefile` to point to it exactly,
as well as setting/unsetting the defines you need in `config.h`.

Having more than one libpcap install is not uncommon, since various functions such
as `pcap_set_immediate()` or mmapped packet sockets just appeared recently.


3. Compiling the examples
-------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/Makefile.in
Expand Up @@ -4,7 +4,7 @@
LIBS=@LIBS@
LDFLAGS=@LDFLAGS@
DEFS=
CXXFLAGS=-I . -I .. @CXXFLAGS@ -I/usr/include/pcap -Wall -c -pedantic -std=c++11 $(DEFS)
CXXFLAGS=-I . -I .. @CXXFLAGS@ -Wall -c -pedantic -std=c++11 $(DEFS)
CXX=@CXX@
CC=@CC@
INSTALL=@INSTALL@
Expand All @@ -19,7 +19,7 @@ usi++: icmp.o datalink.o ip.o misc.o udp.o tcp.o TX_IP.o Layer2.o arp.o\
eapol.o ip6.o TX_IP6.o icmp6.o TX_dnet_ip.o TX_dnet_eth.o\
TX_pcap_eth.o TX_pcap.o TX_string.o RX_fd.o RX_string.o object.o
ar cr libusi++.a $^
$(CC) $^ -shared -Wl,$(LDFLAGS) $(LIBS) -lstdc++ -o libusi++.so
$(CC) $^ -shared $(LDFLAGS) $(LIBS) -lstdc++ -o libusi++.so
$(RANLIB) libusi++.a

object.o: object.cc
Expand Down
6 changes: 6 additions & 0 deletions src/config.h.in
Expand Up @@ -18,6 +18,9 @@
/* Define to 1 if you have the `dnet' library (-ldnet). */
#undef HAVE_LIBDNET

/* Define to 1 if you have the `dumbnet' library (-ldumbnet). */
#undef HAVE_LIBDUMBNET

/* Define to 1 if you have the `nsl' library (-lnsl). */
#undef HAVE_LIBNSL

Expand All @@ -42,6 +45,9 @@
/* Define to 1 if you have the `pcap_inject' function. */
#undef HAVE_PCAP_INJECT

/* Define if you have pcap_set_immediate. */
#undef HAVE_PCAP_SET_IMMEDIATE

/* Define if radiotap exists. */
#undef HAVE_RADIOTAP

Expand Down
12 changes: 11 additions & 1 deletion src/configure.ac
Expand Up @@ -13,7 +13,7 @@ AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_RANLIB

LDFLAGS="$LDFLAGS -L/usr/local/lib"
LDFLAGS="$LDFLAGS -L/usr/local/lib64 -L/usr/local/lib"
CXXFLAGS="$CXXFLAGS -fPIC -I/usr/local/include"

# Checks for libraries.
Expand Down Expand Up @@ -73,6 +73,16 @@ case "$r" in
*)
esac

r=`grep pcap_set_immediate /usr/include/pcap/pcap.h 2>/dev/null`
r+=`grep pcap_set_immediate /usr/local/include/pcap/pcap.h 2>/dev/null`
case "$r" in
*pcap_set_immediate*)
AC_DEFINE([HAVE_PCAP_SET_IMMEDIATE], [1], [Define if you have pcap_set_immediate.])
echo "Enabling pcap_set_immediate"
;;
*)
esac


AC_CONFIG_FILES([Makefile])
AC_OUTPUT
Expand Down
2 changes: 2 additions & 0 deletions src/datalink.cc
Expand Up @@ -263,8 +263,10 @@ int pcap::init_device(const string &dev, int promisc, size_t snaplen)
e += ebuf;
return die(e, STDERR, -1);
}
#ifdef HAVE_PCAP_SET_IMMEDIATE
if (pcap_set_immediate_mode(d_pd, 1) < 0)
return die("pcap::init_device: Unable to set immediate mode.", STDERR, -1);
#endif

pcap_set_promisc(d_pd, 1);
pcap_set_timeout(d_pd, 0);
Expand Down
18 changes: 12 additions & 6 deletions usi++/radiotap.h
Expand Up @@ -4,6 +4,7 @@
#define usipp_radiotap_h

#include <stdint.h>
#include <cstring>
#include "80211.h"

namespace usipp {
Expand Down Expand Up @@ -202,9 +203,9 @@ struct radiotap_hdr {
uint32_t txflags:1;
uint32_t rtsretries:1;
uint32_t dataretries:1;
uint32_t channelpus:1;
uint32_t htinfo:1;
uint32_t channelplus:1;
uint32_t mcs:1;
uint32_t ampdu:1;
uint32_t unused:8;
uint32_t rtnsnext:1; // radiotap NS next
uint32_t vnsnext:1; // vendor NS next
Expand Down Expand Up @@ -233,17 +234,19 @@ struct radiotap_hdr {
uint8_t asignal;
uint8_t anoise;
uint8_t antenna;

uint16_t txflags;
uint8_t pad[1];

// construct a sane default
radiotap_hdr() : version(0), hlen(0x19),
radiotap_hdr() : version(0), hlen(28),
timestamp{0,0,0,0,0,0,0,0},
rate(2), // 1MBit/s
ch_freq(channel7), // 2442 Mhz
ch_type(0x00a0), // 802.11b
asignal(0xde),
anoise(0),
antenna(0)
antenna(0),
txflags(0)
{
pflags.value = 0;
pflags.bits.tsft = 1;
Expand All @@ -254,12 +257,15 @@ struct radiotap_hdr {
pflags.bits.asignal = 1;
pflags.bits.anoise = 1;
pflags.bits.antenna = 1;
pflags.bits.txflags = 0;

flags.value = 0;

memset(pad, 0, sizeof(pad));
}

~radiotap_hdr() {}
};
} __attribute__((packed));

} // namespace ieee80211

Expand Down

0 comments on commit 692f836

Please sign in to comment.