关闭

Linux内核--网络栈实现分析(五)--传输层之UDP协议(上)

发表于:2012-12-27 10:26

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:闫明    来源:51Testing软件测试网采编

  注:标题中的”(上)“,”(下)“表示分析过程基于数据包的传递方向:”(上)“表示分析是从底层向上分析、”(下)“表示分析是从上向下分析。

  这里看看数据包从IP层是如何交给传输层来处理的,为了方便,这里传输层以UDP协议为例来分析。

  从ip_rcv()函数中可以看到

        /*
  * Pass on the datagram to each protocol that wants it,
  * based on the datagram protocol.  We should really
  * check the protocol handler's return values here...
  */
  ipprot->handler(skb2, dev, opts_p ? &opt : 0, iph->daddr,
    (ntohs(iph->tot_len) - (iph->ihl * 4)),
    iph->saddr, 0, ipprot);

  这里调用指定协议的handler函数,如果是UDP协议,该函数的定义 udp_protocol如下

static struct inet_protocol udp_protocol = {
  udp_rcv,  /* UDP handler  */
  NULL,   /* Will be UDP fraglist handler */
  udp_err,  /* UDP error control */
  &tcp_protocol, /* next   */
  IPPROTO_UDP,  /* protocol ID  */
  0,   /* copy   */
  NULL,   /* data   */
  "UDP"   /* name   */
};

  先看UDP协议数据报的报头定义如下:比较简单

struct udphdr {
  unsigned short source;//源端口
  unsigned short dest;//目的端口
  unsigned short len;//数据包长度
  unsigned short check;//检验和
};

  下面就分析下udp_rcv()函数,流程图:

41/41234>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号