The comments say that net/if.h
is part of the GNU C Library and linux/if.h
says it is "An implementation of the TCP/IP protocol suite for the LINUX operating system."
But why are there two of them and what is the use of each one?
Initially, both provide data structures to manage network interfaces.linux/if.h
is specifically more related to interact with Linux kernel's network interfaces. Actually, it states so at the beginning of the file:
/*
* INET An implementation of the TCP/IP protocol suite for the LINUX
* operating system. INET is implemented using the BSD Socket
* interface as the means of communication with the user level.
*
* Global definitions for the INET interface module.
*/
net/if.h
is glibc's file for same purpose and is initially more user space
focused.
Is important to note that, if you're going to use both (they share some structures but not all), include order is quite important, suggesting, in most cases, to include linux/if.h
before net/if.h
.
linux/if.h
is part of the kernel (or imported in the libc from the kernel), and net/if.h
is part of the C library.
Thus, net/if.h
is what your processes can see, and linux/if.h
what the kernel wants. The kernel internals (which doesn't see libc) include the kernel headers. net/if.h
is what your hardcore networking tool includes. :-)
Far-far ago there were incompatibility problems between the two. This resulted f.e. don't working ifconfig, etc. tools. Currently (since around 10-15 yrs) they are well integrated and backward compatible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With