Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libtins 4.2 #4587

Merged
merged 17 commits into from
Feb 20, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions recipes/libtins/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8.1)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory("source_subfolder")
4 changes: 4 additions & 0 deletions recipes/libtins/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"4.2":
sha256: a9fed73e13f06b06a4857d342bb30815fa8c359d00bd69547e567eecbbb4c3a1
url: https://github.com/mfontanini/libtins/archive/v4.2.tar.gz
102 changes: 102 additions & 0 deletions recipes/libtins/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
from conans import tools, CMake, ConanFile
import os


class LibTinsConan(ConanFile):
name = "libtins"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/mfontanini/libtins"
description = "High-level, multiplatform C++ network packet sniffing and crafting library."
license = "BSD-2-Clause"
topics = ("pcap", "packets", "network", "packet-analyser", "packet-parsing", "libpcap", "sniffing")
exports_sources = ["CMakeLists.txt"]
generators = "cmake", "cmake_find_package", "cmake_find_package_multi"
Fefer-Ivan marked this conversation as resolved.
Show resolved Hide resolved
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_ack_tracker": [True, False],
"with_wpa2": [True, False],
"with_dot11": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_ack_tracker": True,
"with_wpa2": True,
"with_dot11": True,
}
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def requirements(self):
self.requires("libpcap/1.10.0")
if self.options.with_ack_tracker:
self.requires("boost/1.75.0")
if self.options.with_wpa2:
self.requires("openssl/1.1.1i")

def configure(self):
if self.options.shared:
del self.options.fPIC

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)

def _patch_sources(self):
# Workaround for casing issues in cmake_find_package generator of openssl recipe
top_cmakelists = os.path.join(self._source_subfolder, "CMakeLists.txt")
src_cmakelists = os.path.join(self._source_subfolder, "src", "CMakeLists.txt")
tools.replace_in_file(top_cmakelists, "OPENSSL_FOUND", "OpenSSL_FOUND")
tools.replace_in_file(src_cmakelists, "OPENSSL_INCLUDE_DIR", "OpenSSL_INCLUDE_DIR")
tools.replace_in_file(src_cmakelists, "OPENSSL_LIBRARIES", "OpenSSL_LIBRARIES")

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["LIBTINS_BUILD_EXAMPLES"] = False
self._cmake.definitions["LIBTINS_BUILD_TESTS"] = False

self._cmake.definitions["LIBTINS_BUILD_SHARED"] = self.options.shared
self._cmake.definitions["LIBTINS_ENABLE_CXX11"] = tools.valid_min_cppstd(self, 11)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never clear in my head, does this take into account the compiler's default and the build settings?

Copy link
Contributor

@SpaceIm SpaceIm Feb 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it takes into account compiler.cppstd, and if not set default cpp standard of compiler.

self._cmake.definitions["LIBTINS_ENABLE_ACK_TRACKER"] = self.options.with_ack_tracker
self._cmake.definitions["LIBTINS_ENABLE_WPA2"] = self.options.with_wpa2
self._cmake.definitions["LIBTINS_ENABLE_DOT11"] = self.options.with_dot11

self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def build(self):
Fefer-Ivan marked this conversation as resolved.
Show resolved Hide resolved
self._patch_sources()
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy(os.path.join(self._source_subfolder, "LICENSE"), dst="licenses")
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))

def package_info(self):
# FIXME: official CMake imported target is not namespaced
self.cpp_info.names["cmake_find_package"] = "libtins"
Fefer-Ivan marked this conversation as resolved.
Show resolved Hide resolved
self.cpp_info.names["cmake_find_package_multi"] = "libtins"
self.cpp_info.names["pkg_config"] = "libtins"
self.cpp_info.libs = tools.collect_libs(self)
Fefer-Ivan marked this conversation as resolved.
Show resolved Hide resolved
if self.settings.os == "Windows" and not self.options.shared:
self.cpp_info.defines.append("TINS_STATIC")
8 changes: 8 additions & 0 deletions recipes/libtins/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(test_package test_package.cpp)
target_link_libraries(test_package ${CONAN_LIBS})
17 changes: 17 additions & 0 deletions recipes/libtins/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import tools, ConanFile, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
10 changes: 10 additions & 0 deletions recipes/libtins/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <tins/tins.h>

using namespace Tins;

int main() {
SnifferConfiguration config;
config.set_filter("port 80");
config.set_promisc_mode(true);
config.set_snap_len(400);
}
3 changes: 3 additions & 0 deletions recipes/libtins/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"4.2":
folder: all