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

📄 nat_ip.c

📁 vxworks下ppp的实现源码
💻 C
字号:
/* nat_ip.c *//* Copyright 2000-2003 Wind River Systems, Inc. *//* @format.tab-size 4, @format.use-tabs true, @format.new-line lf *//*modification history--------------------01b,23apr03,zhu  updated copyright01a,21apr03,myz replaced swap(_long) with the ntohs(l) and htons(l) macros.112202  zhu	Fixed a return type problem070201	tk	Modified implementations to call natSetBind to create IP control blocks so it		will work with the upgraded version of ALG API.*/#include "nat.h"#define IP_DEBUG/**************************************************************************************************/IP_TRANSLATION_ENTRY *handle_ip_translation_global_rx (IP_PACKET *sptr_ip_packet){	IP_TRANSLATION_ENTRY *sptr_ip_translation_entry;	sptr_ip_translation_entry = NULL;	if (nat.single_global_address_enabled == TRUE)		{		}	else		{		sptr_ip_translation_entry = handle_ip_translation_global_rx_natg (sptr_ip_packet);		}	return (sptr_ip_translation_entry);				}/*************************************************************************************************/IP_TRANSLATION_ENTRY *handle_ip_translation_local_rx (IP_PACKET *sptr_ip_packet){	PARAMETER_NOT_USED (sptr_ip_packet);	/* code may be added for a possible cut-thru capability */	return ((IP_TRANSLATION_ENTRY *) sptr_ip_packet);}/*************************************************************************************************/IP_TRANSLATION_ENTRY *handle_ip_translation_global_rx_natg (IP_PACKET *sptr_ip_packet){	IP_TRANSLATION_ENTRY *sptr_ip_translation_entry;	IP_ADDRESS destination_address;	USHORT checksum;	sptr_ip_translation_entry = match_sa_with_global_address (ntohl (sptr_ip_packet->header.destination_address),		&nat.natg.ip_translation_list);	if (sptr_ip_translation_entry == NULL)		{		return (NULL);		}					sptr_ip_translation_entry->time_stamp = nat.ip_translation_entry_timer;	destination_address = htonl (sptr_ip_translation_entry->sa_local_address);	checksum = sptr_ip_packet->header.header_checksum;	checksum_fixup ((BYTE *)&checksum, (BYTE *)&sptr_ip_packet->header.destination_address, sizeof (destination_address),		(BYTE *)&destination_address, sizeof (destination_address));#ifdef IP_DEBUG	nat_printf (NAT_PRINTF_DATA, "IP source address 0x%lx, original destination address 0x%lx\n",			ntohl (sptr_ip_packet->header.source_address), ntohl (sptr_ip_packet->header.destination_address));	nat_printf (NAT_PRINTF_DATA, "translated destination address 0x%lx\n",			ntohl (destination_address));	nat_printf (NAT_PRINTF_DATA, "original IP header checksum 0x%x, new IP header checksum 0x%x\n",			ntohs (sptr_ip_packet->header.header_checksum), ntohs (checksum));#endif	sptr_ip_packet->header.destination_address = destination_address;	sptr_ip_packet->header.header_checksum = checksum;	return (sptr_ip_translation_entry);}/*************************************************************************************************	Description:		This function is called when a packet is received at local port in basic NAT.		It checks the source IP in the packet to see if there is a match (i.e. it has been		translated).  If the match is not found, it assigns an IP address from its global address		pool, and sticks it into the packet.  The checksum is adjusted accordingly.		new_ip_translation_entry() gets a new IP address in the global address pool and create		a new entry in the IP translation list.*************************************************************************************************/IP_TRANSLATION_ENTRY *handle_ip_translation_local_rx_natg (IP_PACKET *sptr_ip_packet){	IP_TRANSLATION_ENTRY *sptr_ip_translation_entry;	USHORT checksum;	IP_ADDRESS		source_address;	NAT_BIND_INFO	bind_info;	NAT_STATUS		status;	sptr_ip_translation_entry = match_sa_with_local_address (ntohl (sptr_ip_packet->header.source_address), &nat.natg.ip_translation_list);	if (sptr_ip_translation_entry == NULL)		{		memset(&bind_info,0,sizeof(bind_info));		bind_info.agent_id = 0;			/* agent is NAT */		bind_info.type = NAT_BIND_BASIC;		bind_info.direction = NAT_OUTBOUND;		bind_info.protocol = IPPROTO_IP;		bind_info.static_entry = FALSE;		bind_info.local_addr = ntohl(sptr_ip_packet->header.source_address);		bind_info.remote_addr = ntohl(sptr_ip_packet->header.destination_address);			status = natSetBind((u_long)&nat, 0, &bind_info);		if(status != NAT_OK)			{			nat_printf (NAT_PRINTF_ERROR, "natSetBind returned %d\n",status);			return(NULL);			}		sptr_ip_translation_entry = (IP_TRANSLATION_ENTRY *) bind_info.nat_address_entry;		}	sptr_ip_translation_entry->time_stamp = nat.ip_translation_entry_timer;	source_address = htonl (sptr_ip_translation_entry->sa_global_address);	checksum = sptr_ip_packet->header.header_checksum;	checksum_fixup ((BYTE *)&checksum, (BYTE *)&sptr_ip_packet->header.source_address, sizeof (source_address),		(BYTE *)&source_address, sizeof (source_address));#ifdef IP_DEBUG	nat_printf (NAT_PRINTF_DATA, "NAT original IP source address 0x%lx, destination address 0x%lx\n",			ntohl (sptr_ip_packet->header.source_address), ntohl (sptr_ip_packet->header.destination_address));	nat_printf (NAT_PRINTF_DATA, "NAT translated source address 0x%lx\n",			ntohl (source_address));	nat_printf (NAT_PRINTF_DATA, "NAT original IP header checksum 0x%x, new IP header checksum 0x%x\n",			ntohs (sptr_ip_packet->header.header_checksum), ntohs (checksum));#endif	sptr_ip_packet->header.source_address = source_address;	sptr_ip_packet->header.header_checksum = checksum;		return (sptr_ip_translation_entry);}

⌨️ 快捷键说明

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