- 13
- 0
- 约1.39万字
- 约 18页
- 2018-01-01 发布于河南
- 举报
ARP实现代码
ARP实现代码
struct arphdr
{
unsigned short ar_hrd; /* format of hardware address */
unsigned short ar_pro; /* format of protocol address */
unsigned char ar_hln; /* length of hardware address */
unsigned char ar_pln; /* length of protocol address */
unsigned short ar_op; /* ARP opcode (command) */
#if 0
/*
Ethernet looks like this : This bit is variable sized however...
*/
unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */
unsigned char ar_sip[4]; /* sender IP address */
unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
unsigned char ar_tip[4]; /* target IP address */
};
/*
* Create an arp packet. If (dest_hw == NULL), we create a broadcast
* message.
*/
struct sk_buff *arp_create(int type, int ptype, u32 dest_ip,
struct net_device *dev, u32 src_ip,
unsigned char *dest_hw, unsigned char *src_hw,
unsigned char *target_hw)
{
struct sk_buff *skb;
struct arphdr *arp;
unsigned char *arp_ptr;
/*
* Allocate a buffer
*/
skb = alloc_skb(sizeof(struct arphdr)+ 2*(dev-addr_len+4)
+ LL_RESERVED_SPACE(dev), GFP_ATOMIC);
if (skb == NULL)
return NULL;
skb_reserve(skb, LL_RESERVED_SPACE(dev));
skb-nh.raw = skb-data;
arp = (struct arphdr *) skb_put(skb,sizeof(struct arphdr) + 2*(dev-addr_len+4));
skb-dev = dev;
skb-protocol = htons(ETH_P_ARP);
if (src_hw == NULL)
src_hw = dev-dev_addr;
if (dest_hw == NULL)
dest_hw = dev-broadcast;
/*
* Fill the device header for the ARP frame
*/
if (dev-hard_header
dev-hard_header(skb,dev,ptype,dest_hw,src_hw,skb-len) 0)
goto out;
/*
* Fill out the arp protocol part.
*
* The arp hardware type should match the device type, except for FDDI,
* which (according to RFC 1390) should always equal 1 (Ethernet).
*/
/*
* Exceptions everywhere. AX.25 uses the AX.25 PID value not the
* DIX code for the protocol. Make these device structure fields.
*/
switch (dev-type) {
default:
arp-ar_hrd = htons(dev-type);
arp-ar_pro = htons(ETH_P_IP);
break;
#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
case ARPHRD_AX25:
arp-ar_hrd = htons(ARP
您可能关注的文档
最近下载
- 上海大学2022-2023学年第1学期《高等数学(上)》期末考试试卷(A卷)附参考答案.pdf
- 中国教育行业人才流动与薪酬水平_2025年12月.docx
- 2024全国初中数学联赛初二卷 .pdf VIP
- 全国初中数学联合竞赛真题及答案(初二组)2015-年.pdf VIP
- AIAG-VDA-SPC手册-Yellow-Volume2026年2月第一版 中文.pdf VIP
- 美甲美睫投资回报2026年培训课件.pptx VIP
- 中国王氏家谱字辈大全.doc VIP
- 《Michael_Porter_Creating_Shared_Value》.pdf VIP
- 直播带货虚假宣传法律规制研究.pdf
- 新大洲本田MS01说明书用户手册.pdf
原创力文档

文档评论(0)