<linux/in.h> VS <netinet/in.h>

本文探讨了Linux内核中的头文件 (*.h) 的原始设计目的及其在现代软件开发中的角色转变。早期,这些头文件被用户空间的C库(如libc4和libc5)依赖,用于定义类型、常量等。随着时间发展,标准POSIX头文件成为主流选择,而Linux特有的头文件则更多地服务于底层硬件支持。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值