diff --git a/Makefile.in b/Makefile.in index f82f2ad..510fec1 100644 --- a/Makefile.in +++ b/Makefile.in @@ -7,14 +7,14 @@ SONAME=$(BASENAME).$(MAJOR) CXX=@CXX@ CFLAGS=-c -Wall -fPIC @CFLAGS@ -DTINS_VERSION=@PACKAGE_VERSION@ LDFLAGS=-lpcap -shared -Wl,-soname,$(SONAME) -Wl,-z,defs -SOURCES=$(wildcard src/*.cpp) +SOURCES=@SOURCE_FILES@ OBJECTS=$(SOURCES:.cpp=.o) INCLUDE=-Iinclude/ EXECUTABLE=$(BASENAME).$(MAJOR).$(MINOR) DEPS = $(SOURCES:.cpp=.d) -prefix = /usr/local +prefix = /usr exec_prefix = $(prefix) bindir = $(exec_prefix)/bin @@ -48,7 +48,7 @@ clean: install: install -d $(DESTDIR)$(includedir)/tins/ - install -m 644 -t $(DESTDIR)$(includedir)/tins/ include/* + install -m 644 include/* $(DESTDIR)$(includedir)/tins/ install -d $(DESTDIR)$(libdir) install -m 644 $(EXECUTABLE) $(DESTDIR)$(libdir)/ if [ -f $(DESTDIR)$(libdir)/$(BASENAME) ]; then rm $(DESTDIR)$(libdir)/$(BASENAME); fi @@ -62,4 +62,4 @@ uninstall: rm $(DESTDIR)$(libdir)/$(BASENAME) rm $(DESTDIR)$(libdir)/$(SONAME) --include depends.d +include depends.d diff --git a/configure b/configure index ab79daa..bee5bfb 100755 --- a/configure +++ b/configure @@ -600,6 +600,7 @@ ac_includes_default="\ ac_subst_vars='LTLIBOBJS LIBOBJS +SOURCE_FILES CFLAGS EGREP GREP @@ -2528,7 +2529,7 @@ if test "${enable_c__11+set}" = set; then : fi - +SOURCE_FILES=$(ls src/*cpp | tr '\n' ' ') ac_ext=cpp @@ -2984,6 +2985,7 @@ else fi + ac_config_files="$ac_config_files Makefile" cat >confcache <<\_ACEOF diff --git a/configure.ac b/configure.ac index 67673cf..0a0b5d9 100644 --- a/configure.ac +++ b/configure.ac @@ -16,9 +16,10 @@ AC_ARG_ENABLE( [CFLAGS="$CFLAGS -std=c++0x"] ) - +SOURCE_FILES=$(ls src/*cpp | tr '\n' ' ') AC_CHECK_HEADERS([pcap.h]) AC_CHECK_LIB(pcap, pcap_loop, [], [AC_MSG_ERROR([pcap library is needed!])]) AC_SUBST(CFLAGS) +AC_SUBST(SOURCE_FILES) AC_OUTPUT(Makefile) diff --git a/include/utils.h b/include/utils.h index 0f00986..debee4d 100644 --- a/include/utils.h +++ b/include/utils.h @@ -302,49 +302,49 @@ namespace Tins { dereference_until_pdu(T &value) { return dereference_until_pdu(*value); } + #ifdef BSD + inline std::vector query_route_table() { + int mib[6]; + std::vector buf; + size_t len; + + mib[0] = CTL_NET; + mib[1] = AF_ROUTE; + mib[2] = 0; + mib[3] = AF_INET; + mib[4] = NET_RT_DUMP; + mib[5] = 0; + if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) + throw std::runtime_error("sysctl failed"); + + buf.resize(len); + if (sysctl(mib, 6, &buf[0], &len, NULL, 0) < 0) { + throw std::runtime_error("sysctl failed"); + } + + return buf; + } + + template + void parse_header(struct rt_msghdr *rtm, ForwardIterator iter) + { + char *ptr = (char *)(rtm + 1); + sockaddr *sa = 0; + + for (int i = 0; i < RTAX_MAX; i++) { + if (rtm->rtm_addrs & (1 << i)) { + sa = (struct sockaddr *)ptr; + ptr += sa->sa_len; + if (sa->sa_family == 0) + sa = 0; + } + *iter++ = sa; + } + } + #endif } } #ifdef BSD -inline std::vector query_route_table() -{ - int mib[6]; - std::vector buf; - size_t len; - - mib[0] = CTL_NET; - mib[1] = AF_ROUTE; - mib[2] = 0; - mib[3] = AF_INET; - mib[4] = NET_RT_DUMP; - mib[5] = 0; - if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) - throw std::runtime_error("Failed to ioctl"); - - buf.resize(len); - if (sysctl(mib, 6, &buf[0], &len, NULL, 0) < 0) { - throw std::runtime_error("Failed to ioctl"); - } - - return buf; -} - -template -void parse_header(struct rt_msghdr *rtm, ForwardIterator iter) -{ - char *ptr = (char *)(rtm + 1); - sockaddr *sa; - - for (int i = 0; i < RTAX_MAX; i++) { - if (rtm->rtm_addrs & (1 << i)) { - sa = (struct sockaddr *)ptr; - ptr += sa->sa_len; - if (sa->sa_family == 0) - sa = 0; - } - *iter++ = sa; - } -} - template void Tins::Utils::route_entries(ForwardIterator output) { std::vector buffer = query_route_table(); diff --git a/src/utils.cpp b/src/utils.cpp index d4180b7..1500bdb 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -194,11 +194,12 @@ uint32_t Utils::pseudoheader_checksum(IPv4Address source_ip, IPv4Address dest_ip uint32_t checksum(0); uint32_t source_ip_int = Endian::host_to_be(source_ip), dest_ip_int = Endian::host_to_be(dest_ip); - uint16_t *ptr = (uint16_t*)&source_ip_int; - - checksum += (uint32_t)(*ptr) + (uint32_t)(*(ptr+1)); - ptr = (uint16_t*)&dest_ip_int; - checksum += (uint32_t)(*ptr) + (uint32_t)(*(ptr+1)); + char buffer[sizeof(uint32_t) * 2]; + uint16_t *ptr = (uint16_t*)buffer, *end = (uint16_t*)(buffer + sizeof(buffer)); + std::memcpy(buffer, &source_ip_int, sizeof(source_ip_int)); + std::memcpy(buffer + sizeof(uint32_t), &dest_ip_int, sizeof(dest_ip_int)); + while(ptr < end) + checksum += (uint32_t)*ptr++; checksum += flag + len; return checksum; } diff --git a/tests/Makefile.in b/tests/Makefile.in index 3c6bdf2..c987ffd 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -1,7 +1,7 @@ CXX=@CXX@ CFLAGS=-c -Wall @CFLAGS@ -DTINS_VERSION=@PACKAGE_VERSION@ LDFLAGS=-lpcap -lgtest -lpthread -SOURCES=$(wildcard src/*.cpp src/dot11/*.cpp ../src/*.cpp) +SOURCES=@SOURCE_FILES@ OBJECTS=$(SOURCES:.cpp=.o) INCLUDE=-Iinclude/ -I../include @@ -32,4 +32,4 @@ $(EXECUTABLE): $(OBJECTS) clean: rm $(OBJECTS) $(EXECUTABLE) --include depends.d +include depends.d diff --git a/tests/configure b/tests/configure index ea27acd..5cabe5e 100755 --- a/tests/configure +++ b/tests/configure @@ -600,6 +600,7 @@ ac_includes_default="\ ac_subst_vars='LTLIBOBJS LIBOBJS +SOURCE_FILES CFLAGS EGREP GREP @@ -2523,6 +2524,8 @@ if test "${enable_c__11+set}" = set; then : fi +SOURCE_FILES=$(ls ../src/*cpp src/*cpp src/dot11/*cpp | tr '\n' ' ') + ac_ext=cpp ac_cpp='$CXXCPP $CPPFLAGS' @@ -2979,6 +2982,7 @@ fi #AC_CHECK_LIB([gtest_main], [main], [], [AC_MSG_ERROR([gtest library is needed!])]) + ac_config_files="$ac_config_files Makefile" cat >confcache <<\_ACEOF diff --git a/tests/configure.ac b/tests/configure.ac index f8863e6..b4130d2 100644 --- a/tests/configure.ac +++ b/tests/configure.ac @@ -11,8 +11,11 @@ AC_ARG_ENABLE( [CFLAGS="$CFLAGS -std=c++0x"] ) +SOURCE_FILES=$(ls ../src/*cpp src/*cpp src/dot11/*cpp | tr '\n' ' ') + AC_CHECK_HEADERS([pcap.h gtest/gtest.h]) AC_CHECK_LIB(pcap, pcap_loop, [], [AC_MSG_ERROR([pcap library is needed!])]) #AC_CHECK_LIB([gtest_main], [main], [], [AC_MSG_ERROR([gtest library is needed!])]) AC_SUBST(CFLAGS) +AC_SUBST(SOURCE_FILES) AC_OUTPUT(Makefile)