首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Linux内核源代码中inet_sock.h中的“本地端口”和“源端口”有什么区别?

问Linux内核源代码中inet_sock.h中的“本地端口”和“源端口”有什么区别?
EN

Stack Overflow用户
提问于 2019-03-23 19:40:55
回答 1查看 167关注 0票数 2

我对linux/include/net/inet_sock.h文件中的可变端口和inet_sport之间的区别感到困惑,文档中只说一个是“本地端口”,另一个是“源端口”。

我将它们打印到终端,并且在每个sock中,inet_num和inet_sport都是不同的。我找不到更多关于这方面的文件。

代码语言:javascript
复制
/* 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
 */

它们代表什么?它们之间的区别是什么?它们有什么用呢?

EN

回答 1

Stack Overflow用户

发布于 2019-03-25 01:36:01

inet_num -主机字节顺序/协议类型中的本地端口。

代码语言:javascript
复制
         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 -网络字节顺序的源端口。这是您在中看到的端口

代码语言:javascript
复制
          packet.
代码语言:javascript
复制
         inet_sport = hton(inet_num)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55313362

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档