Reputation: 706
As far as I have observed,both libs consist of over 90% same exact codes. When I declare them in my example programs,no magic happens. I don't really understand the difference of those libs even though they are located in seperated directories.Can someone break it down for me?
Plus: I tried declaring linux/in.h above sys/socket.h ,the complier buzzed like "cannot find specified-qualified-list for sa_family_t",which means sa_family_t is not defined in the scope of linux/in.h,if called in this manner...
Then I tried same thing for netinet/in.h,well,it works regardless of places the declaration are.
Upvotes: 12
Views: 7054
Reputation: 215193
The linux/*.h
headers were really meant for internal kernel use and if Linux were being created today, these files would not even exist under /usr/include
. But early on, a lot of the userspace libc (libc4 and libc5 at the time) relied on Linux headers to define types, constants, structures, etc. for use in userspace, so netinet/in.h
contained just #include <linux/in.h>
or similar, and the lovely tradition got started. Today the only headers in the linux
tree that should be used for userspace apps are some things related to supporting specific hardware at a low level, like the Linux console, framebuffer, video4linux, etc.
In short, you should use netinet/in.h
(the standard header specified by POSIX) and pretend you never saw linux/in.h
. :-)
Upvotes: 18
Reputation: 7095
From the header for <linux/in.h>:
* Authors: Original taken from the GNU Project <netinet/in.h> file.
* Fred N. van Kempen, <[email protected]>
It's meant for kernel code that does networking. Use <netinet/in.h> in your own code.
Upvotes: 1
Reputation: 6536
They do nearly the same thing, however, one is fairly standard, the other isn't.
netinet is present in many BSD *nixes, and and *nixes even before BSD, so, linux opts to have a very similar interface for netinet so code can be ported.
Upvotes: 0