Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the practical difference between the headers <linux/in.h> and <netinet/in.h>?

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.

like image 625
jasonkim Avatar asked Feb 22 '12 03:02

jasonkim


1 Answers

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. :-)

like image 135
R.. GitHub STOP HELPING ICE Avatar answered Oct 17 '22 02:10

R.. GitHub STOP HELPING ICE