header 和 ?

时间:2021-09-12 15:48:41

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?

据我观察,这两个libs都包含超过90%的相同的代码。当我在示例程序中声明它们时,不会发生奇迹。我并不真正理解这些lib的区别,即使它们位于分离的目录中。谁能帮我把它拆开吗?

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

另外:我尝试声明linux/in。h以上sys /套接字。h,像“无法找到sa_family_t的指定限定列表”这样的编译器,这意味着sa_family_t不在linux/in的范围内定义。h,如果这样叫……

Then I tried same thing for netinet/in.h,well,it works regardless of places the declaration are.

然后我也尝试了netinet/in。h,不管申报地点是什么,它都可以。

3 个解决方案

#1


12  

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.

linux / *。h header实际上是用于内部内核的,如果今天创建了Linux,这些文件甚至不存在于/usr/ include。但是在早期,许多用户空间libc(当时是libc4和libc5)依赖于Linux头文件来定义类型、常量、结构等,以便在用户空间中使用,所以netinet/in。h只包含#include 或类似的,可爱的传统开始了。今天,linux树中唯一应该用于userspace应用程序的头文件是一些与支持底层特定硬件相关的东西,比如linux控制台、framebuffer、video4linux等等。

In short, you should use netinet/in.h (the standard header specified by POSIX) and pretend you never saw linux/in.h. :-)

简而言之,你应该使用netinet/ In。h (POSIX指定的标准头)并假设您从未见过linux/in.h。:-)

#2


1  

From the header for <linux/in.h>:

的头中:

* Authors:     Original taken from the GNU Project <netinet/in.h> file.
*              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>

It's meant for kernel code that does networking. Use <netinet/in.h> in your own code.

这意味着内核代码可以进行联网。使用< netinet /。h>在你自己的代码中。

#3


0  

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.

netinet在许多BSD *nixes中都存在,甚至在BSD之前也存在*nixes,因此,linux opts对于netinet有一个非常相似的接口,所以代码可以被移植。

#1


12  

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.

linux / *。h header实际上是用于内部内核的,如果今天创建了Linux,这些文件甚至不存在于/usr/ include。但是在早期,许多用户空间libc(当时是libc4和libc5)依赖于Linux头文件来定义类型、常量、结构等,以便在用户空间中使用,所以netinet/in。h只包含#include 或类似的,可爱的传统开始了。今天,linux树中唯一应该用于userspace应用程序的头文件是一些与支持底层特定硬件相关的东西,比如linux控制台、framebuffer、video4linux等等。

In short, you should use netinet/in.h (the standard header specified by POSIX) and pretend you never saw linux/in.h. :-)

简而言之,你应该使用netinet/ In。h (POSIX指定的标准头)并假设您从未见过linux/in.h。:-)

#2


1  

From the header for <linux/in.h>:

的头中:

* Authors:     Original taken from the GNU Project <netinet/in.h> file.
*              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>

It's meant for kernel code that does networking. Use <netinet/in.h> in your own code.

这意味着内核代码可以进行联网。使用< netinet /。h>在你自己的代码中。

#3


0  

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.

netinet在许多BSD *nixes中都存在,甚至在BSD之前也存在*nixes,因此,linux opts对于netinet有一个非常相似的接口,所以代码可以被移植。