【问题标题】:What is the difference between 'Local port' and 'Source port' in inet_sock.h in Linux kernel source code?Linux内核源代码中inet_sock.h中的“本地端口”和“源端口”有什么区别?
【发布时间】:2019-03-23 11:40:55
【问题描述】:

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

我将它们打印到终端,并且在每只袜子中,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
 */

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

【问题讨论】:

    标签: linux-kernel network-programming


    【解决方案1】:

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-16
      • 1970-01-01
      • 1970-01-01
      • 2019-10-16
      • 2016-09-26
      • 2013-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多