nmap / npcap

Nmap Project's Windows packet capture and transmission library
https://npcap.com
Other
2.99k stars 516 forks source link

pkg-config support #299

Open PlushBeaver opened 3 years ago

PlushBeaver commented 3 years ago

pkg-config tool can work on Windows and libpcap upstream has libpcap.pc. Can npcap SDK provide this file on Windows? It would eliminate libpcap.a/wpcap.lib difference for cross-platform projects that use pkg-config, e.g. via meson build system.

Probably 32-bit and 64-bit folder should have their own .pc files, so that they are selected by PKG_CONFIG_PATH. Prefix path can be set to some recommended location to install SDK, like C:\Program Files\Npcap. (Update: on Windows, pkg-config can detect prefix if file is placed inside ${prefix}/lib/pkgconfig.)

PlushBeaver commented 3 years ago

Example file:

prefix="C:/Program Files/Npcap"
Name: libpcap
Version: 1.10
Description: Platform-independent network traffic capture library
Cflags: -I${prefix}/Include
Libs: -L${prefix}/Lib/x64 -lwpcap

Or, if it's feasible to change installation layout, this way $prefix could be calculated automatically:

C:/Program Files/Npcap/
    Include/
    x64/
        Lib/
            wpcap.lib
            pkgconfig/
                libpcap.pc
    x86/
        (ditto)
guyharris commented 3 years ago

Probably 32-bit and 64-bit folder should have their own .pc files, so that they are selected by PKG_CONFIG_PATH.

So is there a convention used on UN*Xes to deal with cross-building (which includes building for 32-bit on 64-bit and building for 64-bit on 32-bit)? If so, the same convention should probably be used on Windows (there's nothing inherently special about Npcap here; that would apply to all libraries).

PlushBeaver commented 3 years ago

On Unices binaries are installed to prefixes like /lib/i686-linux-gnu or /lib/x86_64-linux-gnu and so do *.pc files. Pkg-config searches packages by filename without .pc in PKG_CONFIG_PATH, which contains paths under appropriate prefix. So Npcap only has to place libpcap.pc (this exact name) in different folders for x86 and x64.

PlushBeaver commented 3 years ago

Bump. Is there a decision if Npcap will integrate pkg-config support? If it will, shall directory layout be changed? How can I help besides providing libpcap.pc above?

fyodor commented 3 years ago

Thanks for the suggestion. So far we haven't received many requests for this, but this issue is a good place for people to comment if they are interested in pkg-config support for Npcap and why. Npcap OEM customers can also request it through their support channel and we will tally those requests as well. Also, does upstream libpcap support this?

PlushBeaver commented 3 years ago

Upstream libpcap supports pkg-config from 1.9.0. My use case is Npcap being an optional dependency of DPDK on Windows. DPDK uses pkg-config as the primary dependency locator on all platforms.

guyharris commented 3 years ago

Also, does upstream libpcap support this?

"This" meaning what?

Both autotools and CMake builds of libpcap will, if you do make install with autotools or whatever builds the install target with CMake, install a libpcap.pc file.

For an autotools file, it will be installed in $(DESTDIR)$(libdir)/pkgconfig/libpcap.pc; that would only install under lib/i686-linux-gnu or /lib/x86_64-linux-gnu if DESTDIR and libdir are set appropriately when ./configure is run; it doesn't, as far as I know, do so automatically. Note that

On Unices binaries are installed to prefixes like /lib/i686-linux-gnu or /lib/x86_64-linux-gnu and so do *.pc files.

may be true of some UN*Xes but not all. On multi-architecture systems:

So the answer to "So is there a convention used on UNXes to deal with cross-building (which includes building for 32-bit on 64-bit and building for 64-bit on 32-bit)?" appears to be "No, there isn't a convention, there are several of them, and which one is used depends on the UN\X you're using."

This means that Npcap isn't constrained by what various UN*Xes have done. It should do whatever works best in Windows build environments.

The current installation layout for the SDK is

C:/{wherever you install it}/
    Include/
    Lib/
        Packet.lib
        wpcap.lib
        x64/
            Packet.lib
            wpcap.lib

I don't know what issues modifying the installation layout to the proposed layout would cause for existing projects.

(Update: on Windows, pkg-config can detect prefix if file is placed inside ${prefix}/lib/pkgconfig.)

So where is the Windows pkg-config port, including the documentation where that's mentioned?

PlushBeaver commented 3 years ago

may be true of some UN*Xes but not all.

Thanks a lot for enlightening, I stand corrected.

(Update: on Windows, pkg-config can detect prefix if file is placed inside ${prefix}/lib/pkgconfig.)

So where is the Windows pkg-config port, including the documentation where that's mentioned?

It's not a port, pkg-config upstream supports Windows. Official binaries are here:

Documentation for the mentioned feature: https://gitlab.freedesktop.org/pkg-config/pkg-config/-/blob/master/README.win32#L17