Repository: conan-io/conan-center-index

Issue:
[request] libdumbnet/1.16.3
### Package Name/Version

libdumbnet/1.16.3
### Webpage

https://github.com/ofalk/libdnet
http://code.google.com/p/libdnet/
### Source code

https://github.com/ofalk/libdnet
### Description of the library/tool

 libdumbnet provides a simplified, portable interface to several low-level networking routines, including

  * network address manipulation
  * kernel arp(4) cache and route(4) table lookup and manipulation
  * network firewalling (Ip filter, ipfw, ipchains, pdf, ...)
  * network interface lookup and manipulation
  * raw IP packet and Ethernet frame transmission

libdumbnet is known as libdnet in other distributions, but was renamed in Debian-based distros in favour of the older DECnet library 'libdnet'. 


Discussion:

Resolving patch:
diff --git a/recipes/dnet/all/conanfile.py b/recipes/dnet/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/dnet/all/conanfile.py
@@ -0,0 +1,70 @@
+from conan import ConanFile
+from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
+from conan.tools.files import copy, get, rmdir
+import os
+
+
+required_conan_version = ">=1.56.0"
+
+
+class dnetConan(ConanFile):
+    name = "dnet"
+    description = "Provides a simplified, portable interface to several low-level networking routines."
+    homepage = "https://github.com/ofalk/libdnet"
+    topics = ("dnet", "libdnet", "libdumbnet")
+    license = "BSD-3-Clause"
+    url = "https://github.com/conan-io/conan-center-index"
+    package_type = "library"
+    options = {
+        "shared": [True, False],
+        "fPIC": [True, False],
+    }
+    default_options = {
+        "shared": False,
+        "fPIC": True
+    }
+    settings = "os", "arch", "compiler", "build_type"
+
+
+    def layout(self):
+        cmake_layout(self, src_folder="src")
+
+    def config_options(self):
+        if self.settings.os == "Windows":
+            del self.options.fPIC
+
+    def configure(self):
+        if self.options.shared:
+            self.options.rm_safe("fPIC")
+        # This is a pure C project
+        self.settings.rm_safe("compiler.cppstd")
+        self.settings.rm_safe("compiler.libcxx")
+
+    def source(self):
+        get(self, **self.conan_data["sources"][self.version], strip_root=True)
+
+    def generate(self):
+        tc = CMakeToolchain(self)
+        tc.generate()
+
+        deps = CMakeDeps(self)
+        deps.generate()
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+    
+    def package(self):
+        copy(self,"LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.install()
+        rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
+
+    def package_info(self):
+        self.cpp_info.libs.append("dnet")
+        self.cpp_info.includedirs.append(os.path.join("include", "dnet"))
+ 
+        if self.settings.os == 'Windows':
+            self.cpp_info.system_libs = ['Iphlpapi', 'wsock32']


Test patch:
diff --git a/recipes/dnet/all/test_package/CMakeLists.txt b/recipes/dnet/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/dnet/all/test_package/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 3.1)
+project(test_package C)
+
+find_package(dnet REQUIRED CONFIG)
+
+add_executable(${PROJECT_NAME} test_package.c)
+target_link_libraries(${PROJECT_NAME} PRIVATE dnet::dnet)
diff --git a/recipes/dnet/all/test_package/conanfile.py b/recipes/dnet/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/dnet/all/test_package/conanfile.py
@@ -0,0 +1,26 @@
+from conan import ConanFile
+from conan.tools.build import can_run
+from conan.tools.cmake import CMake, cmake_layout
+import os
+
+
+class TestPackageConan(ConanFile):
+    settings = "os", "arch", "compiler", "build_type"
+    generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
+    test_type = "explicit"
+
+    def layout(self):
+        cmake_layout(self)
+
+    def requirements(self):
+        self.requires(self.tested_reference_str)
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def test(self):
+        if can_run(self):
+            bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
+            self.run("{} {}".format(bin_path, "127.0.0.1"), env="conanrun")
diff --git a/recipes/dnet/all/test_package/test_package.c b/recipes/dnet/all/test_package/test_package.c
new file mode 100644
--- /dev/null
+++ b/recipes/dnet/all/test_package/test_package.c
@@ -0,0 +1,39 @@
+#include <dnet/dnet.h>
+#include <dnet/config.h>
+#include <dnet/err.h>
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
+#include <unistd.h>
+#elif defined(_WIN32)
+#include <io.h>
+#endif
+
+void addr_usage(void)
+{
+	fprintf(stderr, "Usage: dnet addr <address> ...\n");
+	exit(1);
+}
+
+int main(int argc, char *argv[])
+{
+	struct addr addr;
+	int c, len;
+
+	if (argc == 1 || *(argv[1]) == '-')
+		addr_usage();
+
+	for (c = 1; c < argc; c++) {
+		if (addr_aton(argv[c], &addr) < 0)
+			addr_usage();
+
+		len = addr.addr_bits / 8;
+
+		if (write(1, addr.addr_data8, len) != len)
+			err(1, "write");
+	}
+	return 0;
+}