the-tcpdump-group / libpcap

the LIBpcap interface to various kernel packet capture mechanism
https://www.tcpdump.org/
Other
2.72k stars 854 forks source link

rpcapd, MinGW gcc 8.x series and inet_ntop #877

Closed bscottm closed 5 years ago

bscottm commented 5 years ago

rpcapd compile breaks with an undefined reference to inet_ntop. The cause is the MinGW 8.x series gcc and associated WinXX runtime support. The workaround, if one calls it that, is to conditionally compile for _WIN32 and use getnameinfo. Not sure if that's the preferred patch or if there's a different approach to fix.

Note: This would afflict users who install the MinGW gcc compilers via scoop, which is still on the 8.x series. An updated MinGW 9.x series compiler doesn't have this issue. Nonetheless, things should just work out-of-the-box.

guyharris commented 5 years ago

rpcapd compile breaks with an undefined reference to inet_ntop. The cause is the MinGW 8.x series gcc and associated WinXX runtime support.

So the MinGW 8.x runtime support doesn't include inet_ntop(), unlike the libraries shipped by Microsoft?

The workaround, if one calls it that, is to conditionally compile for _WIN32 and use getnameinfo.

Presumably that's "getnameinfo() with NI_NUMERICHOST and NI_NUMERICSERV set"?

Not sure if that's the preferred patch or if there's a different approach to fix.

rpcapd already uses getnameinfo(), so we could just unconditionally use it for those error messages - call getnameinfo() to convert both the address and the port to numeric strings (passing NI_NUMERICHOST| NI_NUMERICSERV as the flags argument), and then log them.

bscottm commented 5 years ago

So the MinGW 8.x runtime support doesn't include inet_ntop(), unlike the libraries shipped by Microsoft?

No reason to be snippy. It's an issue with MingGW's 8.x series; the 9.x gcc doesn't have the problem (but I'm not betting on a mass upgrade for scoop users any time soon.) It's not as if there aren't differences between Linux distros lagging each other on kernel versions and unsupported ioctl calls that cause similar portability issues.

Presumably that's "getnameinfo() with NI_NUMERICHOST and NI_NUMERICSERV set"?

Sure, if that makes the most sense.

rpcapd already uses getnameinfo(), so we could just unconditionally use it for those error messages - call getnameinfo() to convert both the address and the port to numeric strings (passing NI_NUMERICHOST| NI_NUMERICSERV as the flags argument), and then log them.

It's not as straightforward as just unconditionally using it for specific error messages, at least not when I looked at the code. I'll attempt a patch for a pull.

gvanem commented 5 years ago

What is you just define _WIN32_WINNT >= 0x600? My old v4.0 TDM-MinGW gets you inet_ntop() if you do that.

bscottm commented 5 years ago

I could give that a shot. Not sure where I'd do that in CMakeLists.txt.

guyharris commented 5 years ago

I could give that a shot. Not sure where I'd do that in CMakeLists.txt.

Somewhere in the "Project settings" section. If it should be done only with MinGW, do it inside a test for MinGW:

if(MINGW)
    # We want support for APIs that appeared in Windows Vista
    add_definitions(-D _WIN32_WINNT=0x600)
endif(MINGW)
guyharris commented 5 years ago

What is you just define _WIN32_WINNT >= 0x600? My old v4.0 TDM-MinGW gets you inet_ntop() if you do that.

Done in ee7b04c4d30ba1afbd81debfc71899eb8a24d5ab.

guyharris commented 5 years ago

And:

so I'm closing this.

bscottm commented 5 years ago

@guyharris: WFM.

guyharris commented 5 years ago

@guyharris: WFM.

WFM2, as per builds on ci.appveyor.com.