linux-kernel - Linux内核源代码中inet_sock.h中的“本地端口”和“源端口”有什么区别?
问题描述
inet_num
我对变量和inet_sport
文件中的区别感到困惑linux/include/net/inet_sock.h
,文件只是说一个是“本地端口”,另一个是“源端口”。
我将它们打印到终端,并且在每只袜子中,inet_num 和 inet_sport 都是不同的。我找不到更多关于此的文件。
/* linux/include/net/inet_sock.h */
/** struct inet_sock - representation of INET sockets
*
* @sk - ancestor class
* @pinet6 - pointer to IPv6 control block
* @inet_daddr - Foreign IPv4 addr
* @inet_rcv_saddr - Bound local IPv4 addr
* @inet_dport - Destination port
* @inet_num - Local port
* @inet_saddr - Sending source
* @uc_ttl - Unicast TTL
* @inet_sport - Source port
* @inet_id - ID counter for DF pkts
* @tos - TOS
* @mc_ttl - Multicasting TTL
* @is_icsk - is this an inet_connection_sock?
* @uc_index - Unicast outgoing device index
* @mc_index - Multicast device index
* @mc_list - Group array
* @cork - info to build ip hdr on each ip frag while socket is corked
*/
他们代表什么?它们之间有什么区别?它们的用途是什么?
解决方案
inet_num - 主机字节顺序/协议类型的本地端口。
For TCP/UDP sockets - it is a local port
Linux allocates the local port from the rage defined by user or
initialized by kernel at boot
https://ma.ttias.be/linux-increase-ip_local_port_range-tcp-port-range/
For RAW sockets/other protocols (where sport is not req)- protocol type
inet_sport - 网络字节顺序的源端口。
这是您在数据包中看到的端口。
inet_sport = hton(inet_num)
推荐阅读
- laravel - 我可以在保存 Laravel Excel 之前更改行吗?
- flowtype - 构造流类型的函数?
- r - 如果对 if 语句的任何提交为真,我如何获得嵌入在 for 循环中的 if else 语句以选择一个选项而不是另一个选项?
- c++ - 创建一个允许轻松创建虚函数包装函数的 C++ 宏
- unity3d - 如何在 Unity 中旋转等轴测图
- python - Kivy 从线程添加小部件
- python - Keras:模型总是预测相似的结果
- sql - 根据 SQL 中的记录 ID 选择最后 2 条记录
- azure-devops - 使用 NU1101 构建失败:找不到包 Microsoft.Bot.Protocol.StreamingExtensions.NetCore
- c++ - 未在 VS2017 中加载的符号文件在 JAGPDF 中仅发生 10% 的时间