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

📄 udp.c

📁 深圳优龙公司LPC2292开发板的BIOS源码和测试程序
💻 C
字号:
#include "../../inc/config.h"
#include "skbuff.h"
#include "eth.h"
#include "ip.h"
#include "udp.h"
#include "tftp.h"
#include "utils.h"

#ifdef	TFTP_DOWNLOAD_SUPPORT

int udp_init( void )
{
	return 0;
}

int udp_rcv_packet( struct sk_buff* skb )
{
	struct udphdr* udp_hdr = ( struct udphdr* ) ( skb->data );

	skb->len = ntohs( udp_hdr->len );
	skb_pull( skb , sizeof( struct udphdr ) );

	if ( ntohs( udp_hdr->dest ) == TFTP )
		tftp_rcv_packet( skb );

	return 0;
}

int udp_send( struct sk_buff* skb , unsigned long ip , unsigned short source ,
	unsigned short dest )
{
	struct udphdr* udp_hdr;

	udp_hdr = ( struct udphdr * ) skb_push( skb , sizeof( struct udphdr ) );
	udp_hdr->source = htons( source );
	udp_hdr->dest = htons( dest );
	udp_hdr->len = htons( 12 );
	udp_hdr->check = 0;

	ip_send( skb , ip , UDP );

	return 0;
}

void udp_skb_reserve( struct sk_buff* skb )
{
	ip_skb_reserve( skb );
	skb_reserve( skb , sizeof( struct udphdr ) );
}

unsigned short udp_get_source_port( struct sk_buff* skb )
{
	struct udphdr* udp_hdr;

	udp_hdr = ( struct udphdr * )
		( skb->buf + ETH_HLEN + sizeof( struct iphdr ) );
	return ntohs( udp_hdr->source );
}

#endif

⌨️ 快捷键说明

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