【问题标题】:What network layer handles responding to pings?哪个网络层处理对 ping 的响应?
【发布时间】:2015-02-03 18:06:17
【问题描述】:

我最近一直在学习 TCP 和 UDP,我知道 ping 使用 ICMP,所以我也试图理解这一点。我的理解是,当命令ping google.com 运行时,您的计算机通过IP 向google 发送一个echo request ICMP 数据包,然后google 用一个echo reply 消息进行响应。

我的问题是,当服务器以该回显回复消息进行响应时,实际上是由什么来处理的?是操作系统吗?它是一个特定的应用程序吗?还是完全是另外一回事?

【问题讨论】:

    标签: networking ping icmp


    【解决方案1】:

    它是响应 ICMP 请求的内核模块。 ICMPv4 模块是net/ipv4/icmp.c

    ICMP模块定义了一个数组表,用于处理各种ICMP请求,对象为icmp_objects,命名为icmp_pointers,由ICMP消息类型索引。

    ICMP控制结构:

    struct icmp_control {
      void (*handler)(struct sk_buff *skb);
      short error; /* This ICMP is classed as an error message */
    };
    
    static const struct icmp_control icmp_pointers[NR_ICMP_TYPES + 1] = {
    ...
      [ICMP_ECHO] = {
            .handler = icmp_echo,
      },
    ...
    };   
    

    从上面的结构中,当您向 google.com 服务器发送回显请求时,消息类型将为 icmp_echo 归结为子例程调用 icmp_echo(),它通过发送回显回复 (ICMP_ECHOREPLY) 来处理回显 (ping) 请求 (ICMP_ECHO) ) 和 icmp_reply().

    【讨论】:

      【解决方案2】:

      就 TCP/IP 参考模型而言,它是协议栈的网络层,通常位于内核中。

      【讨论】:

        猜你喜欢
        • 2021-12-28
        • 2010-12-26
        • 1970-01-01
        • 2016-08-21
        • 2011-09-15
        • 1970-01-01
        • 2017-04-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多