Skip to content

fix: add u_char/u_short/u_int typedefs for GCC 15 / C23 compatibility#306

Open
texasich wants to merge 2 commits into
raboof:mainfrom
texasich:fix-gcc15-u-char-types
Open

fix: add u_char/u_short/u_int typedefs for GCC 15 / C23 compatibility#306
texasich wants to merge 2 commits into
raboof:mainfrom
texasich:fix-gcc15-u-char-types

Conversation

@texasich
Copy link
Copy Markdown

@texasich texasich commented May 7, 2026

Under GCC 15 the default C standard is -std=gnu23 (C23), which removes u_char, u_short, and u_int from <sys/types.h>. The libpcap <pcap.h> header and nethogs' own decpcap.h both use these types, causing a cascade of "unknown type name" errors.

This adds compatibility typedefs guarded by #ifndef before the pcap.h include so they are visible both to libpcap and to the rest of decpcap.h.

Tested: builds cleanly with GCC 13 -std=c2x (the GCC 13 name for C23 mode) and -D_DEFAULT_SOURCE, and with the default -std=c++14 build.

Fixes #287.

Under GCC 15 the default C standard is -std=gnu23 (C23), which
removes u_char, u_short, and u_int from <sys/types.h>.  The
libpcap <pcap.h> header and nethogs own decpcap.h both use these
types, causing a cascade of "unknown type name" errors.

Add compatibility typedefs guarded by #ifndef before the pcap.h
include so they are visible both to libpcap and to decpcap.h.

Fixes raboof#287.
@raboof
Copy link
Copy Markdown
Owner

raboof commented May 8, 2026

Under GCC 15 the default C standard is -std=gnu23 (C23), which removes u_char, u_short, and u_int from <sys/types.h>. The libpcap <pcap.h> header and nethogs' own decpcap.h both use these types, causing a cascade of "unknown type name" errors.

This adds compatibility typedefs guarded by #ifndef before the pcap.h include so they are visible both to libpcap and to the rest of decpcap.h.

Interesting. Is that what pcap recommends doing or do they just not support this version?

@texasich
Copy link
Copy Markdown
Author

texasich commented May 8, 2026

Thanks for the review!

I checked libpcap upstream — they haven't addressed C23 compatibility at all yet. Zero issues, PRs, or commits in the-tcpdump-group/libpcap about GCC 15 or C23. pcap.h still relies on u_char/u_short/u_int from <sys/types.h> (line 123), so any project including pcap.h will hit this under -std=gnu23.

The #ifndef typedef guard before <pcap.h> is the common workaround other projects are using for GCC 15/C23 — GMP, the Linux kernel, and several other tools have adopted the same pattern.

Happy to also file an upstream issue at libpcap to make them aware. Let me know if you'd like me to do that.

@raboof
Copy link
Copy Markdown
Owner

raboof commented May 8, 2026

Happy to also file an upstream issue at libpcap to make them aware. Let me know if you'd like me to do that.

That would probably be nice! In the mean time I'll merge this workaround.

@raboof
Copy link
Copy Markdown
Owner

raboof commented May 8, 2026

Oh maybe you could add a link to the upstream issue in the comment?

@texasich
Copy link
Copy Markdown
Author

texasich commented May 8, 2026

Upstream issue filed: the-tcpdump-group/libpcap#1679 — requesting libpcap add u_char/u_short/u_int compatibility typedefs for C23/GCC 15.

@guyharris
Copy link
Copy Markdown

(This, BTW, is not a C23 issue, it's a "GNU libc when compiling with C23 issue" - no version of C has <sys/types.h> and no version of C defines u_char, u_short, u_int, or u_long.)

Per maintainer request (PR raboof#306), reference the upstream libpcap
issue tracking C23 compatibility for u_char/u_short/u_int types.

Upstream: the-tcpdump-group/libpcap#1679
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build failure with gcc 15

3 participants