免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2556 | 回复: 2
打印 上一主题 下一主题

[FreeBSD] bsd4.4网络源码中output函数。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-12-04 13:29 |只看该作者 |倒序浏览
int ether_outpu(struct ifnet *ifp,struct mbuf *m0,struct sockaddr *dst,struct rtentry *rt0);
m0指的是第一个链表还是所有的链表呢。如果是所有链表那么下面的代码怎么解释呢?
           short  type;
                 u_char edst[6];
                 struct arpcom *ac;

           struct ether_header *eh=mtod(m,struct ether_header *);
               short  type = htons((u_short)type);
        bcopy((caddr_t)&type,(caddr_t)&eh->ether_type,
                sizeof(eh->ether_type));
        bcopy((caddr_t)edst, (caddr_t)eh->ether_dhost, sizeof (edst));
        bcopy((caddr_t)ac->ac_enaddr, (caddr_t)eh->ether_shost,
            sizeof(eh->ether_shost));
这里面mbuf怎么样将全部的内容正好转换成ether_header结构的呢。谢谢大伙帮忙解释一下。

论坛徽章:
0
2 [报告]
发表于 2006-12-04 14:34 |只看该作者
1、什么是第一个链表?什么是所有的链表?

2、m0指向的是存储着需要通过以太网发送出去的报文的第一个mbuf结构体。

3、这里不存在将mbuf的全部内容“正好转换成ether_header结构体”的问题。这里只是在上层传递下来的报文的第一个mbuf中附加上以太网头而已。如果第一个mbuf中没有足够的空间来存放以太网头,则由之前的M_PREPEND(m, sizeof (struct ether_header), M_DONTWAIT);这句话另行分配一个mbuf,作为新的“第一个”mbuf。

4、mtod宏直接将第一个mbuf的data指针转换为ether_header结构体类型的指针。前述M_PREPEND()宏保证了在这个指针之后有14个空闲字节用来存放以太网头。

5、3个bcopy只是填充以太网头结构体中的ether_dhost、ether_shost、ether_type字段而已。与“后面的”实际发送数据无关。

6、ether_output forms the Ethernet header from type, edst, and ac_enaddr. ac_enaddr is the unicast Ethernet address associated with the output interface and is the source Ethernet address for all frames transmitted on the interface. ether_output overwrites the source address the caller may have specified in the ether_header structure with ac_enaddr. This makes it more difficult to forge the source address of an Ethernet frame.

论坛徽章:
0
3 [报告]
发表于 2006-12-06 12:08 |只看该作者

哪位大哥有tcp/ip V2 实现英文版PDF格式的先谢谢

哪位大哥有tcp/ip V2 实现英文版PDF格式的先谢谢
xiaoning158@gmail.com
给我网址自己下也可以谢谢了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP