⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ip.c

📁 Boot code for ADM5120 with serial console for Edimax router.
💻 C
字号:
/*****************************************************************************;;    Project : Edimax;    Creator :;    File    : ip.c;    Abstract: defines the specific items that loader nedded.;;*****************************************************************************/#include <skbuff.h>#include <eth.h>#include <ip.h>#include <checksum.h>#include <helpers.h>#include <test_def.h>static UINT32 local_ip = 0;int ip_init(){	bsp_GetTftpIp(&local_ip);	return 0;}int ip_reinit(){	bsp_GetTftpIp(&local_ip);	return 0;}int ip_rcv_packet(struct sk_buff *skb){	struct iphdr *ip_hdr;	int udp_protocol;	udp_protocol = 0;	if (eth_rcv_packet(skb) == 1) {		ip_hdr = (struct iphdr *) (skb->data);		if (ntohl(ip_hdr->daddr) == local_ip) {			skb->len = ntohs(ip_hdr->tot_len);			skb_pull(skb, sizeof(struct iphdr));			if (ip_hdr->protocol == UDP)				udp_protocol = 1;		}	}	return udp_protocol;}int ip_send(struct sk_buff *skb, unsigned long ip, unsigned char proto){	struct iphdr *ip_hdr;	static unsigned short ip_id = 32;	unsigned char dest_eth_addr[ETH_ALEN];	if (arp_get_eth_addr(ip, dest_eth_addr))		return -1;	ip_hdr = (struct iphdr *)skb_push(skb, sizeof(struct iphdr));	ip_hdr->ihl = 5;	ip_hdr->version = 4;	ip_hdr->tos = 0;	ip_hdr->tot_len = htons(skb->len);	ip_hdr->id = htons(ip_id++);	ip_hdr->frag_off = 0;	ip_hdr->ttl = 20;	ip_hdr->protocol = proto;	ip_hdr->check = 0;	ip_hdr->saddr = htonl(local_ip);	ip_hdr->daddr = htonl(ip);	ip_hdr->check = ip_fast_csum((unsigned char *)ip_hdr,ip_hdr->ihl);	eth_send(skb, dest_eth_addr, ETH_P_IP);	return 0;}void ip_skb_reserve(struct sk_buff *skb){	eth_skb_reserve(skb);	skb_reserve(skb, sizeof(struct iphdr));}unsigned long ip_get_source_ip(struct sk_buff *skb){	struct iphdr *ip_hdr;	ip_hdr = (struct iphdr *)(skb->buf + ETH_HLEN);	return ntohl(ip_hdr->saddr);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -