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

📄 igmp_serialize_message.c

📁 路由器协议平台igmp协议设计实现源码。
💻 C
字号:
/*
 $Log:: /OEM Source Code/igmp/igmp_serialize_message.c                                             $
 * 
 * 1     4/23/98 9:53p Release Engineer
 * Initial release
 * IGMP v4.1.0
 */
/************************************************************************/
/*  Copyright (C) 1997-1998 RouterWare, Inc.                            */
/*  Unpublished - rights reserved under the Copyright Laws of the       */
/*  United States.  Use, duplication, or disclosure by the              */
/*  Government is subject to restrictions as set forth in               */
/*  subparagraph (c)(1)(ii) of the Rights in Technical Data and         */
/*  Computer Software clause at 252.227-7013.                           */
/*  RouterWare, Inc., 3961 MacArthur Blvd. Suite 212, Newport Beach, CA */
/************************************************************************/
#include <memory.h>
#include "igmp.h"
#include "igmp_packet.h"
/*******************************************************************************************/
static void igmp_put_message_information_into_packet_to_tx (IGMP_MESSAGE *sptr_igmp_message, IGMP_PAYLOAD *sptr_igmp_payload);
static void igmp_fill_ip_parameters_for_message_to_tx (UINT port, ULONG group_ip_address, 
															IP_UPPER_LAYER_PARAMETERS *sptr_ip_parameters);
/*******************************************************************************************/
enum TEST igmp_serialize_message (UINT port, IGMP_MESSAGE *sptr_igmp_message)
{
	char ip_address[IP_ADDRESS_PRINT_BUFFER_SIZE];
	IP_UPPER_LAYER_PARAMETERS ip_parameters;
	IGMP_PACKET *sptr_igmp_tx_packet;
	UINT igmp_tx_packet_size;

	/* first allocate the packet */
	igmp_tx_packet_size = (UINT) (sizeof (IGMP_PAYLOAD) + sizeof (IP_HEADER) + sizeof (UNION_MAC_HEADER));

	sptr_igmp_tx_packet = (IGMP_PACKET *) get_an_ip_send_packet ((USHORT) port, (ULONG) (igmp_tx_packet_size + MAXIMUM_IP_OPTION_LENGTH));

	if (sptr_igmp_tx_packet == NULL)
		{
		IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP: Failed to get an ip send packet to send %s for group %s on port %u.\n",
			igmp_message_type_string [sptr_igmp_message->type],
			convert_ip_address_to_dot_format (&ip_address[0], sptr_igmp_message->group_ip_address),port);
		
		return (FAIL);
		}

	igmp_put_message_information_into_packet_to_tx (sptr_igmp_message, &sptr_igmp_tx_packet->igmp_payload);

	/* finally fill in the IP upper layer parameters */
	igmp_fill_ip_parameters_for_message_to_tx (port, sptr_igmp_message->group_ip_address, &ip_parameters);

	if (send_ip_packet_from_upper_layer (&ip_parameters, FALSE, (IP_PACKET *) sptr_igmp_tx_packet,
		(USHORT) igmp_tx_packet_size, (void (*) (USHORT port_number, IP_PACKET *sptr_ip_packet)) free_an_ip_send_packet) == FAIL)
		{
		IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP: Failed to send packet on port %u.\n", port);

		return (FAIL);
		}

	IGMP_PROTOCOL_TRACE (IGMP_TRACE, "IGMP: TRANSMITTED an IGMP message on port %u.\n", port);

	IGMP_PROTOCOL_TRACE_DISPLAY_MESSAGE (ip_parameters.source_address, ip_parameters.destination_address,
			sptr_igmp_message->type, sptr_igmp_message->max_response_time, sptr_igmp_message->group_ip_address);

	return (PASS);
}
/*******************************************************************************************/
static void igmp_put_message_information_into_packet_to_tx (IGMP_MESSAGE *sptr_igmp_message, IGMP_PAYLOAD *sptr_igmp_payload)
{
	USHORT checksum;

	sptr_igmp_payload->message_type = (BYTE) sptr_igmp_message->type;

	sptr_igmp_payload->max_response_time = (BYTE) sptr_igmp_message->max_response_time;

	sptr_igmp_payload->group_ip_address = serialize_long (sptr_igmp_message->group_ip_address);

	sptr_igmp_payload->checksum = serialize_short (0x0000);

	checksum = calculate_ip_checksum (NULL, (BYTE *) sptr_igmp_payload, sizeof (IGMP_PAYLOAD));

	checksum = net_to_host_short (checksum); /* put here because function is not host oriented...yet */

	sptr_igmp_payload->checksum = serialize_short (checksum); 
}
/*******************************************************************************************/
static void igmp_fill_ip_parameters_for_message_to_tx (UINT port, ULONG group_ip_address, IP_UPPER_LAYER_PARAMETERS *sptr_ip_parameters)
{
	memset (sptr_ip_parameters, 0, sizeof (IP_UPPER_LAYER_PARAMETERS));

	sptr_ip_parameters->virtual_port_number = (USHORT) port;

	sptr_ip_parameters->gateway = 0x00000000L;
	
	/* IP would fill in the source address */
	sptr_ip_parameters->source_address = 0x00000000L;

	/* the packet destination is determined by the group */
	if (group_ip_address == 0x00000000L)
		{
		/* General Queries are addressed to All systems group */
		sptr_ip_parameters->destination_address = ALL_SYSTEMS_MULTICAST_GROUP_ADDRESS;
		}
	else
		{
		/* Group specific queries are addressed to the group */
		sptr_ip_parameters->destination_address = group_ip_address;
		}
		
	sptr_ip_parameters->time_to_live = IGMP_V2_DEFAULT_IP_TTL;

	sptr_ip_parameters->protocol = IGMP_PROTOCOL_ID;

	/* add the router alert option */
	if (igmp.port_table[port].version == IGMP_VERSION_2)
		{
		sptr_ip_parameters->option_length = ROUTER_ALERT_OPTION_LENGTH;

		sptr_ip_parameters->user_options.char_options[0] = ROUTER_ALERT_OPTION_ID;

		sptr_ip_parameters->user_options.char_options[1] = ROUTER_ALERT_OPTION_LENGTH;

		sptr_ip_parameters->user_options.char_options[2] = 0x00;

		sptr_ip_parameters->user_options.char_options[3] = 0x00;
		}
}

⌨️ 快捷键说明

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