ARP实现代码.docVIP

  • 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

文档评论(0)

1亿VIP精品文档

相关文档