Repository: conan-io/conan-center-index

Issue:
[request] libnet/1.2
### Package Details
  * Package Name/Version: **libnet/1.2**
  * Website: **http://libnet.sourceforge.net/**
  * Source code: **https://github.com/libnet/libnet**

### Description Of The Library / Tool
Libnet is an API to help with the construction and injection of network packets. It provides a portable framework for low-level network packet writing and handling (use libnet in conjunction with libpcap and you can write some really cool stuff). Libnet includes packet creation at the IP layer and at the link layer as well as a host of supplementary and complementary functionality.


Discussion:

Resolving patch:
diff --git a/recipes/libnet/all/conanfile.py b/recipes/libnet/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/libnet/all/conanfile.py
@@ -0,0 +1,87 @@
+from conans import ConanFile, AutoToolsBuildEnvironment, tools
+from conans.errors import ConanInvalidConfiguration
+import os
+
+required_conan_version = ">=1.33.0"
+
+
+class LibnetConan(ConanFile):
+    name = "libnet"
+
+    description = "Libnet is an API to help with the construction and injection of network packets."
+    topics = ("conan", "libnet", "network")
+    url = "https://github.com/conan-io/conan-center-index"
+    homepage = "http://libnet.sourceforge.net/"
+    license = ["BSD-2-Clause"]
+    settings = "os", "arch", "compiler", "build_type"
+    options = {
+        "shared": [True, False],
+        "fPIC": [True, False],
+    }
+    default_options = {
+        "shared": False,
+        "fPIC": True,
+    }
+
+    _autotools = None
+
+    @property
+    def _source_subfolder(self):
+        return "source_subfolder"
+
+    def config_options(self):
+        if self.settings.os == "Windows":
+            del self.options.fPIC
+
+    def configure(self):
+        del self.settings.compiler.libcxx
+        del self.settings.compiler.cppstd
+        if self.options.shared:
+            del self.options.fPIC
+        if self.settings.compiler == "Visual Studio":
+            raise ConanInvalidConfiguration("libnet is not supported by Visual Studio")
+        if self.settings.os == "Windows" and self.options.shared:
+            raise ConanInvalidConfiguration("libnet can't be built as shared on Windows")
+
+    def source(self):
+        tools.get(**self.conan_data["sources"][self.version],
+                  strip_root=True, destination=self._source_subfolder)
+
+    def _configure_autotools(self):
+        if self._autotools:
+            return self._autotools
+
+        self._autotools = AutoToolsBuildEnvironment(self)
+
+        args = []
+        if self.options.shared:
+            args.extend(["--disable-static", "--enable-shared"])
+        else:
+            args.extend(["--disable-shared", "--enable-static"])
+            args.append("--disable-doxygen-doc")
+
+        self._autotools.configure(configure_dir=self._source_subfolder, args=args)
+
+        return self._autotools
+
+    def build(self):
+        autotools = self._configure_autotools()
+        autotools.make()
+
+    def package(self):
+        self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
+
+        autotools = self._configure_autotools()
+        autotools.install()
+
+        tools.rmdir(os.path.join(self.package_folder, "share"))
+        os.unlink(os.path.join(self.package_folder, "lib", "libnet.la"))
+        os.unlink(os.path.join(self.package_folder, "lib", "pkgconfig", "libnet.pc"))
+
+    def package_info(self):
+        self.cpp_info.libs = ["net"]
+        self.cpp_info.names["pkg_config"] = "libnet"
+        if self.settings.os == "Linux":
+            self.cpp_info.system_libs.append("m")
+        elif self.settings.os == "Windows":
+            self.cpp_info.system_libs.append("ws2_32")


Test patch:
diff --git a/recipes/libnet/all/test_package/CMakeLists.txt b/recipes/libnet/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/libnet/all/test_package/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.1)
+project(test_package)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup()
+
+add_executable(${PROJECT_NAME} test_package.c)
+target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
diff --git a/recipes/libnet/all/test_package/conanfile.py b/recipes/libnet/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/libnet/all/test_package/conanfile.py
@@ -0,0 +1,16 @@
+from conans import ConanFile, CMake, tools
+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)
diff --git a/recipes/libnet/all/test_package/test_package.c b/recipes/libnet/all/test_package/test_package.c
new file mode 100644
--- /dev/null
+++ b/recipes/libnet/all/test_package/test_package.c
@@ -0,0 +1,19 @@
+#include <libnet.h>
+#include <stdio.h>
+
+int main()
+{
+    libnet_t *l = NULL;
+    unsigned char enet_dst[6] = {0x0d, 0x0e, 0x0a, 0x0d, 0x00, 0x00};
+    libnet_ptag_t t = libnet_autobuild_ethernet(
+                        enet_dst,                   /* ethernet destination */
+                        ETHERTYPE_ARP,              /* protocol type */
+                        l);                         /* libnet handle */
+    if (t != (-1)) {
+        fprintf(stderr, "[-] Failed!\n");
+        return 1;
+    }
+
+    fprintf(stderr, "[+] Passed!\n");
+    return 0;
+}