What is the difference between linux/if.h and net/if.h?

c, linux

Solution

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`.

Problem

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?

Original source